dt-common-device 13.4.11 → 13.4.13

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");
@@ -90,18 +90,13 @@ let EmailService = (() => {
90
90
  accessKeyId: process.env.AWS_ACCESS_KEY_ID ?? "",
91
91
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ?? "",
92
92
  };
93
+ console.log("credentials:------", credentials);
93
94
  const region = process.env.AWS_REGION ?? "us-east-1";
94
95
  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
- });
96
+ this.sesClient = new client_ses_1.SESClient({ credentials, region });
104
97
  this.propertyService = typedi_1.default.get(Property_service_1.LocalPropertyService);
98
+ console.log("s3Client:------", this.s3Client);
99
+ console.log("sesClient:------", this.sesClient);
105
100
  }
106
101
  async getTemplateForProperty(fileName, propertyId) {
107
102
  let res;
@@ -244,47 +239,43 @@ let EmailService = (() => {
244
239
  else {
245
240
  imageURL = `https://api-sandbox-new.devicethread.com/dt-logo.png`;
246
241
  }
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.
242
+ const fromEmail = typeof mailData.fromEmail === "string" ? mailData.fromEmail.trim() : "";
253
243
  const currentYear = new Date().getFullYear().toString();
254
- // const logo: any = await GetLogo(ctx);
255
- let finalMessage = message
244
+ const finalMessage = message
256
245
  .replaceAll("{{year}}", currentYear)
257
- .replaceAll("{{contactUsPhone}}", `${CONTACT_US_DETAILS?.PHONE}`)
258
- .replaceAll("{{contactUsEmail}}", `${CONTACT_US_DETAILS?.TO_EMAIL_ADDRESS}`)
246
+ .replaceAll("{{contactUsEmail}}", fromEmail)
259
247
  .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
248
+ (0, config_1.getLogger)().info(`sending email (SES) with params: ${JSON.stringify(toAddr)}`);
270
249
  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
250
  (0, config_1.getLogger)().info(`CC addresses: ${JSON.stringify(ccAddr)}`);
276
251
  }
277
- mailData.from = CONTACT_US_DETAILS?.FROM_EMAIL_ADDRESS;
252
+ mailData.from = fromEmail;
278
253
  if (pdfBuffer) {
279
- // this.sendEmailWithAttachments(this.transporter, mailData, finalMessage, pdfBuffer)
280
- }
281
- else {
282
- await this.transporter.sendMail(mailOptions);
254
+ return;
283
255
  }
256
+ await this.sesClient.send(new client_ses_1.SendEmailCommand({
257
+ Source: fromEmail,
258
+ Destination: {
259
+ ToAddresses: toAddr,
260
+ ...(ccAddr && Array.isArray(ccAddr) && ccAddr.length > 0
261
+ ? {
262
+ CcAddresses: ccAddr.filter((e) => typeof e === "string" && e.trim()),
263
+ }
264
+ : {}),
265
+ },
266
+ Message: {
267
+ Subject: { Data: subject, Charset: "UTF-8" },
268
+ Body: {
269
+ Html: { Data: finalMessage, Charset: "UTF-8" },
270
+ },
271
+ },
272
+ ...(fromEmail ? { ReplyToAddresses: [fromEmail] } : {}),
273
+ }));
284
274
  const maskedEmailsList = toAddr.map((email) => (0, Email_1.GetMaskedEmail)(email));
285
275
  (0, config_1.getLogger)().info(`Sending email to: ${maskedEmailsList.join(", ")}`);
286
276
  }
287
277
  catch (error) {
278
+ console.log("error in sendMail:------", error);
288
279
  (0, config_1.getLogger)().error("sendMail: Error", JSON.stringify(error));
289
280
  }
290
281
  }
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.13",
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",