@solidstarters/solid-core 1.2.144 → 1.2.145

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 (66) hide show
  1. package/dist/config/common.config.d.ts +2 -0
  2. package/dist/config/common.config.d.ts.map +1 -1
  3. package/dist/config/common.config.js +3 -2
  4. package/dist/config/common.config.js.map +1 -1
  5. package/dist/index.d.ts +6 -3
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +8 -4
  8. package/dist/index.js.map +1 -1
  9. package/dist/interfaces.js.map +1 -1
  10. package/dist/jobs/api-email-subscriber.service.d.ts +1 -1
  11. package/dist/jobs/api-email-subscriber.service.d.ts.map +1 -1
  12. package/dist/jobs/api-email-subscriber.service.js +2 -2
  13. package/dist/jobs/api-email-subscriber.service.js.map +1 -1
  14. package/dist/jobs/database/api-email-subscriber-database.service.d.ts +1 -1
  15. package/dist/jobs/database/api-email-subscriber-database.service.d.ts.map +1 -1
  16. package/dist/jobs/database/api-email-subscriber-database.service.js +2 -2
  17. package/dist/jobs/database/api-email-subscriber-database.service.js.map +1 -1
  18. package/dist/jobs/database/email-subscriber-database.service.d.ts +1 -1
  19. package/dist/jobs/database/email-subscriber-database.service.d.ts.map +1 -1
  20. package/dist/jobs/database/email-subscriber-database.service.js +2 -2
  21. package/dist/jobs/database/email-subscriber-database.service.js.map +1 -1
  22. package/dist/jobs/email-subscriber.service.d.ts +1 -1
  23. package/dist/jobs/email-subscriber.service.d.ts.map +1 -1
  24. package/dist/jobs/email-subscriber.service.js +2 -2
  25. package/dist/jobs/email-subscriber.service.js.map +1 -1
  26. package/dist/seeders/seed-data/solid-core-metadata.json +12 -12
  27. package/dist/services/authentication.service.d.ts +1 -1
  28. package/dist/services/authentication.service.d.ts.map +1 -1
  29. package/dist/services/authentication.service.js +2 -2
  30. package/dist/services/authentication.service.js.map +1 -1
  31. package/dist/services/import-transaction.service.d.ts.map +1 -1
  32. package/dist/services/import-transaction.service.js +1 -0
  33. package/dist/services/import-transaction.service.js.map +1 -1
  34. package/dist/services/mail/{ElasticEmailService.d.ts → elastic-email.service.d.ts} +1 -1
  35. package/dist/services/mail/elastic-email.service.d.ts.map +1 -0
  36. package/dist/services/mail/{ElasticEmailService.js → elastic-email.service.js} +1 -1
  37. package/dist/services/mail/elastic-email.service.js.map +1 -0
  38. package/dist/services/mail/{SMTPEmailService.d.ts → smtp-email.service.d.ts} +3 -3
  39. package/dist/services/mail/smtp-email.service.d.ts.map +1 -0
  40. package/dist/services/mail/{SMTPEmailService.js → smtp-email.service.js} +8 -6
  41. package/dist/services/mail/smtp-email.service.js.map +1 -0
  42. package/dist/services/model-metadata.service.js +1 -1
  43. package/dist/services/model-metadata.service.js.map +1 -1
  44. package/dist/solid-core.module.d.ts.map +1 -1
  45. package/dist/solid-core.module.js +9 -7
  46. package/dist/solid-core.module.js.map +1 -1
  47. package/dist/tsconfig.tsbuildinfo +1 -1
  48. package/package.json +1 -1
  49. package/src/config/common.config.ts +3 -2
  50. package/src/index.ts +7 -3
  51. package/src/interfaces.ts +3 -3
  52. package/src/jobs/api-email-subscriber.service.ts +1 -1
  53. package/src/jobs/database/api-email-subscriber-database.service.ts +1 -1
  54. package/src/jobs/database/email-subscriber-database.service.ts +1 -1
  55. package/src/jobs/email-subscriber.service.ts +1 -1
  56. package/src/seeders/seed-data/solid-core-metadata.json +12 -12
  57. package/src/services/authentication.service.ts +1 -1
  58. package/src/services/import-transaction.service.ts +1 -0
  59. package/src/services/mail/{SMTPEmailService.ts → smtp-email.service.ts} +7 -5
  60. package/src/services/model-metadata.service.ts +1 -1
  61. package/src/solid-core.module.ts +5 -3
  62. package/dist/services/mail/ElasticEmailService.d.ts.map +0 -1
  63. package/dist/services/mail/ElasticEmailService.js.map +0 -1
  64. package/dist/services/mail/SMTPEmailService.d.ts.map +0 -1
  65. package/dist/services/mail/SMTPEmailService.js.map +0 -1
  66. /package/src/services/mail/{ElasticEmailService.ts → elastic-email.service.ts} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidstarters/solid-core",
3
- "version": "1.2.144",
3
+ "version": "1.2.145",
4
4
  "description": "This module is a NestJS module containing all the required core providers required by a Solid application",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -13,10 +13,11 @@ export default registerAs('common', () => {
13
13
  port: +(process.env.COMMON_SMTP_EMAIL_SMTP_PORT ?? 587),
14
14
  username: process.env.COMMON_SMTP_EMAIL_USERNAME,
15
15
  password: process.env.COMMON_SMTP_EMAIL_PASSWORD,
16
- from: process.env.COMMON_SMTP_EMAIL_FROM,
16
+ from: process.env.COMMON_SMTP_EMAIL_FROM ?? process.env.COMMON_EMAIL_FROM,
17
17
  },
18
18
  apiMail: {
19
- key: process.env.COMMON_API_EMAIL_KEY
19
+ key: process.env.COMMON_API_EMAIL_KEY,
20
+ from: process.env.COMMON_EMAIL_FROM
20
21
  },
21
22
  msg91Sms: {
22
23
  url: process.env.COMMON_MSG91_SMS_URL,
package/src/index.ts CHANGED
@@ -5,7 +5,7 @@ export * from './commands/remove-fields.command'
5
5
  export * from './commands/seed.command'
6
6
 
7
7
  export * from './config/app-builder.config'
8
- export * from './config/common.config'
8
+ export {default as commonConfig} from './config/common.config'
9
9
  export * from './config/iam.config'
10
10
  export * from './config/cache.options'
11
11
 
@@ -216,8 +216,8 @@ export * from './services/field-metadata.service'
216
216
  export * from './services/file.service'
217
217
  export * from './services/hashing.service'
218
218
  export * from './services/list-of-values.service'
219
- export * from './services/mail/ElasticEmailService'
220
- export * from './services/mail/SMTPEmailService'
219
+ export * from './services/mail/elastic-email.service'
220
+ export * from './services/mail/smtp-email.service'
221
221
  export * from './services/media-storage-provider-metadata-seeder.service'
222
222
  export * from './services/media-storage-provider-metadata.service'
223
223
  export * from './services/media.service'
@@ -257,6 +257,10 @@ export * from './services/import-transaction.service'
257
257
  export * from './services/import-transaction-error-log.service'
258
258
  export * from './services/excel.service'
259
259
  export * from './services/csv.service'
260
+ export * from './services/queues/publisher-factory.service'
261
+ export * from './services/queues/database-publisher.service'
262
+ export * from './services/queues/database-subscriber.service'
263
+
260
264
  // Repositories
261
265
  export * from './repository/solid-base.repository'
262
266
  export * from './repository/security-rule.repository'
package/src/interfaces.ts CHANGED
@@ -201,11 +201,11 @@ export interface MailAttachmentWrapper {
201
201
 
202
202
  export interface MailAttachment {
203
203
  filename: string;
204
- templatePath?: string;
205
- templateParams?: any;
204
+ templatePath?: string; // deprecated
205
+ templateParams?: any; // deprecated
206
206
  content?: string | Buffer;
207
207
  contentType?: string;
208
- path?: string;
208
+ path?: string; //Filesystem absolute path or URL.
209
209
  }
210
210
 
211
211
  export enum BrokerType {
@@ -3,7 +3,7 @@ import { Injectable } from '@nestjs/common';
3
3
  import mailQueueOptions from './api-email-queue-options';
4
4
  import { RabbitMqSubscriber } from 'src/services/queues/rabbitmq-subscriber.service';
5
5
  import { QueueMessage } from 'src/interfaces/mq';
6
- import { ElasticEmailService } from '../services/mail/ElasticEmailService';
6
+ import { ElasticEmailService } from '../services/mail/elastic-email.service';
7
7
  import { MqMessageService } from 'src/services/mq-message.service';
8
8
  import { MqMessageQueueService } from 'src/services/mq-message-queue.service';
9
9
  import { QueuesModuleOptions } from "../interfaces";
@@ -4,7 +4,7 @@ import mailQueueOptions from './api-email-queue-options-database';
4
4
  import { QueueMessage } from 'src/interfaces/mq';
5
5
  import { MqMessageService } from 'src/services/mq-message.service';
6
6
  import { MqMessageQueueService } from 'src/services/mq-message-queue.service';
7
- import { ElasticEmailService } from 'src/services/mail/ElasticEmailService';
7
+ import { ElasticEmailService } from 'src/services/mail/elastic-email.service';
8
8
  import { QueuesModuleOptions } from 'src/interfaces';
9
9
  import { DatabaseSubscriber } from 'src/services/queues/database-subscriber.service';
10
10
 
@@ -5,7 +5,7 @@ import { QueueMessage } from 'src/interfaces/mq';
5
5
  import { MqMessageService } from 'src/services/mq-message.service';
6
6
  import { MqMessageQueueService } from 'src/services/mq-message-queue.service';
7
7
  import { DatabaseSubscriber } from 'src/services/queues/database-subscriber.service';
8
- import { SMTPEMailService } from 'src/services/mail/SMTPEmailService';
8
+ import { SMTPEMailService } from 'src/services/mail/smtp-email.service';
9
9
  import { QueuesModuleOptions } from 'src/interfaces';
10
10
 
11
11
  @Injectable()
@@ -3,7 +3,7 @@ import { Injectable } from '@nestjs/common';
3
3
  import mailQueueOptions from './email-queue-options';
4
4
  import { RabbitMqSubscriber } from 'src/services/queues/rabbitmq-subscriber.service';
5
5
  import { QueueMessage } from 'src/interfaces/mq';
6
- import { SMTPEMailService } from '../services/mail/SMTPEmailService';
6
+ import { SMTPEMailService } from '../services/mail/smtp-email.service';
7
7
  import { MqMessageService } from 'src/services/mq-message.service';
8
8
  import { MqMessageQueueService } from 'src/services/mq-message-queue.service';
9
9
  import { QueuesModuleOptions } from "../interfaces";
@@ -5387,27 +5387,27 @@
5387
5387
  },
5388
5388
  {
5389
5389
  "displayName": "Email list action",
5390
- "name": "email-list-action",
5390
+ "name": "emailTemplate-list-action",
5391
5391
  "type": "solid",
5392
5392
  "domain": "",
5393
5393
  "context": "",
5394
5394
  "customComponent": "",
5395
5395
  "customIsModal": true,
5396
5396
  "serverEndpoint": "",
5397
- "viewUserKey": "email-list-view",
5397
+ "viewUserKey": "emailTemplate-list-view",
5398
5398
  "moduleUserKey": "solid-core",
5399
5399
  "modelUserKey": "emailTemplate"
5400
5400
  },
5401
5401
  {
5402
5402
  "displayName": "SMS list action",
5403
- "name": "sms-list-action",
5403
+ "name": "smsTemplate-list-action",
5404
5404
  "type": "solid",
5405
5405
  "domain": "",
5406
5406
  "context": "",
5407
5407
  "customComponent": "",
5408
5408
  "customIsModal": true,
5409
5409
  "serverEndpoint": "",
5410
- "viewUserKey": "sms-list-view",
5410
+ "viewUserKey": "smsTemplate-list-view",
5411
5411
  "moduleUserKey": "solid-core",
5412
5412
  "modelUserKey": "smsTemplate"
5413
5413
  },
@@ -5755,17 +5755,17 @@
5755
5755
  },
5756
5756
  {
5757
5757
  "displayName": "Email",
5758
- "name": "email-menu-item",
5758
+ "name": "emailTemplate-menu-item",
5759
5759
  "sequenceNumber": 1,
5760
- "actionUserKey": "email-list-action",
5760
+ "actionUserKey": "emailTemplate-list-action",
5761
5761
  "moduleUserKey": "solid-core",
5762
5762
  "parentMenuItemUserKey": "notification-menu-item"
5763
5763
  },
5764
5764
  {
5765
5765
  "displayName": "SMS",
5766
- "name": "sms-menu-item",
5766
+ "name": "smsTemplate-menu-item",
5767
5767
  "sequenceNumber": 1,
5768
- "actionUserKey": "sms-list-action",
5768
+ "actionUserKey": "smsTemplate-list-action",
5769
5769
  "moduleUserKey": "solid-core",
5770
5770
  "parentMenuItemUserKey": "notification-menu-item"
5771
5771
  },
@@ -10672,7 +10672,7 @@
10672
10672
  }
10673
10673
  },
10674
10674
  {
10675
- "name": "email-list-view",
10675
+ "name": "emailTemplate-list-view",
10676
10676
  "displayName": "Email",
10677
10677
  "type": "list",
10678
10678
  "context": "{}",
@@ -10706,7 +10706,7 @@
10706
10706
  }
10707
10707
  },
10708
10708
  {
10709
- "name": "email-form-view",
10709
+ "name": "emailTemplate-form-view",
10710
10710
  "displayName": "Email",
10711
10711
  "type": "form",
10712
10712
  "context": "{}",
@@ -10805,7 +10805,7 @@
10805
10805
  }
10806
10806
  },
10807
10807
  {
10808
- "name": "sms-list-view",
10808
+ "name": "smsTemplate-list-view",
10809
10809
  "displayName": "SMS Template",
10810
10810
  "type": "list",
10811
10811
  "context": "{}",
@@ -10839,7 +10839,7 @@
10839
10839
  }
10840
10840
  },
10841
10841
  {
10842
- "name": "sms-form-view",
10842
+ "name": "smsTemplate-form-view",
10843
10843
  "displayName": "SMS Template",
10844
10844
  "type": "form",
10845
10845
  "context": "{}",
@@ -15,7 +15,7 @@ import { JwtService } from '@nestjs/jwt';
15
15
  import { InjectRepository } from '@nestjs/typeorm';
16
16
  import { isEmpty, isNotEmpty } from 'class-validator';
17
17
  import { randomInt, randomUUID } from 'crypto';
18
- import { SMTPEMailService } from 'src/services/mail/SMTPEmailService';
18
+ import { SMTPEMailService } from 'src/services/mail/smtp-email.service';
19
19
  import { Msg91OTPService } from 'src/services/sms/Msg91OTPService';
20
20
  import { Repository } from 'typeorm';
21
21
  import { iamConfig, jwtConfig } from '../config/iam.config';
@@ -385,6 +385,7 @@ export class ImportTransactionService extends CRUDService<ImportTransaction> {
385
385
  field.type !== SolidFieldType.password &&
386
386
  field.type !== SolidFieldType.richText &&
387
387
  field.type !== SolidFieldType.uuid &&
388
+ field.relationType !== RelationType.oneToMany &&
388
389
  field.isSystem !== true // Exclude system fields
389
390
  );
390
391
  }
@@ -33,7 +33,7 @@ export class SMTPEMailService implements IMail {
33
33
  });
34
34
  }
35
35
 
36
- async sendEmailUsingTemplate(to: string, templateName: string, templateParams: any, shouldQueueEmails = false, parentEntity = null, parentEntityId = null, attachments: MailAttachment[] = [], cc: string[] = []): Promise<void> {
36
+ 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> {
37
37
  // Load template and evaluate it.
38
38
  const emailTemplate = await this.emailTemplateService.findOneByName(templateName);
39
39
  if (!emailTemplate) {
@@ -49,18 +49,19 @@ export class SMTPEMailService implements IMail {
49
49
  const subject = subjectTemplate(templateParams);
50
50
 
51
51
  // Finally send the email.
52
- await this.sendEmail(to, subject, body, shouldQueueEmails, parentEntity, parentEntityId, attachments);
52
+ await this.sendEmail(to, subject, body, shouldQueueEmails, parentEntity, parentEntityId, attachments, cc, bcc, from);
53
53
  }
54
54
 
55
- async sendEmail(to: string, subject: string, body: string, shouldQueueEmails = false, parentEntity = null, parentEntityId = null, attachments: MailAttachment[] = [], cc: string[] = []): Promise<void> {
55
+ 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> {
56
56
  const message = {
57
57
  payload: {
58
- from: this.commonConfiguration.smtpMail.from,
58
+ from: from || this.commonConfiguration.smtpMail.from,
59
59
  to: to,
60
60
  subject: subject,
61
61
  body: body,
62
62
  attachments: attachments,
63
63
  cc: cc,
64
+ bcc: bcc,
64
65
  },
65
66
  parentEntity: parentEntity,
66
67
  parentEntityId: parentEntityId,
@@ -92,7 +93,7 @@ export class SMTPEMailService implements IMail {
92
93
  }
93
94
 
94
95
  async sendEmailSynchronously(message: QueueMessage<any>): Promise<void> {
95
- const { from, to, subject, body, attachments, cc } = message.payload;
96
+ const { from, to, subject, body, attachments, cc, bcc } = message.payload;
96
97
 
97
98
  const attachmentsList = attachments.map((attachment: MailAttachment) => {
98
99
  const attachmentEntry = {
@@ -113,6 +114,7 @@ export class SMTPEMailService implements IMail {
113
114
  from: from,
114
115
  to: to,
115
116
  cc: cc,
117
+ bcc: bcc,
116
118
  subject: subject,
117
119
  html: body,
118
120
  attachments: attachmentsList,
@@ -910,7 +910,7 @@ export class ModelMetadataService {
910
910
  metaData.menus.push(menu);
911
911
  }
912
912
 
913
- if (notExists(metaData.actions, viewName)) {
913
+ if (notExists(metaData.actions, actionName)) {
914
914
  metaData.actions.push(action);
915
915
  }
916
916
 
@@ -108,8 +108,8 @@ import { UuidExternalIdComputedFieldProvider } from './services/computed-fields/
108
108
  import { EmailTemplateService } from './services/email-template.service';
109
109
  import { FileService } from './services/file.service';
110
110
  import { HashingService } from './services/hashing.service';
111
- import { ElasticEmailService } from './services/mail/ElasticEmailService';
112
- import { SMTPEMailService } from './services/mail/SMTPEmailService';
111
+ import { ElasticEmailService } from './services/mail/elastic-email.service';
112
+ import { SMTPEMailService } from './services/mail/smtp-email.service';
113
113
  import { MenuItemMetadataService } from './services/menu-item-metadata.service';
114
114
  import { MqMessageQueueService } from './services/mq-message-queue.service';
115
115
  import { MqMessageService } from './services/mq-message.service';
@@ -586,7 +586,9 @@ import { AlphaNumExternalIdComputationProvider } from './services/computed-field
586
586
  SolidIntrospectService,
587
587
  ImportTransactionService,
588
588
  HttpModule,
589
- ListOfValuesService
589
+ ListOfValuesService,
590
+ ConfigModule,
591
+ PublisherFactory,
590
592
  ],
591
593
  })
592
594
  export class SolidCoreModule { }
@@ -1 +0,0 @@
1
- {"version":3,"file":"ElasticEmailService.d.ts","sourceRoot":"","sources":["../../../src/services/mail/ElasticEmailService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,YAAY,MAAM,0BAA0B,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAkB,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAIvE,qBACa,mBAAoB,YAAW,KAAK;IAMzC,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IAEpC,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IACrC,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAVhC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwC;IAC/D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;gBAIN,mBAAmB,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,EAEpD,gBAAgB,EAAE,gBAAgB,CAAC,GAAG,CAAC,EACvC,oBAAoB,EAAE,oBAAoB,EAC1C,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,WAAW;IAQvC,sBAAsB,CAAC,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EA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AAQ,CAAC,sBAAsB,CAAC,CAAA;QACxE,MAAM,YAAY,GAAG,oBAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAClD,MAAM,IAAI,GAAG,YAAY,CAAC,cAAc,CAAC,CAAC;QAC1C,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAC1D,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACtC,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ,CAAA;AAnKY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;IAMJ,WAAA,IAAA,eAAM,EAAC,uBAAY,CAAC,GAAG,CAAC,CAAA;6CAGU,4CAAgB;QACZ,6CAAoB;QAC9B,wBAAU;QACT,0BAAW;GAXpC,mBAAmB,CAmK/B","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 { EmailAttachment } from 'src/entities/email-attachment.entity';\nimport { QueueMessage } from 'src/interfaces/mq';\nimport { EmailTemplateService } from '../email-template.service';\nimport { PdfService } from '../pdf.service';\nimport { FileService } from '../file.service';\nimport { IMail, MailAttachment, MailAttachmentWrapper } from \"../../interfaces\";\nimport { PublisherFactory } from '../queues/publisher-factory.service';\n\nconst ElasticEmail = require('@elasticemail/elasticemail-client');\n\n@Injectable()\nexport class ElasticEmailService implements IMail {\n private readonly logger = new Logger(ElasticEmailService.name);\n private readonly emailsApi;\n\n constructor(\n @Inject(commonConfig.KEY)\n private readonly commonConfiguration: ConfigType<typeof commonConfig>,\n // private readonly emailPublisher: ApiEmailQueuePublisher,\n private readonly publisherFactory: PublisherFactory<any>,\n private readonly emailTemplateService: EmailTemplateService,\n private readonly pdfService: PdfService,\n private readonly fileService: FileService,\n ) {\n const client = ElasticEmail.ApiClient.instance;\n const apikey = client.authentications['apikey'];\n apikey.apiKey = commonConfiguration.apiMail.key;\n this.emailsApi = new ElasticEmail.EmailsApi();\n }\n\n async sendEmailUsingTemplate(to: string, templateName: string, templateParams: any, shouldQueueEmails = false, parentEntity = null, parentEntityId = null): Promise<void> {\n // Load template and evaluate it. \n const emailTemplate = await this.emailTemplateService.findOneByName(templateName, { attachments: true });\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 // Populate the email with the template.\n const emailTemplateAttachments = emailTemplate.attachments;\n const attachmentWrappers: MailAttachmentWrapper[] = [];\n for (const attachment of emailTemplateAttachments) {\n const attachmentWrapper = await this.toAttachmentWrapper(attachment, templateParams);\n attachmentWrappers.push(attachmentWrapper);\n }\n\n // Finally send the email.\n await this.sendEmail(to, subject, body, shouldQueueEmails, parentEntity, parentEntityId, attachmentWrappers);\n }\n\n async sendEmail(to: string, subject: string, body: string, shouldQueueEmails = false, parentEntity = null, parentEntityId = null, wrapperAttachments: MailAttachmentWrapper[] = []): Promise<void> {\n const message = {\n payload: {\n from: this.commonConfiguration.smtpMail.from,\n to: to,\n subject: subject,\n body: body,\n wrapperAttachments: wrapperAttachments,\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: QueueMessage<any>) {\n const { to, subject, body } = message.payload;\n // this.notificationPublisherService.publish(message);\n // this.emailPublisher.publish(message);\n this.publisherFactory.publish(message, 'ApiEmailQueuePublisher');\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, wrapperAttachments }: { from: string, to: string, subject: string, body: string, wrapperAttachments: MailAttachmentWrapper[] } = message.payload;\n const emailData = {\n Recipients: {\n To: [to]\n },\n Content: {\n Body: [\n {\n ContentType: \"HTML\", //ContentType Text version is handled by elastic email automatically through a config setting\n Charset: \"utf-8\",\n Content: body\n }\n ],\n From: from,\n Subject: subject\n }\n };\n\n // Handle relative attachments i.e attachments that are uploaded to the email service.\n const relativeAttachments = wrapperAttachments.filter(wrapperAttachment => wrapperAttachment.relativePath);\n if (relativeAttachments.length > 0) {\n emailData.Content['AttachFiles'] = relativeAttachments.map(attachment => attachment.relativePath);\n }\n\n const binaryAttachments = wrapperAttachments.filter(wrapperAttachment => wrapperAttachment.attachment);\n if (binaryAttachments.length > 0) {\n //FIXME Replace this with actual attachment.\n // const dummyAttachmentBuffer = await this.dummyAttachment();\n // emailData.Content['Attachments'] = [{\n // \"BinaryContent\": dummyAttachmentBuffer.toString('base64'),\n // \"Name\": \"Invoice.pdf\", \n // }];\n const attachments = [];\n for (const wrapperAttachment of binaryAttachments) {\n const attachment = await this.toMessageAttachment(wrapperAttachment.attachment, wrapperAttachment.attachment.templateParams);\n attachments.push(attachment);\n }\n emailData.Content['Attachments'] = attachments;\n }\n\n const callback = (error, _data, _response) => {\n if (error) {\n this.logger.debug(`Error while sending email to ${to} with subject ${subject}`, error);\n } else {\n this.logger.debug(`Sending email to ${to} with subject ${subject}`);\n }\n };\n\n this.emailsApi.emailsTransactionalPost(emailData, callback);\n }\n\n private async toAttachmentWrapper(attachment: EmailAttachment, templateParams: any): Promise<MailAttachmentWrapper> {\n const attachmentWrapper: MailAttachmentWrapper = {}\n if (attachment.template) {\n attachmentWrapper.attachment = {\n filename: attachment.displayName,\n templatePath: attachment.template,\n templateParams: templateParams,\n }\n } else {\n attachmentWrapper.relativePath = attachment.relativePath\n }\n return attachmentWrapper;\n }\n\n private async toMessageAttachment(attachment: MailAttachment, templateParams: any): Promise<any> {\n const attachmentContent = await this.getAttachmentAsPDF(attachment.templatePath, templateParams);\n return {\n \"BinaryContent\": attachmentContent.toString('base64'),\n \"Name\": attachment.filename,\n }\n }\n\n private async getAttachmentAsPDF(attachmentTemplatePath: string, templateParams: any): Promise<Buffer> {\n const template = await this.fileService.readFile(attachmentTemplatePath)\n const bodyTemplate = Handlebars.compile(template);\n const html = bodyTemplate(templateParams);\n const pdfBuffer = await this.pdfService.generatePdf(html);\n const buffer = Buffer.from(pdfBuffer);\n return buffer;\n }\n}"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"SMTPEmailService.d.ts","sourceRoot":"","sources":["../../../src/services/mail/SMTPEmailService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,YAAY,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAIvE,qBACa,gBAAiB,YAAW,KAAK;IAMtC,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IAGpC,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IATzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqC;IAC5D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAM;gBAIb,mBAAmB,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,EAGpD,gBAAgB,EAAE,gBAAgB,CAAC,GAAG,CAAC,EACvC,oBAAoB,EAAE,oBA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,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,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;AAhHY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;IAMJ,WAAA,IAAA,eAAM,EAAC,uBAAY,CAAC,GAAG,CAAC,CAAA;6CAIU,4CAAgB;QACZ,6CAAoB;GAVtD,gBAAgB,CAgH5B","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[] = []): 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);\n }\n\n async sendEmail(to: string, subject: string, body: string, shouldQueueEmails = false, parentEntity = null, parentEntityId = null, attachments: MailAttachment[] = [], cc: string[] = []): Promise<void> {\n const message = {\n payload: {\n from: this.commonConfiguration.smtpMail.from,\n to: to,\n subject: subject,\n body: body,\n attachments: attachments,\n cc: cc,\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 } = 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 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}"]}