create-cartbase 0.1.0 → 0.1.2
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/dist/index.js +3 -3
- package/package.json +1 -1
- package/template/app/docs/BUILD-A-STOREFRONT.md +6 -6
- package/template/app/docs/README.md +77 -76
- package/template/app/docs/auth.md +1 -1
- package/template/app/docs/carts.md +6 -6
- package/template/app/docs/categories.md +1 -1
- package/template/app/docs/checkout.md +127 -76
- package/template/app/docs/collections.md +1 -1
- package/template/app/docs/components.md +59 -60
- package/template/app/docs/consent.md +1 -1
- package/template/app/docs/content.md +1 -1
- package/template/app/docs/customers.md +1 -1
- package/template/app/docs/deploy.md +5 -5
- package/template/app/docs/gift-cards.md +1 -1
- package/template/app/docs/integrations.md +1 -1
- package/template/app/docs/menus.md +1 -1
- package/template/app/docs/metaobjects.md +1 -1
- package/template/app/docs/orders.md +1 -1
- package/template/app/docs/platform.md +126 -0
- package/template/app/docs/products.md +1 -1
- package/template/app/docs/redirects.md +1 -1
- package/template/app/docs/regions.md +5 -6
- package/template/app/docs/reviews.md +1 -1
- package/template/app/docs/search.md +1 -1
- package/template/app/docs/subscriptions.md +1 -1
- package/template/app/docs/variables.md +315 -0
- package/template/app/next-env.d.ts +6 -0
- package/template/app/next.config.ts +3 -3
- package/template/app/package.json +1 -1
- package/template/app/smoke.mjs +1 -1
- package/template/app/src/app/checkout/checkout-page-client.tsx +26 -10
- package/template/app/src/app/checkout/mypos-demo-tab.tsx +101 -0
- package/template/app/src/app/checkout/page.tsx +5 -6
- package/template/app/src/app/layout.tsx +113 -105
- package/template/app/src/app/order/[id]/confirmed/page.tsx +5 -4
- package/template/app/src/lib/cart-actions.ts +47 -43
- package/template/app/src/lib/config.ts +10 -5
- package/template/app/tsconfig.tsbuildinfo +1 -1
package/dist/index.js
CHANGED
|
@@ -68,9 +68,9 @@ as flags they are written into .env.local, otherwise placeholders are.`);
|
|
|
68
68
|
const key = typeof flags.get("key") === "string" ? flags.get("key") : "";
|
|
69
69
|
fs.writeFileSync(path.join(target, ".env.local"), [
|
|
70
70
|
"# Your store's inputs — Cartbase admin, Settings.",
|
|
71
|
-
`
|
|
72
|
-
`
|
|
73
|
-
`
|
|
71
|
+
`NEXT_PUBLIC_CARTBASE_URL=${url}`,
|
|
72
|
+
`NEXT_PUBLIC_CARTBASE_CLIENT_ID=${clientId}`,
|
|
73
|
+
`NEXT_PUBLIC_CARTBASE_PUBLISHABLE_KEY=${key}`,
|
|
74
74
|
"",
|
|
75
75
|
].join("\n"));
|
|
76
76
|
const filled = url && clientId;
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Build a storefront
|
|
1
|
+
# Build a storefront
|
|
2
2
|
|
|
3
3
|
**This runbook takes you from a blank Next.js app to a completed checkout
|
|
4
4
|
against your Cartbase store.** It is written to be followed by a developer
|
|
@@ -12,9 +12,9 @@ What you need before starting (all three are in your Cartbase admin under
|
|
|
12
12
|
|
|
13
13
|
| Input | Example | Where it goes |
|
|
14
14
|
|---|---|---|
|
|
15
|
-
| API origin | `https://admin.bitfar.co` | `
|
|
16
|
-
| Store client id | `1e7a4c02-9b31-4f7e-8d2a-5c6f90ab12cd` (uuid) | `
|
|
17
|
-
| Publishable API key | `pk_…` (optional, channel scope) | `
|
|
15
|
+
| API origin | `https://admin.bitfar.co` | `NEXT_PUBLIC_CARTBASE_URL` |
|
|
16
|
+
| Store client id | `1e7a4c02-9b31-4f7e-8d2a-5c6f90ab12cd` (uuid) | `NEXT_PUBLIC_CARTBASE_CLIENT_ID` |
|
|
17
|
+
| Publishable API key | `pk_…` (optional, channel scope) | `NEXT_PUBLIC_CARTBASE_PUBLISHABLE_KEY` |
|
|
18
18
|
|
|
19
19
|
Sanity-check the store before writing any code:
|
|
20
20
|
|
|
@@ -73,7 +73,7 @@ whole checkout orchestration) only work same-origin. Unless your
|
|
|
73
73
|
storefront is served from the Cartbase deployment origin itself, proxy the
|
|
74
74
|
store surface through your own origin — in Next.js one rewrite does it —
|
|
75
75
|
and give the BROWSER client `window.location.origin` as `baseUrl`
|
|
76
|
-
(server-side calls hit `
|
|
76
|
+
(server-side calls hit `NEXT_PUBLIC_CARTBASE_URL` directly and are
|
|
77
77
|
unaffected; see `examples/storefront/next.config.ts` for the working
|
|
78
78
|
rewrite):
|
|
79
79
|
|
|
@@ -81,7 +81,7 @@ rewrite):
|
|
|
81
81
|
// next.config.ts — proxy browser SDK traffic to the API origin
|
|
82
82
|
async rewrites() {
|
|
83
83
|
return [{ source: "/api/store/:path*",
|
|
84
|
-
destination: `${process.env.
|
|
84
|
+
destination: `${process.env.NEXT_PUBLIC_CARTBASE_URL}/api/store/:path*` }]
|
|
85
85
|
}
|
|
86
86
|
```
|
|
87
87
|
|
|
@@ -1,76 +1,77 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
**Audience: an AGENT building a storefront from a blank Next.js app.** These
|
|
4
|
-
docs are the entire knowledge transfer — every call shape, every curl, every
|
|
5
|
-
setting, every component contract. If a storefront can't be built from these
|
|
6
|
-
files alone, the fix is a doc fix, never tribal knowledge.
|
|
7
|
-
|
|
8
|
-
Start at **[BUILD-A-STOREFRONT.md](BUILD-A-STOREFRONT.md)** — the runbook.
|
|
9
|
-
Domain files below are its reference chapters.
|
|
10
|
-
|
|
11
|
-
## Executable-docs contract (docs-truth CI)
|
|
12
|
-
|
|
13
|
-
Docs that can lie aren't bulletproof, so every ```bash block in every file
|
|
14
|
-
here is **extracted and executed** against the real test server by
|
|
15
|
-
`tests/docs/storefront-curls.test.ts`. A drifted doc FAILS the build.
|
|
16
|
-
|
|
17
|
-
Rules for doc authors (agents included):
|
|
18
|
-
|
|
19
|
-
1. All ```bash blocks in one file form ONE script, executed top-to-bottom
|
|
20
|
-
with `bash -euo pipefail`. Later blocks may use variables exported by
|
|
21
|
-
earlier blocks (`CART_ID=$(curl … | grep -o …)`).
|
|
22
|
-
2. The harness pre-exports: `BASE` (test-server origin), `CLIENT_ID` (dev
|
|
23
|
-
tenant id), `PUBLISHABLE_KEY` (the B2B-channel dev key — channel-scoped,
|
|
24
|
-
use only where the doc discusses key scoping).
|
|
25
|
-
3. Every curl uses `-sf` (silent + fail-on-HTTP-error) unless the block
|
|
26
|
-
demonstrates an error case — then capture the status explicitly
|
|
27
|
-
(`-o /dev/null -w '%{http_code}'`) and assert it (`test "$STATUS" = 404`).
|
|
28
|
-
4. Assert shape, not just liveness: pipe to `grep -q '"key"'` (or `node -e`
|
|
29
|
-
for anything structural). A block that checks nothing proves nothing.
|
|
30
|
-
5. A block that must NOT run (illustrative only, external side effects)
|
|
31
|
-
starts with `# doc-noexec` on its first line. Use sparingly — every
|
|
32
|
-
noexec block is a hole in the truth gate.
|
|
33
|
-
6. Blocks must be idempotent-safe on the shared dev tenant: create what you
|
|
34
|
-
read, suffix names with `$RUN` (pre-exported unique stamp), and clean up
|
|
35
|
-
in a final block when you created durable rows.
|
|
36
|
-
|
|
37
|
-
## Per-domain file format
|
|
38
|
-
|
|
39
|
-
One file per domain. For each endpoint, in order:
|
|
40
|
-
|
|
41
|
-
- **Purpose** — one sentence, when a storefront calls it.
|
|
42
|
-
- **Auth** — which headers (anon `x-client-id` / publishable key / Bearer).
|
|
43
|
-
- **Request** — method, path, query/body shape (jsonc block).
|
|
44
|
-
- **Response** — shape (jsonc block), with field notes.
|
|
45
|
-
- **Working curl** — executable per the contract above.
|
|
46
|
-
- **Errors** — status + `code` for every contract-listed failure.
|
|
47
|
-
- **SDK** — the `@cartbase/storefront/api` function that wraps it.
|
|
48
|
-
- **Components** — which `@cartbase/storefront` UI components consume it.
|
|
49
|
-
- **Settings** — admin settings that change its behavior (checkout rules,
|
|
50
|
-
locales, consent, accounts mode…).
|
|
51
|
-
|
|
52
|
-
## Files
|
|
53
|
-
|
|
54
|
-
| File | Domain |
|
|
55
|
-
|---|---|
|
|
56
|
-
| [BUILD-A-STOREFRONT.md](BUILD-A-STOREFRONT.md) | The agent runbook — blank app → completed checkout |
|
|
57
|
-
| [products.md](products.md) | Products, variants, pricing context |
|
|
58
|
-
| [search.md](search.md) | Search, facets, related products |
|
|
59
|
-
| [collections.md](collections.md) | Collections + membership listings |
|
|
60
|
-
| [categories.md](categories.md) | Categories, tags, types |
|
|
61
|
-
| [regions.md](regions.md) | Regions, currencies, locales |
|
|
62
|
-
| [carts.md](carts.md) | Cart lifecycle + line items |
|
|
63
|
-
| [gift-cards.md](gift-cards.md) | Gift-card tender on carts |
|
|
64
|
-
| [checkout.md](checkout.md) | Shipping options, payment providers/collections, prepare-checkout orchestration, complete |
|
|
65
|
-
| [orders.md](orders.md) | Order reads, display-id lookup, transfers |
|
|
66
|
-
| [customers.md](customers.md) | Customer profile, addresses, documents |
|
|
67
|
-
| [subscriptions.md](subscriptions.md) | Subscription portal: schedule control, contract edits, payment-method recovery |
|
|
68
|
-
| [auth.md](auth.md) | Passwordless code login + session discipline |
|
|
69
|
-
| [content.md](content.md) | Pages + blogs |
|
|
70
|
-
| [menus.md](menus.md) | Navigation menus |
|
|
71
|
-
| [metaobjects.md](metaobjects.md) | Merchant-defined content types |
|
|
72
|
-
| [reviews.md](reviews.md) | Review widget, token wizard, photo rewards |
|
|
73
|
-
| [integrations.md](integrations.md) | Store config: carriers, COD, tracking block, lockers |
|
|
74
|
-
| [consent.md](consent.md) | Consent Mode v2 banner config |
|
|
75
|
-
| [redirects.md](redirects.md) | 404-path URL redirects |
|
|
76
|
-
| [components.md](components.md) | UI component families: contracts + required SDK calls |
|
|
1
|
+
# Storefront docs
|
|
2
|
+
|
|
3
|
+
**Audience: an AGENT building a storefront from a blank Next.js app.** These
|
|
4
|
+
docs are the entire knowledge transfer — every call shape, every curl, every
|
|
5
|
+
setting, every component contract. If a storefront can't be built from these
|
|
6
|
+
files alone, the fix is a doc fix, never tribal knowledge.
|
|
7
|
+
|
|
8
|
+
Start at **[BUILD-A-STOREFRONT.md](BUILD-A-STOREFRONT.md)** — the runbook.
|
|
9
|
+
Domain files below are its reference chapters.
|
|
10
|
+
|
|
11
|
+
## Executable-docs contract (docs-truth CI)
|
|
12
|
+
|
|
13
|
+
Docs that can lie aren't bulletproof, so every ```bash block in every file
|
|
14
|
+
here is **extracted and executed** against the real test server by
|
|
15
|
+
`tests/docs/storefront-curls.test.ts`. A drifted doc FAILS the build.
|
|
16
|
+
|
|
17
|
+
Rules for doc authors (agents included):
|
|
18
|
+
|
|
19
|
+
1. All ```bash blocks in one file form ONE script, executed top-to-bottom
|
|
20
|
+
with `bash -euo pipefail`. Later blocks may use variables exported by
|
|
21
|
+
earlier blocks (`CART_ID=$(curl … | grep -o …)`).
|
|
22
|
+
2. The harness pre-exports: `BASE` (test-server origin), `CLIENT_ID` (dev
|
|
23
|
+
tenant id), `PUBLISHABLE_KEY` (the B2B-channel dev key — channel-scoped,
|
|
24
|
+
use only where the doc discusses key scoping).
|
|
25
|
+
3. Every curl uses `-sf` (silent + fail-on-HTTP-error) unless the block
|
|
26
|
+
demonstrates an error case — then capture the status explicitly
|
|
27
|
+
(`-o /dev/null -w '%{http_code}'`) and assert it (`test "$STATUS" = 404`).
|
|
28
|
+
4. Assert shape, not just liveness: pipe to `grep -q '"key"'` (or `node -e`
|
|
29
|
+
for anything structural). A block that checks nothing proves nothing.
|
|
30
|
+
5. A block that must NOT run (illustrative only, external side effects)
|
|
31
|
+
starts with `# doc-noexec` on its first line. Use sparingly — every
|
|
32
|
+
noexec block is a hole in the truth gate.
|
|
33
|
+
6. Blocks must be idempotent-safe on the shared dev tenant: create what you
|
|
34
|
+
read, suffix names with `$RUN` (pre-exported unique stamp), and clean up
|
|
35
|
+
in a final block when you created durable rows.
|
|
36
|
+
|
|
37
|
+
## Per-domain file format
|
|
38
|
+
|
|
39
|
+
One file per domain. For each endpoint, in order:
|
|
40
|
+
|
|
41
|
+
- **Purpose** — one sentence, when a storefront calls it.
|
|
42
|
+
- **Auth** — which headers (anon `x-client-id` / publishable key / Bearer).
|
|
43
|
+
- **Request** — method, path, query/body shape (jsonc block).
|
|
44
|
+
- **Response** — shape (jsonc block), with field notes.
|
|
45
|
+
- **Working curl** — executable per the contract above.
|
|
46
|
+
- **Errors** — status + `code` for every contract-listed failure.
|
|
47
|
+
- **SDK** — the `@cartbase/storefront/api` function that wraps it.
|
|
48
|
+
- **Components** — which `@cartbase/storefront` UI components consume it.
|
|
49
|
+
- **Settings** — admin settings that change its behavior (checkout rules,
|
|
50
|
+
locales, consent, accounts mode…).
|
|
51
|
+
|
|
52
|
+
## Files
|
|
53
|
+
|
|
54
|
+
| File | Domain |
|
|
55
|
+
|---|---|
|
|
56
|
+
| [BUILD-A-STOREFRONT.md](BUILD-A-STOREFRONT.md) | The agent runbook — blank app → completed checkout |
|
|
57
|
+
| [products.md](products.md) | Products, variants, pricing context |
|
|
58
|
+
| [search.md](search.md) | Search, facets, related products |
|
|
59
|
+
| [collections.md](collections.md) | Collections + membership listings |
|
|
60
|
+
| [categories.md](categories.md) | Categories, tags, types |
|
|
61
|
+
| [regions.md](regions.md) | Regions, currencies, locales |
|
|
62
|
+
| [carts.md](carts.md) | Cart lifecycle + line items |
|
|
63
|
+
| [gift-cards.md](gift-cards.md) | Gift-card tender on carts |
|
|
64
|
+
| [checkout.md](checkout.md) | Shipping options, payment providers/collections, prepare-checkout orchestration, complete |
|
|
65
|
+
| [orders.md](orders.md) | Order reads, display-id lookup, transfers |
|
|
66
|
+
| [customers.md](customers.md) | Customer profile, addresses, documents |
|
|
67
|
+
| [subscriptions.md](subscriptions.md) | Subscription portal: schedule control, contract edits, payment-method recovery |
|
|
68
|
+
| [auth.md](auth.md) | Passwordless code login + session discipline |
|
|
69
|
+
| [content.md](content.md) | Pages + blogs |
|
|
70
|
+
| [menus.md](menus.md) | Navigation menus |
|
|
71
|
+
| [metaobjects.md](metaobjects.md) | Merchant-defined content types |
|
|
72
|
+
| [reviews.md](reviews.md) | Review widget, token wizard, photo rewards |
|
|
73
|
+
| [integrations.md](integrations.md) | Store config: carriers, COD, tracking block, lockers |
|
|
74
|
+
| [consent.md](consent.md) | Consent Mode v2 banner config |
|
|
75
|
+
| [redirects.md](redirects.md) | 404-path URL redirects |
|
|
76
|
+
| [components.md](components.md) | UI component families: contracts + required SDK calls |
|
|
77
|
+
| [platform.md](platform.md) | Platform fingerprints: generator meta, window.Cartbase, x-cartbase-version header, cart cookie naming |
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Carts
|
|
1
|
+
# Carts
|
|
2
2
|
|
|
3
3
|
The cart is the storefront's working document: created anonymously, mutated
|
|
4
4
|
through line-item and update calls, completed into an order (see
|
|
@@ -118,8 +118,8 @@ test -n "$CART_ID" && test -n "$REGION_ID"
|
|
|
118
118
|
"item_total": 54, "item_subtotal": 45, "item_tax_total": 9,
|
|
119
119
|
"original_total": 54, "original_subtotal": 45, "original_tax_total": 9,
|
|
120
120
|
"credit_line_total": 0,
|
|
121
|
-
"
|
|
122
|
-
"
|
|
121
|
+
"payment_method_fee_total": 0, // the selected method's own fee — non-zero only with a live method session
|
|
122
|
+
"payment_method_fee_label": null,
|
|
123
123
|
// gift-card tender decoration (totals above NEVER move):
|
|
124
124
|
"gift_cards": [], // [{id, last4, amount}] in apply order
|
|
125
125
|
"gift_card_total": 0, // Σ applied-card coverage
|
|
@@ -305,11 +305,11 @@ curl -sf -X DELETE "$BASE/api/store/carts/$CART_ID/line-items/$LINE_ID" \
|
|
|
305
305
|
cart promotion and recomputes totals (automatic promotions layer in on
|
|
306
306
|
their own — only coded ones travel through here).
|
|
307
307
|
- **Auth** — anon `x-client-id`.
|
|
308
|
-
- **Request** — `{promo_codes: string[]}` on BOTH verbs (
|
|
309
|
-
|
|
308
|
+
- **Request** — `{promo_codes: string[]}` on BOTH verbs (the DELETE reads
|
|
309
|
+
its body, not query params).
|
|
310
310
|
- **Response** — `200 {cart}` (decorated; `cart.promotions` is the raw
|
|
311
311
|
pivot embed `[{promotion: {...}}]`). Unknown codes on REMOVE silently
|
|
312
|
-
no-op
|
|
312
|
+
no-op by design; on ADD they error.
|
|
313
313
|
- **Errors** — 404 `cart_not_found`; 404 `promotion_not_found` (unknown
|
|
314
314
|
code on add), 400 `promotion_inactive` (draft/expired code on add), 400
|
|
315
315
|
zod (empty array / non-string entries).
|