@sentry/browser 6.19.2 → 6.19.3

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 (52) hide show
  1. package/bundles/bundle.debug.min.js +2 -2
  2. package/bundles/bundle.debug.min.js.map +1 -1
  3. package/bundles/bundle.es6.debug.min.js +2 -2
  4. package/bundles/bundle.es6.debug.min.js.map +1 -1
  5. package/bundles/bundle.es6.js +311 -163
  6. package/bundles/bundle.es6.js.map +1 -1
  7. package/bundles/bundle.es6.min.js +2 -2
  8. package/bundles/bundle.es6.min.js.map +1 -1
  9. package/bundles/bundle.js +316 -163
  10. package/bundles/bundle.js.map +1 -1
  11. package/bundles/bundle.min.js +2 -2
  12. package/bundles/bundle.min.js.map +1 -1
  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/eventbuilder.js.map +1 -1
  17. package/dist/transports/index.d.ts +2 -0
  18. package/dist/transports/index.d.ts.map +1 -1
  19. package/dist/transports/index.js +4 -0
  20. package/dist/transports/index.js.map +1 -1
  21. package/dist/transports/new-fetch.d.ts +10 -0
  22. package/dist/transports/new-fetch.d.ts.map +1 -0
  23. package/dist/transports/new-fetch.js +27 -0
  24. package/dist/transports/new-fetch.js.map +1 -0
  25. package/dist/transports/new-xhr.d.ts +11 -0
  26. package/dist/transports/new-xhr.d.ts.map +1 -0
  27. package/dist/transports/new-xhr.js +46 -0
  28. package/dist/transports/new-xhr.js.map +1 -0
  29. package/esm/backend.d.ts.map +1 -1
  30. package/esm/backend.js +10 -2
  31. package/esm/backend.js.map +1 -1
  32. package/esm/eventbuilder.js.map +1 -1
  33. package/esm/transports/index.d.ts +2 -0
  34. package/esm/transports/index.d.ts.map +1 -1
  35. package/esm/transports/index.js +2 -0
  36. package/esm/transports/index.js.map +1 -1
  37. package/esm/transports/new-fetch.d.ts +10 -0
  38. package/esm/transports/new-fetch.d.ts.map +1 -0
  39. package/esm/transports/new-fetch.js +25 -0
  40. package/esm/transports/new-fetch.js.map +1 -0
  41. package/esm/transports/new-xhr.d.ts +11 -0
  42. package/esm/transports/new-xhr.d.ts.map +1 -0
  43. package/esm/transports/new-xhr.js +44 -0
  44. package/esm/transports/new-xhr.js.map +1 -0
  45. package/package.json +4 -4
  46. package/types/backend.d.ts.map +1 -1
  47. package/types/transports/index.d.ts +2 -0
  48. package/types/transports/index.d.ts.map +1 -1
  49. package/types/transports/new-fetch.d.ts +10 -0
  50. package/types/transports/new-fetch.d.ts.map +1 -0
  51. package/types/transports/new-xhr.d.ts +11 -0
  52. package/types/transports/new-xhr.d.ts.map +1 -0
@@ -1,4 +1,4 @@
1
- /*! @sentry/browser 6.19.2 (f49c509) | https://github.com/getsentry/sentry-javascript */
1
+ /*! @sentry/browser 6.19.3 (fe6f7b3) | https://github.com/getsentry/sentry-javascript */
2
2
  var Sentry = (function (exports) {
3
3
 
4
4
  /**
@@ -201,6 +201,16 @@ var Sentry = (function (exports) {
201
201
  function isSyntheticEvent(wat) {
202
202
  return isPlainObject(wat) && 'nativeEvent' in wat && 'preventDefault' in wat && 'stopPropagation' in wat;
203
203
  }
204
+ /**
205
+ * Checks whether given value is NaN
206
+ * {@link isNaN}.
207
+ *
208
+ * @param wat A value to be checked.
209
+ * @returns A boolean representing the result.
210
+ */
211
+ function isNaN$1(wat) {
212
+ return typeof wat === 'number' && wat !== wat;
213
+ }
204
214
  /**
205
215
  * Checks whether given value's type is an instance of provided constructor.
206
216
  * {@link isInstanceOf}.
@@ -664,55 +674,38 @@ var Sentry = (function (exports) {
664
674
  *
665
675
  * @param value Initial source that we have to transform in order for it to be usable by the serializer
666
676
  */
667
- function getWalkSource(value) {
677
+ function convertToPlainObject(value) {
678
+ let newObj = value;
668
679
  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;
680
+ newObj = Object.assign({ message: value.message, name: value.name, stack: value.stack }, getOwnProperties(value));
681
681
  }
682
- if (isEvent(value)) {
682
+ else if (isEvent(value)) {
683
683
  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
- }
684
+ newObj = Object.assign({ type: event.type, target: serializeEventTarget(event.target), currentTarget: serializeEventTarget(event.currentTarget) }, getOwnProperties(event));
705
685
  if (typeof CustomEvent !== 'undefined' && isInstanceOf(value, CustomEvent)) {
706
- source.detail = event.detail;
686
+ newObj.detail = event.detail;
707
687
  }
708
- for (const attr in event) {
709
- if (Object.prototype.hasOwnProperty.call(event, attr)) {
710
- source[attr] = event[attr];
711
- }
688
+ }
689
+ return newObj;
690
+ }
691
+ /** Creates a string representation of the target of an `Event` object */
692
+ function serializeEventTarget(target) {
693
+ try {
694
+ return isElement(target) ? htmlTreeAsString(target) : Object.prototype.toString.call(target);
695
+ }
696
+ catch (_oO) {
697
+ return '<unknown>';
698
+ }
699
+ }
700
+ /** Filters out all but an object's own properties */
701
+ function getOwnProperties(obj) {
702
+ const extractedProps = {};
703
+ for (const property in obj) {
704
+ if (Object.prototype.hasOwnProperty.call(obj, property)) {
705
+ extractedProps[property] = obj[property];
712
706
  }
713
- return source;
714
707
  }
715
- return value;
708
+ return extractedProps;
716
709
  }
717
710
  /**
718
711
  * Given any captured exception, extract its keys and create a sorted
@@ -721,7 +714,7 @@ var Sentry = (function (exports) {
721
714
  */
722
715
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
723
716
  function extractExceptionKeysForMessage(exception, maxLength = 40) {
724
- const keys = Object.keys(getWalkSource(exception));
717
+ const keys = Object.keys(convertToPlainObject(exception));
725
718
  keys.sort();
726
719
  if (!keys.length) {
727
720
  return '[object has no keys]';
@@ -747,11 +740,10 @@ var Sentry = (function (exports) {
747
740
  */
748
741
  function dropUndefinedKeys(val) {
749
742
  if (isPlainObject(val)) {
750
- const obj = val;
751
743
  const rv = {};
752
- for (const key of Object.keys(obj)) {
753
- if (typeof obj[key] !== 'undefined') {
754
- rv[key] = dropUndefinedKeys(obj[key]);
744
+ for (const key of Object.keys(val)) {
745
+ if (typeof val[key] !== 'undefined') {
746
+ rv[key] = dropUndefinedKeys(val[key]);
755
747
  }
756
748
  }
757
749
  return rv;
@@ -1631,10 +1623,10 @@ var Sentry = (function (exports) {
1631
1623
  function normalize(input, depth = +Infinity, maxProperties = +Infinity) {
1632
1624
  try {
1633
1625
  // since we're at the outermost level, there is no key
1634
- return walk('', input, depth, maxProperties);
1626
+ return visit('', input, depth, maxProperties);
1635
1627
  }
1636
- catch (_oO) {
1637
- return '**non-serializable**';
1628
+ catch (err) {
1629
+ return { ERROR: `**non-serializable** (${err})` };
1638
1630
  }
1639
1631
  }
1640
1632
  /** JSDoc */
@@ -1643,142 +1635,142 @@ var Sentry = (function (exports) {
1643
1635
  depth = 3,
1644
1636
  // 100kB, as 200kB is max payload size, so half sounds reasonable
1645
1637
  maxSize = 100 * 1024) {
1646
- const serialized = normalize(object, depth);
1647
- if (jsonSize(serialized) > maxSize) {
1638
+ const normalized = normalize(object, depth);
1639
+ if (jsonSize(normalized) > maxSize) {
1648
1640
  return normalizeToSize(object, depth - 1, maxSize);
1649
1641
  }
1650
- return serialized;
1642
+ return normalized;
1651
1643
  }
1652
1644
  /**
1653
- * Walks an object to perform a normalization on it
1645
+ * Visits a node to perform normalization on it
1654
1646
  *
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
1647
+ * @param key The key corresponding to the given node
1648
+ * @param value The node to be visited
1649
+ * @param depth Optional number indicating the maximum recursion depth
1650
+ * @param maxProperties Optional maximum number of properties/elements included in any single object/array
1659
1651
  * @param memo Optional Memo class handling decycling
1660
1652
  */
1661
- function walk(key, value, depth = +Infinity, maxProperties = +Infinity, memo = memoBuilder()) {
1653
+ function visit(key, value, depth = +Infinity, maxProperties = +Infinity, memo = memoBuilder()) {
1662
1654
  const [memoize, unmemoize] = memo;
1663
- // If we reach the maximum depth, serialize whatever is left
1655
+ // If the value has a `toJSON` method, see if we can bail and let it do the work
1656
+ const valueWithToJSON = value;
1657
+ if (valueWithToJSON && typeof valueWithToJSON.toJSON === 'function') {
1658
+ try {
1659
+ return valueWithToJSON.toJSON();
1660
+ }
1661
+ catch (err) {
1662
+ // pass (The built-in `toJSON` failed, but we can still try to do it ourselves)
1663
+ }
1664
+ }
1665
+ // Get the simple cases out of the way first
1666
+ if (value === null || (['number', 'boolean', 'string'].includes(typeof value) && !isNaN$1(value))) {
1667
+ return value;
1668
+ }
1669
+ const stringified = stringifyValue(key, value);
1670
+ // Anything we could potentially dig into more (objects or arrays) will have come back as `"[object XXXX]"`.
1671
+ // Everything else will have already been serialized, so if we don't see that pattern, we're done.
1672
+ if (!stringified.startsWith('[object ')) {
1673
+ return stringified;
1674
+ }
1675
+ // We're also done if we've reached the max depth
1664
1676
  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
1677
+ // At this point we know `serialized` is a string of the form `"[object XXXX]"`. Clean it up so it's just `"[XXXX]"`.
1678
+ return stringified.replace('object ', '');
1679
+ }
1680
+ // If we've already visited this branch, bail out, as it's circular reference. If not, note that we're seeing it now.
1684
1681
  if (memoize(value)) {
1685
1682
  return '[Circular ~]';
1686
1683
  }
1687
- let propertyCount = 0;
1688
- // Walk all keys of the source
1689
- for (const innerKey in source) {
1684
+ // 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
1685
+ // because we haven't yet reached the max depth. Create an accumulator to hold the results of visiting each
1686
+ // property/entry, and keep track of the number of items we add to it.
1687
+ const normalized = (Array.isArray(value) ? [] : {});
1688
+ let numAdded = 0;
1689
+ // Before we begin, convert`Error` and`Event` instances into plain objects, since some of each of their relevant
1690
+ // properties are non-enumerable and otherwise would get missed.
1691
+ const visitable = (isError(value) || isEvent(value) ? convertToPlainObject(value) : value);
1692
+ for (const visitKey in visitable) {
1690
1693
  // Avoid iterating over fields in the prototype if they've somehow been exposed to enumeration.
1691
- if (!Object.prototype.hasOwnProperty.call(source, innerKey)) {
1694
+ if (!Object.prototype.hasOwnProperty.call(visitable, visitKey)) {
1692
1695
  continue;
1693
1696
  }
1694
- if (propertyCount >= maxProperties) {
1695
- acc[innerKey] = '[MaxProperties ~]';
1697
+ if (numAdded >= maxProperties) {
1698
+ normalized[visitKey] = '[MaxProperties ~]';
1696
1699
  break;
1697
1700
  }
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);
1701
+ // Recursively visit all the child nodes
1702
+ const visitValue = visitable[visitKey];
1703
+ normalized[visitKey] = visit(visitKey, visitValue, depth - 1, maxProperties, memo);
1704
+ numAdded += 1;
1702
1705
  }
1703
- // Once walked through all the branches, remove the parent from memo storage
1706
+ // Once we've visited all the branches, remove the parent from memo storage
1704
1707
  unmemoize(value);
1705
1708
  // Return accumulated values
1706
- return acc;
1709
+ return normalized;
1707
1710
  }
1708
1711
  /**
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.
1712
+ * Stringify the given value. Handles various known special values and types.
1711
1713
  *
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;
1733
- }
1734
- /**
1735
- * makeSerializable()
1736
- *
1737
- * Takes unserializable input and make it serializer-friendly.
1714
+ * Not meant to be used on simple primitives which already have a string representation, as it will, for example, turn
1715
+ * the number 1231 into "[Object Number]", nor on `null`, as it will throw.
1738
1716
  *
1739
- * Handles globals, functions, `undefined`, `NaN`, and other non-serializable values.
1717
+ * @param value The value to stringify
1718
+ * @returns A stringified representation of the given value
1740
1719
  */
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)}]`;
1720
+ function stringifyValue(key,
1721
+ // this type is a tiny bit of a cheat, since this function does handle NaN (which is technically a number), but for
1722
+ // our internal use, it'll do
1723
+ value) {
1724
+ try {
1725
+ if (key === 'domain' && value && typeof value === 'object' && value._events) {
1726
+ return '[Domain]';
1727
+ }
1728
+ if (key === 'domainEmitter') {
1729
+ return '[DomainEmitter]';
1730
+ }
1731
+ // It's safe to use `global`, `window`, and `document` here in this manner, as we are asserting using `typeof` first
1732
+ // which won't throw if they are not present.
1733
+ if (typeof global !== 'undefined' && value === global) {
1734
+ return '[Global]';
1735
+ }
1736
+ // eslint-disable-next-line no-restricted-globals
1737
+ if (typeof window !== 'undefined' && value === window) {
1738
+ return '[Window]';
1739
+ }
1740
+ // eslint-disable-next-line no-restricted-globals
1741
+ if (typeof document !== 'undefined' && value === document) {
1742
+ return '[Document]';
1743
+ }
1744
+ // React's SyntheticEvent thingy
1745
+ if (isSyntheticEvent(value)) {
1746
+ return '[SyntheticEvent]';
1747
+ }
1748
+ if (typeof value === 'number' && value !== value) {
1749
+ return '[NaN]';
1750
+ }
1751
+ // this catches `undefined` (but not `null`, which is a primitive and can be serialized on its own)
1752
+ if (value === void 0) {
1753
+ return '[undefined]';
1754
+ }
1755
+ if (typeof value === 'function') {
1756
+ return `[Function: ${getFunctionName(value)}]`;
1757
+ }
1758
+ if (typeof value === 'symbol') {
1759
+ return `[${String(value)}]`;
1760
+ }
1761
+ // stringified BigInts are indistinguishable from regular numbers, so we need to label them to avoid confusion
1762
+ if (typeof value === 'bigint') {
1763
+ return `[BigInt: ${String(value)}]`;
1764
+ }
1765
+ // Now that we've knocked out all the special cases and the primitives, all we have left are objects. Simply casting
1766
+ // them to strings means that instances of classes which haven't defined their `toStringTag` will just come out as
1767
+ // `"[object Object]"`. If we instead look at the constructor's name (which is the same as the name of the class),
1768
+ // we can make sure that only plain objects come out that way.
1769
+ return `[object ${Object.getPrototypeOf(value).constructor.name}]`;
1777
1770
  }
1778
- if (typeof value === 'bigint') {
1779
- return `[BigInt: ${String(value)}]`;
1771
+ catch (err) {
1772
+ return `**non-serializable** (${err})`;
1780
1773
  }
1781
- return value;
1782
1774
  }
1783
1775
  /** Calculates bytes size of input string */
1784
1776
  function utf8Length(value) {
@@ -2190,6 +2182,13 @@ var Sentry = (function (exports) {
2190
2182
  function createEnvelope(headers, items = []) {
2191
2183
  return [headers, items];
2192
2184
  }
2185
+ /**
2186
+ * Get the type of the envelope. Grabs the type from the first envelope item.
2187
+ */
2188
+ function getEnvelopeType(envelope) {
2189
+ const [, [[firstItemHeader]]] = envelope;
2190
+ return firstItemHeader.type;
2191
+ }
2193
2192
  /**
2194
2193
  * Serializes an envelope into a string.
2195
2194
  */
@@ -3932,7 +3931,7 @@ var Sentry = (function (exports) {
3932
3931
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
3933
3932
  normalized.contexts.trace = event.contexts.trace;
3934
3933
  }
3935
- event.sdkProcessingMetadata = Object.assign(Object.assign({}, event.sdkProcessingMetadata), { baseClientNormalized: true });
3934
+ normalized.sdkProcessingMetadata = Object.assign(Object.assign({}, normalized.sdkProcessingMetadata), { baseClientNormalized: true });
3936
3935
  return normalized;
3937
3936
  }
3938
3937
  /**
@@ -4155,6 +4154,32 @@ var Sentry = (function (exports) {
4155
4154
  const eventType = event.type || 'event';
4156
4155
  const { transactionSampling } = event.sdkProcessingMetadata || {};
4157
4156
  const { method: samplingMethod, rate: sampleRate } = transactionSampling || {};
4157
+ // TODO: Below is a temporary hack in order to debug a serialization error - see
4158
+ // https://github.com/getsentry/sentry-javascript/issues/2809,
4159
+ // https://github.com/getsentry/sentry-javascript/pull/4425, and
4160
+ // https://github.com/getsentry/sentry-javascript/pull/4574.
4161
+ //
4162
+ // TL; DR: even though we normalize all events (which should prevent this), something is causing `JSON.stringify` to
4163
+ // throw a circular reference error.
4164
+ //
4165
+ // When it's time to remove it:
4166
+ // 1. Delete everything between here and where the request object `req` is created, EXCEPT the line deleting
4167
+ // `sdkProcessingMetadata`
4168
+ // 2. Restore the original version of the request body, which is commented out
4169
+ // 3. Search for either of the PR URLs above and pull out the companion hacks in the browser playwright tests and the
4170
+ // baseClient tests in this package
4171
+ enhanceEventWithSdkInfo(event, api.metadata.sdk);
4172
+ event.tags = event.tags || {};
4173
+ event.extra = event.extra || {};
4174
+ // In theory, all events should be marked as having gone through normalization and so
4175
+ // we should never set this tag/extra data
4176
+ if (!(event.sdkProcessingMetadata && event.sdkProcessingMetadata.baseClientNormalized)) {
4177
+ event.tags.skippedNormalization = true;
4178
+ event.extra.normalizeDepth = event.sdkProcessingMetadata ? event.sdkProcessingMetadata.normalizeDepth : 'unset';
4179
+ }
4180
+ // prevent this data from being sent to sentry
4181
+ // TODO: This is NOT part of the hack - DO NOT DELETE
4182
+ delete event.sdkProcessingMetadata;
4158
4183
  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
4184
  const eventItem = [
4160
4185
  {
@@ -4379,7 +4404,57 @@ var Sentry = (function (exports) {
4379
4404
  hub.bindClient(client);
4380
4405
  }
4381
4406
 
4382
- const SDK_VERSION = '6.19.2';
4407
+ const DEFAULT_TRANSPORT_BUFFER_SIZE = 30;
4408
+ /**
4409
+ * Creates a `NewTransport`
4410
+ *
4411
+ * @param options
4412
+ * @param makeRequest
4413
+ */
4414
+ function createTransport(options, makeRequest, buffer = makePromiseBuffer(options.bufferSize || DEFAULT_TRANSPORT_BUFFER_SIZE)) {
4415
+ let rateLimits = {};
4416
+ const flush = (timeout) => buffer.drain(timeout);
4417
+ function send(envelope) {
4418
+ const envCategory = getEnvelopeType(envelope);
4419
+ const category = envCategory === 'event' ? 'error' : envCategory;
4420
+ const request = {
4421
+ category,
4422
+ body: serializeEnvelope(envelope),
4423
+ };
4424
+ // Don't add to buffer if transport is already rate-limited
4425
+ if (isRateLimited(rateLimits, category)) {
4426
+ return rejectedSyncPromise({
4427
+ status: 'rate_limit',
4428
+ reason: getRateLimitReason(rateLimits, category),
4429
+ });
4430
+ }
4431
+ const requestTask = () => makeRequest(request).then(({ body, headers, reason, statusCode }) => {
4432
+ const status = eventStatusFromHttpCode(statusCode);
4433
+ if (headers) {
4434
+ rateLimits = updateRateLimits(rateLimits, headers);
4435
+ }
4436
+ if (status === 'success') {
4437
+ return resolvedSyncPromise({ status, reason });
4438
+ }
4439
+ return rejectedSyncPromise({
4440
+ status,
4441
+ reason: reason ||
4442
+ body ||
4443
+ (status === 'rate_limit' ? getRateLimitReason(rateLimits, category) : 'Unknown transport error'),
4444
+ });
4445
+ });
4446
+ return buffer.add(requestTask);
4447
+ }
4448
+ return {
4449
+ send,
4450
+ flush,
4451
+ };
4452
+ }
4453
+ function getRateLimitReason(rateLimits, category) {
4454
+ return `Too many ${category} requests, backing off until: ${new Date(disabledUntil(rateLimits, category)).toISOString()}`;
4455
+ }
4456
+
4457
+ const SDK_VERSION = '6.19.3';
4383
4458
 
4384
4459
  let originalFunctionToString;
4385
4460
  /** Patch toString calls to return proper name for wrapped functions */
@@ -5248,11 +5323,76 @@ var Sentry = (function (exports) {
5248
5323
  }
5249
5324
  }
5250
5325
 
5326
+ /**
5327
+ * Creates a Transport that uses the Fetch API to send events to Sentry.
5328
+ */
5329
+ function makeNewFetchTransport(options, nativeFetch = getNativeFetchImplementation()) {
5330
+ function makeRequest(request) {
5331
+ const requestOptions = Object.assign({ body: request.body, method: 'POST', referrerPolicy: 'origin' }, options.requestOptions);
5332
+ return nativeFetch(options.url, requestOptions).then(response => {
5333
+ return response.text().then(body => ({
5334
+ body,
5335
+ headers: {
5336
+ 'x-sentry-rate-limits': response.headers.get('X-Sentry-Rate-Limits'),
5337
+ 'retry-after': response.headers.get('Retry-After'),
5338
+ },
5339
+ reason: response.statusText,
5340
+ statusCode: response.status,
5341
+ }));
5342
+ });
5343
+ }
5344
+ return createTransport({ bufferSize: options.bufferSize }, makeRequest);
5345
+ }
5346
+
5347
+ /**
5348
+ * The DONE ready state for XmlHttpRequest
5349
+ *
5350
+ * Defining it here as a constant b/c XMLHttpRequest.DONE is not always defined
5351
+ * (e.g. during testing, it is `undefined`)
5352
+ *
5353
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readyState}
5354
+ */
5355
+ const XHR_READYSTATE_DONE = 4;
5356
+ /**
5357
+ * Creates a Transport that uses the XMLHttpRequest API to send events to Sentry.
5358
+ */
5359
+ function makeNewXHRTransport(options) {
5360
+ function makeRequest(request) {
5361
+ return new SyncPromise((resolve, _reject) => {
5362
+ const xhr = new XMLHttpRequest();
5363
+ xhr.onreadystatechange = () => {
5364
+ if (xhr.readyState === XHR_READYSTATE_DONE) {
5365
+ const response = {
5366
+ body: xhr.response,
5367
+ headers: {
5368
+ 'x-sentry-rate-limits': xhr.getResponseHeader('X-Sentry-Rate-Limits'),
5369
+ 'retry-after': xhr.getResponseHeader('Retry-After'),
5370
+ },
5371
+ reason: xhr.statusText,
5372
+ statusCode: xhr.status,
5373
+ };
5374
+ resolve(response);
5375
+ }
5376
+ };
5377
+ xhr.open('POST', options.url);
5378
+ for (const header in options.headers) {
5379
+ if (Object.prototype.hasOwnProperty.call(options.headers, header)) {
5380
+ xhr.setRequestHeader(header, options.headers[header]);
5381
+ }
5382
+ }
5383
+ xhr.send(request.body);
5384
+ });
5385
+ }
5386
+ return createTransport({ bufferSize: options.bufferSize }, makeRequest);
5387
+ }
5388
+
5251
5389
  var index = /*#__PURE__*/Object.freeze({
5252
5390
  __proto__: null,
5253
5391
  BaseTransport: BaseTransport,
5254
5392
  FetchTransport: FetchTransport,
5255
- XHRTransport: XHRTransport
5393
+ XHRTransport: XHRTransport,
5394
+ makeNewFetchTransport: makeNewFetchTransport,
5395
+ makeNewXHRTransport: makeNewXHRTransport
5256
5396
  });
5257
5397
 
5258
5398
  /**
@@ -5281,12 +5421,20 @@ var Sentry = (function (exports) {
5281
5421
  return super._setupTransport();
5282
5422
  }
5283
5423
  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 });
5424
+ const api = initAPIDetails(transportOptions.dsn, transportOptions._metadata, transportOptions.tunnel);
5425
+ const url = getEnvelopeEndpointWithUrlEncodedAuth(api.dsn, api.tunnel);
5284
5426
  if (this._options.transport) {
5285
5427
  return new this._options.transport(transportOptions);
5286
5428
  }
5287
5429
  if (supportsFetch()) {
5430
+ const requestOptions = Object.assign({}, transportOptions.fetchParameters);
5431
+ this._newTransport = makeNewFetchTransport({ requestOptions, url });
5288
5432
  return new FetchTransport(transportOptions);
5289
5433
  }
5434
+ this._newTransport = makeNewXHRTransport({
5435
+ url,
5436
+ headers: transportOptions.headers,
5437
+ });
5290
5438
  return new XHRTransport(transportOptions);
5291
5439
  }
5292
5440
  }