@base44/app-plugin-commerce 0.8.3 → 0.8.4

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/README.md CHANGED
@@ -85,12 +85,18 @@ From your existing Base44 app:
85
85
  npx npq install <only the missing names> # npq audits the package before npm installs it
86
86
  ```
87
87
  See [`src/commerce/admin/README.md`](./src/commerce/admin/README.md) for the exact shadcn component list.
88
- 5. **Mount the admin router** in your app:
88
+ 5. **Mount the admin** as a layout route in your app's `src/App.jsx` — Base44 discovers an app's pages by reading the literal `<Route>` JSX in that file, so the screens that should be listed as pages are declared there and the rest run off a splat handled by the kit's own router:
89
89
  ```jsx
90
- import AdminApp from "@/commerce/admin";
90
+ import AdminApp, { AdminRoutes } from "@/commerce/admin";
91
91
  // inside your <Routes>:
92
- <Route path="/store-admin/*" element={<AdminApp />} />
92
+ <Route path="/store-admin" element={<AdminApp />}>
93
+ <Route index element={<Dashboard />} />
94
+ <Route path="orders" element={<OrdersList />} />
95
+ {/* …products, customers, coupons, reports… */}
96
+ <Route path="*" element={<AdminRoutes />} /> {/* editors, settings, webhooks */}
97
+ </Route>
93
98
  ```
99
+ Name the section they group under in `base44/ui.jsonc` (app-owned — edit in place): `{ "version": 1, "sections": [{ "path": "/store-admin/*", "name": "Store Management" }] }`
94
100
  6. **Grant yourself the `admin` role** (Base44 dashboard → users, or `users.inviteUser(email, "admin")`). The admin UI refuses non-admins.
95
101
  7. **Seed the store.** Either open `/store-admin` and click **Initialize store defaults** on the first-run setup screen, or call `commerce/seed-store` directly — it creates the settings groups, the payment gateway rows (`offline` enabled, `card` off — enable it only with a provider wired) and — unless you pass your own `locations` — a fallback Shipping & Tax Location, plus the catalog: pass `products` (whole products with attributes — variants, categories, ribbons and taxonomy are created internally) or `with_sample_data: true` for the generic demo. Either way pass `store_name` (the app's name) — it is required on a first seed and becomes both the email subject prefix and the sender name. Once the `general` settings group exists the store counts as ready and the first-run screen stops appearing. Worked example: [`skills/commerce/install/03-data.md`](./skills/commerce/install/03-data.md); the full payload contract: [`skills/commerce/docs/api-admin.md`](./skills/commerce/docs/api-admin.md). Shipping zones are part of the same call — `locations` takes `continents: ["EU"]` and `rest_of_world: true`, so "€20 in Europe, €100 worldwide" is six lines.
96
102
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44/app-plugin-commerce",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "description": "Base44 Commerce plugin — entities, backend functions, shared commerce engine, admin UI and the commerce skill, shipped as copyable source",
5
5
  "keywords": [
6
6
  "base44",
@@ -217,8 +217,10 @@
217
217
  "\n" +
218
218
  " 1. No deps to add: sonner, recharts and react-markdown ship with the default\n" +
219
219
  " Base44 template — check package.json and npm i only what is truly missing\n" +
220
- ' 2. Mount the admin router: <Route path="/store-admin/*" element={<AdminApp />} />\n' +
221
- " plus the mandatory /order-received route (useOrderReturn + your markup)\n" +
220
+ ' 2. Mount the admin in src/App.jsx: <Route path="/store-admin" element={<AdminApp />}>\n' +
221
+ " with the main screens as literal child <Route>s (that file is what the platform\n" +
222
+ ' discovers pages from) and <Route path="*" element={<AdminRoutes />} /> for the\n' +
223
+ " rest, plus the mandatory /order-received route (useOrderReturn + your markup)\n" +
222
224
  " 3. Seed the store — one commerce/seed-store call (store_name required) takes the\n" +
223
225
  " catalog, currency, shipping locations and payment methods\n" +
224
226
  " 4. CLI installs only: npx base44 agents push (the hosted runtime syncs agents on write)"
@@ -122,7 +122,7 @@ batch (above).
122
122
 
123
123
  | Topic | Open when | Size |
124
124
  |---|---|---|
125
- | [`install/01-install.md`](./install/01-install.md) | installing — routes you to 02 and 03 | 6K |
125
+ | [`install/01-install.md`](./install/01-install.md) | installing — routes you to 02 and 03 | 8K |
126
126
  | [`install/02-storefront.md`](./install/02-storefront.md) | building storefront pages | 38K |
127
127
  | [`install/03-data.md`](./install/03-data.md) | seeding catalog, shipping rates/zones, payments; re-callable per slice | 11K |
128
128
  | [`docs/entities.md`](./docs/entities.md) | any direct entity read/write ("which entity holds X") | 11K |
@@ -1,9 +1,10 @@
1
1
  ---
2
2
  stage: install/01
3
3
  read_when: "The commerce kit's files were just copied into the app, or you are installing it now."
4
- skip_when: "The admin already mounts at /store-admin/* behind the shipped AuthGuard and / routes somewhere real."
4
+ skip_when: "src/App.jsx already declares the admin's screens as literal <Route> JSX under a /store-admin layout route, and / routes somewhere real."
5
5
  forget_when: "The checklist at the bottom of this file passes (admin mounts, / routes somewhere real, /order-received exists)."
6
6
  carry_forward:
7
+ - "The admin's six picker-visible routes are literal <Route> JSX in src/App.jsx (the platform discovers pages by reading that file — an array or a .map() discovers nothing); the rest run off its <Route path=\"*\" element={<AdminRoutes />} />."
7
8
  - "Admin enforcement is three layers — AuthGuard (UI), admin-only entity RLS, requireAdmin() in every admin function. Never weaken any of them."
8
9
  - "/order-received must exist as a route: every payment link returns there, and confirming is what marks an order paid."
9
10
  - "The storefront header shows a visible \"Store manager\" link to /store-admin when the signed-in user's role is admin, and nothing for everyone else."
@@ -41,18 +42,33 @@ Image generation is the slowest step and nothing depends on it until seed time;
41
42
 
42
43
  The only dependency edges are *image URLs → seed payload* and *seed done → real products on the pages*.
43
44
 
44
- ## Mount the admin router
45
+ ## Mount the admin
45
46
 
46
- ```jsx
47
- import AdminApp from "@/commerce/admin";
48
- import { Navigate } from "react-router-dom";
47
+ The admin mounts as a **layout route in the app's own `src/App.jsx`**: the six screens the store owner opens from the builder are declared there as literal `<Route>` JSX, and everything deeper goes to `<AdminRoutes />` on a splat. The platform discovers an app's pages by reading that file — a screen declared anywhere else is unreachable from the page picker.
49
48
 
50
- <Route path="/store-admin/*" element={<AdminApp />} />
49
+ ```jsx
50
+ import AdminApp, { AdminRoutes } from "@/commerce/admin";
51
+ import Dashboard from "@/commerce/admin/pages/Dashboard"; // …and orders/OrdersList,
52
+ // products/ProductsList, customers/CustomersList, coupons/CouponsList, reports/Reports
53
+
54
+ {/* Literal JSX — the platform reads this file, it never runs it. Do not refactor into a map. */}
55
+ <Route path="/store-admin" element={<AdminApp />}>
56
+ <Route index element={<Dashboard />} />
57
+ <Route path="orders" element={<OrdersList />} />
58
+ <Route path="products" element={<ProductsList />} />
59
+ <Route path="customers" element={<CustomersList />} />
60
+ <Route path="coupons" element={<CouponsList />} />
61
+ <Route path="reports" element={<Reports />} />
62
+ <Route path="*" element={<AdminRoutes />} /> {/* editors, settings, webhooks */}
63
+ </Route>
51
64
  <Route path="/" element={<Navigate to="/store-admin" replace />} /> {/* until a storefront exists */}
52
65
  <Route path="/order-received" element={<OrderReceived />} /> {/* mandatory — see below */}
53
66
  ```
54
67
 
55
- - **The `/*` splat is required** without it every nested admin link 404s. Mounting elsewhere: `<AdminApp basePath="/backoffice" />` (prefix without the splat).
68
+ - **Those seven lines, as they are.** The splat is what keeps the app's listed pages to six instead of 26: `path="*"` is skipped, so the editors, settings tabs and webhook screens stay navigable without appearing there, and `<AdminRoutes />` still serves the admin's own 404.
69
+ - **Don't add `settings` to the list** — it is a tabbed layout around a nested route, so it only renders correctly from the splat.
70
+ - **Elsewhere than `/store-admin`**: change the layout route's path and pass the prefix — `<AdminApp basePath="/backoffice" />`; the children are unchanged.
71
+ - **Name the group** in `base44/ui.jsonc` — app-owned, so edit it in place, keep any other keys, never recreate a deleted one: `{ "version": 1, "sections": [{ "path": "/store-admin/*", "name": "Store Management" }] }`
56
72
  - **Give `/` something** — a blank app has no `/` route, and "page not found" at the app's own URL reads like a broken install.
57
73
  - **Link the admin from the storefront header** — otherwise the merchant has no way in but typing the URL. Resolve the signed-in user once (`base44.auth.me()`, rejection/no session = not an admin, never blocking the page) and render a plainly visible "Store manager" link to `/store-admin` in the header when `role === "admin"` — and nothing at all for everyone else.
58
74
  - **`/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`).
@@ -69,7 +85,7 @@ Storefront functions are public on purpose (per-action verification, above). To
69
85
 
70
86
  ## Done — forget this file
71
87
 
72
- - [ ] `/store-admin/*` mounted with the splat, behind the shipped `AuthGuard`; the three enforcement layers untouched.
88
+ - [ ] The `/store-admin` layout route is in `src/App.jsx` with its six literal `<Route>` screens and the `path="*"` → `<AdminRoutes />` splat; `base44/ui.jsonc` names the section; the three enforcement layers untouched.
73
89
  - [ ] `/` routes somewhere real; `/order-received` is a route.
74
90
  - [ ] The storefront header shows a visible `/store-admin` link to signed-in admins, and to nobody else.
75
91
  - [ ] Anonymous function invocation is allowed in the app's settings.
@@ -50,7 +50,7 @@ import AdminApp from "@/commerce/admin";
50
50
  <Route path="/product/:slug" element={<ProductPage />} />
51
51
  {/* /bag, /checkout, and /order-received — which is mandatory */}
52
52
  </Route>
53
- <Route path="/store-admin/*" element={<AdminApp />} /> {/* own chrome, outside the provider */}
53
+ <Route path="/store-admin" element={<AdminApp />}>…</Route> {/* own chrome, outside the provider */}
54
54
  </Routes>
55
55
  </BrowserRouter>
56
56
 
@@ -25,12 +25,20 @@ Tailwind + shadcn/ui + React Router) to get a full store back office.
25
25
  npx npq install <only the missing names> # npq audits the package before npm installs it
26
26
  ```
27
27
 
28
- 4. Mount the app in your router:
28
+ 4. Mount it as a layout route in the app's own `src/App.jsx` — that is the file
29
+ Base44 discovers an app's pages from, so the screens that should be listed as
30
+ pages are declared there literally, and the rest go to `<AdminRoutes />` on a
31
+ splat. The full step is the skill's `install/01-install.md`.
29
32
 
30
33
  ```jsx
31
- import AdminApp from "@/commerce/admin";
32
-
33
- <Route path="/store-admin/*" element={<AdminApp />} />
34
+ import AdminApp, { AdminRoutes } from "@/commerce/admin";
35
+
36
+ <Route path="/store-admin" element={<AdminApp />}>
37
+ <Route index element={<Dashboard />} />
38
+ <Route path="orders" element={<OrdersList />} />
39
+ {/* …products, customers, coupons, reports… */}
40
+ <Route path="*" element={<AdminRoutes />} />
41
+ </Route>
34
42
  // mounted elsewhere? → <AdminApp basePath="/backoffice" />
35
43
  ```
36
44
 
@@ -75,8 +83,8 @@ npx shadcn@latest add <component>
75
83
  ## Layout of this folder
76
84
 
77
85
  ```
78
- index.jsx AdminApp: providers → auth guard → layout → routes
79
- routes.jsx Route table + <AdminRoutes/>
86
+ index.jsx AdminApp: providers → auth guard → layout → <Outlet/>
87
+ routes.jsx Route table + <AdminRoutes/> (the splat handler App.jsx delegates to)
80
88
  layout/ AdminLayout, Sidebar, Topbar, AuthGuard (admin-role gate), AccessDenied
81
89
  bot/ StoreAdminBot (chat panel over the commerce/StoreAdmin agent), Markdown (GFM renderer)
82
90
  context/ SettingsContext (store settings + first-run seeding), BasePathContext
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
+ import { useOutlet } from "react-router-dom";
2
3
  import { Toaster } from "sonner";
3
4
  import AuthGuard from "./layout/AuthGuard";
4
5
  import AdminLayout from "./layout/AdminLayout";
@@ -6,27 +7,50 @@ import AdminRoutes from "./routes";
6
7
  import { SettingsProvider } from "./context/SettingsContext";
7
8
  import { BasePathProvider } from "./context/BasePathContext";
8
9
 
10
+ export { default as AdminRoutes } from "./routes";
11
+
9
12
  /**
10
13
  * The store admin application.
11
14
  *
12
- * Mount inside your app's router:
13
- * <Route path="/store-admin/*" element={<AdminApp />} />
15
+ * Mount it as a *layout route* in the app's own `src/App.jsx`: declare the few
16
+ * screens that should be listed among the app's pages there, as literal `<Route>`
17
+ * JSX, and hand everything deeper to `<AdminRoutes />` on a splat. Base44
18
+ * discovers an app's pages by reading that file rather than running it, so a
19
+ * route declared anywhere else is reachable by URL but never listed — and a
20
+ * splat is skipped by discovery, which is what keeps the editors and the
21
+ * settings tabs off the list while leaving them navigable.
22
+ *
23
+ * <Route path="/store-admin" element={<AdminApp />}>
24
+ * <Route index element={<Dashboard />} />
25
+ * <Route path="orders" element={<OrdersList />} />
26
+ * …
27
+ * <Route path="*" element={<AdminRoutes />} />
28
+ * </Route>
14
29
  *
15
30
  * If mounted somewhere other than /store-admin, pass the prefix:
16
- * <Route path="/backoffice/*" element={<AdminApp basePath="/backoffice" />} />
31
+ * <Route path="/backoffice" element={<AdminApp basePath="/backoffice" />}>
32
+ *
33
+ * The providers belong here, above the outlet, and must not be repeated per
34
+ * route: SettingsProvider fetches commerce.StoreSettings on mount, so wrapping
35
+ * each route would cost a round trip and a remounted sidebar on every admin
36
+ * navigation.
17
37
  *
18
38
  * Requires an authenticated user with role "admin" (enforced by AuthGuard,
19
39
  * and independently by entity RLS + requireAdmin() in backend functions).
20
40
  */
21
41
  export default function AdminApp({ basePath = "/store-admin" }) {
42
+ // Installs from before the routes moved into App.jsx mount the whole admin
43
+ // behind one splat route (`<Route path="/store-admin/*" element={<AdminApp />} />`)
44
+ // and declare no children, so nothing ever fills the outlet. Fall back to the
45
+ // kit's own router there rather than drawing an empty page area under the
46
+ // sidebar; those apps keep working until an agent rewrites their App.jsx.
47
+ const outlet = useOutlet();
22
48
  return (
23
49
  <BasePathProvider value={basePath}>
24
50
  <Toaster richColors position="top-right" />
25
51
  <AuthGuard>
26
52
  <SettingsProvider>
27
- <AdminLayout>
28
- <AdminRoutes />
29
- </AdminLayout>
53
+ <AdminLayout>{outlet ?? <AdminRoutes />}</AdminLayout>
30
54
  </SettingsProvider>
31
55
  </AuthGuard>
32
56
  </BasePathProvider>
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * Mount-path handling for the admin app.
3
3
  *
4
- * The admin is mounted with a splat route `<Route path="/store-admin/*">` and both
5
- * halves of that pattern leak into places they shouldn't: the `basePath` prop
4
+ * Installs from before the routes moved into App.jsx mount the admin with a splat
5
+ * route `<Route path="/store-admin/*">` and both halves of that pattern leak
6
+ * into places they shouldn't: the `basePath` prop
6
7
  * gets the pattern pasted in verbatim, and the literal URL `/store-admin/*` gets
7
8
  * opened (pattern copied into the address bar, or a nav link built from the
8
9
  * route table). Neither is a real page, so both are normalized here rather than
@@ -92,7 +92,20 @@ function UnmatchedRoute() {
92
92
  return isMountPatternPath(params["*"]) ? <Navigate to={href()} replace /> : <NotFound />;
93
93
  }
94
94
 
95
- /** All admin routes. Rendered inside AdminLayout; mount AdminApp at `/store-admin/*`. */
95
+ /**
96
+ * Every admin route, matched relative to the mount point.
97
+ *
98
+ * The app's `src/App.jsx` declares the handful of screens that should be listed
99
+ * among the app's pages — discovery only sees literal `<Route>` JSX in that file —
100
+ * and sends the rest here on a splat: `<Route path="*" element={<AdminRoutes />} />`.
101
+ * A descendant `<Routes>` needs exactly that trailing splat to resolve against.
102
+ * The overlap is deliberate: a path declared in App.jsx wins there, and the same
103
+ * entry here keeps this table complete for anything App.jsx does not name —
104
+ * `orders/:id` and the settings tabs among them.
105
+ *
106
+ * With no splat and no children at all — an install predating the move into
107
+ * App.jsx — `index.jsx` renders this component directly instead.
108
+ */
96
109
  export default function AdminRoutes() {
97
110
  return (
98
111
  <Routes>