import { HttpSetup } from 'kibana/public' ; import { BASE_ALERTING_API_PATH } from '../common' ; import type { Alert , RuleType } from '../common' ; import { AsApiContract } from '../../actions/common' ; import { transformAlert , transformRuleType , ApiAlert } from './lib/common_transformations' ; export async function loadAlertTypes ( { http } ) { const res = await http . get < Array < AsApiContract < RuleType > > > ( `${ BASE_ALERTING_API_PATH }/rule_types` ) ; return res . map ( ( ruleType ) => transformRuleType ( ruleType ) ) ; } export async function loadAlertType ( { http , id , } ) { const ruleTypes = await loadAlertTypes ( { http } ) ; return ruleTypes . find ( ( type ) => type . id === id ) ; } export async function loadAlert ( { http , alertId , } ) { const res = await http . get < ApiAlert > ( `${ BASE_ALERTING_API_PATH }/rule/${ alertId }` ) ; return transformAlert ( res ) ; }