import { AdapterFlags, Context } from "@decaf-ts/core"; export type ResponseParser = = Context>(res: any, ctx: C) => void; /** * @description HTTP configuration type * @summary Configuration type for HTTP connections specifying protocol and host * @typedef {Object} HttpConfig * @property {('http'|'https')} protocol - The HTTP protocol to use * @property {string} host - The host address * @property {boolean} [idInUrl=true] - When true (default), write operations (create, update) include the resource id (and composed pk parts) in the URL path, matching REST semantics. Set to false to POST/PUT against the collection URL only. * @memberOf module:for-http */ export type HttpConfig = { protocol: "http" | "https"; host: string; parsers?: ResponseParser[]; eventsListenerPath?: string; headers?: boolean; events?: boolean; eventsSubscription?: boolean; eventHeaderResolver?: () => Promise> | Record; idInUrl?: boolean; }; export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE"; export type HttpRequestTransform = (data: any, headers?: Record) => any; /** * @description Generic request options for simple HttpAdapter calls * @summary for-http owned request options shaped after Axios request config. * The adapter maps these options to the underlying client configuration. * @interface HttpRequestOptions */ export interface HttpRequestOptions { timeout?: number; headers?: Record; params?: Record; baseURL?: string; responseType?: "json" | "text" | "arraybuffer" | "blob" | "document" | "stream"; auth?: { username: string; password: string; }; signal?: AbortSignal; transformRequest?: HttpRequestTransform | HttpRequestTransform[]; transformResponse?: HttpRequestTransform | HttpRequestTransform[]; validateStatus?: (status: number) => boolean; includeCredentials?: boolean; withCredentials?: boolean; } /** * @description Generic HTTP response shape used by simple HttpAdapter helpers * @summary for-http owned response envelope aligned with Axios semantics by default. * `code` maps to HTTP status code, `data` to response payload, and `error` to failure details. * @interface HttpResponse */ export interface HttpResponse { code: number; data?: T; error?: E; } /** * @description HTTP flags interface * @summary Interface extending RepositoryFlags with HTTP-specific options * @interface HttpFlags * @property {Record} [headers] - Optional HTTP headers to include with requests * @memberOf module:for-http */ export interface HttpFlags extends AdapterFlags { headers?: Record; }