Skip to content

feat(client): expose shared request preparation - #117

Merged
betegon merged 2 commits into
mainfrom
bt/sdk-request-preparation
Oct 29, 2026
Merged

betegon merged 2 commits into
mainfrom
bt/sdk-request-preparation

Conversation

@betegon

@betegon betegon commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Consumers that inspect a raw request before sending it currently have to repeat URL, header and body preparation. Expose sentry.client.prepareRequest(options): Promise<Request> from the concrete client, and extract the same preparation stage used by ordinary SDK requests. This lets consumers inspect and dispatch one native request through their existing transport.

Before / after

Before, the CLI prepares URLs and effective headers for pagination identity and previews, then rebuilds them during raw dispatch. The SDK cannot expose its prepared request without sending it. Passing query alongside a URL that already has query parameters also appends a second ?.

After:

const sentry = createSentryClient({ baseUrl: "https://example.test/sentry" });
const request = await sentry.client.prepareRequest({
  method: "GET",
  url: "/api/0/organizations/example/events/?field=id&field=title&cursor=old",
  query: { cursor: "opaque-next", per_page: 50 },
});
// No fetch yet. Both field values remain and the old cursor is replaced:
// https://example.test/sentry/api/0/organizations/example/events/?field=id&field=title&cursor=opaque-next&per_page=50
const response = await fetch(request);
// The consumer retains raw status, headers and body handling.

Preparation runs configured auth, validation, serialization and request interceptors once. It preserves the native signal and does not invoke fetch or response/error processing. Transports can still attach browser CSRF, credentials or routing when dispatching. Existing custom Client implementations accepted by generated operations need no new method.

The shared URL builder replaces explicitly serialized query keys while retaining unrelated repeated values and encoding. With the default serializer, null clears a parameter and undefined leaves it unchanged. Custom serializers and opaque cursor strings remain supported. Ordinary requests use the same behavior.

Validation and scope

Build, typecheck, 253 SDK tests and 2 Node cancellation tests pass. Coverage compares preparation with ordinary dispatch, exercises raw and browser transports, custom cursors/serializers, body handling, cancellation, concurrent clients and reconfiguration. The packed npm artifact is exercised in a clean Node consumer, including public types and raw non-2xx responses. Review and cleanup completed.

Refs #93 and #99. This is the generic preparation slice for Toolkit #1659; CLI adoption follows publication. Request identity, navigation history, bookmark codecs, output and endpoint recovery remain consumer policy. No production or browser-login validation is claimed, and the remaining v1 adoption gates stay open.

@betegon
betegon marked this pull request as ready for review October 29, 2026 19:46
@betegon
betegon merged commit 37723c6 into main Oct 29, 2026
10 checks passed
@betegon
betegon deleted the bt/sdk-request-preparation branch October 29, 2026 20:12
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