@partrocks/events
v0.0.8
Published
Event / Listener Register and Message Queue Management for PartRocks Platform.
Downloads
2
Readme
@partrocks/events
@partrocks/events
Installation
Use the package manager npm to install to node_modules.
npm install @partrocks/events
Usage (nodejs)
const {
connectMessageQueue,
dispatch,
addListener,
RockEvent,
RockEventTypes,
} = require("@partrocks/events")
...or with import syntax
import {
connectMessageQueue,
dispatch,
addListener,
RockEvent,
RockEventTypes,
} from "@partrocks/events"
Usage
to dispatch an event (example)
await connectMessageQueue(async () => {
const link = "https://www.link.com"
await dispatch(
new RockEvent(RockEventTypes.EMAIL, {
template: "OrderComplete",
from: "Part Rocks <[email protected]>",
to: "[email protected]",
subject: "You Order has been recieved",
text: `Its on its way `,
html: `<body><h1>Recieved/h1><p>Click this link to track your order<a href='${link}'>${link}</a></p></body>`,
})
)
})
or on the other end (example an SMTP service)
await connectMessageQueue(async () => {
addListener(RockEventTypes.EMAIL, (message: any) => {
// relay email from message to SMTP
console.log(message.subject) // >> "You Order has been recieved"
})
})
Contributing
Get in touch [email protected]
License