@honeybadger-io/js 6.5.3 → 6.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,9 +4,10 @@ var require$$0$1 = require('os');
4
4
  var require$$1$1 = require('domain');
5
5
  var require$$1 = require('fs');
6
6
  var require$$2 = require('util');
7
+ var require$$3 = require('cosmiconfig');
7
8
  var require$$0$2 = require('url');
8
- var require$$2$1 = require('http');
9
- var require$$3 = require('https');
9
+ var require$$3$1 = require('http');
10
+ var require$$4 = require('https');
10
11
 
11
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
13
 
@@ -14,9 +15,10 @@ var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
14
15
  var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
15
16
  var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
16
17
  var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
17
- var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
18
- var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
19
18
  var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
19
+ var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
20
+ var require$$3__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$3$1);
21
+ var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
20
22
 
21
23
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
22
24
 
@@ -49,7 +51,7 @@ var server$1 = {};
49
51
 
50
52
  var src = {};
51
53
 
52
- var client = {};
54
+ var client$1 = {};
53
55
 
54
56
  var util$1 = {};
55
57
 
@@ -806,8 +808,8 @@ var GlobalStore = /** @class */ (function () {
806
808
  }());
807
809
  store.GlobalStore = GlobalStore;
808
810
 
809
- var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
810
- __assign = Object.assign || function(t) {
811
+ var __assign$1 = (commonjsGlobal && commonjsGlobal.__assign) || function () {
812
+ __assign$1 = Object.assign || function(t) {
811
813
  for (var s, i = 1, n = arguments.length; i < n; i++) {
812
814
  s = arguments[i];
813
815
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
@@ -815,9 +817,9 @@ var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
815
817
  }
816
818
  return t;
817
819
  };
818
- return __assign.apply(this, arguments);
820
+ return __assign$1.apply(this, arguments);
819
821
  };
820
- var __awaiter$1 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
822
+ var __awaiter$2 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
821
823
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
822
824
  return new (P || (P = Promise))(function (resolve, reject) {
823
825
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -826,7 +828,7 @@ var __awaiter$1 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (this
826
828
  step((generator = generator.apply(thisArg, _arguments || [])).next());
827
829
  });
828
830
  };
829
- var __generator$1 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
831
+ var __generator$2 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
830
832
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
831
833
  return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
832
834
  function verb(n) { return function (v) { return step([n, v]); }; }
@@ -853,8 +855,8 @@ var __generator$1 = (commonjsGlobal && commonjsGlobal.__generator) || function (
853
855
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
854
856
  }
855
857
  };
856
- Object.defineProperty(client, "__esModule", { value: true });
857
- client.Client = void 0;
858
+ Object.defineProperty(client$1, "__esModule", { value: true });
859
+ client$1.Client = void 0;
858
860
  var util_1$4 = util$1;
859
861
  var store_1 = store;
860
862
  // Split at commas and spaces
@@ -871,9 +873,9 @@ var Client = /** @class */ (function () {
871
873
  this.__notifier = {
872
874
  name: '@honeybadger-io/core',
873
875
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/core',
874
- version: '6.5.3'
876
+ version: '6.6.0'
875
877
  };
876
- this.config = __assign({ apiKey: null, endpoint: 'https://api.honeybadger.io', environment: null, hostname: null, projectRoot: null, component: null, action: null, revision: null, reportData: null, breadcrumbsEnabled: true, maxBreadcrumbs: 40, maxObjectDepth: 8, logger: console, developmentEnvironments: ['dev', 'development', 'test'], debug: false, tags: null, enableUncaught: true, enableUnhandledRejection: true, afterUncaught: function () { return true; }, filters: ['creditcard', 'password'], __plugins: [] }, opts);
878
+ this.config = __assign$1({ apiKey: null, endpoint: 'https://api.honeybadger.io', environment: null, hostname: null, projectRoot: null, component: null, action: null, revision: null, reportData: null, breadcrumbsEnabled: true, maxBreadcrumbs: 40, maxObjectDepth: 8, logger: console, developmentEnvironments: ['dev', 'development', 'test'], debug: false, tags: null, enableUncaught: true, enableUnhandledRejection: true, afterUncaught: function () { return true; }, filters: ['creditcard', 'password'], __plugins: [] }, opts);
877
879
  this.__initStore();
878
880
  this.__transport = transport;
879
881
  this.logger = (0, util_1$4.logger)(this);
@@ -1087,7 +1089,7 @@ var Client = /** @class */ (function () {
1087
1089
  };
1088
1090
  Client.prototype.__buildPayload = function (notice) {
1089
1091
  var headers = (0, util_1$4.filter)(notice.headers, this.config.filters) || {};
1090
- var cgiData = (0, util_1$4.filter)(__assign(__assign({}, notice.cgiData), (0, util_1$4.formatCGIData)(headers, 'HTTP_')), this.config.filters);
1092
+ var cgiData = (0, util_1$4.filter)(__assign$1(__assign$1({}, notice.cgiData), (0, util_1$4.formatCGIData)(headers, 'HTTP_')), this.config.filters);
1091
1093
  return {
1092
1094
  notifier: this.__notifier,
1093
1095
  breadcrumbs: {
@@ -1182,9 +1184,9 @@ var Client = /** @class */ (function () {
1182
1184
  notice.__breadcrumbs = [];
1183
1185
  }
1184
1186
  return (0, util_1$4.getSourceForBacktrace)(originalBacktrace, this.__getSourceFileHandler)
1185
- .then(function (sourcePerTrace) { return __awaiter$1(_this, void 0, void 0, function () {
1187
+ .then(function (sourcePerTrace) { return __awaiter$2(_this, void 0, void 0, function () {
1186
1188
  var payload;
1187
- return __generator$1(this, function (_a) {
1189
+ return __generator$2(this, function (_a) {
1188
1190
  sourcePerTrace.forEach(function (source, index) {
1189
1191
  notice.backtrace[index].source = source;
1190
1192
  });
@@ -1224,7 +1226,7 @@ var Client = /** @class */ (function () {
1224
1226
  };
1225
1227
  return Client;
1226
1228
  }());
1227
- client.Client = Client;
1229
+ client$1.Client = Client;
1228
1230
 
1229
1231
  var types = {};
1230
1232
 
@@ -1259,7 +1261,7 @@ Object.defineProperty(types, "__esModule", { value: true });
1259
1261
  };
1260
1262
  Object.defineProperty(exports, "__esModule", { value: true });
1261
1263
  exports.Util = exports.Types = exports.Client = void 0;
1262
- var client_1 = client;
1264
+ var client_1 = client$1;
1263
1265
  Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
1264
1266
  __exportStar(store, exports);
1265
1267
  exports.Types = __importStar(types);
@@ -1269,7 +1271,7 @@ Object.defineProperty(types, "__esModule", { value: true });
1269
1271
 
1270
1272
  var util = {};
1271
1273
 
1272
- var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
1274
+ var __awaiter$1 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
1273
1275
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1274
1276
  return new (P || (P = Promise))(function (resolve, reject) {
1275
1277
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1278,7 +1280,7 @@ var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisAr
1278
1280
  step((generator = generator.apply(thisArg, _arguments || [])).next());
1279
1281
  });
1280
1282
  };
1281
- var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
1283
+ var __generator$1 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
1282
1284
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
1283
1285
  return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
1284
1286
  function verb(n) { return function (v) { return step([n, v]); }; }
@@ -1305,14 +1307,15 @@ var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (th
1305
1307
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
1306
1308
  }
1307
1309
  };
1308
- var __importDefault$4 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1310
+ var __importDefault$3 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1309
1311
  return (mod && mod.__esModule) ? mod : { "default": mod };
1310
1312
  };
1311
1313
  Object.defineProperty(util, "__esModule", { value: true });
1312
- util.getSourceFile = util.getStats = util.fatallyLogAndExit = void 0;
1313
- var os_1 = __importDefault$4(require$$0__default["default"]);
1314
- var fs_1 = __importDefault$4(require$$1__default["default"]);
1314
+ util.readConfigFromFileSystem = util.getSourceFile = util.getStats = util.fatallyLogAndExit = void 0;
1315
+ var os_1 = __importDefault$3(require$$0__default["default"]);
1316
+ var fs_1 = __importDefault$3(require$$1__default["default"]);
1315
1317
  var util_1$3 = require$$2__default["default"];
1318
+ var cosmiconfig_1 = require$$3__default["default"];
1316
1319
  var readFile = (0, util_1$3.promisify)(fs_1.default.readFile);
1317
1320
  function fatallyLogAndExit(err) {
1318
1321
  console.error('[Honeybadger] Exiting process due to uncaught exception');
@@ -1321,9 +1324,9 @@ function fatallyLogAndExit(err) {
1321
1324
  }
1322
1325
  util.fatallyLogAndExit = fatallyLogAndExit;
1323
1326
  function getStats() {
1324
- return __awaiter(this, void 0, void 0, function () {
1327
+ return __awaiter$1(this, void 0, void 0, function () {
1325
1328
  var load, stats, fallback, memData, data, results;
1326
- return __generator(this, function (_a) {
1329
+ return __generator$1(this, function (_a) {
1327
1330
  switch (_a.label) {
1328
1331
  case 0:
1329
1332
  load = os_1.default.loadavg();
@@ -1382,8 +1385,8 @@ util.getStats = getStats;
1382
1385
  * @param path to source code
1383
1386
  */
1384
1387
  function getSourceFile(path) {
1385
- return __awaiter(this, void 0, void 0, function () {
1386
- return __generator(this, function (_a) {
1388
+ return __awaiter$1(this, void 0, void 0, function () {
1389
+ return __generator$1(this, function (_a) {
1387
1390
  switch (_a.label) {
1388
1391
  case 0:
1389
1392
  _a.trys.push([0, 2, , 3]);
@@ -1398,6 +1401,22 @@ function getSourceFile(path) {
1398
1401
  });
1399
1402
  }
1400
1403
  util.getSourceFile = getSourceFile;
1404
+ function readConfigFromFileSystem() {
1405
+ return readConfigForModule('honeybadger');
1406
+ }
1407
+ util.readConfigFromFileSystem = readConfigFromFileSystem;
1408
+ function readConfigForModule(moduleName) {
1409
+ var _a;
1410
+ try {
1411
+ var fileExplorer = (0, cosmiconfig_1.cosmiconfigSync)(moduleName);
1412
+ var result = fileExplorer.search();
1413
+ return (_a = result === null || result === void 0 ? void 0 : result.config) !== null && _a !== void 0 ? _a : null;
1414
+ }
1415
+ catch (e) {
1416
+ console.debug("[Honeybadger] Could not read config for module ".concat(moduleName, ": ").concat(e.message));
1417
+ return null;
1418
+ }
1419
+ }
1401
1420
 
1402
1421
  var uncaught_exception_plugin = {};
1403
1422
 
@@ -1584,11 +1603,11 @@ var UncaughtExceptionMonitor = /** @class */ (function () {
1584
1603
  }());
1585
1604
  uncaught_exception_monitor.default = UncaughtExceptionMonitor;
1586
1605
 
1587
- var __importDefault$3 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1606
+ var __importDefault$2 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1588
1607
  return (mod && mod.__esModule) ? mod : { "default": mod };
1589
1608
  };
1590
1609
  Object.defineProperty(uncaught_exception_plugin, "__esModule", { value: true });
1591
- var uncaught_exception_monitor_1 = __importDefault$3(uncaught_exception_monitor);
1610
+ var uncaught_exception_monitor_1 = __importDefault$2(uncaught_exception_monitor);
1592
1611
  var uncaughtExceptionMonitor = new uncaught_exception_monitor_1.default();
1593
1612
  function default_1$1() {
1594
1613
  return {
@@ -1663,11 +1682,11 @@ var UnhandledRejectionMonitor = /** @class */ (function () {
1663
1682
  }());
1664
1683
  unhandled_rejection_monitor.default = UnhandledRejectionMonitor;
1665
1684
 
1666
- var __importDefault$2 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1685
+ var __importDefault$1 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1667
1686
  return (mod && mod.__esModule) ? mod : { "default": mod };
1668
1687
  };
1669
1688
  Object.defineProperty(unhandled_rejection_plugin, "__esModule", { value: true });
1670
- var unhandled_rejection_monitor_1 = __importDefault$2(unhandled_rejection_monitor);
1689
+ var unhandled_rejection_monitor_1 = __importDefault$1(unhandled_rejection_monitor);
1671
1690
  var unhandledRejectionMonitor = new unhandled_rejection_monitor_1.default();
1672
1691
  function default_1() {
1673
1692
  return {
@@ -1687,12 +1706,12 @@ unhandled_rejection_plugin.default = default_1;
1687
1706
 
1688
1707
  var middleware = {};
1689
1708
 
1690
- var __importDefault$1 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1709
+ var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1691
1710
  return (mod && mod.__esModule) ? mod : { "default": mod };
1692
1711
  };
1693
1712
  Object.defineProperty(middleware, "__esModule", { value: true });
1694
1713
  middleware.errorHandler = middleware.requestHandler = void 0;
1695
- var url_1$1 = __importDefault$1(require$$0__default$1["default"]);
1714
+ var url_1$1 = __importDefault(require$$0__default$1["default"]);
1696
1715
  function fullUrl(req) {
1697
1716
  var connection = req.connection;
1698
1717
  var address = connection && connection.address();
@@ -1730,24 +1749,61 @@ middleware.errorHandler = errorHandler;
1730
1749
 
1731
1750
  var transport = {};
1732
1751
 
1733
- var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1734
- return (mod && mod.__esModule) ? mod : { "default": mod };
1752
+ var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
1753
+ __assign = Object.assign || function(t) {
1754
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
1755
+ s = arguments[i];
1756
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
1757
+ t[p] = s[p];
1758
+ }
1759
+ return t;
1760
+ };
1761
+ return __assign.apply(this, arguments);
1762
+ };
1763
+ var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1764
+ if (k2 === undefined) k2 = k;
1765
+ var desc = Object.getOwnPropertyDescriptor(m, k);
1766
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
1767
+ desc = { enumerable: true, get: function() { return m[k]; } };
1768
+ }
1769
+ Object.defineProperty(o, k2, desc);
1770
+ }) : (function(o, m, k, k2) {
1771
+ if (k2 === undefined) k2 = k;
1772
+ o[k2] = m[k];
1773
+ }));
1774
+ var __setModuleDefault = (commonjsGlobal && commonjsGlobal.__setModuleDefault) || (Object.create ? (function(o, v) {
1775
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
1776
+ }) : function(o, v) {
1777
+ o["default"] = v;
1778
+ });
1779
+ var __importStar = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) {
1780
+ if (mod && mod.__esModule) return mod;
1781
+ var result = {};
1782
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1783
+ __setModuleDefault(result, mod);
1784
+ return result;
1735
1785
  };
1736
1786
  Object.defineProperty(transport, "__esModule", { value: true });
1737
1787
  transport.ServerTransport = void 0;
1738
1788
  var core_1$1 = src;
1739
1789
  var url_1 = require$$0__default$1["default"];
1740
- var http_1 = __importDefault(require$$2__default$1["default"]);
1741
- var https_1 = __importDefault(require$$3__default["default"]);
1742
1790
  var util_1 = util;
1791
+ var http = __importStar(require$$3__default$1["default"]);
1792
+ var https = __importStar(require$$4__default["default"]);
1743
1793
  var sanitize = core_1$1.Util.sanitize;
1744
1794
  var ServerTransport = /** @class */ (function () {
1745
- function ServerTransport() {
1795
+ function ServerTransport(headers) {
1796
+ if (headers === void 0) { headers = {}; }
1797
+ this.headers = {};
1798
+ this.headers = headers;
1746
1799
  }
1800
+ ServerTransport.prototype.defaultHeaders = function () {
1801
+ return this.headers;
1802
+ };
1747
1803
  ServerTransport.prototype.send = function (options, payload) {
1748
1804
  var _this = this;
1749
1805
  var _a = new url_1.URL(options.endpoint), protocol = _a.protocol, hostname = _a.hostname, pathname = _a.pathname;
1750
- var transport = (protocol === 'http:' ? http_1.default : https_1.default);
1806
+ var transport = (protocol === 'http:' ? http : https);
1751
1807
  return new Promise(function (resolve, reject) {
1752
1808
  var promise;
1753
1809
  // this should not be here. it should be done before reaching the transport layer
@@ -1764,7 +1820,7 @@ var ServerTransport = /** @class */ (function () {
1764
1820
  // See https://github.com/honeybadger-io/honeybadger-js/issues/825#issuecomment-1193113433
1765
1821
  var httpOptions = {
1766
1822
  method: options.method,
1767
- headers: options.headers,
1823
+ headers: __assign(__assign({}, _this.defaultHeaders()), options.headers),
1768
1824
  path: pathname,
1769
1825
  protocol: protocol,
1770
1826
  hostname: hostname,
@@ -1924,6 +1980,308 @@ var StackedStore = /** @class */ (function () {
1924
1980
  }());
1925
1981
  stacked_store.StackedStore = StackedStore;
1926
1982
 
1983
+ var client = {};
1984
+
1985
+ var checkin = {};
1986
+
1987
+ Object.defineProperty(checkin, "__esModule", { value: true });
1988
+ checkin.Checkin = void 0;
1989
+ var Checkin = /** @class */ (function () {
1990
+ function Checkin(props) {
1991
+ this.id = props.id;
1992
+ this.name = props.name;
1993
+ this.slug = props.slug;
1994
+ this.scheduleType = props.scheduleType;
1995
+ this.reportPeriod = props.reportPeriod;
1996
+ this.gracePeriod = props.gracePeriod;
1997
+ this.cronSchedule = props.cronSchedule;
1998
+ this.cronTimezone = props.cronTimezone;
1999
+ this.projectId = props.projectId;
2000
+ this.deleted = false;
2001
+ }
2002
+ Checkin.prototype.isDeleted = function () {
2003
+ return this.deleted;
2004
+ };
2005
+ Checkin.prototype.markAsDeleted = function () {
2006
+ this.deleted = true;
2007
+ };
2008
+ Checkin.prototype.validate = function () {
2009
+ if (!this.projectId) {
2010
+ throw new Error('projectId is required for each checkin');
2011
+ }
2012
+ if (!this.name) {
2013
+ throw new Error('name is required for each checkin');
2014
+ }
2015
+ if (!this.scheduleType) {
2016
+ throw new Error('scheduleType is required for each checkin');
2017
+ }
2018
+ if (!['simple', 'cron'].includes(this.scheduleType)) {
2019
+ throw new Error("".concat(this.name, " [scheduleType] must be \"simple\" or \"cron\""));
2020
+ }
2021
+ if (this.scheduleType === 'simple' && !this.reportPeriod) {
2022
+ throw new Error("".concat(this.name, " [reportPeriod] is required for simple checkins"));
2023
+ }
2024
+ if (this.scheduleType === 'cron' && !this.cronSchedule) {
2025
+ throw new Error("".concat(this.name, " [cronSchedule] is required for cron checkins"));
2026
+ }
2027
+ };
2028
+ Checkin.prototype.asRequestPayload = function () {
2029
+ var _a, _b, _c;
2030
+ var payload = {
2031
+ name: this.name,
2032
+ schedule_type: this.scheduleType,
2033
+ slug: (_a = this.slug) !== null && _a !== void 0 ? _a : '',
2034
+ grace_period: (_b = this.gracePeriod) !== null && _b !== void 0 ? _b : '' // default is empty string
2035
+ };
2036
+ if (this.scheduleType === 'simple') {
2037
+ payload.report_period = this.reportPeriod;
2038
+ }
2039
+ else {
2040
+ payload.cron_schedule = this.cronSchedule;
2041
+ payload.cron_timezone = (_c = this.cronTimezone) !== null && _c !== void 0 ? _c : ''; // default is empty string
2042
+ }
2043
+ return payload;
2044
+ };
2045
+ /**
2046
+ * Compares two checkins, usually the one from the API and the one from the config file.
2047
+ * If the one in the config file does not match the checkin from the API,
2048
+ * then we issue an update request.
2049
+ */
2050
+ Checkin.prototype.isInSync = function (other) {
2051
+ var _a, _b, _c, _d, _e, _f;
2052
+ return this.name === other.name
2053
+ && this.projectId === other.projectId
2054
+ && this.scheduleType === other.scheduleType
2055
+ && this.reportPeriod === other.reportPeriod
2056
+ && this.cronSchedule === other.cronSchedule
2057
+ && ((_a = this.slug) !== null && _a !== void 0 ? _a : '') === ((_b = other.slug) !== null && _b !== void 0 ? _b : '')
2058
+ && ((_c = this.gracePeriod) !== null && _c !== void 0 ? _c : '') === ((_d = other.gracePeriod) !== null && _d !== void 0 ? _d : '')
2059
+ && ((_e = this.cronTimezone) !== null && _e !== void 0 ? _e : '') === ((_f = other.cronTimezone) !== null && _f !== void 0 ? _f : '');
2060
+ };
2061
+ Checkin.fromResponsePayload = function (projectId, payload) {
2062
+ return new Checkin({
2063
+ projectId: projectId,
2064
+ id: payload.id,
2065
+ name: payload.name,
2066
+ slug: payload.slug,
2067
+ scheduleType: payload.schedule_type,
2068
+ reportPeriod: payload.report_period,
2069
+ gracePeriod: payload.grace_period,
2070
+ cronSchedule: payload.cron_schedule,
2071
+ cronTimezone: payload.cron_timezone,
2072
+ });
2073
+ };
2074
+ return Checkin;
2075
+ }());
2076
+ checkin.Checkin = Checkin;
2077
+
2078
+ var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
2079
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2080
+ return new (P || (P = Promise))(function (resolve, reject) {
2081
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
2082
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
2083
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
2084
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
2085
+ });
2086
+ };
2087
+ var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
2088
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
2089
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
2090
+ function verb(n) { return function (v) { return step([n, v]); }; }
2091
+ function step(op) {
2092
+ if (f) throw new TypeError("Generator is already executing.");
2093
+ while (_) try {
2094
+ 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;
2095
+ if (y = 0, t) op = [op[0] & 2, t.value];
2096
+ switch (op[0]) {
2097
+ case 0: case 1: t = op; break;
2098
+ case 4: _.label++; return { value: op[1], done: false };
2099
+ case 5: _.label++; y = op[1]; op = [0]; continue;
2100
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
2101
+ default:
2102
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
2103
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
2104
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
2105
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
2106
+ if (t[2]) _.ops.pop();
2107
+ _.trys.pop(); continue;
2108
+ }
2109
+ op = body.call(thisArg, _);
2110
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
2111
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
2112
+ }
2113
+ };
2114
+ Object.defineProperty(client, "__esModule", { value: true });
2115
+ client.CheckinsClient = void 0;
2116
+ var checkin_1 = checkin;
2117
+ var CheckinsClient = /** @class */ (function () {
2118
+ function CheckinsClient(config, transport) {
2119
+ this.BASE_URL = 'https://app.honeybadger.io';
2120
+ this.transport = transport;
2121
+ this.config = config;
2122
+ this.logger = config.logger;
2123
+ this.cache = {};
2124
+ }
2125
+ CheckinsClient.prototype.listForProject = function (projectId) {
2126
+ return __awaiter(this, void 0, void 0, function () {
2127
+ var response, data, checkins;
2128
+ return __generator(this, function (_a) {
2129
+ switch (_a.label) {
2130
+ case 0:
2131
+ if (this.cache[projectId]) {
2132
+ return [2 /*return*/, this.cache[projectId]];
2133
+ }
2134
+ if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
2135
+ throw new Error('personalAuthToken is required');
2136
+ }
2137
+ return [4 /*yield*/, this.transport.send({
2138
+ method: 'GET',
2139
+ headers: this.getHeaders(),
2140
+ endpoint: "".concat(this.BASE_URL, "/v2/projects/").concat(projectId, "/check_ins"),
2141
+ logger: this.logger,
2142
+ })];
2143
+ case 1:
2144
+ response = _a.sent();
2145
+ if (response.statusCode !== 200) {
2146
+ throw new Error("Failed to fetch checkins for project[".concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
2147
+ }
2148
+ data = JSON.parse(response.body);
2149
+ checkins = data.results.map(function (checkin) { return checkin_1.Checkin.fromResponsePayload(projectId, checkin); });
2150
+ this.cache[projectId] = checkins;
2151
+ return [2 /*return*/, checkins];
2152
+ }
2153
+ });
2154
+ });
2155
+ };
2156
+ CheckinsClient.prototype.get = function (projectId, checkinId) {
2157
+ return __awaiter(this, void 0, void 0, function () {
2158
+ var response, data, checkin;
2159
+ return __generator(this, function (_a) {
2160
+ switch (_a.label) {
2161
+ case 0:
2162
+ if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
2163
+ throw new Error('personalAuthToken is required');
2164
+ }
2165
+ return [4 /*yield*/, this.transport.send({
2166
+ method: 'GET',
2167
+ headers: this.getHeaders(),
2168
+ endpoint: "".concat(this.BASE_URL, "/v2/projects/").concat(projectId, "/check_ins/").concat(checkinId),
2169
+ logger: this.logger,
2170
+ })];
2171
+ case 1:
2172
+ response = _a.sent();
2173
+ if (response.statusCode !== 200) {
2174
+ throw new Error("Failed to fetch checkin[".concat(checkinId, "] for project[").concat(projectId, "]: ").concat(this.getErrorMessage(response.body)));
2175
+ }
2176
+ data = JSON.parse(response.body);
2177
+ checkin = checkin_1.Checkin.fromResponsePayload(projectId, data);
2178
+ checkin.projectId = projectId;
2179
+ return [2 /*return*/, checkin];
2180
+ }
2181
+ });
2182
+ });
2183
+ };
2184
+ CheckinsClient.prototype.create = function (checkin) {
2185
+ return __awaiter(this, void 0, void 0, function () {
2186
+ var response, data, result;
2187
+ return __generator(this, function (_a) {
2188
+ switch (_a.label) {
2189
+ case 0:
2190
+ if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
2191
+ throw new Error('personalAuthToken is required');
2192
+ }
2193
+ return [4 /*yield*/, this.transport.send({
2194
+ method: 'POST',
2195
+ headers: this.getHeaders(),
2196
+ endpoint: "".concat(this.BASE_URL, "/v2/projects/").concat(checkin.projectId, "/check_ins"),
2197
+ logger: this.logger,
2198
+ }, { check_in: checkin.asRequestPayload() })];
2199
+ case 1:
2200
+ response = _a.sent();
2201
+ if (response.statusCode !== 201) {
2202
+ throw new Error("Failed to create checkin[".concat(checkin.name, "] for project[").concat(checkin.projectId, "]: ").concat(this.getErrorMessage(response.body)));
2203
+ }
2204
+ data = JSON.parse(response.body);
2205
+ result = checkin_1.Checkin.fromResponsePayload(checkin.projectId, data);
2206
+ result.projectId = checkin.projectId;
2207
+ return [2 /*return*/, result];
2208
+ }
2209
+ });
2210
+ });
2211
+ };
2212
+ CheckinsClient.prototype.update = function (checkin) {
2213
+ return __awaiter(this, void 0, void 0, function () {
2214
+ var response;
2215
+ return __generator(this, function (_a) {
2216
+ switch (_a.label) {
2217
+ case 0:
2218
+ if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
2219
+ throw new Error('personalAuthToken is required');
2220
+ }
2221
+ return [4 /*yield*/, this.transport.send({
2222
+ method: 'PUT',
2223
+ headers: this.getHeaders(),
2224
+ endpoint: "".concat(this.BASE_URL, "/v2/projects/").concat(checkin.projectId, "/check_ins/").concat(checkin.id),
2225
+ logger: this.logger,
2226
+ }, { check_in: checkin.asRequestPayload() })];
2227
+ case 1:
2228
+ response = _a.sent();
2229
+ if (response.statusCode !== 204) {
2230
+ throw new Error("Failed to update checkin[".concat(checkin.name, "] for project[").concat(checkin.projectId, "]: ").concat(this.getErrorMessage(response.body)));
2231
+ }
2232
+ return [2 /*return*/, checkin];
2233
+ }
2234
+ });
2235
+ });
2236
+ };
2237
+ CheckinsClient.prototype.remove = function (checkin) {
2238
+ return __awaiter(this, void 0, void 0, function () {
2239
+ var response;
2240
+ return __generator(this, function (_a) {
2241
+ switch (_a.label) {
2242
+ case 0:
2243
+ if (!this.config.personalAuthToken || this.config.personalAuthToken === '') {
2244
+ throw new Error('personalAuthToken is required');
2245
+ }
2246
+ return [4 /*yield*/, this.transport.send({
2247
+ method: 'DELETE',
2248
+ headers: this.getHeaders(),
2249
+ endpoint: "".concat(this.BASE_URL, "/v2/projects/").concat(checkin.projectId, "/check_ins/").concat(checkin.id),
2250
+ logger: this.logger,
2251
+ })];
2252
+ case 1:
2253
+ response = _a.sent();
2254
+ if (response.statusCode !== 204) {
2255
+ throw new Error("Failed to remove checkin[".concat(checkin.name, "] for project[").concat(checkin.projectId, "]: ").concat(this.getErrorMessage(response.body)));
2256
+ }
2257
+ return [2 /*return*/];
2258
+ }
2259
+ });
2260
+ });
2261
+ };
2262
+ CheckinsClient.prototype.getHeaders = function () {
2263
+ return {
2264
+ 'Authorization': "Basic ".concat(Buffer.from("".concat(this.config.personalAuthToken, ":")).toString('base64')),
2265
+ 'Content-Type': 'application/json'
2266
+ };
2267
+ };
2268
+ CheckinsClient.prototype.getErrorMessage = function (responseBody) {
2269
+ var _a;
2270
+ if (!responseBody) {
2271
+ return '';
2272
+ }
2273
+ try {
2274
+ var jsonBody = JSON.parse(responseBody);
2275
+ return (_a = jsonBody.errors) !== null && _a !== void 0 ? _a : '';
2276
+ }
2277
+ catch (e) {
2278
+ return responseBody;
2279
+ }
2280
+ };
2281
+ return CheckinsClient;
2282
+ }());
2283
+ client.CheckinsClient = CheckinsClient;
2284
+
1927
2285
  (function (exports) {
1928
2286
  var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
1929
2287
  var extendStatics = function (d, b) {
@@ -1951,9 +2309,46 @@ stacked_store.StackedStore = StackedStore;
1951
2309
  };
1952
2310
  return __assign.apply(this, arguments);
1953
2311
  };
2312
+ var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
2313
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2314
+ return new (P || (P = Promise))(function (resolve, reject) {
2315
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
2316
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
2317
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
2318
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
2319
+ });
2320
+ };
2321
+ var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
2322
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
2323
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
2324
+ function verb(n) { return function (v) { return step([n, v]); }; }
2325
+ function step(op) {
2326
+ if (f) throw new TypeError("Generator is already executing.");
2327
+ while (_) try {
2328
+ 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;
2329
+ if (y = 0, t) op = [op[0] & 2, t.value];
2330
+ switch (op[0]) {
2331
+ case 0: case 1: t = op; break;
2332
+ case 4: _.label++; return { value: op[1], done: false };
2333
+ case 5: _.label++; y = op[1]; op = [0]; continue;
2334
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
2335
+ default:
2336
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
2337
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
2338
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
2339
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
2340
+ if (t[2]) _.ops.pop();
2341
+ _.trys.pop(); continue;
2342
+ }
2343
+ op = body.call(thisArg, _);
2344
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
2345
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
2346
+ }
2347
+ };
1954
2348
  var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1955
2349
  return (mod && mod.__esModule) ? mod : { "default": mod };
1956
2350
  };
2351
+ var _a;
1957
2352
  Object.defineProperty(exports, "__esModule", { value: true });
1958
2353
  exports.Types = void 0;
1959
2354
  var os_1 = __importDefault(require$$0__default["default"]);
@@ -1966,14 +2361,20 @@ stacked_store.StackedStore = StackedStore;
1966
2361
  var aws_lambda_1 = aws_lambda;
1967
2362
  var transport_1 = transport;
1968
2363
  var stacked_store_1 = stacked_store;
2364
+ var client_1 = client;
1969
2365
  var endpoint = core_1.Util.endpoint;
2366
+ var DEFAULT_PLUGINS = [
2367
+ (0, uncaught_exception_plugin_1.default)(),
2368
+ (0, unhandled_rejection_plugin_1.default)()
2369
+ ];
1970
2370
  var Honeybadger = /** @class */ (function (_super) {
1971
2371
  __extends(Honeybadger, _super);
1972
2372
  function Honeybadger(opts) {
1973
2373
  if (opts === void 0) { opts = {}; }
1974
2374
  var _this = this;
1975
2375
  var _a;
1976
- _this = _super.call(this, __assign({ projectRoot: process.cwd(), hostname: os_1.default.hostname() }, opts), new transport_1.ServerTransport()) || this;
2376
+ var transport = new transport_1.ServerTransport();
2377
+ _this = _super.call(this, __assign({ projectRoot: process.cwd(), hostname: os_1.default.hostname() }, opts), transport) || this;
1977
2378
  /** @internal */
1978
2379
  _this.__beforeNotifyHandlers = [
1979
2380
  function (notice) {
@@ -1992,6 +2393,7 @@ stacked_store.StackedStore = StackedStore;
1992
2393
  var config = _this.config;
1993
2394
  config.reportTimeoutWarning = (_a = config.reportTimeoutWarning) !== null && _a !== void 0 ? _a : true;
1994
2395
  config.timeoutWarningThresholdMs = config.timeoutWarningThresholdMs || 50;
2396
+ _this.__checkinsClient = new client_1.CheckinsClient(_this.config, transport);
1995
2397
  _this.__getSourceFileHandler = util_1.getSourceFile.bind(_this);
1996
2398
  _this.errorHandler = middleware_1.errorHandler.bind(_this);
1997
2399
  _this.requestHandler = middleware_1.requestHandler.bind(_this);
@@ -1999,8 +2401,8 @@ stacked_store.StackedStore = StackedStore;
1999
2401
  return _this;
2000
2402
  }
2001
2403
  Honeybadger.prototype.factory = function (opts) {
2002
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2003
- var clone = new Honeybadger(opts);
2404
+ var _a;
2405
+ var clone = new Honeybadger(__assign(__assign({}, ((_a = (0, util_1.readConfigFromFileSystem)()) !== null && _a !== void 0 ? _a : {})), opts));
2004
2406
  clone.setNotifier(this.getNotifier());
2005
2407
  return clone;
2006
2408
  };
@@ -2015,20 +2417,64 @@ stacked_store.StackedStore = StackedStore;
2015
2417
  Honeybadger.prototype.showUserFeedbackForm = function () {
2016
2418
  throw new Error('Honeybadger.showUserFeedbackForm() is not supported on the server-side');
2017
2419
  };
2018
- Honeybadger.prototype.checkIn = function (id) {
2019
- var _this = this;
2020
- return this.__transport
2021
- .send({
2022
- method: 'GET',
2023
- endpoint: endpoint(this.config.endpoint, "v1/check_in/".concat(id)),
2024
- logger: this.logger,
2025
- })
2026
- .then(function () {
2027
- _this.logger.info('CheckIn sent');
2028
- return Promise.resolve();
2029
- })
2030
- .catch(function (err) {
2031
- _this.logger.error('CheckIn failed: an unknown error occurred.', "message=".concat(err.message));
2420
+ Honeybadger.prototype.checkIn = function (idOrName) {
2421
+ return __awaiter(this, void 0, void 0, function () {
2422
+ var id, err_1;
2423
+ return __generator(this, function (_a) {
2424
+ switch (_a.label) {
2425
+ case 0:
2426
+ _a.trys.push([0, 3, , 4]);
2427
+ return [4 /*yield*/, this.getCheckinId(idOrName)];
2428
+ case 1:
2429
+ id = _a.sent();
2430
+ return [4 /*yield*/, this.__transport
2431
+ .send({
2432
+ method: 'GET',
2433
+ endpoint: endpoint(this.config.endpoint, "v1/check_in/".concat(id)),
2434
+ logger: this.logger,
2435
+ })];
2436
+ case 2:
2437
+ _a.sent();
2438
+ this.logger.info('CheckIn sent');
2439
+ return [3 /*break*/, 4];
2440
+ case 3:
2441
+ err_1 = _a.sent();
2442
+ this.logger.error("CheckIn[".concat(idOrName, "] failed: an unknown error occurred."), "message=".concat(err_1.message));
2443
+ return [3 /*break*/, 4];
2444
+ case 4: return [2 /*return*/];
2445
+ }
2446
+ });
2447
+ });
2448
+ };
2449
+ Honeybadger.prototype.getCheckinId = function (idOrName) {
2450
+ return __awaiter(this, void 0, void 0, function () {
2451
+ var localCheckin, projectCheckins, remoteCheckin;
2452
+ return __generator(this, function (_a) {
2453
+ switch (_a.label) {
2454
+ case 0:
2455
+ if (!this.config.checkins || this.config.checkins.length === 0) {
2456
+ return [2 /*return*/, idOrName];
2457
+ }
2458
+ localCheckin = this.config.checkins.find(function (c) { return c.name === idOrName; });
2459
+ if (!localCheckin) {
2460
+ return [2 /*return*/, idOrName];
2461
+ }
2462
+ if (localCheckin.id) {
2463
+ return [2 /*return*/, localCheckin.id];
2464
+ }
2465
+ return [4 /*yield*/, this.__checkinsClient.listForProject(localCheckin.projectId)];
2466
+ case 1:
2467
+ projectCheckins = _a.sent();
2468
+ remoteCheckin = projectCheckins.find(function (c) { return c.name === localCheckin.name; });
2469
+ if (!remoteCheckin) {
2470
+ this.logger.debug("Checkin[".concat(idOrName, "] was not found on HB. This should not happen. Was the sync command executed?"));
2471
+ return [2 /*return*/, idOrName];
2472
+ }
2473
+ // store the id locally, so subsequent checkins won't have to call the API
2474
+ localCheckin.id = remoteCheckin.id;
2475
+ return [2 /*return*/, localCheckin.id];
2476
+ }
2477
+ });
2032
2478
  });
2033
2479
  };
2034
2480
  // This method is intended for web frameworks.
@@ -2060,16 +2506,11 @@ stacked_store.StackedStore = StackedStore;
2060
2506
  };
2061
2507
  return Honeybadger;
2062
2508
  }(core_1.Client));
2063
- var singleton = new Honeybadger({
2064
- __plugins: [
2065
- (0, uncaught_exception_plugin_1.default)(),
2066
- (0, unhandled_rejection_plugin_1.default)()
2067
- ],
2068
- });
2509
+ var singleton = new Honeybadger(__assign({ __plugins: DEFAULT_PLUGINS }, ((_a = (0, util_1.readConfigFromFileSystem)()) !== null && _a !== void 0 ? _a : {})));
2069
2510
  var NOTIFIER = {
2070
2511
  name: '@honeybadger-io/js',
2071
2512
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/js',
2072
- version: '6.5.3'
2513
+ version: '6.6.0'
2073
2514
  };
2074
2515
  singleton.setNotifier(NOTIFIER);
2075
2516
  var core_2 = src;