From 18096b68d1779d14d373b902e5bbb119b59112ed Mon Sep 17 00:00:00 2001 From: Yevheniy Oliynyk Date: Sun, 7 Jul 2024 13:41:14 +0200 Subject: [PATCH] wip --- src/organizationWebhooks/index.ts | 25 +++++++++++++++++++++---- src/webhooks/index.ts | 4 ++-- tests/organizationWebhooks/api.test.ts | 4 ++-- tests/webhooks/api.test.ts | 4 ++-- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/organizationWebhooks/index.ts b/src/organizationWebhooks/index.ts index a0425c82d..1dcafb1ec 100644 --- a/src/organizationWebhooks/index.ts +++ b/src/organizationWebhooks/index.ts @@ -11,7 +11,7 @@ export class OrganizationWebhooks extends CrowdinApi { * @param options optional pagination parameters for the request * @see https://developer.crowdin.com/api/v2/#operation/api.webhooks.getMany */ - listWebhooks(options?: PaginationOptions): Promise> { + listWebhooks(options?: PaginationOptions): Promise> { const url = `${this.url}/webhooks`; return this.getList(url, options?.limit, options?.offset); } @@ -20,7 +20,9 @@ export class OrganizationWebhooks extends CrowdinApi { * @param request request body * @see https://developer.crowdin.com/api/v2/#operation/api.webhooks.post */ - addWebhook(request: WebhooksModel.AddWebhookRequest): Promise> { + addWebhook( + request: OrganizationWebhooksModel.AddOrganizationWebhookRequest, + ): Promise> { const url = `${this.url}/webhooks`; return this.post(url, request, this.defaultConfig()); } @@ -29,7 +31,7 @@ export class OrganizationWebhooks extends CrowdinApi { * @param webhookId webhook identifier * @see https://developer.crowdin.com/api/v2/#operation/api.webhooks.get */ - getWebhook(webhookId: number): Promise> { + getWebhook(webhookId: number): Promise> { const url = `${this.url}/webhooks/${webhookId}`; return this.get(url, this.defaultConfig()); } @@ -48,8 +50,23 @@ export class OrganizationWebhooks extends CrowdinApi { * @param request request body * @see https://developer.crowdin.com/api/v2/#operation/api.webhooks.patch */ - editWebhook(webhookId: number, request: PatchRequest[]): Promise> { + editWebhook( + webhookId: number, + request: PatchRequest[], + ): Promise> { const url = `${this.url}/webhooks/${webhookId}`; return this.patch(url, request, this.defaultConfig()); } } + +export namespace OrganizationWebhooksModel { + export type OrganizationWebhook = Omit & { + events: Event[]; + }; + + export type AddOrganizationWebhookRequest = Omit & { + events: Event[]; + }; + + export type Event = 'group.created' | 'group.deleted' | 'project.created' | 'project.deleted'; +} diff --git a/src/webhooks/index.ts b/src/webhooks/index.ts index 699726a67..a78492ccc 100644 --- a/src/webhooks/index.ts +++ b/src/webhooks/index.ts @@ -101,12 +101,12 @@ export namespace WebhooksModel { export interface AddWebhookRequest { name: string; url: string; + events: Event[]; + requestType: RequestType; isActive?: boolean; batchingEnabled?: boolean; contentType?: ContentType; - events: Event[]; headers?: Record; - requestType: RequestType; payload?: Record; } diff --git a/tests/organizationWebhooks/api.test.ts b/tests/organizationWebhooks/api.test.ts index f8b341518..64478bc84 100644 --- a/tests/organizationWebhooks/api.test.ts +++ b/tests/organizationWebhooks/api.test.ts @@ -40,7 +40,7 @@ describe('Organization Webhooks API', () => { { name: name, url: url, - events: [], + events: ['project.created'], requestType: requestType, }, { @@ -108,7 +108,7 @@ describe('Organization Webhooks API', () => { const webhook = await api.addWebhook({ name: name, url: url, - events: [], + events: ['project.created'], requestType: requestType, }); expect(webhook.data.id).toBe(webhookId); diff --git a/tests/webhooks/api.test.ts b/tests/webhooks/api.test.ts index 3e998d17b..fce8b534a 100644 --- a/tests/webhooks/api.test.ts +++ b/tests/webhooks/api.test.ts @@ -41,7 +41,7 @@ describe('Web-hooks API', () => { { name: name, url: url, - events: [], + events: ['file.added'], requestType: requestType, }, { @@ -109,7 +109,7 @@ describe('Web-hooks API', () => { const webhook = await api.addWebhook(projectId, { name: name, url: url, - events: [], + events: ['file.added'], requestType: requestType, }); expect(webhook.data.id).toBe(webhookId);