import { has } from 'lodash/fp' ; import { SavedObjectsBulkCreateObject , SavedObjectsClientContract } from 'kibana/server' ; import { ExceptionListSoSchema } from '../../../../schemas/saved_objects/exceptions_list_so_schema' ; import { ImportResponse } from '../../import_exception_list_and_items' ; param itemsToCreate { array } param savedObjectsClient { object } returns { array } export const bulkCreateImportedItems = async ( { itemsToCreate , savedObjectsClient , } ) : Promise < ImportResponse [ ] > => { if ( ! itemsToCreate . length ) { return [ ] ; } const bulkCreateResponse = await savedObjectsClient . bulkCreate ( itemsToCreate , { overwrite : false , } ) ; return bulkCreateResponse . saved_objects . map ( ( so ) => { if ( has ( 'error' , so ) && so . error != null ) { return { error : { message : so . error . message , status_code : so . error . statusCode ?? 400 , } , item_id : '(unknown item_id)' , } ; } else { return { id : so . id , status_code : 200 , } ; } } ) ; } ;