@sentry/browser 6.18.2 → 6.19.2

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 (167) hide show
  1. package/bundles/bundle.debug.min.js +3 -0
  2. package/bundles/bundle.debug.min.js.map +1 -0
  3. package/bundles/bundle.es6.debug.min.js +3 -0
  4. package/bundles/bundle.es6.debug.min.js.map +1 -0
  5. package/{build → bundles}/bundle.es6.js +723 -702
  6. package/bundles/bundle.es6.js.map +1 -0
  7. package/bundles/bundle.es6.min.js +3 -0
  8. package/bundles/bundle.es6.min.js.map +1 -0
  9. package/{build → bundles}/bundle.js +777 -749
  10. package/bundles/bundle.js.map +1 -0
  11. package/bundles/bundle.min.js +3 -0
  12. package/bundles/bundle.min.js.map +1 -0
  13. package/dist/backend.d.ts.map +1 -1
  14. package/dist/backend.js.map +1 -1
  15. package/dist/client.d.ts.map +1 -1
  16. package/dist/client.js +1 -1
  17. package/dist/client.js.map +1 -1
  18. package/dist/eventbuilder.d.ts.map +1 -1
  19. package/dist/eventbuilder.js.map +1 -1
  20. package/dist/exports.d.ts.map +1 -1
  21. package/dist/exports.js.map +1 -1
  22. package/dist/helpers.d.ts.map +1 -1
  23. package/dist/helpers.js +2 -6
  24. package/dist/helpers.js.map +1 -1
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js.map +1 -1
  27. package/dist/integrations/breadcrumbs.d.ts.map +1 -1
  28. package/dist/integrations/breadcrumbs.js.map +1 -1
  29. package/dist/integrations/dedupe.d.ts.map +1 -1
  30. package/dist/integrations/dedupe.js +1 -1
  31. package/dist/integrations/dedupe.js.map +1 -1
  32. package/dist/integrations/globalhandlers.d.ts.map +1 -1
  33. package/dist/integrations/globalhandlers.js +1 -3
  34. package/dist/integrations/globalhandlers.js.map +1 -1
  35. package/dist/integrations/index.d.ts.map +1 -1
  36. package/dist/integrations/index.js.map +1 -1
  37. package/dist/integrations/linkederrors.d.ts.map +1 -1
  38. package/dist/integrations/linkederrors.js.map +1 -1
  39. package/dist/integrations/trycatch.d.ts.map +1 -1
  40. package/dist/integrations/trycatch.js +26 -21
  41. package/dist/integrations/trycatch.js.map +1 -1
  42. package/dist/integrations/useragent.d.ts.map +1 -1
  43. package/dist/integrations/useragent.js.map +1 -1
  44. package/dist/sdk.d.ts.map +1 -1
  45. package/dist/sdk.js +3 -9
  46. package/dist/sdk.js.map +1 -1
  47. package/dist/stack-parsers.d.ts.map +1 -1
  48. package/dist/stack-parsers.js.map +1 -1
  49. package/dist/transports/base.d.ts +6 -6
  50. package/dist/transports/base.d.ts.map +1 -1
  51. package/dist/transports/base.js +17 -68
  52. package/dist/transports/base.js.map +1 -1
  53. package/dist/transports/fetch.d.ts.map +1 -1
  54. package/dist/transports/fetch.js +2 -0
  55. package/dist/transports/fetch.js.map +1 -1
  56. package/dist/transports/index.d.ts.map +1 -1
  57. package/dist/transports/index.js.map +1 -1
  58. package/dist/transports/utils.d.ts.map +1 -1
  59. package/dist/transports/utils.js +1 -2
  60. package/dist/transports/utils.js.map +1 -1
  61. package/dist/transports/xhr.d.ts.map +1 -1
  62. package/dist/transports/xhr.js +2 -0
  63. package/dist/transports/xhr.js.map +1 -1
  64. package/dist/version.d.ts.map +1 -1
  65. package/dist/version.js.map +1 -1
  66. package/esm/backend.d.ts.map +1 -1
  67. package/esm/backend.js.map +1 -1
  68. package/esm/client.d.ts.map +1 -1
  69. package/esm/client.js +2 -2
  70. package/esm/client.js.map +1 -1
  71. package/esm/eventbuilder.d.ts.map +1 -1
  72. package/esm/eventbuilder.js.map +1 -1
  73. package/esm/exports.d.ts.map +1 -1
  74. package/esm/exports.js.map +1 -1
  75. package/esm/helpers.d.ts.map +1 -1
  76. package/esm/helpers.js +2 -6
  77. package/esm/helpers.js.map +1 -1
  78. package/esm/index.d.ts.map +1 -1
  79. package/esm/index.js.map +1 -1
  80. package/esm/integrations/breadcrumbs.d.ts.map +1 -1
  81. package/esm/integrations/breadcrumbs.js.map +1 -1
  82. package/esm/integrations/dedupe.d.ts.map +1 -1
  83. package/esm/integrations/dedupe.js +2 -2
  84. package/esm/integrations/dedupe.js.map +1 -1
  85. package/esm/integrations/globalhandlers.d.ts.map +1 -1
  86. package/esm/integrations/globalhandlers.js +1 -3
  87. package/esm/integrations/globalhandlers.js.map +1 -1
  88. package/esm/integrations/index.d.ts.map +1 -1
  89. package/esm/integrations/index.js.map +1 -1
  90. package/esm/integrations/linkederrors.d.ts.map +1 -1
  91. package/esm/integrations/linkederrors.js.map +1 -1
  92. package/esm/integrations/trycatch.d.ts.map +1 -1
  93. package/esm/integrations/trycatch.js +26 -21
  94. package/esm/integrations/trycatch.js.map +1 -1
  95. package/esm/integrations/useragent.d.ts.map +1 -1
  96. package/esm/integrations/useragent.js.map +1 -1
  97. package/esm/sdk.d.ts.map +1 -1
  98. package/esm/sdk.js +3 -9
  99. package/esm/sdk.js.map +1 -1
  100. package/esm/stack-parsers.d.ts.map +1 -1
  101. package/esm/stack-parsers.js.map +1 -1
  102. package/esm/transports/base.d.ts +6 -6
  103. package/esm/transports/base.d.ts.map +1 -1
  104. package/esm/transports/base.js +19 -70
  105. package/esm/transports/base.js.map +1 -1
  106. package/esm/transports/fetch.d.ts.map +1 -1
  107. package/esm/transports/fetch.js +2 -0
  108. package/esm/transports/fetch.js.map +1 -1
  109. package/esm/transports/index.d.ts.map +1 -1
  110. package/esm/transports/index.js.map +1 -1
  111. package/esm/transports/utils.d.ts.map +1 -1
  112. package/esm/transports/utils.js +1 -2
  113. package/esm/transports/utils.js.map +1 -1
  114. package/esm/transports/xhr.d.ts.map +1 -1
  115. package/esm/transports/xhr.js +2 -0
  116. package/esm/transports/xhr.js.map +1 -1
  117. package/esm/version.d.ts.map +1 -1
  118. package/esm/version.js.map +1 -1
  119. package/package.json +14 -12
  120. package/types/backend.d.ts +43 -0
  121. package/types/backend.d.ts.map +1 -0
  122. package/types/client.d.ts +33 -0
  123. package/types/client.d.ts.map +1 -0
  124. package/types/eventbuilder.d.ts +39 -0
  125. package/types/eventbuilder.d.ts.map +1 -0
  126. package/types/exports.d.ts +10 -0
  127. package/types/exports.d.ts.map +1 -0
  128. package/types/helpers.d.ts +52 -0
  129. package/types/helpers.d.ts.map +1 -0
  130. package/types/index.d.ts +16 -0
  131. package/types/index.d.ts.map +1 -0
  132. package/types/integrations/breadcrumbs.d.ts +47 -0
  133. package/types/integrations/breadcrumbs.d.ts.map +1 -0
  134. package/types/integrations/dedupe.d.ts +21 -0
  135. package/types/integrations/dedupe.d.ts.map +1 -0
  136. package/types/integrations/globalhandlers.d.ts +30 -0
  137. package/types/integrations/globalhandlers.d.ts.map +1 -0
  138. package/types/integrations/index.d.ts +7 -0
  139. package/types/integrations/index.d.ts.map +1 -0
  140. package/types/integrations/linkederrors.d.ts +42 -0
  141. package/types/integrations/linkederrors.d.ts.map +1 -0
  142. package/types/integrations/trycatch.d.ts +33 -0
  143. package/types/integrations/trycatch.d.ts.map +1 -0
  144. package/types/integrations/useragent.d.ts +17 -0
  145. package/types/integrations/useragent.d.ts.map +1 -0
  146. package/types/sdk.d.ts +112 -0
  147. package/types/sdk.d.ts.map +1 -0
  148. package/types/stack-parsers.d.ts +7 -0
  149. package/types/stack-parsers.d.ts.map +1 -0
  150. package/types/transports/base.d.ts +65 -0
  151. package/types/transports/base.d.ts.map +1 -0
  152. package/types/transports/fetch.d.ts +17 -0
  153. package/types/transports/fetch.d.ts.map +1 -0
  154. package/types/transports/index.d.ts +4 -0
  155. package/types/transports/index.d.ts.map +1 -0
  156. package/types/transports/utils.d.ts +48 -0
  157. package/types/transports/utils.d.ts.map +1 -0
  158. package/types/transports/xhr.d.ts +11 -0
  159. package/types/transports/xhr.d.ts.map +1 -0
  160. package/types/version.d.ts +2 -0
  161. package/types/version.d.ts.map +1 -0
  162. package/build/bundle.es6.js.map +0 -1
  163. package/build/bundle.es6.min.js +0 -3
  164. package/build/bundle.es6.min.js.map +0 -1
  165. package/build/bundle.js.map +0 -1
  166. package/build/bundle.min.js +0 -3
  167. package/build/bundle.min.js.map +0 -1
@@ -1,4 +1,4 @@
1
- /*! @sentry/browser 6.18.2 (22f518e) | https://github.com/getsentry/sentry-javascript */
1
+ /*! @sentry/browser 6.19.2 (f49c509) | https://github.com/getsentry/sentry-javascript */
2
2
  var Sentry = (function (exports) {
3
3
 
4
4
  /**
@@ -36,14 +36,11 @@ var Sentry = (function (exports) {
36
36
  }
37
37
 
38
38
  /**
39
- * This module mostly exists for optimizations in the build process
40
- * through rollup and terser. We define some global constants which
41
- * are normally undefined. However terser overrides these with global
42
- * definitions which can be evaluated by the static analyzer when
43
- * creating a bundle.
44
- *
45
- * In turn the `isDebugBuild` and `isBrowserBundle` functions are pure
46
- * and can help us remove unused code from the bundles.
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.
47
44
  */
48
45
  /**
49
46
  * Figures out if we're building with debug functionality.
@@ -51,7 +48,7 @@ var Sentry = (function (exports) {
51
48
  * @returns true if this is a debug build
52
49
  */
53
50
  function isDebugBuild() {
54
- return typeof __SENTRY_NO_DEBUG__ !== 'undefined' && !true;
51
+ return true;
55
52
  }
56
53
 
57
54
  /**
@@ -415,9 +412,6 @@ var Sentry = (function (exports) {
415
412
  };
416
413
  }
417
414
  function validateDsn(dsn) {
418
- if (!isDebugBuild()) {
419
- return;
420
- }
421
415
  const { port, projectId, protocol } = dsn;
422
416
  const requiredComponents = ['protocol', 'publicKey', 'host', 'projectId'];
423
417
  requiredComponents.forEach(component => {
@@ -449,6 +443,7 @@ var Sentry = (function (exports) {
449
443
  const global$6 = getGlobalObject();
450
444
  /** Prefix for logging strings */
451
445
  const PREFIX = 'Sentry Logger ';
446
+ const CONSOLE_LEVELS = ['debug', 'info', 'warn', 'error', 'log', 'assert'];
452
447
  /**
453
448
  * Temporarily unwrap `console.log` and friends in order to perform the given callback using the original methods.
454
449
  * Restores wrapping after the callback completes.
@@ -458,7 +453,6 @@ var Sentry = (function (exports) {
458
453
  */
459
454
  function consoleSandbox(callback) {
460
455
  const global = getGlobalObject();
461
- const levels = ['debug', 'info', 'warn', 'error', 'log', 'assert'];
462
456
  if (!('console' in global)) {
463
457
  return callback();
464
458
  }
@@ -466,7 +460,7 @@ var Sentry = (function (exports) {
466
460
  const originalConsole = global.console;
467
461
  const wrappedLevels = {};
468
462
  // Restore all wrapped console methods
469
- levels.forEach(level => {
463
+ CONSOLE_LEVELS.forEach(level => {
470
464
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
471
465
  if (level in global.console && originalConsole[level].__sentry_original__) {
472
466
  wrappedLevels[level] = originalConsole[level];
@@ -523,116 +517,12 @@ var Sentry = (function (exports) {
523
517
  });
524
518
  }
525
519
  }
526
- // Ensure we only have a single logger instance, even if multiple versions of @sentry/utils are being used
527
- global$6.__SENTRY__ = global$6.__SENTRY__ || {};
528
- const logger = global$6.__SENTRY__.logger || (global$6.__SENTRY__.logger = new Logger());
529
-
530
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
531
- /* eslint-disable @typescript-eslint/no-explicit-any */
532
- /**
533
- * Helper to decycle json objects
534
- */
535
- function memoBuilder() {
536
- const hasWeakSet = typeof WeakSet === 'function';
537
- const inner = hasWeakSet ? new WeakSet() : [];
538
- function memoize(obj) {
539
- if (hasWeakSet) {
540
- if (inner.has(obj)) {
541
- return true;
542
- }
543
- inner.add(obj);
544
- return false;
545
- }
546
- // eslint-disable-next-line @typescript-eslint/prefer-for-of
547
- for (let i = 0; i < inner.length; i++) {
548
- const value = inner[i];
549
- if (value === obj) {
550
- return true;
551
- }
552
- }
553
- inner.push(obj);
554
- return false;
555
- }
556
- function unmemoize(obj) {
557
- if (hasWeakSet) {
558
- inner.delete(obj);
559
- }
560
- else {
561
- for (let i = 0; i < inner.length; i++) {
562
- if (inner[i] === obj) {
563
- inner.splice(i, 1);
564
- break;
565
- }
566
- }
567
- }
568
- }
569
- return [memoize, unmemoize];
570
- }
571
-
572
- const STACKTRACE_LIMIT = 50;
573
- /**
574
- * Creates a stack parser with the supplied line parsers
575
- *
576
- * StackFrames are returned in the correct order for Sentry Exception
577
- * frames and with Sentry SDK internal frames removed from the top and bottom
578
- *
579
- */
580
- function createStackParser(...parsers) {
581
- const sortedParsers = parsers.sort((a, b) => a[0] - b[0]).map(p => p[1]);
582
- return (stack, skipFirst = 0) => {
583
- const frames = [];
584
- for (const line of stack.split('\n').slice(skipFirst)) {
585
- for (const parser of sortedParsers) {
586
- const frame = parser(line);
587
- if (frame) {
588
- frames.push(frame);
589
- break;
590
- }
591
- }
592
- }
593
- return stripSentryFramesAndReverse(frames);
594
- };
595
- }
596
- /**
597
- * @hidden
598
- */
599
- function stripSentryFramesAndReverse(stack) {
600
- if (!stack.length) {
601
- return [];
602
- }
603
- let localStack = stack;
604
- const firstFrameFunction = localStack[0].function || '';
605
- const lastFrameFunction = localStack[localStack.length - 1].function || '';
606
- // If stack starts with one of our API calls, remove it (starts, meaning it's the top of the stack - aka last call)
607
- if (firstFrameFunction.indexOf('captureMessage') !== -1 || firstFrameFunction.indexOf('captureException') !== -1) {
608
- localStack = localStack.slice(1);
609
- }
610
- // If stack ends with one of our internal API calls, remove it (ends, meaning it's the bottom of the stack - aka top-most call)
611
- if (lastFrameFunction.indexOf('sentryWrapped') !== -1) {
612
- localStack = localStack.slice(0, -1);
613
- }
614
- // The frame where the crash happened, should be the last entry in the array
615
- return localStack
616
- .slice(0, STACKTRACE_LIMIT)
617
- .map(frame => (Object.assign(Object.assign({}, frame), { filename: frame.filename || localStack[0].filename, function: frame.function || '?' })))
618
- .reverse();
619
- }
620
- const defaultFunctionName = '<anonymous>';
621
- /**
622
- * Safely extract function name from itself
623
- */
624
- function getFunctionName(fn) {
625
- try {
626
- if (!fn || typeof fn !== 'function') {
627
- return defaultFunctionName;
628
- }
629
- return fn.name || defaultFunctionName;
630
- }
631
- catch (e) {
632
- // Just accessing custom props in some Selenium environments
633
- // can cause a "Permission denied" exception (see raven-js#495).
634
- return defaultFunctionName;
635
- }
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;
636
526
  }
637
527
 
638
528
  /**
@@ -824,176 +714,6 @@ var Sentry = (function (exports) {
824
714
  }
825
715
  return value;
826
716
  }
827
- /** Calculates bytes size of input string */
828
- function utf8Length(value) {
829
- // eslint-disable-next-line no-bitwise
830
- return ~-encodeURI(value).split(/%..|./).length;
831
- }
832
- /** Calculates bytes size of input object */
833
- function jsonSize(value) {
834
- return utf8Length(JSON.stringify(value));
835
- }
836
- /** JSDoc */
837
- function normalizeToSize(object,
838
- // Default Node.js REPL depth
839
- depth = 3,
840
- // 100kB, as 200kB is max payload size, so half sounds reasonable
841
- maxSize = 100 * 1024) {
842
- const serialized = normalize(object, depth);
843
- if (jsonSize(serialized) > maxSize) {
844
- return normalizeToSize(object, depth - 1, maxSize);
845
- }
846
- return serialized;
847
- }
848
- /**
849
- * Transform any non-primitive, BigInt, or Symbol-type value into a string. Acts as a no-op on strings, numbers,
850
- * booleans, null, and undefined.
851
- *
852
- * @param value The value to stringify
853
- * @returns For non-primitive, BigInt, and Symbol-type values, a string denoting the value's type, type and value, or
854
- * type and `description` property, respectively. For non-BigInt, non-Symbol primitives, returns the original value,
855
- * unchanged.
856
- */
857
- function serializeValue(value) {
858
- // Node.js REPL notation
859
- if (typeof value === 'string') {
860
- return value;
861
- }
862
- const type = Object.prototype.toString.call(value);
863
- if (type === '[object Object]') {
864
- return '[Object]';
865
- }
866
- if (type === '[object Array]') {
867
- return '[Array]';
868
- }
869
- // `makeSerializable` provides a string representation of certain non-serializable values. For all others, it's a
870
- // pass-through.
871
- const serializable = makeSerializable(value);
872
- return isPrimitive(serializable) ? serializable : type;
873
- }
874
- /**
875
- * makeSerializable()
876
- *
877
- * Takes unserializable input and make it serializer-friendly.
878
- *
879
- * Handles globals, functions, `undefined`, `NaN`, and other non-serializable values.
880
- */
881
- function makeSerializable(value, key) {
882
- if (key === 'domain' && value && typeof value === 'object' && value._events) {
883
- return '[Domain]';
884
- }
885
- if (key === 'domainEmitter') {
886
- return '[DomainEmitter]';
887
- }
888
- if (typeof global !== 'undefined' && value === global) {
889
- return '[Global]';
890
- }
891
- // It's safe to use `window` and `document` here in this manner, as we are asserting using `typeof` first
892
- // which won't throw if they are not present.
893
- // eslint-disable-next-line no-restricted-globals
894
- if (typeof window !== 'undefined' && value === window) {
895
- return '[Window]';
896
- }
897
- // eslint-disable-next-line no-restricted-globals
898
- if (typeof document !== 'undefined' && value === document) {
899
- return '[Document]';
900
- }
901
- // React's SyntheticEvent thingy
902
- if (isSyntheticEvent(value)) {
903
- return '[SyntheticEvent]';
904
- }
905
- if (typeof value === 'number' && value !== value) {
906
- return '[NaN]';
907
- }
908
- if (value === void 0) {
909
- return '[undefined]';
910
- }
911
- if (typeof value === 'function') {
912
- return `[Function: ${getFunctionName(value)}]`;
913
- }
914
- // symbols and bigints are considered primitives by TS, but aren't natively JSON-serilaizable
915
- if (typeof value === 'symbol') {
916
- return `[${String(value)}]`;
917
- }
918
- if (typeof value === 'bigint') {
919
- return `[BigInt: ${String(value)}]`;
920
- }
921
- return value;
922
- }
923
- /**
924
- * Walks an object to perform a normalization on it
925
- *
926
- * @param key of object that's walked in current iteration
927
- * @param value object to be walked
928
- * @param depth Optional number indicating how deep should walking be performed
929
- * @param memo Optional Memo class handling decycling
930
- */
931
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
932
- function walk(key, value, depth = +Infinity, memo = memoBuilder()) {
933
- const [memoize, unmemoize] = memo;
934
- // If we reach the maximum depth, serialize whatever is left
935
- if (depth === 0) {
936
- return serializeValue(value);
937
- }
938
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
939
- // If value implements `toJSON` method, call it and return early
940
- if (value !== null && value !== undefined && typeof value.toJSON === 'function') {
941
- return value.toJSON();
942
- }
943
- /* eslint-enable @typescript-eslint/no-unsafe-member-access */
944
- // `makeSerializable` provides a string representation of certain non-serializable values. For all others, it's a
945
- // pass-through. If what comes back is a primitive (either because it's been stringified or because it was primitive
946
- // all along), we're done.
947
- const serializable = makeSerializable(value, key);
948
- if (isPrimitive(serializable)) {
949
- return serializable;
950
- }
951
- // Create source that we will use for the next iteration. It will either be an objectified error object (`Error` type
952
- // with extracted key:value pairs) or the input itself.
953
- const source = getWalkSource(value);
954
- // Create an accumulator that will act as a parent for all future itterations of that branch
955
- const acc = Array.isArray(value) ? [] : {};
956
- // If we already walked that branch, bail out, as it's circular reference
957
- if (memoize(value)) {
958
- return '[Circular ~]';
959
- }
960
- // Walk all keys of the source
961
- for (const innerKey in source) {
962
- // Avoid iterating over fields in the prototype if they've somehow been exposed to enumeration.
963
- if (!Object.prototype.hasOwnProperty.call(source, innerKey)) {
964
- continue;
965
- }
966
- // Recursively walk through all the child nodes
967
- const innerValue = source[innerKey];
968
- acc[innerKey] = walk(innerKey, innerValue, depth - 1, memo);
969
- }
970
- // Once walked through all the branches, remove the parent from memo storage
971
- unmemoize(value);
972
- // Return accumulated values
973
- return acc;
974
- }
975
- /**
976
- * normalize()
977
- *
978
- * - Creates a copy to prevent original input mutation
979
- * - Skip non-enumerablers
980
- * - Calls `toJSON` if implemented
981
- * - Removes circular references
982
- * - Translates non-serializeable values (undefined/NaN/Functions) to serializable format
983
- * - Translates known global objects/Classes to a string representations
984
- * - Takes care of Error objects serialization
985
- * - Optionally limit depth of final output
986
- */
987
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
988
- function normalize(input, depth) {
989
- try {
990
- // since we're at the outermost level, there is no key
991
- return walk('', input, depth);
992
- }
993
- catch (_oO) {
994
- return '**non-serializable**';
995
- }
996
- }
997
717
  /**
998
718
  * Given any captured exception, extract its keys and create a sorted
999
719
  * and truncated list that will be used inside the event message.
@@ -1042,6 +762,72 @@ var Sentry = (function (exports) {
1042
762
  return val;
1043
763
  }
1044
764
 
765
+ const STACKTRACE_LIMIT = 50;
766
+ /**
767
+ * Creates a stack parser with the supplied line parsers
768
+ *
769
+ * StackFrames are returned in the correct order for Sentry Exception
770
+ * frames and with Sentry SDK internal frames removed from the top and bottom
771
+ *
772
+ */
773
+ function createStackParser(...parsers) {
774
+ const sortedParsers = parsers.sort((a, b) => a[0] - b[0]).map(p => p[1]);
775
+ return (stack, skipFirst = 0) => {
776
+ const frames = [];
777
+ for (const line of stack.split('\n').slice(skipFirst)) {
778
+ for (const parser of sortedParsers) {
779
+ const frame = parser(line);
780
+ if (frame) {
781
+ frames.push(frame);
782
+ break;
783
+ }
784
+ }
785
+ }
786
+ return stripSentryFramesAndReverse(frames);
787
+ };
788
+ }
789
+ /**
790
+ * @hidden
791
+ */
792
+ function stripSentryFramesAndReverse(stack) {
793
+ if (!stack.length) {
794
+ return [];
795
+ }
796
+ let localStack = stack;
797
+ const firstFrameFunction = localStack[0].function || '';
798
+ const lastFrameFunction = localStack[localStack.length - 1].function || '';
799
+ // If stack starts with one of our API calls, remove it (starts, meaning it's the top of the stack - aka last call)
800
+ if (firstFrameFunction.indexOf('captureMessage') !== -1 || firstFrameFunction.indexOf('captureException') !== -1) {
801
+ localStack = localStack.slice(1);
802
+ }
803
+ // If stack ends with one of our internal API calls, remove it (ends, meaning it's the bottom of the stack - aka top-most call)
804
+ if (lastFrameFunction.indexOf('sentryWrapped') !== -1) {
805
+ localStack = localStack.slice(0, -1);
806
+ }
807
+ // The frame where the crash happened, should be the last entry in the array
808
+ return localStack
809
+ .slice(0, STACKTRACE_LIMIT)
810
+ .map(frame => (Object.assign(Object.assign({}, frame), { filename: frame.filename || localStack[0].filename, function: frame.function || '?' })))
811
+ .reverse();
812
+ }
813
+ const defaultFunctionName = '<anonymous>';
814
+ /**
815
+ * Safely extract function name from itself
816
+ */
817
+ function getFunctionName(fn) {
818
+ try {
819
+ if (!fn || typeof fn !== 'function') {
820
+ return defaultFunctionName;
821
+ }
822
+ return fn.name || defaultFunctionName;
823
+ }
824
+ catch (e) {
825
+ // Just accessing custom props in some Selenium environments
826
+ // can cause a "Permission denied" exception (see raven-js#495).
827
+ return defaultFunctionName;
828
+ }
829
+ }
830
+
1045
831
  /**
1046
832
  * Tells whether current environment supports Fetch API
1047
833
  * {@link supportsFetch}.
@@ -1102,9 +888,7 @@ var Sentry = (function (exports) {
1102
888
  doc.head.removeChild(sandbox);
1103
889
  }
1104
890
  catch (err) {
1105
- if (isDebugBuild()) {
1106
- logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', err);
1107
- }
891
+ logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', err);
1108
892
  }
1109
893
  }
1110
894
  return result;
@@ -1196,6 +980,7 @@ var Sentry = (function (exports) {
1196
980
  break;
1197
981
  default:
1198
982
  logger.warn('unknown instrumentation type:', type);
983
+ return;
1199
984
  }
1200
985
  }
1201
986
  /**
@@ -1218,9 +1003,7 @@ var Sentry = (function (exports) {
1218
1003
  handler(data);
1219
1004
  }
1220
1005
  catch (e) {
1221
- if (isDebugBuild()) {
1222
- logger.error(`Error while triggering instrumentation handler.\nType: ${type}\nName: ${getFunctionName(handler)}\nError:`, e);
1223
- }
1006
+ logger.error(`Error while triggering instrumentation handler.\nType: ${type}\nName: ${getFunctionName(handler)}\nError:`, e);
1224
1007
  }
1225
1008
  }
1226
1009
  }
@@ -1229,7 +1012,7 @@ var Sentry = (function (exports) {
1229
1012
  if (!('console' in global$5)) {
1230
1013
  return;
1231
1014
  }
1232
- ['debug', 'info', 'warn', 'error', 'log', 'assert'].forEach(function (level) {
1015
+ CONSOLE_LEVELS.forEach(function (level) {
1233
1016
  if (!(level in global$5.console)) {
1234
1017
  return;
1235
1018
  }
@@ -1627,6 +1410,48 @@ var Sentry = (function (exports) {
1627
1410
  };
1628
1411
  }
1629
1412
 
1413
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
1414
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1415
+ /**
1416
+ * Helper to decycle json objects
1417
+ */
1418
+ function memoBuilder() {
1419
+ const hasWeakSet = typeof WeakSet === 'function';
1420
+ const inner = hasWeakSet ? new WeakSet() : [];
1421
+ function memoize(obj) {
1422
+ if (hasWeakSet) {
1423
+ if (inner.has(obj)) {
1424
+ return true;
1425
+ }
1426
+ inner.add(obj);
1427
+ return false;
1428
+ }
1429
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
1430
+ for (let i = 0; i < inner.length; i++) {
1431
+ const value = inner[i];
1432
+ if (value === obj) {
1433
+ return true;
1434
+ }
1435
+ }
1436
+ inner.push(obj);
1437
+ return false;
1438
+ }
1439
+ function unmemoize(obj) {
1440
+ if (hasWeakSet) {
1441
+ inner.delete(obj);
1442
+ }
1443
+ else {
1444
+ for (let i = 0; i < inner.length; i++) {
1445
+ if (inner[i] === obj) {
1446
+ inner.splice(i, 1);
1447
+ break;
1448
+ }
1449
+ }
1450
+ }
1451
+ }
1452
+ return [memoize, unmemoize];
1453
+ }
1454
+
1630
1455
  /**
1631
1456
  * UUID4 generator
1632
1457
  *
@@ -1723,65 +1548,246 @@ var Sentry = (function (exports) {
1723
1548
  if (!firstException.value) {
1724
1549
  firstException.value = value || '';
1725
1550
  }
1726
- if (!firstException.type) {
1727
- firstException.type = type || 'Error';
1551
+ if (!firstException.type) {
1552
+ firstException.type = type || 'Error';
1553
+ }
1554
+ }
1555
+ /**
1556
+ * Adds exception mechanism data to a given event. Uses defaults if the second parameter is not passed.
1557
+ *
1558
+ * @param event The event to modify.
1559
+ * @param newMechanism Mechanism data to add to the event.
1560
+ * @hidden
1561
+ */
1562
+ function addExceptionMechanism(event, newMechanism) {
1563
+ const firstException = getFirstException(event);
1564
+ if (!firstException) {
1565
+ return;
1566
+ }
1567
+ const defaultMechanism = { type: 'generic', handled: true };
1568
+ const currentMechanism = firstException.mechanism;
1569
+ firstException.mechanism = Object.assign(Object.assign(Object.assign({}, defaultMechanism), currentMechanism), newMechanism);
1570
+ if (newMechanism && 'data' in newMechanism) {
1571
+ const mergedData = Object.assign(Object.assign({}, (currentMechanism && currentMechanism.data)), newMechanism.data);
1572
+ firstException.mechanism.data = mergedData;
1573
+ }
1574
+ }
1575
+ /**
1576
+ * Checks whether or not we've already captured the given exception (note: not an identical exception - the very object
1577
+ * in question), and marks it captured if not.
1578
+ *
1579
+ * This is useful because it's possible for an error to get captured by more than one mechanism. After we intercept and
1580
+ * record an error, we rethrow it (assuming we've intercepted it before it's reached the top-level global handlers), so
1581
+ * that we don't interfere with whatever effects the error might have had were the SDK not there. At that point, because
1582
+ * the error has been rethrown, it's possible for it to bubble up to some other code we've instrumented. If it's not
1583
+ * caught after that, it will bubble all the way up to the global handlers (which of course we also instrument). This
1584
+ * function helps us ensure that even if we encounter the same error more than once, we only record it the first time we
1585
+ * see it.
1586
+ *
1587
+ * Note: It will ignore primitives (always return `false` and not mark them as seen), as properties can't be set on
1588
+ * them. {@link: Object.objectify} can be used on exceptions to convert any that are primitives into their equivalent
1589
+ * object wrapper forms so that this check will always work. However, because we need to flag the exact object which
1590
+ * will get rethrown, and because that rethrowing happens outside of the event processing pipeline, the objectification
1591
+ * must be done before the exception captured.
1592
+ *
1593
+ * @param A thrown exception to check or flag as having been seen
1594
+ * @returns `true` if the exception has already been captured, `false` if not (with the side effect of marking it seen)
1595
+ */
1596
+ function checkOrSetAlreadyCaught(exception) {
1597
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1598
+ if (exception && exception.__sentry_captured__) {
1599
+ return true;
1600
+ }
1601
+ try {
1602
+ // set it this way rather than by assignment so that it's not ennumerable and therefore isn't recorded by the
1603
+ // `ExtraErrorData` integration
1604
+ addNonEnumerableProperty(exception, '__sentry_captured__', true);
1605
+ }
1606
+ catch (err) {
1607
+ // `exception` is a primitive, so we can't mark it seen
1608
+ }
1609
+ return false;
1610
+ }
1611
+
1612
+ /**
1613
+ * Recursively normalizes the given object.
1614
+ *
1615
+ * - Creates a copy to prevent original input mutation
1616
+ * - Skips non-enumerable properties
1617
+ * - When stringifying, calls `toJSON` if implemented
1618
+ * - Removes circular references
1619
+ * - Translates non-serializable values (`undefined`/`NaN`/functions) to serializable format
1620
+ * - Translates known global objects/classes to a string representations
1621
+ * - Takes care of `Error` object serialization
1622
+ * - Optionally limits depth of final output
1623
+ * - Optionally limits number of properties/elements included in any single object/array
1624
+ *
1625
+ * @param input The object to be normalized.
1626
+ * @param depth The max depth to which to normalize the object. (Anything deeper stringified whole.)
1627
+ * @param maxProperties The max number of elements or properties to be included in any single array or
1628
+ * object in the normallized output..
1629
+ * @returns A normalized version of the object, or `"**non-serializable**"` if any errors are thrown during normalization.
1630
+ */
1631
+ function normalize(input, depth = +Infinity, maxProperties = +Infinity) {
1632
+ try {
1633
+ // since we're at the outermost level, there is no key
1634
+ return walk('', input, depth, maxProperties);
1635
+ }
1636
+ catch (_oO) {
1637
+ return '**non-serializable**';
1638
+ }
1639
+ }
1640
+ /** JSDoc */
1641
+ function normalizeToSize(object,
1642
+ // Default Node.js REPL depth
1643
+ depth = 3,
1644
+ // 100kB, as 200kB is max payload size, so half sounds reasonable
1645
+ maxSize = 100 * 1024) {
1646
+ const serialized = normalize(object, depth);
1647
+ if (jsonSize(serialized) > maxSize) {
1648
+ return normalizeToSize(object, depth - 1, maxSize);
1649
+ }
1650
+ return serialized;
1651
+ }
1652
+ /**
1653
+ * Walks an object to perform a normalization on it
1654
+ *
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
1659
+ * @param memo Optional Memo class handling decycling
1660
+ */
1661
+ function walk(key, value, depth = +Infinity, maxProperties = +Infinity, memo = memoBuilder()) {
1662
+ const [memoize, unmemoize] = memo;
1663
+ // If we reach the maximum depth, serialize whatever is left
1664
+ 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
1684
+ if (memoize(value)) {
1685
+ return '[Circular ~]';
1686
+ }
1687
+ let propertyCount = 0;
1688
+ // Walk all keys of the source
1689
+ for (const innerKey in source) {
1690
+ // Avoid iterating over fields in the prototype if they've somehow been exposed to enumeration.
1691
+ if (!Object.prototype.hasOwnProperty.call(source, innerKey)) {
1692
+ continue;
1693
+ }
1694
+ if (propertyCount >= maxProperties) {
1695
+ acc[innerKey] = '[MaxProperties ~]';
1696
+ break;
1697
+ }
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);
1728
1702
  }
1703
+ // Once walked through all the branches, remove the parent from memo storage
1704
+ unmemoize(value);
1705
+ // Return accumulated values
1706
+ return acc;
1729
1707
  }
1730
1708
  /**
1731
- * Adds exception mechanism data to a given event. Uses defaults if the second parameter is not passed.
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.
1732
1711
  *
1733
- * @param event The event to modify.
1734
- * @param newMechanism Mechanism data to add to the event.
1735
- * @hidden
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.
1736
1716
  */
1737
- function addExceptionMechanism(event, newMechanism) {
1738
- const firstException = getFirstException(event);
1739
- if (!firstException) {
1740
- return;
1717
+ function serializeValue(value) {
1718
+ // Node.js REPL notation
1719
+ if (typeof value === 'string') {
1720
+ return value;
1741
1721
  }
1742
- const defaultMechanism = { type: 'generic', handled: true };
1743
- const currentMechanism = firstException.mechanism;
1744
- firstException.mechanism = Object.assign(Object.assign(Object.assign({}, defaultMechanism), currentMechanism), newMechanism);
1745
- if (newMechanism && 'data' in newMechanism) {
1746
- const mergedData = Object.assign(Object.assign({}, (currentMechanism && currentMechanism.data)), newMechanism.data);
1747
- firstException.mechanism.data = mergedData;
1722
+ const type = Object.prototype.toString.call(value);
1723
+ if (type === '[object Object]') {
1724
+ return '[Object]';
1748
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;
1749
1733
  }
1750
1734
  /**
1751
- * Checks whether or not we've already captured the given exception (note: not an identical exception - the very object
1752
- * in question), and marks it captured if not.
1753
- *
1754
- * This is useful because it's possible for an error to get captured by more than one mechanism. After we intercept and
1755
- * record an error, we rethrow it (assuming we've intercepted it before it's reached the top-level global handlers), so
1756
- * that we don't interfere with whatever effects the error might have had were the SDK not there. At that point, because
1757
- * the error has been rethrown, it's possible for it to bubble up to some other code we've instrumented. If it's not
1758
- * caught after that, it will bubble all the way up to the global handlers (which of course we also instrument). This
1759
- * function helps us ensure that even if we encounter the same error more than once, we only record it the first time we
1760
- * see it.
1735
+ * makeSerializable()
1761
1736
  *
1762
- * Note: It will ignore primitives (always return `false` and not mark them as seen), as properties can't be set on
1763
- * them. {@link: Object.objectify} can be used on exceptions to convert any that are primitives into their equivalent
1764
- * object wrapper forms so that this check will always work. However, because we need to flag the exact object which
1765
- * will get rethrown, and because that rethrowing happens outside of the event processing pipeline, the objectification
1766
- * must be done before the exception captured.
1737
+ * Takes unserializable input and make it serializer-friendly.
1767
1738
  *
1768
- * @param A thrown exception to check or flag as having been seen
1769
- * @returns `true` if the exception has already been captured, `false` if not (with the side effect of marking it seen)
1739
+ * Handles globals, functions, `undefined`, `NaN`, and other non-serializable values.
1770
1740
  */
1771
- function checkOrSetAlreadyCaught(exception) {
1772
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1773
- if (exception && exception.__sentry_captured__) {
1774
- return true;
1741
+ function makeSerializable(value, key) {
1742
+ if (key === 'domain' && value && typeof value === 'object' && value._events) {
1743
+ return '[Domain]';
1775
1744
  }
1776
- try {
1777
- // set it this way rather than by assignment so that it's not ennumerable and therefore isn't recorded by the
1778
- // `ExtraErrorData` integration
1779
- addNonEnumerableProperty(exception, '__sentry_captured__', true);
1745
+ if (key === 'domainEmitter') {
1746
+ return '[DomainEmitter]';
1780
1747
  }
1781
- catch (err) {
1782
- // `exception` is a primitive, so we can't mark it seen
1748
+ if (typeof global !== 'undefined' && value === global) {
1749
+ return '[Global]';
1783
1750
  }
1784
- return false;
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)}]`;
1777
+ }
1778
+ if (typeof value === 'bigint') {
1779
+ return `[BigInt: ${String(value)}]`;
1780
+ }
1781
+ return value;
1782
+ }
1783
+ /** Calculates bytes size of input string */
1784
+ function utf8Length(value) {
1785
+ // eslint-disable-next-line no-bitwise
1786
+ return ~-encodeURI(value).split(/%..|./).length;
1787
+ }
1788
+ /** Calculates bytes size of input object */
1789
+ function jsonSize(value) {
1790
+ return utf8Length(JSON.stringify(value));
1785
1791
  }
1786
1792
 
1787
1793
  /* eslint-disable @typescript-eslint/explicit-function-return-type */
@@ -2236,6 +2242,60 @@ var Sentry = (function (exports) {
2236
2242
  return headerDate - now;
2237
2243
  }
2238
2244
  return DEFAULT_RETRY_AFTER;
2245
+ }
2246
+ /**
2247
+ * Gets the time that given category is disabled until for rate limiting
2248
+ */
2249
+ function disabledUntil(limits, category) {
2250
+ return limits[category] || limits.all || 0;
2251
+ }
2252
+ /**
2253
+ * Checks if a category is rate limited
2254
+ */
2255
+ function isRateLimited(limits, category, now = Date.now()) {
2256
+ return disabledUntil(limits, category) > now;
2257
+ }
2258
+ /**
2259
+ * Update ratelimits from incoming headers.
2260
+ * Returns true if headers contains a non-empty rate limiting header.
2261
+ */
2262
+ function updateRateLimits(limits, headers, now = Date.now()) {
2263
+ const updatedRateLimits = Object.assign({}, limits);
2264
+ // "The name is case-insensitive."
2265
+ // https://developer.mozilla.org/en-US/docs/Web/API/Headers/get
2266
+ const rateLimitHeader = headers['x-sentry-rate-limits'];
2267
+ const retryAfterHeader = headers['retry-after'];
2268
+ if (rateLimitHeader) {
2269
+ /**
2270
+ * rate limit headers are of the form
2271
+ * <header>,<header>,..
2272
+ * where each <header> is of the form
2273
+ * <retry_after>: <categories>: <scope>: <reason_code>
2274
+ * where
2275
+ * <retry_after> is a delay in seconds
2276
+ * <categories> is the event type(s) (error, transaction, etc) being rate limited and is of the form
2277
+ * <category>;<category>;...
2278
+ * <scope> is what's being limited (org, project, or key) - ignored by SDK
2279
+ * <reason_code> is an arbitrary string like "org_quota" - ignored by SDK
2280
+ */
2281
+ for (const limit of rateLimitHeader.trim().split(',')) {
2282
+ const parameters = limit.split(':', 2);
2283
+ const headerDelay = parseInt(parameters[0], 10);
2284
+ const delay = (!isNaN(headerDelay) ? headerDelay : 60) * 1000; // 60sec default
2285
+ if (!parameters[1]) {
2286
+ updatedRateLimits.all = now + delay;
2287
+ }
2288
+ else {
2289
+ for (const category of parameters[1].split(';')) {
2290
+ updatedRateLimits[category] = now + delay;
2291
+ }
2292
+ }
2293
+ }
2294
+ }
2295
+ else if (retryAfterHeader) {
2296
+ updatedRateLimits.all = now + parseRetryAfterHeader(retryAfterHeader, now);
2297
+ }
2298
+ return updatedRateLimits;
2239
2299
  }
2240
2300
 
2241
2301
  /**
@@ -3269,13 +3329,7 @@ var Sentry = (function (exports) {
3269
3329
  */
3270
3330
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
3271
3331
  function captureException(exception, captureContext) {
3272
- let syntheticException;
3273
- try {
3274
- throw new Error('Sentry syntheticException');
3275
- }
3276
- catch (exception) {
3277
- syntheticException = exception;
3278
- }
3332
+ const syntheticException = new Error('Sentry syntheticException');
3279
3333
  return callOnHub('captureException', exception, {
3280
3334
  captureContext,
3281
3335
  originalException: exception,
@@ -3290,13 +3344,7 @@ var Sentry = (function (exports) {
3290
3344
  * @returns The generated eventId.
3291
3345
  */
3292
3346
  function captureMessage(message, captureContext) {
3293
- let syntheticException;
3294
- try {
3295
- throw new Error(message);
3296
- }
3297
- catch (exception) {
3298
- syntheticException = exception;
3299
- }
3347
+ const syntheticException = new Error(message);
3300
3348
  // This is necessary to provide explicit scopes upgrade, without changing the original
3301
3349
  // arity of the `captureMessage(message, level)` method.
3302
3350
  const level = typeof captureContext === 'string' ? captureContext : undefined;
@@ -3668,15 +3716,11 @@ var Sentry = (function (exports) {
3668
3716
  */
3669
3717
  captureSession(session) {
3670
3718
  if (!this._isEnabled()) {
3671
- if (isDebugBuild()) {
3672
- logger.warn('SDK not enabled, will not capture session.');
3673
- }
3719
+ logger.warn('SDK not enabled, will not capture session.');
3674
3720
  return;
3675
3721
  }
3676
3722
  if (!(typeof session.release === 'string')) {
3677
- if (isDebugBuild()) {
3678
- logger.warn('Discarded session because of missing or non-string release');
3679
- }
3723
+ logger.warn('Discarded session because of missing or non-string release');
3680
3724
  }
3681
3725
  else {
3682
3726
  this._sendSession(session);
@@ -3822,7 +3866,7 @@ var Sentry = (function (exports) {
3822
3866
  * @returns A new event with more information.
3823
3867
  */
3824
3868
  _prepareEvent(event, scope, hint) {
3825
- const { normalizeDepth = 3 } = this.getOptions();
3869
+ const { normalizeDepth = 3, normalizeMaxBreadth = 1000 } = this.getOptions();
3826
3870
  const prepared = Object.assign(Object.assign({}, event), { event_id: event.event_id || (hint && hint.event_id ? hint.event_id : uuid4()), timestamp: event.timestamp || dateTimestampInSeconds() });
3827
3871
  this._applyClientOptions(prepared);
3828
3872
  this._applyIntegrationsMetadata(prepared);
@@ -3847,7 +3891,7 @@ var Sentry = (function (exports) {
3847
3891
  evt.sdkProcessingMetadata = Object.assign(Object.assign({}, evt.sdkProcessingMetadata), { normalizeDepth: normalize(normalizeDepth) });
3848
3892
  }
3849
3893
  if (typeof normalizeDepth === 'number' && normalizeDepth > 0) {
3850
- return this._normalizeEvent(evt, normalizeDepth);
3894
+ return this._normalizeEvent(evt, normalizeDepth, normalizeMaxBreadth);
3851
3895
  }
3852
3896
  return evt;
3853
3897
  });
@@ -3862,20 +3906,20 @@ var Sentry = (function (exports) {
3862
3906
  * @param event Event
3863
3907
  * @returns Normalized event
3864
3908
  */
3865
- _normalizeEvent(event, depth) {
3909
+ _normalizeEvent(event, depth, maxBreadth) {
3866
3910
  if (!event) {
3867
3911
  return null;
3868
3912
  }
3869
3913
  const normalized = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, event), (event.breadcrumbs && {
3870
3914
  breadcrumbs: event.breadcrumbs.map(b => (Object.assign(Object.assign({}, b), (b.data && {
3871
- data: normalize(b.data, depth),
3915
+ data: normalize(b.data, depth, maxBreadth),
3872
3916
  })))),
3873
3917
  })), (event.user && {
3874
- user: normalize(event.user, depth),
3918
+ user: normalize(event.user, depth, maxBreadth),
3875
3919
  })), (event.contexts && {
3876
- contexts: normalize(event.contexts, depth),
3920
+ contexts: normalize(event.contexts, depth, maxBreadth),
3877
3921
  })), (event.extra && {
3878
- extra: normalize(event.extra, depth),
3922
+ extra: normalize(event.extra, depth, maxBreadth),
3879
3923
  }));
3880
3924
  // event.contexts.trace stores information about a Transaction. Similarly,
3881
3925
  // event.spans[] stores information about child Spans. Given that a
@@ -4059,91 +4103,6 @@ var Sentry = (function (exports) {
4059
4103
  return rv;
4060
4104
  }
4061
4105
 
4062
- /** Noop transport */
4063
- class NoopTransport {
4064
- /**
4065
- * @inheritDoc
4066
- */
4067
- sendEvent(_) {
4068
- return resolvedSyncPromise({
4069
- reason: 'NoopTransport: Event has been skipped because no Dsn is configured.',
4070
- status: 'skipped',
4071
- });
4072
- }
4073
- /**
4074
- * @inheritDoc
4075
- */
4076
- close(_) {
4077
- return resolvedSyncPromise(true);
4078
- }
4079
- }
4080
-
4081
- /**
4082
- * This is the base implemention of a Backend.
4083
- * @hidden
4084
- */
4085
- class BaseBackend {
4086
- /** Creates a new backend instance. */
4087
- constructor(options) {
4088
- this._options = options;
4089
- if (!this._options.dsn) {
4090
- logger.warn('No DSN provided, backend will not do anything.');
4091
- }
4092
- this._transport = this._setupTransport();
4093
- }
4094
- /**
4095
- * @inheritDoc
4096
- */
4097
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
4098
- eventFromException(_exception, _hint) {
4099
- throw new SentryError('Backend has to implement `eventFromException` method');
4100
- }
4101
- /**
4102
- * @inheritDoc
4103
- */
4104
- eventFromMessage(_message, _level, _hint) {
4105
- throw new SentryError('Backend has to implement `eventFromMessage` method');
4106
- }
4107
- /**
4108
- * @inheritDoc
4109
- */
4110
- sendEvent(event) {
4111
- void this._transport.sendEvent(event).then(null, reason => {
4112
- if (isDebugBuild()) {
4113
- logger.error('Error while sending event:', reason);
4114
- }
4115
- });
4116
- }
4117
- /**
4118
- * @inheritDoc
4119
- */
4120
- sendSession(session) {
4121
- if (!this._transport.sendSession) {
4122
- if (isDebugBuild()) {
4123
- logger.warn("Dropping session because custom transport doesn't implement sendSession");
4124
- }
4125
- return;
4126
- }
4127
- void this._transport.sendSession(session).then(null, reason => {
4128
- if (isDebugBuild()) {
4129
- logger.error('Error while sending session:', reason);
4130
- }
4131
- });
4132
- }
4133
- /**
4134
- * @inheritDoc
4135
- */
4136
- getTransport() {
4137
- return this._transport;
4138
- }
4139
- /**
4140
- * Sets up the transport so it can be used later to send requests.
4141
- */
4142
- _setupTransport() {
4143
- return new NoopTransport();
4144
- }
4145
- }
4146
-
4147
4106
  /** Extract sdk info from from the API metadata */
4148
4107
  function getSdkMetadataForEnvelopeHeader(api) {
4149
4108
  if (!api.metadata || !api.metadata.sdk) {
@@ -4167,8 +4126,8 @@ var Sentry = (function (exports) {
4167
4126
  event.sdk.packages = [...(event.sdk.packages || []), ...(sdkInfo.packages || [])];
4168
4127
  return event;
4169
4128
  }
4170
- /** Creates a SentryRequest from a Session. */
4171
- function sessionToSentryRequest(session, api) {
4129
+ /** Creates an envelope from a Session */
4130
+ function createSessionEnvelope(session, api) {
4172
4131
  const sdkInfo = getSdkMetadataForEnvelopeHeader(api);
4173
4132
  const envelopeHeaders = Object.assign(Object.assign({ sent_at: new Date().toISOString() }, (sdkInfo && { sdk: sdkInfo })), (!!api.tunnel && { dsn: dsnToString(api.dsn) }));
4174
4133
  // I know this is hacky but we don't want to add `sessions` to request type since it's never rate limited
@@ -4176,12 +4135,36 @@ var Sentry = (function (exports) {
4176
4135
  // TODO (v7) Have to cast type because envelope items do not accept a `SentryRequestType`
4177
4136
  const envelopeItem = [{ type }, session];
4178
4137
  const envelope = createEnvelope(envelopeHeaders, [envelopeItem]);
4138
+ return [envelope, type];
4139
+ }
4140
+ /** Creates a SentryRequest from a Session. */
4141
+ function sessionToSentryRequest(session, api) {
4142
+ const [envelope, type] = createSessionEnvelope(session, api);
4179
4143
  return {
4180
4144
  body: serializeEnvelope(envelope),
4181
4145
  type,
4182
4146
  url: getEnvelopeEndpointWithUrlEncodedAuth(api.dsn, api.tunnel),
4183
4147
  };
4184
4148
  }
4149
+ /**
4150
+ * Create an Envelope from an event. Note that this is duplicated from below,
4151
+ * but on purpose as this will be refactored in v7.
4152
+ */
4153
+ function createEventEnvelope(event, api) {
4154
+ const sdkInfo = getSdkMetadataForEnvelopeHeader(api);
4155
+ const eventType = event.type || 'event';
4156
+ const { transactionSampling } = event.sdkProcessingMetadata || {};
4157
+ const { method: samplingMethod, rate: sampleRate } = transactionSampling || {};
4158
+ 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
+ const eventItem = [
4160
+ {
4161
+ type: eventType,
4162
+ sample_rates: [{ id: samplingMethod, rate: sampleRate }],
4163
+ },
4164
+ event,
4165
+ ];
4166
+ return createEnvelope(envelopeHeaders, [eventItem]);
4167
+ }
4185
4168
  /** Creates a SentryRequest from an event. */
4186
4169
  function eventToSentryRequest(event, api) {
4187
4170
  const sdkInfo = getSdkMetadataForEnvelopeHeader(api);
@@ -4269,6 +4252,111 @@ var Sentry = (function (exports) {
4269
4252
  return req;
4270
4253
  }
4271
4254
 
4255
+ /** Noop transport */
4256
+ class NoopTransport {
4257
+ /**
4258
+ * @inheritDoc
4259
+ */
4260
+ sendEvent(_) {
4261
+ return resolvedSyncPromise({
4262
+ reason: 'NoopTransport: Event has been skipped because no Dsn is configured.',
4263
+ status: 'skipped',
4264
+ });
4265
+ }
4266
+ /**
4267
+ * @inheritDoc
4268
+ */
4269
+ close(_) {
4270
+ return resolvedSyncPromise(true);
4271
+ }
4272
+ }
4273
+
4274
+ /**
4275
+ * This is the base implemention of a Backend.
4276
+ * @hidden
4277
+ */
4278
+ class BaseBackend {
4279
+ /** Creates a new backend instance. */
4280
+ constructor(options) {
4281
+ this._options = options;
4282
+ if (!this._options.dsn) {
4283
+ logger.warn('No DSN provided, backend will not do anything.');
4284
+ }
4285
+ this._transport = this._setupTransport();
4286
+ }
4287
+ /**
4288
+ * @inheritDoc
4289
+ */
4290
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
4291
+ eventFromException(_exception, _hint) {
4292
+ throw new SentryError('Backend has to implement `eventFromException` method');
4293
+ }
4294
+ /**
4295
+ * @inheritDoc
4296
+ */
4297
+ eventFromMessage(_message, _level, _hint) {
4298
+ throw new SentryError('Backend has to implement `eventFromMessage` method');
4299
+ }
4300
+ /**
4301
+ * @inheritDoc
4302
+ */
4303
+ sendEvent(event) {
4304
+ // TODO(v7): Remove the if-else
4305
+ if (this._newTransport &&
4306
+ this._options.dsn &&
4307
+ this._options._experiments &&
4308
+ this._options._experiments.newTransport) {
4309
+ const api = initAPIDetails(this._options.dsn, this._options._metadata, this._options.tunnel);
4310
+ const env = createEventEnvelope(event, api);
4311
+ void this._newTransport.send(env).then(null, reason => {
4312
+ logger.error('Error while sending event:', reason);
4313
+ });
4314
+ }
4315
+ else {
4316
+ void this._transport.sendEvent(event).then(null, reason => {
4317
+ logger.error('Error while sending event:', reason);
4318
+ });
4319
+ }
4320
+ }
4321
+ /**
4322
+ * @inheritDoc
4323
+ */
4324
+ sendSession(session) {
4325
+ if (!this._transport.sendSession) {
4326
+ logger.warn("Dropping session because custom transport doesn't implement sendSession");
4327
+ return;
4328
+ }
4329
+ // TODO(v7): Remove the if-else
4330
+ if (this._newTransport &&
4331
+ this._options.dsn &&
4332
+ this._options._experiments &&
4333
+ this._options._experiments.newTransport) {
4334
+ const api = initAPIDetails(this._options.dsn, this._options._metadata, this._options.tunnel);
4335
+ const [env] = createSessionEnvelope(session, api);
4336
+ void this._newTransport.send(env).then(null, reason => {
4337
+ logger.error('Error while sending session:', reason);
4338
+ });
4339
+ }
4340
+ else {
4341
+ void this._transport.sendSession(session).then(null, reason => {
4342
+ logger.error('Error while sending session:', reason);
4343
+ });
4344
+ }
4345
+ }
4346
+ /**
4347
+ * @inheritDoc
4348
+ */
4349
+ getTransport() {
4350
+ return this._transport;
4351
+ }
4352
+ /**
4353
+ * Sets up the transport so it can be used later to send requests.
4354
+ */
4355
+ _setupTransport() {
4356
+ return new NoopTransport();
4357
+ }
4358
+ }
4359
+
4272
4360
  /**
4273
4361
  * Internal function to create a new SDK client instance. The client is
4274
4362
  * installed and then bound to the current scope.
@@ -4278,7 +4366,9 @@ var Sentry = (function (exports) {
4278
4366
  */
4279
4367
  function initAndBind(clientClass, options) {
4280
4368
  if (options.debug === true) {
4281
- logger.enable();
4369
+ {
4370
+ logger.enable();
4371
+ }
4282
4372
  }
4283
4373
  const hub = getCurrentHub();
4284
4374
  const scope = hub.getScope();
@@ -4289,7 +4379,7 @@ var Sentry = (function (exports) {
4289
4379
  hub.bindClient(client);
4290
4380
  }
4291
4381
 
4292
- const SDK_VERSION = '6.18.2';
4382
+ const SDK_VERSION = '6.19.2';
4293
4383
 
4294
4384
  let originalFunctionToString;
4295
4385
  /** Patch toString calls to return proper name for wrapped functions */
@@ -4333,184 +4423,151 @@ var Sentry = (function (exports) {
4333
4423
  /**
4334
4424
  * @inheritDoc
4335
4425
  */
4336
- setupOnce() {
4426
+ setupOnce(addGlobalEventProcessor, getCurrentHub) {
4337
4427
  addGlobalEventProcessor((event) => {
4338
4428
  const hub = getCurrentHub();
4339
- if (!hub) {
4340
- return event;
4341
- }
4342
- const self = hub.getIntegration(InboundFilters);
4343
- if (self) {
4344
- const client = hub.getClient();
4345
- const clientOptions = client ? client.getOptions() : {};
4346
- // This checks prevents most of the occurrences of the bug linked below:
4347
- // https://github.com/getsentry/sentry-javascript/issues/2622
4348
- // The bug is caused by multiple SDK instances, where one is minified and one is using non-mangled code.
4349
- // Unfortunatelly we cannot fix it reliably (thus reserved property in rollup's terser config),
4350
- // as we cannot force people using multiple instances in their apps to sync SDK versions.
4351
- const options = typeof self._mergeOptions === 'function' ? self._mergeOptions(clientOptions) : {};
4352
- if (typeof self._shouldDropEvent !== 'function') {
4353
- return event;
4429
+ if (hub) {
4430
+ const self = hub.getIntegration(InboundFilters);
4431
+ if (self) {
4432
+ const client = hub.getClient();
4433
+ const clientOptions = client ? client.getOptions() : {};
4434
+ const options = _mergeOptions(self._options, clientOptions);
4435
+ return _shouldDropEvent$1(event, options) ? null : event;
4354
4436
  }
4355
- return self._shouldDropEvent(event, options) ? null : event;
4356
4437
  }
4357
4438
  return event;
4358
4439
  });
4359
4440
  }
4360
- /** JSDoc */
4361
- _shouldDropEvent(event, options) {
4362
- if (this._isSentryError(event, options)) {
4363
- if (isDebugBuild()) {
4364
- logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
4365
- }
4366
- return true;
4367
- }
4368
- if (this._isIgnoredError(event, options)) {
4369
- if (isDebugBuild()) {
4370
- logger.warn(`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`);
4371
- }
4372
- return true;
4373
- }
4374
- if (this._isDeniedUrl(event, options)) {
4375
- if (isDebugBuild()) {
4376
- logger.warn(`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(event)}.\nUrl: ${this._getEventFilterUrl(event)}`);
4377
- }
4378
- return true;
4379
- }
4380
- if (!this._isAllowedUrl(event, options)) {
4381
- if (isDebugBuild()) {
4382
- logger.warn(`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(event)}.\nUrl: ${this._getEventFilterUrl(event)}`);
4383
- }
4384
- return true;
4385
- }
4441
+ }
4442
+ /**
4443
+ * @inheritDoc
4444
+ */
4445
+ InboundFilters.id = 'InboundFilters';
4446
+ /** JSDoc */
4447
+ function _mergeOptions(internalOptions = {}, clientOptions = {}) {
4448
+ return {
4449
+ allowUrls: [
4450
+ // eslint-disable-next-line deprecation/deprecation
4451
+ ...(internalOptions.whitelistUrls || []),
4452
+ ...(internalOptions.allowUrls || []),
4453
+ // eslint-disable-next-line deprecation/deprecation
4454
+ ...(clientOptions.whitelistUrls || []),
4455
+ ...(clientOptions.allowUrls || []),
4456
+ ],
4457
+ denyUrls: [
4458
+ // eslint-disable-next-line deprecation/deprecation
4459
+ ...(internalOptions.blacklistUrls || []),
4460
+ ...(internalOptions.denyUrls || []),
4461
+ // eslint-disable-next-line deprecation/deprecation
4462
+ ...(clientOptions.blacklistUrls || []),
4463
+ ...(clientOptions.denyUrls || []),
4464
+ ],
4465
+ ignoreErrors: [
4466
+ ...(internalOptions.ignoreErrors || []),
4467
+ ...(clientOptions.ignoreErrors || []),
4468
+ ...DEFAULT_IGNORE_ERRORS,
4469
+ ],
4470
+ ignoreInternal: internalOptions.ignoreInternal !== undefined ? internalOptions.ignoreInternal : true,
4471
+ };
4472
+ }
4473
+ /** JSDoc */
4474
+ function _shouldDropEvent$1(event, options) {
4475
+ if (options.ignoreInternal && _isSentryError(event)) {
4476
+ logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
4477
+ return true;
4478
+ }
4479
+ if (_isIgnoredError(event, options.ignoreErrors)) {
4480
+ logger.warn(`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`);
4481
+ return true;
4482
+ }
4483
+ if (_isDeniedUrl(event, options.denyUrls)) {
4484
+ logger.warn(`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(event)}.\nUrl: ${_getEventFilterUrl(event)}`);
4485
+ return true;
4486
+ }
4487
+ if (!_isAllowedUrl(event, options.allowUrls)) {
4488
+ logger.warn(`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(event)}.\nUrl: ${_getEventFilterUrl(event)}`);
4489
+ return true;
4490
+ }
4491
+ return false;
4492
+ }
4493
+ function _isIgnoredError(event, ignoreErrors) {
4494
+ if (!ignoreErrors || !ignoreErrors.length) {
4386
4495
  return false;
4387
4496
  }
4388
- /** JSDoc */
4389
- _isSentryError(event, options) {
4390
- if (!options.ignoreInternal) {
4391
- return false;
4392
- }
4393
- try {
4394
- // @ts-ignore can't be a sentry error if undefined
4395
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
4396
- return event.exception.values[0].type === 'SentryError';
4397
- }
4398
- catch (e) {
4399
- // ignore
4400
- }
4497
+ return _getPossibleEventMessages(event).some(message => ignoreErrors.some(pattern => isMatchingPattern(message, pattern)));
4498
+ }
4499
+ function _isDeniedUrl(event, denyUrls) {
4500
+ // TODO: Use Glob instead?
4501
+ if (!denyUrls || !denyUrls.length) {
4401
4502
  return false;
4402
4503
  }
4403
- /** JSDoc */
4404
- _isIgnoredError(event, options) {
4405
- if (!options.ignoreErrors || !options.ignoreErrors.length) {
4406
- return false;
4407
- }
4408
- return this._getPossibleEventMessages(event).some(message =>
4409
- // Not sure why TypeScript complains here...
4410
- options.ignoreErrors.some(pattern => isMatchingPattern(message, pattern)));
4504
+ const url = _getEventFilterUrl(event);
4505
+ return !url ? false : denyUrls.some(pattern => isMatchingPattern(url, pattern));
4506
+ }
4507
+ function _isAllowedUrl(event, allowUrls) {
4508
+ // TODO: Use Glob instead?
4509
+ if (!allowUrls || !allowUrls.length) {
4510
+ return true;
4411
4511
  }
4412
- /** JSDoc */
4413
- _isDeniedUrl(event, options) {
4414
- // TODO: Use Glob instead?
4415
- if (!options.denyUrls || !options.denyUrls.length) {
4416
- return false;
4417
- }
4418
- const url = this._getEventFilterUrl(event);
4419
- return !url ? false : options.denyUrls.some(pattern => isMatchingPattern(url, pattern));
4512
+ const url = _getEventFilterUrl(event);
4513
+ return !url ? true : allowUrls.some(pattern => isMatchingPattern(url, pattern));
4514
+ }
4515
+ function _getPossibleEventMessages(event) {
4516
+ if (event.message) {
4517
+ return [event.message];
4420
4518
  }
4421
- /** JSDoc */
4422
- _isAllowedUrl(event, options) {
4423
- // TODO: Use Glob instead?
4424
- if (!options.allowUrls || !options.allowUrls.length) {
4425
- return true;
4519
+ if (event.exception) {
4520
+ try {
4521
+ const { type = '', value = '' } = (event.exception.values && event.exception.values[0]) || {};
4522
+ return [`${value}`, `${type}: ${value}`];
4523
+ }
4524
+ catch (oO) {
4525
+ logger.error(`Cannot extract message for event ${getEventDescription(event)}`);
4526
+ return [];
4426
4527
  }
4427
- const url = this._getEventFilterUrl(event);
4428
- return !url ? true : options.allowUrls.some(pattern => isMatchingPattern(url, pattern));
4429
4528
  }
4430
- /** JSDoc */
4431
- _mergeOptions(clientOptions = {}) {
4432
- return {
4433
- allowUrls: [
4434
- // eslint-disable-next-line deprecation/deprecation
4435
- ...(this._options.whitelistUrls || []),
4436
- ...(this._options.allowUrls || []),
4437
- // eslint-disable-next-line deprecation/deprecation
4438
- ...(clientOptions.whitelistUrls || []),
4439
- ...(clientOptions.allowUrls || []),
4440
- ],
4441
- denyUrls: [
4442
- // eslint-disable-next-line deprecation/deprecation
4443
- ...(this._options.blacklistUrls || []),
4444
- ...(this._options.denyUrls || []),
4445
- // eslint-disable-next-line deprecation/deprecation
4446
- ...(clientOptions.blacklistUrls || []),
4447
- ...(clientOptions.denyUrls || []),
4448
- ],
4449
- ignoreErrors: [
4450
- ...(this._options.ignoreErrors || []),
4451
- ...(clientOptions.ignoreErrors || []),
4452
- ...DEFAULT_IGNORE_ERRORS,
4453
- ],
4454
- ignoreInternal: typeof this._options.ignoreInternal !== 'undefined' ? this._options.ignoreInternal : true,
4455
- };
4529
+ return [];
4530
+ }
4531
+ function _isSentryError(event) {
4532
+ try {
4533
+ // @ts-ignore can't be a sentry error if undefined
4534
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
4535
+ return event.exception.values[0].type === 'SentryError';
4456
4536
  }
4457
- /** JSDoc */
4458
- _getPossibleEventMessages(event) {
4459
- if (event.message) {
4460
- return [event.message];
4461
- }
4462
- if (event.exception) {
4463
- try {
4464
- const { type = '', value = '' } = (event.exception.values && event.exception.values[0]) || {};
4465
- return [`${value}`, `${type}: ${value}`];
4466
- }
4467
- catch (oO) {
4468
- if (isDebugBuild()) {
4469
- logger.error(`Cannot extract message for event ${getEventDescription(event)}`);
4470
- }
4471
- return [];
4472
- }
4473
- }
4474
- return [];
4537
+ catch (e) {
4538
+ // ignore
4475
4539
  }
4476
- /** JSDoc */
4477
- _getLastValidUrl(frames = []) {
4478
- for (let i = frames.length - 1; i >= 0; i--) {
4479
- const frame = frames[i];
4480
- if (frame && frame.filename !== '<anonymous>' && frame.filename !== '[native code]') {
4481
- return frame.filename || null;
4482
- }
4540
+ return false;
4541
+ }
4542
+ function _getLastValidUrl(frames = []) {
4543
+ for (let i = frames.length - 1; i >= 0; i--) {
4544
+ const frame = frames[i];
4545
+ if (frame && frame.filename !== '<anonymous>' && frame.filename !== '[native code]') {
4546
+ return frame.filename || null;
4483
4547
  }
4484
- return null;
4485
4548
  }
4486
- /** JSDoc */
4487
- _getEventFilterUrl(event) {
4549
+ return null;
4550
+ }
4551
+ function _getEventFilterUrl(event) {
4552
+ try {
4553
+ if (event.stacktrace) {
4554
+ return _getLastValidUrl(event.stacktrace.frames);
4555
+ }
4556
+ let frames;
4488
4557
  try {
4489
- if (event.stacktrace) {
4490
- return this._getLastValidUrl(event.stacktrace.frames);
4491
- }
4492
- let frames;
4493
- try {
4494
- // @ts-ignore we only care about frames if the whole thing here is defined
4495
- frames = event.exception.values[0].stacktrace.frames;
4496
- }
4497
- catch (e) {
4498
- // ignore
4499
- }
4500
- return frames ? this._getLastValidUrl(frames) : null;
4558
+ // @ts-ignore we only care about frames if the whole thing here is defined
4559
+ frames = event.exception.values[0].stacktrace.frames;
4501
4560
  }
4502
- catch (oO) {
4503
- if (isDebugBuild()) {
4504
- logger.error(`Cannot extract url for event ${getEventDescription(event)}`);
4505
- }
4506
- return null;
4561
+ catch (e) {
4562
+ // ignore
4507
4563
  }
4564
+ return frames ? _getLastValidUrl(frames) : null;
4508
4565
  }
4509
- }
4510
- /**
4511
- * @inheritDoc
4512
- */
4513
- InboundFilters.id = 'InboundFilters';
4566
+ catch (oO) {
4567
+ logger.error(`Cannot extract url for event ${getEventDescription(event)}`);
4568
+ return null;
4569
+ }
4570
+ }
4514
4571
 
4515
4572
  var CoreIntegrations = /*#__PURE__*/Object.freeze({
4516
4573
  __proto__: null,
@@ -4911,9 +4968,7 @@ var Sentry = (function (exports) {
4911
4968
  document.head.removeChild(sandbox);
4912
4969
  }
4913
4970
  catch (e) {
4914
- if (isDebugBuild()) {
4915
- logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', e);
4916
- }
4971
+ logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', e);
4917
4972
  }
4918
4973
  }
4919
4974
  return (cachedFetchImpl = fetchImpl.bind(global$4));
@@ -5042,13 +5097,11 @@ var Sentry = (function (exports) {
5042
5097
  */
5043
5098
  _handleResponse({ requestType, response, headers, resolve, reject, }) {
5044
5099
  const status = eventStatusFromHttpCode(response.status);
5045
- /**
5046
- * "The name is case-insensitive."
5047
- * https://developer.mozilla.org/en-US/docs/Web/API/Headers/get
5048
- */
5049
- const limited = this._handleRateLimit(headers);
5050
- if (limited && isDebugBuild()) {
5051
- logger.warn(`Too many ${requestType} requests, backing off until: ${this._disabledUntil(requestType)}`);
5100
+ this._rateLimits = updateRateLimits(this._rateLimits, headers);
5101
+ // eslint-disable-next-line deprecation/deprecation
5102
+ if (this._isRateLimited(requestType) && isDebugBuild()) {
5103
+ // eslint-disable-next-line deprecation/deprecation
5104
+ logger.warn(`Too many ${requestType} requests, backing off until: ${this._disabledUntil(requestType)}`);
5052
5105
  }
5053
5106
  if (status === 'success') {
5054
5107
  resolve({ status });
@@ -5058,50 +5111,21 @@ var Sentry = (function (exports) {
5058
5111
  }
5059
5112
  /**
5060
5113
  * Gets the time that given category is disabled until for rate limiting
5114
+ *
5115
+ * @deprecated Please use `disabledUntil` from @sentry/utils
5061
5116
  */
5062
5117
  _disabledUntil(requestType) {
5063
5118
  const category = requestTypeToCategory(requestType);
5064
- return this._rateLimits[category] || this._rateLimits.all;
5119
+ return new Date(disabledUntil(this._rateLimits, category));
5065
5120
  }
5066
5121
  /**
5067
5122
  * Checks if a category is rate limited
5123
+ *
5124
+ * @deprecated Please use `isRateLimited` from @sentry/utils
5068
5125
  */
5069
5126
  _isRateLimited(requestType) {
5070
- return this._disabledUntil(requestType) > new Date(Date.now());
5071
- }
5072
- /**
5073
- * Sets internal _rateLimits from incoming headers. Returns true if headers contains a non-empty rate limiting header.
5074
- */
5075
- _handleRateLimit(headers) {
5076
- const now = Date.now();
5077
- const rlHeader = headers['x-sentry-rate-limits'];
5078
- const raHeader = headers['retry-after'];
5079
- if (rlHeader) {
5080
- // rate limit headers are of the form
5081
- // <header>,<header>,..
5082
- // where each <header> is of the form
5083
- // <retry_after>: <categories>: <scope>: <reason_code>
5084
- // where
5085
- // <retry_after> is a delay in ms
5086
- // <categories> is the event type(s) (error, transaction, etc) being rate limited and is of the form
5087
- // <category>;<category>;...
5088
- // <scope> is what's being limited (org, project, or key) - ignored by SDK
5089
- // <reason_code> is an arbitrary string like "org_quota" - ignored by SDK
5090
- for (const limit of rlHeader.trim().split(',')) {
5091
- const parameters = limit.split(':', 2);
5092
- const headerDelay = parseInt(parameters[0], 10);
5093
- const delay = (!isNaN(headerDelay) ? headerDelay : 60) * 1000; // 60sec default
5094
- for (const category of parameters[1].split(';')) {
5095
- this._rateLimits[category || 'all'] = new Date(now + delay);
5096
- }
5097
- }
5098
- return true;
5099
- }
5100
- else if (raHeader) {
5101
- this._rateLimits.all = new Date(now + parseRetryAfterHeader(raHeader, now));
5102
- return true;
5103
- }
5104
- return false;
5127
+ const category = requestTypeToCategory(requestType);
5128
+ return isRateLimited(this._rateLimits, category);
5105
5129
  }
5106
5130
  }
5107
5131
 
@@ -5116,11 +5140,13 @@ var Sentry = (function (exports) {
5116
5140
  * @param originalPayload Original payload used to create SentryRequest
5117
5141
  */
5118
5142
  _sendRequest(sentryRequest, originalPayload) {
5143
+ // eslint-disable-next-line deprecation/deprecation
5119
5144
  if (this._isRateLimited(sentryRequest.type)) {
5120
5145
  this.recordLostEvent('ratelimit_backoff', sentryRequest.type);
5121
5146
  return Promise.reject({
5122
5147
  event: originalPayload,
5123
5148
  type: sentryRequest.type,
5149
+ // eslint-disable-next-line deprecation/deprecation
5124
5150
  reason: `Transport for ${sentryRequest.type} requests locked till ${this._disabledUntil(sentryRequest.type)} due to too many requests.`,
5125
5151
  status: 429,
5126
5152
  });
@@ -5178,11 +5204,13 @@ var Sentry = (function (exports) {
5178
5204
  * @param originalPayload Original payload used to create SentryRequest
5179
5205
  */
5180
5206
  _sendRequest(sentryRequest, originalPayload) {
5207
+ // eslint-disable-next-line deprecation/deprecation
5181
5208
  if (this._isRateLimited(sentryRequest.type)) {
5182
5209
  this.recordLostEvent('ratelimit_backoff', sentryRequest.type);
5183
5210
  return Promise.reject({
5184
5211
  event: originalPayload,
5185
5212
  type: sentryRequest.type,
5213
+ // eslint-disable-next-line deprecation/deprecation
5186
5214
  reason: `Transport for ${sentryRequest.type} requests locked till ${this._disabledUntil(sentryRequest.type)} due to too many requests.`,
5187
5215
  status: 429,
5188
5216
  });
@@ -5388,15 +5416,11 @@ var Sentry = (function (exports) {
5388
5416
  return;
5389
5417
  }
5390
5418
  if (!options.eventId) {
5391
- if (isDebugBuild()) {
5392
- logger.error('Missing eventId option in showReportDialog call');
5393
- }
5419
+ logger.error('Missing eventId option in showReportDialog call');
5394
5420
  return;
5395
5421
  }
5396
5422
  if (!options.dsn) {
5397
- if (isDebugBuild()) {
5398
- logger.error('Missing dsn option in showReportDialog call');
5399
- }
5423
+ logger.error('Missing dsn option in showReportDialog call');
5400
5424
  return;
5401
5425
  }
5402
5426
  const script = global$2.document.createElement('script');
@@ -5588,9 +5612,7 @@ var Sentry = (function (exports) {
5588
5612
  return event;
5589
5613
  }
5590
5614
  function globalHandlerLog(type) {
5591
- if (isDebugBuild()) {
5592
- logger.log(`Global Handler attached: ${type}`);
5593
- }
5615
+ logger.log(`Global Handler attached: ${type}`);
5594
5616
  }
5595
5617
  function addMechanismAndCapture(hub, error, event, type) {
5596
5618
  addExceptionMechanism(event, {
@@ -5701,16 +5723,18 @@ var Sentry = (function (exports) {
5701
5723
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5702
5724
  return function (callback) {
5703
5725
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
5704
- return original.call(this, wrap$1(callback, {
5705
- mechanism: {
5706
- data: {
5707
- function: 'requestAnimationFrame',
5708
- handler: getFunctionName(original),
5726
+ return original.apply(this, [
5727
+ wrap$1(callback, {
5728
+ mechanism: {
5729
+ data: {
5730
+ function: 'requestAnimationFrame',
5731
+ handler: getFunctionName(original),
5732
+ },
5733
+ handled: true,
5734
+ type: 'instrument',
5709
5735
  },
5710
- handled: true,
5711
- type: 'instrument',
5712
- },
5713
- }));
5736
+ }),
5737
+ ]);
5714
5738
  };
5715
5739
  }
5716
5740
  /** JSDoc */
@@ -5777,19 +5801,22 @@ var Sentry = (function (exports) {
5777
5801
  catch (err) {
5778
5802
  // can sometimes get 'Permission denied to access property "handle Event'
5779
5803
  }
5780
- return original.call(this, eventName,
5781
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
5782
- wrap$1(fn, {
5783
- mechanism: {
5784
- data: {
5785
- function: 'addEventListener',
5786
- handler: getFunctionName(fn),
5787
- target,
5804
+ return original.apply(this, [
5805
+ eventName,
5806
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5807
+ wrap$1(fn, {
5808
+ mechanism: {
5809
+ data: {
5810
+ function: 'addEventListener',
5811
+ handler: getFunctionName(fn),
5812
+ target,
5813
+ },
5814
+ handled: true,
5815
+ type: 'instrument',
5788
5816
  },
5789
- handled: true,
5790
- type: 'instrument',
5791
- },
5792
- }), options);
5817
+ }),
5818
+ options,
5819
+ ]);
5793
5820
  };
5794
5821
  });
5795
5822
  fill(proto, 'removeEventListener', function (originalRemoveEventListener) {
@@ -6512,9 +6539,7 @@ var Sentry = (function (exports) {
6512
6539
  if (client) {
6513
6540
  return client.flush(timeout);
6514
6541
  }
6515
- if (isDebugBuild()) {
6516
- logger.warn('Cannot flush events. No client defined.');
6517
- }
6542
+ logger.warn('Cannot flush events. No client defined.');
6518
6543
  return resolvedSyncPromise(false);
6519
6544
  }
6520
6545
  /**
@@ -6530,9 +6555,7 @@ var Sentry = (function (exports) {
6530
6555
  if (client) {
6531
6556
  return client.close(timeout);
6532
6557
  }
6533
- if (isDebugBuild()) {
6534
- logger.warn('Cannot flush events and disable SDK. No client defined.');
6535
- }
6558
+ logger.warn('Cannot flush events and disable SDK. No client defined.');
6536
6559
  return resolvedSyncPromise(false);
6537
6560
  }
6538
6561
  /**
@@ -6557,9 +6580,7 @@ var Sentry = (function (exports) {
6557
6580
  const window = getGlobalObject();
6558
6581
  const document = window.document;
6559
6582
  if (typeof document === 'undefined') {
6560
- if (isDebugBuild()) {
6561
- logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');
6562
- }
6583
+ logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');
6563
6584
  return;
6564
6585
  }
6565
6586
  const hub = getCurrentHub();