import { IRouter } from 'kibana/server' ; import { ILicenseState } from '../lib' ; import { RegistryAlertTypeWithAuth } from '../authorization' ; import { RewriteResponseCase , verifyAccessAndContext } from './lib' ; import { AlertingRequestHandlerContext , BASE_ALERTING_API_PATH } from '../types' ; const rewriteBodyRes = ( results ) => { return results . map ( ( { enabledInLicense , recoveryActionGroup , actionGroups , defaultActionGroupId , minimumLicenseRequired , isExportable , ruleTaskTimeout , actionVariables , authorizedConsumers , minimumScheduleInterval , defaultScheduleInterval , ... rest } ) => ( { ... rest , enabled_in_license : enabledInLicense , recovery_action_group : recoveryActionGroup , action_groups : actionGroups , default_action_group_id : defaultActionGroupId , minimum_license_required : minimumLicenseRequired , is_exportable : isExportable , rule_task_timeout : ruleTaskTimeout , action_variables : actionVariables , authorized_consumers : authorizedConsumers , minimum_schedule_interval : minimumScheduleInterval , default_schedule_interval : defaultScheduleInterval , } ) ) ; } ; export const ruleTypesRoute = ( router , licenseState ) => { router . get ( { path : `${ BASE_ALERTING_API_PATH }/rule_types` , validate : { } , } , router . handleLegacyErrors ( verifyAccessAndContext ( licenseState , async function ( context , req , res ) { const ruleTypes = Array . from ( await context . alerting . getRulesClient ( ) . listAlertTypes ( ) ) ; return res . ok ( { body : rewriteBodyRes ( ruleTypes ) , } ) ; } ) ) ) ; } ;