@stacksjs/defaults 0.75.617 → 0.75.621
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-commerce/SKILL.md +78 -4
- package/ai/skills/stacks-dashboard/SKILL.md +2 -2
- package/ai/skills/stacks-database/SKILL.md +1 -1
- 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 +11 -11
- package/ai/skills/stacks-orm/SKILL.md +2 -2
- 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/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/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/sidebar.ts +4 -1
- 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
|
@@ -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
|
|
@@ -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 444 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, 444 components, and a multi-section layout.
|
|
12
12
|
|
|
13
13
|
## Key Paths
|
|
14
14
|
- Dashboard components: `storage/framework/defaults/resources/components/Dashboard/`
|
|
@@ -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
|
|
|
@@ -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.
|
|
@@ -11,7 +11,7 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
|
|
|
11
11
|
| Package | Task guidance | Source entry | Retained tests |
|
|
12
12
|
|---|---|---|---|
|
|
13
13
|
| `@stacksjs/action-runner` | [`stacks-actions`](../stacks-actions/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/action-runner/src/index.ts) | 1 |
|
|
14
|
-
| `@stacksjs/actions` | [`stacks-actions`](../stacks-actions/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/index.ts) |
|
|
14
|
+
| `@stacksjs/actions` | [`stacks-actions`](../stacks-actions/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/index.ts) | 124 |
|
|
15
15
|
| `@stacksjs/ai` | [`stacks-ai`](../stacks-ai/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/ai/src/index.ts) | 24 |
|
|
16
16
|
| `@stacksjs/alias` | [`stacks-alias`](../stacks-alias/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/alias/src/index.ts) | 3 |
|
|
17
17
|
| `@stacksjs/analytics` | [`stacks-analytics`](../stacks-analytics/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/analytics/src/index.ts) | 7 |
|
|
@@ -31,11 +31,11 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
|
|
|
31
31
|
| `@stacksjs/cloud` | [`stacks-cloud`](../stacks-cloud/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cloud/src/index.ts) | 10 |
|
|
32
32
|
| `@stacksjs/cms` | [`stacks-cms`](../stacks-cms/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cms/src/index.ts) | 5 |
|
|
33
33
|
| `@stacksjs/collections` | [`stacks-collections`](../stacks-collections/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/collections/src/index.ts) | 2 |
|
|
34
|
-
| `@stacksjs/commerce` | [`stacks-commerce`](../stacks-commerce/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/index.ts) |
|
|
34
|
+
| `@stacksjs/commerce` | [`stacks-commerce`](../stacks-commerce/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/index.ts) | 16 |
|
|
35
35
|
| `@stacksjs/composables` | [`stacks-composables`](../stacks-composables/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/composables/src/index.ts) | 18 |
|
|
36
36
|
| `@stacksjs/config` | [`stacks-config`](../stacks-config/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/index.ts) | 17 |
|
|
37
37
|
| `@stacksjs/cron` | [`stacks-cron`](../stacks-cron/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cron/src/index.ts) | 6 |
|
|
38
|
-
| `@stacksjs/database` | [`stacks-database`](../stacks-database/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/index.ts) |
|
|
38
|
+
| `@stacksjs/database` | [`stacks-database`](../stacks-database/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/index.ts) | 148 |
|
|
39
39
|
| `@stacksjs/datetime` | [`stacks-datetime`](../stacks-datetime/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/datetime/src/index.ts) | 22 |
|
|
40
40
|
| `@stacksjs/defaults` | [`stacks-build`](../stacks-build/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/defaults/package.json) | 3 |
|
|
41
41
|
| `@stacksjs/deploy` | [`stacks-deploy`](../stacks-deploy/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/deploy/package.json) | 1 |
|
|
@@ -55,7 +55,7 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
|
|
|
55
55
|
| `@stacksjs/git` | [`stacks-git`](../stacks-git/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/git/src/index.ts) | 2 |
|
|
56
56
|
| `@stacksjs/github` | [`stacks-git`](../stacks-git/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/github/src/index.ts) | 8 |
|
|
57
57
|
| `@stacksjs/health` | [`stacks-health`](../stacks-health/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/health/src/index.ts) | 2 |
|
|
58
|
-
| `@stacksjs/hq` | [`stacks-hq`](../stacks-hq/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/hq/src/index.ts) |
|
|
58
|
+
| `@stacksjs/hq` | [`stacks-hq`](../stacks-hq/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/hq/src/index.ts) | 11 |
|
|
59
59
|
| `@stacksjs/http` | [`stacks-http`](../stacks-http/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/http/src/index.ts) | 4 |
|
|
60
60
|
| `@stacksjs/i18n` | [`stacks-i18n`](../stacks-i18n/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/i18n/src/index.ts) | 7 |
|
|
61
61
|
| `@stacksjs/image` | [`stacks-image`](../stacks-image/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/image/src/index.ts) | 4 |
|
|
@@ -122,7 +122,7 @@ Declared runtime exports: `BlogAdminError`, `DEFAULT_IOS_DEPENDENCIES`, `DEFAULT
|
|
|
122
122
|
|
|
123
123
|
Local source modules: [src/action.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/action.ts), [src/add.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/add.ts), [src/blog-admin.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/blog-admin.ts), [src/build/ios-toolchain.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/build/ios-toolchain.ts), [src/build/macos-native.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/build/macos-native.ts), [src/commit.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/commit.ts), [src/dev/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/dev/index.ts), [src/discover-packages.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/discover-packages.ts), [src/generate/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/generate/index.ts), [src/github-release.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/github-release.ts), [src/helpers/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/helpers/index.ts), [src/library/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/library/index.ts), [src/lint/lint.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/lint/lint.ts), [src/lint/stx-gate.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/lint/stx-gate.ts), [src/make-command.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/make-command.ts), [src/make-job.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/make-job.ts), [src/make-policy.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/make-policy.ts), [src/make-resource.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/make-resource.ts), [src/make.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/make.ts), [src/publication-preflight.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/publication-preflight.ts), [src/release-evidence.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/release-evidence.ts), [src/reviewos-evidence.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/reviewos-evidence.ts), [src/reviewos-workflows.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/reviewos-workflows.ts), [src/scaffold-crud.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/scaffold-crud.ts), [src/setup/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/setup/index.ts), [src/stacks.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/stacks.ts), [src/stx-source.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/stx-source.ts), [src/upgrade/package-project.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/upgrade/package-project.ts), [src/upgrade/route-actions.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/upgrade/route-actions.ts).
|
|
124
124
|
|
|
125
|
-
Evidence directory: [
|
|
125
|
+
Evidence directory: [124 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
126
126
|
|
|
127
127
|
### @stacksjs/ai
|
|
128
128
|
|
|
@@ -316,11 +316,11 @@ Evidence directory: [2 retained tests](https://github.com/stacksjs/stacks/blob/m
|
|
|
316
316
|
|
|
317
317
|
Guidance: [`stacks-commerce`](../stacks-commerce/SKILL.md). Source: [storage/framework/core/commerce/src/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/index.ts).
|
|
318
318
|
|
|
319
|
-
Declared runtime exports: `PriceFormatError`, `auctions`, `breakdownFor`, `carts`, `catalog`, `catalogImport`, `commerce`, `coupons`, `currencyExponent`, `customers`, `decimalToMinor`, `default`, `devices`, `errors`, `formatCurrency`, `formatMinor`, `giftCards`, `licensing`, `minorToDecimal`, `minorToInput`, `minorToMajor`, `money`, `moneyInputError`, `moneyInputStep`, `multiplierOf`, `orders`, `parseMoneyInput`, `parseSalesTaxSetup`, `parseTaxRateWriteData`, `payments`, `products`, `receiptLinesText`, `receipts`, `register`, `releases`, `restaurant`, `restockedQuantity`, `shippings`, `tax`, `waitlists`.
|
|
319
|
+
Declared runtime exports: `PriceFormatError`, `auctions`, `breakdownFor`, `carts`, `catalog`, `catalogImport`, `commerce`, `coupons`, `currencyExponent`, `customers`, `decimalToMinor`, `default`, `devices`, `discounts`, `errors`, `formatCurrency`, `formatMinor`, `giftCards`, `licensing`, `minorToDecimal`, `minorToInput`, `minorToMajor`, `money`, `moneyInputError`, `moneyInputStep`, `multiplierOf`, `orders`, `parseMoneyInput`, `parseSalesTaxSetup`, `parseTaxRateWriteData`, `payments`, `products`, `receiptLinesText`, `receipts`, `register`, `releases`, `restaurant`, `restockedQuantity`, `shippings`, `tax`, `upsells`, `waitlists`.
|
|
320
320
|
|
|
321
|
-
Local source modules: [src/auctions/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/auctions/index.ts), [src/carts/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/carts/index.ts), [src/catalog.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/catalog.ts), [src/coupons/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/coupons/index.ts), [src/customers/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/customers/index.ts), [src/devices/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/devices/index.ts), [src/errors/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/errors/index.ts), [src/gift-cards/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/gift-cards/index.ts), [src/imports/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/imports/index.ts), [src/inventory.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/inventory.ts), [src/licensing/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/licensing/index.ts), [src/money.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/money.ts), [src/orders/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/orders/index.ts), [src/payments/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/payments/index.ts), [src/products/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/products/index.ts), [src/receipt-text.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/receipt-text.ts), [src/receipts/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/receipts/index.ts), [src/register.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/register.ts), [src/releases.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/releases.ts), [src/sales-tax.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/sales-tax.ts), [src/shippings/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/shippings/index.ts), [src/tax-input.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/tax-input.ts), [src/tax/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/tax/index.ts), [src/waitlists/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/waitlists/index.ts), [src/waitlists/restaurant/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/waitlists/restaurant/index.ts).
|
|
321
|
+
Local source modules: [src/auctions/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/auctions/index.ts), [src/carts/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/carts/index.ts), [src/catalog.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/catalog.ts), [src/coupons/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/coupons/index.ts), [src/customers/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/customers/index.ts), [src/devices/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/devices/index.ts), [src/discounts/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/discounts/index.ts), [src/errors/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/errors/index.ts), [src/gift-cards/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/gift-cards/index.ts), [src/imports/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/imports/index.ts), [src/inventory.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/inventory.ts), [src/licensing/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/licensing/index.ts), [src/money.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/money.ts), [src/orders/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/orders/index.ts), [src/payments/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/payments/index.ts), [src/products/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/products/index.ts), [src/receipt-text.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/receipt-text.ts), [src/receipts/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/receipts/index.ts), [src/register.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/register.ts), [src/releases.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/releases.ts), [src/sales-tax.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/sales-tax.ts), [src/shippings/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/shippings/index.ts), [src/tax-input.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/tax-input.ts), [src/tax/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/tax/index.ts), [src/upsells/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/upsells/index.ts), [src/waitlists/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/waitlists/index.ts), [src/waitlists/restaurant/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/waitlists/restaurant/index.ts).
|
|
322
322
|
|
|
323
|
-
Evidence directory: [
|
|
323
|
+
Evidence directory: [16 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
324
324
|
|
|
325
325
|
### @stacksjs/composables
|
|
326
326
|
|
|
@@ -360,7 +360,7 @@ Declared runtime exports: `Database`, `EntityQueryBuilder`, `__flushAfterCommitN
|
|
|
360
360
|
|
|
361
361
|
Local source modules: [src/affected-rows.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/affected-rows.ts), [src/auth-tables.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/auth-tables.ts), [src/custom/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/custom/index.ts), [src/database.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/database.ts), [src/datetime-columns.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/datetime-columns.ts), [src/ddl-constraints.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/ddl-constraints.ts), [src/defaults.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/defaults.ts), [src/dialect.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/dialect.ts), [src/driver-config.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/driver-config.ts), [src/drivers/dynamodb.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/drivers/dynamodb.ts), [src/drivers/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/drivers/index.ts), [src/ensure-database.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/ensure-database.ts), [src/erd.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/erd.ts), [src/fk-audit.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/fk-audit.ts), [src/framework-renames.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/framework-renames.ts), [src/framework-route-admission.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/framework-route-admission.ts), [src/hand-written-migrations.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/hand-written-migrations.ts), [src/ignored-migrations.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/ignored-migrations.ts), [src/index-shape.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/index-shape.ts), [src/managed-columns.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/managed-columns.ts), [src/migration-dialect.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/migration-dialect.ts), [src/migration-ledger.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/migration-ledger.ts), [src/migration-names.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/migration-names.ts), [src/migration-path.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/migration-path.ts), [src/migrations.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/migrations.ts), [src/model-sources.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/model-sources.ts), [src/notification-tables.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/notification-tables.ts), [src/package-migrations.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/package-migrations.ts), [src/package-models.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/package-models.ts), [src/query-logger.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/query-logger.ts), [src/rbac-tables.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/rbac-tables.ts), [src/relation-columns.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/relation-columns.ts), [src/replicas.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/replicas.ts), [src/row-lease.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/row-lease.ts), [src/row-lock.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/row-lock.ts), [src/safe-migrations.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/safe-migrations.ts), [src/schema-align.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/schema-align.ts), [src/schema-drift.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/schema-drift.ts), [src/seeder.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/seeder.ts), [src/shadowed-models.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/shadowed-models.ts), [src/sql-helpers.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/sql-helpers.ts), [src/table-exists.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/table-exists.ts), [src/trait-tables.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/trait-tables.ts), [src/transaction-context.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/transaction-context.ts), [src/transaction-options.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/transaction-options.ts), [src/types.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/types.ts), [src/unique-audit.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/unique-audit.ts), [src/utc-defaults.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/utc-defaults.ts), [src/utils.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/utils.ts), [src/uuid-columns.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/uuid-columns.ts), [src/vschema.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/vschema.ts).
|
|
362
362
|
|
|
363
|
-
Evidence directory: [
|
|
363
|
+
Evidence directory: [148 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
364
364
|
|
|
365
365
|
### @stacksjs/datetime
|
|
366
366
|
|
|
@@ -550,7 +550,7 @@ Read the entrypoint and package export map for re-exported or type-only surfaces
|
|
|
550
550
|
|
|
551
551
|
Local source modules: [src/client.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/hq/src/client.ts), [src/meter.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/hq/src/meter.ts), [src/service.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/hq/src/service.ts).
|
|
552
552
|
|
|
553
|
-
Evidence directory: [
|
|
553
|
+
Evidence directory: [11 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/hq/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
554
554
|
|
|
555
555
|
### @stacksjs/http
|
|
556
556
|
|
|
@@ -650,7 +650,7 @@ Evidence directory: [10 retained tests](https://github.com/stacksjs/stacks/blob/
|
|
|
650
650
|
|
|
651
651
|
Guidance: [`stacks-orm`](../stacks-orm/SKILL.md). Source: [storage/framework/core/orm/src/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/index.ts).
|
|
652
652
|
|
|
653
|
-
Declared runtime exports: `Activity`, `AnalyticsEvent`, `Auction`, `AuctionItem`, `Author`, `Automation`, `AutomationRun`, `BILLABLE_INSTANCE_METHODS`, `Bid`, `Board`, `BoardColumn`, `Campaign`, `CampaignSend`, `CampaignVariant`, `Card`, `CardAttachment`, `CardComment`, `Cart`, `CartItem`, `Categorizable`, `Category`, `Comment`, `CommunicationSuppression`, `ConsentEvent`, `Coupon`, `Courier`, `CourierPing`, `Customer`, `DeliveryRoute`, `DeliveryStop`, `Deployment`, `DigitalDelivery`, `EmailIdempotency`, `EmailList`, `EmailListSubscriber`, `EmailSuppression`, `EmailWebhookEvent`, `ErrorModel`, `FailedJob`, `FeedbackToken`, `Form`, `FormField`, `FormSubmission`, `GdprRequest`, `GiftCard`, `Job`, `Label`, `LicenseActivation`, `LicenseKey`, `LicenseSeat`, `Log`, `LoyaltyPoint`, `LoyaltyReward`, `MagicLinkToken`, `MailPreference`, `Manufacturer`, `Menu`, `MenuItem`, `ModelUnavailableError`, `Notification`, `NotificationDelivery`, `Order`, `OrderIdempotency`, `OrderItem`, `Page`, `PageRevision`, `Payment`, `PaymentMethod`, `PaymentProduct`, `PaymentTransaction`, `PaymentWebhookEvent`, `PersonalAccessToken`, `Pledge`, `Post`, `PrintDevice`, `Product`, `ProductUnit`, `ProductVariant`, `QueryLog`, `QueueWorker`, `Receipt`, `Redirect`, `Referral`, `ReferralCode`, `Release`, `Request`, `Review`, `SenderDomain`, `ShippingMethod`, `ShippingRate`, `ShippingZone`, `Site`, `SiteDomain`, `SmsOptOut`, `SocialAccount`, `SocialPost`, `StorageItem`, `StorageItemTask`, `Subscriber`, `SubscriberEmail`, `Subscription`, `SubscriptionNotOwnedError`, `Tag`, `TaxRate`, `Team`, `TeamInvitation`, `TeamMember`, `Transaction`, `UsageEvent`, `User`, `WaitlistProduct`, `WaitlistRestaurant`, `Websocket`, `buildDatabaseSchema`, `collectEncryptedAttributes`, `createAuditMethods`, `createCategorizableMethods`, `createCommentableMethods`, `createLikeableMethods`, `createTaggableMethods`, `customerOwnership`, `decryptValue`, `decryptValueInPlace`, `encryptValue`, `enrichPaginatorUrls`, `filterFillable`, `frameworkModelFeature`, `getWritableFields`, `isBillable`, `isCursorPaginator`, `isEncrypted`, `isPaginator`, `isSimplePaginator`, `isUniqueViolation`, `mapWriteError`, `modelGlobalNames`, `ormReady`, `parentOwnership`, `parseCursor`, `renderDatabaseTypeFile`, `resolveCursorArgs`, `resolvePageArgs`, `selfOwnership`, `setAuditUser`, `siteOwnership`, `teamMembershipOwnership`, `toCursorPaginator`, `toPaginator`, `toSimplePaginator`, `toSnakeCaseKeys`.
|
|
653
|
+
Declared runtime exports: `Activity`, `AnalyticsEvent`, `Auction`, `AuctionItem`, `Author`, `Automation`, `AutomationRun`, `BILLABLE_INSTANCE_METHODS`, `Bid`, `Board`, `BoardColumn`, `Campaign`, `CampaignSend`, `CampaignVariant`, `Card`, `CardAttachment`, `CardComment`, `Cart`, `CartItem`, `Categorizable`, `Category`, `Comment`, `CommunicationSuppression`, `ConsentEvent`, `Coupon`, `Courier`, `CourierPing`, `Customer`, `DeliveryRoute`, `DeliveryStop`, `Deployment`, `DigitalDelivery`, `Discount`, `EmailIdempotency`, `EmailList`, `EmailListSubscriber`, `EmailSuppression`, `EmailWebhookEvent`, `ErrorModel`, `FailedJob`, `FeedbackToken`, `Form`, `FormField`, `FormSubmission`, `GdprRequest`, `GiftCard`, `Job`, `Label`, `LicenseActivation`, `LicenseKey`, `LicenseSeat`, `Log`, `LoyaltyPoint`, `LoyaltyReward`, `MagicLinkToken`, `MailPreference`, `Manufacturer`, `Menu`, `MenuItem`, `ModelUnavailableError`, `Notification`, `NotificationDelivery`, `Order`, `OrderIdempotency`, `OrderItem`, `Page`, `PageRevision`, `Payment`, `PaymentMethod`, `PaymentProduct`, `PaymentTransaction`, `PaymentWebhookEvent`, `PersonalAccessToken`, `Pledge`, `Post`, `PostPurchaseOffer`, `PostPurchaseOfferResponse`, `PrintDevice`, `Product`, `ProductUnit`, `ProductVariant`, `QueryLog`, `QueueWorker`, `Receipt`, `Redirect`, `Referral`, `ReferralCode`, `Release`, `Request`, `Review`, `SenderDomain`, `ShippingMethod`, `ShippingRate`, `ShippingZone`, `Site`, `SiteDomain`, `SmsOptOut`, `SocialAccount`, `SocialPost`, `StorageItem`, `StorageItemTask`, `Subscriber`, `SubscriberEmail`, `Subscription`, `SubscriptionNotOwnedError`, `Tag`, `TaxRate`, `Team`, `TeamInvitation`, `TeamMember`, `Transaction`, `UsageEvent`, `User`, `WaitlistProduct`, `WaitlistRestaurant`, `Websocket`, `buildDatabaseSchema`, `collectEncryptedAttributes`, `createAuditMethods`, `createCategorizableMethods`, `createCommentableMethods`, `createLikeableMethods`, `createTaggableMethods`, `customerOwnership`, `decryptValue`, `decryptValueInPlace`, `encryptValue`, `enrichPaginatorUrls`, `filterFillable`, `frameworkModelFeature`, `getWritableFields`, `isBillable`, `isCursorPaginator`, `isEncrypted`, `isPaginator`, `isSimplePaginator`, `isUniqueViolation`, `mapWriteError`, `modelGlobalNames`, `ormReady`, `parentOwnership`, `parseCursor`, `renderDatabaseTypeFile`, `resolveCursorArgs`, `resolvePageArgs`, `selfOwnership`, `setAuditUser`, `siteOwnership`, `teamMembershipOwnership`, `toCursorPaginator`, `toPaginator`, `toSimplePaginator`, `toSnakeCaseKeys`.
|
|
654
654
|
|
|
655
655
|
Local source modules: [src/auto-crud.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/auto-crud.ts), [src/batch-loader.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/batch-loader.ts), [src/db.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/db.ts), [src/define-model.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/define-model.ts), [src/extend-model.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/extend-model.ts), [src/gdpr/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/gdpr/index.ts), [src/generate-database-schema.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/generate-database-schema.ts), [src/locked-row.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/locked-row.ts), [src/messaging.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/messaging.ts), [src/model-types.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/model-types.ts), [src/ownership.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/ownership.ts), [src/paginator-request.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/paginator-request.ts), [src/row-token.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/row-token.ts), [src/subquery.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/subquery.ts), [src/traits/audit.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/traits/audit.ts), [src/traits/billable.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/traits/billable.ts), [src/traits/categorizable.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/traits/categorizable.ts), [src/traits/commentable.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/traits/commentable.ts), [src/traits/likeable.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/traits/likeable.ts), [src/traits/taggable.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/traits/taggable.ts), [src/transaction.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/transaction.ts), [src/types.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/types.ts), [src/utils/encrypted.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/utils/encrypted.ts), [src/utils/prunable.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/utils/prunable.ts).
|
|
656
656
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: stacks-orm
|
|
3
|
-
description: Use when querying or writing Stacks models, using transactions and relationships, preserving inferred model types, or enabling native model traits. Covers @stacksjs/orm, the model runtime, and
|
|
3
|
+
description: Use when querying or writing Stacks models, using transactions and relationships, preserving inferred model types, or enabling native model traits. Covers @stacksjs/orm, the model runtime, and 113 built-in models.
|
|
4
4
|
license: MIT
|
|
5
5
|
compatibility: Bun >= 1.3.0, TypeScript
|
|
6
6
|
allowed-tools: Read Edit Write Bash Grep Glob
|
|
@@ -10,7 +10,7 @@ allowed-tools: Read Edit Write Bash Grep Glob
|
|
|
10
10
|
|
|
11
11
|
`defineModel` produces an immediately usable query surface over
|
|
12
12
|
`bun-query-builder`. Model-driven migrations change the schema; there are no
|
|
13
|
-
per-model ORM classes to generate. The framework declares
|
|
13
|
+
per-model ORM classes to generate. The framework declares 113 models on disk,
|
|
14
14
|
but optional feature gates determine which built-ins load in a running app.
|
|
15
15
|
|
|
16
16
|
## Definitions and typed rows
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { RequestInstance } from '@stacksjs/types'
|
|
2
|
+
import { Action } from '@stacksjs/actions/runtime'
|
|
3
|
+
import { response } from '@stacksjs/router'
|
|
4
|
+
import { dashboardOperationalError } from '../dashboard-response'
|
|
5
|
+
import { deleteDiscount } from './commerce-discount-write'
|
|
6
|
+
|
|
7
|
+
/** `DELETE /api/dashboard/commerce/discounts/{id}` - remove a discount. Placed orders keep their totals. */
|
|
8
|
+
export default new Action({
|
|
9
|
+
name: 'CommerceDiscountDestroyAction',
|
|
10
|
+
description: 'Deletes a Discount from the dashboard.',
|
|
11
|
+
method: 'DELETE',
|
|
12
|
+
apiResponse: true,
|
|
13
|
+
|
|
14
|
+
async handle(request: RequestInstance) {
|
|
15
|
+
const id = Number(request.getParam('id'))
|
|
16
|
+
if (!Number.isSafeInteger(id) || id <= 0)
|
|
17
|
+
return response.json({ message: 'The discount id must be a positive whole number.' }, 422)
|
|
18
|
+
try {
|
|
19
|
+
if (!await deleteDiscount(id))
|
|
20
|
+
return response.json({ message: `Discount ${id} does not exist.` }, 404)
|
|
21
|
+
return response.json({ ok: true })
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
return dashboardOperationalError(error, 'The discount could not be deleted.', 'CommerceDiscountDestroyAction')
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RequestInstance } from '@stacksjs/types'
|
|
2
|
+
import { Action } from '@stacksjs/actions/runtime'
|
|
3
|
+
import { config } from '@stacksjs/config'
|
|
4
|
+
import { response } from '@stacksjs/router'
|
|
5
|
+
import { dashboardOperationalError } from '../dashboard-response'
|
|
6
|
+
import { asFieldErrors, saveDiscount } from './commerce-discount-write'
|
|
7
|
+
import { normalizeCommerceCurrency } from './commerce-product-records'
|
|
8
|
+
|
|
9
|
+
/** `POST /api/dashboard/commerce/discounts` - create a discount, checked by the engine first. */
|
|
10
|
+
export default new Action({
|
|
11
|
+
name: 'CommerceDiscountStoreAction',
|
|
12
|
+
description: 'Creates a Discount from the dashboard.',
|
|
13
|
+
method: 'POST',
|
|
14
|
+
apiResponse: true,
|
|
15
|
+
|
|
16
|
+
async handle(request: RequestInstance) {
|
|
17
|
+
try {
|
|
18
|
+
const result = await saveDiscount(null, request.all() as Record<string, unknown>, normalizeCommerceCurrency(config.commerce?.currency))
|
|
19
|
+
if (!result.ok)
|
|
20
|
+
return response.json({ message: result.message, errors: asFieldErrors(result.errors) }, result.status)
|
|
21
|
+
return response.json(result.record, 201)
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
return dashboardOperationalError(error, 'The discount could not be saved.', 'CommerceDiscountStoreAction')
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { RequestInstance } from '@stacksjs/types'
|
|
2
|
+
import { Action } from '@stacksjs/actions/runtime'
|
|
3
|
+
import { config } from '@stacksjs/config'
|
|
4
|
+
import { response } from '@stacksjs/router'
|
|
5
|
+
import { dashboardOperationalError } from '../dashboard-response'
|
|
6
|
+
import { asFieldErrors, saveDiscount } from './commerce-discount-write'
|
|
7
|
+
import { normalizeCommerceCurrency } from './commerce-product-records'
|
|
8
|
+
|
|
9
|
+
/** `PATCH /api/dashboard/commerce/discounts/{id}` - change a discount, checked by the engine first. */
|
|
10
|
+
export default new Action({
|
|
11
|
+
name: 'CommerceDiscountUpdateAction',
|
|
12
|
+
description: 'Updates a Discount from the dashboard.',
|
|
13
|
+
method: 'PATCH',
|
|
14
|
+
apiResponse: true,
|
|
15
|
+
|
|
16
|
+
async handle(request: RequestInstance) {
|
|
17
|
+
const id = Number(request.getParam('id'))
|
|
18
|
+
if (!Number.isSafeInteger(id) || id <= 0)
|
|
19
|
+
return response.json({ message: 'The discount id must be a positive whole number.' }, 422)
|
|
20
|
+
try {
|
|
21
|
+
const result = await saveDiscount(id, request.all() as Record<string, unknown>, normalizeCommerceCurrency(config.commerce?.currency))
|
|
22
|
+
if (!result.ok)
|
|
23
|
+
return response.json({ message: result.message, errors: asFieldErrors(result.errors) }, result.status)
|
|
24
|
+
return response.json(result.record)
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
return dashboardOperationalError(error, 'The discount could not be saved.', 'CommerceDiscountUpdateAction')
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { RequestInstance } from '@stacksjs/types'
|
|
2
|
+
import { Action } from '@stacksjs/actions/runtime'
|
|
3
|
+
import { config } from '@stacksjs/config'
|
|
4
|
+
import { response } from '@stacksjs/router'
|
|
5
|
+
import { dashboardOperationalError } from '../dashboard-response'
|
|
6
|
+
import { parseDiscountListQuery, readDiscountPage } from './commerce-discount-list'
|
|
7
|
+
import { normalizeCommerceCurrency } from './commerce-product-records'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* `GET /api/dashboard/commerce/discounts` - one page of discounts, searched,
|
|
11
|
+
* filtered by method, type and state, sorted and counted by the database, with
|
|
12
|
+
* the summary of every discount (commerce-discount-list.ts). The store
|
|
13
|
+
* currency comes with it: fixed amounts and minimums are minor units of it.
|
|
14
|
+
*/
|
|
15
|
+
export default new Action({
|
|
16
|
+
name: 'CommerceDiscountsAction',
|
|
17
|
+
description: 'Returns one page of Discount records for dashboard management.',
|
|
18
|
+
method: 'GET',
|
|
19
|
+
apiResponse: true,
|
|
20
|
+
|
|
21
|
+
async handle(request: RequestInstance) {
|
|
22
|
+
const query = parseDiscountListQuery(key => request.get<unknown>(key, ''))
|
|
23
|
+
if ('error' in query)
|
|
24
|
+
return response.json({ message: query.error }, 422)
|
|
25
|
+
|
|
26
|
+
const currency = normalizeCommerceCurrency(config.commerce?.currency)
|
|
27
|
+
try {
|
|
28
|
+
const discounts = await readDiscountPage(query, currency)
|
|
29
|
+
return {
|
|
30
|
+
records: discounts.records,
|
|
31
|
+
total: discounts.total,
|
|
32
|
+
page: discounts.page,
|
|
33
|
+
perPage: query.perPage,
|
|
34
|
+
summary: discounts.summary,
|
|
35
|
+
currency,
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
return dashboardOperationalError(error, 'Discount records could not be read.', 'CommerceDiscountsAction')
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
})
|