dt-common-device 2.0.6 → 3.0.0

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 (187) hide show
  1. package/README.md +321 -99
  2. package/dist/alerts/Alert.model.d.ts +28 -0
  3. package/dist/alerts/Alert.model.js +222 -0
  4. package/dist/alerts/Alert.repository.d.ts +106 -0
  5. package/dist/alerts/Alert.repository.js +374 -0
  6. package/dist/alerts/Alert.service.d.ts +137 -0
  7. package/dist/alerts/Alert.service.js +476 -0
  8. package/dist/alerts/AlertBuilder.d.ts +87 -0
  9. package/dist/alerts/AlertBuilder.example.d.ts +11 -0
  10. package/dist/alerts/AlertBuilder.example.js +117 -0
  11. package/dist/alerts/AlertBuilder.js +185 -0
  12. package/dist/alerts/AlertService.example.d.ts +55 -0
  13. package/dist/alerts/AlertService.example.js +148 -0
  14. package/dist/alerts/alert.types.d.ts +57 -0
  15. package/dist/alerts/alert.types.js +22 -0
  16. package/dist/alerts/index.d.ts +3 -0
  17. package/dist/alerts/index.js +19 -0
  18. package/dist/config/config.d.ts +4 -4
  19. package/dist/config/config.js +3 -3
  20. package/dist/config/config.types.d.ts +19 -0
  21. package/dist/config/config.types.js +2 -0
  22. package/dist/connection/Connection.repository.d.ts +8 -0
  23. package/dist/connection/Connection.repository.js +92 -0
  24. package/dist/connection/Connection.service.d.ts +8 -0
  25. package/dist/connection/Connection.service.js +32 -0
  26. package/dist/connection/IConnection.d.ts +26 -0
  27. package/dist/connection/IConnection.js +14 -0
  28. package/dist/connection/index.d.ts +2 -0
  29. package/dist/connection/index.js +18 -0
  30. package/dist/device/cloud/entities/CloudDevice.d.ts +2 -2
  31. package/dist/device/cloud/entities/CloudDeviceService.d.ts +1 -1
  32. package/dist/device/cloud/entities/DeviceFactory.d.ts +1 -1
  33. package/dist/device/cloud/entities/DeviceFactory.js +1 -1
  34. package/dist/device/cloud/interfaces/ICloudDeviceService.d.ts +1 -1
  35. package/dist/device/cloud/interfaces/IRawDevice.d.ts +1 -1
  36. package/dist/device/local/interfaces/index.d.ts +2 -3
  37. package/dist/device/local/interfaces/index.js +2 -3
  38. package/dist/device/local/repository/Device.repository.d.ts +2 -0
  39. package/dist/device/local/repository/Device.repository.js +22 -3
  40. package/dist/device/local/repository/Hub.repository.js +4 -4
  41. package/dist/device/local/repository/Schedule.repository.js +2 -2
  42. package/dist/device/local/services/Device.service.d.ts +2 -2
  43. package/dist/device/local/services/Device.service.js +3 -1
  44. package/dist/device/local/services/index.d.ts +0 -4
  45. package/dist/device/local/services/index.js +0 -4
  46. package/dist/events/BaseEventHandler.d.ts +2 -2
  47. package/dist/events/BaseEventHandler.js +2 -2
  48. package/dist/events/BaseEventTransformer.d.ts +1 -1
  49. package/dist/events/BaseEventTransformer.js +1 -1
  50. package/dist/events/DeviceEventHandler.d.ts +1 -1
  51. package/dist/events/DeviceEventHandler.js +2 -2
  52. package/dist/events/EventHandler.js +1 -1
  53. package/dist/events/EventHandlerOrchestrator.js +1 -1
  54. package/dist/events/EventProcessingService.js +1 -1
  55. package/dist/events/InternalEventSubscription.js +1 -1
  56. package/dist/index.d.ts +7 -5
  57. package/dist/index.js +16 -13
  58. package/dist/issues/Issue.model.d.ts +28 -0
  59. package/dist/issues/Issue.model.js +260 -0
  60. package/dist/issues/Issue.repository.d.ts +113 -0
  61. package/dist/issues/Issue.repository.js +401 -0
  62. package/dist/issues/Issue.service.d.ts +168 -0
  63. package/dist/issues/Issue.service.js +642 -0
  64. package/dist/issues/IssueBuilder.d.ts +109 -0
  65. package/dist/issues/IssueBuilder.example.d.ts +16 -0
  66. package/dist/issues/IssueBuilder.example.js +196 -0
  67. package/dist/issues/IssueBuilder.js +237 -0
  68. package/dist/issues/IssueService.example.d.ts +68 -0
  69. package/dist/issues/IssueService.example.js +177 -0
  70. package/dist/issues/index.d.ts +2 -0
  71. package/dist/issues/index.js +18 -0
  72. package/dist/issues/issue.types.d.ts +90 -0
  73. package/dist/issues/issue.types.js +40 -0
  74. package/dist/property/IProperty.d.ts +29 -0
  75. package/dist/property/IProperty.js +2 -0
  76. package/dist/property/Property.repository.d.ts +8 -0
  77. package/dist/property/Property.repository.js +95 -0
  78. package/dist/property/Property.service.d.ts +8 -0
  79. package/dist/property/Property.service.js +36 -0
  80. package/dist/property/index.d.ts +2 -0
  81. package/dist/property/index.js +18 -0
  82. package/dist/queue/entities/HybridHttpQueue.d.ts +23 -0
  83. package/dist/queue/entities/HybridHttpQueue.js +189 -0
  84. package/dist/queue/entities/index.d.ts +1 -0
  85. package/dist/queue/entities/index.js +17 -0
  86. package/dist/queue/index.d.ts +5 -0
  87. package/dist/queue/index.js +22 -0
  88. package/dist/queue/interfaces/IHttpRequestJob.d.ts +9 -0
  89. package/dist/queue/interfaces/IHttpRequestJob.js +2 -0
  90. package/dist/queue/interfaces/IHybridHttpQueue.d.ts +16 -0
  91. package/dist/queue/interfaces/IHybridHttpQueue.js +2 -0
  92. package/dist/queue/interfaces/IJobResult.d.ts +6 -0
  93. package/dist/queue/interfaces/IJobResult.js +2 -0
  94. package/dist/queue/interfaces/IRateLimitConfig.d.ts +5 -0
  95. package/dist/queue/interfaces/IRateLimitConfig.js +2 -0
  96. package/dist/queue/interfaces/index.d.ts +4 -0
  97. package/dist/queue/interfaces/index.js +20 -0
  98. package/dist/queue/services/QueueService.d.ts +19 -0
  99. package/dist/queue/services/QueueService.js +73 -0
  100. package/dist/queue/services/index.d.ts +1 -0
  101. package/dist/queue/services/index.js +17 -0
  102. package/dist/queue/types/http.types.d.ts +21 -0
  103. package/dist/queue/types/http.types.js +2 -0
  104. package/dist/queue/types/index.d.ts +2 -0
  105. package/dist/queue/types/index.js +18 -0
  106. package/dist/queue/types/queue.types.d.ts +35 -0
  107. package/dist/queue/types/queue.types.js +2 -0
  108. package/dist/queue/utils/index.d.ts +3 -0
  109. package/dist/queue/utils/index.js +19 -0
  110. package/dist/queue/utils/jobUtils.d.ts +10 -0
  111. package/dist/queue/utils/jobUtils.js +64 -0
  112. package/dist/queue/utils/queueUtils.d.ts +5 -0
  113. package/dist/queue/utils/queueUtils.js +59 -0
  114. package/dist/queue/utils/rateLimit.utils.d.ts +6 -0
  115. package/dist/queue/utils/rateLimit.utils.js +44 -0
  116. package/package.json +2 -1
  117. package/src/{device/local/models → alerts}/Alert.model.ts +1 -1
  118. package/src/{device/local/repository → alerts}/Alert.repository.ts +2 -2
  119. package/src/{device/local/services → alerts}/Alert.service.ts +14 -7
  120. package/src/{device/local/entities → alerts}/AlertBuilder.example.ts +2 -2
  121. package/src/{device/local/entities → alerts}/AlertBuilder.ts +14 -8
  122. package/src/{device/local/services → alerts}/AlertService.example.ts +6 -5
  123. package/src/{types → alerts}/alert.types.ts +2 -2
  124. package/src/alerts/index.ts +3 -0
  125. package/src/config/config.ts +7 -7
  126. package/src/{types → config}/config.types.ts +1 -1
  127. package/src/{device/local/repository → connection}/Connection.repository.ts +2 -2
  128. package/src/{device/local/services → connection}/Connection.service.ts +2 -2
  129. package/src/connection/index.ts +3 -0
  130. package/src/device/cloud/entities/CloudDevice.ts +2 -2
  131. package/src/device/cloud/entities/CloudDeviceService.ts +1 -1
  132. package/src/device/cloud/entities/DeviceFactory.ts +2 -2
  133. package/src/device/cloud/interfaces/ICloudDeviceService.ts +1 -1
  134. package/src/device/cloud/interfaces/IRawDevice.ts +1 -1
  135. package/src/device/local/interfaces/index.ts +2 -3
  136. package/src/device/local/repository/Device.repository.ts +29 -3
  137. package/src/device/local/repository/Hub.repository.ts +4 -4
  138. package/src/device/local/repository/Schedule.repository.ts +2 -2
  139. package/src/device/local/services/Device.service.ts +5 -1
  140. package/src/device/local/services/index.ts +0 -4
  141. package/{TROUBLESHOOTING.md → src/docs/TROUBLESHOOTING.md} +2 -2
  142. package/src/events/BaseEventHandler.ts +3 -3
  143. package/src/events/BaseEventTransformer.ts +2 -2
  144. package/src/events/DeviceEventHandler.ts +3 -3
  145. package/src/events/EventHandler.ts +1 -1
  146. package/src/events/EventHandlerOrchestrator.ts +2 -2
  147. package/src/events/EventProcessingService.ts +2 -2
  148. package/src/events/InternalEventSubscription.ts +2 -2
  149. package/src/index.ts +19 -13
  150. package/src/{device/local/models → issues}/Issue.model.ts +1 -1
  151. package/src/{device/local/repository → issues}/Issue.repository.ts +2 -2
  152. package/src/{device/local/services → issues}/Issue.service.ts +4 -4
  153. package/src/{device/local/entities → issues}/IssueBuilder.example.ts +1 -1
  154. package/src/{device/local/entities → issues}/IssueBuilder.ts +1 -1
  155. package/src/{device/local/services → issues}/IssueService.example.ts +6 -5
  156. package/src/issues/index.ts +2 -0
  157. package/src/{device/local/repository → property}/Property.repository.ts +2 -2
  158. package/src/{device/local/services → property}/Property.service.ts +1 -1
  159. package/src/property/index.ts +2 -0
  160. package/src/queue/entities/HybridHttpQueue.ts +196 -0
  161. package/src/queue/entities/index.ts +1 -0
  162. package/src/queue/index.ts +6 -0
  163. package/src/queue/interfaces/IHttpRequestJob.ts +10 -0
  164. package/src/queue/interfaces/IHybridHttpQueue.ts +23 -0
  165. package/src/queue/interfaces/IJobResult.ts +6 -0
  166. package/src/queue/interfaces/IRateLimitConfig.ts +5 -0
  167. package/src/queue/interfaces/index.ts +4 -0
  168. package/src/queue/services/QueueService.ts +39 -0
  169. package/src/queue/services/index.ts +1 -0
  170. package/src/queue/types/http.types.ts +22 -0
  171. package/src/queue/types/index.ts +2 -0
  172. package/src/queue/types/queue.types.ts +22 -0
  173. package/src/queue/utils/index.ts +3 -0
  174. package/src/queue/utils/jobUtils.ts +80 -0
  175. package/src/queue/utils/queueUtils.ts +90 -0
  176. package/src/queue/utils/rateLimit.utils.ts +58 -0
  177. package/tsconfig.json +4 -0
  178. package/src/device/local/entities/README.md +0 -173
  179. package/src/device/local/entities/index.ts +0 -2
  180. package/src/types/index.ts +0 -3
  181. /package/src/{device/local/interfaces → connection}/IConnection.ts +0 -0
  182. /package/src/{device/local/models → docs}/Alert.model.md +0 -0
  183. /package/src/{device/local/models/README.md → docs/Alerts&IssuesModel.md} +0 -0
  184. /package/src/{device/local/models → docs}/Issue.model.md +0 -0
  185. /package/{SECURITY.md → src/docs/SECURITY.md} +0 -0
  186. /package/src/{types → issues}/issue.types.ts +0 -0
  187. /package/src/{device/local/interfaces → property}/IProperty.ts +0 -0
@@ -0,0 +1,87 @@
1
+ import { CreateAlertData, AlertCategory, AlertSeverity, EntityType } from "./alert.types";
2
+ /**
3
+ * AlertBuilder - A builder pattern implementation for constructing CreateAlertData objects
4
+ *
5
+ * This builder provides a fluent interface for creating alert data with proper validation
6
+ * and default values. It follows the Builder pattern which is a standard design pattern
7
+ * in TypeScript for constructing complex objects.
8
+ *
9
+ * Usage example:
10
+ * const alertData = new AlertBuilder()
11
+ * .setCategory(AlertCategory.OPERATIONS)
12
+ * .setPropertyId("prop123")
13
+ * .setTitle("Device Offline")
14
+ * .setDescription("Device has been offline for more than 5 minutes")
15
+ * .setEntityId("device456")
16
+ * .setEntityType(EntityType.DEVICE)
17
+ * .setSeverity(AlertSeverity.HIGH)
18
+ * .setCreatedBy("user789")
19
+ * .build();
20
+ */
21
+ export declare class AlertBuilder {
22
+ private data;
23
+ /**
24
+ * Sets the alert category
25
+ */
26
+ setCategory(category: AlertCategory): AlertBuilder;
27
+ /**
28
+ * Sets the property ID
29
+ */
30
+ setPropertyId(propertyId: string): AlertBuilder;
31
+ /**
32
+ * Sets the alert title
33
+ */
34
+ setTitle(title: string): AlertBuilder;
35
+ /**
36
+ * Sets the alert description
37
+ */
38
+ setDescription(description: string): AlertBuilder;
39
+ /**
40
+ * Sets the entity ID (optional)
41
+ */
42
+ setEntityId(entityId?: string): AlertBuilder;
43
+ /**
44
+ * Sets the entity type
45
+ */
46
+ setEntityType(entityType: EntityType): AlertBuilder;
47
+ /**
48
+ * Sets the alert severity (optional, defaults to MEDIUM)
49
+ */
50
+ setSeverity(severity?: AlertSeverity): AlertBuilder;
51
+ /**
52
+ * Sets the user who created the alert (optional)
53
+ */
54
+ setCreatedBy(createdBy?: string): AlertBuilder;
55
+ /**
56
+ * Sets the snooze until date (optional)
57
+ */
58
+ setSnoozeUntil(snoozeUntil?: Date): AlertBuilder;
59
+ /**
60
+ * Validates that all required fields are present
61
+ */
62
+ private validate;
63
+ /**
64
+ * Builds and returns the CreateAlertData object
65
+ * @throws Error if required fields are missing
66
+ */
67
+ build(): CreateAlertData;
68
+ /**
69
+ * Resets the builder to its initial state
70
+ */
71
+ reset(): AlertBuilder;
72
+ /**
73
+ * Creates a new builder instance with predefined values for common alert types
74
+ */
75
+ static createReadinessAlert(): AlertBuilder;
76
+ static createOperationsAlert(): AlertBuilder;
77
+ static createSecurityAlert(): AlertBuilder;
78
+ static createEnergyAlert(): AlertBuilder;
79
+ /**
80
+ * Creates a device-specific alert builder
81
+ */
82
+ static createDeviceAlert(deviceId: string, propertyId: string): AlertBuilder;
83
+ /**
84
+ * Creates a hub-specific alert builder
85
+ */
86
+ static createHubAlert(hubId: string, propertyId: string): AlertBuilder;
87
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Example usage of AlertBuilder
3
+ * This file demonstrates various ways to use the AlertBuilder pattern
4
+ */
5
+ export declare function createBasicAlert(): import("./alert.types").CreateAlertData;
6
+ export declare function createDeviceAlert(): import("./alert.types").CreateAlertData;
7
+ export declare function createSecurityAlert(): import("./alert.types").CreateAlertData;
8
+ export declare function createEnergyAlert(): import("./alert.types").CreateAlertData;
9
+ export declare function createHubAlert(): import("./alert.types").CreateAlertData;
10
+ export declare function createSnoozedAlert(): import("./alert.types").CreateAlertData;
11
+ export declare function createMultipleAlerts(): import("./alert.types").CreateAlertData[];
@@ -0,0 +1,117 @@
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
+ }
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AlertBuilder = void 0;
4
+ const alert_types_1 = require("./alert.types");
5
+ /**
6
+ * AlertBuilder - A builder pattern implementation for constructing CreateAlertData objects
7
+ *
8
+ * This builder provides a fluent interface for creating alert data with proper validation
9
+ * and default values. It follows the Builder pattern which is a standard design pattern
10
+ * in TypeScript for constructing complex objects.
11
+ *
12
+ * Usage example:
13
+ * const alertData = new AlertBuilder()
14
+ * .setCategory(AlertCategory.OPERATIONS)
15
+ * .setPropertyId("prop123")
16
+ * .setTitle("Device Offline")
17
+ * .setDescription("Device has been offline for more than 5 minutes")
18
+ * .setEntityId("device456")
19
+ * .setEntityType(EntityType.DEVICE)
20
+ * .setSeverity(AlertSeverity.HIGH)
21
+ * .setCreatedBy("user789")
22
+ * .build();
23
+ */
24
+ class AlertBuilder {
25
+ constructor() {
26
+ this.data = {};
27
+ }
28
+ /**
29
+ * Sets the alert category
30
+ */
31
+ setCategory(category) {
32
+ this.data.category = category;
33
+ return this;
34
+ }
35
+ /**
36
+ * Sets the property ID
37
+ */
38
+ setPropertyId(propertyId) {
39
+ if (!propertyId || propertyId.trim() === "") {
40
+ throw new Error("Property ID is required and cannot be empty");
41
+ }
42
+ this.data.propertyId = propertyId;
43
+ return this;
44
+ }
45
+ /**
46
+ * Sets the alert title
47
+ */
48
+ setTitle(title) {
49
+ if (!title || title.trim() === "") {
50
+ throw new Error("Title is required and cannot be empty");
51
+ }
52
+ this.data.title = title.trim();
53
+ return this;
54
+ }
55
+ /**
56
+ * Sets the alert description
57
+ */
58
+ setDescription(description) {
59
+ if (!description || description.trim() === "") {
60
+ throw new Error("Description is required and cannot be empty");
61
+ }
62
+ this.data.description = description.trim();
63
+ return this;
64
+ }
65
+ /**
66
+ * Sets the entity ID (optional)
67
+ */
68
+ setEntityId(entityId) {
69
+ if (entityId !== undefined) {
70
+ this.data.entityId = entityId.trim() || undefined;
71
+ }
72
+ return this;
73
+ }
74
+ /**
75
+ * Sets the entity type
76
+ */
77
+ setEntityType(entityType) {
78
+ this.data.entityType = entityType;
79
+ return this;
80
+ }
81
+ /**
82
+ * Sets the alert severity (optional, defaults to MEDIUM)
83
+ */
84
+ setSeverity(severity) {
85
+ if (severity !== undefined) {
86
+ this.data.severity = severity;
87
+ }
88
+ return this;
89
+ }
90
+ /**
91
+ * Sets the user who created the alert (optional)
92
+ */
93
+ setCreatedBy(createdBy) {
94
+ if (createdBy !== undefined) {
95
+ this.data.createdBy = createdBy.trim() || undefined;
96
+ }
97
+ return this;
98
+ }
99
+ /**
100
+ * Sets the snooze until date (optional)
101
+ */
102
+ setSnoozeUntil(snoozeUntil) {
103
+ if (snoozeUntil !== undefined) {
104
+ this.data.snoozeUntil = snoozeUntil;
105
+ }
106
+ return this;
107
+ }
108
+ /**
109
+ * Validates that all required fields are present
110
+ */
111
+ validate() {
112
+ const requiredFields = [
113
+ "category",
114
+ "propertyId",
115
+ "title",
116
+ "description",
117
+ "entityType",
118
+ ];
119
+ const missingFields = requiredFields.filter((field) => !this.data[field]);
120
+ if (missingFields.length > 0) {
121
+ throw new Error(`Missing required fields: ${missingFields.join(", ")}`);
122
+ }
123
+ }
124
+ /**
125
+ * Builds and returns the CreateAlertData object
126
+ * @throws Error if required fields are missing
127
+ */
128
+ build() {
129
+ this.validate();
130
+ // Set default severity if not provided
131
+ if (!this.data.severity) {
132
+ this.data.severity = alert_types_1.AlertSeverity.MEDIUM;
133
+ }
134
+ return this.data;
135
+ }
136
+ /**
137
+ * Resets the builder to its initial state
138
+ */
139
+ reset() {
140
+ this.data = {};
141
+ return this;
142
+ }
143
+ /**
144
+ * Creates a new builder instance with predefined values for common alert types
145
+ */
146
+ static createReadinessAlert() {
147
+ return new AlertBuilder()
148
+ .setCategory(alert_types_1.AlertCategory.READINESS)
149
+ .setSeverity(alert_types_1.AlertSeverity.MEDIUM);
150
+ }
151
+ static createOperationsAlert() {
152
+ return new AlertBuilder()
153
+ .setCategory(alert_types_1.AlertCategory.OPERATIONS)
154
+ .setSeverity(alert_types_1.AlertSeverity.HIGH);
155
+ }
156
+ static createSecurityAlert() {
157
+ return new AlertBuilder()
158
+ .setCategory(alert_types_1.AlertCategory.SECURITY)
159
+ .setSeverity(alert_types_1.AlertSeverity.CRITICAL);
160
+ }
161
+ static createEnergyAlert() {
162
+ return new AlertBuilder()
163
+ .setCategory(alert_types_1.AlertCategory.ENERGY)
164
+ .setSeverity(alert_types_1.AlertSeverity.LOW);
165
+ }
166
+ /**
167
+ * Creates a device-specific alert builder
168
+ */
169
+ static createDeviceAlert(deviceId, propertyId) {
170
+ return new AlertBuilder()
171
+ .setEntityType(alert_types_1.EntityType.DEVICE)
172
+ .setEntityId(deviceId)
173
+ .setPropertyId(propertyId);
174
+ }
175
+ /**
176
+ * Creates a hub-specific alert builder
177
+ */
178
+ static createHubAlert(hubId, propertyId) {
179
+ return new AlertBuilder()
180
+ .setEntityType(alert_types_1.EntityType.HUB)
181
+ .setEntityId(hubId)
182
+ .setPropertyId(propertyId);
183
+ }
184
+ }
185
+ exports.AlertBuilder = AlertBuilder;
@@ -0,0 +1,55 @@
1
+ import { AlertService } from "./Alert.service";
2
+ /**
3
+ * Example usage of the updated AlertService with AlertBuilder integration
4
+ * This file demonstrates various ways to use the AlertService with the new AlertBuilder
5
+ */
6
+ export declare class AlertServiceExample {
7
+ private readonly alertService;
8
+ constructor(alertService: AlertService);
9
+ /**
10
+ * Example 1: Using the updated createAlert method with AlertBuilder
11
+ */
12
+ createAlertWithBuilder(): Promise<import("./alert.types").AlertDocument>;
13
+ /**
14
+ * Example 2: Using convenience methods for specific alert types
15
+ */
16
+ createSpecificAlerts(): Promise<{
17
+ readinessAlert: import("./alert.types").AlertDocument;
18
+ operationsAlert: import("./alert.types").AlertDocument;
19
+ securityAlert: import("./alert.types").AlertDocument;
20
+ energyAlert: import("./alert.types").AlertDocument;
21
+ }>;
22
+ /**
23
+ * Example 3: Using device-specific alert methods
24
+ */
25
+ createDeviceAlerts(): Promise<{
26
+ deviceAlert1: import("./alert.types").AlertDocument;
27
+ deviceAlert2: import("./alert.types").AlertDocument;
28
+ }>;
29
+ /**
30
+ * Example 4: Using hub-specific alert methods
31
+ */
32
+ createHubAlerts(): Promise<{
33
+ hubAlert1: import("./alert.types").AlertDocument;
34
+ hubAlert2: import("./alert.types").AlertDocument;
35
+ }>;
36
+ /**
37
+ * Example 5: Using static factory methods with AlertBuilder
38
+ */
39
+ createAlertsWithStaticMethods(): Promise<{
40
+ alert1: import("./alert.types").AlertDocument;
41
+ alert2: import("./alert.types").AlertDocument;
42
+ }>;
43
+ /**
44
+ * Example 6: Creating multiple alerts efficiently
45
+ */
46
+ createMultipleAlerts(): Promise<import("./alert.types").AlertDocument[]>;
47
+ /**
48
+ * Example 7: Creating alerts with snooze functionality
49
+ */
50
+ createSnoozedAlert(): Promise<import("./alert.types").AlertDocument>;
51
+ /**
52
+ * Example 8: Backward compatibility - still works with CreateAlertData
53
+ */
54
+ createAlertWithLegacyData(): Promise<import("./alert.types").AlertDocument>;
55
+ }
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AlertServiceExample = void 0;
4
+ const AlertBuilder_1 = require("./AlertBuilder");
5
+ const alert_types_1 = require("./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;
@@ -0,0 +1,57 @@
1
+ import { EntityType } from "../issues/issue.types";
2
+ export declare enum AlertCategory {
3
+ READINESS = "READINESS",
4
+ OPERATIONS = "OPERATIONS",
5
+ SECURITY = "SECURITY",
6
+ ENERGY = "ENERGY",
7
+ OTHER = "OTHER"
8
+ }
9
+ export declare enum AlertSeverity {
10
+ INFO = "INFO",
11
+ LOW = "LOW",
12
+ MEDIUM = "MEDIUM",
13
+ HIGH = "HIGH",
14
+ CRITICAL = "CRITICAL"
15
+ }
16
+ export interface AlertDocument {
17
+ _id: string;
18
+ category: AlertCategory;
19
+ propertyId: string;
20
+ title: string;
21
+ description: string;
22
+ entityId?: string;
23
+ entityType: EntityType;
24
+ severity: AlertSeverity;
25
+ isRead: boolean;
26
+ isActive: boolean;
27
+ isDeleted: boolean;
28
+ snoozeUntil?: Date;
29
+ createdBy?: string;
30
+ updatedBy?: string;
31
+ createdAt: Date;
32
+ updatedAt: Date;
33
+ }
34
+ export interface CreateAlertData {
35
+ category: AlertCategory;
36
+ propertyId: string;
37
+ title: string;
38
+ description: string;
39
+ entityId?: string;
40
+ entityType: EntityType;
41
+ severity?: AlertSeverity;
42
+ createdBy?: string;
43
+ snoozeUntil?: Date;
44
+ }
45
+ export interface UpdateAlertData {
46
+ category?: AlertCategory;
47
+ title?: string;
48
+ description?: string;
49
+ entityId?: string;
50
+ entityType?: EntityType;
51
+ severity?: AlertSeverity;
52
+ isRead?: boolean;
53
+ isActive?: boolean;
54
+ snoozeUntil?: Date;
55
+ updatedBy?: string;
56
+ }
57
+ export { EntityType } from "../issues/issue.types";
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EntityType = exports.AlertSeverity = exports.AlertCategory = void 0;
4
+ var AlertCategory;
5
+ (function (AlertCategory) {
6
+ AlertCategory["READINESS"] = "READINESS";
7
+ AlertCategory["OPERATIONS"] = "OPERATIONS";
8
+ AlertCategory["SECURITY"] = "SECURITY";
9
+ AlertCategory["ENERGY"] = "ENERGY";
10
+ AlertCategory["OTHER"] = "OTHER";
11
+ })(AlertCategory || (exports.AlertCategory = AlertCategory = {}));
12
+ var AlertSeverity;
13
+ (function (AlertSeverity) {
14
+ AlertSeverity["INFO"] = "INFO";
15
+ AlertSeverity["LOW"] = "LOW";
16
+ AlertSeverity["MEDIUM"] = "MEDIUM";
17
+ AlertSeverity["HIGH"] = "HIGH";
18
+ AlertSeverity["CRITICAL"] = "CRITICAL";
19
+ })(AlertSeverity || (exports.AlertSeverity = AlertSeverity = {}));
20
+ // Re-export EntityType from issue.types.ts to avoid duplication
21
+ var issue_types_1 = require("../issues/issue.types");
22
+ Object.defineProperty(exports, "EntityType", { enumerable: true, get: function () { return issue_types_1.EntityType; } });