UNPKG

cloudflare-client

Version:
63 lines (62 loc) 1.8 kB
export declare enum HttpMethod { GET = "GET", PUT = "PUT", POST = "POST", PATCH = "PATCH", DELETE = "DELETE" } export declare type Credentials = { /** * Cloudflare API token */ accessToken: string; } | { authKey: string; authEmail: string; }; declare type FetchOptions = { method: HttpMethod; url: URL | string; searchParams?: Record<string, unknown>; contentType?: string; accept?: string; body?: BodyInit; single?: true; type?: "text" | "json" | "binary"; notFoundResponse?: any; credentials: Credentials; }; declare type FetchInit = (...args: ReadonlyArray<any>) => FetchOptions; export declare type Params = Record<string, string | number | unknown> | string; export declare type Message = { code: number; message: string; type?: string; }; export interface Response { success: boolean; errors: Message[]; messages: Message[]; } interface QueryResponse<T> extends AsyncIterable<T> { all: () => Promise<Array<T>>; first: () => Promise<T | undefined>; totalCount: number; } export interface Query<T> extends Promise<QueryResponse<T>>, Omit<QueryResponse<T>, "totalCount"> { all: () => Promise<Array<T>>; first: () => Promise<T | undefined>; } export declare const baseUrl = "https://api.cloudflare.com/client/v4"; export declare function createFetch<I extends FetchInit>(init: I): { response: <R>() => (...args: Parameters<I>) => Promise<R>; query: <R>() => (...args: Parameters<I>) => Query<R>; }; export declare class FetchError extends Error { readonly code: number; readonly errors: Message[]; readonly messages: Message[]; readonly response: globalThis.Response; constructor(data: Response, res: globalThis.Response); } export {};