import { KibanaRequest , SavedObjectsClientContract } from 'kibana/server' ; import { GetGuards } from '../shared_services' ; import { alertingServiceProvider , MlAlertingService } from '../../lib/alerts/alerting_service' ; import { datafeedsProvider } from '../../models/job_service/datafeeds' ; export function getAlertingServiceProvider ( getGuards ) { return { alertingServiceProvider ( savedObjectsClient , request ) { return { preview : async ( ... args ) => { return await getGuards ( request , savedObjectsClient ) . isFullLicense ( ) . hasMlCapabilities ( [ 'canGetJobs' ] ) . ok ( ( { mlClient , scopedClient , getFieldsFormatRegistry , getDataViewsService } ) => alertingServiceProvider ( mlClient , datafeedsProvider ( scopedClient , mlClient ) , getFieldsFormatRegistry , getDataViewsService ) . preview ( ... args ) ) ; } , execute : async ( ... args ) : ReturnType < MlAlertingService [ 'execute' ] > => { return await getGuards ( request , savedObjectsClient ) . isFullLicense ( ) . hasMlCapabilities ( [ 'canGetJobs' ] ) . ok ( ( { mlClient , scopedClient , getFieldsFormatRegistry , getDataViewsService } ) => alertingServiceProvider ( mlClient , datafeedsProvider ( scopedClient , mlClient ) , getFieldsFormatRegistry , getDataViewsService ) . execute ( ... args ) ) ; } , } ; } , } ; } export type MlAlertingServiceProvider = ReturnType < typeof getAlertingServiceProvider > ;