Class: CartService
Defined in: server/checkout/cart-service.ts:99
The cart aggregate (proposal §Cart — state machine, seam & pricing
injection). Carts are mutable, disposable, INPUT-only: items store consumer
inputs, never prices — pricing is computed on read through the injected
priceCart adapter. finalize is the one-way seam to an order.
Extends
BaseCheckoutService
Constructors
Constructor
new CartService(deps: CheckoutFeatureDeps): CartService;Defined in: server/checkout/base-checkout-service.ts:43
Parameters
| Parameter | Type |
|---|---|
deps | CheckoutFeatureDeps |
Returns
CartService
Inherited from
BaseCheckoutService.constructorProperties
deps
protected readonly deps: CheckoutFeatureDeps;Defined in: server/checkout/base-checkout-service.ts:43
Inherited from
BaseCheckoutService.depsAccessors
actorId
Get Signature
get protected actorId(): string | null;Defined in: server/checkout/base-checkout-service.ts:45
Returns
string | null
Inherited from
BaseCheckoutService.actorIdMethods
addItem()
addItem(
scope: CartAccessScope,
cartId: string,
input: AddItemInput
): Promise<{
cartId: string;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
id: string;
metadata: JsonValue;
organizationId: string;
quantity: number;
referenceId: string | null;
referenceType: string;
updatedAt: Date;
updatedBy: string | null;
}>;Defined in: server/checkout/cart-service.ts:133
Add an input line to an open cart. Items carry INPUTS only
(referenceType/referenceId/quantity/metadata) — no price field: prices
are computed on read. Requires trusted cart scope, refreshes activity, and
advances the cart version.
Parameters
| Parameter | Type |
|---|---|
scope | CartAccessScope |
cartId | string |
input | AddItemInput |
Returns
Promise<{
cartId: string;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
id: string;
metadata: JsonValue;
organizationId: string;
quantity: number;
referenceId: string | null;
referenceType: string;
updatedAt: Date;
updatedBy: string | null;
}>
createCart()
createCart(scope: CartAccessScope, input?: CreateCartInput): Promise<{
createdAt: Date;
createdBy: string | null;
currencyCode: string;
customerId: string | null;
deletedAt: Date | null;
deletedBy: string | null;
expiresAt: Date | null;
externalRef: string | null;
guestEmail: string | null;
id: string;
lastActivityAt: Date;
metadata: JsonValue;
organizationId: string;
status: CartStatus;
updatedAt: Date;
updatedBy: string | null;
version: number;
}>;Defined in: server/checkout/cart-service.ts:101
Create an open cart from trusted identity scope.
Parameters
| Parameter | Type |
|---|---|
scope | CartAccessScope |
input | CreateCartInput |
Returns
Promise<{
createdAt: Date;
createdBy: string | null;
currencyCode: string;
customerId: string | null;
deletedAt: Date | null;
deletedBy: string | null;
expiresAt: Date | null;
externalRef: string | null;
guestEmail: string | null;
id: string;
lastActivityAt: Date;
metadata: JsonValue;
organizationId: string;
status: CartStatus;
updatedAt: Date;
updatedBy: string | null;
version: number;
}>
expireCarts()
expireCarts(organizationId: string, cartIds: string[]): Promise<number>;Defined in: server/checkout/cart-service.ts:302
Mark the given carts expired (the expires_at inventory-hold lapse).
Skips any cart already in a terminal state — only open carts transition.
Returns the number transitioned.
Parameters
| Parameter | Type |
|---|---|
organizationId | string |
cartIds | string[] |
Returns
Promise<number>
expireStaleCarts()
expireStaleCarts(organizationId: string, before: Date): Promise<number>;Defined in: server/checkout/cart-service.ts:312
Sweep: mark one organization's open carts idle past before as
abandoned (proposal §Cart state machine: "cleanup job: idle > threshold
→ abandoned"). The consumer runs this on a cron — taproot runs no
background jobs.
Parameters
| Parameter | Type |
|---|---|
organizationId | string |
before | Date |
Returns
Promise<number>
finalize()
finalize(
scope: CartAccessScope,
cartId: string,
opts: FinalizeOptions
): Promise<BigIntsAsNumbers<{
anomalyAt: Date | null;
applicationFeeTotalCents: bigint | null;
authorizedTotalCents: bigint;
authorizeStatus: OrderAuthorizeStatus;
capturedTotalCents: bigint;
cartId: string | null;
chargeStatus: OrderChargeStatus;
closedAt: Date | null;
code: string;
createdAt: Date;
createdBy: string | null;
currencyCode: string;
customerEmail: string | null;
customerId: string | null;
customerTotalCents: bigint;
disputedTotalCents: bigint;
externalRef: string | null;
id: string;
idempotencyKey: string | null;
metadata: JsonValue;
notes: string | null;
operatorId: string | null;
organizationId: string;
orgBorneTotalCents: bigint;
origin: string;
placedAt: Date | null;
platformBorneTotalCents: bigint;
processingFeeTotalCents: bigint | null;
refundedTotalCents: bigint;
requestHash: string | null;
status: OrderStatus;
statusUpdatedAt: Date;
statusUpdatedBy: string | null;
subtotalCents: bigint;
updatedAt: Date;
updatedBy: string | null;
}>>;Defined in: server/checkout/cart-service.ts:225
The one-way seam (proposal §finalize): open cart → row lock → version
bump → re-price → expected-total guard → createOrder → cart converted
→ append order.placed. Returns the created (or, on re-entry, existing)
order.
RE-ENTRY (proposal §finalize step 1): a converted cart + a matching
(organizationId, idempotencyKey) order returns that prior order
unconditionally — no request-hash check, because the priced payload
doesn't exist until step 2 re-prices, so the converted-cart + key hit IS
the idempotent handle. Any other non-open status, or converted with a
different / absent key → CartNotOpenError(status).
Parameters
| Parameter | Type |
|---|---|
scope | CartAccessScope |
cartId | string |
opts | FinalizeOptions |
Returns
Promise<BigIntsAsNumbers<{
anomalyAt: Date | null;
applicationFeeTotalCents: bigint | null;
authorizedTotalCents: bigint;
authorizeStatus: OrderAuthorizeStatus;
capturedTotalCents: bigint;
cartId: string | null;
chargeStatus: OrderChargeStatus;
closedAt: Date | null;
code: string;
createdAt: Date;
createdBy: string | null;
currencyCode: string;
customerEmail: string | null;
customerId: string | null;
customerTotalCents: bigint;
disputedTotalCents: bigint;
externalRef: string | null;
id: string;
idempotencyKey: string | null;
metadata: JsonValue;
notes: string | null;
operatorId: string | null;
organizationId: string;
orgBorneTotalCents: bigint;
origin: string;
placedAt: Date | null;
platformBorneTotalCents: bigint;
processingFeeTotalCents: bigint | null;
refundedTotalCents: bigint;
requestHash: string | null;
status: OrderStatus;
statusUpdatedAt: Date;
statusUpdatedBy: string | null;
subtotalCents: bigint;
updatedAt: Date;
updatedBy: string | null;
}>>
findStaleCarts()
findStaleCarts(organizationId: string, before: Date): Promise<{
createdAt: Date;
createdBy: string | null;
currencyCode: string;
customerId: string | null;
deletedAt: Date | null;
deletedBy: string | null;
expiresAt: Date | null;
externalRef: string | null;
guestEmail: string | null;
id: string;
lastActivityAt: Date;
metadata: JsonValue;
organizationId: string;
status: CartStatus;
updatedAt: Date;
updatedBy: string | null;
version: number;
}[]>;Defined in: server/checkout/cart-service.ts:293
One organization's open carts idle before the cutoff.
Parameters
| Parameter | Type |
|---|---|
organizationId | string |
before | Date |
Returns
Promise<{
createdAt: Date;
createdBy: string | null;
currencyCode: string;
customerId: string | null;
deletedAt: Date | null;
deletedBy: string | null;
expiresAt: Date | null;
externalRef: string | null;
guestEmail: string | null;
id: string;
lastActivityAt: Date;
metadata: JsonValue;
organizationId: string;
status: CartStatus;
updatedAt: Date;
updatedBy: string | null;
version: number;
}[]>
getCart()
getCart(scope: CartAccessScope, cartId: string): Promise<{
createdAt: Date;
createdBy: string | null;
currencyCode: string;
customerId: string | null;
deletedAt: Date | null;
deletedBy: string | null;
expiresAt: Date | null;
externalRef: string | null;
guestEmail: string | null;
id: string;
lastActivityAt: Date;
metadata: JsonValue;
organizationId: string;
status: CartStatus;
updatedAt: Date;
updatedBy: string | null;
version: number;
}>;Defined in: server/checkout/cart-service.ts:121
Fetch a scoped cart; missing, foreign, or deleted → not found.
Parameters
| Parameter | Type |
|---|---|
scope | CartAccessScope |
cartId | string |
Returns
Promise<{
createdAt: Date;
createdBy: string | null;
currencyCode: string;
customerId: string | null;
deletedAt: Date | null;
deletedBy: string | null;
expiresAt: Date | null;
externalRef: string | null;
guestEmail: string | null;
id: string;
lastActivityAt: Date;
metadata: JsonValue;
organizationId: string;
status: CartStatus;
updatedAt: Date;
updatedBy: string | null;
version: number;
}>
getPricedCart()
getPricedCart(scope: CartAccessScope, cartId: string): Promise<PricedCartSnapshot>;Defined in: server/checkout/cart-service.ts:191
Re-price the cart through the injected priceCart adapter (proposal
§Pricing injection). The adapter owns the consumer catalog + classify
policy — taproot only hands it the cart and its live items.
Parameters
| Parameter | Type |
|---|---|
scope | CartAccessScope |
cartId | string |
Returns
Promise<PricedCartSnapshot>
recomputeTenderFromLedger()
protected recomputeTenderFromLedger(
repos: CheckoutRepositories,
payment: PaymentRow,
overrides?: Partial<Pick<TenderFacts, "clientActionRequired" | "clientActionRequiredAt">>
): Promise<{
fold: TenderComputation;
patch: TenderBucketPatch;
}>;Defined in: server/checkout/base-checkout-service.ts:94
Re-project a tender from its persisted ledger without writing it.
Explicit clientActionRequiredAt: null clears the stored timestamp.
Parameters
| Parameter | Type |
|---|---|
repos | CheckoutRepositories |
payment | PaymentRow |
overrides? | Partial<Pick<TenderFacts, "clientActionRequired" | "clientActionRequiredAt">> |
Returns
Promise<{
fold: TenderComputation;
patch: TenderBucketPatch;
}>
Inherited from
BaseCheckoutService.recomputeTenderFromLedgerreconcileClosedAt()
protected reconcileClosedAt(
repos: CheckoutRepositories,
order: OrderRow,
now: Date
): Promise<void>;Defined in: server/checkout/base-checkout-service.ts:121
Reconcile closedAt and the once-per-order order.paid event after a
money write. The caller must hold the order lock in an ambient transaction.
Parameters
| Parameter | Type |
|---|---|
repos | CheckoutRepositories |
order | OrderRow |
now | Date |
Returns
Promise<void>
Inherited from
BaseCheckoutService.reconcileClosedAtrecordCanonicalTransactions()
protected recordCanonicalTransactions(
repos: CheckoutRepositories,
context: RecordTxnContext,
transactions: CanonicalTxn[]
): Promise<RecordedCanonicalTxn[]>;Defined in: server/checkout/base-checkout-service.ts:61
Record canonical transactions sequentially and identify both fresh inserts and pending rows resolved in place. Callers own the resulting side effects.
Parameters
| Parameter | Type |
|---|---|
repos | CheckoutRepositories |
context | RecordTxnContext |
transactions | CanonicalTxn[] |
Returns
Promise<RecordedCanonicalTxn[]>
Inherited from
BaseCheckoutService.recordCanonicalTransactionsremoveItem()
removeItem(
scope: CartAccessScope,
cartId: string,
itemId: string
): Promise<void>;Defined in: server/checkout/cart-service.ts:174
Soft-delete an open cart's item; refresh activity and advance version.
Parameters
| Parameter | Type |
|---|---|
scope | CartAccessScope |
cartId | string |
itemId | string |
Returns
Promise<void>
transaction()
protected transaction<T>(fn: (deps: CheckoutFeatureDeps) => Promise<T>): Promise<T>;Defined in: server/checkout/base-checkout-service.ts:49
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fn | (deps: CheckoutFeatureDeps) => Promise<T> |
Returns
Promise<T>
Inherited from
BaseCheckoutService.transactionupdateItem()
updateItem(
scope: CartAccessScope,
cartId: string,
itemId: string,
input: UpdateItemInput
): Promise<{
cartId: string;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
id: string;
metadata: JsonValue;
organizationId: string;
quantity: number;
referenceId: string | null;
referenceType: string;
updatedAt: Date;
updatedBy: string | null;
}>;Defined in: server/checkout/cart-service.ts:155
Update an open cart's item; refresh activity and advance version.
Parameters
| Parameter | Type |
|---|---|
scope | CartAccessScope |
cartId | string |
itemId | string |
input | UpdateItemInput |
Returns
Promise<{
cartId: string;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
id: string;
metadata: JsonValue;
organizationId: string;
quantity: number;
referenceId: string | null;
referenceType: string;
updatedAt: Date;
updatedBy: string | null;
}>