feat: update @sentry/api to 0.133.0 and adopt pagination improvements#915
feat: update @sentry/api to 0.133.0 and adopt pagination improvements#915MathurAditya724 wants to merge 3 commits intomainfrom
Conversation
Update @sentry/api from 0.113.0 to 0.133.0, which includes pagination
wrappers, prevCursor support, and widened query types (cursor and
per_page now declared on paginated endpoints).
Changes:
- Bump @sentry/api to ^0.133.0 in devDependencies
- Add prevCursor to PaginatedResponse type and unwrapPaginatedResult
- Replace manual pagination loops with autoPaginate in listProjects()
and listAllRepositories(), eliminating ~40 lines of cursor management
- Narrow 5 unsafe `as { cursor?: string }` casts to typed alternatives
now that cursor/per_page are in the SDK query types
- Remove unnecessary multi-line result casts in issues, events, teams
- Remove stale comments about per_page not being in the OpenAPI spec
The CLI keeps its own unwrapPaginatedResult (not the SDK's) because
the CLI's error pipeline depends on ApiError/AuthError types that the
SDK's unwrapResult does not preserve.
traces.ts, discover.ts, and dashboards.ts widget queries are left
on raw apiRequestToRegion — they use Zod validation schemas and the
error-type incompatibility makes migration to SDK wrappers non-trivial.
These will be addressed in a follow-up.
|
Codecov Results 📊✅ 6664 passed | Total: 6664 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ❌ Patch coverage is 58.33%. Project has 13510 uncovered lines. Files with missing lines (4)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 76.63% 76.63% —%
==========================================
Files 303 303 —
Lines 57823 57809 -14
Branches 0 0 —
==========================================
+ Hits 44307 44299 -8
- Misses 13516 13510 -6
- Partials 0 0 —Generated by Codecov Action |
| */ | ||
| export async function listProjects(orgSlug: string): Promise<SentryProject[]> { | ||
| const config = await getOrgSdkConfig(orgSlug); | ||
| const allResults: SentryProject[] = []; | ||
| let cursor: string | undefined; | ||
|
|
||
| for (let page = 0; page < MAX_PAGINATION_PAGES; page++) { | ||
| const { data: allResults } = await autoPaginate(async (cursor) => { | ||
| const result = await listAnOrganization_sProjects({ | ||
| ...config, | ||
| path: { organization_id_or_slug: orgSlug }, | ||
| // per_page is supported by Sentry's pagination framework at runtime | ||
| // but not yet in the OpenAPI spec | ||
| query: { cursor, per_page: API_MAX_PER_PAGE } as { cursor?: string }, | ||
| query: { cursor, per_page: API_MAX_PER_PAGE } as { | ||
| cursor?: string; |
There was a problem hiding this comment.
Bug: The autoPaginate function silently truncates results when the page limit is reached, as the previous warning log for incomplete data has been removed.
Severity: MEDIUM
Suggested Fix
Modify the autoPaginate function to log a warning when it terminates due to reaching the MAX_PAGINATION_PAGES limit. This will restore the previous behavior of notifying operators when a returned dataset is incomplete.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: src/lib/api/projects.ts#L53-L62
Potential issue: The refactor to use the `autoPaginate` function in `listProjects` and
`listAllRepositories` has inadvertently removed a warning log. Previously, a warning was
issued when the maximum number of pagination pages (`MAX_PAGINATION_PAGES`, defaulting
to 50) was reached. The new implementation silently truncates the list of projects or
repositories for organizations that have more than 5000 items. Callers will receive an
incomplete list without any indication that data is missing, which is a regression from
the previous behavior where operators were notified.
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
Good catch — this was a real regression. The old per-callsite warning logs were dropped when switching to autoPaginate, and autoPaginate itself had no warning on the MAX_PAGINATION_PAGES exit path.
Fixed in a528058: added logger.warn() directly inside autoPaginate when the page-limit safety net is hit. This is better than the old approach since all callers now get the warning automatically instead of each callsite needing to remember to add one.
The refactor to use autoPaginate removed per-callsite warning logs that fired when MAX_PAGINATION_PAGES was reached. Move the warning into autoPaginate itself so all callers benefit from the truncation notice.
Update
@sentry/apifrom 0.113.0 to 0.133.0 and adopt the new pagination type improvements. This eliminates 5 unsafeas { cursor?: string }casts, replaces 2 manual pagination loops withautoPaginate, and addsprevCursorsupport toPaginatedResponse.Changes
@sentry/api^0.133.0 — includes pagination wrappers (fetchPage_*,paginateAll_*,paginateUpTo_*), widened query types (cursor+per_pagenow typed), andprevCursorin link header parsingPaginatedResponse<T>gainsprevCursor?: string;unwrapPaginatedResultpasses it throughautoPaginateone-liner; casts cleaned upautoPaginate; casts cleaned upas { cursor?: string }casts narrowed/removed; multi-line result casts collapsedWhat's NOT migrated (follow-up)
traces.ts,discover.ts, anddashboards.tswidget queries stay on rawapiRequestToRegion— they use Zod validation schemas and the SDK wrappers' error handling (plainError) is incompatible with the CLI'sApiError/AuthErrorpipeline.Testing
bun test test/lib/api-client.coverage.test.ts— 91/91 passnpx tsc --noEmit— clean (no new errors)