types.ts (1474B)
1 import type { IError } from "@radroots/types-bindings"; 2 import type { ResolveError } from "@radroots/utils"; 3 4 export type FieldRecord = Record<string, string>; 5 6 export type NotifyMessage = { 7 message: string; 8 ok?: string; 9 cancel?: string; 10 }; 11 12 export type HttpMethod = "get" | "post" | "put"; 13 14 export type HttpJsonPrimitive = string | number | boolean | null; 15 export type HttpJsonValue = HttpJsonPrimitive | { [key: string]: HttpJsonValue } | HttpJsonValue[]; 16 17 export type IHttpOptsData = HttpJsonValue | FormData | Blob | ArrayBuffer | URLSearchParams; 18 export type IHttpOptsParams = Record<string, string | string[]>; 19 20 export type IHttpOpts = { 21 url: string; 22 method?: HttpMethod; 23 params?: IHttpOptsParams; 24 data?: IHttpOptsData; 25 data_bin?: Uint8Array; 26 authorization?: string; 27 headers?: FieldRecord; 28 connect_timeout?: number; 29 }; 30 31 export type IHttpImageResponse = { 32 status: number; 33 blob?: Blob; 34 headers: FieldRecord; 35 url: string; 36 }; 37 38 export type IHttpResponse = { 39 status: number; 40 data?: unknown; 41 error?: string; 42 message?: NotifyMessage; 43 headers: FieldRecord; 44 url: string; 45 }; 46 47 export type HttpError = IError<string>; 48 49 export interface IClientHttp { 50 fetch(opts: IHttpOpts): Promise<ResolveError<IHttpResponse>>; 51 fetch_image(url: string): Promise<ResolveError<IHttpImageResponse>>; 52 } 53 54 export type WebHttpConfig = { 55 app_name?: string; 56 app_version?: string; 57 app_hash?: string; 58 };