import { KibanaRequest } from '../../../../../src/core/server' ; import { SpacesPluginStart } from '../../../spaces/server' ; import { PLUGIN_ID } from '../../common/constants/app' ; export function spacesUtilsProvider ( getSpacesPlugin , request ) { async function isMlEnabledInSpace ( ) { if ( getSpacesPlugin === undefined ) { return true ; } const space = await ( await getSpacesPlugin ( ) ) . spacesService . getActiveSpace ( request ) ; return space . disabledFeatures . includes ( PLUGIN_ID ) === false ; } async function getAllSpaces ( ) { if ( getSpacesPlugin === undefined ) { return null ; } const client = ( await getSpacesPlugin ( ) ) . spacesService . createSpacesClient ( request ) ; return await client . getAll ( ) ; } async function getAllSpaceIds ( ) { const spaces = await getAllSpaces ( ) ; if ( spaces === null ) { return null ; } return spaces . map ( ( s ) => s . id ) ; } async function getMlSpaceIds ( ) { const spaces = await getAllSpaces ( ) ; if ( spaces === null ) { return null ; } return spaces . filter ( ( s ) => s . disabledFeatures . includes ( PLUGIN_ID ) === false ) . map ( ( s ) => s . id ) ; } async function getCurrentSpaceId ( ) { if ( getSpacesPlugin === undefined ) { return null ; } const space = await ( await getSpacesPlugin ( ) ) . spacesService . getActiveSpace ( request ) ; return space . id ; } return { isMlEnabledInSpace , getAllSpaces , getAllSpaceIds , getMlSpaceIds , getCurrentSpaceId } ; }