Skip to content
This repository was archived by the owner on Nov 16, 2026. It is now read-only.

feat(client): Move the shared API client from toolkit into @sentry/api - #122

Merged
BYK merged 7 commits into
mainfrom
feat/shared-api-client
Nov 4, 2026
Merged

BYK merged 7 commits into
mainfrom
feat/shared-api-client

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Refs getsentry/toolkit#1875 (task 8.5 of the unify-sentry-api-layer plan)

This moves the API client that toolkit's CLI and MCP share (packages/toolkit-core/src/api-client/) into this package, so there is one client. Toolkit does not switch to it in this PR. That happens in getsentry/toolkit#1876.

Layout

  • lib/api-client/ holds the moved modules: api-path, auth-token, core, endpoints/, errors, idempotent-operations, pagination, response, response-cache/ (cache policy plus the memory store, with an injected BodyCodec), retry, time-params, transport, validate, and standard-schema (vendored StandardSchemaV1 types, MIT).
  • It adds two new entries:
    • @sentry/api/client: transport, core request, errors, pagination, response cache, retry, auth token, and path helpers.
    • @sentry/api/client/endpoints: the endpoint wrappers.
  • The root @sentry/api, ./zod and ./valibot exports are unchanged.
  • @sentry/api stays external in the new bundles, so SentryApiError and the pagination helpers are the same class and functions in every entry.

Reconciliation

  • One error type. ApiError and its subclasses (ApiNotFoundError and the rest) now extend SentryApiError:
    • body is set to responseBody.
    • documented is set to false.
    • response is undefined.
    • instanceof SentryApiError catches errors from both the generated client and the shared client.
  • One pagination helper. The shared cursor pagination is built on the root consumePage/paginateUpTo. To avoid name clashes, the toolkit versions are renamed: PagePosition → CursorPosition and consumePage → consumeCursorPage.
  • One transport. createBrowserFetch stays a credential adapter, unchanged, because existing tests pin its Request identity and signal behaviour. To get retry, caching and the other transport features in a browser, compose it: createApiTransport({ fetch: createBrowserFetch(), retry }).
  • Injected interfaces are kept: credentials provider, CacheStore, fresh-read scope, logger, and span hook. Host storage stays in toolkit, including the node:zlib cache codec.

Portability guard

  • tsconfig.browser.json typechecks src/api-client and src/browser.ts with DOM libs only and types: []. I planted a Buffer/process use and confirmed this check fails on it. It runs as part of bun run typecheck.
  • test/api-client/portability.test.ts does a TypeScript AST import check. It rejects Node builtins, and also zod and valibot, in the shared modules.

Tests

  • Toolkit's api-client tests are ported from vitest to bun:test in test/api-client/. Fake timers are replaced with setSystemTime plus a waitFor helper.
  • The 5 MB zstd memory-store test is dropped because it tests toolkit's codec, which stays in toolkit.
  • Added tests for errors, auth-token and api-path.
  • Added test/client-package.test.ts, which:
    • packs and installs the package,
    • builds the browser entry with Bun.build --target browser,
    • checks the bundle has no node: imports and a single SentryApiError class,
    • sends a request through createBrowserFetch → transport → listOrganizations against a mocked fetch,
    • checks that a 404 is both an ApiNotFoundError and a SentryApiError.

Local results: bun run build passes, bun run typecheck passes, bun test has 585 pass / 0 fail, and bun run test:node passes.

Dependencies

  • New runtime dependency: http-cache-semantics (external, not bundled).
  • New dev dependencies: @types/http-cache-semantics and fast-check.

Breaking changes

None. No existing export was changed or removed. getsentry/sentry does not depend on or import @sentry/api.

Response cache

The stored cache policy keeps request headers when a response has Vary. policy.ts replaces the authorization value with its SHA-256 hash (WebCrypto) before building the policy, on both lookup and store, so a raw token is never written to a cache store and Vary: Authorization still separates tokens.

Release

Nothing is published here. After this merges, run the Release workflow. The pending release/0.445.0 branch must be published or dropped first, because Craft refuses to prepare a new release while it exists. Then run it (Craft, npm + GitHub) for a minor bump. getsentry/toolkit#1876 then bumps toolkit's @sentry/api catalog version and switches its imports.

via @BYK.

--

View Session in Sentry

sentry-junior Bot and others added 2 commits November 3, 2026 21:49
Adds @sentry/api/client and @sentry/api/client/endpoints: the transport,
request core, errors, retry policy, response cache policy, cursor
pagination, validation, and endpoint wrappers that getsentry/toolkit
shares between the CLI and MCP. The core's ApiError classes now extend
SentryApiError, and pagination builds on paginateUpTo and consumePage.

Refs getsentry/toolkit#1875

Co-Authored-By: BYK <[email protected]>
@sentry-junior

sentry-junior Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Clarification on the local results in the description: bun run build (and the tests that build or pack the package) passed with the fix/tree-shake-bigint-bounds patch to scripts/make-tree-shakeable.mjs applied locally but not committed here. Without it, the build fails on the same pre-existing BigInt(0) error as main.

Comment thread lib/api-client/response-cache/policy.ts Resolved
CachePolicy#toObject() persists request headers when the response has
Vary, so the Bearer token reached the cache store. Record a SHA-256
digest of authorization instead, on both lookup and store, so Vary
matching still tells tokens apart.
@sentry-junior
sentry-junior Bot marked this pull request as ready for review November 3, 2026 22:24

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread lib/api-client/transport.ts Resolved
Comment thread lib/api-client/transport.ts Resolved
Comment thread lib/api-client/transport.ts Resolved
- Bound a buffered body read by the attempt's signal, so a body that
  ignores the abort after the headers still times out.
- Replay after a credential refresh outside the retry budget, so a 401
  refreshes with maxRetries 0 and the replay does not use up a retry.
- Look up the cache with the Authorization a send would set, so a
  Vary: Authorization entry matches with a host authorization().
Comment thread build.mjs Resolved

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 1b74ad9. Configure here.

Comment thread lib/api-client/endpoints/projects.ts Resolved
listProjectTeams and listRepositories followed Link cursors until the
header was empty. Walk them with fetchAllPages, so a repeated cursor or
more than MAX_LIST_PAGES pages fails like listPage does.
visitReplayRecordingSegments counted only rows toward maxSegments, so
empty pages with a cursor never ended; stop there as truncated.
@BYK
BYK merged commit ed45ff3 into main Nov 4, 2026
10 checks passed
@BYK
BYK deleted the feat/shared-api-client branch November 4, 2026 11:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant