create-cartbase 0.1.17 → 0.1.18

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,24 +1,24 @@
1
- {
2
- "name": "create-cartbase",
3
- "version": "0.1.17",
4
- "description": "Scaffold a Cartbase storefront: npm create cartbase my-store",
5
- "license": "MIT",
6
- "type": "module",
7
- "bin": {
8
- "create-cartbase": "./dist/index.js"
9
- },
10
- "files": [
11
- "dist",
12
- "template"
13
- ],
14
- "scripts": {
15
- "build": "bun scripts/build-template.mjs && tsc -p tsconfig.json",
16
- "prepack": "bun scripts/build-template.mjs && tsc -p tsconfig.json"
17
- },
18
- "engines": {
19
- "node": ">=20"
20
- },
21
- "devDependencies": {
22
- "typescript": "^5"
23
- }
24
- }
1
+ {
2
+ "name": "create-cartbase",
3
+ "version": "0.1.18",
4
+ "description": "Scaffold a Cartbase storefront: npm create cartbase my-store",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "bin": {
8
+ "create-cartbase": "./dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "template"
13
+ ],
14
+ "scripts": {
15
+ "build": "bun scripts/build-template.mjs && tsc -p tsconfig.json",
16
+ "prepack": "bun scripts/build-template.mjs && tsc -p tsconfig.json"
17
+ },
18
+ "engines": {
19
+ "node": ">=20"
20
+ },
21
+ "devDependencies": {
22
+ "typescript": "^5"
23
+ }
24
+ }
@@ -612,12 +612,22 @@ Domain doc for every call: [carts.md](carts.md); gift-card tender:
612
612
  added a moment ago carries `pending: true` and a placeholder id
613
613
  (`isPendingLine(line)`); its quantity and removal work at once and are
614
614
  sent to the real line when the platform has confirmed it.
615
+ - **A completed cart is no cart (since 0.18.1)** — Medusa's rule: the
616
+ platform still answers a completed cart and refuses every change to it
617
+ (`409 cart_completed`), so the drawer never holds one. Reading one, or
618
+ being told the stored cart is gone (`cart_not_found`), empties the drawer
619
+ and calls `onCartEnd`; an add aimed at such a cart starts a new cart with
620
+ the item. The checkout clears the cookie (`clearCartCookie`,
621
+ `lib/cookie-names`) and calls `forget()` the moment the order is placed,
622
+ Medusa's `removeCartId()`.
615
623
  - **Props contract** — `cart?: Cart|null` (server-fetched snapshot; prop
616
624
  updates win unless a change of the provider's own is on its way; leave it
617
625
  out and pass `cartId` so the page never waits for the cart),
618
626
  `client?: StorefrontClient` (enables `addLine`/`addItem`/
619
627
  `updateQuantity`/`removeItem`/`refresh`), `cartId?` (read in the browser
620
- on mount, through the queue, when no snapshot), `onCartChange?(cart)` (fires on every confirmed
628
+ on mount, through the queue, when no snapshot), `onCartEnd?()` (the cart
629
+ is over: clear the stored id; `onCartEnd={clearCartCookie}` for the
630
+ cookie), `onCartChange?(cart)` (fires on every confirmed
621
631
  change INCLUDING first-add cart creation — persist `cart.id` here),
622
632
  `onOptimisticError?(failure)` (the ops funnel for every failed
623
633
  optimistic mutation — wire to store logging; replaces the source's
@@ -628,7 +638,8 @@ Domain doc for every call: [carts.md](carts.md); gift-card tender:
628
638
  addLine(variantId, qty?, display?)` (answers `{ok: true, cart}` or
629
639
  `{ok: false, error}`, the platform's refusal with its `code`),
630
640
  `addItem(variantId, qty?, display?)` (the same, answering a boolean),
631
- `updateQuantity(lineId, qty), removeItem(lineId), refresh, canMutate,
641
+ `updateQuantity(lineId, qty), removeItem(lineId), refresh, forget`
642
+ (empties the drawer and calls `onCartEnd`), `canMutate,
632
643
  applyOptimistic, dispatchOptimistic, labels, hrefs}`.
633
644
  `applyOptimistic(action, serverAction)` stays for store-owned server
634
645
  actions; the SDK methods are the fast path.
@@ -9,7 +9,7 @@
9
9
  "typecheck": "tsc --noEmit"
10
10
  },
11
11
  "dependencies": {
12
- "@cartbase/storefront": "^0.18.0",
12
+ "@cartbase/storefront": "^0.18.1",
13
13
  "next": "16.2.4",
14
14
  "react": "19.2.4",
15
15
  "react-dom": "19.2.4"
@@ -10,6 +10,7 @@ import {
10
10
  type ConsentSettings,
11
11
  } from "@cartbase/storefront/tracking/consent"
12
12
  import { StorefrontLocaleProvider } from "@cartbase/storefront/locales"
13
+ import { clearCartCookie } from "@cartbase/storefront/lib/cookie-names"
13
14
  import { CART_COOKIE, CART_COOKIE_MAX_AGE, STORE_LOCALE } from "@/lib/config"
14
15
  import { browserClient } from "@/lib/browser-client"
15
16
 
@@ -47,6 +48,9 @@ export function Providers({
47
48
  next.id
48
49
  )};path=/;max-age=${CART_COOKIE_MAX_AGE};samesite=lax`
49
50
  }}
51
+ // The cart is over (ordered, or gone): forget the stored id, so the
52
+ // next add starts a new cart.
53
+ onCartEnd={clearCartCookie}
50
54
  >
51
55
  {children}
52
56
  <CartDrawerTemplate />