Skip to content

WebhookRouter

Defined in: core/src/index.ts:90

WebhookRouter - A type-safe event router for webhook events

TEventMap extends Record<string, WebhookEvent> = DefaultEventMap

A mapping of event type strings to their event types

new WebhookRouter<TEventMap>(): WebhookRouter<TEventMap>

WebhookRouter<TEventMap>

dispatch(event): Promise<void>

Defined in: core/src/index.ts:246

Dispatch an event to registered handlers

The event to dispatch

WebhookEvent | TEventMap[keyof TEventMap]

Promise<void>


fanout<T>(event, handlers, options?): this

Defined in: core/src/index.ts:207

Register multiple handlers to be executed in parallel (fanout pattern)

T extends string

T

The event type to handle

EventHandler<TEventMap[T]>[]

Array of handler functions to execute in parallel

FanoutOptions = {}

Fanout options

this

this for chaining


group(prefix, callback): this

Defined in: core/src/index.ts:185

Create a group of handlers with a common prefix

string

The event type prefix (e.g., ‘payment_intent’)

(router) => void

Function that receives a prefixed router

this

this for chaining


on<T>(event, handler): this

Defined in: core/src/index.ts:103

Register a handler for a specific event type

T extends string

T

The event type to handle

EventHandler<TEventMap[T]>

The handler function

this

this for chaining

on<T>(events, handler): this

Defined in: core/src/index.ts:115

Register a handler for multiple event types

T extends string

T[]

Array of event types to handle

EventHandler<TEventMap[T]>

The handler function

this

this for chaining


route(prefix, router): this

Defined in: core/src/index.ts:162

Mount a nested router with a prefix

string

The event type prefix (e.g., ‘customer.subscription’)

WebhookRouter

The nested WebhookRouter instance

this

this for chaining


use(middleware): this

Defined in: core/src/index.ts:150

Register a middleware function

Middleware<TEventMap[keyof TEventMap]>

The middleware function

this

this for chaining