import type { IncomingMessage, ServerResponse } from 'node:http'; import type { MailboxEventEmitter } from './mailbox-events.js'; import type { Mailbox } from './mailbox-types.js'; export declare const MAILBOX_HTTP_MAX_BODY_BYTES: number; export declare const MAILBOX_HTTP_RATE_LIMIT_PER_MINUTE = 120; export declare const MAILBOX_HTTP_RATE_LIMIT_WINDOW_MS = 60000; export declare const MAILBOX_HTTP_DEFAULT_MAX_AGE_MS: number; export declare const MAILBOX_HTTP_MAX_AGE_CEILING_MS: number; export type MailboxHttpAccessDecision = { allowed: true; rateLimitKey?: string; } | { allowed: false; status?: number; body?: unknown; }; export interface MailboxHttpRouterOptions { mailbox: Mailbox; eventEmitter?: MailboxEventEmitter; authorize?: (request: IncomingMessage) => MailboxHttpAccessDecision | Promise; rateLimiter?: MailboxHttpRateLimiter; maxBodyBytes?: number; /** * Server-default look-back window for mailbox routes that return * `MailboxMessage` records (`/mailbox/query`, `/mailbox/check`, * `/mailbox/events`). * * The filter is **opt-in**: leaving `defaultMaxAgeMs` `undefined` * (the default) leaves the filter disabled and every retained * message is eligible to be returned or streamed. Pass an explicit * non-negative integer (e.g. `60 * 60_000` for a 1-hour look-back, * or {@link MAILBOX_HTTP_DEFAULT_MAX_AGE_MS}) to activate it. * * Mail older than the resolved look-back is filtered out of JSON * responses and from SSE delivery so polling agents are never * flooded with stale mail. The library intentionally does NOT * enable a default look-back; host integrators that want the * 1-hour server default must opt in explicitly. * * Per-request override: callers may append `?sinceMs=` to the * request URL (the URL is rewritten by hosts that mount the router * below a prefix). `0` opts in to the full retained history (matches * the disable semantics of `defaultMaxAgeMs` below) and any positive * value above {@link MAILBOX_HTTP_MAX_AGE_CEILING_MS} is silently * clamped to that ceiling — this is a soft cap, not a hard rejection. * * Disabling the filter server-wide: pass `defaultMaxAgeMs` as * `undefined` (the default), any negative number (`-1` is the * canonical test-suite escape hatch), any non-finite value (`NaN`, * `Infinity`, `-Infinity`), or `0`. `0` here is reserved because * `now - 0` would otherwise map to the current instant and hide * every retained message; `resolveDefault()` therefore treats `0` as * equivalent to "disabled" via the same sentinel path as * `undefined` / negative / non-finite values. The per-request * `?sinceMs=0` URL parameter and the server-side `defaultMaxAgeMs=0` * option therefore share identical "no filter" semantics. */ defaultMaxAgeMs?: number; } export declare function authorizeMailboxBearerToken(request: IncomingMessage, expectedToken: string): MailboxHttpAccessDecision; export interface MailboxHttpRouter { /** * Handle one canonical mailbox HTTP request. `routePath` lets a host mount * the protocol below another prefix while preserving the public * `/mailbox/*` route contract internally. */ handle(request: IncomingMessage, response: ServerResponse, routePath?: string): Promise; /** Close every active SSE stream owned by this router. Idempotent. */ close(): void; } /** Sliding-window request limiter shared by every mailbox HTTP host. */ export declare class MailboxHttpRateLimiter { readonly limit: number; readonly windowMs: number; private readonly hits; constructor(limit?: number, windowMs?: number); allow(key: string): boolean; cleanup(): void; } export declare function createMailboxHttpRouter(options: MailboxHttpRouterOptions): MailboxHttpRouter; //# sourceMappingURL=mailbox-http-router.d.ts.map