@base44/app-plugin-commerce 0.2.4 → 0.2.6
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 +1 -1
- package/skills/commerce/SKILL.md +64 -76
- package/skills/commerce/docs/api-admin.md +11 -50
- package/skills/commerce/docs/api-storefront.md +25 -118
- package/skills/commerce/install/01-install.md +20 -49
- package/skills/commerce/install/02-storefront.md +185 -319
- package/skills/commerce/install/03-data.md +43 -106
- package/skills/commerce/references/admin-product-form.md +26 -0
- package/skills/commerce/references/catalog-rendering.md +8 -8
- package/skills/commerce/references/online-payments.md +4 -15
- package/skills/commerce/references/operations.md +19 -1
- package/skills/commerce/references/storefront-verification.md +47 -0
- package/src/commerce/storefront/StorefrontProvider.jsx +45 -8
- package/src/commerce/storefront/cartUI.jsx +190 -0
- package/src/commerce/storefront/index.js +50 -20
- package/src/commerce/storefront/pickers.jsx +98 -23
- package/src/commerce/storefront/useAddressForm.js +71 -25
- package/src/commerce/storefront/useCartLine.js +40 -4
- package/src/commerce/storefront/useCheckout.jsx +13 -0
- package/src/commerce/storefront/useOrderReturn.js +7 -5
- package/src/commerce/storefront/usePlaceOrder.js +55 -0
- package/src/commerce/storefront/useProduct.js +93 -13
- package/src/commerce/storefront/useProductList.js +12 -0
- package/src/commerce/storefront/useUpsell.js +90 -0
- package/src/commerce/utils/index.js +3 -2
- package/src/commerce/utils/specs.js +104 -17
- package/src/commerce/utils/totals.js +23 -12
|
@@ -12,41 +12,23 @@ carry_forward:
|
|
|
12
12
|
|
|
13
13
|
# 01 — Install
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
**Inside the Base44 runtime, writing a resource file *is* the deploy** — the 20 `commerce.*` entities, the 16 `commerce/*` functions + shared engine, the StoreAdmin agent, the finished admin app (`src/commerce/admin/` — don't validate it, it ships tested) and the storefront hooks (`src/commerce/storefront/` + `utils/`) are live the moment the files exist. If `scripts/install.js` ran, all of that is already in place; there is no build step and nothing to push.
|
|
16
16
|
|
|
17
|
-
**
|
|
17
|
+
**Anonymous function calls must be allowed** in the app's settings — the storefront functions are public by design (they verify per action: auth session, `cart_token`, or `order_key`). If the app blocks unauthenticated invocation, every guest hits errors on the entire storefront.
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|---|---|
|
|
21
|
-
| `base44/entities/commerce.*.jsonc` | 20 entity schemas, all admin-only RLS |
|
|
22
|
-
| `base44/functions/commerce/` + `shared/` + `agents/` | 16 functions, the engine, the StoreAdmin copilot |
|
|
23
|
-
| `src/commerce/admin/` | the finished admin app — **don't validate it, it ships tested** |
|
|
24
|
-
| `src/commerce/storefront/` + `utils/` | the headless hooks you build the storefront UI on ([`./02-storefront.md`](./02-storefront.md)) |
|
|
25
|
-
| `.agents/skills/commerce/` | these docs |
|
|
26
|
-
|
|
27
|
-
<details>
|
|
28
|
-
<summary>CLI path (outside the runtime only — as a Base44 agent, skip all of it)</summary>
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
node examples/commerce/scripts/install.js # copies the table above
|
|
32
|
-
npx base44 entities push && npx base44 functions deploy && npx base44 agents push
|
|
33
|
-
```
|
|
34
|
-
Confirm `base44/config.jsonc`'s `entitiesDir`/`functionsDir` point at those folders (the defaults do). Granting a user the `admin` role is an operator step, not yours.
|
|
35
|
-
</details>
|
|
36
|
-
|
|
37
|
-
**Dependencies.** Check `package.json` for `sonner`, `recharts` and `react-markdown`, and `npm i` **only** the ones actually absent — all three ship with the default Base44 template, so the normal outcome is installing nothing. Never re-install a package that is already a dependency. The kit needs no other dependency; verify the shadcn primitives listed in `src/commerce/admin/README.md` exist.
|
|
19
|
+
**Dependencies.** `sonner`, `recharts`, `react-markdown` — all three ship with the default Base44 template, so check `package.json` and `npm i` only what is actually absent (the normal outcome is installing nothing).
|
|
38
20
|
|
|
39
21
|
## Work order — interleave, don't queue
|
|
40
22
|
|
|
41
|
-
Image generation is the slowest step
|
|
23
|
+
Image generation is the slowest step and nothing depends on it until seed time; the storefront doesn't wait on live data either.
|
|
42
24
|
|
|
43
25
|
1. **Start image generation first** — every product image, before anything else.
|
|
44
|
-
2. **Mount the admin (below) and build the storefront** while
|
|
45
|
-
3. **Seed the moment the image URLs are back** — one `commerce/seed-store` call ([`./03-data.md`](./03-data.md))
|
|
26
|
+
2. **Mount the admin (below) and build the storefront** while images render.
|
|
27
|
+
3. **Seed the moment the image URLs are back** — one `commerce/seed-store` call ([`./03-data.md`](./03-data.md)).
|
|
46
28
|
4. **Converge**: open the finished pages against the live catalog.
|
|
47
|
-
5. **Payments last, if at all** — cards are off by default
|
|
29
|
+
5. **Payments last, if at all** — cards are off by default; [`./03-data.md`](./03-data.md) decides it.
|
|
48
30
|
|
|
49
|
-
The only
|
|
31
|
+
The only dependency edges are *image URLs → seed payload* and *seed done → real products on the pages*.
|
|
50
32
|
|
|
51
33
|
## Mount the admin router
|
|
52
34
|
|
|
@@ -59,39 +41,28 @@ import { Navigate } from "react-router-dom";
|
|
|
59
41
|
<Route path="/order-received" element={<OrderReceived />} /> {/* mandatory — see below */}
|
|
60
42
|
```
|
|
61
43
|
|
|
62
|
-
- **The `/*` splat is required
|
|
63
|
-
- **Give `/` something
|
|
64
|
-
- **`/order-received` is mandatory**, even
|
|
44
|
+
- **The `/*` splat is required** — without it every nested admin link 404s. Mounting elsewhere: `<AdminApp basePath="/backoffice" />` (prefix without the splat).
|
|
45
|
+
- **Give `/` something** — a blank app has no `/` route, and "page not found" at the app's own URL reads like a broken install.
|
|
46
|
+
- **`/order-received` is mandatory**, even offline-only: every payment link returns there, and confirming is what marks an order paid — without it a paying customer hits a 404 and the order stays unpaid. The page is one hook, `useOrderReturn()` ([`./02-storefront.md`](./02-storefront.md)). A different path must be set in Settings → General (`general.order_received_path`).
|
|
65
47
|
|
|
66
48
|
## Admin-role enforcement — do not weaken
|
|
67
49
|
|
|
68
|
-
|
|
50
|
+
Three layers, all load-bearing; keep every one when touching routes or schemas:
|
|
69
51
|
|
|
70
|
-
|
|
52
|
+
1. **UI guard** — the shipped `AuthGuard` (requires `role === "admin"`; grant via the dashboard or `base44.users.inviteUser(email, "admin")`).
|
|
53
|
+
2. **Entity RLS** — every commerce entity is admin-only on all operations.
|
|
54
|
+
3. **Function guard** — every `commerce/admin-*` function and `commerce/seed-store` calls `requireAdmin()`: **401** unauthenticated, **403** not admin.
|
|
71
55
|
|
|
72
|
-
|
|
73
|
-
2. **Entity RLS** — every commerce entity carries `"user_condition": { "role": "admin" }` on all operations, so a direct SDK read or write by a non-admin is rejected by the backend.
|
|
74
|
-
3. **Function guard** — every `commerce/admin-*` function and `commerce/seed-store` calls `requireAdmin()` before touching data via the service role: **401** unauthenticated, **403** not an admin.
|
|
75
|
-
|
|
76
|
-
Bypassing the client guard therefore reaches nothing. Storefront functions are public on purpose and verify per action instead (auth session, `cart_token`, or `order_key`). The StoreAdmin agent has no entity tools and no service role for the same reason: its calls run with the chatting user's own credentials, so layer 3 still authorizes them.
|
|
77
|
-
|
|
78
|
-
Check the install at any point:
|
|
79
|
-
|
|
80
|
-
```js
|
|
81
|
-
const { data } = (await base44.functions.invoke("commerce/admin-tools", { action: "status" })).data;
|
|
82
|
-
// → { template_version, seeded, settings_groups, counts: { "commerce.Product": n, … },
|
|
83
|
-
// checks: { has_payment_gateways, has_default_location } }
|
|
84
|
-
```
|
|
56
|
+
Storefront functions are public on purpose (per-action verification, above). To check install state at any point: `commerce/admin-tools` `{ action: "status" }` ([`../docs/api-admin.md`](../docs/api-admin.md)).
|
|
85
57
|
|
|
86
58
|
## Done — forget this file
|
|
87
59
|
|
|
88
60
|
- [ ] `/store-admin/*` mounted with the splat, behind the shipped `AuthGuard`; the three enforcement layers untouched.
|
|
89
|
-
- [ ] `/` routes somewhere real
|
|
90
|
-
- [ ]
|
|
91
|
-
- [ ]
|
|
92
|
-
- [ ] Image generation is already running, or the store has no product images to make.
|
|
61
|
+
- [ ] `/` routes somewhere real; `/order-received` is a route.
|
|
62
|
+
- [ ] Anonymous function invocation is allowed in the app's settings.
|
|
63
|
+
- [ ] Missing dependencies (if any) installed; image generation already running.
|
|
93
64
|
|
|
94
|
-
Then continue: **[`./02-storefront.md`](./02-storefront.md) when you start building UI**, **[`./03-data.md`](./03-data.md) when you start the seed payload**. Do **not** read them now, and
|
|
65
|
+
Then continue: **[`./02-storefront.md`](./02-storefront.md) when you start building UI**, **[`./03-data.md`](./03-data.md) when you start the seed payload**. Do **not** read them now, and open no `references/` or `docs/` file during an install — a file read early costs its size on every later call.
|
|
95
66
|
|
|
96
67
|
Record these lines in your working notes; do not re-read this file.
|
|
97
68
|
|