@@ -13,9 +13,7 @@ import Logger, { createLogger } from 'bunyan-category';
1313import { networkRequest } from './networkRequest' ;
1414
1515import {
16- Entity ,
1716 EntityForSync ,
18- Relationship ,
1917 RelationshipForSync ,
2018 IntegrationDefinition ,
2119 ListIntegrationDefinitions ,
@@ -74,8 +72,10 @@ export class FetchError extends Error {
7472 nameForLogging ?: string ;
7573 } ) {
7674 super (
77- `JupiterOne API error. Response not OK (requestName=${ options . nameForLogging || '(none)'
78- } , status=${ options . response . status } , url=${ options . url } , method=${ options . method
75+ `JupiterOne API error. Response not OK (requestName=${
76+ options . nameForLogging || '(none)'
77+ } , status=${ options . response . status } , url=${ options . url } , method=${
78+ options . method
7979 } ). Response: ${ options . responseBody } `,
8080 ) ;
8181 this . httpStatusCode = options . response . status ;
@@ -363,7 +363,6 @@ export class JupiterOneClient {
363363 */
364364 startPage = 0 ,
365365 ) {
366-
367366 let cursor : string ;
368367 let complete = false ;
369368 let results : any [ ] = [ ] ;
@@ -379,9 +378,9 @@ export class JupiterOneClient {
379378 query : j1ql ,
380379 deferredResponse : 'FORCE' ,
381380 flags : {
382- variableResultSize : true
381+ variableResultSize : true ,
383382 } ,
384- cursor
383+ cursor,
385384 } ,
386385 ...options ,
387386 } ) ;
@@ -396,7 +395,8 @@ export class JupiterOneClient {
396395 do {
397396 if ( Date . now ( ) - startTimeInMs > QUERY_RESULTS_TIMEOUT ) {
398397 throw new Error (
399- `Exceeded request timeout of ${ QUERY_RESULTS_TIMEOUT / 1000
398+ `Exceeded request timeout of ${
399+ QUERY_RESULTS_TIMEOUT / 1000
400400 } seconds.`,
401401 ) ;
402402 }
@@ -408,27 +408,31 @@ export class JupiterOneClient {
408408 } while ( status === JobStatus . IN_PROGRESS ) ;
409409
410410 if ( status === JobStatus . FAILED ) {
411- throw new Error ( `JupiterOne returned error(s) for query: '${ statusFile . error } '` ) ;
411+ throw new Error (
412+ `JupiterOne returned error(s) for query: '${ statusFile . error } '` ,
413+ ) ;
412414 }
413415
414416 const result = statusFile . data ;
415417
416418 if ( showProgress && ! limitCheck ) {
417419 if ( results . length === 0 ) {
418- progress = new cliProgress . SingleBar ( { } , cliProgress . Presets . shades_classic ) ;
420+ progress = new cliProgress . SingleBar (
421+ { } ,
422+ cliProgress . Presets . shades_classic ,
423+ ) ;
419424 progress . start ( Number ( statusFile . totalCount ) , 0 ) ;
420425 }
421426 progress . update ( results . length ) ;
422427 }
423428
424429 if ( result ) {
425- results = results . concat ( result )
430+ results = results . concat ( result ) ;
426431 }
427432
428433 if ( status === JobStatus . COMPLETED && ( cursor == null || limitCheck ) ) {
429434 complete = true ;
430435 }
431-
432436 } while ( complete === false ) ;
433437 return results ;
434438 }
@@ -866,57 +870,38 @@ export class JupiterOneClient {
866870 return validateSyncJobResponse ( response ) ;
867871 }
868872
869- async uploadGraphObjectsForDeleteSyncJob ( options : {
873+ async uploadGraphObjectsForSyncJob ( options : {
870874 syncJobId : string ;
871- entities ?: Entity [ ] ;
872- relationships ?: Relationship [ ] ;
875+ entities ?: EntityForSync [ ] ;
876+ relationships ?: RelationshipForSync [ ] ;
873877 } ) : Promise < SyncJobResponse > {
874- const upload : GraphObjectDeletionPayload = {
875- deleteEntities : [ ] ,
876- deleteRelationships : [ ] ,
877- } ;
878- for ( const e of options . entities || [ ] ) {
879- upload . deleteEntities . push ( { _id : e ?. [ '_id' ] } ) ;
880- }
881-
882- for ( const r of options . relationships || [ ] ) {
883- upload . deleteRelationships . push ( { _id : r ?. [ '_id' ] } ) ;
884- }
885-
886- this . logger . trace ( upload , 'Full upload of deletion sync job' ) ;
887- this . logger . info ( 'uploading deletion sync job' ) ;
878+ const { syncJobId, entities, relationships } = options ;
888879 const headers = this . headers ;
889- const response = await makeFetchRequest (
890- this . apiUrl +
891- `/persister/synchronization/jobs/${ options . syncJobId } /upload` ,
880+ const entitiesResponse = await makeFetchRequest (
881+ this . apiUrl + `/persister/synchronization/jobs/${ syncJobId } /entities` ,
892882 {
893883 method : 'POST' ,
894884 headers,
895- body : JSON . stringify ( upload ) ,
885+ body : JSON . stringify ( {
886+ entities,
887+ } ) ,
896888 } ,
897889 ) ;
898- return validateSyncJobResponse ( response ) ;
899- }
890+ validateSyncJobResponse ( entitiesResponse ) ;
900891
901- async uploadGraphObjectsForSyncJob ( options : {
902- syncJobId : string ;
903- entities ?: EntityForSync [ ] ;
904- relationships ?: RelationshipForSync [ ] ;
905- } ) : Promise < SyncJobResponse > {
906- const { syncJobId, entities, relationships } = options ;
907- const headers = this . headers ;
908- const response = await makeFetchRequest (
909- this . apiUrl + `/persister/synchronization/jobs/${ syncJobId } /upload` ,
892+ const relationshipsResponse = await makeFetchRequest (
893+ this . apiUrl +
894+ `/persister/synchronization/jobs/${ syncJobId } /relationships` ,
910895 {
911896 method : 'POST' ,
912897 headers,
913898 body : JSON . stringify ( {
914- entities,
915899 relationships,
916900 } ) ,
917901 } ,
918902 ) ;
919- return validateSyncJobResponse ( response ) ;
903+
904+ return validateSyncJobResponse ( relationshipsResponse ) ;
920905 }
921906
922907 async finalizeSyncJob ( options : {
@@ -1031,29 +1016,4 @@ export class JupiterOneClient {
10311016 finalizeResult,
10321017 } ;
10331018 }
1034-
1035- async bulkDelete ( data : {
1036- entities ?: Entity [ ] ;
1037- relationships ?: Relationship [ ] ;
1038- } ) : Promise < SyncJobResult | undefined > {
1039- if ( data . entities || data . relationships ) {
1040- const { job : syncJob } = await this . startSyncJob ( {
1041- source : SyncJobSources . API ,
1042- syncMode : SyncJobModes . CREATE_OR_UPDATE ,
1043- } ) ;
1044- const syncJobId = syncJob . id ;
1045- await this . uploadGraphObjectsForDeleteSyncJob ( {
1046- syncJobId,
1047- entities : data . entities ,
1048- relationships : data . relationships ,
1049- } ) ;
1050- const finalizeResult = await this . finalizeSyncJob ( { syncJobId } ) ;
1051- return {
1052- syncJobId,
1053- finalizeResult,
1054- } ;
1055- } else {
1056- this . logger . info ( 'No entities or relationships to upload.' ) ;
1057- }
1058- }
10591019}
0 commit comments