@solidstarters/solid-core 1.2.145 → 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 (187) 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 +6 -1
  4. package/dist/config/common.config.js.map +1 -1
  5. package/dist/decorators/mail-provider.decorator.d.ts +3 -0
  6. package/dist/decorators/mail-provider.decorator.d.ts.map +1 -0
  7. package/dist/decorators/mail-provider.decorator.js +11 -0
  8. package/dist/decorators/mail-provider.decorator.js.map +1 -0
  9. package/dist/factories/mail.factory.d.ts +14 -0
  10. package/dist/factories/mail.factory.d.ts.map +1 -0
  11. package/dist/factories/mail.factory.js +50 -0
  12. package/dist/factories/mail.factory.js.map +1 -0
  13. package/dist/helpers/solid-registry.d.ts +3 -0
  14. package/dist/helpers/solid-registry.d.ts.map +1 -1
  15. package/dist/helpers/solid-registry.js +7 -0
  16. package/dist/helpers/solid-registry.js.map +1 -1
  17. package/dist/index.d.ts +7 -3
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +12 -4
  20. package/dist/index.js.map +1 -1
  21. package/dist/interfaces.d.ts +5 -5
  22. package/dist/interfaces.d.ts.map +1 -1
  23. package/dist/interfaces.js.map +1 -1
  24. package/dist/jobs/database/api-email-subscriber-database.service.d.ts +3 -1
  25. package/dist/jobs/database/api-email-subscriber-database.service.d.ts.map +1 -1
  26. package/dist/jobs/database/api-email-subscriber-database.service.js +6 -3
  27. package/dist/jobs/database/api-email-subscriber-database.service.js.map +1 -1
  28. package/dist/jobs/database/computed-field-evaluation-subscriber.service.d.ts +3 -1
  29. package/dist/jobs/database/computed-field-evaluation-subscriber.service.d.ts.map +1 -1
  30. package/dist/jobs/database/computed-field-evaluation-subscriber.service.js +6 -3
  31. package/dist/jobs/database/computed-field-evaluation-subscriber.service.js.map +1 -1
  32. package/dist/jobs/database/generate-code-subscriber-database.service.d.ts +3 -1
  33. package/dist/jobs/database/generate-code-subscriber-database.service.d.ts.map +1 -1
  34. package/dist/jobs/database/generate-code-subscriber-database.service.js +6 -3
  35. package/dist/jobs/database/generate-code-subscriber-database.service.js.map +1 -1
  36. package/dist/jobs/database/otp-subscriber-database.service.d.ts +3 -1
  37. package/dist/jobs/database/otp-subscriber-database.service.d.ts.map +1 -1
  38. package/dist/jobs/database/otp-subscriber-database.service.js +5 -2
  39. package/dist/jobs/database/otp-subscriber-database.service.js.map +1 -1
  40. package/dist/jobs/database/sms-subscriber-database.service.d.ts +4 -2
  41. package/dist/jobs/database/sms-subscriber-database.service.d.ts.map +1 -1
  42. package/dist/jobs/database/sms-subscriber-database.service.js +7 -4
  43. package/dist/jobs/database/sms-subscriber-database.service.js.map +1 -1
  44. package/dist/jobs/database/{email-publisher-database.service.d.ts → smtp-email-publisher-database.service.d.ts} +2 -2
  45. package/dist/jobs/database/smtp-email-publisher-database.service.d.ts.map +1 -0
  46. package/dist/jobs/database/{email-publisher-database.service.js → smtp-email-publisher-database.service.js} +8 -8
  47. package/dist/jobs/database/smtp-email-publisher-database.service.js.map +1 -0
  48. package/dist/jobs/database/{email-queue-options-database.d.ts → smtp-email-queue-options-database.d.ts} +1 -1
  49. package/dist/jobs/database/smtp-email-queue-options-database.d.ts.map +1 -0
  50. package/dist/jobs/database/{email-queue-options-database.js → smtp-email-queue-options-database.js} +1 -1
  51. package/dist/jobs/database/smtp-email-queue-options-database.js.map +1 -0
  52. package/dist/jobs/database/{email-subscriber-database.service.d.ts → smtp-email-subscriber-database.service.d.ts} +6 -4
  53. package/dist/jobs/database/smtp-email-subscriber-database.service.d.ts.map +1 -0
  54. package/dist/jobs/database/{email-subscriber-database.service.js → smtp-email-subscriber-database.service.js} +14 -11
  55. package/dist/jobs/database/smtp-email-subscriber-database.service.js.map +1 -0
  56. package/dist/jobs/database/test-queue-subscriber-database.service.d.ts +3 -1
  57. package/dist/jobs/database/test-queue-subscriber-database.service.d.ts.map +1 -1
  58. package/dist/jobs/database/test-queue-subscriber-database.service.js +6 -3
  59. package/dist/jobs/database/test-queue-subscriber-database.service.js.map +1 -1
  60. package/dist/jobs/database/trigger-mcp-client-subscriber-database.service.d.ts +3 -1
  61. package/dist/jobs/database/trigger-mcp-client-subscriber-database.service.d.ts.map +1 -1
  62. package/dist/jobs/database/trigger-mcp-client-subscriber-database.service.js +5 -2
  63. package/dist/jobs/database/trigger-mcp-client-subscriber-database.service.js.map +1 -1
  64. package/dist/jobs/database/twilio-sms-publisher-database.service.d.ts +11 -0
  65. package/dist/jobs/database/twilio-sms-publisher-database.service.d.ts.map +1 -0
  66. package/dist/jobs/database/twilio-sms-publisher-database.service.js +39 -0
  67. package/dist/jobs/database/twilio-sms-publisher-database.service.js.map +1 -0
  68. package/dist/jobs/database/twilio-sms-queue-database-options.d.ts +8 -0
  69. package/dist/jobs/database/twilio-sms-queue-database-options.d.ts.map +1 -0
  70. package/dist/jobs/database/twilio-sms-queue-database-options.js +10 -0
  71. package/dist/jobs/database/twilio-sms-queue-database-options.js.map +1 -0
  72. package/dist/jobs/database/twilio-sms-subscriber-database.service.d.ts +17 -0
  73. package/dist/jobs/database/twilio-sms-subscriber-database.service.d.ts.map +1 -0
  74. package/dist/jobs/database/twilio-sms-subscriber-database.service.js +48 -0
  75. package/dist/jobs/database/twilio-sms-subscriber-database.service.js.map +1 -0
  76. package/dist/jobs/database/whatsapp-subscriber-database.service.d.ts +3 -1
  77. package/dist/jobs/database/whatsapp-subscriber-database.service.d.ts.map +1 -1
  78. package/dist/jobs/database/whatsapp-subscriber-database.service.js +6 -3
  79. package/dist/jobs/database/whatsapp-subscriber-database.service.js.map +1 -1
  80. package/dist/jobs/sms-subscriber.service.d.ts +1 -1
  81. package/dist/jobs/sms-subscriber.service.js +1 -1
  82. package/dist/jobs/sms-subscriber.service.js.map +1 -1
  83. package/dist/jobs/{email-publisher.service.d.ts → smtp-email-publisher.service.d.ts} +2 -2
  84. package/dist/jobs/smtp-email-publisher.service.d.ts.map +1 -0
  85. package/dist/jobs/{email-publisher.service.js → smtp-email-publisher.service.js} +8 -8
  86. package/dist/jobs/smtp-email-publisher.service.js.map +1 -0
  87. package/dist/jobs/{email-queue-options.d.ts → smtp-email-queue-options.d.ts} +1 -1
  88. package/dist/jobs/smtp-email-queue-options.d.ts.map +1 -0
  89. package/dist/jobs/{email-queue-options.js → smtp-email-queue-options.js} +1 -1
  90. package/dist/jobs/smtp-email-queue-options.js.map +1 -0
  91. package/dist/jobs/{email-subscriber.service.d.ts → smtp-email-subscriber.service.d.ts} +3 -3
  92. package/dist/jobs/smtp-email-subscriber.service.d.ts.map +1 -0
  93. package/dist/jobs/{email-subscriber.service.js → smtp-email-subscriber.service.js} +8 -8
  94. package/dist/jobs/smtp-email-subscriber.service.js.map +1 -0
  95. package/dist/seeders/module-metadata-seeder.service.d.ts +1 -1
  96. package/dist/seeders/module-metadata-seeder.service.d.ts.map +1 -1
  97. package/dist/seeders/module-metadata-seeder.service.js +42 -31
  98. package/dist/seeders/module-metadata-seeder.service.js.map +1 -1
  99. package/dist/services/authentication.service.d.ts +3 -3
  100. package/dist/services/authentication.service.d.ts.map +1 -1
  101. package/dist/services/authentication.service.js +16 -12
  102. package/dist/services/authentication.service.js.map +1 -1
  103. package/dist/services/mail/elastic-email.service.d.ts.map +1 -1
  104. package/dist/services/mail/elastic-email.service.js +2 -0
  105. package/dist/services/mail/elastic-email.service.js.map +1 -1
  106. package/dist/services/mail/smtp-email.service.d.ts +6 -6
  107. package/dist/services/mail/smtp-email.service.d.ts.map +1 -1
  108. package/dist/services/mail/smtp-email.service.js +17 -11
  109. package/dist/services/mail/smtp-email.service.js.map +1 -1
  110. package/dist/services/poller.service.d.ts +24 -0
  111. package/dist/services/poller.service.d.ts.map +1 -0
  112. package/dist/services/poller.service.js +131 -0
  113. package/dist/services/poller.service.js.map +1 -0
  114. package/dist/services/queues/database-subscriber.service.d.ts +4 -1
  115. package/dist/services/queues/database-subscriber.service.d.ts.map +1 -1
  116. package/dist/services/queues/database-subscriber.service.js +13 -13
  117. package/dist/services/queues/database-subscriber.service.js.map +1 -1
  118. package/dist/services/sms/Msg91BaseSMSService.d.ts +2 -2
  119. package/dist/services/sms/Msg91BaseSMSService.d.ts.map +1 -1
  120. package/dist/services/sms/Msg91BaseSMSService.js.map +1 -1
  121. package/dist/services/sms/Msg91OTPService.d.ts +1 -1
  122. package/dist/services/sms/Msg91OTPService.d.ts.map +1 -1
  123. package/dist/services/sms/Msg91OTPService.js.map +1 -1
  124. package/dist/services/sms/Msg91SMSService.d.ts +1 -1
  125. package/dist/services/sms/Msg91SMSService.d.ts.map +1 -1
  126. package/dist/services/sms/Msg91SMSService.js.map +1 -1
  127. package/dist/services/sms/TwilioSMSService.d.ts +18 -0
  128. package/dist/services/sms/TwilioSMSService.d.ts.map +1 -0
  129. package/dist/services/sms/TwilioSMSService.js +115 -0
  130. package/dist/services/sms/TwilioSMSService.js.map +1 -0
  131. package/dist/services/solid-introspect.service.d.ts +1 -0
  132. package/dist/services/solid-introspect.service.d.ts.map +1 -1
  133. package/dist/services/solid-introspect.service.js +14 -0
  134. package/dist/services/solid-introspect.service.js.map +1 -1
  135. package/dist/solid-core.module.d.ts.map +1 -1
  136. package/dist/solid-core.module.js +21 -8
  137. package/dist/solid-core.module.js.map +1 -1
  138. package/dist/tsconfig.tsbuildinfo +1 -1
  139. package/package.json +4 -3
  140. package/src/config/common.config.ts +6 -1
  141. package/src/decorators/mail-provider.decorator.ts +7 -0
  142. package/src/factories/mail.factory.ts +38 -0
  143. package/src/helpers/solid-registry.ts +9 -0
  144. package/src/index.ts +10 -3
  145. package/src/interfaces.ts +11 -5
  146. package/src/jobs/database/api-email-subscriber-database.service.ts +3 -1
  147. package/src/jobs/database/computed-field-evaluation-subscriber.service.ts +4 -2
  148. package/src/jobs/database/generate-code-subscriber-database.service.ts +3 -1
  149. package/src/jobs/database/otp-subscriber-database.service.ts +3 -1
  150. package/src/jobs/database/sms-subscriber-database.service.ts +4 -2
  151. package/src/jobs/database/{email-publisher-database.service.ts → smtp-email-publisher-database.service.ts} +2 -2
  152. package/src/jobs/database/{email-subscriber-database.service.ts → smtp-email-subscriber-database.service.ts} +5 -3
  153. package/src/jobs/database/test-queue-subscriber-database.service.ts +3 -1
  154. package/src/jobs/database/trigger-mcp-client-subscriber-database.service.ts +3 -1
  155. package/src/jobs/database/twilio-sms-publisher-database.service.ts +23 -0
  156. package/src/jobs/database/twilio-sms-queue-database-options.ts +9 -0
  157. package/src/jobs/database/twilio-sms-subscriber-database.service.ts +32 -0
  158. package/src/jobs/database/whatsapp-subscriber-database.service.ts +3 -1
  159. package/src/jobs/sms-subscriber.service.ts +1 -1
  160. package/src/jobs/{email-publisher.service.ts → smtp-email-publisher.service.ts} +2 -2
  161. package/src/jobs/{email-subscriber.service.ts → smtp-email-subscriber.service.ts} +2 -2
  162. package/src/seeders/module-metadata-seeder.service.ts +45 -42
  163. package/src/services/authentication.service.ts +24 -9
  164. package/src/services/mail/elastic-email.service.ts +2 -0
  165. package/src/services/mail/smtp-email.service.ts +48 -21
  166. package/src/services/poller.service.ts +163 -0
  167. package/src/services/queues/database-subscriber.service.ts +39 -12
  168. package/src/services/sms/Msg91BaseSMSService.ts +2 -2
  169. package/src/services/sms/Msg91OTPService.ts +1 -1
  170. package/src/services/sms/Msg91SMSService.ts +1 -1
  171. package/src/services/sms/TwilioSMSService.ts +118 -0
  172. package/src/services/solid-introspect.service.ts +21 -5
  173. package/src/solid-core.module.ts +24 -8
  174. package/dist/jobs/database/email-publisher-database.service.d.ts.map +0 -1
  175. package/dist/jobs/database/email-publisher-database.service.js.map +0 -1
  176. package/dist/jobs/database/email-queue-options-database.d.ts.map +0 -1
  177. package/dist/jobs/database/email-queue-options-database.js.map +0 -1
  178. package/dist/jobs/database/email-subscriber-database.service.d.ts.map +0 -1
  179. package/dist/jobs/database/email-subscriber-database.service.js.map +0 -1
  180. package/dist/jobs/email-publisher.service.d.ts.map +0 -1
  181. package/dist/jobs/email-publisher.service.js.map +0 -1
  182. package/dist/jobs/email-queue-options.d.ts.map +0 -1
  183. package/dist/jobs/email-queue-options.js.map +0 -1
  184. package/dist/jobs/email-subscriber.service.d.ts.map +0 -1
  185. package/dist/jobs/email-subscriber.service.js.map +0 -1
  186. /package/src/jobs/database/{email-queue-options-database.ts → smtp-email-queue-options-database.ts} +0 -0
  187. /package/src/jobs/{email-queue-options.ts → smtp-email-queue-options.ts} +0 -0
@@ -18,9 +18,10 @@ var SMTPEMailService_1;
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.SMTPEMailService = void 0;
20
20
  const common_1 = require("@nestjs/common");
21
+ const handlebars_1 = __importDefault(require("handlebars"));
21
22
  const common_config_1 = __importDefault(require("../../config/common.config"));
23
+ const mail_provider_decorator_1 = require("../../decorators/mail-provider.decorator");
22
24
  const email_template_service_1 = require("../email-template.service");
23
- const handlebars_1 = __importDefault(require("handlebars"));
24
25
  const publisher_factory_service_1 = require("../queues/publisher-factory.service");
25
26
  const nodemailer = require("nodemailer");
26
27
  let SMTPEMailService = SMTPEMailService_1 = class SMTPEMailService {
@@ -39,7 +40,7 @@ let SMTPEMailService = SMTPEMailService_1 = class SMTPEMailService {
39
40
  }
40
41
  });
41
42
  }
42
- async sendEmailUsingTemplate(to, templateName, templateParams, shouldQueueEmails = false, parentEntity = null, parentEntityId = null, attachments = [], cc = [], bcc = [], from = null) {
43
+ async sendEmailUsingTemplate(to, templateName, templateParams, shouldQueueEmails = false, wrapperAttachments, attachments, parentEntity, parentEntityId, cc, bcc, from) {
43
44
  const emailTemplate = await this.emailTemplateService.findOneByName(templateName);
44
45
  if (!emailTemplate) {
45
46
  throw new Error(`Invalid template name ${templateName}`);
@@ -48,9 +49,9 @@ let SMTPEMailService = SMTPEMailService_1 = class SMTPEMailService {
48
49
  const body = bodyTemplate(templateParams);
49
50
  const subjectTemplate = handlebars_1.default.compile(emailTemplate.subject);
50
51
  const subject = subjectTemplate(templateParams);
51
- await this.sendEmail(to, subject, body, shouldQueueEmails, parentEntity, parentEntityId, attachments, cc, bcc, from);
52
+ return await this.sendEmail(to, subject, body, shouldQueueEmails, wrapperAttachments, attachments, parentEntity, parentEntityId, cc, bcc, from);
52
53
  }
53
- async sendEmail(to, subject, body, shouldQueueEmails = false, parentEntity = null, parentEntityId = null, attachments = [], cc = [], bcc = [], from = null) {
54
+ async sendEmail(to, subject, body, shouldQueueEmails = false, wrapperAttachments, attachments, parentEntity, parentEntityId, cc, bcc, from) {
54
55
  const message = {
55
56
  payload: {
56
57
  from: from || this.commonConfiguration.smtpMail.from,
@@ -65,23 +66,27 @@ let SMTPEMailService = SMTPEMailService_1 = class SMTPEMailService {
65
66
  parentEntityId: parentEntityId,
66
67
  };
67
68
  if (shouldQueueEmails === true) {
68
- this.sendEmailAsynchronously(message);
69
+ return this.sendEmailAsynchronously(message);
69
70
  }
70
71
  else if (shouldQueueEmails == false && this.commonConfiguration.shouldQueueEmails === true) {
71
- this.sendEmailAsynchronously(message);
72
+ return this.sendEmailAsynchronously(message);
72
73
  }
73
74
  else {
74
- await this.sendEmailSynchronously(message);
75
+ return await this.sendEmailSynchronously(message);
75
76
  }
76
77
  }
77
78
  async sendEmailAsynchronously(message) {
78
79
  const { to, subject, body } = message.payload;
79
- this.publisherFactory.publish(message, 'EmailQueuePublisher');
80
80
  this.logger.debug(`Queueing email to ${to} with subject ${subject} and body ${body}`);
81
+ return this.publisherFactory.publish(message, 'SmtpEmailQueuePublisher');
81
82
  }
82
83
  async sendEmailSynchronously(message) {
83
- const { from, to, subject, body, attachments, cc, bcc } = message.payload;
84
- const attachmentsList = attachments.map((attachment) => {
84
+ const { from, to, subject, body, attachments = [], cc, bcc } = message.payload;
85
+ if (!from || !to || !subject || !body) {
86
+ this.logger.error(`Required fields are missing in the email message: ${JSON.stringify(message.payload)}`);
87
+ return;
88
+ }
89
+ const attachmentsList = attachments?.map((attachment) => {
85
90
  const attachmentEntry = {
86
91
  filename: attachment.filename,
87
92
  contentType: attachment.contentType,
@@ -93,7 +98,7 @@ let SMTPEMailService = SMTPEMailService_1 = class SMTPEMailService {
93
98
  attachmentEntry['content'] = attachment.content;
94
99
  }
95
100
  return attachmentEntry;
96
- });
101
+ }) || [];
97
102
  const r = await this.transporter.sendMail({
98
103
  from: from,
99
104
  to: to,
@@ -110,6 +115,7 @@ let SMTPEMailService = SMTPEMailService_1 = class SMTPEMailService {
110
115
  exports.SMTPEMailService = SMTPEMailService;
111
116
  exports.SMTPEMailService = SMTPEMailService = SMTPEMailService_1 = __decorate([
112
117
  (0, common_1.Injectable)(),
118
+ (0, mail_provider_decorator_1.MailProvider)(),
113
119
  __param(0, (0, common_1.Inject)(common_config_1.default.KEY)),
114
120
  __metadata("design:paramtypes", [void 0, publisher_factory_service_1.PublisherFactory,
115
121
  email_template_service_1.EmailTemplateService])
@@ -1 +1 @@
1
- {"version":3,"file":"smtp-email.service.js","sourceRoot":"","sources":["../../../src/services/mail/smtp-email.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,2CAA4D;AAG5D,+EAAoD;AACpD,sEAAiE;AACjE,4DAAoC;AAEpC,mFAAuE;AAEvE,MAAM,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAGlC,IAAM,gBAAgB,wBAAtB,MAAM,gBAAgB;IAIzB,YAEI,mBAAqE,EAGpD,gBAAuC,EACvC,oBAA0C;QAJ1C,wBAAmB,GAAnB,mBAAmB,CAAiC;QAGpD,qBAAgB,GAAhB,gBAAgB,CAAuB;QACvC,yBAAoB,GAApB,oBAAoB,CAAsB;QAT9C,WAAM,GAAG,IAAI,eAAM,CAAC,kBAAgB,CAAC,IAAI,CAAC,CAAC;QAWxD,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,eAAe,CAAC;YAC1C,IAAI,EAAE,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,IAAI;YAC5C,IAAI,EAAE,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,IAAI;YAC5C,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,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;QAE1E,MAAM,eAAe,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,UAA0B,EAAE,EAAE;YACnE,MAAM,eAAe,GAAG;gBACpB,QAAQ,EAAE,UAAU,CAAC,QAAQ;gBAC7B,WAAW,EAAE,UAAU,CAAC,WAAW;aACtC,CAAA;YACD,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC;gBAClB,eAAe,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC;YAC9C,CAAC;YACD,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;gBACrB,eAAe,CAAC,SAAS,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC;YACpD,CAAC;YACD,OAAO,eAAe,CAAC;QAC3B,CAAC,CAAC,CAAC;QAGH,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;YACtC,IAAI,EAAE,IAAI;YACV,EAAE,EAAE,EAAE;YACN,EAAE,EAAE,EAAE;YACN,GAAG,EAAE,GAAG;YACR,OAAO,EAAE,OAAO;YAChB,IAAI,EAAE,IAAI;YACV,WAAW,EAAE,eAAe;SAC/B,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,iBAAiB,OAAO,EAAE,CAAC,CAAC;QAEpE,OAAO,CAAC,CAAC;IACb,CAAC;CACJ,CAAA;AAlHY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;IAMJ,WAAA,IAAA,eAAM,EAAC,uBAAY,CAAC,GAAG,CAAC,CAAA;6CAIU,4CAAgB;QACZ,6CAAoB;GAVtD,gBAAgB,CAkH5B","sourcesContent":["import { Inject, Injectable, Logger } from '@nestjs/common';\nimport { ConfigType } from '@nestjs/config';\nimport { QueueMessage } from 'src/interfaces/mq';\nimport commonConfig from 'src/config/common.config';\nimport { EmailTemplateService } from '../email-template.service';\nimport Handlebars from \"handlebars\";\nimport { IMail, MailAttachment } from \"../../interfaces\";\nimport { PublisherFactory } from '../queues/publisher-factory.service';\n\nconst nodemailer = require(\"nodemailer\");\n\n@Injectable()\nexport class SMTPEMailService implements IMail {\n private readonly logger = new Logger(SMTPEMailService.name);\n private readonly transporter: any;\n\n constructor(\n @Inject(commonConfig.KEY)\n private readonly commonConfiguration: ConfigType<typeof commonConfig>,\n // private readonly emailPublisher: EmailQueuePublisher,\n // private readonly emailDbPublisher: EmailQueueDbPublisher,\n private readonly publisherFactory: PublisherFactory<any>,\n private readonly emailTemplateService: EmailTemplateService,\n ) {\n this.transporter = nodemailer.createTransport({\n host: this.commonConfiguration.smtpMail.host,\n port: this.commonConfiguration.smtpMail.port,\n secure: this.commonConfiguration.smtpMail.port === 465,\n auth: {\n user: this.commonConfiguration.smtpMail.username,\n pass: this.commonConfiguration.smtpMail.password\n }\n });\n }\n\n async sendEmailUsingTemplate(to: string, templateName: string, templateParams: any, shouldQueueEmails = false, parentEntity = null, parentEntityId = null, attachments: MailAttachment[] = [], cc: string[] = [], bcc: string[] = [], from: string = null): Promise<void> {\n // Load template and evaluate it. \n const emailTemplate = await this.emailTemplateService.findOneByName(templateName);\n if (!emailTemplate) {\n throw new Error(`Invalid template name ${templateName}`);\n }\n\n // Evaluate the body template.\n const bodyTemplate = Handlebars.compile(emailTemplate.body);\n const body = bodyTemplate(templateParams);\n\n // Evaluate the subject template \n const subjectTemplate = Handlebars.compile(emailTemplate.subject);\n const subject = subjectTemplate(templateParams);\n\n // Finally send the email.\n await this.sendEmail(to, subject, body, shouldQueueEmails, parentEntity, parentEntityId, attachments, cc, bcc, from);\n }\n\n async sendEmail(to: string, subject: string, body: string, shouldQueueEmails = false, parentEntity = null, parentEntityId = null, attachments: MailAttachment[] = [], cc: string[] = [], bcc: string[] = [], from: string = null): Promise<void> {\n const message = {\n payload: {\n from: from || this.commonConfiguration.smtpMail.from,\n to: to,\n subject: subject,\n body: body,\n attachments: attachments,\n cc: cc,\n bcc: bcc,\n },\n parentEntity: parentEntity,\n parentEntityId: parentEntityId,\n };\n\n // Send using queue if the developer has explicitly invoked with true.\n if (shouldQueueEmails === true) {\n this.sendEmailAsynchronously(message);\n }\n // If developer has not, however system config mandates that we send using queue, still we send.\n else if (shouldQueueEmails == false && this.commonConfiguration.shouldQueueEmails === true) {\n this.sendEmailAsynchronously(message);\n }\n // Else we send synch\n else {\n await this.sendEmailSynchronously(message);\n }\n }\n\n async sendEmailAsynchronously(message) {\n const { to, subject, body } = message.payload;\n // this.notificationPublisherService.publish(message);\n // this.emailPublisher.publish(message);\n // this.emailDbPublisher.publish(message);\n\n this.publisherFactory.publish(message, 'EmailQueuePublisher');\n\n this.logger.debug(`Queueing email to ${to} with subject ${subject} and body ${body}`);\n }\n\n async sendEmailSynchronously(message: QueueMessage<any>): Promise<void> {\n const { from, to, subject, body, attachments, cc, bcc } = message.payload;\n\n const attachmentsList = attachments.map((attachment: MailAttachment) => {\n const attachmentEntry = {\n filename: attachment.filename,\n contentType: attachment.contentType,\n }\n if (attachment.path) {\n attachmentEntry['path'] = attachment.path;\n }\n if (attachment.content) {\n attachmentEntry['content'] = attachment.content;\n }\n return attachmentEntry;\n });\n\n // throw new Error('Random error....');\n const r = await this.transporter.sendMail({\n from: from,\n to: to,\n cc: cc,\n bcc: bcc,\n subject: subject,\n html: body,\n attachments: attachmentsList,\n });\n // this.logger.debug(`Sending email to ${to} with subject ${subject} and body ${body}`);\n this.logger.debug(`Sending email to ${to} with subject ${subject}`);\n\n return r;\n }\n}"]}
1
+ {"version":3,"file":"smtp-email.service.js","sourceRoot":"","sources":["../../../src/services/mail/smtp-email.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,2CAA4D;AAE5D,4DAAoC;AACpC,+EAAoD;AACpD,sFAAsE;AAGtE,sEAAiE;AACjE,mFAAuE;AAEvE,MAAM,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAIlC,IAAM,gBAAgB,wBAAtB,MAAM,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YACtC,IAAI,EAAE,IAAI;YACV,EAAE,EAAE,EAAE;YACN,EAAE,EAAE,EAAE;YACN,GAAG,EAAE,GAAG;YACR,OAAO,EAAE,OAAO;YAChB,IAAI,EAAE,IAAI;YACV,WAAW,EAAE,eAAe;SAC/B,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,iBAAiB,OAAO,EAAE,CAAC,CAAC;QAEpE,OAAO,CAAC,CAAC;IACb,CAAC;CACJ,CAAA;AA3IY,4CAAgB;2BAAhB,gBAAgB;IAF5B,IAAA,mBAAU,GAAE;IACZ,IAAA,sCAAY,GAAE;IAMN,WAAA,IAAA,eAAM,EAAC,uBAAY,CAAC,GAAG,CAAC,CAAA;6CAIU,4CAAgB;QACZ,6CAAoB;GAVtD,gBAAgB,CA2I5B","sourcesContent":["import { Inject, Injectable, Logger } from '@nestjs/common';\nimport { ConfigType } from '@nestjs/config';\nimport Handlebars from \"handlebars\";\nimport commonConfig from 'src/config/common.config';\nimport { MailProvider } from 'src/decorators/mail-provider.decorator';\nimport { QueueMessage } from 'src/interfaces/mq';\nimport { IMail, MailAttachment, MailAttachmentWrapper } from \"../../interfaces\";\nimport { EmailTemplateService } from '../email-template.service';\nimport { PublisherFactory } from '../queues/publisher-factory.service';\n\nconst nodemailer = require(\"nodemailer\");\n\n@Injectable()\n@MailProvider()\nexport class SMTPEMailService implements IMail {\n private readonly logger = new Logger(SMTPEMailService.name);\n private readonly transporter: any;\n\n constructor(\n @Inject(commonConfig.KEY)\n private readonly commonConfiguration: ConfigType<typeof commonConfig>,\n // private readonly emailPublisher: EmailQueuePublisher,\n // private readonly emailDbPublisher: EmailQueueDbPublisher,\n private readonly publisherFactory: PublisherFactory<any>,\n private readonly emailTemplateService: EmailTemplateService,\n ) {\n this.transporter = nodemailer.createTransport({\n host: this.commonConfiguration.smtpMail.host,\n port: this.commonConfiguration.smtpMail.port,\n secure: this.commonConfiguration.smtpMail.port === 465,\n auth: {\n user: this.commonConfiguration.smtpMail.username,\n pass: this.commonConfiguration.smtpMail.password\n }\n });\n }\n\n async sendEmailUsingTemplate(\n to: string,\n templateName: string,\n templateParams: any,\n shouldQueueEmails = false,\n wrapperAttachments?: MailAttachmentWrapper[],\n attachments?: MailAttachment[],\n parentEntity?: any,\n parentEntityId?: any,\n cc?: string[],\n bcc?: string[],\n from?: string\n ) {\n // Load template and evaluate it.\n const emailTemplate = await this.emailTemplateService.findOneByName(templateName);\n if (!emailTemplate) {\n throw new Error(`Invalid template name ${templateName}`);\n }\n\n // Evaluate the body template.\n const bodyTemplate = Handlebars.compile(emailTemplate.body);\n const body = bodyTemplate(templateParams);\n\n // Evaluate the subject template \n const subjectTemplate = Handlebars.compile(emailTemplate.subject);\n const subject = subjectTemplate(templateParams);\n\n // Finally send the email.\n return await this.sendEmail(to, subject, body, shouldQueueEmails, wrapperAttachments, attachments, parentEntity, parentEntityId, cc, bcc, from);\n }\n\n async sendEmail(\n to: string,\n subject: string,\n body: string,\n shouldQueueEmails = false,\n wrapperAttachments?: MailAttachmentWrapper[],\n attachments?: MailAttachment[],\n parentEntity?: any,\n parentEntityId?: any,\n cc?: string[],\n bcc?: string[],\n from?: string\n ) {\n const message = {\n payload: {\n from: from || this.commonConfiguration.smtpMail.from,\n to: to,\n subject: subject,\n body: body,\n attachments: attachments,\n cc: cc,\n bcc: bcc,\n },\n parentEntity: parentEntity,\n parentEntityId: parentEntityId,\n };\n\n // Send using queue if the developer has explicitly invoked with true.\n if (shouldQueueEmails === true) {\n return this.sendEmailAsynchronously(message);\n }\n // If developer has not, however system config mandates that we send using queue, still we send.\n else if (shouldQueueEmails == false && this.commonConfiguration.shouldQueueEmails === true) {\n return this.sendEmailAsynchronously(message);\n }\n // Else we send synchronously\n else {\n return await this.sendEmailSynchronously(message);\n }\n }\n\n async sendEmailAsynchronously(message) {\n const { to, subject, body } = message.payload;\n this.logger.debug(`Queueing email to ${to} with subject ${subject} and body ${body}`);\n return this.publisherFactory.publish(message, 'SmtpEmailQueuePublisher');\n }\n\n async sendEmailSynchronously(message: QueueMessage<any>) {\n const { from, to, subject, body, attachments = [], cc, bcc } = message.payload;\n\n // if any of the required fields are missing, throw an error.\n if (!from || !to || !subject || !body) {\n this.logger.error(`Required fields are missing in the email message: ${JSON.stringify(message.payload)}`);\n return;\n }\n\n const attachmentsList = attachments?.map((attachment: MailAttachment) => {\n const attachmentEntry = {\n filename: attachment.filename,\n contentType: attachment.contentType,\n }\n if (attachment.path) {\n attachmentEntry['path'] = attachment.path;\n }\n if (attachment.content) {\n attachmentEntry['content'] = attachment.content;\n }\n return attachmentEntry;\n }) || [];\n\n // throw new Error('Random error....');\n const r = await this.transporter.sendMail({\n from: from,\n to: to,\n cc: cc,\n bcc: bcc,\n subject: subject,\n html: body,\n attachments: attachmentsList,\n });\n // this.logger.debug(`Sending email to ${to} with subject ${subject} and body ${body}`);\n this.logger.debug(`Sending email to ${to} with subject ${subject}`);\n\n return r;\n }\n}"]}
@@ -0,0 +1,24 @@
1
+ import { OnModuleDestroy, BeforeApplicationShutdown } from '@nestjs/common';
2
+ export interface PollOptions {
3
+ baseDelayMs?: number;
4
+ maxDelayMs?: number;
5
+ timeoutPerIterationMs?: number;
6
+ jitter?: boolean;
7
+ }
8
+ type ProcessNextFn = (queueName: string) => Promise<unknown>;
9
+ export declare class PollerService implements OnModuleDestroy, BeforeApplicationShutdown {
10
+ private readonly logger;
11
+ private readonly pollers;
12
+ start(queueName: string, processNext: ProcessNextFn, options?: PollOptions): void;
13
+ stop(queueName: string): void;
14
+ stopAll(): void;
15
+ onModuleDestroy(): Promise<void>;
16
+ beforeApplicationShutdown(): Promise<void>;
17
+ private poll;
18
+ private schedule;
19
+ private computeWait;
20
+ private withTimeout;
21
+ private errorToString;
22
+ }
23
+ export {};
24
+ //# sourceMappingURL=poller.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"poller.service.d.ts","sourceRoot":"","sources":["../../src/services/poller.service.ts"],"names":[],"mappings":"AACA,OAAO,EAGH,eAAe,EACf,yBAAyB,EAC5B,MAAM,gBAAgB,CAAC;AAExB,MAAM,WAAW,WAAW;IAExB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B,MAAM,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,KAAK,aAAa,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAY7D,qBACa,aAAc,YAAW,eAAe,EAAE,yBAAyB;IAC5E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkC;IACzD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkC;IAE1D,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,GAAE,WAAgB,GAAG,IAAI;IA6BrF,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAa7B,OAAO,IAAI,IAAI;IAMT,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhC,yBAAyB,IAAI,OAAO,CAAC,IAAI,CAAC;YAMlC,IAAI;IA2BlB,OAAO,CAAC,QAAQ;IAWhB,OAAO,CAAC,WAAW;YAQL,WAAW;IAczB,OAAO,CAAC,aAAa;CAQxB"}
@@ -0,0 +1,131 @@
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 PollerService_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.PollerService = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ let PollerService = PollerService_1 = class PollerService {
13
+ constructor() {
14
+ this.logger = new common_1.Logger(PollerService_1.name);
15
+ this.pollers = new Map();
16
+ }
17
+ start(queueName, processNext, options = {}) {
18
+ if (this.pollers.has(queueName)) {
19
+ this.logger.warn(`Poller "${queueName}" already started; ignoring.`);
20
+ return;
21
+ }
22
+ const opts = {
23
+ baseDelayMs: options.baseDelayMs ?? 1000,
24
+ maxDelayMs: options.maxDelayMs ?? 30_000,
25
+ timeoutPerIterationMs: options.timeoutPerIterationMs ?? 60_000,
26
+ jitter: options.jitter ?? true,
27
+ };
28
+ const state = {
29
+ queueName,
30
+ processNext,
31
+ opts,
32
+ inFlight: false,
33
+ stopped: false,
34
+ backoff: opts.baseDelayMs,
35
+ nextTimer: undefined,
36
+ };
37
+ this.pollers.set(queueName, state);
38
+ setImmediate(() => this.poll(state).catch(() => { }));
39
+ this.logger.log(`Started poller "${queueName}"`);
40
+ }
41
+ stop(queueName) {
42
+ const state = this.pollers.get(queueName);
43
+ if (!state)
44
+ return;
45
+ state.stopped = true;
46
+ if (state.nextTimer) {
47
+ clearTimeout(state.nextTimer);
48
+ state.nextTimer = undefined;
49
+ }
50
+ this.pollers.delete(queueName);
51
+ this.logger.log(`Stopped poller "${queueName}"`);
52
+ }
53
+ stopAll() {
54
+ for (const name of Array.from(this.pollers.keys())) {
55
+ this.stop(name);
56
+ }
57
+ }
58
+ async onModuleDestroy() {
59
+ this.stopAll();
60
+ }
61
+ async beforeApplicationShutdown() {
62
+ this.stopAll();
63
+ }
64
+ async poll(state) {
65
+ if (state.stopped || state.inFlight)
66
+ return;
67
+ state.inFlight = true;
68
+ try {
69
+ await this.withTimeout(state.processNext(state.queueName), state.opts.timeoutPerIterationMs);
70
+ state.backoff = state.opts.baseDelayMs;
71
+ this.schedule(state, state.opts.baseDelayMs);
72
+ }
73
+ catch (err) {
74
+ const msg = this.errorToString(err);
75
+ this.logger.error(`[${state.queueName}] iteration failed: ${msg}`);
76
+ const wait = this.computeWait(state.backoff, state.opts);
77
+ state.backoff = Math.min(state.backoff * 2, state.opts.maxDelayMs);
78
+ this.schedule(state, wait);
79
+ }
80
+ finally {
81
+ state.inFlight = false;
82
+ }
83
+ }
84
+ schedule(state, delayMs) {
85
+ if (state.stopped)
86
+ return;
87
+ if (state.nextTimer)
88
+ clearTimeout(state.nextTimer);
89
+ state.nextTimer = setTimeout(() => {
90
+ state.nextTimer = undefined;
91
+ this.poll(state).catch(() => { });
92
+ }, delayMs);
93
+ }
94
+ computeWait(currentBackoff, opts) {
95
+ if (!opts.jitter)
96
+ return currentBackoff;
97
+ const doubled = Math.min(currentBackoff * 2, opts.maxDelayMs);
98
+ const jittered = Math.floor(Math.random() * doubled);
99
+ return Math.max(250, jittered);
100
+ }
101
+ async withTimeout(p, ms) {
102
+ let timer;
103
+ try {
104
+ return await Promise.race([
105
+ p,
106
+ new Promise((_, rej) => {
107
+ timer = setTimeout(() => rej(new Error(`Iteration timed out after ${ms} ms`)), ms);
108
+ }),
109
+ ]);
110
+ }
111
+ finally {
112
+ if (timer)
113
+ clearTimeout(timer);
114
+ }
115
+ }
116
+ errorToString(err) {
117
+ if (err instanceof Error)
118
+ return err.stack ?? err.message;
119
+ try {
120
+ return JSON.stringify(err);
121
+ }
122
+ catch {
123
+ return String(err);
124
+ }
125
+ }
126
+ };
127
+ exports.PollerService = PollerService;
128
+ exports.PollerService = PollerService = PollerService_1 = __decorate([
129
+ (0, common_1.Injectable)()
130
+ ], PollerService);
131
+ //# sourceMappingURL=poller.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"poller.service.js","sourceRoot":"","sources":["../../src/services/poller.service.ts"],"names":[],"mappings":";;;;;;;;;;AACA,2CAKwB;AA0BjB,IAAM,aAAa,qBAAnB,MAAM,aAAa;IAAnB;QACc,WAAM,GAAG,IAAI,eAAM,CAAC,eAAa,CAAC,IAAI,CAAC,CAAC;QAC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KAAiC,CAAC;QACtC,IAAI,CAAC;YACD,OAAO,MAAM,OAAO,CAAC,IAAI,CAAI;gBACzB,CAAC;gBACD,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;oBAC1B,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBACvF,CAAC,CAAC;aACL,CAAC,CAAC;QACP,CAAC;gBAAS,CAAC;YACP,IAAI,KAAK;gBAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;IACL,CAAC;IAEO,aAAa,CAAC,GAAY;QAC9B,IAAI,GAAG,YAAY,KAAK;YAAE,OAAO,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC;QAC1D,IAAI,CAAC;YACD,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACL,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;IACL,CAAC;CACJ,CAAA;AAlIY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;GACA,aAAa,CAkIzB","sourcesContent":["// src/common/poller/poller.service.ts\nimport {\n Injectable,\n Logger,\n OnModuleDestroy,\n BeforeApplicationShutdown,\n} from '@nestjs/common';\n\nexport interface PollOptions {\n /** Wait after a successful iteration */\n baseDelayMs?: number; // default 1000\n /** Maximum delay after repeated failures */\n maxDelayMs?: number; // default 30000\n /** Per-iteration timeout guard */\n timeoutPerIterationMs?: number; // default 60000\n /** Add jitter to spread load */\n jitter?: boolean; // default true\n}\n\ntype ProcessNextFn = (queueName: string) => Promise<unknown>;\n\ninterface PollerState {\n queueName: string;\n processNext: ProcessNextFn;\n opts: Required<PollOptions>;\n inFlight: boolean;\n stopped: boolean;\n backoff: number;\n nextTimer?: NodeJS.Timeout;\n}\n\n@Injectable()\nexport class PollerService implements OnModuleDestroy, BeforeApplicationShutdown {\n private readonly logger = new Logger(PollerService.name);\n private readonly pollers = new Map<string, PollerState>();\n\n start(queueName: string, processNext: ProcessNextFn, options: PollOptions = {}): void {\n if (this.pollers.has(queueName)) {\n this.logger.warn(`Poller \"${queueName}\" already started; ignoring.`);\n return;\n }\n\n const opts: Required<PollOptions> = {\n baseDelayMs: options.baseDelayMs ?? 1000,\n maxDelayMs: options.maxDelayMs ?? 30_000,\n timeoutPerIterationMs: options.timeoutPerIterationMs ?? 60_000,\n jitter: options.jitter ?? true,\n };\n\n const state: PollerState = {\n queueName,\n processNext,\n opts,\n inFlight: false,\n stopped: false,\n backoff: opts.baseDelayMs,\n nextTimer: undefined,\n };\n\n this.pollers.set(queueName, state);\n // kick off on next tick\n setImmediate(() => this.poll(state).catch(() => { }));\n this.logger.log(`Started poller \"${queueName}\"`);\n }\n\n stop(queueName: string): void {\n const state = this.pollers.get(queueName);\n if (!state) return;\n\n state.stopped = true;\n if (state.nextTimer) {\n clearTimeout(state.nextTimer);\n state.nextTimer = undefined;\n }\n this.pollers.delete(queueName);\n this.logger.log(`Stopped poller \"${queueName}\"`);\n }\n\n stopAll(): void {\n for (const name of Array.from(this.pollers.keys())) {\n this.stop(name);\n }\n }\n\n async onModuleDestroy(): Promise<void> {\n this.stopAll();\n }\n\n async beforeApplicationShutdown(): Promise<void> {\n this.stopAll();\n }\n\n // ---- internals ----\n\n private async poll(state: PollerState): Promise<void> {\n if (state.stopped || state.inFlight) return;\n state.inFlight = true;\n\n try {\n await this.withTimeout(\n state.processNext(state.queueName),\n state.opts.timeoutPerIterationMs,\n );\n\n // success: reset backoff and schedule next run after base delay\n state.backoff = state.opts.baseDelayMs;\n // this.logger.debug(`[${state.queueName}] iteration completed`);\n this.schedule(state, state.opts.baseDelayMs);\n } catch (err: unknown) {\n const msg = this.errorToString(err);\n this.logger.error(`[${state.queueName}] iteration failed: ${msg}`);\n\n // failure: schedule with backoff + optional jitter, then increase backoff\n const wait = this.computeWait(state.backoff, state.opts);\n state.backoff = Math.min(state.backoff * 2, state.opts.maxDelayMs);\n this.schedule(state, wait);\n } finally {\n state.inFlight = false;\n }\n }\n\n private schedule(state: PollerState, delayMs: number) {\n if (state.stopped) return;\n if (state.nextTimer) clearTimeout(state.nextTimer);\n\n state.nextTimer = setTimeout(() => {\n // clear reference before calling poll to avoid re-entrancy confusion\n state.nextTimer = undefined;\n this.poll(state).catch(() => { });\n }, delayMs);\n }\n\n private computeWait(currentBackoff: number, opts: Required<PollOptions>): number {\n if (!opts.jitter) return currentBackoff;\n // Full jitter: random in [250ms, currentBackoff * 2], clamped to maxDelayMs\n const doubled = Math.min(currentBackoff * 2, opts.maxDelayMs);\n const jittered = Math.floor(Math.random() * doubled);\n return Math.max(250, jittered);\n }\n\n private async withTimeout<T>(p: Promise<T>, ms: number): Promise<T> {\n let timer: NodeJS.Timeout | undefined;\n try {\n return await Promise.race<T>([\n p,\n new Promise<never>((_, rej) => {\n timer = setTimeout(() => rej(new Error(`Iteration timed out after ${ms} ms`)), ms);\n }),\n ]);\n } finally {\n if (timer) clearTimeout(timer);\n }\n }\n\n private errorToString(err: unknown): string {\n if (err instanceof Error) return err.stack ?? err.message;\n try {\n return JSON.stringify(err);\n } catch {\n return String(err);\n }\n }\n}"]}
@@ -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,qBAAqB,EAAE,qBAAqB;IANnE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuC;IAC9D,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;gBAGd,gBAAgB,EAAE,gBAAgB,EAClC,qBAAqB,EAAE,qBAAqB;IASnE,QAAQ,CAAC,SAAS,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC;IAE3C,QAAQ,CAAC,OAAO,IAAI,mBAAmB;YAEzB,WAAW;IA6CnB,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;cA4BnB,cAAc,CAAC,OAAO,EAAE,YA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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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G,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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Aa,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;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/Msg91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ACxC,CAAC;QACD,IAAI,aAAa,CAAC,qBAAqB,EAAE,CAAC;YACtC,UAAU,GAAG,aAAa,CAAC,qBAAqB,CAAC;QACrD,CAAC;QACD,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,iFAAiF,YAAY,EAAE,CAAC,CAAC;QACrH,CAAC;QAED,MAAM,OAAO,GAAG;YACZ,OAAO,EAAE;gBACL,GAAG,cAAc;gBACjB,EAAE,EAAE,EAAE;gBACN,UAAU,EAAE,UAAU;aACzB;SAGJ,CAAC;QAGF,IAAI,cAAc,KAAK,IAAI,EAAE,CAAC;YAC1B,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC;QAC9C,CAAC;aAEI,IAAI,cAAc,KAAK,KAAK,IAAI,IAAI,CAAC,mBAAmB,CAAC,cAAc,KAAK,IAAI,EAAE,CAAC;YACpF,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC;QAC9C,CAAC;aAEI,CAAC;YACF,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAC7C,CAAC;IACL,CAAC;IAED,KAAK,CAAC,qBAAqB,CAAC,OAAO;QAC/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<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,cAAc,GAAG,KAAK;QAEpG,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;QAChF,IAAI,CAAC,aAAa,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,yBAAyB,YAAY,EAAE,CAAC,CAAC;QAC7D,CAAC;QAGD,IAAI,IAAI,GAAG,IAAI,CAAC;QAChB,IAAI,UAAU,GAAG,IAAI,CAAC;QAItB,IAAI,aAAa,CAAC,IAAI,EAAE,CAAC;YACrB,MAAM,YAAY,GAAG,oBAAU,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YAC5D,IAAI,GAAG,YAAY,CAAC,cAAc,CAAC,CAAC;QACxC,CAAC;QACD,IAAI,aAAa,CAAC,qBAAqB,EAAE,CAAC;YACtC,UAAU,GAAG,aAAa,CAAC,qBAAqB,CAAC;QACrD,CAAC;QACD,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,iFAAiF,YAAY,EAAE,CAAC,CAAC;QACrH,CAAC;QAED,MAAM,OAAO,GAAG;YACZ,OAAO,EAAE;gBACL,GAAG,cAAc;gBACjB,EAAE,EAAE,EAAE;gBACN,UAAU,EAAE,UAAU;aACzB;SAGJ,CAAC;QAGF,IAAI,cAAc,KAAK,IAAI,EAAE,CAAC;YAC1B,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC;QAC9C,CAAC;aAEI,IAAI,cAAc,KAAK,KAAK,IAAI,IAAI,CAAC,mBAAmB,CAAC,cAAc,KAAK,IAAI,EAAE,CAAC;YACpF,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC;QAC9C,CAAC;aAEI,CAAC;YACF,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAC7C,CAAC;IACL,CAAC;IAED,KAAK,CAAC,qBAAqB,CAAC,OAAO;QAC/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,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AASvE,qBACa,eAAgB,SAAQ,mBAAoB,YAAW,IAAI;IAOhE,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAJ5B,mBAAmB,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,EAEpD,gBAAgB,EAAE,gBAAgB,CAAC,GAAG,CAAC,EACvC,kBAAkB,EAAE,kBAAkB,EACrB,WAAW,EAAE,WAAW;IAKvC,oBAAoB,CAAC,OAAO,EAAE,YAAY,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAQrE,OAAO,CAAC,mBAAmB;CAS9B"}
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,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AASvE,qBACa,eAAgB,SAAQ,mBAAoB,YAAW,IAAI;IAOhE,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAJ5B,mBAAmB,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,EAEpD,gBAAgB,EAAE,gBAAgB,CAAC,GAAG,CAAC,EACvC,kBAAkB,EAAE,kBAAkB,EACrB,WAAW,EAAE,WAAW;IAKvC,oBAAoB,CAAC,OAAO,EAAE,YAAY,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;IAQpE,OAAO,CAAC,mBAAmB;CAS9B"}
@@ -1 +1 @@
1
- {"version":3,"file":"Msg91OTPService.js","sourceRoot":"","sources":["../../../src/services/sms/Msg91OTPService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,yCAA4C;AAC5C,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D,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,CAAC;AAC5C,OAAO,YAAY,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAEvE,qBACa,eAAgB,SAAQ,mBAAoB,YAAW,IAAI;IAOhE,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAJ5B,mBAAmB,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,EAEpD,gBAAgB,EAAE,gBAAgB,CAAC,GAAG,CAAC,EACvC,kBAAkB,EAAE,kBAAkB,EACrB,WAAW,EAAE,WAAW;IAKvC,oBAAoB,CAAC,OAAO,EAAE,YAAY,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAOxE"}
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,CAAC;AAC5C,OAAO,YAAY,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAEvE,qBACa,eAAgB,SAAQ,mBAAoB,YAAW,IAAI;IAOhE,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAJ5B,mBAAmB,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,EAEpD,gBAAgB,EAAE,gBAAgB,CAAC,GAAG,CAAC,EACvC,kBAAkB,EAAE,kBAAkB,EACrB,WAAW,EAAE,WAAW;IAKvC,oBAAoB,CAAC,OAAO,EAAE,YAAY,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;CAOvE"}
@@ -1 +1 @@
1
- {"version":3,"file":"Msg91SMSService.js","sourceRoot":"","sources":["../../../src/services/sms/Msg91SMSService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,yCAA4C;AAC5C,2CAAoD;AAEpD,+EAAoD;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ttpService } 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)}`);\n }\n}"]}
1
+ {"version":3,"file":"Msg91SMSService.js","sourceRoot":"","sources":["../../../src/services/sms/Msg91SMSService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,yCAA4C;AAC5C,2CAAoD;AAEpD,+EAAoD;AAEpD,kEAA6D;AAC7D,+DAA4D;AAE5D,mFAAuE;AAGhE,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,CAAA;QAFpE,gBAAW,GAAX,WAAW,CAAa;IAG7C,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAC,OAA0B;QACjD,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;QAC9D,MAAM,IAAI,GAAG,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,cAAc,EAAE,CAAC,EAAE,CAAC;QAC3G,MAAM,OAAO,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QACxE,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,GAAG,OAAO,EAAE,IAAI,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<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"}