//#region src/http/index.d.ts /** * HTTP method accepted by {@link HttpInvocationConfig}. Distinct from the core * `builtin_triggers` HTTP method enum, which also covers HEAD/OPTIONS. */ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; /** * Authentication configuration for HTTP-invoked functions. * * - `hmac`: HMAC signature verification using a shared secret. * - `bearer`: Bearer token authentication. * - `api_key`: API key sent via a custom header. */ type HttpAuthConfig = { type: 'hmac'; secret_key: string; } | { type: 'bearer'; token_key: string; } | { type: 'api_key'; header: string; value_key: string; }; /** * Configuration for an HTTP-invoked function (Lambda, Cloudflare Workers, etc.). */ type HttpInvocationConfig = { /** URL to invoke. */url: string; /** HTTP method. Defaults to `POST`. */ method?: HttpMethod; /** Timeout in milliseconds. */ timeout_ms?: number; /** Custom headers to send with the request. */ headers?: Record; /** Authentication configuration. */ auth?: HttpAuthConfig; }; /** * Incoming buffered HTTP request received by a function handler. * * @typeParam TBody - Type of the parsed request body. */ type HttpRequest = { /** Path parameters extracted from the matched route. */path_params: Record; /** Query-string parameters from the request URL. */ query_params: Record; /** Parsed request body. */ body: TBody; /** Request headers. */ headers: Record; /** HTTP method of the request (e.g. `GET`, `POST`). */ method: string; /** Streaming reader for the raw request body. */ request_body: HttpStreamReader; }; /** * Structured buffered HTTP response returned from function handlers. * * @typeParam TStatus - HTTP status code literal type. * @typeParam TBody - Type of the response body. * * @example * ```typescript * const response: HttpResponse = { * status_code: 200, * headers: { 'content-type': 'application/json' }, * body: { message: 'ok' }, * } * ``` */ type HttpResponse> = { /** HTTP status code. */status_code: TStatus; /** Response headers. */ headers?: Record; /** Response body. */ body?: TBody; }; /** * Structural shape of the reader end of a stream channel. Declared locally so * the helpers package does not runtime-depend on the core SDK. */ type HttpStreamReader = { stream: NodeJS.ReadableStream; readAll: () => Promise; onMessage: (callback: (msg: string) => void) => void; close: () => void; }; /** Structural shape of the writer end of a stream channel. */ type HttpStreamWriter = { sendMessage: (message: string) => unknown; stream: NodeJS.WritableStream; close: () => unknown; }; /** Structural shape of a streaming request passed to the {@link http} handler. */ type HttpStreamingRequest = { path_params: Record; query_params: Record; body: unknown; headers: Record; method: string; request_body: HttpStreamReader; }; /** Structural shape of the streaming response passed to the {@link http} handler. */ type HttpStreamingResponse = { status: (statusCode: number) => void; headers: (headers: Record) => void; stream: NodeJS.WritableStream; close: () => void; }; /** Structural shape of the internal request delivered by the runtime. */ type HttpInternalRequest = HttpStreamingRequest & { response: HttpStreamWriter; }; /** * Helper that wraps an HTTP-style handler (with separate `req`/`res` arguments) * into the function handler format expected by the SDK. * * @param callback - Async handler receiving a streaming request and response. * @returns A function handler compatible with `IIIClient.registerFunction`. * * @example * ```typescript * import { http } from '@iii-dev/helpers/http' * * worker.registerFunction( * 'my-api', * http(async (req, res) => { * res.status(200) * res.headers({ 'content-type': 'application/json' }) * res.stream.end(JSON.stringify({ hello: 'world' })) * res.close() * }), * ) * ``` */ declare const http: (callback: (req: HttpStreamingRequest, res: HttpStreamingResponse) => Promise) => (req: HttpInternalRequest) => Promise | Record>>; //#endregion export { HttpAuthConfig, HttpInvocationConfig, HttpMethod, HttpRequest, HttpResponse, http }; //# sourceMappingURL=index.d.mts.map