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GAAG,CAAC,iBAAiB,CAAQ,CAAC;KACrD;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAjBD,8CAiBC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { ExtendedError, WrappedFunction } from '@sentry/types';\n\nimport { htmlTreeAsString } from './browser';\nimport { isElement, isError, isEvent, isInstanceOf, isPlainObject, isPrimitive, isSyntheticEvent } from './is';\nimport { Memo } from './memo';\nimport { getFunctionName } from './stacktrace';\nimport { truncate } from './string';\n\n/**\n * Replace a method in an object with a wrapped version of itself.\n *\n * @param source An object that contains a method to be wrapped.\n * @param name The name of the method to be wrapped.\n * @param replacementFactory A higher-order function that takes the original version of the given method and returns a\n * wrapped version. Note: The function returned by `replacementFactory` needs to be a non-arrow function, in order to\n * preserve the correct value of `this`, and the original method must be called using `origMethod.call(this, <other\n * args>)` or `origMethod.apply(this, [<other args>])` (rather than being called directly), again to preserve `this`.\n * @returns void\n */\nexport function fill(source: { [key: string]: any }, name: string, replacementFactory: (...args: any[]) => any): void {\n if (!(name in source)) {\n return;\n }\n\n const original = source[name] as () => any;\n const wrapped = replacementFactory(original) as WrappedFunction;\n\n // Make sure it's a function first, as we need to attach an empty prototype for `defineProperties` to work\n // otherwise it'll throw \"TypeError: Object.defineProperties called on non-object\"\n if (typeof wrapped === 'function') {\n try {\n wrapped.prototype = wrapped.prototype || {};\n Object.defineProperties(wrapped, {\n __sentry_original__: {\n enumerable: false,\n value: original,\n },\n });\n } catch (_Oo) {\n // This can throw if multiple fill happens on a global object like XMLHttpRequest\n // Fixes https://github.com/getsentry/sentry-javascript/issues/2043\n }\n }\n\n source[name] = wrapped;\n}\n\n/**\n * Encodes given object into url-friendly format\n *\n * @param object An object that contains serializable values\n * @returns string Encoded\n */\nexport function urlEncode(object: { [key: string]: any }): string {\n return Object.keys(object)\n .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(object[key])}`)\n .join('&');\n}\n\n/**\n * Transforms any object into an object literal with all its attributes\n * attached to it.\n *\n * @param value Initial source that we have to transform in order for it to be usable by the serializer\n */\nfunction getWalkSource(\n value: any,\n): {\n [key: string]: any;\n} {\n if (isError(value)) {\n const error = value as ExtendedError;\n const err: {\n [key: string]: any;\n stack: string | undefined;\n message: string;\n name: string;\n } = {\n message: error.message,\n name: error.name,\n stack: error.stack,\n };\n\n for (const i in error) {\n if (Object.prototype.hasOwnProperty.call(error, i)) {\n err[i] = error[i];\n }\n }\n\n return err;\n }\n\n if (isEvent(value)) {\n /**\n * Event-like interface that's usable in browser and node\n */\n interface SimpleEvent {\n [key: string]: unknown;\n type: string;\n target?: unknown;\n currentTarget?: unknown;\n }\n\n const event = value as SimpleEvent;\n\n const source: {\n [key: string]: any;\n } = {};\n\n // Accessing event attributes can throw (see https://github.com/getsentry/sentry-javascript/issues/768 and\n // https://github.com/getsentry/sentry-javascript/issues/838), but accessing `type` hasn't been wrapped in a\n // try-catch in at least two years and no one's complained, so that's likely not an issue anymore\n source.type = event.type;\n\n try {\n source.target = isElement(event.target)\n ? htmlTreeAsString(event.target)\n : Object.prototype.toString.call(event.target);\n } catch (_oO) {\n source.target = '<unknown>';\n }\n\n try {\n source.currentTarget = isElement(event.currentTarget)\n ? htmlTreeAsString(event.currentTarget)\n : Object.prototype.toString.call(event.currentTarget);\n } catch (_oO) {\n source.currentTarget = '<unknown>';\n }\n\n if (typeof CustomEvent !== 'undefined' && isInstanceOf(value, CustomEvent)) {\n source.detail = event.detail;\n }\n\n for (const attr in event) {\n if (Object.prototype.hasOwnProperty.call(event, attr)) {\n source[attr] = event[attr];\n }\n }\n\n return source;\n }\n\n return value as {\n [key: string]: any;\n };\n}\n\n/** Calculates bytes size of input string */\nfunction utf8Length(value: string): number {\n // eslint-disable-next-line no-bitwise\n return ~-encodeURI(value).split(/%..|./).length;\n}\n\n/** Calculates bytes size of input object */\nfunction jsonSize(value: any): number {\n return utf8Length(JSON.stringify(value));\n}\n\n/** JSDoc */\nexport function normalizeToSize<T>(\n object: { [key: string]: any },\n // Default Node.js REPL depth\n depth: number = 3,\n // 100kB, as 200kB is max payload size, so half sounds reasonable\n maxSize: number = 100 * 1024,\n): T {\n const serialized = normalize(object, depth);\n\n if (jsonSize(serialized) > maxSize) {\n return normalizeToSize(object, depth - 1, maxSize);\n }\n\n return serialized as T;\n}\n\n/**\n * Transform any non-primitive, BigInt, or Symbol-type value into a string. Acts as a no-op on strings, numbers,\n * booleans, null, and undefined.\n *\n * @param value The value to stringify\n * @returns For non-primitive, BigInt, and Symbol-type values, a string denoting the value's type, type and value, or\n * type and `description` property, respectively. For non-BigInt, non-Symbol primitives, returns the original value,\n * unchanged.\n */\nfunction serializeValue(value: any): any {\n const type = Object.prototype.toString.call(value);\n\n // Node.js REPL notation\n if (typeof value === 'string') {\n return value;\n }\n if (type === '[object Object]') {\n return '[Object]';\n }\n if (type === '[object Array]') {\n return '[Array]';\n }\n\n const normalized = normalizeValue(value);\n return isPrimitive(normalized) ? normalized : type;\n}\n\n/**\n * normalizeValue()\n *\n * Takes unserializable input and make it serializable friendly\n *\n * - translates undefined/NaN values to \"[undefined]\"/\"[NaN]\" respectively,\n * - serializes Error objects\n * - filter global objects\n */\nfunction normalizeValue<T>(value: T, key?: any): T | string {\n if (key === 'domain' && value && typeof value === 'object' && ((value as unknown) as { _events: any })._events) {\n return '[Domain]';\n }\n\n if (key === 'domainEmitter') {\n return '[DomainEmitter]';\n }\n\n if (typeof (global as any) !== 'undefined' && (value as unknown) === global) {\n return '[Global]';\n }\n\n if (typeof (window as any) !== 'undefined' && (value as unknown) === window) {\n return '[Window]';\n }\n\n if (typeof (document as any) !== 'undefined' && (value as unknown) === document) {\n return '[Document]';\n }\n\n // React's SyntheticEvent thingy\n if (isSyntheticEvent(value)) {\n return '[SyntheticEvent]';\n }\n\n if (typeof value === 'number' && value !== value) {\n return '[NaN]';\n }\n\n if (value === void 0) {\n return '[undefined]';\n }\n\n if (typeof value === 'function') {\n return `[Function: ${getFunctionName(value)}]`;\n }\n\n // symbols and bigints are considered primitives by TS, but aren't natively JSON-serilaizable\n\n if (typeof value === 'symbol') {\n return `[${String(value)}]`;\n }\n\n if (typeof value === 'bigint') {\n return `[BigInt: ${String(value)}]`;\n }\n\n return value;\n}\n\n/**\n * Walks an object to perform a normalization on it\n *\n * @param key of object that's walked in current iteration\n * @param value object to be walked\n * @param depth Optional number indicating how deep should walking be performed\n * @param memo Optional Memo class handling decycling\n */\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nexport function walk(key: string, value: any, depth: number = +Infinity, memo: Memo = new Memo()): any {\n // If we reach the maximum depth, serialize whatever has left\n if (depth === 0) {\n return serializeValue(value);\n }\n\n /* eslint-disable @typescript-eslint/no-unsafe-member-access */\n // If value implements `toJSON` method, call it and return early\n if (value !== null && value !== undefined && typeof value.toJSON === 'function') {\n return value.toJSON();\n }\n /* eslint-enable @typescript-eslint/no-unsafe-member-access */\n\n // If normalized value is a primitive, there are no branches left to walk, so we can just bail out, as theres no point in going down that branch any further\n const normalized = normalizeValue(value, key);\n if (isPrimitive(normalized)) {\n return normalized;\n }\n\n // Create source that we will use for next itterations, either objectified error object (Error type with extracted keys:value pairs) or the input itself\n const source = getWalkSource(value);\n\n // Create an accumulator that will act as a parent for all future itterations of that branch\n const acc = Array.isArray(value) ? [] : {};\n\n // If we already walked that branch, bail out, as it's circular reference\n if (memo.memoize(value)) {\n return '[Circular ~]';\n }\n\n // Walk all keys of the source\n for (const innerKey in source) {\n // Avoid iterating over fields in the prototype if they've somehow been exposed to enumeration.\n if (!Object.prototype.hasOwnProperty.call(source, innerKey)) {\n continue;\n }\n // Recursively walk through all the child nodes\n (acc as { [key: string]: any })[innerKey] = walk(innerKey, source[innerKey], depth - 1, memo);\n }\n\n // Once walked through all the branches, remove the parent from memo storage\n memo.unmemoize(value);\n\n // Return accumulated values\n return acc;\n}\n\n/**\n * normalize()\n *\n * - Creates a copy to prevent original input mutation\n * - Skip non-enumerablers\n * - Calls `toJSON` if implemented\n * - Removes circular references\n * - Translates non-serializeable values (undefined/NaN/Functions) to serializable format\n * - Translates known global objects/Classes to a string representations\n * - Takes care of Error objects serialization\n * - Optionally limit depth of final output\n */\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nexport function normalize(input: any, depth?: number): any {\n try {\n return JSON.parse(JSON.stringify(input, (key: string, value: any) => walk(key, value, depth)));\n } catch (_oO) {\n return '**non-serializable**';\n }\n}\n\n/**\n * Given any captured exception, extract its keys and create a sorted\n * and truncated list that will be used inside the event message.\n * eg. `Non-error exception captured with keys: foo, bar, baz`\n */\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nexport function extractExceptionKeysForMessage(exception: any, maxLength: number = 40): string {\n const keys = Object.keys(getWalkSource(exception));\n keys.sort();\n\n if (!keys.length) {\n return '[object has no keys]';\n }\n\n if (keys[0].length >= maxLength) {\n return truncate(keys[0], maxLength);\n }\n\n for (let includedKeys = keys.length; includedKeys > 0; includedKeys--) {\n const serialized = keys.slice(0, includedKeys).join(', ');\n if (serialized.length > maxLength) {\n continue;\n }\n if (includedKeys === keys.length) {\n return serialized;\n }\n return truncate(serialized, maxLength);\n }\n\n return '';\n}\n\n/**\n * Given any object, return the new object with removed keys that value was `undefined`.\n * Works recursively on objects and arrays.\n */\nexport function dropUndefinedKeys<T>(val: T): T {\n if (isPlainObject(val)) {\n const obj = val as { [key: string]: any };\n const rv: { [key: string]: any } = {};\n for (const key of Object.keys(obj)) {\n if (typeof obj[key] !== 'undefined') {\n rv[key] = dropUndefinedKeys(obj[key]);\n }\n }\n return rv as T;\n }\n\n if (Array.isArray(val)) {\n return (val as any[]).map(dropUndefinedKeys) as any;\n }\n\n return val;\n}\n"]}
\No newline at end of file