Skip to content

Commit f22b8b0

Browse files
yosiharanclaude
andauthored
feat(user): rename loginId to loginIdOrUserId in user management methods (#691)
* feat(user): rename loginId to loginIdOrUserId in user management methods Renames the `loginId` parameter to `loginIdOrUserId` across 22 user management methods to clarify that both login IDs and user IDs are accepted identifiers, aligning with the go-sdk naming convention. The JSON field sent to the Descope API remains `loginId` unchanged. Adds `PatchUserOptionsUsingIdentifier` interface for `patchBatch` with backward-compatible deprecated `loginId` field. Resolves: descope/etc#14620 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(user): address patchBatch edge cases and update overload formatting - Add runtime guard in patchBatch throwing if neither loginIdOrUserId nor loginId is provided - Replace PatchUserOptionsUsingIdentifier interface with a union type that enforces at least one identifier at compile time - Add tests for deprecated loginId backward-compat path and missing identifier error - Revert update() overload 1 to single-line form (no-op formatting) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * test(user): use loginId for user3 in main patchBatch test for BC coverage The main test now mixes loginIdOrUserId (user1, user2) and loginId (user3), covering backward compatibility inline without a separate test case. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(test): use synchronous toThrow for patchBatch missing-identifier test The error is thrown synchronously inside Array.map before any promise is created, so rejects.toThrow() never receives a rejected promise. Switch to the synchronous expect(() => ...).toThrow() form. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore: prettier fix --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 444d52f commit f22b8b0

File tree

2 files changed

+139
-60
lines changed

2 files changed

+139
-60
lines changed

lib/management/user.test.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,13 +620,13 @@ describe('Management User', () => {
620620
mockHttpClient.patch.mockResolvedValue(httpResponse);
621621
const resp: SdkResponse<PatchUserBatchResponse> = await management.user.patchBatch([
622622
{
623-
loginId: 'user1',
623+
loginIdOrUserId: 'user1',
624624
email: 'user1@example.com',
625625
displayName: 'User One',
626626
roles: ['role1'],
627627
},
628628
{
629-
loginId: 'user2',
629+
loginIdOrUserId: 'user2',
630630
phone: '+1234567890',
631631
verifiedPhone: true,
632632
customAttributes: { department: 'engineering' },
@@ -698,7 +698,7 @@ describe('Management User', () => {
698698
mockHttpClient.patch.mockResolvedValue(httpResponse);
699699
await management.user.patchBatch([
700700
{
701-
loginId: 'user1',
701+
loginIdOrUserId: 'user1',
702702
email: 'user1@example.com',
703703
phone: undefined,
704704
displayName: 'Updated Name',
@@ -718,6 +718,28 @@ describe('Management User', () => {
718718
],
719719
});
720720
});
721+
722+
it('should support deprecated loginId field for backward compatibility', async () => {
723+
const httpResponse = {
724+
ok: true,
725+
json: () => mockMgmtPatchBatchResponse,
726+
clone: () => ({
727+
json: () => Promise.resolve(mockMgmtPatchBatchResponse),
728+
}),
729+
status: 200,
730+
};
731+
mockHttpClient.patch.mockResolvedValue(httpResponse);
732+
await management.user.patchBatch([{ loginId: 'user1', email: 'user1@example.com' }]);
733+
expect(mockHttpClient.patch).toHaveBeenCalledWith(apiPaths.user.patchBatch, {
734+
users: [{ loginId: 'user1', email: 'user1@example.com' }],
735+
});
736+
});
737+
738+
it('should throw if neither loginIdOrUserId nor loginId is provided', async () => {
739+
await expect(
740+
management.user.patchBatch([{ loginIdOrUserId: undefined, loginId: undefined } as any]),
741+
).rejects.toThrow('patchBatch: each user must have loginIdOrUserId or loginId');
742+
});
721743
});
722744

723745
describe('delete', () => {

0 commit comments

Comments
 (0)