New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@thecolvinco/nodejs-messenger

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thecolvinco/nodejs-messenger - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

2

package.json
{
"name": "@thecolvinco/nodejs-messenger",
"description": "Message library for nodejs applications",
"version": "1.1.1",
"version": "1.1.2",
"source": "src/main.ts",

@@ -6,0 +6,0 @@ "main": "dist/main.js",

@@ -15,3 +15,3 @@ # Colvin nodejs async events

### Create a config file with a required structure
You have to create a file with this structure. Later you must to import this file so you can put it in any place. Let's see an example explained
You have to create a file with this structure or a callable which returns this structure (up to you). Later you must to import this file so you can put it in any place. Let's see an example explained

@@ -39,2 +39,3 @@ ```js

delay: 2000,
retryExchangeName: 'blom.superapp.retry.exchange',
},

@@ -60,3 +61,4 @@ },

eventName: 'blom.accounting.1.command.order.syncronize_order', // The event which the built-in command subscribers will subscribe it
handlerPath: 'server/events/orders/command/SyncronizeOrderCommandHandler.js', // The handler which will be invoke passing their Command as argument
handlerFactory: () => new SyncronizeOrderCommandHandler(), // The handler which will be invoke passing their Command as argument
commandPath: 'server/events/orders/command/SendOrderNotificationCommand.js' // The command path
},

@@ -95,43 +97,61 @@ // <--- Other commands goes here

```js
export default class SendOrderNotificationCommand {
constructor({ message }) {
this.message = message;
export default class CreateProductToAlgoliaCommand extends Command {
readonly product: { userId: string; id: string; };
constructor ({ product }) {
super();
this.product = product;
}
getName() {
return 'blom.accounting.1.command.order.send_notification';
getActionName (): string {
return 'create_algolia';
}
getPayload() {
return this.message.data.attributes;
getEntity (): string {
return 'product';
}
getCorrelationId() {
return this.message.data.messageId || null;
static fromPayload ({ message }): CreateProductToAlgoliaCommand {
const { product } = message.data.attributes;
return new CreateProductToAlgoliaCommand({ product });
}
getPayload () {
return {
product: this.product,
};
}
}
```
This is an example for a command handler
```js
export default class SendOrderNotificationCommandHandler {
constructor({ command }) {
this.command = command;
export default class CreateProductToAlgoliaCommandHandler {
// Some constructor with some deps here
async handle (command: CreateProductToAlgoliaCommand) {
const { product } = command;
// Do something here!
}
}
handle() {
console.log('Do something!');
}
}
```
---
### Create your consumers
### Consumers example
```js
import { CommandConsumer } from '@thecolvinco/nodejs-messenger';
import config from 'path-to-your-config';
import eventsConfig from '../../config/events.config.js';
import container from '../container';
const commandConsumer = new CommandConsumer({ config });
const { commandEmitter, logger } = container;
const commandConsumer = new CommandConsumer({ config: eventsConfig({ container }) });
commandConsumer.consume({
transport: 'accounting_commands',
queueName: 'blom.accounting.commands',
emitter: commandEmitter,
prefetchValue: 1,
transport: 'superapp_commands',
queueName: 'blom.superapp.commands',
onError: (error: Error) => logger.error(error.message, { tags: ['commands-consumer'] }),
}).then(() => {

@@ -144,2 +164,3 @@ console.info('Waiting for messages....');

```

@@ -146,0 +167,0 @@ ### About

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc