Skip to content

feat: SDK auth/client config factories (bearerToken, browserSession, createSentryClient) - #78

Open
betegon wants to merge 2 commits into
mainfrom
feat/sdk-auth-factories
Open

betegon wants to merge 2 commits into
mainfrom
feat/sdk-auth-factories

Conversation

@betegon

@betegon betegon commented Jul 10, 2026 •

Copy link
Copy Markdown
Member

Configuring a Sentry deployment and credentials currently requires repeating options across calls. Export the generated client and add bearerToken(...) and browserSession(...) so consumers can configure requests once. Servers can create an isolated createSentryClient(...) per deployment and authentication context.

Before and after

Here, token and baseUrl come from the consumer's deployment configuration.

Before: pass deployment and authentication options to each operation.

import { listOrganizations, getOrganization } from "@sentry/api";

const organizations = await listOrganizations({
  baseUrl,
  headers: { Authorization: `Bearer ${token}` },
});
const organization = await getOrganization({
  baseUrl,
  headers: { Authorization: `Bearer ${token}` },
  path: { organization_id_or_slug: "example-org" },
});

After: configure an isolated client once and reuse it across operations.

import {
  bearerToken,
  createSentryClient,
  listOrganizations,
  getOrganization,
} from "@sentry/api";

const sentry = createSentryClient(bearerToken({ token, baseUrl }));

const organizations = await listOrganizations({ client: sentry });
const organization = await getOrganization({
  client: sentry,
  path: { organization_id_or_slug: "example-org" },
});

Each instance belongs to one deployment and authentication context. For a single-context application, the exported singleton also supports client.setConfig(bearerToken({ token, baseUrl })), followed by calls without a client option. Result and error handling are unchanged.

Explicit Enterprise, self-hosted, custom, and regional origins are preserved without discovery or extra requests. Existing custom fetch implementations and per-call overrides still compose with the client. The browser factory reuses the existing cookie/CSRF helper. Generated fetch configuration accepts portable callable implementations under both Bun and Node, without requiring runtime-specific properties such as fetch.preconnect.

The README covers the public entry points, and the client design records region/cache ownership, control versus regional operations, canonical web links, and consumer responsibilities. This foundation can support a bounded MCP adoption with raw adapters for endpoints outside the public schema; it does not need to wait for the routing and progressive-accuracy helpers in #79 and #80. Region discovery/cache, link builders, retries, and identity endpoint publication remain separate work.

Validation: bun run build, bun run typecheck (Bun/DOM and Node-only declarations), bun test (115 passing), and npm pack. Public-package contract tests cover exact request origins, credential isolation, overrides, custom transport, error policy, generic requests, and browser authentication. A Node smoke test against the unpacked tarball verified imports and singleton request configuration without validator dependencies. No live Sentry deployment or real browser was exercised.

Part of #81.

…createSentryClient)

Configure the client once instead of threading baseUrl + auth into every call.
`bearerToken({ token })` returns a typed config (default baseUrl https://sentry.io) for
`client.setConfig(...)` (global) or `createSentryClient(...)` (isolated, for servers/tests).
`browserSession()` (in ./browser) is the blessed name for the existing cookie+CSRF browser
config; `createBrowserSdkConfig` stays as an alias.

Re-exports the client (`client`, `createClient`, `createSentryClient`, `createConfig`, `Config`)
from the public entry so consumers configure it without reaching into generated internals.

Pure builders, no side effects, no `mode` enum. Additive and opt-in; existing per-call config
still works. First of three PRs (auth factories -> region routing -> query accuracy) toward one
SDK for the CLI, MCP, and frontend.

Co-Authored-By: Claude <noreply@anthropic.com>
Update the auth-factory branch with current main, document deployment and region ownership, and validate public client composition across Bun and Node.
@betegon
betegon marked this pull request as ready for review September 25, 2026 12:59
@betegon betegon mentioned this pull request Oct 1, 2026
35 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant