@honeybadger-io/js 6.10.0 → 6.11.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.
@@ -835,9 +835,9 @@ var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(stackTraceParser_esm);
835
835
  } (util$1));
836
836
 
837
837
  Object.defineProperty(events, "__esModule", { value: true });
838
- var util_1$7 = util$1;
839
- function default_1$2(_window) {
840
- if (_window === void 0) { _window = (0, util_1$7.globalThisOrWindow)(); }
838
+ var util_1$8 = util$1;
839
+ function default_1$3(_window) {
840
+ if (_window === void 0) { _window = (0, util_1$8.globalThisOrWindow)(); }
841
841
  return {
842
842
  shouldReloadOnConfigure: false,
843
843
  load: function (client) {
@@ -847,7 +847,7 @@ function default_1$2(_window) {
847
847
  if (!sendEventsToInsights()) {
848
848
  return;
849
849
  }
850
- (0, util_1$7.instrumentConsole)(_window, function (level, args) {
850
+ (0, util_1$8.instrumentConsole)(_window, function (level, args) {
851
851
  if (!sendEventsToInsights()) {
852
852
  return;
853
853
  }
@@ -869,7 +869,7 @@ function default_1$2(_window) {
869
869
  }
870
870
  };
871
871
  }
872
- events.default = default_1$2;
872
+ events.default = default_1$3;
873
873
 
874
874
  var client$1 = {};
875
875
 
@@ -877,7 +877,7 @@ var store = {};
877
877
 
878
878
  Object.defineProperty(store, "__esModule", { value: true });
879
879
  store.GlobalStore = void 0;
880
- var util_1$6 = util$1;
880
+ var util_1$7 = util$1;
881
881
  var GlobalStore = /** @class */ (function () {
882
882
  function GlobalStore(contents, breadcrumbsLimit) {
883
883
  this.contents = contents;
@@ -894,7 +894,7 @@ var GlobalStore = /** @class */ (function () {
894
894
  return JSON.parse(JSON.stringify(value));
895
895
  };
896
896
  GlobalStore.prototype.setContext = function (context) {
897
- this.contents.context = (0, util_1$6.merge)(this.contents.context, context || {});
897
+ this.contents.context = (0, util_1$7.merge)(this.contents.context, context || {});
898
898
  };
899
899
  GlobalStore.prototype.addBreadcrumb = function (breadcrumb) {
900
900
  if (this.contents.breadcrumbs.length == this.breadcrumbsLimit) {
@@ -973,7 +973,7 @@ var __assign$2 = (commonjsGlobal && commonjsGlobal.__assign) || function () {
973
973
  };
974
974
  return __assign$2.apply(this, arguments);
975
975
  };
976
- var __awaiter$3 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
976
+ var __awaiter$4 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
977
977
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
978
978
  return new (P || (P = Promise))(function (resolve, reject) {
979
979
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -982,7 +982,7 @@ var __awaiter$3 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (this
982
982
  step((generator = generator.apply(thisArg, _arguments || [])).next());
983
983
  });
984
984
  };
985
- var __generator$3 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
985
+ var __generator$4 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
986
986
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
987
987
  return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
988
988
  function verb(n) { return function (v) { return step([n, v]); }; }
@@ -1012,7 +1012,7 @@ var __generator$3 = (commonjsGlobal && commonjsGlobal.__generator) || function (
1012
1012
  Object.defineProperty(throttled_events_logger, "__esModule", { value: true });
1013
1013
  throttled_events_logger.ThrottledEventsLogger = void 0;
1014
1014
  var json_nd_1 = require$$0;
1015
- var util_1$5 = util$1;
1015
+ var util_1$6 = util$1;
1016
1016
  var defaults_1$1 = defaults;
1017
1017
  var ThrottledEventsLogger = /** @class */ (function () {
1018
1018
  function ThrottledEventsLogger(config, transport) {
@@ -1034,16 +1034,17 @@ var ThrottledEventsLogger = /** @class */ (function () {
1034
1034
  this.processQueue();
1035
1035
  }
1036
1036
  };
1037
+ ThrottledEventsLogger.prototype.flushAsync = function () {
1038
+ this.logger.debug('[Honeybadger] Flushing events');
1039
+ return this.send();
1040
+ };
1037
1041
  ThrottledEventsLogger.prototype.processQueue = function () {
1038
1042
  var _this = this;
1039
1043
  if (this.queue.length === 0 || this.isProcessing) {
1040
1044
  return;
1041
1045
  }
1042
1046
  this.isProcessing = true;
1043
- var eventsData = this.queue.slice();
1044
- this.queue = [];
1045
- var data = json_nd_1.NdJson.stringify(eventsData);
1046
- this.makeHttpRequest(data)
1047
+ this.send()
1047
1048
  .then(function () {
1048
1049
  setTimeout(function () {
1049
1050
  _this.isProcessing = false;
@@ -1059,10 +1060,24 @@ var ThrottledEventsLogger = /** @class */ (function () {
1059
1060
  }, 50);
1060
1061
  });
1061
1062
  };
1063
+ ThrottledEventsLogger.prototype.send = function () {
1064
+ return __awaiter$4(this, void 0, void 0, function () {
1065
+ var eventsData, data;
1066
+ return __generator$4(this, function (_a) {
1067
+ if (this.queue.length === 0) {
1068
+ return [2 /*return*/];
1069
+ }
1070
+ eventsData = this.queue.slice();
1071
+ this.queue = [];
1072
+ data = json_nd_1.NdJson.stringify(eventsData);
1073
+ return [2 /*return*/, this.makeHttpRequest(data)];
1074
+ });
1075
+ });
1076
+ };
1062
1077
  ThrottledEventsLogger.prototype.makeHttpRequest = function (data) {
1063
- return __awaiter$3(this, void 0, void 0, function () {
1078
+ return __awaiter$4(this, void 0, void 0, function () {
1064
1079
  var _this = this;
1065
- return __generator$3(this, function (_a) {
1080
+ return __generator$4(this, function (_a) {
1066
1081
  return [2 /*return*/, this.transport
1067
1082
  .send({
1068
1083
  headers: {
@@ -1070,7 +1085,7 @@ var ThrottledEventsLogger = /** @class */ (function () {
1070
1085
  'Content-Type': 'application/json',
1071
1086
  },
1072
1087
  method: 'POST',
1073
- endpoint: (0, util_1$5.endpoint)(this.config.endpoint, '/v1/events'),
1088
+ endpoint: (0, util_1$6.endpoint)(this.config.endpoint, '/v1/events'),
1074
1089
  maxObjectDepth: this.config.maxObjectDepth,
1075
1090
  logger: this.logger,
1076
1091
  }, data)
@@ -1122,7 +1137,7 @@ var __assign$1 = (commonjsGlobal && commonjsGlobal.__assign) || function () {
1122
1137
  };
1123
1138
  return __assign$1.apply(this, arguments);
1124
1139
  };
1125
- var __awaiter$2 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
1140
+ var __awaiter$3 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
1126
1141
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1127
1142
  return new (P || (P = Promise))(function (resolve, reject) {
1128
1143
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1131,7 +1146,7 @@ var __awaiter$2 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (this
1131
1146
  step((generator = generator.apply(thisArg, _arguments || [])).next());
1132
1147
  });
1133
1148
  };
1134
- var __generator$2 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
1149
+ var __generator$3 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
1135
1150
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
1136
1151
  return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
1137
1152
  function verb(n) { return function (v) { return step([n, v]); }; }
@@ -1160,7 +1175,7 @@ var __generator$2 = (commonjsGlobal && commonjsGlobal.__generator) || function (
1160
1175
  };
1161
1176
  Object.defineProperty(client$1, "__esModule", { value: true });
1162
1177
  client$1.Client = void 0;
1163
- var util_1$4 = util$1;
1178
+ var util_1$5 = util$1;
1164
1179
  var store_1 = store;
1165
1180
  var throttled_events_logger_1 = throttled_events_logger;
1166
1181
  var defaults_1 = defaults;
@@ -1178,13 +1193,13 @@ var Client = /** @class */ (function () {
1178
1193
  this.__notifier = {
1179
1194
  name: '@honeybadger-io/core',
1180
1195
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/core',
1181
- version: '6.10.0'
1196
+ version: '6.11.0'
1182
1197
  };
1183
1198
  this.config = __assign$1(__assign$1({}, defaults_1.CONFIG), opts);
1184
1199
  this.__initStore();
1185
1200
  this.__transport = transport;
1186
1201
  this.__eventsLogger = new throttled_events_logger_1.ThrottledEventsLogger(this.config, this.__transport);
1187
- this.logger = (0, util_1$4.logger)(this);
1202
+ this.logger = (0, util_1$5.logger)(this);
1188
1203
  }
1189
1204
  Client.prototype.getVersion = function () {
1190
1205
  return this.__notifier.version;
@@ -1255,16 +1270,16 @@ var Client = /** @class */ (function () {
1255
1270
  var notice = this.makeNotice(noticeable, name, extra);
1256
1271
  // we need to have the source file data before the beforeNotifyHandlers,
1257
1272
  // in case they modify them
1258
- var sourceCodeData = notice && notice.backtrace ? notice.backtrace.map(function (trace) { return (0, util_1$4.shallowClone)(trace); }) : null;
1273
+ var sourceCodeData = notice && notice.backtrace ? notice.backtrace.map(function (trace) { return (0, util_1$5.shallowClone)(trace); }) : null;
1259
1274
  var preConditionsResult = this.__runPreconditions(notice);
1260
1275
  if (preConditionsResult instanceof Error) {
1261
- (0, util_1$4.runAfterNotifyHandlers)(notice, this.__afterNotifyHandlers, preConditionsResult);
1276
+ (0, util_1$5.runAfterNotifyHandlers)(notice, this.__afterNotifyHandlers, preConditionsResult);
1262
1277
  return false;
1263
1278
  }
1264
1279
  if (preConditionsResult instanceof Promise) {
1265
1280
  preConditionsResult.then(function (result) {
1266
1281
  if (result instanceof Error) {
1267
- (0, util_1$4.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, result);
1282
+ (0, util_1$5.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, result);
1268
1283
  return false;
1269
1284
  }
1270
1285
  return _this.__send(notice, sourceCodeData);
@@ -1322,18 +1337,18 @@ var Client = /** @class */ (function () {
1322
1337
  Client.prototype.makeNotice = function (noticeable, name, extra) {
1323
1338
  if (name === void 0) { name = undefined; }
1324
1339
  if (extra === void 0) { extra = undefined; }
1325
- var notice = (0, util_1$4.makeNotice)(noticeable);
1340
+ var notice = (0, util_1$5.makeNotice)(noticeable);
1326
1341
  if (name && !(typeof name === 'object')) {
1327
1342
  var n = String(name);
1328
1343
  name = { name: n };
1329
1344
  }
1330
1345
  if (name) {
1331
- notice = (0, util_1$4.mergeNotice)(notice, name);
1346
+ notice = (0, util_1$5.mergeNotice)(notice, name);
1332
1347
  }
1333
1348
  if (typeof extra === 'object' && extra !== null) {
1334
- notice = (0, util_1$4.mergeNotice)(notice, extra);
1349
+ notice = (0, util_1$5.mergeNotice)(notice, extra);
1335
1350
  }
1336
- if ((0, util_1$4.objectIsEmpty)(notice)) {
1351
+ if ((0, util_1$5.objectIsEmpty)(notice)) {
1337
1352
  return null;
1338
1353
  }
1339
1354
  var context = this.__store.getContents('context');
@@ -1343,9 +1358,9 @@ var Client = /** @class */ (function () {
1343
1358
  // Turning into a Set will remove duplicates
1344
1359
  var tags = noticeTags.concat(contextTags).concat(configTags);
1345
1360
  var uniqueTags = tags.filter(function (item, index) { return tags.indexOf(item) === index; });
1346
- notice = (0, util_1$4.merge)(notice, {
1361
+ notice = (0, util_1$5.merge)(notice, {
1347
1362
  name: notice.name || 'Error',
1348
- context: (0, util_1$4.merge)(context, notice.context),
1363
+ context: (0, util_1$5.merge)(context, notice.context),
1349
1364
  projectRoot: notice.projectRoot || this.config.projectRoot,
1350
1365
  environment: notice.environment || this.config.environment,
1351
1366
  component: notice.component || this.config.component,
@@ -1357,11 +1372,11 @@ var Client = /** @class */ (function () {
1357
1372
  // Otherwise we make one.
1358
1373
  if (!Array.isArray(notice.backtrace) || !notice.backtrace.length) {
1359
1374
  if (typeof notice.stack !== 'string' || !notice.stack.trim()) {
1360
- notice.stack = (0, util_1$4.generateStackTrace)();
1361
- notice.backtrace = (0, util_1$4.makeBacktrace)(notice.stack, true, this.logger);
1375
+ notice.stack = (0, util_1$5.generateStackTrace)();
1376
+ notice.backtrace = (0, util_1$5.makeBacktrace)(notice.stack, true, this.logger);
1362
1377
  }
1363
1378
  else {
1364
- notice.backtrace = (0, util_1$4.makeBacktrace)(notice.stack, false, this.logger);
1379
+ notice.backtrace = (0, util_1$5.makeBacktrace)(notice.stack, false, this.logger);
1365
1380
  }
1366
1381
  }
1367
1382
  return notice;
@@ -1371,7 +1386,7 @@ var Client = /** @class */ (function () {
1371
1386
  return;
1372
1387
  }
1373
1388
  opts = opts || {};
1374
- var metadata = (0, util_1$4.shallowClone)(opts.metadata);
1389
+ var metadata = (0, util_1$5.shallowClone)(opts.metadata);
1375
1390
  var category = opts.category || 'custom';
1376
1391
  var timestamp = new Date().toISOString();
1377
1392
  this.__store.addBreadcrumb({
@@ -1386,7 +1401,7 @@ var Client = /** @class */ (function () {
1386
1401
  * @deprecated Use {@link event} instead.
1387
1402
  */
1388
1403
  Client.prototype.logEvent = function (data) {
1389
- (0, util_1$4.logDeprecatedMethod)(this.logger, 'Honeybadger.logEvent', 'Honeybadger.event');
1404
+ (0, util_1$5.logDeprecatedMethod)(this.logger, 'Honeybadger.logEvent', 'Honeybadger.event');
1390
1405
  this.event('log', data);
1391
1406
  };
1392
1407
  Client.prototype.event = function (type, data) {
@@ -1397,6 +1412,13 @@ var Client = /** @class */ (function () {
1397
1412
  }
1398
1413
  this.__eventsLogger.log(__assign$1({ event_type: type, ts: new Date().toISOString() }, data));
1399
1414
  };
1415
+ /**
1416
+ * This method currently flushes the event (Insights) queue.
1417
+ * In the future, it should also flush the error queue (assuming an error throttler is implemented).
1418
+ */
1419
+ Client.prototype.flushAsync = function () {
1420
+ return this.__eventsLogger.flushAsync();
1421
+ };
1400
1422
  Client.prototype.__getBreadcrumbs = function () {
1401
1423
  return this.__store.getContents('breadcrumbs').slice();
1402
1424
  };
@@ -1410,8 +1432,8 @@ var Client = /** @class */ (function () {
1410
1432
  return (this.config.environment && this.config.developmentEnvironments.includes(this.config.environment));
1411
1433
  };
1412
1434
  Client.prototype.__buildPayload = function (notice) {
1413
- var headers = (0, util_1$4.filter)(notice.headers, this.config.filters) || {};
1414
- var cgiData = (0, util_1$4.filter)(__assign$1(__assign$1({}, notice.cgiData), (0, util_1$4.formatCGIData)(headers, 'HTTP_')), this.config.filters);
1435
+ var headers = (0, util_1$5.filter)(notice.headers, this.config.filters) || {};
1436
+ var cgiData = (0, util_1$5.filter)(__assign$1(__assign$1({}, notice.cgiData), (0, util_1$5.formatCGIData)(headers, 'HTTP_')), this.config.filters);
1415
1437
  return {
1416
1438
  notifier: this.__notifier,
1417
1439
  breadcrumbs: {
@@ -1424,16 +1446,16 @@ var Client = /** @class */ (function () {
1424
1446
  backtrace: notice.backtrace,
1425
1447
  fingerprint: notice.fingerprint,
1426
1448
  tags: notice.tags,
1427
- causes: (0, util_1$4.getCauses)(notice, this.logger),
1449
+ causes: (0, util_1$5.getCauses)(notice, this.logger),
1428
1450
  },
1429
1451
  request: {
1430
- url: (0, util_1$4.filterUrl)(notice.url, this.config.filters),
1452
+ url: (0, util_1$5.filterUrl)(notice.url, this.config.filters),
1431
1453
  component: notice.component,
1432
1454
  action: notice.action,
1433
1455
  context: notice.context,
1434
1456
  cgi_data: cgiData,
1435
- params: (0, util_1$4.filter)(notice.params, this.config.filters) || {},
1436
- session: (0, util_1$4.filter)(notice.session, this.config.filters) || {}
1457
+ params: (0, util_1$5.filter)(notice.params, this.config.filters) || {},
1458
+ session: (0, util_1$5.filter)(notice.session, this.config.filters) || {}
1437
1459
  },
1438
1460
  server: {
1439
1461
  project_root: notice.projectRoot,
@@ -1470,7 +1492,7 @@ var Client = /** @class */ (function () {
1470
1492
  this.logger.warn('could not send error report: no API key has been configured', notice);
1471
1493
  preConditionError = new Error('missing API key');
1472
1494
  }
1473
- var beforeNotifyResult = (0, util_1$4.runBeforeNotifyHandlers)(notice, this.__beforeNotifyHandlers);
1495
+ var beforeNotifyResult = (0, util_1$5.runBeforeNotifyHandlers)(notice, this.__beforeNotifyHandlers);
1474
1496
  if (!preConditionError && !beforeNotifyResult.result) {
1475
1497
  this.logger.debug('skipping error report: one or more beforeNotify handlers returned false', notice);
1476
1498
  preConditionError = new Error('beforeNotify handlers returned false');
@@ -1505,10 +1527,10 @@ var Client = /** @class */ (function () {
1505
1527
  else {
1506
1528
  notice.__breadcrumbs = [];
1507
1529
  }
1508
- return (0, util_1$4.getSourceForBacktrace)(originalBacktrace, this.__getSourceFileHandler)
1509
- .then(function (sourcePerTrace) { return __awaiter$2(_this, void 0, void 0, function () {
1530
+ return (0, util_1$5.getSourceForBacktrace)(originalBacktrace, this.__getSourceFileHandler)
1531
+ .then(function (sourcePerTrace) { return __awaiter$3(_this, void 0, void 0, function () {
1510
1532
  var payload;
1511
- return __generator$2(this, function (_a) {
1533
+ return __generator$3(this, function (_a) {
1512
1534
  sourcePerTrace.forEach(function (source, index) {
1513
1535
  notice.backtrace[index].source = source;
1514
1536
  });
@@ -1521,7 +1543,7 @@ var Client = /** @class */ (function () {
1521
1543
  'Accept': 'text/json, application/json'
1522
1544
  },
1523
1545
  method: 'POST',
1524
- endpoint: (0, util_1$4.endpoint)(this.config.endpoint, '/v1/notices/js'),
1546
+ endpoint: (0, util_1$5.endpoint)(this.config.endpoint, '/v1/notices/js'),
1525
1547
  maxObjectDepth: this.config.maxObjectDepth,
1526
1548
  logger: this.logger,
1527
1549
  }, payload)];
@@ -1529,12 +1551,12 @@ var Client = /** @class */ (function () {
1529
1551
  }); })
1530
1552
  .then(function (res) {
1531
1553
  if (res.statusCode !== 201) {
1532
- (0, util_1$4.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, new Error("Bad HTTP response: ".concat(res.statusCode)));
1554
+ (0, util_1$5.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, new Error("Bad HTTP response: ".concat(res.statusCode)));
1533
1555
  _this.logger.warn("Error report failed: unknown response from server. code=".concat(res.statusCode));
1534
1556
  return false;
1535
1557
  }
1536
1558
  var uuid = JSON.parse(res.body).id;
1537
- (0, util_1$4.runAfterNotifyHandlers)((0, util_1$4.merge)(notice, {
1559
+ (0, util_1$5.runAfterNotifyHandlers)((0, util_1$5.merge)(notice, {
1538
1560
  id: uuid
1539
1561
  }), _this.__afterNotifyHandlers);
1540
1562
  _this.logger.info("Error report sent \u26A1 https://app.honeybadger.io/notice/".concat(uuid));
@@ -1542,7 +1564,7 @@ var Client = /** @class */ (function () {
1542
1564
  })
1543
1565
  .catch(function (err) {
1544
1566
  _this.logger.error('Error report failed: an unknown error occurred.', "message=".concat(err.message));
1545
- (0, util_1$4.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, err);
1567
+ (0, util_1$5.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, err);
1546
1568
  return false;
1547
1569
  });
1548
1570
  };
@@ -1600,7 +1622,7 @@ Object.defineProperty(types, "__esModule", { value: true });
1600
1622
 
1601
1623
  var util = {};
1602
1624
 
1603
- var __awaiter$1 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
1625
+ var __awaiter$2 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
1604
1626
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1605
1627
  return new (P || (P = Promise))(function (resolve, reject) {
1606
1628
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1609,7 +1631,7 @@ var __awaiter$1 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (this
1609
1631
  step((generator = generator.apply(thisArg, _arguments || [])).next());
1610
1632
  });
1611
1633
  };
1612
- var __generator$1 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
1634
+ var __generator$2 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
1613
1635
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
1614
1636
  return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
1615
1637
  function verb(n) { return function (v) { return step([n, v]); }; }
@@ -1636,26 +1658,31 @@ var __generator$1 = (commonjsGlobal && commonjsGlobal.__generator) || function (
1636
1658
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
1637
1659
  }
1638
1660
  };
1639
- var __importDefault$3 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1661
+ var __importDefault$4 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1640
1662
  return (mod && mod.__esModule) ? mod : { "default": mod };
1641
1663
  };
1642
1664
  Object.defineProperty(util, "__esModule", { value: true });
1643
- util.readConfigFromFileSystem = util.getSourceFile = util.getStats = util.fatallyLogAndExit = void 0;
1644
- var os_1 = __importDefault$3(require$$0__default["default"]);
1645
- var fs_1 = __importDefault$3(require$$1__default["default"]);
1646
- var path_1 = __importDefault$3(require$$2__default["default"]);
1647
- var util_1$3 = require$$3__default["default"];
1648
- var readFile = (0, util_1$3.promisify)(fs_1.default.readFile);
1649
- function fatallyLogAndExit(err) {
1650
- console.error('[Honeybadger] Exiting process due to uncaught exception');
1665
+ util.readConfigFromFileSystem = util.getSourceFile = util.getStats = util.fatallyLogAndExit = util.fatallyLogAndExitGracefully = void 0;
1666
+ var os_1 = __importDefault$4(require$$0__default["default"]);
1667
+ var fs_1 = __importDefault$4(require$$1__default["default"]);
1668
+ var path_1 = __importDefault$4(require$$2__default["default"]);
1669
+ var util_1$4 = require$$3__default["default"];
1670
+ var readFile = (0, util_1$4.promisify)(fs_1.default.readFile);
1671
+ function fatallyLogAndExitGracefully(signal) {
1672
+ console.log("[Honeybadger] Received ".concat(signal, ", exiting immediately"));
1673
+ process.exit();
1674
+ }
1675
+ util.fatallyLogAndExitGracefully = fatallyLogAndExitGracefully;
1676
+ function fatallyLogAndExit(err, source) {
1677
+ console.error("[Honeybadger] Exiting process due to ".concat(source));
1651
1678
  console.error(err.stack || err);
1652
1679
  process.exit(1);
1653
1680
  }
1654
1681
  util.fatallyLogAndExit = fatallyLogAndExit;
1655
1682
  function getStats() {
1656
- return __awaiter$1(this, void 0, void 0, function () {
1683
+ return __awaiter$2(this, void 0, void 0, function () {
1657
1684
  var load, stats, fallback, memData, data, results;
1658
- return __generator$1(this, function (_a) {
1685
+ return __generator$2(this, function (_a) {
1659
1686
  switch (_a.label) {
1660
1687
  case 0:
1661
1688
  load = os_1.default.loadavg();
@@ -1714,8 +1741,8 @@ util.getStats = getStats;
1714
1741
  * @param path to source code
1715
1742
  */
1716
1743
  function getSourceFile(path) {
1717
- return __awaiter$1(this, void 0, void 0, function () {
1718
- return __generator$1(this, function (_a) {
1744
+ return __awaiter$2(this, void 0, void 0, function () {
1745
+ return __generator$2(this, function (_a) {
1719
1746
  switch (_a.label) {
1720
1747
  case 0:
1721
1748
  _a.trys.push([0, 2, , 3]);
@@ -1852,7 +1879,7 @@ aws_lambda.removeAwsDefaultUncaughtExceptionListener = removeAwsDefaultUncaughtE
1852
1879
 
1853
1880
  Object.defineProperty(uncaught_exception_monitor, "__esModule", { value: true });
1854
1881
  var aws_lambda_1 = aws_lambda;
1855
- var util_1$2 = util;
1882
+ var util_1$3 = util;
1856
1883
  var UncaughtExceptionMonitor = /** @class */ (function () {
1857
1884
  function UncaughtExceptionMonitor() {
1858
1885
  this.__isReporting = false;
@@ -1865,6 +1892,7 @@ var UncaughtExceptionMonitor = /** @class */ (function () {
1865
1892
  };
1866
1893
  UncaughtExceptionMonitor.prototype.makeListener = function () {
1867
1894
  var _this = this;
1895
+ // noinspection UnnecessaryLocalVariableJS
1868
1896
  var honeybadgerUncaughtExceptionListener = function (uncaughtError) {
1869
1897
  if (_this.__isReporting || !_this.__client) {
1870
1898
  return;
@@ -1872,7 +1900,7 @@ var UncaughtExceptionMonitor = /** @class */ (function () {
1872
1900
  // report only the first error - prevent reporting recursive errors
1873
1901
  if (_this.__handlerAlreadyCalled) {
1874
1902
  if (!_this.hasOtherUncaughtExceptionListeners()) {
1875
- (0, util_1$2.fatallyLogAndExit)(uncaughtError);
1903
+ (0, util_1$3.fatallyLogAndExit)(uncaughtError, 'uncaught exception');
1876
1904
  }
1877
1905
  return;
1878
1906
  }
@@ -1883,7 +1911,7 @@ var UncaughtExceptionMonitor = /** @class */ (function () {
1883
1911
  _this.__handlerAlreadyCalled = true;
1884
1912
  _this.__client.config.afterUncaught(uncaughtError);
1885
1913
  if (!_this.hasOtherUncaughtExceptionListeners()) {
1886
- (0, util_1$2.fatallyLogAndExit)(uncaughtError);
1914
+ (0, util_1$3.fatallyLogAndExit)(uncaughtError, 'uncaught exception');
1887
1915
  }
1888
1916
  }
1889
1917
  });
@@ -1929,13 +1957,13 @@ var UncaughtExceptionMonitor = /** @class */ (function () {
1929
1957
  }());
1930
1958
  uncaught_exception_monitor.default = UncaughtExceptionMonitor;
1931
1959
 
1932
- var __importDefault$2 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1960
+ var __importDefault$3 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1933
1961
  return (mod && mod.__esModule) ? mod : { "default": mod };
1934
1962
  };
1935
1963
  Object.defineProperty(uncaught_exception_plugin, "__esModule", { value: true });
1936
- var uncaught_exception_monitor_1 = __importDefault$2(uncaught_exception_monitor);
1964
+ var uncaught_exception_monitor_1 = __importDefault$3(uncaught_exception_monitor);
1937
1965
  var uncaughtExceptionMonitor = new uncaught_exception_monitor_1.default();
1938
- function default_1$1() {
1966
+ function default_1$2() {
1939
1967
  return {
1940
1968
  load: function (client) {
1941
1969
  uncaughtExceptionMonitor.setClient(client);
@@ -1949,14 +1977,14 @@ function default_1$1() {
1949
1977
  shouldReloadOnConfigure: true,
1950
1978
  };
1951
1979
  }
1952
- uncaught_exception_plugin.default = default_1$1;
1980
+ uncaught_exception_plugin.default = default_1$2;
1953
1981
 
1954
1982
  var unhandled_rejection_plugin = {};
1955
1983
 
1956
1984
  var unhandled_rejection_monitor = {};
1957
1985
 
1958
1986
  Object.defineProperty(unhandled_rejection_monitor, "__esModule", { value: true });
1959
- var util_1$1 = util;
1987
+ var util_1$2 = util;
1960
1988
  var UnhandledRejectionMonitor = /** @class */ (function () {
1961
1989
  function UnhandledRejectionMonitor() {
1962
1990
  this.__isReporting = false;
@@ -1967,13 +1995,14 @@ var UnhandledRejectionMonitor = /** @class */ (function () {
1967
1995
  };
1968
1996
  UnhandledRejectionMonitor.prototype.makeListener = function () {
1969
1997
  var _this = this;
1998
+ // noinspection UnnecessaryLocalVariableJS
1970
1999
  var honeybadgerUnhandledRejectionListener = function (reason, _promise) {
1971
2000
  _this.__isReporting = true;
1972
2001
  _this.__client.notify(reason, { component: 'unhandledRejection' }, {
1973
2002
  afterNotify: function () {
1974
2003
  _this.__isReporting = false;
1975
2004
  if (!_this.hasOtherUnhandledRejectionListeners()) {
1976
- (0, util_1$1.fatallyLogAndExit)(reason);
2005
+ (0, util_1$2.fatallyLogAndExit)(reason, 'unhandled rejection');
1977
2006
  }
1978
2007
  }
1979
2008
  });
@@ -2008,13 +2037,13 @@ var UnhandledRejectionMonitor = /** @class */ (function () {
2008
2037
  }());
2009
2038
  unhandled_rejection_monitor.default = UnhandledRejectionMonitor;
2010
2039
 
2011
- var __importDefault$1 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
2040
+ var __importDefault$2 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
2012
2041
  return (mod && mod.__esModule) ? mod : { "default": mod };
2013
2042
  };
2014
2043
  Object.defineProperty(unhandled_rejection_plugin, "__esModule", { value: true });
2015
- var unhandled_rejection_monitor_1 = __importDefault$1(unhandled_rejection_monitor);
2044
+ var unhandled_rejection_monitor_1 = __importDefault$2(unhandled_rejection_monitor);
2016
2045
  var unhandledRejectionMonitor = new unhandled_rejection_monitor_1.default();
2017
- function default_1() {
2046
+ function default_1$1() {
2018
2047
  return {
2019
2048
  load: function (client) {
2020
2049
  unhandledRejectionMonitor.setClient(client);
@@ -2028,7 +2057,137 @@ function default_1() {
2028
2057
  shouldReloadOnConfigure: true,
2029
2058
  };
2030
2059
  }
2031
- unhandled_rejection_plugin.default = default_1;
2060
+ unhandled_rejection_plugin.default = default_1$1;
2061
+
2062
+ var shutdown_plugin = {};
2063
+
2064
+ var shutdown_monitor = {};
2065
+
2066
+ var __awaiter$1 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
2067
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2068
+ return new (P || (P = Promise))(function (resolve, reject) {
2069
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
2070
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
2071
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
2072
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
2073
+ });
2074
+ };
2075
+ var __generator$1 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
2076
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
2077
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
2078
+ function verb(n) { return function (v) { return step([n, v]); }; }
2079
+ function step(op) {
2080
+ if (f) throw new TypeError("Generator is already executing.");
2081
+ while (_) try {
2082
+ 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;
2083
+ if (y = 0, t) op = [op[0] & 2, t.value];
2084
+ switch (op[0]) {
2085
+ case 0: case 1: t = op; break;
2086
+ case 4: _.label++; return { value: op[1], done: false };
2087
+ case 5: _.label++; y = op[1]; op = [0]; continue;
2088
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
2089
+ default:
2090
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
2091
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
2092
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
2093
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
2094
+ if (t[2]) _.ops.pop();
2095
+ _.trys.pop(); continue;
2096
+ }
2097
+ op = body.call(thisArg, _);
2098
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
2099
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
2100
+ }
2101
+ };
2102
+ Object.defineProperty(shutdown_monitor, "__esModule", { value: true });
2103
+ var util_1$1 = util;
2104
+ var ShutdownMonitor = /** @class */ (function () {
2105
+ function ShutdownMonitor() {
2106
+ this.__isReporting = false;
2107
+ this.__listener = this.makeListener();
2108
+ }
2109
+ ShutdownMonitor.prototype.setClient = function (client) {
2110
+ this.__client = client;
2111
+ };
2112
+ ShutdownMonitor.prototype.makeListener = function () {
2113
+ var _this = this;
2114
+ // noinspection UnnecessaryLocalVariableJS
2115
+ var honeybadgerShutdownListener = function (signal) { return __awaiter$1(_this, void 0, void 0, function () {
2116
+ return __generator$1(this, function (_a) {
2117
+ switch (_a.label) {
2118
+ case 0:
2119
+ if (this.__isReporting || !this.__client) {
2120
+ return [2 /*return*/];
2121
+ }
2122
+ this.__isReporting = true;
2123
+ return [4 /*yield*/, this.__client.flushAsync()];
2124
+ case 1:
2125
+ _a.sent();
2126
+ this.__isReporting = false;
2127
+ if (!this.hasOtherShutdownListeners(signal)) {
2128
+ (0, util_1$1.fatallyLogAndExitGracefully)(signal);
2129
+ }
2130
+ return [2 /*return*/];
2131
+ }
2132
+ });
2133
+ }); };
2134
+ return honeybadgerShutdownListener;
2135
+ };
2136
+ ShutdownMonitor.prototype.maybeAddListener = function () {
2137
+ for (var _i = 0, _a = ShutdownMonitor.KILL_SIGNALS; _i < _a.length; _i++) {
2138
+ var signal = _a[_i];
2139
+ var signalListeners = process.listeners(signal);
2140
+ if (!signalListeners.includes(this.__listener)) {
2141
+ process.on(signal, this.__listener);
2142
+ }
2143
+ }
2144
+ };
2145
+ ShutdownMonitor.prototype.maybeRemoveListener = function () {
2146
+ for (var _i = 0, _a = ShutdownMonitor.KILL_SIGNALS; _i < _a.length; _i++) {
2147
+ var signal = _a[_i];
2148
+ var signalListeners = process.listeners(signal);
2149
+ if (signalListeners.includes(this.__listener)) {
2150
+ process.removeListener(signal, this.__listener);
2151
+ }
2152
+ }
2153
+ };
2154
+ ShutdownMonitor.prototype.hasOtherShutdownListeners = function (signal) {
2155
+ var _this = this;
2156
+ var otherListeners = process
2157
+ .listeners(signal)
2158
+ .filter(function (listener) { return listener !== _this.__listener; });
2159
+ return otherListeners.length > 0;
2160
+ };
2161
+ // SIGTERM is raised by AWS Lambda when the function is being shut down
2162
+ // SIGINT is raised by the user pressing CTRL+C
2163
+ ShutdownMonitor.KILL_SIGNALS = ['SIGTERM', 'SIGINT'];
2164
+ return ShutdownMonitor;
2165
+ }());
2166
+ shutdown_monitor.default = ShutdownMonitor;
2167
+
2168
+ var __importDefault$1 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
2169
+ return (mod && mod.__esModule) ? mod : { "default": mod };
2170
+ };
2171
+ Object.defineProperty(shutdown_plugin, "__esModule", { value: true });
2172
+ var shutdown_monitor_1 = __importDefault$1(shutdown_monitor);
2173
+ var shutdownMonitor = new shutdown_monitor_1.default();
2174
+ function default_1() {
2175
+ return {
2176
+ load: function (client) {
2177
+ shutdownMonitor.setClient(client);
2178
+ // at the moment, the shutdown monitor only sends events from the queue
2179
+ // if we implement a queue for throttling errors, we won't have to check for `config.eventsEnabled`
2180
+ if (client.config.eventsEnabled) {
2181
+ shutdownMonitor.maybeAddListener();
2182
+ }
2183
+ else {
2184
+ shutdownMonitor.maybeRemoveListener();
2185
+ }
2186
+ },
2187
+ shouldReloadOnConfigure: true,
2188
+ };
2189
+ }
2190
+ shutdown_plugin.default = default_1;
2032
2191
 
2033
2192
  var middleware = {};
2034
2193
 
@@ -2700,6 +2859,7 @@ client.CheckInsClient = CheckInsClient;
2700
2859
  var util_1 = util;
2701
2860
  var uncaught_exception_plugin_1 = __importDefault(uncaught_exception_plugin);
2702
2861
  var unhandled_rejection_plugin_1 = __importDefault(unhandled_rejection_plugin);
2862
+ var shutdown_plugin_1 = __importDefault(shutdown_plugin);
2703
2863
  var middleware_1 = middleware;
2704
2864
  var aws_lambda_1 = aws_lambda;
2705
2865
  var transport_1 = transport;
@@ -2709,6 +2869,7 @@ client.CheckInsClient = CheckInsClient;
2709
2869
  var DEFAULT_PLUGINS = [
2710
2870
  (0, uncaught_exception_plugin_1.default)(),
2711
2871
  (0, unhandled_rejection_plugin_1.default)(),
2872
+ (0, shutdown_plugin_1.default)(),
2712
2873
  core_1.Plugins.events(),
2713
2874
  ];
2714
2875
  var Honeybadger = /** @class */ (function (_super) {
@@ -2861,7 +3022,7 @@ client.CheckInsClient = CheckInsClient;
2861
3022
  var NOTIFIER = {
2862
3023
  name: '@honeybadger-io/js',
2863
3024
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/js',
2864
- version: '6.10.0'
3025
+ version: '6.11.0'
2865
3026
  };
2866
3027
  var userAgent = function () {
2867
3028
  return "Honeybadger JS Server Client ".concat(NOTIFIER.version, ", ").concat(os_1.default.version(), "; ").concat(os_1.default.platform());