@honeybadger-io/js 4.7.1 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  import { Types } from '@honeybadger-io/core';
2
- export default function (_window?: Window & typeof globalThis): Types.Plugin;
2
+ export default function (_window?: typeof globalThis): Types.Plugin;
3
3
  //# sourceMappingURL=breadcrumbs.d.ts.map
@@ -1,3 +1,3 @@
1
1
  import { Types } from '@honeybadger-io/core';
2
- export default function (_window?: Window & typeof globalThis): Types.Plugin;
2
+ export default function (_window?: typeof globalThis): Types.Plugin;
3
3
  //# sourceMappingURL=event_listeners.d.ts.map
@@ -1,3 +1,3 @@
1
1
  import { Types } from '@honeybadger-io/core';
2
- export default function (_window?: Window & typeof globalThis): Types.Plugin;
2
+ export default function (_window?: typeof globalThis): Types.Plugin;
3
3
  //# sourceMappingURL=timers.d.ts.map
@@ -16,4 +16,8 @@ export declare function localURLPathname(url: any): any;
16
16
  export declare function decodeCookie(string: string): Record<string, unknown>;
17
17
  export declare function encodeCookie(object: any): string;
18
18
  export declare const preferCatch: boolean;
19
+ /** globalThis has fairly good support. But just in case, lets check its defined.
20
+ * @see {https://caniuse.com/?search=globalThis}
21
+ */
22
+ export declare function globalThisOrWindow(): typeof globalThis;
19
23
  //# sourceMappingURL=util.d.ts.map
@@ -703,7 +703,7 @@ var store = {};
703
703
 
704
704
  Object.defineProperty(store, "__esModule", { value: true });
705
705
  store.GlobalStore = void 0;
706
- var util_1$4 = util$1;
706
+ var util_1$5 = util$1;
707
707
  var GlobalStore = /** @class */ (function () {
708
708
  function GlobalStore(contents, breadcrumbsLimit) {
709
709
  this.contents = contents;
@@ -720,7 +720,7 @@ var GlobalStore = /** @class */ (function () {
720
720
  return JSON.parse(JSON.stringify(value));
721
721
  };
722
722
  GlobalStore.prototype.setContext = function (context) {
723
- this.contents.context = (0, util_1$4.merge)(this.contents.context, context || {});
723
+ this.contents.context = (0, util_1$5.merge)(this.contents.context, context || {});
724
724
  };
725
725
  GlobalStore.prototype.addBreadcrumb = function (breadcrumb) {
726
726
  if (this.contents.breadcrumbs.length == this.breadcrumbsLimit) {
@@ -752,12 +752,12 @@ var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
752
752
  };
753
753
  Object.defineProperty(client, "__esModule", { value: true });
754
754
  client.Client = void 0;
755
- var util_1$3 = util$1;
755
+ var util_1$4 = util$1;
756
756
  var store_1 = store;
757
757
  var notifier = {
758
758
  name: 'honeybadger-js',
759
759
  url: 'https://github.com/honeybadger-io/honeybadger-js',
760
- version: '4.7.1'
760
+ version: '4.8.0'
761
761
  };
762
762
  // Split at commas and spaces
763
763
  var TAG_SEPARATOR = /,|\s+/;
@@ -773,7 +773,7 @@ var Client = /** @class */ (function () {
773
773
  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);
774
774
  this.__initStore();
775
775
  this.__transport = transport;
776
- this.logger = (0, util_1$3.logger)(this);
776
+ this.logger = (0, util_1$4.logger)(this);
777
777
  }
778
778
  Client.prototype.getVersion = function () {
779
779
  return notifier.version;
@@ -843,14 +843,14 @@ var Client = /** @class */ (function () {
843
843
  }
844
844
  // we need to have the source file data before the beforeNotifyHandlers,
845
845
  // in case they modify them
846
- var sourceCodeData = notice && notice.backtrace ? notice.backtrace.map(function (trace) { return (0, util_1$3.shallowClone)(trace); }) : null;
847
- var beforeNotifyResult = (0, util_1$3.runBeforeNotifyHandlers)(notice, this.__beforeNotifyHandlers);
846
+ var sourceCodeData = notice && notice.backtrace ? notice.backtrace.map(function (trace) { return (0, util_1$4.shallowClone)(trace); }) : null;
847
+ var beforeNotifyResult = (0, util_1$4.runBeforeNotifyHandlers)(notice, this.__beforeNotifyHandlers);
848
848
  if (!preConditionError && !beforeNotifyResult) {
849
849
  this.logger.debug('skipping error report: beforeNotify handlers returned false', notice);
850
850
  preConditionError = new Error('beforeNotify handlers returned false');
851
851
  }
852
852
  if (preConditionError) {
853
- (0, util_1$3.runAfterNotifyHandlers)(notice, this.__afterNotifyHandlers, preConditionError);
853
+ (0, util_1$4.runAfterNotifyHandlers)(notice, this.__afterNotifyHandlers, preConditionError);
854
854
  return false;
855
855
  }
856
856
  this.addBreadcrumb('Honeybadger Notice', {
@@ -863,7 +863,7 @@ var Client = /** @class */ (function () {
863
863
  });
864
864
  var breadcrumbs = this.__store.getContents('breadcrumbs');
865
865
  notice.__breadcrumbs = this.config.breadcrumbsEnabled ? breadcrumbs : [];
866
- (0, util_1$3.getSourceForBacktrace)(sourceCodeData, this.__getSourceFileHandler)
866
+ (0, util_1$4.getSourceForBacktrace)(sourceCodeData, this.__getSourceFileHandler)
867
867
  .then(function (sourcePerTrace) {
868
868
  sourcePerTrace.forEach(function (source, index) {
869
869
  notice.backtrace[index].source = source;
@@ -877,26 +877,25 @@ var Client = /** @class */ (function () {
877
877
  'Accept': 'text/json, application/json'
878
878
  },
879
879
  method: 'POST',
880
- endpoint: (0, util_1$3.endpoint)(_this.config.endpoint, '/v1/notices/js'),
880
+ endpoint: (0, util_1$4.endpoint)(_this.config.endpoint, '/v1/notices/js'),
881
881
  maxObjectDepth: _this.config.maxObjectDepth,
882
882
  logger: _this.logger,
883
- async: (0, util_1$3.isBrowserConfig)(_this.config) ? _this.config.async : undefined,
884
883
  }, payload)
885
884
  .then(function (res) {
886
885
  if (res.statusCode !== 201) {
887
- (0, util_1$3.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, new Error("Bad HTTP response: ".concat(res.statusCode)));
886
+ (0, util_1$4.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, new Error("Bad HTTP response: ".concat(res.statusCode)));
888
887
  _this.logger.warn("Error report failed: unknown response from server. code=".concat(res.statusCode));
889
888
  return;
890
889
  }
891
890
  var uuid = JSON.parse(res.body).id;
892
- (0, util_1$3.runAfterNotifyHandlers)((0, util_1$3.merge)(notice, {
891
+ (0, util_1$4.runAfterNotifyHandlers)((0, util_1$4.merge)(notice, {
893
892
  id: uuid
894
893
  }), _this.__afterNotifyHandlers);
895
894
  _this.logger.info("Error report sent \u26A1 https://app.honeybadger.io/notice/".concat(uuid));
896
895
  })
897
896
  .catch(function (err) {
898
897
  _this.logger.error('Error report failed: an unknown error occurred.', "message=".concat(err.message));
899
- (0, util_1$3.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, err);
898
+ (0, util_1$4.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, err);
900
899
  });
901
900
  });
902
901
  return true;
@@ -949,18 +948,18 @@ var Client = /** @class */ (function () {
949
948
  Client.prototype.makeNotice = function (noticeable, name, extra) {
950
949
  if (name === void 0) { name = undefined; }
951
950
  if (extra === void 0) { extra = undefined; }
952
- var notice = (0, util_1$3.makeNotice)(noticeable);
951
+ var notice = (0, util_1$4.makeNotice)(noticeable);
953
952
  if (name && !(typeof name === 'object')) {
954
953
  var n = String(name);
955
954
  name = { name: n };
956
955
  }
957
956
  if (name) {
958
- notice = (0, util_1$3.mergeNotice)(notice, name);
957
+ notice = (0, util_1$4.mergeNotice)(notice, name);
959
958
  }
960
959
  if (typeof extra === 'object' && extra !== null) {
961
- notice = (0, util_1$3.mergeNotice)(notice, extra);
960
+ notice = (0, util_1$4.mergeNotice)(notice, extra);
962
961
  }
963
- if ((0, util_1$3.objectIsEmpty)(notice)) {
962
+ if ((0, util_1$4.objectIsEmpty)(notice)) {
964
963
  return null;
965
964
  }
966
965
  var context = this.__store.getContents('context');
@@ -970,9 +969,9 @@ var Client = /** @class */ (function () {
970
969
  // Turning into a Set will remove duplicates
971
970
  var tags = noticeTags.concat(contextTags).concat(configTags);
972
971
  var uniqueTags = tags.filter(function (item, index) { return tags.indexOf(item) === index; });
973
- notice = (0, util_1$3.merge)(notice, {
972
+ notice = (0, util_1$4.merge)(notice, {
974
973
  name: notice.name || 'Error',
975
- context: (0, util_1$3.merge)(context, notice.context),
974
+ context: (0, util_1$4.merge)(context, notice.context),
976
975
  projectRoot: notice.projectRoot || this.config.projectRoot,
977
976
  environment: notice.environment || this.config.environment,
978
977
  component: notice.component || this.config.component,
@@ -982,10 +981,10 @@ var Client = /** @class */ (function () {
982
981
  });
983
982
  var backtraceShift = 0;
984
983
  if (typeof notice.stack !== 'string' || !notice.stack.trim()) {
985
- notice.stack = (0, util_1$3.generateStackTrace)();
984
+ notice.stack = (0, util_1$4.generateStackTrace)();
986
985
  backtraceShift = 2;
987
986
  }
988
- notice.backtrace = (0, util_1$3.makeBacktrace)(notice.stack, backtraceShift);
987
+ notice.backtrace = (0, util_1$4.makeBacktrace)(notice.stack, backtraceShift);
989
988
  return notice;
990
989
  };
991
990
  Client.prototype.addBreadcrumb = function (message, opts) {
@@ -993,7 +992,7 @@ var Client = /** @class */ (function () {
993
992
  return;
994
993
  }
995
994
  opts = opts || {};
996
- var metadata = (0, util_1$3.shallowClone)(opts.metadata);
995
+ var metadata = (0, util_1$4.shallowClone)(opts.metadata);
997
996
  var category = opts.category || 'custom';
998
997
  var timestamp = new Date().toISOString();
999
998
  this.__store.addBreadcrumb({
@@ -1017,8 +1016,8 @@ var Client = /** @class */ (function () {
1017
1016
  return (this.config.environment && this.config.developmentEnvironments.includes(this.config.environment));
1018
1017
  };
1019
1018
  Client.prototype.__buildPayload = function (notice) {
1020
- var headers = (0, util_1$3.filter)(notice.headers, this.config.filters) || {};
1021
- var cgiData = (0, util_1$3.filter)(__assign(__assign({}, notice.cgiData), (0, util_1$3.formatCGIData)(headers, 'HTTP_')), this.config.filters);
1019
+ var headers = (0, util_1$4.filter)(notice.headers, this.config.filters) || {};
1020
+ var cgiData = (0, util_1$4.filter)(__assign(__assign({}, notice.cgiData), (0, util_1$4.formatCGIData)(headers, 'HTTP_')), this.config.filters);
1022
1021
  return {
1023
1022
  notifier: notifier,
1024
1023
  breadcrumbs: {
@@ -1031,16 +1030,16 @@ var Client = /** @class */ (function () {
1031
1030
  backtrace: notice.backtrace,
1032
1031
  fingerprint: notice.fingerprint,
1033
1032
  tags: notice.tags,
1034
- causes: (0, util_1$3.getCauses)(notice),
1033
+ causes: (0, util_1$4.getCauses)(notice),
1035
1034
  },
1036
1035
  request: {
1037
- url: (0, util_1$3.filterUrl)(notice.url, this.config.filters),
1036
+ url: (0, util_1$4.filterUrl)(notice.url, this.config.filters),
1038
1037
  component: notice.component,
1039
1038
  action: notice.action,
1040
1039
  context: notice.context,
1041
1040
  cgi_data: cgiData,
1042
- params: (0, util_1$3.filter)(notice.params, this.config.filters) || {},
1043
- session: (0, util_1$3.filter)(notice.session, this.config.filters) || {}
1041
+ params: (0, util_1$4.filter)(notice.params, this.config.filters) || {},
1042
+ session: (0, util_1$4.filter)(notice.session, this.config.filters) || {}
1044
1043
  },
1045
1044
  server: {
1046
1045
  project_root: notice.projectRoot,
@@ -1100,6 +1099,7 @@ Object.defineProperty(types, "__esModule", { value: true });
1100
1099
  __exportStar(store, exports);
1101
1100
  exports.Types = __importStar(types);
1102
1101
  exports.Util = __importStar(util$1);
1102
+
1103
1103
  } (src));
1104
1104
 
1105
1105
  var util = {};
@@ -1147,8 +1147,8 @@ Object.defineProperty(util, "__esModule", { value: true });
1147
1147
  util.getSourceFile = util.getStats = util.fatallyLogAndExit = void 0;
1148
1148
  var os_1 = __importDefault$2(require$$0__default["default"]);
1149
1149
  var fs_1 = __importDefault$2(require$$1__default["default"]);
1150
- var util_1$2 = require$$2__default["default"];
1151
- var readFile = (0, util_1$2.promisify)(fs_1.default.readFile);
1150
+ var util_1$3 = require$$2__default["default"];
1151
+ var readFile = (0, util_1$3.promisify)(fs_1.default.readFile);
1152
1152
  function fatallyLogAndExit(err) {
1153
1153
  console.error('[Honeybadger] Exiting process due to uncaught exception');
1154
1154
  console.error(err.stack || err);
@@ -1339,9 +1339,10 @@ function removeAwsDefaultUncaughtExceptionListener() {
1339
1339
  aws_lambda.removeAwsDefaultUncaughtExceptionListener = removeAwsDefaultUncaughtExceptionListener;
1340
1340
 
1341
1341
  Object.defineProperty(uncaught_exception, "__esModule", { value: true });
1342
- var util_1$1 = util;
1342
+ var util_1$2 = util;
1343
1343
  var aws_lambda_1 = aws_lambda;
1344
- var count = 0;
1344
+ var isReporting$1 = false;
1345
+ var handlerAlreadyCalled = false;
1345
1346
  function removeAwsLambdaListener() {
1346
1347
  var isLambda = !!process.env.LAMBDA_TASK_ROOT;
1347
1348
  if (!isLambda) {
@@ -1349,6 +1350,15 @@ function removeAwsLambdaListener() {
1349
1350
  }
1350
1351
  (0, aws_lambda_1.removeAwsDefaultUncaughtExceptionListener)();
1351
1352
  }
1353
+ /**
1354
+ * If there are no other uncaughtException listeners,
1355
+ * we want to report the exception to Honeybadger and
1356
+ * mimic the default behavior of NodeJs,
1357
+ * which is to exit the process with code 1
1358
+ */
1359
+ function hasOtherUncaughtExceptionListeners() {
1360
+ return process.listeners('uncaughtException').length > 1;
1361
+ }
1352
1362
  function default_1$1() {
1353
1363
  return {
1354
1364
  load: function (client) {
@@ -1357,22 +1367,34 @@ function default_1$1() {
1357
1367
  }
1358
1368
  removeAwsLambdaListener();
1359
1369
  process.on('uncaughtException', function honeybadgerUncaughtExceptionListener(uncaughtError) {
1360
- // Prevent recursive errors
1361
- if (count > 1) {
1362
- (0, util_1$1.fatallyLogAndExit)(uncaughtError);
1370
+ if (!client.config.enableUncaught) {
1371
+ client.config.afterUncaught(uncaughtError);
1372
+ if (!hasOtherUncaughtExceptionListeners()) {
1373
+ (0, util_1$2.fatallyLogAndExit)(uncaughtError);
1374
+ }
1375
+ return;
1363
1376
  }
1364
- if (client.config.enableUncaught) {
1365
- client.notify(uncaughtError, {
1366
- afterNotify: function (_err, _notice) {
1367
- count += 1;
1368
- client.config.afterUncaught(uncaughtError);
1369
- }
1370
- });
1377
+ // report only the first error - prevent reporting recursive errors
1378
+ if (handlerAlreadyCalled) {
1379
+ if (!hasOtherUncaughtExceptionListeners()) {
1380
+ (0, util_1$2.fatallyLogAndExit)(uncaughtError);
1381
+ }
1382
+ return;
1371
1383
  }
1372
- else {
1373
- count += 1;
1374
- client.config.afterUncaught(uncaughtError);
1384
+ if (isReporting$1) {
1385
+ return;
1375
1386
  }
1387
+ isReporting$1 = true;
1388
+ client.notify(uncaughtError, {
1389
+ afterNotify: function (_err, _notice) {
1390
+ isReporting$1 = false;
1391
+ handlerAlreadyCalled = true;
1392
+ client.config.afterUncaught(uncaughtError);
1393
+ if (!hasOtherUncaughtExceptionListeners()) {
1394
+ (0, util_1$2.fatallyLogAndExit)(uncaughtError);
1395
+ }
1396
+ }
1397
+ });
1376
1398
  });
1377
1399
  }
1378
1400
  };
@@ -1382,17 +1404,39 @@ uncaught_exception.default = default_1$1;
1382
1404
  var unhandled_rejection = {};
1383
1405
 
1384
1406
  Object.defineProperty(unhandled_rejection, "__esModule", { value: true });
1407
+ var util_1$1 = util;
1408
+ var isReporting = false;
1409
+ /**
1410
+ * If there are no other unhandledRejection listeners,
1411
+ * we want to report the exception to Honeybadger and
1412
+ * mimic the default behavior of NodeJs,
1413
+ * which is to exit the process with code 1
1414
+ */
1415
+ function hasOtherUnhandledRejectionListeners() {
1416
+ return process.listeners('unhandledRejection').length > 1;
1417
+ }
1385
1418
  function default_1() {
1386
1419
  return {
1387
1420
  load: function (client) {
1388
1421
  if (!client.config.enableUnhandledRejection) {
1389
1422
  return;
1390
1423
  }
1391
- process.on('unhandledRejection', function (reason, _promise) {
1424
+ process.on('unhandledRejection', function honeybadgerUnhandledRejectionListener(reason, _promise) {
1392
1425
  if (!client.config.enableUnhandledRejection) {
1426
+ if (!hasOtherUnhandledRejectionListeners() && !isReporting) {
1427
+ (0, util_1$1.fatallyLogAndExit)(reason);
1428
+ }
1393
1429
  return;
1394
1430
  }
1395
- client.notify(reason, { component: 'unhandledRejection' });
1431
+ isReporting = true;
1432
+ client.notify(reason, { component: 'unhandledRejection' }, {
1433
+ afterNotify: function () {
1434
+ isReporting = false;
1435
+ if (!hasOtherUnhandledRejectionListeners()) {
1436
+ (0, util_1$1.fatallyLogAndExit)(reason);
1437
+ }
1438
+ }
1439
+ });
1396
1440
  });
1397
1441
  }
1398
1442
  };
@@ -1777,8 +1821,10 @@ stacked_store.StackedStore = StackedStore;
1777
1821
  (0, unhandled_rejection_1.default)()
1778
1822
  ],
1779
1823
  });
1824
+
1780
1825
  } (server$1));
1781
1826
 
1782
1827
  var server = /*@__PURE__*/getDefaultExportFromCjs(server$1);
1783
1828
 
1784
1829
  module.exports = server;
1830
+ //# sourceMappingURL=honeybadger.js.map