@classytic/cart 0.3.1 → 1.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 +188 -147
- package/LICENSE +75 -21
- package/dist/{cart-event-catalog-BxDJhtTM.d.mts → cart-event-catalog-Cokx0iOw.d.mts} +1 -2
- package/dist/cart.error-xi5OT4Sz.mjs +52 -0
- package/dist/{clock.port-CNu2wgdA.d.mts → clock.port-DrSBrsit.d.mts} +9 -5
- package/dist/{create-cart-zgAh3UVt.mjs → define-cart-Cr9VMeVc.mjs} +362 -236
- package/dist/domain/errors/index.d.mts +2 -2
- package/dist/domain/errors/index.mjs +6 -6
- package/dist/domain/events/index.d.mts +2 -2
- package/dist/domain/events/index.mjs +2 -2
- package/dist/domain/index.d.mts +14 -11
- package/dist/domain/index.mjs +12 -12
- package/dist/domain/ports/index.d.mts +3 -3
- package/dist/domain/ports/index.mjs +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 +3 -4
- package/dist/engine/cart-config.schema.mjs +7 -7
- package/dist/engine/index.d.mts +3 -3
- package/dist/engine/index.mjs +3 -3
- package/dist/{errors-BNPgUilS.mjs → errors-Dj8itvAh.mjs} +1 -1
- package/dist/{id.port-BhbFZJPm.mjs → id.port-DYAnXbfV.mjs} +1 -1
- package/dist/{index-wh5Q7UY1.d.mts → index-BTSo-RLv.d.mts} +41 -3
- package/dist/index.d.mts +88 -24
- package/dist/index.mjs +195 -14
- package/dist/{internal-event-bus-DFcwV79F.d.mts → internal-event-bus-BA-WrtE0.d.mts} +200 -179
- package/dist/{kind-registry-DG2iCCH1.d.mts → kind-registry-DFvNDb81.d.mts} +3 -5
- package/dist/{kind-registry-Bvrj3P1Q.mjs → kind-registry-DQYqRQZU.mjs} +1 -1
- package/dist/{kind.error-DIaJpdUb.mjs → kind.error-BoyoVjKx.mjs} +1 -1
- package/dist/kinds/index.d.mts +1 -1
- package/dist/kinds/index.mjs +1 -1
- package/dist/{line-kind-B1mU1iJp.d.mts → line-kind-BW2zLNSr.d.mts} +3 -4
- package/dist/line-total-6VJQMjGV.mjs +24 -0
- package/dist/{outbox-store-CBt9fSYh.d.mts → outbox-store-Br7MHuOz.d.mts} +3 -18
- package/dist/{outbox-store-CWW8ppxS.mjs → outbox-store-DLxCPOUN.mjs} +2 -30
- package/dist/{reservation.entity-DLMxgpLE.d.mts → reservation.entity-BEeYbRUY.d.mts} +4 -5
- package/dist/{state-transition.error-2fRLh3p0.mjs → state-transition.error-BssJiRoW.mjs} +1 -1
- package/dist/{state-transitions-D19wZe-w.d.mts → state-transitions-BQ2Nhxnb.d.mts} +14 -11
- package/dist/{state-transitions-Defw8gAt.mjs → state-transitions-wunwhjap.mjs} +1 -1
- package/dist/{unmanaged-session.error-C9Z1Yh9j.mjs → unmanaged-session.error-DIRT2PR3.mjs} +31 -2
- package/dist/{variant.kind-q-yv-vnQ.d.mts → variant.kind-CClf8MTF.d.mts} +3 -3
- package/dist/{variant.kind-BHiivO9B.mjs → variant.kind-NmWSslu-.mjs} +23 -32
- package/package.json +10 -9
- package/dist/cart.error-BwWy4RlY.mjs +0 -27
- package/dist/index-2Ag-54t8.d.mts +0 -1
- /package/dist/{cart-status.vo-CNJw4aaB.d.mts → cart-status.vo-BoVPaSXX.d.mts} +0 -0
- /package/dist/{domain-event-CIEORKF6.mjs → domain-event-DBFsiHNJ.mjs} +0 -0
- /package/dist/{id.port-DitjeoHg.d.mts → id.port-DzgWy8sy.d.mts} +0 -0
- /package/dist/{idempotency-key.vo-D0lJsvGn.mjs → idempotency-key.vo-BoRvSIxx.mjs} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,49 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
Format based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
4
|
-
adhering to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
5
|
-
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Format based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
4
|
+
adhering to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
5
|
+
|
|
6
|
+
## 1.1.0 - 2026-08-17
|
|
7
|
+
|
|
8
|
+
### Changed
|
|
9
|
+
- `cleanup/steps.ts`: bare calendar-date `before` param refused — must be a full ISO instant (prevents silent UTC-midnight misfire in non-UTC deployments)
|
|
10
|
+
- `define-cart`: `resolveCartTenant` wired; tenant injection centralised
|
|
11
|
+
- `inject-tenant` refactored; models and repositories simplified
|
|
12
|
+
|
|
13
|
+
## 1.0.0 - 2026-07-29
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- **License:** relicensed from MIT to the **Classytic Source-Available License** (Community & Commercial). Evaluation/development use remains free; production use now requires a commercial license from Classytic LLC. See `LICENSE`.
|
|
17
|
+
- Major bump marks the license change; versions published before 1.0.0 remain under their original MIT terms.
|
|
18
|
+
|
|
19
|
+
## [0.3.3] — unpublished (2026-07-22)
|
|
20
|
+
|
|
21
|
+
### Changed — event infra consolidated onto `@classytic/primitives/event-infra`
|
|
22
|
+
|
|
23
|
+
- `InProcessCartEventBus` is now a thin subclass of primitives' shared
|
|
24
|
+
`InProcessEventBus` (name `in-process-cart`, `logger: null` — cart's
|
|
25
|
+
silent-swallow dialect preserved: handler errors never propagate OR log).
|
|
26
|
+
Internal delivery detail: subscriptions are now Set-deduped per handler
|
|
27
|
+
across matching patterns (previously per-subscription array order) — no
|
|
28
|
+
cart code subscribes one handler under multiple patterns, so delivery is
|
|
29
|
+
unchanged in practice. `MemoryOutboxStore` is re-exported from
|
|
30
|
+
`@classytic/primitives/event-infra` instead of a local copy (gains
|
|
31
|
+
`all()` / `clear()` test helpers). No public API or event-shape changes.
|
|
32
|
+
- `@classytic/primitives` peer floor raised to `>=0.13.0` (the
|
|
33
|
+
`/event-infra` subpath).
|
|
34
|
+
|
|
35
|
+
## [0.3.2] — unpublished (2026-07-22)
|
|
36
|
+
|
|
37
|
+
### Fixed — `destroy()` was an empty no-op
|
|
38
|
+
|
|
39
|
+
- **`engine.destroy()` now actually tears down**: closes the self-created
|
|
40
|
+
`InProcessCartEventBus` (skipped when the host injected `eventTransport`).
|
|
41
|
+
- `destroy()` follows the fleet ownsBus convention (manufacturing/purchase
|
|
42
|
+
pattern): only what the engine itself created is closed; a host-injected
|
|
43
|
+
transport is the host's to close. Idempotent — a second call is a no-op.
|
|
44
|
+
Mongoose models/connection are untouched (host-owned).
|
|
45
|
+
- Lifecycle coverage in `tests/unit/engine-lifecycle.test.ts` (lite mode).
|
|
46
|
+
|
|
6
47
|
## [0.3.1] — 2026-07-16
|
|
7
48
|
|
|
8
49
|
### Fixed
|
|
@@ -13,145 +54,145 @@ adhering to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
13
54
|
index audit). A dedicated tenant index is still created when a schema
|
|
14
55
|
declares no compounds to prepend. Index-declaration change only.
|
|
15
56
|
|
|
16
|
-
## [0.3.0] — unpublished (2026-07-15)
|
|
17
|
-
|
|
18
|
-
### Changed — kit refresh (peer floors: mongokit >=3.22.0, repo-core >=0.13.0, primitives >=0.11.0)
|
|
19
|
-
|
|
20
|
-
- Verified against the mongokit 3.22 sweep. DEFERRED (design note, not a
|
|
21
|
-
drive-by): checkout `finalize`/`cancel` are assert-then-`updateWithVersion`
|
|
22
|
-
— the version CAS serializes writers, so the window is narrow; converting
|
|
23
|
-
to `applyTransition` (state+version compound CAS) needs a pass that
|
|
24
|
-
preserves the updateWithVersion helper's semantics.
|
|
25
|
-
|
|
26
|
-
## [0.2.1] - 2026-07-02
|
|
27
|
-
|
|
28
|
-
### Changed (behavioral) — 2026-07-05 addendum
|
|
29
|
-
|
|
30
|
-
- **`commit()` is crash-retry convergent.** The finalize CAS runs first and
|
|
31
|
-
its tail (`markConverted` on the draft + the `cart.checkout.committed`
|
|
32
|
-
event) is non-atomic — a crash in between left the draft looking live
|
|
33
|
-
(re-checkout → duplicate order risk) with NO retry path, because a second
|
|
34
|
-
`commit()` failed the `finalized → finalized` state assertion. A retry
|
|
35
|
-
with the SAME `externalRef` (or none) now re-runs both idempotent tails
|
|
36
|
-
and returns the finalized checkout; a DIFFERENT `externalRef` throws
|
|
37
|
-
`ConcurrencyError`. `cart.checkout.committed` delivery is at-least-once —
|
|
38
|
-
subscribers must already dedupe by `checkoutId`.
|
|
39
|
-
|
|
40
|
-
### Added
|
|
41
|
-
|
|
42
|
-
- **`engine.withTransaction(ctx, body)`** — unit-of-work wrapper (transaction
|
|
43
|
-
+ post-commit event publish), the contract shared with `@classytic/refit`
|
|
44
|
-
and `@classytic/review`. Events emitted inside the unit are queued under
|
|
45
|
-
`ctx[PENDING_EVENTS]` and flushed to the in-process transport only AFTER
|
|
46
|
-
commit — a rollback or retry can't leak ghost events. New exports:
|
|
47
|
-
`PENDING_EVENTS`, `flushPending`, `UnmanagedSessionError`; new config:
|
|
48
|
-
`allowNonTransactional` (standalone-Mongo dev fallback, explicit opt-in).
|
|
49
|
-
- **Boot capability gate** — `createCart` (full mode) asserts the backend
|
|
50
|
-
declares `capabilities.upsert` (idempotency lease pattern) at engine
|
|
51
|
-
creation instead of failing on the first checkout.
|
|
52
|
-
- **Event-catalog no-drift test** (rule 18) — every `CartEvents` constant
|
|
53
|
-
must have a Zod definition; orphan definitions also fail.
|
|
54
|
-
- **Compensation scenario test** — proves the documented
|
|
55
|
-
`cart.checkout.canceled` → `inventory.release()` host wiring end-to-end.
|
|
56
|
-
- `PriceChangedErrorContext` — formal type for the error's structured
|
|
57
|
-
context (current pricing payload), previously an untyped inline shape.
|
|
58
|
-
|
|
59
|
-
### Changed
|
|
60
|
-
|
|
61
|
-
- **`CartEventPublisher`**: a host-owned `ctx.session` without an outbox now
|
|
62
|
-
throws typed `UnmanagedSessionError` (was a plain `Error`) unless a
|
|
63
|
-
`PENDING_EVENTS` queue is attached; transport publish failures on the
|
|
64
|
-
no-session path are now swallowed and logged per P8 (the domain verb no
|
|
65
|
-
longer fails after its write landed because a transport hiccuped).
|
|
66
|
-
- Safe-integer guard on line-total arithmetic (`unitPrice × quantity`);
|
|
67
|
-
idempotency repo now uses mongokit's `isDuplicateKeyError`; `cancel()`
|
|
68
|
-
and the timeslot kind's `revalidate` carry explicit contracts (host owns
|
|
69
|
-
hold release; validity-window-only revalidation — real slot-locking via
|
|
70
|
-
`@classytic/order`'s `BookingBridge`).
|
|
71
|
-
|
|
72
|
-
## [0.2.0]
|
|
73
|
-
|
|
74
|
-
### Changed
|
|
75
|
-
|
|
76
|
-
- **`pricingHash` is now hex SHA-256** over the same canonical sorted
|
|
77
|
-
line string (was the raw concatenation). The hash is opaque — compare,
|
|
78
|
-
never parse. **Migration:** drafts priced before 0.2.0 carry old-format
|
|
79
|
-
hashes; the first checkout attempt against them raises
|
|
80
|
-
`PriceChangedError` once and the client re-fetches/re-confirms.
|
|
81
|
-
Accepted clean break.
|
|
82
|
-
- **Guest→user merge is now double-CAS atomic.** `mergeDrafts` retires the
|
|
83
|
-
source with a version CAS, then writes the target with a version CAS
|
|
84
|
-
(bounded retries) — a concurrent add-to-cart on either draft is retried
|
|
85
|
-
into the result instead of silently lost. `DraftRepository.markAbandoned`
|
|
86
|
-
gains an optional `{ expectedVersion }`; `replaceLines` gains an
|
|
87
|
-
optional `expectedVersion` input.
|
|
88
|
-
- **Zombie open checkouts self-heal.** `createFromDraft` CAS-expires an
|
|
89
|
-
open checkout older than `checkout.staleOpenCheckoutMs` (new config,
|
|
90
|
-
default 10 min) and creates a fresh one; fresh open checkouts are still
|
|
91
|
-
returned idempotently. `expireStaleOpenCheckouts` remains the bulk cron
|
|
92
|
-
sweep. No TTL deletes — checkout rows stay as audit history.
|
|
93
|
-
- **`PriceChangedError` context now includes `currentPricing`** (per-line
|
|
94
|
-
`lineId`/`quantity`/`unitPrice`/`subtotals` + `totals`) so hosts render
|
|
95
|
-
a price diff without re-fetching the draft.
|
|
96
|
-
- **`ctx.signal` is threaded to every mongokit call** — cancelled requests
|
|
97
|
-
stop at the driver-call boundary (repo-core 0.6 `QueryOptions.signal`).
|
|
98
|
-
- Peer deps: `@classytic/mongokit >= 3.16`, `@classytic/repo-core >= 0.6`.
|
|
99
|
-
|
|
100
|
-
### Added
|
|
101
|
-
|
|
102
|
-
- `checkoutConfigSchema` / `CartConfig.checkout.staleOpenCheckoutMs` and
|
|
103
|
-
`DEFAULT_STALE_OPEN_CHECKOUT_MS` export.
|
|
104
|
-
- Documented host contract: checkout → order → `inventory.commit()`
|
|
105
|
-
(CLAUDE.md "Host responsibilities") — `commit()` intentionally does not
|
|
106
|
-
commit inventory holds.
|
|
107
|
-
- Scenario 10: stale quote → `revalidate()` reprice path (`bundle` kind).
|
|
108
|
-
|
|
109
|
-
## [0.1.0]
|
|
110
|
-
|
|
111
|
-
Initial release. Framework-agnostic universal cart engine — mutable drafts,
|
|
112
|
-
locked checkout snapshots, composable pricing, and the **LineKind** strategy
|
|
113
|
-
that handles every business variation. Zero framework dependencies.
|
|
114
|
-
|
|
115
|
-
### Exports
|
|
116
|
-
|
|
117
|
-
- **`.`** (root) — `createCart(config)` engine factory, re-exports of the
|
|
118
|
-
most-used services and types.
|
|
119
|
-
- **`./domain`** — pure domain types: `Draft`, `Checkout`, `Line`, `Money`,
|
|
120
|
-
validity/staleness, idempotency key shapes.
|
|
121
|
-
- **`./kinds`** — built-in `sku` LineKind + the generic `LineKind<T>` contract.
|
|
122
|
-
- **`./ports`** — 5 bridge ports: `CatalogBridge` (required), `InventoryBridge`,
|
|
123
|
-
`PromotionsBridge`, `TaxBridge`, `ShippingBridge`.
|
|
124
|
-
- **`./errors`** — typed error classes (`DraftNotFoundError`,
|
|
125
|
-
`PriceChangedError`, `InventoryReservationError`, etc.).
|
|
126
|
-
- **`./events`** — `cartEventDefinitions`, `OutboxRepository`, payload map;
|
|
127
|
-
arc-compatible structural types (no arc import).
|
|
128
|
-
- **`./saga`** — checkout state machine (`open → finalized | canceled`),
|
|
129
|
-
transition helpers.
|
|
130
|
-
- **`./engine`** — engine internals for hosts that want to reach past the
|
|
131
|
-
factory.
|
|
132
|
-
- **`./schemas`** — Zod schemas for `createCart()` config; exported for hosts
|
|
133
|
-
that validate config from env or a database.
|
|
134
|
-
|
|
135
|
-
### Peer dependencies
|
|
136
|
-
|
|
137
|
-
- `@classytic/mongokit >= 3.11` — repositories extend `Repository<T>` directly.
|
|
138
|
-
- `@classytic/primitives >= 0.1` — `Money`, `OperationContext`, events.
|
|
139
|
-
- `@classytic/repo-core >= 0.2` — shared repository abstractions.
|
|
140
|
-
- `mongoose >= 9.4` · `zod >= 4`.
|
|
141
|
-
|
|
142
|
-
### Design
|
|
143
|
-
|
|
144
|
-
- **No modes / no tiers.** Features light up based on which bridges the host
|
|
145
|
-
passes to `createCart()`. Catalog bridge is required; inventory, promo, tax,
|
|
146
|
-
shipping are opt-in.
|
|
147
|
-
- **Denormalized display snapshot** on every line (`display.name`,
|
|
148
|
-
`imageUrl`, `variantLabel`, `compareAtPrice`, `capturedAt`) captured at
|
|
149
|
-
add-time by `kind.displayOf()`. UI reads the cart with zero `.populate()`
|
|
150
|
-
calls. Drift is cosmetic; price drift is caught via `pricingHash` at checkout.
|
|
151
|
-
- **Checkout state machine: 3 states, 2 transitions.** `open → finalized`
|
|
152
|
-
(host called `commit`) or `open → canceled`. No payment state inside cart.
|
|
153
|
-
- **Idempotent + typed.** Every mutation accepts an idempotency key.
|
|
154
|
-
Operations are pure async functions with serializable inputs — agent-ready.
|
|
155
|
-
- **Arc-compatible events.** `cartEventDefinitions` are structurally
|
|
156
|
-
compatible with arc's `EventDefinitionOutput`; `OutboxRepository` implements
|
|
157
|
-
arc's `OutboxStore` without importing arc.
|
|
57
|
+
## [0.3.0] — unpublished (2026-07-15)
|
|
58
|
+
|
|
59
|
+
### Changed — kit refresh (peer floors: mongokit >=3.22.0, repo-core >=0.13.0, primitives >=0.11.0)
|
|
60
|
+
|
|
61
|
+
- Verified against the mongokit 3.22 sweep. DEFERRED (design note, not a
|
|
62
|
+
drive-by): checkout `finalize`/`cancel` are assert-then-`updateWithVersion`
|
|
63
|
+
— the version CAS serializes writers, so the window is narrow; converting
|
|
64
|
+
to `applyTransition` (state+version compound CAS) needs a pass that
|
|
65
|
+
preserves the updateWithVersion helper's semantics.
|
|
66
|
+
|
|
67
|
+
## [0.2.1] - 2026-07-02
|
|
68
|
+
|
|
69
|
+
### Changed (behavioral) — 2026-07-05 addendum
|
|
70
|
+
|
|
71
|
+
- **`commit()` is crash-retry convergent.** The finalize CAS runs first and
|
|
72
|
+
its tail (`markConverted` on the draft + the `cart.checkout.committed`
|
|
73
|
+
event) is non-atomic — a crash in between left the draft looking live
|
|
74
|
+
(re-checkout → duplicate order risk) with NO retry path, because a second
|
|
75
|
+
`commit()` failed the `finalized → finalized` state assertion. A retry
|
|
76
|
+
with the SAME `externalRef` (or none) now re-runs both idempotent tails
|
|
77
|
+
and returns the finalized checkout; a DIFFERENT `externalRef` throws
|
|
78
|
+
`ConcurrencyError`. `cart.checkout.committed` delivery is at-least-once —
|
|
79
|
+
subscribers must already dedupe by `checkoutId`.
|
|
80
|
+
|
|
81
|
+
### Added
|
|
82
|
+
|
|
83
|
+
- **`engine.withTransaction(ctx, body)`** — unit-of-work wrapper (transaction
|
|
84
|
+
+ post-commit event publish), the contract shared with `@classytic/refit`
|
|
85
|
+
and `@classytic/review`. Events emitted inside the unit are queued under
|
|
86
|
+
`ctx[PENDING_EVENTS]` and flushed to the in-process transport only AFTER
|
|
87
|
+
commit — a rollback or retry can't leak ghost events. New exports:
|
|
88
|
+
`PENDING_EVENTS`, `flushPending`, `UnmanagedSessionError`; new config:
|
|
89
|
+
`allowNonTransactional` (standalone-Mongo dev fallback, explicit opt-in).
|
|
90
|
+
- **Boot capability gate** — `createCart` (full mode) asserts the backend
|
|
91
|
+
declares `capabilities.upsert` (idempotency lease pattern) at engine
|
|
92
|
+
creation instead of failing on the first checkout.
|
|
93
|
+
- **Event-catalog no-drift test** (rule 18) — every `CartEvents` constant
|
|
94
|
+
must have a Zod definition; orphan definitions also fail.
|
|
95
|
+
- **Compensation scenario test** — proves the documented
|
|
96
|
+
`cart.checkout.canceled` → `inventory.release()` host wiring end-to-end.
|
|
97
|
+
- `PriceChangedErrorContext` — formal type for the error's structured
|
|
98
|
+
context (current pricing payload), previously an untyped inline shape.
|
|
99
|
+
|
|
100
|
+
### Changed
|
|
101
|
+
|
|
102
|
+
- **`CartEventPublisher`**: a host-owned `ctx.session` without an outbox now
|
|
103
|
+
throws typed `UnmanagedSessionError` (was a plain `Error`) unless a
|
|
104
|
+
`PENDING_EVENTS` queue is attached; transport publish failures on the
|
|
105
|
+
no-session path are now swallowed and logged per P8 (the domain verb no
|
|
106
|
+
longer fails after its write landed because a transport hiccuped).
|
|
107
|
+
- Safe-integer guard on line-total arithmetic (`unitPrice × quantity`);
|
|
108
|
+
idempotency repo now uses mongokit's `isDuplicateKeyError`; `cancel()`
|
|
109
|
+
and the timeslot kind's `revalidate` carry explicit contracts (host owns
|
|
110
|
+
hold release; validity-window-only revalidation — real slot-locking via
|
|
111
|
+
`@classytic/order`'s `BookingBridge`).
|
|
112
|
+
|
|
113
|
+
## [0.2.0]
|
|
114
|
+
|
|
115
|
+
### Changed
|
|
116
|
+
|
|
117
|
+
- **`pricingHash` is now hex SHA-256** over the same canonical sorted
|
|
118
|
+
line string (was the raw concatenation). The hash is opaque — compare,
|
|
119
|
+
never parse. **Migration:** drafts priced before 0.2.0 carry old-format
|
|
120
|
+
hashes; the first checkout attempt against them raises
|
|
121
|
+
`PriceChangedError` once and the client re-fetches/re-confirms.
|
|
122
|
+
Accepted clean break.
|
|
123
|
+
- **Guest→user merge is now double-CAS atomic.** `mergeDrafts` retires the
|
|
124
|
+
source with a version CAS, then writes the target with a version CAS
|
|
125
|
+
(bounded retries) — a concurrent add-to-cart on either draft is retried
|
|
126
|
+
into the result instead of silently lost. `DraftRepository.markAbandoned`
|
|
127
|
+
gains an optional `{ expectedVersion }`; `replaceLines` gains an
|
|
128
|
+
optional `expectedVersion` input.
|
|
129
|
+
- **Zombie open checkouts self-heal.** `createFromDraft` CAS-expires an
|
|
130
|
+
open checkout older than `checkout.staleOpenCheckoutMs` (new config,
|
|
131
|
+
default 10 min) and creates a fresh one; fresh open checkouts are still
|
|
132
|
+
returned idempotently. `expireStaleOpenCheckouts` remains the bulk cron
|
|
133
|
+
sweep. No TTL deletes — checkout rows stay as audit history.
|
|
134
|
+
- **`PriceChangedError` context now includes `currentPricing`** (per-line
|
|
135
|
+
`lineId`/`quantity`/`unitPrice`/`subtotals` + `totals`) so hosts render
|
|
136
|
+
a price diff without re-fetching the draft.
|
|
137
|
+
- **`ctx.signal` is threaded to every mongokit call** — cancelled requests
|
|
138
|
+
stop at the driver-call boundary (repo-core 0.6 `QueryOptions.signal`).
|
|
139
|
+
- Peer deps: `@classytic/mongokit >= 3.16`, `@classytic/repo-core >= 0.6`.
|
|
140
|
+
|
|
141
|
+
### Added
|
|
142
|
+
|
|
143
|
+
- `checkoutConfigSchema` / `CartConfig.checkout.staleOpenCheckoutMs` and
|
|
144
|
+
`DEFAULT_STALE_OPEN_CHECKOUT_MS` export.
|
|
145
|
+
- Documented host contract: checkout → order → `inventory.commit()`
|
|
146
|
+
(CLAUDE.md "Host responsibilities") — `commit()` intentionally does not
|
|
147
|
+
commit inventory holds.
|
|
148
|
+
- Scenario 10: stale quote → `revalidate()` reprice path (`bundle` kind).
|
|
149
|
+
|
|
150
|
+
## [0.1.0]
|
|
151
|
+
|
|
152
|
+
Initial release. Framework-agnostic universal cart engine — mutable drafts,
|
|
153
|
+
locked checkout snapshots, composable pricing, and the **LineKind** strategy
|
|
154
|
+
that handles every business variation. Zero framework dependencies.
|
|
155
|
+
|
|
156
|
+
### Exports
|
|
157
|
+
|
|
158
|
+
- **`.`** (root) — `createCart(config)` engine factory, re-exports of the
|
|
159
|
+
most-used services and types.
|
|
160
|
+
- **`./domain`** — pure domain types: `Draft`, `Checkout`, `Line`, `Money`,
|
|
161
|
+
validity/staleness, idempotency key shapes.
|
|
162
|
+
- **`./kinds`** — built-in `sku` LineKind + the generic `LineKind<T>` contract.
|
|
163
|
+
- **`./ports`** — 5 bridge ports: `CatalogBridge` (required), `InventoryBridge`,
|
|
164
|
+
`PromotionsBridge`, `TaxBridge`, `ShippingBridge`.
|
|
165
|
+
- **`./errors`** — typed error classes (`DraftNotFoundError`,
|
|
166
|
+
`PriceChangedError`, `InventoryReservationError`, etc.).
|
|
167
|
+
- **`./events`** — `cartEventDefinitions`, `OutboxRepository`, payload map;
|
|
168
|
+
arc-compatible structural types (no arc import).
|
|
169
|
+
- **`./saga`** — checkout state machine (`open → finalized | canceled`),
|
|
170
|
+
transition helpers.
|
|
171
|
+
- **`./engine`** — engine internals for hosts that want to reach past the
|
|
172
|
+
factory.
|
|
173
|
+
- **`./schemas`** — Zod schemas for `createCart()` config; exported for hosts
|
|
174
|
+
that validate config from env or a database.
|
|
175
|
+
|
|
176
|
+
### Peer dependencies
|
|
177
|
+
|
|
178
|
+
- `@classytic/mongokit >= 3.11` — repositories extend `Repository<T>` directly.
|
|
179
|
+
- `@classytic/primitives >= 0.1` — `Money`, `OperationContext`, events.
|
|
180
|
+
- `@classytic/repo-core >= 0.2` — shared repository abstractions.
|
|
181
|
+
- `mongoose >= 9.4` · `zod >= 4`.
|
|
182
|
+
|
|
183
|
+
### Design
|
|
184
|
+
|
|
185
|
+
- **No modes / no tiers.** Features light up based on which bridges the host
|
|
186
|
+
passes to `createCart()`. Catalog bridge is required; inventory, promo, tax,
|
|
187
|
+
shipping are opt-in.
|
|
188
|
+
- **Denormalized display snapshot** on every line (`display.name`,
|
|
189
|
+
`imageUrl`, `variantLabel`, `compareAtPrice`, `capturedAt`) captured at
|
|
190
|
+
add-time by `kind.displayOf()`. UI reads the cart with zero `.populate()`
|
|
191
|
+
calls. Drift is cosmetic; price drift is caught via `pricingHash` at checkout.
|
|
192
|
+
- **Checkout state machine: 3 states, 2 transitions.** `open → finalized`
|
|
193
|
+
(host called `commit`) or `open → canceled`. No payment state inside cart.
|
|
194
|
+
- **Idempotent + typed.** Every mutation accepts an idempotency key.
|
|
195
|
+
Operations are pure async functions with serializable inputs — agent-ready.
|
|
196
|
+
- **Arc-compatible events.** `cartEventDefinitions` are structurally
|
|
197
|
+
compatible with arc's `EventDefinitionOutput`; `OutboxRepository` implements
|
|
198
|
+
arc's `OutboxStore` without importing arc.
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Classytic
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
Classytic Source-Available License (Community & Commercial), Version 1.0
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Classytic LLC. All rights reserved.
|
|
4
|
+
|
|
5
|
+
This software is source-available, not open source. Please read this License
|
|
6
|
+
before using it.
|
|
7
|
+
|
|
8
|
+
1. DEFINITIONS
|
|
9
|
+
"Software" means the contents of this package and any accompanying source
|
|
10
|
+
code, object code, or documentation, in any form.
|
|
11
|
+
"Licensor" means Classytic LLC, a limited liability company organized in the
|
|
12
|
+
United States.
|
|
13
|
+
"You" means the individual or legal entity exercising rights under this
|
|
14
|
+
License.
|
|
15
|
+
"Evaluation Use" means use for evaluation, development, testing,
|
|
16
|
+
experimentation, or internal non-commercial purposes only.
|
|
17
|
+
"Production Use" means any use of the Software that is live, commercial,
|
|
18
|
+
revenue-generating, or customer-facing, or any use other than Evaluation Use.
|
|
19
|
+
"Commercial License" means a separate written agreement executed with
|
|
20
|
+
Licensor that grants Production Use rights.
|
|
21
|
+
|
|
22
|
+
2. OWNERSHIP
|
|
23
|
+
The Software is licensed, not sold. Licensor retains all right, title, and
|
|
24
|
+
interest in and to the Software, including all intellectual property rights.
|
|
25
|
+
All rights not expressly granted in this License are reserved by Licensor.
|
|
26
|
+
|
|
27
|
+
3. EVALUATION GRANT
|
|
28
|
+
Subject to Your compliance with this License, Licensor grants You a
|
|
29
|
+
worldwide, royalty-free, non-exclusive, non-transferable, revocable license
|
|
30
|
+
to download, install, run, and modify the Software solely for Evaluation Use.
|
|
31
|
+
|
|
32
|
+
4. PRODUCTION USE REQUIRES A COMMERCIAL LICENSE
|
|
33
|
+
Production Use of the Software is NOT permitted under this License and
|
|
34
|
+
requires a Commercial License from Licensor. A Commercial License may be
|
|
35
|
+
granted at Licensor's discretion, with or without a fee, and may confer
|
|
36
|
+
perpetual, irrevocable, and transferable Production Use rights as set out in
|
|
37
|
+
that agreement. Contact licensing@classytic.com to obtain one.
|
|
38
|
+
|
|
39
|
+
5. RESTRICTIONS
|
|
40
|
+
You may not:
|
|
41
|
+
(a) make any Production Use of the Software without a Commercial License;
|
|
42
|
+
(b) redistribute, resell, rent, sublicense, or otherwise make the Software
|
|
43
|
+
(in whole or in part, original or modified) available to third parties as
|
|
44
|
+
a stand-alone product, framework, library, or hosted/managed service that
|
|
45
|
+
competes with the Software or with Licensor;
|
|
46
|
+
(c) remove, obscure, or alter any copyright, license, or attribution notice.
|
|
47
|
+
|
|
48
|
+
6. FEEDBACK AND CONTRIBUTIONS
|
|
49
|
+
Any feedback, suggestions, or contributions You provide relating to the
|
|
50
|
+
Software may be used by Licensor for any purpose without obligation to You.
|
|
51
|
+
|
|
52
|
+
7. TERMINATION
|
|
53
|
+
This License and the Evaluation Grant terminate automatically if You breach
|
|
54
|
+
any term. Upon termination You must cease all use of the Software and destroy
|
|
55
|
+
all copies in Your possession. Rights under a Commercial License are governed
|
|
56
|
+
by that agreement's own terms and survive termination of this License to the
|
|
57
|
+
extent stated there.
|
|
58
|
+
|
|
59
|
+
8. DISCLAIMER OF WARRANTY
|
|
60
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
61
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
62
|
+
FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT.
|
|
63
|
+
|
|
64
|
+
9. LIMITATION OF LIABILITY
|
|
65
|
+
TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL LICENSOR BE LIABLE
|
|
66
|
+
FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
67
|
+
TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE
|
|
68
|
+
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
69
|
+
|
|
70
|
+
10. GOVERNING LAW
|
|
71
|
+
This License is governed by the laws of the State of Delaware, United States,
|
|
72
|
+
without regard to its conflict-of-laws principles. (Adjust to Your LLC's state
|
|
73
|
+
of formation.)
|
|
74
|
+
|
|
75
|
+
For commercial licensing, contact: licensing@classytic.com
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { _ as CartEventMeta, b as CartEventName, h as CartDomainEvent } from "./outbox-store-
|
|
2
|
-
|
|
1
|
+
import { _ as CartEventMeta, b as CartEventName, h as CartDomainEvent } from "./outbox-store-Br7MHuOz.mjs";
|
|
3
2
|
//#region src/domain/events/event-schema.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* EventSchema — minimal JSON-schema-like shape for event payload validation.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//#region src/domain/errors/cart.error.ts
|
|
2
|
+
var CartError = class extends Error {
|
|
3
|
+
/** Optional structured context for logging / debugging. */
|
|
4
|
+
context;
|
|
5
|
+
/**
|
|
6
|
+
* Canonical `HttpError.status` (`@classytic/repo-core/errors`), DERIVED from
|
|
7
|
+
* {@link category} — the category already encodes exactly the distinction a
|
|
8
|
+
* status code makes, so deriving it keeps the two from ever disagreeing.
|
|
9
|
+
*
|
|
10
|
+
* Without a numeric `status`, arc's global handler has nothing to key on and
|
|
11
|
+
* serializes every cart error as `arc.internal_error` / 500 — `NotFoundError`
|
|
12
|
+
* answered 500 instead of 404, `ConcurrencyError` 500 instead of 409. That
|
|
13
|
+
* tells a client "the server broke, retrying is pointless" about outcomes
|
|
14
|
+
* that are neither broken nor unretryable, and it defeats `retryable` above:
|
|
15
|
+
* the field says "retry is reasonable" while the status says "don't bother".
|
|
16
|
+
*
|
|
17
|
+
* A subclass may still override with `readonly status = N` for a genuinely
|
|
18
|
+
* special case; nothing here depends on the mapping being total.
|
|
19
|
+
*/
|
|
20
|
+
get status() {
|
|
21
|
+
switch (this.category) {
|
|
22
|
+
case "not_found": return 404;
|
|
23
|
+
case "concurrency":
|
|
24
|
+
case "state": return 409;
|
|
25
|
+
case "validation": return 422;
|
|
26
|
+
case "external": return 502;
|
|
27
|
+
default: return 500;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
constructor(message, context) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.name = new.target.name;
|
|
33
|
+
this.context = context;
|
|
34
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Serialize to a wire-safe shape. Suitable for HTTP error bodies and
|
|
38
|
+
* structured logging. Never includes stack frames.
|
|
39
|
+
*/
|
|
40
|
+
toJSON() {
|
|
41
|
+
return {
|
|
42
|
+
name: this.name,
|
|
43
|
+
code: this.code,
|
|
44
|
+
category: this.category,
|
|
45
|
+
message: this.message,
|
|
46
|
+
retryable: this.retryable,
|
|
47
|
+
context: this.context
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
export { CartError as t };
|
|
@@ -2,7 +2,6 @@ import { Money } from "@classytic/primitives/money";
|
|
|
2
2
|
import { ClientSession } from "mongoose";
|
|
3
3
|
import { OperationContext } from "@classytic/primitives/context";
|
|
4
4
|
import { ContactAddress as Address } from "@classytic/primitives/address";
|
|
5
|
-
|
|
6
5
|
//#region src/domain/value-objects/pricing-snapshot.vo.d.ts
|
|
7
6
|
/**
|
|
8
7
|
* A priced line — the output of the pricing pipeline for a single LineItem.
|
|
@@ -77,10 +76,15 @@ interface PricingSnapshot {
|
|
|
77
76
|
tax: Money;
|
|
78
77
|
/** Final post-rounding totals from step 6. */
|
|
79
78
|
totals: {
|
|
80
|
-
/** Sum of all PricedLine.subtotals.prePromo. */
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
/** Sum of all PricedLine.subtotals.prePromo. */
|
|
80
|
+
subtotal: Money;
|
|
81
|
+
/** Sum of all line discounts + orderDiscount. */
|
|
82
|
+
discount: Money;
|
|
83
|
+
/** Alias of `tax`. */
|
|
84
|
+
taxTotal: Money;
|
|
85
|
+
/** Alias of `shipping`. */
|
|
86
|
+
shippingTotal: Money;
|
|
87
|
+
/** Final order grand total after rounding. */
|
|
84
88
|
grandTotal: Money;
|
|
85
89
|
};
|
|
86
90
|
/**
|