Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/nice-candles-send.md
Original file line number Diff line number Diff line change
@@ -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();
```
28 changes: 28 additions & 0 deletions packages/backend/src/api/endpoints/WebhookApi.ts
Original file line number Diff line number Diff line change
@@ -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<WebhooksSvixJSON>({
method: 'POST',
path: joinPaths(basePath, 'svix'),
});
}

public async generateSvixAuthURL() {
return this.request<WebhooksSvixJSON>({
method: 'POST',
path: joinPaths(basePath, 'svix_url'),
});
}

public async deleteSvixApp() {
return this.request<void>({
method: 'DELETE',
path: joinPaths(basePath, 'svix'),
});
}
}
1 change: 1 addition & 0 deletions packages/backend/src/api/endpoints/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export * from './SignInTokenApi';
export * from './UserApi';
export * from './SamlConnectionApi';
export * from './TestingTokenApi';
export * from './WebhookApi';
2 changes: 2 additions & 0 deletions packages/backend/src/api/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
SignInTokenAPI,
TestingTokenAPI,
UserAPI,
WebhookAPI,
} from './endpoints';
import { buildRequest } from './request';

Expand Down Expand Up @@ -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),
};
}
4 changes: 4 additions & 0 deletions packages/backend/src/api/resources/JSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,7 @@ export interface SamlAccountConnectionJSON extends ClerkResourceJSON {
created_at: number;
updated_at: number;
}

export interface WebhooksSvixJSON {
svix_url: string;
}
1 change: 1 addition & 0 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export type {
DeletedObjectJSON,
PaginatedResponseJSON,
TestingTokenJSON,
WebhooksSvixJSON,
} from './api/resources/JSON';

/**
Expand Down