nextEventBridge

cart · /next·function

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

@nordcom/commerce-cart

Parameters

NameTypeDescription
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);

AuthBridge CartIdStorage CreateTypedCartActionsOpts FormCartActions HttpOnlyCookieStorageOpts NextEventBridge TypedCartActions NextEventBridgeHandlers

On this page