|
1 | | -// tslint:disable:deprecation |
2 | | -import { Integration } from '@sentry/types'; |
3 | | -import { logger } from '@sentry/utils/logger'; |
4 | | -import { Options } from '../interfaces'; |
5 | | - |
6 | 1 | export { Dedupe } from './dedupe'; |
7 | 2 | export { FunctionToString } from './functiontostring'; |
8 | 3 | export { SDKInformation } from './sdkinformation'; |
9 | 4 | export { InboundFilters } from './inboundfilters'; |
10 | 5 |
|
11 | 6 | export { Debug } from './pluggable/debug'; |
12 | 7 | export { RewriteFrames } from './pluggable/rewriteframes'; |
13 | | - |
14 | | -export const installedIntegrations: string[] = []; |
15 | | - |
16 | | -/** Map of integrations assigned to a client */ |
17 | | -export interface IntegrationIndex { |
18 | | - [key: string]: Integration; |
19 | | -} |
20 | | - |
21 | | -/** Gets integration to install */ |
22 | | -export function getIntegrationsToSetup(options: Options): Integration[] { |
23 | | - const defaultIntegrations = (options.defaultIntegrations && [...options.defaultIntegrations]) || []; |
24 | | - const userIntegrations = options.integrations; |
25 | | - let integrations: Integration[] = []; |
26 | | - if (Array.isArray(userIntegrations)) { |
27 | | - const userIntegrationsNames = userIntegrations.map(i => i.name); |
28 | | - const pickedIntegrationsNames = []; |
29 | | - |
30 | | - // Leave only unique default integrations, that were not overridden with provided user integrations |
31 | | - for (const defaultIntegration of defaultIntegrations) { |
32 | | - if ( |
33 | | - userIntegrationsNames.indexOf(getIntegrationName(defaultIntegration)) === -1 && |
34 | | - pickedIntegrationsNames.indexOf(getIntegrationName(defaultIntegration)) === -1 |
35 | | - ) { |
36 | | - integrations.push(defaultIntegration); |
37 | | - pickedIntegrationsNames.push(getIntegrationName(defaultIntegration)); |
38 | | - } |
39 | | - } |
40 | | - |
41 | | - // Don't add same user integration twice |
42 | | - for (const userIntegration of userIntegrations) { |
43 | | - if (pickedIntegrationsNames.indexOf(getIntegrationName(userIntegration)) === -1) { |
44 | | - integrations.push(userIntegration); |
45 | | - pickedIntegrationsNames.push(getIntegrationName(userIntegration)); |
46 | | - } |
47 | | - } |
48 | | - } else if (typeof userIntegrations === 'function') { |
49 | | - integrations = userIntegrations(defaultIntegrations); |
50 | | - integrations = Array.isArray(integrations) ? integrations : [integrations]; |
51 | | - } else { |
52 | | - return [...defaultIntegrations]; |
53 | | - } |
54 | | - |
55 | | - return integrations; |
56 | | -} |
57 | | - |
58 | | -/** Setup given integration */ |
59 | | -export function setupIntegration(integration: Integration, options: Options): void { |
60 | | - if (installedIntegrations.indexOf(getIntegrationName(integration)) !== -1) { |
61 | | - return; |
62 | | - } |
63 | | - |
64 | | - try { |
65 | | - integration.setupOnce(); |
66 | | - } catch (_Oo) { |
67 | | - /** @deprecated */ |
68 | | - // TODO: Remove in v5 |
69 | | - logger.warn(`Integration ${getIntegrationName(integration)}: The install method is deprecated. Use "setupOnce".`); |
70 | | - |
71 | | - if (integration.install) { |
72 | | - integration.install(options); |
73 | | - } |
74 | | - } |
75 | | - |
76 | | - installedIntegrations.push(getIntegrationName(integration)); |
77 | | - logger.log(`Integration installed: ${getIntegrationName(integration)}`); |
78 | | -} |
79 | | - |
80 | | -/** |
81 | | - * Given a list of integration instances this installs them all. When `withDefaults` is set to `true` then all default |
82 | | - * integrations are added unless they were already provided before. |
83 | | - * @param integrations array of integration instances |
84 | | - * @param withDefault should enable default integrations |
85 | | - */ |
86 | | -export function setupIntegrations<O extends Options>(options: O): IntegrationIndex { |
87 | | - const integrations: IntegrationIndex = {}; |
88 | | - getIntegrationsToSetup(options).forEach(integration => { |
89 | | - integrations[getIntegrationName(integration)] = integration; |
90 | | - setupIntegration(integration, options); |
91 | | - }); |
92 | | - return integrations; |
93 | | -} |
94 | | - |
95 | | -/** |
96 | | - * Returns the integration static id. |
97 | | - * @param integration Integration to retrieve id |
98 | | - */ |
99 | | -function getIntegrationName(integration: Integration): string { |
100 | | - /** |
101 | | - * @depracted |
102 | | - */ |
103 | | - // tslint:disable-next-line:no-unsafe-any |
104 | | - return (integration as any).constructor.id || integration.name; |
105 | | -} |
0 commit comments