@honeybadger-io/js 6.12.0 → 6.12.2

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.
@@ -994,7 +994,7 @@ var __assign$2 = (commonjsGlobal && commonjsGlobal.__assign) || function () {
994
994
  };
995
995
  return __assign$2.apply(this, arguments);
996
996
  };
997
- var __awaiter$3 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
997
+ var __awaiter$4 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
998
998
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
999
999
  return new (P || (P = Promise))(function (resolve, reject) {
1000
1000
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1003,7 +1003,7 @@ var __awaiter$3 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (this
1003
1003
  step((generator = generator.apply(thisArg, _arguments || [])).next());
1004
1004
  });
1005
1005
  };
1006
- var __generator$3 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
1006
+ var __generator$4 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
1007
1007
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
1008
1008
  return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
1009
1009
  function verb(n) { return function (v) { return step([n, v]); }; }
@@ -1082,9 +1082,9 @@ var ThrottledEventsLogger = /** @class */ (function () {
1082
1082
  });
1083
1083
  };
1084
1084
  ThrottledEventsLogger.prototype.send = function () {
1085
- return __awaiter$3(this, void 0, void 0, function () {
1085
+ return __awaiter$4(this, void 0, void 0, function () {
1086
1086
  var eventsData, data;
1087
- return __generator$3(this, function (_a) {
1087
+ return __generator$4(this, function (_a) {
1088
1088
  if (this.queue.length === 0) {
1089
1089
  return [2 /*return*/];
1090
1090
  }
@@ -1096,9 +1096,9 @@ var ThrottledEventsLogger = /** @class */ (function () {
1096
1096
  });
1097
1097
  };
1098
1098
  ThrottledEventsLogger.prototype.makeHttpRequest = function (data) {
1099
- return __awaiter$3(this, void 0, void 0, function () {
1099
+ return __awaiter$4(this, void 0, void 0, function () {
1100
1100
  var _this = this;
1101
- return __generator$3(this, function (_a) {
1101
+ return __generator$4(this, function (_a) {
1102
1102
  return [2 /*return*/, this.transport
1103
1103
  .send({
1104
1104
  headers: {
@@ -1158,7 +1158,7 @@ var __assign$1 = (commonjsGlobal && commonjsGlobal.__assign) || function () {
1158
1158
  };
1159
1159
  return __assign$1.apply(this, arguments);
1160
1160
  };
1161
- var __awaiter$2 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
1161
+ var __awaiter$3 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
1162
1162
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1163
1163
  return new (P || (P = Promise))(function (resolve, reject) {
1164
1164
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1167,7 +1167,7 @@ var __awaiter$2 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (this
1167
1167
  step((generator = generator.apply(thisArg, _arguments || [])).next());
1168
1168
  });
1169
1169
  };
1170
- var __generator$2 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
1170
+ var __generator$3 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
1171
1171
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
1172
1172
  return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
1173
1173
  function verb(n) { return function (v) { return step([n, v]); }; }
@@ -1214,7 +1214,7 @@ var Client = /** @class */ (function () {
1214
1214
  this.__notifier = {
1215
1215
  name: '@honeybadger-io/core',
1216
1216
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/core',
1217
- version: '6.12.0'
1217
+ version: '6.12.2'
1218
1218
  };
1219
1219
  this.config = __assign$1(__assign$1({}, defaults_1.CONFIG), opts);
1220
1220
  this.__initStore();
@@ -1549,9 +1549,9 @@ var Client = /** @class */ (function () {
1549
1549
  notice.__breadcrumbs = [];
1550
1550
  }
1551
1551
  return (0, util_1$5.getSourceForBacktrace)(originalBacktrace, this.__getSourceFileHandler)
1552
- .then(function (sourcePerTrace) { return __awaiter$2(_this, void 0, void 0, function () {
1552
+ .then(function (sourcePerTrace) { return __awaiter$3(_this, void 0, void 0, function () {
1553
1553
  var payload;
1554
- return __generator$2(this, function (_a) {
1554
+ return __generator$3(this, function (_a) {
1555
1555
  sourcePerTrace.forEach(function (source, index) {
1556
1556
  notice.backtrace[index].source = source;
1557
1557
  });
@@ -1645,7 +1645,7 @@ Object.defineProperty(types, "__esModule", { value: true });
1645
1645
 
1646
1646
  var util = {};
1647
1647
 
1648
- var __awaiter$1 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
1648
+ var __awaiter$2 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
1649
1649
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1650
1650
  return new (P || (P = Promise))(function (resolve, reject) {
1651
1651
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1654,7 +1654,7 @@ var __awaiter$1 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (this
1654
1654
  step((generator = generator.apply(thisArg, _arguments || [])).next());
1655
1655
  });
1656
1656
  };
1657
- var __generator$1 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
1657
+ var __generator$2 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
1658
1658
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
1659
1659
  return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
1660
1660
  function verb(n) { return function (v) { return step([n, v]); }; }
@@ -1703,9 +1703,9 @@ function fatallyLogAndExit(err, source) {
1703
1703
  }
1704
1704
  util.fatallyLogAndExit = fatallyLogAndExit;
1705
1705
  function getStats() {
1706
- return __awaiter$1(this, void 0, void 0, function () {
1706
+ return __awaiter$2(this, void 0, void 0, function () {
1707
1707
  var load, stats, fallback, memData, data, results;
1708
- return __generator$1(this, function (_a) {
1708
+ return __generator$2(this, function (_a) {
1709
1709
  switch (_a.label) {
1710
1710
  case 0:
1711
1711
  load = os_1.default.loadavg();
@@ -1764,8 +1764,8 @@ util.getStats = getStats;
1764
1764
  * @param path to source code
1765
1765
  */
1766
1766
  function getSourceFile(path) {
1767
- return __awaiter$1(this, void 0, void 0, function () {
1768
- return __generator$1(this, function (_a) {
1767
+ return __awaiter$2(this, void 0, void 0, function () {
1768
+ return __generator$2(this, function (_a) {
1769
1769
  switch (_a.label) {
1770
1770
  case 0:
1771
1771
  _a.trys.push([0, 2, , 3]);
@@ -2086,7 +2086,7 @@ var shutdown_plugin = {};
2086
2086
 
2087
2087
  var shutdown_monitor = {};
2088
2088
 
2089
- var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
2089
+ var __awaiter$1 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
2090
2090
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2091
2091
  return new (P || (P = Promise))(function (resolve, reject) {
2092
2092
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2095,7 +2095,7 @@ var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisAr
2095
2095
  step((generator = generator.apply(thisArg, _arguments || [])).next());
2096
2096
  });
2097
2097
  };
2098
- var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
2098
+ var __generator$1 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
2099
2099
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
2100
2100
  return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
2101
2101
  function verb(n) { return function (v) { return step([n, v]); }; }
@@ -2135,8 +2135,8 @@ var ShutdownMonitor = /** @class */ (function () {
2135
2135
  ShutdownMonitor.prototype.makeListener = function () {
2136
2136
  var _this = this;
2137
2137
  // noinspection UnnecessaryLocalVariableJS
2138
- var honeybadgerShutdownListener = function (signal) { return __awaiter(_this, void 0, void 0, function () {
2139
- return __generator(this, function (_a) {
2138
+ var honeybadgerShutdownListener = function (signal) { return __awaiter$1(_this, void 0, void 0, function () {
2139
+ return __generator$1(this, function (_a) {
2140
2140
  switch (_a.label) {
2141
2141
  case 0:
2142
2142
  if (this.__isReporting || !this.__client) {
@@ -2293,12 +2293,12 @@ var __importStar = (commonjsGlobal && commonjsGlobal.__importStar) || function (
2293
2293
  };
2294
2294
  Object.defineProperty(transport, "__esModule", { value: true });
2295
2295
  transport.ServerTransport = void 0;
2296
- var core_1$1 = src;
2296
+ var core_1$2 = src;
2297
2297
  var url_1 = require$$0__default$1["default"];
2298
2298
  var util_1 = util;
2299
2299
  var http = __importStar(require$$3__default$1["default"]);
2300
2300
  var https = __importStar(require$$4__default["default"]);
2301
- var sanitize = core_1$1.Util.sanitize;
2301
+ var sanitize = core_1$2.Util.sanitize;
2302
2302
  var ServerTransport = /** @class */ (function () {
2303
2303
  function ServerTransport(headers) {
2304
2304
  if (headers === void 0) { headers = {}; }
@@ -2445,7 +2445,7 @@ async_store.AsyncStore = AsyncStore;
2445
2445
 
2446
2446
  Object.defineProperty(stacked_store, "__esModule", { value: true });
2447
2447
  stacked_store.StackedStore = void 0;
2448
- var core_1 = src;
2448
+ var core_1$1 = src;
2449
2449
  var async_store_1 = async_store;
2450
2450
  /**
2451
2451
  * A store that's really a "stack" of stores (async and global)
@@ -2458,7 +2458,7 @@ var StackedStore = /** @class */ (function () {
2458
2458
  function StackedStore(breadcrumbsLimit) {
2459
2459
  this.contents = { context: {}, breadcrumbs: [] };
2460
2460
  this.asyncStore = async_store_1.AsyncStore.create(this.contents, breadcrumbsLimit);
2461
- this.globalStore = core_1.GlobalStore.create(this.contents, breadcrumbsLimit);
2461
+ this.globalStore = core_1$1.GlobalStore.create(this.contents, breadcrumbsLimit);
2462
2462
  }
2463
2463
  StackedStore.prototype.__activeStore = function () {
2464
2464
  var _a;
@@ -2593,11 +2593,236 @@ function requireCheckIn () {
2593
2593
  return checkIn;
2594
2594
  }
2595
2595
 
2596
- var hasRequiredClient;
2596
+ var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
2597
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2598
+ return new (P || (P = Promise))(function (resolve, reject) {
2599
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
2600
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
2601
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
2602
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
2603
+ });
2604
+ };
2605
+ var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
2606
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
2607
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
2608
+ function verb(n) { return function (v) { return step([n, v]); }; }
2609
+ function step(op) {
2610
+ if (f) throw new TypeError("Generator is already executing.");
2611
+ while (_) try {
2612
+ 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;
2613
+ if (y = 0, t) op = [op[0] & 2, t.value];
2614
+ switch (op[0]) {
2615
+ case 0: case 1: t = op; break;
2616
+ case 4: _.label++; return { value: op[1], done: false };
2617
+ case 5: _.label++; y = op[1]; op = [0]; continue;
2618
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
2619
+ default:
2620
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
2621
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
2622
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
2623
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
2624
+ if (t[2]) _.ops.pop();
2625
+ _.trys.pop(); continue;
2626
+ }
2627
+ op = body.call(thisArg, _);
2628
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
2629
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
2630
+ }
2631
+ };
2632
+ Object.defineProperty(client, "__esModule", { value: true });
2633
+ client.CheckInsClient = void 0;
2634
+ var core_1 = src;
2635
+ var check_in_1 = requireCheckIn();
2636
+ var CheckInsClient = /** @class */ (function () {
2637
+ function CheckInsClient(config, transport) {
2638
+ this.transport = transport;
2639
+ this.config = config;
2640
+ this.logger = config.logger;
2641
+ }
2642
+ CheckInsClient.prototype.configure = function (config) {
2643
+ this.config = config;
2644
+ };
2645
+ CheckInsClient.prototype.getProjectId = function (projectApiKey) {
2646
+ var _a;
2647
+ return __awaiter(this, void 0, void 0, function () {
2648
+ var response, data;
2649
+ return __generator(this, function (_b) {
2650
+ switch (_b.label) {
2651
+ case 0:
2652
+ if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
2653
+ throw new Error('personalAuthToken is required');
2654
+ }
2655
+ return [4 /*yield*/, this.transport.send({
2656
+ method: 'GET',
2657
+ headers: this.getHeaders(),
2658
+ endpoint: core_1.Util.endpoint(this.config.appEndpoint, "v2/project_keys/".concat(projectApiKey)),
2659
+ logger: this.logger,
2660
+ })];
2661
+ case 1:
2662
+ response = _b.sent();
2663
+ if (response.statusCode !== 200) {
2664
+ throw new Error("Failed to fetch project[".concat(projectApiKey, "]: ").concat(this.getErrorMessage(response.body)));
2665
+ }
2666
+ data = JSON.parse(response.body);
2667
+ return [2 /*return*/, (_a = data === null || data === void 0 ? void 0 : data.project) === null || _a === void 0 ? void 0 : _a.id];
2668
+ }
2669
+ });
2670
+ });
2671
+ };
2672
+ CheckInsClient.prototype.listForProject = function (projectId) {
2673
+ return __awaiter(this, void 0, void 0, function () {
2674
+ var response, data;
2675
+ return __generator(this, function (_a) {
2676
+ switch (_a.label) {
2677
+ case 0:
2678
+ if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
2679
+ throw new Error('personalAuthToken is required');
2680
+ }
2681
+ return [4 /*yield*/, this.transport.send({
2682
+ method: 'GET',
2683
+ headers: this.getHeaders(),
2684
+ endpoint: core_1.Util.endpoint(this.config.appEndpoint, "v2/projects/".concat(projectId, "/check_ins")),
2685
+ logger: this.logger,
2686
+ })];
2687
+ case 1:
2688
+ response = _a.sent();
2689
+ if (response.statusCode !== 200) {
2690
+ throw new Error("Failed to fetch checkins for project[".concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
2691
+ }
2692
+ data = JSON.parse(response.body);
2693
+ return [2 /*return*/, data.results.map(function (checkin) { return check_in_1.CheckIn.fromResponsePayload(checkin); })];
2694
+ }
2695
+ });
2696
+ });
2697
+ };
2698
+ CheckInsClient.prototype.get = function (projectId, checkInId) {
2699
+ return __awaiter(this, void 0, void 0, function () {
2700
+ var response, data;
2701
+ return __generator(this, function (_a) {
2702
+ switch (_a.label) {
2703
+ case 0:
2704
+ if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
2705
+ throw new Error('personalAuthToken is required');
2706
+ }
2707
+ return [4 /*yield*/, this.transport.send({
2708
+ method: 'GET',
2709
+ headers: this.getHeaders(),
2710
+ endpoint: core_1.Util.endpoint(this.config.appEndpoint, "v2/projects/".concat(projectId, "/check_ins/").concat(checkInId)),
2711
+ logger: this.logger,
2712
+ })];
2713
+ case 1:
2714
+ response = _a.sent();
2715
+ if (response.statusCode !== 200) {
2716
+ throw new Error("Failed to fetch check-in[".concat(checkInId, "] for project[").concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
2717
+ }
2718
+ data = JSON.parse(response.body);
2719
+ return [2 /*return*/, check_in_1.CheckIn.fromResponsePayload(data)];
2720
+ }
2721
+ });
2722
+ });
2723
+ };
2724
+ CheckInsClient.prototype.create = function (projectId, checkIn) {
2725
+ return __awaiter(this, void 0, void 0, function () {
2726
+ var checkInTyped, response, data;
2727
+ return __generator(this, function (_a) {
2728
+ switch (_a.label) {
2729
+ case 0:
2730
+ if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
2731
+ throw new Error('personalAuthToken is required');
2732
+ }
2733
+ checkInTyped = checkIn instanceof check_in_1.CheckIn ? checkIn : new check_in_1.CheckIn(checkIn);
2734
+ return [4 /*yield*/, this.transport.send({
2735
+ method: 'POST',
2736
+ headers: this.getHeaders(),
2737
+ endpoint: core_1.Util.endpoint(this.config.appEndpoint, "v2/projects/".concat(projectId, "/check_ins")),
2738
+ logger: this.logger,
2739
+ }, { check_in: checkInTyped.asRequestPayload() })];
2740
+ case 1:
2741
+ response = _a.sent();
2742
+ if (response.statusCode !== 201) {
2743
+ throw new Error("Failed to create check-in[".concat(checkIn.slug, "] for project[").concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
2744
+ }
2745
+ data = JSON.parse(response.body);
2746
+ return [2 /*return*/, check_in_1.CheckIn.fromResponsePayload(data)];
2747
+ }
2748
+ });
2749
+ });
2750
+ };
2751
+ CheckInsClient.prototype.update = function (projectId, checkIn) {
2752
+ return __awaiter(this, void 0, void 0, function () {
2753
+ var checkInTyped, response;
2754
+ return __generator(this, function (_a) {
2755
+ switch (_a.label) {
2756
+ case 0:
2757
+ if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
2758
+ throw new Error('personalAuthToken is required');
2759
+ }
2760
+ checkInTyped = checkIn instanceof check_in_1.CheckIn ? checkIn : new check_in_1.CheckIn(checkIn);
2761
+ return [4 /*yield*/, this.transport.send({
2762
+ method: 'PUT',
2763
+ headers: this.getHeaders(),
2764
+ endpoint: core_1.Util.endpoint(this.config.appEndpoint, "v2/projects/".concat(projectId, "/check_ins/").concat(checkIn.id)),
2765
+ logger: this.logger,
2766
+ }, { check_in: checkInTyped.asRequestPayload() })];
2767
+ case 1:
2768
+ response = _a.sent();
2769
+ if (response.statusCode !== 204) {
2770
+ throw new Error("Failed to update checkin[".concat(checkIn.slug, "] for project[").concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
2771
+ }
2772
+ return [2 /*return*/, checkInTyped];
2773
+ }
2774
+ });
2775
+ });
2776
+ };
2777
+ CheckInsClient.prototype.remove = function (projectId, checkIn) {
2778
+ return __awaiter(this, void 0, void 0, function () {
2779
+ var response;
2780
+ return __generator(this, function (_a) {
2781
+ switch (_a.label) {
2782
+ case 0:
2783
+ if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
2784
+ throw new Error('personalAuthToken is required');
2785
+ }
2786
+ return [4 /*yield*/, this.transport.send({
2787
+ method: 'DELETE',
2788
+ headers: this.getHeaders(),
2789
+ endpoint: core_1.Util.endpoint(this.config.appEndpoint, "v2/projects/".concat(projectId, "/check_ins/").concat(checkIn.id)),
2790
+ logger: this.logger,
2791
+ })];
2792
+ case 1:
2793
+ response = _a.sent();
2794
+ if (response.statusCode !== 204) {
2795
+ throw new Error("Failed to remove checkin[".concat(checkIn.slug, "] for project[").concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
2796
+ }
2797
+ return [2 /*return*/];
2798
+ }
2799
+ });
2800
+ });
2801
+ };
2802
+ CheckInsClient.prototype.getHeaders = function () {
2803
+ return {
2804
+ 'Authorization': "Basic ".concat(Buffer.from("".concat(this.config.personalAuthToken, ":")).toString('base64')),
2805
+ 'Content-Type': 'application/json'
2806
+ };
2807
+ };
2808
+ CheckInsClient.prototype.getErrorMessage = function (responseBody) {
2809
+ var _a;
2810
+ if (!responseBody) {
2811
+ return '';
2812
+ }
2813
+ try {
2814
+ var jsonBody = JSON.parse(responseBody);
2815
+ return (_a = jsonBody.errors) !== null && _a !== void 0 ? _a : '';
2816
+ }
2817
+ catch (e) {
2818
+ return responseBody;
2819
+ }
2820
+ };
2821
+ return CheckInsClient;
2822
+ }());
2823
+ client.CheckInsClient = CheckInsClient;
2597
2824
 
2598
- function requireClient () {
2599
- if (hasRequiredClient) return client;
2600
- hasRequiredClient = 1;
2825
+ (function (exports) {
2601
2826
  var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
2602
2827
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2603
2828
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -2634,415 +2859,180 @@ function requireClient () {
2634
2859
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
2635
2860
  }
2636
2861
  };
2637
- Object.defineProperty(client, "__esModule", { value: true });
2638
- client.CheckInsClient = void 0;
2862
+ var __spreadArray = (commonjsGlobal && commonjsGlobal.__spreadArray) || function (to, from, pack) {
2863
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
2864
+ if (ar || !(i in from)) {
2865
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
2866
+ ar[i] = from[i];
2867
+ }
2868
+ }
2869
+ return to.concat(ar || Array.prototype.slice.call(from));
2870
+ };
2871
+ Object.defineProperty(exports, "__esModule", { value: true });
2872
+ exports.CheckInsManager = exports.CheckIn = exports.CheckInsClient = void 0;
2639
2873
  var core_1 = src;
2874
+ var client_1 = client;
2875
+ var transport_1 = transport;
2640
2876
  var check_in_1 = requireCheckIn();
2641
- var CheckInsClient = /** @class */ (function () {
2642
- function CheckInsClient(config, transport) {
2643
- this.transport = transport;
2644
- this.config = config;
2645
- this.logger = config.logger;
2877
+ var client_2 = client;
2878
+ Object.defineProperty(exports, "CheckInsClient", { enumerable: true, get: function () { return client_2.CheckInsClient; } });
2879
+ var check_in_2 = requireCheckIn();
2880
+ Object.defineProperty(exports, "CheckIn", { enumerable: true, get: function () { return check_in_2.CheckIn; } });
2881
+ var CheckInsManager = /** @class */ (function () {
2882
+ function CheckInsManager(config, client) {
2883
+ var _a, _b, _c, _d, _e, _f;
2884
+ this.config = {
2885
+ appEndpoint: (_a = config.appEndpoint) !== null && _a !== void 0 ? _a : core_1.Defaults.CONFIG.appEndpoint,
2886
+ debug: (_b = config.debug) !== null && _b !== void 0 ? _b : false,
2887
+ apiKey: (_c = config.apiKey) !== null && _c !== void 0 ? _c : undefined,
2888
+ personalAuthToken: (_d = config.personalAuthToken) !== null && _d !== void 0 ? _d : undefined,
2889
+ checkins: (_e = config.checkins) !== null && _e !== void 0 ? _e : [],
2890
+ logger: (_f = config.logger) !== null && _f !== void 0 ? _f : console,
2891
+ };
2892
+ var transport = new transport_1.ServerTransport();
2893
+ this.logger = core_1.Util.logger(this);
2894
+ this.client = client !== null && client !== void 0 ? client : new client_1.CheckInsClient({
2895
+ appEndpoint: config.appEndpoint,
2896
+ apiKey: config.apiKey,
2897
+ personalAuthToken: config.personalAuthToken,
2898
+ logger: this.logger
2899
+ }, transport);
2646
2900
  }
2647
- CheckInsClient.prototype.getProjectId = function (projectApiKey) {
2648
- var _a;
2649
- return __awaiter(this, void 0, void 0, function () {
2650
- var response, data;
2651
- return __generator(this, function (_b) {
2652
- switch (_b.label) {
2653
- case 0:
2654
- if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
2655
- throw new Error('personalAuthToken is required');
2656
- }
2657
- return [4 /*yield*/, this.transport.send({
2658
- method: 'GET',
2659
- headers: this.getHeaders(),
2660
- endpoint: core_1.Util.endpoint(this.config.appEndpoint, "v2/project_keys/".concat(projectApiKey)),
2661
- logger: this.logger,
2662
- })];
2663
- case 1:
2664
- response = _b.sent();
2665
- if (response.statusCode !== 200) {
2666
- throw new Error("Failed to fetch project[".concat(projectApiKey, "]: ").concat(this.getErrorMessage(response.body)));
2667
- }
2668
- data = JSON.parse(response.body);
2669
- return [2 /*return*/, (_a = data === null || data === void 0 ? void 0 : data.project) === null || _a === void 0 ? void 0 : _a.id];
2670
- }
2671
- });
2672
- });
2673
- };
2674
- CheckInsClient.prototype.listForProject = function (projectId) {
2901
+ CheckInsManager.prototype.sync = function () {
2675
2902
  return __awaiter(this, void 0, void 0, function () {
2676
- var response, data;
2903
+ var localCheckIns, projectId, remoteCheckIns, createdOrUpdated, removed;
2677
2904
  return __generator(this, function (_a) {
2678
2905
  switch (_a.label) {
2679
2906
  case 0:
2680
- if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
2681
- throw new Error('personalAuthToken is required');
2907
+ // check if app endpoint is set
2908
+ if (!this.config.appEndpoint || this.config.appEndpoint === '') {
2909
+ throw new Error('appEndpoint is required');
2682
2910
  }
2683
- return [4 /*yield*/, this.transport.send({
2684
- method: 'GET',
2685
- headers: this.getHeaders(),
2686
- endpoint: core_1.Util.endpoint(this.config.appEndpoint, "v2/projects/".concat(projectId, "/check_ins")),
2687
- logger: this.logger,
2688
- })];
2689
- case 1:
2690
- response = _a.sent();
2691
- if (response.statusCode !== 200) {
2692
- throw new Error("Failed to fetch checkins for project[".concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
2911
+ // check if api key is set
2912
+ if (!this.config.apiKey || this.config.apiKey === '') {
2913
+ throw new Error('apiKey is required');
2693
2914
  }
2694
- data = JSON.parse(response.body);
2695
- return [2 /*return*/, data.results.map(function (checkin) { return check_in_1.CheckIn.fromResponsePayload(checkin); })];
2696
- }
2697
- });
2698
- });
2699
- };
2700
- CheckInsClient.prototype.get = function (projectId, checkInId) {
2701
- return __awaiter(this, void 0, void 0, function () {
2702
- var response, data;
2703
- return __generator(this, function (_a) {
2704
- switch (_a.label) {
2705
- case 0:
2915
+ // check if personal auth token is set
2706
2916
  if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
2707
2917
  throw new Error('personalAuthToken is required');
2708
2918
  }
2709
- return [4 /*yield*/, this.transport.send({
2710
- method: 'GET',
2711
- headers: this.getHeaders(),
2712
- endpoint: core_1.Util.endpoint(this.config.appEndpoint, "v2/projects/".concat(projectId, "/check_ins/").concat(checkInId)),
2713
- logger: this.logger,
2714
- })];
2919
+ localCheckIns = this.getLocalCheckIns();
2920
+ return [4 /*yield*/, this.client.getProjectId(this.config.apiKey)];
2715
2921
  case 1:
2716
- response = _a.sent();
2717
- if (response.statusCode !== 200) {
2718
- throw new Error("Failed to fetch check-in[".concat(checkInId, "] for project[").concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
2719
- }
2720
- data = JSON.parse(response.body);
2721
- return [2 /*return*/, check_in_1.CheckIn.fromResponsePayload(data)];
2922
+ projectId = _a.sent();
2923
+ return [4 /*yield*/, this.client.listForProject(projectId)];
2924
+ case 2:
2925
+ remoteCheckIns = _a.sent();
2926
+ return [4 /*yield*/, this.createOrUpdate(projectId, localCheckIns, remoteCheckIns)];
2927
+ case 3:
2928
+ createdOrUpdated = _a.sent();
2929
+ return [4 /*yield*/, this.remove(projectId, localCheckIns, remoteCheckIns)];
2930
+ case 4:
2931
+ removed = _a.sent();
2932
+ return [2 /*return*/, __spreadArray(__spreadArray([], createdOrUpdated, true), removed, true)];
2722
2933
  }
2723
2934
  });
2724
2935
  });
2725
2936
  };
2726
- CheckInsClient.prototype.create = function (projectId, checkIn) {
2727
- return __awaiter(this, void 0, void 0, function () {
2728
- var response, data;
2729
- return __generator(this, function (_a) {
2730
- switch (_a.label) {
2731
- case 0:
2732
- if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
2733
- throw new Error('personalAuthToken is required');
2734
- }
2735
- return [4 /*yield*/, this.transport.send({
2736
- method: 'POST',
2737
- headers: this.getHeaders(),
2738
- endpoint: core_1.Util.endpoint(this.config.appEndpoint, "v2/projects/".concat(projectId, "/check_ins")),
2739
- logger: this.logger,
2740
- }, { check_in: checkIn.asRequestPayload() })];
2741
- case 1:
2742
- response = _a.sent();
2743
- if (response.statusCode !== 201) {
2744
- throw new Error("Failed to create check-in[".concat(checkIn.slug, "] for project[").concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
2745
- }
2746
- data = JSON.parse(response.body);
2747
- return [2 /*return*/, check_in_1.CheckIn.fromResponsePayload(data)];
2748
- }
2749
- });
2937
+ CheckInsManager.prototype.getLocalCheckIns = function () {
2938
+ // create check-ins from configuration and validate them
2939
+ var localCheckIns = this.config.checkins.map(function (dto) {
2940
+ var checkIn = new check_in_1.CheckIn(dto);
2941
+ checkIn.validate();
2942
+ return checkIn;
2750
2943
  });
2944
+ // validate that we have unique check-in slugs
2945
+ var checkInSlugs = localCheckIns.map(function (checkIn) { return checkIn.slug; });
2946
+ var uniqueCheckInSlugs = new Set(checkInSlugs);
2947
+ if (checkInSlugs.length !== uniqueCheckInSlugs.size) {
2948
+ throw new Error('check-in slugs must be unique');
2949
+ }
2950
+ return localCheckIns;
2751
2951
  };
2752
- CheckInsClient.prototype.update = function (projectId, checkIn) {
2952
+ CheckInsManager.prototype.createOrUpdate = function (projectId, localCheckIns, remoteCheckIns) {
2753
2953
  return __awaiter(this, void 0, void 0, function () {
2754
- var response;
2954
+ var results, _loop_1, this_1, _i, localCheckIns_1, localCheckIn;
2755
2955
  return __generator(this, function (_a) {
2756
2956
  switch (_a.label) {
2757
2957
  case 0:
2758
- if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
2759
- throw new Error('personalAuthToken is required');
2760
- }
2761
- return [4 /*yield*/, this.transport.send({
2762
- method: 'PUT',
2763
- headers: this.getHeaders(),
2764
- endpoint: core_1.Util.endpoint(this.config.appEndpoint, "v2/projects/".concat(projectId, "/check_ins/").concat(checkIn.id)),
2765
- logger: this.logger,
2766
- }, { check_in: checkIn.asRequestPayload() })];
2958
+ results = [];
2959
+ _loop_1 = function (localCheckIn) {
2960
+ var remoteCheckIn, _b, _c, _d, _e;
2961
+ return __generator(this, function (_f) {
2962
+ switch (_f.label) {
2963
+ case 0:
2964
+ remoteCheckIn = remoteCheckIns.find(function (checkIn) {
2965
+ return checkIn.slug === localCheckIn.slug;
2966
+ });
2967
+ if (!!remoteCheckIn) return [3 /*break*/, 2];
2968
+ _c = (_b = results).push;
2969
+ return [4 /*yield*/, this_1.client.create(projectId, localCheckIn)];
2970
+ case 1:
2971
+ _c.apply(_b, [_f.sent()]);
2972
+ return [3 /*break*/, 5];
2973
+ case 2:
2974
+ if (!!localCheckIn.isInSync(remoteCheckIn)) return [3 /*break*/, 4];
2975
+ localCheckIn.id = remoteCheckIn.id;
2976
+ _e = (_d = results).push;
2977
+ return [4 /*yield*/, this_1.client.update(projectId, localCheckIn)];
2978
+ case 3:
2979
+ _e.apply(_d, [_f.sent()]);
2980
+ return [3 /*break*/, 5];
2981
+ case 4:
2982
+ // no change - still need to add to results
2983
+ results.push(remoteCheckIn);
2984
+ _f.label = 5;
2985
+ case 5: return [2 /*return*/];
2986
+ }
2987
+ });
2988
+ };
2989
+ this_1 = this;
2990
+ _i = 0, localCheckIns_1 = localCheckIns;
2991
+ _a.label = 1;
2767
2992
  case 1:
2768
- response = _a.sent();
2769
- if (response.statusCode !== 204) {
2770
- throw new Error("Failed to update checkin[".concat(checkIn.slug, "] for project[").concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
2771
- }
2772
- return [2 /*return*/, checkIn];
2993
+ if (!(_i < localCheckIns_1.length)) return [3 /*break*/, 4];
2994
+ localCheckIn = localCheckIns_1[_i];
2995
+ return [5 /*yield**/, _loop_1(localCheckIn)];
2996
+ case 2:
2997
+ _a.sent();
2998
+ _a.label = 3;
2999
+ case 3:
3000
+ _i++;
3001
+ return [3 /*break*/, 1];
3002
+ case 4: return [2 /*return*/, results];
2773
3003
  }
2774
3004
  });
2775
3005
  });
2776
3006
  };
2777
- CheckInsClient.prototype.remove = function (projectId, checkIn) {
3007
+ CheckInsManager.prototype.remove = function (projectId, localCheckIns, remoteCheckIns) {
2778
3008
  return __awaiter(this, void 0, void 0, function () {
2779
- var response;
3009
+ var checkInsToRemove;
3010
+ var _this = this;
2780
3011
  return __generator(this, function (_a) {
2781
- switch (_a.label) {
2782
- case 0:
2783
- if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
2784
- throw new Error('personalAuthToken is required');
2785
- }
2786
- return [4 /*yield*/, this.transport.send({
2787
- method: 'DELETE',
2788
- headers: this.getHeaders(),
2789
- endpoint: core_1.Util.endpoint(this.config.appEndpoint, "v2/projects/".concat(projectId, "/check_ins/").concat(checkIn.id)),
2790
- logger: this.logger,
2791
- })];
2792
- case 1:
2793
- response = _a.sent();
2794
- if (response.statusCode !== 204) {
2795
- throw new Error("Failed to remove checkin[".concat(checkIn.slug, "] for project[").concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
2796
- }
2797
- return [2 /*return*/];
2798
- }
3012
+ checkInsToRemove = remoteCheckIns.filter(function (remoteCheckIn) {
3013
+ return !localCheckIns.find(function (localCheckIn) {
3014
+ return localCheckIn.slug === remoteCheckIn.slug;
3015
+ });
3016
+ });
3017
+ return [2 /*return*/, Promise.all(checkInsToRemove.map(function (checkIn) { return __awaiter(_this, void 0, void 0, function () {
3018
+ return __generator(this, function (_a) {
3019
+ switch (_a.label) {
3020
+ case 0: return [4 /*yield*/, this.client.remove(projectId, checkIn)];
3021
+ case 1:
3022
+ _a.sent();
3023
+ checkIn.markAsDeleted();
3024
+ return [2 /*return*/, checkIn];
3025
+ }
3026
+ });
3027
+ }); }))];
2799
3028
  });
2800
3029
  });
2801
3030
  };
2802
- CheckInsClient.prototype.getHeaders = function () {
2803
- return {
2804
- 'Authorization': "Basic ".concat(Buffer.from("".concat(this.config.personalAuthToken, ":")).toString('base64')),
2805
- 'Content-Type': 'application/json'
2806
- };
2807
- };
2808
- CheckInsClient.prototype.getErrorMessage = function (responseBody) {
2809
- var _a;
2810
- if (!responseBody) {
2811
- return '';
2812
- }
2813
- try {
2814
- var jsonBody = JSON.parse(responseBody);
2815
- return (_a = jsonBody.errors) !== null && _a !== void 0 ? _a : '';
2816
- }
2817
- catch (e) {
2818
- return responseBody;
2819
- }
2820
- };
2821
- return CheckInsClient;
3031
+ return CheckInsManager;
2822
3032
  }());
2823
- client.CheckInsClient = CheckInsClient;
3033
+ exports.CheckInsManager = CheckInsManager;
2824
3034
 
2825
- return client;
2826
- }
2827
-
2828
- var hasRequiredCheckInsManager;
2829
-
2830
- function requireCheckInsManager () {
2831
- if (hasRequiredCheckInsManager) return checkInsManager;
2832
- hasRequiredCheckInsManager = 1;
2833
- (function (exports) {
2834
- var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
2835
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2836
- return new (P || (P = Promise))(function (resolve, reject) {
2837
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
2838
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
2839
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
2840
- step((generator = generator.apply(thisArg, _arguments || [])).next());
2841
- });
2842
- };
2843
- var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
2844
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
2845
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
2846
- function verb(n) { return function (v) { return step([n, v]); }; }
2847
- function step(op) {
2848
- if (f) throw new TypeError("Generator is already executing.");
2849
- while (_) try {
2850
- 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;
2851
- if (y = 0, t) op = [op[0] & 2, t.value];
2852
- switch (op[0]) {
2853
- case 0: case 1: t = op; break;
2854
- case 4: _.label++; return { value: op[1], done: false };
2855
- case 5: _.label++; y = op[1]; op = [0]; continue;
2856
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
2857
- default:
2858
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
2859
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
2860
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
2861
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
2862
- if (t[2]) _.ops.pop();
2863
- _.trys.pop(); continue;
2864
- }
2865
- op = body.call(thisArg, _);
2866
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
2867
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
2868
- }
2869
- };
2870
- var __spreadArray = (commonjsGlobal && commonjsGlobal.__spreadArray) || function (to, from, pack) {
2871
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
2872
- if (ar || !(i in from)) {
2873
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
2874
- ar[i] = from[i];
2875
- }
2876
- }
2877
- return to.concat(ar || Array.prototype.slice.call(from));
2878
- };
2879
- Object.defineProperty(exports, "__esModule", { value: true });
2880
- exports.CheckInsManager = exports.CheckIn = exports.CheckInsClient = void 0;
2881
- var core_1 = src;
2882
- var client_1 = requireClient();
2883
- var transport_1 = transport;
2884
- var check_in_1 = requireCheckIn();
2885
- var client_2 = requireClient();
2886
- Object.defineProperty(exports, "CheckInsClient", { enumerable: true, get: function () { return client_2.CheckInsClient; } });
2887
- var check_in_2 = requireCheckIn();
2888
- Object.defineProperty(exports, "CheckIn", { enumerable: true, get: function () { return check_in_2.CheckIn; } });
2889
- var CheckInsManager = /** @class */ (function () {
2890
- function CheckInsManager(config, client) {
2891
- var _a, _b, _c, _d, _e, _f;
2892
- this.config = {
2893
- appEndpoint: (_a = config.appEndpoint) !== null && _a !== void 0 ? _a : core_1.Defaults.CONFIG.appEndpoint,
2894
- debug: (_b = config.debug) !== null && _b !== void 0 ? _b : false,
2895
- apiKey: (_c = config.apiKey) !== null && _c !== void 0 ? _c : undefined,
2896
- personalAuthToken: (_d = config.personalAuthToken) !== null && _d !== void 0 ? _d : undefined,
2897
- checkins: (_e = config.checkins) !== null && _e !== void 0 ? _e : [],
2898
- logger: (_f = config.logger) !== null && _f !== void 0 ? _f : console,
2899
- };
2900
- var transport = new transport_1.ServerTransport();
2901
- this.logger = core_1.Util.logger(this);
2902
- this.client = client !== null && client !== void 0 ? client : new client_1.CheckInsClient({
2903
- appEndpoint: config.appEndpoint,
2904
- apiKey: config.apiKey,
2905
- personalAuthToken: config.personalAuthToken,
2906
- logger: this.logger
2907
- }, transport);
2908
- }
2909
- CheckInsManager.prototype.sync = function () {
2910
- return __awaiter(this, void 0, void 0, function () {
2911
- var localCheckIns, projectId, remoteCheckIns, createdOrUpdated, removed;
2912
- return __generator(this, function (_a) {
2913
- switch (_a.label) {
2914
- case 0:
2915
- // check if app endpoint is set
2916
- if (!this.config.appEndpoint || this.config.appEndpoint === '') {
2917
- throw new Error('appEndpoint is required');
2918
- }
2919
- // check if api key is set
2920
- if (!this.config.apiKey || this.config.apiKey === '') {
2921
- throw new Error('apiKey is required');
2922
- }
2923
- // check if personal auth token is set
2924
- if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
2925
- throw new Error('personalAuthToken is required');
2926
- }
2927
- localCheckIns = this.getLocalCheckIns();
2928
- return [4 /*yield*/, this.client.getProjectId(this.config.apiKey)];
2929
- case 1:
2930
- projectId = _a.sent();
2931
- return [4 /*yield*/, this.client.listForProject(projectId)];
2932
- case 2:
2933
- remoteCheckIns = _a.sent();
2934
- return [4 /*yield*/, this.createOrUpdate(projectId, localCheckIns, remoteCheckIns)];
2935
- case 3:
2936
- createdOrUpdated = _a.sent();
2937
- return [4 /*yield*/, this.remove(projectId, localCheckIns, remoteCheckIns)];
2938
- case 4:
2939
- removed = _a.sent();
2940
- return [2 /*return*/, __spreadArray(__spreadArray([], createdOrUpdated, true), removed, true)];
2941
- }
2942
- });
2943
- });
2944
- };
2945
- CheckInsManager.prototype.getLocalCheckIns = function () {
2946
- // create check-ins from configuration and validate them
2947
- var localCheckIns = this.config.checkins.map(function (dto) {
2948
- var checkIn = new check_in_1.CheckIn(dto);
2949
- checkIn.validate();
2950
- return checkIn;
2951
- });
2952
- // validate that we have unique check-in slugs
2953
- var checkInSlugs = localCheckIns.map(function (checkIn) { return checkIn.slug; });
2954
- var uniqueCheckInSlugs = new Set(checkInSlugs);
2955
- if (checkInSlugs.length !== uniqueCheckInSlugs.size) {
2956
- throw new Error('check-in slugs must be unique');
2957
- }
2958
- return localCheckIns;
2959
- };
2960
- CheckInsManager.prototype.createOrUpdate = function (projectId, localCheckIns, remoteCheckIns) {
2961
- return __awaiter(this, void 0, void 0, function () {
2962
- var results, _loop_1, this_1, _i, localCheckIns_1, localCheckIn;
2963
- return __generator(this, function (_a) {
2964
- switch (_a.label) {
2965
- case 0:
2966
- results = [];
2967
- _loop_1 = function (localCheckIn) {
2968
- var remoteCheckIn, _b, _c, _d, _e;
2969
- return __generator(this, function (_f) {
2970
- switch (_f.label) {
2971
- case 0:
2972
- remoteCheckIn = remoteCheckIns.find(function (checkIn) {
2973
- return checkIn.slug === localCheckIn.slug;
2974
- });
2975
- if (!!remoteCheckIn) return [3 /*break*/, 2];
2976
- _c = (_b = results).push;
2977
- return [4 /*yield*/, this_1.client.create(projectId, localCheckIn)];
2978
- case 1:
2979
- _c.apply(_b, [_f.sent()]);
2980
- return [3 /*break*/, 5];
2981
- case 2:
2982
- if (!!localCheckIn.isInSync(remoteCheckIn)) return [3 /*break*/, 4];
2983
- localCheckIn.id = remoteCheckIn.id;
2984
- _e = (_d = results).push;
2985
- return [4 /*yield*/, this_1.client.update(projectId, localCheckIn)];
2986
- case 3:
2987
- _e.apply(_d, [_f.sent()]);
2988
- return [3 /*break*/, 5];
2989
- case 4:
2990
- // no change - still need to add to results
2991
- results.push(remoteCheckIn);
2992
- _f.label = 5;
2993
- case 5: return [2 /*return*/];
2994
- }
2995
- });
2996
- };
2997
- this_1 = this;
2998
- _i = 0, localCheckIns_1 = localCheckIns;
2999
- _a.label = 1;
3000
- case 1:
3001
- if (!(_i < localCheckIns_1.length)) return [3 /*break*/, 4];
3002
- localCheckIn = localCheckIns_1[_i];
3003
- return [5 /*yield**/, _loop_1(localCheckIn)];
3004
- case 2:
3005
- _a.sent();
3006
- _a.label = 3;
3007
- case 3:
3008
- _i++;
3009
- return [3 /*break*/, 1];
3010
- case 4: return [2 /*return*/, results];
3011
- }
3012
- });
3013
- });
3014
- };
3015
- CheckInsManager.prototype.remove = function (projectId, localCheckIns, remoteCheckIns) {
3016
- return __awaiter(this, void 0, void 0, function () {
3017
- var checkInsToRemove;
3018
- var _this = this;
3019
- return __generator(this, function (_a) {
3020
- checkInsToRemove = remoteCheckIns.filter(function (remoteCheckIn) {
3021
- return !localCheckIns.find(function (localCheckIn) {
3022
- return localCheckIn.slug === remoteCheckIn.slug;
3023
- });
3024
- });
3025
- return [2 /*return*/, Promise.all(checkInsToRemove.map(function (checkIn) { return __awaiter(_this, void 0, void 0, function () {
3026
- return __generator(this, function (_a) {
3027
- switch (_a.label) {
3028
- case 0: return [4 /*yield*/, this.client.remove(projectId, checkIn)];
3029
- case 1:
3030
- _a.sent();
3031
- checkIn.markAsDeleted();
3032
- return [2 /*return*/, checkIn];
3033
- }
3034
- });
3035
- }); }))];
3036
- });
3037
- });
3038
- };
3039
- return CheckInsManager;
3040
- }());
3041
- exports.CheckInsManager = CheckInsManager;
3042
-
3043
3035
  } (checkInsManager));
3044
- return checkInsManager;
3045
- }
3046
3036
 
3047
3037
  (function (exports) {
3048
3038
  var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
@@ -3112,7 +3102,7 @@ function requireCheckInsManager () {
3112
3102
  };
3113
3103
  var _a;
3114
3104
  Object.defineProperty(exports, "__esModule", { value: true });
3115
- exports.ServerTransport = exports.CheckIn = exports.CheckInsClient = exports.Types = void 0;
3105
+ exports.CheckIn = exports.Types = void 0;
3116
3106
  var os_1 = __importDefault(require$$0__default["default"]);
3117
3107
  var domain_1 = __importDefault(require$$1__default$1["default"]);
3118
3108
  var core_1 = src;
@@ -3124,6 +3114,7 @@ function requireCheckInsManager () {
3124
3114
  var aws_lambda_1 = aws_lambda;
3125
3115
  var transport_1 = transport;
3126
3116
  var stacked_store_1 = stacked_store;
3117
+ var check_ins_manager_1 = checkInsManager;
3127
3118
  var endpoint = core_1.Util.endpoint;
3128
3119
  var DEFAULT_PLUGINS = [
3129
3120
  (0, uncaught_exception_plugin_1.default)(),
@@ -3163,6 +3154,7 @@ function requireCheckInsManager () {
3163
3154
  _this.errorHandler = middleware_1.errorHandler.bind(_this);
3164
3155
  _this.requestHandler = middleware_1.requestHandler.bind(_this);
3165
3156
  _this.lambdaHandler = aws_lambda_1.lambdaHandler.bind(_this);
3157
+ _this.checkInsApi = new check_ins_manager_1.CheckInsClient(_this.config, transport);
3166
3158
  return _this;
3167
3159
  }
3168
3160
  Honeybadger.prototype.factory = function (opts) {
@@ -3173,6 +3165,12 @@ function requireCheckInsManager () {
3173
3165
  };
3174
3166
  Honeybadger.prototype.configure = function (opts) {
3175
3167
  if (opts === void 0) { opts = {}; }
3168
+ this.checkInsApi.configure({
3169
+ appEndpoint: opts.appEndpoint,
3170
+ apiKey: opts.apiKey,
3171
+ personalAuthToken: opts.personalAuthToken,
3172
+ logger: opts.logger,
3173
+ });
3176
3174
  return _super.prototype.configure.call(this, opts);
3177
3175
  };
3178
3176
  Honeybadger.prototype.__initStore = function () {
@@ -3280,7 +3278,7 @@ function requireCheckInsManager () {
3280
3278
  var NOTIFIER = {
3281
3279
  name: '@honeybadger-io/js',
3282
3280
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/js',
3283
- version: '6.12.0'
3281
+ version: '6.12.2'
3284
3282
  };
3285
3283
  var userAgent = function () {
3286
3284
  return "Honeybadger JS Server Client ".concat(NOTIFIER.version, ", ").concat(os_1.default.version(), "; ").concat(os_1.default.platform());
@@ -3289,11 +3287,8 @@ function requireCheckInsManager () {
3289
3287
  singleton.setNotifier(NOTIFIER);
3290
3288
  var core_2 = src;
3291
3289
  Object.defineProperty(exports, "Types", { enumerable: true, get: function () { return core_2.Types; } });
3292
- var check_ins_manager_1 = requireCheckInsManager();
3293
- Object.defineProperty(exports, "CheckInsClient", { enumerable: true, get: function () { return check_ins_manager_1.CheckInsClient; } });
3294
- Object.defineProperty(exports, "CheckIn", { enumerable: true, get: function () { return check_ins_manager_1.CheckIn; } });
3295
- var transport_2 = transport;
3296
- Object.defineProperty(exports, "ServerTransport", { enumerable: true, get: function () { return transport_2.ServerTransport; } });
3290
+ var check_in_1 = requireCheckIn();
3291
+ Object.defineProperty(exports, "CheckIn", { enumerable: true, get: function () { return check_in_1.CheckIn; } });
3297
3292
  exports.default = singleton;
3298
3293
 
3299
3294
  } (server$1));