@stacksjs/defaults 0.75.634 → 0.75.636

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.
@@ -21,6 +21,32 @@ The `@stacksjs/auth` package provides comprehensive authentication and authoriza
21
21
  - Middleware aliases: `app/Middleware.ts`
22
22
  - Auth types: `storage/framework/core/types/src/auth.ts`
23
23
 
24
+ ## Changing the sign-in flow: `buddy make:auth`
25
+
26
+ Login, registration, two-factor sign-in, logout and password reset already run
27
+ from the framework defaults: `defaults/routes/auth.ts` serves them, and nothing
28
+ has to be copied for them to work. `buddy make:auth` is for changing them. It
29
+ copies the files that make up the flow to the paths the framework reads before
30
+ its own:
31
+
32
+ - pages: `resources/views/login.stx`, `register.stx`, `forgot-password.stx`,
33
+ `password/reset/[token].stx`;
34
+ - the components they render, under `resources/components/Dashboard/Auth/`.
35
+ Each page is a thin wrapper: `LoginDashboard` signs in and redirects, `Login`
36
+ is the form, `AuthCard` the shared card. Change the form in `Login.stx`;
37
+ - the actions the default routes name, under `app/Actions/Auth/` and
38
+ `app/Actions/Password/`, plus `app/password-policy.ts`, which they import.
39
+
40
+ The routes are not copied: user routes load first and the router reads an
41
+ action from `app/Actions` before the default, so the default routes already run
42
+ the copies. A file the app has is kept unless `--force` is passed, so running it
43
+ again only fills in what is missing. `--api` copies the actions only, and
44
+ `--dry-run` lists the files. It regenerates the action registry, so the router
45
+ does not warn that the registry is stale. A copied file no longer receives
46
+ framework updates from `buddy upgrade`; copy one file at a time with
47
+ `buddy publish:view`, `publish:component` or `publish:action` when that is all
48
+ you need.
49
+
24
50
  ## Source Files
25
51
 
26
52
  ```
@@ -124,7 +124,8 @@ class Cdp {
124
124
 
125
125
  static connect(wsUrl: string, timeoutMs = 10_000): Promise<Cdp> {
126
126
  return new Promise((resolve, reject) => {
127
- const ws = new WebSocket(wsUrl)
127
+ // Uncompressed: loopback gains nothing from permessage-deflate.
128
+ const ws = new WebSocket(wsUrl, { perMessageDeflate: false })
128
129
  const t = setTimeout(() => reject(new Error('CDP connect timeout')), timeoutMs)
129
130
  ws.addEventListener('open', () => { clearTimeout(t); resolve(new Cdp(ws)) })
130
131
  ws.addEventListener('error', e => { clearTimeout(t); reject(e) })
@@ -74,8 +74,8 @@ buddy dashboard [project] # open a project's dashboard, started in the back
74
74
  --stop # stop that project's background dashboard
75
75
 
76
76
  buddy daemon # is buddy running in the background, and what is it running
77
- buddy daemon:start # start it (nothing requires this; it starts on demand)
78
- buddy daemon:stop # stop it and the dashboards it started
77
+ buddy daemon:start # start it to watch opted-in projects
78
+ buddy daemon:stop # stop generation and its dashboards
79
79
  buddy daemon:restart
80
80
  buddy daemon:logs # --lines <count>
81
81
  ```
@@ -90,10 +90,13 @@ projects. `findStacksProjects()` in `@stacksjs/utils` is the disk scan behind
90
90
  `projects:scan` and nothing else should need it.
91
91
 
92
92
  The daemon (`core/actions/src/daemon/`) starts a project's dashboard through
93
- that project's own `./buddy dev:dashboard`, on a port reserved for that project
94
- (3900 upwards, the same one every time), with no native window and an idle
95
- limit. It listens on a unix socket in `~/.stacks/buddy/`, loads no project
96
- code, polls nothing, and exits once it has no dashboards left. Reach it through
93
+ that project's own `./buddy dev:dashboard`, on a port reserved for that project.
94
+ It also watches registered projects with `generation.enabled: true` in
95
+ `config/buddy.json`, debounces native source events, and starts one project-local
96
+ `generate:project` worker at a time for barrels, migrations, and declarations.
97
+ The policy supports individual `imports`, `migrations`, and `types` switches
98
+ and `generation.autoCommit` defaults to false. The daemon loads no project
99
+ code and exits when it has no dashboards or active generation watches. Reach it through
97
100
  `openProjectDashboard()` / `daemonStatus()` in `@stacksjs/actions/daemon/client`,
98
101
  which start it when it is not running.
99
102
 
@@ -334,6 +337,10 @@ buddy make:job [name] # create background job
334
337
  -c/--class # class-based job
335
338
  -t/--tries [n] # retry attempts (default: 3)
336
339
  -b/--backoff [n] # backoff delay in seconds (default: 3)
340
+ buddy make:auth # copy the sign-in pages, components and actions into the app
341
+ --api # actions only, no pages or components
342
+ -f/--force # overwrite the copies the app already has
343
+ --dry-run # list the files, copy nothing
337
344
  buddy make:lang [name] # create i18n language file
338
345
  buddy make:migration [name] # create database migration
339
346
  buddy make:model [name] # create data model
@@ -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) | 215 |
24
+ | `@stacksjs/buddy` | [`stacks-buddy`](../stacks-buddy/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/src/index.ts) | 217 |
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 |
@@ -42,7 +42,7 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
42
42
  | `@stacksjs/desktop-build` | [`stacks-desktop`](../stacks-desktop/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/index.ts) | 23 |
43
43
  | `@stacksjs/development` | [`stacks-development`](../stacks-development/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/development/package.json) | 1 |
44
44
  | `@stacksjs/dns` | [`stacks-dns`](../stacks-dns/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/dns/src/index.ts) | 4 |
45
- | `@stacksjs/docs` | [`stacks-docs`](../stacks-docs/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/docs/src/index.ts) | 5 |
45
+ | `@stacksjs/docs` | [`stacks-docs`](../stacks-docs/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/docs/src/index.ts) | 7 |
46
46
  | `@stacksjs/email` | [`stacks-email`](../stacks-email/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/email/src/index.ts) | 27 |
47
47
  | `@stacksjs/enums` | [`stacks-enums`](../stacks-enums/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/enums/src/index.ts) | 3 |
48
48
  | `@stacksjs/env` | [`stacks-env`](../stacks-env/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/env/src/index.ts) | 33 |
@@ -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) | 113 |
79
+ | `@stacksjs/router` | [`stacks-router`](../stacks-router/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/index.ts) | 114 |
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 |
@@ -91,7 +91,7 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
91
91
  | `@stacksjs/strings` | [`stacks-strings`](../stacks-strings/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/strings/src/index.ts) | 12 |
92
92
  | `@stacksjs/support` | [`stacks-support`](../stacks-support/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/support/src/index.ts) | 6 |
93
93
  | `@stacksjs/telephony` | [`stacks-telephony`](../stacks-telephony/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/telephony/src/index.ts) | 5 |
94
- | `@stacksjs/testing` | [`stacks-testing`](../stacks-testing/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/testing/src/index.ts) | 25 |
94
+ | `@stacksjs/testing` | [`stacks-testing`](../stacks-testing/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/testing/src/index.ts) | 26 |
95
95
  | `@stacksjs/tinker` | [`stacks-repl`](../stacks-repl/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/tinker/src/index.ts) | 4 |
96
96
  | `@stacksjs/tunnel` | [`stacks-tunnel`](../stacks-tunnel/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/tunnel/src/index.ts) | 1 |
97
97
  | `@stacksjs/types` | [`stacks-types`](../stacks-types/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/types/src/index.ts) | 3 |
@@ -99,6 +99,7 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
99
99
  | `@stacksjs/utils` | [`stacks-utils`](../stacks-utils/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/utils/src/index.ts) | 28 |
100
100
  | `@stacksjs/validation` | [`stacks-validation`](../stacks-validation/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/validation/src/index.ts) | 26 |
101
101
  | `@stacksjs/video` | [`stacks-video`](../stacks-video/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/video/src/index.ts) | 3 |
102
+ | `@stacksjs/waf` | [`stacks-security`](../stacks-security/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/waf/src/index.ts) | 2 |
102
103
  | `@stacksjs/whois` | [`stacks-whois`](../stacks-whois/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/whois/src/index.ts) | 5 |
103
104
 
104
105
  ## Source surfaces
@@ -222,7 +223,7 @@ Read the entrypoint and package export map for re-exported or type-only surfaces
222
223
 
223
224
  Local source modules: [src/commands/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/src/commands/index.ts).
224
225
 
225
- Evidence directory: [215 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
+ Evidence directory: [217 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
227
 
227
228
  ### @stacksjs/build
228
229
 
@@ -424,7 +425,7 @@ Declared runtime exports: `docsConfig`, `frameworkDefaults`.
424
425
 
425
426
  Local source modules: [src/meta.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/docs/src/meta.ts).
426
427
 
427
- Evidence directory: [5 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/docs/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
428
+ Evidence directory: [7 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/docs/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
428
429
 
429
430
  ### @stacksjs/email
430
431
 
@@ -744,11 +745,11 @@ Evidence directory: [2 retained tests](https://github.com/stacksjs/stacks/blob/m
744
745
 
745
746
  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
747
 
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
+ 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`, `peerSocket`, `provideActions`, `provideMiddleware`, `rateLimit`, `rateLimitScale`, `rateLimitStatus`, `readJsonBody`, `readTextBody`, `refuse`, `registerPeerSource`, `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
749
 
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
+ 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/peer-socket.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/router/src/peer-socket.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
751
 
751
- Evidence directory: [113 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
+ Evidence directory: [114 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
753
 
753
754
  ### @stacksjs/scheduler
754
755
 
@@ -896,7 +897,7 @@ Read the entrypoint and package export map for re-exported or type-only surfaces
896
897
 
897
898
  Local source modules: [src/console.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/testing/src/console.ts), [src/disposable-database.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/testing/src/disposable-database.ts), [src/events.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/testing/src/events.ts), [src/feature.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/testing/src/feature.ts), [src/isolated.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/testing/src/isolated.ts), [src/mail.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/testing/src/mail.ts), [src/schema.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/testing/src/schema.ts), [src/service.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/testing/src/service.ts), [src/time.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/testing/src/time.ts).
898
899
 
899
- Evidence directory: [25 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/testing/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
900
+ Evidence directory: [26 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/testing/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
900
901
 
901
902
  ### @stacksjs/tinker
902
903
 
@@ -968,6 +969,16 @@ Local source modules: [src/files.ts](https://github.com/stacksjs/stacks/blob/mai
968
969
 
969
970
  Evidence directory: [3 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/video/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
970
971
 
972
+ ### @stacksjs/waf
973
+
974
+ Guidance: [`stacks-security`](../stacks-security/SKILL.md). Source: [storage/framework/core/waf/src/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/waf/src/index.ts).
975
+
976
+ Declared runtime exports: `Waf`, `findWafLibrary`, `libraryFileName`, `renderWafRules`.
977
+
978
+ Local source modules: [src/ffi.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/waf/src/ffi.ts), [src/library.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/waf/src/library.ts), [src/rules.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/waf/src/rules.ts).
979
+
980
+ Evidence directory: [2 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/waf/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
981
+
971
982
  ### @stacksjs/whois
972
983
 
973
984
  Guidance: [`stacks-whois`](../stacks-whois/SKILL.md). Source: [storage/framework/core/whois/src/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/whois/src/index.ts).
@@ -197,6 +197,21 @@ import { eraseSubject, exportSubjectData, pruneRetainedData } from '@stacksjs/or
197
197
  `compute.waf` in `config/cloud.ts` still wins field by field and the deploy warns about it.
198
198
  Nothing ever switches to `blocking` by itself: read the detection log first. On AWS deploys the
199
199
  zig-waf-only options are reported, not applied.
200
+ - An app not behind rpx (`buddy dev`, serverless, a host of your own) can run the same engine in
201
+ process: add the `waf` middleware to a route or group (`.middleware('waf')`). It is
202
+ `@stacksjs/waf`, zig-waf's C ABI through `bun:ffi`, and reads the same `security.waf` plus two
203
+ settings of its own: `rules`, the SecLang files to load in order (usually an OWASP CRS checkout:
204
+ `crs-setup.conf` then `rules/*.conf`; zig-waf ships none, so it refuses to start without them),
205
+ and `library`, the path to zig-waf's shared library (or `ZIG_WAF_LIBRARY`; it is in `lib/` of a
206
+ zig-waf release or `zig-out/lib/` after `zig build`). Detection mode logs a match and lets the
207
+ request through; blocking refuses it with the rule's status. `dataDir` (default: the last rule
208
+ file's directory, a CRS checkout's `rules/`) is where `.data` files resolve, and `allowedMethods`
209
+ defaults to CRS's GET HEAD POST OPTIONS plus PUT, PATCH and DELETE, which CRS alone would refuse.
210
+ At most `maxBodyBytes` of a body is read; blocking refuses a larger one with 413. In blocking mode a WAF that cannot
211
+ start answers 503 instead of letting everything through; in detection mode it logs and passes. A
212
+ request built in-process has no socket and is not inspected. With zig-utils/zig-waf#84 a two-rule set
213
+ costs about 15 us per request and full CRS about 10 ms for a GET and more for a form post, most of
214
+ it zig-waf recompiling operators per request (zig-utils/zig-waf#83); see `core/waf/README.md`.
200
215
  - The firewall rate limit is per-minute per-IP at the WAF (`firewall.rateLimitPerMinute`)
201
216
  - Application rate limits (`.rateLimit()`, `rateLimit()`, the login lockout) share the Redis cache when it is configured and count per process otherwise; see `stacks-router`
202
217
 
@@ -1400,7 +1400,8 @@ class PipeCdp {
1400
1400
  this.readPipe = { readable: true, readableEnded: false, destroyed: false };
1401
1401
  this.writePipe = { writable: true, writableEnded: false, destroyed: false, writableLength: 0 };
1402
1402
  this.socketPromise = Promise.resolve(socketUrl).then(url => new Promise((resolve, reject) => {
1403
- const socket = new WebSocket(url);
1403
+ // Uncompressed: loopback gains nothing from permessage-deflate.
1404
+ const socket = new WebSocket(url, { perMessageDeflate: false });
1404
1405
  socket.addEventListener('open', () => resolve(socket), { once: true });
1405
1406
  socket.addEventListener('message', event => this.consume(String(event.data) + '\0'));
1406
1407
  socket.addEventListener('error', () => { const error = new Error('Chrome WebSocket failed'); reject(error); this.failAll(error); });
@@ -350,6 +350,7 @@ bun run test:coverage # with coverage
350
350
  bun run test:types # type tests
351
351
  buddy test:page-audit --url /,/dashboard --base http://localhost:3000 # duplicate API requests, failures, console errors
352
352
  buddy test:page-audit --url http://localhost:3000/pricing --mobile --json
353
+ buddy test:page-audit --lighthouse --sitemap public/sitemap.xml --base http://localhost:3000 --min-score 100
353
354
  ```
354
355
 
355
356
  Name a path to run only what is under it, file or directory, anywhere in the
@@ -365,7 +366,20 @@ root matches nothing and reports a clean run over no files, while
365
366
  you, so prefer it.
366
367
 
367
368
  `test:page-audit` exits 1 when any page has duplicates, failed same-origin requests or errors, or
368
- never settles.
369
+ never settles. With `--lighthouse`, it also runs the standard mobile and desktop Lighthouse
370
+ profiles and requires every category to meet `--min-score` (100 by default).
371
+ `--device mobile|desktop|both` selects profiles; `--output` selects the directory
372
+ for HTML, JSON and an incremental `summary.json`. A failed collection is recorded
373
+ as failed, never as a passing score. When performance falls below the budget,
374
+ the terminal reports the metric that cost the most points. Sitemap canonical hosts are mapped onto
375
+ `--base` so a production sitemap can audit a local build. Set `CHROME_PATH` if
376
+ Chrome is not installed at a standard path. Reports retain real audits and use
377
+ Lighthouse default throttling.
378
+
379
+ For Basic-auth protected previews, pass `--basic-auth` and inject
380
+ `STACKS_AUDIT_USERNAME` and `STACKS_AUDIT_PASSWORD` through the environment.
381
+ Set `--base` to the protected HTTPS or loopback origin. The browser answers
382
+ challenges for that origin and Lighthouse uses the isolated browser session.
369
383
 
370
384
  ## Configuration (bunfig.toml)
371
385
 
@@ -0,0 +1,187 @@
1
+ import type { WafSecurityOptions } from '@stacksjs/types'
2
+ import type { WafDecision } from '@stacksjs/waf'
3
+ import { isAbsolute } from 'node:path'
4
+ import { config } from '@stacksjs/config'
5
+ import { HttpError } from '@stacksjs/error-handling'
6
+ import { log } from '@stacksjs/logging'
7
+ import { path } from '@stacksjs/path'
8
+ import { clientAddress, Middleware, peerSocket } from '@stacksjs/router'
9
+ import { Waf } from '@stacksjs/waf'
10
+
11
+ /**
12
+ * Waf Middleware
13
+ *
14
+ * Runs each request through zig-waf in process (`@stacksjs/waf`), for an app
15
+ * that is not behind rpx: `buddy dev`, serverless, a host of your own. On a box
16
+ * deploy rpx's dataplane runs the same engine in front of the app, so this is
17
+ * not needed there.
18
+ *
19
+ * It reads `config.security.waf`:
20
+ *
21
+ * - `mode`: `detection` (the default) logs a match and lets the request
22
+ * through; `blocking` refuses it with the status the rule asked for. `off`
23
+ * turns the middleware into a no-op.
24
+ * - `rules`: the SecLang files to load, usually an OWASP CRS checkout. Required:
25
+ * zig-waf ships no rules.
26
+ * - `library`: zig-waf's shared library, or set `ZIG_WAF_LIBRARY`.
27
+ * - `dataDir`: where the rules' `.data` files are; defaults to the last rule
28
+ * file's directory, a CRS checkout's `rules/`.
29
+ * - `allowedMethods`: defaults to CRS's GET HEAD POST OPTIONS plus the PUT,
30
+ * PATCH and DELETE a Stacks API's update and destroy routes use.
31
+ * - `maxBodyBytes`: at most this much of a body is read. Blocking refuses a
32
+ * larger one with 413; detection inspects its start and logs that it could
33
+ * not see the rest.
34
+ * - `paranoiaLevel`, thresholds, `bypassPaths`, `exclusions`: as on box deploys.
35
+ *
36
+ * Off unless a route asks for it:
37
+ * route.post('/login', 'Actions/Auth/LoginAction').middleware('waf')
38
+ * route.group({ middleware: ['waf'] }, () => { ... })
39
+ *
40
+ * A request built in-process (a test, an internal `handleRequest`) has no
41
+ * socket, so there is no network traffic to inspect and it passes.
42
+ */
43
+ export default new Middleware({
44
+ name: 'waf',
45
+ priority: 1,
46
+
47
+ async handle(request) {
48
+ await inspectWithWaf(request as unknown as Request, (config as { security?: { waf?: WafSecurityOptions } }).security?.waf ?? {})
49
+ },
50
+ })
51
+
52
+ const engines = new Map<string, Waf>()
53
+
54
+ /** A configured path, relative to the project root unless it is absolute. */
55
+ function fromProject(file: string): string {
56
+ return isAbsolute(file) ? file : path.projectPath(file)
57
+ }
58
+
59
+ /** The engine for these settings, compiled once and kept for the process. */
60
+ function engineFor(settings: WafSecurityOptions): Waf {
61
+ const key = JSON.stringify(settings)
62
+ let waf = engines.get(key)
63
+ if (!waf) {
64
+ waf = new Waf({
65
+ ...settings,
66
+ mode: settings.mode === 'blocking' ? 'blocking' : 'detection',
67
+ rules: (settings.rules ?? []).map(fromProject),
68
+ dataDir: settings.dataDir === undefined ? undefined : fromProject(settings.dataDir),
69
+ })
70
+ for (const warning of waf.warnings)
71
+ log.warn(`[waf] ${warning}`)
72
+ engines.set(key, waf)
73
+ }
74
+ return waf
75
+ }
76
+
77
+ /**
78
+ * Inspect one request under `settings`; refuse it with an `HttpError` when the
79
+ * engine enforces a decision. Returns what the engine decided, or `null` when
80
+ * the request was not inspected.
81
+ */
82
+ export async function inspectWithWaf(request: Request, settings: WafSecurityOptions): Promise<WafDecision | null> {
83
+ if (settings.mode === 'off')
84
+ return null
85
+
86
+ const socket = peerSocket(request)
87
+ if (!socket)
88
+ return null
89
+
90
+ let waf: Waf
91
+ try {
92
+ waf = engineFor(settings)
93
+ }
94
+ catch (error) {
95
+ // A WAF asked to block that cannot start must not quietly let everything
96
+ // through; one asked only to watch should not take the app down.
97
+ log.error(`[waf] ${(error as Error).message}`)
98
+ if (settings.mode === 'blocking')
99
+ throw new HttpError(503, 'Service Unavailable')
100
+ return null
101
+ }
102
+
103
+ const url = new URL(request.url)
104
+ const body = await bodyPrefix(request, waf.maxBodyBytes)
105
+ if (body.oversized) {
106
+ // Past maxBodyBytes the engine sees only the start, so padding a request
107
+ // would carry anything past every rule. Blocking refuses it; detection
108
+ // inspects what fits and says what it could not see.
109
+ if (settings.mode === 'blocking')
110
+ throw new HttpError(413, 'Payload Too Large')
111
+ log.warn(`[waf] ${request.method} ${url.pathname}: the body is larger than maxBodyBytes (${waf.maxBodyBytes}); only its start was inspected`)
112
+ }
113
+
114
+ const decision = waf.inspect({
115
+ method: request.method,
116
+ uri: `${url.pathname}${url.search}`,
117
+ headers: request.headers.entries(),
118
+ body: body.bytes,
119
+ clientAddress: clientAddress(request) ?? socket.address,
120
+ clientPort: socket.port,
121
+ serverAddress: url.hostname,
122
+ serverPort: Number(url.port) || (url.protocol === 'https:' ? 443 : 80),
123
+ })
124
+
125
+ if (decision.matched) {
126
+ log.warn(`[waf] rule ${decision.ruleId ?? 'unknown'} matched ${request.method} ${url.pathname} from ${clientAddress(request) ?? socket.address}: ${decision.enforced ? 'refused' : 'allowed (detection mode)'}`)
127
+ if (decision.enforced)
128
+ throw new HttpError(decision.status ?? 403, 'Forbidden')
129
+ }
130
+ return decision
131
+ }
132
+
133
+ /**
134
+ * At most `limit` bytes of the body, without taking it from the action.
135
+ *
136
+ * The router buffers a JSON body (`_rawBody`) and replays it; a form or
137
+ * multipart body it reads from a clone and leaves the original for the action.
138
+ * So this reads the buffered copy when there is one and a clone otherwise,
139
+ * stopping one byte past the limit: enough to know the body is larger, never
140
+ * the whole of an arbitrarily large upload in memory.
141
+ */
142
+ async function bodyPrefix(request: Request, limit: number): Promise<{ bytes?: Uint8Array, oversized: boolean }> {
143
+ if (request.method === 'GET' || request.method === 'HEAD')
144
+ return { oversized: false }
145
+
146
+ const declared = Number(request.headers.get('content-length'))
147
+ if (Number.isFinite(declared) && declared > limit)
148
+ return { oversized: true }
149
+
150
+ const buffered = (request as { _rawBody?: unknown })._rawBody
151
+ if (typeof buffered === 'string') {
152
+ const all = new TextEncoder().encode(buffered)
153
+ return { bytes: all.subarray(0, limit), oversized: all.length > limit }
154
+ }
155
+
156
+ if (!request.body || request.bodyUsed)
157
+ return { oversized: false }
158
+
159
+ const reader = request.clone().body!.getReader()
160
+ const chunks: Uint8Array[] = []
161
+ let size = 0
162
+ while (size <= limit) {
163
+ const { done, value } = await reader.read()
164
+ if (done)
165
+ break
166
+ chunks.push(value)
167
+ size += value.length
168
+ }
169
+ const oversized = size > limit
170
+ // Cancelled so this branch stops buffering what the action goes on to read,
171
+ // and not awaited: a tee branch's cancel settles only once both branches
172
+ // are cancelled (the Streams standard), and the action's branch is still
173
+ // being read.
174
+ if (oversized)
175
+ void reader.cancel().catch(() => {})
176
+
177
+ const bytes = new Uint8Array(Math.min(size, limit))
178
+ let offset = 0
179
+ for (const chunk of chunks) {
180
+ if (offset >= bytes.length)
181
+ break
182
+ const part = chunk.subarray(0, bytes.length - offset)
183
+ bytes.set(part, offset)
184
+ offset += part.length
185
+ }
186
+ return { bytes, oversized }
187
+ }
package/app/Middleware.ts CHANGED
@@ -49,5 +49,6 @@ export default defineMiddleware({
49
49
  'verified': 'EnsureEmailIsVerified',
50
50
  'csrf': 'Csrf',
51
51
  'compress': 'Compress',
52
+ 'waf': 'Waf',
52
53
  // Add more middleware aliases here
53
54
  })
@@ -2,7 +2,7 @@
2
2
  "publisher": "Stacks",
3
3
  "name": "vscode-stacks",
4
4
  "displayName": "Stacks",
5
- "version": "0.75.634",
5
+ "version": "0.75.636",
6
6
  "description": "Stacks, built into VS Code: stx templates, pickier linting and formatting, encrypted env files, the dev server preview and every buddy command. No other extensions required.",
7
7
  "license": "MIT",
8
8
  "funding": "https://github.com/sponsors/chrisbbreuer",
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/defaults",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.634",
5
+ "version": "0.75.636",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/stacksjs/stacks.git",
@@ -45,14 +45,14 @@
45
45
  "dependencies": {
46
46
  "@iconify-json/f7": "^1.2.2",
47
47
  "@iconify-json/hugeicons": "^1.2.35",
48
- "@stacksjs/mobile": "0.75.634",
48
+ "@stacksjs/mobile": "0.75.636",
49
49
  "@stacksjs/sanitizer": "^0.2.908",
50
50
  "@stacksjs/stx": "^0.2.908",
51
- "@stacksjs/strings": "0.75.634",
51
+ "@stacksjs/strings": "0.75.636",
52
52
  "@xterm/addon-fit": "^0.11.0",
53
53
  "@xterm/xterm": "^6.0.0",
54
54
  "ts-qr-codes": "^0.1.8",
55
- "@stacksjs/support": "0.75.634",
56
- "@stacksjs/browser": "0.75.634"
55
+ "@stacksjs/support": "0.75.636",
56
+ "@stacksjs/browser": "0.75.636"
57
57
  }
58
58
  }
@@ -10,6 +10,12 @@
10
10
  <script server>
11
11
  import { config } from '@stacksjs/config'
12
12
 
13
+ interface InheritedContext {
14
+ pageTitle?: string
15
+ pageDescription?: string
16
+ canonicalPath?: string
17
+ }
18
+
13
19
  const appName = config.app.name || 'My App'
14
20
 
15
21
  // APP_URL is often a bare host (`my-app.localhost`), which is not a valid