Function: createEventRouter()
createEventRouter(
options):object
Creates a transport-agnostic event router that parses { type, data } against the canonical schema registry and dispatches to typed handlers.
Works for both SSE events and webhook payloads. Use for consistent parse-and-dispatch logic across consumers.
Parameters
options
Returns
object
handle()
handle(
input):void
Parameters
input
Returns
void
Example
const router = createEventRouter({
handlers: {
'asset.updated': (data) => { /* data is typed */ },
'notification.new': () => { /* ... */ },
},
onUnknown: (type) => console.warn('Unknown event:', type),
onParseError: (type, err) => console.error('Parse failed:', type, err),
});
router.handle({ type: 'asset.updated', data: rawData });