dt-common-device 7.10.7 → 7.10.8
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.
- package/dist/chronicle/Cronicle.service.d.ts +6 -2
- package/dist/chronicle/Cronicle.service.js +19 -2
- package/dist/chronicle/ICronicle.interface.d.ts +1 -0
- package/dist/constants/Event.d.ts +16 -0
- package/dist/constants/Event.js +16 -0
- package/dist/cronicle/Cronicle.service.d.ts +13 -0
- package/dist/cronicle/Cronicle.service.js +91 -0
- package/dist/cronicle/ICronicle.interface.d.ts +16 -0
- package/dist/cronicle/ICronicle.interface.js +2 -0
- package/dist/cronicle/index.d.ts +2 -0
- package/dist/cronicle/index.js +5 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -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
|
}
|
|
@@ -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
|
};
|
package/dist/constants/Event.js
CHANGED
|
@@ -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,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; } });
|
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 "./
|
|
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("./
|
|
48
|
+
__exportStar(require("./cronicle"), exports);
|
|
49
49
|
// REDIS EXPORTS
|
|
50
50
|
__exportStar(require("./utils"), exports);
|
|
51
51
|
// QUEUE EXPORTS
|