@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.
Files changed (206) hide show
  1. package/README.md +2 -1
  2. package/dist/bin/server.mjs +1 -1
  3. package/dist/bin/server.mjs.map +1 -1
  4. package/dist/bin/services.mjs +1 -1
  5. package/dist/bin/services.mjs.map +1 -1
  6. package/dist/client.d.ts +296 -27
  7. package/dist/client.d.ts.map +1 -1
  8. package/dist/client.js +649 -295
  9. package/dist/client.js.map +1 -1
  10. package/dist/contract.d.ts +2 -2
  11. package/dist/contract.js +2 -2
  12. package/dist/contract2.js +331 -21
  13. package/dist/contract2.js.map +1 -1
  14. package/dist/email.d.ts +1773 -32
  15. package/dist/email.d.ts.map +1 -1
  16. package/dist/email.js +3478 -288
  17. package/dist/email.js.map +1 -1
  18. package/dist/errors.d.ts +2 -0
  19. package/dist/errors.js +48 -0
  20. package/dist/errors.js.map +1 -0
  21. package/dist/index.d.ts +466 -13
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index2.d.ts +35 -0
  24. package/dist/index2.d.ts.map +1 -0
  25. package/dist/listen.mjs +447 -290
  26. package/dist/listen.mjs.map +1 -1
  27. package/dist/runtime-cloudflare.d.ts +89 -0
  28. package/dist/runtime-cloudflare.d.ts.map +1 -0
  29. package/dist/runtime-cloudflare.js +15667 -0
  30. package/dist/runtime-cloudflare.js.map +1 -0
  31. package/dist/runtime-node.d.mts +2963 -294
  32. package/dist/runtime-node.d.mts.map +1 -1
  33. package/dist/server.d.ts +3473 -842
  34. package/dist/server.d.ts.map +1 -1
  35. package/dist/server.js +12187 -8244
  36. package/dist/server.js.map +1 -1
  37. package/dist/server.mjs +7739 -3548
  38. package/dist/server.mjs.map +1 -1
  39. package/dist/server2.mjs +5 -5
  40. package/dist/server2.mjs.map +1 -1
  41. package/package.json +22 -5
  42. package/src/admin/audit/service.ts +2 -2
  43. package/src/admin/documents/service.ts +76 -6
  44. package/src/admin/reports/service.ts +7 -1
  45. package/src/client/api.ts +23 -471
  46. package/src/client/auth/client.ts +22 -3
  47. package/src/client/billing.ts +80 -0
  48. package/src/client/community.ts +40 -0
  49. package/src/client/discovery.ts +35 -9
  50. package/src/client/documents.ts +160 -0
  51. package/src/client/index.ts +7 -0
  52. package/src/client/portal/account.ts +54 -2
  53. package/src/client/portal/request.ts +2 -0
  54. package/src/client/response.ts +21 -0
  55. package/src/client/schema.ts +8 -0
  56. package/src/client/services.ts +23 -18
  57. package/src/client/sharing.ts +262 -0
  58. package/src/client/versions.ts +104 -0
  59. package/src/contract/account.ts +50 -0
  60. package/src/contract/billing.ts +166 -0
  61. package/src/contract/collaboration.ts +5 -0
  62. package/src/contract/community.ts +60 -0
  63. package/src/contract/discovery.ts +63 -2
  64. package/src/contract/entitlements.ts +10 -0
  65. package/src/contract/index.ts +54 -5
  66. package/src/contract/links.ts +57 -4
  67. package/src/contract/locale.ts +27 -0
  68. package/src/contract/portal.ts +12 -1
  69. package/src/contract/routes.ts +10 -0
  70. package/src/contract/services.ts +18 -16
  71. package/src/email/i18n.ts +174 -0
  72. package/src/email/index.ts +13 -2
  73. package/src/email/locales/ar.json +141 -0
  74. package/src/email/locales/de.json +141 -0
  75. package/src/email/locales/es.json +141 -0
  76. package/src/email/locales/fr.json +141 -0
  77. package/src/email/locales/it.json +141 -0
  78. package/src/email/locales/ja.json +141 -0
  79. package/src/email/locales/pl.json +141 -0
  80. package/src/email/locales/pt-br.json +141 -0
  81. package/src/email/locales/ru.json +141 -0
  82. package/src/email/locales/zh-cn.json +141 -0
  83. package/src/email/messages.ts +200 -0
  84. package/src/email/render.ts +142 -276
  85. package/src/email/samples.ts +115 -0
  86. package/src/email/schema.ts +70 -6
  87. package/src/email/templates/BrandEmail.vue +54 -0
  88. package/src/email/templates/DocumentBlocked.vue +45 -0
  89. package/src/email/templates/DocumentInvitation.vue +24 -0
  90. package/src/email/templates/DocumentReport.vue +32 -0
  91. package/src/email/templates/DocumentReportDecided.vue +36 -0
  92. package/src/email/templates/DocumentReportReceived.vue +18 -0
  93. package/src/email/templates/DocumentRestored.vue +24 -0
  94. package/src/email/templates/EmailChangeRequested.vue +24 -0
  95. package/src/email/templates/EmailRoot.vue +19 -0
  96. package/src/email/templates/EmailText.vue +9 -0
  97. package/src/email/templates/EmailVerification.vue +38 -0
  98. package/src/email/templates/EnrollmentNotification.vue +24 -0
  99. package/src/email/templates/EnrollmentUpdate.vue +52 -0
  100. package/src/email/templates/NewSignIn.vue +37 -0
  101. package/src/email/templates/PasswordChanged.vue +22 -0
  102. package/src/email/templates/PasswordReset.vue +23 -0
  103. package/src/email/templates/StorageLimitReached.vue +28 -0
  104. package/src/email/templates/TwoStepChanged.vue +32 -0
  105. package/src/email/templates/WaitlistConfirmation.vue +29 -0
  106. package/src/email/templates/WorkspaceInvitation.vue +28 -0
  107. package/src/email/templates/brand.ts +9 -61
  108. package/src/email/templates/localization.ts +17 -0
  109. package/src/errors/index.ts +6 -0
  110. package/src/global.d.ts +7 -0
  111. package/src/runtime/cloudflare/relay/index.ts +7 -1
  112. package/src/runtime/cloudflare/tsconfig.json +2 -1
  113. package/src/runtime/cloudflare/worker.ts +8 -1
  114. package/src/runtime/node/cleanup.ts +5 -1
  115. package/src/runtime/node/email/transport.ts +13 -10
  116. package/src/runtime/node/main.ts +1 -1
  117. package/src/runtime/node/server.ts +12 -2
  118. package/src/runtime/node/services/main.ts +1 -1
  119. package/src/runtime/posthog/errors.ts +2 -1
  120. package/src/runtime/s3/objects.ts +17 -0
  121. package/src/runtime/site/community.ts +101 -0
  122. package/src/runtime/site/server.ts +17 -1
  123. package/src/server/account/deletion.ts +2 -0
  124. package/src/server/account/routes.ts +271 -240
  125. package/src/server/account/tokens.ts +57 -0
  126. package/src/server/api/router.ts +23 -0
  127. package/src/server/app/checks.ts +84 -0
  128. package/src/server/app/editors.ts +20 -0
  129. package/src/server/app/index.ts +128 -0
  130. package/src/server/app/indexing.ts +40 -0
  131. package/src/server/app/limiters.ts +53 -0
  132. package/src/server/app/routes.ts +114 -0
  133. package/src/server/app/services.ts +185 -0
  134. package/src/server/auth/access-tokens.ts +62 -0
  135. package/src/server/auth/adapter.ts +21 -1
  136. package/src/server/auth/email.ts +4 -1
  137. package/src/server/auth/enrollment.ts +116 -0
  138. package/src/server/auth/factory.ts +88 -131
  139. package/src/server/auth/logger.ts +23 -0
  140. package/src/server/auth/mfa-assurance.ts +51 -0
  141. package/src/server/auth/passwords.ts +43 -0
  142. package/src/server/auth/session.ts +2 -0
  143. package/src/server/billing/index.ts +6 -0
  144. package/src/server/billing/routes.ts +27 -0
  145. package/src/server/billing/tokens.ts +37 -0
  146. package/src/server/cleanup/configured.ts +16 -3
  147. package/src/server/cleanup/worker.ts +10 -1
  148. package/src/server/collaboration/relay/hub.ts +25 -142
  149. package/src/server/collaboration/relay/room.ts +154 -0
  150. package/src/server/collaboration/service.ts +21 -2
  151. package/src/server/community/index.ts +2 -0
  152. package/src/server/community/routes.ts +93 -0
  153. package/src/server/community/service.ts +134 -0
  154. package/src/server/config/deployment.ts +17 -5
  155. package/src/server/config/index.ts +1 -1
  156. package/src/server/config/public.ts +7 -1
  157. package/src/server/config/schema.ts +40 -292
  158. package/src/server/config/toml/schema.ts +307 -0
  159. package/src/server/db/index.ts +1 -0
  160. package/src/server/db/migrate.ts +13 -1
  161. package/src/server/db/migrations/009_access_tokens.ts +47 -0
  162. package/src/server/db/migrations/010_storage_limit_notices.ts +50 -0
  163. package/src/server/db/migrations/011_account_ids.ts +30 -0
  164. package/src/server/db/migrations/012_email_locales.ts +34 -0
  165. package/src/server/db/migrations/013_document_block_emails.ts +40 -0
  166. package/src/server/db/migrations/014_report_replies.ts +28 -0
  167. package/src/server/db/migrations/schema.ts +26 -1
  168. package/src/server/db/tables.ts +30 -1
  169. package/src/server/db/users.ts +22 -0
  170. package/src/server/documents/index.ts +1 -1
  171. package/src/server/documents/limits.ts +7 -1
  172. package/src/server/documents/service.ts +12 -402
  173. package/src/server/documents/uploads.ts +450 -0
  174. package/src/server/documents/versions/service.ts +81 -24
  175. package/src/server/email/invitations.ts +1 -0
  176. package/src/server/email/service.ts +31 -4
  177. package/src/server/email/types.ts +12 -0
  178. package/src/server/errors/index.ts +1 -9
  179. package/src/server/index.ts +12 -5
  180. package/src/server/invitations/types.ts +5 -1
  181. package/src/server/objects/types.ts +5 -0
  182. package/src/server/policy/configured.ts +9 -3
  183. package/src/server/policy/database.ts +13 -2
  184. package/src/server/policy/policy.ts +39 -12
  185. package/src/server/policy/service.ts +71 -52
  186. package/src/server/policy/storage.ts +33 -0
  187. package/src/server/quota/index.ts +6 -0
  188. package/src/server/quota/notices.ts +121 -0
  189. package/src/server/quota/storage.ts +5 -0
  190. package/src/server/rate-limit/middleware.ts +4 -0
  191. package/src/server/reports/index.ts +1 -0
  192. package/src/server/reports/replies.ts +55 -0
  193. package/src/server/reports/routes.ts +3 -1
  194. package/src/server/reports/service.ts +24 -2
  195. package/src/server/sharing/capabilities/service.ts +2 -3
  196. package/src/server/sharing/invitations/service.ts +14 -4
  197. package/src/server/validation.ts +3 -0
  198. package/src/server/workspaces/members.ts +7 -19
  199. package/src/services/app.ts +1 -3
  200. package/src/services/config.ts +1 -0
  201. package/src/services/usage.ts +6 -14
  202. package/src/email/templates/document-invitation.ts +0 -35
  203. package/src/email/templates/enrollment.ts +0 -27
  204. package/src/email/templates/layout.ts +0 -18
  205. package/src/server/app.ts +0 -453
  206. /package/src/{server/errors → errors}/posthog.ts +0 -0
@@ -1,302 +1,168 @@
1
1
  import { render } from '@vue-email/render'
2
- import { compact } from 'es-toolkit'
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
- TwoStepChange,
16
- TwoStepChangedPayload,
17
- WorkspaceInvitationEmailPayload
15
+ TransactionalEmailPayloadByKind
18
16
  } from './schema'
19
- import { DocumentInvitationEmail } from './templates/document-invitation'
20
- import { EnrollmentEmail } from './templates/enrollment'
21
-
22
- async function rendered(
23
- component: Parameters<typeof render>[0],
24
- props: Record<string, string | undefined>,
25
- subject: string
26
- ): Promise<RenderedTransactionalEmail> {
27
- const [html, text] = await Promise.all([
28
- render(component, props),
29
- render(component, props, { plainText: true })
30
- ])
31
- return { subject, html, text }
32
- }
33
-
34
- async function renderDocumentInvitation(payload: DocumentInvitationEmailPayload) {
35
- const permissionLabel = payload.permission === 'edit' ? 'edit' : 'view'
36
- return rendered(
37
- DocumentInvitationEmail,
38
- {
39
- inviterName: payload.inviterName,
40
- documentName: payload.documentName,
41
- permissionLabel,
42
- expiresAt: new Date(payload.expiresAt).toUTCString(),
43
- acceptanceURL: payload.acceptanceURL
44
- },
45
- `${payload.inviterName} invited you to ${permissionLabel} ${payload.documentName}`
46
- )
47
- }
48
-
49
- const WORKSPACE_ROLE_LABELS = { admin: 'manage', editor: 'edit in', viewer: 'view' } as const
50
-
51
- async function renderWorkspaceInvitation(payload: WorkspaceInvitationEmailPayload) {
52
- const action = WORKSPACE_ROLE_LABELS[payload.role]
53
- return rendered(
54
- EnrollmentEmail,
55
- {
56
- heading: `Join ${payload.workspaceName}`,
57
- preview: `${payload.inviterName} invited you to ${payload.workspaceName}`,
58
- message: `${payload.inviterName} invited you to ${action} the workspace “${payload.workspaceName}” on OpenPencil Cloud. You will see its documents on Home once you join.`,
59
- actionLabel: 'Join workspace',
60
- actionURL: payload.acceptanceURL,
61
- footer: `This invitation expires ${new Date(payload.expiresAt).toUTCString()}.`
62
- },
63
- `${payload.inviterName} invited you to ${payload.workspaceName}`
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
- subject: 'We received your OpenPencil Cloud request',
92
- heading: 'Request received',
93
- preview: 'Your OpenPencil Cloud access request is awaiting review.',
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
- subject: 'Your OpenPencil Cloud access is ready',
98
- heading: 'Access approved',
99
- preview: 'You can now sign in to OpenPencil Cloud.',
100
- actionLabel: 'Sign in'
69
+ component: EnrollmentUpdate,
70
+ props: { kind: 'approved' },
71
+ subject: (_payload, t) => t.enrollmentApprovedSubject
101
72
  },
102
73
  'enrollment-rejected': {
103
- subject: 'Your OpenPencil Cloud request was reviewed',
104
- heading: 'Request reviewed',
105
- preview: 'Your current access request was not approved.',
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
- subject: 'Your OpenPencil Cloud access has changed',
110
- heading: 'Access changed',
111
- preview: 'Your OpenPencil Cloud access is no longer active.',
112
- actionLabel: 'Open OpenPencil'
113
- }
114
- }
115
-
116
- function enrollmentCopy(kind: EnrollmentMessageKind, name: string): EnrollmentCopy {
117
- const copy = ENROLLMENT_COPY[kind]
118
- const messages: Record<EnrollmentMessageKind, string> = {
119
- 'enrollment-requested': `Hi ${name}, your request is awaiting manual review.`,
120
- 'enrollment-approved': `Hi ${name}, your access request was approved.`,
121
- 'enrollment-rejected': `Hi ${name}, your current access request was not approved.`,
122
- 'enrollment-revoked': `Hi ${name}, your Cloud access is no longer active.`
123
- }
124
- return { ...copy, message: messages[kind] }
125
- }
126
-
127
- async function renderEnrollment(kind: EnrollmentMessageKind, payload: EnrollmentEmailPayload) {
128
- const copy = enrollmentCopy(kind, payload.name)
129
- return rendered(EnrollmentEmail, { ...copy, actionURL: payload.actionURL }, copy.subject)
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
- 'authenticator-off': {
249
- heading: 'Authenticator app turned off',
250
- message: 'your sign-ins no longer ask for a code from an authenticator app.'
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
- 'passkey-added': {
253
- heading: 'Passkey added',
254
- message: 'a passkey was added to your account.'
107
+ 'storage-limit-reached': {
108
+ component: StorageLimitReached,
109
+ subject: (_payload, t) => t.storageFullSubject
255
110
  },
256
- 'passkey-removed': {
257
- heading: 'Passkey removed',
258
- message: 'a passkey was removed from your account.'
111
+ 'document-blocked': {
112
+ component: DocumentBlocked,
113
+ subject: (payload, t) => t.documentBlockedSubject({ document: payload.documentName })
259
114
  },
260
- 'reset-by-administrator': {
261
- heading: 'Two-step sign-in was reset',
262
- message:
263
- 'an administrator removed your authenticator app, recovery codes, and passkeys, so you can set them up again.'
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
- async function renderTwoStepChanged(payload: TwoStepChangedPayload) {
268
- const copy = TWO_STEP_COPY[payload.change]
269
- return rendered(
270
- EnrollmentEmail,
271
- {
272
- heading: copy.heading,
273
- preview: `${copy.heading} on your OpenPencil Cloud account.`,
274
- message: `Hi ${payload.name}, ${copy.message} If this wasn’t you, change your password and contact your administrator.`,
275
- actionLabel: 'Review security',
276
- actionURL: payload.actionURL
277
- },
278
- `${copy.heading} on your OpenPencil Cloud account`
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
- if (content.kind === 'document-invitation') return renderDocumentInvitation(content.payload)
286
- if (content.kind === 'workspace-invitation') return renderWorkspaceInvitation(content.payload)
287
- if (content.kind === 'admin-enrollment-notification') {
288
- return renderAdminNotification(content.payload)
289
- }
290
- if (
291
- content.kind === 'email-verification' ||
292
- content.kind === 'password-reset' ||
293
- content.kind === 'password-changed'
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
+ ]