import { shareReplay } from 'rxjs/operators' ; import type { RequestHandlerContext } from 'src/core/server' ; import { CoreContext } from '../core_context' ; import { PluginWrapper } from './plugin' ; import { PluginsServicePrebootSetupDeps , PluginsServiceSetupDeps , PluginsServiceStartDeps , } from './plugins_service' ; import { PluginInitializerContext , PluginManifest , PluginOpaqueId } from './types' ; import { IRouter , RequestHandlerContextProvider } from '../http' ; import { getGlobalConfig , getGlobalConfig$ } from './legacy_config' ; import { CorePreboot , CoreSetup , CoreStart } from '..' ; export interface InstanceInfo { uuid : string ; } param coreContext param pluginManifest internal export function createPluginInitializerContext ( coreContext , opaqueId , pluginManifest , instanceInfo ) { return { opaqueId , /**
         * Environment information that is safe to expose to plugins and may be beneficial for them.
         */ env : { mode : coreContext . env . mode , packageInfo : coreContext . env . packageInfo , instanceUuid : instanceInfo . uuid , configs : coreContext . env . configs , } , /**
         * Plugin-scoped logger
         */ logger : { get ( ... contextParts ) { return coreContext . logger . get ( 'plugins' , pluginManifest . id , ... contextParts ) ; } , } , /**
         * Core configuration functionality, enables fetching a subset of the config.
         */ config : { legacy : { globalConfig$ : getGlobalConfig$ ( coreContext . configService ) , get : ( ) => getGlobalConfig ( coreContext . configService ) , } , /**
             * Reads the subset of the config at the `configPath` defined in the plugin
             * manifest.
             */ create < T > ( ) { return coreContext . configService . atPath < T > ( pluginManifest . configPath ) . pipe ( shareReplay ( 1 ) ) ; } , get < T > ( ) { return coreContext . configService . atPathSync < T > ( pluginManifest . configPath ) ; } , } , } ; } param coreContext param deps param plugin internal export function createPluginPrebootSetupContext ( coreContext , deps , plugin ) { return { elasticsearch : { config : deps . elasticsearch . config , createClient : deps . elasticsearch . createClient , } , http : { registerRoutes : deps . http . registerRoutes , basePath : deps . http . basePath , getServerInfo : deps . http . getServerInfo , } , preboot : { isSetupOnHold : deps . preboot . isSetupOnHold , holdSetupUntilResolved : ( reason , promise ) => deps . preboot . holdSetupUntilResolved ( plugin . name , reason , promise ) , } , } ; } param coreContext param plugin param deps internal export function createPluginSetupContext < TPlugin , TPluginDependencies > ( coreContext , deps , plugin ) { const router = deps . http . createRouter ( '' , plugin . opaqueId ) ; return { capabilities : { registerProvider : deps . capabilities . registerProvider , registerSwitcher : deps . capabilities . registerSwitcher , } , context : { createContextContainer : deps . context . createContextContainer , } , elasticsearch : { legacy : deps . elasticsearch . legacy , } , executionContext : { withContext : deps . executionContext . withContext , } , http : { createCookieSessionStorageFactory : deps . http . createCookieSessionStorageFactory , registerRouteHandlerContext : < Context extends RequestHandlerContext , ContextName extends keyof Context > ( contextName , provider ) => deps . http . registerRouteHandlerContext ( plugin . opaqueId , contextName , provider ) , createRouter : < Context extends RequestHandlerContext = RequestHandlerContext > ( ) => router as IRouter < Context > , resources : deps . httpResources . createRegistrar ( router ) , registerOnPreRouting : deps . http . registerOnPreRouting , registerOnPreAuth : deps . http . registerOnPreAuth , registerAuth : deps . http . registerAuth , registerOnPostAuth : deps . http . registerOnPostAuth , registerOnPreResponse : deps . http . registerOnPreResponse , basePath : deps . http . basePath , auth : { get : deps . http . auth . get , isAuthenticated : deps . http . auth . isAuthenticated , } , csp : deps . http . csp , getServerInfo : deps . http . getServerInfo , } , i18n : deps . i18n , logging : { configure : ( config$ ) => deps . logging . configure ( [ 'plugins' , plugin . name ] , config$ ) , } , metrics : { collectionInterval : deps . metrics . collectionInterval , getOpsMetrics$ : deps . metrics . getOpsMetrics$ , } , savedObjects : { setClientFactoryProvider : deps . savedObjects . setClientFactoryProvider , addClientWrapper : deps . savedObjects . addClientWrapper , registerType : deps . savedObjects . registerType , getKibanaIndex : deps . savedObjects . getKibanaIndex , } , status : { core$ : deps . status . core$ , overall$ : deps . status . overall$ , set : deps . status . plugins . set . bind ( null , plugin . name ) , dependencies$ : deps . status . plugins . getDependenciesStatus$ ( plugin . name ) , derivedStatus$ : deps . status . plugins . getDerivedStatus$ ( plugin . name ) , isStatusPageAnonymous : deps . status . isStatusPageAnonymous , } , uiSettings : { register : deps . uiSettings . register , } , getStartServices : ( ) => plugin . startDependencies , deprecations : deps . deprecations . getRegistry ( plugin . name ) , coreUsageData : { registerUsageCounter : deps . coreUsageData . registerUsageCounter , } , } ; } param coreContext param plugin param deps internal export function createPluginStartContext < TPlugin , TPluginDependencies > ( coreContext , deps , plugin ) { return { capabilities : { resolveCapabilities : deps . capabilities . resolveCapabilities , } , elasticsearch : { client : deps . elasticsearch . client , createClient : deps . elasticsearch . createClient , legacy : deps . elasticsearch . legacy , } , executionContext : deps . executionContext , http : { auth : deps . http . auth , basePath : deps . http . basePath , getServerInfo : deps . http . getServerInfo , } , savedObjects : { getScopedClient : deps . savedObjects . getScopedClient , createInternalRepository : deps . savedObjects . createInternalRepository , createScopedRepository : deps . savedObjects . createScopedRepository , createSerializer : deps . savedObjects . createSerializer , createExporter : deps . savedObjects . createExporter , createImporter : deps . savedObjects . createImporter , getTypeRegistry : deps . savedObjects . getTypeRegistry , } , metrics : { collectionInterval : deps . metrics . collectionInterval , getOpsMetrics$ : deps . metrics . getOpsMetrics$ , } , uiSettings : { asScopedToClient : deps . uiSettings . asScopedToClient , } , coreUsageData : deps . coreUsageData , } ; }