@base44/app-plugin-commerce 0.9.5 → 0.10.1

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
@@ -12,7 +12,8 @@ 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. Renders in the store's own theme, with a topbar toggle to a neutral Base44-dashboard palette and font for stores whose site theme makes the back office hard to read (colors and fonts only; remembered per browser). Localized — ships in English (default), German, Spanish, French, Japanese and Portuguese, switched by one line of code, with a documented recipe for adding any other language (no i18n dependency; see [`src/commerce/admin/README.md`](./src/commerce/admin/README.md) and the skill's `references/admin-localization.md`).
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/`) — **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.
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 catalog pages you build is yours, so a brief like "make it feel like <site>" applies to the pages that carry the store's identity. **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
+ - **Shipped conversion surfaces** (`src/commerce/storefront-ui/`) — **the four pages that must convert, finished**: `<CartPage />`, `<MiniCart />` (a real dialog: portal, focus trap, scroll-lock, opens on add-to-cart), `<CheckoutPage />` (addresses, shipping/payment choice, blockers, offline instructions and card redirect) and `<OrderReceivedPage />` (all return states incl. payment instructions), plus an optional `<CartButton />` header trigger. Built on the headless layer above; themed through a paired `--sfui-*` token block with shadcn-variable fallbacks and a runtime contrast guard (an unreadable pair falls back to the defaults), functional labels localized in six languages (`storefront-ui/i18n/`), brand wording via `brand` props, behavior via `sections`/`slots`. Kit-owned and re-copied on updates — customization goes through tokens/props/slots ([`skills/commerce/references/storefront-ui.md`](./skills/commerce/references/storefront-ui.md)), never file edits.
16
17
  - **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
18
  - **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
19
 
@@ -32,8 +33,10 @@ base44-commerce-template/
32
33
  │ └── commerce/
33
34
  │ ├── admin/ React admin UI (copy into your app's src/commerce/)
34
35
  │ ├── utils/ storefront helpers — API client, variants, price/totals rules
35
- └── storefront/ storefront React layer — headless hooks (catalog, cart,
36
- checkout, receipt); no markup, CSS or copy ships
36
+ ├── storefront/ storefront React layer — headless hooks (catalog, cart,
37
+ checkout, receipt); no markup, CSS or copy ships
38
+ │ └── storefront-ui/ shipped conversion surfaces — CartPage, MiniCart,
39
+ │ CheckoutPage, OrderReceivedPage; tokens + brand props
37
40
  ├── scripts/
38
41
  │ └── install.js static installer (run from <app>/examples/commerce/scripts/)
39
42
  ├── skills/
@@ -352,6 +352,10 @@ async function listAttributes(sr: any): Promise<any> {
352
352
  async function getStoreInfo(sr: any): Promise<any> {
353
353
  const settings = await getSettings(sr);
354
354
  const gateways = (await sr.entities["commerce.PaymentGateway"].filter({ enabled: true }, "order", 50)) ?? [];
355
+ // `has_coupons` lets a storefront decide whether to render a coupon field
356
+ // without knowing the seed: existence only, so day-2 coupons created in the
357
+ // admin start showing the field with no storefront change.
358
+ const anyCoupon = (await sr.entities["commerce.Coupon"].filter({}, undefined, 1)) ?? [];
355
359
  // Every enabled gateway is returned — the admin's Payments settings are the
356
360
  // single switch. `online: true` marks the card option (place-order answers
357
361
  // with a payment page to redirect to); everything else settles manually.
@@ -363,6 +367,7 @@ async function getStoreInfo(sr: any): Promise<any> {
363
367
  description: g.description ?? "",
364
368
  online: isCardGateway(g.slug),
365
369
  })),
370
+ has_coupons: anyCoupon.length > 0,
366
371
  countries: COUNTRIES,
367
372
  currencies: CURRENCIES,
368
373
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44/app-plugin-commerce",
3
- "version": "0.9.5",
3
+ "version": "0.10.1",
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",
@@ -198,6 +198,9 @@
198
198
  // headless shipping/payment pickers, order-received hook. Logic only, no
199
199
  // visual components: the shopfront's look stays the app's to design.
200
200
  { label: "storefront", from: ["src", "commerce", "storefront"], to: ["src", "commerce", "storefront"] },
201
+ // Shipped conversion surfaces — cart page, cart drawer, checkout,
202
+ // order-received — complete and tested; themed via tokens + brand props.
203
+ { label: "storefront-ui", from: ["src", "commerce", "storefront-ui"], to: ["src", "commerce", "storefront-ui"] },
201
204
  // Commerce skill — SKILL.md, install/post-install guides, references/
202
205
  // and docs/, the guidance agents read before working on the store.
203
206
  { label: "skills", from: ["skills", "commerce"], to: [".agents", "skills", "commerce"] },
@@ -54,56 +54,52 @@ and stop — never edit admin screens. Other:
54
54
  takes manual (`offline`) payment and works end to end; cards are a late,
55
55
  deliberate step ([`installation/install.md`](./installation/install.md)).
56
56
 
57
- ## The storefront: logic is premade, UI never is
58
-
59
- **The UI is yours, all of it**every page, element, class and word of copy.
60
- The kit deliberately ships **no markup and no CSS anywhere**; a brief like
61
- "make it feel like <site>" is your work, done as you would with no kit. Encode
62
- that identity **once** — design classes in `index.css`, spent across every
63
- page not as decoration re-typed on every element;
64
- [`installation/install.md`](./installation/install.md) opens with the
65
- method.
66
-
67
- **The logic ships as headless hooks** (`@/commerce/storefront`) checkout
68
- repricing, variant resolution, cart state, coupon redemption, order-return
69
- verification, cart-drawer state. Each returns **plain states and handlers**
70
- (`status` to branch on, arrays to map, callbacks) you write every element and
71
- attribute from them. **Never re-implement what a hook does** — that is where
72
- storefront bugs cluster.
73
-
74
- One deliberate exception: **the checkout address form ships rendered**, as the
75
- unstyled `<AddressFields>` component (the state/province field, `autoComplete`
76
- tokens and address errors are exactly where hand-rolled forms break). Style it
77
- with your classes; everything around it stays yours.
78
-
79
- It ships **no copy**, either: where a state needs words you get the state
80
- (`buy.state`, `hint.code`, `blockers`) and write the words in the store's voice.
81
- A kit sentence rendered into every store is how storefronts end up alike.
57
+ ## The storefront: the catalog is yours, the conversion surfaces ship
58
+
59
+ **The catalog UI collection and product pageis yours, all of it**: every
60
+ element, class and word of copy. A brief like "make it feel like <site>" is your
61
+ work, done as you would with no kit. Encode that identity **once** — design
62
+ classes in `index.css`, spent across every page — not as decoration re-typed on
63
+ every element; [`installation/install.md`](./installation/install.md) opens with
64
+ the method. Its logic ships as **headless hooks** (`@/commerce/storefront`)
65
+ variant resolution, cart state, pricing — returning plain states and handlers
66
+ (`status` to branch on, arrays to map); **never re-implement what a hook does**,
67
+ and where a state needs words you get the state (`buy.state`) and write them in
68
+ the store's voice.
69
+
70
+ **The conversion surfaces cart page, cart drawer, checkout, order received
71
+ ship finished** (`@/commerce/storefront-ui`): complete components with every
72
+ state handled and worded in six locales. Your job there is mounting them,
73
+ one `.sfui` theme-token block (paired colors — invisible text is structurally
74
+ impossible), and `brand` wording props. Never rebuild one, never edit their
75
+ files (kit updates re-copy the directory); day-2 changes go through
76
+ [`references/storefront-ui.md`](./references/storefront-ui.md).
82
77
 
83
78
  ```jsx
84
- import { useCart, CartLine } from "@/commerce/storefront";
85
- const { status, cart } = useCart(); // branch on status, map cart.items into YOUR rows
79
+ import { useProductList } from "@/commerce/storefront"; // catalog: YOUR pages on the hooks
80
+ import { CheckoutPage } from "@/commerce/storefront-ui"; // conversion: mount, theme, brand
86
81
  ```
87
82
 
88
83
  The admin UI (`src/commerce/admin/`) is finished and **also yours to change** —
89
84
  restyle it, add pages, rework flows ([`docs/api-admin.md`](./docs/api-admin.md)
90
85
  is the backend it talks to).
91
86
 
92
- Four rules the API enforces a storefront that skips them cannot complete a
93
- purchase. In React the hooks implement all four; your markup renders what they
94
- hand back (API-level statements for non-React clients:
87
+ Three rules the API enforces on the pages you build plus what the shipped
88
+ surfaces already cover (API-level statements for non-React clients:
95
89
  [`docs/api-storefront.md`](./docs/api-storefront.md)):
96
90
 
97
91
  1. A product with variants needs **one selector per attribute**, resolved to a
98
92
  `variation_id` (`useProduct` + `variantAxes`).
99
- 2. Checkout must **recalculate shipping from the address and send a choice**
100
- (`useCheckout` automatic).
101
- 3. **`/order-received` must exist** and render the return state, including a
102
- manual order's payment instructions (`useOrderReturn`).
103
- 4. **Never advertise what isn't configured** — no free-shipping banner without
104
- a real rate, no coupon codes without a field to redeem them in.
105
-
106
- A fifth that breaks nothing but flattens the catalog, and is skipped most often:
93
+ 2. **`/order-received` must exist** mount the shipped `<OrderReceivedPage />`;
94
+ every payment link returns there.
95
+ 3. **Never advertise what isn't configured** no free-shipping banner without a
96
+ real rate, no coupon codes named in your copy (the shipped surfaces show the
97
+ redemption field by themselves when coupons exist).
98
+
99
+ Shipping recalculation, payment choice, blockers and the offline/card order
100
+ flows are the shipped checkout's job not rules for you anymore.
101
+
102
+ A rule that breaks nothing but flattens the catalog, and is skipped most often:
107
103
  **ribbons belong in both the grid and the product page**, each linking to its
108
104
  filtered listing. They are the merchant's own merchandising.
109
105
 
@@ -123,11 +119,12 @@ as one file and arrive with the installer (above).
123
119
 
124
120
  | Topic | Open when | Size |
125
121
  |---|---|---|
126
- | [`installation/install.md`](./installation/install.md) | installing — all three stages: admin mount, storefront pages, then the seed payload | 59K |
122
+ | [`installation/install.md`](./installation/install.md) | installing — all three stages: admin mount, storefront pages, then the seed payload | 51K |
127
123
  | [`docs/entities.md`](./docs/entities.md) | any direct entity read/write ("which entity holds X") | 11K |
128
124
  | [`references/catalog-rendering.md`](./references/catalog-rendering.md) | field shapes each catalog call returns, variant edge cases | 16K |
129
125
  | [`references/shipping-and-tax.md`](./references/shipping-and-tax.md) | zones beyond stage 03's recipe, taxes, day-2 edits | 8K |
130
126
  | [`references/online-payments.md`](./references/online-payments.md) | enabling card payments, or wiring the provider — at install or any time later | 10K |
127
+ | [`references/storefront-ui.md`](./references/storefront-ui.md) | changing the shipped cart/drawer/checkout/order-received surfaces: props, slots, tokens, locales, restyling | 8K |
131
128
  | [`references/storefront-verification.md`](./references/storefront-verification.md) | driving the storefront from a browser script | 3K |
132
129
  | [`references/reviews.md`](./references/reviews.md) | review policies (open by default; login-gated, verified buyers), moderation | 6K |
133
130
  | [`references/store-settings.md`](./references/store-settings.md) | changing store behavior through settings keys | 5K |
@@ -2,7 +2,7 @@
2
2
 
3
3
  The raw HTTP/SDK surface behind a customer-facing shopfront. **A React storefront should not call most of it directly** — `src/commerce/storefront/` ships the logic layer, and this file is the reference for what lies beyond it, for non-React and headless clients, and for the exact payloads and error codes.
4
4
 
5
- **Logic is premade, UI never is.** In a React app every surface here — listing, product page, cart, checkout, the receipt, reviews — has a headless hook in `@/commerce/storefront` ([`../installation/install.md`](../installation/install.md) is the surface, one line per export). The hooks own the API calls and the branching below and hand you a view-model; **all markup, styling and copy are yours** — nothing in the kit renders UI or ships a word of customer-facing text. Never hand-roll a hook's logic. Framework-free helpers (API client, variant resolution, price and totals rules, free-shipping rules) live in `src/commerce/utils/`.
5
+ **Logic is premade.** In a React app every surface here — listing, product page, cart, checkout, the receipt, reviews — has a headless hook in `@/commerce/storefront` ([`../installation/install.md`](../installation/install.md) is the surface, one line per export), and the conversion surfaces (cart page, drawer, checkout, order received) additionally ship as **finished components** in `@/commerce/storefront-ui` — a React app mounts those rather than building them. The hooks own the API calls and the branching below and hand you a view-model; on the pages you build, markup, styling and copy are yours. Never hand-roll a hook's logic. Framework-free helpers (API client, variant resolution, price and totals rules, free-shipping rules) live in `src/commerce/utils/`.
6
6
 
7
7
  Entities and direct CRUD → [`entities.md`](./entities.md) · admin surface → [`api-admin.md`](./api-admin.md)
8
8