refactor(api): migrate dashboards.ts CRUD to SDK functions#863
Merged
MathurAditya724 merged 2 commits intomainfrom Apr 28, 2026
Merged
refactor(api): migrate dashboards.ts CRUD to SDK functions#863MathurAditya724 merged 2 commits intomainfrom
MathurAditya724 merged 2 commits intomainfrom
Conversation
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.
Contributor
|
Contributor
Codecov Results 📊✅ 6213 passed | Total: 6213 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ❌ Patch coverage is 7.55%. Project has 12992 uncovered lines. Files with missing lines (1)
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Migrates the four CRUD wrappers in
src/lib/api/dashboards.tsfrom rawapiRequestToRegionto@sentry/apiSDK functions, following thepattern established by PR #321 (repositories/teams) and PR #803
(releases).
The dashboards module was written before the
@sentry/api0.94 → 0.113upgrade 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
listDashboardsPaginatedapiRequestToRegion+ manualparseLinkHeaderlistAnOrganization_sCustomDashboards+unwrapPaginatedResultgetDashboardapiRequestToRegionretrieveAnOrganization_sCustomDashboard+unwrapResultcreateDashboardapiRequestToRegion(POST)createANewDashboardForAnOrganization+unwrapResultupdateDashboardapiRequestToRegion(PUT)editAnOrganization_sCustomDashboard+unwrapResultSingle file changed:
src/lib/api/dashboards.ts(+71 / -28 lines).Out of scope
The widget data query path (
queryWidgetTimeseries,queryWidgetTable,and
queryAllWidgets) still usesapiRequestToRegion. Those target the/events-stats/and/events/endpoints (not dashboards) and havenon-trivial batching/concurrency invariants in
queryAllWidgetsthatwarrant a separate review.
Type casts
Two
as unknowncasts are needed and documented inline:dashboard_idis typednumberin the SDK schema, but the APIaccepts string IDs verbatim in the URL path (and the CLI uses
strings throughout). The cast lives at the API layer boundary.
strictly snake_case. The OpenAPI docstring on
CreateANewDashboardForAnOrganizationData.bodyconfirms the APIaccepts 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 typecheckcleanbun run lintclean (only pre-existing unrelated warning inmarkdown.ts)bun run test:unit— 6,213 tests pass (no dashboard CRUD tests existed before this change either, sincetest/lib/api/dashboards.test.tsonly covers the helper utilities)