Ksike Hook library for easy implementation of Event Driven Design
npm install kshookThis library belong to the Ksike ecosystem:
- KsMf - Microframework (WEB, REST API, CLI, Proxy, etc)
- Ksdp - Design Patterns Library (GoF, GRASP, IoC, DI, etc)
- KsCryp - Cryptographic Library (RSA, JWT, x509, HEX, Base64, Hash, etc)
- KsHook - Event Driven Library
- KsEval - Expression Evaluator Library
- KsWC - Web API deployment Library
For further information, check the following topics:
- Getting Started
- Notifiers
- Processors
- Subscribers
- Workflow
- Ksdp Hooks Model
- Create a preconfigured hook service in your project.
- Create a route/controller to handle hooks
The library comprises four key components: Hooks, Subscriber, Notifier, and Processor. These components work in tandem to provide a modular and customizable solution for managing events and executing actions based on event triggers.
Install the library:
`` npm install kshook`
Load your custom notifier, subscriber, and processors:
`js`
const locator = require('./notifier.locator');
const { models, driver, manager } = require('./db');
Register subscribers for each event in the data model
``
------------------------------------------------------------------------------------------
| id | event | notifier | value | param | processor | expression |
------------------------------------------------------------------------------------------
| 1 | logout | locator | newrelic | null | null | null |
| 2 | login | locator | alert | { failure: dto.inf} | native | failure EQUAL 11 |
------------------------------------------------------------------------------------------
Extended model useful for workflows:
``
----------------------------------------------------------------------------------------------------------------------------------------
| id | event | notifier | value | param | processor | expression | notifier_alt | value_alt | param_alt |
----------------------------------------------------------------------------------------------------------------------------------------
| 1 | logout | locator | newrelic | null | null | null | null | null | null |
| 2 | login | locator | alert | {failure:dto.inf} | native | failure EQUAL 11 | email | test@srv.com | {note:dto.note} |
----------------------------------------------------------------------------------------------------------------------------------------
For more details check the workflow section.
Configure and run
`js
const KsHook = require('kshook');
// Initialize KsHook instance
const hook = KsHook.get();
// Configure supported components
hook.notifier.set({
name: "locator",
target: locator
});
hook.subscriber.get("Model").configure({
models,
driver,
manager
});
// Trigger the 'login' event
const res = hook.trigger({
subscriber: ["Model"],
event: "login",
data: { failure: 10, flow: "6868465468415", step: "STEP-1" }
});
``
Explore the potential of dynamic event handling with KsHook, a library designed to empower developers with flexibility, extensibility, and seamless event-driven architecture.