dt-common-device 13.3.15 → 13.3.18

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 (172) hide show
  1. package/dist/constants/Email.d.ts +43 -0
  2. package/dist/constants/Email.js +77 -0
  3. package/dist/emails/emailService.d.ts +16 -0
  4. package/dist/emails/emailService.js +343 -0
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.js +2 -0
  7. package/dist/queue/utils/rateLimit.utils.js +1 -1
  8. package/package.json +4 -1
  9. package/dist/Integrations/twilio/interface/twilloInterface.d.ts +0 -4
  10. package/dist/Integrations/twilio/interface/twilloInterface.js +0 -2
  11. package/dist/admin/Admin.repository.d.ts +0 -7
  12. package/dist/admin/Admin.service.d.ts +0 -5
  13. package/dist/admin/index.d.ts +0 -1
  14. package/dist/alerts/AlertBuilder.example.d.ts +0 -11
  15. package/dist/alerts/AlertService.example.d.ts +0 -55
  16. package/dist/audit/AuditProperties.d.ts +0 -16
  17. package/dist/chronicle/Cronicle.service.d.ts +0 -9
  18. package/dist/chronicle/IChronicle.interface.d.ts +0 -14
  19. package/dist/chronicle/ICronicle.interface.d.ts +0 -15
  20. package/dist/chronicle/chronicle.service.d.ts +0 -4
  21. package/dist/chronicle/index.d.ts +0 -2
  22. package/dist/connection/Connection.repository.d.ts +0 -8
  23. package/dist/connection/Connection.service.d.ts +0 -8
  24. package/dist/connection/IConnection.d.ts +0 -28
  25. package/dist/connection/index.d.ts +0 -2
  26. package/dist/copilotQueue/examples/CopilotQueue.example.d.ts +0 -37
  27. package/dist/copilotQueue/examples/index.d.ts +0 -1
  28. package/dist/device/cloud/entities/CloudConnection.d.ts +0 -6
  29. package/dist/device/cloud/entities/CloudDevice.d.ts +0 -16
  30. package/dist/device/cloud/entities/CloudDeviceService.d.ts +0 -5
  31. package/dist/device/cloud/entities/DeviceFactory.d.ts +0 -7
  32. package/dist/device/cloud/entities/index.d.ts +0 -3
  33. package/dist/device/cloud/interface.d.ts +0 -101
  34. package/dist/device/cloud/interfaces/ICloudConnection.d.ts +0 -5
  35. package/dist/device/cloud/interfaces/ICloudDevice.d.ts +0 -9
  36. package/dist/device/cloud/interfaces/ICloudDeviceService.d.ts +0 -4
  37. package/dist/device/cloud/interfaces/IConnectionService.d.ts +0 -7
  38. package/dist/device/cloud/interfaces/IDeviceConnectionService.d.ts +0 -7
  39. package/dist/device/cloud/interfaces/IDeviceFactory.d.ts +0 -4
  40. package/dist/device/cloud/interfaces/IDeviceService.d.ts +0 -8
  41. package/dist/device/cloud/interfaces/IDevicesService.d.ts +0 -9
  42. package/dist/device/cloud/interfaces/IHubService.d.ts +0 -5
  43. package/dist/device/cloud/interfaces/IRawDataTransformer.d.ts +0 -4
  44. package/dist/device/cloud/interfaces/IRawDevice.d.ts +0 -17
  45. package/dist/device/cloud/interfaces/index.d.ts +0 -5
  46. package/dist/device/cloud/services/CloudDevice.service.d.ts +0 -5
  47. package/dist/device/cloud/services/Connection.service.d.ts +0 -8
  48. package/dist/device/cloud/services/Device.service.d.ts +0 -39
  49. package/dist/device/cloud/services/DeviceCloudService.d.ts +0 -42
  50. package/dist/device/cloud/services/DeviceHub.service.d.ts +0 -3
  51. package/dist/device/cloud/services/Hub.service.d.ts +0 -25
  52. package/dist/device/cloud/services/SmartThingsDeviceService.d.ts +0 -38
  53. package/dist/device/cloud/services/SmartThingsDeviceService.js +0 -52
  54. package/dist/device/cloud/services/index.d.ts +0 -2
  55. package/dist/device/cloud/types.d.ts +0 -52
  56. package/dist/device/cloud/types.js +0 -15
  57. package/dist/device/index.d.ts +0 -4
  58. package/dist/device/local/entities/AlertBuilder.d.ts +0 -87
  59. package/dist/device/local/entities/AlertBuilder.example.d.ts +0 -11
  60. package/dist/device/local/entities/IssueBuilder.d.ts +0 -109
  61. package/dist/device/local/entities/IssueBuilder.example.d.ts +0 -16
  62. package/dist/device/local/entities/IssueBuilder.example.js +0 -196
  63. package/dist/device/local/entities/IssueBuilder.js +0 -237
  64. package/dist/device/local/entities/index.d.ts +0 -2
  65. package/dist/device/local/events/EventHandler.d.ts +0 -11
  66. package/dist/device/local/events/Events.d.ts +0 -54
  67. package/dist/device/local/events/index.d.ts +0 -2
  68. package/dist/device/local/handler/EventHandler.d.ts +0 -7
  69. package/dist/device/local/interface.d.ts +0 -0
  70. package/dist/device/local/interfaces/IConnection.d.ts +0 -26
  71. package/dist/device/local/interfaces/IDevice.d.ts +0 -68
  72. package/dist/device/local/interfaces/IDtDevice.d.ts +0 -16
  73. package/dist/device/local/interfaces/IHub.d.ts +0 -46
  74. package/dist/device/local/interfaces/IProperty.d.ts +0 -29
  75. package/dist/device/local/interfaces/ISchedule.d.ts +0 -25
  76. package/dist/device/local/interfaces/index.d.ts +0 -3
  77. package/dist/device/local/models/Alert.model.d.ts +0 -28
  78. package/dist/device/local/models/Issue.model.d.ts +0 -28
  79. package/dist/device/local/repository/Alert.repository.d.ts +0 -106
  80. package/dist/device/local/repository/Connection.repository.d.ts +0 -8
  81. package/dist/device/local/repository/Device.repository.d.ts +0 -30
  82. package/dist/device/local/repository/Hub.repository.d.ts +0 -13
  83. package/dist/device/local/repository/Issue.repository.d.ts +0 -113
  84. package/dist/device/local/repository/Property.repository.d.ts +0 -8
  85. package/dist/device/local/repository/Property.repository.js +0 -95
  86. package/dist/device/local/repository/Schedule.repository.d.ts +0 -9
  87. package/dist/device/local/repository/Schedule.repository.js +0 -109
  88. package/dist/device/local/services/Alert.service.d.ts +0 -137
  89. package/dist/device/local/services/AlertService.example.d.ts +0 -55
  90. package/dist/device/local/services/Connection.service.d.ts +0 -8
  91. package/dist/device/local/services/Device.service.d.ts +0 -40
  92. package/dist/device/local/services/DeviceHub.service.d.ts +0 -11
  93. package/dist/device/local/services/Hub.service.d.ts +0 -12
  94. package/dist/device/local/services/Issue.service.d.ts +0 -168
  95. package/dist/device/local/services/Issue.service.js +0 -642
  96. package/dist/device/local/services/IssueService.example.d.ts +0 -68
  97. package/dist/device/local/services/IssueService.example.js +0 -177
  98. package/dist/device/local/services/Property.service.d.ts +0 -8
  99. package/dist/device/local/services/Property.service.js +0 -36
  100. package/dist/device/local/services/Schedule.service.d.ts +0 -9
  101. package/dist/device/local/services/Schedule.service.js +0 -26
  102. package/dist/device/local/services/index.d.ts +0 -3
  103. package/dist/entities/accessGroup/AccessGroup.repository.d.ts +0 -5
  104. package/dist/entities/accessGroup/AccessGroup.service.d.ts +0 -5
  105. package/dist/entities/accessGroup/IAccessGroup.d.ts +0 -14
  106. package/dist/entities/accessGroup/index.d.ts +0 -2
  107. package/dist/entities/device/local/repository/DeviceProfile.repository.d.ts +0 -5
  108. package/dist/entities/guest/Guest.repository.d.ts +0 -6
  109. package/dist/entities/guest/Guest.service.d.ts +0 -6
  110. package/dist/entities/guest/IGuest.d.ts +0 -12
  111. package/dist/entities/guest/index.d.ts +0 -2
  112. package/dist/entities/schedules/ISchedule.d.ts +0 -14
  113. package/dist/entities/schedules/Schedule.repository.d.ts +0 -6
  114. package/dist/entities/schedules/Schedule.repository.js +0 -74
  115. package/dist/entities/schedules/Schedule.service.d.ts +0 -6
  116. package/dist/entities/schedules/Schedule.service.js +0 -104
  117. package/dist/entities/schedules/index.d.ts +0 -2
  118. package/dist/entities/user/IUser.d.ts +0 -15
  119. package/dist/entities/user/IUser.js +0 -2
  120. package/dist/entities/user/User.repository.d.ts +0 -5
  121. package/dist/entities/user/User.repository.js +0 -68
  122. package/dist/entities/user/User.service.d.ts +0 -6
  123. package/dist/entities/user/User.service.js +0 -103
  124. package/dist/entities/zone/IZone.d.ts +0 -10
  125. package/dist/entities/zone/IZone.js +0 -2
  126. package/dist/entities/zone/Zone.repository.d.ts +0 -6
  127. package/dist/entities/zone/Zone.repository.js +0 -77
  128. package/dist/entities/zone/Zone.service.d.ts +0 -6
  129. package/dist/entities/zone/Zone.service.js +0 -104
  130. package/dist/entities/zone/index.d.ts +0 -2
  131. package/dist/issues/IssueBuilder.example.d.ts +0 -16
  132. package/dist/issues/IssueBuilder.example.js +0 -196
  133. package/dist/issues/IssueService.example.d.ts +0 -68
  134. package/dist/issues/IssueService.example.js +0 -292
  135. package/dist/pms/IPms.d.ts +0 -6
  136. package/dist/pms/index.d.ts +0 -1
  137. package/dist/pms/webhookQueue/examples/index.d.ts +0 -2
  138. package/dist/pms/webhookQueue/examples/pms-integration.d.ts +0 -65
  139. package/dist/pms/webhookQueue/examples/pms-integration.js +0 -254
  140. package/dist/pms/webhookQueue/examples/usage.d.ts +0 -7
  141. package/dist/pms/webhookQueue/examples/usage.js +0 -175
  142. package/dist/pms/webhookQueue/index.d.ts +0 -3
  143. package/dist/pms/webhookQueue/interfaces/IWebhookQueue.d.ts +0 -33
  144. package/dist/pms/webhookQueue/interfaces/IWebhookQueue.js +0 -2
  145. package/dist/pms/webhookQueue/interfaces/IWebhookWorker.d.ts +0 -38
  146. package/dist/pms/webhookQueue/interfaces/IWebhookWorker.js +0 -2
  147. package/dist/pms/webhookQueue/interfaces/index.d.ts +0 -1
  148. package/dist/pms/webhookQueue/services/WebhookQueueFactory.d.ts +0 -38
  149. package/dist/pms/webhookQueue/services/WebhookQueueFactory.js +0 -131
  150. package/dist/pms/webhookQueue/services/WebhookQueueIntegration.d.ts +0 -70
  151. package/dist/pms/webhookQueue/services/WebhookQueueIntegration.js +0 -207
  152. package/dist/pms/webhookQueue/services/WebhookQueueService.d.ts +0 -45
  153. package/dist/pms/webhookQueue/services/WebhookQueueService.js +0 -270
  154. package/dist/pms/webhookQueue/services/WebhookWorker.d.ts +0 -37
  155. package/dist/pms/webhookQueue/services/WebhookWorker.js +0 -201
  156. package/dist/pms/webhookQueue/services/index.d.ts +0 -1
  157. package/dist/pms/webhookQueue/types/index.d.ts +0 -1
  158. package/dist/pms/webhookQueue/types/webhook.types.d.ts +0 -39
  159. package/dist/pms/webhookQueue/types/webhook.types.js +0 -2
  160. package/dist/property/IProperty.d.ts +0 -29
  161. package/dist/property/Property.repository.d.ts +0 -8
  162. package/dist/property/Property.repository.js +0 -109
  163. package/dist/property/Property.service.d.ts +0 -8
  164. package/dist/property/Property.service.js +0 -124
  165. package/dist/property/index.d.ts +0 -2
  166. package/dist/queue/interfaces/IHttpRequestJob.d.ts +0 -9
  167. package/dist/types/alert.types.d.ts +0 -57
  168. package/dist/types/config.types.d.ts +0 -19
  169. package/dist/types/index.d.ts +0 -3
  170. package/dist/types/issue.types.d.ts +0 -90
  171. package/dist/types/issue.types.js +0 -40
  172. package/dist/utils/http-utils.d.ts +0 -13
@@ -0,0 +1,43 @@
1
+ export declare const EMAIL_TEMPLATES: {
2
+ devicethread: string;
3
+ propertyCustom: string;
4
+ organizationCustom: string;
5
+ };
6
+ export declare const getContactUsDetails: () => {
7
+ FROM_EMAIL_ADDRESS: string;
8
+ TO_EMAIL_ADDRESS: string;
9
+ PHONE: string;
10
+ } | undefined;
11
+ export declare const CONTACT_US_DETAILS: {
12
+ DEV: {
13
+ FROM_EMAIL_ADDRESS: string;
14
+ TO_EMAIL_ADDRESS: string;
15
+ PHONE: string;
16
+ };
17
+ QA: {
18
+ FROM_EMAIL_ADDRESS: string;
19
+ TO_EMAIL_ADDRESS: string;
20
+ PHONE: string;
21
+ };
22
+ EUT: {
23
+ FROM_EMAIL_ADDRESS: string;
24
+ TO_EMAIL_ADDRESS: string;
25
+ PHONE: string;
26
+ };
27
+ BETA: {
28
+ FROM_EMAIL_ADDRESS: string;
29
+ TO_EMAIL_ADDRESS: string;
30
+ PHONE: string;
31
+ };
32
+ SANDBOX: {
33
+ FROM_EMAIL_ADDRESS: string;
34
+ TO_EMAIL_ADDRESS: string;
35
+ PHONE: string;
36
+ };
37
+ PROD: {
38
+ FROM_EMAIL_ADDRESS: string;
39
+ TO_EMAIL_ADDRESS: string;
40
+ PHONE: string;
41
+ };
42
+ };
43
+ export declare const GetMaskedEmail: (email: string) => string;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GetMaskedEmail = exports.CONTACT_US_DETAILS = exports.getContactUsDetails = exports.EMAIL_TEMPLATES = void 0;
4
+ const config_1 = require("../config/config");
5
+ exports.EMAIL_TEMPLATES = {
6
+ devicethread: `email-templates/devicethread/{{fileName}}`,
7
+ propertyCustom: `email-templates/custom/property/{{propertyId}}/{{fileName}}`,
8
+ organizationCustom: `email-templates/custom/organization/{{organizationId}}/{{fileName}}`,
9
+ };
10
+ const getContactUsDetails = () => {
11
+ try {
12
+ switch (process.env.NODE_ENV?.toLocaleLowerCase()) {
13
+ case 'qa-ecs': {
14
+ return exports.CONTACT_US_DETAILS.PROD;
15
+ }
16
+ case 'prod-ecs': {
17
+ return exports.CONTACT_US_DETAILS.QA;
18
+ }
19
+ case 'eut': {
20
+ return exports.CONTACT_US_DETAILS.EUT;
21
+ }
22
+ case 'stage': {
23
+ return exports.CONTACT_US_DETAILS.BETA;
24
+ }
25
+ case 'uat-ecs': {
26
+ return exports.CONTACT_US_DETAILS.EUT;
27
+ }
28
+ case 'green-ecs': {
29
+ return exports.CONTACT_US_DETAILS.PROD;
30
+ }
31
+ default: {
32
+ return exports.CONTACT_US_DETAILS.DEV;
33
+ }
34
+ }
35
+ }
36
+ catch (err) {
37
+ (0, config_1.getLogger)().error('GetContactUsDetails error ' + err.message);
38
+ }
39
+ };
40
+ exports.getContactUsDetails = getContactUsDetails;
41
+ exports.CONTACT_US_DETAILS = {
42
+ DEV: {
43
+ FROM_EMAIL_ADDRESS: 'dev-notifications@dthreaddev.com',
44
+ TO_EMAIL_ADDRESS: 'dev-support@dthreaddev.com',
45
+ PHONE: '(972) 945-8332',
46
+ },
47
+ QA: {
48
+ FROM_EMAIL_ADDRESS: 'qa-notifications@dthreaddev.com',
49
+ TO_EMAIL_ADDRESS: 'qa-support@dthreaddev.com',
50
+ PHONE: '(972) 945-8332',
51
+ },
52
+ EUT: {
53
+ FROM_EMAIL_ADDRESS: 'uat-notifications@devicethread.com',
54
+ TO_EMAIL_ADDRESS: 'uat-support@devicethread.com',
55
+ PHONE: '(972) 945-8332',
56
+ },
57
+ BETA: {
58
+ FROM_EMAIL_ADDRESS: 'beta-notifications@devicethread.com',
59
+ TO_EMAIL_ADDRESS: 'beta-support@devicethread.com',
60
+ PHONE: '(972) 945-8332',
61
+ },
62
+ SANDBOX: {
63
+ FROM_EMAIL_ADDRESS: 'sandbox-notifications@devicethread.com',
64
+ TO_EMAIL_ADDRESS: 'sandbox-support@devicethread.com',
65
+ PHONE: '(972) 945-8332',
66
+ },
67
+ PROD: {
68
+ FROM_EMAIL_ADDRESS: 'notifications@devicethread.com',
69
+ TO_EMAIL_ADDRESS: 'support@devicethread.com',
70
+ PHONE: '(972) 945-8332',
71
+ },
72
+ };
73
+ const GetMaskedEmail = (email) => {
74
+ const maskedEmail = email.replace(/^(.)(.*)(.@.*)$/, (_, a, b, c) => a + b.replace(/./g, '*') + c);
75
+ return maskedEmail;
76
+ };
77
+ exports.GetMaskedEmail = GetMaskedEmail;
@@ -0,0 +1,16 @@
1
+ import { SESClient } from "@aws-sdk/client-ses";
2
+ export declare class EmailService {
3
+ private readonly s3Client;
4
+ private readonly sesClient;
5
+ private readonly propertyService;
6
+ constructor();
7
+ getTemplateForProperty(fileName: string, propertyId: string): Promise<import("@aws-sdk/client-s3").GetObjectCommandOutput | undefined>;
8
+ getTemplateForOrganization(fileName: string, organizationId: string): Promise<import("@aws-sdk/client-s3").GetObjectCommandOutput>;
9
+ getTemplateFromS3(fileName: string, defaultEmail: boolean, propertyId?: string, organizationId?: string): Promise<{
10
+ bodyContents: string;
11
+ defaultEmail: boolean;
12
+ } | undefined>;
13
+ getRawHtmlTemplate(fileName: string, propertyId?: string, organizationId?: string): Promise<any>;
14
+ sendMail(mailData: any, pdfBuffer?: any): Promise<void>;
15
+ sendEmailWithAttachments(sesClient: SESClient, mailData: any, finalMessage: string, attachment: any): Promise<void>;
16
+ }
@@ -0,0 +1,343 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
19
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
20
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
21
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
22
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
23
+ var _, done = false;
24
+ for (var i = decorators.length - 1; i >= 0; i--) {
25
+ var context = {};
26
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
27
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
28
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
29
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
30
+ if (kind === "accessor") {
31
+ if (result === void 0) continue;
32
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
33
+ if (_ = accept(result.get)) descriptor.get = _;
34
+ if (_ = accept(result.set)) descriptor.set = _;
35
+ if (_ = accept(result.init)) initializers.unshift(_);
36
+ }
37
+ else if (_ = accept(result)) {
38
+ if (kind === "field") initializers.unshift(_);
39
+ else descriptor[key] = _;
40
+ }
41
+ }
42
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
43
+ done = true;
44
+ };
45
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
46
+ var useValue = arguments.length > 2;
47
+ for (var i = 0; i < initializers.length; i++) {
48
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
49
+ }
50
+ return useValue ? value : void 0;
51
+ };
52
+ var __importStar = (this && this.__importStar) || (function () {
53
+ var ownKeys = function(o) {
54
+ ownKeys = Object.getOwnPropertyNames || function (o) {
55
+ var ar = [];
56
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
57
+ return ar;
58
+ };
59
+ return ownKeys(o);
60
+ };
61
+ return function (mod) {
62
+ if (mod && mod.__esModule) return mod;
63
+ var result = {};
64
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
65
+ __setModuleDefault(result, mod);
66
+ return result;
67
+ };
68
+ })();
69
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
70
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
71
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
72
+ };
73
+ Object.defineProperty(exports, "__esModule", { value: true });
74
+ exports.EmailService = void 0;
75
+ const client_s3_1 = require("@aws-sdk/client-s3");
76
+ const client_ses_1 = require("@aws-sdk/client-ses");
77
+ const fs = __importStar(require("fs"));
78
+ const mimetext_1 = require("mimetext");
79
+ const typedi_1 = __importStar(require("typedi"));
80
+ const Email_1 = require("../constants/Email");
81
+ const Property_service_1 = require("../entities/property/Property.service");
82
+ const config_1 = require("../config/config");
83
+ let EmailService = (() => {
84
+ let _classDecorators = [(0, typedi_1.Service)()];
85
+ let _classDescriptor;
86
+ let _classExtraInitializers = [];
87
+ let _classThis;
88
+ var EmailService = _classThis = class {
89
+ constructor() {
90
+ const credentials = {
91
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID ?? "",
92
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ?? "",
93
+ };
94
+ const region = process.env.AWS_REGION ?? "us-east-1";
95
+ this.s3Client = new client_s3_1.S3Client({ credentials, region });
96
+ this.sesClient = new client_ses_1.SESClient({ credentials, region });
97
+ this.propertyService = typedi_1.default.get(Property_service_1.LocalPropertyService);
98
+ }
99
+ async getTemplateForProperty(fileName, propertyId) {
100
+ let res;
101
+ // let organizationData = (await prisma.propertyOrganizationRole.findFirst({
102
+ // where: { propertyId, type: OrganizationRoleType.OWNER_ORGANIZATION },
103
+ // }))!
104
+ try {
105
+ // check template on org folder
106
+ let organizationEmail = Email_1.EMAIL_TEMPLATES.propertyCustom
107
+ .replaceAll("{{fileName}}", `${fileName}`)
108
+ .replaceAll("{{propertyId}}", `${propertyId}`);
109
+ const organizationParams = {
110
+ Bucket: process.env.AWS_S3_ASSETS_BUCKET,
111
+ Key: organizationEmail,
112
+ };
113
+ res = await this.s3Client.send(new client_s3_1.GetObjectCommand(organizationParams));
114
+ }
115
+ catch (error) {
116
+ //if not at org, check on property folder
117
+ if (error?.name === "NoSuchKey") {
118
+ let propertyEmail = Email_1.EMAIL_TEMPLATES.devicethread.replaceAll("{{fileName}}", `${fileName}`);
119
+ // .replaceAll('{{propertyId}}', `${propertyId}`)
120
+ const propertyParams = {
121
+ Bucket: process.env.AWS_S3_ASSETS_BUCKET,
122
+ Key: propertyEmail,
123
+ };
124
+ res = await this.s3Client.send(new client_s3_1.GetObjectCommand(propertyParams));
125
+ }
126
+ }
127
+ return res;
128
+ }
129
+ async getTemplateForOrganization(fileName, organizationId) {
130
+ let res;
131
+ let organizationEmail = Email_1.EMAIL_TEMPLATES.devicethread
132
+ .replaceAll("{{fileName}}", `${fileName}`)
133
+ .replaceAll("{{organizationId}}", `${organizationId}`);
134
+ const organizationParams = {
135
+ Bucket: process.env.AWS_S3_ASSETS_BUCKET,
136
+ Key: organizationEmail,
137
+ };
138
+ res = await this.s3Client.send(new client_s3_1.GetObjectCommand(organizationParams));
139
+ return res;
140
+ }
141
+ async getTemplateFromS3(fileName, defaultEmail, propertyId, organizationId) {
142
+ let dtEmail = Email_1.EMAIL_TEMPLATES.devicethread.replaceAll("{{fileName}}", `${fileName}`);
143
+ let res;
144
+ // try {
145
+ if (propertyId && defaultEmail == false) {
146
+ res = await this.getTemplateForProperty(fileName, propertyId);
147
+ //
148
+ }
149
+ else if (organizationId && defaultEmail == false) {
150
+ res = await this.getTemplateForOrganization(fileName, organizationId);
151
+ //
152
+ }
153
+ else {
154
+ //default template
155
+ const params = { Bucket: process.env.AWS_S3_ASSETS_BUCKET, Key: dtEmail };
156
+ res = await this.s3Client.send(new client_s3_1.GetObjectCommand(params));
157
+ defaultEmail = true;
158
+ }
159
+ // } catch (error: any) {
160
+ // //default template
161
+ // if (error.Code === 'NoSuchKey') {
162
+ // const params = { Bucket: process.env.AWS_S3_ASSETS_BUCKET, Key: dtEmail }
163
+ // res = await s3Client.send(new GetObjectCommand(params))
164
+ // defaultEmail = true
165
+ // }
166
+ // }
167
+ const streamToString = async (stream) => {
168
+ const chunks = [];
169
+ for await (const chunk of stream) {
170
+ chunks.push(chunk);
171
+ }
172
+ return Buffer.concat(chunks).toString("utf-8");
173
+ };
174
+ if (res && res.Body) {
175
+ const bodyContents = await streamToString(res.Body);
176
+ return { bodyContents, defaultEmail };
177
+ }
178
+ }
179
+ async getRawHtmlTemplate(fileName, propertyId, organizationId) {
180
+ let dtEmail = false;
181
+ try {
182
+ // throw new Error('')
183
+ let body = await this.getTemplateFromS3(`${fileName}.html`, dtEmail, propertyId, organizationId);
184
+ if (body) {
185
+ if (body.defaultEmail) {
186
+ dtEmail = true;
187
+ }
188
+ // let footer: any = await this.getTemplateFromS3(
189
+ // 'footer.html',
190
+ // dtEmail,
191
+ // propertyId,
192
+ // organizationId,
193
+ // )
194
+ // let header: any = await this.getTemplateFromS3(
195
+ // 'header.html',
196
+ // dtEmail,
197
+ // propertyId,
198
+ // organizationId,
199
+ // )
200
+ // //
201
+ // let data = ''
202
+ // data += header.bodyContents
203
+ // //
204
+ // data = data.replace('<dt-body />', body.bodyContents)
205
+ // data = data.replace('<dt-footer />', footer.bodyContents)
206
+ // //
207
+ return body.bodyContents;
208
+ }
209
+ }
210
+ catch (error) {
211
+ //Comment above lines of code and use these to send emails from local templates
212
+ // let footer: any = await fs.promises.readFile(
213
+ // __dirname + '/../templates/footer.html',
214
+ // )
215
+ // footer = footer.toString()
216
+ // let header: any = await fs.promises.readFile(
217
+ // __dirname + '/../templates/header.html',
218
+ // )
219
+ // header = header.toString()
220
+ let localBody = await fs.promises.readFile(__dirname + `/../templates/${fileName}.html`);
221
+ localBody = localBody.toString();
222
+ // Replacing the custom body and footer tag with actual content
223
+ // header = header.replace('<dt-body />', localBody)
224
+ // header = header.replace('<dt-footer />', footer)
225
+ //
226
+ return localBody;
227
+ }
228
+ }
229
+ async sendMail(mailData, pdfBuffer = null) {
230
+ try {
231
+ const { toAddr, subject, message, ccAddr } = mailData;
232
+ let imageURL = "";
233
+ if (mailData.propertyId) {
234
+ const propertyDetail = await this.propertyService.getProperty(mailData.propertyId);
235
+ imageURL = propertyDetail?.imageURL ?? "";
236
+ }
237
+ else {
238
+ imageURL = `https://api-sandbox-new.devicethread.com/dt-logo.png`;
239
+ }
240
+ const CONTACT_US_DETAILS = (0, Email_1.getContactUsDetails)();
241
+ const from = CONTACT_US_DETAILS?.FROM_EMAIL_ADDRESS;
242
+ if (!process.env.AWS_ACCESS_KEY_ID ||
243
+ !process.env.AWS_SECRET_ACCESS_KEY) {
244
+ throw new Error("AWS credentials are not set");
245
+ }
246
+ // Section below is replacing the global variables from template like contact us email, phone and current year.
247
+ const currentYear = new Date().getFullYear().toString();
248
+ // const logo: any = await GetLogo(ctx);
249
+ let finalMessage = message
250
+ .replaceAll("{{year}}", currentYear)
251
+ .replaceAll("{{contactUsPhone}}", `${CONTACT_US_DETAILS?.PHONE}`)
252
+ .replaceAll("{{contactUsEmail}}", `${CONTACT_US_DETAILS?.TO_EMAIL_ADDRESS}`)
253
+ .replaceAll("{{logo}}", `${imageURL}`);
254
+ // .replaceAll('{{logo}}', `${logo}`);
255
+ //
256
+ const params = {
257
+ Destination: {
258
+ ToAddresses: toAddr,
259
+ },
260
+ Message: {
261
+ Body: {
262
+ Html: {
263
+ Charset: "UTF-8",
264
+ Data: finalMessage,
265
+ },
266
+ },
267
+ Subject: {
268
+ Charset: "UTF-8",
269
+ Data: subject,
270
+ },
271
+ },
272
+ Source: from, // SENDER_ADDRESS
273
+ ReplyToAddresses: [CONTACT_US_DETAILS?.TO_EMAIL_ADDRESS],
274
+ };
275
+ // Add CC addresses if present
276
+ if (ccAddr && Array.isArray(ccAddr) && ccAddr.length > 0) {
277
+ params.Destination.CcAddresses = ccAddr;
278
+ }
279
+ (0, config_1.getLogger)().info(`sending email with params: ${JSON.stringify(toAddr)}`);
280
+ if (ccAddr && ccAddr.length > 0) {
281
+ (0, config_1.getLogger)().info(`CC addresses: ${JSON.stringify(ccAddr)}`);
282
+ }
283
+ mailData.from = CONTACT_US_DETAILS?.FROM_EMAIL_ADDRESS;
284
+ if (pdfBuffer) {
285
+ // this.sendEmailWithAttachments(this.sesClient, mailData, finalMessage, pdfBuffer)
286
+ }
287
+ else {
288
+ await this.sesClient.send(new client_ses_1.SendEmailCommand(params));
289
+ }
290
+ const maskedEmailsList = toAddr.map((email) => (0, Email_1.GetMaskedEmail)(email));
291
+ (0, config_1.getLogger)().info(`Sending email to: ${maskedEmailsList.join(", ")}`);
292
+ }
293
+ catch (error) {
294
+ (0, config_1.getLogger)().error("sendMail: Error", error);
295
+ }
296
+ }
297
+ async sendEmailWithAttachments(sesClient, mailData, finalMessage, attachment) {
298
+ const { toAddr, subject, ccAddr } = mailData;
299
+ // const from = CONTACT_US_DETAILS?.FROM_EMAIL_ADDRESS
300
+ const from = mailData.from;
301
+ const mimeMessage = (0, mimetext_1.createMimeMessage)();
302
+ mimeMessage.setSender(from);
303
+ // Set recipients - combine to and cc for mime message
304
+ const allRecipients = [...toAddr];
305
+ if (ccAddr && Array.isArray(ccAddr) && ccAddr.length > 0) {
306
+ allRecipients.push(...ccAddr);
307
+ }
308
+ mimeMessage.setRecipients(allRecipients);
309
+ // Add CC header if CC addresses are present
310
+ if (ccAddr && Array.isArray(ccAddr) && ccAddr.length > 0) {
311
+ mimeMessage.setHeader("Cc", ccAddr.join(", "));
312
+ }
313
+ mimeMessage.setSubject(subject);
314
+ mimeMessage.addMessage({ contentType: "text/html", data: finalMessage });
315
+ if (attachment) {
316
+ mimeMessage.addAttachment({
317
+ filename: "report.pdf",
318
+ contentType: "application/pdf",
319
+ data: attachment.toString("base64"),
320
+ });
321
+ }
322
+ const params = {
323
+ Destinations: allRecipients,
324
+ RawMessage: {
325
+ Data: Buffer.from(mimeMessage.asRaw(), "utf8"), // the raw message data needs to be sent as uint8array
326
+ },
327
+ Source: mimeMessage.getSender()?.addr,
328
+ };
329
+ // @ts-ignore
330
+ await sesClient.send(new client_ses_1.SendRawEmailCommand(params));
331
+ }
332
+ };
333
+ __setFunctionName(_classThis, "EmailService");
334
+ (() => {
335
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
336
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
337
+ EmailService = _classThis = _classDescriptor.value;
338
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
339
+ __runInitializers(_classThis, _classExtraInitializers);
340
+ })();
341
+ return EmailService = _classThis;
342
+ })();
343
+ exports.EmailService = EmailService;
package/dist/index.d.ts CHANGED
@@ -24,3 +24,4 @@ export * from "./notificationQueue";
24
24
  export * from "./webhooks";
25
25
  export * from "./Integrations";
26
26
  export * from "./Integrations/twilio";
27
+ export * from "./emails/emailService";
package/dist/index.js CHANGED
@@ -73,3 +73,5 @@ __exportStar(require("./webhooks"), exports);
73
73
  __exportStar(require("./Integrations"), exports);
74
74
  //Export Twilio Service
75
75
  __exportStar(require("./Integrations/twilio"), exports);
76
+ // Export Email Service
77
+ __exportStar(require("./emails/emailService"), exports);
@@ -58,7 +58,7 @@ class RateLimitUtils {
58
58
  maxTimeoutWindowMs: 120000,
59
59
  });
60
60
  configs.set(constants_1.CONNECTION_PROVIDERS.TTLOCK, {
61
- maxRequests: 15,
61
+ maxRequests: 100,
62
62
  windowMs: 60000, // 1 minute
63
63
  provider: constants_1.CONNECTION_PROVIDERS.TTLOCK,
64
64
  maxTimeoutWindowMs: 120000,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "13.3.15",
3
+ "version": "13.3.18",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -43,12 +43,15 @@
43
43
  "typescript": "^5.8.3"
44
44
  },
45
45
  "dependencies": {
46
+ "@aws-sdk/client-s3": "^3.835.0",
47
+ "@aws-sdk/client-ses": "3.1003.0",
46
48
  "axios": "1.10.0",
47
49
  "bullmq": "5.56.4",
48
50
  "dt-audit-library": "1.7.1",
49
51
  "dt-pub-sub": "^1.0.0",
50
52
  "ioredis": "5.6.1",
51
53
  "lodash": "^4.17.21",
54
+ "mimetext": "3.0.28",
52
55
  "mongoose": "8.17.1",
53
56
  "pg": "8.16.3",
54
57
  "svix": "1.84.1",
@@ -1,4 +0,0 @@
1
- export interface ISendSMSRequest {
2
- propertyId: string;
3
- message: string;
4
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +0,0 @@
1
- export declare class AdminRepository {
2
- private readonly axiosInstance;
3
- private readonly deviceRepository;
4
- private readonly postgres;
5
- constructor();
6
- getZonesByAccessGroupIds(accessGroupIds: string[]): Promise<any[]>;
7
- }
@@ -1,5 +0,0 @@
1
- export declare class AdminService {
2
- private readonly adminRepository;
3
- constructor();
4
- getZonesByAccessGroupIds(accessGroupIds: string[]): Promise<any[]>;
5
- }
@@ -1 +0,0 @@
1
- export * from "./Admin.service";
@@ -1,11 +0,0 @@
1
- /**
2
- * Example usage of AlertBuilder
3
- * This file demonstrates various ways to use the AlertBuilder pattern
4
- */
5
- export declare function createBasicAlert(): import("./alert.types").CreateAlertData;
6
- export declare function createDeviceAlert(): import("./alert.types").CreateAlertData;
7
- export declare function createSecurityAlert(): import("./alert.types").CreateAlertData;
8
- export declare function createEnergyAlert(): import("./alert.types").CreateAlertData;
9
- export declare function createHubAlert(): import("./alert.types").CreateAlertData;
10
- export declare function createSnoozedAlert(): import("./alert.types").CreateAlertData;
11
- export declare function createMultipleAlerts(): import("./alert.types").CreateAlertData[];
@@ -1,55 +0,0 @@
1
- import { AlertService } from "./Alert.service";
2
- /**
3
- * Example usage of the updated AlertService with AlertBuilder integration
4
- * This file demonstrates various ways to use the AlertService with the new AlertBuilder
5
- */
6
- export declare class AlertServiceExample {
7
- private readonly alertService;
8
- constructor(alertService: AlertService);
9
- /**
10
- * Example 1: Using the updated createAlert method with AlertBuilder
11
- */
12
- createAlertWithBuilder(): Promise<import("./alert.types").AlertDocument>;
13
- /**
14
- * Example 2: Using convenience methods for specific alert types
15
- */
16
- createSpecificAlerts(): Promise<{
17
- readinessAlert: import("./alert.types").AlertDocument;
18
- operationsAlert: import("./alert.types").AlertDocument;
19
- securityAlert: import("./alert.types").AlertDocument;
20
- energyAlert: import("./alert.types").AlertDocument;
21
- }>;
22
- /**
23
- * Example 3: Using device-specific alert methods
24
- */
25
- createDeviceAlerts(): Promise<{
26
- deviceAlert1: import("./alert.types").AlertDocument;
27
- deviceAlert2: import("./alert.types").AlertDocument;
28
- }>;
29
- /**
30
- * Example 4: Using hub-specific alert methods
31
- */
32
- createHubAlerts(): Promise<{
33
- hubAlert1: import("./alert.types").AlertDocument;
34
- hubAlert2: import("./alert.types").AlertDocument;
35
- }>;
36
- /**
37
- * Example 5: Using static factory methods with AlertBuilder
38
- */
39
- createAlertsWithStaticMethods(): Promise<{
40
- alert1: import("./alert.types").AlertDocument;
41
- alert2: import("./alert.types").AlertDocument;
42
- }>;
43
- /**
44
- * Example 6: Creating multiple alerts efficiently
45
- */
46
- createMultipleAlerts(): Promise<import("./alert.types").AlertDocument[]>;
47
- /**
48
- * Example 7: Creating alerts with snooze functionality
49
- */
50
- createSnoozedAlert(): Promise<import("./alert.types").AlertDocument>;
51
- /**
52
- * Example 8: Backward compatibility - still works with CreateAlertData
53
- */
54
- createAlertWithLegacyData(): Promise<import("./alert.types").AlertDocument>;
55
- }
@@ -1,16 +0,0 @@
1
- export interface AuditProperties {
2
- resource: string;
3
- propertyId: string;
4
- propertyName?: string;
5
- userId?: string;
6
- userName?: string;
7
- deviceId?: string;
8
- deviceName?: string;
9
- zoneId?: string;
10
- zoneName?: string;
11
- accessGroupId?: string;
12
- accessGroupName?: string;
13
- scheduleId?: string;
14
- scheduleName?: string;
15
- [key: string]: any;
16
- }
@@ -1,9 +0,0 @@
1
- import { ICronicle } from "./ICronicle.interface";
2
- export declare class CronicleService {
3
- private cronicleEndpoint;
4
- private cronicleApiKey;
5
- constructor();
6
- registerJob(payload: ICronicle): Promise<void>;
7
- getJob(jobId: string): Promise<any>;
8
- deleteJob(jobId: string): Promise<void>;
9
- }
@@ -1,14 +0,0 @@
1
- export interface ICronicle {
2
- name: string;
3
- cronJobId: string;
4
- apiUrl: string;
5
- method: "POST";
6
- target: string;
7
- schedule: {
8
- minutes?: string;
9
- hours?: string;
10
- dom?: string;
11
- month?: string;
12
- dow?: string;
13
- };
14
- }