@open-pencil/cloud 0.17.0-beta.4 → 0.17.0-beta.5
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/README.md +2 -1
- package/dist/bin/server.mjs +1 -1
- package/dist/bin/server.mjs.map +1 -1
- package/dist/bin/services.mjs +1 -1
- package/dist/bin/services.mjs.map +1 -1
- package/dist/client.d.ts +296 -27
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +649 -295
- package/dist/client.js.map +1 -1
- package/dist/contract.d.ts +2 -2
- package/dist/contract.js +2 -2
- package/dist/contract2.js +331 -21
- package/dist/contract2.js.map +1 -1
- package/dist/email.d.ts +1773 -32
- package/dist/email.d.ts.map +1 -1
- package/dist/email.js +3478 -288
- package/dist/email.js.map +1 -1
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +48 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +466 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index2.d.ts +35 -0
- package/dist/index2.d.ts.map +1 -0
- package/dist/listen.mjs +447 -290
- package/dist/listen.mjs.map +1 -1
- package/dist/runtime-cloudflare.d.ts +89 -0
- package/dist/runtime-cloudflare.d.ts.map +1 -0
- package/dist/runtime-cloudflare.js +15667 -0
- package/dist/runtime-cloudflare.js.map +1 -0
- package/dist/runtime-node.d.mts +2963 -294
- package/dist/runtime-node.d.mts.map +1 -1
- package/dist/server.d.ts +3473 -842
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +12187 -8244
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +7739 -3548
- package/dist/server.mjs.map +1 -1
- package/dist/server2.mjs +5 -5
- package/dist/server2.mjs.map +1 -1
- package/package.json +22 -5
- package/src/admin/audit/service.ts +2 -2
- package/src/admin/documents/service.ts +76 -6
- package/src/admin/reports/service.ts +7 -1
- package/src/client/api.ts +23 -471
- package/src/client/auth/client.ts +22 -3
- package/src/client/billing.ts +80 -0
- package/src/client/community.ts +40 -0
- package/src/client/discovery.ts +35 -9
- package/src/client/documents.ts +160 -0
- package/src/client/index.ts +7 -0
- package/src/client/portal/account.ts +54 -2
- package/src/client/portal/request.ts +2 -0
- package/src/client/response.ts +21 -0
- package/src/client/schema.ts +8 -0
- package/src/client/services.ts +23 -18
- package/src/client/sharing.ts +262 -0
- package/src/client/versions.ts +104 -0
- package/src/contract/account.ts +50 -0
- package/src/contract/billing.ts +166 -0
- package/src/contract/collaboration.ts +5 -0
- package/src/contract/community.ts +60 -0
- package/src/contract/discovery.ts +63 -2
- package/src/contract/entitlements.ts +10 -0
- package/src/contract/index.ts +54 -5
- package/src/contract/links.ts +57 -4
- package/src/contract/locale.ts +27 -0
- package/src/contract/portal.ts +12 -1
- package/src/contract/routes.ts +10 -0
- package/src/contract/services.ts +18 -16
- package/src/email/i18n.ts +174 -0
- package/src/email/index.ts +13 -2
- package/src/email/locales/ar.json +141 -0
- package/src/email/locales/de.json +141 -0
- package/src/email/locales/es.json +141 -0
- package/src/email/locales/fr.json +141 -0
- package/src/email/locales/it.json +141 -0
- package/src/email/locales/ja.json +141 -0
- package/src/email/locales/pl.json +141 -0
- package/src/email/locales/pt-br.json +141 -0
- package/src/email/locales/ru.json +141 -0
- package/src/email/locales/zh-cn.json +141 -0
- package/src/email/messages.ts +200 -0
- package/src/email/render.ts +142 -276
- package/src/email/samples.ts +115 -0
- package/src/email/schema.ts +70 -6
- package/src/email/templates/BrandEmail.vue +54 -0
- package/src/email/templates/DocumentBlocked.vue +45 -0
- package/src/email/templates/DocumentInvitation.vue +24 -0
- package/src/email/templates/DocumentReport.vue +32 -0
- package/src/email/templates/DocumentReportDecided.vue +36 -0
- package/src/email/templates/DocumentReportReceived.vue +18 -0
- package/src/email/templates/DocumentRestored.vue +24 -0
- package/src/email/templates/EmailChangeRequested.vue +24 -0
- package/src/email/templates/EmailRoot.vue +19 -0
- package/src/email/templates/EmailText.vue +9 -0
- package/src/email/templates/EmailVerification.vue +38 -0
- package/src/email/templates/EnrollmentNotification.vue +24 -0
- package/src/email/templates/EnrollmentUpdate.vue +52 -0
- package/src/email/templates/NewSignIn.vue +37 -0
- package/src/email/templates/PasswordChanged.vue +22 -0
- package/src/email/templates/PasswordReset.vue +23 -0
- package/src/email/templates/StorageLimitReached.vue +28 -0
- package/src/email/templates/TwoStepChanged.vue +32 -0
- package/src/email/templates/WaitlistConfirmation.vue +29 -0
- package/src/email/templates/WorkspaceInvitation.vue +28 -0
- package/src/email/templates/brand.ts +9 -61
- package/src/email/templates/localization.ts +17 -0
- package/src/errors/index.ts +6 -0
- package/src/global.d.ts +7 -0
- package/src/runtime/cloudflare/relay/index.ts +7 -1
- package/src/runtime/cloudflare/tsconfig.json +2 -1
- package/src/runtime/cloudflare/worker.ts +8 -1
- package/src/runtime/node/cleanup.ts +5 -1
- package/src/runtime/node/email/transport.ts +13 -10
- package/src/runtime/node/main.ts +1 -1
- package/src/runtime/node/server.ts +12 -2
- package/src/runtime/node/services/main.ts +1 -1
- package/src/runtime/posthog/errors.ts +2 -1
- package/src/runtime/s3/objects.ts +17 -0
- package/src/runtime/site/community.ts +101 -0
- package/src/runtime/site/server.ts +17 -1
- package/src/server/account/deletion.ts +2 -0
- package/src/server/account/routes.ts +271 -240
- package/src/server/account/tokens.ts +57 -0
- package/src/server/api/router.ts +23 -0
- package/src/server/app/checks.ts +84 -0
- package/src/server/app/editors.ts +20 -0
- package/src/server/app/index.ts +128 -0
- package/src/server/app/indexing.ts +40 -0
- package/src/server/app/limiters.ts +53 -0
- package/src/server/app/routes.ts +114 -0
- package/src/server/app/services.ts +185 -0
- package/src/server/auth/access-tokens.ts +62 -0
- package/src/server/auth/adapter.ts +21 -1
- package/src/server/auth/email.ts +4 -1
- package/src/server/auth/enrollment.ts +116 -0
- package/src/server/auth/factory.ts +88 -131
- package/src/server/auth/logger.ts +23 -0
- package/src/server/auth/mfa-assurance.ts +51 -0
- package/src/server/auth/passwords.ts +43 -0
- package/src/server/auth/session.ts +2 -0
- package/src/server/billing/index.ts +6 -0
- package/src/server/billing/routes.ts +27 -0
- package/src/server/billing/tokens.ts +37 -0
- package/src/server/cleanup/configured.ts +16 -3
- package/src/server/cleanup/worker.ts +10 -1
- package/src/server/collaboration/relay/hub.ts +25 -142
- package/src/server/collaboration/relay/room.ts +154 -0
- package/src/server/collaboration/service.ts +21 -2
- package/src/server/community/index.ts +2 -0
- package/src/server/community/routes.ts +93 -0
- package/src/server/community/service.ts +134 -0
- package/src/server/config/deployment.ts +17 -5
- package/src/server/config/index.ts +1 -1
- package/src/server/config/public.ts +7 -1
- package/src/server/config/schema.ts +40 -292
- package/src/server/config/toml/schema.ts +307 -0
- package/src/server/db/index.ts +1 -0
- package/src/server/db/migrate.ts +13 -1
- package/src/server/db/migrations/009_access_tokens.ts +47 -0
- package/src/server/db/migrations/010_storage_limit_notices.ts +50 -0
- package/src/server/db/migrations/011_account_ids.ts +30 -0
- package/src/server/db/migrations/012_email_locales.ts +34 -0
- package/src/server/db/migrations/013_document_block_emails.ts +40 -0
- package/src/server/db/migrations/014_report_replies.ts +28 -0
- package/src/server/db/migrations/schema.ts +26 -1
- package/src/server/db/tables.ts +30 -1
- package/src/server/db/users.ts +22 -0
- package/src/server/documents/index.ts +1 -1
- package/src/server/documents/limits.ts +7 -1
- package/src/server/documents/service.ts +12 -402
- package/src/server/documents/uploads.ts +450 -0
- package/src/server/documents/versions/service.ts +81 -24
- package/src/server/email/invitations.ts +1 -0
- package/src/server/email/service.ts +31 -4
- package/src/server/email/types.ts +12 -0
- package/src/server/errors/index.ts +1 -9
- package/src/server/index.ts +12 -5
- package/src/server/invitations/types.ts +5 -1
- package/src/server/objects/types.ts +5 -0
- package/src/server/policy/configured.ts +9 -3
- package/src/server/policy/database.ts +13 -2
- package/src/server/policy/policy.ts +39 -12
- package/src/server/policy/service.ts +71 -52
- package/src/server/policy/storage.ts +33 -0
- package/src/server/quota/index.ts +6 -0
- package/src/server/quota/notices.ts +121 -0
- package/src/server/quota/storage.ts +5 -0
- package/src/server/rate-limit/middleware.ts +4 -0
- package/src/server/reports/index.ts +1 -0
- package/src/server/reports/replies.ts +55 -0
- package/src/server/reports/routes.ts +3 -1
- package/src/server/reports/service.ts +24 -2
- package/src/server/sharing/capabilities/service.ts +2 -3
- package/src/server/sharing/invitations/service.ts +14 -4
- package/src/server/validation.ts +3 -0
- package/src/server/workspaces/members.ts +7 -19
- package/src/services/app.ts +1 -3
- package/src/services/config.ts +1 -0
- package/src/services/usage.ts +6 -14
- package/src/email/templates/document-invitation.ts +0 -35
- package/src/email/templates/enrollment.ts +0 -27
- package/src/email/templates/layout.ts +0 -18
- package/src/server/app.ts +0 -453
- /package/src/{server/errors → errors}/posthog.ts +0 -0
package/src/email/render.ts
CHANGED
|
@@ -1,302 +1,168 @@
|
|
|
1
1
|
import { render } from '@vue-email/render'
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import type { Component } from 'vue'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
emailLocalization,
|
|
6
|
+
type EmailLocale,
|
|
7
|
+
type EmailLocalization,
|
|
8
|
+
type EmailMessages
|
|
9
|
+
} from './i18n'
|
|
4
10
|
import type {
|
|
5
|
-
AdminEnrollmentNotificationPayload,
|
|
6
|
-
AuthenticationEmailPayload,
|
|
7
11
|
DocumentInvitationEmailPayload,
|
|
8
|
-
DocumentReportPayload,
|
|
9
|
-
EmailChangeRequestedPayload,
|
|
10
|
-
EnrollmentEmailPayload,
|
|
11
|
-
NewSignInPayload,
|
|
12
12
|
RenderedTransactionalEmail,
|
|
13
13
|
TransactionalEmailContent,
|
|
14
14
|
TransactionalEmailKind,
|
|
15
|
-
|
|
16
|
-
TwoStepChangedPayload,
|
|
17
|
-
WorkspaceInvitationEmailPayload
|
|
15
|
+
TransactionalEmailPayloadByKind
|
|
18
16
|
} from './schema'
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
type EnrollmentMessageKind = Exclude<
|
|
68
|
-
TransactionalEmailKind,
|
|
69
|
-
| 'document-invitation'
|
|
70
|
-
| 'workspace-invitation'
|
|
71
|
-
| 'admin-enrollment-notification'
|
|
72
|
-
| 'email-verification'
|
|
73
|
-
| 'password-reset'
|
|
74
|
-
| 'password-changed'
|
|
75
|
-
| 'email-change-requested'
|
|
76
|
-
| 'new-sign-in'
|
|
77
|
-
| 'two-step-changed'
|
|
78
|
-
| 'document-report'
|
|
79
|
-
>
|
|
80
|
-
|
|
81
|
-
type EnrollmentCopy = {
|
|
82
|
-
subject: string
|
|
83
|
-
heading: string
|
|
84
|
-
preview: string
|
|
85
|
-
message: string
|
|
86
|
-
actionLabel: string
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const ENROLLMENT_COPY: Record<EnrollmentMessageKind, Omit<EnrollmentCopy, 'message'>> = {
|
|
17
|
+
import DocumentBlocked from './templates/DocumentBlocked.vue'
|
|
18
|
+
import DocumentInvitation from './templates/DocumentInvitation.vue'
|
|
19
|
+
import DocumentReport from './templates/DocumentReport.vue'
|
|
20
|
+
import DocumentReportDecided from './templates/DocumentReportDecided.vue'
|
|
21
|
+
import DocumentReportReceived from './templates/DocumentReportReceived.vue'
|
|
22
|
+
import DocumentRestored from './templates/DocumentRestored.vue'
|
|
23
|
+
import EmailChangeRequested from './templates/EmailChangeRequested.vue'
|
|
24
|
+
import EmailRoot from './templates/EmailRoot.vue'
|
|
25
|
+
import EmailVerification from './templates/EmailVerification.vue'
|
|
26
|
+
import EnrollmentNotification from './templates/EnrollmentNotification.vue'
|
|
27
|
+
import EnrollmentUpdate from './templates/EnrollmentUpdate.vue'
|
|
28
|
+
import NewSignIn from './templates/NewSignIn.vue'
|
|
29
|
+
import PasswordChanged from './templates/PasswordChanged.vue'
|
|
30
|
+
import PasswordReset from './templates/PasswordReset.vue'
|
|
31
|
+
import StorageLimitReached from './templates/StorageLimitReached.vue'
|
|
32
|
+
import TwoStepChanged from './templates/TwoStepChanged.vue'
|
|
33
|
+
import WaitlistConfirmation from './templates/WaitlistConfirmation.vue'
|
|
34
|
+
import WorkspaceInvitation from './templates/WorkspaceInvitation.vue'
|
|
35
|
+
|
|
36
|
+
/** One kind of email: the component that draws it from its payload, and its subject line. */
|
|
37
|
+
type EmailDefinition<Payload> = {
|
|
38
|
+
component: Component
|
|
39
|
+
/** What the component takes besides `payload`. */
|
|
40
|
+
props?: Record<string, unknown>
|
|
41
|
+
subject: (payload: Payload, t: EmailMessages) => string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function documentInvitationSubject(payload: DocumentInvitationEmailPayload, t: EmailMessages) {
|
|
45
|
+
const names = { inviter: payload.inviterName ?? t.someone, document: payload.documentName }
|
|
46
|
+
return payload.permission === 'edit'
|
|
47
|
+
? t.documentInvitationEditSubject(names)
|
|
48
|
+
: t.documentInvitationViewSubject(names)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const EMAILS: {
|
|
52
|
+
[Kind in TransactionalEmailKind]: EmailDefinition<TransactionalEmailPayloadByKind[Kind]>
|
|
53
|
+
} = {
|
|
54
|
+
'document-invitation': { component: DocumentInvitation, subject: documentInvitationSubject },
|
|
55
|
+
'workspace-invitation': {
|
|
56
|
+
component: WorkspaceInvitation,
|
|
57
|
+
subject: (payload, t) =>
|
|
58
|
+
t.workspaceInvitationSubject({
|
|
59
|
+
inviter: payload.inviterName ?? t.someone,
|
|
60
|
+
workspace: payload.workspaceName
|
|
61
|
+
})
|
|
62
|
+
},
|
|
90
63
|
'enrollment-requested': {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
actionLabel: 'Open OpenPencil Cloud'
|
|
64
|
+
component: EnrollmentUpdate,
|
|
65
|
+
props: { kind: 'requested' },
|
|
66
|
+
subject: (_payload, t) => t.enrollmentRequestedSubject
|
|
95
67
|
},
|
|
96
68
|
'enrollment-approved': {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
actionLabel: 'Sign in'
|
|
69
|
+
component: EnrollmentUpdate,
|
|
70
|
+
props: { kind: 'approved' },
|
|
71
|
+
subject: (_payload, t) => t.enrollmentApprovedSubject
|
|
101
72
|
},
|
|
102
73
|
'enrollment-rejected': {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
actionLabel: 'Request access again'
|
|
74
|
+
component: EnrollmentUpdate,
|
|
75
|
+
props: { kind: 'rejected' },
|
|
76
|
+
subject: (_payload, t) => t.enrollmentRejectedSubject
|
|
107
77
|
},
|
|
108
78
|
'enrollment-revoked': {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
async function renderAdminNotification(payload: AdminEnrollmentNotificationPayload) {
|
|
133
|
-
return rendered(
|
|
134
|
-
EnrollmentEmail,
|
|
135
|
-
{
|
|
136
|
-
heading: 'New Cloud access request',
|
|
137
|
-
preview: `${payload.requesterEmail} requested OpenPencil Cloud access.`,
|
|
138
|
-
message: `${payload.requesterName} (${payload.requesterEmail}) requested access. ${payload.reason}`,
|
|
139
|
-
actionLabel: 'Review request',
|
|
140
|
-
actionURL: payload.actionURL
|
|
141
|
-
},
|
|
142
|
-
'New OpenPencil Cloud access request'
|
|
143
|
-
)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const REPORT_REASON_LABELS: Record<string, string> = {
|
|
147
|
-
'spam-phishing': 'spam or phishing',
|
|
148
|
-
illegal: 'illegal content',
|
|
149
|
-
copyright: 'copyright',
|
|
150
|
-
harassment: 'harassment',
|
|
151
|
-
other: 'something else'
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
async function renderDocumentReport(payload: DocumentReportPayload) {
|
|
155
|
-
const reason = REPORT_REASON_LABELS[payload.reason] ?? payload.reason
|
|
156
|
-
return rendered(
|
|
157
|
-
EnrollmentEmail,
|
|
158
|
-
{
|
|
159
|
-
heading: 'A shared document was reported',
|
|
160
|
-
preview: `“${payload.documentName}” was reported for ${reason}.`,
|
|
161
|
-
message: `Someone who opened “${payload.documentName}” from a share link reported it for ${reason}: ${payload.description}`,
|
|
162
|
-
actionLabel: 'Review report',
|
|
163
|
-
actionURL: payload.actionURL
|
|
164
|
-
},
|
|
165
|
-
'A shared OpenPencil Cloud document was reported'
|
|
166
|
-
)
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
async function renderAuthentication(
|
|
170
|
-
kind: 'email-verification' | 'password-reset' | 'password-changed',
|
|
171
|
-
payload: AuthenticationEmailPayload
|
|
172
|
-
) {
|
|
173
|
-
const copy = {
|
|
174
|
-
'email-verification':
|
|
175
|
-
payload.purpose === 'change'
|
|
176
|
-
? {
|
|
177
|
-
subject: 'Confirm your new OpenPencil Cloud email',
|
|
178
|
-
heading: 'Confirm your new email',
|
|
179
|
-
preview: 'One click to move your OpenPencil Cloud account to this address.',
|
|
180
|
-
message: `Hi ${payload.name}, confirm this address to make it your OpenPencil Cloud account’s email. Your old address stays until you do.`,
|
|
181
|
-
actionLabel: 'Confirm email',
|
|
182
|
-
footer: 'Didn’t ask for this? Ignore this email and nothing changes.'
|
|
183
|
-
}
|
|
184
|
-
: {
|
|
185
|
-
subject: 'Confirm your OpenPencil Cloud email',
|
|
186
|
-
heading: 'Confirm your email',
|
|
187
|
-
preview: 'One click to finish creating your OpenPencil Cloud account.',
|
|
188
|
-
message: `Hi ${payload.name}, confirm this address to finish creating your OpenPencil Cloud account. Then go back to OpenPencil; it signs you in by itself.`,
|
|
189
|
-
actionLabel: 'Confirm email',
|
|
190
|
-
footer: 'Didn’t create an account? Ignore this email and nothing happens.'
|
|
191
|
-
},
|
|
192
|
-
'password-reset': {
|
|
193
|
-
subject: 'Reset your OpenPencil Cloud password',
|
|
194
|
-
heading: 'Reset your password',
|
|
195
|
-
preview: 'Use this secure link to choose a new password.',
|
|
196
|
-
message: `Hi ${payload.name}, use the link below to choose a new password.`,
|
|
197
|
-
actionLabel: 'Reset password',
|
|
198
|
-
footer: 'Didn’t ask for this? Ignore this email and your password stays the same.'
|
|
199
|
-
},
|
|
200
|
-
'password-changed': {
|
|
201
|
-
subject: 'Your OpenPencil Cloud password changed',
|
|
202
|
-
heading: 'Password changed',
|
|
203
|
-
preview: 'Your OpenPencil Cloud password was changed.',
|
|
204
|
-
message: `Hi ${payload.name}, your password was changed. If this was not you, contact your administrator.`,
|
|
205
|
-
actionLabel: 'Open OpenPencil Cloud'
|
|
206
|
-
}
|
|
207
|
-
}[kind]
|
|
208
|
-
return rendered(EnrollmentEmail, { ...copy, actionURL: payload.actionURL ?? '#' }, copy.subject)
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
async function renderEmailChangeRequested(payload: EmailChangeRequestedPayload) {
|
|
212
|
-
return rendered(
|
|
213
|
-
EnrollmentEmail,
|
|
214
|
-
{
|
|
215
|
-
heading: 'Your email is changing',
|
|
216
|
-
preview: `Your OpenPencil Cloud email is changing to ${payload.newEmail}.`,
|
|
217
|
-
message: `Hi ${payload.name}, someone signed in to your account asked to change its email to ${payload.newEmail}. It changes once that address confirms it. If this wasn’t you, change your password and sign out of your other sessions.`,
|
|
218
|
-
actionLabel: 'Review your account',
|
|
219
|
-
actionURL: payload.actionURL
|
|
220
|
-
},
|
|
221
|
-
'Your OpenPencil Cloud email is changing'
|
|
222
|
-
)
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
async function renderNewSignIn(payload: NewSignInPayload) {
|
|
226
|
-
const device = payload.desktop
|
|
227
|
-
? 'the OpenPencil app'
|
|
228
|
-
: compact([payload.browser, payload.system]).join(' on ') || 'an unknown browser'
|
|
229
|
-
const place = payload.ipAddress ? ` from ${payload.ipAddress}` : ''
|
|
230
|
-
return rendered(
|
|
231
|
-
EnrollmentEmail,
|
|
232
|
-
{
|
|
233
|
-
heading: 'New sign-in to your account',
|
|
234
|
-
preview: `Your OpenPencil Cloud account was signed in to with ${device}.`,
|
|
235
|
-
message: `Hi ${payload.name}, your account was signed in to with ${device}${place} on ${new Date(payload.signedInAt).toUTCString()}. If this was you, there’s nothing to do. If it wasn’t, sign that session out and change your password.`,
|
|
236
|
-
actionLabel: 'Review sessions',
|
|
237
|
-
actionURL: payload.actionURL
|
|
238
|
-
},
|
|
239
|
-
'New sign-in to your OpenPencil Cloud account'
|
|
240
|
-
)
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const TWO_STEP_COPY: Record<TwoStepChange, { heading: string; message: string }> = {
|
|
244
|
-
'authenticator-on': {
|
|
245
|
-
heading: 'Authenticator app turned on',
|
|
246
|
-
message: 'an authenticator app now confirms your sign-ins.'
|
|
79
|
+
component: EnrollmentUpdate,
|
|
80
|
+
props: { kind: 'revoked' },
|
|
81
|
+
subject: (_payload, t) => t.enrollmentRevokedSubject
|
|
82
|
+
},
|
|
83
|
+
'admin-enrollment-notification': {
|
|
84
|
+
component: EnrollmentNotification,
|
|
85
|
+
subject: (_payload, t) => t.enrollmentNotificationSubject
|
|
86
|
+
},
|
|
87
|
+
'email-verification': {
|
|
88
|
+
component: EmailVerification,
|
|
89
|
+
subject: (payload, t) =>
|
|
90
|
+
payload.purpose === 'change' ? t.verifyChangeSubject : t.verifyAccountSubject
|
|
91
|
+
},
|
|
92
|
+
'password-reset': { component: PasswordReset, subject: (_payload, t) => t.passwordResetSubject },
|
|
93
|
+
'password-changed': {
|
|
94
|
+
component: PasswordChanged,
|
|
95
|
+
subject: (_payload, t) => t.passwordChangedSubject
|
|
96
|
+
},
|
|
97
|
+
'email-change-requested': {
|
|
98
|
+
component: EmailChangeRequested,
|
|
99
|
+
subject: (_payload, t) => t.emailChangeSubject
|
|
247
100
|
},
|
|
248
|
-
'
|
|
249
|
-
|
|
250
|
-
|
|
101
|
+
'new-sign-in': { component: NewSignIn, subject: (_payload, t) => t.newSignInSubject },
|
|
102
|
+
'two-step-changed': { component: TwoStepChanged, subject: (_payload, t) => t.twoStepSubject },
|
|
103
|
+
'document-report': {
|
|
104
|
+
component: DocumentReport,
|
|
105
|
+
subject: (_payload, t) => t.documentReportSubject
|
|
251
106
|
},
|
|
252
|
-
'
|
|
253
|
-
|
|
254
|
-
|
|
107
|
+
'storage-limit-reached': {
|
|
108
|
+
component: StorageLimitReached,
|
|
109
|
+
subject: (_payload, t) => t.storageFullSubject
|
|
255
110
|
},
|
|
256
|
-
'
|
|
257
|
-
|
|
258
|
-
|
|
111
|
+
'document-blocked': {
|
|
112
|
+
component: DocumentBlocked,
|
|
113
|
+
subject: (payload, t) => t.documentBlockedSubject({ document: payload.documentName })
|
|
259
114
|
},
|
|
260
|
-
'
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
115
|
+
'document-restored': {
|
|
116
|
+
component: DocumentRestored,
|
|
117
|
+
subject: (payload, t) => t.documentRestoredSubject({ document: payload.documentName })
|
|
118
|
+
},
|
|
119
|
+
'document-report-received': {
|
|
120
|
+
component: DocumentReportReceived,
|
|
121
|
+
subject: (payload, t) => t.reportReceivedSubject({ document: payload.documentName })
|
|
122
|
+
},
|
|
123
|
+
'document-report-decided': {
|
|
124
|
+
component: DocumentReportDecided,
|
|
125
|
+
subject: (payload, t) => t.reportDecidedSubject({ document: payload.documentName })
|
|
264
126
|
}
|
|
265
127
|
}
|
|
266
128
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
129
|
+
/** Renders an email component as HTML and as plain text, in its reader's language. */
|
|
130
|
+
async function renderComponent(
|
|
131
|
+
email: Component,
|
|
132
|
+
props: Record<string, unknown>,
|
|
133
|
+
subject: string,
|
|
134
|
+
localization: EmailLocalization
|
|
135
|
+
): Promise<RenderedTransactionalEmail> {
|
|
136
|
+
const root = { email, props, localization }
|
|
137
|
+
const [html, text] = await Promise.all([
|
|
138
|
+
render(EmailRoot, root),
|
|
139
|
+
render(EmailRoot, root, { plainText: true })
|
|
140
|
+
])
|
|
141
|
+
return { subject, html, text }
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function renderKind<Kind extends TransactionalEmailKind>(
|
|
145
|
+
kind: Kind,
|
|
146
|
+
payload: TransactionalEmailPayloadByKind[Kind],
|
|
147
|
+
localization: EmailLocalization
|
|
148
|
+
) {
|
|
149
|
+
const { component, props, subject } = EMAILS[kind]
|
|
150
|
+
const content = { ...props, payload }
|
|
151
|
+
return renderComponent(component, content, subject(payload, localization.t), localization)
|
|
280
152
|
}
|
|
281
153
|
|
|
282
154
|
export async function renderTransactionalEmail(
|
|
283
|
-
content: TransactionalEmailContent
|
|
155
|
+
content: TransactionalEmailContent,
|
|
156
|
+
locale: EmailLocale
|
|
284
157
|
): Promise<RenderedTransactionalEmail> {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
)
|
|
295
|
-
return renderAuthentication(content.kind, content.payload)
|
|
296
|
-
}
|
|
297
|
-
if (content.kind === 'email-change-requested') return renderEmailChangeRequested(content.payload)
|
|
298
|
-
if (content.kind === 'new-sign-in') return renderNewSignIn(content.payload)
|
|
299
|
-
if (content.kind === 'two-step-changed') return renderTwoStepChanged(content.payload)
|
|
300
|
-
if (content.kind === 'document-report') return renderDocumentReport(content.payload)
|
|
301
|
-
return renderEnrollment(content.kind, content.payload)
|
|
158
|
+
return renderKind(content.kind, content.payload, emailLocalization(locale))
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** The waitlist's confirmation email, which the feedback service sends rather than Cloud. */
|
|
162
|
+
export async function renderWaitlistConfirmation(
|
|
163
|
+
links: { confirmURL: string; leaveURL: string },
|
|
164
|
+
locale: EmailLocale
|
|
165
|
+
): Promise<RenderedTransactionalEmail> {
|
|
166
|
+
const localization = emailLocalization(locale)
|
|
167
|
+
return renderComponent(WaitlistConfirmation, links, localization.t.waitlistSubject, localization)
|
|
302
168
|
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { TransactionalEmailContent } from './schema'
|
|
2
|
+
|
|
3
|
+
/** Where every sample's button goes. */
|
|
4
|
+
export const EMAIL_SAMPLE_URL = 'https://cloud.example.com/next'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One email of every kind, with every optional part filled, as previews and tests show them. Its
|
|
8
|
+
* names and addresses are made up.
|
|
9
|
+
*/
|
|
10
|
+
export const EMAIL_SAMPLES: TransactionalEmailContent[] = [
|
|
11
|
+
{
|
|
12
|
+
kind: 'document-invitation',
|
|
13
|
+
payload: {
|
|
14
|
+
inviterName: 'Ada',
|
|
15
|
+
documentName: 'Homepage',
|
|
16
|
+
permission: 'edit',
|
|
17
|
+
expiresAt: '2026-11-20T10:00:00.000Z',
|
|
18
|
+
acceptanceURL: EMAIL_SAMPLE_URL
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
kind: 'workspace-invitation',
|
|
23
|
+
payload: {
|
|
24
|
+
inviterName: null,
|
|
25
|
+
workspaceName: 'Studio',
|
|
26
|
+
role: 'viewer',
|
|
27
|
+
expiresAt: '2026-11-20T10:00:00.000Z',
|
|
28
|
+
acceptanceURL: EMAIL_SAMPLE_URL
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
...(
|
|
32
|
+
[
|
|
33
|
+
'enrollment-requested',
|
|
34
|
+
'enrollment-approved',
|
|
35
|
+
'enrollment-rejected',
|
|
36
|
+
'enrollment-revoked'
|
|
37
|
+
] as const
|
|
38
|
+
).map((kind): TransactionalEmailContent => ({
|
|
39
|
+
kind,
|
|
40
|
+
payload: { name: 'Ada', actionURL: EMAIL_SAMPLE_URL }
|
|
41
|
+
})),
|
|
42
|
+
{
|
|
43
|
+
kind: 'admin-enrollment-notification',
|
|
44
|
+
payload: {
|
|
45
|
+
requesterEmail: 'ada@example.com',
|
|
46
|
+
requesterName: 'Ada',
|
|
47
|
+
reason: 'Design',
|
|
48
|
+
actionURL: EMAIL_SAMPLE_URL
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
kind: 'email-verification',
|
|
53
|
+
payload: { name: 'Ada', actionURL: EMAIL_SAMPLE_URL, purpose: 'change' }
|
|
54
|
+
},
|
|
55
|
+
{ kind: 'password-reset', payload: { name: 'Ada', actionURL: EMAIL_SAMPLE_URL } },
|
|
56
|
+
{ kind: 'password-changed', payload: { name: 'Ada', actionURL: EMAIL_SAMPLE_URL } },
|
|
57
|
+
{
|
|
58
|
+
kind: 'email-change-requested',
|
|
59
|
+
payload: { name: 'Ada', newEmail: 'ada@new.example.com', actionURL: EMAIL_SAMPLE_URL }
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
kind: 'new-sign-in',
|
|
63
|
+
payload: {
|
|
64
|
+
name: 'Ada',
|
|
65
|
+
signedInAt: '2026-11-13T10:00:00.000Z',
|
|
66
|
+
ipAddress: '203.0.113.9',
|
|
67
|
+
browser: 'Firefox',
|
|
68
|
+
system: 'Linux',
|
|
69
|
+
desktop: false,
|
|
70
|
+
actionURL: EMAIL_SAMPLE_URL
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
kind: 'two-step-changed',
|
|
75
|
+
payload: { name: 'Ada', change: 'passkey-added', actionURL: EMAIL_SAMPLE_URL }
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
kind: 'document-report',
|
|
79
|
+
payload: {
|
|
80
|
+
documentName: 'Homepage',
|
|
81
|
+
reason: 'copyright',
|
|
82
|
+
description: 'Copied',
|
|
83
|
+
actionURL: EMAIL_SAMPLE_URL
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
kind: 'storage-limit-reached',
|
|
88
|
+
payload: {
|
|
89
|
+
name: 'Ada',
|
|
90
|
+
usedBytes: 310 * 1024 ** 2,
|
|
91
|
+
limitBytes: 300 * 1024 ** 2,
|
|
92
|
+
upgradable: true,
|
|
93
|
+
actionURL: EMAIL_SAMPLE_URL
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
kind: 'document-blocked',
|
|
98
|
+
payload: {
|
|
99
|
+
name: 'Ada',
|
|
100
|
+
documentName: 'Homepage',
|
|
101
|
+
reason: 'Phishing page imitating a bank',
|
|
102
|
+
contactEmail: 'abuse@example.com',
|
|
103
|
+
actionURL: EMAIL_SAMPLE_URL
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
kind: 'document-restored',
|
|
108
|
+
payload: { name: 'Ada', documentName: 'Homepage', actionURL: EMAIL_SAMPLE_URL }
|
|
109
|
+
},
|
|
110
|
+
{ kind: 'document-report-received', payload: { documentName: 'Homepage' } },
|
|
111
|
+
{
|
|
112
|
+
kind: 'document-report-decided',
|
|
113
|
+
payload: { documentName: 'Homepage', outcome: 'blocked', contactEmail: 'abuse@example.com' }
|
|
114
|
+
}
|
|
115
|
+
]
|