dt-common-device 1.0.0

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 (58) hide show
  1. package/README.md +73 -0
  2. package/dist/device/cloud/interface.d.ts +101 -0
  3. package/dist/device/cloud/interface.js +3 -0
  4. package/dist/device/cloud/interfaces/IDeviceConnectionService.d.ts +39 -0
  5. package/dist/device/cloud/interfaces/IDeviceConnectionService.js +3 -0
  6. package/dist/device/cloud/interfaces/IDevicesService.d.ts +9 -0
  7. package/dist/device/cloud/interfaces/IDevicesService.js +2 -0
  8. package/dist/device/cloud/interfaces/index.d.ts +2 -0
  9. package/dist/device/cloud/interfaces/index.js +18 -0
  10. package/dist/device/cloud/services/Connection.service.d.ts +42 -0
  11. package/dist/device/cloud/services/Connection.service.js +59 -0
  12. package/dist/device/cloud/services/Device.service.d.ts +10 -0
  13. package/dist/device/cloud/services/Device.service.js +30 -0
  14. package/dist/device/cloud/services/DeviceCloudService.d.ts +42 -0
  15. package/dist/device/cloud/services/DeviceCloudService.js +59 -0
  16. package/dist/device/cloud/services/DeviceHub.service.d.ts +3 -0
  17. package/dist/device/cloud/services/DeviceHub.service.js +10 -0
  18. package/dist/device/cloud/services/SmartThingsDeviceService.d.ts +38 -0
  19. package/dist/device/cloud/services/SmartThingsDeviceService.js +52 -0
  20. package/dist/device/cloud/services/index.d.ts +2 -0
  21. package/dist/device/cloud/services/index.js +19 -0
  22. package/dist/device/cloud/types.d.ts +77 -0
  23. package/dist/device/cloud/types.js +3 -0
  24. package/dist/device/index.d.ts +4 -0
  25. package/dist/device/index.js +20 -0
  26. package/dist/device/local/interface.d.ts +0 -0
  27. package/dist/device/local/interface.js +1 -0
  28. package/dist/device/local/interfaces/IDevice.d.ts +46 -0
  29. package/dist/device/local/interfaces/IDevice.js +3 -0
  30. package/dist/device/local/interfaces/IHub.d.ts +46 -0
  31. package/dist/device/local/interfaces/IHub.js +2 -0
  32. package/dist/device/local/interfaces/index.d.ts +2 -0
  33. package/dist/device/local/interfaces/index.js +18 -0
  34. package/dist/device/local/services/Device.service.d.ts +18 -0
  35. package/dist/device/local/services/Device.service.js +27 -0
  36. package/dist/device/local/services/DeviceHub.service.d.ts +21 -0
  37. package/dist/device/local/services/DeviceHub.service.js +28 -0
  38. package/dist/device/local/services/index.d.ts +2 -0
  39. package/dist/device/local/services/index.js +18 -0
  40. package/dist/index.d.ts +5 -0
  41. package/dist/index.js +47 -0
  42. package/package.json +21 -0
  43. package/src/device/cloud/interfaces/IDeviceConnectionService.ts +54 -0
  44. package/src/device/cloud/interfaces/IDevicesService.ts +10 -0
  45. package/src/device/cloud/interfaces/index.ts +2 -0
  46. package/src/device/cloud/services/Connection.service.ts +76 -0
  47. package/src/device/cloud/services/Device.service.ts +40 -0
  48. package/src/device/cloud/services/DeviceHub.service.ts +6 -0
  49. package/src/device/cloud/services/index.ts +4 -0
  50. package/src/device/cloud/types.ts +83 -0
  51. package/src/device/local/interfaces/IDevice.ts +48 -0
  52. package/src/device/local/interfaces/IHub.ts +46 -0
  53. package/src/device/local/interfaces/index.ts +2 -0
  54. package/src/device/local/services/Device.service.ts +46 -0
  55. package/src/device/local/services/DeviceHub.service.ts +50 -0
  56. package/src/device/local/services/index.ts +2 -0
  57. package/src/index.ts +10 -0
  58. package/tsconfig.json +20 -0
@@ -0,0 +1,83 @@
1
+ // Device Cloud Type Interfaces for DeviceThread Common Library
2
+
3
+ export interface IConnection {
4
+ connectionName: string;
5
+ connectionRefId: string;
6
+ propertyId: string;
7
+ connectionProvider: ConnectionProvider;
8
+ accessToken?: string;
9
+ clientId?: string;
10
+ clientSecret?: string;
11
+ }
12
+
13
+ export interface IDevice {
14
+ deviceId: string;
15
+ propertyId: string;
16
+ name: string;
17
+ hubId: string[];
18
+ specifications?: {
19
+ manufacturer?: string;
20
+ model?: string;
21
+ firmware?: {
22
+ version?: string;
23
+ newVersionAvailable?: boolean;
24
+ newVersion?: string;
25
+ mandatoryUpdate?: boolean;
26
+ };
27
+ };
28
+ protocol?: {
29
+ location?: {
30
+ id?: string;
31
+ name?: string;
32
+ city?: string;
33
+ };
34
+ name?: string;
35
+ room?: {
36
+ id?: string;
37
+ name?: string;
38
+ };
39
+ accountId?: string;
40
+ };
41
+ deviceType: {
42
+ id: string;
43
+ type: string;
44
+ };
45
+ status: {
46
+ online: boolean;
47
+ error?: {
48
+ type?: string;
49
+ message?: string;
50
+ };
51
+ lastUpdated?: string;
52
+ };
53
+ state?: Record<string, any>;
54
+ metaData?: Record<string, any>;
55
+ hubDeviceDetails?: IDevice[];
56
+ }
57
+
58
+ export interface IDeviceAccountResponse {
59
+ id: string;
60
+ connection_name: string;
61
+ connection_access_token: string;
62
+ connection_provider: string;
63
+ totalDevices: number;
64
+ connection_ref_id: string;
65
+ isActive: boolean;
66
+ }
67
+
68
+ export interface IConnectionConnectParams {
69
+ code?: string;
70
+ propertyId?: string;
71
+ [key: string]: any;
72
+ }
73
+
74
+ export interface ConnectionProvider {
75
+ Smartthings: "Smartthings";
76
+ SaltoKS: "SaltoKS";
77
+ Tuya: "Tuya";
78
+ TTLock: "TTLock";
79
+ Schlage: "Schlage";
80
+ YaleWifi: "YaleWifi";
81
+ Devicethread: "Devicethread";
82
+ Sensibo: "Sensibo";
83
+ }
@@ -0,0 +1,48 @@
1
+ // Interfaces for DeviceService methods
2
+
3
+ export interface IDeviceCreateParams {
4
+ deviceId: string;
5
+ propertyId: string;
6
+ name: string;
7
+ hubId?: string[];
8
+ specifications: {
9
+ manufacturer?: string;
10
+ model?: string;
11
+ firmware?: {
12
+ version?: string;
13
+ newVersionAvailable?: boolean;
14
+ newVersion?: string;
15
+ mandatoryUpdate?: boolean;
16
+ };
17
+ };
18
+ protocol: {
19
+ location?: {
20
+ id?: string;
21
+ name?: string;
22
+ city?: string;
23
+ };
24
+ name?: string;
25
+ room?: {
26
+ id?: string;
27
+ name?: string;
28
+ };
29
+ accountId?: string;
30
+ };
31
+ deviceType: {
32
+ id: string;
33
+ type: string;
34
+ };
35
+ status: {
36
+ online: boolean;
37
+ error?: {
38
+ type?: string;
39
+ message?: string;
40
+ default?: object;
41
+ };
42
+ lastUpdated?: Date;
43
+ };
44
+ state?: object;
45
+ metaData?: object;
46
+ createdAt?: Date;
47
+ updatedAt?: Date;
48
+ }
@@ -0,0 +1,46 @@
1
+ export interface IHubCreateParams {
2
+ deviceId: string;
3
+ propertyId: string;
4
+ name: string;
5
+ hubId?: string[];
6
+ specifications: {
7
+ manufacturer?: string;
8
+ model?: string;
9
+ firmware?: {
10
+ version?: string;
11
+ newVersionAvailable?: boolean;
12
+ newVersion?: string;
13
+ mandatoryUpdate?: boolean;
14
+ };
15
+ };
16
+ protocol: {
17
+ location?: {
18
+ id?: string;
19
+ name?: string;
20
+ city?: string;
21
+ };
22
+ name?: string;
23
+ room?: {
24
+ id?: string;
25
+ name?: string;
26
+ };
27
+ accountId?: string;
28
+ };
29
+ deviceType: {
30
+ id: string;
31
+ type: string;
32
+ };
33
+ status: {
34
+ online: boolean;
35
+ error?: {
36
+ type?: string;
37
+ message?: string;
38
+ default?: object;
39
+ };
40
+ lastUpdated?: Date;
41
+ };
42
+ state?: object;
43
+ metaData?: object;
44
+ createdAt?: Date;
45
+ updatedAt?: Date;
46
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./IDevice";
2
+ export * from "./IHub";
@@ -0,0 +1,46 @@
1
+ // src/device/local/services/Device.service.ts
2
+
3
+ import { IDeviceCreateParams } from "../interfaces";
4
+
5
+ export class DeviceService {
6
+ async createDevice(
7
+ body: IDeviceCreateParams,
8
+ httpClient: { post: (url: string, options: any) => Promise<any> }
9
+ ): Promise<void> {
10
+ // Create main device
11
+ await httpClient.post("/devices", { body });
12
+ }
13
+
14
+ async getDevice(
15
+ deviceId: string,
16
+ httpClient: { get: (url: string) => Promise<any> }
17
+ ): Promise<any> {
18
+ return await httpClient.get(`/devices/${deviceId}`);
19
+ }
20
+
21
+ async getPropertyDevices(
22
+ propertyId: string,
23
+ httpClient: { get: (url: string, options: any) => Promise<any> }
24
+ ): Promise<any> {
25
+ return await httpClient.get(`/devices`, {
26
+ params: {
27
+ propertyId,
28
+ },
29
+ });
30
+ }
31
+
32
+ async updateDevice(
33
+ deviceId: string,
34
+ body: any,
35
+ httpClient: { put: (url: string, options: any) => Promise<any> }
36
+ ): Promise<any> {
37
+ return await httpClient.put(`/devices/${deviceId}`, { body });
38
+ }
39
+
40
+ async deleteDevice(
41
+ deviceId: string,
42
+ httpClient: { delete: (url: string) => Promise<any> }
43
+ ): Promise<any> {
44
+ return await httpClient.delete(`/devices/${deviceId}`);
45
+ }
46
+ }
@@ -0,0 +1,50 @@
1
+ import { IHubCreateParams } from "../interfaces";
2
+
3
+ export class DeviceHubService {
4
+ async addHub(
5
+ body: IHubCreateParams,
6
+ httpClient: { post: (url: string, options: any) => Promise<any> }
7
+ ): Promise<any> {
8
+ return await httpClient.post(`/devices/hubs`, { body });
9
+ }
10
+
11
+ //get hubs takes an array of hub ids as query params
12
+ async getHubs(
13
+ hubIds: string[],
14
+ httpClient: { get: (url: string, options?: any) => Promise<any> }
15
+ ): Promise<any> {
16
+ const query = hubIds && hubIds.length ? `?ids=${hubIds.join(",")}` : "";
17
+ return await httpClient.get(`/devices/hubs${query}`);
18
+ }
19
+
20
+ //get hub takes a hub id in params
21
+ async getHub(
22
+ hubId: string,
23
+ httpClient: { get: (url: string) => Promise<any> }
24
+ ): Promise<any> {
25
+ return await httpClient.get(`/devices/hubs/${hubId}`);
26
+ }
27
+
28
+ async updateHub(
29
+ hubId: string,
30
+ body: any,
31
+ httpClient: { put: (url: string, options: any) => Promise<any> }
32
+ ): Promise<any> {
33
+ return await httpClient.put(`/devices/hubs/${hubId}`, { body });
34
+ }
35
+
36
+ async deleteHub(
37
+ hubId: string,
38
+ httpClient: { delete: (url: string) => Promise<any> }
39
+ ): Promise<any> {
40
+ return await httpClient.delete(`/devices/hubs/${hubId}`);
41
+ }
42
+
43
+ async deleteAllHubs(
44
+ hubIds: string[],
45
+ httpClient: { delete: (url: string) => Promise<any> }
46
+ ): Promise<any> {
47
+ const query = hubIds.length ? `?ids=${hubIds.join(",")}` : "";
48
+ return await httpClient.delete(`/devices/hubs${query}`);
49
+ }
50
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./Device.service";
2
+ export * from "./DeviceHub.service";
package/src/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ // Main entry point for dt-common-device
2
+
3
+ // Cloud exports
4
+ export * as cloud from "./device/cloud/services";
5
+ export * as cloudInterfaces from "./device/cloud/interfaces";
6
+ export * from "./device/cloud/types";
7
+
8
+ // Local exports
9
+ export * as local from "./device/local/services";
10
+ export * as localInterfaces from "./device/local/interfaces";
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "lib": ["ES2020"],
6
+ "declaration": true,
7
+ "outDir": "./dist",
8
+ "rootDir": "./src",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "moduleResolution": "node",
14
+ "resolveJsonModule": true,
15
+ "isolatedModules": true,
16
+ "noEmit": false
17
+ },
18
+ "include": ["src/**/*"],
19
+ "exclude": ["node_modules", "dist"]
20
+ }