UNPKG

2.75 kBJavaScriptView Raw
1Object.defineProperty(exports, '__esModule', { value: true });
2
3var hub = require('@sentry/hub');
4var utils = require('@sentry/utils');
5
6var installedIntegrations = [];
7
8/** Map of integrations assigned to a client */
9
10/**
11 * @private
12 */
13function filterDuplicates(integrations) {
14 return integrations.reduce((acc, integrations) => {
15 if (acc.every(accIntegration => integrations.name !== accIntegration.name)) {
16 acc.push(integrations);
17 }
18 return acc;
19 }, [] );
20}
21
22/** Gets integration to install */
23function getIntegrationsToSetup(options) {
24 var defaultIntegrations = (options.defaultIntegrations && [...options.defaultIntegrations]) || [];
25 var userIntegrations = options.integrations;
26
27 let integrations = [...filterDuplicates(defaultIntegrations)];
28
29 if (Array.isArray(userIntegrations)) {
30 // Filter out integrations that are also included in user options
31 integrations = [
32 ...integrations.filter(integrations =>
33 userIntegrations.every(userIntegration => userIntegration.name !== integrations.name),
34 ),
35 // And filter out duplicated user options integrations
36 ...filterDuplicates(userIntegrations),
37 ];
38 } else if (typeof userIntegrations === 'function') {
39 integrations = userIntegrations(integrations);
40 integrations = Array.isArray(integrations) ? integrations : [integrations];
41 }
42
43 // Make sure that if present, `Debug` integration will always run last
44 var integrationsNames = integrations.map(i => i.name);
45 var alwaysLastToRun = 'Debug';
46 if (integrationsNames.indexOf(alwaysLastToRun) !== -1) {
47 integrations.push(...integrations.splice(integrationsNames.indexOf(alwaysLastToRun), 1));
48 }
49
50 return integrations;
51}
52
53/**
54 * Given a list of integration instances this installs them all. When `withDefaults` is set to `true` then all default
55 * integrations are added unless they were already provided before.
56 * @param integrations array of integration instances
57 * @param withDefault should enable default integrations
58 */
59function setupIntegrations(integrations) {
60 var integrationIndex = {};
61
62 integrations.forEach(integration => {
63 integrationIndex[integration.name] = integration;
64
65 if (installedIntegrations.indexOf(integration.name) === -1) {
66 integration.setupOnce(hub.addGlobalEventProcessor, hub.getCurrentHub);
67 installedIntegrations.push(integration.name);
68 (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log(`Integration installed: ${integration.name}`);
69 }
70 });
71
72 return integrationIndex;
73}
74
75exports.getIntegrationsToSetup = getIntegrationsToSetup;
76exports.installedIntegrations = installedIntegrations;
77exports.setupIntegrations = setupIntegrations;
78//# sourceMappingURL=integration.js.map