Interface: CartRecoveryOperation<T>
Description of an operation the runner will execute, with optional recovery strategy.
run is the happy-path call against an existing cartId. The runner invokes
it first; on success, returns its value.
recreateAndRun is the auto-replay strategy: when defined, on recoverable
error the runner clears the cookie, calls recreateAndRun(cartClient) which
atomically creates a fresh cart with the same payload (e.g. cartCreate({ lines })
for addItems), persists the new id, and returns the operation result in one
round trip. When absent, the runner bails with CartRecoveryNotPossibleError
and emits a cart-expired event — appropriate for operations that reference
state from the dead cart (updateItems(lineId), selectShippingMethod, etc.).
Type Parameters
T
T
Properties
name?
optionalname?:string
Optional diagnostic label surfaced in CartExpiredEvent.operation.
recreateAndRun?
optionalrecreateAndRun?: (cartClient) =>Promise<{cart:CartFragment;result:T;secret?:string|null; }>
Optional atomic "create new cart and run with payload in one go" strategy.
Define for replay-safe operations; omit for state-dependent ones. Return
the fresh cart's one-time secret so the runner persists the composite
cookie (the recovered cart is reachable on the next mutation).
Parameters
cartClient
Returns
Promise<{ cart: CartFragment; result: T; secret?: string | null; }>
run
run: (
cartId) =>Promise<T>
Happy-path call with current cart id.
Parameters
cartId
string
Returns
Promise<T>