Commit e0233bd
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- src
- lib
- types
- test
- commands/issue
- lib
- mocks
12 files changed
+1269
-1115
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | | - | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
0 commit comments