dt-common-device 3.0.1 → 3.0.3

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 (87) hide show
  1. package/README.md +7 -2
  2. package/dist/alerts/Alert.model.js +8 -2
  3. package/dist/alerts/Alert.repository.d.ts +3 -3
  4. package/dist/alerts/Alert.repository.js +28 -5
  5. package/dist/alerts/Alert.service.d.ts +18 -4
  6. package/dist/alerts/Alert.service.js +34 -3
  7. package/dist/alerts/AlertBuilder.d.ts +1 -1
  8. package/dist/alerts/AlertBuilder.js +1 -1
  9. package/dist/alerts/AlertService.example.js +5 -3
  10. package/dist/alerts/alert.types.d.ts +3 -3
  11. package/dist/config/config.d.ts +1 -1
  12. package/dist/config/config.js +3 -3
  13. package/dist/connection/Connection.repository.js +1 -1
  14. package/dist/constants/ConnectionProviders.d.ts +11 -0
  15. package/dist/constants/ConnectionProviders.js +14 -0
  16. package/dist/constants/Event.d.ts +14 -0
  17. package/dist/constants/Event.js +14 -0
  18. package/dist/constants/Service.d.ts +15 -0
  19. package/dist/constants/Service.js +19 -0
  20. package/dist/constants/index.d.ts +3 -0
  21. package/dist/constants/index.js +19 -0
  22. package/dist/device/cloud/entities/CloudDevice.d.ts +2 -2
  23. package/dist/device/cloud/entities/CloudDeviceService.d.ts +1 -1
  24. package/dist/device/cloud/entities/DeviceFactory.d.ts +1 -1
  25. package/dist/device/cloud/entities/DeviceFactory.js +1 -1
  26. package/dist/device/local/interfaces/IDevice.d.ts +3 -2
  27. package/dist/device/local/repository/Device.repository.js +3 -3
  28. package/dist/device/local/repository/Hub.repository.js +3 -3
  29. package/dist/device/local/repository/Schedule.repository.js +2 -2
  30. package/dist/device/local/services/Device.service.d.ts +11 -2
  31. package/dist/device/local/services/Device.service.js +145 -25
  32. package/dist/events/BaseEventHandler.d.ts +2 -2
  33. package/dist/events/BaseEventHandler.js +2 -2
  34. package/dist/events/BaseEventTransformer.d.ts +1 -1
  35. package/dist/events/BaseEventTransformer.js +1 -1
  36. package/dist/events/DeviceEventHandler.d.ts +1 -1
  37. package/dist/events/DeviceEventHandler.js +4 -3
  38. package/dist/events/EventHandler.js +1 -1
  39. package/dist/events/EventHandlerOrchestrator.js +1 -1
  40. package/dist/events/EventProcessingService.js +1 -1
  41. package/dist/events/InternalEventSubscription.js +1 -1
  42. package/dist/index.d.ts +1 -0
  43. package/dist/index.js +2 -0
  44. package/dist/issues/Issue.service.d.ts +11 -1
  45. package/dist/issues/Issue.service.js +16 -3
  46. package/dist/issues/IssueService.example.js +4 -2
  47. package/dist/queue/entities/HybridHttpQueue.d.ts +1 -0
  48. package/dist/queue/entities/HybridHttpQueue.js +2 -1
  49. package/dist/queue/interfaces/IHybridHttpQueue.d.ts +1 -0
  50. package/dist/queue/services/QueueService.d.ts +1 -0
  51. package/dist/queue/types/http.types.d.ts +1 -0
  52. package/package.json +1 -1
  53. package/src/alerts/Alert.model.ts +8 -2
  54. package/src/alerts/Alert.repository.ts +28 -6
  55. package/src/alerts/Alert.service.ts +91 -7
  56. package/src/alerts/AlertBuilder.ts +2 -2
  57. package/src/alerts/AlertService.example.ts +5 -3
  58. package/src/alerts/alert.types.ts +3 -3
  59. package/src/config/config.ts +3 -3
  60. package/src/connection/Connection.repository.ts +1 -1
  61. package/src/constants/ConnectionProviders.ts +11 -0
  62. package/src/constants/Event.ts +14 -0
  63. package/src/constants/Service.ts +17 -0
  64. package/src/constants/index.ts +3 -0
  65. package/src/device/cloud/entities/CloudDevice.ts +2 -2
  66. package/src/device/cloud/entities/CloudDeviceService.ts +1 -1
  67. package/src/device/cloud/entities/DeviceFactory.ts +2 -2
  68. package/src/device/local/interfaces/IDevice.ts +3 -2
  69. package/src/device/local/repository/Device.repository.ts +3 -3
  70. package/src/device/local/repository/Hub.repository.ts +3 -3
  71. package/src/device/local/repository/Schedule.repository.ts +2 -2
  72. package/src/device/local/services/Device.service.ts +231 -29
  73. package/src/events/BaseEventHandler.ts +3 -3
  74. package/src/events/BaseEventTransformer.ts +2 -2
  75. package/src/events/DeviceEventHandler.ts +6 -4
  76. package/src/events/EventHandler.ts +1 -1
  77. package/src/events/EventHandlerOrchestrator.ts +2 -2
  78. package/src/events/EventProcessingService.ts +2 -2
  79. package/src/events/InternalEventSubscription.ts +2 -2
  80. package/src/index.ts +3 -0
  81. package/src/issues/Issue.service.ts +67 -7
  82. package/src/issues/IssueService.example.ts +4 -2
  83. package/src/queue/entities/HybridHttpQueue.ts +3 -1
  84. package/src/queue/interfaces/IHybridHttpQueue.ts +1 -0
  85. package/src/queue/services/QueueService.ts +1 -0
  86. package/src/queue/types/http.types.ts +1 -0
  87. package/tsconfig.json +0 -4
package/README.md CHANGED
@@ -143,11 +143,16 @@ await deviceService.setState(deviceId, newState);
143
143
 
144
144
  // Status management
145
145
  const status = await deviceService.getStatus(deviceId);
146
- await deviceService.setStatus(deviceId, newStatus);
146
+ await deviceService.setStatus(
147
+ deviceId,
148
+ newStatus,
149
+ "heartbeat",
150
+ "Device went offline due to network connectivity issues"
151
+ );
147
152
 
148
153
  // Battery management
149
154
  const battery = await deviceService.getBatteryLevel(deviceId);
150
- await deviceService.setBatteryLevel(deviceId, batteryLevel);
155
+ await deviceService.setBatteryLevel(deviceId, batteryLevel, "heartbeat");
151
156
 
152
157
  // Metadata management
153
158
  const metadata = await deviceService.getMetaData(deviceId);
@@ -39,9 +39,15 @@ const alert_types_1 = require("./alert.types");
39
39
  // Main Alert schema
40
40
  const AlertSchema = new mongoose_1.Schema({
41
41
  category: {
42
- type: String,
42
+ type: [String],
43
43
  enum: Object.values(alert_types_1.AlertCategory),
44
44
  required: true,
45
+ validate: {
46
+ validator: function (categories) {
47
+ return categories && categories.length > 0;
48
+ },
49
+ message: "At least one category is required",
50
+ },
45
51
  },
46
52
  propertyId: {
47
53
  type: String,
@@ -164,7 +170,7 @@ AlertSchema.statics.findByEntity = function (entityId, entityType, includeDelete
164
170
  return this.find(query).sort({ createdAt: -1 });
165
171
  };
166
172
  AlertSchema.statics.findByCategory = function (category, includeDeleted = false) {
167
- const query = { category };
173
+ const query = { category: { $in: [category] } };
168
174
  if (!includeDeleted) {
169
175
  query.isDeleted = false;
170
176
  }
@@ -14,7 +14,7 @@ export declare class AlertRepository {
14
14
  */
15
15
  findAll(filters?: {
16
16
  propertyId?: string;
17
- category?: AlertCategory;
17
+ category?: AlertCategory | AlertCategory[];
18
18
  severity?: AlertSeverity;
19
19
  entityType?: EntityType;
20
20
  entityId?: string;
@@ -44,7 +44,7 @@ export declare class AlertRepository {
44
44
  */
45
45
  count(filters?: {
46
46
  propertyId?: string;
47
- category?: AlertCategory;
47
+ category?: AlertCategory | AlertCategory[];
48
48
  severity?: AlertSeverity;
49
49
  entityType?: EntityType;
50
50
  entityId?: string;
@@ -63,7 +63,7 @@ export declare class AlertRepository {
63
63
  /**
64
64
  * Find alerts by category
65
65
  */
66
- findByCategory(category: AlertCategory, includeDeleted?: boolean): Promise<IAlertDocument[]>;
66
+ findByCategory(category: AlertCategory | AlertCategory[], includeDeleted?: boolean): Promise<IAlertDocument[]>;
67
67
  /**
68
68
  * Find alerts by severity
69
69
  */
@@ -89,8 +89,14 @@ let AlertRepository = (() => {
89
89
  const query = {};
90
90
  if (filters.propertyId)
91
91
  query.propertyId = filters.propertyId;
92
- if (filters.category)
93
- query.category = filters.category;
92
+ if (filters.category) {
93
+ if (Array.isArray(filters.category)) {
94
+ query.category = { $in: filters.category };
95
+ }
96
+ else {
97
+ query.category = { $in: [filters.category] };
98
+ }
99
+ }
94
100
  if (filters.severity)
95
101
  query.severity = filters.severity;
96
102
  if (filters.entityType)
@@ -167,8 +173,14 @@ let AlertRepository = (() => {
167
173
  const query = {};
168
174
  if (filters.propertyId)
169
175
  query.propertyId = filters.propertyId;
170
- if (filters.category)
171
- query.category = filters.category;
176
+ if (filters.category) {
177
+ if (Array.isArray(filters.category)) {
178
+ query.category = { $in: filters.category };
179
+ }
180
+ else {
181
+ query.category = { $in: [filters.category] };
182
+ }
183
+ }
172
184
  if (filters.severity)
173
185
  query.severity = filters.severity;
174
186
  if (filters.entityType)
@@ -214,7 +226,17 @@ let AlertRepository = (() => {
214
226
  */
215
227
  async findByCategory(category, includeDeleted = false) {
216
228
  try {
217
- return await Alert_model_1.AlertModel.findByCategory(category, includeDeleted);
229
+ if (Array.isArray(category)) {
230
+ // Use $in operator for array of categories
231
+ const query = { category: { $in: category } };
232
+ if (!includeDeleted) {
233
+ query.isDeleted = false;
234
+ }
235
+ return await Alert_model_1.AlertModel.find(query).sort({ createdAt: -1 });
236
+ }
237
+ else {
238
+ return await Alert_model_1.AlertModel.findByCategory(category, includeDeleted);
239
+ }
218
240
  }
219
241
  catch (error) {
220
242
  throw new Error(`Failed to find alerts by category: ${error instanceof Error ? error.message : "Unknown error"}`);
@@ -297,6 +319,7 @@ let AlertRepository = (() => {
297
319
  ]),
298
320
  Alert_model_1.AlertModel.aggregate([
299
321
  { $match: query },
322
+ { $unwind: "$category" },
300
323
  { $group: { _id: "$category", count: { $sum: 1 } } },
301
324
  ]),
302
325
  ]);
@@ -1,7 +1,9 @@
1
1
  import { AlertRepository } from "./Alert.repository";
2
2
  import { IAlertDocument } from "./Alert.model";
3
3
  import { CreateAlertData, UpdateAlertData, AlertCategory, AlertSeverity, EntityType } from "./alert.types";
4
+ import { Source } from "../constants/Service";
4
5
  import { AlertBuilder } from "./AlertBuilder";
6
+ import { IDevice } from "../device/local/interfaces";
5
7
  export declare class AlertService {
6
8
  private readonly alertRepository;
7
9
  constructor(alertRepository: AlertRepository);
@@ -24,11 +26,23 @@ export declare class AlertService {
24
26
  /**
25
27
  * Create a device-specific alert using AlertBuilder
26
28
  */
27
- raiseDeviceAlert(deviceId: string, propertyId: string, title: string, description: string, category?: AlertCategory, severity?: AlertSeverity, createdBy?: string): Promise<IAlertDocument>;
29
+ raiseDeviceAlert(deviceId: string, propertyId: string, title: string, description: string, category?: AlertCategory | AlertCategory[], severity?: AlertSeverity, source?: Source): Promise<IAlertDocument>;
28
30
  /**
29
31
  * Create a hub-specific alert using AlertBuilder
30
32
  */
31
- raiseHubAlert(hubId: string, propertyId: string, title: string, description: string, category?: AlertCategory, severity?: AlertSeverity, createdBy?: string): Promise<IAlertDocument>;
33
+ raiseHubAlert(hubId: string, propertyId: string, title: string, description: string, category?: AlertCategory | AlertCategory[], severity?: AlertSeverity, createdBy?: string): Promise<IAlertDocument>;
34
+ /**
35
+ * Raise alert for device going offline
36
+ */
37
+ raiseDeviceOfflineAlert(device: IDevice, source: Source, reason?: string): Promise<IAlertDocument>;
38
+ /**
39
+ * Raise alert for device coming online
40
+ */
41
+ raiseDeviceOnlineAlert(device: IDevice, source: Source, reason?: string): Promise<IAlertDocument>;
42
+ /**
43
+ * Raise alert for device battery level below threshold
44
+ */
45
+ raiseDeviceBatteryAlert(device: IDevice, batteryLevel: number, threshold: number, source: Source): Promise<IAlertDocument>;
32
46
  /**
33
47
  * Create a new alert with business logic validation
34
48
  * Accepts either a CreateAlertData object or an AlertBuilder instance
@@ -43,7 +57,7 @@ export declare class AlertService {
43
57
  */
44
58
  getAlerts(filters?: {
45
59
  propertyId?: string;
46
- category?: AlertCategory;
60
+ category?: AlertCategory | AlertCategory[];
47
61
  severity?: AlertSeverity;
48
62
  entityType?: EntityType;
49
63
  entityId?: string;
@@ -96,7 +110,7 @@ export declare class AlertService {
96
110
  /**
97
111
  * Get alerts by category with business logic
98
112
  */
99
- getAlertsByCategory(category: AlertCategory, includeDeleted?: boolean): Promise<IAlertDocument[]>;
113
+ getAlertsByCategory(category: AlertCategory | AlertCategory[], includeDeleted?: boolean): Promise<IAlertDocument[]>;
100
114
  /**
101
115
  * Get alerts by severity with business logic
102
116
  */
@@ -119,7 +119,7 @@ let AlertService = (() => {
119
119
  /**
120
120
  * Create a device-specific alert using AlertBuilder
121
121
  */
122
- async raiseDeviceAlert(deviceId, propertyId, title, description, category, severity, createdBy) {
122
+ async raiseDeviceAlert(deviceId, propertyId, title, description, category, severity, source) {
123
123
  const alertBuilder = AlertBuilder_1.AlertBuilder.createDeviceAlert(deviceId, propertyId)
124
124
  .setTitle(title)
125
125
  .setDescription(description);
@@ -127,8 +127,8 @@ let AlertService = (() => {
127
127
  alertBuilder.setCategory(category);
128
128
  if (severity)
129
129
  alertBuilder.setSeverity(severity);
130
- if (createdBy)
131
- alertBuilder.setCreatedBy(createdBy);
130
+ if (source)
131
+ alertBuilder.setCreatedBy(source);
132
132
  return await this.createAlert(alertBuilder);
133
133
  }
134
134
  /**
@@ -146,6 +146,24 @@ let AlertService = (() => {
146
146
  alertBuilder.setCreatedBy(createdBy);
147
147
  return await this.createAlert(alertBuilder);
148
148
  }
149
+ /**
150
+ * Raise alert for device going offline
151
+ */
152
+ async raiseDeviceOfflineAlert(device, source, reason) {
153
+ return await this.raiseDeviceAlert(device.deviceId, device.propertyId, "Device Offline", `Device ${device.name} (${device.deviceId}) has gone offline. ${reason ? `Reason: ${reason}` : ""}`, [alert_types_1.AlertCategory.OPERATIONS], alert_types_1.AlertSeverity.HIGH, source);
154
+ }
155
+ /**
156
+ * Raise alert for device coming online
157
+ */
158
+ async raiseDeviceOnlineAlert(device, source, reason) {
159
+ return await this.raiseDeviceAlert(device.deviceId, device.propertyId, "Device Online", `Device ${device.name} (${device.deviceId}) is now online. ${reason ? `Reason: ${reason}` : ""}`, [alert_types_1.AlertCategory.OPERATIONS], alert_types_1.AlertSeverity.INFO, source);
160
+ }
161
+ /**
162
+ * Raise alert for device battery level below threshold
163
+ */
164
+ async raiseDeviceBatteryAlert(device, batteryLevel, threshold, source) {
165
+ return await this.raiseDeviceAlert(device.deviceId, device.propertyId, "Device Battery Low", `Device ${device.name} (${device.deviceId}) battery level is ${batteryLevel}%, which is below the property threshold of ${threshold}%.`, [alert_types_1.AlertCategory.ENERGY], alert_types_1.AlertSeverity.MEDIUM, source);
166
+ }
149
167
  /**
150
168
  * Create a new alert with business logic validation
151
169
  * Accepts either a CreateAlertData object or an AlertBuilder instance
@@ -451,6 +469,19 @@ let AlertService = (() => {
451
469
  [alert_types_1.AlertCategory.ENERGY]: alert_types_1.AlertSeverity.LOW,
452
470
  [alert_types_1.AlertCategory.OTHER]: alert_types_1.AlertSeverity.MEDIUM,
453
471
  };
472
+ // If it's an array, use the highest severity category
473
+ if (Array.isArray(category)) {
474
+ const severities = category.map((cat) => categorySeverities[cat] || alert_types_1.AlertSeverity.MEDIUM);
475
+ const severityOrder = [
476
+ alert_types_1.AlertSeverity.CRITICAL,
477
+ alert_types_1.AlertSeverity.HIGH,
478
+ alert_types_1.AlertSeverity.MEDIUM,
479
+ alert_types_1.AlertSeverity.LOW,
480
+ alert_types_1.AlertSeverity.INFO,
481
+ ];
482
+ return (severityOrder.find((severity) => severities.includes(severity)) ||
483
+ alert_types_1.AlertSeverity.MEDIUM);
484
+ }
454
485
  return categorySeverities[category] || alert_types_1.AlertSeverity.MEDIUM;
455
486
  }
456
487
  applyBusinessRules(filters) {
@@ -23,7 +23,7 @@ export declare class AlertBuilder {
23
23
  /**
24
24
  * Sets the alert category
25
25
  */
26
- setCategory(category: AlertCategory): AlertBuilder;
26
+ setCategory(category: AlertCategory | AlertCategory[]): AlertBuilder;
27
27
  /**
28
28
  * Sets the property ID
29
29
  */
@@ -29,7 +29,7 @@ class AlertBuilder {
29
29
  * Sets the alert category
30
30
  */
31
31
  setCategory(category) {
32
- this.data.category = category;
32
+ this.data.category = Array.isArray(category) ? category : [category];
33
33
  return this;
34
34
  }
35
35
  /**
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AlertServiceExample = void 0;
4
+ const Service_1 = require("../constants/Service");
4
5
  const AlertBuilder_1 = require("./AlertBuilder");
5
6
  const alert_types_1 = require("./alert.types");
6
7
  /**
@@ -49,9 +50,9 @@ class AlertServiceExample {
49
50
  // Create a device alert with default category and severity
50
51
  const deviceAlert1 = await this.alertService.raiseDeviceAlert("device123", "prop456", "Device Battery Low", "Device battery level is below 20%", undefined, // Use default category
51
52
  undefined, // Use default severity
52
- "system");
53
+ Service_1.Source.CLOUD_EVENT);
53
54
  // Create a device alert with custom category and severity
54
- const deviceAlert2 = await this.alertService.raiseDeviceAlert("device789", "prop456", "Device Firmware Update Available", "New firmware version is available for installation", alert_types_1.AlertCategory.READINESS, alert_types_1.AlertSeverity.MEDIUM, "firmware-manager");
55
+ const deviceAlert2 = await this.alertService.raiseDeviceAlert("device789", "prop456", "Device Firmware Update Available", "New firmware version is available for installation", alert_types_1.AlertCategory.READINESS, alert_types_1.AlertSeverity.MEDIUM, Service_1.Source.CLOUD_EVENT);
55
56
  return { deviceAlert1, deviceAlert2 };
56
57
  }
57
58
  /**
@@ -131,7 +132,7 @@ class AlertServiceExample {
131
132
  */
132
133
  async createAlertWithLegacyData() {
133
134
  const alertData = {
134
- category: alert_types_1.AlertCategory.OPERATIONS,
135
+ category: [alert_types_1.AlertCategory.OPERATIONS],
135
136
  propertyId: "prop123",
136
137
  title: "Legacy Alert",
137
138
  description: "This alert was created using the old CreateAlertData format",
@@ -139,6 +140,7 @@ class AlertServiceExample {
139
140
  entityType: alert_types_1.EntityType.DEVICE,
140
141
  severity: alert_types_1.AlertSeverity.MEDIUM,
141
142
  createdBy: "legacy-system",
143
+ source: Service_1.Source.CLOUD_EVENT,
142
144
  };
143
145
  // This still works with the updated createAlert method
144
146
  const alert = await this.alertService.createAlert(alertData);
@@ -15,7 +15,7 @@ export declare enum AlertSeverity {
15
15
  }
16
16
  export interface AlertDocument {
17
17
  _id: string;
18
- category: AlertCategory;
18
+ category: AlertCategory[];
19
19
  propertyId: string;
20
20
  title: string;
21
21
  description: string;
@@ -32,7 +32,7 @@ export interface AlertDocument {
32
32
  updatedAt: Date;
33
33
  }
34
34
  export interface CreateAlertData {
35
- category: AlertCategory;
35
+ category: AlertCategory[];
36
36
  propertyId: string;
37
37
  title: string;
38
38
  description: string;
@@ -43,7 +43,7 @@ export interface CreateAlertData {
43
43
  snoozeUntil?: Date;
44
44
  }
45
45
  export interface UpdateAlertData {
46
- category?: AlertCategory;
46
+ category?: AlertCategory[];
47
47
  title?: string;
48
48
  description?: string;
49
49
  entityId?: string;
@@ -1,4 +1,4 @@
1
- import { InternalEventSubscription } from "src/events";
1
+ import { InternalEventSubscription } from "../events";
2
2
  import { IConfig } from "./config.types";
3
3
  export declare function initialize(cfg: IConfig): Promise<void>;
4
4
  export declare function getConfig(): IConfig;
@@ -13,10 +13,10 @@ exports.getMongoUri = getMongoUri;
13
13
  exports.getRedisDbHostAndPort = getRedisDbHostAndPort;
14
14
  exports.shutdown = shutdown;
15
15
  const dt_audit_library_1 = require("dt-audit-library");
16
- const db_1 = require("src/db/db");
16
+ const db_1 = require("../db/db");
17
17
  const dotenv_1 = __importDefault(require("dotenv"));
18
- const events_1 = require("src/events");
19
- const http_utils_1 = require("src/utils/http.utils");
18
+ const events_1 = require("../events");
19
+ const http_utils_1 = require("../utils/http.utils");
20
20
  dotenv_1.default.config();
21
21
  let config = null;
22
22
  let auditInitialized = false;
@@ -39,7 +39,7 @@ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, p
39
39
  };
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.ConnectionRepository = void 0;
42
- const db_1 = require("src/db");
42
+ const db_1 = require("../db");
43
43
  const typedi_1 = require("typedi");
44
44
  let ConnectionRepository = (() => {
45
45
  let _classDecorators = [(0, typedi_1.Service)()];
@@ -0,0 +1,11 @@
1
+ export declare const CONNECTION_PROVIDERS: {
2
+ readonly DEVICETHREAD: "Devicethread";
3
+ readonly SALTOKS: "SaltoKS";
4
+ readonly SCHLAGE: "Schlage";
5
+ readonly SENSIBO: "Sensibo";
6
+ readonly SMARTTHINGS: "Smartthings";
7
+ readonly TTLOCK: "TTLock";
8
+ readonly TUYA: "Tuya";
9
+ readonly VERDANT: "Verdant";
10
+ readonly YALEWIFI: "YaleWifi";
11
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CONNECTION_PROVIDERS = void 0;
4
+ exports.CONNECTION_PROVIDERS = {
5
+ DEVICETHREAD: "Devicethread",
6
+ SALTOKS: "SaltoKS",
7
+ SCHLAGE: "Schlage",
8
+ SENSIBO: "Sensibo",
9
+ SMARTTHINGS: "Smartthings",
10
+ TTLOCK: "TTLock",
11
+ TUYA: "Tuya",
12
+ VERDANT: "Verdant",
13
+ YALEWIFI: "YaleWifi",
14
+ };
@@ -39,6 +39,20 @@ export declare const DT_EVENT_TYPES: {
39
39
  UPDATED: string;
40
40
  CHANGED: string;
41
41
  };
42
+ EVENT: {
43
+ RECEIVED: string;
44
+ REGISTERED: string;
45
+ UNREGISTERED: string;
46
+ PROCESSED: string;
47
+ UNPROCESSED: string;
48
+ };
49
+ WEBHOOK: {
50
+ RECEIVED: string;
51
+ REGISTERED: string;
52
+ UNREGISTERED: string;
53
+ PROCESSED: string;
54
+ UNPROCESSED: string;
55
+ };
42
56
  };
43
57
  CONNECTION: {
44
58
  CREATE: {
@@ -42,6 +42,20 @@ exports.DT_EVENT_TYPES = {
42
42
  UPDATED: "device.metaData.updated",
43
43
  CHANGED: "device.metaData.changed",
44
44
  },
45
+ EVENT: {
46
+ RECEIVED: "device.event.received",
47
+ REGISTERED: "device.event.registered",
48
+ UNREGISTERED: "device.event.unregistered",
49
+ PROCESSED: "device.event.processed",
50
+ UNPROCESSED: "device.event.unprocessed",
51
+ },
52
+ WEBHOOK: {
53
+ RECEIVED: "device.webhook.received",
54
+ REGISTERED: "device.webhook.registered",
55
+ UNREGISTERED: "device.webhook.unregistered",
56
+ PROCESSED: "device.webhook.processed",
57
+ UNPROCESSED: "device.webhook.unprocessed",
58
+ },
45
59
  },
46
60
  CONNECTION: {
47
61
  CREATE: {
@@ -0,0 +1,15 @@
1
+ export declare const SERVICE_NAMES: {
2
+ readonly CLOUD: "smart-cloud";
3
+ readonly ACCESS: "smart-access";
4
+ readonly ENERGY: "smart-energy";
5
+ readonly SCHEDULE: "smart-schedule";
6
+ readonly DEVICE: "smart-device";
7
+ };
8
+ export declare enum Source {
9
+ USER = "user",
10
+ CLOUD_EVENT = "cloud-event",
11
+ CLOUD_WEBHOOK = "cloud-webhook",
12
+ HEARTBEAT = "heartbeat",
13
+ CODE_ACTION = "code-action",
14
+ DEVICE_ACTION = "device-action"
15
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Source = exports.SERVICE_NAMES = void 0;
4
+ exports.SERVICE_NAMES = {
5
+ CLOUD: "smart-cloud",
6
+ ACCESS: "smart-access",
7
+ ENERGY: "smart-energy",
8
+ SCHEDULE: "smart-schedule",
9
+ DEVICE: "smart-device",
10
+ };
11
+ var Source;
12
+ (function (Source) {
13
+ Source["USER"] = "user";
14
+ Source["CLOUD_EVENT"] = "cloud-event";
15
+ Source["CLOUD_WEBHOOK"] = "cloud-webhook";
16
+ Source["HEARTBEAT"] = "heartbeat";
17
+ Source["CODE_ACTION"] = "code-action";
18
+ Source["DEVICE_ACTION"] = "device-action";
19
+ })(Source || (exports.Source = Source = {}));
@@ -0,0 +1,3 @@
1
+ export * from "./ConnectionProviders";
2
+ export * from "./Event";
3
+ export * from "./Service";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ConnectionProviders"), exports);
18
+ __exportStar(require("./Event"), exports);
19
+ __exportStar(require("./Service"), exports);
@@ -1,7 +1,7 @@
1
- import { IDevice } from "src/device/local/interfaces";
1
+ import { IDevice } from "../../local/interfaces";
2
2
  import { ICloudDevice } from "../interfaces/ICloudDevice";
3
3
  import { ICloudDeviceService } from "../interfaces/ICloudDeviceService";
4
- import { IConnection } from "src/connection";
4
+ import { IConnection } from "../../../connection";
5
5
  export declare abstract class CloudDevice implements ICloudDevice {
6
6
  deviceId: string;
7
7
  localDevice?: IDevice;
@@ -1,5 +1,5 @@
1
1
  import { ICloudDeviceService } from "../interfaces/ICloudDeviceService";
2
- import { IConnection } from "src/connection";
2
+ import { IConnection } from "../../../connection";
3
3
  export declare class CloudDeviceService implements ICloudDeviceService {
4
4
  getConnection(deviceId: string): Promise<IConnection>;
5
5
  }
@@ -1,4 +1,4 @@
1
- import { IDevice } from "src/device/local/interfaces";
1
+ import { IDevice } from "../../local/interfaces";
2
2
  import { IDeviceFactory } from "../interfaces/IDeviceFactory";
3
3
  export declare class DeviceFactory implements IDeviceFactory {
4
4
  private readonly localDeviceService;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DeviceFactory = void 0;
4
- const Device_service_1 = require("src/device/local/services/Device.service");
4
+ const Device_service_1 = require("../../local/services/Device.service");
5
5
  class DeviceFactory {
6
6
  constructor() {
7
7
  this.localDeviceService = new Device_service_1.LocalDeviceService();
@@ -40,14 +40,15 @@ export interface IDevice {
40
40
  value: boolean;
41
41
  lastUpdated: string;
42
42
  };
43
- state?: object;
44
- metaData?: object;
43
+ state?: Record<string, any>;
44
+ metaData?: Record<string, any>;
45
45
  createdAt?: Date;
46
46
  updatedAt?: Date;
47
47
  hubDeviceDetails?: IDevice[];
48
48
  }
49
49
  export declare class IStatus {
50
50
  online: boolean;
51
+ liveStatus?: "ONLINE" | "OFFLINE";
51
52
  error?: {
52
53
  type?: string;
53
54
  message?: string;
@@ -39,10 +39,10 @@ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, p
39
39
  };
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.DeviceRepository = void 0;
42
- const config_1 = require("src/config/config");
43
- const db_1 = require("src/db");
42
+ const config_1 = require("../../../config/config");
43
+ const db_1 = require("../../../db");
44
44
  const typedi_1 = require("typedi");
45
- const http_utils_1 = require("src/utils/http.utils");
45
+ const http_utils_1 = require("../../../utils/http.utils");
46
46
  let DeviceRepository = (() => {
47
47
  let _classDecorators = [(0, typedi_1.Service)()];
48
48
  let _classDescriptor;
@@ -39,10 +39,10 @@ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, p
39
39
  };
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.HubRepository = void 0;
42
- const config_1 = require("src/config/config");
43
- const db_1 = require("src/db");
42
+ const config_1 = require("../../../config/config");
43
+ const db_1 = require("../../../db");
44
44
  const typedi_1 = require("typedi");
45
- const http_utils_1 = require("src/utils/http.utils");
45
+ const http_utils_1 = require("../../../utils/http.utils");
46
46
  let HubRepository = (() => {
47
47
  let _classDecorators = [(0, typedi_1.Service)()];
48
48
  let _classDescriptor;
@@ -40,8 +40,8 @@ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, p
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.ScheduleRepository = void 0;
42
42
  const typedi_1 = require("typedi");
43
- const config_1 = require("src/config/config");
44
- const http_utils_1 = require("src/utils/http.utils");
43
+ const config_1 = require("../../../config/config");
44
+ const http_utils_1 = require("../../../utils/http.utils");
45
45
  let ScheduleRepository = (() => {
46
46
  let _classDecorators = [(0, typedi_1.Service)()];
47
47
  let _classDescriptor;
@@ -1,7 +1,11 @@
1
1
  import { IDevice, IStatus } from "../interfaces";
2
+ import { Source } from "../../../constants/Service";
2
3
  export declare class LocalDeviceService {
3
4
  private readonly eventHandler;
4
5
  private readonly deviceRepository;
6
+ private readonly alertService;
7
+ private readonly issueService;
8
+ private readonly logger;
5
9
  constructor();
6
10
  createDevice(body: IDevice): Promise<IDevice>;
7
11
  getDevice(deviceId: string, withHubDetails?: boolean): Promise<IDevice>;
@@ -13,9 +17,14 @@ export declare class LocalDeviceService {
13
17
  getState(deviceId: string): Promise<any>;
14
18
  setState(deviceId: string, newState: any): Promise<void>;
15
19
  getStatus(deviceId: string): Promise<Record<string, any>>;
16
- setStatus(deviceId: string, newStatus: IStatus): Promise<void>;
20
+ setStatus(deviceId: string, newStatus: IStatus, source: Source, reason?: string): Promise<void>;
21
+ private handleOfflineStatus;
22
+ private handleOnlineStatus;
23
+ private getDeviceBaseline;
17
24
  getBatteryLevel(deviceId: string): Promise<Record<string, any>>;
18
- setBatteryLevel(deviceId: string, batteryLevel: number): Promise<void>;
25
+ setBatteryLevel(deviceId: string, batteryLevel: number, source: Source): Promise<void>;
26
+ private shouldUpdateBatteryLevel;
27
+ private getPropertyBatteryThreshold;
19
28
  getMetaData(deviceId: string): Promise<any>;
20
29
  setMetaData(deviceId: string, metaData: Record<string, any>): Promise<any>;
21
30
  getDevicesByZone(zoneId: string): Promise<import("../interfaces").IDtDevice[]>;