dt-common-device 7.10.8 → 7.10.10

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.
@@ -25,13 +25,10 @@ export declare class AlertService {
25
25
  startDate: string;
26
26
  endDate: string;
27
27
  }): Promise<IAlertDocument | null>;
28
- raiseNewDeviceAlert(device: {
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, data.zoneId || "")
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, data.zoneId || "")
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(device, connection, propertyId, source) {
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: `New device ${device.name} has been detected on the ${connection.provider} account.`,
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, zoneId: string): AlertBuilder;
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, zoneId: string): AlertBuilder;
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, zoneId) {
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, zoneId) {
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;
@@ -29,6 +29,7 @@ export declare enum AlertType {
29
29
  }
30
30
  export interface AlertDocument {
31
31
  _id: string;
32
+ id: string;
32
33
  category: AlertCategory;
33
34
  propertyId: string;
34
35
  zoneId?: string;
@@ -1,5 +1,5 @@
1
1
  export declare class DeviceProfileRepository {
2
2
  private readonly axiosInstance;
3
3
  constructor();
4
- getDeviceBaseLine(deviceId: string): Promise<void>;
4
+ getDeviceBaseLine(deviceId: string): Promise<any>;
5
5
  }
@@ -41,6 +41,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.DeviceProfileRepository = void 0;
42
42
  const typedi_1 = require("typedi");
43
43
  const utils_1 = require("../../../../utils");
44
+ const config_1 = require("../../../../config/config");
44
45
  let DeviceProfileRepository = (() => {
45
46
  let _classDecorators = [(0, typedi_1.Service)()];
46
47
  let _classDescriptor;
@@ -50,7 +51,16 @@ let DeviceProfileRepository = (() => {
50
51
  constructor() {
51
52
  this.axiosInstance = (0, utils_1.getDeviceServiceAxiosInstance)();
52
53
  }
53
- async getDeviceBaseLine(deviceId) { }
54
+ async getDeviceBaseLine(deviceId) {
55
+ try {
56
+ const response = await this.axiosInstance.get(`/baseline/${deviceId}`);
57
+ return response.data;
58
+ }
59
+ catch (error) {
60
+ (0, config_1.getConfig)().LOGGER.error(`Failed to get device baseline for ${deviceId}:`, error);
61
+ throw new Error(`Failed to get device baseline: ${error.message || "Unknown error"}`);
62
+ }
63
+ }
54
64
  };
55
65
  __setFunctionName(_classThis, "DeviceProfileRepository");
56
66
  (() => {
@@ -27,9 +27,8 @@ class InternalEventSubscription {
27
27
  try {
28
28
  const eventType = message["detail-type"];
29
29
  const eventData = message.detail;
30
- //TODO: To be sent with event data, to delete the message if processing is failed!
31
- const eventToken = message.receiptHandle;
32
- console.log('eventToken', eventToken);
30
+ const MessageId = message.id;
31
+ eventData.MessageId = MessageId;
33
32
  this.logger.info(`Received internal event: ${eventType} ${eventData}`);
34
33
  switch (eventType) {
35
34
  case InternalEventType.HEARTBEAT:
@@ -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(device: {
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(device, connection, propertyId, source) {
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: `${device.name} is missing from the ${connection.provider} account.`,
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
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "7.10.8",
3
+ "version": "7.10.10",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [