import { Channel } from '../core/channels'; import { EventName, PermissionGrant } from '../core/protocol'; import { CapabilityHandlers } from '../interfaces/host'; import { INostr } from '../interfaces/nostr'; /** * Legacy host config shape — `{ methodHandlers: { nostr: INostr } }`. Kept so * `apna-app` keeps working unchanged until APNA-RD-HOST-009 swaps it for the * namespaced `CapabilityHandlers` registry. See `adaptLegacyMethodHandlers`. */ export interface IHostMethodHandlers { nostr?: INostr; } export interface ApnaHostConfig { /** New: namespaced/versioned capability registry. */ handlers?: CapabilityHandlers; /** Legacy: old `{ nostr: {...} }` method-handlers object (host-shape shim). */ methodHandlers?: IHostMethodHandlers; /** * Channel to communicate over. Defaults to an auto-binding `IframeChannel` * that latches onto the first mini-app iframe that handshakes — preserving * the legacy "just construct it" behavior. APNA-RD-HOST-013 will pass an * explicit per-iframe channel for true parallel-instance isolation. */ channel?: Channel; /** Optional HTTP read endpoint to advertise at handshake. */ httpEndpoint?: string; /** Optional design-component Module Federation remote to advertise. */ designRemote?: string; /** Host-supplied permission gate. If omitted, gated calls pass through. */ permissionGate?: { check(capability: string): Promise<'allow' | 'deny'>; request?(capabilities: string[]): Promise; query?(): PermissionGrant[]; revoke?(capability: string): void; }; } /** * `ApnaHost` — the host (super-app) side of the bridge, one per mini-app * instance. Dispatches `rpc:request`s against a `CapabilityHandlers` registry, * answers the handshake, and pushes typed events to the mini-app. * * Transitional: a `permissionGate` is NOT yet wired (APNA-RD-HOST-010/-014) — * every call currently passes straight through to its handler. */ export declare class ApnaHost { private readonly handlers; private readonly channel; private readonly bridge; private readonly httpEndpoint?; private readonly designRemote?; private readonly permissionGate?; private readonly streamCleanups; /** instanceId of the connected mini-app, learned at handshake. */ private connectedInstanceId; constructor(config: ApnaHostConfig); /** Push a typed event to the connected mini-app. */ emit(event: EventName, payload?: unknown): void; /** * Legacy compat for the old `sendMessage(iframe, 'superapp:message', payload)`. * The only message the ecosystem sent this way is the Customise-Mode toggle; * translate it to a typed event. Superseded by `emit` (APNA-RD-HOST-014). */ sendMessage(_iframe: unknown, type: string, payload?: { type?: string; }): void; /** Tear down listeners and the channel. */ dispose(): void; private readonly onHandshake; private readonly onRpcRequest; private readonly onPermissionRequest; private readonly onStreamStart; private readonly onStreamStop; private dispatch; private handlePermissionRequest; private startStream; private stopStream; private ensureAllowed; }