dt-common-device 1.0.20 → 1.2.1

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 (76) hide show
  1. package/dist/device/cloud/entities/CloudConnection.d.ts +6 -0
  2. package/dist/device/cloud/entities/CloudConnection.js +6 -0
  3. package/dist/device/cloud/entities/CloudDevice.js +0 -19
  4. package/dist/device/cloud/entities/CloudDeviceService.d.ts +5 -0
  5. package/dist/device/cloud/entities/CloudDeviceService.js +9 -0
  6. package/dist/device/cloud/entities/DeviceFactory.d.ts +2 -1
  7. package/dist/device/cloud/entities/index.d.ts +2 -0
  8. package/dist/device/cloud/entities/index.js +2 -0
  9. package/dist/device/cloud/interfaces/ICloudConnection.d.ts +5 -0
  10. package/dist/device/cloud/interfaces/ICloudConnection.js +2 -0
  11. package/dist/device/cloud/interfaces/IDeviceFactory.d.ts +4 -0
  12. package/dist/device/cloud/interfaces/IDeviceFactory.js +2 -0
  13. package/dist/device/cloud/interfaces/index.d.ts +1 -3
  14. package/dist/device/cloud/interfaces/index.js +1 -3
  15. package/dist/device/cloud/types.d.ts +1 -1
  16. package/dist/device/local/events/EventHandler.d.ts +10 -0
  17. package/dist/device/local/events/EventHandler.js +75 -0
  18. package/dist/device/local/events/Events.d.ts +21 -0
  19. package/dist/device/local/events/Events.js +24 -0
  20. package/dist/device/local/interfaces/IDtDevice.d.ts +16 -0
  21. package/dist/device/local/interfaces/IDtDevice.js +2 -0
  22. package/dist/device/local/interfaces/index.d.ts +0 -1
  23. package/dist/device/local/interfaces/index.js +0 -1
  24. package/dist/device/local/repository/Connection.repository.d.ts +7 -0
  25. package/dist/device/local/repository/Connection.repository.js +77 -0
  26. package/dist/device/local/repository/Device.repository.d.ts +16 -0
  27. package/dist/device/local/repository/Device.repository.js +134 -0
  28. package/dist/device/local/repository/Hub.repository.d.ts +13 -0
  29. package/dist/device/local/repository/Hub.repository.js +97 -0
  30. package/dist/device/local/repository/Property.repository.d.ts +9 -0
  31. package/dist/device/local/repository/Property.repository.js +81 -0
  32. package/dist/device/local/services/Connection.service.d.ts +3 -2
  33. package/dist/device/local/services/Connection.service.js +7 -4
  34. package/dist/device/local/services/Device.service.d.ts +7 -9
  35. package/dist/device/local/services/Device.service.js +17 -91
  36. package/dist/device/local/services/Hub.service.d.ts +7 -7
  37. package/dist/device/local/services/Hub.service.js +13 -21
  38. package/dist/device/local/services/Property.service.d.ts +9 -0
  39. package/dist/device/local/services/Property.service.js +13 -0
  40. package/dist/device/local/services/index.d.ts +2 -1
  41. package/dist/device/local/services/index.js +4 -2
  42. package/dist/index.d.ts +2 -3
  43. package/dist/index.js +8 -8
  44. package/package.json +4 -3
  45. package/src/device/cloud/entities/CloudConnection.ts +13 -0
  46. package/src/device/cloud/entities/CloudDevice.ts +1 -21
  47. package/src/device/cloud/entities/DeviceFactory.ts +2 -1
  48. package/src/device/cloud/entities/index.ts +2 -0
  49. package/src/device/cloud/interfaces/ICloudConnection.ts +6 -0
  50. package/src/device/cloud/interfaces/ICloudDevice.ts +0 -1
  51. package/src/device/cloud/interfaces/IDeviceFactory.ts +5 -0
  52. package/src/device/cloud/interfaces/index.ts +1 -3
  53. package/src/device/cloud/types.ts +1 -1
  54. package/src/device/local/events/EventHandler.ts +101 -0
  55. package/src/device/local/events/Events.ts +23 -0
  56. package/src/device/local/interfaces/IDtDevice.ts +16 -0
  57. package/src/device/local/interfaces/index.ts +0 -1
  58. package/src/device/local/repository/Connection.repository.ts +32 -0
  59. package/src/device/local/repository/Device.repository.ts +106 -0
  60. package/src/device/local/repository/Hub.repository.ts +51 -0
  61. package/src/device/local/repository/Property.repository.ts +32 -0
  62. package/src/device/local/services/Connection.service.ts +11 -9
  63. package/src/device/local/services/Device.service.ts +21 -109
  64. package/src/device/local/services/Hub.service.ts +17 -28
  65. package/src/device/local/services/Property.service.ts +12 -0
  66. package/src/device/local/services/index.ts +2 -1
  67. package/src/index.ts +5 -3
  68. package/src/device/cloud/interfaces/IConnectionService.ts +0 -15
  69. package/src/device/cloud/interfaces/IDeviceService.ts +0 -12
  70. package/src/device/cloud/interfaces/IHubService.ts +0 -5
  71. package/src/device/cloud/services/Connection.service.ts +0 -19
  72. package/src/device/cloud/services/index.ts +0 -2
  73. package/src/device/local/handler/EventHandler.ts +0 -52
  74. package/src/device/local/interfaces/IConnection.ts +0 -17
  75. package/src/device/local/interfaces/IHub.ts +0 -46
  76. /package/src/device/cloud/{services/CloudDevice.service.ts → entities/CloudDeviceService.ts} +0 -0
@@ -0,0 +1,9 @@
1
+ export declare class PropertyRepository {
2
+ private readonly postgres;
3
+ constructor();
4
+ getPropertyPreferences(propertyId: string): Promise<{
5
+ id: string;
6
+ propertyId: string;
7
+ settings: string;
8
+ } | null>;
9
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
36
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
37
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
38
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
39
+ };
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.PropertyRepository = void 0;
42
+ const db_1 = require("../../../db");
43
+ const typedi_1 = require("typedi");
44
+ let PropertyRepository = (() => {
45
+ let _classDecorators = [(0, typedi_1.Service)()];
46
+ let _classDescriptor;
47
+ let _classExtraInitializers = [];
48
+ let _classThis;
49
+ var PropertyRepository = _classThis = class {
50
+ constructor() {
51
+ this.postgres = (0, db_1.getPostgresClient)();
52
+ }
53
+ async getPropertyPreferences(propertyId) {
54
+ try {
55
+ const propertyPreferences = await this.postgres.query("SELECT * FROM dt_property_settings WHERE propertyId = $1", [propertyId]);
56
+ if (propertyPreferences.rows.length > 0) {
57
+ return {
58
+ id: propertyPreferences.rows[0].id,
59
+ propertyId: propertyPreferences.rows[0].propertyId,
60
+ settings: JSON.parse(propertyPreferences.rows[0].settings),
61
+ };
62
+ }
63
+ return null;
64
+ }
65
+ catch (error) {
66
+ console.log(error);
67
+ throw new Error("Failed to get property preferences");
68
+ }
69
+ }
70
+ };
71
+ __setFunctionName(_classThis, "PropertyRepository");
72
+ (() => {
73
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
74
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
75
+ PropertyRepository = _classThis = _classDescriptor.value;
76
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
77
+ __runInitializers(_classThis, _classExtraInitializers);
78
+ })();
79
+ return PropertyRepository = _classThis;
80
+ })();
81
+ exports.PropertyRepository = PropertyRepository;
@@ -1,6 +1,7 @@
1
- import { IConnection } from "../interfaces/IConnection";
1
+ import { IConnection } from "../../cloud/types";
2
2
  export declare class LocalConnectionService {
3
- private readonly pool;
3
+ private readonly connectionRepository;
4
4
  constructor();
5
5
  getConnection(connectionId: string): Promise<IConnection>;
6
+ updateConnection(connectionId: string, data: any): Promise<any>;
6
7
  }
@@ -1,14 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LocalConnectionService = void 0;
4
- const db_1 = require("../../../db");
4
+ const typedi_1 = require("typedi");
5
+ const Connection_repository_1 = require("../repository/Connection.repository");
5
6
  class LocalConnectionService {
6
7
  constructor() {
7
- this.pool = (0, db_1.getPostgresClient)();
8
+ this.connectionRepository = typedi_1.Container.get(Connection_repository_1.ConnectionRepository);
8
9
  }
9
10
  async getConnection(connectionId) {
10
- const result = await this.pool.query("SELECT * FROM dt_connections WHERE id = $1", [connectionId]);
11
- return result.rows[0];
11
+ return await this.connectionRepository.getConnectionById(connectionId);
12
+ }
13
+ async updateConnection(connectionId, data) {
14
+ return await this.connectionRepository.updateConnection(connectionId, data);
12
15
  }
13
16
  }
14
17
  exports.LocalConnectionService = LocalConnectionService;
@@ -1,10 +1,9 @@
1
1
  import { IDevice } from "../interfaces";
2
2
  export declare class LocalDeviceService {
3
- private readonly baseUrl;
4
3
  private readonly source;
5
4
  private readonly eventHandler;
6
5
  private readonly alertService;
7
- private readonly postgres;
6
+ private readonly deviceRepository;
8
7
  constructor();
9
8
  createDevice(body: IDevice): Promise<void>;
10
9
  getDevice(deviceId: string, withHubDetails?: boolean): Promise<IDevice>;
@@ -12,15 +11,14 @@ export declare class LocalDeviceService {
12
11
  getPropertyDevices(propertyId: string, withHubDetails?: boolean): Promise<IDevice[]>;
13
12
  updateDevice(deviceId: string, body: any): Promise<any>;
14
13
  deleteDevice(deviceId: string): Promise<any>;
15
- getState(deviceId: string): Promise<import("axios").AxiosResponse<any, any>>;
14
+ getState(deviceId: string): Promise<any>;
16
15
  setState(deviceId: string, newState: any): Promise<void>;
17
- getStatus(deviceId: string): Promise<import("axios").AxiosResponse<any, any>>;
16
+ getStatus(deviceId: string): Promise<Record<string, any>>;
18
17
  setStatus(deviceId: string, newStatus: any): Promise<void>;
19
- getBatteryLevel(deviceId: string): Promise<import("axios").AxiosResponse<any, any>>;
18
+ getBatteryLevel(deviceId: string): Promise<Record<string, any>>;
20
19
  setBatteryLevel(deviceId: string, newBatteryLevel: any): Promise<void>;
21
- getMetaData(deviceId: string): Promise<import("axios").AxiosResponse<any, any>>;
20
+ getMetaData(deviceId: string): Promise<any>;
22
21
  setMetaData(deviceId: string, metaData: Record<string, any>): Promise<void>;
23
- getDeviceByZone(zoneId: string): Promise<any>;
24
- getDevicesByAccessGroup(accessGroupId: string): Promise<any>;
25
- getPropertyPreferences(propertyId: string): Promise<any>;
22
+ getDevicesByZone(zoneId: string): Promise<import("../interfaces/IDtDevice").IDtDevice[]>;
23
+ getDevicesByAccessGroup(accessGroupId: string): Promise<import("../interfaces/IDtDevice").IDtDevice[]>;
26
24
  }
@@ -4,82 +4,44 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.LocalDeviceService = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
7
  const config_1 = require("../../../config/config");
9
8
  const dt_pub_sub_1 = require("dt-pub-sub");
10
9
  const dt_audit_library_1 = require("dt-audit-library");
11
- const EventHandler_1 = require("../handler/EventHandler");
10
+ const EventHandler_1 = require("../events/EventHandler");
12
11
  const lodash_1 = require("lodash");
13
12
  const Alert_service_1 = require("./Alert.service");
14
- const db_1 = require("../../../db");
13
+ const Device_repository_1 = require("../repository/Device.repository");
14
+ const typedi_1 = __importDefault(require("typedi"));
15
15
  class LocalDeviceService {
16
16
  constructor() {
17
17
  this.source = "dt-common-device";
18
- const { DEVICE_SERVICE } = (0, config_1.getConfig)();
19
- if (!DEVICE_SERVICE) {
20
- throw new Error("DEVICE_SERVICE is not configured. Call initialize() first with DEVICE_SERVICE.");
21
- }
22
18
  // this.redis = getRedisClient();
23
- this.postgres = (0, db_1.getPostgresClient)();
24
- this.baseUrl = DEVICE_SERVICE;
25
19
  (0, config_1.checkAwsEnv)();
26
20
  (0, config_1.ensureAuditInitialized)();
27
21
  this.eventHandler = new EventHandler_1.EventHandler();
28
22
  this.alertService = new Alert_service_1.AlertService();
23
+ this.deviceRepository = typedi_1.default.get(Device_repository_1.DeviceRepository);
29
24
  }
30
25
  async createDevice(body) {
31
- await dt_pub_sub_1.eventDispatcher.publishEvent("device.created", body, this.source);
32
- const payload = {
33
- eventType: "device.created",
34
- properties: {
35
- ...body,
36
- },
37
- };
38
- await (0, dt_audit_library_1.publishAudit)(payload);
26
+ return await this.eventHandler.onDeviceCreate(body);
39
27
  }
40
28
  async getDevice(deviceId, withHubDetails = false) {
41
- try {
42
- const response = await axios_1.default.get(`${this.baseUrl}/devices/${deviceId}?withHubDetails=${withHubDetails} `);
43
- return response.data;
44
- }
45
- catch (error) {
46
- console.log(error);
47
- throw new Error(`Failed to get device: ${error.message}`);
48
- }
29
+ return await this.deviceRepository.getDevice(deviceId, withHubDetails);
49
30
  }
50
31
  async getDevices(deviceIds, withHubDetails = false) {
51
- return await axios_1.default.get(`${this.baseUrl}/devices`, {
52
- params: { deviceIds, withHubDetails },
53
- });
32
+ return await this.deviceRepository.getDevices(deviceIds, withHubDetails);
54
33
  }
55
34
  async getPropertyDevices(propertyId, withHubDetails = false) {
56
- return await axios_1.default.get(`${this.baseUrl}/devices`, {
57
- params: { propertyId, withHubDetails },
58
- });
35
+ return await this.deviceRepository.getPropertyDevices(propertyId, withHubDetails);
59
36
  }
60
37
  async updateDevice(deviceId, body) {
61
- //return await axios.put(`${this.baseUrl}/devices/${deviceId}`, body);
62
- await dt_pub_sub_1.eventDispatcher.publishEvent("device.updated", { deviceId, body }, this.source);
63
- const payload = {
64
- eventType: "device.updated",
65
- properties: {
66
- ...body,
67
- },
68
- };
69
- await (0, dt_audit_library_1.publishAudit)(payload);
38
+ return await this.eventHandler.onDeviceUpdate(deviceId, body);
70
39
  }
71
40
  async deleteDevice(deviceId) {
72
- await dt_pub_sub_1.eventDispatcher.publishEvent("device.deleted", { deviceId }, this.source);
73
- const payload = {
74
- eventType: "device.deleted",
75
- properties: {
76
- deviceId,
77
- },
78
- };
79
- await (0, dt_audit_library_1.publishAudit)(payload);
41
+ return await this.eventHandler.onDeviceDelete(deviceId);
80
42
  }
81
43
  async getState(deviceId) {
82
- return await axios_1.default.get(`${this.baseUrl}/devices/${deviceId}/state`);
44
+ return await this.deviceRepository.getState(deviceId);
83
45
  }
84
46
  async setState(deviceId, newState) {
85
47
  // If old state and new state are different
@@ -90,7 +52,7 @@ class LocalDeviceService {
90
52
  }
91
53
  }
92
54
  async getStatus(deviceId) {
93
- return await axios_1.default.get(`${this.baseUrl}/devices/${deviceId}/status`);
55
+ return await this.deviceRepository.getStatus(deviceId);
94
56
  }
95
57
  async setStatus(deviceId, newStatus) {
96
58
  // If old status and new status are different
@@ -113,7 +75,7 @@ class LocalDeviceService {
113
75
  }
114
76
  }
115
77
  async getBatteryLevel(deviceId) {
116
- return await axios_1.default.get(`${this.baseUrl}/devices/${deviceId}/battery-level`);
78
+ return await this.deviceRepository.getBatteryLevel(deviceId);
117
79
  }
118
80
  async setBatteryLevel(deviceId, newBatteryLevel) {
119
81
  // If old battery level and new battery level are different
@@ -132,7 +94,7 @@ class LocalDeviceService {
132
94
  }
133
95
  }
134
96
  async getMetaData(deviceId) {
135
- return await axios_1.default.get(`${this.baseUrl}/devices/${deviceId}/metaData`);
97
+ return await this.deviceRepository.getMetaData(deviceId);
136
98
  }
137
99
  async setMetaData(deviceId, metaData) {
138
100
  await dt_pub_sub_1.eventDispatcher.publishEvent("device.metaData.set", { deviceId, metaData }, this.source);
@@ -145,47 +107,11 @@ class LocalDeviceService {
145
107
  };
146
108
  await (0, dt_audit_library_1.publishAudit)(payload);
147
109
  }
148
- async getDeviceByZone(zoneId) {
149
- try {
150
- // If not available, fetch from PostgreSQL DB
151
- const result = await this.postgres.query("SELECT * FROM dt_devices WHERE zoneId = $1", [zoneId]);
152
- if (result.rows.length > 0) {
153
- return result.rows[0];
154
- }
155
- // If data is not available, return null
156
- return null;
157
- }
158
- catch (error) {
159
- console.log(error);
160
- throw new Error("Failed to get device by zone");
161
- }
110
+ async getDevicesByZone(zoneId) {
111
+ return await this.deviceRepository.getDevicesByZone(zoneId);
162
112
  }
163
113
  async getDevicesByAccessGroup(accessGroupId) {
164
- try {
165
- // Fetch from Postgres if not in cache
166
- const result = await this.postgres.query("SELECT * FROM dt_group WHERE id = $1", [accessGroupId]);
167
- if (result.rows.length > 0) {
168
- return result.rows[0];
169
- }
170
- return null;
171
- }
172
- catch (error) {
173
- console.log(error);
174
- throw new Error("Failed to get devices by access group");
175
- }
176
- }
177
- async getPropertyPreferences(propertyId) {
178
- try {
179
- const propertyPreferences = await this.postgres.query("SELECT * FROM dt_property_settings WHERE propertyId = $1", [propertyId]);
180
- if (propertyPreferences.rows.length > 0) {
181
- return propertyPreferences.rows[0];
182
- }
183
- return null;
184
- }
185
- catch (error) {
186
- console.log(error);
187
- throw new Error("Failed to get property preferences");
188
- }
114
+ return await this.deviceRepository.getDevicesByAccessGroup(accessGroupId);
189
115
  }
190
116
  }
191
117
  exports.LocalDeviceService = LocalDeviceService;
@@ -1,11 +1,11 @@
1
- import { IHub } from "../interfaces";
2
- export declare class HubService {
3
- private readonly baseUrl;
1
+ import { IDevice } from "../interfaces";
2
+ export declare class LocalHubService {
3
+ private readonly hubRepository;
4
4
  constructor();
5
- addHub(body: IHub): Promise<any>;
6
- getHubs(hubIds: string[]): Promise<IHub[]>;
7
- getHub(hubId: string): Promise<IHub>;
8
- updateHub(hubId: string, body: any): Promise<any>;
5
+ addHub(body: IDevice): Promise<IDevice>;
6
+ getHubs(hubIds: string[]): Promise<IDevice[]>;
7
+ getHub(hubId: string): Promise<IDevice>;
8
+ updateHub(hubId: string, body: Partial<IDevice>): Promise<IDevice>;
9
9
  getStatus(hubId: string): Promise<any>;
10
10
  deleteHub(hubId: string): Promise<any>;
11
11
  deleteAllHubs(hubIds: string[]): Promise<any>;
@@ -3,41 +3,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.HubService = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- const config_1 = require("../../../config/config");
9
- class HubService {
6
+ exports.LocalHubService = void 0;
7
+ const Hub_repository_1 = require("../repository/Hub.repository");
8
+ const typedi_1 = __importDefault(require("typedi"));
9
+ class LocalHubService {
10
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;
11
+ this.hubRepository = typedi_1.default.get(Hub_repository_1.HubRepository);
16
12
  }
17
13
  async addHub(body) {
18
- return await axios_1.default.post(`${this.baseUrl}/devices/hubs`, body);
14
+ return await this.hubRepository.addHub(body);
19
15
  }
20
- //get hubs takes an array of hub ids as query params
21
16
  async getHubs(hubIds) {
22
- const query = hubIds && hubIds.length ? `?ids=${hubIds.join(",")}` : "";
23
- return await axios_1.default.get(`${this.baseUrl}/devices/hubs${query}`);
17
+ return await this.hubRepository.getHubs(hubIds);
24
18
  }
25
- //get hub takes a hub id in params
26
19
  async getHub(hubId) {
27
- return await axios_1.default.get(`${this.baseUrl}/devices/hubs/${hubId}`);
20
+ return await this.hubRepository.getHub(hubId);
28
21
  }
29
22
  async updateHub(hubId, body) {
30
- return await axios_1.default.put(`${this.baseUrl}/devices/hubs/${hubId}`, body);
23
+ return await this.hubRepository.updateHub(hubId, body);
31
24
  }
32
25
  async getStatus(hubId) {
33
- return await axios_1.default.get(`${this.baseUrl}/devices/hubs/${hubId}/status`);
26
+ return await this.hubRepository.getStatus(hubId);
34
27
  }
35
28
  async deleteHub(hubId) {
36
- return await axios_1.default.delete(`${this.baseUrl}/devices/hubs/${hubId}`);
29
+ return await this.hubRepository.deleteHub(hubId);
37
30
  }
38
31
  async deleteAllHubs(hubIds) {
39
- const query = hubIds.length ? `?ids=${hubIds.join(",")}` : "";
40
- return await axios_1.default.delete(`${this.baseUrl}/devices/hubs${query}`);
32
+ return await this.hubRepository.deleteAllHubs(hubIds);
41
33
  }
42
34
  }
43
- exports.HubService = HubService;
35
+ exports.LocalHubService = LocalHubService;
@@ -0,0 +1,9 @@
1
+ export declare class LocalPropertyService {
2
+ private readonly propertyRepository;
3
+ constructor();
4
+ getPropertyPreferences(propertyId: string): Promise<{
5
+ id: string;
6
+ propertyId: string;
7
+ settings: string;
8
+ } | null>;
9
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocalPropertyService = void 0;
4
+ const Property_repository_1 = require("../repository/Property.repository");
5
+ class LocalPropertyService {
6
+ constructor() {
7
+ this.propertyRepository = new Property_repository_1.PropertyRepository();
8
+ }
9
+ async getPropertyPreferences(propertyId) {
10
+ return await this.propertyRepository.getPropertyPreferences(propertyId);
11
+ }
12
+ }
13
+ exports.LocalPropertyService = LocalPropertyService;
@@ -1,3 +1,4 @@
1
1
  export { LocalDeviceService } from "./Device.service";
2
- export { HubService as LocalHubService } from "./Hub.service";
2
+ export { LocalHubService } from "./Hub.service";
3
3
  export { LocalConnectionService } from "./Connection.service";
4
+ export { LocalPropertyService } from "./Property.service";
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LocalConnectionService = exports.LocalHubService = exports.LocalDeviceService = void 0;
3
+ exports.LocalPropertyService = 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
- Object.defineProperty(exports, "LocalHubService", { enumerable: true, get: function () { return Hub_service_1.HubService; } });
7
+ Object.defineProperty(exports, "LocalHubService", { enumerable: true, get: function () { return Hub_service_1.LocalHubService; } });
8
8
  var Connection_service_1 = require("./Connection.service");
9
9
  Object.defineProperty(exports, "LocalConnectionService", { enumerable: true, get: function () { return Connection_service_1.LocalConnectionService; } });
10
+ var Property_service_1 = require("./Property.service");
11
+ Object.defineProperty(exports, "LocalPropertyService", { enumerable: true, get: function () { return Property_service_1.LocalPropertyService; } });
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- export { CloudDeviceService, ConnectionService as CloudConnectionService, } from "./device/cloud/services";
2
- export { CloudDevice, DeviceFactory } from "./device/cloud/entities";
3
- export { LocalDeviceService, LocalHubService, LocalConnectionService, } from "./device/local/services";
1
+ export { CloudDevice, DeviceFactory, CloudConnection, CloudDeviceService, } from "./device/cloud/entities";
2
+ export { LocalDeviceService, LocalHubService, LocalConnectionService, LocalPropertyService, } from "./device/local/services";
4
3
  export * from "./device/cloud/interfaces";
5
4
  export * from "./device/cloud/types";
6
5
  export * from "./device/local/interfaces";
package/dist/index.js CHANGED
@@ -15,18 +15,18 @@ 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.LocalConnectionService = exports.LocalHubService = exports.LocalDeviceService = exports.DeviceFactory = exports.CloudDevice = exports.CloudConnectionService = exports.CloudDeviceService = void 0;
18
+ exports.getConfig = exports.initialize = exports.LocalPropertyService = exports.LocalConnectionService = exports.LocalHubService = exports.LocalDeviceService = exports.CloudDeviceService = exports.CloudConnection = exports.DeviceFactory = exports.CloudDevice = void 0;
19
19
  // Cloud exports
20
- var services_1 = require("./device/cloud/services");
21
- Object.defineProperty(exports, "CloudDeviceService", { enumerable: true, get: function () { return services_1.CloudDeviceService; } });
22
- Object.defineProperty(exports, "CloudConnectionService", { enumerable: true, get: function () { return services_1.ConnectionService; } });
23
20
  var entities_1 = require("./device/cloud/entities");
24
21
  Object.defineProperty(exports, "CloudDevice", { enumerable: true, get: function () { return entities_1.CloudDevice; } });
25
22
  Object.defineProperty(exports, "DeviceFactory", { enumerable: true, get: function () { return entities_1.DeviceFactory; } });
26
- var services_2 = require("./device/local/services");
27
- Object.defineProperty(exports, "LocalDeviceService", { enumerable: true, get: function () { return services_2.LocalDeviceService; } });
28
- Object.defineProperty(exports, "LocalHubService", { enumerable: true, get: function () { return services_2.LocalHubService; } });
29
- Object.defineProperty(exports, "LocalConnectionService", { enumerable: true, get: function () { return services_2.LocalConnectionService; } });
23
+ Object.defineProperty(exports, "CloudConnection", { enumerable: true, get: function () { return entities_1.CloudConnection; } });
24
+ Object.defineProperty(exports, "CloudDeviceService", { enumerable: true, get: function () { return entities_1.CloudDeviceService; } });
25
+ var services_1 = require("./device/local/services");
26
+ Object.defineProperty(exports, "LocalDeviceService", { enumerable: true, get: function () { return services_1.LocalDeviceService; } });
27
+ Object.defineProperty(exports, "LocalHubService", { enumerable: true, get: function () { return services_1.LocalHubService; } });
28
+ Object.defineProperty(exports, "LocalConnectionService", { enumerable: true, get: function () { return services_1.LocalConnectionService; } });
29
+ Object.defineProperty(exports, "LocalPropertyService", { enumerable: true, get: function () { return services_1.LocalPropertyService; } });
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,10 +1,10 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "1.0.20",
3
+ "version": "1.2.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
7
- "build": "tsc ",
7
+ "build": "tsc",
8
8
  "patch": "npm version patch && npm run build",
9
9
  "minor": "npm version minor && npm run build",
10
10
  "major": "npm version major && npm run build",
@@ -43,6 +43,7 @@
43
43
  "dt-pub-sub": "^1.0.0",
44
44
  "ioredis": "5.6.1",
45
45
  "lodash": "^4.17.21",
46
- "pg": "8.16.3"
46
+ "pg": "8.16.3",
47
+ "typedi": "0.10.0"
47
48
  }
48
49
  }
@@ -0,0 +1,13 @@
1
+ // Device Cloud Service - Class Implementation
2
+ import { ICloudConnection } from "../interfaces";
3
+ import { IDeviceAccountResponse, IConnection } from "../types";
4
+
5
+ export abstract class CloudConnection implements ICloudConnection {
6
+ abstract createConnection(
7
+ data: IConnection,
8
+ userId: string
9
+ ): Promise<IConnection>;
10
+ abstract getDeviceAccount(
11
+ connection: IConnection
12
+ ): Promise<IDeviceAccountResponse>;
13
+ }
@@ -33,24 +33,4 @@ export abstract class CloudDevice implements ICloudDevice {
33
33
  async getStatus(connectionId: string, deviceId: string): Promise<string> {
34
34
  throw new Error("Method not implemented in Super Class.");
35
35
  }
36
- }
37
-
38
- /*
39
- Usage Example:
40
-
41
- // When extending CloudDevice, you can now do:
42
- class MyCloudDevice extends CloudDevice {
43
- constructor(device: IDevice, cloudDeviceService: ICloudDeviceService) {
44
- super(device, cloudDeviceService);
45
- // Additional initialization if needed
46
- }
47
- }
48
-
49
- // Create and initialize in one step:
50
- const device = await MyCloudDevice.create(device, cloudDeviceService);
51
- // The device is now fully initialized with connection and localDevice loaded
52
-
53
- // Or if you need to create without auto-initialization:
54
- const device = new MyCloudDevice(device, cloudDeviceService);
55
- await device.initialize(); // Manual initialization
56
- */
36
+ }
@@ -1,7 +1,8 @@
1
1
  import { IDevice } from "../../local/interfaces";
2
2
  import { LocalDeviceService } from "../../local/services/Device.service";
3
+ import { IDeviceFactory } from "../interfaces/IDeviceFactory";
3
4
 
4
- export class DeviceFactory {
5
+ export class DeviceFactory implements IDeviceFactory {
5
6
  private readonly localDeviceService: LocalDeviceService;
6
7
 
7
8
  constructor() {
@@ -1,2 +1,4 @@
1
1
  export * from "./CloudDevice";
2
2
  export * from "./DeviceFactory";
3
+ export * from "./CloudConnection";
4
+ export * from "./CloudDeviceService";
@@ -0,0 +1,6 @@
1
+ import { IConnection, IDeviceAccountResponse } from "../types";
2
+
3
+ export interface ICloudConnection {
4
+ createConnection(data: IConnection, userId: string): Promise<IConnection>;
5
+ getDeviceAccount(connection: IConnection): Promise<IDeviceAccountResponse>;
6
+ }
@@ -4,7 +4,6 @@ import { ICloudDeviceService } from "./ICloudDeviceService";
4
4
  export interface ICloudDevice {
5
5
  deviceId: string;
6
6
  cloudDeviceService: ICloudDeviceService;
7
-
8
7
  getDevice(
9
8
  connectionId: string,
10
9
  deviceId: string
@@ -0,0 +1,5 @@
1
+ import { IDevice } from "../../local/interfaces";
2
+
3
+ export interface IDeviceFactory {
4
+ getDevice(deviceId: string): Promise<IDevice>;
5
+ }
@@ -1,5 +1,3 @@
1
- export * from "./IConnectionService";
2
- export * from "./IDeviceService";
3
- export * from "./IHubService";
1
+ export * from "./ICloudConnection";
4
2
  export * from "./ICloudDevice";
5
3
  export * from "./ICloudDeviceService";
@@ -15,7 +15,7 @@ export interface IConnection {
15
15
  connectionProvider: ConnectionProvider;
16
16
  accessToken?: string;
17
17
  clientId?: string;
18
- clientSecret?: string;
18
+ clientSecret: string;
19
19
  isActive?: boolean;
20
20
  metaData?: any;
21
21
  }