@solidstarters/solid-core 1.2.146 → 1.2.148

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.
Files changed (122) hide show
  1. package/dist/config/common.config.d.ts +10 -0
  2. package/dist/config/common.config.d.ts.map +1 -1
  3. package/dist/config/common.config.js +5 -0
  4. package/dist/config/common.config.js.map +1 -1
  5. package/dist/index.d.ts +2 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +2 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/interfaces.d.ts +5 -5
  10. package/dist/interfaces.d.ts.map +1 -1
  11. package/dist/interfaces.js.map +1 -1
  12. package/dist/jobs/database/api-email-subscriber-database.service.d.ts +3 -1
  13. package/dist/jobs/database/api-email-subscriber-database.service.d.ts.map +1 -1
  14. package/dist/jobs/database/api-email-subscriber-database.service.js +6 -3
  15. package/dist/jobs/database/api-email-subscriber-database.service.js.map +1 -1
  16. package/dist/jobs/database/computed-field-evaluation-subscriber.service.d.ts +3 -1
  17. package/dist/jobs/database/computed-field-evaluation-subscriber.service.d.ts.map +1 -1
  18. package/dist/jobs/database/computed-field-evaluation-subscriber.service.js +6 -3
  19. package/dist/jobs/database/computed-field-evaluation-subscriber.service.js.map +1 -1
  20. package/dist/jobs/database/generate-code-subscriber-database.service.d.ts +3 -1
  21. package/dist/jobs/database/generate-code-subscriber-database.service.d.ts.map +1 -1
  22. package/dist/jobs/database/generate-code-subscriber-database.service.js +6 -3
  23. package/dist/jobs/database/generate-code-subscriber-database.service.js.map +1 -1
  24. package/dist/jobs/database/otp-subscriber-database.service.d.ts +3 -1
  25. package/dist/jobs/database/otp-subscriber-database.service.d.ts.map +1 -1
  26. package/dist/jobs/database/otp-subscriber-database.service.js +5 -2
  27. package/dist/jobs/database/otp-subscriber-database.service.js.map +1 -1
  28. package/dist/jobs/database/sms-subscriber-database.service.d.ts +4 -2
  29. package/dist/jobs/database/sms-subscriber-database.service.d.ts.map +1 -1
  30. package/dist/jobs/database/sms-subscriber-database.service.js +7 -4
  31. package/dist/jobs/database/sms-subscriber-database.service.js.map +1 -1
  32. package/dist/jobs/database/smtp-email-subscriber-database.service.d.ts +4 -2
  33. package/dist/jobs/database/smtp-email-subscriber-database.service.d.ts.map +1 -1
  34. package/dist/jobs/database/smtp-email-subscriber-database.service.js +6 -3
  35. package/dist/jobs/database/smtp-email-subscriber-database.service.js.map +1 -1
  36. package/dist/jobs/database/test-queue-subscriber-database.service.d.ts +3 -1
  37. package/dist/jobs/database/test-queue-subscriber-database.service.d.ts.map +1 -1
  38. package/dist/jobs/database/test-queue-subscriber-database.service.js +6 -3
  39. package/dist/jobs/database/test-queue-subscriber-database.service.js.map +1 -1
  40. package/dist/jobs/database/trigger-mcp-client-subscriber-database.service.d.ts +3 -1
  41. package/dist/jobs/database/trigger-mcp-client-subscriber-database.service.d.ts.map +1 -1
  42. package/dist/jobs/database/trigger-mcp-client-subscriber-database.service.js +5 -2
  43. package/dist/jobs/database/trigger-mcp-client-subscriber-database.service.js.map +1 -1
  44. package/dist/jobs/database/twilio-sms-publisher-database.service.d.ts +11 -0
  45. package/dist/jobs/database/twilio-sms-publisher-database.service.d.ts.map +1 -0
  46. package/dist/jobs/database/twilio-sms-publisher-database.service.js +39 -0
  47. package/dist/jobs/database/twilio-sms-publisher-database.service.js.map +1 -0
  48. package/dist/jobs/database/twilio-sms-queue-database-options.d.ts +8 -0
  49. package/dist/jobs/database/twilio-sms-queue-database-options.d.ts.map +1 -0
  50. package/dist/jobs/database/twilio-sms-queue-database-options.js +10 -0
  51. package/dist/jobs/database/twilio-sms-queue-database-options.js.map +1 -0
  52. package/dist/jobs/database/twilio-sms-subscriber-database.service.d.ts +17 -0
  53. package/dist/jobs/database/twilio-sms-subscriber-database.service.d.ts.map +1 -0
  54. package/dist/jobs/database/twilio-sms-subscriber-database.service.js +48 -0
  55. package/dist/jobs/database/twilio-sms-subscriber-database.service.js.map +1 -0
  56. package/dist/jobs/database/whatsapp-subscriber-database.service.d.ts +3 -1
  57. package/dist/jobs/database/whatsapp-subscriber-database.service.d.ts.map +1 -1
  58. package/dist/jobs/database/whatsapp-subscriber-database.service.js +6 -3
  59. package/dist/jobs/database/whatsapp-subscriber-database.service.js.map +1 -1
  60. package/dist/jobs/sms-subscriber.service.d.ts +1 -1
  61. package/dist/jobs/sms-subscriber.service.js +1 -1
  62. package/dist/jobs/sms-subscriber.service.js.map +1 -1
  63. package/dist/jobs/smtp-email-subscriber.service.d.ts +1 -1
  64. package/dist/seeders/module-metadata-seeder.service.d.ts +1 -1
  65. package/dist/seeders/module-metadata-seeder.service.d.ts.map +1 -1
  66. package/dist/seeders/module-metadata-seeder.service.js +15 -4
  67. package/dist/seeders/module-metadata-seeder.service.js.map +1 -1
  68. package/dist/services/mail/smtp-email.service.d.ts +4 -4
  69. package/dist/services/mail/smtp-email.service.d.ts.map +1 -1
  70. package/dist/services/mail/smtp-email.service.js +12 -8
  71. package/dist/services/mail/smtp-email.service.js.map +1 -1
  72. package/dist/services/poller.service.d.ts +24 -0
  73. package/dist/services/poller.service.d.ts.map +1 -0
  74. package/dist/services/poller.service.js +131 -0
  75. package/dist/services/poller.service.js.map +1 -0
  76. package/dist/services/queues/database-subscriber.service.d.ts +4 -1
  77. package/dist/services/queues/database-subscriber.service.d.ts.map +1 -1
  78. package/dist/services/queues/database-subscriber.service.js +13 -13
  79. package/dist/services/queues/database-subscriber.service.js.map +1 -1
  80. package/dist/services/sms/Msg91BaseSMSService.d.ts +2 -2
  81. package/dist/services/sms/Msg91BaseSMSService.d.ts.map +1 -1
  82. package/dist/services/sms/Msg91BaseSMSService.js.map +1 -1
  83. package/dist/services/sms/Msg91OTPService.d.ts +1 -1
  84. package/dist/services/sms/Msg91OTPService.d.ts.map +1 -1
  85. package/dist/services/sms/Msg91OTPService.js.map +1 -1
  86. package/dist/services/sms/Msg91SMSService.d.ts +1 -1
  87. package/dist/services/sms/Msg91SMSService.d.ts.map +1 -1
  88. package/dist/services/sms/Msg91SMSService.js.map +1 -1
  89. package/dist/services/sms/TwilioSMSService.d.ts +18 -0
  90. package/dist/services/sms/TwilioSMSService.d.ts.map +1 -0
  91. package/dist/services/sms/TwilioSMSService.js +115 -0
  92. package/dist/services/sms/TwilioSMSService.js.map +1 -0
  93. package/dist/solid-core.module.d.ts.map +1 -1
  94. package/dist/solid-core.module.js +10 -0
  95. package/dist/solid-core.module.js.map +1 -1
  96. package/dist/tsconfig.tsbuildinfo +1 -1
  97. package/package.json +4 -3
  98. package/src/config/common.config.ts +5 -0
  99. package/src/index.ts +2 -0
  100. package/src/interfaces.ts +5 -5
  101. package/src/jobs/database/api-email-subscriber-database.service.ts +3 -1
  102. package/src/jobs/database/computed-field-evaluation-subscriber.service.ts +4 -2
  103. package/src/jobs/database/generate-code-subscriber-database.service.ts +3 -1
  104. package/src/jobs/database/otp-subscriber-database.service.ts +3 -1
  105. package/src/jobs/database/sms-subscriber-database.service.ts +4 -2
  106. package/src/jobs/database/smtp-email-subscriber-database.service.ts +3 -1
  107. package/src/jobs/database/test-queue-subscriber-database.service.ts +3 -1
  108. package/src/jobs/database/trigger-mcp-client-subscriber-database.service.ts +3 -1
  109. package/src/jobs/database/twilio-sms-publisher-database.service.ts +23 -0
  110. package/src/jobs/database/twilio-sms-queue-database-options.ts +9 -0
  111. package/src/jobs/database/twilio-sms-subscriber-database.service.ts +32 -0
  112. package/src/jobs/database/whatsapp-subscriber-database.service.ts +3 -1
  113. package/src/jobs/sms-subscriber.service.ts +1 -1
  114. package/src/seeders/module-metadata-seeder.service.ts +18 -15
  115. package/src/services/mail/smtp-email.service.ts +18 -17
  116. package/src/services/poller.service.ts +163 -0
  117. package/src/services/queues/database-subscriber.service.ts +39 -12
  118. package/src/services/sms/Msg91BaseSMSService.ts +2 -2
  119. package/src/services/sms/Msg91OTPService.ts +1 -1
  120. package/src/services/sms/Msg91SMSService.ts +1 -1
  121. package/src/services/sms/TwilioSMSService.ts +118 -0
  122. package/src/solid-core.module.ts +13 -0
@@ -3,17 +3,20 @@ import { QueuesModuleOptions } from "../../interfaces";
3
3
  import { QueueMessage, QueueSubscriber } from '../../interfaces/mq';
4
4
  import { MqMessageQueueService } from '../mq-message-queue.service';
5
5
  import { MqMessageService } from '../mq-message.service';
6
+ import { PollerService } from '../poller.service';
6
7
  export declare abstract class DatabaseSubscriber<T> implements OnModuleInit, QueueSubscriber<T> {
7
8
  protected readonly mqMessageService: MqMessageService;
8
9
  protected readonly mqMessageQueueService: MqMessageQueueService;
10
+ protected readonly poller: PollerService;
9
11
  private readonly logger;
10
12
  private readonly url;
11
13
  private readonly serviceRole;
12
- constructor(mqMessageService: MqMessageService, mqMessageQueueService: MqMessageQueueService);
14
+ constructor(mqMessageService: MqMessageService, mqMessageQueueService: MqMessageQueueService, poller: PollerService);
13
15
  abstract subscribe(message: QueueMessage<T>): any;
14
16
  abstract options(): QueuesModuleOptions;
15
17
  private processNext;
16
18
  onModuleInit(): Promise<void>;
19
+ onModuleDestroy(): void;
17
20
  protected processMessage(message: QueueMessage<T>): Promise<void>;
18
21
  private retryMessage;
19
22
  private updateStatusInDatabase;
@@ -1 +1 @@
1
- {"version":3,"file":"database-subscriber.service.d.ts","sourceRoot":"","sources":["../../../src/services/queues/database-subscriber.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,8BAAsB,kBAAkB,CAAC,CAAC,CAAE,YAAW,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC;IAM/E,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB;IACrD,SAAS,CAAC,QAAQ,CAAC,qB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,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;gBAGd,gBAAgB,EAAE,gBAAgB,EAClC,qBAAqB,EAAE,qBAAqB,EAC5C,MAAM,EAAE,aAAa;IAS5C,QAAQ,CAAC,SAAS,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC;IAE3C,QAAQ,CAAC,OAAO,IAAI,mBAAmB;YAEzB,WAAW;IAsEnB,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAmBnC,eAAe;cASC,cAAc,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;YAazD,YAAY;YAsBZ,sBAAsB;CAoCvC"}
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DatabaseSubscriber = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  class DatabaseSubscriber {
6
- constructor(mqMessageService, mqMessageQueueService) {
6
+ constructor(mqMessageService, mqMessageQueueService, poller) {
7
7
  this.mqMessageService = mqMessageService;
8
8
  this.mqMessageQueueService = mqMessageQueueService;
9
+ this.poller = poller;
9
10
  this.logger = new common_1.Logger(DatabaseSubscriber.name);
10
11
  this.serviceRole = process.env.QUEUES_SERVICE_ROLE;
11
12
  if (!this.serviceRole) {
@@ -52,21 +53,20 @@ class DatabaseSubscriber {
52
53
  if (['both', 'subscriber'].includes(this.serviceRole)) {
53
54
  const options = this.options();
54
55
  const queueName = options.queueName;
55
- const poll = async () => {
56
- try {
57
- await this.processNext(queueName);
58
- }
59
- catch (err) {
60
- this.logger.error(`Polling error: ${err.message}`);
61
- }
62
- finally {
63
- setTimeout(poll, 1000);
64
- }
65
- };
66
- poll();
56
+ this.poller.start(queueName, (q) => this.processNext(q), {
57
+ baseDelayMs: 1000,
58
+ maxDelayMs: 30_000,
59
+ timeoutPerIterationMs: 60_000,
60
+ jitter: true,
61
+ });
67
62
  this.logger.log(`DatabaseSubscriber ready to consume messages: ${JSON.stringify(this.options())}`);
68
63
  }
69
64
  }
65
+ onModuleDestroy() {
66
+ const options = this.options();
67
+ const queueName = options.queueName;
68
+ this.poller.stop(queueName);
69
+ }
70
70
  async processMessage(message) {
71
71
  await this.updateStatusInDatabase('started', message);
72
72
  const result = await this.subscribe(message);
@@ -1 +1 @@
1
- {"version":3,"file":"database-subscriber.service.js","sourceRoot":"","sources":["../../../src/services/queues/database-subscriber.service.ts"],"names":[],"mappings":";;;AAAA,2CAAsD;AAOtD,MAAsB,kBAAkB;IAKpC,YACuB,gBAAkC,EAClC,qBAA4C;QAD5C,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,0BAAqB,GAArB,qBAAqB,CAAuB;QANlD,WAAM,GAAG,IAAI,eAAM,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAQ1D,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;QACnD,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gEAAgE,CAAC,CAAC;QACxF,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,qDAAqD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;IAC7G,CAAC;IAMO,KAAK,CAAC,WAAW,CAAC,SAAiB;QAEvC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC;QAC1E,IAAI,CAAC,GAAG,EAAE,CAAC;YACP,OAAO;QACX,CAAC;QAED,MAAM,oBAAoB,GAAG,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QAGlD,IAAI,OAAO,GAAoB,IAAI,CAAC;QAEpC,IAAI,CAAC;YACD,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAoB,CAAC;YAG9D,IAAI,C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CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;gBACvF,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wCAAwC,KAAK,mBAAmB,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC;gBAElG,MAAM,aAAa,GAAG;oBAClB,KAAK,EAAE,KAAK;iBACf,CAAC;gBACF,IAAI,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,WAAW,EAAE,CAAC;oBAC9C,aAAa,CAAC,YAAY,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;oBACzC,aAAa,CAAC,eAAe,CAAC,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,GAAG,SAAS,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;gBAC3G,CAAC;gBACD,IAAI,KAAK,KAAK,WAAW,EAAE,CAAC;oBACxB,aAAa,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC;gBACrC,CAAC;gBACD,IAAI,KAAK,KAAK,QAAQ,EAAE,CAAC;oBACrB,aAAa,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC;gBACnC,CAAC;gBACD,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,EAAE,aAAa,CAAC,CAAC;gBACrE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,KAAK,mBAAmB,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC;YAC3F,CAAC;QACL,CAAC;QACD,OAAO,KAAK,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QAClD,CAAC;IACL,CAAC;CACJ;AApKD,gDAoKC","sourcesContent":["import { Logger, OnModuleInit } from '@nestjs/common';\nimport { QueuesModuleOptions } from \"../../interfaces\";\nimport { QueueMessage, QueueSubscriber } from '../../interfaces/mq';\nimport { MqMessageQueueService } from '../mq-message-queue.service';\nimport { MqMessageService } from '../mq-message.service';\n\n\nexport abstract class DatabaseSubscriber<T> implements OnModuleInit, QueueSubscriber<T> {\n private readonly logger = new Logger(DatabaseSubscriber.name);\n private readonly url: string;\n private readonly serviceRole: string;\n\n constructor(\n protected readonly mqMessageService: MqMessageService,\n protected readonly mqMessageQueueService: MqMessageQueueService,\n ) {\n this.serviceRole = process.env.QUEUES_SERVICE_ROLE;\n if (!this.serviceRole) {\n this.logger.debug('Queue service Role is not defined in the environment variables');\n }\n this.logger.debug(`DatabaseSubscriber instance created with options: ${JSON.stringify(this.options())}`);\n }\n\n abstract subscribe(message: QueueMessage<T>);\n\n abstract options(): QueuesModuleOptions;\n\n private async processNext(queueName: string) {\n // this.logger.debug(`#### DatabaseSubscriber processing next message from queue: ${queueName}`);\n const job = await this.mqMessageService.lockNextPendingMessage(queueName);\n if (!job) {\n return;\n }\n\n const messageContentString = job.input.toString();\n // this.logger.debug(`DatabaseSubscriber Received raw message: ${messageContentString}`);\n\n let message: QueueMessage<T> = null;\n\n try {\n message = JSON.parse(messageContentString) as QueueMessage<T>;\n\n // this is the first time we are receiving the message so we set the currentRetry to 0\n if (!message.retryCount) message.retryCount = 0;\n if (!message.retryInterval) message.retryInterval = 1000;\n if (!message.currentRetry) message.currentRetry = 0;\n\n await this.processMessage(message);\n }\n catch (error) {\n this.logger.error(`Error processing message: ${error.message}`);\n\n // if an error occurs then if retryCount is set we start retrying. \n if (message) {\n if (message.currentRetry < message.retryCount) {\n await this.updateStatusInDatabase('retrying', message);\n\n message.currentRetry++;\n this.logger.warn(`Retrying message (${message.currentRetry}/${message.retryCount}) after ${message.retryInterval}ms`);\n setTimeout(() => {\n this.retryMessage(message);\n }, message.retryInterval);\n } else {\n // Discard the message after max retries\n await this.updateStatusInDatabase('failed', message, error.message, '');\n this.logger.error(`Message failed after ${message.retryCount} attempts: ${error.message}`);\n }\n }\n }\n // this.logger.debug(`#### DatabaseSubscriber finished processing message from queue: ${queueName}`);\n }\n\n async onModuleInit(): Promise<void> {\n // we will start subscriber only if the current service role is subscriber. \n if (['both', 'subscriber'].includes(this.serviceRole)) {\n\n const options = this.options();\n\n const queueName = options.queueName;\n // setInterval(() => this.processNext(queueName), 1000);\n const poll = async () => {\n try {\n await this.processNext(queueName);\n } catch (err) {\n this.logger.error(`Polling error: ${err.message}`);\n } finally {\n setTimeout(poll, 1000); // Wait 1s *after* processing finishes\n }\n };\n\n // start the loop\n poll();\n\n this.logger.log(`DatabaseSubscriber ready to consume messages: ${JSON.stringify(this.options())}`);\n }\n }\n\n /**\n * Abstract method for message processing logic.\n */\n protected async processMessage(message: QueueMessage<T>): Promise<void> {\n await this.updateStatusInDatabase('started', message);\n\n // Capture the results of handling the task.\n const result = await this.subscribe(message);\n\n // TODO: Update the database to indicate that the task is finished.\n await this.updateStatusInDatabase('succeeded', message, '', result ? JSON.stringify(result, null, 2) : '');\n }\n\n /**\n * Retry the message by invoking the processing logic again.\n */\n private async retryMessage(message: QueueMessage<T>) {\n try {\n await this.processMessage(message);\n } catch (error) {\n if (message.currentRetry < message.retryCount) {\n await this.updateStatusInDatabase('retrying', message);\n\n message.currentRetry++;\n this.logger.warn(`Retrying message (${message.currentRetry}/${message.retryCount}) after ${message.retryInterval}ms: ${error.message}`);\n setTimeout(() => {\n this.retryMessage(message);\n }, message.retryInterval);\n } else {\n this.logger.error(`Message failed after ${message.retryCount} attempts: ${error.message}`);\n\n // TODO: Store the error in the database and update the status accordingly.\n await this.updateStatusInDatabase('failed', message, error.message, '');\n\n }\n }\n }\n\n private async updateStatusInDatabase(stage: string, message: QueueMessage<T>, error: string = '', result: string = '') {\n try {\n this.logger.debug(`Updating message status in database: ${stage} for messageId: ${message.messageId}`);\n\n // 1. resolve the queue first\n const mqMessage = await this.mqMessageService.repo.findOne({\n where: {\n messageId: message.messageId,\n }\n });\n\n if (mqMessage) {\n this.logger.debug(`Found message in database: ${JSON.stringify(mqMessage.messageId)}`);\n this.logger.debug(`Updating message status in database: ${stage} for messageId: ${mqMessage.id}`);\n\n const updatedFields = {\n stage: stage\n };\n if (stage === 'failed' || stage === 'succeeded') {\n updatedFields['finishedAt'] = new Date();\n updatedFields['elapsedMillis'] = updatedFields['finishedAt'].getTime() - mqMessage.startedAt.getTime();\n }\n if (stage === 'succeeded') {\n updatedFields['output'] = result;\n }\n if (stage === 'failed') {\n updatedFields['error'] = error;\n }\n await this.mqMessageService.repo.update(mqMessage.id, updatedFields);\n this.logger.debug(`Message status updated to ${stage} for messageId: ${mqMessage.id}`);\n }\n }\n catch (error) {\n this.logger.error(error.message, error.stack);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"database-subscriber.service.js","sourceRoot":"","sources":["../../../src/services/queues/database-subscriber.service.ts"],"names":[],"mappings":";;;AAAA,2CAAsD;AAQtD,MAAsB,kBAAkB;IAKpC,YACuB,gBAAkC,EAClC,qBAA4C,EAC5C,MAAqB;QAFrB,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,WAAM,GAAN,MAAM,CAAe;QAP3B,WAAM,GAAG,IAAI,eAAM,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAS1D,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;QACnD,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gEAAgE,CAAC,CAAC;QACxF,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,qDAAqD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;IAC7G,CAAC;IAMO,KAAK,CAAC,WAAW,CAAC,SAAiB;QAEvC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC;QAC1E,IAAI,CAAC,GAAG,EAAE,CAAC;YACP,OAAO;QACX,CAAC;QA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,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QAClD,CAAC;IACL,CAAC;CACJ;AA9LD,gDA8LC","sourcesContent":["import { Logger, OnModuleInit } from '@nestjs/common';\nimport { QueuesModuleOptions } from \"../../interfaces\";\nimport { QueueMessage, QueueSubscriber } from '../../interfaces/mq';\nimport { MqMessageQueueService } from '../mq-message-queue.service';\nimport { MqMessageService } from '../mq-message.service';\nimport { PollerService } from '../poller.service';\n\n\nexport abstract class DatabaseSubscriber<T> implements OnModuleInit, QueueSubscriber<T> {\n private readonly logger = new Logger(DatabaseSubscriber.name);\n private readonly url: string;\n private readonly serviceRole: string;\n\n constructor(\n protected readonly mqMessageService: MqMessageService,\n protected readonly mqMessageQueueService: MqMessageQueueService,\n protected readonly poller: PollerService,\n ) {\n this.serviceRole = process.env.QUEUES_SERVICE_ROLE;\n if (!this.serviceRole) {\n this.logger.debug('Queue service Role is not defined in the environment variables');\n }\n this.logger.debug(`DatabaseSubscriber instance created with options: ${JSON.stringify(this.options())}`);\n }\n\n abstract subscribe(message: QueueMessage<T>);\n\n abstract options(): QueuesModuleOptions;\n\n private async processNext(queueName: string) {\n // this.logger.debug(`#### DatabaseSubscriber processing next message from queue: ${queueName}`);\n const job = await this.mqMessageService.lockNextPendingMessage(queueName);\n if (!job) {\n return;\n }\n\n const messageContentString = job.input.toString();\n // this.logger.debug(`DatabaseSubscriber Received raw message: ${messageContentString}`);\n\n let message: QueueMessage<T> = null;\n\n try {\n message = JSON.parse(messageContentString) as QueueMessage<T>;\n\n // this is the first time we are receiving the message so we set the currentRetry to 0\n if (!message.retryCount) message.retryCount = 0;\n if (!message.retryInterval) message.retryInterval = 1000;\n if (!message.currentRetry) message.currentRetry = 0;\n\n await this.processMessage(message);\n }\n catch (error) {\n this.logger.error(`Error processing message: ${error.message}`);\n\n // if an error occurs then if retryCount is set we start retrying. \n if (message) {\n if (message.currentRetry < message.retryCount) {\n await this.updateStatusInDatabase('retrying', message);\n\n message.currentRetry++;\n this.logger.warn(`Retrying message (${message.currentRetry}/${message.retryCount}) after ${message.retryInterval}ms`);\n setTimeout(() => {\n this.retryMessage(message);\n }, message.retryInterval);\n } else {\n // Discard the message after max retries\n await this.updateStatusInDatabase('failed', message, error.message, '');\n this.logger.error(`Message failed after ${message.retryCount} attempts: ${error.message}`);\n }\n }\n }\n // this.logger.debug(`#### DatabaseSubscriber finished processing message from queue: ${queueName}`);\n }\n\n // async onModuleInit(): Promise<void> {\n // // we will start subscriber only if the current service role is subscriber. \n // if (['both', 'subscriber'].includes(this.serviceRole)) {\n\n // const options = this.options();\n\n // const queueName = options.queueName;\n // // setInterval(() => this.processNext(queueName), 1000);\n // const poll = async () => {\n // try {\n // await this.processNext(queueName);\n // } catch (err) {\n // this.logger.error(`Polling error: ${err.message}`);\n // } finally {\n // setTimeout(poll, 1000); // Wait 1s *after* processing finishes\n // }\n // };\n\n // // start the loop\n // poll();\n\n // this.logger.log(`DatabaseSubscriber ready to consume messages: ${JSON.stringify(this.options())}`);\n // }\n // }\n\n async onModuleInit(): Promise<void> {\n // we will start subscriber only if the current service role is subscriber. \n if (['both', 'subscriber'].includes(this.serviceRole)) {\n\n const options = this.options();\n\n const queueName = options.queueName;\n\n this.poller.start(queueName, (q) => this.processNext(q), {\n baseDelayMs: 1000,\n maxDelayMs: 30_000,\n timeoutPerIterationMs: 60_000,\n jitter: true,\n });\n\n this.logger.log(`DatabaseSubscriber ready to consume messages: ${JSON.stringify(this.options())}`);\n }\n }\n\n onModuleDestroy() {\n const options = this.options();\n const queueName = options.queueName;\n this.poller.stop(queueName);\n }\n\n /**\n * Abstract method for message processing logic.\n */\n protected async processMessage(message: QueueMessage<T>): Promise<void> {\n await this.updateStatusInDatabase('started', message);\n\n // Capture the results of handling the task.\n const result = await this.subscribe(message);\n\n // TODO: Update the database to indicate that the task is finished.\n await this.updateStatusInDatabase('succeeded', message, '', result ? JSON.stringify(result, null, 2) : '');\n }\n\n /**\n * Retry the message by invoking the processing logic again.\n */\n private async retryMessage(message: QueueMessage<T>) {\n try {\n await this.processMessage(message);\n } catch (error) {\n if (message.currentRetry < message.retryCount) {\n await this.updateStatusInDatabase('retrying', message);\n\n message.currentRetry++;\n this.logger.warn(`Retrying message (${message.currentRetry}/${message.retryCount}) after ${message.retryInterval}ms: ${error.message}`);\n setTimeout(() => {\n this.retryMessage(message);\n }, message.retryInterval);\n } else {\n this.logger.error(`Message failed after ${message.retryCount} attempts: ${error.message}`);\n\n // TODO: Store the error in the database and update the status accordingly.\n await this.updateStatusInDatabase('failed', message, error.message, '');\n\n }\n }\n }\n\n private async updateStatusInDatabase(stage: string, message: QueueMessage<T>, error: string = '', result: string = '') {\n try {\n this.logger.debug(`Updating message status in database: ${stage} for messageId: ${message.messageId}`);\n\n // 1. resolve the queue first\n const mqMessage = await this.mqMessageService.repo.findOne({\n where: {\n messageId: message.messageId,\n }\n });\n\n if (mqMessage) {\n this.logger.debug(`Found message in database: ${JSON.stringify(mqMessage.messageId)}`);\n this.logger.debug(`Updating message status in database: ${stage} for messageId: ${mqMessage.id}`);\n\n const updatedFields = {\n stage: stage\n };\n if (stage === 'failed' || stage === 'succeeded') {\n updatedFields['finishedAt'] = new Date();\n updatedFields['elapsedMillis'] = updatedFields['finishedAt'].getTime() - mqMessage.startedAt.getTime();\n }\n if (stage === 'succeeded') {\n updatedFields['output'] = result;\n }\n if (stage === 'failed') {\n updatedFields['error'] = error;\n }\n await this.mqMessageService.repo.update(mqMessage.id, updatedFields);\n this.logger.debug(`Message status updated to ${stage} for messageId: ${mqMessage.id}`);\n }\n }\n catch (error) {\n this.logger.error(error.message, error.stack);\n }\n }\n}\n"]}
@@ -13,8 +13,8 @@ export declare abstract class Msg91BaseSMSService implements ISMS {
13
13
  protected readonly logger: Logger;
14
14
  constructor(commonConfiguration: ConfigType<typeof commonConfig>, smsPublisher: string, publisherFactory: PublisherFactory<any>, smsTemplateService: SmsTemplateService);
15
15
  sendSMS(_to: string, _body: string, _shouldQueueSms: boolean): Promise<void>;
16
- sendSMSUsingTemplate(to: string, templateName: string, templateParams: any, shouldQueueSms?: boolean): Promise<void>;
16
+ sendSMSUsingTemplate(to: string, templateName: string, templateParams: any, shouldQueueSms?: boolean): Promise<any>;
17
17
  sendSMSAsynchronously(message: any): Promise<void>;
18
- abstract sendSMSSynchronously(message: QueueMessage<any>): Promise<void>;
18
+ abstract sendSMSSynchronously(message: QueueMessage<any>): Promise<any>;
19
19
  }
20
20
  //# sourceMappingURL=Msg91BaseSMSService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Msg91BaseSMSService.d.ts","sourceRoot":"","sources":["../../../src/services/sms/Msg91BaseSMSService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,YAAY,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAEvE,8BAAsB,mBAAoB,YAAW,IAAI;IAGjD,SAAS,CAAC,QAAQ,CAAC,mBAAmB,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC;IACvE,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,MAAM;IACvC,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,GAAG,CAAC;IAC1D,SAAS,CAAC,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB;IAL7D,SAAS,CAAC,QAAQ,CAAC,MAAM,SAAwC;gBAE1C,mBAAmB,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,EACpD,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,gBAAgB,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,OAAO,CAAC;QAG/B,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC1D,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,iBAAiB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACvF,CAAC;CAGJ;AAtED,kDAsEC","sourcesContent":["import { Logger } from \"@nestjs/common\";\nimport { ConfigType } from \"@nestjs/config\";\nimport Handlebars from \"handlebars\";\nimport commonConfig from \"src/config/common.config\";\nimport { QueueMessage } from \"src/interfaces/mq\";\nimport { SmsTemplateService } from \"../sms-template.service\";\nimport { ISMS } from \"../../interfaces\";\nimport { PublisherFactory } from \"../queues/publisher-factory.service\";\n\nexport abstract class Msg91BaseSMSService implements ISMS {\n protected readonly logger = new Logger(Msg91BaseSMSService.name);\n constructor(\n protected readonly commonConfiguration: ConfigType<typeof commonConfig>,\n protected readonly smsPublisher: string,\n protected readonly publisherFactory: PublisherFactory<any>,\n protected readonly smsTemplateService: SmsTemplateService,\n ) { }\n\n sendSMS(_to: string, _body: string, _shouldQueueSms: boolean): Promise<void> {\n throw new Error(`Msg91 does not support sending plain text messages, you need to register a template and use the templateId to send the SMS.`);\n }\n\n async sendSMSUsingTemplate(to: string, templateName: string, templateParams: any, shouldQueueSms = false): Promise<void> {\n // Load template and evaluate it. \n const emailTemplate = await this.smsTemplateService.findOneByName(templateName);\n if (!emailTemplate) {\n throw new Error(`Invalid template name ${templateName}`);\n }\n\n // Evaluate the body template.\n let body = null;\n let templateId = null;\n\n // The below code is only for reference, msh91 maintains the SMS templates in their database, and we need to only specify the templateId. \n // The below was designed assuming that there are certain sms gateways who do not work this way.\n if (emailTemplate.body) {\n const bodyTemplate = Handlebars.compile(emailTemplate.body);\n body = bodyTemplate(templateParams);\n }\n if (emailTemplate.smsProviderTemplateId) {\n templateId = emailTemplate.smsProviderTemplateId;\n }\n if (!body && !templateId) {\n throw new Error(`Invalid template, neither body nor templateId specified on template with name ${templateName}`);\n }\n\n const message = {\n payload: {\n ...templateParams,\n to: to,\n templateId: templateId,\n },\n // parentEntity: 'Address', //FIXME Need to dynamically set this\n // parentEntityId: 23, //FIXME Need to dynamically set this\n };\n\n // Send using queue if the developer has explicitly invoked with true.\n if (shouldQueueSms === true) {\n await this.sendSMSAsynchronously(message);\n }\n // If developer has not, however system config mandates that we send using queue, still we send.\n else if (shouldQueueSms === false && this.commonConfiguration.shouldQueueSms === true) {\n await this.sendSMSAsynchronously(message);\n }\n // Else we send synch\n else {\n await this.sendSMSSynchronously(message);\n }\n }\n\n async sendSMSAsynchronously(message) {\n const { to } = message.payload;\n // this.notificationPublisherService.publish(message);\n // this.smsPublisher.publish(message);\n this.publisherFactory.publish(message, this.smsPublisher);\n this.logger.debug(`Queueing SMS to ${to} with message ${JSON.stringify(message)}`);\n }\n\n abstract sendSMSSynchronously(message: QueueMessage<any>): Promise<void>\n}"]}
1
+ {"version":3,"file":"Msg91BaseSMSService.js","sourceRoot":"","sources":["../../../src/services/sms/Msg91BaseSMSService.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAwC;AAExC,4DAAoC;AAOpC,MAAsB,mBAAmB;IAErC,YACuB,mBAAoD,EACpD,YAAoB,EACpB,gBAAuC,EACvC,kBAAsC;QAHtC,wBAAmB,GAAnB,mBAAmB,CAAiC;QACpD,iBAAY,GAAZ,YAAY,CAAQ;QACpB,qBAAgB,GAAhB,gBAAgB,CAAuB;QACvC,uBAAkB,GAAlB,kBAAkB,CAAoB;QAL1C,WAAM,GAAG,IAAI,eAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAM7D,CAAC;IAEL,OAAO,CAAC,GAAW,EAAE,KAAa,EAAE,eAAwB;QACxD,MAAM,IAAI,KAAK,CAAC,6HAA6H,CAAC,CAAC;IACnJ,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAC,EAAU,EAAE,YAAoB,EAAE,cAAmB,EAAE,c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AC/B,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;QAG/B,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC1D,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,iBAAiB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACvF,CAAC;CAGJ;AAtED,kDAsEC","sourcesContent":["import { Logger } from \"@nestjs/common\";\nimport { ConfigType } from \"@nestjs/config\";\nimport Handlebars from \"handlebars\";\nimport commonConfig from \"src/config/common.config\";\nimport { QueueMessage } from \"src/interfaces/mq\";\nimport { SmsTemplateService } from \"../sms-template.service\";\nimport { ISMS } from \"../../interfaces\";\nimport { PublisherFactory } from \"../queues/publisher-factory.service\";\n\nexport abstract class Msg91BaseSMSService implements ISMS {\n protected readonly logger = new Logger(Msg91BaseSMSService.name);\n constructor(\n protected readonly commonConfiguration: ConfigType<typeof commonConfig>,\n protected readonly smsPublisher: string,\n protected readonly publisherFactory: PublisherFactory<any>,\n protected readonly smsTemplateService: SmsTemplateService,\n ) { }\n\n sendSMS(_to: string, _body: string, _shouldQueueSms: boolean): Promise<void> {\n throw new Error(`Msg91 does not support sending plain text messages, you need to register a template and use the templateId to send the SMS.`);\n }\n\n async sendSMSUsingTemplate(to: string, templateName: string, templateParams: any, shouldQueueSms = false): Promise<any> {\n // Load template and evaluate it. \n const emailTemplate = await this.smsTemplateService.findOneByName(templateName);\n if (!emailTemplate) {\n throw new Error(`Invalid template name ${templateName}`);\n }\n\n // Evaluate the body template.\n let body = null;\n let templateId = null;\n\n // The below code is only for reference, msh91 maintains the SMS templates in their database, and we need to only specify the templateId. \n // The below was designed assuming that there are certain sms gateways who do not work this way.\n if (emailTemplate.body) {\n const bodyTemplate = Handlebars.compile(emailTemplate.body);\n body = bodyTemplate(templateParams);\n }\n if (emailTemplate.smsProviderTemplateId) {\n templateId = emailTemplate.smsProviderTemplateId;\n }\n if (!body && !templateId) {\n throw new Error(`Invalid template, neither body nor templateId specified on template with name ${templateName}`);\n }\n\n const message = {\n payload: {\n ...templateParams,\n to: to,\n templateId: templateId,\n },\n // parentEntity: 'Address', //FIXME Need to dynamically set this\n // parentEntityId: 23, //FIXME Need to dynamically set this\n };\n\n // Send using queue if the developer has explicitly invoked with true.\n if (shouldQueueSms === true) {\n await this.sendSMSAsynchronously(message);\n }\n // If developer has not, however system config mandates that we send using queue, still we send.\n else if (shouldQueueSms === false && this.commonConfiguration.shouldQueueSms === true) {\n await this.sendSMSAsynchronously(message);\n }\n // Else we send synch\n else {\n await this.sendSMSSynchronously(message);\n }\n }\n\n async sendSMSAsynchronously(message) {\n const { to } = message.payload;\n // this.notificationPublisherService.publish(message);\n // this.smsPublisher.publish(message);\n this.publisherFactory.publish(message, this.smsPublisher);\n this.logger.debug(`Queueing SMS to ${to} with message ${JSON.stringify(message)}`);\n }\n\n abstract sendSMSSynchronously(message: QueueMessage<any>): Promise<any>\n}"]}
@@ -9,7 +9,7 @@ import { PublisherFactory } from "../queues/publisher-factory.service";
9
9
  export declare class Msg91OTPService extends Msg91BaseSMSService implements ISMS {
10
10
  private readonly httpService;
11
11
  constructor(commonConfiguration: ConfigType<typeof commonConfig>, publisherFactory: PublisherFactory<any>, smsTemplateService: SmsTemplateService, httpService: HttpService);
12
- sendSMSSynchronously(message: QueueMessage<any>): Promise<void>;
12
+ sendSMSSynchronously(message: QueueMessage<any>): Promise<any>;
13
13
  private paramsToQueryString;
14
14
  }
15
15
  //# sourceMappingURL=Msg91OTPService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Msg91OTPService.d.ts","sourceRoot":"","sources":["../../../src/services/sms/Msg91OTPService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,YAAY,MA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C,CAAC;QACjD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,kBAAkB,EAAE,aAAa,MAAM,EAAE,CAAC,CAAC;IACjE,CAAC;IAEO,mBAAmB,CAAC,MAAiB;QACzC,MAAM,OAAO,GAAa,EAAE,CAAA;QAC5B,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACrC,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;YAC1B,OAAO,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,kBAAkB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAA;QAC7D,CAAC;QACD,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC7B,OAAO,EAAE,CAAC;IACd,CAAC;CACJ,CAAA;AA7BY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;IAGJ,WAAA,IAAA,eAAM,EAAC,uBAAY,CAAC,GAAG,CAAC,CAAA;6CAGP,4CAAgB;QACd,yCAAkB;QACR,mBAAW;GAPpC,eAAe,CA6B3B","sourcesContent":["import { HttpService } from \"@nestjs/axios\";\nimport { Inject, Injectable } from \"@nestjs/common\";\nimport { ConfigType } from \"@nestjs/config\";\nimport commonConfig from \"src/config/common.config\";\nimport { QueueMessage } from \"src/interfaces/mq\";\nimport { SmsTemplateService } from \"../sms-template.service\";\nimport { Msg91BaseSMSService } from \"./Msg91BaseSMSService\";\nimport { ISMS } from \"../../interfaces\";\nimport { PublisherFactory } from \"../queues/publisher-factory.service\";\n\ninterface OtpParams {\n otp: string,\n template_id: string,\n mobile: string,\n authkey: string\n}\n\n@Injectable()\nexport class Msg91OTPService extends Msg91BaseSMSService implements ISMS {\n constructor(\n @Inject(commonConfig.KEY)\n commonConfiguration: ConfigType<typeof commonConfig>,\n // smsPublisher: OTPQueuePublisher,\n publisherFactory: PublisherFactory<any>,\n smsTemplateService: SmsTemplateService,\n private readonly httpService: HttpService,\n ) {\n super(commonConfiguration, 'OTPQueuePublisher', publisherFactory, smsTemplateService);\n }\n\n async sendSMSSynchronously(message: QueueMessage<any>): Promise<void> {\n const { to, templateId, otp } = message.payload;\n const params = { otp, template_id: templateId, mobile: to, authkey: this.commonConfiguration.msg91Sms.apiKey }\n const otpUrl = `${this.commonConfiguration.msg91Sms.url}/otp?${this.paramsToQueryString(params)}`;\n await this.httpService.axiosRef.post(otpUrl, {});\n this.logger.debug(`Sending OTP to ${to} with url ${otpUrl}`);\n }\n\n private paramsToQueryString(params: OtpParams): string {\n const qsArray: string[] = []\n const paramKeys = Object.keys(params)\n for (const key of paramKeys) {\n qsArray.push(`${key}=${encodeURIComponent(params[key])}`)\n }\n const qs = qsArray.join(\"&\");\n return qs;\n }\n}"]}
1
+ {"version":3,"file":"Msg91OTPService.js","sourceRoot":"","sources":["../../../src/services/sms/Msg91OTPService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,yCAA4C;AAC5C,2CAAoD;AAEpD,+EAAoD;AAEpD,kEAA6D;AAC7D,+DAA4D;AAE5D,mFAAuE;AAUhE,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,yCAAmB;IACpD,YAEI,mBAAoD,EAEpD,gBAAuC,EACvC,kBAAsC,EACrB,WAAwB;QAEzC,KAAK,CAAC,mBAAmB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;QAFrE,gBAAW,GAAX,WAAW,CAAa;IAG7C,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAC,OAA0B;QACjD,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;QAChD,MAAM,MAAM,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAA;QAC9G,MAAM,MAAM,GAAG,GAAG,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,GAAG,QAAQ,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE,CAAC;QAClG,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,kBAAkB,EAAE,aAAa,MAAM,EAAE,CAAC,CAAC;IACjE,CAAC;IAEO,mBAAmB,CAAC,MAAiB;QACzC,MAAM,OAAO,GAAa,EAAE,CAAA;QAC5B,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACrC,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;YAC1B,OAAO,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,kBAAkB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAA;QAC7D,CAAC;QACD,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC7B,OAAO,EAAE,CAAC;IACd,CAAC;CACJ,CAAA;AA7BY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;IAGJ,WAAA,IAAA,eAAM,EAAC,uBAAY,CAAC,GAAG,CAAC,CAAA;6CAGP,4CAAgB;QACd,yCAAkB;QACR,mBAAW;GAPpC,eAAe,CA6B3B","sourcesContent":["import { HttpService } from \"@nestjs/axios\";\nimport { Inject, Injectable } from \"@nestjs/common\";\nimport { ConfigType } from \"@nestjs/config\";\nimport commonConfig from \"src/config/common.config\";\nimport { QueueMessage } from \"src/interfaces/mq\";\nimport { SmsTemplateService } from \"../sms-template.service\";\nimport { Msg91BaseSMSService } from \"./Msg91BaseSMSService\";\nimport { ISMS } from \"../../interfaces\";\nimport { PublisherFactory } from \"../queues/publisher-factory.service\";\n\ninterface OtpParams {\n otp: string,\n template_id: string,\n mobile: string,\n authkey: string\n}\n\n@Injectable()\nexport class Msg91OTPService extends Msg91BaseSMSService implements ISMS {\n constructor(\n @Inject(commonConfig.KEY)\n commonConfiguration: ConfigType<typeof commonConfig>,\n // smsPublisher: OTPQueuePublisher,\n publisherFactory: PublisherFactory<any>,\n smsTemplateService: SmsTemplateService,\n private readonly httpService: HttpService,\n ) {\n super(commonConfiguration, 'OTPQueuePublisher', publisherFactory, smsTemplateService);\n }\n\n async sendSMSSynchronously(message: QueueMessage<any>): Promise<any> {\n const { to, templateId, otp } = message.payload;\n const params = { otp, template_id: templateId, mobile: to, authkey: this.commonConfiguration.msg91Sms.apiKey }\n const otpUrl = `${this.commonConfiguration.msg91Sms.url}/otp?${this.paramsToQueryString(params)}`;\n await this.httpService.axiosRef.post(otpUrl, {});\n this.logger.debug(`Sending OTP to ${to} with url ${otpUrl}`);\n }\n\n private paramsToQueryString(params: OtpParams): string {\n const qsArray: string[] = []\n const paramKeys = Object.keys(params)\n for (const key of paramKeys) {\n qsArray.push(`${key}=${encodeURIComponent(params[key])}`)\n }\n const qs = qsArray.join(\"&\");\n return qs;\n }\n}"]}
@@ -9,6 +9,6 @@ import { PublisherFactory } from "../queues/publisher-factory.service";
9
9
  export declare class Msg91SMSService extends Msg91BaseSMSService implements ISMS {
10
10
  private readonly httpService;
11
11
  constructor(commonConfiguration: ConfigType<typeof commonConfig>, publisherFactory: PublisherFactory<any>, smsTemplateService: SmsTemplateService, httpService: HttpService);
12
- sendSMSSynchronously(message: QueueMessage<any>): Promise<void>;
12
+ sendSMSSynchronously(message: QueueMessage<any>): Promise<any>;
13
13
  }
14
14
  //# sourceMappingURL=Msg91SMSService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Msg91SMSService.d.ts","sourceRoot":"","sources":["../../../src/services/sms/Msg91SMSService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB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EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QACzG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,kBAAkB,EAAE,cAAc,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,gBAAgB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACvH,CAAC;CACJ,CAAA;AAnBY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;IAGJ,WAAA,IAAA,eAAM,EAAC,uBAAY,CAAC,GAAG,CAAC,CAAA;6CAGP,4CAAgB;QACd,yCAAkB;QACR,mBAAW;GAPpC,eAAe,CAmB3B","sourcesContent":["import { HttpService } from \"@nestjs/axios\";\nimport { Inject, Injectable } from \"@nestjs/common\";\nimport { ConfigType } from \"@nestjs/config\";\nimport commonConfig from \"src/config/common.config\";\nimport { QueueMessage } from \"src/interfaces/mq\";\nimport { SmsTemplateService } from \"../sms-template.service\";\nimport { Msg91BaseSMSService } from \"./Msg91BaseSMSService\";\nimport { ISMS } from \"../../interfaces\";\nimport { PublisherFactory } from \"../queues/publisher-factory.service\";\n\n@Injectable()\nexport class Msg91SMSService extends Msg91BaseSMSService implements ISMS {\n constructor(\n @Inject(commonConfig.KEY)\n commonConfiguration: ConfigType<typeof commonConfig>,\n // smsPublisher: SmsQueuePublisher,\n publisherFactory: PublisherFactory<any>,\n smsTemplateService: SmsTemplateService,\n private readonly httpService: HttpService,\n ) {\n super(commonConfiguration, 'SmsQueuePublisher', publisherFactory, smsTemplateService)\n }\n\n async sendSMSSynchronously(message: QueueMessage<any>): Promise<void> {\n const { to, templateId, ...templateParams } = message.payload;\n const body = { template_id: templateId, short_url: \"0\", recipients: [{ mobiles: to, ...templateParams }] };\n const headers = { \"authkey\": this.commonConfiguration.msg91Sms.apiKey };\n await this.httpService.axiosRef.post(`${this.commonConfiguration.msg91Sms.url}/flow`, body, { headers });\n this.logger.debug(`Sending SMS to ${to} with body ${JSON.stringify(body)} and headers ${JSON.stringify(headers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AAe;IAD3B,IAAA,mBAAU,GAAE;IAGJ,WAAA,IAAA,eAAM,EAAC,uBAAY,CAAC,GAAG,CAAC,CAAA;6CAGP,4CAAgB;QACd,yCAAkB;QACR,mBAAW;GAPpC,eAAe,CAmB3B","sourcesContent":["import { HttpService } from \"@nestjs/axios\";\nimport { Inject, Injectable } from \"@nestjs/common\";\nimport { ConfigType } from \"@nestjs/config\";\nimport commonConfig from \"src/config/common.config\";\nimport { QueueMessage } from \"src/interfaces/mq\";\nimport { SmsTemplateService } from \"../sms-template.service\";\nimport { Msg91BaseSMSService } from \"./Msg91BaseSMSService\";\nimport { ISMS } from \"../../interfaces\";\nimport { PublisherFactory } from \"../queues/publisher-factory.service\";\n\n@Injectable()\nexport class Msg91SMSService extends Msg91BaseSMSService implements ISMS {\n constructor(\n @Inject(commonConfig.KEY)\n commonConfiguration: ConfigType<typeof commonConfig>,\n // smsPublisher: SmsQueuePublisher,\n publisherFactory: PublisherFactory<any>,\n smsTemplateService: SmsTemplateService,\n private readonly httpService: HttpService,\n ) {\n super(commonConfiguration, 'SmsQueuePublisher', publisherFactory, smsTemplateService)\n }\n\n async sendSMSSynchronously(message: QueueMessage<any>): Promise<any> {\n const { to, templateId, ...templateParams } = message.payload;\n const body = { template_id: templateId, short_url: \"0\", recipients: [{ mobiles: to, ...templateParams }] };\n const headers = { \"authkey\": this.commonConfiguration.msg91Sms.apiKey };\n await this.httpService.axiosRef.post(`${this.commonConfiguration.msg91Sms.url}/flow`, body, { headers });\n this.logger.debug(`Sending SMS to ${to} with body ${JSON.stringify(body)} and headers ${JSON.stringify(headers)}`);\n }\n}"]}
@@ -0,0 +1,18 @@
1
+ import { ConfigType } from "@nestjs/config";
2
+ import commonConfig from "src/config/common.config";
3
+ import { SmsTemplateService } from "../sms-template.service";
4
+ import { ISMS } from "../../interfaces";
5
+ import { PublisherFactory } from "../queues/publisher-factory.service";
6
+ import { QueueMessage } from "src/interfaces/mq";
7
+ export declare class TwilioSMSService implements ISMS {
8
+ private commonConfiguration;
9
+ private publisherFactory;
10
+ private smsTemplateService;
11
+ private readonly logger;
12
+ constructor(commonConfiguration: ConfigType<typeof commonConfig>, publisherFactory: PublisherFactory<any>, smsTemplateService: SmsTemplateService);
13
+ sendSMS(to: string, body: string, shouldQueueSms: boolean): Promise<any>;
14
+ sendSMSUsingTemplate(to: string, templateName: string, templateParams: any, shouldQueueSms: boolean): Promise<any>;
15
+ sendSMSAsynchronously(message: any): Promise<void>;
16
+ sendSMSSynchronously(message: QueueMessage<any>): Promise<any>;
17
+ }
18
+ //# sourceMappingURL=TwilioSMSService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TwilioSMSService.d.ts","sourceRoot":"","sources":["../../../src/services/sms/TwilioSMSService.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,YAAY,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAEvE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,qBACa,gBAAiB,YAAW,IAAI;IAKrC,OAAO,CAAC,mBAAmB;IAC3B,OAAO,CAAC,gBAAgB;IACxB,OAAO,CAAC,kBAAkB;IAN9B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqC;gBAIhD,mBAAmB,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,EACpD,gBAAgB,EAAE,gBAAgB,CAAC,GAAG,CAAC,EACvC,kBAAkB,EAAE,kBAAkB;IAK5C,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC;IA+BxE,oBAAoB,CAAC,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,cAAc,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC;IAoBlH,qBAAqB,CAAC,OAAO,KAAA;IAM7B,oBAAoB,CAAC,OAAO,EAAE,YAAY,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;CAoCvE"}
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ var TwilioSMSService_1;
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.TwilioSMSService = void 0;
20
+ const handlebars_1 = __importDefault(require("handlebars"));
21
+ const common_1 = require("@nestjs/common");
22
+ const common_config_1 = __importDefault(require("../../config/common.config"));
23
+ const sms_template_service_1 = require("../sms-template.service");
24
+ const publisher_factory_service_1 = require("../queues/publisher-factory.service");
25
+ const twilio_1 = __importDefault(require("twilio"));
26
+ let TwilioSMSService = TwilioSMSService_1 = class TwilioSMSService {
27
+ constructor(commonConfiguration, publisherFactory, smsTemplateService) {
28
+ this.commonConfiguration = commonConfiguration;
29
+ this.publisherFactory = publisherFactory;
30
+ this.smsTemplateService = smsTemplateService;
31
+ this.logger = new common_1.Logger(TwilioSMSService_1.name);
32
+ }
33
+ async sendSMS(to, body, shouldQueueSms) {
34
+ const accountSid = this.commonConfiguration.twilio.accountSid;
35
+ const authToken = this.commonConfiguration.twilio.authToken;
36
+ const twilioNumber = this.commonConfiguration.twilio.number;
37
+ if (!accountSid || !authToken || !twilioNumber) {
38
+ throw new Error("Missing COMMON_TWILIO_ACCOUNT_SID or COMMON_TWILIO_AUTH_TOKEN or COMMON_TWILIO_NUMBER in env.");
39
+ }
40
+ const message = {
41
+ payload: {
42
+ body: body,
43
+ to: to,
44
+ },
45
+ };
46
+ if (shouldQueueSms === true) {
47
+ await this.sendSMSAsynchronously(message);
48
+ }
49
+ else if (shouldQueueSms === false && this.commonConfiguration.shouldQueueSms === true) {
50
+ await this.sendSMSAsynchronously(message);
51
+ }
52
+ else {
53
+ await this.sendSMSSynchronously(message);
54
+ }
55
+ return message;
56
+ }
57
+ async sendSMSUsingTemplate(to, templateName, templateParams, shouldQueueSms) {
58
+ const smsTemplate = await this.smsTemplateService.findOneByName(templateName);
59
+ if (!smsTemplate) {
60
+ throw new Error(`Invalid template name ${templateName}`);
61
+ }
62
+ let body = '';
63
+ try {
64
+ const bodyTemplate = handlebars_1.default.compile(smsTemplate.body);
65
+ body = bodyTemplate(templateParams);
66
+ }
67
+ catch (error) {
68
+ throw new Error('Unable to compile sms template body');
69
+ }
70
+ return await this.sendSMS(to, body, shouldQueueSms);
71
+ }
72
+ async sendSMSAsynchronously(message) {
73
+ const { to } = message.payload;
74
+ this.publisherFactory.publish(message, 'TwilioSmsQueuePublisher');
75
+ this.logger.debug(`Queueing SMS to ${to} with message ${JSON.stringify(message)}`);
76
+ }
77
+ async sendSMSSynchronously(message) {
78
+ const accountSid = this.commonConfiguration.twilio.accountSid;
79
+ const authToken = this.commonConfiguration.twilio.authToken;
80
+ const twilioNumber = this.commonConfiguration.twilio.number;
81
+ if (!accountSid || !authToken || !twilioNumber) {
82
+ throw new Error("Missing COMMON_TWILIO_ACCOUNT_SID or COMMON_TWILIO_AUTH_TOKEN or COMMON_TWILIO_NUMBER in env.");
83
+ }
84
+ const { to, body } = message.payload;
85
+ const client = (0, twilio_1.default)(accountSid, authToken);
86
+ try {
87
+ const toSplit = to.split(',');
88
+ const r = [];
89
+ for (let i = 0; i < toSplit.length; i++) {
90
+ const actualTo = toSplit[i];
91
+ const twilioResponseMsg = await client.messages.create({
92
+ body: body,
93
+ from: twilioNumber,
94
+ to: actualTo,
95
+ });
96
+ this.logger.debug(`Sending SMS to ${actualTo} using Twilio`);
97
+ this.logger.debug(`Twilio response: `);
98
+ this.logger.debug(JSON.stringify(twilioResponseMsg));
99
+ r.push(twilioResponseMsg);
100
+ }
101
+ return r;
102
+ }
103
+ catch (error) {
104
+ throw new Error(error);
105
+ }
106
+ }
107
+ };
108
+ exports.TwilioSMSService = TwilioSMSService;
109
+ exports.TwilioSMSService = TwilioSMSService = TwilioSMSService_1 = __decorate([
110
+ (0, common_1.Injectable)(),
111
+ __param(0, (0, common_1.Inject)(common_config_1.default.KEY)),
112
+ __metadata("design:paramtypes", [void 0, publisher_factory_service_1.PublisherFactory,
113
+ sms_template_service_1.SmsTemplateService])
114
+ ], TwilioSMSService);
115
+ //# sourceMappingURL=TwilioSMSService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TwilioSMSService.js","sourceRoot":"","sources":["../../../src/services/sms/TwilioSMSService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,4DAAoC;AACpC,2CAA4D;AAE5D,+EAAoD;AACpD,kEAA6D;AAE7D,mFAAuE;AACvE,oDAA4B;AAKrB,IAAM,gBAAgB,wBAAtB,MAAM,gBAAgB;IAGzB,YAEI,mBAA4D,EACpD,gBAAuC,EACvC,kBAAsC;QAFtC,wBAAmB,GAAnB,mBAAmB,CAAiC;QACpD,qBAAgB,GAAhB,gBAAgB,CAAuB;QACvC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@nestjs/config\";\nimport commonConfig from \"src/config/common.config\";\nimport { SmsTemplateService } from \"../sms-template.service\";\nimport { ISMS } from \"../../interfaces\";\nimport { PublisherFactory } from \"../queues/publisher-factory.service\";\nimport twilio from 'twilio';\nimport { QueueMessage } from \"src/interfaces/mq\";\n\n\n@Injectable()\nexport class TwilioSMSService implements ISMS {\n private readonly logger = new Logger(TwilioSMSService.name);\n\n constructor(\n @Inject(commonConfig.KEY)\n private commonConfiguration: ConfigType<typeof commonConfig>,\n private publisherFactory: PublisherFactory<any>,\n private smsTemplateService: SmsTemplateService,\n ) {\n // super(commonConfiguration, 'OTPQueuePublisher', publisherFactory, smsTemplateService);\n }\n\n async sendSMS(to: string, body: string, shouldQueueSms: boolean): Promise<any> {\n const accountSid = this.commonConfiguration.twilio.accountSid;\n const authToken = this.commonConfiguration.twilio.authToken;\n const twilioNumber = this.commonConfiguration.twilio.number;\n if (!accountSid || !authToken || !twilioNumber) {\n throw new Error(\"Missing COMMON_TWILIO_ACCOUNT_SID or COMMON_TWILIO_AUTH_TOKEN or COMMON_TWILIO_NUMBER in env.\");\n }\n\n const message = {\n payload: {\n body: body,\n to: to,\n },\n };\n\n // Send using queue if the developer has explicitly invoked with true.\n if (shouldQueueSms === true) {\n await this.sendSMSAsynchronously(message);\n }\n // If developer has not, however system config mandates that we send using queue, still we send.\n else if (shouldQueueSms === false && this.commonConfiguration.shouldQueueSms === true) {\n await this.sendSMSAsynchronously(message);\n }\n // Else we send synch\n else {\n await this.sendSMSSynchronously(message);\n }\n\n return message;\n }\n\n async sendSMSUsingTemplate(to: string, templateName: string, templateParams: any, shouldQueueSms: boolean): Promise<any> {\n // Load template and evaluate it.\n const smsTemplate = await this.smsTemplateService.findOneByName(templateName);\n if (!smsTemplate) {\n throw new Error(`Invalid template name ${templateName}`);\n }\n\n // Evaluate the body template.\n let body = '';\n try {\n const bodyTemplate = Handlebars.compile(smsTemplate.body);\n body = bodyTemplate(templateParams);\n } catch (error) {\n throw new Error('Unable to compile sms template body');\n }\n // Finally send the email.\n return await this.sendSMS(to, body, shouldQueueSms);\n\n }\n\n async sendSMSAsynchronously(message) {\n const { to } = message.payload;\n this.publisherFactory.publish(message, 'TwilioSmsQueuePublisher');\n this.logger.debug(`Queueing SMS to ${to} with message ${JSON.stringify(message)}`);\n }\n\n async sendSMSSynchronously(message: QueueMessage<any>): Promise<any> {\n const accountSid = this.commonConfiguration.twilio.accountSid;\n const authToken = this.commonConfiguration.twilio.authToken;\n const twilioNumber = this.commonConfiguration.twilio.number;\n if (!accountSid || !authToken || !twilioNumber) {\n throw new Error(\"Missing COMMON_TWILIO_ACCOUNT_SID or COMMON_TWILIO_AUTH_TOKEN or COMMON_TWILIO_NUMBER in env.\");\n }\n\n const { to, body } = message.payload;\n\n const client = twilio(accountSid, authToken);\n try {\n const toSplit = to.split(',');\n\n const r = [];\n\n for (let i = 0; i < toSplit.length; i++) {\n const actualTo = toSplit[i];\n const twilioResponseMsg = await client.messages.create({\n body: body,\n from: twilioNumber,\n to: actualTo,\n });\n\n this.logger.debug(`Sending SMS to ${actualTo} using Twilio`);\n this.logger.debug(`Twilio response: `);\n this.logger.debug(JSON.stringify(twilioResponseMsg))\n\n r.push(twilioResponseMsg);\n }\n\n return r;\n } catch (error) {\n throw new Error(error);\n }\n }\n}"]}
@@ -1 +1 @@
1
- {"version":3,"file":"solid-core.module.d.ts","sourceRoot":"","sources":["../src/solid-core.module.ts"],"names":[],"mappings":"AAwQA,qBA4Ua,eAAe;CAAI"}
1
+ {"version":3,"file":"solid-core.module.d.ts","sourceRoot":"","sources":["../src/solid-core.module.ts"],"names":[],"mappings":"AA+QA,qBAkVa,eAAe;CAAI"}
@@ -181,6 +181,8 @@ const otp_publisher_database_service_1 = require("./jobs/database/otp-publisher-
181
181
  const otp_subscriber_database_service_1 = require("./jobs/database/otp-subscriber-database.service");
182
182
  const sms_publisher_database_service_1 = require("./jobs/database/sms-publisher-database.service");
183
183
  const sms_subscriber_database_service_1 = require("./jobs/database/sms-subscriber-database.service");
184
+ const twilio_sms_publisher_database_service_1 = require("./jobs/database/twilio-sms-publisher-database.service");
185
+ const twilio_sms_subscriber_database_service_1 = require("./jobs/database/twilio-sms-subscriber-database.service");
184
186
  const trigger_mcp_client_publisher_database_service_1 = require("./jobs/database/trigger-mcp-client-publisher-database.service");
185
187
  const trigger_mcp_client_subscriber_database_service_1 = require("./jobs/database/trigger-mcp-client-subscriber-database.service");
186
188
  const whatsapp_publisher_database_service_1 = require("./jobs/database/whatsapp-publisher-database.service");
@@ -255,6 +257,8 @@ const solid_save_model_layout_mcp_tool_response_handler_service_1 = require("./s
255
257
  const noops_entity_computed_field_provider_service_1 = require("./services/computed-fields/entity/noops-entity-computed-field-provider.service");
256
258
  const alpha_num_external_id_computed_field_provider_1 = require("./services/computed-fields/entity/alpha-num-external-id-computed-field-provider");
257
259
  const mail_factory_1 = require("./factories/mail.factory");
260
+ const TwilioSMSService_1 = require("./services/sms/TwilioSMSService");
261
+ const poller_service_1 = require("./services/poller.service");
258
262
  let SolidCoreModule = class SolidCoreModule {
259
263
  };
260
264
  exports.SolidCoreModule = SolidCoreModule;
@@ -424,9 +428,11 @@ exports.SolidCoreModule = SolidCoreModule = __decorate([
424
428
  Msg91SMSService_1.Msg91SMSService,
425
429
  Msg91OTPService_1.Msg91OTPService,
426
430
  Msg91WhatsappService_1.Msg91WhatsappService,
431
+ TwilioSMSService_1.TwilioSMSService,
427
432
  sms_template_service_1.SmsTemplateService,
428
433
  email_template_service_1.EmailTemplateService,
429
434
  publisher_factory_service_1.PublisherFactory,
435
+ poller_service_1.PollerService,
430
436
  mcp_tool_response_handler_factory_service_1.McpToolResponseHandlerFactory,
431
437
  solid_create_module_mcp_tool_response_handler_service_1.SolidCreateModuleMcpToolResponseHandler,
432
438
  trigger_mcp_client_publisher_database_service_1.TriggerMcpClientPublisherDatabase,
@@ -443,6 +449,8 @@ exports.SolidCoreModule = SolidCoreModule = __decorate([
443
449
  sms_subscriber_service_1.SmsQueueSubscriber,
444
450
  sms_publisher_database_service_1.SmsQueuePublisherDatabase,
445
451
  sms_subscriber_database_service_1.SmsQueueSubscriberDatabase,
452
+ twilio_sms_publisher_database_service_1.TwilioSmsQueuePublisherDatabase,
453
+ twilio_sms_subscriber_database_service_1.TwilioSmsQueueSubscriberDatabase,
446
454
  otp_publisher_service_1.OTPQueuePublisher,
447
455
  otp_subscriber_service_1.OTPQueueSubscriber,
448
456
  otp_publisher_database_service_1.OTPQueuePublisherDatabase,
@@ -561,6 +569,7 @@ exports.SolidCoreModule = SolidCoreModule = __decorate([
561
569
  elastic_email_service_1.ElasticEmailService,
562
570
  Msg91SMSService_1.Msg91SMSService,
563
571
  Msg91OTPService_1.Msg91OTPService,
572
+ TwilioSMSService_1.TwilioSMSService,
564
573
  Msg91WhatsappService_1.Msg91WhatsappService,
565
574
  tiny_url_service_1.TinyUrlService,
566
575
  pdf_service_1.PdfService,
@@ -586,6 +595,7 @@ exports.SolidCoreModule = SolidCoreModule = __decorate([
586
595
  config_1.ConfigModule,
587
596
  publisher_factory_service_1.PublisherFactory,
588
597
  mail_factory_1.MailFactory,
598
+ poller_service_1.PollerService
589
599
  ],
590
600
  })
591
601
  ], SolidCoreModule);