type EventStreamConnectionState = "connected" | "connecting" | "disconnected" | "disposed"; interface EventStreamSocket { addEventListener(type: "close", listener: (event: CloseEvent) => void): void; addEventListener(type: "error", listener: (event: Event) => void): void; addEventListener(type: "message", listener: (event: MessageEvent) => void): void; removeEventListener(type: "close", listener: (event: CloseEvent) => void): void; removeEventListener(type: "error", listener: (event: Event) => void): void; removeEventListener(type: "message", listener: (event: MessageEvent) => void): void; close(code?: number, reason?: string): void; send(data: string): void; } type EventStreamSocketFactory = (url: string) => EventStreamSocket; type TimerCleanup = () => void; interface EventStreamHeartbeatConfig { pingIntervalMs: number; pongTimeoutMs: number; scheduleInterval: (callback: () => void, delayMs: number) => TimerCleanup; scheduleTimeout: (callback: () => void, delayMs: number) => TimerCleanup; } interface EventStreamReconnectConfig { initialDelayMs: number; maxDelayMs: number; scheduleTimeout: (callback: () => void, delayMs: number) => TimerCleanup; } type EventStreamClientFrame = { kind: "subscribe"; requestId: string; topics: string[]; scope?: TScope; } | { kind: "unsubscribe"; requestId: string; topics: string[]; scope?: TScope; } | { kind: "publish"; requestId: string; event: TClientEvent; } | { kind: "ping"; requestId: string; sentAt: string; }; type EventStreamServerFrame = { kind: "ready"; protocolVersion: number; catalogRevision: string; serverTime?: string; } | { kind: "ack"; requestId: string; acceptedAt?: string; } | { kind: "error"; requestId?: string; code?: string; message?: string; } | { kind: "event"; event: TServerEvent; } | { kind: "pong"; requestId: string; sentAt?: string; }; interface EventStreamServerEvent { topic: string; scope?: TScope; } interface EventStreamProtocol { protocolVersion: number; catalogRevision: string; assertValidClientFrame(frame: unknown): void; assertValidServerFrame(frame: unknown): void; createClientEvent(topic: string, payload: unknown): TClientEvent; normalizeScope(scope: TScope | undefined): TScope | undefined; scopeKey(scope: TScope | undefined): string; eventMatchesScope(eventScope: TScope | undefined, subscriptionScope: TScope | undefined): boolean; } interface CreateEventStreamClientInput { protocol: EventStreamProtocol; resolveUrl: () => Promise | string; defaultScope?: TScope; webSocketFactory?: EventStreamSocketFactory; heartbeat?: Partial; reconnect?: false | Partial; /** * Invoked when a server frame fails parsing or schema validation. After the * ready handshake such frames are dropped without disconnecting; without * this hook the drop is invisible, which hides producer/schema drift. */ onInvalidFrame?: (error: Error, context: { ready: boolean; summary: EventStreamInvalidFrameSummary; }) => void; } interface EventStreamInvalidFrameSummary { dataBytes: number | null; dataType: string; eventKeys: string[]; frameKind: string | null; payloadKeys: string[]; payloadType: string | null; topic: string | null; } interface EventStreamClient { connect(): Promise; dispose(): void; getConnectionState(): EventStreamConnectionState; publishIntent(topic: string, payload: unknown): Promise; subscribe(topic: string, listener: (event: TServerEvent) => void, options?: { scope?: TScope | null; }): () => void; subscribeConnectionState(listener: (state: EventStreamConnectionState) => void): () => void; } declare function createEventStreamClient, TScope>(input: CreateEventStreamClientInput): EventStreamClient; export { type CreateEventStreamClientInput, type EventStreamClient, type EventStreamClientFrame, type EventStreamConnectionState, type EventStreamHeartbeatConfig, type EventStreamInvalidFrameSummary, type EventStreamProtocol, type EventStreamReconnectConfig, type EventStreamServerEvent, type EventStreamServerFrame, type EventStreamSocket, type EventStreamSocketFactory, createEventStreamClient };