@sentry/browser 6.16.1 → 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 +1255 -1375
  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 +1292 -1443
  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 +4 -5
  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 +5 -6
  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 +4 -5
package/build/bundle.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @sentry/browser 6.16.1 (6919d17) | 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,6 +1938,28 @@ var Sentry = (function (exports) {
2031
1938
  }
2032
1939
 
2033
1940
  /* eslint-disable @typescript-eslint/explicit-function-return-type */
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
+ }
2034
1963
  /**
2035
1964
  * Thenable class that behaves like a Promise and follows it's interface
2036
1965
  * but is not async internally
@@ -2038,19 +1967,19 @@ var Sentry = (function (exports) {
2038
1967
  var SyncPromise = /** @class */ (function () {
2039
1968
  function SyncPromise(executor) {
2040
1969
  var _this = this;
2041
- this._state = "PENDING" /* PENDING */;
1970
+ this._state = 0 /* PENDING */;
2042
1971
  this._handlers = [];
2043
1972
  /** JSDoc */
2044
1973
  this._resolve = function (value) {
2045
- _this._setResult("RESOLVED" /* RESOLVED */, value);
1974
+ _this._setResult(1 /* RESOLVED */, value);
2046
1975
  };
2047
1976
  /** JSDoc */
2048
1977
  this._reject = function (reason) {
2049
- _this._setResult("REJECTED" /* REJECTED */, reason);
1978
+ _this._setResult(2 /* REJECTED */, reason);
2050
1979
  };
2051
1980
  /** JSDoc */
2052
1981
  this._setResult = function (state, value) {
2053
- if (_this._state !== "PENDING" /* PENDING */) {
1982
+ if (_this._state !== 0 /* PENDING */) {
2054
1983
  return;
2055
1984
  }
2056
1985
  if (isThenable(value)) {
@@ -2061,35 +1990,25 @@ var Sentry = (function (exports) {
2061
1990
  _this._value = value;
2062
1991
  _this._executeHandlers();
2063
1992
  };
2064
- // TODO: FIXME
2065
- /** JSDoc */
2066
- this._attachHandler = function (handler) {
2067
- _this._handlers = _this._handlers.concat(handler);
2068
- _this._executeHandlers();
2069
- };
2070
1993
  /** JSDoc */
2071
1994
  this._executeHandlers = function () {
2072
- if (_this._state === "PENDING" /* PENDING */) {
1995
+ if (_this._state === 0 /* PENDING */) {
2073
1996
  return;
2074
1997
  }
2075
1998
  var cachedHandlers = _this._handlers.slice();
2076
1999
  _this._handlers = [];
2077
2000
  cachedHandlers.forEach(function (handler) {
2078
- if (handler.done) {
2001
+ if (handler[0]) {
2079
2002
  return;
2080
2003
  }
2081
- if (_this._state === "RESOLVED" /* RESOLVED */) {
2082
- if (handler.onfulfilled) {
2083
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
2084
- handler.onfulfilled(_this._value);
2085
- }
2004
+ if (_this._state === 1 /* RESOLVED */) {
2005
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
2006
+ handler[1](_this._value);
2086
2007
  }
2087
- if (_this._state === "REJECTED" /* REJECTED */) {
2088
- if (handler.onrejected) {
2089
- handler.onrejected(_this._value);
2090
- }
2008
+ if (_this._state === 2 /* REJECTED */) {
2009
+ handler[2](_this._value);
2091
2010
  }
2092
- handler.done = true;
2011
+ handler[0] = true;
2093
2012
  });
2094
2013
  };
2095
2014
  try {
@@ -2100,81 +2019,41 @@ var Sentry = (function (exports) {
2100
2019
  }
2101
2020
  }
2102
2021
  /** JSDoc */
2103
- SyncPromise.resolve = function (value) {
2104
- return new SyncPromise(function (resolve) {
2105
- resolve(value);
2106
- });
2107
- };
2108
- /** JSDoc */
2109
- SyncPromise.reject = function (reason) {
2110
- return new SyncPromise(function (_, reject) {
2111
- reject(reason);
2112
- });
2113
- };
2114
- /** JSDoc */
2115
- SyncPromise.all = function (collection) {
2116
- return new SyncPromise(function (resolve, reject) {
2117
- if (!Array.isArray(collection)) {
2118
- reject(new TypeError("Promise.all requires an array as input."));
2119
- return;
2120
- }
2121
- if (collection.length === 0) {
2122
- resolve([]);
2123
- return;
2124
- }
2125
- var counter = collection.length;
2126
- var resolvedCollection = [];
2127
- collection.forEach(function (item, index) {
2128
- void SyncPromise.resolve(item)
2129
- .then(function (value) {
2130
- resolvedCollection[index] = value;
2131
- counter -= 1;
2132
- if (counter !== 0) {
2133
- return;
2134
- }
2135
- resolve(resolvedCollection);
2136
- })
2137
- .then(null, reject);
2138
- });
2139
- });
2140
- };
2141
- /** JSDoc */
2142
2022
  SyncPromise.prototype.then = function (onfulfilled, onrejected) {
2143
2023
  var _this = this;
2144
2024
  return new SyncPromise(function (resolve, reject) {
2145
- _this._attachHandler({
2146
- done: false,
2147
- onfulfilled: function (result) {
2025
+ _this._handlers.push([
2026
+ false,
2027
+ function (result) {
2148
2028
  if (!onfulfilled) {
2149
2029
  // TODO: ¯\_(ツ)_/¯
2150
2030
  // TODO: FIXME
2151
2031
  resolve(result);
2152
- return;
2153
- }
2154
- try {
2155
- resolve(onfulfilled(result));
2156
- return;
2157
2032
  }
2158
- catch (e) {
2159
- reject(e);
2160
- return;
2033
+ else {
2034
+ try {
2035
+ resolve(onfulfilled(result));
2036
+ }
2037
+ catch (e) {
2038
+ reject(e);
2039
+ }
2161
2040
  }
2162
2041
  },
2163
- onrejected: function (reason) {
2042
+ function (reason) {
2164
2043
  if (!onrejected) {
2165
2044
  reject(reason);
2166
- return;
2167
2045
  }
2168
- try {
2169
- resolve(onrejected(reason));
2170
- return;
2171
- }
2172
- catch (e) {
2173
- reject(e);
2174
- return;
2046
+ else {
2047
+ try {
2048
+ resolve(onrejected(reason));
2049
+ }
2050
+ catch (e) {
2051
+ reject(e);
2052
+ }
2175
2053
  }
2176
2054
  },
2177
- });
2055
+ ]);
2056
+ _this._executeHandlers();
2178
2057
  });
2179
2058
  };
2180
2059
  /** JSDoc */
@@ -2208,26 +2087,27 @@ var Sentry = (function (exports) {
2208
2087
  });
2209
2088
  });
2210
2089
  };
2211
- /** JSDoc */
2212
- SyncPromise.prototype.toString = function () {
2213
- return '[object SyncPromise]';
2214
- };
2215
2090
  return SyncPromise;
2216
2091
  }());
2217
2092
 
2218
- /** A simple queue that holds promises. */
2219
- var PromiseBuffer = /** @class */ (function () {
2220
- function PromiseBuffer(_limit) {
2221
- this._limit = _limit;
2222
- /** Internal set of queued Promises */
2223
- 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;
2224
2101
  }
2225
2102
  /**
2226
- * 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.
2227
2107
  */
2228
- PromiseBuffer.prototype.isReady = function () {
2229
- return this._limit === undefined || this.length() < this._limit;
2230
- };
2108
+ function remove(task) {
2109
+ return buffer.splice(buffer.indexOf(task), 1)[0];
2110
+ }
2231
2111
  /**
2232
2112
  * Add a promise (representing an in-flight action) to the queue, and set it to remove itself on fulfillment.
2233
2113
  *
@@ -2238,44 +2118,27 @@ var Sentry = (function (exports) {
2238
2118
  * limit check.
2239
2119
  * @returns The original promise.
2240
2120
  */
2241
- PromiseBuffer.prototype.add = function (taskProducer) {
2242
- var _this = this;
2243
- if (!this.isReady()) {
2244
- 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.'));
2245
2124
  }
2246
2125
  // start the task and add its promise to the queue
2247
2126
  var task = taskProducer();
2248
- if (this._buffer.indexOf(task) === -1) {
2249
- this._buffer.push(task);
2127
+ if (buffer.indexOf(task) === -1) {
2128
+ buffer.push(task);
2250
2129
  }
2251
2130
  void task
2252
- .then(function () { return _this.remove(task); })
2131
+ .then(function () { return remove(task); })
2253
2132
  // Use `then(null, rejectionHandler)` rather than `catch(rejectionHandler)` so that we can use `PromiseLike`
2254
2133
  // rather than `Promise`. `PromiseLike` doesn't have a `.catch` method, making its polyfill smaller. (ES5 didn't
2255
2134
  // have promises, so TS has to polyfill when down-compiling.)
2256
2135
  .then(null, function () {
2257
- return _this.remove(task).then(null, function () {
2258
- // 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.
2259
2138
  });
2260
2139
  });
2261
2140
  return task;
2262
- };
2263
- /**
2264
- * Remove a promise from the queue.
2265
- *
2266
- * @param task Can be any PromiseLike<T>
2267
- * @returns Removed promise.
2268
- */
2269
- PromiseBuffer.prototype.remove = function (task) {
2270
- var removedTask = this._buffer.splice(this._buffer.indexOf(task), 1)[0];
2271
- return removedTask;
2272
- };
2273
- /**
2274
- * This function returns the number of unresolved promises in the queue.
2275
- */
2276
- PromiseBuffer.prototype.length = function () {
2277
- return this._buffer.length;
2278
- };
2141
+ }
2279
2142
  /**
2280
2143
  * Wait for all promises in the queue to resolve or for timeout to expire, whichever comes first.
2281
2144
  *
@@ -2285,9 +2148,12 @@ var Sentry = (function (exports) {
2285
2148
  * @returns A promise which will resolve to `true` if the queue is already empty or drains before the timeout, and
2286
2149
  * `false` otherwise
2287
2150
  */
2288
- PromiseBuffer.prototype.drain = function (timeout) {
2289
- var _this = this;
2290
- 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
+ }
2291
2157
  // wait for `timeout` ms and then resolve to `false` (if not cancelled first)
2292
2158
  var capturedSetTimeout = setTimeout(function () {
2293
2159
  if (timeout && timeout > 0) {
@@ -2295,18 +2161,85 @@ var Sentry = (function (exports) {
2295
2161
  }
2296
2162
  }, timeout);
2297
2163
  // if all promises resolve in time, cancel the timer and resolve to `true`
2298
- void SyncPromise.all(_this._buffer)
2299
- .then(function () {
2300
- clearTimeout(capturedSetTimeout);
2301
- resolve(true);
2302
- })
2303
- .then(null, function () {
2304
- 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);
2305
2172
  });
2306
2173
  });
2174
+ }
2175
+ return {
2176
+ $: buffer,
2177
+ add: add,
2178
+ drain: drain,
2307
2179
  };
2308
- return PromiseBuffer;
2309
- }());
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
+ }
2310
2243
 
2311
2244
  /**
2312
2245
  * A TimestampSource implementation for environments that do not support the Performance Web API natively.
@@ -2629,15 +2562,14 @@ var Sentry = (function (exports) {
2629
2562
  * @inheritDoc
2630
2563
  */
2631
2564
  Scope.prototype.getTransaction = function () {
2632
- var _a, _b, _c, _d;
2633
2565
  // often, this span will be a transaction, but it's not guaranteed to be
2634
2566
  var span = this.getSpan();
2635
2567
  // try it the new way first
2636
- if ((_a = span) === null || _a === void 0 ? void 0 : _a.transaction) {
2637
- return (_b = span) === null || _b === void 0 ? void 0 : _b.transaction;
2568
+ if (span && span.transaction) {
2569
+ return span.transaction;
2638
2570
  }
2639
2571
  // fallback to the old way (known bug: this only finds transactions with sampled = true)
2640
- 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]) {
2641
2573
  return span.spanRecorder.spans[0];
2642
2574
  }
2643
2575
  // neither way found a transaction
@@ -2760,7 +2692,6 @@ var Sentry = (function (exports) {
2760
2692
  * @hidden
2761
2693
  */
2762
2694
  Scope.prototype.applyToEvent = function (event, hint) {
2763
- var _a;
2764
2695
  if (this._extra && Object.keys(this._extra).length) {
2765
2696
  event.extra = __assign(__assign({}, this._extra), event.extra);
2766
2697
  }
@@ -2784,7 +2715,7 @@ var Sentry = (function (exports) {
2784
2715
  // errors with transaction and it relies on that.
2785
2716
  if (this._span) {
2786
2717
  event.contexts = __assign({ trace: this._span.getTraceContext() }, event.contexts);
2787
- var transactionName = (_a = this._span.transaction) === null || _a === void 0 ? void 0 : _a.name;
2718
+ var transactionName = this._span.transaction && this._span.transaction.name;
2788
2719
  if (transactionName) {
2789
2720
  event.tags = __assign({ transaction: transactionName }, event.tags);
2790
2721
  }
@@ -2885,7 +2816,7 @@ var Sentry = (function (exports) {
2885
2816
  this.errors = 0;
2886
2817
  this.sid = uuid4();
2887
2818
  this.duration = 0;
2888
- this.status = SessionStatus.Ok;
2819
+ this.status = 'ok';
2889
2820
  this.init = true;
2890
2821
  this.ignoreDuration = false;
2891
2822
  // Both timestamp and started are in seconds since the UNIX epoch.
@@ -2959,8 +2890,8 @@ var Sentry = (function (exports) {
2959
2890
  if (status) {
2960
2891
  this.update({ status: status });
2961
2892
  }
2962
- else if (this.status === SessionStatus.Ok) {
2963
- this.update({ status: SessionStatus.Exited });
2893
+ else if (this.status === 'ok') {
2894
+ this.update({ status: 'exited' });
2964
2895
  }
2965
2896
  else {
2966
2897
  this.update();
@@ -2978,12 +2909,12 @@ var Sentry = (function (exports) {
2978
2909
  errors: this.errors,
2979
2910
  did: typeof this.did === 'number' || typeof this.did === 'string' ? "" + this.did : undefined,
2980
2911
  duration: this.duration,
2981
- attrs: dropUndefinedKeys({
2912
+ attrs: {
2982
2913
  release: this.release,
2983
2914
  environment: this.environment,
2984
2915
  ip_address: this.ipAddress,
2985
2916
  user_agent: this.userAgent,
2986
- }),
2917
+ },
2987
2918
  });
2988
2919
  };
2989
2920
  return Session;
@@ -3301,11 +3232,17 @@ var Sentry = (function (exports) {
3301
3232
  * @inheritDoc
3302
3233
  */
3303
3234
  Hub.prototype.endSession = function () {
3304
- var _a, _b, _c, _d, _e;
3305
- (_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
+ }
3306
3241
  this._sendSessionUpdate();
3307
3242
  // the session is over; take it off of the scope
3308
- (_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
+ }
3309
3246
  };
3310
3247
  /**
3311
3248
  * @inheritDoc
@@ -3321,8 +3258,8 @@ var Sentry = (function (exports) {
3321
3258
  if (scope) {
3322
3259
  // End existing session if there's one
3323
3260
  var currentSession = scope.getSession && scope.getSession();
3324
- if (currentSession && currentSession.status === SessionStatus.Ok) {
3325
- currentSession.update({ status: SessionStatus.Exited });
3261
+ if (currentSession && currentSession.status === 'ok') {
3262
+ currentSession.update({ status: 'exited' });
3326
3263
  }
3327
3264
  this.endSession();
3328
3265
  // Afterwards we set the new session on the scope
@@ -3434,9 +3371,9 @@ var Sentry = (function (exports) {
3434
3371
  * @returns discovered hub
3435
3372
  */
3436
3373
  function getHubFromActiveDomain(registry) {
3437
- var _a, _b, _c;
3438
3374
  try {
3439
- 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;
3440
3377
  // If there's no active domain, just return global hub
3441
3378
  if (!activeDomain) {
3442
3379
  return getHubFromCarrier(registry);
@@ -3531,7 +3468,7 @@ var Sentry = (function (exports) {
3531
3468
  * Captures a message event and sends it to Sentry.
3532
3469
  *
3533
3470
  * @param message The message to send to Sentry.
3534
- * @param level Define the level of the message.
3471
+ * @param SeverityLevel Define the level of the message.
3535
3472
  * @returns The generated eventId.
3536
3473
  */
3537
3474
  function captureMessage(message, captureContext) {
@@ -3663,138 +3600,84 @@ var Sentry = (function (exports) {
3663
3600
  }
3664
3601
 
3665
3602
  var SENTRY_API_VERSION = '7';
3666
- /**
3667
- * Helper class to provide urls, headers and metadata that can be used to form
3668
- * different types of requests to Sentry endpoints.
3669
- * Supports both envelopes and regular event requests.
3670
- **/
3671
- var API = /** @class */ (function () {
3672
- /** Create a new instance of API */
3673
- function API(dsn, metadata, tunnel) {
3674
- if (metadata === void 0) { metadata = {}; }
3675
- this.dsn = dsn;
3676
- this._dsnObject = new Dsn(dsn);
3677
- this.metadata = metadata;
3678
- this._tunnel = tunnel;
3679
- }
3680
- /** Returns the Dsn object. */
3681
- API.prototype.getDsn = function () {
3682
- return this._dsnObject;
3683
- };
3684
- /** Does this transport force envelopes? */
3685
- API.prototype.forceEnvelope = function () {
3686
- return !!this._tunnel;
3687
- };
3688
- /** Returns the prefix to construct Sentry ingestion API endpoints. */
3689
- API.prototype.getBaseApiEndpoint = function () {
3690
- var dsn = this.getDsn();
3691
- var protocol = dsn.protocol ? dsn.protocol + ":" : '';
3692
- var port = dsn.port ? ":" + dsn.port : '';
3693
- return protocol + "//" + dsn.host + port + (dsn.path ? "/" + dsn.path : '') + "/api/";
3694
- };
3695
- /** Returns the store endpoint URL. */
3696
- API.prototype.getStoreEndpoint = function () {
3697
- return this._getIngestEndpoint('store');
3698
- };
3699
- /**
3700
- * Returns the store endpoint URL with auth in the query string.
3701
- *
3702
- * Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
3703
- */
3704
- API.prototype.getStoreEndpointWithUrlEncodedAuth = function () {
3705
- return this.getStoreEndpoint() + "?" + this._encodedAuth();
3706
- };
3707
- /**
3708
- * Returns the envelope endpoint URL with auth in the query string.
3709
- *
3710
- * Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
3711
- */
3712
- API.prototype.getEnvelopeEndpointWithUrlEncodedAuth = function () {
3713
- if (this.forceEnvelope()) {
3714
- return this._tunnel;
3715
- }
3716
- return this._getEnvelopeEndpoint() + "?" + this._encodedAuth();
3717
- };
3718
- /** Returns only the path component for the store endpoint. */
3719
- API.prototype.getStoreEndpointPath = function () {
3720
- var dsn = this.getDsn();
3721
- 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,
3722
3610
  };
3723
- /**
3724
- * Returns an object that can be used in request headers.
3725
- * This is needed for node and the old /store endpoint in sentry
3726
- */
3727
- API.prototype.getRequestHeaders = function (clientName, clientVersion) {
3728
- // CHANGE THIS to use metadata but keep clientName and clientVersion compatible
3729
- var dsn = this.getDsn();
3730
- var header = ["Sentry sentry_version=" + SENTRY_API_VERSION];
3731
- header.push("sentry_client=" + clientName + "/" + clientVersion);
3732
- header.push("sentry_key=" + dsn.publicKey);
3733
- if (dsn.pass) {
3734
- 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;
3735
3663
  }
3736
- return {
3737
- 'Content-Type': 'application/json',
3738
- 'X-Sentry-Auth': header.join(', '),
3739
- };
3740
- };
3741
- /** Returns the url to the report dialog endpoint. */
3742
- API.prototype.getReportDialogEndpoint = function (dialogOptions) {
3743
- if (dialogOptions === void 0) { dialogOptions = {}; }
3744
- var dsn = this.getDsn();
3745
- var endpoint = this.getBaseApiEndpoint() + "embed/error-page/";
3746
- var encodedOptions = [];
3747
- encodedOptions.push("dsn=" + dsn.toString());
3748
- for (var key in dialogOptions) {
3749
- if (key === 'dsn') {
3664
+ if (key === 'user') {
3665
+ if (!dialogOptions.user) {
3750
3666
  continue;
3751
3667
  }
3752
- if (key === 'user') {
3753
- if (!dialogOptions.user) {
3754
- continue;
3755
- }
3756
- if (dialogOptions.user.name) {
3757
- encodedOptions.push("name=" + encodeURIComponent(dialogOptions.user.name));
3758
- }
3759
- if (dialogOptions.user.email) {
3760
- encodedOptions.push("email=" + encodeURIComponent(dialogOptions.user.email));
3761
- }
3668
+ if (dialogOptions.user.name) {
3669
+ encodedOptions += "&name=" + encodeURIComponent(dialogOptions.user.name);
3762
3670
  }
3763
- else {
3764
- encodedOptions.push(encodeURIComponent(key) + "=" + encodeURIComponent(dialogOptions[key]));
3671
+ if (dialogOptions.user.email) {
3672
+ encodedOptions += "&email=" + encodeURIComponent(dialogOptions.user.email);
3765
3673
  }
3766
3674
  }
3767
- if (encodedOptions.length) {
3768
- return endpoint + "?" + encodedOptions.join('&');
3769
- }
3770
- return endpoint;
3771
- };
3772
- /** Returns the envelope endpoint URL. */
3773
- API.prototype._getEnvelopeEndpoint = function () {
3774
- return this._getIngestEndpoint('envelope');
3775
- };
3776
- /** Returns the ingest API endpoint for target. */
3777
- API.prototype._getIngestEndpoint = function (target) {
3778
- if (this._tunnel) {
3779
- return this._tunnel;
3675
+ else {
3676
+ encodedOptions += "&" + encodeURIComponent(key) + "=" + encodeURIComponent(dialogOptions[key]);
3780
3677
  }
3781
- var base = this.getBaseApiEndpoint();
3782
- var dsn = this.getDsn();
3783
- return "" + base + dsn.projectId + "/" + target + "/";
3784
- };
3785
- /** Returns a URL-encoded string with auth config suitable for a query string. */
3786
- API.prototype._encodedAuth = function () {
3787
- var dsn = this.getDsn();
3788
- var auth = {
3789
- // We send only the minimum set of required information. See
3790
- // https://github.com/getsentry/sentry-javascript/issues/2572.
3791
- sentry_key: dsn.publicKey,
3792
- sentry_version: SENTRY_API_VERSION,
3793
- };
3794
- return urlEncode(auth);
3795
- };
3796
- return API;
3797
- }());
3678
+ }
3679
+ return endpoint + "?" + encodedOptions;
3680
+ }
3798
3681
 
3799
3682
  var installedIntegrations = [];
3800
3683
  /**
@@ -3855,7 +3738,7 @@ var Sentry = (function (exports) {
3855
3738
  // set the `initialized` flag so we don't run through the process again unecessarily; use `Object.defineProperty`
3856
3739
  // because by default it creates a property which is nonenumerable, which we want since `initialized` shouldn't be
3857
3740
  // considered a member of the index the way the actual integrations are
3858
- Object.defineProperty(integrations, 'initialized', { value: true });
3741
+ addNonEnumerableProperty(integrations, 'initialized', true);
3859
3742
  return integrations;
3860
3743
  }
3861
3744
 
@@ -3907,7 +3790,7 @@ var Sentry = (function (exports) {
3907
3790
  this._backend = new backendClass(options);
3908
3791
  this._options = options;
3909
3792
  if (options.dsn) {
3910
- this._dsn = new Dsn(options.dsn);
3793
+ this._dsn = makeDsn(options.dsn);
3911
3794
  }
3912
3795
  }
3913
3796
  /**
@@ -3950,9 +3833,8 @@ var Sentry = (function (exports) {
3950
3833
  * @inheritDoc
3951
3834
  */
3952
3835
  BaseClient.prototype.captureEvent = function (event, hint, scope) {
3953
- var _a;
3954
3836
  // ensure we haven't captured this very object before
3955
- if (((_a = hint) === null || _a === void 0 ? void 0 : _a.originalException) && checkOrSetAlreadyCaught(hint.originalException)) {
3837
+ if (hint && hint.originalException && checkOrSetAlreadyCaught(hint.originalException)) {
3956
3838
  logger.log(ALREADY_SEEN_ERROR);
3957
3839
  return;
3958
3840
  }
@@ -3967,11 +3849,15 @@ var Sentry = (function (exports) {
3967
3849
  */
3968
3850
  BaseClient.prototype.captureSession = function (session) {
3969
3851
  if (!this._isEnabled()) {
3970
- logger.warn('SDK not enabled, will not capture session.');
3852
+ if (isDebugBuild()) {
3853
+ logger.warn('SDK not enabled, will not capture session.');
3854
+ }
3971
3855
  return;
3972
3856
  }
3973
3857
  if (!(typeof session.release === 'string')) {
3974
- 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
+ }
3975
3861
  }
3976
3862
  else {
3977
3863
  this._sendSession(session);
@@ -4067,10 +3953,10 @@ var Sentry = (function (exports) {
4067
3953
  // A session is updated and that session update is sent in only one of the two following scenarios:
4068
3954
  // 1. Session with non terminal status and 0 errors + an error occurred -> Will set error count to 1 and send update
4069
3955
  // 2. Session with non terminal status and 1 error + a crash occurred -> Will set status crashed and send update
4070
- var sessionNonTerminal = session.status === SessionStatus.Ok;
3956
+ var sessionNonTerminal = session.status === 'ok';
4071
3957
  var shouldUpdateAndSend = (sessionNonTerminal && session.errors === 0) || (sessionNonTerminal && crashed);
4072
3958
  if (shouldUpdateAndSend) {
4073
- 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) }));
4074
3960
  this.captureSession(session);
4075
3961
  }
4076
3962
  };
@@ -4143,7 +4029,7 @@ var Sentry = (function (exports) {
4143
4029
  finalScope = Scope.clone(finalScope).update(hint.captureContext);
4144
4030
  }
4145
4031
  // We prepare the result here with a resolved Event.
4146
- var result = SyncPromise.resolve(prepared);
4032
+ var result = resolvedSyncPromise(prepared);
4147
4033
  // This should be the last thing called, since we want that
4148
4034
  // {@link Hub.addEventProcessor} gets the finished prepared event.
4149
4035
  if (finalScope) {
@@ -4276,26 +4162,29 @@ var Sentry = (function (exports) {
4276
4162
  */
4277
4163
  BaseClient.prototype._processEvent = function (event, hint, scope) {
4278
4164
  var _this = this;
4279
- var _a, _b;
4280
4165
  // eslint-disable-next-line @typescript-eslint/unbound-method
4281
- var _c = this.getOptions(), beforeSend = _c.beforeSend, sampleRate = _c.sampleRate;
4166
+ var _a = this.getOptions(), beforeSend = _a.beforeSend, sampleRate = _a.sampleRate;
4282
4167
  var transport = this.getTransport();
4168
+ function recordLostEvent(outcome, category) {
4169
+ if (transport.recordLostEvent) {
4170
+ transport.recordLostEvent(outcome, category);
4171
+ }
4172
+ }
4283
4173
  if (!this._isEnabled()) {
4284
- return SyncPromise.reject(new SentryError('SDK not enabled, will not capture event.'));
4174
+ return rejectedSyncPromise(new SentryError('SDK not enabled, will not capture event.'));
4285
4175
  }
4286
4176
  var isTransaction = event.type === 'transaction';
4287
4177
  // 1.0 === 100% events are sent
4288
4178
  // 0.0 === 0% events are sent
4289
4179
  // Sampling for transaction happens somewhere else
4290
4180
  if (!isTransaction && typeof sampleRate === 'number' && Math.random() > sampleRate) {
4291
- (_b = (_a = transport).recordLostEvent) === null || _b === void 0 ? void 0 : _b.call(_a, Outcome.SampleRate, 'event');
4292
- 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 + ")"));
4293
4183
  }
4294
4184
  return this._prepareEvent(event, scope, hint)
4295
4185
  .then(function (prepared) {
4296
- var _a, _b;
4297
4186
  if (prepared === null) {
4298
- (_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');
4299
4188
  throw new SentryError('An event processor returned null, will not send event.');
4300
4189
  }
4301
4190
  var isInternalException = hint && hint.data && hint.data.__sentry__ === true;
@@ -4303,12 +4192,11 @@ var Sentry = (function (exports) {
4303
4192
  return prepared;
4304
4193
  }
4305
4194
  var beforeSendResult = beforeSend(prepared, hint);
4306
- return _this._ensureBeforeSendRv(beforeSendResult);
4195
+ return _ensureBeforeSendRv(beforeSendResult);
4307
4196
  })
4308
4197
  .then(function (processedEvent) {
4309
- var _a, _b;
4310
4198
  if (processedEvent === null) {
4311
- (_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');
4312
4200
  throw new SentryError('`beforeSend` returned `null`, will not send event.');
4313
4201
  }
4314
4202
  var session = scope && scope.getSession && scope.getSession();
@@ -4345,28 +4233,28 @@ var Sentry = (function (exports) {
4345
4233
  return reason;
4346
4234
  });
4347
4235
  };
4348
- /**
4349
- * Verifies that return value of configured `beforeSend` is of expected type.
4350
- */
4351
- BaseClient.prototype._ensureBeforeSendRv = function (rv) {
4352
- var nullErr = '`beforeSend` method has to return `null` or a valid event.';
4353
- if (isThenable(rv)) {
4354
- return rv.then(function (event) {
4355
- if (!(isPlainObject(event) || event === null)) {
4356
- throw new SentryError(nullErr);
4357
- }
4358
- return event;
4359
- }, function (e) {
4360
- throw new SentryError("beforeSend rejected with " + e);
4361
- });
4362
- }
4363
- else if (!(isPlainObject(rv) || rv === null)) {
4364
- throw new SentryError(nullErr);
4365
- }
4366
- return rv;
4367
- };
4368
4236
  return BaseClient;
4369
- }());
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
+ }
4370
4258
 
4371
4259
  /** Noop transport */
4372
4260
  var NoopTransport = /** @class */ (function () {
@@ -4376,16 +4264,16 @@ var Sentry = (function (exports) {
4376
4264
  * @inheritDoc
4377
4265
  */
4378
4266
  NoopTransport.prototype.sendEvent = function (_) {
4379
- return SyncPromise.resolve({
4267
+ return resolvedSyncPromise({
4380
4268
  reason: "NoopTransport: Event has been skipped because no Dsn is configured.",
4381
- status: exports.Status.Skipped,
4269
+ status: 'skipped',
4382
4270
  });
4383
4271
  };
4384
4272
  /**
4385
4273
  * @inheritDoc
4386
4274
  */
4387
4275
  NoopTransport.prototype.close = function (_) {
4388
- return SyncPromise.resolve(true);
4276
+ return resolvedSyncPromise(true);
4389
4277
  };
4390
4278
  return NoopTransport;
4391
4279
  }());
@@ -4421,7 +4309,9 @@ var Sentry = (function (exports) {
4421
4309
  */
4422
4310
  BaseBackend.prototype.sendEvent = function (event) {
4423
4311
  void this._transport.sendEvent(event).then(null, function (reason) {
4424
- logger.error("Error while sending event: " + reason);
4312
+ if (isDebugBuild()) {
4313
+ logger.error("Error while sending event: " + reason);
4314
+ }
4425
4315
  });
4426
4316
  };
4427
4317
  /**
@@ -4429,11 +4319,15 @@ var Sentry = (function (exports) {
4429
4319
  */
4430
4320
  BaseBackend.prototype.sendSession = function (session) {
4431
4321
  if (!this._transport.sendSession) {
4432
- 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
+ }
4433
4325
  return;
4434
4326
  }
4435
4327
  void this._transport.sendSession(session).then(null, function (reason) {
4436
- logger.error("Error while sending session: " + reason);
4328
+ if (isDebugBuild()) {
4329
+ logger.error("Error while sending session: " + reason);
4330
+ }
4437
4331
  });
4438
4332
  };
4439
4333
  /**
@@ -4477,7 +4371,7 @@ var Sentry = (function (exports) {
4477
4371
  /** Creates a SentryRequest from a Session. */
4478
4372
  function sessionToSentryRequest(session, api) {
4479
4373
  var sdkInfo = getSdkMetadataForEnvelopeHeader(api);
4480
- 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) })));
4481
4375
  // I know this is hacky but we don't want to add `session` to request type since it's never rate limited
4482
4376
  var type = 'aggregates' in session ? 'sessions' : 'session';
4483
4377
  var itemHeaders = JSON.stringify({
@@ -4486,14 +4380,14 @@ var Sentry = (function (exports) {
4486
4380
  return {
4487
4381
  body: envelopeHeaders + "\n" + itemHeaders + "\n" + JSON.stringify(session),
4488
4382
  type: type,
4489
- url: api.getEnvelopeEndpointWithUrlEncodedAuth(),
4383
+ url: getEnvelopeEndpointWithUrlEncodedAuth(api.dsn, api.tunnel),
4490
4384
  };
4491
4385
  }
4492
4386
  /** Creates a SentryRequest from an event. */
4493
4387
  function eventToSentryRequest(event, api) {
4494
4388
  var sdkInfo = getSdkMetadataForEnvelopeHeader(api);
4495
4389
  var eventType = event.type || 'event';
4496
- var useEnvelope = eventType === 'transaction' || api.forceEnvelope();
4390
+ var useEnvelope = eventType === 'transaction' || !!api.tunnel;
4497
4391
  var _a = event.debug_meta || {}, transactionSampling = _a.transactionSampling, metadata = __rest(_a, ["transactionSampling"]);
4498
4392
  var _b = transactionSampling || {}, samplingMethod = _b.method, sampleRate = _b.rate;
4499
4393
  if (Object.keys(metadata).length === 0) {
@@ -4505,7 +4399,9 @@ var Sentry = (function (exports) {
4505
4399
  var req = {
4506
4400
  body: JSON.stringify(sdkInfo ? enhanceEventWithSdkInfo(event, api.metadata.sdk) : event),
4507
4401
  type: eventType,
4508
- url: useEnvelope ? api.getEnvelopeEndpointWithUrlEncodedAuth() : api.getStoreEndpointWithUrlEncodedAuth(),
4402
+ url: useEnvelope
4403
+ ? getEnvelopeEndpointWithUrlEncodedAuth(api.dsn, api.tunnel)
4404
+ : getStoreEndpointWithUrlEncodedAuth(api.dsn),
4509
4405
  };
4510
4406
  // https://develop.sentry.dev/sdk/envelopes/
4511
4407
  // Since we don't need to manipulate envelopes nor store them, there is no
@@ -4513,7 +4409,7 @@ var Sentry = (function (exports) {
4513
4409
  // deserialization. Instead, we only implement a minimal subset of the spec to
4514
4410
  // serialize events inline here.
4515
4411
  if (useEnvelope) {
4516
- 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) })));
4517
4413
  var itemHeaders = JSON.stringify({
4518
4414
  type: eventType,
4519
4415
  // TODO: Right now, sampleRate may or may not be defined (it won't be in the cases of inheritance and
@@ -4538,17 +4434,19 @@ var Sentry = (function (exports) {
4538
4434
  * @param options Options to pass to the client.
4539
4435
  */
4540
4436
  function initAndBind(clientClass, options) {
4541
- var _a;
4542
4437
  if (options.debug === true) {
4543
4438
  logger.enable();
4544
4439
  }
4545
4440
  var hub = getCurrentHub();
4546
- (_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
+ }
4547
4445
  var client = new clientClass(options);
4548
4446
  hub.bindClient(client);
4549
4447
  }
4550
4448
 
4551
- var SDK_VERSION = '6.16.1';
4449
+ var SDK_VERSION = '6.17.0-beta.0';
4552
4450
 
4553
4451
  var originalFunctionToString;
4554
4452
  /** Patch toString calls to return proper name for wrapped functions */
@@ -4571,7 +4469,7 @@ var Sentry = (function (exports) {
4571
4469
  for (var _i = 0; _i < arguments.length; _i++) {
4572
4470
  args[_i] = arguments[_i];
4573
4471
  }
4574
- var context = this.__sentry_original__ || this;
4472
+ var context = getOriginalFunction(this) || this;
4575
4473
  return originalFunctionToString.apply(context, args);
4576
4474
  };
4577
4475
  };
@@ -4625,19 +4523,27 @@ var Sentry = (function (exports) {
4625
4523
  /** JSDoc */
4626
4524
  InboundFilters.prototype._shouldDropEvent = function (event, options) {
4627
4525
  if (this._isSentryError(event, options)) {
4628
- 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
+ }
4629
4529
  return true;
4630
4530
  }
4631
4531
  if (this._isIgnoredError(event, options)) {
4632
- 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
+ }
4633
4535
  return true;
4634
4536
  }
4635
4537
  if (this._isDeniedUrl(event, options)) {
4636
- 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
+ }
4637
4541
  return true;
4638
4542
  }
4639
4543
  if (!this._isAllowedUrl(event, options)) {
4640
- 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
+ }
4641
4547
  return true;
4642
4548
  }
4643
4549
  return false;
@@ -4648,16 +4554,14 @@ var Sentry = (function (exports) {
4648
4554
  return false;
4649
4555
  }
4650
4556
  try {
4651
- return ((event &&
4652
- event.exception &&
4653
- event.exception.values &&
4654
- event.exception.values[0] &&
4655
- event.exception.values[0].type === 'SentryError') ||
4656
- 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';
4657
4560
  }
4658
- catch (_oO) {
4659
- return false;
4561
+ catch (e) {
4562
+ // ignore
4660
4563
  }
4564
+ return false;
4661
4565
  };
4662
4566
  /** JSDoc */
4663
4567
  InboundFilters.prototype._isIgnoredError = function (event, options) {
@@ -4708,7 +4612,9 @@ var Sentry = (function (exports) {
4708
4612
  return ["" + value, type + ": " + value];
4709
4613
  }
4710
4614
  catch (oO) {
4711
- logger.error("Cannot extract message for event " + getEventDescription(event));
4615
+ if (isDebugBuild()) {
4616
+ logger.error("Cannot extract message for event " + getEventDescription(event));
4617
+ }
4712
4618
  return [];
4713
4619
  }
4714
4620
  }
@@ -4717,10 +4623,9 @@ var Sentry = (function (exports) {
4717
4623
  /** JSDoc */
4718
4624
  InboundFilters.prototype._getLastValidUrl = function (frames) {
4719
4625
  if (frames === void 0) { frames = []; }
4720
- var _a, _b;
4721
4626
  for (var i = frames.length - 1; i >= 0; i--) {
4722
4627
  var frame = frames[i];
4723
- 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]') {
4724
4629
  return frame.filename || null;
4725
4630
  }
4726
4631
  }
@@ -4730,17 +4635,22 @@ var Sentry = (function (exports) {
4730
4635
  InboundFilters.prototype._getEventFilterUrl = function (event) {
4731
4636
  try {
4732
4637
  if (event.stacktrace) {
4733
- var frames_1 = event.stacktrace.frames;
4734
- return this._getLastValidUrl(frames_1);
4638
+ return this._getLastValidUrl(event.stacktrace.frames);
4735
4639
  }
4736
- if (event.exception) {
4737
- var frames_2 = event.exception.values && event.exception.values[0].stacktrace && event.exception.values[0].stacktrace.frames;
4738
- 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;
4739
4644
  }
4740
- return null;
4645
+ catch (e) {
4646
+ // ignore
4647
+ }
4648
+ return frames_1 ? this._getLastValidUrl(frames_1) : null;
4741
4649
  }
4742
4650
  catch (oO) {
4743
- logger.error("Cannot extract url for event " + getEventDescription(event));
4651
+ if (isDebugBuild()) {
4652
+ logger.error("Cannot extract url for event " + getEventDescription(event));
4653
+ }
4744
4654
  return null;
4745
4655
  }
4746
4656
  };
@@ -5113,18 +5023,18 @@ var Sentry = (function (exports) {
5113
5023
  attachStacktrace: options.attachStacktrace,
5114
5024
  });
5115
5025
  addExceptionMechanism(event); // defaults to { type: 'generic', handled: true }
5116
- event.level = exports.Severity.Error;
5026
+ event.level = 'error';
5117
5027
  if (hint && hint.event_id) {
5118
5028
  event.event_id = hint.event_id;
5119
5029
  }
5120
- return SyncPromise.resolve(event);
5030
+ return resolvedSyncPromise(event);
5121
5031
  }
5122
5032
  /**
5123
5033
  * Builds and Event from a Message
5124
5034
  * @hidden
5125
5035
  */
5126
5036
  function eventFromMessage(options, message, level, hint) {
5127
- if (level === void 0) { level = exports.Severity.Info; }
5037
+ if (level === void 0) { level = 'info'; }
5128
5038
  var syntheticException = (hint && hint.syntheticException) || undefined;
5129
5039
  var event = eventFromString(message, syntheticException, {
5130
5040
  attachStacktrace: options.attachStacktrace,
@@ -5133,7 +5043,7 @@ var Sentry = (function (exports) {
5133
5043
  if (hint && hint.event_id) {
5134
5044
  event.event_id = hint.event_id;
5135
5045
  }
5136
- return SyncPromise.resolve(event);
5046
+ return resolvedSyncPromise(event);
5137
5047
  }
5138
5048
  /**
5139
5049
  * @hidden
@@ -5263,7 +5173,6 @@ var Sentry = (function (exports) {
5263
5173
  * Safari: resource blocked by content blocker
5264
5174
  */
5265
5175
  function getNativeFetchImplementation() {
5266
- var _a, _b;
5267
5176
  if (cachedFetchImpl) {
5268
5177
  return cachedFetchImpl;
5269
5178
  }
@@ -5275,18 +5184,21 @@ var Sentry = (function (exports) {
5275
5184
  var document = global$3.document;
5276
5185
  var fetchImpl = global$3.fetch;
5277
5186
  // eslint-disable-next-line deprecation/deprecation
5278
- if (typeof ((_a = document) === null || _a === void 0 ? void 0 : _a.createElement) === "function") {
5187
+ if (document && typeof document.createElement === "function") {
5279
5188
  try {
5280
5189
  var sandbox = document.createElement('iframe');
5281
5190
  sandbox.hidden = true;
5282
5191
  document.head.appendChild(sandbox);
5283
- if ((_b = sandbox.contentWindow) === null || _b === void 0 ? void 0 : _b.fetch) {
5284
- fetchImpl = sandbox.contentWindow.fetch;
5192
+ var contentWindow = sandbox.contentWindow;
5193
+ if (contentWindow && contentWindow.fetch) {
5194
+ fetchImpl = contentWindow.fetch;
5285
5195
  }
5286
5196
  document.head.removeChild(sandbox);
5287
5197
  }
5288
5198
  catch (e) {
5289
- 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
+ }
5290
5202
  }
5291
5203
  }
5292
5204
  return (cachedFetchImpl = fetchImpl.bind(global$3));
@@ -5317,12 +5229,10 @@ var Sentry = (function (exports) {
5317
5229
  }
5318
5230
  }
5319
5231
 
5320
- var CATEGORY_MAPPING = {
5321
- event: 'error',
5322
- transaction: 'transaction',
5323
- session: 'session',
5324
- attachment: 'attachment',
5325
- };
5232
+ function requestTypeToCategory(ty) {
5233
+ var tyStr = ty;
5234
+ return tyStr === 'event' ? 'error' : tyStr;
5235
+ }
5326
5236
  var global$4 = getGlobalObject();
5327
5237
  /** Base Transport class implementation */
5328
5238
  var BaseTransport = /** @class */ (function () {
@@ -5330,13 +5240,13 @@ var Sentry = (function (exports) {
5330
5240
  var _this = this;
5331
5241
  this.options = options;
5332
5242
  /** A simple buffer holding all requests. */
5333
- this._buffer = new PromiseBuffer(30);
5243
+ this._buffer = makePromiseBuffer(30);
5334
5244
  /** Locks transport after receiving rate limits in a response */
5335
5245
  this._rateLimits = {};
5336
5246
  this._outcomes = {};
5337
- this._api = new API(options.dsn, options._metadata, options.tunnel);
5247
+ this._api = initAPIDetails(options.dsn, options._metadata, options.tunnel);
5338
5248
  // eslint-disable-next-line deprecation/deprecation
5339
- this.url = this._api.getStoreEndpointWithUrlEncodedAuth();
5249
+ this.url = getStoreEndpointWithUrlEncodedAuth(this._api.dsn);
5340
5250
  if (this.options.sendClientReports && global$4.document) {
5341
5251
  global$4.document.addEventListener('visibilitychange', function () {
5342
5252
  if (global$4.document.visibilityState === 'hidden') {
@@ -5348,8 +5258,14 @@ var Sentry = (function (exports) {
5348
5258
  /**
5349
5259
  * @inheritDoc
5350
5260
  */
5351
- BaseTransport.prototype.sendEvent = function (_) {
5352
- 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);
5353
5269
  };
5354
5270
  /**
5355
5271
  * @inheritDoc
@@ -5370,7 +5286,7 @@ var Sentry = (function (exports) {
5370
5286
  // We could use nested maps, but it's much easier to read and type this way.
5371
5287
  // A correct type for map-based implementation if we want to go that route
5372
5288
  // would be `Partial<Record<SentryRequestType, Partial<Record<Outcome, number>>>>`
5373
- var key = CATEGORY_MAPPING[category] + ":" + reason;
5289
+ var key = requestTypeToCategory(category) + ":" + reason;
5374
5290
  logger.log("Adding outcome: " + key);
5375
5291
  this._outcomes[key] = (_a = this._outcomes[key], (_a !== null && _a !== void 0 ? _a : 0)) + 1;
5376
5292
  };
@@ -5389,9 +5305,9 @@ var Sentry = (function (exports) {
5389
5305
  return;
5390
5306
  }
5391
5307
  logger.log("Flushing outcomes:\n" + JSON.stringify(outcomes, null, 2));
5392
- var url = this._api.getEnvelopeEndpointWithUrlEncodedAuth();
5308
+ var url = getEnvelopeEndpointWithUrlEncodedAuth(this._api.dsn, this._api.tunnel);
5393
5309
  // Envelope header is required to be at least an empty object
5394
- 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) })));
5395
5311
  var itemHeaders = JSON.stringify({
5396
5312
  type: 'client_report',
5397
5313
  });
@@ -5419,15 +5335,16 @@ var Sentry = (function (exports) {
5419
5335
  */
5420
5336
  BaseTransport.prototype._handleResponse = function (_a) {
5421
5337
  var requestType = _a.requestType, response = _a.response, headers = _a.headers, resolve = _a.resolve, reject = _a.reject;
5422
- var status = exports.Status.fromHttpCode(response.status);
5338
+ var status = eventStatusFromHttpCode(response.status);
5423
5339
  /**
5424
5340
  * "The name is case-insensitive."
5425
5341
  * https://developer.mozilla.org/en-US/docs/Web/API/Headers/get
5426
5342
  */
5427
5343
  var limited = this._handleRateLimit(headers);
5428
- if (limited)
5344
+ if (limited && isDebugBuild()) {
5429
5345
  logger.warn("Too many " + requestType + " requests, backing off until: " + this._disabledUntil(requestType));
5430
- if (status === exports.Status.Success) {
5346
+ }
5347
+ if (status === 'success') {
5431
5348
  resolve({ status: status });
5432
5349
  return;
5433
5350
  }
@@ -5437,7 +5354,7 @@ var Sentry = (function (exports) {
5437
5354
  * Gets the time that given category is disabled until for rate limiting
5438
5355
  */
5439
5356
  BaseTransport.prototype._disabledUntil = function (requestType) {
5440
- var category = CATEGORY_MAPPING[requestType];
5357
+ var category = requestTypeToCategory(requestType);
5441
5358
  return this._rateLimits[category] || this._rateLimits.all;
5442
5359
  };
5443
5360
  /**
@@ -5513,18 +5430,6 @@ var Sentry = (function (exports) {
5513
5430
  _this._fetch = fetchImpl;
5514
5431
  return _this;
5515
5432
  }
5516
- /**
5517
- * @inheritDoc
5518
- */
5519
- FetchTransport.prototype.sendEvent = function (event) {
5520
- return this._sendRequest(eventToSentryRequest(event, this._api), event);
5521
- };
5522
- /**
5523
- * @inheritDoc
5524
- */
5525
- FetchTransport.prototype.sendSession = function (session) {
5526
- return this._sendRequest(sessionToSentryRequest(session, this._api), session);
5527
- };
5528
5433
  /**
5529
5434
  * @param sentryRequest Prepared SentryRequest to be delivered
5530
5435
  * @param originalPayload Original payload used to create SentryRequest
@@ -5532,7 +5437,7 @@ var Sentry = (function (exports) {
5532
5437
  FetchTransport.prototype._sendRequest = function (sentryRequest, originalPayload) {
5533
5438
  var _this = this;
5534
5439
  if (this._isRateLimited(sentryRequest.type)) {
5535
- this.recordLostEvent(Outcome.RateLimitBackoff, sentryRequest.type);
5440
+ this.recordLostEvent('ratelimit_backoff', sentryRequest.type);
5536
5441
  return Promise.reject({
5537
5442
  event: originalPayload,
5538
5443
  type: sentryRequest.type,
@@ -5578,10 +5483,10 @@ var Sentry = (function (exports) {
5578
5483
  .then(undefined, function (reason) {
5579
5484
  // It's either buffer rejection or any other xhr/fetch error, which are treated as NetworkError.
5580
5485
  if (reason instanceof SentryError) {
5581
- _this.recordLostEvent(Outcome.QueueOverflow, sentryRequest.type);
5486
+ _this.recordLostEvent('queue_overflow', sentryRequest.type);
5582
5487
  }
5583
5488
  else {
5584
- _this.recordLostEvent(Outcome.NetworkError, sentryRequest.type);
5489
+ _this.recordLostEvent('network_error', sentryRequest.type);
5585
5490
  }
5586
5491
  throw reason;
5587
5492
  });
@@ -5595,18 +5500,6 @@ var Sentry = (function (exports) {
5595
5500
  function XHRTransport() {
5596
5501
  return _super !== null && _super.apply(this, arguments) || this;
5597
5502
  }
5598
- /**
5599
- * @inheritDoc
5600
- */
5601
- XHRTransport.prototype.sendEvent = function (event) {
5602
- return this._sendRequest(eventToSentryRequest(event, this._api), event);
5603
- };
5604
- /**
5605
- * @inheritDoc
5606
- */
5607
- XHRTransport.prototype.sendSession = function (session) {
5608
- return this._sendRequest(sessionToSentryRequest(session, this._api), session);
5609
- };
5610
5503
  /**
5611
5504
  * @param sentryRequest Prepared SentryRequest to be delivered
5612
5505
  * @param originalPayload Original payload used to create SentryRequest
@@ -5614,7 +5507,7 @@ var Sentry = (function (exports) {
5614
5507
  XHRTransport.prototype._sendRequest = function (sentryRequest, originalPayload) {
5615
5508
  var _this = this;
5616
5509
  if (this._isRateLimited(sentryRequest.type)) {
5617
- this.recordLostEvent(Outcome.RateLimitBackoff, sentryRequest.type);
5510
+ this.recordLostEvent('ratelimit_backoff', sentryRequest.type);
5618
5511
  return Promise.reject({
5619
5512
  event: originalPayload,
5620
5513
  type: sentryRequest.type,
@@ -5647,10 +5540,10 @@ var Sentry = (function (exports) {
5647
5540
  .then(undefined, function (reason) {
5648
5541
  // It's either buffer rejection or any other xhr/fetch error, which are treated as NetworkError.
5649
5542
  if (reason instanceof SentryError) {
5650
- _this.recordLostEvent(Outcome.QueueOverflow, sentryRequest.type);
5543
+ _this.recordLostEvent('queue_overflow', sentryRequest.type);
5651
5544
  }
5652
5545
  else {
5653
- _this.recordLostEvent(Outcome.NetworkError, sentryRequest.type);
5546
+ _this.recordLostEvent('network_error', sentryRequest.type);
5654
5547
  }
5655
5548
  throw reason;
5656
5549
  });
@@ -5686,7 +5579,7 @@ var Sentry = (function (exports) {
5686
5579
  * @inheritDoc
5687
5580
  */
5688
5581
  BrowserBackend.prototype.eventFromMessage = function (message, level, hint) {
5689
- if (level === void 0) { level = exports.Severity.Info; }
5582
+ if (level === void 0) { level = 'info'; }
5690
5583
  return eventFromMessage(this._options, message, level, hint);
5691
5584
  };
5692
5585
  /**
@@ -5736,19 +5629,27 @@ var Sentry = (function (exports) {
5736
5629
  * @hidden
5737
5630
  */
5738
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
5739
5638
  if (options === void 0) { options = {}; }
5740
5639
  if (typeof fn !== 'function') {
5741
5640
  return fn;
5742
5641
  }
5743
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
+ }
5744
5649
  // We don't wanna wrap it twice
5745
- if (fn.__sentry__) {
5650
+ if (getOriginalFunction(fn)) {
5746
5651
  return fn;
5747
5652
  }
5748
- // If this has already been wrapped in the past, return that wrapped function
5749
- if (fn.__sentry_wrapped__) {
5750
- return fn.__sentry_wrapped__;
5751
- }
5752
5653
  }
5753
5654
  catch (e) {
5754
5655
  // Just accessing custom props in some Selenium environments
@@ -5766,14 +5667,6 @@ var Sentry = (function (exports) {
5766
5667
  }
5767
5668
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
5768
5669
  var wrappedArguments = args.map(function (arg) { return wrap(arg, options); });
5769
- if (fn.handleEvent) {
5770
- // Attempt to invoke user-land function
5771
- // NOTE: If you are a Sentry user, and you are seeing this stack frame, it
5772
- // means the sentry.javascript SDK caught an error invoking your application code. This
5773
- // is expected behavior and NOT indicative of a bug with sentry.javascript.
5774
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
5775
- return fn.handleEvent.apply(this, wrappedArguments);
5776
- }
5777
5670
  // Attempt to invoke user-land function
5778
5671
  // NOTE: If you are a Sentry user, and you are seeing this stack frame, it
5779
5672
  // means the sentry.javascript SDK caught an error invoking your application code. This
@@ -5784,13 +5677,12 @@ var Sentry = (function (exports) {
5784
5677
  ignoreNextOnError();
5785
5678
  withScope(function (scope) {
5786
5679
  scope.addEventProcessor(function (event) {
5787
- var processedEvent = __assign({}, event);
5788
5680
  if (options.mechanism) {
5789
- addExceptionTypeValue(processedEvent, undefined, undefined);
5790
- addExceptionMechanism(processedEvent, options.mechanism);
5681
+ addExceptionTypeValue(event, undefined, undefined);
5682
+ addExceptionMechanism(event, options.mechanism);
5791
5683
  }
5792
- processedEvent.extra = __assign(__assign({}, processedEvent.extra), { arguments: args });
5793
- return processedEvent;
5684
+ event.extra = __assign(__assign({}, event.extra), { arguments: args });
5685
+ return event;
5794
5686
  });
5795
5687
  captureException(ex);
5796
5688
  });
@@ -5808,24 +5700,10 @@ var Sentry = (function (exports) {
5808
5700
  }
5809
5701
  }
5810
5702
  catch (_oO) { } // eslint-disable-line no-empty
5811
- fn.prototype = fn.prototype || {};
5812
- sentryWrapped.prototype = fn.prototype;
5813
- Object.defineProperty(fn, '__sentry_wrapped__', {
5814
- enumerable: false,
5815
- value: sentryWrapped,
5816
- });
5817
5703
  // Signal that this function has been wrapped/filled already
5818
5704
  // for both debugging and to prevent it to being wrapped/filled twice
5819
- Object.defineProperties(sentryWrapped, {
5820
- __sentry__: {
5821
- enumerable: false,
5822
- value: true,
5823
- },
5824
- __sentry_original__: {
5825
- enumerable: false,
5826
- value: fn,
5827
- },
5828
- });
5705
+ markFunctionWrapped(sentryWrapped, fn);
5706
+ addNonEnumerableProperty(fn, '__sentry_wrapped__', sentryWrapped);
5829
5707
  // Restore original function name (not all browsers allow that)
5830
5708
  try {
5831
5709
  var descriptor = Object.getOwnPropertyDescriptor(sentryWrapped, 'name');
@@ -5851,16 +5729,20 @@ var Sentry = (function (exports) {
5851
5729
  return;
5852
5730
  }
5853
5731
  if (!options.eventId) {
5854
- logger.error("Missing eventId option in showReportDialog call");
5732
+ if (isDebugBuild()) {
5733
+ logger.error("Missing eventId option in showReportDialog call");
5734
+ }
5855
5735
  return;
5856
5736
  }
5857
5737
  if (!options.dsn) {
5858
- logger.error("Missing dsn option in showReportDialog call");
5738
+ if (isDebugBuild()) {
5739
+ logger.error("Missing dsn option in showReportDialog call");
5740
+ }
5859
5741
  return;
5860
5742
  }
5861
5743
  var script = global$5.document.createElement('script');
5862
5744
  script.async = true;
5863
- script.src = new API(options.dsn).getReportDialogEndpoint(options);
5745
+ script.src = getReportDialogEndpoint(options.dsn, options);
5864
5746
  if (options.onLoad) {
5865
5747
  // eslint-disable-next-line @typescript-eslint/unbound-method
5866
5748
  script.onload = options.onLoad;
@@ -5879,10 +5761,14 @@ var Sentry = (function (exports) {
5879
5761
  * @inheritDoc
5880
5762
  */
5881
5763
  this.name = GlobalHandlers.id;
5882
- /** JSDoc */
5883
- this._onErrorHandlerInstalled = false;
5884
- /** JSDoc */
5885
- 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
+ };
5886
5772
  this._options = __assign({ onerror: true, onunhandledrejection: true }, options);
5887
5773
  }
5888
5774
  /**
@@ -5890,179 +5776,183 @@ var Sentry = (function (exports) {
5890
5776
  */
5891
5777
  GlobalHandlers.prototype.setupOnce = function () {
5892
5778
  Error.stackTraceLimit = 50;
5893
- if (this._options.onerror) {
5894
- logger.log('Global Handler attached: onerror');
5895
- this._installGlobalOnErrorHandler();
5896
- }
5897
- if (this._options.onunhandledrejection) {
5898
- logger.log('Global Handler attached: onunhandledrejection');
5899
- this._installGlobalOnUnhandledRejectionHandler();
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
+ }
5900
5790
  }
5901
5791
  };
5902
- /** JSDoc */
5903
- GlobalHandlers.prototype._installGlobalOnErrorHandler = function () {
5904
- var _this = this;
5905
- if (this._onErrorHandlerInstalled) {
5792
+ /**
5793
+ * @inheritDoc
5794
+ */
5795
+ GlobalHandlers.id = 'GlobalHandlers';
5796
+ return GlobalHandlers;
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)) {
5906
5805
  return;
5907
5806
  }
5908
- addInstrumentationHandler({
5909
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
5910
- callback: function (data) {
5911
- var error = data.error;
5912
- var currentHub = getCurrentHub();
5913
- var hasIntegration = currentHub.getIntegration(GlobalHandlers);
5914
- var isFailedOwnDelivery = error && error.__sentry_own_request__ === true;
5915
- if (!hasIntegration || shouldIgnoreOnError() || isFailedOwnDelivery) {
5916
- return;
5917
- }
5918
- var client = currentHub.getClient();
5919
- var event = error === undefined && isString(data.msg)
5920
- ? _this._eventFromIncompleteOnError(data.msg, data.url, data.line, data.column)
5921
- : _this._enhanceEventWithInitialFrame(eventFromUnknownInput(error || data.msg, undefined, {
5922
- attachStacktrace: client && client.getOptions().attachStacktrace,
5923
- rejection: false,
5924
- }), data.url, data.line, data.column);
5925
- addExceptionMechanism(event, {
5926
- handled: false,
5927
- type: 'onerror',
5928
- });
5929
- currentHub.captureEvent(event, {
5930
- originalException: error,
5931
- });
5932
- },
5933
- type: 'error',
5934
- });
5935
- this._onErrorHandlerInstalled = true;
5936
- };
5937
- /** JSDoc */
5938
- GlobalHandlers.prototype._installGlobalOnUnhandledRejectionHandler = function () {
5939
- var _this = this;
5940
- if (this._onUnhandledRejectionHandlerInstalled) {
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__)) {
5941
5809
  return;
5942
5810
  }
5943
- addInstrumentationHandler({
5944
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
5945
- callback: function (e) {
5946
- var error = e;
5947
- // dig the object of the rejection out of known event types
5948
- try {
5949
- // PromiseRejectionEvents store the object of the rejection under 'reason'
5950
- // see https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent
5951
- if ('reason' in e) {
5952
- error = e.reason;
5953
- }
5954
- // something, somewhere, (likely a browser extension) effectively casts PromiseRejectionEvents
5955
- // to CustomEvents, moving the `promise` and `reason` attributes of the PRE into
5956
- // the CustomEvent's `detail` attribute, since they're not part of CustomEvent's spec
5957
- // see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent and
5958
- // https://github.com/getsentry/sentry-javascript/issues/2380
5959
- else if ('detail' in e && 'reason' in e.detail) {
5960
- error = e.detail.reason;
5961
- }
5962
- }
5963
- catch (_oO) {
5964
- // no-empty
5965
- }
5966
- var currentHub = getCurrentHub();
5967
- var hasIntegration = currentHub.getIntegration(GlobalHandlers);
5968
- var isFailedOwnDelivery = error && error.__sentry_own_request__ === true;
5969
- if (!hasIntegration || shouldIgnoreOnError() || isFailedOwnDelivery) {
5970
- return true;
5971
- }
5972
- var client = currentHub.getClient();
5973
- var event = isPrimitive(error)
5974
- ? _this._eventFromRejectionWithPrimitive(error)
5975
- : eventFromUnknownInput(error, undefined, {
5976
- attachStacktrace: client && client.getOptions().attachStacktrace,
5977
- rejection: true,
5978
- });
5979
- event.level = exports.Severity.Error;
5980
- addExceptionMechanism(event, {
5981
- handled: false,
5982
- type: 'onunhandledrejection',
5983
- });
5984
- currentHub.captureEvent(event, {
5985
- originalException: error,
5986
- });
5987
- return;
5988
- },
5989
- type: 'unhandledrejection',
5990
- });
5991
- this._onUnhandledRejectionHandlerInstalled = true;
5992
- };
5993
- /**
5994
- * This function creates a stack from an old, error-less onerror handler.
5995
- */
5996
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
5997
- GlobalHandlers.prototype._eventFromIncompleteOnError = function (msg, url, line, column) {
5998
- var ERROR_TYPES_RE = /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i;
5999
- // If 'message' is ErrorEvent, get real message from inside
6000
- var message = isErrorEvent(msg) ? msg.message : msg;
6001
- var name;
6002
- var groups = message.match(ERROR_TYPES_RE);
6003
- if (groups) {
6004
- name = groups[1];
6005
- message = groups[2];
6006
- }
6007
- var event = {
6008
- exception: {
6009
- values: [
6010
- {
6011
- type: name || 'Error',
6012
- value: message,
6013
- },
6014
- ],
6015
- },
6016
- };
6017
- return this._enhanceEventWithInitialFrame(event, url, line, column);
6018
- };
6019
- /**
6020
- * Create an event from a promise rejection where the `reason` is a primitive.
6021
- *
6022
- * @param reason: The `reason` property of the promise rejection
6023
- * @returns An Event object with an appropriate `exception` value
6024
- */
6025
- GlobalHandlers.prototype._eventFromRejectionWithPrimitive = function (reason) {
6026
- return {
6027
- exception: {
6028
- values: [
6029
- {
6030
- type: 'UnhandledRejection',
6031
- // String() is needed because the Primitive type includes symbols (which can't be automatically stringified)
6032
- value: "Non-Error promise rejection captured with value: " + String(reason),
6033
- },
6034
- ],
6035
- },
6036
- };
6037
- };
6038
- /** JSDoc */
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',
6039
5823
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6040
- GlobalHandlers.prototype._enhanceEventWithInitialFrame = function (event, url, line, column) {
6041
- event.exception = event.exception || {};
6042
- event.exception.values = event.exception.values || [];
6043
- event.exception.values[0] = event.exception.values[0] || {};
6044
- event.exception.values[0].stacktrace = event.exception.values[0].stacktrace || {};
6045
- event.exception.values[0].stacktrace.frames = event.exception.values[0].stacktrace.frames || [];
6046
- var colno = isNaN(parseInt(column, 10)) ? undefined : column;
6047
- var lineno = isNaN(parseInt(line, 10)) ? undefined : line;
6048
- var filename = isString(url) && url.length > 0 ? url : getLocationHref();
6049
- if (event.exception.values[0].stacktrace.frames.length === 0) {
6050
- event.exception.values[0].stacktrace.frames.push({
6051
- colno: colno,
6052
- filename: filename,
6053
- function: '?',
6054
- in_app: true,
6055
- lineno: lineno,
6056
- });
5824
+ function (e) {
5825
+ var _a = __read(getHubAndAttachStacktrace(), 2), hub = _a[0], attachStacktrace = _a[1];
5826
+ if (!hub.getIntegration(GlobalHandlers)) {
5827
+ return;
6057
5828
  }
6058
- return event;
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
+ }
5845
+ }
5846
+ catch (_oO) {
5847
+ // no-empty
5848
+ }
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,
5857
+ });
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
+ },
6059
5880
  };
6060
- /**
6061
- * @inheritDoc
6062
- */
6063
- GlobalHandlers.id = 'GlobalHandlers';
6064
- return GlobalHandlers;
6065
- }());
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,
5902
+ },
5903
+ ],
5904
+ },
5905
+ };
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
+ }
6066
5956
 
6067
5957
  var DEFAULT_EVENT_TARGET = [
6068
5958
  'EventTarget',
@@ -6114,181 +6004,182 @@ var Sentry = (function (exports) {
6114
6004
  TryCatch.prototype.setupOnce = function () {
6115
6005
  var global = getGlobalObject();
6116
6006
  if (this._options.setTimeout) {
6117
- fill(global, 'setTimeout', this._wrapTimeFunction.bind(this));
6007
+ fill(global, 'setTimeout', _wrapTimeFunction);
6118
6008
  }
6119
6009
  if (this._options.setInterval) {
6120
- fill(global, 'setInterval', this._wrapTimeFunction.bind(this));
6010
+ fill(global, 'setInterval', _wrapTimeFunction);
6121
6011
  }
6122
6012
  if (this._options.requestAnimationFrame) {
6123
- fill(global, 'requestAnimationFrame', this._wrapRAF.bind(this));
6013
+ fill(global, 'requestAnimationFrame', _wrapRAF);
6124
6014
  }
6125
6015
  if (this._options.XMLHttpRequest && 'XMLHttpRequest' in global) {
6126
- fill(XMLHttpRequest.prototype, 'send', this._wrapXHR.bind(this));
6016
+ fill(XMLHttpRequest.prototype, 'send', _wrapXHR);
6127
6017
  }
6128
- if (this._options.eventTarget) {
6129
- var eventTarget = Array.isArray(this._options.eventTarget) ? this._options.eventTarget : DEFAULT_EVENT_TARGET;
6130
- eventTarget.forEach(this._wrapEventTarget.bind(this));
6018
+ var eventTargetOption = this._options.eventTarget;
6019
+ if (eventTargetOption) {
6020
+ var eventTarget = Array.isArray(eventTargetOption) ? eventTargetOption : DEFAULT_EVENT_TARGET;
6021
+ eventTarget.forEach(_wrapEventTarget);
6131
6022
  }
6132
6023
  };
6133
- /** JSDoc */
6134
- TryCatch.prototype._wrapTimeFunction = function (original) {
6135
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6136
- return function () {
6137
- var args = [];
6138
- for (var _i = 0; _i < arguments.length; _i++) {
6139
- args[_i] = arguments[_i];
6140
- }
6141
- var originalCallback = args[0];
6142
- args[0] = wrap(originalCallback, {
6143
- mechanism: {
6144
- data: { function: getFunctionName(original) },
6145
- handled: true,
6146
- type: 'instrument',
6147
- },
6148
- });
6149
- return original.apply(this, args);
6150
- };
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);
6151
6047
  };
6152
- /** JSDoc */
6048
+ }
6049
+ /** JSDoc */
6050
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6051
+ function _wrapRAF(original) {
6153
6052
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6154
- TryCatch.prototype._wrapRAF = function (original) {
6155
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6156
- return function (callback) {
6157
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6158
- return original.call(this, wrap(callback, {
6159
- mechanism: {
6160
- data: {
6161
- function: 'requestAnimationFrame',
6162
- handler: getFunctionName(original),
6163
- },
6164
- handled: true,
6165
- type: 'instrument',
6053
+ return function (callback) {
6054
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6055
+ return original.call(this, wrap(callback, {
6056
+ mechanism: {
6057
+ data: {
6058
+ function: 'requestAnimationFrame',
6059
+ handler: getFunctionName(original),
6166
6060
  },
6167
- }));
6168
- };
6061
+ handled: true,
6062
+ type: 'instrument',
6063
+ },
6064
+ }));
6169
6065
  };
6170
- /** JSDoc */
6171
- TryCatch.prototype._wrapEventTarget = function (target) {
6172
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6173
- var global = getGlobalObject();
6174
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6175
- var proto = global[target] && global[target].prototype;
6176
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-prototype-builtins
6177
- if (!proto || !proto.hasOwnProperty || !proto.hasOwnProperty('addEventListener')) {
6178
- return;
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];
6179
6074
  }
6180
- fill(proto, 'addEventListener', function (original) {
6181
- return function (eventName, fn, options) {
6182
- try {
6183
- if (typeof fn.handleEvent === 'function') {
6184
- fn.handleEvent = wrap(fn.handleEvent.bind(fn), {
6185
- mechanism: {
6186
- data: {
6187
- function: 'handleEvent',
6188
- handler: getFunctionName(fn),
6189
- target: target,
6190
- },
6191
- handled: true,
6192
- type: 'instrument',
6193
- },
6194
- });
6195
- }
6196
- }
6197
- catch (err) {
6198
- // can sometimes get 'Permission denied to access property "handle Event'
6199
- }
6200
- 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') {
6201
6080
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6202
- wrap(fn, {
6203
- mechanism: {
6204
- data: {
6205
- function: 'addEventListener',
6206
- handler: getFunctionName(fn),
6207
- 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',
6208
6090
  },
6209
- handled: true,
6210
- type: 'instrument',
6211
- },
6212
- }), options);
6213
- };
6214
- });
6215
- fill(proto, 'removeEventListener', function (originalRemoveEventListener) {
6216
- return function (eventName, fn, options) {
6217
- var _a;
6218
- /**
6219
- * There are 2 possible scenarios here:
6220
- *
6221
- * 1. Someone passes a callback, which was attached prior to Sentry initialization, or by using unmodified
6222
- * method, eg. `document.addEventListener.call(el, name, handler). In this case, we treat this function
6223
- * as a pass-through, and call original `removeEventListener` with it.
6224
- *
6225
- * 2. Someone passes a callback, which was attached after Sentry was initialized, which means that it was using
6226
- * our wrapped version of `addEventListener`, which internally calls `wrap` helper.
6227
- * This helper "wraps" whole callback inside a try/catch statement, and attached appropriate metadata to it,
6228
- * in order for us to make a distinction between wrapped/non-wrapped functions possible.
6229
- * If a function was wrapped, it has additional property of `__sentry_wrapped__`, holding the handler.
6230
- *
6231
- * When someone adds a handler prior to initialization, and then do it again, but after,
6232
- * then we have to detach both of them. Otherwise, if we'd detach only wrapped one, it'd be impossible
6233
- * to get rid of the initial handler and it'd stick there forever.
6234
- */
6235
- var wrappedEventHandler = fn;
6236
- try {
6237
- var originalEventHandler = (_a = wrappedEventHandler) === null || _a === void 0 ? void 0 : _a.__sentry_wrapped__;
6238
- if (originalEventHandler) {
6239
- 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);
6240
6096
  }
6241
- }
6242
- catch (e) {
6243
- // ignore, accessing __sentry_wrapped__ will throw in some Selenium environments
6244
- }
6245
- return originalRemoveEventListener.call(this, eventName, wrappedEventHandler, options);
6246
- };
6097
+ // Otherwise wrap directly
6098
+ return wrap(original, wrapOptions);
6099
+ });
6100
+ }
6247
6101
  });
6102
+ return originalSend.apply(this, args);
6248
6103
  };
6249
- /** JSDoc */
6250
- TryCatch.prototype._wrapXHR = function (originalSend) {
6251
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6252
- return function () {
6253
- var args = [];
6254
- for (var _i = 0; _i < arguments.length; _i++) {
6255
- args[_i] = arguments[_i];
6256
- }
6257
- // eslint-disable-next-line @typescript-eslint/no-this-alias
6258
- var xhr = this;
6259
- var xmlHttpRequestProps = ['onload', 'onerror', 'onprogress', 'onreadystatechange'];
6260
- xmlHttpRequestProps.forEach(function (prop) {
6261
- if (prop in xhr && typeof xhr[prop] === 'function') {
6262
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6263
- fill(xhr, prop, function (original) {
6264
- var wrapOptions = {
6265
- mechanism: {
6266
- data: {
6267
- function: prop,
6268
- handler: getFunctionName(original),
6269
- },
6270
- handled: true,
6271
- 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,
6272
6125
  },
6273
- };
6274
- // If Instrument integration has been called before TryCatch, get the name of original function
6275
- if (original.__sentry_original__) {
6276
- wrapOptions.mechanism.data.handler = getFunctionName(original.__sentry_original__);
6277
- }
6278
- // Otherwise wrap directly
6279
- return wrap(original, wrapOptions);
6126
+ handled: true,
6127
+ type: 'instrument',
6128
+ },
6280
6129
  });
6281
6130
  }
6282
- });
6283
- 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);
6284
6148
  };
6285
- };
6286
- /**
6287
- * @inheritDoc
6288
- */
6289
- TryCatch.id = 'TryCatch';
6290
- return TryCatch;
6291
- }());
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
+ }
6292
6183
 
6293
6184
  /**
6294
6185
  * Default Breadcrumbs instrumentations
@@ -6330,104 +6221,38 @@ var Sentry = (function (exports) {
6330
6221
  * - History API
6331
6222
  */
6332
6223
  Breadcrumbs.prototype.setupOnce = function () {
6333
- var _this = this;
6334
6224
  if (this._options.console) {
6335
- addInstrumentationHandler({
6336
- callback: function () {
6337
- var args = [];
6338
- for (var _i = 0; _i < arguments.length; _i++) {
6339
- args[_i] = arguments[_i];
6340
- }
6341
- _this._consoleBreadcrumb.apply(_this, __spread(args));
6342
- },
6343
- type: 'console',
6344
- });
6225
+ addInstrumentationHandler('console', _consoleBreadcrumb);
6345
6226
  }
6346
6227
  if (this._options.dom) {
6347
- addInstrumentationHandler({
6348
- callback: function () {
6349
- var args = [];
6350
- for (var _i = 0; _i < arguments.length; _i++) {
6351
- args[_i] = arguments[_i];
6352
- }
6353
- _this._domBreadcrumb.apply(_this, __spread(args));
6354
- },
6355
- type: 'dom',
6356
- });
6228
+ addInstrumentationHandler('dom', _domBreadcrumb(this._options.dom));
6357
6229
  }
6358
6230
  if (this._options.xhr) {
6359
- addInstrumentationHandler({
6360
- callback: function () {
6361
- var args = [];
6362
- for (var _i = 0; _i < arguments.length; _i++) {
6363
- args[_i] = arguments[_i];
6364
- }
6365
- _this._xhrBreadcrumb.apply(_this, __spread(args));
6366
- },
6367
- type: 'xhr',
6368
- });
6231
+ addInstrumentationHandler('xhr', _xhrBreadcrumb);
6369
6232
  }
6370
6233
  if (this._options.fetch) {
6371
- addInstrumentationHandler({
6372
- callback: function () {
6373
- var args = [];
6374
- for (var _i = 0; _i < arguments.length; _i++) {
6375
- args[_i] = arguments[_i];
6376
- }
6377
- _this._fetchBreadcrumb.apply(_this, __spread(args));
6378
- },
6379
- type: 'fetch',
6380
- });
6234
+ addInstrumentationHandler('fetch', _fetchBreadcrumb);
6381
6235
  }
6382
6236
  if (this._options.history) {
6383
- addInstrumentationHandler({
6384
- callback: function () {
6385
- var args = [];
6386
- for (var _i = 0; _i < arguments.length; _i++) {
6387
- args[_i] = arguments[_i];
6388
- }
6389
- _this._historyBreadcrumb.apply(_this, __spread(args));
6390
- },
6391
- type: 'history',
6392
- });
6237
+ addInstrumentationHandler('history', _historyBreadcrumb);
6393
6238
  }
6394
6239
  };
6395
6240
  /**
6396
- * Creates breadcrumbs from console API calls
6397
- */
6398
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6399
- Breadcrumbs.prototype._consoleBreadcrumb = function (handlerData) {
6400
- var breadcrumb = {
6401
- category: 'console',
6402
- data: {
6403
- arguments: handlerData.args,
6404
- logger: 'console',
6405
- },
6406
- level: exports.Severity.fromString(handlerData.level),
6407
- message: safeJoin(handlerData.args, ' '),
6408
- };
6409
- if (handlerData.level === 'assert') {
6410
- if (handlerData.args[0] === false) {
6411
- breadcrumb.message = "Assertion failed: " + (safeJoin(handlerData.args.slice(1), ' ') || 'console.assert');
6412
- breadcrumb.data.arguments = handlerData.args.slice(1);
6413
- }
6414
- else {
6415
- // Don't capture a breadcrumb for passed assertions
6416
- return;
6417
- }
6418
- }
6419
- getCurrentHub().addBreadcrumb(breadcrumb, {
6420
- input: handlerData.args,
6421
- level: handlerData.level,
6422
- });
6423
- };
6424
- /**
6425
- * Creates breadcrumbs from DOM API calls
6241
+ * @inheritDoc
6426
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) {
6427
6252
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6428
- Breadcrumbs.prototype._domBreadcrumb = function (handlerData) {
6253
+ function _innerDomBreadcrumb(handlerData) {
6429
6254
  var target;
6430
- var keyAttrs = typeof this._options.dom === 'object' ? this._options.dom.serializeAttribute : undefined;
6255
+ var keyAttrs = typeof dom === 'object' ? dom.serializeAttribute : undefined;
6431
6256
  if (typeof keyAttrs === 'string') {
6432
6257
  keyAttrs = [keyAttrs];
6433
6258
  }
@@ -6451,105 +6276,130 @@ var Sentry = (function (exports) {
6451
6276
  name: handlerData.name,
6452
6277
  global: handlerData.global,
6453
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, ' '),
6454
6295
  };
6455
- /**
6456
- * Creates breadcrumbs from XHR API calls
6457
- */
6458
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6459
- Breadcrumbs.prototype._xhrBreadcrumb = function (handlerData) {
6460
- if (handlerData.endTimestamp) {
6461
- // We only capture complete, non-sentry requests
6462
- if (handlerData.xhr.__sentry_own_request__) {
6463
- return;
6464
- }
6465
- var _a = handlerData.xhr.__sentry_xhr__ || {}, method = _a.method, url = _a.url, status_code = _a.status_code, body = _a.body;
6466
- getCurrentHub().addBreadcrumb({
6467
- category: 'xhr',
6468
- data: {
6469
- method: method,
6470
- url: url,
6471
- status_code: status_code,
6472
- },
6473
- type: 'http',
6474
- }, {
6475
- xhr: handlerData.xhr,
6476
- input: body,
6477
- });
6478
- 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);
6479
6300
  }
6480
- };
6481
- /**
6482
- * Creates breadcrumbs from fetch API calls
6483
- */
6484
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6485
- Breadcrumbs.prototype._fetchBreadcrumb = function (handlerData) {
6486
- // We only capture complete fetch requests
6487
- if (!handlerData.endTimestamp) {
6301
+ else {
6302
+ // Don't capture a breadcrumb for passed assertions
6488
6303
  return;
6489
6304
  }
6490
- if (handlerData.fetchData.url.match(/sentry_key/) && handlerData.fetchData.method === 'POST') {
6491
- // 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__) {
6492
6319
  return;
6493
6320
  }
6494
- if (handlerData.error) {
6495
- getCurrentHub().addBreadcrumb({
6496
- category: 'fetch',
6497
- data: handlerData.fetchData,
6498
- level: exports.Severity.Error,
6499
- type: 'http',
6500
- }, {
6501
- data: handlerData.error,
6502
- input: handlerData.args,
6503
- });
6504
- }
6505
- else {
6506
- getCurrentHub().addBreadcrumb({
6507
- category: 'fetch',
6508
- data: __assign(__assign({}, handlerData.fetchData), { status_code: handlerData.response.status }),
6509
- type: 'http',
6510
- }, {
6511
- input: handlerData.args,
6512
- response: handlerData.response,
6513
- });
6514
- }
6515
- };
6516
- /**
6517
- * Creates breadcrumbs from history API calls
6518
- */
6519
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6520
- Breadcrumbs.prototype._historyBreadcrumb = function (handlerData) {
6521
- var global = getGlobalObject();
6522
- var from = handlerData.from;
6523
- var to = handlerData.to;
6524
- var parsedLoc = parseUrl(global.location.href);
6525
- var parsedFrom = parseUrl(from);
6526
- var parsedTo = parseUrl(to);
6527
- // Initial pushState doesn't provide `from` information
6528
- if (!parsedFrom.path) {
6529
- parsedFrom = parsedLoc;
6530
- }
6531
- // Use only the path component of the URL if the URL matches the current
6532
- // document (almost all the time when using pushState)
6533
- if (parsedLoc.protocol === parsedTo.protocol && parsedLoc.host === parsedTo.host) {
6534
- to = parsedTo.relative;
6535
- }
6536
- if (parsedLoc.protocol === parsedFrom.protocol && parsedLoc.host === parsedFrom.host) {
6537
- from = parsedFrom.relative;
6538
- }
6321
+ var _a = handlerData.xhr.__sentry_xhr__ || {}, method = _a.method, url = _a.url, status_code = _a.status_code, body = _a.body;
6539
6322
  getCurrentHub().addBreadcrumb({
6540
- category: 'navigation',
6323
+ category: 'xhr',
6541
6324
  data: {
6542
- from: from,
6543
- to: to,
6325
+ method: method,
6326
+ url: url,
6327
+ status_code: status_code,
6544
6328
  },
6329
+ type: 'http',
6330
+ }, {
6331
+ xhr: handlerData.xhr,
6332
+ input: body,
6545
6333
  });
6546
- };
6547
- /**
6548
- * @inheritDoc
6549
- */
6550
- Breadcrumbs.id = 'Breadcrumbs';
6551
- return Breadcrumbs;
6552
- }());
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
+ }
6553
6403
 
6554
6404
  var DEFAULT_KEY = 'cause';
6555
6405
  var DEFAULT_LIMIT = 5;
@@ -6573,42 +6423,38 @@ var Sentry = (function (exports) {
6573
6423
  LinkedErrors.prototype.setupOnce = function () {
6574
6424
  addGlobalEventProcessor(function (event, hint) {
6575
6425
  var self = getCurrentHub().getIntegration(LinkedErrors);
6576
- if (self) {
6577
- var handler = self._handler && self._handler.bind(self);
6578
- return typeof handler === 'function' ? handler(event, hint) : event;
6579
- }
6580
- return event;
6426
+ return self ? _handler(self._key, self._limit, event, hint) : event;
6581
6427
  });
6582
6428
  };
6583
- /**
6584
- * @inheritDoc
6585
- */
6586
- LinkedErrors.prototype._handler = function (event, hint) {
6587
- if (!event.exception || !event.exception.values || !hint || !isInstanceOf(hint.originalException, Error)) {
6588
- return event;
6589
- }
6590
- var linkedErrors = this._walkErrorTree(hint.originalException, this._key);
6591
- event.exception.values = __spread(linkedErrors, event.exception.values);
6592
- return event;
6593
- };
6594
- /**
6595
- * @inheritDoc
6596
- */
6597
- LinkedErrors.prototype._walkErrorTree = function (error, key, stack) {
6598
- if (stack === void 0) { stack = []; }
6599
- if (!isInstanceOf(error[key], Error) || stack.length + 1 >= this._limit) {
6600
- return stack;
6601
- }
6602
- var stacktrace = computeStackTrace(error[key]);
6603
- var exception = exceptionFromStacktrace(stacktrace);
6604
- return this._walkErrorTree(error[key], key, __spread([exception], stack));
6605
- };
6606
6429
  /**
6607
6430
  * @inheritDoc
6608
6431
  */
6609
6432
  LinkedErrors.id = 'LinkedErrors';
6610
6433
  return LinkedErrors;
6611
- }());
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
+ }
6612
6458
 
6613
6459
  var global$6 = getGlobalObject();
6614
6460
  /** UserAgent */
@@ -6624,17 +6470,16 @@ var Sentry = (function (exports) {
6624
6470
  */
6625
6471
  UserAgent.prototype.setupOnce = function () {
6626
6472
  addGlobalEventProcessor(function (event) {
6627
- var _a, _b, _c;
6628
6473
  if (getCurrentHub().getIntegration(UserAgent)) {
6629
6474
  // if none of the information we want exists, don't bother
6630
6475
  if (!global$6.navigator && !global$6.location && !global$6.document) {
6631
6476
  return event;
6632
6477
  }
6633
6478
  // grab as much info as exists and add it to the event
6634
- 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);
6635
6480
  var referrer = (global$6.document || {}).referrer;
6636
6481
  var userAgent = (global$6.navigator || {}).userAgent;
6637
- 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 }));
6638
6483
  var request = __assign(__assign({}, (url && { url: url })), { headers: headers });
6639
6484
  return __assign(__assign({}, event), { request: request });
6640
6485
  }
@@ -6665,7 +6510,7 @@ var Sentry = (function (exports) {
6665
6510
  if (self) {
6666
6511
  // Juuust in case something goes wrong
6667
6512
  try {
6668
- if (self._shouldDropEvent(currentEvent, self._previousEvent)) {
6513
+ if (_shouldDropEvent(currentEvent, self._previousEvent)) {
6669
6514
  logger.warn("Event dropped due to being a duplicate of previously captured event.");
6670
6515
  return null;
6671
6516
  }
@@ -6678,140 +6523,140 @@ var Sentry = (function (exports) {
6678
6523
  return currentEvent;
6679
6524
  });
6680
6525
  };
6681
- /** JSDoc */
6682
- Dedupe.prototype._shouldDropEvent = function (currentEvent, previousEvent) {
6683
- if (!previousEvent) {
6684
- return false;
6685
- }
6686
- if (this._isSameMessageEvent(currentEvent, previousEvent)) {
6687
- return true;
6688
- }
6689
- if (this._isSameExceptionEvent(currentEvent, previousEvent)) {
6690
- return true;
6691
- }
6526
+ /**
6527
+ * @inheritDoc
6528
+ */
6529
+ Dedupe.id = 'Dedupe';
6530
+ return Dedupe;
6531
+ }());
6532
+ /** JSDoc */
6533
+ function _shouldDropEvent(currentEvent, previousEvent) {
6534
+ if (!previousEvent) {
6692
6535
  return false;
6693
- };
6694
- /** JSDoc */
6695
- Dedupe.prototype._isSameMessageEvent = function (currentEvent, previousEvent) {
6696
- var currentMessage = currentEvent.message;
6697
- var previousMessage = previousEvent.message;
6698
- // If neither event has a message property, they were both exceptions, so bail out
6699
- if (!currentMessage && !previousMessage) {
6700
- return false;
6701
- }
6702
- // If only one event has a stacktrace, but not the other one, they are not the same
6703
- if ((currentMessage && !previousMessage) || (!currentMessage && previousMessage)) {
6704
- return false;
6705
- }
6706
- if (currentMessage !== previousMessage) {
6707
- return false;
6708
- }
6709
- if (!this._isSameFingerprint(currentEvent, previousEvent)) {
6710
- return false;
6711
- }
6712
- if (!this._isSameStacktrace(currentEvent, previousEvent)) {
6713
- return false;
6714
- }
6536
+ }
6537
+ if (_isSameMessageEvent(currentEvent, previousEvent)) {
6715
6538
  return true;
6716
- };
6717
- /** JSDoc */
6718
- Dedupe.prototype._getFramesFromEvent = function (event) {
6719
- var exception = event.exception;
6720
- if (exception) {
6721
- try {
6722
- // @ts-ignore Object could be undefined
6723
- return exception.values[0].stacktrace.frames;
6724
- }
6725
- catch (_oO) {
6726
- return undefined;
6727
- }
6728
- }
6729
- else if (event.stacktrace) {
6730
- return event.stacktrace.frames;
6731
- }
6732
- return undefined;
6733
- };
6734
- /** JSDoc */
6735
- Dedupe.prototype._isSameStacktrace = function (currentEvent, previousEvent) {
6736
- var currentFrames = this._getFramesFromEvent(currentEvent);
6737
- var previousFrames = this._getFramesFromEvent(previousEvent);
6738
- // If neither event has a stacktrace, they are assumed to be the same
6739
- if (!currentFrames && !previousFrames) {
6740
- return true;
6741
- }
6742
- // If only one event has a stacktrace, but not the other one, they are not the same
6743
- if ((currentFrames && !previousFrames) || (!currentFrames && previousFrames)) {
6744
- return false;
6745
- }
6746
- currentFrames = currentFrames;
6747
- previousFrames = previousFrames;
6748
- // If number of frames differ, they are not the same
6749
- if (previousFrames.length !== currentFrames.length) {
6750
- return false;
6751
- }
6752
- // Otherwise, compare the two
6753
- for (var i = 0; i < previousFrames.length; i++) {
6754
- var frameA = previousFrames[i];
6755
- var frameB = currentFrames[i];
6756
- if (frameA.filename !== frameB.filename ||
6757
- frameA.lineno !== frameB.lineno ||
6758
- frameA.colno !== frameB.colno ||
6759
- frameA.function !== frameB.function) {
6760
- return false;
6761
- }
6762
- }
6539
+ }
6540
+ if (_isSameExceptionEvent(currentEvent, previousEvent)) {
6763
6541
  return true;
6764
- };
6765
- /** JSDoc */
6766
- Dedupe.prototype._getExceptionFromEvent = function (event) {
6767
- return event.exception && event.exception.values && event.exception.values[0];
6768
- };
6769
- /** JSDoc */
6770
- Dedupe.prototype._isSameExceptionEvent = function (currentEvent, previousEvent) {
6771
- var previousException = this._getExceptionFromEvent(previousEvent);
6772
- var currentException = this._getExceptionFromEvent(currentEvent);
6773
- if (!previousException || !currentException) {
6774
- return false;
6775
- }
6776
- if (previousException.type !== currentException.type || previousException.value !== currentException.value) {
6777
- return false;
6778
- }
6779
- if (!this._isSameFingerprint(currentEvent, previousEvent)) {
6780
- return false;
6781
- }
6782
- if (!this._isSameStacktrace(currentEvent, previousEvent)) {
6783
- return false;
6784
- }
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) {
6785
6592
  return true;
6786
- };
6787
- /** JSDoc */
6788
- Dedupe.prototype._isSameFingerprint = function (currentEvent, previousEvent) {
6789
- var currentFingerprint = currentEvent.fingerprint;
6790
- var previousFingerprint = previousEvent.fingerprint;
6791
- // If neither event has a fingerprint, they are assumed to be the same
6792
- if (!currentFingerprint && !previousFingerprint) {
6793
- return true;
6794
- }
6795
- // If only one event has a fingerprint, but not the other one, they are not the same
6796
- 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) {
6797
6612
  return false;
6798
6613
  }
6799
- currentFingerprint = currentFingerprint;
6800
- previousFingerprint = previousFingerprint;
6801
- // 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) {
6802
6647
  try {
6803
- return !!(currentFingerprint.join('') === previousFingerprint.join(''));
6648
+ // @ts-ignore Object could be undefined
6649
+ return exception.values[0].stacktrace.frames;
6804
6650
  }
6805
6651
  catch (_oO) {
6806
- return false;
6652
+ return undefined;
6807
6653
  }
6808
- };
6809
- /**
6810
- * @inheritDoc
6811
- */
6812
- Dedupe.id = 'Dedupe';
6813
- return Dedupe;
6814
- }());
6654
+ }
6655
+ else if (event.stacktrace) {
6656
+ return event.stacktrace.frames;
6657
+ }
6658
+ return undefined;
6659
+ }
6815
6660
 
6816
6661
 
6817
6662
 
@@ -7038,8 +6883,10 @@ var Sentry = (function (exports) {
7038
6883
  if (client) {
7039
6884
  return client.flush(timeout);
7040
6885
  }
7041
- logger.warn('Cannot flush events. No client defined.');
7042
- return SyncPromise.resolve(false);
6886
+ if (isDebugBuild()) {
6887
+ logger.warn('Cannot flush events. No client defined.');
6888
+ }
6889
+ return resolvedSyncPromise(false);
7043
6890
  }
7044
6891
  /**
7045
6892
  * Call `close()` on the current client, if there is one. See {@link Client.close}.
@@ -7054,8 +6901,10 @@ var Sentry = (function (exports) {
7054
6901
  if (client) {
7055
6902
  return client.close(timeout);
7056
6903
  }
7057
- logger.warn('Cannot flush events and disable SDK. No client defined.');
7058
- return SyncPromise.resolve(false);
6904
+ if (isDebugBuild()) {
6905
+ logger.warn('Cannot flush events and disable SDK. No client defined.');
6906
+ }
6907
+ return resolvedSyncPromise(false);
7059
6908
  }
7060
6909
  /**
7061
6910
  * Wrap code within a try/catch block so the SDK is able to capture errors.
@@ -7068,6 +6917,10 @@ var Sentry = (function (exports) {
7068
6917
  function wrap$1(fn) {
7069
6918
  return wrap(fn)();
7070
6919
  }
6920
+ function startSessionOnHub(hub) {
6921
+ hub.startSession({ ignoreDuration: true });
6922
+ hub.captureSession();
6923
+ }
7071
6924
  /**
7072
6925
  * Enable automatic Session Tracking for the initial page load.
7073
6926
  */
@@ -7075,7 +6928,9 @@ var Sentry = (function (exports) {
7075
6928
  var window = getGlobalObject();
7076
6929
  var document = window.document;
7077
6930
  if (typeof document === 'undefined') {
7078
- 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
+ }
7079
6934
  return;
7080
6935
  }
7081
6936
  var hub = getCurrentHub();
@@ -7085,27 +6940,21 @@ var Sentry = (function (exports) {
7085
6940
  // https://github.com/getsentry/sentry-javascript/issues/3207 and
7086
6941
  // https://github.com/getsentry/sentry-javascript/issues/3234 and
7087
6942
  // https://github.com/getsentry/sentry-javascript/issues/3278.
7088
- if (typeof hub.startSession !== 'function' || typeof hub.captureSession !== 'function') {
6943
+ if (!hub.captureSession) {
7089
6944
  return;
7090
6945
  }
7091
6946
  // The session duration for browser sessions does not track a meaningful
7092
6947
  // concept that can be used as a metric.
7093
6948
  // Automatically captured sessions are akin to page views, and thus we
7094
6949
  // discard their duration.
7095
- hub.startSession({ ignoreDuration: true });
7096
- hub.captureSession();
6950
+ startSessionOnHub(hub);
7097
6951
  // We want to create a session for every navigation as well
7098
- addInstrumentationHandler({
7099
- callback: function (_a) {
7100
- var from = _a.from, to = _a.to;
7101
- // Don't create an additional session for the initial route or if the location did not change
7102
- if (from === undefined || from === to) {
7103
- return;
7104
- }
7105
- hub.startSession({ ignoreDuration: true });
7106
- hub.captureSession();
7107
- },
7108
- 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
+ }
7109
6958
  });
7110
6959
  }
7111
6960