@sentry/browser 6.15.0 → 6.17.0

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 (111) hide show
  1. package/build/bundle.es6.js +1265 -1435
  2. package/build/bundle.es6.js.map +1 -1
  3. package/build/bundle.es6.min.js +2 -2
  4. package/build/bundle.es6.min.js.map +1 -1
  5. package/build/bundle.js +1304 -1490
  6. package/build/bundle.js.map +1 -1
  7. package/build/bundle.min.js +2 -2
  8. package/build/bundle.min.js.map +1 -1
  9. package/dist/eventbuilder.d.ts +2 -2
  10. package/dist/eventbuilder.d.ts.map +1 -1
  11. package/dist/eventbuilder.js +7 -7
  12. package/dist/eventbuilder.js.map +1 -1
  13. package/dist/exports.d.ts +1 -1
  14. package/dist/exports.d.ts.map +1 -1
  15. package/dist/exports.js +0 -1
  16. package/dist/exports.js.map +1 -1
  17. package/dist/helpers.d.ts.map +1 -1
  18. package/dist/helpers.js +26 -37
  19. package/dist/helpers.js.map +1 -1
  20. package/dist/integrations/breadcrumbs.d.ts +0 -20
  21. package/dist/integrations/breadcrumbs.d.ts.map +1 -1
  22. package/dist/integrations/breadcrumbs.js +132 -173
  23. package/dist/integrations/breadcrumbs.js.map +1 -1
  24. package/dist/integrations/dedupe.d.ts +0 -14
  25. package/dist/integrations/dedupe.d.ts.map +1 -1
  26. package/dist/integrations/dedupe.js +126 -126
  27. package/dist/integrations/dedupe.js.map +1 -1
  28. package/dist/integrations/globalhandlers.d.ts +7 -25
  29. package/dist/integrations/globalhandlers.d.ts.map +1 -1
  30. package/dist/integrations/globalhandlers.js +176 -168
  31. package/dist/integrations/globalhandlers.js.map +1 -1
  32. package/dist/integrations/linkederrors.d.ts +15 -13
  33. package/dist/integrations/linkederrors.d.ts.map +1 -1
  34. package/dist/integrations/linkederrors.js +26 -28
  35. package/dist/integrations/linkederrors.js.map +1 -1
  36. package/dist/integrations/trycatch.d.ts +0 -8
  37. package/dist/integrations/trycatch.d.ts.map +1 -1
  38. package/dist/integrations/trycatch.js +154 -153
  39. package/dist/integrations/trycatch.js.map +1 -1
  40. package/dist/integrations/useragent.js +2 -3
  41. package/dist/integrations/useragent.js.map +1 -1
  42. package/dist/sdk.d.ts.map +1 -1
  43. package/dist/sdk.js +23 -19
  44. package/dist/sdk.js.map +1 -1
  45. package/dist/transports/base.d.ts +9 -4
  46. package/dist/transports/base.d.ts.map +1 -1
  47. package/dist/transports/base.js +23 -19
  48. package/dist/transports/base.js.map +1 -1
  49. package/dist/transports/fetch.d.ts +2 -10
  50. package/dist/transports/fetch.d.ts.map +1 -1
  51. package/dist/transports/fetch.js +6 -20
  52. package/dist/transports/fetch.js.map +1 -1
  53. package/dist/transports/utils.d.ts.map +1 -1
  54. package/dist/transports/utils.js +7 -5
  55. package/dist/transports/utils.js.map +1 -1
  56. package/dist/transports/xhr.d.ts +2 -10
  57. package/dist/transports/xhr.d.ts.map +1 -1
  58. package/dist/transports/xhr.js +3 -17
  59. package/dist/transports/xhr.js.map +1 -1
  60. package/esm/eventbuilder.d.ts +2 -2
  61. package/esm/eventbuilder.d.ts.map +1 -1
  62. package/esm/eventbuilder.js +8 -8
  63. package/esm/eventbuilder.js.map +1 -1
  64. package/esm/exports.d.ts +1 -1
  65. package/esm/exports.d.ts.map +1 -1
  66. package/esm/exports.js +1 -1
  67. package/esm/exports.js.map +1 -1
  68. package/esm/helpers.d.ts.map +1 -1
  69. package/esm/helpers.js +28 -39
  70. package/esm/helpers.js.map +1 -1
  71. package/esm/integrations/breadcrumbs.d.ts +0 -20
  72. package/esm/integrations/breadcrumbs.d.ts.map +1 -1
  73. package/esm/integrations/breadcrumbs.js +134 -175
  74. package/esm/integrations/breadcrumbs.js.map +1 -1
  75. package/esm/integrations/dedupe.d.ts +0 -14
  76. package/esm/integrations/dedupe.d.ts.map +1 -1
  77. package/esm/integrations/dedupe.js +126 -126
  78. package/esm/integrations/dedupe.js.map +1 -1
  79. package/esm/integrations/globalhandlers.d.ts +7 -25
  80. package/esm/integrations/globalhandlers.d.ts.map +1 -1
  81. package/esm/integrations/globalhandlers.js +178 -170
  82. package/esm/integrations/globalhandlers.js.map +1 -1
  83. package/esm/integrations/linkederrors.d.ts +15 -13
  84. package/esm/integrations/linkederrors.d.ts.map +1 -1
  85. package/esm/integrations/linkederrors.js +24 -28
  86. package/esm/integrations/linkederrors.js.map +1 -1
  87. package/esm/integrations/trycatch.d.ts +0 -8
  88. package/esm/integrations/trycatch.d.ts.map +1 -1
  89. package/esm/integrations/trycatch.js +155 -154
  90. package/esm/integrations/trycatch.js.map +1 -1
  91. package/esm/integrations/useragent.js +2 -3
  92. package/esm/integrations/useragent.js.map +1 -1
  93. package/esm/sdk.d.ts.map +1 -1
  94. package/esm/sdk.js +24 -20
  95. package/esm/sdk.js.map +1 -1
  96. package/esm/transports/base.d.ts +9 -4
  97. package/esm/transports/base.d.ts.map +1 -1
  98. package/esm/transports/base.js +25 -21
  99. package/esm/transports/base.js.map +1 -1
  100. package/esm/transports/fetch.d.ts +2 -10
  101. package/esm/transports/fetch.d.ts.map +1 -1
  102. package/esm/transports/fetch.js +6 -20
  103. package/esm/transports/fetch.js.map +1 -1
  104. package/esm/transports/utils.d.ts.map +1 -1
  105. package/esm/transports/utils.js +8 -6
  106. package/esm/transports/utils.js.map +1 -1
  107. package/esm/transports/xhr.d.ts +2 -10
  108. package/esm/transports/xhr.d.ts.map +1 -1
  109. package/esm/transports/xhr.js +3 -17
  110. package/esm/transports/xhr.js.map +1 -1
  111. package/package.json +15 -17
package/build/bundle.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @sentry/browser 6.15.0 (aa30ab6) | https://github.com/getsentry/sentry-javascript */
1
+ /*! @sentry/browser 6.17.0 (ad2f4ad) | https://github.com/getsentry/sentry-javascript */
2
2
  var Sentry = (function (exports) {
3
3
  /*! *****************************************************************************
4
4
  Copyright (c) Microsoft Corporation. All rights reserved.
@@ -40,16 +40,6 @@ var Sentry = (function (exports) {
40
40
  return __assign.apply(this, arguments);
41
41
  };
42
42
 
43
- function __rest(s, e) {
44
- var t = {};
45
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
46
- t[p] = s[p];
47
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
48
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
49
- t[p[i]] = s[p[i]];
50
- return t;
51
- }
52
-
53
43
  function __values(o) {
54
44
  var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
55
45
  if (m) return m.call(o);
@@ -84,44 +74,9 @@ var Sentry = (function (exports) {
84
74
  return ar;
85
75
  }
86
76
 
87
- /** Console logging verbosity for the SDK. */
88
- var LogLevel;
89
- (function (LogLevel) {
90
- /** No logs will be generated. */
91
- LogLevel[LogLevel["None"] = 0] = "None";
92
- /** Only SDK internal errors will be logged. */
93
- LogLevel[LogLevel["Error"] = 1] = "Error";
94
- /** Information useful for debugging the SDK will be logged. */
95
- LogLevel[LogLevel["Debug"] = 2] = "Debug";
96
- /** All SDK actions will be logged. */
97
- LogLevel[LogLevel["Verbose"] = 3] = "Verbose";
98
- })(LogLevel || (LogLevel = {}));
99
-
100
77
  /**
101
- * Session Status
78
+ * TODO(v7): Remove this enum and replace with SeverityLevel
102
79
  */
103
- var SessionStatus;
104
- (function (SessionStatus) {
105
- /** JSDoc */
106
- SessionStatus["Ok"] = "ok";
107
- /** JSDoc */
108
- SessionStatus["Exited"] = "exited";
109
- /** JSDoc */
110
- SessionStatus["Crashed"] = "crashed";
111
- /** JSDoc */
112
- SessionStatus["Abnormal"] = "abnormal";
113
- })(SessionStatus || (SessionStatus = {}));
114
- var RequestSessionStatus;
115
- (function (RequestSessionStatus) {
116
- /** JSDoc */
117
- RequestSessionStatus["Ok"] = "ok";
118
- /** JSDoc */
119
- RequestSessionStatus["Errored"] = "errored";
120
- /** JSDoc */
121
- RequestSessionStatus["Crashed"] = "crashed";
122
- })(RequestSessionStatus || (RequestSessionStatus = {}));
123
-
124
- /** JSDoc */
125
80
  (function (Severity) {
126
81
  /** JSDoc */
127
82
  Severity["Fatal"] = "fatal";
@@ -138,95 +93,7 @@ var Sentry = (function (exports) {
138
93
  /** JSDoc */
139
94
  Severity["Critical"] = "critical";
140
95
  })(exports.Severity || (exports.Severity = {}));
141
- // eslint-disable-next-line @typescript-eslint/no-namespace, import/export
142
- (function (Severity) {
143
- /**
144
- * Converts a string-based level into a {@link Severity}.
145
- *
146
- * @param level string representation of Severity
147
- * @returns Severity
148
- */
149
- function fromString(level) {
150
- switch (level) {
151
- case 'debug':
152
- return Severity.Debug;
153
- case 'info':
154
- return Severity.Info;
155
- case 'warn':
156
- case 'warning':
157
- return Severity.Warning;
158
- case 'error':
159
- return Severity.Error;
160
- case 'fatal':
161
- return Severity.Fatal;
162
- case 'critical':
163
- return Severity.Critical;
164
- case 'log':
165
- default:
166
- return Severity.Log;
167
- }
168
- }
169
- Severity.fromString = fromString;
170
- })(exports.Severity || (exports.Severity = {}));
171
-
172
- /** The status of an event. */
173
- (function (Status) {
174
- /** The status could not be determined. */
175
- Status["Unknown"] = "unknown";
176
- /** The event was skipped due to configuration or callbacks. */
177
- Status["Skipped"] = "skipped";
178
- /** The event was sent to Sentry successfully. */
179
- Status["Success"] = "success";
180
- /** The client is currently rate limited and will try again later. */
181
- Status["RateLimit"] = "rate_limit";
182
- /** The event could not be processed. */
183
- Status["Invalid"] = "invalid";
184
- /** A server-side error occurred during submission. */
185
- Status["Failed"] = "failed";
186
- })(exports.Status || (exports.Status = {}));
187
- // eslint-disable-next-line @typescript-eslint/no-namespace, import/export
188
- (function (Status) {
189
- /**
190
- * Converts a HTTP status code into a {@link Status}.
191
- *
192
- * @param code The HTTP response status code.
193
- * @returns The send status or {@link Status.Unknown}.
194
- */
195
- function fromHttpCode(code) {
196
- if (code >= 200 && code < 300) {
197
- return Status.Success;
198
- }
199
- if (code === 429) {
200
- return Status.RateLimit;
201
- }
202
- if (code >= 400 && code < 500) {
203
- return Status.Invalid;
204
- }
205
- if (code >= 500) {
206
- return Status.Failed;
207
- }
208
- return Status.Unknown;
209
- }
210
- Status.fromHttpCode = fromHttpCode;
211
- })(exports.Status || (exports.Status = {}));
212
-
213
- var TransactionSamplingMethod;
214
- (function (TransactionSamplingMethod) {
215
- TransactionSamplingMethod["Explicit"] = "explicitly_set";
216
- TransactionSamplingMethod["Sampler"] = "client_sampler";
217
- TransactionSamplingMethod["Rate"] = "client_rate";
218
- TransactionSamplingMethod["Inheritance"] = "inheritance";
219
- })(TransactionSamplingMethod || (TransactionSamplingMethod = {}));
220
-
221
- var Outcome;
222
- (function (Outcome) {
223
- Outcome["BeforeSend"] = "before_send";
224
- Outcome["EventProcessor"] = "event_processor";
225
- Outcome["NetworkError"] = "network_error";
226
- Outcome["QueueOverflow"] = "queue_overflow";
227
- Outcome["RateLimitBackoff"] = "ratelimit_backoff";
228
- Outcome["SampleRate"] = "sample_rate";
229
- })(Outcome || (Outcome = {}));
96
+ var SeverityLevels = ['fatal', 'error', 'warning', 'log', 'info', 'debug', 'critical'];
230
97
 
231
98
  /**
232
99
  * Consumes the promise and logs the error when it rejects.
@@ -241,6 +108,33 @@ var Sentry = (function (exports) {
241
108
  });
242
109
  }
243
110
 
111
+ /**
112
+ * This module mostly exists for optimizations in the build process
113
+ * through rollup and terser. We define some global constants which
114
+ * are normally undefined. However terser overrides these with global
115
+ * definitions which can be evaluated by the static analyzer when
116
+ * creating a bundle.
117
+ *
118
+ * In turn the `isDebugBuild` and `isBrowserBundle` functions are pure
119
+ * and can help us remove unused code from the bundles.
120
+ */
121
+ /**
122
+ * Figures out if we're building with debug functionality.
123
+ *
124
+ * @returns true if this is a debug build
125
+ */
126
+ function isDebugBuild() {
127
+ return typeof __SENTRY_NO_DEBUG__ !== 'undefined' && !__SENTRY_BROWSER_BUNDLE__;
128
+ }
129
+ /**
130
+ * Figures out if we're building a browser bundle.
131
+ *
132
+ * @returns true if this is a browser bundle build.
133
+ */
134
+ function isBrowserBundle() {
135
+ return typeof __SENTRY_BROWSER_BUNDLE__ !== 'undefined' && !!__SENTRY_BROWSER_BUNDLE__;
136
+ }
137
+
244
138
  /**
245
139
  * NOTE: In order to avoid circular dependencies, if you add a function to this module and it needs to print something,
246
140
  * you must either a) use `console.log` rather than the logger, or b) put your function elsewhere.
@@ -251,7 +145,10 @@ var Sentry = (function (exports) {
251
145
  * @returns Answer to given question
252
146
  */
253
147
  function isNodeEnv() {
254
- return Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
148
+ // explicitly check for browser bundles as those can be optimized statically
149
+ // by terser/rollup.
150
+ return (!isBrowserBundle() &&
151
+ Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]');
255
152
  }
256
153
  /**
257
154
  * Requires a module which is protected against bundler minification.
@@ -286,6 +183,8 @@ var Sentry = (function (exports) {
286
183
 
287
184
  /* eslint-disable @typescript-eslint/no-explicit-any */
288
185
  /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
186
+ // eslint-disable-next-line @typescript-eslint/unbound-method
187
+ var objectToString = Object.prototype.toString;
289
188
  /**
290
189
  * Checks whether given value's type is one of a few Error or Error-like
291
190
  * {@link isError}.
@@ -294,17 +193,18 @@ var Sentry = (function (exports) {
294
193
  * @returns A boolean representing the result.
295
194
  */
296
195
  function isError(wat) {
297
- switch (Object.prototype.toString.call(wat)) {
196
+ switch (objectToString.call(wat)) {
298
197
  case '[object Error]':
299
- return true;
300
198
  case '[object Exception]':
301
- return true;
302
199
  case '[object DOMException]':
303
200
  return true;
304
201
  default:
305
202
  return isInstanceOf(wat, Error);
306
203
  }
307
204
  }
205
+ function isBuiltin(wat, ty) {
206
+ return objectToString.call(wat) === "[object " + ty + "]";
207
+ }
308
208
  /**
309
209
  * Checks whether given value's type is ErrorEvent
310
210
  * {@link isErrorEvent}.
@@ -313,7 +213,7 @@ var Sentry = (function (exports) {
313
213
  * @returns A boolean representing the result.
314
214
  */
315
215
  function isErrorEvent(wat) {
316
- return Object.prototype.toString.call(wat) === '[object ErrorEvent]';
216
+ return isBuiltin(wat, 'ErrorEvent');
317
217
  }
318
218
  /**
319
219
  * Checks whether given value's type is DOMError
@@ -323,7 +223,7 @@ var Sentry = (function (exports) {
323
223
  * @returns A boolean representing the result.
324
224
  */
325
225
  function isDOMError(wat) {
326
- return Object.prototype.toString.call(wat) === '[object DOMError]';
226
+ return isBuiltin(wat, 'DOMError');
327
227
  }
328
228
  /**
329
229
  * Checks whether given value's type is DOMException
@@ -333,7 +233,7 @@ var Sentry = (function (exports) {
333
233
  * @returns A boolean representing the result.
334
234
  */
335
235
  function isDOMException(wat) {
336
- return Object.prototype.toString.call(wat) === '[object DOMException]';
236
+ return isBuiltin(wat, 'DOMException');
337
237
  }
338
238
  /**
339
239
  * Checks whether given value's type is a string
@@ -343,10 +243,10 @@ var Sentry = (function (exports) {
343
243
  * @returns A boolean representing the result.
344
244
  */
345
245
  function isString(wat) {
346
- return Object.prototype.toString.call(wat) === '[object String]';
246
+ return isBuiltin(wat, 'String');
347
247
  }
348
248
  /**
349
- * Checks whether given value's is a primitive (undefined, null, number, boolean, string, bigint, symbol)
249
+ * Checks whether given value is a primitive (undefined, null, number, boolean, string, bigint, symbol)
350
250
  * {@link isPrimitive}.
351
251
  *
352
252
  * @param wat A value to be checked.
@@ -363,7 +263,7 @@ var Sentry = (function (exports) {
363
263
  * @returns A boolean representing the result.
364
264
  */
365
265
  function isPlainObject(wat) {
366
- return Object.prototype.toString.call(wat) === '[object Object]';
266
+ return isBuiltin(wat, 'Object');
367
267
  }
368
268
  /**
369
269
  * Checks whether given value's type is an Event instance
@@ -393,7 +293,7 @@ var Sentry = (function (exports) {
393
293
  * @returns A boolean representing the result.
394
294
  */
395
295
  function isRegExp(wat) {
396
- return Object.prototype.toString.call(wat) === '[object RegExp]';
296
+ return isBuiltin(wat, 'RegExp');
397
297
  }
398
298
  /**
399
299
  * Checks whether given value has a then function.
@@ -477,7 +377,6 @@ var Sentry = (function (exports) {
477
377
  * @returns generated DOM path
478
378
  */
479
379
  function _htmlElementAsString(el, keyAttrs) {
480
- var _a, _b;
481
380
  var elem = el;
482
381
  var out = [];
483
382
  var className;
@@ -490,9 +389,10 @@ var Sentry = (function (exports) {
490
389
  }
491
390
  out.push(elem.tagName.toLowerCase());
492
391
  // Pairs of attribute keys defined in `serializeAttribute` and their values on element.
493
- var keyAttrPairs = ((_a = keyAttrs) === null || _a === void 0 ? void 0 : _a.length) ? keyAttrs.filter(function (keyAttr) { return elem.getAttribute(keyAttr); }).map(function (keyAttr) { return [keyAttr, elem.getAttribute(keyAttr)]; })
392
+ var keyAttrPairs = keyAttrs && keyAttrs.length
393
+ ? keyAttrs.filter(function (keyAttr) { return elem.getAttribute(keyAttr); }).map(function (keyAttr) { return [keyAttr, elem.getAttribute(keyAttr)]; })
494
394
  : null;
495
- if ((_b = keyAttrPairs) === null || _b === void 0 ? void 0 : _b.length) {
395
+ if (keyAttrPairs && keyAttrPairs.length) {
496
396
  keyAttrPairs.forEach(function (keyAttrPair) {
497
397
  out.push("[" + keyAttrPair[0] + "=\"" + keyAttrPair[1] + "\"]");
498
398
  });
@@ -573,92 +473,89 @@ var Sentry = (function (exports) {
573
473
 
574
474
  /** Regular expression used to parse a Dsn. */
575
475
  var DSN_REGEX = /^(?:(\w+):)\/\/(?:(\w+)(?::(\w+))?@)([\w.-]+)(?::(\d+))?\/(.+)/;
576
- /** Error message */
577
- var ERROR_MESSAGE = 'Invalid Dsn';
578
- /** The Sentry Dsn, identifying a Sentry instance and project. */
579
- var Dsn = /** @class */ (function () {
580
- /** Creates a new Dsn component */
581
- function Dsn(from) {
582
- if (typeof from === 'string') {
583
- this._fromString(from);
584
- }
585
- else {
586
- this._fromComponents(from);
587
- }
588
- this._validate();
476
+ function isValidProtocol(protocol) {
477
+ return protocol === 'http' || protocol === 'https';
478
+ }
479
+ /**
480
+ * Renders the string representation of this Dsn.
481
+ *
482
+ * By default, this will render the public representation without the password
483
+ * component. To get the deprecated private representation, set `withPassword`
484
+ * to true.
485
+ *
486
+ * @param withPassword When set to true, the password will be included.
487
+ */
488
+ function dsnToString(dsn, withPassword) {
489
+ if (withPassword === void 0) { withPassword = false; }
490
+ var host = dsn.host, path = dsn.path, pass = dsn.pass, port = dsn.port, projectId = dsn.projectId, protocol = dsn.protocol, publicKey = dsn.publicKey;
491
+ return (protocol + "://" + publicKey + (withPassword && pass ? ":" + pass : '') +
492
+ ("@" + host + (port ? ":" + port : '') + "/" + (path ? path + "/" : path) + projectId));
493
+ }
494
+ function dsnFromString(str) {
495
+ var match = DSN_REGEX.exec(str);
496
+ if (!match) {
497
+ throw new SentryError("Invalid Sentry Dsn: " + str);
589
498
  }
590
- /**
591
- * Renders the string representation of this Dsn.
592
- *
593
- * By default, this will render the public representation without the password
594
- * component. To get the deprecated private representation, set `withPassword`
595
- * to true.
596
- *
597
- * @param withPassword When set to true, the password will be included.
598
- */
599
- Dsn.prototype.toString = function (withPassword) {
600
- if (withPassword === void 0) { withPassword = false; }
601
- var _a = this, host = _a.host, path = _a.path, pass = _a.pass, port = _a.port, projectId = _a.projectId, protocol = _a.protocol, publicKey = _a.publicKey;
602
- return (protocol + "://" + publicKey + (withPassword && pass ? ":" + pass : '') +
603
- ("@" + host + (port ? ":" + port : '') + "/" + (path ? path + "/" : path) + projectId));
604
- };
605
- /** Parses a string into this Dsn. */
606
- Dsn.prototype._fromString = function (str) {
607
- var match = DSN_REGEX.exec(str);
608
- if (!match) {
609
- throw new SentryError(ERROR_MESSAGE);
610
- }
611
- var _a = __read(match.slice(1), 6), protocol = _a[0], publicKey = _a[1], _b = _a[2], pass = _b === void 0 ? '' : _b, host = _a[3], _c = _a[4], port = _c === void 0 ? '' : _c, lastPath = _a[5];
612
- var path = '';
613
- var projectId = lastPath;
614
- var split = projectId.split('/');
615
- if (split.length > 1) {
616
- path = split.slice(0, -1).join('/');
617
- projectId = split.pop();
618
- }
619
- if (projectId) {
620
- var projectMatch = projectId.match(/^\d+/);
621
- if (projectMatch) {
622
- projectId = projectMatch[0];
623
- }
624
- }
625
- this._fromComponents({ host: host, pass: pass, path: path, projectId: projectId, port: port, protocol: protocol, publicKey: publicKey });
626
- };
627
- /** Maps Dsn components into this instance. */
628
- Dsn.prototype._fromComponents = function (components) {
629
- // TODO this is for backwards compatibility, and can be removed in a future version
630
- if ('user' in components && !('publicKey' in components)) {
631
- components.publicKey = components.user;
632
- }
633
- this.user = components.publicKey || '';
634
- this.protocol = components.protocol;
635
- this.publicKey = components.publicKey || '';
636
- this.pass = components.pass || '';
637
- this.host = components.host;
638
- this.port = components.port || '';
639
- this.path = components.path || '';
640
- this.projectId = components.projectId;
641
- };
642
- /** Validates this Dsn and throws on error. */
643
- Dsn.prototype._validate = function () {
644
- var _this = this;
645
- ['protocol', 'publicKey', 'host', 'projectId'].forEach(function (component) {
646
- if (!_this[component]) {
647
- throw new SentryError(ERROR_MESSAGE + ": " + component + " missing");
648
- }
649
- });
650
- if (!this.projectId.match(/^\d+$/)) {
651
- throw new SentryError(ERROR_MESSAGE + ": Invalid projectId " + this.projectId);
652
- }
653
- if (this.protocol !== 'http' && this.protocol !== 'https') {
654
- throw new SentryError(ERROR_MESSAGE + ": Invalid protocol " + this.protocol);
655
- }
656
- if (this.port && isNaN(parseInt(this.port, 10))) {
657
- throw new SentryError(ERROR_MESSAGE + ": Invalid port " + this.port);
499
+ var _a = __read(match.slice(1), 6), protocol = _a[0], publicKey = _a[1], _b = _a[2], pass = _b === void 0 ? '' : _b, host = _a[3], _c = _a[4], port = _c === void 0 ? '' : _c, lastPath = _a[5];
500
+ var path = '';
501
+ var projectId = lastPath;
502
+ var split = projectId.split('/');
503
+ if (split.length > 1) {
504
+ path = split.slice(0, -1).join('/');
505
+ projectId = split.pop();
506
+ }
507
+ if (projectId) {
508
+ var projectMatch = projectId.match(/^\d+/);
509
+ if (projectMatch) {
510
+ projectId = projectMatch[0];
658
511
  }
512
+ }
513
+ return dsnFromComponents({ host: host, pass: pass, path: path, projectId: projectId, port: port, protocol: protocol, publicKey: publicKey });
514
+ }
515
+ function dsnFromComponents(components) {
516
+ // TODO this is for backwards compatibility, and can be removed in a future version
517
+ if ('user' in components && !('publicKey' in components)) {
518
+ components.publicKey = components.user;
519
+ }
520
+ return {
521
+ user: components.publicKey || '',
522
+ protocol: components.protocol,
523
+ publicKey: components.publicKey || '',
524
+ pass: components.pass || '',
525
+ host: components.host,
526
+ port: components.port || '',
527
+ path: components.path || '',
528
+ projectId: components.projectId,
659
529
  };
660
- return Dsn;
661
- }());
530
+ }
531
+ function validateDsn(dsn) {
532
+ if (!isDebugBuild()) {
533
+ return;
534
+ }
535
+ var port = dsn.port, projectId = dsn.projectId, protocol = dsn.protocol;
536
+ var requiredComponents = ['protocol', 'publicKey', 'host', 'projectId'];
537
+ requiredComponents.forEach(function (component) {
538
+ if (!dsn[component]) {
539
+ throw new SentryError("Invalid Sentry Dsn: " + component + " missing");
540
+ }
541
+ });
542
+ if (!projectId.match(/^\d+$/)) {
543
+ throw new SentryError("Invalid Sentry Dsn: Invalid projectId " + projectId);
544
+ }
545
+ if (!isValidProtocol(protocol)) {
546
+ throw new SentryError("Invalid Sentry Dsn: Invalid protocol " + protocol);
547
+ }
548
+ if (port && isNaN(parseInt(port, 10))) {
549
+ throw new SentryError("Invalid Sentry Dsn: Invalid port " + port);
550
+ }
551
+ return true;
552
+ }
553
+ /** The Sentry Dsn, identifying a Sentry instance and project. */
554
+ function makeDsn(from) {
555
+ var components = typeof from === 'string' ? dsnFromString(from) : dsnFromComponents(from);
556
+ validateDsn(components);
557
+ return components;
558
+ }
662
559
 
663
560
  // TODO: Implement different loggers for different environments
664
561
  var global$1 = getGlobalObject();
@@ -757,56 +654,45 @@ var Sentry = (function (exports) {
757
654
 
758
655
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
759
656
  /* eslint-disable @typescript-eslint/no-explicit-any */
760
- /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
761
657
  /**
762
- * Memo class used for decycle json objects. Uses WeakSet if available otherwise array.
658
+ * Helper to decycle json objects
763
659
  */
764
- var Memo = /** @class */ (function () {
765
- function Memo() {
766
- this._hasWeakSet = typeof WeakSet === 'function';
767
- this._inner = this._hasWeakSet ? new WeakSet() : [];
768
- }
769
- /**
770
- * Sets obj to remember.
771
- * @param obj Object to remember
772
- */
773
- Memo.prototype.memoize = function (obj) {
774
- if (this._hasWeakSet) {
775
- if (this._inner.has(obj)) {
660
+ function memoBuilder() {
661
+ var hasWeakSet = typeof WeakSet === 'function';
662
+ var inner = hasWeakSet ? new WeakSet() : [];
663
+ function memoize(obj) {
664
+ if (hasWeakSet) {
665
+ if (inner.has(obj)) {
776
666
  return true;
777
667
  }
778
- this._inner.add(obj);
668
+ inner.add(obj);
779
669
  return false;
780
670
  }
781
671
  // eslint-disable-next-line @typescript-eslint/prefer-for-of
782
- for (var i = 0; i < this._inner.length; i++) {
783
- var value = this._inner[i];
672
+ for (var i = 0; i < inner.length; i++) {
673
+ var value = inner[i];
784
674
  if (value === obj) {
785
675
  return true;
786
676
  }
787
677
  }
788
- this._inner.push(obj);
678
+ inner.push(obj);
789
679
  return false;
790
- };
791
- /**
792
- * Removes object from internal storage.
793
- * @param obj Object to forget
794
- */
795
- Memo.prototype.unmemoize = function (obj) {
796
- if (this._hasWeakSet) {
797
- this._inner.delete(obj);
680
+ }
681
+ function unmemoize(obj) {
682
+ if (hasWeakSet) {
683
+ inner.delete(obj);
798
684
  }
799
685
  else {
800
- for (var i = 0; i < this._inner.length; i++) {
801
- if (this._inner[i] === obj) {
802
- this._inner.splice(i, 1);
686
+ for (var i = 0; i < inner.length; i++) {
687
+ if (inner[i] === obj) {
688
+ inner.splice(i, 1);
803
689
  break;
804
690
  }
805
691
  }
806
692
  }
807
- };
808
- return Memo;
809
- }());
693
+ }
694
+ return [memoize, unmemoize];
695
+ }
810
696
 
811
697
  var defaultFunctionName = '<anonymous>';
812
698
  /**
@@ -903,13 +789,7 @@ var Sentry = (function (exports) {
903
789
  // otherwise it'll throw "TypeError: Object.defineProperties called on non-object"
904
790
  if (typeof wrapped === 'function') {
905
791
  try {
906
- wrapped.prototype = wrapped.prototype || {};
907
- Object.defineProperties(wrapped, {
908
- __sentry_original__: {
909
- enumerable: false,
910
- value: original,
911
- },
912
- });
792
+ markFunctionWrapped(wrapped, original);
913
793
  }
914
794
  catch (_Oo) {
915
795
  // This can throw if multiple fill happens on a global object like XMLHttpRequest
@@ -918,6 +798,41 @@ var Sentry = (function (exports) {
918
798
  }
919
799
  source[name] = wrapped;
920
800
  }
801
+ /**
802
+ * Defines a non enumerable property. This creates a non enumerable property on an object.
803
+ *
804
+ * @param func The function to set a property to
805
+ * @param name the name of the special sentry property
806
+ * @param value the property to define
807
+ */
808
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
809
+ function addNonEnumerableProperty(func, name, value) {
810
+ Object.defineProperty(func, name, {
811
+ value: value,
812
+ });
813
+ }
814
+ /**
815
+ * Remembers the original function on the wrapped function and
816
+ * patches up the prototype.
817
+ *
818
+ * @param wrapped the wrapper function
819
+ * @param original the original function that gets wrapped
820
+ */
821
+ function markFunctionWrapped(wrapped, original) {
822
+ var proto = original.prototype || {};
823
+ wrapped.prototype = original.prototype = proto;
824
+ addNonEnumerableProperty(wrapped, '__sentry_original__', original);
825
+ }
826
+ /**
827
+ * This extracts the original function if available. See
828
+ * `markFunctionWrapped` for more information.
829
+ *
830
+ * @param func the function to unwrap
831
+ * @returns the unwrapped version of the function if available.
832
+ */
833
+ function getOriginalFunction(func) {
834
+ return func.__sentry_original__;
835
+ }
921
836
  /**
922
837
  * Encodes given object into url-friendly format
923
838
  *
@@ -1018,11 +933,11 @@ var Sentry = (function (exports) {
1018
933
  * unchanged.
1019
934
  */
1020
935
  function serializeValue(value) {
1021
- var type = Object.prototype.toString.call(value);
1022
936
  // Node.js REPL notation
1023
937
  if (typeof value === 'string') {
1024
938
  return value;
1025
939
  }
940
+ var type = Object.prototype.toString.call(value);
1026
941
  if (type === '[object Object]') {
1027
942
  return '[Object]';
1028
943
  }
@@ -1094,8 +1009,8 @@ var Sentry = (function (exports) {
1094
1009
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1095
1010
  function walk(key, value, depth, memo) {
1096
1011
  if (depth === void 0) { depth = +Infinity; }
1097
- if (memo === void 0) { memo = new Memo(); }
1098
- // If we reach the maximum depth, serialize whatever has left
1012
+ if (memo === void 0) { memo = memoBuilder(); }
1013
+ // If we reach the maximum depth, serialize whatever is left
1099
1014
  if (depth === 0) {
1100
1015
  return serializeValue(value);
1101
1016
  }
@@ -1105,17 +1020,18 @@ var Sentry = (function (exports) {
1105
1020
  return value.toJSON();
1106
1021
  }
1107
1022
  /* eslint-enable @typescript-eslint/no-unsafe-member-access */
1108
- // If normalized value is a primitive, there are no branches left to walk, so we can just bail out, as theres no point in going down that branch any further
1023
+ // If normalized value is a primitive, there are no branches left to walk, so bail out
1109
1024
  var normalized = normalizeValue(value, key);
1110
1025
  if (isPrimitive(normalized)) {
1111
1026
  return normalized;
1112
1027
  }
1113
- // Create source that we will use for next itterations, either objectified error object (Error type with extracted keys:value pairs) or the input itself
1028
+ // Create source that we will use for the next iteration. It will either be an objectified error object (`Error` type
1029
+ // with extracted key:value pairs) or the input itself.
1114
1030
  var source = getWalkSource(value);
1115
1031
  // Create an accumulator that will act as a parent for all future itterations of that branch
1116
1032
  var acc = Array.isArray(value) ? [] : {};
1117
1033
  // If we already walked that branch, bail out, as it's circular reference
1118
- if (memo.memoize(value)) {
1034
+ if (memo[0](value)) {
1119
1035
  return '[Circular ~]';
1120
1036
  }
1121
1037
  // Walk all keys of the source
@@ -1128,7 +1044,7 @@ var Sentry = (function (exports) {
1128
1044
  acc[innerKey] = walk(innerKey, source[innerKey], depth - 1, memo);
1129
1045
  }
1130
1046
  // Once walked through all the branches, remove the parent from memo storage
1131
- memo.unmemoize(value);
1047
+ memo[1](value);
1132
1048
  // Return accumulated values
1133
1049
  return acc;
1134
1050
  }
@@ -1273,7 +1189,9 @@ var Sentry = (function (exports) {
1273
1189
  doc.head.removeChild(sandbox);
1274
1190
  }
1275
1191
  catch (err) {
1276
- logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', err);
1192
+ if (isDebugBuild()) {
1193
+ logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', err);
1194
+ }
1277
1195
  }
1278
1196
  }
1279
1197
  return result;
@@ -1285,9 +1203,9 @@ var Sentry = (function (exports) {
1285
1203
  * @returns Answer to the given question.
1286
1204
  */
1287
1205
  function supportsReferrerPolicy() {
1288
- // Despite all stars in the sky saying that Edge supports old draft syntax, aka 'never', 'always', 'origin' and 'default
1289
- // https://caniuse.com/#feat=referrer-policy
1290
- // It doesn't. And it throw exception instead of ignoring this parameter...
1206
+ // Despite all stars in the sky saying that Edge supports old draft syntax, aka 'never', 'always', 'origin' and 'default'
1207
+ // (see https://caniuse.com/#feat=referrer-policy),
1208
+ // it doesn't. And it throws an exception instead of ignoring this parameter...
1291
1209
  // REF: https://github.com/getsentry/raven-js/issues/1233
1292
1210
  if (!supportsFetch()) {
1293
1211
  return false;
@@ -1372,13 +1290,10 @@ var Sentry = (function (exports) {
1372
1290
  * Use at your own risk, this might break without changelog notice, only used internally.
1373
1291
  * @hidden
1374
1292
  */
1375
- function addInstrumentationHandler(handler) {
1376
- if (!handler || typeof handler.type !== 'string' || typeof handler.callback !== 'function') {
1377
- return;
1378
- }
1379
- handlers[handler.type] = handlers[handler.type] || [];
1380
- handlers[handler.type].push(handler.callback);
1381
- instrument(handler.type);
1293
+ function addInstrumentationHandler(type, callback) {
1294
+ handlers[type] = handlers[type] || [];
1295
+ handlers[type].push(callback);
1296
+ instrument(type);
1382
1297
  }
1383
1298
  /** JSDoc */
1384
1299
  function triggerHandlers(type, data) {
@@ -1393,7 +1308,9 @@ var Sentry = (function (exports) {
1393
1308
  handler(data);
1394
1309
  }
1395
1310
  catch (e) {
1396
- logger.error("Error while triggering instrumentation handler.\nType: " + type + "\nName: " + getFunctionName(handler) + "\nError: " + e);
1311
+ if (isDebugBuild()) {
1312
+ logger.error("Error while triggering instrumentation handler.\nType: " + type + "\nName: " + getFunctionName(handler) + "\nError: " + e);
1313
+ }
1397
1314
  }
1398
1315
  }
1399
1316
  }
@@ -1492,9 +1409,6 @@ var Sentry = (function (exports) {
1492
1409
  if (!('XMLHttpRequest' in global$2)) {
1493
1410
  return;
1494
1411
  }
1495
- // Poor man's implementation of ES6 `Map`, tracking and keeping in sync key and value separately.
1496
- var requestKeys = [];
1497
- var requestValues = [];
1498
1412
  var xhrproto = XMLHttpRequest.prototype;
1499
1413
  fill(xhrproto, 'open', function (originalOpen) {
1500
1414
  return function () {
@@ -1505,14 +1419,14 @@ var Sentry = (function (exports) {
1505
1419
  // eslint-disable-next-line @typescript-eslint/no-this-alias
1506
1420
  var xhr = this;
1507
1421
  var url = args[1];
1508
- xhr.__sentry_xhr__ = {
1422
+ var xhrInfo = (xhr.__sentry_xhr__ = {
1509
1423
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1510
1424
  method: isString(args[0]) ? args[0].toUpperCase() : args[0],
1511
1425
  url: args[1],
1512
- };
1426
+ });
1513
1427
  // if Sentry key appears in URL, don't capture it as a request
1514
1428
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1515
- if (isString(url) && xhr.__sentry_xhr__.method === 'POST' && url.match(/sentry_key/)) {
1429
+ if (isString(url) && xhrInfo.method === 'POST' && url.match(/sentry_key/)) {
1516
1430
  xhr.__sentry_own_request__ = true;
1517
1431
  }
1518
1432
  var onreadystatechangeHandler = function () {
@@ -1520,23 +1434,7 @@ var Sentry = (function (exports) {
1520
1434
  try {
1521
1435
  // touching statusCode in some platforms throws
1522
1436
  // an exception
1523
- if (xhr.__sentry_xhr__) {
1524
- xhr.__sentry_xhr__.status_code = xhr.status;
1525
- }
1526
- }
1527
- catch (e) {
1528
- /* do nothing */
1529
- }
1530
- try {
1531
- var requestPos = requestKeys.indexOf(xhr);
1532
- if (requestPos !== -1) {
1533
- // Make sure to pop both key and value to keep it in sync.
1534
- requestKeys.splice(requestPos);
1535
- var args_1 = requestValues.splice(requestPos)[0];
1536
- if (xhr.__sentry_xhr__ && args_1[0] !== undefined) {
1537
- xhr.__sentry_xhr__.body = args_1[0];
1538
- }
1539
- }
1437
+ xhrInfo.status_code = xhr.status;
1540
1438
  }
1541
1439
  catch (e) {
1542
1440
  /* do nothing */
@@ -1573,8 +1471,9 @@ var Sentry = (function (exports) {
1573
1471
  for (var _i = 0; _i < arguments.length; _i++) {
1574
1472
  args[_i] = arguments[_i];
1575
1473
  }
1576
- requestKeys.push(this);
1577
- requestValues.push(args);
1474
+ if (this.__sentry_xhr__ && args[0] !== undefined) {
1475
+ this.__sentry_xhr__.body = args[0];
1476
+ }
1578
1477
  triggerHandlers('xhr', {
1579
1478
  args: args,
1580
1479
  startTimestamp: Date.now(),
@@ -1918,22 +1817,26 @@ var Sentry = (function (exports) {
1918
1817
  relative: match[5] + query + fragment,
1919
1818
  };
1920
1819
  }
1820
+ function getFirstException(event) {
1821
+ return event.exception && event.exception.values ? event.exception.values[0] : undefined;
1822
+ }
1921
1823
  /**
1922
1824
  * Extracts either message or type+value from an event that can be used for user-facing logs
1923
1825
  * @returns event's description
1924
1826
  */
1925
1827
  function getEventDescription(event) {
1926
- if (event.message) {
1927
- return event.message;
1828
+ var message = event.message, eventId = event.event_id;
1829
+ if (message) {
1830
+ return message;
1928
1831
  }
1929
- if (event.exception && event.exception.values && event.exception.values[0]) {
1930
- var exception = event.exception.values[0];
1931
- if (exception.type && exception.value) {
1932
- return exception.type + ": " + exception.value;
1832
+ var firstException = getFirstException(event);
1833
+ if (firstException) {
1834
+ if (firstException.type && firstException.value) {
1835
+ return firstException.type + ": " + firstException.value;
1933
1836
  }
1934
- return exception.type || exception.value || event.event_id || '<unknown>';
1837
+ return firstException.type || firstException.value || eventId || '<unknown>';
1935
1838
  }
1936
- return event.event_id || '<unknown>';
1839
+ return eventId || '<unknown>';
1937
1840
  }
1938
1841
  /**
1939
1842
  * Adds exception values, type and value to an synthetic Exception.
@@ -1943,11 +1846,15 @@ var Sentry = (function (exports) {
1943
1846
  * @hidden
1944
1847
  */
1945
1848
  function addExceptionTypeValue(event, value, type) {
1946
- event.exception = event.exception || {};
1947
- event.exception.values = event.exception.values || [];
1948
- event.exception.values[0] = event.exception.values[0] || {};
1949
- event.exception.values[0].value = event.exception.values[0].value || value || '';
1950
- event.exception.values[0].type = event.exception.values[0].type || type || 'Error';
1849
+ var exception = (event.exception = event.exception || {});
1850
+ var values = (exception.values = exception.values || []);
1851
+ var firstException = (values[0] = values[0] || {});
1852
+ if (!firstException.value) {
1853
+ firstException.value = value || '';
1854
+ }
1855
+ if (!firstException.type) {
1856
+ firstException.type = type || 'Error';
1857
+ }
1951
1858
  }
1952
1859
  /**
1953
1860
  * Adds exception mechanism data to a given event. Uses defaults if the second parameter is not passed.
@@ -1957,17 +1864,16 @@ var Sentry = (function (exports) {
1957
1864
  * @hidden
1958
1865
  */
1959
1866
  function addExceptionMechanism(event, newMechanism) {
1960
- var _a;
1961
- if (!event.exception || !event.exception.values) {
1867
+ var firstException = getFirstException(event);
1868
+ if (!firstException) {
1962
1869
  return;
1963
1870
  }
1964
- var exceptionValue0 = event.exception.values[0];
1965
1871
  var defaultMechanism = { type: 'generic', handled: true };
1966
- var currentMechanism = exceptionValue0.mechanism;
1967
- exceptionValue0.mechanism = __assign(__assign(__assign({}, defaultMechanism), currentMechanism), newMechanism);
1872
+ var currentMechanism = firstException.mechanism;
1873
+ firstException.mechanism = __assign(__assign(__assign({}, defaultMechanism), currentMechanism), newMechanism);
1968
1874
  if (newMechanism && 'data' in newMechanism) {
1969
- var mergedData = __assign(__assign({}, (_a = currentMechanism) === null || _a === void 0 ? void 0 : _a.data), newMechanism.data);
1970
- exceptionValue0.mechanism.data = mergedData;
1875
+ var mergedData = __assign(__assign({}, (currentMechanism && currentMechanism.data)), newMechanism.data);
1876
+ firstException.mechanism.data = mergedData;
1971
1877
  }
1972
1878
  }
1973
1879
  var defaultRetryAfter = 60 * 1000; // 60 seconds
@@ -2012,17 +1918,14 @@ var Sentry = (function (exports) {
2012
1918
  * @returns `true` if the exception has already been captured, `false` if not (with the side effect of marking it seen)
2013
1919
  */
2014
1920
  function checkOrSetAlreadyCaught(exception) {
2015
- var _a;
2016
1921
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
2017
- if ((_a = exception) === null || _a === void 0 ? void 0 : _a.__sentry_captured__) {
1922
+ if (exception && exception.__sentry_captured__) {
2018
1923
  return true;
2019
1924
  }
2020
1925
  try {
2021
1926
  // set it this way rather than by assignment so that it's not ennumerable and therefore isn't recorded by the
2022
1927
  // `ExtraErrorData` integration
2023
- Object.defineProperty(exception, '__sentry_captured__', {
2024
- value: true,
2025
- });
1928
+ addNonEnumerableProperty(exception, '__sentry_captured__', true);
2026
1929
  }
2027
1930
  catch (err) {
2028
1931
  // `exception` is a primitive, so we can't mark it seen
@@ -2031,16 +1934,28 @@ var Sentry = (function (exports) {
2031
1934
  }
2032
1935
 
2033
1936
  /* eslint-disable @typescript-eslint/explicit-function-return-type */
2034
- /** SyncPromise internal states */
2035
- var States;
2036
- (function (States) {
2037
- /** Pending */
2038
- States["PENDING"] = "PENDING";
2039
- /** Resolved / OK */
2040
- States["RESOLVED"] = "RESOLVED";
2041
- /** Rejected / Error */
2042
- States["REJECTED"] = "REJECTED";
2043
- })(States || (States = {}));
1937
+ /**
1938
+ * Creates a resolved sync promise.
1939
+ *
1940
+ * @param value the value to resolve the promise with
1941
+ * @returns the resolved sync promise
1942
+ */
1943
+ function resolvedSyncPromise(value) {
1944
+ return new SyncPromise(function (resolve) {
1945
+ resolve(value);
1946
+ });
1947
+ }
1948
+ /**
1949
+ * Creates a rejected sync promise.
1950
+ *
1951
+ * @param value the value to reject the promise with
1952
+ * @returns the rejected sync promise
1953
+ */
1954
+ function rejectedSyncPromise(reason) {
1955
+ return new SyncPromise(function (_, reject) {
1956
+ reject(reason);
1957
+ });
1958
+ }
2044
1959
  /**
2045
1960
  * Thenable class that behaves like a Promise and follows it's interface
2046
1961
  * but is not async internally
@@ -2048,19 +1963,19 @@ var Sentry = (function (exports) {
2048
1963
  var SyncPromise = /** @class */ (function () {
2049
1964
  function SyncPromise(executor) {
2050
1965
  var _this = this;
2051
- this._state = States.PENDING;
1966
+ this._state = 0 /* PENDING */;
2052
1967
  this._handlers = [];
2053
1968
  /** JSDoc */
2054
1969
  this._resolve = function (value) {
2055
- _this._setResult(States.RESOLVED, value);
1970
+ _this._setResult(1 /* RESOLVED */, value);
2056
1971
  };
2057
1972
  /** JSDoc */
2058
1973
  this._reject = function (reason) {
2059
- _this._setResult(States.REJECTED, reason);
1974
+ _this._setResult(2 /* REJECTED */, reason);
2060
1975
  };
2061
1976
  /** JSDoc */
2062
1977
  this._setResult = function (state, value) {
2063
- if (_this._state !== States.PENDING) {
1978
+ if (_this._state !== 0 /* PENDING */) {
2064
1979
  return;
2065
1980
  }
2066
1981
  if (isThenable(value)) {
@@ -2071,35 +1986,25 @@ var Sentry = (function (exports) {
2071
1986
  _this._value = value;
2072
1987
  _this._executeHandlers();
2073
1988
  };
2074
- // TODO: FIXME
2075
- /** JSDoc */
2076
- this._attachHandler = function (handler) {
2077
- _this._handlers = _this._handlers.concat(handler);
2078
- _this._executeHandlers();
2079
- };
2080
1989
  /** JSDoc */
2081
1990
  this._executeHandlers = function () {
2082
- if (_this._state === States.PENDING) {
1991
+ if (_this._state === 0 /* PENDING */) {
2083
1992
  return;
2084
1993
  }
2085
1994
  var cachedHandlers = _this._handlers.slice();
2086
1995
  _this._handlers = [];
2087
1996
  cachedHandlers.forEach(function (handler) {
2088
- if (handler.done) {
1997
+ if (handler[0]) {
2089
1998
  return;
2090
1999
  }
2091
- if (_this._state === States.RESOLVED) {
2092
- if (handler.onfulfilled) {
2093
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
2094
- handler.onfulfilled(_this._value);
2095
- }
2000
+ if (_this._state === 1 /* RESOLVED */) {
2001
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
2002
+ handler[1](_this._value);
2096
2003
  }
2097
- if (_this._state === States.REJECTED) {
2098
- if (handler.onrejected) {
2099
- handler.onrejected(_this._value);
2100
- }
2004
+ if (_this._state === 2 /* REJECTED */) {
2005
+ handler[2](_this._value);
2101
2006
  }
2102
- handler.done = true;
2007
+ handler[0] = true;
2103
2008
  });
2104
2009
  };
2105
2010
  try {
@@ -2110,81 +2015,41 @@ var Sentry = (function (exports) {
2110
2015
  }
2111
2016
  }
2112
2017
  /** JSDoc */
2113
- SyncPromise.resolve = function (value) {
2114
- return new SyncPromise(function (resolve) {
2115
- resolve(value);
2116
- });
2117
- };
2118
- /** JSDoc */
2119
- SyncPromise.reject = function (reason) {
2120
- return new SyncPromise(function (_, reject) {
2121
- reject(reason);
2122
- });
2123
- };
2124
- /** JSDoc */
2125
- SyncPromise.all = function (collection) {
2126
- return new SyncPromise(function (resolve, reject) {
2127
- if (!Array.isArray(collection)) {
2128
- reject(new TypeError("Promise.all requires an array as input."));
2129
- return;
2130
- }
2131
- if (collection.length === 0) {
2132
- resolve([]);
2133
- return;
2134
- }
2135
- var counter = collection.length;
2136
- var resolvedCollection = [];
2137
- collection.forEach(function (item, index) {
2138
- void SyncPromise.resolve(item)
2139
- .then(function (value) {
2140
- resolvedCollection[index] = value;
2141
- counter -= 1;
2142
- if (counter !== 0) {
2143
- return;
2144
- }
2145
- resolve(resolvedCollection);
2146
- })
2147
- .then(null, reject);
2148
- });
2149
- });
2150
- };
2151
- /** JSDoc */
2152
2018
  SyncPromise.prototype.then = function (onfulfilled, onrejected) {
2153
2019
  var _this = this;
2154
2020
  return new SyncPromise(function (resolve, reject) {
2155
- _this._attachHandler({
2156
- done: false,
2157
- onfulfilled: function (result) {
2021
+ _this._handlers.push([
2022
+ false,
2023
+ function (result) {
2158
2024
  if (!onfulfilled) {
2159
2025
  // TODO: ¯\_(ツ)_/¯
2160
2026
  // TODO: FIXME
2161
2027
  resolve(result);
2162
- return;
2163
- }
2164
- try {
2165
- resolve(onfulfilled(result));
2166
- return;
2167
2028
  }
2168
- catch (e) {
2169
- reject(e);
2170
- return;
2029
+ else {
2030
+ try {
2031
+ resolve(onfulfilled(result));
2032
+ }
2033
+ catch (e) {
2034
+ reject(e);
2035
+ }
2171
2036
  }
2172
2037
  },
2173
- onrejected: function (reason) {
2038
+ function (reason) {
2174
2039
  if (!onrejected) {
2175
2040
  reject(reason);
2176
- return;
2177
2041
  }
2178
- try {
2179
- resolve(onrejected(reason));
2180
- return;
2181
- }
2182
- catch (e) {
2183
- reject(e);
2184
- return;
2042
+ else {
2043
+ try {
2044
+ resolve(onrejected(reason));
2045
+ }
2046
+ catch (e) {
2047
+ reject(e);
2048
+ }
2185
2049
  }
2186
2050
  },
2187
- });
2051
+ ]);
2052
+ _this._executeHandlers();
2188
2053
  });
2189
2054
  };
2190
2055
  /** JSDoc */
@@ -2218,26 +2083,27 @@ var Sentry = (function (exports) {
2218
2083
  });
2219
2084
  });
2220
2085
  };
2221
- /** JSDoc */
2222
- SyncPromise.prototype.toString = function () {
2223
- return '[object SyncPromise]';
2224
- };
2225
2086
  return SyncPromise;
2226
2087
  }());
2227
2088
 
2228
- /** A simple queue that holds promises. */
2229
- var PromiseBuffer = /** @class */ (function () {
2230
- function PromiseBuffer(_limit) {
2231
- this._limit = _limit;
2232
- /** Internal set of queued Promises */
2233
- this._buffer = [];
2089
+ /**
2090
+ * Creates an new PromiseBuffer object with the specified limit
2091
+ * @param limit max number of promises that can be stored in the buffer
2092
+ */
2093
+ function makePromiseBuffer(limit) {
2094
+ var buffer = [];
2095
+ function isReady() {
2096
+ return limit === undefined || buffer.length < limit;
2234
2097
  }
2235
2098
  /**
2236
- * Says if the buffer is ready to take more requests
2099
+ * Remove a promise from the queue.
2100
+ *
2101
+ * @param task Can be any PromiseLike<T>
2102
+ * @returns Removed promise.
2237
2103
  */
2238
- PromiseBuffer.prototype.isReady = function () {
2239
- return this._limit === undefined || this.length() < this._limit;
2240
- };
2104
+ function remove(task) {
2105
+ return buffer.splice(buffer.indexOf(task), 1)[0];
2106
+ }
2241
2107
  /**
2242
2108
  * Add a promise (representing an in-flight action) to the queue, and set it to remove itself on fulfillment.
2243
2109
  *
@@ -2248,44 +2114,27 @@ var Sentry = (function (exports) {
2248
2114
  * limit check.
2249
2115
  * @returns The original promise.
2250
2116
  */
2251
- PromiseBuffer.prototype.add = function (taskProducer) {
2252
- var _this = this;
2253
- if (!this.isReady()) {
2254
- return SyncPromise.reject(new SentryError('Not adding Promise due to buffer limit reached.'));
2117
+ function add(taskProducer) {
2118
+ if (!isReady()) {
2119
+ return rejectedSyncPromise(new SentryError('Not adding Promise due to buffer limit reached.'));
2255
2120
  }
2256
2121
  // start the task and add its promise to the queue
2257
2122
  var task = taskProducer();
2258
- if (this._buffer.indexOf(task) === -1) {
2259
- this._buffer.push(task);
2123
+ if (buffer.indexOf(task) === -1) {
2124
+ buffer.push(task);
2260
2125
  }
2261
2126
  void task
2262
- .then(function () { return _this.remove(task); })
2127
+ .then(function () { return remove(task); })
2263
2128
  // Use `then(null, rejectionHandler)` rather than `catch(rejectionHandler)` so that we can use `PromiseLike`
2264
2129
  // rather than `Promise`. `PromiseLike` doesn't have a `.catch` method, making its polyfill smaller. (ES5 didn't
2265
2130
  // have promises, so TS has to polyfill when down-compiling.)
2266
2131
  .then(null, function () {
2267
- return _this.remove(task).then(null, function () {
2268
- // We have to add another catch here because `this.remove()` starts a new promise chain.
2132
+ return remove(task).then(null, function () {
2133
+ // We have to add another catch here because `remove()` starts a new promise chain.
2269
2134
  });
2270
2135
  });
2271
2136
  return task;
2272
- };
2273
- /**
2274
- * Remove a promise from the queue.
2275
- *
2276
- * @param task Can be any PromiseLike<T>
2277
- * @returns Removed promise.
2278
- */
2279
- PromiseBuffer.prototype.remove = function (task) {
2280
- var removedTask = this._buffer.splice(this._buffer.indexOf(task), 1)[0];
2281
- return removedTask;
2282
- };
2283
- /**
2284
- * This function returns the number of unresolved promises in the queue.
2285
- */
2286
- PromiseBuffer.prototype.length = function () {
2287
- return this._buffer.length;
2288
- };
2137
+ }
2289
2138
  /**
2290
2139
  * Wait for all promises in the queue to resolve or for timeout to expire, whichever comes first.
2291
2140
  *
@@ -2295,9 +2144,12 @@ var Sentry = (function (exports) {
2295
2144
  * @returns A promise which will resolve to `true` if the queue is already empty or drains before the timeout, and
2296
2145
  * `false` otherwise
2297
2146
  */
2298
- PromiseBuffer.prototype.drain = function (timeout) {
2299
- var _this = this;
2300
- return new SyncPromise(function (resolve) {
2147
+ function drain(timeout) {
2148
+ return new SyncPromise(function (resolve, reject) {
2149
+ var counter = buffer.length;
2150
+ if (!counter) {
2151
+ return resolve(true);
2152
+ }
2301
2153
  // wait for `timeout` ms and then resolve to `false` (if not cancelled first)
2302
2154
  var capturedSetTimeout = setTimeout(function () {
2303
2155
  if (timeout && timeout > 0) {
@@ -2305,18 +2157,63 @@ var Sentry = (function (exports) {
2305
2157
  }
2306
2158
  }, timeout);
2307
2159
  // if all promises resolve in time, cancel the timer and resolve to `true`
2308
- void SyncPromise.all(_this._buffer)
2309
- .then(function () {
2310
- clearTimeout(capturedSetTimeout);
2311
- resolve(true);
2312
- })
2313
- .then(null, function () {
2314
- resolve(true);
2160
+ buffer.forEach(function (item) {
2161
+ void resolvedSyncPromise(item).then(function () {
2162
+ // eslint-disable-next-line no-plusplus
2163
+ if (!--counter) {
2164
+ clearTimeout(capturedSetTimeout);
2165
+ resolve(true);
2166
+ }
2167
+ }, reject);
2315
2168
  });
2316
2169
  });
2170
+ }
2171
+ return {
2172
+ $: buffer,
2173
+ add: add,
2174
+ drain: drain,
2317
2175
  };
2318
- return PromiseBuffer;
2319
- }());
2176
+ }
2177
+
2178
+ function isSupportedSeverity(level) {
2179
+ return SeverityLevels.indexOf(level) !== -1;
2180
+ }
2181
+ /**
2182
+ * Converts a string-based level into a {@link Severity}.
2183
+ *
2184
+ * @param level string representation of Severity
2185
+ * @returns Severity
2186
+ */
2187
+ function severityFromString(level) {
2188
+ if (level === 'warn')
2189
+ return exports.Severity.Warning;
2190
+ if (isSupportedSeverity(level)) {
2191
+ return level;
2192
+ }
2193
+ return exports.Severity.Log;
2194
+ }
2195
+
2196
+ /**
2197
+ * Converts an HTTP status code to sentry status {@link EventStatus}.
2198
+ *
2199
+ * @param code number HTTP status code
2200
+ * @returns EventStatus
2201
+ */
2202
+ function eventStatusFromHttpCode(code) {
2203
+ if (code >= 200 && code < 300) {
2204
+ return 'success';
2205
+ }
2206
+ if (code === 429) {
2207
+ return 'rate_limit';
2208
+ }
2209
+ if (code >= 400 && code < 500) {
2210
+ return 'invalid';
2211
+ }
2212
+ if (code >= 500) {
2213
+ return 'failed';
2214
+ }
2215
+ return 'unknown';
2216
+ }
2320
2217
 
2321
2218
  /**
2322
2219
  * A TimestampSource implementation for environments that do not support the Performance Web API natively.
@@ -2474,6 +2371,11 @@ var Sentry = (function (exports) {
2474
2371
  this._extra = {};
2475
2372
  /** Contexts */
2476
2373
  this._contexts = {};
2374
+ /**
2375
+ * A place to stash data which is needed at some point in the SDK's event processing pipeline but which shouldn't get
2376
+ * sent to Sentry
2377
+ */
2378
+ this._sdkProcessingMetadata = {};
2477
2379
  }
2478
2380
  /**
2479
2381
  * Inherit values from the parent scope.
@@ -2639,19 +2541,10 @@ var Sentry = (function (exports) {
2639
2541
  * @inheritDoc
2640
2542
  */
2641
2543
  Scope.prototype.getTransaction = function () {
2642
- var _a, _b, _c, _d;
2643
- // often, this span will be a transaction, but it's not guaranteed to be
2544
+ // Often, this span (if it exists at all) will be a transaction, but it's not guaranteed to be. Regardless, it will
2545
+ // have a pointer to the currently-active transaction.
2644
2546
  var span = this.getSpan();
2645
- // try it the new way first
2646
- if ((_a = span) === null || _a === void 0 ? void 0 : _a.transaction) {
2647
- return (_b = span) === null || _b === void 0 ? void 0 : _b.transaction;
2648
- }
2649
- // fallback to the old way (known bug: this only finds transactions with sampled = true)
2650
- if ((_d = (_c = span) === null || _c === void 0 ? void 0 : _c.spanRecorder) === null || _d === void 0 ? void 0 : _d.spans[0]) {
2651
- return span.spanRecorder.spans[0];
2652
- }
2653
- // neither way found a transaction
2654
- return undefined;
2547
+ return span && span.transaction;
2655
2548
  };
2656
2549
  /**
2657
2550
  * @inheritDoc
@@ -2770,7 +2663,6 @@ var Sentry = (function (exports) {
2770
2663
  * @hidden
2771
2664
  */
2772
2665
  Scope.prototype.applyToEvent = function (event, hint) {
2773
- var _a;
2774
2666
  if (this._extra && Object.keys(this._extra).length) {
2775
2667
  event.extra = __assign(__assign({}, this._extra), event.extra);
2776
2668
  }
@@ -2794,7 +2686,7 @@ var Sentry = (function (exports) {
2794
2686
  // errors with transaction and it relies on that.
2795
2687
  if (this._span) {
2796
2688
  event.contexts = __assign({ trace: this._span.getTraceContext() }, event.contexts);
2797
- var transactionName = (_a = this._span.transaction) === null || _a === void 0 ? void 0 : _a.name;
2689
+ var transactionName = this._span.transaction && this._span.transaction.name;
2798
2690
  if (transactionName) {
2799
2691
  event.tags = __assign({ transaction: transactionName }, event.tags);
2800
2692
  }
@@ -2802,8 +2694,16 @@ var Sentry = (function (exports) {
2802
2694
  this._applyFingerprint(event);
2803
2695
  event.breadcrumbs = __spread((event.breadcrumbs || []), this._breadcrumbs);
2804
2696
  event.breadcrumbs = event.breadcrumbs.length > 0 ? event.breadcrumbs : undefined;
2697
+ event.sdkProcessingMetadata = this._sdkProcessingMetadata;
2805
2698
  return this._notifyEventProcessors(__spread(getGlobalEventProcessors(), this._eventProcessors), event, hint);
2806
2699
  };
2700
+ /**
2701
+ * Add data which will be accessible during event processing but won't get sent to Sentry
2702
+ */
2703
+ Scope.prototype.setSDKProcessingMetadata = function (newData) {
2704
+ this._sdkProcessingMetadata = __assign(__assign({}, this._sdkProcessingMetadata), newData);
2705
+ return this;
2706
+ };
2807
2707
  /**
2808
2708
  * This will be called after {@link applyToEvent} is finished.
2809
2709
  */
@@ -2895,7 +2795,7 @@ var Sentry = (function (exports) {
2895
2795
  this.errors = 0;
2896
2796
  this.sid = uuid4();
2897
2797
  this.duration = 0;
2898
- this.status = SessionStatus.Ok;
2798
+ this.status = 'ok';
2899
2799
  this.init = true;
2900
2800
  this.ignoreDuration = false;
2901
2801
  // Both timestamp and started are in seconds since the UNIX epoch.
@@ -2969,8 +2869,8 @@ var Sentry = (function (exports) {
2969
2869
  if (status) {
2970
2870
  this.update({ status: status });
2971
2871
  }
2972
- else if (this.status === SessionStatus.Ok) {
2973
- this.update({ status: SessionStatus.Exited });
2872
+ else if (this.status === 'ok') {
2873
+ this.update({ status: 'exited' });
2974
2874
  }
2975
2875
  else {
2976
2876
  this.update();
@@ -2988,12 +2888,12 @@ var Sentry = (function (exports) {
2988
2888
  errors: this.errors,
2989
2889
  did: typeof this.did === 'number' || typeof this.did === 'string' ? "" + this.did : undefined,
2990
2890
  duration: this.duration,
2991
- attrs: dropUndefinedKeys({
2891
+ attrs: {
2992
2892
  release: this.release,
2993
2893
  environment: this.environment,
2994
2894
  ip_address: this.ipAddress,
2995
2895
  user_agent: this.userAgent,
2996
- }),
2896
+ },
2997
2897
  });
2998
2898
  };
2999
2899
  return Session;
@@ -3311,11 +3211,17 @@ var Sentry = (function (exports) {
3311
3211
  * @inheritDoc
3312
3212
  */
3313
3213
  Hub.prototype.endSession = function () {
3314
- var _a, _b, _c, _d, _e;
3315
- (_c = (_b = (_a = this.getStackTop()) === null || _a === void 0 ? void 0 : _a.scope) === null || _b === void 0 ? void 0 : _b.getSession()) === null || _c === void 0 ? void 0 : _c.close();
3214
+ var layer = this.getStackTop();
3215
+ var scope = layer && layer.scope;
3216
+ var session = scope && scope.getSession();
3217
+ if (session) {
3218
+ session.close();
3219
+ }
3316
3220
  this._sendSessionUpdate();
3317
3221
  // the session is over; take it off of the scope
3318
- (_e = (_d = this.getStackTop()) === null || _d === void 0 ? void 0 : _d.scope) === null || _e === void 0 ? void 0 : _e.setSession();
3222
+ if (scope) {
3223
+ scope.setSession();
3224
+ }
3319
3225
  };
3320
3226
  /**
3321
3227
  * @inheritDoc
@@ -3331,8 +3237,8 @@ var Sentry = (function (exports) {
3331
3237
  if (scope) {
3332
3238
  // End existing session if there's one
3333
3239
  var currentSession = scope.getSession && scope.getSession();
3334
- if (currentSession && currentSession.status === SessionStatus.Ok) {
3335
- currentSession.update({ status: SessionStatus.Exited });
3240
+ if (currentSession && currentSession.status === 'ok') {
3241
+ currentSession.update({ status: 'exited' });
3336
3242
  }
3337
3243
  this.endSession();
3338
3244
  // Afterwards we set the new session on the scope
@@ -3444,9 +3350,9 @@ var Sentry = (function (exports) {
3444
3350
  * @returns discovered hub
3445
3351
  */
3446
3352
  function getHubFromActiveDomain(registry) {
3447
- var _a, _b, _c;
3448
3353
  try {
3449
- var activeDomain = (_c = (_b = (_a = getMainCarrier().__SENTRY__) === null || _a === void 0 ? void 0 : _a.extensions) === null || _b === void 0 ? void 0 : _b.domain) === null || _c === void 0 ? void 0 : _c.active;
3354
+ var sentry = getMainCarrier().__SENTRY__;
3355
+ var activeDomain = sentry && sentry.extensions && sentry.extensions.domain && sentry.extensions.domain.active;
3450
3356
  // If there's no active domain, just return global hub
3451
3357
  if (!activeDomain) {
3452
3358
  return getHubFromCarrier(registry);
@@ -3541,7 +3447,7 @@ var Sentry = (function (exports) {
3541
3447
  * Captures a message event and sends it to Sentry.
3542
3448
  *
3543
3449
  * @param message The message to send to Sentry.
3544
- * @param level Define the level of the message.
3450
+ * @param Severity Define the level of the message.
3545
3451
  * @returns The generated eventId.
3546
3452
  */
3547
3453
  function captureMessage(message, captureContext) {
@@ -3673,138 +3579,84 @@ var Sentry = (function (exports) {
3673
3579
  }
3674
3580
 
3675
3581
  var SENTRY_API_VERSION = '7';
3676
- /**
3677
- * Helper class to provide urls, headers and metadata that can be used to form
3678
- * different types of requests to Sentry endpoints.
3679
- * Supports both envelopes and regular event requests.
3680
- **/
3681
- var API = /** @class */ (function () {
3682
- /** Create a new instance of API */
3683
- function API(dsn, metadata, tunnel) {
3684
- if (metadata === void 0) { metadata = {}; }
3685
- this.dsn = dsn;
3686
- this._dsnObject = new Dsn(dsn);
3687
- this.metadata = metadata;
3688
- this._tunnel = tunnel;
3689
- }
3690
- /** Returns the Dsn object. */
3691
- API.prototype.getDsn = function () {
3692
- return this._dsnObject;
3693
- };
3694
- /** Does this transport force envelopes? */
3695
- API.prototype.forceEnvelope = function () {
3696
- return !!this._tunnel;
3697
- };
3698
- /** Returns the prefix to construct Sentry ingestion API endpoints. */
3699
- API.prototype.getBaseApiEndpoint = function () {
3700
- var dsn = this.getDsn();
3701
- var protocol = dsn.protocol ? dsn.protocol + ":" : '';
3702
- var port = dsn.port ? ":" + dsn.port : '';
3703
- return protocol + "//" + dsn.host + port + (dsn.path ? "/" + dsn.path : '') + "/api/";
3704
- };
3705
- /** Returns the store endpoint URL. */
3706
- API.prototype.getStoreEndpoint = function () {
3707
- return this._getIngestEndpoint('store');
3708
- };
3709
- /**
3710
- * Returns the store endpoint URL with auth in the query string.
3711
- *
3712
- * Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
3713
- */
3714
- API.prototype.getStoreEndpointWithUrlEncodedAuth = function () {
3715
- return this.getStoreEndpoint() + "?" + this._encodedAuth();
3716
- };
3717
- /**
3718
- * Returns the envelope endpoint URL with auth in the query string.
3719
- *
3720
- * Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
3721
- */
3722
- API.prototype.getEnvelopeEndpointWithUrlEncodedAuth = function () {
3723
- if (this.forceEnvelope()) {
3724
- return this._tunnel;
3725
- }
3726
- return this._getEnvelopeEndpoint() + "?" + this._encodedAuth();
3727
- };
3728
- /** Returns only the path component for the store endpoint. */
3729
- API.prototype.getStoreEndpointPath = function () {
3730
- var dsn = this.getDsn();
3731
- return (dsn.path ? "/" + dsn.path : '') + "/api/" + dsn.projectId + "/store/";
3582
+ /** Initializes API Details */
3583
+ function initAPIDetails(dsn, metadata, tunnel) {
3584
+ return {
3585
+ initDsn: dsn,
3586
+ metadata: metadata || {},
3587
+ dsn: makeDsn(dsn),
3588
+ tunnel: tunnel,
3732
3589
  };
3733
- /**
3734
- * Returns an object that can be used in request headers.
3735
- * This is needed for node and the old /store endpoint in sentry
3736
- */
3737
- API.prototype.getRequestHeaders = function (clientName, clientVersion) {
3738
- // CHANGE THIS to use metadata but keep clientName and clientVersion compatible
3739
- var dsn = this.getDsn();
3740
- var header = ["Sentry sentry_version=" + SENTRY_API_VERSION];
3741
- header.push("sentry_client=" + clientName + "/" + clientVersion);
3742
- header.push("sentry_key=" + dsn.publicKey);
3743
- if (dsn.pass) {
3744
- header.push("sentry_secret=" + dsn.pass);
3745
- }
3746
- return {
3747
- 'Content-Type': 'application/json',
3748
- 'X-Sentry-Auth': header.join(', '),
3749
- };
3750
- };
3751
- /** Returns the url to the report dialog endpoint. */
3752
- API.prototype.getReportDialogEndpoint = function (dialogOptions) {
3753
- if (dialogOptions === void 0) { dialogOptions = {}; }
3754
- var dsn = this.getDsn();
3755
- var endpoint = this.getBaseApiEndpoint() + "embed/error-page/";
3756
- var encodedOptions = [];
3757
- encodedOptions.push("dsn=" + dsn.toString());
3758
- for (var key in dialogOptions) {
3759
- if (key === 'dsn') {
3590
+ }
3591
+ /** Returns the prefix to construct Sentry ingestion API endpoints. */
3592
+ function getBaseApiEndpoint(dsn) {
3593
+ var protocol = dsn.protocol ? dsn.protocol + ":" : '';
3594
+ var port = dsn.port ? ":" + dsn.port : '';
3595
+ return protocol + "//" + dsn.host + port + (dsn.path ? "/" + dsn.path : '') + "/api/";
3596
+ }
3597
+ /** Returns the ingest API endpoint for target. */
3598
+ function _getIngestEndpoint(dsn, target) {
3599
+ return "" + getBaseApiEndpoint(dsn) + dsn.projectId + "/" + target + "/";
3600
+ }
3601
+ /** Returns a URL-encoded string with auth config suitable for a query string. */
3602
+ function _encodedAuth(dsn) {
3603
+ return urlEncode({
3604
+ // We send only the minimum set of required information. See
3605
+ // https://github.com/getsentry/sentry-javascript/issues/2572.
3606
+ sentry_key: dsn.publicKey,
3607
+ sentry_version: SENTRY_API_VERSION,
3608
+ });
3609
+ }
3610
+ /** Returns the store endpoint URL. */
3611
+ function getStoreEndpoint(dsn) {
3612
+ return _getIngestEndpoint(dsn, 'store');
3613
+ }
3614
+ /**
3615
+ * Returns the store endpoint URL with auth in the query string.
3616
+ *
3617
+ * Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
3618
+ */
3619
+ function getStoreEndpointWithUrlEncodedAuth(dsn) {
3620
+ return getStoreEndpoint(dsn) + "?" + _encodedAuth(dsn);
3621
+ }
3622
+ /** Returns the envelope endpoint URL. */
3623
+ function _getEnvelopeEndpoint(dsn) {
3624
+ return _getIngestEndpoint(dsn, 'envelope');
3625
+ }
3626
+ /**
3627
+ * Returns the envelope endpoint URL with auth in the query string.
3628
+ *
3629
+ * Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
3630
+ */
3631
+ function getEnvelopeEndpointWithUrlEncodedAuth(dsn, tunnel) {
3632
+ return tunnel ? tunnel : _getEnvelopeEndpoint(dsn) + "?" + _encodedAuth(dsn);
3633
+ }
3634
+ /** Returns the url to the report dialog endpoint. */
3635
+ function getReportDialogEndpoint(dsnLike, dialogOptions) {
3636
+ var dsn = makeDsn(dsnLike);
3637
+ var endpoint = getBaseApiEndpoint(dsn) + "embed/error-page/";
3638
+ var encodedOptions = "dsn=" + dsnToString(dsn);
3639
+ for (var key in dialogOptions) {
3640
+ if (key === 'dsn') {
3641
+ continue;
3642
+ }
3643
+ if (key === 'user') {
3644
+ if (!dialogOptions.user) {
3760
3645
  continue;
3761
3646
  }
3762
- if (key === 'user') {
3763
- if (!dialogOptions.user) {
3764
- continue;
3765
- }
3766
- if (dialogOptions.user.name) {
3767
- encodedOptions.push("name=" + encodeURIComponent(dialogOptions.user.name));
3768
- }
3769
- if (dialogOptions.user.email) {
3770
- encodedOptions.push("email=" + encodeURIComponent(dialogOptions.user.email));
3771
- }
3647
+ if (dialogOptions.user.name) {
3648
+ encodedOptions += "&name=" + encodeURIComponent(dialogOptions.user.name);
3772
3649
  }
3773
- else {
3774
- encodedOptions.push(encodeURIComponent(key) + "=" + encodeURIComponent(dialogOptions[key]));
3650
+ if (dialogOptions.user.email) {
3651
+ encodedOptions += "&email=" + encodeURIComponent(dialogOptions.user.email);
3775
3652
  }
3776
3653
  }
3777
- if (encodedOptions.length) {
3778
- return endpoint + "?" + encodedOptions.join('&');
3779
- }
3780
- return endpoint;
3781
- };
3782
- /** Returns the envelope endpoint URL. */
3783
- API.prototype._getEnvelopeEndpoint = function () {
3784
- return this._getIngestEndpoint('envelope');
3785
- };
3786
- /** Returns the ingest API endpoint for target. */
3787
- API.prototype._getIngestEndpoint = function (target) {
3788
- if (this._tunnel) {
3789
- return this._tunnel;
3654
+ else {
3655
+ encodedOptions += "&" + encodeURIComponent(key) + "=" + encodeURIComponent(dialogOptions[key]);
3790
3656
  }
3791
- var base = this.getBaseApiEndpoint();
3792
- var dsn = this.getDsn();
3793
- return "" + base + dsn.projectId + "/" + target + "/";
3794
- };
3795
- /** Returns a URL-encoded string with auth config suitable for a query string. */
3796
- API.prototype._encodedAuth = function () {
3797
- var dsn = this.getDsn();
3798
- var auth = {
3799
- // We send only the minimum set of required information. See
3800
- // https://github.com/getsentry/sentry-javascript/issues/2572.
3801
- sentry_key: dsn.publicKey,
3802
- sentry_version: SENTRY_API_VERSION,
3803
- };
3804
- return urlEncode(auth);
3805
- };
3806
- return API;
3807
- }());
3657
+ }
3658
+ return endpoint + "?" + encodedOptions;
3659
+ }
3808
3660
 
3809
3661
  var installedIntegrations = [];
3810
3662
  /**
@@ -3865,7 +3717,7 @@ var Sentry = (function (exports) {
3865
3717
  // set the `initialized` flag so we don't run through the process again unecessarily; use `Object.defineProperty`
3866
3718
  // because by default it creates a property which is nonenumerable, which we want since `initialized` shouldn't be
3867
3719
  // considered a member of the index the way the actual integrations are
3868
- Object.defineProperty(integrations, 'initialized', { value: true });
3720
+ addNonEnumerableProperty(integrations, 'initialized', true);
3869
3721
  return integrations;
3870
3722
  }
3871
3723
 
@@ -3917,7 +3769,7 @@ var Sentry = (function (exports) {
3917
3769
  this._backend = new backendClass(options);
3918
3770
  this._options = options;
3919
3771
  if (options.dsn) {
3920
- this._dsn = new Dsn(options.dsn);
3772
+ this._dsn = makeDsn(options.dsn);
3921
3773
  }
3922
3774
  }
3923
3775
  /**
@@ -3960,9 +3812,8 @@ var Sentry = (function (exports) {
3960
3812
  * @inheritDoc
3961
3813
  */
3962
3814
  BaseClient.prototype.captureEvent = function (event, hint, scope) {
3963
- var _a;
3964
3815
  // ensure we haven't captured this very object before
3965
- if (((_a = hint) === null || _a === void 0 ? void 0 : _a.originalException) && checkOrSetAlreadyCaught(hint.originalException)) {
3816
+ if (hint && hint.originalException && checkOrSetAlreadyCaught(hint.originalException)) {
3966
3817
  logger.log(ALREADY_SEEN_ERROR);
3967
3818
  return;
3968
3819
  }
@@ -3977,11 +3828,15 @@ var Sentry = (function (exports) {
3977
3828
  */
3978
3829
  BaseClient.prototype.captureSession = function (session) {
3979
3830
  if (!this._isEnabled()) {
3980
- logger.warn('SDK not enabled, will not capture session.');
3831
+ if (isDebugBuild()) {
3832
+ logger.warn('SDK not enabled, will not capture session.');
3833
+ }
3981
3834
  return;
3982
3835
  }
3983
3836
  if (!(typeof session.release === 'string')) {
3984
- logger.warn('Discarded session because of missing or non-string release');
3837
+ if (isDebugBuild()) {
3838
+ logger.warn('Discarded session because of missing or non-string release');
3839
+ }
3985
3840
  }
3986
3841
  else {
3987
3842
  this._sendSession(session);
@@ -4077,10 +3932,10 @@ var Sentry = (function (exports) {
4077
3932
  // A session is updated and that session update is sent in only one of the two following scenarios:
4078
3933
  // 1. Session with non terminal status and 0 errors + an error occurred -> Will set error count to 1 and send update
4079
3934
  // 2. Session with non terminal status and 1 error + a crash occurred -> Will set status crashed and send update
4080
- var sessionNonTerminal = session.status === SessionStatus.Ok;
3935
+ var sessionNonTerminal = session.status === 'ok';
4081
3936
  var shouldUpdateAndSend = (sessionNonTerminal && session.errors === 0) || (sessionNonTerminal && crashed);
4082
3937
  if (shouldUpdateAndSend) {
4083
- session.update(__assign(__assign({}, (crashed && { status: SessionStatus.Crashed })), { errors: session.errors || Number(errored || crashed) }));
3938
+ session.update(__assign(__assign({}, (crashed && { status: 'crashed' })), { errors: session.errors || Number(errored || crashed) }));
4084
3939
  this.captureSession(session);
4085
3940
  }
4086
3941
  };
@@ -4153,7 +4008,7 @@ var Sentry = (function (exports) {
4153
4008
  finalScope = Scope.clone(finalScope).update(hint.captureContext);
4154
4009
  }
4155
4010
  // We prepare the result here with a resolved Event.
4156
- var result = SyncPromise.resolve(prepared);
4011
+ var result = resolvedSyncPromise(prepared);
4157
4012
  // This should be the last thing called, since we want that
4158
4013
  // {@link Hub.addEventProcessor} gets the finished prepared event.
4159
4014
  if (finalScope) {
@@ -4286,26 +4141,29 @@ var Sentry = (function (exports) {
4286
4141
  */
4287
4142
  BaseClient.prototype._processEvent = function (event, hint, scope) {
4288
4143
  var _this = this;
4289
- var _a, _b;
4290
4144
  // eslint-disable-next-line @typescript-eslint/unbound-method
4291
- var _c = this.getOptions(), beforeSend = _c.beforeSend, sampleRate = _c.sampleRate;
4145
+ var _a = this.getOptions(), beforeSend = _a.beforeSend, sampleRate = _a.sampleRate;
4292
4146
  var transport = this.getTransport();
4147
+ function recordLostEvent(outcome, category) {
4148
+ if (transport.recordLostEvent) {
4149
+ transport.recordLostEvent(outcome, category);
4150
+ }
4151
+ }
4293
4152
  if (!this._isEnabled()) {
4294
- return SyncPromise.reject(new SentryError('SDK not enabled, will not capture event.'));
4153
+ return rejectedSyncPromise(new SentryError('SDK not enabled, will not capture event.'));
4295
4154
  }
4296
4155
  var isTransaction = event.type === 'transaction';
4297
4156
  // 1.0 === 100% events are sent
4298
4157
  // 0.0 === 0% events are sent
4299
4158
  // Sampling for transaction happens somewhere else
4300
4159
  if (!isTransaction && typeof sampleRate === 'number' && Math.random() > sampleRate) {
4301
- (_b = (_a = transport).recordLostEvent) === null || _b === void 0 ? void 0 : _b.call(_a, Outcome.SampleRate, 'event');
4302
- return SyncPromise.reject(new SentryError("Discarding event because it's not included in the random sample (sampling rate = " + sampleRate + ")"));
4160
+ recordLostEvent('sample_rate', 'event');
4161
+ return rejectedSyncPromise(new SentryError("Discarding event because it's not included in the random sample (sampling rate = " + sampleRate + ")"));
4303
4162
  }
4304
4163
  return this._prepareEvent(event, scope, hint)
4305
4164
  .then(function (prepared) {
4306
- var _a, _b;
4307
4165
  if (prepared === null) {
4308
- (_b = (_a = transport).recordLostEvent) === null || _b === void 0 ? void 0 : _b.call(_a, Outcome.EventProcessor, event.type || 'event');
4166
+ recordLostEvent('event_processor', event.type || 'event');
4309
4167
  throw new SentryError('An event processor returned null, will not send event.');
4310
4168
  }
4311
4169
  var isInternalException = hint && hint.data && hint.data.__sentry__ === true;
@@ -4313,12 +4171,11 @@ var Sentry = (function (exports) {
4313
4171
  return prepared;
4314
4172
  }
4315
4173
  var beforeSendResult = beforeSend(prepared, hint);
4316
- return _this._ensureBeforeSendRv(beforeSendResult);
4174
+ return _ensureBeforeSendRv(beforeSendResult);
4317
4175
  })
4318
4176
  .then(function (processedEvent) {
4319
- var _a, _b;
4320
4177
  if (processedEvent === null) {
4321
- (_b = (_a = transport).recordLostEvent) === null || _b === void 0 ? void 0 : _b.call(_a, Outcome.BeforeSend, event.type || 'event');
4178
+ recordLostEvent('before_send', event.type || 'event');
4322
4179
  throw new SentryError('`beforeSend` returned `null`, will not send event.');
4323
4180
  }
4324
4181
  var session = scope && scope.getSession && scope.getSession();
@@ -4355,28 +4212,28 @@ var Sentry = (function (exports) {
4355
4212
  return reason;
4356
4213
  });
4357
4214
  };
4358
- /**
4359
- * Verifies that return value of configured `beforeSend` is of expected type.
4360
- */
4361
- BaseClient.prototype._ensureBeforeSendRv = function (rv) {
4362
- var nullErr = '`beforeSend` method has to return `null` or a valid event.';
4363
- if (isThenable(rv)) {
4364
- return rv.then(function (event) {
4365
- if (!(isPlainObject(event) || event === null)) {
4366
- throw new SentryError(nullErr);
4367
- }
4368
- return event;
4369
- }, function (e) {
4370
- throw new SentryError("beforeSend rejected with " + e);
4371
- });
4372
- }
4373
- else if (!(isPlainObject(rv) || rv === null)) {
4374
- throw new SentryError(nullErr);
4375
- }
4376
- return rv;
4377
- };
4378
4215
  return BaseClient;
4379
- }());
4216
+ }());
4217
+ /**
4218
+ * Verifies that return value of configured `beforeSend` is of expected type.
4219
+ */
4220
+ function _ensureBeforeSendRv(rv) {
4221
+ var nullErr = '`beforeSend` method has to return `null` or a valid event.';
4222
+ if (isThenable(rv)) {
4223
+ return rv.then(function (event) {
4224
+ if (!(isPlainObject(event) || event === null)) {
4225
+ throw new SentryError(nullErr);
4226
+ }
4227
+ return event;
4228
+ }, function (e) {
4229
+ throw new SentryError("beforeSend rejected with " + e);
4230
+ });
4231
+ }
4232
+ else if (!(isPlainObject(rv) || rv === null)) {
4233
+ throw new SentryError(nullErr);
4234
+ }
4235
+ return rv;
4236
+ }
4380
4237
 
4381
4238
  /** Noop transport */
4382
4239
  var NoopTransport = /** @class */ (function () {
@@ -4386,16 +4243,16 @@ var Sentry = (function (exports) {
4386
4243
  * @inheritDoc
4387
4244
  */
4388
4245
  NoopTransport.prototype.sendEvent = function (_) {
4389
- return SyncPromise.resolve({
4246
+ return resolvedSyncPromise({
4390
4247
  reason: "NoopTransport: Event has been skipped because no Dsn is configured.",
4391
- status: exports.Status.Skipped,
4248
+ status: 'skipped',
4392
4249
  });
4393
4250
  };
4394
4251
  /**
4395
4252
  * @inheritDoc
4396
4253
  */
4397
4254
  NoopTransport.prototype.close = function (_) {
4398
- return SyncPromise.resolve(true);
4255
+ return resolvedSyncPromise(true);
4399
4256
  };
4400
4257
  return NoopTransport;
4401
4258
  }());
@@ -4431,7 +4288,9 @@ var Sentry = (function (exports) {
4431
4288
  */
4432
4289
  BaseBackend.prototype.sendEvent = function (event) {
4433
4290
  void this._transport.sendEvent(event).then(null, function (reason) {
4434
- logger.error("Error while sending event: " + reason);
4291
+ if (isDebugBuild()) {
4292
+ logger.error("Error while sending event: " + reason);
4293
+ }
4435
4294
  });
4436
4295
  };
4437
4296
  /**
@@ -4439,11 +4298,15 @@ var Sentry = (function (exports) {
4439
4298
  */
4440
4299
  BaseBackend.prototype.sendSession = function (session) {
4441
4300
  if (!this._transport.sendSession) {
4442
- logger.warn("Dropping session because custom transport doesn't implement sendSession");
4301
+ if (isDebugBuild()) {
4302
+ logger.warn("Dropping session because custom transport doesn't implement sendSession");
4303
+ }
4443
4304
  return;
4444
4305
  }
4445
4306
  void this._transport.sendSession(session).then(null, function (reason) {
4446
- logger.error("Error while sending session: " + reason);
4307
+ if (isDebugBuild()) {
4308
+ logger.error("Error while sending session: " + reason);
4309
+ }
4447
4310
  });
4448
4311
  };
4449
4312
  /**
@@ -4487,7 +4350,7 @@ var Sentry = (function (exports) {
4487
4350
  /** Creates a SentryRequest from a Session. */
4488
4351
  function sessionToSentryRequest(session, api) {
4489
4352
  var sdkInfo = getSdkMetadataForEnvelopeHeader(api);
4490
- var envelopeHeaders = JSON.stringify(__assign(__assign({ sent_at: new Date().toISOString() }, (sdkInfo && { sdk: sdkInfo })), (api.forceEnvelope() && { dsn: api.getDsn().toString() })));
4353
+ var envelopeHeaders = JSON.stringify(__assign(__assign({ sent_at: new Date().toISOString() }, (sdkInfo && { sdk: sdkInfo })), (!!api.tunnel && { dsn: dsnToString(api.dsn) })));
4491
4354
  // I know this is hacky but we don't want to add `session` to request type since it's never rate limited
4492
4355
  var type = 'aggregates' in session ? 'sessions' : 'session';
4493
4356
  var itemHeaders = JSON.stringify({
@@ -4496,26 +4359,24 @@ var Sentry = (function (exports) {
4496
4359
  return {
4497
4360
  body: envelopeHeaders + "\n" + itemHeaders + "\n" + JSON.stringify(session),
4498
4361
  type: type,
4499
- url: api.getEnvelopeEndpointWithUrlEncodedAuth(),
4362
+ url: getEnvelopeEndpointWithUrlEncodedAuth(api.dsn, api.tunnel),
4500
4363
  };
4501
4364
  }
4502
4365
  /** Creates a SentryRequest from an event. */
4503
4366
  function eventToSentryRequest(event, api) {
4504
4367
  var sdkInfo = getSdkMetadataForEnvelopeHeader(api);
4505
4368
  var eventType = event.type || 'event';
4506
- var useEnvelope = eventType === 'transaction' || api.forceEnvelope();
4507
- var _a = event.debug_meta || {}, transactionSampling = _a.transactionSampling, metadata = __rest(_a, ["transactionSampling"]);
4508
- var _b = transactionSampling || {}, samplingMethod = _b.method, sampleRate = _b.rate;
4509
- if (Object.keys(metadata).length === 0) {
4510
- delete event.debug_meta;
4511
- }
4512
- else {
4513
- event.debug_meta = metadata;
4514
- }
4369
+ var useEnvelope = eventType === 'transaction' || !!api.tunnel;
4370
+ var transactionSampling = (event.sdkProcessingMetadata || {}).transactionSampling;
4371
+ var _a = transactionSampling || {}, samplingMethod = _a.method, sampleRate = _a.rate;
4372
+ // prevent this data from being sent to sentry
4373
+ delete event.sdkProcessingMetadata;
4515
4374
  var req = {
4516
4375
  body: JSON.stringify(sdkInfo ? enhanceEventWithSdkInfo(event, api.metadata.sdk) : event),
4517
4376
  type: eventType,
4518
- url: useEnvelope ? api.getEnvelopeEndpointWithUrlEncodedAuth() : api.getStoreEndpointWithUrlEncodedAuth(),
4377
+ url: useEnvelope
4378
+ ? getEnvelopeEndpointWithUrlEncodedAuth(api.dsn, api.tunnel)
4379
+ : getStoreEndpointWithUrlEncodedAuth(api.dsn),
4519
4380
  };
4520
4381
  // https://develop.sentry.dev/sdk/envelopes/
4521
4382
  // Since we don't need to manipulate envelopes nor store them, there is no
@@ -4523,7 +4384,7 @@ var Sentry = (function (exports) {
4523
4384
  // deserialization. Instead, we only implement a minimal subset of the spec to
4524
4385
  // serialize events inline here.
4525
4386
  if (useEnvelope) {
4526
- var envelopeHeaders = JSON.stringify(__assign(__assign({ event_id: event.event_id, sent_at: new Date().toISOString() }, (sdkInfo && { sdk: sdkInfo })), (api.forceEnvelope() && { dsn: api.getDsn().toString() })));
4387
+ var envelopeHeaders = JSON.stringify(__assign(__assign({ event_id: event.event_id, sent_at: new Date().toISOString() }, (sdkInfo && { sdk: sdkInfo })), (!!api.tunnel && { dsn: dsnToString(api.dsn) })));
4527
4388
  var itemHeaders = JSON.stringify({
4528
4389
  type: eventType,
4529
4390
  // TODO: Right now, sampleRate may or may not be defined (it won't be in the cases of inheritance and
@@ -4548,17 +4409,19 @@ var Sentry = (function (exports) {
4548
4409
  * @param options Options to pass to the client.
4549
4410
  */
4550
4411
  function initAndBind(clientClass, options) {
4551
- var _a;
4552
4412
  if (options.debug === true) {
4553
4413
  logger.enable();
4554
4414
  }
4555
4415
  var hub = getCurrentHub();
4556
- (_a = hub.getScope()) === null || _a === void 0 ? void 0 : _a.update(options.initialScope);
4416
+ var scope = hub.getScope();
4417
+ if (scope) {
4418
+ scope.update(options.initialScope);
4419
+ }
4557
4420
  var client = new clientClass(options);
4558
4421
  hub.bindClient(client);
4559
4422
  }
4560
4423
 
4561
- var SDK_VERSION = '6.15.0';
4424
+ var SDK_VERSION = '6.17.0';
4562
4425
 
4563
4426
  var originalFunctionToString;
4564
4427
  /** Patch toString calls to return proper name for wrapped functions */
@@ -4581,7 +4444,7 @@ var Sentry = (function (exports) {
4581
4444
  for (var _i = 0; _i < arguments.length; _i++) {
4582
4445
  args[_i] = arguments[_i];
4583
4446
  }
4584
- var context = this.__sentry_original__ || this;
4447
+ var context = getOriginalFunction(this) || this;
4585
4448
  return originalFunctionToString.apply(context, args);
4586
4449
  };
4587
4450
  };
@@ -4635,19 +4498,27 @@ var Sentry = (function (exports) {
4635
4498
  /** JSDoc */
4636
4499
  InboundFilters.prototype._shouldDropEvent = function (event, options) {
4637
4500
  if (this._isSentryError(event, options)) {
4638
- logger.warn("Event dropped due to being internal Sentry Error.\nEvent: " + getEventDescription(event));
4501
+ if (isDebugBuild()) {
4502
+ logger.warn("Event dropped due to being internal Sentry Error.\nEvent: " + getEventDescription(event));
4503
+ }
4639
4504
  return true;
4640
4505
  }
4641
4506
  if (this._isIgnoredError(event, options)) {
4642
- logger.warn("Event dropped due to being matched by `ignoreErrors` option.\nEvent: " + getEventDescription(event));
4507
+ if (isDebugBuild()) {
4508
+ logger.warn("Event dropped due to being matched by `ignoreErrors` option.\nEvent: " + getEventDescription(event));
4509
+ }
4643
4510
  return true;
4644
4511
  }
4645
4512
  if (this._isDeniedUrl(event, options)) {
4646
- logger.warn("Event dropped due to being matched by `denyUrls` option.\nEvent: " + getEventDescription(event) + ".\nUrl: " + this._getEventFilterUrl(event));
4513
+ if (isDebugBuild()) {
4514
+ logger.warn("Event dropped due to being matched by `denyUrls` option.\nEvent: " + getEventDescription(event) + ".\nUrl: " + this._getEventFilterUrl(event));
4515
+ }
4647
4516
  return true;
4648
4517
  }
4649
4518
  if (!this._isAllowedUrl(event, options)) {
4650
- logger.warn("Event dropped due to not being matched by `allowUrls` option.\nEvent: " + getEventDescription(event) + ".\nUrl: " + this._getEventFilterUrl(event));
4519
+ if (isDebugBuild()) {
4520
+ logger.warn("Event dropped due to not being matched by `allowUrls` option.\nEvent: " + getEventDescription(event) + ".\nUrl: " + this._getEventFilterUrl(event));
4521
+ }
4651
4522
  return true;
4652
4523
  }
4653
4524
  return false;
@@ -4658,16 +4529,14 @@ var Sentry = (function (exports) {
4658
4529
  return false;
4659
4530
  }
4660
4531
  try {
4661
- return ((event &&
4662
- event.exception &&
4663
- event.exception.values &&
4664
- event.exception.values[0] &&
4665
- event.exception.values[0].type === 'SentryError') ||
4666
- false);
4532
+ // @ts-ignore can't be a sentry error if undefined
4533
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
4534
+ return event.exception.values[0].type === 'SentryError';
4667
4535
  }
4668
- catch (_oO) {
4669
- return false;
4536
+ catch (e) {
4537
+ // ignore
4670
4538
  }
4539
+ return false;
4671
4540
  };
4672
4541
  /** JSDoc */
4673
4542
  InboundFilters.prototype._isIgnoredError = function (event, options) {
@@ -4718,7 +4587,9 @@ var Sentry = (function (exports) {
4718
4587
  return ["" + value, type + ": " + value];
4719
4588
  }
4720
4589
  catch (oO) {
4721
- logger.error("Cannot extract message for event " + getEventDescription(event));
4590
+ if (isDebugBuild()) {
4591
+ logger.error("Cannot extract message for event " + getEventDescription(event));
4592
+ }
4722
4593
  return [];
4723
4594
  }
4724
4595
  }
@@ -4727,10 +4598,9 @@ var Sentry = (function (exports) {
4727
4598
  /** JSDoc */
4728
4599
  InboundFilters.prototype._getLastValidUrl = function (frames) {
4729
4600
  if (frames === void 0) { frames = []; }
4730
- var _a, _b;
4731
4601
  for (var i = frames.length - 1; i >= 0; i--) {
4732
4602
  var frame = frames[i];
4733
- if (((_a = frame) === null || _a === void 0 ? void 0 : _a.filename) !== '<anonymous>' && ((_b = frame) === null || _b === void 0 ? void 0 : _b.filename) !== '[native code]') {
4603
+ if (frame && frame.filename !== '<anonymous>' && frame.filename !== '[native code]') {
4734
4604
  return frame.filename || null;
4735
4605
  }
4736
4606
  }
@@ -4740,17 +4610,22 @@ var Sentry = (function (exports) {
4740
4610
  InboundFilters.prototype._getEventFilterUrl = function (event) {
4741
4611
  try {
4742
4612
  if (event.stacktrace) {
4743
- var frames_1 = event.stacktrace.frames;
4744
- return this._getLastValidUrl(frames_1);
4613
+ return this._getLastValidUrl(event.stacktrace.frames);
4614
+ }
4615
+ var frames_1;
4616
+ try {
4617
+ // @ts-ignore we only care about frames if the whole thing here is defined
4618
+ frames_1 = event.exception.values[0].stacktrace.frames;
4745
4619
  }
4746
- if (event.exception) {
4747
- var frames_2 = event.exception.values && event.exception.values[0].stacktrace && event.exception.values[0].stacktrace.frames;
4748
- return this._getLastValidUrl(frames_2);
4620
+ catch (e) {
4621
+ // ignore
4749
4622
  }
4750
- return null;
4623
+ return frames_1 ? this._getLastValidUrl(frames_1) : null;
4751
4624
  }
4752
4625
  catch (oO) {
4753
- logger.error("Cannot extract url for event " + getEventDescription(event));
4626
+ if (isDebugBuild()) {
4627
+ logger.error("Cannot extract url for event " + getEventDescription(event));
4628
+ }
4754
4629
  return null;
4755
4630
  }
4756
4631
  };
@@ -5114,7 +4989,7 @@ var Sentry = (function (exports) {
5114
4989
  }
5115
4990
 
5116
4991
  /**
5117
- * Builds and Event from a Exception
4992
+ * Creates an {@link Event} from all inputs to `captureException` and non-primitive inputs to `captureMessage`.
5118
4993
  * @hidden
5119
4994
  */
5120
4995
  function eventFromException(options, exception, hint) {
@@ -5127,7 +5002,7 @@ var Sentry = (function (exports) {
5127
5002
  if (hint && hint.event_id) {
5128
5003
  event.event_id = hint.event_id;
5129
5004
  }
5130
- return SyncPromise.resolve(event);
5005
+ return resolvedSyncPromise(event);
5131
5006
  }
5132
5007
  /**
5133
5008
  * Builds and Event from a Message
@@ -5143,7 +5018,7 @@ var Sentry = (function (exports) {
5143
5018
  if (hint && hint.event_id) {
5144
5019
  event.event_id = hint.event_id;
5145
5020
  }
5146
- return SyncPromise.resolve(event);
5021
+ return resolvedSyncPromise(event);
5147
5022
  }
5148
5023
  /**
5149
5024
  * @hidden
@@ -5188,11 +5063,11 @@ var Sentry = (function (exports) {
5188
5063
  return event;
5189
5064
  }
5190
5065
  if (isPlainObject(exception) || isEvent(exception)) {
5191
- // If it is plain Object or Event, serialize it manually and extract options
5192
- // This will allow us to group events based on top-level keys
5193
- // which is much better than creating new group when any key/value change
5066
+ // If it's a plain object or an instance of `Event` (the built-in JS kind, not this SDK's `Event` type), serialize
5067
+ // it manually. This will allow us to group events based on top-level keys which is much better than creating a new
5068
+ // group on any key/value change.
5194
5069
  var objectException = exception;
5195
- event = eventFromPlainObject(objectException, syntheticException, options.rejection);
5070
+ event = eventFromPlainObject(objectException, syntheticException, options.isRejection);
5196
5071
  addExceptionMechanism(event, {
5197
5072
  synthetic: true,
5198
5073
  });
@@ -5273,7 +5148,6 @@ var Sentry = (function (exports) {
5273
5148
  * Safari: resource blocked by content blocker
5274
5149
  */
5275
5150
  function getNativeFetchImplementation() {
5276
- var _a, _b;
5277
5151
  if (cachedFetchImpl) {
5278
5152
  return cachedFetchImpl;
5279
5153
  }
@@ -5285,18 +5159,21 @@ var Sentry = (function (exports) {
5285
5159
  var document = global$3.document;
5286
5160
  var fetchImpl = global$3.fetch;
5287
5161
  // eslint-disable-next-line deprecation/deprecation
5288
- if (typeof ((_a = document) === null || _a === void 0 ? void 0 : _a.createElement) === "function") {
5162
+ if (document && typeof document.createElement === "function") {
5289
5163
  try {
5290
5164
  var sandbox = document.createElement('iframe');
5291
5165
  sandbox.hidden = true;
5292
5166
  document.head.appendChild(sandbox);
5293
- if ((_b = sandbox.contentWindow) === null || _b === void 0 ? void 0 : _b.fetch) {
5294
- fetchImpl = sandbox.contentWindow.fetch;
5167
+ var contentWindow = sandbox.contentWindow;
5168
+ if (contentWindow && contentWindow.fetch) {
5169
+ fetchImpl = contentWindow.fetch;
5295
5170
  }
5296
5171
  document.head.removeChild(sandbox);
5297
5172
  }
5298
5173
  catch (e) {
5299
- logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', e);
5174
+ if (isDebugBuild()) {
5175
+ logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', e);
5176
+ }
5300
5177
  }
5301
5178
  }
5302
5179
  return (cachedFetchImpl = fetchImpl.bind(global$3));
@@ -5327,12 +5204,10 @@ var Sentry = (function (exports) {
5327
5204
  }
5328
5205
  }
5329
5206
 
5330
- var CATEGORY_MAPPING = {
5331
- event: 'error',
5332
- transaction: 'transaction',
5333
- session: 'session',
5334
- attachment: 'attachment',
5335
- };
5207
+ function requestTypeToCategory(ty) {
5208
+ var tyStr = ty;
5209
+ return tyStr === 'event' ? 'error' : tyStr;
5210
+ }
5336
5211
  var global$4 = getGlobalObject();
5337
5212
  /** Base Transport class implementation */
5338
5213
  var BaseTransport = /** @class */ (function () {
@@ -5340,13 +5215,13 @@ var Sentry = (function (exports) {
5340
5215
  var _this = this;
5341
5216
  this.options = options;
5342
5217
  /** A simple buffer holding all requests. */
5343
- this._buffer = new PromiseBuffer(30);
5218
+ this._buffer = makePromiseBuffer(30);
5344
5219
  /** Locks transport after receiving rate limits in a response */
5345
5220
  this._rateLimits = {};
5346
5221
  this._outcomes = {};
5347
- this._api = new API(options.dsn, options._metadata, options.tunnel);
5222
+ this._api = initAPIDetails(options.dsn, options._metadata, options.tunnel);
5348
5223
  // eslint-disable-next-line deprecation/deprecation
5349
- this.url = this._api.getStoreEndpointWithUrlEncodedAuth();
5224
+ this.url = getStoreEndpointWithUrlEncodedAuth(this._api.dsn);
5350
5225
  if (this.options.sendClientReports && global$4.document) {
5351
5226
  global$4.document.addEventListener('visibilitychange', function () {
5352
5227
  if (global$4.document.visibilityState === 'hidden') {
@@ -5358,8 +5233,14 @@ var Sentry = (function (exports) {
5358
5233
  /**
5359
5234
  * @inheritDoc
5360
5235
  */
5361
- BaseTransport.prototype.sendEvent = function (_) {
5362
- throw new SentryError('Transport Class has to implement `sendEvent` method');
5236
+ BaseTransport.prototype.sendEvent = function (event) {
5237
+ return this._sendRequest(eventToSentryRequest(event, this._api), event);
5238
+ };
5239
+ /**
5240
+ * @inheritDoc
5241
+ */
5242
+ BaseTransport.prototype.sendSession = function (session) {
5243
+ return this._sendRequest(sessionToSentryRequest(session, this._api), session);
5363
5244
  };
5364
5245
  /**
5365
5246
  * @inheritDoc
@@ -5380,7 +5261,7 @@ var Sentry = (function (exports) {
5380
5261
  // We could use nested maps, but it's much easier to read and type this way.
5381
5262
  // A correct type for map-based implementation if we want to go that route
5382
5263
  // would be `Partial<Record<SentryRequestType, Partial<Record<Outcome, number>>>>`
5383
- var key = CATEGORY_MAPPING[category] + ":" + reason;
5264
+ var key = requestTypeToCategory(category) + ":" + reason;
5384
5265
  logger.log("Adding outcome: " + key);
5385
5266
  this._outcomes[key] = (_a = this._outcomes[key], (_a !== null && _a !== void 0 ? _a : 0)) + 1;
5386
5267
  };
@@ -5399,9 +5280,9 @@ var Sentry = (function (exports) {
5399
5280
  return;
5400
5281
  }
5401
5282
  logger.log("Flushing outcomes:\n" + JSON.stringify(outcomes, null, 2));
5402
- var url = this._api.getEnvelopeEndpointWithUrlEncodedAuth();
5283
+ var url = getEnvelopeEndpointWithUrlEncodedAuth(this._api.dsn, this._api.tunnel);
5403
5284
  // Envelope header is required to be at least an empty object
5404
- var envelopeHeader = JSON.stringify(__assign({}, (this.options.tunnel && { dsn: this._api.getDsn().toString() })));
5285
+ var envelopeHeader = JSON.stringify(__assign({}, (this._api.tunnel && { dsn: dsnToString(this._api.dsn) })));
5405
5286
  var itemHeaders = JSON.stringify({
5406
5287
  type: 'client_report',
5407
5288
  });
@@ -5429,15 +5310,16 @@ var Sentry = (function (exports) {
5429
5310
  */
5430
5311
  BaseTransport.prototype._handleResponse = function (_a) {
5431
5312
  var requestType = _a.requestType, response = _a.response, headers = _a.headers, resolve = _a.resolve, reject = _a.reject;
5432
- var status = exports.Status.fromHttpCode(response.status);
5313
+ var status = eventStatusFromHttpCode(response.status);
5433
5314
  /**
5434
5315
  * "The name is case-insensitive."
5435
5316
  * https://developer.mozilla.org/en-US/docs/Web/API/Headers/get
5436
5317
  */
5437
5318
  var limited = this._handleRateLimit(headers);
5438
- if (limited)
5319
+ if (limited && isDebugBuild()) {
5439
5320
  logger.warn("Too many " + requestType + " requests, backing off until: " + this._disabledUntil(requestType));
5440
- if (status === exports.Status.Success) {
5321
+ }
5322
+ if (status === 'success') {
5441
5323
  resolve({ status: status });
5442
5324
  return;
5443
5325
  }
@@ -5447,7 +5329,7 @@ var Sentry = (function (exports) {
5447
5329
  * Gets the time that given category is disabled until for rate limiting
5448
5330
  */
5449
5331
  BaseTransport.prototype._disabledUntil = function (requestType) {
5450
- var category = CATEGORY_MAPPING[requestType];
5332
+ var category = requestTypeToCategory(requestType);
5451
5333
  return this._rateLimits[category] || this._rateLimits.all;
5452
5334
  };
5453
5335
  /**
@@ -5523,18 +5405,6 @@ var Sentry = (function (exports) {
5523
5405
  _this._fetch = fetchImpl;
5524
5406
  return _this;
5525
5407
  }
5526
- /**
5527
- * @inheritDoc
5528
- */
5529
- FetchTransport.prototype.sendEvent = function (event) {
5530
- return this._sendRequest(eventToSentryRequest(event, this._api), event);
5531
- };
5532
- /**
5533
- * @inheritDoc
5534
- */
5535
- FetchTransport.prototype.sendSession = function (session) {
5536
- return this._sendRequest(sessionToSentryRequest(session, this._api), session);
5537
- };
5538
5408
  /**
5539
5409
  * @param sentryRequest Prepared SentryRequest to be delivered
5540
5410
  * @param originalPayload Original payload used to create SentryRequest
@@ -5542,7 +5412,7 @@ var Sentry = (function (exports) {
5542
5412
  FetchTransport.prototype._sendRequest = function (sentryRequest, originalPayload) {
5543
5413
  var _this = this;
5544
5414
  if (this._isRateLimited(sentryRequest.type)) {
5545
- this.recordLostEvent(Outcome.RateLimitBackoff, sentryRequest.type);
5415
+ this.recordLostEvent('ratelimit_backoff', sentryRequest.type);
5546
5416
  return Promise.reject({
5547
5417
  event: originalPayload,
5548
5418
  type: sentryRequest.type,
@@ -5553,9 +5423,9 @@ var Sentry = (function (exports) {
5553
5423
  var options = {
5554
5424
  body: sentryRequest.body,
5555
5425
  method: 'POST',
5556
- // Despite all stars in the sky saying that Edge supports old draft syntax, aka 'never', 'always', 'origin' and 'default
5557
- // https://caniuse.com/#feat=referrer-policy
5558
- // It doesn't. And it throw exception instead of ignoring this parameter...
5426
+ // Despite all stars in the sky saying that Edge supports old draft syntax, aka 'never', 'always', 'origin' and 'default'
5427
+ // (see https://caniuse.com/#feat=referrer-policy),
5428
+ // it doesn't. And it throws an exception instead of ignoring this parameter...
5559
5429
  // REF: https://github.com/getsentry/raven-js/issues/1233
5560
5430
  referrerPolicy: (supportsReferrerPolicy() ? 'origin' : ''),
5561
5431
  };
@@ -5588,10 +5458,10 @@ var Sentry = (function (exports) {
5588
5458
  .then(undefined, function (reason) {
5589
5459
  // It's either buffer rejection or any other xhr/fetch error, which are treated as NetworkError.
5590
5460
  if (reason instanceof SentryError) {
5591
- _this.recordLostEvent(Outcome.QueueOverflow, sentryRequest.type);
5461
+ _this.recordLostEvent('queue_overflow', sentryRequest.type);
5592
5462
  }
5593
5463
  else {
5594
- _this.recordLostEvent(Outcome.NetworkError, sentryRequest.type);
5464
+ _this.recordLostEvent('network_error', sentryRequest.type);
5595
5465
  }
5596
5466
  throw reason;
5597
5467
  });
@@ -5605,18 +5475,6 @@ var Sentry = (function (exports) {
5605
5475
  function XHRTransport() {
5606
5476
  return _super !== null && _super.apply(this, arguments) || this;
5607
5477
  }
5608
- /**
5609
- * @inheritDoc
5610
- */
5611
- XHRTransport.prototype.sendEvent = function (event) {
5612
- return this._sendRequest(eventToSentryRequest(event, this._api), event);
5613
- };
5614
- /**
5615
- * @inheritDoc
5616
- */
5617
- XHRTransport.prototype.sendSession = function (session) {
5618
- return this._sendRequest(sessionToSentryRequest(session, this._api), session);
5619
- };
5620
5478
  /**
5621
5479
  * @param sentryRequest Prepared SentryRequest to be delivered
5622
5480
  * @param originalPayload Original payload used to create SentryRequest
@@ -5624,7 +5482,7 @@ var Sentry = (function (exports) {
5624
5482
  XHRTransport.prototype._sendRequest = function (sentryRequest, originalPayload) {
5625
5483
  var _this = this;
5626
5484
  if (this._isRateLimited(sentryRequest.type)) {
5627
- this.recordLostEvent(Outcome.RateLimitBackoff, sentryRequest.type);
5485
+ this.recordLostEvent('ratelimit_backoff', sentryRequest.type);
5628
5486
  return Promise.reject({
5629
5487
  event: originalPayload,
5630
5488
  type: sentryRequest.type,
@@ -5657,10 +5515,10 @@ var Sentry = (function (exports) {
5657
5515
  .then(undefined, function (reason) {
5658
5516
  // It's either buffer rejection or any other xhr/fetch error, which are treated as NetworkError.
5659
5517
  if (reason instanceof SentryError) {
5660
- _this.recordLostEvent(Outcome.QueueOverflow, sentryRequest.type);
5518
+ _this.recordLostEvent('queue_overflow', sentryRequest.type);
5661
5519
  }
5662
5520
  else {
5663
- _this.recordLostEvent(Outcome.NetworkError, sentryRequest.type);
5521
+ _this.recordLostEvent('network_error', sentryRequest.type);
5664
5522
  }
5665
5523
  throw reason;
5666
5524
  });
@@ -5746,19 +5604,27 @@ var Sentry = (function (exports) {
5746
5604
  * @hidden
5747
5605
  */
5748
5606
  function wrap(fn, options, before) {
5607
+ // for future readers what this does is wrap a function and then create
5608
+ // a bi-directional wrapping between them.
5609
+ //
5610
+ // example: wrapped = wrap(original);
5611
+ // original.__sentry_wrapped__ -> wrapped
5612
+ // wrapped.__sentry_original__ -> original
5749
5613
  if (options === void 0) { options = {}; }
5750
5614
  if (typeof fn !== 'function') {
5751
5615
  return fn;
5752
5616
  }
5753
5617
  try {
5618
+ // if we're dealing with a function that was previously wrapped, return
5619
+ // the original wrapper.
5620
+ var wrapper = fn.__sentry_wrapped__;
5621
+ if (wrapper) {
5622
+ return wrapper;
5623
+ }
5754
5624
  // We don't wanna wrap it twice
5755
- if (fn.__sentry__) {
5625
+ if (getOriginalFunction(fn)) {
5756
5626
  return fn;
5757
5627
  }
5758
- // If this has already been wrapped in the past, return that wrapped function
5759
- if (fn.__sentry_wrapped__) {
5760
- return fn.__sentry_wrapped__;
5761
- }
5762
5628
  }
5763
5629
  catch (e) {
5764
5630
  // Just accessing custom props in some Selenium environments
@@ -5776,14 +5642,6 @@ var Sentry = (function (exports) {
5776
5642
  }
5777
5643
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
5778
5644
  var wrappedArguments = args.map(function (arg) { return wrap(arg, options); });
5779
- if (fn.handleEvent) {
5780
- // Attempt to invoke user-land function
5781
- // NOTE: If you are a Sentry user, and you are seeing this stack frame, it
5782
- // means the sentry.javascript SDK caught an error invoking your application code. This
5783
- // is expected behavior and NOT indicative of a bug with sentry.javascript.
5784
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
5785
- return fn.handleEvent.apply(this, wrappedArguments);
5786
- }
5787
5645
  // Attempt to invoke user-land function
5788
5646
  // NOTE: If you are a Sentry user, and you are seeing this stack frame, it
5789
5647
  // means the sentry.javascript SDK caught an error invoking your application code. This
@@ -5794,13 +5652,12 @@ var Sentry = (function (exports) {
5794
5652
  ignoreNextOnError();
5795
5653
  withScope(function (scope) {
5796
5654
  scope.addEventProcessor(function (event) {
5797
- var processedEvent = __assign({}, event);
5798
5655
  if (options.mechanism) {
5799
- addExceptionTypeValue(processedEvent, undefined, undefined);
5800
- addExceptionMechanism(processedEvent, options.mechanism);
5656
+ addExceptionTypeValue(event, undefined, undefined);
5657
+ addExceptionMechanism(event, options.mechanism);
5801
5658
  }
5802
- processedEvent.extra = __assign(__assign({}, processedEvent.extra), { arguments: args });
5803
- return processedEvent;
5659
+ event.extra = __assign(__assign({}, event.extra), { arguments: args });
5660
+ return event;
5804
5661
  });
5805
5662
  captureException(ex);
5806
5663
  });
@@ -5818,24 +5675,10 @@ var Sentry = (function (exports) {
5818
5675
  }
5819
5676
  }
5820
5677
  catch (_oO) { } // eslint-disable-line no-empty
5821
- fn.prototype = fn.prototype || {};
5822
- sentryWrapped.prototype = fn.prototype;
5823
- Object.defineProperty(fn, '__sentry_wrapped__', {
5824
- enumerable: false,
5825
- value: sentryWrapped,
5826
- });
5827
5678
  // Signal that this function has been wrapped/filled already
5828
5679
  // for both debugging and to prevent it to being wrapped/filled twice
5829
- Object.defineProperties(sentryWrapped, {
5830
- __sentry__: {
5831
- enumerable: false,
5832
- value: true,
5833
- },
5834
- __sentry_original__: {
5835
- enumerable: false,
5836
- value: fn,
5837
- },
5838
- });
5680
+ markFunctionWrapped(sentryWrapped, fn);
5681
+ addNonEnumerableProperty(fn, '__sentry_wrapped__', sentryWrapped);
5839
5682
  // Restore original function name (not all browsers allow that)
5840
5683
  try {
5841
5684
  var descriptor = Object.getOwnPropertyDescriptor(sentryWrapped, 'name');
@@ -5861,16 +5704,20 @@ var Sentry = (function (exports) {
5861
5704
  return;
5862
5705
  }
5863
5706
  if (!options.eventId) {
5864
- logger.error("Missing eventId option in showReportDialog call");
5707
+ if (isDebugBuild()) {
5708
+ logger.error("Missing eventId option in showReportDialog call");
5709
+ }
5865
5710
  return;
5866
5711
  }
5867
5712
  if (!options.dsn) {
5868
- logger.error("Missing dsn option in showReportDialog call");
5713
+ if (isDebugBuild()) {
5714
+ logger.error("Missing dsn option in showReportDialog call");
5715
+ }
5869
5716
  return;
5870
5717
  }
5871
5718
  var script = global$5.document.createElement('script');
5872
5719
  script.async = true;
5873
- script.src = new API(options.dsn).getReportDialogEndpoint(options);
5720
+ script.src = getReportDialogEndpoint(options.dsn, options);
5874
5721
  if (options.onLoad) {
5875
5722
  // eslint-disable-next-line @typescript-eslint/unbound-method
5876
5723
  script.onload = options.onLoad;
@@ -5889,10 +5736,14 @@ var Sentry = (function (exports) {
5889
5736
  * @inheritDoc
5890
5737
  */
5891
5738
  this.name = GlobalHandlers.id;
5892
- /** JSDoc */
5893
- this._onErrorHandlerInstalled = false;
5894
- /** JSDoc */
5895
- this._onUnhandledRejectionHandlerInstalled = false;
5739
+ /**
5740
+ * Stores references functions to installing handlers. Will set to undefined
5741
+ * after they have been run so that they are not used twice.
5742
+ */
5743
+ this._installFunc = {
5744
+ onerror: _installGlobalOnErrorHandler,
5745
+ onunhandledrejection: _installGlobalOnUnhandledRejectionHandler,
5746
+ };
5896
5747
  this._options = __assign({ onerror: true, onunhandledrejection: true }, options);
5897
5748
  }
5898
5749
  /**
@@ -5900,179 +5751,183 @@ var Sentry = (function (exports) {
5900
5751
  */
5901
5752
  GlobalHandlers.prototype.setupOnce = function () {
5902
5753
  Error.stackTraceLimit = 50;
5903
- if (this._options.onerror) {
5904
- logger.log('Global Handler attached: onerror');
5905
- this._installGlobalOnErrorHandler();
5906
- }
5907
- if (this._options.onunhandledrejection) {
5908
- logger.log('Global Handler attached: onunhandledrejection');
5909
- this._installGlobalOnUnhandledRejectionHandler();
5754
+ var options = this._options;
5755
+ // We can disable guard-for-in as we construct the options object above + do checks against
5756
+ // `this._installFunc` for the property.
5757
+ // eslint-disable-next-line guard-for-in
5758
+ for (var key in options) {
5759
+ var installFunc = this._installFunc[key];
5760
+ if (installFunc && options[key]) {
5761
+ globalHandlerLog(key);
5762
+ installFunc();
5763
+ this._installFunc[key] = undefined;
5764
+ }
5910
5765
  }
5911
5766
  };
5912
- /** JSDoc */
5913
- GlobalHandlers.prototype._installGlobalOnErrorHandler = function () {
5914
- var _this = this;
5915
- if (this._onErrorHandlerInstalled) {
5767
+ /**
5768
+ * @inheritDoc
5769
+ */
5770
+ GlobalHandlers.id = 'GlobalHandlers';
5771
+ return GlobalHandlers;
5772
+ }());
5773
+ /** JSDoc */
5774
+ function _installGlobalOnErrorHandler() {
5775
+ addInstrumentationHandler('error',
5776
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5777
+ function (data) {
5778
+ var _a = __read(getHubAndAttachStacktrace(), 2), hub = _a[0], attachStacktrace = _a[1];
5779
+ if (!hub.getIntegration(GlobalHandlers)) {
5916
5780
  return;
5917
5781
  }
5918
- addInstrumentationHandler({
5919
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
5920
- callback: function (data) {
5921
- var error = data.error;
5922
- var currentHub = getCurrentHub();
5923
- var hasIntegration = currentHub.getIntegration(GlobalHandlers);
5924
- var isFailedOwnDelivery = error && error.__sentry_own_request__ === true;
5925
- if (!hasIntegration || shouldIgnoreOnError() || isFailedOwnDelivery) {
5926
- return;
5927
- }
5928
- var client = currentHub.getClient();
5929
- var event = error === undefined && isString(data.msg)
5930
- ? _this._eventFromIncompleteOnError(data.msg, data.url, data.line, data.column)
5931
- : _this._enhanceEventWithInitialFrame(eventFromUnknownInput(error || data.msg, undefined, {
5932
- attachStacktrace: client && client.getOptions().attachStacktrace,
5933
- rejection: false,
5934
- }), data.url, data.line, data.column);
5935
- addExceptionMechanism(event, {
5936
- handled: false,
5937
- type: 'onerror',
5938
- });
5939
- currentHub.captureEvent(event, {
5940
- originalException: error,
5941
- });
5942
- },
5943
- type: 'error',
5944
- });
5945
- this._onErrorHandlerInstalled = true;
5946
- };
5947
- /** JSDoc */
5948
- GlobalHandlers.prototype._installGlobalOnUnhandledRejectionHandler = function () {
5949
- var _this = this;
5950
- if (this._onUnhandledRejectionHandlerInstalled) {
5782
+ var msg = data.msg, url = data.url, line = data.line, column = data.column, error = data.error;
5783
+ if (shouldIgnoreOnError() || (error && error.__sentry_own_request__)) {
5951
5784
  return;
5952
5785
  }
5953
- addInstrumentationHandler({
5954
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
5955
- callback: function (e) {
5956
- var error = e;
5957
- // dig the object of the rejection out of known event types
5958
- try {
5959
- // PromiseRejectionEvents store the object of the rejection under 'reason'
5960
- // see https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent
5961
- if ('reason' in e) {
5962
- error = e.reason;
5963
- }
5964
- // something, somewhere, (likely a browser extension) effectively casts PromiseRejectionEvents
5965
- // to CustomEvents, moving the `promise` and `reason` attributes of the PRE into
5966
- // the CustomEvent's `detail` attribute, since they're not part of CustomEvent's spec
5967
- // see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent and
5968
- // https://github.com/getsentry/sentry-javascript/issues/2380
5969
- else if ('detail' in e && 'reason' in e.detail) {
5970
- error = e.detail.reason;
5971
- }
5972
- }
5973
- catch (_oO) {
5974
- // no-empty
5975
- }
5976
- var currentHub = getCurrentHub();
5977
- var hasIntegration = currentHub.getIntegration(GlobalHandlers);
5978
- var isFailedOwnDelivery = error && error.__sentry_own_request__ === true;
5979
- if (!hasIntegration || shouldIgnoreOnError() || isFailedOwnDelivery) {
5980
- return true;
5981
- }
5982
- var client = currentHub.getClient();
5983
- var event = isPrimitive(error)
5984
- ? _this._eventFromRejectionWithPrimitive(error)
5985
- : eventFromUnknownInput(error, undefined, {
5986
- attachStacktrace: client && client.getOptions().attachStacktrace,
5987
- rejection: true,
5988
- });
5989
- event.level = exports.Severity.Error;
5990
- addExceptionMechanism(event, {
5991
- handled: false,
5992
- type: 'onunhandledrejection',
5993
- });
5994
- currentHub.captureEvent(event, {
5995
- originalException: error,
5996
- });
5997
- return;
5998
- },
5999
- type: 'unhandledrejection',
6000
- });
6001
- this._onUnhandledRejectionHandlerInstalled = true;
6002
- };
6003
- /**
6004
- * This function creates a stack from an old, error-less onerror handler.
6005
- */
6006
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6007
- GlobalHandlers.prototype._eventFromIncompleteOnError = function (msg, url, line, column) {
6008
- var ERROR_TYPES_RE = /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i;
6009
- // If 'message' is ErrorEvent, get real message from inside
6010
- var message = isErrorEvent(msg) ? msg.message : msg;
6011
- var name;
6012
- var groups = message.match(ERROR_TYPES_RE);
6013
- if (groups) {
6014
- name = groups[1];
6015
- message = groups[2];
6016
- }
6017
- var event = {
6018
- exception: {
6019
- values: [
6020
- {
6021
- type: name || 'Error',
6022
- value: message,
6023
- },
6024
- ],
6025
- },
6026
- };
6027
- return this._enhanceEventWithInitialFrame(event, url, line, column);
6028
- };
6029
- /**
6030
- * Create an event from a promise rejection where the `reason` is a primitive.
6031
- *
6032
- * @param reason: The `reason` property of the promise rejection
6033
- * @returns An Event object with an appropriate `exception` value
6034
- */
6035
- GlobalHandlers.prototype._eventFromRejectionWithPrimitive = function (reason) {
6036
- return {
6037
- exception: {
6038
- values: [
6039
- {
6040
- type: 'UnhandledRejection',
6041
- // String() is needed because the Primitive type includes symbols (which can't be automatically stringified)
6042
- value: "Non-Error promise rejection captured with value: " + String(reason),
6043
- },
6044
- ],
6045
- },
6046
- };
6047
- };
6048
- /** JSDoc */
5786
+ var event = error === undefined && isString(msg)
5787
+ ? _eventFromIncompleteOnError(msg, url, line, column)
5788
+ : _enhanceEventWithInitialFrame(eventFromUnknownInput(error || msg, undefined, {
5789
+ attachStacktrace: attachStacktrace,
5790
+ isRejection: false,
5791
+ }), url, line, column);
5792
+ addMechanismAndCapture(hub, error, event, 'onerror');
5793
+ });
5794
+ }
5795
+ /** JSDoc */
5796
+ function _installGlobalOnUnhandledRejectionHandler() {
5797
+ addInstrumentationHandler('unhandledrejection',
6049
5798
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6050
- GlobalHandlers.prototype._enhanceEventWithInitialFrame = function (event, url, line, column) {
6051
- event.exception = event.exception || {};
6052
- event.exception.values = event.exception.values || [];
6053
- event.exception.values[0] = event.exception.values[0] || {};
6054
- event.exception.values[0].stacktrace = event.exception.values[0].stacktrace || {};
6055
- event.exception.values[0].stacktrace.frames = event.exception.values[0].stacktrace.frames || [];
6056
- var colno = isNaN(parseInt(column, 10)) ? undefined : column;
6057
- var lineno = isNaN(parseInt(line, 10)) ? undefined : line;
6058
- var filename = isString(url) && url.length > 0 ? url : getLocationHref();
6059
- if (event.exception.values[0].stacktrace.frames.length === 0) {
6060
- event.exception.values[0].stacktrace.frames.push({
6061
- colno: colno,
6062
- filename: filename,
6063
- function: '?',
6064
- in_app: true,
6065
- lineno: lineno,
6066
- });
5799
+ function (e) {
5800
+ var _a = __read(getHubAndAttachStacktrace(), 2), hub = _a[0], attachStacktrace = _a[1];
5801
+ if (!hub.getIntegration(GlobalHandlers)) {
5802
+ return;
6067
5803
  }
6068
- return event;
5804
+ var error = e;
5805
+ // dig the object of the rejection out of known event types
5806
+ try {
5807
+ // PromiseRejectionEvents store the object of the rejection under 'reason'
5808
+ // see https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent
5809
+ if ('reason' in e) {
5810
+ error = e.reason;
5811
+ }
5812
+ // something, somewhere, (likely a browser extension) effectively casts PromiseRejectionEvents
5813
+ // to CustomEvents, moving the `promise` and `reason` attributes of the PRE into
5814
+ // the CustomEvent's `detail` attribute, since they're not part of CustomEvent's spec
5815
+ // see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent and
5816
+ // https://github.com/getsentry/sentry-javascript/issues/2380
5817
+ else if ('detail' in e && 'reason' in e.detail) {
5818
+ error = e.detail.reason;
5819
+ }
5820
+ }
5821
+ catch (_oO) {
5822
+ // no-empty
5823
+ }
5824
+ if (shouldIgnoreOnError() || (error && error.__sentry_own_request__)) {
5825
+ return true;
5826
+ }
5827
+ var event = isPrimitive(error)
5828
+ ? _eventFromRejectionWithPrimitive(error)
5829
+ : eventFromUnknownInput(error, undefined, {
5830
+ attachStacktrace: attachStacktrace,
5831
+ isRejection: true,
5832
+ });
5833
+ event.level = exports.Severity.Error;
5834
+ addMechanismAndCapture(hub, error, event, 'onunhandledrejection');
5835
+ return;
5836
+ });
5837
+ }
5838
+ /**
5839
+ * Create an event from a promise rejection where the `reason` is a primitive.
5840
+ *
5841
+ * @param reason: The `reason` property of the promise rejection
5842
+ * @returns An Event object with an appropriate `exception` value
5843
+ */
5844
+ function _eventFromRejectionWithPrimitive(reason) {
5845
+ return {
5846
+ exception: {
5847
+ values: [
5848
+ {
5849
+ type: 'UnhandledRejection',
5850
+ // String() is needed because the Primitive type includes symbols (which can't be automatically stringified)
5851
+ value: "Non-Error promise rejection captured with value: " + String(reason),
5852
+ },
5853
+ ],
5854
+ },
6069
5855
  };
6070
- /**
6071
- * @inheritDoc
6072
- */
6073
- GlobalHandlers.id = 'GlobalHandlers';
6074
- return GlobalHandlers;
6075
- }());
5856
+ }
5857
+ /**
5858
+ * This function creates a stack from an old, error-less onerror handler.
5859
+ */
5860
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5861
+ function _eventFromIncompleteOnError(msg, url, line, column) {
5862
+ var ERROR_TYPES_RE = /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i;
5863
+ // If 'message' is ErrorEvent, get real message from inside
5864
+ var message = isErrorEvent(msg) ? msg.message : msg;
5865
+ var name = 'Error';
5866
+ var groups = message.match(ERROR_TYPES_RE);
5867
+ if (groups) {
5868
+ name = groups[1];
5869
+ message = groups[2];
5870
+ }
5871
+ var event = {
5872
+ exception: {
5873
+ values: [
5874
+ {
5875
+ type: name,
5876
+ value: message,
5877
+ },
5878
+ ],
5879
+ },
5880
+ };
5881
+ return _enhanceEventWithInitialFrame(event, url, line, column);
5882
+ }
5883
+ /** JSDoc */
5884
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5885
+ function _enhanceEventWithInitialFrame(event, url, line, column) {
5886
+ // event.exception
5887
+ var e = (event.exception = event.exception || {});
5888
+ // event.exception.values
5889
+ var ev = (e.values = e.values || []);
5890
+ // event.exception.values[0]
5891
+ var ev0 = (ev[0] = ev[0] || {});
5892
+ // event.exception.values[0].stacktrace
5893
+ var ev0s = (ev0.stacktrace = ev0.stacktrace || {});
5894
+ // event.exception.values[0].stacktrace.frames
5895
+ var ev0sf = (ev0s.frames = ev0s.frames || []);
5896
+ var colno = isNaN(parseInt(column, 10)) ? undefined : column;
5897
+ var lineno = isNaN(parseInt(line, 10)) ? undefined : line;
5898
+ var filename = isString(url) && url.length > 0 ? url : getLocationHref();
5899
+ // event.exception.values[0].stacktrace.frames
5900
+ if (ev0sf.length === 0) {
5901
+ ev0sf.push({
5902
+ colno: colno,
5903
+ filename: filename,
5904
+ function: '?',
5905
+ in_app: true,
5906
+ lineno: lineno,
5907
+ });
5908
+ }
5909
+ return event;
5910
+ }
5911
+ function globalHandlerLog(type) {
5912
+ if (isDebugBuild()) {
5913
+ logger.log("Global Handler attached: " + type);
5914
+ }
5915
+ }
5916
+ function addMechanismAndCapture(hub, error, event, type) {
5917
+ addExceptionMechanism(event, {
5918
+ handled: false,
5919
+ type: type,
5920
+ });
5921
+ hub.captureEvent(event, {
5922
+ originalException: error,
5923
+ });
5924
+ }
5925
+ function getHubAndAttachStacktrace() {
5926
+ var hub = getCurrentHub();
5927
+ var client = hub.getClient();
5928
+ var attachStacktrace = client && client.getOptions().attachStacktrace;
5929
+ return [hub, attachStacktrace];
5930
+ }
6076
5931
 
6077
5932
  var DEFAULT_EVENT_TARGET = [
6078
5933
  'EventTarget',
@@ -6124,181 +5979,182 @@ var Sentry = (function (exports) {
6124
5979
  TryCatch.prototype.setupOnce = function () {
6125
5980
  var global = getGlobalObject();
6126
5981
  if (this._options.setTimeout) {
6127
- fill(global, 'setTimeout', this._wrapTimeFunction.bind(this));
5982
+ fill(global, 'setTimeout', _wrapTimeFunction);
6128
5983
  }
6129
5984
  if (this._options.setInterval) {
6130
- fill(global, 'setInterval', this._wrapTimeFunction.bind(this));
5985
+ fill(global, 'setInterval', _wrapTimeFunction);
6131
5986
  }
6132
5987
  if (this._options.requestAnimationFrame) {
6133
- fill(global, 'requestAnimationFrame', this._wrapRAF.bind(this));
5988
+ fill(global, 'requestAnimationFrame', _wrapRAF);
6134
5989
  }
6135
5990
  if (this._options.XMLHttpRequest && 'XMLHttpRequest' in global) {
6136
- fill(XMLHttpRequest.prototype, 'send', this._wrapXHR.bind(this));
5991
+ fill(XMLHttpRequest.prototype, 'send', _wrapXHR);
6137
5992
  }
6138
- if (this._options.eventTarget) {
6139
- var eventTarget = Array.isArray(this._options.eventTarget) ? this._options.eventTarget : DEFAULT_EVENT_TARGET;
6140
- eventTarget.forEach(this._wrapEventTarget.bind(this));
5993
+ var eventTargetOption = this._options.eventTarget;
5994
+ if (eventTargetOption) {
5995
+ var eventTarget = Array.isArray(eventTargetOption) ? eventTargetOption : DEFAULT_EVENT_TARGET;
5996
+ eventTarget.forEach(_wrapEventTarget);
6141
5997
  }
6142
5998
  };
6143
- /** JSDoc */
6144
- TryCatch.prototype._wrapTimeFunction = function (original) {
6145
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6146
- return function () {
6147
- var args = [];
6148
- for (var _i = 0; _i < arguments.length; _i++) {
6149
- args[_i] = arguments[_i];
6150
- }
6151
- var originalCallback = args[0];
6152
- args[0] = wrap(originalCallback, {
6153
- mechanism: {
6154
- data: { function: getFunctionName(original) },
6155
- handled: true,
6156
- type: 'instrument',
6157
- },
6158
- });
6159
- return original.apply(this, args);
6160
- };
5999
+ /**
6000
+ * @inheritDoc
6001
+ */
6002
+ TryCatch.id = 'TryCatch';
6003
+ return TryCatch;
6004
+ }());
6005
+ /** JSDoc */
6006
+ function _wrapTimeFunction(original) {
6007
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6008
+ return function () {
6009
+ var args = [];
6010
+ for (var _i = 0; _i < arguments.length; _i++) {
6011
+ args[_i] = arguments[_i];
6012
+ }
6013
+ var originalCallback = args[0];
6014
+ args[0] = wrap(originalCallback, {
6015
+ mechanism: {
6016
+ data: { function: getFunctionName(original) },
6017
+ handled: true,
6018
+ type: 'instrument',
6019
+ },
6020
+ });
6021
+ return original.apply(this, args);
6161
6022
  };
6162
- /** JSDoc */
6023
+ }
6024
+ /** JSDoc */
6025
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6026
+ function _wrapRAF(original) {
6163
6027
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6164
- TryCatch.prototype._wrapRAF = function (original) {
6165
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6166
- return function (callback) {
6167
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6168
- return original.call(this, wrap(callback, {
6169
- mechanism: {
6170
- data: {
6171
- function: 'requestAnimationFrame',
6172
- handler: getFunctionName(original),
6173
- },
6174
- handled: true,
6175
- type: 'instrument',
6028
+ return function (callback) {
6029
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6030
+ return original.call(this, wrap(callback, {
6031
+ mechanism: {
6032
+ data: {
6033
+ function: 'requestAnimationFrame',
6034
+ handler: getFunctionName(original),
6176
6035
  },
6177
- }));
6178
- };
6036
+ handled: true,
6037
+ type: 'instrument',
6038
+ },
6039
+ }));
6179
6040
  };
6180
- /** JSDoc */
6181
- TryCatch.prototype._wrapEventTarget = function (target) {
6182
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6183
- var global = getGlobalObject();
6184
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6185
- var proto = global[target] && global[target].prototype;
6186
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-prototype-builtins
6187
- if (!proto || !proto.hasOwnProperty || !proto.hasOwnProperty('addEventListener')) {
6188
- return;
6041
+ }
6042
+ /** JSDoc */
6043
+ function _wrapXHR(originalSend) {
6044
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6045
+ return function () {
6046
+ var args = [];
6047
+ for (var _i = 0; _i < arguments.length; _i++) {
6048
+ args[_i] = arguments[_i];
6189
6049
  }
6190
- fill(proto, 'addEventListener', function (original) {
6191
- return function (eventName, fn, options) {
6192
- try {
6193
- if (typeof fn.handleEvent === 'function') {
6194
- fn.handleEvent = wrap(fn.handleEvent.bind(fn), {
6195
- mechanism: {
6196
- data: {
6197
- function: 'handleEvent',
6198
- handler: getFunctionName(fn),
6199
- target: target,
6200
- },
6201
- handled: true,
6202
- type: 'instrument',
6203
- },
6204
- });
6205
- }
6206
- }
6207
- catch (err) {
6208
- // can sometimes get 'Permission denied to access property "handle Event'
6209
- }
6210
- return original.call(this, eventName,
6050
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
6051
+ var xhr = this;
6052
+ var xmlHttpRequestProps = ['onload', 'onerror', 'onprogress', 'onreadystatechange'];
6053
+ xmlHttpRequestProps.forEach(function (prop) {
6054
+ if (prop in xhr && typeof xhr[prop] === 'function') {
6211
6055
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6212
- wrap(fn, {
6213
- mechanism: {
6214
- data: {
6215
- function: 'addEventListener',
6216
- handler: getFunctionName(fn),
6217
- target: target,
6056
+ fill(xhr, prop, function (original) {
6057
+ var wrapOptions = {
6058
+ mechanism: {
6059
+ data: {
6060
+ function: prop,
6061
+ handler: getFunctionName(original),
6062
+ },
6063
+ handled: true,
6064
+ type: 'instrument',
6218
6065
  },
6219
- handled: true,
6220
- type: 'instrument',
6221
- },
6222
- }), options);
6223
- };
6224
- });
6225
- fill(proto, 'removeEventListener', function (originalRemoveEventListener) {
6226
- return function (eventName, fn, options) {
6227
- var _a;
6228
- /**
6229
- * There are 2 possible scenarios here:
6230
- *
6231
- * 1. Someone passes a callback, which was attached prior to Sentry initialization, or by using unmodified
6232
- * method, eg. `document.addEventListener.call(el, name, handler). In this case, we treat this function
6233
- * as a pass-through, and call original `removeEventListener` with it.
6234
- *
6235
- * 2. Someone passes a callback, which was attached after Sentry was initialized, which means that it was using
6236
- * our wrapped version of `addEventListener`, which internally calls `wrap` helper.
6237
- * This helper "wraps" whole callback inside a try/catch statement, and attached appropriate metadata to it,
6238
- * in order for us to make a distinction between wrapped/non-wrapped functions possible.
6239
- * If a function was wrapped, it has additional property of `__sentry_wrapped__`, holding the handler.
6240
- *
6241
- * When someone adds a handler prior to initialization, and then do it again, but after,
6242
- * then we have to detach both of them. Otherwise, if we'd detach only wrapped one, it'd be impossible
6243
- * to get rid of the initial handler and it'd stick there forever.
6244
- */
6245
- var wrappedEventHandler = fn;
6246
- try {
6247
- var originalEventHandler = (_a = wrappedEventHandler) === null || _a === void 0 ? void 0 : _a.__sentry_wrapped__;
6248
- if (originalEventHandler) {
6249
- originalRemoveEventListener.call(this, eventName, originalEventHandler, options);
6066
+ };
6067
+ // If Instrument integration has been called before TryCatch, get the name of original function
6068
+ var originalFunction = getOriginalFunction(original);
6069
+ if (originalFunction) {
6070
+ wrapOptions.mechanism.data.handler = getFunctionName(originalFunction);
6250
6071
  }
6251
- }
6252
- catch (e) {
6253
- // ignore, accessing __sentry_wrapped__ will throw in some Selenium environments
6254
- }
6255
- return originalRemoveEventListener.call(this, eventName, wrappedEventHandler, options);
6256
- };
6072
+ // Otherwise wrap directly
6073
+ return wrap(original, wrapOptions);
6074
+ });
6075
+ }
6257
6076
  });
6077
+ return originalSend.apply(this, args);
6258
6078
  };
6259
- /** JSDoc */
6260
- TryCatch.prototype._wrapXHR = function (originalSend) {
6261
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6262
- return function () {
6263
- var args = [];
6264
- for (var _i = 0; _i < arguments.length; _i++) {
6265
- args[_i] = arguments[_i];
6266
- }
6267
- // eslint-disable-next-line @typescript-eslint/no-this-alias
6268
- var xhr = this;
6269
- var xmlHttpRequestProps = ['onload', 'onerror', 'onprogress', 'onreadystatechange'];
6270
- xmlHttpRequestProps.forEach(function (prop) {
6271
- if (prop in xhr && typeof xhr[prop] === 'function') {
6272
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6273
- fill(xhr, prop, function (original) {
6274
- var wrapOptions = {
6275
- mechanism: {
6276
- data: {
6277
- function: prop,
6278
- handler: getFunctionName(original),
6279
- },
6280
- handled: true,
6281
- type: 'instrument',
6079
+ }
6080
+ /** JSDoc */
6081
+ function _wrapEventTarget(target) {
6082
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6083
+ var global = getGlobalObject();
6084
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6085
+ var proto = global[target] && global[target].prototype;
6086
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-prototype-builtins
6087
+ if (!proto || !proto.hasOwnProperty || !proto.hasOwnProperty('addEventListener')) {
6088
+ return;
6089
+ }
6090
+ fill(proto, 'addEventListener', function (original) {
6091
+ return function (eventName, fn, options) {
6092
+ try {
6093
+ if (typeof fn.handleEvent === 'function') {
6094
+ fn.handleEvent = wrap(fn.handleEvent.bind(fn), {
6095
+ mechanism: {
6096
+ data: {
6097
+ function: 'handleEvent',
6098
+ handler: getFunctionName(fn),
6099
+ target: target,
6282
6100
  },
6283
- };
6284
- // If Instrument integration has been called before TryCatch, get the name of original function
6285
- if (original.__sentry_original__) {
6286
- wrapOptions.mechanism.data.handler = getFunctionName(original.__sentry_original__);
6287
- }
6288
- // Otherwise wrap directly
6289
- return wrap(original, wrapOptions);
6101
+ handled: true,
6102
+ type: 'instrument',
6103
+ },
6290
6104
  });
6291
6105
  }
6292
- });
6293
- return originalSend.apply(this, args);
6106
+ }
6107
+ catch (err) {
6108
+ // can sometimes get 'Permission denied to access property "handle Event'
6109
+ }
6110
+ return original.call(this, eventName,
6111
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6112
+ wrap(fn, {
6113
+ mechanism: {
6114
+ data: {
6115
+ function: 'addEventListener',
6116
+ handler: getFunctionName(fn),
6117
+ target: target,
6118
+ },
6119
+ handled: true,
6120
+ type: 'instrument',
6121
+ },
6122
+ }), options);
6294
6123
  };
6295
- };
6296
- /**
6297
- * @inheritDoc
6298
- */
6299
- TryCatch.id = 'TryCatch';
6300
- return TryCatch;
6301
- }());
6124
+ });
6125
+ fill(proto, 'removeEventListener', function (originalRemoveEventListener) {
6126
+ return function (eventName, fn, options) {
6127
+ /**
6128
+ * There are 2 possible scenarios here:
6129
+ *
6130
+ * 1. Someone passes a callback, which was attached prior to Sentry initialization, or by using unmodified
6131
+ * method, eg. `document.addEventListener.call(el, name, handler). In this case, we treat this function
6132
+ * as a pass-through, and call original `removeEventListener` with it.
6133
+ *
6134
+ * 2. Someone passes a callback, which was attached after Sentry was initialized, which means that it was using
6135
+ * our wrapped version of `addEventListener`, which internally calls `wrap` helper.
6136
+ * This helper "wraps" whole callback inside a try/catch statement, and attached appropriate metadata to it,
6137
+ * in order for us to make a distinction between wrapped/non-wrapped functions possible.
6138
+ * If a function was wrapped, it has additional property of `__sentry_wrapped__`, holding the handler.
6139
+ *
6140
+ * When someone adds a handler prior to initialization, and then do it again, but after,
6141
+ * then we have to detach both of them. Otherwise, if we'd detach only wrapped one, it'd be impossible
6142
+ * to get rid of the initial handler and it'd stick there forever.
6143
+ */
6144
+ var wrappedEventHandler = fn;
6145
+ try {
6146
+ var originalEventHandler = wrappedEventHandler && wrappedEventHandler.__sentry_wrapped__;
6147
+ if (originalEventHandler) {
6148
+ originalRemoveEventListener.call(this, eventName, originalEventHandler, options);
6149
+ }
6150
+ }
6151
+ catch (e) {
6152
+ // ignore, accessing __sentry_wrapped__ will throw in some Selenium environments
6153
+ }
6154
+ return originalRemoveEventListener.call(this, eventName, wrappedEventHandler, options);
6155
+ };
6156
+ });
6157
+ }
6302
6158
 
6303
6159
  /**
6304
6160
  * Default Breadcrumbs instrumentations
@@ -6340,104 +6196,38 @@ var Sentry = (function (exports) {
6340
6196
  * - History API
6341
6197
  */
6342
6198
  Breadcrumbs.prototype.setupOnce = function () {
6343
- var _this = this;
6344
6199
  if (this._options.console) {
6345
- addInstrumentationHandler({
6346
- callback: function () {
6347
- var args = [];
6348
- for (var _i = 0; _i < arguments.length; _i++) {
6349
- args[_i] = arguments[_i];
6350
- }
6351
- _this._consoleBreadcrumb.apply(_this, __spread(args));
6352
- },
6353
- type: 'console',
6354
- });
6200
+ addInstrumentationHandler('console', _consoleBreadcrumb);
6355
6201
  }
6356
6202
  if (this._options.dom) {
6357
- addInstrumentationHandler({
6358
- callback: function () {
6359
- var args = [];
6360
- for (var _i = 0; _i < arguments.length; _i++) {
6361
- args[_i] = arguments[_i];
6362
- }
6363
- _this._domBreadcrumb.apply(_this, __spread(args));
6364
- },
6365
- type: 'dom',
6366
- });
6203
+ addInstrumentationHandler('dom', _domBreadcrumb(this._options.dom));
6367
6204
  }
6368
6205
  if (this._options.xhr) {
6369
- addInstrumentationHandler({
6370
- callback: function () {
6371
- var args = [];
6372
- for (var _i = 0; _i < arguments.length; _i++) {
6373
- args[_i] = arguments[_i];
6374
- }
6375
- _this._xhrBreadcrumb.apply(_this, __spread(args));
6376
- },
6377
- type: 'xhr',
6378
- });
6206
+ addInstrumentationHandler('xhr', _xhrBreadcrumb);
6379
6207
  }
6380
6208
  if (this._options.fetch) {
6381
- addInstrumentationHandler({
6382
- callback: function () {
6383
- var args = [];
6384
- for (var _i = 0; _i < arguments.length; _i++) {
6385
- args[_i] = arguments[_i];
6386
- }
6387
- _this._fetchBreadcrumb.apply(_this, __spread(args));
6388
- },
6389
- type: 'fetch',
6390
- });
6209
+ addInstrumentationHandler('fetch', _fetchBreadcrumb);
6391
6210
  }
6392
6211
  if (this._options.history) {
6393
- addInstrumentationHandler({
6394
- callback: function () {
6395
- var args = [];
6396
- for (var _i = 0; _i < arguments.length; _i++) {
6397
- args[_i] = arguments[_i];
6398
- }
6399
- _this._historyBreadcrumb.apply(_this, __spread(args));
6400
- },
6401
- type: 'history',
6402
- });
6403
- }
6404
- };
6405
- /**
6406
- * Creates breadcrumbs from console API calls
6407
- */
6408
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6409
- Breadcrumbs.prototype._consoleBreadcrumb = function (handlerData) {
6410
- var breadcrumb = {
6411
- category: 'console',
6412
- data: {
6413
- arguments: handlerData.args,
6414
- logger: 'console',
6415
- },
6416
- level: exports.Severity.fromString(handlerData.level),
6417
- message: safeJoin(handlerData.args, ' '),
6418
- };
6419
- if (handlerData.level === 'assert') {
6420
- if (handlerData.args[0] === false) {
6421
- breadcrumb.message = "Assertion failed: " + (safeJoin(handlerData.args.slice(1), ' ') || 'console.assert');
6422
- breadcrumb.data.arguments = handlerData.args.slice(1);
6423
- }
6424
- else {
6425
- // Don't capture a breadcrumb for passed assertions
6426
- return;
6427
- }
6212
+ addInstrumentationHandler('history', _historyBreadcrumb);
6428
6213
  }
6429
- getCurrentHub().addBreadcrumb(breadcrumb, {
6430
- input: handlerData.args,
6431
- level: handlerData.level,
6432
- });
6433
6214
  };
6434
6215
  /**
6435
- * Creates breadcrumbs from DOM API calls
6216
+ * @inheritDoc
6436
6217
  */
6218
+ Breadcrumbs.id = 'Breadcrumbs';
6219
+ return Breadcrumbs;
6220
+ }());
6221
+ /**
6222
+ * A HOC that creaes a function that creates breadcrumbs from DOM API calls.
6223
+ * This is a HOC so that we get access to dom options in the closure.
6224
+ */
6225
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6226
+ function _domBreadcrumb(dom) {
6437
6227
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6438
- Breadcrumbs.prototype._domBreadcrumb = function (handlerData) {
6228
+ function _innerDomBreadcrumb(handlerData) {
6439
6229
  var target;
6440
- var keyAttrs = typeof this._options.dom === 'object' ? this._options.dom.serializeAttribute : undefined;
6230
+ var keyAttrs = typeof dom === 'object' ? dom.serializeAttribute : undefined;
6441
6231
  if (typeof keyAttrs === 'string') {
6442
6232
  keyAttrs = [keyAttrs];
6443
6233
  }
@@ -6461,105 +6251,130 @@ var Sentry = (function (exports) {
6461
6251
  name: handlerData.name,
6462
6252
  global: handlerData.global,
6463
6253
  });
6254
+ }
6255
+ return _innerDomBreadcrumb;
6256
+ }
6257
+ /**
6258
+ * Creates breadcrumbs from console API calls
6259
+ */
6260
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6261
+ function _consoleBreadcrumb(handlerData) {
6262
+ var breadcrumb = {
6263
+ category: 'console',
6264
+ data: {
6265
+ arguments: handlerData.args,
6266
+ logger: 'console',
6267
+ },
6268
+ level: severityFromString(handlerData.level),
6269
+ message: safeJoin(handlerData.args, ' '),
6464
6270
  };
6465
- /**
6466
- * Creates breadcrumbs from XHR API calls
6467
- */
6468
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6469
- Breadcrumbs.prototype._xhrBreadcrumb = function (handlerData) {
6470
- if (handlerData.endTimestamp) {
6471
- // We only capture complete, non-sentry requests
6472
- if (handlerData.xhr.__sentry_own_request__) {
6473
- return;
6474
- }
6475
- var _a = handlerData.xhr.__sentry_xhr__ || {}, method = _a.method, url = _a.url, status_code = _a.status_code, body = _a.body;
6476
- getCurrentHub().addBreadcrumb({
6477
- category: 'xhr',
6478
- data: {
6479
- method: method,
6480
- url: url,
6481
- status_code: status_code,
6482
- },
6483
- type: 'http',
6484
- }, {
6485
- xhr: handlerData.xhr,
6486
- input: body,
6487
- });
6488
- return;
6271
+ if (handlerData.level === 'assert') {
6272
+ if (handlerData.args[0] === false) {
6273
+ breadcrumb.message = "Assertion failed: " + (safeJoin(handlerData.args.slice(1), ' ') || 'console.assert');
6274
+ breadcrumb.data.arguments = handlerData.args.slice(1);
6489
6275
  }
6490
- };
6491
- /**
6492
- * Creates breadcrumbs from fetch API calls
6493
- */
6494
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6495
- Breadcrumbs.prototype._fetchBreadcrumb = function (handlerData) {
6496
- // We only capture complete fetch requests
6497
- if (!handlerData.endTimestamp) {
6276
+ else {
6277
+ // Don't capture a breadcrumb for passed assertions
6498
6278
  return;
6499
6279
  }
6500
- if (handlerData.fetchData.url.match(/sentry_key/) && handlerData.fetchData.method === 'POST') {
6501
- // We will not create breadcrumbs for fetch requests that contain `sentry_key` (internal sentry requests)
6280
+ }
6281
+ getCurrentHub().addBreadcrumb(breadcrumb, {
6282
+ input: handlerData.args,
6283
+ level: handlerData.level,
6284
+ });
6285
+ }
6286
+ /**
6287
+ * Creates breadcrumbs from XHR API calls
6288
+ */
6289
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6290
+ function _xhrBreadcrumb(handlerData) {
6291
+ if (handlerData.endTimestamp) {
6292
+ // We only capture complete, non-sentry requests
6293
+ if (handlerData.xhr.__sentry_own_request__) {
6502
6294
  return;
6503
6295
  }
6504
- if (handlerData.error) {
6505
- getCurrentHub().addBreadcrumb({
6506
- category: 'fetch',
6507
- data: handlerData.fetchData,
6508
- level: exports.Severity.Error,
6509
- type: 'http',
6510
- }, {
6511
- data: handlerData.error,
6512
- input: handlerData.args,
6513
- });
6514
- }
6515
- else {
6516
- getCurrentHub().addBreadcrumb({
6517
- category: 'fetch',
6518
- data: __assign(__assign({}, handlerData.fetchData), { status_code: handlerData.response.status }),
6519
- type: 'http',
6520
- }, {
6521
- input: handlerData.args,
6522
- response: handlerData.response,
6523
- });
6524
- }
6525
- };
6526
- /**
6527
- * Creates breadcrumbs from history API calls
6528
- */
6529
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6530
- Breadcrumbs.prototype._historyBreadcrumb = function (handlerData) {
6531
- var global = getGlobalObject();
6532
- var from = handlerData.from;
6533
- var to = handlerData.to;
6534
- var parsedLoc = parseUrl(global.location.href);
6535
- var parsedFrom = parseUrl(from);
6536
- var parsedTo = parseUrl(to);
6537
- // Initial pushState doesn't provide `from` information
6538
- if (!parsedFrom.path) {
6539
- parsedFrom = parsedLoc;
6540
- }
6541
- // Use only the path component of the URL if the URL matches the current
6542
- // document (almost all the time when using pushState)
6543
- if (parsedLoc.protocol === parsedTo.protocol && parsedLoc.host === parsedTo.host) {
6544
- to = parsedTo.relative;
6545
- }
6546
- if (parsedLoc.protocol === parsedFrom.protocol && parsedLoc.host === parsedFrom.host) {
6547
- from = parsedFrom.relative;
6548
- }
6296
+ var _a = handlerData.xhr.__sentry_xhr__ || {}, method = _a.method, url = _a.url, status_code = _a.status_code, body = _a.body;
6549
6297
  getCurrentHub().addBreadcrumb({
6550
- category: 'navigation',
6298
+ category: 'xhr',
6551
6299
  data: {
6552
- from: from,
6553
- to: to,
6300
+ method: method,
6301
+ url: url,
6302
+ status_code: status_code,
6554
6303
  },
6304
+ type: 'http',
6305
+ }, {
6306
+ xhr: handlerData.xhr,
6307
+ input: body,
6555
6308
  });
6556
- };
6557
- /**
6558
- * @inheritDoc
6559
- */
6560
- Breadcrumbs.id = 'Breadcrumbs';
6561
- return Breadcrumbs;
6562
- }());
6309
+ return;
6310
+ }
6311
+ }
6312
+ /**
6313
+ * Creates breadcrumbs from fetch API calls
6314
+ */
6315
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6316
+ function _fetchBreadcrumb(handlerData) {
6317
+ // We only capture complete fetch requests
6318
+ if (!handlerData.endTimestamp) {
6319
+ return;
6320
+ }
6321
+ if (handlerData.fetchData.url.match(/sentry_key/) && handlerData.fetchData.method === 'POST') {
6322
+ // We will not create breadcrumbs for fetch requests that contain `sentry_key` (internal sentry requests)
6323
+ return;
6324
+ }
6325
+ if (handlerData.error) {
6326
+ getCurrentHub().addBreadcrumb({
6327
+ category: 'fetch',
6328
+ data: handlerData.fetchData,
6329
+ level: exports.Severity.Error,
6330
+ type: 'http',
6331
+ }, {
6332
+ data: handlerData.error,
6333
+ input: handlerData.args,
6334
+ });
6335
+ }
6336
+ else {
6337
+ getCurrentHub().addBreadcrumb({
6338
+ category: 'fetch',
6339
+ data: __assign(__assign({}, handlerData.fetchData), { status_code: handlerData.response.status }),
6340
+ type: 'http',
6341
+ }, {
6342
+ input: handlerData.args,
6343
+ response: handlerData.response,
6344
+ });
6345
+ }
6346
+ }
6347
+ /**
6348
+ * Creates breadcrumbs from history API calls
6349
+ */
6350
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6351
+ function _historyBreadcrumb(handlerData) {
6352
+ var global = getGlobalObject();
6353
+ var from = handlerData.from;
6354
+ var to = handlerData.to;
6355
+ var parsedLoc = parseUrl(global.location.href);
6356
+ var parsedFrom = parseUrl(from);
6357
+ var parsedTo = parseUrl(to);
6358
+ // Initial pushState doesn't provide `from` information
6359
+ if (!parsedFrom.path) {
6360
+ parsedFrom = parsedLoc;
6361
+ }
6362
+ // Use only the path component of the URL if the URL matches the current
6363
+ // document (almost all the time when using pushState)
6364
+ if (parsedLoc.protocol === parsedTo.protocol && parsedLoc.host === parsedTo.host) {
6365
+ to = parsedTo.relative;
6366
+ }
6367
+ if (parsedLoc.protocol === parsedFrom.protocol && parsedLoc.host === parsedFrom.host) {
6368
+ from = parsedFrom.relative;
6369
+ }
6370
+ getCurrentHub().addBreadcrumb({
6371
+ category: 'navigation',
6372
+ data: {
6373
+ from: from,
6374
+ to: to,
6375
+ },
6376
+ });
6377
+ }
6563
6378
 
6564
6379
  var DEFAULT_KEY = 'cause';
6565
6380
  var DEFAULT_LIMIT = 5;
@@ -6583,42 +6398,38 @@ var Sentry = (function (exports) {
6583
6398
  LinkedErrors.prototype.setupOnce = function () {
6584
6399
  addGlobalEventProcessor(function (event, hint) {
6585
6400
  var self = getCurrentHub().getIntegration(LinkedErrors);
6586
- if (self) {
6587
- var handler = self._handler && self._handler.bind(self);
6588
- return typeof handler === 'function' ? handler(event, hint) : event;
6589
- }
6590
- return event;
6401
+ return self ? _handler(self._key, self._limit, event, hint) : event;
6591
6402
  });
6592
6403
  };
6593
- /**
6594
- * @inheritDoc
6595
- */
6596
- LinkedErrors.prototype._handler = function (event, hint) {
6597
- if (!event.exception || !event.exception.values || !hint || !isInstanceOf(hint.originalException, Error)) {
6598
- return event;
6599
- }
6600
- var linkedErrors = this._walkErrorTree(hint.originalException, this._key);
6601
- event.exception.values = __spread(linkedErrors, event.exception.values);
6602
- return event;
6603
- };
6604
- /**
6605
- * @inheritDoc
6606
- */
6607
- LinkedErrors.prototype._walkErrorTree = function (error, key, stack) {
6608
- if (stack === void 0) { stack = []; }
6609
- if (!isInstanceOf(error[key], Error) || stack.length + 1 >= this._limit) {
6610
- return stack;
6611
- }
6612
- var stacktrace = computeStackTrace(error[key]);
6613
- var exception = exceptionFromStacktrace(stacktrace);
6614
- return this._walkErrorTree(error[key], key, __spread([exception], stack));
6615
- };
6616
6404
  /**
6617
6405
  * @inheritDoc
6618
6406
  */
6619
6407
  LinkedErrors.id = 'LinkedErrors';
6620
6408
  return LinkedErrors;
6621
- }());
6409
+ }());
6410
+ /**
6411
+ * @inheritDoc
6412
+ */
6413
+ function _handler(key, limit, event, hint) {
6414
+ if (!event.exception || !event.exception.values || !hint || !isInstanceOf(hint.originalException, Error)) {
6415
+ return event;
6416
+ }
6417
+ var linkedErrors = _walkErrorTree(limit, hint.originalException, key);
6418
+ event.exception.values = __spread(linkedErrors, event.exception.values);
6419
+ return event;
6420
+ }
6421
+ /**
6422
+ * JSDOC
6423
+ */
6424
+ function _walkErrorTree(limit, error, key, stack) {
6425
+ if (stack === void 0) { stack = []; }
6426
+ if (!isInstanceOf(error[key], Error) || stack.length + 1 >= limit) {
6427
+ return stack;
6428
+ }
6429
+ var stacktrace = computeStackTrace(error[key]);
6430
+ var exception = exceptionFromStacktrace(stacktrace);
6431
+ return _walkErrorTree(limit, error[key], key, __spread([exception], stack));
6432
+ }
6622
6433
 
6623
6434
  var global$6 = getGlobalObject();
6624
6435
  /** UserAgent */
@@ -6634,17 +6445,16 @@ var Sentry = (function (exports) {
6634
6445
  */
6635
6446
  UserAgent.prototype.setupOnce = function () {
6636
6447
  addGlobalEventProcessor(function (event) {
6637
- var _a, _b, _c;
6638
6448
  if (getCurrentHub().getIntegration(UserAgent)) {
6639
6449
  // if none of the information we want exists, don't bother
6640
6450
  if (!global$6.navigator && !global$6.location && !global$6.document) {
6641
6451
  return event;
6642
6452
  }
6643
6453
  // grab as much info as exists and add it to the event
6644
- var url = ((_a = event.request) === null || _a === void 0 ? void 0 : _a.url) || ((_b = global$6.location) === null || _b === void 0 ? void 0 : _b.href);
6454
+ var url = (event.request && event.request.url) || (global$6.location && global$6.location.href);
6645
6455
  var referrer = (global$6.document || {}).referrer;
6646
6456
  var userAgent = (global$6.navigator || {}).userAgent;
6647
- var headers = __assign(__assign(__assign({}, (_c = event.request) === null || _c === void 0 ? void 0 : _c.headers), (referrer && { Referer: referrer })), (userAgent && { 'User-Agent': userAgent }));
6457
+ var headers = __assign(__assign(__assign({}, (event.request && event.request.headers)), (referrer && { Referer: referrer })), (userAgent && { 'User-Agent': userAgent }));
6648
6458
  var request = __assign(__assign({}, (url && { url: url })), { headers: headers });
6649
6459
  return __assign(__assign({}, event), { request: request });
6650
6460
  }
@@ -6675,7 +6485,7 @@ var Sentry = (function (exports) {
6675
6485
  if (self) {
6676
6486
  // Juuust in case something goes wrong
6677
6487
  try {
6678
- if (self._shouldDropEvent(currentEvent, self._previousEvent)) {
6488
+ if (_shouldDropEvent(currentEvent, self._previousEvent)) {
6679
6489
  logger.warn("Event dropped due to being a duplicate of previously captured event.");
6680
6490
  return null;
6681
6491
  }
@@ -6688,140 +6498,140 @@ var Sentry = (function (exports) {
6688
6498
  return currentEvent;
6689
6499
  });
6690
6500
  };
6691
- /** JSDoc */
6692
- Dedupe.prototype._shouldDropEvent = function (currentEvent, previousEvent) {
6693
- if (!previousEvent) {
6694
- return false;
6695
- }
6696
- if (this._isSameMessageEvent(currentEvent, previousEvent)) {
6697
- return true;
6698
- }
6699
- if (this._isSameExceptionEvent(currentEvent, previousEvent)) {
6700
- return true;
6701
- }
6501
+ /**
6502
+ * @inheritDoc
6503
+ */
6504
+ Dedupe.id = 'Dedupe';
6505
+ return Dedupe;
6506
+ }());
6507
+ /** JSDoc */
6508
+ function _shouldDropEvent(currentEvent, previousEvent) {
6509
+ if (!previousEvent) {
6702
6510
  return false;
6703
- };
6704
- /** JSDoc */
6705
- Dedupe.prototype._isSameMessageEvent = function (currentEvent, previousEvent) {
6706
- var currentMessage = currentEvent.message;
6707
- var previousMessage = previousEvent.message;
6708
- // If neither event has a message property, they were both exceptions, so bail out
6709
- if (!currentMessage && !previousMessage) {
6710
- return false;
6711
- }
6712
- // If only one event has a stacktrace, but not the other one, they are not the same
6713
- if ((currentMessage && !previousMessage) || (!currentMessage && previousMessage)) {
6714
- return false;
6715
- }
6716
- if (currentMessage !== previousMessage) {
6717
- return false;
6718
- }
6719
- if (!this._isSameFingerprint(currentEvent, previousEvent)) {
6720
- return false;
6721
- }
6722
- if (!this._isSameStacktrace(currentEvent, previousEvent)) {
6723
- return false;
6724
- }
6511
+ }
6512
+ if (_isSameMessageEvent(currentEvent, previousEvent)) {
6725
6513
  return true;
6726
- };
6727
- /** JSDoc */
6728
- Dedupe.prototype._getFramesFromEvent = function (event) {
6729
- var exception = event.exception;
6730
- if (exception) {
6731
- try {
6732
- // @ts-ignore Object could be undefined
6733
- return exception.values[0].stacktrace.frames;
6734
- }
6735
- catch (_oO) {
6736
- return undefined;
6737
- }
6738
- }
6739
- else if (event.stacktrace) {
6740
- return event.stacktrace.frames;
6741
- }
6742
- return undefined;
6743
- };
6744
- /** JSDoc */
6745
- Dedupe.prototype._isSameStacktrace = function (currentEvent, previousEvent) {
6746
- var currentFrames = this._getFramesFromEvent(currentEvent);
6747
- var previousFrames = this._getFramesFromEvent(previousEvent);
6748
- // If neither event has a stacktrace, they are assumed to be the same
6749
- if (!currentFrames && !previousFrames) {
6750
- return true;
6751
- }
6752
- // If only one event has a stacktrace, but not the other one, they are not the same
6753
- if ((currentFrames && !previousFrames) || (!currentFrames && previousFrames)) {
6754
- return false;
6755
- }
6756
- currentFrames = currentFrames;
6757
- previousFrames = previousFrames;
6758
- // If number of frames differ, they are not the same
6759
- if (previousFrames.length !== currentFrames.length) {
6760
- return false;
6761
- }
6762
- // Otherwise, compare the two
6763
- for (var i = 0; i < previousFrames.length; i++) {
6764
- var frameA = previousFrames[i];
6765
- var frameB = currentFrames[i];
6766
- if (frameA.filename !== frameB.filename ||
6767
- frameA.lineno !== frameB.lineno ||
6768
- frameA.colno !== frameB.colno ||
6769
- frameA.function !== frameB.function) {
6770
- return false;
6771
- }
6772
- }
6514
+ }
6515
+ if (_isSameExceptionEvent(currentEvent, previousEvent)) {
6773
6516
  return true;
6774
- };
6775
- /** JSDoc */
6776
- Dedupe.prototype._getExceptionFromEvent = function (event) {
6777
- return event.exception && event.exception.values && event.exception.values[0];
6778
- };
6779
- /** JSDoc */
6780
- Dedupe.prototype._isSameExceptionEvent = function (currentEvent, previousEvent) {
6781
- var previousException = this._getExceptionFromEvent(previousEvent);
6782
- var currentException = this._getExceptionFromEvent(currentEvent);
6783
- if (!previousException || !currentException) {
6784
- return false;
6785
- }
6786
- if (previousException.type !== currentException.type || previousException.value !== currentException.value) {
6787
- return false;
6788
- }
6789
- if (!this._isSameFingerprint(currentEvent, previousEvent)) {
6790
- return false;
6791
- }
6792
- if (!this._isSameStacktrace(currentEvent, previousEvent)) {
6793
- return false;
6794
- }
6517
+ }
6518
+ return false;
6519
+ }
6520
+ /** JSDoc */
6521
+ function _isSameMessageEvent(currentEvent, previousEvent) {
6522
+ var currentMessage = currentEvent.message;
6523
+ var previousMessage = previousEvent.message;
6524
+ // If neither event has a message property, they were both exceptions, so bail out
6525
+ if (!currentMessage && !previousMessage) {
6526
+ return false;
6527
+ }
6528
+ // If only one event has a stacktrace, but not the other one, they are not the same
6529
+ if ((currentMessage && !previousMessage) || (!currentMessage && previousMessage)) {
6530
+ return false;
6531
+ }
6532
+ if (currentMessage !== previousMessage) {
6533
+ return false;
6534
+ }
6535
+ if (!_isSameFingerprint(currentEvent, previousEvent)) {
6536
+ return false;
6537
+ }
6538
+ if (!_isSameStacktrace(currentEvent, previousEvent)) {
6539
+ return false;
6540
+ }
6541
+ return true;
6542
+ }
6543
+ /** JSDoc */
6544
+ function _isSameExceptionEvent(currentEvent, previousEvent) {
6545
+ var previousException = _getExceptionFromEvent(previousEvent);
6546
+ var currentException = _getExceptionFromEvent(currentEvent);
6547
+ if (!previousException || !currentException) {
6548
+ return false;
6549
+ }
6550
+ if (previousException.type !== currentException.type || previousException.value !== currentException.value) {
6551
+ return false;
6552
+ }
6553
+ if (!_isSameFingerprint(currentEvent, previousEvent)) {
6554
+ return false;
6555
+ }
6556
+ if (!_isSameStacktrace(currentEvent, previousEvent)) {
6557
+ return false;
6558
+ }
6559
+ return true;
6560
+ }
6561
+ /** JSDoc */
6562
+ function _isSameStacktrace(currentEvent, previousEvent) {
6563
+ var currentFrames = _getFramesFromEvent(currentEvent);
6564
+ var previousFrames = _getFramesFromEvent(previousEvent);
6565
+ // If neither event has a stacktrace, they are assumed to be the same
6566
+ if (!currentFrames && !previousFrames) {
6795
6567
  return true;
6796
- };
6797
- /** JSDoc */
6798
- Dedupe.prototype._isSameFingerprint = function (currentEvent, previousEvent) {
6799
- var currentFingerprint = currentEvent.fingerprint;
6800
- var previousFingerprint = previousEvent.fingerprint;
6801
- // If neither event has a fingerprint, they are assumed to be the same
6802
- if (!currentFingerprint && !previousFingerprint) {
6803
- return true;
6804
- }
6805
- // If only one event has a fingerprint, but not the other one, they are not the same
6806
- if ((currentFingerprint && !previousFingerprint) || (!currentFingerprint && previousFingerprint)) {
6568
+ }
6569
+ // If only one event has a stacktrace, but not the other one, they are not the same
6570
+ if ((currentFrames && !previousFrames) || (!currentFrames && previousFrames)) {
6571
+ return false;
6572
+ }
6573
+ currentFrames = currentFrames;
6574
+ previousFrames = previousFrames;
6575
+ // If number of frames differ, they are not the same
6576
+ if (previousFrames.length !== currentFrames.length) {
6577
+ return false;
6578
+ }
6579
+ // Otherwise, compare the two
6580
+ for (var i = 0; i < previousFrames.length; i++) {
6581
+ var frameA = previousFrames[i];
6582
+ var frameB = currentFrames[i];
6583
+ if (frameA.filename !== frameB.filename ||
6584
+ frameA.lineno !== frameB.lineno ||
6585
+ frameA.colno !== frameB.colno ||
6586
+ frameA.function !== frameB.function) {
6807
6587
  return false;
6808
6588
  }
6809
- currentFingerprint = currentFingerprint;
6810
- previousFingerprint = previousFingerprint;
6811
- // Otherwise, compare the two
6589
+ }
6590
+ return true;
6591
+ }
6592
+ /** JSDoc */
6593
+ function _isSameFingerprint(currentEvent, previousEvent) {
6594
+ var currentFingerprint = currentEvent.fingerprint;
6595
+ var previousFingerprint = previousEvent.fingerprint;
6596
+ // If neither event has a fingerprint, they are assumed to be the same
6597
+ if (!currentFingerprint && !previousFingerprint) {
6598
+ return true;
6599
+ }
6600
+ // If only one event has a fingerprint, but not the other one, they are not the same
6601
+ if ((currentFingerprint && !previousFingerprint) || (!currentFingerprint && previousFingerprint)) {
6602
+ return false;
6603
+ }
6604
+ currentFingerprint = currentFingerprint;
6605
+ previousFingerprint = previousFingerprint;
6606
+ // Otherwise, compare the two
6607
+ try {
6608
+ return !!(currentFingerprint.join('') === previousFingerprint.join(''));
6609
+ }
6610
+ catch (_oO) {
6611
+ return false;
6612
+ }
6613
+ }
6614
+ /** JSDoc */
6615
+ function _getExceptionFromEvent(event) {
6616
+ return event.exception && event.exception.values && event.exception.values[0];
6617
+ }
6618
+ /** JSDoc */
6619
+ function _getFramesFromEvent(event) {
6620
+ var exception = event.exception;
6621
+ if (exception) {
6812
6622
  try {
6813
- return !!(currentFingerprint.join('') === previousFingerprint.join(''));
6623
+ // @ts-ignore Object could be undefined
6624
+ return exception.values[0].stacktrace.frames;
6814
6625
  }
6815
6626
  catch (_oO) {
6816
- return false;
6627
+ return undefined;
6817
6628
  }
6818
- };
6819
- /**
6820
- * @inheritDoc
6821
- */
6822
- Dedupe.id = 'Dedupe';
6823
- return Dedupe;
6824
- }());
6629
+ }
6630
+ else if (event.stacktrace) {
6631
+ return event.stacktrace.frames;
6632
+ }
6633
+ return undefined;
6634
+ }
6825
6635
 
6826
6636
 
6827
6637
 
@@ -7048,8 +6858,10 @@ var Sentry = (function (exports) {
7048
6858
  if (client) {
7049
6859
  return client.flush(timeout);
7050
6860
  }
7051
- logger.warn('Cannot flush events. No client defined.');
7052
- return SyncPromise.resolve(false);
6861
+ if (isDebugBuild()) {
6862
+ logger.warn('Cannot flush events. No client defined.');
6863
+ }
6864
+ return resolvedSyncPromise(false);
7053
6865
  }
7054
6866
  /**
7055
6867
  * Call `close()` on the current client, if there is one. See {@link Client.close}.
@@ -7064,8 +6876,10 @@ var Sentry = (function (exports) {
7064
6876
  if (client) {
7065
6877
  return client.close(timeout);
7066
6878
  }
7067
- logger.warn('Cannot flush events and disable SDK. No client defined.');
7068
- return SyncPromise.resolve(false);
6879
+ if (isDebugBuild()) {
6880
+ logger.warn('Cannot flush events and disable SDK. No client defined.');
6881
+ }
6882
+ return resolvedSyncPromise(false);
7069
6883
  }
7070
6884
  /**
7071
6885
  * Wrap code within a try/catch block so the SDK is able to capture errors.
@@ -7078,6 +6892,10 @@ var Sentry = (function (exports) {
7078
6892
  function wrap$1(fn) {
7079
6893
  return wrap(fn)();
7080
6894
  }
6895
+ function startSessionOnHub(hub) {
6896
+ hub.startSession({ ignoreDuration: true });
6897
+ hub.captureSession();
6898
+ }
7081
6899
  /**
7082
6900
  * Enable automatic Session Tracking for the initial page load.
7083
6901
  */
@@ -7085,7 +6903,9 @@ var Sentry = (function (exports) {
7085
6903
  var window = getGlobalObject();
7086
6904
  var document = window.document;
7087
6905
  if (typeof document === 'undefined') {
7088
- logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');
6906
+ if (isDebugBuild()) {
6907
+ logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');
6908
+ }
7089
6909
  return;
7090
6910
  }
7091
6911
  var hub = getCurrentHub();
@@ -7095,27 +6915,21 @@ var Sentry = (function (exports) {
7095
6915
  // https://github.com/getsentry/sentry-javascript/issues/3207 and
7096
6916
  // https://github.com/getsentry/sentry-javascript/issues/3234 and
7097
6917
  // https://github.com/getsentry/sentry-javascript/issues/3278.
7098
- if (typeof hub.startSession !== 'function' || typeof hub.captureSession !== 'function') {
6918
+ if (!hub.captureSession) {
7099
6919
  return;
7100
6920
  }
7101
6921
  // The session duration for browser sessions does not track a meaningful
7102
6922
  // concept that can be used as a metric.
7103
6923
  // Automatically captured sessions are akin to page views, and thus we
7104
6924
  // discard their duration.
7105
- hub.startSession({ ignoreDuration: true });
7106
- hub.captureSession();
6925
+ startSessionOnHub(hub);
7107
6926
  // We want to create a session for every navigation as well
7108
- addInstrumentationHandler({
7109
- callback: function (_a) {
7110
- var from = _a.from, to = _a.to;
7111
- // Don't create an additional session for the initial route or if the location did not change
7112
- if (from === undefined || from === to) {
7113
- return;
7114
- }
7115
- hub.startSession({ ignoreDuration: true });
7116
- hub.captureSession();
7117
- },
7118
- type: 'history',
6927
+ addInstrumentationHandler('history', function (_a) {
6928
+ var from = _a.from, to = _a.to;
6929
+ // Don't create an additional session for the initial route or if the location did not change
6930
+ if (!(from === undefined || from === to)) {
6931
+ startSessionOnHub(getCurrentHub());
6932
+ }
7119
6933
  });
7120
6934
  }
7121
6935