@solidstarters/solid-core 1.2.145 → 1.2.146

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 (97) hide show
  1. package/dist/config/common.config.js +1 -1
  2. package/dist/config/common.config.js.map +1 -1
  3. package/dist/decorators/mail-provider.decorator.d.ts +3 -0
  4. package/dist/decorators/mail-provider.decorator.d.ts.map +1 -0
  5. package/dist/decorators/mail-provider.decorator.js +11 -0
  6. package/dist/decorators/mail-provider.decorator.js.map +1 -0
  7. package/dist/factories/mail.factory.d.ts +14 -0
  8. package/dist/factories/mail.factory.d.ts.map +1 -0
  9. package/dist/factories/mail.factory.js +50 -0
  10. package/dist/factories/mail.factory.js.map +1 -0
  11. package/dist/helpers/solid-registry.d.ts +3 -0
  12. package/dist/helpers/solid-registry.d.ts.map +1 -1
  13. package/dist/helpers/solid-registry.js +7 -0
  14. package/dist/helpers/solid-registry.js.map +1 -1
  15. package/dist/index.d.ts +5 -3
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +10 -4
  18. package/dist/index.js.map +1 -1
  19. package/dist/interfaces.d.ts +2 -2
  20. package/dist/interfaces.d.ts.map +1 -1
  21. package/dist/interfaces.js.map +1 -1
  22. package/dist/jobs/database/{email-publisher-database.service.d.ts → smtp-email-publisher-database.service.d.ts} +2 -2
  23. package/dist/jobs/database/smtp-email-publisher-database.service.d.ts.map +1 -0
  24. package/dist/jobs/database/{email-publisher-database.service.js → smtp-email-publisher-database.service.js} +8 -8
  25. package/dist/jobs/database/smtp-email-publisher-database.service.js.map +1 -0
  26. package/dist/jobs/database/{email-queue-options-database.d.ts → smtp-email-queue-options-database.d.ts} +1 -1
  27. package/dist/jobs/database/smtp-email-queue-options-database.d.ts.map +1 -0
  28. package/dist/jobs/database/{email-queue-options-database.js → smtp-email-queue-options-database.js} +1 -1
  29. package/dist/jobs/database/smtp-email-queue-options-database.js.map +1 -0
  30. package/dist/jobs/database/{email-subscriber-database.service.d.ts → smtp-email-subscriber-database.service.d.ts} +2 -2
  31. package/dist/jobs/database/smtp-email-subscriber-database.service.d.ts.map +1 -0
  32. package/dist/jobs/database/{email-subscriber-database.service.js → smtp-email-subscriber-database.service.js} +8 -8
  33. package/dist/jobs/database/smtp-email-subscriber-database.service.js.map +1 -0
  34. package/dist/jobs/{email-publisher.service.d.ts → smtp-email-publisher.service.d.ts} +2 -2
  35. package/dist/jobs/smtp-email-publisher.service.d.ts.map +1 -0
  36. package/dist/jobs/{email-publisher.service.js → smtp-email-publisher.service.js} +8 -8
  37. package/dist/jobs/smtp-email-publisher.service.js.map +1 -0
  38. package/dist/jobs/{email-queue-options.d.ts → smtp-email-queue-options.d.ts} +1 -1
  39. package/dist/jobs/smtp-email-queue-options.d.ts.map +1 -0
  40. package/dist/jobs/{email-queue-options.js → smtp-email-queue-options.js} +1 -1
  41. package/dist/jobs/smtp-email-queue-options.js.map +1 -0
  42. package/dist/jobs/{email-subscriber.service.d.ts → smtp-email-subscriber.service.d.ts} +2 -2
  43. package/dist/jobs/smtp-email-subscriber.service.d.ts.map +1 -0
  44. package/dist/jobs/{email-subscriber.service.js → smtp-email-subscriber.service.js} +8 -8
  45. package/dist/jobs/smtp-email-subscriber.service.js.map +1 -0
  46. package/dist/seeders/module-metadata-seeder.service.js +27 -27
  47. package/dist/seeders/module-metadata-seeder.service.js.map +1 -1
  48. package/dist/services/authentication.service.d.ts +3 -3
  49. package/dist/services/authentication.service.d.ts.map +1 -1
  50. package/dist/services/authentication.service.js +16 -12
  51. package/dist/services/authentication.service.js.map +1 -1
  52. package/dist/services/mail/elastic-email.service.d.ts.map +1 -1
  53. package/dist/services/mail/elastic-email.service.js +2 -0
  54. package/dist/services/mail/elastic-email.service.js.map +1 -1
  55. package/dist/services/mail/smtp-email.service.d.ts +4 -4
  56. package/dist/services/mail/smtp-email.service.d.ts.map +1 -1
  57. package/dist/services/mail/smtp-email.service.js +7 -5
  58. package/dist/services/mail/smtp-email.service.js.map +1 -1
  59. package/dist/services/solid-introspect.service.d.ts +1 -0
  60. package/dist/services/solid-introspect.service.d.ts.map +1 -1
  61. package/dist/services/solid-introspect.service.js +14 -0
  62. package/dist/services/solid-introspect.service.js.map +1 -1
  63. package/dist/solid-core.module.d.ts.map +1 -1
  64. package/dist/solid-core.module.js +11 -8
  65. package/dist/solid-core.module.js.map +1 -1
  66. package/dist/tsconfig.tsbuildinfo +1 -1
  67. package/package.json +1 -1
  68. package/src/config/common.config.ts +1 -1
  69. package/src/decorators/mail-provider.decorator.ts +7 -0
  70. package/src/factories/mail.factory.ts +38 -0
  71. package/src/helpers/solid-registry.ts +9 -0
  72. package/src/index.ts +8 -3
  73. package/src/interfaces.ts +6 -0
  74. package/src/jobs/database/{email-publisher-database.service.ts → smtp-email-publisher-database.service.ts} +2 -2
  75. package/src/jobs/database/{email-subscriber-database.service.ts → smtp-email-subscriber-database.service.ts} +2 -2
  76. package/src/jobs/{email-publisher.service.ts → smtp-email-publisher.service.ts} +2 -2
  77. package/src/jobs/{email-subscriber.service.ts → smtp-email-subscriber.service.ts} +2 -2
  78. package/src/seeders/module-metadata-seeder.service.ts +27 -27
  79. package/src/services/authentication.service.ts +24 -9
  80. package/src/services/mail/elastic-email.service.ts +2 -0
  81. package/src/services/mail/smtp-email.service.ts +34 -8
  82. package/src/services/solid-introspect.service.ts +21 -5
  83. package/src/solid-core.module.ts +11 -8
  84. package/dist/jobs/database/email-publisher-database.service.d.ts.map +0 -1
  85. package/dist/jobs/database/email-publisher-database.service.js.map +0 -1
  86. package/dist/jobs/database/email-queue-options-database.d.ts.map +0 -1
  87. package/dist/jobs/database/email-queue-options-database.js.map +0 -1
  88. package/dist/jobs/database/email-subscriber-database.service.d.ts.map +0 -1
  89. package/dist/jobs/database/email-subscriber-database.service.js.map +0 -1
  90. package/dist/jobs/email-publisher.service.d.ts.map +0 -1
  91. package/dist/jobs/email-publisher.service.js.map +0 -1
  92. package/dist/jobs/email-queue-options.d.ts.map +0 -1
  93. package/dist/jobs/email-queue-options.js.map +0 -1
  94. package/dist/jobs/email-subscriber.service.d.ts.map +0 -1
  95. package/dist/jobs/email-subscriber.service.js.map +0 -1
  96. /package/src/jobs/database/{email-queue-options-database.ts → smtp-email-queue-options-database.ts} +0 -0
  97. /package/src/jobs/{email-queue-options.ts → smtp-email-queue-options.ts} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidstarters/solid-core",
3
- "version": "1.2.145",
3
+ "version": "1.2.146",
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",
@@ -2,7 +2,7 @@ import { registerAs } from '@nestjs/config';
2
2
 
3
3
  export default registerAs('common', () => {
4
4
  return {
5
- emailProvider: process.env.COMMON_EMAIL_PROVIDER,
5
+ emailProvider: process.env.COMMON_EMAIL_PROVIDER ?? "SMTPEMailService",
6
6
  emailTemplateSeederFiles: process.env.COMMON_EMAIL_TEMPLATE_SEEDER_FILES,
7
7
  smsProvider: process.env.COMMON_SMS_PROVIDER,
8
8
  smsTemplateSeederFiles: process.env.COMMON_SMS_TEMPLATE_SEEDER_FILES,
@@ -0,0 +1,7 @@
1
+ export const IS_MAIL_PROVIDER = 'IS_MAIL_PROVIDER';
2
+
3
+ export const MailProvider = () => {
4
+ return (target: Function) => {
5
+ Reflect.defineMetadata(IS_MAIL_PROVIDER, true, target);
6
+ };
7
+ };
@@ -0,0 +1,38 @@
1
+ import { Inject, Injectable, Logger } from "@nestjs/common";
2
+ import { ConfigType } from "@nestjs/config";
3
+ import { ModuleRef } from "@nestjs/core";
4
+ import commonConfig from "src/config/common.config";
5
+ import { SolidRegistry } from "src/helpers/solid-registry";
6
+ import { IMail } from "src/interfaces";
7
+
8
+ function norm(s?: string) {
9
+ return s?.trim().toLowerCase();
10
+ }
11
+
12
+ // This factory will be use to return a mail service instance, using the configured environment variables
13
+ @Injectable()
14
+ export class MailFactory {
15
+ private readonly logger = new Logger(this.constructor.name);
16
+ constructor(
17
+ private readonly moduleRef: ModuleRef, // Use the module ref to dynamically resolve the mail service
18
+ private readonly solidRegistry: SolidRegistry,
19
+ @Inject(commonConfig.KEY)
20
+ private readonly commonConfiguration: ConfigType<typeof commonConfig>,
21
+ ) { }
22
+
23
+
24
+ getMailService(): IMail {
25
+ const mailServiceName = this.commonConfiguration.emailProvider;
26
+ const mailProviders = this.solidRegistry.getMailProviders();
27
+ // Return the instance which matches the mailServiceName
28
+ if (!mailProviders.length) {
29
+ // throw new Error("No mail providers are registered.");
30
+ this.logger.error("No mail providers are registered.");
31
+ }
32
+
33
+ const mailServiceProvider = mailProviders.find(provider => provider.name === mailServiceName);
34
+
35
+ return mailServiceProvider.instance as IMail;
36
+ }
37
+
38
+ }
@@ -65,6 +65,11 @@ export class SolidRegistry {
65
65
  private computedFieldMetadata: ComputedFieldMetadata[] = [];
66
66
  private dashboardVariableSelectionProviders: Set<InstanceWrapper> = new Set();
67
67
  private dashboardQuestionDataProviders: Set<InstanceWrapper> = new Set();
68
+ private mailProviders: Set<InstanceWrapper> = new Set();
69
+
70
+ registerMailProvider(mailProvider: InstanceWrapper): void {
71
+ this.mailProviders.add(mailProvider);
72
+ }
68
73
 
69
74
  registerController(name: string, methodNames: string[]): void {
70
75
  this.controllers.add({ name: name, methods: methodNames });
@@ -106,6 +111,10 @@ export class SolidRegistry {
106
111
  this.modules = new Set(modules);
107
112
  }
108
113
 
114
+ getMailProviders(): Array<InstanceWrapper> {
115
+ return Array.from(this.mailProviders);
116
+ }
117
+
109
118
  getSeeders(): Array<InstanceWrapper> {
110
119
  return Array.from(this.seeders);
111
120
  }
package/src/index.ts CHANGED
@@ -21,6 +21,8 @@ export * from './decorators/roles.decorator'
21
21
  export * from './decorators/selection-provider.decorator'
22
22
  export * from './decorators/solid-database-module.decorator'
23
23
  export * from './decorators/solid-service.decorator'
24
+ export * from './decorators/mail-provider.decorator'
25
+
24
26
  export * from './dtos/basic-filters.dto'
25
27
  export * from './dtos/solid-request-context.dto'
26
28
  export * from './dtos/change-password.dto'
@@ -177,9 +179,9 @@ export * from './services/scheduled-jobs/scheduler.service';
177
179
  export * from './jobs/api-email-publisher.service'
178
180
  export * from './jobs/api-email-queue-options'
179
181
  export * from './jobs/api-email-subscriber.service'
180
- export * from './jobs/email-publisher.service'
181
- export * from './jobs/email-queue-options'
182
- export * from './jobs/email-subscriber.service'
182
+ export { SmtpEmailQueuePublisherRabbitmq, SmtpEmailQueuePublisherRabbitmq as EmailQueuePublisher } from './jobs/smtp-email-publisher.service' // alias for backward compatibility
183
+ export * from './jobs/smtp-email-queue-options'
184
+ export { SmtpEmailQueueSubscriberRabbitmq, SmtpEmailQueueSubscriberRabbitmq as EmailQueueSubscriber } from './jobs/smtp-email-subscriber.service' // alias for backward compatibility
183
185
  export * from './jobs/otp-publisher.service'
184
186
  export * from './jobs/otp-queue-options'
185
187
  export * from './jobs/otp-subscriber.service'
@@ -261,6 +263,9 @@ export * from './services/queues/publisher-factory.service'
261
263
  export * from './services/queues/database-publisher.service'
262
264
  export * from './services/queues/database-subscriber.service'
263
265
 
266
+ // Factories
267
+ export * from './factories/mail.factory'
268
+
264
269
  // Repositories
265
270
  export * from './repository/solid-base.repository'
266
271
  export * from './repository/security-rule.repository'
package/src/interfaces.ts CHANGED
@@ -169,6 +169,9 @@ export interface IMail {
169
169
  attachments?: MailAttachment[],
170
170
  parentEntity?: any,
171
171
  parentEntityId?: any,
172
+ cc?: string[],
173
+ bcc?: string[],
174
+ from?: string,
172
175
  ): Promise<void>;
173
176
 
174
177
  sendEmailUsingTemplate(
@@ -180,6 +183,9 @@ export interface IMail {
180
183
  attachments?: MailAttachment[],
181
184
  parentEntity?: any,
182
185
  parentEntityId?: any,
186
+ cc?: string[],
187
+ bcc?: string[],
188
+ from?: string,
183
189
  ): Promise<void>;
184
190
  }
185
191
 
@@ -1,13 +1,13 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
 
3
- import mailQueueOptions from './email-queue-options-database';
3
+ import mailQueueOptions from './smtp-email-queue-options-database';
4
4
  import { MqMessageQueueService } from 'src/services/mq-message-queue.service';
5
5
  import { MqMessageService } from 'src/services/mq-message.service';
6
6
  import { QueuesModuleOptions } from 'src/interfaces';
7
7
  import { DatabasePublisher } from 'src/services/queues/database-publisher.service';
8
8
 
9
9
  @Injectable()
10
- export class EmailQueuePublisherDatabase extends DatabasePublisher<any> {
10
+ export class SmtpEmailQueuePublisherDatabase extends DatabasePublisher<any> {
11
11
  constructor(
12
12
  protected readonly mqMessageService: MqMessageService,
13
13
  protected readonly mqMessageQueueService: MqMessageQueueService,
@@ -1,6 +1,6 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
 
3
- import mailQueueOptions from './email-queue-options-database';
3
+ import mailQueueOptions from './smtp-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';
@@ -9,7 +9,7 @@ import { SMTPEMailService } from 'src/services/mail/smtp-email.service';
9
9
  import { QueuesModuleOptions } from 'src/interfaces';
10
10
 
11
11
  @Injectable()
12
- export class EmailQueueSubscriberDatabase extends DatabaseSubscriber<any> {
12
+ export class SmtpEmailQueueSubscriberDatabase extends DatabaseSubscriber<any> {
13
13
  constructor(
14
14
  private readonly emailService: SMTPEMailService,
15
15
  readonly mqMessageService: MqMessageService,
@@ -1,13 +1,13 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
 
3
3
  import { RabbitMqPublisher } from 'src/services/queues/rabbitmq-publisher.service';
4
- import mailQueueOptions from './email-queue-options';
4
+ import mailQueueOptions from './smtp-email-queue-options';
5
5
  import { MqMessageQueueService } from 'src/services/mq-message-queue.service';
6
6
  import { MqMessageService } from 'src/services/mq-message.service';
7
7
  import { QueuesModuleOptions } from "../interfaces";
8
8
 
9
9
  @Injectable()
10
- export class EmailQueuePublisher extends RabbitMqPublisher<any> {
10
+ export class SmtpEmailQueuePublisherRabbitmq extends RabbitMqPublisher<any> {
11
11
  constructor(
12
12
  protected readonly mqMessageService: MqMessageService,
13
13
  protected readonly mqMessageQueueService: MqMessageQueueService,
@@ -1,6 +1,6 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
 
3
- import mailQueueOptions from './email-queue-options';
3
+ import mailQueueOptions from './smtp-email-queue-options';
4
4
  import { RabbitMqSubscriber } from 'src/services/queues/rabbitmq-subscriber.service';
5
5
  import { QueueMessage } from 'src/interfaces/mq';
6
6
  import { SMTPEMailService } from '../services/mail/smtp-email.service';
@@ -9,7 +9,7 @@ import { MqMessageQueueService } from 'src/services/mq-message-queue.service';
9
9
  import { QueuesModuleOptions } from "../interfaces";
10
10
 
11
11
  @Injectable()
12
- export class EmailQueueSubscriber extends RabbitMqSubscriber<any> {
12
+ export class SmtpEmailQueueSubscriberRabbitmq extends RabbitMqSubscriber<any> {
13
13
  constructor(
14
14
  private readonly emailService: SMTPEMailService,
15
15
  readonly mqMessageService: MqMessageService,
@@ -134,18 +134,18 @@ export class ModuleMetadataSeederService {
134
134
 
135
135
  // Process module metadata first.
136
136
  const moduleMetadata: CreateModuleMetadataDto = overallMetadata.moduleMetadata;
137
- this.logger.debug(`[Start] Processing module metadata for ${moduleMetadata.name}`)
137
+ this.logger.log(`[Start] Processing module metadata for ${moduleMetadata.name}`)
138
138
  await this.seedModuleModelFields(moduleMetadata);
139
- this.logger.debug(`[End] Processing module metadata for ${moduleMetadata.name}`)
139
+ this.logger.log(`[End] Processing module metadata for ${moduleMetadata.name}`)
140
140
 
141
141
  // Media Storage provider templates
142
- this.logger.debug(`[Start] Processing Media Storage Provider for ${moduleMetadata.name}`);
142
+ this.logger.log(`[Start] Processing Media Storage Provider for ${moduleMetadata.name}`);
143
143
  const mediaStorageProviders = overallMetadata.mediaStorageProviders;
144
144
  await this.seedMediaStorageProviders(mediaStorageProviders);
145
- this.logger.debug(`[End] Processing Media Storage Provider for ${moduleMetadata.name}`);
145
+ this.logger.log(`[End] Processing Media Storage Provider for ${moduleMetadata.name}`);
146
146
 
147
147
  // Custom role handling
148
- this.logger.debug(`[End] Processing roles for ${moduleMetadata.name}`)
148
+ this.logger.log(`[End] Processing roles for ${moduleMetadata.name}`)
149
149
  const roles = overallMetadata.roles;
150
150
 
151
151
  // Every role configuration in the seeder json can optionally have a permissions attribute.
@@ -159,67 +159,67 @@ export class ModuleMetadataSeederService {
159
159
  await this.roleService.addPermissionsToRole(role.name, role.permissions)
160
160
  }
161
161
  }
162
- this.logger.debug(`[End] Processing roles for ${moduleMetadata.name}`)
162
+ this.logger.log(`[End] Processing roles for ${moduleMetadata.name}`)
163
163
 
164
164
  // Custom user handling
165
- this.logger.debug(`[Start] Processing users for ${moduleMetadata.name}`);
165
+ this.logger.log(`[Start] Processing users for ${moduleMetadata.name}`);
166
166
  const users = overallMetadata.users;
167
167
  usersDetail = users;
168
168
  await this.seedUsers(users);
169
- this.logger.debug(`[End] Processing users for ${moduleMetadata.name}`)
169
+ this.logger.log(`[End] Processing users for ${moduleMetadata.name}`)
170
170
 
171
171
  // Application Module View handling
172
- this.logger.debug(`[Start] Processing views for ${moduleMetadata.name}`);
172
+ this.logger.log(`[Start] Processing views for ${moduleMetadata.name}`);
173
173
  const views = overallMetadata.views;
174
174
  await this.seedViews(views);
175
- this.logger.debug(`[End] Processing views for ${moduleMetadata.name}`)
175
+ this.logger.log(`[End] Processing views for ${moduleMetadata.name}`)
176
176
 
177
177
  // Application Module Action handling
178
- this.logger.debug(`[Start] Processing actions for ${moduleMetadata.name}`);
178
+ this.logger.log(`[Start] Processing actions for ${moduleMetadata.name}`);
179
179
  const actions = overallMetadata.actions;
180
180
  await this.seedActions(actions);
181
- this.logger.debug(`[End] Processing actions for ${moduleMetadata.name}`)
181
+ this.logger.log(`[End] Processing actions for ${moduleMetadata.name}`)
182
182
 
183
183
  // Application Module Menu handling
184
- this.logger.debug(`[Start] Processing menus for ${moduleMetadata.name}`);
184
+ this.logger.log(`[Start] Processing menus for ${moduleMetadata.name}`);
185
185
  const menus = overallMetadata.menus;
186
186
  await this.seedMenus(menus);
187
- this.logger.debug(`[End] Processing menus for ${moduleMetadata.name}`)
187
+ this.logger.log(`[End] Processing menus for ${moduleMetadata.name}`)
188
188
 
189
189
  // Email templates
190
- this.logger.debug(`[Start] Processing email templates for ${moduleMetadata.name}`);
190
+ this.logger.log(`[Start] Processing email templates for ${moduleMetadata.name}`);
191
191
  const emailTemplates: CreateEmailTemplateDto[] = overallMetadata.emailTemplates;
192
192
  await this.seedEmailTemplates(emailTemplates, moduleMetadata);
193
- this.logger.debug(`[End] Processing email templates for ${moduleMetadata.name}`);
193
+ this.logger.log(`[End] Processing email templates for ${moduleMetadata.name}`);
194
194
 
195
195
  // Sms templates
196
- this.logger.debug(`[Start] Processing sms templates for ${moduleMetadata.name}`);
196
+ this.logger.log(`[Start] Processing sms templates for ${moduleMetadata.name}`);
197
197
  const smsTemplates: CreateSmsTemplateDto[] = overallMetadata.smsTemplates;
198
198
  await this.seedSmsTemplates(smsTemplates);
199
- this.logger.debug(`[End] Processing sms templates for ${moduleMetadata.name}`);
199
+ this.logger.log(`[End] Processing sms templates for ${moduleMetadata.name}`);
200
200
 
201
201
  // Settings
202
- this.logger.debug(`[Start] Processing settings for ${moduleMetadata.name}`);
202
+ this.logger.log(`[Start] Processing settings for ${moduleMetadata.name}`);
203
203
  await this.seetingService.seedDefaultSettings();
204
- this.logger.debug(`[End] Processing settings for ${moduleMetadata.name}`);
204
+ this.logger.log(`[End] Processing settings for ${moduleMetadata.name}`);
205
205
 
206
206
  // Security rules
207
- this.logger.debug(`[Start] Processing security rules for ${moduleMetadata.name}`);
207
+ this.logger.log(`[Start] Processing security rules for ${moduleMetadata.name}`);
208
208
  const securityRules: CreateSecurityRuleDto[] = overallMetadata.securityRules;
209
209
  await this.seedSecurityRules(securityRules);
210
- this.logger.debug(`[End] Processing security rules for ${moduleMetadata.name}`);
210
+ this.logger.log(`[End] Processing security rules for ${moduleMetadata.name}`);
211
211
 
212
212
  // List Of Values
213
- this.logger.debug(`[Start] Processing List Of Values for ${moduleMetadata.name}`);
213
+ this.logger.log(`[Start] Processing List Of Values for ${moduleMetadata.name}`);
214
214
  const listOfValues: CreateListOfValuesDto[] = overallMetadata.listOfValues;
215
215
  await this.seedListOfValues(listOfValues);
216
- this.logger.debug(`[End] Processing List Of Values for ${moduleMetadata.name}`);
216
+ this.logger.log(`[End] Processing List Of Values for ${moduleMetadata.name}`);
217
217
 
218
218
  // Dashboards
219
- this.logger.debug(`[Start] Processing dashboards for ${moduleMetadata.name}`);
219
+ this.logger.log(`[Start] Processing dashboards for ${moduleMetadata.name}`);
220
220
  const dashboards: CreateDashboardDto[] = overallMetadata.dashboards;
221
221
  await this.seedDashboards(dashboards);
222
- this.logger.debug(`[End] Processing dashboards for ${moduleMetadata.name}`);
222
+ this.logger.log(`[End] Processing dashboards for ${moduleMetadata.name}`);
223
223
 
224
224
 
225
225
  this.logger.debug(`[End] module seed data: ${overallMetadata}`);
@@ -229,7 +229,7 @@ export class ModuleMetadataSeederService {
229
229
  // Post seed data file processing.
230
230
 
231
231
  // 1. Give all permissions to the Admin role.
232
- this.logger.debug(`About to add all permissions to the Admin role`);
232
+ this.logger.log(`About to add all permissions to the Admin role`);
233
233
  await this.roleService.addAllPermissionsToRole("Admin");
234
234
  // 2. Give wrapSettings permissions to the Public role.
235
235
  const internalRolePermission = [
@@ -34,7 +34,7 @@ import { ActiveUserData } from '../interfaces/active-user-data.interface';
34
34
  import { HashingService } from './hashing.service';
35
35
  import { InvalidatedRefreshTokenError, RefreshTokenIdsStorageService } from './refresh-token-ids-storage.service';
36
36
  import { UserService } from './user.service';
37
- import { EventDetails, EventType } from "../interfaces";
37
+ import { EventDetails, EventType, IMail } from "../interfaces";
38
38
  import {
39
39
  ForgotPasswordSendVerificationTokenOn,
40
40
  RegistrationValidationSource,
@@ -48,6 +48,7 @@ import { UserActivityHistoryService } from './user-activity-history.service';
48
48
  import { RequestContextService } from './request-context.service';
49
49
  import { ERROR_MESSAGES } from 'src/constants/error-messages';
50
50
  import { SUCCESS_MESSAGES } from 'src/constants/success-messages';
51
+ import { MailFactory } from 'src/factories/mail.factory';
51
52
 
52
53
 
53
54
  enum LoginProvider {
@@ -64,7 +65,7 @@ interface otp {
64
65
  @Injectable()
65
66
  export class AuthenticationService {
66
67
  private readonly logger = new Logger(AuthenticationService.name);
67
-
68
+ // private readonly mailService: IMail;
68
69
  constructor(
69
70
  private readonly userService: UserService,
70
71
  @InjectRepository(User) private readonly userRepository: Repository<User>,
@@ -77,7 +78,8 @@ export class AuthenticationService {
77
78
  private readonly iamConfiguration: ConfigType<typeof iamConfig>,
78
79
  private readonly refreshTokenIdsStorage: RefreshTokenIdsStorageService,
79
80
  private readonly httpService: HttpService,
80
- private readonly mailService: SMTPEMailService,
81
+ // private readonly mailService: SMTPEMailService,
82
+ private readonly mailServiceFactory: MailFactory,
81
83
  private readonly smsService: Msg91OTPService,
82
84
  private readonly eventEmitter: EventEmitter2,
83
85
  private readonly settingService: SettingService,
@@ -86,7 +88,9 @@ export class AuthenticationService {
86
88
  private readonly commonConfiguration: ConfigType<typeof commonConfig>,
87
89
  private readonly userActivityHistoryService: UserActivityHistoryService,
88
90
  private readonly requestContextService: RequestContextService,
89
- ) { }
91
+ ) {
92
+ // this.mailService = this.mailServiceFactory.getMailService();
93
+ }
90
94
 
91
95
  private async getConfig(key: string): Promise<any> {
92
96
  return this.settingService.getConfigValue(key);
@@ -253,8 +257,8 @@ export class AuthenticationService {
253
257
 
254
258
  private async notifyUserOnForcePasswordChange(user: User, autoGeneratedPwd: string) {
255
259
  const companyLogo = await this.getCompanyLogo();
256
-
257
- this.mailService.sendEmailUsingTemplate(
260
+ const mailService = this.mailServiceFactory.getMailService();
261
+ mailService.sendEmailUsingTemplate(
258
262
  user.email,
259
263
  'on-force-password-change',
260
264
  {
@@ -268,6 +272,8 @@ export class AuthenticationService {
268
272
  companyLogoUrl: companyLogo
269
273
  },
270
274
  this.commonConfiguration.shouldQueueEmails,
275
+ null,
276
+ null,
271
277
  'user',
272
278
  user.id
273
279
  );
@@ -375,7 +381,8 @@ export class AuthenticationService {
375
381
  if (this.iamConfiguration.dummyOtp)
376
382
  return; // Do nothing if dummy otp is configured.
377
383
  if (registrationValidationSources.includes(RegistrationValidationSource.EMAIL)) {
378
- this.mailService.sendEmailUsingTemplate(
384
+ const mailService = this.mailServiceFactory.getMailService();
385
+ mailService.sendEmailUsingTemplate(
379
386
  user.email,
380
387
  'otp-on-register',
381
388
  {
@@ -387,6 +394,8 @@ export class AuthenticationService {
387
394
  companyLogoUrl: companyLogo
388
395
  },
389
396
  this.commonConfiguration.shouldQueueEmails,
397
+ null,
398
+ null,
390
399
  'user',
391
400
  user.id
392
401
  );
@@ -563,7 +572,8 @@ export class AuthenticationService {
563
572
  if (this.iamConfiguration.dummyOtp)
564
573
  return; // Do nothing if dummy otp is configured.
565
574
  if (loginType === RegistrationValidationSource.EMAIL) {
566
- this.mailService.sendEmailUsingTemplate(
575
+ const mailService = this.mailServiceFactory.getMailService();
576
+ mailService.sendEmailUsingTemplate(
567
577
  user.email,
568
578
  'otp-on-login',
569
579
  {
@@ -575,6 +585,8 @@ export class AuthenticationService {
575
585
  companyLogoUrl: companyLogo
576
586
  },
577
587
  this.commonConfiguration.shouldQueueEmails,
588
+ null,
589
+ null,
578
590
  'user',
579
591
  user.id
580
592
  );
@@ -767,7 +779,8 @@ export class AuthenticationService {
767
779
  const forgotPasswordSendVerificationTokenOn = this.iamConfiguration.forgotPasswordSendVerificationTokenOn;
768
780
 
769
781
  if (forgotPasswordSendVerificationTokenOn == ForgotPasswordSendVerificationTokenOn.EMAIL) {
770
- this.mailService.sendEmailUsingTemplate(
782
+ const mailService = this.mailServiceFactory.getMailService();
783
+ mailService.sendEmailUsingTemplate(
771
784
  user.email,
772
785
  'forgot-password',
773
786
  {
@@ -780,6 +793,8 @@ export class AuthenticationService {
780
793
  companyLogoUrl: companyLogo
781
794
  },
782
795
  this.commonConfiguration.shouldQueueEmails,
796
+ null,
797
+ null,
783
798
  'user',
784
799
  user.id
785
800
  );
@@ -9,10 +9,12 @@ import { PdfService } from '../pdf.service';
9
9
  import { FileService } from '../file.service';
10
10
  import { IMail, MailAttachment, MailAttachmentWrapper } from "../../interfaces";
11
11
  import { PublisherFactory } from '../queues/publisher-factory.service';
12
+ import { MailProvider } from 'src/decorators/mail-provider.decorator';
12
13
 
13
14
  const ElasticEmail = require('@elasticemail/elasticemail-client');
14
15
 
15
16
  @Injectable()
17
+ @MailProvider()
16
18
  export class ElasticEmailService implements IMail {
17
19
  private readonly logger = new Logger(ElasticEmailService.name);
18
20
  private readonly emailsApi;
@@ -1,15 +1,17 @@
1
1
  import { Inject, Injectable, Logger } from '@nestjs/common';
2
2
  import { ConfigType } from '@nestjs/config';
3
- import { QueueMessage } from 'src/interfaces/mq';
3
+ import Handlebars from "handlebars";
4
4
  import commonConfig from 'src/config/common.config';
5
+ import { MailProvider } from 'src/decorators/mail-provider.decorator';
6
+ import { QueueMessage } from 'src/interfaces/mq';
7
+ import { IMail, MailAttachment, MailAttachmentWrapper } from "../../interfaces";
5
8
  import { EmailTemplateService } from '../email-template.service';
6
- import Handlebars from "handlebars";
7
- import { IMail, MailAttachment } from "../../interfaces";
8
9
  import { PublisherFactory } from '../queues/publisher-factory.service';
9
10
 
10
11
  const nodemailer = require("nodemailer");
11
12
 
12
13
  @Injectable()
14
+ @MailProvider()
13
15
  export class SMTPEMailService implements IMail {
14
16
  private readonly logger = new Logger(SMTPEMailService.name);
15
17
  private readonly transporter: any;
@@ -33,8 +35,20 @@ export class SMTPEMailService implements IMail {
33
35
  });
34
36
  }
35
37
 
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
- // Load template and evaluate it.
38
+ async sendEmailUsingTemplate(
39
+ to: string,
40
+ templateName: string,
41
+ templateParams: any,
42
+ shouldQueueEmails = false,
43
+ wrapperAttachments?: MailAttachmentWrapper[],
44
+ attachments?: MailAttachment[],
45
+ parentEntity?: any,
46
+ parentEntityId?: any,
47
+ cc?: string[],
48
+ bcc?: string[],
49
+ from?: string
50
+ ): Promise<void> {
51
+ // Load template and evaluate it.
38
52
  const emailTemplate = await this.emailTemplateService.findOneByName(templateName);
39
53
  if (!emailTemplate) {
40
54
  throw new Error(`Invalid template name ${templateName}`);
@@ -49,10 +63,22 @@ export class SMTPEMailService implements IMail {
49
63
  const subject = subjectTemplate(templateParams);
50
64
 
51
65
  // Finally send the email.
52
- await this.sendEmail(to, subject, body, shouldQueueEmails, parentEntity, parentEntityId, attachments, cc, bcc, from);
66
+ await this.sendEmail(to, subject, body, shouldQueueEmails, wrapperAttachments, attachments, parentEntity, parentEntityId, cc, bcc, from);
53
67
  }
54
68
 
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> {
69
+ async sendEmail(
70
+ to: string,
71
+ subject: string,
72
+ body: string,
73
+ shouldQueueEmails = false,
74
+ wrapperAttachments?: MailAttachmentWrapper[],
75
+ attachments?: MailAttachment[],
76
+ parentEntity?: any,
77
+ parentEntityId?: any,
78
+ cc?: string[],
79
+ bcc?: string[],
80
+ from?: string
81
+ ): Promise<void> {
56
82
  const message = {
57
83
  payload: {
58
84
  from: from || this.commonConfiguration.smtpMail.from,
@@ -87,7 +113,7 @@ export class SMTPEMailService implements IMail {
87
113
  // this.emailPublisher.publish(message);
88
114
  // this.emailDbPublisher.publish(message);
89
115
 
90
- this.publisherFactory.publish(message, 'EmailQueuePublisher');
116
+ this.publisherFactory.publish(message, 'SmtpEmailQueuePublisher');
91
117
 
92
118
  this.logger.debug(`Queueing email to ${to} with subject ${subject} and body ${body}`);
93
119
  }
@@ -10,6 +10,7 @@ import { CRUDService } from './crud.service';
10
10
  import { IS_SCHEDULED_JOB_PROVIDER } from 'src/decorators/scheduled-job-provider.decorator';
11
11
  import { IS_DASHBOARD_VARIABLE_SELECTION_PROVIDER } from 'src/decorators/dashboard-selection-provider.decorator';
12
12
  import { IS_DASHBOARD_QUESTION_DATA_PROVIDER } from 'src/decorators/dashboard-question-data-provider.decorator';
13
+ import { IS_MAIL_PROVIDER } from 'src/decorators/mail-provider.decorator';
13
14
 
14
15
  @Injectable()
15
16
  export class SolidIntrospectService implements OnApplicationBootstrap {
@@ -40,7 +41,6 @@ export class SolidIntrospectService implements OnApplicationBootstrap {
40
41
  .filter((provider) => this.isSelectionProvider(provider));
41
42
 
42
43
  selectionProviders.forEach((selectionProvider) => {
43
- // @ts-ignore
44
44
  this.solidRegistry.registerSelectionProvider(selectionProvider);
45
45
  });
46
46
 
@@ -50,7 +50,6 @@ export class SolidIntrospectService implements OnApplicationBootstrap {
50
50
  .filter((provider) => this.isDashboardVariableSelectionProvider(provider));
51
51
 
52
52
  dashboardVariableSelectionProviders.forEach((dashboardSelectionProvider) => {
53
- // @ts-ignore
54
53
  this.solidRegistry.registerDashboardVariableSelectionProvider(dashboardSelectionProvider);
55
54
  });
56
55
 
@@ -60,7 +59,6 @@ export class SolidIntrospectService implements OnApplicationBootstrap {
60
59
  .filter((provider) => this.isDashboardQuestionDataProvider(provider));
61
60
 
62
61
  dashboardQuestionDataProviders.forEach((provider) => {
63
- // @ts-ignore
64
62
  this.solidRegistry.registerDashboardQuestionDataProvider(provider);
65
63
  });
66
64
 
@@ -81,7 +79,6 @@ export class SolidIntrospectService implements OnApplicationBootstrap {
81
79
  .filter((provider) => this.isSolidDatabaseModule(provider));
82
80
 
83
81
  solidDatabaseModules.forEach((solidDatabaseModule) => {
84
- // @ts-ignore
85
82
  this.solidRegistry.registerSolidDatabaseModule(solidDatabaseModule);
86
83
  });
87
84
 
@@ -110,10 +107,17 @@ export class SolidIntrospectService implements OnApplicationBootstrap {
110
107
  .filter((provider) => this.isScheduledJobProvider(provider));
111
108
 
112
109
  scheduledJobProviders.forEach((scheduledJobProvider) => {
113
- // @ts-ignore
114
110
  this.solidRegistry.registerScheduledJobProvider(scheduledJobProvider);
115
111
  });
116
112
 
113
+ // Register all IMail implementations
114
+ const mailProviders = this.discoveryService
115
+ .getProviders()
116
+ .filter((provider) => this.isMailProvider(provider));
117
+
118
+ mailProviders.forEach((mailProvider) => {
119
+ this.solidRegistry.registerMailProvider(mailProvider);
120
+ });
117
121
  }
118
122
 
119
123
  isDashboardQuestionDataProvider(providerWrapper: InstanceWrapper<any>) {
@@ -196,6 +200,18 @@ export class SolidIntrospectService implements OnApplicationBootstrap {
196
200
  return !!isSolidDatabaseModule;
197
201
  }
198
202
 
203
+ private isMailProvider(provider: InstanceWrapper) {
204
+ const { instance } = provider;
205
+ if (!instance) return false;
206
+
207
+ const isMailProvider = this.reflector.get<boolean>(
208
+ IS_MAIL_PROVIDER,
209
+ instance.constructor,
210
+ );
211
+
212
+ return !!isMailProvider;
213
+ }
214
+
199
215
  private isModule(provider: InstanceWrapper): boolean {
200
216
  const metatype = provider.metatype;
201
217
  // Check if it's a Static Module (Class-Based)