@wizzer-tech/events-factory
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

Events Factory

Events Factory is a versatile tool designed to streamline the generation of structured event objects within your JavaScript applications. This package offers a simple yet powerful interface for creating events with customizable properties and defaults.

Installation

You can install the Events Factory package via npm:

npm install events-factory

Usage

Importing

import EventsFactory from '@wizzer-tech/events-factory';

Initializing

To initialize the Events Factory, simply create an instance of the class, providing the necessary parameters:

const eventsFactory = new EventsFactory('my-service', {
  app: 'my-app',
  version: '1.0.0',
  eventIdPrefix: 'evt'
});

Generating Events

Once initialized, you can use the generate method to create structured event objects:

const event = eventsFactory.generate('user.created', { userId: '12345' });

Customization

You can customize the default properties set during initialization or override them when generating events:

eventsFactory.setVersion('2.0.0');
const customEvent = eventsFactory.generate('user.signout', { userId: '12345' }, { app: 'another-app', version: '1.5.0' });

API

EventsFactory

Constructor

new EventsFactory(service: string = "", props: IEventsFactoryProps)
  • service: The service generating the event.
  • props: Additional properties for customizing the factory.

Methods

  • setVersion(version: string) Sets the default version for events created by this factory.
  • generate(type: string, data: Record<string, any>, props: IEventProperties) Generates a structured event object.

References

Package Sidebar

Install

npm i @wizzer-tech/events-factory

Weekly Downloads

88

Version

2.0.1

License

Apache-2.0

Unpacked Size

165 kB

Total Files

8

Last publish

Collaborators

  • pawan-wizzer