createTypedCartActions

cart · /next·function

Builds the typed, JSON-arg server-action surface for cart-next hosts. Each returned method threads the supplied idempotencyKey into via resolveContext({ idempotencyKey }) and routes the call through the kernel — so middleware (logger, tracing, idempotency, retry, analytics) runs on every action just as it would for a direct kernel.mutate call.

Error mapping is centralised here: anything thrown becomes a typed CartActionResult with a localized message, instead of bubbling raw provider exceptions across the server-action boundary.

Signature

@nordcom/commerce-cart

Parameters

NameTypeDescription
optsCreateTypedCartActionsOpts<TExt, TShop>

Returns

A surface ready to bind as "use server" re-exports.

Example

const actions = createTypedCartActions({
    kernel,
    storage: httpOnlyCookieStorage(),
    resolveContext: async ({ idempotencyKey } = {}) => ({ shop, locale, idempotencyKey }),
});
const result = await actions.addLine({
    variantId: 'gid://shopify/ProductVariant/123',
    quantity: 1,
    idempotencyKey: crypto.randomUUID(),
});

AuthBridge CartIdStorage CreateTypedCartActionsOpts FormCartActions HttpOnlyCookieStorageOpts NextEventBridge TypedCartActions NextEventBridgeHandlers

On this page