@base44/app-plugin-commerce 0.5.0 → 0.6.0
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 +2 -2
- package/package.json +1 -1
- package/skills/commerce/SKILL.md +56 -49
- package/skills/commerce/install/01-install.md +1 -1
- package/skills/commerce/install/02-storefront.md +178 -154
- package/skills/commerce/references/catalog-rendering.md +2 -2
- package/skills/commerce/references/storefront-verification.md +0 -4
- package/src/commerce/storefront/AddressFields.jsx +150 -0
- package/src/commerce/storefront/StorefrontProvider.jsx +3 -10
- package/src/commerce/storefront/cartUI.jsx +17 -63
- package/src/commerce/storefront/index.js +10 -32
- package/src/commerce/storefront/useCheckout.jsx +0 -27
- package/src/commerce/utils/index.js +4 -1
- package/src/commerce/utils/specs.js +95 -10
- package/skills/commerce/references/storefront-custom.md +0 -150
- package/skills/commerce/references/storefront-parts.md +0 -184
- package/src/commerce/storefront/parts/cart.jsx +0 -191
- package/src/commerce/storefront/parts/checkout.jsx +0 -540
- package/src/commerce/storefront/parts/drawer.jsx +0 -87
- package/src/commerce/storefront/parts/labels.jsx +0 -140
- package/src/commerce/storefront/parts/orderReceived.jsx +0 -200
- package/src/commerce/storefront/parts/parts.css +0 -215
- package/src/commerce/storefront/parts/shared.jsx +0 -137
- package/src/commerce/storefront/parts/visibility.js +0 -36
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ It provides a full-featured **commerce data model and behavior** (variant-driven
|
|
|
12
12
|
- **Shared commerce engine** (`base44/shared/commerce/`) — totals, tax, shipping, coupons, stock, order lifecycle, webhook dispatch (HMAC-signed), emails, card-payment plumbing, plus static country/currency/continent data.
|
|
13
13
|
- **Admin UI** (`src/commerce/admin/`) — a React/Tailwind/shadcn admin with a familiar store back-office information architecture: dashboard, orders, products, coupons, customers, reports, and full settings including webhooks. Admin-role gated.
|
|
14
14
|
- **Storefront helpers** (`src/commerce/utils/`) — framework-free, dependency-free modules for the shopfront you build: `storefront.js` is the API client (`createStorefront(base44)` — cart-token lifecycle, cached store-info, catalog/cart/checkout/reviews/return-page calls); `variants.js` maps an attribute selection (Size, Color) onto a `ProductVariation` and back, plus per-option availability and price ranges; `price.js` encodes the from-price and price-range rules; `totals.js` projects a cart *or* an order into one summary shape; `address-spec.js` is the checkout address form as data; `images.js` and `ribbons.js` normalize the two catalog fields that are arrays of objects (`{src, name, alt}` images, `{id, name}` ribbons) rather than strings; `types.js` writes the catalog shapes down as JSDoc typedefs (`StorefrontProduct` and the rest), so what a field holds is answerable from the frontend; `shipping-promos.js` reads the store's real free-shipping configuration so "Free shipping over €150" states a configured rule rather than an invented number.
|
|
15
|
-
- **Storefront React layer** (`src/commerce/storefront/`) —
|
|
15
|
+
- **Storefront React layer** (`src/commerce/storefront/`) — **headless: the logic is premade, the UI never is.** Nothing in the layer renders markup or carries CSS; every element, class and word of copy in the storefront you build is yours, so a brief like "make it feel like <site>" applies to the whole store, checkout included. **It ships no customer-facing copy either**: where a state needs words you get the *state* — `buy.state`, a picker's `hint.code`, the checkout's `blockers`, a review's `status` — and write the sentence. What ships is every piece of logic that is the same in all stores: `StorefrontProvider` (+ `useStorefront`/`useStoreInfo`/`useFormatMoney`/`useCountries`), `useProductList`/`useCategories`/`useRibbons`, `useProduct`/`useAddToCart`, `useCart`/`useCartLine` (+ `useCartUI`/`CartUIProvider` for a drawer), `useCheckout`/`CheckoutProvider`/`useCheckoutContext`, `useOrderReturn`/`orderReceivedUrl` — plus three render-prop components that stay just as headless (`ShippingMethodPicker`/`PaymentMethodPicker` for the two checkout choices that are store data, `CartLine` for per-row cart bindings), one deliberately rendered-but-unstyled component (`AddressFields` — the checkout address form, whose state/province and `autoComplete` mechanics are where hand-rolled forms break; it ships no CSS and styles via `data-part` selectors or class props), and the framework-free view-model helpers re-exported so one import line covers a page (`variantAxes`, `productPrice`, `productImages`, `productRibbons`, `productSpecs`, `attributesLabel`, `cartTotalsLines`/`orderTotalsLines`, `addressFieldSpec`). Each hook's doc comment states the render rules that keep a store correct (an unbuyable variant option renders disabled, not hidden; a receipt page must render `paymentInstructions`; …) and names its return type from `storefront/types.js`, so a page reads a field's shape off the hook instead of off a backend function. Needs React and nothing else.
|
|
16
16
|
- **StoreAdmin agent + bot** — an AI copilot (`base44/agents/commerce/StoreAdmin.jsonc`, registered as `commerce/StoreAdmin`) with the `commerce/*` functions attached directly as tools (calls run as the chatting user → `requireAdmin()` still applies), variant-aware order editing, plus a chat panel in the admin sidebar with GFM markdown-table rendering.
|
|
17
17
|
- **Docs** — this README plus the commerce skill folder [`skills/commerce/`](./skills/commerce/): [`SKILL.md`](./skills/commerce/SKILL.md) is the map every agent starts from (and the only path the platform needs to know); [`install/`](./skills/commerce/install/) holds the three stage files that are the whole install (`01-install` → `02-storefront` → `03-data`, each read at the moment its work starts and dropped when its checklist passes); [`references/`](./skills/commerce/references/) holds per-topic guides opened only on demand; [`docs/`](./skills/commerce/docs/) holds the data-model map ([`entities.md`](./skills/commerce/docs/entities.md)) and the two API references. The whole folder is installed into the app at `.agents/skills/commerce/` so agents pick it up natively.
|
|
18
18
|
|
|
@@ -104,7 +104,7 @@ If you build on Base44's hosted platform, use the Base44 agent/MCP to write the
|
|
|
104
104
|
|
|
105
105
|
## What's NOT included
|
|
106
106
|
|
|
107
|
-
- **No storefront *design*.** The parts of a shopfront that carry a brand — the home page, the collection grid, the product card, the product page's layout, the theme
|
|
107
|
+
- **No storefront *design*.** The parts of a shopfront that carry a brand — the home page, the collection grid, the product card, the product page's layout, the theme — ship as nothing at all, on purpose: that is the work a build should spend its effort on. Everything under those surfaces does ship: the storefront API and the hooks that own the logic of every surface (catalog, product, cart, checkout, order-received, reviews) — the markup, styling and copy on top of them stay yours, including the commodity screens — see [`skills/commerce/install/02-storefront.md`](./skills/commerce/install/02-storefront.md) for how the two tiers fit together, [`skills/commerce/references/catalog-rendering.md`](./skills/commerce/references/catalog-rendering.md) for what each catalog call returns, and [`skills/commerce/docs/api-storefront.md`](./skills/commerce/docs/api-storefront.md) for the raw API.
|
|
108
108
|
- **No payment provider — and cards are off by default.** The order side of card payments is premade (see above), but charging a card needs a provider, so `commerce/seed-store` enables the manual **`offline`** method (bank transfer, cash on delivery, pickup — no code, no credentials) and leaves the **`card`** gateway **switched off**. **Enable cards only if a provider is wired, or is about to be** — implement the four functions in `base44/shared/commerce/card-payment.ts`, or for Stripe copy the shipped `card-payment.stripe.ts` over it and use it as-is (`skills/commerce/references/online-payments.md`), then enable the gateway via the seed's `payment_methods: ["offline", "card"]`; enabled with nothing behind it, checkout answers `503 no_card_payment_provider`. The rule and why it belongs at the end of a build rather than its start: `skills/commerce/install/03-data.md`.
|
|
109
109
|
- **No scheduled workflows shipped.** Base44 *does* have a scheduler, but this template ships no workflow files — time-based jobs (stock-hold release, cart expiry, webhook-log pruning) run **opportunistically** where possible, and for the rest you (or the Base44 agent) create scheduled workflows that call `commerce/admin-tools`/`commerce/admin-orders` actions — see [`skills/commerce/references/operations.md`](./skills/commerce/references/operations.md).
|
|
110
110
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44/app-plugin-commerce",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
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",
|
package/skills/commerce/SKILL.md
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: commerce
|
|
3
|
-
description: Base44 Commerce — commerce.* entities, commerce/* backend functions (storefront + admin APIs, payments, webhooks), the shared engine under base44/shared/commerce/, the Store Management UI at /store-admin, and the headless storefront
|
|
3
|
+
description: Base44 Commerce — commerce.* entities, commerce/* backend functions (storefront + admin APIs, payments, webhooks), the shared engine under base44/shared/commerce/, the Store Management UI at /store-admin, and the headless storefront hooks under src/commerce/. Read before working on store features: installing, building a storefront, seeding a catalog, shipping zones, payments, or the admin.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Commerce
|
|
7
7
|
|
|
8
8
|
**This file is the map. It tells you what to read, when, and what you can skip.**
|
|
9
|
+
Nothing else in this skill needs to be open right now.
|
|
9
10
|
|
|
10
11
|
The kit ships, already written and tested: 20 `commerce.*` entities, the
|
|
11
12
|
`commerce/*` backend functions (storefront API, admin API, payments, webhooks,
|
|
@@ -15,14 +16,16 @@ emails), the shared engine, a complete admin back office at `/store-admin`, the
|
|
|
15
16
|
store's *UI and data*, not the plumbing.
|
|
16
17
|
|
|
17
18
|
**Paths in this skill** are relative to the skill's folder
|
|
18
|
-
(`.agents/skills/commerce/` in an installed app) wherever they are named
|
|
19
|
-
|
|
19
|
+
(`.agents/skills/commerce/` in an installed app), wherever they are named —
|
|
20
|
+
docs, checklists, code comments. Resolve them from the skill folder, never from
|
|
21
|
+
the file that mentioned them.
|
|
20
22
|
|
|
21
23
|
## Installing right now?
|
|
22
24
|
|
|
23
|
-
Read **[`install/01-install.md`](./install/01-install.md)** and follow it
|
|
25
|
+
Read **[`install/01-install.md`](./install/01-install.md)** and follow it. It
|
|
24
26
|
routes you to `install/02-storefront.md` when you start the UI and
|
|
25
|
-
`install/03-data.md` when you seed
|
|
27
|
+
`install/03-data.md` when you seed the catalog — in that order, at those
|
|
28
|
+
moments. Read nothing else up front.
|
|
26
29
|
|
|
27
30
|
## Four things to hold from the start
|
|
28
31
|
|
|
@@ -43,51 +46,54 @@ routes you to `install/02-storefront.md` when you start the UI and
|
|
|
43
46
|
takes manual (`offline`) payment and works end to end; cards are a late,
|
|
44
47
|
deliberate step ([`install/03-data.md`](./install/03-data.md)).
|
|
45
48
|
|
|
46
|
-
## The storefront:
|
|
49
|
+
## The storefront: logic is premade, UI never is
|
|
47
50
|
|
|
48
|
-
**The
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
**The UI is yours, all of it** — every page, element, class and word of copy.
|
|
52
|
+
The kit deliberately ships **no markup and no CSS anywhere**; a brief like
|
|
53
|
+
"make it feel like <site>" is your work, done as you would with no kit. Encode
|
|
54
|
+
that identity **once** — design classes in `index.css`, spent across every
|
|
55
|
+
page — not as decoration re-typed on every element;
|
|
53
56
|
[`install/02-storefront.md`](./install/02-storefront.md) opens with the
|
|
54
|
-
method.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
57
|
+
method.
|
|
58
|
+
|
|
59
|
+
**The logic ships as headless hooks** (`@/commerce/storefront`) — checkout
|
|
60
|
+
repricing, variant resolution, cart state, coupon redemption, order-return
|
|
61
|
+
verification, cart-drawer state. Each returns **plain states and handlers**
|
|
62
|
+
(`status` to branch on, arrays to map, callbacks) — you write every element and
|
|
63
|
+
attribute from them. **Never re-implement what a hook does** — that is where
|
|
64
|
+
storefront bugs cluster.
|
|
65
|
+
|
|
66
|
+
One deliberate exception: **the checkout address form ships rendered**, as the
|
|
67
|
+
unstyled `<AddressFields>` component (the state/province field, `autoComplete`
|
|
68
|
+
tokens and address errors are exactly where hand-rolled forms break). Style it
|
|
69
|
+
with your classes; everything around it stays yours.
|
|
70
|
+
|
|
71
|
+
It ships **no copy**, either: where a state needs words you get the state
|
|
72
|
+
(`buy.state`, `hint.code`, `blockers`) and write the words in the store's voice.
|
|
73
|
+
A kit sentence rendered into every store is how storefronts end up alike.
|
|
68
74
|
|
|
69
75
|
```jsx
|
|
70
|
-
import {
|
|
76
|
+
import { useCart, CartLine } from "@/commerce/storefront";
|
|
77
|
+
const { status, cart } = useCart(); // branch on status, map cart.items into YOUR rows
|
|
71
78
|
```
|
|
72
79
|
|
|
73
|
-
The admin UI (`src/commerce/admin/`) is finished and **also yours to change**
|
|
74
|
-
([`docs/api-admin.md`](./docs/api-admin.md)
|
|
75
|
-
|
|
76
|
-
as a last resort when a user requirement outgrows their props.
|
|
80
|
+
The admin UI (`src/commerce/admin/`) is finished and **also yours to change** —
|
|
81
|
+
restyle it, add pages, rework flows ([`docs/api-admin.md`](./docs/api-admin.md)
|
|
82
|
+
is the backend it talks to).
|
|
77
83
|
|
|
78
84
|
Four rules the API enforces — a storefront that skips them cannot complete a
|
|
79
|
-
purchase. In React the hooks
|
|
80
|
-
|
|
85
|
+
purchase. In React the hooks implement all four; your markup renders what they
|
|
86
|
+
hand back (API-level statements for non-React clients:
|
|
81
87
|
[`docs/api-storefront.md`](./docs/api-storefront.md)):
|
|
82
88
|
|
|
83
89
|
1. A product with variants needs **one selector per attribute**, resolved to a
|
|
84
90
|
`variation_id` (`useProduct` + `variantAxes`).
|
|
85
91
|
2. Checkout must **recalculate shipping from the address and send a choice**
|
|
86
|
-
(
|
|
87
|
-
3.
|
|
88
|
-
|
|
92
|
+
(`useCheckout` — automatic).
|
|
93
|
+
3. **`/order-received` must exist** and render the return state, including a
|
|
94
|
+
manual order's payment instructions (`useOrderReturn`).
|
|
89
95
|
4. **Never advertise what isn't configured** — no free-shipping banner without
|
|
90
|
-
a real rate, no coupon codes without a
|
|
96
|
+
a real rate, no coupon codes without a field to redeem them in.
|
|
91
97
|
|
|
92
98
|
A fifth that breaks nothing but flattens the catalog, and is skipped most often:
|
|
93
99
|
**ribbons belong in both the grid and the product page**, each linking to its
|
|
@@ -108,14 +114,12 @@ Open a file when its work starts — not while planning.
|
|
|
108
114
|
| Topic | Open when | Size |
|
|
109
115
|
|---|---|---|
|
|
110
116
|
| [`install/01-install.md`](./install/01-install.md) | installing — routes you to 02 and 03 | 5K |
|
|
111
|
-
| [`install/02-storefront.md`](./install/02-storefront.md) | building storefront pages |
|
|
117
|
+
| [`install/02-storefront.md`](./install/02-storefront.md) | building storefront pages | 34K |
|
|
112
118
|
| [`install/03-data.md`](./install/03-data.md) | seeding catalog, shipping rates/zones, payments; re-callable per slice | 11K |
|
|
113
119
|
| [`docs/entities.md`](./docs/entities.md) | any direct entity read/write ("which entity holds X") | 11K |
|
|
114
120
|
| [`references/catalog-rendering.md`](./references/catalog-rendering.md) | field shapes each catalog call returns, variant edge cases | 16K |
|
|
115
121
|
| [`references/shipping-and-tax.md`](./references/shipping-and-tax.md) | zones beyond 03's recipe, taxes, day-2 edits | 8K |
|
|
116
122
|
| [`references/online-payments.md`](./references/online-payments.md) | enabling card payments, or wiring the provider — at install or any time later | 8K |
|
|
117
|
-
| [`references/storefront-parts.md`](./references/storefront-parts.md) | the parts' copy map, CSS selectors and control overrides | 10K |
|
|
118
|
-
| [`references/storefront-custom.md`](./references/storefront-custom.md) | a custom cart row / checkout section on the raw hooks | 8K |
|
|
119
123
|
| [`references/storefront-verification.md`](./references/storefront-verification.md) | driving the storefront from a browser script | 3K |
|
|
120
124
|
| [`references/reviews.md`](./references/reviews.md) | review policies (login-gated, verified buyers), moderation | 5K |
|
|
121
125
|
| [`references/store-settings.md`](./references/store-settings.md) | changing store behavior through settings keys | 5K |
|
|
@@ -127,13 +131,16 @@ Open a file when its work starts — not while planning.
|
|
|
127
131
|
| [`docs/api-storefront.md`](./docs/api-storefront.md) | filters, customer accounts, refunds, a non-React client | 31K |
|
|
128
132
|
| [`docs/api-admin.md`](./docs/api-admin.md) | changing admin pages, automating admin functions, the full seed contract | 24K |
|
|
129
133
|
|
|
130
|
-
**The read budget.** Content
|
|
131
|
-
call
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
134
|
+
**The read budget.** Content you pull into context is re-read on every later
|
|
135
|
+
call, so a file opened while planning costs many times what it costs opened at
|
|
136
|
+
the moment it is used. Open one reference when its task starts, take what you
|
|
137
|
+
need, and when a stage's checklist passes, record its carry-forward lines and
|
|
138
|
+
treat the file as gone.
|
|
139
|
+
|
|
140
|
+
**The install stages are self-contained.** Every request and response shape they
|
|
141
|
+
build against is written out in them — `install/02-storefront.md` carries a table
|
|
142
|
+
of exactly what each storefront hook resolves to. You should not need to open a
|
|
143
|
+
file under `src/commerce/` while building, and doing it mid-build is the most
|
|
144
|
+
expensive way to answer a question the stage already answers. (The source is
|
|
145
|
+
still the final authority if a doc and the code ever disagree — report that
|
|
146
|
+
rather than working around it.)
|
|
@@ -48,7 +48,7 @@ import { Navigate } from "react-router-dom";
|
|
|
48
48
|
- **The `/*` splat is required** — without it every nested admin link 404s. Mounting elsewhere: `<AdminApp basePath="/backoffice" />` (prefix without the splat).
|
|
49
49
|
- **Give `/` something** — a blank app has no `/` route, and "page not found" at the app's own URL reads like a broken install.
|
|
50
50
|
- **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.
|
|
51
|
-
- **`/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
|
|
51
|
+
- **`/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`).
|
|
52
52
|
|
|
53
53
|
## Admin-role enforcement — do not weaken
|
|
54
54
|
|