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/README.md CHANGED
@@ -1,73 +1,138 @@
1
+ # dt-common-device
2
+
3
+ A TypeScript library for device management, supporting both cloud and local device operations.
4
+
5
+ ## Installation
6
+
7
+ ```sh
1
8
  npm install dt-common-device
9
+ ```
2
10
 
3
- ## Import
11
+ ## Initialization (Required)
4
12
 
5
- import { cloud, local, cloudInterfaces, localInterfaces } from "dt-common-device";
13
+ Before using any service, you **must** call `initialize()` in your main entry file:
6
14
 
7
- ## Cloud Functions
15
+ ```ts
16
+ import { initialize } from "dt-common-device";
17
+
18
+ initialize({
19
+ DEVICE_SERVICE: "https://api.example.com/device",
20
+ ADMIN_SERVICE: "https://api.example.com/admin",
21
+ OPERATIONAL_SERVICE: "https://api.example.com/ops",
22
+ MONITORING_SERVICE: "https://api.example.com/monitor",
23
+ // ...other config as needed
24
+ });
25
+ ```
8
26
 
9
- These are stubs and must be implemented by the consuming project.
27
+ At least one service URL must be provided.
28
+
29
+ ---
30
+
31
+ ## Importing Services
32
+
33
+ ### Cloud Device Service
10
34
 
11
35
  ```ts
12
- const connectionService = new cloud.ConnectionService();
36
+ import { CloudDeviceService } from "dt-common-device";
13
37
 
14
- // Example: create a connection (must implement this in your project)
15
- await connectionService.createConnection(connectionData, userId);
38
+ const cloudService = new CloudDeviceService();
16
39
 
17
- // Example: get device account (must implement this in your project)
18
- await connectionService.getDeviceAccount(connection);
40
+ // Example: get devices (must implement in your project)
41
+ // await cloudService.getDevices(connection);
19
42
  ```
20
43
 
21
- ## Local Functions
22
-
23
- ### DeviceService
44
+ ### Local Device Service
24
45
 
25
46
  ```ts
26
- const deviceService = new local.DeviceService();
47
+ import { LocalDeviceService } from "dt-common-device";
48
+
49
+ const localService = new LocalDeviceService();
27
50
 
28
51
  // Create a device
29
- await deviceService.createDevice(deviceBody, httpClient);
52
+ await localService.createDevice(deviceBody);
30
53
 
31
54
  // Get a device
32
- const device = await deviceService.getDevice(deviceId, httpClient);
55
+ const device = await localService.getDevice(deviceId);
33
56
 
34
57
  // Update a device
35
- await deviceService.updateDevice(deviceId, updateBody, httpClient);
58
+ await localService.updateDevice(deviceId, updateBody);
36
59
 
37
60
  // Delete a device
38
- await deviceService.deleteDevice(deviceId, httpClient);
61
+ await localService.deleteDevice(deviceId);
39
62
  ```
40
63
 
41
- ## Local Functions
42
-
43
- ### DeviceHubService
64
+ ### Local Device Hub Service
44
65
 
45
66
  ```ts
46
- const deviceHubService = new local.DeviceHubService();
67
+ import { LocalDeviceHubService } from "dt-common-device";
68
+
69
+ const deviceHubService = new LocalDeviceHubService();
47
70
 
48
71
  // Add a hub
49
- await deviceHubService.addHub(hubBody, httpClient);
72
+ await deviceHubService.addHub(hubBody);
50
73
 
51
74
  // Get hubs
52
- const hubs = await deviceHubService.getHubs(hubIds, httpClient);
75
+ const hubs = await deviceHubService.getHubs(hubIds);
53
76
 
54
77
  // Get a single hub
55
- const hub = await deviceHubService.getHub(hubId, httpClient);
78
+ const hub = await deviceHubService.getHub(hubId);
56
79
 
57
80
  // Update a hub
58
- await deviceHubService.updateHub(hubId, updateBody, httpClient);
81
+ await deviceHubService.updateHub(hubId, updateBody);
59
82
 
60
83
  // Delete a hub
61
- await deviceHubService.deleteHub(hubId, httpClient);
84
+ await deviceHubService.deleteHub(hubId);
62
85
 
63
86
  // Delete multiple hubs
64
- await deviceHubService.deleteAllHubs(hubIds, httpClient);
87
+ await deviceHubService.deleteAllHubs(hubIds);
65
88
  ```
66
89
 
67
- ### Types
90
+ ---
91
+
92
+ ## Importing Types and Interfaces
68
93
 
69
94
  All types and interfaces are available as named exports:
70
95
 
71
96
  ```ts
72
- import { IDevice, IHubCreateParams } from "dt-common-device";
97
+ import { IDevice, IHubCreateParams, IConnection } from "dt-common-device";
98
+ ```
99
+
100
+ ---
101
+
102
+ ## Notes
103
+
104
+ - You **must** call `initialize()` before using any service. If not, you will get a runtime error.
105
+ - Cloud service methods are stubs and must be implemented by the consuming project.
106
+ - All types are strongly typed for TypeScript support.
107
+
108
+ ---
109
+
110
+ ## Example Usage
111
+
112
+ ```ts
113
+ import {
114
+ initialize,
115
+ CloudDeviceService,
116
+ LocalDeviceService,
117
+ IDevice,
118
+ } from "dt-common-device";
119
+
120
+ initialize({
121
+ DEVICE_SERVICE: "https://api.example.com/device",
122
+ });
123
+
124
+ const cloudService = new CloudDeviceService();
125
+ const localService = new LocalDeviceService();
126
+
127
+ async function main() {
128
+ // Example: get devices from cloud (must implement in your project)
129
+ // const devices: IDevice[] = await cloudService.getDevices(connection);
130
+
131
+ // Example: create a device locally
132
+ await localService.createDevice({
133
+ /* device params */
134
+ });
135
+ }
136
+
137
+ main();
73
138
  ```
@@ -0,0 +1,3 @@
1
+ import { DeviceConfig } from "../types";
2
+ export declare function initialize(cfg: DeviceConfig): void;
3
+ export declare function getConfig(): DeviceConfig;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initialize = initialize;
4
+ exports.getConfig = getConfig;
5
+ let config = null;
6
+ function initialize(cfg) {
7
+ // Check if at least one service is provided
8
+ const hasAtLeastOneService = [
9
+ "ADMIN_SERVICE",
10
+ "OPERATIONAL_SERVICE",
11
+ "DEVICE_SERVICE",
12
+ "MONITORING_SERVICE",
13
+ ].some((key) => Boolean(cfg[key]));
14
+ if (!hasAtLeastOneService) {
15
+ throw new Error("At least one http service must be initialized");
16
+ }
17
+ config = { ...cfg };
18
+ }
19
+ function getConfig() {
20
+ if (!config) {
21
+ throw new Error("dt-common-device: Library not initialized. Call initialize() first.");
22
+ }
23
+ return config;
24
+ }
@@ -1,39 +1,8 @@
1
1
  import { IConnection, IConnectionConnectParams, IDevice, IDeviceAccountResponse } from "../types";
2
- /**
3
- * Class interface for device cloud operations and connection management
4
- */
5
2
  export interface IDeviceConnectionService {
6
- /**
7
- * Creates a new connection for device management
8
- * @param data - Connection data
9
- * @param userId - User identifier
10
- * @returns Promise with connection result
11
- */
12
3
  createConnection(data: IConnection, userId: string): Promise<any>;
13
- /**
14
- * Gets device account information for a connection
15
- * @param connection - Connection object
16
- * @returns Promise with device account response
17
- */
18
4
  getDeviceAccount(connection: IConnection): Promise<IDeviceAccountResponse>;
19
- /**
20
- * Gets all devices for a connection
21
- * @param connection - Connection object
22
- * @returns Promise with array of devices
23
- */
24
- getDevices(connection: IConnection): Promise<any>;
25
- /**
26
- * Filters devices based on connection and device list
27
- * @param connection - Connection object
28
- * @param devices - Array of devices to filter
29
- * @returns Promise with filtered devices
30
- */
31
- filterDevices(connection: IConnection, devices: any[]): Promise<IDevice[]>;
32
- /**
33
- * Connects to a device service
34
- * @param connection - Connection object
35
- * @param connectionConnect - Connection parameters
36
- * @returns Promise with connection result
37
- */
5
+ getDevices(connection: IConnection): Promise<IDevice[]>;
6
+ filterDevices(connection: IConnection, devices: Record<string, any>[]): Promise<IDevice[]>;
38
7
  connect(connection: IConnection, connectionConnect: IConnectionConnectParams): Promise<any>;
39
8
  }
@@ -1,9 +1,9 @@
1
1
  import { IConnection } from "../types";
2
2
  export interface IDeviceService {
3
- getDevices(connection: IConnection): Promise<any[]>;
4
- getDevice(connectionId: string, deviceId: string): Promise<any>;
3
+ getDevices(connection: IConnection): Promise<Record<string, any>[]>;
4
+ getDevice(connectionId: string, deviceId: string): Promise<Record<string, any>>;
5
5
  getStatus(connectionId: string, deviceId: string): Promise<string | null>;
6
- getState(deviceId: string): Promise<any>;
6
+ getState(deviceId: string): Promise<Record<string, any>>;
7
7
  getGateways(connectionId: string): Promise<any[] | null>;
8
8
  getGatewayDetails(connectionId: string, gatewayId: string): Promise<any>;
9
9
  }
@@ -1,42 +1,9 @@
1
1
  import { IDeviceConnectionService } from "../interfaces";
2
- import { IConnection, IConnectionConnectParams, IDevice, IDeviceAccountResponse } from "../types";
3
- /**
4
- * Device Cloud Service Class
5
- * Implements IDeviceCloudService interface with empty implementations
6
- * Implementation will be provided by the consuming project
7
- */
2
+ import { IConnection, IDevice, IDeviceAccountResponse } from "../types";
8
3
  export declare class ConnectionService implements IDeviceConnectionService {
9
- /**
10
- * Creates a new connection for device management
11
- * @param data - Connection data
12
- * @param userId - User identifier
13
- * @returns Promise with connection result
14
- */
15
- createConnection(data: IConnection, userId: string): Promise<any>;
16
- /**
17
- * Gets device account information for a connection
18
- * @param connection - Connection object
19
- * @returns Promise with device account response
20
- */
4
+ createConnection(data: IConnection, userId: string): Promise<void>;
21
5
  getDeviceAccount(connection: IConnection): Promise<IDeviceAccountResponse>;
22
- /**
23
- * Gets all devices for a connection
24
- * @param connection - Connection object
25
- * @returns Promise with array of devices
26
- */
27
- getDevices(connection: IConnection): Promise<any>;
28
- /**
29
- * Filters devices based on connection and device list
30
- * @param connection - Connection object
31
- * @param devices - Array of devices to filter
32
- * @returns Promise with filtered devices
33
- */
34
- filterDevices(connection: IConnection, devices: any[]): Promise<IDevice[]>;
35
- /**
36
- * Connects to a device service
37
- * @param connection - Connection object
38
- * @param connectionConnect - Connection parameters
39
- * @returns Promise with connection result
40
- */
41
- connect(connection: IConnection, connectionConnect: IConnectionConnectParams): Promise<any>;
6
+ getDevices(connection: IConnection): Promise<IDevice[]>;
7
+ filterDevices(connection: IConnection, devices: Record<string, any>[]): Promise<IDevice[]>;
8
+ connect(connection: IConnection): Promise<void>;
42
9
  }
@@ -1,57 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConnectionService = void 0;
4
- /**
5
- * Device Cloud Service Class
6
- * Implements IDeviceCloudService interface with empty implementations
7
- * Implementation will be provided by the consuming project
8
- */
9
4
  class ConnectionService {
10
- /**
11
- * Creates a new connection for device management
12
- * @param data - Connection data
13
- * @param userId - User identifier
14
- * @returns Promise with connection result
15
- */
16
5
  async createConnection(data, userId) {
17
6
  // Implementation will be provided by the consuming project
18
7
  throw new Error("createConnection method not implemented");
19
8
  }
20
- /**
21
- * Gets device account information for a connection
22
- * @param connection - Connection object
23
- * @returns Promise with device account response
24
- */
25
9
  async getDeviceAccount(connection) {
26
10
  // Implementation will be provided by the consuming project
27
11
  throw new Error("getDeviceAccount method not implemented");
28
12
  }
29
- /**
30
- * Gets all devices for a connection
31
- * @param connection - Connection object
32
- * @returns Promise with array of devices
33
- */
34
13
  async getDevices(connection) {
35
14
  // Implementation will be provided by the consuming project
36
15
  throw new Error("getDevices method not implemented");
37
16
  }
38
- /**
39
- * Filters devices based on connection and device list
40
- * @param connection - Connection object
41
- * @param devices - Array of devices to filter
42
- * @returns Promise with filtered devices
43
- */
44
17
  async filterDevices(connection, devices) {
45
18
  // Implementation will be provided by the consuming project
46
19
  throw new Error("filterDevices method not implemented");
47
20
  }
48
- /**
49
- * Connects to a device service
50
- * @param connection - Connection object
51
- * @param connectionConnect - Connection parameters
52
- * @returns Promise with connection result
53
- */
54
- async connect(connection, connectionConnect) {
21
+ async connect(connection) {
55
22
  // Implementation will be provided by the consuming project
56
23
  throw new Error("connect method not implemented");
57
24
  }
@@ -1,10 +1,10 @@
1
1
  import { IDeviceService } from "../interfaces";
2
2
  import { IConnection } from "../types";
3
3
  export declare class DeviceService implements IDeviceService {
4
- getDevices(connection: IConnection): Promise<any[]>;
4
+ getDevices(connection: IConnection): Promise<Record<string, any>[]>;
5
5
  getDevice(connectionId: string, deviceId: string): Promise<any>;
6
6
  getStatus(connectionId: string, deviceId: string): Promise<string | null>;
7
- getState(deviceId: string): Promise<any>;
7
+ getState(deviceId: string): Promise<Record<string, any>>;
8
8
  getGateways(connectionId: string): Promise<any[] | null>;
9
- getGatewayDetails(connectionId: string, gatewayId: string): Promise<any>;
9
+ getGatewayDetails(connectionId: string, gatewayId: string): Promise<Record<string, any>>;
10
10
  }
@@ -1,2 +1,3 @@
1
- export * from "./Connection.service";
2
- export * from "./Device.service";
1
+ export { DeviceService as CloudDeviceService } from "./Device.service";
2
+ export { ConnectionService as CloudConnectionService } from "./Connection.service";
3
+ export { DeviceHubService as CloudDeviceHubService } from "./DeviceHub.service";
@@ -1,19 +1,10 @@
1
1
  "use strict";
2
2
  // Device Cloud Services - Export all service classes
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
- };
17
3
  Object.defineProperty(exports, "__esModule", { value: true });
18
- __exportStar(require("./Connection.service"), exports);
19
- __exportStar(require("./Device.service"), exports);
4
+ exports.CloudDeviceHubService = exports.CloudConnectionService = exports.CloudDeviceService = void 0;
5
+ var Device_service_1 = require("./Device.service");
6
+ Object.defineProperty(exports, "CloudDeviceService", { enumerable: true, get: function () { return Device_service_1.DeviceService; } });
7
+ var Connection_service_1 = require("./Connection.service");
8
+ Object.defineProperty(exports, "CloudConnectionService", { enumerable: true, get: function () { return Connection_service_1.ConnectionService; } });
9
+ var DeviceHub_service_1 = require("./DeviceHub.service");
10
+ Object.defineProperty(exports, "CloudDeviceHubService", { enumerable: true, get: function () { return DeviceHub_service_1.DeviceHubService; } });
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Represents a connection to a device provider.
3
+ * WARNING: Do not log or expose sensitive fields (accessToken, clientSecret).
4
+ */
1
5
  export interface IConnection {
2
6
  connectionName: string;
3
7
  connectionRefId: string;
@@ -7,6 +11,14 @@ export interface IConnection {
7
11
  clientId?: string;
8
12
  clientSecret?: string;
9
13
  }
14
+ export interface IConnectionPagination {
15
+ page: number;
16
+ limit: number;
17
+ }
18
+ /**
19
+ * Represents a device in the system.
20
+ * All date fields must be ISO 8601 strings.
21
+ */
10
22
  export interface IDevice {
11
23
  deviceId: string;
12
24
  propertyId: string;
@@ -49,8 +61,23 @@ export interface IDevice {
49
61
  };
50
62
  state?: Record<string, any>;
51
63
  metaData?: Record<string, any>;
64
+ createdAt?: Date;
65
+ updatedAt?: Date;
66
+ isDeleted?: boolean;
52
67
  hubDeviceDetails?: IDevice[];
68
+ parentZones?: {
69
+ id: string;
70
+ name: string;
71
+ }[];
72
+ zone?: {
73
+ id: string;
74
+ name: string;
75
+ };
53
76
  }
77
+ /**
78
+ * Device account response from provider.
79
+ * WARNING: Do not log or expose connection_access_token.
80
+ */
54
81
  export interface IDeviceAccountResponse {
55
82
  id: string;
56
83
  connection_name: string;
@@ -63,7 +90,7 @@ export interface IDeviceAccountResponse {
63
90
  export interface IConnectionConnectParams {
64
91
  code?: string;
65
92
  propertyId?: string;
66
- [key: string]: any;
93
+ [key: string]: unknown;
67
94
  }
68
95
  export interface ConnectionProvider {
69
96
  Smartthings: "Smartthings";
@@ -1,18 +1,10 @@
1
1
  import { IDeviceCreateParams } from "../interfaces";
2
2
  export declare class DeviceService {
3
- createDevice(body: IDeviceCreateParams, httpClient: {
4
- post: (url: string, options: any) => Promise<any>;
5
- }): Promise<void>;
6
- getDevice(deviceId: string, httpClient: {
7
- get: (url: string) => Promise<any>;
8
- }): Promise<any>;
9
- getPropertyDevices(propertyId: string, httpClient: {
10
- get: (url: string, options: any) => Promise<any>;
11
- }): Promise<any>;
12
- updateDevice(deviceId: string, body: any, httpClient: {
13
- put: (url: string, options: any) => Promise<any>;
14
- }): Promise<any>;
15
- deleteDevice(deviceId: string, httpClient: {
16
- delete: (url: string) => Promise<any>;
17
- }): Promise<any>;
3
+ private readonly baseUrl;
4
+ constructor();
5
+ createDevice(body: IDeviceCreateParams): Promise<void>;
6
+ getDevice(deviceId: string): Promise<any>;
7
+ getPropertyDevices(propertyId: string): Promise<any>;
8
+ updateDevice(deviceId: string, body: any): Promise<any>;
9
+ deleteDevice(deviceId: string): Promise<any>;
18
10
  }
@@ -1,27 +1,36 @@
1
1
  "use strict";
2
2
  // src/device/local/services/Device.service.ts
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
3
6
  Object.defineProperty(exports, "__esModule", { value: true });
4
7
  exports.DeviceService = void 0;
8
+ const axios_1 = __importDefault(require("axios"));
9
+ const config_1 = require("../../../config/config");
5
10
  class DeviceService {
6
- async createDevice(body, httpClient) {
7
- // Create main device
8
- await httpClient.post("/devices", { body });
11
+ constructor() {
12
+ const { DEVICE_SERVICE } = (0, config_1.getConfig)();
13
+ if (!DEVICE_SERVICE) {
14
+ throw new Error("DEVICE_SERVICE is not configured. Call initialize() first with DEVICE_SERVICE.");
15
+ }
16
+ this.baseUrl = DEVICE_SERVICE;
9
17
  }
10
- async getDevice(deviceId, httpClient) {
11
- return await httpClient.get(`/devices/${deviceId}`);
18
+ async createDevice(body) {
19
+ await axios_1.default.post(`${this.baseUrl}/devices`, body);
12
20
  }
13
- async getPropertyDevices(propertyId, httpClient) {
14
- return await httpClient.get(`/devices`, {
15
- params: {
16
- propertyId,
17
- },
21
+ async getDevice(deviceId) {
22
+ return await axios_1.default.get(`${this.baseUrl}/devices/${deviceId}`);
23
+ }
24
+ async getPropertyDevices(propertyId) {
25
+ return await axios_1.default.get(`${this.baseUrl}/devices`, {
26
+ params: { propertyId },
18
27
  });
19
28
  }
20
- async updateDevice(deviceId, body, httpClient) {
21
- return await httpClient.put(`/devices/${deviceId}`, { body });
29
+ async updateDevice(deviceId, body) {
30
+ return await axios_1.default.put(`${this.baseUrl}/devices/${deviceId}`, body);
22
31
  }
23
- async deleteDevice(deviceId, httpClient) {
24
- return await httpClient.delete(`/devices/${deviceId}`);
32
+ async deleteDevice(deviceId) {
33
+ return await axios_1.default.delete(`${this.baseUrl}/devices/${deviceId}`);
25
34
  }
26
35
  }
27
36
  exports.DeviceService = DeviceService;
@@ -1,21 +1,11 @@
1
1
  import { IHubCreateParams } from "../interfaces";
2
2
  export declare class DeviceHubService {
3
- addHub(body: IHubCreateParams, httpClient: {
4
- post: (url: string, options: any) => Promise<any>;
5
- }): Promise<any>;
6
- getHubs(hubIds: string[], httpClient: {
7
- get: (url: string, options?: any) => Promise<any>;
8
- }): Promise<any>;
9
- getHub(hubId: string, httpClient: {
10
- get: (url: string) => Promise<any>;
11
- }): Promise<any>;
12
- updateHub(hubId: string, body: any, httpClient: {
13
- put: (url: string, options: any) => Promise<any>;
14
- }): Promise<any>;
15
- deleteHub(hubId: string, httpClient: {
16
- delete: (url: string) => Promise<any>;
17
- }): Promise<any>;
18
- deleteAllHubs(hubIds: string[], httpClient: {
19
- delete: (url: string) => Promise<any>;
20
- }): Promise<any>;
3
+ private readonly baseUrl;
4
+ constructor();
5
+ addHub(body: IHubCreateParams): Promise<any>;
6
+ getHubs(hubIds: string[]): Promise<any>;
7
+ getHub(hubId: string): Promise<any>;
8
+ updateHub(hubId: string, body: any): Promise<any>;
9
+ deleteHub(hubId: string): Promise<any>;
10
+ deleteAllHubs(hubIds: string[]): Promise<any>;
21
11
  }
@@ -1,28 +1,40 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.DeviceHubService = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const config_1 = require("../../../config/config");
4
9
  class DeviceHubService {
5
- async addHub(body, httpClient) {
6
- return await httpClient.post(`/devices/hubs`, { body });
10
+ constructor() {
11
+ const { DEVICE_SERVICE } = (0, config_1.getConfig)();
12
+ if (!DEVICE_SERVICE) {
13
+ throw new Error("DEVICE_SERVICE is not configured. Call initialize() first with DEVICE_SERVICE.");
14
+ }
15
+ this.baseUrl = DEVICE_SERVICE;
16
+ }
17
+ async addHub(body) {
18
+ return await axios_1.default.post(`${this.baseUrl}/devices/hubs`, body);
7
19
  }
8
20
  //get hubs takes an array of hub ids as query params
9
- async getHubs(hubIds, httpClient) {
21
+ async getHubs(hubIds) {
10
22
  const query = hubIds && hubIds.length ? `?ids=${hubIds.join(",")}` : "";
11
- return await httpClient.get(`/devices/hubs${query}`);
23
+ return await axios_1.default.get(`${this.baseUrl}/devices/hubs${query}`);
12
24
  }
13
25
  //get hub takes a hub id in params
14
- async getHub(hubId, httpClient) {
15
- return await httpClient.get(`/devices/hubs/${hubId}`);
26
+ async getHub(hubId) {
27
+ return await axios_1.default.get(`${this.baseUrl}/devices/hubs/${hubId}`);
16
28
  }
17
- async updateHub(hubId, body, httpClient) {
18
- return await httpClient.put(`/devices/hubs/${hubId}`, { body });
29
+ async updateHub(hubId, body) {
30
+ return await axios_1.default.put(`${this.baseUrl}/devices/hubs/${hubId}`, body);
19
31
  }
20
- async deleteHub(hubId, httpClient) {
21
- return await httpClient.delete(`/devices/hubs/${hubId}`);
32
+ async deleteHub(hubId) {
33
+ return await axios_1.default.delete(`${this.baseUrl}/devices/hubs/${hubId}`);
22
34
  }
23
- async deleteAllHubs(hubIds, httpClient) {
35
+ async deleteAllHubs(hubIds) {
24
36
  const query = hubIds.length ? `?ids=${hubIds.join(",")}` : "";
25
- return await httpClient.delete(`/devices/hubs${query}`);
37
+ return await axios_1.default.delete(`${this.baseUrl}/devices/hubs${query}`);
26
38
  }
27
39
  }
28
40
  exports.DeviceHubService = DeviceHubService;
@@ -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";
@@ -1,18 +1,7 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Device.service"), exports);
18
- __exportStar(require("./DeviceHub.service"), exports);
3
+ exports.LocalDeviceHubService = exports.LocalDeviceService = void 0;
4
+ var Device_service_1 = require("./Device.service");
5
+ Object.defineProperty(exports, "LocalDeviceService", { enumerable: true, get: function () { return Device_service_1.DeviceService; } });
6
+ var DeviceHub_service_1 = require("./DeviceHub.service");
7
+ Object.defineProperty(exports, "LocalDeviceHubService", { enumerable: true, get: function () { return DeviceHub_service_1.DeviceHubService; } });