Skip to content

feat: update @sentry/api to 0.133.0 and adopt pagination improvements#915

Open
MathurAditya724 wants to merge 3 commits intomainfrom
feat/migrate-to-sentry-api-pagination-wrappers
Open

feat: update @sentry/api to 0.133.0 and adopt pagination improvements#915
MathurAditya724 wants to merge 3 commits intomainfrom
feat/migrate-to-sentry-api-pagination-wrappers

Conversation

@MathurAditya724
Copy link
Copy Markdown
Member

Update @sentry/api from 0.113.0 to 0.133.0 and adopt the new pagination type improvements. This eliminates 5 unsafe as { cursor?: string } casts, replaces 2 manual pagination loops with autoPaginate, and adds prevCursor support to PaginatedResponse.

Changes

  • @sentry/api ^0.133.0 — includes pagination wrappers (fetchPage_*, paginateAll_*, paginateUpTo_*), widened query types (cursor + per_page now typed), and prevCursor in link header parsing
  • infrastructure.tsPaginatedResponse<T> gains prevCursor?: string; unwrapPaginatedResult passes it through
  • projects.ts — manual 30-line pagination loop → autoPaginate one-liner; casts cleaned up
  • repositories.ts — manual 15-line pagination loop → autoPaginate; casts cleaned up
  • teams.ts, releases.ts, issues.ts, events.tsas { cursor?: string } casts narrowed/removed; multi-line result casts collapsed

What's NOT migrated (follow-up)

traces.ts, discover.ts, and dashboards.ts widget queries stay on raw apiRequestToRegion — they use Zod validation schemas and the SDK wrappers' error handling (plain Error) is incompatible with the CLI's ApiError/AuthError pipeline.

Testing

  • bun test test/lib/api-client.coverage.test.ts — 91/91 pass
  • npx tsc --noEmit — clean (no new errors)

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.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-915/

Built to branch gh-pages at 2026-05-05 00:16 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

Codecov Results 📊

6664 passed | Total: 6664 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

❌ Patch coverage is 58.33%. Project has 13510 uncovered lines.
✅ Project coverage is 76.63%. Comparing base (base) to head (head).

Files with missing lines (4)
File Patch % Lines
src/lib/api/releases.ts 9.09% ⚠️ 10 Missing
src/lib/api/infrastructure.ts 64.71% ⚠️ 6 Missing
src/lib/api/projects.ts 62.50% ⚠️ 3 Missing
src/lib/api/events.ts 0.00% ⚠️ 1 Missing
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

@MathurAditya724 MathurAditya724 marked this pull request as ready for review May 5, 2026 00:08
@MathurAditya724 MathurAditya724 requested a review from BYK May 5, 2026 00:08
Comment thread src/lib/api/projects.ts
Comment on lines 53 to +62
*/
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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.
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.

2 participants