Server-Sent Events (SSE) reference for OFFER-HUB — subscribe, filter, reconnect and replay, plus the complete domain event catalog with a payload example for every event type.
OFFER-HUB delivers real-time domain events over Server-Sent Events (SSE). Connect your marketplace backend once and react to changes such as a credited balance, funded escrow, or resolved dispute without polling.
Note
This is an outbound stream from the Orchestrator. OFFER-HUB does not send outbound webhooks to your application. The only inbound webhook endpoints that exist (POST /api/v1/webhooks/airtm and POST /api/v1/webhooks/trustless-work) are receivers used by external providers to notify your Orchestrator — see the Inbound Webhooks reference.
Subscribe to the event stream
GET/api/v1/events
Authenticate with a valid API key in the Authorization header:
typescript
Authorization: Bearer ohk_live_...
The route is protected by ApiKeyGuard only — no additional scope is required. EventsController.streamEvents in the Orchestrator (apps/api/src/modules/events/events.controller.ts) does not apply ScopeGuard, so any valid API key (or the master key) can connect.
Events are scoped to the marketplace bound to your API key. The controller reads apiKey.marketplaceId and SseService.getEventStream drops every event whose metadata.marketplaceId does not match (apps/api/src/modules/events/sse.service.ts). Each marketplace only ever receives its own events — even with a replay request.
Filter the stream
Use repeated query parameters to filter by exact event or aggregate type:
One or more aggregate types, such as Order or Balance
Includes only events with a matching aggregateType.
since
ISO 8601 timestamp
Replays buffered events after the timestamp when no Last-Event-ID header is supplied.
Warning
SSE filters use exact matches (filters.types.includes(event.eventType) against the values you send). types=order.* and types=* are not valid on the public stream — use individual event types such as order.created and order.closed. Wildcard patterns (order.*, *) exist only on the internal event bus.
Event envelope
Every event is a DomainEvent. payload varies by eventType; the remaining fields use the same shape for every event (apps/api/src/modules/events/types/domain-event.ts).
typescript
interface DomainEvent<T = unknown> { eventId: string; // "evt_..." — unique, for dedup eventType: string; // "order.escrow_funded" — from the catalog below occurredAt: string; // ISO 8601 timestamp aggregateId: string; // ID of the resource that produced the event aggregateType: string; // "Order", "TopUp", "Withdrawal", ... payload: T; // Event-specific data (see catalog below) metadata: { correlationId?: string; // Request ID that triggered the event causationId?: string; // ID of the event that caused this one userId?: string; // User who triggered the action marketplaceId?: string; // Used for marketplace isolation [key: string]: unknown; };}
Documentation table
Field
Type
Description
eventId
string
Unique event identifier, generated with the evt_ prefix. Use it for deduplication.
eventType
string
The event name from the catalog below, such as order.escrow_funded.
occurredAt
string
ISO 8601 timestamp at which the event was emitted.
aggregateId
string
ID of the resource that produced the event.
aggregateType
string
Resource type, such as Order, TopUp, or Withdrawal.
payload
object
Data specific to the event type.
metadata
object
Correlation, causation, user, marketplace, and any additional context.
On the wire, each SSE message uses the event's timestamp as its SSE id, its eventType as the SSE event name, and the complete envelope as JSON data (apps/api/src/modules/events/events.controller.ts):
The ping has no eventId — ignore it rather than treating it as a domain event.
Reconnect and replay
Missed events are replayed from a Redis sorted set (events:log) scored by occurredAt, capped at the last 1,000 events (SseService.MAX_EVENTS, apps/api/src/modules/events/sse.service.ts). To resume after a disconnect, send the id of the last event you received in the standard Last-Event-ID header. This header takes precedence over the since query parameter:
Replay is exclusive of the cursor timestamp (SseService.getMissedEvents opens the scan at (<timestamp>), so the event you already processed is not re-sent. While history is being replayed, live events are buffered at the connection and de-duplicated against the history by eventId, closing the gap between Last-Event-ID and reconnection (ReplaySubject(100) in EventsController).
Treat the stream as at-least-once delivery: persist processed eventId values and ignore a duplicate before performing side effects.
Reconnection example
A resilient subscriber reconnects on error, passes the last eventId back as Last-Event-ID, and ignores duplicates:
typescript
import { EventSource } from 'eventsource';class EventSubscriber { private url = 'http://localhost:4000/api/v1/events'; private lastEventId?: string; private processed = new Set<string>(); // persist this in production connect() { const headers = { Authorization: 'Bearer ohk_live_...' }; if (this.lastEventId) { (headers as Record<string, string>)['Last-Event-ID'] = this.lastEventId; } const es = new EventSource(this.url, { headers }); es.onmessage = (message) => { if (message.lastEventId) this.lastEventId = message.lastEventId; const event = JSON.parse(message.data); if (this.processed.has(event.eventId)) return; // already handled this.processed.add(event.eventId); this.handle(event); }; es.onerror = () => { // EventSource auto-reconnects; the next connection replays from lastEventId }; }}
The native browser EventSource cannot set an Authorization header, so connect through your backend or another credential-safe proxy:
typescript
const events = new EventSource('/api/v1/events'); // proxied by your backendevents.addEventListener('order.escrow_funded', (message) => { const event = JSON.parse(message.data); console.log(event.eventType, event.payload);});
Event catalog
Replay Sequence
Mermaid
Rendering diagram…
The catalog below is derived from the Orchestrator's apps/api/src/modules/events/event-catalog.ts (event names) and apps/api/src/modules/events/types/*-events.ts (payload contracts). There are currently no wallet.* events in the catalog — wallet activity that changes available funds is represented by the balance events below. Optional fields are suffixed with ?.