Skip to content

Latest commit

 

History

History
80 lines (53 loc) · 1.84 KB

README.md

File metadata and controls

80 lines (53 loc) · 1.84 KB

Builder for handler event payments

Description

This package provides a class builder of handlers to receive events and execute jobs from roles registered in this

how to use

install in project with:

npm install bm-ev-handler-builder

or

yarn add bm-ev-handler-builder

create instance:

import  { WebhookHandlerBuilder } from 'bm-ev-handler-builder';

const useCases = {
  activeContract: (contract) => ({ ...contract, status: 'ACTIVE'}),
  cancelContract: (contract) => ({ ...contract, status: 'CANCELED'})
  }

const repository = {
  getContractByReferenceId: (referenceId) => contract
  }

const dictRoles = { 'PAYMENT_CONFIRMED': {
  active: [ 'activeContract' ],
  pending: ['cancelContract']
}}

const handlerBuilder = new WebhookHandlerBuilder(useCases, repository, dictRoles);

export handlerBuilder.handler(EventReceived)

create instance:

import  { WebhookHandlerBuilder } from 'bm-ev-handler-builder';

const handlerBuilder = new WebhookHandlerBuilder();
handlerBuilder.setRepository(myRepository)
handlerBuilder.setUseCases(myUseCases)
handlerBuilder.setDictRoles(myRoles)

export handlerBuilder.handler(EventReceived)

Has possible to add use cases, repositories, and roles after instance one by one:

import  { WebhookHandlerBuilder } from 'bm-ev-handler-builder';

const handlerBuilder = new WebhookHandlerBuilder();

// roles
handlerBuilder.addActionRole('PAYMENT_CONFIRMED', 'PENDING', ['activeContract'])
handlerBuilder.addActionRole('PAYMENT_OVERDUE', 'ACTIVE', ['cancelContract'])

// useCases
handlerBuilder.addUseCase('cancelContract', cancelContractFunction)

// export handler to use e route
export handlerBuilder.handler(EventReceived)



ko-fi