@honeybadger-io/js 6.16.4 → 6.16.5

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.
@@ -1455,7 +1455,7 @@ var Client = /** @class */ (function () {
1455
1455
  this.__notifier = {
1456
1456
  name: '@honeybadger-io/core',
1457
1457
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/core',
1458
- version: '6.16.4'
1458
+ version: '6.16.5'
1459
1459
  };
1460
1460
  this.config = __assign(__assign({}, defaults_1.CONFIG), opts);
1461
1461
  this.__initStore();
@@ -1473,7 +1473,7 @@ var Client = /** @class */ (function () {
1473
1473
  this.__notifier = {
1474
1474
  name: '@honeybadger-io/core',
1475
1475
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/core',
1476
- version: '6.16.4'
1476
+ version: '6.16.5'
1477
1477
  };
1478
1478
  this.config = __assign$1(__assign$1({}, defaults_1.CONFIG), opts);
1479
1479
  this.__initStore();
@@ -3747,6 +3747,104 @@ client.CheckInsClient = CheckInsClient;
3747
3747
 
3748
3748
  } (checkInsManager));
3749
3749
 
3750
+ var globalSingleton = {};
3751
+
3752
+ (function (exports) {
3753
+ Object.defineProperty(exports, "__esModule", { value: true });
3754
+ exports.getOrCreateSingleton = exports.singletonKey = exports.DISABLE_GLOBAL_SINGLETON_KEY = void 0;
3755
+ var core_1 = src;
3756
+ /**
3757
+ * Set this on the global object before the package is loaded to opt out of sharing.
3758
+ * Two independently bundled copies on one page then keep their own clients, the way
3759
+ * they did before the singleton was shared.
3760
+ */
3761
+ exports.DISABLE_GLOBAL_SINGLETON_KEY = '__HONEYBADGER_DISABLE_GLOBAL_SINGLETON__';
3762
+ /**
3763
+ * Stamped on the client when it is stored, and required when it is read back, so the slot
3764
+ * is only ever trusted when this package wrote it. Duck typing would not do: a value that
3765
+ * happens to carry a `notify` method would be handed out as the client.
3766
+ */
3767
+ var CLIENT_MARKER = '__honeybadger_client__';
3768
+ function singletonKey(target, version) {
3769
+ return "__honeybadger_singleton_".concat(target, "_").concat(version, "__");
3770
+ }
3771
+ exports.singletonKey = singletonKey;
3772
+ function isSingleton(value) {
3773
+ return !!value && value[CLIENT_MARKER] === true;
3774
+ }
3775
+ function markAsSingleton(client) {
3776
+ Object.defineProperty(client, CLIENT_MARKER, {
3777
+ value: true,
3778
+ writable: false,
3779
+ configurable: true,
3780
+ enumerable: false,
3781
+ });
3782
+ }
3783
+ /**
3784
+ * Returns the client stored on the global object, creating and storing it the first time.
3785
+ *
3786
+ * Bundlers can emit more than one copy of this module — Next.js compiles the
3787
+ * instrumentation, page-rendering and edge contexts into separate module graphs — and
3788
+ * each copy would otherwise build its own client. Only the copy the configuration code
3789
+ * ran in would be configured, so a `Honeybadger.notify()` made through any other copy
3790
+ * would silently do nothing. Keeping the instance on the realm's global object lets every
3791
+ * copy find the same configured client.
3792
+ *
3793
+ * The slot is keyed by build target and by exact version: an older copy must never be
3794
+ * handed to a newer caller that would then call a method it does not have. Two different
3795
+ * versions in one realm fall back to one client each, which is the behaviour that shipped
3796
+ * before the singleton was shared.
3797
+ */
3798
+ function getOrCreateSingleton(target, version, create, _global) {
3799
+ if (_global === void 0) { _global = core_1.Util.globalThisOrWindow(); }
3800
+ if (!_global) {
3801
+ return create();
3802
+ }
3803
+ var key = singletonKey(target, version);
3804
+ var shared;
3805
+ var canShare = false;
3806
+ // Reading the global object can throw as easily as writing to it can: the opt-out
3807
+ // flag, the slot and the marker are all ordinary properties, and a host or another
3808
+ // script may have installed a getter on any of them. `create()` stays outside, so a
3809
+ // genuine failure to build the client still propagates.
3810
+ try {
3811
+ if (_global[exports.DISABLE_GLOBAL_SINGLETON_KEY] !== true) {
3812
+ canShare = true;
3813
+ var existing = _global[key];
3814
+ if (isSingleton(existing)) {
3815
+ shared = existing;
3816
+ }
3817
+ }
3818
+ }
3819
+ catch (_e) {
3820
+ canShare = false;
3821
+ }
3822
+ if (shared) {
3823
+ return shared;
3824
+ }
3825
+ var created = create();
3826
+ if (!canShare) {
3827
+ return created;
3828
+ }
3829
+ try {
3830
+ markAsSingleton(created);
3831
+ Object.defineProperty(_global, key, {
3832
+ value: created,
3833
+ writable: true,
3834
+ configurable: true,
3835
+ enumerable: false,
3836
+ });
3837
+ }
3838
+ catch (_e) {
3839
+ // A frozen global object (node --frozen-intrinsics, SES lockdown). Importing this
3840
+ // package must never throw, so this copy keeps the client to itself.
3841
+ }
3842
+ return created;
3843
+ }
3844
+ exports.getOrCreateSingleton = getOrCreateSingleton;
3845
+
3846
+ } (globalSingleton));
3847
+
3750
3848
  (function (exports) {
3751
3849
  var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
3752
3850
  var extendStatics = function (d, b) {
@@ -3813,7 +3911,6 @@ client.CheckInsClient = CheckInsClient;
3813
3911
  var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
3814
3912
  return (mod && mod.__esModule) ? mod : { "default": mod };
3815
3913
  };
3816
- var _a;
3817
3914
  Object.defineProperty(exports, "__esModule", { value: true });
3818
3915
  exports.CheckIn = exports.Types = void 0;
3819
3916
  var os_1 = __importDefault(require$$0__default["default"]);
@@ -3828,6 +3925,7 @@ client.CheckInsClient = CheckInsClient;
3828
3925
  var transport_1 = transport;
3829
3926
  var stacked_store_1 = stacked_store;
3830
3927
  var check_ins_manager_1 = checkInsManager;
3928
+ var global_singleton_1 = globalSingleton;
3831
3929
  var endpoint = core_1.Util.endpoint;
3832
3930
  var DEFAULT_PLUGINS = [
3833
3931
  (0, uncaught_exception_plugin_1.default)(),
@@ -3991,13 +4089,17 @@ client.CheckInsClient = CheckInsClient;
3991
4089
  var NOTIFIER = {
3992
4090
  name: '@honeybadger-io/js',
3993
4091
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/js',
3994
- version: '6.16.4'
4092
+ version: '6.16.5'
3995
4093
  };
3996
4094
  var userAgent = function () {
3997
4095
  return "Honeybadger JS Server Client ".concat(NOTIFIER.version, ", ").concat(os_1.default.version(), "; ").concat(os_1.default.platform());
3998
4096
  };
3999
- var singleton = new Honeybadger(__assign({ __plugins: DEFAULT_PLUGINS }, ((_a = (0, util_1.readConfigFromFileSystem)()) !== null && _a !== void 0 ? _a : {})));
4000
- singleton.setNotifier(NOTIFIER);
4097
+ var singleton = (0, global_singleton_1.getOrCreateSingleton)('server', NOTIFIER.version, function () {
4098
+ var _a;
4099
+ var client = new Honeybadger(__assign({ __plugins: DEFAULT_PLUGINS }, ((_a = (0, util_1.readConfigFromFileSystem)()) !== null && _a !== void 0 ? _a : {})));
4100
+ client.setNotifier(NOTIFIER);
4101
+ return client;
4102
+ });
4001
4103
  var core_2 = src;
4002
4104
  Object.defineProperty(exports, "Types", { enumerable: true, get: function () { return core_2.Types; } });
4003
4105
  var check_in_1 = requireCheckIn();