rittenhop-dev/versions/5.94.2/node_modules/@sentry/utils/esm/userIntegrations.js.map

1 line
6.8 KiB
Plaintext
Raw Normal View History

2024-09-23 19:40:12 -04:00
{"version":3,"file":"userIntegrations.js","sources":["../../src/userIntegrations.ts"],"sourcesContent":["import type { Integration } from '@sentry/types';\n\nexport type UserIntegrationsFunction = (integrations: Integration[]) => Integration[];\nexport type UserIntegrations = Integration[] | UserIntegrationsFunction;\nexport type IntegrationWithExclusionOption = Integration & {\n /**\n * Allow the user to exclude this integration by not returning it from a function provided as the `integrations` option\n * in `Sentry.init()`. Meant to be used with default integrations, the idea being that if a user has actively filtered\n * an integration out, we should be able to respect that choice if we wish.\n */\n allowExclusionByUser?: boolean;\n};\n\ntype ForcedIntegrationOptions = {\n [keyPath: string]: unknown;\n};\n\n/**\n * Recursively traverses an object to update an existing nested key.\n * Note: The provided key path must include existing properties,\n * the function will not create objects while traversing.\n *\n * @param obj An object to update\n * @param value The value to update the nested key with\n * @param keyPath The path to the key to update ex. fizz.buzz.foo\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction setNestedKey(obj: Record<string, any>, keyPath: string, value: unknown): void {\n // Ex. foo.bar.zoop will extract foo and bar.zoop\n const match = keyPath.match(/([a-z_]+)\\.(.*)/i);\n // The match will be null when there's no more recursing to do, i.e., when we've reached the right level of the object\n if (match === null) {\n obj[keyPath] = value;\n } else {\n // `match[1]` is the initial segment of the path, and `match[2]` is the remainder of the path\n const innerObj = obj[match[1]];\n setNestedKey(innerObj, match[2], value);\n }\n}\n\n/**\n * Enforces inclusion of a given integration with specified options in an integration array originally determined by the\n * user, by either including the given default instance or by patching an existing user instance with the given options.\n *\n * Ideally this would happen when integrations are set up, but there isn't currently a mechanism there for merging\n * options from a default integration instance with those from a user-provided instance of the same integration, only\n * for allowing the user to override a default instance entirely. (TODO: Fix that.)\n *\n * @param defaultIntegrationInstance An instance of the integration with the correct options already set\n * @param userIntegrations Integrations defined by the user.\n * @param forcedOptions Options with which to patch an existing user-derived instance on the integration.\n * @returns A final integrations array.\n *\n * @deprecated This will be removed in v8.\n */\nexport function addOrUpdateIntegration<T extends UserIntegrations>(\n defaultIntegrationInstance: Integration,\n userIntegrations: T,\n forcedOptions: ForcedIntegrationOptions = {},\n): T {\n return (\n Array.isArray(userIntegrations)\n ? addOrUpdateIntegrationInArray(defaultIntegrationInstance, userIntegrations, forcedOptions)\n : addOrUpdateIntegrationInFunction(\n defaultIntegrationInstance,\n // Somehow TS can't figure out that not being an array makes this necessarily a function\n userIntegrations as UserIntegrationsFunction,\n forcedOptions,\n )\n ) as T;\n}\n\nfunction addOrUpdateIntegrationInArray(\n defaultIntegrationInstance: Integration,\n userIntegrations: Integration[],\n forcedOptions: ForcedIntegrationOptions,\n): Integration[] {\n const userInstance = userIntegrations.find(integration => integration.name === defaultIntegrationInstance.name);\n\n if (userInstance) {\n for (const [keyPath, value] of Object.entries(forcedOptions)) {\n setNestedKey(userInstance, keyPath, value);\n }\n\n return userIntegrations;\n }\n\n return [...userIntegrations, defaultIntegrationInstance];\n}\n\nfunction addOrUpdateIntegrationInFunction(\n defaultIntegrationInstance: IntegrationWithExclusionOption,\n userInte