import { ImportExceptionListSchemaDecoded } from '@kbn/securitysolution-io-ts-list-types' ; import { SavedObjectsClientContract } from '../../../../../../../../src/core/server/' ; import { ImportDataResponse , ImportResponse } from '../../import_exception_list_and_items' ; import { getAllListTypes } from './find_all_exception_list_types' ; import { sortExceptionListsToUpdateOrCreate } from './sort_exception_lists_to_create_update' ; import { bulkCreateImportedLists } from './bulk_create_imported_lists' ; import { bulkUpdateImportedLists } from './bulk_update_imported_lists' ; import { deleteListItemsToBeOverwritten } from './delete_list_items_to_overwrite' ; import { sortListsImportsByNamespace } from './sort_import_by_namespace' ; import { sortImportResponses } from './sort_import_responses' ; param exceptionListsClient param listsChunks param isOverwrite returns { Object } export const importExceptionLists = async ( { isOverwrite , listsChunks , savedObjectsClient , user , } ) : Promise < ImportDataResponse > => { let importExceptionListsResponse = [ ] ; for await ( const listChunk of listsChunks ) { const [ agnosticLists , nonAgnosticLists ] = sortListsImportsByNamespace ( listChunk ) ; const foundLists = await getAllListTypes ( agnosticLists . map ( ( list ) => ( { listId : list . list_id , namespaceType : list . namespace_type } ) ) , nonAgnosticLists . map ( ( list ) => ( { listId : list . list_id , namespaceType : list . namespace_type , } ) ) , savedObjectsClient ) ; const { errors , listItemsToDelete , listsToCreate , listsToUpdate } = sortExceptionListsToUpdateOrCreate ( { existingLists : foundLists , isOverwrite , lists : listChunk , user , } ) ; const bulkCreateResponse = await bulkCreateImportedLists ( { listsToCreate , savedObjectsClient , } ) ; await deleteListItemsToBeOverwritten ( { listsOfItemsToDelete : listItemsToDelete , savedObjectsClient , } ) ; const bulkUpdateResponse = await bulkUpdateImportedLists ( { listsToUpdate , savedObjectsClient , } ) ; importExceptionListsResponse = [ ... importExceptionListsResponse , ... bulkCreateResponse , ... bulkUpdateResponse , ... errors , ] ; } return sortImportResponses ( importExceptionListsResponse ) ; } ;