import { pick } from 'lodash' ; import { RawRule } from '../types' ; import { SavedObjectsClient , SavedObjectsErrorHelpers , SavedObjectsUpdateOptions , } from '../../../../../src/core/server' ; import { AlertAttributesExcludedFromAAD , AlertAttributesExcludedFromAADType } from './index' ; export type PartiallyUpdateableAlertAttributes = Partial < Pick < RawRule , AlertAttributesExcludedFromAADType > > ; export interface PartiallyUpdateAlertSavedObjectOptions { refresh ? : SavedObjectsUpdateOptions [ 'refresh' ] ; version ? : string ; ignore404 ? : boolean ; namespace ? : string ; } type SavedObjectClientForUpdate = Pick < SavedObjectsClient , 'update' > ; export async function partiallyUpdateAlert ( savedObjectsClient , id , attributes , options = { } ) { const attributeUpdates = pick ( attributes , AlertAttributesExcludedFromAAD ) ; const updateOptions = pick ( options , 'namespace' , 'version' , 'refresh' ) ; try { await savedObjectsClient . update < RawRule > ( 'alert' , id , attributeUpdates , updateOptions ) ; } catch ( err ) { if ( options ?. ignore404 && SavedObjectsErrorHelpers . isNotFoundError ( err ) ) { return ; } throw err ; } }