@@ -59,8 +59,13 @@ function sleep(ms: number): Promise<NodeJS.Timeout> {
5959 } ) ;
6060}
6161
62- class FetchError extends Error {
62+ export class FetchError extends Error {
6363 httpStatusCode : number ;
64+ responseBody : string ;
65+ response : FetchResponse ;
66+ method : string ;
67+ url : string ;
68+ nameForLogging ?: string ;
6469
6570 constructor ( options : {
6671 responseBody : string ;
@@ -77,6 +82,11 @@ class FetchError extends Error {
7782 } ). Response: ${ options . responseBody } `,
7883 ) ;
7984 this . httpStatusCode = options . response . status ;
85+ this . responseBody = options . responseBody ;
86+ this . response = options . response ;
87+ this . method = options . method ;
88+ this . url = options . url ;
89+ this . nameForLogging = options . nameForLogging ;
8090 }
8191}
8292
@@ -263,6 +273,15 @@ export type SyncJobResponse = {
263273 job : SyncJob ;
264274} ;
265275
276+ export type PublishEventsResponse = {
277+ events : Array < {
278+ id : string ;
279+ name : string ;
280+ description : string ;
281+ createDate : number ;
282+ } > ;
283+ } ;
284+
266285export type ObjectDeletion = {
267286 _id : string ;
268287} ;
@@ -958,6 +977,40 @@ export class JupiterOneClient {
958977 return validateSyncJobResponse ( response ) ;
959978 }
960979
980+ async abortSyncJob ( options : {
981+ syncJobId : string ;
982+ reason : string ;
983+ } ) : Promise < SyncJobResponse > {
984+ const { syncJobId, reason } = options ;
985+ const headers = this . headers ;
986+ const response = await makeFetchRequest (
987+ this . apiUrl + `/persister/synchronization/jobs/${ syncJobId } /abort` ,
988+ {
989+ method : 'POST' ,
990+ headers,
991+ body : JSON . stringify ( { reason } ) ,
992+ } ,
993+ ) ;
994+ return validateSyncJobResponse ( response ) ;
995+ }
996+
997+ async publishEvents ( options : {
998+ syncJobId : string ;
999+ events : Array < { name : string ; description : string } > ;
1000+ } ) : Promise < PublishEventsResponse > {
1001+ const { syncJobId, events } = options ;
1002+ const headers = this . headers ;
1003+ const response = await makeFetchRequest (
1004+ this . apiUrl + `/persister/synchronization/jobs/${ syncJobId } /events` ,
1005+ {
1006+ method : 'POST' ,
1007+ headers,
1008+ body : JSON . stringify ( { events } ) ,
1009+ } ,
1010+ ) ;
1011+ return response . json ( ) ;
1012+ }
1013+
9611014 async fetchSyncJobStatus ( options : {
9621015 syncJobId : string ;
9631016 } ) : Promise < SyncJobResponse > {
0 commit comments