dt-common-device 13.4.5 → 13.4.7

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.
@@ -5,6 +5,7 @@ export declare function getConfig(): IConfig;
5
5
  export declare function getDeviceServiceUrl(): string;
6
6
  export declare function getAdminServiceUrl(): string;
7
7
  export declare function getMonitoringServiceUrl(): string;
8
+ export declare function getNotificationServiceUrl(): string;
8
9
  export declare function getSqsQueueUrl(): string;
9
10
  export declare function getReservationSqsQueueUrl(): string;
10
11
  export declare function getHeartbeatSqsQueueUrl(): string;
@@ -41,6 +41,7 @@ exports.getConfig = getConfig;
41
41
  exports.getDeviceServiceUrl = getDeviceServiceUrl;
42
42
  exports.getAdminServiceUrl = getAdminServiceUrl;
43
43
  exports.getMonitoringServiceUrl = getMonitoringServiceUrl;
44
+ exports.getNotificationServiceUrl = getNotificationServiceUrl;
44
45
  exports.getSqsQueueUrl = getSqsQueueUrl;
45
46
  exports.getReservationSqsQueueUrl = getReservationSqsQueueUrl;
46
47
  exports.getHeartbeatSqsQueueUrl = getHeartbeatSqsQueueUrl;
@@ -194,6 +195,14 @@ function getMonitoringServiceUrl() {
194
195
  }
195
196
  return monitoringServiceUrl;
196
197
  }
198
+ function getNotificationServiceUrl() {
199
+ const notificationServiceUrl = process.env.NOTIFICATION_SERVICE;
200
+ if (!notificationServiceUrl) {
201
+ getConfig().LOGGER.error("NOTIFICATION_SERVICE must be set in environment variables");
202
+ throw new Error("dt-common-device: NOTIFICATION_SERVICE must be set in environment variables");
203
+ }
204
+ return notificationServiceUrl;
205
+ }
197
206
  function getSqsQueueUrl() {
198
207
  if (constants_1.CONFIG_KEYS[sourceKey].env.includes("AWS_SQS_URL")) {
199
208
  const sqsQueueUrl = process.env.AWS_SQS_URL;
@@ -285,7 +285,7 @@ let EmailService = (() => {
285
285
  (0, config_1.getLogger)().info(`Sending email to: ${maskedEmailsList.join(", ")}`);
286
286
  }
287
287
  catch (error) {
288
- (0, config_1.getLogger)().error("sendMail: Error", error);
288
+ (0, config_1.getLogger)().error("sendMail: Error", JSON.stringify(error));
289
289
  }
290
290
  }
291
291
  };
@@ -1,4 +1,4 @@
1
- import { IAccessGroup, INotificationTemplate, INotificationTemplateResolve, IUser, IZone, IZoneAccessGroup } from "./IAdmin";
1
+ import { IAccessGroup, IUser, IZone, IZoneAccessGroup } from "./IAdmin";
2
2
  export declare class AdminRepository {
3
3
  private readonly deviceRepository;
4
4
  private readonly postgres;
@@ -23,5 +23,4 @@ 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>;
27
26
  }
@@ -536,16 +536,6 @@ 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
- }
549
539
  };
550
540
  __setFunctionName(_classThis, "AdminRepository");
551
541
  (() => {
@@ -1,4 +1,4 @@
1
- import { IAccessGroup, INotificationTemplate, INotificationTemplateResolve, IUser, IZone } from "./IAdmin";
1
+ import { IAccessGroup, IUser, IZone } from "./IAdmin";
2
2
  export declare class AdminService {
3
3
  private readonly adminRepository;
4
4
  private readonly redisUtils;
@@ -17,5 +17,4 @@ 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>;
21
20
  }
@@ -310,15 +310,6 @@ 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
- }
322
313
  };
323
314
  __setFunctionName(_classThis, "AdminService");
324
315
  (() => {
@@ -48,31 +48,3 @@ 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
- }
@@ -0,0 +1,28 @@
1
+ export type NotificationChannel = "email" | "sms";
2
+ export type NotificationScope = "platform" | "organization" | "property";
3
+ export interface INotificationTemplateResolve {
4
+ propertyId?: string;
5
+ organizationId?: string;
6
+ eventName?: string;
7
+ channel?: NotificationChannel;
8
+ }
9
+ export interface INotificationTemplate {
10
+ _id?: string;
11
+ id?: string;
12
+ eventName: string;
13
+ channel: NotificationChannel;
14
+ scope: NotificationScope;
15
+ organizationId: string | null;
16
+ propertyId: string | null;
17
+ subject?: string;
18
+ template: string;
19
+ variables: string[];
20
+ isActive: boolean;
21
+ isDeleted?: boolean;
22
+ createdBy?: string;
23
+ updatedBy?: string;
24
+ createdAt?: Date;
25
+ updatedAt?: Date;
26
+ deletedAt?: Date;
27
+ deletedBy?: string;
28
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import { INotificationTemplate, INotificationTemplateResolve } from "./INotification";
2
+ export declare class NotificationRepository {
3
+ getNotificationTemplate(payload: INotificationTemplateResolve): Promise<INotificationTemplate | null>;
4
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
36
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
37
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
38
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
39
+ };
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.NotificationRepository = void 0;
42
+ const typedi_1 = require("typedi");
43
+ const http_utils_1 = require("../../utils/http.utils");
44
+ let NotificationRepository = (() => {
45
+ let _classDecorators = [(0, typedi_1.Service)()];
46
+ let _classDescriptor;
47
+ let _classExtraInitializers = [];
48
+ let _classThis;
49
+ var NotificationRepository = _classThis = class {
50
+ async getNotificationTemplate(payload) {
51
+ if (!payload.propertyId ||
52
+ !payload.organizationId ||
53
+ !payload.eventName ||
54
+ !payload.channel) {
55
+ throw new Error("Property ID, Organization ID, Event Name, and Channel are required in payload");
56
+ }
57
+ const response = await (0, http_utils_1.getNotificationServiceAxiosInstance)().post(`/notification-templates/resolve`, payload);
58
+ return response.data.data;
59
+ }
60
+ };
61
+ __setFunctionName(_classThis, "NotificationRepository");
62
+ (() => {
63
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
64
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
65
+ NotificationRepository = _classThis = _classDescriptor.value;
66
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
67
+ __runInitializers(_classThis, _classExtraInitializers);
68
+ })();
69
+ return NotificationRepository = _classThis;
70
+ })();
71
+ exports.NotificationRepository = NotificationRepository;
@@ -0,0 +1,6 @@
1
+ import { INotificationTemplate, INotificationTemplateResolve } from "./INotification";
2
+ export declare class NotificationService {
3
+ private readonly notificationRepository;
4
+ constructor();
5
+ getNotificationTemplate(payload: INotificationTemplateResolve): Promise<INotificationTemplate | null>;
6
+ }
@@ -0,0 +1,106 @@
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.NotificationService = void 0;
75
+ const typedi_1 = __importStar(require("typedi"));
76
+ const Notification_repository_1 = require("./Notification.repository");
77
+ let NotificationService = (() => {
78
+ let _classDecorators = [(0, typedi_1.Service)()];
79
+ let _classDescriptor;
80
+ let _classExtraInitializers = [];
81
+ let _classThis;
82
+ var NotificationService = _classThis = class {
83
+ constructor() {
84
+ this.notificationRepository = typedi_1.default.get(Notification_repository_1.NotificationRepository);
85
+ }
86
+ async getNotificationTemplate(payload) {
87
+ if (!payload.propertyId ||
88
+ !payload.organizationId ||
89
+ !payload.eventName ||
90
+ !payload.channel) {
91
+ throw new Error("Property ID, Organization ID, Event Name, and Channel are required");
92
+ }
93
+ return await this.notificationRepository.getNotificationTemplate(payload);
94
+ }
95
+ };
96
+ __setFunctionName(_classThis, "NotificationService");
97
+ (() => {
98
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
99
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
100
+ NotificationService = _classThis = _classDescriptor.value;
101
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
102
+ __runInitializers(_classThis, _classExtraInitializers);
103
+ })();
104
+ return NotificationService = _classThis;
105
+ })();
106
+ exports.NotificationService = NotificationService;
@@ -0,0 +1,2 @@
1
+ export * from "./Notification.service";
2
+ export * from "./INotification";
@@ -0,0 +1,18 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Notification.service"), exports);
18
+ __exportStar(require("./INotification"), exports);
package/dist/index.d.ts CHANGED
@@ -25,3 +25,4 @@ export * from "./webhooks";
25
25
  export * from "./Integrations";
26
26
  export * from "./Integrations/twilio";
27
27
  export * from "./emails/emailService";
28
+ export * from "./entities/notification";
package/dist/index.js CHANGED
@@ -75,3 +75,5 @@ __exportStar(require("./Integrations"), exports);
75
75
  __exportStar(require("./Integrations/twilio"), exports);
76
76
  // Export Email Service
77
77
  __exportStar(require("./emails/emailService"), exports);
78
+ // Export Notification Service
79
+ __exportStar(require("./entities/notification"), exports);
@@ -9,6 +9,7 @@ export declare function createAxiosInstance(baseURL?: string): import("axios").A
9
9
  export declare function getDeviceServiceAxiosInstance(): any;
10
10
  export declare function getAdminServiceAxiosInstance(): any;
11
11
  export declare function getMonitoringServiceAxiosInstance(): any;
12
+ export declare function getNotificationServiceAxiosInstance(): any;
12
13
  /**
13
14
  * Retry function for failed HTTP requests
14
15
  */
@@ -8,6 +8,7 @@ exports.createAxiosInstance = createAxiosInstance;
8
8
  exports.getDeviceServiceAxiosInstance = getDeviceServiceAxiosInstance;
9
9
  exports.getAdminServiceAxiosInstance = getAdminServiceAxiosInstance;
10
10
  exports.getMonitoringServiceAxiosInstance = getMonitoringServiceAxiosInstance;
11
+ exports.getNotificationServiceAxiosInstance = getNotificationServiceAxiosInstance;
11
12
  exports.retryRequest = retryRequest;
12
13
  const config_1 = require("../config/config");
13
14
  const axios_1 = __importDefault(require("axios"));
@@ -105,6 +106,13 @@ function getMonitoringServiceAxiosInstance() {
105
106
  }
106
107
  return deviceMonitoringServiceAxiosInstance;
107
108
  }
109
+ let notificationServiceAxiosInstance = null;
110
+ function getNotificationServiceAxiosInstance() {
111
+ if (!notificationServiceAxiosInstance) {
112
+ notificationServiceAxiosInstance = createAxiosInstance((0, config_1.getNotificationServiceUrl)());
113
+ }
114
+ return notificationServiceAxiosInstance;
115
+ }
108
116
  /**
109
117
  * Retry function for failed HTTP requests
110
118
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "13.4.5",
3
+ "version": "13.4.7",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [