/** * `HttpClient` — the optional cached-read path. * * When the host advertised an `httpEndpoint` at handshake, read-only, * `open`-gated capabilities route here instead of over the bridge: a plain * `POST` the host's Next.js backend can cache (`unstable_cache` / CDN), shared * across every mini-app and user. * * Wire contract (uniform across all capabilities — see `transport.ts`): * - `call` → `POST {endpoint}/{method}` with body `{ capability, args }`, * response is the capability's JSON return value. * - `subscribe` → `EventSource` on * `GET {endpoint}/subscribe?capability=…&args=…`, one JSON * frame per event. * * NOTE for APNA-RD-HOST-008: the host's `/api/nostr/query` + `/api/nostr/subscribe` * routes (built in HOST-005/006) currently take `{ filters, relays?, revalidate? }` * / `?filters=&relays=`. They must be aligned to this uniform * `{ capability, args }` shape so HTTP and bridge are interchangeable transports * for the same `(capability, args)` call. Those routes are not wired to anything * yet, so the change is safe. */ /** Minimal `EventSource` shape — injectable for tests / non-browser runtimes. */ export interface EventSourceLike { onmessage: ((event: { data: string; }) => void) | null; onerror: ((event: unknown) => void) | null; close(): void; } export declare type EventSourceCtor = (url: string) => EventSourceLike; export interface HttpClientOptions { /** Base URL the host advertised, e.g. `https://host/api/nostr`. */ endpoint: string; /** In-flight promise dedup TTL in ms. Default 10000. */ dedupTtlMs?: number; /** Injectable `fetch` (defaults to the global). */ fetchImpl?: typeof fetch; /** Injectable `EventSource` constructor (defaults to the global). */ eventSourceCtor?: EventSourceCtor; } export declare class HttpClient { private readonly endpoint; private readonly dedupTtlMs; private readonly fetchImpl; private readonly eventSourceCtor?; private readonly inflight; constructor(options: HttpClientOptions); /** POST a read-only capability call; identical in-flight calls are de-duped. */ call(capability: string, args?: unknown[]): Promise; /** Open an SSE stream for a read-only capability. Returns an unsubscribe fn. */ subscribe(capability: string, args: unknown[], onEvent: (data: unknown) => void): () => void; }