Skip to content

Commit

Permalink
Merge pull request #156 from SrdjanCosicPrica/main
Browse files Browse the repository at this point in the history
Adding abort & publish events methods for jobs
  • Loading branch information
Xander Dumaine authored Feb 15, 2024
2 parents ba51adb + 4938aec commit 2d69c64
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"bunyan-category": "^0.4.0",
"chalk": "^4.1.2",
"commander": "^5.0.0",
"eslint-config-prettier": "^6.10.1",
"graphql": "^14.6.0",
"graphql-tag": "^2.10.1",
"inquirer": "^8.2.0",
Expand All @@ -68,6 +67,7 @@
"@typescript-eslint/parser": "^5.10.2",
"dotenv": "^7.0.0",
"eslint": "^8.8.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-jest": "^23.8.2",
"husky": "^7.0.0",
"jest": "^27.4.7",
Expand Down
55 changes: 54 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ function sleep(ms: number): Promise<NodeJS.Timeout> {
});
}

class FetchError extends Error {
export class FetchError extends Error {
httpStatusCode: number;
responseBody: string;
response: FetchResponse;
method: string;
url: string;
nameForLogging?: string;

constructor(options: {
responseBody: string;
Expand All @@ -77,6 +82,11 @@ class FetchError extends Error {
}). Response: ${options.responseBody}`,
);
this.httpStatusCode = options.response.status;
this.responseBody = options.responseBody;
this.response = options.response;
this.method = options.method;
this.url = options.url;
this.nameForLogging = options.nameForLogging;
}
}

Expand Down Expand Up @@ -263,6 +273,15 @@ export type SyncJobResponse = {
job: SyncJob;
};

export type PublishEventsResponse = {
events: Array<{
id: string;
name: string;
description: string;
createDate: number;
}>;
};

export type ObjectDeletion = {
_id: string;
};
Expand Down Expand Up @@ -958,6 +977,40 @@ export class JupiterOneClient {
return validateSyncJobResponse(response);
}

async abortSyncJob(options: {
syncJobId: string;
reason: string;
}): Promise<SyncJobResponse> {
const { syncJobId, reason } = options;
const headers = this.headers;
const response = await makeFetchRequest(
this.apiUrl + `/persister/synchronization/jobs/${syncJobId}/abort`,
{
method: 'POST',
headers,
body: JSON.stringify({ reason }),
},
);
return validateSyncJobResponse(response);
}

async publishEvents(options: {
syncJobId: string;
events: Array<{ name: string; description: string }>;
}): Promise<PublishEventsResponse> {
const { syncJobId, events } = options;
const headers = this.headers;
const response = await makeFetchRequest(
this.apiUrl + `/persister/synchronization/jobs/${syncJobId}/events`,
{
method: 'POST',
headers,
body: JSON.stringify({ events }),
},
);
return response.json();
}

async fetchSyncJobStatus(options: {
syncJobId: string;
}): Promise<SyncJobResponse> {
Expand Down

0 comments on commit 2d69c64

Please sign in to comment.