dt-common-device 1.3.0 → 2.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 (132) hide show
  1. package/TROUBLESHOOTING.md +184 -0
  2. package/dist/config/config.d.ts +9 -2
  3. package/dist/config/config.js +97 -14
  4. package/dist/constants/Event.d.ts +75 -0
  5. package/dist/constants/Event.js +78 -0
  6. package/dist/db/db.d.ts +1 -0
  7. package/dist/db/db.js +18 -2
  8. package/dist/device/local/entities/AlertBuilder.d.ts +87 -0
  9. package/dist/device/local/entities/AlertBuilder.example.d.ts +11 -0
  10. package/dist/device/local/entities/AlertBuilder.example.js +117 -0
  11. package/dist/device/local/entities/AlertBuilder.js +179 -0
  12. package/dist/device/local/entities/IssueBuilder.d.ts +109 -0
  13. package/dist/device/local/entities/IssueBuilder.example.d.ts +16 -0
  14. package/dist/device/local/entities/IssueBuilder.example.js +196 -0
  15. package/dist/device/local/entities/IssueBuilder.js +237 -0
  16. package/dist/device/local/entities/index.d.ts +2 -0
  17. package/dist/device/local/entities/index.js +7 -0
  18. package/dist/device/local/interfaces/IDevice.d.ts +10 -9
  19. package/dist/device/local/interfaces/IDevice.js +7 -0
  20. package/dist/device/local/models/Alert.model.d.ts +28 -0
  21. package/dist/device/local/models/Alert.model.js +222 -0
  22. package/dist/device/local/models/Issue.model.d.ts +28 -0
  23. package/dist/device/local/models/Issue.model.js +260 -0
  24. package/dist/device/local/repository/Alert.repository.d.ts +106 -0
  25. package/dist/device/local/repository/Alert.repository.js +374 -0
  26. package/dist/device/local/repository/Device.repository.d.ts +10 -2
  27. package/dist/device/local/repository/Device.repository.js +153 -30
  28. package/dist/device/local/repository/Hub.repository.d.ts +1 -1
  29. package/dist/device/local/repository/Hub.repository.js +60 -18
  30. package/dist/device/local/repository/Issue.repository.d.ts +113 -0
  31. package/dist/device/local/repository/Issue.repository.js +401 -0
  32. package/dist/device/local/repository/Schedule.repository.d.ts +1 -1
  33. package/dist/device/local/repository/Schedule.repository.js +14 -18
  34. package/dist/device/local/services/Alert.service.d.ts +135 -5
  35. package/dist/device/local/services/Alert.service.js +471 -7
  36. package/dist/device/local/services/AlertService.example.d.ts +55 -0
  37. package/dist/device/local/services/AlertService.example.js +148 -0
  38. package/dist/device/local/services/Device.service.d.ts +8 -5
  39. package/dist/device/local/services/Device.service.js +58 -40
  40. package/dist/device/local/services/Issue.service.d.ts +168 -0
  41. package/dist/device/local/services/Issue.service.js +642 -0
  42. package/dist/device/local/services/IssueService.example.d.ts +68 -0
  43. package/dist/device/local/services/IssueService.example.js +177 -0
  44. package/dist/device/local/services/index.d.ts +7 -5
  45. package/dist/device/local/services/index.js +21 -11
  46. package/dist/events/BaseEventHandler.d.ts +43 -0
  47. package/dist/events/BaseEventHandler.js +111 -0
  48. package/dist/events/BaseEventTransformer.d.ts +26 -0
  49. package/dist/events/BaseEventTransformer.js +72 -0
  50. package/dist/events/DeviceEventHandler.d.ts +15 -0
  51. package/dist/events/DeviceEventHandler.js +152 -0
  52. package/dist/events/DeviceEventTransformerFactory.d.ts +27 -0
  53. package/dist/events/DeviceEventTransformerFactory.js +116 -0
  54. package/dist/events/EventHandler.d.ts +11 -0
  55. package/dist/events/EventHandler.js +106 -0
  56. package/dist/events/EventHandlerOrchestrator.d.ts +35 -0
  57. package/dist/events/EventHandlerOrchestrator.js +141 -0
  58. package/dist/events/EventProcessingService.d.ts +43 -0
  59. package/dist/events/EventProcessingService.js +243 -0
  60. package/dist/events/InternalEventSubscription.d.ts +44 -0
  61. package/dist/events/InternalEventSubscription.js +152 -0
  62. package/dist/events/index.d.ts +9 -0
  63. package/dist/events/index.js +21 -0
  64. package/dist/events/interfaces/DeviceEvent.d.ts +48 -0
  65. package/dist/events/interfaces/DeviceEvent.js +2 -0
  66. package/dist/events/interfaces/IEventHandler.d.ts +23 -0
  67. package/dist/events/interfaces/IEventHandler.js +2 -0
  68. package/dist/events/interfaces/IEventTransformer.d.ts +7 -0
  69. package/dist/events/interfaces/IEventTransformer.js +2 -0
  70. package/dist/events/interfaces/IInternalEvent.d.ts +42 -0
  71. package/dist/events/interfaces/IInternalEvent.js +2 -0
  72. package/dist/events/interfaces/index.d.ts +4 -0
  73. package/dist/events/interfaces/index.js +20 -0
  74. package/dist/index.d.ts +6 -2
  75. package/dist/index.js +9 -2
  76. package/dist/types/alert.types.d.ts +57 -0
  77. package/dist/types/alert.types.js +22 -0
  78. package/dist/types/config.types.d.ts +15 -4
  79. package/dist/types/index.d.ts +2 -0
  80. package/dist/types/index.js +2 -0
  81. package/dist/types/issue.types.d.ts +90 -0
  82. package/dist/types/issue.types.js +40 -0
  83. package/dist/utils/http-utils.d.ts +13 -0
  84. package/dist/utils/http-utils.js +117 -0
  85. package/package.json +2 -1
  86. package/src/config/config.ts +117 -14
  87. package/src/{device/local/events/Events.ts → constants/Event.ts} +34 -13
  88. package/src/db/db.ts +14 -5
  89. package/src/device/local/entities/AlertBuilder.example.ts +126 -0
  90. package/src/device/local/entities/AlertBuilder.ts +202 -0
  91. package/src/device/local/entities/IssueBuilder.example.ts +210 -0
  92. package/src/device/local/entities/IssueBuilder.ts +263 -0
  93. package/src/device/local/entities/README.md +173 -0
  94. package/src/device/local/entities/index.ts +2 -0
  95. package/src/device/local/interfaces/IDevice.ts +11 -9
  96. package/src/device/local/models/Alert.model.md +319 -0
  97. package/src/device/local/models/Alert.model.ts +283 -0
  98. package/src/device/local/models/Issue.model.md +386 -0
  99. package/src/device/local/models/Issue.model.ts +350 -0
  100. package/src/device/local/models/README.md +312 -0
  101. package/src/device/local/repository/Alert.repository.ts +465 -0
  102. package/src/device/local/repository/Device.repository.ts +241 -32
  103. package/src/device/local/repository/Hub.repository.ts +74 -18
  104. package/src/device/local/repository/Issue.repository.ts +517 -0
  105. package/src/device/local/repository/Schedule.repository.ts +28 -22
  106. package/src/device/local/services/Alert.service.ts +617 -5
  107. package/src/device/local/services/AlertService.example.ts +229 -0
  108. package/src/device/local/services/Device.service.ts +70 -50
  109. package/src/device/local/services/Issue.service.ts +872 -0
  110. package/src/device/local/services/IssueService.example.ts +307 -0
  111. package/src/device/local/services/index.ts +7 -5
  112. package/src/events/BaseEventHandler.ts +145 -0
  113. package/src/events/BaseEventTransformer.ts +97 -0
  114. package/src/events/DeviceEventHandler.ts +211 -0
  115. package/src/events/DeviceEventTransformerFactory.ts +77 -0
  116. package/src/{device/local/events → events}/EventHandler.ts +19 -15
  117. package/src/events/EventHandlerOrchestrator.ts +119 -0
  118. package/src/events/EventProcessingService.ts +248 -0
  119. package/src/events/InternalEventSubscription.ts +219 -0
  120. package/src/events/index.ts +9 -0
  121. package/src/events/interfaces/DeviceEvent.ts +56 -0
  122. package/src/events/interfaces/IEventHandler.ts +28 -0
  123. package/src/events/interfaces/IEventTransformer.ts +8 -0
  124. package/src/events/interfaces/IInternalEvent.ts +47 -0
  125. package/src/events/interfaces/index.ts +4 -0
  126. package/src/index.ts +9 -2
  127. package/src/types/alert.types.ts +64 -0
  128. package/src/types/config.types.ts +17 -4
  129. package/src/types/index.ts +2 -0
  130. package/src/types/issue.types.ts +98 -0
  131. package/src/utils/http-utils.ts +143 -0
  132. package/src/device/local/events/index.ts +0 -2
@@ -0,0 +1,68 @@
1
+ import { IssueService } from "./Issue.service";
2
+ /**
3
+ * Example usage of the updated IssueService with IssueBuilder integration
4
+ * This file demonstrates various ways to use the IssueService with the new IssueBuilder
5
+ */
6
+ export declare class IssueServiceExample {
7
+ private readonly issueService;
8
+ constructor(issueService: IssueService);
9
+ /**
10
+ * Example 1: Using the updated createIssue method with IssueBuilder
11
+ */
12
+ createIssueWithBuilder(): Promise<import("../../../types/issue.types").IssueDocument>;
13
+ /**
14
+ * Example 2: Using convenience methods for specific issue types
15
+ */
16
+ createSpecificIssues(): Promise<{
17
+ readinessIssue: import("../../../types/issue.types").IssueDocument;
18
+ operationsIssue: import("../../../types/issue.types").IssueDocument;
19
+ securityIssue: import("../../../types/issue.types").IssueDocument;
20
+ energyIssue: import("../../../types/issue.types").IssueDocument;
21
+ }>;
22
+ /**
23
+ * Example 3: Using device-specific issue methods
24
+ */
25
+ createDeviceIssues(): Promise<{
26
+ deviceIssue1: import("../../../types/issue.types").IssueDocument;
27
+ deviceIssue2: import("../../../types/issue.types").IssueDocument;
28
+ }>;
29
+ /**
30
+ * Example 4: Using hub-specific issue methods
31
+ */
32
+ createHubIssues(): Promise<{
33
+ hubIssue1: import("../../../types/issue.types").IssueDocument;
34
+ hubIssue2: import("../../../types/issue.types").IssueDocument;
35
+ }>;
36
+ /**
37
+ * Example 5: Using user-specific issue methods
38
+ */
39
+ createUserIssues(): Promise<{
40
+ userIssue: import("../../../types/issue.types").IssueDocument;
41
+ }>;
42
+ /**
43
+ * Example 6: Using maintenance and urgent issue methods
44
+ */
45
+ createMaintenanceAndUrgentIssues(): Promise<{
46
+ maintenanceIssue: import("../../../types/issue.types").IssueDocument;
47
+ urgentIssue: import("../../../types/issue.types").IssueDocument;
48
+ }>;
49
+ /**
50
+ * Example 7: Using static factory methods with IssueBuilder
51
+ */
52
+ createIssuesWithStaticMethods(): Promise<{
53
+ issue1: import("../../../types/issue.types").IssueDocument;
54
+ issue2: import("../../../types/issue.types").IssueDocument;
55
+ }>;
56
+ /**
57
+ * Example 8: Creating multiple issues efficiently
58
+ */
59
+ createMultipleIssues(): Promise<import("../../../types/issue.types").IssueDocument[]>;
60
+ /**
61
+ * Example 9: Creating issue with due date calculation
62
+ */
63
+ createIssueWithDueDate(): Promise<import("../../../types/issue.types").IssueDocument>;
64
+ /**
65
+ * Example 10: Backward compatibility - still works with CreateIssueData
66
+ */
67
+ createIssueWithLegacyData(): Promise<import("../../../types/issue.types").IssueDocument>;
68
+ }
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IssueServiceExample = void 0;
4
+ const IssueBuilder_1 = require("../entities/IssueBuilder");
5
+ const issue_types_1 = require("../../../types/issue.types");
6
+ /**
7
+ * Example usage of the updated IssueService with IssueBuilder integration
8
+ * This file demonstrates various ways to use the IssueService with the new IssueBuilder
9
+ */
10
+ class IssueServiceExample {
11
+ constructor(issueService) {
12
+ this.issueService = issueService;
13
+ }
14
+ /**
15
+ * Example 1: Using the updated createIssue method with IssueBuilder
16
+ */
17
+ async createIssueWithBuilder() {
18
+ const issueBuilder = new IssueBuilder_1.IssueBuilder()
19
+ .setCategory(issue_types_1.IssuesCategory.OPERATIONS)
20
+ .setPropertyId("prop123")
21
+ .setTitle("Device Maintenance Required")
22
+ .setDescription("Device requires scheduled maintenance")
23
+ .setEntityId("device456")
24
+ .setEntityType(issue_types_1.EntityType.DEVICE)
25
+ .setPriority(issue_types_1.IssuePriority.HIGH)
26
+ .setAssignedTo("tech789")
27
+ .setCreatedBy("user123")
28
+ .setDueDate(new Date("2024-01-15"));
29
+ // Pass the IssueBuilder directly to createIssue
30
+ const issue = await this.issueService.createIssue(issueBuilder);
31
+ return issue;
32
+ }
33
+ /**
34
+ * Example 2: Using convenience methods for specific issue types
35
+ */
36
+ async createSpecificIssues() {
37
+ // Create a readiness issue
38
+ const readinessIssue = await this.issueService.createReadinessIssue("prop123", "System Maintenance Required", "System maintenance is scheduled for tonight", "admin", "system456", issue_types_1.EntityType.PROPERTY, "maintenance-team", new Date("2024-01-20"));
39
+ // Create an operations issue
40
+ const operationsIssue = await this.issueService.createOperationsIssue("prop123", "Device Temperature High", "Device temperature exceeds normal operating range", "monitor", "device789", issue_types_1.EntityType.DEVICE, "tech-support", new Date("2024-01-10"));
41
+ // Create a security issue
42
+ const securityIssue = await this.issueService.createSecurityIssue("prop123", "Unauthorized Access Attempt", "Multiple failed login attempts detected", "security-system", "user123", issue_types_1.EntityType.USER, "security-team", new Date("2024-01-05"));
43
+ // Create an energy issue
44
+ const energyIssue = await this.issueService.createEnergyIssue("prop123", "High Energy Consumption", "Energy usage is 20% above normal levels", "energy-monitor", "zone456", issue_types_1.EntityType.COLLECTION, "energy-manager", new Date("2024-01-25"));
45
+ return { readinessIssue, operationsIssue, securityIssue, energyIssue };
46
+ }
47
+ /**
48
+ * Example 3: Using device-specific issue methods
49
+ */
50
+ async createDeviceIssues() {
51
+ // Create a device issue with default category and priority
52
+ const deviceIssue1 = await this.issueService.createDeviceIssue("device123", "prop456", "Device Battery Low", "Device battery level is below 20%", "system", undefined, // Use default category
53
+ undefined, // Use default priority
54
+ "maintenance-team", new Date("2024-01-12"));
55
+ // Create a device issue with custom category and priority
56
+ const deviceIssue2 = await this.issueService.createDeviceIssue("device789", "prop456", "Device Firmware Update Available", "New firmware version is available for installation", "firmware-manager", issue_types_1.IssuesCategory.READINESS, issue_types_1.IssuePriority.MEDIUM, "admin", new Date("2024-01-20"));
57
+ return { deviceIssue1, deviceIssue2 };
58
+ }
59
+ /**
60
+ * Example 4: Using hub-specific issue methods
61
+ */
62
+ async createHubIssues() {
63
+ // Create a hub issue with default settings
64
+ const hubIssue1 = await this.issueService.createHubIssue("hub123", "prop456", "Hub Connection Lost", "Hub has lost connection to the network", "network-monitor", undefined, // Use default category
65
+ undefined, // Use default priority
66
+ "network-admin", new Date("2024-01-05"));
67
+ // Create a hub issue with custom settings
68
+ const hubIssue2 = await this.issueService.createHubIssue("hub789", "prop456", "Hub Maintenance Required", "Hub requires scheduled maintenance", "maintenance-system", issue_types_1.IssuesCategory.READINESS, issue_types_1.IssuePriority.LOW, "technician", new Date("2024-01-15"));
69
+ return { hubIssue1, hubIssue2 };
70
+ }
71
+ /**
72
+ * Example 5: Using user-specific issue methods
73
+ */
74
+ async createUserIssues() {
75
+ // Create a user issue
76
+ const userIssue = await this.issueService.createUserIssue("user456", "prop303", "User Access Review Required", "User access permissions need review", "access-control", issue_types_1.IssuesCategory.SECURITY, issue_types_1.IssuePriority.MEDIUM, "hr-admin", new Date("2024-01-30"));
77
+ return { userIssue };
78
+ }
79
+ /**
80
+ * Example 6: Using maintenance and urgent issue methods
81
+ */
82
+ async createMaintenanceAndUrgentIssues() {
83
+ // Create a maintenance issue
84
+ const maintenanceIssue = await this.issueService.createMaintenanceIssue("prop505", "Scheduled Device Maintenance", "Regular maintenance is scheduled for this device", "maintenance-scheduler", "device789", issue_types_1.EntityType.DEVICE, "technician", new Date("2024-01-12"));
85
+ // Create an urgent issue
86
+ const urgentIssue = await this.issueService.createUrgentIssue("prop606", "Critical Hub Failure", "Hub is experiencing critical failures", "monitoring-system", "hub123", issue_types_1.EntityType.HUB, "emergency-tech", new Date("2024-01-03"));
87
+ return { maintenanceIssue, urgentIssue };
88
+ }
89
+ /**
90
+ * Example 7: Using static factory methods with IssueBuilder
91
+ */
92
+ async createIssuesWithStaticMethods() {
93
+ // Create a device issue using static factory method
94
+ const deviceIssue = IssueBuilder_1.IssueBuilder.createDeviceIssue("device123", "prop456")
95
+ .setCategory(issue_types_1.IssuesCategory.OPERATIONS)
96
+ .setTitle("Device Offline")
97
+ .setDescription("Device has been offline for more than 5 minutes")
98
+ .setPriority(issue_types_1.IssuePriority.HIGH)
99
+ .setAssignedTo("tech-support")
100
+ .setCreatedBy("monitor")
101
+ .setDueDate(new Date("2024-01-10"));
102
+ const issue1 = await this.issueService.createIssue(deviceIssue);
103
+ // Create a hub issue using static factory method
104
+ const hubIssue = IssueBuilder_1.IssueBuilder.createHubIssue("hub789", "prop202")
105
+ .setCategory(issue_types_1.IssuesCategory.SECURITY)
106
+ .setTitle("Hub Security Breach")
107
+ .setDescription("Unauthorized access attempt detected on hub")
108
+ .setPriority(issue_types_1.IssuePriority.CRITICAL)
109
+ .setAssignedTo("security-team")
110
+ .setCreatedBy("security-system")
111
+ .setDueDate(new Date("2024-01-05"));
112
+ const issue2 = await this.issueService.createIssue(hubIssue);
113
+ return { issue1, issue2 };
114
+ }
115
+ /**
116
+ * Example 8: Creating multiple issues efficiently
117
+ */
118
+ async createMultipleIssues() {
119
+ const issues = [];
120
+ // Create multiple device issues efficiently
121
+ const deviceIds = ["device1", "device2", "device3"];
122
+ const propertyId = "prop123";
123
+ for (const deviceId of deviceIds) {
124
+ const issueBuilder = IssueBuilder_1.IssueBuilder.createDeviceIssue(deviceId, propertyId)
125
+ .setCategory(issue_types_1.IssuesCategory.OPERATIONS)
126
+ .setTitle(`Device ${deviceId} Status`)
127
+ .setDescription(`Status check for device ${deviceId}`)
128
+ .setPriority(issue_types_1.IssuePriority.MEDIUM)
129
+ .setAssignedTo("batch-processor")
130
+ .setCreatedBy("batch-processor")
131
+ .setDueDate(new Date("2024-01-15"));
132
+ const issue = await this.issueService.createIssue(issueBuilder);
133
+ issues.push(issue);
134
+ }
135
+ return issues;
136
+ }
137
+ /**
138
+ * Example 9: Creating issue with due date calculation
139
+ */
140
+ async createIssueWithDueDate() {
141
+ const dueDate = new Date();
142
+ dueDate.setDate(dueDate.getDate() + 7); // Due in 7 days
143
+ const issueBuilder = new IssueBuilder_1.IssueBuilder()
144
+ .setCategory(issue_types_1.IssuesCategory.READINESS)
145
+ .setPropertyId("prop808")
146
+ .setTitle("System Update Required")
147
+ .setDescription("System requires critical security update")
148
+ .setEntityType(issue_types_1.EntityType.PROPERTY)
149
+ .setPriority(issue_types_1.IssuePriority.HIGH)
150
+ .setAssignedTo("system-admin")
151
+ .setCreatedBy("update-manager")
152
+ .setDueDate(dueDate);
153
+ const issue = await this.issueService.createIssue(issueBuilder);
154
+ return issue;
155
+ }
156
+ /**
157
+ * Example 10: Backward compatibility - still works with CreateIssueData
158
+ */
159
+ async createIssueWithLegacyData() {
160
+ const issueData = {
161
+ category: issue_types_1.IssuesCategory.OPERATIONS,
162
+ propertyId: "prop123",
163
+ title: "Legacy Issue",
164
+ description: "This issue was created using the old CreateIssueData format",
165
+ entityId: "device456",
166
+ entityType: issue_types_1.EntityType.DEVICE,
167
+ priority: issue_types_1.IssuePriority.MEDIUM,
168
+ assignedTo: "tech-support",
169
+ createdBy: "legacy-system",
170
+ dueDate: new Date("2024-01-20")
171
+ };
172
+ // This still works with the updated createIssue method
173
+ const issue = await this.issueService.createIssue(issueData);
174
+ return issue;
175
+ }
176
+ }
177
+ exports.IssueServiceExample = IssueServiceExample;
@@ -1,5 +1,7 @@
1
- export { LocalDeviceService } from "./Device.service";
2
- export { LocalHubService } from "./Hub.service";
3
- export { LocalConnectionService } from "./Connection.service";
4
- export { LocalPropertyService } from "./Property.service";
5
- export { LocalScheduleService } from "./Schedule.service";
1
+ export * from "./Alert.service";
2
+ export * from "./Connection.service";
3
+ export * from "./Device.service";
4
+ export * from "./Hub.service";
5
+ export * from "./Issue.service";
6
+ export * from "./Property.service";
7
+ export * from "./Schedule.service";
@@ -1,13 +1,23 @@
1
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
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LocalScheduleService = exports.LocalPropertyService = exports.LocalConnectionService = exports.LocalHubService = exports.LocalDeviceService = void 0;
4
- var Device_service_1 = require("./Device.service");
5
- Object.defineProperty(exports, "LocalDeviceService", { enumerable: true, get: function () { return Device_service_1.LocalDeviceService; } });
6
- var Hub_service_1 = require("./Hub.service");
7
- Object.defineProperty(exports, "LocalHubService", { enumerable: true, get: function () { return Hub_service_1.LocalHubService; } });
8
- var Connection_service_1 = require("./Connection.service");
9
- Object.defineProperty(exports, "LocalConnectionService", { enumerable: true, get: function () { return Connection_service_1.LocalConnectionService; } });
10
- var Property_service_1 = require("./Property.service");
11
- Object.defineProperty(exports, "LocalPropertyService", { enumerable: true, get: function () { return Property_service_1.LocalPropertyService; } });
12
- var Schedule_service_1 = require("./Schedule.service");
13
- Object.defineProperty(exports, "LocalScheduleService", { enumerable: true, get: function () { return Schedule_service_1.LocalScheduleService; } });
17
+ __exportStar(require("./Alert.service"), exports);
18
+ __exportStar(require("./Connection.service"), exports);
19
+ __exportStar(require("./Device.service"), exports);
20
+ __exportStar(require("./Hub.service"), exports);
21
+ __exportStar(require("./Issue.service"), exports);
22
+ __exportStar(require("./Property.service"), exports);
23
+ __exportStar(require("./Schedule.service"), exports);
@@ -0,0 +1,43 @@
1
+ import { DeviceEvent } from "./interfaces/DeviceEvent";
2
+ import { IEventHandler } from "./interfaces/IEventHandler";
3
+ import { ILogger } from "../types/config.types";
4
+ import { LocalDeviceService } from "../device/local/services/Device.service";
5
+ export declare abstract class BaseEventHandler implements IEventHandler {
6
+ protected readonly supportedEventTypes: string[];
7
+ protected readonly priority: number;
8
+ protected readonly logger: ILogger;
9
+ protected readonly localDeviceService: LocalDeviceService;
10
+ constructor(supportedEventTypes: string[], priority?: number);
11
+ /**
12
+ * Handle a single event - to be implemented by specific handlers
13
+ */
14
+ handleEvent(event: DeviceEvent): Promise<void>;
15
+ beforeEvent(event: DeviceEvent): Promise<void>;
16
+ abstract onEvent(event: DeviceEvent): Promise<void>;
17
+ afterEvent(event: DeviceEvent): Promise<void>;
18
+ /**
19
+ * Handle multiple events - default implementation processes them sequentially
20
+ */
21
+ handleEvents(events: DeviceEvent[]): Promise<void>;
22
+ onStateChange(deviceId: string, state: Record<string, any>, event: DeviceEvent): Promise<void>;
23
+ /**
24
+ * Check if this handler can process the given event type
25
+ */
26
+ canHandle(eventType: string): boolean;
27
+ /**
28
+ * Get the priority of this handler
29
+ */
30
+ getPriority(): number;
31
+ /**
32
+ * Get the event types this handler can process
33
+ */
34
+ getSupportedEventTypes(): string[];
35
+ /**
36
+ * Common validation method
37
+ */
38
+ protected validateEvent(event: DeviceEvent): boolean;
39
+ /**
40
+ * Common error handling method
41
+ */
42
+ protected handleError(error: any, context: string): Promise<void>;
43
+ }
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseEventHandler = void 0;
4
+ const config_1 = require("../config/config");
5
+ const Device_service_1 = require("../device/local/services/Device.service");
6
+ class BaseEventHandler {
7
+ constructor(supportedEventTypes, priority = 100) {
8
+ this.supportedEventTypes = supportedEventTypes;
9
+ this.priority = priority;
10
+ this.logger = (0, config_1.getConfig)().LOGGER;
11
+ this.localDeviceService = new Device_service_1.LocalDeviceService();
12
+ }
13
+ /**
14
+ * Handle a single event - to be implemented by specific handlers
15
+ */
16
+ async handleEvent(event) {
17
+ try {
18
+ await this.beforeEvent(event);
19
+ await this.onEvent(event);
20
+ }
21
+ catch (error) {
22
+ this.logger.error(`${this.constructor.name}: Error during event processing`, {
23
+ eventName: event.eventName,
24
+ deviceId: event.deviceId,
25
+ error,
26
+ });
27
+ throw error;
28
+ }
29
+ finally {
30
+ await this.afterEvent(event);
31
+ }
32
+ }
33
+ async beforeEvent(event) {
34
+ this.logger.info("[DT | CDL]:[BaseEventHandler]: Before event - Handle Before Event");
35
+ }
36
+ async afterEvent(event) {
37
+ this.logger.info("[DT | CDL]:[BaseEventHandler]: After event - Event processing completed", {
38
+ eventName: event.eventName,
39
+ deviceId: event.deviceId,
40
+ handler: this.constructor.name,
41
+ });
42
+ //TODO: Implement AUDIT Here!
43
+ }
44
+ /**
45
+ * Handle multiple events - default implementation processes them sequentially
46
+ */
47
+ async handleEvents(events) {
48
+ try {
49
+ this.logger.info(`Processing ${events.length} events with ${this.constructor.name}`);
50
+ for (const event of events) {
51
+ if (this.canHandle(event.eventName || "unknown")) {
52
+ await this.handleEvent(event);
53
+ }
54
+ else {
55
+ this.logger.warn(`Event type ${event.eventName} not supported by ${this.constructor.name}`);
56
+ }
57
+ }
58
+ }
59
+ catch (error) {
60
+ this.logger.error(`${this.constructor.name}: handleEvents Error`, error);
61
+ }
62
+ }
63
+ async onStateChange(deviceId, state, event) {
64
+ try {
65
+ await this.localDeviceService.setState(deviceId, state);
66
+ await this.afterEvent(event);
67
+ }
68
+ catch (error) {
69
+ this.logger.error(`[DT | CDL]:[BaseEventHandler]: Error during state change: ${error.message || error.toString()}`);
70
+ }
71
+ }
72
+ /**
73
+ * Check if this handler can process the given event type
74
+ */
75
+ canHandle(eventType) {
76
+ return this.supportedEventTypes.includes(eventType);
77
+ }
78
+ /**
79
+ * Get the priority of this handler
80
+ */
81
+ getPriority() {
82
+ return this.priority;
83
+ }
84
+ /**
85
+ * Get the event types this handler can process
86
+ */
87
+ getSupportedEventTypes() {
88
+ return this.supportedEventTypes;
89
+ }
90
+ /**
91
+ * Common validation method
92
+ */
93
+ validateEvent(event) {
94
+ if (!event) {
95
+ this.logger.error("Event is null or undefined");
96
+ return false;
97
+ }
98
+ if (!event.eventName) {
99
+ this.logger.error("Event name is missing");
100
+ return false;
101
+ }
102
+ return true;
103
+ }
104
+ /**
105
+ * Common error handling method
106
+ */
107
+ async handleError(error, context) {
108
+ this.logger.error(`${this.constructor.name}: ${context} Error`, error);
109
+ }
110
+ }
111
+ exports.BaseEventHandler = BaseEventHandler;
@@ -0,0 +1,26 @@
1
+ import { ILogger } from "../types/config.types";
2
+ import { DeviceEvent } from "./interfaces/DeviceEvent";
3
+ import { IEventTransformer } from "./interfaces/IEventTransformer";
4
+ export declare abstract class BaseEventTransformer implements IEventTransformer {
5
+ protected readonly deviceType: string;
6
+ protected rawData: any;
7
+ protected readonly logger: ILogger;
8
+ constructor(deviceType: string, rawData: any);
9
+ parseData(rawData: any): any;
10
+ /**
11
+ * Transform parsed data into DeviceEvent format - to be implemented by device-specific transformers
12
+ */
13
+ abstract transform(parsedData: any): DeviceEvent | DeviceEvent[];
14
+ /**
15
+ * Validate transformed event - default implementation, can be overridden
16
+ */
17
+ validate(transformedEvent: DeviceEvent): boolean;
18
+ /**
19
+ * Get the device type this transformer handles
20
+ */
21
+ getDeviceType(): string;
22
+ /**
23
+ * Execute the full transformation pipeline
24
+ */
25
+ executeTransformation(): DeviceEvent[];
26
+ }
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseEventTransformer = void 0;
4
+ const config_1 = require("../config/config");
5
+ class BaseEventTransformer {
6
+ constructor(deviceType, rawData) {
7
+ this.deviceType = deviceType;
8
+ this.rawData = rawData;
9
+ this.logger = (0, config_1.getConfig)().LOGGER;
10
+ }
11
+ // Parse raw event data - to be implemented by device-specific transformers
12
+ parseData(rawData) {
13
+ try {
14
+ this.logger.info(`${this.deviceType}EventTransformer: Parsed event data`);
15
+ return rawData;
16
+ }
17
+ catch (error) {
18
+ this.logger.error(`${this.deviceType}EventTransformer: Error parsing data`, error);
19
+ return null;
20
+ }
21
+ }
22
+ /**
23
+ * Validate transformed event - default implementation, can be overridden
24
+ */
25
+ validate(transformedEvent) {
26
+ try {
27
+ // Basic validation - ensure required fields exist
28
+ if (!transformedEvent) {
29
+ this.logger.error("Transformed event is null or undefined");
30
+ return false;
31
+ }
32
+ // Add more validation logic as needed
33
+ return true;
34
+ }
35
+ catch (error) {
36
+ this.logger.error("BaseEventTransformer: validate Error", error);
37
+ return false;
38
+ }
39
+ }
40
+ /**
41
+ * Get the device type this transformer handles
42
+ */
43
+ getDeviceType() {
44
+ return this.deviceType;
45
+ }
46
+ /**
47
+ * Execute the full transformation pipeline
48
+ */
49
+ executeTransformation() {
50
+ try {
51
+ this.logger.info(`Starting transformation for device type: ${this.deviceType}`);
52
+ // Step 1: Parse the raw data
53
+ const parsedData = this.parseData(this.rawData);
54
+ // Step 2: Transform to DeviceEvent format
55
+ const transformedResult = this.transform(parsedData);
56
+ // Step 3: Convert to array format
57
+ // TODO: Check if any service sends multiple events
58
+ const events = Array.isArray(transformedResult)
59
+ ? transformedResult
60
+ : [transformedResult];
61
+ // Step 4: Validate each event
62
+ const validEvents = events.filter((event) => this.validate(event));
63
+ this.logger.info(`Transformation completed. ${validEvents.length} valid events created.`);
64
+ return validEvents;
65
+ }
66
+ catch (error) {
67
+ this.logger.error("BaseEventTransformer: executeTransformation Error", error);
68
+ return [];
69
+ }
70
+ }
71
+ }
72
+ exports.BaseEventTransformer = BaseEventTransformer;
@@ -0,0 +1,15 @@
1
+ import { IDevice } from "../device/local/interfaces";
2
+ import { BaseEventHandler } from "./BaseEventHandler";
3
+ import { DeviceEvent, DeviceEventEntity, EventConstructionOptions } from "./interfaces/DeviceEvent";
4
+ export declare class DeviceEventHandler extends BaseEventHandler {
5
+ private readonly localHubService;
6
+ constructor();
7
+ onEvent(event: DeviceEvent): Promise<void>;
8
+ updateDeviceEventData(deviceData: IDevice, event: DeviceEvent): Promise<void>;
9
+ extractHubDetails(device: IDevice): Promise<any[]>;
10
+ constructDeviceEventEntity(eventData: any, device: IDevice, hubDetails: any[], options?: EventConstructionOptions): DeviceEventEntity;
11
+ dumpToEventOperation(data: any, device: IDevice): Promise<void>;
12
+ updateTablesBasedOnEventType(eventData: any, device: IDevice): Promise<void>;
13
+ updateDeviceStatus(data: any, device: IDevice): Promise<void>;
14
+ updateDeviceBattery(data: any, device: IDevice): Promise<void>;
15
+ }