import { omit } from 'lodash' ; import { schema } from '@kbn/config-schema' ; import { IRouter } from 'kibana/server' ; import { ILicenseState } from '../lib' ; import { verifyAccessAndContext , RewriteResponseCase } from './lib' ; import { AlertTypeParams , AlertingRequestHandlerContext , INTERNAL_BASE_ALERTING_API_PATH , ResolvedSanitizedRule , } from '../types' ; const paramSchema = schema . object ( { id : schema . string ( ) , } ) ; const rewriteBodyRes = ( { alertTypeId , createdBy , updatedBy , createdAt , updatedAt , apiKeyOwner , notifyWhen , muteAll , mutedInstanceIds , executionStatus , actions , scheduledTaskId , ... rest } ) => ( { ... rest , rule_type_id : alertTypeId , created_by : createdBy , updated_by : updatedBy , created_at : createdAt , updated_at : updatedAt , api_key_owner : apiKeyOwner , notify_when : notifyWhen , mute_all : muteAll , muted_alert_ids : mutedInstanceIds , scheduled_task_id : scheduledTaskId , execution_status : executionStatus && { ... omit ( executionStatus , 'lastExecutionDate' , 'lastDuration' ) , last_execution_date : executionStatus . lastExecutionDate , last_duration : executionStatus . lastDuration , } , actions : actions . map ( ( { group , id , actionTypeId , params } ) => ( { group , id , params , connector_type_id : actionTypeId , } ) ) , } ) ; export const resolveRuleRoute = ( router , licenseState ) => { router . get ( { path : `${ INTERNAL_BASE_ALERTING_API_PATH }/rule/{id}/_resolve` , validate : { params : paramSchema , } , } , router . handleLegacyErrors ( verifyAccessAndContext ( licenseState , async function ( context , req , res ) { const rulesClient = context . alerting . getRulesClient ( ) ; const { id } = req . params ; const rule = await rulesClient . resolve ( { id } ) ; return res . ok ( { body : rewriteBodyRes ( rule ) , } ) ; } ) ) ) ; } ;