@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 @@
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$1(__assign$1({}, defaults_1.CONFIG), opts);
1461
1461
  this.__initStore();
@@ -2883,6 +2883,104 @@
2883
2883
  }());
2884
2884
  feedbackForm.BrowserFeedbackForm = BrowserFeedbackForm;
2885
2885
 
2886
+ var globalSingleton = {};
2887
+
2888
+ (function (exports) {
2889
+ Object.defineProperty(exports, "__esModule", { value: true });
2890
+ exports.getOrCreateSingleton = exports.singletonKey = exports.DISABLE_GLOBAL_SINGLETON_KEY = void 0;
2891
+ var core_1 = src;
2892
+ /**
2893
+ * Set this on the global object before the package is loaded to opt out of sharing.
2894
+ * Two independently bundled copies on one page then keep their own clients, the way
2895
+ * they did before the singleton was shared.
2896
+ */
2897
+ exports.DISABLE_GLOBAL_SINGLETON_KEY = '__HONEYBADGER_DISABLE_GLOBAL_SINGLETON__';
2898
+ /**
2899
+ * Stamped on the client when it is stored, and required when it is read back, so the slot
2900
+ * is only ever trusted when this package wrote it. Duck typing would not do: a value that
2901
+ * happens to carry a `notify` method would be handed out as the client.
2902
+ */
2903
+ var CLIENT_MARKER = '__honeybadger_client__';
2904
+ function singletonKey(target, version) {
2905
+ return "__honeybadger_singleton_".concat(target, "_").concat(version, "__");
2906
+ }
2907
+ exports.singletonKey = singletonKey;
2908
+ function isSingleton(value) {
2909
+ return !!value && value[CLIENT_MARKER] === true;
2910
+ }
2911
+ function markAsSingleton(client) {
2912
+ Object.defineProperty(client, CLIENT_MARKER, {
2913
+ value: true,
2914
+ writable: false,
2915
+ configurable: true,
2916
+ enumerable: false,
2917
+ });
2918
+ }
2919
+ /**
2920
+ * Returns the client stored on the global object, creating and storing it the first time.
2921
+ *
2922
+ * Bundlers can emit more than one copy of this module — Next.js compiles the
2923
+ * instrumentation, page-rendering and edge contexts into separate module graphs — and
2924
+ * each copy would otherwise build its own client. Only the copy the configuration code
2925
+ * ran in would be configured, so a `Honeybadger.notify()` made through any other copy
2926
+ * would silently do nothing. Keeping the instance on the realm's global object lets every
2927
+ * copy find the same configured client.
2928
+ *
2929
+ * The slot is keyed by build target and by exact version: an older copy must never be
2930
+ * handed to a newer caller that would then call a method it does not have. Two different
2931
+ * versions in one realm fall back to one client each, which is the behaviour that shipped
2932
+ * before the singleton was shared.
2933
+ */
2934
+ function getOrCreateSingleton(target, version, create, _global) {
2935
+ if (_global === void 0) { _global = core_1.Util.globalThisOrWindow(); }
2936
+ if (!_global) {
2937
+ return create();
2938
+ }
2939
+ var key = singletonKey(target, version);
2940
+ var shared;
2941
+ var canShare = false;
2942
+ // Reading the global object can throw as easily as writing to it can: the opt-out
2943
+ // flag, the slot and the marker are all ordinary properties, and a host or another
2944
+ // script may have installed a getter on any of them. `create()` stays outside, so a
2945
+ // genuine failure to build the client still propagates.
2946
+ try {
2947
+ if (_global[exports.DISABLE_GLOBAL_SINGLETON_KEY] !== true) {
2948
+ canShare = true;
2949
+ var existing = _global[key];
2950
+ if (isSingleton(existing)) {
2951
+ shared = existing;
2952
+ }
2953
+ }
2954
+ }
2955
+ catch (_e) {
2956
+ canShare = false;
2957
+ }
2958
+ if (shared) {
2959
+ return shared;
2960
+ }
2961
+ var created = create();
2962
+ if (!canShare) {
2963
+ return created;
2964
+ }
2965
+ try {
2966
+ markAsSingleton(created);
2967
+ Object.defineProperty(_global, key, {
2968
+ value: created,
2969
+ writable: true,
2970
+ configurable: true,
2971
+ enumerable: false,
2972
+ });
2973
+ }
2974
+ catch (_e) {
2975
+ // A frozen global object (node --frozen-intrinsics, SES lockdown). Importing this
2976
+ // package must never throw, so this copy keeps the client to itself.
2977
+ }
2978
+ return created;
2979
+ }
2980
+ exports.getOrCreateSingleton = getOrCreateSingleton;
2981
+
2982
+ } (globalSingleton));
2983
+
2886
2984
  (function (exports) {
2887
2985
  var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
2888
2986
  var extendStatics = function (d, b) {
@@ -2960,6 +3058,7 @@
2960
3058
  var event_listeners_1 = __importDefault(event_listeners);
2961
3059
  var transport_1 = transport;
2962
3060
  var feedback_form_1 = feedbackForm;
3061
+ var global_singleton_1 = globalSingleton;
2963
3062
  var merge = core_1.Util.merge, filter = core_1.Util.filter, objectIsExtensible = core_1.Util.objectIsExtensible, globalThisOrWindow = core_1.Util.globalThisOrWindow;
2964
3063
  var getProjectRoot = function () {
2965
3064
  var global = globalThisOrWindow();
@@ -3156,7 +3255,7 @@
3156
3255
  var NOTIFIER = {
3157
3256
  name: '@honeybadger-io/js',
3158
3257
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/js',
3159
- version: '6.16.4'
3258
+ version: '6.16.5'
3160
3259
  };
3161
3260
  var userAgent = function () {
3162
3261
  if (typeof navigator !== 'undefined') {
@@ -3164,17 +3263,20 @@
3164
3263
  }
3165
3264
  return "Honeybadger JS Browser Client ".concat(NOTIFIER.version, "; n/a; n/a");
3166
3265
  };
3167
- var singleton = new Honeybadger({
3168
- __plugins: [
3169
- (0, onerror_1.onError)(),
3170
- (0, onunhandledrejection_1.default)(),
3171
- (0, timers_1.default)(),
3172
- (0, event_listeners_1.default)(),
3173
- (0, breadcrumbs_1.default)(),
3174
- core_1.Plugins.consoleEvents(),
3175
- ]
3266
+ var singleton = (0, global_singleton_1.getOrCreateSingleton)('browser', NOTIFIER.version, function () {
3267
+ var client = new Honeybadger({
3268
+ __plugins: [
3269
+ (0, onerror_1.onError)(),
3270
+ (0, onunhandledrejection_1.default)(),
3271
+ (0, timers_1.default)(),
3272
+ (0, event_listeners_1.default)(),
3273
+ (0, breadcrumbs_1.default)(),
3274
+ core_1.Plugins.consoleEvents(),
3275
+ ]
3276
+ });
3277
+ client.setNotifier(NOTIFIER);
3278
+ return client;
3176
3279
  });
3177
- singleton.setNotifier(NOTIFIER);
3178
3280
  var core_2 = src;
3179
3281
  Object.defineProperty(exports, "Types", { enumerable: true, get: function () { return core_2.Types; } });
3180
3282
  exports.default = singleton;