@base44/app-plugin-commerce 0.2.5 → 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.
@@ -12,41 +12,23 @@ carry_forward:
12
12
 
13
13
  # 01 — Install
14
14
 
15
- What lands in the app, how the admin gets mounted, and the order to do the rest of the work in.
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
- **Inside the Base44 runtime, writing a resource file *is* the deploy** entities, functions and the `commerce/StoreAdmin` agent go live the moment the files exist. Nothing to push, no build step. If `scripts/install.js` ran, everything below is already in place.
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
- | Copied to | What it is |
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 of the install and nothing depends on it until seed time. The storefront doesn't wait on live data either — every shape you build against is documented in [`./02-storefront.md`](./02-storefront.md). So:
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 the images render.
45
- 3. **Seed the moment the image URLs are back** — one `commerce/seed-store` call ([`./03-data.md`](./03-data.md)); don't idle on it, pick the response (slugs) up when you need it.
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 and nothing above depends on them ([`./03-data.md`](./03-data.md) decides it).
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 real dependency edges are *image URLs → seed payload* and *seed done → real products on the pages*. Everything else overlaps.
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.** The admin renders nested routes; a bare `path="/store-admin"` matches only the dashboard and every deeper link 404s. Mounting elsewhere: `<AdminApp basePath="/backoffice" />` — the prefix *without* the splat.
63
- - **Give `/` something.** A blank Base44 app has no `/` route, so after mounting only the admin the app's own URL renders "page not found", which reads exactly like a broken install. Redirect until the storefront exists.
64
- - **`/order-received` is mandatory**, even for a store that only ever takes offline payments. Every payment link (checkout, the admin's payment link, emails) returns there, and confirming is what marks an order paid — without the route a paying customer hits a 404 and the order stays unpaid. The page is one hook, `useOrderReturn()`, plus your markup for its states ([`./02-storefront.md`](./02-storefront.md)). A different path must be set in Settings → General → *Payment return path*.
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
- The shipped `AuthGuard` requires an authenticated user whose `role === "admin"`: not signed in → "Please sign in"; signed in without the role "Admin access required". Grant it in the Base44 dashboard or with `base44.users.inviteUser(email, "admin")`.
50
+ Three layers, all load-bearing; keep every one when touching routes or schemas:
69
51
 
70
- That guard is the **first of three layers**, and all three are load-bearing:
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
- 1. **UI guard** `AuthGuard` around every admin route (client-side; convenience and UX).
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 the storefront, or the redirect above.
90
- - [ ] `/order-received` is a route in the app's `<Routes>`.
91
- - [ ] `sonner` / `recharts` / `react-markdown` present (installed only if they were missing).
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 do not open any `references/` or `docs/` file during an install — the stage files say when one is genuinely needed, and a file read early costs its size on every later call.
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