@honeybadger-io/js 6.7.1 → 6.8.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 +11 -0
- package/dist/browser/honeybadger.js +2 -2
- package/dist/browser/honeybadger.min.js +1 -1
- package/dist/server/check-ins-manager/check-in.d.ts +7 -4
- package/dist/server/check-ins-manager/client.d.ts +6 -8
- package/dist/server/check-ins-manager/types.d.ts +5 -8
- package/dist/server/check-ins-sync-exec.js +136 -123
- package/dist/server/check-ins-sync-exec.js.map +1 -1
- package/dist/server/honeybadger.d.ts +4 -2
- package/dist/server/honeybadger.js +121 -101
- package/dist/server/honeybadger.js.map +1 -1
- package/dist/server/util.d.ts +1 -1
- package/package.json +4 -4
|
@@ -5,8 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
|
|
6
6
|
var require$$0 = require('os');
|
|
7
7
|
var require$$1 = require('fs');
|
|
8
|
-
var require$$2 = require('
|
|
9
|
-
var require$$3 = require('
|
|
8
|
+
var require$$2 = require('path');
|
|
9
|
+
var require$$3 = require('util');
|
|
10
10
|
var require$$0$1 = require('@honeybadger-io/core');
|
|
11
11
|
var require$$1$1 = require('url');
|
|
12
12
|
var require$$3$1 = require('http');
|
|
@@ -74,8 +74,8 @@ Object.defineProperty(util, "__esModule", { value: true });
|
|
|
74
74
|
util.readConfigFromFileSystem = util.getSourceFile = util.getStats = util.fatallyLogAndExit = void 0;
|
|
75
75
|
var os_1 = __importDefault(require$$0__default["default"]);
|
|
76
76
|
var fs_1 = __importDefault(require$$1__default["default"]);
|
|
77
|
-
var
|
|
78
|
-
var
|
|
77
|
+
var path_1 = __importDefault(require$$2__default["default"]);
|
|
78
|
+
var util_1$1 = require$$3__default["default"];
|
|
79
79
|
var readFile = (0, util_1$1.promisify)(fs_1.default.readFile);
|
|
80
80
|
function fatallyLogAndExit(err) {
|
|
81
81
|
console.error('[Honeybadger] Exiting process due to uncaught exception');
|
|
@@ -162,21 +162,18 @@ function getSourceFile(path) {
|
|
|
162
162
|
}
|
|
163
163
|
util.getSourceFile = getSourceFile;
|
|
164
164
|
function readConfigFromFileSystem$1() {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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;
|
|
165
|
+
var options = ['honeybadger.config.js', 'honeybadger.config.ts'];
|
|
166
|
+
var config = null;
|
|
167
|
+
while (config === null && options.length > 0) {
|
|
168
|
+
var configPath = options.shift();
|
|
169
|
+
try {
|
|
170
|
+
config = require(path_1.default.join(process.cwd(), configPath));
|
|
171
|
+
}
|
|
172
|
+
catch (_e) { /* empty */ }
|
|
178
173
|
}
|
|
174
|
+
return config;
|
|
179
175
|
}
|
|
176
|
+
util.readConfigFromFileSystem = readConfigFromFileSystem$1;
|
|
180
177
|
|
|
181
178
|
var checkInsManager = {};
|
|
182
179
|
|
|
@@ -196,7 +193,6 @@ var CheckIn = /** @class */ (function () {
|
|
|
196
193
|
this.gracePeriod = props.gracePeriod;
|
|
197
194
|
this.cronSchedule = props.cronSchedule;
|
|
198
195
|
this.cronTimezone = props.cronTimezone;
|
|
199
|
-
this.projectId = props.projectId;
|
|
200
196
|
this.deleted = false;
|
|
201
197
|
}
|
|
202
198
|
CheckIn.prototype.isDeleted = function () {
|
|
@@ -206,39 +202,36 @@ var CheckIn = /** @class */ (function () {
|
|
|
206
202
|
this.deleted = true;
|
|
207
203
|
};
|
|
208
204
|
CheckIn.prototype.validate = function () {
|
|
209
|
-
if (!this.
|
|
210
|
-
throw new Error('
|
|
211
|
-
}
|
|
212
|
-
if (!this.name) {
|
|
213
|
-
throw new Error('name is required for each check-in');
|
|
205
|
+
if (!this.slug) {
|
|
206
|
+
throw new Error('slug is required for each check-in');
|
|
214
207
|
}
|
|
215
208
|
if (!this.scheduleType) {
|
|
216
209
|
throw new Error('scheduleType is required for each check-in');
|
|
217
210
|
}
|
|
218
211
|
if (!['simple', 'cron'].includes(this.scheduleType)) {
|
|
219
|
-
throw new Error("".concat(this.
|
|
212
|
+
throw new Error("".concat(this.slug, " [scheduleType] must be \"simple\" or \"cron\""));
|
|
220
213
|
}
|
|
221
214
|
if (this.scheduleType === 'simple' && !this.reportPeriod) {
|
|
222
|
-
throw new Error("".concat(this.
|
|
215
|
+
throw new Error("".concat(this.slug, " [reportPeriod] is required for simple check-ins"));
|
|
223
216
|
}
|
|
224
217
|
if (this.scheduleType === 'cron' && !this.cronSchedule) {
|
|
225
|
-
throw new Error("".concat(this.
|
|
218
|
+
throw new Error("".concat(this.slug, " [cronSchedule] is required for cron check-ins"));
|
|
226
219
|
}
|
|
227
220
|
};
|
|
228
221
|
CheckIn.prototype.asRequestPayload = function () {
|
|
229
|
-
var _a, _b
|
|
222
|
+
var _a, _b;
|
|
230
223
|
var payload = {
|
|
231
224
|
name: this.name,
|
|
232
225
|
schedule_type: this.scheduleType,
|
|
233
|
-
slug:
|
|
234
|
-
grace_period: (
|
|
226
|
+
slug: this.slug,
|
|
227
|
+
grace_period: (_a = this.gracePeriod) !== null && _a !== void 0 ? _a : '' // default is empty string
|
|
235
228
|
};
|
|
236
229
|
if (this.scheduleType === 'simple') {
|
|
237
230
|
payload.report_period = this.reportPeriod;
|
|
238
231
|
}
|
|
239
232
|
else {
|
|
240
233
|
payload.cron_schedule = this.cronSchedule;
|
|
241
|
-
payload.cron_timezone = (
|
|
234
|
+
payload.cron_timezone = (_b = this.cronTimezone) !== null && _b !== void 0 ? _b : ''; // default is empty string
|
|
242
235
|
}
|
|
243
236
|
return payload;
|
|
244
237
|
};
|
|
@@ -246,21 +239,25 @@ var CheckIn = /** @class */ (function () {
|
|
|
246
239
|
* Compares two check-ins, usually the one from the API and the one from the config file.
|
|
247
240
|
* If the one in the config file does not match the check-in from the API,
|
|
248
241
|
* then we issue an update request.
|
|
242
|
+
*
|
|
243
|
+
* `name`, `gracePeriod` and `cronTimezone` are optional fields that are automatically
|
|
244
|
+
* set to a value from the server if one is not provided,
|
|
245
|
+
* so we ignore their values if they are not set locally.
|
|
249
246
|
*/
|
|
250
247
|
CheckIn.prototype.isInSync = function (other) {
|
|
251
|
-
var
|
|
252
|
-
|
|
253
|
-
|
|
248
|
+
var ignoreNameCheck = this.name === undefined;
|
|
249
|
+
var ignoreGracePeriodCheck = this.gracePeriod === undefined;
|
|
250
|
+
var ignoreCronTimezoneCheck = this.cronTimezone === undefined;
|
|
251
|
+
return this.slug === other.slug
|
|
254
252
|
&& this.scheduleType === other.scheduleType
|
|
255
253
|
&& this.reportPeriod === other.reportPeriod
|
|
256
254
|
&& this.cronSchedule === other.cronSchedule
|
|
257
|
-
&& (
|
|
258
|
-
&& (
|
|
259
|
-
&& (
|
|
255
|
+
&& (ignoreNameCheck || this.name === other.name)
|
|
256
|
+
&& (ignoreGracePeriodCheck || this.gracePeriod === other.gracePeriod)
|
|
257
|
+
&& (ignoreCronTimezoneCheck || this.cronTimezone === other.cronTimezone);
|
|
260
258
|
};
|
|
261
|
-
CheckIn.fromResponsePayload = function (
|
|
259
|
+
CheckIn.fromResponsePayload = function (payload) {
|
|
262
260
|
return new CheckIn({
|
|
263
|
-
projectId: projectId,
|
|
264
261
|
id: payload.id,
|
|
265
262
|
name: payload.name,
|
|
266
263
|
slug: payload.slug,
|
|
@@ -320,17 +317,40 @@ var CheckInsClient = /** @class */ (function () {
|
|
|
320
317
|
this.transport = transport;
|
|
321
318
|
this.config = config;
|
|
322
319
|
this.logger = config.logger;
|
|
323
|
-
this.cache = {};
|
|
324
320
|
}
|
|
321
|
+
CheckInsClient.prototype.getProjectId = function (projectApiKey) {
|
|
322
|
+
var _a;
|
|
323
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
324
|
+
var response, data;
|
|
325
|
+
return __generator$2(this, function (_b) {
|
|
326
|
+
switch (_b.label) {
|
|
327
|
+
case 0:
|
|
328
|
+
if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
|
|
329
|
+
throw new Error('personalAuthToken is required');
|
|
330
|
+
}
|
|
331
|
+
return [4 /*yield*/, this.transport.send({
|
|
332
|
+
method: 'GET',
|
|
333
|
+
headers: this.getHeaders(),
|
|
334
|
+
endpoint: "".concat(this.BASE_URL, "/v2/project_keys/").concat(projectApiKey),
|
|
335
|
+
logger: this.logger,
|
|
336
|
+
})];
|
|
337
|
+
case 1:
|
|
338
|
+
response = _b.sent();
|
|
339
|
+
if (response.statusCode !== 200) {
|
|
340
|
+
throw new Error("Failed to fetch project[".concat(projectApiKey, "]: ").concat(this.getErrorMessage(response.body)));
|
|
341
|
+
}
|
|
342
|
+
data = JSON.parse(response.body);
|
|
343
|
+
return [2 /*return*/, (_a = data === null || data === void 0 ? void 0 : data.project) === null || _a === void 0 ? void 0 : _a.id];
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
};
|
|
325
348
|
CheckInsClient.prototype.listForProject = function (projectId) {
|
|
326
349
|
return __awaiter$2(this, void 0, void 0, function () {
|
|
327
|
-
var response, data
|
|
350
|
+
var response, data;
|
|
328
351
|
return __generator$2(this, function (_a) {
|
|
329
352
|
switch (_a.label) {
|
|
330
353
|
case 0:
|
|
331
|
-
if (this.cache[projectId]) {
|
|
332
|
-
return [2 /*return*/, this.cache[projectId]];
|
|
333
|
-
}
|
|
334
354
|
if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
|
|
335
355
|
throw new Error('personalAuthToken is required');
|
|
336
356
|
}
|
|
@@ -346,16 +366,14 @@ var CheckInsClient = /** @class */ (function () {
|
|
|
346
366
|
throw new Error("Failed to fetch checkins for project[".concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
|
|
347
367
|
}
|
|
348
368
|
data = JSON.parse(response.body);
|
|
349
|
-
|
|
350
|
-
this.cache[projectId] = checkIns;
|
|
351
|
-
return [2 /*return*/, checkIns];
|
|
369
|
+
return [2 /*return*/, data.results.map(function (checkin) { return check_in_1$1.CheckIn.fromResponsePayload(checkin); })];
|
|
352
370
|
}
|
|
353
371
|
});
|
|
354
372
|
});
|
|
355
373
|
};
|
|
356
374
|
CheckInsClient.prototype.get = function (projectId, checkInId) {
|
|
357
375
|
return __awaiter$2(this, void 0, void 0, function () {
|
|
358
|
-
var response, data
|
|
376
|
+
var response, data;
|
|
359
377
|
return __generator$2(this, function (_a) {
|
|
360
378
|
switch (_a.label) {
|
|
361
379
|
case 0:
|
|
@@ -374,16 +392,14 @@ var CheckInsClient = /** @class */ (function () {
|
|
|
374
392
|
throw new Error("Failed to fetch check-in[".concat(checkInId, "] for project[").concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
|
|
375
393
|
}
|
|
376
394
|
data = JSON.parse(response.body);
|
|
377
|
-
|
|
378
|
-
checkIn.projectId = projectId;
|
|
379
|
-
return [2 /*return*/, checkIn];
|
|
395
|
+
return [2 /*return*/, check_in_1$1.CheckIn.fromResponsePayload(data)];
|
|
380
396
|
}
|
|
381
397
|
});
|
|
382
398
|
});
|
|
383
399
|
};
|
|
384
|
-
CheckInsClient.prototype.create = function (checkIn) {
|
|
400
|
+
CheckInsClient.prototype.create = function (projectId, checkIn) {
|
|
385
401
|
return __awaiter$2(this, void 0, void 0, function () {
|
|
386
|
-
var response, data
|
|
402
|
+
var response, data;
|
|
387
403
|
return __generator$2(this, function (_a) {
|
|
388
404
|
switch (_a.label) {
|
|
389
405
|
case 0:
|
|
@@ -393,23 +409,21 @@ var CheckInsClient = /** @class */ (function () {
|
|
|
393
409
|
return [4 /*yield*/, this.transport.send({
|
|
394
410
|
method: 'POST',
|
|
395
411
|
headers: this.getHeaders(),
|
|
396
|
-
endpoint: "".concat(this.BASE_URL, "/v2/projects/").concat(
|
|
412
|
+
endpoint: "".concat(this.BASE_URL, "/v2/projects/").concat(projectId, "/check_ins"),
|
|
397
413
|
logger: this.logger,
|
|
398
414
|
}, { check_in: checkIn.asRequestPayload() })];
|
|
399
415
|
case 1:
|
|
400
416
|
response = _a.sent();
|
|
401
417
|
if (response.statusCode !== 201) {
|
|
402
|
-
throw new Error("Failed to create check-in[".concat(checkIn.
|
|
418
|
+
throw new Error("Failed to create check-in[".concat(checkIn.slug, "] for project[").concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
|
|
403
419
|
}
|
|
404
420
|
data = JSON.parse(response.body);
|
|
405
|
-
|
|
406
|
-
result.projectId = checkIn.projectId;
|
|
407
|
-
return [2 /*return*/, result];
|
|
421
|
+
return [2 /*return*/, check_in_1$1.CheckIn.fromResponsePayload(data)];
|
|
408
422
|
}
|
|
409
423
|
});
|
|
410
424
|
});
|
|
411
425
|
};
|
|
412
|
-
CheckInsClient.prototype.update = function (checkIn) {
|
|
426
|
+
CheckInsClient.prototype.update = function (projectId, checkIn) {
|
|
413
427
|
return __awaiter$2(this, void 0, void 0, function () {
|
|
414
428
|
var response;
|
|
415
429
|
return __generator$2(this, function (_a) {
|
|
@@ -421,20 +435,20 @@ var CheckInsClient = /** @class */ (function () {
|
|
|
421
435
|
return [4 /*yield*/, this.transport.send({
|
|
422
436
|
method: 'PUT',
|
|
423
437
|
headers: this.getHeaders(),
|
|
424
|
-
endpoint: "".concat(this.BASE_URL, "/v2/projects/").concat(
|
|
438
|
+
endpoint: "".concat(this.BASE_URL, "/v2/projects/").concat(projectId, "/check_ins/").concat(checkIn.id),
|
|
425
439
|
logger: this.logger,
|
|
426
440
|
}, { check_in: checkIn.asRequestPayload() })];
|
|
427
441
|
case 1:
|
|
428
442
|
response = _a.sent();
|
|
429
443
|
if (response.statusCode !== 204) {
|
|
430
|
-
throw new Error("Failed to update checkin[".concat(checkIn.
|
|
444
|
+
throw new Error("Failed to update checkin[".concat(checkIn.slug, "] for project[").concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
|
|
431
445
|
}
|
|
432
446
|
return [2 /*return*/, checkIn];
|
|
433
447
|
}
|
|
434
448
|
});
|
|
435
449
|
});
|
|
436
450
|
};
|
|
437
|
-
CheckInsClient.prototype.remove = function (checkIn) {
|
|
451
|
+
CheckInsClient.prototype.remove = function (projectId, checkIn) {
|
|
438
452
|
return __awaiter$2(this, void 0, void 0, function () {
|
|
439
453
|
var response;
|
|
440
454
|
return __generator$2(this, function (_a) {
|
|
@@ -446,13 +460,13 @@ var CheckInsClient = /** @class */ (function () {
|
|
|
446
460
|
return [4 /*yield*/, this.transport.send({
|
|
447
461
|
method: 'DELETE',
|
|
448
462
|
headers: this.getHeaders(),
|
|
449
|
-
endpoint: "".concat(this.BASE_URL, "/v2/projects/").concat(
|
|
463
|
+
endpoint: "".concat(this.BASE_URL, "/v2/projects/").concat(projectId, "/check_ins/").concat(checkIn.id),
|
|
450
464
|
logger: this.logger,
|
|
451
465
|
})];
|
|
452
466
|
case 1:
|
|
453
467
|
response = _a.sent();
|
|
454
468
|
if (response.statusCode !== 204) {
|
|
455
|
-
throw new Error("Failed to remove checkin[".concat(checkIn.
|
|
469
|
+
throw new Error("Failed to remove checkin[".concat(checkIn.slug, "] for project[").concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
|
|
456
470
|
}
|
|
457
471
|
return [2 /*return*/];
|
|
458
472
|
}
|
|
@@ -649,36 +663,48 @@ var transport_1 = transport;
|
|
|
649
663
|
var check_in_1 = checkIn;
|
|
650
664
|
var CheckInsManager$1 = /** @class */ (function () {
|
|
651
665
|
function CheckInsManager(config, client) {
|
|
652
|
-
var _a, _b, _c, _d;
|
|
666
|
+
var _a, _b, _c, _d, _e;
|
|
653
667
|
this.config = {
|
|
654
668
|
debug: (_a = config.debug) !== null && _a !== void 0 ? _a : false,
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
669
|
+
apiKey: (_b = config.apiKey) !== null && _b !== void 0 ? _b : undefined,
|
|
670
|
+
personalAuthToken: (_c = config.personalAuthToken) !== null && _c !== void 0 ? _c : undefined,
|
|
671
|
+
checkins: (_d = config.checkins) !== null && _d !== void 0 ? _d : [],
|
|
672
|
+
logger: (_e = config.logger) !== null && _e !== void 0 ? _e : console,
|
|
658
673
|
};
|
|
659
674
|
var transport = new transport_1.ServerTransport();
|
|
660
675
|
this.logger = core_1.Util.logger(this);
|
|
661
676
|
this.client = client !== null && client !== void 0 ? client : new client_1.CheckInsClient({
|
|
677
|
+
apiKey: config.apiKey,
|
|
662
678
|
personalAuthToken: config.personalAuthToken,
|
|
663
679
|
logger: this.logger
|
|
664
680
|
}, transport);
|
|
665
681
|
}
|
|
666
682
|
CheckInsManager.prototype.sync = function () {
|
|
667
683
|
return __awaiter$1(this, void 0, void 0, function () {
|
|
668
|
-
var localCheckIns, createdOrUpdated, removed;
|
|
684
|
+
var localCheckIns, projectId, remoteCheckIns, createdOrUpdated, removed;
|
|
669
685
|
return __generator$1(this, function (_a) {
|
|
670
686
|
switch (_a.label) {
|
|
671
687
|
case 0:
|
|
688
|
+
// check if api key is set
|
|
689
|
+
if (!this.config.apiKey || this.config.apiKey === '') {
|
|
690
|
+
throw new Error('apiKey is required');
|
|
691
|
+
}
|
|
672
692
|
// check if personal auth token is set
|
|
673
693
|
if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
|
|
674
694
|
throw new Error('personalAuthToken is required');
|
|
675
695
|
}
|
|
676
696
|
localCheckIns = this.getLocalCheckIns();
|
|
677
|
-
return [4 /*yield*/, this.
|
|
697
|
+
return [4 /*yield*/, this.client.getProjectId(this.config.apiKey)];
|
|
678
698
|
case 1:
|
|
679
|
-
|
|
680
|
-
return [4 /*yield*/, this.
|
|
699
|
+
projectId = _a.sent();
|
|
700
|
+
return [4 /*yield*/, this.client.listForProject(projectId)];
|
|
681
701
|
case 2:
|
|
702
|
+
remoteCheckIns = _a.sent();
|
|
703
|
+
return [4 /*yield*/, this.createOrUpdate(projectId, localCheckIns, remoteCheckIns)];
|
|
704
|
+
case 3:
|
|
705
|
+
createdOrUpdated = _a.sent();
|
|
706
|
+
return [4 /*yield*/, this.remove(projectId, localCheckIns, remoteCheckIns)];
|
|
707
|
+
case 4:
|
|
682
708
|
removed = _a.sent();
|
|
683
709
|
return [2 /*return*/, __spreadArray(__spreadArray([], createdOrUpdated, true), removed, true)];
|
|
684
710
|
}
|
|
@@ -692,16 +718,15 @@ var CheckInsManager$1 = /** @class */ (function () {
|
|
|
692
718
|
checkIn.validate();
|
|
693
719
|
return checkIn;
|
|
694
720
|
});
|
|
695
|
-
// validate that we have unique check-in
|
|
696
|
-
|
|
697
|
-
var
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
throw new Error('check-in names must be unique per project');
|
|
721
|
+
// validate that we have unique check-in slugs
|
|
722
|
+
var checkInSlugs = localCheckIns.map(function (checkIn) { return checkIn.slug; });
|
|
723
|
+
var uniqueCheckInSlugs = new Set(checkInSlugs);
|
|
724
|
+
if (checkInSlugs.length !== uniqueCheckInSlugs.size) {
|
|
725
|
+
throw new Error('check-in slugs must be unique');
|
|
701
726
|
}
|
|
702
727
|
return localCheckIns;
|
|
703
728
|
};
|
|
704
|
-
CheckInsManager.prototype.createOrUpdate = function (localCheckIns) {
|
|
729
|
+
CheckInsManager.prototype.createOrUpdate = function (projectId, localCheckIns, remoteCheckIns) {
|
|
705
730
|
return __awaiter$1(this, void 0, void 0, function () {
|
|
706
731
|
var results, _loop_1, this_1, _i, localCheckIns_1, localCheckIn;
|
|
707
732
|
return __generator$1(this, function (_a) {
|
|
@@ -709,34 +734,32 @@ var CheckInsManager$1 = /** @class */ (function () {
|
|
|
709
734
|
case 0:
|
|
710
735
|
results = [];
|
|
711
736
|
_loop_1 = function (localCheckIn) {
|
|
712
|
-
var
|
|
737
|
+
var remoteCheckIn, _b, _c, _d, _e;
|
|
713
738
|
return __generator$1(this, function (_f) {
|
|
714
739
|
switch (_f.label) {
|
|
715
|
-
case 0:
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
remoteCheckIn = projectCheckIns.find(function (checkIn) {
|
|
719
|
-
return checkIn.name === localCheckIn.name;
|
|
740
|
+
case 0:
|
|
741
|
+
remoteCheckIn = remoteCheckIns.find(function (checkIn) {
|
|
742
|
+
return checkIn.slug === localCheckIn.slug;
|
|
720
743
|
});
|
|
721
|
-
if (!!remoteCheckIn) return [3 /*break*/,
|
|
744
|
+
if (!!remoteCheckIn) return [3 /*break*/, 2];
|
|
722
745
|
_c = (_b = results).push;
|
|
723
|
-
return [4 /*yield*/, this_1.client.create(localCheckIn)];
|
|
724
|
-
case
|
|
746
|
+
return [4 /*yield*/, this_1.client.create(projectId, localCheckIn)];
|
|
747
|
+
case 1:
|
|
725
748
|
_c.apply(_b, [_f.sent()]);
|
|
726
|
-
return [3 /*break*/,
|
|
727
|
-
case
|
|
728
|
-
if (!!localCheckIn.isInSync(remoteCheckIn)) return [3 /*break*/,
|
|
749
|
+
return [3 /*break*/, 5];
|
|
750
|
+
case 2:
|
|
751
|
+
if (!!localCheckIn.isInSync(remoteCheckIn)) return [3 /*break*/, 4];
|
|
729
752
|
localCheckIn.id = remoteCheckIn.id;
|
|
730
753
|
_e = (_d = results).push;
|
|
731
|
-
return [4 /*yield*/, this_1.client.update(localCheckIn)];
|
|
732
|
-
case
|
|
754
|
+
return [4 /*yield*/, this_1.client.update(projectId, localCheckIn)];
|
|
755
|
+
case 3:
|
|
733
756
|
_e.apply(_d, [_f.sent()]);
|
|
734
|
-
return [3 /*break*/,
|
|
735
|
-
case
|
|
757
|
+
return [3 /*break*/, 5];
|
|
758
|
+
case 4:
|
|
736
759
|
// no change - still need to add to results
|
|
737
760
|
results.push(remoteCheckIn);
|
|
738
|
-
_f.label =
|
|
739
|
-
case
|
|
761
|
+
_f.label = 5;
|
|
762
|
+
case 5: return [2 /*return*/];
|
|
740
763
|
}
|
|
741
764
|
});
|
|
742
765
|
};
|
|
@@ -758,37 +781,27 @@ var CheckInsManager$1 = /** @class */ (function () {
|
|
|
758
781
|
});
|
|
759
782
|
});
|
|
760
783
|
};
|
|
761
|
-
CheckInsManager.prototype.remove = function (localCheckIns) {
|
|
784
|
+
CheckInsManager.prototype.remove = function (projectId, localCheckIns, remoteCheckIns) {
|
|
762
785
|
return __awaiter$1(this, void 0, void 0, function () {
|
|
763
|
-
var
|
|
786
|
+
var checkInsToRemove;
|
|
764
787
|
var _this = this;
|
|
765
788
|
return __generator$1(this, function (_a) {
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
789
|
+
checkInsToRemove = remoteCheckIns.filter(function (remoteCheckIn) {
|
|
790
|
+
return !localCheckIns.find(function (localCheckIn) {
|
|
791
|
+
return localCheckIn.slug === remoteCheckIn.slug;
|
|
792
|
+
});
|
|
793
|
+
});
|
|
794
|
+
return [2 /*return*/, Promise.all(checkInsToRemove.map(function (checkIn) { return __awaiter$1(_this, void 0, void 0, function () {
|
|
795
|
+
return __generator$1(this, function (_a) {
|
|
796
|
+
switch (_a.label) {
|
|
797
|
+
case 0: return [4 /*yield*/, this.client.remove(projectId, checkIn)];
|
|
798
|
+
case 1:
|
|
799
|
+
_a.sent();
|
|
800
|
+
checkIn.markAsDeleted();
|
|
801
|
+
return [2 /*return*/, checkIn];
|
|
802
|
+
}
|
|
779
803
|
});
|
|
780
|
-
|
|
781
|
-
return __generator$1(this, function (_a) {
|
|
782
|
-
switch (_a.label) {
|
|
783
|
-
case 0: return [4 /*yield*/, this.client.remove(checkIn)];
|
|
784
|
-
case 1:
|
|
785
|
-
_a.sent();
|
|
786
|
-
checkIn.markAsDeleted();
|
|
787
|
-
return [2 /*return*/, checkIn];
|
|
788
|
-
}
|
|
789
|
-
});
|
|
790
|
-
}); }))];
|
|
791
|
-
}
|
|
804
|
+
}); }))];
|
|
792
805
|
});
|
|
793
806
|
});
|
|
794
807
|
};
|