@honeybadger-io/js 6.16.4 → 6.16.6

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.
@@ -182,6 +182,17 @@
182
182
  var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(stackTraceParser_esm);
183
183
 
184
184
  (function (exports) {
185
+ var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
186
+ __assign = Object.assign || function(t) {
187
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
188
+ s = arguments[i];
189
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
190
+ t[p] = s[p];
191
+ }
192
+ return t;
193
+ };
194
+ return __assign.apply(this, arguments);
195
+ };
185
196
  var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
186
197
  if (k2 === undefined) k2 = k;
187
198
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -242,7 +253,7 @@
242
253
  }
243
254
  };
244
255
  Object.defineProperty(exports, "__esModule", { value: true });
245
- exports.logDeprecatedMethod = exports.globalThisOrWindow = exports.isBrowserConfig = exports.clone = exports.formatCGIData = exports.filterUrl = exports.filter = exports.generateStackTrace = exports.endpoint = exports.instrumentConsole = exports.instrument = exports.isErrorObject = exports.makeNotice = exports.logger = exports.sanitize = exports.shallowClone = exports.runAfterNotifyHandlers = exports.shouldSampleEvent = exports.resolveInsights = exports.runBeforeEventHandlers = exports.runBeforeNotifyHandlers = exports.getSourceForBacktrace = exports.getCauses = exports.calculateBacktraceShift = exports.DEFAULT_BACKTRACE_SHIFT = exports.makeBacktrace = exports.objectIsExtensible = exports.objectIsEmpty = exports.mergeNotice = exports.merge = void 0;
256
+ exports.logDeprecatedMethod = exports.globalThisOrWindow = exports.isBrowserConfig = exports.clone = exports.formatCGIData = exports.filterBreadcrumbs = exports.filterUrl = exports.filter = exports.generateStackTrace = exports.endpoint = exports.instrumentConsole = exports.instrument = exports.isErrorObject = exports.makeNotice = exports.logger = exports.sanitize = exports.shallowClone = exports.runAfterNotifyHandlers = exports.shouldSampleEvent = exports.resolveInsights = exports.runBeforeEventHandlers = exports.runBeforeNotifyHandlers = exports.getSourceForBacktrace = exports.getCauses = exports.calculateBacktraceShift = exports.DEFAULT_BACKTRACE_SHIFT = exports.makeBacktrace = exports.objectIsExtensible = exports.objectIsEmpty = exports.mergeNotice = exports.merge = void 0;
246
257
  /* eslint-disable prefer-rest-params */
247
258
  var stackTraceParser = __importStar(require$$0$1);
248
259
  function merge(obj1, obj2) {
@@ -828,6 +839,76 @@
828
839
  return result;
829
840
  }
830
841
  exports.filterUrl = filterUrl;
842
+ /**
843
+ * Breadcrumb metadata keys whose value is a URL, and so may carry a query string.
844
+ *
845
+ * Checked by name rather than by running `filterUrl` over every string value: a `?` is
846
+ * ordinary punctuation in a breadcrumb message or a console argument, and rewriting around
847
+ * it would mangle text that is not a URL at all.
848
+ */
849
+ var URL_METADATA_KEYS = ['url', 'from', 'to', 'href'];
850
+ /**
851
+ * Recursively rewrites the query string of every URL-bearing value.
852
+ *
853
+ * Nested as well as top-level: a breadcrumb may well carry
854
+ * `metadata: { request: { url: '/checkout?token=secret' } }`, and `filter` leaves that URL
855
+ * alone because the key `request` matches no filter.
856
+ *
857
+ * Safe to recurse without a seen-list because `filter` has already run: it replaces a
858
+ * circular reference with a string, so what arrives here is acyclic.
859
+ */
860
+ function filterUrlValues(value, filters) {
861
+ if (is('Array', value)) {
862
+ return value.map(function (entry) { return filterUrlValues(entry, filters); });
863
+ }
864
+ if (!is('Object', value)) {
865
+ return value;
866
+ }
867
+ var result = {};
868
+ var source = value;
869
+ // Own enumerable keys only, assigned with `defineProperty`: a plain `result[key] =` would
870
+ // reassign the prototype rather than create a property for a key named `__proto__`, and
871
+ // breadcrumb metadata is host-supplied.
872
+ Object.keys(source).forEach(function (key) {
873
+ var entry = source[key];
874
+ var filtered = URL_METADATA_KEYS.includes(key.toLowerCase()) && typeof entry === 'string'
875
+ ? filterUrl(entry, filters)
876
+ : filterUrlValues(entry, filters);
877
+ Object.defineProperty(result, key, {
878
+ value: filtered,
879
+ enumerable: true,
880
+ writable: true,
881
+ configurable: true
882
+ });
883
+ });
884
+ return result;
885
+ }
886
+ /**
887
+ * Applies `filters` to a breadcrumb trail.
888
+ *
889
+ * Metadata is filtered by key, exactly as `params` and `session` are, and any value under a
890
+ * URL-bearing key additionally has its query string filtered. Breadcrumb metadata is mostly
891
+ * generated by this library -- the XHR, fetch and navigation integrations all record a full
892
+ * URL -- so a query string lands there without the user ever choosing to put it there.
893
+ */
894
+ function filterBreadcrumbs(trail, filters) {
895
+ if (!is('Array', trail)) {
896
+ return [];
897
+ }
898
+ return trail.map(function (breadcrumb) {
899
+ // Leave a crumb that never carried metadata exactly as it is, so the payload shape does
900
+ // not change for it.
901
+ if (!is('Object', breadcrumb === null || breadcrumb === void 0 ? void 0 : breadcrumb.metadata)) {
902
+ return breadcrumb;
903
+ }
904
+ // `filter` runs first, so a key-matched value is already '[FILTERED]' by the time the
905
+ // URL pass sees it. Passing that through `filterUrl` is harmless: it holds no '?', so
906
+ // it is returned untouched.
907
+ var metadata = filterUrlValues(filter(breadcrumb.metadata, filters), filters);
908
+ return __assign(__assign({}, breadcrumb), { metadata: metadata });
909
+ });
910
+ }
911
+ exports.filterBreadcrumbs = filterBreadcrumbs;
831
912
  function formatCGIData(vars, prefix) {
832
913
  if (prefix === void 0) { prefix = ''; }
833
914
  var formattedVars = {};
@@ -1455,7 +1536,7 @@
1455
1536
  this.__notifier = {
1456
1537
  name: '@honeybadger-io/core',
1457
1538
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/core',
1458
- version: '6.16.4'
1539
+ version: '6.16.6'
1459
1540
  };
1460
1541
  this.config = __assign$1(__assign$1({}, defaults_1.CONFIG), opts);
1461
1542
  this.__initStore();
@@ -1816,7 +1897,7 @@
1816
1897
  notifier: this.__notifier,
1817
1898
  breadcrumbs: {
1818
1899
  enabled: !!this.config.breadcrumbsEnabled,
1819
- trail: notice.__breadcrumbs || []
1900
+ trail: (0, util_1$1.filterBreadcrumbs)(notice.__breadcrumbs || [], this.config.filters)
1820
1901
  },
1821
1902
  error: {
1822
1903
  class: notice.name,
@@ -2556,7 +2637,10 @@
2556
2637
  method = method.toUpperCase();
2557
2638
  }
2558
2639
  // localURLPathname cant be constructed for CF workers due to reliance on "document".
2559
- var message = "".concat(method, " ").concat(typeof document === 'undefined' ? url : (0, util_1.localURLPathname)(url));
2640
+ // Drop the query string by hand there: nothing filters a breadcrumb message, and
2641
+ // localURLPathname would have removed it on the branch we cannot take, so leaving
2642
+ // the raw url in would report a secret the configured `filters` were meant to catch.
2643
+ var message = "".concat(method, " ").concat(typeof document === 'undefined' ? url.split('?')[0] : (0, util_1.localURLPathname)(url));
2560
2644
  var metadata = {
2561
2645
  type: 'fetch',
2562
2646
  method: method,
@@ -2883,6 +2967,104 @@
2883
2967
  }());
2884
2968
  feedbackForm.BrowserFeedbackForm = BrowserFeedbackForm;
2885
2969
 
2970
+ var globalSingleton = {};
2971
+
2972
+ (function (exports) {
2973
+ Object.defineProperty(exports, "__esModule", { value: true });
2974
+ exports.getOrCreateSingleton = exports.singletonKey = exports.DISABLE_GLOBAL_SINGLETON_KEY = void 0;
2975
+ var core_1 = src;
2976
+ /**
2977
+ * Set this on the global object before the package is loaded to opt out of sharing.
2978
+ * Two independently bundled copies on one page then keep their own clients, the way
2979
+ * they did before the singleton was shared.
2980
+ */
2981
+ exports.DISABLE_GLOBAL_SINGLETON_KEY = '__HONEYBADGER_DISABLE_GLOBAL_SINGLETON__';
2982
+ /**
2983
+ * Stamped on the client when it is stored, and required when it is read back, so the slot
2984
+ * is only ever trusted when this package wrote it. Duck typing would not do: a value that
2985
+ * happens to carry a `notify` method would be handed out as the client.
2986
+ */
2987
+ var CLIENT_MARKER = '__honeybadger_client__';
2988
+ function singletonKey(target, version) {
2989
+ return "__honeybadger_singleton_".concat(target, "_").concat(version, "__");
2990
+ }
2991
+ exports.singletonKey = singletonKey;
2992
+ function isSingleton(value) {
2993
+ return !!value && value[CLIENT_MARKER] === true;
2994
+ }
2995
+ function markAsSingleton(client) {
2996
+ Object.defineProperty(client, CLIENT_MARKER, {
2997
+ value: true,
2998
+ writable: false,
2999
+ configurable: true,
3000
+ enumerable: false,
3001
+ });
3002
+ }
3003
+ /**
3004
+ * Returns the client stored on the global object, creating and storing it the first time.
3005
+ *
3006
+ * Bundlers can emit more than one copy of this module — Next.js compiles the
3007
+ * instrumentation, page-rendering and edge contexts into separate module graphs — and
3008
+ * each copy would otherwise build its own client. Only the copy the configuration code
3009
+ * ran in would be configured, so a `Honeybadger.notify()` made through any other copy
3010
+ * would silently do nothing. Keeping the instance on the realm's global object lets every
3011
+ * copy find the same configured client.
3012
+ *
3013
+ * The slot is keyed by build target and by exact version: an older copy must never be
3014
+ * handed to a newer caller that would then call a method it does not have. Two different
3015
+ * versions in one realm fall back to one client each, which is the behaviour that shipped
3016
+ * before the singleton was shared.
3017
+ */
3018
+ function getOrCreateSingleton(target, version, create, _global) {
3019
+ if (_global === void 0) { _global = core_1.Util.globalThisOrWindow(); }
3020
+ if (!_global) {
3021
+ return create();
3022
+ }
3023
+ var key = singletonKey(target, version);
3024
+ var shared;
3025
+ var canShare = false;
3026
+ // Reading the global object can throw as easily as writing to it can: the opt-out
3027
+ // flag, the slot and the marker are all ordinary properties, and a host or another
3028
+ // script may have installed a getter on any of them. `create()` stays outside, so a
3029
+ // genuine failure to build the client still propagates.
3030
+ try {
3031
+ if (_global[exports.DISABLE_GLOBAL_SINGLETON_KEY] !== true) {
3032
+ canShare = true;
3033
+ var existing = _global[key];
3034
+ if (isSingleton(existing)) {
3035
+ shared = existing;
3036
+ }
3037
+ }
3038
+ }
3039
+ catch (_e) {
3040
+ canShare = false;
3041
+ }
3042
+ if (shared) {
3043
+ return shared;
3044
+ }
3045
+ var created = create();
3046
+ if (!canShare) {
3047
+ return created;
3048
+ }
3049
+ try {
3050
+ markAsSingleton(created);
3051
+ Object.defineProperty(_global, key, {
3052
+ value: created,
3053
+ writable: true,
3054
+ configurable: true,
3055
+ enumerable: false,
3056
+ });
3057
+ }
3058
+ catch (_e) {
3059
+ // A frozen global object (node --frozen-intrinsics, SES lockdown). Importing this
3060
+ // package must never throw, so this copy keeps the client to itself.
3061
+ }
3062
+ return created;
3063
+ }
3064
+ exports.getOrCreateSingleton = getOrCreateSingleton;
3065
+
3066
+ } (globalSingleton));
3067
+
2886
3068
  (function (exports) {
2887
3069
  var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
2888
3070
  var extendStatics = function (d, b) {
@@ -2960,6 +3142,7 @@
2960
3142
  var event_listeners_1 = __importDefault(event_listeners);
2961
3143
  var transport_1 = transport;
2962
3144
  var feedback_form_1 = feedbackForm;
3145
+ var global_singleton_1 = globalSingleton;
2963
3146
  var merge = core_1.Util.merge, filter = core_1.Util.filter, objectIsExtensible = core_1.Util.objectIsExtensible, globalThisOrWindow = core_1.Util.globalThisOrWindow;
2964
3147
  var getProjectRoot = function () {
2965
3148
  var global = globalThisOrWindow();
@@ -3156,7 +3339,7 @@
3156
3339
  var NOTIFIER = {
3157
3340
  name: '@honeybadger-io/js',
3158
3341
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/js',
3159
- version: '6.16.4'
3342
+ version: '6.16.6'
3160
3343
  };
3161
3344
  var userAgent = function () {
3162
3345
  if (typeof navigator !== 'undefined') {
@@ -3164,17 +3347,20 @@
3164
3347
  }
3165
3348
  return "Honeybadger JS Browser Client ".concat(NOTIFIER.version, "; n/a; n/a");
3166
3349
  };
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
- ]
3350
+ var singleton = (0, global_singleton_1.getOrCreateSingleton)('browser', NOTIFIER.version, function () {
3351
+ var client = new Honeybadger({
3352
+ __plugins: [
3353
+ (0, onerror_1.onError)(),
3354
+ (0, onunhandledrejection_1.default)(),
3355
+ (0, timers_1.default)(),
3356
+ (0, event_listeners_1.default)(),
3357
+ (0, breadcrumbs_1.default)(),
3358
+ core_1.Plugins.consoleEvents(),
3359
+ ]
3360
+ });
3361
+ client.setNotifier(NOTIFIER);
3362
+ return client;
3176
3363
  });
3177
- singleton.setNotifier(NOTIFIER);
3178
3364
  var core_2 = src;
3179
3365
  Object.defineProperty(exports, "Types", { enumerable: true, get: function () { return core_2.Types; } });
3180
3366
  exports.default = singleton;