import { addGlobalEventProcessor , getCurrentHub } from '../hub' ; import { Integration , Options } from '../types' ; import { logger } from '../utils' ; export const installedIntegrations = [ ] ; /** Map of integrations assigned to a client */ export interface IntegrationIndex { [ key ] : Integration ; } /** Setup given integration */ export function setupIntegration ( integration ) { if ( installedIntegrations . indexOf ( integration . name ) !== - 1 ) { return ; } integration . setupOnce ( addGlobalEventProcessor , getCurrentHub ) ; installedIntegrations . push ( integration . name ) ; logger . log ( `Integration installed: ${ integration . name }` ) ; } export function setupIntegrations < O extends Options > ( options ) { const integrations = { } ; if ( Array . isArray ( options . defaultIntegrations ) && options . defaultIntegrations . length ) { options . defaultIntegrations . forEach ( integration => { integrations [ integration . name ] = integration ; setupIntegration ( integration ) ; } ) ; } return integrations ; }