@sentry/browser 6.14.3 → 6.17.0-beta.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 (119) hide show
  1. package/build/bundle.es6.js +1271 -1393
  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 +1367 -1520
  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/backend.d.ts +2 -2
  10. package/dist/backend.d.ts.map +1 -1
  11. package/dist/backend.js +1 -2
  12. package/dist/backend.js.map +1 -1
  13. package/dist/eventbuilder.d.ts +2 -2
  14. package/dist/eventbuilder.d.ts.map +1 -1
  15. package/dist/eventbuilder.js +20 -13
  16. package/dist/eventbuilder.js.map +1 -1
  17. package/dist/exports.d.ts +1 -1
  18. package/dist/exports.d.ts.map +1 -1
  19. package/dist/exports.js +0 -3
  20. package/dist/exports.js.map +1 -1
  21. package/dist/helpers.d.ts.map +1 -1
  22. package/dist/helpers.js +26 -37
  23. package/dist/helpers.js.map +1 -1
  24. package/dist/integrations/breadcrumbs.d.ts +0 -20
  25. package/dist/integrations/breadcrumbs.d.ts.map +1 -1
  26. package/dist/integrations/breadcrumbs.js +132 -174
  27. package/dist/integrations/breadcrumbs.js.map +1 -1
  28. package/dist/integrations/dedupe.d.ts +0 -14
  29. package/dist/integrations/dedupe.d.ts.map +1 -1
  30. package/dist/integrations/dedupe.js +126 -126
  31. package/dist/integrations/dedupe.js.map +1 -1
  32. package/dist/integrations/globalhandlers.d.ts +7 -25
  33. package/dist/integrations/globalhandlers.d.ts.map +1 -1
  34. package/dist/integrations/globalhandlers.js +176 -169
  35. package/dist/integrations/globalhandlers.js.map +1 -1
  36. package/dist/integrations/linkederrors.d.ts +15 -13
  37. package/dist/integrations/linkederrors.d.ts.map +1 -1
  38. package/dist/integrations/linkederrors.js +26 -28
  39. package/dist/integrations/linkederrors.js.map +1 -1
  40. package/dist/integrations/trycatch.d.ts +0 -8
  41. package/dist/integrations/trycatch.d.ts.map +1 -1
  42. package/dist/integrations/trycatch.js +154 -153
  43. package/dist/integrations/trycatch.js.map +1 -1
  44. package/dist/integrations/useragent.js +2 -3
  45. package/dist/integrations/useragent.js.map +1 -1
  46. package/dist/sdk.d.ts.map +1 -1
  47. package/dist/sdk.js +23 -19
  48. package/dist/sdk.js.map +1 -1
  49. package/dist/transports/base.d.ts +9 -4
  50. package/dist/transports/base.d.ts.map +1 -1
  51. package/dist/transports/base.js +23 -19
  52. package/dist/transports/base.js.map +1 -1
  53. package/dist/transports/fetch.d.ts +2 -10
  54. package/dist/transports/fetch.d.ts.map +1 -1
  55. package/dist/transports/fetch.js +3 -17
  56. package/dist/transports/fetch.js.map +1 -1
  57. package/dist/transports/utils.d.ts.map +1 -1
  58. package/dist/transports/utils.js +7 -5
  59. package/dist/transports/utils.js.map +1 -1
  60. package/dist/transports/xhr.d.ts +2 -10
  61. package/dist/transports/xhr.d.ts.map +1 -1
  62. package/dist/transports/xhr.js +3 -17
  63. package/dist/transports/xhr.js.map +1 -1
  64. package/esm/backend.d.ts +2 -2
  65. package/esm/backend.d.ts.map +1 -1
  66. package/esm/backend.js +1 -2
  67. package/esm/backend.js.map +1 -1
  68. package/esm/eventbuilder.d.ts +2 -2
  69. package/esm/eventbuilder.d.ts.map +1 -1
  70. package/esm/eventbuilder.js +21 -14
  71. package/esm/eventbuilder.js.map +1 -1
  72. package/esm/exports.d.ts +1 -1
  73. package/esm/exports.d.ts.map +1 -1
  74. package/esm/exports.js +0 -1
  75. package/esm/exports.js.map +1 -1
  76. package/esm/helpers.d.ts.map +1 -1
  77. package/esm/helpers.js +28 -39
  78. package/esm/helpers.js.map +1 -1
  79. package/esm/integrations/breadcrumbs.d.ts +0 -20
  80. package/esm/integrations/breadcrumbs.d.ts.map +1 -1
  81. package/esm/integrations/breadcrumbs.js +134 -176
  82. package/esm/integrations/breadcrumbs.js.map +1 -1
  83. package/esm/integrations/dedupe.d.ts +0 -14
  84. package/esm/integrations/dedupe.d.ts.map +1 -1
  85. package/esm/integrations/dedupe.js +126 -126
  86. package/esm/integrations/dedupe.js.map +1 -1
  87. package/esm/integrations/globalhandlers.d.ts +7 -25
  88. package/esm/integrations/globalhandlers.d.ts.map +1 -1
  89. package/esm/integrations/globalhandlers.js +178 -171
  90. package/esm/integrations/globalhandlers.js.map +1 -1
  91. package/esm/integrations/linkederrors.d.ts +15 -13
  92. package/esm/integrations/linkederrors.d.ts.map +1 -1
  93. package/esm/integrations/linkederrors.js +24 -28
  94. package/esm/integrations/linkederrors.js.map +1 -1
  95. package/esm/integrations/trycatch.d.ts +0 -8
  96. package/esm/integrations/trycatch.d.ts.map +1 -1
  97. package/esm/integrations/trycatch.js +155 -154
  98. package/esm/integrations/trycatch.js.map +1 -1
  99. package/esm/integrations/useragent.js +2 -3
  100. package/esm/integrations/useragent.js.map +1 -1
  101. package/esm/sdk.d.ts.map +1 -1
  102. package/esm/sdk.js +24 -20
  103. package/esm/sdk.js.map +1 -1
  104. package/esm/transports/base.d.ts +9 -4
  105. package/esm/transports/base.d.ts.map +1 -1
  106. package/esm/transports/base.js +25 -21
  107. package/esm/transports/base.js.map +1 -1
  108. package/esm/transports/fetch.d.ts +2 -10
  109. package/esm/transports/fetch.d.ts.map +1 -1
  110. package/esm/transports/fetch.js +3 -17
  111. package/esm/transports/fetch.js.map +1 -1
  112. package/esm/transports/utils.d.ts.map +1 -1
  113. package/esm/transports/utils.js +8 -6
  114. package/esm/transports/utils.js.map +1 -1
  115. package/esm/transports/xhr.d.ts +2 -10
  116. package/esm/transports/xhr.d.ts.map +1 -1
  117. package/esm/transports/xhr.js +3 -17
  118. package/esm/transports/xhr.js.map +1 -1
  119. package/package.json +15 -17
package/build/bundle.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @sentry/browser 6.14.3 (3807d99) | https://github.com/getsentry/sentry-javascript */
1
+ /*! @sentry/browser 6.17.0-beta.0 (2a9a3d4) | https://github.com/getsentry/sentry-javascript */
2
2
  var Sentry = (function (exports) {
3
3
  /*! *****************************************************************************
4
4
  Copyright (c) Microsoft Corporation. All rights reserved.
@@ -84,150 +84,6 @@ var Sentry = (function (exports) {
84
84
  return ar;
85
85
  }
86
86
 
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
- /**
101
- * Session Status
102
- */
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
- (function (Severity) {
126
- /** JSDoc */
127
- Severity["Fatal"] = "fatal";
128
- /** JSDoc */
129
- Severity["Error"] = "error";
130
- /** JSDoc */
131
- Severity["Warning"] = "warning";
132
- /** JSDoc */
133
- Severity["Log"] = "log";
134
- /** JSDoc */
135
- Severity["Info"] = "info";
136
- /** JSDoc */
137
- Severity["Debug"] = "debug";
138
- /** JSDoc */
139
- Severity["Critical"] = "critical";
140
- })(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 = {}));
230
-
231
87
  /**
232
88
  * Consumes the promise and logs the error when it rejects.
233
89
  * @param promise A promise to forget.
@@ -241,6 +97,33 @@ var Sentry = (function (exports) {
241
97
  });
242
98
  }
243
99
 
100
+ /**
101
+ * This module mostly exists for optimizations in the build process
102
+ * through rollup and terser. We define some global constants which
103
+ * are normally undefined. However terser overrides these with global
104
+ * definitions which can be evaluated by the static analyzer when
105
+ * creating a bundle.
106
+ *
107
+ * In turn the `isDebugBuild` and `isBrowserBundle` functions are pure
108
+ * and can help us remove unused code from the bundles.
109
+ */
110
+ /**
111
+ * Figures out if we're building with debug functionality.
112
+ *
113
+ * @returns true if this is a debug build
114
+ */
115
+ function isDebugBuild() {
116
+ return typeof __SENTRY_NO_DEBUG__ !== 'undefined' && !__SENTRY_BROWSER_BUNDLE__;
117
+ }
118
+ /**
119
+ * Figures out if we're building a browser bundle.
120
+ *
121
+ * @returns true if this is a browser bundle build.
122
+ */
123
+ function isBrowserBundle() {
124
+ return typeof __SENTRY_BROWSER_BUNDLE__ !== 'undefined' && !!__SENTRY_BROWSER_BUNDLE__;
125
+ }
126
+
244
127
  /**
245
128
  * NOTE: In order to avoid circular dependencies, if you add a function to this module and it needs to print something,
246
129
  * you must either a) use `console.log` rather than the logger, or b) put your function elsewhere.
@@ -251,7 +134,10 @@ var Sentry = (function (exports) {
251
134
  * @returns Answer to given question
252
135
  */
253
136
  function isNodeEnv() {
254
- return Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
137
+ // explicitly check for browser bundles as those can be optimized statically
138
+ // by terser/rollup.
139
+ return (!isBrowserBundle() &&
140
+ Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]');
255
141
  }
256
142
  /**
257
143
  * Requires a module which is protected against bundler minification.
@@ -286,6 +172,8 @@ var Sentry = (function (exports) {
286
172
 
287
173
  /* eslint-disable @typescript-eslint/no-explicit-any */
288
174
  /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
175
+ // eslint-disable-next-line @typescript-eslint/unbound-method
176
+ var objectToString = Object.prototype.toString;
289
177
  /**
290
178
  * Checks whether given value's type is one of a few Error or Error-like
291
179
  * {@link isError}.
@@ -294,17 +182,18 @@ var Sentry = (function (exports) {
294
182
  * @returns A boolean representing the result.
295
183
  */
296
184
  function isError(wat) {
297
- switch (Object.prototype.toString.call(wat)) {
185
+ switch (objectToString.call(wat)) {
298
186
  case '[object Error]':
299
- return true;
300
187
  case '[object Exception]':
301
- return true;
302
188
  case '[object DOMException]':
303
189
  return true;
304
190
  default:
305
191
  return isInstanceOf(wat, Error);
306
192
  }
307
193
  }
194
+ function isBuiltin(wat, ty) {
195
+ return objectToString.call(wat) === "[object " + ty + "]";
196
+ }
308
197
  /**
309
198
  * Checks whether given value's type is ErrorEvent
310
199
  * {@link isErrorEvent}.
@@ -313,7 +202,7 @@ var Sentry = (function (exports) {
313
202
  * @returns A boolean representing the result.
314
203
  */
315
204
  function isErrorEvent(wat) {
316
- return Object.prototype.toString.call(wat) === '[object ErrorEvent]';
205
+ return isBuiltin(wat, 'ErrorEvent');
317
206
  }
318
207
  /**
319
208
  * Checks whether given value's type is DOMError
@@ -323,7 +212,7 @@ var Sentry = (function (exports) {
323
212
  * @returns A boolean representing the result.
324
213
  */
325
214
  function isDOMError(wat) {
326
- return Object.prototype.toString.call(wat) === '[object DOMError]';
215
+ return isBuiltin(wat, 'DOMError');
327
216
  }
328
217
  /**
329
218
  * Checks whether given value's type is DOMException
@@ -333,7 +222,7 @@ var Sentry = (function (exports) {
333
222
  * @returns A boolean representing the result.
334
223
  */
335
224
  function isDOMException(wat) {
336
- return Object.prototype.toString.call(wat) === '[object DOMException]';
225
+ return isBuiltin(wat, 'DOMException');
337
226
  }
338
227
  /**
339
228
  * Checks whether given value's type is a string
@@ -343,7 +232,7 @@ var Sentry = (function (exports) {
343
232
  * @returns A boolean representing the result.
344
233
  */
345
234
  function isString(wat) {
346
- return Object.prototype.toString.call(wat) === '[object String]';
235
+ return isBuiltin(wat, 'String');
347
236
  }
348
237
  /**
349
238
  * Checks whether given value's is a primitive (undefined, null, number, boolean, string, bigint, symbol)
@@ -363,7 +252,7 @@ var Sentry = (function (exports) {
363
252
  * @returns A boolean representing the result.
364
253
  */
365
254
  function isPlainObject(wat) {
366
- return Object.prototype.toString.call(wat) === '[object Object]';
255
+ return isBuiltin(wat, 'Object');
367
256
  }
368
257
  /**
369
258
  * Checks whether given value's type is an Event instance
@@ -393,7 +282,7 @@ var Sentry = (function (exports) {
393
282
  * @returns A boolean representing the result.
394
283
  */
395
284
  function isRegExp(wat) {
396
- return Object.prototype.toString.call(wat) === '[object RegExp]';
285
+ return isBuiltin(wat, 'RegExp');
397
286
  }
398
287
  /**
399
288
  * Checks whether given value has a then function.
@@ -477,7 +366,6 @@ var Sentry = (function (exports) {
477
366
  * @returns generated DOM path
478
367
  */
479
368
  function _htmlElementAsString(el, keyAttrs) {
480
- var _a, _b;
481
369
  var elem = el;
482
370
  var out = [];
483
371
  var className;
@@ -490,9 +378,10 @@ var Sentry = (function (exports) {
490
378
  }
491
379
  out.push(elem.tagName.toLowerCase());
492
380
  // 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)]; })
381
+ var keyAttrPairs = keyAttrs && keyAttrs.length
382
+ ? keyAttrs.filter(function (keyAttr) { return elem.getAttribute(keyAttr); }).map(function (keyAttr) { return [keyAttr, elem.getAttribute(keyAttr)]; })
494
383
  : null;
495
- if ((_b = keyAttrPairs) === null || _b === void 0 ? void 0 : _b.length) {
384
+ if (keyAttrPairs && keyAttrPairs.length) {
496
385
  keyAttrPairs.forEach(function (keyAttrPair) {
497
386
  out.push("[" + keyAttrPair[0] + "=\"" + keyAttrPair[1] + "\"]");
498
387
  });
@@ -573,92 +462,89 @@ var Sentry = (function (exports) {
573
462
 
574
463
  /** Regular expression used to parse a Dsn. */
575
464
  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();
465
+ function isValidProtocol(protocol) {
466
+ return protocol === 'http' || protocol === 'https';
467
+ }
468
+ /**
469
+ * Renders the string representation of this Dsn.
470
+ *
471
+ * By default, this will render the public representation without the password
472
+ * component. To get the deprecated private representation, set `withPassword`
473
+ * to true.
474
+ *
475
+ * @param withPassword When set to true, the password will be included.
476
+ */
477
+ function dsnToString(dsn, withPassword) {
478
+ if (withPassword === void 0) { withPassword = false; }
479
+ var host = dsn.host, path = dsn.path, pass = dsn.pass, port = dsn.port, projectId = dsn.projectId, protocol = dsn.protocol, publicKey = dsn.publicKey;
480
+ return (protocol + "://" + publicKey + (withPassword && pass ? ":" + pass : '') +
481
+ ("@" + host + (port ? ":" + port : '') + "/" + (path ? path + "/" : path) + projectId));
482
+ }
483
+ function dsnFromString(str) {
484
+ var match = DSN_REGEX.exec(str);
485
+ if (!match) {
486
+ throw new SentryError('Invalid Dsn');
589
487
  }
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);
488
+ 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];
489
+ var path = '';
490
+ var projectId = lastPath;
491
+ var split = projectId.split('/');
492
+ if (split.length > 1) {
493
+ path = split.slice(0, -1).join('/');
494
+ projectId = split.pop();
495
+ }
496
+ if (projectId) {
497
+ var projectMatch = projectId.match(/^\d+/);
498
+ if (projectMatch) {
499
+ projectId = projectMatch[0];
658
500
  }
501
+ }
502
+ return dsnFromComponents({ host: host, pass: pass, path: path, projectId: projectId, port: port, protocol: protocol, publicKey: publicKey });
503
+ }
504
+ function dsnFromComponents(components) {
505
+ // TODO this is for backwards compatibility, and can be removed in a future version
506
+ if ('user' in components && !('publicKey' in components)) {
507
+ components.publicKey = components.user;
508
+ }
509
+ return {
510
+ user: components.publicKey || '',
511
+ protocol: components.protocol,
512
+ publicKey: components.publicKey || '',
513
+ pass: components.pass || '',
514
+ host: components.host,
515
+ port: components.port || '',
516
+ path: components.path || '',
517
+ projectId: components.projectId,
659
518
  };
660
- return Dsn;
661
- }());
519
+ }
520
+ function validateDsn(dsn) {
521
+ if (!isDebugBuild()) {
522
+ return;
523
+ }
524
+ var port = dsn.port, projectId = dsn.projectId, protocol = dsn.protocol;
525
+ var requiredComponents = ['protocol', 'publicKey', 'host', 'projectId'];
526
+ requiredComponents.forEach(function (component) {
527
+ if (!dsn[component]) {
528
+ throw new SentryError("Invalid Dsn: " + component + " missing");
529
+ }
530
+ });
531
+ if (!projectId.match(/^\d+$/)) {
532
+ throw new SentryError("Invalid Dsn: Invalid projectId " + projectId);
533
+ }
534
+ if (!isValidProtocol(protocol)) {
535
+ throw new SentryError("Invalid Dsn: Invalid protocol " + protocol);
536
+ }
537
+ if (port && isNaN(parseInt(port, 10))) {
538
+ throw new SentryError("Invalid Dsn: Invalid port " + port);
539
+ }
540
+ return true;
541
+ }
542
+ /** The Sentry Dsn, identifying a Sentry instance and project. */
543
+ function makeDsn(from) {
544
+ var components = typeof from === 'string' ? dsnFromString(from) : dsnFromComponents(from);
545
+ validateDsn(components);
546
+ return components;
547
+ }
662
548
 
663
549
  // TODO: Implement different loggers for different environments
664
550
  var global$1 = getGlobalObject();
@@ -757,56 +643,45 @@ var Sentry = (function (exports) {
757
643
 
758
644
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
759
645
  /* eslint-disable @typescript-eslint/no-explicit-any */
760
- /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
761
646
  /**
762
- * Memo class used for decycle json objects. Uses WeakSet if available otherwise array.
647
+ * Helper to decycle json objects
763
648
  */
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)) {
649
+ function memoBuilder() {
650
+ var hasWeakSet = typeof WeakSet === 'function';
651
+ var inner = hasWeakSet ? new WeakSet() : [];
652
+ function memoize(obj) {
653
+ if (hasWeakSet) {
654
+ if (inner.has(obj)) {
776
655
  return true;
777
656
  }
778
- this._inner.add(obj);
657
+ inner.add(obj);
779
658
  return false;
780
659
  }
781
660
  // 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];
661
+ for (var i = 0; i < inner.length; i++) {
662
+ var value = inner[i];
784
663
  if (value === obj) {
785
664
  return true;
786
665
  }
787
666
  }
788
- this._inner.push(obj);
667
+ inner.push(obj);
789
668
  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);
669
+ }
670
+ function unmemoize(obj) {
671
+ if (hasWeakSet) {
672
+ inner.delete(obj);
798
673
  }
799
674
  else {
800
- for (var i = 0; i < this._inner.length; i++) {
801
- if (this._inner[i] === obj) {
802
- this._inner.splice(i, 1);
675
+ for (var i = 0; i < inner.length; i++) {
676
+ if (inner[i] === obj) {
677
+ inner.splice(i, 1);
803
678
  break;
804
679
  }
805
680
  }
806
681
  }
807
- };
808
- return Memo;
809
- }());
682
+ }
683
+ return [memoize, unmemoize];
684
+ }
810
685
 
811
686
  var defaultFunctionName = '<anonymous>';
812
687
  /**
@@ -903,13 +778,7 @@ var Sentry = (function (exports) {
903
778
  // otherwise it'll throw "TypeError: Object.defineProperties called on non-object"
904
779
  if (typeof wrapped === 'function') {
905
780
  try {
906
- wrapped.prototype = wrapped.prototype || {};
907
- Object.defineProperties(wrapped, {
908
- __sentry_original__: {
909
- enumerable: false,
910
- value: original,
911
- },
912
- });
781
+ markFunctionWrapped(wrapped, original);
913
782
  }
914
783
  catch (_Oo) {
915
784
  // This can throw if multiple fill happens on a global object like XMLHttpRequest
@@ -918,6 +787,41 @@ var Sentry = (function (exports) {
918
787
  }
919
788
  source[name] = wrapped;
920
789
  }
790
+ /**
791
+ * Defines a non enumerable property. This creates a non enumerable property on an object.
792
+ *
793
+ * @param func The function to set a property to
794
+ * @param name the name of the special sentry property
795
+ * @param value the property to define
796
+ */
797
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
798
+ function addNonEnumerableProperty(func, name, value) {
799
+ Object.defineProperty(func, name, {
800
+ value: value,
801
+ });
802
+ }
803
+ /**
804
+ * Remembers the original function on the wrapped function and
805
+ * patches up the prototype.
806
+ *
807
+ * @param wrapped the wrapper function
808
+ * @param original the original function that gets wrapped
809
+ */
810
+ function markFunctionWrapped(wrapped, original) {
811
+ var proto = original.prototype || {};
812
+ wrapped.prototype = original.prototype = proto;
813
+ addNonEnumerableProperty(wrapped, '__sentry_original__', original);
814
+ }
815
+ /**
816
+ * This extracts the original function if available. See
817
+ * `markFunctionWrapped` for more information.
818
+ *
819
+ * @param func the function to unwrap
820
+ * @returns the unwrapped version of the function if available.
821
+ */
822
+ function getOriginalFunction(func) {
823
+ return func.__sentry_original__;
824
+ }
921
825
  /**
922
826
  * Encodes given object into url-friendly format
923
827
  *
@@ -1018,11 +922,11 @@ var Sentry = (function (exports) {
1018
922
  * unchanged.
1019
923
  */
1020
924
  function serializeValue(value) {
1021
- var type = Object.prototype.toString.call(value);
1022
925
  // Node.js REPL notation
1023
926
  if (typeof value === 'string') {
1024
927
  return value;
1025
928
  }
929
+ var type = Object.prototype.toString.call(value);
1026
930
  if (type === '[object Object]') {
1027
931
  return '[Object]';
1028
932
  }
@@ -1094,7 +998,7 @@ var Sentry = (function (exports) {
1094
998
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1095
999
  function walk(key, value, depth, memo) {
1096
1000
  if (depth === void 0) { depth = +Infinity; }
1097
- if (memo === void 0) { memo = new Memo(); }
1001
+ if (memo === void 0) { memo = memoBuilder(); }
1098
1002
  // If we reach the maximum depth, serialize whatever has left
1099
1003
  if (depth === 0) {
1100
1004
  return serializeValue(value);
@@ -1115,7 +1019,7 @@ var Sentry = (function (exports) {
1115
1019
  // Create an accumulator that will act as a parent for all future itterations of that branch
1116
1020
  var acc = Array.isArray(value) ? [] : {};
1117
1021
  // If we already walked that branch, bail out, as it's circular reference
1118
- if (memo.memoize(value)) {
1022
+ if (memo[0](value)) {
1119
1023
  return '[Circular ~]';
1120
1024
  }
1121
1025
  // Walk all keys of the source
@@ -1128,7 +1032,7 @@ var Sentry = (function (exports) {
1128
1032
  acc[innerKey] = walk(innerKey, source[innerKey], depth - 1, memo);
1129
1033
  }
1130
1034
  // Once walked through all the branches, remove the parent from memo storage
1131
- memo.unmemoize(value);
1035
+ memo[1](value);
1132
1036
  // Return accumulated values
1133
1037
  return acc;
1134
1038
  }
@@ -1273,7 +1177,9 @@ var Sentry = (function (exports) {
1273
1177
  doc.head.removeChild(sandbox);
1274
1178
  }
1275
1179
  catch (err) {
1276
- logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', err);
1180
+ if (isDebugBuild()) {
1181
+ logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', err);
1182
+ }
1277
1183
  }
1278
1184
  }
1279
1185
  return result;
@@ -1372,13 +1278,10 @@ var Sentry = (function (exports) {
1372
1278
  * Use at your own risk, this might break without changelog notice, only used internally.
1373
1279
  * @hidden
1374
1280
  */
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);
1281
+ function addInstrumentationHandler(type, callback) {
1282
+ handlers[type] = handlers[type] || [];
1283
+ handlers[type].push(callback);
1284
+ instrument(type);
1382
1285
  }
1383
1286
  /** JSDoc */
1384
1287
  function triggerHandlers(type, data) {
@@ -1393,7 +1296,9 @@ var Sentry = (function (exports) {
1393
1296
  handler(data);
1394
1297
  }
1395
1298
  catch (e) {
1396
- logger.error("Error while triggering instrumentation handler.\nType: " + type + "\nName: " + getFunctionName(handler) + "\nError: " + e);
1299
+ if (isDebugBuild()) {
1300
+ logger.error("Error while triggering instrumentation handler.\nType: " + type + "\nName: " + getFunctionName(handler) + "\nError: " + e);
1301
+ }
1397
1302
  }
1398
1303
  }
1399
1304
  }
@@ -1505,14 +1410,14 @@ var Sentry = (function (exports) {
1505
1410
  // eslint-disable-next-line @typescript-eslint/no-this-alias
1506
1411
  var xhr = this;
1507
1412
  var url = args[1];
1508
- xhr.__sentry_xhr__ = {
1413
+ var xhrInfo = (xhr.__sentry_xhr__ = {
1509
1414
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1510
1415
  method: isString(args[0]) ? args[0].toUpperCase() : args[0],
1511
1416
  url: args[1],
1512
- };
1417
+ });
1513
1418
  // if Sentry key appears in URL, don't capture it as a request
1514
1419
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1515
- if (isString(url) && xhr.__sentry_xhr__.method === 'POST' && url.match(/sentry_key/)) {
1420
+ if (isString(url) && xhrInfo.method === 'POST' && url.match(/sentry_key/)) {
1516
1421
  xhr.__sentry_own_request__ = true;
1517
1422
  }
1518
1423
  var onreadystatechangeHandler = function () {
@@ -1520,9 +1425,7 @@ var Sentry = (function (exports) {
1520
1425
  try {
1521
1426
  // touching statusCode in some platforms throws
1522
1427
  // an exception
1523
- if (xhr.__sentry_xhr__) {
1524
- xhr.__sentry_xhr__.status_code = xhr.status;
1525
- }
1428
+ xhrInfo.status_code = xhr.status;
1526
1429
  }
1527
1430
  catch (e) {
1528
1431
  /* do nothing */
@@ -1533,8 +1436,8 @@ var Sentry = (function (exports) {
1533
1436
  // Make sure to pop both key and value to keep it in sync.
1534
1437
  requestKeys.splice(requestPos);
1535
1438
  var args_1 = requestValues.splice(requestPos)[0];
1536
- if (xhr.__sentry_xhr__ && args_1[0] !== undefined) {
1537
- xhr.__sentry_xhr__.body = args_1[0];
1439
+ if (args_1[0] !== undefined) {
1440
+ xhrInfo.body = args_1[0];
1538
1441
  }
1539
1442
  }
1540
1443
  }
@@ -1918,22 +1821,26 @@ var Sentry = (function (exports) {
1918
1821
  relative: match[5] + query + fragment,
1919
1822
  };
1920
1823
  }
1824
+ function getFirstException(event) {
1825
+ return event.exception && event.exception.values ? event.exception.values[0] : undefined;
1826
+ }
1921
1827
  /**
1922
1828
  * Extracts either message or type+value from an event that can be used for user-facing logs
1923
1829
  * @returns event's description
1924
1830
  */
1925
1831
  function getEventDescription(event) {
1926
- if (event.message) {
1927
- return event.message;
1832
+ var message = event.message, eventId = event.event_id;
1833
+ if (message) {
1834
+ return message;
1928
1835
  }
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;
1836
+ var firstException = getFirstException(event);
1837
+ if (firstException) {
1838
+ if (firstException.type && firstException.value) {
1839
+ return firstException.type + ": " + firstException.value;
1933
1840
  }
1934
- return exception.type || exception.value || event.event_id || '<unknown>';
1841
+ return firstException.type || firstException.value || eventId || '<unknown>';
1935
1842
  }
1936
- return event.event_id || '<unknown>';
1843
+ return eventId || '<unknown>';
1937
1844
  }
1938
1845
  /**
1939
1846
  * Adds exception values, type and value to an synthetic Exception.
@@ -1943,11 +1850,15 @@ var Sentry = (function (exports) {
1943
1850
  * @hidden
1944
1851
  */
1945
1852
  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';
1853
+ var exception = (event.exception = event.exception || {});
1854
+ var values = (exception.values = exception.values || []);
1855
+ var firstException = (values[0] = values[0] || {});
1856
+ if (!firstException.value) {
1857
+ firstException.value = value || '';
1858
+ }
1859
+ if (!firstException.type) {
1860
+ firstException.type = type || 'Error';
1861
+ }
1951
1862
  }
1952
1863
  /**
1953
1864
  * Adds exception mechanism data to a given event. Uses defaults if the second parameter is not passed.
@@ -1957,17 +1868,16 @@ var Sentry = (function (exports) {
1957
1868
  * @hidden
1958
1869
  */
1959
1870
  function addExceptionMechanism(event, newMechanism) {
1960
- var _a;
1961
- if (!event.exception || !event.exception.values) {
1871
+ var firstException = getFirstException(event);
1872
+ if (!firstException) {
1962
1873
  return;
1963
1874
  }
1964
- var exceptionValue0 = event.exception.values[0];
1965
1875
  var defaultMechanism = { type: 'generic', handled: true };
1966
- var currentMechanism = exceptionValue0.mechanism;
1967
- exceptionValue0.mechanism = __assign(__assign(__assign({}, defaultMechanism), currentMechanism), newMechanism);
1876
+ var currentMechanism = firstException.mechanism;
1877
+ firstException.mechanism = __assign(__assign(__assign({}, defaultMechanism), currentMechanism), newMechanism);
1968
1878
  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;
1879
+ var mergedData = __assign(__assign({}, (currentMechanism && currentMechanism.data)), newMechanism.data);
1880
+ firstException.mechanism.data = mergedData;
1971
1881
  }
1972
1882
  }
1973
1883
  var defaultRetryAfter = 60 * 1000; // 60 seconds
@@ -2012,17 +1922,14 @@ var Sentry = (function (exports) {
2012
1922
  * @returns `true` if the exception has already been captured, `false` if not (with the side effect of marking it seen)
2013
1923
  */
2014
1924
  function checkOrSetAlreadyCaught(exception) {
2015
- var _a;
2016
1925
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
2017
- if ((_a = exception) === null || _a === void 0 ? void 0 : _a.__sentry_captured__) {
1926
+ if (exception && exception.__sentry_captured__) {
2018
1927
  return true;
2019
1928
  }
2020
1929
  try {
2021
1930
  // set it this way rather than by assignment so that it's not ennumerable and therefore isn't recorded by the
2022
1931
  // `ExtraErrorData` integration
2023
- Object.defineProperty(exception, '__sentry_captured__', {
2024
- value: true,
2025
- });
1932
+ addNonEnumerableProperty(exception, '__sentry_captured__', true);
2026
1933
  }
2027
1934
  catch (err) {
2028
1935
  // `exception` is a primitive, so we can't mark it seen
@@ -2031,16 +1938,28 @@ var Sentry = (function (exports) {
2031
1938
  }
2032
1939
 
2033
1940
  /* 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 = {}));
1941
+ /**
1942
+ * Creates a resolved sync promise.
1943
+ *
1944
+ * @param value the value to resolve the promise with
1945
+ * @returns the resolved sync promise
1946
+ */
1947
+ function resolvedSyncPromise(value) {
1948
+ return new SyncPromise(function (resolve) {
1949
+ resolve(value);
1950
+ });
1951
+ }
1952
+ /**
1953
+ * Creates a rejected sync promise.
1954
+ *
1955
+ * @param value the value to reject the promise with
1956
+ * @returns the rejected sync promise
1957
+ */
1958
+ function rejectedSyncPromise(reason) {
1959
+ return new SyncPromise(function (_, reject) {
1960
+ reject(reason);
1961
+ });
1962
+ }
2044
1963
  /**
2045
1964
  * Thenable class that behaves like a Promise and follows it's interface
2046
1965
  * but is not async internally
@@ -2048,19 +1967,19 @@ var Sentry = (function (exports) {
2048
1967
  var SyncPromise = /** @class */ (function () {
2049
1968
  function SyncPromise(executor) {
2050
1969
  var _this = this;
2051
- this._state = States.PENDING;
1970
+ this._state = 0 /* PENDING */;
2052
1971
  this._handlers = [];
2053
1972
  /** JSDoc */
2054
1973
  this._resolve = function (value) {
2055
- _this._setResult(States.RESOLVED, value);
1974
+ _this._setResult(1 /* RESOLVED */, value);
2056
1975
  };
2057
1976
  /** JSDoc */
2058
1977
  this._reject = function (reason) {
2059
- _this._setResult(States.REJECTED, reason);
1978
+ _this._setResult(2 /* REJECTED */, reason);
2060
1979
  };
2061
1980
  /** JSDoc */
2062
1981
  this._setResult = function (state, value) {
2063
- if (_this._state !== States.PENDING) {
1982
+ if (_this._state !== 0 /* PENDING */) {
2064
1983
  return;
2065
1984
  }
2066
1985
  if (isThenable(value)) {
@@ -2071,35 +1990,25 @@ var Sentry = (function (exports) {
2071
1990
  _this._value = value;
2072
1991
  _this._executeHandlers();
2073
1992
  };
2074
- // TODO: FIXME
2075
- /** JSDoc */
2076
- this._attachHandler = function (handler) {
2077
- _this._handlers = _this._handlers.concat(handler);
2078
- _this._executeHandlers();
2079
- };
2080
1993
  /** JSDoc */
2081
1994
  this._executeHandlers = function () {
2082
- if (_this._state === States.PENDING) {
1995
+ if (_this._state === 0 /* PENDING */) {
2083
1996
  return;
2084
1997
  }
2085
1998
  var cachedHandlers = _this._handlers.slice();
2086
1999
  _this._handlers = [];
2087
2000
  cachedHandlers.forEach(function (handler) {
2088
- if (handler.done) {
2001
+ if (handler[0]) {
2089
2002
  return;
2090
2003
  }
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
- }
2004
+ if (_this._state === 1 /* RESOLVED */) {
2005
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
2006
+ handler[1](_this._value);
2096
2007
  }
2097
- if (_this._state === States.REJECTED) {
2098
- if (handler.onrejected) {
2099
- handler.onrejected(_this._value);
2100
- }
2008
+ if (_this._state === 2 /* REJECTED */) {
2009
+ handler[2](_this._value);
2101
2010
  }
2102
- handler.done = true;
2011
+ handler[0] = true;
2103
2012
  });
2104
2013
  };
2105
2014
  try {
@@ -2110,81 +2019,41 @@ var Sentry = (function (exports) {
2110
2019
  }
2111
2020
  }
2112
2021
  /** 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
2022
  SyncPromise.prototype.then = function (onfulfilled, onrejected) {
2153
2023
  var _this = this;
2154
2024
  return new SyncPromise(function (resolve, reject) {
2155
- _this._attachHandler({
2156
- done: false,
2157
- onfulfilled: function (result) {
2025
+ _this._handlers.push([
2026
+ false,
2027
+ function (result) {
2158
2028
  if (!onfulfilled) {
2159
2029
  // TODO: ¯\_(ツ)_/¯
2160
2030
  // TODO: FIXME
2161
2031
  resolve(result);
2162
- return;
2163
- }
2164
- try {
2165
- resolve(onfulfilled(result));
2166
- return;
2167
2032
  }
2168
- catch (e) {
2169
- reject(e);
2170
- return;
2033
+ else {
2034
+ try {
2035
+ resolve(onfulfilled(result));
2036
+ }
2037
+ catch (e) {
2038
+ reject(e);
2039
+ }
2171
2040
  }
2172
2041
  },
2173
- onrejected: function (reason) {
2042
+ function (reason) {
2174
2043
  if (!onrejected) {
2175
2044
  reject(reason);
2176
- return;
2177
2045
  }
2178
- try {
2179
- resolve(onrejected(reason));
2180
- return;
2181
- }
2182
- catch (e) {
2183
- reject(e);
2184
- return;
2046
+ else {
2047
+ try {
2048
+ resolve(onrejected(reason));
2049
+ }
2050
+ catch (e) {
2051
+ reject(e);
2052
+ }
2185
2053
  }
2186
2054
  },
2187
- });
2055
+ ]);
2056
+ _this._executeHandlers();
2188
2057
  });
2189
2058
  };
2190
2059
  /** JSDoc */
@@ -2218,26 +2087,27 @@ var Sentry = (function (exports) {
2218
2087
  });
2219
2088
  });
2220
2089
  };
2221
- /** JSDoc */
2222
- SyncPromise.prototype.toString = function () {
2223
- return '[object SyncPromise]';
2224
- };
2225
2090
  return SyncPromise;
2226
2091
  }());
2227
2092
 
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 = [];
2093
+ /**
2094
+ * Creates an new PromiseBuffer object with the specified limit
2095
+ * @param limit max number of promises that can be stored in the buffer
2096
+ */
2097
+ function makePromiseBuffer(limit) {
2098
+ var buffer = [];
2099
+ function isReady() {
2100
+ return limit === undefined || buffer.length < limit;
2234
2101
  }
2235
2102
  /**
2236
- * Says if the buffer is ready to take more requests
2103
+ * Remove a promise from the queue.
2104
+ *
2105
+ * @param task Can be any PromiseLike<T>
2106
+ * @returns Removed promise.
2237
2107
  */
2238
- PromiseBuffer.prototype.isReady = function () {
2239
- return this._limit === undefined || this.length() < this._limit;
2240
- };
2108
+ function remove(task) {
2109
+ return buffer.splice(buffer.indexOf(task), 1)[0];
2110
+ }
2241
2111
  /**
2242
2112
  * Add a promise (representing an in-flight action) to the queue, and set it to remove itself on fulfillment.
2243
2113
  *
@@ -2248,44 +2118,27 @@ var Sentry = (function (exports) {
2248
2118
  * limit check.
2249
2119
  * @returns The original promise.
2250
2120
  */
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.'));
2121
+ function add(taskProducer) {
2122
+ if (!isReady()) {
2123
+ return rejectedSyncPromise(new SentryError('Not adding Promise due to buffer limit reached.'));
2255
2124
  }
2256
2125
  // start the task and add its promise to the queue
2257
2126
  var task = taskProducer();
2258
- if (this._buffer.indexOf(task) === -1) {
2259
- this._buffer.push(task);
2127
+ if (buffer.indexOf(task) === -1) {
2128
+ buffer.push(task);
2260
2129
  }
2261
2130
  void task
2262
- .then(function () { return _this.remove(task); })
2131
+ .then(function () { return remove(task); })
2263
2132
  // Use `then(null, rejectionHandler)` rather than `catch(rejectionHandler)` so that we can use `PromiseLike`
2264
2133
  // rather than `Promise`. `PromiseLike` doesn't have a `.catch` method, making its polyfill smaller. (ES5 didn't
2265
2134
  // have promises, so TS has to polyfill when down-compiling.)
2266
2135
  .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.
2136
+ return remove(task).then(null, function () {
2137
+ // We have to add another catch here because `remove()` starts a new promise chain.
2269
2138
  });
2270
2139
  });
2271
2140
  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
- };
2141
+ }
2289
2142
  /**
2290
2143
  * Wait for all promises in the queue to resolve or for timeout to expire, whichever comes first.
2291
2144
  *
@@ -2295,9 +2148,12 @@ var Sentry = (function (exports) {
2295
2148
  * @returns A promise which will resolve to `true` if the queue is already empty or drains before the timeout, and
2296
2149
  * `false` otherwise
2297
2150
  */
2298
- PromiseBuffer.prototype.drain = function (timeout) {
2299
- var _this = this;
2300
- return new SyncPromise(function (resolve) {
2151
+ function drain(timeout) {
2152
+ return new SyncPromise(function (resolve, reject) {
2153
+ var counter = buffer.length;
2154
+ if (!counter) {
2155
+ return resolve(true);
2156
+ }
2301
2157
  // wait for `timeout` ms and then resolve to `false` (if not cancelled first)
2302
2158
  var capturedSetTimeout = setTimeout(function () {
2303
2159
  if (timeout && timeout > 0) {
@@ -2305,18 +2161,85 @@ var Sentry = (function (exports) {
2305
2161
  }
2306
2162
  }, timeout);
2307
2163
  // 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);
2164
+ buffer.forEach(function (item) {
2165
+ void resolvedSyncPromise(item).then(function () {
2166
+ // eslint-disable-next-line no-plusplus
2167
+ if (!--counter) {
2168
+ clearTimeout(capturedSetTimeout);
2169
+ resolve(true);
2170
+ }
2171
+ }, reject);
2315
2172
  });
2316
2173
  });
2174
+ }
2175
+ return {
2176
+ $: buffer,
2177
+ add: add,
2178
+ drain: drain,
2317
2179
  };
2318
- return PromiseBuffer;
2319
- }());
2180
+ }
2181
+
2182
+ /** JSDoc
2183
+ * @deprecated Use string literals - if you require type casting, cast to SeverityLevel type
2184
+ */
2185
+ var Severity;
2186
+ (function (Severity) {
2187
+ /** JSDoc */
2188
+ Severity["Fatal"] = "fatal";
2189
+ /** JSDoc */
2190
+ Severity["Error"] = "error";
2191
+ /** JSDoc */
2192
+ Severity["Warning"] = "warning";
2193
+ /** JSDoc */
2194
+ Severity["Log"] = "log";
2195
+ /** JSDoc */
2196
+ Severity["Info"] = "info";
2197
+ /** JSDoc */
2198
+ Severity["Debug"] = "debug";
2199
+ /** JSDoc */
2200
+ Severity["Critical"] = "critical";
2201
+ })(Severity || (Severity = {}));
2202
+ var SeverityLevels = ['fatal', 'error', 'warning', 'log', 'info', 'debug', 'critical'];
2203
+
2204
+ function isSupportedSeverity(level) {
2205
+ return SeverityLevels.indexOf(level) !== -1;
2206
+ }
2207
+ /**
2208
+ * Converts a string-based level into a {@link Severity}.
2209
+ *
2210
+ * @param level string representation of Severity
2211
+ * @returns Severity
2212
+ */
2213
+ function severityFromString(level) {
2214
+ if (level === 'warn')
2215
+ return 'warning';
2216
+ if (isSupportedSeverity(level)) {
2217
+ return level;
2218
+ }
2219
+ return 'log';
2220
+ }
2221
+
2222
+ /**
2223
+ * Converts an HTTP status code to sentry status {@link EventStatus}.
2224
+ *
2225
+ * @param code number HTTP status code
2226
+ * @returns EventStatus
2227
+ */
2228
+ function eventStatusFromHttpCode(code) {
2229
+ if (code >= 200 && code < 300) {
2230
+ return 'success';
2231
+ }
2232
+ if (code === 429) {
2233
+ return 'rate_limit';
2234
+ }
2235
+ if (code >= 400 && code < 500) {
2236
+ return 'invalid';
2237
+ }
2238
+ if (code >= 500) {
2239
+ return 'failed';
2240
+ }
2241
+ return 'unknown';
2242
+ }
2320
2243
 
2321
2244
  /**
2322
2245
  * A TimestampSource implementation for environments that do not support the Performance Web API natively.
@@ -2639,15 +2562,14 @@ var Sentry = (function (exports) {
2639
2562
  * @inheritDoc
2640
2563
  */
2641
2564
  Scope.prototype.getTransaction = function () {
2642
- var _a, _b, _c, _d;
2643
2565
  // often, this span will be a transaction, but it's not guaranteed to be
2644
2566
  var span = this.getSpan();
2645
2567
  // 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;
2568
+ if (span && span.transaction) {
2569
+ return span.transaction;
2648
2570
  }
2649
2571
  // 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]) {
2572
+ if (span && span.spanRecorder && span.spanRecorder.spans[0]) {
2651
2573
  return span.spanRecorder.spans[0];
2652
2574
  }
2653
2575
  // neither way found a transaction
@@ -2770,7 +2692,6 @@ var Sentry = (function (exports) {
2770
2692
  * @hidden
2771
2693
  */
2772
2694
  Scope.prototype.applyToEvent = function (event, hint) {
2773
- var _a;
2774
2695
  if (this._extra && Object.keys(this._extra).length) {
2775
2696
  event.extra = __assign(__assign({}, this._extra), event.extra);
2776
2697
  }
@@ -2794,7 +2715,7 @@ var Sentry = (function (exports) {
2794
2715
  // errors with transaction and it relies on that.
2795
2716
  if (this._span) {
2796
2717
  event.contexts = __assign({ trace: this._span.getTraceContext() }, event.contexts);
2797
- var transactionName = (_a = this._span.transaction) === null || _a === void 0 ? void 0 : _a.name;
2718
+ var transactionName = this._span.transaction && this._span.transaction.name;
2798
2719
  if (transactionName) {
2799
2720
  event.tags = __assign({ transaction: transactionName }, event.tags);
2800
2721
  }
@@ -2895,7 +2816,7 @@ var Sentry = (function (exports) {
2895
2816
  this.errors = 0;
2896
2817
  this.sid = uuid4();
2897
2818
  this.duration = 0;
2898
- this.status = SessionStatus.Ok;
2819
+ this.status = 'ok';
2899
2820
  this.init = true;
2900
2821
  this.ignoreDuration = false;
2901
2822
  // Both timestamp and started are in seconds since the UNIX epoch.
@@ -2969,8 +2890,8 @@ var Sentry = (function (exports) {
2969
2890
  if (status) {
2970
2891
  this.update({ status: status });
2971
2892
  }
2972
- else if (this.status === SessionStatus.Ok) {
2973
- this.update({ status: SessionStatus.Exited });
2893
+ else if (this.status === 'ok') {
2894
+ this.update({ status: 'exited' });
2974
2895
  }
2975
2896
  else {
2976
2897
  this.update();
@@ -2988,12 +2909,12 @@ var Sentry = (function (exports) {
2988
2909
  errors: this.errors,
2989
2910
  did: typeof this.did === 'number' || typeof this.did === 'string' ? "" + this.did : undefined,
2990
2911
  duration: this.duration,
2991
- attrs: dropUndefinedKeys({
2912
+ attrs: {
2992
2913
  release: this.release,
2993
2914
  environment: this.environment,
2994
2915
  ip_address: this.ipAddress,
2995
2916
  user_agent: this.userAgent,
2996
- }),
2917
+ },
2997
2918
  });
2998
2919
  };
2999
2920
  return Session;
@@ -3311,11 +3232,17 @@ var Sentry = (function (exports) {
3311
3232
  * @inheritDoc
3312
3233
  */
3313
3234
  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();
3235
+ var layer = this.getStackTop();
3236
+ var scope = layer && layer.scope;
3237
+ var session = scope && scope.getSession();
3238
+ if (session) {
3239
+ session.close();
3240
+ }
3316
3241
  this._sendSessionUpdate();
3317
3242
  // 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();
3243
+ if (scope) {
3244
+ scope.setSession();
3245
+ }
3319
3246
  };
3320
3247
  /**
3321
3248
  * @inheritDoc
@@ -3331,8 +3258,8 @@ var Sentry = (function (exports) {
3331
3258
  if (scope) {
3332
3259
  // End existing session if there's one
3333
3260
  var currentSession = scope.getSession && scope.getSession();
3334
- if (currentSession && currentSession.status === SessionStatus.Ok) {
3335
- currentSession.update({ status: SessionStatus.Exited });
3261
+ if (currentSession && currentSession.status === 'ok') {
3262
+ currentSession.update({ status: 'exited' });
3336
3263
  }
3337
3264
  this.endSession();
3338
3265
  // Afterwards we set the new session on the scope
@@ -3444,9 +3371,9 @@ var Sentry = (function (exports) {
3444
3371
  * @returns discovered hub
3445
3372
  */
3446
3373
  function getHubFromActiveDomain(registry) {
3447
- var _a, _b, _c;
3448
3374
  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;
3375
+ var sentry = getMainCarrier().__SENTRY__;
3376
+ var activeDomain = sentry && sentry.extensions && sentry.extensions.domain && sentry.extensions.domain.active;
3450
3377
  // If there's no active domain, just return global hub
3451
3378
  if (!activeDomain) {
3452
3379
  return getHubFromCarrier(registry);
@@ -3541,7 +3468,7 @@ var Sentry = (function (exports) {
3541
3468
  * Captures a message event and sends it to Sentry.
3542
3469
  *
3543
3470
  * @param message The message to send to Sentry.
3544
- * @param level Define the level of the message.
3471
+ * @param SeverityLevel Define the level of the message.
3545
3472
  * @returns The generated eventId.
3546
3473
  */
3547
3474
  function captureMessage(message, captureContext) {
@@ -3673,138 +3600,84 @@ var Sentry = (function (exports) {
3673
3600
  }
3674
3601
 
3675
3602
  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/";
3603
+ /** Initializes API Details */
3604
+ function initAPIDetails(dsn, metadata, tunnel) {
3605
+ return {
3606
+ initDsn: dsn,
3607
+ metadata: metadata || {},
3608
+ dsn: makeDsn(dsn),
3609
+ tunnel: tunnel,
3732
3610
  };
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);
3611
+ }
3612
+ /** Returns the prefix to construct Sentry ingestion API endpoints. */
3613
+ function getBaseApiEndpoint(dsn) {
3614
+ var protocol = dsn.protocol ? dsn.protocol + ":" : '';
3615
+ var port = dsn.port ? ":" + dsn.port : '';
3616
+ return protocol + "//" + dsn.host + port + (dsn.path ? "/" + dsn.path : '') + "/api/";
3617
+ }
3618
+ /** Returns the ingest API endpoint for target. */
3619
+ function _getIngestEndpoint(dsn, target) {
3620
+ return "" + getBaseApiEndpoint(dsn) + dsn.projectId + "/" + target + "/";
3621
+ }
3622
+ /** Returns a URL-encoded string with auth config suitable for a query string. */
3623
+ function _encodedAuth(dsn) {
3624
+ return urlEncode({
3625
+ // We send only the minimum set of required information. See
3626
+ // https://github.com/getsentry/sentry-javascript/issues/2572.
3627
+ sentry_key: dsn.publicKey,
3628
+ sentry_version: SENTRY_API_VERSION,
3629
+ });
3630
+ }
3631
+ /** Returns the store endpoint URL. */
3632
+ function getStoreEndpoint(dsn) {
3633
+ return _getIngestEndpoint(dsn, 'store');
3634
+ }
3635
+ /**
3636
+ * Returns the store endpoint URL with auth in the query string.
3637
+ *
3638
+ * Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
3639
+ */
3640
+ function getStoreEndpointWithUrlEncodedAuth(dsn) {
3641
+ return getStoreEndpoint(dsn) + "?" + _encodedAuth(dsn);
3642
+ }
3643
+ /** Returns the envelope endpoint URL. */
3644
+ function _getEnvelopeEndpoint(dsn) {
3645
+ return _getIngestEndpoint(dsn, 'envelope');
3646
+ }
3647
+ /**
3648
+ * Returns the envelope endpoint URL with auth in the query string.
3649
+ *
3650
+ * Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
3651
+ */
3652
+ function getEnvelopeEndpointWithUrlEncodedAuth(dsn, tunnel) {
3653
+ return tunnel ? tunnel : _getEnvelopeEndpoint(dsn) + "?" + _encodedAuth(dsn);
3654
+ }
3655
+ /** Returns the url to the report dialog endpoint. */
3656
+ function getReportDialogEndpoint(dsnLike, dialogOptions) {
3657
+ var dsn = makeDsn(dsnLike);
3658
+ var endpoint = getBaseApiEndpoint(dsn) + "embed/error-page/";
3659
+ var encodedOptions = "dsn=" + dsnToString(dsn);
3660
+ for (var key in dialogOptions) {
3661
+ if (key === 'dsn') {
3662
+ continue;
3745
3663
  }
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') {
3664
+ if (key === 'user') {
3665
+ if (!dialogOptions.user) {
3760
3666
  continue;
3761
3667
  }
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
- }
3668
+ if (dialogOptions.user.name) {
3669
+ encodedOptions += "&name=" + encodeURIComponent(dialogOptions.user.name);
3772
3670
  }
3773
- else {
3774
- encodedOptions.push(encodeURIComponent(key) + "=" + encodeURIComponent(dialogOptions[key]));
3671
+ if (dialogOptions.user.email) {
3672
+ encodedOptions += "&email=" + encodeURIComponent(dialogOptions.user.email);
3775
3673
  }
3776
3674
  }
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;
3675
+ else {
3676
+ encodedOptions += "&" + encodeURIComponent(key) + "=" + encodeURIComponent(dialogOptions[key]);
3790
3677
  }
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
- }());
3678
+ }
3679
+ return endpoint + "?" + encodedOptions;
3680
+ }
3808
3681
 
3809
3682
  var installedIntegrations = [];
3810
3683
  /**
@@ -3865,7 +3738,7 @@ var Sentry = (function (exports) {
3865
3738
  // set the `initialized` flag so we don't run through the process again unecessarily; use `Object.defineProperty`
3866
3739
  // because by default it creates a property which is nonenumerable, which we want since `initialized` shouldn't be
3867
3740
  // considered a member of the index the way the actual integrations are
3868
- Object.defineProperty(integrations, 'initialized', { value: true });
3741
+ addNonEnumerableProperty(integrations, 'initialized', true);
3869
3742
  return integrations;
3870
3743
  }
3871
3744
 
@@ -3917,7 +3790,7 @@ var Sentry = (function (exports) {
3917
3790
  this._backend = new backendClass(options);
3918
3791
  this._options = options;
3919
3792
  if (options.dsn) {
3920
- this._dsn = new Dsn(options.dsn);
3793
+ this._dsn = makeDsn(options.dsn);
3921
3794
  }
3922
3795
  }
3923
3796
  /**
@@ -3960,9 +3833,8 @@ var Sentry = (function (exports) {
3960
3833
  * @inheritDoc
3961
3834
  */
3962
3835
  BaseClient.prototype.captureEvent = function (event, hint, scope) {
3963
- var _a;
3964
3836
  // ensure we haven't captured this very object before
3965
- if (((_a = hint) === null || _a === void 0 ? void 0 : _a.originalException) && checkOrSetAlreadyCaught(hint.originalException)) {
3837
+ if (hint && hint.originalException && checkOrSetAlreadyCaught(hint.originalException)) {
3966
3838
  logger.log(ALREADY_SEEN_ERROR);
3967
3839
  return;
3968
3840
  }
@@ -3977,11 +3849,15 @@ var Sentry = (function (exports) {
3977
3849
  */
3978
3850
  BaseClient.prototype.captureSession = function (session) {
3979
3851
  if (!this._isEnabled()) {
3980
- logger.warn('SDK not enabled, will not capture session.');
3852
+ if (isDebugBuild()) {
3853
+ logger.warn('SDK not enabled, will not capture session.');
3854
+ }
3981
3855
  return;
3982
3856
  }
3983
3857
  if (!(typeof session.release === 'string')) {
3984
- logger.warn('Discarded session because of missing or non-string release');
3858
+ if (isDebugBuild()) {
3859
+ logger.warn('Discarded session because of missing or non-string release');
3860
+ }
3985
3861
  }
3986
3862
  else {
3987
3863
  this._sendSession(session);
@@ -4077,10 +3953,10 @@ var Sentry = (function (exports) {
4077
3953
  // A session is updated and that session update is sent in only one of the two following scenarios:
4078
3954
  // 1. Session with non terminal status and 0 errors + an error occurred -> Will set error count to 1 and send update
4079
3955
  // 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;
3956
+ var sessionNonTerminal = session.status === 'ok';
4081
3957
  var shouldUpdateAndSend = (sessionNonTerminal && session.errors === 0) || (sessionNonTerminal && crashed);
4082
3958
  if (shouldUpdateAndSend) {
4083
- session.update(__assign(__assign({}, (crashed && { status: SessionStatus.Crashed })), { errors: session.errors || Number(errored || crashed) }));
3959
+ session.update(__assign(__assign({}, (crashed && { status: 'crashed' })), { errors: session.errors || Number(errored || crashed) }));
4084
3960
  this.captureSession(session);
4085
3961
  }
4086
3962
  };
@@ -4153,7 +4029,7 @@ var Sentry = (function (exports) {
4153
4029
  finalScope = Scope.clone(finalScope).update(hint.captureContext);
4154
4030
  }
4155
4031
  // We prepare the result here with a resolved Event.
4156
- var result = SyncPromise.resolve(prepared);
4032
+ var result = resolvedSyncPromise(prepared);
4157
4033
  // This should be the last thing called, since we want that
4158
4034
  // {@link Hub.addEventProcessor} gets the finished prepared event.
4159
4035
  if (finalScope) {
@@ -4286,26 +4162,29 @@ var Sentry = (function (exports) {
4286
4162
  */
4287
4163
  BaseClient.prototype._processEvent = function (event, hint, scope) {
4288
4164
  var _this = this;
4289
- var _a, _b;
4290
4165
  // eslint-disable-next-line @typescript-eslint/unbound-method
4291
- var _c = this.getOptions(), beforeSend = _c.beforeSend, sampleRate = _c.sampleRate;
4166
+ var _a = this.getOptions(), beforeSend = _a.beforeSend, sampleRate = _a.sampleRate;
4292
4167
  var transport = this.getTransport();
4168
+ function recordLostEvent(outcome, category) {
4169
+ if (transport.recordLostEvent) {
4170
+ transport.recordLostEvent(outcome, category);
4171
+ }
4172
+ }
4293
4173
  if (!this._isEnabled()) {
4294
- return SyncPromise.reject(new SentryError('SDK not enabled, will not capture event.'));
4174
+ return rejectedSyncPromise(new SentryError('SDK not enabled, will not capture event.'));
4295
4175
  }
4296
4176
  var isTransaction = event.type === 'transaction';
4297
4177
  // 1.0 === 100% events are sent
4298
4178
  // 0.0 === 0% events are sent
4299
4179
  // Sampling for transaction happens somewhere else
4300
4180
  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 + ")"));
4181
+ recordLostEvent('sample_rate', 'event');
4182
+ return rejectedSyncPromise(new SentryError("Discarding event because it's not included in the random sample (sampling rate = " + sampleRate + ")"));
4303
4183
  }
4304
4184
  return this._prepareEvent(event, scope, hint)
4305
4185
  .then(function (prepared) {
4306
- var _a, _b;
4307
4186
  if (prepared === null) {
4308
- (_b = (_a = transport).recordLostEvent) === null || _b === void 0 ? void 0 : _b.call(_a, Outcome.EventProcessor, event.type || 'event');
4187
+ recordLostEvent('event_processor', event.type || 'event');
4309
4188
  throw new SentryError('An event processor returned null, will not send event.');
4310
4189
  }
4311
4190
  var isInternalException = hint && hint.data && hint.data.__sentry__ === true;
@@ -4313,12 +4192,11 @@ var Sentry = (function (exports) {
4313
4192
  return prepared;
4314
4193
  }
4315
4194
  var beforeSendResult = beforeSend(prepared, hint);
4316
- return _this._ensureBeforeSendRv(beforeSendResult);
4195
+ return _ensureBeforeSendRv(beforeSendResult);
4317
4196
  })
4318
4197
  .then(function (processedEvent) {
4319
- var _a, _b;
4320
4198
  if (processedEvent === null) {
4321
- (_b = (_a = transport).recordLostEvent) === null || _b === void 0 ? void 0 : _b.call(_a, Outcome.BeforeSend, event.type || 'event');
4199
+ recordLostEvent('before_send', event.type || 'event');
4322
4200
  throw new SentryError('`beforeSend` returned `null`, will not send event.');
4323
4201
  }
4324
4202
  var session = scope && scope.getSession && scope.getSession();
@@ -4355,28 +4233,28 @@ var Sentry = (function (exports) {
4355
4233
  return reason;
4356
4234
  });
4357
4235
  };
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
4236
  return BaseClient;
4379
- }());
4237
+ }());
4238
+ /**
4239
+ * Verifies that return value of configured `beforeSend` is of expected type.
4240
+ */
4241
+ function _ensureBeforeSendRv(rv) {
4242
+ var nullErr = '`beforeSend` method has to return `null` or a valid event.';
4243
+ if (isThenable(rv)) {
4244
+ return rv.then(function (event) {
4245
+ if (!(isPlainObject(event) || event === null)) {
4246
+ throw new SentryError(nullErr);
4247
+ }
4248
+ return event;
4249
+ }, function (e) {
4250
+ throw new SentryError("beforeSend rejected with " + e);
4251
+ });
4252
+ }
4253
+ else if (!(isPlainObject(rv) || rv === null)) {
4254
+ throw new SentryError(nullErr);
4255
+ }
4256
+ return rv;
4257
+ }
4380
4258
 
4381
4259
  /** Noop transport */
4382
4260
  var NoopTransport = /** @class */ (function () {
@@ -4386,16 +4264,16 @@ var Sentry = (function (exports) {
4386
4264
  * @inheritDoc
4387
4265
  */
4388
4266
  NoopTransport.prototype.sendEvent = function (_) {
4389
- return SyncPromise.resolve({
4267
+ return resolvedSyncPromise({
4390
4268
  reason: "NoopTransport: Event has been skipped because no Dsn is configured.",
4391
- status: exports.Status.Skipped,
4269
+ status: 'skipped',
4392
4270
  });
4393
4271
  };
4394
4272
  /**
4395
4273
  * @inheritDoc
4396
4274
  */
4397
4275
  NoopTransport.prototype.close = function (_) {
4398
- return SyncPromise.resolve(true);
4276
+ return resolvedSyncPromise(true);
4399
4277
  };
4400
4278
  return NoopTransport;
4401
4279
  }());
@@ -4431,7 +4309,9 @@ var Sentry = (function (exports) {
4431
4309
  */
4432
4310
  BaseBackend.prototype.sendEvent = function (event) {
4433
4311
  void this._transport.sendEvent(event).then(null, function (reason) {
4434
- logger.error("Error while sending event: " + reason);
4312
+ if (isDebugBuild()) {
4313
+ logger.error("Error while sending event: " + reason);
4314
+ }
4435
4315
  });
4436
4316
  };
4437
4317
  /**
@@ -4439,11 +4319,15 @@ var Sentry = (function (exports) {
4439
4319
  */
4440
4320
  BaseBackend.prototype.sendSession = function (session) {
4441
4321
  if (!this._transport.sendSession) {
4442
- logger.warn("Dropping session because custom transport doesn't implement sendSession");
4322
+ if (isDebugBuild()) {
4323
+ logger.warn("Dropping session because custom transport doesn't implement sendSession");
4324
+ }
4443
4325
  return;
4444
4326
  }
4445
4327
  void this._transport.sendSession(session).then(null, function (reason) {
4446
- logger.error("Error while sending session: " + reason);
4328
+ if (isDebugBuild()) {
4329
+ logger.error("Error while sending session: " + reason);
4330
+ }
4447
4331
  });
4448
4332
  };
4449
4333
  /**
@@ -4487,7 +4371,7 @@ var Sentry = (function (exports) {
4487
4371
  /** Creates a SentryRequest from a Session. */
4488
4372
  function sessionToSentryRequest(session, api) {
4489
4373
  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() })));
4374
+ var envelopeHeaders = JSON.stringify(__assign(__assign({ sent_at: new Date().toISOString() }, (sdkInfo && { sdk: sdkInfo })), (!!api.tunnel && { dsn: dsnToString(api.dsn) })));
4491
4375
  // I know this is hacky but we don't want to add `session` to request type since it's never rate limited
4492
4376
  var type = 'aggregates' in session ? 'sessions' : 'session';
4493
4377
  var itemHeaders = JSON.stringify({
@@ -4496,14 +4380,14 @@ var Sentry = (function (exports) {
4496
4380
  return {
4497
4381
  body: envelopeHeaders + "\n" + itemHeaders + "\n" + JSON.stringify(session),
4498
4382
  type: type,
4499
- url: api.getEnvelopeEndpointWithUrlEncodedAuth(),
4383
+ url: getEnvelopeEndpointWithUrlEncodedAuth(api.dsn, api.tunnel),
4500
4384
  };
4501
4385
  }
4502
4386
  /** Creates a SentryRequest from an event. */
4503
4387
  function eventToSentryRequest(event, api) {
4504
4388
  var sdkInfo = getSdkMetadataForEnvelopeHeader(api);
4505
4389
  var eventType = event.type || 'event';
4506
- var useEnvelope = eventType === 'transaction' || api.forceEnvelope();
4390
+ var useEnvelope = eventType === 'transaction' || !!api.tunnel;
4507
4391
  var _a = event.debug_meta || {}, transactionSampling = _a.transactionSampling, metadata = __rest(_a, ["transactionSampling"]);
4508
4392
  var _b = transactionSampling || {}, samplingMethod = _b.method, sampleRate = _b.rate;
4509
4393
  if (Object.keys(metadata).length === 0) {
@@ -4515,7 +4399,9 @@ var Sentry = (function (exports) {
4515
4399
  var req = {
4516
4400
  body: JSON.stringify(sdkInfo ? enhanceEventWithSdkInfo(event, api.metadata.sdk) : event),
4517
4401
  type: eventType,
4518
- url: useEnvelope ? api.getEnvelopeEndpointWithUrlEncodedAuth() : api.getStoreEndpointWithUrlEncodedAuth(),
4402
+ url: useEnvelope
4403
+ ? getEnvelopeEndpointWithUrlEncodedAuth(api.dsn, api.tunnel)
4404
+ : getStoreEndpointWithUrlEncodedAuth(api.dsn),
4519
4405
  };
4520
4406
  // https://develop.sentry.dev/sdk/envelopes/
4521
4407
  // Since we don't need to manipulate envelopes nor store them, there is no
@@ -4523,7 +4409,7 @@ var Sentry = (function (exports) {
4523
4409
  // deserialization. Instead, we only implement a minimal subset of the spec to
4524
4410
  // serialize events inline here.
4525
4411
  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() })));
4412
+ 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
4413
  var itemHeaders = JSON.stringify({
4528
4414
  type: eventType,
4529
4415
  // TODO: Right now, sampleRate may or may not be defined (it won't be in the cases of inheritance and
@@ -4548,17 +4434,19 @@ var Sentry = (function (exports) {
4548
4434
  * @param options Options to pass to the client.
4549
4435
  */
4550
4436
  function initAndBind(clientClass, options) {
4551
- var _a;
4552
4437
  if (options.debug === true) {
4553
4438
  logger.enable();
4554
4439
  }
4555
4440
  var hub = getCurrentHub();
4556
- (_a = hub.getScope()) === null || _a === void 0 ? void 0 : _a.update(options.initialScope);
4441
+ var scope = hub.getScope();
4442
+ if (scope) {
4443
+ scope.update(options.initialScope);
4444
+ }
4557
4445
  var client = new clientClass(options);
4558
4446
  hub.bindClient(client);
4559
4447
  }
4560
4448
 
4561
- var SDK_VERSION = '6.14.3';
4449
+ var SDK_VERSION = '6.17.0-beta.0';
4562
4450
 
4563
4451
  var originalFunctionToString;
4564
4452
  /** Patch toString calls to return proper name for wrapped functions */
@@ -4581,7 +4469,7 @@ var Sentry = (function (exports) {
4581
4469
  for (var _i = 0; _i < arguments.length; _i++) {
4582
4470
  args[_i] = arguments[_i];
4583
4471
  }
4584
- var context = this.__sentry_original__ || this;
4472
+ var context = getOriginalFunction(this) || this;
4585
4473
  return originalFunctionToString.apply(context, args);
4586
4474
  };
4587
4475
  };
@@ -4635,19 +4523,27 @@ var Sentry = (function (exports) {
4635
4523
  /** JSDoc */
4636
4524
  InboundFilters.prototype._shouldDropEvent = function (event, options) {
4637
4525
  if (this._isSentryError(event, options)) {
4638
- logger.warn("Event dropped due to being internal Sentry Error.\nEvent: " + getEventDescription(event));
4526
+ if (isDebugBuild()) {
4527
+ logger.warn("Event dropped due to being internal Sentry Error.\nEvent: " + getEventDescription(event));
4528
+ }
4639
4529
  return true;
4640
4530
  }
4641
4531
  if (this._isIgnoredError(event, options)) {
4642
- logger.warn("Event dropped due to being matched by `ignoreErrors` option.\nEvent: " + getEventDescription(event));
4532
+ if (isDebugBuild()) {
4533
+ logger.warn("Event dropped due to being matched by `ignoreErrors` option.\nEvent: " + getEventDescription(event));
4534
+ }
4643
4535
  return true;
4644
4536
  }
4645
4537
  if (this._isDeniedUrl(event, options)) {
4646
- logger.warn("Event dropped due to being matched by `denyUrls` option.\nEvent: " + getEventDescription(event) + ".\nUrl: " + this._getEventFilterUrl(event));
4538
+ if (isDebugBuild()) {
4539
+ logger.warn("Event dropped due to being matched by `denyUrls` option.\nEvent: " + getEventDescription(event) + ".\nUrl: " + this._getEventFilterUrl(event));
4540
+ }
4647
4541
  return true;
4648
4542
  }
4649
4543
  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));
4544
+ if (isDebugBuild()) {
4545
+ logger.warn("Event dropped due to not being matched by `allowUrls` option.\nEvent: " + getEventDescription(event) + ".\nUrl: " + this._getEventFilterUrl(event));
4546
+ }
4651
4547
  return true;
4652
4548
  }
4653
4549
  return false;
@@ -4658,16 +4554,14 @@ var Sentry = (function (exports) {
4658
4554
  return false;
4659
4555
  }
4660
4556
  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);
4557
+ // @ts-ignore can't be a sentry error if undefined
4558
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
4559
+ return event.exception.values[0].type === 'SentryError';
4667
4560
  }
4668
- catch (_oO) {
4669
- return false;
4561
+ catch (e) {
4562
+ // ignore
4670
4563
  }
4564
+ return false;
4671
4565
  };
4672
4566
  /** JSDoc */
4673
4567
  InboundFilters.prototype._isIgnoredError = function (event, options) {
@@ -4718,7 +4612,9 @@ var Sentry = (function (exports) {
4718
4612
  return ["" + value, type + ": " + value];
4719
4613
  }
4720
4614
  catch (oO) {
4721
- logger.error("Cannot extract message for event " + getEventDescription(event));
4615
+ if (isDebugBuild()) {
4616
+ logger.error("Cannot extract message for event " + getEventDescription(event));
4617
+ }
4722
4618
  return [];
4723
4619
  }
4724
4620
  }
@@ -4727,10 +4623,9 @@ var Sentry = (function (exports) {
4727
4623
  /** JSDoc */
4728
4624
  InboundFilters.prototype._getLastValidUrl = function (frames) {
4729
4625
  if (frames === void 0) { frames = []; }
4730
- var _a, _b;
4731
4626
  for (var i = frames.length - 1; i >= 0; i--) {
4732
4627
  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]') {
4628
+ if (frame && frame.filename !== '<anonymous>' && frame.filename !== '[native code]') {
4734
4629
  return frame.filename || null;
4735
4630
  }
4736
4631
  }
@@ -4740,17 +4635,22 @@ var Sentry = (function (exports) {
4740
4635
  InboundFilters.prototype._getEventFilterUrl = function (event) {
4741
4636
  try {
4742
4637
  if (event.stacktrace) {
4743
- var frames_1 = event.stacktrace.frames;
4744
- return this._getLastValidUrl(frames_1);
4638
+ return this._getLastValidUrl(event.stacktrace.frames);
4745
4639
  }
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);
4640
+ var frames_1;
4641
+ try {
4642
+ // @ts-ignore we only care about frames if the whole thing here is defined
4643
+ frames_1 = event.exception.values[0].stacktrace.frames;
4749
4644
  }
4750
- return null;
4645
+ catch (e) {
4646
+ // ignore
4647
+ }
4648
+ return frames_1 ? this._getLastValidUrl(frames_1) : null;
4751
4649
  }
4752
4650
  catch (oO) {
4753
- logger.error("Cannot extract url for event " + getEventDescription(event));
4651
+ if (isDebugBuild()) {
4652
+ logger.error("Cannot extract url for event " + getEventDescription(event));
4653
+ }
4754
4654
  return null;
4755
4655
  }
4756
4656
  };
@@ -5123,18 +5023,18 @@ var Sentry = (function (exports) {
5123
5023
  attachStacktrace: options.attachStacktrace,
5124
5024
  });
5125
5025
  addExceptionMechanism(event); // defaults to { type: 'generic', handled: true }
5126
- event.level = exports.Severity.Error;
5026
+ event.level = 'error';
5127
5027
  if (hint && hint.event_id) {
5128
5028
  event.event_id = hint.event_id;
5129
5029
  }
5130
- return SyncPromise.resolve(event);
5030
+ return resolvedSyncPromise(event);
5131
5031
  }
5132
5032
  /**
5133
5033
  * Builds and Event from a Message
5134
5034
  * @hidden
5135
5035
  */
5136
5036
  function eventFromMessage(options, message, level, hint) {
5137
- if (level === void 0) { level = exports.Severity.Info; }
5037
+ if (level === void 0) { level = 'info'; }
5138
5038
  var syntheticException = (hint && hint.syntheticException) || undefined;
5139
5039
  var event = eventFromString(message, syntheticException, {
5140
5040
  attachStacktrace: options.attachStacktrace,
@@ -5143,7 +5043,7 @@ var Sentry = (function (exports) {
5143
5043
  if (hint && hint.event_id) {
5144
5044
  event.event_id = hint.event_id;
5145
5045
  }
5146
- return SyncPromise.resolve(event);
5046
+ return resolvedSyncPromise(event);
5147
5047
  }
5148
5048
  /**
5149
5049
  * @hidden
@@ -5159,16 +5059,24 @@ var Sentry = (function (exports) {
5159
5059
  event = eventFromStacktrace(computeStackTrace(exception));
5160
5060
  return event;
5161
5061
  }
5062
+ // If it is a `DOMError` (which is a legacy API, but still supported in some browsers) then we just extract the name
5063
+ // and message, as it doesn't provide anything else. According to the spec, all `DOMExceptions` should also be
5064
+ // `Error`s, but that's not the case in IE11, so in that case we treat it the same as we do a `DOMError`.
5065
+ //
5066
+ // https://developer.mozilla.org/en-US/docs/Web/API/DOMError
5067
+ // https://developer.mozilla.org/en-US/docs/Web/API/DOMException
5068
+ // https://webidl.spec.whatwg.org/#es-DOMException-specialness
5162
5069
  if (isDOMError(exception) || isDOMException(exception)) {
5163
- // If it is a DOMError or DOMException (which are legacy APIs, but still supported in some browsers)
5164
- // then we just extract the name, code, and message, as they don't provide anything else
5165
- // https://developer.mozilla.org/en-US/docs/Web/API/DOMError
5166
- // https://developer.mozilla.org/en-US/docs/Web/API/DOMException
5167
5070
  var domException = exception;
5168
- var name_1 = domException.name || (isDOMError(domException) ? 'DOMError' : 'DOMException');
5169
- var message = domException.message ? name_1 + ": " + domException.message : name_1;
5170
- event = eventFromString(message, syntheticException, options);
5171
- addExceptionTypeValue(event, message);
5071
+ if ('stack' in exception) {
5072
+ event = eventFromStacktrace(computeStackTrace(exception));
5073
+ }
5074
+ else {
5075
+ var name_1 = domException.name || (isDOMError(domException) ? 'DOMError' : 'DOMException');
5076
+ var message = domException.message ? name_1 + ": " + domException.message : name_1;
5077
+ event = eventFromString(message, syntheticException, options);
5078
+ addExceptionTypeValue(event, message);
5079
+ }
5172
5080
  if ('code' in domException) {
5173
5081
  event.tags = __assign(__assign({}, event.tags), { 'DOMException.code': "" + domException.code });
5174
5082
  }
@@ -5265,7 +5173,6 @@ var Sentry = (function (exports) {
5265
5173
  * Safari: resource blocked by content blocker
5266
5174
  */
5267
5175
  function getNativeFetchImplementation() {
5268
- var _a, _b;
5269
5176
  if (cachedFetchImpl) {
5270
5177
  return cachedFetchImpl;
5271
5178
  }
@@ -5277,18 +5184,21 @@ var Sentry = (function (exports) {
5277
5184
  var document = global$3.document;
5278
5185
  var fetchImpl = global$3.fetch;
5279
5186
  // eslint-disable-next-line deprecation/deprecation
5280
- if (typeof ((_a = document) === null || _a === void 0 ? void 0 : _a.createElement) === "function") {
5187
+ if (document && typeof document.createElement === "function") {
5281
5188
  try {
5282
5189
  var sandbox = document.createElement('iframe');
5283
5190
  sandbox.hidden = true;
5284
5191
  document.head.appendChild(sandbox);
5285
- if ((_b = sandbox.contentWindow) === null || _b === void 0 ? void 0 : _b.fetch) {
5286
- fetchImpl = sandbox.contentWindow.fetch;
5192
+ var contentWindow = sandbox.contentWindow;
5193
+ if (contentWindow && contentWindow.fetch) {
5194
+ fetchImpl = contentWindow.fetch;
5287
5195
  }
5288
5196
  document.head.removeChild(sandbox);
5289
5197
  }
5290
5198
  catch (e) {
5291
- logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', e);
5199
+ if (isDebugBuild()) {
5200
+ logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', e);
5201
+ }
5292
5202
  }
5293
5203
  }
5294
5204
  return (cachedFetchImpl = fetchImpl.bind(global$3));
@@ -5319,12 +5229,10 @@ var Sentry = (function (exports) {
5319
5229
  }
5320
5230
  }
5321
5231
 
5322
- var CATEGORY_MAPPING = {
5323
- event: 'error',
5324
- transaction: 'transaction',
5325
- session: 'session',
5326
- attachment: 'attachment',
5327
- };
5232
+ function requestTypeToCategory(ty) {
5233
+ var tyStr = ty;
5234
+ return tyStr === 'event' ? 'error' : tyStr;
5235
+ }
5328
5236
  var global$4 = getGlobalObject();
5329
5237
  /** Base Transport class implementation */
5330
5238
  var BaseTransport = /** @class */ (function () {
@@ -5332,13 +5240,13 @@ var Sentry = (function (exports) {
5332
5240
  var _this = this;
5333
5241
  this.options = options;
5334
5242
  /** A simple buffer holding all requests. */
5335
- this._buffer = new PromiseBuffer(30);
5243
+ this._buffer = makePromiseBuffer(30);
5336
5244
  /** Locks transport after receiving rate limits in a response */
5337
5245
  this._rateLimits = {};
5338
5246
  this._outcomes = {};
5339
- this._api = new API(options.dsn, options._metadata, options.tunnel);
5247
+ this._api = initAPIDetails(options.dsn, options._metadata, options.tunnel);
5340
5248
  // eslint-disable-next-line deprecation/deprecation
5341
- this.url = this._api.getStoreEndpointWithUrlEncodedAuth();
5249
+ this.url = getStoreEndpointWithUrlEncodedAuth(this._api.dsn);
5342
5250
  if (this.options.sendClientReports && global$4.document) {
5343
5251
  global$4.document.addEventListener('visibilitychange', function () {
5344
5252
  if (global$4.document.visibilityState === 'hidden') {
@@ -5350,8 +5258,14 @@ var Sentry = (function (exports) {
5350
5258
  /**
5351
5259
  * @inheritDoc
5352
5260
  */
5353
- BaseTransport.prototype.sendEvent = function (_) {
5354
- throw new SentryError('Transport Class has to implement `sendEvent` method');
5261
+ BaseTransport.prototype.sendEvent = function (event) {
5262
+ return this._sendRequest(eventToSentryRequest(event, this._api), event);
5263
+ };
5264
+ /**
5265
+ * @inheritDoc
5266
+ */
5267
+ BaseTransport.prototype.sendSession = function (session) {
5268
+ return this._sendRequest(sessionToSentryRequest(session, this._api), session);
5355
5269
  };
5356
5270
  /**
5357
5271
  * @inheritDoc
@@ -5372,7 +5286,7 @@ var Sentry = (function (exports) {
5372
5286
  // We could use nested maps, but it's much easier to read and type this way.
5373
5287
  // A correct type for map-based implementation if we want to go that route
5374
5288
  // would be `Partial<Record<SentryRequestType, Partial<Record<Outcome, number>>>>`
5375
- var key = CATEGORY_MAPPING[category] + ":" + reason;
5289
+ var key = requestTypeToCategory(category) + ":" + reason;
5376
5290
  logger.log("Adding outcome: " + key);
5377
5291
  this._outcomes[key] = (_a = this._outcomes[key], (_a !== null && _a !== void 0 ? _a : 0)) + 1;
5378
5292
  };
@@ -5391,9 +5305,9 @@ var Sentry = (function (exports) {
5391
5305
  return;
5392
5306
  }
5393
5307
  logger.log("Flushing outcomes:\n" + JSON.stringify(outcomes, null, 2));
5394
- var url = this._api.getEnvelopeEndpointWithUrlEncodedAuth();
5308
+ var url = getEnvelopeEndpointWithUrlEncodedAuth(this._api.dsn, this._api.tunnel);
5395
5309
  // Envelope header is required to be at least an empty object
5396
- var envelopeHeader = JSON.stringify(__assign({}, (this.options.tunnel && { dsn: this._api.getDsn().toString() })));
5310
+ var envelopeHeader = JSON.stringify(__assign({}, (this._api.tunnel && { dsn: dsnToString(this._api.dsn) })));
5397
5311
  var itemHeaders = JSON.stringify({
5398
5312
  type: 'client_report',
5399
5313
  });
@@ -5421,15 +5335,16 @@ var Sentry = (function (exports) {
5421
5335
  */
5422
5336
  BaseTransport.prototype._handleResponse = function (_a) {
5423
5337
  var requestType = _a.requestType, response = _a.response, headers = _a.headers, resolve = _a.resolve, reject = _a.reject;
5424
- var status = exports.Status.fromHttpCode(response.status);
5338
+ var status = eventStatusFromHttpCode(response.status);
5425
5339
  /**
5426
5340
  * "The name is case-insensitive."
5427
5341
  * https://developer.mozilla.org/en-US/docs/Web/API/Headers/get
5428
5342
  */
5429
5343
  var limited = this._handleRateLimit(headers);
5430
- if (limited)
5344
+ if (limited && isDebugBuild()) {
5431
5345
  logger.warn("Too many " + requestType + " requests, backing off until: " + this._disabledUntil(requestType));
5432
- if (status === exports.Status.Success) {
5346
+ }
5347
+ if (status === 'success') {
5433
5348
  resolve({ status: status });
5434
5349
  return;
5435
5350
  }
@@ -5439,7 +5354,7 @@ var Sentry = (function (exports) {
5439
5354
  * Gets the time that given category is disabled until for rate limiting
5440
5355
  */
5441
5356
  BaseTransport.prototype._disabledUntil = function (requestType) {
5442
- var category = CATEGORY_MAPPING[requestType];
5357
+ var category = requestTypeToCategory(requestType);
5443
5358
  return this._rateLimits[category] || this._rateLimits.all;
5444
5359
  };
5445
5360
  /**
@@ -5515,18 +5430,6 @@ var Sentry = (function (exports) {
5515
5430
  _this._fetch = fetchImpl;
5516
5431
  return _this;
5517
5432
  }
5518
- /**
5519
- * @inheritDoc
5520
- */
5521
- FetchTransport.prototype.sendEvent = function (event) {
5522
- return this._sendRequest(eventToSentryRequest(event, this._api), event);
5523
- };
5524
- /**
5525
- * @inheritDoc
5526
- */
5527
- FetchTransport.prototype.sendSession = function (session) {
5528
- return this._sendRequest(sessionToSentryRequest(session, this._api), session);
5529
- };
5530
5433
  /**
5531
5434
  * @param sentryRequest Prepared SentryRequest to be delivered
5532
5435
  * @param originalPayload Original payload used to create SentryRequest
@@ -5534,7 +5437,7 @@ var Sentry = (function (exports) {
5534
5437
  FetchTransport.prototype._sendRequest = function (sentryRequest, originalPayload) {
5535
5438
  var _this = this;
5536
5439
  if (this._isRateLimited(sentryRequest.type)) {
5537
- this.recordLostEvent(Outcome.RateLimitBackoff, sentryRequest.type);
5440
+ this.recordLostEvent('ratelimit_backoff', sentryRequest.type);
5538
5441
  return Promise.reject({
5539
5442
  event: originalPayload,
5540
5443
  type: sentryRequest.type,
@@ -5580,10 +5483,10 @@ var Sentry = (function (exports) {
5580
5483
  .then(undefined, function (reason) {
5581
5484
  // It's either buffer rejection or any other xhr/fetch error, which are treated as NetworkError.
5582
5485
  if (reason instanceof SentryError) {
5583
- _this.recordLostEvent(Outcome.QueueOverflow, sentryRequest.type);
5486
+ _this.recordLostEvent('queue_overflow', sentryRequest.type);
5584
5487
  }
5585
5488
  else {
5586
- _this.recordLostEvent(Outcome.NetworkError, sentryRequest.type);
5489
+ _this.recordLostEvent('network_error', sentryRequest.type);
5587
5490
  }
5588
5491
  throw reason;
5589
5492
  });
@@ -5597,18 +5500,6 @@ var Sentry = (function (exports) {
5597
5500
  function XHRTransport() {
5598
5501
  return _super !== null && _super.apply(this, arguments) || this;
5599
5502
  }
5600
- /**
5601
- * @inheritDoc
5602
- */
5603
- XHRTransport.prototype.sendEvent = function (event) {
5604
- return this._sendRequest(eventToSentryRequest(event, this._api), event);
5605
- };
5606
- /**
5607
- * @inheritDoc
5608
- */
5609
- XHRTransport.prototype.sendSession = function (session) {
5610
- return this._sendRequest(sessionToSentryRequest(session, this._api), session);
5611
- };
5612
5503
  /**
5613
5504
  * @param sentryRequest Prepared SentryRequest to be delivered
5614
5505
  * @param originalPayload Original payload used to create SentryRequest
@@ -5616,7 +5507,7 @@ var Sentry = (function (exports) {
5616
5507
  XHRTransport.prototype._sendRequest = function (sentryRequest, originalPayload) {
5617
5508
  var _this = this;
5618
5509
  if (this._isRateLimited(sentryRequest.type)) {
5619
- this.recordLostEvent(Outcome.RateLimitBackoff, sentryRequest.type);
5510
+ this.recordLostEvent('ratelimit_backoff', sentryRequest.type);
5620
5511
  return Promise.reject({
5621
5512
  event: originalPayload,
5622
5513
  type: sentryRequest.type,
@@ -5649,10 +5540,10 @@ var Sentry = (function (exports) {
5649
5540
  .then(undefined, function (reason) {
5650
5541
  // It's either buffer rejection or any other xhr/fetch error, which are treated as NetworkError.
5651
5542
  if (reason instanceof SentryError) {
5652
- _this.recordLostEvent(Outcome.QueueOverflow, sentryRequest.type);
5543
+ _this.recordLostEvent('queue_overflow', sentryRequest.type);
5653
5544
  }
5654
5545
  else {
5655
- _this.recordLostEvent(Outcome.NetworkError, sentryRequest.type);
5546
+ _this.recordLostEvent('network_error', sentryRequest.type);
5656
5547
  }
5657
5548
  throw reason;
5658
5549
  });
@@ -5688,7 +5579,7 @@ var Sentry = (function (exports) {
5688
5579
  * @inheritDoc
5689
5580
  */
5690
5581
  BrowserBackend.prototype.eventFromMessage = function (message, level, hint) {
5691
- if (level === void 0) { level = exports.Severity.Info; }
5582
+ if (level === void 0) { level = 'info'; }
5692
5583
  return eventFromMessage(this._options, message, level, hint);
5693
5584
  };
5694
5585
  /**
@@ -5738,19 +5629,27 @@ var Sentry = (function (exports) {
5738
5629
  * @hidden
5739
5630
  */
5740
5631
  function wrap(fn, options, before) {
5632
+ // for future readers what this does is wrap a function and then create
5633
+ // a bi-directional wrapping between them.
5634
+ //
5635
+ // example: wrapped = wrap(original);
5636
+ // original.__sentry_wrapped__ -> wrapped
5637
+ // wrapped.__sentry_original__ -> original
5741
5638
  if (options === void 0) { options = {}; }
5742
5639
  if (typeof fn !== 'function') {
5743
5640
  return fn;
5744
5641
  }
5745
5642
  try {
5643
+ // if we're dealing with a function that was previously wrapped, return
5644
+ // the original wrapper.
5645
+ var wrapper = fn.__sentry_wrapped__;
5646
+ if (wrapper) {
5647
+ return wrapper;
5648
+ }
5746
5649
  // We don't wanna wrap it twice
5747
- if (fn.__sentry__) {
5650
+ if (getOriginalFunction(fn)) {
5748
5651
  return fn;
5749
5652
  }
5750
- // If this has already been wrapped in the past, return that wrapped function
5751
- if (fn.__sentry_wrapped__) {
5752
- return fn.__sentry_wrapped__;
5753
- }
5754
5653
  }
5755
5654
  catch (e) {
5756
5655
  // Just accessing custom props in some Selenium environments
@@ -5768,14 +5667,6 @@ var Sentry = (function (exports) {
5768
5667
  }
5769
5668
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
5770
5669
  var wrappedArguments = args.map(function (arg) { return wrap(arg, options); });
5771
- if (fn.handleEvent) {
5772
- // Attempt to invoke user-land function
5773
- // NOTE: If you are a Sentry user, and you are seeing this stack frame, it
5774
- // means the sentry.javascript SDK caught an error invoking your application code. This
5775
- // is expected behavior and NOT indicative of a bug with sentry.javascript.
5776
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
5777
- return fn.handleEvent.apply(this, wrappedArguments);
5778
- }
5779
5670
  // Attempt to invoke user-land function
5780
5671
  // NOTE: If you are a Sentry user, and you are seeing this stack frame, it
5781
5672
  // means the sentry.javascript SDK caught an error invoking your application code. This
@@ -5786,13 +5677,12 @@ var Sentry = (function (exports) {
5786
5677
  ignoreNextOnError();
5787
5678
  withScope(function (scope) {
5788
5679
  scope.addEventProcessor(function (event) {
5789
- var processedEvent = __assign({}, event);
5790
5680
  if (options.mechanism) {
5791
- addExceptionTypeValue(processedEvent, undefined, undefined);
5792
- addExceptionMechanism(processedEvent, options.mechanism);
5681
+ addExceptionTypeValue(event, undefined, undefined);
5682
+ addExceptionMechanism(event, options.mechanism);
5793
5683
  }
5794
- processedEvent.extra = __assign(__assign({}, processedEvent.extra), { arguments: args });
5795
- return processedEvent;
5684
+ event.extra = __assign(__assign({}, event.extra), { arguments: args });
5685
+ return event;
5796
5686
  });
5797
5687
  captureException(ex);
5798
5688
  });
@@ -5810,24 +5700,10 @@ var Sentry = (function (exports) {
5810
5700
  }
5811
5701
  }
5812
5702
  catch (_oO) { } // eslint-disable-line no-empty
5813
- fn.prototype = fn.prototype || {};
5814
- sentryWrapped.prototype = fn.prototype;
5815
- Object.defineProperty(fn, '__sentry_wrapped__', {
5816
- enumerable: false,
5817
- value: sentryWrapped,
5818
- });
5819
5703
  // Signal that this function has been wrapped/filled already
5820
5704
  // for both debugging and to prevent it to being wrapped/filled twice
5821
- Object.defineProperties(sentryWrapped, {
5822
- __sentry__: {
5823
- enumerable: false,
5824
- value: true,
5825
- },
5826
- __sentry_original__: {
5827
- enumerable: false,
5828
- value: fn,
5829
- },
5830
- });
5705
+ markFunctionWrapped(sentryWrapped, fn);
5706
+ addNonEnumerableProperty(fn, '__sentry_wrapped__', sentryWrapped);
5831
5707
  // Restore original function name (not all browsers allow that)
5832
5708
  try {
5833
5709
  var descriptor = Object.getOwnPropertyDescriptor(sentryWrapped, 'name');
@@ -5853,16 +5729,20 @@ var Sentry = (function (exports) {
5853
5729
  return;
5854
5730
  }
5855
5731
  if (!options.eventId) {
5856
- logger.error("Missing eventId option in showReportDialog call");
5732
+ if (isDebugBuild()) {
5733
+ logger.error("Missing eventId option in showReportDialog call");
5734
+ }
5857
5735
  return;
5858
5736
  }
5859
5737
  if (!options.dsn) {
5860
- logger.error("Missing dsn option in showReportDialog call");
5738
+ if (isDebugBuild()) {
5739
+ logger.error("Missing dsn option in showReportDialog call");
5740
+ }
5861
5741
  return;
5862
5742
  }
5863
5743
  var script = global$5.document.createElement('script');
5864
5744
  script.async = true;
5865
- script.src = new API(options.dsn).getReportDialogEndpoint(options);
5745
+ script.src = getReportDialogEndpoint(options.dsn, options);
5866
5746
  if (options.onLoad) {
5867
5747
  // eslint-disable-next-line @typescript-eslint/unbound-method
5868
5748
  script.onload = options.onLoad;
@@ -5881,10 +5761,14 @@ var Sentry = (function (exports) {
5881
5761
  * @inheritDoc
5882
5762
  */
5883
5763
  this.name = GlobalHandlers.id;
5884
- /** JSDoc */
5885
- this._onErrorHandlerInstalled = false;
5886
- /** JSDoc */
5887
- this._onUnhandledRejectionHandlerInstalled = false;
5764
+ /**
5765
+ * Stores references functions to installing handlers. Will set to undefined
5766
+ * after they have been run so that they are not used twice.
5767
+ */
5768
+ this._installFunc = {
5769
+ onerror: _installGlobalOnErrorHandler,
5770
+ onunhandledrejection: _installGlobalOnUnhandledRejectionHandler,
5771
+ };
5888
5772
  this._options = __assign({ onerror: true, onunhandledrejection: true }, options);
5889
5773
  }
5890
5774
  /**
@@ -5892,405 +5776,410 @@ var Sentry = (function (exports) {
5892
5776
  */
5893
5777
  GlobalHandlers.prototype.setupOnce = function () {
5894
5778
  Error.stackTraceLimit = 50;
5895
- if (this._options.onerror) {
5896
- logger.log('Global Handler attached: onerror');
5897
- this._installGlobalOnErrorHandler();
5898
- }
5899
- if (this._options.onunhandledrejection) {
5900
- logger.log('Global Handler attached: onunhandledrejection');
5901
- this._installGlobalOnUnhandledRejectionHandler();
5902
- }
5903
- };
5904
- /** JSDoc */
5905
- GlobalHandlers.prototype._installGlobalOnErrorHandler = function () {
5906
- var _this = this;
5907
- if (this._onErrorHandlerInstalled) {
5908
- return;
5909
- }
5910
- addInstrumentationHandler({
5911
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
5912
- callback: function (data) {
5913
- var error = data.error;
5914
- var currentHub = getCurrentHub();
5915
- var hasIntegration = currentHub.getIntegration(GlobalHandlers);
5916
- var isFailedOwnDelivery = error && error.__sentry_own_request__ === true;
5917
- if (!hasIntegration || shouldIgnoreOnError() || isFailedOwnDelivery) {
5918
- return;
5919
- }
5920
- var client = currentHub.getClient();
5921
- var event = error === undefined && isString(data.msg)
5922
- ? _this._eventFromIncompleteOnError(data.msg, data.url, data.line, data.column)
5923
- : _this._enhanceEventWithInitialFrame(eventFromUnknownInput(error || data.msg, undefined, {
5924
- attachStacktrace: client && client.getOptions().attachStacktrace,
5925
- rejection: false,
5926
- }), data.url, data.line, data.column);
5927
- addExceptionMechanism(event, {
5928
- handled: false,
5929
- type: 'onerror',
5930
- });
5931
- currentHub.captureEvent(event, {
5932
- originalException: error,
5933
- });
5934
- },
5935
- type: 'error',
5936
- });
5937
- this._onErrorHandlerInstalled = true;
5938
- };
5939
- /** JSDoc */
5940
- GlobalHandlers.prototype._installGlobalOnUnhandledRejectionHandler = function () {
5941
- var _this = this;
5942
- if (this._onUnhandledRejectionHandlerInstalled) {
5943
- return;
5944
- }
5945
- addInstrumentationHandler({
5946
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
5947
- callback: function (e) {
5948
- var error = e;
5949
- // dig the object of the rejection out of known event types
5950
- try {
5951
- // PromiseRejectionEvents store the object of the rejection under 'reason'
5952
- // see https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent
5953
- if ('reason' in e) {
5954
- error = e.reason;
5955
- }
5956
- // something, somewhere, (likely a browser extension) effectively casts PromiseRejectionEvents
5957
- // to CustomEvents, moving the `promise` and `reason` attributes of the PRE into
5958
- // the CustomEvent's `detail` attribute, since they're not part of CustomEvent's spec
5959
- // see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent and
5960
- // https://github.com/getsentry/sentry-javascript/issues/2380
5961
- else if ('detail' in e && 'reason' in e.detail) {
5962
- error = e.detail.reason;
5963
- }
5964
- }
5965
- catch (_oO) {
5966
- // no-empty
5967
- }
5968
- var currentHub = getCurrentHub();
5969
- var hasIntegration = currentHub.getIntegration(GlobalHandlers);
5970
- var isFailedOwnDelivery = error && error.__sentry_own_request__ === true;
5971
- if (!hasIntegration || shouldIgnoreOnError() || isFailedOwnDelivery) {
5972
- return true;
5973
- }
5974
- var client = currentHub.getClient();
5975
- var event = isPrimitive(error)
5976
- ? _this._eventFromRejectionWithPrimitive(error)
5977
- : eventFromUnknownInput(error, undefined, {
5978
- attachStacktrace: client && client.getOptions().attachStacktrace,
5979
- rejection: true,
5980
- });
5981
- event.level = exports.Severity.Error;
5982
- addExceptionMechanism(event, {
5983
- handled: false,
5984
- type: 'onunhandledrejection',
5985
- });
5986
- currentHub.captureEvent(event, {
5987
- originalException: error,
5988
- });
5989
- return;
5990
- },
5991
- type: 'unhandledrejection',
5992
- });
5993
- this._onUnhandledRejectionHandlerInstalled = true;
5994
- };
5995
- /**
5996
- * This function creates a stack from an old, error-less onerror handler.
5997
- */
5998
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
5999
- GlobalHandlers.prototype._eventFromIncompleteOnError = function (msg, url, line, column) {
6000
- var ERROR_TYPES_RE = /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i;
6001
- // If 'message' is ErrorEvent, get real message from inside
6002
- var message = isErrorEvent(msg) ? msg.message : msg;
6003
- var name;
6004
- var groups = message.match(ERROR_TYPES_RE);
6005
- if (groups) {
6006
- name = groups[1];
6007
- message = groups[2];
6008
- }
6009
- var event = {
6010
- exception: {
6011
- values: [
6012
- {
6013
- type: name || 'Error',
6014
- value: message,
6015
- },
6016
- ],
6017
- },
6018
- };
6019
- return this._enhanceEventWithInitialFrame(event, url, line, column);
6020
- };
6021
- /**
6022
- * Create an event from a promise rejection where the `reason` is a primitive.
6023
- *
6024
- * @param reason: The `reason` property of the promise rejection
6025
- * @returns An Event object with an appropriate `exception` value
6026
- */
6027
- GlobalHandlers.prototype._eventFromRejectionWithPrimitive = function (reason) {
6028
- return {
6029
- exception: {
6030
- values: [
6031
- {
6032
- type: 'UnhandledRejection',
6033
- // String() is needed because the Primitive type includes symbols (which can't be automatically stringified)
6034
- value: "Non-Error promise rejection captured with value: " + String(reason),
6035
- },
6036
- ],
6037
- },
6038
- };
6039
- };
6040
- /** JSDoc */
6041
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6042
- GlobalHandlers.prototype._enhanceEventWithInitialFrame = function (event, url, line, column) {
6043
- event.exception = event.exception || {};
6044
- event.exception.values = event.exception.values || [];
6045
- event.exception.values[0] = event.exception.values[0] || {};
6046
- event.exception.values[0].stacktrace = event.exception.values[0].stacktrace || {};
6047
- event.exception.values[0].stacktrace.frames = event.exception.values[0].stacktrace.frames || [];
6048
- var colno = isNaN(parseInt(column, 10)) ? undefined : column;
6049
- var lineno = isNaN(parseInt(line, 10)) ? undefined : line;
6050
- var filename = isString(url) && url.length > 0 ? url : getLocationHref();
6051
- if (event.exception.values[0].stacktrace.frames.length === 0) {
6052
- event.exception.values[0].stacktrace.frames.push({
6053
- colno: colno,
6054
- filename: filename,
6055
- function: '?',
6056
- in_app: true,
6057
- lineno: lineno,
6058
- });
5779
+ var options = this._options;
5780
+ // We can disable guard-for-in as we construct the options object above + do checks against
5781
+ // `this._installFunc` for the property.
5782
+ // eslint-disable-next-line guard-for-in
5783
+ for (var key in options) {
5784
+ var installFunc = this._installFunc[key];
5785
+ if (installFunc && options[key]) {
5786
+ globalHandlerLog(key);
5787
+ installFunc();
5788
+ this._installFunc[key] = undefined;
5789
+ }
6059
5790
  }
6060
- return event;
6061
5791
  };
6062
5792
  /**
6063
5793
  * @inheritDoc
6064
5794
  */
6065
5795
  GlobalHandlers.id = 'GlobalHandlers';
6066
5796
  return GlobalHandlers;
6067
- }());
6068
-
6069
- var DEFAULT_EVENT_TARGET = [
6070
- 'EventTarget',
6071
- 'Window',
6072
- 'Node',
6073
- 'ApplicationCache',
6074
- 'AudioTrackList',
6075
- 'ChannelMergerNode',
6076
- 'CryptoOperation',
6077
- 'EventSource',
6078
- 'FileReader',
6079
- 'HTMLUnknownElement',
6080
- 'IDBDatabase',
6081
- 'IDBRequest',
6082
- 'IDBTransaction',
6083
- 'KeyOperation',
6084
- 'MediaController',
6085
- 'MessagePort',
6086
- 'ModalWindow',
6087
- 'Notification',
6088
- 'SVGElementInstance',
6089
- 'Screen',
6090
- 'TextTrack',
6091
- 'TextTrackCue',
6092
- 'TextTrackList',
6093
- 'WebSocket',
6094
- 'WebSocketWorker',
6095
- 'Worker',
6096
- 'XMLHttpRequest',
6097
- 'XMLHttpRequestEventTarget',
6098
- 'XMLHttpRequestUpload',
6099
- ];
6100
- /** Wrap timer functions and event targets to catch errors and provide better meta data */
6101
- var TryCatch = /** @class */ (function () {
6102
- /**
6103
- * @inheritDoc
6104
- */
6105
- function TryCatch(options) {
6106
- /**
6107
- * @inheritDoc
6108
- */
6109
- this.name = TryCatch.id;
6110
- this._options = __assign({ XMLHttpRequest: true, eventTarget: true, requestAnimationFrame: true, setInterval: true, setTimeout: true }, options);
6111
- }
6112
- /**
6113
- * Wrap timer functions and event targets to catch errors
6114
- * and provide better metadata.
6115
- */
6116
- TryCatch.prototype.setupOnce = function () {
6117
- var global = getGlobalObject();
6118
- if (this._options.setTimeout) {
6119
- fill(global, 'setTimeout', this._wrapTimeFunction.bind(this));
5797
+ }());
5798
+ /** JSDoc */
5799
+ function _installGlobalOnErrorHandler() {
5800
+ addInstrumentationHandler('error',
5801
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5802
+ function (data) {
5803
+ var _a = __read(getHubAndAttachStacktrace(), 2), hub = _a[0], attachStacktrace = _a[1];
5804
+ if (!hub.getIntegration(GlobalHandlers)) {
5805
+ return;
6120
5806
  }
6121
- if (this._options.setInterval) {
6122
- fill(global, 'setInterval', this._wrapTimeFunction.bind(this));
5807
+ var msg = data.msg, url = data.url, line = data.line, column = data.column, error = data.error;
5808
+ if (shouldIgnoreOnError() || (error && error.__sentry_own_request__)) {
5809
+ return;
6123
5810
  }
6124
- if (this._options.requestAnimationFrame) {
6125
- fill(global, 'requestAnimationFrame', this._wrapRAF.bind(this));
5811
+ var event = error === undefined && isString(msg)
5812
+ ? _eventFromIncompleteOnError(msg, url, line, column)
5813
+ : _enhanceEventWithInitialFrame(eventFromUnknownInput(error || msg, undefined, {
5814
+ attachStacktrace: attachStacktrace,
5815
+ rejection: false,
5816
+ }), url, line, column);
5817
+ addMechanismAndCapture(hub, error, event, 'onerror');
5818
+ });
5819
+ }
5820
+ /** JSDoc */
5821
+ function _installGlobalOnUnhandledRejectionHandler() {
5822
+ addInstrumentationHandler('unhandledrejection',
5823
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5824
+ function (e) {
5825
+ var _a = __read(getHubAndAttachStacktrace(), 2), hub = _a[0], attachStacktrace = _a[1];
5826
+ if (!hub.getIntegration(GlobalHandlers)) {
5827
+ return;
6126
5828
  }
6127
- if (this._options.XMLHttpRequest && 'XMLHttpRequest' in global) {
6128
- fill(XMLHttpRequest.prototype, 'send', this._wrapXHR.bind(this));
5829
+ var error = e;
5830
+ // dig the object of the rejection out of known event types
5831
+ try {
5832
+ // PromiseRejectionEvents store the object of the rejection under 'reason'
5833
+ // see https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent
5834
+ if ('reason' in e) {
5835
+ error = e.reason;
5836
+ }
5837
+ // something, somewhere, (likely a browser extension) effectively casts PromiseRejectionEvents
5838
+ // to CustomEvents, moving the `promise` and `reason` attributes of the PRE into
5839
+ // the CustomEvent's `detail` attribute, since they're not part of CustomEvent's spec
5840
+ // see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent and
5841
+ // https://github.com/getsentry/sentry-javascript/issues/2380
5842
+ else if ('detail' in e && 'reason' in e.detail) {
5843
+ error = e.detail.reason;
5844
+ }
6129
5845
  }
6130
- if (this._options.eventTarget) {
6131
- var eventTarget = Array.isArray(this._options.eventTarget) ? this._options.eventTarget : DEFAULT_EVENT_TARGET;
6132
- eventTarget.forEach(this._wrapEventTarget.bind(this));
5846
+ catch (_oO) {
5847
+ // no-empty
6133
5848
  }
6134
- };
6135
- /** JSDoc */
6136
- TryCatch.prototype._wrapTimeFunction = function (original) {
6137
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6138
- return function () {
6139
- var args = [];
6140
- for (var _i = 0; _i < arguments.length; _i++) {
6141
- args[_i] = arguments[_i];
6142
- }
6143
- var originalCallback = args[0];
6144
- args[0] = wrap(originalCallback, {
6145
- mechanism: {
6146
- data: { function: getFunctionName(original) },
6147
- handled: true,
6148
- type: 'instrument',
6149
- },
5849
+ if (shouldIgnoreOnError() || (error && error.__sentry_own_request__)) {
5850
+ return true;
5851
+ }
5852
+ var event = isPrimitive(error)
5853
+ ? _eventFromRejectionWithPrimitive(error)
5854
+ : eventFromUnknownInput(error, undefined, {
5855
+ attachStacktrace: attachStacktrace,
5856
+ rejection: true,
6150
5857
  });
6151
- return original.apply(this, args);
6152
- };
5858
+ event.level = 'error';
5859
+ addMechanismAndCapture(hub, error, event, 'onunhandledrejection');
5860
+ return;
5861
+ });
5862
+ }
5863
+ /**
5864
+ * Create an event from a promise rejection where the `reason` is a primitive.
5865
+ *
5866
+ * @param reason: The `reason` property of the promise rejection
5867
+ * @returns An Event object with an appropriate `exception` value
5868
+ */
5869
+ function _eventFromRejectionWithPrimitive(reason) {
5870
+ return {
5871
+ exception: {
5872
+ values: [
5873
+ {
5874
+ type: 'UnhandledRejection',
5875
+ // String() is needed because the Primitive type includes symbols (which can't be automatically stringified)
5876
+ value: "Non-Error promise rejection captured with value: " + String(reason),
5877
+ },
5878
+ ],
5879
+ },
6153
5880
  };
6154
- /** JSDoc */
6155
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6156
- TryCatch.prototype._wrapRAF = function (original) {
6157
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6158
- return function (callback) {
6159
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6160
- return original.call(this, wrap(callback, {
6161
- mechanism: {
6162
- data: {
6163
- function: 'requestAnimationFrame',
6164
- handler: getFunctionName(original),
6165
- },
6166
- handled: true,
6167
- type: 'instrument',
5881
+ }
5882
+ /**
5883
+ * This function creates a stack from an old, error-less onerror handler.
5884
+ */
5885
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5886
+ function _eventFromIncompleteOnError(msg, url, line, column) {
5887
+ var ERROR_TYPES_RE = /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i;
5888
+ // If 'message' is ErrorEvent, get real message from inside
5889
+ var message = isErrorEvent(msg) ? msg.message : msg;
5890
+ var name = 'Error';
5891
+ var groups = message.match(ERROR_TYPES_RE);
5892
+ if (groups) {
5893
+ name = groups[1];
5894
+ message = groups[2];
5895
+ }
5896
+ var event = {
5897
+ exception: {
5898
+ values: [
5899
+ {
5900
+ type: name,
5901
+ value: message,
6168
5902
  },
6169
- }));
6170
- };
5903
+ ],
5904
+ },
6171
5905
  };
6172
- /** JSDoc */
6173
- TryCatch.prototype._wrapEventTarget = function (target) {
6174
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
5906
+ return _enhanceEventWithInitialFrame(event, url, line, column);
5907
+ }
5908
+ /** JSDoc */
5909
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5910
+ function _enhanceEventWithInitialFrame(event, url, line, column) {
5911
+ // event.exception
5912
+ var e = (event.exception = event.exception || {});
5913
+ // event.exception.values
5914
+ var ev = (e.values = e.values || []);
5915
+ // event.exception.values[0]
5916
+ var ev0 = (ev[0] = ev[0] || {});
5917
+ // event.exception.values[0].stacktrace
5918
+ var ev0s = (ev0.stacktrace = ev0.stacktrace || {});
5919
+ // event.exception.values[0].stacktrace.frames
5920
+ var ev0sf = (ev0s.frames = ev0s.frames || []);
5921
+ var colno = isNaN(parseInt(column, 10)) ? undefined : column;
5922
+ var lineno = isNaN(parseInt(line, 10)) ? undefined : line;
5923
+ var filename = isString(url) && url.length > 0 ? url : getLocationHref();
5924
+ // event.exception.values[0].stacktrace.frames
5925
+ if (ev0sf.length === 0) {
5926
+ ev0sf.push({
5927
+ colno: colno,
5928
+ filename: filename,
5929
+ function: '?',
5930
+ in_app: true,
5931
+ lineno: lineno,
5932
+ });
5933
+ }
5934
+ return event;
5935
+ }
5936
+ function globalHandlerLog(type) {
5937
+ if (isDebugBuild()) {
5938
+ logger.log("Global Handler attached: " + type);
5939
+ }
5940
+ }
5941
+ function addMechanismAndCapture(hub, error, event, type) {
5942
+ addExceptionMechanism(event, {
5943
+ handled: false,
5944
+ type: type,
5945
+ });
5946
+ hub.captureEvent(event, {
5947
+ originalException: error,
5948
+ });
5949
+ }
5950
+ function getHubAndAttachStacktrace() {
5951
+ var hub = getCurrentHub();
5952
+ var client = hub.getClient();
5953
+ var attachStacktrace = client && client.getOptions().attachStacktrace;
5954
+ return [hub, attachStacktrace];
5955
+ }
5956
+
5957
+ var DEFAULT_EVENT_TARGET = [
5958
+ 'EventTarget',
5959
+ 'Window',
5960
+ 'Node',
5961
+ 'ApplicationCache',
5962
+ 'AudioTrackList',
5963
+ 'ChannelMergerNode',
5964
+ 'CryptoOperation',
5965
+ 'EventSource',
5966
+ 'FileReader',
5967
+ 'HTMLUnknownElement',
5968
+ 'IDBDatabase',
5969
+ 'IDBRequest',
5970
+ 'IDBTransaction',
5971
+ 'KeyOperation',
5972
+ 'MediaController',
5973
+ 'MessagePort',
5974
+ 'ModalWindow',
5975
+ 'Notification',
5976
+ 'SVGElementInstance',
5977
+ 'Screen',
5978
+ 'TextTrack',
5979
+ 'TextTrackCue',
5980
+ 'TextTrackList',
5981
+ 'WebSocket',
5982
+ 'WebSocketWorker',
5983
+ 'Worker',
5984
+ 'XMLHttpRequest',
5985
+ 'XMLHttpRequestEventTarget',
5986
+ 'XMLHttpRequestUpload',
5987
+ ];
5988
+ /** Wrap timer functions and event targets to catch errors and provide better meta data */
5989
+ var TryCatch = /** @class */ (function () {
5990
+ /**
5991
+ * @inheritDoc
5992
+ */
5993
+ function TryCatch(options) {
5994
+ /**
5995
+ * @inheritDoc
5996
+ */
5997
+ this.name = TryCatch.id;
5998
+ this._options = __assign({ XMLHttpRequest: true, eventTarget: true, requestAnimationFrame: true, setInterval: true, setTimeout: true }, options);
5999
+ }
6000
+ /**
6001
+ * Wrap timer functions and event targets to catch errors
6002
+ * and provide better metadata.
6003
+ */
6004
+ TryCatch.prototype.setupOnce = function () {
6175
6005
  var global = getGlobalObject();
6006
+ if (this._options.setTimeout) {
6007
+ fill(global, 'setTimeout', _wrapTimeFunction);
6008
+ }
6009
+ if (this._options.setInterval) {
6010
+ fill(global, 'setInterval', _wrapTimeFunction);
6011
+ }
6012
+ if (this._options.requestAnimationFrame) {
6013
+ fill(global, 'requestAnimationFrame', _wrapRAF);
6014
+ }
6015
+ if (this._options.XMLHttpRequest && 'XMLHttpRequest' in global) {
6016
+ fill(XMLHttpRequest.prototype, 'send', _wrapXHR);
6017
+ }
6018
+ var eventTargetOption = this._options.eventTarget;
6019
+ if (eventTargetOption) {
6020
+ var eventTarget = Array.isArray(eventTargetOption) ? eventTargetOption : DEFAULT_EVENT_TARGET;
6021
+ eventTarget.forEach(_wrapEventTarget);
6022
+ }
6023
+ };
6024
+ /**
6025
+ * @inheritDoc
6026
+ */
6027
+ TryCatch.id = 'TryCatch';
6028
+ return TryCatch;
6029
+ }());
6030
+ /** JSDoc */
6031
+ function _wrapTimeFunction(original) {
6032
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6033
+ return function () {
6034
+ var args = [];
6035
+ for (var _i = 0; _i < arguments.length; _i++) {
6036
+ args[_i] = arguments[_i];
6037
+ }
6038
+ var originalCallback = args[0];
6039
+ args[0] = wrap(originalCallback, {
6040
+ mechanism: {
6041
+ data: { function: getFunctionName(original) },
6042
+ handled: true,
6043
+ type: 'instrument',
6044
+ },
6045
+ });
6046
+ return original.apply(this, args);
6047
+ };
6048
+ }
6049
+ /** JSDoc */
6050
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6051
+ function _wrapRAF(original) {
6052
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6053
+ return function (callback) {
6176
6054
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6177
- var proto = global[target] && global[target].prototype;
6178
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-prototype-builtins
6179
- if (!proto || !proto.hasOwnProperty || !proto.hasOwnProperty('addEventListener')) {
6180
- return;
6055
+ return original.call(this, wrap(callback, {
6056
+ mechanism: {
6057
+ data: {
6058
+ function: 'requestAnimationFrame',
6059
+ handler: getFunctionName(original),
6060
+ },
6061
+ handled: true,
6062
+ type: 'instrument',
6063
+ },
6064
+ }));
6065
+ };
6066
+ }
6067
+ /** JSDoc */
6068
+ function _wrapXHR(originalSend) {
6069
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6070
+ return function () {
6071
+ var args = [];
6072
+ for (var _i = 0; _i < arguments.length; _i++) {
6073
+ args[_i] = arguments[_i];
6181
6074
  }
6182
- fill(proto, 'addEventListener', function (original) {
6183
- return function (eventName, fn, options) {
6184
- try {
6185
- if (typeof fn.handleEvent === 'function') {
6186
- fn.handleEvent = wrap(fn.handleEvent.bind(fn), {
6187
- mechanism: {
6188
- data: {
6189
- function: 'handleEvent',
6190
- handler: getFunctionName(fn),
6191
- target: target,
6192
- },
6193
- handled: true,
6194
- type: 'instrument',
6195
- },
6196
- });
6197
- }
6198
- }
6199
- catch (err) {
6200
- // can sometimes get 'Permission denied to access property "handle Event'
6201
- }
6202
- return original.call(this, eventName,
6075
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
6076
+ var xhr = this;
6077
+ var xmlHttpRequestProps = ['onload', 'onerror', 'onprogress', 'onreadystatechange'];
6078
+ xmlHttpRequestProps.forEach(function (prop) {
6079
+ if (prop in xhr && typeof xhr[prop] === 'function') {
6203
6080
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6204
- wrap(fn, {
6205
- mechanism: {
6206
- data: {
6207
- function: 'addEventListener',
6208
- handler: getFunctionName(fn),
6209
- target: target,
6081
+ fill(xhr, prop, function (original) {
6082
+ var wrapOptions = {
6083
+ mechanism: {
6084
+ data: {
6085
+ function: prop,
6086
+ handler: getFunctionName(original),
6087
+ },
6088
+ handled: true,
6089
+ type: 'instrument',
6210
6090
  },
6211
- handled: true,
6212
- type: 'instrument',
6213
- },
6214
- }), options);
6215
- };
6216
- });
6217
- fill(proto, 'removeEventListener', function (originalRemoveEventListener) {
6218
- return function (eventName, fn, options) {
6219
- var _a;
6220
- /**
6221
- * There are 2 possible scenarios here:
6222
- *
6223
- * 1. Someone passes a callback, which was attached prior to Sentry initialization, or by using unmodified
6224
- * method, eg. `document.addEventListener.call(el, name, handler). In this case, we treat this function
6225
- * as a pass-through, and call original `removeEventListener` with it.
6226
- *
6227
- * 2. Someone passes a callback, which was attached after Sentry was initialized, which means that it was using
6228
- * our wrapped version of `addEventListener`, which internally calls `wrap` helper.
6229
- * This helper "wraps" whole callback inside a try/catch statement, and attached appropriate metadata to it,
6230
- * in order for us to make a distinction between wrapped/non-wrapped functions possible.
6231
- * If a function was wrapped, it has additional property of `__sentry_wrapped__`, holding the handler.
6232
- *
6233
- * When someone adds a handler prior to initialization, and then do it again, but after,
6234
- * then we have to detach both of them. Otherwise, if we'd detach only wrapped one, it'd be impossible
6235
- * to get rid of the initial handler and it'd stick there forever.
6236
- */
6237
- var wrappedEventHandler = fn;
6238
- try {
6239
- var originalEventHandler = (_a = wrappedEventHandler) === null || _a === void 0 ? void 0 : _a.__sentry_wrapped__;
6240
- if (originalEventHandler) {
6241
- originalRemoveEventListener.call(this, eventName, originalEventHandler, options);
6091
+ };
6092
+ // If Instrument integration has been called before TryCatch, get the name of original function
6093
+ var originalFunction = getOriginalFunction(original);
6094
+ if (originalFunction) {
6095
+ wrapOptions.mechanism.data.handler = getFunctionName(originalFunction);
6242
6096
  }
6243
- }
6244
- catch (e) {
6245
- // ignore, accessing __sentry_wrapped__ will throw in some Selenium environments
6246
- }
6247
- return originalRemoveEventListener.call(this, eventName, wrappedEventHandler, options);
6248
- };
6097
+ // Otherwise wrap directly
6098
+ return wrap(original, wrapOptions);
6099
+ });
6100
+ }
6249
6101
  });
6102
+ return originalSend.apply(this, args);
6250
6103
  };
6251
- /** JSDoc */
6252
- TryCatch.prototype._wrapXHR = function (originalSend) {
6253
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6254
- return function () {
6255
- var args = [];
6256
- for (var _i = 0; _i < arguments.length; _i++) {
6257
- args[_i] = arguments[_i];
6258
- }
6259
- // eslint-disable-next-line @typescript-eslint/no-this-alias
6260
- var xhr = this;
6261
- var xmlHttpRequestProps = ['onload', 'onerror', 'onprogress', 'onreadystatechange'];
6262
- xmlHttpRequestProps.forEach(function (prop) {
6263
- if (prop in xhr && typeof xhr[prop] === 'function') {
6264
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6265
- fill(xhr, prop, function (original) {
6266
- var wrapOptions = {
6267
- mechanism: {
6268
- data: {
6269
- function: prop,
6270
- handler: getFunctionName(original),
6271
- },
6272
- handled: true,
6273
- type: 'instrument',
6104
+ }
6105
+ /** JSDoc */
6106
+ function _wrapEventTarget(target) {
6107
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6108
+ var global = getGlobalObject();
6109
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6110
+ var proto = global[target] && global[target].prototype;
6111
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-prototype-builtins
6112
+ if (!proto || !proto.hasOwnProperty || !proto.hasOwnProperty('addEventListener')) {
6113
+ return;
6114
+ }
6115
+ fill(proto, 'addEventListener', function (original) {
6116
+ return function (eventName, fn, options) {
6117
+ try {
6118
+ if (typeof fn.handleEvent === 'function') {
6119
+ fn.handleEvent = wrap(fn.handleEvent.bind(fn), {
6120
+ mechanism: {
6121
+ data: {
6122
+ function: 'handleEvent',
6123
+ handler: getFunctionName(fn),
6124
+ target: target,
6274
6125
  },
6275
- };
6276
- // If Instrument integration has been called before TryCatch, get the name of original function
6277
- if (original.__sentry_original__) {
6278
- wrapOptions.mechanism.data.handler = getFunctionName(original.__sentry_original__);
6279
- }
6280
- // Otherwise wrap directly
6281
- return wrap(original, wrapOptions);
6126
+ handled: true,
6127
+ type: 'instrument',
6128
+ },
6282
6129
  });
6283
6130
  }
6284
- });
6285
- return originalSend.apply(this, args);
6131
+ }
6132
+ catch (err) {
6133
+ // can sometimes get 'Permission denied to access property "handle Event'
6134
+ }
6135
+ return original.call(this, eventName,
6136
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6137
+ wrap(fn, {
6138
+ mechanism: {
6139
+ data: {
6140
+ function: 'addEventListener',
6141
+ handler: getFunctionName(fn),
6142
+ target: target,
6143
+ },
6144
+ handled: true,
6145
+ type: 'instrument',
6146
+ },
6147
+ }), options);
6286
6148
  };
6287
- };
6288
- /**
6289
- * @inheritDoc
6290
- */
6291
- TryCatch.id = 'TryCatch';
6292
- return TryCatch;
6293
- }());
6149
+ });
6150
+ fill(proto, 'removeEventListener', function (originalRemoveEventListener) {
6151
+ return function (eventName, fn, options) {
6152
+ /**
6153
+ * There are 2 possible scenarios here:
6154
+ *
6155
+ * 1. Someone passes a callback, which was attached prior to Sentry initialization, or by using unmodified
6156
+ * method, eg. `document.addEventListener.call(el, name, handler). In this case, we treat this function
6157
+ * as a pass-through, and call original `removeEventListener` with it.
6158
+ *
6159
+ * 2. Someone passes a callback, which was attached after Sentry was initialized, which means that it was using
6160
+ * our wrapped version of `addEventListener`, which internally calls `wrap` helper.
6161
+ * This helper "wraps" whole callback inside a try/catch statement, and attached appropriate metadata to it,
6162
+ * in order for us to make a distinction between wrapped/non-wrapped functions possible.
6163
+ * If a function was wrapped, it has additional property of `__sentry_wrapped__`, holding the handler.
6164
+ *
6165
+ * When someone adds a handler prior to initialization, and then do it again, but after,
6166
+ * then we have to detach both of them. Otherwise, if we'd detach only wrapped one, it'd be impossible
6167
+ * to get rid of the initial handler and it'd stick there forever.
6168
+ */
6169
+ var wrappedEventHandler = fn;
6170
+ try {
6171
+ var originalEventHandler = wrappedEventHandler && wrappedEventHandler.__sentry_wrapped__;
6172
+ if (originalEventHandler) {
6173
+ originalRemoveEventListener.call(this, eventName, originalEventHandler, options);
6174
+ }
6175
+ }
6176
+ catch (e) {
6177
+ // ignore, accessing __sentry_wrapped__ will throw in some Selenium environments
6178
+ }
6179
+ return originalRemoveEventListener.call(this, eventName, wrappedEventHandler, options);
6180
+ };
6181
+ });
6182
+ }
6294
6183
 
6295
6184
  /**
6296
6185
  * Default Breadcrumbs instrumentations
@@ -6332,104 +6221,38 @@ var Sentry = (function (exports) {
6332
6221
  * - History API
6333
6222
  */
6334
6223
  Breadcrumbs.prototype.setupOnce = function () {
6335
- var _this = this;
6336
6224
  if (this._options.console) {
6337
- addInstrumentationHandler({
6338
- callback: function () {
6339
- var args = [];
6340
- for (var _i = 0; _i < arguments.length; _i++) {
6341
- args[_i] = arguments[_i];
6342
- }
6343
- _this._consoleBreadcrumb.apply(_this, __spread(args));
6344
- },
6345
- type: 'console',
6346
- });
6225
+ addInstrumentationHandler('console', _consoleBreadcrumb);
6347
6226
  }
6348
6227
  if (this._options.dom) {
6349
- addInstrumentationHandler({
6350
- callback: function () {
6351
- var args = [];
6352
- for (var _i = 0; _i < arguments.length; _i++) {
6353
- args[_i] = arguments[_i];
6354
- }
6355
- _this._domBreadcrumb.apply(_this, __spread(args));
6356
- },
6357
- type: 'dom',
6358
- });
6228
+ addInstrumentationHandler('dom', _domBreadcrumb(this._options.dom));
6359
6229
  }
6360
6230
  if (this._options.xhr) {
6361
- addInstrumentationHandler({
6362
- callback: function () {
6363
- var args = [];
6364
- for (var _i = 0; _i < arguments.length; _i++) {
6365
- args[_i] = arguments[_i];
6366
- }
6367
- _this._xhrBreadcrumb.apply(_this, __spread(args));
6368
- },
6369
- type: 'xhr',
6370
- });
6371
- }
6372
- if (this._options.fetch) {
6373
- addInstrumentationHandler({
6374
- callback: function () {
6375
- var args = [];
6376
- for (var _i = 0; _i < arguments.length; _i++) {
6377
- args[_i] = arguments[_i];
6378
- }
6379
- _this._fetchBreadcrumb.apply(_this, __spread(args));
6380
- },
6381
- type: 'fetch',
6382
- });
6383
- }
6384
- if (this._options.history) {
6385
- addInstrumentationHandler({
6386
- callback: function () {
6387
- var args = [];
6388
- for (var _i = 0; _i < arguments.length; _i++) {
6389
- args[_i] = arguments[_i];
6390
- }
6391
- _this._historyBreadcrumb.apply(_this, __spread(args));
6392
- },
6393
- type: 'history',
6394
- });
6395
- }
6396
- };
6397
- /**
6398
- * Creates breadcrumbs from console API calls
6399
- */
6400
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6401
- Breadcrumbs.prototype._consoleBreadcrumb = function (handlerData) {
6402
- var breadcrumb = {
6403
- category: 'console',
6404
- data: {
6405
- arguments: handlerData.args,
6406
- logger: 'console',
6407
- },
6408
- level: exports.Severity.fromString(handlerData.level),
6409
- message: safeJoin(handlerData.args, ' '),
6410
- };
6411
- if (handlerData.level === 'assert') {
6412
- if (handlerData.args[0] === false) {
6413
- breadcrumb.message = "Assertion failed: " + (safeJoin(handlerData.args.slice(1), ' ') || 'console.assert');
6414
- breadcrumb.data.arguments = handlerData.args.slice(1);
6415
- }
6416
- else {
6417
- // Don't capture a breadcrumb for passed assertions
6418
- return;
6419
- }
6231
+ addInstrumentationHandler('xhr', _xhrBreadcrumb);
6232
+ }
6233
+ if (this._options.fetch) {
6234
+ addInstrumentationHandler('fetch', _fetchBreadcrumb);
6235
+ }
6236
+ if (this._options.history) {
6237
+ addInstrumentationHandler('history', _historyBreadcrumb);
6420
6238
  }
6421
- getCurrentHub().addBreadcrumb(breadcrumb, {
6422
- input: handlerData.args,
6423
- level: handlerData.level,
6424
- });
6425
6239
  };
6426
6240
  /**
6427
- * Creates breadcrumbs from DOM API calls
6241
+ * @inheritDoc
6428
6242
  */
6243
+ Breadcrumbs.id = 'Breadcrumbs';
6244
+ return Breadcrumbs;
6245
+ }());
6246
+ /**
6247
+ * A HOC that creaes a function that creates breadcrumbs from DOM API calls.
6248
+ * This is a HOC so that we get access to dom options in the closure.
6249
+ */
6250
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6251
+ function _domBreadcrumb(dom) {
6429
6252
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6430
- Breadcrumbs.prototype._domBreadcrumb = function (handlerData) {
6253
+ function _innerDomBreadcrumb(handlerData) {
6431
6254
  var target;
6432
- var keyAttrs = typeof this._options.dom === 'object' ? this._options.dom.serializeAttribute : undefined;
6255
+ var keyAttrs = typeof dom === 'object' ? dom.serializeAttribute : undefined;
6433
6256
  if (typeof keyAttrs === 'string') {
6434
6257
  keyAttrs = [keyAttrs];
6435
6258
  }
@@ -6453,105 +6276,130 @@ var Sentry = (function (exports) {
6453
6276
  name: handlerData.name,
6454
6277
  global: handlerData.global,
6455
6278
  });
6279
+ }
6280
+ return _innerDomBreadcrumb;
6281
+ }
6282
+ /**
6283
+ * Creates breadcrumbs from console API calls
6284
+ */
6285
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6286
+ function _consoleBreadcrumb(handlerData) {
6287
+ var breadcrumb = {
6288
+ category: 'console',
6289
+ data: {
6290
+ arguments: handlerData.args,
6291
+ logger: 'console',
6292
+ },
6293
+ level: severityFromString(handlerData.level),
6294
+ message: safeJoin(handlerData.args, ' '),
6456
6295
  };
6457
- /**
6458
- * Creates breadcrumbs from XHR API calls
6459
- */
6460
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6461
- Breadcrumbs.prototype._xhrBreadcrumb = function (handlerData) {
6462
- if (handlerData.endTimestamp) {
6463
- // We only capture complete, non-sentry requests
6464
- if (handlerData.xhr.__sentry_own_request__) {
6465
- return;
6466
- }
6467
- var _a = handlerData.xhr.__sentry_xhr__ || {}, method = _a.method, url = _a.url, status_code = _a.status_code, body = _a.body;
6468
- getCurrentHub().addBreadcrumb({
6469
- category: 'xhr',
6470
- data: {
6471
- method: method,
6472
- url: url,
6473
- status_code: status_code,
6474
- },
6475
- type: 'http',
6476
- }, {
6477
- xhr: handlerData.xhr,
6478
- input: body,
6479
- });
6480
- return;
6296
+ if (handlerData.level === 'assert') {
6297
+ if (handlerData.args[0] === false) {
6298
+ breadcrumb.message = "Assertion failed: " + (safeJoin(handlerData.args.slice(1), ' ') || 'console.assert');
6299
+ breadcrumb.data.arguments = handlerData.args.slice(1);
6481
6300
  }
6482
- };
6483
- /**
6484
- * Creates breadcrumbs from fetch API calls
6485
- */
6486
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6487
- Breadcrumbs.prototype._fetchBreadcrumb = function (handlerData) {
6488
- // We only capture complete fetch requests
6489
- if (!handlerData.endTimestamp) {
6301
+ else {
6302
+ // Don't capture a breadcrumb for passed assertions
6490
6303
  return;
6491
6304
  }
6492
- if (handlerData.fetchData.url.match(/sentry_key/) && handlerData.fetchData.method === 'POST') {
6493
- // We will not create breadcrumbs for fetch requests that contain `sentry_key` (internal sentry requests)
6305
+ }
6306
+ getCurrentHub().addBreadcrumb(breadcrumb, {
6307
+ input: handlerData.args,
6308
+ level: handlerData.level,
6309
+ });
6310
+ }
6311
+ /**
6312
+ * Creates breadcrumbs from XHR API calls
6313
+ */
6314
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6315
+ function _xhrBreadcrumb(handlerData) {
6316
+ if (handlerData.endTimestamp) {
6317
+ // We only capture complete, non-sentry requests
6318
+ if (handlerData.xhr.__sentry_own_request__) {
6494
6319
  return;
6495
6320
  }
6496
- if (handlerData.error) {
6497
- getCurrentHub().addBreadcrumb({
6498
- category: 'fetch',
6499
- data: handlerData.fetchData,
6500
- level: exports.Severity.Error,
6501
- type: 'http',
6502
- }, {
6503
- data: handlerData.error,
6504
- input: handlerData.args,
6505
- });
6506
- }
6507
- else {
6508
- getCurrentHub().addBreadcrumb({
6509
- category: 'fetch',
6510
- data: __assign(__assign({}, handlerData.fetchData), { status_code: handlerData.response.status }),
6511
- type: 'http',
6512
- }, {
6513
- input: handlerData.args,
6514
- response: handlerData.response,
6515
- });
6516
- }
6517
- };
6518
- /**
6519
- * Creates breadcrumbs from history API calls
6520
- */
6521
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6522
- Breadcrumbs.prototype._historyBreadcrumb = function (handlerData) {
6523
- var global = getGlobalObject();
6524
- var from = handlerData.from;
6525
- var to = handlerData.to;
6526
- var parsedLoc = parseUrl(global.location.href);
6527
- var parsedFrom = parseUrl(from);
6528
- var parsedTo = parseUrl(to);
6529
- // Initial pushState doesn't provide `from` information
6530
- if (!parsedFrom.path) {
6531
- parsedFrom = parsedLoc;
6532
- }
6533
- // Use only the path component of the URL if the URL matches the current
6534
- // document (almost all the time when using pushState)
6535
- if (parsedLoc.protocol === parsedTo.protocol && parsedLoc.host === parsedTo.host) {
6536
- to = parsedTo.relative;
6537
- }
6538
- if (parsedLoc.protocol === parsedFrom.protocol && parsedLoc.host === parsedFrom.host) {
6539
- from = parsedFrom.relative;
6540
- }
6321
+ var _a = handlerData.xhr.__sentry_xhr__ || {}, method = _a.method, url = _a.url, status_code = _a.status_code, body = _a.body;
6541
6322
  getCurrentHub().addBreadcrumb({
6542
- category: 'navigation',
6323
+ category: 'xhr',
6543
6324
  data: {
6544
- from: from,
6545
- to: to,
6325
+ method: method,
6326
+ url: url,
6327
+ status_code: status_code,
6546
6328
  },
6329
+ type: 'http',
6330
+ }, {
6331
+ xhr: handlerData.xhr,
6332
+ input: body,
6547
6333
  });
6548
- };
6549
- /**
6550
- * @inheritDoc
6551
- */
6552
- Breadcrumbs.id = 'Breadcrumbs';
6553
- return Breadcrumbs;
6554
- }());
6334
+ return;
6335
+ }
6336
+ }
6337
+ /**
6338
+ * Creates breadcrumbs from fetch API calls
6339
+ */
6340
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6341
+ function _fetchBreadcrumb(handlerData) {
6342
+ // We only capture complete fetch requests
6343
+ if (!handlerData.endTimestamp) {
6344
+ return;
6345
+ }
6346
+ if (handlerData.fetchData.url.match(/sentry_key/) && handlerData.fetchData.method === 'POST') {
6347
+ // We will not create breadcrumbs for fetch requests that contain `sentry_key` (internal sentry requests)
6348
+ return;
6349
+ }
6350
+ if (handlerData.error) {
6351
+ getCurrentHub().addBreadcrumb({
6352
+ category: 'fetch',
6353
+ data: handlerData.fetchData,
6354
+ level: 'error',
6355
+ type: 'http',
6356
+ }, {
6357
+ data: handlerData.error,
6358
+ input: handlerData.args,
6359
+ });
6360
+ }
6361
+ else {
6362
+ getCurrentHub().addBreadcrumb({
6363
+ category: 'fetch',
6364
+ data: __assign(__assign({}, handlerData.fetchData), { status_code: handlerData.response.status }),
6365
+ type: 'http',
6366
+ }, {
6367
+ input: handlerData.args,
6368
+ response: handlerData.response,
6369
+ });
6370
+ }
6371
+ }
6372
+ /**
6373
+ * Creates breadcrumbs from history API calls
6374
+ */
6375
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6376
+ function _historyBreadcrumb(handlerData) {
6377
+ var global = getGlobalObject();
6378
+ var from = handlerData.from;
6379
+ var to = handlerData.to;
6380
+ var parsedLoc = parseUrl(global.location.href);
6381
+ var parsedFrom = parseUrl(from);
6382
+ var parsedTo = parseUrl(to);
6383
+ // Initial pushState doesn't provide `from` information
6384
+ if (!parsedFrom.path) {
6385
+ parsedFrom = parsedLoc;
6386
+ }
6387
+ // Use only the path component of the URL if the URL matches the current
6388
+ // document (almost all the time when using pushState)
6389
+ if (parsedLoc.protocol === parsedTo.protocol && parsedLoc.host === parsedTo.host) {
6390
+ to = parsedTo.relative;
6391
+ }
6392
+ if (parsedLoc.protocol === parsedFrom.protocol && parsedLoc.host === parsedFrom.host) {
6393
+ from = parsedFrom.relative;
6394
+ }
6395
+ getCurrentHub().addBreadcrumb({
6396
+ category: 'navigation',
6397
+ data: {
6398
+ from: from,
6399
+ to: to,
6400
+ },
6401
+ });
6402
+ }
6555
6403
 
6556
6404
  var DEFAULT_KEY = 'cause';
6557
6405
  var DEFAULT_LIMIT = 5;
@@ -6575,42 +6423,38 @@ var Sentry = (function (exports) {
6575
6423
  LinkedErrors.prototype.setupOnce = function () {
6576
6424
  addGlobalEventProcessor(function (event, hint) {
6577
6425
  var self = getCurrentHub().getIntegration(LinkedErrors);
6578
- if (self) {
6579
- var handler = self._handler && self._handler.bind(self);
6580
- return typeof handler === 'function' ? handler(event, hint) : event;
6581
- }
6582
- return event;
6426
+ return self ? _handler(self._key, self._limit, event, hint) : event;
6583
6427
  });
6584
6428
  };
6585
- /**
6586
- * @inheritDoc
6587
- */
6588
- LinkedErrors.prototype._handler = function (event, hint) {
6589
- if (!event.exception || !event.exception.values || !hint || !isInstanceOf(hint.originalException, Error)) {
6590
- return event;
6591
- }
6592
- var linkedErrors = this._walkErrorTree(hint.originalException, this._key);
6593
- event.exception.values = __spread(linkedErrors, event.exception.values);
6594
- return event;
6595
- };
6596
- /**
6597
- * @inheritDoc
6598
- */
6599
- LinkedErrors.prototype._walkErrorTree = function (error, key, stack) {
6600
- if (stack === void 0) { stack = []; }
6601
- if (!isInstanceOf(error[key], Error) || stack.length + 1 >= this._limit) {
6602
- return stack;
6603
- }
6604
- var stacktrace = computeStackTrace(error[key]);
6605
- var exception = exceptionFromStacktrace(stacktrace);
6606
- return this._walkErrorTree(error[key], key, __spread([exception], stack));
6607
- };
6608
6429
  /**
6609
6430
  * @inheritDoc
6610
6431
  */
6611
6432
  LinkedErrors.id = 'LinkedErrors';
6612
6433
  return LinkedErrors;
6613
- }());
6434
+ }());
6435
+ /**
6436
+ * @inheritDoc
6437
+ */
6438
+ function _handler(key, limit, event, hint) {
6439
+ if (!event.exception || !event.exception.values || !hint || !isInstanceOf(hint.originalException, Error)) {
6440
+ return event;
6441
+ }
6442
+ var linkedErrors = _walkErrorTree(limit, hint.originalException, key);
6443
+ event.exception.values = __spread(linkedErrors, event.exception.values);
6444
+ return event;
6445
+ }
6446
+ /**
6447
+ * JSDOC
6448
+ */
6449
+ function _walkErrorTree(limit, error, key, stack) {
6450
+ if (stack === void 0) { stack = []; }
6451
+ if (!isInstanceOf(error[key], Error) || stack.length + 1 >= limit) {
6452
+ return stack;
6453
+ }
6454
+ var stacktrace = computeStackTrace(error[key]);
6455
+ var exception = exceptionFromStacktrace(stacktrace);
6456
+ return _walkErrorTree(limit, error[key], key, __spread([exception], stack));
6457
+ }
6614
6458
 
6615
6459
  var global$6 = getGlobalObject();
6616
6460
  /** UserAgent */
@@ -6626,17 +6470,16 @@ var Sentry = (function (exports) {
6626
6470
  */
6627
6471
  UserAgent.prototype.setupOnce = function () {
6628
6472
  addGlobalEventProcessor(function (event) {
6629
- var _a, _b, _c;
6630
6473
  if (getCurrentHub().getIntegration(UserAgent)) {
6631
6474
  // if none of the information we want exists, don't bother
6632
6475
  if (!global$6.navigator && !global$6.location && !global$6.document) {
6633
6476
  return event;
6634
6477
  }
6635
6478
  // grab as much info as exists and add it to the event
6636
- 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);
6479
+ var url = (event.request && event.request.url) || (global$6.location && global$6.location.href);
6637
6480
  var referrer = (global$6.document || {}).referrer;
6638
6481
  var userAgent = (global$6.navigator || {}).userAgent;
6639
- var headers = __assign(__assign(__assign({}, (_c = event.request) === null || _c === void 0 ? void 0 : _c.headers), (referrer && { Referer: referrer })), (userAgent && { 'User-Agent': userAgent }));
6482
+ var headers = __assign(__assign(__assign({}, (event.request && event.request.headers)), (referrer && { Referer: referrer })), (userAgent && { 'User-Agent': userAgent }));
6640
6483
  var request = __assign(__assign({}, (url && { url: url })), { headers: headers });
6641
6484
  return __assign(__assign({}, event), { request: request });
6642
6485
  }
@@ -6667,7 +6510,7 @@ var Sentry = (function (exports) {
6667
6510
  if (self) {
6668
6511
  // Juuust in case something goes wrong
6669
6512
  try {
6670
- if (self._shouldDropEvent(currentEvent, self._previousEvent)) {
6513
+ if (_shouldDropEvent(currentEvent, self._previousEvent)) {
6671
6514
  logger.warn("Event dropped due to being a duplicate of previously captured event.");
6672
6515
  return null;
6673
6516
  }
@@ -6680,140 +6523,140 @@ var Sentry = (function (exports) {
6680
6523
  return currentEvent;
6681
6524
  });
6682
6525
  };
6683
- /** JSDoc */
6684
- Dedupe.prototype._shouldDropEvent = function (currentEvent, previousEvent) {
6685
- if (!previousEvent) {
6686
- return false;
6687
- }
6688
- if (this._isSameMessageEvent(currentEvent, previousEvent)) {
6689
- return true;
6690
- }
6691
- if (this._isSameExceptionEvent(currentEvent, previousEvent)) {
6692
- return true;
6693
- }
6526
+ /**
6527
+ * @inheritDoc
6528
+ */
6529
+ Dedupe.id = 'Dedupe';
6530
+ return Dedupe;
6531
+ }());
6532
+ /** JSDoc */
6533
+ function _shouldDropEvent(currentEvent, previousEvent) {
6534
+ if (!previousEvent) {
6694
6535
  return false;
6695
- };
6696
- /** JSDoc */
6697
- Dedupe.prototype._isSameMessageEvent = function (currentEvent, previousEvent) {
6698
- var currentMessage = currentEvent.message;
6699
- var previousMessage = previousEvent.message;
6700
- // If neither event has a message property, they were both exceptions, so bail out
6701
- if (!currentMessage && !previousMessage) {
6702
- return false;
6703
- }
6704
- // If only one event has a stacktrace, but not the other one, they are not the same
6705
- if ((currentMessage && !previousMessage) || (!currentMessage && previousMessage)) {
6706
- return false;
6707
- }
6708
- if (currentMessage !== previousMessage) {
6709
- return false;
6710
- }
6711
- if (!this._isSameFingerprint(currentEvent, previousEvent)) {
6712
- return false;
6713
- }
6714
- if (!this._isSameStacktrace(currentEvent, previousEvent)) {
6715
- return false;
6716
- }
6536
+ }
6537
+ if (_isSameMessageEvent(currentEvent, previousEvent)) {
6717
6538
  return true;
6718
- };
6719
- /** JSDoc */
6720
- Dedupe.prototype._getFramesFromEvent = function (event) {
6721
- var exception = event.exception;
6722
- if (exception) {
6723
- try {
6724
- // @ts-ignore Object could be undefined
6725
- return exception.values[0].stacktrace.frames;
6726
- }
6727
- catch (_oO) {
6728
- return undefined;
6729
- }
6730
- }
6731
- else if (event.stacktrace) {
6732
- return event.stacktrace.frames;
6733
- }
6734
- return undefined;
6735
- };
6736
- /** JSDoc */
6737
- Dedupe.prototype._isSameStacktrace = function (currentEvent, previousEvent) {
6738
- var currentFrames = this._getFramesFromEvent(currentEvent);
6739
- var previousFrames = this._getFramesFromEvent(previousEvent);
6740
- // If neither event has a stacktrace, they are assumed to be the same
6741
- if (!currentFrames && !previousFrames) {
6742
- return true;
6743
- }
6744
- // If only one event has a stacktrace, but not the other one, they are not the same
6745
- if ((currentFrames && !previousFrames) || (!currentFrames && previousFrames)) {
6746
- return false;
6747
- }
6748
- currentFrames = currentFrames;
6749
- previousFrames = previousFrames;
6750
- // If number of frames differ, they are not the same
6751
- if (previousFrames.length !== currentFrames.length) {
6752
- return false;
6753
- }
6754
- // Otherwise, compare the two
6755
- for (var i = 0; i < previousFrames.length; i++) {
6756
- var frameA = previousFrames[i];
6757
- var frameB = currentFrames[i];
6758
- if (frameA.filename !== frameB.filename ||
6759
- frameA.lineno !== frameB.lineno ||
6760
- frameA.colno !== frameB.colno ||
6761
- frameA.function !== frameB.function) {
6762
- return false;
6763
- }
6764
- }
6539
+ }
6540
+ if (_isSameExceptionEvent(currentEvent, previousEvent)) {
6765
6541
  return true;
6766
- };
6767
- /** JSDoc */
6768
- Dedupe.prototype._getExceptionFromEvent = function (event) {
6769
- return event.exception && event.exception.values && event.exception.values[0];
6770
- };
6771
- /** JSDoc */
6772
- Dedupe.prototype._isSameExceptionEvent = function (currentEvent, previousEvent) {
6773
- var previousException = this._getExceptionFromEvent(previousEvent);
6774
- var currentException = this._getExceptionFromEvent(currentEvent);
6775
- if (!previousException || !currentException) {
6776
- return false;
6777
- }
6778
- if (previousException.type !== currentException.type || previousException.value !== currentException.value) {
6779
- return false;
6780
- }
6781
- if (!this._isSameFingerprint(currentEvent, previousEvent)) {
6782
- return false;
6783
- }
6784
- if (!this._isSameStacktrace(currentEvent, previousEvent)) {
6785
- return false;
6786
- }
6542
+ }
6543
+ return false;
6544
+ }
6545
+ /** JSDoc */
6546
+ function _isSameMessageEvent(currentEvent, previousEvent) {
6547
+ var currentMessage = currentEvent.message;
6548
+ var previousMessage = previousEvent.message;
6549
+ // If neither event has a message property, they were both exceptions, so bail out
6550
+ if (!currentMessage && !previousMessage) {
6551
+ return false;
6552
+ }
6553
+ // If only one event has a stacktrace, but not the other one, they are not the same
6554
+ if ((currentMessage && !previousMessage) || (!currentMessage && previousMessage)) {
6555
+ return false;
6556
+ }
6557
+ if (currentMessage !== previousMessage) {
6558
+ return false;
6559
+ }
6560
+ if (!_isSameFingerprint(currentEvent, previousEvent)) {
6561
+ return false;
6562
+ }
6563
+ if (!_isSameStacktrace(currentEvent, previousEvent)) {
6564
+ return false;
6565
+ }
6566
+ return true;
6567
+ }
6568
+ /** JSDoc */
6569
+ function _isSameExceptionEvent(currentEvent, previousEvent) {
6570
+ var previousException = _getExceptionFromEvent(previousEvent);
6571
+ var currentException = _getExceptionFromEvent(currentEvent);
6572
+ if (!previousException || !currentException) {
6573
+ return false;
6574
+ }
6575
+ if (previousException.type !== currentException.type || previousException.value !== currentException.value) {
6576
+ return false;
6577
+ }
6578
+ if (!_isSameFingerprint(currentEvent, previousEvent)) {
6579
+ return false;
6580
+ }
6581
+ if (!_isSameStacktrace(currentEvent, previousEvent)) {
6582
+ return false;
6583
+ }
6584
+ return true;
6585
+ }
6586
+ /** JSDoc */
6587
+ function _isSameStacktrace(currentEvent, previousEvent) {
6588
+ var currentFrames = _getFramesFromEvent(currentEvent);
6589
+ var previousFrames = _getFramesFromEvent(previousEvent);
6590
+ // If neither event has a stacktrace, they are assumed to be the same
6591
+ if (!currentFrames && !previousFrames) {
6787
6592
  return true;
6788
- };
6789
- /** JSDoc */
6790
- Dedupe.prototype._isSameFingerprint = function (currentEvent, previousEvent) {
6791
- var currentFingerprint = currentEvent.fingerprint;
6792
- var previousFingerprint = previousEvent.fingerprint;
6793
- // If neither event has a fingerprint, they are assumed to be the same
6794
- if (!currentFingerprint && !previousFingerprint) {
6795
- return true;
6796
- }
6797
- // If only one event has a fingerprint, but not the other one, they are not the same
6798
- if ((currentFingerprint && !previousFingerprint) || (!currentFingerprint && previousFingerprint)) {
6593
+ }
6594
+ // If only one event has a stacktrace, but not the other one, they are not the same
6595
+ if ((currentFrames && !previousFrames) || (!currentFrames && previousFrames)) {
6596
+ return false;
6597
+ }
6598
+ currentFrames = currentFrames;
6599
+ previousFrames = previousFrames;
6600
+ // If number of frames differ, they are not the same
6601
+ if (previousFrames.length !== currentFrames.length) {
6602
+ return false;
6603
+ }
6604
+ // Otherwise, compare the two
6605
+ for (var i = 0; i < previousFrames.length; i++) {
6606
+ var frameA = previousFrames[i];
6607
+ var frameB = currentFrames[i];
6608
+ if (frameA.filename !== frameB.filename ||
6609
+ frameA.lineno !== frameB.lineno ||
6610
+ frameA.colno !== frameB.colno ||
6611
+ frameA.function !== frameB.function) {
6799
6612
  return false;
6800
6613
  }
6801
- currentFingerprint = currentFingerprint;
6802
- previousFingerprint = previousFingerprint;
6803
- // Otherwise, compare the two
6614
+ }
6615
+ return true;
6616
+ }
6617
+ /** JSDoc */
6618
+ function _isSameFingerprint(currentEvent, previousEvent) {
6619
+ var currentFingerprint = currentEvent.fingerprint;
6620
+ var previousFingerprint = previousEvent.fingerprint;
6621
+ // If neither event has a fingerprint, they are assumed to be the same
6622
+ if (!currentFingerprint && !previousFingerprint) {
6623
+ return true;
6624
+ }
6625
+ // If only one event has a fingerprint, but not the other one, they are not the same
6626
+ if ((currentFingerprint && !previousFingerprint) || (!currentFingerprint && previousFingerprint)) {
6627
+ return false;
6628
+ }
6629
+ currentFingerprint = currentFingerprint;
6630
+ previousFingerprint = previousFingerprint;
6631
+ // Otherwise, compare the two
6632
+ try {
6633
+ return !!(currentFingerprint.join('') === previousFingerprint.join(''));
6634
+ }
6635
+ catch (_oO) {
6636
+ return false;
6637
+ }
6638
+ }
6639
+ /** JSDoc */
6640
+ function _getExceptionFromEvent(event) {
6641
+ return event.exception && event.exception.values && event.exception.values[0];
6642
+ }
6643
+ /** JSDoc */
6644
+ function _getFramesFromEvent(event) {
6645
+ var exception = event.exception;
6646
+ if (exception) {
6804
6647
  try {
6805
- return !!(currentFingerprint.join('') === previousFingerprint.join(''));
6648
+ // @ts-ignore Object could be undefined
6649
+ return exception.values[0].stacktrace.frames;
6806
6650
  }
6807
6651
  catch (_oO) {
6808
- return false;
6652
+ return undefined;
6809
6653
  }
6810
- };
6811
- /**
6812
- * @inheritDoc
6813
- */
6814
- Dedupe.id = 'Dedupe';
6815
- return Dedupe;
6816
- }());
6654
+ }
6655
+ else if (event.stacktrace) {
6656
+ return event.stacktrace.frames;
6657
+ }
6658
+ return undefined;
6659
+ }
6817
6660
 
6818
6661
 
6819
6662
 
@@ -7040,8 +6883,10 @@ var Sentry = (function (exports) {
7040
6883
  if (client) {
7041
6884
  return client.flush(timeout);
7042
6885
  }
7043
- logger.warn('Cannot flush events. No client defined.');
7044
- return SyncPromise.resolve(false);
6886
+ if (isDebugBuild()) {
6887
+ logger.warn('Cannot flush events. No client defined.');
6888
+ }
6889
+ return resolvedSyncPromise(false);
7045
6890
  }
7046
6891
  /**
7047
6892
  * Call `close()` on the current client, if there is one. See {@link Client.close}.
@@ -7056,8 +6901,10 @@ var Sentry = (function (exports) {
7056
6901
  if (client) {
7057
6902
  return client.close(timeout);
7058
6903
  }
7059
- logger.warn('Cannot flush events and disable SDK. No client defined.');
7060
- return SyncPromise.resolve(false);
6904
+ if (isDebugBuild()) {
6905
+ logger.warn('Cannot flush events and disable SDK. No client defined.');
6906
+ }
6907
+ return resolvedSyncPromise(false);
7061
6908
  }
7062
6909
  /**
7063
6910
  * Wrap code within a try/catch block so the SDK is able to capture errors.
@@ -7070,6 +6917,10 @@ var Sentry = (function (exports) {
7070
6917
  function wrap$1(fn) {
7071
6918
  return wrap(fn)();
7072
6919
  }
6920
+ function startSessionOnHub(hub) {
6921
+ hub.startSession({ ignoreDuration: true });
6922
+ hub.captureSession();
6923
+ }
7073
6924
  /**
7074
6925
  * Enable automatic Session Tracking for the initial page load.
7075
6926
  */
@@ -7077,7 +6928,9 @@ var Sentry = (function (exports) {
7077
6928
  var window = getGlobalObject();
7078
6929
  var document = window.document;
7079
6930
  if (typeof document === 'undefined') {
7080
- logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');
6931
+ if (isDebugBuild()) {
6932
+ logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');
6933
+ }
7081
6934
  return;
7082
6935
  }
7083
6936
  var hub = getCurrentHub();
@@ -7087,27 +6940,21 @@ var Sentry = (function (exports) {
7087
6940
  // https://github.com/getsentry/sentry-javascript/issues/3207 and
7088
6941
  // https://github.com/getsentry/sentry-javascript/issues/3234 and
7089
6942
  // https://github.com/getsentry/sentry-javascript/issues/3278.
7090
- if (typeof hub.startSession !== 'function' || typeof hub.captureSession !== 'function') {
6943
+ if (!hub.captureSession) {
7091
6944
  return;
7092
6945
  }
7093
6946
  // The session duration for browser sessions does not track a meaningful
7094
6947
  // concept that can be used as a metric.
7095
6948
  // Automatically captured sessions are akin to page views, and thus we
7096
6949
  // discard their duration.
7097
- hub.startSession({ ignoreDuration: true });
7098
- hub.captureSession();
6950
+ startSessionOnHub(hub);
7099
6951
  // We want to create a session for every navigation as well
7100
- addInstrumentationHandler({
7101
- callback: function (_a) {
7102
- var from = _a.from, to = _a.to;
7103
- // Don't create an additional session for the initial route or if the location did not change
7104
- if (from === undefined || from === to) {
7105
- return;
7106
- }
7107
- hub.startSession({ ignoreDuration: true });
7108
- hub.captureSession();
7109
- },
7110
- type: 'history',
6952
+ addInstrumentationHandler('history', function (_a) {
6953
+ var from = _a.from, to = _a.to;
6954
+ // Don't create an additional session for the initial route or if the location did not change
6955
+ if (!(from === undefined || from === to)) {
6956
+ startSessionOnHub(getCurrentHub());
6957
+ }
7111
6958
  });
7112
6959
  }
7113
6960