Fix: expose next_page at top level for paginated endpoints #304
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.
Pull Request: Make next_page available in paginated responses
Overview
This PR addresses the pagination defect in the Asana Node.js SDK where pagination metadata (next_page) existed only within the internal _response object, which was inconvenient for users to access paginated endpoints. With this update, next_page is exposed at the top level of the SDK response, which aligns with the Asana API documentation.
Changes Included
In the Collection / Resource / Response constructor (e.g. in src/utils/collection.js or src/resource_response.js), added logic to elevate this._response.next_page to this.next_page when it exists.
Added unit and integration tests:
test/utils/collection.spec.js — tests exposing next_page, handling no pagination, edge cases.
test/integration/pagination.spec.js — end-to-end tests for UsersApi.getUsers() and other paginated endpoints.
Added example script examples/pagination_example.js to illustrate usage.
Documentation update / summary in PAGINATION_FIX_DOCUMENTATION.md (optional but preferred).
How to Test / Validate
Run the full test suite:
npm testAll current tests must work; the new pagination tests must work too.
Use the example:
node examples/pagination_example.jsIt must retrieve more than one page (if your team/account has more than one page) and log next_page objects.
Manual sanity check:
Backward Compatibility & Behavior
The internal _response object remains in place; code that currently uses res._response.next_page will remain functional.
No API break — we aren't changing method signatures or eliminating working functionality.
The nextPage() helper (if it exists) still works the same way as before (if implemented in SDK).
Related Issue / Context
This resolves the outstanding question regarding pagination visibility in UsersApi.getUsers() and such SDK endpoints. Users manually had to unpack res._response.next_page in their app code. This PR brings SDK behavior in line with the official Asana API spec.
Notes / Considerations
There could be other SDK methods or endpoints taking the same Collection / Response pattern (e.g. Tasks, Projects). It's suggested to make sure this pattern is spread throughout all paginated endpoints.
In SDK auto-generated code generation pipelines, this patch should be taken into account while regenerating client libraries for future releases.