dt-common-device 13.4.2 → 13.4.5

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.
@@ -85,6 +85,7 @@ exports.CONFIG_KEYS = {
85
85
  "ADMIN_DB_URI",
86
86
  "ACCESS_DB_URI",
87
87
  "AWS_SQS_URL",
88
+ "ADMIN_SERVICE",
88
89
  "HEARTBEAT_SQS_URL",
89
90
  "CRONICLE_ENDPOINT",
90
91
  "CRONICLE_API_KEY",
@@ -1,6 +1,6 @@
1
1
  export declare class EmailService {
2
2
  private readonly s3Client;
3
- private readonly sesClient;
3
+ private readonly transporter;
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");
77
76
  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,7 +92,15 @@ 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.sesClient = new client_ses_1.SESClient({ 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
104
  this.propertyService = typedi_1.default.get(Property_service_1.LocalPropertyService);
97
105
  }
98
106
  async getTemplateForProperty(fileName, propertyId) {
@@ -238,9 +246,8 @@ let EmailService = (() => {
238
246
  }
239
247
  const CONTACT_US_DETAILS = (0, Email_1.getContactUsDetails)();
240
248
  const from = CONTACT_US_DETAILS?.FROM_EMAIL_ADDRESS;
241
- if (!process.env.AWS_ACCESS_KEY_ID ||
242
- !process.env.AWS_SECRET_ACCESS_KEY) {
243
- throw new Error("AWS credentials are not set");
249
+ if (!process.env.SMTP_USER || !process.env.SMTP_PASSWORD) {
250
+ throw new Error("SMTP credentials are not set");
244
251
  }
245
252
  // Section below is replacing the global variables from template like contact us email, phone and current year.
246
253
  const currentYear = new Date().getFullYear().toString();
@@ -252,28 +259,16 @@ let EmailService = (() => {
252
259
  .replaceAll("{{logo}}", `${imageURL}`);
253
260
  // .replaceAll('{{logo}}', `${logo}`);
254
261
  //
255
- const params = {
256
- Destination: {
257
- ToAddresses: toAddr,
258
- },
259
- Message: {
260
- Body: {
261
- Html: {
262
- Charset: "UTF-8",
263
- Data: finalMessage,
264
- },
265
- },
266
- Subject: {
267
- Charset: "UTF-8",
268
- Data: subject,
269
- },
270
- },
271
- Source: from, // SENDER_ADDRESS
272
- ReplyToAddresses: [CONTACT_US_DETAILS?.TO_EMAIL_ADDRESS],
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,
273
268
  };
274
269
  // Add CC addresses if present
275
270
  if (ccAddr && Array.isArray(ccAddr) && ccAddr.length > 0) {
276
- params.Destination.CcAddresses = ccAddr;
271
+ mailOptions.cc = ccAddr;
277
272
  }
278
273
  (0, config_1.getLogger)().info(`sending email with params: ${JSON.stringify(toAddr)}`);
279
274
  if (ccAddr && ccAddr.length > 0) {
@@ -281,10 +276,10 @@ let EmailService = (() => {
281
276
  }
282
277
  mailData.from = CONTACT_US_DETAILS?.FROM_EMAIL_ADDRESS;
283
278
  if (pdfBuffer) {
284
- // this.sendEmailWithAttachments(this.sesClient, mailData, finalMessage, pdfBuffer)
279
+ // this.sendEmailWithAttachments(this.transporter, mailData, finalMessage, pdfBuffer)
285
280
  }
286
281
  else {
287
- await this.sesClient.send(new client_ses_1.SendEmailCommand(params));
282
+ await this.transporter.sendMail(mailOptions);
288
283
  }
289
284
  const maskedEmailsList = toAddr.map((email) => (0, Email_1.GetMaskedEmail)(email));
290
285
  (0, config_1.getLogger)().info(`Sending email to: ${maskedEmailsList.join(", ")}`);
@@ -1,4 +1,4 @@
1
- import { IAccessGroup, IUser, IZone, IZoneAccessGroup } from "./IAdmin";
1
+ import { IAccessGroup, INotificationTemplate, INotificationTemplateResolve, IUser, IZone, IZoneAccessGroup } from "./IAdmin";
2
2
  export declare class AdminRepository {
3
3
  private readonly deviceRepository;
4
4
  private readonly postgres;
@@ -23,4 +23,5 @@ export declare class AdminRepository {
23
23
  getChildCollectionsByParentIds(parentIds: string[]): Promise<any[]>;
24
24
  deleteAllCollectionHierarchy(propertyId: string, source: string): Promise<void>;
25
25
  getCollectionByName(name: string, propertyId: string): Promise<any | null>;
26
+ getNotificationTemplate(payload: INotificationTemplateResolve): Promise<INotificationTemplate | null>;
26
27
  }
@@ -536,6 +536,16 @@ let AdminRepository = (() => {
536
536
  return null;
537
537
  }
538
538
  }
539
+ async getNotificationTemplate(payload) {
540
+ if (!payload.propertyId ||
541
+ !payload.organizationId ||
542
+ !payload.eventName ||
543
+ !payload.channel) {
544
+ throw new Error("Property ID, Organization ID, Event Name, and Channel are required in payload");
545
+ }
546
+ const response = await (0, utils_1.getAdminServiceAxiosInstance)().post(`/notification-templates/resolve`, payload);
547
+ return response.data.data;
548
+ }
539
549
  };
540
550
  __setFunctionName(_classThis, "AdminRepository");
541
551
  (() => {
@@ -1,4 +1,4 @@
1
- import { IAccessGroup, IUser, IZone } from "./IAdmin";
1
+ import { IAccessGroup, INotificationTemplate, INotificationTemplateResolve, IUser, IZone } from "./IAdmin";
2
2
  export declare class AdminService {
3
3
  private readonly adminRepository;
4
4
  private readonly redisUtils;
@@ -17,4 +17,5 @@ export declare class AdminService {
17
17
  deleteAllCollectionHierarchy(propertyId: string, source: string): Promise<void>;
18
18
  getCollectionByName(name: string, propertyId: string): Promise<any | null>;
19
19
  propertyHasSaltoConnection(propertyId: string): Promise<boolean>;
20
+ getNotificationTemplate(payload: INotificationTemplateResolve): Promise<INotificationTemplate | null>;
20
21
  }
@@ -310,6 +310,15 @@ let AdminService = (() => {
310
310
  return connections.every((connection) => connection.connectionProvider === connection_1.ConnectionProvider.SaltoKS ||
311
311
  connection.connectionProvider === connection_1.ConnectionProvider.SaltoSpace);
312
312
  }
313
+ async getNotificationTemplate(payload) {
314
+ if (!payload.propertyId ||
315
+ !payload.organizationId ||
316
+ !payload.eventName ||
317
+ !payload.channel) {
318
+ throw new Error("Property ID, Organization ID, Event Name, and Channel are required");
319
+ }
320
+ return await this.adminRepository.getNotificationTemplate(payload);
321
+ }
313
322
  };
314
323
  __setFunctionName(_classThis, "AdminService");
315
324
  (() => {
@@ -48,3 +48,31 @@ export interface IUser {
48
48
  deletedAt?: Date | null;
49
49
  imageURL?: string | null;
50
50
  }
51
+ export type NotificationChannel = "email" | "sms";
52
+ export type NotificationScope = "platform" | "organization" | "property";
53
+ export interface INotificationTemplate {
54
+ _id?: string;
55
+ id?: string;
56
+ eventName: string;
57
+ channel: NotificationChannel;
58
+ scope: NotificationScope;
59
+ organizationId: string | null;
60
+ propertyId: string | null;
61
+ subject?: string;
62
+ template: string;
63
+ variables: string[];
64
+ isActive: boolean;
65
+ isDeleted?: boolean;
66
+ createdBy?: string;
67
+ updatedBy?: string;
68
+ createdAt?: Date;
69
+ updatedAt?: Date;
70
+ deletedAt?: Date;
71
+ deletedBy?: string;
72
+ }
73
+ export interface INotificationTemplateResolve {
74
+ propertyId?: string;
75
+ organizationId?: string;
76
+ eventName?: string;
77
+ channel?: NotificationChannel;
78
+ }
@@ -4,5 +4,6 @@ export declare class PropertyRepository {
4
4
  constructor();
5
5
  getPropertyPreferences(propertyId: string, keys?: string[]): Promise<IPropertySettings | null>;
6
6
  getProperty(propertyId: string): Promise<IProperty | null>;
7
+ getOrganizationByPropertyId(propertyId: string): Promise<any | null>;
7
8
  getAllProperties(): Promise<any[]>;
8
9
  }
@@ -41,6 +41,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.PropertyRepository = void 0;
42
42
  const db_1 = require("../../db");
43
43
  const typedi_1 = require("typedi");
44
+ const utils_1 = require("../../utils");
44
45
  let PropertyRepository = (() => {
45
46
  let _classDecorators = [(0, typedi_1.Service)()];
46
47
  let _classDescriptor;
@@ -84,6 +85,10 @@ let PropertyRepository = (() => {
84
85
  }
85
86
  return null;
86
87
  }
88
+ async getOrganizationByPropertyId(propertyId) {
89
+ const organization = await (0, utils_1.getAdminServiceAxiosInstance)().get(`/properties/${propertyId}/organizations`);
90
+ return organization.data.data;
91
+ }
87
92
  async getAllProperties() {
88
93
  try {
89
94
  //Retrieve all the properties ids from the database where isDeleted is false
@@ -5,4 +5,5 @@ export declare class LocalPropertyService {
5
5
  getProperty(propertyId: string): Promise<import("./IProperty").IProperty | null>;
6
6
  getPropertyTimeZone(propertyId: string): Promise<string>;
7
7
  getAllProperties(): Promise<any[]>;
8
+ getOrganizationByPropertyId(propertyId: string): Promise<any>;
8
9
  }
@@ -110,6 +110,12 @@ let LocalPropertyService = (() => {
110
110
  const properties = await this.propertyRepository.getAllProperties();
111
111
  return properties;
112
112
  }
113
+ async getOrganizationByPropertyId(propertyId) {
114
+ if (!propertyId) {
115
+ throw new Error("Property ID is required");
116
+ }
117
+ return await this.propertyRepository.getOrganizationByPropertyId(propertyId);
118
+ }
113
119
  };
114
120
  __setFunctionName(_classThis, "LocalPropertyService");
115
121
  (() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "13.4.2",
3
+ "version": "13.4.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -38,6 +38,7 @@
38
38
  "devDependencies": {
39
39
  "@types/lodash": "^4.17.19",
40
40
  "@types/node": "^20.0.0",
41
+ "@types/nodemailer": "7.0.11",
41
42
  "@types/pg": "8.15.4",
42
43
  "ts-node": "^10.9.2",
43
44
  "typescript": "^5.8.3"
@@ -52,6 +53,7 @@
52
53
  "ioredis": "5.6.1",
53
54
  "lodash": "^4.17.21",
54
55
  "mongoose": "8.17.1",
56
+ "nodemailer": "8.0.1",
55
57
  "pg": "8.16.3",
56
58
  "svix": "1.84.1",
57
59
  "twilio": "5.12.2",