Skip to content

Commit 6cba4e2

Browse files
authored
feat(backend): Add Waitlist Entry endpoints to Backend API client (#5591)
1 parent 4307e64 commit 6cba4e2

File tree

9 files changed

+100
-4
lines changed

9 files changed

+100
-4
lines changed

.changeset/thick-showers-drop.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@clerk/backend': patch
3+
---
4+
5+
Adds the ability to list and create waitlist entries to the Backend API client.
6+
7+
8+
```ts
9+
import { createClerkClient } from '@clerk/backend';
10+
11+
const clerkClient = createClerkClient(...);
12+
13+
await clerkClient.waitlistEntries.list({...});
14+
await clerkClient.waitlistEntries.create({
15+
emailAddress: '[email protected]',
16+
notify: true
17+
});
18+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import type { ClerkPaginationRequest } from '@clerk/types';
2+
3+
import type { PaginatedResourceResponse } from '../resources/Deserializer';
4+
import type { WaitlistEntryStatus } from '../resources/Enums';
5+
import type { WaitlistEntry } from '../resources/WaitlistEntry';
6+
import { AbstractAPI } from './AbstractApi';
7+
import type { WithSign } from './util-types';
8+
9+
const basePath = '/waitlist_entries';
10+
11+
type WaitlistEntryListParams = ClerkPaginationRequest<{
12+
/**
13+
* Filter waitlist entries by `email_address` or `id`
14+
*/
15+
query?: string;
16+
status?: WaitlistEntryStatus;
17+
orderBy?: WithSign<'created_at' | 'invited_at' | 'email_address'>;
18+
}>;
19+
20+
type WaitlistEntryCreateParams = {
21+
emailAddress: string;
22+
notify?: boolean;
23+
};
24+
25+
export class WaitlistEntryAPI extends AbstractAPI {
26+
public async list(params: WaitlistEntryListParams = {}) {
27+
return this.request<PaginatedResourceResponse<WaitlistEntry>>({
28+
method: 'GET',
29+
path: basePath,
30+
queryParams: params,
31+
});
32+
}
33+
34+
public async create(params: WaitlistEntryCreateParams) {
35+
return this.request<WaitlistEntry>({
36+
method: 'POST',
37+
path: basePath,
38+
bodyParams: params,
39+
});
40+
}
41+
}

packages/backend/src/api/endpoints/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ export * from './SessionApi';
2020
export * from './SignInTokenApi';
2121
export * from './TestingTokenApi';
2222
export * from './UserApi';
23+
export * from './WaitlistEntryApi';
2324
export * from './WebhookApi';

packages/backend/src/api/factory.ts

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
SignInTokenAPI,
2121
TestingTokenAPI,
2222
UserAPI,
23+
WaitlistEntryAPI,
2324
WebhookAPI,
2425
} from './endpoints';
2526
import { buildRequest } from './request';
@@ -55,6 +56,7 @@ export function createBackendApiClient(options: CreateBackendApiOptions) {
5556
signInTokens: new SignInTokenAPI(request),
5657
testingTokens: new TestingTokenAPI(request),
5758
users: new UserAPI(request),
59+
waitlistEntries: new WaitlistEntryAPI(request),
5860
webhooks: new WebhookAPI(request),
5961
};
6062
}

packages/backend/src/api/resources/Deserializer.ts

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
import { AccountlessApplication } from './AccountlessApplication';
3232
import type { PaginatedResponseJSON } from './JSON';
3333
import { ObjectType } from './JSON';
34+
import { WaitlistEntry } from './WaitlistEntry';
3435

3536
type ResourceResponse<T> = {
3637
data: T;
@@ -135,6 +136,8 @@ function jsonToObject(item: any): any {
135136
return getCount(item);
136137
case ObjectType.User:
137138
return User.fromJSON(item);
139+
case ObjectType.WaitlistEntry:
140+
return WaitlistEntry.fromJSON(item);
138141
default:
139142
return item;
140143
}

packages/backend/src/api/resources/Enums.ts

+2
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,5 @@ export type ActorTokenStatus = (typeof ActorTokenStatus)[keyof typeof ActorToken
5454
export type AllowlistIdentifierType = 'email_address' | 'phone_number' | 'web3_wallet';
5555

5656
export type BlocklistIdentifierType = AllowlistIdentifierType;
57+
58+
export type WaitlistEntryStatus = 'pending' | 'invited' | 'completed' | 'rejected';

packages/backend/src/api/resources/JSON.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {
1111
OrganizationMembershipRole,
1212
SignInStatus,
1313
SignUpStatus,
14+
WaitlistEntryStatus,
1415
} from './Enums';
1516

1617
export const ObjectType = {
@@ -543,13 +544,13 @@ export interface VerificationJSON extends ClerkResourceJSON {
543544
}
544545

545546
export interface WaitlistEntryJSON extends ClerkResourceJSON {
546-
created_at: number;
547-
email_address: string;
547+
object: typeof ObjectType.WaitlistEntry;
548548
id: string;
549+
status: WaitlistEntryStatus;
550+
email_address: string;
549551
invitation: InvitationJSON | null;
550552
is_locked: boolean;
551-
object: typeof ObjectType.WaitlistEntry;
552-
status: string;
553+
created_at: number;
553554
updated_at: number;
554555
}
555556

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { WaitlistEntryStatus } from './Enums';
2+
import { Invitation } from './Invitation';
3+
import type { WaitlistEntryJSON } from './JSON';
4+
5+
export class WaitlistEntry {
6+
constructor(
7+
readonly id: string,
8+
readonly emailAddress: string,
9+
readonly status: WaitlistEntryStatus,
10+
readonly invitation: Invitation | null,
11+
readonly createdAt: number,
12+
readonly updatedAt: number,
13+
readonly isLocked?: boolean,
14+
) {}
15+
16+
static fromJSON(data: WaitlistEntryJSON): WaitlistEntry {
17+
return new WaitlistEntry(
18+
data.id,
19+
data.email_address,
20+
data.status,
21+
data.invitation && Invitation.fromJSON(data.invitation),
22+
data.created_at,
23+
data.updated_at,
24+
data.is_locked,
25+
);
26+
}
27+
}

packages/backend/src/api/resources/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export * from './User';
4545
export * from './Verification';
4646
export * from './SamlConnection';
4747
export * from './TestingToken';
48+
export * from './WaitlistEntry';
4849

4950
export type {
5051
EmailWebhookEvent,

0 commit comments

Comments
 (0)