@honeybadger-io/js 6.5.2 → 6.6.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/dist/browser/honeybadger.js +10 -4
- package/dist/browser/honeybadger.js.map +1 -1
- package/dist/browser/honeybadger.min.js +1 -1
- package/dist/browser/honeybadger.min.js.map +1 -1
- package/dist/browser/transport.d.ts +4 -1
- package/dist/server/checkins-manager/checkin.d.ts +31 -0
- package/dist/server/checkins-manager/client.d.ts +21 -0
- package/dist/server/checkins-manager/index.d.ts +15 -0
- package/dist/server/checkins-manager/types.d.ts +66 -0
- package/dist/server/checkins-sync-exec.d.ts +2 -0
- package/dist/server/checkins-sync-exec.js +885 -0
- package/dist/server/checkins-sync-exec.js.map +1 -0
- package/dist/server/checkins-sync.d.ts +2 -0
- package/dist/server/honeybadger.d.ts +9 -5
- package/dist/server/honeybadger.js +507 -66
- package/dist/server/honeybadger.js.map +1 -1
- package/dist/server/transport.d.ts +4 -1
- package/dist/server/util.d.ts +1 -0
- package/package.json +11 -6
|
@@ -0,0 +1,885 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var require$$0 = require('os');
|
|
7
|
+
var require$$1 = require('fs');
|
|
8
|
+
var require$$2 = require('util');
|
|
9
|
+
var require$$3 = require('cosmiconfig');
|
|
10
|
+
var require$$0$1 = require('@honeybadger-io/core');
|
|
11
|
+
var require$$1$1 = require('url');
|
|
12
|
+
var require$$3$1 = require('http');
|
|
13
|
+
var require$$4 = require('https');
|
|
14
|
+
|
|
15
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
|
+
|
|
17
|
+
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
18
|
+
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
19
|
+
var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
|
|
20
|
+
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
|
|
21
|
+
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
22
|
+
var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
|
|
23
|
+
var require$$3__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$3$1);
|
|
24
|
+
var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
|
|
25
|
+
|
|
26
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
27
|
+
|
|
28
|
+
var checkinsSyncExec = {};
|
|
29
|
+
|
|
30
|
+
var checkinsSync = {};
|
|
31
|
+
|
|
32
|
+
var util = {};
|
|
33
|
+
|
|
34
|
+
var __awaiter$3 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
35
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
36
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
37
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
38
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
39
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
40
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
var __generator$3 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
|
|
44
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
45
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
46
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
47
|
+
function step(op) {
|
|
48
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
49
|
+
while (_) try {
|
|
50
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
51
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
52
|
+
switch (op[0]) {
|
|
53
|
+
case 0: case 1: t = op; break;
|
|
54
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
55
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
56
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
57
|
+
default:
|
|
58
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
59
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
60
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
61
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
62
|
+
if (t[2]) _.ops.pop();
|
|
63
|
+
_.trys.pop(); continue;
|
|
64
|
+
}
|
|
65
|
+
op = body.call(thisArg, _);
|
|
66
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
67
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
71
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
72
|
+
};
|
|
73
|
+
Object.defineProperty(util, "__esModule", { value: true });
|
|
74
|
+
util.readConfigFromFileSystem = util.getSourceFile = util.getStats = util.fatallyLogAndExit = void 0;
|
|
75
|
+
var os_1 = __importDefault(require$$0__default["default"]);
|
|
76
|
+
var fs_1 = __importDefault(require$$1__default["default"]);
|
|
77
|
+
var util_1$1 = require$$2__default["default"];
|
|
78
|
+
var cosmiconfig_1 = require$$3__default["default"];
|
|
79
|
+
var readFile = (0, util_1$1.promisify)(fs_1.default.readFile);
|
|
80
|
+
function fatallyLogAndExit(err) {
|
|
81
|
+
console.error('[Honeybadger] Exiting process due to uncaught exception');
|
|
82
|
+
console.error(err.stack || err);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
util.fatallyLogAndExit = fatallyLogAndExit;
|
|
86
|
+
function getStats() {
|
|
87
|
+
return __awaiter$3(this, void 0, void 0, function () {
|
|
88
|
+
var load, stats, fallback, memData, data, results;
|
|
89
|
+
return __generator$3(this, function (_a) {
|
|
90
|
+
switch (_a.label) {
|
|
91
|
+
case 0:
|
|
92
|
+
load = os_1.default.loadavg();
|
|
93
|
+
stats = {
|
|
94
|
+
load: {
|
|
95
|
+
one: load[0],
|
|
96
|
+
five: load[1],
|
|
97
|
+
fifteen: load[2]
|
|
98
|
+
},
|
|
99
|
+
mem: {}
|
|
100
|
+
};
|
|
101
|
+
fallback = function () {
|
|
102
|
+
stats.mem = {
|
|
103
|
+
free: os_1.default.freemem(),
|
|
104
|
+
total: os_1.default.totalmem()
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
if (!fs_1.default.existsSync('/proc/meminfo')) {
|
|
108
|
+
fallback();
|
|
109
|
+
return [2 /*return*/, stats];
|
|
110
|
+
}
|
|
111
|
+
_a.label = 1;
|
|
112
|
+
case 1:
|
|
113
|
+
_a.trys.push([1, 3, , 4]);
|
|
114
|
+
return [4 /*yield*/, readFile('/proc/meminfo', 'utf8')
|
|
115
|
+
// The first four lines, in order, are Total, Free, Buffers, Cached.
|
|
116
|
+
// @TODO: Figure out if there's a way to only read these lines
|
|
117
|
+
];
|
|
118
|
+
case 2:
|
|
119
|
+
memData = _a.sent();
|
|
120
|
+
data = memData.split('\n').slice(0, 4);
|
|
121
|
+
results = data.map(function (i) {
|
|
122
|
+
return parseInt(/\s+(\d+)\skB/i.exec(i)[1], 10) / 1024.0;
|
|
123
|
+
});
|
|
124
|
+
stats.mem = {
|
|
125
|
+
total: results[0],
|
|
126
|
+
free: results[1],
|
|
127
|
+
buffers: results[2],
|
|
128
|
+
cached: results[3],
|
|
129
|
+
free_total: results[1] + results[2] + results[3]
|
|
130
|
+
};
|
|
131
|
+
return [3 /*break*/, 4];
|
|
132
|
+
case 3:
|
|
133
|
+
_a.sent();
|
|
134
|
+
fallback();
|
|
135
|
+
return [3 /*break*/, 4];
|
|
136
|
+
case 4: return [2 /*return*/, stats];
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
util.getStats = getStats;
|
|
142
|
+
/**
|
|
143
|
+
* Get source file if possible, used to build `notice.backtrace.source`
|
|
144
|
+
*
|
|
145
|
+
* @param path to source code
|
|
146
|
+
*/
|
|
147
|
+
function getSourceFile(path) {
|
|
148
|
+
return __awaiter$3(this, void 0, void 0, function () {
|
|
149
|
+
return __generator$3(this, function (_a) {
|
|
150
|
+
switch (_a.label) {
|
|
151
|
+
case 0:
|
|
152
|
+
_a.trys.push([0, 2, , 3]);
|
|
153
|
+
return [4 /*yield*/, readFile(path, 'utf-8')];
|
|
154
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
155
|
+
case 2:
|
|
156
|
+
_a.sent();
|
|
157
|
+
return [2 /*return*/, null];
|
|
158
|
+
case 3: return [2 /*return*/];
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
util.getSourceFile = getSourceFile;
|
|
164
|
+
function readConfigFromFileSystem$1() {
|
|
165
|
+
return readConfigForModule('honeybadger');
|
|
166
|
+
}
|
|
167
|
+
util.readConfigFromFileSystem = readConfigFromFileSystem$1;
|
|
168
|
+
function readConfigForModule(moduleName) {
|
|
169
|
+
var _a;
|
|
170
|
+
try {
|
|
171
|
+
var fileExplorer = (0, cosmiconfig_1.cosmiconfigSync)(moduleName);
|
|
172
|
+
var result = fileExplorer.search();
|
|
173
|
+
return (_a = result === null || result === void 0 ? void 0 : result.config) !== null && _a !== void 0 ? _a : null;
|
|
174
|
+
}
|
|
175
|
+
catch (e) {
|
|
176
|
+
console.debug("[Honeybadger] Could not read config for module ".concat(moduleName, ": ").concat(e.message));
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
var checkinsManager = {};
|
|
182
|
+
|
|
183
|
+
var client = {};
|
|
184
|
+
|
|
185
|
+
var checkin = {};
|
|
186
|
+
|
|
187
|
+
Object.defineProperty(checkin, "__esModule", { value: true });
|
|
188
|
+
checkin.Checkin = void 0;
|
|
189
|
+
var Checkin = /** @class */ (function () {
|
|
190
|
+
function Checkin(props) {
|
|
191
|
+
this.id = props.id;
|
|
192
|
+
this.name = props.name;
|
|
193
|
+
this.slug = props.slug;
|
|
194
|
+
this.scheduleType = props.scheduleType;
|
|
195
|
+
this.reportPeriod = props.reportPeriod;
|
|
196
|
+
this.gracePeriod = props.gracePeriod;
|
|
197
|
+
this.cronSchedule = props.cronSchedule;
|
|
198
|
+
this.cronTimezone = props.cronTimezone;
|
|
199
|
+
this.projectId = props.projectId;
|
|
200
|
+
this.deleted = false;
|
|
201
|
+
}
|
|
202
|
+
Checkin.prototype.isDeleted = function () {
|
|
203
|
+
return this.deleted;
|
|
204
|
+
};
|
|
205
|
+
Checkin.prototype.markAsDeleted = function () {
|
|
206
|
+
this.deleted = true;
|
|
207
|
+
};
|
|
208
|
+
Checkin.prototype.validate = function () {
|
|
209
|
+
if (!this.projectId) {
|
|
210
|
+
throw new Error('projectId is required for each checkin');
|
|
211
|
+
}
|
|
212
|
+
if (!this.name) {
|
|
213
|
+
throw new Error('name is required for each checkin');
|
|
214
|
+
}
|
|
215
|
+
if (!this.scheduleType) {
|
|
216
|
+
throw new Error('scheduleType is required for each checkin');
|
|
217
|
+
}
|
|
218
|
+
if (!['simple', 'cron'].includes(this.scheduleType)) {
|
|
219
|
+
throw new Error("".concat(this.name, " [scheduleType] must be \"simple\" or \"cron\""));
|
|
220
|
+
}
|
|
221
|
+
if (this.scheduleType === 'simple' && !this.reportPeriod) {
|
|
222
|
+
throw new Error("".concat(this.name, " [reportPeriod] is required for simple checkins"));
|
|
223
|
+
}
|
|
224
|
+
if (this.scheduleType === 'cron' && !this.cronSchedule) {
|
|
225
|
+
throw new Error("".concat(this.name, " [cronSchedule] is required for cron checkins"));
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
Checkin.prototype.asRequestPayload = function () {
|
|
229
|
+
var _a, _b, _c;
|
|
230
|
+
var payload = {
|
|
231
|
+
name: this.name,
|
|
232
|
+
schedule_type: this.scheduleType,
|
|
233
|
+
slug: (_a = this.slug) !== null && _a !== void 0 ? _a : '',
|
|
234
|
+
grace_period: (_b = this.gracePeriod) !== null && _b !== void 0 ? _b : '' // default is empty string
|
|
235
|
+
};
|
|
236
|
+
if (this.scheduleType === 'simple') {
|
|
237
|
+
payload.report_period = this.reportPeriod;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
payload.cron_schedule = this.cronSchedule;
|
|
241
|
+
payload.cron_timezone = (_c = this.cronTimezone) !== null && _c !== void 0 ? _c : ''; // default is empty string
|
|
242
|
+
}
|
|
243
|
+
return payload;
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* Compares two checkins, usually the one from the API and the one from the config file.
|
|
247
|
+
* If the one in the config file does not match the checkin from the API,
|
|
248
|
+
* then we issue an update request.
|
|
249
|
+
*/
|
|
250
|
+
Checkin.prototype.isInSync = function (other) {
|
|
251
|
+
var _a, _b, _c, _d, _e, _f;
|
|
252
|
+
return this.name === other.name
|
|
253
|
+
&& this.projectId === other.projectId
|
|
254
|
+
&& this.scheduleType === other.scheduleType
|
|
255
|
+
&& this.reportPeriod === other.reportPeriod
|
|
256
|
+
&& this.cronSchedule === other.cronSchedule
|
|
257
|
+
&& ((_a = this.slug) !== null && _a !== void 0 ? _a : '') === ((_b = other.slug) !== null && _b !== void 0 ? _b : '')
|
|
258
|
+
&& ((_c = this.gracePeriod) !== null && _c !== void 0 ? _c : '') === ((_d = other.gracePeriod) !== null && _d !== void 0 ? _d : '')
|
|
259
|
+
&& ((_e = this.cronTimezone) !== null && _e !== void 0 ? _e : '') === ((_f = other.cronTimezone) !== null && _f !== void 0 ? _f : '');
|
|
260
|
+
};
|
|
261
|
+
Checkin.fromResponsePayload = function (projectId, payload) {
|
|
262
|
+
return new Checkin({
|
|
263
|
+
projectId: projectId,
|
|
264
|
+
id: payload.id,
|
|
265
|
+
name: payload.name,
|
|
266
|
+
slug: payload.slug,
|
|
267
|
+
scheduleType: payload.schedule_type,
|
|
268
|
+
reportPeriod: payload.report_period,
|
|
269
|
+
gracePeriod: payload.grace_period,
|
|
270
|
+
cronSchedule: payload.cron_schedule,
|
|
271
|
+
cronTimezone: payload.cron_timezone,
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
return Checkin;
|
|
275
|
+
}());
|
|
276
|
+
checkin.Checkin = Checkin;
|
|
277
|
+
|
|
278
|
+
var __awaiter$2 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
279
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
280
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
281
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
282
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
283
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
284
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
285
|
+
});
|
|
286
|
+
};
|
|
287
|
+
var __generator$2 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
|
|
288
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
289
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
290
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
291
|
+
function step(op) {
|
|
292
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
293
|
+
while (_) try {
|
|
294
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
295
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
296
|
+
switch (op[0]) {
|
|
297
|
+
case 0: case 1: t = op; break;
|
|
298
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
299
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
300
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
301
|
+
default:
|
|
302
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
303
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
304
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
305
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
306
|
+
if (t[2]) _.ops.pop();
|
|
307
|
+
_.trys.pop(); continue;
|
|
308
|
+
}
|
|
309
|
+
op = body.call(thisArg, _);
|
|
310
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
311
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
Object.defineProperty(client, "__esModule", { value: true });
|
|
315
|
+
client.CheckinsClient = void 0;
|
|
316
|
+
var checkin_1$1 = checkin;
|
|
317
|
+
var CheckinsClient = /** @class */ (function () {
|
|
318
|
+
function CheckinsClient(config, transport) {
|
|
319
|
+
this.BASE_URL = 'https://app.honeybadger.io';
|
|
320
|
+
this.transport = transport;
|
|
321
|
+
this.config = config;
|
|
322
|
+
this.logger = config.logger;
|
|
323
|
+
this.cache = {};
|
|
324
|
+
}
|
|
325
|
+
CheckinsClient.prototype.listForProject = function (projectId) {
|
|
326
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
327
|
+
var response, data, checkins;
|
|
328
|
+
return __generator$2(this, function (_a) {
|
|
329
|
+
switch (_a.label) {
|
|
330
|
+
case 0:
|
|
331
|
+
if (this.cache[projectId]) {
|
|
332
|
+
return [2 /*return*/, this.cache[projectId]];
|
|
333
|
+
}
|
|
334
|
+
if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
|
|
335
|
+
throw new Error('personalAuthToken is required');
|
|
336
|
+
}
|
|
337
|
+
return [4 /*yield*/, this.transport.send({
|
|
338
|
+
method: 'GET',
|
|
339
|
+
headers: this.getHeaders(),
|
|
340
|
+
endpoint: "".concat(this.BASE_URL, "/v2/projects/").concat(projectId, "/check_ins"),
|
|
341
|
+
logger: this.logger,
|
|
342
|
+
})];
|
|
343
|
+
case 1:
|
|
344
|
+
response = _a.sent();
|
|
345
|
+
if (response.statusCode !== 200) {
|
|
346
|
+
throw new Error("Failed to fetch checkins for project[".concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
|
|
347
|
+
}
|
|
348
|
+
data = JSON.parse(response.body);
|
|
349
|
+
checkins = data.results.map(function (checkin) { return checkin_1$1.Checkin.fromResponsePayload(projectId, checkin); });
|
|
350
|
+
this.cache[projectId] = checkins;
|
|
351
|
+
return [2 /*return*/, checkins];
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
};
|
|
356
|
+
CheckinsClient.prototype.get = function (projectId, checkinId) {
|
|
357
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
358
|
+
var response, data, checkin;
|
|
359
|
+
return __generator$2(this, function (_a) {
|
|
360
|
+
switch (_a.label) {
|
|
361
|
+
case 0:
|
|
362
|
+
if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
|
|
363
|
+
throw new Error('personalAuthToken is required');
|
|
364
|
+
}
|
|
365
|
+
return [4 /*yield*/, this.transport.send({
|
|
366
|
+
method: 'GET',
|
|
367
|
+
headers: this.getHeaders(),
|
|
368
|
+
endpoint: "".concat(this.BASE_URL, "/v2/projects/").concat(projectId, "/check_ins/").concat(checkinId),
|
|
369
|
+
logger: this.logger,
|
|
370
|
+
})];
|
|
371
|
+
case 1:
|
|
372
|
+
response = _a.sent();
|
|
373
|
+
if (response.statusCode !== 200) {
|
|
374
|
+
throw new Error("Failed to fetch checkin[".concat(checkinId, "] for project[").concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
|
|
375
|
+
}
|
|
376
|
+
data = JSON.parse(response.body);
|
|
377
|
+
checkin = checkin_1$1.Checkin.fromResponsePayload(projectId, data);
|
|
378
|
+
checkin.projectId = projectId;
|
|
379
|
+
return [2 /*return*/, checkin];
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
};
|
|
384
|
+
CheckinsClient.prototype.create = function (checkin) {
|
|
385
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
386
|
+
var response, data, result;
|
|
387
|
+
return __generator$2(this, function (_a) {
|
|
388
|
+
switch (_a.label) {
|
|
389
|
+
case 0:
|
|
390
|
+
if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
|
|
391
|
+
throw new Error('personalAuthToken is required');
|
|
392
|
+
}
|
|
393
|
+
return [4 /*yield*/, this.transport.send({
|
|
394
|
+
method: 'POST',
|
|
395
|
+
headers: this.getHeaders(),
|
|
396
|
+
endpoint: "".concat(this.BASE_URL, "/v2/projects/").concat(checkin.projectId, "/check_ins"),
|
|
397
|
+
logger: this.logger,
|
|
398
|
+
}, { check_in: checkin.asRequestPayload() })];
|
|
399
|
+
case 1:
|
|
400
|
+
response = _a.sent();
|
|
401
|
+
if (response.statusCode !== 201) {
|
|
402
|
+
throw new Error("Failed to create checkin[".concat(checkin.name, "] for project[").concat(checkin.projectId, "]: ").concat(this.getErrorMessage(response.body)));
|
|
403
|
+
}
|
|
404
|
+
data = JSON.parse(response.body);
|
|
405
|
+
result = checkin_1$1.Checkin.fromResponsePayload(checkin.projectId, data);
|
|
406
|
+
result.projectId = checkin.projectId;
|
|
407
|
+
return [2 /*return*/, result];
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
};
|
|
412
|
+
CheckinsClient.prototype.update = function (checkin) {
|
|
413
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
414
|
+
var response;
|
|
415
|
+
return __generator$2(this, function (_a) {
|
|
416
|
+
switch (_a.label) {
|
|
417
|
+
case 0:
|
|
418
|
+
if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
|
|
419
|
+
throw new Error('personalAuthToken is required');
|
|
420
|
+
}
|
|
421
|
+
return [4 /*yield*/, this.transport.send({
|
|
422
|
+
method: 'PUT',
|
|
423
|
+
headers: this.getHeaders(),
|
|
424
|
+
endpoint: "".concat(this.BASE_URL, "/v2/projects/").concat(checkin.projectId, "/check_ins/").concat(checkin.id),
|
|
425
|
+
logger: this.logger,
|
|
426
|
+
}, { check_in: checkin.asRequestPayload() })];
|
|
427
|
+
case 1:
|
|
428
|
+
response = _a.sent();
|
|
429
|
+
if (response.statusCode !== 204) {
|
|
430
|
+
throw new Error("Failed to update checkin[".concat(checkin.name, "] for project[").concat(checkin.projectId, "]: ").concat(this.getErrorMessage(response.body)));
|
|
431
|
+
}
|
|
432
|
+
return [2 /*return*/, checkin];
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
};
|
|
437
|
+
CheckinsClient.prototype.remove = function (checkin) {
|
|
438
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
439
|
+
var response;
|
|
440
|
+
return __generator$2(this, function (_a) {
|
|
441
|
+
switch (_a.label) {
|
|
442
|
+
case 0:
|
|
443
|
+
if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
|
|
444
|
+
throw new Error('personalAuthToken is required');
|
|
445
|
+
}
|
|
446
|
+
return [4 /*yield*/, this.transport.send({
|
|
447
|
+
method: 'DELETE',
|
|
448
|
+
headers: this.getHeaders(),
|
|
449
|
+
endpoint: "".concat(this.BASE_URL, "/v2/projects/").concat(checkin.projectId, "/check_ins/").concat(checkin.id),
|
|
450
|
+
logger: this.logger,
|
|
451
|
+
})];
|
|
452
|
+
case 1:
|
|
453
|
+
response = _a.sent();
|
|
454
|
+
if (response.statusCode !== 204) {
|
|
455
|
+
throw new Error("Failed to remove checkin[".concat(checkin.name, "] for project[").concat(checkin.projectId, "]: ").concat(this.getErrorMessage(response.body)));
|
|
456
|
+
}
|
|
457
|
+
return [2 /*return*/];
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
};
|
|
462
|
+
CheckinsClient.prototype.getHeaders = function () {
|
|
463
|
+
return {
|
|
464
|
+
'Authorization': "Basic ".concat(Buffer.from("".concat(this.config.personalAuthToken, ":")).toString('base64')),
|
|
465
|
+
'Content-Type': 'application/json'
|
|
466
|
+
};
|
|
467
|
+
};
|
|
468
|
+
CheckinsClient.prototype.getErrorMessage = function (responseBody) {
|
|
469
|
+
var _a;
|
|
470
|
+
if (!responseBody) {
|
|
471
|
+
return '';
|
|
472
|
+
}
|
|
473
|
+
try {
|
|
474
|
+
var jsonBody = JSON.parse(responseBody);
|
|
475
|
+
return (_a = jsonBody.errors) !== null && _a !== void 0 ? _a : '';
|
|
476
|
+
}
|
|
477
|
+
catch (e) {
|
|
478
|
+
return responseBody;
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
return CheckinsClient;
|
|
482
|
+
}());
|
|
483
|
+
client.CheckinsClient = CheckinsClient;
|
|
484
|
+
|
|
485
|
+
var transport = {};
|
|
486
|
+
|
|
487
|
+
var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
|
|
488
|
+
__assign = Object.assign || function(t) {
|
|
489
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
490
|
+
s = arguments[i];
|
|
491
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
492
|
+
t[p] = s[p];
|
|
493
|
+
}
|
|
494
|
+
return t;
|
|
495
|
+
};
|
|
496
|
+
return __assign.apply(this, arguments);
|
|
497
|
+
};
|
|
498
|
+
var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
499
|
+
if (k2 === undefined) k2 = k;
|
|
500
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
501
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
502
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
503
|
+
}
|
|
504
|
+
Object.defineProperty(o, k2, desc);
|
|
505
|
+
}) : (function(o, m, k, k2) {
|
|
506
|
+
if (k2 === undefined) k2 = k;
|
|
507
|
+
o[k2] = m[k];
|
|
508
|
+
}));
|
|
509
|
+
var __setModuleDefault = (commonjsGlobal && commonjsGlobal.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
510
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
511
|
+
}) : function(o, v) {
|
|
512
|
+
o["default"] = v;
|
|
513
|
+
});
|
|
514
|
+
var __importStar = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) {
|
|
515
|
+
if (mod && mod.__esModule) return mod;
|
|
516
|
+
var result = {};
|
|
517
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
518
|
+
__setModuleDefault(result, mod);
|
|
519
|
+
return result;
|
|
520
|
+
};
|
|
521
|
+
Object.defineProperty(transport, "__esModule", { value: true });
|
|
522
|
+
transport.ServerTransport = void 0;
|
|
523
|
+
var core_1$1 = require$$0__default$1["default"];
|
|
524
|
+
var url_1 = require$$1__default$1["default"];
|
|
525
|
+
var util_1 = util;
|
|
526
|
+
var http = __importStar(require$$3__default$1["default"]);
|
|
527
|
+
var https = __importStar(require$$4__default["default"]);
|
|
528
|
+
var sanitize = core_1$1.Util.sanitize;
|
|
529
|
+
var ServerTransport = /** @class */ (function () {
|
|
530
|
+
function ServerTransport(headers) {
|
|
531
|
+
if (headers === void 0) { headers = {}; }
|
|
532
|
+
this.headers = {};
|
|
533
|
+
this.headers = headers;
|
|
534
|
+
}
|
|
535
|
+
ServerTransport.prototype.defaultHeaders = function () {
|
|
536
|
+
return this.headers;
|
|
537
|
+
};
|
|
538
|
+
ServerTransport.prototype.send = function (options, payload) {
|
|
539
|
+
var _this = this;
|
|
540
|
+
var _a = new url_1.URL(options.endpoint), protocol = _a.protocol, hostname = _a.hostname, pathname = _a.pathname;
|
|
541
|
+
var transport = (protocol === 'http:' ? http : https);
|
|
542
|
+
return new Promise(function (resolve, reject) {
|
|
543
|
+
var promise;
|
|
544
|
+
// this should not be here. it should be done before reaching the transport layer
|
|
545
|
+
// it could be inside a beforeNotifyHandler, but is not possible at the moment because those handlers are synchronous
|
|
546
|
+
if (_this.isNoticePayload(payload)) {
|
|
547
|
+
promise = _this.appendMetadata(payload);
|
|
548
|
+
}
|
|
549
|
+
else {
|
|
550
|
+
promise = Promise.resolve();
|
|
551
|
+
}
|
|
552
|
+
promise.then(function () {
|
|
553
|
+
//
|
|
554
|
+
// We use a httpOptions object to limit issues with libraries that may patch Node.js
|
|
555
|
+
// See https://github.com/honeybadger-io/honeybadger-js/issues/825#issuecomment-1193113433
|
|
556
|
+
var httpOptions = {
|
|
557
|
+
method: options.method,
|
|
558
|
+
headers: __assign(__assign({}, _this.defaultHeaders()), options.headers),
|
|
559
|
+
path: pathname,
|
|
560
|
+
protocol: protocol,
|
|
561
|
+
hostname: hostname,
|
|
562
|
+
};
|
|
563
|
+
var data = undefined;
|
|
564
|
+
if (payload) {
|
|
565
|
+
data = Buffer.from(JSON.stringify(sanitize(payload, options.maxObjectDepth)), 'utf8');
|
|
566
|
+
httpOptions.headers['Content-Length'] = data.length;
|
|
567
|
+
}
|
|
568
|
+
var req = transport.request(httpOptions, function (res) {
|
|
569
|
+
options.logger.debug("statusCode: ".concat(res.statusCode));
|
|
570
|
+
var body = '';
|
|
571
|
+
res.on('data', function (chunk) {
|
|
572
|
+
body += chunk;
|
|
573
|
+
});
|
|
574
|
+
res.on('end', function () { return resolve({ statusCode: res.statusCode, body: body }); });
|
|
575
|
+
});
|
|
576
|
+
req.on('error', function (err) { return reject(err); });
|
|
577
|
+
if (data) {
|
|
578
|
+
req.write(data);
|
|
579
|
+
}
|
|
580
|
+
req.end();
|
|
581
|
+
});
|
|
582
|
+
});
|
|
583
|
+
};
|
|
584
|
+
ServerTransport.prototype.isNoticePayload = function (payload) {
|
|
585
|
+
return payload && payload.error !== undefined;
|
|
586
|
+
};
|
|
587
|
+
ServerTransport.prototype.appendMetadata = function (payload) {
|
|
588
|
+
payload.server.pid = process.pid;
|
|
589
|
+
return (0, util_1.getStats)()
|
|
590
|
+
.then(function (stats) {
|
|
591
|
+
payload.server.stats = stats;
|
|
592
|
+
});
|
|
593
|
+
};
|
|
594
|
+
return ServerTransport;
|
|
595
|
+
}());
|
|
596
|
+
transport.ServerTransport = ServerTransport;
|
|
597
|
+
|
|
598
|
+
var __awaiter$1 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
599
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
600
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
601
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
602
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
603
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
604
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
605
|
+
});
|
|
606
|
+
};
|
|
607
|
+
var __generator$1 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
|
|
608
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
609
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
610
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
611
|
+
function step(op) {
|
|
612
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
613
|
+
while (_) try {
|
|
614
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
615
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
616
|
+
switch (op[0]) {
|
|
617
|
+
case 0: case 1: t = op; break;
|
|
618
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
619
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
620
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
621
|
+
default:
|
|
622
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
623
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
624
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
625
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
626
|
+
if (t[2]) _.ops.pop();
|
|
627
|
+
_.trys.pop(); continue;
|
|
628
|
+
}
|
|
629
|
+
op = body.call(thisArg, _);
|
|
630
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
631
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
var __spreadArray = (commonjsGlobal && commonjsGlobal.__spreadArray) || function (to, from, pack) {
|
|
635
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
636
|
+
if (ar || !(i in from)) {
|
|
637
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
638
|
+
ar[i] = from[i];
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
642
|
+
};
|
|
643
|
+
Object.defineProperty(checkinsManager, "__esModule", { value: true });
|
|
644
|
+
checkinsManager.CheckinsManager = void 0;
|
|
645
|
+
var core_1 = require$$0__default$1["default"];
|
|
646
|
+
var client_1 = client;
|
|
647
|
+
var transport_1 = transport;
|
|
648
|
+
var checkin_1 = checkin;
|
|
649
|
+
var CheckinsManager$1 = /** @class */ (function () {
|
|
650
|
+
function CheckinsManager(config, client) {
|
|
651
|
+
var _a, _b, _c, _d;
|
|
652
|
+
this.config = {
|
|
653
|
+
debug: (_a = config.debug) !== null && _a !== void 0 ? _a : false,
|
|
654
|
+
personalAuthToken: (_b = config.personalAuthToken) !== null && _b !== void 0 ? _b : undefined,
|
|
655
|
+
checkins: (_c = config.checkins) !== null && _c !== void 0 ? _c : [],
|
|
656
|
+
logger: (_d = config.logger) !== null && _d !== void 0 ? _d : console,
|
|
657
|
+
};
|
|
658
|
+
var transport = new transport_1.ServerTransport();
|
|
659
|
+
this.logger = core_1.Util.logger(this);
|
|
660
|
+
this.client = client !== null && client !== void 0 ? client : new client_1.CheckinsClient({
|
|
661
|
+
personalAuthToken: config.personalAuthToken,
|
|
662
|
+
logger: this.logger
|
|
663
|
+
}, transport);
|
|
664
|
+
}
|
|
665
|
+
CheckinsManager.prototype.sync = function () {
|
|
666
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
667
|
+
var localCheckins, createdOrUpdated, removed;
|
|
668
|
+
return __generator$1(this, function (_a) {
|
|
669
|
+
switch (_a.label) {
|
|
670
|
+
case 0:
|
|
671
|
+
// check if personal auth token is set
|
|
672
|
+
if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
|
|
673
|
+
throw new Error('personalAuthToken is required');
|
|
674
|
+
}
|
|
675
|
+
localCheckins = this.getLocalCheckins();
|
|
676
|
+
return [4 /*yield*/, this.createOrUpdate(localCheckins)];
|
|
677
|
+
case 1:
|
|
678
|
+
createdOrUpdated = _a.sent();
|
|
679
|
+
return [4 /*yield*/, this.remove(localCheckins)];
|
|
680
|
+
case 2:
|
|
681
|
+
removed = _a.sent();
|
|
682
|
+
return [2 /*return*/, __spreadArray(__spreadArray([], createdOrUpdated, true), removed, true)];
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
});
|
|
686
|
+
};
|
|
687
|
+
CheckinsManager.prototype.getLocalCheckins = function () {
|
|
688
|
+
// create checkins from configuration and validate them
|
|
689
|
+
var localCheckins = this.config.checkins.map(function (dto) {
|
|
690
|
+
var checkin = new checkin_1.Checkin(dto);
|
|
691
|
+
checkin.validate();
|
|
692
|
+
return checkin;
|
|
693
|
+
});
|
|
694
|
+
// validate that we have unique checkin names
|
|
695
|
+
// throw error if there are checkins with the same name and project id
|
|
696
|
+
var checkinNames = localCheckins.map(function (checkin) { return "".concat(checkin.projectId, "_").concat(checkin.name); });
|
|
697
|
+
var uniqueCheckinNames = new Set(checkinNames);
|
|
698
|
+
if (checkinNames.length !== uniqueCheckinNames.size) {
|
|
699
|
+
throw new Error('check-in names must be unique per project');
|
|
700
|
+
}
|
|
701
|
+
return localCheckins;
|
|
702
|
+
};
|
|
703
|
+
CheckinsManager.prototype.createOrUpdate = function (localCheckins) {
|
|
704
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
705
|
+
var results, _loop_1, this_1, _i, localCheckins_1, localCheckin;
|
|
706
|
+
return __generator$1(this, function (_a) {
|
|
707
|
+
switch (_a.label) {
|
|
708
|
+
case 0:
|
|
709
|
+
results = [];
|
|
710
|
+
_loop_1 = function (localCheckin) {
|
|
711
|
+
var projectCheckins, remoteCheckin, _b, _c, _d, _e;
|
|
712
|
+
return __generator$1(this, function (_f) {
|
|
713
|
+
switch (_f.label) {
|
|
714
|
+
case 0: return [4 /*yield*/, this_1.client.listForProject(localCheckin.projectId)];
|
|
715
|
+
case 1:
|
|
716
|
+
projectCheckins = _f.sent();
|
|
717
|
+
remoteCheckin = projectCheckins.find(function (checkin) {
|
|
718
|
+
return checkin.name === localCheckin.name;
|
|
719
|
+
});
|
|
720
|
+
if (!!remoteCheckin) return [3 /*break*/, 3];
|
|
721
|
+
_c = (_b = results).push;
|
|
722
|
+
return [4 /*yield*/, this_1.client.create(localCheckin)];
|
|
723
|
+
case 2:
|
|
724
|
+
_c.apply(_b, [_f.sent()]);
|
|
725
|
+
return [3 /*break*/, 6];
|
|
726
|
+
case 3:
|
|
727
|
+
if (!!localCheckin.isInSync(remoteCheckin)) return [3 /*break*/, 5];
|
|
728
|
+
localCheckin.id = remoteCheckin.id;
|
|
729
|
+
_e = (_d = results).push;
|
|
730
|
+
return [4 /*yield*/, this_1.client.update(localCheckin)];
|
|
731
|
+
case 4:
|
|
732
|
+
_e.apply(_d, [_f.sent()]);
|
|
733
|
+
return [3 /*break*/, 6];
|
|
734
|
+
case 5:
|
|
735
|
+
// no change - still need to add to results
|
|
736
|
+
results.push(remoteCheckin);
|
|
737
|
+
_f.label = 6;
|
|
738
|
+
case 6: return [2 /*return*/];
|
|
739
|
+
}
|
|
740
|
+
});
|
|
741
|
+
};
|
|
742
|
+
this_1 = this;
|
|
743
|
+
_i = 0, localCheckins_1 = localCheckins;
|
|
744
|
+
_a.label = 1;
|
|
745
|
+
case 1:
|
|
746
|
+
if (!(_i < localCheckins_1.length)) return [3 /*break*/, 4];
|
|
747
|
+
localCheckin = localCheckins_1[_i];
|
|
748
|
+
return [5 /*yield**/, _loop_1(localCheckin)];
|
|
749
|
+
case 2:
|
|
750
|
+
_a.sent();
|
|
751
|
+
_a.label = 3;
|
|
752
|
+
case 3:
|
|
753
|
+
_i++;
|
|
754
|
+
return [3 /*break*/, 1];
|
|
755
|
+
case 4: return [2 /*return*/, results];
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
});
|
|
759
|
+
};
|
|
760
|
+
CheckinsManager.prototype.remove = function (localCheckins) {
|
|
761
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
762
|
+
var projectIds, remoteCheckinsPerProject, allRemoteCheckins, checkinsToRemove;
|
|
763
|
+
var _this = this;
|
|
764
|
+
return __generator$1(this, function (_a) {
|
|
765
|
+
switch (_a.label) {
|
|
766
|
+
case 0:
|
|
767
|
+
projectIds = Array.from(new Set(localCheckins.map(function (checkin) { return checkin.projectId; })));
|
|
768
|
+
return [4 /*yield*/, Promise.all(projectIds.map(function (projectId) {
|
|
769
|
+
return _this.client.listForProject(projectId);
|
|
770
|
+
}))];
|
|
771
|
+
case 1:
|
|
772
|
+
remoteCheckinsPerProject = _a.sent();
|
|
773
|
+
allRemoteCheckins = remoteCheckinsPerProject.flat();
|
|
774
|
+
checkinsToRemove = allRemoteCheckins.filter(function (remoteCheckin) {
|
|
775
|
+
return !localCheckins.find(function (localCheckin) {
|
|
776
|
+
return localCheckin.name === remoteCheckin.name;
|
|
777
|
+
});
|
|
778
|
+
});
|
|
779
|
+
return [2 /*return*/, Promise.all(checkinsToRemove.map(function (checkin) { return __awaiter$1(_this, void 0, void 0, function () {
|
|
780
|
+
return __generator$1(this, function (_a) {
|
|
781
|
+
switch (_a.label) {
|
|
782
|
+
case 0: return [4 /*yield*/, this.client.remove(checkin)];
|
|
783
|
+
case 1:
|
|
784
|
+
_a.sent();
|
|
785
|
+
checkin.markAsDeleted();
|
|
786
|
+
return [2 /*return*/, checkin];
|
|
787
|
+
}
|
|
788
|
+
});
|
|
789
|
+
}); }))];
|
|
790
|
+
}
|
|
791
|
+
});
|
|
792
|
+
});
|
|
793
|
+
};
|
|
794
|
+
return CheckinsManager;
|
|
795
|
+
}());
|
|
796
|
+
checkinsManager.CheckinsManager = CheckinsManager$1;
|
|
797
|
+
|
|
798
|
+
var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
799
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
800
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
801
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
802
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
803
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
804
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
805
|
+
});
|
|
806
|
+
};
|
|
807
|
+
var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
|
|
808
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
809
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
810
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
811
|
+
function step(op) {
|
|
812
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
813
|
+
while (_) try {
|
|
814
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
815
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
816
|
+
switch (op[0]) {
|
|
817
|
+
case 0: case 1: t = op; break;
|
|
818
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
819
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
820
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
821
|
+
default:
|
|
822
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
823
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
824
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
825
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
826
|
+
if (t[2]) _.ops.pop();
|
|
827
|
+
_.trys.pop(); continue;
|
|
828
|
+
}
|
|
829
|
+
op = body.call(thisArg, _);
|
|
830
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
831
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
Object.defineProperty(checkinsSync, "__esModule", { value: true });
|
|
835
|
+
checkinsSync.syncCheckins = void 0;
|
|
836
|
+
var readConfigFromFileSystem = util.readConfigFromFileSystem;
|
|
837
|
+
var CheckinsManager = checkinsManager.CheckinsManager;
|
|
838
|
+
function syncCheckins$1() {
|
|
839
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
840
|
+
var config, checkinsManager, checkins, table;
|
|
841
|
+
return __generator(this, function (_a) {
|
|
842
|
+
switch (_a.label) {
|
|
843
|
+
case 0:
|
|
844
|
+
config = readConfigFromFileSystem();
|
|
845
|
+
if (!config) {
|
|
846
|
+
throw new Error('Could not find a Honeybadger configuration file.');
|
|
847
|
+
}
|
|
848
|
+
checkinsManager = new CheckinsManager(config);
|
|
849
|
+
return [4 /*yield*/, checkinsManager.sync()];
|
|
850
|
+
case 1:
|
|
851
|
+
checkins = _a.sent();
|
|
852
|
+
if (!checkins.length) {
|
|
853
|
+
console.log('No check-ins found to synchronize with Honeybadger.');
|
|
854
|
+
return [2 /*return*/];
|
|
855
|
+
}
|
|
856
|
+
table = checkins.map(function (c) {
|
|
857
|
+
return {
|
|
858
|
+
'Id': c.id,
|
|
859
|
+
'Name': c.name,
|
|
860
|
+
'Slug': c.slug,
|
|
861
|
+
'Schedule Type': c.scheduleType,
|
|
862
|
+
'Report Period': c.reportPeriod,
|
|
863
|
+
'Cron Schedule': c.cronSchedule,
|
|
864
|
+
'Cron Timezone': c.cronTimezone,
|
|
865
|
+
'Grace Period': c.gracePeriod,
|
|
866
|
+
'Status': c.isDeleted() ? '❌ Removed' : '✅ Synchronized'
|
|
867
|
+
};
|
|
868
|
+
});
|
|
869
|
+
console.log('Check-ins were synchronized with Honeybadger.');
|
|
870
|
+
console.table(table);
|
|
871
|
+
return [2 /*return*/];
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
checkinsSync.syncCheckins = syncCheckins$1;
|
|
877
|
+
|
|
878
|
+
var syncCheckins = checkinsSync.syncCheckins;
|
|
879
|
+
syncCheckins().catch(function (err) {
|
|
880
|
+
console.error(err);
|
|
881
|
+
process.exit(1);
|
|
882
|
+
});
|
|
883
|
+
|
|
884
|
+
exports["default"] = checkinsSyncExec;
|
|
885
|
+
//# sourceMappingURL=checkins-sync-exec.js.map
|