@solidstarters/solid-core 1.2.143 → 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.
- package/dist/config/common.config.d.ts +2 -0
- package/dist/config/common.config.d.ts.map +1 -1
- package/dist/config/common.config.js +3 -2
- package/dist/config/common.config.js.map +1 -1
- package/dist/constants/error-messages.d.ts +83 -0
- package/dist/constants/error-messages.d.ts.map +1 -0
- package/dist/constants/error-messages.js +86 -0
- package/dist/constants/error-messages.js.map +1 -0
- package/dist/constants/success-messages.d.ts +11 -0
- package/dist/constants/success-messages.d.ts.map +1 -0
- package/dist/constants/success-messages.js +14 -0
- package/dist/constants/success-messages.js.map +1 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -4
- package/dist/index.js.map +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/jobs/api-email-subscriber.service.d.ts +1 -1
- package/dist/jobs/api-email-subscriber.service.d.ts.map +1 -1
- package/dist/jobs/api-email-subscriber.service.js +2 -2
- package/dist/jobs/api-email-subscriber.service.js.map +1 -1
- package/dist/jobs/database/api-email-subscriber-database.service.d.ts +1 -1
- package/dist/jobs/database/api-email-subscriber-database.service.d.ts.map +1 -1
- package/dist/jobs/database/api-email-subscriber-database.service.js +2 -2
- package/dist/jobs/database/api-email-subscriber-database.service.js.map +1 -1
- package/dist/jobs/database/email-subscriber-database.service.d.ts +1 -1
- package/dist/jobs/database/email-subscriber-database.service.d.ts.map +1 -1
- package/dist/jobs/database/email-subscriber-database.service.js +2 -2
- package/dist/jobs/database/email-subscriber-database.service.js.map +1 -1
- package/dist/jobs/email-subscriber.service.d.ts +1 -1
- package/dist/jobs/email-subscriber.service.d.ts.map +1 -1
- package/dist/jobs/email-subscriber.service.js +2 -2
- package/dist/jobs/email-subscriber.service.js.map +1 -1
- package/dist/seeders/seed-data/solid-core-metadata.json +12 -12
- package/dist/services/ai-interaction.service.d.ts.map +1 -1
- package/dist/services/ai-interaction.service.js +4 -3
- package/dist/services/ai-interaction.service.js.map +1 -1
- package/dist/services/authentication.service.d.ts +1 -1
- package/dist/services/authentication.service.d.ts.map +1 -1
- package/dist/services/authentication.service.js +68 -66
- package/dist/services/authentication.service.js.map +1 -1
- package/dist/services/crud-helper.service.d.ts.map +1 -1
- package/dist/services/crud-helper.service.js +3 -2
- package/dist/services/crud-helper.service.js.map +1 -1
- package/dist/services/crud.service.d.ts.map +1 -1
- package/dist/services/crud.service.js +23 -21
- package/dist/services/crud.service.js.map +1 -1
- package/dist/services/csv.service.d.ts.map +1 -1
- package/dist/services/csv.service.js +3 -2
- package/dist/services/csv.service.js.map +1 -1
- package/dist/services/excel.service.d.ts.map +1 -1
- package/dist/services/excel.service.js +3 -2
- package/dist/services/excel.service.js.map +1 -1
- package/dist/services/export-transaction.service.d.ts.map +1 -1
- package/dist/services/export-transaction.service.js +2 -1
- package/dist/services/export-transaction.service.js.map +1 -1
- package/dist/services/field-metadata.service.d.ts.map +1 -1
- package/dist/services/field-metadata.service.js +9 -8
- package/dist/services/field-metadata.service.js.map +1 -1
- package/dist/services/file.service.d.ts.map +1 -1
- package/dist/services/file.service.js +5 -4
- package/dist/services/file.service.js.map +1 -1
- package/dist/services/import-transaction.service.d.ts.map +1 -1
- package/dist/services/import-transaction.service.js +11 -9
- package/dist/services/import-transaction.service.js.map +1 -1
- package/dist/services/mail/{ElasticEmailService.d.ts → elastic-email.service.d.ts} +1 -1
- package/dist/services/mail/elastic-email.service.d.ts.map +1 -0
- package/dist/services/mail/{ElasticEmailService.js → elastic-email.service.js} +1 -1
- package/dist/services/mail/elastic-email.service.js.map +1 -0
- package/dist/services/mail/{SMTPEmailService.d.ts → smtp-email.service.d.ts} +3 -3
- package/dist/services/mail/smtp-email.service.d.ts.map +1 -0
- package/dist/services/mail/{SMTPEmailService.js → smtp-email.service.js} +8 -6
- package/dist/services/mail/smtp-email.service.js.map +1 -0
- package/dist/services/media-storage-provider-metadata.service.d.ts.map +1 -1
- package/dist/services/media-storage-provider-metadata.service.js +4 -3
- package/dist/services/media-storage-provider-metadata.service.js.map +1 -1
- package/dist/services/media.service.d.ts.map +1 -1
- package/dist/services/media.service.js +2 -1
- package/dist/services/media.service.js.map +1 -1
- package/dist/services/model-metadata.service.d.ts.map +1 -1
- package/dist/services/model-metadata.service.js +11 -10
- package/dist/services/model-metadata.service.js.map +1 -1
- package/dist/services/module-metadata.service.d.ts.map +1 -1
- package/dist/services/module-metadata.service.js +11 -10
- package/dist/services/module-metadata.service.js.map +1 -1
- package/dist/services/role-metadata.service.d.ts.map +1 -1
- package/dist/services/role-metadata.service.js +3 -2
- package/dist/services/role-metadata.service.js.map +1 -1
- package/dist/services/sql-expression-resolver.service.d.ts.map +1 -1
- package/dist/services/sql-expression-resolver.service.js +2 -1
- package/dist/services/sql-expression-resolver.service.js.map +1 -1
- package/dist/services/user.service.d.ts.map +1 -1
- package/dist/services/user.service.js +11 -10
- package/dist/services/user.service.js.map +1 -1
- package/dist/solid-core.module.d.ts.map +1 -1
- package/dist/solid-core.module.js +9 -7
- package/dist/solid-core.module.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/config/common.config.ts +3 -2
- package/src/constants/error-messages.ts +123 -0
- package/src/constants/success-messages.ts +13 -0
- package/src/index.ts +10 -4
- package/src/interfaces.ts +3 -3
- package/src/jobs/api-email-subscriber.service.ts +1 -1
- package/src/jobs/database/api-email-subscriber-database.service.ts +1 -1
- package/src/jobs/database/email-subscriber-database.service.ts +1 -1
- package/src/jobs/email-subscriber.service.ts +1 -1
- package/src/seeders/seed-data/solid-core-metadata.json +12 -12
- package/src/services/ai-interaction.service.ts +4 -3
- package/src/services/authentication.service.ts +67 -65
- package/src/services/crud-helper.service.ts +3 -2
- package/src/services/crud.service.ts +23 -23
- package/src/services/csv.service.ts +3 -2
- package/src/services/excel.service.ts +3 -2
- package/src/services/export-transaction.service.ts +2 -1
- package/src/services/field-metadata.service.ts +9 -8
- package/src/services/file.service.ts +5 -4
- package/src/services/import-transaction.service.ts +11 -9
- package/src/services/mail/{SMTPEmailService.ts → smtp-email.service.ts} +7 -5
- package/src/services/media-storage-provider-metadata.service.ts +4 -3
- package/src/services/media.service.ts +2 -1
- package/src/services/model-metadata.service.ts +11 -10
- package/src/services/module-metadata.service.ts +11 -10
- package/src/services/role-metadata.service.ts +3 -2
- package/src/services/sql-expression-resolver.service.ts +2 -1
- package/src/services/user.service.ts +11 -10
- package/src/solid-core.module.ts +5 -3
- package/dist/services/mail/ElasticEmailService.d.ts.map +0 -1
- package/dist/services/mail/ElasticEmailService.js.map +0 -1
- package/dist/services/mail/SMTPEmailService.d.ts.map +0 -1
- package/dist/services/mail/SMTPEmailService.js.map +0 -1
- /package/src/services/mail/{ElasticEmailService.ts → elastic-email.service.ts} +0 -0
|
@@ -15,6 +15,7 @@ import { RoleMetadata } from '../entities/role-metadata.entity';
|
|
|
15
15
|
import { User } from '../entities/user.entity';
|
|
16
16
|
import { ActiveUserData } from '../interfaces/active-user-data.interface';
|
|
17
17
|
import { iamConfig } from 'src/config/iam.config';
|
|
18
|
+
import { ERROR_MESSAGES } from 'src/constants/error-messages';
|
|
18
19
|
|
|
19
20
|
@Injectable()
|
|
20
21
|
export class UserService extends CRUDService<User> {
|
|
@@ -42,7 +43,7 @@ export class UserService extends CRUDService<User> {
|
|
|
42
43
|
override async delete(id: number, solidRequestContext: any = {}) {
|
|
43
44
|
// Prevent user from deleting themselves
|
|
44
45
|
if (solidRequestContext?.activeUser?.sub === id) {
|
|
45
|
-
throw new BadRequestException(
|
|
46
|
+
throw new BadRequestException(ERROR_MESSAGES.DELETE_SELF_NOT_ALLOWED);
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
// ✅ Proceed with the default deletion logic
|
|
@@ -51,12 +52,12 @@ export class UserService extends CRUDService<User> {
|
|
|
51
52
|
|
|
52
53
|
override async deleteMany(ids: number[], solidRequestContext: any = {}): Promise<any> {
|
|
53
54
|
if (!ids || ids.length === 0) {
|
|
54
|
-
throw new Error(
|
|
55
|
+
throw new Error(ERROR_MESSAGES.DELETE_IDS_REQUIRED);
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
// ❌ If the active user is trying to delete themselves
|
|
58
59
|
if (solidRequestContext?.activeUser?.sub && ids.includes(solidRequestContext.activeUser.id)) {
|
|
59
|
-
throw new BadRequestException(
|
|
60
|
+
throw new BadRequestException(ERROR_MESSAGES.DELETE_SELF_NOT_ALLOWED);
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
return super.deleteMany(ids, solidRequestContext);
|
|
@@ -105,7 +106,7 @@ export class UserService extends CRUDService<User> {
|
|
|
105
106
|
}
|
|
106
107
|
});
|
|
107
108
|
if (!user) {
|
|
108
|
-
throw new Error(
|
|
109
|
+
throw new Error(ERROR_MESSAGES.USER_NOT_FOUND);
|
|
109
110
|
}
|
|
110
111
|
const roles = updateDto.roles ? updateDto.roles : [];
|
|
111
112
|
await this.addRolesToUser(user.username, roles);
|
|
@@ -121,11 +122,11 @@ export class UserService extends CRUDService<User> {
|
|
|
121
122
|
}
|
|
122
123
|
});
|
|
123
124
|
if (!user) {
|
|
124
|
-
throw new Error(
|
|
125
|
+
throw new Error(ERROR_MESSAGES.USER_NOT_FOUND_BY_USERNAME(username));
|
|
125
126
|
}
|
|
126
127
|
const role = await this.roleRepository.findOne({ where: { name: roleName } });
|
|
127
128
|
if (!role) {
|
|
128
|
-
throw new Error(
|
|
129
|
+
throw new Error(ERROR_MESSAGES.ROLE_NOT_FOUND(roleName));
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
if (user.roles && user.roles.length > 0) {
|
|
@@ -145,7 +146,7 @@ export class UserService extends CRUDService<User> {
|
|
|
145
146
|
});
|
|
146
147
|
|
|
147
148
|
if (!user) {
|
|
148
|
-
throw new Error(
|
|
149
|
+
throw new Error(ERROR_MESSAGES.USER_NOT_FOUND_BY_USERNAME(username));
|
|
149
150
|
}
|
|
150
151
|
|
|
151
152
|
const roles = await this.roleRepository.find({
|
|
@@ -155,7 +156,7 @@ export class UserService extends CRUDService<User> {
|
|
|
155
156
|
if (roles.length !== roleNames.length) {
|
|
156
157
|
const foundRoleNames = roles.map(role => role.name);
|
|
157
158
|
const missingRoles = roleNames.filter(roleName => !foundRoleNames.includes(roleName));
|
|
158
|
-
throw new Error(
|
|
159
|
+
throw new Error(ERROR_MESSAGES.ROLES_NOT_FOUND(missingRoles));
|
|
159
160
|
}
|
|
160
161
|
|
|
161
162
|
const currentRoles = user.roles.map(role => role.name);
|
|
@@ -189,7 +190,7 @@ export class UserService extends CRUDService<User> {
|
|
|
189
190
|
});
|
|
190
191
|
|
|
191
192
|
if (!user) {
|
|
192
|
-
throw new Error(
|
|
193
|
+
throw new Error(ERROR_MESSAGES.USER_NOT_FOUND_BY_USERNAME(username));
|
|
193
194
|
}
|
|
194
195
|
|
|
195
196
|
// modify the permissions array.
|
|
@@ -261,7 +262,7 @@ export class UserService extends CRUDService<User> {
|
|
|
261
262
|
|
|
262
263
|
async initializeRolesForNewUser(roles: string[], user: User) {
|
|
263
264
|
if (!user.id) {
|
|
264
|
-
throw new BadRequestException(
|
|
265
|
+
throw new BadRequestException(ERROR_MESSAGES.USER_MISSING_ID);
|
|
265
266
|
}
|
|
266
267
|
let userRoles = [];
|
|
267
268
|
// Default Internal user role assigned
|
package/src/solid-core.module.ts
CHANGED
|
@@ -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/
|
|
112
|
-
import { SMTPEMailService } from './services/mail/
|
|
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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CAAC,CAAC;QACjG,OAAO;YACH,eAAe,EAAE,iBAAiB,CAAC,QAAQ,CAAC,QAAQ,CAAC;YACrD,MAAM,EAAE,UAAU,CAAC,QAAQ;SAC9B,CAAA;IACL,CAAC;IAEO,KAAK,CAAC,kBAAkB,CAAC,sBAA8B,EAAE,cAAmB;QAChF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,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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B;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}"]}
|
|
File without changes
|