@stacksjs/defaults 0.75.612 → 0.75.613

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.
Files changed (116) hide show
  1. package/ai/skills/stacks-actions/SKILL.md +208 -0
  2. package/ai/skills/stacks-api/SKILL.md +1 -1
  3. package/ai/skills/stacks-buddy/SKILL.md +1 -1
  4. package/ai/skills/stacks-dashboard/SKILL.md +79 -0
  5. package/ai/skills/stacks-middleware/SKILL.md +4 -1
  6. package/ai/skills/stacks-native/CATALOG.md +12 -12
  7. package/ai/skills/stacks-validation/SKILL.md +7 -0
  8. package/app/Actions/Storefront/AddToCartAction.ts +12 -15
  9. package/app/Actions/Storefront/CheckoutContactAction.ts +18 -10
  10. package/app/Actions/Storefront/CheckoutShippingAction.ts +20 -10
  11. package/app/Actions/Storefront/PlaceOrderAction.ts +9 -12
  12. package/app/Actions/Storefront/UpdateCartItemAction.ts +11 -9
  13. package/app/Middleware/Abilities.ts +4 -3
  14. package/app/Middleware/Csrf.ts +10 -1
  15. package/app/Middleware/Throttle.ts +4 -4
  16. package/ide/vscode/package.json +1 -1
  17. package/package.json +5 -5
  18. package/resources/components/Dashboard/Analytics/AnalyticsPageHeader.stx +3 -13
  19. package/resources/components/Dashboard/App/RequestsOverview.stx +3 -20
  20. package/resources/components/Dashboard/App/SourceInventory.stx +1 -5
  21. package/resources/components/Dashboard/Auth/AccessTokenCreateDialog.stx +11 -28
  22. package/resources/components/Dashboard/Commerce/CommerceCategoriesDashboard.stx +4 -8
  23. package/resources/components/Dashboard/Commerce/CommerceCategoryDialog.stx +9 -9
  24. package/resources/components/Dashboard/Commerce/CommerceCouponDialog.stx +14 -14
  25. package/resources/components/Dashboard/Commerce/CommerceCouponsDashboard.stx +5 -9
  26. package/resources/components/Dashboard/Commerce/CommerceCustomerDialog.stx +7 -7
  27. package/resources/components/Dashboard/Commerce/CommerceCustomersDashboard.stx +3 -7
  28. package/resources/components/Dashboard/Commerce/CommerceGiftCardDialog.stx +15 -15
  29. package/resources/components/Dashboard/Commerce/CommerceGiftCardsDashboard.stx +5 -9
  30. package/resources/components/Dashboard/Commerce/CommerceManufacturerDialog.stx +12 -15
  31. package/resources/components/Dashboard/Commerce/CommerceManufacturersDashboard.stx +4 -28
  32. package/resources/components/Dashboard/Commerce/CommerceOrderDialog.stx +15 -15
  33. package/resources/components/Dashboard/Commerce/CommerceOrdersDashboard.stx +4 -8
  34. package/resources/components/Dashboard/Commerce/CommerceOverviewDashboard.stx +3 -11
  35. package/resources/components/Dashboard/Commerce/CommercePaymentsDashboard.stx +8 -9
  36. package/resources/components/Dashboard/Commerce/CommercePosCatalog.stx +3 -20
  37. package/resources/components/Dashboard/Commerce/CommercePosCheckoutDialog.stx +4 -4
  38. package/resources/components/Dashboard/Commerce/CommerceProductDialog.stx +14 -14
  39. package/resources/components/Dashboard/Commerce/CommerceProductsDashboard.stx +4 -8
  40. package/resources/components/Dashboard/Commerce/CommerceReviewEditDialog.stx +14 -24
  41. package/resources/components/Dashboard/Commerce/CommerceReviewsDashboard.stx +5 -43
  42. package/resources/components/Dashboard/Commerce/CommerceTaxDialog.stx +22 -38
  43. package/resources/components/Dashboard/Commerce/CommerceTaxesDashboard.stx +5 -33
  44. package/resources/components/Dashboard/Commerce/CommerceUnitDialog.stx +16 -30
  45. package/resources/components/Dashboard/Commerce/CommerceUnitsDashboard.stx +4 -28
  46. package/resources/components/Dashboard/Commerce/CommerceVariantDialog.stx +15 -9
  47. package/resources/components/Dashboard/Commerce/CommerceVariantsDashboard.stx +8 -9
  48. package/resources/components/Dashboard/Commerce/Delivery/CourierDialog.stx +14 -12
  49. package/resources/components/Dashboard/Commerce/Delivery/DeliveryRouteDialog.stx +9 -11
  50. package/resources/components/Dashboard/Commerce/Delivery/DigitalDeliveryDialog.stx +15 -9
  51. package/resources/components/Dashboard/Commerce/Delivery/LicenseKeyDialog.stx +11 -7
  52. package/resources/components/Dashboard/Commerce/Delivery/ShippingMethodDialog.stx +14 -8
  53. package/resources/components/Dashboard/Commerce/Delivery/ShippingRateDialog.stx +11 -17
  54. package/resources/components/Dashboard/Commerce/Delivery/ShippingZoneDialog.stx +18 -12
  55. package/resources/components/Dashboard/Commerce/PaymentRefundDialog.stx +1 -1
  56. package/resources/components/Dashboard/Commerce/PrintDeviceDialog.stx +5 -5
  57. package/resources/components/Dashboard/Commerce/PrintDevicesDashboard.stx +4 -8
  58. package/resources/components/Dashboard/Commerce/PrintLogsDashboard.stx +5 -9
  59. package/resources/components/Dashboard/Commerce/ProductWaitlistDashboard.stx +2 -10
  60. package/resources/components/Dashboard/Commerce/ProductWaitlistEntryDialog.stx +14 -67
  61. package/resources/components/Dashboard/Commerce/RestaurantWaitlistDashboard.stx +3 -18
  62. package/resources/components/Dashboard/Commerce/RestaurantWaitlistEntryDialog.stx +23 -69
  63. package/resources/components/Dashboard/Content/AuthorEditorDialog.stx +4 -16
  64. package/resources/components/Dashboard/Content/BlogDashboard.stx +2 -19
  65. package/resources/components/Dashboard/Content/BlogPostEditorDialog.stx +31 -51
  66. package/resources/components/Dashboard/Content/CommentsDashboard.stx +1 -1
  67. package/resources/components/Dashboard/Content/ContentDashboard.stx +1 -11
  68. package/resources/components/Dashboard/Content/CreateFolderDialog.stx +1 -4
  69. package/resources/components/Dashboard/Content/FileManagerDashboard.stx +2 -2
  70. package/resources/components/Dashboard/Content/PageEditorDialog.stx +8 -17
  71. package/resources/components/Dashboard/Content/PostEditorDialog.stx +35 -45
  72. package/resources/components/Dashboard/Content/PostsDashboard.stx +1 -13
  73. package/resources/components/Dashboard/Content/SeoDashboard.stx +2 -20
  74. package/resources/components/Dashboard/Content/SeoEditorDialog.stx +4 -38
  75. package/resources/components/Dashboard/Content/TaxonomyEditorDialog.stx +8 -15
  76. package/resources/components/Dashboard/Data/ActivityLog.stx +1 -5
  77. package/resources/components/Dashboard/Deployments/DeploymentList.stx +2 -11
  78. package/resources/components/Dashboard/Email/InboxMessageList.stx +1 -5
  79. package/resources/components/Dashboard/Infrastructure/DnsDashboard.stx +2 -16
  80. package/resources/components/Dashboard/Infrastructure/LogsDashboard.stx +6 -10
  81. package/resources/components/Dashboard/Infrastructure/MailboxesDashboard.stx +1 -5
  82. package/resources/components/Dashboard/Infrastructure/ServersDashboard.stx +1 -5
  83. package/resources/components/Dashboard/Jobs/JobHistory.stx +3 -12
  84. package/resources/components/Dashboard/Kanban/KanbanCardDialog.stx +57 -51
  85. package/resources/components/Dashboard/Library/ComponentsDashboard.stx +4 -14
  86. package/resources/components/Dashboard/Library/DependenciesDashboard.stx +2 -15
  87. package/resources/components/Dashboard/Library/PackagesDashboard.stx +1 -8
  88. package/resources/components/Dashboard/Library/SourceScaffoldDialog.stx +1 -12
  89. package/resources/components/Dashboard/Management/PermissionsDashboard.stx +3 -3
  90. package/resources/components/Dashboard/Marketing/AbandonedCartsDashboard.stx +4 -4
  91. package/resources/components/Dashboard/Marketing/CampaignDeliveryDialog.stx +3 -5
  92. package/resources/components/Dashboard/Marketing/CampaignDialog.stx +59 -93
  93. package/resources/components/Dashboard/Marketing/CampaignsDashboard.stx +5 -5
  94. package/resources/components/Dashboard/Marketing/MarketingListDialog.stx +12 -26
  95. package/resources/components/Dashboard/Marketing/MarketingListsDashboard.stx +4 -4
  96. package/resources/components/Dashboard/Marketing/RecoveryCampaignDialog.stx +12 -43
  97. package/resources/components/Dashboard/Marketing/SocialPostDialog.stx +7 -41
  98. package/resources/components/Dashboard/Marketing/SocialPostsDashboard.stx +5 -5
  99. package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +7 -23
  100. package/resources/components/Dashboard/Models/ModelsOverview.stx +2 -12
  101. package/resources/components/Dashboard/Notifications/NotificationDeliveries.stx +4 -27
  102. package/resources/components/Dashboard/Notifications/NotificationDeliveryHistory.stx +4 -36
  103. package/resources/components/Dashboard/Operations/RecoveryDestinationDialog.stx +18 -47
  104. package/resources/components/Dashboard/Operations/RecoveryPolicyDialog.stx +24 -78
  105. package/resources/components/Dashboard/Operations/RecoveryRestoreDialog.stx +8 -19
  106. package/resources/components/Dashboard/Queries/QueryDashboard.stx +3 -21
  107. package/resources/components/Dashboard/Releases/ReleaseDashboard.stx +2 -9
  108. package/resources/components/Dashboard/Settings/SettingsDashboard.stx +1 -11
  109. package/resources/components/Dashboard/UI/Input.stx +50 -1
  110. package/resources/components/Dashboard/UI/SearchFilter.stx +27 -17
  111. package/resources/components/Dashboard/UI/Select.stx +4 -1
  112. package/resources/components/Dashboard/UI/Textarea.stx +16 -1
  113. package/resources/views/cart.stx +14 -0
  114. package/resources/views/checkout/contact.stx +15 -1
  115. package/resources/views/checkout/payment.stx +7 -0
  116. package/resources/views/checkout/shipping.stx +39 -5
@@ -88,6 +88,214 @@ returning a raw Response owns the wire format and yields unknown client output.
88
88
  external boundaries without module-wide mocking. They do not justify mocking
89
89
  every internal collaborator or replacing a real database test with a fake.
90
90
 
91
+ ### A refused form goes back to its page
92
+
93
+ What a refused request is answered with follows what the caller asked for,
94
+ never the endpoint (stacksjs/stacks#3309):
95
+
96
+ | Caller | Answer |
97
+ |---|---|
98
+ | `fetch()`, an API client, anything that did not ask for a page | `422` with `{ success: false, message: 'Validation failed', errors }`, as always |
99
+ | A browser submitting an HTML form (`Accept` has `text/html`, not a GET) | `303` back to the page the form was on, with the messages and what was posted |
100
+
101
+ A script that asks for HTML is still a script: when the browser says what it
102
+ is fetching (`Sec-Fetch-Dest`), only a document or a frame counts as a page.
103
+ An action or route group with `apiResponse: true` answers JSON to everyone.
104
+
105
+ `validations` run before `handle()`, so an action cannot do this for itself.
106
+ The browser used to get the 422 body: a page of JSON with the back button as
107
+ the only way out. Do not work around it in `handle()` with a hand-rolled
108
+ `response.json({ error }, 422)`: declare the rule and let the router answer.
109
+ `request.validate()` inside a handler is answered the same way.
110
+
111
+ The page reads what came back, in a `<script server>`:
112
+
113
+ ```html
114
+ <script server>
115
+ const emailError = requestContext.error('email') // '' when there is none
116
+ const emailValue = requestContext.old('email', cart.email) // what was typed, else the saved value
117
+ </script>
118
+
119
+ <input type="email" name="email" value="{{ emailValue }}" aria-invalid="{{ emailError ? 'true' : 'false' }}">
120
+ @if (emailError)
121
+ <p role="alert">{{ emailError }}</p>
122
+ @endif
123
+ ```
124
+
125
+ - `requestContext.errors()` is every message by field (`{}` when nothing was
126
+ refused), `error(field)` the first for one field, `hasErrors()` whether
127
+ there are any, `old(field, fallback)` what was posted and `oldValues(field)`
128
+ every value of a repeated field.
129
+ - **Shown once.** They travel in a cookie (`stacks_form_flash`) signed with
130
+ `APP_KEY`, good for two minutes and for the one page it names. The page's
131
+ server removes it with the response that showed it. With no `APP_KEY` there
132
+ is nothing to sign with, and the browser gets a plain page listing the
133
+ messages instead.
134
+ - **Never a secret.** A field whose name says password, token, secret, key or
135
+ card is not sent back, and nor is a file. Draw those empty.
136
+ - **Only to this application's own page.** The form has to be on the same
137
+ origin (`Sec-Fetch-Site: same-origin`, or a matching host for a browser too
138
+ old to send it). A form on another site, or one with no `Referer`, gets the
139
+ plain page of messages and is not redirected.
140
+ - What was typed is dropped, longest value first, when it would not fit a
141
+ cookie. The messages always arrive.
142
+ - A form says a list by repeating a field name, and one occurrence arrives as
143
+ a string. A rule that asks for `schema.array()` takes it as a list of one,
144
+ and an empty field as an empty list. A value is never split on commas.
145
+ - A ticked checkbox with no `value` sends `on`, which a `schema.boolean()`
146
+ rule takes as true, like `true` and `1`.
147
+
148
+ A refusal only `handle()` can know about ("your cart is empty", "that item
149
+ has gone") is answered with `refuse()` from `@stacksjs/router`, never with a
150
+ hand-written `response.json({ error }, 400)` (stacksjs/stacks#3311):
151
+
152
+ ```ts
153
+ import { refuse } from '@stacksjs/router'
154
+
155
+ if (!cart)
156
+ return refuse('Your cart is empty.', { status: 400 })
157
+ if (!deliversTo(zip))
158
+ return refuse('We do not deliver to that postcode yet.', { field: 'shipping_zip' })
159
+ ```
160
+
161
+ - A caller that asked for data gets `{ error: message }` with that status
162
+ (`422` when none is given), plus `errors` by field when `field` is named:
163
+ the body such actions already wrote.
164
+ - A browser form goes back to its page with what was posted. A message with
165
+ a `field` is read with `requestContext.error(field)`; one without is about
166
+ the whole form and is read with `requestContext.formError()`.
167
+ `hasErrors()` is true for either.
168
+ - `authorize` and `before` can return one too.
169
+ - With no page to go back to, the browser gets the plain page of messages,
170
+ with the status the action chose.
171
+
172
+ ```html
173
+ <script server>
174
+ const formError = requestContext.formError()
175
+ </script>
176
+
177
+ @if (formError)
178
+ <p role="alert">{{ formError }}</p>
179
+ @endif
180
+ ```
181
+
182
+ A browser form refused for its CSRF token (a tab left open past the token's
183
+ life, or a second tab that replaced it) goes back to its page the same way,
184
+ with a sentence for the whole form and what was typed. The action does not
185
+ run. A script still gets the `403`, and a form posted from another site is
186
+ never sent back to a page of this one. A middleware of your own can do the
187
+ same by marking the error it throws with `FORM_REFUSAL` (`{ message, status }`).
188
+
189
+ A form can only send text, files and a name repeated for a list, and an
190
+ unticked checkbox sends nothing. `buddy doctor` reads every page's plain POST
191
+ form, finds the action it posts to in the route table, and warns, with the
192
+ file and line, about each rule that form can never meet: an object, a
193
+ required field the form has no control for, a required yes or no only a
194
+ checkbox sends, or a checkbox, radio or option value the rule refuses
195
+ (stacksjs/stacks#3311). A form whose address or field names are computed on
196
+ the page is not read.
197
+
198
+ Not covered yet: a form submitted with `method="get"`. It is a navigation, so
199
+ a failed rule is still answered with the 422 body; going back to its page
200
+ with a cookie is a different design, since the query string already holds
201
+ what was typed.
202
+
203
+ The shipped checkout is the worked example: the contact and shipping steps
204
+ declare their fields (`Actions/Storefront/CheckoutContactAction.ts`,
205
+ `CheckoutShippingAction.ts`), and every storefront action refuses an empty
206
+ cart with `refuse()`. The pages are `views/checkout/*.stx` and `views/cart.stx`.
207
+ Tests: `core/router/tests/form-validation-refusal.test.ts`,
208
+ `core/router/tests/form-action-refusal.test.ts`,
209
+ `core/config/tests/form-flash.test.ts`, and
210
+ `core/buddy/tests/refused-form-page.test.ts`, which posts a form through each
211
+ view server and reads the page that comes back.
212
+
213
+ ### A form that worked goes back to its page
214
+
215
+ The same split holds when the action succeeds (stacksjs/stacks#3312). A
216
+ browser form the action answers with **data** (an object, a list, a string,
217
+ nothing, or a JSON `Response`) is sent back (`303`) to the page it was on. A
218
+ `fetch()` or API caller gets the body, unchanged. The data in a tab was a page
219
+ of JSON that said nothing a person could read: from it, "revoked" and "broken"
220
+ looked the same.
221
+
222
+ Say what happened with `notice`, in the words the person would use about the
223
+ control they pressed:
224
+
225
+ ```ts
226
+ export default new Action({
227
+ name: 'RevokeTokenAction',
228
+ method: 'POST',
229
+ notice: result => result.already_revoked ? 'That token was already revoked' : 'Token revoked',
230
+ async handle(request) {
231
+ // ...
232
+ return { id: token.id, revoked_at: token.revoked_at, already_revoked: false }
233
+ },
234
+ })
235
+ ```
236
+
237
+ ```html
238
+ <script server>
239
+ const notice = requestContext.notice() // '' when there is nothing to say
240
+ </script>
241
+
242
+ @if (notice)
243
+ <p role="status">{{ notice }}</p>
244
+ @endif
245
+ ```
246
+
247
+ - **The words are yours.** `notice` is a string, or a function of what
248
+ `handle` returned and the request. The framework never makes one up: "Done"
249
+ cannot say which of the controls on a page just worked.
250
+ - **No notice, or an empty one, goes back and says nothing.** Right for a POST
251
+ that only reads. No cookie is set, so the page draws no empty bar.
252
+ - **What the action built itself is left alone**: a page it rendered (an HTML
253
+ `Response`), a redirect, an error status, a download, a stream. A secret
254
+ shown once, such as a new API token, must not travel in a redirect, so
255
+ answer with a rendered page that carries it.
256
+ - With no page of this application to go back to (no `Referer`, another site),
257
+ a notice is shown on a small page of its own; with no notice the body is
258
+ sent as before. With no `APP_KEY`, the notice is shown on that small page.
259
+ - Do not write the split by hand (`if (accept.includes('text/html')) return
260
+ response.redirect(...)`). Return the data and declare the notice, and
261
+ `next` when the form should go on somewhere else.
262
+
263
+ To send the browser on instead of back, say where with `next`, a path of this
264
+ application or a function of the result and the request:
265
+
266
+ ```ts
267
+ export default new Action({
268
+ name: 'CheckoutShippingAction',
269
+ method: 'POST',
270
+ next: '/checkout/payment',
271
+ async handle(request) {
272
+ // ...
273
+ return { ok: true, next: '/checkout/payment' }
274
+ },
275
+ })
276
+
277
+ // next: result => `/orders/${result.order_id}`
278
+ ```
279
+
280
+ - A script gets the body and is never redirected. A refusal still goes back
281
+ to the form's own page. A `notice` goes with the browser to the next page.
282
+ - Only ever a path on this application. A string that is not one fails when
283
+ the route is registered. A function's answer that is not one (an address
284
+ taken from the request) is not followed, and the browser goes back to the
285
+ form's page instead, so `next: (_, request) => request.get('redirect')`
286
+ cannot send anyone to another site.
287
+ - `notice` and `next` are told only what `handle` answered when it did what
288
+ was asked: `refuse()` is left out of `result`'s type. When `handle` reads
289
+ its request without a type written on it, declare `handle` first, because
290
+ TypeScript works out what it returns in the order the object is written.
291
+
292
+ The shipped cart is the worked example (`Actions/Storefront/UpdateCartItemAction.ts`,
293
+ `views/cart.stx`), and the checkout steps declare `next`
294
+ (`CheckoutContactAction`, `CheckoutShippingAction`, `PlaceOrderAction`,
295
+ `AddToCartAction`). Tests: `core/router/tests/form-success-answer.test.ts`,
296
+ `core/router/tests/form-next-page.test.ts`, and
297
+ `core/buddy/tests/refused-form-page.test.ts` for the cart page.
298
+
91
299
  `Precognition: true` or `?_validate=1` requests a validation-only probe.
92
300
  `Precognition-Validate-Only` narrows explicit validation fields. Probes stop
93
301
  before authorization/hooks/handler side effects, and do not magically run
@@ -316,7 +316,7 @@ export default new Middleware({
316
316
  throw error
317
317
  }
318
318
  // Set authenticated user on request
319
- ;(request as any)._authenticatedUser = user
319
+ request._authenticatedUser = user
320
320
  },
321
321
  })
322
322
  ```
@@ -616,7 +616,7 @@ buddy ai:context # compact deterministic project context for coding
616
616
  -o/--output [path] # write to a file instead of stdout
617
617
  --max-chars [characters] # prompt payload character budget (default: 4000)
618
618
  --model [model] # model family for heuristic token estimates
619
- buddy doctor # health checks (Bun version, Node, package.json, .env, APP_KEY, mail DNS)
619
+ buddy doctor # health checks (Bun version, Node, package.json, .env, APP_KEY, mail DNS, forms their action's rules refuse)
620
620
  buddy tinker # interactive REPL with Stacks preloaded
621
621
  -e/--eval [expr] # evaluate expression and exit
622
622
  --print [expr] # evaluate, print, and exit
@@ -635,6 +635,85 @@ this save only ("Clear stored password"), an acknowledgement, and "remember
635
635
  me" or the terms on the sign-in forms. `tests/unit/dashboard-switch-contract.test.ts`
636
636
  lists every one by file with its reason and fails on any other.
637
637
 
638
+ ### A dialog asks with the shared controls
639
+
640
+ A hand-built dialog asks for a value with `Dashboard/UI/Input.stx`,
641
+ `Select.stx` and `Textarea.stx`, as a model's form does, never with a native
642
+ `<input>`, `<select>` or `<textarea>` and a copy of their classes
643
+ (stacksjs/stacks#3310). Every dashboard dialog is converted;
644
+ `tests/unit/dashboard-form-controls.test.ts` fails if one writes its own again,
645
+ and names the one native control a converted dialog keeps (the upload
646
+ dialog's file picker) with its reason.
647
+
648
+ ```html
649
+ <Input v-model:value="name" label="Name" :maxLength="50" :required="true" />
650
+ <Input v-model:value="price" :label="'Price (' + currency() + ')'" type="number" min="0" :step="moneyInputStep(currency())" inputmode="decimal" :required="true" :error="price() !== '' ? priceError() : ''" />
651
+ <Select v-model:value="parentCategoryId" label="Parent category" placeholder="" :options="[{ value: '', label: 'Root category' }, ...parentOptions().map(option => ({ value: option.id, label: option.name }))]" />
652
+ <Textarea v-model:value="notes" label="Notes" :rows="3" :maxLength="500" />
653
+ ```
654
+
655
+ - **Input** takes what the browser holds a value to: `min`, `max`, `step`,
656
+ `maxLength`, `minLength`, `inputmode`, `:spellcheck="false"`, `list` (the id
657
+ of a `<datalist>` kept beside it), plus `monospace` for a code, a key or a
658
+ slug and `class` for what is added to the input itself (`uppercase`). A
659
+ number input gets digits of one width without being asked.
660
+ - **Select** takes its choices as `:options`, each `{ value, label }`. A choice
661
+ that may be left empty is one of the options and `placeholder=""`; a choice
662
+ that must be made keeps a `placeholder`, which is shown and cannot be
663
+ chosen. It keeps its choice when the options arrive after the value, which a
664
+ search-then-pick field does every time.
665
+ - **A hint and an error are props.** `hint` is the sentence under the field;
666
+ `error` takes its place and marks the field. Both can follow what is typed
667
+ (`:hint`, `:error`).
668
+ - **The input reports text.** There is no `.number` or `.trim`: make a value a
669
+ number, or trim it, where it is checked and where it is sent. `@input`,
670
+ `@change` and `@blur` hand the handler the value, not the event.
671
+ - **Do not name a field as the Modal names its own.** A prop bound inside a
672
+ `Modal`'s slot is first read in the Modal's own script, so a field called
673
+ `description` opened showing the dialog's description text. The Modal's
674
+ names are its props: `title`, `description`, `size`, `position`, `role` and
675
+ the rest. Call the field `descriptionText`, `reviewTitle`. The test reads
676
+ the Modal's props and fails on a collision.
677
+ - **Give it a box of its own inside a `space-y-*` stack**, as a switch needs.
678
+ - **Several of many is a `Checkbox` per option**, ticked when its id is in the
679
+ list and adding or removing it as it is ticked. Loop on a wrapper, not on
680
+ the component (a loop on a component tag loses its item in slot content):
681
+
682
+ ```html
683
+ <span :for="tagOption in tags()" class="contents">
684
+ <Checkbox size="sm" :label="tagOption.name" :checked="tagIds().includes(tagOption.id)" @update:checked="chooseTag(tagOption.id, $event)" />
685
+ </span>
686
+ ```
687
+ - `Input` takes `autofocus` for the field a dialog focuses when it opens and
688
+ `pattern` as a native input does, and `Textarea` takes `minLength`.
689
+ - **Keys arrive as the event.** `@keydown` on either hands over the
690
+ `KeyboardEvent`, so the dialog says what Enter, Command+Enter or Escape
691
+ does and can call `preventDefault()` or `stopPropagation()`; there are no
692
+ `.enter` or `.meta` modifiers on a component.
693
+
694
+ ### A list page filters with the shared controls
695
+
696
+ A list page's filter row is `UI/SearchFilter.stx` and `Select`, never a native
697
+ search box or dropdown with copied classes (stacksjs/stacks#3310). The same
698
+ test fails if one comes back, and names the few native ones left (a settings
699
+ form, a console, the search palette) with what they are.
700
+
701
+ ```html
702
+ <div class="sm:col-span-2"><SearchFilter v-model:searchValue="search" placeholder="Search codes or products" ariaLabel="Search coupons" /></div>
703
+ <Select v-model:value="statusFilter" ariaLabel="Coupon status" placeholder="" :options="[{ value: 'all', label: 'All statuses' }, ...statuses().map(status => ({ value: status, label: status }))]" @change="reloadFilters" />
704
+ ```
705
+
706
+ - **SearchFilter is the shared input with a search icon**, so it matches the
707
+ dropdowns beside it. `ariaLabel` names the list it searches; a `class` on
708
+ it sizes the whole field (`class="w-56"`).
709
+ - **It reports only what is typed**: `@search` does not fire as the page
710
+ mounts, nor when the page sets the box itself (`search.set('')` to clear
711
+ it), so a page that reloads on `@search` loads once.
712
+ - **A dropdown updates its value before `@change`**, so a handler that reloads
713
+ reads the choice just made.
714
+ - A hidden label becomes `ariaLabel`. A visible word beside the dropdown
715
+ ("Sort") stays, with the dropdown inside its label at `size="sm"`.
716
+
638
717
  ### Sidebar-aware overlays
639
718
 
640
719
  The desktop sidebar is fixed and publishes its current width through
@@ -248,7 +248,10 @@ User middleware in `app/Middleware/` always takes precedence over framework defa
248
248
  The default `defaults/app/Middleware/Auth.ts` resolves a parsed bearer first,
249
249
  then the configured token cookie, then `session_id`. It loads the user, calls
250
250
  `Auth.setUser`, stamps `_authenticatedUser`, and stamps `_currentAccessToken`
251
- for token authentication. The following is only a minimal custom bearer guard:
251
+ for token authentication. Both read back typed, with no cast:
252
+ `_authenticatedUser` is the User row (`AuthenticatedUser`, which
253
+ `@stacksjs/auth` registers through the router's `RequestTypeRegistry`), and
254
+ `_currentAccessToken` is an `AccessToken`, whose `scopes` say what it grants. The following is only a minimal custom bearer guard:
252
255
 
253
256
  ```typescript
254
257
  export default new Middleware({
@@ -21,7 +21,7 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
21
21
  | `@stacksjs/auth` | [`stacks-auth`](../stacks-auth/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/index.ts) | 136 |
22
22
  | `@stacksjs/browser` | [`stacks-browser`](../stacks-browser/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/browser/src/index.ts) | 10 |
23
23
  | `@stacksjs/browser-extension` | [`stacks-browser-extension`](../stacks-browser-extension/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/browser-extension/src/index.ts) | 9 |
24
- | `@stacksjs/buddy` | [`stacks-buddy`](../stacks-buddy/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/src/index.ts) | 210 |
24
+ | `@stacksjs/buddy` | [`stacks-buddy`](../stacks-buddy/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/src/index.ts) | 212 |
25
25
  | `@stacksjs/build` | [`stacks-build`](../stacks-build/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/build/src/index.ts) | 7 |
26
26
  | `@stacksjs/cache` | [`stacks-cache`](../stacks-cache/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cache/src/index.ts) | 24 |
27
27
  | `@stacksjs/calendar-api` | [`stacks-calendar`](../stacks-calendar/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/calendar-api/src/index.ts) | 5 |
@@ -33,7 +33,7 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
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
34
  | `@stacksjs/commerce` | [`stacks-commerce`](../stacks-commerce/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/index.ts) | 15 |
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
- | `@stacksjs/config` | [`stacks-config`](../stacks-config/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/index.ts) | 16 |
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
38
  | `@stacksjs/database` | [`stacks-database`](../stacks-database/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/index.ts) | 147 |
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 |
@@ -66,7 +66,7 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
66
66
  | `@stacksjs/newsletter` | [`stacks-newsletter`](../stacks-newsletter/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/newsletter/src/index.ts) | 10 |
67
67
  | `@stacksjs/notifications` | [`stacks-notifications`](../stacks-notifications/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/notifications/src/index.ts) | 18 |
68
68
  | `@stacksjs/objects` | [`stacks-objects`](../stacks-objects/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/objects/src/index.ts) | 10 |
69
- | `@stacksjs/orm` | [`stacks-orm`](../stacks-orm/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/index.ts) | 78 |
69
+ | `@stacksjs/orm` | [`stacks-orm`](../stacks-orm/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/index.ts) | 79 |
70
70
  | `@stacksjs/pagination` | [`stacks-pagination`](../stacks-pagination/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/pagination/src/index.ts) | 1 |
71
71
  | `@stacksjs/path` | [`stacks-path`](../stacks-path/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/path/src/index.ts) | 13 |
72
72
  | `@stacksjs/payments` | [`stacks-payments`](../stacks-payments/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/payments/src/index.ts) | 40 |
@@ -76,7 +76,7 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
76
76
  | `@stacksjs/realtime` | [`stacks-realtime`](../stacks-realtime/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/realtime/src/index.ts) | 21 |
77
77
  | `@stacksjs/registry` | [`stacks-registry`](../stacks-registry/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/registry/src/index.ts) | 1 |
78
78
  | `@stacksjs/repl` | [`stacks-repl`](../stacks-repl/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/repl/src/index.ts) | 2 |
79
- | `@stacksjs/router` | [`stacks-router`](../stacks-router/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/index.ts) | 106 |
79
+ | `@stacksjs/router` | [`stacks-router`](../stacks-router/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/index.ts) | 112 |
80
80
  | `@stacksjs/scheduler` | [`stacks-scheduler`](../stacks-scheduler/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/scheduler/src/index.ts) | 19 |
81
81
  | `@stacksjs/search-engine` | [`stacks-search-engine`](../stacks-search-engine/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/search-engine/src/index.ts) | 11 |
82
82
  | `@stacksjs/security` | [`stacks-security`](../stacks-security/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/security/src/index.ts) | 12 |
@@ -222,7 +222,7 @@ Read the entrypoint and package export map for re-exported or type-only surfaces
222
222
 
223
223
  Local source modules: [src/commands/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/src/commands/index.ts).
224
224
 
225
- Evidence directory: [210 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
225
+ Evidence directory: [212 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
226
226
 
227
227
  ### @stacksjs/build
228
228
 
@@ -336,11 +336,11 @@ Evidence directory: [18 retained tests](https://github.com/stacksjs/stacks/blob/
336
336
 
337
337
  Guidance: [`stacks-config`](../stacks-config/SKILL.md). Source: [storage/framework/core/config/src/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/index.ts).
338
338
 
339
- Declared runtime exports: `DEFAULT_VIEWS_ALWAYS`, `DEFAULT_VIEW_ROUTE_BUNDLES`, `DEFAULT_VIEW_TEMPLATES`, `FRAMEWORK_DEFAULTS`, `createRequestContext`, `disableFeature`, `enableFeature`, `enterRequestScope`, `feature`, `installRequestContext`, `installRequestScope`, `listFeatures`, `packageComponentRoots`, `packageJobRoots`, `packageMigrationRoots`, `packageModelRoots`, `packageViewRoots`, `parseCookieHeader`, `reportConfigIssues`, `resetFeature`, `resolveViewPatterns`, `scopeStxServeContext`, `scopedRequestSnapshot`, `useRequestEvent`, `validateConfig`, `withheldDefaultViews`.
339
+ Declared runtime exports: `DEFAULT_VIEWS_ALWAYS`, `DEFAULT_VIEW_ROUTE_BUNDLES`, `DEFAULT_VIEW_TEMPLATES`, `FORM_FLASH_COOKIE`, `FORM_FLASH_MAX_BYTES`, `FORM_FLASH_SECONDS`, `FRAMEWORK_DEFAULTS`, `clearShownFormFlash`, `createRequestContext`, `disableFeature`, `enableFeature`, `enterRequestScope`, `expiredFormFlashCookie`, `feature`, `flashableField`, `flashableInput`, `formFlashCookie`, `installRequestContext`, `installRequestScope`, `listFeatures`, `openFormFlash`, `packageComponentRoots`, `packageJobRoots`, `packageMigrationRoots`, `packageModelRoots`, `packageViewRoots`, `parseCookieHeader`, `reportConfigIssues`, `resetFeature`, `resolveViewPatterns`, `scopeStxServeContext`, `scopedRequestSnapshot`, `sealFormFlash`, `useRequestEvent`, `validateConfig`, `withheldDefaultViews`.
340
340
 
341
- Local source modules: [src/capabilities.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/capabilities.ts), [src/config.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/config.ts), [src/defaults.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/defaults.ts), [src/discovered-resources.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/discovered-resources.ts), [src/features.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/features.ts), [src/request-context.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/request-context.ts), [src/validators.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/validators.ts), [src/views.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/views.ts).
341
+ Local source modules: [src/capabilities.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/capabilities.ts), [src/config.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/config.ts), [src/defaults.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/defaults.ts), [src/discovered-resources.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/discovered-resources.ts), [src/features.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/features.ts), [src/form-flash.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/form-flash.ts), [src/request-context.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/request-context.ts), [src/validators.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/validators.ts), [src/views.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/views.ts).
342
342
 
343
- Evidence directory: [16 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
343
+ Evidence directory: [17 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
344
344
 
345
345
  ### @stacksjs/cron
346
346
 
@@ -654,7 +654,7 @@ Declared runtime exports: `Activity`, `AnalyticsEvent`, `Auction`, `AuctionItem`
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
 
657
- Evidence directory: [78 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
657
+ Evidence directory: [79 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
658
658
 
659
659
  ### @stacksjs/pagination
660
660
 
@@ -744,11 +744,11 @@ Evidence directory: [2 retained tests](https://github.com/stacksjs/stacks/blob/m
744
744
 
745
745
  Guidance: [`stacks-router`](../stacks-router/SKILL.md). Source: [storage/framework/core/router/src/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/index.ts).
746
746
 
747
- Declared runtime exports: `DASHBOARD_ROUTE_GROUPS`, `DEFAULT_ROUTE_BUNDLE_FEATURES`, `DEFAULT_ROUTE_REGISTRY`, `DatabaseSessionStore`, `EncryptedSessionStore`, `FileSessionStore`, `JSON_CONTENT_TYPE`, `MemorySessionStore`, `Middleware`, `PathParamError`, `RedisSessionStore`, `RequestBodyError`, `appRouteRegistry`, `assertRouteMiddlewareResolvable`, `bundleMounts`, `cacheRedisConnection`, `cacheRequestQuery`, `checkApplicationHealth`, `clearCsrfModuleCache`, `clearCurrentRequest`, `clearMiddlewareCache`, `clearRateLimit`, `clearRouteModelBindings`, `clearTrackedQueries`, `clientAddress`, `configureViewDirectories`, `createErrorResponse`, `createMiddlewareErrorResponse`, `createNotFoundResponse`, `createSessionStore`, `createStacksRouter`, `createStacksSessionStore`, `createTypedRouter`, `createValidationErrorResponse`, `dashboardGroupMiddleware`, `defineMiddleware`, `defineRouteModelBinding`, `describeUnknownDashboardGroups`, `disableViewRouting`, `enhanceRequest`, `fallbackStorage`, `findUnresolvableRouteMiddleware`, `getCurrentRequest`, `getQueryShapeCounts`, `getTraceId`, `installMiddlewareHotReload`, `isApiRequest`, `isRouterAction`, `listNamedRoutes`, `listRedirectRoutes`, `listRegisteredRoutes`, `listRootMountedAppRoutes`, `loadMiddlewareHandlers`, `loadRoutes`, `mountedDefaultRouteBundles`, `parseJsonText`, `provideActions`, `provideMiddleware`, `rateLimit`, `rateLimitScale`, `rateLimitStatus`, `readJsonBody`, `readTextBody`, `request`, `resetBootHooks`, `resetRateLimiters`, `resetSharedRateLimitStorage`, `resetShutdownHooks`, `resolveActionHandler`, `resolveActionValidations`, `resolveDashboardAccess`, `resolveRouteModel`, `route`, `routeModelBindings`, `routeParams`, `runBootHooks`, `runHealthProbes`, `runShutdownHooks`, `runWithRequest`, `safePathParam`, `sanitizePathParam`, `scaledLimit`, `serve`, `serverResponse`, `setCurrentRequest`, `setRouteModelFallback`, `sharedRateLimitStorage`, `signUrl`, `signedUrl`, `stream`, `trackQuery`, `trustedProxies`, `url`, `useRateLimitStorage`, `verifySignedUrl`, `verifySignedUrlMiddleware`, `warnOnMultipleRouterInstances`, `withRouteAdmission`, `withTraceId`, `wrapAction`.
747
+ Declared runtime exports: `DASHBOARD_ROUTE_GROUPS`, `DEFAULT_ROUTE_BUNDLE_FEATURES`, `DEFAULT_ROUTE_REGISTRY`, `DatabaseSessionStore`, `EncryptedSessionStore`, `FORM_REFUSAL`, `FileSessionStore`, `JSON_CONTENT_TYPE`, `MemorySessionStore`, `Middleware`, `PathParamError`, `RedisSessionStore`, `RequestBodyError`, `appRouteRegistry`, `assertRouteMiddlewareResolvable`, `bundleMounts`, `cacheRedisConnection`, `cacheRequestQuery`, `checkApplicationHealth`, `clearCsrfModuleCache`, `clearCurrentRequest`, `clearMiddlewareCache`, `clearRateLimit`, `clearRouteModelBindings`, `clearTrackedQueries`, `clientAddress`, `configureViewDirectories`, `createErrorResponse`, `createMiddlewareErrorResponse`, `createNotFoundResponse`, `createSessionStore`, `createStacksRouter`, `createStacksSessionStore`, `createTypedRouter`, `createValidationErrorResponse`, `dashboardGroupMiddleware`, `defineMiddleware`, `defineRouteModelBinding`, `describeUnknownDashboardGroups`, `disableViewRouting`, `enhanceRequest`, `fallbackStorage`, `findUnresolvableRouteMiddleware`, `formRefusalOf`, `getCurrentRequest`, `getQueryShapeCounts`, `getTraceId`, `installMiddlewareHotReload`, `isApiRequest`, `isRouterAction`, `listNamedRoutes`, `listRedirectRoutes`, `listRegisteredRoutes`, `listRootMountedAppRoutes`, `loadMiddlewareHandlers`, `loadRoutes`, `mountedDefaultRouteBundles`, `parseJsonText`, `provideActions`, `provideMiddleware`, `rateLimit`, `rateLimitScale`, `rateLimitStatus`, `readJsonBody`, `readTextBody`, `refuse`, `request`, `resetBootHooks`, `resetRateLimiters`, `resetSharedRateLimitStorage`, `resetShutdownHooks`, `resolveActionHandler`, `resolveActionValidations`, `resolveDashboardAccess`, `resolveRouteModel`, `route`, `routeModelBindings`, `routeParams`, `runBootHooks`, `runHealthProbes`, `runShutdownHooks`, `runWithRequest`, `safePathParam`, `sanitizePathParam`, `scaledLimit`, `serve`, `serverResponse`, `setCurrentRequest`, `setRouteModelFallback`, `sharedRateLimitStorage`, `signUrl`, `signedUrl`, `stream`, `trackQuery`, `trustedProxies`, `url`, `useRateLimitStorage`, `verifySignedUrl`, `verifySignedUrlMiddleware`, `warnOnMultipleRouterInstances`, `withRouteAdmission`, `withTraceId`, `wrapAction`.
748
748
 
749
- Local source modules: [src/api-shape.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/api-shape.ts), [src/body.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/body.ts), [src/dashboard-access.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/dashboard-access.ts), [src/encrypted-session-store.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/encrypted-session-store.ts), [src/error-handler.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/error-handler.ts), [src/health.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/health.ts), [src/json.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/json.ts), [src/middleware.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/middleware.ts), [src/path-sanitize.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/path-sanitize.ts), [src/rate-limit.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/rate-limit.ts), [src/request-augmentation.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/request-augmentation.ts), [src/request-context.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/request-context.ts), [src/route-loader.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/route-loader.ts), [src/route-model-binding.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/route-model-binding.ts), [src/security-settings.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/security-settings.ts), [src/session-factory.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/session-factory.ts), [src/signed-url.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/signed-url.ts), [src/stacks-router.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/stacks-router.ts), [src/typed-router.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/typed-router.ts).
749
+ Local source modules: [src/api-shape.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/api-shape.ts), [src/body.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/body.ts), [src/dashboard-access.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/dashboard-access.ts), [src/encrypted-session-store.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/encrypted-session-store.ts), [src/error-handler.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/error-handler.ts), [src/health.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/health.ts), [src/json.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/json.ts), [src/middleware.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/middleware.ts), [src/path-sanitize.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/path-sanitize.ts), [src/rate-limit.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/rate-limit.ts), [src/refuse.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/refuse.ts), [src/request-augmentation.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/request-augmentation.ts), [src/request-context.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/request-context.ts), [src/route-loader.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/route-loader.ts), [src/route-model-binding.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/route-model-binding.ts), [src/security-settings.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/security-settings.ts), [src/session-factory.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/session-factory.ts), [src/signed-url.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/signed-url.ts), [src/stacks-router.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/stacks-router.ts), [src/typed-router.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/typed-router.ts).
750
750
 
751
- Evidence directory: [106 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
751
+ Evidence directory: [112 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
752
752
 
753
753
  ### @stacksjs/scheduler
754
754
 
@@ -435,6 +435,13 @@ and validateFieldAsync support application async validation. These helpers propa
435
435
  instead of approving unchecked values. Keep operational failures separate from invalid input. Validate
436
436
  uniqueness at the durable write boundary and handle a uniqueness violation there.
437
437
 
438
+ A refused request is answered by what the caller asked for: a script or an API
439
+ client gets the 422 body, and a browser that submitted an HTML form is sent
440
+ back to its page with the messages and what it posted, which the page reads
441
+ with `requestContext.error(field)` and `requestContext.old(field)`
442
+ (stacksjs/stacks#3309). The whole of it is in the stacks-actions skill, under
443
+ "A refused form goes back to its page".
444
+
438
445
  Local is.ts helpers and legacy rules/type declarations are not
439
446
  automatically all public exports from the root.
440
447
 
@@ -1,7 +1,7 @@
1
1
  import { Action } from '@stacksjs/actions/runtime'
2
2
  import { config } from '@stacksjs/config'
3
3
  import { db, sqlDateTime } from '@stacksjs/database/runtime'
4
- import { response } from '@stacksjs/router'
4
+ import { refuse } from '@stacksjs/router'
5
5
  import { randomUUIDv7 } from 'bun'
6
6
  import { readCartCookie, writeCartCookie } from '../../Storefront/CartCookie'
7
7
  import { storefrontCurrency } from '../../Storefront/StorefrontMoney'
@@ -22,21 +22,26 @@ const COOKIE_OPTS = {
22
22
  * on first add so empty visitors don't litter the table.
23
23
  * - Idempotent per product: if the same slug is already in the cart we
24
24
  * bump the existing line's quantity instead of inserting a duplicate.
25
- * - Form vs XHR: a normal HTML form post redirects to /cart so the
26
- * back button works; XHR callers (the cart drawer) get JSON and
27
- * stay on the current page.
25
+ * - Form vs XHR: a normal HTML form post goes on to the cart, or to the
26
+ * page its `redirect` field names when that is a page of this shop
27
+ * (`next` below never follows another site); XHR callers (the cart
28
+ * drawer) get JSON and stay on the current page.
28
29
  */
29
30
  export default new Action({
30
31
  name: 'AddToCartAction',
31
32
  description: 'Add a product to the anonymous cart, keyed by cookie session.',
32
33
  method: 'POST',
34
+ // The field was followed wherever it pointed, so a link could send a
35
+ // shopper to any site after adding to the cart. The router follows only a
36
+ // path of this application, and goes back to the form's page otherwise.
37
+ next: (_result: unknown, request: any) => String(request.get('redirect') ?? '') || '/cart',
33
38
 
34
39
  async handle(request: any) {
35
40
  const slug = String(request.get('slug') ?? '').trim()
36
41
  const quantity = Math.max(1, Math.min(99, Number(request.get('quantity') ?? 1) || 1))
37
42
 
38
43
  if (!slug)
39
- return response.json({ error: 'A product slug is required.' }, { status: 422 })
44
+ return refuse('Choose a product to add.', { field: 'slug' })
40
45
 
41
46
  const product = await (db as any)
42
47
  .selectFrom('products')
@@ -47,7 +52,7 @@ export default new Action({
47
52
  .executeTakeFirst()
48
53
 
49
54
  if (!product)
50
- return response.json({ error: `Product "${slug}" not found` }, { status: 404 })
55
+ return refuse('That product is no longer available.', { status: 404 })
51
56
 
52
57
  // readCartCookie verifies the HMAC; tampered cookies return null
53
58
  // and the action falls through to the "create new cart" branch as
@@ -129,15 +134,7 @@ export default new Action({
129
134
 
130
135
  await recomputeCartTotals(cart.id)
131
136
 
132
- // Browser form post → redirect; XHR (cart drawer) → JSON.
133
- const wantsHtml = (request.headers?.get?.('accept') || '').includes('text/html')
134
- const xhr = request.headers?.get?.('x-requested-with') === 'XMLHttpRequest'
135
- const redirectTarget = String(request.get('redirect') ?? '/cart')
136
-
137
- if (wantsHtml && !xhr)
138
- return response.redirect(redirectTarget)
139
-
140
- return response.json({ ok: true, cart_id: cart.id })
137
+ return { ok: true, cart_id: cart.id }
141
138
  },
142
139
  })
143
140
 
@@ -1,6 +1,7 @@
1
1
  import { Action } from '@stacksjs/actions/runtime'
2
2
  import { db } from '@stacksjs/database/runtime'
3
- import { response } from '@stacksjs/router'
3
+ import { refuse } from '@stacksjs/router'
4
+ import { schema } from '@stacksjs/validation/runtime'
4
5
  import { readCartCookie } from '../../Storefront/CartCookie'
5
6
 
6
7
  const CART_COOKIE = 'stacks_cart'
@@ -14,15 +15,27 @@ export default new Action({
14
15
  name: 'CheckoutContactAction',
15
16
  description: 'Save the shopper email on the active cart.',
16
17
  method: 'POST',
18
+ // A browser form goes on to the next step; a script gets `next` in the body.
19
+ next: '/checkout/shipping',
20
+
21
+ // Declared, so the router answers a wrong address the way the caller asked
22
+ // to be answered: the checkout page gets the shopper back on the contact
23
+ // step with the message under the field and what they typed still in it,
24
+ // and a script gets the 422 body. Checked by hand in `handle`, a form was
25
+ // answered with a page of JSON (stacksjs/stacks#3309).
26
+ validations: {
27
+ email: { rule: schema.string().email().required(), message: 'Enter a valid email address.' },
28
+ },
17
29
 
18
30
  async handle(request: any) {
19
31
  const email = String(request.get('email') ?? '').trim().toLowerCase()
32
+ // For a caller that runs the action without the router in front of it.
20
33
  if (!email || !email.includes('@'))
21
- return response.json({ error: 'A valid email is required.' }, { status: 422 })
34
+ return refuse('Enter a valid email address.', { field: 'email' })
22
35
 
23
36
  const token = readCartCookie(request, CART_COOKIE)
24
37
  if (!token)
25
- return response.json({ error: 'Your cart is empty.' }, { status: 400 })
38
+ return refuse('Your cart is empty.', { status: 400 })
26
39
 
27
40
  const cart = await (db as any)
28
41
  .selectFrom('carts')
@@ -32,7 +45,7 @@ export default new Action({
32
45
  .executeTakeFirst()
33
46
 
34
47
  if (!cart)
35
- return response.json({ error: 'Your cart is empty.' }, { status: 400 })
48
+ return refuse('Your cart is empty.', { status: 400 })
36
49
 
37
50
  await (db as any)
38
51
  .updateTable('carts')
@@ -40,11 +53,6 @@ export default new Action({
40
53
  .where('id', '=', cart.id)
41
54
  .execute()
42
55
 
43
- const wantsHtml = (request.headers?.get?.('accept') || '').includes('text/html')
44
- const xhr = request.headers?.get?.('x-requested-with') === 'XMLHttpRequest'
45
- if (wantsHtml && !xhr)
46
- return response.redirect('/checkout/shipping')
47
-
48
- return response.json({ ok: true, next: '/checkout/shipping' })
56
+ return { ok: true, next: '/checkout/shipping' }
49
57
  },
50
58
  })