@honeybadger-io/js 6.11.3 → 6.12.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.
@@ -28,7 +28,7 @@ var checkInsSync = {};
28
28
 
29
29
  var util = {};
30
30
 
31
- var __awaiter$3 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
31
+ var __awaiter$2 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
32
32
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
33
33
  return new (P || (P = Promise))(function (resolve, reject) {
34
34
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -37,7 +37,7 @@ var __awaiter$3 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (this
37
37
  step((generator = generator.apply(thisArg, _arguments || [])).next());
38
38
  });
39
39
  };
40
- var __generator$3 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
40
+ var __generator$2 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
41
41
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
42
42
  return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
43
43
  function verb(n) { return function (v) { return step([n, v]); }; }
@@ -86,9 +86,9 @@ function fatallyLogAndExit(err, source) {
86
86
  }
87
87
  util.fatallyLogAndExit = fatallyLogAndExit;
88
88
  function getStats() {
89
- return __awaiter$3(this, void 0, void 0, function () {
89
+ return __awaiter$2(this, void 0, void 0, function () {
90
90
  var load, stats, fallback, memData, data, results;
91
- return __generator$3(this, function (_a) {
91
+ return __generator$2(this, function (_a) {
92
92
  switch (_a.label) {
93
93
  case 0:
94
94
  load = os_1.default.loadavg();
@@ -147,8 +147,8 @@ util.getStats = getStats;
147
147
  * @param path to source code
148
148
  */
149
149
  function getSourceFile(path) {
150
- return __awaiter$3(this, void 0, void 0, function () {
151
- return __generator$3(this, function (_a) {
150
+ return __awaiter$2(this, void 0, void 0, function () {
151
+ return __generator$2(this, function (_a) {
152
152
  switch (_a.label) {
153
153
  case 0:
154
154
  _a.trys.push([0, 2, , 3]);
@@ -274,7 +274,7 @@ var CheckIn = /** @class */ (function () {
274
274
  }());
275
275
  checkIn.CheckIn = CheckIn;
276
276
 
277
- var __awaiter$2 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
277
+ var __awaiter$1 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
278
278
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
279
279
  return new (P || (P = Promise))(function (resolve, reject) {
280
280
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -283,7 +283,7 @@ var __awaiter$2 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (this
283
283
  step((generator = generator.apply(thisArg, _arguments || [])).next());
284
284
  });
285
285
  };
286
- var __generator$2 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
286
+ var __generator$1 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
287
287
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
288
288
  return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
289
289
  function verb(n) { return function (v) { return step([n, v]); }; }
@@ -312,8 +312,8 @@ var __generator$2 = (commonjsGlobal && commonjsGlobal.__generator) || function (
312
312
  };
313
313
  Object.defineProperty(client, "__esModule", { value: true });
314
314
  client.CheckInsClient = void 0;
315
- var core_1$2 = require$$0__default$1["default"];
316
- var check_in_1$1 = checkIn;
315
+ var core_1$1 = require$$0__default$1["default"];
316
+ var check_in_1 = checkIn;
317
317
  var CheckInsClient = /** @class */ (function () {
318
318
  function CheckInsClient(config, transport) {
319
319
  this.transport = transport;
@@ -322,9 +322,9 @@ var CheckInsClient = /** @class */ (function () {
322
322
  }
323
323
  CheckInsClient.prototype.getProjectId = function (projectApiKey) {
324
324
  var _a;
325
- return __awaiter$2(this, void 0, void 0, function () {
325
+ return __awaiter$1(this, void 0, void 0, function () {
326
326
  var response, data;
327
- return __generator$2(this, function (_b) {
327
+ return __generator$1(this, function (_b) {
328
328
  switch (_b.label) {
329
329
  case 0:
330
330
  if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
@@ -333,7 +333,7 @@ var CheckInsClient = /** @class */ (function () {
333
333
  return [4 /*yield*/, this.transport.send({
334
334
  method: 'GET',
335
335
  headers: this.getHeaders(),
336
- endpoint: core_1$2.Util.endpoint(this.config.appEndpoint, "v2/project_keys/".concat(projectApiKey)),
336
+ endpoint: core_1$1.Util.endpoint(this.config.appEndpoint, "v2/project_keys/".concat(projectApiKey)),
337
337
  logger: this.logger,
338
338
  })];
339
339
  case 1:
@@ -348,9 +348,9 @@ var CheckInsClient = /** @class */ (function () {
348
348
  });
349
349
  };
350
350
  CheckInsClient.prototype.listForProject = function (projectId) {
351
- return __awaiter$2(this, void 0, void 0, function () {
351
+ return __awaiter$1(this, void 0, void 0, function () {
352
352
  var response, data;
353
- return __generator$2(this, function (_a) {
353
+ return __generator$1(this, function (_a) {
354
354
  switch (_a.label) {
355
355
  case 0:
356
356
  if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
@@ -359,7 +359,7 @@ var CheckInsClient = /** @class */ (function () {
359
359
  return [4 /*yield*/, this.transport.send({
360
360
  method: 'GET',
361
361
  headers: this.getHeaders(),
362
- endpoint: core_1$2.Util.endpoint(this.config.appEndpoint, "v2/projects/".concat(projectId, "/check_ins")),
362
+ endpoint: core_1$1.Util.endpoint(this.config.appEndpoint, "v2/projects/".concat(projectId, "/check_ins")),
363
363
  logger: this.logger,
364
364
  })];
365
365
  case 1:
@@ -368,15 +368,15 @@ var CheckInsClient = /** @class */ (function () {
368
368
  throw new Error("Failed to fetch checkins for project[".concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
369
369
  }
370
370
  data = JSON.parse(response.body);
371
- return [2 /*return*/, data.results.map(function (checkin) { return check_in_1$1.CheckIn.fromResponsePayload(checkin); })];
371
+ return [2 /*return*/, data.results.map(function (checkin) { return check_in_1.CheckIn.fromResponsePayload(checkin); })];
372
372
  }
373
373
  });
374
374
  });
375
375
  };
376
376
  CheckInsClient.prototype.get = function (projectId, checkInId) {
377
- return __awaiter$2(this, void 0, void 0, function () {
377
+ return __awaiter$1(this, void 0, void 0, function () {
378
378
  var response, data;
379
- return __generator$2(this, function (_a) {
379
+ return __generator$1(this, function (_a) {
380
380
  switch (_a.label) {
381
381
  case 0:
382
382
  if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
@@ -385,7 +385,7 @@ var CheckInsClient = /** @class */ (function () {
385
385
  return [4 /*yield*/, this.transport.send({
386
386
  method: 'GET',
387
387
  headers: this.getHeaders(),
388
- endpoint: core_1$2.Util.endpoint(this.config.appEndpoint, "v2/projects/".concat(projectId, "/check_ins/").concat(checkInId)),
388
+ endpoint: core_1$1.Util.endpoint(this.config.appEndpoint, "v2/projects/".concat(projectId, "/check_ins/").concat(checkInId)),
389
389
  logger: this.logger,
390
390
  })];
391
391
  case 1:
@@ -394,15 +394,15 @@ var CheckInsClient = /** @class */ (function () {
394
394
  throw new Error("Failed to fetch check-in[".concat(checkInId, "] for project[").concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
395
395
  }
396
396
  data = JSON.parse(response.body);
397
- return [2 /*return*/, check_in_1$1.CheckIn.fromResponsePayload(data)];
397
+ return [2 /*return*/, check_in_1.CheckIn.fromResponsePayload(data)];
398
398
  }
399
399
  });
400
400
  });
401
401
  };
402
402
  CheckInsClient.prototype.create = function (projectId, checkIn) {
403
- return __awaiter$2(this, void 0, void 0, function () {
403
+ return __awaiter$1(this, void 0, void 0, function () {
404
404
  var response, data;
405
- return __generator$2(this, function (_a) {
405
+ return __generator$1(this, function (_a) {
406
406
  switch (_a.label) {
407
407
  case 0:
408
408
  if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
@@ -411,7 +411,7 @@ var CheckInsClient = /** @class */ (function () {
411
411
  return [4 /*yield*/, this.transport.send({
412
412
  method: 'POST',
413
413
  headers: this.getHeaders(),
414
- endpoint: core_1$2.Util.endpoint(this.config.appEndpoint, "v2/projects/".concat(projectId, "/check_ins")),
414
+ endpoint: core_1$1.Util.endpoint(this.config.appEndpoint, "v2/projects/".concat(projectId, "/check_ins")),
415
415
  logger: this.logger,
416
416
  }, { check_in: checkIn.asRequestPayload() })];
417
417
  case 1:
@@ -420,15 +420,15 @@ var CheckInsClient = /** @class */ (function () {
420
420
  throw new Error("Failed to create check-in[".concat(checkIn.slug, "] for project[").concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
421
421
  }
422
422
  data = JSON.parse(response.body);
423
- return [2 /*return*/, check_in_1$1.CheckIn.fromResponsePayload(data)];
423
+ return [2 /*return*/, check_in_1.CheckIn.fromResponsePayload(data)];
424
424
  }
425
425
  });
426
426
  });
427
427
  };
428
428
  CheckInsClient.prototype.update = function (projectId, checkIn) {
429
- return __awaiter$2(this, void 0, void 0, function () {
429
+ return __awaiter$1(this, void 0, void 0, function () {
430
430
  var response;
431
- return __generator$2(this, function (_a) {
431
+ return __generator$1(this, function (_a) {
432
432
  switch (_a.label) {
433
433
  case 0:
434
434
  if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
@@ -437,7 +437,7 @@ var CheckInsClient = /** @class */ (function () {
437
437
  return [4 /*yield*/, this.transport.send({
438
438
  method: 'PUT',
439
439
  headers: this.getHeaders(),
440
- endpoint: core_1$2.Util.endpoint(this.config.appEndpoint, "v2/projects/".concat(projectId, "/check_ins/").concat(checkIn.id)),
440
+ endpoint: core_1$1.Util.endpoint(this.config.appEndpoint, "v2/projects/".concat(projectId, "/check_ins/").concat(checkIn.id)),
441
441
  logger: this.logger,
442
442
  }, { check_in: checkIn.asRequestPayload() })];
443
443
  case 1:
@@ -451,9 +451,9 @@ var CheckInsClient = /** @class */ (function () {
451
451
  });
452
452
  };
453
453
  CheckInsClient.prototype.remove = function (projectId, checkIn) {
454
- return __awaiter$2(this, void 0, void 0, function () {
454
+ return __awaiter$1(this, void 0, void 0, function () {
455
455
  var response;
456
- return __generator$2(this, function (_a) {
456
+ return __generator$1(this, function (_a) {
457
457
  switch (_a.label) {
458
458
  case 0:
459
459
  if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
@@ -462,7 +462,7 @@ var CheckInsClient = /** @class */ (function () {
462
462
  return [4 /*yield*/, this.transport.send({
463
463
  method: 'DELETE',
464
464
  headers: this.getHeaders(),
465
- endpoint: core_1$2.Util.endpoint(this.config.appEndpoint, "v2/projects/".concat(projectId, "/check_ins/").concat(checkIn.id)),
465
+ endpoint: core_1$1.Util.endpoint(this.config.appEndpoint, "v2/projects/".concat(projectId, "/check_ins/").concat(checkIn.id)),
466
466
  logger: this.logger,
467
467
  })];
468
468
  case 1:
@@ -536,12 +536,12 @@ var __importStar = (commonjsGlobal && commonjsGlobal.__importStar) || function (
536
536
  };
537
537
  Object.defineProperty(transport, "__esModule", { value: true });
538
538
  transport.ServerTransport = void 0;
539
- var core_1$1 = require$$0__default$1["default"];
539
+ var core_1 = require$$0__default$1["default"];
540
540
  var url_1 = require$$1__default$1["default"];
541
541
  var util_1 = util;
542
542
  var http = __importStar(require$$3__default$1["default"]);
543
543
  var https = __importStar(require$$4__default["default"]);
544
- var sanitize = core_1$1.Util.sanitize;
544
+ var sanitize = core_1.Util.sanitize;
545
545
  var ServerTransport = /** @class */ (function () {
546
546
  function ServerTransport(headers) {
547
547
  if (headers === void 0) { headers = {}; }
@@ -611,210 +611,217 @@ var ServerTransport = /** @class */ (function () {
611
611
  }());
612
612
  transport.ServerTransport = ServerTransport;
613
613
 
614
- var __awaiter$1 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
615
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
616
- return new (P || (P = Promise))(function (resolve, reject) {
617
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
618
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
619
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
620
- step((generator = generator.apply(thisArg, _arguments || [])).next());
621
- });
622
- };
623
- var __generator$1 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
624
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
625
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
626
- function verb(n) { return function (v) { return step([n, v]); }; }
627
- function step(op) {
628
- if (f) throw new TypeError("Generator is already executing.");
629
- while (_) try {
630
- 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;
631
- if (y = 0, t) op = [op[0] & 2, t.value];
632
- switch (op[0]) {
633
- case 0: case 1: t = op; break;
634
- case 4: _.label++; return { value: op[1], done: false };
635
- case 5: _.label++; y = op[1]; op = [0]; continue;
636
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
637
- default:
638
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
639
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
640
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
641
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
642
- if (t[2]) _.ops.pop();
643
- _.trys.pop(); continue;
644
- }
645
- op = body.call(thisArg, _);
646
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
647
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
648
- }
649
- };
650
- var __spreadArray = (commonjsGlobal && commonjsGlobal.__spreadArray) || function (to, from, pack) {
651
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
652
- if (ar || !(i in from)) {
653
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
654
- ar[i] = from[i];
655
- }
656
- }
657
- return to.concat(ar || Array.prototype.slice.call(from));
658
- };
659
- Object.defineProperty(checkInsManager, "__esModule", { value: true });
660
- checkInsManager.CheckInsManager = void 0;
661
- var core_1 = require$$0__default$1["default"];
662
- var client_1 = client;
663
- var transport_1 = transport;
664
- var check_in_1 = checkIn;
665
- var CheckInsManager$1 = /** @class */ (function () {
666
- function CheckInsManager(config, client) {
667
- var _a, _b, _c, _d, _e, _f;
668
- this.config = {
669
- appEndpoint: (_a = config.appEndpoint) !== null && _a !== void 0 ? _a : core_1.Defaults.CONFIG.appEndpoint,
670
- debug: (_b = config.debug) !== null && _b !== void 0 ? _b : false,
671
- apiKey: (_c = config.apiKey) !== null && _c !== void 0 ? _c : undefined,
672
- personalAuthToken: (_d = config.personalAuthToken) !== null && _d !== void 0 ? _d : undefined,
673
- checkins: (_e = config.checkins) !== null && _e !== void 0 ? _e : [],
674
- logger: (_f = config.logger) !== null && _f !== void 0 ? _f : console,
675
- };
676
- var transport = new transport_1.ServerTransport();
677
- this.logger = core_1.Util.logger(this);
678
- this.client = client !== null && client !== void 0 ? client : new client_1.CheckInsClient({
679
- appEndpoint: config.appEndpoint,
680
- apiKey: config.apiKey,
681
- personalAuthToken: config.personalAuthToken,
682
- logger: this.logger
683
- }, transport);
684
- }
685
- CheckInsManager.prototype.sync = function () {
686
- return __awaiter$1(this, void 0, void 0, function () {
687
- var localCheckIns, projectId, remoteCheckIns, createdOrUpdated, removed;
688
- return __generator$1(this, function (_a) {
689
- switch (_a.label) {
690
- case 0:
691
- // check if app endpoint is set
692
- if (!this.config.appEndpoint || this.config.appEndpoint === '') {
693
- throw new Error('appEndpoint is required');
694
- }
695
- // check if api key is set
696
- if (!this.config.apiKey || this.config.apiKey === '') {
697
- throw new Error('apiKey is required');
698
- }
699
- // check if personal auth token is set
700
- if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
701
- throw new Error('personalAuthToken is required');
702
- }
703
- localCheckIns = this.getLocalCheckIns();
704
- return [4 /*yield*/, this.client.getProjectId(this.config.apiKey)];
705
- case 1:
706
- projectId = _a.sent();
707
- return [4 /*yield*/, this.client.listForProject(projectId)];
708
- case 2:
709
- remoteCheckIns = _a.sent();
710
- return [4 /*yield*/, this.createOrUpdate(projectId, localCheckIns, remoteCheckIns)];
711
- case 3:
712
- createdOrUpdated = _a.sent();
713
- return [4 /*yield*/, this.remove(projectId, localCheckIns, remoteCheckIns)];
714
- case 4:
715
- removed = _a.sent();
716
- return [2 /*return*/, __spreadArray(__spreadArray([], createdOrUpdated, true), removed, true)];
717
- }
718
- });
719
- });
720
- };
721
- CheckInsManager.prototype.getLocalCheckIns = function () {
722
- // create check-ins from configuration and validate them
723
- var localCheckIns = this.config.checkins.map(function (dto) {
724
- var checkIn = new check_in_1.CheckIn(dto);
725
- checkIn.validate();
726
- return checkIn;
727
- });
728
- // validate that we have unique check-in slugs
729
- var checkInSlugs = localCheckIns.map(function (checkIn) { return checkIn.slug; });
730
- var uniqueCheckInSlugs = new Set(checkInSlugs);
731
- if (checkInSlugs.length !== uniqueCheckInSlugs.size) {
732
- throw new Error('check-in slugs must be unique');
733
- }
734
- return localCheckIns;
735
- };
736
- CheckInsManager.prototype.createOrUpdate = function (projectId, localCheckIns, remoteCheckIns) {
737
- return __awaiter$1(this, void 0, void 0, function () {
738
- var results, _loop_1, this_1, _i, localCheckIns_1, localCheckIn;
739
- return __generator$1(this, function (_a) {
740
- switch (_a.label) {
741
- case 0:
742
- results = [];
743
- _loop_1 = function (localCheckIn) {
744
- var remoteCheckIn, _b, _c, _d, _e;
745
- return __generator$1(this, function (_f) {
746
- switch (_f.label) {
747
- case 0:
748
- remoteCheckIn = remoteCheckIns.find(function (checkIn) {
749
- return checkIn.slug === localCheckIn.slug;
750
- });
751
- if (!!remoteCheckIn) return [3 /*break*/, 2];
752
- _c = (_b = results).push;
753
- return [4 /*yield*/, this_1.client.create(projectId, localCheckIn)];
754
- case 1:
755
- _c.apply(_b, [_f.sent()]);
756
- return [3 /*break*/, 5];
757
- case 2:
758
- if (!!localCheckIn.isInSync(remoteCheckIn)) return [3 /*break*/, 4];
759
- localCheckIn.id = remoteCheckIn.id;
760
- _e = (_d = results).push;
761
- return [4 /*yield*/, this_1.client.update(projectId, localCheckIn)];
762
- case 3:
763
- _e.apply(_d, [_f.sent()]);
764
- return [3 /*break*/, 5];
765
- case 4:
766
- // no change - still need to add to results
767
- results.push(remoteCheckIn);
768
- _f.label = 5;
769
- case 5: return [2 /*return*/];
770
- }
771
- });
772
- };
773
- this_1 = this;
774
- _i = 0, localCheckIns_1 = localCheckIns;
775
- _a.label = 1;
776
- case 1:
777
- if (!(_i < localCheckIns_1.length)) return [3 /*break*/, 4];
778
- localCheckIn = localCheckIns_1[_i];
779
- return [5 /*yield**/, _loop_1(localCheckIn)];
780
- case 2:
781
- _a.sent();
782
- _a.label = 3;
783
- case 3:
784
- _i++;
785
- return [3 /*break*/, 1];
786
- case 4: return [2 /*return*/, results];
787
- }
788
- });
789
- });
790
- };
791
- CheckInsManager.prototype.remove = function (projectId, localCheckIns, remoteCheckIns) {
792
- return __awaiter$1(this, void 0, void 0, function () {
793
- var checkInsToRemove;
794
- var _this = this;
795
- return __generator$1(this, function (_a) {
796
- checkInsToRemove = remoteCheckIns.filter(function (remoteCheckIn) {
797
- return !localCheckIns.find(function (localCheckIn) {
798
- return localCheckIn.slug === remoteCheckIn.slug;
799
- });
800
- });
801
- return [2 /*return*/, Promise.all(checkInsToRemove.map(function (checkIn) { return __awaiter$1(_this, void 0, void 0, function () {
802
- return __generator$1(this, function (_a) {
803
- switch (_a.label) {
804
- case 0: return [4 /*yield*/, this.client.remove(projectId, checkIn)];
805
- case 1:
806
- _a.sent();
807
- checkIn.markAsDeleted();
808
- return [2 /*return*/, checkIn];
809
- }
810
- });
811
- }); }))];
812
- });
813
- });
814
- };
815
- return CheckInsManager;
816
- }());
817
- checkInsManager.CheckInsManager = CheckInsManager$1;
614
+ (function (exports) {
615
+ var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
616
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
617
+ return new (P || (P = Promise))(function (resolve, reject) {
618
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
619
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
620
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
621
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
622
+ });
623
+ };
624
+ var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
625
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
626
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
627
+ function verb(n) { return function (v) { return step([n, v]); }; }
628
+ function step(op) {
629
+ if (f) throw new TypeError("Generator is already executing.");
630
+ while (_) try {
631
+ 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;
632
+ if (y = 0, t) op = [op[0] & 2, t.value];
633
+ switch (op[0]) {
634
+ case 0: case 1: t = op; break;
635
+ case 4: _.label++; return { value: op[1], done: false };
636
+ case 5: _.label++; y = op[1]; op = [0]; continue;
637
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
638
+ default:
639
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
640
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
641
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
642
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
643
+ if (t[2]) _.ops.pop();
644
+ _.trys.pop(); continue;
645
+ }
646
+ op = body.call(thisArg, _);
647
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
648
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
649
+ }
650
+ };
651
+ var __spreadArray = (commonjsGlobal && commonjsGlobal.__spreadArray) || function (to, from, pack) {
652
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
653
+ if (ar || !(i in from)) {
654
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
655
+ ar[i] = from[i];
656
+ }
657
+ }
658
+ return to.concat(ar || Array.prototype.slice.call(from));
659
+ };
660
+ Object.defineProperty(exports, "__esModule", { value: true });
661
+ exports.CheckInsManager = exports.CheckIn = exports.CheckInsClient = void 0;
662
+ var core_1 = require$$0__default$1["default"];
663
+ var client_1 = client;
664
+ var transport_1 = transport;
665
+ var check_in_1 = checkIn;
666
+ var client_2 = client;
667
+ Object.defineProperty(exports, "CheckInsClient", { enumerable: true, get: function () { return client_2.CheckInsClient; } });
668
+ var check_in_2 = checkIn;
669
+ Object.defineProperty(exports, "CheckIn", { enumerable: true, get: function () { return check_in_2.CheckIn; } });
670
+ var CheckInsManager = /** @class */ (function () {
671
+ function CheckInsManager(config, client) {
672
+ var _a, _b, _c, _d, _e, _f;
673
+ this.config = {
674
+ appEndpoint: (_a = config.appEndpoint) !== null && _a !== void 0 ? _a : core_1.Defaults.CONFIG.appEndpoint,
675
+ debug: (_b = config.debug) !== null && _b !== void 0 ? _b : false,
676
+ apiKey: (_c = config.apiKey) !== null && _c !== void 0 ? _c : undefined,
677
+ personalAuthToken: (_d = config.personalAuthToken) !== null && _d !== void 0 ? _d : undefined,
678
+ checkins: (_e = config.checkins) !== null && _e !== void 0 ? _e : [],
679
+ logger: (_f = config.logger) !== null && _f !== void 0 ? _f : console,
680
+ };
681
+ var transport = new transport_1.ServerTransport();
682
+ this.logger = core_1.Util.logger(this);
683
+ this.client = client !== null && client !== void 0 ? client : new client_1.CheckInsClient({
684
+ appEndpoint: config.appEndpoint,
685
+ apiKey: config.apiKey,
686
+ personalAuthToken: config.personalAuthToken,
687
+ logger: this.logger
688
+ }, transport);
689
+ }
690
+ CheckInsManager.prototype.sync = function () {
691
+ return __awaiter(this, void 0, void 0, function () {
692
+ var localCheckIns, projectId, remoteCheckIns, createdOrUpdated, removed;
693
+ return __generator(this, function (_a) {
694
+ switch (_a.label) {
695
+ case 0:
696
+ // check if app endpoint is set
697
+ if (!this.config.appEndpoint || this.config.appEndpoint === '') {
698
+ throw new Error('appEndpoint is required');
699
+ }
700
+ // check if api key is set
701
+ if (!this.config.apiKey || this.config.apiKey === '') {
702
+ throw new Error('apiKey is required');
703
+ }
704
+ // check if personal auth token is set
705
+ if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
706
+ throw new Error('personalAuthToken is required');
707
+ }
708
+ localCheckIns = this.getLocalCheckIns();
709
+ return [4 /*yield*/, this.client.getProjectId(this.config.apiKey)];
710
+ case 1:
711
+ projectId = _a.sent();
712
+ return [4 /*yield*/, this.client.listForProject(projectId)];
713
+ case 2:
714
+ remoteCheckIns = _a.sent();
715
+ return [4 /*yield*/, this.createOrUpdate(projectId, localCheckIns, remoteCheckIns)];
716
+ case 3:
717
+ createdOrUpdated = _a.sent();
718
+ return [4 /*yield*/, this.remove(projectId, localCheckIns, remoteCheckIns)];
719
+ case 4:
720
+ removed = _a.sent();
721
+ return [2 /*return*/, __spreadArray(__spreadArray([], createdOrUpdated, true), removed, true)];
722
+ }
723
+ });
724
+ });
725
+ };
726
+ CheckInsManager.prototype.getLocalCheckIns = function () {
727
+ // create check-ins from configuration and validate them
728
+ var localCheckIns = this.config.checkins.map(function (dto) {
729
+ var checkIn = new check_in_1.CheckIn(dto);
730
+ checkIn.validate();
731
+ return checkIn;
732
+ });
733
+ // validate that we have unique check-in slugs
734
+ var checkInSlugs = localCheckIns.map(function (checkIn) { return checkIn.slug; });
735
+ var uniqueCheckInSlugs = new Set(checkInSlugs);
736
+ if (checkInSlugs.length !== uniqueCheckInSlugs.size) {
737
+ throw new Error('check-in slugs must be unique');
738
+ }
739
+ return localCheckIns;
740
+ };
741
+ CheckInsManager.prototype.createOrUpdate = function (projectId, localCheckIns, remoteCheckIns) {
742
+ return __awaiter(this, void 0, void 0, function () {
743
+ var results, _loop_1, this_1, _i, localCheckIns_1, localCheckIn;
744
+ return __generator(this, function (_a) {
745
+ switch (_a.label) {
746
+ case 0:
747
+ results = [];
748
+ _loop_1 = function (localCheckIn) {
749
+ var remoteCheckIn, _b, _c, _d, _e;
750
+ return __generator(this, function (_f) {
751
+ switch (_f.label) {
752
+ case 0:
753
+ remoteCheckIn = remoteCheckIns.find(function (checkIn) {
754
+ return checkIn.slug === localCheckIn.slug;
755
+ });
756
+ if (!!remoteCheckIn) return [3 /*break*/, 2];
757
+ _c = (_b = results).push;
758
+ return [4 /*yield*/, this_1.client.create(projectId, localCheckIn)];
759
+ case 1:
760
+ _c.apply(_b, [_f.sent()]);
761
+ return [3 /*break*/, 5];
762
+ case 2:
763
+ if (!!localCheckIn.isInSync(remoteCheckIn)) return [3 /*break*/, 4];
764
+ localCheckIn.id = remoteCheckIn.id;
765
+ _e = (_d = results).push;
766
+ return [4 /*yield*/, this_1.client.update(projectId, localCheckIn)];
767
+ case 3:
768
+ _e.apply(_d, [_f.sent()]);
769
+ return [3 /*break*/, 5];
770
+ case 4:
771
+ // no change - still need to add to results
772
+ results.push(remoteCheckIn);
773
+ _f.label = 5;
774
+ case 5: return [2 /*return*/];
775
+ }
776
+ });
777
+ };
778
+ this_1 = this;
779
+ _i = 0, localCheckIns_1 = localCheckIns;
780
+ _a.label = 1;
781
+ case 1:
782
+ if (!(_i < localCheckIns_1.length)) return [3 /*break*/, 4];
783
+ localCheckIn = localCheckIns_1[_i];
784
+ return [5 /*yield**/, _loop_1(localCheckIn)];
785
+ case 2:
786
+ _a.sent();
787
+ _a.label = 3;
788
+ case 3:
789
+ _i++;
790
+ return [3 /*break*/, 1];
791
+ case 4: return [2 /*return*/, results];
792
+ }
793
+ });
794
+ });
795
+ };
796
+ CheckInsManager.prototype.remove = function (projectId, localCheckIns, remoteCheckIns) {
797
+ return __awaiter(this, void 0, void 0, function () {
798
+ var checkInsToRemove;
799
+ var _this = this;
800
+ return __generator(this, function (_a) {
801
+ checkInsToRemove = remoteCheckIns.filter(function (remoteCheckIn) {
802
+ return !localCheckIns.find(function (localCheckIn) {
803
+ return localCheckIn.slug === remoteCheckIn.slug;
804
+ });
805
+ });
806
+ return [2 /*return*/, Promise.all(checkInsToRemove.map(function (checkIn) { return __awaiter(_this, void 0, void 0, function () {
807
+ return __generator(this, function (_a) {
808
+ switch (_a.label) {
809
+ case 0: return [4 /*yield*/, this.client.remove(projectId, checkIn)];
810
+ case 1:
811
+ _a.sent();
812
+ checkIn.markAsDeleted();
813
+ return [2 /*return*/, checkIn];
814
+ }
815
+ });
816
+ }); }))];
817
+ });
818
+ });
819
+ };
820
+ return CheckInsManager;
821
+ }());
822
+ exports.CheckInsManager = CheckInsManager;
823
+
824
+ } (checkInsManager));
818
825
 
819
826
  var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
820
827
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }