import { Plugin , CoreSetup , CoreStart , PluginInitializerContext , Logger } from 'kibana/server' ; import { schema } from '@kbn/config-schema' ; import { PluginSetupContract as FeaturesPluginSetup } from '../../../../../../../plugins/features/server' ; import { SpacesPluginStart } from '../../../../../../../plugins/spaces/server' ; import { SecurityPluginStart } from '../../../../../../../plugins/security/server' ; import { PluginStartContract as CasesPluginStart } from '../../../../../../../plugins/cases/server' ; import { CasesPatchRequest } from '../../../../../../../plugins/cases/common/api' ; export interface FixtureSetupDeps { features : FeaturesPluginSetup ; } export interface FixtureStartDeps { security ? : SecurityPluginStart ; spaces ? : SpacesPluginStart ; cases ? : CasesPluginStart ; } export class FixturePlugin implements Plugin < void , void , FixtureSetupDeps , FixtureStartDeps > { private readonly log : Logger ; private casesPluginStart ? : CasesPluginStart ; constructor ( initContext ) { this . log = initContext . logger . get ( ) ; } public setup ( core , deps ) { const router = core . http . createRouter ( ) ; /**
         * This simply wraps the cases patch case api so that we can test updating the status of an alert using
         * the cases client interface instead of going through the case plugin's RESTful interface
         */ router . patch ( { path : '/api/cases_user/cases' , validate : { body : schema . object ( { } , { unknowns : 'allow' } ) , } , } , async ( context , request , response ) => { try { const client = await this . casesPluginStart ?. getCasesClientWithRequest ( request ) ; if ( ! client ) { throw new Error ( 'Cases client was undefined' ) ; } return response . ok ( { body : await client . cases . update ( request . body as CasesPatchRequest ) , } ) ; } catch ( error ) { this . log . error ( `CasesClientUser failure: ${ error }` ) ; throw error ; } } ) ; } public start ( core , plugins ) { this . casesPluginStart = plugins . cases ; } public stop ( ) { } }