dt-common-device 1.0.12 → 1.0.14

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 (65) hide show
  1. package/README.md +15 -35
  2. package/dist/config/config.d.ts +13 -0
  3. package/dist/config/config.js +30 -0
  4. package/dist/db/db.d.ts +2 -0
  5. package/dist/db/db.js +15 -0
  6. package/dist/db/index.d.ts +2 -0
  7. package/dist/db/index.js +18 -0
  8. package/dist/db/redis.d.ts +2 -0
  9. package/dist/db/redis.js +22 -0
  10. package/dist/device/cloud/entities/CloudDevice.d.ts +15 -0
  11. package/dist/device/cloud/entities/CloudDevice.js +42 -0
  12. package/dist/device/cloud/entities/DeviceFactory.d.ts +6 -0
  13. package/dist/device/cloud/entities/DeviceFactory.js +13 -0
  14. package/dist/device/cloud/entities/index.d.ts +2 -0
  15. package/dist/device/cloud/entities/index.js +18 -0
  16. package/dist/device/cloud/interfaces/ICloudDevice.d.ts +9 -0
  17. package/dist/device/cloud/interfaces/ICloudDevice.js +2 -0
  18. package/dist/device/cloud/interfaces/ICloudDeviceService.d.ts +4 -0
  19. package/dist/device/cloud/interfaces/ICloudDeviceService.js +2 -0
  20. package/dist/device/cloud/interfaces/IConnectionService.js +0 -1
  21. package/dist/device/cloud/interfaces/index.d.ts +2 -0
  22. package/dist/device/cloud/interfaces/index.js +2 -0
  23. package/dist/device/cloud/services/CloudDevice.service.d.ts +5 -0
  24. package/dist/device/cloud/services/CloudDevice.service.js +6 -0
  25. package/dist/device/cloud/services/Connection.service.d.ts +1 -1
  26. package/dist/device/cloud/services/index.d.ts +2 -3
  27. package/dist/device/cloud/services/index.js +16 -8
  28. package/dist/device/cloud/types.d.ts +9 -68
  29. package/dist/device/cloud/types.js +0 -12
  30. package/dist/device/local/interfaces/IConnection.d.ts +16 -0
  31. package/dist/device/local/interfaces/IConnection.js +2 -0
  32. package/dist/device/local/interfaces/IDevice.d.ts +4 -0
  33. package/dist/device/local/services/Connection.service.d.ts +5 -0
  34. package/dist/device/local/services/Connection.service.js +14 -0
  35. package/dist/device/local/services/Device.service.d.ts +7 -3
  36. package/dist/device/local/services/Device.service.js +85 -31
  37. package/dist/device/local/services/index.d.ts +2 -1
  38. package/dist/device/local/services/index.js +4 -2
  39. package/dist/index.d.ts +5 -4
  40. package/dist/index.js +8 -27
  41. package/package.json +7 -9
  42. package/src/config/config.ts +31 -0
  43. package/src/db/db.ts +15 -0
  44. package/src/db/index.ts +2 -0
  45. package/src/db/redis.ts +18 -0
  46. package/src/device/cloud/entities/CloudDevice.ts +56 -0
  47. package/src/device/cloud/entities/DeviceFactory.ts +14 -0
  48. package/src/device/cloud/entities/index.ts +2 -0
  49. package/src/device/cloud/interfaces/ICloudDevice.ts +15 -0
  50. package/src/device/cloud/interfaces/ICloudDeviceService.ts +6 -0
  51. package/src/device/cloud/interfaces/IConnectionService.ts +0 -2
  52. package/src/device/cloud/interfaces/index.ts +2 -0
  53. package/src/device/cloud/services/CloudDevice.service.ts +6 -0
  54. package/src/device/cloud/services/Connection.service.ts +1 -1
  55. package/src/device/cloud/services/index.ts +2 -5
  56. package/src/device/cloud/types.ts +9 -63
  57. package/src/device/local/interfaces/IConnection.ts +17 -0
  58. package/src/device/local/interfaces/IDevice.ts +4 -0
  59. package/src/device/local/interfaces/index.ts +1 -1
  60. package/src/device/local/services/Connection.service.ts +15 -0
  61. package/src/device/local/services/Device.service.ts +107 -31
  62. package/src/device/local/services/index.ts +2 -1
  63. package/src/index.ts +9 -5
  64. package/src/device/cloud/services/Device.service.ts +0 -41
  65. package/src/device/cloud/services/Hub.service.ts +0 -34
package/README.md CHANGED
@@ -20,6 +20,20 @@ npm install dt-common-device
20
20
  - `dt-common-device` will automatically initialize audit logging using these environment variables when you create a local device service.
21
21
  - If either variable is missing, the library will throw a clear error at runtime.
22
22
 
23
+ ## Environment Variables
24
+
25
+ This library requires the following environment variable to be set in your project's environment or in a `.env` file:
26
+
27
+ - `POSTGRESQL_DB_URI`: The connection URI for your PostgreSQL database.
28
+
29
+ Example `.env` file:
30
+
31
+ ```
32
+ POSTGRESQL_DB_URI=postgres://username:password@host:port/database
33
+ ```
34
+
35
+ The library will throw an error if this variable is not set when attempting to connect to the database.
36
+
23
37
  ---
24
38
 
25
39
  ## Initialization (Required)
@@ -176,38 +190,4 @@ import { IDevice, IHub, IConnection } from "dt-common-device";
176
190
 
177
191
  - You **must** call `initialize()` before using any service. If not, you will get a runtime error.
178
192
  - **You must set `POSTHOG_API_KEY` and `POSTHOG_HOST` in your environment before using any local device service.**
179
- - You do **not** need to call `initializeAudit()`; the library will handle audit initialization automatically.
180
- - Cloud service methods are stubs and must be implemented by the consuming project.
181
- - All types are strongly typed for TypeScript support.
182
-
183
- ---
184
-
185
- ## Example Usage
186
-
187
- ```ts
188
- import {
189
- initialize,
190
- CloudDeviceService,
191
- LocalDeviceService,
192
- IDevice,
193
- } from "dt-common-device";
194
-
195
- initialize({
196
- DEVICE_SERVICE: "https://api.example.com/device",
197
- });
198
-
199
- const cloudService = new CloudDeviceService();
200
- const localService = new LocalDeviceService();
201
-
202
- async function main() {
203
- // Example: get devices from cloud (must implement in your project)
204
- // const devices: IDevice[] = await cloudService.getDevices(connection);
205
-
206
- // Example: create a device locally
207
- await localService.createDevice({
208
- /* device params */
209
- });
210
- }
211
-
212
- main();
213
- ```
193
+ - You do **not** need to call `initializeAudit()`
@@ -3,3 +3,16 @@ export declare function initialize(cfg: DeviceConfig): void;
3
3
  export declare function getConfig(): DeviceConfig;
4
4
  export declare function checkAwsEnv(): void;
5
5
  export declare function ensureAuditInitialized(): void;
6
+ /**
7
+ * Returns the PostgreSQL DB URI from environment variables.
8
+ * Throws an error if not set.
9
+ */
10
+ export declare function getPostgresDbUri(): string;
11
+ /**
12
+ * Returns the Redis DB Host and port from environment variables.
13
+ * Throws an error if not set.
14
+ */
15
+ export declare function getRedisDbHostAndPort(): {
16
+ host: string;
17
+ port: number;
18
+ };
@@ -1,10 +1,17 @@
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.initialize = initialize;
4
7
  exports.getConfig = getConfig;
5
8
  exports.checkAwsEnv = checkAwsEnv;
6
9
  exports.ensureAuditInitialized = ensureAuditInitialized;
10
+ exports.getPostgresDbUri = getPostgresDbUri;
11
+ exports.getRedisDbHostAndPort = getRedisDbHostAndPort;
7
12
  const dt_audit_library_1 = require("dt-audit-library");
13
+ const dotenv_1 = __importDefault(require("dotenv"));
14
+ dotenv_1.default.config();
8
15
  let config = null;
9
16
  let auditInitialized = false;
10
17
  function initialize(cfg) {
@@ -50,3 +57,26 @@ function ensureAuditInitialized() {
50
57
  (0, dt_audit_library_1.initializeAudit)(apiKey, host);
51
58
  auditInitialized = true;
52
59
  }
60
+ /**
61
+ * Returns the PostgreSQL DB URI from environment variables.
62
+ * Throws an error if not set.
63
+ */
64
+ function getPostgresDbUri() {
65
+ const uri = process.env.DATABASE_URL;
66
+ if (!uri) {
67
+ throw new Error("dt-common-device: POSTGRESQL_DB_URI must be set in environment variables or .env file");
68
+ }
69
+ return uri;
70
+ }
71
+ /**
72
+ * Returns the Redis DB Host and port from environment variables.
73
+ * Throws an error if not set.
74
+ */
75
+ function getRedisDbHostAndPort() {
76
+ const host = process.env.REDIS_HOST;
77
+ const port = process.env.REDIS_PORT;
78
+ if (!host || !port) {
79
+ throw new Error("dt-common-device: REDIS_HOST and REDIS_PORT must be set in environment variables");
80
+ }
81
+ return { host, port: Number(port) };
82
+ }
@@ -0,0 +1,2 @@
1
+ import { Pool } from "pg";
2
+ export declare function getPostgresClient(): Pool;
package/dist/db/db.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPostgresClient = getPostgresClient;
4
+ const pg_1 = require("pg");
5
+ const config_1 = require("../config/config");
6
+ const dbUri = (0, config_1.getPostgresDbUri)();
7
+ let pool = null;
8
+ function getPostgresClient() {
9
+ if (!pool) {
10
+ pool = new pg_1.Pool({
11
+ connectionString: dbUri,
12
+ });
13
+ }
14
+ return pool;
15
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./db";
2
+ export * from "./redis";
@@ -0,0 +1,18 @@
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("./db"), exports);
18
+ __exportStar(require("./redis"), exports);
@@ -0,0 +1,2 @@
1
+ import Redis from "ioredis";
2
+ export declare function getRedisClient(): Redis;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getRedisClient = getRedisClient;
7
+ const config_1 = require("../config/config");
8
+ const ioredis_1 = __importDefault(require("ioredis"));
9
+ let redisClient = null;
10
+ function getRedisClient() {
11
+ if (!redisClient) {
12
+ const { host, port } = (0, config_1.getRedisDbHostAndPort)();
13
+ redisClient = new ioredis_1.default({
14
+ host,
15
+ port,
16
+ });
17
+ redisClient.on("error", (error) => {
18
+ console.error("Redis error:", error);
19
+ });
20
+ }
21
+ return redisClient;
22
+ }
@@ -0,0 +1,15 @@
1
+ import { IDevice } from "../../local/interfaces";
2
+ import { ICloudDevice } from "../interfaces/ICloudDevice";
3
+ import { ICloudDeviceService } from "../interfaces/ICloudDeviceService";
4
+ import { IConnection } from "../types";
5
+ export declare abstract class CloudDevice implements ICloudDevice {
6
+ deviceId: string;
7
+ localDevice?: IDevice;
8
+ connection?: IConnection;
9
+ cloudDeviceService: ICloudDeviceService;
10
+ constructor(device: IDevice, cloudDeviceService: ICloudDeviceService);
11
+ getDevice(connectionId: string, deviceId: string): Promise<Record<string, any>>;
12
+ getBattery(deviceId: string): Promise<number | string>;
13
+ getState(deviceId: string): Promise<string>;
14
+ getStatus(connectionId: string, deviceId: string): Promise<string>;
15
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CloudDevice = void 0;
4
+ class CloudDevice {
5
+ constructor(device, cloudDeviceService) {
6
+ this.deviceId = device.deviceId;
7
+ this.localDevice = device;
8
+ this.cloudDeviceService = cloudDeviceService;
9
+ }
10
+ async getDevice(connectionId, deviceId) {
11
+ throw new Error("Method not implemented in Super Class.");
12
+ }
13
+ async getBattery(deviceId) {
14
+ throw new Error("Method not implemented in Super Class.");
15
+ }
16
+ async getState(deviceId) {
17
+ throw new Error("Method not implemented in Super Class.");
18
+ }
19
+ async getStatus(connectionId, deviceId) {
20
+ throw new Error("Method not implemented in Super Class.");
21
+ }
22
+ }
23
+ exports.CloudDevice = CloudDevice;
24
+ /*
25
+ Usage Example:
26
+
27
+ // When extending CloudDevice, you can now do:
28
+ class MyCloudDevice extends CloudDevice {
29
+ constructor(device: IDevice, cloudDeviceService: ICloudDeviceService) {
30
+ super(device, cloudDeviceService);
31
+ // Additional initialization if needed
32
+ }
33
+ }
34
+
35
+ // Create and initialize in one step:
36
+ const device = await MyCloudDevice.create(device, cloudDeviceService);
37
+ // The device is now fully initialized with connection and localDevice loaded
38
+
39
+ // Or if you need to create without auto-initialization:
40
+ const device = new MyCloudDevice(device, cloudDeviceService);
41
+ await device.initialize(); // Manual initialization
42
+ */
@@ -0,0 +1,6 @@
1
+ import { IDevice } from "../../local/interfaces";
2
+ export declare class DeviceFactory {
3
+ private readonly localDeviceService;
4
+ constructor();
5
+ getDevice(deviceId: string): Promise<IDevice>;
6
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeviceFactory = void 0;
4
+ const Device_service_1 = require("../../local/services/Device.service");
5
+ class DeviceFactory {
6
+ constructor() {
7
+ this.localDeviceService = new Device_service_1.LocalDeviceService();
8
+ }
9
+ async getDevice(deviceId) {
10
+ return await this.localDeviceService.getDevice(deviceId);
11
+ }
12
+ }
13
+ exports.DeviceFactory = DeviceFactory;
@@ -0,0 +1,2 @@
1
+ export * from "./CloudDevice";
2
+ export * from "./DeviceFactory";
@@ -0,0 +1,18 @@
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("./CloudDevice"), exports);
18
+ __exportStar(require("./DeviceFactory"), exports);
@@ -0,0 +1,9 @@
1
+ import { ICloudDeviceService } from "./ICloudDeviceService";
2
+ export interface ICloudDevice {
3
+ deviceId: string;
4
+ cloudDeviceService: ICloudDeviceService;
5
+ getDevice(connectionId: string, deviceId: string): Promise<Record<string, any>>;
6
+ getBattery(deviceId: string): Promise<number | string>;
7
+ getState(deviceId: string): Promise<string>;
8
+ getStatus(connectionId: string, deviceId: string): Promise<string>;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import { IConnection } from "../types";
2
+ export interface ICloudDeviceService {
3
+ getConnection(deviceId: string): Promise<IConnection>;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
- // Device Cloud Class Interface for DeviceThread Common Library
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,5 @@
1
1
  export * from "./IConnectionService";
2
2
  export * from "./IDeviceService";
3
3
  export * from "./IHubService";
4
+ export * from "./ICloudDevice";
5
+ export * from "./ICloudDeviceService";
@@ -17,3 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./IConnectionService"), exports);
18
18
  __exportStar(require("./IDeviceService"), exports);
19
19
  __exportStar(require("./IHubService"), exports);
20
+ __exportStar(require("./ICloudDevice"), exports);
21
+ __exportStar(require("./ICloudDeviceService"), exports);
@@ -0,0 +1,5 @@
1
+ import { ICloudDeviceService } from "../interfaces/ICloudDeviceService";
2
+ import { IConnection } from "../types";
3
+ export declare abstract class CloudDeviceService implements ICloudDeviceService {
4
+ abstract getConnection(deviceId: string): Promise<IConnection>;
5
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CloudDeviceService = void 0;
4
+ class CloudDeviceService {
5
+ }
6
+ exports.CloudDeviceService = CloudDeviceService;
@@ -1,5 +1,5 @@
1
1
  import { IConnectionService } from "../interfaces";
2
- import { IConnection, IDeviceAccountResponse, IConnectionConnectParams } from "../types";
2
+ import { IDeviceAccountResponse, IConnectionConnectParams, IConnection } from "../types";
3
3
  export declare abstract class ConnectionService implements IConnectionService {
4
4
  abstract createConnection(data: IConnection, userId: string): Promise<any>;
5
5
  abstract getDeviceAccount(connection: IConnection): Promise<IDeviceAccountResponse>;
@@ -1,3 +1,2 @@
1
- export { DeviceService as CloudDeviceService } from "./Device.service";
2
- export { ConnectionService as CloudConnectionService } from "./Connection.service";
3
- export { HubService as CloudHubService } from "./Hub.service";
1
+ export * from "./CloudDevice.service";
2
+ export * from "./Connection.service";
@@ -1,10 +1,18 @@
1
1
  "use strict";
2
- // Device Cloud Services - Export all service classes
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
+ };
3
16
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.CloudHubService = 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 Hub_service_1 = require("./Hub.service");
10
- Object.defineProperty(exports, "CloudHubService", { enumerable: true, get: function () { return Hub_service_1.HubService; } });
17
+ __exportStar(require("./CloudDevice.service"), exports);
18
+ __exportStar(require("./Connection.service"), exports);
@@ -21,65 +21,6 @@ export interface IConnectionPagination {
21
21
  page: number;
22
22
  limit: number;
23
23
  }
24
- /**
25
- * Represents a device in the system.
26
- * All date fields must be ISO 8601 strings.
27
- */
28
- export interface IDevice {
29
- deviceId: string;
30
- propertyId: string;
31
- name: string;
32
- hubId: string[];
33
- specifications?: {
34
- manufacturer?: string;
35
- model?: string;
36
- firmware?: {
37
- version?: string;
38
- newVersionAvailable?: boolean;
39
- newVersion?: string;
40
- mandatoryUpdate?: boolean;
41
- };
42
- };
43
- protocol?: {
44
- location?: {
45
- id?: string;
46
- name?: string;
47
- city?: string;
48
- };
49
- name?: string;
50
- room?: {
51
- id?: string;
52
- name?: string;
53
- };
54
- accountId?: string;
55
- };
56
- deviceType: {
57
- id: string;
58
- type: string;
59
- };
60
- status: {
61
- online: boolean;
62
- error?: {
63
- type?: string;
64
- message?: string;
65
- };
66
- lastUpdated?: string;
67
- };
68
- state?: Record<string, any>;
69
- metaData?: Record<string, any>;
70
- createdAt?: Date;
71
- updatedAt?: Date;
72
- isDeleted?: boolean;
73
- hubDeviceDetails?: IDevice[];
74
- parentZones?: {
75
- id: string;
76
- name: string;
77
- }[];
78
- zone?: {
79
- id: string;
80
- name: string;
81
- };
82
- }
83
24
  /**
84
25
  * Device account response from provider.
85
26
  * WARNING: Do not log or expose connection_access_token.
@@ -98,13 +39,13 @@ export interface IConnectionConnectParams {
98
39
  propertyId?: string;
99
40
  [key: string]: unknown;
100
41
  }
101
- export declare enum ConnectionProvider {
102
- Devicethread = "Devicethread",
103
- Smartthings = "Smartthings",
104
- SaltoKS = "SaltoKS",
105
- Tuya = "Tuya",
106
- TTLock = "TTLock",
107
- Schlage = "Schlage",
108
- YaleWifi = "YaleWifi",
109
- Sensibo = "Sensibo"
42
+ export interface ConnectionProvider {
43
+ DEVICETHREAD: "Devicethread";
44
+ SMARTTHINGS: "Smartthings";
45
+ SALTOKS: "SaltoKS";
46
+ TUYA: "Tuya";
47
+ TTLOCK: "TTLock";
48
+ SCHLAGE: "Schlage";
49
+ YALEWIFI: "YaleWifi";
50
+ SENSIBO: "Sensibo";
110
51
  }
@@ -1,15 +1,3 @@
1
1
  "use strict";
2
2
  // Device Cloud Type Interfaces for DeviceThread Common Library
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.ConnectionProvider = void 0;
5
- var ConnectionProvider;
6
- (function (ConnectionProvider) {
7
- ConnectionProvider["Devicethread"] = "Devicethread";
8
- ConnectionProvider["Smartthings"] = "Smartthings";
9
- ConnectionProvider["SaltoKS"] = "SaltoKS";
10
- ConnectionProvider["Tuya"] = "Tuya";
11
- ConnectionProvider["TTLock"] = "TTLock";
12
- ConnectionProvider["Schlage"] = "Schlage";
13
- ConnectionProvider["YaleWifi"] = "YaleWifi";
14
- ConnectionProvider["Sensibo"] = "Sensibo";
15
- })(ConnectionProvider || (exports.ConnectionProvider = ConnectionProvider = {}));
@@ -0,0 +1,16 @@
1
+ import { ConnectionProvider } from "../../cloud/types";
2
+ export interface IConnection {
3
+ id?: string;
4
+ createdAt?: Date;
5
+ updatedAt?: Date;
6
+ isDeleted?: boolean;
7
+ connectionName: string;
8
+ connectionRefId: string;
9
+ propertyId: string;
10
+ connectionProvider: ConnectionProvider;
11
+ accessToken?: string;
12
+ clientId?: string;
13
+ clientSecret?: string;
14
+ isActive?: boolean;
15
+ metaData?: any;
16
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -26,6 +26,10 @@ export interface IDevice {
26
26
  };
27
27
  accountId?: string;
28
28
  };
29
+ account: {
30
+ id: string;
31
+ name: string;
32
+ };
29
33
  deviceType: {
30
34
  id: string;
31
35
  type: string;
@@ -0,0 +1,5 @@
1
+ export declare class ConnectionService {
2
+ private readonly pool;
3
+ constructor();
4
+ getConnection(connectionId: string): Promise<any>;
5
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectionService = void 0;
4
+ const db_1 = require("../../../db");
5
+ class ConnectionService {
6
+ constructor() {
7
+ this.pool = (0, db_1.getPostgresClient)();
8
+ }
9
+ async getConnection(connectionId) {
10
+ const result = await this.pool.query("SELECT * FROM dt_connections WHERE id = $1", [connectionId]);
11
+ return result.rows[0];
12
+ }
13
+ }
14
+ exports.ConnectionService = ConnectionService;
@@ -1,8 +1,11 @@
1
1
  import { IDevice } from "../interfaces";
2
- export declare class DeviceService {
2
+ export declare class LocalDeviceService {
3
3
  private readonly baseUrl;
4
4
  private readonly source;
5
5
  private readonly eventHandler;
6
+ private readonly alertService;
7
+ private readonly redis;
8
+ private readonly postgres;
6
9
  constructor();
7
10
  createDevice(body: IDevice): Promise<void>;
8
11
  getDevice(deviceId: string, withHubDetails?: boolean): Promise<IDevice>;
@@ -18,6 +21,7 @@ export declare class DeviceService {
18
21
  setBatteryLevel(deviceId: string, batteryLevel: number): Promise<void>;
19
22
  getMetaData(deviceId: string): Promise<import("axios").AxiosResponse<any, any>>;
20
23
  setMetaData(deviceId: string, metaData: Record<string, any>): Promise<void>;
21
- getDeviceByZone(zoneId: string): Promise<void>;
22
- getDevicesByAccessGroup(accessGroupId: string): Promise<void>;
24
+ getDeviceByZone(zoneId: string): Promise<any>;
25
+ getDevicesByAccessGroup(accessGroupId: string): Promise<any>;
26
+ getPropertyPreferences(propertyId: string): Promise<any>;
23
27
  }