dt-common-device 8.0.0 → 8.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.
@@ -4,9 +4,11 @@ export declare function initialize(cfg: IConfig): Promise<void>;
4
4
  export declare function getConfig(): IConfig;
5
5
  export declare function getDeviceServiceUrl(): string;
6
6
  export declare function getAdminServiceUrl(): string;
7
- export declare function getDeviceProfileServiceUrl(): string;
7
+ export declare function getMonitoringServiceUrl(): string;
8
8
  export declare function getSqsQueueUrl(): string;
9
9
  export declare function getReservationSqsQueueUrl(): string;
10
+ export declare function getHeartbeatSqsQueueUrl(): string;
11
+ export declare function getIssueSqsQueueUrl(): string;
10
12
  export declare function getEventSubscription(): InternalEventSubscription | null;
11
13
  export declare function checkRequiredEnv(requiredEnvs: string[]): void;
12
14
  export declare function ensureAuditInitialized(): void;
@@ -7,9 +7,11 @@ exports.initialize = initialize;
7
7
  exports.getConfig = getConfig;
8
8
  exports.getDeviceServiceUrl = getDeviceServiceUrl;
9
9
  exports.getAdminServiceUrl = getAdminServiceUrl;
10
- exports.getDeviceProfileServiceUrl = getDeviceProfileServiceUrl;
10
+ exports.getMonitoringServiceUrl = getMonitoringServiceUrl;
11
11
  exports.getSqsQueueUrl = getSqsQueueUrl;
12
12
  exports.getReservationSqsQueueUrl = getReservationSqsQueueUrl;
13
+ exports.getHeartbeatSqsQueueUrl = getHeartbeatSqsQueueUrl;
14
+ exports.getIssueSqsQueueUrl = getIssueSqsQueueUrl;
13
15
  exports.getEventSubscription = getEventSubscription;
14
16
  exports.checkRequiredEnv = checkRequiredEnv;
15
17
  exports.ensureAuditInitialized = ensureAuditInitialized;
@@ -140,16 +142,13 @@ function getAdminServiceUrl() {
140
142
  }
141
143
  throw new Error("dt-common-device: ADMIN_SERVICE is not configured for this service");
142
144
  }
143
- function getDeviceProfileServiceUrl() {
144
- if (constants_1.CONFIG_KEYS[sourceKey].env.includes("MONITORING_SERVICE_PYTHON")) {
145
- const deviceProfileServiceUrl = process.env.MONITORING_SERVICE_PYTHON;
146
- if (!deviceProfileServiceUrl) {
147
- getConfig().LOGGER.error("MONITORING_SERVICE_PYTHON must be set in environment variables");
148
- throw new Error("dt-common-device: MONITORING_SERVICE_PYTHON must be set in environment variables");
149
- }
150
- return deviceProfileServiceUrl;
145
+ function getMonitoringServiceUrl() {
146
+ const monitoringServiceUrl = process.env.MONITORING_SERVICE_PYTHON;
147
+ if (!monitoringServiceUrl) {
148
+ getConfig().LOGGER.error("MONITORING_SERVICE_PYTHON must be set in environment variables");
149
+ throw new Error("dt-common-device: MONITORING_SERVICE_PYTHON must be set in environment variables");
151
150
  }
152
- throw new Error("dt-common-device: DEVICE_PROFILE_SERVICE is not configured for this service");
151
+ return monitoringServiceUrl;
153
152
  }
154
153
  function getSqsQueueUrl() {
155
154
  if (constants_1.CONFIG_KEYS[sourceKey].env.includes("AWS_SQS_URL")) {
@@ -173,6 +172,28 @@ function getReservationSqsQueueUrl() {
173
172
  }
174
173
  return "";
175
174
  }
175
+ function getHeartbeatSqsQueueUrl() {
176
+ if (constants_1.CONFIG_KEYS[sourceKey].env.includes("HEARTBEAT_SQS_URL")) {
177
+ const heartbeatSqsQueueUrl = process.env.HEARTBEAT_SQS_URL;
178
+ if (!heartbeatSqsQueueUrl) {
179
+ getConfig().LOGGER.error("HEARTBEAT_SQS_URL must be set in environment variables");
180
+ throw new Error("dt-common-device: HEARTBEAT_SQS_URL must be set in environment variables");
181
+ }
182
+ return heartbeatSqsQueueUrl;
183
+ }
184
+ return "";
185
+ }
186
+ function getIssueSqsQueueUrl() {
187
+ if (constants_1.CONFIG_KEYS[sourceKey].env.includes("ISSUE_SQS_URL")) {
188
+ const issueSqsQueueUrl = process.env.ISSUE_SQS_URL;
189
+ if (!issueSqsQueueUrl) {
190
+ getConfig().LOGGER.error("ISSUE_SQS_URL must be set in environment variables");
191
+ throw new Error("dt-common-device: ISSUE_SQS_URL must be set in environment variables");
192
+ }
193
+ return issueSqsQueueUrl;
194
+ }
195
+ return "";
196
+ }
176
197
  function getEventSubscription() {
177
198
  return eventSubscription;
178
199
  }
@@ -23,6 +23,7 @@ exports.CONFIG_KEYS = {
23
23
  "PMS_DB_URI",
24
24
  "AWS_SQS_URL",
25
25
  "RESERVATION_SQS_URL",
26
+ "HEARTBEAT_SQS_URL",
26
27
  "ADMIN_SERVICE",
27
28
  "CRONICLE_ENDPOINT",
28
29
  "CRONICLE_API_KEY",
@@ -41,6 +42,7 @@ exports.CONFIG_KEYS = {
41
42
  "CRONICLE_ENDPOINT",
42
43
  "CRONICLE_API_KEY",
43
44
  "AWS_SQS_URL",
45
+ "ISSUE_SQS_URL",
44
46
  ],
45
47
  INTERNAL_EVENT_HANDLER: true,
46
48
  db_keys: {
@@ -50,7 +52,13 @@ exports.CONFIG_KEYS = {
50
52
  },
51
53
  },
52
54
  ENERGY: {
53
- env: ["ADMIN_DB_URI", "PMS_DB_URI", "AWS_SQS_URL", "ADMIN_SERVICE"],
55
+ env: [
56
+ "ADMIN_DB_URI",
57
+ "PMS_DB_URI",
58
+ "AWS_SQS_URL",
59
+ "ADMIN_SERVICE",
60
+ "HEARTBEAT_SQS_URL",
61
+ ],
54
62
  INTERNAL_EVENT_HANDLER: true,
55
63
  db_keys: {
56
64
  energy: "DATABASE_URL",
@@ -72,6 +80,7 @@ exports.CONFIG_KEYS = {
72
80
  "ADMIN_DB_URI",
73
81
  "ACCESS_DB_URI",
74
82
  "AWS_SQS_URL",
83
+ "HEARTBEAT_SQS_URL",
75
84
  "CRONICLE_ENDPOINT",
76
85
  "CRONICLE_API_KEY",
77
86
  ],
@@ -6,7 +6,7 @@ export declare class LocalDeviceService {
6
6
  private readonly deviceRepository;
7
7
  private readonly issueService;
8
8
  private readonly localPropertyService;
9
- private readonly deviceProfileRepository;
9
+ private readonly monitoringRepository;
10
10
  constructor();
11
11
  createDevice(body: IDevice): Promise<IDevice>;
12
12
  getDevice(deviceId: string, withHubDetails?: boolean): Promise<IDevice>;
@@ -83,7 +83,7 @@ const constants_1 = require("../../../../constants");
83
83
  const audit_1 = require("../../../../audit");
84
84
  const issue_types_1 = require("../../../../issues/issue.types");
85
85
  const property_1 = require("../../../property");
86
- const DeviceProfile_repository_1 = require("../repository/DeviceProfile.repository");
86
+ const Monitoring_repository_1 = require("../../../monitoring/Monitoring.repository");
87
87
  let LocalDeviceService = (() => {
88
88
  let _classDecorators = [(0, typedi_1.Service)()];
89
89
  let _classDescriptor;
@@ -96,7 +96,7 @@ let LocalDeviceService = (() => {
96
96
  this.deviceRepository = typedi_1.default.get(Device_repository_1.DeviceRepository);
97
97
  this.issueService = typedi_1.default.get(Issue_service_1.IssueService);
98
98
  this.localPropertyService = typedi_1.default.get(property_1.LocalPropertyService);
99
- this.deviceProfileRepository = typedi_1.default.get(DeviceProfile_repository_1.DeviceProfileRepository);
99
+ this.monitoringRepository = typedi_1.default.get(Monitoring_repository_1.MonitoringRepository);
100
100
  }
101
101
  async createDevice(body) {
102
102
  const device = await this.deviceRepository.createDevice(body);
@@ -351,7 +351,7 @@ let LocalDeviceService = (() => {
351
351
  }
352
352
  }
353
353
  async getDeviceBaseline(deviceId) {
354
- const response = await this.deviceProfileRepository.getDeviceBaseLine(deviceId);
354
+ const response = await this.monitoringRepository.getDeviceBaseLine(deviceId);
355
355
  const baselineInMilliseconds = response?.baseline && response?.baseline * 60 * 1000;
356
356
  return baselineInMilliseconds ?? 3600000; // 1 hour in milliseconds
357
357
  }
@@ -0,0 +1,5 @@
1
+ export declare class MonitoringRepository {
2
+ private readonly axiosInstance;
3
+ constructor();
4
+ getDeviceBaseLine(deviceId: string): Promise<any>;
5
+ }
@@ -0,0 +1,75 @@
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.MonitoringRepository = void 0;
42
+ const typedi_1 = require("typedi");
43
+ const utils_1 = require("../../utils");
44
+ const config_1 = require("../../config/config");
45
+ let MonitoringRepository = (() => {
46
+ let _classDecorators = [(0, typedi_1.Service)()];
47
+ let _classDescriptor;
48
+ let _classExtraInitializers = [];
49
+ let _classThis;
50
+ var MonitoringRepository = _classThis = class {
51
+ constructor() {
52
+ this.axiosInstance = (0, utils_1.getMonitoringServiceAxiosInstance)();
53
+ }
54
+ async getDeviceBaseLine(deviceId) {
55
+ try {
56
+ const response = await this.axiosInstance.get(`/baseline/${deviceId}`);
57
+ return response.data;
58
+ }
59
+ catch (error) {
60
+ (0, config_1.getConfig)().LOGGER.error(`Failed to get device baseline for ${deviceId}:`, error);
61
+ throw new Error(`Failed to get device baseline: ${error.message || "Unknown error"}`);
62
+ }
63
+ }
64
+ };
65
+ __setFunctionName(_classThis, "MonitoringRepository");
66
+ (() => {
67
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
68
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
69
+ MonitoringRepository = _classThis = _classDescriptor.value;
70
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
71
+ __runInitializers(_classThis, _classExtraInitializers);
72
+ })();
73
+ return MonitoringRepository = _classThis;
74
+ })();
75
+ exports.MonitoringRepository = MonitoringRepository;
@@ -10,6 +10,8 @@ export declare class InternalEventSubscription {
10
10
  private readonly internalEventHandler;
11
11
  private readonly sqsQueueUrl;
12
12
  private readonly reservationSqsQueueUrl;
13
+ private readonly heartbeatSqsQueueUrl;
14
+ private readonly issueSqsQueueUrl;
13
15
  private readonly logger;
14
16
  private readonly isInitialized;
15
17
  private isSubscribed;
@@ -20,6 +20,8 @@ class InternalEventSubscription {
20
20
  this.isSubscribed = false;
21
21
  this.sqsQueueUrl = (0, config_1.getSqsQueueUrl)() || "";
22
22
  this.reservationSqsQueueUrl = (0, config_1.getReservationSqsQueueUrl)() || "";
23
+ this.heartbeatSqsQueueUrl = (0, config_1.getHeartbeatSqsQueueUrl)() || "";
24
+ this.issueSqsQueueUrl = (0, config_1.getIssueSqsQueueUrl)() || "";
23
25
  this.logger = (0, config_1.getConfig)().LOGGER;
24
26
  this.isInitialized = true;
25
27
  }
@@ -108,9 +110,13 @@ class InternalEventSubscription {
108
110
  }
109
111
  try {
110
112
  if (this.reservationSqsQueueUrl) {
111
- this.logger.info(`Subscribing to reservation events : ${this.reservationSqsQueueUrl}`);
112
113
  await dt_pub_sub_1.eventDispatcher.subscribeToQueue(this.reservationSqsQueueUrl, this.handleMessage.bind(this));
113
- this.logger.info(`Successfully subscribed to reservation events : ${this.reservationSqsQueueUrl}`);
114
+ }
115
+ if (this.heartbeatSqsQueueUrl) {
116
+ await dt_pub_sub_1.eventDispatcher.subscribeToQueue(this.heartbeatSqsQueueUrl, this.handleMessage.bind(this));
117
+ }
118
+ if (this.issueSqsQueueUrl) {
119
+ await dt_pub_sub_1.eventDispatcher.subscribeToQueue(this.issueSqsQueueUrl, this.handleMessage.bind(this));
114
120
  }
115
121
  await dt_pub_sub_1.eventDispatcher.subscribeToQueue(this.sqsQueueUrl, this.handleMessage.bind(this));
116
122
  this.isSubscribed = true;
@@ -8,7 +8,7 @@ export declare function validateServiceUrl(url: string): boolean;
8
8
  export declare function createAxiosInstance(baseURL?: string): import("axios").AxiosInstance;
9
9
  export declare function getDeviceServiceAxiosInstance(): any;
10
10
  export declare function getAdminServiceAxiosInstance(): any;
11
- export declare function getDeviceProfileServiceAxiosInstance(): any;
11
+ export declare function getMonitoringServiceAxiosInstance(): any;
12
12
  /**
13
13
  * Retry function for failed HTTP requests
14
14
  */
@@ -7,7 +7,7 @@ exports.validateServiceUrl = validateServiceUrl;
7
7
  exports.createAxiosInstance = createAxiosInstance;
8
8
  exports.getDeviceServiceAxiosInstance = getDeviceServiceAxiosInstance;
9
9
  exports.getAdminServiceAxiosInstance = getAdminServiceAxiosInstance;
10
- exports.getDeviceProfileServiceAxiosInstance = getDeviceProfileServiceAxiosInstance;
10
+ exports.getMonitoringServiceAxiosInstance = getMonitoringServiceAxiosInstance;
11
11
  exports.retryRequest = retryRequest;
12
12
  const config_1 = require("../config/config");
13
13
  const axios_1 = __importDefault(require("axios"));
@@ -98,12 +98,12 @@ function getAdminServiceAxiosInstance() {
98
98
  }
99
99
  return cloudServiceAxiosInstance;
100
100
  }
101
- let deviceProfileServiceAxiosInstance = null;
102
- function getDeviceProfileServiceAxiosInstance() {
103
- if (!deviceProfileServiceAxiosInstance) {
104
- deviceProfileServiceAxiosInstance = createAxiosInstance((0, config_1.getDeviceProfileServiceUrl)());
101
+ let deviceMonitoringServiceAxiosInstance = null;
102
+ function getMonitoringServiceAxiosInstance() {
103
+ if (!deviceMonitoringServiceAxiosInstance) {
104
+ deviceMonitoringServiceAxiosInstance = createAxiosInstance((0, config_1.getMonitoringServiceUrl)());
105
105
  }
106
- return deviceProfileServiceAxiosInstance;
106
+ return deviceMonitoringServiceAxiosInstance;
107
107
  }
108
108
  /**
109
109
  * Retry function for failed HTTP requests
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "8.0.0",
3
+ "version": "8.0.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [