dt-common-device 1.0.0 → 1.0.2

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 (37) hide show
  1. package/README.md +94 -29
  2. package/dist/config/config.d.ts +3 -0
  3. package/dist/config/config.js +24 -0
  4. package/dist/device/cloud/interfaces/IDeviceConnectionService.d.ts +2 -33
  5. package/dist/device/cloud/interfaces/IDevicesService.d.ts +3 -3
  6. package/dist/device/cloud/services/Connection.service.d.ts +5 -38
  7. package/dist/device/cloud/services/Connection.service.js +1 -34
  8. package/dist/device/cloud/services/Device.service.d.ts +3 -3
  9. package/dist/device/cloud/services/index.d.ts +3 -2
  10. package/dist/device/cloud/services/index.js +7 -16
  11. package/dist/device/cloud/types.d.ts +28 -1
  12. package/dist/device/local/services/Device.service.d.ts +7 -15
  13. package/dist/device/local/services/Device.service.js +23 -14
  14. package/dist/device/local/services/DeviceHub.service.d.ts +8 -18
  15. package/dist/device/local/services/DeviceHub.service.js +24 -12
  16. package/dist/device/local/services/index.d.ts +2 -2
  17. package/dist/device/local/services/index.js +5 -16
  18. package/dist/index.d.ts +3 -2
  19. package/dist/index.js +12 -3
  20. package/dist/types/config.types.d.ts +7 -0
  21. package/dist/types/config.types.js +2 -0
  22. package/dist/types/index.d.ts +1 -0
  23. package/dist/types/index.js +17 -0
  24. package/package.json +1 -1
  25. package/src/config/config.ts +27 -0
  26. package/src/device/cloud/interfaces/IDeviceConnectionService.ts +5 -33
  27. package/src/device/cloud/interfaces/IDevicesService.ts +6 -3
  28. package/src/device/cloud/services/Connection.service.ts +5 -46
  29. package/src/device/cloud/services/Device.service.ts +3 -3
  30. package/src/device/cloud/services/index.ts +3 -2
  31. package/src/device/cloud/types.ts +105 -83
  32. package/src/device/local/services/Device.service.ts +25 -30
  33. package/src/device/local/services/DeviceHub.service.ts +26 -31
  34. package/src/device/local/services/index.ts +2 -2
  35. package/src/index.ts +13 -2
  36. package/src/types/config.types.ts +7 -0
  37. package/src/types/index.ts +1 -0
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export * as cloud from "./device/cloud/services";
1
+ export { CloudDeviceService, CloudDeviceHubService, CloudConnectionService, } from "./device/cloud/services";
2
+ export { LocalDeviceService, LocalDeviceHubService, } from "./device/local/services";
2
3
  export * as cloudInterfaces from "./device/cloud/interfaces";
3
4
  export * from "./device/cloud/types";
4
- export * as local from "./device/local/services";
5
5
  export * as localInterfaces from "./device/local/interfaces";
6
+ export { initialize, getConfig } from "./config/config";
package/dist/index.js CHANGED
@@ -37,11 +37,20 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
37
37
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
38
38
  };
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.localInterfaces = exports.local = exports.cloudInterfaces = exports.cloud = void 0;
40
+ exports.getConfig = exports.initialize = exports.localInterfaces = exports.cloudInterfaces = exports.LocalDeviceHubService = exports.LocalDeviceService = exports.CloudConnectionService = exports.CloudDeviceHubService = exports.CloudDeviceService = void 0;
41
41
  // Cloud exports
42
- exports.cloud = __importStar(require("./device/cloud/services"));
42
+ var services_1 = require("./device/cloud/services");
43
+ Object.defineProperty(exports, "CloudDeviceService", { enumerable: true, get: function () { return services_1.CloudDeviceService; } });
44
+ Object.defineProperty(exports, "CloudDeviceHubService", { enumerable: true, get: function () { return services_1.CloudDeviceHubService; } });
45
+ Object.defineProperty(exports, "CloudConnectionService", { enumerable: true, get: function () { return services_1.CloudConnectionService; } });
46
+ var services_2 = require("./device/local/services");
47
+ Object.defineProperty(exports, "LocalDeviceService", { enumerable: true, get: function () { return services_2.LocalDeviceService; } });
48
+ Object.defineProperty(exports, "LocalDeviceHubService", { enumerable: true, get: function () { return services_2.LocalDeviceHubService; } });
43
49
  exports.cloudInterfaces = __importStar(require("./device/cloud/interfaces"));
44
50
  __exportStar(require("./device/cloud/types"), exports);
45
51
  // Local exports
46
- exports.local = __importStar(require("./device/local/services"));
47
52
  exports.localInterfaces = __importStar(require("./device/local/interfaces"));
53
+ //initialize export
54
+ var config_1 = require("./config/config");
55
+ Object.defineProperty(exports, "initialize", { enumerable: true, get: function () { return config_1.initialize; } });
56
+ Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return config_1.getConfig; } });
@@ -0,0 +1,7 @@
1
+ export type DeviceConfig = {
2
+ ADMIN_SERVICE: string;
3
+ OPERATIONAL_SERVICE: string;
4
+ DEVICE_SERVICE: string;
5
+ MONITORING_SERVICE: string;
6
+ [key: string]: string;
7
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export * from "./config.types";
@@ -0,0 +1,17 @@
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("./config.types"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
@@ -0,0 +1,27 @@
1
+ import { DeviceConfig } from "../types";
2
+
3
+ let config: DeviceConfig | null = null;
4
+
5
+ export function initialize(cfg: DeviceConfig) {
6
+ // Check if at least one service is provided
7
+ const hasAtLeastOneService = [
8
+ "ADMIN_SERVICE",
9
+ "OPERATIONAL_SERVICE",
10
+ "DEVICE_SERVICE",
11
+ "MONITORING_SERVICE",
12
+ ].some((key) => Boolean(cfg[key]));
13
+
14
+ if (!hasAtLeastOneService) {
15
+ throw new Error("At least one http service must be initialized");
16
+ }
17
+ config = { ...cfg };
18
+ }
19
+
20
+ export function getConfig(): DeviceConfig {
21
+ if (!config) {
22
+ throw new Error(
23
+ "dt-common-device: Library not initialized. Call initialize() first."
24
+ );
25
+ }
26
+ return config;
27
+ }
@@ -7,46 +7,18 @@ import {
7
7
  IDeviceAccountResponse,
8
8
  } from "../types";
9
9
 
10
- /**
11
- * Class interface for device cloud operations and connection management
12
- */
13
10
  export interface IDeviceConnectionService {
14
- /**
15
- * Creates a new connection for device management
16
- * @param data - Connection data
17
- * @param userId - User identifier
18
- * @returns Promise with connection result
19
- */
20
11
  createConnection(data: IConnection, userId: string): Promise<any>;
21
12
 
22
- /**
23
- * Gets device account information for a connection
24
- * @param connection - Connection object
25
- * @returns Promise with device account response
26
- */
27
13
  getDeviceAccount(connection: IConnection): Promise<IDeviceAccountResponse>;
28
14
 
29
- /**
30
- * Gets all devices for a connection
31
- * @param connection - Connection object
32
- * @returns Promise with array of devices
33
- */
34
- getDevices(connection: IConnection): Promise<any>;
15
+ getDevices(connection: IConnection): Promise<IDevice[]>;
35
16
 
36
- /**
37
- * Filters devices based on connection and device list
38
- * @param connection - Connection object
39
- * @param devices - Array of devices to filter
40
- * @returns Promise with filtered devices
41
- */
42
- filterDevices(connection: IConnection, devices: any[]): Promise<IDevice[]>;
17
+ filterDevices(
18
+ connection: IConnection,
19
+ devices: Record<string, any>[]
20
+ ): Promise<IDevice[]>;
43
21
 
44
- /**
45
- * Connects to a device service
46
- * @param connection - Connection object
47
- * @param connectionConnect - Connection parameters
48
- * @returns Promise with connection result
49
- */
50
22
  connect(
51
23
  connection: IConnection,
52
24
  connectionConnect: IConnectionConnectParams
@@ -1,10 +1,13 @@
1
1
  import { IConnection } from "../types";
2
2
 
3
3
  export interface IDeviceService {
4
- getDevices(connection: IConnection): Promise<any[]>;
5
- getDevice(connectionId: string, deviceId: string): Promise<any>;
4
+ getDevices(connection: IConnection): Promise<Record<string, any>[]>;
5
+ getDevice(
6
+ connectionId: string,
7
+ deviceId: string
8
+ ): Promise<Record<string, any>>;
6
9
  getStatus(connectionId: string, deviceId: string): Promise<string | null>;
7
- getState(deviceId: string): Promise<any>;
10
+ getState(deviceId: string): Promise<Record<string, any>>;
8
11
  getGateways(connectionId: string): Promise<any[] | null>;
9
12
  getGatewayDetails(connectionId: string, gatewayId: string): Promise<any>;
10
13
  }
@@ -1,34 +1,13 @@
1
1
  // Device Cloud Service - Class Implementation
2
2
  import { IDeviceConnectionService } from "../interfaces";
3
- import {
4
- IConnection,
5
- IConnectionConnectParams,
6
- IDevice,
7
- IDeviceAccountResponse,
8
- } from "../types";
3
+ import { IConnection, IDevice, IDeviceAccountResponse } from "../types";
9
4
 
10
- /**
11
- * Device Cloud Service Class
12
- * Implements IDeviceCloudService interface with empty implementations
13
- * Implementation will be provided by the consuming project
14
- */
15
5
  export class ConnectionService implements IDeviceConnectionService {
16
- /**
17
- * Creates a new connection for device management
18
- * @param data - Connection data
19
- * @param userId - User identifier
20
- * @returns Promise with connection result
21
- */
22
- async createConnection(data: IConnection, userId: string): Promise<any> {
6
+ async createConnection(data: IConnection, userId: string) {
23
7
  // Implementation will be provided by the consuming project
24
8
  throw new Error("createConnection method not implemented");
25
9
  }
26
10
 
27
- /**
28
- * Gets device account information for a connection
29
- * @param connection - Connection object
30
- * @returns Promise with device account response
31
- */
32
11
  async getDeviceAccount(
33
12
  connection: IConnection
34
13
  ): Promise<IDeviceAccountResponse> {
@@ -36,40 +15,20 @@ export class ConnectionService implements IDeviceConnectionService {
36
15
  throw new Error("getDeviceAccount method not implemented");
37
16
  }
38
17
 
39
- /**
40
- * Gets all devices for a connection
41
- * @param connection - Connection object
42
- * @returns Promise with array of devices
43
- */
44
- async getDevices(connection: IConnection): Promise<any> {
18
+ async getDevices(connection: IConnection): Promise<IDevice[]> {
45
19
  // Implementation will be provided by the consuming project
46
20
  throw new Error("getDevices method not implemented");
47
21
  }
48
22
 
49
- /**
50
- * Filters devices based on connection and device list
51
- * @param connection - Connection object
52
- * @param devices - Array of devices to filter
53
- * @returns Promise with filtered devices
54
- */
55
23
  async filterDevices(
56
24
  connection: IConnection,
57
- devices: any[]
25
+ devices: Record<string, any>[]
58
26
  ): Promise<IDevice[]> {
59
27
  // Implementation will be provided by the consuming project
60
28
  throw new Error("filterDevices method not implemented");
61
29
  }
62
30
 
63
- /**
64
- * Connects to a device service
65
- * @param connection - Connection object
66
- * @param connectionConnect - Connection parameters
67
- * @returns Promise with connection result
68
- */
69
- async connect(
70
- connection: IConnection,
71
- connectionConnect: IConnectionConnectParams
72
- ): Promise<any> {
31
+ async connect(connection: IConnection) {
73
32
  // Implementation will be provided by the consuming project
74
33
  throw new Error("connect method not implemented");
75
34
  }
@@ -2,7 +2,7 @@ import { IDeviceService } from "../interfaces";
2
2
  import { IConnection } from "../types";
3
3
 
4
4
  export class DeviceService implements IDeviceService {
5
- async getDevices(connection: IConnection): Promise<any[]> {
5
+ async getDevices(connection: IConnection): Promise<Record<string, any>[]> {
6
6
  // Implementation will be provided by the consuming project
7
7
  throw new Error("getDevices method not implemented");
8
8
  }
@@ -20,7 +20,7 @@ export class DeviceService implements IDeviceService {
20
20
  throw new Error("getDeviceStatus method not implemented");
21
21
  }
22
22
 
23
- async getState(deviceId: string): Promise<any> {
23
+ async getState(deviceId: string): Promise<Record<string, any>> {
24
24
  // Implementation will be provided by the consuming project
25
25
  throw new Error("getState method not implemented");
26
26
  }
@@ -33,7 +33,7 @@ export class DeviceService implements IDeviceService {
33
33
  async getGatewayDetails(
34
34
  connectionId: string,
35
35
  gatewayId: string
36
- ): Promise<any> {
36
+ ): Promise<Record<string, any>> {
37
37
  // Implementation will be provided by the consuming project
38
38
  throw new Error("getGatewayDetails method not implemented");
39
39
  }
@@ -1,4 +1,5 @@
1
1
  // Device Cloud Services - Export all service classes
2
2
 
3
- export * from "./Connection.service";
4
- export * from "./Device.service";
3
+ export { DeviceService as CloudDeviceService } from "./Device.service";
4
+ export { ConnectionService as CloudConnectionService } from "./Connection.service";
5
+ export { DeviceHubService as CloudDeviceHubService } from "./DeviceHub.service";
@@ -1,83 +1,105 @@
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
- }
1
+ // Device Cloud Type Interfaces for DeviceThread Common Library
2
+
3
+ /**
4
+ * Represents a connection to a device provider.
5
+ * WARNING: Do not log or expose sensitive fields (accessToken, clientSecret).
6
+ */
7
+ export interface IConnection {
8
+ connectionName: string;
9
+ connectionRefId: string;
10
+ propertyId: string;
11
+ connectionProvider: ConnectionProvider;
12
+ accessToken?: string;
13
+ clientId?: string;
14
+ clientSecret?: string;
15
+ }
16
+
17
+ export interface IConnectionPagination {
18
+ page: number;
19
+ limit: number;
20
+ }
21
+
22
+ /**
23
+ * Represents a device in the system.
24
+ * All date fields must be ISO 8601 strings.
25
+ */
26
+ export interface IDevice {
27
+ deviceId: string;
28
+ propertyId: string;
29
+ name: string;
30
+ hubId: string[];
31
+ specifications?: {
32
+ manufacturer?: string;
33
+ model?: string;
34
+ firmware?: {
35
+ version?: string;
36
+ newVersionAvailable?: boolean;
37
+ newVersion?: string;
38
+ mandatoryUpdate?: boolean;
39
+ };
40
+ };
41
+ protocol?: {
42
+ location?: {
43
+ id?: string;
44
+ name?: string;
45
+ city?: string;
46
+ };
47
+ name?: string;
48
+ room?: {
49
+ id?: string;
50
+ name?: string;
51
+ };
52
+ accountId?: string;
53
+ };
54
+ deviceType: {
55
+ id: string;
56
+ type: string;
57
+ };
58
+ status: {
59
+ online: boolean;
60
+ error?: {
61
+ type?: string;
62
+ message?: string;
63
+ };
64
+ lastUpdated?: string;
65
+ };
66
+ state?: Record<string, any>;
67
+ metaData?: Record<string, any>;
68
+ createdAt?: Date;
69
+ updatedAt?: Date;
70
+ isDeleted?: boolean;
71
+ hubDeviceDetails?: IDevice[];
72
+ parentZones?: { id: string; name: string }[];
73
+ zone?: { id: string; name: string };
74
+ }
75
+
76
+ /**
77
+ * Device account response from provider.
78
+ * WARNING: Do not log or expose connection_access_token.
79
+ */
80
+ export interface IDeviceAccountResponse {
81
+ id: string;
82
+ connection_name: string;
83
+ connection_access_token: string;
84
+ connection_provider: string;
85
+ totalDevices: number;
86
+ connection_ref_id: string;
87
+ isActive: boolean;
88
+ }
89
+
90
+ export interface IConnectionConnectParams {
91
+ code?: string;
92
+ propertyId?: string;
93
+ [key: string]: unknown;
94
+ }
95
+
96
+ export interface ConnectionProvider {
97
+ Smartthings: "Smartthings";
98
+ SaltoKS: "SaltoKS";
99
+ Tuya: "Tuya";
100
+ TTLock: "TTLock";
101
+ Schlage: "Schlage";
102
+ YaleWifi: "YaleWifi";
103
+ Devicethread: "Devicethread";
104
+ Sensibo: "Sensibo";
105
+ }
@@ -1,46 +1,41 @@
1
1
  // src/device/local/services/Device.service.ts
2
2
 
3
+ import axios from "axios";
4
+ import { getConfig } from "../../../config/config";
3
5
  import { IDeviceCreateParams } from "../interfaces";
4
6
 
5
7
  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 });
8
+ private readonly baseUrl: string;
9
+
10
+ constructor() {
11
+ const { DEVICE_SERVICE } = getConfig();
12
+ if (!DEVICE_SERVICE) {
13
+ throw new Error(
14
+ "DEVICE_SERVICE is not configured. Call initialize() first with DEVICE_SERVICE."
15
+ );
16
+ }
17
+ this.baseUrl = DEVICE_SERVICE;
18
+ }
19
+
20
+ async createDevice(body: IDeviceCreateParams): Promise<void> {
21
+ await axios.post(`${this.baseUrl}/devices`, body);
12
22
  }
13
23
 
14
- async getDevice(
15
- deviceId: string,
16
- httpClient: { get: (url: string) => Promise<any> }
17
- ): Promise<any> {
18
- return await httpClient.get(`/devices/${deviceId}`);
24
+ async getDevice(deviceId: string): Promise<any> {
25
+ return await axios.get(`${this.baseUrl}/devices/${deviceId}`);
19
26
  }
20
27
 
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
- },
28
+ async getPropertyDevices(propertyId: string): Promise<any> {
29
+ return await axios.get(`${this.baseUrl}/devices`, {
30
+ params: { propertyId },
29
31
  });
30
32
  }
31
33
 
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 });
34
+ async updateDevice(deviceId: string, body: any): Promise<any> {
35
+ return await axios.put(`${this.baseUrl}/devices/${deviceId}`, body);
38
36
  }
39
37
 
40
- async deleteDevice(
41
- deviceId: string,
42
- httpClient: { delete: (url: string) => Promise<any> }
43
- ): Promise<any> {
44
- return await httpClient.delete(`/devices/${deviceId}`);
38
+ async deleteDevice(deviceId: string): Promise<any> {
39
+ return await axios.delete(`${this.baseUrl}/devices/${deviceId}`);
45
40
  }
46
41
  }
@@ -1,50 +1,45 @@
1
+ import axios from "axios";
2
+ import { getConfig } from "../../../config/config";
1
3
  import { IHubCreateParams } from "../interfaces";
2
4
 
3
5
  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 });
6
+ private readonly baseUrl: string;
7
+
8
+ constructor() {
9
+ const { DEVICE_SERVICE } = getConfig();
10
+ if (!DEVICE_SERVICE) {
11
+ throw new Error(
12
+ "DEVICE_SERVICE is not configured. Call initialize() first with DEVICE_SERVICE."
13
+ );
14
+ }
15
+ this.baseUrl = DEVICE_SERVICE;
16
+ }
17
+
18
+ async addHub(body: IHubCreateParams): Promise<any> {
19
+ return await axios.post(`${this.baseUrl}/devices/hubs`, body);
9
20
  }
10
21
 
11
22
  //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> {
23
+ async getHubs(hubIds: string[]): Promise<any> {
16
24
  const query = hubIds && hubIds.length ? `?ids=${hubIds.join(",")}` : "";
17
- return await httpClient.get(`/devices/hubs${query}`);
25
+ return await axios.get(`${this.baseUrl}/devices/hubs${query}`);
18
26
  }
19
27
 
20
28
  //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}`);
29
+ async getHub(hubId: string): Promise<any> {
30
+ return await axios.get(`${this.baseUrl}/devices/hubs/${hubId}`);
26
31
  }
27
32
 
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 });
33
+ async updateHub(hubId: string, body: any): Promise<any> {
34
+ return await axios.put(`${this.baseUrl}/devices/hubs/${hubId}`, body);
34
35
  }
35
36
 
36
- async deleteHub(
37
- hubId: string,
38
- httpClient: { delete: (url: string) => Promise<any> }
39
- ): Promise<any> {
40
- return await httpClient.delete(`/devices/hubs/${hubId}`);
37
+ async deleteHub(hubId: string): Promise<any> {
38
+ return await axios.delete(`${this.baseUrl}/devices/hubs/${hubId}`);
41
39
  }
42
40
 
43
- async deleteAllHubs(
44
- hubIds: string[],
45
- httpClient: { delete: (url: string) => Promise<any> }
46
- ): Promise<any> {
41
+ async deleteAllHubs(hubIds: string[]): Promise<any> {
47
42
  const query = hubIds.length ? `?ids=${hubIds.join(",")}` : "";
48
- return await httpClient.delete(`/devices/hubs${query}`);
43
+ return await axios.delete(`${this.baseUrl}/devices/hubs${query}`);
49
44
  }
50
45
  }
@@ -1,2 +1,2 @@
1
- export * from "./Device.service";
2
- export * from "./DeviceHub.service";
1
+ export { DeviceService as LocalDeviceService } from "./Device.service";
2
+ export { DeviceHubService as LocalDeviceHubService } from "./DeviceHub.service";
package/src/index.ts CHANGED
@@ -1,10 +1,21 @@
1
1
  // Main entry point for dt-common-device
2
2
 
3
3
  // Cloud exports
4
- export * as cloud from "./device/cloud/services";
4
+ export {
5
+ CloudDeviceService,
6
+ CloudDeviceHubService,
7
+ CloudConnectionService,
8
+ } from "./device/cloud/services";
9
+ export {
10
+ LocalDeviceService,
11
+ LocalDeviceHubService,
12
+ } from "./device/local/services";
13
+
5
14
  export * as cloudInterfaces from "./device/cloud/interfaces";
6
15
  export * from "./device/cloud/types";
7
16
 
8
17
  // Local exports
9
- export * as local from "./device/local/services";
10
18
  export * as localInterfaces from "./device/local/interfaces";
19
+
20
+ //initialize export
21
+ export { initialize, getConfig } from "./config/config";