@cartbase/storefront 0.5.0 → 0.6.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cartbase/storefront",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Storefront SDK + UI component library for Cartbase stores: typed API client, checkout orchestration, cart drawer, product/catalog components, tracking. Source-shipped TypeScript — add it to transpilePackages.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
package/src/api/products.ts
CHANGED
|
@@ -116,6 +116,13 @@ export interface StoreProductVariant {
|
|
|
116
116
|
* context. Varies by customer group — never cache shared.
|
|
117
117
|
*/
|
|
118
118
|
calculated_price: CalculatedPrice | null
|
|
119
|
+
/**
|
|
120
|
+
* THE availability predicate, computed server-side (untracked or
|
|
121
|
+
* backorderable ⇒ true; otherwise kit-aware available stock > 0).
|
|
122
|
+
* Optional only for wire back-compat with platforms that predate it —
|
|
123
|
+
* when absent, components fall back to the optimistic legacy behavior.
|
|
124
|
+
*/
|
|
125
|
+
in_stock?: boolean
|
|
119
126
|
}
|
|
120
127
|
|
|
121
128
|
export interface StoreProduct {
|
|
@@ -14,13 +14,12 @@
|
|
|
14
14
|
* - `countryCode` (Medusa region routing) is dropped — Cartbase pricing
|
|
15
15
|
* context travels with the product fetch, and the host's `addToCart`
|
|
16
16
|
* closes over whatever routing it needs.
|
|
17
|
-
* - Stock:
|
|
18
|
-
*
|
|
19
|
-
* 400 `insufficient_inventory`
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* quantity check.
|
|
17
|
+
* - Stock: the variant DTO carries `in_stock`, computed server-side by THE
|
|
18
|
+
* availability predicate — this component only reads it. The server still
|
|
19
|
+
* enforces stock at add (400 `insufficient_inventory` flips the button to
|
|
20
|
+
* the out-of-stock state). On a legacy wire without the field, managed
|
|
21
|
+
* variants fall back to the old optimistic behavior; richer DTOs carrying
|
|
22
|
+
* `inventory_quantity` keep the original quantity check.
|
|
24
23
|
*
|
|
25
24
|
* Variant matching is the extracted pure module `./variant-matching`
|
|
26
25
|
* (handles Cartbase's option-value link shape).
|
|
@@ -121,10 +120,17 @@ export function ProductActions({
|
|
|
121
120
|
|
|
122
121
|
const inStock = useMemo(() => {
|
|
123
122
|
if (!selectedVariant) return false
|
|
123
|
+
// The server computes THE availability predicate and emits it as
|
|
124
|
+
// `in_stock` on the variant DTO — read it, never re-derive it here
|
|
125
|
+
// (the hand-copied clauses this replaced could not see stock levels and
|
|
126
|
+
// showed an enabled Add to cart on sold-out variants until a 400).
|
|
127
|
+
if (typeof selectedVariant.in_stock === "boolean") {
|
|
128
|
+
return selectedVariant.in_stock && !stockExhausted
|
|
129
|
+
}
|
|
130
|
+
// Legacy wire (platform predates the field): optimistic fallback — the
|
|
131
|
+
// server still enforces stock on add.
|
|
124
132
|
if (!selectedVariant.manage_inventory) return true
|
|
125
133
|
if (selectedVariant.allow_backorder) return true
|
|
126
|
-
// Cartbase wire shape carries no inventory_quantity — optimistic; the
|
|
127
|
-
// server enforces stock on add. Richer DTOs keep the original check.
|
|
128
134
|
const qty = (selectedVariant as { inventory_quantity?: number })
|
|
129
135
|
.inventory_quantity
|
|
130
136
|
if (qty === undefined) return !stockExhausted
|