ref(api): Adopt SDK types for the projects domain - #1213
Conversation
|
Codecov Results 📊✅ Patch coverage is 100.00%. Project has 5337 uncovered lines. Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 81.81% 81.82% +0.01%
==========================================
Files 423 423 —
Lines 29358 29359 +1
Branches 19126 19126 —
==========================================
+ Hits 24019 24022 +3
- Misses 5339 5337 -2
- Partials 1988 1986 -2Generated by Codecov Action |
Follow-up to the @sentry/api bump (#1194): a bounded testbed that uses the SDK as intended for the projects domain and establishes the overlay convention the remaining domains will follow. - Convert createProjectWithAutoTeam from a raw apiRequestToRegion POST to the SDK createOrganizationProject function; keep team_slug as a documented typed overlay (returned by the API but absent from the OpenAPI spec). - Collapse getProject's double-cast to a single localized `query as never` cast for the undocumented collapse=organization param. - Annotate findProjectByDsnKey's internal ?query=dsn: filter as an intentional escape hatch and backend @extend_schema candidate. - Codify the overlay convention on SentryProject: the SDK type carries every documented field; overlays add only undocumented-but-returned fields. No behavior change. tsc clean, biome clean, project/team/api-client tests pass. Co-Authored-By: Claude <noreply@anthropic.com>
fcdbabc to
d4a9093
Compare
|
rebased onto |
|
Jared, people cannot review their own changes reliably 😅 You review it and merge if you think it's good to go |
There was a problem hiding this comment.
reviewed the diff against the SDK types — looks correct:
createProjectWithAutoTeammirrors the existingcreateProject/createTeamProjectpattern exactly (getOrgSdkConfig+path+body+unwrapResult);CreateOrganizationProjectDatamatches the call shape andCreateProjectBodyis a subset of itsbody.team_slugoverlay is accurate — it's returned but not in the spec.getProject: confirmedGetProjectData.queryis typedneverin the SDK, soquery: { collapse: 'organization' } as neveris the correct minimal escape hatch. cleaner than the prior double-cast-via-unknown.findProjectByDsnKeychange is comment-only; the?query=dsn:raw call is genuinely not in the SDK.
tsc + biome clean, 255 project/api-client tests pass, full CI green. no behavior change. good to merge.
…ows/ (#1223) ## What & why Final slice of migrating issue alerts off the deprecated (HTTP 410 brownout) project-scoped `/projects/{org}/{project}/rules/` endpoint (#1182), after read (#1215) and delete (#1216). This migrates **create** and **edit**. `create`/`edit` now go through the `@sentry/api` SDK (`createOrganizationWorkflow` / `updateOrganizationWorkflow`), assembling the workflow-document body: - `triggers: { logicType, conditions }` from `--condition` / `--action-match` - `actionFilters: [{ logicType, conditions, actions }]` from `--filter` / `--filter-match` / `--action` - `config.frequency` from `--frequency` - `detectorIds` resolved from the project's **error detector** (an issue alert has to attach to it to fire) via `listOrganizationDetectors(?project=…&query=type:error)` `--action-match` / `--filter-match` map to `DataConditionGroup` logic types the same way the backend dual-write does (`any` → `any-short`, `all` → `all`). `edit` reads the workflow document (`getOrganizationWorkflow`), applies the flag overrides in workflow shape (`--status` → `enabled`), and PUTs it back. The SDK types conditions/actions as `unknown[]` and its body fields as snake_case, but the endpoint's `CamelSnakeSerializer` wants camelCase — so the body is built as a record and cast into the typed SDK arg, the same double-cast pattern as `getProject`. No backend change needed. ## Breaking change `--condition` / `--action` / `--filter` now take **workflow-native JSON** (`{type, comparison, conditionResult}` / `{type, data, config}`) instead of the legacy rule identifiers (`{id: "sentry.rules..."}`). The `--help` examples are updated accordingly. ## Scope Read/delete (merged in #1215/#1216) use `apiRequestToRegion`; create/edit here use the `@sentry/api` SDK + cast, matching the projects-domain SDK adoption (#1213). Minor inconsistency within `alerts.ts`, intentional — this is the SDK-adoption direction. ## Test plan - `tsc --noEmit` + `biome check`: clean. - `vitest run test/lib/api/alerts.test.ts test/commands/alert`: green (19 tests). API-level tests pin the exact workflow create/update/detector requests via `mockFetch`; command tests mock the api-client so they are transparent to the mechanism. - **Not yet run live.** The unit tests mock the API, so three things still need a real create/edit to confirm: (1) the edit read-modify-write round-trips through the workflows PUT, (2) `config.frequency` unit (minutes, per the CLI flag), (3) `query=type:error` returns the project error detector. Refs #1182 --------- Co-authored-by: jared-outpost[bot] <jared-outpost[bot]@users.noreply.github.com>
What
A small, bounded testbed for the CLI type-cleanup effort — the follow-up to the
@sentry/apibump (#1194, which renamed call sites but reduced no code). This slice uses the SDK as intended for the projects domain and establishes the overlay convention the remaining domains will follow. It intentionally does not touch all the types.Projects was chosen because it exercises every realistic case in one cohesive, low-blast-radius slice (all imports flow through the
types/index.tsbarrel): clean SDK adoption, an undocumented-field overlay, the?collapseresponse variant, and a genuine escape hatch.Changes
createProjectWithAutoTeamfrom a rawapiRequestToRegionPOST to the SDKcreateOrganizationProjectfunction (samegetOrgSdkConfig+unwrapResultpattern as the rest of the file).team_slug(returned by the API but absent from the OpenAPI spec) is kept as a documented typed overlay.getProject: collapse the whole-argument + result double-cast to a single localizedquery: { collapse: 'organization' } as never. Thecollapseparam is server-supported but not in the spec; the trimmedorganizationpayload is modeled by theSentryProject.organizationoverlay.findProjectByDsnKey: its internal?query=dsn:filter is not in the public API, so it stays a raw call — now clearly documented as an intentional escape hatch and a backend@extend_schemapromotion candidate (rather than a silent cast).SentryProject: the SDK type carries every documented field; an overlay adds only fields the API returns but the spec omits (organization,status,team_slug), each a backend@extend_schemacandidate.Why not remove more types
Full removal is blocked by four things, none of them CLI-side: loosely-typed endpoints (SDK type thinner than hand-written), undocumented-but-returned fields,
expand/collapseresponse variants, and private endpoints. These are captured as a backend unlock worklist and are out of scope here.Test plan
tsc --noEmit: cleanbiome check: cleancreateProjectWithAutoTeamcoverage asserts the POST target +team_slugreturn, unchanged.bete-dev):project viewreturns the project with both thestatusandorganizationoverlays intact — behavior unchanged.No behavior change.