import { get } from 'lodash' ; import { deepFreeze } from '@osd/std' ; import { DiscoveredPlugin , PluginName } from '../../server' ; import { EnvironmentMode , PackageInfo , UiSettingsParams , UserProvidedValues , } from '../../server/types' ; import { AppCategory , Branding } from '../' ; export interface InjectedPluginMetadata { id : PluginName ; plugin : DiscoveredPlugin ; config ? : { [ key ] : unknown ; } ; } internal export interface InjectedMetadataParams { injectedMetadata : { version : string ; buildNumber : number ; branch : string ; basePath : string ; serverBasePath : string ; category ? : AppCategory ; csp : { warnLegacyBrowsers : boolean ; } ; vars : { [ key ] : unknown ; } ; env : { mode : Readonly < EnvironmentMode > ; packageInfo : Readonly < PackageInfo > ; } ; uiPlugins : InjectedPluginMetadata [ ] ; anonymousStatusPage : boolean ; legacyMetadata : { uiSettings : { defaults : Record < string , UiSettingsParams > ; user ? : Record < string , UserProvidedValues > ; } ; } ; branding : Branding ; } ; } internal export class InjectedMetadataService { private state = deepFreeze ( this . params . injectedMetadata ) as InjectedMetadataParams [ 'injectedMetadata' ] ; constructor ( private readonly params ) { } public start ( ) { return this . setup ( ) ; } public setup ( ) { return { getBasePath : ( ) => { return this . state . basePath ; } , getServerBasePath : ( ) => { return this . state . serverBasePath ; } , getAnonymousStatusPage : ( ) => { return this . state . anonymousStatusPage ; } , getOpenSearchDashboardsVersion : ( ) => { return this . state . version ; } , getCspConfig : ( ) => { return this . state . csp ; } , getPlugins : ( ) => { return this . state . uiPlugins ; } , getLegacyMetadata : ( ) => { return this . state . legacyMetadata ; } , getInjectedVar : ( name , defaultValue ? ) : unknown => { return get ( this . state . vars , name , defaultValue ) ; } , getInjectedVars : ( ) => { return this . state . vars ; } , getOpenSearchDashboardsBuildNumber : ( ) => { return this . state . buildNumber ; } , getOpenSearchDashboardsBranch : ( ) => { return this . state . branch ; } , getBranding : ( ) => { return this . state . branding ; } , } ; } } internal export interface InjectedMetadataSetup { getBasePath : ( ) => string ; getServerBasePath : ( ) => string ; getOpenSearchDashboardsBuildNumber : ( ) => number ; getOpenSearchDashboardsBranch : ( ) => string ; getOpenSearchDashboardsVersion : ( ) => string ; getCspConfig : ( ) => { warnLegacyBrowsers : boolean ; } ; /**
     * An array of frontend plugins in topological order.
     */ getPlugins : ( ) => InjectedPluginMetadata [ ] ; getAnonymousStatusPage : ( ) => boolean ; getLegacyMetadata : ( ) => { uiSettings : { defaults : Record < string , UiSettingsParams > ; user ? : Record < string , UserProvidedValues > | undefined ; } ; } ; getInjectedVar : ( name : string , defaultValue ? : any ) => unknown ; getInjectedVars : ( ) => { [ key ] : unknown ; } ; getBranding : ( ) => Branding ; } internal export type InjectedMetadataStart = InjectedMetadataSetup ;