nextEventBridge
Builds a Next.js-aware event bridge that pipes cart kernel events into
after() callbacks. Use this when a host needs to emit analytics, kick
off downstream webhooks, or trigger cache invalidations on cart changes
without blocking the user-facing response.
Handlers are keyed by type and may be async — failures
inside after() surface through Next's standard observability surface,
not the cart-core event-bus error sink (which only catches synchronous
throws from the kernel's queueMicrotask dispatcher).
Signature
function nextEventBridge(opts: { handlers: NextEventBridgeHandlers }): NextEventBridge;Parameters
| Name | Type | Description |
|---|---|---|
opts | { handlers: NextEventBridgeHandlers } |
Returns
A ready to bind to a kernel.
Example
const bridge = nextEventBridge({
handlers: {
'cart.line.added': async (event) => {
await analytics.track('AddToCart', { lineId: event.line.id });
},
'cart.updated': (event) => {
cache.invalidate(`cart:${event.cart.id}`);
},
},
});
bridge.onKernel(kernel);Related
AuthBridge CartIdStorage CreateTypedCartActionsOpts FormCartActions HttpOnlyCookieStorageOpts NextEventBridge TypedCartActions NextEventBridgeHandlers
NextEventBridgeHandlers
Perevent handler map passed to . Each key is a discriminant; TypeScript infers the narrowed event payload for that variant so handlers receive the concrete fiel
TypedCartActions
Stronglytyped serveraction surface built by . Each method accepts a serializable plainobject args bag (no FormData) so client components can invoke actions thro