/*! * Copyright (c) 2026 Interop Alliance. All rights reserved. */ /** * The load-bearing transport layer: wraps `zcapClient.request(...)`, resolving * paths against the server URL and defaulting the capability `action` to the * HTTP method (never ezcap's `read`/`write`). `send()` adds the typed-error * mapping and the null-on-404 read translation; `rawRequest()` is the * unmapped escape hatch used by `was.request()`. */ import type { ZcapClient } from '@interop/ezcap'; import type { HttpResponse } from '@interop/http-client'; import type { EncryptionProvider } from '../codec.js'; import type { IZcap, RequestInput } from '../types.js'; /** * The shared context threaded through every handle: the server base URL, the * wrapped ezcap client, the cached controller DID of its signer, and the * optional encryption provider that supplies an encrypting codec for the * collections the client holds keys for. */ export interface ClientContext { serverUrl: string; zcapClient: ZcapClient; controllerDid: string; encryption?: EncryptionProvider; } /** * A single signed request: the public `RequestInput` shape (either `path`, * resolved against `serverUrl`, or an absolute `url` must be given) plus the * `send()`-level 404 translations. */ export interface SendInput extends RequestInput { /** * When true, a 404 response resolves to `null` instead of throwing. */ read?: boolean; /** * When true, a 404 response resolves to `null` instead of throwing, so a * delete of an already-absent target succeeds (idempotent delete). */ idempotent?: boolean; } /** * Signs and sends a request via the wrapped ezcap client, returning the raw * `HttpResponse` and throwing the raw ky/ezcap error. Does not apply error * mapping or null-on-404 -- this is the escape-hatch primitive. * * @param context {ClientContext} * @param input {SendInput} * @returns {Promise} */ export declare function rawRequest(context: ClientContext, input: SendInput): Promise; /** * Sends an **unsigned** request (a plain `fetch`, no capability invocation), for * reading public (`PublicCanRead`) resources that need no authorization. Applies * the same typed-error mapping and null-on-404 read translation as `send()`. * Takes an absolute `url` -- public reads address a resource by its link, not by * a server-relative path. * * @param input {object} * @param input.url {string} absolute URL to read * @param [input.method] {string} HTTP method (defaults to `GET`) * @param [input.headers] {Record} * @param [input.read] {boolean} when true, a 404/401/403 resolves to `null` * @returns {Promise} */ export declare function unsignedRequest(input: { url: string; method?: string; headers?: Record; read?: boolean; }): Promise; /** * Signs and sends a request, applying the typed-error mapping. When `read` is * set, a 404 resolves to `null` (MongoDB `findOne` semantics); otherwise every * non-2xx maps to a `WasError` subclass. * * @param context {ClientContext} * @param input {SendInput} * @returns {Promise} */ export declare function send(context: ClientContext, input: SendInput): Promise; /** * The GET-a-JSON-description read shared across the handles: a signed * null-on-404 `GET` of `path` whose pre-parsed body is unwrapped as `T`. Both * a missing/unauthorized target (404) and a bodyless/non-JSON response resolve * to `null` (see `dataOrNull`). * * @param context {ClientContext} * @param options {object} * @param options.path {string} the path to read * @param [options.capability] {IZcap} capability attached to the request * @returns {Promise} */ export declare function readData(context: ClientContext, { path, capability }: { path: string; capability?: IZcap; }): Promise; //# sourceMappingURL=request.d.ts.map