From 7a4290f6a8b2fdd1c46077b1089c2b27df376e23 Mon Sep 17 00:00:00 2001 From: Tom Milewski Date: Mon, 14 Apr 2025 12:19:38 -0400 Subject: [PATCH] feat(backend): Add webhooks endpoints to the Backend API client --- .changeset/nice-candles-send.md | 14 ++++++++++ .../backend/src/api/endpoints/WebhookApi.ts | 28 +++++++++++++++++++ packages/backend/src/api/endpoints/index.ts | 1 + packages/backend/src/api/factory.ts | 2 ++ packages/backend/src/api/resources/JSON.ts | 4 +++ packages/backend/src/index.ts | 1 + 6 files changed, 50 insertions(+) create mode 100644 .changeset/nice-candles-send.md create mode 100644 packages/backend/src/api/endpoints/WebhookApi.ts diff --git a/.changeset/nice-candles-send.md b/.changeset/nice-candles-send.md new file mode 100644 index 00000000000..44193a7d6f6 --- /dev/null +++ b/.changeset/nice-candles-send.md @@ -0,0 +1,14 @@ +--- +'@clerk/backend': minor +--- + +Adds webhooks endpoints to the Backend API client. + +```ts + import { createClerkClient } from '@clerk/backend'; + + const clerkClient = createClerkClient(...); + await clerkClient.webhooks.createSvixApp(); + await clerkClient.webhooks.generateSvixAuthURL(); + await clerkClient.webhooks.deleteSvixApp(); +``` \ No newline at end of file diff --git a/packages/backend/src/api/endpoints/WebhookApi.ts b/packages/backend/src/api/endpoints/WebhookApi.ts new file mode 100644 index 00000000000..4fed9b2bb25 --- /dev/null +++ b/packages/backend/src/api/endpoints/WebhookApi.ts @@ -0,0 +1,28 @@ +import { joinPaths } from '../../util/path'; +import type { WebhooksSvixJSON } from '../resources/JSON'; +import { AbstractAPI } from './AbstractApi'; + +const basePath = '/webhooks'; + +export class WebhookAPI extends AbstractAPI { + public async createSvixApp() { + return this.request({ + method: 'POST', + path: joinPaths(basePath, 'svix'), + }); + } + + public async generateSvixAuthURL() { + return this.request({ + method: 'POST', + path: joinPaths(basePath, 'svix_url'), + }); + } + + public async deleteSvixApp() { + return this.request({ + method: 'DELETE', + path: joinPaths(basePath, 'svix'), + }); + } +} diff --git a/packages/backend/src/api/endpoints/index.ts b/packages/backend/src/api/endpoints/index.ts index 90ca493b116..7d5ee343c2b 100644 --- a/packages/backend/src/api/endpoints/index.ts +++ b/packages/backend/src/api/endpoints/index.ts @@ -16,3 +16,4 @@ export * from './SignInTokenApi'; export * from './UserApi'; export * from './SamlConnectionApi'; export * from './TestingTokenApi'; +export * from './WebhookApi'; diff --git a/packages/backend/src/api/factory.ts b/packages/backend/src/api/factory.ts index 4e81685b813..8bf59573373 100644 --- a/packages/backend/src/api/factory.ts +++ b/packages/backend/src/api/factory.ts @@ -16,6 +16,7 @@ import { SignInTokenAPI, TestingTokenAPI, UserAPI, + WebhookAPI, } from './endpoints'; import { buildRequest } from './request'; @@ -46,5 +47,6 @@ export function createBackendApiClient(options: CreateBackendApiOptions) { domains: new DomainAPI(request), samlConnections: new SamlConnectionAPI(request), testingTokens: new TestingTokenAPI(request), + webhooks: new WebhookAPI(request), }; } diff --git a/packages/backend/src/api/resources/JSON.ts b/packages/backend/src/api/resources/JSON.ts index 08201d86921..4aaf3018651 100644 --- a/packages/backend/src/api/resources/JSON.ts +++ b/packages/backend/src/api/resources/JSON.ts @@ -524,3 +524,7 @@ export interface SamlAccountConnectionJSON extends ClerkResourceJSON { created_at: number; updated_at: number; } + +export interface WebhooksSvixJSON { + svix_url: string; +} diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts index eda48e7e90a..e6990393b6f 100644 --- a/packages/backend/src/index.ts +++ b/packages/backend/src/index.ts @@ -88,6 +88,7 @@ export type { DeletedObjectJSON, PaginatedResponseJSON, TestingTokenJSON, + WebhooksSvixJSON, } from './api/resources/JSON'; /**