From 34a12a6ee0f4845b848be65ca17d35ac974a0c73 Mon Sep 17 00:00:00 2001 From: ghostrider-05 Date: Fri, 18 Oct 2024 13:05:12 +0200 Subject: [PATCH] add DELETE /webhooks/{id} endpoint --- src/rest/v2/oauth2/rest.ts | 5 +++++ src/rest/v2/oauth2/routes.ts | 1 + src/rest/v2/webhooks/client.ts | 18 +++++++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/rest/v2/oauth2/rest.ts b/src/rest/v2/oauth2/rest.ts index 7f26980..7a65172 100644 --- a/src/rest/v2/oauth2/rest.ts +++ b/src/rest/v2/oauth2/rest.ts @@ -209,6 +209,7 @@ export const DefaultRestOptions: RESTOptions = { } export enum RequestMethod { + Delete = 'DELETE', Get = 'GET', Patch = 'PATCH', Post = 'POST', @@ -346,6 +347,10 @@ export class RestClient { clearInterval(this.requestInterval) } + public async delete (path: string, options?: RequestOptions) { + return await this.request({ ...options, method: RequestMethod.Delete, path }) + } + public async get (path: string, options?: RequestOptions) { return await this.request({ ...options, method: RequestMethod.Get, path }) } diff --git a/src/rest/v2/oauth2/routes.ts b/src/rest/v2/oauth2/routes.ts index 33d3852..b35baf0 100644 --- a/src/rest/v2/oauth2/routes.ts +++ b/src/rest/v2/oauth2/routes.ts @@ -72,6 +72,7 @@ export const Oauth2Routes = { * Routes for: * * - PATCH `/webhooks/{webhookId}` + * - DELETE `/webhooks/{webhookId}` * @param webhookId The id of the webhook */ webhook (webhookId: string) { diff --git a/src/rest/v2/webhooks/client.ts b/src/rest/v2/webhooks/client.ts index b36a10a..00854cf 100644 --- a/src/rest/v2/webhooks/client.ts +++ b/src/rest/v2/webhooks/client.ts @@ -9,7 +9,7 @@ import { type Webhook, } from '../../../schemas/v2' -import { Oauth2Routes } from '../oauth2' +import { Oauth2Routes, RequestMethod } from '../oauth2' import { createQuery, type BasePatreonQueryType, type GetResponsePayload } from '../query' import type { Oauth2RouteOptions } from '../clients/baseMethods' @@ -139,6 +139,22 @@ export class WebhookClient { }) as unknown as APIPostWebhookResponse | undefined } + /** + * Delete a webhook created by this client + * @param webhookId The webhook id + * @param options Request options + * @returns the webhooks managed by this client + */ + public async deleteWebhook( + webhookId: string, + options?: Oauth2WebhookRouteOptions, + ): Promise { + await this.oauth.fetch(Oauth2Routes.webhook(webhookId), createQuery(new URLSearchParams()), { + ...(options ?? {}), + method: RequestMethod.Delete, + }) + } + /** * Check if the webhook should be unpaused as events have failed to send. *