dt-common-device 11.2.2 → 11.2.3

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 (242) hide show
  1. package/dist/chronicle/Cronicle.service.d.ts +6 -2
  2. package/dist/chronicle/Cronicle.service.js +19 -2
  3. package/dist/chronicle/ICronicle.interface.d.ts +1 -0
  4. package/dist/config/config.js +0 -5
  5. package/dist/config/config.types.d.ts +1 -1
  6. package/dist/config/constants.d.ts +0 -7
  7. package/dist/config/constants.js +2 -7
  8. package/dist/constants/ConnectionProviders.d.ts +0 -1
  9. package/dist/constants/ConnectionProviders.js +0 -1
  10. package/dist/entities/accessGroup/AccessGroup.repository.d.ts +2 -1
  11. package/dist/entities/accessGroup/AccessGroup.repository.js +4 -1
  12. package/dist/entities/accessGroup/AccessGroup.service.d.ts +2 -1
  13. package/dist/entities/accessGroup/AccessGroup.service.js +4 -3
  14. package/dist/entities/admin/Admin.repository.d.ts +1 -2
  15. package/dist/entities/admin/Admin.repository.js +19 -15
  16. package/dist/entities/admin/Admin.service.d.ts +1 -1
  17. package/dist/entities/admin/Admin.service.js +2 -2
  18. package/dist/entities/connection/Connection.repository.d.ts +1 -0
  19. package/dist/entities/connection/Connection.repository.js +22 -0
  20. package/dist/entities/connection/Connection.service.d.ts +1 -0
  21. package/dist/entities/connection/Connection.service.js +3 -0
  22. package/dist/entities/guest/Guest.repository.d.ts +1 -1
  23. package/dist/entities/guest/Guest.repository.js +5 -2
  24. package/dist/entities/guest/Guest.service.d.ts +1 -1
  25. package/dist/entities/guest/Guest.service.js +4 -1
  26. package/dist/entities/schedules/Schedule.repository.d.ts +1 -1
  27. package/dist/entities/schedules/Schedule.repository.js +5 -2
  28. package/dist/entities/schedules/Schedule.service.d.ts +1 -1
  29. package/dist/entities/schedules/Schedule.service.js +4 -1
  30. package/dist/entities/user/User.repository.js +4 -1
  31. package/dist/entities/user/User.service.d.ts +1 -1
  32. package/dist/entities/user/User.service.js +4 -1
  33. package/dist/entities/zone/Zone.service.js +4 -1
  34. package/dist/issues/Issue.service.js +1 -1
  35. package/dist/queue/utils/rateLimit.utils.js +0 -6
  36. package/package.json +1 -1
  37. package/dist/admin/Admin.repository.d.ts +0 -7
  38. package/dist/admin/Admin.repository.js +0 -182
  39. package/dist/admin/Admin.service.d.ts +0 -5
  40. package/dist/admin/Admin.service.js +0 -17
  41. package/dist/admin/index.d.ts +0 -1
  42. package/dist/admin/index.js +0 -17
  43. package/dist/audit/AuditProperties.d.ts +0 -16
  44. package/dist/audit/AuditProperties.js +0 -2
  45. package/dist/chronicle/IChronicle.interface.d.ts +0 -14
  46. package/dist/chronicle/IChronicle.interface.js +0 -2
  47. package/dist/chronicle/chronicle.service.d.ts +0 -4
  48. package/dist/chronicle/chronicle.service.js +0 -44
  49. package/dist/connection/Connection.repository.d.ts +0 -8
  50. package/dist/connection/Connection.repository.js +0 -92
  51. package/dist/connection/Connection.service.d.ts +0 -8
  52. package/dist/connection/Connection.service.js +0 -32
  53. package/dist/connection/IConnection.d.ts +0 -28
  54. package/dist/connection/IConnection.js +0 -16
  55. package/dist/connection/index.d.ts +0 -2
  56. package/dist/connection/index.js +0 -18
  57. package/dist/copilotQueue/examples/CopilotQueue.example.d.ts +0 -37
  58. package/dist/copilotQueue/examples/CopilotQueue.example.js +0 -140
  59. package/dist/copilotQueue/examples/index.d.ts +0 -1
  60. package/dist/copilotQueue/examples/index.js +0 -17
  61. package/dist/device/cloud/entities/CloudConnection.d.ts +0 -6
  62. package/dist/device/cloud/entities/CloudConnection.js +0 -6
  63. package/dist/device/cloud/entities/CloudDevice.d.ts +0 -16
  64. package/dist/device/cloud/entities/CloudDevice.js +0 -26
  65. package/dist/device/cloud/entities/CloudDeviceService.d.ts +0 -5
  66. package/dist/device/cloud/entities/CloudDeviceService.js +0 -9
  67. package/dist/device/cloud/entities/DeviceFactory.d.ts +0 -7
  68. package/dist/device/cloud/entities/DeviceFactory.js +0 -80
  69. package/dist/device/cloud/entities/index.d.ts +0 -3
  70. package/dist/device/cloud/entities/index.js +0 -19
  71. package/dist/device/cloud/interface.d.ts +0 -101
  72. package/dist/device/cloud/interface.js +0 -3
  73. package/dist/device/cloud/interfaces/ICloudConnection.d.ts +0 -5
  74. package/dist/device/cloud/interfaces/ICloudConnection.js +0 -2
  75. package/dist/device/cloud/interfaces/ICloudDevice.d.ts +0 -9
  76. package/dist/device/cloud/interfaces/ICloudDevice.js +0 -2
  77. package/dist/device/cloud/interfaces/ICloudDeviceService.d.ts +0 -4
  78. package/dist/device/cloud/interfaces/ICloudDeviceService.js +0 -2
  79. package/dist/device/cloud/interfaces/IConnectionService.d.ts +0 -7
  80. package/dist/device/cloud/interfaces/IConnectionService.js +0 -2
  81. package/dist/device/cloud/interfaces/IDeviceConnectionService.d.ts +0 -7
  82. package/dist/device/cloud/interfaces/IDeviceConnectionService.js +0 -3
  83. package/dist/device/cloud/interfaces/IDeviceFactory.d.ts +0 -4
  84. package/dist/device/cloud/interfaces/IDeviceFactory.js +0 -2
  85. package/dist/device/cloud/interfaces/IDeviceService.d.ts +0 -8
  86. package/dist/device/cloud/interfaces/IDeviceService.js +0 -2
  87. package/dist/device/cloud/interfaces/IDevicesService.d.ts +0 -9
  88. package/dist/device/cloud/interfaces/IDevicesService.js +0 -2
  89. package/dist/device/cloud/interfaces/IHubService.d.ts +0 -5
  90. package/dist/device/cloud/interfaces/IHubService.js +0 -2
  91. package/dist/device/cloud/interfaces/IRawDataTransformer.d.ts +0 -4
  92. package/dist/device/cloud/interfaces/IRawDataTransformer.js +0 -2
  93. package/dist/device/cloud/interfaces/IRawDevice.d.ts +0 -17
  94. package/dist/device/cloud/interfaces/IRawDevice.js +0 -11
  95. package/dist/device/cloud/interfaces/index.d.ts +0 -5
  96. package/dist/device/cloud/interfaces/index.js +0 -21
  97. package/dist/device/cloud/services/CloudDevice.service.d.ts +0 -5
  98. package/dist/device/cloud/services/CloudDevice.service.js +0 -9
  99. package/dist/device/cloud/services/Connection.service.d.ts +0 -8
  100. package/dist/device/cloud/services/Connection.service.js +0 -6
  101. package/dist/device/cloud/services/Device.service.d.ts +0 -39
  102. package/dist/device/cloud/services/Device.service.js +0 -9
  103. package/dist/device/cloud/services/DeviceCloudService.d.ts +0 -42
  104. package/dist/device/cloud/services/DeviceCloudService.js +0 -59
  105. package/dist/device/cloud/services/DeviceHub.service.d.ts +0 -3
  106. package/dist/device/cloud/services/DeviceHub.service.js +0 -6
  107. package/dist/device/cloud/services/Hub.service.d.ts +0 -25
  108. package/dist/device/cloud/services/Hub.service.js +0 -9
  109. package/dist/device/cloud/services/SmartThingsDeviceService.d.ts +0 -38
  110. package/dist/device/cloud/services/SmartThingsDeviceService.js +0 -52
  111. package/dist/device/cloud/services/index.d.ts +0 -2
  112. package/dist/device/cloud/services/index.js +0 -18
  113. package/dist/device/cloud/types.d.ts +0 -52
  114. package/dist/device/cloud/types.js +0 -15
  115. package/dist/device/index.d.ts +0 -4
  116. package/dist/device/index.js +0 -20
  117. package/dist/device/local/entities/AlertBuilder.d.ts +0 -87
  118. package/dist/device/local/entities/AlertBuilder.example.d.ts +0 -11
  119. package/dist/device/local/entities/AlertBuilder.example.js +0 -117
  120. package/dist/device/local/entities/AlertBuilder.js +0 -179
  121. package/dist/device/local/entities/IssueBuilder.d.ts +0 -109
  122. package/dist/device/local/entities/IssueBuilder.example.d.ts +0 -16
  123. package/dist/device/local/entities/IssueBuilder.example.js +0 -196
  124. package/dist/device/local/entities/IssueBuilder.js +0 -237
  125. package/dist/device/local/entities/index.d.ts +0 -2
  126. package/dist/device/local/entities/index.js +0 -7
  127. package/dist/device/local/events/EventHandler.d.ts +0 -11
  128. package/dist/device/local/events/EventHandler.js +0 -86
  129. package/dist/device/local/events/Events.d.ts +0 -54
  130. package/dist/device/local/events/Events.js +0 -57
  131. package/dist/device/local/events/index.d.ts +0 -2
  132. package/dist/device/local/events/index.js +0 -7
  133. package/dist/device/local/handler/EventHandler.d.ts +0 -7
  134. package/dist/device/local/handler/EventHandler.js +0 -44
  135. package/dist/device/local/interface.d.ts +0 -0
  136. package/dist/device/local/interface.js +0 -1
  137. package/dist/device/local/interfaces/IConnection.d.ts +0 -26
  138. package/dist/device/local/interfaces/IConnection.js +0 -14
  139. package/dist/device/local/interfaces/IDevice.d.ts +0 -68
  140. package/dist/device/local/interfaces/IDevice.js +0 -10
  141. package/dist/device/local/interfaces/IDtDevice.d.ts +0 -16
  142. package/dist/device/local/interfaces/IDtDevice.js +0 -2
  143. package/dist/device/local/interfaces/IHub.d.ts +0 -46
  144. package/dist/device/local/interfaces/IHub.js +0 -2
  145. package/dist/device/local/interfaces/IProperty.d.ts +0 -29
  146. package/dist/device/local/interfaces/IProperty.js +0 -2
  147. package/dist/device/local/interfaces/ISchedule.d.ts +0 -25
  148. package/dist/device/local/interfaces/ISchedule.js +0 -2
  149. package/dist/device/local/interfaces/index.d.ts +0 -3
  150. package/dist/device/local/interfaces/index.js +0 -19
  151. package/dist/device/local/models/Alert.model.d.ts +0 -28
  152. package/dist/device/local/models/Alert.model.js +0 -222
  153. package/dist/device/local/models/Issue.model.d.ts +0 -28
  154. package/dist/device/local/models/Issue.model.js +0 -260
  155. package/dist/device/local/repository/Alert.repository.d.ts +0 -106
  156. package/dist/device/local/repository/Alert.repository.js +0 -374
  157. package/dist/device/local/repository/Connection.repository.d.ts +0 -8
  158. package/dist/device/local/repository/Connection.repository.js +0 -92
  159. package/dist/device/local/repository/Device.repository.d.ts +0 -30
  160. package/dist/device/local/repository/Device.repository.js +0 -325
  161. package/dist/device/local/repository/Hub.repository.d.ts +0 -13
  162. package/dist/device/local/repository/Hub.repository.js +0 -139
  163. package/dist/device/local/repository/Issue.repository.d.ts +0 -113
  164. package/dist/device/local/repository/Issue.repository.js +0 -401
  165. package/dist/device/local/repository/Property.repository.d.ts +0 -8
  166. package/dist/device/local/repository/Property.repository.js +0 -95
  167. package/dist/device/local/repository/Schedule.repository.d.ts +0 -9
  168. package/dist/device/local/repository/Schedule.repository.js +0 -109
  169. package/dist/device/local/services/Alert.service.d.ts +0 -137
  170. package/dist/device/local/services/Alert.service.js +0 -475
  171. package/dist/device/local/services/AlertService.example.d.ts +0 -55
  172. package/dist/device/local/services/AlertService.example.js +0 -148
  173. package/dist/device/local/services/Connection.service.d.ts +0 -8
  174. package/dist/device/local/services/Connection.service.js +0 -32
  175. package/dist/device/local/services/Device.service.d.ts +0 -40
  176. package/dist/device/local/services/Device.service.js +0 -391
  177. package/dist/device/local/services/DeviceHub.service.d.ts +0 -11
  178. package/dist/device/local/services/DeviceHub.service.js +0 -40
  179. package/dist/device/local/services/Hub.service.d.ts +0 -12
  180. package/dist/device/local/services/Hub.service.js +0 -107
  181. package/dist/device/local/services/Issue.service.d.ts +0 -168
  182. package/dist/device/local/services/Issue.service.js +0 -642
  183. package/dist/device/local/services/IssueService.example.d.ts +0 -68
  184. package/dist/device/local/services/IssueService.example.js +0 -177
  185. package/dist/device/local/services/Property.service.d.ts +0 -8
  186. package/dist/device/local/services/Property.service.js +0 -36
  187. package/dist/device/local/services/Schedule.service.d.ts +0 -9
  188. package/dist/device/local/services/Schedule.service.js +0 -26
  189. package/dist/device/local/services/index.d.ts +0 -3
  190. package/dist/device/local/services/index.js +0 -19
  191. package/dist/pms/IPms.d.ts +0 -6
  192. package/dist/pms/IPms.js +0 -10
  193. package/dist/pms/index.d.ts +0 -1
  194. package/dist/pms/index.js +0 -18
  195. package/dist/pms/webhookQueue/examples/index.d.ts +0 -2
  196. package/dist/pms/webhookQueue/examples/index.js +0 -18
  197. package/dist/pms/webhookQueue/examples/pms-integration.d.ts +0 -65
  198. package/dist/pms/webhookQueue/examples/pms-integration.js +0 -254
  199. package/dist/pms/webhookQueue/examples/usage.d.ts +0 -7
  200. package/dist/pms/webhookQueue/examples/usage.js +0 -175
  201. package/dist/pms/webhookQueue/index.d.ts +0 -3
  202. package/dist/pms/webhookQueue/index.js +0 -20
  203. package/dist/pms/webhookQueue/interfaces/IWebhookQueue.d.ts +0 -33
  204. package/dist/pms/webhookQueue/interfaces/IWebhookQueue.js +0 -2
  205. package/dist/pms/webhookQueue/interfaces/IWebhookWorker.d.ts +0 -38
  206. package/dist/pms/webhookQueue/interfaces/IWebhookWorker.js +0 -2
  207. package/dist/pms/webhookQueue/interfaces/index.d.ts +0 -1
  208. package/dist/pms/webhookQueue/interfaces/index.js +0 -17
  209. package/dist/pms/webhookQueue/services/WebhookQueueFactory.d.ts +0 -38
  210. package/dist/pms/webhookQueue/services/WebhookQueueFactory.js +0 -131
  211. package/dist/pms/webhookQueue/services/WebhookQueueIntegration.d.ts +0 -70
  212. package/dist/pms/webhookQueue/services/WebhookQueueIntegration.js +0 -207
  213. package/dist/pms/webhookQueue/services/WebhookQueueService.d.ts +0 -45
  214. package/dist/pms/webhookQueue/services/WebhookQueueService.js +0 -270
  215. package/dist/pms/webhookQueue/services/WebhookWorker.d.ts +0 -37
  216. package/dist/pms/webhookQueue/services/WebhookWorker.js +0 -201
  217. package/dist/pms/webhookQueue/services/index.d.ts +0 -1
  218. package/dist/pms/webhookQueue/services/index.js +0 -17
  219. package/dist/pms/webhookQueue/types/index.d.ts +0 -1
  220. package/dist/pms/webhookQueue/types/index.js +0 -17
  221. package/dist/pms/webhookQueue/types/webhook.types.d.ts +0 -39
  222. package/dist/pms/webhookQueue/types/webhook.types.js +0 -2
  223. package/dist/property/IProperty.d.ts +0 -29
  224. package/dist/property/IProperty.js +0 -2
  225. package/dist/property/Property.repository.d.ts +0 -8
  226. package/dist/property/Property.repository.js +0 -109
  227. package/dist/property/Property.service.d.ts +0 -8
  228. package/dist/property/Property.service.js +0 -124
  229. package/dist/property/index.d.ts +0 -2
  230. package/dist/property/index.js +0 -18
  231. package/dist/queue/interfaces/IHttpRequestJob.d.ts +0 -9
  232. package/dist/queue/interfaces/IHttpRequestJob.js +0 -2
  233. package/dist/types/alert.types.d.ts +0 -57
  234. package/dist/types/alert.types.js +0 -22
  235. package/dist/types/config.types.d.ts +0 -19
  236. package/dist/types/config.types.js +0 -2
  237. package/dist/types/index.d.ts +0 -3
  238. package/dist/types/index.js +0 -19
  239. package/dist/types/issue.types.d.ts +0 -90
  240. package/dist/types/issue.types.js +0 -40
  241. package/dist/utils/http-utils.d.ts +0 -13
  242. package/dist/utils/http-utils.js +0 -117
@@ -1,148 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AlertServiceExample = void 0;
4
- const AlertBuilder_1 = require("../entities/AlertBuilder");
5
- const alert_types_1 = require("../../../types/alert.types");
6
- /**
7
- * Example usage of the updated AlertService with AlertBuilder integration
8
- * This file demonstrates various ways to use the AlertService with the new AlertBuilder
9
- */
10
- class AlertServiceExample {
11
- constructor(alertService) {
12
- this.alertService = alertService;
13
- }
14
- /**
15
- * Example 1: Using the updated createAlert method with AlertBuilder
16
- */
17
- async createAlertWithBuilder() {
18
- const alertBuilder = 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
- // Pass the AlertBuilder directly to createAlert
28
- const alert = await this.alertService.createAlert(alertBuilder);
29
- return alert;
30
- }
31
- /**
32
- * Example 2: Using convenience methods for specific alert types
33
- */
34
- async createSpecificAlerts() {
35
- // Create a readiness alert
36
- const readinessAlert = await this.alertService.raiseReadinessAlert("prop123", "System Maintenance Required", "System maintenance is scheduled for tonight", "system456", alert_types_1.EntityType.PROPERTY, "admin");
37
- // Create an operations alert
38
- const operationsAlert = await this.alertService.raiseOperationsAlert("prop123", "Device Temperature High", "Device temperature exceeds normal operating range", "device789", alert_types_1.EntityType.DEVICE, "monitor");
39
- // Create a security alert
40
- const securityAlert = await this.alertService.raiseSecurityAlert("prop123", "Unauthorized Access Attempt", "Multiple failed login attempts detected", "user123", alert_types_1.EntityType.USER, "security-system");
41
- // Create an energy alert
42
- 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");
43
- return { readinessAlert, operationsAlert, securityAlert, energyAlert };
44
- }
45
- /**
46
- * Example 3: Using device-specific alert methods
47
- */
48
- async createDeviceAlerts() {
49
- // Create a device alert with default category and severity
50
- const deviceAlert1 = await this.alertService.raiseDeviceAlert("device123", "prop456", "Device Battery Low", "Device battery level is below 20%", undefined, // Use default category
51
- undefined, // Use default severity
52
- "system");
53
- // Create a device alert with custom category and severity
54
- 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, "firmware-manager");
55
- return { deviceAlert1, deviceAlert2 };
56
- }
57
- /**
58
- * Example 4: Using hub-specific alert methods
59
- */
60
- async createHubAlerts() {
61
- // Create a hub alert with default settings
62
- const hubAlert1 = await this.alertService.raiseHubAlert("hub123", "prop456", "Hub Connection Lost", "Hub has lost connection to the network", undefined, // Use default category
63
- undefined, // Use default severity
64
- "network-monitor");
65
- // Create a hub alert with custom settings
66
- 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");
67
- return { hubAlert1, hubAlert2 };
68
- }
69
- /**
70
- * Example 5: Using static factory methods with AlertBuilder
71
- */
72
- async createAlertsWithStaticMethods() {
73
- // Create a device alert using static factory method
74
- const deviceAlert = AlertBuilder_1.AlertBuilder.createDeviceAlert("device123", "prop456")
75
- .setCategory(alert_types_1.AlertCategory.OPERATIONS)
76
- .setTitle("Device Offline")
77
- .setDescription("Device has been offline for more than 5 minutes")
78
- .setSeverity(alert_types_1.AlertSeverity.HIGH)
79
- .setCreatedBy("monitor");
80
- const alert1 = await this.alertService.createAlert(deviceAlert);
81
- // Create a hub alert using static factory method
82
- const hubAlert = AlertBuilder_1.AlertBuilder.createHubAlert("hub789", "prop202")
83
- .setCategory(alert_types_1.AlertCategory.SECURITY)
84
- .setTitle("Hub Security Breach")
85
- .setDescription("Unauthorized access attempt detected on hub")
86
- .setSeverity(alert_types_1.AlertSeverity.CRITICAL)
87
- .setCreatedBy("security-system");
88
- const alert2 = await this.alertService.createAlert(hubAlert);
89
- return { alert1, alert2 };
90
- }
91
- /**
92
- * Example 6: Creating multiple alerts efficiently
93
- */
94
- async createMultipleAlerts() {
95
- const alerts = [];
96
- // Create multiple device alerts efficiently
97
- const deviceIds = ["device1", "device2", "device3"];
98
- const propertyId = "prop123";
99
- for (const deviceId of deviceIds) {
100
- const alertBuilder = AlertBuilder_1.AlertBuilder.createDeviceAlert(deviceId, propertyId)
101
- .setCategory(alert_types_1.AlertCategory.OPERATIONS)
102
- .setTitle(`Device ${deviceId} Status`)
103
- .setDescription(`Status check for device ${deviceId}`)
104
- .setSeverity(alert_types_1.AlertSeverity.MEDIUM)
105
- .setCreatedBy("batch-processor");
106
- const alert = await this.alertService.createAlert(alertBuilder);
107
- alerts.push(alert);
108
- }
109
- return alerts;
110
- }
111
- /**
112
- * Example 7: Creating alerts with snooze functionality
113
- */
114
- async createSnoozedAlert() {
115
- const snoozeUntil = new Date();
116
- snoozeUntil.setHours(snoozeUntil.getHours() + 2); // Snooze for 2 hours
117
- const alertBuilder = new AlertBuilder_1.AlertBuilder()
118
- .setCategory(alert_types_1.AlertCategory.OTHER)
119
- .setPropertyId("prop303")
120
- .setTitle("Scheduled Maintenance")
121
- .setDescription("System maintenance scheduled for tonight")
122
- .setEntityType(alert_types_1.EntityType.PROPERTY)
123
- .setSeverity(alert_types_1.AlertSeverity.INFO)
124
- .setCreatedBy("admin")
125
- .setSnoozeUntil(snoozeUntil);
126
- const alert = await this.alertService.createAlert(alertBuilder);
127
- return alert;
128
- }
129
- /**
130
- * Example 8: Backward compatibility - still works with CreateAlertData
131
- */
132
- async createAlertWithLegacyData() {
133
- const alertData = {
134
- category: alert_types_1.AlertCategory.OPERATIONS,
135
- propertyId: "prop123",
136
- title: "Legacy Alert",
137
- description: "This alert was created using the old CreateAlertData format",
138
- entityId: "device456",
139
- entityType: alert_types_1.EntityType.DEVICE,
140
- severity: alert_types_1.AlertSeverity.MEDIUM,
141
- createdBy: "legacy-system"
142
- };
143
- // This still works with the updated createAlert method
144
- const alert = await this.alertService.createAlert(alertData);
145
- return alert;
146
- }
147
- }
148
- exports.AlertServiceExample = AlertServiceExample;
@@ -1,8 +0,0 @@
1
- import { IConnection } from "../interfaces/IConnection";
2
- export declare class LocalConnectionService {
3
- private readonly connectionRepository;
4
- constructor();
5
- createConnection(data: Partial<IConnection>): Promise<IConnection>;
6
- getConnection(connectionId: string): Promise<IConnection>;
7
- updateConnection(connectionId: string, data: Partial<IConnection>): Promise<IConnection>;
8
- }
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LocalConnectionService = void 0;
4
- const typedi_1 = require("typedi");
5
- const Connection_repository_1 = require("../repository/Connection.repository");
6
- class LocalConnectionService {
7
- constructor() {
8
- this.connectionRepository = typedi_1.Container.get(Connection_repository_1.ConnectionRepository);
9
- }
10
- async createConnection(data) {
11
- if (!data.connectionName ||
12
- !data.connectionRefId ||
13
- !data.propertyId ||
14
- !data.connectionProvider) {
15
- throw new Error("Missing required fields");
16
- }
17
- return await this.connectionRepository.createConnection(data);
18
- }
19
- async getConnection(connectionId) {
20
- if (!connectionId) {
21
- throw new Error("Connection ID is required");
22
- }
23
- return await this.connectionRepository.getConnectionById(connectionId);
24
- }
25
- async updateConnection(connectionId, data) {
26
- if (!connectionId) {
27
- throw new Error("Connection ID is required");
28
- }
29
- return await this.connectionRepository.updateConnection(connectionId, data);
30
- }
31
- }
32
- exports.LocalConnectionService = LocalConnectionService;
@@ -1,40 +0,0 @@
1
- import { IDevice, IStatus, IStatusQuery } from "../interfaces";
2
- import { Source } from "../../../constants/Service";
3
- import { AuditProperties } from "../../../audit/AuditProperties";
4
- export declare class LocalDeviceService {
5
- private readonly eventHandler;
6
- private readonly deviceRepository;
7
- private readonly alertService;
8
- private readonly issueService;
9
- private readonly logger;
10
- constructor();
11
- createDevice(body: IDevice): Promise<IDevice>;
12
- getDevice(deviceId: string, withHubDetails?: boolean): Promise<IDevice>;
13
- getDevices(deviceIds: string[], withHubDetails?: boolean): Promise<IDevice[]>;
14
- getPropertyDevices(propertyId: string, selectDeviceId?: boolean, type?: string, withHubDetails?: boolean): Promise<IDevice[]>;
15
- getPropertyDeviceIds(propertyId: string, selectDeviceId: boolean | undefined, type: string): Promise<any>;
16
- updateDevice(deviceId: string, body: any, auditBody: AuditProperties): Promise<any>;
17
- updateDevices(query: any, updateData: any): Promise<any>;
18
- deleteDevice(deviceId: string, auditBody: AuditProperties): Promise<any>;
19
- getState(deviceId: string): Promise<any>;
20
- setState(deviceId: string, newState: any, auditProperties: AuditProperties): Promise<void>;
21
- getStatus(deviceId: string): Promise<Record<string, any>>;
22
- setStatus(deviceId: string, newStatus: IStatus, source: Source, auditBody: AuditProperties, reason?: string): Promise<void>;
23
- setStatusMany(query: IStatusQuery, newStatus: IStatus, source: Source, auditBody: AuditProperties): Promise<void>;
24
- private handleOfflineStatus;
25
- private handleOnlineStatus;
26
- private getDeviceBaseline;
27
- getBatteryLevel(deviceId: string): Promise<Record<string, any>>;
28
- setBatteryLevel(deviceId: string, batteryLevel: number, source: Source, auditBody: AuditProperties): Promise<void>;
29
- private shouldUpdateBatteryLevel;
30
- private getPropertyBatteryThreshold;
31
- private checkForDeviceMalfunctions;
32
- getMetaData(deviceId: string): Promise<any>;
33
- setMetaData(deviceId: string, metaData: Record<string, any>, auditBody: AuditProperties): Promise<any>;
34
- getDevicesByZone(zoneId: string): Promise<import("../interfaces").IDtDevice[]>;
35
- getDevicesByAccessGroup(accessGroupId: string): Promise<import("../interfaces").IDtDevice[]>;
36
- querySelect(query: any, fields: string[]): Promise<any>;
37
- queryCount(query: any): Promise<number>;
38
- deleteDevices(query: any): Promise<any>;
39
- queryDevices(query: any): Promise<any>;
40
- }
@@ -1,391 +0,0 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
41
- return (mod && mod.__esModule) ? mod : { "default": mod };
42
- };
43
- Object.defineProperty(exports, "__esModule", { value: true });
44
- exports.LocalDeviceService = void 0;
45
- const EventHandler_1 = require("../../../events/EventHandler");
46
- const lodash_1 = require("lodash");
47
- const Device_repository_1 = require("../repository/Device.repository");
48
- const typedi_1 = __importDefault(require("typedi"));
49
- const Alert_service_1 = require("../../../alerts/Alert.service");
50
- const Issue_service_1 = require("../../../issues/Issue.service");
51
- const config_1 = require("../../../config/config");
52
- const typedi_2 = require("typedi");
53
- let LocalDeviceService = (() => {
54
- let _classDecorators = [(0, typedi_2.Service)()];
55
- let _classDescriptor;
56
- let _classExtraInitializers = [];
57
- let _classThis;
58
- var LocalDeviceService = _classThis = class {
59
- constructor() {
60
- // Use dependency injection instead of creating new instances
61
- this.eventHandler = typedi_1.default.get(EventHandler_1.EventHandler);
62
- this.deviceRepository = typedi_1.default.get(Device_repository_1.DeviceRepository);
63
- this.alertService = typedi_1.default.get(Alert_service_1.AlertService);
64
- this.issueService = typedi_1.default.get(Issue_service_1.IssueService);
65
- this.logger = (0, config_1.getConfig)().LOGGER;
66
- }
67
- async createDevice(body) {
68
- const device = await this.deviceRepository.createDevice(body);
69
- await this.eventHandler.onDeviceCreate(device);
70
- return device;
71
- }
72
- async getDevice(deviceId, withHubDetails = false) {
73
- if (!deviceId) {
74
- throw new Error("Device ID is required");
75
- }
76
- return await this.deviceRepository.getDevice(deviceId, withHubDetails);
77
- }
78
- async getDevices(deviceIds, withHubDetails = false) {
79
- if (!deviceIds.length) {
80
- throw new Error("At least one device ID is required");
81
- }
82
- return await this.deviceRepository.getDevices(deviceIds, withHubDetails);
83
- }
84
- async getPropertyDevices(propertyId, selectDeviceId = false, type, withHubDetails = false) {
85
- if (!propertyId) {
86
- throw new Error("Property ID is required");
87
- }
88
- return await this.deviceRepository.getPropertyDevices(propertyId, selectDeviceId, type, withHubDetails);
89
- }
90
- async getPropertyDeviceIds(propertyId, selectDeviceId = false, type) {
91
- if (!propertyId) {
92
- throw new Error("Property ID is required");
93
- }
94
- return await this.deviceRepository.getPropertyDeviceIds(propertyId, selectDeviceId, type);
95
- }
96
- async updateDevice(deviceId, body, auditBody) {
97
- if (!deviceId) {
98
- throw new Error("Device ID is required");
99
- }
100
- await this.deviceRepository.updateDevice(deviceId, body);
101
- return await this.eventHandler.onDeviceUpdate(deviceId, body, auditBody);
102
- }
103
- async updateDevices(query, updateData) {
104
- if (!query || !updateData) {
105
- throw new Error("Query and update data are required");
106
- }
107
- return await this.deviceRepository.updateDevices(query, updateData);
108
- }
109
- async deleteDevice(deviceId, auditBody) {
110
- if (!deviceId) {
111
- throw new Error("Device ID is required");
112
- }
113
- await this.deviceRepository.deleteDevice(deviceId);
114
- return await this.eventHandler.onDeviceDelete(deviceId, auditBody);
115
- }
116
- async getState(deviceId) {
117
- if (!deviceId) {
118
- throw new Error("Device ID is required");
119
- }
120
- return await this.deviceRepository.getState(deviceId);
121
- }
122
- async setState(deviceId, newState, auditProperties) {
123
- if (!deviceId || !newState) {
124
- throw new Error("Device ID and new state are required");
125
- }
126
- // If old state and new state are different
127
- const oldState = (await this.getState(deviceId))?.state ?? {};
128
- const changedKeys = Object.keys(newState).filter((key) => !(0, lodash_1.isEqual)(oldState[key], newState[key]));
129
- if (changedKeys.length > 0) {
130
- await this.deviceRepository.setState(deviceId, newState);
131
- return await this.eventHandler.onStateChange(deviceId, newState, auditProperties);
132
- }
133
- }
134
- async getStatus(deviceId) {
135
- if (!deviceId) {
136
- throw new Error("Device ID is required");
137
- }
138
- return await this.deviceRepository.getStatus(deviceId);
139
- }
140
- async setStatus(deviceId, newStatus, source, auditBody, reason) {
141
- if (!deviceId || !newStatus) {
142
- throw new Error("Device ID and new status are required");
143
- }
144
- const device = await this.getDevice(deviceId);
145
- const oldStatus = device.status;
146
- const currentTime = new Date().toISOString();
147
- // Determine if the new status is ONLINE or OFFLINE
148
- const isNewStatusOnline = newStatus.liveStatus === "ONLINE";
149
- const isNewStatusOffline = newStatus.liveStatus === "OFFLINE";
150
- if (isNewStatusOffline) {
151
- // New Status = OFFLINE
152
- await this.handleOfflineStatus(device, oldStatus, newStatus, source, auditBody, reason, currentTime);
153
- }
154
- else if (isNewStatusOnline) {
155
- // New Status = ONLINE
156
- await this.handleOnlineStatus(device, oldStatus, newStatus, source, auditBody, reason, currentTime);
157
- }
158
- else {
159
- // For any other status, just update normally
160
- await this.deviceRepository.setStatus(deviceId, newStatus);
161
- await this.eventHandler.onStatusChange(deviceId, newStatus, auditBody);
162
- }
163
- }
164
- async setStatusMany(query, newStatus, source, auditBody) {
165
- if (!query || !newStatus) {
166
- throw new Error("Query and new status are required");
167
- }
168
- newStatus.lastUpdated = new Date().toISOString();
169
- await this.deviceRepository.setStatusMany(query, newStatus);
170
- await this.eventHandler.onStatusChangeMany(query, newStatus, auditBody);
171
- }
172
- async handleOfflineStatus(device, oldStatus, newStatus, source, auditBody, reason, currentTime) {
173
- const isExistingStatusOnline = oldStatus?.online === true;
174
- const isExistingStatusOffline = oldStatus?.online === false;
175
- if (isExistingStatusOnline) {
176
- // Existing status is Online
177
- newStatus.online = true;
178
- newStatus.liveStatus = "OFFLINE";
179
- newStatus.lastUpdated = currentTime;
180
- newStatus.error = {
181
- type: "offline",
182
- message: reason || "Device went offline",
183
- default: {},
184
- };
185
- await this.deviceRepository.setStatus(device.deviceId, newStatus);
186
- await this.eventHandler.onStatusChange(device.deviceId, newStatus, auditBody);
187
- }
188
- else if (isExistingStatusOffline) {
189
- // Existing status is Offline
190
- const timeLapsed = oldStatus?.lastUpdated
191
- ? Date.now() - new Date(oldStatus.lastUpdated).getTime()
192
- : 0;
193
- const baselineTime = await this.getDeviceBaseline(device.deviceId);
194
- if (timeLapsed > baselineTime) {
195
- // When the time lapsed is higher than the baseline time
196
- newStatus.online = false;
197
- newStatus.liveStatus = "OFFLINE";
198
- newStatus.lastUpdated = currentTime;
199
- newStatus.error = {
200
- type: "offline",
201
- message: reason || "Device has been offline for longer than baseline",
202
- default: {},
203
- };
204
- await this.deviceRepository.setStatus(device.deviceId, newStatus);
205
- await this.eventHandler.onStatusChange(device.deviceId, newStatus, auditBody);
206
- // Raise alert (OPERATIONAL only)
207
- await this.alertService.raiseDeviceOfflineAlert(device, source, reason);
208
- // Raise issue when the device goes offline if longer than the baseline (OPERATIONAL only)
209
- await this.issueService.createDeviceOfflineIssue(device, source, reason);
210
- }
211
- }
212
- }
213
- async handleOnlineStatus(device, oldStatus, newStatus, source, auditBody, reason, currentTime) {
214
- const isExistingStatusOnline = oldStatus?.online === true;
215
- const isExistingStatusOffline = oldStatus?.online === false;
216
- if (isExistingStatusOnline) {
217
- // Existing status is Online
218
- if (oldStatus?.liveStatus === "ONLINE") {
219
- // liveStatus = Online → Do nothing
220
- return;
221
- }
222
- else if (oldStatus?.liveStatus === "OFFLINE") {
223
- // liveStatus = Offline → Follow the step #2 (same as existing status is Offline)
224
- newStatus.online = true;
225
- newStatus.liveStatus = "ONLINE";
226
- newStatus.lastUpdated = currentTime;
227
- newStatus.error = {}; // Clear the error
228
- await this.deviceRepository.setStatus(device.deviceId, newStatus);
229
- await this.eventHandler.onStatusChange(device.deviceId, newStatus, auditBody);
230
- //TODO: ALERT NEEDED?
231
- // Raise alert
232
- await this.alertService.raiseDeviceOnlineAlert(device, source, reason);
233
- }
234
- }
235
- else if (isExistingStatusOffline) {
236
- // Existing status is Offline
237
- newStatus.online = true;
238
- newStatus.liveStatus = "ONLINE";
239
- newStatus.lastUpdated = currentTime;
240
- newStatus.error = undefined; // Clear the error
241
- await this.deviceRepository.setStatus(device.deviceId, newStatus);
242
- await this.eventHandler.onStatusChange(device.deviceId, newStatus, auditBody);
243
- //TODO: ALERT NEEDED?
244
- // Raise alert
245
- await this.alertService.raiseDeviceOnlineAlert(device, source, reason);
246
- }
247
- }
248
- async getDeviceBaseline(deviceId) {
249
- // TODO: Implement device baseline retrieval
250
- // This should return the baseline time in milliseconds for the specific device
251
- // For now, returning a default value of 5 minutes (300000ms)
252
- // In a real implementation, this would fetch from device configuration or settings
253
- return 3600000; // 1 hour in milliseconds
254
- }
255
- async getBatteryLevel(deviceId) {
256
- if (!deviceId) {
257
- throw new Error("Device ID is required");
258
- }
259
- return await this.deviceRepository.getBatteryLevel(deviceId);
260
- }
261
- async setBatteryLevel(deviceId, batteryLevel, source, auditBody) {
262
- if (!deviceId || batteryLevel === undefined || batteryLevel === null) {
263
- throw new Error("Device ID and battery level are required");
264
- }
265
- // Get device information
266
- const device = await this.getDevice(deviceId);
267
- // Fetch the old battery level state
268
- const oldBatteryLevel = device.state?.batteryPercentage;
269
- // Check if battery level has changed
270
- const isDifferent = !(0, lodash_1.isEqual)(oldBatteryLevel?.value, batteryLevel);
271
- if (isDifferent) {
272
- // Check if current time is greater than or equal to last updated time (8-hour logic)
273
- const shouldUpdate = this.shouldUpdateBatteryLevel(oldBatteryLevel?.lastUpdated);
274
- if (shouldUpdate) {
275
- // Save the battery level in the device
276
- await this.deviceRepository.setBatteryLevel(deviceId, batteryLevel);
277
- await this.eventHandler.onBatteryLevelChange(deviceId, batteryLevel, auditBody);
278
- // Get property threshold
279
- const propertyThreshold = await this.getPropertyBatteryThreshold(device.propertyId);
280
- // Check if battery level is below threshold
281
- if (batteryLevel < propertyThreshold) {
282
- // Raise alert
283
- await this.alertService.raiseDeviceBatteryAlert(device, batteryLevel, propertyThreshold, source);
284
- // Raise issue when the level is below threshold
285
- await this.issueService.createDeviceBatteryIssue(device, batteryLevel, propertyThreshold, source);
286
- }
287
- }
288
- }
289
- }
290
- shouldUpdateBatteryLevel(lastUpdated) {
291
- if (!lastUpdated) {
292
- return true; // No previous update, so we should update
293
- }
294
- const lastUpdateTime = new Date(lastUpdated).getTime();
295
- const currentTime = Date.now();
296
- const eightHoursInMs = 8 * 60 * 60 * 1000; // 8 hours in milliseconds
297
- // Return true if current time is greater than or equal to last updated time + 8 hours
298
- return currentTime >= lastUpdateTime + eightHoursInMs;
299
- }
300
- async getPropertyBatteryThreshold(propertyId) {
301
- // TODO: Implement property battery threshold retrieval
302
- // This should return the battery threshold for the specific property
303
- // For now, returning a default value of 20%
304
- // In a real implementation, this would fetch from property configuration or settings
305
- return 20; // 20% default threshold
306
- }
307
- async checkForDeviceMalfunctions(device, source, reason) {
308
- // TODO: Implement device malfunction detection logic
309
- // This should check for:
310
- // - Lock jammed
311
- // - Device not accepting codes
312
- // - Other malfunction indicators
313
- // For now, we'll check if the reason indicates a malfunction
314
- const malfunctionIndicators = [
315
- "jammed",
316
- "not accepting codes",
317
- "malfunction",
318
- "error",
319
- "failure",
320
- ];
321
- const hasMalfunction = malfunctionIndicators.some((indicator) => reason?.toLowerCase().includes(indicator));
322
- if (hasMalfunction) {
323
- // Raise alert for device malfunction (READINESS + OPERATIONAL)
324
- await this.alertService.raiseDeviceIssueAlert(device, "Device Malfunction Detected", source, reason);
325
- // Raise issue for device malfunction (READINESS + OPERATIONAL)
326
- await this.issueService.createDeviceMalfunctionIssue(device, "Device Malfunction", source, reason);
327
- }
328
- }
329
- async getMetaData(deviceId) {
330
- if (!deviceId) {
331
- throw new Error("Device ID is required");
332
- }
333
- return await this.deviceRepository.getMetaData(deviceId);
334
- }
335
- async setMetaData(deviceId, metaData, auditBody) {
336
- if (!deviceId || !metaData) {
337
- throw new Error("Device ID and meta data are required");
338
- }
339
- await this.eventHandler.onDeviceMetaChange(deviceId, metaData, auditBody);
340
- return await this.deviceRepository.setMetaData(deviceId, metaData);
341
- }
342
- async getDevicesByZone(zoneId) {
343
- if (!zoneId) {
344
- throw new Error("Zone ID is required");
345
- }
346
- return await this.deviceRepository.getDevicesByZone(zoneId);
347
- }
348
- async getDevicesByAccessGroup(accessGroupId) {
349
- if (!accessGroupId) {
350
- throw new Error("Access Group ID is required");
351
- }
352
- return await this.deviceRepository.getDevicesByAccessGroup(accessGroupId);
353
- }
354
- async querySelect(query, fields) {
355
- if (!query || Object.keys(query).length === 0) {
356
- throw new Error("Query is required");
357
- }
358
- return await this.deviceRepository.querySelect(query, fields);
359
- }
360
- async queryCount(query) {
361
- if (!query || Object.keys(query).length === 0) {
362
- throw new Error("Query is required");
363
- }
364
- const count = await this.deviceRepository.queryCount(query);
365
- return count;
366
- }
367
- async deleteDevices(query) {
368
- if (!query || Object.keys(query).length === 0) {
369
- throw new Error("Query is required");
370
- }
371
- return await this.deviceRepository.deleteDevices(query);
372
- }
373
- async queryDevices(query) {
374
- if (!query || Object.keys(query).length === 0) {
375
- throw new Error("Query is required");
376
- }
377
- const res = await this.deviceRepository.queryDevices(query);
378
- return res;
379
- }
380
- };
381
- __setFunctionName(_classThis, "LocalDeviceService");
382
- (() => {
383
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
384
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
385
- LocalDeviceService = _classThis = _classDescriptor.value;
386
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
387
- __runInitializers(_classThis, _classExtraInitializers);
388
- })();
389
- return LocalDeviceService = _classThis;
390
- })();
391
- exports.LocalDeviceService = LocalDeviceService;
@@ -1,11 +0,0 @@
1
- import { IHubCreateParams } from "../interfaces";
2
- export declare class DeviceHubService {
3
- private readonly baseUrl;
4
- constructor();
5
- addHub(body: IHubCreateParams): Promise<any>;
6
- getHubs(hubIds: string[]): Promise<any>;
7
- getHub(hubId: string): Promise<any>;
8
- updateHub(hubId: string, body: any): Promise<any>;
9
- deleteHub(hubId: string): Promise<any>;
10
- deleteAllHubs(hubIds: string[]): Promise<any>;
11
- }