Skip to content

Commit 1f9d256

Browse files
authored
Merge branch 'main' into jacek/user-4607-do-not-await-nonce-in-the-clerkprovider
2 parents 526d114 + b66eb8d commit 1f9d256

3 files changed

Lines changed: 86 additions & 0 deletions

File tree

.changeset/tough-taxis-care.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/backend': minor
3+
---
4+
5+
Add `createBulk()` method to `WaitlistEntryAPI` for bulk creating waitlist entries

packages/backend/src/api/__tests__/factory.test.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,4 +465,71 @@ describe('api.client', () => {
465465
expect(response.id).toBe('mt_test');
466466
});
467467
});
468+
469+
describe('WaitlistEntry', () => {
470+
it('executes a successful backend API request to bulk create waitlist entries', async () => {
471+
const emailAddresses = ['foo@bar.com', 'bar@foo.com'];
472+
const ids = ['wle_123', 'wle_456'];
473+
const createdAt = 1700000000;
474+
const updatedAt = 1700000100;
475+
476+
server.use(
477+
http.post(
478+
`https://api.clerk.test/v1/waitlist_entries/bulk`,
479+
validateHeaders(async ({ request }) => {
480+
const body = await request.json();
481+
expect(body).toEqual([
482+
{ email_address: emailAddresses[0] },
483+
{ email_address: emailAddresses[1], notify: true },
484+
]);
485+
486+
return HttpResponse.json([
487+
{
488+
object: 'waitlist_entry',
489+
id: ids[0],
490+
email_address: emailAddresses[0],
491+
status: 'pending',
492+
is_locked: false,
493+
created_at: createdAt,
494+
updated_at: updatedAt,
495+
invitation: null,
496+
},
497+
{
498+
object: 'waitlist_entry',
499+
id: ids[1],
500+
email_address: emailAddresses[1],
501+
status: 'pending',
502+
is_locked: false,
503+
created_at: createdAt,
504+
updated_at: updatedAt,
505+
invitation: null,
506+
},
507+
]);
508+
}),
509+
),
510+
);
511+
512+
const response = await apiClient.waitlistEntries.createBulk([
513+
{ emailAddress: emailAddresses[0] },
514+
{ emailAddress: emailAddresses[1], notify: true },
515+
]);
516+
517+
expect(response).toHaveLength(2);
518+
expect(response[0].id).toBe(ids[0]);
519+
expect(response[0].emailAddress).toBe(emailAddresses[0]);
520+
expect(response[0].status).toBe('pending');
521+
expect(response[0].isLocked).toBe(false);
522+
expect(response[0].createdAt).toBe(createdAt);
523+
expect(response[0].updatedAt).toBe(updatedAt);
524+
expect(response[0].invitation).toBe(null);
525+
526+
expect(response[1].id).toBe(ids[1]);
527+
expect(response[1].emailAddress).toBe(emailAddresses[1]);
528+
expect(response[1].status).toBe('pending');
529+
expect(response[1].isLocked).toBe(false);
530+
expect(response[1].createdAt).toBe(createdAt);
531+
expect(response[1].updatedAt).toBe(updatedAt);
532+
expect(response[1].invitation).toBe(null);
533+
});
534+
});
468535
});

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ type WaitlistEntryCreateParams = {
2424
notify?: boolean;
2525
};
2626

27+
type WaitlistEntryBulkCreateParams = Array<WaitlistEntryCreateParams>;
28+
2729
type WaitlistEntryInviteParams = {
2830
/**
2931
* When true, do not error if an invitation already exists. Default: false.
@@ -56,6 +58,18 @@ export class WaitlistEntryAPI extends AbstractAPI {
5658
});
5759
}
5860

61+
/**
62+
* Bulk create waitlist entries.
63+
* @param params An array of parameters for creating waitlist entries.
64+
*/
65+
public async createBulk(params: WaitlistEntryBulkCreateParams) {
66+
return this.request<WaitlistEntry[]>({
67+
method: 'POST',
68+
path: joinPaths(basePath, 'bulk'),
69+
bodyParams: params,
70+
});
71+
}
72+
5973
/**
6074
* Invite a waitlist entry.
6175
* @param id The waitlist entry ID.

0 commit comments

Comments
 (0)