/** * Minimal `fetch` shape the task packages depend on (JSON responses only). * * This is the single canonical definition — task packages import it from here * rather than re-declaring the same type in every client. `init` and its fields * are optional so both GET-heavy clients and always-POST clients satisfy it. */ export type FetchLike = (url: string, init?: { method?: string; headers?: Record; body?: string; }) => Promise<{ ok: boolean; status: number; text(): Promise; json(): Promise; /** * Response headers, if the fetch implementation exposes them. Optional so the * many fakes in tests need not provide it; the real `fetch` Response always * does. Read here to honor a `Retry-After` on a rate-limited response. */ headers?: { get(name: string): string | null; }; }>; /** * Throw a clear error on a non-2xx response so the durable task retry fires * (ADR-0005). `label` is the vendor + path context, e.g. `"GitLab API /projects"`. * The body is best-effort — a failed `text()` read must not mask the status. */ export declare function throwIfNotOk(res: { ok: boolean; status: number; text(): Promise; }, label: string): Promise; /** Init for a single {@link HttpClient.call}. */ export interface CallInit { method?: string; /** Serialized as JSON when present; omitted entirely when `undefined`. */ body?: unknown; /** * A pre-serialized body sent verbatim (multipart, form-urlencoded, …). Set the * matching `content-type` via `headers`. Takes precedence over `body`; use one * or the other. */ rawBody?: string; /** Per-call headers, merged over the client's default + auth headers. */ headers?: Record; /** How to parse the response body. Defaults to `"json"`; use `"text"` for non-JSON APIs. */ responseType?: "json" | "text"; } /** * Bounded in-process backoff for transient responses (429 / 5xx, per * {@link isRetryable}). This is an **opt-in, bounded** exception to ADR-0005's * "durable task retry is the single source of truth": a rate-limited control * plane (e.g. the Render API) rate-limits a *whole workspace*, so a durable * re-dispatch that re-fires the same doomed request every 15s sustains the limit * rather than clearing it. Absorbing a short burst in-process — honoring the * server's `Retry-After`, else exponential backoff with jitter, capped at a * small number of attempts — lets the window recover before the durable retry * layer ever sees the failure. It is bounded (`maxRetries`) so it can never * become an unbounded hidden loop; the durable policy still owns the long tail. * Left unset, the client makes exactly one attempt (the prior behavior). */ export interface HttpRetryOptions { /** Max in-process retries after the first attempt (total attempts = maxRetries + 1). */ maxRetries: number; /** Base delay for exponential backoff; the ceiling is `baseDelayMs * 2^attempt`. */ baseDelayMs: number; /** Upper bound on the exponential ceiling before jitter. Defaults to 30s. */ maxDelayMs?: number; /** Injectable sleep for tests; defaults to a real `setTimeout` delay. */ sleep?: (ms: number) => Promise; /** Injectable jitter source in [0, 1); defaults to `Math.random`. */ random?: () => number; } export interface HttpClientOptions { /** Base URL (or a lazy builder, e.g. to read an env-configured host at call time). */ baseUrl: string | (() => string); /** * Lazy auth-header builder, invoked per call. Read the credential here (never * at import) so a missing secret fails close on first use, per ADR-0007. * * May return a promise, which is what lets a port mint a short-lived token * (an OAuth refresh exchange, say) instead of only reading one from the * environment. A synchronous builder still satisfies this. */ auth?: () => Record | Promise>; /** Vendor + purpose prefix for error messages, e.g. `"GitLab API"`. */ label?: string; /** Injectable fetch for tests; defaults to the global `fetch`. */ fetchImpl?: FetchLike; /** * Opt-in bounded backoff for transient (429/5xx) responses. Omit for the * default single-attempt behavior. See {@link HttpRetryOptions}. */ retry?: HttpRetryOptions; } export interface HttpClient { /** Make an authenticated JSON request; returns the parsed body, throws on non-2xx. */ call(path: string, init?: CallInit): Promise; } export declare function createHttpClient(opts: HttpClientOptions): HttpClient; //# sourceMappingURL=http.d.ts.map