@classytic/cart 0.1.2 → 0.2.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 +37 -0
- package/README.md +12 -2
- package/dist/{shipping.bridge-CmQFTgSE.d.mts → clock.port-BUe6Dk_M.d.mts} +27 -10
- package/dist/{create-cart-B4l61iKT.mjs → create-cart-Iqvlv0V2.mjs} +183 -24
- package/dist/domain/errors/index.d.mts +1 -1
- package/dist/domain/errors/index.mjs +2 -2
- package/dist/domain/index.d.mts +7 -7
- package/dist/domain/index.mjs +3 -3
- package/dist/domain/ports/index.d.mts +2 -2
- 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 +10 -1
- package/dist/engine/index.d.mts +1 -1
- package/dist/engine/index.mjs +1 -1
- package/dist/{errors-DzR7Pipp.mjs → errors-7Pd0yATM.mjs} +1 -26
- package/dist/{id.port-C7ygWLRU.d.mts → id.port-DitjeoHg.d.mts} +1 -19
- package/dist/{index-BFBUk6qT.d.mts → index-qfN8dZN9.d.mts} +6 -5
- package/dist/index.d.mts +41 -15
- package/dist/index.mjs +84 -27
- package/dist/{internal-event-bus-DKcDteh-.d.mts → internal-event-bus-vMG6v-e6.d.mts} +71 -6
- package/dist/{kind-registry-C1n47C7h.d.mts → kind-registry-D03c2VV5.d.mts} +1 -1
- package/dist/kinds/index.d.mts +2 -2
- package/dist/kinds/index.mjs +2 -2
- package/dist/{line-kind-Ck3fVXzG.d.mts → line-kind-CKOWafK0.d.mts} +11 -6
- package/dist/{reservation.entity-b5cZ1ojx.d.mts → reservation.entity-WdaZCJg9.d.mts} +3 -3
- package/dist/{price-changed.error-C-wGVcfc.mjs → stale-quote.error-BkFLXWo5.mjs} +30 -4
- package/dist/{state-transitions-e4z3Yhxb.mjs → state-transitions-Bm3lC2Uv.mjs} +2 -2
- package/dist/{state-transitions-X_Eix5Iw.d.mts → state-transitions-D8CRykBv.d.mts} +7 -7
- package/dist/{variant.kind-9P1DXdXu.d.mts → variant.kind-Cpo_Hh7G.d.mts} +65 -2
- package/dist/{variant.kind-DfEh2oku.mjs → variant.kind-z2gwH9Vo.mjs} +92 -10
- package/package.json +8 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as OperationContext, c as TaxBridge, d as InventoryBridge, f as ReservationRef, m as CatalogBridge, r as ShippingBridge, t as ClockPort, w as PricedLine, y as PromotionsBridge } from "./clock.port-BUe6Dk_M.mjs";
|
|
2
2
|
import { Money } from "@classytic/primitives/money";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
|
|
@@ -19,10 +19,10 @@ import { z } from "zod";
|
|
|
19
19
|
* cache to manage.
|
|
20
20
|
*
|
|
21
21
|
* **Staleness.** The snapshot can drift from the live catalog (product
|
|
22
|
-
* renamed, image updated).
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
22
|
+
* renamed, image updated). Checkout's pricingHash and expiry checks catch
|
|
23
|
+
* price drift. Display drift is almost always acceptable — the user already
|
|
24
|
+
* saw the name + image they wanted — but hosts that care about absolute
|
|
25
|
+
* freshness can refresh by calling `displayOf()`
|
|
26
26
|
* again from their own cron or webhook consumer.
|
|
27
27
|
*
|
|
28
28
|
* All fields are optional so hosts can populate only what they need.
|
|
@@ -70,7 +70,7 @@ interface ValidityPolicy {
|
|
|
70
70
|
/**
|
|
71
71
|
* reprice — silently re-run price() and continue. Suitable for bundles,
|
|
72
72
|
* group-buy, and other cases where drift is acceptable.
|
|
73
|
-
* error — abort
|
|
73
|
+
* error — abort checkout with StaleQuoteError; the client must
|
|
74
74
|
* re-display and re-confirm. Required for bids, timeslots,
|
|
75
75
|
* rentals, and anything auction-like.
|
|
76
76
|
* extend — treat as indefinitely valid. Only for catalog SKUs where
|
|
@@ -187,6 +187,11 @@ interface LineLike<TPayload = unknown> {
|
|
|
187
187
|
* one type; adding a new bridge to the engine does not break existing kinds.
|
|
188
188
|
*/
|
|
189
189
|
interface KindContext extends OperationContext {
|
|
190
|
+
/**
|
|
191
|
+
* Engine clock for deterministic validity windows. Older direct kind tests
|
|
192
|
+
* may omit it; engine-created contexts always provide it.
|
|
193
|
+
*/
|
|
194
|
+
readonly clock?: ClockPort;
|
|
190
195
|
/**
|
|
191
196
|
* Bridge registry. Keys match the bridge names in CartConfig. Values are
|
|
192
197
|
* typed via the interface augmentation in `engine-types.ts`.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as DraftStatus, r as ReservationStatus, t as CheckoutState } from "./cart-status.vo-CNJw4aaB.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { o as CheckoutFlowState } from "./state-transitions-
|
|
4
|
-
import { a as IdempotencyReplay, c as LineItem, o as OperationName } from "./kind-registry-
|
|
2
|
+
import { T as PricingSnapshot, g as AdjustmentSpec } from "./clock.port-BUe6Dk_M.mjs";
|
|
3
|
+
import { o as CheckoutFlowState } from "./state-transitions-D8CRykBv.mjs";
|
|
4
|
+
import { a as IdempotencyReplay, c as LineItem, o as OperationName } from "./kind-registry-D03c2VV5.mjs";
|
|
5
5
|
import { Money } from "@classytic/primitives/money";
|
|
6
6
|
|
|
7
7
|
//#region src/domain/entities/adjustment.entity.d.ts
|
|
@@ -44,11 +44,12 @@ var NotFoundError = class extends CartError {
|
|
|
44
44
|
//#endregion
|
|
45
45
|
//#region src/domain/errors/price-changed.error.ts
|
|
46
46
|
/**
|
|
47
|
-
* The
|
|
48
|
-
* the client supplied when initiating
|
|
47
|
+
* The stored pricing snapshot's hash does not match the `expectedPricingHash`
|
|
48
|
+
* the client supplied when initiating checkout. Fired from the cheap hash
|
|
49
|
+
* check before the checkout snapshot is frozen.
|
|
49
50
|
*
|
|
50
51
|
* This is a safety interlock: the client saw totals X, but by the time the
|
|
51
|
-
*
|
|
52
|
+
* checkout ran, totals are now Y. Rather than silently charging a different
|
|
52
53
|
* amount, the saga aborts with this error so the client re-displays and
|
|
53
54
|
* re-confirms.
|
|
54
55
|
*
|
|
@@ -68,4 +69,29 @@ var PriceChangedError = class extends CartError {
|
|
|
68
69
|
}
|
|
69
70
|
};
|
|
70
71
|
//#endregion
|
|
71
|
-
|
|
72
|
+
//#region src/domain/errors/stale-quote.error.ts
|
|
73
|
+
/**
|
|
74
|
+
* A priced line's validity window has elapsed. Fired during checkout's
|
|
75
|
+
* freshness check before the snapshot is frozen.
|
|
76
|
+
*
|
|
77
|
+
* Example: a bid line whose underlying auction moved to a new highest bid
|
|
78
|
+
* while the user was reviewing the cart.
|
|
79
|
+
*
|
|
80
|
+
* Clients should re-read the cart, show the updated state, and confirm again.
|
|
81
|
+
* Retryable with a new idempotency key.
|
|
82
|
+
*/
|
|
83
|
+
var StaleQuoteError = class extends CartError {
|
|
84
|
+
code = "cart/stale_quote";
|
|
85
|
+
category = "validation";
|
|
86
|
+
retryable = true;
|
|
87
|
+
constructor(lineId, kind, reason, details) {
|
|
88
|
+
super(`Line ${lineId} (${kind}) is no longer valid: ${reason}`, {
|
|
89
|
+
lineId,
|
|
90
|
+
kind,
|
|
91
|
+
reason,
|
|
92
|
+
...details
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
//#endregion
|
|
97
|
+
export { ConcurrencyError as i, PriceChangedError as n, NotFoundError as r, StaleQuoteError as t };
|
|
@@ -15,9 +15,9 @@ import { defineStateMachine } from "@classytic/primitives/state-machine";
|
|
|
15
15
|
const CheckoutStep = {
|
|
16
16
|
/** Step 1 — load draft + validate status + version. */
|
|
17
17
|
LoadDraft: 1,
|
|
18
|
-
/** Step 2 —
|
|
18
|
+
/** Step 2 — enforce stored snapshot freshness without extra bridge reads. */
|
|
19
19
|
Revalidate: 2,
|
|
20
|
-
/** Step 3 —
|
|
20
|
+
/** Step 3 — compare stored pricingHash with expectedPricingHash. */
|
|
21
21
|
Reprice: 3,
|
|
22
22
|
/** Step 4 — create the checkout document with the frozen snapshot. */
|
|
23
23
|
CreateCheckout: 4,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as CheckoutState } from "./cart-status.vo-CNJw4aaB.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { t as KindBridges } from "./line-kind-
|
|
4
|
-
import {
|
|
2
|
+
import { C as OperationContext, t as ClockPort } from "./clock.port-BUe6Dk_M.mjs";
|
|
3
|
+
import { t as KindBridges } from "./line-kind-CKOWafK0.mjs";
|
|
4
|
+
import { t as IdPort } from "./id.port-DitjeoHg.mjs";
|
|
5
5
|
import * as _$_classytic_primitives_state_machine0 from "@classytic/primitives/state-machine";
|
|
6
6
|
|
|
7
7
|
//#region src/domain/saga/saga-steps.d.ts
|
|
@@ -17,8 +17,8 @@ import * as _$_classytic_primitives_state_machine0 from "@classytic/primitives/s
|
|
|
17
17
|
* than a reverse walk of a multi-step chain.
|
|
18
18
|
*/
|
|
19
19
|
declare const CheckoutStep: {
|
|
20
|
-
/** Step 1 — load draft + validate status + version. */readonly LoadDraft: 1; /** Step 2 —
|
|
21
|
-
readonly Revalidate: 2; /** Step 3 —
|
|
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
22
|
readonly Reprice: 3; /** Step 4 — create the checkout document with the frozen snapshot. */
|
|
23
23
|
readonly CreateCheckout: 4; /** Step 5 — commit (host-called after its own external work succeeds). */
|
|
24
24
|
readonly Commit: 5;
|
|
@@ -29,8 +29,8 @@ type CheckoutStepNumber = (typeof CheckoutStep)[keyof typeof CheckoutStep];
|
|
|
29
29
|
/**
|
|
30
30
|
* Transient checkout flow state stored on the Checkout document.
|
|
31
31
|
*
|
|
32
|
-
* In the simplified later model, the flow is short (load →
|
|
33
|
-
*
|
|
32
|
+
* In the simplified later model, the flow is short (load → freshness check →
|
|
33
|
+
* hash check → create → commit/cancel) and each method is an atomic service
|
|
34
34
|
* call. There is no long-running saga, so this state is almost
|
|
35
35
|
* decorative — it records the last successful step for diagnostics.
|
|
36
36
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { r as LineKind } from "./line-kind-
|
|
1
|
+
import { r as LineKind } from "./line-kind-CKOWafK0.mjs";
|
|
2
|
+
import { Money } from "@classytic/primitives/money";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
|
|
4
5
|
//#region src/kinds/bundle.kind.d.ts
|
|
@@ -31,6 +32,68 @@ declare const bundlePayloadSchema: z.ZodObject<{
|
|
|
31
32
|
}, z.core.$strip>;
|
|
32
33
|
declare const bundleKind: LineKind<BundlePayload>;
|
|
33
34
|
//#endregion
|
|
35
|
+
//#region src/kinds/service-fee.kind.d.ts
|
|
36
|
+
/**
|
|
37
|
+
* `service-fee` — non-product upsell line for cart-wide add-ons.
|
|
38
|
+
*
|
|
39
|
+
* Models the per-order fees a host wants to surface as first-class line
|
|
40
|
+
* items: gift wrap, paper bag, rush handling, card-payment surcharge,
|
|
41
|
+
* cleaning fee on bookings, etc. Distinct from a product line because:
|
|
42
|
+
*
|
|
43
|
+
* - There is NO catalog SKU behind it. The line carries its own
|
|
44
|
+
* code + label + unit price; the host's "services" config table is
|
|
45
|
+
* the source of truth for valid codes (a 5-10 row JSON or collection
|
|
46
|
+
* in the host, not a catalog product).
|
|
47
|
+
* - It does NOT reserve inventory. There is nothing to ship; the fee
|
|
48
|
+
* ships with the products it accompanies (gift wrap goes in the same
|
|
49
|
+
* box as the gift).
|
|
50
|
+
* - It is NOT product-specific. One toggle on the cart adds the fee to
|
|
51
|
+
* the whole order; no need to attach a `modifierGroup` to every
|
|
52
|
+
* product the way catalog modifiers work.
|
|
53
|
+
*
|
|
54
|
+
* Use a catalog `modifierGroup` instead when the upsell is genuinely
|
|
55
|
+
* per-product (espresso → +decaf shot). Use this kind when the upsell is
|
|
56
|
+
* per-order (any cart → +gift wrap).
|
|
57
|
+
*
|
|
58
|
+
* Survives the cart → checkout snapshot → order trail naturally because
|
|
59
|
+
* `@classytic/order`'s OrderLine carries a free-form `kind: string` and
|
|
60
|
+
* the snapshot fields this kind populates (`sku`, `name`, `unitPrice`,
|
|
61
|
+
* `currency`, `requiresShipping: false`) are exactly the fields the
|
|
62
|
+
* order kernel persists. The order's `kind: 'service-fee'` discriminator
|
|
63
|
+
* lets refund / RMA / fulfillment handlers branch on the line type
|
|
64
|
+
* without inferring from the SKU shape.
|
|
65
|
+
*/
|
|
66
|
+
interface ServiceFeePayload {
|
|
67
|
+
/**
|
|
68
|
+
* Stable code for the service the host bills (`gift-wrap`, `paper-bag`,
|
|
69
|
+
* `rush-handling`, `card-surcharge`). The host's services config
|
|
70
|
+
* resolves the code to a price + label; this kind takes both as
|
|
71
|
+
* payload so the cart line carries the full pricing surface
|
|
72
|
+
* end-to-end (no per-render bridge call).
|
|
73
|
+
*/
|
|
74
|
+
code: string;
|
|
75
|
+
/**
|
|
76
|
+
* User-facing label rendered on the cart, receipt, and order detail
|
|
77
|
+
* (`Gift wrap`, `Paper bag`). Localized at call-site by the host.
|
|
78
|
+
*/
|
|
79
|
+
label: string;
|
|
80
|
+
/**
|
|
81
|
+
* Per-unit price for the service in minor units of the cart's
|
|
82
|
+
* currency (e.g. paisa for BDT). Multiplied by `quantity` for the
|
|
83
|
+
* line total.
|
|
84
|
+
*/
|
|
85
|
+
unitPrice: Money;
|
|
86
|
+
}
|
|
87
|
+
declare const serviceFeePayloadSchema: z.ZodObject<{
|
|
88
|
+
code: z.ZodString;
|
|
89
|
+
label: z.ZodString;
|
|
90
|
+
unitPrice: z.ZodObject<{
|
|
91
|
+
amount: z.ZodNumber;
|
|
92
|
+
currency: z.ZodString;
|
|
93
|
+
}, z.core.$strip>;
|
|
94
|
+
}, z.core.$strip>;
|
|
95
|
+
declare const serviceFeeKind: LineKind<ServiceFeePayload>;
|
|
96
|
+
//#endregion
|
|
34
97
|
//#region src/kinds/sku.kind.d.ts
|
|
35
98
|
/**
|
|
36
99
|
* `sku` — the plain retail LineKind.
|
|
@@ -111,4 +174,4 @@ declare const variantPayloadSchema: z.ZodObject<{
|
|
|
111
174
|
}, z.core.$strip>;
|
|
112
175
|
declare const variantKind: LineKind<VariantPayload>;
|
|
113
176
|
//#endregion
|
|
114
|
-
export { timeslotKind as a, skuKind as c,
|
|
177
|
+
export { timeslotKind as a, skuKind as c, serviceFeeKind as d, serviceFeePayloadSchema as f, bundlePayloadSchema as g, bundleKind as h, TimeslotPayload as i, skuPayloadSchema as l, BundlePayload as m, variantKind as n, timeslotPayloadSchema as o, BundleComponent as p, variantPayloadSchema as r, SkuPayload as s, VariantPayload as t, ServiceFeePayload as u };
|
|
@@ -49,7 +49,7 @@ const bundleKind = {
|
|
|
49
49
|
amount: 0,
|
|
50
50
|
currency: unitPrice.currency
|
|
51
51
|
},
|
|
52
|
-
validUntil: new Date(
|
|
52
|
+
validUntil: new Date((ctx.clock?.now() ?? /* @__PURE__ */ new Date()).getTime() + 900 * 1e3),
|
|
53
53
|
kindMeta: {
|
|
54
54
|
bundleRef: typed.payload.bundleRef,
|
|
55
55
|
componentCount: typed.payload.components.length
|
|
@@ -87,7 +87,7 @@ const bundleKind = {
|
|
|
87
87
|
postPromo: newTotal,
|
|
88
88
|
postPromoPostTax: newTotal
|
|
89
89
|
},
|
|
90
|
-
validUntil: new Date(
|
|
90
|
+
validUntil: new Date((ctx.clock?.now() ?? /* @__PURE__ */ new Date()).getTime() + 900 * 1e3)
|
|
91
91
|
},
|
|
92
92
|
delta
|
|
93
93
|
};
|
|
@@ -106,7 +106,89 @@ const bundleKind = {
|
|
|
106
106
|
imageUrl: bundle.primaryImage,
|
|
107
107
|
slug: bundle.slug,
|
|
108
108
|
variantLabel: `${typed.payload.components.length} items`,
|
|
109
|
-
capturedAt: /* @__PURE__ */ new Date()
|
|
109
|
+
capturedAt: ctx.clock?.now() ?? /* @__PURE__ */ new Date()
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/kinds/service-fee.kind.ts
|
|
115
|
+
const serviceFeePayloadSchema = z.object({
|
|
116
|
+
code: z.string().min(1).max(64),
|
|
117
|
+
label: z.string().min(1).max(120),
|
|
118
|
+
unitPrice: z.object({
|
|
119
|
+
amount: z.number().int().nonnegative(),
|
|
120
|
+
currency: z.string().length(3)
|
|
121
|
+
})
|
|
122
|
+
});
|
|
123
|
+
const serviceFeeKind = {
|
|
124
|
+
name: "service-fee",
|
|
125
|
+
payloadSchema: serviceFeePayloadSchema,
|
|
126
|
+
validity: { onStale: "extend" },
|
|
127
|
+
async validate(line) {
|
|
128
|
+
const parsed = serviceFeePayloadSchema.safeParse(line.payload);
|
|
129
|
+
if (!parsed.success) throw new KindError(this.name, "invalid payload shape", { details: { issues: parsed.error.issues } });
|
|
130
|
+
if (line.quantity < 1) throw new KindError(this.name, `quantity must be >= 1, got ${line.quantity}`);
|
|
131
|
+
if (line.currency !== parsed.data.unitPrice.currency) throw new KindError(this.name, `service fee currency ${parsed.data.unitPrice.currency} does not match cart currency ${line.currency}`);
|
|
132
|
+
},
|
|
133
|
+
async price(line) {
|
|
134
|
+
const typed = line;
|
|
135
|
+
const unitPrice = typed.overrideUnitPrice ?? typed.payload.unitPrice;
|
|
136
|
+
const lineTotal = {
|
|
137
|
+
amount: unitPrice.amount * typed.quantity,
|
|
138
|
+
currency: unitPrice.currency
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
lineId: typed.lineId,
|
|
142
|
+
unitPrice,
|
|
143
|
+
quantity: typed.quantity,
|
|
144
|
+
subtotals: {
|
|
145
|
+
prePromo: lineTotal,
|
|
146
|
+
postPromo: lineTotal,
|
|
147
|
+
postPromoPostTax: lineTotal
|
|
148
|
+
},
|
|
149
|
+
discountTotal: {
|
|
150
|
+
amount: 0,
|
|
151
|
+
currency: unitPrice.currency
|
|
152
|
+
},
|
|
153
|
+
taxTotal: {
|
|
154
|
+
amount: 0,
|
|
155
|
+
currency: unitPrice.currency
|
|
156
|
+
},
|
|
157
|
+
validUntil: null
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
async revalidate(_line, priced) {
|
|
161
|
+
return {
|
|
162
|
+
status: "unchanged",
|
|
163
|
+
priced
|
|
164
|
+
};
|
|
165
|
+
},
|
|
166
|
+
/**
|
|
167
|
+
* Two adds of the same service code merge by default (gift wrap +
|
|
168
|
+
* gift wrap = qty 2 of gift wrap). Hosts that want each add to stay
|
|
169
|
+
* separate (e.g. distinct rationale per fee) should call addItem with
|
|
170
|
+
* a custom note in the line metadata to differentiate.
|
|
171
|
+
*/
|
|
172
|
+
mergeKey(line) {
|
|
173
|
+
const typed = line;
|
|
174
|
+
if (!typed.payload?.code) return null;
|
|
175
|
+
return `service-fee:${typed.payload.code}`;
|
|
176
|
+
},
|
|
177
|
+
/**
|
|
178
|
+
* Display snapshot for the cart UI — there is no catalog product
|
|
179
|
+
* behind a fee, so we synthesize from the payload directly (no
|
|
180
|
+
* bridge call). The receipt / order detail render path uses these
|
|
181
|
+
* fields verbatim.
|
|
182
|
+
*/
|
|
183
|
+
async displayOf(line, ctx) {
|
|
184
|
+
const typed = line;
|
|
185
|
+
return {
|
|
186
|
+
name: typed.payload.label,
|
|
187
|
+
imageUrl: void 0,
|
|
188
|
+
slug: typed.payload.code,
|
|
189
|
+
variantLabel: void 0,
|
|
190
|
+
compareAtPrice: void 0,
|
|
191
|
+
capturedAt: ctx.clock?.now() ?? /* @__PURE__ */ new Date()
|
|
110
192
|
};
|
|
111
193
|
}
|
|
112
194
|
};
|
|
@@ -180,7 +262,7 @@ const skuKind = {
|
|
|
180
262
|
slug: product.slug,
|
|
181
263
|
variantLabel: product.variantLabel,
|
|
182
264
|
compareAtPrice: product.compareAtPrice,
|
|
183
|
-
capturedAt: ctx.
|
|
265
|
+
capturedAt: ctx.clock?.now() ?? /* @__PURE__ */ new Date()
|
|
184
266
|
};
|
|
185
267
|
}
|
|
186
268
|
};
|
|
@@ -234,7 +316,7 @@ const timeslotKind = {
|
|
|
234
316
|
amount: 0,
|
|
235
317
|
currency: unitPrice.currency
|
|
236
318
|
},
|
|
237
|
-
validUntil: new Date(
|
|
319
|
+
validUntil: new Date((ctx.clock?.now() ?? /* @__PURE__ */ new Date()).getTime() + TIMESLOT_VALIDITY_MS),
|
|
238
320
|
kindMeta: {
|
|
239
321
|
startsAt: typed.payload.startsAt,
|
|
240
322
|
endsAt: typed.payload.endsAt,
|
|
@@ -242,8 +324,8 @@ const timeslotKind = {
|
|
|
242
324
|
}
|
|
243
325
|
};
|
|
244
326
|
},
|
|
245
|
-
async revalidate(
|
|
246
|
-
if (priced.validUntil && priced.validUntil.getTime() <=
|
|
327
|
+
async revalidate(_line, priced, ctx) {
|
|
328
|
+
if (priced.validUntil && priced.validUntil.getTime() <= (ctx.clock?.now() ?? /* @__PURE__ */ new Date()).getTime()) return {
|
|
247
329
|
status: "invalid",
|
|
248
330
|
reason: "timeslot hold expired — the slot may no longer be available"
|
|
249
331
|
};
|
|
@@ -282,7 +364,7 @@ const timeslotKind = {
|
|
|
282
364
|
hour: "2-digit",
|
|
283
365
|
minute: "2-digit"
|
|
284
366
|
})}`,
|
|
285
|
-
capturedAt: /* @__PURE__ */ new Date()
|
|
367
|
+
capturedAt: ctx.clock?.now() ?? /* @__PURE__ */ new Date()
|
|
286
368
|
};
|
|
287
369
|
}
|
|
288
370
|
};
|
|
@@ -354,9 +436,9 @@ const variantKind = {
|
|
|
354
436
|
slug: product.slug,
|
|
355
437
|
variantLabel: product.variantLabel,
|
|
356
438
|
compareAtPrice: product.compareAtPrice,
|
|
357
|
-
capturedAt: /* @__PURE__ */ new Date()
|
|
439
|
+
capturedAt: ctx.clock?.now() ?? /* @__PURE__ */ new Date()
|
|
358
440
|
};
|
|
359
441
|
}
|
|
360
442
|
};
|
|
361
443
|
//#endregion
|
|
362
|
-
export { skuKind as a,
|
|
444
|
+
export { skuKind as a, serviceFeePayloadSchema as c, timeslotPayloadSchema as i, bundleKind as l, variantPayloadSchema as n, skuPayloadSchema as o, timeslotKind as r, serviceFeeKind as s, variantKind as t, bundlePayloadSchema as u };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@classytic/cart",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Framework-agnostic universal cart engine for commerce
|
|
3
|
+
"version": "0.2.0",
|
|
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",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -83,16 +83,18 @@
|
|
|
83
83
|
"release": "npm run push -- main && npm run release:tag && npm publish"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
|
-
"@classytic/mongokit": ">=3.
|
|
87
|
-
"@classytic/primitives": ">=0.
|
|
86
|
+
"@classytic/mongokit": ">=3.16.0",
|
|
87
|
+
"@classytic/primitives": ">=0.5.0",
|
|
88
|
+
"@classytic/repo-core": ">=0.6.0",
|
|
88
89
|
"mongoose": ">=9.4.1",
|
|
89
90
|
"zod": ">=4.0.0"
|
|
90
91
|
},
|
|
91
92
|
"devDependencies": {
|
|
92
93
|
"@biomejs/biome": "^2.4.13",
|
|
93
94
|
"@classytic/dev-tools": "^0.2.0",
|
|
94
|
-
"@classytic/mongokit": "^3.
|
|
95
|
-
"@classytic/primitives": ">=0.
|
|
95
|
+
"@classytic/mongokit": "^3.16.0",
|
|
96
|
+
"@classytic/primitives": ">=0.5.0",
|
|
97
|
+
"@classytic/repo-core": "^0.6.0",
|
|
96
98
|
"@types/node": "^25.5.0",
|
|
97
99
|
"knip": "^6.7.0",
|
|
98
100
|
"mongodb-memory-server": "^10.2.3",
|