@sentry/browser 6.19.2 → 6.19.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.
Files changed (179) hide show
  1. package/build/bundle.debug.min.js +3 -0
  2. package/build/bundle.debug.min.js.map +1 -0
  3. package/build/bundle.es6.debug.min.js +3 -0
  4. package/build/bundle.es6.debug.min.js.map +1 -0
  5. package/{bundles → build}/bundle.es6.js +476 -270
  6. package/build/bundle.es6.js.map +1 -0
  7. package/build/bundle.es6.min.js +3 -0
  8. package/build/bundle.es6.min.js.map +1 -0
  9. package/{bundles → build}/bundle.js +486 -289
  10. package/build/bundle.js.map +1 -0
  11. package/build/bundle.min.js +3 -0
  12. package/build/bundle.min.js.map +1 -0
  13. package/dist/backend.d.ts.map +1 -1
  14. package/dist/backend.js +8 -0
  15. package/dist/backend.js.map +1 -1
  16. package/dist/client.d.ts.map +1 -1
  17. package/dist/client.js +2 -1
  18. package/dist/client.js.map +1 -1
  19. package/dist/eventbuilder.d.ts.map +1 -1
  20. package/dist/eventbuilder.js.map +1 -1
  21. package/dist/exports.d.ts.map +1 -1
  22. package/dist/exports.js.map +1 -1
  23. package/dist/flags.d.ts +3 -0
  24. package/dist/flags.d.ts.map +1 -0
  25. package/dist/flags.js +17 -0
  26. package/dist/flags.js.map +1 -0
  27. package/dist/helpers.d.ts.map +1 -1
  28. package/dist/helpers.js +3 -2
  29. package/dist/helpers.js.map +1 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js.map +1 -1
  32. package/dist/integrations/breadcrumbs.d.ts.map +1 -1
  33. package/dist/integrations/breadcrumbs.js.map +1 -1
  34. package/dist/integrations/dedupe.d.ts.map +1 -1
  35. package/dist/integrations/dedupe.js +2 -1
  36. package/dist/integrations/dedupe.js.map +1 -1
  37. package/dist/integrations/globalhandlers.d.ts.map +1 -1
  38. package/dist/integrations/globalhandlers.js +2 -1
  39. package/dist/integrations/globalhandlers.js.map +1 -1
  40. package/dist/integrations/index.d.ts.map +1 -1
  41. package/dist/integrations/index.js.map +1 -1
  42. package/dist/integrations/linkederrors.d.ts.map +1 -1
  43. package/dist/integrations/linkederrors.js.map +1 -1
  44. package/dist/integrations/trycatch.d.ts.map +1 -1
  45. package/dist/integrations/trycatch.js.map +1 -1
  46. package/dist/integrations/useragent.d.ts.map +1 -1
  47. package/dist/integrations/useragent.js.map +1 -1
  48. package/dist/sdk.d.ts.map +1 -1
  49. package/dist/sdk.js +4 -3
  50. package/dist/sdk.js.map +1 -1
  51. package/dist/stack-parsers.d.ts.map +1 -1
  52. package/dist/stack-parsers.js.map +1 -1
  53. package/dist/transports/base.d.ts.map +1 -1
  54. package/dist/transports/base.js +7 -6
  55. package/dist/transports/base.js.map +1 -1
  56. package/dist/transports/fetch.d.ts.map +1 -1
  57. package/dist/transports/fetch.js.map +1 -1
  58. package/dist/transports/index.d.ts +2 -0
  59. package/dist/transports/index.d.ts.map +1 -1
  60. package/dist/transports/index.js +4 -0
  61. package/dist/transports/index.js.map +1 -1
  62. package/dist/transports/new-fetch.d.ts +10 -0
  63. package/dist/transports/new-fetch.d.ts.map +1 -0
  64. package/dist/transports/new-fetch.js +27 -0
  65. package/dist/transports/new-fetch.js.map +1 -0
  66. package/dist/transports/new-xhr.d.ts +11 -0
  67. package/dist/transports/new-xhr.d.ts.map +1 -0
  68. package/dist/transports/new-xhr.js +46 -0
  69. package/dist/transports/new-xhr.js.map +1 -0
  70. package/dist/transports/utils.d.ts.map +1 -1
  71. package/dist/transports/utils.js +2 -1
  72. package/dist/transports/utils.js.map +1 -1
  73. package/dist/transports/xhr.d.ts.map +1 -1
  74. package/dist/transports/xhr.js.map +1 -1
  75. package/dist/version.d.ts.map +1 -1
  76. package/dist/version.js.map +1 -1
  77. package/esm/backend.d.ts.map +1 -1
  78. package/esm/backend.js +10 -2
  79. package/esm/backend.js.map +1 -1
  80. package/esm/client.d.ts.map +1 -1
  81. package/esm/client.js +3 -2
  82. package/esm/client.js.map +1 -1
  83. package/esm/eventbuilder.d.ts.map +1 -1
  84. package/esm/eventbuilder.js.map +1 -1
  85. package/esm/exports.d.ts.map +1 -1
  86. package/esm/exports.js.map +1 -1
  87. package/esm/flags.d.ts +3 -0
  88. package/esm/flags.d.ts.map +1 -0
  89. package/esm/flags.js +16 -0
  90. package/esm/flags.js.map +1 -0
  91. package/esm/helpers.d.ts.map +1 -1
  92. package/esm/helpers.js +4 -3
  93. package/esm/helpers.js.map +1 -1
  94. package/esm/index.d.ts.map +1 -1
  95. package/esm/index.js.map +1 -1
  96. package/esm/integrations/breadcrumbs.d.ts.map +1 -1
  97. package/esm/integrations/breadcrumbs.js.map +1 -1
  98. package/esm/integrations/dedupe.d.ts.map +1 -1
  99. package/esm/integrations/dedupe.js +3 -2
  100. package/esm/integrations/dedupe.js.map +1 -1
  101. package/esm/integrations/globalhandlers.d.ts.map +1 -1
  102. package/esm/integrations/globalhandlers.js +3 -2
  103. package/esm/integrations/globalhandlers.js.map +1 -1
  104. package/esm/integrations/index.d.ts.map +1 -1
  105. package/esm/integrations/index.js.map +1 -1
  106. package/esm/integrations/linkederrors.d.ts.map +1 -1
  107. package/esm/integrations/linkederrors.js.map +1 -1
  108. package/esm/integrations/trycatch.d.ts.map +1 -1
  109. package/esm/integrations/trycatch.js.map +1 -1
  110. package/esm/integrations/useragent.d.ts.map +1 -1
  111. package/esm/integrations/useragent.js.map +1 -1
  112. package/esm/sdk.d.ts.map +1 -1
  113. package/esm/sdk.js +5 -4
  114. package/esm/sdk.js.map +1 -1
  115. package/esm/stack-parsers.d.ts.map +1 -1
  116. package/esm/stack-parsers.js.map +1 -1
  117. package/esm/transports/base.d.ts.map +1 -1
  118. package/esm/transports/base.js +8 -7
  119. package/esm/transports/base.js.map +1 -1
  120. package/esm/transports/fetch.d.ts.map +1 -1
  121. package/esm/transports/fetch.js.map +1 -1
  122. package/esm/transports/index.d.ts +2 -0
  123. package/esm/transports/index.d.ts.map +1 -1
  124. package/esm/transports/index.js +2 -0
  125. package/esm/transports/index.js.map +1 -1
  126. package/esm/transports/new-fetch.d.ts +10 -0
  127. package/esm/transports/new-fetch.d.ts.map +1 -0
  128. package/esm/transports/new-fetch.js +25 -0
  129. package/esm/transports/new-fetch.js.map +1 -0
  130. package/esm/transports/new-xhr.d.ts +11 -0
  131. package/esm/transports/new-xhr.d.ts.map +1 -0
  132. package/esm/transports/new-xhr.js +44 -0
  133. package/esm/transports/new-xhr.js.map +1 -0
  134. package/esm/transports/utils.d.ts.map +1 -1
  135. package/esm/transports/utils.js +3 -2
  136. package/esm/transports/utils.js.map +1 -1
  137. package/esm/transports/xhr.d.ts.map +1 -1
  138. package/esm/transports/xhr.js.map +1 -1
  139. package/esm/version.d.ts.map +1 -1
  140. package/esm/version.js.map +1 -1
  141. package/package.json +6 -45
  142. package/types/backend.d.ts.map +1 -1
  143. package/types/client.d.ts.map +1 -1
  144. package/types/eventbuilder.d.ts.map +1 -1
  145. package/types/exports.d.ts.map +1 -1
  146. package/types/flags.d.ts +3 -0
  147. package/types/flags.d.ts.map +1 -0
  148. package/types/helpers.d.ts.map +1 -1
  149. package/types/index.d.ts.map +1 -1
  150. package/types/integrations/breadcrumbs.d.ts.map +1 -1
  151. package/types/integrations/dedupe.d.ts.map +1 -1
  152. package/types/integrations/globalhandlers.d.ts.map +1 -1
  153. package/types/integrations/index.d.ts.map +1 -1
  154. package/types/integrations/linkederrors.d.ts.map +1 -1
  155. package/types/integrations/trycatch.d.ts.map +1 -1
  156. package/types/integrations/useragent.d.ts.map +1 -1
  157. package/types/sdk.d.ts.map +1 -1
  158. package/types/stack-parsers.d.ts.map +1 -1
  159. package/types/transports/base.d.ts.map +1 -1
  160. package/types/transports/fetch.d.ts.map +1 -1
  161. package/types/transports/index.d.ts +2 -0
  162. package/types/transports/index.d.ts.map +1 -1
  163. package/types/transports/new-fetch.d.ts +10 -0
  164. package/types/transports/new-fetch.d.ts.map +1 -0
  165. package/types/transports/new-xhr.d.ts +11 -0
  166. package/types/transports/new-xhr.d.ts.map +1 -0
  167. package/types/transports/utils.d.ts.map +1 -1
  168. package/types/transports/xhr.d.ts.map +1 -1
  169. package/types/version.d.ts.map +1 -1
  170. package/bundles/bundle.debug.min.js +0 -3
  171. package/bundles/bundle.debug.min.js.map +0 -1
  172. package/bundles/bundle.es6.debug.min.js +0 -3
  173. package/bundles/bundle.es6.debug.min.js.map +0 -1
  174. package/bundles/bundle.es6.js.map +0 -1
  175. package/bundles/bundle.es6.min.js +0 -3
  176. package/bundles/bundle.es6.min.js.map +0 -1
  177. package/bundles/bundle.js.map +0 -1
  178. package/bundles/bundle.min.js +0 -3
  179. package/bundles/bundle.min.js.map +0 -1
@@ -1,4 +1,4 @@
1
- /*! @sentry/browser 6.19.2 (f49c509) | https://github.com/getsentry/sentry-javascript */
1
+ /*! @sentry/browser 6.19.5 (755d2cd) | https://github.com/getsentry/sentry-javascript */
2
2
  var Sentry = (function (exports) {
3
3
 
4
4
  /**
@@ -35,22 +35,6 @@ var Sentry = (function (exports) {
35
35
  });
36
36
  }
37
37
 
38
- /**
39
- * This module exists for optimizations in the build process through rollup and terser. We define some global
40
- * constants, which can be overridden during build. By guarding certain pieces of code with functions that return these
41
- * constants, we can control whether or not they appear in the final bundle. (Any code guarded by a false condition will
42
- * never run, and will hence be dropped during treeshaking.) The two primary uses for this are stripping out calls to
43
- * `logger` and preventing node-related code from appearing in browser bundles.
44
- */
45
- /**
46
- * Figures out if we're building with debug functionality.
47
- *
48
- * @returns true if this is a debug build
49
- */
50
- function isDebugBuild() {
51
- return true;
52
- }
53
-
54
38
  /**
55
39
  * NOTE: In order to avoid circular dependencies, if you add a function to this module and it needs to print something,
56
40
  * you must either a) use `console.log` rather than the logger, or b) put your function elsewhere.
@@ -67,6 +51,23 @@ var Sentry = (function (exports) {
67
51
  : typeof self !== 'undefined'
68
52
  ? self
69
53
  : fallbackGlobalObject);
54
+ }
55
+ /**
56
+ * Returns a global singleton contained in the global `__SENTRY__` object.
57
+ *
58
+ * If the singleton doesn't already exist in `__SENTRY__`, it will be created using the given factory
59
+ * function and added to the `__SENTRY__` object.
60
+ *
61
+ * @param name name of the global singleton on __SENTRY__
62
+ * @param creator creator Factory function to create the singleton if it doesn't already exist on `__SENTRY__`
63
+ * @param obj (Optional) The global object on which to look for `__SENTRY__`, if not `getGlobalObject`'s return value
64
+ * @returns the singleton
65
+ */
66
+ function getGlobalSingleton(name, creator, obj) {
67
+ const global = (obj || getGlobalObject());
68
+ const __SENTRY__ = (global.__SENTRY__ = global.__SENTRY__ || {});
69
+ const singleton = __SENTRY__[name] || (__SENTRY__[name] = creator());
70
+ return singleton;
70
71
  }
71
72
 
72
73
  /* eslint-disable @typescript-eslint/no-explicit-any */
@@ -201,6 +202,16 @@ var Sentry = (function (exports) {
201
202
  function isSyntheticEvent(wat) {
202
203
  return isPlainObject(wat) && 'nativeEvent' in wat && 'preventDefault' in wat && 'stopPropagation' in wat;
203
204
  }
205
+ /**
206
+ * Checks whether given value is NaN
207
+ * {@link isNaN}.
208
+ *
209
+ * @param wat A value to be checked.
210
+ * @returns A boolean representing the result.
211
+ */
212
+ function isNaN$1(wat) {
213
+ return typeof wat === 'number' && wat !== wat;
214
+ }
204
215
  /**
205
216
  * Checks whether given value's type is an instance of provided constructor.
206
217
  * {@link isInstanceOf}.
@@ -355,6 +366,22 @@ var Sentry = (function (exports) {
355
366
  }
356
367
  }
357
368
 
369
+ /*
370
+ * This file defines flags and constants that can be modified during compile time in order to facilitate tree shaking
371
+ * for users.
372
+ *
373
+ * Debug flags need to be declared in each package individually and must not be imported across package boundaries,
374
+ * because some build tools have trouble tree-shaking imported guards.
375
+ *
376
+ * As a convention, we define debug flags in a `flags.ts` file in the root of a package's `src` folder.
377
+ *
378
+ * Debug flag files will contain "magic strings" like `true` that may get replaced with actual values during
379
+ * our, or the user's build process. Take care when introducing new flags - they must not throw if they are not
380
+ * replaced.
381
+ */
382
+ /** Flag that is true for debug builds, false otherwise. */
383
+ const IS_DEBUG_BUILD$3 = true;
384
+
358
385
  /** Regular expression used to parse a Dsn. */
359
386
  const DSN_REGEX = /^(?:(\w+):)\/\/(?:(\w+)(?::(\w+))?@)([\w.-]+)(?::(\d+))?\/(.+)/;
360
387
  function isValidProtocol(protocol) {
@@ -412,6 +439,9 @@ var Sentry = (function (exports) {
412
439
  };
413
440
  }
414
441
  function validateDsn(dsn) {
442
+ if (!IS_DEBUG_BUILD$3) {
443
+ return;
444
+ }
415
445
  const { port, projectId, protocol } = dsn;
416
446
  const requiredComponents = ['protocol', 'publicKey', 'host', 'projectId'];
417
447
  requiredComponents.forEach(component => {
@@ -445,8 +475,7 @@ var Sentry = (function (exports) {
445
475
  const PREFIX = 'Sentry Logger ';
446
476
  const CONSOLE_LEVELS = ['debug', 'info', 'warn', 'error', 'log', 'assert'];
447
477
  /**
448
- * Temporarily unwrap `console.log` and friends in order to perform the given callback using the original methods.
449
- * Restores wrapping after the callback completes.
478
+ * Temporarily disable sentry console instrumentations.
450
479
  *
451
480
  * @param callback The function to run against the original `console` messages
452
481
  * @returns The results of the callback
@@ -456,73 +485,63 @@ var Sentry = (function (exports) {
456
485
  if (!('console' in global)) {
457
486
  return callback();
458
487
  }
459
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
460
488
  const originalConsole = global.console;
461
489
  const wrappedLevels = {};
462
490
  // Restore all wrapped console methods
463
491
  CONSOLE_LEVELS.forEach(level => {
464
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
465
- if (level in global.console && originalConsole[level].__sentry_original__) {
492
+ // TODO(v7): Remove this check as it's only needed for Node 6
493
+ const originalWrappedFunc = originalConsole[level] && originalConsole[level].__sentry_original__;
494
+ if (level in global.console && originalWrappedFunc) {
466
495
  wrappedLevels[level] = originalConsole[level];
467
- originalConsole[level] = originalConsole[level].__sentry_original__;
496
+ originalConsole[level] = originalWrappedFunc;
468
497
  }
469
498
  });
470
- // Perform callback manipulations
471
- const result = callback();
472
- // Revert restoration to wrapped state
473
- Object.keys(wrappedLevels).forEach(level => {
474
- originalConsole[level] = wrappedLevels[level];
475
- });
476
- return result;
477
- }
478
- /** JSDoc */
479
- class Logger {
480
- /** JSDoc */
481
- constructor() {
482
- this._enabled = false;
483
- }
484
- /** JSDoc */
485
- disable() {
486
- this._enabled = false;
487
- }
488
- /** JSDoc */
489
- enable() {
490
- this._enabled = true;
499
+ try {
500
+ return callback();
491
501
  }
492
- /** JSDoc */
493
- log(...args) {
494
- if (!this._enabled) {
495
- return;
496
- }
497
- consoleSandbox(() => {
498
- global$6.console.log(`${PREFIX}[Log]:`, ...args);
502
+ finally {
503
+ // Revert restoration to wrapped state
504
+ Object.keys(wrappedLevels).forEach(level => {
505
+ originalConsole[level] = wrappedLevels[level];
499
506
  });
500
507
  }
501
- /** JSDoc */
502
- warn(...args) {
503
- if (!this._enabled) {
504
- return;
505
- }
506
- consoleSandbox(() => {
507
- global$6.console.warn(`${PREFIX}[Warn]:`, ...args);
508
+ }
509
+ function makeLogger() {
510
+ let enabled = false;
511
+ const logger = {
512
+ enable: () => {
513
+ enabled = true;
514
+ },
515
+ disable: () => {
516
+ enabled = false;
517
+ },
518
+ };
519
+ if (IS_DEBUG_BUILD$3) {
520
+ CONSOLE_LEVELS.forEach(name => {
521
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
522
+ logger[name] = (...args) => {
523
+ if (enabled) {
524
+ consoleSandbox(() => {
525
+ global$6.console[name](`${PREFIX}[${name}]:`, ...args);
526
+ });
527
+ }
528
+ };
508
529
  });
509
530
  }
510
- /** JSDoc */
511
- error(...args) {
512
- if (!this._enabled) {
513
- return;
514
- }
515
- consoleSandbox(() => {
516
- global$6.console.error(`${PREFIX}[Error]:`, ...args);
531
+ else {
532
+ CONSOLE_LEVELS.forEach(name => {
533
+ logger[name] = () => undefined;
517
534
  });
518
535
  }
536
+ return logger;
537
+ }
538
+ // Ensure we only have a single logger instance, even if multiple versions of @sentry/utils are being used
539
+ let logger;
540
+ if (IS_DEBUG_BUILD$3) {
541
+ logger = getGlobalSingleton('logger', makeLogger);
519
542
  }
520
- const sentryGlobal = global$6.__SENTRY__ || {};
521
- const logger = sentryGlobal.logger || new Logger();
522
- {
523
- // Ensure we only have a single logger instance, even if multiple versions of @sentry/utils are being used
524
- sentryGlobal.logger = logger;
525
- global$6.__SENTRY__ = sentryGlobal;
543
+ else {
544
+ logger = makeLogger();
526
545
  }
527
546
 
528
547
  /**
@@ -664,55 +683,38 @@ var Sentry = (function (exports) {
664
683
  *
665
684
  * @param value Initial source that we have to transform in order for it to be usable by the serializer
666
685
  */
667
- function getWalkSource(value) {
686
+ function convertToPlainObject(value) {
687
+ let newObj = value;
668
688
  if (isError(value)) {
669
- const error = value;
670
- const err = {
671
- message: error.message,
672
- name: error.name,
673
- stack: error.stack,
674
- };
675
- for (const i in error) {
676
- if (Object.prototype.hasOwnProperty.call(error, i)) {
677
- err[i] = error[i];
678
- }
679
- }
680
- return err;
689
+ newObj = Object.assign({ message: value.message, name: value.name, stack: value.stack }, getOwnProperties(value));
681
690
  }
682
- if (isEvent(value)) {
691
+ else if (isEvent(value)) {
683
692
  const event = value;
684
- const source = {};
685
- // Accessing event attributes can throw (see https://github.com/getsentry/sentry-javascript/issues/768 and
686
- // https://github.com/getsentry/sentry-javascript/issues/838), but accessing `type` hasn't been wrapped in a
687
- // try-catch in at least two years and no one's complained, so that's likely not an issue anymore
688
- source.type = event.type;
689
- try {
690
- source.target = isElement(event.target)
691
- ? htmlTreeAsString(event.target)
692
- : Object.prototype.toString.call(event.target);
693
- }
694
- catch (_oO) {
695
- source.target = '<unknown>';
696
- }
697
- try {
698
- source.currentTarget = isElement(event.currentTarget)
699
- ? htmlTreeAsString(event.currentTarget)
700
- : Object.prototype.toString.call(event.currentTarget);
701
- }
702
- catch (_oO) {
703
- source.currentTarget = '<unknown>';
704
- }
693
+ newObj = Object.assign({ type: event.type, target: serializeEventTarget(event.target), currentTarget: serializeEventTarget(event.currentTarget) }, getOwnProperties(event));
705
694
  if (typeof CustomEvent !== 'undefined' && isInstanceOf(value, CustomEvent)) {
706
- source.detail = event.detail;
695
+ newObj.detail = event.detail;
707
696
  }
708
- for (const attr in event) {
709
- if (Object.prototype.hasOwnProperty.call(event, attr)) {
710
- source[attr] = event[attr];
711
- }
697
+ }
698
+ return newObj;
699
+ }
700
+ /** Creates a string representation of the target of an `Event` object */
701
+ function serializeEventTarget(target) {
702
+ try {
703
+ return isElement(target) ? htmlTreeAsString(target) : Object.prototype.toString.call(target);
704
+ }
705
+ catch (_oO) {
706
+ return '<unknown>';
707
+ }
708
+ }
709
+ /** Filters out all but an object's own properties */
710
+ function getOwnProperties(obj) {
711
+ const extractedProps = {};
712
+ for (const property in obj) {
713
+ if (Object.prototype.hasOwnProperty.call(obj, property)) {
714
+ extractedProps[property] = obj[property];
712
715
  }
713
- return source;
714
716
  }
715
- return value;
717
+ return extractedProps;
716
718
  }
717
719
  /**
718
720
  * Given any captured exception, extract its keys and create a sorted
@@ -721,7 +723,7 @@ var Sentry = (function (exports) {
721
723
  */
722
724
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
723
725
  function extractExceptionKeysForMessage(exception, maxLength = 40) {
724
- const keys = Object.keys(getWalkSource(exception));
726
+ const keys = Object.keys(convertToPlainObject(exception));
725
727
  keys.sort();
726
728
  if (!keys.length) {
727
729
  return '[object has no keys]';
@@ -747,11 +749,10 @@ var Sentry = (function (exports) {
747
749
  */
748
750
  function dropUndefinedKeys(val) {
749
751
  if (isPlainObject(val)) {
750
- const obj = val;
751
752
  const rv = {};
752
- for (const key of Object.keys(obj)) {
753
- if (typeof obj[key] !== 'undefined') {
754
- rv[key] = dropUndefinedKeys(obj[key]);
753
+ for (const key of Object.keys(val)) {
754
+ if (typeof val[key] !== 'undefined') {
755
+ rv[key] = dropUndefinedKeys(val[key]);
755
756
  }
756
757
  }
757
758
  return rv;
@@ -1631,10 +1632,10 @@ var Sentry = (function (exports) {
1631
1632
  function normalize(input, depth = +Infinity, maxProperties = +Infinity) {
1632
1633
  try {
1633
1634
  // since we're at the outermost level, there is no key
1634
- return walk('', input, depth, maxProperties);
1635
+ return visit('', input, depth, maxProperties);
1635
1636
  }
1636
- catch (_oO) {
1637
- return '**non-serializable**';
1637
+ catch (err) {
1638
+ return { ERROR: `**non-serializable** (${err})` };
1638
1639
  }
1639
1640
  }
1640
1641
  /** JSDoc */
@@ -1643,142 +1644,142 @@ var Sentry = (function (exports) {
1643
1644
  depth = 3,
1644
1645
  // 100kB, as 200kB is max payload size, so half sounds reasonable
1645
1646
  maxSize = 100 * 1024) {
1646
- const serialized = normalize(object, depth);
1647
- if (jsonSize(serialized) > maxSize) {
1647
+ const normalized = normalize(object, depth);
1648
+ if (jsonSize(normalized) > maxSize) {
1648
1649
  return normalizeToSize(object, depth - 1, maxSize);
1649
1650
  }
1650
- return serialized;
1651
+ return normalized;
1651
1652
  }
1652
1653
  /**
1653
- * Walks an object to perform a normalization on it
1654
+ * Visits a node to perform normalization on it
1654
1655
  *
1655
- * @param key of object that's walked in current iteration
1656
- * @param value object to be walked
1657
- * @param depth Optional number indicating how deep should walking be performed
1658
- * @param maxProperties Optional maximum number of properties/elements included in any single object/array
1656
+ * @param key The key corresponding to the given node
1657
+ * @param value The node to be visited
1658
+ * @param depth Optional number indicating the maximum recursion depth
1659
+ * @param maxProperties Optional maximum number of properties/elements included in any single object/array
1659
1660
  * @param memo Optional Memo class handling decycling
1660
1661
  */
1661
- function walk(key, value, depth = +Infinity, maxProperties = +Infinity, memo = memoBuilder()) {
1662
+ function visit(key, value, depth = +Infinity, maxProperties = +Infinity, memo = memoBuilder()) {
1662
1663
  const [memoize, unmemoize] = memo;
1663
- // If we reach the maximum depth, serialize whatever is left
1664
+ // If the value has a `toJSON` method, see if we can bail and let it do the work
1665
+ const valueWithToJSON = value;
1666
+ if (valueWithToJSON && typeof valueWithToJSON.toJSON === 'function') {
1667
+ try {
1668
+ return valueWithToJSON.toJSON();
1669
+ }
1670
+ catch (err) {
1671
+ // pass (The built-in `toJSON` failed, but we can still try to do it ourselves)
1672
+ }
1673
+ }
1674
+ // Get the simple cases out of the way first
1675
+ if (value === null || (['number', 'boolean', 'string'].includes(typeof value) && !isNaN$1(value))) {
1676
+ return value;
1677
+ }
1678
+ const stringified = stringifyValue(key, value);
1679
+ // Anything we could potentially dig into more (objects or arrays) will have come back as `"[object XXXX]"`.
1680
+ // Everything else will have already been serialized, so if we don't see that pattern, we're done.
1681
+ if (!stringified.startsWith('[object ')) {
1682
+ return stringified;
1683
+ }
1684
+ // We're also done if we've reached the max depth
1664
1685
  if (depth === 0) {
1665
- return serializeValue(value);
1666
- }
1667
- // If value implements `toJSON` method, call it and return early
1668
- if (value !== null && value !== undefined && typeof value.toJSON === 'function') {
1669
- return value.toJSON();
1670
- }
1671
- // `makeSerializable` provides a string representation of certain non-serializable values. For all others, it's a
1672
- // pass-through. If what comes back is a primitive (either because it's been stringified or because it was primitive
1673
- // all along), we're done.
1674
- const serializable = makeSerializable(value, key);
1675
- if (isPrimitive(serializable)) {
1676
- return serializable;
1677
- }
1678
- // Create source that we will use for the next iteration. It will either be an objectified error object (`Error` type
1679
- // with extracted key:value pairs) or the input itself.
1680
- const source = getWalkSource(value);
1681
- // Create an accumulator that will act as a parent for all future itterations of that branch
1682
- const acc = Array.isArray(value) ? [] : {};
1683
- // If we already walked that branch, bail out, as it's circular reference
1686
+ // At this point we know `serialized` is a string of the form `"[object XXXX]"`. Clean it up so it's just `"[XXXX]"`.
1687
+ return stringified.replace('object ', '');
1688
+ }
1689
+ // If we've already visited this branch, bail out, as it's circular reference. If not, note that we're seeing it now.
1684
1690
  if (memoize(value)) {
1685
1691
  return '[Circular ~]';
1686
1692
  }
1687
- let propertyCount = 0;
1688
- // Walk all keys of the source
1689
- for (const innerKey in source) {
1693
+ // At this point we know we either have an object or an array, we haven't seen it before, and we're going to recurse
1694
+ // because we haven't yet reached the max depth. Create an accumulator to hold the results of visiting each
1695
+ // property/entry, and keep track of the number of items we add to it.
1696
+ const normalized = (Array.isArray(value) ? [] : {});
1697
+ let numAdded = 0;
1698
+ // Before we begin, convert`Error` and`Event` instances into plain objects, since some of each of their relevant
1699
+ // properties are non-enumerable and otherwise would get missed.
1700
+ const visitable = (isError(value) || isEvent(value) ? convertToPlainObject(value) : value);
1701
+ for (const visitKey in visitable) {
1690
1702
  // Avoid iterating over fields in the prototype if they've somehow been exposed to enumeration.
1691
- if (!Object.prototype.hasOwnProperty.call(source, innerKey)) {
1703
+ if (!Object.prototype.hasOwnProperty.call(visitable, visitKey)) {
1692
1704
  continue;
1693
1705
  }
1694
- if (propertyCount >= maxProperties) {
1695
- acc[innerKey] = '[MaxProperties ~]';
1706
+ if (numAdded >= maxProperties) {
1707
+ normalized[visitKey] = '[MaxProperties ~]';
1696
1708
  break;
1697
1709
  }
1698
- propertyCount += 1;
1699
- // Recursively walk through all the child nodes
1700
- const innerValue = source[innerKey];
1701
- acc[innerKey] = walk(innerKey, innerValue, depth - 1, maxProperties, memo);
1710
+ // Recursively visit all the child nodes
1711
+ const visitValue = visitable[visitKey];
1712
+ normalized[visitKey] = visit(visitKey, visitValue, depth - 1, maxProperties, memo);
1713
+ numAdded += 1;
1702
1714
  }
1703
- // Once walked through all the branches, remove the parent from memo storage
1715
+ // Once we've visited all the branches, remove the parent from memo storage
1704
1716
  unmemoize(value);
1705
1717
  // Return accumulated values
1706
- return acc;
1707
- }
1708
- /**
1709
- * Transform any non-primitive, BigInt, or Symbol-type value into a string. Acts as a no-op on strings, numbers,
1710
- * booleans, null, and undefined.
1711
- *
1712
- * @param value The value to stringify
1713
- * @returns For non-primitive, BigInt, and Symbol-type values, a string denoting the value's type, type and value, or
1714
- * type and `description` property, respectively. For non-BigInt, non-Symbol primitives, returns the original value,
1715
- * unchanged.
1716
- */
1717
- function serializeValue(value) {
1718
- // Node.js REPL notation
1719
- if (typeof value === 'string') {
1720
- return value;
1721
- }
1722
- const type = Object.prototype.toString.call(value);
1723
- if (type === '[object Object]') {
1724
- return '[Object]';
1725
- }
1726
- if (type === '[object Array]') {
1727
- return '[Array]';
1728
- }
1729
- // `makeSerializable` provides a string representation of certain non-serializable values. For all others, it's a
1730
- // pass-through.
1731
- const serializable = makeSerializable(value);
1732
- return isPrimitive(serializable) ? serializable : type;
1718
+ return normalized;
1733
1719
  }
1734
1720
  /**
1735
- * makeSerializable()
1721
+ * Stringify the given value. Handles various known special values and types.
1736
1722
  *
1737
- * Takes unserializable input and make it serializer-friendly.
1723
+ * Not meant to be used on simple primitives which already have a string representation, as it will, for example, turn
1724
+ * the number 1231 into "[Object Number]", nor on `null`, as it will throw.
1738
1725
  *
1739
- * Handles globals, functions, `undefined`, `NaN`, and other non-serializable values.
1726
+ * @param value The value to stringify
1727
+ * @returns A stringified representation of the given value
1740
1728
  */
1741
- function makeSerializable(value, key) {
1742
- if (key === 'domain' && value && typeof value === 'object' && value._events) {
1743
- return '[Domain]';
1744
- }
1745
- if (key === 'domainEmitter') {
1746
- return '[DomainEmitter]';
1747
- }
1748
- if (typeof global !== 'undefined' && value === global) {
1749
- return '[Global]';
1750
- }
1751
- // It's safe to use `window` and `document` here in this manner, as we are asserting using `typeof` first
1752
- // which won't throw if they are not present.
1753
- // eslint-disable-next-line no-restricted-globals
1754
- if (typeof window !== 'undefined' && value === window) {
1755
- return '[Window]';
1756
- }
1757
- // eslint-disable-next-line no-restricted-globals
1758
- if (typeof document !== 'undefined' && value === document) {
1759
- return '[Document]';
1760
- }
1761
- // React's SyntheticEvent thingy
1762
- if (isSyntheticEvent(value)) {
1763
- return '[SyntheticEvent]';
1764
- }
1765
- if (typeof value === 'number' && value !== value) {
1766
- return '[NaN]';
1767
- }
1768
- if (value === void 0) {
1769
- return '[undefined]';
1770
- }
1771
- if (typeof value === 'function') {
1772
- return `[Function: ${getFunctionName(value)}]`;
1773
- }
1774
- // symbols and bigints are considered primitives by TS, but aren't natively JSON-serilaizable
1775
- if (typeof value === 'symbol') {
1776
- return `[${String(value)}]`;
1729
+ function stringifyValue(key,
1730
+ // this type is a tiny bit of a cheat, since this function does handle NaN (which is technically a number), but for
1731
+ // our internal use, it'll do
1732
+ value) {
1733
+ try {
1734
+ if (key === 'domain' && value && typeof value === 'object' && value._events) {
1735
+ return '[Domain]';
1736
+ }
1737
+ if (key === 'domainEmitter') {
1738
+ return '[DomainEmitter]';
1739
+ }
1740
+ // It's safe to use `global`, `window`, and `document` here in this manner, as we are asserting using `typeof` first
1741
+ // which won't throw if they are not present.
1742
+ if (typeof global !== 'undefined' && value === global) {
1743
+ return '[Global]';
1744
+ }
1745
+ // eslint-disable-next-line no-restricted-globals
1746
+ if (typeof window !== 'undefined' && value === window) {
1747
+ return '[Window]';
1748
+ }
1749
+ // eslint-disable-next-line no-restricted-globals
1750
+ if (typeof document !== 'undefined' && value === document) {
1751
+ return '[Document]';
1752
+ }
1753
+ // React's SyntheticEvent thingy
1754
+ if (isSyntheticEvent(value)) {
1755
+ return '[SyntheticEvent]';
1756
+ }
1757
+ if (typeof value === 'number' && value !== value) {
1758
+ return '[NaN]';
1759
+ }
1760
+ // this catches `undefined` (but not `null`, which is a primitive and can be serialized on its own)
1761
+ if (value === void 0) {
1762
+ return '[undefined]';
1763
+ }
1764
+ if (typeof value === 'function') {
1765
+ return `[Function: ${getFunctionName(value)}]`;
1766
+ }
1767
+ if (typeof value === 'symbol') {
1768
+ return `[${String(value)}]`;
1769
+ }
1770
+ // stringified BigInts are indistinguishable from regular numbers, so we need to label them to avoid confusion
1771
+ if (typeof value === 'bigint') {
1772
+ return `[BigInt: ${String(value)}]`;
1773
+ }
1774
+ // Now that we've knocked out all the special cases and the primitives, all we have left are objects. Simply casting
1775
+ // them to strings means that instances of classes which haven't defined their `toStringTag` will just come out as
1776
+ // `"[object Object]"`. If we instead look at the constructor's name (which is the same as the name of the class),
1777
+ // we can make sure that only plain objects come out that way.
1778
+ return `[object ${Object.getPrototypeOf(value).constructor.name}]`;
1777
1779
  }
1778
- if (typeof value === 'bigint') {
1779
- return `[BigInt: ${String(value)}]`;
1780
+ catch (err) {
1781
+ return `**non-serializable** (${err})`;
1780
1782
  }
1781
- return value;
1782
1783
  }
1783
1784
  /** Calculates bytes size of input string */
1784
1785
  function utf8Length(value) {
@@ -2190,6 +2191,13 @@ var Sentry = (function (exports) {
2190
2191
  function createEnvelope(headers, items = []) {
2191
2192
  return [headers, items];
2192
2193
  }
2194
+ /**
2195
+ * Get the type of the envelope. Grabs the type from the first envelope item.
2196
+ */
2197
+ function getEnvelopeType(envelope) {
2198
+ const [, [[firstItemHeader]]] = envelope;
2199
+ return firstItemHeader.type;
2200
+ }
2193
2201
  /**
2194
2202
  * Serializes an envelope into a string.
2195
2203
  */
@@ -2719,12 +2727,7 @@ var Sentry = (function (exports) {
2719
2727
  * Returns the global event processors.
2720
2728
  */
2721
2729
  function getGlobalEventProcessors() {
2722
- /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */
2723
- const global = getGlobalObject();
2724
- global.__SENTRY__ = global.__SENTRY__ || {};
2725
- global.__SENTRY__.globalEventProcessors = global.__SENTRY__.globalEventProcessors || [];
2726
- return global.__SENTRY__.globalEventProcessors;
2727
- /* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */
2730
+ return getGlobalSingleton('globalEventProcessors', () => []);
2728
2731
  }
2729
2732
  /**
2730
2733
  * Add a EventProcessor to be kept globally.
@@ -2844,6 +2847,22 @@ var Sentry = (function (exports) {
2844
2847
  }
2845
2848
  }
2846
2849
 
2850
+ /*
2851
+ * This file defines flags and constants that can be modified during compile time in order to facilitate tree shaking
2852
+ * for users.
2853
+ *
2854
+ * Debug flags need to be declared in each package individually and must not be imported across package boundaries,
2855
+ * because some build tools have trouble tree-shaking imported guards.
2856
+ *
2857
+ * As a convention, we define debug flags in a `flags.ts` file in the root of a package's `src` folder.
2858
+ *
2859
+ * Debug flag files will contain "magic strings" like `true` that may get replaced with actual values during
2860
+ * our, or the user's build process. Take care when introducing new flags - they must not throw if they are not
2861
+ * replaced.
2862
+ */
2863
+ /** Flag that is true for debug builds, false otherwise. */
2864
+ const IS_DEBUG_BUILD$2 = true;
2865
+
2847
2866
  /**
2848
2867
  * API compatibility version of this hub.
2849
2868
  *
@@ -3116,7 +3135,7 @@ var Sentry = (function (exports) {
3116
3135
  return client.getIntegration(integration);
3117
3136
  }
3118
3137
  catch (_oO) {
3119
- logger.warn(`Cannot retrieve integration ${integration.id} from the current Hub`);
3138
+ IS_DEBUG_BUILD$2 && logger.warn(`Cannot retrieve integration ${integration.id} from the current Hub`);
3120
3139
  return null;
3121
3140
  }
3122
3141
  }
@@ -3227,7 +3246,7 @@ var Sentry = (function (exports) {
3227
3246
  if (sentry && sentry.extensions && typeof sentry.extensions[method] === 'function') {
3228
3247
  return sentry.extensions[method].apply(this, args);
3229
3248
  }
3230
- logger.warn(`Extension method ${method} couldn't be found, doing nothing.`);
3249
+ IS_DEBUG_BUILD$2 && logger.warn(`Extension method ${method} couldn't be found, doing nothing.`);
3231
3250
  }
3232
3251
  }
3233
3252
  /**
@@ -3287,11 +3306,7 @@ var Sentry = (function (exports) {
3287
3306
  * @hidden
3288
3307
  */
3289
3308
  function getHubFromCarrier(carrier) {
3290
- if (carrier && carrier.__SENTRY__ && carrier.__SENTRY__.hub)
3291
- return carrier.__SENTRY__.hub;
3292
- carrier.__SENTRY__ = carrier.__SENTRY__ || {};
3293
- carrier.__SENTRY__.hub = new Hub();
3294
- return carrier.__SENTRY__.hub;
3309
+ return getGlobalSingleton('hub', () => new Hub(), carrier);
3295
3310
  }
3296
3311
  /**
3297
3312
  * This will set passed {@link Hub} on the passed object's __SENTRY__.hub attribute
@@ -3302,8 +3317,8 @@ var Sentry = (function (exports) {
3302
3317
  function setHubOnCarrier(carrier, hub) {
3303
3318
  if (!carrier)
3304
3319
  return false;
3305
- carrier.__SENTRY__ = carrier.__SENTRY__ || {};
3306
- carrier.__SENTRY__.hub = hub;
3320
+ const __SENTRY__ = (carrier.__SENTRY__ = carrier.__SENTRY__ || {});
3321
+ __SENTRY__.hub = hub;
3307
3322
  return true;
3308
3323
  }
3309
3324
 
@@ -3545,6 +3560,22 @@ var Sentry = (function (exports) {
3545
3560
  return `${endpoint}?${encodedOptions}`;
3546
3561
  }
3547
3562
 
3563
+ /*
3564
+ * This file defines flags and constants that can be modified during compile time in order to facilitate tree shaking
3565
+ * for users.
3566
+ *
3567
+ * Debug flags need to be declared in each package individually and must not be imported across package boundaries,
3568
+ * because some build tools have trouble tree-shaking imported guards.
3569
+ *
3570
+ * As a convention, we define debug flags in a `flags.ts` file in the root of a package's `src` folder.
3571
+ *
3572
+ * Debug flag files will contain "magic strings" like `true` that may get replaced with actual values during
3573
+ * our, or the user's build process. Take care when introducing new flags - they must not throw if they are not
3574
+ * replaced.
3575
+ */
3576
+ /** Flag that is true for debug builds, false otherwise. */
3577
+ const IS_DEBUG_BUILD$1 = true;
3578
+
3548
3579
  const installedIntegrations = [];
3549
3580
  /**
3550
3581
  * @private
@@ -3888,7 +3919,7 @@ var Sentry = (function (exports) {
3888
3919
  if (evt) {
3889
3920
  // TODO this is more of the hack trying to solve https://github.com/getsentry/sentry-javascript/issues/2809
3890
3921
  // it is only attached as extra data to the event if the event somehow skips being normalized
3891
- evt.sdkProcessingMetadata = Object.assign(Object.assign({}, evt.sdkProcessingMetadata), { normalizeDepth: normalize(normalizeDepth) });
3922
+ evt.sdkProcessingMetadata = Object.assign(Object.assign({}, evt.sdkProcessingMetadata), { normalizeDepth: `${normalize(normalizeDepth)} (${typeof normalizeDepth})` });
3892
3923
  }
3893
3924
  if (typeof normalizeDepth === 'number' && normalizeDepth > 0) {
3894
3925
  return this._normalizeEvent(evt, normalizeDepth, normalizeMaxBreadth);
@@ -3932,7 +3963,7 @@ var Sentry = (function (exports) {
3932
3963
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
3933
3964
  normalized.contexts.trace = event.contexts.trace;
3934
3965
  }
3935
- event.sdkProcessingMetadata = Object.assign(Object.assign({}, event.sdkProcessingMetadata), { baseClientNormalized: true });
3966
+ normalized.sdkProcessingMetadata = Object.assign(Object.assign({}, normalized.sdkProcessingMetadata), { baseClientNormalized: true });
3936
3967
  return normalized;
3937
3968
  }
3938
3969
  /**
@@ -4155,6 +4186,32 @@ var Sentry = (function (exports) {
4155
4186
  const eventType = event.type || 'event';
4156
4187
  const { transactionSampling } = event.sdkProcessingMetadata || {};
4157
4188
  const { method: samplingMethod, rate: sampleRate } = transactionSampling || {};
4189
+ // TODO: Below is a temporary hack in order to debug a serialization error - see
4190
+ // https://github.com/getsentry/sentry-javascript/issues/2809,
4191
+ // https://github.com/getsentry/sentry-javascript/pull/4425, and
4192
+ // https://github.com/getsentry/sentry-javascript/pull/4574.
4193
+ //
4194
+ // TL; DR: even though we normalize all events (which should prevent this), something is causing `JSON.stringify` to
4195
+ // throw a circular reference error.
4196
+ //
4197
+ // When it's time to remove it:
4198
+ // 1. Delete everything between here and where the request object `req` is created, EXCEPT the line deleting
4199
+ // `sdkProcessingMetadata`
4200
+ // 2. Restore the original version of the request body, which is commented out
4201
+ // 3. Search for either of the PR URLs above and pull out the companion hacks in the browser playwright tests and the
4202
+ // baseClient tests in this package
4203
+ enhanceEventWithSdkInfo(event, api.metadata.sdk);
4204
+ event.tags = event.tags || {};
4205
+ event.extra = event.extra || {};
4206
+ // In theory, all events should be marked as having gone through normalization and so
4207
+ // we should never set this tag/extra data
4208
+ if (!(event.sdkProcessingMetadata && event.sdkProcessingMetadata.baseClientNormalized)) {
4209
+ event.tags.skippedNormalization = true;
4210
+ event.extra.normalizeDepth = event.sdkProcessingMetadata ? event.sdkProcessingMetadata.normalizeDepth : 'unset';
4211
+ }
4212
+ // prevent this data from being sent to sentry
4213
+ // TODO: This is NOT part of the hack - DO NOT DELETE
4214
+ delete event.sdkProcessingMetadata;
4158
4215
  const envelopeHeaders = Object.assign(Object.assign({ event_id: event.event_id, sent_at: new Date().toISOString() }, (sdkInfo && { sdk: sdkInfo })), (!!api.tunnel && { dsn: dsnToString(api.dsn) }));
4159
4216
  const eventItem = [
4160
4217
  {
@@ -4366,9 +4423,14 @@ var Sentry = (function (exports) {
4366
4423
  */
4367
4424
  function initAndBind(clientClass, options) {
4368
4425
  if (options.debug === true) {
4369
- {
4426
+ if (IS_DEBUG_BUILD$1) {
4370
4427
  logger.enable();
4371
4428
  }
4429
+ else {
4430
+ // use `console.warn` rather than `logger.warn` since by non-debug bundles have all `logger.x` statements stripped
4431
+ // eslint-disable-next-line no-console
4432
+ console.warn('[Sentry] Cannot initialize SDK with `debug` option using a non-debug bundle.');
4433
+ }
4372
4434
  }
4373
4435
  const hub = getCurrentHub();
4374
4436
  const scope = hub.getScope();
@@ -4379,7 +4441,57 @@ var Sentry = (function (exports) {
4379
4441
  hub.bindClient(client);
4380
4442
  }
4381
4443
 
4382
- const SDK_VERSION = '6.19.2';
4444
+ const DEFAULT_TRANSPORT_BUFFER_SIZE = 30;
4445
+ /**
4446
+ * Creates a `NewTransport`
4447
+ *
4448
+ * @param options
4449
+ * @param makeRequest
4450
+ */
4451
+ function createTransport(options, makeRequest, buffer = makePromiseBuffer(options.bufferSize || DEFAULT_TRANSPORT_BUFFER_SIZE)) {
4452
+ let rateLimits = {};
4453
+ const flush = (timeout) => buffer.drain(timeout);
4454
+ function send(envelope) {
4455
+ const envCategory = getEnvelopeType(envelope);
4456
+ const category = envCategory === 'event' ? 'error' : envCategory;
4457
+ const request = {
4458
+ category,
4459
+ body: serializeEnvelope(envelope),
4460
+ };
4461
+ // Don't add to buffer if transport is already rate-limited
4462
+ if (isRateLimited(rateLimits, category)) {
4463
+ return rejectedSyncPromise({
4464
+ status: 'rate_limit',
4465
+ reason: getRateLimitReason(rateLimits, category),
4466
+ });
4467
+ }
4468
+ const requestTask = () => makeRequest(request).then(({ body, headers, reason, statusCode }) => {
4469
+ const status = eventStatusFromHttpCode(statusCode);
4470
+ if (headers) {
4471
+ rateLimits = updateRateLimits(rateLimits, headers);
4472
+ }
4473
+ if (status === 'success') {
4474
+ return resolvedSyncPromise({ status, reason });
4475
+ }
4476
+ return rejectedSyncPromise({
4477
+ status,
4478
+ reason: reason ||
4479
+ body ||
4480
+ (status === 'rate_limit' ? getRateLimitReason(rateLimits, category) : 'Unknown transport error'),
4481
+ });
4482
+ });
4483
+ return buffer.add(requestTask);
4484
+ }
4485
+ return {
4486
+ send,
4487
+ flush,
4488
+ };
4489
+ }
4490
+ function getRateLimitReason(rateLimits, category) {
4491
+ return `Too many ${category} requests, backing off until: ${new Date(disabledUntil(rateLimits, category)).toISOString()}`;
4492
+ }
4493
+
4494
+ const SDK_VERSION = '6.19.5';
4383
4495
 
4384
4496
  let originalFunctionToString;
4385
4497
  /** Patch toString calls to return proper name for wrapped functions */
@@ -4473,19 +4585,23 @@ var Sentry = (function (exports) {
4473
4585
  /** JSDoc */
4474
4586
  function _shouldDropEvent$1(event, options) {
4475
4587
  if (options.ignoreInternal && _isSentryError(event)) {
4476
- logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
4588
+ IS_DEBUG_BUILD$1 &&
4589
+ logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
4477
4590
  return true;
4478
4591
  }
4479
4592
  if (_isIgnoredError(event, options.ignoreErrors)) {
4480
- logger.warn(`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`);
4593
+ IS_DEBUG_BUILD$1 &&
4594
+ logger.warn(`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`);
4481
4595
  return true;
4482
4596
  }
4483
4597
  if (_isDeniedUrl(event, options.denyUrls)) {
4484
- logger.warn(`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(event)}.\nUrl: ${_getEventFilterUrl(event)}`);
4598
+ IS_DEBUG_BUILD$1 &&
4599
+ logger.warn(`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(event)}.\nUrl: ${_getEventFilterUrl(event)}`);
4485
4600
  return true;
4486
4601
  }
4487
4602
  if (!_isAllowedUrl(event, options.allowUrls)) {
4488
- logger.warn(`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(event)}.\nUrl: ${_getEventFilterUrl(event)}`);
4603
+ IS_DEBUG_BUILD$1 &&
4604
+ logger.warn(`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(event)}.\nUrl: ${_getEventFilterUrl(event)}`);
4489
4605
  return true;
4490
4606
  }
4491
4607
  return false;
@@ -4522,7 +4638,7 @@ var Sentry = (function (exports) {
4522
4638
  return [`${value}`, `${type}: ${value}`];
4523
4639
  }
4524
4640
  catch (oO) {
4525
- logger.error(`Cannot extract message for event ${getEventDescription(event)}`);
4641
+ IS_DEBUG_BUILD$1 && logger.error(`Cannot extract message for event ${getEventDescription(event)}`);
4526
4642
  return [];
4527
4643
  }
4528
4644
  }
@@ -4564,7 +4680,7 @@ var Sentry = (function (exports) {
4564
4680
  return frames ? _getLastValidUrl(frames) : null;
4565
4681
  }
4566
4682
  catch (oO) {
4567
- logger.error(`Cannot extract url for event ${getEventDescription(event)}`);
4683
+ IS_DEBUG_BUILD$1 && logger.error(`Cannot extract url for event ${getEventDescription(event)}`);
4568
4684
  return null;
4569
4685
  }
4570
4686
  }
@@ -4904,6 +5020,22 @@ var Sentry = (function (exports) {
4904
5020
  return event;
4905
5021
  }
4906
5022
 
5023
+ /*
5024
+ * This file defines flags and constants that can be modified during compile time in order to facilitate tree shaking
5025
+ * for users.
5026
+ *
5027
+ * Debug flags need to be declared in each package individually and must not be imported across package boundaries,
5028
+ * because some build tools have trouble tree-shaking imported guards.
5029
+ *
5030
+ * As a convention, we define debug flags in a `flags.ts` file in the root of a package's `src` folder.
5031
+ *
5032
+ * Debug flag files will contain "magic strings" like `true` that may get replaced with actual values during
5033
+ * our, or the user's build process. Take care when introducing new flags - they must not throw if they are not
5034
+ * replaced.
5035
+ */
5036
+ /** Flag that is true for debug builds, false otherwise. */
5037
+ const IS_DEBUG_BUILD = true;
5038
+
4907
5039
  const global$4 = getGlobalObject();
4908
5040
  let cachedFetchImpl;
4909
5041
  /**
@@ -5056,7 +5188,7 @@ var Sentry = (function (exports) {
5056
5188
  // A correct type for map-based implementation if we want to go that route
5057
5189
  // would be `Partial<Record<SentryRequestType, Partial<Record<Outcome, number>>>>`
5058
5190
  const key = `${requestTypeToCategory(category)}:${reason}`;
5059
- logger.log(`Adding outcome: ${key}`);
5191
+ IS_DEBUG_BUILD && logger.log(`Adding outcome: ${key}`);
5060
5192
  this._outcomes[key] = (_a = this._outcomes[key], (_a !== null && _a !== void 0 ? _a : 0)) + 1;
5061
5193
  }
5062
5194
  /**
@@ -5070,10 +5202,10 @@ var Sentry = (function (exports) {
5070
5202
  this._outcomes = {};
5071
5203
  // Nothing to send
5072
5204
  if (!Object.keys(outcomes).length) {
5073
- logger.log('No outcomes to flush');
5205
+ IS_DEBUG_BUILD && logger.log('No outcomes to flush');
5074
5206
  return;
5075
5207
  }
5076
- logger.log(`Flushing outcomes:\n${JSON.stringify(outcomes, null, 2)}`);
5208
+ IS_DEBUG_BUILD && logger.log(`Flushing outcomes:\n${JSON.stringify(outcomes, null, 2)}`);
5077
5209
  const url = getEnvelopeEndpointWithUrlEncodedAuth(this._api.dsn, this._api.tunnel);
5078
5210
  const discardedEvents = Object.keys(outcomes).map(key => {
5079
5211
  const [category, reason] = key.split(':');
@@ -5089,7 +5221,7 @@ var Sentry = (function (exports) {
5089
5221
  sendReport(url, serializeEnvelope(envelope));
5090
5222
  }
5091
5223
  catch (e) {
5092
- logger.error(e);
5224
+ IS_DEBUG_BUILD && logger.error(e);
5093
5225
  }
5094
5226
  }
5095
5227
  /**
@@ -5099,8 +5231,9 @@ var Sentry = (function (exports) {
5099
5231
  const status = eventStatusFromHttpCode(response.status);
5100
5232
  this._rateLimits = updateRateLimits(this._rateLimits, headers);
5101
5233
  // eslint-disable-next-line deprecation/deprecation
5102
- if (this._isRateLimited(requestType) && isDebugBuild()) {
5103
- // eslint-disable-next-line deprecation/deprecation
5234
+ if (this._isRateLimited(requestType)) {
5235
+ IS_DEBUG_BUILD &&
5236
+ // eslint-disable-next-line deprecation/deprecation
5104
5237
  logger.warn(`Too many ${requestType} requests, backing off until: ${this._disabledUntil(requestType)}`);
5105
5238
  }
5106
5239
  if (status === 'success') {
@@ -5248,11 +5381,76 @@ var Sentry = (function (exports) {
5248
5381
  }
5249
5382
  }
5250
5383
 
5384
+ /**
5385
+ * Creates a Transport that uses the Fetch API to send events to Sentry.
5386
+ */
5387
+ function makeNewFetchTransport(options, nativeFetch = getNativeFetchImplementation()) {
5388
+ function makeRequest(request) {
5389
+ const requestOptions = Object.assign({ body: request.body, method: 'POST', referrerPolicy: 'origin' }, options.requestOptions);
5390
+ return nativeFetch(options.url, requestOptions).then(response => {
5391
+ return response.text().then(body => ({
5392
+ body,
5393
+ headers: {
5394
+ 'x-sentry-rate-limits': response.headers.get('X-Sentry-Rate-Limits'),
5395
+ 'retry-after': response.headers.get('Retry-After'),
5396
+ },
5397
+ reason: response.statusText,
5398
+ statusCode: response.status,
5399
+ }));
5400
+ });
5401
+ }
5402
+ return createTransport({ bufferSize: options.bufferSize }, makeRequest);
5403
+ }
5404
+
5405
+ /**
5406
+ * The DONE ready state for XmlHttpRequest
5407
+ *
5408
+ * Defining it here as a constant b/c XMLHttpRequest.DONE is not always defined
5409
+ * (e.g. during testing, it is `undefined`)
5410
+ *
5411
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readyState}
5412
+ */
5413
+ const XHR_READYSTATE_DONE = 4;
5414
+ /**
5415
+ * Creates a Transport that uses the XMLHttpRequest API to send events to Sentry.
5416
+ */
5417
+ function makeNewXHRTransport(options) {
5418
+ function makeRequest(request) {
5419
+ return new SyncPromise((resolve, _reject) => {
5420
+ const xhr = new XMLHttpRequest();
5421
+ xhr.onreadystatechange = () => {
5422
+ if (xhr.readyState === XHR_READYSTATE_DONE) {
5423
+ const response = {
5424
+ body: xhr.response,
5425
+ headers: {
5426
+ 'x-sentry-rate-limits': xhr.getResponseHeader('X-Sentry-Rate-Limits'),
5427
+ 'retry-after': xhr.getResponseHeader('Retry-After'),
5428
+ },
5429
+ reason: xhr.statusText,
5430
+ statusCode: xhr.status,
5431
+ };
5432
+ resolve(response);
5433
+ }
5434
+ };
5435
+ xhr.open('POST', options.url);
5436
+ for (const header in options.headers) {
5437
+ if (Object.prototype.hasOwnProperty.call(options.headers, header)) {
5438
+ xhr.setRequestHeader(header, options.headers[header]);
5439
+ }
5440
+ }
5441
+ xhr.send(request.body);
5442
+ });
5443
+ }
5444
+ return createTransport({ bufferSize: options.bufferSize }, makeRequest);
5445
+ }
5446
+
5251
5447
  var index = /*#__PURE__*/Object.freeze({
5252
5448
  __proto__: null,
5253
5449
  BaseTransport: BaseTransport,
5254
5450
  FetchTransport: FetchTransport,
5255
- XHRTransport: XHRTransport
5451
+ XHRTransport: XHRTransport,
5452
+ makeNewFetchTransport: makeNewFetchTransport,
5453
+ makeNewXHRTransport: makeNewXHRTransport
5256
5454
  });
5257
5455
 
5258
5456
  /**
@@ -5281,12 +5479,20 @@ var Sentry = (function (exports) {
5281
5479
  return super._setupTransport();
5282
5480
  }
5283
5481
  const transportOptions = Object.assign(Object.assign({}, this._options.transportOptions), { dsn: this._options.dsn, tunnel: this._options.tunnel, sendClientReports: this._options.sendClientReports, _metadata: this._options._metadata });
5482
+ const api = initAPIDetails(transportOptions.dsn, transportOptions._metadata, transportOptions.tunnel);
5483
+ const url = getEnvelopeEndpointWithUrlEncodedAuth(api.dsn, api.tunnel);
5284
5484
  if (this._options.transport) {
5285
5485
  return new this._options.transport(transportOptions);
5286
5486
  }
5287
5487
  if (supportsFetch()) {
5488
+ const requestOptions = Object.assign({}, transportOptions.fetchParameters);
5489
+ this._newTransport = makeNewFetchTransport({ requestOptions, url });
5288
5490
  return new FetchTransport(transportOptions);
5289
5491
  }
5492
+ this._newTransport = makeNewXHRTransport({
5493
+ url,
5494
+ headers: transportOptions.headers,
5495
+ });
5290
5496
  return new XHRTransport(transportOptions);
5291
5497
  }
5292
5498
  }
@@ -5416,11 +5622,11 @@ var Sentry = (function (exports) {
5416
5622
  return;
5417
5623
  }
5418
5624
  if (!options.eventId) {
5419
- logger.error('Missing eventId option in showReportDialog call');
5625
+ IS_DEBUG_BUILD && logger.error('Missing eventId option in showReportDialog call');
5420
5626
  return;
5421
5627
  }
5422
5628
  if (!options.dsn) {
5423
- logger.error('Missing dsn option in showReportDialog call');
5629
+ IS_DEBUG_BUILD && logger.error('Missing dsn option in showReportDialog call');
5424
5630
  return;
5425
5631
  }
5426
5632
  const script = global$2.document.createElement('script');
@@ -5612,7 +5818,7 @@ var Sentry = (function (exports) {
5612
5818
  return event;
5613
5819
  }
5614
5820
  function globalHandlerLog(type) {
5615
- logger.log(`Global Handler attached: ${type}`);
5821
+ IS_DEBUG_BUILD && logger.log(`Global Handler attached: ${type}`);
5616
5822
  }
5617
5823
  function addMechanismAndCapture(hub, error, event, type) {
5618
5824
  addExceptionMechanism(event, {
@@ -6178,7 +6384,7 @@ var Sentry = (function (exports) {
6178
6384
  // Juuust in case something goes wrong
6179
6385
  try {
6180
6386
  if (_shouldDropEvent(currentEvent, self._previousEvent)) {
6181
- logger.warn('Event dropped due to being a duplicate of previously captured event.');
6387
+ IS_DEBUG_BUILD && logger.warn('Event dropped due to being a duplicate of previously captured event.');
6182
6388
  return null;
6183
6389
  }
6184
6390
  }
@@ -6372,7 +6578,7 @@ var Sentry = (function (exports) {
6372
6578
  return;
6373
6579
  }
6374
6580
  if (!this._isEnabled()) {
6375
- logger.error('Trying to call showReportDialog with Sentry Client disabled');
6581
+ IS_DEBUG_BUILD && logger.error('Trying to call showReportDialog with Sentry Client disabled');
6376
6582
  return;
6377
6583
  }
6378
6584
  injectReportDialog(Object.assign(Object.assign({}, options), { dsn: options.dsn || this.getDsn() }));
@@ -6539,7 +6745,7 @@ var Sentry = (function (exports) {
6539
6745
  if (client) {
6540
6746
  return client.flush(timeout);
6541
6747
  }
6542
- logger.warn('Cannot flush events. No client defined.');
6748
+ IS_DEBUG_BUILD && logger.warn('Cannot flush events. No client defined.');
6543
6749
  return resolvedSyncPromise(false);
6544
6750
  }
6545
6751
  /**
@@ -6555,7 +6761,7 @@ var Sentry = (function (exports) {
6555
6761
  if (client) {
6556
6762
  return client.close(timeout);
6557
6763
  }
6558
- logger.warn('Cannot flush events and disable SDK. No client defined.');
6764
+ IS_DEBUG_BUILD && logger.warn('Cannot flush events and disable SDK. No client defined.');
6559
6765
  return resolvedSyncPromise(false);
6560
6766
  }
6561
6767
  /**
@@ -6580,7 +6786,7 @@ var Sentry = (function (exports) {
6580
6786
  const window = getGlobalObject();
6581
6787
  const document = window.document;
6582
6788
  if (typeof document === 'undefined') {
6583
- logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');
6789
+ IS_DEBUG_BUILD && logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');
6584
6790
  return;
6585
6791
  }
6586
6792
  const hub = getCurrentHub();