dt-common-device 1.0.14 → 1.0.16

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.
@@ -1,5 +1,5 @@
1
1
  import { ICloudDeviceService } from "../interfaces/ICloudDeviceService";
2
2
  import { IConnection } from "../types";
3
- export declare abstract class CloudDeviceService implements ICloudDeviceService {
4
- abstract getConnection(deviceId: string): Promise<IConnection>;
3
+ export declare class CloudDeviceService implements ICloudDeviceService {
4
+ getConnection(deviceId: string): Promise<IConnection>;
5
5
  }
@@ -2,5 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CloudDeviceService = void 0;
4
4
  class CloudDeviceService {
5
+ async getConnection(deviceId) {
6
+ throw new Error("Method not implemented.");
7
+ }
5
8
  }
6
9
  exports.CloudDeviceService = CloudDeviceService;
@@ -39,13 +39,13 @@ export interface IConnectionConnectParams {
39
39
  propertyId?: string;
40
40
  [key: string]: unknown;
41
41
  }
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";
42
+ export declare enum ConnectionProvider {
43
+ Smartthings = "Smartthings",
44
+ SaltoKS = "SaltoKS",
45
+ TTLock = "TTLock",
46
+ Tuya = "Tuya",
47
+ Schlage = "Schlage",
48
+ YaleWifi = "YaleWifi",
49
+ Sensibo = "Sensibo",
50
+ Devicethread = "Devicethread"
51
51
  }
@@ -1,3 +1,15 @@
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["Smartthings"] = "Smartthings";
8
+ ConnectionProvider["SaltoKS"] = "SaltoKS";
9
+ ConnectionProvider["TTLock"] = "TTLock";
10
+ ConnectionProvider["Tuya"] = "Tuya";
11
+ ConnectionProvider["Schlage"] = "Schlage";
12
+ ConnectionProvider["YaleWifi"] = "YaleWifi";
13
+ ConnectionProvider["Sensibo"] = "Sensibo";
14
+ ConnectionProvider["Devicethread"] = "Devicethread";
15
+ })(ConnectionProvider || (exports.ConnectionProvider = ConnectionProvider = {}));
@@ -1,5 +1,6 @@
1
- export declare class ConnectionService {
1
+ import { IConnection } from "../interfaces/IConnection";
2
+ export declare class LocalConnectionService {
2
3
  private readonly pool;
3
4
  constructor();
4
- getConnection(connectionId: string): Promise<any>;
5
+ getConnection(connectionId: string): Promise<IConnection>;
5
6
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConnectionService = void 0;
3
+ exports.LocalConnectionService = void 0;
4
4
  const db_1 = require("../../../db");
5
- class ConnectionService {
5
+ class LocalConnectionService {
6
6
  constructor() {
7
7
  this.pool = (0, db_1.getPostgresClient)();
8
8
  }
@@ -11,4 +11,4 @@ class ConnectionService {
11
11
  return result.rows[0];
12
12
  }
13
13
  }
14
- exports.ConnectionService = ConnectionService;
14
+ exports.LocalConnectionService = LocalConnectionService;
@@ -4,7 +4,6 @@ export declare class LocalDeviceService {
4
4
  private readonly source;
5
5
  private readonly eventHandler;
6
6
  private readonly alertService;
7
- private readonly redis;
8
7
  private readonly postgres;
9
8
  constructor();
10
9
  createDevice(body: IDevice): Promise<void>;
@@ -19,7 +19,7 @@ class LocalDeviceService {
19
19
  if (!DEVICE_SERVICE) {
20
20
  throw new Error("DEVICE_SERVICE is not configured. Call initialize() first with DEVICE_SERVICE.");
21
21
  }
22
- this.redis = (0, db_1.getRedisClient)();
22
+ // this.redis = getRedisClient();
23
23
  this.postgres = (0, db_1.getPostgresClient)();
24
24
  this.baseUrl = DEVICE_SERVICE;
25
25
  (0, config_1.checkAwsEnv)();
@@ -137,17 +137,9 @@ class LocalDeviceService {
137
137
  }
138
138
  async getDeviceByZone(zoneId) {
139
139
  try {
140
- // Step 1: Check if zone data is available in Redis
141
- let cached = await this.redis.get(`zone:${zoneId}`);
142
- if (cached) {
143
- // Parse if stored as JSON string
144
- return typeof cached === "string" ? JSON.parse(cached) : cached;
145
- }
146
140
  // If not available, fetch from PostgreSQL DB
147
141
  const result = await this.postgres.query("SELECT * FROM dt_devices WHERE zoneId = $1", [zoneId]);
148
142
  if (result.rows.length > 0) {
149
- // Store in Redis as JSON string
150
- await this.redis.set(`zone:${zoneId}`, JSON.stringify(result.rows[0]));
151
143
  return result.rows[0];
152
144
  }
153
145
  // If data is not available, return null
@@ -160,16 +152,9 @@ class LocalDeviceService {
160
152
  }
161
153
  async getDevicesByAccessGroup(accessGroupId) {
162
154
  try {
163
- // Try to get from Redis
164
- let cached = await this.redis.get(`accessGroup:${accessGroupId}`);
165
- if (cached) {
166
- return typeof cached === "string" ? JSON.parse(cached) : cached;
167
- }
168
155
  // Fetch from Postgres if not in cache
169
- const result = await this.postgres.query("SELECT * FROM access_groups WHERE id = $1", [accessGroupId]);
156
+ const result = await this.postgres.query("SELECT * FROM dt_group WHERE id = $1", [accessGroupId]);
170
157
  if (result.rows.length > 0) {
171
- // Cache in Redis as JSON string
172
- await this.redis.set(`accessGroup:${accessGroupId}`, JSON.stringify(result.rows[0]));
173
158
  return result.rows[0];
174
159
  }
175
160
  return null;
@@ -181,18 +166,11 @@ class LocalDeviceService {
181
166
  }
182
167
  async getPropertyPreferences(propertyId) {
183
168
  try {
184
- const propertyPreferences = await this.redis.get(`propertyPreferences:${propertyId}`);
185
- if (!propertyPreferences) {
186
- const propertyPreferences = await this.postgres.query("SELECT * FROM property_preferences WHERE property_id = $1", [propertyId]);
187
- if (propertyPreferences.rows.length > 0) {
188
- await this.redis.set(`propertyPreferences:${propertyId}`, propertyPreferences.rows[0]);
189
- return propertyPreferences.rows[0];
190
- }
191
- return null;
192
- }
193
- else {
194
- return propertyPreferences;
169
+ const propertyPreferences = await this.postgres.query("SELECT * FROM dt_property_settings WHERE propertyId = $1", [propertyId]);
170
+ if (propertyPreferences.rows.length > 0) {
171
+ return propertyPreferences.rows[0];
195
172
  }
173
+ return null;
196
174
  }
197
175
  catch (error) {
198
176
  console.log(error);
@@ -1,3 +1,3 @@
1
1
  export { LocalDeviceService } from "./Device.service";
2
2
  export { HubService as LocalHubService } from "./Hub.service";
3
- export { ConnectionService } from "./Connection.service";
3
+ export { LocalConnectionService } from "./Connection.service";
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConnectionService = exports.LocalHubService = exports.LocalDeviceService = void 0;
3
+ exports.LocalConnectionService = exports.LocalHubService = exports.LocalDeviceService = void 0;
4
4
  var Device_service_1 = require("./Device.service");
5
5
  Object.defineProperty(exports, "LocalDeviceService", { enumerable: true, get: function () { return Device_service_1.LocalDeviceService; } });
6
6
  var Hub_service_1 = require("./Hub.service");
7
7
  Object.defineProperty(exports, "LocalHubService", { enumerable: true, get: function () { return Hub_service_1.HubService; } });
8
8
  var Connection_service_1 = require("./Connection.service");
9
- Object.defineProperty(exports, "ConnectionService", { enumerable: true, get: function () { return Connection_service_1.ConnectionService; } });
9
+ Object.defineProperty(exports, "LocalConnectionService", { enumerable: true, get: function () { return Connection_service_1.LocalConnectionService; } });
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { CloudDeviceService, ConnectionService as CloudConnectionService, } from "./device/cloud/services";
2
2
  export { CloudDevice, DeviceFactory } from "./device/cloud/entities";
3
- export { LocalDeviceService, LocalHubService, ConnectionService, } from "./device/local/services";
3
+ export { LocalDeviceService, LocalHubService, LocalConnectionService, } from "./device/local/services";
4
4
  export * from "./device/cloud/interfaces";
5
5
  export * from "./device/cloud/types";
6
6
  export * from "./device/local/interfaces";
package/dist/index.js CHANGED
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
16
  };
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.getConfig = exports.initialize = exports.ConnectionService = exports.LocalHubService = exports.LocalDeviceService = exports.DeviceFactory = exports.CloudDevice = exports.CloudConnectionService = exports.CloudDeviceService = void 0;
18
+ exports.getConfig = exports.initialize = exports.LocalConnectionService = exports.LocalHubService = exports.LocalDeviceService = exports.DeviceFactory = exports.CloudDevice = exports.CloudConnectionService = exports.CloudDeviceService = void 0;
19
19
  // Cloud exports
20
20
  var services_1 = require("./device/cloud/services");
21
21
  Object.defineProperty(exports, "CloudDeviceService", { enumerable: true, get: function () { return services_1.CloudDeviceService; } });
@@ -26,7 +26,7 @@ Object.defineProperty(exports, "DeviceFactory", { enumerable: true, get: functio
26
26
  var services_2 = require("./device/local/services");
27
27
  Object.defineProperty(exports, "LocalDeviceService", { enumerable: true, get: function () { return services_2.LocalDeviceService; } });
28
28
  Object.defineProperty(exports, "LocalHubService", { enumerable: true, get: function () { return services_2.LocalHubService; } });
29
- Object.defineProperty(exports, "ConnectionService", { enumerable: true, get: function () { return services_2.ConnectionService; } });
29
+ Object.defineProperty(exports, "LocalConnectionService", { enumerable: true, get: function () { return services_2.LocalConnectionService; } });
30
30
  __exportStar(require("./device/cloud/interfaces"), exports);
31
31
  __exportStar(require("./device/cloud/types"), exports);
32
32
  // Local exports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
@@ -40,7 +40,6 @@
40
40
  "dt-pub-sub": "^1.0.0",
41
41
  "ioredis": "5.6.1",
42
42
  "lodash": "^4.17.21",
43
- "pg": "8.16.3",
44
- "redis": "5.5.6"
43
+ "pg": "8.16.3"
45
44
  }
46
45
  }
@@ -1,6 +1,8 @@
1
1
  import { ICloudDeviceService } from "../interfaces/ICloudDeviceService";
2
2
  import { IConnection } from "../types";
3
3
 
4
- export abstract class CloudDeviceService implements ICloudDeviceService {
5
- abstract getConnection(deviceId: string): Promise<IConnection>;
4
+ export class CloudDeviceService implements ICloudDeviceService {
5
+ async getConnection(deviceId: string): Promise<IConnection> {
6
+ throw new Error("Method not implemented.");
7
+ }
6
8
  }
@@ -45,13 +45,13 @@ export interface IConnectionConnectParams {
45
45
  [key: string]: unknown;
46
46
  }
47
47
 
48
- export interface ConnectionProvider {
49
- DEVICETHREAD: "Devicethread";
50
- SMARTTHINGS: "Smartthings";
51
- SALTOKS: "SaltoKS";
52
- TUYA: "Tuya";
53
- TTLOCK: "TTLock";
54
- SCHLAGE: "Schlage";
55
- YALEWIFI: "YaleWifi";
56
- SENSIBO: "Sensibo";
57
- }
48
+ export enum ConnectionProvider {
49
+ Smartthings = "Smartthings",
50
+ SaltoKS = "SaltoKS",
51
+ TTLock = "TTLock",
52
+ Tuya = "Tuya",
53
+ Schlage = "Schlage",
54
+ YaleWifi = "YaleWifi",
55
+ Sensibo = "Sensibo",
56
+ Devicethread = "Devicethread",
57
+ }
@@ -1,11 +1,12 @@
1
1
  import { getPostgresClient } from "../../../db";
2
- export class ConnectionService {
2
+ import { IConnection } from "../interfaces/IConnection";
3
+ export class LocalConnectionService {
3
4
  private readonly pool;
4
5
  constructor() {
5
6
  this.pool = getPostgresClient();
6
7
  }
7
8
 
8
- async getConnection(connectionId: string) {
9
+ async getConnection(connectionId: string): Promise<IConnection> {
9
10
  const result = await this.pool.query(
10
11
  "SELECT * FROM dt_connections WHERE id = $1",
11
12
  [connectionId]
@@ -17,7 +17,7 @@ export class LocalDeviceService {
17
17
  private readonly source = "dt-common-device";
18
18
  private readonly eventHandler: EventHandler;
19
19
  private readonly alertService: AlertService;
20
- private readonly redis;
20
+ //private readonly redis;
21
21
  private readonly postgres;
22
22
  constructor() {
23
23
  const { DEVICE_SERVICE } = getConfig();
@@ -26,7 +26,7 @@ export class LocalDeviceService {
26
26
  "DEVICE_SERVICE is not configured. Call initialize() first with DEVICE_SERVICE."
27
27
  );
28
28
  }
29
- this.redis = getRedisClient();
29
+ // this.redis = getRedisClient();
30
30
  this.postgres = getPostgresClient();
31
31
  this.baseUrl = DEVICE_SERVICE;
32
32
  checkAwsEnv();
@@ -183,21 +183,12 @@ export class LocalDeviceService {
183
183
 
184
184
  async getDeviceByZone(zoneId: string) {
185
185
  try {
186
- // Step 1: Check if zone data is available in Redis
187
- let cached = await this.redis.get(`zone:${zoneId}`);
188
- if (cached) {
189
- // Parse if stored as JSON string
190
- return typeof cached === "string" ? JSON.parse(cached) : cached;
191
- }
192
-
193
186
  // If not available, fetch from PostgreSQL DB
194
187
  const result = await this.postgres.query(
195
188
  "SELECT * FROM dt_devices WHERE zoneId = $1",
196
189
  [zoneId]
197
190
  );
198
191
  if (result.rows.length > 0) {
199
- // Store in Redis as JSON string
200
- await this.redis.set(`zone:${zoneId}`, JSON.stringify(result.rows[0]));
201
192
  return result.rows[0];
202
193
  }
203
194
  // If data is not available, return null
@@ -210,22 +201,12 @@ export class LocalDeviceService {
210
201
 
211
202
  async getDevicesByAccessGroup(accessGroupId: string) {
212
203
  try {
213
- // Try to get from Redis
214
- let cached = await this.redis.get(`accessGroup:${accessGroupId}`);
215
- if (cached) {
216
- return typeof cached === "string" ? JSON.parse(cached) : cached;
217
- }
218
204
  // Fetch from Postgres if not in cache
219
205
  const result = await this.postgres.query(
220
- "SELECT * FROM access_groups WHERE id = $1",
206
+ "SELECT * FROM dt_group WHERE id = $1",
221
207
  [accessGroupId]
222
208
  );
223
209
  if (result.rows.length > 0) {
224
- // Cache in Redis as JSON string
225
- await this.redis.set(
226
- `accessGroup:${accessGroupId}`,
227
- JSON.stringify(result.rows[0])
228
- );
229
210
  return result.rows[0];
230
211
  }
231
212
  return null;
@@ -237,25 +218,14 @@ export class LocalDeviceService {
237
218
 
238
219
  async getPropertyPreferences(propertyId: string) {
239
220
  try {
240
- const propertyPreferences = await this.redis.get(
241
- `propertyPreferences:${propertyId}`
221
+ const propertyPreferences = await this.postgres.query(
222
+ "SELECT * FROM dt_property_settings WHERE propertyId = $1",
223
+ [propertyId]
242
224
  );
243
- if (!propertyPreferences) {
244
- const propertyPreferences = await this.postgres.query(
245
- "SELECT * FROM property_preferences WHERE property_id = $1",
246
- [propertyId]
247
- );
248
- if (propertyPreferences.rows.length > 0) {
249
- await this.redis.set(
250
- `propertyPreferences:${propertyId}`,
251
- propertyPreferences.rows[0]
252
- );
253
- return propertyPreferences.rows[0];
254
- }
255
- return null;
256
- } else {
257
- return propertyPreferences;
225
+ if (propertyPreferences.rows.length > 0) {
226
+ return propertyPreferences.rows[0];
258
227
  }
228
+ return null;
259
229
  } catch (error) {
260
230
  console.log(error);
261
231
  throw new Error("Failed to get property preferences");
@@ -1,3 +1,3 @@
1
1
  export { LocalDeviceService } from "./Device.service";
2
2
  export { HubService as LocalHubService } from "./Hub.service";
3
- export { ConnectionService } from "./Connection.service";
3
+ export { LocalConnectionService } from "./Connection.service";
package/src/index.ts CHANGED
@@ -9,7 +9,7 @@ export { CloudDevice, DeviceFactory } from "./device/cloud/entities";
9
9
  export {
10
10
  LocalDeviceService,
11
11
  LocalHubService,
12
- ConnectionService,
12
+ LocalConnectionService,
13
13
  } from "./device/local/services";
14
14
 
15
15
  export * from "./device/cloud/interfaces";