import type { ErrorCode } from '@cleocode/contracts/cloud'; /** * `E_NETWORK`: the request never got an answer. `E_PROTOCOL`: the server answered with something the * contract or the E2E checks do not allow (a malformed body, replayed or reordered segments, a rolled-back * checkpoint). Both are client-side codes; the server never sends them. */ export type ClientErrorCode = ErrorCode | 'E_NETWORK' | 'E_PROTOCOL'; export declare class NexusError extends Error { readonly code: ClientErrorCode; readonly status: number; readonly requestId: string | null; readonly details?: Record | undefined; /** The server's own message, without the code prefix and request id `message` carries. */ readonly serverMessage: string; constructor(code: ClientErrorCode, message: string, status: number, requestId: string | null, details?: Record | undefined); } export type FetchLike = (input: string, init?: RequestInit) => Promise; /** Anything with zod's `safeParse`: every response body is parsed against its contract schema. */ export interface ResponseSchema { safeParse(data: unknown): { success: boolean; data?: T; }; } export interface HttpOptions { /** https, or http only for localhost (tests and local development). */ baseUrl: string; token: string; deviceId?: string; fetch?: FetchLike; /** Attempts for retryable failures: network, 5xx, 429. Default 4. */ maxAttempts?: number; sleep?: (ms: number) => Promise; } /** The longest a server-sent Retry-After may make the client wait. Longer values are clamped. */ export declare const MAX_RETRY_AFTER_MS = 30000; /** True for https URLs, and for http URLs on a loopback host. */ export declare function isSecureUrl(url: string): boolean; /** * The header saying this client reads journal (checkpoint/v3) streams (T13867). * Cleo Nexus refuses a v3 stream's checkpoint and head reads to a request * without it (T13876): such a client reads only snapshots and would report a * stale store as current. Released v2026.10.19 does not send it. */ export declare const NEXUS_STREAM_READER_HEADER: { readonly name: "x-cleo-stream-reader"; readonly value: "3"; }; /** * Minimal envelope-aware HTTP client. It retries only failures that are safe to retry. Every API * write is idempotent or lineage-checked, so a retried write either no-ops or is refused explicitly. * It never follows redirects, so a bearer token is never replayed to another origin. */ export declare class Http { private readonly o; private readonly fetch; private readonly sleep; /** * The server's clock relative to this device's, from the `Date` header of * its latest response: `serverDate − receivedAt` in ms (negative when this * device runs ahead), or null before one arrived (or when it sent none). * Measured at receipt, so time spent after the response never counts as * drift. Push pauses when this device runs ahead (journal spec §1.3). */ lastServerOffsetMs: number | null; constructor(o: HttpOptions); /** Send a request and parse the success payload against `schema`. A payload that does not parse is E_PROTOCOL. */ request(method: string, path: string, schema: ResponseSchema, body?: unknown): Promise; /** * {@link Http.request}, plus the HTTP status of the successful response, for routes whose * status carries meaning (e.g. `POST /v1/projects`: 201 created, 200 already registered). */ requestWithStatus(method: string, path: string, schema: ResponseSchema, body?: unknown): Promise<{ data: T; status: number; }>; } /** Honour a numeric Retry-After, clamped to MAX_RETRY_AFTER_MS; otherwise back off exponentially. */ export declare function retryDelay(retryAfter: string | null, attempt: number): number; //# sourceMappingURL=http.d.ts.map