@stacksjs/defaults 0.75.618 → 0.75.622
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/ai/skills/stacks-actions/SKILL.md +1 -1
- package/ai/skills/stacks-auth/SKILL.md +12 -1
- package/ai/skills/stacks-auto-imports/SKILL.md +1 -1
- package/ai/skills/stacks-buddy/SKILL.md +70 -7
- package/ai/skills/stacks-commerce/SKILL.md +78 -4
- package/ai/skills/stacks-dashboard/SKILL.md +32 -2
- package/ai/skills/stacks-database/SKILL.md +1 -1
- package/ai/skills/stacks-development/SKILL.md +3 -0
- package/ai/skills/stacks-migrations/SKILL.md +10 -2
- package/ai/skills/stacks-mobile/SKILL.md +21 -2
- package/ai/skills/stacks-models/SKILL.md +2 -2
- package/ai/skills/stacks-native/CATALOG.md +21 -21
- package/ai/skills/stacks-orm/SKILL.md +2 -2
- package/ai/skills/stacks-utils/SKILL.md +8 -3
- package/app/Actions/Dashboard/Commerce/CommerceDiscountDestroyAction.ts +27 -0
- package/app/Actions/Dashboard/Commerce/CommerceDiscountStoreAction.ts +28 -0
- package/app/Actions/Dashboard/Commerce/CommerceDiscountUpdateAction.ts +30 -0
- package/app/Actions/Dashboard/Commerce/CommerceDiscountsAction.ts +42 -0
- package/app/Actions/Dashboard/Commerce/CommerceUpsellDestroyAction.ts +31 -0
- package/app/Actions/Dashboard/Commerce/CommerceUpsellDetailAction.ts +28 -0
- package/app/Actions/Dashboard/Commerce/CommerceUpsellStoreAction.ts +26 -0
- package/app/Actions/Dashboard/Commerce/CommerceUpsellUpdateAction.ts +29 -0
- package/app/Actions/Dashboard/Commerce/CommerceUpsellsAction.ts +40 -0
- package/app/Actions/Dashboard/Commerce/commerce-discount-list.ts +204 -0
- package/app/Actions/Dashboard/Commerce/commerce-discount-write.ts +53 -0
- package/app/Actions/Dashboard/Commerce/commerce-discounts-upsells.test.ts +228 -0
- package/app/Actions/Dashboard/Commerce/commerce-upsell-list.ts +289 -0
- package/app/Actions/Dashboard/Commerce/discount-records.ts +392 -0
- package/app/Actions/Dashboard/Commerce/upsell-offer-records.ts +307 -0
- package/app/Actions/Dashboard/Models/ModelSaveAction.ts +6 -1
- package/app/Actions/Dashboard/Models/model-relations.ts +17 -7
- package/app/Actions/Dashboard/Models/model-row-writes.ts +9 -8
- package/app/Actions/Dashboard/Models/model-write.ts +51 -2
- package/app/Actions/Dashboard/Remote/RemoteCommandRunAction.ts +1 -2
- package/app/Actions/Dashboard/Remote/RemoteTerminalCloseAction.ts +1 -2
- package/app/Actions/Dashboard/Remote/RemoteTerminalInputAction.ts +1 -2
- package/app/Actions/Dashboard/Remote/RemoteTerminalOpenAction.ts +1 -2
- package/app/Actions/Dashboard/Remote/RemoteTerminalResizeAction.ts +1 -2
- package/app/Actions/Dashboard/Remote/RemoteTerminalStreamAction.ts +1 -2
- package/app/Actions/Dashboard/Remote/remote-commands.test.ts +2 -2
- package/app/Actions/Dashboard/Remote/remote-commands.ts +4 -4
- package/app/Actions/Dashboard/Remote/remote-terminal.test.ts +45 -25
- package/app/Actions/Dashboard/Remote/remote-terminal.ts +9 -9
- package/app/Actions/Storefront/AcceptOrderOfferAction.ts +68 -0
- package/app/Actions/Storefront/ApplyDiscountCodeAction.ts +83 -0
- package/app/Actions/Storefront/DeclineOrderOfferAction.ts +25 -0
- package/app/Actions/Storefront/PlaceOrderAction.ts +135 -72
- package/app/Gates.ts +4 -4
- package/app/Mail/OrderConfirmation.ts +7 -1
- package/app/Models/commerce/Cart.ts +14 -0
- package/app/Models/commerce/Discount.ts +255 -0
- package/app/Models/commerce/PostPurchaseOffer.ts +175 -0
- package/app/Models/commerce/PostPurchaseOfferResponse.ts +145 -0
- package/app/Policies/PostPolicy.ts +11 -11
- package/app/Storefront/DiscountCodeMessages.ts +12 -0
- package/app/Storefront/OrderKey.ts +29 -0
- package/app/Storefront/StorefrontPricing.ts +211 -0
- package/app/Storefront/UpsellCharge.ts +43 -0
- package/functions/projects.test.ts +38 -0
- package/functions/projects.ts +99 -0
- package/ide/vscode/package.json +1 -1
- package/package.json +7 -7
- package/resources/components/Dashboard/Commerce/CommerceDiscountBreakdown.stx +72 -0
- package/resources/components/Dashboard/Commerce/CommerceDiscountDeleteDialog.stx +19 -0
- package/resources/components/Dashboard/Commerce/CommerceDiscountDetailsDialog.stx +110 -0
- package/resources/components/Dashboard/Commerce/CommerceDiscountDialog.stx +353 -0
- package/resources/components/Dashboard/Commerce/CommerceDiscountsDashboard.stx +211 -0
- package/resources/components/Dashboard/Commerce/CommerceDiscountsTable.stx +105 -0
- package/resources/components/Dashboard/Commerce/CommerceProductPicker.stx +115 -0
- package/resources/components/Dashboard/Commerce/CommerceUpsellDeleteDialog.stx +21 -0
- package/resources/components/Dashboard/Commerce/CommerceUpsellDetailsDialog.stx +153 -0
- package/resources/components/Dashboard/Commerce/CommerceUpsellDialog.stx +191 -0
- package/resources/components/Dashboard/Commerce/CommerceUpsellsDashboard.stx +214 -0
- package/resources/components/Dashboard/Commerce/CommerceUpsellsTable.stx +91 -0
- package/resources/components/Dashboard/Email/InboxSettingsDashboard.stx +4 -19
- package/resources/components/Dashboard/ProjectSwitcher.stx +302 -0
- package/resources/components/Dashboard/Settings/SettingsDashboard.stx +5 -3
- package/resources/components/Dashboard/UI/SearchFilter.stx +7 -4
- package/resources/components/Storefront/OrderSummary.stx +17 -0
- package/resources/functions/dashboard/project-switcher.test.ts +14 -0
- package/resources/functions/dashboard/project-switcher.ts +28 -0
- package/resources/functions/dashboard/sidebar.ts +4 -1
- package/resources/plugins/preloader.ts +33 -2
- package/resources/views/cart.stx +50 -16
- package/resources/views/checkout/contact.stx +11 -5
- package/resources/views/checkout/payment.stx +11 -5
- package/resources/views/checkout/shipping.stx +11 -5
- package/resources/views/orders/[id].stx +227 -50
- package/routes/dashboard-api.ts +12 -0
- package/routes/dashboard.ts +2 -0
- package/routes/storefront.ts +8 -0
- package/views/dashboard/commerce/discounts/index.stx +10 -0
- package/views/dashboard/commerce/upsells/index.stx +10 -0
- package/views/dashboard/layouts/default.stx +17 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: stacks-actions
|
|
3
|
-
description: Use when working with Stacks server actions - creating actions in app/Actions/, auto-generated API actions from the useApi model trait, the
|
|
3
|
+
description: Use when working with Stacks server actions - creating actions in app/Actions/, auto-generated API actions from the useApi model trait, the 778 default framework actions (auth, dashboard, commerce, content, deployment, jobs), action request/response handling, or action registration. Covers @stacksjs/actions and storage/framework/defaults/app/Actions/.
|
|
4
4
|
license: MIT
|
|
5
5
|
compatibility: Bun >= 1.3.0, TypeScript
|
|
6
6
|
allowed-tools: Read Edit Write Bash Grep Glob
|
|
@@ -360,6 +360,17 @@ objects can cross bundle copies; arbitrary objects, forged prototypes and
|
|
|
360
360
|
accessor fields are rejected. A conflicting shared-state version/shape refuses
|
|
361
361
|
module initialization. This does not synchronize different processes or Workers.
|
|
362
362
|
|
|
363
|
+
### The user a gate receives: `GateUser`
|
|
364
|
+
Every gate callback, policy method, `Gate.*` check and RBAC helper takes
|
|
365
|
+
`GateUser | null`. That is the User row (`AuthUser`, what `User.find` returns,
|
|
366
|
+
carried by the router's request and passed by `request.can()`) or the
|
|
367
|
+
`AuthenticatedUser` that `request.user()` gives an action typed with
|
|
368
|
+
`RequestInstance` from `@stacksjs/types`. They are the same object; pass either
|
|
369
|
+
with no cast. Annotate a callback with `GateUser | null` from `@stacksjs/auth`,
|
|
370
|
+
or leave it unannotated and let `defineGates` infer it. Not the ORM's
|
|
371
|
+
`UserModel`: no User row satisfies that hand-written interface
|
|
372
|
+
(stacksjs/stacks#3314).
|
|
373
|
+
|
|
363
374
|
### Gate Functions
|
|
364
375
|
- `define<T>(ability: string, callback: GateCallback<T>): void`
|
|
365
376
|
- `policy(model: string | { name }, policyClass: new () => Policy): void`
|
|
@@ -602,7 +613,7 @@ with the reason and whether the address was ever verified. It only lists.
|
|
|
602
613
|
|
|
603
614
|
## User Helpers (user.ts)
|
|
604
615
|
|
|
605
|
-
- `authUser(): Promise<
|
|
616
|
+
- `authUser(): Promise<AuthUser | undefined>` - `AuthUser` is the User row `User.find` returns
|
|
606
617
|
- `check(): Promise<boolean>`
|
|
607
618
|
- `id(): Promise<number | undefined>`
|
|
608
619
|
- `email(): Promise<string | undefined>`
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: stacks-auto-imports
|
|
3
|
-
description: Use before adding imports in Stacks app code, checking available runtime functions, browser/server delivery, model globals, or registry generation. Covers Stacks auto-imports, the generated runtime inventory, stx client delivery and server boot (
|
|
3
|
+
description: Use before adding imports in Stacks app code, checking available runtime functions, browser/server delivery, model globals, or registry generation. Covers Stacks auto-imports, the generated runtime inventory, stx client delivery and server boot (113 models).
|
|
4
4
|
license: MIT
|
|
5
5
|
compatibility: Bun >= 1.3.0, TypeScript
|
|
6
6
|
allowed-tools: Read Edit Write Bash Grep Glob
|
|
@@ -15,6 +15,9 @@ The complete CLI runtime for the Stacks framework, lazy-loaded for fast cold sta
|
|
|
15
15
|
- CLI entry point: `storage/framework/core/buddy/src/cli.ts`
|
|
16
16
|
- Commands directory: `storage/framework/core/buddy/src/commands/`
|
|
17
17
|
- Lazy command registry: `storage/framework/core/buddy/src/lazy-commands.ts`
|
|
18
|
+
- Launcher (which project, whose CLI): `storage/framework/core/buddy/src/launcher.ts`
|
|
19
|
+
- Machine project list and service records: `storage/framework/core/path/src/projects.ts`
|
|
20
|
+
- Background daemon: `storage/framework/core/actions/src/daemon/`
|
|
18
21
|
- Config system: `storage/framework/core/buddy/src/config.ts`
|
|
19
22
|
- Shell entry: `buddy` (shell script at project root that invokes `bun run ./storage/framework/core/buddy/src/cli.ts`)
|
|
20
23
|
- Application commands: `app/Commands/` (auto-discovered; no registration step)
|
|
@@ -25,6 +28,65 @@ The complete CLI runtime for the Stacks framework, lazy-loaded for fast cold sta
|
|
|
25
28
|
`./buddy`, `bud`, and `stacks` invoke the Stacks CLI. The `stx` binary belongs
|
|
26
29
|
to the STX template engine; use it for template and native screen compilation.
|
|
27
30
|
|
|
31
|
+
## One buddy for every project
|
|
32
|
+
|
|
33
|
+
Buddy is installed once (`bun add -g @stacksjs/buddy`) and serves every Stacks
|
|
34
|
+
project on the machine. Each invocation first settles two things in
|
|
35
|
+
`launcher.ts`, before any command module loads:
|
|
36
|
+
|
|
37
|
+
1. **Which project.** `--project <name|path>` when given (`-p` too, on the
|
|
38
|
+
built-in commands that declare it as the project), otherwise the nearest
|
|
39
|
+
ancestor of the working directory that `isProjectRoot` accepts. So
|
|
40
|
+
`buddy migrate` works from `app/Models`, and `buddy migrate --project shop`
|
|
41
|
+
works from anywhere. A name that matches no project, or more than one, is
|
|
42
|
+
refused rather than guessed.
|
|
43
|
+
2. **Whose code runs it.** A project that has its own `buddy` installed gets
|
|
44
|
+
the command handed to it (the process is replaced, not wrapped), so it runs
|
|
45
|
+
on the framework version that project pins. A project with nothing
|
|
46
|
+
installed is run by the buddy that was invoked.
|
|
47
|
+
|
|
48
|
+
The process that does the work always starts in the project root, because Bun
|
|
49
|
+
reads `bunfig.toml` and its preloads from the directory it starts in.
|
|
50
|
+
|
|
51
|
+
Machine-level commands are never handed to a project and run from any
|
|
52
|
+
directory: `new`, `create`, `projects`, `projects:*`, `cd`, `daemon`,
|
|
53
|
+
`daemon:*`, `dashboard`.
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
buddy projects # the projects on this machine, most recently used first
|
|
57
|
+
-q/--quiet # paths only, one per line
|
|
58
|
+
--json # the list as JSON
|
|
59
|
+
buddy projects:add [path] # add a project (the current one by default)
|
|
60
|
+
buddy projects:remove <name> # take one off the list (alias: projects:forget)
|
|
61
|
+
buddy projects:scan [dir] # find projects on disk and add them
|
|
62
|
+
buddy projects:prune # drop listed projects whose directory is gone
|
|
63
|
+
buddy cd <name> # print a project's path (--eval for a shell function)
|
|
64
|
+
|
|
65
|
+
buddy dashboard [project] # open a project's dashboard, started in the background if needed
|
|
66
|
+
--no-open # print the address without opening a browser
|
|
67
|
+
--stop # stop that project's background dashboard
|
|
68
|
+
|
|
69
|
+
buddy daemon # is buddy running in the background, and what is it running
|
|
70
|
+
buddy daemon:start # start it (nothing requires this; it starts on demand)
|
|
71
|
+
buddy daemon:stop # stop it and the dashboards it started
|
|
72
|
+
buddy daemon:restart
|
|
73
|
+
buddy daemon:logs # --lines <count>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
A project joins the list (`~/.stacks/projects/<id>.json`, one file each) the
|
|
77
|
+
first time buddy runs inside it. Read the list with `listProjects()` and
|
|
78
|
+
`findProject()` from `@stacksjs/path`; do not walk the filesystem for
|
|
79
|
+
projects. `findStacksProjects()` in `@stacksjs/utils` is the disk scan behind
|
|
80
|
+
`projects:scan` and nothing else should need it.
|
|
81
|
+
|
|
82
|
+
The daemon (`core/actions/src/daemon/`) starts a project's dashboard through
|
|
83
|
+
that project's own `./buddy dev:dashboard`, on a port reserved for that project
|
|
84
|
+
(3900 upwards, the same one every time), with no native window and an idle
|
|
85
|
+
limit. It listens on a unix socket in `~/.stacks/buddy/`, loads no project
|
|
86
|
+
code, polls nothing, and exits once it has no dashboards left. Reach it through
|
|
87
|
+
`openProjectDashboard()` / `daemonStatus()` in `@stacksjs/actions/daemon/client`,
|
|
88
|
+
which start it when it is not running.
|
|
89
|
+
|
|
28
90
|
## Architecture
|
|
29
91
|
|
|
30
92
|
### Lazy Loading System
|
|
@@ -650,11 +712,10 @@ buddy search # search engine operations
|
|
|
650
712
|
buddy configure # configure project
|
|
651
713
|
buddy create # create new project
|
|
652
714
|
buddy completion [shell] # shell completion (bash/zsh/fish)
|
|
653
|
-
buddy ports #
|
|
654
|
-
-
|
|
655
|
-
|
|
656
|
-
buddy ports:
|
|
657
|
-
buddy ports:check # check ports across all Stacks projects
|
|
715
|
+
buddy ports # the ports this project's servers use
|
|
716
|
+
-c/--check # which of them are free and which are in use
|
|
717
|
+
buddy ports:list # same list
|
|
718
|
+
buddy ports:check # which of this project's ports are free or in use
|
|
658
719
|
buddy setup # ensure project is set up correctly (alias: ensure)
|
|
659
720
|
--skip-aws # skip AWS configuration
|
|
660
721
|
--skip-keygen # skip APP_KEY generation
|
|
@@ -680,7 +741,7 @@ buddy auth # auth commands
|
|
|
680
741
|
buddy queue # queue management
|
|
681
742
|
buddy schedule # schedule management
|
|
682
743
|
buddy package # package management
|
|
683
|
-
buddy projects # project
|
|
744
|
+
buddy projects # the Stacks projects on this machine (see "One buddy for every project")
|
|
684
745
|
buddy prepublish # pre-publish checks
|
|
685
746
|
buddy stacks # Stacks framework commands (registered as 'stack' in lazy-commands)
|
|
686
747
|
```
|
|
@@ -767,7 +828,9 @@ export default {
|
|
|
767
828
|
|
|
768
829
|
## Gotchas
|
|
769
830
|
- Application commands go in `app/Commands/`, framework commands in `storage/framework/core/buddy/src/commands/`
|
|
770
|
-
- The `buddy` file at root is a shell script that
|
|
831
|
+
- The `buddy` file at root is a shell script that picks a usable Bun and runs the project's CLI entry: vendored `storage/framework/core/buddy/src/cli.ts` first, then `@stacksjs/buddy` from `node_modules`, then from `pantry`. `projectCliEntry()` in `@stacksjs/path` looks in the same places in the same order, and `buddy/tests/launcher.test.ts` fails when the two disagree
|
|
832
|
+
- `--project` is read by the launcher, before the command runs, and only for built-in commands. An application command's own `--project` is passed through untouched. `build`, `make`, `preview`, `serve`, `serve:api` and `share` use `-p` for something else, so only the long form selects a project there
|
|
833
|
+
- `buddy dev:dashboard` becomes the dashboard server (the CLI process is replaced) instead of waiting beside it
|
|
771
834
|
- Commands are lazy-loaded with a 5-second timeout per command to prevent startup hangs
|
|
772
835
|
- The `list` command loads ALL commands to display them
|
|
773
836
|
- When no command matches, the CLI loads only `version` for minimal overhead
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: stacks-commerce
|
|
3
|
-
description: Use when building e-commerce features in Stacks - the commerce namespace
|
|
3
|
+
description: Use when building e-commerce features in Stacks - the commerce namespace (products, carts, orders, customers, coupons, discounts, post-purchase upsells, payments, gift cards, auctions, shipping, tax, waitlists, restaurant, devices, receipts, errors), the commerce models, checkout, discount and redemption logic, or the commerce configuration. Covers @stacksjs/commerce.
|
|
4
4
|
license: MIT
|
|
5
5
|
compatibility: Bun >= 1.3.0, TypeScript
|
|
6
6
|
allowed-tools: Read Edit Write Bash Grep Glob
|
|
@@ -8,7 +8,7 @@ allowed-tools: Read Edit Write Bash Grep Glob
|
|
|
8
8
|
|
|
9
9
|
# Stacks Commerce
|
|
10
10
|
|
|
11
|
-
Comprehensive e-commerce module with
|
|
11
|
+
Comprehensive e-commerce module with 21 sub-modules in the `commerce` namespace and 42 models.
|
|
12
12
|
|
|
13
13
|
## Key Paths
|
|
14
14
|
- Core package: `storage/framework/core/commerce/src/`
|
|
@@ -20,12 +20,13 @@ Comprehensive e-commerce module with 15 sub-modules and 39 models.
|
|
|
20
20
|
```typescript
|
|
21
21
|
import { commerce } from '@stacksjs/commerce'
|
|
22
22
|
|
|
23
|
-
// 15 sub-modules
|
|
24
23
|
commerce.products // Products, variants, units, manufacturers, reviews, categories
|
|
25
24
|
commerce.carts // The pre-checkout basket
|
|
26
25
|
commerce.orders // Orders, order items, export, checkout guards
|
|
27
26
|
commerce.customers // Customer records
|
|
28
27
|
commerce.coupons // Coupons, including atomic redemption
|
|
28
|
+
commerce.discounts // Automatic + code discounts: buy X get Y, volume tiers, free shipping
|
|
29
|
+
commerce.upsells // Post-purchase offers: one-click, discounted additions to a placed order
|
|
29
30
|
commerce.payments // Payment records, refunds
|
|
30
31
|
commerce.giftCards // Gift cards, balance, redemption and reload
|
|
31
32
|
commerce.auctions // Benefit auctions: lots, bids, proxy bidding, pledges
|
|
@@ -87,6 +88,9 @@ Each sub-module typically provides:
|
|
|
87
88
|
| Order | status, totalAmount, orderType, deliveryAddress | hasMany: OrderItem, Payment; belongsTo: Customer |
|
|
88
89
|
| OrderItem | quantity, price | belongsTo: Order, Product |
|
|
89
90
|
| Coupon | code(unique), discountType, discountValue, usageLimit | hasMany: Order |
|
|
91
|
+
| Discount | title, code (null = automatic), type (percentage/fixed_amount/buy_x_get_y/volume/free_shipping), target JSON, buy/get quantities, tiers JSON, minimums, maxAmount, combinesWith*, usageLimit | |
|
|
92
|
+
| PostPurchaseOffer | headline, message, productIds JSON, discountPercent, min/default/maxQuantity, triggerProductIds JSON, minOrderTotal, windowMinutes, priority | hasMany: PostPurchaseOfferResponse |
|
|
93
|
+
| PostPurchaseOfferResponse | status (viewed/pending/accepted/declined/failed), product/variant, quantity, unitPrice, amount, paymentReference; unique (order, offer, product) | belongsTo: PostPurchaseOffer, Order |
|
|
90
94
|
| GiftCard | code(unique), initialBalance, currentBalance, isReloadable | belongsTo: Customer |
|
|
91
95
|
| Customer | name, email, totalSpent, status | hasMany: Order, GiftCard, Review, Payment |
|
|
92
96
|
| Manufacturer | manufacturer info | hasMany: Product |
|
|
@@ -155,6 +159,75 @@ enforces `refund_amount + amount <= amount` in the WHERE clause, so operators
|
|
|
155
159
|
cannot over-refund a payment by racing each other. It flips the status to
|
|
156
160
|
`refunded` or `partiallyRefunded` depending on where the total lands.
|
|
157
161
|
|
|
162
|
+
## Discounts
|
|
163
|
+
|
|
164
|
+
`commerce.discounts` prices a basket with a pure engine
|
|
165
|
+
(`@stacksjs/commerce/discounts/engine`, browser-safe) against `Discount` rows and
|
|
166
|
+
coupons. Full guide: `docs/guide/commerce/discounts.md`.
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
const priced = await commerce.discounts.price({ lines, codes, shipping })
|
|
170
|
+
// priced.total, priced.discount, priced.applied, priced.rejectedCodes, priced.lines[i].allocations
|
|
171
|
+
await commerce.discounts.redeemApplied(priced.applied) // atomic, limit enforced in SQL
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
- No `code` means automatic. Classes are product / order / shipping; two apply
|
|
175
|
+
together only when each `combinesWith` the other's class (default: none).
|
|
176
|
+
A line takes its single best product discount; order discounts apply to the
|
|
177
|
+
remainder and are spread over lines by largest remainder.
|
|
178
|
+
- Buy X get Y discounts the cheapest qualifying units. Minimums count the
|
|
179
|
+
targeted lines for product discounts, the basket otherwise.
|
|
180
|
+
- Rule ids are `discount:<id>` / `coupon:<id>`; `ruleFromDiscount` /
|
|
181
|
+
`ruleFromCoupon` (pure, `discounts/rules`) map rows for pages that read their
|
|
182
|
+
own SQLite. `store()` validates the rule through the engine before inserting.
|
|
183
|
+
|
|
184
|
+
## Post-purchase upsells
|
|
185
|
+
|
|
186
|
+
`commerce.upsells`: a discounted, one-time offer on the confirmation page that
|
|
187
|
+
adds to the order just placed. Full guide: `docs/guide/commerce/upsells.md`.
|
|
188
|
+
|
|
189
|
+
```ts
|
|
190
|
+
const offers = await commerce.upsells.presentOffers(order.id) // records `viewed`
|
|
191
|
+
const result = await commerce.upsells.acceptOffer({
|
|
192
|
+
orderId, offerId, productId, variantId, quantity,
|
|
193
|
+
charge: commerce.upsells.chargeDefaultMethod(paymentDriver(), payer), // or chargeWith, or 'collect-later'
|
|
194
|
+
})
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
- Claim (response `pending` + stock reserved, one transaction; the unique
|
|
198
|
+
`(order, offer, product)` index is the one-time guard), then charge outside
|
|
199
|
+
the transaction with a per-claim idempotency key, then finish (order item,
|
|
200
|
+
payment row, totals) in one transaction.
|
|
201
|
+
- `requires_action` (3-D Secure) stays pending; `handleCommercePaymentEvent`
|
|
202
|
+
finishes or releases it by payment reference and never cancels the paid
|
|
203
|
+
order. Schedule `releaseStalePending()` for abandoned prompts.
|
|
204
|
+
- Prices come from the catalog and offer, never the request. `charge` is
|
|
205
|
+
required; `'collect-later'` is the explicit no-payment path.
|
|
206
|
+
|
|
207
|
+
## Dashboard pages
|
|
208
|
+
|
|
209
|
+
`/commerce/discounts` and `/commerce/upsells` (components
|
|
210
|
+
`Dashboard/Commerce/CommerceDiscounts*` and `CommerceUpsells*`, actions
|
|
211
|
+
`Actions/Dashboard/Commerce/CommerceDiscount*` / `CommerceUpsell*`, routes in
|
|
212
|
+
`routes/dashboard-api.ts`). Both models are in `dedicatedPages`, so no generic
|
|
213
|
+
`/models/...` page duplicates them. Writes go through `discountWriteData` /
|
|
214
|
+
`upsellWriteData` (field errors, engine-checked); an answered offer cannot be
|
|
215
|
+
deleted (409). `CommerceProductPicker` is the shared multi-product search.
|
|
216
|
+
|
|
217
|
+
## The default storefront
|
|
218
|
+
|
|
219
|
+
- Cart, checkout steps and `PlaceOrderAction` price through
|
|
220
|
+
`app/Storefront/StorefrontPricing.ts` (automatic discounts; shipping on the
|
|
221
|
+
discounted subtotal). `PlaceOrderAction` uses `orders.placeOrder` (atomic,
|
|
222
|
+
stock-guarded, idempotent per cart).
|
|
223
|
+
- `carts.discount_code` holds the shopper's code (`POST /api/cart/discount`);
|
|
224
|
+
pages read it through `storefrontCartSummary`, and `PlaceOrderAction`
|
|
225
|
+
re-checks it and refuses (clearing it) when it no longer applies.
|
|
226
|
+
- `/orders/{id}` opens only with `?key=<orders.tracking_token>`
|
|
227
|
+
(`app/Storefront/OrderKey.ts`); never link an order page by id alone. It renders
|
|
228
|
+
the offer, posting to `/api/orders/offers/accept|decline`. The charge for an
|
|
229
|
+
accepted offer is decided in `app/Storefront/UpsellCharge.ts` (override it).
|
|
230
|
+
|
|
158
231
|
## Carts
|
|
159
232
|
|
|
160
233
|
`commerce.carts` is the pre-checkout basket, with the same CRUD shape as every
|
|
@@ -322,7 +395,8 @@ is the helper for when the count is genuinely what you want.
|
|
|
322
395
|
- Order `observe: true` emits events on create/update/delete
|
|
323
396
|
- Products have JSON fields for allergens and nutritionalInfo
|
|
324
397
|
- Cart expiry is tracked via `expiresAt`; `cleanupAbandonedCarts` is the sweeper
|
|
325
|
-
- Coupon types: `fixed_amount` or `percentage
|
|
398
|
+
- Coupon types: `fixed_amount` or `percentage`; anything richer (buy X get Y,
|
|
399
|
+
tiers, automatic, free shipping) is a `Discount`
|
|
326
400
|
- Gift card codes are unique and auto-generated
|
|
327
401
|
- License keys follow XXXX-XXXX-XXXX-XXXX-XXXX format
|
|
328
402
|
- Software licensing (issue from a payment webhook, device activations, team
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: stacks-dashboard
|
|
3
|
-
description: Use when building or customizing the Stacks admin dashboard, including dashboard pages, model management views, analytics widgets, commerce dashboards, content management, settings panels, deployment monitoring, job/queue management, or the
|
|
3
|
+
description: Use when building or customizing the Stacks admin dashboard, including dashboard pages, model management views, analytics widgets, commerce dashboards, content management, settings panels, deployment monitoring, job/queue management, or the 445 built-in dashboard components. Covers the dashboard system at storage/framework/defaults/.
|
|
4
4
|
license: MIT
|
|
5
5
|
compatibility: Bun >= 1.3.0, TypeScript
|
|
6
6
|
allowed-tools: Read Edit Write Bash Grep Glob
|
|
@@ -8,7 +8,7 @@ allowed-tools: Read Edit Write Bash Grep Glob
|
|
|
8
8
|
|
|
9
9
|
# Stacks Dashboard
|
|
10
10
|
|
|
11
|
-
The Stacks admin dashboard provides a full-featured admin panel with 100+ route views,
|
|
11
|
+
The Stacks admin dashboard provides a full-featured admin panel with 100+ route views, 445 components, and a multi-section layout.
|
|
12
12
|
|
|
13
13
|
## Key Paths
|
|
14
14
|
- Dashboard components: `storage/framework/defaults/resources/components/Dashboard/`
|
|
@@ -714,6 +714,36 @@ form, a console, the search palette) with what they are.
|
|
|
714
714
|
- A hidden label becomes `ariaLabel`. A visible word beside the dropdown
|
|
715
715
|
("Sort") stays, with the dropdown inside its label at `size="sm"`.
|
|
716
716
|
|
|
717
|
+
### The project switcher
|
|
718
|
+
|
|
719
|
+
The top of the sidebar names the project being served and opens a menu of
|
|
720
|
+
every Stacks project on the machine (`resources/components/Dashboard/ProjectSwitcher.stx`,
|
|
721
|
+
placed in the layout's `#header` slot under the window-controls strip).
|
|
722
|
+
|
|
723
|
+
A dashboard process serves exactly one project: its config, database
|
|
724
|
+
connection, routes and model globals are bound when it starts. Switching
|
|
725
|
+
therefore goes to the other project's dashboard, at that project's own
|
|
726
|
+
address, and never re-points the running one. Do not try to make a dashboard
|
|
727
|
+
page read another project's data.
|
|
728
|
+
|
|
729
|
+
- The button is rendered on the server with the project's name
|
|
730
|
+
(`dashboardProjectIdentity()` in `resources/functions/dashboard/project-switcher.ts`),
|
|
731
|
+
so the sidebar does not shift on hydration. The list is fetched in the
|
|
732
|
+
browser when the menu opens, because the layout is rendered once and kept.
|
|
733
|
+
- The client lives in `functions/projects.ts` and talks to the dev dashboard
|
|
734
|
+
server's `/__buddy/` routes. Picking a project whose dashboard is up goes
|
|
735
|
+
straight there; otherwise the server asks the background daemon to start it
|
|
736
|
+
and answers with the address once it is ready.
|
|
737
|
+
- It is drawn only on the developer's machine. The dev dashboard server sets
|
|
738
|
+
`STACKS_DASHBOARD_PROJECTS=1`; a deployed dashboard has one project and no
|
|
739
|
+
switcher.
|
|
740
|
+
- Each project has its own origin (a port reserved for it, the same every
|
|
741
|
+
time), so appearance settings, the sign-in token and kept state are per
|
|
742
|
+
project by construction.
|
|
743
|
+
- The sidebar's header and its scroll area are stacked at the same level, so
|
|
744
|
+
the layout lifts the header (`:has([data-project-switcher][data-open="true"])`)
|
|
745
|
+
while the menu is open. A new header control with a menu needs the same.
|
|
746
|
+
|
|
717
747
|
### Sidebar-aware overlays
|
|
718
748
|
|
|
719
749
|
The desktop sidebar is fixed and publishes its current width through
|
|
@@ -12,7 +12,7 @@ allowed-tools: Read Edit Write Bash Grep Glob
|
|
|
12
12
|
- Database package: `storage/framework/core/database/src/`
|
|
13
13
|
- Configuration: `config/database.ts`
|
|
14
14
|
- QB config: `config/query-builder.ts`
|
|
15
|
-
- Migrations: `database/migrations/` (
|
|
15
|
+
- Migrations: `database/migrations/` (256 migration files, `.sql` format)
|
|
16
16
|
- QB state: `.qb/`
|
|
17
17
|
- ORM: `storage/framework/orm/`
|
|
18
18
|
|
|
@@ -158,6 +158,9 @@ Uses `bun-plugin-stx` serve function with pattern-based view resolution:
|
|
|
158
158
|
- Leaves `resources/functions` to the STX client auto-import pipeline because browser helpers may depend on signals and other browser-only primitives
|
|
159
159
|
- Opens a Craft `createApp()` window when a supported SDK and native binary are available (1400x900, titlebar hidden)
|
|
160
160
|
- Builds the web sidebar from configured sections and discovered model dashboard metadata
|
|
161
|
+
- Records itself in `storage/framework/runtime/services/dashboard.json` (pid, port, address) once it is up, which is how `buddy dashboard`, the background daemon and every other dashboard's project switcher know this project already has one. Read it with `readProjectService(root, 'dashboard')` from `@stacksjs/path`; a record whose process has died reads as null
|
|
162
|
+
- Serves the project switcher's routes under `/__buddy/` (`dev/dashboard-projects.ts`): the machine's project list, opening another project's dashboard through the daemon, adding a project. They stay out of `/api/` because an application may well have its own `/api/projects`
|
|
163
|
+
- With `STACKS_DASHBOARD_IDLE_EXIT_MS` set (the daemon sets it), exits after that long without a request. An open page reports in on a timer, so a dashboard someone is reading stays up
|
|
161
164
|
|
|
162
165
|
### Docs Dev Server (docs.ts)
|
|
163
166
|
- Uses `@stacksjs/bunpress` with `{ watch: true, quiet: true }`
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: stacks-migrations
|
|
3
|
-
description: Use when working with database migrations in a Stacks application - creating migration files, running migrations, fresh migration (drop + recreate), seeding after migration, migration file naming conventions, or the
|
|
3
|
+
description: Use when working with database migrations in a Stacks application - creating migration files, running migrations, fresh migration (drop + recreate), seeding after migration, migration file naming conventions, or the 256 built-in migration files. For the database API itself (queries, connections, SQL helpers), see stacks-database.
|
|
4
4
|
license: MIT
|
|
5
5
|
compatibility: Bun >= 1.3.0, TypeScript, SQLite >= 3.47.2
|
|
6
6
|
allowed-tools: Read Edit Write Bash Grep Glob
|
|
@@ -237,6 +237,14 @@ adds missing indexes, foreign keys after an orphan check, missing columns, and
|
|
|
237
237
|
lossless widenings; reports everything destructive), then
|
|
238
238
|
`migrate:status --reconcile` and `migrate`.
|
|
239
239
|
|
|
240
|
+
A database that moved onto a corpus of its own (Postgres beside a SQLite
|
|
241
|
+
`database/migrations`) keeps a row for every file it ran from the old corpus.
|
|
242
|
+
`migrate:status` lists those as history, not drift, and reconcile never
|
|
243
|
+
repoints, prunes or deletes them: the files are still in the other corpus, and
|
|
244
|
+
the rows stop them running twice. Reconcile names every ledger row it changes.
|
|
245
|
+
A row whose name several files share (`auto-misc`) is ambiguous, never a
|
|
246
|
+
duplicate.
|
|
247
|
+
|
|
240
248
|
## Gotchas
|
|
241
249
|
- `migrate:fresh` drops ALL tables — only use in development
|
|
242
250
|
- Migrations run in filename order; two files with one number run alphabetically, which `--strict` refuses
|
|
@@ -246,7 +254,7 @@ lossless widenings; reports everything destructive), then
|
|
|
246
254
|
- Do not commit a second snapshot under `.qb/`; that indicates a missing `snapshotDir` configuration
|
|
247
255
|
- If a generated SQLite migration rebuilds tables, test it against a copy of the current database and run `PRAGMA integrity_check` plus `PRAGMA foreign_key_check`
|
|
248
256
|
- `--seed` flag after `migrate:fresh` seeds the database with factory data
|
|
249
|
-
-
|
|
257
|
+
- 256 migration files exist by default for all framework models
|
|
250
258
|
- SQLite >= 3.47.2 is required (system requirement)
|
|
251
259
|
- For the database API (queries, connections), see the `stacks-database` skill
|
|
252
260
|
|
|
@@ -485,6 +485,24 @@ prompt with `ios.usageDescriptions.NSAppleMusicUsageDescription`. The
|
|
|
485
485
|
simulator's Music app has nothing to play; launch a simulator build with
|
|
486
486
|
`-CraftFakeMusicPlayer YES` for three made-up songs that play and skip.
|
|
487
487
|
|
|
488
|
+
## Signed-out launch gate
|
|
489
|
+
|
|
490
|
+
`nativeGate` in `config/mobile.ts` passes Craft's `nativeGate` (craft-native
|
|
491
|
+
>= 0.0.488) to both shells: before the first frame, a signed-out launch whose
|
|
492
|
+
start path is not public opens on `redirect` instead of drawing the signed-in
|
|
493
|
+
home and its tabs until the app script pushes sign-in on top.
|
|
494
|
+
|
|
495
|
+
```ts
|
|
496
|
+
nativeGate: { token: 'auth.token', redirect: '/m/login', publicPaths: ['/m/login'] },
|
|
497
|
+
ios: { /* ... */ }, // ios.nativeGate replaces the shared one whole
|
|
498
|
+
android: { /* ... */ }, // so does android.nativeGate
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
`token` is the secure-storage key holding the sign-in (Craft defaults it to
|
|
502
|
+
`sessionTokenKey`). Each public path admits what sits under it, and `redirect`
|
|
503
|
+
must be one of them. The gate checks the start path from `url`, never a deep
|
|
504
|
+
link. Craft validates every path when it generates the project.
|
|
505
|
+
|
|
488
506
|
## Crash reporting (bughq)
|
|
489
507
|
|
|
490
508
|
`crashReporting` in `config/mobile.ts` turns on Craft's native reporter (craft-native >= 0.0.179; the build refuses an older one). It sends crashes, hangs (MetricKit), ANRs and native crashes (ApplicationExitInfo) and uncaught JavaScript errors in native screens and the app script to bughq from an on-disk outbox, with app version and build, OS, device model, session and breadcrumbs (screens shown, failed requests).
|
|
@@ -773,8 +791,9 @@ missing font files and invalid names. Fonts work without a network request.
|
|
|
773
791
|
## Native passkeys
|
|
774
792
|
|
|
775
793
|
Enable `ios.capabilities.passkeys` and a `webcredentials:<relying-party-host>`
|
|
776
|
-
associated domain
|
|
777
|
-
|
|
794
|
+
associated domain; the build refuses passkeys without one, since iOS fails
|
|
795
|
+
every passkey request from an app its domain does not vouch for. Craft >=
|
|
796
|
+
0.0.451 supplies the system AuthenticationServices sheet. Import `passkeys` from `@stacksjs/mobile`, check
|
|
778
797
|
`await passkeys.isAvailable()`, then pass server-issued JSON WebAuthn options to
|
|
779
798
|
`create(options)` or `get(options)`. Send the JSON credential back to the server
|
|
780
799
|
for verification. The native capability never replaces the server challenge,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: stacks-models
|
|
3
|
-
description: Use when defining or extending Stacks models, deriving migrations and CRUD, configuring attributes/relationships/traits/ownership, or preserving model inference. Covers defineModel, extendModel, model types, native data workflows, and the
|
|
3
|
+
description: Use when defining or extending Stacks models, deriving migrations and CRUD, configuring attributes/relationships/traits/ownership, or preserving model inference. Covers defineModel, extendModel, model types, native data workflows, and the 113 built-in framework models.
|
|
4
4
|
license: MIT
|
|
5
5
|
compatibility: Bun >= 1.3.0, TypeScript, SQLite >= 3.47.2
|
|
6
6
|
allowed-tools: Read Edit Write Bash Grep Glob
|
|
@@ -457,7 +457,7 @@ honoured: fewer rows are seeded rather than a duplicate combination.
|
|
|
457
457
|
## Built-in models by category
|
|
458
458
|
|
|
459
459
|
The ones below are worth knowing by name. They are a selection, not the set:
|
|
460
|
-
`storage/framework/defaults/app/Models/` holds
|
|
460
|
+
`storage/framework/defaults/app/Models/` holds 113, and that directory is the
|
|
461
461
|
authority. This section said "All 62 built-in models by category" while
|
|
462
462
|
listing fewer than that against 102 on disk, so an agent reading to the end
|
|
463
463
|
had no way to tell it was short.
|