import { Logger } from 'kibana/server' ; import { IntegrationCategory , INTEGRATION_CATEGORY_DISPLAY , CustomIntegration } from '../common' ; function isAddable ( integration ) { return ! ! integration . categories . length && ! integration . eprOverlap ; } function isReplacement ( integration ) { return ! ! integration . categories . length && ! ! integration . eprOverlap ; } export class CustomIntegrationRegistry { private readonly _integrations : CustomIntegration [ ] ; private readonly _logger : Logger ; private readonly _isDev : boolean ; constructor ( logger , isDev ) { this . _integrations = [ ] ; this . _logger = logger ; this . _isDev = isDev ; } registerCustomIntegration ( customIntegration ) { if ( this . _integrations . some ( ( integration ) => { return integration . id === customIntegration . id ; } ) ) { const message = `Integration with id=${ customIntegration . id } already exists.` ; if ( this . _isDev ) { this . _logger . error ( message ) ; } else { this . _logger . debug ( message ) ; } return ; } const allowedCategories = ( customIntegration . categories ?? [ ] ) . filter ( ( category ) => { return INTEGRATION_CATEGORY_DISPLAY . hasOwnProperty ( category ) ; } ) as IntegrationCategory [ ] ; this . _integrations . push ( { ... customIntegration , categories : allowedCategories } ) ; } getAppendCustomIntegrations ( ) { return this . _integrations . filter ( isAddable ) ; } getReplacementCustomIntegrations ( ) { return this . _integrations . filter ( isReplacement ) ; } }