Skip to content

Commit e0233bd

Browse files
ref: use @sentry/api client for requests (#226)
## Summary Migrates the Sentry API client from hand-rolled `ky` HTTP calls with Zod-validated responses to the [`@sentry/api`](https://www.npmjs.com/package/@sentry/api) SDK package. This gives us type-safe API calls generated from the OpenAPI spec, while keeping raw requests for internal/undocumented endpoints. This supersedes #164, which generated the client in-repo using `@hey-api/openapi-ts`. Using the published `@sentry/api` package instead avoids maintaining ~20k lines of generated code in the repo. ## What changed ### New: `src/lib/sentry-client.ts` Request configuration layer for `@sentry/api` SDK functions. Provides: - **Authenticated fetch** with Bearer token injection - **Automatic retry** on transient errors (408, 429, 5xx) with exponential backoff - **401 token refresh** — force-refreshes OAuth token and retries once - **Request timeout** via AbortController (30s) - Per-region config via `getSdkConfig(regionUrl)` ### Rewritten: `src/lib/api-client.ts` All API functions now use `@sentry/api` SDK functions where possible: | Function | SDK function used | |----------|------------------| | `listOrganizationsInRegion` | `listYourOrganizations` | | `getOrganization` | `retrieveAnOrganization` | | `listProjects` | `listAnOrganization_sProjects` | | `getProject` | `retrieveAProject` | | `getProjectKeys` | `listAProject_sClientKeys` | | `getIssueByShortId` | `resolveAShortId` | | `getLatestEvent` | `retrieveAnIssueEvent` | | `getEvent` | `retrieveAnEventForAProject` | | `triggerRootCauseAnalysis` | `startSeerIssueFix` | | `getAutofixState` | `retrieveSeerIssueFixState` | | `listLogs` / `getLog` | `queryExploreEventsInTableFormat` | Functions that use raw requests (no SDK equivalent): - `getUserRegions` — `/users/me/regions/` (internal endpoint) - `getCurrentUser` — `/users/me/` (internal endpoint) - `findProjectByDsnKey` — `/projects/?query=dsn:...` (internal query param) - `listIssues` — SDK missing `limit`/`sort` params - `getIssue` / `updateIssueStatus` — legacy `/issues/{id}/` endpoint (no org slug needed) - `getDetailedTrace` — `/organizations/{org}/trace/{traceId}/` (internal endpoint) - `triggerSolutionPlanning` — SDK doesn't support `run_id` + `step` body ### Refactored: `src/types/sentry.ts` - SDK-backed types now derive from `@sentry/api` response types using `Partial<SdkType> & RequiredCore` - Keeps Zod schemas only for internal endpoints not covered by the SDK (Region, User, Logs) - Event entry types (exceptions, breadcrumbs, request, etc.) remain as plain TypeScript interfaces ### Removed - `ky` dependency (replaced by `@sentry/api` + native fetch) - Most Zod schemas for SDK-covered types (Organization, Project, Issue, Event, ProjectKey, etc.) - `SentryOrganizationSchema` and other schema exports from `types/index.ts` --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent fecff2c commit e0233bd

File tree

12 files changed

+1269
-1115
lines changed

12 files changed

+1269
-1115
lines changed

bun.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
},
2828
"devDependencies": {
2929
"@biomejs/biome": "2.3.8",
30+
"@sentry/api": "^0.1.0",
3031
"@sentry/bun": "10.38.0",
3132
"@sentry/esbuild-plugin": "^2.23.0",
3233
"@sentry/node": "10.38.0",
@@ -40,7 +41,6 @@
4041
"esbuild": "^0.25.0",
4142
"fast-check": "^4.5.3",
4243
"ignore": "^7.0.5",
43-
"ky": "^1.14.2",
4444
"p-limit": "^7.2.0",
4545
"pretty-ms": "^9.3.0",
4646
"qrcode-terminal": "^0.12.0",

0 commit comments

Comments
 (0)