import type { Logger } from './logger.js'; /** * HTTP request configuration */ export interface RequestConfig { /** Request path (relative to baseUrl) */ path: string; /** HTTP method */ method: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE'; /** Request body */ body?: unknown; /** Query parameters */ params?: Record; /** Additional headers */ headers?: Record; /** Request timeout in milliseconds */ timeout?: number; } /** * Request options for individual requests */ export interface RequestOptions { /** Query parameters */ params?: Record; /** Additional headers */ headers?: Record; /** Request timeout in milliseconds */ timeout?: number; /** Signal for aborting the request */ signal?: AbortSignal; /** * Response type hint for the transport layer. * - 'json' (default): Parse response as JSON * - 'stream': Return the raw Response object for SSE/streaming */ responseType?: 'json' | 'stream'; /** * Override the transport's base URL for this request only. * Used for routing specific requests to different domains (e.g., SSE streaming). */ baseUrl?: string; /** * Request body for methods (like DELETE) whose top-level signature doesn't * accept a body positional arg. Required for endpoints that read params * from the DELETE body (non-standard but used by some 23blocks routes). * Ignored when calling `post`, `put`, or `patch` (those take body as a * positional argument). */ body?: unknown; } /** * Transport interface - abstraction over HTTP implementations */ export interface Transport { /** * Perform a GET request */ get(path: string, options?: RequestOptions): Promise; /** * Perform a POST request */ post(path: string, body?: unknown, options?: RequestOptions): Promise; /** * Perform a PATCH request */ patch(path: string, body?: unknown, options?: RequestOptions): Promise; /** * Perform a PUT request */ put(path: string, body?: unknown, options?: RequestOptions): Promise; /** * Perform a DELETE request */ delete(path: string, options?: RequestOptions): Promise; } /** * Headers provider function type */ export type HeadersProvider = (() => Record) | (() => Promise>); /** * Interceptors for request/response lifecycle */ export interface Interceptors { /** * Called before each request is sent * Can modify the request config or throw to abort */ onRequest?: (config: { method: string; path: string; body?: unknown; headers: Record; requestId: string; }) => void | Promise; /** * Called after each successful response * Can transform the response or throw to convert to error */ onResponse?: (response: T, context: { method: string; path: string; status: number; duration: number; requestId: string; }) => T | Promise; /** * Called when an error occurs * Can transform the error, recover, or re-throw */ onError?: (error: Error, context: { method: string; path: string; duration: number; requestId: string; }) => never | Promise; } /** * Transport configuration */ export interface TransportConfig { /** Base URL for all requests */ baseUrl: string; /** Default headers or headers provider */ headers?: Record | HeadersProvider; /** Default timeout in milliseconds */ timeout?: number; /** Retry configuration */ retry?: RetryConfig; /** * Credentials mode for fetch requests * - 'include': Always send cookies, even for cross-origin requests * - 'same-origin': Only send cookies for same-origin requests (default browser behavior) * - 'omit': Never send cookies * Use 'include' for cookie-based authentication */ credentials?: 'include' | 'same-origin' | 'omit'; /** * Enable debug logging * When true, logs all requests and responses to the console */ debug?: boolean; /** * Custom logger implementation * Defaults to consoleLogger when debug is true, noopLogger otherwise */ logger?: Logger; /** * Custom request ID generator * Defaults to generateRequestId() which produces 'req__' */ generateRequestId?: () => string; /** * Request/response interceptors */ interceptors?: Interceptors; } /** * Retry configuration */ export interface RetryConfig { /** Maximum number of retries */ maxRetries: number; /** Initial delay in milliseconds */ initialDelay: number; /** Maximum delay in milliseconds */ maxDelay: number; /** Backoff multiplier */ backoffMultiplier: number; /** Status codes to retry on */ retryableStatuses?: number[]; } //# sourceMappingURL=transport.d.ts.map