Skip to content

Commit 2749a08

Browse files
dorshaclaude
andcommitted
feat: add total field to user search API response
The search API returns both users array and total count, but the SDK was only returning the users array. This change updates the SDK to return both fields in a UserSearchResponse object. Changes: - Added UserSearchResponse type with users and total fields - Updated search() and searchTestUsers() to return UserSearchResponse - Updated internal MultipleUsersResponse type to include total field - Updated tests to verify total field is returned - Kept deprecated searchAll() unchanged for backward compatibility Fixes issue where SDK users couldn't access the total count returned by the API, making pagination planning difficult. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 24d4316 commit 2749a08

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

lib/management/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,11 @@ export type PatchUserBatchResponse = {
582582
additionalErrors: Record<string, string>;
583583
};
584584

585+
export type UserSearchResponse = {
586+
users: UserResponse[];
587+
total: number;
588+
};
589+
585590
/**
586591
* Search options to filter which audit records we should retrieve.
587592
* All parameters are optional. `From` is currently limited to 30 days.

lib/management/user.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
CreateOrInviteBatchResponse,
1212
PatchUserBatchResponse,
1313
UserPasswordHashed,
14+
UserSearchResponse,
1415
} from './types';
1516

1617
const management = withManagement(mockHttpClient);
@@ -25,6 +26,7 @@ const mockMgmtUserResponse = {
2526

2627
const mockMgmtUsersResponse = {
2728
users: [mockUserResponse],
29+
total: 1,
2830
};
2931

3032
const mockMgmtInviteBatchResponse = {
@@ -1012,7 +1014,7 @@ describe('Management User', () => {
10121014
};
10131015
mockHttpClient.post.mockResolvedValue(httpResponse);
10141016
const now = new Date().getTime();
1015-
const resp: SdkResponse<UserResponse[]> = await management.user.searchTestUsers({
1017+
const resp: SdkResponse<UserSearchResponse> = await management.user.searchTestUsers({
10161018
tenantIds: ['t1'],
10171019
roles: ['r1'],
10181020
limit: 100,
@@ -1050,7 +1052,7 @@ describe('Management User', () => {
10501052

10511053
expect(resp).toEqual({
10521054
code: 200,
1053-
data: [mockUserResponse],
1055+
data: { users: [mockUserResponse], total: 1 },
10541056
ok: true,
10551057
response: httpResponse,
10561058
});
@@ -1069,7 +1071,7 @@ describe('Management User', () => {
10691071
};
10701072
mockHttpClient.post.mockResolvedValue(httpResponse);
10711073
const now = new Date().getTime();
1072-
const resp: SdkResponse<UserResponse[]> = await management.user.search({
1074+
const resp: SdkResponse<UserSearchResponse> = await management.user.search({
10731075
tenantIds: ['t1'],
10741076
roles: ['r1'],
10751077
limit: 100,
@@ -1105,7 +1107,7 @@ describe('Management User', () => {
11051107

11061108
expect(resp).toEqual({
11071109
code: 200,
1108-
data: [mockUserResponse],
1110+
data: { users: [mockUserResponse], total: 1 },
11091111
ok: true,
11101112
response: httpResponse,
11111113
});

lib/management/user.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
TemplateOptions,
2222
ProviderTokenOptions,
2323
UserOptions,
24+
UserSearchResponse,
2425
} from './types';
2526
import { DeliveryMethodForTestUser } from '../types';
2627
import apiPaths from './paths';
@@ -66,6 +67,7 @@ type SingleUserResponse = {
6667

6768
type MultipleUsersResponse = {
6869
users: UserResponse[];
70+
total: number;
6971
};
7072

7173
const withUser = (httpClient: HttpClient) => {
@@ -618,25 +620,25 @@ const withUser = (httpClient: HttpClient) => {
618620
}),
619621
(data) => data.users,
620622
),
621-
searchTestUsers: (searchReq: SearchRequest): Promise<SdkResponse<UserResponse[]>> =>
622-
transformResponse<MultipleUsersResponse, UserResponse[]>(
623+
searchTestUsers: (searchReq: SearchRequest): Promise<SdkResponse<UserSearchResponse>> =>
624+
transformResponse<MultipleUsersResponse, UserSearchResponse>(
623625
httpClient.post(apiPaths.user.searchTestUsers, {
624626
...searchReq,
625627
withTestUser: true,
626628
testUsersOnly: true,
627629
roleNames: searchReq.roles,
628630
roles: undefined,
629631
}),
630-
(data) => data.users,
632+
(data) => ({ users: data.users, total: data.total }),
631633
),
632-
search: (searchReq: SearchRequest): Promise<SdkResponse<UserResponse[]>> =>
633-
transformResponse<MultipleUsersResponse, UserResponse[]>(
634+
search: (searchReq: SearchRequest): Promise<SdkResponse<UserSearchResponse>> =>
635+
transformResponse<MultipleUsersResponse, UserSearchResponse>(
634636
httpClient.post(apiPaths.user.search, {
635637
...searchReq,
636638
roleNames: searchReq.roles,
637639
roles: undefined,
638640
}),
639-
(data) => data.users,
641+
(data) => ({ users: data.users, total: data.total }),
640642
),
641643
/**
642644
* Get the provider token for the given login ID.

0 commit comments

Comments
 (0)