Events
Follow server-sent event operations, with reconnection handled for you.
1 min read36 pages in SDK Reference
On this page1
import { Compozy } from "@compozy/client";Subscribe to a stream
The TypeScript client reconnects dropped event streams and 5xx responses with Last-Event-ID, starting at 500 ms and doubling to 8 seconds. It also reconnects after a clean server close, so end the subscription by aborting its signal. It stops after 20 consecutive failed reconnects; a received frame resets that count. A 4xx stops immediately. Go streams do not reconnect: they return io.EOF when the server closes them.
compozy.events<Id extends SseOperationId>(
operationId: Id,
options: SseOptions<Id>
): AsyncIterable<StreamEvent<SseFrame<Id>>>Options
- pathobject
The operation's path parameters.
- queryobject
The operation's query parameters.
- signalAbortSignal
Abort the signal to end the subscription.
options is required: pass {} to an operation without parameters. Each frame carries data, and event and id when the server sent them.
const controller = new AbortController();
for await (const frame of compozy.events("streamSession", {
path: { workspace_id: workspace.id, session_id: session.id },
signal: controller.signal,
})) {
console.log(frame.event, frame.id, frame.data);
}