@stacksjs/defaults 0.75.683 → 0.75.687

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.
@@ -27,6 +27,16 @@ The readiness promise and override storage are shared across installed copies.
27
27
  Compiled server builds have a separate minimal env config and may deliberately
28
28
  set `SKIP_CONFIG_LOADING=true`; see `stacks-server`.
29
29
 
30
+ A compiled app has no `config/` beside it, and the loader's `import()` of a
31
+ computed path is one the bundler cannot follow. Its entry hands the loader
32
+ static loaders instead, before anything imports config:
33
+ `registerBundledConfig({ app: () => import('/abs/config/app.ts') })` from the
34
+ dependency-free `@stacksjs/config/sources` (it throws once config has loaded).
35
+ `USER_CONFIG_FILES` / `userConfigFileNames()` list the files the loader reads.
36
+ `settledConfigSource()` says what was loaded: `bundled`, `files` under a root,
37
+ or `skipped`, the files that loaded and those that threw.
38
+ `describeConfigSource()` turns that into one log line.
39
+
30
40
  Individual exports (app, auth, database, queue, filesystems and others) are also
31
41
  available. Use the matching `satisfies ...Config` type or define helper.
32
42
  `defineModel` belongs to `@stacksjs/orm`. App registries are owned by their
@@ -565,10 +565,23 @@ applied with `migrateCompiledDatabase` and `DB_CONNECTION`/`DB_DATABASE_PATH` po
565
565
  newer version changed, or a migration that fails (the backup is put back), stops the launch with the reason in the
566
566
  app's log.
567
567
 
568
+ A launch that fails once the instance lock is held (the database, config, the agent module or its `start`) says why in
569
+ a small window of its own as well as the log, since nobody reads the log of an app opened from Finder or a desktop
570
+ entry. The agent is stopped first. The page is static and escaped, served from loopback only while the window is open,
571
+ and names the log file when the log goes to one. The window keeps its titlebar whatever `window.titlebarHidden` says.
572
+ Closing it quits with exit code 1 and releases the lock (`showFailureWindow`, `renderFailurePage`).
573
+
568
574
  `buddy build:desktop` also bundles the project's own scripts that pages load as `src="/assets/....ts"` (every `.stx`
569
575
  under `resources/` is read for them): each is built for the browser with what it imports (`appClientScripts`) and
570
576
  embedded at the URL the page asks for, served as JavaScript. A page naming a script that is not in `resources/assets`
571
- fails the build. Config is not bundled yet (stacksjs/stacks#3368).
577
+ fails the build.
578
+
579
+ `agent.config: true` compiles the project's `config/*.ts` into the app: every file the config loader reads that the
580
+ project has (`appConfigFiles`), each named in a static `import()`. At launch, after the database and before the agent
581
+ module, they are registered with `registerBundledConfig` and loaded, so a built app runs on its own config rather
582
+ than the framework defaults. A file that throws stops the launch with the reason in the log. Either way the app logs
583
+ which config it booted with (`[App] config: app.ts, database.ts compiled into the app; framework defaults for the
584
+ rest`, or `no config/*.ts under <root>` when a built app has none). Off by default.
572
585
 
573
586
  **Views.** `buddy dev:desktop` serves `agent.views` live through stx (`bun-plugin-stx/serve`, with the gate and the
574
587
  agent module in its `onRequest`). `buddy build:desktop` builds them to static pages with stx's `buildStaticSite`
@@ -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) | 11 |
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) | 224 |
24
+ | `@stacksjs/buddy` | [`stacks-buddy`](../stacks-buddy/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/src/index.ts) | 225 |
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,13 +33,13 @@ 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) | 16 |
35
35
  | `@stacksjs/composables` | [`stacks-composables`](../stacks-composables/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/composables/src/index.ts) | 18 |
36
- | `@stacksjs/config` | [`stacks-config`](../stacks-config/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/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) | 19 |
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) | 152 |
39
39
  | `@stacksjs/datetime` | [`stacks-datetime`](../stacks-datetime/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/datetime/src/index.ts) | 22 |
40
40
  | `@stacksjs/defaults` | [`stacks-build`](../stacks-build/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/defaults/package.json) | 3 |
41
41
  | `@stacksjs/deploy` | [`stacks-deploy`](../stacks-deploy/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/deploy/package.json) | 1 |
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) | 24 |
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) | 25 |
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
45
  | `@stacksjs/docs` | [`stacks-docs`](../stacks-docs/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/docs/src/index.ts) | 8 |
@@ -98,7 +98,7 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
98
98
  | `@stacksjs/ui` | [`stacks-ui`](../stacks-ui/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/ui/src/index.ts) | 6 |
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
- | `@stacksjs/video` | [`stacks-video`](../stacks-video/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/video/src/index.ts) | 5 |
101
+ | `@stacksjs/video` | [`stacks-video`](../stacks-video/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/video/src/index.ts) | 6 |
102
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 |
103
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 |
104
104
 
@@ -223,7 +223,7 @@ Read the entrypoint and package export map for re-exported or type-only surfaces
223
223
 
224
224
  Local source modules: [src/commands/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/src/commands/index.ts).
225
225
 
226
- Evidence directory: [224 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: [225 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.
227
227
 
228
228
  ### @stacksjs/build
229
229
 
@@ -337,11 +337,11 @@ Evidence directory: [18 retained tests](https://github.com/stacksjs/stacks/blob/
337
337
 
338
338
  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).
339
339
 
340
- 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
+ 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`, `configSource`, `createRequestContext`, `describeConfigSource`, `disableFeature`, `enableFeature`, `enterRequestScope`, `expiredFormFlashCookie`, `feature`, `flashableField`, `flashableInput`, `formFlashCookie`, `installRequestContext`, `installRequestScope`, `listFeatures`, `openFormFlash`, `packageComponentRoots`, `packageJobRoots`, `packageMigrationRoots`, `packageModelRoots`, `packageViewRoots`, `parseCookieHeader`, `registerBundledConfig`, `reportConfigIssues`, `resetFeature`, `resolveViewPatterns`, `scopeStxServeContext`, `scopedRequestSnapshot`, `sealFormFlash`, `settledConfigSource`, `useRequestEvent`, `userConfigFileNames`, `validateConfig`, `withheldDefaultViews`.
341
341
 
342
- 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
+ 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/sources.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/sources.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).
343
343
 
344
- Evidence directory: [18 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
+ Evidence directory: [19 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.
345
345
 
346
346
  ### @stacksjs/cron
347
347
 
@@ -397,7 +397,7 @@ Declared runtime exports: `BUN_EXECUTABLE_MARKER`, `RESERVED_PLIST_KEYS`, `USERL
397
397
 
398
398
  Local source modules: [src/agent-launcher.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/agent-launcher.ts), [src/agent.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/agent.ts), [src/craft-runtime.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/craft-runtime.ts), [src/invites.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/invites.ts), [src/macos-app.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/macos-app.ts), [src/macos-bundle.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/macos-bundle.ts), [src/macos-release.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/macos-release.ts), [src/support.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/support.ts), [src/update-feed.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/update-feed.ts), [src/update-install.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/update-install.ts), [src/update-signing.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/update-signing.ts), [src/updater.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/updater.ts), [src/webview-agent.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/webview-agent.ts), [src/webview-app.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/webview-app.ts), [src/webview-build-record.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/webview-build-record.ts), [src/webview-launcher.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/webview-launcher.ts).
399
399
 
400
- Evidence directory: [24 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
400
+ Evidence directory: [25 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
401
401
 
402
402
  ### @stacksjs/development
403
403
 
@@ -969,7 +969,7 @@ Declared runtime exports: `VideoBuilder`, `assertVideoPlanExecutable`, `createHl
969
969
 
970
970
  Local source modules: [src/files.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/video/src/files.ts), [src/inspect.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/video/src/inspect.ts), [src/upload.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/video/src/upload.ts).
971
971
 
972
- Evidence directory: [5 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.
972
+ Evidence directory: [6 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.
973
973
 
974
974
  ### @stacksjs/waf
975
975
 
@@ -2,7 +2,7 @@
2
2
  "publisher": "Stacks",
3
3
  "name": "vscode-stacks",
4
4
  "displayName": "Stacks",
5
- "version": "0.75.683",
5
+ "version": "0.75.687",
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.683",
5
+ "version": "0.75.687",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/stacksjs/stacks.git",
@@ -45,15 +45,15 @@
45
45
  "dependencies": {
46
46
  "@iconify-json/f7": "^1.2.2",
47
47
  "@iconify-json/hugeicons": "^1.2.35",
48
- "@stacksjs/desktop": "^0.2.934",
49
- "@stacksjs/mobile": "0.75.683",
50
- "@stacksjs/sanitizer": "^0.2.934",
51
- "@stacksjs/stx": "^0.2.934",
52
- "@stacksjs/strings": "0.75.683",
48
+ "@stacksjs/desktop": "^0.2.938",
49
+ "@stacksjs/mobile": "0.75.687",
50
+ "@stacksjs/sanitizer": "^0.2.938",
51
+ "@stacksjs/stx": "^0.2.938",
52
+ "@stacksjs/strings": "0.75.687",
53
53
  "@xterm/addon-fit": "^0.11.0",
54
54
  "@xterm/xterm": "^6.0.0",
55
55
  "ts-qr-codes": "^0.1.8",
56
- "@stacksjs/support": "0.75.683",
57
- "@stacksjs/browser": "0.75.683"
56
+ "@stacksjs/support": "0.75.687",
57
+ "@stacksjs/browser": "0.75.687"
58
58
  }
59
59
  }
@@ -63,20 +63,8 @@ function guarded(prefix: string, base?: Parameters<typeof dashboardGroupMiddlewa
63
63
  // Email
64
64
  // ============================================================================
65
65
 
66
- // CSRF is skipped for the same reason the storefront cart routes skip
67
- // it: the storefront's email-subscribe form is rendered in static HTML
68
- // without a CSRF token round-trip, and the abuse case (bots inflating
69
- // the subscriber list) is better handled with the rate limiter — at
70
- // the action layer — than with a token check the form can't satisfy.
71
- route.post('/api/email/subscribe', 'Actions/SubscriberEmailAction').name('email.subscribe').skipCsrf()
72
- // The button in the double opt-in email (lists with `double_opt_in` on).
73
- route.get('/api/email/confirm', 'Actions/ConfirmSubscriptionAction').name('email.confirm')
74
- route.get('/api/email/unsubscribe', 'Actions/UnsubscribeAction').name('email.unsubscribe')
75
- // RFC 8058 one-click endpoint. Mailbox providers (Gmail, Yahoo, Outlook)
76
- // POST here with body `List-Unsubscribe=One-Click` when the user clicks
77
- // the inbox-native unsubscribe affordance — the request never carries a
78
- // CSRF token because the mailbox provider isn't in our session, so skip.
79
- route.post('/api/email/unsubscribe', 'Actions/UnsubscribeAction').name('email.unsubscribe.oneclick').skipCsrf()
66
+ // The newsletter signup, its double opt-in confirmation and its unsubscribe
67
+ // links are in routes/email.ts: they ship in every app, dashboard or not.
80
68
 
81
69
  // Public contact form. CSRF skipped for the same reason as the
82
70
  // subscribe endpoint — the form renders without JS — and the outbound
package/routes/email.ts CHANGED
@@ -7,6 +7,9 @@
7
7
  * - POST /webhooks/email/postmark — bounce/complaint events
8
8
  * - POST /webhooks/email/ses — SES via SNS
9
9
  * - POST /webhooks/email/sendgrid — event webhook
10
+ * - POST /api/email/subscribe — the public newsletter signup
11
+ * - GET /api/email/confirm — the double opt-in link
12
+ * - GET/POST /api/email/unsubscribe — a list membership's opt-out
10
13
  *
11
14
  * All routes are CSRF-exempt (they're called by external providers
12
15
  * or anonymous users clicking unsubscribe links). User routes
@@ -136,3 +139,28 @@ route.post('/webhooks/email/sendgrid', async (req) => {
136
139
  const result = await handleSendgridWebhook(rawBody, sig, ts, { publicKeyPem })
137
140
  return Response.json(result.body, { status: result.status })
138
141
  }).skipCsrf()
142
+
143
+ // ============================================================================
144
+ // Newsletter signup
145
+ // ============================================================================
146
+ //
147
+ // These lived in routes/dashboard.ts, so an app without the dashboard mounted
148
+ // the signup action (directly, or under its own path) but not the link in the
149
+ // double opt-in email or the unsubscribe link in the welcome email: the
150
+ // confirmation failed to send ("Route 'email.confirm' is not defined") and
151
+ // nobody could leave the list. They belong with the rest of the email routes.
152
+
153
+ // CSRF is skipped for the same reason the storefront cart routes skip
154
+ // it: the storefront's email-subscribe form is rendered in static HTML
155
+ // without a CSRF token round-trip, and the abuse case (bots inflating
156
+ // the subscriber list) is better handled with the rate limiter — at
157
+ // the action layer — than with a token check the form can't satisfy.
158
+ route.post('/api/email/subscribe', 'Actions/SubscriberEmailAction').name('email.subscribe').skipCsrf()
159
+ // The button in the double opt-in email (lists with `double_opt_in` on).
160
+ route.get('/api/email/confirm', 'Actions/ConfirmSubscriptionAction').name('email.confirm')
161
+ route.get('/api/email/unsubscribe', 'Actions/UnsubscribeAction').name('email.unsubscribe')
162
+ // RFC 8058 one-click endpoint. Mailbox providers (Gmail, Yahoo, Outlook)
163
+ // POST here with body `List-Unsubscribe=One-Click` when the user clicks
164
+ // the inbox-native unsubscribe affordance — the request never carries a
165
+ // CSRF token because the mailbox provider isn't in our session, so skip.
166
+ route.post('/api/email/unsubscribe', 'Actions/UnsubscribeAction').name('email.unsubscribe.oneclick').skipCsrf()