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