From d3f03583093afe9f3a0abedfdd70bb647d73a320 Mon Sep 17 00:00:00 2001 From: SrdjanCosicPrica <15933115+SrdjanCosicPrica@users.noreply.github.com> Date: Tue, 13 Feb 2024 11:43:46 +0000 Subject: [PATCH 1/4] Export FetchError class and add more properties --- src/index.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index ac5bd22..a2b49a6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -59,8 +59,13 @@ function sleep(ms: number): Promise { }); } -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; @@ -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; } } From ef71d19ae4f186ca4389b70e0648e2f67d20b555 Mon Sep 17 00:00:00 2001 From: SrdjanCosicPrica <15933115+SrdjanCosicPrica@users.noreply.github.com> Date: Tue, 13 Feb 2024 12:32:56 +0000 Subject: [PATCH 2/4] Add feature to abort sync job --- src/index.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/index.ts b/src/index.ts index a2b49a6..7136f9a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -968,6 +968,23 @@ export class JupiterOneClient { return validateSyncJobResponse(response); } + async abortSyncJob(options: { + syncJobId: string; + reason: string; + }): Promise { + 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 fetchSyncJobStatus(options: { syncJobId: string; }): Promise { From 9109d91d0d2b89d445bf128b06f86c765f40e836 Mon Sep 17 00:00:00 2001 From: SrdjanCosicPrica <15933115+SrdjanCosicPrica@users.noreply.github.com> Date: Tue, 13 Feb 2024 12:45:51 +0000 Subject: [PATCH 3/4] Add feature to publish events to a job --- src/index.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/index.ts b/src/index.ts index 7136f9a..ba449c9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -273,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; }; @@ -985,6 +994,23 @@ export class JupiterOneClient { return validateSyncJobResponse(response); } + async publishEvents(options: { + syncJobId: string; + events: Array<{ name: string; description: string }>; + }): Promise { + 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 { From 4938aec2c39f88a9d61e19b0ab9df40cd0d71cce Mon Sep 17 00:00:00 2001 From: SrdjanCosicPrica <15933115+SrdjanCosicPrica@users.noreply.github.com> Date: Tue, 13 Feb 2024 12:47:56 +0000 Subject: [PATCH 4/4] Move "eslint-config-prettier" to dev dependencies --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3ea8fc7..7c78313 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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",