Skip to content

Commit 2d69c64

Browse files
author
Xander Dumaine
authored
Merge pull request #156 from SrdjanCosicPrica/main
Adding abort & publish events methods for jobs
2 parents ba51adb + 4938aec commit 2d69c64

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
"bunyan-category": "^0.4.0",
5050
"chalk": "^4.1.2",
5151
"commander": "^5.0.0",
52-
"eslint-config-prettier": "^6.10.1",
5352
"graphql": "^14.6.0",
5453
"graphql-tag": "^2.10.1",
5554
"inquirer": "^8.2.0",
@@ -68,6 +67,7 @@
6867
"@typescript-eslint/parser": "^5.10.2",
6968
"dotenv": "^7.0.0",
7069
"eslint": "^8.8.0",
70+
"eslint-config-prettier": "^6.10.1",
7171
"eslint-plugin-jest": "^23.8.2",
7272
"husky": "^7.0.0",
7373
"jest": "^27.4.7",

src/index.ts

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
266285
export 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

Comments
 (0)