@stacksjs/defaults 0.75.663 → 0.75.668
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ai/skills/stacks-actions/SKILL.md +1 -1
- package/ai/skills/stacks-dashboard/SKILL.md +2 -2
- package/ai/skills/stacks-native/CATALOG.md +9 -9
- package/ai/skills/stacks-newsletter/SKILL.md +51 -0
- package/ai/skills/stacks-payments/SKILL.md +13 -0
- package/ai/skills/stacks-socials/SKILL.md +20 -2
- package/app/Actions/ConfirmSubscriptionAction.ts +53 -0
- package/app/Actions/SubscriberEmailAction.ts +77 -39
- package/app/Actions/UnsubscribeAction.ts +5 -50
- package/app/Actions/form-return.ts +0 -20
- package/app/Actions/subscription-page.ts +50 -0
- package/app/Mail/SubscriptionConfirmRequest.ts +56 -0
- package/app/Mail/SubscriptionConfirmation.ts +13 -3
- package/ide/vscode/package.json +1 -1
- package/package.json +7 -7
- package/resources/assets/scripts/main.ts +5 -6
- package/resources/components/Marketing/ComingSoon.stx +3 -101
- package/resources/components/Marketing/SubscribeForm.stx +315 -0
- package/resources/emails/subscription-confirm.stx +31 -0
- package/routes/dashboard.ts +2 -0
- package/scaffold/config/server.ts +141 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: stacks-actions
|
|
3
|
-
description: Use when working with Stacks server actions - creating actions in app/Actions/, auto-generated API actions from the useApi model trait, the
|
|
3
|
+
description: Use when working with Stacks server actions - creating actions in app/Actions/, auto-generated API actions from the useApi model trait, the 783 default framework actions (auth, dashboard, commerce, content, deployment, jobs), action request/response handling, or action registration. Covers @stacksjs/actions and storage/framework/defaults/app/Actions/.
|
|
4
4
|
license: MIT
|
|
5
5
|
compatibility: Bun >= 1.3.0, TypeScript
|
|
6
6
|
allowed-tools: Read Edit Write Bash Grep Glob
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: stacks-dashboard
|
|
3
|
-
description: Use when building or customizing the Stacks admin dashboard, including dashboard pages, model management views, analytics widgets, commerce dashboards, content management, settings panels, deployment monitoring, job/queue management, or the
|
|
3
|
+
description: Use when building or customizing the Stacks admin dashboard, including dashboard pages, model management views, analytics widgets, commerce dashboards, content management, settings panels, deployment monitoring, job/queue management, or the 446 built-in dashboard components. Covers the dashboard system at storage/framework/defaults/.
|
|
4
4
|
license: MIT
|
|
5
5
|
compatibility: Bun >= 1.3.0, TypeScript
|
|
6
6
|
allowed-tools: Read Edit Write Bash Grep Glob
|
|
@@ -8,7 +8,7 @@ allowed-tools: Read Edit Write Bash Grep Glob
|
|
|
8
8
|
|
|
9
9
|
# Stacks Dashboard
|
|
10
10
|
|
|
11
|
-
The Stacks admin dashboard provides a full-featured admin panel with 100+ route views,
|
|
11
|
+
The Stacks admin dashboard provides a full-featured admin panel with 100+ route views, 446 components, and a multi-section layout.
|
|
12
12
|
|
|
13
13
|
## Key Paths
|
|
14
14
|
- Dashboard components: `storage/framework/defaults/resources/components/Dashboard/`
|
|
@@ -11,7 +11,7 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
|
|
|
11
11
|
| Package | Task guidance | Source entry | Retained tests |
|
|
12
12
|
|---|---|---|---|
|
|
13
13
|
| `@stacksjs/action-runner` | [`stacks-actions`](../stacks-actions/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/action-runner/src/index.ts) | 1 |
|
|
14
|
-
| `@stacksjs/actions` | [`stacks-actions`](../stacks-actions/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/index.ts) |
|
|
14
|
+
| `@stacksjs/actions` | [`stacks-actions`](../stacks-actions/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/index.ts) | 130 |
|
|
15
15
|
| `@stacksjs/ai` | [`stacks-ai`](../stacks-ai/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/ai/src/index.ts) | 27 |
|
|
16
16
|
| `@stacksjs/alias` | [`stacks-alias`](../stacks-alias/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/alias/src/index.ts) | 3 |
|
|
17
17
|
| `@stacksjs/analytics` | [`stacks-analytics`](../stacks-analytics/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/analytics/src/index.ts) | 7 |
|
|
@@ -63,13 +63,13 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
|
|
|
63
63
|
| `@stacksjs/logging` | [`stacks-logging`](../stacks-logging/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/logging/src/index.ts) | 15 |
|
|
64
64
|
| `@stacksjs/mobile` | [`stacks-mobile`](../stacks-mobile/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/mobile/src/index.ts) | 23 |
|
|
65
65
|
| `@stacksjs/model-meta` | [`stacks-models`](../stacks-models/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/model-meta/src/index.ts) | 1 |
|
|
66
|
-
| `@stacksjs/newsletter` | [`stacks-newsletter`](../stacks-newsletter/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/newsletter/src/index.ts) |
|
|
66
|
+
| `@stacksjs/newsletter` | [`stacks-newsletter`](../stacks-newsletter/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/newsletter/src/index.ts) | 11 |
|
|
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
69
|
| `@stacksjs/orm` | [`stacks-orm`](../stacks-orm/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/orm/src/index.ts) | 81 |
|
|
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) | 14 |
|
|
72
|
-
| `@stacksjs/payments` | [`stacks-payments`](../stacks-payments/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/payments/src/index.ts) |
|
|
72
|
+
| `@stacksjs/payments` | [`stacks-payments`](../stacks-payments/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/payments/src/index.ts) | 42 |
|
|
73
73
|
| `@stacksjs/push` | [`stacks-push`](../stacks-push/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/push/src/index.ts) | 8 |
|
|
74
74
|
| `@stacksjs/query-builder` | [`stacks-query-builder`](../stacks-query-builder/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/query-builder/src/index.ts) | 7 |
|
|
75
75
|
| `@stacksjs/queue` | [`stacks-queue`](../stacks-queue/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/queue/src/index.ts) | 59 |
|
|
@@ -86,7 +86,7 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
|
|
|
86
86
|
| `@stacksjs/skills` | [`stacks-skills`](../stacks-skills/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/skills/src/index.ts) | 1 |
|
|
87
87
|
| `@stacksjs/slug` | [`stacks-slug`](../stacks-slug/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/slug/src/index.ts) | 5 |
|
|
88
88
|
| `@stacksjs/sms` | [`stacks-sms`](../stacks-sms/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/sms/src/index.ts) | 7 |
|
|
89
|
-
| `@stacksjs/socials` | [`stacks-socials`](../stacks-socials/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/index.ts) |
|
|
89
|
+
| `@stacksjs/socials` | [`stacks-socials`](../stacks-socials/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/index.ts) | 21 |
|
|
90
90
|
| `@stacksjs/storage` | [`stacks-storage`](../stacks-storage/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/storage/src/index.ts) | 52 |
|
|
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 |
|
|
@@ -123,7 +123,7 @@ Declared runtime exports: `BlogAdminError`, `DEFAULT_IOS_DEPENDENCIES`, `DEFAULT
|
|
|
123
123
|
|
|
124
124
|
Local source modules: [src/action.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/action.ts), [src/add.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/add.ts), [src/blog-admin.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/blog-admin.ts), [src/build/ios-toolchain.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/build/ios-toolchain.ts), [src/build/macos-native.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/build/macos-native.ts), [src/commit.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/commit.ts), [src/dev/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/dev/index.ts), [src/discover-packages.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/discover-packages.ts), [src/generate/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/generate/index.ts), [src/github-release.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/github-release.ts), [src/helpers/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/helpers/index.ts), [src/library/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/library/index.ts), [src/lint/lint.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/lint/lint.ts), [src/lint/stx-gate.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/lint/stx-gate.ts), [src/make-command.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/make-command.ts), [src/make-job.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/make-job.ts), [src/make-policy.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/make-policy.ts), [src/make-resource.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/make-resource.ts), [src/make.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/make.ts), [src/publication-preflight.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/publication-preflight.ts), [src/release-evidence.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/release-evidence.ts), [src/reviewos-evidence.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/reviewos-evidence.ts), [src/reviewos-workflows.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/reviewos-workflows.ts), [src/scaffold-crud.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/scaffold-crud.ts), [src/setup/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/setup/index.ts), [src/stacks.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/stacks.ts), [src/stx-source.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/stx-source.ts), [src/upgrade/package-project.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/upgrade/package-project.ts), [src/upgrade/route-actions.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/src/upgrade/route-actions.ts).
|
|
125
125
|
|
|
126
|
-
Evidence directory: [
|
|
126
|
+
Evidence directory: [130 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/actions/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
127
127
|
|
|
128
128
|
### @stacksjs/ai
|
|
129
129
|
|
|
@@ -627,7 +627,7 @@ Read the entrypoint and package export map for re-exported or type-only surfaces
|
|
|
627
627
|
|
|
628
628
|
Local source modules: [src/campaigns.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/newsletter/src/campaigns.ts), [src/delivery.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/newsletter/src/delivery.ts), [src/headers.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/newsletter/src/headers.ts), [src/lists.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/newsletter/src/lists.ts), [src/newsletter.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/newsletter/src/newsletter.ts), [src/subscriptions.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/newsletter/src/subscriptions.ts), [src/sync.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/newsletter/src/sync.ts), [src/types.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/newsletter/src/types.ts), [src/usage.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/newsletter/src/usage.ts).
|
|
629
629
|
|
|
630
|
-
Evidence directory: [
|
|
630
|
+
Evidence directory: [11 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/newsletter/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
631
631
|
|
|
632
632
|
### @stacksjs/notifications
|
|
633
633
|
|
|
@@ -685,7 +685,7 @@ Declared runtime exports: `Payment`, `freshIdempotencyKey`, `stacksIdempotencyKe
|
|
|
685
685
|
|
|
686
686
|
Local source modules: [src/billable/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/payments/src/billable/index.ts), [src/checkout-outcome.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/payments/src/checkout-outcome.ts), [src/connect/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/payments/src/connect/index.ts), [src/direct-debit.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/payments/src/direct-debit.ts), [src/driver/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/payments/src/driver/index.ts), [src/drivers/stripe.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/payments/src/drivers/stripe.ts), [src/idempotency.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/payments/src/idempotency.ts), [src/payment.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/payments/src/payment.ts), [src/subscription-state.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/payments/src/subscription-state.ts), [src/terminal.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/payments/src/terminal.ts).
|
|
687
687
|
|
|
688
|
-
Evidence directory: [
|
|
688
|
+
Evidence directory: [42 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/payments/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
689
689
|
|
|
690
690
|
### @stacksjs/push
|
|
691
691
|
|
|
@@ -847,9 +847,9 @@ Guidance: [`stacks-socials`](../stacks-socials/SKILL.md). Source: [storage/frame
|
|
|
847
847
|
|
|
848
848
|
Read the entrypoint and package export map for re-exported or type-only surfaces.
|
|
849
849
|
|
|
850
|
-
Local source modules: [src/abstract.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/abstract.ts), [src/authorize.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/authorize.ts), [src/drivers/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/drivers/index.ts), [src/exceptions.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/exceptions.ts), [src/flows.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/flows.ts), [src/handoff.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/handoff.ts), [src/identities.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/identities.ts), [src/meta-graph.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/meta-graph.ts), [src/publish.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/publish.ts), [src/registry.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/registry.ts), [src/token.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/token.ts), [src/types.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/types.ts).
|
|
850
|
+
Local source modules: [src/abstract.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/abstract.ts), [src/authorize.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/authorize.ts), [src/drivers/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/drivers/index.ts), [src/exceptions.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/exceptions.ts), [src/flows.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/flows.ts), [src/handoff.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/handoff.ts), [src/identities.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/identities.ts), [src/media.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/media.ts), [src/meta-graph.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/meta-graph.ts), [src/publish-errors.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/publish-errors.ts), [src/publish.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/publish.ts), [src/registry.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/registry.ts), [src/text.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/text.ts), [src/token.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/token.ts), [src/types.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/types.ts).
|
|
851
851
|
|
|
852
|
-
Evidence directory: [
|
|
852
|
+
Evidence directory: [21 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
853
853
|
|
|
854
854
|
### @stacksjs/storage
|
|
855
855
|
|
|
@@ -26,6 +26,57 @@ before that still match. A sync skips an address whose row on the list is
|
|
|
26
26
|
unsubscribed under any spelling. subscriberIdsForEmail(email) and
|
|
27
27
|
listStatusForEmail(email, listId) are the lookups they share.
|
|
28
28
|
|
|
29
|
+
## Public signup
|
|
30
|
+
|
|
31
|
+
Put `<SubscribeForm />` on a page for a newsletter signup; it ships in the
|
|
32
|
+
framework defaults (`resources/components/Marketing/SubscribeForm.stx`) and
|
|
33
|
+
needs no setup. It is an stx component: it submits in place with a spinner and
|
|
34
|
+
shows the answer under the field, and without JavaScript it still posts as a
|
|
35
|
+
plain form. Props are all optional: `list` (a public list's slug, else the
|
|
36
|
+
default list), `source`, `label`, `placeholder`, `intro`, `fine`,
|
|
37
|
+
`successText`, `alreadyText`, `tone` (`primary` or `outline`), `buttonClass`,
|
|
38
|
+
`returnTo`, and `outcome`. A plain post comes back with `?subscribe=<outcome>`;
|
|
39
|
+
pass it to `outcome` so the page shows the answer on load. Restyle it with the
|
|
40
|
+
`--subscribe-*` CSS variables or your own classes; its rules have zero
|
|
41
|
+
specificity.
|
|
42
|
+
|
|
43
|
+
The form posts to `POST /api/email/subscribe` (`SubscriberEmailAction`), which
|
|
44
|
+
goes through `subscribe(email, { list, source, publicOnly: true })`: the
|
|
45
|
+
signup joins a list, so campaigns reach it. `publicOnly` refuses a list whose
|
|
46
|
+
`is_public` is false (`NewsletterListUnavailableError`, answered as a 422), so a
|
|
47
|
+
form field never joins an internal list. Outcomes: `subscribed` (new, or a
|
|
48
|
+
returning opt-out signed back up), `already`, `invalid`, `busy` (rate limited)
|
|
49
|
+
and `error`. Scripts get JSON; a browser form post gets a 303 back to `return`
|
|
50
|
+
or the Referer. The welcome email carries the membership's own token, so its
|
|
51
|
+
unsubscribe link and RFC 8058 headers leave that list only.
|
|
52
|
+
|
|
53
|
+
`subscribe()` validates with `emailAddress()` and reports `created`,
|
|
54
|
+
`reactivated` (signed back up after a per-list or global opt-out),
|
|
55
|
+
`subscriberId` and `token`. The legacy global unsubscribe link (a subscriber
|
|
56
|
+
uuid) also unsubscribes every list membership, since campaigns send to
|
|
57
|
+
memberships.
|
|
58
|
+
|
|
59
|
+
## Double opt-in
|
|
60
|
+
|
|
61
|
+
Turn on `doubleOptIn` for a list (`lists.create({ ..., doubleOptIn: true })`
|
|
62
|
+
or the dashboard) and its public signups confirm their address first. The
|
|
63
|
+
endpoint calls `subscribe()` with `confirmation: 'list'`, so a new or returning
|
|
64
|
+
address on such a list is stored `pending` (the membership, and the person if
|
|
65
|
+
they are new), the `SubscriptionConfirmRequest` mail sends a
|
|
66
|
+
`resources/emails/subscription-confirm.stx` email, and the form answers
|
|
67
|
+
`pending` (`pendingText`). Its button opens `GET /api/email/confirm?token=`
|
|
68
|
+
(`ConfirmSubscriptionAction`), which calls `confirm(token)`, stamps
|
|
69
|
+
`subscribed_at`, and sends the welcome email. Campaigns skip pending
|
|
70
|
+
memberships. Signing up again while pending re-sends the email; confirming
|
|
71
|
+
twice is harmless; a token that has since unsubscribed is refused.
|
|
72
|
+
|
|
73
|
+
`subscribe()` without `confirmation: 'list'` (imports, admin adds) subscribes
|
|
74
|
+
at once and promotes a pending membership. The auto-created default list is
|
|
75
|
+
single opt-in. A default list created by an older release has
|
|
76
|
+
`double_opt_in` on; set it off if you do not want confirmation there. The
|
|
77
|
+
confirm and unsubscribe routes stay reachable in maintenance and coming-soon
|
|
78
|
+
mode, like the signup.
|
|
79
|
+
|
|
29
80
|
Campaign delivery snapshots, dispatch keys and state conflict errors protect
|
|
30
81
|
retries and concurrent queue requests. Scheduled work uses the package's actual
|
|
31
82
|
transition and readiness checks. DeliveryVariant allocation and
|
|
@@ -102,6 +102,8 @@ const upgrade = await Payment.subscriptionCheckout(user, 'price_xxx', {
|
|
|
102
102
|
|
|
103
103
|
Send the payer to `session.url`. `trialDays` starts a subscription checkout with a trial. `reference` and `metadata` are copied onto the payment or subscription the checkout creates. Return URLs must be on the app's origin.
|
|
104
104
|
|
|
105
|
+
For Stripe checkout, persist an `idempotencyKey` before starting an attempt. Reuse the key and the same parameters when retrying that attempt within Stripe's replay window. Reconcile the original attempt before retrying after the replay window. Omit the key to start a new attempt, or supply a new key if the app needs to retry it safely. The key goes in a Stripe request header. Other built-in drivers reject this option.
|
|
106
|
+
|
|
105
107
|
### Subscriptions
|
|
106
108
|
|
|
107
109
|
```typescript
|
|
@@ -706,6 +708,15 @@ portal: {
|
|
|
706
708
|
paymentMethodUpdate: true, // default true
|
|
707
709
|
invoiceHistory: true, // default true
|
|
708
710
|
emailUpdate: true, // default true
|
|
711
|
+
subscriptionUpdate: {
|
|
712
|
+
allowedUpdates: ['price', 'quantity'],
|
|
713
|
+
prorationBehavior: 'always_invoice',
|
|
714
|
+
products: [{
|
|
715
|
+
product: 'prod_xxx',
|
|
716
|
+
prices: ['price_monthly', 'price_yearly'],
|
|
717
|
+
adjustableQuantity: { minimum: 1, maximum: 20 },
|
|
718
|
+
}],
|
|
719
|
+
},
|
|
709
720
|
}
|
|
710
721
|
```
|
|
711
722
|
|
|
@@ -714,6 +725,8 @@ and found by that tag, so several apps can share one Stripe account without
|
|
|
714
725
|
editing each other's portal. `billingPortal()` uses it, or the account default
|
|
715
726
|
when the app declares no portal.
|
|
716
727
|
|
|
728
|
+
Use Stripe product IDs and price IDs to choose which subscriptions customers can change. Include an `adjustableQuantity` range on each product where customers may change the seat count. Set `subscriptionUpdate: false` to disable the feature. Omit the setting to preserve the portal configuration's existing subscription-update settings.
|
|
729
|
+
|
|
717
730
|
### Utility Functions
|
|
718
731
|
|
|
719
732
|
```typescript
|
|
@@ -117,6 +117,22 @@ through it. PublishPostInput/PublishedPost/SocialPublishingDriver are exported
|
|
|
117
117
|
contracts. Read their driver methods before using media, metrics, deletion,
|
|
118
118
|
refresh or profile functionality; support differs per provider.
|
|
119
119
|
|
|
120
|
+
Each driver measures its limit the way its network counts (countText and
|
|
121
|
+
exceedsLimit in text.ts: graphemes on Bluesky and Threads, X's weighted count,
|
|
122
|
+
Mastodon's link and mention rules) and sends several images with alt text: X up
|
|
123
|
+
to four, carousels on Threads and Instagram, multiImage on LinkedIn. An image
|
|
124
|
+
given by URL is downloaded through fetchPostImage (the outbound guard in
|
|
125
|
+
@stacksjs/security) and a URL that gives no image throws PostImageError; tests
|
|
126
|
+
replace a driver's fetchImage. Mastodon's publish takes a third argument
|
|
127
|
+
(idempotencyKey, visibility, spoilerText, language) and reads the instance's
|
|
128
|
+
limits. Bluesky uploads external.thumb for link cards. PublishedPost.warnings
|
|
129
|
+
lists what went out without failing the post. The LinkedIn version is
|
|
130
|
+
LINKEDIN_API_VERSION unless a configured one is still supported.
|
|
131
|
+
|
|
132
|
+
A driver error's isAuthError is narrow; classifySocialError in
|
|
133
|
+
publish-errors.ts sorts any failure by status and body, and only `expired`
|
|
134
|
+
means the account must sign in again (a duplicate post on X is a 403).
|
|
135
|
+
|
|
120
136
|
## Authorization and operational limits
|
|
121
137
|
|
|
122
138
|
The native terminal consent helper in authorize.ts currently supports X only.
|
|
@@ -133,8 +149,10 @@ conformance or successful publication for arbitrary accounts.
|
|
|
133
149
|
## Source and evidence
|
|
134
150
|
|
|
135
151
|
`storage/framework/core/socials/src/index.ts`, registry.ts, abstract.ts, flows.ts,
|
|
136
|
-
handoff.ts, identities.ts, publish.ts, authorize.ts, meta-graph.ts
|
|
152
|
+
handoff.ts, identities.ts, publish.ts, authorize.ts, meta-graph.ts, text.ts,
|
|
153
|
+
media.ts, publish-errors.ts and drivers/.
|
|
137
154
|
Tests: registry.test.ts, apple.test.ts, session-handoff.test.ts, oauth-flows.test.ts,
|
|
138
155
|
provider-flow-state.test.ts, auth/tests/social-callback-flow.test.ts,
|
|
139
156
|
identities.test.ts, publish.test.ts, authorize.test.ts,
|
|
140
|
-
credentials-stay-out-of-output.test.ts
|
|
157
|
+
credentials-stay-out-of-output.test.ts, meta-graph.test.ts,
|
|
158
|
+
publishing-drivers.test.ts, text.test.ts and publish-errors.test.ts.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { RequestInstance } from '@stacksjs/types'
|
|
2
|
+
import { Action } from '@stacksjs/actions/runtime'
|
|
3
|
+
import { confirm } from '@stacksjs/newsletter'
|
|
4
|
+
import { sendSubscriptionConfirmation } from '../Mail/SubscriptionConfirmation'
|
|
5
|
+
import { subscriptionPage } from './subscription-page'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* `GET /api/email/confirm?token=…`: the button in the double opt-in email.
|
|
9
|
+
*
|
|
10
|
+
* Confirms the pending list membership the token names (@stacksjs/newsletter's
|
|
11
|
+
* `confirm()`), sends the welcome email the first time, and answers with a
|
|
12
|
+
* small page. Confirming twice is harmless. A token that has since
|
|
13
|
+
* unsubscribed is refused, so an old confirmation link never undoes an
|
|
14
|
+
* opt-out.
|
|
15
|
+
*/
|
|
16
|
+
export default new Action({
|
|
17
|
+
name: 'ConfirmSubscriptionAction',
|
|
18
|
+
description: 'Confirm a double opt-in newsletter subscription from the emailed link',
|
|
19
|
+
method: 'GET',
|
|
20
|
+
|
|
21
|
+
async handle(request: RequestInstance) {
|
|
22
|
+
const token = String(request.get('token') || '')
|
|
23
|
+
const html = (title: string, message: string, success: boolean) => new Response(subscriptionPage(title, message, success), {
|
|
24
|
+
headers: { 'Content-Type': 'text/html; charset=utf-8' },
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
if (!token)
|
|
28
|
+
return html('Missing token', 'This confirmation link is incomplete. Open it again from the email.', false)
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const result = await confirm(token)
|
|
32
|
+
|
|
33
|
+
if (!result.ok)
|
|
34
|
+
return html('Link no longer valid', 'This confirmation link has expired or was already used to unsubscribe. Sign up again to get a fresh one.', false)
|
|
35
|
+
|
|
36
|
+
if (result.alreadyConfirmed)
|
|
37
|
+
return html('Already confirmed', `${result.email ?? 'Your address'} is already subscribed. Nothing else to do.`, true)
|
|
38
|
+
|
|
39
|
+
if (result.email) {
|
|
40
|
+
sendSubscriptionConfirmation({ to: result.email, token }).catch((err: unknown) => {
|
|
41
|
+
const message = err instanceof Error ? err.message : String(err)
|
|
42
|
+
console.error(`Failed to send welcome email to ${result.email}:`, message)
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return html('You are subscribed', `Thanks for confirming. ${result.email ?? 'Your address'} is on the list, and a welcome email is on its way.`, true)
|
|
47
|
+
}
|
|
48
|
+
catch (error: unknown) {
|
|
49
|
+
console.error('Confirm subscription error:', error instanceof Error ? error.message : String(error))
|
|
50
|
+
return html('Something went wrong', 'We could not confirm your subscription just now. Please try the link again in a moment.', false)
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
})
|
|
@@ -1,24 +1,49 @@
|
|
|
1
1
|
import { Action } from '@stacksjs/actions/runtime'
|
|
2
|
-
import {
|
|
2
|
+
import { emailAddress, NewsletterListUnavailableError, subscribe } from '@stacksjs/newsletter'
|
|
3
|
+
import { SubscriberEmail } from '@stacksjs/orm'
|
|
3
4
|
import { rateLimit } from '@stacksjs/router'
|
|
5
|
+
import { sendSubscriptionConfirmRequest } from '../Mail/SubscriptionConfirmRequest'
|
|
4
6
|
import { sendSubscriptionConfirmation } from '../Mail/SubscriptionConfirmation'
|
|
5
|
-
import { formReturnLocation,
|
|
7
|
+
import { formReturnLocation, wantsFormRedirect } from './form-return'
|
|
6
8
|
|
|
7
9
|
/**
|
|
10
|
+
* The public newsletter signup, `POST /api/email/subscribe`, behind every
|
|
11
|
+
* `<SubscribeForm>` and any hand-written form.
|
|
12
|
+
*
|
|
13
|
+
* It goes through `@stacksjs/newsletter`'s `subscribe()`, so a signup joins a
|
|
14
|
+
* list (the default list, or a public one the form names in `list`) and
|
|
15
|
+
* campaigns reach it. It used to write only a `subscribers` row and join no
|
|
16
|
+
* list at all, so nobody who signed up on a website ever got a campaign.
|
|
17
|
+
*
|
|
18
|
+
* Fields: `email`, `source` (where they signed up, stored on the row), `list`
|
|
19
|
+
* (a public list's slug; private lists are refused), `return` (where a plain
|
|
20
|
+
* form post comes back to).
|
|
21
|
+
*
|
|
8
22
|
* What a signup came to. A plain form gets it back as `?subscribe=<outcome>`;
|
|
9
23
|
* a script gets the JSON beside it.
|
|
10
24
|
*
|
|
11
25
|
* - `subscribed`: a new address, or one that had unsubscribed and came back.
|
|
26
|
+
* - `pending`: the list has double opt-in on; a confirmation email went out
|
|
27
|
+
* and the address joins once its link is opened (ConfirmSubscriptionAction).
|
|
12
28
|
* - `already`: the address is on the list.
|
|
13
29
|
* - `invalid`: not an email address.
|
|
14
30
|
* - `busy`: too many attempts from this visitor in a minute.
|
|
15
31
|
* - `error`: anything else. Logged here; the visitor is asked to try again.
|
|
16
32
|
*/
|
|
17
|
-
type Outcome = 'subscribed' | 'already' | 'invalid' | 'busy' | 'error'
|
|
33
|
+
type Outcome = 'subscribed' | 'pending' | 'already' | 'invalid' | 'busy' | 'error'
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The tables this action writes, most of them through @stacksjs/newsletter
|
|
37
|
+
* rather than by model name. Stated here because frameworkRouteAdmission
|
|
38
|
+
* decides from this file's own source whether the route can be mounted: in an
|
|
39
|
+
* app without these tables the route is withheld instead of failing per
|
|
40
|
+
* request.
|
|
41
|
+
*/
|
|
42
|
+
export const subscriberTables = ['subscribers', 'email_lists', 'email_list_subscribers', 'subscriber_emails'] as const
|
|
18
43
|
|
|
19
44
|
export default new Action({
|
|
20
45
|
name: 'SubscriberEmailAction',
|
|
21
|
-
description: '
|
|
46
|
+
description: 'Subscribe an address to a newsletter list and send the welcome email',
|
|
22
47
|
method: 'POST',
|
|
23
48
|
|
|
24
49
|
async handle(request: RequestInstance) {
|
|
@@ -43,50 +68,51 @@ export default new Action({
|
|
|
43
68
|
throw err
|
|
44
69
|
}
|
|
45
70
|
|
|
46
|
-
const email =
|
|
47
|
-
const source = String(request.get('source') || 'homepage').slice(0,
|
|
71
|
+
const email = emailAddress(request.get('email'))
|
|
72
|
+
const source = String(request.get('source') || 'homepage').slice(0, 100)
|
|
73
|
+
const list = String(request.get('list') || '').trim() || undefined
|
|
48
74
|
|
|
49
75
|
if (!email)
|
|
50
76
|
return answer('invalid', { success: false, message: 'A valid email is required' })
|
|
51
77
|
|
|
52
78
|
try {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (existing.status !== 'unsubscribed')
|
|
57
|
-
return answer('already', { success: true, message: 'Already subscribed' })
|
|
58
|
-
|
|
59
|
-
// They left and came back. Telling them "already subscribed" while
|
|
60
|
-
// the row still says unsubscribed would keep them off every send.
|
|
61
|
-
await existing.update({ status: 'subscribed', unsubscribed_at: null, source })
|
|
62
|
-
await SubscriberEmail.create({ email, source })
|
|
63
|
-
welcome(email, existing.uuid)
|
|
64
|
-
return answer('subscribed', { success: true, message: 'Subscribed' })
|
|
65
|
-
}
|
|
79
|
+
// `confirmation: 'list'`: a list with double opt-in on holds the address
|
|
80
|
+
// as pending until it confirms; any other list subscribes it at once.
|
|
81
|
+
const result = await subscribe(email, { list, source, publicOnly: true, confirmation: 'list' })
|
|
66
82
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
subscriber = await Subscriber.create({ email, status: 'subscribed', source })
|
|
75
|
-
}
|
|
76
|
-
catch (err) {
|
|
77
|
-
if (isUniqueViolation(err))
|
|
78
|
-
return answer('already', { success: true, message: 'Already subscribed' })
|
|
79
|
-
throw err
|
|
83
|
+
if (result.pending) {
|
|
84
|
+
// New, returning, or asking again while still pending: (re)send the
|
|
85
|
+
// confirmation email. The rate limit above bounds how often.
|
|
86
|
+
if (result.created || result.reactivated)
|
|
87
|
+
await SubscriberEmail.create({ email, source, subscriber_id: result.subscriberId })
|
|
88
|
+
confirmRequest(email, result.token)
|
|
89
|
+
return answer('pending', { success: true, pending: true, message: 'Confirmation required' })
|
|
80
90
|
}
|
|
81
91
|
|
|
82
|
-
|
|
83
|
-
|
|
92
|
+
if (!result.created && !result.reactivated)
|
|
93
|
+
return answer('already', { success: true, message: 'Already subscribed' })
|
|
84
94
|
|
|
85
|
-
|
|
95
|
+
// The signup log, tied to the person it belongs to.
|
|
96
|
+
await SubscriberEmail.create({ email, source, subscriber_id: result.subscriberId })
|
|
86
97
|
|
|
87
|
-
|
|
98
|
+
welcome(email, result.token)
|
|
99
|
+
|
|
100
|
+
return answer('subscribed', {
|
|
101
|
+
success: true,
|
|
102
|
+
message: result.reactivated ? 'Subscribed again' : 'Subscribed',
|
|
103
|
+
subscriber: { email, listId: result.listId },
|
|
104
|
+
})
|
|
88
105
|
}
|
|
89
106
|
catch (err) {
|
|
107
|
+
// A form naming a list that is missing or private: say so plainly, as
|
|
108
|
+
// a 422, rather than a 500 carrying the internal error's name.
|
|
109
|
+
if (err instanceof NewsletterListUnavailableError) {
|
|
110
|
+
console.error('[subscribe] signup refused:', err.message)
|
|
111
|
+
return backToForm
|
|
112
|
+
? answer('error', {})
|
|
113
|
+
: response.json({ success: false, error: 'list_unavailable', message: 'That list is not open for signups.' }, 422)
|
|
114
|
+
}
|
|
115
|
+
|
|
90
116
|
if (!backToForm)
|
|
91
117
|
throw err
|
|
92
118
|
|
|
@@ -96,9 +122,21 @@ export default new Action({
|
|
|
96
122
|
},
|
|
97
123
|
})
|
|
98
124
|
|
|
99
|
-
/** Send the
|
|
100
|
-
function
|
|
101
|
-
|
|
125
|
+
/** Send the double opt-in email without holding up the response; a failure is logged. */
|
|
126
|
+
function confirmRequest(to: string, token: string): void {
|
|
127
|
+
sendSubscriptionConfirmRequest({ to, token }).catch((err: unknown) => {
|
|
128
|
+
const message = err instanceof Error ? err.message : String(err)
|
|
129
|
+
console.error(`Failed to send the confirmation request to ${to}:`, message)
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Send the welcome email without holding up the response; a failure is
|
|
135
|
+
* logged. `token` is the list membership's own, so the unsubscribe link in
|
|
136
|
+
* the email leaves that list and nothing else.
|
|
137
|
+
*/
|
|
138
|
+
function welcome(to: string, token: string): void {
|
|
139
|
+
sendSubscriptionConfirmation({ to, token }).catch((err: unknown) => {
|
|
102
140
|
const message = err instanceof Error ? err.message : String(err)
|
|
103
141
|
console.error(`Failed to send confirmation email to ${to}:`, message)
|
|
104
142
|
})
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { RequestInstance } from '@stacksjs/types'
|
|
2
2
|
import { Action } from '@stacksjs/actions/runtime'
|
|
3
|
-
import {
|
|
3
|
+
import { unsubscribeAll } from '@stacksjs/newsletter'
|
|
4
4
|
import { EmailList, EmailListSubscriber, Subscriber } from '@stacksjs/orm'
|
|
5
|
+
import { subscriptionPage as unsubscribePage } from './subscription-page'
|
|
5
6
|
|
|
6
7
|
export default new Action({
|
|
7
8
|
name: 'UnsubscribeAction',
|
|
@@ -69,6 +70,9 @@ export default new Action({
|
|
|
69
70
|
status: 'unsubscribed',
|
|
70
71
|
unsubscribed_at: new Date().toISOString(),
|
|
71
72
|
})
|
|
73
|
+
// The global link means every list. Campaigns send to list memberships,
|
|
74
|
+
// so marking only the subscriber row left them all still receiving.
|
|
75
|
+
await unsubscribeAll(subscriber.email)
|
|
72
76
|
|
|
73
77
|
return new Response(unsubscribePage('Unsubscribed', `${subscriber.email} has been successfully unsubscribed. You will no longer receive emails from us.`, true), {
|
|
74
78
|
headers: { 'Content-Type': 'text/html' },
|
|
@@ -83,52 +87,3 @@ export default new Action({
|
|
|
83
87
|
}
|
|
84
88
|
},
|
|
85
89
|
})
|
|
86
|
-
|
|
87
|
-
function escapeHtml(value: string): string {
|
|
88
|
-
return value.replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', '\'': ''' }[c]!))
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* The page an unsubscribe link lands on.
|
|
93
|
-
*
|
|
94
|
-
* It names the app the visitor subscribed to, from config, rather than
|
|
95
|
-
* stacksjs.com, which every app using this default used to print. The
|
|
96
|
-
* message carries the subscriber's stored address, so everything is escaped.
|
|
97
|
-
*/
|
|
98
|
-
function unsubscribePage(title: string, message: string, success: boolean): string {
|
|
99
|
-
const appName = escapeHtml(config.app?.name || 'Home')
|
|
100
|
-
const rawUrl = String(config.app?.url || '/')
|
|
101
|
-
const appUrl = escapeHtml(/^https?:\/\//.test(rawUrl) || rawUrl.startsWith('/') ? rawUrl : `https://${rawUrl}`)
|
|
102
|
-
const accent = success ? '#1747c9' : '#dc2626'
|
|
103
|
-
const icon = success ? '✓' : '!'
|
|
104
|
-
|
|
105
|
-
return `<!DOCTYPE html>
|
|
106
|
-
<html lang="en">
|
|
107
|
-
<head>
|
|
108
|
-
<meta charset="UTF-8">
|
|
109
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
110
|
-
<meta name="robots" content="noindex">
|
|
111
|
-
<meta name="color-scheme" content="light dark">
|
|
112
|
-
<title>${escapeHtml(title)} - ${appName}</title>
|
|
113
|
-
<style>
|
|
114
|
-
:root { --bg: #f6f7f9; --card: #ffffff; --text: #0b1220; --muted: #4a5468; --line: rgba(11, 18, 32, 0.1); }
|
|
115
|
-
@media (prefers-color-scheme: dark) { :root { --bg: #070b14; --card: #0d1322; --text: #e8edf7; --muted: #9ba7be; --line: rgba(232, 237, 247, 0.1); } }
|
|
116
|
-
* { box-sizing: border-box; }
|
|
117
|
-
body { margin: 0; min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; }
|
|
118
|
-
main { width: min(440px, 100%); padding: 40px 32px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); text-align: center; }
|
|
119
|
-
.icon { display: inline-grid; place-items: center; width: 56px; height: 56px; margin-bottom: 20px; border-radius: 50%; color: ${accent}; font-size: 24px; font-weight: 700; background: ${accent}1a; }
|
|
120
|
-
h1 { margin: 0 0 10px; font-size: 22px; letter-spacing: -0.01em; }
|
|
121
|
-
p { margin: 0 0 28px; color: var(--muted); font-size: 15px; line-height: 1.6; overflow-wrap: anywhere; }
|
|
122
|
-
a { display: inline-block; padding: 11px 20px; border-radius: 10px; color: #fff; font-size: 14px; font-weight: 600; text-decoration: none; background: #1747c9; }
|
|
123
|
-
</style>
|
|
124
|
-
</head>
|
|
125
|
-
<body>
|
|
126
|
-
<main>
|
|
127
|
-
<div class="icon" aria-hidden="true">${icon}</div>
|
|
128
|
-
<h1>${escapeHtml(title)}</h1>
|
|
129
|
-
<p>${escapeHtml(message)}</p>
|
|
130
|
-
<a href="${appUrl}">Back to ${appName}</a>
|
|
131
|
-
</main>
|
|
132
|
-
</body>
|
|
133
|
-
</html>`
|
|
134
|
-
}
|
|
@@ -9,26 +9,6 @@
|
|
|
9
9
|
* `fetch()` asks for anything (`Accept: *\/*`) and keeps getting JSON.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* An email address as a public form should store it, or null.
|
|
14
|
-
*
|
|
15
|
-
* Trimmed and lowercased, so `Ada@Example.com ` and `ada@example.com` are one
|
|
16
|
-
* subscriber, and held to the shape every mail system accepts: one `@`, a
|
|
17
|
-
* dot in the domain, no spaces or angle brackets, at most 254 characters.
|
|
18
|
-
* Checking only for an `@` let `<b>@x` into the list and onto every page
|
|
19
|
-
* that prints an address.
|
|
20
|
-
*/
|
|
21
|
-
export function normalizeEmail(value: unknown): string | null {
|
|
22
|
-
if (typeof value !== 'string')
|
|
23
|
-
return null
|
|
24
|
-
|
|
25
|
-
const email = value.trim().toLowerCase()
|
|
26
|
-
if (email.length > 254)
|
|
27
|
-
return null
|
|
28
|
-
|
|
29
|
-
return /^[^\s@<>"'(),;:]+@[^\s@<>"'(),;:]+\.[^\s@<>"'(),;:]{2,}$/.test(email) ? email : null
|
|
30
|
-
}
|
|
31
|
-
|
|
32
12
|
/** Whether the request is a browser submitting a `<form>`, rather than a script. */
|
|
33
13
|
export function wantsFormRedirect(headers: Headers): boolean {
|
|
34
14
|
const accept = headers.get('accept') || ''
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { config } from '@stacksjs/config'
|
|
2
|
+
|
|
3
|
+
function escapeHtml(value: string): string {
|
|
4
|
+
return value.replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', '\'': ''' }[c]!))
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The page an unsubscribe or confirmation link lands on.
|
|
9
|
+
*
|
|
10
|
+
* It names the app the visitor subscribed to, from config, rather than
|
|
11
|
+
* stacksjs.com, which every app using this default used to print. The
|
|
12
|
+
* message carries the subscriber's stored address, so everything is escaped.
|
|
13
|
+
*/
|
|
14
|
+
export function subscriptionPage(title: string, message: string, success: boolean): string {
|
|
15
|
+
const appName = escapeHtml(config.app?.name || 'Home')
|
|
16
|
+
const rawUrl = String(config.app?.url || '/')
|
|
17
|
+
const appUrl = escapeHtml(/^https?:\/\//.test(rawUrl) || rawUrl.startsWith('/') ? rawUrl : `https://${rawUrl}`)
|
|
18
|
+
const accent = success ? '#1747c9' : '#dc2626'
|
|
19
|
+
const icon = success ? '✓' : '!'
|
|
20
|
+
|
|
21
|
+
return `<!DOCTYPE html>
|
|
22
|
+
<html lang="en">
|
|
23
|
+
<head>
|
|
24
|
+
<meta charset="UTF-8">
|
|
25
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
26
|
+
<meta name="robots" content="noindex">
|
|
27
|
+
<meta name="color-scheme" content="light dark">
|
|
28
|
+
<title>${escapeHtml(title)} - ${appName}</title>
|
|
29
|
+
<style>
|
|
30
|
+
:root { --bg: #f6f7f9; --card: #ffffff; --text: #0b1220; --muted: #4a5468; --line: rgba(11, 18, 32, 0.1); }
|
|
31
|
+
@media (prefers-color-scheme: dark) { :root { --bg: #070b14; --card: #0d1322; --text: #e8edf7; --muted: #9ba7be; --line: rgba(232, 237, 247, 0.1); } }
|
|
32
|
+
* { box-sizing: border-box; }
|
|
33
|
+
body { margin: 0; min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; }
|
|
34
|
+
main { width: min(440px, 100%); padding: 40px 32px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); text-align: center; }
|
|
35
|
+
.icon { display: inline-grid; place-items: center; width: 56px; height: 56px; margin-bottom: 20px; border-radius: 50%; color: ${accent}; font-size: 24px; font-weight: 700; background: ${accent}1a; }
|
|
36
|
+
h1 { margin: 0 0 10px; font-size: 22px; letter-spacing: -0.01em; }
|
|
37
|
+
p { margin: 0 0 28px; color: var(--muted); font-size: 15px; line-height: 1.6; overflow-wrap: anywhere; }
|
|
38
|
+
a { display: inline-block; padding: 11px 20px; border-radius: 10px; color: #fff; font-size: 14px; font-weight: 600; text-decoration: none; background: #1747c9; }
|
|
39
|
+
</style>
|
|
40
|
+
</head>
|
|
41
|
+
<body>
|
|
42
|
+
<main>
|
|
43
|
+
<div class="icon" aria-hidden="true">${icon}</div>
|
|
44
|
+
<h1>${escapeHtml(title)}</h1>
|
|
45
|
+
<p>${escapeHtml(message)}</p>
|
|
46
|
+
<a href="${appUrl}">Back to ${appName}</a>
|
|
47
|
+
</main>
|
|
48
|
+
</body>
|
|
49
|
+
</html>`
|
|
50
|
+
}
|