Skip to content

feat(user): add total field to search api response#663

Closed
dorsha wants to merge 2 commits intomainfrom
shuni/task-20260227190635
Closed

feat(user): add total field to search api response#663
dorsha wants to merge 2 commits intomainfrom
shuni/task-20260227190635

Conversation

@dorsha
Copy link
Member

@dorsha dorsha commented Feb 27, 2026

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 total field that the backend API provides.

Changes Made:

  1. Added UserSearchResponse type (lib/management/types.ts):

  2. Updated user.ts (lib/management/user.ts):

    • Imported the new UserSearchResponse type
    • Updated the internal MultipleUsersResponse type to include the total field
    • Modified search() method to return Promise<SdkResponse<UserSearchResponse>> instead of Promise<SdkResponse<UserResponse[]>>
    • Modified searchTestUsers() method to return Promise<SdkResponse<UserSearchResponse>> instead of Promise<SdkResponse<UserResponse[]>>
    • Updated transformation logic to return both users and total fields instead of just extracting users
    • Note: The deprecated searchAll() method was left unchanged to maintain backward compatibility
  3. Updated tests (lib/management/user.test.ts):

    • Added UserSearchResponse to imports
    • Updated mockMgmtUsersResponse to include total: 1 field
    • Updated test expectations for search() and searchTestUsers() to expect the new response structure with both users and total

Migration Path for Users:

Before (only had access to users array):

const result = await client.management.user.search({ limit: 10 });
const users = result.data; // UserResponse[]
// No way to get total count!

After (now has access to both users and total):

const result = await client.management.user.search({ limit: 10 });
const users = result.data.users; // UserResponse[]
const total = result.data.total; // number
// Can now plan pagination!

Testing:

  • All existing tests pass ✅
  • Build succeeds ✅
  • Pre-commit hooks (lint + format) pass ✅

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 🐕

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>
Copilot AI review requested due to automatic review settings February 27, 2026 19:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 UserSearchResponse type ({ users, total }) in management types.
  • Updates management.user.search() and management.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.

@dorsha
Copy link
Member Author

dorsha commented Feb 27, 2026

@shuni please fix above comments, and also fix readme.

@shuni-bot
Copy link

shuni-bot bot commented Feb 27, 2026

🐕 Done! Updated PR: #663

View workflow run

📋 Actions Taken

✅ Reply to all 3 review threads
✅ Implement backward-compatible solution with new methods
✅ Update README with new search methods
✅ Run tests and verify changes
✅ Commit changes

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>
@dorsha dorsha closed this Feb 27, 2026
@dorsha dorsha deleted the shuni/task-20260227190635 branch February 27, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

search API returns total but the SDK does not

2 participants