@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,4 +1,8 @@
1
- import { documentPermissionSchema, workspaceRoleSchema } from '#cloud/contract'
1
+ import {
2
+ documentPermissionSchema,
3
+ documentReportReasonSchema,
4
+ workspaceRoleSchema
5
+ } from '#cloud/contract'
2
6
  import * as v from 'valibot'
3
7
 
4
8
  export type TransactionalEmailKind =
@@ -16,9 +20,15 @@ export type TransactionalEmailKind =
16
20
  | 'new-sign-in'
17
21
  | 'two-step-changed'
18
22
  | 'document-report'
23
+ | 'storage-limit-reached'
24
+ | 'document-blocked'
25
+ | 'document-restored'
26
+ | 'document-report-received'
27
+ | 'document-report-decided'
19
28
 
20
29
  const documentInvitationEmailPayloadSchema = v.object({
21
- inviterName: v.string(),
30
+ /** Null when the inviter's account is gone, so the email says someone invited you. */
31
+ inviterName: v.nullable(v.string()),
22
32
  documentName: v.string(),
23
33
  permission: documentPermissionSchema,
24
34
  expiresAt: v.string(),
@@ -26,7 +36,8 @@ const documentInvitationEmailPayloadSchema = v.object({
26
36
  })
27
37
 
28
38
  const workspaceInvitationEmailPayloadSchema = v.object({
29
- inviterName: v.string(),
39
+ /** Null when the inviter's account is gone, so the email says someone invited you. */
40
+ inviterName: v.nullable(v.string()),
30
41
  workspaceName: v.string(),
31
42
  role: workspaceRoleSchema,
32
43
  expiresAt: v.string(),
@@ -34,7 +45,8 @@ const workspaceInvitationEmailPayloadSchema = v.object({
34
45
  })
35
46
 
36
47
  const enrollmentEmailPayloadSchema = v.object({
37
- name: v.string(),
48
+ /** Null when the request named no one, so the email greets no one by name. */
49
+ name: v.nullable(v.string()),
38
50
  actionURL: v.string()
39
51
  })
40
52
 
@@ -47,11 +59,51 @@ const adminEnrollmentNotificationPayloadSchema = v.object({
47
59
 
48
60
  const documentReportPayloadSchema = v.object({
49
61
  documentName: v.string(),
50
- reason: v.string(),
62
+ reason: documentReportReasonSchema,
51
63
  description: v.string(),
52
64
  actionURL: v.string()
53
65
  })
54
66
 
67
+ const storageLimitReachedPayloadSchema = v.object({
68
+ name: v.string(),
69
+ usedBytes: v.number(),
70
+ limitBytes: v.number(),
71
+ /** Whether the server sells plans, so the account can get more storage rather than only free it. */
72
+ upgradable: v.boolean(),
73
+ actionURL: v.string()
74
+ })
75
+
76
+ /** To a workspace's owner: an administrator took one of its documents down. */
77
+ const documentBlockedPayloadSchema = v.object({
78
+ /** The owner's name, or null when the account has none. */
79
+ name: v.nullable(v.string()),
80
+ documentName: v.string(),
81
+ /** Why, as the administrator wrote it, or null when they gave no reason. */
82
+ reason: v.nullable(v.string()),
83
+ /** Where to write to contest it: the deployment's abuse address, or null without one. */
84
+ contactEmail: v.nullable(v.pipe(v.string(), v.email())),
85
+ actionURL: v.string()
86
+ })
87
+
88
+ /** To a workspace's owner: a document taken down is back. */
89
+ const documentRestoredPayloadSchema = v.object({
90
+ name: v.nullable(v.string()),
91
+ documentName: v.string(),
92
+ actionURL: v.string()
93
+ })
94
+
95
+ /** To whoever reported a document: their report arrived. */
96
+ const documentReportReceivedPayloadSchema = v.object({ documentName: v.string() })
97
+
98
+ /** To whoever reported a document: what the administrators decided. */
99
+ const documentReportDecidedPayloadSchema = v.object({
100
+ documentName: v.string(),
101
+ /** The document blocked, the report acted on some other way, or the document left as it was. */
102
+ outcome: v.picklist(['blocked', 'actioned', 'dismissed']),
103
+ /** Where to write to disagree: the deployment's abuse address, or null without one. */
104
+ contactEmail: v.nullable(v.pipe(v.string(), v.email()))
105
+ })
106
+
55
107
  const authenticationEmailPayloadSchema = v.object({
56
108
  name: v.string(),
57
109
  actionURL: v.optional(v.string()),
@@ -111,7 +163,12 @@ export const transactionalEmailContentSchema = v.variant('kind', [
111
163
  content('email-change-requested', emailChangeRequestedPayloadSchema),
112
164
  content('new-sign-in', newSignInPayloadSchema),
113
165
  content('two-step-changed', twoStepChangedPayloadSchema),
114
- content('document-report', documentReportPayloadSchema)
166
+ content('document-report', documentReportPayloadSchema),
167
+ content('storage-limit-reached', storageLimitReachedPayloadSchema),
168
+ content('document-blocked', documentBlockedPayloadSchema),
169
+ content('document-restored', documentRestoredPayloadSchema),
170
+ content('document-report-received', documentReportReceivedPayloadSchema),
171
+ content('document-report-decided', documentReportDecidedPayloadSchema)
115
172
  ])
116
173
 
117
174
  /** A transactional email's kind with the payload that kind renders. */
@@ -152,3 +209,10 @@ export type RenderedTransactionalEmail = {
152
209
  text: string
153
210
  }
154
211
  export type DocumentReportPayload = v.InferOutput<typeof documentReportPayloadSchema>
212
+ export type StorageLimitReachedPayload = v.InferOutput<typeof storageLimitReachedPayloadSchema>
213
+ export type DocumentBlockedPayload = v.InferOutput<typeof documentBlockedPayloadSchema>
214
+ export type DocumentRestoredPayload = v.InferOutput<typeof documentRestoredPayloadSchema>
215
+ export type DocumentReportReceivedPayload = v.InferOutput<
216
+ typeof documentReportReceivedPayloadSchema
217
+ >
218
+ export type DocumentReportDecidedPayload = v.InferOutput<typeof documentReportDecidedPayloadSchema>
@@ -0,0 +1,54 @@
1
+ <script setup lang="ts">
2
+ import {
3
+ Body,
4
+ Button,
5
+ Container,
6
+ Head,
7
+ Heading,
8
+ // eslint-disable-next-line @open-pencil/structure/no-mixed-case-acronym-identifiers -- Upstream export spelling.
9
+ Html as HTML,
10
+ Img,
11
+ Link,
12
+ Preview,
13
+ Section,
14
+ Text
15
+ } from '@vue-email/components'
16
+
17
+ import { LOGO_URL, SITE_URL, styles } from './brand'
18
+ import { useEmailLocalization } from './localization'
19
+
20
+ /**
21
+ * The branded email every OpenPencil service sends, in its reader's language and direction: a
22
+ * heading, the paragraphs in the default slot, one button, and small print in `note`.
23
+ */
24
+ const { preview, heading, action } = defineProps<{
25
+ /** The line mail clients show beside the subject. */
26
+ preview: string
27
+ heading: string
28
+ /** The one thing the email asks the reader to do, if there is one. */
29
+ action?: { label: string; url: string }
30
+ }>()
31
+
32
+ const { locale, dir, t } = useEmailLocalization()
33
+ </script>
34
+
35
+ <template>
36
+ <HTML :lang="locale" :dir="dir">
37
+ <Head />
38
+ <Preview>{{ preview }}</Preview>
39
+ <Body :style="styles.body">
40
+ <Container :style="styles.card">
41
+ <Img :src="LOGO_URL" :width="44" :height="44" alt="OpenPencil" :style="styles.logo" />
42
+ <Heading as="h1" :style="styles.heading">{{ heading }}</Heading>
43
+ <slot />
44
+ <Section v-if="action" :style="styles.action">
45
+ <Button :href="action.url" :style="styles.button">{{ action.label }}</Button>
46
+ </Section>
47
+ <Text v-if="$slots.note" :style="styles.note"><slot name="note" /></Text>
48
+ </Container>
49
+ <Text :style="styles.footer">
50
+ {{ t.footer }} · <Link :href="SITE_URL" :style="styles.footerLink">openpencil.dev</Link>
51
+ </Text>
52
+ </Body>
53
+ </HTML>
54
+ </template>
@@ -0,0 +1,45 @@
1
+ <script setup lang="ts">
2
+ import { Link } from '@vue-email/components'
3
+
4
+ import type { DocumentBlockedPayload } from '../schema'
5
+ import { styles } from './brand'
6
+ import BrandEmail from './BrandEmail.vue'
7
+ import EmailText from './EmailText.vue'
8
+ import { greeting, useEmailLocalization } from './localization'
9
+
10
+ /**
11
+ * To a workspace's owner: an administrator took one of its documents down. It says why, when the
12
+ * administrator gave a reason, and where to contest it.
13
+ */
14
+ const { payload } = defineProps<{ payload: DocumentBlockedPayload }>()
15
+
16
+ const localization = useEmailLocalization()
17
+ const { t } = localization
18
+ const document = { document: payload.documentName }
19
+ // The translation places the address inside its sentence, where `{email}` is.
20
+ const [beforeEmail = '', afterEmail = ''] = t
21
+ .documentBlockedContest({ email: '{email}' })
22
+ .split('{email}')
23
+ </script>
24
+
25
+ <template>
26
+ <BrandEmail
27
+ :preview="t.documentBlocked(document)"
28
+ :heading="t.documentBlockedHeading"
29
+ :action="{ label: t.openHome, url: payload.actionURL }"
30
+ >
31
+ <EmailText>{{ greeting(localization, payload.name) }}</EmailText>
32
+ <EmailText>{{ t.documentBlocked(document) }}</EmailText>
33
+ <EmailText v-if="payload.reason">
34
+ {{ t.documentBlockedReason({ reason: payload.reason }) }}
35
+ </EmailText>
36
+ <EmailText v-if="payload.contactEmail">
37
+ {{ beforeEmail
38
+ }}<Link :href="`mailto:${payload.contactEmail}`" :style="styles.link">{{
39
+ payload.contactEmail
40
+ }}</Link
41
+ >{{ afterEmail }}
42
+ </EmailText>
43
+ <EmailText v-else>{{ t.documentBlockedContestAdministrators }}</EmailText>
44
+ </BrandEmail>
45
+ </template>
@@ -0,0 +1,24 @@
1
+ <script setup lang="ts">
2
+ import type { DocumentInvitationEmailPayload } from '../schema'
3
+ import BrandEmail from './BrandEmail.vue'
4
+ import EmailText from './EmailText.vue'
5
+ import { useEmailLocalization } from './localization'
6
+
7
+ const { payload } = defineProps<{ payload: DocumentInvitationEmailPayload }>()
8
+
9
+ const { t, dateTime } = useEmailLocalization()
10
+ const names = { inviter: payload.inviterName ?? t.someone, document: payload.documentName }
11
+ const message =
12
+ payload.permission === 'edit' ? t.documentInvitationEdit(names) : t.documentInvitationView(names)
13
+ </script>
14
+
15
+ <template>
16
+ <BrandEmail
17
+ :preview="message"
18
+ :heading="t.documentInvitationHeading"
19
+ :action="{ label: t.documentInvitationAction, url: payload.acceptanceURL }"
20
+ >
21
+ <EmailText>{{ message }}</EmailText>
22
+ <template #note>{{ t.invitationExpires({ date: dateTime(payload.expiresAt) }) }}</template>
23
+ </BrandEmail>
24
+ </template>
@@ -0,0 +1,32 @@
1
+ <script setup lang="ts">
2
+ import type { DocumentReportReason } from '#cloud/contract'
3
+
4
+ import type { DocumentReportPayload } from '../schema'
5
+ import BrandEmail from './BrandEmail.vue'
6
+ import EmailText from './EmailText.vue'
7
+ import { useEmailLocalization } from './localization'
8
+
9
+ /** To administrators: someone reported a shared document, in their own words. */
10
+ const { payload } = defineProps<{ payload: DocumentReportPayload }>()
11
+
12
+ const { t } = useEmailLocalization()
13
+ const reasons: Record<DocumentReportReason, string> = {
14
+ 'spam-phishing': t.reportReasonSpamPhishing,
15
+ illegal: t.reportReasonIllegal,
16
+ copyright: t.reportReasonCopyright,
17
+ harassment: t.reportReasonHarassment,
18
+ other: t.reportReasonOther
19
+ }
20
+ const report = { document: payload.documentName, reason: reasons[payload.reason] }
21
+ </script>
22
+
23
+ <template>
24
+ <BrandEmail
25
+ :preview="t.documentReportPreview(report)"
26
+ :heading="t.documentReportHeading"
27
+ :action="{ label: t.documentReportAction, url: payload.actionURL }"
28
+ >
29
+ <EmailText>{{ t.documentReport(report) }}</EmailText>
30
+ <EmailText>{{ payload.description }}</EmailText>
31
+ </BrandEmail>
32
+ </template>
@@ -0,0 +1,36 @@
1
+ <script setup lang="ts">
2
+ import { Link } from '@vue-email/components'
3
+
4
+ import type { DocumentReportDecidedPayload } from '../schema'
5
+ import { styles } from './brand'
6
+ import BrandEmail from './BrandEmail.vue'
7
+ import EmailText from './EmailText.vue'
8
+ import { useEmailLocalization } from './localization'
9
+
10
+ /** To whoever reported a document: what the administrators decided, and where to disagree. */
11
+ const { payload } = defineProps<{ payload: DocumentReportDecidedPayload }>()
12
+
13
+ const { t } = useEmailLocalization()
14
+ const document = { document: payload.documentName }
15
+ const decision = {
16
+ blocked: { heading: t.reportBlockedHeading, message: t.reportBlocked(document) },
17
+ actioned: { heading: t.reportActionedHeading, message: t.reportActioned(document) },
18
+ dismissed: { heading: t.reportDismissedHeading, message: t.reportDismissed(document) }
19
+ }[payload.outcome]
20
+ // The translation places the address inside its sentence, where `{email}` is.
21
+ const [beforeEmail = '', afterEmail = ''] = t.reportDisagree({ email: '{email}' }).split('{email}')
22
+ </script>
23
+
24
+ <template>
25
+ <BrandEmail :preview="decision.message" :heading="decision.heading">
26
+ <EmailText>{{ decision.message }}</EmailText>
27
+ <EmailText v-if="payload.contactEmail">
28
+ {{ beforeEmail
29
+ }}<Link :href="`mailto:${payload.contactEmail}`" :style="styles.link">{{
30
+ payload.contactEmail
31
+ }}</Link
32
+ >{{ afterEmail }}
33
+ </EmailText>
34
+ <EmailText v-else>{{ t.reportDisagreeAdministrators }}</EmailText>
35
+ </BrandEmail>
36
+ </template>
@@ -0,0 +1,18 @@
1
+ <script setup lang="ts">
2
+ import type { DocumentReportReceivedPayload } from '../schema'
3
+ import BrandEmail from './BrandEmail.vue'
4
+ import EmailText from './EmailText.vue'
5
+ import { useEmailLocalization } from './localization'
6
+
7
+ /** To whoever reported a document: their report arrived, and they'll hear the decision. */
8
+ const { payload } = defineProps<{ payload: DocumentReportReceivedPayload }>()
9
+
10
+ const { t } = useEmailLocalization()
11
+ const document = { document: payload.documentName }
12
+ </script>
13
+
14
+ <template>
15
+ <BrandEmail :preview="t.reportReceived(document)" :heading="t.reportReceivedHeading">
16
+ <EmailText>{{ t.reportReceived(document) }}</EmailText>
17
+ </BrandEmail>
18
+ </template>
@@ -0,0 +1,24 @@
1
+ <script setup lang="ts">
2
+ import type { DocumentRestoredPayload } from '../schema'
3
+ import BrandEmail from './BrandEmail.vue'
4
+ import EmailText from './EmailText.vue'
5
+ import { greeting, useEmailLocalization } from './localization'
6
+
7
+ /** To a workspace's owner: a document an administrator took down is back. */
8
+ const { payload } = defineProps<{ payload: DocumentRestoredPayload }>()
9
+
10
+ const localization = useEmailLocalization()
11
+ const { t } = localization
12
+ const document = { document: payload.documentName }
13
+ </script>
14
+
15
+ <template>
16
+ <BrandEmail
17
+ :preview="t.documentRestored(document)"
18
+ :heading="t.documentRestoredHeading"
19
+ :action="{ label: t.openHome, url: payload.actionURL }"
20
+ >
21
+ <EmailText>{{ greeting(localization, payload.name) }}</EmailText>
22
+ <EmailText>{{ t.documentRestored(document) }}</EmailText>
23
+ </BrandEmail>
24
+ </template>
@@ -0,0 +1,24 @@
1
+ <script setup lang="ts">
2
+ import type { EmailChangeRequestedPayload } from '../schema'
3
+ import BrandEmail from './BrandEmail.vue'
4
+ import EmailText from './EmailText.vue'
5
+ import { greeting, useEmailLocalization } from './localization'
6
+
7
+ /** To the address being replaced: which address is taking over, before it confirms. */
8
+ const { payload } = defineProps<{ payload: EmailChangeRequestedPayload }>()
9
+
10
+ const localization = useEmailLocalization()
11
+ const { t } = localization
12
+ </script>
13
+
14
+ <template>
15
+ <BrandEmail
16
+ :preview="t.emailChangePreview({ email: payload.newEmail })"
17
+ :heading="t.emailChangeHeading"
18
+ :action="{ label: t.reviewAccount, url: payload.actionURL }"
19
+ >
20
+ <EmailText>{{ greeting(localization, payload.name) }}</EmailText>
21
+ <EmailText>{{ t.emailChange({ email: payload.newEmail }) }}</EmailText>
22
+ <EmailText>{{ t.emailChangeNotYou }}</EmailText>
23
+ </BrandEmail>
24
+ </template>
@@ -0,0 +1,19 @@
1
+ <script setup lang="ts">
2
+ import { provide, type Component } from 'vue'
3
+
4
+ import type { EmailLocalization } from '../i18n'
5
+ import { EMAIL_LOCALIZATION } from './localization'
6
+
7
+ /** Renders an email in its reader's language, which it and its layout read. */
8
+ const { email, props, localization } = defineProps<{
9
+ email: Component
10
+ props: Record<string, unknown>
11
+ localization: EmailLocalization
12
+ }>()
13
+
14
+ provide(EMAIL_LOCALIZATION, localization)
15
+ </script>
16
+
17
+ <template>
18
+ <component :is="email" v-bind="props" />
19
+ </template>
@@ -0,0 +1,9 @@
1
+ <script setup lang="ts">
2
+ import { Text } from '@vue-email/components'
3
+
4
+ import { styles } from './brand'
5
+ </script>
6
+
7
+ <template>
8
+ <Text :style="styles.text"><slot /></Text>
9
+ </template>
@@ -0,0 +1,38 @@
1
+ <script setup lang="ts">
2
+ import type { AuthenticationEmailPayload } from '../schema'
3
+ import BrandEmail from './BrandEmail.vue'
4
+ import EmailText from './EmailText.vue'
5
+ import { greeting, useEmailLocalization } from './localization'
6
+
7
+ /** Confirms the address a new account signed up with, or one an account is moving to. */
8
+ const { payload } = defineProps<{ payload: AuthenticationEmailPayload }>()
9
+
10
+ const localization = useEmailLocalization()
11
+ const { t } = localization
12
+ const copy =
13
+ payload.purpose === 'change'
14
+ ? {
15
+ preview: t.verifyChangePreview,
16
+ heading: t.verifyChangeHeading,
17
+ message: t.verifyChange,
18
+ note: t.verifyChangeNote
19
+ }
20
+ : {
21
+ preview: t.verifyAccountPreview,
22
+ heading: t.verifyAccountHeading,
23
+ message: t.verifyAccount,
24
+ note: t.verifyAccountNote
25
+ }
26
+ </script>
27
+
28
+ <template>
29
+ <BrandEmail
30
+ :preview="copy.preview"
31
+ :heading="copy.heading"
32
+ :action="{ label: t.verifyAction, url: payload.actionURL ?? '#' }"
33
+ >
34
+ <EmailText>{{ greeting(localization, payload.name) }}</EmailText>
35
+ <EmailText>{{ copy.message }}</EmailText>
36
+ <template #note>{{ copy.note }}</template>
37
+ </BrandEmail>
38
+ </template>
@@ -0,0 +1,24 @@
1
+ <script setup lang="ts">
2
+ import type { AdminEnrollmentNotificationPayload } from '../schema'
3
+ import BrandEmail from './BrandEmail.vue'
4
+ import EmailText from './EmailText.vue'
5
+ import { useEmailLocalization } from './localization'
6
+
7
+ /** To administrators: someone asked for access, in their own words. */
8
+ const { payload } = defineProps<{ payload: AdminEnrollmentNotificationPayload }>()
9
+
10
+ const { t } = useEmailLocalization()
11
+ </script>
12
+
13
+ <template>
14
+ <BrandEmail
15
+ :preview="t.enrollmentNotificationPreview({ email: payload.requesterEmail })"
16
+ :heading="t.enrollmentNotificationHeading"
17
+ :action="{ label: t.enrollmentNotificationAction, url: payload.actionURL }"
18
+ >
19
+ <EmailText>
20
+ {{ t.enrollmentNotification({ name: payload.requesterName, email: payload.requesterEmail }) }}
21
+ </EmailText>
22
+ <EmailText>{{ payload.reason }}</EmailText>
23
+ </BrandEmail>
24
+ </template>
@@ -0,0 +1,52 @@
1
+ <script setup lang="ts">
2
+ import type { EnrollmentEmailPayload } from '../schema'
3
+ import BrandEmail from './BrandEmail.vue'
4
+ import EmailText from './EmailText.vue'
5
+ import { greeting, useEmailLocalization } from './localization'
6
+
7
+ /** Where an access request stands, to the person who made it. */
8
+ const { kind, payload } = defineProps<{
9
+ kind: 'requested' | 'approved' | 'rejected' | 'revoked'
10
+ payload: EnrollmentEmailPayload
11
+ }>()
12
+
13
+ const localization = useEmailLocalization()
14
+ const { t } = localization
15
+ const copy = {
16
+ requested: {
17
+ preview: t.enrollmentRequestedPreview,
18
+ heading: t.enrollmentRequestedHeading,
19
+ message: t.enrollmentRequested,
20
+ action: t.openCloud
21
+ },
22
+ approved: {
23
+ preview: t.enrollmentApprovedPreview,
24
+ heading: t.enrollmentApprovedHeading,
25
+ message: t.enrollmentApproved,
26
+ action: t.enrollmentApprovedAction
27
+ },
28
+ rejected: {
29
+ preview: t.enrollmentRejectedPreview,
30
+ heading: t.enrollmentRejectedHeading,
31
+ message: t.enrollmentRejected,
32
+ action: t.enrollmentRejectedAction
33
+ },
34
+ revoked: {
35
+ preview: t.enrollmentRevokedPreview,
36
+ heading: t.enrollmentRevokedHeading,
37
+ message: t.enrollmentRevoked,
38
+ action: t.enrollmentRevokedAction
39
+ }
40
+ }[kind]
41
+ </script>
42
+
43
+ <template>
44
+ <BrandEmail
45
+ :preview="copy.preview"
46
+ :heading="copy.heading"
47
+ :action="{ label: copy.action, url: payload.actionURL }"
48
+ >
49
+ <EmailText>{{ greeting(localization, payload.name) }}</EmailText>
50
+ <EmailText>{{ copy.message }}</EmailText>
51
+ </BrandEmail>
52
+ </template>
@@ -0,0 +1,37 @@
1
+ <script setup lang="ts">
2
+ import type { NewSignInPayload } from '../schema'
3
+ import BrandEmail from './BrandEmail.vue'
4
+ import EmailText from './EmailText.vue'
5
+ import { greeting, useEmailLocalization } from './localization'
6
+
7
+ /** An account was signed in to from somewhere it never was before. */
8
+ const { payload } = defineProps<{ payload: NewSignInPayload }>()
9
+
10
+ const localization = useEmailLocalization()
11
+ const { t, dateTime } = localization
12
+
13
+ function signedInWith(): string {
14
+ if (payload.desktop) return t.newSignInApp
15
+ const { browser, system } = payload
16
+ if (browser && system) return t.newSignInBrowser({ browser, system })
17
+ return browser ?? system ?? t.newSignInUnknownBrowser
18
+ }
19
+
20
+ const device = signedInWith()
21
+ const date = dateTime(payload.signedInAt)
22
+ const message = payload.ipAddress
23
+ ? t.newSignInFrom({ device, address: payload.ipAddress, date })
24
+ : t.newSignIn({ device, date })
25
+ </script>
26
+
27
+ <template>
28
+ <BrandEmail
29
+ :preview="t.newSignInPreview({ device })"
30
+ :heading="t.newSignInHeading"
31
+ :action="{ label: t.reviewSessions, url: payload.actionURL }"
32
+ >
33
+ <EmailText>{{ greeting(localization, payload.name) }}</EmailText>
34
+ <EmailText>{{ message }}</EmailText>
35
+ <EmailText>{{ t.newSignInNotYou }}</EmailText>
36
+ </BrandEmail>
37
+ </template>
@@ -0,0 +1,22 @@
1
+ <script setup lang="ts">
2
+ import type { AuthenticationEmailPayload } from '../schema'
3
+ import BrandEmail from './BrandEmail.vue'
4
+ import EmailText from './EmailText.vue'
5
+ import { greeting, useEmailLocalization } from './localization'
6
+
7
+ const { payload } = defineProps<{ payload: AuthenticationEmailPayload }>()
8
+
9
+ const localization = useEmailLocalization()
10
+ const { t } = localization
11
+ </script>
12
+
13
+ <template>
14
+ <BrandEmail
15
+ :preview="t.passwordChangedPreview"
16
+ :heading="t.passwordChangedHeading"
17
+ :action="{ label: t.openCloud, url: payload.actionURL ?? '#' }"
18
+ >
19
+ <EmailText>{{ greeting(localization, payload.name) }}</EmailText>
20
+ <EmailText>{{ t.passwordChanged }}</EmailText>
21
+ </BrandEmail>
22
+ </template>
@@ -0,0 +1,23 @@
1
+ <script setup lang="ts">
2
+ import type { AuthenticationEmailPayload } from '../schema'
3
+ import BrandEmail from './BrandEmail.vue'
4
+ import EmailText from './EmailText.vue'
5
+ import { greeting, useEmailLocalization } from './localization'
6
+
7
+ const { payload } = defineProps<{ payload: AuthenticationEmailPayload }>()
8
+
9
+ const localization = useEmailLocalization()
10
+ const { t } = localization
11
+ </script>
12
+
13
+ <template>
14
+ <BrandEmail
15
+ :preview="t.passwordResetPreview"
16
+ :heading="t.passwordResetHeading"
17
+ :action="{ label: t.passwordResetAction, url: payload.actionURL ?? '#' }"
18
+ >
19
+ <EmailText>{{ greeting(localization, payload.name) }}</EmailText>
20
+ <EmailText>{{ t.passwordReset }}</EmailText>
21
+ <template #note>{{ t.passwordResetNote }}</template>
22
+ </BrandEmail>
23
+ </template>
@@ -0,0 +1,28 @@
1
+ <script setup lang="ts">
2
+ import type { StorageLimitReachedPayload } from '../schema'
3
+ import BrandEmail from './BrandEmail.vue'
4
+ import EmailText from './EmailText.vue'
5
+ import { greeting, useEmailLocalization } from './localization'
6
+
7
+ /** The account holds all the storage its plan includes, so its workspaces are read-only. */
8
+ const { payload } = defineProps<{ payload: StorageLimitReachedPayload }>()
9
+
10
+ const localization = useEmailLocalization()
11
+ const { t, storage } = localization
12
+ const amounts = { used: storage(payload.usedBytes), limit: storage(payload.limitBytes) }
13
+ </script>
14
+
15
+ <template>
16
+ <BrandEmail
17
+ :preview="t.storageFullPreview(amounts)"
18
+ :heading="t.storageFullHeading"
19
+ :action="{
20
+ label: payload.upgradable ? t.storageFullAction : t.openCloud,
21
+ url: payload.actionURL
22
+ }"
23
+ >
24
+ <EmailText>{{ greeting(localization, payload.name) }}</EmailText>
25
+ <EmailText>{{ t.storageFull(amounts) }}</EmailText>
26
+ <EmailText>{{ payload.upgradable ? t.storageFullUpgrade : t.storageFullFreeSpace }}</EmailText>
27
+ </BrandEmail>
28
+ </template>