npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@janiscommerce/event-emitter

v3.0.0

Published

A package for emit events

Downloads

1,015

Readme

Event Emitter

Build Status Coverage Status npm version

A package to emit events to JANIS Events

Installation

npm install @janiscommerce/event-emitter

Configuration

ENV variables

JANIS_SERVICE_NAME (required): The name of the service that will emit the event.

Important

This package uses @janiscommerce/microservice-call, it's strongly recommended to read this package docs before continue.

API

emit(event)

Emits an event to janis-events. Returns an object with a boolean property result set to true if the operation is successful, false otherwise, and a response property with the MS Call response.

Event parameter

The event parameter is an [Object] and have the following structure:

  • entity [String] (required): The name of the entity that is emitting the event.
  • event [String] (required): The event name.
  • client [String] (optional): The client code name.
  • id [Number|String|Array of Strings|Array of Numbers] (optional): The ID or ID's of the entity that is emitting the event.

Errors

The errors are informed with a EventEmitterError. This object has a code that can be useful for a correct error handling. The codes are the following:

| Code | Description | |------|--------------------------------| | 1 | Invalid event | | 2 | Invalid event properties | | 3 | Unknown/empty service name | | 4 | MicroserviceCall Error |

Usage

'use strict';

const EventEmitter = require('@janiscommerce/event-emitter');

process.env.JANIS_SERVICE_NAME = 'my-service';

(async () => {

	try {
		const { result, response } = await EventEmitter.emit({
			entity: 'some-entity',
			event: 'some-event',
			client: 'some-client',
			id: 1
		});

		if(!result)
			console.log(response);

	} catch(err) {
		throw err;
	}

	try {
		const { result, response } = await EventEmitter.emit({
			entity: 'some-entity',
			event: 'some-event',
			client: 'some-client',
			id: [1, 2, 3, 4]
		});

		if(!result)
			console.log(response);

	} catch(err) {
		throw err;
	}

})();