import { Readable } from "stream"; import { ClientError } from "../client-error"; export type HttpMethod = "get" | "head" | "post" | "put" | "delete" | "connect" | "trace" | "patch"; export type RequestConfig = { parse: "json" | "text" | "stream" | "response"; json?: boolean; throwOnErrorHttpCode?: boolean; }; export type SendStreamOptions = Partial<{ type: string; end: boolean; parseResponse?: "json" | "text" | "stream" | "response"; }>; export type GetStreamOptions = Partial<{ type: string; encoding?: BufferEncoding; }>; export type Headers = Record; export type RequestLogger = { request: (...req: any) => void; end: (...req: any) => void; ok: (res: any) => void; error: (res: ClientError) => void; }; export interface HttpClient { addLogger(logger: Partial): void; get(url: string, requestInit?: RequestInit): Promise; getStream(url: string, requestInit?: RequestInit): Promise; post(url: string, data: any, requestInit?: RequestInit, options?: { json: boolean; } & RequestConfig): Promise; put(url: string, data: any, requestInit?: RequestInit, options?: { json: boolean; } & RequestConfig): Promise; delete(url: string, requestInit?: RequestInit): Promise; request(method: HttpMethod, url: string, requestInit?: RequestInit, options?: RequestConfig): Promise; sendStream(url: string, stream: any, requestInit?: RequestInit, options?: SendStreamOptions): Promise; } export interface HttpClientNode extends HttpClient { getStream(url: string, requestInit?: RequestInit): Promise; sendStream(url: string, stream: Readable | string, requestInit?: RequestInit, options?: SendStreamOptions): Promise; } export interface HttpClientBrowser extends HttpClient { getStream(url: string, requestInit?: RequestInit): Promise; sendStream(url: string, stream: ReadableStream | string, requestInit?: RequestInit, options?: SendStreamOptions): Promise; }