import { schema } from '@kbn/config-schema' ; import { PLUGIN_ID } from '../../../common' ; import { IRouter } from '../../../../../../src/core/server' ; import { savedQuerySavedObjectType } from '../../../common/types' ; import { convertECSMappingToObject } from '../utils' ; export const readSavedQueryRoute = ( router ) => { router . get ( { path : '/internal/osquery/saved_query/{id}' , validate : { params : schema . object ( { id : schema . string ( ) , } ) , } , options : { tags : [ `access:${ PLUGIN_ID }-readSavedQueries` ] } , } , async ( context , request , response ) => { const savedObjectsClient = context . core . savedObjects . client ; const savedQuery = await savedObjectsClient . get < { ecs_mapping : Array < { key : string ; value : Record < string , object > ; } > ; } > ( savedQuerySavedObjectType , request . params . id ) ; if ( savedQuery . attributes . ecs_mapping ) { savedQuery . attributes . ecs_mapping = convertECSMappingToObject ( savedQuery . attributes . ecs_mapping ) ; } return response . ok ( { body : savedQuery , } ) ; } ) ; } ;