@classytic/cart 0.1.3 → 0.2.1
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 +83 -0
- package/README.md +12 -2
- package/dist/{clock.port-BUe6Dk_M.d.mts → clock.port-CNu2wgdA.d.mts} +13 -1
- package/dist/{create-cart-4wql1XGi.mjs → create-cart-BeW0xAqD.mjs} +302 -30
- package/dist/domain/errors/index.d.mts +2 -2
- package/dist/domain/errors/index.mjs +2 -2
- package/dist/domain/index.d.mts +7 -7
- package/dist/domain/index.mjs +4 -4
- package/dist/domain/ports/index.d.mts +1 -1
- package/dist/domain/saga/index.d.mts +1 -1
- package/dist/domain/saga/index.mjs +1 -1
- package/dist/engine/cart-config.schema.d.mts +7 -1
- package/dist/engine/cart-config.schema.mjs +12 -2
- package/dist/engine/index.d.mts +1 -1
- package/dist/engine/index.mjs +1 -1
- package/dist/{index-qfN8dZN9.d.mts → index-BB0XzkXF.d.mts} +45 -2
- package/dist/index.d.mts +52 -15
- package/dist/index.mjs +83 -26
- package/dist/{internal-event-bus-DhSLiZHi.d.mts → internal-event-bus-DhQKi9KS.d.mts} +104 -6
- package/dist/{kind-registry-D03c2VV5.d.mts → kind-registry-DG2iCCH1.d.mts} +1 -1
- package/dist/kinds/index.d.mts +1 -1
- package/dist/kinds/index.mjs +1 -1
- package/dist/{line-kind-CKOWafK0.d.mts → line-kind-B1mU1iJp.d.mts} +1 -1
- package/dist/{reservation.entity-WdaZCJg9.d.mts → reservation.entity-DLMxgpLE.d.mts} +3 -3
- package/dist/{state-transitions-D8CRykBv.d.mts → state-transitions-D19wZe-w.d.mts} +2 -2
- package/dist/{stale-quote.error-BkFLXWo5.mjs → unmanaged-session.error-C9Z1Yh9j.mjs} +31 -1
- package/dist/{variant.kind-z2gwH9Vo.mjs → variant.kind-BHiivO9B.mjs} +2 -1
- package/dist/{variant.kind-Cpo_Hh7G.d.mts → variant.kind-q-yv-vnQ.d.mts} +1 -1
- package/package.json +6 -6
- /package/dist/{kind-registry-C99h_-8t.mjs → kind-registry-Bvrj3P1Q.mjs} +0 -0
- /package/dist/{state-transitions-Bm3lC2Uv.mjs → state-transitions-Defw8gAt.mjs} +0 -0
package/dist/domain/index.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { t as CART_REF_NEW } from "../idempotency-key.vo-D0lJsvGn.mjs";
|
|
2
2
|
import { t as CartError } from "../cart.error-BwWy4RlY.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { a as ConcurrencyError, i as NotFoundError, n as StaleQuoteError, r as PriceChangedError, t as UnmanagedSessionError } from "../unmanaged-session.error-C9Z1Yh9j.mjs";
|
|
4
4
|
import { n as UnknownKindError, t as KindError } from "../kind.error-DIaJpdUb.mjs";
|
|
5
5
|
import { i as ReservationError, n as IdempotencyStorageError, r as SagaError, t as IdempotencyBusyError } from "../errors-7Pd0yATM.mjs";
|
|
6
6
|
import { t as StateTransitionError } from "../state-transition.error-2fRLh3p0.mjs";
|
|
7
7
|
import { n as CartEvents, t as createCartEvent } from "../domain-event-CIEORKF6.mjs";
|
|
8
8
|
import { a as cartEventsByName, i as cartEventDefinitions, n as MemoryOutboxStore, o as createCartEventRegistry, r as OutboxOwnershipError, s as defineCartEvent, t as InvalidOutboxEventError } from "../outbox-store-CWW8ppxS.mjs";
|
|
9
9
|
import { n as cryptoIdPort, r as systemClock, t as createCounterIdPort } from "../id.port-BhbFZJPm.mjs";
|
|
10
|
-
import { t as createKindRegistry } from "../kind-registry-
|
|
11
|
-
import { i as CheckoutStep, n as CHECKOUT_STATE_TRANSITIONS, r as isLegalCheckoutTransition, t as CHECKOUT_MACHINE } from "../state-transitions-
|
|
10
|
+
import { t as createKindRegistry } from "../kind-registry-Bvrj3P1Q.mjs";
|
|
11
|
+
import { i as CheckoutStep, n as CHECKOUT_STATE_TRANSITIONS, r as isLegalCheckoutTransition, t as CHECKOUT_MACHINE } from "../state-transitions-Defw8gAt.mjs";
|
|
12
12
|
import "./events/index.mjs";
|
|
13
13
|
import "./ports/index.mjs";
|
|
14
14
|
import "./saga/index.mjs";
|
|
15
15
|
import { addMoney, fromMajor, money, multiplyMoney, subtractMoney, sumMoney, toMajor } from "@classytic/primitives/money";
|
|
16
|
-
export { CART_REF_NEW, CHECKOUT_MACHINE, CHECKOUT_STATE_TRANSITIONS, CartError, CartEvents, CheckoutStep, ConcurrencyError, IdempotencyBusyError, IdempotencyStorageError, InvalidOutboxEventError, KindError, MemoryOutboxStore, NotFoundError, OutboxOwnershipError, PriceChangedError, ReservationError, SagaError, StaleQuoteError, StateTransitionError, UnknownKindError, addMoney, cartEventDefinitions, cartEventsByName, createCartEvent, createCartEventRegistry, createCounterIdPort, createKindRegistry, cryptoIdPort, defineCartEvent, fromMajor, isLegalCheckoutTransition, money, multiplyMoney, subtractMoney, sumMoney, systemClock, toMajor };
|
|
16
|
+
export { CART_REF_NEW, CHECKOUT_MACHINE, CHECKOUT_STATE_TRANSITIONS, CartError, CartEvents, CheckoutStep, ConcurrencyError, IdempotencyBusyError, IdempotencyStorageError, InvalidOutboxEventError, KindError, MemoryOutboxStore, NotFoundError, OutboxOwnershipError, PriceChangedError, ReservationError, SagaError, StaleQuoteError, StateTransitionError, UnknownKindError, UnmanagedSessionError, addMoney, cartEventDefinitions, cartEventsByName, createCartEvent, createCartEventRegistry, createCounterIdPort, createKindRegistry, cryptoIdPort, defineCartEvent, fromMajor, isLegalCheckoutTransition, money, multiplyMoney, subtractMoney, sumMoney, systemClock, toMajor };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { C as OperationContext, S as BridgeStatus, _ as CartSnapshot, a as ShippingQuote, c as TaxBridge, d as InventoryBridge, f as ReservationRef, g as AdjustmentSpec, h as ProductSummary, i as ShippingMethod, l as TaxCalculationRequest, m as CatalogBridge, n as systemClock, o as ShippingQuoteRequest, p as ReservationRequest, r as ShippingBridge, s as TaxBreakdown, t as ClockPort, u as TaxCalculationResult, v as PromotionResult, x as BridgeRef, y as PromotionsBridge } from "../../clock.port-
|
|
1
|
+
import { C as OperationContext, S as BridgeStatus, _ as CartSnapshot, a as ShippingQuote, c as TaxBridge, d as InventoryBridge, f as ReservationRef, g as AdjustmentSpec, h as ProductSummary, i as ShippingMethod, l as TaxCalculationRequest, m as CatalogBridge, n as systemClock, o as ShippingQuoteRequest, p as ReservationRequest, r as ShippingBridge, s as TaxBreakdown, t as ClockPort, u as TaxCalculationResult, v as PromotionResult, x as BridgeRef, y as PromotionsBridge } from "../../clock.port-CNu2wgdA.mjs";
|
|
2
2
|
import { n as createCounterIdPort, r as cryptoIdPort, t as IdPort } from "../../id.port-DitjeoHg.mjs";
|
|
3
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 };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as SagaStepFn, c as CheckoutStepNumber, i as SagaDependencies, n as CHECKOUT_STATE_TRANSITIONS, o as CheckoutFlowState, r as isLegalCheckoutTransition, s as CheckoutStep, t as CHECKOUT_MACHINE } from "../../state-transitions-
|
|
1
|
+
import { a as SagaStepFn, c as CheckoutStepNumber, i as SagaDependencies, n as CHECKOUT_STATE_TRANSITIONS, o as CheckoutFlowState, r as isLegalCheckoutTransition, s as CheckoutStep, t as CHECKOUT_MACHINE } from "../../state-transitions-D19wZe-w.mjs";
|
|
2
2
|
export { CHECKOUT_MACHINE, CHECKOUT_STATE_TRANSITIONS, type CheckoutFlowState, CheckoutStep, type CheckoutStepNumber, type SagaDependencies, type SagaStepFn, isLegalCheckoutTransition };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as CheckoutStep, n as CHECKOUT_STATE_TRANSITIONS, r as isLegalCheckoutTransition, t as CHECKOUT_MACHINE } from "../../state-transitions-
|
|
1
|
+
import { i as CheckoutStep, n as CHECKOUT_STATE_TRANSITIONS, r as isLegalCheckoutTransition, t as CHECKOUT_MACHINE } from "../../state-transitions-Defw8gAt.mjs";
|
|
2
2
|
export { CHECKOUT_MACHINE, CHECKOUT_STATE_TRANSITIONS, CheckoutStep, isLegalCheckoutTransition };
|
|
@@ -14,6 +14,9 @@ declare const idempotencyConfigSchema: z.ZodObject<{
|
|
|
14
14
|
declare const reservationConfigSchema: z.ZodObject<{
|
|
15
15
|
defaultTtlSeconds: z.ZodDefault<z.ZodNumber>;
|
|
16
16
|
}, z.core.$strip>;
|
|
17
|
+
declare const checkoutConfigSchema: z.ZodObject<{
|
|
18
|
+
staleOpenCheckoutMs: z.ZodDefault<z.ZodNumber>;
|
|
19
|
+
}, z.core.$strip>;
|
|
17
20
|
declare const scopeConfigSchema: z.ZodObject<{
|
|
18
21
|
contextKey: z.ZodDefault<z.ZodString>;
|
|
19
22
|
}, z.core.$strip>;
|
|
@@ -30,6 +33,9 @@ declare const cartConfigSchema: z.ZodObject<{
|
|
|
30
33
|
reservation: z.ZodDefault<z.ZodObject<{
|
|
31
34
|
defaultTtlSeconds: z.ZodDefault<z.ZodNumber>;
|
|
32
35
|
}, z.core.$strip>>;
|
|
36
|
+
checkout: z.ZodDefault<z.ZodObject<{
|
|
37
|
+
staleOpenCheckoutMs: z.ZodDefault<z.ZodNumber>;
|
|
38
|
+
}, z.core.$strip>>;
|
|
33
39
|
draftTtlSeconds: z.ZodOptional<z.ZodNumber>;
|
|
34
40
|
}, z.core.$strip>;
|
|
35
41
|
/**
|
|
@@ -38,4 +44,4 @@ declare const cartConfigSchema: z.ZodObject<{
|
|
|
38
44
|
*/
|
|
39
45
|
type CartConfigShape = z.infer<typeof cartConfigSchema>;
|
|
40
46
|
//#endregion
|
|
41
|
-
export { CartConfigShape, cartConfigSchema, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema };
|
|
47
|
+
export { CartConfigShape, cartConfigSchema, checkoutConfigSchema, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CURRENCY_PATTERN } from "@classytic/primitives/currency";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
//#region src/engine/cart-config.schema.ts
|
|
3
4
|
/**
|
|
@@ -16,6 +17,14 @@ const idempotencyConfigSchema = z.object({
|
|
|
16
17
|
const reservationConfigSchema = z.object({
|
|
17
18
|
/** Default TTL for reservations in seconds. Default 10 minutes. */
|
|
18
19
|
defaultTtlSeconds: z.number().int().positive().default(600) });
|
|
20
|
+
const checkoutConfigSchema = z.object({
|
|
21
|
+
/**
|
|
22
|
+
* Age (ms) past which an `open` checkout counts as a zombie and is
|
|
23
|
+
* lazily expired by `createFromDraft` (CAS `open → canceled`, reason
|
|
24
|
+
* `'expired'`) so a fresh checkout can be created. Default 10 minutes —
|
|
25
|
+
* matches `reservationConfigSchema.defaultTtlSeconds`.
|
|
26
|
+
*/
|
|
27
|
+
staleOpenCheckoutMs: z.number().int().positive().default(6e5) });
|
|
19
28
|
const scopeConfigSchema = z.object({
|
|
20
29
|
/**
|
|
21
30
|
* Optional context key name. The STORAGE FIELD is always
|
|
@@ -26,15 +35,16 @@ contextKey: z.string().default("organizationId") });
|
|
|
26
35
|
const cartConfigSchema = z.object({
|
|
27
36
|
scope: scopeConfigSchema.default({ contextKey: "organizationId" }),
|
|
28
37
|
/** Default currency if a draft is created with no currency set. */
|
|
29
|
-
defaultCurrency: z.string().
|
|
38
|
+
defaultCurrency: z.string().regex(CURRENCY_PATTERN, "ISO 4217 (3 uppercase letters)").default("USD"),
|
|
30
39
|
idempotency: idempotencyConfigSchema.default({
|
|
31
40
|
inlineThresholdBytes: 12 * 1024,
|
|
32
41
|
leaseMs: 3e4,
|
|
33
42
|
retentionSeconds: 1440 * 60
|
|
34
43
|
}),
|
|
35
44
|
reservation: reservationConfigSchema.default({ defaultTtlSeconds: 600 }),
|
|
45
|
+
checkout: checkoutConfigSchema.default({ staleOpenCheckoutMs: 6e5 }),
|
|
36
46
|
/** Whether drafts auto-expire via TTL. Default off. */
|
|
37
47
|
draftTtlSeconds: z.number().int().positive().optional()
|
|
38
48
|
});
|
|
39
49
|
//#endregion
|
|
40
|
-
export { cartConfigSchema, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema };
|
|
50
|
+
export { cartConfigSchema, checkoutConfigSchema, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema };
|
package/dist/engine/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
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-
|
|
2
|
+
import { a as CartEngine, i as CartConfig, n as createCart, r as CartBridges, t as InProcessCartEventBus } from "../internal-event-bus-DhQKi9KS.mjs";
|
|
3
3
|
export { type CartBridges, type CartConfig, type CartConfigShape, type CartEngine, InProcessCartEventBus, cartConfigSchema, createCart, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema };
|
package/dist/engine/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as InProcessCartEventBus, t as createCart } from "../create-cart-
|
|
1
|
+
import { n as InProcessCartEventBus, t as createCart } from "../create-cart-BeW0xAqD.mjs";
|
|
2
2
|
import { cartConfigSchema, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema } from "./cart-config.schema.mjs";
|
|
3
3
|
export { InProcessCartEventBus, cartConfigSchema, createCart, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema };
|
|
@@ -102,6 +102,21 @@ declare class NotFoundError extends CartError {
|
|
|
102
102
|
}
|
|
103
103
|
//#endregion
|
|
104
104
|
//#region src/domain/errors/price-changed.error.d.ts
|
|
105
|
+
/**
|
|
106
|
+
* Structured context carried on `PriceChangedError` — includes the CURRENT
|
|
107
|
+
* pricing so hosts re-display without another fetch. Formalized so a
|
|
108
|
+
* refactor of the shape is a compile error here instead of a silent client
|
|
109
|
+
* break.
|
|
110
|
+
*/
|
|
111
|
+
interface PriceChangedErrorContext extends Record<string, unknown> {
|
|
112
|
+
expectedHash: string;
|
|
113
|
+
actualHash: string;
|
|
114
|
+
draftPublicId?: string;
|
|
115
|
+
currentPricing?: {
|
|
116
|
+
lines: ReadonlyArray<Record<string, unknown>>;
|
|
117
|
+
totals: Record<string, unknown>;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
105
120
|
/**
|
|
106
121
|
* The stored pricing snapshot's hash does not match the `expectedPricingHash`
|
|
107
122
|
* the client supplied when initiating checkout. Fired from the cheap hash
|
|
@@ -119,7 +134,7 @@ declare class PriceChangedError extends CartError {
|
|
|
119
134
|
readonly code = "cart/price_changed";
|
|
120
135
|
readonly category: CartErrorCategory;
|
|
121
136
|
readonly retryable = true;
|
|
122
|
-
constructor(expectedHash: string, actualHash: string, context?:
|
|
137
|
+
constructor(expectedHash: string, actualHash: string, context?: Omit<PriceChangedErrorContext, 'expectedHash' | 'actualHash'>);
|
|
123
138
|
}
|
|
124
139
|
//#endregion
|
|
125
140
|
//#region src/domain/errors/reservation.error.d.ts
|
|
@@ -229,4 +244,32 @@ declare class StateTransitionError extends CartError {
|
|
|
229
244
|
constructor(checkoutId: string, from: CheckoutState, to: CheckoutState);
|
|
230
245
|
}
|
|
231
246
|
//#endregion
|
|
232
|
-
|
|
247
|
+
//#region src/domain/errors/unmanaged-session.error.d.ts
|
|
248
|
+
/**
|
|
249
|
+
* The caller owns the outer transaction (`ctx.session`) but gave cart no way
|
|
250
|
+
* to coordinate event publishing:
|
|
251
|
+
*
|
|
252
|
+
* - no `OutboxStore` (durable row that commits WITH the transaction), AND
|
|
253
|
+
* - no `[PENDING_EVENTS]` queue (post-commit in-process flush).
|
|
254
|
+
*
|
|
255
|
+
* Publishing to in-process subscribers mid-transaction would leak ghost
|
|
256
|
+
* events on rollback, and silently dropping the event loses it entirely —
|
|
257
|
+
* both are worse than failing fast. Safe patterns:
|
|
258
|
+
*
|
|
259
|
+
* 1. `engine.withTransaction(ctx, (txCtx) => …)` — cart owns the unit of
|
|
260
|
+
* work, queues events, and flushes them after commit.
|
|
261
|
+
* 2. Wire an `outbox` — the row commits with your transaction and the
|
|
262
|
+
* host relay delivers post-commit.
|
|
263
|
+
* 3. Manage it yourself: attach `{ ...ctx, [PENDING_EVENTS]: queue }` and
|
|
264
|
+
* call `flushPending(transport, queue)` after your commit.
|
|
265
|
+
*
|
|
266
|
+
* `PENDING_EVENTS` and `flushPending` are exported from '@classytic/cart'.
|
|
267
|
+
*/
|
|
268
|
+
declare class UnmanagedSessionError extends CartError {
|
|
269
|
+
readonly code = "cart/transaction_unmanaged_session";
|
|
270
|
+
readonly category: CartErrorCategory;
|
|
271
|
+
readonly retryable = false;
|
|
272
|
+
constructor();
|
|
273
|
+
}
|
|
274
|
+
//#endregion
|
|
275
|
+
export { IdempotencyStorageError as a, ReservationError as c, KindError as d, UnknownKindError as f, CartErrorCategory as h, IdempotencyBusyError as i, PriceChangedError as l, CartError as m, StateTransitionError as n, SagaError as o, ConcurrencyError as p, StaleQuoteError as r, SagaFailurePhase as s, UnmanagedSessionError as t, NotFoundError as u };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,21 +1,32 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as IdempotencyStorageError, c as ReservationError, d as KindError, f as UnknownKindError, h as CartErrorCategory, i as IdempotencyBusyError, l as PriceChangedError, m as CartError, n as StateTransitionError, o as SagaError, p as ConcurrencyError, r as StaleQuoteError, s as SagaFailurePhase, t as UnmanagedSessionError, u as NotFoundError } from "./index-BB0XzkXF.mjs";
|
|
2
2
|
import { n as DraftStatus, r as ReservationStatus, t as CheckoutState } from "./cart-status.vo-CNJw4aaB.mjs";
|
|
3
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-CBt9fSYh.mjs";
|
|
4
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-BxDJhtTM.mjs";
|
|
5
|
-
import { C as OperationContext, S as BridgeStatus, T as
|
|
6
|
-
import { a as Adjustment, i as Checkout, n as IdempotencyRecord, r as Draft, t as Reservation } from "./reservation.entity-
|
|
7
|
-
import { a as SagaStepFn, c as CheckoutStepNumber, i as SagaDependencies, n as CHECKOUT_STATE_TRANSITIONS, o as CheckoutFlowState, r as isLegalCheckoutTransition, s as CheckoutStep } from "./state-transitions-
|
|
8
|
-
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-
|
|
9
|
-
import { a as IdempotencyReplay, c as LineItem, i as IdempotencyIdentity, n as createKindRegistry, o as OperationName, r as CART_REF_NEW, s as TotalsSnapshot, t as KindRegistry } from "./kind-registry-
|
|
5
|
+
import { C as OperationContext, E as PricingSnapshot, S as BridgeStatus, T as PricedLine, _ as CartSnapshot, a as ShippingQuote, b as Address, c as TaxBridge, d as InventoryBridge, f as ReservationRef, g as AdjustmentSpec, h as ProductSummary, i as ShippingMethod, l as TaxCalculationRequest, m as CatalogBridge, n as systemClock, o as ShippingQuoteRequest, p as ReservationRequest, r as ShippingBridge, s as TaxBreakdown, t as ClockPort, u as TaxCalculationResult, v as PromotionResult, w as PENDING_EVENTS, x as BridgeRef, y as PromotionsBridge } from "./clock.port-CNu2wgdA.mjs";
|
|
6
|
+
import { a as Adjustment, i as Checkout, n as IdempotencyRecord, r as Draft, t as Reservation } from "./reservation.entity-DLMxgpLE.mjs";
|
|
7
|
+
import { a as SagaStepFn, c as CheckoutStepNumber, i as SagaDependencies, n as CHECKOUT_STATE_TRANSITIONS, o as CheckoutFlowState, r as isLegalCheckoutTransition, s as CheckoutStep } from "./state-transitions-D19wZe-w.mjs";
|
|
8
|
+
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-B1mU1iJp.mjs";
|
|
9
|
+
import { a as IdempotencyReplay, c as LineItem, i as IdempotencyIdentity, n as createKindRegistry, o as OperationName, r as CART_REF_NEW, s as TotalsSnapshot, t as KindRegistry } from "./kind-registry-DG2iCCH1.mjs";
|
|
10
10
|
import { n as createCounterIdPort, r as cryptoIdPort, t as IdPort } from "./id.port-DitjeoHg.mjs";
|
|
11
|
-
import { CartConfigShape, cartConfigSchema, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema } from "./engine/cart-config.schema.mjs";
|
|
12
|
-
import { C as
|
|
13
|
-
import { a as timeslotKind, c as skuKind, d as serviceFeeKind, f as serviceFeePayloadSchema, g as bundlePayloadSchema, h as bundleKind, i as TimeslotPayload, l as skuPayloadSchema, m as BundlePayload, n as variantKind, o as timeslotPayloadSchema, p as BundleComponent, r as variantPayloadSchema, s as SkuPayload, t as VariantPayload, u as ServiceFeePayload } from "./variant.kind-
|
|
11
|
+
import { CartConfigShape, cartConfigSchema, checkoutConfigSchema, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema } from "./engine/cart-config.schema.mjs";
|
|
12
|
+
import { C as createReservationModel, D as createDraftModel, E as DraftDocument, O as CheckoutDocument, S as ReservationDocument, T as createIdempotencyModel, _ as CartEventPublisherDeps, a as CartEngine, b as CreateCartModelsOptions, c as CreateCartRepositoriesConfig, d as IdempotencyRepository, f as CheckoutRepository, g as DraftRepositoryDeps, h as DraftRepository, i as CartConfig, k as createCheckoutModel, l as createCartRepositories, m as DEFAULT_STALE_OPEN_CHECKOUT_MS, n as createCart, o as CartRepositories, p as CheckoutRepositoryDeps, r as CartBridges, s as CartRepositoryPluginBundle, t as InProcessCartEventBus, u as ReservationRepository, v as CartModelName, w as IdempotencyDocument, x as createCartModels, y as CartModels } from "./internal-event-bus-DhQKi9KS.mjs";
|
|
13
|
+
import { a as timeslotKind, c as skuKind, d as serviceFeeKind, f as serviceFeePayloadSchema, g as bundlePayloadSchema, h as bundleKind, i as TimeslotPayload, l as skuPayloadSchema, m as BundlePayload, n as variantKind, o as timeslotPayloadSchema, p as BundleComponent, r as variantPayloadSchema, s as SkuPayload, t as VariantPayload, u as ServiceFeePayload } from "./variant.kind-q-yv-vnQ.mjs";
|
|
14
14
|
import { Money, addMoney, fromMajor, money, multiplyMoney, subtractMoney, sumMoney, toMajor } from "@classytic/primitives/money";
|
|
15
|
-
import { EventHandler, EventTransport, PublishManyResult } from "@classytic/primitives/events";
|
|
16
|
-
import { Schema } from "mongoose";
|
|
15
|
+
import { DomainEvent, EventHandler, EventTransport, EventTransport as EventTransport$1, PublishManyResult } from "@classytic/primitives/events";
|
|
16
|
+
import { Connection, Schema } from "mongoose";
|
|
17
17
|
import { ResolvedTenantConfig, TenantConfig } from "@classytic/repo-core/tenant";
|
|
18
18
|
|
|
19
|
+
//#region src/engine/run-unit.d.ts
|
|
20
|
+
/**
|
|
21
|
+
* Drain a `[PENDING_EVENTS]` queue through a transport after commit,
|
|
22
|
+
* swallowing per-event errors (durable delivery is the outbox's job).
|
|
23
|
+
* Hosts composing their own outer transaction call this after commit;
|
|
24
|
+
* most should use `engine.withTransaction(ctx, fn)` instead.
|
|
25
|
+
*/
|
|
26
|
+
declare function flushPending(eventTransport: EventTransport$1 | undefined, events: DomainEvent[], logger?: {
|
|
27
|
+
error(message: string, ...args: unknown[]): void;
|
|
28
|
+
}): Promise<void>;
|
|
29
|
+
//#endregion
|
|
19
30
|
//#region src/services/abandonment.service.d.ts
|
|
20
31
|
/**
|
|
21
32
|
* Abandonment query primitives. Hosts call these from their own cron
|
|
@@ -50,9 +61,35 @@ declare function markAbandoned(opts: {
|
|
|
50
61
|
* active draft on login.
|
|
51
62
|
*
|
|
52
63
|
* Merge strategy: iterate the source's lines. For each line, if a line
|
|
53
|
-
* with the same `(kind, skuRef)`
|
|
54
|
-
* target's quantity. Otherwise,
|
|
55
|
-
* from the source since they're
|
|
64
|
+
* with the same merge key (kind-defined, `(kind, skuRef)` fallback)
|
|
65
|
+
* exists in the target, increment the target's quantity. Otherwise,
|
|
66
|
+
* append. Display snapshots carry over from the source since they're
|
|
67
|
+
* already captured.
|
|
68
|
+
*
|
|
69
|
+
* ## Concurrency — double-CAS, no lost updates
|
|
70
|
+
*
|
|
71
|
+
* Both drafts can be mutated concurrently (guest tab still open, user
|
|
72
|
+
* adding from another device). The merge is therefore guarded by TWO
|
|
73
|
+
* compare-and-set writes, ordered so a retry can never double-apply:
|
|
74
|
+
*
|
|
75
|
+
* 1. The SOURCE is retired first — `markAbandoned` with
|
|
76
|
+
* `expectedVersion` CAS-pinned to the read that captured its lines.
|
|
77
|
+
* A concurrent add-to-cart on the source bumps `version`, the CAS
|
|
78
|
+
* misses, and the whole merge retries from a fresh read (bounded).
|
|
79
|
+
* Once this write lands, the captured source line set is final.
|
|
80
|
+
* 2. The TARGET write — `replaceLines` CAS-pinned (`expectedVersion`)
|
|
81
|
+
* to the target read the merged line set was computed from. A
|
|
82
|
+
* concurrent add-to-cart on the target surfaces as
|
|
83
|
+
* `ConcurrencyError`; the merge re-reads the target, re-merges the
|
|
84
|
+
* (already-frozen) source lines, and retries — so the concurrent
|
|
85
|
+
* line survives. Because the source was retired exactly once in
|
|
86
|
+
* step 1, target retries can never double-count source quantities.
|
|
87
|
+
*
|
|
88
|
+
* Hosts that need the two writes to be all-or-nothing (no
|
|
89
|
+
* retired-source/unmerged-lines window on a crash between steps) can
|
|
90
|
+
* pass a Mongoose `ctx.session` opened on a transaction — both writes
|
|
91
|
+
* thread it — at the cost of requiring a replica set and a configured
|
|
92
|
+
* outbox (see docs/host-integration.md).
|
|
56
93
|
*
|
|
57
94
|
* After merging, the source draft is marked `abandoned` so it's no
|
|
58
95
|
* longer active.
|
|
@@ -115,4 +152,4 @@ type CartTenantInput = TenantConfig | boolean | {
|
|
|
115
152
|
/** Re-export of primitives' resolved shape under the legacy name. */
|
|
116
153
|
type ResolvedTenant = ResolvedTenantConfig;
|
|
117
154
|
//#endregion
|
|
118
|
-
export { type Address, type Adjustment, type AdjustmentSpec, type BridgeRef, type BridgeStatus, type BundleComponent, type BundlePayload, CART_REF_NEW, CHECKOUT_STATE_TRANSITIONS, type CartAggregateType, type CartBridges, type CartConfig, type CartConfigShape, type CartDomainEvent, type CartEngine, CartError, type CartErrorCategory, type CartEventAggregate, type CartEventDefinition, type CartEventDefinitionInput, type CartEventMap, type CartEventMeta, type CartEventName, type CartEventPayload, type CartEventPublisherDeps, type CartEventRegistry, CartEvents, type CartModelName, type CartModels, type CartRepositories, type CartRepositoryPluginBundle, type CartSnapshot, type CartTenantInput, type CatalogBridge, type Checkout, type CheckoutDocument, type CheckoutFlowState, CheckoutRepository, type CheckoutRepositoryDeps, type CheckoutState, CheckoutStep, type CheckoutStepNumber, type ClockPort, ConcurrencyError, type CreateCartModelsOptions, type CreateCartRepositoriesConfig, type Draft, type DraftDocument, DraftRepository, type DraftRepositoryDeps, type DraftStatus, type EventHandler, type EventSchema, type EventSchemaProperty, type EventTransport, type EventValidationResult, type EventValidator, type IdPort, IdempotencyBusyError, type IdempotencyDocument, type IdempotencyIdentity, type IdempotencyRecord, type IdempotencyReplay, IdempotencyRepository, IdempotencyStorageError, InProcessCartEventBus, InvalidOutboxEventError, type InventoryBridge, type KindBridges, type KindContext, KindError, type KindRegistry, type LineDisplay, type LineItem, type LineKind, type LineLike, MemoryOutboxStore, type Money, NotFoundError, type OperationContext, type OperationName, type OutboxAcknowledgeOptions, type OutboxClaimOptions, type OutboxErrorInfo, type OutboxFailOptions, type OutboxFailureContext, type OutboxFailureDecision, type OutboxFailurePolicy, OutboxOwnershipError, type OutboxStore, type OutboxStoreWriteOptions, type OutboxWriteOptions, type PayloadOf, PriceChangedError, type PricedLine, type PricingSnapshot, type ProductSummary, type PromotionResult, type PromotionsBridge, type PublishManyResult, type Reservation, type ReservationDocument, ReservationError, type ReservationRef, ReservationRepository, type ReservationRequest, type ReservationStatus, type ResolvedTenant, type RevalidationResult, type SagaDependencies, SagaError, type SagaFailurePhase, type SagaStepFn, type ServiceFeePayload, type ShippingBridge, type ShippingMethod, type ShippingQuote, type ShippingQuoteRequest, type SkuPayload, type StaleBehavior, StaleQuoteError, type StaleTrigger, StateTransitionError, type TaxBreakdown, type TaxBridge, type TaxCalculationRequest, type TaxCalculationResult, type TimeslotPayload, type TotalsSnapshot, UnknownKindError, type ValidityPolicy, type VariantPayload, addMoney, bundleKind, bundlePayloadSchema, cartConfigSchema, cartEventDefinitions, cartEventsByName, createCart, createCartEvent, createCartEventRegistry, createCartModels, createCartRepositories, createCheckoutModel, createCounterIdPort, createDraftModel, createIdempotencyModel, createKindRegistry, createReservationModel, cryptoIdPort, defineCartEvent, findAbandonedDrafts, fromMajor, idempotencyConfigSchema, isLegalCheckoutTransition, markAbandoned, mergeDrafts, money, multiplyMoney, reservationConfigSchema, runPricing, scopeConfigSchema, serviceFeeKind, serviceFeePayloadSchema, skuKind, skuPayloadSchema, subtractMoney, sumMoney, systemClock, timeslotKind, timeslotPayloadSchema, toMajor, variantKind, variantPayloadSchema };
|
|
155
|
+
export { type Address, type Adjustment, type AdjustmentSpec, type BridgeRef, type BridgeStatus, type BundleComponent, type BundlePayload, CART_REF_NEW, CHECKOUT_STATE_TRANSITIONS, type CartAggregateType, type CartBridges, type CartConfig, type CartConfigShape, type CartDomainEvent, type CartEngine, CartError, type CartErrorCategory, type CartEventAggregate, type CartEventDefinition, type CartEventDefinitionInput, type CartEventMap, type CartEventMeta, type CartEventName, type CartEventPayload, type CartEventPublisherDeps, type CartEventRegistry, CartEvents, type CartModelName, type CartModels, type CartRepositories, type CartRepositoryPluginBundle, type CartSnapshot, type CartTenantInput, type CatalogBridge, type Checkout, type CheckoutDocument, type CheckoutFlowState, CheckoutRepository, type CheckoutRepositoryDeps, type CheckoutState, CheckoutStep, type CheckoutStepNumber, type ClockPort, ConcurrencyError, type CreateCartModelsOptions, type CreateCartRepositoriesConfig, DEFAULT_STALE_OPEN_CHECKOUT_MS, type Draft, type DraftDocument, DraftRepository, type DraftRepositoryDeps, type DraftStatus, type EventHandler, type EventSchema, type EventSchemaProperty, type EventTransport, type EventValidationResult, type EventValidator, type IdPort, IdempotencyBusyError, type IdempotencyDocument, type IdempotencyIdentity, type IdempotencyRecord, type IdempotencyReplay, IdempotencyRepository, IdempotencyStorageError, InProcessCartEventBus, InvalidOutboxEventError, type InventoryBridge, type KindBridges, type KindContext, KindError, type KindRegistry, type LineDisplay, type LineItem, type LineKind, type LineLike, MemoryOutboxStore, type Money, NotFoundError, type OperationContext, type OperationName, type OutboxAcknowledgeOptions, type OutboxClaimOptions, type OutboxErrorInfo, type OutboxFailOptions, type OutboxFailureContext, type OutboxFailureDecision, type OutboxFailurePolicy, OutboxOwnershipError, type OutboxStore, type OutboxStoreWriteOptions, type OutboxWriteOptions, PENDING_EVENTS, type PayloadOf, PriceChangedError, type PricedLine, type PricingSnapshot, type ProductSummary, type PromotionResult, type PromotionsBridge, type PublishManyResult, type Reservation, type ReservationDocument, ReservationError, type ReservationRef, ReservationRepository, type ReservationRequest, type ReservationStatus, type ResolvedTenant, type RevalidationResult, type SagaDependencies, SagaError, type SagaFailurePhase, type SagaStepFn, type ServiceFeePayload, type ShippingBridge, type ShippingMethod, type ShippingQuote, type ShippingQuoteRequest, type SkuPayload, type StaleBehavior, StaleQuoteError, type StaleTrigger, StateTransitionError, type TaxBreakdown, type TaxBridge, type TaxCalculationRequest, type TaxCalculationResult, type TimeslotPayload, type TotalsSnapshot, UnknownKindError, UnmanagedSessionError, type ValidityPolicy, type VariantPayload, addMoney, bundleKind, bundlePayloadSchema, cartConfigSchema, cartEventDefinitions, cartEventsByName, checkoutConfigSchema, createCart, createCartEvent, createCartEventRegistry, createCartModels, createCartRepositories, createCheckoutModel, createCounterIdPort, createDraftModel, createIdempotencyModel, createKindRegistry, createReservationModel, cryptoIdPort, defineCartEvent, findAbandonedDrafts, flushPending, fromMajor, idempotencyConfigSchema, isLegalCheckoutTransition, markAbandoned, mergeDrafts, money, multiplyMoney, reservationConfigSchema, runPricing, scopeConfigSchema, serviceFeeKind, serviceFeePayloadSchema, skuKind, skuPayloadSchema, subtractMoney, sumMoney, systemClock, timeslotKind, timeslotPayloadSchema, toMajor, variantKind, variantPayloadSchema };
|
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { t as CART_REF_NEW } from "./idempotency-key.vo-D0lJsvGn.mjs";
|
|
2
2
|
import { t as CartError } from "./cart.error-BwWy4RlY.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { a as ConcurrencyError, i as NotFoundError, n as StaleQuoteError, r as PriceChangedError, t as UnmanagedSessionError } from "./unmanaged-session.error-C9Z1Yh9j.mjs";
|
|
4
4
|
import { n as UnknownKindError, t as KindError } from "./kind.error-DIaJpdUb.mjs";
|
|
5
5
|
import { i as ReservationError, n as IdempotencyStorageError, r as SagaError, t as IdempotencyBusyError } from "./errors-7Pd0yATM.mjs";
|
|
6
6
|
import { t as StateTransitionError } from "./state-transition.error-2fRLh3p0.mjs";
|
|
7
7
|
import { n as CartEvents, t as createCartEvent } from "./domain-event-CIEORKF6.mjs";
|
|
8
8
|
import { a as cartEventsByName, i as cartEventDefinitions, n as MemoryOutboxStore, o as createCartEventRegistry, r as OutboxOwnershipError, s as defineCartEvent, t as InvalidOutboxEventError } from "./outbox-store-CWW8ppxS.mjs";
|
|
9
9
|
import { n as cryptoIdPort, r as systemClock, t as createCounterIdPort } from "./id.port-BhbFZJPm.mjs";
|
|
10
|
-
import { t as
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { a as skuKind, c as serviceFeePayloadSchema, i as timeslotPayloadSchema, l as bundleKind, n as variantPayloadSchema, o as skuPayloadSchema, r as timeslotKind, s as serviceFeeKind, t as variantKind, u as bundlePayloadSchema } from "./variant.kind-
|
|
14
|
-
import { cartConfigSchema, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema } from "./engine/cart-config.schema.mjs";
|
|
10
|
+
import { a as IdempotencyRepository, c as CheckoutRepository, d as createReservationModel, f as createIdempotencyModel, g as PENDING_EVENTS, h as flushPending, i as ReservationRepository, l as DEFAULT_STALE_OPEN_CHECKOUT_MS, m as createCheckoutModel, n as InProcessCartEventBus, o as DraftRepository, p as createDraftModel, r as createCartRepositories, s as runPricing, t as createCart, u as createCartModels } from "./create-cart-BeW0xAqD.mjs";
|
|
11
|
+
import { t as createKindRegistry } from "./kind-registry-Bvrj3P1Q.mjs";
|
|
12
|
+
import { i as CheckoutStep, n as CHECKOUT_STATE_TRANSITIONS, r as isLegalCheckoutTransition } from "./state-transitions-Defw8gAt.mjs";
|
|
13
|
+
import { a as skuKind, c as serviceFeePayloadSchema, i as timeslotPayloadSchema, l as bundleKind, n as variantPayloadSchema, o as skuPayloadSchema, r as timeslotKind, s as serviceFeeKind, t as variantKind, u as bundlePayloadSchema } from "./variant.kind-BHiivO9B.mjs";
|
|
14
|
+
import { cartConfigSchema, checkoutConfigSchema, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema } from "./engine/cart-config.schema.mjs";
|
|
15
15
|
import { addMoney, fromMajor, money, multiplyMoney, subtractMoney, sumMoney, toMajor } from "@classytic/primitives/money";
|
|
16
16
|
//#region src/services/abandonment.service.ts
|
|
17
17
|
/**
|
|
@@ -40,6 +40,7 @@ async function findAbandonedDrafts(opts) {
|
|
|
40
40
|
}, {
|
|
41
41
|
organizationId: ctx.organizationId,
|
|
42
42
|
skipTenant: ctx.skipTenant,
|
|
43
|
+
signal: ctx.signal,
|
|
43
44
|
lean: true
|
|
44
45
|
})).data;
|
|
45
46
|
}
|
|
@@ -54,40 +55,96 @@ async function markAbandoned(opts) {
|
|
|
54
55
|
}
|
|
55
56
|
//#endregion
|
|
56
57
|
//#region src/services/merge.service.ts
|
|
58
|
+
/** Bounded retries for each CAS-guarded phase of the merge. */
|
|
59
|
+
const MAX_MERGE_ATTEMPTS = 3;
|
|
57
60
|
/**
|
|
58
61
|
* Merge a guest (session-scoped) draft into an authenticated user's
|
|
59
62
|
* active draft on login.
|
|
60
63
|
*
|
|
61
64
|
* Merge strategy: iterate the source's lines. For each line, if a line
|
|
62
|
-
* with the same `(kind, skuRef)`
|
|
63
|
-
* target's quantity. Otherwise,
|
|
64
|
-
* from the source since they're
|
|
65
|
+
* with the same merge key (kind-defined, `(kind, skuRef)` fallback)
|
|
66
|
+
* exists in the target, increment the target's quantity. Otherwise,
|
|
67
|
+
* append. Display snapshots carry over from the source since they're
|
|
68
|
+
* already captured.
|
|
69
|
+
*
|
|
70
|
+
* ## Concurrency — double-CAS, no lost updates
|
|
71
|
+
*
|
|
72
|
+
* Both drafts can be mutated concurrently (guest tab still open, user
|
|
73
|
+
* adding from another device). The merge is therefore guarded by TWO
|
|
74
|
+
* compare-and-set writes, ordered so a retry can never double-apply:
|
|
75
|
+
*
|
|
76
|
+
* 1. The SOURCE is retired first — `markAbandoned` with
|
|
77
|
+
* `expectedVersion` CAS-pinned to the read that captured its lines.
|
|
78
|
+
* A concurrent add-to-cart on the source bumps `version`, the CAS
|
|
79
|
+
* misses, and the whole merge retries from a fresh read (bounded).
|
|
80
|
+
* Once this write lands, the captured source line set is final.
|
|
81
|
+
* 2. The TARGET write — `replaceLines` CAS-pinned (`expectedVersion`)
|
|
82
|
+
* to the target read the merged line set was computed from. A
|
|
83
|
+
* concurrent add-to-cart on the target surfaces as
|
|
84
|
+
* `ConcurrencyError`; the merge re-reads the target, re-merges the
|
|
85
|
+
* (already-frozen) source lines, and retries — so the concurrent
|
|
86
|
+
* line survives. Because the source was retired exactly once in
|
|
87
|
+
* step 1, target retries can never double-count source quantities.
|
|
88
|
+
*
|
|
89
|
+
* Hosts that need the two writes to be all-or-nothing (no
|
|
90
|
+
* retired-source/unmerged-lines window on a crash between steps) can
|
|
91
|
+
* pass a Mongoose `ctx.session` opened on a transaction — both writes
|
|
92
|
+
* thread it — at the cost of requiring a replica set and a configured
|
|
93
|
+
* outbox (see docs/host-integration.md).
|
|
65
94
|
*
|
|
66
95
|
* After merging, the source draft is marked `abandoned` so it's no
|
|
67
96
|
* longer active.
|
|
68
97
|
*/
|
|
69
98
|
async function mergeDrafts(opts) {
|
|
70
99
|
const { repo, sourcePublicId, targetActorRef, ctx } = opts;
|
|
71
|
-
const source = await repo.findByPublicId(sourcePublicId, ctx);
|
|
72
|
-
if (!source || source.status !== "active") throw new Error(`Source draft '${sourcePublicId}' not found or not active`);
|
|
73
100
|
const targetCtx = {
|
|
74
101
|
...ctx,
|
|
75
102
|
actorRef: targetActorRef
|
|
76
103
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
104
|
+
let sourceLines = null;
|
|
105
|
+
let lastError;
|
|
106
|
+
for (let attempt = 0; attempt < MAX_MERGE_ATTEMPTS; attempt++) {
|
|
107
|
+
const source = await repo.findByPublicId(sourcePublicId, ctx);
|
|
108
|
+
if (!source || source.status !== "active") throw new Error(`Source draft '${sourcePublicId}' not found or not active`);
|
|
109
|
+
if (!await repo.findActiveByActor(targetActorRef, targetCtx)) try {
|
|
110
|
+
return await repo.updateWithVersion(source._id, source.version, {
|
|
111
|
+
actorRef: targetActorRef,
|
|
112
|
+
actorKind: "user"
|
|
113
|
+
}, ctx);
|
|
114
|
+
} catch (err) {
|
|
115
|
+
if (err instanceof ConcurrencyError) {
|
|
116
|
+
lastError = err;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
throw err;
|
|
120
|
+
}
|
|
121
|
+
if (!await repo.markAbandoned(source._id, ctx, { expectedVersion: source.version })) {
|
|
122
|
+
lastError = new ConcurrencyError("draft", source.version, String(source._id));
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
sourceLines = source.lines;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
if (!sourceLines) throw lastError;
|
|
129
|
+
for (let attempt = 0; attempt < MAX_MERGE_ATTEMPTS; attempt++) {
|
|
130
|
+
const target = await repo.findActiveByActor(targetActorRef, targetCtx);
|
|
131
|
+
if (!target) throw new Error(`Target draft for actor '${targetActorRef}' disappeared during merge of '${sourcePublicId}'`);
|
|
132
|
+
const mergedLines = repo.mergeLines(target.lines, sourceLines);
|
|
133
|
+
try {
|
|
134
|
+
return await repo.replaceLines({
|
|
135
|
+
draftPublicId: target.publicId,
|
|
136
|
+
lines: mergedLines,
|
|
137
|
+
expectedVersion: target.version
|
|
138
|
+
}, targetCtx);
|
|
139
|
+
} catch (err) {
|
|
140
|
+
if (err instanceof ConcurrencyError) {
|
|
141
|
+
lastError = err;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
throw err;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
throw lastError;
|
|
91
148
|
}
|
|
92
149
|
//#endregion
|
|
93
|
-
export { CART_REF_NEW, CHECKOUT_STATE_TRANSITIONS, CartError, CartEvents, CheckoutRepository, CheckoutStep, ConcurrencyError, DraftRepository, IdempotencyBusyError, IdempotencyRepository, IdempotencyStorageError, InProcessCartEventBus, InvalidOutboxEventError, KindError, MemoryOutboxStore, NotFoundError, OutboxOwnershipError, PriceChangedError, ReservationError, ReservationRepository, SagaError, StaleQuoteError, StateTransitionError, UnknownKindError, addMoney, bundleKind, bundlePayloadSchema, cartConfigSchema, cartEventDefinitions, cartEventsByName, createCart, createCartEvent, createCartEventRegistry, createCartModels, createCartRepositories, createCheckoutModel, createCounterIdPort, createDraftModel, createIdempotencyModel, createKindRegistry, createReservationModel, cryptoIdPort, defineCartEvent, findAbandonedDrafts, fromMajor, idempotencyConfigSchema, isLegalCheckoutTransition, markAbandoned, mergeDrafts, money, multiplyMoney, reservationConfigSchema, runPricing, scopeConfigSchema, serviceFeeKind, serviceFeePayloadSchema, skuKind, skuPayloadSchema, subtractMoney, sumMoney, systemClock, timeslotKind, timeslotPayloadSchema, toMajor, variantKind, variantPayloadSchema };
|
|
150
|
+
export { CART_REF_NEW, CHECKOUT_STATE_TRANSITIONS, CartError, CartEvents, CheckoutRepository, CheckoutStep, ConcurrencyError, DEFAULT_STALE_OPEN_CHECKOUT_MS, DraftRepository, IdempotencyBusyError, IdempotencyRepository, IdempotencyStorageError, InProcessCartEventBus, InvalidOutboxEventError, KindError, MemoryOutboxStore, NotFoundError, OutboxOwnershipError, PENDING_EVENTS, PriceChangedError, ReservationError, ReservationRepository, SagaError, StaleQuoteError, StateTransitionError, UnknownKindError, UnmanagedSessionError, addMoney, bundleKind, bundlePayloadSchema, cartConfigSchema, cartEventDefinitions, cartEventsByName, checkoutConfigSchema, createCart, createCartEvent, createCartEventRegistry, createCartModels, createCartRepositories, createCheckoutModel, createCounterIdPort, createDraftModel, createIdempotencyModel, createKindRegistry, createReservationModel, cryptoIdPort, defineCartEvent, findAbandonedDrafts, flushPending, fromMajor, idempotencyConfigSchema, isLegalCheckoutTransition, markAbandoned, mergeDrafts, money, multiplyMoney, reservationConfigSchema, runPricing, scopeConfigSchema, serviceFeeKind, serviceFeePayloadSchema, skuKind, skuPayloadSchema, subtractMoney, sumMoney, systemClock, timeslotKind, timeslotPayloadSchema, toMajor, variantKind, variantPayloadSchema };
|