dt-common-device 3.1.4 → 3.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/audit/AuditProperties.d.ts +16 -0
  2. package/dist/audit/AuditUtils.d.ts +2 -0
  3. package/dist/audit/AuditUtils.js +36 -0
  4. package/dist/config/config.types.d.ts +1 -0
  5. package/dist/device/local/events/EventHandler.js +6 -6
  6. package/dist/device/local/events/Events.d.ts +33 -12
  7. package/dist/device/local/events/Events.js +33 -12
  8. package/dist/events/DeviceEventHandler.js +223 -139
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.js +2 -0
  11. package/dist/utils/http.utils.d.ts +2 -0
  12. package/dist/utils/http.utils.js +30 -0
  13. package/dist/utils/redis.utils.d.ts +39 -0
  14. package/dist/utils/redis.utils.js +49 -20
  15. package/package.json +4 -4
  16. package/dist/device/cloud/interface.d.ts +0 -101
  17. package/dist/device/cloud/interface.js +0 -3
  18. package/dist/device/cloud/interfaces/IDeviceConnectionService.d.ts +0 -7
  19. package/dist/device/cloud/interfaces/IDeviceConnectionService.js +0 -3
  20. package/dist/device/cloud/interfaces/IDevicesService.d.ts +0 -9
  21. package/dist/device/cloud/services/Device.service.d.ts +0 -39
  22. package/dist/device/cloud/services/Device.service.js +0 -9
  23. package/dist/device/cloud/services/DeviceCloudService.d.ts +0 -42
  24. package/dist/device/cloud/services/DeviceCloudService.js +0 -59
  25. package/dist/device/cloud/services/DeviceHub.service.d.ts +0 -3
  26. package/dist/device/cloud/services/DeviceHub.service.js +0 -6
  27. package/dist/device/cloud/services/Hub.service.d.ts +0 -25
  28. package/dist/device/cloud/services/Hub.service.js +0 -9
  29. package/dist/device/cloud/services/SmartThingsDeviceService.d.ts +0 -38
  30. package/dist/device/cloud/services/SmartThingsDeviceService.js +0 -52
  31. package/dist/device/index.d.ts +0 -4
  32. package/dist/device/index.js +0 -20
  33. package/dist/device/local/interface.d.ts +0 -0
  34. package/dist/device/local/interface.js +0 -1
  35. package/dist/device/local/services/DeviceHub.service.d.ts +0 -11
  36. package/dist/device/local/services/DeviceHub.service.js +0 -40
  37. /package/dist/{device/cloud/interfaces/IDevicesService.js → audit/AuditProperties.js} +0 -0
@@ -0,0 +1,16 @@
1
+ export interface AuditProperties {
2
+ resource: string;
3
+ propertyId: string;
4
+ propertyName?: string;
5
+ userId?: string;
6
+ userName?: string;
7
+ deviceId: string;
8
+ deviceName: string;
9
+ zoneId?: string;
10
+ zoneName?: string;
11
+ accessGroupId?: string;
12
+ accessGroupName?: string;
13
+ scheduleId?: string;
14
+ scheduleName?: string;
15
+ [key: string]: any;
16
+ }
@@ -0,0 +1,2 @@
1
+ import { AuditProperties } from "./AuditProperties";
2
+ export declare function buildAuditProperties(input: AuditProperties): Record<string, any>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildAuditProperties = buildAuditProperties;
4
+ const AUDIT_FIELDS = [
5
+ "resource",
6
+ "propertyId",
7
+ "propertyName",
8
+ "userId",
9
+ "userName",
10
+ "deviceId",
11
+ "deviceName",
12
+ "zoneId",
13
+ "zoneName",
14
+ "accessGroupId",
15
+ "accessGroupName",
16
+ "scheduleId",
17
+ "scheduleName",
18
+ ];
19
+ function buildAuditProperties(input) {
20
+ // Normalize keys to camelCase for matching
21
+ const normalized = { ...input };
22
+ // Build the audit object with all standard fields
23
+ const audit = {};
24
+ for (const field of AUDIT_FIELDS) {
25
+ // Try to find a matching key in input (case-insensitive)
26
+ const foundKey = Object.keys(normalized).find((k) => k.toLowerCase() === field.toLowerCase());
27
+ audit[field] = foundKey ? normalized[foundKey] : undefined;
28
+ }
29
+ // Merge in all other event-specific data (but don't overwrite audit fields)
30
+ for (const key of Object.keys(normalized)) {
31
+ if (!audit.hasOwnProperty(key)) {
32
+ audit[key] = normalized[key];
33
+ }
34
+ }
35
+ return audit;
36
+ }
@@ -12,6 +12,7 @@ export type IConfig = {
12
12
  ADMIN_SERVICE?: string;
13
13
  ACCESS_SERVICE?: string;
14
14
  ENERGY_SERVICE?: string;
15
+ REMOTE_SERVICE?: string;
15
16
  INTERNAL_EVENT_HANDLER: IInternalEvent;
16
17
  LOGGER: ILogger;
17
18
  CLOUD_SERVICE_API_KEY?: string;
@@ -9,9 +9,9 @@ class EventHandler {
9
9
  this.source = "dt-common-device";
10
10
  }
11
11
  async onDeviceCreate(body) {
12
- await dt_pub_sub_1.eventDispatcher.publishEvent(Events_1.DT_EVENT_TYPES.DEVICE.DEVICE.CREATED, body, this.source);
12
+ await dt_pub_sub_1.eventDispatcher.publishEvent(Events_1.DT_EVENT_TYPES.DEVICE.CREATE.SUCCESS, body, this.source);
13
13
  const payload = {
14
- eventType: Events_1.DT_EVENT_TYPES.DEVICE.DEVICE.CREATED,
14
+ eventType: Events_1.DT_EVENT_TYPES.DEVICE.CREATE.SUCCESS,
15
15
  properties: {
16
16
  ...body,
17
17
  },
@@ -19,9 +19,9 @@ class EventHandler {
19
19
  await (0, dt_audit_library_1.publishAudit)(payload);
20
20
  }
21
21
  async onDeviceUpdate(deviceId, body) {
22
- await dt_pub_sub_1.eventDispatcher.publishEvent(Events_1.DT_EVENT_TYPES.DEVICE.DEVICE.UPDATED, { deviceId, body }, this.source);
22
+ await dt_pub_sub_1.eventDispatcher.publishEvent(Events_1.DT_EVENT_TYPES.DEVICE.UPDATE.SUCCESS, { deviceId, body }, this.source);
23
23
  const payload = {
24
- eventType: Events_1.DT_EVENT_TYPES.DEVICE.DEVICE.UPDATED,
24
+ eventType: Events_1.DT_EVENT_TYPES.DEVICE.UPDATE.SUCCESS,
25
25
  properties: {
26
26
  ...body,
27
27
  },
@@ -29,9 +29,9 @@ class EventHandler {
29
29
  await (0, dt_audit_library_1.publishAudit)(payload);
30
30
  }
31
31
  async onDeviceDelete(deviceId) {
32
- await dt_pub_sub_1.eventDispatcher.publishEvent(Events_1.DT_EVENT_TYPES.DEVICE.DEVICE.DELETED, { deviceId }, this.source);
32
+ await dt_pub_sub_1.eventDispatcher.publishEvent(Events_1.DT_EVENT_TYPES.DEVICE.DELETE.SUCCESS, { deviceId }, this.source);
33
33
  const payload = {
34
- eventType: Events_1.DT_EVENT_TYPES.DEVICE.DEVICE.DELETED,
34
+ eventType: Events_1.DT_EVENT_TYPES.DEVICE.DELETE.SUCCESS,
35
35
  properties: {
36
36
  deviceId,
37
37
  },
@@ -1,9 +1,16 @@
1
1
  export declare const DT_EVENT_TYPES: {
2
2
  DEVICE: {
3
- DEVICE: {
4
- CREATED: string;
5
- UPDATED: string;
6
- DELETED: string;
3
+ CREATE: {
4
+ SUCCESS: string;
5
+ FAILED: string;
6
+ };
7
+ UPDATE: {
8
+ SUCCESS: string;
9
+ FAILED: string;
10
+ };
11
+ DELETE: {
12
+ SUCCESS: string;
13
+ FAILED: string;
7
14
  };
8
15
  STATE: {
9
16
  SET: string;
@@ -34,17 +41,31 @@ export declare const DT_EVENT_TYPES: {
34
41
  };
35
42
  };
36
43
  CONNECTION: {
37
- CONNECTION: {
38
- CREATED: string;
39
- UPDATED: string;
40
- DELETED: string;
44
+ CREATE: {
45
+ SUCCESS: string;
46
+ FAILED: string;
47
+ };
48
+ UPDATE: {
49
+ SUCCESS: string;
50
+ FAILED: string;
51
+ };
52
+ DELETE: {
53
+ SUCCESS: string;
54
+ FAILED: string;
41
55
  };
42
56
  };
43
57
  PROPERTY: {
44
- PROPERTY: {
45
- CREATED: string;
46
- UPDATED: string;
47
- DELETED: string;
58
+ CREATE: {
59
+ SUCCESS: string;
60
+ FAILED: string;
61
+ };
62
+ UPDATE: {
63
+ SUCCESS: string;
64
+ FAILED: string;
65
+ };
66
+ DELETE: {
67
+ SUCCESS: string;
68
+ FAILED: string;
48
69
  };
49
70
  PREFERENCES: {
50
71
  UPDATED: string;
@@ -3,10 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DT_EVENT_TYPES = void 0;
4
4
  exports.DT_EVENT_TYPES = {
5
5
  DEVICE: {
6
- DEVICE: {
7
- CREATED: "device.device.created",
8
- UPDATED: "device.device.updated",
9
- DELETED: "device.device.deleted",
6
+ CREATE: {
7
+ SUCCESS: "device.create.success",
8
+ FAILED: "device.create.failed",
9
+ },
10
+ UPDATE: {
11
+ SUCCESS: "device.update.success",
12
+ FAILED: "device.update.failed",
13
+ },
14
+ DELETE: {
15
+ SUCCESS: "device.delete.success",
16
+ FAILED: "device.delete.failed",
10
17
  },
11
18
  STATE: {
12
19
  SET: "device.state.set",
@@ -37,17 +44,31 @@ exports.DT_EVENT_TYPES = {
37
44
  },
38
45
  },
39
46
  CONNECTION: {
40
- CONNECTION: {
41
- CREATED: "connection.connection.created",
42
- UPDATED: "connection.connection.updated",
43
- DELETED: "connection.connection.deleted",
47
+ CREATE: {
48
+ SUCCESS: "connection.create.success",
49
+ FAILED: "connection.create.failed",
50
+ },
51
+ UPDATE: {
52
+ SUCCESS: "connection.update.success",
53
+ FAILED: "connection.update.failed",
54
+ },
55
+ DELETE: {
56
+ SUCCESS: "connection.delete.success",
57
+ FAILED: "connection.delete.failed",
44
58
  },
45
59
  },
46
60
  PROPERTY: {
47
- PROPERTY: {
48
- CREATED: "property.property.created",
49
- UPDATED: "property.property.updated",
50
- DELETED: "property.property.deleted",
61
+ CREATE: {
62
+ SUCCESS: "property.create.success",
63
+ FAILED: "property.create.failed",
64
+ },
65
+ UPDATE: {
66
+ SUCCESS: "property.update.success",
67
+ FAILED: "property.update.failed",
68
+ },
69
+ DELETE: {
70
+ SUCCESS: "property.delete.success",
71
+ FAILED: "property.delete.failed",
51
72
  },
52
73
  PREFERENCES: {
53
74
  UPDATED: "property.preferences.updated",
@@ -1,6 +1,74 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
19
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
20
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
21
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
22
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
23
+ var _, done = false;
24
+ for (var i = decorators.length - 1; i >= 0; i--) {
25
+ var context = {};
26
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
27
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
28
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
29
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
30
+ if (kind === "accessor") {
31
+ if (result === void 0) continue;
32
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
33
+ if (_ = accept(result.get)) descriptor.get = _;
34
+ if (_ = accept(result.set)) descriptor.set = _;
35
+ if (_ = accept(result.init)) initializers.unshift(_);
36
+ }
37
+ else if (_ = accept(result)) {
38
+ if (kind === "field") initializers.unshift(_);
39
+ else descriptor[key] = _;
40
+ }
41
+ }
42
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
43
+ done = true;
44
+ };
45
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
46
+ var useValue = arguments.length > 2;
47
+ for (var i = 0; i < initializers.length; i++) {
48
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
49
+ }
50
+ return useValue ? value : void 0;
51
+ };
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
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
70
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
71
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
4
72
  };
5
73
  Object.defineProperty(exports, "__esModule", { value: true });
6
74
  exports.DeviceEventHandler = void 0;
@@ -8,151 +76,167 @@ const constants_1 = require("../constants");
8
76
  const Event_1 = require("../constants/Event");
9
77
  const services_1 = require("../device/local/services");
10
78
  const BaseEventHandler_1 = require("./BaseEventHandler");
11
- const typedi_1 = __importDefault(require("typedi"));
12
- class DeviceEventHandler extends BaseEventHandler_1.BaseEventHandler {
13
- constructor() {
14
- super([
15
- Event_1.DT_EVENT_TYPES.DEVICE.STATUS.ONLINE,
16
- Event_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE,
17
- Event_1.DT_EVENT_TYPES.DEVICE.STATUS.CHANGED,
18
- Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.CRITICAL,
19
- Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.LOW,
20
- Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.CHANGED,
21
- ], 100);
22
- // Use dependency injection instead of creating new instance
23
- this.localHubService = typedi_1.default.get(services_1.LocalHubService);
24
- }
25
- async onEvent(event) {
26
- this.logger.info("[DT | CDL]:[DeviceEventHandler]: Processing event", {
27
- eventName: event.eventName,
28
- });
29
- try {
30
- const device = await this.localDeviceService.getDevice(event.deviceId);
31
- if (!device?.deviceId) {
32
- throw new Error("[DT | CDL]:[DeviceEventHandler]: deviceId does not exist");
33
- }
34
- await this.updateDeviceEventData(device, event);
35
- // Update relevant tables based on event type
36
- await this.updateTablesBasedOnEventType(event, device);
37
- // Save event logs
38
- await this.dumpToEventOperation(event, device);
79
+ const typedi_1 = __importStar(require("typedi"));
80
+ let DeviceEventHandler = (() => {
81
+ let _classDecorators = [(0, typedi_1.Service)()];
82
+ let _classDescriptor;
83
+ let _classExtraInitializers = [];
84
+ let _classThis;
85
+ let _classSuper = BaseEventHandler_1.BaseEventHandler;
86
+ var DeviceEventHandler = _classThis = class extends _classSuper {
87
+ constructor() {
88
+ super([
89
+ Event_1.DT_EVENT_TYPES.DEVICE.STATUS.ONLINE,
90
+ Event_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE,
91
+ Event_1.DT_EVENT_TYPES.DEVICE.STATUS.CHANGED,
92
+ Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.CRITICAL,
93
+ Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.LOW,
94
+ Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.CHANGED,
95
+ ], 100);
96
+ // Use dependency injection instead of creating new instance
97
+ this.localHubService = typedi_1.default.get(services_1.LocalHubService);
39
98
  }
40
- catch (error) {
41
- this.logger.error("[DT | CDL]:[DeviceEventHandler]: Error processing event", error);
42
- throw error;
99
+ async onEvent(event) {
100
+ this.logger.info("[DT | CDL]:[DeviceEventHandler]: Processing event", {
101
+ eventName: event.eventName,
102
+ });
103
+ try {
104
+ const device = await this.localDeviceService.getDevice(event.deviceId);
105
+ if (!device?.deviceId) {
106
+ throw new Error("[DT | CDL]:[DeviceEventHandler]: deviceId does not exist");
107
+ }
108
+ await this.updateDeviceEventData(device, event);
109
+ // Update relevant tables based on event type
110
+ await this.updateTablesBasedOnEventType(event, device);
111
+ // Save event logs
112
+ await this.dumpToEventOperation(event, device);
113
+ }
114
+ catch (error) {
115
+ this.logger.error("[DT | CDL]:[DeviceEventHandler]: Error processing event", error);
116
+ throw error;
117
+ }
43
118
  }
44
- }
45
- async updateDeviceEventData(deviceData, event) {
46
- switch (event.eventName) {
47
- case Event_1.DT_EVENT_TYPES.DEVICE.STATUS.ONLINE:
48
- case Event_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE:
49
- await this.localDeviceService.setState(deviceData.deviceId, {
50
- status: {
51
- online: event.eventName === Event_1.DT_EVENT_TYPES.DEVICE.STATUS.ONLINE,
52
- lastUpdated: new Date().toISOString(),
53
- error: {
54
- type: event.eventName === Event_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE
55
- ? "offline"
56
- : "",
57
- message: event.eventName === Event_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE
58
- ? "Device is offline"
59
- : "",
60
- default: {},
119
+ async updateDeviceEventData(deviceData, event) {
120
+ switch (event.eventName) {
121
+ case Event_1.DT_EVENT_TYPES.DEVICE.STATUS.ONLINE:
122
+ case Event_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE:
123
+ await this.localDeviceService.setState(deviceData.deviceId, {
124
+ status: {
125
+ online: event.eventName === Event_1.DT_EVENT_TYPES.DEVICE.STATUS.ONLINE,
126
+ lastUpdated: new Date().toISOString(),
127
+ error: {
128
+ type: event.eventName === Event_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE
129
+ ? "offline"
130
+ : "",
131
+ message: event.eventName === Event_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE
132
+ ? "Device is offline"
133
+ : "",
134
+ default: {},
135
+ },
61
136
  },
62
- },
63
- });
64
- break;
65
- case Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.CHANGED:
66
- await this.localDeviceService.setBatteryLevel(deviceData.deviceId, event?.data?.batteryLevel ?? 0, constants_1.Source.CLOUD_EVENT);
67
- break;
137
+ });
138
+ break;
139
+ case Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.CHANGED:
140
+ await this.localDeviceService.setBatteryLevel(deviceData.deviceId, event?.data?.batteryLevel ?? 0, constants_1.Source.CLOUD_EVENT);
141
+ break;
142
+ }
68
143
  }
69
- }
70
- async extractHubDetails(device) {
71
- const hubIds = device?.hubId;
72
- const hubDetails = [];
73
- if (hubIds) {
74
- for (const hubId of hubIds) {
75
- const hubDetail = await this.localHubService.getHub(hubId);
76
- hubDetails.push({
77
- id: hubDetail?.deviceId,
78
- name: hubDetail?.name,
79
- type: hubDetail?.deviceType?.type,
80
- brand: hubDetail?.specifications?.manufacturer,
81
- model: hubDetail?.specifications?.model,
82
- status: hubDetail?.status?.online ? "ONLINE" : "OFFLINE",
144
+ async extractHubDetails(device) {
145
+ const hubIds = device?.hubId;
146
+ const hubDetails = [];
147
+ if (hubIds) {
148
+ for (const hubId of hubIds) {
149
+ const hubDetail = await this.localHubService.getHub(hubId);
150
+ hubDetails.push({
151
+ id: hubDetail?.deviceId,
152
+ name: hubDetail?.name,
153
+ type: hubDetail?.deviceType?.type,
154
+ brand: hubDetail?.specifications?.manufacturer,
155
+ model: hubDetail?.specifications?.model,
156
+ status: hubDetail?.status?.online ? "ONLINE" : "OFFLINE",
157
+ });
158
+ }
159
+ }
160
+ return hubDetails;
161
+ }
162
+ constructDeviceEventEntity(eventData, device, hubDetails, options = {}) {
163
+ return {
164
+ event: {
165
+ eventId: options.eventId || eventData?.eventId || "",
166
+ eventName: options.eventName || eventData?.eventName || "",
167
+ status: options.status || eventData?.status || "",
168
+ mode: options.mode || eventData?.data?.mode,
169
+ userName: options.userName || eventData?.userName || "",
170
+ userId: options.userId || eventData?.userId || "",
171
+ userType: options.userType || eventData?.userType || "",
172
+ raw_event: options.rawEvent || eventData?.rawData || {},
173
+ batteryLevel: options.batteryLevel || eventData?.data?.batteryLevel || "",
174
+ reason: options.reason || eventData?.data?.reason || "",
175
+ eventDescription: options.eventDescription || eventData?.event || "",
176
+ },
177
+ device: {
178
+ id: eventData?.deviceId || "",
179
+ name: device?.name || "",
180
+ type: device?.deviceType?.type || "",
181
+ brand: device?.specifications?.manufacturer || "",
182
+ model: device?.specifications?.model || "",
183
+ },
184
+ hub: hubDetails,
185
+ property: {
186
+ id: eventData?.property?.id || "",
187
+ name: eventData?.property?.name || "",
188
+ location: eventData?.property?.apartment || "",
189
+ },
190
+ };
191
+ }
192
+ async dumpToEventOperation(data, device) {
193
+ try {
194
+ const hubDetails = await this.extractHubDetails(device);
195
+ const eventData = this.constructDeviceEventEntity(data, device, hubDetails, {
196
+ status: data.eventName === "lock.unlock" ? "UNLOCKED" : "LOCKED",
197
+ rawEvent: data.rawData,
83
198
  });
199
+ this.logger.info("[DT | CDL]:[DeviceEventHandler]: Event data dumped to event operation", { eventData });
200
+ }
201
+ catch (error) {
202
+ this.logger.error("[DT | CDL]:[DeviceEventHandler]: Error dumping to event operation", error);
84
203
  }
85
204
  }
86
- return hubDetails;
87
- }
88
- constructDeviceEventEntity(eventData, device, hubDetails, options = {}) {
89
- return {
90
- event: {
91
- eventId: options.eventId || eventData?.eventId || "",
92
- eventName: options.eventName || eventData?.eventName || "",
93
- status: options.status || eventData?.status || "",
94
- mode: options.mode || eventData?.data?.mode,
95
- userName: options.userName || eventData?.userName || "",
96
- userId: options.userId || eventData?.userId || "",
97
- userType: options.userType || eventData?.userType || "",
98
- raw_event: options.rawEvent || eventData?.rawData || {},
99
- batteryLevel: options.batteryLevel || eventData?.data?.batteryLevel || "",
100
- reason: options.reason || eventData?.data?.reason || "",
101
- eventDescription: options.eventDescription || eventData?.event || "",
102
- },
103
- device: {
104
- id: eventData?.deviceId || "",
105
- name: device?.name || "",
106
- type: device?.deviceType?.type || "",
107
- brand: device?.specifications?.manufacturer || "",
108
- model: device?.specifications?.model || "",
109
- },
110
- hub: hubDetails,
111
- property: {
112
- id: eventData?.property?.id || "",
113
- name: eventData?.property?.name || "",
114
- location: eventData?.property?.apartment || "",
115
- },
116
- };
117
- }
118
- async dumpToEventOperation(data, device) {
119
- try {
120
- const hubDetails = await this.extractHubDetails(device);
121
- const eventData = this.constructDeviceEventEntity(data, device, hubDetails, {
122
- status: data.eventName === "lock.unlock" ? "UNLOCKED" : "LOCKED",
123
- rawEvent: data.rawData,
124
- });
125
- this.logger.info("[DT | CDL]:[DeviceEventHandler]: Event data dumped to event operation", { eventData });
205
+ async updateTablesBasedOnEventType(eventData, device) {
206
+ switch (eventData.eventName) {
207
+ case Event_1.DT_EVENT_TYPES.DEVICE.STATUS.ONLINE:
208
+ case Event_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE:
209
+ case Event_1.DT_EVENT_TYPES.DEVICE.STATUS.CHANGED:
210
+ this.updateDeviceStatus(eventData, device);
211
+ break;
212
+ case Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.CHANGED:
213
+ case Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.CRITICAL:
214
+ case Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.LOW:
215
+ this.updateDeviceBattery(eventData, device);
216
+ break;
217
+ }
126
218
  }
127
- catch (error) {
128
- this.logger.error("[DT | CDL]:[DeviceEventHandler]: Error dumping to event operation", error);
219
+ async updateDeviceStatus(data, device) {
220
+ this.logger.info("[DT | CDL]:[DeviceEventHandler]: Updating device status", {
221
+ data,
222
+ device,
223
+ });
129
224
  }
130
- }
131
- async updateTablesBasedOnEventType(eventData, device) {
132
- switch (eventData.eventName) {
133
- case Event_1.DT_EVENT_TYPES.DEVICE.STATUS.ONLINE:
134
- case Event_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE:
135
- case Event_1.DT_EVENT_TYPES.DEVICE.STATUS.CHANGED:
136
- this.updateDeviceStatus(eventData, device);
137
- break;
138
- case Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.CHANGED:
139
- case Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.CRITICAL:
140
- case Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.LOW:
141
- this.updateDeviceBattery(eventData, device);
142
- break;
225
+ async updateDeviceBattery(data, device) {
226
+ this.logger.info("[DT | CDL]:[DeviceEventHandler]: Updating device battery", {
227
+ data,
228
+ device,
229
+ });
143
230
  }
144
- }
145
- async updateDeviceStatus(data, device) {
146
- this.logger.info("[DT | CDL]:[DeviceEventHandler]: Updating device status", {
147
- data,
148
- device,
149
- });
150
- }
151
- async updateDeviceBattery(data, device) {
152
- this.logger.info("[DT | CDL]:[DeviceEventHandler]: Updating device battery", {
153
- data,
154
- device,
155
- });
156
- }
157
- }
231
+ };
232
+ __setFunctionName(_classThis, "DeviceEventHandler");
233
+ (() => {
234
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
235
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
236
+ DeviceEventHandler = _classThis = _classDescriptor.value;
237
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
238
+ __runInitializers(_classThis, _classExtraInitializers);
239
+ })();
240
+ return DeviceEventHandler = _classThis;
241
+ })();
158
242
  exports.DeviceEventHandler = DeviceEventHandler;
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export { CloudDevice, CloudDeviceService, DeviceFactory, } from "./device/cloud/
4
4
  export { LocalDeviceService, LocalHubService, LocalScheduleService, } from "./device/local/services";
5
5
  export * from "./device/local/interfaces";
6
6
  export * from "./device/cloud/interfaces";
7
+ export * from "./admin";
7
8
  export * from "./connection";
8
9
  export * from "./property";
9
10
  export * from "./events";
package/dist/index.js CHANGED
@@ -31,6 +31,8 @@ Object.defineProperty(exports, "LocalHubService", { enumerable: true, get: funct
31
31
  Object.defineProperty(exports, "LocalScheduleService", { enumerable: true, get: function () { return services_1.LocalScheduleService; } });
32
32
  __exportStar(require("./device/local/interfaces"), exports);
33
33
  __exportStar(require("./device/cloud/interfaces"), exports);
34
+ // ADMIN EXPORTS
35
+ __exportStar(require("./admin"), exports);
34
36
  // CONNECTION EXPORTS
35
37
  __exportStar(require("./connection"), exports);
36
38
  // PROPERTY EXPORTS
@@ -7,6 +7,8 @@ export declare function validateServiceUrl(url: string): boolean;
7
7
  */
8
8
  export declare function createAxiosInstance(baseURL?: string): import("axios").AxiosInstance;
9
9
  export declare function getDeviceServiceAxiosInstance(): any;
10
+ export declare function getAccessServiceAxiosInstance(): any;
11
+ export declare function getCloudServiceAxiosInstance(): any;
10
12
  /**
11
13
  * Retry function for failed HTTP requests
12
14
  */