dt-common-device 1.2.4 → 1.2.5

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 (67) hide show
  1. package/dist/device/cloud/entities/CloudDevice.d.ts +1 -1
  2. package/dist/device/cloud/entities/CloudDeviceService.d.ts +1 -1
  3. package/dist/device/cloud/entities/index.d.ts +1 -0
  4. package/dist/device/cloud/entities/index.js +1 -0
  5. package/dist/device/cloud/interface.d.ts +101 -0
  6. package/dist/device/cloud/interface.js +3 -0
  7. package/dist/device/cloud/interfaces/ICloudDeviceService.d.ts +1 -1
  8. package/dist/device/cloud/interfaces/IDeviceConnectionService.d.ts +7 -0
  9. package/dist/device/cloud/interfaces/IDeviceConnectionService.js +3 -0
  10. package/dist/device/cloud/interfaces/IDevicesService.d.ts +9 -0
  11. package/dist/device/cloud/interfaces/IDevicesService.js +2 -0
  12. package/dist/device/cloud/interfaces/index.d.ts +1 -1
  13. package/dist/device/cloud/interfaces/index.js +1 -1
  14. package/dist/device/cloud/services/Device.service.d.ts +39 -0
  15. package/dist/device/cloud/services/Device.service.js +9 -0
  16. package/dist/device/cloud/services/DeviceCloudService.d.ts +42 -0
  17. package/dist/device/cloud/services/DeviceCloudService.js +59 -0
  18. package/dist/device/cloud/services/DeviceHub.service.d.ts +3 -0
  19. package/dist/device/cloud/services/DeviceHub.service.js +6 -0
  20. package/dist/device/cloud/services/Hub.service.d.ts +25 -0
  21. package/dist/device/cloud/services/Hub.service.js +9 -0
  22. package/dist/device/cloud/services/SmartThingsDeviceService.d.ts +38 -0
  23. package/dist/device/cloud/services/SmartThingsDeviceService.js +52 -0
  24. package/dist/device/index.d.ts +4 -0
  25. package/dist/device/index.js +20 -0
  26. package/dist/device/local/events/EventHandler.d.ts +0 -1
  27. package/dist/device/local/events/EventHandler.js +0 -11
  28. package/dist/device/local/interface.d.ts +0 -0
  29. package/dist/device/local/interface.js +1 -0
  30. package/dist/device/local/interfaces/IConnection.d.ts +1 -11
  31. package/dist/device/local/interfaces/IConnection.js +0 -12
  32. package/dist/device/local/repository/Connection.repository.d.ts +1 -2
  33. package/dist/device/local/repository/Connection.repository.js +0 -15
  34. package/dist/device/local/repository/Hub.repository.d.ts +1 -1
  35. package/dist/device/local/repository/Property.repository.d.ts +1 -0
  36. package/dist/device/local/repository/Property.repository.js +12 -1
  37. package/dist/device/local/services/Connection.service.d.ts +2 -3
  38. package/dist/device/local/services/Connection.service.js +0 -15
  39. package/dist/device/local/services/Device.service.d.ts +1 -0
  40. package/dist/device/local/services/Device.service.js +13 -46
  41. package/dist/device/local/services/DeviceHub.service.d.ts +11 -0
  42. package/dist/device/local/services/DeviceHub.service.js +40 -0
  43. package/dist/device/local/services/Hub.service.d.ts +1 -1
  44. package/dist/device/local/services/Hub.service.js +0 -18
  45. package/dist/device/local/services/Property.service.d.ts +1 -0
  46. package/dist/device/local/services/Property.service.js +4 -9
  47. package/dist/index.d.ts +2 -1
  48. package/dist/index.js +4 -2
  49. package/package.json +4 -4
  50. package/src/device/cloud/entities/CloudConnection.ts +13 -0
  51. package/src/device/cloud/entities/CloudDevice.ts +1 -1
  52. package/src/device/cloud/entities/CloudDeviceService.ts +1 -1
  53. package/src/device/cloud/entities/index.ts +1 -0
  54. package/src/device/cloud/interfaces/ICloudConnection.ts +6 -0
  55. package/src/device/cloud/interfaces/ICloudDeviceService.ts +1 -1
  56. package/src/device/cloud/interfaces/index.ts +1 -1
  57. package/src/device/cloud/types.ts +58 -0
  58. package/src/device/local/events/EventHandler.ts +0 -16
  59. package/src/device/local/repository/Connection.repository.ts +1 -21
  60. package/src/device/local/repository/Hub.repository.ts +1 -1
  61. package/src/device/local/repository/Property.repository.ts +14 -1
  62. package/src/device/local/services/Connection.service.ts +2 -23
  63. package/src/device/local/services/Device.service.ts +25 -47
  64. package/src/device/local/services/Hub.service.ts +1 -20
  65. package/src/device/local/services/Property.service.ts +5 -9
  66. package/src/index.ts +3 -1
  67. package/src/device/local/interfaces/IConnection.ts +0 -27
@@ -1,16 +1,27 @@
1
- import { checkAwsEnv, ensureAuditInitialized } from "../../../config/config";
1
+ import axios from "axios";
2
+ import {
3
+ getConfig,
4
+ checkAwsEnv,
5
+ ensureAuditInitialized,
6
+ } from "../../../config/config";
2
7
  import { IDevice } from "../interfaces";
8
+ import { eventDispatcher } from "dt-pub-sub";
9
+ import { publishAudit } from "dt-audit-library";
3
10
  import { EventHandler } from "../events/EventHandler";
4
11
  import { isEqual } from "lodash";
5
12
  import { AlertService } from "./Alert.service";
13
+ import { getPostgresClient } from "../../../db";
6
14
  import { DeviceRepository } from "../repository/Device.repository";
7
15
  import Container from "typedi";
8
16
 
9
17
  export class LocalDeviceService {
18
+ private readonly source = "dt-common-device";
10
19
  private readonly eventHandler: EventHandler;
11
20
  private readonly alertService: AlertService;
21
+ //private readonly redis;
12
22
  private readonly deviceRepository: DeviceRepository;
13
23
  constructor() {
24
+ // this.redis = getRedisClient();
14
25
  checkAwsEnv();
15
26
  ensureAuditInitialized();
16
27
  this.eventHandler = new EventHandler();
@@ -26,9 +37,6 @@ export class LocalDeviceService {
26
37
  deviceId: string,
27
38
  withHubDetails: boolean = false
28
39
  ): Promise<IDevice> {
29
- if (!deviceId) {
30
- throw new Error("Device ID is required");
31
- }
32
40
  return await this.deviceRepository.getDevice(deviceId, withHubDetails);
33
41
  }
34
42
 
@@ -36,9 +44,6 @@ export class LocalDeviceService {
36
44
  deviceIds: string[],
37
45
  withHubDetails: boolean = false
38
46
  ): Promise<IDevice[]> {
39
- if (!deviceIds.length) {
40
- throw new Error("At least one device ID is required");
41
- }
42
47
  return await this.deviceRepository.getDevices(deviceIds, withHubDetails);
43
48
  }
44
49
 
@@ -46,9 +51,6 @@ export class LocalDeviceService {
46
51
  propertyId: string,
47
52
  withHubDetails: boolean = false
48
53
  ): Promise<IDevice[]> {
49
- if (!propertyId) {
50
- throw new Error("Property ID is required");
51
- }
52
54
  return await this.deviceRepository.getPropertyDevices(
53
55
  propertyId,
54
56
  withHubDetails
@@ -56,30 +58,18 @@ export class LocalDeviceService {
56
58
  }
57
59
 
58
60
  async updateDevice(deviceId: string, body: any): Promise<any> {
59
- if (!deviceId) {
60
- throw new Error("Device ID is required");
61
- }
62
61
  return await this.eventHandler.onDeviceUpdate(deviceId, body);
63
62
  }
64
63
 
65
64
  async deleteDevice(deviceId: string): Promise<any> {
66
- if (!deviceId) {
67
- throw new Error("Device ID is required");
68
- }
69
65
  return await this.eventHandler.onDeviceDelete(deviceId);
70
66
  }
71
67
 
72
68
  async getState(deviceId: string) {
73
- if (!deviceId) {
74
- throw new Error("Device ID is required");
75
- }
76
69
  return await this.deviceRepository.getState(deviceId);
77
70
  }
78
71
 
79
72
  async setState(deviceId: string, newState: any) {
80
- if (!deviceId || !newState) {
81
- throw new Error("Device ID and new state are required");
82
- }
83
73
  // If old state and new state are different
84
74
  const oldState = (await this.getState(deviceId))?.data?.state || {};
85
75
  const changedKeys = Object.keys(newState).filter(
@@ -91,16 +81,10 @@ export class LocalDeviceService {
91
81
  }
92
82
 
93
83
  async getStatus(deviceId: string) {
94
- if (!deviceId) {
95
- throw new Error("Device ID is required");
96
- }
97
84
  return await this.deviceRepository.getStatus(deviceId);
98
85
  }
99
86
 
100
87
  async setStatus(deviceId: string, newStatus: any) {
101
- if (!deviceId || !newStatus) {
102
- throw new Error("Device ID and new status are required");
103
- }
104
88
  // If old status and new status are different
105
89
  const oldStatus = await this.getStatus(deviceId);
106
90
  const changedKeys = Object.keys(newStatus).filter(
@@ -126,15 +110,9 @@ export class LocalDeviceService {
126
110
  }
127
111
 
128
112
  async getBatteryLevel(deviceId: string) {
129
- if (!deviceId) {
130
- throw new Error("Device ID is required");
131
- }
132
113
  return await this.deviceRepository.getBatteryLevel(deviceId);
133
114
  }
134
115
  async setBatteryLevel(deviceId: string, newBatteryLevel: any) {
135
- if (!deviceId || !newBatteryLevel) {
136
- throw new Error("Device ID and new battery level are required");
137
- }
138
116
  // If old battery level and new battery level are different
139
117
  const oldBatteryLevel = await this.getBatteryLevel(deviceId);
140
118
  const changedKeys = Object.keys(newBatteryLevel).filter(
@@ -158,29 +136,29 @@ export class LocalDeviceService {
158
136
  }
159
137
  }
160
138
  async getMetaData(deviceId: string) {
161
- if (!deviceId) {
162
- throw new Error("Device ID is required");
163
- }
164
139
  return await this.deviceRepository.getMetaData(deviceId);
165
140
  }
166
141
  async setMetaData(deviceId: string, metaData: Record<string, any>) {
167
- if (!deviceId || !metaData) {
168
- throw new Error("Device ID and meta data are required");
169
- }
170
- return await this.eventHandler.onDeviceMetaChange(deviceId, metaData);
142
+ await eventDispatcher.publishEvent(
143
+ "device.metaData.set",
144
+ { deviceId, metaData },
145
+ this.source
146
+ );
147
+ const payload = {
148
+ eventType: "device.metaData.set",
149
+ properties: {
150
+ deviceId,
151
+ metaData,
152
+ },
153
+ };
154
+ await publishAudit(payload);
171
155
  }
172
156
 
173
157
  async getDevicesByZone(zoneId: string) {
174
- if (!zoneId) {
175
- throw new Error("Zone ID is required");
176
- }
177
158
  return await this.deviceRepository.getDevicesByZone(zoneId);
178
159
  }
179
160
 
180
161
  async getDevicesByAccessGroup(accessGroupId: string) {
181
- if (!accessGroupId) {
182
- throw new Error("Access Group ID is required");
183
- }
184
162
  return await this.deviceRepository.getDevicesByAccessGroup(accessGroupId);
185
163
  }
186
164
  }
@@ -8,50 +8,31 @@ export class LocalHubService {
8
8
  this.hubRepository = Container.get(HubRepository);
9
9
  }
10
10
 
11
- async addHub(body: Partial<IDevice>): Promise<IDevice> {
11
+ async addHub(body: IDevice): Promise<IDevice> {
12
12
  return await this.hubRepository.addHub(body);
13
13
  }
14
14
 
15
15
  async getHubs(hubIds: string[]): Promise<IDevice[]> {
16
- if (!hubIds.length) {
17
- throw new Error("At least one hub ID is required");
18
- }
19
16
  return await this.hubRepository.getHubs(hubIds);
20
17
  }
21
18
 
22
19
  async getHub(hubId: string): Promise<IDevice> {
23
- if (!hubId) {
24
- throw new Error("Hub ID is required");
25
- }
26
20
  return await this.hubRepository.getHub(hubId);
27
21
  }
28
22
 
29
23
  async updateHub(hubId: string, body: Partial<IDevice>): Promise<IDevice> {
30
- if (!hubId) {
31
- throw new Error("Hub ID is required");
32
- }
33
24
  return await this.hubRepository.updateHub(hubId, body);
34
25
  }
35
26
 
36
27
  async getStatus(hubId: string): Promise<any> {
37
- if (!hubId) {
38
- throw new Error("Hub ID is required");
39
- }
40
28
  return await this.hubRepository.getStatus(hubId);
41
29
  }
42
30
 
43
31
  async deleteHub(hubId: string): Promise<any> {
44
- if (!hubId) {
45
- throw new Error("Hub ID is required");
46
- }
47
32
  return await this.hubRepository.deleteHub(hubId);
48
33
  }
49
34
 
50
-
51
35
  async deleteAllHubs(hubIds: string[]): Promise<any> {
52
- if (!hubIds.length) {
53
- throw new Error("At least one hub ID is required");
54
- }
55
36
  return await this.hubRepository.deleteAllHubs(hubIds);
56
37
  }
57
38
  }
@@ -7,27 +7,23 @@ export class LocalPropertyService {
7
7
  }
8
8
 
9
9
  async getPropertyPreferences(propertyId: string) {
10
- if (!propertyId) {
11
- throw new Error("Property ID is required");
12
- }
13
10
  return await this.propertyRepository.getPropertyPreferences(propertyId);
14
11
  }
15
12
 
16
13
  async getProperty(propertyId: string) {
17
- if (!propertyId) {
18
- throw new Error("Property ID is required");
19
- }
20
14
  return await this.propertyRepository.getProperty(propertyId);
21
15
  }
22
16
 
23
17
  async getPropertyTimeZone(propertyId: string) {
24
- if (!propertyId) {
25
- throw new Error("Property ID is required");
26
- }
27
18
  const property = await this.propertyRepository.getProperty(propertyId);
28
19
  if (!property) {
29
20
  throw new Error("Property not found");
30
21
  }
31
22
  return property.timezone;
32
23
  }
24
+
25
+ async getAllProperties() {
26
+ const properties = await this.propertyRepository.getAllProperties();
27
+ return properties;
28
+ }
33
29
  }
package/src/index.ts CHANGED
@@ -3,8 +3,9 @@
3
3
  // Cloud exports
4
4
  export {
5
5
  CloudDevice,
6
- CloudDeviceService,
7
6
  DeviceFactory,
7
+ CloudConnection,
8
+ CloudDeviceService,
8
9
  } from "./device/cloud/entities";
9
10
  export {
10
11
  LocalDeviceService,
@@ -15,6 +16,7 @@ export {
15
16
  } from "./device/local/services";
16
17
 
17
18
  export * from "./device/cloud/interfaces";
19
+ export * from "./device/cloud/types";
18
20
 
19
21
  // Local exports
20
22
  export * from "./device/local/interfaces";
@@ -1,27 +0,0 @@
1
- export interface IConnection {
2
- id?: string;
3
- createdAt?: Date;
4
- updatedAt?: Date;
5
- isDeleted?: boolean;
6
- connectionName: string;
7
- connectionRefId: string;
8
- propertyId: string;
9
- connectionProvider: ConnectionProvider;
10
- accessToken?: string;
11
- refreshToken?: string;
12
- clientId?: string;
13
- clientSecret: string;
14
- isActive?: boolean;
15
- metaData?: any;
16
- }
17
-
18
- export enum ConnectionProvider {
19
- Smartthings = "Smartthings",
20
- SaltoKS = "SaltoKS",
21
- TTLock = "TTLock",
22
- Tuya = "Tuya",
23
- Schlage = "Schlage",
24
- YaleWifi = "YaleWifi",
25
- Sensibo = "Sensibo",
26
- Devicethread = "Devicethread",
27
- }