import { Features } from './features' ; type BuildCallback = ( featureId : string ) => boolean ; export class NavLinksBuilder { private readonly features : Features ; constructor ( features ) { this . features = { ... features , management : { app : [ 'kibana:stack_management' ] , } , kibana : { app : [ 'kibana' ] , } , } ; } public all ( ) { return this . build ( ( ) => true ) ; } public except ( ... feature ) { return this . build ( ( featureId ) => ! feature . includes ( featureId ) ) ; } public none ( ) { return this . build ( ( ) => false ) ; } public only ( ... feature ) { return this . build ( ( featureId ) => feature . includes ( featureId ) ) ; } private build ( callback ) { const navLinks = { } as Record < string , boolean > ; for ( const [ featureId , feature ] of Object . entries ( this . features ) ) { feature . app . forEach ( ( app ) => { navLinks [ app ] = callback ( featureId ) ; } ) ; } return navLinks ; } }