createCart
Builds a cart kernel bound to one adapter. The kernel is the host-facing surface: it routes typed s to adapter methods, gates mutations against , runs the middleware chain around every dispatch, and broadcasts s on success + failure.
The chain is composed once at construction; recreate the kernel when
middleware changes.
Signature
function createCart(opts: CreateCartOpts<TExt, TShop>): CartKernel<TExt, TShop>;Parameters
| Name | Type | Description |
|---|---|---|
opts | CreateCartOpts<TExt, TShop> |
Returns
A ready to read / create / mutate.
Example
const kernel = createCart({
adapter: createMockCartAdapter(),
middleware: [logger(), retry({ attempts: 3, backoffMs: 100 })],
});
const cart = await kernel.create(ctx);
await kernel.mutate(ctx, { kind: 'add-line', variantId: 'v_1', quantity: 2 });Related
RunCartAdapterContractOpts runCartAdapterContract CartCapabilityUnsupportedError CartError CartNotFoundError CartProviderError CartUserError CartAdapter
CreateCartOpts
Configuration bag passed to . Declares the adapter, optional middleware pipeline, and an optional logger override for the internal event bus.
createEventBus
Inprocess event bus used by the cart kernel to broadcast lifecycle events to UI layers (React store, analytics, tab sync). Delivery is fireandforget via queueMi