import type { ApplicationError, TResponsedError } from '@venizia/ignis-helpers/core'; /** * What an IGNIS server answers - `Content-Range`, the error envelope - read once, here, for every * client of that server: the http connector, and a client that reads it without the connector. */ export declare class HttpResponseReader { static isPlainObject(value: unknown): value is Record; /** An empty string reads as absent, so a fallback still applies. */ static toText(value: unknown): string | undefined; /** * A `Content-Range` header as the IGNIS server writes it: `records 0-24/137` -> skip 0, total 137; * an empty page, `records *\/137` -> total 137. Anything else, including an absent header or an * unknown total, is `undefined`. */ static parseContentRange(opts: { header?: string | null; }): { skip?: number; total: number; } | undefined; /** * The IGNIS error envelope - `{ message, statusCode, normalized: { text, code, args }, requestId, * extra, details }` - read off a parsed response body. A server configured with `error.rootKey` * wraps it under that key; pass the same `rootKey` to unwrap it. A body without that key, or with a * non-object under it (a proxy's `{ error: 'Bad Gateway' }`), is read as it stands. * * A body that is not a plain object yields `{}`; any other body yields its known fields, each * `undefined` when absent or mistyped. An empty string reads as absent. */ static readErrorEnvelope(opts: { body: unknown; rootKey?: string; }): TResponsedError; /** A failed response's envelope. A body that is not JSON yields `{}`, and the status alone still describes it. */ static readError(opts: { response: Response; rootKey?: string; }): Promise; /** * A failed response as the error the server threw: its status, code, args and text, and its * `extra` with the `requestId` added. `message` is `context` plus the server's text, for logs; * `normalized.text` stays the server's, for display - `HTTP ` when the server sent none. * `cause` is the server's `details.cause` - a 422's per-field issues, `{ path, message, code }`. * * `requestId` names the request this client made. A relaying server's `extra` carries the id of * the request it made upstream: it joins `upstreamRequestIds`, nearest first, at every hop. */ static toApplicationError(opts: { response: Response; /** Where it failed, for logs - e.g. `[HttpDataSource][read] 404 | /tickets`. */ context: string; rootKey?: string; }): Promise; /** * A body the server marked with `x-response-extra` carries `extra` beside its rows. `body` is what * the route answers without extras: the `{ count, data }` envelope when the count was asked for in * the body, the rows otherwise. Any other body is returned as it stands - an unmarked object is * never unwrapped, so a row that has `data` and `extra` columns of its own is never misread. */ static readExtra(opts: { body: unknown; headers: Pick; }): { body: unknown; extra?: Record; }; } //# sourceMappingURL=response-reader.d.ts.map