feat(user): add total field to search api response#663
Closed
Conversation
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>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds support for returning the backend-provided total count in management user search responses, enabling proper pagination metadata in the Node SDK.
Changes:
- Introduces a new
UserSearchResponsetype ({ users, total }) in management types. - Updates
management.user.search()andmanagement.user.searchTestUsers()to return{ users, total }instead of just the users array. - Updates user management tests to validate the new response shape.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lib/management/types.ts | Adds UserSearchResponse type with users and total. |
| lib/management/user.ts | Changes search / searchTestUsers return types and response mapping to include total. |
| lib/management/user.test.ts | Updates mocks and expectations for the new { users, total } shape. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
Author
|
@shuni please fix above comments, and also fix readme. |
|
🐕 Done! Updated PR: #663 📋 Actions Taken✅ Reply to all 3 review threads |
Address PR review feedback to prevent breaking changes: - Made total field optional in MultipleUsersResponse - Kept search() and searchTestUsers() returning UserResponse[] (deprecated) - Added searchWithTotal() and searchTestUsersWithTotal() for new functionality - Updated tests to cover both old and new methods - Updated README with migration examples This preserves backward compatibility while providing access to the total field for pagination. Existing consumers continue working without changes. Closes review comments on #663 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #662
View workflow run
Perfect! The commit has been created successfully. Now let me create a summary of the changes:
Summary
I've successfully fixed the issue where the SDK's search API was not returning the
totalfield that the backend API provides.Changes Made:
Added
UserSearchResponsetype (lib/management/types.ts):users: UserResponse[]andtotal: numberfieldsUpdated
user.ts(lib/management/user.ts):UserSearchResponsetypeMultipleUsersResponsetype to include thetotalfieldsearch()method to returnPromise<SdkResponse<UserSearchResponse>>instead ofPromise<SdkResponse<UserResponse[]>>searchTestUsers()method to returnPromise<SdkResponse<UserSearchResponse>>instead ofPromise<SdkResponse<UserResponse[]>>usersandtotalfields instead of just extractinguserssearchAll()method was left unchanged to maintain backward compatibilityUpdated tests (
lib/management/user.test.ts):UserSearchResponseto importsmockMgmtUsersResponseto includetotal: 1fieldsearch()andsearchTestUsers()to expect the new response structure with bothusersandtotalMigration Path for Users:
Before (only had access to users array):
After (now has access to both users and total):
Testing:
The commit has been created and is ready. As per the workflow instructions, I will not push or create a PR - the GitHub Actions workflow will handle that automatically.
Created by Shuni 🐕