dt-common-device 13.4.11 → 13.4.12

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.
@@ -1,6 +1,6 @@
1
1
  export declare class EmailService {
2
2
  private readonly s3Client;
3
- private readonly transporter;
3
+ private readonly sesClient;
4
4
  private readonly propertyService;
5
5
  constructor();
6
6
  getTemplateForProperty(fileName: string, propertyId: string): Promise<import("@aws-sdk/client-s3").GetObjectCommandOutput | undefined>;
@@ -73,8 +73,8 @@ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, p
73
73
  Object.defineProperty(exports, "__esModule", { value: true });
74
74
  exports.EmailService = void 0;
75
75
  const client_s3_1 = require("@aws-sdk/client-s3");
76
+ const client_ses_1 = require("@aws-sdk/client-ses");
76
77
  const fs = __importStar(require("fs"));
77
- const nodemailer = __importStar(require("nodemailer"));
78
78
  const typedi_1 = __importStar(require("typedi"));
79
79
  const Email_1 = require("../constants/Email");
80
80
  const Property_service_1 = require("../entities/property/Property.service");
@@ -92,15 +92,7 @@ let EmailService = (() => {
92
92
  };
93
93
  const region = process.env.AWS_REGION ?? "us-east-1";
94
94
  this.s3Client = new client_s3_1.S3Client({ credentials, region });
95
- this.transporter = nodemailer.createTransport({
96
- host: 'smtp.gmail.com',
97
- port: 587,
98
- secure: false,
99
- auth: {
100
- user: process.env.SMTP_USER,
101
- pass: process.env.SMTP_PASSWORD,
102
- },
103
- });
95
+ this.sesClient = new client_ses_1.SESClient({ credentials, region });
104
96
  this.propertyService = typedi_1.default.get(Property_service_1.LocalPropertyService);
105
97
  }
106
98
  async getTemplateForProperty(fileName, propertyId) {
@@ -244,43 +236,38 @@ let EmailService = (() => {
244
236
  else {
245
237
  imageURL = `https://api-sandbox-new.devicethread.com/dt-logo.png`;
246
238
  }
247
- const CONTACT_US_DETAILS = (0, Email_1.getContactUsDetails)();
248
- const from = CONTACT_US_DETAILS?.FROM_EMAIL_ADDRESS;
249
- if (!process.env.SMTP_USER || !process.env.SMTP_PASSWORD) {
250
- throw new Error("SMTP credentials are not set");
251
- }
252
- // Section below is replacing the global variables from template like contact us email, phone and current year.
239
+ const fromEmail = typeof mailData.fromEmail === "string" ? mailData.fromEmail.trim() : "";
253
240
  const currentYear = new Date().getFullYear().toString();
254
- // const logo: any = await GetLogo(ctx);
255
- let finalMessage = message
241
+ const finalMessage = message
256
242
  .replaceAll("{{year}}", currentYear)
257
- .replaceAll("{{contactUsPhone}}", `${CONTACT_US_DETAILS?.PHONE}`)
258
- .replaceAll("{{contactUsEmail}}", `${CONTACT_US_DETAILS?.TO_EMAIL_ADDRESS}`)
243
+ .replaceAll("{{contactUsEmail}}", fromEmail)
259
244
  .replaceAll("{{logo}}", `${imageURL}`);
260
- // .replaceAll('{{logo}}', `${logo}`);
261
- //
262
- const mailOptions = {
263
- from: `"devicethread™ Inc." <${from}>`,
264
- to: toAddr,
265
- subject: subject,
266
- html: finalMessage,
267
- replyTo: CONTACT_US_DETAILS?.TO_EMAIL_ADDRESS,
268
- };
269
- // Add CC addresses if present
245
+ (0, config_1.getLogger)().info(`sending email (SES) with params: ${JSON.stringify(toAddr)}`);
270
246
  if (ccAddr && Array.isArray(ccAddr) && ccAddr.length > 0) {
271
- mailOptions.cc = ccAddr;
272
- }
273
- (0, config_1.getLogger)().info(`sending email with params: ${JSON.stringify(toAddr)}`);
274
- if (ccAddr && ccAddr.length > 0) {
275
247
  (0, config_1.getLogger)().info(`CC addresses: ${JSON.stringify(ccAddr)}`);
276
248
  }
277
- mailData.from = CONTACT_US_DETAILS?.FROM_EMAIL_ADDRESS;
249
+ mailData.from = fromEmail;
278
250
  if (pdfBuffer) {
279
- // this.sendEmailWithAttachments(this.transporter, mailData, finalMessage, pdfBuffer)
280
- }
281
- else {
282
- await this.transporter.sendMail(mailOptions);
251
+ return;
283
252
  }
253
+ await this.sesClient.send(new client_ses_1.SendEmailCommand({
254
+ Source: fromEmail,
255
+ Destination: {
256
+ ToAddresses: toAddr,
257
+ ...(ccAddr && Array.isArray(ccAddr) && ccAddr.length > 0
258
+ ? {
259
+ CcAddresses: ccAddr.filter((e) => typeof e === "string" && e.trim()),
260
+ }
261
+ : {}),
262
+ },
263
+ Message: {
264
+ Subject: { Data: subject, Charset: "UTF-8" },
265
+ Body: {
266
+ Html: { Data: finalMessage, Charset: "UTF-8" },
267
+ },
268
+ },
269
+ ...(fromEmail ? { ReplyToAddresses: [fromEmail] } : {}),
270
+ }));
284
271
  const maskedEmailsList = toAddr.map((email) => (0, Email_1.GetMaskedEmail)(email));
285
272
  (0, config_1.getLogger)().info(`Sending email to: ${maskedEmailsList.join(", ")}`);
286
273
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "13.4.11",
3
+ "version": "13.4.12",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -38,13 +38,12 @@
38
38
  "devDependencies": {
39
39
  "@types/lodash": "^4.17.19",
40
40
  "@types/node": "^20.0.0",
41
- "@types/nodemailer": "7.0.11",
42
41
  "@types/pg": "8.15.4",
43
42
  "ts-node": "^10.9.2",
44
43
  "typescript": "^5.8.3"
45
44
  },
46
45
  "dependencies": {
47
- "@aws-sdk/client-s3": "^3.835.0",
46
+ "@aws-sdk/client-s3": "3.1015.0",
48
47
  "@aws-sdk/client-ses": "3.1003.0",
49
48
  "axios": "1.10.0",
50
49
  "bullmq": "5.56.4",
@@ -53,7 +52,6 @@
53
52
  "ioredis": "5.6.1",
54
53
  "lodash": "^4.17.21",
55
54
  "mongoose": "8.17.1",
56
- "nodemailer": "8.0.1",
57
55
  "pg": "8.16.3",
58
56
  "svix": "1.84.1",
59
57
  "twilio": "5.12.2",