dt-common-device 7.10.7 → 7.10.9

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,9 +1,13 @@
1
1
  import { ICronicle } from "./ICronicle.interface";
2
2
  export declare class CronicleService {
3
- private cronicleEndpoint;
4
- private cronicleApiKey;
3
+ private readonly cronicleEndpoint;
4
+ private readonly cronicleApiKey;
5
5
  constructor();
6
6
  registerJob(payload: ICronicle): Promise<void>;
7
7
  getJob(jobId: string): Promise<any>;
8
+ getSchedules(filter: {
9
+ offset: number;
10
+ limit: number;
11
+ }): Promise<any>;
8
12
  deleteJob(jobId: string): Promise<void>;
9
13
  }
@@ -12,12 +12,12 @@ class CronicleService {
12
12
  this.cronicleApiKey = process.env.CRONICLE_API_KEY || "";
13
13
  }
14
14
  async registerJob(payload) {
15
- const { name, apiUrl, method, schedule, cronJobId, target } = payload;
15
+ const { name, apiUrl, method, schedule, cronJobId, target, category } = payload;
16
16
  try {
17
17
  await axios_1.default.post(`${this.cronicleEndpoint}/create_event/v1`, {
18
18
  id: cronJobId,
19
19
  title: name,
20
- category: "general",
20
+ category: category ?? "general",
21
21
  plugin: "urlplug",
22
22
  timeZone: "UTC",
23
23
  enabled: 1,
@@ -48,6 +48,8 @@ class CronicleService {
48
48
  }
49
49
  async getJob(jobId) {
50
50
  try {
51
+ (0, config_1.getConfig)().LOGGER.info(`Getting job: ${jobId}`);
52
+ (0, config_1.getConfig)().LOGGER.info(`Cronicle endpoint: ${this.cronicleEndpoint}/get_event/v1`);
51
53
  const res = await axios_1.default.post(`${this.cronicleEndpoint}/get_event/v1`, {
52
54
  id: jobId,
53
55
  api_key: this.cronicleApiKey,
@@ -55,6 +57,21 @@ class CronicleService {
55
57
  return res.data;
56
58
  }
57
59
  catch (error) {
60
+ (0, config_1.getConfig)().LOGGER.error(`Failed to get job: ${error.message}`);
61
+ return;
62
+ }
63
+ }
64
+ async getSchedules(filter) {
65
+ try {
66
+ const res = await axios_1.default.post(`${this.cronicleEndpoint}/get_schedule/v1`, {
67
+ api_key: this.cronicleApiKey,
68
+ offset: filter.offset ?? 0,
69
+ limit: filter.limit ?? 100,
70
+ });
71
+ return res.data;
72
+ }
73
+ catch (error) {
74
+ (0, config_1.getConfig)().LOGGER.error(`Failed to get schedules: ${error.message}`);
58
75
  return;
59
76
  }
60
77
  }
@@ -1,6 +1,7 @@
1
1
  export interface ICronicle {
2
2
  name: string;
3
3
  cronJobId: string;
4
+ category?: "heartbeat" | "replenish_codes" | "sync_reservations" | "delete_reservations" | "deliver_codes" | "daily_summary" | "battery_report";
4
5
  apiUrl: string;
5
6
  method: "POST";
6
7
  target: string;
@@ -236,4 +236,20 @@ export declare const DT_EVENT_TYPES: {
236
236
  FAILED: string;
237
237
  };
238
238
  };
239
+ HEARTBEAT: {
240
+ DISABLED: string;
241
+ STARTED: string;
242
+ STOPPED: string;
243
+ COMPLETED: string;
244
+ FAILED: string;
245
+ EVENT_PUBLISHED: string;
246
+ EVENT_RECEIVED: string;
247
+ ERROR: string;
248
+ };
249
+ ACCOUNT: {
250
+ DEVICE: {
251
+ NEW: string;
252
+ MISSING: string;
253
+ };
254
+ };
239
255
  };
@@ -239,4 +239,20 @@ exports.DT_EVENT_TYPES = {
239
239
  FAILED: "alert.mark_as_unread.failed",
240
240
  },
241
241
  },
242
+ HEARTBEAT: {
243
+ DISABLED: 'heartbeat.disabled',
244
+ STARTED: 'heartbeat.started',
245
+ STOPPED: 'heartbeat.stopped',
246
+ COMPLETED: 'heartbeat.completed',
247
+ FAILED: 'heartbeat.failed',
248
+ EVENT_PUBLISHED: 'heartbeat.event_published',
249
+ EVENT_RECEIVED: 'heartbeat.event_received',
250
+ ERROR: 'heartbeat.error',
251
+ },
252
+ ACCOUNT: {
253
+ DEVICE: {
254
+ NEW: 'account.device.new',
255
+ MISSING: 'account.device.missing',
256
+ }
257
+ }
242
258
  };
@@ -0,0 +1,13 @@
1
+ import { ICronicle } from "./ICronicle.interface";
2
+ export declare class CronicleService {
3
+ private readonly cronicleEndpoint;
4
+ private readonly cronicleApiKey;
5
+ constructor();
6
+ registerJob(payload: ICronicle): Promise<void>;
7
+ getJob(jobId: string): Promise<any>;
8
+ getSchedules(filter: {
9
+ offset: number;
10
+ limit: number;
11
+ }): Promise<any>;
12
+ deleteJob(jobId: string): Promise<void>;
13
+ }
@@ -0,0 +1,91 @@
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.CronicleService = void 0;
7
+ const config_1 = require("../config/config");
8
+ const axios_1 = __importDefault(require("axios"));
9
+ class CronicleService {
10
+ constructor() {
11
+ this.cronicleEndpoint = process.env.CRONICLE_ENDPOINT || "";
12
+ this.cronicleApiKey = process.env.CRONICLE_API_KEY || "";
13
+ }
14
+ async registerJob(payload) {
15
+ const { name, apiUrl, method, schedule, cronJobId, target, category } = payload;
16
+ try {
17
+ await axios_1.default.post(`${this.cronicleEndpoint}/create_event/v1`, {
18
+ id: cronJobId,
19
+ title: name,
20
+ category: "general",
21
+ plugin: "urlplug",
22
+ timeZone: "UTC",
23
+ enabled: 1,
24
+ target: target,
25
+ api_key: this.cronicleApiKey,
26
+ params: {
27
+ url: apiUrl,
28
+ method,
29
+ headers: {
30
+ "Content-Type": "application/json",
31
+ "x-api-key": this.cronicleApiKey,
32
+ },
33
+ },
34
+ data: payload,
35
+ timing: {
36
+ years: schedule.years,
37
+ months: schedule.months,
38
+ days: schedule.days,
39
+ weekdays: schedule.weekdays,
40
+ hours: schedule.hours,
41
+ minutes: schedule.minutes,
42
+ },
43
+ });
44
+ }
45
+ catch (error) {
46
+ (0, config_1.getConfig)().LOGGER.error(`Failed to create device: ${error.message}`);
47
+ }
48
+ }
49
+ async getJob(jobId) {
50
+ try {
51
+ const res = await axios_1.default.post(`${this.cronicleEndpoint}/get_event/v1`, {
52
+ id: jobId,
53
+ api_key: this.cronicleApiKey,
54
+ });
55
+ return res.data;
56
+ }
57
+ catch (error) {
58
+ (0, config_1.getConfig)().LOGGER.error(`Failed to get job: ${error.message}`);
59
+ return;
60
+ }
61
+ }
62
+ async getSchedules(filter) {
63
+ try {
64
+ const res = await axios_1.default.post(`${this.cronicleEndpoint}/get_schedule/v1`, {
65
+ api_key: this.cronicleApiKey,
66
+ offset: filter.offset ?? 0,
67
+ limit: filter.limit ?? 100,
68
+ });
69
+ return res.data;
70
+ }
71
+ catch (error) {
72
+ (0, config_1.getConfig)().LOGGER.error(`Failed to get schedules: ${error.message}`);
73
+ return;
74
+ }
75
+ }
76
+ async deleteJob(jobId) {
77
+ try {
78
+ (0, config_1.getConfig)().LOGGER.info(`Deleting job: ${jobId}`);
79
+ await axios_1.default.post(`${this.cronicleEndpoint}/delete_event/v1`, {
80
+ id: jobId,
81
+ api_key: this.cronicleApiKey,
82
+ });
83
+ (0, config_1.getConfig)().LOGGER.info(`Deleted job: ${jobId}`);
84
+ }
85
+ catch (error) {
86
+ (0, config_1.getConfig)().LOGGER.error(`Failed to delete job: ${error.message}`);
87
+ throw error;
88
+ }
89
+ }
90
+ }
91
+ exports.CronicleService = CronicleService;
@@ -0,0 +1,16 @@
1
+ export interface ICronicle {
2
+ name: string;
3
+ cronJobId: string;
4
+ category?: "heartbeat" | "replenish_codes" | "sync_schedules" | "delete_schedules" | "deliver_codes" | "daily_summary" | "battery_report" | "deactivate_alerts" | "activate_alerts";
5
+ apiUrl: string;
6
+ method: "POST";
7
+ target: string;
8
+ schedule: {
9
+ years?: number[];
10
+ months?: number[];
11
+ days?: number[];
12
+ weekdays?: number[];
13
+ hours?: number[];
14
+ minutes?: number[];
15
+ };
16
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export { CronicleService } from "./Cronicle.service";
2
+ export type { ICronicle } from "./ICronicle.interface";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CronicleService = void 0;
4
+ var Cronicle_service_1 = require("./Cronicle.service");
5
+ Object.defineProperty(exports, "CronicleService", { enumerable: true, get: function () { return Cronicle_service_1.CronicleService; } });
@@ -1,5 +1,5 @@
1
1
  export declare class DeviceProfileRepository {
2
2
  private readonly axiosInstance;
3
3
  constructor();
4
- getDeviceBaseLine(deviceId: string): Promise<void>;
4
+ getDeviceBaseLine(deviceId: string): Promise<any>;
5
5
  }
@@ -41,6 +41,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.DeviceProfileRepository = void 0;
42
42
  const typedi_1 = require("typedi");
43
43
  const utils_1 = require("../../../../utils");
44
+ const config_1 = require("../../../../config/config");
44
45
  let DeviceProfileRepository = (() => {
45
46
  let _classDecorators = [(0, typedi_1.Service)()];
46
47
  let _classDescriptor;
@@ -50,7 +51,16 @@ let DeviceProfileRepository = (() => {
50
51
  constructor() {
51
52
  this.axiosInstance = (0, utils_1.getDeviceServiceAxiosInstance)();
52
53
  }
53
- async getDeviceBaseLine(deviceId) { }
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
+ }
54
64
  };
55
65
  __setFunctionName(_classThis, "DeviceProfileRepository");
56
66
  (() => {
@@ -27,9 +27,8 @@ class InternalEventSubscription {
27
27
  try {
28
28
  const eventType = message["detail-type"];
29
29
  const eventData = message.detail;
30
- //TODO: To be sent with event data, to delete the message if processing is failed!
31
- const eventToken = message.receiptHandle;
32
- console.log('eventToken', eventToken);
30
+ const MessageId = message.id;
31
+ eventData.MessageId = MessageId;
33
32
  this.logger.info(`Received internal event: ${eventType} ${eventData}`);
34
33
  switch (eventType) {
35
34
  case InternalEventType.HEARTBEAT:
package/dist/index.d.ts CHANGED
@@ -11,7 +11,7 @@ export * from "./events";
11
11
  export * from "./events/interfaces";
12
12
  export * from "./alerts";
13
13
  export * from "./issues";
14
- export * from "./chronicle";
14
+ export * from "./cronicle";
15
15
  export * from "./utils";
16
16
  export * from "./queue";
17
17
  export * from "./entities/pms";
package/dist/index.js CHANGED
@@ -45,7 +45,7 @@ __exportStar(require("./alerts"), exports);
45
45
  // ISSUES EXPORTS
46
46
  __exportStar(require("./issues"), exports);
47
47
  // CHRONICLE EXPORTS
48
- __exportStar(require("./chronicle"), exports);
48
+ __exportStar(require("./cronicle"), exports);
49
49
  // REDIS EXPORTS
50
50
  __exportStar(require("./utils"), exports);
51
51
  // QUEUE EXPORTS
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "7.10.7",
3
+ "version": "7.10.9",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [