{"_id":"@abassade/events","_rev":"11-40887fb12450af2e230bea91903b59c6","name":"@abassade/events","dist-tags":{"latest":"1.0.10"},"versions":{"1.0.0":{"name":"@abassade/events","version":"1.0.0","keywords":[],"author":{"name":"Abass Makinde"},"license":"ISC","_id":"@abassade/events@1.0.0","maintainers":[{"name":"abassade","email":"abs4real16.ma@gmail.com"}],"dist":{"shasum":"9261390906be8a5e8db9c7fbc064a1b8c330d03d","tarball":"https://registry.npmjs.org/@abassade/events/-/events-1.0.0.tgz","fileCount":12,"integrity":"sha512-ETQKJOo63xSuzH42CJZG2sKYSon95NX5r/QIno+ZAaKXdFja/Vv42dXvBQwN1BT9TNq2Kq65MYp2NCRmHaF94Q==","signatures":[{"sig":"MEQCIBDloD/IcrWNp1Wr+nGxwNLwmrzEX+EGuimbHi0pr3UdAiBRnzCUci9a9UI2taFqP9YQue9jwh/1yni68HMRLYZDmw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":10189},"main":"./build/index.js","types":"./build/index.d.ts","gitHead":"f1c6f2e0546ed2908e898db7066d1d863064f01f","scripts":{"pub":"npm version patch && npm run build && npm publish --access=public","build":"npm run clean && tsc","clean":"del-cli ./build/*"},"_npmUser":{"name":"abassade","email":"abs4real16.ma@gmail.com"},"_npmVersion":"8.19.2","description":"The events module for nats-jetstream","directories":{},"_nodeVersion":"16.18.0","dependencies":{"nats":"^2.8.0","@types/node":"^18.11.0"},"_hasShrinkwrap":false,"devDependencies":{"del-cli":"^5.0.0","typescript":"^4.8.4"},"_npmOperationalInternal":{"tmp":"tmp/events_1.0.0_1715958420720_0.56914493463515","host":"s3://npm-registry-packages"}},"1.0.8":{"name":"@abassade/events","version":"1.0.8","keywords":[],"author":{"name":"Abass Makinde"},"license":"ISC","_id":"@abassade/events@1.0.8","maintainers":[{"name":"abassade","email":"abs4real16.ma@gmail.com"}],"dist":{"shasum":"1c069a92c6ba4cd76e518d2231cf785c5a305dde","tarball":"https://registry.npmjs.org/@abassade/events/-/events-1.0.8.tgz","fileCount":12,"integrity":"sha512-Ku9+IWxlq9TtmlG7q+/kZ5FVYJpdihPWJCccfhX1/OdYsWtNMIjTdesv0+JZVT9l7hcm+BvyC7BqKZ67gwnWVw==","signatures":[{"sig":"MEYCIQDvgqeaqMNNAqn/BJemkN1nv13yoso/jweMxMwMhhRMYQIhAO6QzAsrtXfxRSC2Wn3DAnWwuCUY1SkrV62ynZgHpiAS","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":10357},"main":"./build/index.js","types":"./build/index.d.ts","gitHead":"7c208b55cde244d110711b2c4ac51a10ce22baf0","scripts":{"pub":"npm version patch && npm run build && npm publish --access=public","build":"npm run clean && tsc","clean":"del-cli ./build/*"},"_npmUser":{"name":"abassade","email":"abs4real16.ma@gmail.com"},"_npmVersion":"8.19.2","description":"The events module for nats-jetstream","directories":{},"_nodeVersion":"16.18.0","dependencies":{"nats":"^2.8.0","@types/node":"^18.11.0"},"_hasShrinkwrap":false,"devDependencies":{"del-cli":"^5.0.0","typescript":"^4.8.4"},"_npmOperationalInternal":{"tmp":"tmp/events_1.0.8_1716119960861_0.9490604613711118","host":"s3://npm-registry-packages"}},"1.0.9":{"name":"@abassade/events","version":"1.0.9","keywords":[],"author":{"name":"Abass Makinde"},"license":"ISC","_id":"@abassade/events@1.0.9","maintainers":[{"name":"abassade","email":"abs4real16.ma@gmail.com"}],"dist":{"shasum":"6fc8f6f771f64665450cfe1a3d7b50f57191711c","tarball":"https://registry.npmjs.org/@abassade/events/-/events-1.0.9.tgz","fileCount":12,"integrity":"sha512-0MHG5UaVH9d4m8fmcdeB47JXHqIbZepRt51nuxP1Ye2inSvbW9xjSrFk6p8UXHhI3zn5koJOeZ5/EQiOP1HaQw==","signatures":[{"sig":"MEQCIDuZdYQG/9iuzWZb7VJNXx5FBn1Tc0ARW6NVRBl88kw2AiAIdnfH2u5PgX1Qjmi//skcY0vaXo7yO3AEhg+rB2+F4Q==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":13453},"main":"./build/index.js","types":"./build/index.d.ts","gitHead":"922f2b71a0bc9d7134a056b8fd48aa241d00aa82","scripts":{"pub":"npm version patch && npm run build && npm publish --access=public","build":"npm run clean && tsc","clean":"del-cli ./build/*"},"_npmUser":{"name":"abassade","email":"abs4real16.ma@gmail.com"},"_npmVersion":"8.19.2","description":"The events module for nats-jetstream","directories":{},"_nodeVersion":"16.18.0","dependencies":{"nats":"^2.8.0","@types/node":"^18.11.0"},"_hasShrinkwrap":false,"devDependencies":{"del-cli":"^5.0.0","typescript":"^4.8.4"},"_npmOperationalInternal":{"tmp":"tmp/events_1.0.9_1716154366068_0.276488529278081","host":"s3://npm-registry-packages"}},"1.0.10":{"name":"@abassade/events","version":"1.0.10","description":"The events module for nats-jetstream","main":"./build/index.js","types":"./build/index.d.ts","scripts":{"clean":"del-cli ./build/*","build":"npm run clean && tsc","pub":"npm version patch && npm run build && npm publish --access=public"},"keywords":[],"author":{"name":"Abass Makinde"},"license":"ISC","devDependencies":{"del-cli":"^5.0.0","typescript":"^4.8.4"},"dependencies":{"@types/node":"^18.11.0","nats":"^2.8.0"},"gitHead":"eee3479a6ef3e8f8b4adbfddb14e358183fb01e9","_id":"@abassade/events@1.0.10","_nodeVersion":"16.18.0","_npmVersion":"8.19.2","dist":{"integrity":"sha512-4zKKCsTY23FnWEoARxBbAaAYm/NAy7EFpzylxIwgFeuOPcWG924qLOSPowqIkoK7cFmpoBMGZA6HCef1lWbdZw==","shasum":"5e90a1565571c850792062e5d7b4b4d184b1c955","tarball":"https://registry.npmjs.org/@abassade/events/-/events-1.0.10.tgz","fileCount":12,"unpackedSize":15109,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAK9CX4ml3fC6VW54GOMa9vCGXZ5xOmSS3Dh0G8FkaxXAiAcl5W9yFFXeU8qla9Lkv2irpBBFkh7L0BNSs0RufExLg=="}]},"_npmUser":{"name":"abassade","email":"abs4real16.ma@gmail.com"},"directories":{},"maintainers":[{"name":"abassade","email":"abs4real16.ma@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/events_1.0.10_1737100689614_0.9624785906025115"},"_hasShrinkwrap":false}},"time":{"created":"2024-05-17T15:07:00.594Z","modified":"2025-01-17T07:58:09.954Z","1.0.1":"2024-05-17T14:15:07.900Z","1.0.2":"2024-05-17T15:01:36.951Z","1.0.3":"2024-05-17T15:01:42.066Z","1.0.4":"2024-05-17T15:01:46.111Z","1.0.5":"2024-05-17T15:01:49.868Z","1.0.6":"2024-05-17T15:01:53.525Z","1.0.7":"2024-05-17T15:01:58.273Z","1.0.0":"2024-05-17T15:07:00.855Z","1.0.8":"2024-05-19T11:59:21.011Z","1.0.9":"2024-05-19T21:32:46.222Z","1.0.10":"2025-01-17T07:58:09.802Z"},"author":{"name":"Abass Makinde"},"license":"ISC","keywords":[],"description":"The events module for nats-jetstream","maintainers":[{"name":"abassade","email":"abs4real16.ma@gmail.com"}],"readme":"\n# Nats Jetstream library for NodeJS\n\nThe @abassade/events package provides a simplified interface for integrating NATS and JetStream messaging into your Node.js applications. This library exposes easy-to-use methods for connecting, publishing, and subscribing to messages, making it straightforward to incorporate these powerful messaging systems into your projects.\n\n\n\n\n\n## Installation\nTo install the package, use npm or yarn:\n\n```sh\nnpm install @abassade/events\n```\nor\n```sh\nyarn add @abassade/events\n```\n\n## Usage\n### Connecting\nTo use the library, first, you need to establish a connection to the NATS server and setup the topics/subjects with the stream.\n```typescript\nimport { nats, normalizeSubject } from '@abassade/events';\n\nconst natsUrl = 'nats://localhost:4222'; // you can replace this by your nats server url (host:port)\nconst subjects = [\"provider.bank.account.created\"]; // list of topics\nconst streamName = \"Account-stream\"; // stream name\n\nasync function start() {\n    try {\n         await nats.connect({ servers: \"0.0.0.0:4222\" });\n         const jsm = await nats.nc.jetstreamManager();\n         await nats.setupStream(subjects, streamName, jsm);\n    } catch (error) {\n        console.error('Failed to connect to NATS server:', error);\n    }\n}\nstart();\n```\n### Publishing Messages\nOnce connected, you can publish messages to a subject.\n```typescript\nimport { nats, normalizeSubject } from '@abassade/events';\n\n\nasync function start() {\n    try {\n         await nats.publish(normalizeSubject(\"provider.bank.account.created\"), {\n            id: \"sdzfsdfz\",\n            account_name: \"John Doe\",\n         });\n         console.log(\"published successful\");\n    } catch (error) {\n        console.error('Failed to publish:', error);\n    }\n}\n```\n\n### Subscribing to Messages\nYou can also subscribe to subjects to receive messages.\n```typescript\nimport { nats, normalizeSubject } from '@abassade/events';\n\n\nasync function start() {\n    const postCreatedHandler = async (event: any, msg: JsMsg) => {\n  try {\n    console.log(\"event>>>\", event); // you can make use of the events recieved\n    msg.ack();\n  } catch (error) {\n    console.log(error);\n  }\n};\n(async () => {\n  await nats.subscribe(\n    normalizeSubject(\"provider.polaris.account.created\"),\n    postCreatedHandler\n  );\n})();\n\n```\n\n## API Reference\n\n### `connect(natsUrl: string): Promise<void>`\n\nEstablishes a connection to the NATS server.\n\n- `natsUrl`: The URL of the NATS server.\n\n### `publish(subject: string, message: any): Promise<void>`\n\nPublishes a message to the specified subject.\n\n- `subject`: The subject to which the message will be published.\n- `message`: The message to publish.\n\n### `subscribe(subject: string, callback: (message: any) => void): Promise<void>`\n\nSubscribes to the specified subject to receive messages.\n\n- `subject`: The subject to subscribe to.\n- `callback`: A function that will be called with each received message.\n\n## Contributing\n\nContributions are welcome! Please open an issue or submit a pull request on GitHub.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.","readmeFilename":"Readme.md"}