dt-common-device 5.0.4 → 5.1.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.
- package/dist/alerts/Alert.model.d.ts +1 -1
- package/dist/audit/AuditUtils.d.ts +1 -1
- package/dist/audit/AuditUtils.js +13 -8
- package/dist/config/config.js +10 -34
- package/dist/config/constants.d.ts +6 -6
- package/dist/config/constants.js +18 -19
- package/dist/constants/Event.d.ts +80 -14
- package/dist/constants/Event.js +84 -18
- package/dist/entities/device/local/repository/Device.repository.js +0 -5
- package/dist/entities/device/local/services/Device.service.d.ts +1 -1
- package/dist/entities/device/local/services/Device.service.js +13 -8
- package/dist/entities/property/Property.repository.js +0 -1
- package/dist/events/BaseEventHandler.d.ts +1 -1
- package/dist/events/BaseEventHandler.js +2 -2
- package/dist/events/DeviceEventHandler.js +7 -7
- package/dist/events/EventHandler.d.ts +5 -7
- package/dist/events/EventHandler.js +133 -101
- package/dist/issues/Issue.model.d.ts +1 -1
- package/dist/utils/redis.utils.d.ts +5 -0
- package/dist/utils/redis.utils.js +5 -0
- package/package.json +2 -2
|
@@ -18,7 +18,7 @@ interface IAlertModel extends Model<IAlertDocument, {}, IAlertMethods> {
|
|
|
18
18
|
findSnoozed(includeDeleted?: boolean): Promise<IAlertDocument[]>;
|
|
19
19
|
findExpiredSnooze(includeDeleted?: boolean): Promise<IAlertDocument[]>;
|
|
20
20
|
}
|
|
21
|
-
declare const AlertSchema: mongoose.Schema<IAlertDocument, IAlertModel, IAlertMethods, {}, {}, {}, mongoose.DefaultSchemaOptions, IAlertDocument, mongoose.Document<unknown, {}, mongoose.FlatRecord<IAlertDocument>, {}
|
|
21
|
+
declare const AlertSchema: mongoose.Schema<IAlertDocument, IAlertModel, IAlertMethods, {}, {}, {}, mongoose.DefaultSchemaOptions, IAlertDocument, mongoose.Document<unknown, {}, mongoose.FlatRecord<IAlertDocument>, {}, mongoose.ResolveSchemaOptions<mongoose.DefaultSchemaOptions>> & Omit<mongoose.FlatRecord<IAlertDocument> & Required<{
|
|
22
22
|
_id: string;
|
|
23
23
|
}> & {
|
|
24
24
|
__v: number;
|
package/dist/audit/AuditUtils.js
CHANGED
|
@@ -139,17 +139,22 @@ let AuditUtils = (() => {
|
|
|
139
139
|
if (propertyId && !propertyName)
|
|
140
140
|
audit.propertyName = await this.getPropertyName(propertyId);
|
|
141
141
|
if (!propertyId && deviceId) {
|
|
142
|
-
audit.propertyId = await this.
|
|
142
|
+
audit.propertyId = await this.getFieldFromDevice(deviceId, "propertyId");
|
|
143
143
|
audit.propertyName = await this.getPropertyName(audit.propertyId);
|
|
144
144
|
}
|
|
145
|
+
if (zoneId && !zoneName)
|
|
146
|
+
audit.zoneName = await this.getZoneName(zoneId);
|
|
147
|
+
if (!zoneId && deviceId) {
|
|
148
|
+
audit.zoneId = await this.getFieldFromDevice(deviceId, "zoneId");
|
|
149
|
+
audit.zoneName = await this.getZoneName(audit.zoneId);
|
|
150
|
+
}
|
|
145
151
|
if (userId && !userName)
|
|
146
152
|
audit.userName = await this.getUserName(userId);
|
|
147
153
|
if (guestId && !guestName)
|
|
148
154
|
audit.guestName = await this.getGuestName(guestId);
|
|
149
|
-
if (deviceId && !deviceName)
|
|
155
|
+
if (deviceId && !deviceName) {
|
|
150
156
|
audit.deviceName = await this.getDeviceName(deviceId);
|
|
151
|
-
|
|
152
|
-
audit.zoneName = await this.getZoneName(zoneId);
|
|
157
|
+
}
|
|
153
158
|
if (accessGroupId && !accessGroupName)
|
|
154
159
|
audit.accessGroupName = await this.getAccessGroupName(accessGroupId);
|
|
155
160
|
if (scheduleId) {
|
|
@@ -189,17 +194,17 @@ let AuditUtils = (() => {
|
|
|
189
194
|
return property?.name || "";
|
|
190
195
|
});
|
|
191
196
|
}
|
|
192
|
-
async
|
|
197
|
+
async getFieldFromDevice(deviceId, field) {
|
|
193
198
|
const redisKey = `device:${deviceId}`;
|
|
194
199
|
const redisDevice = await this.redisUtils.hget(redisKey, "device");
|
|
195
200
|
if (redisDevice) {
|
|
196
|
-
return
|
|
201
|
+
return redisDevice[field];
|
|
197
202
|
}
|
|
198
203
|
else {
|
|
199
204
|
const device = await typedi_1.default.get(services_1.LocalDeviceService).getDevice(deviceId);
|
|
200
205
|
await this.redisUtils.hset(redisKey, "device", JSON.stringify(device));
|
|
201
206
|
await this.redisUtils.expire(redisKey, this.CACHE_TTL);
|
|
202
|
-
return device
|
|
207
|
+
return device[field];
|
|
203
208
|
}
|
|
204
209
|
}
|
|
205
210
|
async getUserName(userId) {
|
|
@@ -217,7 +222,7 @@ let AuditUtils = (() => {
|
|
|
217
222
|
async getDeviceName(deviceId) {
|
|
218
223
|
return this.getCachedEntityData("device", deviceId, async () => {
|
|
219
224
|
const device = await typedi_1.default.get(services_1.LocalDeviceService).querySelect({ deviceId }, ["name"]);
|
|
220
|
-
return device?.name || "";
|
|
225
|
+
return device[0]?.name || "";
|
|
221
226
|
});
|
|
222
227
|
}
|
|
223
228
|
async getZoneName(zoneId) {
|
package/dist/config/config.js
CHANGED
|
@@ -32,33 +32,33 @@ let db_keys = null;
|
|
|
32
32
|
let sourceKey = null;
|
|
33
33
|
async function initialize(cfg) {
|
|
34
34
|
// Check if required env variables are set
|
|
35
|
-
checkRequiredEnv(constants_1.
|
|
35
|
+
checkRequiredEnv(constants_1.REQUIRED.env);
|
|
36
36
|
// Initialize config
|
|
37
37
|
config = { ...cfg };
|
|
38
38
|
if (cfg.SOURCE === "ADMIN_SERVICE") {
|
|
39
39
|
sourceKey = "ADMIN";
|
|
40
40
|
db_keys = constants_1.CONFIG_KEYS.ADMIN.db_keys;
|
|
41
|
-
await
|
|
41
|
+
await validateServiceConfig(cfg);
|
|
42
42
|
}
|
|
43
43
|
if (cfg.SOURCE === "ACCESS_SERVICE") {
|
|
44
44
|
sourceKey = "ACCESS";
|
|
45
45
|
db_keys = constants_1.CONFIG_KEYS.ACCESS.db_keys;
|
|
46
|
-
await
|
|
46
|
+
await validateServiceConfig(cfg);
|
|
47
47
|
}
|
|
48
48
|
if (cfg.SOURCE === "SCHEDULE_SERVICE") {
|
|
49
49
|
sourceKey = "SCHEDULE";
|
|
50
50
|
db_keys = constants_1.CONFIG_KEYS.SCHEDULE.db_keys;
|
|
51
|
-
await
|
|
51
|
+
await validateServiceConfig(cfg);
|
|
52
52
|
}
|
|
53
53
|
if (cfg.SOURCE === "ENERGY_SERVICE") {
|
|
54
54
|
sourceKey = "ENERGY";
|
|
55
55
|
db_keys = constants_1.CONFIG_KEYS.ENERGY.db_keys;
|
|
56
|
-
await
|
|
56
|
+
await validateServiceConfig(cfg);
|
|
57
57
|
}
|
|
58
58
|
if (cfg.SOURCE === "REMOTE_SERVICE") {
|
|
59
59
|
sourceKey = "REMOTE";
|
|
60
60
|
db_keys = constants_1.CONFIG_KEYS.REMOTE.db_keys;
|
|
61
|
-
await
|
|
61
|
+
await validateServiceConfig(cfg);
|
|
62
62
|
}
|
|
63
63
|
// Connect to databases
|
|
64
64
|
try {
|
|
@@ -82,7 +82,7 @@ async function initialize(cfg) {
|
|
|
82
82
|
}
|
|
83
83
|
// Initialize audit
|
|
84
84
|
ensureAuditInitialized();
|
|
85
|
-
|
|
85
|
+
cfg.LOGGER.info("dt-common-device: Initialization completed successfully");
|
|
86
86
|
}
|
|
87
87
|
async function validateInternalEventHandler(cfg) {
|
|
88
88
|
// Initialize internal event subscription if handler is provided
|
|
@@ -99,33 +99,9 @@ async function validateInternalEventHandler(cfg) {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
|
-
async function
|
|
103
|
-
checkRequiredEnv(constants_1.CONFIG_KEYS.
|
|
104
|
-
if (constants_1.CONFIG_KEYS.
|
|
105
|
-
await validateInternalEventHandler(cfg);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
async function validateAccessConfig(cfg) {
|
|
109
|
-
checkRequiredEnv(constants_1.CONFIG_KEYS.ACCESS.env);
|
|
110
|
-
if (constants_1.CONFIG_KEYS.ACCESS.INTERNAL_EVENT_HANDLER) {
|
|
111
|
-
await validateInternalEventHandler(cfg);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
async function validateEnergyConfig(cfg) {
|
|
115
|
-
checkRequiredEnv(constants_1.CONFIG_KEYS.ENERGY.env);
|
|
116
|
-
if (constants_1.CONFIG_KEYS.ENERGY.INTERNAL_EVENT_HANDLER) {
|
|
117
|
-
await validateInternalEventHandler(cfg);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
async function validateRemoteConfig(cfg) {
|
|
121
|
-
checkRequiredEnv(constants_1.CONFIG_KEYS.REMOTE.env);
|
|
122
|
-
if (constants_1.CONFIG_KEYS.REMOTE.INTERNAL_EVENT_HANDLER) {
|
|
123
|
-
await validateInternalEventHandler(cfg);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
async function validateScheduleConfig(cfg) {
|
|
127
|
-
checkRequiredEnv(constants_1.CONFIG_KEYS.SCHEDULE.env);
|
|
128
|
-
if (constants_1.CONFIG_KEYS.SCHEDULE.INTERNAL_EVENT_HANDLER) {
|
|
102
|
+
async function validateServiceConfig(cfg) {
|
|
103
|
+
checkRequiredEnv(constants_1.CONFIG_KEYS[sourceKey].env);
|
|
104
|
+
if (constants_1.CONFIG_KEYS[sourceKey].INTERNAL_EVENT_HANDLER) {
|
|
129
105
|
await validateInternalEventHandler(cfg);
|
|
130
106
|
}
|
|
131
107
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
export declare const REQUIRED: {
|
|
2
|
+
env: string[];
|
|
3
|
+
};
|
|
1
4
|
export declare const CONFIG_KEYS: {
|
|
2
|
-
REQUIRED: {
|
|
3
|
-
env: string[];
|
|
4
|
-
};
|
|
5
5
|
ACCESS: {
|
|
6
6
|
env: string[];
|
|
7
7
|
INTERNAL_EVENT_HANDLER: boolean;
|
|
8
8
|
db_keys: {
|
|
9
|
-
|
|
9
|
+
access: string;
|
|
10
10
|
admin: string;
|
|
11
11
|
pms: string;
|
|
12
12
|
};
|
|
@@ -15,7 +15,7 @@ export declare const CONFIG_KEYS: {
|
|
|
15
15
|
env: string[];
|
|
16
16
|
INTERNAL_EVENT_HANDLER: boolean;
|
|
17
17
|
db_keys: {
|
|
18
|
-
|
|
18
|
+
admin: string;
|
|
19
19
|
access: string;
|
|
20
20
|
pms: string;
|
|
21
21
|
};
|
|
@@ -24,7 +24,7 @@ export declare const CONFIG_KEYS: {
|
|
|
24
24
|
env: string[];
|
|
25
25
|
INTERNAL_EVENT_HANDLER: boolean;
|
|
26
26
|
db_keys: {
|
|
27
|
-
|
|
27
|
+
energy: string;
|
|
28
28
|
admin: string;
|
|
29
29
|
pms: string;
|
|
30
30
|
};
|
package/dist/config/constants.js
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CONFIG_KEYS = void 0;
|
|
3
|
+
exports.CONFIG_KEYS = exports.REQUIRED = void 0;
|
|
4
|
+
exports.REQUIRED = {
|
|
5
|
+
env: [
|
|
6
|
+
"AWS_SECRET_ACCESS_KEY",
|
|
7
|
+
"AWS_REGION",
|
|
8
|
+
"AWS_ACCESS_KEY_ID",
|
|
9
|
+
"EVENT_BUS_NAME",
|
|
10
|
+
"REDIS_HOST",
|
|
11
|
+
"REDIS_PORT",
|
|
12
|
+
"POSTHOG_API_KEY",
|
|
13
|
+
"POSTHOG_HOST",
|
|
14
|
+
"DEVICE_SERVICE",
|
|
15
|
+
"DT_API_KEY",
|
|
16
|
+
],
|
|
17
|
+
};
|
|
4
18
|
exports.CONFIG_KEYS = {
|
|
5
|
-
REQUIRED: {
|
|
6
|
-
env: [
|
|
7
|
-
"AWS_SECRET_ACCESS_KEY",
|
|
8
|
-
"AWS_REGION",
|
|
9
|
-
"AWS_ACCESS_KEY_ID",
|
|
10
|
-
"EVENT_BUS_NAME",
|
|
11
|
-
"MONGODB_URI",
|
|
12
|
-
"REDIS_HOST",
|
|
13
|
-
"REDIS_PORT",
|
|
14
|
-
"POSTHOG_API_KEY",
|
|
15
|
-
"POSTHOG_HOST",
|
|
16
|
-
"DEVICE_SERVICE",
|
|
17
|
-
"DT_API_KEY",
|
|
18
|
-
],
|
|
19
|
-
},
|
|
20
19
|
ACCESS: {
|
|
21
20
|
env: ["ADMIN_DB_URI", "PMS_DB_URI", "AWS_SQS_URL", "ADMIN_SERVICE"],
|
|
22
21
|
INTERNAL_EVENT_HANDLER: true,
|
|
23
22
|
db_keys: {
|
|
24
|
-
|
|
23
|
+
access: "DATABASE_URL",
|
|
25
24
|
admin: "ADMIN_DB_URI",
|
|
26
25
|
pms: "PMS_DB_URI",
|
|
27
26
|
},
|
|
@@ -30,7 +29,7 @@ exports.CONFIG_KEYS = {
|
|
|
30
29
|
env: ["ACCESS_DB_URI", "PMS_DB_URI"],
|
|
31
30
|
INTERNAL_EVENT_HANDLER: false,
|
|
32
31
|
db_keys: {
|
|
33
|
-
|
|
32
|
+
admin: "DATABASE_URL",
|
|
34
33
|
access: "ACCESS_DB_URI",
|
|
35
34
|
pms: "PMS_DB_URI",
|
|
36
35
|
},
|
|
@@ -39,7 +38,7 @@ exports.CONFIG_KEYS = {
|
|
|
39
38
|
env: ["ADMIN_DB_URI", "PMS_DB_URI", "AWS_SQS_URL"],
|
|
40
39
|
INTERNAL_EVENT_HANDLER: true,
|
|
41
40
|
db_keys: {
|
|
42
|
-
|
|
41
|
+
energy: "DATABASE_URL",
|
|
43
42
|
admin: "ADMIN_DB_URI",
|
|
44
43
|
pms: "PMS_DB_URI",
|
|
45
44
|
},
|
|
@@ -1,43 +1,55 @@
|
|
|
1
1
|
export declare const DT_EVENT_TYPES: {
|
|
2
2
|
DEVICE: {
|
|
3
3
|
CREATE: {
|
|
4
|
+
ATTEMPT: string;
|
|
4
5
|
SUCCESS: string;
|
|
5
6
|
FAILED: string;
|
|
6
7
|
};
|
|
7
8
|
UPDATE: {
|
|
9
|
+
ATTEMPT: string;
|
|
8
10
|
SUCCESS: string;
|
|
9
11
|
FAILED: string;
|
|
10
12
|
};
|
|
11
13
|
DELETE: {
|
|
14
|
+
ATTEMPT: string;
|
|
15
|
+
SUCCESS: string;
|
|
16
|
+
FAILED: string;
|
|
17
|
+
};
|
|
18
|
+
ZONE: {
|
|
19
|
+
UPDATE: {
|
|
20
|
+
ATTEMPT: string;
|
|
21
|
+
SUCCESS: string;
|
|
22
|
+
FAILED: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
REFRESH: {
|
|
26
|
+
ATTEMPT: string;
|
|
12
27
|
SUCCESS: string;
|
|
13
28
|
FAILED: string;
|
|
14
29
|
};
|
|
15
30
|
STATE: {
|
|
16
|
-
SET: string;
|
|
17
|
-
UNKNOWN: string;
|
|
18
|
-
UPDATED: string;
|
|
19
31
|
CHANGED: string;
|
|
20
32
|
};
|
|
21
33
|
STATUS: {
|
|
22
|
-
SET: string;
|
|
23
34
|
ONLINE: string;
|
|
24
35
|
OFFLINE: string;
|
|
25
36
|
UNKNOWN: string;
|
|
26
|
-
UPDATED: string;
|
|
27
|
-
CHANGED: string;
|
|
28
37
|
};
|
|
29
38
|
BATTERY: {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
39
|
+
REPLACED: string;
|
|
40
|
+
LEVEL: {
|
|
41
|
+
UNKNOWN: string;
|
|
42
|
+
NORMAL: string;
|
|
43
|
+
LOW: string;
|
|
44
|
+
CRITICAL: string;
|
|
45
|
+
UPDATED: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
METADATA: {
|
|
34
49
|
UPDATED: string;
|
|
35
|
-
CHANGED: string;
|
|
36
50
|
};
|
|
37
|
-
|
|
38
|
-
SET: string;
|
|
51
|
+
NAME: {
|
|
39
52
|
UPDATED: string;
|
|
40
|
-
CHANGED: string;
|
|
41
53
|
};
|
|
42
54
|
EVENT: {
|
|
43
55
|
RECEIVED: string;
|
|
@@ -45,6 +57,7 @@ export declare const DT_EVENT_TYPES: {
|
|
|
45
57
|
UNREGISTERED: string;
|
|
46
58
|
PROCESSED: string;
|
|
47
59
|
UNPROCESSED: string;
|
|
60
|
+
UNHANDLED: string;
|
|
48
61
|
};
|
|
49
62
|
WEBHOOK: {
|
|
50
63
|
RECEIVED: string;
|
|
@@ -52,38 +65,91 @@ export declare const DT_EVENT_TYPES: {
|
|
|
52
65
|
UNREGISTERED: string;
|
|
53
66
|
PROCESSED: string;
|
|
54
67
|
UNPROCESSED: string;
|
|
68
|
+
UNHANDLED: string;
|
|
55
69
|
};
|
|
56
70
|
};
|
|
57
71
|
CONNECTION: {
|
|
58
72
|
CREATE: {
|
|
73
|
+
ATTEMPT: string;
|
|
59
74
|
SUCCESS: string;
|
|
60
75
|
FAILED: string;
|
|
61
76
|
};
|
|
62
77
|
UPDATE: {
|
|
78
|
+
ATTEMPT: string;
|
|
63
79
|
SUCCESS: string;
|
|
64
80
|
FAILED: string;
|
|
65
81
|
};
|
|
66
82
|
DELETE: {
|
|
83
|
+
ATTEMPT: string;
|
|
84
|
+
SUCCESS: string;
|
|
85
|
+
FAILED: string;
|
|
86
|
+
};
|
|
87
|
+
TOKEN_REFRESH: {
|
|
88
|
+
ATTEMPT: string;
|
|
67
89
|
SUCCESS: string;
|
|
68
90
|
FAILED: string;
|
|
69
91
|
};
|
|
70
92
|
};
|
|
71
93
|
PROPERTY: {
|
|
72
94
|
CREATE: {
|
|
95
|
+
ATTEMPT: string;
|
|
73
96
|
SUCCESS: string;
|
|
74
97
|
FAILED: string;
|
|
75
98
|
};
|
|
76
99
|
UPDATE: {
|
|
100
|
+
ATTEMPT: string;
|
|
77
101
|
SUCCESS: string;
|
|
78
102
|
FAILED: string;
|
|
79
103
|
};
|
|
80
104
|
DELETE: {
|
|
105
|
+
ATTEMPT: string;
|
|
81
106
|
SUCCESS: string;
|
|
82
107
|
FAILED: string;
|
|
83
108
|
};
|
|
84
109
|
PREFERENCES: {
|
|
85
110
|
UPDATED: string;
|
|
111
|
+
};
|
|
112
|
+
PROFILE: {
|
|
113
|
+
UPDATED: string;
|
|
114
|
+
};
|
|
115
|
+
USER: {
|
|
116
|
+
ATTEMPT: string;
|
|
86
117
|
CREATED: string;
|
|
118
|
+
UPDATED: string;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
ACCESS_GROUP: {
|
|
122
|
+
CREATE: {
|
|
123
|
+
ATTEMPT: string;
|
|
124
|
+
SUCCESS: string;
|
|
125
|
+
FAILED: string;
|
|
126
|
+
};
|
|
127
|
+
UPDATE: {
|
|
128
|
+
ATTEMPT: string;
|
|
129
|
+
SUCCESS: string;
|
|
130
|
+
FAILED: string;
|
|
131
|
+
};
|
|
132
|
+
DELETE: {
|
|
133
|
+
ATTEMPT: string;
|
|
134
|
+
SUCCESS: string;
|
|
135
|
+
FAILED: string;
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
ZONE: {
|
|
139
|
+
CREATE: {
|
|
140
|
+
ATTEMPT: string;
|
|
141
|
+
SUCCESS: string;
|
|
142
|
+
FAILED: string;
|
|
143
|
+
};
|
|
144
|
+
UPDATE: {
|
|
145
|
+
ATTEMPT: string;
|
|
146
|
+
SUCCESS: string;
|
|
147
|
+
FAILED: string;
|
|
148
|
+
};
|
|
149
|
+
DELETE: {
|
|
150
|
+
ATTEMPT: string;
|
|
151
|
+
SUCCESS: string;
|
|
152
|
+
FAILED: string;
|
|
87
153
|
};
|
|
88
154
|
};
|
|
89
155
|
};
|
package/dist/constants/Event.js
CHANGED
|
@@ -4,43 +4,55 @@ exports.DT_EVENT_TYPES = void 0;
|
|
|
4
4
|
exports.DT_EVENT_TYPES = {
|
|
5
5
|
DEVICE: {
|
|
6
6
|
CREATE: {
|
|
7
|
+
ATTEMPT: "device.create.attempt",
|
|
7
8
|
SUCCESS: "device.create.success",
|
|
8
9
|
FAILED: "device.create.failed",
|
|
9
10
|
},
|
|
10
11
|
UPDATE: {
|
|
12
|
+
ATTEMPT: "device.update.attempt",
|
|
11
13
|
SUCCESS: "device.update.success",
|
|
12
14
|
FAILED: "device.update.failed",
|
|
13
15
|
},
|
|
14
16
|
DELETE: {
|
|
17
|
+
ATTEMPT: "device.delete.attempt",
|
|
15
18
|
SUCCESS: "device.delete.success",
|
|
16
19
|
FAILED: "device.delete.failed",
|
|
17
20
|
},
|
|
21
|
+
ZONE: {
|
|
22
|
+
UPDATE: {
|
|
23
|
+
ATTEMPT: "device.zone.update.attempt",
|
|
24
|
+
SUCCESS: "device.zone.update.success",
|
|
25
|
+
FAILED: "device.zone.update.failed",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
REFRESH: {
|
|
29
|
+
ATTEMPT: "device.refresh.attempt",
|
|
30
|
+
SUCCESS: "device.refresh.success",
|
|
31
|
+
FAILED: "device.refresh.failed",
|
|
32
|
+
},
|
|
18
33
|
STATE: {
|
|
19
|
-
SET: "device.state.set",
|
|
20
|
-
UNKNOWN: "device.state.unknown",
|
|
21
|
-
UPDATED: "device.state.updated",
|
|
22
34
|
CHANGED: "device.state.changed",
|
|
23
35
|
},
|
|
24
36
|
STATUS: {
|
|
25
|
-
SET: "device.status.set",
|
|
26
37
|
ONLINE: "device.status.online",
|
|
27
38
|
OFFLINE: "device.status.offline",
|
|
28
39
|
UNKNOWN: "device.status.unknown",
|
|
29
|
-
UPDATED: "device.status.updated",
|
|
30
|
-
CHANGED: "device.status.changed",
|
|
31
40
|
},
|
|
32
41
|
BATTERY: {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
REPLACED: "device.battery.replaced",
|
|
43
|
+
LEVEL: {
|
|
44
|
+
UNKNOWN: "device.battery.level.unknown",
|
|
45
|
+
NORMAL: "device.battery.level.normal",
|
|
46
|
+
LOW: "device.battery.level.low",
|
|
47
|
+
CRITICAL: "device.battery.level.critical",
|
|
48
|
+
UPDATED: "device.battery.level.updated",
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
METADATA: {
|
|
52
|
+
UPDATED: "device.metadata.updated",
|
|
53
|
+
},
|
|
54
|
+
NAME: {
|
|
55
|
+
UPDATED: "device.name.updated",
|
|
44
56
|
},
|
|
45
57
|
EVENT: {
|
|
46
58
|
RECEIVED: "device.event.received",
|
|
@@ -48,6 +60,7 @@ exports.DT_EVENT_TYPES = {
|
|
|
48
60
|
UNREGISTERED: "device.event.unregistered",
|
|
49
61
|
PROCESSED: "device.event.processed",
|
|
50
62
|
UNPROCESSED: "device.event.unprocessed",
|
|
63
|
+
UNHANDLED: "device.event.unhandled",
|
|
51
64
|
},
|
|
52
65
|
WEBHOOK: {
|
|
53
66
|
RECEIVED: "device.webhook.received",
|
|
@@ -55,38 +68,91 @@ exports.DT_EVENT_TYPES = {
|
|
|
55
68
|
UNREGISTERED: "device.webhook.unregistered",
|
|
56
69
|
PROCESSED: "device.webhook.processed",
|
|
57
70
|
UNPROCESSED: "device.webhook.unprocessed",
|
|
71
|
+
UNHANDLED: "device.webhook.unhandled",
|
|
58
72
|
},
|
|
59
73
|
},
|
|
60
74
|
CONNECTION: {
|
|
61
75
|
CREATE: {
|
|
76
|
+
ATTEMPT: "connection.create.attempt",
|
|
62
77
|
SUCCESS: "connection.create.success",
|
|
63
78
|
FAILED: "connection.create.failed",
|
|
64
79
|
},
|
|
65
80
|
UPDATE: {
|
|
81
|
+
ATTEMPT: "connection.update.attempt",
|
|
66
82
|
SUCCESS: "connection.update.success",
|
|
67
83
|
FAILED: "connection.update.failed",
|
|
68
84
|
},
|
|
69
85
|
DELETE: {
|
|
86
|
+
ATTEMPT: "connection.delete.attempt",
|
|
70
87
|
SUCCESS: "connection.delete.success",
|
|
71
88
|
FAILED: "connection.delete.failed",
|
|
72
89
|
},
|
|
90
|
+
TOKEN_REFRESH: {
|
|
91
|
+
ATTEMPT: "connection.token.refresh.attempt",
|
|
92
|
+
SUCCESS: "connection.token.refresh.success",
|
|
93
|
+
FAILED: "connection.token.refresh.failed",
|
|
94
|
+
},
|
|
73
95
|
},
|
|
74
96
|
PROPERTY: {
|
|
75
97
|
CREATE: {
|
|
98
|
+
ATTEMPT: "property.create.attempt",
|
|
76
99
|
SUCCESS: "property.create.success",
|
|
77
100
|
FAILED: "property.create.failed",
|
|
78
101
|
},
|
|
79
102
|
UPDATE: {
|
|
103
|
+
ATTEMPT: "property.update.attempt",
|
|
80
104
|
SUCCESS: "property.update.success",
|
|
81
105
|
FAILED: "property.update.failed",
|
|
82
106
|
},
|
|
83
107
|
DELETE: {
|
|
108
|
+
ATTEMPT: "property.delete.attempt",
|
|
84
109
|
SUCCESS: "property.delete.success",
|
|
85
110
|
FAILED: "property.delete.failed",
|
|
86
111
|
},
|
|
87
112
|
PREFERENCES: {
|
|
88
113
|
UPDATED: "property.preferences.updated",
|
|
89
|
-
|
|
114
|
+
},
|
|
115
|
+
PROFILE: {
|
|
116
|
+
UPDATED: "property.profile.updated",
|
|
117
|
+
},
|
|
118
|
+
USER: {
|
|
119
|
+
ATTEMPT: "property.user.attempt",
|
|
120
|
+
CREATED: "property.user.created",
|
|
121
|
+
UPDATED: "property.user.updated",
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
ACCESS_GROUP: {
|
|
125
|
+
CREATE: {
|
|
126
|
+
ATTEMPT: "accessgroup.create.attempt",
|
|
127
|
+
SUCCESS: "accessgroup.create.success",
|
|
128
|
+
FAILED: "accessgroup.create.failed",
|
|
129
|
+
},
|
|
130
|
+
UPDATE: {
|
|
131
|
+
ATTEMPT: "accessgroup.update.attempt",
|
|
132
|
+
SUCCESS: "accessgroup.update.success",
|
|
133
|
+
FAILED: "accessgroup.update.failed",
|
|
134
|
+
},
|
|
135
|
+
DELETE: {
|
|
136
|
+
ATTEMPT: "accessgroup.delete.attempt",
|
|
137
|
+
SUCCESS: "accessgroup.delete.success",
|
|
138
|
+
FAILED: "accessgroup.delete.failed",
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
ZONE: {
|
|
142
|
+
CREATE: {
|
|
143
|
+
ATTEMPT: "zone.create.attempt",
|
|
144
|
+
SUCCESS: "zone.create.success",
|
|
145
|
+
FAILED: "zone.create.failed",
|
|
146
|
+
},
|
|
147
|
+
UPDATE: {
|
|
148
|
+
ATTEMPT: "zone.update.attempt",
|
|
149
|
+
SUCCESS: "zone.update.success",
|
|
150
|
+
FAILED: "zone.update.failed",
|
|
151
|
+
},
|
|
152
|
+
DELETE: {
|
|
153
|
+
ATTEMPT: "zone.delete.attempt",
|
|
154
|
+
SUCCESS: "zone.delete.success",
|
|
155
|
+
FAILED: "zone.delete.failed",
|
|
90
156
|
},
|
|
91
157
|
},
|
|
92
158
|
};
|
|
@@ -144,7 +144,6 @@ let DeviceRepository = (() => {
|
|
|
144
144
|
async getState(deviceId) {
|
|
145
145
|
try {
|
|
146
146
|
const response = await this.axiosInstance.get(`/devices/${deviceId}/state`);
|
|
147
|
-
console.log("GetState response:------------", response.data);
|
|
148
147
|
return response.data;
|
|
149
148
|
}
|
|
150
149
|
catch (error) {
|
|
@@ -183,18 +182,14 @@ let DeviceRepository = (() => {
|
|
|
183
182
|
}
|
|
184
183
|
}
|
|
185
184
|
async setStatusMany(query, newStatus) {
|
|
186
|
-
console.log("SetStatusMany query:------------", query);
|
|
187
|
-
console.log("SetStatusMany newStatus:------------", newStatus);
|
|
188
185
|
try {
|
|
189
186
|
const response = await this.axiosInstance.put(`/devices/statusMany`, {
|
|
190
187
|
query,
|
|
191
188
|
status: newStatus,
|
|
192
189
|
});
|
|
193
|
-
console.log("SetStatusMany response:------------", response);
|
|
194
190
|
return response.data;
|
|
195
191
|
}
|
|
196
192
|
catch (error) {
|
|
197
|
-
console.log("SetStatusMany error:------------", error);
|
|
198
193
|
(0, config_1.getConfig)().LOGGER.error(`Failed to set status for multiple devices: ${error.message}`);
|
|
199
194
|
throw new Error(`Failed to set status for multiple devices: ${error.message}`);
|
|
200
195
|
}
|
|
@@ -17,7 +17,7 @@ export declare class LocalDeviceService {
|
|
|
17
17
|
updateDevices(query: any, updateData: any): Promise<any>;
|
|
18
18
|
deleteDevice(deviceId: string, auditBody: IAuditProperties): Promise<any>;
|
|
19
19
|
getState(deviceId: string): Promise<any>;
|
|
20
|
-
setState(deviceId: string, newState: any, auditProperties: IAuditProperties): Promise<void>;
|
|
20
|
+
setState(deviceId: string, newState: any, auditProperties: IAuditProperties, eventType?: string): Promise<void>;
|
|
21
21
|
getStatus(deviceId: string): Promise<Record<string, any>>;
|
|
22
22
|
setStatus(deviceId: string, newStatus: IStatus, source: Source, auditBody: IAuditProperties, reason?: string): Promise<void>;
|
|
23
23
|
setStatusMany(query: IStatusQuery, newStatus: IStatus, source: Source, auditBody: IAuditProperties): Promise<void>;
|
|
@@ -50,6 +50,7 @@ const Alert_service_1 = require("../../../../alerts/Alert.service");
|
|
|
50
50
|
const Issue_service_1 = require("../../../../issues/Issue.service");
|
|
51
51
|
const config_1 = require("../../../../config/config");
|
|
52
52
|
const typedi_2 = require("typedi");
|
|
53
|
+
const constants_1 = require("../../../../constants");
|
|
53
54
|
let LocalDeviceService = (() => {
|
|
54
55
|
let _classDecorators = [(0, typedi_2.Service)()];
|
|
55
56
|
let _classDescriptor;
|
|
@@ -119,7 +120,7 @@ let LocalDeviceService = (() => {
|
|
|
119
120
|
}
|
|
120
121
|
return await this.deviceRepository.getState(deviceId);
|
|
121
122
|
}
|
|
122
|
-
async setState(deviceId, newState, auditProperties) {
|
|
123
|
+
async setState(deviceId, newState, auditProperties, eventType) {
|
|
123
124
|
if (!deviceId || !newState) {
|
|
124
125
|
throw new Error("Device ID and new state are required");
|
|
125
126
|
}
|
|
@@ -128,7 +129,7 @@ let LocalDeviceService = (() => {
|
|
|
128
129
|
const changedKeys = Object.keys(newState).filter((key) => !(0, lodash_1.isEqual)(oldState[key], newState[key]));
|
|
129
130
|
if (changedKeys.length > 0) {
|
|
130
131
|
await this.deviceRepository.setState(deviceId, newState);
|
|
131
|
-
return await this.eventHandler.onStateChange(deviceId, newState, auditProperties);
|
|
132
|
+
return await this.eventHandler.onStateChange(deviceId, newState, auditProperties, eventType);
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
135
|
async getStatus(deviceId) {
|
|
@@ -158,16 +159,20 @@ let LocalDeviceService = (() => {
|
|
|
158
159
|
else {
|
|
159
160
|
// For any other status, just update normally
|
|
160
161
|
await this.deviceRepository.setStatus(deviceId, newStatus);
|
|
161
|
-
await this.eventHandler.onStatusChange(deviceId, newStatus, auditBody);
|
|
162
|
+
await this.eventHandler.onStatusChange(deviceId, newStatus, auditBody, constants_1.DT_EVENT_TYPES.DEVICE.STATUS.UNKNOWN);
|
|
162
163
|
}
|
|
163
164
|
}
|
|
164
165
|
async setStatusMany(query, newStatus, source, auditBody) {
|
|
166
|
+
//TODO: Compare old and new if different then update
|
|
165
167
|
if (!query || !newStatus) {
|
|
166
168
|
throw new Error("Query and new status are required");
|
|
167
169
|
}
|
|
168
170
|
newStatus.lastUpdated = new Date().toISOString();
|
|
171
|
+
const eventType = newStatus.online
|
|
172
|
+
? constants_1.DT_EVENT_TYPES.DEVICE.STATUS.ONLINE
|
|
173
|
+
: constants_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE;
|
|
169
174
|
await this.deviceRepository.setStatusMany(query, newStatus);
|
|
170
|
-
await this.eventHandler.onStatusChangeMany(query, newStatus, auditBody);
|
|
175
|
+
await this.eventHandler.onStatusChangeMany(query, newStatus, auditBody, eventType);
|
|
171
176
|
}
|
|
172
177
|
async handleOfflineStatus(device, oldStatus, newStatus, source, auditBody, reason, currentTime) {
|
|
173
178
|
const isExistingStatusOnline = oldStatus?.online === true;
|
|
@@ -183,7 +188,7 @@ let LocalDeviceService = (() => {
|
|
|
183
188
|
default: {},
|
|
184
189
|
};
|
|
185
190
|
await this.deviceRepository.setStatus(device.deviceId, newStatus);
|
|
186
|
-
await this.eventHandler.onStatusChange(device.deviceId, newStatus, auditBody);
|
|
191
|
+
await this.eventHandler.onStatusChange(device.deviceId, newStatus, auditBody, constants_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE);
|
|
187
192
|
}
|
|
188
193
|
else if (isExistingStatusOffline) {
|
|
189
194
|
// Existing status is Offline
|
|
@@ -202,7 +207,7 @@ let LocalDeviceService = (() => {
|
|
|
202
207
|
default: {},
|
|
203
208
|
};
|
|
204
209
|
await this.deviceRepository.setStatus(device.deviceId, newStatus);
|
|
205
|
-
await this.eventHandler.onStatusChange(device.deviceId, newStatus, auditBody);
|
|
210
|
+
await this.eventHandler.onStatusChange(device.deviceId, newStatus, auditBody, constants_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE);
|
|
206
211
|
// Raise alert (OPERATIONAL only)
|
|
207
212
|
await this.alertService.raiseDeviceOfflineAlert(device, source, reason);
|
|
208
213
|
// Raise issue when the device goes offline if longer than the baseline (OPERATIONAL only)
|
|
@@ -226,7 +231,7 @@ let LocalDeviceService = (() => {
|
|
|
226
231
|
newStatus.lastUpdated = currentTime;
|
|
227
232
|
newStatus.error = {}; // Clear the error
|
|
228
233
|
await this.deviceRepository.setStatus(device.deviceId, newStatus);
|
|
229
|
-
await this.eventHandler.onStatusChange(device.deviceId, newStatus, auditBody);
|
|
234
|
+
await this.eventHandler.onStatusChange(device.deviceId, newStatus, auditBody, constants_1.DT_EVENT_TYPES.DEVICE.STATUS.ONLINE);
|
|
230
235
|
//TODO: ALERT NEEDED?
|
|
231
236
|
// Raise alert
|
|
232
237
|
await this.alertService.raiseDeviceOnlineAlert(device, source, reason);
|
|
@@ -239,7 +244,7 @@ let LocalDeviceService = (() => {
|
|
|
239
244
|
newStatus.lastUpdated = currentTime;
|
|
240
245
|
newStatus.error = undefined; // Clear the error
|
|
241
246
|
await this.deviceRepository.setStatus(device.deviceId, newStatus);
|
|
242
|
-
await this.eventHandler.onStatusChange(device.deviceId, newStatus, auditBody);
|
|
247
|
+
await this.eventHandler.onStatusChange(device.deviceId, newStatus, auditBody, constants_1.DT_EVENT_TYPES.DEVICE.STATUS.ONLINE);
|
|
243
248
|
//TODO: ALERT NEEDED?
|
|
244
249
|
// Raise alert
|
|
245
250
|
await this.alertService.raiseDeviceOnlineAlert(device, source, reason);
|
|
@@ -20,7 +20,7 @@ export declare abstract class BaseEventHandler implements IEventHandler {
|
|
|
20
20
|
* Handle multiple events - default implementation processes them sequentially
|
|
21
21
|
*/
|
|
22
22
|
handleEvents(events: DeviceEvent[]): Promise<void>;
|
|
23
|
-
onStateChange(deviceId: string, state: Record<string, any>, event: DeviceEvent, auditProperties: IAuditProperties): Promise<void>;
|
|
23
|
+
onStateChange(deviceId: string, state: Record<string, any>, event: DeviceEvent, auditProperties: IAuditProperties, eventType?: string): Promise<void>;
|
|
24
24
|
/**
|
|
25
25
|
* Check if this handler can process the given event type
|
|
26
26
|
*/
|
|
@@ -66,9 +66,9 @@ class BaseEventHandler {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
// TODO: Check AuditBody for this function
|
|
69
|
-
async onStateChange(deviceId, state, event, auditProperties) {
|
|
69
|
+
async onStateChange(deviceId, state, event, auditProperties, eventType) {
|
|
70
70
|
try {
|
|
71
|
-
await this.localDeviceService.setState(deviceId, state, auditProperties);
|
|
71
|
+
await this.localDeviceService.setState(deviceId, state, auditProperties, eventType);
|
|
72
72
|
await this.afterEvent(event);
|
|
73
73
|
}
|
|
74
74
|
catch (error) {
|
|
@@ -89,12 +89,12 @@ let DeviceEventHandler = (() => {
|
|
|
89
89
|
super([
|
|
90
90
|
Event_1.DT_EVENT_TYPES.DEVICE.STATUS.ONLINE,
|
|
91
91
|
Event_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE,
|
|
92
|
-
Event_1.DT_EVENT_TYPES.DEVICE.STATUS.
|
|
93
|
-
Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.
|
|
94
|
-
Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.
|
|
95
|
-
Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.
|
|
96
|
-
Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.
|
|
97
|
-
Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.
|
|
92
|
+
Event_1.DT_EVENT_TYPES.DEVICE.STATUS.UNKNOWN,
|
|
93
|
+
Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.REPLACED,
|
|
94
|
+
Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.LEVEL.UNKNOWN,
|
|
95
|
+
Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.LEVEL.LOW,
|
|
96
|
+
Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.LEVEL.CRITICAL,
|
|
97
|
+
Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.LEVEL.UPDATED,
|
|
98
98
|
], 100);
|
|
99
99
|
// Use dependency injection instead of creating new instance
|
|
100
100
|
this.localHubService = typedi_1.default.get(services_1.LocalHubService);
|
|
@@ -141,7 +141,7 @@ let DeviceEventHandler = (() => {
|
|
|
141
141
|
source: constants_1.Source.CLOUD_EVENT,
|
|
142
142
|
});
|
|
143
143
|
break;
|
|
144
|
-
case Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.
|
|
144
|
+
case Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.LEVEL.UPDATED:
|
|
145
145
|
await this.localDeviceService.setBatteryLevel(deviceData.deviceId, event?.data?.batteryLevel ?? 0, constants_1.Source.CLOUD_EVENT, {
|
|
146
146
|
deviceId: deviceData.deviceId,
|
|
147
147
|
deviceName: deviceData.name,
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { IAuditProperties } from "../audit/IAuditProperties";
|
|
2
|
-
import { IStatus, IStatusQuery } from "../entities/device/local/interfaces";
|
|
2
|
+
import { IDevice, IStatus, IStatusQuery } from "../entities/device/local/interfaces";
|
|
3
3
|
export declare class EventHandler {
|
|
4
|
-
private readonly source;
|
|
5
|
-
private readonly auditUtils;
|
|
6
4
|
constructor();
|
|
7
|
-
onDeviceCreate(body:
|
|
5
|
+
onDeviceCreate(body: IDevice): Promise<void>;
|
|
8
6
|
onDeviceUpdate(deviceId: string, body: any, auditBody: IAuditProperties): Promise<void>;
|
|
9
7
|
onDeviceDelete(deviceId: string, auditBody: IAuditProperties): Promise<void>;
|
|
10
|
-
onStateChange(deviceId: string, state: any, auditProperties: IAuditProperties): Promise<void>;
|
|
11
|
-
onStatusChange(deviceId: string, status: any, auditProperties: IAuditProperties): Promise<void>;
|
|
12
|
-
onStatusChangeMany(query: IStatusQuery, status: IStatus, auditProperties: IAuditProperties): Promise<void>;
|
|
8
|
+
onStateChange(deviceId: string, state: any, auditProperties: IAuditProperties, eventType?: any): Promise<void>;
|
|
9
|
+
onStatusChange(deviceId: string, status: any, auditProperties: IAuditProperties, eventType: any): Promise<void>;
|
|
10
|
+
onStatusChangeMany(query: IStatusQuery, status: IStatus, auditProperties: IAuditProperties, eventType: any): Promise<void>;
|
|
13
11
|
onBatteryLevelChange(deviceId: string, batteryLevel: number, auditProperties: IAuditProperties): Promise<void>;
|
|
14
12
|
onDeviceMetaChange(deviceId: string, metaData: Record<string, any>, auditProperties: IAuditProperties): Promise<void>;
|
|
15
13
|
}
|
|
@@ -1,20 +1,4 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
2
|
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
19
3
|
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
20
4
|
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
@@ -49,33 +33,17 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
|
|
|
49
33
|
}
|
|
50
34
|
return useValue ? value : void 0;
|
|
51
35
|
};
|
|
52
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
53
|
-
var ownKeys = function(o) {
|
|
54
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
55
|
-
var ar = [];
|
|
56
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
57
|
-
return ar;
|
|
58
|
-
};
|
|
59
|
-
return ownKeys(o);
|
|
60
|
-
};
|
|
61
|
-
return function (mod) {
|
|
62
|
-
if (mod && mod.__esModule) return mod;
|
|
63
|
-
var result = {};
|
|
64
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
65
|
-
__setModuleDefault(result, mod);
|
|
66
|
-
return result;
|
|
67
|
-
};
|
|
68
|
-
})();
|
|
69
36
|
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
70
37
|
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
71
38
|
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
72
39
|
};
|
|
73
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
74
41
|
exports.EventHandler = void 0;
|
|
75
|
-
const dt_audit_library_1 = require("dt-audit-library");
|
|
76
42
|
const Event_1 = require("../constants/Event");
|
|
77
|
-
const typedi_1 =
|
|
78
|
-
const
|
|
43
|
+
const typedi_1 = require("typedi");
|
|
44
|
+
const IAuditProperties_1 = require("../audit/IAuditProperties");
|
|
45
|
+
const audit_1 = require("../audit");
|
|
46
|
+
const constants_1 = require("../constants");
|
|
79
47
|
// TODO: For all the Event handlers, we need to publish the respective events for External Consumption
|
|
80
48
|
let EventHandler = (() => {
|
|
81
49
|
let _classDecorators = [(0, typedi_1.Service)()];
|
|
@@ -83,92 +51,156 @@ let EventHandler = (() => {
|
|
|
83
51
|
let _classExtraInitializers = [];
|
|
84
52
|
let _classThis;
|
|
85
53
|
var EventHandler = _classThis = class {
|
|
86
|
-
constructor() {
|
|
87
|
-
this.source = "dt-common-device";
|
|
88
|
-
this.auditUtils = typedi_1.default.get(AuditUtils_1.AuditUtils);
|
|
89
|
-
}
|
|
54
|
+
constructor() { }
|
|
90
55
|
async onDeviceCreate(body) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
56
|
+
await (0, audit_1.pushAudit)({
|
|
57
|
+
auditType: Event_1.DT_EVENT_TYPES.DEVICE.CREATE.SUCCESS,
|
|
58
|
+
auditData: {
|
|
59
|
+
deviceId: body.deviceId,
|
|
60
|
+
deviceName: body.name,
|
|
61
|
+
propertyId: body.propertyId,
|
|
62
|
+
zoneId: body.zoneId,
|
|
63
|
+
source: constants_1.Source.USER,
|
|
64
|
+
resource: IAuditProperties_1.Resource.DEVICE,
|
|
65
|
+
actionPayload: body,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
// const payload = {
|
|
69
|
+
// eventType: DT_EVENT_TYPES.DEVICE.CREATE.SUCCESS,
|
|
70
|
+
// properties: await this.auditUtils.buildAuditProperties(body),
|
|
71
|
+
// };
|
|
72
|
+
// await publishAudit(payload);
|
|
96
73
|
}
|
|
97
74
|
async onDeviceUpdate(deviceId, body, auditBody) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
...auditBody,
|
|
75
|
+
await (0, audit_1.pushAudit)({
|
|
76
|
+
auditType: Event_1.DT_EVENT_TYPES.DEVICE.UPDATE.SUCCESS,
|
|
77
|
+
auditData: {
|
|
102
78
|
deviceId,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
79
|
+
body,
|
|
80
|
+
...auditBody,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
// const payload = {
|
|
84
|
+
// eventType: DT_EVENT_TYPES.DEVICE.UPDATE.SUCCESS,
|
|
85
|
+
// properties: await this.auditUtils.buildAuditProperties({
|
|
86
|
+
// ...auditBody,
|
|
87
|
+
// deviceId,
|
|
88
|
+
// ...body,
|
|
89
|
+
// }),
|
|
90
|
+
// };
|
|
91
|
+
// await publishAudit(payload);
|
|
107
92
|
}
|
|
108
93
|
async onDeviceDelete(deviceId, auditBody) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
...auditBody,
|
|
94
|
+
await (0, audit_1.pushAudit)({
|
|
95
|
+
auditType: Event_1.DT_EVENT_TYPES.DEVICE.DELETE.SUCCESS,
|
|
96
|
+
auditData: {
|
|
113
97
|
deviceId,
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
98
|
+
...auditBody,
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
// const payload = {
|
|
102
|
+
// eventType: DT_EVENT_TYPES.DEVICE.DELETE.SUCCESS,
|
|
103
|
+
// properties: await this.auditUtils.buildAuditProperties({
|
|
104
|
+
// ...auditBody,
|
|
105
|
+
// deviceId,
|
|
106
|
+
// }),
|
|
107
|
+
// };
|
|
108
|
+
// await publishAudit(payload);
|
|
117
109
|
}
|
|
118
|
-
async onStateChange(deviceId, state, auditProperties) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
...auditProperties,
|
|
110
|
+
async onStateChange(deviceId, state, auditProperties, eventType) {
|
|
111
|
+
await (0, audit_1.pushAudit)({
|
|
112
|
+
auditType: eventType || Event_1.DT_EVENT_TYPES.DEVICE.STATE.CHANGED,
|
|
113
|
+
auditData: {
|
|
123
114
|
deviceId,
|
|
124
|
-
|
|
125
|
-
}),
|
|
126
|
-
};
|
|
127
|
-
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
128
|
-
}
|
|
129
|
-
async onStatusChange(deviceId, status, auditProperties) {
|
|
130
|
-
const payload = {
|
|
131
|
-
eventType: Event_1.DT_EVENT_TYPES.DEVICE.STATUS.SET,
|
|
132
|
-
properties: await this.auditUtils.buildAuditProperties({
|
|
115
|
+
state,
|
|
133
116
|
...auditProperties,
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
// const payload = {
|
|
120
|
+
// eventType: eventType || DT_EVENT_TYPES.DEVICE.STATE.CHANGED,
|
|
121
|
+
// properties: await this.auditUtils.buildAuditProperties({
|
|
122
|
+
// ...auditProperties,
|
|
123
|
+
// deviceId,
|
|
124
|
+
// ...state,
|
|
125
|
+
// }),
|
|
126
|
+
// };
|
|
127
|
+
// await publishAudit(payload);
|
|
128
|
+
}
|
|
129
|
+
async onStatusChange(deviceId, status, auditProperties, eventType) {
|
|
130
|
+
await (0, audit_1.pushAudit)({
|
|
131
|
+
auditType: eventType,
|
|
132
|
+
auditData: {
|
|
134
133
|
deviceId,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
134
|
+
status,
|
|
135
|
+
...auditProperties,
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
// const payload = {
|
|
139
|
+
// eventType: eventType || DT_EVENT_TYPES.DEVICE.STATUS.CHANGED,
|
|
140
|
+
// properties: await this.auditUtils.buildAuditProperties({
|
|
141
|
+
// ...auditProperties,
|
|
142
|
+
// deviceId,
|
|
143
|
+
// ...status,
|
|
144
|
+
// }),
|
|
145
|
+
// };
|
|
146
|
+
// await publishAudit(payload);
|
|
139
147
|
}
|
|
140
|
-
async onStatusChangeMany(query, status, auditProperties) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
148
|
+
async onStatusChangeMany(query, status, auditProperties, eventType) {
|
|
149
|
+
await (0, audit_1.pushAudit)({
|
|
150
|
+
auditType: eventType,
|
|
151
|
+
auditData: {
|
|
152
|
+
status,
|
|
153
|
+
query,
|
|
144
154
|
...auditProperties,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
await
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
// const payload = {
|
|
158
|
+
// eventType: eventType || DT_EVENT_TYPES.DEVICE.STATUS.UPDATED,
|
|
159
|
+
// properties: await this.auditUtils.buildAuditProperties({
|
|
160
|
+
// ...auditProperties,
|
|
161
|
+
// ...query,
|
|
162
|
+
// ...status,
|
|
163
|
+
// }),
|
|
164
|
+
// };
|
|
165
|
+
// await publishAudit(payload);
|
|
150
166
|
}
|
|
151
167
|
async onBatteryLevelChange(deviceId, batteryLevel, auditProperties) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
...auditProperties,
|
|
168
|
+
await (0, audit_1.pushAudit)({
|
|
169
|
+
auditType: Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.LEVEL.UPDATED,
|
|
170
|
+
auditData: {
|
|
156
171
|
deviceId,
|
|
157
172
|
batteryLevel,
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
173
|
+
...auditProperties,
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
// const payload = {
|
|
177
|
+
// eventType: DT_EVENT_TYPES.DEVICE.BATTERY_LEVEL.UPDATED,
|
|
178
|
+
// properties: await this.auditUtils.buildAuditProperties({
|
|
179
|
+
// ...auditProperties,
|
|
180
|
+
// deviceId,
|
|
181
|
+
// batteryLevel,
|
|
182
|
+
// }),
|
|
183
|
+
// };
|
|
184
|
+
// await publishAudit(payload);
|
|
161
185
|
}
|
|
162
186
|
async onDeviceMetaChange(deviceId, metaData, auditProperties) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
...auditProperties,
|
|
187
|
+
await (0, audit_1.pushAudit)({
|
|
188
|
+
auditType: Event_1.DT_EVENT_TYPES.DEVICE.METADATA.UPDATED,
|
|
189
|
+
auditData: {
|
|
167
190
|
deviceId,
|
|
168
191
|
metaData,
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
192
|
+
...auditProperties,
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
// const payload = {
|
|
196
|
+
// eventType: DT_EVENT_TYPES.DEVICE.METADATA.UPDATED,
|
|
197
|
+
// properties: await this.auditUtils.buildAuditProperties({
|
|
198
|
+
// ...auditProperties,
|
|
199
|
+
// deviceId,
|
|
200
|
+
// metaData,
|
|
201
|
+
// }),
|
|
202
|
+
// };
|
|
203
|
+
// await publishAudit(payload);
|
|
172
204
|
}
|
|
173
205
|
};
|
|
174
206
|
__setFunctionName(_classThis, "EventHandler");
|
|
@@ -18,7 +18,7 @@ interface IIssueModel extends Model<IIssueDocument, {}, IIssueMethods> {
|
|
|
18
18
|
findOverdue(includeDeleted?: boolean): Promise<IIssueDocument[]>;
|
|
19
19
|
findUpcoming(days?: number, includeDeleted?: boolean): Promise<IIssueDocument[]>;
|
|
20
20
|
}
|
|
21
|
-
declare const IssueSchema: mongoose.Schema<IIssueDocument, IIssueModel, IIssueMethods, {}, {}, {}, mongoose.DefaultSchemaOptions, IIssueDocument, mongoose.Document<unknown, {}, mongoose.FlatRecord<IIssueDocument>, {}
|
|
21
|
+
declare const IssueSchema: mongoose.Schema<IIssueDocument, IIssueModel, IIssueMethods, {}, {}, {}, mongoose.DefaultSchemaOptions, IIssueDocument, mongoose.Document<unknown, {}, mongoose.FlatRecord<IIssueDocument>, {}, mongoose.ResolveSchemaOptions<mongoose.DefaultSchemaOptions>> & Omit<mongoose.FlatRecord<IIssueDocument> & Required<{
|
|
22
22
|
_id: string;
|
|
23
23
|
}> & {
|
|
24
24
|
__v: number;
|
|
@@ -64,5 +64,10 @@ export declare class RedisUtils {
|
|
|
64
64
|
* @returns 1 if the expiration was set, 0 if the key does not exist
|
|
65
65
|
*/
|
|
66
66
|
expire(key: string, seconds: number): Promise<any>;
|
|
67
|
+
/**
|
|
68
|
+
* Get all fields and values from a hash
|
|
69
|
+
* @param key - The key to get
|
|
70
|
+
* @returns The fields and values
|
|
71
|
+
*/
|
|
67
72
|
hgetAll(key: string): Promise<any>;
|
|
68
73
|
}
|
|
@@ -168,6 +168,11 @@ let RedisUtils = (() => {
|
|
|
168
168
|
throw error;
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Get all fields and values from a hash
|
|
173
|
+
* @param key - The key to get
|
|
174
|
+
* @returns The fields and values
|
|
175
|
+
*/
|
|
171
176
|
async hgetAll(key) {
|
|
172
177
|
try {
|
|
173
178
|
return await this.client.hgetall(key);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dt-common-device",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"dt-pub-sub": "^1.0.0",
|
|
50
50
|
"ioredis": "5.6.1",
|
|
51
51
|
"lodash": "^4.17.21",
|
|
52
|
-
"mongoose": "8.
|
|
52
|
+
"mongoose": "8.17.1",
|
|
53
53
|
"pg": "8.16.3",
|
|
54
54
|
"typedi": "0.10.0"
|
|
55
55
|
}
|