createCart

cart · /core·function

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

@nordcom/commerce-cart
function createCart(opts: CreateCartOpts<TExt, TShop>): CartKernel<TExt, TShop>;

Parameters

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

RunCartAdapterContractOpts runCartAdapterContract CartCapabilityUnsupportedError CartError CartNotFoundError CartProviderError CartUserError CartAdapter

Sourcekernel.ts:79Edit the JSDoc directly

On this page