Skip to content

Commit f430f9d

Browse files
feat(toolkit-core): Share the API transport with the CLI
Move the CLI's request loop from sentry-client.ts into @sentry/toolkit-core/api-transport: the Authorization header, the 401 refresh (any method, once), per-attempt timeouts, retries through api-retry, request-body replay, validated redirect following with origin provenance, and GET cache lookup, revalidation, storage, and post-write invalidation. The host injects a CredentialProvider, header rules, a cache, its error classes, a logger, and a span hook, so the module stays free of Node APIs. The CLI now configures the transport with its stored credentials, host-scope checks, disk cache, telemetry span, and error classes. Implements #1669 tasks 5.1 and 5.2. Co-Authored-By: BYK <burak.kaya@sentry.io>
1 parent 6b5c859 commit f430f9d

7 files changed

Lines changed: 1559 additions & 893 deletions

File tree

‎docs/contributing/api-patterns.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,12 @@ Retries are:
294294
Callers and tools need no changes: a retried request either resolves normally or
295295
throws the same error it would have thrown without retries.
296296

297-
The CLI's transport (`packages/cli/src/lib/sentry-client.ts`) follows the same
298-
shared rule. Only the caps differ (`RETRY_POLICY`): the hosted MCP keeps its
299-
total wait short so a Workers request isn't held open, while the CLI can wait
300-
longer. The CLI also applies its own per-request timeout, which counts as a
301-
network failure.
297+
The CLI sends its requests through the shared transport in
298+
`@sentry/toolkit-core/api-transport`, configured in
299+
`packages/cli/src/lib/sentry-client.ts`. It follows the same shared rule; only
300+
the caps differ (`RETRY_POLICY`): the hosted MCP keeps its total wait short so
301+
a Workers request isn't held open, while the CLI can wait longer. The CLI also
302+
applies its own per-request timeout, which counts as a network failure.
302303

303304
## Best Practices
304305

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
/**
2-
* Helpers for the `input` argument of `fetch()`.
2+
* Helpers for the `input` argument of `fetch()`. The transport owns the
3+
* implementation; this path stays for CLI callers and tests.
34
*/
45

5-
/**
6-
* Extract the full URL string from a fetch input.
7-
*
8-
* `String(request)` yields `"[object Request]"`, so `Request` inputs need
9-
* their `.url` read explicitly.
10-
*/
11-
export function extractInputUrl(input: Request | string | URL): string {
12-
if (typeof input === "string") {
13-
return input;
14-
}
15-
if (input instanceof URL) {
16-
return input.href;
17-
}
18-
return input.url;
19-
}
6+
export { extractInputUrl } from "@sentry/toolkit-core/api-transport";

0 commit comments

Comments
 (0)