|
1 | 1 | /* eslint-disable @typescript-eslint/no-explicit-any */ |
2 | | -import { Event, Integration, StackFrame, WrappedFunction } from '@sentry/types'; |
| 2 | +import { Event, StackFrame } from '@sentry/types'; |
3 | 3 |
|
4 | | -import { isNodeEnv } from './node'; |
| 4 | +import { getGlobalObject } from './global'; |
5 | 5 | import { snipLine } from './string'; |
6 | 6 |
|
7 | | -/** Internal */ |
8 | | -interface SentryGlobal { |
9 | | - Sentry?: { |
10 | | - Integrations?: Integration[]; |
11 | | - }; |
12 | | - SENTRY_ENVIRONMENT?: string; |
13 | | - SENTRY_DSN?: string; |
14 | | - SENTRY_RELEASE?: { |
15 | | - id?: string; |
16 | | - }; |
17 | | - __SENTRY__: { |
18 | | - globalEventProcessors: any; |
19 | | - hub: any; |
20 | | - logger: any; |
21 | | - }; |
22 | | -} |
23 | | - |
24 | | -const fallbackGlobalObject = {}; |
25 | | - |
26 | | -/** |
27 | | - * Safely get global scope object |
28 | | - * |
29 | | - * @returns Global scope object |
30 | | - */ |
31 | | -export function getGlobalObject<T>(): T & SentryGlobal { |
32 | | - return (isNodeEnv() |
33 | | - ? global |
34 | | - : typeof window !== 'undefined' // eslint-disable-line no-restricted-globals |
35 | | - ? window // eslint-disable-line no-restricted-globals |
36 | | - : typeof self !== 'undefined' |
37 | | - ? self |
38 | | - : fallbackGlobalObject) as T & SentryGlobal; |
39 | | -} |
40 | | - |
41 | 7 | /** |
42 | 8 | * Extended Window interface that allows for Crypto API usage in IE browsers |
43 | 9 | */ |
@@ -143,44 +109,6 @@ export function getEventDescription(event: Event): string { |
143 | 109 | return event.event_id || '<unknown>'; |
144 | 110 | } |
145 | 111 |
|
146 | | -/** JSDoc */ |
147 | | -interface ExtensibleConsole extends Console { |
148 | | - [key: string]: any; |
149 | | -} |
150 | | - |
151 | | -/** JSDoc */ |
152 | | -export function consoleSandbox(callback: () => any): any { |
153 | | - const global = getGlobalObject<Window>(); |
154 | | - const levels = ['debug', 'info', 'warn', 'error', 'log', 'assert']; |
155 | | - |
156 | | - if (!('console' in global)) { |
157 | | - return callback(); |
158 | | - } |
159 | | - |
160 | | - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access |
161 | | - const originalConsole = (global as any).console as ExtensibleConsole; |
162 | | - const wrappedLevels: { [key: string]: any } = {}; |
163 | | - |
164 | | - // Restore all wrapped console methods |
165 | | - levels.forEach(level => { |
166 | | - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access |
167 | | - if (level in (global as any).console && (originalConsole[level] as WrappedFunction).__sentry_original__) { |
168 | | - wrappedLevels[level] = originalConsole[level] as WrappedFunction; |
169 | | - originalConsole[level] = (originalConsole[level] as WrappedFunction).__sentry_original__; |
170 | | - } |
171 | | - }); |
172 | | - |
173 | | - // Perform callback manipulations |
174 | | - const result = callback(); |
175 | | - |
176 | | - // Revert restoration to wrapped state |
177 | | - Object.keys(wrappedLevels).forEach(level => { |
178 | | - originalConsole[level] = wrappedLevels[level]; |
179 | | - }); |
180 | | - |
181 | | - return result; |
182 | | -} |
183 | | - |
184 | 112 | /** |
185 | 113 | * Adds exception values, type and value to an synthetic Exception. |
186 | 114 | * @param event The event to modify. |
@@ -223,18 +151,6 @@ export function addExceptionMechanism( |
223 | 151 | } |
224 | 152 | } |
225 | 153 |
|
226 | | -/** |
227 | | - * A safe form of location.href |
228 | | - */ |
229 | | -export function getLocationHref(): string { |
230 | | - const global = getGlobalObject<Window>(); |
231 | | - try { |
232 | | - return global.document.location.href; |
233 | | - } catch (oO) { |
234 | | - return ''; |
235 | | - } |
236 | | -} |
237 | | - |
238 | 154 | // https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string |
239 | 155 | const SEMVER_REGEXP = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/; |
240 | 156 |
|
|
0 commit comments