dt-common-device 13.4.0 → 13.4.2

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 (101) hide show
  1. package/dist/emails/emailService.d.ts +0 -2
  2. package/dist/emails/emailService.js +0 -36
  3. package/package.json +4 -1
  4. package/dist/admin/Admin.repository.js +0 -182
  5. package/dist/admin/Admin.service.js +0 -17
  6. package/dist/admin/index.js +0 -17
  7. package/dist/alerts/AlertBuilder.example.js +0 -117
  8. package/dist/alerts/AlertService.example.js +0 -150
  9. package/dist/audit/AuditProperties.js +0 -2
  10. package/dist/chronicle/Cronicle.service.js +0 -76
  11. package/dist/chronicle/IChronicle.interface.js +0 -2
  12. package/dist/chronicle/ICronicle.interface.js +0 -2
  13. package/dist/chronicle/chronicle.service.js +0 -44
  14. package/dist/chronicle/index.js +0 -5
  15. package/dist/connection/Connection.repository.js +0 -92
  16. package/dist/connection/Connection.service.js +0 -32
  17. package/dist/connection/IConnection.js +0 -16
  18. package/dist/connection/index.js +0 -18
  19. package/dist/copilotQueue/examples/CopilotQueue.example.js +0 -140
  20. package/dist/copilotQueue/examples/index.js +0 -17
  21. package/dist/device/cloud/entities/CloudConnection.js +0 -6
  22. package/dist/device/cloud/entities/CloudDevice.js +0 -26
  23. package/dist/device/cloud/entities/CloudDeviceService.js +0 -9
  24. package/dist/device/cloud/entities/DeviceFactory.js +0 -80
  25. package/dist/device/cloud/entities/index.js +0 -19
  26. package/dist/device/cloud/interface.js +0 -3
  27. package/dist/device/cloud/interfaces/ICloudConnection.js +0 -2
  28. package/dist/device/cloud/interfaces/ICloudDevice.js +0 -2
  29. package/dist/device/cloud/interfaces/ICloudDeviceService.js +0 -2
  30. package/dist/device/cloud/interfaces/IConnectionService.js +0 -2
  31. package/dist/device/cloud/interfaces/IDeviceConnectionService.js +0 -3
  32. package/dist/device/cloud/interfaces/IDeviceFactory.js +0 -2
  33. package/dist/device/cloud/interfaces/IDeviceService.js +0 -2
  34. package/dist/device/cloud/interfaces/IDevicesService.js +0 -2
  35. package/dist/device/cloud/interfaces/IHubService.js +0 -2
  36. package/dist/device/cloud/interfaces/IRawDataTransformer.js +0 -2
  37. package/dist/device/cloud/interfaces/IRawDevice.js +0 -11
  38. package/dist/device/cloud/interfaces/index.js +0 -21
  39. package/dist/device/cloud/services/CloudDevice.service.js +0 -9
  40. package/dist/device/cloud/services/Connection.service.js +0 -6
  41. package/dist/device/cloud/services/Device.service.js +0 -9
  42. package/dist/device/cloud/services/DeviceCloudService.js +0 -59
  43. package/dist/device/cloud/services/DeviceHub.service.js +0 -6
  44. package/dist/device/cloud/services/Hub.service.js +0 -9
  45. package/dist/device/cloud/services/index.js +0 -18
  46. package/dist/device/index.js +0 -20
  47. package/dist/device/local/entities/AlertBuilder.example.js +0 -117
  48. package/dist/device/local/entities/AlertBuilder.js +0 -179
  49. package/dist/device/local/entities/index.js +0 -7
  50. package/dist/device/local/events/EventHandler.js +0 -86
  51. package/dist/device/local/events/Events.js +0 -57
  52. package/dist/device/local/events/index.js +0 -7
  53. package/dist/device/local/handler/EventHandler.js +0 -44
  54. package/dist/device/local/interface.js +0 -1
  55. package/dist/device/local/interfaces/IConnection.js +0 -14
  56. package/dist/device/local/interfaces/IDevice.js +0 -10
  57. package/dist/device/local/interfaces/IDtDevice.js +0 -2
  58. package/dist/device/local/interfaces/IHub.js +0 -2
  59. package/dist/device/local/interfaces/IProperty.js +0 -2
  60. package/dist/device/local/interfaces/ISchedule.js +0 -2
  61. package/dist/device/local/interfaces/index.js +0 -19
  62. package/dist/device/local/models/Alert.model.js +0 -222
  63. package/dist/device/local/models/Issue.model.js +0 -260
  64. package/dist/device/local/repository/Alert.repository.js +0 -374
  65. package/dist/device/local/repository/Connection.repository.js +0 -92
  66. package/dist/device/local/repository/Device.repository.js +0 -325
  67. package/dist/device/local/repository/Hub.repository.js +0 -139
  68. package/dist/device/local/repository/Issue.repository.js +0 -401
  69. package/dist/device/local/services/Alert.service.js +0 -475
  70. package/dist/device/local/services/AlertService.example.js +0 -148
  71. package/dist/device/local/services/Connection.service.js +0 -32
  72. package/dist/device/local/services/Device.service.js +0 -391
  73. package/dist/device/local/services/DeviceHub.service.js +0 -40
  74. package/dist/device/local/services/Hub.service.js +0 -107
  75. package/dist/device/local/services/index.js +0 -19
  76. package/dist/entities/accessGroup/AccessGroup.repository.js +0 -72
  77. package/dist/entities/accessGroup/AccessGroup.service.js +0 -105
  78. package/dist/entities/accessGroup/IAccessGroup.js +0 -2
  79. package/dist/entities/accessGroup/index.js +0 -18
  80. package/dist/entities/device/local/repository/DeviceProfile.repository.js +0 -75
  81. package/dist/entities/guest/Guest.repository.js +0 -74
  82. package/dist/entities/guest/Guest.service.js +0 -104
  83. package/dist/entities/guest/IGuest.js +0 -2
  84. package/dist/entities/guest/index.js +0 -18
  85. package/dist/entities/schedules/ISchedule.js +0 -2
  86. package/dist/entities/schedules/index.js +0 -18
  87. package/dist/entities/zone/index.js +0 -18
  88. package/dist/pms/IPms.js +0 -10
  89. package/dist/pms/index.js +0 -18
  90. package/dist/pms/webhookQueue/examples/index.js +0 -18
  91. package/dist/pms/webhookQueue/index.js +0 -20
  92. package/dist/pms/webhookQueue/interfaces/index.js +0 -17
  93. package/dist/pms/webhookQueue/services/index.js +0 -17
  94. package/dist/pms/webhookQueue/types/index.js +0 -17
  95. package/dist/property/IProperty.js +0 -2
  96. package/dist/property/index.js +0 -18
  97. package/dist/queue/interfaces/IHttpRequestJob.js +0 -2
  98. package/dist/types/alert.types.js +0 -22
  99. package/dist/types/config.types.js +0 -2
  100. package/dist/types/index.js +0 -19
  101. package/dist/utils/http-utils.js +0 -117
@@ -1,4 +1,3 @@
1
- import { SESClient } from "@aws-sdk/client-ses";
2
1
  export declare class EmailService {
3
2
  private readonly s3Client;
4
3
  private readonly sesClient;
@@ -12,5 +11,4 @@ export declare class EmailService {
12
11
  } | undefined>;
13
12
  getRawHtmlTemplate(fileName: string, propertyId?: string, organizationId?: string): Promise<any>;
14
13
  sendMail(mailData: any, pdfBuffer?: any): Promise<void>;
15
- sendEmailWithAttachments(sesClient: SESClient, mailData: any, finalMessage: string, attachment: any): Promise<void>;
16
14
  }
@@ -75,7 +75,6 @@ exports.EmailService = void 0;
75
75
  const client_s3_1 = require("@aws-sdk/client-s3");
76
76
  const client_ses_1 = require("@aws-sdk/client-ses");
77
77
  const fs = __importStar(require("fs"));
78
- const mimetext_1 = require("mimetext");
79
78
  const typedi_1 = __importStar(require("typedi"));
80
79
  const Email_1 = require("../constants/Email");
81
80
  const Property_service_1 = require("../entities/property/Property.service");
@@ -294,41 +293,6 @@ let EmailService = (() => {
294
293
  (0, config_1.getLogger)().error("sendMail: Error", error);
295
294
  }
296
295
  }
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
296
  };
333
297
  __setFunctionName(_classThis, "EmailService");
334
298
  (() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "13.4.0",
3
+ "version": "13.4.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -43,6 +43,8 @@
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",
@@ -52,6 +54,7 @@
52
54
  "mongoose": "8.17.1",
53
55
  "pg": "8.16.3",
54
56
  "svix": "1.84.1",
57
+ "twilio": "5.12.2",
55
58
  "typedi": "0.10.0"
56
59
  }
57
60
  }
@@ -1,182 +0,0 @@
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.AdminRepository = void 0;
75
- const typedi_1 = __importStar(require("typedi"));
76
- const utils_1 = require("../utils");
77
- const Device_repository_1 = require("../device/local/repository/Device.repository");
78
- const db_1 = require("../db/db");
79
- const interfaces_1 = require("../device/cloud/interfaces");
80
- let AdminRepository = (() => {
81
- let _classDecorators = [(0, typedi_1.Service)()];
82
- let _classDescriptor;
83
- let _classExtraInitializers = [];
84
- let _classThis;
85
- var AdminRepository = _classThis = class {
86
- constructor() {
87
- this.axiosInstance = (0, utils_1.getCloudServiceAxiosInstance)();
88
- this.deviceRepository = typedi_1.default.get(Device_repository_1.DeviceRepository);
89
- this.postgres = (0, db_1.getPostgresClient)();
90
- }
91
- async getZonesByAccessGroupIds(accessGroupIds) {
92
- const result = await this.postgres.query(`SELECT "zc".*, "z"."id", "z"."name"
93
- FROM "dt_zones_collection_map" "zc"
94
- INNER JOIN "dt_zones" "z" ON "zc"."zoneId" = "z"."id"
95
- WHERE "zc"."collectionId" = ANY($1)`, [accessGroupIds]);
96
- const response = result.rows;
97
- const _zones = (nestedZones, allzones = []) => {
98
- nestedZones.forEach((z) => {
99
- const onlyZone = { ...z };
100
- delete onlyZone.childZones;
101
- allzones.push(onlyZone);
102
- if (!Array.isArray(z.childZones)) {
103
- if (z.childZones.id)
104
- z.childZones = [z.childZones];
105
- }
106
- if (z.childZones.length) {
107
- _zones(z.childZones, allzones);
108
- }
109
- });
110
- return allzones.map((e) => e.id);
111
- };
112
- // const zones = _zones(response);
113
- const zoneIds = response.map((el) => el.id);
114
- const collectionZone = [];
115
- for (let i = 0; i < response.length; i++) {
116
- let zoneIds = [];
117
- const zones = await this.axiosInstance.get(`/zones/child?zoneId=${response[i].zoneId}`);
118
- zoneIds.push(response[i].zoneId);
119
- if (zones.childZones?.length > 0) {
120
- const nestedZoneIds = new Set(_zones(zones.childZones));
121
- zoneIds = [...zoneIds, ...nestedZoneIds];
122
- }
123
- if (collectionZone.length == 0) {
124
- const obj = {
125
- collectionId: response[i].collectionId,
126
- zoneIds,
127
- };
128
- collectionZone.push(obj);
129
- }
130
- else {
131
- const obj = collectionZone.find((e) => e.collectionId == response[i].collectionId);
132
- if (obj) {
133
- obj.zoneIds = [...obj.zoneIds, ...zoneIds];
134
- }
135
- else {
136
- collectionZone.push({
137
- collectionId: response[i].collectionId,
138
- zoneIds,
139
- });
140
- }
141
- }
142
- }
143
- let _zoneIds = collectionZone.flatMap((e) => {
144
- return e.zoneIds.map((z) => z);
145
- });
146
- if (_zoneIds.length === 0)
147
- return [];
148
- const deviecDetail = await this.deviceRepository.queryDevices({
149
- zoneIds: _zoneIds,
150
- excludeDeviceType: interfaces_1.DeviceType.HUB
151
- });
152
- const _collectionZone = collectionZone.map((e) => {
153
- const zones = e.zoneIds;
154
- let devices = [];
155
- zones.forEach((element) => {
156
- const device = deviecDetail.filter((d) => d.zoneId == element);
157
- // Add collectionId to each device
158
- device.forEach((dev) => {
159
- dev.collectionId = e.collectionId;
160
- });
161
- const _devices = devices.concat(device);
162
- devices = _devices;
163
- });
164
- e.devices = devices;
165
- e.parentZone = response;
166
- return e;
167
- });
168
- const collectionZoneDevices = Array.from(new Set(_collectionZone));
169
- return collectionZoneDevices;
170
- }
171
- };
172
- __setFunctionName(_classThis, "AdminRepository");
173
- (() => {
174
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
175
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
176
- AdminRepository = _classThis = _classDescriptor.value;
177
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
178
- __runInitializers(_classThis, _classExtraInitializers);
179
- })();
180
- return AdminRepository = _classThis;
181
- })();
182
- exports.AdminRepository = AdminRepository;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.AdminService = void 0;
7
- const typedi_1 = __importDefault(require("typedi"));
8
- const Admin_repository_1 = require("./Admin.repository");
9
- class AdminService {
10
- constructor() {
11
- this.adminRepository = typedi_1.default.get(Admin_repository_1.AdminRepository);
12
- }
13
- async getZonesByAccessGroupIds(accessGroupIds) {
14
- return await this.adminRepository.getZonesByAccessGroupIds(accessGroupIds);
15
- }
16
- }
17
- exports.AdminService = AdminService;
@@ -1,17 +0,0 @@
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("./Admin.service"), exports);
@@ -1,117 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createBasicAlert = createBasicAlert;
4
- exports.createDeviceAlert = createDeviceAlert;
5
- exports.createSecurityAlert = createSecurityAlert;
6
- exports.createEnergyAlert = createEnergyAlert;
7
- exports.createHubAlert = createHubAlert;
8
- exports.createSnoozedAlert = createSnoozedAlert;
9
- exports.createMultipleAlerts = createMultipleAlerts;
10
- const AlertBuilder_1 = require("./AlertBuilder");
11
- const alert_types_1 = require("./alert.types");
12
- /**
13
- * Example usage of AlertBuilder
14
- * This file demonstrates various ways to use the AlertBuilder pattern
15
- */
16
- // Example 1: Basic alert creation
17
- function createBasicAlert() {
18
- const alertData = new AlertBuilder_1.AlertBuilder()
19
- .setCategory(alert_types_1.AlertCategory.OPERATIONS)
20
- .setPropertyId("prop123")
21
- .setTitle("Device Offline")
22
- .setDescription("Device has been offline for more than 5 minutes")
23
- .setEntityId("device456")
24
- .setEntityType(alert_types_1.EntityType.DEVICE)
25
- .setSeverity(alert_types_1.AlertSeverity.HIGH)
26
- .setCreatedBy("user789")
27
- .build();
28
- return alertData;
29
- }
30
- // Example 2: Using static factory methods
31
- function createDeviceAlert() {
32
- const alertData = AlertBuilder_1.AlertBuilder.createDeviceAlert("device123", "prop456")
33
- .setCategory(alert_types_1.AlertCategory.READINESS)
34
- .setTitle("Device Maintenance Required")
35
- .setDescription("Device firmware update is available")
36
- .setSeverity(alert_types_1.AlertSeverity.MEDIUM)
37
- .setCreatedBy("system")
38
- .build();
39
- return alertData;
40
- }
41
- // Example 3: Using predefined alert types
42
- function createSecurityAlert() {
43
- const alertData = AlertBuilder_1.AlertBuilder.createSecurityAlert()
44
- .setPropertyId("prop789")
45
- .setTitle("Unauthorized Access Attempt")
46
- .setDescription("Multiple failed login attempts detected")
47
- .setEntityId("user123")
48
- .setEntityType(alert_types_1.EntityType.USER)
49
- .setCreatedBy("security-system")
50
- .build();
51
- return alertData;
52
- }
53
- // Example 4: Creating energy alert
54
- function createEnergyAlert() {
55
- const alertData = AlertBuilder_1.AlertBuilder.createEnergyAlert()
56
- .setPropertyId("prop101")
57
- .setTitle("High Energy Consumption")
58
- .setDescription("Energy usage is 20% above normal levels")
59
- .setEntityId("zone456")
60
- .setEntityType(alert_types_1.EntityType.COLLECTION)
61
- .setCreatedBy("energy-monitor")
62
- .build();
63
- return alertData;
64
- }
65
- // Example 5: Creating hub alert
66
- function createHubAlert() {
67
- const alertData = AlertBuilder_1.AlertBuilder.createHubAlert("hub789", "prop202")
68
- .setCategory(alert_types_1.AlertCategory.OPERATIONS)
69
- .setTitle("Hub Connection Lost")
70
- .setDescription("Hub has lost connection to the network")
71
- .setSeverity(alert_types_1.AlertSeverity.CRITICAL)
72
- .setCreatedBy("network-monitor")
73
- .build();
74
- return alertData;
75
- }
76
- // Example 6: Alert with snooze
77
- function createSnoozedAlert() {
78
- const snoozeUntil = new Date();
79
- snoozeUntil.setHours(snoozeUntil.getHours() + 2); // Snooze for 2 hours
80
- const alertData = new AlertBuilder_1.AlertBuilder()
81
- .setCategory(alert_types_1.AlertCategory.OTHER)
82
- .setPropertyId("prop303")
83
- .setTitle("Scheduled Maintenance")
84
- .setDescription("System maintenance scheduled for tonight")
85
- .setEntityType(alert_types_1.EntityType.PROPERTY)
86
- .setSeverity(alert_types_1.AlertSeverity.INFO)
87
- .setCreatedBy("admin")
88
- .setSnoozeUntil(snoozeUntil)
89
- .build();
90
- return alertData;
91
- }
92
- // Example 7: Reusing builder instance
93
- function createMultipleAlerts() {
94
- const builder = new AlertBuilder_1.AlertBuilder()
95
- .setPropertyId("prop404")
96
- .setCreatedBy("system");
97
- const alert1 = builder
98
- .setCategory(alert_types_1.AlertCategory.OPERATIONS)
99
- .setTitle("Device Temperature High")
100
- .setDescription("Device temperature exceeds normal operating range")
101
- .setEntityId("device789")
102
- .setEntityType(alert_types_1.EntityType.DEVICE)
103
- .setSeverity(alert_types_1.AlertSeverity.HIGH)
104
- .build();
105
- const alert2 = builder
106
- .reset()
107
- .setPropertyId("prop404")
108
- .setCategory(alert_types_1.AlertCategory.ENERGY)
109
- .setTitle("Low Battery Warning")
110
- .setDescription("Device battery level is below 20%")
111
- .setEntityId("device789")
112
- .setEntityType(alert_types_1.EntityType.DEVICE)
113
- .setSeverity(alert_types_1.AlertSeverity.MEDIUM)
114
- .setCreatedBy("system")
115
- .build();
116
- return [alert1, alert2];
117
- }
@@ -1,150 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AlertServiceExample = void 0;
4
- const Service_1 = require("../constants/Service");
5
- const AlertBuilder_1 = require("./AlertBuilder");
6
- const alert_types_1 = require("./alert.types");
7
- /**
8
- * Example usage of the updated AlertService with AlertBuilder integration
9
- * This file demonstrates various ways to use the AlertService with the new AlertBuilder
10
- */
11
- class AlertServiceExample {
12
- constructor(alertService) {
13
- this.alertService = alertService;
14
- }
15
- /**
16
- * Example 1: Using the updated createAlert method with AlertBuilder
17
- */
18
- async createAlertWithBuilder() {
19
- const alertBuilder = new AlertBuilder_1.AlertBuilder()
20
- .setCategory(alert_types_1.AlertCategory.OPERATIONS)
21
- .setPropertyId("prop123")
22
- .setTitle("Device Offline")
23
- .setDescription("Device has been offline for more than 5 minutes")
24
- .setEntityId("device456")
25
- .setEntityType(alert_types_1.EntityType.DEVICE)
26
- .setSeverity(alert_types_1.AlertSeverity.HIGH)
27
- .setCreatedBy("user789");
28
- // Pass the AlertBuilder directly to createAlert
29
- const alert = await this.alertService.createAlert(alertBuilder);
30
- return alert;
31
- }
32
- /**
33
- * Example 2: Using convenience methods for specific alert types
34
- */
35
- async createSpecificAlerts() {
36
- // Create a readiness alert
37
- const readinessAlert = await this.alertService.raiseReadinessAlert("prop123", "System Maintenance Required", "System maintenance is scheduled for tonight", "system456", alert_types_1.EntityType.PROPERTY, "admin");
38
- // Create an operations alert
39
- const operationsAlert = await this.alertService.raiseOperationsAlert("prop123", "Device Temperature High", "Device temperature exceeds normal operating range", "device789", alert_types_1.EntityType.DEVICE, "monitor");
40
- // Create a security alert
41
- const securityAlert = await this.alertService.raiseSecurityAlert("prop123", "Unauthorized Access Attempt", "Multiple failed login attempts detected", "user123", alert_types_1.EntityType.USER, "security-system");
42
- // Create an energy alert
43
- const energyAlert = await this.alertService.raiseEnergyAlert("prop123", "High Energy Consumption", "Energy usage is 20% above normal levels", "zone456", alert_types_1.EntityType.COLLECTION, "energy-monitor");
44
- return { readinessAlert, operationsAlert, securityAlert, energyAlert };
45
- }
46
- /**
47
- * Example 3: Using device-specific alert methods
48
- */
49
- async createDeviceAlerts() {
50
- // Create a device alert with default category and severity
51
- const deviceAlert1 = await this.alertService.raiseDeviceAlert("device123", "prop456", "Device Battery Low", "Device battery level is below 20%", undefined, // Use default category
52
- undefined, // Use default severity
53
- Service_1.Source.CLOUD_EVENT);
54
- // Create a device alert with custom category and severity
55
- const deviceAlert2 = await this.alertService.raiseDeviceAlert("device789", "prop456", "Device Firmware Update Available", "New firmware version is available for installation", alert_types_1.AlertCategory.READINESS, alert_types_1.AlertSeverity.MEDIUM, Service_1.Source.CLOUD_EVENT);
56
- return { deviceAlert1, deviceAlert2 };
57
- }
58
- /**
59
- * Example 4: Using hub-specific alert methods
60
- */
61
- async createHubAlerts() {
62
- // Create a hub alert with default settings
63
- const hubAlert1 = await this.alertService.raiseHubAlert("hub123", "prop456", "Hub Connection Lost", "Hub has lost connection to the network", undefined, // Use default category
64
- undefined, // Use default severity
65
- "network-monitor");
66
- // Create a hub alert with custom settings
67
- const hubAlert2 = await this.alertService.raiseHubAlert("hub789", "prop456", "Hub Maintenance Required", "Hub requires scheduled maintenance", alert_types_1.AlertCategory.READINESS, alert_types_1.AlertSeverity.LOW, "maintenance-system");
68
- return { hubAlert1, hubAlert2 };
69
- }
70
- /**
71
- * Example 5: Using static factory methods with AlertBuilder
72
- */
73
- async createAlertsWithStaticMethods() {
74
- // Create a device alert using static factory method
75
- const deviceAlert = AlertBuilder_1.AlertBuilder.createDeviceAlert("device123", "prop456")
76
- .setCategory(alert_types_1.AlertCategory.OPERATIONS)
77
- .setTitle("Device Offline")
78
- .setDescription("Device has been offline for more than 5 minutes")
79
- .setSeverity(alert_types_1.AlertSeverity.HIGH)
80
- .setCreatedBy("monitor");
81
- const alert1 = await this.alertService.createAlert(deviceAlert);
82
- // Create a hub alert using static factory method
83
- const hubAlert = AlertBuilder_1.AlertBuilder.createHubAlert("hub789", "prop202")
84
- .setCategory(alert_types_1.AlertCategory.SECURITY)
85
- .setTitle("Hub Security Breach")
86
- .setDescription("Unauthorized access attempt detected on hub")
87
- .setSeverity(alert_types_1.AlertSeverity.CRITICAL)
88
- .setCreatedBy("security-system");
89
- const alert2 = await this.alertService.createAlert(hubAlert);
90
- return { alert1, alert2 };
91
- }
92
- /**
93
- * Example 6: Creating multiple alerts efficiently
94
- */
95
- async createMultipleAlerts() {
96
- const alerts = [];
97
- // Create multiple device alerts efficiently
98
- const deviceIds = ["device1", "device2", "device3"];
99
- const propertyId = "prop123";
100
- for (const deviceId of deviceIds) {
101
- const alertBuilder = AlertBuilder_1.AlertBuilder.createDeviceAlert(deviceId, propertyId)
102
- .setCategory(alert_types_1.AlertCategory.OPERATIONS)
103
- .setTitle(`Device ${deviceId} Status`)
104
- .setDescription(`Status check for device ${deviceId}`)
105
- .setSeverity(alert_types_1.AlertSeverity.MEDIUM)
106
- .setCreatedBy("batch-processor");
107
- const alert = await this.alertService.createAlert(alertBuilder);
108
- alerts.push(alert);
109
- }
110
- return alerts;
111
- }
112
- /**
113
- * Example 7: Creating alerts with snooze functionality
114
- */
115
- async createSnoozedAlert() {
116
- const snoozeUntil = new Date();
117
- snoozeUntil.setHours(snoozeUntil.getHours() + 2); // Snooze for 2 hours
118
- const alertBuilder = new AlertBuilder_1.AlertBuilder()
119
- .setCategory(alert_types_1.AlertCategory.OTHER)
120
- .setPropertyId("prop303")
121
- .setTitle("Scheduled Maintenance")
122
- .setDescription("System maintenance scheduled for tonight")
123
- .setEntityType(alert_types_1.EntityType.PROPERTY)
124
- .setSeverity(alert_types_1.AlertSeverity.INFO)
125
- .setCreatedBy("admin")
126
- .setSnoozeUntil(snoozeUntil);
127
- const alert = await this.alertService.createAlert(alertBuilder);
128
- return alert;
129
- }
130
- /**
131
- * Example 8: Backward compatibility - still works with CreateAlertData
132
- */
133
- async createAlertWithLegacyData() {
134
- const alertData = {
135
- category: alert_types_1.AlertCategory.OPERATIONS,
136
- propertyId: "prop123",
137
- title: "Legacy Alert",
138
- description: "This alert was created using the old CreateAlertData format",
139
- entityId: "device456",
140
- entityType: alert_types_1.EntityType.DEVICE,
141
- severity: alert_types_1.AlertSeverity.MEDIUM,
142
- createdBy: "legacy-system",
143
- source: Service_1.Source.CLOUD_EVENT,
144
- };
145
- // This still works with the updated createAlert method
146
- const alert = await this.alertService.createAlert(alertData);
147
- return alert;
148
- }
149
- }
150
- exports.AlertServiceExample = AlertServiceExample;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,76 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CronicleService = void 0;
7
- const config_1 = require("../config/config");
8
- const axios_1 = __importDefault(require("axios"));
9
- class CronicleService {
10
- constructor() {
11
- this.cronicleEndpoint = process.env.CRONICLE_ENDPOINT || "";
12
- this.cronicleApiKey = process.env.CRONICLE_API_KEY || "";
13
- }
14
- async registerJob(payload) {
15
- const { name, apiUrl, method, schedule, cronJobId, target } = payload;
16
- try {
17
- await axios_1.default.post(`${this.cronicleEndpoint}/create_event/v1`, {
18
- id: cronJobId,
19
- title: name,
20
- category: "general",
21
- plugin: "urlplug",
22
- timeZone: "UTC",
23
- enabled: 1,
24
- target: target,
25
- api_key: this.cronicleApiKey,
26
- params: {
27
- url: apiUrl,
28
- method,
29
- headers: {
30
- "Content-Type": "application/json",
31
- "x-api-key": this.cronicleApiKey,
32
- },
33
- },
34
- data: payload,
35
- timing: {
36
- years: schedule.years,
37
- months: schedule.months,
38
- days: schedule.days,
39
- weekdays: schedule.weekdays,
40
- hours: schedule.hours,
41
- minutes: schedule.minutes,
42
- },
43
- });
44
- }
45
- catch (error) {
46
- (0, config_1.getConfig)().LOGGER.error(`Failed to create device: ${error.message}`);
47
- }
48
- }
49
- async getJob(jobId) {
50
- try {
51
- const res = await axios_1.default.post(`${this.cronicleEndpoint}/get_event/v1`, {
52
- id: jobId,
53
- api_key: this.cronicleApiKey,
54
- });
55
- return res.data;
56
- }
57
- catch (error) {
58
- return;
59
- }
60
- }
61
- async deleteJob(jobId) {
62
- try {
63
- (0, config_1.getConfig)().LOGGER.info(`Deleting job: ${jobId}`);
64
- await axios_1.default.post(`${this.cronicleEndpoint}/delete_event/v1`, {
65
- id: jobId,
66
- api_key: this.cronicleApiKey,
67
- });
68
- (0, config_1.getConfig)().LOGGER.info(`Deleted job: ${jobId}`);
69
- }
70
- catch (error) {
71
- (0, config_1.getConfig)().LOGGER.error(`Failed to delete job: ${error.message}`);
72
- throw error;
73
- }
74
- }
75
- }
76
- exports.CronicleService = CronicleService;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });