@chirpier/chirpier-js 0.2.1 → 0.4.0
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/README.md +42 -10
- package/dist/__tests__/chirpier.test.js +410 -7
- package/dist/index.d.ts +67 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +227 -14
- package/package.json +1 -1
- package/src/__tests__/chirpier.test.ts +267 -6
- package/src/index.ts +232 -16
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,6 @@ export interface Config {
|
|
|
13
13
|
timeout?: number;
|
|
14
14
|
batchSize?: number;
|
|
15
15
|
flushDelay?: number;
|
|
16
|
-
/** @deprecated Queues are unbounded in memory. */
|
|
17
16
|
maxQueueSize?: number;
|
|
18
17
|
}
|
|
19
18
|
/**
|
|
@@ -39,6 +38,15 @@ export interface Event {
|
|
|
39
38
|
readonly timezone: string;
|
|
40
39
|
readonly created_at?: string;
|
|
41
40
|
}
|
|
41
|
+
export interface CreateEventPayload {
|
|
42
|
+
agent?: string;
|
|
43
|
+
event: string;
|
|
44
|
+
title?: string;
|
|
45
|
+
public?: boolean;
|
|
46
|
+
description?: string;
|
|
47
|
+
unit?: string;
|
|
48
|
+
timezone?: string;
|
|
49
|
+
}
|
|
42
50
|
export interface Policy {
|
|
43
51
|
readonly policy_id: string;
|
|
44
52
|
readonly event_id: string;
|
|
@@ -52,6 +60,8 @@ export interface Policy {
|
|
|
52
60
|
readonly severity: string;
|
|
53
61
|
readonly enabled: boolean;
|
|
54
62
|
}
|
|
63
|
+
export type CreatePolicyPayload = Omit<Policy, "policy_id">;
|
|
64
|
+
export type UpdatePolicyPayload = Partial<Omit<Policy, "policy_id">>;
|
|
55
65
|
export interface Alert {
|
|
56
66
|
readonly alert_id: string;
|
|
57
67
|
readonly policy_id: string;
|
|
@@ -76,7 +86,7 @@ export interface Alert {
|
|
|
76
86
|
export interface AlertDelivery {
|
|
77
87
|
readonly attempt_id: string;
|
|
78
88
|
readonly alert_id: string;
|
|
79
|
-
readonly
|
|
89
|
+
readonly destination_id?: string;
|
|
80
90
|
readonly channel: string;
|
|
81
91
|
readonly target: string;
|
|
82
92
|
readonly status: string;
|
|
@@ -84,6 +94,17 @@ export interface AlertDelivery {
|
|
|
84
94
|
readonly error_message?: string;
|
|
85
95
|
readonly created_at: string;
|
|
86
96
|
}
|
|
97
|
+
export interface Destination {
|
|
98
|
+
readonly destination_id: string;
|
|
99
|
+
readonly channel: string;
|
|
100
|
+
readonly url?: string;
|
|
101
|
+
readonly credentials?: Record<string, unknown>;
|
|
102
|
+
readonly scope: string;
|
|
103
|
+
readonly policy_ids?: string[];
|
|
104
|
+
readonly enabled: boolean;
|
|
105
|
+
}
|
|
106
|
+
export type CreateDestinationPayload = Omit<Destination, "destination_id">;
|
|
107
|
+
export type UpdateDestinationPayload = Partial<Omit<Destination, "destination_id">>;
|
|
87
108
|
export interface EventLogPoint {
|
|
88
109
|
readonly event_id: string;
|
|
89
110
|
readonly agent?: string;
|
|
@@ -96,6 +117,39 @@ export interface EventLogPoint {
|
|
|
96
117
|
readonly min: number;
|
|
97
118
|
readonly max: number;
|
|
98
119
|
}
|
|
120
|
+
export interface AnalyticsWindowQuery {
|
|
121
|
+
view: "window";
|
|
122
|
+
period: "1h" | "1d" | "7d" | "1m";
|
|
123
|
+
previous: "previous_window" | "previous_1d" | "previous_7d" | "previous_1m";
|
|
124
|
+
}
|
|
125
|
+
export interface AnalyticsWindowData {
|
|
126
|
+
readonly current_value: number;
|
|
127
|
+
readonly current_count: number;
|
|
128
|
+
readonly previous_value: number;
|
|
129
|
+
readonly previous_count: number;
|
|
130
|
+
readonly value_delta: number;
|
|
131
|
+
readonly count_delta: number;
|
|
132
|
+
readonly value_pct_change: number;
|
|
133
|
+
readonly count_pct_change: number;
|
|
134
|
+
readonly current_mean: number;
|
|
135
|
+
readonly previous_mean: number;
|
|
136
|
+
readonly mean_delta: number;
|
|
137
|
+
readonly mean_pct_change: number;
|
|
138
|
+
readonly current_stddev: number;
|
|
139
|
+
readonly previous_stddev: number;
|
|
140
|
+
}
|
|
141
|
+
export interface AnalyticsWindowResponse {
|
|
142
|
+
readonly event_id: string;
|
|
143
|
+
readonly view: "window";
|
|
144
|
+
readonly period: "1h" | "1d" | "7d" | "1m";
|
|
145
|
+
readonly previous: "previous_window" | "previous_1d" | "previous_7d" | "previous_1m";
|
|
146
|
+
readonly data: AnalyticsWindowData | null;
|
|
147
|
+
}
|
|
148
|
+
export interface DestinationTestResult {
|
|
149
|
+
readonly alert_id: string;
|
|
150
|
+
readonly destination_id: string;
|
|
151
|
+
readonly status: string;
|
|
152
|
+
}
|
|
99
153
|
export interface PaginationOptions {
|
|
100
154
|
period?: "minute" | "hour" | "day";
|
|
101
155
|
limit?: number;
|
|
@@ -130,11 +184,15 @@ export declare class Client {
|
|
|
130
184
|
shutdown(): Promise<void>;
|
|
131
185
|
close(): Promise<void>;
|
|
132
186
|
listEvents(): Promise<Event[]>;
|
|
187
|
+
createEvent(payload: CreateEventPayload): Promise<Event>;
|
|
133
188
|
getEvent(eventID: string): Promise<Event>;
|
|
134
189
|
updateEvent(eventID: string, payload: Partial<Omit<Event, "event_id" | "created_at">>): Promise<Event>;
|
|
135
190
|
listPolicies(): Promise<Policy[]>;
|
|
136
|
-
|
|
191
|
+
getPolicy(policyID: string): Promise<Policy>;
|
|
192
|
+
createPolicy(payload: CreatePolicyPayload): Promise<Policy>;
|
|
193
|
+
updatePolicy(policyID: string, payload: UpdatePolicyPayload): Promise<Policy>;
|
|
137
194
|
listAlerts(status?: string): Promise<Alert[]>;
|
|
195
|
+
getAlert(alertID: string): Promise<Alert>;
|
|
138
196
|
getAlertDeliveries(alertID: string, options?: {
|
|
139
197
|
limit?: number;
|
|
140
198
|
offset?: number;
|
|
@@ -142,8 +200,13 @@ export declare class Client {
|
|
|
142
200
|
}): Promise<AlertDelivery[]>;
|
|
143
201
|
acknowledgeAlert(alertID: string): Promise<Alert>;
|
|
144
202
|
archiveAlert(alertID: string): Promise<Alert>;
|
|
145
|
-
|
|
203
|
+
listDestinations(): Promise<Destination[]>;
|
|
204
|
+
createDestination(payload: CreateDestinationPayload): Promise<Destination>;
|
|
205
|
+
getDestination(destinationID: string): Promise<Destination>;
|
|
206
|
+
updateDestination(destinationID: string, payload: UpdateDestinationPayload): Promise<Destination>;
|
|
207
|
+
testDestination(destinationID: string): Promise<DestinationTestResult>;
|
|
146
208
|
getEventLogs(eventID: string, options?: PaginationOptions): Promise<EventLogPoint[]>;
|
|
209
|
+
getEventAnalytics(eventID: string, query: AnalyticsWindowQuery): Promise<AnalyticsWindowResponse>;
|
|
147
210
|
resolveAlert(alertID: string): Promise<Alert>;
|
|
148
211
|
}
|
|
149
212
|
export declare function createClient(config?: Config): Client;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAeA,0BAAkB,QAAQ;IACxB,IAAI,IAAI;IACR,KAAK,IAAI;IACT,IAAI,IAAI;IACR,KAAK,IAAI;CACV;AAED,MAAM,WAAW,MAAM;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAeA,0BAAkB,QAAQ;IACxB,IAAI,IAAI;IACR,KAAK,IAAI;IACT,IAAI,IAAI;IACR,KAAK,IAAI;CACV;AAED,MAAM,WAAW,MAAM;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;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,OAAO,CAAC,uBAAuB,CAAC;IASjG,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;CAK3D;AAID,wBAAgB,YAAY,CAAC,MAAM,GAAE,MAAW,GAAG,MAAM,CAExD;AA4DD,wBAAgB,UAAU,CAAC,OAAO,GAAE,MAAW,GAAG,IAAI,CA+BrD;AAED,wBAAsB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAStD;AAED,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAO1C;AAED,wBAAsB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAS3C"}
|
package/dist/index.js
CHANGED
|
@@ -99,6 +99,83 @@ var ChirpierError = /** @class */ (function (_super) {
|
|
|
99
99
|
return ChirpierError;
|
|
100
100
|
}(Error));
|
|
101
101
|
exports.ChirpierError = ChirpierError;
|
|
102
|
+
function classifyLogResponseStatus(status) {
|
|
103
|
+
if (status === undefined) {
|
|
104
|
+
return "success";
|
|
105
|
+
}
|
|
106
|
+
if (status === 429) {
|
|
107
|
+
return "retry_after";
|
|
108
|
+
}
|
|
109
|
+
if (status >= 500) {
|
|
110
|
+
if (status === 500 || status === 503) {
|
|
111
|
+
return "non_retryable";
|
|
112
|
+
}
|
|
113
|
+
return "retryable";
|
|
114
|
+
}
|
|
115
|
+
if (status >= 400) {
|
|
116
|
+
return "non_retryable";
|
|
117
|
+
}
|
|
118
|
+
return "success";
|
|
119
|
+
}
|
|
120
|
+
function getChirpierResponseMessage(data) {
|
|
121
|
+
if (typeof data === "string") {
|
|
122
|
+
var trimmed = data.trim();
|
|
123
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
124
|
+
}
|
|
125
|
+
if (data && typeof data === "object") {
|
|
126
|
+
var record = data;
|
|
127
|
+
if (typeof record.message === "string" && record.message.trim().length > 0) {
|
|
128
|
+
return record.message.trim();
|
|
129
|
+
}
|
|
130
|
+
if (typeof record.error === "string" && record.error.trim().length > 0) {
|
|
131
|
+
return record.error.trim();
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
return JSON.stringify(data);
|
|
135
|
+
}
|
|
136
|
+
catch (_a) {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
function getRetryDelayMs(retryCount, error) {
|
|
143
|
+
var _a, _b;
|
|
144
|
+
if (axios_1.default.isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 429) {
|
|
145
|
+
var retryAfterHeader = (_b = error.response.headers) === null || _b === void 0 ? void 0 : _b["retry-after"];
|
|
146
|
+
var retryAfterSeconds = Number(retryAfterHeader);
|
|
147
|
+
if (Number.isFinite(retryAfterSeconds) && retryAfterSeconds >= 0) {
|
|
148
|
+
return retryAfterSeconds * 1000;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
var baseDelay = Math.pow(2, retryCount) * 1000;
|
|
152
|
+
var jitter = Math.random() * 0.3 * baseDelay;
|
|
153
|
+
return baseDelay + jitter;
|
|
154
|
+
}
|
|
155
|
+
function normalizeSendLogsError(error, logLevel) {
|
|
156
|
+
var _a, _b;
|
|
157
|
+
if (!axios_1.default.isAxiosError(error)) {
|
|
158
|
+
return error;
|
|
159
|
+
}
|
|
160
|
+
var status = (_a = error.response) === null || _a === void 0 ? void 0 : _a.status;
|
|
161
|
+
if (classifyLogResponseStatus(status) !== "non_retryable") {
|
|
162
|
+
return error;
|
|
163
|
+
}
|
|
164
|
+
var responseMessage = getChirpierResponseMessage((_b = error.response) === null || _b === void 0 ? void 0 : _b.data);
|
|
165
|
+
if ((status === 401 || status === 403) && logLevel >= 1 /* LogLevel.Error */) {
|
|
166
|
+
if (responseMessage) {
|
|
167
|
+
console.error("Chirpier API returned ".concat(status, ": ").concat(responseMessage));
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
console.error("Chirpier API returned ".concat(status));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
var message = responseMessage ? "HTTP ".concat(status, ": ").concat(responseMessage) : "HTTP ".concat(status);
|
|
174
|
+
return new ChirpierError(message, "NON_RETRYABLE_RESPONSE");
|
|
175
|
+
}
|
|
176
|
+
function isNonRetryableLogError(error) {
|
|
177
|
+
return error instanceof ChirpierError && error.code === "NON_RETRYABLE_RESPONSE";
|
|
178
|
+
}
|
|
102
179
|
var Client = /** @class */ (function () {
|
|
103
180
|
function Client(options) {
|
|
104
181
|
if (options === void 0) { options = {}; }
|
|
@@ -158,15 +235,15 @@ var Client = /** @class */ (function () {
|
|
|
158
235
|
this.axiosInstance.interceptors.response.use(function (response) { return response; }, function (error) { return Promise.reject(error); });
|
|
159
236
|
(0, axios_retry_1.default)(this.axiosInstance, {
|
|
160
237
|
retries: this.retries,
|
|
161
|
-
retryDelay: function (retryCount) {
|
|
162
|
-
var baseDelay = Math.pow(2, retryCount) * 1000;
|
|
163
|
-
var jitter = Math.random() * 0.3 * baseDelay;
|
|
164
|
-
return baseDelay + jitter;
|
|
165
|
-
},
|
|
238
|
+
retryDelay: function (retryCount, error) { return getRetryDelayMs(retryCount, error); },
|
|
166
239
|
retryCondition: function (error) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
240
|
+
var _a;
|
|
241
|
+
if (axios_retry_1.default.isNetworkError(error)) {
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
var status = (_a = error.response) === null || _a === void 0 ? void 0 : _a.status;
|
|
245
|
+
var retryPolicy = classifyLogResponseStatus(status);
|
|
246
|
+
return retryPolicy === "retryable" || retryPolicy === "retry_after";
|
|
170
247
|
},
|
|
171
248
|
shouldResetTimeout: true,
|
|
172
249
|
});
|
|
@@ -317,6 +394,12 @@ var Client = /** @class */ (function () {
|
|
|
317
394
|
if (this.logLevel >= 1 /* LogLevel.Error */) {
|
|
318
395
|
console.error("Failed to send logs:", error_1);
|
|
319
396
|
}
|
|
397
|
+
if (isNonRetryableLogError(error_1)) {
|
|
398
|
+
if (this.logLevel >= 1 /* LogLevel.Error */) {
|
|
399
|
+
console.error("Dropping logs after non-retryable response from API");
|
|
400
|
+
}
|
|
401
|
+
return [2 /*return*/];
|
|
402
|
+
}
|
|
320
403
|
return [4 /*yield*/, this.queueLock.acquire("logQueue", function () { return __awaiter(_this, void 0, void 0, function () {
|
|
321
404
|
return __generator(this, function (_a) {
|
|
322
405
|
this.logQueue = __spreadArray(__spreadArray([], logsToSend, true), this.logQueue, true);
|
|
@@ -339,12 +422,19 @@ var Client = /** @class */ (function () {
|
|
|
339
422
|
};
|
|
340
423
|
Client.prototype.sendLogs = function (logs) {
|
|
341
424
|
return __awaiter(this, void 0, void 0, function () {
|
|
425
|
+
var error_2;
|
|
342
426
|
return __generator(this, function (_a) {
|
|
343
427
|
switch (_a.label) {
|
|
344
|
-
case 0:
|
|
428
|
+
case 0:
|
|
429
|
+
_a.trys.push([0, 2, , 3]);
|
|
430
|
+
return [4 /*yield*/, this.axiosInstance.post(this.apiEndpoint, logs)];
|
|
345
431
|
case 1:
|
|
346
432
|
_a.sent();
|
|
347
|
-
return [
|
|
433
|
+
return [3 /*break*/, 3];
|
|
434
|
+
case 2:
|
|
435
|
+
error_2 = _a.sent();
|
|
436
|
+
throw normalizeSendLogsError(error_2, this.logLevel);
|
|
437
|
+
case 3: return [2 /*return*/];
|
|
348
438
|
}
|
|
349
439
|
});
|
|
350
440
|
});
|
|
@@ -403,6 +493,19 @@ var Client = /** @class */ (function () {
|
|
|
403
493
|
});
|
|
404
494
|
});
|
|
405
495
|
};
|
|
496
|
+
Client.prototype.createEvent = function (payload) {
|
|
497
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
498
|
+
var response;
|
|
499
|
+
return __generator(this, function (_a) {
|
|
500
|
+
switch (_a.label) {
|
|
501
|
+
case 0: return [4 /*yield*/, this.axiosInstance.post("".concat(this.servicerEndpoint, "/events"), payload)];
|
|
502
|
+
case 1:
|
|
503
|
+
response = _a.sent();
|
|
504
|
+
return [2 /*return*/, response.data];
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
};
|
|
406
509
|
Client.prototype.getEvent = function (eventID) {
|
|
407
510
|
return __awaiter(this, void 0, void 0, function () {
|
|
408
511
|
var response;
|
|
@@ -442,6 +545,19 @@ var Client = /** @class */ (function () {
|
|
|
442
545
|
});
|
|
443
546
|
});
|
|
444
547
|
};
|
|
548
|
+
Client.prototype.getPolicy = function (policyID) {
|
|
549
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
550
|
+
var response;
|
|
551
|
+
return __generator(this, function (_a) {
|
|
552
|
+
switch (_a.label) {
|
|
553
|
+
case 0: return [4 /*yield*/, this.axiosInstance.get("".concat(this.servicerEndpoint, "/policies/").concat(policyID))];
|
|
554
|
+
case 1:
|
|
555
|
+
response = _a.sent();
|
|
556
|
+
return [2 /*return*/, response.data];
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
});
|
|
560
|
+
};
|
|
445
561
|
Client.prototype.createPolicy = function (payload) {
|
|
446
562
|
return __awaiter(this, void 0, void 0, function () {
|
|
447
563
|
var response;
|
|
@@ -455,6 +571,19 @@ var Client = /** @class */ (function () {
|
|
|
455
571
|
});
|
|
456
572
|
});
|
|
457
573
|
};
|
|
574
|
+
Client.prototype.updatePolicy = function (policyID, payload) {
|
|
575
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
576
|
+
var response;
|
|
577
|
+
return __generator(this, function (_a) {
|
|
578
|
+
switch (_a.label) {
|
|
579
|
+
case 0: return [4 /*yield*/, this.axiosInstance.put("".concat(this.servicerEndpoint, "/policies/").concat(policyID), payload)];
|
|
580
|
+
case 1:
|
|
581
|
+
response = _a.sent();
|
|
582
|
+
return [2 /*return*/, response.data];
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
});
|
|
586
|
+
};
|
|
458
587
|
Client.prototype.listAlerts = function (status) {
|
|
459
588
|
return __awaiter(this, void 0, void 0, function () {
|
|
460
589
|
var endpoint, response;
|
|
@@ -472,6 +601,19 @@ var Client = /** @class */ (function () {
|
|
|
472
601
|
});
|
|
473
602
|
});
|
|
474
603
|
};
|
|
604
|
+
Client.prototype.getAlert = function (alertID) {
|
|
605
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
606
|
+
var response;
|
|
607
|
+
return __generator(this, function (_a) {
|
|
608
|
+
switch (_a.label) {
|
|
609
|
+
case 0: return [4 /*yield*/, this.axiosInstance.get("".concat(this.servicerEndpoint, "/alerts/").concat(alertID))];
|
|
610
|
+
case 1:
|
|
611
|
+
response = _a.sent();
|
|
612
|
+
return [2 /*return*/, response.data];
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
};
|
|
475
617
|
Client.prototype.getAlertDeliveries = function (alertID_1) {
|
|
476
618
|
return __awaiter(this, arguments, void 0, function (alertID, options) {
|
|
477
619
|
var params, suffix, response;
|
|
@@ -524,14 +666,67 @@ var Client = /** @class */ (function () {
|
|
|
524
666
|
});
|
|
525
667
|
});
|
|
526
668
|
};
|
|
527
|
-
Client.prototype.
|
|
669
|
+
Client.prototype.listDestinations = function () {
|
|
528
670
|
return __awaiter(this, void 0, void 0, function () {
|
|
671
|
+
var response;
|
|
529
672
|
return __generator(this, function (_a) {
|
|
530
673
|
switch (_a.label) {
|
|
531
|
-
case 0: return [4 /*yield*/, this.axiosInstance.
|
|
674
|
+
case 0: return [4 /*yield*/, this.axiosInstance.get("".concat(this.servicerEndpoint, "/destinations"))];
|
|
532
675
|
case 1:
|
|
533
|
-
_a.sent();
|
|
534
|
-
return [2 /*return
|
|
676
|
+
response = _a.sent();
|
|
677
|
+
return [2 /*return*/, response.data];
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
});
|
|
681
|
+
};
|
|
682
|
+
Client.prototype.createDestination = function (payload) {
|
|
683
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
684
|
+
var response;
|
|
685
|
+
return __generator(this, function (_a) {
|
|
686
|
+
switch (_a.label) {
|
|
687
|
+
case 0: return [4 /*yield*/, this.axiosInstance.post("".concat(this.servicerEndpoint, "/destinations"), payload)];
|
|
688
|
+
case 1:
|
|
689
|
+
response = _a.sent();
|
|
690
|
+
return [2 /*return*/, response.data];
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
});
|
|
694
|
+
};
|
|
695
|
+
Client.prototype.getDestination = function (destinationID) {
|
|
696
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
697
|
+
var response;
|
|
698
|
+
return __generator(this, function (_a) {
|
|
699
|
+
switch (_a.label) {
|
|
700
|
+
case 0: return [4 /*yield*/, this.axiosInstance.get("".concat(this.servicerEndpoint, "/destinations/").concat(destinationID))];
|
|
701
|
+
case 1:
|
|
702
|
+
response = _a.sent();
|
|
703
|
+
return [2 /*return*/, response.data];
|
|
704
|
+
}
|
|
705
|
+
});
|
|
706
|
+
});
|
|
707
|
+
};
|
|
708
|
+
Client.prototype.updateDestination = function (destinationID, payload) {
|
|
709
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
710
|
+
var response;
|
|
711
|
+
return __generator(this, function (_a) {
|
|
712
|
+
switch (_a.label) {
|
|
713
|
+
case 0: return [4 /*yield*/, this.axiosInstance.put("".concat(this.servicerEndpoint, "/destinations/").concat(destinationID), payload)];
|
|
714
|
+
case 1:
|
|
715
|
+
response = _a.sent();
|
|
716
|
+
return [2 /*return*/, response.data];
|
|
717
|
+
}
|
|
718
|
+
});
|
|
719
|
+
});
|
|
720
|
+
};
|
|
721
|
+
Client.prototype.testDestination = function (destinationID) {
|
|
722
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
723
|
+
var response;
|
|
724
|
+
return __generator(this, function (_a) {
|
|
725
|
+
switch (_a.label) {
|
|
726
|
+
case 0: return [4 /*yield*/, this.axiosInstance.post("".concat(this.servicerEndpoint, "/destinations/").concat(destinationID, "/test"))];
|
|
727
|
+
case 1:
|
|
728
|
+
response = _a.sent();
|
|
729
|
+
return [2 /*return*/, response.data];
|
|
535
730
|
}
|
|
536
731
|
});
|
|
537
732
|
});
|
|
@@ -562,6 +757,24 @@ var Client = /** @class */ (function () {
|
|
|
562
757
|
});
|
|
563
758
|
});
|
|
564
759
|
};
|
|
760
|
+
Client.prototype.getEventAnalytics = function (eventID, query) {
|
|
761
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
762
|
+
var params, response;
|
|
763
|
+
return __generator(this, function (_a) {
|
|
764
|
+
switch (_a.label) {
|
|
765
|
+
case 0:
|
|
766
|
+
params = new URLSearchParams();
|
|
767
|
+
params.set("view", query.view);
|
|
768
|
+
params.set("period", query.period);
|
|
769
|
+
params.set("previous", query.previous);
|
|
770
|
+
return [4 /*yield*/, this.axiosInstance.get("".concat(this.servicerEndpoint, "/events/").concat(eventID, "/analytics?").concat(params.toString()))];
|
|
771
|
+
case 1:
|
|
772
|
+
response = _a.sent();
|
|
773
|
+
return [2 /*return*/, response.data];
|
|
774
|
+
}
|
|
775
|
+
});
|
|
776
|
+
});
|
|
777
|
+
};
|
|
565
778
|
Client.prototype.resolveAlert = function (alertID) {
|
|
566
779
|
return __awaiter(this, void 0, void 0, function () {
|
|
567
780
|
var response;
|