@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/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,89 @@
|
|
|
3
3
|
Format based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
4
4
|
adhering to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
5
5
|
|
|
6
|
+
## [0.2.1] - 2026-07-02
|
|
7
|
+
|
|
8
|
+
### Changed (behavioral) — 2026-07-05 addendum
|
|
9
|
+
|
|
10
|
+
- **`commit()` is crash-retry convergent.** The finalize CAS runs first and
|
|
11
|
+
its tail (`markConverted` on the draft + the `cart.checkout.committed`
|
|
12
|
+
event) is non-atomic — a crash in between left the draft looking live
|
|
13
|
+
(re-checkout → duplicate order risk) with NO retry path, because a second
|
|
14
|
+
`commit()` failed the `finalized → finalized` state assertion. A retry
|
|
15
|
+
with the SAME `externalRef` (or none) now re-runs both idempotent tails
|
|
16
|
+
and returns the finalized checkout; a DIFFERENT `externalRef` throws
|
|
17
|
+
`ConcurrencyError`. `cart.checkout.committed` delivery is at-least-once —
|
|
18
|
+
subscribers must already dedupe by `checkoutId`.
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
|
|
22
|
+
- **`engine.withTransaction(ctx, body)`** — unit-of-work wrapper (transaction
|
|
23
|
+
+ post-commit event publish), the contract shared with `@classytic/refit`
|
|
24
|
+
and `@classytic/review`. Events emitted inside the unit are queued under
|
|
25
|
+
`ctx[PENDING_EVENTS]` and flushed to the in-process transport only AFTER
|
|
26
|
+
commit — a rollback or retry can't leak ghost events. New exports:
|
|
27
|
+
`PENDING_EVENTS`, `flushPending`, `UnmanagedSessionError`; new config:
|
|
28
|
+
`allowNonTransactional` (standalone-Mongo dev fallback, explicit opt-in).
|
|
29
|
+
- **Boot capability gate** — `createCart` (full mode) asserts the backend
|
|
30
|
+
declares `capabilities.upsert` (idempotency lease pattern) at engine
|
|
31
|
+
creation instead of failing on the first checkout.
|
|
32
|
+
- **Event-catalog no-drift test** (rule 18) — every `CartEvents` constant
|
|
33
|
+
must have a Zod definition; orphan definitions also fail.
|
|
34
|
+
- **Compensation scenario test** — proves the documented
|
|
35
|
+
`cart.checkout.canceled` → `inventory.release()` host wiring end-to-end.
|
|
36
|
+
- `PriceChangedErrorContext` — formal type for the error's structured
|
|
37
|
+
context (current pricing payload), previously an untyped inline shape.
|
|
38
|
+
|
|
39
|
+
### Changed
|
|
40
|
+
|
|
41
|
+
- **`CartEventPublisher`**: a host-owned `ctx.session` without an outbox now
|
|
42
|
+
throws typed `UnmanagedSessionError` (was a plain `Error`) unless a
|
|
43
|
+
`PENDING_EVENTS` queue is attached; transport publish failures on the
|
|
44
|
+
no-session path are now swallowed and logged per P8 (the domain verb no
|
|
45
|
+
longer fails after its write landed because a transport hiccuped).
|
|
46
|
+
- Safe-integer guard on line-total arithmetic (`unitPrice × quantity`);
|
|
47
|
+
idempotency repo now uses mongokit's `isDuplicateKeyError`; `cancel()`
|
|
48
|
+
and the timeslot kind's `revalidate` carry explicit contracts (host owns
|
|
49
|
+
hold release; validity-window-only revalidation — real slot-locking via
|
|
50
|
+
`@classytic/order`'s `BookingBridge`).
|
|
51
|
+
|
|
52
|
+
## [0.2.0]
|
|
53
|
+
|
|
54
|
+
### Changed
|
|
55
|
+
|
|
56
|
+
- **`pricingHash` is now hex SHA-256** over the same canonical sorted
|
|
57
|
+
line string (was the raw concatenation). The hash is opaque — compare,
|
|
58
|
+
never parse. **Migration:** drafts priced before 0.2.0 carry old-format
|
|
59
|
+
hashes; the first checkout attempt against them raises
|
|
60
|
+
`PriceChangedError` once and the client re-fetches/re-confirms.
|
|
61
|
+
Accepted clean break.
|
|
62
|
+
- **Guest→user merge is now double-CAS atomic.** `mergeDrafts` retires the
|
|
63
|
+
source with a version CAS, then writes the target with a version CAS
|
|
64
|
+
(bounded retries) — a concurrent add-to-cart on either draft is retried
|
|
65
|
+
into the result instead of silently lost. `DraftRepository.markAbandoned`
|
|
66
|
+
gains an optional `{ expectedVersion }`; `replaceLines` gains an
|
|
67
|
+
optional `expectedVersion` input.
|
|
68
|
+
- **Zombie open checkouts self-heal.** `createFromDraft` CAS-expires an
|
|
69
|
+
open checkout older than `checkout.staleOpenCheckoutMs` (new config,
|
|
70
|
+
default 10 min) and creates a fresh one; fresh open checkouts are still
|
|
71
|
+
returned idempotently. `expireStaleOpenCheckouts` remains the bulk cron
|
|
72
|
+
sweep. No TTL deletes — checkout rows stay as audit history.
|
|
73
|
+
- **`PriceChangedError` context now includes `currentPricing`** (per-line
|
|
74
|
+
`lineId`/`quantity`/`unitPrice`/`subtotals` + `totals`) so hosts render
|
|
75
|
+
a price diff without re-fetching the draft.
|
|
76
|
+
- **`ctx.signal` is threaded to every mongokit call** — cancelled requests
|
|
77
|
+
stop at the driver-call boundary (repo-core 0.6 `QueryOptions.signal`).
|
|
78
|
+
- Peer deps: `@classytic/mongokit >= 3.16`, `@classytic/repo-core >= 0.6`.
|
|
79
|
+
|
|
80
|
+
### Added
|
|
81
|
+
|
|
82
|
+
- `checkoutConfigSchema` / `CartConfig.checkout.staleOpenCheckoutMs` and
|
|
83
|
+
`DEFAULT_STALE_OPEN_CHECKOUT_MS` export.
|
|
84
|
+
- Documented host contract: checkout → order → `inventory.commit()`
|
|
85
|
+
(CLAUDE.md "Host responsibilities") — `commit()` intentionally does not
|
|
86
|
+
commit inventory holds.
|
|
87
|
+
- Scenario 10: stale quote → `revalidate()` reprice path (`bundle` kind).
|
|
88
|
+
|
|
6
89
|
## [0.1.0]
|
|
7
90
|
|
|
8
91
|
Initial release. Framework-agnostic universal cart engine — mutable drafts,
|
package/README.md
CHANGED
|
@@ -70,9 +70,19 @@ No modes. No tiers. Pass the bridges you need:
|
|
|
70
70
|
- **Display snapshots** — denormalized on every line at add-time. UI
|
|
71
71
|
reads `line.display.name` directly. Zero `.populate()` calls.
|
|
72
72
|
- **Optimistic concurrency** — `version` field + `ConcurrencyError` on
|
|
73
|
-
stale writes.
|
|
73
|
+
stale writes. Guest→user merge is double-CAS guarded (source retired
|
|
74
|
+
with a version check, target written with a version check, bounded
|
|
75
|
+
retries) so concurrent add-to-carts are never lost.
|
|
76
|
+
- **Pricing hash interlock** — `pricingHash` is an opaque hex SHA-256
|
|
77
|
+
digest of the priced lines; `createFromDraft` rejects a mismatch with
|
|
78
|
+
`PriceChangedError`, whose context carries the current per-line prices
|
|
79
|
+
and totals so the host can render a diff without re-fetching.
|
|
74
80
|
- **Checkout state** — `open → finalized | canceled`. Cart snapshots;
|
|
75
|
-
host commits.
|
|
81
|
+
host commits (and then commits inventory holds — see CLAUDE.md "Host
|
|
82
|
+
responsibilities"). Zombie `open` checkouts self-heal: `createFromDraft`
|
|
83
|
+
CAS-expires any open checkout older than `checkout.staleOpenCheckoutMs`
|
|
84
|
+
(default 10 min) and creates a fresh one; `expireStaleOpenCheckouts`
|
|
85
|
+
remains the bulk cron sweep.
|
|
76
86
|
- **Arc-compatible** — event definitions match Arc structurally, and hosts
|
|
77
87
|
can inject their app-level outbox store for durable event persistence.
|
|
78
88
|
|
|
@@ -163,6 +163,18 @@ interface OperationContext$1 extends Omit<OperationContext, 'organizationId' | '
|
|
|
163
163
|
*/
|
|
164
164
|
[key: string]: unknown;
|
|
165
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Internal: key under which the post-commit event-publish queue is threaded
|
|
168
|
+
* through the context. When set, `CartEventPublisher.emit` APPENDS the event
|
|
169
|
+
* instead of publishing to the transport — the unit-of-work owner flushes
|
|
170
|
+
* the queue after its transaction commits, so a rollback can't leak ghost
|
|
171
|
+
* events to in-process subscribers. Outbox rows stay inside the transaction
|
|
172
|
+
* (the relay reads only committed rows). Same contract as
|
|
173
|
+
* `@classytic/refit` / `@classytic/review`.
|
|
174
|
+
*
|
|
175
|
+
* A Symbol so it never collides with host context fields.
|
|
176
|
+
*/
|
|
177
|
+
declare const PENDING_EVENTS: unique symbol;
|
|
166
178
|
/**
|
|
167
179
|
* Standard status vocabulary returned by every bridge's `status()` probe.
|
|
168
180
|
* See plan §3 — Saga Recovery Contract.
|
|
@@ -552,4 +564,4 @@ interface ClockPort {
|
|
|
552
564
|
/** Default system clock — passes straight through to `new Date()`. */
|
|
553
565
|
declare const systemClock: ClockPort;
|
|
554
566
|
//#endregion
|
|
555
|
-
export { OperationContext$1 as C, BridgeStatus as S,
|
|
567
|
+
export { OperationContext$1 as C, PricingSnapshot as E, BridgeStatus as S, PricedLine as T, CartSnapshot as _, ShippingQuote as a, Address as b, TaxBridge as c, InventoryBridge as d, ReservationRef as f, AdjustmentSpec as g, ProductSummary as h, ShippingMethod as i, TaxCalculationRequest as l, CatalogBridge as m, systemClock as n, ShippingQuoteRequest as o, ReservationRequest as p, ShippingBridge as r, TaxBreakdown as s, ClockPort as t, TaxCalculationResult as u, PromotionResult as v, PENDING_EVENTS as w, BridgeRef as x, PromotionsBridge as y };
|