@classytic/cart 0.2.1 → 1.0.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/LICENSE +75 -21
  3. package/dist/{cart-event-catalog-BxDJhtTM.d.mts → cart-event-catalog-Cokx0iOw.d.mts} +1 -2
  4. package/dist/cart.error-xi5OT4Sz.mjs +52 -0
  5. package/dist/{clock.port-CNu2wgdA.d.mts → clock.port-DrSBrsit.d.mts} +9 -5
  6. package/dist/{create-cart-BeW0xAqD.mjs → define-cart-BPq2kb_V.mjs} +344 -224
  7. package/dist/domain/errors/index.d.mts +2 -2
  8. package/dist/domain/errors/index.mjs +6 -6
  9. package/dist/domain/events/index.d.mts +2 -2
  10. package/dist/domain/events/index.mjs +2 -2
  11. package/dist/domain/index.d.mts +14 -11
  12. package/dist/domain/index.mjs +12 -12
  13. package/dist/domain/ports/index.d.mts +3 -3
  14. package/dist/domain/ports/index.mjs +1 -1
  15. package/dist/domain/saga/index.d.mts +1 -1
  16. package/dist/domain/saga/index.mjs +1 -1
  17. package/dist/engine/cart-config.schema.d.mts +3 -4
  18. package/dist/engine/cart-config.schema.mjs +7 -7
  19. package/dist/engine/index.d.mts +3 -3
  20. package/dist/engine/index.mjs +3 -3
  21. package/dist/{errors-7Pd0yATM.mjs → errors-Dj8itvAh.mjs} +1 -4
  22. package/dist/{id.port-BhbFZJPm.mjs → id.port-DYAnXbfV.mjs} +1 -1
  23. package/dist/{index-BB0XzkXF.d.mts → index-BTSo-RLv.d.mts} +41 -4
  24. package/dist/index.d.mts +75 -17
  25. package/dist/index.mjs +180 -15
  26. package/dist/{internal-event-bus-DhQKi9KS.d.mts → internal-event-bus-Bu7Xj7j6.d.mts} +203 -170
  27. package/dist/{kind-registry-DG2iCCH1.d.mts → kind-registry-DFvNDb81.d.mts} +3 -5
  28. package/dist/{kind-registry-Bvrj3P1Q.mjs → kind-registry-DQYqRQZU.mjs} +1 -1
  29. package/dist/{kind.error-DIaJpdUb.mjs → kind.error-BoyoVjKx.mjs} +1 -1
  30. package/dist/kinds/index.d.mts +1 -1
  31. package/dist/kinds/index.mjs +1 -1
  32. package/dist/{line-kind-B1mU1iJp.d.mts → line-kind-BW2zLNSr.d.mts} +3 -4
  33. package/dist/line-total-6VJQMjGV.mjs +24 -0
  34. package/dist/{outbox-store-CBt9fSYh.d.mts → outbox-store-Br7MHuOz.d.mts} +3 -18
  35. package/dist/{outbox-store-CWW8ppxS.mjs → outbox-store-DLxCPOUN.mjs} +2 -30
  36. package/dist/{reservation.entity-DLMxgpLE.d.mts → reservation.entity-BEeYbRUY.d.mts} +4 -5
  37. package/dist/{state-transition.error-2fRLh3p0.mjs → state-transition.error-BssJiRoW.mjs} +1 -1
  38. package/dist/{state-transitions-D19wZe-w.d.mts → state-transitions-BQ2Nhxnb.d.mts} +14 -11
  39. package/dist/{state-transitions-Defw8gAt.mjs → state-transitions-wunwhjap.mjs} +1 -1
  40. package/dist/{unmanaged-session.error-C9Z1Yh9j.mjs → unmanaged-session.error-DIRT2PR3.mjs} +31 -2
  41. package/dist/{variant.kind-q-yv-vnQ.d.mts → variant.kind-CClf8MTF.d.mts} +3 -3
  42. package/dist/{variant.kind-BHiivO9B.mjs → variant.kind-NmWSslu-.mjs} +23 -32
  43. package/package.json +10 -9
  44. package/dist/cart.error-BwWy4RlY.mjs +0 -27
  45. package/dist/index-2Ag-54t8.d.mts +0 -1
  46. /package/dist/{cart-status.vo-CNJw4aaB.d.mts → cart-status.vo-BoVPaSXX.d.mts} +0 -0
  47. /package/dist/{domain-event-CIEORKF6.mjs → domain-event-DBFsiHNJ.mjs} +0 -0
  48. /package/dist/{id.port-DitjeoHg.d.mts → id.port-DzgWy8sy.d.mts} +0 -0
  49. /package/dist/{idempotency-key.vo-D0lJsvGn.mjs → idempotency-key.vo-BoRvSIxx.mjs} +0 -0
@@ -1,7 +1,7 @@
1
1
  import { Money } from "@classytic/primitives/money";
2
2
  import { DomainEvent, EventMeta } from "@classytic/primitives/events";
3
- import { InvalidOutboxEventError, OutboxAcknowledgeOptions, OutboxAcknowledgeOptions as OutboxAcknowledgeOptions$1, OutboxClaimOptions, OutboxErrorInfo, OutboxFailOptions, OutboxFailureContext, OutboxFailureDecision, OutboxFailurePolicy, OutboxOwnershipError, OutboxStore, OutboxStore as OutboxStore$1, OutboxWriteOptions, OutboxWriteOptions as OutboxWriteOptions$1 } from "@classytic/primitives/outbox";
4
-
3
+ import { InvalidOutboxEventError, OutboxAcknowledgeOptions, OutboxClaimOptions, OutboxErrorInfo, OutboxFailOptions, OutboxFailureContext, OutboxFailureDecision, OutboxFailurePolicy, OutboxOwnershipError, OutboxStore, OutboxWriteOptions, OutboxWriteOptions as OutboxWriteOptions$1 } from "@classytic/primitives/outbox";
4
+ import { MemoryOutboxStore } from "@classytic/primitives/memory-outbox";
5
5
  //#region src/domain/events/cart-events.d.ts
6
6
  /**
7
7
  * Cart event name + payload map.
@@ -136,20 +136,5 @@ declare function createCartEvent<T>(type: string, payload: T, meta?: Partial<Car
136
136
  * `@classytic/primitives/outbox` in new code.
137
137
  */
138
138
  type OutboxStoreWriteOptions = OutboxWriteOptions;
139
- /**
140
- * In-memory OutboxStore for tests and local dev. Not for production.
141
- *
142
- * Implements the required trio (`save` / `getPending` / `acknowledge`) plus
143
- * optional `purge`. The lease-based methods (`claimPending` / `fail` /
144
- * `getDeadLettered`) are intentionally omitted — single-process tests don't
145
- * need them, and cart's publisher only calls `save()`.
146
- */
147
- declare class MemoryOutboxStore implements OutboxStore {
148
- private events;
149
- save(event: DomainEvent, _options?: OutboxWriteOptions): Promise<void>;
150
- getPending(limit: number): Promise<DomainEvent[]>;
151
- acknowledge(eventId: string, _options?: OutboxAcknowledgeOptions): Promise<void>;
152
- purge(olderThanMs: number): Promise<number>;
153
- }
154
139
  //#endregion
155
- export { CartEvents as S, CartEventMeta as _, OutboxErrorInfo as a, CartEventName as b, OutboxFailureDecision as c, OutboxStore$1 as d, OutboxStoreWriteOptions as f, CartEventAggregate as g, CartDomainEvent as h, OutboxClaimOptions as i, OutboxFailurePolicy as l, CartAggregateType as m, MemoryOutboxStore as n, OutboxFailOptions as o, OutboxWriteOptions$1 as p, OutboxAcknowledgeOptions$1 as r, OutboxFailureContext as s, InvalidOutboxEventError as t, OutboxOwnershipError as u, createCartEvent as v, CartEventPayload as x, CartEventMap as y };
140
+ export { CartEvents as S, CartEventMeta as _, OutboxErrorInfo as a, CartEventName as b, OutboxFailureDecision as c, OutboxStore as d, OutboxStoreWriteOptions as f, CartEventAggregate as g, CartDomainEvent as h, OutboxClaimOptions as i, OutboxFailurePolicy as l, CartAggregateType as m, MemoryOutboxStore as n, OutboxFailOptions as o, OutboxWriteOptions$1 as p, OutboxAcknowledgeOptions as r, OutboxFailureContext as s, InvalidOutboxEventError as t, OutboxOwnershipError as u, createCartEvent as v, CartEventPayload as x, CartEventMap as y };
@@ -1,5 +1,6 @@
1
- import { n as CartEvents, t as createCartEvent } from "./domain-event-CIEORKF6.mjs";
1
+ import { n as CartEvents, t as createCartEvent } from "./domain-event-DBFsiHNJ.mjs";
2
2
  import { InvalidOutboxEventError, OutboxOwnershipError } from "@classytic/primitives/outbox";
3
+ import { MemoryOutboxStore } from "@classytic/primitives/memory-outbox";
3
4
  //#region src/domain/events/event-definition.ts
4
5
  function defineCartEvent(input) {
5
6
  const { name, version = 1, description, schema } = input;
@@ -269,33 +270,4 @@ const cartEventDefinitions = Object.freeze([
269
270
  */
270
271
  const cartEventsByName = Object.freeze(Object.fromEntries(cartEventDefinitions.map((def) => [def.name, def])));
271
272
  //#endregion
272
- //#region src/domain/events/outbox-store.ts
273
- /**
274
- * In-memory OutboxStore for tests and local dev. Not for production.
275
- *
276
- * Implements the required trio (`save` / `getPending` / `acknowledge`) plus
277
- * optional `purge`. The lease-based methods (`claimPending` / `fail` /
278
- * `getDeadLettered`) are intentionally omitted — single-process tests don't
279
- * need them, and cart's publisher only calls `save()`.
280
- */
281
- var MemoryOutboxStore = class {
282
- events = [];
283
- async save(event, _options) {
284
- this.events.push({ event });
285
- }
286
- async getPending(limit) {
287
- return this.events.filter((e) => !e.acknowledgedAt).slice(0, limit).map((e) => e.event);
288
- }
289
- async acknowledge(eventId, _options) {
290
- const entry = this.events.find((e) => e.event.meta.id === eventId);
291
- if (entry) entry.acknowledgedAt = /* @__PURE__ */ new Date();
292
- }
293
- async purge(olderThanMs) {
294
- const cutoff = Date.now() - olderThanMs;
295
- const before = this.events.length;
296
- this.events = this.events.filter((e) => !e.acknowledgedAt || e.acknowledgedAt.getTime() >= cutoff);
297
- return before - this.events.length;
298
- }
299
- };
300
- //#endregion
301
273
  export { cartEventsByName as a, cartEventDefinitions as i, MemoryOutboxStore as n, createCartEventRegistry as o, OutboxOwnershipError as r, defineCartEvent as s, InvalidOutboxEventError as t };
@@ -1,9 +1,8 @@
1
- import { n as DraftStatus, r as ReservationStatus, t as CheckoutState } from "./cart-status.vo-CNJw4aaB.mjs";
2
- import { E as PricingSnapshot, g as AdjustmentSpec } from "./clock.port-CNu2wgdA.mjs";
3
- import { o as CheckoutFlowState } from "./state-transitions-D19wZe-w.mjs";
4
- import { a as IdempotencyReplay, c as LineItem, o as OperationName } from "./kind-registry-DG2iCCH1.mjs";
1
+ import { n as DraftStatus, r as ReservationStatus, t as CheckoutState } from "./cart-status.vo-BoVPaSXX.mjs";
2
+ import { E as PricingSnapshot, g as AdjustmentSpec } from "./clock.port-DrSBrsit.mjs";
3
+ import { o as CheckoutFlowState } from "./state-transitions-BQ2Nhxnb.mjs";
4
+ import { a as IdempotencyReplay, c as LineItem, o as OperationName } from "./kind-registry-DFvNDb81.mjs";
5
5
  import { Money } from "@classytic/primitives/money";
6
-
7
6
  //#region src/domain/entities/adjustment.entity.d.ts
8
7
  /**
9
8
  * Adjustment — an explicit discount / surcharge on the cart, represented as
@@ -1,4 +1,4 @@
1
- import { t as CartError } from "./cart.error-BwWy4RlY.mjs";
1
+ import { t as CartError } from "./cart.error-xi5OT4Sz.mjs";
2
2
  //#region src/domain/errors/state-transition.error.ts
3
3
  /**
4
4
  * A write attempted to transition `checkout.state` along an edge that
@@ -1,9 +1,7 @@
1
- import { t as CheckoutState } from "./cart-status.vo-CNJw4aaB.mjs";
2
- import { C as OperationContext, t as ClockPort } from "./clock.port-CNu2wgdA.mjs";
3
- import { t as KindBridges } from "./line-kind-B1mU1iJp.mjs";
4
- import { t as IdPort } from "./id.port-DitjeoHg.mjs";
5
- import * as _$_classytic_primitives_state_machine0 from "@classytic/primitives/state-machine";
6
-
1
+ import { t as CheckoutState } from "./cart-status.vo-BoVPaSXX.mjs";
2
+ import { C as OperationContext, t as ClockPort } from "./clock.port-DrSBrsit.mjs";
3
+ import { t as KindBridges } from "./line-kind-BW2zLNSr.mjs";
4
+ import { t as IdPort } from "./id.port-DzgWy8sy.mjs";
7
5
  //#region src/domain/saga/saga-steps.d.ts
8
6
  /**
9
7
  * Checkout flow steps. Deliberately minimal — cart's job is to freeze a
@@ -17,10 +15,15 @@ import * as _$_classytic_primitives_state_machine0 from "@classytic/primitives/s
17
15
  * than a reverse walk of a multi-step chain.
18
16
  */
19
17
  declare const CheckoutStep: {
20
- /** Step 1 — load draft + validate status + version. */readonly LoadDraft: 1; /** Step 2 — enforce stored snapshot freshness without extra bridge reads. */
21
- readonly Revalidate: 2; /** Step 3 — compare stored pricingHash with expectedPricingHash. */
22
- readonly Reprice: 3; /** Step 4 — create the checkout document with the frozen snapshot. */
23
- readonly CreateCheckout: 4; /** Step 5 — commit (host-called after its own external work succeeds). */
18
+ /** Step 1 — load draft + validate status + version. */
19
+ readonly LoadDraft: 1;
20
+ /** Step 2 — enforce stored snapshot freshness without extra bridge reads. */
21
+ readonly Revalidate: 2;
22
+ /** Step 3 — compare stored pricingHash with expectedPricingHash. */
23
+ readonly Reprice: 3;
24
+ /** Step 4 — create the checkout document with the frozen snapshot. */
25
+ readonly CreateCheckout: 4;
26
+ /** Step 5 — commit (host-called after its own external work succeeds). */
24
27
  readonly Commit: 5;
25
28
  };
26
29
  type CheckoutStepNumber = (typeof CheckoutStep)[keyof typeof CheckoutStep];
@@ -129,7 +132,7 @@ declare const CHECKOUT_STATE_TRANSITIONS: Record<CheckoutState, readonly Checkou
129
132
  * meta) via `errorFactory`, so existing catch sites that match on
130
133
  * `error.code` or `instanceof StateTransitionError` keep working.
131
134
  */
132
- declare const CHECKOUT_MACHINE: _$_classytic_primitives_state_machine0.StateMachine<CheckoutState>;
135
+ declare const CHECKOUT_MACHINE: import("@classytic/primitives/state-machine").StateMachine<CheckoutState>;
133
136
  /** Predicate — is `to` a legal transition from `from`? */
134
137
  declare function isLegalCheckoutTransition(from: CheckoutState, to: CheckoutState): boolean;
135
138
  //#endregion
@@ -1,4 +1,4 @@
1
- import { t as StateTransitionError } from "./state-transition.error-2fRLh3p0.mjs";
1
+ import { t as StateTransitionError } from "./state-transition.error-BssJiRoW.mjs";
2
2
  import { defineStateMachine } from "@classytic/primitives/state-machine";
3
3
  //#region src/domain/saga/saga-steps.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { t as CartError } from "./cart.error-BwWy4RlY.mjs";
1
+ import { t as CartError } from "./cart.error-xi5OT4Sz.mjs";
2
2
  //#region src/domain/errors/concurrency.error.ts
3
3
  /**
4
4
  * Optimistic-lock mismatch. Thrown when a mutation attempts to update a
@@ -21,6 +21,35 @@ var ConcurrencyError = class extends CartError {
21
21
  }
22
22
  };
23
23
  //#endregion
24
+ //#region src/domain/errors/currency-mismatch.error.ts
25
+ /**
26
+ * Two currencies were mixed inside a single money computation.
27
+ *
28
+ * The pricing pipeline assumes every line shares the draft's ONE currency —
29
+ * grand totals are summed as raw minor-unit integers and stamped with a single
30
+ * currency code. If a line's currency diverges (e.g. an `overrideUnitPrice` in
31
+ * EUR added to a USD draft), a blind sum would silently produce a wrong total
32
+ * and freeze it into the checkout snapshot. `sumMoney` asserts single-currency
33
+ * and throws this instead of returning a mislabeled amount.
34
+ *
35
+ * Kinds guard currency at add-time (`validate`), so in practice this is a
36
+ * defense-in-depth invariant — reaching it means a kind returned a
37
+ * mismatched-currency `PricedLine` or an override slipped past validation.
38
+ * Not retryable: the caller must supply same-currency inputs.
39
+ */
40
+ var CurrencyMismatchError = class extends CartError {
41
+ code = "cart/currency_mismatch";
42
+ category = "validation";
43
+ retryable = false;
44
+ constructor(expected, found, details) {
45
+ super(`Currency mismatch: expected ${expected}, got ${found}`, {
46
+ expected,
47
+ found,
48
+ ...details
49
+ });
50
+ }
51
+ };
52
+ //#endregion
24
53
  //#region src/domain/errors/not-found.error.ts
25
54
  /**
26
55
  * The requested draft, checkout, or reservation does not exist (or is not
@@ -124,4 +153,4 @@ var UnmanagedSessionError = class extends CartError {
124
153
  }
125
154
  };
126
155
  //#endregion
127
- export { ConcurrencyError as a, NotFoundError as i, StaleQuoteError as n, PriceChangedError as r, UnmanagedSessionError as t };
156
+ export { CurrencyMismatchError as a, NotFoundError as i, StaleQuoteError as n, ConcurrencyError as o, PriceChangedError as r, UnmanagedSessionError as t };
@@ -1,7 +1,7 @@
1
- import { r as LineKind } from "./line-kind-B1mU1iJp.mjs";
1
+ import { r as LineKind } from "./line-kind-BW2zLNSr.mjs";
2
2
  import { Money } from "@classytic/primitives/money";
3
+ import { CurrencyCode } from "@classytic/primitives/currency";
3
4
  import { z } from "zod";
4
-
5
5
  //#region src/kinds/bundle.kind.d.ts
6
6
  /**
7
7
  * `bundle` — a group of products sold together at a combined price.
@@ -89,7 +89,7 @@ declare const serviceFeePayloadSchema: z.ZodObject<{
89
89
  label: z.ZodString;
90
90
  unitPrice: z.ZodObject<{
91
91
  amount: z.ZodNumber;
92
- currency: z.ZodString;
92
+ currency: z.ZodCustom<CurrencyCode, CurrencyCode>;
93
93
  }, z.core.$strip>;
94
94
  }, z.core.$strip>;
95
95
  declare const serviceFeeKind: LineKind<ServiceFeePayload>;
@@ -1,5 +1,6 @@
1
- import { t as KindError } from "./kind.error-DIaJpdUb.mjs";
2
- import { CURRENCY_PATTERN } from "@classytic/primitives/currency";
1
+ import { t as KindError } from "./kind.error-BoyoVjKx.mjs";
2
+ import { t as lineTotal } from "./line-total-6VJQMjGV.mjs";
3
+ import { isCurrencyCode } from "@classytic/primitives/currency";
3
4
  import { z } from "zod";
4
5
  //#region src/kinds/bundle.kind.ts
5
6
  const bundlePayloadSchema = z.object({
@@ -13,7 +14,7 @@ const bundleKind = {
13
14
  name: "bundle",
14
15
  payloadSchema: bundlePayloadSchema,
15
16
  validity: {
16
- maxAgeMs: 900 * 1e3,
17
+ maxAgeMs: 9e5,
17
18
  onStale: "reprice"
18
19
  },
19
20
  async validate(line, ctx) {
@@ -29,10 +30,7 @@ const bundleKind = {
29
30
  const bundle = await ctx.bridges.catalog.resolve(typed.payload.bundleRef, ctx);
30
31
  if (!bundle) throw new KindError(this.name, `price() on unknown bundle: ${typed.payload.bundleRef}`);
31
32
  const unitPrice = typed.overrideUnitPrice ?? bundle.unitPrice;
32
- const total = {
33
- amount: unitPrice.amount * typed.quantity,
34
- currency: unitPrice.currency
35
- };
33
+ const total = lineTotal(unitPrice, typed.quantity);
36
34
  return {
37
35
  lineId: typed.lineId,
38
36
  unitPrice,
@@ -50,7 +48,7 @@ const bundleKind = {
50
48
  amount: 0,
51
49
  currency: unitPrice.currency
52
50
  },
53
- validUntil: new Date((ctx.clock?.now() ?? /* @__PURE__ */ new Date()).getTime() + 900 * 1e3),
51
+ validUntil: new Date((ctx.clock?.now() ?? /* @__PURE__ */ new Date()).getTime() + 9e5),
54
52
  kindMeta: {
55
53
  bundleRef: typed.payload.bundleRef,
56
54
  componentCount: typed.payload.components.length
@@ -88,7 +86,7 @@ const bundleKind = {
88
86
  postPromo: newTotal,
89
87
  postPromoPostTax: newTotal
90
88
  },
91
- validUntil: new Date((ctx.clock?.now() ?? /* @__PURE__ */ new Date()).getTime() + 900 * 1e3)
89
+ validUntil: new Date((ctx.clock?.now() ?? /* @__PURE__ */ new Date()).getTime() + 9e5)
92
90
  },
93
91
  delta
94
92
  };
@@ -118,7 +116,7 @@ const serviceFeePayloadSchema = z.object({
118
116
  label: z.string().min(1).max(120),
119
117
  unitPrice: z.object({
120
118
  amount: z.number().int().nonnegative(),
121
- currency: z.string().regex(CURRENCY_PATTERN, "ISO 4217 (3 uppercase letters)")
119
+ currency: z.custom(isCurrencyCode, "ISO 4217 (3 uppercase letters)")
122
120
  })
123
121
  });
124
122
  const serviceFeeKind = {
@@ -134,18 +132,15 @@ const serviceFeeKind = {
134
132
  async price(line) {
135
133
  const typed = line;
136
134
  const unitPrice = typed.overrideUnitPrice ?? typed.payload.unitPrice;
137
- const lineTotal = {
138
- amount: unitPrice.amount * typed.quantity,
139
- currency: unitPrice.currency
140
- };
135
+ const total = lineTotal(unitPrice, typed.quantity);
141
136
  return {
142
137
  lineId: typed.lineId,
143
138
  unitPrice,
144
139
  quantity: typed.quantity,
145
140
  subtotals: {
146
- prePromo: lineTotal,
147
- postPromo: lineTotal,
148
- postPromoPostTax: lineTotal
141
+ prePromo: total,
142
+ postPromo: total,
143
+ postPromoPostTax: total
149
144
  },
150
145
  discountTotal: {
151
146
  amount: 0,
@@ -204,6 +199,7 @@ const skuKind = {
204
199
  const parsed = skuPayloadSchema.safeParse(line.payload);
205
200
  if (!parsed.success) throw new KindError(this.name, "invalid payload shape", { details: { issues: parsed.error.issues } });
206
201
  if (line.quantity < 1) throw new KindError(this.name, `quantity must be >= 1, got ${line.quantity}`);
202
+ if (line.overrideUnitPrice && line.overrideUnitPrice.currency !== line.currency) throw new KindError(this.name, `override unit price currency ${line.overrideUnitPrice.currency} does not match cart currency ${line.currency}`);
207
203
  const product = await ctx.bridges.catalog.resolve(parsed.data.skuRef, ctx);
208
204
  if (!product) throw new KindError(this.name, `unknown skuRef: ${parsed.data.skuRef}`);
209
205
  if (!product.purchasable) throw new KindError(this.name, `product ${parsed.data.skuRef} is not purchasable`);
@@ -213,18 +209,15 @@ const skuKind = {
213
209
  const product = await ctx.bridges.catalog.resolve(typed.payload.skuRef, ctx);
214
210
  if (!product) throw new KindError(this.name, `price() called on unknown skuRef: ${typed.payload.skuRef}`);
215
211
  const unitPrice = typed.overrideUnitPrice ?? product.unitPrice;
216
- const lineTotal = {
217
- amount: unitPrice.amount * typed.quantity,
218
- currency: unitPrice.currency
219
- };
212
+ const total = lineTotal(unitPrice, typed.quantity);
220
213
  return {
221
214
  lineId: typed.lineId,
222
215
  unitPrice,
223
216
  quantity: typed.quantity,
224
217
  subtotals: {
225
- prePromo: lineTotal,
226
- postPromo: lineTotal,
227
- postPromoPostTax: lineTotal
218
+ prePromo: total,
219
+ postPromo: total,
220
+ postPromoPostTax: total
228
221
  },
229
222
  discountTotal: {
230
223
  amount: 0,
@@ -275,7 +268,7 @@ const timeslotPayloadSchema = z.object({
275
268
  endsAt: z.iso.datetime(),
276
269
  providerRef: z.string().optional()
277
270
  });
278
- const TIMESLOT_VALIDITY_MS = 300 * 1e3;
271
+ const TIMESLOT_VALIDITY_MS = 3e5;
279
272
  const timeslotKind = {
280
273
  name: "timeslot",
281
274
  payloadSchema: timeslotPayloadSchema,
@@ -383,6 +376,7 @@ const variantKind = {
383
376
  const parsed = variantPayloadSchema.safeParse(line.payload);
384
377
  if (!parsed.success) throw new KindError(this.name, "invalid variant payload", { details: { issues: parsed.error.issues } });
385
378
  if (line.quantity < 1) throw new KindError(this.name, `quantity must be >= 1, got ${line.quantity}`);
379
+ if (line.overrideUnitPrice && line.overrideUnitPrice.currency !== line.currency) throw new KindError(this.name, `override unit price currency ${line.overrideUnitPrice.currency} does not match cart currency ${line.currency}`);
386
380
  const product = await ctx.bridges.catalog.resolve(parsed.data.variantSku, ctx);
387
381
  if (!product) throw new KindError(this.name, `unknown variant SKU: ${parsed.data.variantSku}`);
388
382
  if (!product.purchasable) throw new KindError(this.name, `variant ${parsed.data.variantSku} is not purchasable`);
@@ -392,18 +386,15 @@ const variantKind = {
392
386
  const product = await ctx.bridges.catalog.resolve(typed.payload.variantSku, ctx);
393
387
  if (!product) throw new KindError(this.name, `price() on unknown variant: ${typed.payload.variantSku}`);
394
388
  const unitPrice = typed.overrideUnitPrice ?? product.unitPrice;
395
- const lineTotal = {
396
- amount: unitPrice.amount * typed.quantity,
397
- currency: unitPrice.currency
398
- };
389
+ const total = lineTotal(unitPrice, typed.quantity);
399
390
  return {
400
391
  lineId: typed.lineId,
401
392
  unitPrice,
402
393
  quantity: typed.quantity,
403
394
  subtotals: {
404
- prePromo: lineTotal,
405
- postPromo: lineTotal,
406
- postPromoPostTax: lineTotal
395
+ prePromo: total,
396
+ postPromo: total,
397
+ postPromoPostTax: total
407
398
  },
408
399
  discountTotal: {
409
400
  amount: 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classytic/cart",
3
- "version": "0.2.1",
3
+ "version": "1.0.0",
4
4
  "description": "Framework-agnostic universal cart engine for commerce — drafts, checkouts, reservations, the LineKind strategy, and a disciplined finalization saga. Powered by MongoDB via @classytic/mongokit. Zero framework deps — usable from Arc, Express, Nest, Next.js, or raw Node.",
5
5
  "author": "Classytic",
6
6
  "type": "module",
@@ -83,23 +83,24 @@
83
83
  "release": "npm run push -- main && npm run release:tag && npm publish"
84
84
  },
85
85
  "peerDependencies": {
86
- "@classytic/mongokit": ">=3.18.0",
87
- "@classytic/primitives": ">=0.9.1",
88
- "@classytic/repo-core": ">=0.7.0",
86
+ "@classytic/mongokit": ">=3.32.0",
87
+ "@classytic/primitives": ">=0.20.0",
88
+ "@classytic/repo-core": ">=0.17.0",
89
89
  "mongoose": ">=9.4.1",
90
90
  "zod": ">=4.0.0"
91
91
  },
92
92
  "devDependencies": {
93
93
  "@biomejs/biome": "^2.4.13",
94
94
  "@classytic/dev-tools": "^0.2.0",
95
- "@classytic/mongokit": "^3.18.0",
96
- "@classytic/primitives": ">=0.5.0",
97
- "@classytic/repo-core": "^0.7.0",
95
+ "@classytic/mongokit": "^3.28.0",
96
+ "@classytic/primitives": ">=0.20.0",
97
+ "@classytic/repo-core": ">=0.20.0",
98
98
  "@types/node": "^25.5.0",
99
99
  "knip": "^6.7.0",
100
100
  "mongodb-memory-server": "^10.2.3",
101
101
  "mongoose": "^9.4.1",
102
- "tsdown": "^0.21.5",
102
+ "publint": "^0.3.23",
103
+ "tsdown": "^0.22.14",
103
104
  "typescript": "^5.7.0",
104
105
  "vitest": "^3.0.0",
105
106
  "zod": "^4.3.6"
@@ -119,5 +120,5 @@
119
120
  "mongodb",
120
121
  "mongoose"
121
122
  ],
122
- "license": "MIT"
123
+ "license": "SEE LICENSE IN LICENSE"
123
124
  }
@@ -1,27 +0,0 @@
1
- //#region src/domain/errors/cart.error.ts
2
- var CartError = class extends Error {
3
- /** Optional structured context for logging / debugging. */
4
- context;
5
- constructor(message, context) {
6
- super(message);
7
- this.name = new.target.name;
8
- this.context = context;
9
- Object.setPrototypeOf(this, new.target.prototype);
10
- }
11
- /**
12
- * Serialize to a wire-safe shape. Suitable for HTTP error bodies and
13
- * structured logging. Never includes stack frames.
14
- */
15
- toJSON() {
16
- return {
17
- name: this.name,
18
- code: this.code,
19
- category: this.category,
20
- message: this.message,
21
- retryable: this.retryable,
22
- context: this.context
23
- };
24
- }
25
- };
26
- //#endregion
27
- export { CartError as t };
@@ -1 +0,0 @@
1
- export { };