import type { RetryOptions } from "../schemas/index.js"; import type { Attributes, Span } from "@opentelemetry/api"; import { type ErrorEvent } from "eventsource"; import type { TriggerTracer } from "../tracer.js"; import type { AnyZodSchema, inferZodSchemaOutput } from "../types/schemas.js"; import type { CursorPageParams, CursorPageResponse, OffsetLimitPageParams, OffsetLimitPageResponse } from "./pagination.js"; import { CursorPage, OffsetLimitPage } from "./pagination.js"; export declare const defaultRetryOptions: { maxAttempts: number; factor: number; minTimeoutInMs: number; maxTimeoutInMs: number; randomize: false; }; export type ZodFetchOptions = { retry?: RetryOptions; tracer?: TriggerTracer; name?: string; attributes?: Attributes; icon?: string; onResponseBody?: (body: TData, span: Span) => void; prepareData?: (data: TData, response: Response) => Promise | TData; }; export type AnyZodFetchOptions = ZodFetchOptions; export type ApiRequestOptions = Pick & { additionalHeaders?: Record; }; export declare const isRequestOptions: (obj: unknown) => obj is ApiRequestOptions; interface FetchCursorPageParams extends CursorPageParams { query?: URLSearchParams; } interface FetchOffsetLimitPageParams extends OffsetLimitPageParams { query?: URLSearchParams; } export declare function zodfetch(schema: TResponseBodySchema, url: string, requestInit?: RequestInit, options?: ZodFetchOptions>): ApiPromise>; export declare function zodfetchCursorPage(schema: TItemSchema, url: string, params: FetchCursorPageParams, requestInit?: RequestInit, options?: ZodFetchOptions): CursorPagePromise; export declare function zodfetchOffsetLimitPage(schema: TItemSchema, url: string, params: FetchOffsetLimitPageParams, requestInit?: RequestInit, options?: ZodFetchOptions): OffsetLimitPagePromise; type ZodFetchResult = { data: T; response: Response; }; /** * A subclass of `Promise` providing additional helper methods * for interacting with the SDK. */ export declare class ApiPromise extends Promise { private responsePromise; constructor(responsePromise: Promise>); /** * Gets the raw `Response` instance instead of parsing the response * data. * * If you want to parse the response body but still get the `Response` * instance, you can use {@link withResponse()}. */ asResponse(): Promise; /** * Gets the parsed response data and the raw `Response` instance. * * If you just want to get the raw `Response` instance without parsing it, * you can use {@link asResponse()}. */ withResponse(): Promise<{ data: T; response: Response; }>; private parse; then(onfulfilled?: ((value: T) => TResult1 | PromiseLike) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike) | undefined | null): Promise; catch(onrejected?: ((reason: any) => TResult | PromiseLike) | undefined | null): Promise; finally(onfinally?: (() => void) | undefined | null): Promise; } export declare class CursorPagePromise extends ApiPromise>> implements AsyncIterable> { #private; private schema; private url; private params; private requestInit?; private options?; constructor(result: Promise>>>, schema: TItemSchema, url: string, params: FetchCursorPageParams, requestInit?: RequestInit | undefined, options?: ZodFetchOptions | undefined); /** * Allow auto-paginating iteration on an unawaited list call, eg: * * for await (const item of client.items.list()) { * console.log(item) * } */ [Symbol.asyncIterator](): AsyncGenerator>, void, unknown>; } export declare class OffsetLimitPagePromise extends ApiPromise>> implements AsyncIterable> { #private; private schema; private url; private params; private requestInit?; private options?; constructor(result: Promise>>>, schema: TItemSchema, url: string, params: FetchOffsetLimitPageParams, requestInit?: RequestInit | undefined, options?: ZodFetchOptions | undefined); /** * Allow auto-paginating iteration on an unawaited list call, eg: * * for await (const item of client.items.list()) { * console.log(item) * } */ [Symbol.asyncIterator](): AsyncGenerator>, void, unknown>; } export declare function isEmptyObj(obj: object | null | undefined): boolean; export declare function hasOwn(obj: object, key: string): boolean; export type ZodFetchSSEMessageValueSchema = TSchema; export interface ZodFetchSSEMessageCatalogSchema { [key: string]: AnyZodSchema; } export type ZodFetchSSEMessageHandlers = Partial<{ [K in keyof TCatalogSchema]: (payload: inferZodSchemaOutput) => Promise | void; }>; export type ZodFetchSSEOptions = { url: string; request?: RequestInit; messages: TMessageCatalog; retry?: RetryOptions; }; export declare class ZodFetchSSEResult { private options; private _eventSource; constructor(options: ZodFetchSSEOptions); onConnectionError(handler: (error: ErrorEvent) => void): void; onMessage(type: T, handler: ZodFetchSSEMessageHandlers[T]): void; stop(): void; } export declare function zodfetchSSE(options: ZodFetchSSEOptions): ZodFetchSSEResult; export type ApiResult = { success: true; data: TSuccessResult; } | { success: false; error: string; /** * HTTP status code, when the failure originated from an API response * (e.g. 429 for rate limiting). Undefined for connection/transport * errors that never reached the server. Lets callers distinguish * transient failures worth retrying from fatal ones. */ statusCode?: number; errorCode?: string | null; /** The server's `x-should-retry` header, when it sent one. Overrides any status-based decision. */ shouldRetry?: boolean; }; export declare function wrapZodFetch(schema: T, url: string, requestInit?: RequestInit, options?: ZodFetchOptions>): Promise>>; export {};