Skip to content

refactor(api): migrate dashboards.ts CRUD to SDK functions#863

Merged
MathurAditya724 merged 2 commits intomainfrom
refactor/dashboards-sdk-migration
Apr 28, 2026
Merged

refactor(api): migrate dashboards.ts CRUD to SDK functions#863
MathurAditya724 merged 2 commits intomainfrom
refactor/dashboards-sdk-migration

Conversation

@MathurAditya724
Copy link
Copy Markdown
Member

Summary

Migrates the four CRUD wrappers in src/lib/api/dashboards.ts from raw
apiRequestToRegion to @sentry/api SDK functions, following the
pattern established by PR #321 (repositories/teams) and PR #803
(releases).

The dashboards module was written before the @sentry/api 0.94 → 0.113
upgrade and was the last commands-facing API module still using the raw
HTTP path for CRUD operations. The SDK functions for these four
endpoints have been available since 0.94 and are non-deprecated in the
OpenAPI spec.

Changes

Function Before After
listDashboardsPaginated apiRequestToRegion + manual parseLinkHeader listAnOrganization_sCustomDashboards + unwrapPaginatedResult
getDashboard apiRequestToRegion retrieveAnOrganization_sCustomDashboard + unwrapResult
createDashboard apiRequestToRegion (POST) createANewDashboardForAnOrganization + unwrapResult
updateDashboard apiRequestToRegion (PUT) editAnOrganization_sCustomDashboard + unwrapResult

Single file changed: src/lib/api/dashboards.ts (+71 / -28 lines).

Out of scope

The widget data query path (queryWidgetTimeseries, queryWidgetTable,
and queryAllWidgets) still uses apiRequestToRegion. Those target the
/events-stats/ and /events/ endpoints (not dashboards) and have
non-trivial batching/concurrency invariants in queryAllWidgets that
warrant a separate review.

Type casts

Two as unknown casts are needed and documented inline:

  1. dashboard_id is typed number in the SDK schema, but the API
    accepts string IDs verbatim in the URL path (and the CLI uses
    strings throughout). The cast lives at the API layer boundary.
  2. Request body shape is camelCase per CLI convention; the SDK type is
    strictly snake_case. The OpenAPI docstring on
    CreateANewDashboardForAnOrganizationData.body confirms the API
    accepts both at runtime.

The body cast follows the established pattern from
src/lib/api/releases.ts:216 (as unknown as Parameters<typeof sdkFn>[0]["body"]).

Verification

  • bun run typecheck clean
  • bun run lint clean (only pre-existing unrelated warning in markdown.ts)
  • bun run test:unit — 6,213 tests pass (no dashboard CRUD tests existed before this change either, since test/lib/api/dashboards.test.ts only covers the helper utilities)

Replaces raw apiRequestToRegion calls with @sentry/api SDK functions
for the four dashboard CRUD wrappers, following the pattern established
in PR #321 (repositories/teams) and PR #803 (releases).

- listDashboardsPaginated -> listAnOrganization_sCustomDashboards
- getDashboard -> retrieveAnOrganization_sCustomDashboard
- createDashboard -> createANewDashboardForAnOrganization
- updateDashboard -> editAnOrganization_sCustomDashboard

Widget data query path (queryWidgetTimeseries, queryWidgetTable) stays
on raw apiRequestToRegion -- those target events endpoints, not
dashboards, and migrating them is a separate concern (different
batching/concurrency invariants in queryAllWidgets).

Two `as unknown` casts are needed and documented inline:
- path.dashboard_id is typed `number` in the SDK schema, but the API
  accepts string IDs verbatim in the URL path
- request body is camelCase per CLI convention; SDK type is strictly
  snake_case (OpenAPI docstring confirms API accepts both)

Mirrors the body-cast pattern from src/lib/api/releases.ts:216.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 28, 2026

PR Preview Action v1.8.1

QR code for preview link

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

Built to branch gh-pages at 2026-04-28 19:45 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 28, 2026

Codecov Results 📊

6213 passed | Total: 6213 | 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 7.55%. Project has 12992 uncovered lines.
❌ Project coverage is 75.91%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
src/lib/api/dashboards.ts 7.55% ⚠️ 49 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    75.98%    75.91%    -0.07%
==========================================
  Files          293       293         —
  Lines        53892     53934       +42
  Branches         0         0         —
==========================================
+ Hits         40947     40942        -5
- Misses       12945     12992       +47
- Partials         0         0         —

Generated by Codecov Action

Per review feedback:

- Remove all 4 inline explanatory comments (the cast + git history are
  self-explanatory; comments were restating what TypeScript already shows)
- Drop the unwrapPaginatedResult result cast in listDashboardsPaginated
  -- TypeScript can narrow the SDK result type directly here (unlike
  repositories.ts where the SentryRepository wrapper requires it)
- Simplify path-id casts from full path-object shape to a narrower
  `dashboardId as unknown as number` -- only the single field needs
  widening
@MathurAditya724 MathurAditya724 merged commit f5bb67e into main Apr 28, 2026
25 checks passed
@MathurAditya724 MathurAditya724 deleted the refactor/dashboards-sdk-migration branch April 28, 2026 19:55
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.

1 participant