@honeybadger-io/js 6.4.1 → 6.4.3

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.
@@ -864,14 +864,14 @@ var NOT_BLANK = /\S/;
864
864
  var Client = /** @class */ (function () {
865
865
  function Client(opts, transport) {
866
866
  if (opts === void 0) { opts = {}; }
867
- this.__pluginsExecuted = false;
867
+ this.__pluginsLoaded = false;
868
868
  this.__store = null;
869
869
  this.__beforeNotifyHandlers = [];
870
870
  this.__afterNotifyHandlers = [];
871
871
  this.__notifier = {
872
872
  name: '@honeybadger-io/core',
873
873
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/core',
874
- version: '6.4.1'
874
+ version: '6.4.3'
875
875
  };
876
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);
877
877
  this.__initStore();
@@ -895,17 +895,21 @@ var Client = /** @class */ (function () {
895
895
  this.__notifier = notifier;
896
896
  };
897
897
  Client.prototype.configure = function (opts) {
898
- var _this = this;
899
898
  if (opts === void 0) { opts = {}; }
900
899
  for (var k in opts) {
901
900
  this.config[k] = opts[k];
902
901
  }
903
- if (!this.__pluginsExecuted) {
904
- this.__pluginsExecuted = true;
905
- this.config.__plugins.forEach(function (plugin) { return plugin.load(_this); });
906
- }
902
+ this.loadPlugins();
907
903
  return this;
908
904
  };
905
+ Client.prototype.loadPlugins = function () {
906
+ var _this = this;
907
+ var pluginsToLoad = this.__pluginsLoaded
908
+ ? this.config.__plugins.filter(function (plugin) { return plugin.shouldReloadOnConfigure; })
909
+ : this.config.__plugins;
910
+ pluginsToLoad.forEach(function (plugin) { return plugin.load(_this); });
911
+ this.__pluginsLoaded = true;
912
+ };
909
913
  Client.prototype.__initStore = function () {
910
914
  this.__store = new store_1.GlobalStore({ context: {}, breadcrumbs: [] }, this.config.maxBreadcrumbs);
911
915
  };
@@ -1301,13 +1305,13 @@ var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (th
1301
1305
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
1302
1306
  }
1303
1307
  };
1304
- var __importDefault$3 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1308
+ var __importDefault$4 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1305
1309
  return (mod && mod.__esModule) ? mod : { "default": mod };
1306
1310
  };
1307
1311
  Object.defineProperty(util, "__esModule", { value: true });
1308
1312
  util.getSourceFile = util.getStats = util.fatallyLogAndExit = void 0;
1309
- var os_1 = __importDefault$3(require$$0__default["default"]);
1310
- var fs_1 = __importDefault$3(require$$1__default["default"]);
1313
+ var os_1 = __importDefault$4(require$$0__default["default"]);
1314
+ var fs_1 = __importDefault$4(require$$1__default["default"]);
1311
1315
  var util_1$3 = require$$2__default["default"];
1312
1316
  var readFile = (0, util_1$3.promisify)(fs_1.default.readFile);
1313
1317
  function fatallyLogAndExit(err) {
@@ -1505,12 +1509,61 @@ Object.defineProperty(uncaught_exception_monitor, "__esModule", { value: true })
1505
1509
  var aws_lambda_1 = aws_lambda;
1506
1510
  var util_1$2 = util;
1507
1511
  var UncaughtExceptionMonitor = /** @class */ (function () {
1508
- function UncaughtExceptionMonitor(client) {
1512
+ function UncaughtExceptionMonitor() {
1509
1513
  this.__isReporting = false;
1510
1514
  this.__handlerAlreadyCalled = false;
1511
- this.__client = client;
1515
+ this.__listener = this.makeListener();
1512
1516
  this.removeAwsLambdaListener();
1513
1517
  }
1518
+ UncaughtExceptionMonitor.prototype.setClient = function (client) {
1519
+ this.__client = client;
1520
+ };
1521
+ UncaughtExceptionMonitor.prototype.makeListener = function () {
1522
+ var _this = this;
1523
+ var honeybadgerUncaughtExceptionListener = function (uncaughtError) {
1524
+ if (_this.__isReporting || !_this.__client) {
1525
+ return;
1526
+ }
1527
+ if (!_this.__client.config.enableUncaught) {
1528
+ _this.__client.config.afterUncaught(uncaughtError);
1529
+ if (!_this.hasOtherUncaughtExceptionListeners()) {
1530
+ (0, util_1$2.fatallyLogAndExit)(uncaughtError);
1531
+ }
1532
+ return;
1533
+ }
1534
+ // report only the first error - prevent reporting recursive errors
1535
+ if (_this.__handlerAlreadyCalled) {
1536
+ if (!_this.hasOtherUncaughtExceptionListeners()) {
1537
+ (0, util_1$2.fatallyLogAndExit)(uncaughtError);
1538
+ }
1539
+ return;
1540
+ }
1541
+ _this.__isReporting = true;
1542
+ _this.__client.notify(uncaughtError, {
1543
+ afterNotify: function (_err, _notice) {
1544
+ _this.__isReporting = false;
1545
+ _this.__handlerAlreadyCalled = true;
1546
+ _this.__client.config.afterUncaught(uncaughtError);
1547
+ if (!_this.hasOtherUncaughtExceptionListeners()) {
1548
+ (0, util_1$2.fatallyLogAndExit)(uncaughtError);
1549
+ }
1550
+ }
1551
+ });
1552
+ };
1553
+ return honeybadgerUncaughtExceptionListener;
1554
+ };
1555
+ UncaughtExceptionMonitor.prototype.maybeAddListener = function () {
1556
+ var listeners = process.listeners('uncaughtException');
1557
+ if (!listeners.includes(this.__listener)) {
1558
+ process.on('uncaughtException', this.__listener);
1559
+ }
1560
+ };
1561
+ UncaughtExceptionMonitor.prototype.maybeRemoveListener = function () {
1562
+ var listeners = process.listeners('uncaughtException');
1563
+ if (listeners.includes(this.__listener)) {
1564
+ process.removeListener('uncaughtException', this.__listener);
1565
+ }
1566
+ };
1514
1567
  UncaughtExceptionMonitor.prototype.removeAwsLambdaListener = function () {
1515
1568
  var isLambda = !!process.env.LAMBDA_TASK_ROOT;
1516
1569
  if (!isLambda) {
@@ -1523,112 +1576,125 @@ var UncaughtExceptionMonitor = /** @class */ (function () {
1523
1576
  * we want to report the exception to Honeybadger and
1524
1577
  * mimic the default behavior of NodeJs,
1525
1578
  * which is to exit the process with code 1
1579
+ *
1580
+ * Node sets up domainUncaughtExceptionClear when we use domains.
1581
+ * Since they're not set up by a user, they shouldn't affect whether we exit or not
1526
1582
  */
1527
1583
  UncaughtExceptionMonitor.prototype.hasOtherUncaughtExceptionListeners = function () {
1528
- var allListeners = process.listeners('uncaughtException');
1529
- // Node sets up these listeners when we use domains
1530
- // Since they're not set up by a user, they shouldn't affect whether we exit or not
1531
- var domainListeners = allListeners.filter(function (listener) {
1532
- listener.name === 'domainUncaughtExceptionClear';
1533
- });
1534
- return allListeners.length - domainListeners.length > 1;
1535
- };
1536
- UncaughtExceptionMonitor.prototype.handleUncaughtException = function (uncaughtError) {
1537
1584
  var _this = this;
1538
- if (this.__isReporting) {
1539
- return;
1540
- }
1541
- if (!this.__client.config.enableUncaught) {
1542
- this.__client.config.afterUncaught(uncaughtError);
1543
- if (!this.hasOtherUncaughtExceptionListeners()) {
1544
- (0, util_1$2.fatallyLogAndExit)(uncaughtError);
1545
- }
1546
- return;
1547
- }
1548
- // report only the first error - prevent reporting recursive errors
1549
- if (this.__handlerAlreadyCalled) {
1550
- if (!this.hasOtherUncaughtExceptionListeners()) {
1551
- (0, util_1$2.fatallyLogAndExit)(uncaughtError);
1552
- }
1553
- return;
1554
- }
1555
- this.__isReporting = true;
1556
- this.__client.notify(uncaughtError, {
1557
- afterNotify: function (_err, _notice) {
1558
- _this.__isReporting = false;
1559
- _this.__handlerAlreadyCalled = true;
1560
- _this.__client.config.afterUncaught(uncaughtError);
1561
- if (!_this.hasOtherUncaughtExceptionListeners()) {
1562
- (0, util_1$2.fatallyLogAndExit)(uncaughtError);
1563
- }
1564
- }
1565
- });
1585
+ var allListeners = process.listeners('uncaughtException');
1586
+ var otherListeners = allListeners.filter(function (listener) { return (listener.name !== 'domainUncaughtExceptionClear'
1587
+ && listener !== _this.__listener); });
1588
+ return otherListeners.length > 0;
1566
1589
  };
1567
1590
  return UncaughtExceptionMonitor;
1568
1591
  }());
1569
1592
  uncaught_exception_monitor.default = UncaughtExceptionMonitor;
1570
1593
 
1571
- var __importDefault$2 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1594
+ var __importDefault$3 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1572
1595
  return (mod && mod.__esModule) ? mod : { "default": mod };
1573
1596
  };
1574
1597
  Object.defineProperty(uncaught_exception_plugin, "__esModule", { value: true });
1575
- var uncaught_exception_monitor_1 = __importDefault$2(uncaught_exception_monitor);
1598
+ var uncaught_exception_monitor_1 = __importDefault$3(uncaught_exception_monitor);
1599
+ var uncaughtExceptionMonitor = new uncaught_exception_monitor_1.default();
1576
1600
  function default_1$1() {
1577
1601
  return {
1578
1602
  load: function (client) {
1579
- if (!client.config.enableUncaught) {
1580
- return;
1603
+ uncaughtExceptionMonitor.setClient(client);
1604
+ if (client.config.enableUncaught) {
1605
+ uncaughtExceptionMonitor.maybeAddListener();
1606
+ }
1607
+ else {
1608
+ uncaughtExceptionMonitor.maybeRemoveListener();
1581
1609
  }
1582
- var uncaughtExceptionMonitor = new uncaught_exception_monitor_1.default(client);
1583
- process.on('uncaughtException', function honeybadgerUncaughtExceptionListener(uncaughtError) {
1584
- uncaughtExceptionMonitor.handleUncaughtException(uncaughtError);
1585
- });
1586
1610
  }
1587
1611
  };
1588
1612
  }
1589
1613
  uncaught_exception_plugin.default = default_1$1;
1590
1614
 
1591
- var unhandled_rejection = {};
1615
+ var unhandled_rejection_plugin = {};
1616
+
1617
+ var unhandled_rejection_monitor = {};
1592
1618
 
1593
- Object.defineProperty(unhandled_rejection, "__esModule", { value: true });
1619
+ Object.defineProperty(unhandled_rejection_monitor, "__esModule", { value: true });
1594
1620
  var util_1$1 = util;
1595
- var isReporting = false;
1596
- /**
1597
- * If there are no other unhandledRejection listeners,
1598
- * we want to report the exception to Honeybadger and
1599
- * mimic the default behavior of NodeJs,
1600
- * which is to exit the process with code 1
1601
- */
1602
- function hasOtherUnhandledRejectionListeners() {
1603
- return process.listeners('unhandledRejection').length > 1;
1604
- }
1605
- function default_1() {
1606
- return {
1607
- load: function (client) {
1608
- if (!client.config.enableUnhandledRejection) {
1621
+ var UnhandledRejectionMonitor = /** @class */ (function () {
1622
+ function UnhandledRejectionMonitor() {
1623
+ this.__isReporting = false;
1624
+ this.__listener = this.makeListener();
1625
+ }
1626
+ UnhandledRejectionMonitor.prototype.setClient = function (client) {
1627
+ this.__client = client;
1628
+ };
1629
+ UnhandledRejectionMonitor.prototype.makeListener = function () {
1630
+ var _this = this;
1631
+ var honeybadgerUnhandledRejectionListener = function (reason, _promise) {
1632
+ if (!_this.__client || !_this.__client.config.enableUnhandledRejection) {
1633
+ if (!_this.hasOtherUnhandledRejectionListeners() && !_this.__isReporting) {
1634
+ (0, util_1$1.fatallyLogAndExit)(reason);
1635
+ }
1609
1636
  return;
1610
1637
  }
1611
- process.on('unhandledRejection', function honeybadgerUnhandledRejectionListener(reason, _promise) {
1612
- if (!client.config.enableUnhandledRejection) {
1613
- if (!hasOtherUnhandledRejectionListeners() && !isReporting) {
1638
+ _this.__isReporting = true;
1639
+ _this.__client.notify(reason, { component: 'unhandledRejection' }, {
1640
+ afterNotify: function () {
1641
+ _this.__isReporting = false;
1642
+ if (!_this.hasOtherUnhandledRejectionListeners()) {
1614
1643
  (0, util_1$1.fatallyLogAndExit)(reason);
1615
1644
  }
1616
- return;
1617
1645
  }
1618
- isReporting = true;
1619
- client.notify(reason, { component: 'unhandledRejection' }, {
1620
- afterNotify: function () {
1621
- isReporting = false;
1622
- if (!hasOtherUnhandledRejectionListeners()) {
1623
- (0, util_1$1.fatallyLogAndExit)(reason);
1624
- }
1625
- }
1626
- });
1627
1646
  });
1647
+ };
1648
+ return honeybadgerUnhandledRejectionListener;
1649
+ };
1650
+ UnhandledRejectionMonitor.prototype.maybeAddListener = function () {
1651
+ var listeners = process.listeners('unhandledRejection');
1652
+ if (!listeners.includes(this.__listener)) {
1653
+ process.on('unhandledRejection', this.__listener);
1654
+ }
1655
+ };
1656
+ UnhandledRejectionMonitor.prototype.maybeRemoveListener = function () {
1657
+ var listeners = process.listeners('unhandledRejection');
1658
+ if (listeners.includes(this.__listener)) {
1659
+ process.removeListener('unhandledRejection', this.__listener);
1660
+ }
1661
+ };
1662
+ /**
1663
+ * If there are no other unhandledRejection listeners,
1664
+ * we want to report the exception to Honeybadger and
1665
+ * mimic the default behavior of NodeJs,
1666
+ * which is to exit the process with code 1
1667
+ */
1668
+ UnhandledRejectionMonitor.prototype.hasOtherUnhandledRejectionListeners = function () {
1669
+ var _this = this;
1670
+ var otherListeners = process.listeners('unhandledRejection')
1671
+ .filter(function (listener) { return listener !== _this.__listener; });
1672
+ return otherListeners.length > 0;
1673
+ };
1674
+ return UnhandledRejectionMonitor;
1675
+ }());
1676
+ unhandled_rejection_monitor.default = UnhandledRejectionMonitor;
1677
+
1678
+ var __importDefault$2 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1679
+ return (mod && mod.__esModule) ? mod : { "default": mod };
1680
+ };
1681
+ Object.defineProperty(unhandled_rejection_plugin, "__esModule", { value: true });
1682
+ var unhandled_rejection_monitor_1 = __importDefault$2(unhandled_rejection_monitor);
1683
+ var unhandledRejectionMonitor = new unhandled_rejection_monitor_1.default();
1684
+ function default_1() {
1685
+ return {
1686
+ load: function (client) {
1687
+ unhandledRejectionMonitor.setClient(client);
1688
+ if (client.config.enableUnhandledRejection) {
1689
+ unhandledRejectionMonitor.maybeAddListener();
1690
+ }
1691
+ else {
1692
+ unhandledRejectionMonitor.maybeRemoveListener();
1693
+ }
1628
1694
  }
1629
1695
  };
1630
1696
  }
1631
- unhandled_rejection.default = default_1;
1697
+ unhandled_rejection_plugin.default = default_1;
1632
1698
 
1633
1699
  var middleware = {};
1634
1700
 
@@ -1906,7 +1972,7 @@ stacked_store.StackedStore = StackedStore;
1906
1972
  var core_1 = src;
1907
1973
  var util_1 = util;
1908
1974
  var uncaught_exception_plugin_1 = __importDefault(uncaught_exception_plugin);
1909
- var unhandled_rejection_1 = __importDefault(unhandled_rejection);
1975
+ var unhandled_rejection_plugin_1 = __importDefault(unhandled_rejection_plugin);
1910
1976
  var middleware_1 = middleware;
1911
1977
  var aws_lambda_1 = aws_lambda;
1912
1978
  var transport_1 = transport;
@@ -2008,13 +2074,13 @@ stacked_store.StackedStore = StackedStore;
2008
2074
  var singleton = new Honeybadger({
2009
2075
  __plugins: [
2010
2076
  (0, uncaught_exception_plugin_1.default)(),
2011
- (0, unhandled_rejection_1.default)()
2077
+ (0, unhandled_rejection_plugin_1.default)()
2012
2078
  ],
2013
2079
  });
2014
2080
  var NOTIFIER = {
2015
2081
  name: '@honeybadger-io/js',
2016
2082
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/js',
2017
- version: '6.4.1'
2083
+ version: '6.4.3'
2018
2084
  };
2019
2085
  singleton.setNotifier(NOTIFIER);
2020
2086
  var core_2 = src;