import { schema , TypeOf } from '@kbn/config-schema' ; import type { KibanaRequest , IKibanaResponse , KibanaResponseFactory , Logger , } from 'src/core/server' ; import type { EventLogRouter , EventLogRequestHandlerContext } from '../types' ; import { BASE_EVENT_LOG_API_PATH } from '../../common' ; import { findOptionsSchema , FindOptionsType } from '../event_log_client' ; const paramSchema = schema . object ( { type : schema . string ( ) , id : schema . string ( ) , } ) ; export const findRoute = ( router , systemLogger ) => { router . get ( { path : `${ BASE_EVENT_LOG_API_PATH }/{type}/{id}/_find` , validate : { params : paramSchema , query : findOptionsSchema , } , } , router . handleLegacyErrors ( async function ( context , req , res ) : Promise < IKibanaResponse > { if ( ! context . eventLog ) { return res . badRequest ( { body : 'RouteHandlerContext is not registered for eventLog' } ) ; } const eventLogClient = context . eventLog . getEventLogClient ( ) ; const { params : { id , type } , query , } = req ; try { return res . ok ( { body : await eventLogClient . findEventsBySavedObjectIds ( type , [ id ] , query ) , } ) ; } catch ( err ) { const call = `findEventsBySavedObjectIds(${ type }, [${ id }], ${ JSON . stringify ( query ) })` ; systemLogger . debug ( `error calling eventLog ${ call }: ${ err . message }` ) ; return res . notFound ( ) ; } } ) ) ; } ;