import uuid from 'uuid' ; import { BulkErrorSchema , ImportExceptionListItemSchemaDecoded , } from '@kbn/securitysolution-io-ts-list-types' ; param items returns { Array } export const getTupleErrorsAndUniqueExceptionListItems = ( items ) : [ BulkErrorSchema [ ] , ImportExceptionListItemSchemaDecoded [ ] ] => { const { errors , itemsAcc } = items . reduce ( ( acc , parsedExceptionItem ) => { if ( parsedExceptionItem instanceof Error ) { acc . errors . set ( uuid . v4 ( ) , { error : { message : `Error found importing exception list item: ${ parsedExceptionItem . message }` , status_code : 400 , } , list_id : '(unknown item_id)' , } ) ; } else { const { item_id : itemId , list_id : listId } = parsedExceptionItem ; if ( acc . itemsAcc . has ( `${ itemId }${ listId }` ) ) { acc . errors . set ( uuid . v4 ( ) , { error : { message : `More than one exception list item with item_id: "${ itemId }" found in imports. The last item will be used.` , status_code : 400 , } , item_id : itemId , } ) ; } acc . itemsAcc . set ( `${ itemId }${ listId }` , parsedExceptionItem ) ; } return acc ; } , { errors : new Map < string , BulkErrorSchema > ( ) , itemsAcc : new Map < string , ImportExceptionListItemSchemaDecoded > ( ) , } ) ; return [ Array . from ( errors . values ( ) ) , Array . from ( itemsAcc . values ( ) ) ] ; } ;