@stacksjs/defaults 0.75.663 → 0.75.667
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
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { config } from '@stacksjs/config'
|
|
2
|
+
import { mail, template } from '@stacksjs/email'
|
|
3
|
+
import { url } from '@stacksjs/router'
|
|
4
|
+
|
|
5
|
+
export interface SubscriptionConfirmRequestOptions {
|
|
6
|
+
to: string
|
|
7
|
+
/** The pending list membership's token (`subscribe()`'s `token`). */
|
|
8
|
+
token: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** The app's own address, with a scheme, for links in the email. */
|
|
12
|
+
function appUrl(): string {
|
|
13
|
+
const raw = String(config.app.url || '').trim().replace(/\/+$/, '')
|
|
14
|
+
if (!raw)
|
|
15
|
+
return ''
|
|
16
|
+
return /^https?:\/\//.test(raw) ? raw : `https://${raw}`
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Ask a new subscriber to confirm their address (double opt-in).
|
|
21
|
+
*
|
|
22
|
+
* Sent by the public signup when the list has `double_opt_in` on. The button
|
|
23
|
+
* opens `GET /api/email/confirm?token=…` (ConfirmSubscriptionAction), which
|
|
24
|
+
* confirms the membership and sends the welcome email. Until then campaigns
|
|
25
|
+
* skip the address. Uses `resources/emails/subscription-confirm.stx`, which an
|
|
26
|
+
* app can override like any email template.
|
|
27
|
+
*/
|
|
28
|
+
export async function sendSubscriptionConfirmRequest(options: SubscriptionConfirmRequestOptions): Promise<void> {
|
|
29
|
+
const appName = config.app.name || 'Stacks'
|
|
30
|
+
const confirmUrl = url('email.confirm', { token: options.token })
|
|
31
|
+
const subject = `Confirm your subscription to ${appName}`
|
|
32
|
+
|
|
33
|
+
const { html, text } = await template('subscription-confirm', {
|
|
34
|
+
variables: {
|
|
35
|
+
email: options.to,
|
|
36
|
+
confirmUrl,
|
|
37
|
+
appName,
|
|
38
|
+
appUrl: appUrl(),
|
|
39
|
+
year: new Date().getFullYear(),
|
|
40
|
+
},
|
|
41
|
+
subject,
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
await mail.sendOrFail({
|
|
45
|
+
to: [options.to],
|
|
46
|
+
from: {
|
|
47
|
+
name: config.email.from?.name || appName,
|
|
48
|
+
address: config.email.from?.address || 'hello@stacksjs.com',
|
|
49
|
+
},
|
|
50
|
+
subject,
|
|
51
|
+
html,
|
|
52
|
+
text,
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default sendSubscriptionConfirmRequest
|
|
@@ -5,7 +5,14 @@ import { url } from '@stacksjs/router'
|
|
|
5
5
|
|
|
6
6
|
export interface SubscriptionConfirmationOptions {
|
|
7
7
|
to: string
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* The unsubscribe token for the link and the List-Unsubscribe headers: the
|
|
10
|
+
* list membership's uuid (`subscribe()`'s `token`), so unsubscribing leaves
|
|
11
|
+
* that list only.
|
|
12
|
+
*/
|
|
13
|
+
token?: string
|
|
14
|
+
/** The subscriber's own uuid, the older global token. Used when `token` is not given. */
|
|
15
|
+
subscriberUuid?: string
|
|
9
16
|
}
|
|
10
17
|
|
|
11
18
|
/** The app's own address, with a scheme, for links in the email. */
|
|
@@ -38,10 +45,13 @@ function unsubscribeHeaders(unsubscribeUrl: string): Record<string, string> | un
|
|
|
38
45
|
* to the framework's.
|
|
39
46
|
*/
|
|
40
47
|
export async function sendSubscriptionConfirmation(options: SubscriptionConfirmationOptions): Promise<void> {
|
|
41
|
-
const { to
|
|
48
|
+
const { to } = options
|
|
49
|
+
const unsubscribeToken = options.token || options.subscriberUuid
|
|
50
|
+
if (!unsubscribeToken)
|
|
51
|
+
throw new Error('[mail] sendSubscriptionConfirmation needs a token for the unsubscribe link')
|
|
42
52
|
|
|
43
53
|
const appName = config.app.name || 'Stacks'
|
|
44
|
-
const unsubscribeUrl = url('email.unsubscribe', { token:
|
|
54
|
+
const unsubscribeUrl = url('email.unsubscribe', { token: unsubscribeToken })
|
|
45
55
|
const subject = `You are on the ${appName} list`
|
|
46
56
|
|
|
47
57
|
const { html, text } = await template('subscription-confirmation', {
|
package/ide/vscode/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"publisher": "Stacks",
|
|
3
3
|
"name": "vscode-stacks",
|
|
4
4
|
"displayName": "Stacks",
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.667",
|
|
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.
|
|
5
|
+
"version": "0.75.667",
|
|
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.
|
|
49
|
-
"@stacksjs/sanitizer": "^0.2.
|
|
50
|
-
"@stacksjs/stx": "^0.2.
|
|
51
|
-
"@stacksjs/strings": "0.75.
|
|
48
|
+
"@stacksjs/mobile": "0.75.667",
|
|
49
|
+
"@stacksjs/sanitizer": "^0.2.930",
|
|
50
|
+
"@stacksjs/stx": "^0.2.930",
|
|
51
|
+
"@stacksjs/strings": "0.75.667",
|
|
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.
|
|
56
|
-
"@stacksjs/browser": "0.75.
|
|
55
|
+
"@stacksjs/support": "0.75.667",
|
|
56
|
+
"@stacksjs/browser": "0.75.667"
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -1197,13 +1197,12 @@ async function subscribeEmail(email: string): Promise<{ success: boolean, messag
|
|
|
1197
1197
|
body: JSON.stringify({ email }),
|
|
1198
1198
|
})
|
|
1199
1199
|
|
|
1200
|
-
|
|
1200
|
+
// The endpoint answers a bad address with 200 and `success: false`, so the
|
|
1201
|
+
// status alone is not the answer: read the body.
|
|
1202
|
+
const data = await response.json().catch(() => ({})) as { success?: boolean, message?: string }
|
|
1203
|
+
if (response.ok && data.success === true)
|
|
1201
1204
|
return { success: true }
|
|
1202
|
-
}
|
|
1203
|
-
else {
|
|
1204
|
-
const data = await response.json().catch(() => ({}))
|
|
1205
|
-
return { success: false, message: data.message || 'Failed to subscribe. Please try again later.' }
|
|
1206
|
-
}
|
|
1205
|
+
return { success: false, message: data.message || 'Failed to subscribe. Please try again later.' }
|
|
1207
1206
|
}
|
|
1208
1207
|
|
|
1209
1208
|
// Email signup (notification popup)
|
|
@@ -53,109 +53,11 @@ const { appName, description } = withDefaults(
|
|
|
53
53
|
</p>
|
|
54
54
|
|
|
55
55
|
<div class="flex gap-x-6 items-center mt-10">
|
|
56
|
-
<
|
|
57
|
-
<
|
|
58
|
-
|
|
59
|
-
<div class="h-5 w-5 text-gray-400 i-hugeicons-envelope"></div>
|
|
60
|
-
</div>
|
|
61
|
-
|
|
62
|
-
<input
|
|
63
|
-
id="coming-soon-email"
|
|
64
|
-
type="email"
|
|
65
|
-
name="email"
|
|
66
|
-
required
|
|
67
|
-
class="block pl-10 py-1.5 w-full text-gray-900 sm:leading-6 sm:text-sm placeholder:text-gray-400 border-0 ring-1 ring-gray-300 ring-inset rounded-l-md rounded-none focus:ring-2 focus:ring-blue-600 focus:ring-inset"
|
|
68
|
-
placeholder="may-we-ask@your-email.org">
|
|
69
|
-
</div>
|
|
70
|
-
|
|
71
|
-
<button
|
|
72
|
-
id="coming-soon-submit"
|
|
73
|
-
type="submit"
|
|
74
|
-
class="inline-flex relative gap-x-1.5 items-center -ml-px px-3 py-2 w-120px font-semibold text-gray-900 text-sm hover:bg-gray-50 ring-1 ring-gray-300 ring-inset rounded-r-md">
|
|
75
|
-
<span id="coming-soon-submit-label">Stay in Touch</span>
|
|
76
|
-
<div id="coming-soon-spinner" class="hidden h-4 w-4 animate-spin i-hugeicons-loading-01"></div>
|
|
77
|
-
</button>
|
|
78
|
-
</form>
|
|
56
|
+
<div class="w-380px">
|
|
57
|
+
<SubscribeForm source="coming-soon" label="Stay in touch" placeholder="may-we-ask@your-email.org" successText="Thanks, we will be in touch." />
|
|
58
|
+
</div>
|
|
79
59
|
</div>
|
|
80
|
-
|
|
81
|
-
<p id="coming-soon-error" class="hidden pt-2 text-red-500 text-xs"></p>
|
|
82
|
-
<p id="coming-soon-success" class="hidden pt-2 text-green-700 text-xs">
|
|
83
|
-
Thanks, we'll be in touch.
|
|
84
|
-
</p>
|
|
85
60
|
</div>
|
|
86
61
|
</div>
|
|
87
62
|
</div>
|
|
88
63
|
|
|
89
|
-
<script client>
|
|
90
|
-
// Client-side wiring for the holding-page email form. The endpoint
|
|
91
|
-
// itself (/api/email/subscribe) is rate-limited server-side; this
|
|
92
|
-
// handler just gives the visitor immediate feedback.
|
|
93
|
-
const form = document.getElementById('coming-soon-form') as HTMLFormElement | null
|
|
94
|
-
const emailInput = document.getElementById('coming-soon-email') as HTMLInputElement | null
|
|
95
|
-
const submitBtn = document.getElementById('coming-soon-submit') as HTMLButtonElement | null
|
|
96
|
-
const submitLabel = document.getElementById('coming-soon-submit-label')
|
|
97
|
-
const spinner = document.getElementById('coming-soon-spinner')
|
|
98
|
-
const errorEl = document.getElementById('coming-soon-error')
|
|
99
|
-
const successEl = document.getElementById('coming-soon-success')
|
|
100
|
-
|
|
101
|
-
function setLoading(loading: boolean) {
|
|
102
|
-
if (!submitBtn || !submitLabel || !spinner) return
|
|
103
|
-
submitBtn.disabled = loading
|
|
104
|
-
submitBtn.classList.toggle('opacity-50', loading)
|
|
105
|
-
submitLabel.classList.toggle('hidden', loading)
|
|
106
|
-
spinner.classList.toggle('hidden', !loading)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function showError(message: string) {
|
|
110
|
-
if (!errorEl) return
|
|
111
|
-
errorEl.textContent = message
|
|
112
|
-
errorEl.classList.remove('hidden')
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function clearMessages() {
|
|
116
|
-
if (errorEl) errorEl.classList.add('hidden')
|
|
117
|
-
if (successEl) successEl.classList.add('hidden')
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (form) {
|
|
121
|
-
form.addEventListener('submit', async function (event) {
|
|
122
|
-
event.preventDefault()
|
|
123
|
-
clearMessages()
|
|
124
|
-
|
|
125
|
-
const email = emailInput && emailInput.value ? emailInput.value.trim() : ''
|
|
126
|
-
if (!email || email.indexOf('@') === -1) {
|
|
127
|
-
showError('Please enter a valid email address.')
|
|
128
|
-
return
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
setLoading(true)
|
|
132
|
-
try {
|
|
133
|
-
const response = await fetch('/api/email/subscribe', {
|
|
134
|
-
method: 'POST',
|
|
135
|
-
headers: { 'Content-Type': 'application/json' },
|
|
136
|
-
body: JSON.stringify({ email }),
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
if (response.ok) {
|
|
140
|
-
if (successEl) successEl.classList.remove('hidden')
|
|
141
|
-
if (form) form.reset()
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
let message = 'Sorry, we could not subscribe you. Please try again later.'
|
|
145
|
-
try {
|
|
146
|
-
const data = await response.json()
|
|
147
|
-
if (data && data.message) message = data.message
|
|
148
|
-
}
|
|
149
|
-
catch { /* ignore parse errors */ }
|
|
150
|
-
showError(message)
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
catch {
|
|
154
|
-
showError('Network error, please try again.')
|
|
155
|
-
}
|
|
156
|
-
finally {
|
|
157
|
-
setLoading(false)
|
|
158
|
-
}
|
|
159
|
-
})
|
|
160
|
-
}
|
|
161
|
-
</script>
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
<script client>
|
|
2
|
+
/*
|
|
3
|
+
* A newsletter signup, answered in place. Drop it on any page:
|
|
4
|
+
*
|
|
5
|
+
* <SubscribeForm />
|
|
6
|
+
* <SubscribeForm list="launch" source="blog" label="Get the launch email" />
|
|
7
|
+
*
|
|
8
|
+
* It posts to the framework's public endpoint, POST /api/email/subscribe
|
|
9
|
+
* (SubscriberEmailAction), which puts the address on a newsletter list through
|
|
10
|
+
* @stacksjs/newsletter and sends the welcome email. Submitting does not reload
|
|
11
|
+
* the page: the button shows a spinner while the request is out and the answer
|
|
12
|
+
* appears under the field. A good address clears the field; a bad one keeps it,
|
|
13
|
+
* with focus, to fix.
|
|
14
|
+
*
|
|
15
|
+
* Without JavaScript it is still a plain form. The endpoint sends the browser
|
|
16
|
+
* back with ?subscribe=<outcome>; hand that to `outcome` and the matching
|
|
17
|
+
* message shows on load:
|
|
18
|
+
*
|
|
19
|
+
* <SubscribeForm outcome="{{ typeof query !== 'undefined' ? query.subscribe : '' }}" />
|
|
20
|
+
*
|
|
21
|
+
* Props (all optional):
|
|
22
|
+
* list a public list's slug; the default list when empty
|
|
23
|
+
* source where the signup came from, stored on the subscriber
|
|
24
|
+
* returnTo the path (and #fragment) a plain form post comes back to
|
|
25
|
+
* outcome the ?subscribe= value the page was loaded with
|
|
26
|
+
* label the button text
|
|
27
|
+
* placeholder the field's placeholder
|
|
28
|
+
* intro a visible label above the field (else a screen-reader label)
|
|
29
|
+
* fine fine print under the field, replaced by the answer
|
|
30
|
+
* successText, pendingText, alreadyText what to say for those outcomes
|
|
31
|
+
* (pending: the list has double opt-in on and a confirmation
|
|
32
|
+
* email went out)
|
|
33
|
+
* tone 'primary' for a filled button, 'outline' for an outlined one
|
|
34
|
+
* buttonClass extra classes for the button, such as an app's own button class
|
|
35
|
+
*
|
|
36
|
+
* Styling: everything is under `.subscribe-form` at zero specificity, coloured
|
|
37
|
+
* from CSS variables (--subscribe-accent, --subscribe-text, --subscribe-muted,
|
|
38
|
+
* --subscribe-border, --subscribe-field, --subscribe-success, --subscribe-error),
|
|
39
|
+
* so an app's own stylesheet wins without a fight.
|
|
40
|
+
*/
|
|
41
|
+
type Outcome = 'subscribed' | 'pending' | 'already' | 'invalid' | 'busy' | 'error'
|
|
42
|
+
|
|
43
|
+
const list = useReactiveProp<string>('list', '')
|
|
44
|
+
const source = useReactiveProp<string>('source', 'website')
|
|
45
|
+
const returnTo = useReactiveProp<string>('returnTo', '')
|
|
46
|
+
const loadedWith = useReactiveProp<string>('outcome', '')
|
|
47
|
+
const label = useReactiveProp<string>('label', 'Subscribe')
|
|
48
|
+
const placeholder = useReactiveProp<string>('placeholder', 'you@example.com')
|
|
49
|
+
const intro = useReactiveProp<string>('intro', '')
|
|
50
|
+
const fine = useReactiveProp<string>('fine', '')
|
|
51
|
+
const successText = useReactiveProp<string>('successText', 'Thanks, you are subscribed. A welcome email is on its way to your inbox.')
|
|
52
|
+
const pendingText = useReactiveProp<string>('pendingText', 'Almost there. Check your inbox and open the link to confirm your subscription.')
|
|
53
|
+
const alreadyText = useReactiveProp<string>('alreadyText', 'You are already subscribed. Thanks for sticking around.')
|
|
54
|
+
const tone = useReactiveProp<string>('tone', 'primary')
|
|
55
|
+
const buttonClass = useReactiveProp<string>('buttonClass', '')
|
|
56
|
+
|
|
57
|
+
const messages = {
|
|
58
|
+
invalid: 'That email address did not look right. Try it again?',
|
|
59
|
+
busy: 'That was a lot of tries in a minute. Give it a moment and try again.',
|
|
60
|
+
error: 'Something went wrong on our side and you are not subscribed yet. Please try again.',
|
|
61
|
+
}
|
|
62
|
+
const outcomes = ['subscribed', 'pending', 'already', 'invalid', 'busy', 'error']
|
|
63
|
+
|
|
64
|
+
const email = state('')
|
|
65
|
+
const sending = state(false)
|
|
66
|
+
const outcome = state<Outcome | ''>(outcomes.includes(loadedWith()) ? loadedWith() as Outcome : '')
|
|
67
|
+
const tonePositive = derived(() => outcome() === 'subscribed' || outcome() === 'pending' || outcome() === 'already')
|
|
68
|
+
const noticeText = derived(() => {
|
|
69
|
+
switch (outcome()) {
|
|
70
|
+
case 'subscribed': return successText()
|
|
71
|
+
case 'pending': return pendingText()
|
|
72
|
+
case 'already': return alreadyText()
|
|
73
|
+
case '': return ''
|
|
74
|
+
default: return messages[outcome() as 'invalid' | 'busy' | 'error']
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
const noticeClass = derived(() => !outcome() ? 'subscribe-form__notice--empty' : tonePositive() ? 'subscribe-form__notice--success' : 'subscribe-form__notice--error')
|
|
78
|
+
const noticeIcon = derived(() => tonePositive() ? 'i-hugeicons-checkmark-circle-02' : 'i-hugeicons-alert-circle')
|
|
79
|
+
const emailInput = useRef('emailInput')
|
|
80
|
+
|
|
81
|
+
// Long enough to read as "working" rather than a flicker, short enough never
|
|
82
|
+
// to be the slow part.
|
|
83
|
+
const minimumSpin = 450
|
|
84
|
+
|
|
85
|
+
/** Read the endpoint's JSON answer as an outcome. */
|
|
86
|
+
function outcomeOf(status: number, body: { success?: unknown, pending?: unknown, message?: unknown } | null): Outcome {
|
|
87
|
+
if (status === 429)
|
|
88
|
+
return 'busy'
|
|
89
|
+
if (status >= 200 && status < 300 && body) {
|
|
90
|
+
if (body.success === true && body.pending === true)
|
|
91
|
+
return 'pending'
|
|
92
|
+
if (body.success === true)
|
|
93
|
+
return body.message === 'Already subscribed' ? 'already' : 'subscribed'
|
|
94
|
+
if (body.success === false)
|
|
95
|
+
return 'invalid'
|
|
96
|
+
}
|
|
97
|
+
return 'error'
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function send(): Promise<Outcome> {
|
|
101
|
+
try {
|
|
102
|
+
const response = await fetch('/api/email/subscribe', {
|
|
103
|
+
method: 'POST',
|
|
104
|
+
headers: { 'Accept': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
105
|
+
body: new URLSearchParams({ email: email(), source: source(), list: list(), return: returnTo() }).toString(),
|
|
106
|
+
})
|
|
107
|
+
let body: { success?: unknown, pending?: unknown, message?: unknown } | null = null
|
|
108
|
+
try {
|
|
109
|
+
body = await response.json()
|
|
110
|
+
}
|
|
111
|
+
catch {}
|
|
112
|
+
return outcomeOf(response.status, body)
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return 'error'
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async function submit(): Promise<void> {
|
|
120
|
+
if (sending())
|
|
121
|
+
return
|
|
122
|
+
|
|
123
|
+
sending.set(true)
|
|
124
|
+
const [answer] = await Promise.all([send(), new Promise(resolve => setTimeout(resolve, minimumSpin))])
|
|
125
|
+
outcome.set(answer)
|
|
126
|
+
sending.set(false)
|
|
127
|
+
|
|
128
|
+
if (answer === 'subscribed' || answer === 'pending' || answer === 'already')
|
|
129
|
+
email.set('')
|
|
130
|
+
else
|
|
131
|
+
void nextTick(() => emailInput.current?.focus())
|
|
132
|
+
}
|
|
133
|
+
</script>
|
|
134
|
+
|
|
135
|
+
<form
|
|
136
|
+
class="subscribe-form"
|
|
137
|
+
:class="sending() ? 'is-loading' : ''"
|
|
138
|
+
action="/api/email/subscribe"
|
|
139
|
+
method="POST"
|
|
140
|
+
:aria-busy="sending() ? 'true' : 'false'"
|
|
141
|
+
@submit.prevent="submit()"
|
|
142
|
+
>
|
|
143
|
+
<input type="hidden" name="source" :value="source()">
|
|
144
|
+
<input type="hidden" name="list" :value="list()">
|
|
145
|
+
<input type="hidden" name="return" :value="returnTo()">
|
|
146
|
+
<label class="subscribe-form__intro" :class="intro() ? '' : 'subscribe-form__sr'" for="subscribe-email">{{ intro() || 'Email address' }}</label>
|
|
147
|
+
<div class="subscribe-form__row">
|
|
148
|
+
<input id="subscribe-email" ref="emailInput" class="subscribe-form__field" type="email" name="email" :placeholder="placeholder()" autocomplete="email" required x-model.trim="email">
|
|
149
|
+
<button type="submit" class="subscribe-form__button" :class="(tone() === 'outline' ? 'subscribe-form__button--outline ' : '') + buttonClass()" :disabled="sending()">
|
|
150
|
+
<span class="subscribe-form__spinner" aria-hidden="true"></span>
|
|
151
|
+
<span>{{ label() }}</span>
|
|
152
|
+
</button>
|
|
153
|
+
</div>
|
|
154
|
+
<p class="subscribe-form__notice" :class="noticeClass()" role="status" aria-live="polite">
|
|
155
|
+
<i aria-hidden="true" :class="noticeIcon()"></i>
|
|
156
|
+
<span>{{ noticeText() }}</span>
|
|
157
|
+
</p>
|
|
158
|
+
<p class="subscribe-form__fine" :class="outcome() || !fine() ? 'subscribe-form__fine--gone' : ''">{{ fine() }}</p>
|
|
159
|
+
</form>
|
|
160
|
+
|
|
161
|
+
<style>
|
|
162
|
+
:where(.subscribe-form) {
|
|
163
|
+
--subscribe-accent: #3451b2;
|
|
164
|
+
--subscribe-on-accent: #ffffff;
|
|
165
|
+
--subscribe-text: inherit;
|
|
166
|
+
--subscribe-muted: #6b7280;
|
|
167
|
+
--subscribe-border: rgba(0, 0, 0, 0.15);
|
|
168
|
+
--subscribe-field: #ffffff;
|
|
169
|
+
--subscribe-success: rgba(52, 81, 178, 0.1);
|
|
170
|
+
--subscribe-error: rgba(220, 38, 38, 0.1);
|
|
171
|
+
display: grid;
|
|
172
|
+
gap: 0.7rem;
|
|
173
|
+
color: var(--subscribe-text);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
:where(.subscribe-form__row) {
|
|
177
|
+
display: flex;
|
|
178
|
+
gap: 0.5rem;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
:where(.subscribe-form__field) {
|
|
182
|
+
flex: 1 1 auto;
|
|
183
|
+
min-width: 0;
|
|
184
|
+
min-height: 44px;
|
|
185
|
+
padding: 0 0.9rem;
|
|
186
|
+
border: 1px solid var(--subscribe-border);
|
|
187
|
+
border-radius: 10px;
|
|
188
|
+
color: inherit;
|
|
189
|
+
font: inherit;
|
|
190
|
+
background: var(--subscribe-field);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
:where(.subscribe-form__button) {
|
|
194
|
+
display: inline-flex;
|
|
195
|
+
flex: 0 0 auto;
|
|
196
|
+
gap: 0.5rem;
|
|
197
|
+
align-items: center;
|
|
198
|
+
justify-content: center;
|
|
199
|
+
min-height: 44px;
|
|
200
|
+
padding: 0 1.1rem;
|
|
201
|
+
border: 1px solid transparent;
|
|
202
|
+
border-radius: 10px;
|
|
203
|
+
color: var(--subscribe-on-accent);
|
|
204
|
+
font: inherit;
|
|
205
|
+
font-weight: 600;
|
|
206
|
+
white-space: nowrap;
|
|
207
|
+
background: var(--subscribe-accent);
|
|
208
|
+
cursor: pointer;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
:where(.subscribe-form__button--outline) {
|
|
212
|
+
border-color: var(--subscribe-border);
|
|
213
|
+
color: inherit;
|
|
214
|
+
background: transparent;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
:where(.subscribe-form__button:disabled) {
|
|
218
|
+
cursor: progress;
|
|
219
|
+
opacity: 0.85;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
:where(.subscribe-form__spinner) {
|
|
223
|
+
display: none;
|
|
224
|
+
width: 1em;
|
|
225
|
+
height: 1em;
|
|
226
|
+
border: 2px solid currentColor;
|
|
227
|
+
border-right-color: transparent;
|
|
228
|
+
border-radius: 50%;
|
|
229
|
+
animation: subscribe-form-spin 0.7s linear infinite;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
:where(.subscribe-form.is-loading .subscribe-form__spinner) {
|
|
233
|
+
display: inline-block;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
:where(.subscribe-form__intro) {
|
|
237
|
+
color: var(--subscribe-muted);
|
|
238
|
+
font-size: 0.9rem;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
:where(.subscribe-form__sr) {
|
|
242
|
+
position: absolute;
|
|
243
|
+
width: 1px;
|
|
244
|
+
height: 1px;
|
|
245
|
+
margin: -1px;
|
|
246
|
+
overflow: hidden;
|
|
247
|
+
clip: rect(0, 0, 0, 0);
|
|
248
|
+
white-space: nowrap;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
:where(.subscribe-form__notice) {
|
|
252
|
+
display: flex;
|
|
253
|
+
gap: 0.5rem;
|
|
254
|
+
align-items: flex-start;
|
|
255
|
+
margin: 0;
|
|
256
|
+
padding: 0.65rem 0.8rem;
|
|
257
|
+
border-radius: 10px;
|
|
258
|
+
font-size: 0.88rem;
|
|
259
|
+
line-height: 1.45;
|
|
260
|
+
animation: subscribe-form-in 0.22s ease-out;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
:where(.subscribe-form__notice i) {
|
|
264
|
+
flex: 0 0 auto;
|
|
265
|
+
width: 1.1rem;
|
|
266
|
+
height: 1.1rem;
|
|
267
|
+
margin-top: 0.05rem;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
:where(.subscribe-form__notice--success) {
|
|
271
|
+
background: var(--subscribe-success);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
:where(.subscribe-form__notice--success i) {
|
|
275
|
+
color: var(--subscribe-accent);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
:where(.subscribe-form__notice--error) {
|
|
279
|
+
background: var(--subscribe-error);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
:where(.subscribe-form__notice--error i) {
|
|
283
|
+
color: #dc2626;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
:where(.subscribe-form__notice--empty, .subscribe-form__fine--gone) {
|
|
287
|
+
display: none;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
:where(.subscribe-form__fine) {
|
|
291
|
+
margin: 0;
|
|
292
|
+
color: var(--subscribe-muted);
|
|
293
|
+
font-size: 0.8rem;
|
|
294
|
+
line-height: 1.5;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
@keyframes subscribe-form-spin {
|
|
298
|
+
to { transform: rotate(360deg); }
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
@keyframes subscribe-form-in {
|
|
302
|
+
from { opacity: 0; transform: translateY(-3px); }
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
@media (max-width: 560px) {
|
|
306
|
+
:where(.subscribe-form__row) {
|
|
307
|
+
flex-direction: column;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
@media (prefers-reduced-motion: reduce) {
|
|
312
|
+
:where(.subscribe-form__spinner) { animation-duration: 1.6s; }
|
|
313
|
+
:where(.subscribe-form__notice) { animation: none; }
|
|
314
|
+
}
|
|
315
|
+
</style>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<script server>
|
|
2
|
+
// The double opt-in email: sent by SubscriptionConfirmRequest (defaults/app/Mail)
|
|
3
|
+
// when someone signs up to a list that has `double_opt_in` on. The button
|
|
4
|
+
// confirms the address; until then the list sends nothing to it. It speaks for
|
|
5
|
+
// the app, from config, and an app overrides it with its own
|
|
6
|
+
// resources/emails/subscription-confirm.stx.
|
|
7
|
+
const email = props.email || ''
|
|
8
|
+
const confirmUrl = props.confirmUrl || '#'
|
|
9
|
+
const appName = props.appName || 'our newsletter'
|
|
10
|
+
const appUrl = props.appUrl || ''
|
|
11
|
+
const primaryColor = props.primaryColor || '#3451b2'
|
|
12
|
+
const year = props.year || new Date().getFullYear()
|
|
13
|
+
const subject = `Confirm your subscription to ${appName}`
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<EmailLayout title="{{ subject }}" preheader="One click to confirm, and you are on the {{ appName }} list." brand="{{ appName }}" brandUrl="{{ appUrl }}" accent="{{ primaryColor }}">
|
|
17
|
+
<EmailText size="heading">Confirm your subscription</EmailText>
|
|
18
|
+
<EmailText>Someone, hopefully you, asked to get {{ appName }} by email at {{ email }}. Confirm the address and you are on the list.</EmailText>
|
|
19
|
+
|
|
20
|
+
<EmailButton href="{{ confirmUrl }}" bg="{{ primaryColor }}">Yes, subscribe me</EmailButton>
|
|
21
|
+
|
|
22
|
+
<EmailDivider />
|
|
23
|
+
<EmailText size="sm" spacing="8px">If you did not sign up, ignore this email and nothing happens: you will not get anything else from us.</EmailText>
|
|
24
|
+
<EmailText size="sm" spacing="0">If the button does not work, open this link: <a href="{{ confirmUrl }}" style="color:{{ primaryColor }};word-break:break-all;">{{ confirmUrl }}</a></EmailText>
|
|
25
|
+
|
|
26
|
+
<template #footer>
|
|
27
|
+
<tr>
|
|
28
|
+
<td class="email-muted" style="padding:16px 40px 20px;border-top:1px solid #e4e4e7;color:#a1a1aa;font-size:11px;text-align:center;">© {{ year }} {{ appName }}</td>
|
|
29
|
+
</tr>
|
|
30
|
+
</template>
|
|
31
|
+
</EmailLayout>
|
package/routes/dashboard.ts
CHANGED
|
@@ -69,6 +69,8 @@ function guarded(prefix: string, base?: Parameters<typeof dashboardGroupMiddlewa
|
|
|
69
69
|
// the subscriber list) is better handled with the rate limiter — at
|
|
70
70
|
// the action layer — than with a token check the form can't satisfy.
|
|
71
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')
|
|
72
74
|
route.get('/api/email/unsubscribe', 'Actions/UnsubscribeAction').name('email.unsubscribe')
|
|
73
75
|
// RFC 8058 one-click endpoint. Mailbox providers (Gmail, Yahoo, Outlook)
|
|
74
76
|
// POST here with body `List-Unsubscribe=One-Click` when the user clicks
|