Skip to content

Commit 66de292

Browse files
authored
Add support for "Batch Delete Users" (#568)
Fixes descope/etc#11608
1 parent 0295559 commit 66de292

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,8 @@ await descopeClient.management.user.patch('desmond@descope.com', options);
827827

828828
// User deletion cannot be undone. Use carefully.
829829
await descopeClient.management.user.delete('desmond@descope.com');
830+
// Delete a batch of users. This requires Descope user IDs.
831+
await descopeClient.management.user.deleteBatch(['<user-ID-1>', '<user-ID-2>']);
830832

831833
// Load specific user
832834
const userRes = await descopeClient.management.user.load('desmond@descope.com');

lib/management/paths.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default {
77
update: '/v1/mgmt/user/update',
88
patch: '/v1/mgmt/user/patch',
99
delete: '/v1/mgmt/user/delete',
10+
deleteBatch: '/v1/mgmt/user/delete/batch',
1011
deleteAllTestUsers: '/v1/mgmt/user/test/delete/all',
1112
load: '/v1/mgmt/user',
1213
logout: '/v1/mgmt/user/logout',

lib/management/user.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,35 @@ describe('Management User', () => {
666666
});
667667
});
668668

669+
describe('deleteBatch', () => {
670+
it('should send the correct request and receive correct response', async () => {
671+
const httpResponse = {
672+
ok: true,
673+
json: () => {},
674+
clone: () => ({
675+
json: () => Promise.resolve({}),
676+
}),
677+
status: 200,
678+
};
679+
mockHttpClient.post.mockResolvedValue(httpResponse);
680+
681+
const resp: SdkResponse<UserResponse> = await management.user.deleteBatch(['a', 'b']);
682+
683+
expect(mockHttpClient.post).toHaveBeenCalledWith(
684+
apiPaths.user.deleteBatch,
685+
{ userIds: ['a', 'b'] },
686+
{ token: 'key' },
687+
);
688+
689+
expect(resp).toEqual({
690+
code: 200,
691+
data: {},
692+
ok: true,
693+
response: httpResponse,
694+
});
695+
});
696+
});
697+
669698
describe('deleteByUserId', () => {
670699
it('should send the correct request and receive correct response', async () => {
671700
const httpResponse = {

lib/management/user.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,10 @@ const withUser = (sdk: CoreSdk, managementKey?: string) => {
485485
),
486486
(data) => data,
487487
),
488+
deleteBatch: (userIds: string[]): Promise<SdkResponse<never>> =>
489+
transformResponse(
490+
sdk.httpClient.post(apiPaths.user.deleteBatch, { userIds }, { token: managementKey }),
491+
),
488492
update,
489493
patch,
490494
/**

0 commit comments

Comments
 (0)