This repository was archived by the owner on Nov 16, 2026. It is now read-only.
Repository navigation
feat(client): Move the shared API client from toolkit into @sentry/api - #122
Merged
Merged
Conversation
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]>
Co-Authored-By: BYK <[email protected]>
Contributor
Author
|
Clarification on the local results in the description: |
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.
Co-Authored-By: BYK <[email protected]>
sentry-junior
Bot
requested review from
BYK,
MathurAditya724 and
betegon
as code owners
November 3, 2026 22:24
- 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().
This was referenced Nov 3, 2026
BYK
suggested changes
Nov 4, 2026
# Conflicts: # bun.lock
BYK
approved these changes
Nov 4, 2026
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.
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
approved these changes
Nov 4, 2026
2 tasks done
This was referenced Nov 16, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Refs getsentry/toolkit#1875 (task 8.5 of the
unify-sentry-api-layerplan)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 injectedBodyCodec),retry,time-params,transport,validate, andstandard-schema(vendored StandardSchemaV1 types, MIT).@sentry/api/client: transport, core request, errors, pagination, response cache, retry, auth token, and path helpers.@sentry/api/client/endpoints: the endpoint wrappers.@sentry/api,./zodand./valibotexports are unchanged.@sentry/apistays external in the new bundles, soSentryApiErrorand the pagination helpers are the same class and functions in every entry.Reconciliation
ApiErrorand its subclasses (ApiNotFoundErrorand the rest) now extendSentryApiError:bodyis set toresponseBody.documentedis set tofalse.responseisundefined.instanceof SentryApiErrorcatches errors from both the generated client and the shared client.consumePage/paginateUpTo. To avoid name clashes, the toolkit versions are renamed:PagePosition→CursorPositionandconsumePage→consumeCursorPage.createBrowserFetchstays 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 }).CacheStore, fresh-read scope, logger, and span hook. Host storage stays in toolkit, including thenode:zlibcache codec.Portability guard
tsconfig.browser.jsontypecheckssrc/api-clientandsrc/browser.tswith DOM libs only andtypes: []. I planted aBuffer/processuse and confirmed this check fails on it. It runs as part ofbun run typecheck.test/api-client/portability.test.tsdoes a TypeScript AST import check. It rejects Node builtins, and alsozodandvalibot, in the shared modules.Tests
bun:testintest/api-client/. Fake timers are replaced withsetSystemTimeplus awaitForhelper.test/client-package.test.ts, which:Bun.build --target browser,node:imports and a singleSentryApiErrorclass,createBrowserFetch→ transport →listOrganizationsagainst a mockedfetch,ApiNotFoundErrorand aSentryApiError.Local results:
bun run buildpasses,bun run typecheckpasses,bun testhas 585 pass / 0 fail, andbun run test:nodepasses.Dependencies
http-cache-semantics(external, not bundled).@types/http-cache-semanticsandfast-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.tsreplaces theauthorizationvalue 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 andVary: Authorizationstill separates tokens.Release
Nothing is published here. After this merges, run the Release workflow. The pending
release/0.445.0branch 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/apicatalog version and switches its imports.via @BYK.
--
View Session in Sentry