dt-common-device 3.1.6 → 4.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/dist/alerts/Alert.service.d.ts +7 -3
- package/dist/alerts/Alert.service.js +10 -4
- package/dist/device/cloud/interface.d.ts +101 -0
- package/dist/device/cloud/interface.js +3 -0
- package/dist/device/cloud/interfaces/IDeviceConnectionService.d.ts +7 -0
- package/dist/device/cloud/interfaces/IDeviceConnectionService.js +3 -0
- package/dist/device/cloud/interfaces/IDevicesService.d.ts +9 -0
- package/dist/device/cloud/interfaces/IDevicesService.js +2 -0
- package/dist/device/cloud/services/Device.service.d.ts +39 -0
- package/dist/device/cloud/services/Device.service.js +9 -0
- package/dist/device/cloud/services/DeviceCloudService.d.ts +42 -0
- package/dist/device/cloud/services/DeviceCloudService.js +59 -0
- package/dist/device/cloud/services/DeviceHub.service.d.ts +3 -0
- package/dist/device/cloud/services/DeviceHub.service.js +6 -0
- package/dist/device/cloud/services/Hub.service.d.ts +25 -0
- package/dist/device/cloud/services/Hub.service.js +9 -0
- package/dist/device/cloud/services/SmartThingsDeviceService.d.ts +38 -0
- package/dist/device/cloud/services/SmartThingsDeviceService.js +52 -0
- package/dist/device/index.d.ts +4 -0
- package/dist/device/index.js +20 -0
- package/dist/device/local/events/EventHandler.js +6 -6
- package/dist/device/local/events/Events.d.ts +12 -33
- package/dist/device/local/events/Events.js +12 -33
- package/dist/device/local/interface.d.ts +0 -0
- package/dist/device/local/interface.js +1 -0
- package/dist/device/local/services/Device.service.d.ts +8 -6
- package/dist/device/local/services/Device.service.js +49 -27
- package/dist/device/local/services/DeviceHub.service.d.ts +11 -0
- package/dist/device/local/services/DeviceHub.service.js +40 -0
- package/dist/events/BaseEventHandler.d.ts +2 -1
- package/dist/events/BaseEventHandler.js +3 -2
- package/dist/events/BaseEventTransformer.d.ts +2 -2
- package/dist/events/BaseEventTransformer.js +2 -2
- package/dist/events/DeviceEventHandler.d.ts +1 -6
- package/dist/events/DeviceEventHandler.js +14 -75
- package/dist/events/DeviceEventTransformerFactory.js +2 -2
- package/dist/events/EventHandler.d.ts +7 -6
- package/dist/events/EventHandler.js +17 -62
- package/dist/events/EventProcessingService.d.ts +1 -1
- package/dist/events/EventProcessingService.js +5 -5
- package/dist/events/interfaces/DeviceEvent.d.ts +8 -4
- package/dist/events/interfaces/IEventTransformer.d.ts +2 -2
- package/dist/issues/Issue.service.d.ts +5 -1
- package/dist/issues/Issue.service.js +7 -1
- package/dist/queue/utils/queueUtils.js +1 -1
- package/dist/utils/redis.utils.d.ts +21 -0
- package/dist/utils/redis.utils.js +35 -0
- package/package.json +1 -1
|
@@ -39,10 +39,11 @@ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, p
|
|
|
39
39
|
};
|
|
40
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
41
|
exports.EventHandler = void 0;
|
|
42
|
-
const dt_pub_sub_1 = require("dt-pub-sub");
|
|
43
42
|
const dt_audit_library_1 = require("dt-audit-library");
|
|
44
43
|
const Event_1 = require("../constants/Event");
|
|
45
44
|
const typedi_1 = require("typedi");
|
|
45
|
+
const AuditUtils_1 = require("../audit/AuditUtils");
|
|
46
|
+
// TODO: For all the Event handlers, we need to publish the respective events for External Consumption
|
|
46
47
|
let EventHandler = (() => {
|
|
47
48
|
let _classDecorators = [(0, typedi_1.Service)()];
|
|
48
49
|
let _classDescriptor;
|
|
@@ -53,101 +54,55 @@ let EventHandler = (() => {
|
|
|
53
54
|
this.source = "dt-common-device";
|
|
54
55
|
}
|
|
55
56
|
async onDeviceCreate(body) {
|
|
56
|
-
// TODO: For Future Consumption
|
|
57
|
-
// await eventDispatcher.publishEvent(
|
|
58
|
-
// DT_EVENT_TYPES.DEVICE.CREATE.SUCCESS,
|
|
59
|
-
// body,
|
|
60
|
-
// this.source
|
|
61
|
-
// );
|
|
62
57
|
const payload = {
|
|
63
58
|
eventType: Event_1.DT_EVENT_TYPES.DEVICE.CREATE.SUCCESS,
|
|
64
|
-
properties:
|
|
65
|
-
...body,
|
|
66
|
-
},
|
|
59
|
+
properties: (0, AuditUtils_1.buildAuditProperties)(body),
|
|
67
60
|
};
|
|
68
61
|
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
69
62
|
}
|
|
70
|
-
async onDeviceUpdate(deviceId, body) {
|
|
71
|
-
await dt_pub_sub_1.eventDispatcher.publishEvent(Event_1.DT_EVENT_TYPES.DEVICE.UPDATE.SUCCESS, { deviceId, body }, this.source);
|
|
63
|
+
async onDeviceUpdate(deviceId, body, auditBody) {
|
|
72
64
|
const payload = {
|
|
73
65
|
eventType: Event_1.DT_EVENT_TYPES.DEVICE.UPDATE.SUCCESS,
|
|
74
|
-
properties: {
|
|
75
|
-
...body,
|
|
76
|
-
},
|
|
66
|
+
properties: (0, AuditUtils_1.buildAuditProperties)({ ...auditBody, deviceId, ...body }),
|
|
77
67
|
};
|
|
78
68
|
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
79
69
|
}
|
|
80
|
-
async onDeviceDelete(deviceId) {
|
|
81
|
-
await dt_pub_sub_1.eventDispatcher.publishEvent(Event_1.DT_EVENT_TYPES.DEVICE.DELETE.SUCCESS, { deviceId }, this.source);
|
|
70
|
+
async onDeviceDelete(deviceId, auditBody) {
|
|
82
71
|
const payload = {
|
|
83
72
|
eventType: Event_1.DT_EVENT_TYPES.DEVICE.DELETE.SUCCESS,
|
|
84
|
-
properties: {
|
|
85
|
-
deviceId,
|
|
86
|
-
},
|
|
73
|
+
properties: (0, AuditUtils_1.buildAuditProperties)({ ...auditBody, deviceId }),
|
|
87
74
|
};
|
|
88
75
|
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
89
76
|
}
|
|
90
|
-
async onStateChange(deviceId, state) {
|
|
91
|
-
// TODO: For Future Consumption
|
|
92
|
-
/* await eventDispatcher.publishEvent(
|
|
93
|
-
DT_EVENT_TYPES.DEVICE.STATE.SET,
|
|
94
|
-
{ deviceId, state },
|
|
95
|
-
this.source
|
|
96
|
-
); */
|
|
77
|
+
async onStateChange(deviceId, state, auditProperties) {
|
|
97
78
|
const payload = {
|
|
98
79
|
eventType: Event_1.DT_EVENT_TYPES.DEVICE.STATE.SET,
|
|
99
|
-
properties: {
|
|
100
|
-
deviceId,
|
|
101
|
-
state,
|
|
102
|
-
},
|
|
80
|
+
properties: (0, AuditUtils_1.buildAuditProperties)({ ...auditProperties, deviceId, ...state }),
|
|
103
81
|
};
|
|
104
82
|
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
105
83
|
}
|
|
106
|
-
async onStatusChange(deviceId, status) {
|
|
107
|
-
// TODO: For Future Consumption
|
|
108
|
-
/* await eventDispatcher.publishEvent(
|
|
109
|
-
DT_EVENT_TYPES.DEVICE.STATUS.SET,
|
|
110
|
-
{ deviceId, status },
|
|
111
|
-
this.source
|
|
112
|
-
); */
|
|
84
|
+
async onStatusChange(deviceId, status, auditProperties) {
|
|
113
85
|
const payload = {
|
|
114
86
|
eventType: Event_1.DT_EVENT_TYPES.DEVICE.STATUS.SET,
|
|
115
|
-
properties: {
|
|
116
|
-
deviceId,
|
|
117
|
-
status,
|
|
118
|
-
},
|
|
87
|
+
properties: (0, AuditUtils_1.buildAuditProperties)({ ...auditProperties, deviceId, ...status }),
|
|
119
88
|
};
|
|
120
89
|
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
121
90
|
}
|
|
122
|
-
async onBatteryLevelChange(deviceId, batteryLevel) {
|
|
123
|
-
// TODO: For Future Consumption
|
|
124
|
-
/* await eventDispatcher.publishEvent(
|
|
125
|
-
DT_EVENT_TYPES.DEVICE.BATTERY.SET,
|
|
126
|
-
{ deviceId, batteryLevel },
|
|
127
|
-
this.source
|
|
128
|
-
); */
|
|
91
|
+
async onBatteryLevelChange(deviceId, batteryLevel, auditProperties) {
|
|
129
92
|
const payload = {
|
|
130
93
|
eventType: Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.SET,
|
|
131
|
-
properties: {
|
|
94
|
+
properties: (0, AuditUtils_1.buildAuditProperties)({
|
|
95
|
+
...auditProperties,
|
|
132
96
|
deviceId,
|
|
133
97
|
batteryLevel,
|
|
134
|
-
},
|
|
98
|
+
}),
|
|
135
99
|
};
|
|
136
100
|
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
137
101
|
}
|
|
138
|
-
async onDeviceMetaChange(deviceId, metaData) {
|
|
139
|
-
// TODO: For Future Consumption
|
|
140
|
-
/* await eventDispatcher.publishEvent(
|
|
141
|
-
DT_EVENT_TYPES.DEVICE.META_DATA.SET,
|
|
142
|
-
{ deviceId, metaData },
|
|
143
|
-
this.source
|
|
144
|
-
); */
|
|
102
|
+
async onDeviceMetaChange(deviceId, metaData, auditProperties) {
|
|
145
103
|
const payload = {
|
|
146
104
|
eventType: Event_1.DT_EVENT_TYPES.DEVICE.META_DATA.SET,
|
|
147
|
-
properties: {
|
|
148
|
-
deviceId,
|
|
149
|
-
metaData,
|
|
150
|
-
},
|
|
105
|
+
properties: (0, AuditUtils_1.buildAuditProperties)({ ...auditProperties, deviceId, metaData }),
|
|
151
106
|
};
|
|
152
107
|
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
153
108
|
}
|
|
@@ -23,7 +23,7 @@ export declare class EventProcessingService {
|
|
|
23
23
|
/**
|
|
24
24
|
* Transform device event using EventTransformerFactory
|
|
25
25
|
*/
|
|
26
|
-
transformDeviceEventWithTransformer(connectionProvider: string, rawData: any): DeviceEvent | null
|
|
26
|
+
transformDeviceEventWithTransformer(connectionProvider: string, rawData: any): Promise<DeviceEvent | null>;
|
|
27
27
|
/**
|
|
28
28
|
* Transform raw event data to DeviceEvent format using EventTransformer
|
|
29
29
|
*/
|
|
@@ -95,7 +95,7 @@ let EventProcessingService = (() => {
|
|
|
95
95
|
/**
|
|
96
96
|
* Transform device event using EventTransformerFactory
|
|
97
97
|
*/
|
|
98
|
-
transformDeviceEventWithTransformer(connectionProvider, rawData) {
|
|
98
|
+
async transformDeviceEventWithTransformer(connectionProvider, rawData) {
|
|
99
99
|
try {
|
|
100
100
|
// Create transformer for the connection provider
|
|
101
101
|
const transformer = this.deviceEventTransformerFactory.createTransformer(connectionProvider, rawData);
|
|
@@ -104,7 +104,7 @@ let EventProcessingService = (() => {
|
|
|
104
104
|
return null;
|
|
105
105
|
}
|
|
106
106
|
// Execute the transformation pipeline
|
|
107
|
-
const transformedEvents = transformer.executeTransformation();
|
|
107
|
+
const transformedEvents = await transformer.executeTransformation();
|
|
108
108
|
if (transformedEvents.length === 0) {
|
|
109
109
|
this.logger.warn(`No events transformed for connection provider: ${connectionProvider}`);
|
|
110
110
|
return null;
|
|
@@ -120,10 +120,10 @@ let EventProcessingService = (() => {
|
|
|
120
120
|
/**
|
|
121
121
|
* Transform raw event data to DeviceEvent format using EventTransformer
|
|
122
122
|
*/
|
|
123
|
-
transformToDeviceEvent(connectionProvider, rawData) {
|
|
123
|
+
async transformToDeviceEvent(connectionProvider, rawData) {
|
|
124
124
|
try {
|
|
125
125
|
// Use the transformer-based approach
|
|
126
|
-
const deviceEvent = this.transformDeviceEventWithTransformer(connectionProvider, rawData);
|
|
126
|
+
const deviceEvent = await this.transformDeviceEventWithTransformer(connectionProvider, rawData);
|
|
127
127
|
if (!deviceEvent) {
|
|
128
128
|
this.logger.warn("Failed to transform event data using transformer", {
|
|
129
129
|
connectionProvider,
|
|
@@ -154,7 +154,7 @@ let EventProcessingService = (() => {
|
|
|
154
154
|
eventName: rawData.eventName ?? rawData.type,
|
|
155
155
|
});
|
|
156
156
|
// Transform raw data to DeviceEvent using EventTransformer
|
|
157
|
-
const deviceEvent = this.transformToDeviceEvent(connectionProvider, rawData);
|
|
157
|
+
const deviceEvent = await this.transformToDeviceEvent(connectionProvider, rawData);
|
|
158
158
|
if (!deviceEvent) {
|
|
159
159
|
this.logger.warn("Failed to transform event data", {
|
|
160
160
|
connectionProvider,
|
|
@@ -3,10 +3,10 @@ export interface DeviceEvent {
|
|
|
3
3
|
deviceId: string;
|
|
4
4
|
eventName: string;
|
|
5
5
|
data: DeviceEventData;
|
|
6
|
-
timestamp
|
|
7
|
-
connectionProvider
|
|
8
|
-
originalEventName
|
|
9
|
-
rawEvent
|
|
6
|
+
timestamp: string;
|
|
7
|
+
connectionProvider: string;
|
|
8
|
+
originalEventName: string;
|
|
9
|
+
rawEvent: any;
|
|
10
10
|
}
|
|
11
11
|
export interface EventConstructionOptions {
|
|
12
12
|
eventId?: string;
|
|
@@ -30,6 +30,10 @@ export interface DeviceEventEntity {
|
|
|
30
30
|
export interface DeviceEventData {
|
|
31
31
|
mode?: string;
|
|
32
32
|
batteryLevel?: number;
|
|
33
|
+
deviceName?: string;
|
|
34
|
+
propertyId?: string;
|
|
35
|
+
propertyName?: string;
|
|
36
|
+
[key: string]: any;
|
|
33
37
|
}
|
|
34
38
|
export interface TTLockEventData extends DeviceEventData {
|
|
35
39
|
label: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DeviceEvent } from "./DeviceEvent";
|
|
2
2
|
export interface IEventTransformer {
|
|
3
3
|
parseData(rawData: any): any;
|
|
4
|
-
transform(parsedData: any): DeviceEvent | DeviceEvent[]
|
|
4
|
+
transform(parsedData: any): Promise<DeviceEvent | DeviceEvent[]>;
|
|
5
5
|
validate(transformedEvent: DeviceEvent): boolean;
|
|
6
|
-
executeTransformation(): DeviceEvent[]
|
|
6
|
+
executeTransformation(): Promise<DeviceEvent[]>;
|
|
7
7
|
}
|
|
@@ -40,9 +40,13 @@ export declare class IssueService {
|
|
|
40
40
|
*/
|
|
41
41
|
createDeviceOfflineIssue(device: IDevice, source: Source, reason?: string): Promise<IIssueDocument>;
|
|
42
42
|
/**
|
|
43
|
-
* Create issue for device battery level below threshold
|
|
43
|
+
* Create issue for device battery level below threshold (READINESS + OPERATIONAL + ENERGY)
|
|
44
44
|
*/
|
|
45
45
|
createDeviceBatteryIssue(device: IDevice, batteryLevel: number, threshold: number, source: Source): Promise<IIssueDocument>;
|
|
46
|
+
/**
|
|
47
|
+
* Create issue for device malfunction (jammed or not accepting codes) (READINESS + OPERATIONAL)
|
|
48
|
+
*/
|
|
49
|
+
createDeviceMalfunctionIssue(device: IDevice, issueType: string, source: Source, reason?: string): Promise<IIssueDocument>;
|
|
46
50
|
/**
|
|
47
51
|
* Create a maintenance issue using IssueBuilder
|
|
48
52
|
*/
|
|
@@ -189,11 +189,17 @@ let IssueService = (() => {
|
|
|
189
189
|
return await this.createDeviceIssue(device.deviceId, device.propertyId, "Device Offline - Requires Attention", `Device ${device.name} (${device.deviceId}) has been offline for longer than the baseline time. ${reason ? `Reason: ${reason}` : ""} This requires immediate attention to restore device functionality.`, source, issue_types_1.IssuesCategory.OPERATIONS, issue_types_1.IssuePriority.HIGH);
|
|
190
190
|
}
|
|
191
191
|
/**
|
|
192
|
-
* Create issue for device battery level below threshold
|
|
192
|
+
* Create issue for device battery level below threshold (READINESS + OPERATIONAL + ENERGY)
|
|
193
193
|
*/
|
|
194
194
|
async createDeviceBatteryIssue(device, batteryLevel, threshold, source) {
|
|
195
195
|
return await this.createDeviceIssue(device.deviceId, device.propertyId, "Device Battery Low - Requires Attention", `Device ${device.name} (${device.deviceId}) battery level is ${batteryLevel}%, which is below the property threshold of ${threshold}%. This requires immediate attention to replace or charge the device battery.`, source, issue_types_1.IssuesCategory.ENERGY, issue_types_1.IssuePriority.MEDIUM);
|
|
196
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Create issue for device malfunction (jammed or not accepting codes) (READINESS + OPERATIONAL)
|
|
199
|
+
*/
|
|
200
|
+
async createDeviceMalfunctionIssue(device, issueType, source, reason) {
|
|
201
|
+
return await this.createDeviceIssue(device.deviceId, device.propertyId, `Device Malfunction - ${issueType} - Requires Attention`, `Device ${device.name} (${device.deviceId}) has a malfunction: ${issueType}. ${reason ? `Reason: ${reason}` : ""} This requires immediate attention to resolve the device malfunction.`, source, issue_types_1.IssuesCategory.OPERATIONS, issue_types_1.IssuePriority.HIGH);
|
|
202
|
+
}
|
|
197
203
|
/**
|
|
198
204
|
* Create a maintenance issue using IssueBuilder
|
|
199
205
|
*/
|
|
@@ -31,6 +31,26 @@ export declare class RedisUtils {
|
|
|
31
31
|
* @returns The number of fields deleted
|
|
32
32
|
*/
|
|
33
33
|
hdel(key: string, ...fields: string[]): Promise<number>;
|
|
34
|
+
/**
|
|
35
|
+
* Set a value in Redis with a TTL
|
|
36
|
+
* @param key - The key to set
|
|
37
|
+
* @param value - The value to set (JSON stringified)
|
|
38
|
+
* @param ttl - The TTL in seconds
|
|
39
|
+
* @returns The value
|
|
40
|
+
*/
|
|
41
|
+
set(key: string, value: string, ttl: number): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Get a value from Redis
|
|
44
|
+
* @param key - The key to get
|
|
45
|
+
* @returns The value
|
|
46
|
+
*/
|
|
47
|
+
get(key: string): Promise<string | null>;
|
|
48
|
+
/**
|
|
49
|
+
* Delete a key from Redis
|
|
50
|
+
* @param key - The key to delete
|
|
51
|
+
* @returns The number of keys deleted
|
|
52
|
+
*/
|
|
53
|
+
del(key: string): Promise<number>;
|
|
34
54
|
/**
|
|
35
55
|
* Check if a key exists
|
|
36
56
|
* @param key - The key to check
|
|
@@ -44,4 +64,5 @@ export declare class RedisUtils {
|
|
|
44
64
|
* @returns 1 if the expiration was set, 0 if the key does not exist
|
|
45
65
|
*/
|
|
46
66
|
expire(key: string, seconds: number): Promise<any>;
|
|
67
|
+
hgetAll(key: string): Promise<any>;
|
|
47
68
|
}
|
|
@@ -113,6 +113,32 @@ let RedisUtils = (() => {
|
|
|
113
113
|
async hdel(key, ...fields) {
|
|
114
114
|
return await this.client.hdel(key, ...fields);
|
|
115
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Set a value in Redis with a TTL
|
|
118
|
+
* @param key - The key to set
|
|
119
|
+
* @param value - The value to set (JSON stringified)
|
|
120
|
+
* @param ttl - The TTL in seconds
|
|
121
|
+
* @returns The value
|
|
122
|
+
*/
|
|
123
|
+
async set(key, value, ttl) {
|
|
124
|
+
return await this.client.set(key, value, "EX", ttl);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get a value from Redis
|
|
128
|
+
* @param key - The key to get
|
|
129
|
+
* @returns The value
|
|
130
|
+
*/
|
|
131
|
+
async get(key) {
|
|
132
|
+
return await this.client.get(key);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Delete a key from Redis
|
|
136
|
+
* @param key - The key to delete
|
|
137
|
+
* @returns The number of keys deleted
|
|
138
|
+
*/
|
|
139
|
+
async del(key) {
|
|
140
|
+
return await this.client.del(key);
|
|
141
|
+
}
|
|
116
142
|
/**
|
|
117
143
|
* Check if a key exists
|
|
118
144
|
* @param key - The key to check
|
|
@@ -142,6 +168,15 @@ let RedisUtils = (() => {
|
|
|
142
168
|
throw error;
|
|
143
169
|
}
|
|
144
170
|
}
|
|
171
|
+
async hgetAll(key) {
|
|
172
|
+
try {
|
|
173
|
+
return await this.client.hgetall(key);
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
console.error(`Error getting all values for key ${key}:`, error);
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
145
180
|
};
|
|
146
181
|
__setFunctionName(_classThis, "RedisUtils");
|
|
147
182
|
(() => {
|