import { map , shareReplay } from 'rxjs/operators' ; import { combineLatest } from 'rxjs' ; import { PathConfigType , config as pathConfig } from '@osd/utils' ; import { pick , deepFreeze } from '@osd/std' ; import { CoreContext } from '../core_context' ; import { PluginWrapper } from './plugin' ; import { PluginsServiceSetupDeps , PluginsServiceStartDeps } from './plugins_service' ; import { PluginInitializerContext , PluginManifest , PluginOpaqueId , SharedGlobalConfigKeys , } from './types' ; import { OpenSearchDashboardsConfigType , config as opensearchDashboardsConfig , } from '../opensearch_dashboards_config' ; import { OpenSearchConfigType , config as opensearchConfig } from '../opensearch/opensearch_config' ; import { SavedObjectsConfigType , savedObjectsConfig } from '../saved_objects/saved_objects_config' ; import { 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 , } , /**
         * 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 : { deprecated globalConfig$ : combineLatest ( [ coreContext . configService . atPath < OpenSearchDashboardsConfigType > ( opensearchDashboardsConfig . path ) , coreContext . configService . atPath < OpenSearchConfigType > ( opensearchConfig . path ) , coreContext . configService . atPath < PathConfigType > ( pathConfig . path ) , coreContext . configService . atPath < SavedObjectsConfigType > ( savedObjectsConfig . path ) , ] ) . pipe ( map ( ( [ opensearchDashboards , opensearch , path , savedObjects ] ) => deepFreeze ( { opensearchDashboards : pick ( opensearchDashboards , SharedGlobalConfigKeys . opensearchDashboards ) , opensearch : pick ( opensearch , SharedGlobalConfigKeys . opensearch ) , path : pick ( path , SharedGlobalConfigKeys . path ) , savedObjects : pick ( savedObjects , SharedGlobalConfigKeys . savedObjects ) , } ) ) ) , } , param ConfigClass create < T > ( ) { return coreContext . configService . atPath < T > ( pluginManifest . configPath ) . pipe ( shareReplay ( 1 ) ) ; } , createIfExists ( ) { return coreContext . configService . optionalAtPath ( pluginManifest . configPath ) ; } , } , } ; } 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 , } , opensearch : { legacy : deps . opensearch . legacy , } , http : { createCookieSessionStorageFactory : deps . http . createCookieSessionStorageFactory , registerRouteHandlerContext : deps . http . registerRouteHandlerContext . bind ( null , plugin . opaqueId ) , createRouter : ( ) => router , 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 , } , 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 , getImportExportObjectLimit : deps . savedObjects . getImportExportObjectLimit , } , 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 , auditTrail : deps . auditTrail , } ; } param coreContext param plugin param deps internal export function createPluginStartContext < TPlugin , TPluginDependencies > ( coreContext , deps , plugin ) { return { capabilities : { resolveCapabilities : deps . capabilities . resolveCapabilities , } , opensearch : { client : deps . opensearch . client , createClient : deps . opensearch . createClient , legacy : deps . opensearch . legacy , } , 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 , getTypeRegistry : deps . savedObjects . getTypeRegistry , } , metrics : { collectionInterval : deps . metrics . collectionInterval , getOpsMetrics$ : deps . metrics . getOpsMetrics$ , } , uiSettings : { asScopedToClient : deps . uiSettings . asScopedToClient , } , auditTrail : deps . auditTrail , coreUsageData : deps . coreUsageData , } ; }