UNPKG

@baqhub/sdk

Version:

The official JavaScript SDK for the BAQ federated app platform.

59 lines (58 loc) 2.68 kB
import { CustomError } from "../helpers/customError.js"; import { HttpHeaders } from "../model/core/httpHeaders.js"; import { HttpMethod } from "../model/core/httpMethod.js"; import { EventSourceMessage } from "./eventSourceParse.js"; interface HttpApi { fetch: typeof fetch; eventSourceFetch: typeof fetch; } declare let api: HttpApi; export declare function setHttpApi(newApi: typeof api): void; export declare class RequestError extends CustomError { options: HttpSendOptions; status: number; headers: Headers; constructor(options: HttpSendOptions, status: number, headers: Headers); } export declare class RequestFailedError extends CustomError { baseError: unknown; constructor(baseError: unknown); } declare function isError<T extends ReadonlyArray<number> | undefined>(error: unknown, statuses?: T): error is T extends undefined ? RequestFailedError | RequestError : RequestError; export interface HttpQuery { [T: string]: string | undefined; } export type HttpAuthorizationBuilder = (method: HttpMethod, url: string, headers: HttpHeaders) => string; export interface HttpOptions { headers?: HttpHeaders; query?: HttpQuery; signal?: AbortSignal; authorizationBuilder?: HttpAuthorizationBuilder; } interface HttpSendOptions extends HttpOptions { method: HttpMethod; url: string; body?: unknown; } declare function httpHead(url: string, options?: HttpOptions): Promise<Headers>; declare function httpGet(url: string, options?: HttpOptions): Promise<readonly [Headers, unknown]>; declare function httpDownload(url: string, options?: HttpOptions): Promise<readonly [Headers, Blob]>; declare function httpPost(body: unknown, url: string, options?: HttpOptions): Promise<readonly [Headers, unknown]>; declare function httpPut(body: unknown, url: string, options?: HttpOptions): Promise<readonly [Headers, unknown]>; declare function httpPatch(body: unknown, url: string, options?: HttpOptions): Promise<readonly [Headers, unknown]>; declare function httpDelete(url: string, options?: HttpOptions): Promise<Response>; declare function httpDeleteBody(body: unknown, url: string, options?: HttpOptions): Promise<readonly [Headers, unknown]>; declare function httpEventSource(onMessage: (event: EventSourceMessage) => void, url: string, options?: HttpOptions): void; export declare const Http: { isError: typeof isError; head: typeof httpHead; get: typeof httpGet; post: typeof httpPost; put: typeof httpPut; patch: typeof httpPatch; delete: typeof httpDelete; deleteBody: typeof httpDeleteBody; download: typeof httpDownload; eventSource: typeof httpEventSource; }; export {};