Skip to content

ref(api): Adopt SDK types for the projects domain - #1213

Merged
jared-outpost[bot] merged 1 commit into
mainfrom
refactor/cli-projects-sdk-types
Aug 1, 2026
Merged

ref(api): Adopt SDK types for the projects domain#1213
jared-outpost[bot] merged 1 commit into
mainfrom
refactor/cli-projects-sdk-types

Conversation

@betegon

@betegon betegon commented Jul 9, 2026

Copy link
Copy Markdown
Member

What

A small, bounded testbed for the CLI type-cleanup effort — the follow-up to the @sentry/api bump (#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.ts barrel): clean SDK adoption, an undocumented-field overlay, the ?collapse response variant, and a genuine escape hatch.

Changes

  • Convert createProjectWithAutoTeam from a raw apiRequestToRegion POST to the SDK createOrganizationProject function (same getOrgSdkConfig + unwrapResult pattern 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.
  • Simplify getProject: collapse the whole-argument + result double-cast to a single localized query: { collapse: 'organization' } as never. The collapse param is server-supported but not in the spec; the trimmed organization payload is modeled by the SentryProject.organization overlay.
  • Annotate 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_schema promotion candidate (rather than a silent cast).
  • Codify the overlay convention on 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_schema candidate.

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/collapse response variants, and private endpoints. These are captured as a backend unlock worklist and are out of scope here.

Test plan

  • tsc --noEmit: clean
  • biome check: clean
  • Unit tests: api/types/commands (2738) + api-client coverage / create-sentry-project / project-create (151) — all green. createProjectWithAutoTeam coverage asserts the POST target + team_slug return, unchanged.
  • Live (branch source, org bete-dev): project view returns the project with both the status and organization overlays intact — behavior unchanged.

No behavior change.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-08-01 10:50 UTC

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ Patch coverage is 100.00%. Project has 5337 uncovered lines.
✅ Project coverage is 81.82%. Comparing base (base) to head (head).

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        -2

Generated by Codecov Action

@BYK BYK added the jared Trigger the Jared agent to work on stuff label Aug 1, 2026
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>
@jared-outpost
jared-outpost Bot force-pushed the refactor/cli-projects-sdk-types branch from fcdbabc to d4a9093 Compare August 1, 2026 10:37
@jared-outpost
jared-outpost Bot marked this pull request as ready for review August 1, 2026 10:46
@jared-outpost

jared-outpost Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

rebased onto main to clear the merge conflict (the branch predated the packages/cli restructure) and marked ready. no content changes from the rebase — the diff is still the same 2-file projects SDK-types refactor. full CI is green: lint/typecheck, unit + e2e tests, codeql, warden, semgrep. requested @betegon for review since it's their change.

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Aug 1, 2026
@BYK

BYK commented Aug 1, 2026

Copy link
Copy Markdown
Member

Jared, people cannot review their own changes reliably 😅 You review it and merge if you think it's good to go

@jared-outpost jared-outpost Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed the diff against the SDK types — looks correct:

  • createProjectWithAutoTeam mirrors the existing createProject/createTeamProject pattern exactly (getOrgSdkConfig + path + body + unwrapResult); CreateOrganizationProjectData matches the call shape and CreateProjectBody is a subset of its body. team_slug overlay is accurate — it's returned but not in the spec.
  • getProject: confirmed GetProjectData.query is typed never in the SDK, so query: { collapse: 'organization' } as never is the correct minimal escape hatch. cleaner than the prior double-cast-via-unknown.
  • findProjectByDsnKey change 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.

@jared-outpost
jared-outpost Bot merged commit 75c0458 into main Aug 1, 2026
33 checks passed
@jared-outpost
jared-outpost Bot deleted the refactor/cli-projects-sdk-types branch August 1, 2026 10:49
jared-outpost Bot added a commit that referenced this pull request Aug 1, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jared Trigger the Jared agent to work on stuff risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants