Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
yevheniyJ committed Jul 7, 2024
1 parent bca7f21 commit 18096b6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
25 changes: 21 additions & 4 deletions src/organizationWebhooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResponseList<WebhooksModel.Webhook>> {
listWebhooks(options?: PaginationOptions): Promise<ResponseList<OrganizationWebhooksModel.OrganizationWebhook>> {
const url = `${this.url}/webhooks`;
return this.getList(url, options?.limit, options?.offset);
}
Expand All @@ -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<ResponseObject<WebhooksModel.Webhook>> {
addWebhook(
request: OrganizationWebhooksModel.AddOrganizationWebhookRequest,
): Promise<ResponseObject<OrganizationWebhooksModel.OrganizationWebhook>> {
const url = `${this.url}/webhooks`;
return this.post(url, request, this.defaultConfig());
}
Expand All @@ -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<ResponseObject<WebhooksModel.Webhook>> {
getWebhook(webhookId: number): Promise<ResponseObject<OrganizationWebhooksModel.OrganizationWebhook>> {
const url = `${this.url}/webhooks/${webhookId}`;
return this.get(url, this.defaultConfig());
}
Expand All @@ -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<ResponseObject<WebhooksModel.Webhook>> {
editWebhook(
webhookId: number,
request: PatchRequest[],
): Promise<ResponseObject<OrganizationWebhooksModel.OrganizationWebhook>> {
const url = `${this.url}/webhooks/${webhookId}`;
return this.patch(url, request, this.defaultConfig());
}
}

export namespace OrganizationWebhooksModel {
export type OrganizationWebhook = Omit<WebhooksModel.Webhook, 'projectId' | 'events'> & {
events: Event[];
};

export type AddOrganizationWebhookRequest = Omit<WebhooksModel.AddWebhookRequest, 'events'> & {
events: Event[];
};

export type Event = 'group.created' | 'group.deleted' | 'project.created' | 'project.deleted';
}
4 changes: 2 additions & 2 deletions src/webhooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;
requestType: RequestType;
payload?: Record<string, any>;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/organizationWebhooks/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Organization Webhooks API', () => {
{
name: name,
url: url,
events: [],
events: ['project.created'],
requestType: requestType,
},
{
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/webhooks/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('Web-hooks API', () => {
{
name: name,
url: url,
events: [],
events: ['file.added'],
requestType: requestType,
},
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 18096b6

Please sign in to comment.