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
5 changes: 5 additions & 0 deletions .changeset/tough-taxis-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/backend': minor
---

Add `createBulk()` method to `WaitlistEntryAPI` for bulk creating waitlist entries
67 changes: 67 additions & 0 deletions packages/backend/src/api/__tests__/factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,4 +465,71 @@ describe('api.client', () => {
expect(response.id).toBe('mt_test');
});
});

describe('WaitlistEntry', () => {
it('executes a successful backend API request to bulk create waitlist entries', async () => {
const emailAddresses = ['foo@bar.com', 'bar@foo.com'];
const ids = ['wle_123', 'wle_456'];
const createdAt = 1700000000;
const updatedAt = 1700000100;

server.use(
http.post(
`https://api.clerk.test/v1/waitlist_entries/bulk`,
validateHeaders(async ({ request }) => {
const body = await request.json();
expect(body).toEqual([
{ email_address: emailAddresses[0] },
{ email_address: emailAddresses[1], notify: true },
]);

return HttpResponse.json([
{
object: 'waitlist_entry',
id: ids[0],
email_address: emailAddresses[0],
status: 'pending',
is_locked: false,
created_at: createdAt,
updated_at: updatedAt,
invitation: null,
},
{
object: 'waitlist_entry',
id: ids[1],
email_address: emailAddresses[1],
status: 'pending',
is_locked: false,
created_at: createdAt,
updated_at: updatedAt,
invitation: null,
},
]);
}),
),
);

const response = await apiClient.waitlistEntries.createBulk([
{ emailAddress: emailAddresses[0] },
{ emailAddress: emailAddresses[1], notify: true },
]);

expect(response).toHaveLength(2);
expect(response[0].id).toBe(ids[0]);
expect(response[0].emailAddress).toBe(emailAddresses[0]);
expect(response[0].status).toBe('pending');
expect(response[0].isLocked).toBe(false);
expect(response[0].createdAt).toBe(createdAt);
expect(response[0].updatedAt).toBe(updatedAt);
expect(response[0].invitation).toBe(null);

expect(response[1].id).toBe(ids[1]);
expect(response[1].emailAddress).toBe(emailAddresses[1]);
expect(response[1].status).toBe('pending');
expect(response[1].isLocked).toBe(false);
expect(response[1].createdAt).toBe(createdAt);
expect(response[1].updatedAt).toBe(updatedAt);
expect(response[1].invitation).toBe(null);
});
});
});
14 changes: 14 additions & 0 deletions packages/backend/src/api/endpoints/WaitlistEntryApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type WaitlistEntryCreateParams = {
notify?: boolean;
};

type WaitlistEntryBulkCreateParams = Array<WaitlistEntryCreateParams>;

type WaitlistEntryInviteParams = {
/**
* When true, do not error if an invitation already exists. Default: false.
Expand Down Expand Up @@ -56,6 +58,18 @@ export class WaitlistEntryAPI extends AbstractAPI {
});
}

/**
* Bulk create waitlist entries.
* @param params An array of parameters for creating waitlist entries.
*/
public async createBulk(params: WaitlistEntryBulkCreateParams) {
return this.request<WaitlistEntry[]>({
method: 'POST',
path: joinPaths(basePath, 'bulk'),
bodyParams: params,
});
}

/**
* Invite a waitlist entry.
* @param id The waitlist entry ID.
Expand Down
Loading