@classytic/cart 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -0
- package/LICENSE +21 -0
- package/README.md +109 -0
- package/dist/bundle.kind-BdgnyKZt.d.mts +114 -0
- package/dist/bundle.kind-DFydSxV_.mjs +362 -0
- package/dist/cart-event-catalog-BIbi2Q_n.d.mts +109 -0
- package/dist/cart-event-catalog-BOP9aDhL.mjs +301 -0
- package/dist/cart-status.vo-2iisZGhb.d.mts +46 -0
- package/dist/create-cart-q3CXxPP7.mjs +1751 -0
- package/dist/domain/errors/index.d.mts +2 -0
- package/dist/domain/errors/index.mjs +4 -0
- package/dist/domain/events/index.d.mts +3 -0
- package/dist/domain/events/index.mjs +3 -0
- package/dist/domain/index.d.mts +12 -0
- package/dist/domain/index.mjs +15 -0
- package/dist/domain/ports/index.d.mts +3 -0
- package/dist/domain/ports/index.mjs +2 -0
- package/dist/domain/saga/index.d.mts +2 -0
- package/dist/domain/saga/index.mjs +3 -0
- package/dist/domain-event-DHNkz15G.mjs +57 -0
- package/dist/engine/cart-config.schema.d.mts +41 -0
- package/dist/engine/cart-config.schema.mjs +40 -0
- package/dist/engine/index.d.mts +3 -0
- package/dist/engine/index.mjs +3 -0
- package/dist/errors-CHR9RlbY.mjs +97 -0
- package/dist/id.port-C3rlDAKP.mjs +29 -0
- package/dist/id.port-DPXLrqb2.d.mts +64 -0
- package/dist/idempotency-key.vo-D0lJsvGn.mjs +9 -0
- package/dist/idempotency-record.entity-DIFXjN1V.d.mts +221 -0
- package/dist/index-DEHBdV_z.d.mts +1 -0
- package/dist/index-Doi5uzux.d.mts +231 -0
- package/dist/index.d.mts +103 -0
- package/dist/index.mjs +92 -0
- package/dist/internal-event-bus-IkUfQJxn.d.mts +661 -0
- package/dist/kind-registry-Ba4PO4WC.mjs +35 -0
- package/dist/kind.error-CCjTB6kW.mjs +69 -0
- package/dist/kinds/index.d.mts +2 -0
- package/dist/kinds/index.mjs +2 -0
- package/dist/line-item.entity-B3M_i-pw.d.mts +157 -0
- package/dist/line-kind-Bndo6IS8.d.mts +231 -0
- package/dist/not-found.error-B6WYnAjX.mjs +95 -0
- package/dist/outbox-store-CTWz9pvG.d.mts +155 -0
- package/dist/saga-step-fn-Cyob38iU.d.mts +135 -0
- package/dist/saga-steps-B27LI7xp.mjs +27 -0
- package/dist/shipping.bridge-DD4A_O0O.d.mts +538 -0
- package/dist/state-transitions-CpJpZZTK.mjs +21 -0
- package/package.json +114 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as IdempotencyBusyError, c as SagaFailurePhase, d as ReservationError, f as ConcurrencyError, i as UnknownKindError, l as PriceChangedError, m as CartErrorCategory, n as StateTransitionError, o as IdempotencyStorageError, p as CartError, r as KindError, s as SagaError, t as NotFoundError, u as StaleQuoteError } from "../../index-Doi5uzux.mjs";
|
|
2
|
+
export { CartError, CartErrorCategory, ConcurrencyError, IdempotencyBusyError, IdempotencyStorageError, KindError, NotFoundError, PriceChangedError, ReservationError, SagaError, SagaFailurePhase, StaleQuoteError, StateTransitionError, UnknownKindError };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { n as UnknownKindError, r as CartError, t as KindError } from "../../kind.error-CCjTB6kW.mjs";
|
|
2
|
+
import { i as ConcurrencyError, n as StateTransitionError, r as PriceChangedError, t as NotFoundError } from "../../not-found.error-B6WYnAjX.mjs";
|
|
3
|
+
import { a as ReservationError, i as StaleQuoteError, n as IdempotencyStorageError, r as SagaError, t as IdempotencyBusyError } from "../../errors-CHR9RlbY.mjs";
|
|
4
|
+
export { CartError, ConcurrencyError, IdempotencyBusyError, IdempotencyStorageError, KindError, NotFoundError, PriceChangedError, ReservationError, SagaError, StaleQuoteError, StateTransitionError, UnknownKindError };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { S as CartEvents, _ as CartEventMeta, a as OutboxErrorInfo, b as CartEventName, c as OutboxFailureDecision, d as OutboxStore, f as OutboxStoreWriteOptions, g as CartEventAggregate, h as CartDomainEvent, i as OutboxClaimOptions, l as OutboxFailurePolicy, m as CartAggregateType, n as MemoryOutboxStore, o as OutboxFailOptions, p as OutboxWriteOptions, r as OutboxAcknowledgeOptions, s as OutboxFailureContext, t as InvalidOutboxEventError, u as OutboxOwnershipError, v as createCartEvent, x as CartEventPayload, y as CartEventMap } from "../../outbox-store-CTWz9pvG.mjs";
|
|
2
|
+
import { a as CartEventRegistry, c as defineCartEvent, d as EventValidationResult, f as EventValidator, i as CartEventDefinitionInput, l as EventSchema, n as cartEventsByName, o as PayloadOf, r as CartEventDefinition, s as createCartEventRegistry, t as cartEventDefinitions, u as EventSchemaProperty } from "../../cart-event-catalog-BIbi2Q_n.mjs";
|
|
3
|
+
export { type CartAggregateType, type CartDomainEvent, type CartEventAggregate, type CartEventDefinition, type CartEventDefinitionInput, type CartEventMap, type CartEventMeta, type CartEventName, type CartEventPayload, type CartEventRegistry, CartEvents, type EventSchema, type EventSchemaProperty, type EventValidationResult, type EventValidator, InvalidOutboxEventError, MemoryOutboxStore, type OutboxAcknowledgeOptions, type OutboxClaimOptions, type OutboxErrorInfo, type OutboxFailOptions, type OutboxFailureContext, type OutboxFailureDecision, type OutboxFailurePolicy, OutboxOwnershipError, type OutboxStore, type OutboxStoreWriteOptions, type OutboxWriteOptions, type PayloadOf, cartEventDefinitions, cartEventsByName, createCartEvent, createCartEventRegistry, defineCartEvent };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { n as CartEvents, t as createCartEvent } from "../../domain-event-DHNkz15G.mjs";
|
|
2
|
+
import { a as OutboxOwnershipError, i as MemoryOutboxStore, n as cartEventsByName, o as createCartEventRegistry, r as InvalidOutboxEventError, s as defineCartEvent, t as cartEventDefinitions } from "../../cart-event-catalog-BOP9aDhL.mjs";
|
|
3
|
+
export { CartEvents, InvalidOutboxEventError, MemoryOutboxStore, OutboxOwnershipError, cartEventDefinitions, cartEventsByName, createCartEvent, createCartEventRegistry, defineCartEvent };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { a as IdempotencyBusyError, c as SagaFailurePhase, d as ReservationError, f as ConcurrencyError, i as UnknownKindError, l as PriceChangedError, m as CartErrorCategory, n as StateTransitionError, o as IdempotencyStorageError, p as CartError, r as KindError, s as SagaError, t as NotFoundError, u as StaleQuoteError } from "../index-Doi5uzux.mjs";
|
|
2
|
+
import { n as DraftStatus, r as ReservationStatus, t as CheckoutState } from "../cart-status.vo-2iisZGhb.mjs";
|
|
3
|
+
import { S as CartEvents, _ as CartEventMeta, a as OutboxErrorInfo, b as CartEventName, c as OutboxFailureDecision, d as OutboxStore, f as OutboxStoreWriteOptions, g as CartEventAggregate, h as CartDomainEvent, i as OutboxClaimOptions, l as OutboxFailurePolicy, m as CartAggregateType, n as MemoryOutboxStore, o as OutboxFailOptions, p as OutboxWriteOptions, r as OutboxAcknowledgeOptions, s as OutboxFailureContext, t as InvalidOutboxEventError, u as OutboxOwnershipError, v as createCartEvent, x as CartEventPayload, y as CartEventMap } from "../outbox-store-CTWz9pvG.mjs";
|
|
4
|
+
import { a as CartEventRegistry, c as defineCartEvent, d as EventValidationResult, f as EventValidator, i as CartEventDefinitionInput, l as EventSchema, n as cartEventsByName, o as PayloadOf, r as CartEventDefinition, s as createCartEventRegistry, t as cartEventDefinitions, u as EventSchemaProperty } from "../cart-event-catalog-BIbi2Q_n.mjs";
|
|
5
|
+
import { a as IdempotencyIdentity, c as TotalsSnapshot, i as CART_REF_NEW, n as KindRegistry, o as IdempotencyReplay, r as createKindRegistry, s as OperationName, t as LineItem } from "../line-item.entity-B3M_i-pw.mjs";
|
|
6
|
+
import { C as PricingSnapshot, S as PricedLine, _ as ProductSummary, a as TaxBreakdown, b as BridgeStatus, c as TaxCalculationResult, d as PromotionResult, f as PromotionsBridge, g as CatalogBridge, h as ReservationRequest, i as ShippingQuoteRequest, l as AdjustmentSpec, m as ReservationRef, n as ShippingMethod, o as TaxBridge, p as InventoryBridge, r as ShippingQuote, s as TaxCalculationRequest, t as ShippingBridge, u as CartSnapshot, x as OperationContext, y as BridgeRef } from "../shipping.bridge-DD4A_O0O.mjs";
|
|
7
|
+
import { a as RevalidationResult, c as ValidityPolicy, i as LineLike, l as LineDisplay, n as KindContext, o as StaleBehavior, r as LineKind, s as StaleTrigger, t as KindBridges } from "../line-kind-Bndo6IS8.mjs";
|
|
8
|
+
import { a as systemClock, i as ClockPort, n as createCounterIdPort, r as cryptoIdPort, t as IdPort } from "../id.port-DPXLrqb2.mjs";
|
|
9
|
+
import { a as CheckoutFlowState, c as CheckoutStepNumber, i as isLegalCheckoutTransition, l as SagaStep, n as SagaStepFn, o as SagaState, r as CHECKOUT_STATE_TRANSITIONS, s as CheckoutStep, t as SagaDependencies, u as SagaStepNumber } from "../saga-step-fn-Cyob38iU.mjs";
|
|
10
|
+
import { a as Adjustment, i as Draft, n as Reservation, r as Checkout, t as IdempotencyRecord } from "../idempotency-record.entity-DIFXjN1V.mjs";
|
|
11
|
+
import { Money, addMoney, fromMajor, money, multiplyMoney, subtractMoney, sumMoney, toMajor } from "@classytic/primitives/money";
|
|
12
|
+
export { type Adjustment, AdjustmentSpec, BridgeRef, BridgeStatus, CART_REF_NEW, CHECKOUT_STATE_TRANSITIONS, CartAggregateType, CartDomainEvent, CartError, CartErrorCategory, CartEventAggregate, CartEventDefinition, CartEventDefinitionInput, CartEventMap, CartEventMeta, CartEventName, CartEventPayload, CartEventRegistry, CartEvents, CartSnapshot, CatalogBridge, type Checkout, CheckoutFlowState, type CheckoutState, CheckoutStep, CheckoutStepNumber, ClockPort, ConcurrencyError, type Draft, type DraftStatus, EventSchema, EventSchemaProperty, EventValidationResult, EventValidator, IdPort, IdempotencyBusyError, type IdempotencyIdentity, type IdempotencyRecord, type IdempotencyReplay, IdempotencyStorageError, InvalidOutboxEventError, InventoryBridge, type KindBridges, type KindContext, KindError, type KindRegistry, type LineDisplay, type LineItem, type LineKind, type LineLike, MemoryOutboxStore, type Money, NotFoundError, OperationContext, type OperationName, OutboxAcknowledgeOptions, OutboxClaimOptions, OutboxErrorInfo, OutboxFailOptions, OutboxFailureContext, OutboxFailureDecision, OutboxFailurePolicy, OutboxOwnershipError, OutboxStore, OutboxStoreWriteOptions, OutboxWriteOptions, PayloadOf, PriceChangedError, type PricedLine, type PricingSnapshot, ProductSummary, PromotionResult, PromotionsBridge, type Reservation, ReservationError, ReservationRef, ReservationRequest, type ReservationStatus, type RevalidationResult, SagaDependencies, SagaError, SagaFailurePhase, SagaState, SagaStep, SagaStepFn, SagaStepNumber, ShippingBridge, ShippingMethod, ShippingQuote, ShippingQuoteRequest, type StaleBehavior, StaleQuoteError, type StaleTrigger, StateTransitionError, TaxBreakdown, TaxBridge, TaxCalculationRequest, TaxCalculationResult, type TotalsSnapshot, UnknownKindError, type ValidityPolicy, addMoney, cartEventDefinitions, cartEventsByName, createCartEvent, createCartEventRegistry, createCounterIdPort, createKindRegistry, cryptoIdPort, defineCartEvent, fromMajor, isLegalCheckoutTransition, money, multiplyMoney, subtractMoney, sumMoney, systemClock, toMajor };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { t as CART_REF_NEW } from "../idempotency-key.vo-D0lJsvGn.mjs";
|
|
2
|
+
import { n as UnknownKindError, r as CartError, t as KindError } from "../kind.error-CCjTB6kW.mjs";
|
|
3
|
+
import { i as ConcurrencyError, n as StateTransitionError, r as PriceChangedError, t as NotFoundError } from "../not-found.error-B6WYnAjX.mjs";
|
|
4
|
+
import { a as ReservationError, i as StaleQuoteError, n as IdempotencyStorageError, r as SagaError, t as IdempotencyBusyError } from "../errors-CHR9RlbY.mjs";
|
|
5
|
+
import { n as CartEvents, t as createCartEvent } from "../domain-event-DHNkz15G.mjs";
|
|
6
|
+
import { a as OutboxOwnershipError, i as MemoryOutboxStore, n as cartEventsByName, o as createCartEventRegistry, r as InvalidOutboxEventError, s as defineCartEvent, t as cartEventDefinitions } from "../cart-event-catalog-BOP9aDhL.mjs";
|
|
7
|
+
import { n as cryptoIdPort, r as systemClock, t as createCounterIdPort } from "../id.port-C3rlDAKP.mjs";
|
|
8
|
+
import { t as createKindRegistry } from "../kind-registry-Ba4PO4WC.mjs";
|
|
9
|
+
import { n as SagaStep, t as CheckoutStep } from "../saga-steps-B27LI7xp.mjs";
|
|
10
|
+
import { n as isLegalCheckoutTransition, t as CHECKOUT_STATE_TRANSITIONS } from "../state-transitions-CpJpZZTK.mjs";
|
|
11
|
+
import "./events/index.mjs";
|
|
12
|
+
import "./ports/index.mjs";
|
|
13
|
+
import "./saga/index.mjs";
|
|
14
|
+
import { addMoney, fromMajor, money, multiplyMoney, subtractMoney, sumMoney, toMajor } from "@classytic/primitives/money";
|
|
15
|
+
export { CART_REF_NEW, CHECKOUT_STATE_TRANSITIONS, CartError, CartEvents, CheckoutStep, ConcurrencyError, IdempotencyBusyError, IdempotencyStorageError, InvalidOutboxEventError, KindError, MemoryOutboxStore, NotFoundError, OutboxOwnershipError, PriceChangedError, ReservationError, SagaError, SagaStep, StaleQuoteError, StateTransitionError, UnknownKindError, addMoney, cartEventDefinitions, cartEventsByName, createCartEvent, createCartEventRegistry, createCounterIdPort, createKindRegistry, cryptoIdPort, defineCartEvent, fromMajor, isLegalCheckoutTransition, money, multiplyMoney, subtractMoney, sumMoney, systemClock, toMajor };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { _ as ProductSummary, a as TaxBreakdown, b as BridgeStatus, c as TaxCalculationResult, d as PromotionResult, f as PromotionsBridge, g as CatalogBridge, h as ReservationRequest, i as ShippingQuoteRequest, l as AdjustmentSpec, m as ReservationRef, n as ShippingMethod, o as TaxBridge, p as InventoryBridge, r as ShippingQuote, s as TaxCalculationRequest, t as ShippingBridge, u as CartSnapshot, x as OperationContext, y as BridgeRef } from "../../shipping.bridge-DD4A_O0O.mjs";
|
|
2
|
+
import { a as systemClock, i as ClockPort, n as createCounterIdPort, r as cryptoIdPort, t as IdPort } from "../../id.port-DPXLrqb2.mjs";
|
|
3
|
+
export { AdjustmentSpec, BridgeRef, BridgeStatus, CartSnapshot, CatalogBridge, ClockPort, IdPort, InventoryBridge, OperationContext, ProductSummary, PromotionResult, PromotionsBridge, ReservationRef, ReservationRequest, ShippingBridge, ShippingMethod, ShippingQuote, ShippingQuoteRequest, TaxBreakdown, TaxBridge, TaxCalculationRequest, TaxCalculationResult, createCounterIdPort, cryptoIdPort, systemClock };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as CheckoutFlowState, c as CheckoutStepNumber, i as isLegalCheckoutTransition, l as SagaStep, n as SagaStepFn, o as SagaState, r as CHECKOUT_STATE_TRANSITIONS, s as CheckoutStep, t as SagaDependencies, u as SagaStepNumber } from "../../saga-step-fn-Cyob38iU.mjs";
|
|
2
|
+
export { CHECKOUT_STATE_TRANSITIONS, type CheckoutFlowState, CheckoutStep, type CheckoutStepNumber, type SagaDependencies, type SagaState, SagaStep, type SagaStepFn, type SagaStepNumber, isLegalCheckoutTransition };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { n as SagaStep, t as CheckoutStep } from "../../saga-steps-B27LI7xp.mjs";
|
|
2
|
+
import { n as isLegalCheckoutTransition, t as CHECKOUT_STATE_TRANSITIONS } from "../../state-transitions-CpJpZZTK.mjs";
|
|
3
|
+
export { CHECKOUT_STATE_TRANSITIONS, CheckoutStep, SagaStep, isLegalCheckoutTransition };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createEvent } from "@classytic/primitives/events";
|
|
2
|
+
//#region src/domain/events/cart-events.ts
|
|
3
|
+
/**
|
|
4
|
+
* Cart event name + payload map.
|
|
5
|
+
*
|
|
6
|
+
* Minimal surface. Cart emits events for its own lifecycle transitions
|
|
7
|
+
* only — draft mutations, checkout creation, and checkout commit/cancel.
|
|
8
|
+
* Payment, order creation, and fulfillment live in the host, so cart
|
|
9
|
+
* emits no events for them.
|
|
10
|
+
*
|
|
11
|
+
* For registration with an arc-compatible event registry, see the
|
|
12
|
+
* `cart-event-catalog.ts` file in this directory — it exposes each event
|
|
13
|
+
* as a `CartEventDefinition` via `defineCartEvent()`.
|
|
14
|
+
*/
|
|
15
|
+
const CartEvents = {
|
|
16
|
+
DRAFT_CREATED: "cart.draft.created",
|
|
17
|
+
DRAFT_ITEM_ADDED: "cart.draft.item_added",
|
|
18
|
+
DRAFT_ITEM_UPDATED: "cart.draft.item_updated",
|
|
19
|
+
DRAFT_ITEM_REMOVED: "cart.draft.item_removed",
|
|
20
|
+
DRAFT_PROMO_APPLIED: "cart.draft.promo_applied",
|
|
21
|
+
DRAFT_MERGED: "cart.draft.merged",
|
|
22
|
+
DRAFT_ABANDONED: "cart.draft.abandoned",
|
|
23
|
+
DRAFT_EXPIRED: "cart.draft.expired",
|
|
24
|
+
CHECKOUT_CREATED: "cart.checkout.created",
|
|
25
|
+
CHECKOUT_COMMITTED: "cart.checkout.committed",
|
|
26
|
+
CHECKOUT_CANCELED: "cart.checkout.canceled"
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/domain/events/domain-event.ts
|
|
30
|
+
/**
|
|
31
|
+
* Construct a {@link CartDomainEvent} with auto-filled id + timestamp
|
|
32
|
+
* (delegated to primitives' {@link createPrimitiveEvent createEvent}) plus
|
|
33
|
+
* cart-specific `version` / `aggregate` / `causationId`. Callers typically go
|
|
34
|
+
* through `defineCartEvent()` rather than calling this directly.
|
|
35
|
+
*/
|
|
36
|
+
function createCartEvent(type, payload, meta = {}, version = 1) {
|
|
37
|
+
const base = createEvent(type, payload, {
|
|
38
|
+
resource: meta.resource,
|
|
39
|
+
resourceId: meta.resourceId,
|
|
40
|
+
userId: meta.userId,
|
|
41
|
+
organizationId: meta.organizationId,
|
|
42
|
+
correlationId: meta.correlationId
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
...base,
|
|
46
|
+
meta: {
|
|
47
|
+
...base.meta,
|
|
48
|
+
id: meta.id ?? base.meta.id,
|
|
49
|
+
timestamp: meta.timestamp ?? base.meta.timestamp,
|
|
50
|
+
version: meta.version ?? version,
|
|
51
|
+
causationId: meta.causationId,
|
|
52
|
+
aggregate: meta.aggregate
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
export { CartEvents as n, createCartEvent as t };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/engine/cart-config.schema.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Zod v4 schema for `CartConfig`. Non-shape fields (connection, kinds,
|
|
6
|
+
* bridges) carry functions and class instances and are validated
|
|
7
|
+
* structurally by the engine factory.
|
|
8
|
+
*/
|
|
9
|
+
declare const idempotencyConfigSchema: z.ZodObject<{
|
|
10
|
+
inlineThresholdBytes: z.ZodDefault<z.ZodNumber>;
|
|
11
|
+
leaseMs: z.ZodDefault<z.ZodNumber>;
|
|
12
|
+
retentionSeconds: z.ZodDefault<z.ZodNumber>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
declare const reservationConfigSchema: z.ZodObject<{
|
|
15
|
+
defaultTtlSeconds: z.ZodDefault<z.ZodNumber>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
declare const scopeConfigSchema: z.ZodObject<{
|
|
18
|
+
contextKey: z.ZodDefault<z.ZodString>;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
declare const cartConfigSchema: z.ZodObject<{
|
|
21
|
+
scope: z.ZodDefault<z.ZodObject<{
|
|
22
|
+
contextKey: z.ZodDefault<z.ZodString>;
|
|
23
|
+
}, z.core.$strip>>;
|
|
24
|
+
defaultCurrency: z.ZodDefault<z.ZodString>;
|
|
25
|
+
idempotency: z.ZodDefault<z.ZodObject<{
|
|
26
|
+
inlineThresholdBytes: z.ZodDefault<z.ZodNumber>;
|
|
27
|
+
leaseMs: z.ZodDefault<z.ZodNumber>;
|
|
28
|
+
retentionSeconds: z.ZodDefault<z.ZodNumber>;
|
|
29
|
+
}, z.core.$strip>>;
|
|
30
|
+
reservation: z.ZodDefault<z.ZodObject<{
|
|
31
|
+
defaultTtlSeconds: z.ZodDefault<z.ZodNumber>;
|
|
32
|
+
}, z.core.$strip>>;
|
|
33
|
+
draftTtlSeconds: z.ZodOptional<z.ZodNumber>;
|
|
34
|
+
}, z.core.$strip>;
|
|
35
|
+
/**
|
|
36
|
+
* The strict config type inferred from the schema. Used for runtime
|
|
37
|
+
* validation of user-supplied config from env/YAML.
|
|
38
|
+
*/
|
|
39
|
+
type CartConfigShape = z.infer<typeof cartConfigSchema>;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { CartConfigShape, cartConfigSchema, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/engine/cart-config.schema.ts
|
|
3
|
+
/**
|
|
4
|
+
* Zod v4 schema for `CartConfig`. Non-shape fields (connection, kinds,
|
|
5
|
+
* bridges) carry functions and class instances and are validated
|
|
6
|
+
* structurally by the engine factory.
|
|
7
|
+
*/
|
|
8
|
+
const idempotencyConfigSchema = z.object({
|
|
9
|
+
/** Inline replay payload byte threshold. Default 12KB. */
|
|
10
|
+
inlineThresholdBytes: z.number().int().positive().default(12 * 1024),
|
|
11
|
+
/** Lease duration for in_flight records. Default 30s. */
|
|
12
|
+
leaseMs: z.number().int().positive().default(3e4),
|
|
13
|
+
/** Retention of resolved records. Default 24h. */
|
|
14
|
+
retentionSeconds: z.number().int().positive().default(1440 * 60)
|
|
15
|
+
});
|
|
16
|
+
const reservationConfigSchema = z.object({
|
|
17
|
+
/** Default TTL for reservations in seconds. Default 10 minutes. */
|
|
18
|
+
defaultTtlSeconds: z.number().int().positive().default(600) });
|
|
19
|
+
const scopeConfigSchema = z.object({
|
|
20
|
+
/**
|
|
21
|
+
* Optional context key name. The STORAGE FIELD is always
|
|
22
|
+
* `organizationId` — see plan §1. Only the lookup key on the host's
|
|
23
|
+
* request context is configurable.
|
|
24
|
+
*/
|
|
25
|
+
contextKey: z.string().default("organizationId") });
|
|
26
|
+
const cartConfigSchema = z.object({
|
|
27
|
+
scope: scopeConfigSchema.default({ contextKey: "organizationId" }),
|
|
28
|
+
/** Default currency if a draft is created with no currency set. */
|
|
29
|
+
defaultCurrency: z.string().length(3).default("USD"),
|
|
30
|
+
idempotency: idempotencyConfigSchema.default({
|
|
31
|
+
inlineThresholdBytes: 12 * 1024,
|
|
32
|
+
leaseMs: 3e4,
|
|
33
|
+
retentionSeconds: 1440 * 60
|
|
34
|
+
}),
|
|
35
|
+
reservation: reservationConfigSchema.default({ defaultTtlSeconds: 600 }),
|
|
36
|
+
/** Whether drafts auto-expire via TTL. Default off. */
|
|
37
|
+
draftTtlSeconds: z.number().int().positive().optional()
|
|
38
|
+
});
|
|
39
|
+
//#endregion
|
|
40
|
+
export { cartConfigSchema, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { CartConfigShape, cartConfigSchema, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema } from "./cart-config.schema.mjs";
|
|
2
|
+
import { a as CartEngine, i as CartConfig, n as createCart, r as CartBridges, t as InProcessCartEventBus } from "../internal-event-bus-IkUfQJxn.mjs";
|
|
3
|
+
export { type CartBridges, type CartConfig, type CartConfigShape, type CartEngine, InProcessCartEventBus, cartConfigSchema, createCart, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { n as InProcessCartEventBus, t as createCart } from "../create-cart-q3CXxPP7.mjs";
|
|
2
|
+
import { cartConfigSchema, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema } from "./cart-config.schema.mjs";
|
|
3
|
+
export { InProcessCartEventBus, cartConfigSchema, createCart, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { r as CartError } from "./kind.error-CCjTB6kW.mjs";
|
|
2
|
+
//#region src/domain/errors/reservation.error.ts
|
|
3
|
+
/**
|
|
4
|
+
* Inventory / slot reservation could not be secured. Thrown from the saga's
|
|
5
|
+
* step 5 (InventoryBridge.reserve) and from compensating `release` when the
|
|
6
|
+
* bridge reports the reservation no longer exists.
|
|
7
|
+
*
|
|
8
|
+
* Category is `external` because the decision is owned by the inventory
|
|
9
|
+
* system, not cart.
|
|
10
|
+
*/
|
|
11
|
+
var ReservationError = class extends CartError {
|
|
12
|
+
code = "cart/reservation_failed";
|
|
13
|
+
category = "external";
|
|
14
|
+
retryable;
|
|
15
|
+
constructor(message, opts) {
|
|
16
|
+
super(message, {
|
|
17
|
+
bridgeError: opts.bridgeError,
|
|
18
|
+
lineIds: opts.lineIds
|
|
19
|
+
});
|
|
20
|
+
this.retryable = opts.retryable;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/domain/errors/stale-quote.error.ts
|
|
25
|
+
/**
|
|
26
|
+
* A priced line's validity window has elapsed and its LineKind's revalidate()
|
|
27
|
+
* returned `invalid`. Fired from the saga's step 2 (revalidation).
|
|
28
|
+
*
|
|
29
|
+
* Example: a bid line whose underlying auction moved to a new highest bid
|
|
30
|
+
* while the user was reviewing the cart.
|
|
31
|
+
*
|
|
32
|
+
* Clients should re-read the cart, show the updated state, and confirm again.
|
|
33
|
+
* Retryable with a new idempotency key.
|
|
34
|
+
*/
|
|
35
|
+
var StaleQuoteError = class extends CartError {
|
|
36
|
+
code = "cart/stale_quote";
|
|
37
|
+
category = "validation";
|
|
38
|
+
retryable = true;
|
|
39
|
+
constructor(lineId, kind, reason, details) {
|
|
40
|
+
super(`Line ${lineId} (${kind}) is no longer valid: ${reason}`, {
|
|
41
|
+
lineId,
|
|
42
|
+
kind,
|
|
43
|
+
reason,
|
|
44
|
+
...details
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/domain/errors/saga.error.ts
|
|
50
|
+
var SagaError = class extends CartError {
|
|
51
|
+
code = "cart/saga_failure";
|
|
52
|
+
category = "system";
|
|
53
|
+
retryable;
|
|
54
|
+
constructor(message, opts) {
|
|
55
|
+
super(message, {
|
|
56
|
+
checkoutId: opts.checkoutId,
|
|
57
|
+
failedStep: opts.failedStep,
|
|
58
|
+
phase: opts.phase,
|
|
59
|
+
completedSteps: opts.completedSteps,
|
|
60
|
+
compensatedSteps: opts.compensatedSteps,
|
|
61
|
+
cause: opts.cause instanceof Error ? opts.cause.message : opts.cause
|
|
62
|
+
});
|
|
63
|
+
this.retryable = opts.retryable;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Raised when a retry attempts to execute an operation that is already
|
|
68
|
+
* `in_flight` in the idempotency collection and the lease has not yet
|
|
69
|
+
* expired. The caller should back off and retry later — by then the lease
|
|
70
|
+
* will have settled or expired.
|
|
71
|
+
*/
|
|
72
|
+
var IdempotencyBusyError = class extends CartError {
|
|
73
|
+
code = "cart/idempotency_busy";
|
|
74
|
+
category = "concurrency";
|
|
75
|
+
retryable = true;
|
|
76
|
+
constructor(operation, leaseExpiresAt) {
|
|
77
|
+
super(`Operation ${operation} is already in-flight until ${leaseExpiresAt.toISOString()}`, {
|
|
78
|
+
operation,
|
|
79
|
+
leaseExpiresAt: leaseExpiresAt.toISOString()
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Raised when the idempotency record points at a `cart_operation_results`
|
|
85
|
+
* document that does not exist, or when a stored record is otherwise
|
|
86
|
+
* malformed. This is data corruption, not a recoverable state.
|
|
87
|
+
*/
|
|
88
|
+
var IdempotencyStorageError = class extends CartError {
|
|
89
|
+
code = "cart/idempotency_storage_corruption";
|
|
90
|
+
category = "system";
|
|
91
|
+
retryable = false;
|
|
92
|
+
constructor(message, context) {
|
|
93
|
+
super(message, context);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
//#endregion
|
|
97
|
+
export { ReservationError as a, StaleQuoteError as i, IdempotencyStorageError as n, SagaError as r, IdempotencyBusyError as t };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/domain/ports/clock.port.ts
|
|
2
|
+
/** Default system clock — passes straight through to `new Date()`. */
|
|
3
|
+
const systemClock = { now: () => /* @__PURE__ */ new Date() };
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/domain/ports/id.port.ts
|
|
6
|
+
/**
|
|
7
|
+
* Default IdPort using `globalThis.crypto.randomUUID()`. Throws a helpful
|
|
8
|
+
* error if `crypto.randomUUID` is not available, so hosts in older runtimes
|
|
9
|
+
* get an actionable failure instead of a silent undefined.
|
|
10
|
+
*/
|
|
11
|
+
const cryptoIdPort = { newId() {
|
|
12
|
+
const g = globalThis;
|
|
13
|
+
if (typeof g.crypto?.randomUUID === "function") return g.crypto.randomUUID();
|
|
14
|
+
throw new Error("cryptoIdPort: globalThis.crypto.randomUUID is not available in this runtime. Node 19+, Deno, Bun, and modern browsers expose it natively. Older runtimes should supply a custom `id` port to createCart(), e.g. uuid v4 from the `uuid` package or Temporal's `workflow.uuid4()`.");
|
|
15
|
+
} };
|
|
16
|
+
/**
|
|
17
|
+
* Deterministic counter-based id port for tests. Not exported from the
|
|
18
|
+
* package root — only used in scenario tests and unit tests. Hosts should
|
|
19
|
+
* never wire this in production.
|
|
20
|
+
*/
|
|
21
|
+
function createCounterIdPort(prefix = "id_") {
|
|
22
|
+
let n = 0;
|
|
23
|
+
return { newId() {
|
|
24
|
+
n += 1;
|
|
25
|
+
return `${prefix}${n}`;
|
|
26
|
+
} };
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { cryptoIdPort as n, systemClock as r, createCounterIdPort as t };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
//#region src/domain/ports/clock.port.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Clock port — the one source of "now" in the cart engine.
|
|
4
|
+
*
|
|
5
|
+
* Injected through config so tests can install a fake clock and fast-forward
|
|
6
|
+
* through TTLs, validity windows, and saga lease expirations. Production
|
|
7
|
+
* hosts pass nothing and get a default `systemClock` that calls `new Date()`.
|
|
8
|
+
*
|
|
9
|
+
* Never read `Date.now()` or `new Date()` directly in cart code. Always use
|
|
10
|
+
* `engine.clock.now()`. Integration tests assert this via ESLint rule.
|
|
11
|
+
*/
|
|
12
|
+
interface ClockPort {
|
|
13
|
+
/** Wall clock — used for timestamps, TTL expiry, idempotency leases. */
|
|
14
|
+
now(): Date;
|
|
15
|
+
}
|
|
16
|
+
/** Default system clock — passes straight through to `new Date()`. */
|
|
17
|
+
declare const systemClock: ClockPort;
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/domain/ports/id.port.d.ts
|
|
20
|
+
/**
|
|
21
|
+
* IdPort — a swappable source of unique identifiers.
|
|
22
|
+
*
|
|
23
|
+
* Cart generates IDs for:
|
|
24
|
+
* - domain events (meta.id)
|
|
25
|
+
* - saga run correlators
|
|
26
|
+
* - internal idempotency lease tokens
|
|
27
|
+
*
|
|
28
|
+
* Why it's a port (not a hardcoded `crypto.randomUUID()` call):
|
|
29
|
+
*
|
|
30
|
+
* 1. **Temporal workflows** run in a deterministic sandbox. Calling
|
|
31
|
+
* `Math.random()` or `crypto.randomUUID()` directly is a replay hazard.
|
|
32
|
+
* Hosts using Temporal pass `workflow.uuid4` via this port.
|
|
33
|
+
*
|
|
34
|
+
* 2. **Deterministic tests** — tests can install a counter-based id port
|
|
35
|
+
* and assert on stable values.
|
|
36
|
+
*
|
|
37
|
+
* 3. **Distributed trace correlation** — some hosts want IDs that embed a
|
|
38
|
+
* tenant prefix or trace id. This port lets them.
|
|
39
|
+
*
|
|
40
|
+
* 4. **Edge runtimes** / environments without `node:crypto` — hosts pass
|
|
41
|
+
* any implementation they prefer.
|
|
42
|
+
*
|
|
43
|
+
* Default implementation uses `globalThis.crypto.randomUUID()` which is
|
|
44
|
+
* available in Node 19+, Deno, Bun, and all modern browsers / edge runtimes.
|
|
45
|
+
* No `require('node:crypto')` — stays pure ESM and sandbox-safe.
|
|
46
|
+
*/
|
|
47
|
+
interface IdPort {
|
|
48
|
+
/** Return a new globally unique identifier. Must never throw. */
|
|
49
|
+
newId(): string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Default IdPort using `globalThis.crypto.randomUUID()`. Throws a helpful
|
|
53
|
+
* error if `crypto.randomUUID` is not available, so hosts in older runtimes
|
|
54
|
+
* get an actionable failure instead of a silent undefined.
|
|
55
|
+
*/
|
|
56
|
+
declare const cryptoIdPort: IdPort;
|
|
57
|
+
/**
|
|
58
|
+
* Deterministic counter-based id port for tests. Not exported from the
|
|
59
|
+
* package root — only used in scenario tests and unit tests. Hosts should
|
|
60
|
+
* never wire this in production.
|
|
61
|
+
*/
|
|
62
|
+
declare function createCounterIdPort(prefix?: string): IdPort;
|
|
63
|
+
//#endregion
|
|
64
|
+
export { systemClock as a, ClockPort as i, createCounterIdPort as n, cryptoIdPort as r, IdPort as t };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/domain/value-objects/idempotency-key.vo.ts
|
|
2
|
+
/**
|
|
3
|
+
* Sentinel for the cart-creation operation where no cartRef exists yet.
|
|
4
|
+
* Using a literal rather than null keeps the composite index unique-safe
|
|
5
|
+
* under MongoDB semantics (nulls are considered equal by the unique index).
|
|
6
|
+
*/
|
|
7
|
+
const CART_REF_NEW = "new";
|
|
8
|
+
//#endregion
|
|
9
|
+
export { CART_REF_NEW as t };
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { n as DraftStatus, r as ReservationStatus, t as CheckoutState } from "./cart-status.vo-2iisZGhb.mjs";
|
|
2
|
+
import { o as IdempotencyReplay, s as OperationName, t as LineItem } from "./line-item.entity-B3M_i-pw.mjs";
|
|
3
|
+
import { C as PricingSnapshot, l as AdjustmentSpec } from "./shipping.bridge-DD4A_O0O.mjs";
|
|
4
|
+
import { a as CheckoutFlowState } from "./saga-step-fn-Cyob38iU.mjs";
|
|
5
|
+
import { Money } from "@classytic/primitives/money";
|
|
6
|
+
|
|
7
|
+
//#region src/domain/entities/adjustment.entity.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Adjustment — an explicit discount / surcharge on the cart, represented as
|
|
10
|
+
* a sibling line item to the priced lines.
|
|
11
|
+
*
|
|
12
|
+
* Rationale (from plan, §6 and the Odoo-inspired discount-as-line pattern):
|
|
13
|
+
* storing discounts as explicit lines makes them trivially auditable and
|
|
14
|
+
* reversible, and avoids the "sum of lines doesn't match subtotal" problems
|
|
15
|
+
* that embedded discounts cause in Shopify-style schemas.
|
|
16
|
+
*
|
|
17
|
+
* Adjustments are NOT LineItems — they are a separate collection on the
|
|
18
|
+
* draft so the pricing pipeline can distinguish "things the user added" from
|
|
19
|
+
* "things the rules engine applied". Promo bridges return PromotionResults;
|
|
20
|
+
* the promo-apply step turns each into one of these.
|
|
21
|
+
*/
|
|
22
|
+
interface Adjustment {
|
|
23
|
+
/** Stable adjustment ID. */
|
|
24
|
+
adjustmentId: string;
|
|
25
|
+
/**
|
|
26
|
+
* Origin of the adjustment. Helps the display layer and audit:
|
|
27
|
+
* promotion — came from PromotionsBridge.evaluate()
|
|
28
|
+
* manual — applied by an admin or support tool
|
|
29
|
+
* system — applied by cart itself (e.g., rounding residual)
|
|
30
|
+
*/
|
|
31
|
+
source: 'promotion' | 'manual' | 'system';
|
|
32
|
+
/** If source==='promotion', the PromotionResult.ruleRef. */
|
|
33
|
+
ruleRef?: string;
|
|
34
|
+
/** The adjustment body, same shape PromotionsBridge returns. */
|
|
35
|
+
spec: AdjustmentSpec;
|
|
36
|
+
/** LineItem this adjustment applies to, or null for order-level. */
|
|
37
|
+
targetLineId: string | null;
|
|
38
|
+
/** Applied amount in minor units after the pipeline computed it. */
|
|
39
|
+
appliedAmount: Money;
|
|
40
|
+
/** Human-readable explanation for display on cart + receipt. */
|
|
41
|
+
explanation?: string;
|
|
42
|
+
/** Stacking priority from the promotion result (higher first). */
|
|
43
|
+
priority: number;
|
|
44
|
+
/** ISO timestamp of when the adjustment was applied. */
|
|
45
|
+
appliedAt: Date;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/domain/entities/draft.entity.d.ts
|
|
49
|
+
/**
|
|
50
|
+
* Draft — the mutable cart the buyer interacts with before checkout.
|
|
51
|
+
*
|
|
52
|
+
* One draft per (organizationId, actorRef). Guest carts are drafts where
|
|
53
|
+
* `actorKind === 'session'`; on login, MergeService promotes a guest draft
|
|
54
|
+
* into an authenticated-user draft, deduping lines per kind semantics.
|
|
55
|
+
*
|
|
56
|
+
* Identity:
|
|
57
|
+
* - `_id`: native ObjectId, used as foreign key target
|
|
58
|
+
* - `publicId`: human-readable string (cart_...) for external surfaces
|
|
59
|
+
* — see plan §1 cart-owned ID strategy.
|
|
60
|
+
*
|
|
61
|
+
* Optimistic concurrency:
|
|
62
|
+
* - `version` is incremented atomically on every write
|
|
63
|
+
* - Writers pass the expected version in the update filter
|
|
64
|
+
* - Mismatch → ConcurrencyError
|
|
65
|
+
*/
|
|
66
|
+
interface Draft {
|
|
67
|
+
_id: string;
|
|
68
|
+
publicId: string;
|
|
69
|
+
organizationId: string;
|
|
70
|
+
actorRef: string;
|
|
71
|
+
actorKind: 'user' | 'session';
|
|
72
|
+
status: DraftStatus;
|
|
73
|
+
lines: readonly LineItem[];
|
|
74
|
+
adjustments: readonly Adjustment[];
|
|
75
|
+
/** Currency the cart is priced in. Frozen on first item add. */
|
|
76
|
+
currency: string;
|
|
77
|
+
/** Latest computed pricing snapshot. Null before any items are added. */
|
|
78
|
+
pricing: PricingSnapshot | null;
|
|
79
|
+
/** Optimistic-lock version. Incremented on every write. */
|
|
80
|
+
version: number;
|
|
81
|
+
/** Optional TTL — opt-in per plan Open Question #4. */
|
|
82
|
+
expiresAt?: Date;
|
|
83
|
+
/** Idempotency key of the operation that last mutated this draft. */
|
|
84
|
+
lastIdempotencyKey?: string;
|
|
85
|
+
/** Public metadata bag for host extensibility. */
|
|
86
|
+
metadata?: Record<string, unknown>;
|
|
87
|
+
/** Private metadata, never exposed to the buyer. */
|
|
88
|
+
privateMetadata?: Record<string, unknown>;
|
|
89
|
+
createdAt: Date;
|
|
90
|
+
updatedAt: Date;
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/domain/entities/checkout.entity.d.ts
|
|
94
|
+
/**
|
|
95
|
+
* Checkout — the locked snapshot a draft produces when the host calls
|
|
96
|
+
* `createFromDraft()`.
|
|
97
|
+
*
|
|
98
|
+
* Deliberately minimal:
|
|
99
|
+
* - Frozen `lines`, `adjustments`, `pricing` (all captured from the draft)
|
|
100
|
+
* - Simple `state` field (`open | finalized | canceled`)
|
|
101
|
+
* - Optional `externalRef` the host attaches on commit — whatever opaque
|
|
102
|
+
* reference the host wants (order ID, Stripe payment intent, ERP
|
|
103
|
+
* invoice number). Cart never interprets it.
|
|
104
|
+
*
|
|
105
|
+
* Cart does NOT carry payment state, capture state, host order refs, or
|
|
106
|
+
* saga compensation bookkeeping. Those are the host's concern.
|
|
107
|
+
*/
|
|
108
|
+
interface Checkout {
|
|
109
|
+
_id: string;
|
|
110
|
+
publicId: string;
|
|
111
|
+
organizationId: string;
|
|
112
|
+
draftId: string;
|
|
113
|
+
actorRef: string;
|
|
114
|
+
actorKind: 'user' | 'session';
|
|
115
|
+
state: CheckoutState;
|
|
116
|
+
/** Minimal transient flow state — for diagnostics and logging. */
|
|
117
|
+
flowState: CheckoutFlowState;
|
|
118
|
+
/** Frozen line snapshot. */
|
|
119
|
+
lines: readonly LineItem[];
|
|
120
|
+
/** Frozen adjustment snapshot. */
|
|
121
|
+
adjustments: readonly Adjustment[];
|
|
122
|
+
currency: string;
|
|
123
|
+
/** Frozen pricing — never mutated. */
|
|
124
|
+
pricing: PricingSnapshot;
|
|
125
|
+
/**
|
|
126
|
+
* Opaque reference the host attaches on commit. May be an order ID,
|
|
127
|
+
* a payment intent, an ERP invoice number — cart does not interpret.
|
|
128
|
+
* Populated only after `commit(checkoutId, externalRef)`.
|
|
129
|
+
*/
|
|
130
|
+
externalRef?: string | null;
|
|
131
|
+
/** Reason string attached on cancel. */
|
|
132
|
+
canceledReason?: string | null;
|
|
133
|
+
version: number;
|
|
134
|
+
metadata?: Record<string, unknown>;
|
|
135
|
+
privateMetadata?: Record<string, unknown>;
|
|
136
|
+
createdAt: Date;
|
|
137
|
+
updatedAt: Date;
|
|
138
|
+
}
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/domain/entities/reservation.entity.d.ts
|
|
141
|
+
/**
|
|
142
|
+
* Reservation — an individual stock/slot hold produced by
|
|
143
|
+
* InventoryBridge.reserve().
|
|
144
|
+
*
|
|
145
|
+
* One reservation per LineItem. Stored in its own collection so each
|
|
146
|
+
* reservation can have independent TTL + status + version, and so the
|
|
147
|
+
* query function can run keyset-paginated scans without materialising the
|
|
148
|
+
* whole checkout.
|
|
149
|
+
*
|
|
150
|
+
* Lifecycle (see plan §4 — Reservations with TTL):
|
|
151
|
+
* held → created by saga step 5
|
|
152
|
+
* committed → transitioned by saga step 10
|
|
153
|
+
* released → by the host, compensation, or manual cancel
|
|
154
|
+
* expired → rarely observed — the host normally releases before
|
|
155
|
+
* the TTL index drops the doc as a backstop
|
|
156
|
+
*
|
|
157
|
+
* The TTL index on `expiresAt` is a GARBAGE COLLECTOR for already-released
|
|
158
|
+
* docs, NOT the release mechanism. Physical holds are released explicitly
|
|
159
|
+
* by the host via InventoryBridge.release().
|
|
160
|
+
*/
|
|
161
|
+
interface Reservation {
|
|
162
|
+
_id: string;
|
|
163
|
+
publicId: string;
|
|
164
|
+
organizationId: string;
|
|
165
|
+
checkoutId: string;
|
|
166
|
+
lineId: string;
|
|
167
|
+
/** The bridge-returned ref payload, opaque to cart. */
|
|
168
|
+
bridgeRef: {
|
|
169
|
+
id: string;
|
|
170
|
+
payload: unknown;
|
|
171
|
+
};
|
|
172
|
+
/** Denormalised from the line for faster sweeper scans. */
|
|
173
|
+
skuRef: string;
|
|
174
|
+
quantity: number;
|
|
175
|
+
status: ReservationStatus;
|
|
176
|
+
/** When the reservation was created. */
|
|
177
|
+
heldAt: Date;
|
|
178
|
+
/** TTL target. Sweeper releases before this; TTL index backstop drops after. */
|
|
179
|
+
expiresAt: Date;
|
|
180
|
+
/** When the reservation was explicitly released. */
|
|
181
|
+
releasedAt?: Date;
|
|
182
|
+
/** Reason for release — for audit. */
|
|
183
|
+
releaseReason?: 'compensation' | 'expired' | 'canceled' | 'manual';
|
|
184
|
+
version: number;
|
|
185
|
+
createdAt: Date;
|
|
186
|
+
updatedAt: Date;
|
|
187
|
+
}
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/domain/entities/idempotency-record.entity.d.ts
|
|
190
|
+
/**
|
|
191
|
+
* IdempotencyRecord — one row per (org, cartRef, op, actor, key) attempt.
|
|
192
|
+
*
|
|
193
|
+
* See plan §2 — Idempotency identity is composite, and the Replay storage
|
|
194
|
+
* rules (inline vs pointer) and the 6-state crash-window table.
|
|
195
|
+
*
|
|
196
|
+
* Stored in a dedicated `cart_idempotency` collection with a unique compound
|
|
197
|
+
* index on the composite identity.
|
|
198
|
+
*/
|
|
199
|
+
interface IdempotencyRecord {
|
|
200
|
+
_id: string;
|
|
201
|
+
organizationId: string;
|
|
202
|
+
cartRef: string;
|
|
203
|
+
operation: OperationName;
|
|
204
|
+
actorRef: string;
|
|
205
|
+
idempotencyKey: string;
|
|
206
|
+
status: 'in_flight' | 'succeeded' | 'failed';
|
|
207
|
+
/**
|
|
208
|
+
* Replay payload — either inline (small results) or a pointer to
|
|
209
|
+
* `cart_operation_results` (large results). Absent on 'in_flight' records.
|
|
210
|
+
*/
|
|
211
|
+
replay?: IdempotencyReplay;
|
|
212
|
+
/** Unique token minted on insert. Used by retries to claim expired leases. */
|
|
213
|
+
leaseToken: string;
|
|
214
|
+
/** When the current lease expires — default insert + 30s. */
|
|
215
|
+
leaseExpiresAt: Date;
|
|
216
|
+
createdAt: Date;
|
|
217
|
+
/** Set when status transitions to 'succeeded' or 'failed'. */
|
|
218
|
+
completedAt?: Date;
|
|
219
|
+
}
|
|
220
|
+
//#endregion
|
|
221
|
+
export { Adjustment as a, Draft as i, Reservation as n, Checkout as r, IdempotencyRecord as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|