WebhookRouter
Defined in: core/src/index.ts:90
WebhookRouter - A type-safe event router for webhook events
Extended by
Section titled “Extended by”Type Parameters
Section titled “Type Parameters”TEventMap
Section titled “TEventMap”TEventMap extends Record<string, WebhookEvent> = DefaultEventMap
A mapping of event type strings to their event types
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new WebhookRouter<
TEventMap>():WebhookRouter<TEventMap>
Returns
Section titled “Returns”WebhookRouter<TEventMap>
Methods
Section titled “Methods”dispatch()
Section titled “dispatch()”dispatch(
event):Promise<void>
Defined in: core/src/index.ts:246
Dispatch an event to registered handlers
Parameters
Section titled “Parameters”The event to dispatch
WebhookEvent | TEventMap[keyof TEventMap]
Returns
Section titled “Returns”Promise<void>
fanout()
Section titled “fanout()”fanout<
T>(event,handlers,options?):this
Defined in: core/src/index.ts:207
Register multiple handlers to be executed in parallel (fanout pattern)
Type Parameters
Section titled “Type Parameters”T extends string
Parameters
Section titled “Parameters”T
The event type to handle
handlers
Section titled “handlers”EventHandler<TEventMap[T]>[]
Array of handler functions to execute in parallel
options?
Section titled “options?”FanoutOptions = {}
Fanout options
Returns
Section titled “Returns”this
this for chaining
group()
Section titled “group()”group(
prefix,callback):this
Defined in: core/src/index.ts:185
Create a group of handlers with a common prefix
Parameters
Section titled “Parameters”prefix
Section titled “prefix”string
The event type prefix (e.g., ‘payment_intent’)
callback
Section titled “callback”(router) => void
Function that receives a prefixed router
Returns
Section titled “Returns”this
this for chaining
Call Signature
Section titled “Call Signature”on<
T>(event,handler):this
Defined in: core/src/index.ts:103
Register a handler for a specific event type
Type Parameters
Section titled “Type Parameters”T extends string
Parameters
Section titled “Parameters”T
The event type to handle
handler
Section titled “handler”EventHandler<TEventMap[T]>
The handler function
Returns
Section titled “Returns”this
this for chaining
Call Signature
Section titled “Call Signature”on<
T>(events,handler):this
Defined in: core/src/index.ts:115
Register a handler for multiple event types
Type Parameters
Section titled “Type Parameters”T extends string
Parameters
Section titled “Parameters”events
Section titled “events”T[]
Array of event types to handle
handler
Section titled “handler”EventHandler<TEventMap[T]>
The handler function
Returns
Section titled “Returns”this
this for chaining
route()
Section titled “route()”route(
prefix,router):this
Defined in: core/src/index.ts:162
Mount a nested router with a prefix
Parameters
Section titled “Parameters”prefix
Section titled “prefix”string
The event type prefix (e.g., ‘customer.subscription’)
router
Section titled “router”WebhookRouter
The nested WebhookRouter instance
Returns
Section titled “Returns”this
this for chaining
use(
middleware):this
Defined in: core/src/index.ts:150
Register a middleware function
Parameters
Section titled “Parameters”middleware
Section titled “middleware”Middleware<TEventMap[keyof TEventMap]>
The middleware function
Returns
Section titled “Returns”this
this for chaining