gemcap-be-common 1.4.249 → 1.4.251

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,7 +19,7 @@ export declare const EVENT_KEYS: {
19
19
  * ========= CRM DOMAIN EVENTS =========
20
20
  */
21
21
  readonly crm: {
22
- readonly PROSPECT_EMAILS_REQUESTED: "crm.prospect.emails.requested";
22
+ readonly PROSPECT_EMAILS_SEND_REQUESTED: "crm.prospect.emails.requested";
23
23
  };
24
24
  /**
25
25
  * ========= FINANCE DOMAIN EVENTS =========
@@ -45,5 +45,8 @@ export declare const EVENT_KEYS: {
45
45
  readonly notifications: {
46
46
  readonly BORROWER_REMINDER_EMAIL_SENT: "notifications.borrower.reminder.email.sent";
47
47
  readonly BORROWER_REMINDER_EMAIL_FAILED: "notifications.borrower.reminder.email.failed";
48
+ readonly EMAIL_SEND_REQUESTED: "notifications.email.send.requested";
49
+ readonly EMAIL_SENT: "notifications.email.sent";
50
+ readonly EMAIL_FAILED: "notifications.email.failed";
48
51
  };
49
52
  };
@@ -22,7 +22,7 @@ exports.EVENT_KEYS = {
22
22
  * ========= CRM DOMAIN EVENTS =========
23
23
  */
24
24
  crm: {
25
- PROSPECT_EMAILS_REQUESTED: 'crm.prospect.emails.requested',
25
+ PROSPECT_EMAILS_SEND_REQUESTED: 'crm.prospect.emails.requested',
26
26
  },
27
27
  /**
28
28
  * ========= FINANCE DOMAIN EVENTS =========
@@ -46,7 +46,10 @@ exports.EVENT_KEYS = {
46
46
  * ========= NOTIFICATIONS DOMAIN EVENTS =========
47
47
  */
48
48
  notifications: {
49
- BORROWER_REMINDER_EMAIL_SENT: 'notifications.borrower.reminder.email.sent',
50
- BORROWER_REMINDER_EMAIL_FAILED: 'notifications.borrower.reminder.email.failed',
49
+ BORROWER_REMINDER_EMAIL_SENT: 'notifications.borrower.reminder.email.sent', // TODO Deprecated
50
+ BORROWER_REMINDER_EMAIL_FAILED: 'notifications.borrower.reminder.email.failed', // TODO Deprecated
51
+ EMAIL_SEND_REQUESTED: 'notifications.email.send.requested',
52
+ EMAIL_SENT: 'notifications.email.sent',
53
+ EMAIL_FAILED: 'notifications.email.failed',
51
54
  }
52
55
  };
@@ -48,7 +48,10 @@ export const EVENT_KEYS = {
48
48
  * ========= NOTIFICATIONS DOMAIN EVENTS =========
49
49
  */
50
50
  notifications: {
51
- BORROWER_REMINDER_EMAIL_SENT: 'notifications.borrower.reminder.email.sent',
52
- BORROWER_REMINDER_EMAIL_FAILED: 'notifications.borrower.reminder.email.failed',
51
+ BORROWER_REMINDER_EMAIL_SENT: 'notifications.borrower.reminder.email.sent', // TODO Deprecated
52
+ BORROWER_REMINDER_EMAIL_FAILED: 'notifications.borrower.reminder.email.failed', // TODO Deprecated
53
+ EMAIL_SEND_REQUESTED: 'notifications.email.send.requested',
54
+ EMAIL_SENT: 'notifications.email.sent',
55
+ EMAIL_FAILED: 'notifications.email.failed',
53
56
  }
54
57
  } as const;
@@ -40,8 +40,12 @@ export declare const QUEUES: {
40
40
  };
41
41
  };
42
42
  readonly notifications: {
43
+ readonly email: {
44
+ readonly sender: "notifications.email.sender";
45
+ };
43
46
  readonly borrowerReminders: {
44
47
  readonly emailSender: "notifications.borrower-reminders.email";
48
+ readonly email: "notifications.borrower-reminders.email";
45
49
  };
46
50
  };
47
51
  };
@@ -43,8 +43,12 @@ exports.QUEUES = {
43
43
  }
44
44
  },
45
45
  notifications: {
46
+ email: {
47
+ sender: 'notifications.email.sender',
48
+ },
46
49
  borrowerReminders: {
47
- emailSender: 'notifications.borrower-reminders.email',
50
+ emailSender: 'notifications.borrower-reminders.email', // TODO Deprecated
51
+ email: 'notifications.borrower-reminders.email', // TODO Deprecated
48
52
  },
49
53
  },
50
54
  };
@@ -40,8 +40,12 @@ export const QUEUES = {
40
40
  }
41
41
  },
42
42
  notifications: {
43
+ email: {
44
+ sender: 'notifications.email.sender',
45
+ },
43
46
  borrowerReminders: {
44
- emailSender: 'notifications.borrower-reminders.email',
47
+ emailSender: 'notifications.borrower-reminders.email', // TODO Deprecated
48
+ email: 'notifications.borrower-reminders.email', // TODO Deprecated
45
49
  },
46
50
  },
47
51
  } as const;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemcap-be-common",
3
- "version": "1.4.249",
3
+ "version": "1.4.251",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,6 @@
1
+ export declare class RabbitService {
2
+ private connection;
3
+ private channel;
4
+ init(): Promise<void>;
5
+ publish(exchange: string, routingKey: string, payload: unknown): Promise<void>;
6
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.RabbitService = void 0;
27
+ const amqp = __importStar(require("amqplib"));
28
+ const { NODE_ENV } = process.env;
29
+ class RabbitService {
30
+ connection = null;
31
+ channel = null;
32
+ async init() {
33
+ const rabbitMQApi = NODE_ENV === 'development' ? 'localhost' : 'rabbitmq';
34
+ this.connection = await amqp.connect(`amqp://${rabbitMQApi}`, { heartbeat: 10 });
35
+ this.connection.on('error', (err) => {
36
+ console.error('RabbitMQ connection error', err);
37
+ });
38
+ this.connection.on('close', () => {
39
+ console.warn('RabbitMQ connection closed. Reconnecting...');
40
+ setTimeout(() => this.init(), 5000);
41
+ });
42
+ this.channel = await this.connection.createChannel();
43
+ console.log('RabbitMQ connected');
44
+ }
45
+ async publish(exchange, routingKey, payload) {
46
+ if (!this.channel) {
47
+ throw new Error('RabbitMQ channel is not initialized');
48
+ }
49
+ this.channel.publish(exchange, routingKey, Buffer.from(JSON.stringify(payload)), { persistent: true });
50
+ }
51
+ }
52
+ exports.RabbitService = RabbitService;
@@ -0,0 +1,40 @@
1
+ import * as amqp from 'amqplib';
2
+
3
+ const { NODE_ENV } = process.env;
4
+
5
+ export class RabbitService {
6
+ private connection: amqp.ChannelModel | null = null;
7
+ private channel: amqp.Channel | null = null;
8
+
9
+ async init() {
10
+ const rabbitMQApi = NODE_ENV === 'development' ? 'localhost' : 'rabbitmq';
11
+
12
+ this.connection = await amqp.connect(`amqp://${rabbitMQApi}`, { heartbeat: 10 });
13
+
14
+ this.connection.on('error', (err) => {
15
+ console.error('RabbitMQ connection error', err);
16
+ });
17
+
18
+ this.connection.on('close', () => {
19
+ console.warn('RabbitMQ connection closed. Reconnecting...');
20
+ setTimeout(() => this.init(), 5000);
21
+ });
22
+
23
+ this.channel = await this.connection.createChannel();
24
+
25
+ console.log('RabbitMQ connected');
26
+ }
27
+
28
+ async publish(exchange: string, routingKey: string, payload: unknown) {
29
+ if (!this.channel) {
30
+ throw new Error('RabbitMQ channel is not initialized');
31
+ }
32
+
33
+ this.channel.publish(
34
+ exchange,
35
+ routingKey,
36
+ Buffer.from(JSON.stringify(payload)),
37
+ { persistent: true },
38
+ );
39
+ }
40
+ }