@open-pencil/cloud 0.17.0-beta.4 → 0.17.0-beta.6

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 (280) 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 +783 -47
  7. package/dist/client.d.ts.map +1 -1
  8. package/dist/client.js +1651 -382
  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 +701 -45
  13. package/dist/contract2.js.map +1 -1
  14. package/dist/email.d.ts +2138 -34
  15. package/dist/email.d.ts.map +1 -1
  16. package/dist/email.js +4343 -306
  17. package/dist/email.js.map +1 -1
  18. package/dist/errors.d.ts +2 -0
  19. package/dist/errors.js +61 -0
  20. package/dist/errors.js.map +1 -0
  21. package/dist/index.d.ts +1338 -44
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index2.d.ts +45 -0
  24. package/dist/index2.d.ts.map +1 -0
  25. package/dist/listen.mjs +958 -340
  26. package/dist/listen.mjs.map +1 -1
  27. package/dist/runtime-cloudflare.d.ts +93 -0
  28. package/dist/runtime-cloudflare.d.ts.map +1 -0
  29. package/dist/runtime-cloudflare.js +18032 -0
  30. package/dist/runtime-cloudflare.js.map +1 -0
  31. package/dist/runtime-node.d.mts +12615 -5249
  32. package/dist/runtime-node.d.mts.map +1 -1
  33. package/dist/server.d.ts +17367 -8567
  34. package/dist/server.d.ts.map +1 -1
  35. package/dist/server.js +13587 -7333
  36. package/dist/server.js.map +1 -1
  37. package/dist/server.mjs +11601 -5401
  38. package/dist/server.mjs.map +1 -1
  39. package/dist/server2.mjs +84 -62
  40. package/dist/server2.mjs.map +1 -1
  41. package/package.json +31 -5
  42. package/src/admin/api/routes.ts +263 -190
  43. package/src/admin/audit/service.ts +11 -3
  44. package/src/admin/bootstrap.ts +86 -0
  45. package/src/admin/documents/service.ts +195 -10
  46. package/src/admin/email/service.ts +2 -1
  47. package/src/admin/enrollment/email.ts +17 -3
  48. package/src/admin/enrollment/service.ts +71 -10
  49. package/src/admin/errors.ts +5 -0
  50. package/src/admin/index.ts +1 -0
  51. package/src/admin/reports/service.ts +15 -3
  52. package/src/admin/schema.ts +6 -5
  53. package/src/admin/users/service.ts +173 -16
  54. package/src/client/api.ts +52 -473
  55. package/src/client/auth/client.ts +22 -3
  56. package/src/client/comments.ts +205 -0
  57. package/src/client/community.ts +40 -0
  58. package/src/client/device-authorization.ts +4 -20
  59. package/src/client/discovery.ts +39 -11
  60. package/src/client/documents.ts +160 -0
  61. package/src/client/files/archive.ts +60 -0
  62. package/src/client/files/checksum.ts +7 -0
  63. package/src/client/files/download.ts +122 -0
  64. package/src/client/files/images.ts +89 -0
  65. package/src/client/files/index.ts +15 -0
  66. package/src/client/files/objects.ts +173 -0
  67. package/src/client/files/save.ts +79 -0
  68. package/src/client/index.ts +4 -0
  69. package/src/client/portal/account.ts +73 -3
  70. package/src/client/portal/administration.ts +52 -5
  71. package/src/client/portal/request.ts +6 -2
  72. package/src/client/response.ts +21 -0
  73. package/src/client/schema.ts +8 -0
  74. package/src/client/services.ts +23 -18
  75. package/src/client/sharing.ts +262 -0
  76. package/src/client/tour.ts +44 -0
  77. package/src/client/versions.ts +110 -0
  78. package/src/contract/account.ts +111 -11
  79. package/src/contract/admin/index.ts +48 -3
  80. package/src/contract/billing.ts +235 -0
  81. package/src/contract/collaboration.ts +5 -0
  82. package/src/contract/comments.ts +223 -0
  83. package/src/contract/community.ts +60 -0
  84. package/src/contract/discovery.ts +94 -5
  85. package/src/contract/entitlements.ts +10 -0
  86. package/src/contract/index.ts +64 -5
  87. package/src/contract/links.ts +62 -4
  88. package/src/contract/locale.ts +27 -0
  89. package/src/contract/portal.ts +12 -1
  90. package/src/contract/relay.ts +3 -1
  91. package/src/contract/routes.ts +10 -0
  92. package/src/contract/services.ts +62 -20
  93. package/src/contract/workspaces.ts +5 -0
  94. package/src/email/i18n.ts +174 -0
  95. package/src/email/index.ts +13 -2
  96. package/src/email/locales/ar.json +169 -0
  97. package/src/email/locales/de.json +169 -0
  98. package/src/email/locales/es.json +169 -0
  99. package/src/email/locales/fr.json +169 -0
  100. package/src/email/locales/it.json +169 -0
  101. package/src/email/locales/ja.json +169 -0
  102. package/src/email/locales/pl.json +169 -0
  103. package/src/email/locales/pt-br.json +169 -0
  104. package/src/email/locales/ru.json +169 -0
  105. package/src/email/locales/zh-cn.json +169 -0
  106. package/src/email/messages.ts +235 -0
  107. package/src/email/render.ts +160 -276
  108. package/src/email/samples.ts +142 -0
  109. package/src/email/schema.ts +98 -8
  110. package/src/email/templates/BrandEmail.vue +56 -0
  111. package/src/email/templates/CommentNotification.vue +39 -0
  112. package/src/email/templates/DocumentBlocked.vue +45 -0
  113. package/src/email/templates/DocumentInvitation.vue +24 -0
  114. package/src/email/templates/DocumentReport.vue +32 -0
  115. package/src/email/templates/DocumentReportDecided.vue +36 -0
  116. package/src/email/templates/DocumentReportReceived.vue +18 -0
  117. package/src/email/templates/DocumentRestored.vue +24 -0
  118. package/src/email/templates/EmailChangeRequested.vue +24 -0
  119. package/src/email/templates/EmailRoot.vue +19 -0
  120. package/src/email/templates/EmailText.vue +9 -0
  121. package/src/email/templates/EmailVerification.vue +38 -0
  122. package/src/email/templates/EnrollmentInvitation.vue +53 -0
  123. package/src/email/templates/EnrollmentNotification.vue +24 -0
  124. package/src/email/templates/EnrollmentUpdate.vue +52 -0
  125. package/src/email/templates/NewSignIn.vue +37 -0
  126. package/src/email/templates/PasswordChanged.vue +22 -0
  127. package/src/email/templates/PasswordReset.vue +23 -0
  128. package/src/email/templates/StorageLimitReached.vue +28 -0
  129. package/src/email/templates/TwoStepChanged.vue +47 -0
  130. package/src/email/templates/WaitlistConfirmation.vue +29 -0
  131. package/src/email/templates/WorkspaceInvitation.vue +28 -0
  132. package/src/email/templates/brand.ts +15 -61
  133. package/src/email/templates/localization.ts +17 -0
  134. package/src/errors/index.ts +6 -0
  135. package/src/{server/errors → errors}/posthog.ts +28 -4
  136. package/src/global.d.ts +7 -0
  137. package/src/runtime/cloudflare/email.ts +2 -0
  138. package/src/runtime/cloudflare/relay/index.ts +28 -7
  139. package/src/runtime/cloudflare/tsconfig.json +2 -1
  140. package/src/runtime/cloudflare/worker.ts +14 -1
  141. package/src/runtime/cloudflare/xml.ts +12 -0
  142. package/src/runtime/node/admin.ts +51 -47
  143. package/src/runtime/node/cleanup.ts +5 -1
  144. package/src/runtime/node/email/runtime.ts +1 -0
  145. package/src/runtime/node/email/transport.ts +14 -10
  146. package/src/runtime/node/main.ts +1 -1
  147. package/src/runtime/node/server.ts +20 -4
  148. package/src/runtime/node/services/main.ts +1 -1
  149. package/src/runtime/posthog/errors.ts +5 -2
  150. package/src/runtime/s3/objects.ts +17 -0
  151. package/src/runtime/site/community.ts +101 -0
  152. package/src/runtime/site/server.ts +17 -1
  153. package/src/server/account/actions.ts +3 -1
  154. package/src/server/account/deletion.ts +40 -4
  155. package/src/server/account/routes.ts +305 -253
  156. package/src/server/account/tokens.ts +57 -0
  157. package/src/server/api/router.ts +44 -6
  158. package/src/server/app/checks.ts +89 -0
  159. package/src/server/app/cors.ts +44 -0
  160. package/src/server/app/editors.ts +20 -0
  161. package/src/server/app/index.ts +128 -0
  162. package/src/server/app/indexing.ts +40 -0
  163. package/src/server/app/limiters.ts +53 -0
  164. package/src/server/app/routes.ts +123 -0
  165. package/src/server/app/services.ts +219 -0
  166. package/src/server/auth/access-control.ts +13 -8
  167. package/src/server/auth/access-tokens.ts +62 -0
  168. package/src/server/auth/account.ts +13 -12
  169. package/src/server/auth/activity.ts +7 -2
  170. package/src/server/auth/adapter.ts +36 -3
  171. package/src/server/auth/email.ts +33 -18
  172. package/src/server/auth/endpoints.ts +4 -0
  173. package/src/server/auth/enrollment.ts +116 -0
  174. package/src/server/auth/factory.ts +165 -189
  175. package/src/server/auth/index.ts +1 -1
  176. package/src/server/auth/logger.ts +23 -0
  177. package/src/server/auth/methods.ts +162 -0
  178. package/src/server/auth/mfa-assurance.ts +190 -2
  179. package/src/server/auth/passwords.ts +43 -0
  180. package/src/server/auth/rate-limit.ts +31 -0
  181. package/src/server/auth/runtime.ts +19 -5
  182. package/src/server/auth/session.ts +2 -0
  183. package/src/server/auth/social-providers.ts +70 -24
  184. package/src/server/billing/index.ts +8 -0
  185. package/src/server/billing/notify.ts +55 -0
  186. package/src/server/billing/routes.ts +27 -0
  187. package/src/server/billing/seats.ts +17 -0
  188. package/src/server/billing/tokens.ts +37 -0
  189. package/src/server/cleanup/configured.ts +16 -3
  190. package/src/server/cleanup/documents.ts +5 -2
  191. package/src/server/cleanup/revisions.ts +6 -3
  192. package/src/server/cleanup/uploads.ts +2 -1
  193. package/src/server/cleanup/worker.ts +10 -1
  194. package/src/server/collaboration/relay/connection.ts +7 -2
  195. package/src/server/collaboration/relay/hub.ts +80 -166
  196. package/src/server/collaboration/relay/room.ts +154 -0
  197. package/src/server/collaboration/routes.ts +8 -5
  198. package/src/server/collaboration/service.ts +21 -2
  199. package/src/server/comments/index.ts +9 -0
  200. package/src/server/comments/notify.ts +277 -0
  201. package/src/server/comments/routes.ts +352 -0
  202. package/src/server/comments/rows.ts +249 -0
  203. package/src/server/comments/service.ts +570 -0
  204. package/src/server/community/index.ts +2 -0
  205. package/src/server/community/routes.ts +93 -0
  206. package/src/server/community/service.ts +134 -0
  207. package/src/server/config/deployment.ts +35 -10
  208. package/src/server/config/index.ts +2 -2
  209. package/src/server/config/public.ts +25 -6
  210. package/src/server/config/schema.ts +53 -293
  211. package/src/server/config/toml/schema.ts +330 -0
  212. package/src/server/db/index.ts +3 -1
  213. package/src/server/db/migrate.ts +33 -1
  214. package/src/server/db/migrations/009_access_tokens.ts +47 -0
  215. package/src/server/db/migrations/010_storage_limit_notices.ts +50 -0
  216. package/src/server/db/migrations/011_account_ids.ts +30 -0
  217. package/src/server/db/migrations/012_email_locales.ts +34 -0
  218. package/src/server/db/migrations/013_document_block_emails.ts +40 -0
  219. package/src/server/db/migrations/014_report_replies.ts +28 -0
  220. package/src/server/db/migrations/015_comments.ts +57 -0
  221. package/src/server/db/migrations/016_comment_notifications.ts +76 -0
  222. package/src/server/db/migrations/017_invitation_emails.ts +19 -0
  223. package/src/server/db/migrations/018_enrollment_source.ts +17 -0
  224. package/src/server/db/migrations/schema.ts +26 -1
  225. package/src/server/db/tables.ts +122 -3
  226. package/src/server/db/users.ts +22 -0
  227. package/src/server/documents/access.ts +17 -0
  228. package/src/server/documents/images.ts +6 -1
  229. package/src/server/documents/index.ts +1 -1
  230. package/src/server/documents/limits.ts +7 -1
  231. package/src/server/documents/routes.ts +12 -12
  232. package/src/server/documents/service.ts +31 -407
  233. package/src/server/documents/summary.ts +15 -0
  234. package/src/server/documents/uploads.ts +450 -0
  235. package/src/server/documents/versions/routes.ts +7 -8
  236. package/src/server/documents/versions/service.ts +86 -26
  237. package/src/server/email/invitations.ts +1 -0
  238. package/src/server/email/service.ts +39 -6
  239. package/src/server/email/types.ts +13 -0
  240. package/src/server/errors/index.ts +49 -12
  241. package/src/server/index.ts +27 -6
  242. package/src/server/internal/routes.ts +8 -2
  243. package/src/server/internal/service.ts +10 -0
  244. package/src/server/invitations/budget.ts +3 -1
  245. package/src/server/invitations/index.ts +1 -0
  246. package/src/server/invitations/links.ts +6 -0
  247. package/src/server/invitations/types.ts +5 -1
  248. package/src/server/objects/types.ts +5 -0
  249. package/src/server/pictures/service.ts +3 -1
  250. package/src/server/policy/configured.ts +9 -3
  251. package/src/server/policy/database.ts +13 -2
  252. package/src/server/policy/policy.ts +39 -12
  253. package/src/server/policy/service.ts +71 -52
  254. package/src/server/policy/storage.ts +33 -0
  255. package/src/server/policy/workspace.ts +5 -2
  256. package/src/server/quota/index.ts +6 -0
  257. package/src/server/quota/notices.ts +121 -0
  258. package/src/server/quota/storage.ts +5 -0
  259. package/src/server/rate-limit/middleware.ts +4 -0
  260. package/src/server/reports/index.ts +1 -0
  261. package/src/server/reports/replies.ts +55 -0
  262. package/src/server/reports/routes.ts +5 -3
  263. package/src/server/reports/service.ts +27 -3
  264. package/src/server/services/routes.ts +2 -2
  265. package/src/server/sharing/capabilities/service.ts +3 -4
  266. package/src/server/sharing/document-routes.ts +3 -3
  267. package/src/server/sharing/invitations/service.ts +17 -8
  268. package/src/server/sharing/routes.ts +15 -15
  269. package/src/server/validation.ts +35 -24
  270. package/src/server/workspaces/members.ts +57 -31
  271. package/src/server/workspaces/repository.ts +23 -12
  272. package/src/server/workspaces/routes.ts +8 -8
  273. package/src/services/app.ts +31 -22
  274. package/src/services/config.ts +48 -8
  275. package/src/services/metering.ts +15 -27
  276. package/src/services/usage.ts +6 -14
  277. package/src/email/templates/document-invitation.ts +0 -35
  278. package/src/email/templates/enrollment.ts +0 -27
  279. package/src/email/templates/layout.ts +0 -18
  280. package/src/server/app.ts +0 -453
@@ -1,302 +1,186 @@
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 CommentNotification from './templates/CommentNotification.vue'
18
+ import DocumentBlocked from './templates/DocumentBlocked.vue'
19
+ import DocumentInvitation from './templates/DocumentInvitation.vue'
20
+ import DocumentReport from './templates/DocumentReport.vue'
21
+ import DocumentReportDecided from './templates/DocumentReportDecided.vue'
22
+ import DocumentReportReceived from './templates/DocumentReportReceived.vue'
23
+ import DocumentRestored from './templates/DocumentRestored.vue'
24
+ import EmailChangeRequested from './templates/EmailChangeRequested.vue'
25
+ import EmailRoot from './templates/EmailRoot.vue'
26
+ import EmailVerification from './templates/EmailVerification.vue'
27
+ import EnrollmentInvitation from './templates/EnrollmentInvitation.vue'
28
+ import EnrollmentNotification from './templates/EnrollmentNotification.vue'
29
+ import EnrollmentUpdate from './templates/EnrollmentUpdate.vue'
30
+ import NewSignIn from './templates/NewSignIn.vue'
31
+ import PasswordChanged from './templates/PasswordChanged.vue'
32
+ import PasswordReset from './templates/PasswordReset.vue'
33
+ import StorageLimitReached from './templates/StorageLimitReached.vue'
34
+ import TwoStepChanged from './templates/TwoStepChanged.vue'
35
+ import WaitlistConfirmation from './templates/WaitlistConfirmation.vue'
36
+ import WorkspaceInvitation from './templates/WorkspaceInvitation.vue'
37
+
38
+ /** One kind of email: the component that draws it from its payload, and its subject line. */
39
+ type EmailDefinition<Payload> = {
40
+ component: Component
41
+ /** What the component takes besides `payload`. */
42
+ props?: Record<string, unknown>
43
+ subject: (payload: Payload, t: EmailMessages) => string
44
+ }
45
+
46
+ function documentInvitationSubject(payload: DocumentInvitationEmailPayload, t: EmailMessages) {
47
+ const names = { inviter: payload.inviterName ?? t.someone, document: payload.documentName }
48
+ return payload.permission === 'edit'
49
+ ? t.documentInvitationEditSubject(names)
50
+ : t.documentInvitationViewSubject(names)
51
+ }
52
+
53
+ const EMAILS: {
54
+ [Kind in TransactionalEmailKind]: EmailDefinition<TransactionalEmailPayloadByKind[Kind]>
55
+ } = {
56
+ 'document-invitation': { component: DocumentInvitation, subject: documentInvitationSubject },
57
+ 'workspace-invitation': {
58
+ component: WorkspaceInvitation,
59
+ subject: (payload, t) =>
60
+ t.workspaceInvitationSubject({
61
+ inviter: payload.inviterName ?? t.someone,
62
+ workspace: payload.workspaceName
63
+ })
64
+ },
90
65
  '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'
66
+ component: EnrollmentUpdate,
67
+ props: { kind: 'requested' },
68
+ subject: (_payload, t) => t.enrollmentRequestedSubject
95
69
  },
96
70
  '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'
71
+ component: EnrollmentUpdate,
72
+ props: { kind: 'approved' },
73
+ subject: (_payload, t) => t.enrollmentApprovedSubject
101
74
  },
102
75
  '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'
76
+ component: EnrollmentUpdate,
77
+ props: { kind: 'rejected' },
78
+ subject: (_payload, t) => t.enrollmentRejectedSubject
107
79
  },
108
80
  '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.'
81
+ component: EnrollmentUpdate,
82
+ props: { kind: 'revoked' },
83
+ subject: (_payload, t) => t.enrollmentRevokedSubject
84
+ },
85
+ 'enrollment-invited': {
86
+ component: EnrollmentInvitation,
87
+ subject: (payload, t) => (payload.waitlist ? t.invitationWaitlistSubject : t.invitationSubject)
88
+ },
89
+ 'admin-enrollment-notification': {
90
+ component: EnrollmentNotification,
91
+ subject: (_payload, t) => t.enrollmentNotificationSubject
92
+ },
93
+ 'email-verification': {
94
+ component: EmailVerification,
95
+ subject: (payload, t) =>
96
+ payload.purpose === 'change' ? t.verifyChangeSubject : t.verifyAccountSubject
97
+ },
98
+ 'password-reset': { component: PasswordReset, subject: (_payload, t) => t.passwordResetSubject },
99
+ 'password-changed': {
100
+ component: PasswordChanged,
101
+ subject: (_payload, t) => t.passwordChangedSubject
102
+ },
103
+ 'email-change-requested': {
104
+ component: EmailChangeRequested,
105
+ subject: (_payload, t) => t.emailChangeSubject
106
+ },
107
+ 'new-sign-in': { component: NewSignIn, subject: (_payload, t) => t.newSignInSubject },
108
+ 'two-step-changed': { component: TwoStepChanged, subject: (_payload, t) => t.twoStepSubject },
109
+ 'document-report': {
110
+ component: DocumentReport,
111
+ subject: (_payload, t) => t.documentReportSubject
247
112
  },
248
- 'authenticator-off': {
249
- heading: 'Authenticator app turned off',
250
- message: 'your sign-ins no longer ask for a code from an authenticator app.'
113
+ 'storage-limit-reached': {
114
+ component: StorageLimitReached,
115
+ subject: (_payload, t) => t.storageFullSubject
251
116
  },
252
- 'passkey-added': {
253
- heading: 'Passkey added',
254
- message: 'a passkey was added to your account.'
117
+ 'document-blocked': {
118
+ component: DocumentBlocked,
119
+ subject: (payload, t) => t.documentBlockedSubject({ document: payload.documentName })
255
120
  },
256
- 'passkey-removed': {
257
- heading: 'Passkey removed',
258
- message: 'a passkey was removed from your account.'
121
+ 'document-restored': {
122
+ component: DocumentRestored,
123
+ subject: (payload, t) => t.documentRestoredSubject({ document: payload.documentName })
259
124
  },
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.'
125
+ 'document-report-received': {
126
+ component: DocumentReportReceived,
127
+ subject: (payload, t) => t.reportReceivedSubject({ document: payload.documentName })
128
+ },
129
+ 'document-report-decided': {
130
+ component: DocumentReportDecided,
131
+ subject: (payload, t) => t.reportDecidedSubject({ document: payload.documentName })
132
+ },
133
+ 'comment-notification': {
134
+ component: CommentNotification,
135
+ subject: (payload, t) => {
136
+ const words = {
137
+ author: payload.authorName ?? t.commentSomeone,
138
+ document: payload.documentName
139
+ }
140
+ return payload.reason === 'mention'
141
+ ? t.commentMentionSubject(words)
142
+ : t.commentReplySubject(words)
143
+ }
264
144
  }
265
145
  }
266
146
 
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
- )
147
+ /** Renders an email component as HTML and as plain text, in its reader's language. */
148
+ async function renderComponent(
149
+ email: Component,
150
+ props: Record<string, unknown>,
151
+ subject: string,
152
+ localization: EmailLocalization
153
+ ): Promise<RenderedTransactionalEmail> {
154
+ const root = { email, props, localization }
155
+ const [html, text] = await Promise.all([
156
+ render(EmailRoot, root),
157
+ render(EmailRoot, root, { plainText: true })
158
+ ])
159
+ return { subject, html, text }
160
+ }
161
+
162
+ function renderKind<Kind extends TransactionalEmailKind>(
163
+ kind: Kind,
164
+ payload: TransactionalEmailPayloadByKind[Kind],
165
+ localization: EmailLocalization
166
+ ) {
167
+ const { component, props, subject } = EMAILS[kind]
168
+ const content = { ...props, payload }
169
+ return renderComponent(component, content, subject(payload, localization.t), localization)
280
170
  }
281
171
 
282
172
  export async function renderTransactionalEmail(
283
- content: TransactionalEmailContent
173
+ content: TransactionalEmailContent,
174
+ locale: EmailLocale
284
175
  ): 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)
176
+ return renderKind(content.kind, content.payload, emailLocalization(locale))
177
+ }
178
+
179
+ /** The waitlist's confirmation email, which the feedback service sends rather than Cloud. */
180
+ export async function renderWaitlistConfirmation(
181
+ links: { confirmURL: string; leaveURL: string },
182
+ locale: EmailLocale
183
+ ): Promise<RenderedTransactionalEmail> {
184
+ const localization = emailLocalization(locale)
185
+ return renderComponent(WaitlistConfirmation, links, localization.t.waitlistSubject, localization)
302
186
  }
@@ -0,0 +1,142 @@
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
+ 'enrollment-invited'
38
+ ] as const
39
+ ).map((kind): TransactionalEmailContent => ({
40
+ kind,
41
+ payload: { name: 'Ada', actionURL: EMAIL_SAMPLE_URL }
42
+ })),
43
+ // The letter to someone from openpencil.dev's waitlist, which gave no name.
44
+ {
45
+ kind: 'enrollment-invited',
46
+ payload: { name: null, actionURL: EMAIL_SAMPLE_URL, waitlist: true }
47
+ },
48
+ {
49
+ kind: 'admin-enrollment-notification',
50
+ payload: {
51
+ requesterEmail: 'ada@example.com',
52
+ requesterName: 'Ada',
53
+ reason: 'Design',
54
+ actionURL: EMAIL_SAMPLE_URL
55
+ }
56
+ },
57
+ {
58
+ kind: 'email-verification',
59
+ payload: { name: 'Ada', actionURL: EMAIL_SAMPLE_URL, purpose: 'change' }
60
+ },
61
+ { kind: 'password-reset', payload: { name: 'Ada', actionURL: EMAIL_SAMPLE_URL } },
62
+ { kind: 'password-changed', payload: { name: 'Ada', actionURL: EMAIL_SAMPLE_URL } },
63
+ {
64
+ kind: 'email-change-requested',
65
+ payload: { name: 'Ada', newEmail: 'ada@new.example.com', actionURL: EMAIL_SAMPLE_URL }
66
+ },
67
+ {
68
+ kind: 'new-sign-in',
69
+ payload: {
70
+ name: 'Ada',
71
+ signedInAt: '2026-11-13T10:00:00.000Z',
72
+ ipAddress: '203.0.113.9',
73
+ browser: 'Firefox',
74
+ system: 'Linux',
75
+ desktop: false,
76
+ actionURL: EMAIL_SAMPLE_URL
77
+ }
78
+ },
79
+ {
80
+ kind: 'two-step-changed',
81
+ payload: { name: 'Ada', change: 'passkey-added', actionURL: EMAIL_SAMPLE_URL }
82
+ },
83
+ {
84
+ kind: 'two-step-changed',
85
+ payload: {
86
+ name: 'Ada',
87
+ change: 'sign-in-method-removed',
88
+ method: 'google',
89
+ actionURL: EMAIL_SAMPLE_URL
90
+ }
91
+ },
92
+ {
93
+ kind: 'document-report',
94
+ payload: {
95
+ documentName: 'Homepage',
96
+ reason: 'copyright',
97
+ description: 'Copied',
98
+ actionURL: EMAIL_SAMPLE_URL
99
+ }
100
+ },
101
+ {
102
+ kind: 'storage-limit-reached',
103
+ payload: {
104
+ name: 'Ada',
105
+ usedBytes: 310 * 1024 ** 2,
106
+ limitBytes: 300 * 1024 ** 2,
107
+ upgradable: true,
108
+ actionURL: EMAIL_SAMPLE_URL
109
+ }
110
+ },
111
+ {
112
+ kind: 'document-blocked',
113
+ payload: {
114
+ name: 'Ada',
115
+ documentName: 'Homepage',
116
+ reason: 'Phishing page imitating a bank',
117
+ contactEmail: 'abuse@example.com',
118
+ actionURL: EMAIL_SAMPLE_URL
119
+ }
120
+ },
121
+ {
122
+ kind: 'document-restored',
123
+ payload: { name: 'Ada', documentName: 'Homepage', actionURL: EMAIL_SAMPLE_URL }
124
+ },
125
+ { kind: 'document-report-received', payload: { documentName: 'Homepage' } },
126
+ {
127
+ kind: 'document-report-decided',
128
+ payload: { documentName: 'Homepage', outcome: 'blocked', contactEmail: 'abuse@example.com' }
129
+ },
130
+ {
131
+ kind: 'comment-notification',
132
+ payload: {
133
+ name: 'Ada',
134
+ authorName: 'Grace',
135
+ documentName: 'Homepage',
136
+ reason: 'mention',
137
+ excerpt: '@Ada can we tighten the heading before launch?',
138
+ actionURL: EMAIL_SAMPLE_URL,
139
+ settingsURL: EMAIL_SAMPLE_URL
140
+ }
141
+ }
142
+ ]