@andre1502/react-utilities 1.0.6 → 1.0.7

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 (202) hide show
  1. package/README.md +35 -51
  2. package/dist/EnvironmentEnum-CXTWJxNo.js +10 -0
  3. package/dist/EnvironmentEnum-CXTWJxNo.js.map +1 -0
  4. package/dist/Utils-CJ7ureSW.js +14 -0
  5. package/dist/Utils-CJ7ureSW.js.map +1 -0
  6. package/dist/browser-ponyfill-C-HVh7ck.js +321 -0
  7. package/dist/browser-ponyfill-C-HVh7ck.js.map +1 -0
  8. package/dist/chunk-vKJrgz-R.js +16 -0
  9. package/dist/config-cli-BIF4xuoO.js +1491 -0
  10. package/dist/config-cli-BIF4xuoO.js.map +1 -0
  11. package/dist/config-cli.js +3 -229
  12. package/dist/enums/CurrencySymbolEnum.d.ts +6 -5
  13. package/dist/enums/DeviceEnum.d.ts +5 -4
  14. package/dist/enums/EnvironmentEnum.d.ts +6 -5
  15. package/dist/format-BgweN3o5.js +65549 -0
  16. package/dist/format-BgweN3o5.js.map +1 -0
  17. package/dist/format.d.ts +26 -26
  18. package/dist/format.js +2 -55
  19. package/dist/hooks-oAipbPQ2.js +78 -0
  20. package/dist/hooks-oAipbPQ2.js.map +1 -0
  21. package/dist/hooks.js +2 -86
  22. package/dist/i18n-D1jKJPI0.js +1941 -0
  23. package/dist/i18n-D1jKJPI0.js.map +1 -0
  24. package/dist/i18n.js +4 -28
  25. package/dist/index-cli.d.ts +0 -1
  26. package/dist/index-cli.js +3 -28
  27. package/dist/index-rn.js +6 -39
  28. package/dist/index.js +7 -61
  29. package/dist/sentry-rn-DZwIel7y.js +743 -0
  30. package/dist/sentry-rn-DZwIel7y.js.map +1 -0
  31. package/dist/sentry-rn.js +2 -28
  32. package/dist/sentry.js +39 -26
  33. package/dist/sentry.js.map +1 -1
  34. package/dist/utils.js +45 -37
  35. package/dist/utils.js.map +1 -1
  36. package/package.json +56 -86
  37. package/src/Config/GoogleAuth.ts +1 -1
  38. package/src/Sentry/React.ts +2 -4
  39. package/src/Sentry/ReactNative.ts +2 -4
  40. package/src/enums/CurrencySymbolEnum.ts +8 -5
  41. package/src/enums/DeviceEnum.ts +6 -4
  42. package/src/enums/EnvironmentEnum.ts +8 -5
  43. package/src/format.ts +32 -32
  44. package/src/index-cli.ts +0 -1
  45. package/dist/Config/Config.js +0 -249
  46. package/dist/Config/Config.js.map +0 -1
  47. package/dist/Config/GoogleAuth.js +0 -68
  48. package/dist/Config/GoogleAuth.js.map +0 -1
  49. package/dist/Config/Locales.js +0 -62
  50. package/dist/Config/Locales.js.map +0 -1
  51. package/dist/Config/Output.js +0 -36
  52. package/dist/Config/Output.js.map +0 -1
  53. package/dist/Config/Sitemap.js +0 -72
  54. package/dist/Config/Sitemap.js.map +0 -1
  55. package/dist/EnvironmentEnum-BjXsfSRZ.js +0 -9
  56. package/dist/EnvironmentEnum-BjXsfSRZ.js.map +0 -1
  57. package/dist/EnvironmentEnum-UcQ6Il1O.js +0 -9
  58. package/dist/EnvironmentEnum-UcQ6Il1O.js.map +0 -1
  59. package/dist/Format/NumberFormat.js +0 -77
  60. package/dist/Format/NumberFormat.js.map +0 -1
  61. package/dist/Format/NumberParser.js +0 -51
  62. package/dist/Format/NumberParser.js.map +0 -1
  63. package/dist/Hooks/useDevice.js +0 -47
  64. package/dist/Hooks/useDevice.js.map +0 -1
  65. package/dist/Hooks/useSound.js +0 -47
  66. package/dist/Hooks/useSound.js.map +0 -1
  67. package/dist/Hooks/useWebSocket.js +0 -120
  68. package/dist/Hooks/useWebSocket.js.map +0 -1
  69. package/dist/I18n/I18n.js +0 -134
  70. package/dist/I18n/I18n.js.map +0 -1
  71. package/dist/NumberFormat-CvvBWhHc.js +0 -89
  72. package/dist/NumberFormat-CvvBWhHc.js.map +0 -1
  73. package/dist/NumberFormat-glmpbk7E.js +0 -94
  74. package/dist/NumberFormat-glmpbk7E.js.map +0 -1
  75. package/dist/React-BaJ1KfGF.js +0 -87
  76. package/dist/React-BaJ1KfGF.js.map +0 -1
  77. package/dist/React-qUl0CBmE.js +0 -109
  78. package/dist/React-qUl0CBmE.js.map +0 -1
  79. package/dist/ReactNative-B4gt8nBr.js +0 -1790
  80. package/dist/ReactNative-B4gt8nBr.js.map +0 -1
  81. package/dist/ReactNative-CDMfQFfN.js +0 -1812
  82. package/dist/ReactNative-CDMfQFfN.js.map +0 -1
  83. package/dist/Sentry/Build.d.ts +0 -9
  84. package/dist/Sentry/Build.js +0 -87
  85. package/dist/Sentry/Build.js.map +0 -1
  86. package/dist/Sentry/React.js +0 -103
  87. package/dist/Sentry/React.js.map +0 -1
  88. package/dist/Sentry/ReactNative.js +0 -113
  89. package/dist/Sentry/ReactNative.js.map +0 -1
  90. package/dist/Sentry/Utils.js +0 -24
  91. package/dist/Sentry/Utils.js.map +0 -1
  92. package/dist/Utils/Array.js +0 -26
  93. package/dist/Utils/Array.js.map +0 -1
  94. package/dist/Utils/Files.js +0 -51
  95. package/dist/Utils/Files.js.map +0 -1
  96. package/dist/Utils/Pagination.js +0 -32
  97. package/dist/Utils/Pagination.js.map +0 -1
  98. package/dist/Utils/Utils.js +0 -101
  99. package/dist/Utils/Utils.js.map +0 -1
  100. package/dist/Utils-BC1fDy39.js +0 -74
  101. package/dist/Utils-BC1fDy39.js.map +0 -1
  102. package/dist/Utils-Cq948gfa.js +0 -20
  103. package/dist/Utils-Cq948gfa.js.map +0 -1
  104. package/dist/Utils-D7KRF8VU.js +0 -64
  105. package/dist/Utils-D7KRF8VU.js.map +0 -1
  106. package/dist/Utils-Dilye04y.js +0 -22
  107. package/dist/Utils-Dilye04y.js.map +0 -1
  108. package/dist/config-cli.cjs +0 -532
  109. package/dist/config-cli.cjs.map +0 -1
  110. package/dist/config-cli.js.map +0 -1
  111. package/dist/config-cli.mjs +0 -500
  112. package/dist/config-cli.mjs.map +0 -1
  113. package/dist/enums/CurrencySymbolEnum.js +0 -15
  114. package/dist/enums/CurrencySymbolEnum.js.map +0 -1
  115. package/dist/enums/DeviceEnum.js +0 -12
  116. package/dist/enums/DeviceEnum.js.map +0 -1
  117. package/dist/enums/EnvironmentEnum.js +0 -13
  118. package/dist/enums/EnvironmentEnum.js.map +0 -1
  119. package/dist/format.cjs +0 -43
  120. package/dist/format.cjs.map +0 -1
  121. package/dist/format.js.map +0 -1
  122. package/dist/format.mjs +0 -30
  123. package/dist/format.mjs.map +0 -1
  124. package/dist/hooks.cjs +0 -13
  125. package/dist/hooks.cjs.map +0 -1
  126. package/dist/hooks.js.map +0 -1
  127. package/dist/hooks.mjs +0 -4
  128. package/dist/hooks.mjs.map +0 -1
  129. package/dist/i18n.cjs +0 -3039
  130. package/dist/i18n.cjs.map +0 -1
  131. package/dist/i18n.js.map +0 -1
  132. package/dist/i18n.mjs +0 -3032
  133. package/dist/i18n.mjs.map +0 -1
  134. package/dist/index-cli.cjs +0 -31
  135. package/dist/index-cli.cjs.map +0 -1
  136. package/dist/index-cli.js.map +0 -1
  137. package/dist/index-cli.mjs +0 -14
  138. package/dist/index-cli.mjs.map +0 -1
  139. package/dist/index-rn.cjs +0 -57
  140. package/dist/index-rn.cjs.map +0 -1
  141. package/dist/index-rn.js.map +0 -1
  142. package/dist/index-rn.mjs +0 -36
  143. package/dist/index-rn.mjs.map +0 -1
  144. package/dist/index.cjs +0 -79
  145. package/dist/index.cjs.map +0 -1
  146. package/dist/index.js.map +0 -1
  147. package/dist/index.mjs +0 -40
  148. package/dist/index.mjs.map +0 -1
  149. package/dist/interfaces/Config/ConfigOptions.js +0 -6
  150. package/dist/interfaces/Config/ConfigOptions.js.map +0 -1
  151. package/dist/interfaces/Config/EntryOptions.js +0 -6
  152. package/dist/interfaces/Config/EntryOptions.js.map +0 -1
  153. package/dist/interfaces/Config/OutputMap.js +0 -6
  154. package/dist/interfaces/Config/OutputMap.js.map +0 -1
  155. package/dist/interfaces/Config/OutputOptions.js +0 -6
  156. package/dist/interfaces/Config/OutputOptions.js.map +0 -1
  157. package/dist/interfaces/Config/SitemapMap.js +0 -6
  158. package/dist/interfaces/Config/SitemapMap.js.map +0 -1
  159. package/dist/interfaces/Config/StringMap.js +0 -6
  160. package/dist/interfaces/Config/StringMap.js.map +0 -1
  161. package/dist/interfaces/Format/FormatOptions.js +0 -6
  162. package/dist/interfaces/Format/FormatOptions.js.map +0 -1
  163. package/dist/interfaces/Sentry/InitOptions.js +0 -6
  164. package/dist/interfaces/Sentry/InitOptions.js.map +0 -1
  165. package/dist/interfaces/Sentry/InitOptionsRN.js +0 -6
  166. package/dist/interfaces/Sentry/InitOptionsRN.js.map +0 -1
  167. package/dist/interfaces/Sentry/SourceMapOptions.d.ts +0 -7
  168. package/dist/interfaces/Sentry/SourceMapOptions.js +0 -6
  169. package/dist/interfaces/Sentry/SourceMapOptions.js.map +0 -1
  170. package/dist/sentry-cli.cjs +0 -119
  171. package/dist/sentry-cli.cjs.map +0 -1
  172. package/dist/sentry-cli.d.ts +0 -9
  173. package/dist/sentry-cli.js +0 -49
  174. package/dist/sentry-cli.js.map +0 -1
  175. package/dist/sentry-cli.mjs +0 -98
  176. package/dist/sentry-cli.mjs.map +0 -1
  177. package/dist/sentry-rn.cjs +0 -11
  178. package/dist/sentry-rn.cjs.map +0 -1
  179. package/dist/sentry-rn.js.map +0 -1
  180. package/dist/sentry-rn.mjs +0 -4
  181. package/dist/sentry-rn.mjs.map +0 -1
  182. package/dist/sentry.cjs +0 -11
  183. package/dist/sentry.cjs.map +0 -1
  184. package/dist/sentry.mjs +0 -4
  185. package/dist/sentry.mjs.map +0 -1
  186. package/dist/types/Config/OptionType.js +0 -6
  187. package/dist/types/Config/OptionType.js.map +0 -1
  188. package/dist/types/Format/OptionType.js +0 -6
  189. package/dist/types/Format/OptionType.js.map +0 -1
  190. package/dist/types/Sentry/OptionType.js +0 -6
  191. package/dist/types/Sentry/OptionType.js.map +0 -1
  192. package/dist/useWebSocket-B_B6kWXM.js +0 -167
  193. package/dist/useWebSocket-B_B6kWXM.js.map +0 -1
  194. package/dist/useWebSocket-YQWaiBz9.js +0 -172
  195. package/dist/useWebSocket-YQWaiBz9.js.map +0 -1
  196. package/dist/utils.cjs +0 -59
  197. package/dist/utils.cjs.map +0 -1
  198. package/dist/utils.mjs +0 -43
  199. package/dist/utils.mjs.map +0 -1
  200. package/src/Sentry/Build.ts +0 -67
  201. package/src/interfaces/Sentry/SourceMapOptions.ts +0 -7
  202. package/src/sentry-cli.ts +0 -16
@@ -1,1790 +0,0 @@
1
- import * as Sentry from '@sentry/react-native';
2
- import { r as recordSentryHttp } from './Utils-Cq948gfa.js';
3
-
4
- /**
5
- * This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.
6
- *
7
- * ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
8
- */
9
- (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__);
10
-
11
- // This is a magic string replaced by rollup
12
-
13
- const SDK_VERSION = "8.54.0" ;
14
-
15
- /** Get's the global object for the current JavaScript runtime */
16
- const GLOBAL_OBJ = globalThis ;
17
-
18
- /**
19
- * Returns a global singleton contained in the global `__SENTRY__[]` object.
20
- *
21
- * If the singleton doesn't already exist in `__SENTRY__`, it will be created using the given factory
22
- * function and added to the `__SENTRY__` object.
23
- *
24
- * @param name name of the global singleton on __SENTRY__
25
- * @param creator creator Factory function to create the singleton if it doesn't already exist on `__SENTRY__`
26
- * @param obj (Optional) The global object on which to look for `__SENTRY__`, if not `GLOBAL_OBJ`'s return value
27
- * @returns the singleton
28
- */
29
- function getGlobalSingleton(name, creator, obj) {
30
- const gbl = (GLOBAL_OBJ) ;
31
- const __SENTRY__ = (gbl.__SENTRY__ = gbl.__SENTRY__ || {});
32
- const versionedCarrier = (__SENTRY__[SDK_VERSION] = __SENTRY__[SDK_VERSION] || {});
33
- return versionedCarrier[name] || (versionedCarrier[name] = creator());
34
- }
35
-
36
- /**
37
- * This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.
38
- *
39
- * ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
40
- */
41
- const DEBUG_BUILD = (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__);
42
-
43
- /** Prefix for logging strings */
44
- const PREFIX = 'Sentry Logger ';
45
-
46
- const CONSOLE_LEVELS = [
47
- 'debug',
48
- 'info',
49
- 'warn',
50
- 'error',
51
- 'log',
52
- 'assert',
53
- 'trace',
54
- ] ;
55
-
56
- /** This may be mutated by the console instrumentation. */
57
- const originalConsoleMethods
58
-
59
- = {};
60
-
61
- /** JSDoc */
62
-
63
- /**
64
- * Temporarily disable sentry console instrumentations.
65
- *
66
- * @param callback The function to run against the original `console` messages
67
- * @returns The results of the callback
68
- */
69
- function consoleSandbox(callback) {
70
- if (!('console' in GLOBAL_OBJ)) {
71
- return callback();
72
- }
73
-
74
- const console = GLOBAL_OBJ.console ;
75
- const wrappedFuncs = {};
76
-
77
- const wrappedLevels = Object.keys(originalConsoleMethods) ;
78
-
79
- // Restore all wrapped console methods
80
- wrappedLevels.forEach(level => {
81
- const originalConsoleMethod = originalConsoleMethods[level] ;
82
- wrappedFuncs[level] = console[level] ;
83
- console[level] = originalConsoleMethod;
84
- });
85
-
86
- try {
87
- return callback();
88
- } finally {
89
- // Revert restoration to wrapped state
90
- wrappedLevels.forEach(level => {
91
- console[level] = wrappedFuncs[level] ;
92
- });
93
- }
94
- }
95
-
96
- function makeLogger() {
97
- let enabled = false;
98
- const logger = {
99
- enable: () => {
100
- enabled = true;
101
- },
102
- disable: () => {
103
- enabled = false;
104
- },
105
- isEnabled: () => enabled,
106
- };
107
-
108
- if (DEBUG_BUILD) {
109
- CONSOLE_LEVELS.forEach(name => {
110
- logger[name] = (...args) => {
111
- if (enabled) {
112
- consoleSandbox(() => {
113
- GLOBAL_OBJ.console[name](`${PREFIX}[${name}]:`, ...args);
114
- });
115
- }
116
- };
117
- });
118
- } else {
119
- CONSOLE_LEVELS.forEach(name => {
120
- logger[name] = () => undefined;
121
- });
122
- }
123
-
124
- return logger ;
125
- }
126
-
127
- /**
128
- * This is a logger singleton which either logs things or no-ops if logging is not enabled.
129
- * The logger is a singleton on the carrier, to ensure that a consistent logger is used throughout the SDK.
130
- */
131
- const logger = getGlobalSingleton('logger', makeLogger);
132
-
133
- const defaultFunctionName = '<anonymous>';
134
-
135
- /**
136
- * Safely extract function name from itself
137
- */
138
- function getFunctionName(fn) {
139
- try {
140
- if (!fn || typeof fn !== 'function') {
141
- return defaultFunctionName;
142
- }
143
- return fn.name || defaultFunctionName;
144
- } catch (e) {
145
- // Just accessing custom props in some Selenium environments
146
- // can cause a "Permission denied" exception (see raven-js#495).
147
- return defaultFunctionName;
148
- }
149
- }
150
-
151
- // We keep the handlers globally
152
- const handlers = {};
153
- const instrumented = {};
154
-
155
- /** Add a handler function. */
156
- function addHandler(type, handler) {
157
- handlers[type] = handlers[type] || [];
158
- (handlers[type] ).push(handler);
159
- }
160
-
161
- /** Maybe run an instrumentation function, unless it was already called. */
162
- function maybeInstrument(type, instrumentFn) {
163
- if (!instrumented[type]) {
164
- instrumented[type] = true;
165
- try {
166
- instrumentFn();
167
- } catch (e) {
168
- DEBUG_BUILD && logger.error(`Error while instrumenting ${type}`, e);
169
- }
170
- }
171
- }
172
-
173
- /** Trigger handlers for a given instrumentation type. */
174
- function triggerHandlers(type, data) {
175
- const typeHandlers = handlers[type];
176
- if (!typeHandlers) {
177
- return;
178
- }
179
-
180
- for (const handler of typeHandlers) {
181
- try {
182
- handler(data);
183
- } catch (e) {
184
- DEBUG_BUILD &&
185
- logger.error(
186
- `Error while triggering instrumentation handler.\nType: ${type}\nName: ${getFunctionName(handler)}\nError:`,
187
- e,
188
- );
189
- }
190
- }
191
- }
192
-
193
- /**
194
- * An object that contains globally accessible properties and maintains a scope stack.
195
- * @hidden
196
- */
197
-
198
- /**
199
- * Returns the global shim registry.
200
- *
201
- * FIXME: This function is problematic, because despite always returning a valid Carrier,
202
- * it has an optional `__SENTRY__` property, which then in turn requires us to always perform an unnecessary check
203
- * at the call-site. We always access the carrier through this function, so we can guarantee that `__SENTRY__` is there.
204
- **/
205
- function getMainCarrier() {
206
- // This ensures a Sentry carrier exists
207
- getSentryCarrier(GLOBAL_OBJ);
208
- return GLOBAL_OBJ;
209
- }
210
-
211
- /** Will either get the existing sentry carrier, or create a new one. */
212
- function getSentryCarrier(carrier) {
213
- const __SENTRY__ = (carrier.__SENTRY__ = carrier.__SENTRY__ || {});
214
-
215
- // For now: First SDK that sets the .version property wins
216
- __SENTRY__.version = __SENTRY__.version || SDK_VERSION;
217
-
218
- // Intentionally populating and returning the version of "this" SDK instance
219
- // rather than what's set in .version so that "this" SDK always gets its carrier
220
- return (__SENTRY__[SDK_VERSION] = __SENTRY__[SDK_VERSION] || {});
221
- }
222
-
223
- // eslint-disable-next-line @typescript-eslint/unbound-method
224
- const objectToString = Object.prototype.toString;
225
- /**
226
- * Checks whether given value is an instance of the given built-in class.
227
- *
228
- * @param wat The value to be checked
229
- * @param className
230
- * @returns A boolean representing the result.
231
- */
232
- function isBuiltin(wat, className) {
233
- return objectToString.call(wat) === `[object ${className}]`;
234
- }
235
-
236
- /**
237
- * Checks whether given value's type is an object literal, or a class instance.
238
- * {@link isPlainObject}.
239
- *
240
- * @param wat A value to be checked.
241
- * @returns A boolean representing the result.
242
- */
243
- function isPlainObject(wat) {
244
- return isBuiltin(wat, 'Object');
245
- }
246
-
247
- /**
248
- * Checks whether given value has a then function.
249
- * @param wat A value to be checked.
250
- */
251
- function isThenable(wat) {
252
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
253
- return Boolean(wat && wat.then && typeof wat.then === 'function');
254
- }
255
-
256
- /**
257
- * Checks whether given value's type is a Vue ViewModel.
258
- *
259
- * @param wat A value to be checked.
260
- * @returns A boolean representing the result.
261
- */
262
- function isVueViewModel(wat) {
263
- // Not using Object.prototype.toString because in Vue 3 it would read the instance's Symbol(Symbol.toStringTag) property.
264
- return !!(typeof wat === 'object' && wat !== null && ((wat ).__isVue || (wat )._isVue));
265
- }
266
-
267
- /**
268
- * Join values in array
269
- * @param input array of values to be joined together
270
- * @param delimiter string to be placed in-between values
271
- * @returns Joined values
272
- */
273
- function safeJoin(input, delimiter) {
274
- if (!Array.isArray(input)) {
275
- return '';
276
- }
277
-
278
- const output = [];
279
- // eslint-disable-next-line @typescript-eslint/prefer-for-of
280
- for (let i = 0; i < input.length; i++) {
281
- const value = input[i];
282
- try {
283
- // This is a hack to fix a Vue3-specific bug that causes an infinite loop of
284
- // console warnings. This happens when a Vue template is rendered with
285
- // an undeclared variable, which we try to stringify, ultimately causing
286
- // Vue to issue another warning which repeats indefinitely.
287
- // see: https://github.com/getsentry/sentry-javascript/pull/8981
288
- if (isVueViewModel(value)) {
289
- output.push('[VueViewModel]');
290
- } else {
291
- output.push(String(value));
292
- }
293
- } catch (e) {
294
- output.push('[value cannot be serialized]');
295
- }
296
- }
297
-
298
- return output.join(delimiter);
299
- }
300
-
301
- /**
302
- * Replace a method in an object with a wrapped version of itself.
303
- *
304
- * @param source An object that contains a method to be wrapped.
305
- * @param name The name of the method to be wrapped.
306
- * @param replacementFactory A higher-order function that takes the original version of the given method and returns a
307
- * wrapped version. Note: The function returned by `replacementFactory` needs to be a non-arrow function, in order to
308
- * preserve the correct value of `this`, and the original method must be called using `origMethod.call(this, <other
309
- * args>)` or `origMethod.apply(this, [<other args>])` (rather than being called directly), again to preserve `this`.
310
- * @returns void
311
- */
312
- function fill(source, name, replacementFactory) {
313
- if (!(name in source)) {
314
- return;
315
- }
316
-
317
- const original = source[name] ;
318
- const wrapped = replacementFactory(original) ;
319
-
320
- // Make sure it's a function first, as we need to attach an empty prototype for `defineProperties` to work
321
- // otherwise it'll throw "TypeError: Object.defineProperties called on non-object"
322
- if (typeof wrapped === 'function') {
323
- markFunctionWrapped(wrapped, original);
324
- }
325
-
326
- try {
327
- source[name] = wrapped;
328
- } catch (e) {
329
- DEBUG_BUILD && logger.log(`Failed to replace method "${name}" in object`, source);
330
- }
331
- }
332
-
333
- /**
334
- * Defines a non-enumerable property on the given object.
335
- *
336
- * @param obj The object on which to set the property
337
- * @param name The name of the property to be set
338
- * @param value The value to which to set the property
339
- */
340
- function addNonEnumerableProperty(obj, name, value) {
341
- try {
342
- Object.defineProperty(obj, name, {
343
- // enumerable: false, // the default, so we can save on bundle size by not explicitly setting it
344
- value: value,
345
- writable: true,
346
- configurable: true,
347
- });
348
- } catch (o_O) {
349
- DEBUG_BUILD && logger.log(`Failed to add non-enumerable property "${name}" to object`, obj);
350
- }
351
- }
352
-
353
- /**
354
- * Remembers the original function on the wrapped function and
355
- * patches up the prototype.
356
- *
357
- * @param wrapped the wrapper function
358
- * @param original the original function that gets wrapped
359
- */
360
- function markFunctionWrapped(wrapped, original) {
361
- try {
362
- const proto = original.prototype || {};
363
- wrapped.prototype = original.prototype = proto;
364
- addNonEnumerableProperty(wrapped, '__sentry_original__', original);
365
- } catch (o_O) {} // eslint-disable-line no-empty
366
- }
367
-
368
- const ONE_SECOND_IN_MS = 1000;
369
-
370
- /**
371
- * A partial definition of the [Performance Web API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Performance}
372
- * for accessing a high-resolution monotonic clock.
373
- */
374
-
375
- /**
376
- * Returns a timestamp in seconds since the UNIX epoch using the Date API.
377
- *
378
- * TODO(v8): Return type should be rounded.
379
- */
380
- function dateTimestampInSeconds() {
381
- return Date.now() / ONE_SECOND_IN_MS;
382
- }
383
-
384
- /**
385
- * Returns a wrapper around the native Performance API browser implementation, or undefined for browsers that do not
386
- * support the API.
387
- *
388
- * Wrapping the native API works around differences in behavior from different browsers.
389
- */
390
- function createUnixTimestampInSecondsFunc() {
391
- const { performance } = GLOBAL_OBJ ;
392
- if (!performance || !performance.now) {
393
- return dateTimestampInSeconds;
394
- }
395
-
396
- // Some browser and environments don't have a timeOrigin, so we fallback to
397
- // using Date.now() to compute the starting time.
398
- const approxStartingTimeOrigin = Date.now() - performance.now();
399
- const timeOrigin = performance.timeOrigin == undefined ? approxStartingTimeOrigin : performance.timeOrigin;
400
-
401
- // performance.now() is a monotonic clock, which means it starts at 0 when the process begins. To get the current
402
- // wall clock time (actual UNIX timestamp), we need to add the starting time origin and the current time elapsed.
403
- //
404
- // TODO: This does not account for the case where the monotonic clock that powers performance.now() drifts from the
405
- // wall clock time, which causes the returned timestamp to be inaccurate. We should investigate how to detect and
406
- // correct for this.
407
- // See: https://github.com/getsentry/sentry-javascript/issues/2590
408
- // See: https://github.com/mdn/content/issues/4713
409
- // See: https://dev.to/noamr/when-a-millisecond-is-not-a-millisecond-3h6
410
- return () => {
411
- return (timeOrigin + performance.now()) / ONE_SECOND_IN_MS;
412
- };
413
- }
414
-
415
- /**
416
- * Returns a timestamp in seconds since the UNIX epoch using either the Performance or Date APIs, depending on the
417
- * availability of the Performance API.
418
- *
419
- * BUG: Note that because of how browsers implement the Performance API, the clock might stop when the computer is
420
- * asleep. This creates a skew between `dateTimestampInSeconds` and `timestampInSeconds`. The
421
- * skew can grow to arbitrary amounts like days, weeks or months.
422
- * See https://github.com/getsentry/sentry-javascript/issues/2590.
423
- */
424
- const timestampInSeconds = createUnixTimestampInSecondsFunc();
425
-
426
- /**
427
- * The number of milliseconds since the UNIX epoch. This value is only usable in a browser, and only when the
428
- * performance API is available.
429
- */
430
- (() => {
431
- // Unfortunately browsers may report an inaccurate time origin data, through either performance.timeOrigin or
432
- // performance.timing.navigationStart, which results in poor results in performance data. We only treat time origin
433
- // data as reliable if they are within a reasonable threshold of the current time.
434
-
435
- const { performance } = GLOBAL_OBJ ;
436
- if (!performance || !performance.now) {
437
- return undefined;
438
- }
439
-
440
- const threshold = 3600 * 1000;
441
- const performanceNow = performance.now();
442
- const dateNow = Date.now();
443
-
444
- // if timeOrigin isn't available set delta to threshold so it isn't used
445
- const timeOriginDelta = performance.timeOrigin
446
- ? Math.abs(performance.timeOrigin + performanceNow - dateNow)
447
- : threshold;
448
- const timeOriginIsReliable = timeOriginDelta < threshold;
449
-
450
- // While performance.timing.navigationStart is deprecated in favor of performance.timeOrigin, performance.timeOrigin
451
- // is not as widely supported. Namely, performance.timeOrigin is undefined in Safari as of writing.
452
- // Also as of writing, performance.timing is not available in Web Workers in mainstream browsers, so it is not always
453
- // a valid fallback. In the absence of an initial time provided by the browser, fallback to the current time from the
454
- // Date API.
455
- // eslint-disable-next-line deprecation/deprecation
456
- const navigationStart = performance.timing && performance.timing.navigationStart;
457
- const hasNavigationStart = typeof navigationStart === 'number';
458
- // if navigationStart isn't available set delta to threshold so it isn't used
459
- const navigationStartDelta = hasNavigationStart ? Math.abs(navigationStart + performanceNow - dateNow) : threshold;
460
- const navigationStartIsReliable = navigationStartDelta < threshold;
461
-
462
- if (timeOriginIsReliable || navigationStartIsReliable) {
463
- // Use the more reliable time origin
464
- if (timeOriginDelta <= navigationStartDelta) {
465
- return performance.timeOrigin;
466
- } else {
467
- return navigationStart;
468
- }
469
- }
470
- return dateNow;
471
- })();
472
-
473
- /**
474
- * UUID4 generator
475
- *
476
- * @returns string Generated UUID4.
477
- */
478
- function uuid4() {
479
- const gbl = GLOBAL_OBJ ;
480
- const crypto = gbl.crypto || gbl.msCrypto;
481
-
482
- let getRandomByte = () => Math.random() * 16;
483
- try {
484
- if (crypto && crypto.randomUUID) {
485
- return crypto.randomUUID().replace(/-/g, '');
486
- }
487
- if (crypto && crypto.getRandomValues) {
488
- getRandomByte = () => {
489
- // crypto.getRandomValues might return undefined instead of the typed array
490
- // in old Chromium versions (e.g. 23.0.1235.0 (151422))
491
- // However, `typedArray` is still filled in-place.
492
- // @see https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues#typedarray
493
- const typedArray = new Uint8Array(1);
494
- crypto.getRandomValues(typedArray);
495
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
496
- return typedArray[0];
497
- };
498
- }
499
- } catch (_) {
500
- // some runtimes can crash invoking crypto
501
- // https://github.com/getsentry/sentry-javascript/issues/8935
502
- }
503
-
504
- // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523
505
- // Concatenating the following numbers as strings results in '10000000100040008000100000000000'
506
- return (([1e7] ) + 1e3 + 4e3 + 8e3 + 1e11).replace(/[018]/g, c =>
507
- // eslint-disable-next-line no-bitwise
508
- ((c ) ^ ((getRandomByte() & 15) >> ((c ) / 4))).toString(16),
509
- );
510
- }
511
-
512
- function getFirstException(event) {
513
- return event.exception && event.exception.values ? event.exception.values[0] : undefined;
514
- }
515
-
516
- /**
517
- * Adds exception mechanism data to a given event. Uses defaults if the second parameter is not passed.
518
- *
519
- * @param event The event to modify.
520
- * @param newMechanism Mechanism data to add to the event.
521
- * @hidden
522
- */
523
- function addExceptionMechanism(event, newMechanism) {
524
- const firstException = getFirstException(event);
525
- if (!firstException) {
526
- return;
527
- }
528
-
529
- const defaultMechanism = { type: 'generic', handled: true };
530
- const currentMechanism = firstException.mechanism;
531
- firstException.mechanism = { ...defaultMechanism, ...currentMechanism, ...newMechanism };
532
-
533
- if (newMechanism && 'data' in newMechanism) {
534
- const mergedData = { ...(currentMechanism && currentMechanism.data), ...newMechanism.data };
535
- firstException.mechanism.data = mergedData;
536
- }
537
- }
538
-
539
- /* eslint-disable @typescript-eslint/explicit-function-return-type */
540
- /* eslint-disable @typescript-eslint/no-explicit-any */
541
-
542
- /** SyncPromise internal states */
543
- var States; (function (States) {
544
- /** Pending */
545
- const PENDING = 0; States[States["PENDING"] = PENDING] = "PENDING";
546
- /** Resolved / OK */
547
- const RESOLVED = 1; States[States["RESOLVED"] = RESOLVED] = "RESOLVED";
548
- /** Rejected / Error */
549
- const REJECTED = 2; States[States["REJECTED"] = REJECTED] = "REJECTED";
550
- })(States || (States = {}));
551
-
552
- /**
553
- * Updates a session object with the properties passed in the context.
554
- *
555
- * Note that this function mutates the passed object and returns void.
556
- * (Had to do this instead of returning a new and updated session because closing and sending a session
557
- * makes an update to the session after it was passed to the sending logic.
558
- * @see BaseClient.captureSession )
559
- *
560
- * @param session the `Session` to update
561
- * @param context the `SessionContext` holding the properties that should be updated in @param session
562
- */
563
- // eslint-disable-next-line complexity
564
- function updateSession(session, context = {}) {
565
- if (context.user) {
566
- if (!session.ipAddress && context.user.ip_address) {
567
- session.ipAddress = context.user.ip_address;
568
- }
569
-
570
- if (!session.did && !context.did) {
571
- session.did = context.user.id || context.user.email || context.user.username;
572
- }
573
- }
574
-
575
- session.timestamp = context.timestamp || timestampInSeconds();
576
-
577
- if (context.abnormal_mechanism) {
578
- session.abnormal_mechanism = context.abnormal_mechanism;
579
- }
580
-
581
- if (context.ignoreDuration) {
582
- session.ignoreDuration = context.ignoreDuration;
583
- }
584
- if (context.sid) {
585
- // Good enough uuid validation. — Kamil
586
- session.sid = context.sid.length === 32 ? context.sid : uuid4();
587
- }
588
- if (context.init !== undefined) {
589
- session.init = context.init;
590
- }
591
- if (!session.did && context.did) {
592
- session.did = `${context.did}`;
593
- }
594
- if (typeof context.started === 'number') {
595
- session.started = context.started;
596
- }
597
- if (session.ignoreDuration) {
598
- session.duration = undefined;
599
- } else if (typeof context.duration === 'number') {
600
- session.duration = context.duration;
601
- } else {
602
- const duration = session.timestamp - session.started;
603
- session.duration = duration >= 0 ? duration : 0;
604
- }
605
- if (context.release) {
606
- session.release = context.release;
607
- }
608
- if (context.environment) {
609
- session.environment = context.environment;
610
- }
611
- if (!session.ipAddress && context.ipAddress) {
612
- session.ipAddress = context.ipAddress;
613
- }
614
- if (!session.userAgent && context.userAgent) {
615
- session.userAgent = context.userAgent;
616
- }
617
- if (typeof context.errors === 'number') {
618
- session.errors = context.errors;
619
- }
620
- if (context.status) {
621
- session.status = context.status;
622
- }
623
- }
624
-
625
- /**
626
- * Generate a random, valid trace ID.
627
- */
628
- function generateTraceId() {
629
- return uuid4();
630
- }
631
-
632
- /**
633
- * Generate a random, valid span ID.
634
- */
635
- function generateSpanId() {
636
- return uuid4().substring(16);
637
- }
638
-
639
- /**
640
- * Shallow merge two objects.
641
- * Does not mutate the passed in objects.
642
- * Undefined/empty values in the merge object will overwrite existing values.
643
- *
644
- * By default, this merges 2 levels deep.
645
- */
646
- function merge(initialObj, mergeObj, levels = 2) {
647
- // If the merge value is not an object, or we have no merge levels left,
648
- // we just set the value to the merge value
649
- if (!mergeObj || typeof mergeObj !== 'object' || levels <= 0) {
650
- return mergeObj;
651
- }
652
-
653
- // If the merge object is an empty object, and the initial object is not undefined, we return the initial object
654
- if (initialObj && mergeObj && Object.keys(mergeObj).length === 0) {
655
- return initialObj;
656
- }
657
-
658
- // Clone object
659
- const output = { ...initialObj };
660
-
661
- // Merge values into output, resursively
662
- for (const key in mergeObj) {
663
- if (Object.prototype.hasOwnProperty.call(mergeObj, key)) {
664
- output[key] = merge(output[key], mergeObj[key], levels - 1);
665
- }
666
- }
667
-
668
- return output;
669
- }
670
-
671
- const SCOPE_SPAN_FIELD = '_sentrySpan';
672
-
673
- /**
674
- * Set the active span for a given scope.
675
- * NOTE: This should NOT be used directly, but is only used internally by the trace methods.
676
- */
677
- function _setSpanForScope(scope, span) {
678
- if (span) {
679
- addNonEnumerableProperty(scope , SCOPE_SPAN_FIELD, span);
680
- } else {
681
- // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
682
- delete (scope )[SCOPE_SPAN_FIELD];
683
- }
684
- }
685
-
686
- /**
687
- * Get the active span for a given scope.
688
- * NOTE: This should NOT be used directly, but is only used internally by the trace methods.
689
- */
690
- function _getSpanForScope(scope) {
691
- return scope[SCOPE_SPAN_FIELD];
692
- }
693
-
694
- /**
695
- * Default value for maximum number of breadcrumbs added to an event.
696
- */
697
- const DEFAULT_MAX_BREADCRUMBS = 100;
698
-
699
- /**
700
- * Holds additional event information.
701
- */
702
- class ScopeClass {
703
- /** Flag if notifying is happening. */
704
-
705
- /** Callback for client to receive scope changes. */
706
-
707
- /** Callback list that will be called during event processing. */
708
-
709
- /** Array of breadcrumbs. */
710
-
711
- /** User */
712
-
713
- /** Tags */
714
-
715
- /** Extra */
716
-
717
- /** Contexts */
718
-
719
- /** Attachments */
720
-
721
- /** Propagation Context for distributed tracing */
722
-
723
- /**
724
- * A place to stash data which is needed at some point in the SDK's event processing pipeline but which shouldn't get
725
- * sent to Sentry
726
- */
727
-
728
- /** Fingerprint */
729
-
730
- /** Severity */
731
-
732
- /**
733
- * Transaction Name
734
- *
735
- * IMPORTANT: The transaction name on the scope has nothing to do with root spans/transaction objects.
736
- * It's purpose is to assign a transaction to the scope that's added to non-transaction events.
737
- */
738
-
739
- /** Session */
740
-
741
- /** Request Mode Session Status */
742
- // eslint-disable-next-line deprecation/deprecation
743
-
744
- /** The client on this scope */
745
-
746
- /** Contains the last event id of a captured event. */
747
-
748
- // NOTE: Any field which gets added here should get added not only to the constructor but also to the `clone` method.
749
-
750
- constructor() {
751
- this._notifyingListeners = false;
752
- this._scopeListeners = [];
753
- this._eventProcessors = [];
754
- this._breadcrumbs = [];
755
- this._attachments = [];
756
- this._user = {};
757
- this._tags = {};
758
- this._extra = {};
759
- this._contexts = {};
760
- this._sdkProcessingMetadata = {};
761
- this._propagationContext = {
762
- traceId: generateTraceId(),
763
- spanId: generateSpanId(),
764
- };
765
- }
766
-
767
- /**
768
- * @inheritDoc
769
- */
770
- clone() {
771
- const newScope = new ScopeClass();
772
- newScope._breadcrumbs = [...this._breadcrumbs];
773
- newScope._tags = { ...this._tags };
774
- newScope._extra = { ...this._extra };
775
- newScope._contexts = { ...this._contexts };
776
- if (this._contexts.flags) {
777
- // We need to copy the `values` array so insertions on a cloned scope
778
- // won't affect the original array.
779
- newScope._contexts.flags = {
780
- values: [...this._contexts.flags.values],
781
- };
782
- }
783
-
784
- newScope._user = this._user;
785
- newScope._level = this._level;
786
- newScope._session = this._session;
787
- newScope._transactionName = this._transactionName;
788
- newScope._fingerprint = this._fingerprint;
789
- newScope._eventProcessors = [...this._eventProcessors];
790
- newScope._requestSession = this._requestSession;
791
- newScope._attachments = [...this._attachments];
792
- newScope._sdkProcessingMetadata = { ...this._sdkProcessingMetadata };
793
- newScope._propagationContext = { ...this._propagationContext };
794
- newScope._client = this._client;
795
- newScope._lastEventId = this._lastEventId;
796
-
797
- _setSpanForScope(newScope, _getSpanForScope(this));
798
-
799
- return newScope;
800
- }
801
-
802
- /**
803
- * @inheritDoc
804
- */
805
- setClient(client) {
806
- this._client = client;
807
- }
808
-
809
- /**
810
- * @inheritDoc
811
- */
812
- setLastEventId(lastEventId) {
813
- this._lastEventId = lastEventId;
814
- }
815
-
816
- /**
817
- * @inheritDoc
818
- */
819
- getClient() {
820
- return this._client ;
821
- }
822
-
823
- /**
824
- * @inheritDoc
825
- */
826
- lastEventId() {
827
- return this._lastEventId;
828
- }
829
-
830
- /**
831
- * @inheritDoc
832
- */
833
- addScopeListener(callback) {
834
- this._scopeListeners.push(callback);
835
- }
836
-
837
- /**
838
- * @inheritDoc
839
- */
840
- addEventProcessor(callback) {
841
- this._eventProcessors.push(callback);
842
- return this;
843
- }
844
-
845
- /**
846
- * @inheritDoc
847
- */
848
- setUser(user) {
849
- // If null is passed we want to unset everything, but still define keys,
850
- // so that later down in the pipeline any existing values are cleared.
851
- this._user = user || {
852
- email: undefined,
853
- id: undefined,
854
- ip_address: undefined,
855
- username: undefined,
856
- };
857
-
858
- if (this._session) {
859
- updateSession(this._session, { user });
860
- }
861
-
862
- this._notifyScopeListeners();
863
- return this;
864
- }
865
-
866
- /**
867
- * @inheritDoc
868
- */
869
- getUser() {
870
- return this._user;
871
- }
872
-
873
- /**
874
- * @inheritDoc
875
- */
876
- // eslint-disable-next-line deprecation/deprecation
877
- getRequestSession() {
878
- return this._requestSession;
879
- }
880
-
881
- /**
882
- * @inheritDoc
883
- */
884
- // eslint-disable-next-line deprecation/deprecation
885
- setRequestSession(requestSession) {
886
- this._requestSession = requestSession;
887
- return this;
888
- }
889
-
890
- /**
891
- * @inheritDoc
892
- */
893
- setTags(tags) {
894
- this._tags = {
895
- ...this._tags,
896
- ...tags,
897
- };
898
- this._notifyScopeListeners();
899
- return this;
900
- }
901
-
902
- /**
903
- * @inheritDoc
904
- */
905
- setTag(key, value) {
906
- this._tags = { ...this._tags, [key]: value };
907
- this._notifyScopeListeners();
908
- return this;
909
- }
910
-
911
- /**
912
- * @inheritDoc
913
- */
914
- setExtras(extras) {
915
- this._extra = {
916
- ...this._extra,
917
- ...extras,
918
- };
919
- this._notifyScopeListeners();
920
- return this;
921
- }
922
-
923
- /**
924
- * @inheritDoc
925
- */
926
- setExtra(key, extra) {
927
- this._extra = { ...this._extra, [key]: extra };
928
- this._notifyScopeListeners();
929
- return this;
930
- }
931
-
932
- /**
933
- * @inheritDoc
934
- */
935
- setFingerprint(fingerprint) {
936
- this._fingerprint = fingerprint;
937
- this._notifyScopeListeners();
938
- return this;
939
- }
940
-
941
- /**
942
- * @inheritDoc
943
- */
944
- setLevel(level) {
945
- this._level = level;
946
- this._notifyScopeListeners();
947
- return this;
948
- }
949
-
950
- /**
951
- * Sets the transaction name on the scope so that the name of e.g. taken server route or
952
- * the page location is attached to future events.
953
- *
954
- * IMPORTANT: Calling this function does NOT change the name of the currently active
955
- * root span. If you want to change the name of the active root span, use
956
- * `Sentry.updateSpanName(rootSpan, 'new name')` instead.
957
- *
958
- * By default, the SDK updates the scope's transaction name automatically on sensible
959
- * occasions, such as a page navigation or when handling a new request on the server.
960
- */
961
- setTransactionName(name) {
962
- this._transactionName = name;
963
- this._notifyScopeListeners();
964
- return this;
965
- }
966
-
967
- /**
968
- * @inheritDoc
969
- */
970
- setContext(key, context) {
971
- if (context === null) {
972
- // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
973
- delete this._contexts[key];
974
- } else {
975
- this._contexts[key] = context;
976
- }
977
-
978
- this._notifyScopeListeners();
979
- return this;
980
- }
981
-
982
- /**
983
- * @inheritDoc
984
- */
985
- setSession(session) {
986
- if (!session) {
987
- delete this._session;
988
- } else {
989
- this._session = session;
990
- }
991
- this._notifyScopeListeners();
992
- return this;
993
- }
994
-
995
- /**
996
- * @inheritDoc
997
- */
998
- getSession() {
999
- return this._session;
1000
- }
1001
-
1002
- /**
1003
- * @inheritDoc
1004
- */
1005
- update(captureContext) {
1006
- if (!captureContext) {
1007
- return this;
1008
- }
1009
-
1010
- const scopeToMerge = typeof captureContext === 'function' ? captureContext(this) : captureContext;
1011
-
1012
- const [scopeInstance, requestSession] =
1013
- scopeToMerge instanceof Scope
1014
- ? // eslint-disable-next-line deprecation/deprecation
1015
- [scopeToMerge.getScopeData(), scopeToMerge.getRequestSession()]
1016
- : isPlainObject(scopeToMerge)
1017
- ? [captureContext , (captureContext ).requestSession]
1018
- : [];
1019
-
1020
- const { tags, extra, user, contexts, level, fingerprint = [], propagationContext } = scopeInstance || {};
1021
-
1022
- this._tags = { ...this._tags, ...tags };
1023
- this._extra = { ...this._extra, ...extra };
1024
- this._contexts = { ...this._contexts, ...contexts };
1025
-
1026
- if (user && Object.keys(user).length) {
1027
- this._user = user;
1028
- }
1029
-
1030
- if (level) {
1031
- this._level = level;
1032
- }
1033
-
1034
- if (fingerprint.length) {
1035
- this._fingerprint = fingerprint;
1036
- }
1037
-
1038
- if (propagationContext) {
1039
- this._propagationContext = propagationContext;
1040
- }
1041
-
1042
- if (requestSession) {
1043
- this._requestSession = requestSession;
1044
- }
1045
-
1046
- return this;
1047
- }
1048
-
1049
- /**
1050
- * @inheritDoc
1051
- */
1052
- clear() {
1053
- // client is not cleared here on purpose!
1054
- this._breadcrumbs = [];
1055
- this._tags = {};
1056
- this._extra = {};
1057
- this._user = {};
1058
- this._contexts = {};
1059
- this._level = undefined;
1060
- this._transactionName = undefined;
1061
- this._fingerprint = undefined;
1062
- this._requestSession = undefined;
1063
- this._session = undefined;
1064
- _setSpanForScope(this, undefined);
1065
- this._attachments = [];
1066
- this.setPropagationContext({ traceId: generateTraceId() });
1067
-
1068
- this._notifyScopeListeners();
1069
- return this;
1070
- }
1071
-
1072
- /**
1073
- * @inheritDoc
1074
- */
1075
- addBreadcrumb(breadcrumb, maxBreadcrumbs) {
1076
- const maxCrumbs = typeof maxBreadcrumbs === 'number' ? maxBreadcrumbs : DEFAULT_MAX_BREADCRUMBS;
1077
-
1078
- // No data has been changed, so don't notify scope listeners
1079
- if (maxCrumbs <= 0) {
1080
- return this;
1081
- }
1082
-
1083
- const mergedBreadcrumb = {
1084
- timestamp: dateTimestampInSeconds(),
1085
- ...breadcrumb,
1086
- };
1087
-
1088
- this._breadcrumbs.push(mergedBreadcrumb);
1089
- if (this._breadcrumbs.length > maxCrumbs) {
1090
- this._breadcrumbs = this._breadcrumbs.slice(-maxCrumbs);
1091
- if (this._client) {
1092
- this._client.recordDroppedEvent('buffer_overflow', 'log_item');
1093
- }
1094
- }
1095
-
1096
- this._notifyScopeListeners();
1097
-
1098
- return this;
1099
- }
1100
-
1101
- /**
1102
- * @inheritDoc
1103
- */
1104
- getLastBreadcrumb() {
1105
- return this._breadcrumbs[this._breadcrumbs.length - 1];
1106
- }
1107
-
1108
- /**
1109
- * @inheritDoc
1110
- */
1111
- clearBreadcrumbs() {
1112
- this._breadcrumbs = [];
1113
- this._notifyScopeListeners();
1114
- return this;
1115
- }
1116
-
1117
- /**
1118
- * @inheritDoc
1119
- */
1120
- addAttachment(attachment) {
1121
- this._attachments.push(attachment);
1122
- return this;
1123
- }
1124
-
1125
- /**
1126
- * @inheritDoc
1127
- */
1128
- clearAttachments() {
1129
- this._attachments = [];
1130
- return this;
1131
- }
1132
-
1133
- /** @inheritDoc */
1134
- getScopeData() {
1135
- return {
1136
- breadcrumbs: this._breadcrumbs,
1137
- attachments: this._attachments,
1138
- contexts: this._contexts,
1139
- tags: this._tags,
1140
- extra: this._extra,
1141
- user: this._user,
1142
- level: this._level,
1143
- fingerprint: this._fingerprint || [],
1144
- eventProcessors: this._eventProcessors,
1145
- propagationContext: this._propagationContext,
1146
- sdkProcessingMetadata: this._sdkProcessingMetadata,
1147
- transactionName: this._transactionName,
1148
- span: _getSpanForScope(this),
1149
- };
1150
- }
1151
-
1152
- /**
1153
- * @inheritDoc
1154
- */
1155
- setSDKProcessingMetadata(newData) {
1156
- this._sdkProcessingMetadata = merge(this._sdkProcessingMetadata, newData, 2);
1157
- return this;
1158
- }
1159
-
1160
- /**
1161
- * @inheritDoc
1162
- */
1163
- setPropagationContext(
1164
- context,
1165
- ) {
1166
- this._propagationContext = {
1167
- // eslint-disable-next-line deprecation/deprecation
1168
- spanId: generateSpanId(),
1169
- ...context,
1170
- };
1171
- return this;
1172
- }
1173
-
1174
- /**
1175
- * @inheritDoc
1176
- */
1177
- getPropagationContext() {
1178
- return this._propagationContext;
1179
- }
1180
-
1181
- /**
1182
- * @inheritDoc
1183
- */
1184
- captureException(exception, hint) {
1185
- const eventId = hint && hint.event_id ? hint.event_id : uuid4();
1186
-
1187
- if (!this._client) {
1188
- logger.warn('No client configured on scope - will not capture exception!');
1189
- return eventId;
1190
- }
1191
-
1192
- const syntheticException = new Error('Sentry syntheticException');
1193
-
1194
- this._client.captureException(
1195
- exception,
1196
- {
1197
- originalException: exception,
1198
- syntheticException,
1199
- ...hint,
1200
- event_id: eventId,
1201
- },
1202
- this,
1203
- );
1204
-
1205
- return eventId;
1206
- }
1207
-
1208
- /**
1209
- * @inheritDoc
1210
- */
1211
- captureMessage(message, level, hint) {
1212
- const eventId = hint && hint.event_id ? hint.event_id : uuid4();
1213
-
1214
- if (!this._client) {
1215
- logger.warn('No client configured on scope - will not capture message!');
1216
- return eventId;
1217
- }
1218
-
1219
- const syntheticException = new Error(message);
1220
-
1221
- this._client.captureMessage(
1222
- message,
1223
- level,
1224
- {
1225
- originalException: message,
1226
- syntheticException,
1227
- ...hint,
1228
- event_id: eventId,
1229
- },
1230
- this,
1231
- );
1232
-
1233
- return eventId;
1234
- }
1235
-
1236
- /**
1237
- * @inheritDoc
1238
- */
1239
- captureEvent(event, hint) {
1240
- const eventId = hint && hint.event_id ? hint.event_id : uuid4();
1241
-
1242
- if (!this._client) {
1243
- logger.warn('No client configured on scope - will not capture event!');
1244
- return eventId;
1245
- }
1246
-
1247
- this._client.captureEvent(event, { ...hint, event_id: eventId }, this);
1248
-
1249
- return eventId;
1250
- }
1251
-
1252
- /**
1253
- * This will be called on every set call.
1254
- */
1255
- _notifyScopeListeners() {
1256
- // We need this check for this._notifyingListeners to be able to work on scope during updates
1257
- // If this check is not here we'll produce endless recursion when something is done with the scope
1258
- // during the callback.
1259
- if (!this._notifyingListeners) {
1260
- this._notifyingListeners = true;
1261
- this._scopeListeners.forEach(callback => {
1262
- callback(this);
1263
- });
1264
- this._notifyingListeners = false;
1265
- }
1266
- }
1267
- }
1268
-
1269
- /**
1270
- * Holds additional event information.
1271
- */
1272
- const Scope = ScopeClass;
1273
-
1274
- /** Get the default current scope. */
1275
- function getDefaultCurrentScope() {
1276
- return getGlobalSingleton('defaultCurrentScope', () => new Scope());
1277
- }
1278
-
1279
- /** Get the default isolation scope. */
1280
- function getDefaultIsolationScope() {
1281
- return getGlobalSingleton('defaultIsolationScope', () => new Scope());
1282
- }
1283
-
1284
- /**
1285
- * This is an object that holds a stack of scopes.
1286
- */
1287
- class AsyncContextStack {
1288
-
1289
- constructor(scope, isolationScope) {
1290
- let assignedScope;
1291
- if (!scope) {
1292
- assignedScope = new Scope();
1293
- } else {
1294
- assignedScope = scope;
1295
- }
1296
-
1297
- let assignedIsolationScope;
1298
- if (!isolationScope) {
1299
- assignedIsolationScope = new Scope();
1300
- } else {
1301
- assignedIsolationScope = isolationScope;
1302
- }
1303
-
1304
- // scope stack for domains or the process
1305
- this._stack = [{ scope: assignedScope }];
1306
- this._isolationScope = assignedIsolationScope;
1307
- }
1308
-
1309
- /**
1310
- * Fork a scope for the stack.
1311
- */
1312
- withScope(callback) {
1313
- const scope = this._pushScope();
1314
-
1315
- let maybePromiseResult;
1316
- try {
1317
- maybePromiseResult = callback(scope);
1318
- } catch (e) {
1319
- this._popScope();
1320
- throw e;
1321
- }
1322
-
1323
- if (isThenable(maybePromiseResult)) {
1324
- // @ts-expect-error - isThenable returns the wrong type
1325
- return maybePromiseResult.then(
1326
- res => {
1327
- this._popScope();
1328
- return res;
1329
- },
1330
- e => {
1331
- this._popScope();
1332
- throw e;
1333
- },
1334
- );
1335
- }
1336
-
1337
- this._popScope();
1338
- return maybePromiseResult;
1339
- }
1340
-
1341
- /**
1342
- * Get the client of the stack.
1343
- */
1344
- getClient() {
1345
- return this.getStackTop().client ;
1346
- }
1347
-
1348
- /**
1349
- * Returns the scope of the top stack.
1350
- */
1351
- getScope() {
1352
- return this.getStackTop().scope;
1353
- }
1354
-
1355
- /**
1356
- * Get the isolation scope for the stack.
1357
- */
1358
- getIsolationScope() {
1359
- return this._isolationScope;
1360
- }
1361
-
1362
- /**
1363
- * Returns the topmost scope layer in the order domain > local > process.
1364
- */
1365
- getStackTop() {
1366
- return this._stack[this._stack.length - 1] ;
1367
- }
1368
-
1369
- /**
1370
- * Push a scope to the stack.
1371
- */
1372
- _pushScope() {
1373
- // We want to clone the content of prev scope
1374
- const scope = this.getScope().clone();
1375
- this._stack.push({
1376
- client: this.getClient(),
1377
- scope,
1378
- });
1379
- return scope;
1380
- }
1381
-
1382
- /**
1383
- * Pop a scope from the stack.
1384
- */
1385
- _popScope() {
1386
- if (this._stack.length <= 1) return false;
1387
- return !!this._stack.pop();
1388
- }
1389
- }
1390
-
1391
- /**
1392
- * Get the global async context stack.
1393
- * This will be removed during the v8 cycle and is only here to make migration easier.
1394
- */
1395
- function getAsyncContextStack() {
1396
- const registry = getMainCarrier();
1397
- const sentry = getSentryCarrier(registry);
1398
-
1399
- return (sentry.stack = sentry.stack || new AsyncContextStack(getDefaultCurrentScope(), getDefaultIsolationScope()));
1400
- }
1401
-
1402
- function withScope$1(callback) {
1403
- return getAsyncContextStack().withScope(callback);
1404
- }
1405
-
1406
- function withSetScope(scope, callback) {
1407
- const stack = getAsyncContextStack() ;
1408
- return stack.withScope(() => {
1409
- stack.getStackTop().scope = scope;
1410
- return callback(scope);
1411
- });
1412
- }
1413
-
1414
- function withIsolationScope(callback) {
1415
- return getAsyncContextStack().withScope(() => {
1416
- return callback(getAsyncContextStack().getIsolationScope());
1417
- });
1418
- }
1419
-
1420
- /**
1421
- * Get the stack-based async context strategy.
1422
- */
1423
- function getStackAsyncContextStrategy() {
1424
- return {
1425
- withIsolationScope,
1426
- withScope: withScope$1,
1427
- withSetScope,
1428
- withSetIsolationScope: (_isolationScope, callback) => {
1429
- return withIsolationScope(callback);
1430
- },
1431
- getCurrentScope: () => getAsyncContextStack().getScope(),
1432
- getIsolationScope: () => getAsyncContextStack().getIsolationScope(),
1433
- };
1434
- }
1435
-
1436
- /**
1437
- * Get the current async context strategy.
1438
- * If none has been setup, the default will be used.
1439
- */
1440
- function getAsyncContextStrategy(carrier) {
1441
- const sentry = getSentryCarrier(carrier);
1442
-
1443
- if (sentry.acs) {
1444
- return sentry.acs;
1445
- }
1446
-
1447
- // Otherwise, use the default one (stack)
1448
- return getStackAsyncContextStrategy();
1449
- }
1450
-
1451
- /**
1452
- * Get the currently active scope.
1453
- */
1454
- function getCurrentScope() {
1455
- const carrier = getMainCarrier();
1456
- const acs = getAsyncContextStrategy(carrier);
1457
- return acs.getCurrentScope();
1458
- }
1459
-
1460
- /**
1461
- * Creates a new scope with and executes the given operation within.
1462
- * The scope is automatically removed once the operation
1463
- * finishes or throws.
1464
- */
1465
-
1466
- /**
1467
- * Either creates a new active scope, or sets the given scope as active scope in the given callback.
1468
- */
1469
- function withScope(
1470
- ...rest
1471
- ) {
1472
- const carrier = getMainCarrier();
1473
- const acs = getAsyncContextStrategy(carrier);
1474
-
1475
- // If a scope is defined, we want to make this the active scope instead of the default one
1476
- if (rest.length === 2) {
1477
- const [scope, callback] = rest;
1478
-
1479
- if (!scope) {
1480
- return acs.withScope(callback);
1481
- }
1482
-
1483
- return acs.withSetScope(scope, callback);
1484
- }
1485
-
1486
- return acs.withScope(rest[0]);
1487
- }
1488
-
1489
- /**
1490
- * Get the currently active client.
1491
- */
1492
- function getClient() {
1493
- return getCurrentScope().getClient();
1494
- }
1495
-
1496
- /**
1497
- * Parse either an `EventHint` directly, or convert a `CaptureContext` to an `EventHint`.
1498
- * This is used to allow to update method signatures that used to accept a `CaptureContext` but should now accept an `EventHint`.
1499
- */
1500
- function parseEventHintOrCaptureContext(
1501
- hint,
1502
- ) {
1503
- if (!hint) {
1504
- return undefined;
1505
- }
1506
-
1507
- // If you pass a Scope or `() => Scope` as CaptureContext, we just return this as captureContext
1508
- if (hintIsScopeOrFunction(hint)) {
1509
- return { captureContext: hint };
1510
- }
1511
-
1512
- if (hintIsScopeContext(hint)) {
1513
- return {
1514
- captureContext: hint,
1515
- };
1516
- }
1517
-
1518
- return hint;
1519
- }
1520
-
1521
- function hintIsScopeOrFunction(
1522
- hint,
1523
- ) {
1524
- return hint instanceof Scope || typeof hint === 'function';
1525
- }
1526
-
1527
- const captureContextKeys = [
1528
- 'user',
1529
- 'level',
1530
- 'extra',
1531
- 'contexts',
1532
- 'tags',
1533
- 'fingerprint',
1534
- 'requestSession',
1535
- 'propagationContext',
1536
- ] ;
1537
-
1538
- function hintIsScopeContext(hint) {
1539
- return Object.keys(hint).some(key => captureContextKeys.includes(key ));
1540
- }
1541
-
1542
- /**
1543
- * Captures an exception event and sends it to Sentry.
1544
- *
1545
- * @param exception The exception to capture.
1546
- * @param hint Optional additional data to attach to the Sentry event.
1547
- * @returns the id of the captured Sentry event.
1548
- */
1549
- function captureException(exception, hint) {
1550
- return getCurrentScope().captureException(exception, parseEventHintOrCaptureContext(hint));
1551
- }
1552
-
1553
- /**
1554
- * Captures a message event and sends it to Sentry.
1555
- *
1556
- * @param message The message to send to Sentry.
1557
- * @param captureContext Define the level of the message or pass in additional data to attach to the message.
1558
- * @returns the id of the captured message.
1559
- */
1560
- function captureMessage(message, captureContext) {
1561
- // This is necessary to provide explicit scopes upgrade, without changing the original
1562
- // arity of the `captureMessage(message, level)` method.
1563
- const level = typeof captureContext === 'string' ? captureContext : undefined;
1564
- const context = typeof captureContext !== 'string' ? { captureContext } : undefined;
1565
- return getCurrentScope().captureMessage(message, level, context);
1566
- }
1567
-
1568
- /**
1569
- * Define an integration function that can be used to create an integration instance.
1570
- * Note that this by design hides the implementation details of the integration, as they are considered internal.
1571
- */
1572
- function defineIntegration(fn) {
1573
- return fn;
1574
- }
1575
-
1576
- /**
1577
- * Add an instrumentation handler for when a console.xxx method is called.
1578
- *
1579
- * Use at your own risk, this might break without changelog notice, only used internally.
1580
- * @hidden
1581
- */
1582
- function addConsoleInstrumentationHandler(handler) {
1583
- const type = 'console';
1584
- addHandler(type, handler);
1585
- maybeInstrument(type, instrumentConsole);
1586
- }
1587
-
1588
- function instrumentConsole() {
1589
- if (!('console' in GLOBAL_OBJ)) {
1590
- return;
1591
- }
1592
-
1593
- CONSOLE_LEVELS.forEach(function (level) {
1594
- if (!(level in GLOBAL_OBJ.console)) {
1595
- return;
1596
- }
1597
-
1598
- fill(GLOBAL_OBJ.console, level, function (originalConsoleMethod) {
1599
- originalConsoleMethods[level] = originalConsoleMethod;
1600
-
1601
- return function (...args) {
1602
- const handlerData = { args, level };
1603
- triggerHandlers('console', handlerData);
1604
-
1605
- const log = originalConsoleMethods[level];
1606
- log && log.apply(GLOBAL_OBJ.console, args);
1607
- };
1608
- });
1609
- });
1610
- }
1611
-
1612
- /**
1613
- * @deprecated This variable has been deprecated and will be removed in the next major version.
1614
- */
1615
-
1616
- /**
1617
- * Converts a string-based level into a `SeverityLevel`, normalizing it along the way.
1618
- *
1619
- * @param level String representation of desired `SeverityLevel`.
1620
- * @returns The `SeverityLevel` corresponding to the given string, or 'log' if the string isn't a valid level.
1621
- */
1622
- function severityLevelFromString(level) {
1623
- return (
1624
- level === 'warn' ? 'warning' : ['fatal', 'error', 'warning', 'log', 'info', 'debug'].includes(level) ? level : 'log'
1625
- ) ;
1626
- }
1627
-
1628
- const INTEGRATION_NAME = 'CaptureConsole';
1629
-
1630
- const _captureConsoleIntegration = ((options = {}) => {
1631
- const levels = options.levels || CONSOLE_LEVELS;
1632
- // TODO(v9): Flip default value to `true`
1633
- const handled = !!options.handled;
1634
-
1635
- return {
1636
- name: INTEGRATION_NAME,
1637
- setup(client) {
1638
- if (!('console' in GLOBAL_OBJ)) {
1639
- return;
1640
- }
1641
-
1642
- addConsoleInstrumentationHandler(({ args, level }) => {
1643
- if (getClient() !== client || !levels.includes(level)) {
1644
- return;
1645
- }
1646
-
1647
- consoleHandler(args, level, handled);
1648
- });
1649
- },
1650
- };
1651
- }) ;
1652
-
1653
- /**
1654
- * Send Console API calls as Sentry Events.
1655
- */
1656
- const captureConsoleIntegration = defineIntegration(_captureConsoleIntegration);
1657
-
1658
- function consoleHandler(args, level, handled) {
1659
- const captureContext = {
1660
- level: severityLevelFromString(level),
1661
- extra: {
1662
- arguments: args,
1663
- },
1664
- };
1665
-
1666
- withScope(scope => {
1667
- scope.addEventProcessor(event => {
1668
- event.logger = 'console';
1669
-
1670
- addExceptionMechanism(event, {
1671
- handled,
1672
- type: 'console',
1673
- });
1674
-
1675
- return event;
1676
- });
1677
-
1678
- if (level === 'assert') {
1679
- if (!args[0]) {
1680
- const message = `Assertion failed: ${safeJoin(args.slice(1), ' ') || 'console.assert'}`;
1681
- scope.setExtra('arguments', args.slice(1));
1682
- captureMessage(message, captureContext);
1683
- }
1684
- return;
1685
- }
1686
-
1687
- const error = args.find(arg => arg instanceof Error);
1688
- if (error) {
1689
- captureException(error, captureContext);
1690
- return;
1691
- }
1692
-
1693
- const message = safeJoin(args, ' ');
1694
- captureMessage(message, captureContext);
1695
- });
1696
- }
1697
-
1698
- /**
1699
- * Initialize Sentry for React Native.
1700
- *
1701
- * @param {InitOptionsRN} options
1702
- * @return {void}
1703
- */
1704
- const initSentry = options => {
1705
- let shouldSendToSentry = options?.requiredEnvForSendToSentry?.includes(options.env);
1706
- let ignoreErrors = [/StallTracking/];
1707
- if (options?.ignoreErrorsOptions) {
1708
- ignoreErrors = ignoreErrors.concat(options.ignoreErrorsOptions);
1709
- }
1710
- if (options?.options?.ignoreErrors) {
1711
- ignoreErrors = ignoreErrors.concat(options.options.ignoreErrors);
1712
- delete options.options.ignoreErrors;
1713
- }
1714
- let integrations = [];
1715
- if (options?.httpClientIntegrationOptions?.failedRequestStatusCodes && options?.httpClientIntegrationOptions?.failedRequestTargets) {
1716
- integrations.push(Sentry.httpClientIntegration({
1717
- failedRequestStatusCodes: options.httpClientIntegrationOptions.failedRequestStatusCodes,
1718
- failedRequestTargets: options.httpClientIntegrationOptions.failedRequestTargets
1719
- }));
1720
- }
1721
- if (options?.captureConsoleIntegrationOptions?.levels) {
1722
- integrations.push(captureConsoleIntegration({
1723
- levels: options.captureConsoleIntegrationOptions.levels
1724
- }));
1725
- }
1726
- if (options?.options?.hasOwnProperty('integrations')) {
1727
- options.options.integrations = [...options.options.integrations, ...integrations];
1728
- } else {
1729
- options.options = options.options || {};
1730
- options.options.integrations = integrations;
1731
- }
1732
- let sentryOptions = {
1733
- dsn: options.dsn,
1734
- debug: options.debug,
1735
- environment: options.env,
1736
- ignoreErrors: ignoreErrors,
1737
- sampleRate: 1.0,
1738
- maxBreadcrumbs: 50,
1739
- autoSessionTracking: true,
1740
- attachScreenshot: true,
1741
- enableCaptureFailedRequests: true,
1742
- enableTracing: true,
1743
- tracesSampleRate: 1.0,
1744
- enableNative: true,
1745
- autoInitializeNativeSdk: true,
1746
- enableNativeCrashHandling: true,
1747
- enableNativeNagger: true,
1748
- enableAutoSessionTracking: true,
1749
- enableNdkScopeSync: true,
1750
- attachThreads: true,
1751
- enableAutoPerformanceTracing: true,
1752
- enableWatchdogTerminationTracking: true,
1753
- enableAppHangTracking: true,
1754
- appHangTimeoutInterval: 5,
1755
- sendDefaultPii: true,
1756
- beforeSend: event => {
1757
- if (event?.message?.includes('StallTracking') || !shouldSendToSentry) {
1758
- return null;
1759
- }
1760
- return event;
1761
- }
1762
- };
1763
- if (options?.release) {
1764
- sentryOptions.release = options.release;
1765
- }
1766
- if (options?.beforeSend) {
1767
- sentryOptions.beforeSend = options.beforeSend;
1768
- }
1769
- if (options?.options) {
1770
- sentryOptions = {
1771
- ...sentryOptions,
1772
- ...options.options
1773
- };
1774
- }
1775
- Sentry.init(sentryOptions);
1776
- };
1777
- /**
1778
- * Record additional http data for Sentry.
1779
- *
1780
- * @param {any | null} config
1781
- * @param {any | null} request
1782
- * @param {any | null} response
1783
- * @return {void}
1784
- */
1785
- const recordAdditionalSentryHttp = (config, request, response) => {
1786
- recordSentryHttp(Sentry, config, request, response);
1787
- };
1788
-
1789
- export { initSentry as i, recordAdditionalSentryHttp as r };
1790
- //# sourceMappingURL=ReactNative-B4gt8nBr.js.map