dt-common-device 7.10.9 → 7.10.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alerts/Alert.service.d.ts +3 -5
- package/dist/alerts/Alert.service.js +37 -9
- package/dist/alerts/AlertBuilder.d.ts +2 -2
- package/dist/alerts/AlertBuilder.js +4 -6
- package/dist/alerts/alert.types.d.ts +1 -0
- package/dist/constants/Event.d.ts +19 -0
- package/dist/constants/Event.js +31 -12
- package/dist/issues/Issue.service.d.ts +3 -5
- package/dist/issues/Issue.service.js +27 -2
- package/package.json +1 -1
|
@@ -25,13 +25,10 @@ export declare class AlertService {
|
|
|
25
25
|
startDate: string;
|
|
26
26
|
endDate: string;
|
|
27
27
|
}): Promise<IAlertDocument | null>;
|
|
28
|
-
raiseNewDeviceAlert(
|
|
29
|
-
deviceId: string;
|
|
30
|
-
deviceType: string;
|
|
31
|
-
name: string;
|
|
32
|
-
}, connection: {
|
|
28
|
+
raiseNewDeviceAlert(connection: {
|
|
33
29
|
id: string;
|
|
34
30
|
provider: string;
|
|
31
|
+
deviceCount: number;
|
|
35
32
|
type?: string;
|
|
36
33
|
}, propertyId: string, source: Source): Promise<IAlertDocument | null>;
|
|
37
34
|
raiseDoorOpenFrequentAlert(device: IDevice, zone: any, accessTimes: number, openThreshold: number, source: Source): Promise<IAlertDocument | null>;
|
|
@@ -65,6 +62,7 @@ export declare class AlertService {
|
|
|
65
62
|
* Update an alert with business logic validation
|
|
66
63
|
*/
|
|
67
64
|
updateAlert(id: string, updateData: UpdateAlertData): Promise<IAlertDocument | null>;
|
|
65
|
+
deleteAlerts(filters: IAlertQuery, deletedBy: string, softDelete?: boolean): Promise<boolean>;
|
|
68
66
|
/**
|
|
69
67
|
* Soft delete an alert with business logic
|
|
70
68
|
*/
|
|
@@ -95,7 +95,6 @@ let AlertService = (() => {
|
|
|
95
95
|
async raiseOperationsAlert(data) {
|
|
96
96
|
const alertBuilder = AlertBuilder_1.AlertBuilder.createOperationsAlert()
|
|
97
97
|
.setPropertyId(data.propertyId)
|
|
98
|
-
.setZoneId(data.zoneId || "")
|
|
99
98
|
.setTitle(data.title)
|
|
100
99
|
.setDescription(data.description);
|
|
101
100
|
if (data.entityId)
|
|
@@ -106,6 +105,8 @@ let AlertService = (() => {
|
|
|
106
105
|
alertBuilder.setEntitySubType(data.entitySubType);
|
|
107
106
|
if (data.createdBy)
|
|
108
107
|
alertBuilder.setCreatedBy(data.createdBy);
|
|
108
|
+
if (data.zoneId)
|
|
109
|
+
alertBuilder.setZoneId(data.zoneId);
|
|
109
110
|
return await this.createAlert(alertBuilder);
|
|
110
111
|
}
|
|
111
112
|
/**
|
|
@@ -114,7 +115,6 @@ let AlertService = (() => {
|
|
|
114
115
|
async raiseSecurityAlert(data) {
|
|
115
116
|
const alertBuilder = AlertBuilder_1.AlertBuilder.createSecurityAlert()
|
|
116
117
|
.setPropertyId(data.propertyId)
|
|
117
|
-
.setZoneId(data.zoneId || "")
|
|
118
118
|
.setTitle(data.title)
|
|
119
119
|
.setDescription(data.description);
|
|
120
120
|
if (data.entityId)
|
|
@@ -125,10 +125,12 @@ let AlertService = (() => {
|
|
|
125
125
|
alertBuilder.setEntitySubType(data.entitySubType);
|
|
126
126
|
if (data.createdBy)
|
|
127
127
|
alertBuilder.setCreatedBy(data.createdBy);
|
|
128
|
+
if (data.zoneId)
|
|
129
|
+
alertBuilder.setZoneId(data.zoneId);
|
|
128
130
|
return await this.createAlert(alertBuilder);
|
|
129
131
|
}
|
|
130
132
|
async raiseDeviceAlert(data) {
|
|
131
|
-
const alertBuilder = AlertBuilder_1.AlertBuilder.createDeviceAlert(data.entityId || "", data.propertyId
|
|
133
|
+
const alertBuilder = AlertBuilder_1.AlertBuilder.createDeviceAlert(data.entityId || "", data.propertyId)
|
|
132
134
|
.setTitle(data.title)
|
|
133
135
|
.setDescription(data.description);
|
|
134
136
|
if (data.category)
|
|
@@ -141,13 +143,15 @@ let AlertService = (() => {
|
|
|
141
143
|
alertBuilder.setCreatedBy(data.createdBy);
|
|
142
144
|
if (data.entitySubType)
|
|
143
145
|
alertBuilder.setEntitySubType(data.entitySubType);
|
|
146
|
+
if (data.zoneId)
|
|
147
|
+
alertBuilder.setZoneId(data.zoneId);
|
|
144
148
|
return await this.createAlert(alertBuilder);
|
|
145
149
|
}
|
|
146
150
|
/**
|
|
147
151
|
* Create a hub-specific alert using AlertBuilder
|
|
148
152
|
*/
|
|
149
153
|
async raiseHubAlert(data) {
|
|
150
|
-
const alertBuilder = AlertBuilder_1.AlertBuilder.createHubAlert(data.entityId || "", data.propertyId
|
|
154
|
+
const alertBuilder = AlertBuilder_1.AlertBuilder.createHubAlert(data.entityId || "", data.propertyId)
|
|
151
155
|
.setTitle(data.title)
|
|
152
156
|
.setDescription(data.description);
|
|
153
157
|
if (data.category)
|
|
@@ -160,6 +164,8 @@ let AlertService = (() => {
|
|
|
160
164
|
alertBuilder.setCreatedBy(data.createdBy);
|
|
161
165
|
if (data.entitySubType)
|
|
162
166
|
alertBuilder.setEntitySubType(data.entitySubType);
|
|
167
|
+
if (data.zoneId)
|
|
168
|
+
alertBuilder.setZoneId(data.zoneId);
|
|
163
169
|
return await this.createAlert(alertBuilder);
|
|
164
170
|
}
|
|
165
171
|
async raiseDeviceTamperAttemptAlert(device, zone, source) {
|
|
@@ -207,14 +213,14 @@ let AlertService = (() => {
|
|
|
207
213
|
type: alert_types_1.AlertType.INCORRECT_CODE_USED,
|
|
208
214
|
});
|
|
209
215
|
}
|
|
210
|
-
async raiseNewDeviceAlert(
|
|
216
|
+
async raiseNewDeviceAlert(connection, propertyId, source) {
|
|
211
217
|
return await this.createAlert({
|
|
212
218
|
entityId: connection.id,
|
|
213
219
|
entityType: alert_types_1.EntityType.CLOUD_DEVICE_ACCOUNT,
|
|
214
220
|
entitySubType: connection.provider,
|
|
215
221
|
propertyId: propertyId,
|
|
216
222
|
title: "New Device Detected",
|
|
217
|
-
description:
|
|
223
|
+
description: `${connection.deviceCount} new device(s), have been detected on the ${connection.provider} account.`,
|
|
218
224
|
createdBy: source,
|
|
219
225
|
category: alert_types_1.AlertCategory.OPERATIONS,
|
|
220
226
|
severity: alert_types_1.AlertSeverity.INFO,
|
|
@@ -506,6 +512,31 @@ let AlertService = (() => {
|
|
|
506
512
|
}
|
|
507
513
|
return await this.alertRepository.update(id, updateData);
|
|
508
514
|
}
|
|
515
|
+
async deleteAlerts(filters, deletedBy, softDelete = true) {
|
|
516
|
+
try {
|
|
517
|
+
if (!filters || Object.keys(filters).length === 0) {
|
|
518
|
+
throw new Error("Filters are required");
|
|
519
|
+
}
|
|
520
|
+
if (!deletedBy) {
|
|
521
|
+
throw new Error("Deleted by user is required");
|
|
522
|
+
}
|
|
523
|
+
const alerts = await this.queryAlerts(filters);
|
|
524
|
+
if (softDelete) {
|
|
525
|
+
for (const alert of alerts) {
|
|
526
|
+
await this.alertRepository.softDelete(alert.id || alert._id, deletedBy);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
else {
|
|
530
|
+
for (const alert of alerts) {
|
|
531
|
+
await this.alertRepository.hardDelete(alert.id || alert._id);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
return true;
|
|
535
|
+
}
|
|
536
|
+
catch (error) {
|
|
537
|
+
throw new Error(`Failed to delete alerts: ${error instanceof Error ? error.message : error}`);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
509
540
|
/**
|
|
510
541
|
* Soft delete an alert with business logic
|
|
511
542
|
*/
|
|
@@ -743,9 +774,6 @@ let AlertService = (() => {
|
|
|
743
774
|
if (!data.propertyId) {
|
|
744
775
|
throw new Error("Property ID is required");
|
|
745
776
|
}
|
|
746
|
-
if (!data.zoneId) {
|
|
747
|
-
throw new Error("Zone ID is required");
|
|
748
|
-
}
|
|
749
777
|
if (!data.entityType) {
|
|
750
778
|
throw new Error("Entity type is required");
|
|
751
779
|
}
|
|
@@ -88,9 +88,9 @@ export declare class AlertBuilder {
|
|
|
88
88
|
/**
|
|
89
89
|
* Creates a device-specific alert builder
|
|
90
90
|
*/
|
|
91
|
-
static createDeviceAlert(deviceId: string, propertyId: string
|
|
91
|
+
static createDeviceAlert(deviceId: string, propertyId: string): AlertBuilder;
|
|
92
92
|
/**
|
|
93
93
|
* Creates a hub-specific alert builder
|
|
94
94
|
*/
|
|
95
|
-
static createHubAlert(hubId: string, propertyId: string
|
|
95
|
+
static createHubAlert(hubId: string, propertyId: string): AlertBuilder;
|
|
96
96
|
}
|
|
@@ -187,22 +187,20 @@ class AlertBuilder {
|
|
|
187
187
|
/**
|
|
188
188
|
* Creates a device-specific alert builder
|
|
189
189
|
*/
|
|
190
|
-
static createDeviceAlert(deviceId, propertyId
|
|
190
|
+
static createDeviceAlert(deviceId, propertyId) {
|
|
191
191
|
return new AlertBuilder()
|
|
192
192
|
.setEntityType(alert_types_1.EntityType.DEVICE)
|
|
193
193
|
.setEntityId(deviceId)
|
|
194
|
-
.setPropertyId(propertyId)
|
|
195
|
-
.setZoneId(zoneId);
|
|
194
|
+
.setPropertyId(propertyId);
|
|
196
195
|
}
|
|
197
196
|
/**
|
|
198
197
|
* Creates a hub-specific alert builder
|
|
199
198
|
*/
|
|
200
|
-
static createHubAlert(hubId, propertyId
|
|
199
|
+
static createHubAlert(hubId, propertyId) {
|
|
201
200
|
return new AlertBuilder()
|
|
202
201
|
.setEntityType(alert_types_1.EntityType.HUB)
|
|
203
202
|
.setEntityId(hubId)
|
|
204
|
-
.setPropertyId(propertyId)
|
|
205
|
-
.setZoneId(zoneId);
|
|
203
|
+
.setPropertyId(propertyId);
|
|
206
204
|
}
|
|
207
205
|
}
|
|
208
206
|
exports.AlertBuilder = AlertBuilder;
|
|
@@ -239,6 +239,25 @@ export declare const DT_EVENT_TYPES: {
|
|
|
239
239
|
HEARTBEAT: {
|
|
240
240
|
DISABLED: string;
|
|
241
241
|
STARTED: string;
|
|
242
|
+
DEVICE: {
|
|
243
|
+
IN_ACTIVE: string;
|
|
244
|
+
OFFLINE: string;
|
|
245
|
+
OFFLINE_HUB: string;
|
|
246
|
+
FURTHER_CHECKS_SKIPPED: string;
|
|
247
|
+
};
|
|
248
|
+
HUB: {
|
|
249
|
+
IN_ACTIVE: string;
|
|
250
|
+
OFFLINE: string;
|
|
251
|
+
};
|
|
252
|
+
LOCK: {
|
|
253
|
+
LOCAL_CODES_EXCLUDING_SET: string;
|
|
254
|
+
CLOUD_CODES: string;
|
|
255
|
+
MISSING_CODES: string;
|
|
256
|
+
ADDITIONAL_CODES: string;
|
|
257
|
+
SCHEDULE_CODES: string;
|
|
258
|
+
MARKED_TO_DELETE_CODES: string;
|
|
259
|
+
UNSET_CODES: string;
|
|
260
|
+
};
|
|
242
261
|
STOPPED: string;
|
|
243
262
|
COMPLETED: string;
|
|
244
263
|
FAILED: string;
|
package/dist/constants/Event.js
CHANGED
|
@@ -240,19 +240,38 @@ exports.DT_EVENT_TYPES = {
|
|
|
240
240
|
},
|
|
241
241
|
},
|
|
242
242
|
HEARTBEAT: {
|
|
243
|
-
DISABLED:
|
|
244
|
-
STARTED:
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
243
|
+
DISABLED: "heartbeat.disabled",
|
|
244
|
+
STARTED: "heartbeat.started",
|
|
245
|
+
DEVICE: {
|
|
246
|
+
IN_ACTIVE: "heartbeat.device.in_active",
|
|
247
|
+
OFFLINE: "heartbeat.device.offline",
|
|
248
|
+
OFFLINE_HUB: "heartbeat.device.offline_hub",
|
|
249
|
+
FURTHER_CHECKS_SKIPPED: "heartbeat.device.further_checks_skipped",
|
|
250
|
+
},
|
|
251
|
+
HUB: {
|
|
252
|
+
IN_ACTIVE: "heartbeat.hub.in_active",
|
|
253
|
+
OFFLINE: "heartbeat.hub.offline",
|
|
254
|
+
},
|
|
255
|
+
LOCK: {
|
|
256
|
+
LOCAL_CODES_EXCLUDING_SET: "heartbeat.lock.local_codes_excluding_set",
|
|
257
|
+
CLOUD_CODES: "heartbeat.lock.cloud_codes",
|
|
258
|
+
MISSING_CODES: "heartbeat.lock.missing_codes",
|
|
259
|
+
ADDITIONAL_CODES: "heartbeat.lock.additional_codes",
|
|
260
|
+
SCHEDULE_CODES: "heartbeat.lock.schedule_codes",
|
|
261
|
+
MARKED_TO_DELETE_CODES: "heartbeat.lock.marked_to_delete_codes",
|
|
262
|
+
UNSET_CODES: "heartbeat.lock.unset_codes",
|
|
263
|
+
},
|
|
264
|
+
STOPPED: "heartbeat.stopped",
|
|
265
|
+
COMPLETED: "heartbeat.completed",
|
|
266
|
+
FAILED: "heartbeat.failed",
|
|
267
|
+
EVENT_PUBLISHED: "heartbeat.event_published",
|
|
268
|
+
EVENT_RECEIVED: "heartbeat.event_received",
|
|
269
|
+
ERROR: "heartbeat.error",
|
|
251
270
|
},
|
|
252
271
|
ACCOUNT: {
|
|
253
272
|
DEVICE: {
|
|
254
|
-
NEW:
|
|
255
|
-
MISSING:
|
|
256
|
-
}
|
|
257
|
-
}
|
|
273
|
+
NEW: "account.device.new",
|
|
274
|
+
MISSING: "account.device.missing",
|
|
275
|
+
},
|
|
276
|
+
},
|
|
258
277
|
};
|
|
@@ -38,13 +38,10 @@ export declare class IssueService {
|
|
|
38
38
|
* Create issue for device battery level below threshold (READINESS + OPERATIONAL + ENERGY)
|
|
39
39
|
*/
|
|
40
40
|
createDeviceBatteryIssue(device: IDevice, batteryLevel: number, threshold: number, priority: IssuePriority, source: Source): Promise<IIssueDocument | null>;
|
|
41
|
-
createAccountMissingDeviceIssue(
|
|
42
|
-
deviceId: string;
|
|
43
|
-
deviceType: string;
|
|
44
|
-
name: string;
|
|
45
|
-
}, connection: {
|
|
41
|
+
createAccountMissingDeviceIssue(connection: {
|
|
46
42
|
id: string;
|
|
47
43
|
provider: string;
|
|
44
|
+
deviceCount: number;
|
|
48
45
|
type?: string;
|
|
49
46
|
}, propertyId: string, source: Source): Promise<IIssueDocument | null>;
|
|
50
47
|
createAccountUnauthorizedIssue(account: {
|
|
@@ -85,6 +82,7 @@ export declare class IssueService {
|
|
|
85
82
|
* Update an issue with business logic validation
|
|
86
83
|
*/
|
|
87
84
|
updateIssue(id: string, updateData: UpdateIssueData): Promise<IIssueDocument | null>;
|
|
85
|
+
deleteIssues(filters: IIssueQuery, deletedBy: string, softDelete?: boolean): Promise<boolean>;
|
|
88
86
|
/**
|
|
89
87
|
* Soft delete an issue with business logic
|
|
90
88
|
*/
|
|
@@ -266,14 +266,14 @@ let IssueService = (() => {
|
|
|
266
266
|
type: issue_types_1.IssueType.BATTERY_LOW,
|
|
267
267
|
});
|
|
268
268
|
}
|
|
269
|
-
async createAccountMissingDeviceIssue(
|
|
269
|
+
async createAccountMissingDeviceIssue(connection, propertyId, source) {
|
|
270
270
|
return await this.createIssue({
|
|
271
271
|
entityId: connection.id,
|
|
272
272
|
entityType: issue_types_1.EntityType.CLOUD_DEVICE_ACCOUNT,
|
|
273
273
|
entitySubType: connection.provider,
|
|
274
274
|
propertyId: propertyId,
|
|
275
275
|
title: "Device Missing",
|
|
276
|
-
description: `${
|
|
276
|
+
description: `${connection.deviceCount} device(s), missing from the ${connection.provider} account.`,
|
|
277
277
|
createdBy: source,
|
|
278
278
|
category: issue_types_1.IssuesCategory.OPERATIONS,
|
|
279
279
|
priority: issue_types_1.IssuePriority.CRITICAL,
|
|
@@ -507,6 +507,31 @@ let IssueService = (() => {
|
|
|
507
507
|
}
|
|
508
508
|
return await this.issueRepository.update(id, updateData);
|
|
509
509
|
}
|
|
510
|
+
async deleteIssues(filters, deletedBy, softDelete = true) {
|
|
511
|
+
try {
|
|
512
|
+
if (!filters || Object.keys(filters).length === 0) {
|
|
513
|
+
throw new Error("Filters are required");
|
|
514
|
+
}
|
|
515
|
+
if (!deletedBy) {
|
|
516
|
+
throw new Error("Deleted by user is required");
|
|
517
|
+
}
|
|
518
|
+
const issues = await this.issueRepository.query(filters);
|
|
519
|
+
if (softDelete) {
|
|
520
|
+
for (const issue of issues) {
|
|
521
|
+
await this.issueRepository.softDelete(issue.id, deletedBy);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
for (const issue of issues) {
|
|
526
|
+
await this.issueRepository.hardDelete(issue.id);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return true;
|
|
530
|
+
}
|
|
531
|
+
catch (error) {
|
|
532
|
+
throw new Error(`Failed to delete issues: ${error instanceof Error ? error.message : error}`);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
510
535
|
/**
|
|
511
536
|
* Soft delete an issue with business logic
|
|
512
537
|
*/
|