@pairdraw/cloud 0.0.0-stage → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/LICENSE-MIT +21 -0
- package/NOTICE +7 -0
- package/README.md +37 -2
- package/dist/bin/ai-relay.d.mts +1 -0
- package/dist/bin/ai-relay.mjs +31 -0
- package/dist/bin/ai-relay.mjs.map +1 -0
- package/dist/bin/server.d.mts +1 -0
- package/dist/bin/server.mjs +29 -0
- package/dist/bin/server.mjs.map +1 -0
- package/dist/client.d.ts +1578 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +2008 -0
- package/dist/client.js.map +1 -0
- package/dist/contract.d.ts +2 -0
- package/dist/contract.js +2 -0
- package/dist/contract2.js +1673 -0
- package/dist/contract2.js.map +1 -0
- package/dist/email.d.ts +155 -0
- package/dist/email.d.ts.map +1 -0
- package/dist/email.js +700 -0
- package/dist/email.js.map +1 -0
- package/dist/index.d.ts +1945 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/listen.mjs +1905 -0
- package/dist/listen.mjs.map +1 -0
- package/dist/runtime-node.d.mts +10715 -0
- package/dist/runtime-node.d.mts.map +1 -0
- package/dist/runtime-node.mjs +32 -0
- package/dist/runtime-node.mjs.map +1 -0
- package/dist/server.d.ts +13772 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +8856 -0
- package/dist/server.js.map +1 -0
- package/dist/server.mjs +8836 -0
- package/dist/server.mjs.map +1 -0
- package/dist/server2.mjs +505 -0
- package/dist/server2.mjs.map +1 -0
- package/package.json +132 -4
- package/src/admin/api/routes.ts +223 -0
- package/src/admin/api/security.ts +12 -0
- package/src/admin/audit/service.ts +138 -0
- package/src/admin/email/service.ts +140 -0
- package/src/admin/enrollment/email.ts +77 -0
- package/src/admin/enrollment/service.ts +308 -0
- package/src/admin/errors.ts +20 -0
- package/src/admin/index.ts +19 -0
- package/src/admin/list.ts +61 -0
- package/src/admin/operations/service.ts +70 -0
- package/src/admin/schema.ts +26 -0
- package/src/admin/users/service.ts +369 -0
- package/src/ai-relay/app.ts +251 -0
- package/src/ai-relay/config.ts +120 -0
- package/src/ai-relay/db/index.ts +10 -0
- package/src/ai-relay/db/migrate.ts +32 -0
- package/src/ai-relay/db/migrations/001_usage.ts +26 -0
- package/src/ai-relay/db/schema.ts +20 -0
- package/src/ai-relay/index.ts +18 -0
- package/src/ai-relay/metering.ts +68 -0
- package/src/ai-relay/usage.ts +115 -0
- package/src/client/ai.ts +96 -0
- package/src/client/api.ts +530 -0
- package/src/client/auth/client.ts +188 -0
- package/src/client/auth/failure.ts +54 -0
- package/src/client/auth/navigation.ts +45 -0
- package/src/client/device-authorization.ts +134 -0
- package/src/client/discovery.ts +105 -0
- package/src/client/images.ts +81 -0
- package/src/client/index.ts +53 -0
- package/src/client/portal/account.ts +183 -0
- package/src/client/portal/administration.ts +130 -0
- package/src/client/portal/client.ts +18 -0
- package/src/client/portal/request.ts +115 -0
- package/src/client/profiles.ts +79 -0
- package/src/client/response.ts +51 -0
- package/src/client/workspaces.ts +142 -0
- package/src/contract/account.ts +204 -0
- package/src/contract/admin/index.ts +187 -0
- package/src/contract/ai.ts +150 -0
- package/src/contract/collaboration.ts +45 -0
- package/src/contract/comments.ts +149 -0
- package/src/contract/discovery.ts +81 -0
- package/src/contract/documents.ts +263 -0
- package/src/contract/entitlements.ts +28 -0
- package/src/contract/index.ts +210 -0
- package/src/contract/links.ts +108 -0
- package/src/contract/portal.ts +11 -0
- package/src/contract/profiles.ts +88 -0
- package/src/contract/relay.ts +370 -0
- package/src/contract/sharing.ts +215 -0
- package/src/contract/versions.ts +87 -0
- package/src/contract/workspaces.ts +100 -0
- package/src/email/index.ts +13 -0
- package/src/email/render.ts +304 -0
- package/src/email/schema.ts +144 -0
- package/src/email/templates/brand.ts +125 -0
- package/src/email/templates/document-invitation.ts +39 -0
- package/src/email/templates/enrollment.ts +30 -0
- package/src/email/templates/layout.ts +20 -0
- package/src/runtime/cloudflare/email.ts +70 -0
- package/src/runtime/cloudflare/environment.ts +57 -0
- package/src/runtime/cloudflare/index.ts +3 -0
- package/src/runtime/cloudflare/relay.ts +136 -0
- package/src/runtime/cloudflare/site.ts +13 -0
- package/src/runtime/cloudflare/tsconfig.json +21 -0
- package/src/runtime/cloudflare/worker.ts +161 -0
- package/src/runtime/node/admin.ts +59 -0
- package/src/runtime/node/ai-relay/main.ts +35 -0
- package/src/runtime/node/ai-relay/server.ts +63 -0
- package/src/runtime/node/application.ts +50 -0
- package/src/runtime/node/bootstrap.ts +22 -0
- package/src/runtime/node/cleanup.ts +24 -0
- package/src/runtime/node/command.ts +17 -0
- package/src/runtime/node/config.ts +16 -0
- package/src/runtime/node/email/runtime.ts +44 -0
- package/src/runtime/node/email/transport.ts +112 -0
- package/src/runtime/node/entitlements/main.ts +41 -0
- package/src/runtime/node/entitlements/refusal.ts +15 -0
- package/src/runtime/node/index.ts +25 -0
- package/src/runtime/node/listen.ts +35 -0
- package/src/runtime/node/main.ts +29 -0
- package/src/runtime/node/migrate.ts +13 -0
- package/src/runtime/node/quota-reconcile.ts +9 -0
- package/src/runtime/node/relay.ts +54 -0
- package/src/runtime/node/server.ts +119 -0
- package/src/runtime/node/site.ts +64 -0
- package/src/runtime/postgres/database.ts +19 -0
- package/src/runtime/s3/objects.ts +244 -0
- package/src/runtime/site/server.ts +82 -0
- package/src/server/account/actions.ts +66 -0
- package/src/server/account/routes.ts +300 -0
- package/src/server/ai/errors.ts +7 -0
- package/src/server/ai/index.ts +4 -0
- package/src/server/ai/keys.ts +43 -0
- package/src/server/ai/routes.ts +43 -0
- package/src/server/ai/service.ts +70 -0
- package/src/server/api/index.ts +8 -0
- package/src/server/api/router.ts +129 -0
- package/src/server/api/types.ts +7 -0
- package/src/server/app.ts +385 -0
- package/src/server/auth/account.ts +73 -0
- package/src/server/auth/activity.ts +213 -0
- package/src/server/auth/adapter.ts +79 -0
- package/src/server/auth/email.ts +125 -0
- package/src/server/auth/endpoints.ts +57 -0
- package/src/server/auth/factory.ts +583 -0
- package/src/server/auth/index.ts +17 -0
- package/src/server/auth/mfa-assurance.ts +55 -0
- package/src/server/auth/runtime.ts +26 -0
- package/src/server/auth/session.ts +19 -0
- package/src/server/auth/social-providers.ts +55 -0
- package/src/server/auth/user-agent.ts +16 -0
- package/src/server/auth/workspace-access.ts +23 -0
- package/src/server/cleanup/configured.ts +38 -0
- package/src/server/cleanup/documents.ts +231 -0
- package/src/server/cleanup/index.ts +29 -0
- package/src/server/cleanup/objects.ts +27 -0
- package/src/server/cleanup/revisions.ts +246 -0
- package/src/server/cleanup/uploads.ts +129 -0
- package/src/server/cleanup/worker.ts +79 -0
- package/src/server/collaboration/index.ts +28 -0
- package/src/server/collaboration/relay/authorize.ts +54 -0
- package/src/server/collaboration/relay/awareness.ts +104 -0
- package/src/server/collaboration/relay/comments.ts +86 -0
- package/src/server/collaboration/relay/documents.ts +39 -0
- package/src/server/collaboration/relay/hub.ts +567 -0
- package/src/server/collaboration/relay/index.ts +15 -0
- package/src/server/collaboration/relay/persistence.ts +48 -0
- package/src/server/collaboration/routes.ts +77 -0
- package/src/server/collaboration/service.ts +190 -0
- package/src/server/config/deployment.ts +178 -0
- package/src/server/config/index.ts +20 -0
- package/src/server/config/limits.ts +8 -0
- package/src/server/config/public.ts +66 -0
- package/src/server/config/schema.ts +512 -0
- package/src/server/db/database.ts +15 -0
- package/src/server/db/expressions.ts +13 -0
- package/src/server/db/index.ts +21 -0
- package/src/server/db/migrate.ts +177 -0
- package/src/server/db/migrations/001_foundation.ts +164 -0
- package/src/server/db/migrations/002_upload_cleanup_claims.ts +34 -0
- package/src/server/db/migrations/003_document_cleanup_claims.ts +23 -0
- package/src/server/db/migrations/004_document_sharing.ts +82 -0
- package/src/server/db/migrations/005_document_collaboration_epoch.ts +13 -0
- package/src/server/db/migrations/006_invitation_continuation.ts +27 -0
- package/src/server/db/migrations/007_collaboration_state.ts +25 -0
- package/src/server/db/migrations/008_storage_reservations.ts +37 -0
- package/src/server/db/migrations/009_workspace_entitlements.ts +22 -0
- package/src/server/db/migrations/010_upload_finalization.ts +22 -0
- package/src/server/db/migrations/011_upload_finalization_lease.ts +12 -0
- package/src/server/db/migrations/012_transactional_email.ts +48 -0
- package/src/server/db/migrations/013_admin_enrollment.ts +54 -0
- package/src/server/db/migrations/014_enrollment_email_kinds.ts +30 -0
- package/src/server/db/migrations/015_cloud_rate_limit.ts +22 -0
- package/src/server/db/migrations/016_auth_schema.ts +16 -0
- package/src/server/db/migrations/017_authentication_email_kinds.ts +32 -0
- package/src/server/db/migrations/018_authentication_mfa.ts +78 -0
- package/src/server/db/migrations/019_better_auth_account_issuer.ts +42 -0
- package/src/server/db/migrations/020_workspace_invitations.ts +57 -0
- package/src/server/db/migrations/021_document_versions.ts +66 -0
- package/src/server/db/migrations/022_entitlement_external_version.ts +17 -0
- package/src/server/db/migrations/023_document_images.ts +61 -0
- package/src/server/db/migrations/024_account_activity.ts +66 -0
- package/src/server/db/migrations/025_table_names.ts +58 -0
- package/src/server/db/migrations/026_user_picture.ts +30 -0
- package/src/server/db/migrations/027_sharing_comments_snapshots_profiles.ts +74 -0
- package/src/server/db/migrations/helpers.ts +78 -0
- package/src/server/db/tables.ts +399 -0
- package/src/server/documents/access.ts +103 -0
- package/src/server/documents/errors.ts +16 -0
- package/src/server/documents/images.ts +405 -0
- package/src/server/documents/index.ts +14 -0
- package/src/server/documents/limits.ts +57 -0
- package/src/server/documents/repository.ts +131 -0
- package/src/server/documents/routes.ts +239 -0
- package/src/server/documents/service.ts +607 -0
- package/src/server/documents/summary.ts +36 -0
- package/src/server/documents/types.ts +13 -0
- package/src/server/documents/versions/checkpoint.ts +98 -0
- package/src/server/documents/versions/history.ts +25 -0
- package/src/server/documents/versions/index.ts +4 -0
- package/src/server/documents/versions/routes.ts +112 -0
- package/src/server/documents/versions/service.ts +396 -0
- package/src/server/email/crypto.ts +57 -0
- package/src/server/email/index.ts +18 -0
- package/src/server/email/invitations.ts +30 -0
- package/src/server/email/service.ts +247 -0
- package/src/server/email/types.ts +56 -0
- package/src/server/email/worker.ts +33 -0
- package/src/server/index.ts +288 -0
- package/src/server/internal/index.ts +8 -0
- package/src/server/internal/routes.ts +41 -0
- package/src/server/internal/schema.ts +10 -0
- package/src/server/internal/service.ts +44 -0
- package/src/server/invitations/index.ts +6 -0
- package/src/server/invitations/types.ts +30 -0
- package/src/server/objects/index.ts +16 -0
- package/src/server/objects/types.ts +81 -0
- package/src/server/pictures/index.ts +9 -0
- package/src/server/pictures/provider.ts +61 -0
- package/src/server/pictures/routes.ts +21 -0
- package/src/server/pictures/service.ts +235 -0
- package/src/server/policy/configured.ts +23 -0
- package/src/server/policy/database.ts +108 -0
- package/src/server/policy/entitlements.ts +29 -0
- package/src/server/policy/index.ts +17 -0
- package/src/server/policy/keys.ts +23 -0
- package/src/server/policy/policy.ts +117 -0
- package/src/server/policy/provider.ts +67 -0
- package/src/server/policy/schema.ts +69 -0
- package/src/server/policy/service.ts +85 -0
- package/src/server/policy/static.ts +62 -0
- package/src/server/profiles/index.ts +12 -0
- package/src/server/profiles/routes.ts +103 -0
- package/src/server/profiles/service.ts +266 -0
- package/src/server/quota/index.ts +7 -0
- package/src/server/quota/reconcile.ts +61 -0
- package/src/server/quota/storage.ts +165 -0
- package/src/server/rate-limit/cleanup.ts +16 -0
- package/src/server/rate-limit/index.ts +12 -0
- package/src/server/rate-limit/keys.ts +38 -0
- package/src/server/rate-limit/middleware.ts +137 -0
- package/src/server/rate-limit/postgres.ts +79 -0
- package/src/server/sharing/access.ts +29 -0
- package/src/server/sharing/actor.ts +12 -0
- package/src/server/sharing/capabilities/service.ts +318 -0
- package/src/server/sharing/continuation.ts +83 -0
- package/src/server/sharing/contracts.ts +82 -0
- package/src/server/sharing/crypto.ts +48 -0
- package/src/server/sharing/document-routes.ts +41 -0
- package/src/server/sharing/errors.ts +20 -0
- package/src/server/sharing/grants/service.ts +79 -0
- package/src/server/sharing/http.ts +45 -0
- package/src/server/sharing/index.ts +40 -0
- package/src/server/sharing/invitations/service.ts +315 -0
- package/src/server/sharing/policy.ts +42 -0
- package/src/server/sharing/routes.ts +251 -0
- package/src/server/sharing/service.ts +117 -0
- package/src/server/validation.ts +24 -0
- package/src/server/worker/interval.ts +23 -0
- package/src/server/worker/periodic.ts +42 -0
- package/src/server/workspaces/index.ts +16 -0
- package/src/server/workspaces/members.ts +502 -0
- package/src/server/workspaces/repository.ts +91 -0
- package/src/server/workspaces/routes.ts +198 -0
- package/src/server/workspaces/service.ts +84 -0
package/dist/email.js
ADDED
|
@@ -0,0 +1,700 @@
|
|
|
1
|
+
import { render } from "@vue-email/render";
|
|
2
|
+
import { compact } from "es-toolkit";
|
|
3
|
+
import { defineComponent, h } from "vue";
|
|
4
|
+
import { Body, Button, Container, Head, Heading, Html, Img, Link, Preview, Section, Text } from "@vue-email/components";
|
|
5
|
+
import * as v from "valibot";
|
|
6
|
+
//#region src/email/templates/brand.ts
|
|
7
|
+
/**
|
|
8
|
+
* The ivory app-icon tile on the server's own site, which serves it beside the editor; PNG because
|
|
9
|
+
* mail clients do not draw SVG.
|
|
10
|
+
*/
|
|
11
|
+
const LOGO_PATH = "/brand/app-icon-1024.png";
|
|
12
|
+
const FONT = "-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif";
|
|
13
|
+
const INK = "#171717";
|
|
14
|
+
const MUTED = "#6B6B6B";
|
|
15
|
+
/** Deep teal from the mark; white text on it passes WCAG AA. */
|
|
16
|
+
const TEAL = "#0A6C65";
|
|
17
|
+
const styles = {
|
|
18
|
+
body: {
|
|
19
|
+
backgroundColor: "#F5F5EF",
|
|
20
|
+
fontFamily: FONT,
|
|
21
|
+
margin: "0",
|
|
22
|
+
padding: "40px 16px"
|
|
23
|
+
},
|
|
24
|
+
card: {
|
|
25
|
+
maxWidth: "480px",
|
|
26
|
+
margin: "0 auto",
|
|
27
|
+
padding: "40px",
|
|
28
|
+
backgroundColor: "#FFFFFF",
|
|
29
|
+
borderRadius: "16px",
|
|
30
|
+
border: "1px solid #E7E5DC"
|
|
31
|
+
},
|
|
32
|
+
logo: {
|
|
33
|
+
borderRadius: "10px",
|
|
34
|
+
margin: "0 0 28px"
|
|
35
|
+
},
|
|
36
|
+
heading: {
|
|
37
|
+
color: INK,
|
|
38
|
+
fontSize: "22px",
|
|
39
|
+
fontWeight: "600",
|
|
40
|
+
lineHeight: "1.3",
|
|
41
|
+
margin: "0 0 12px"
|
|
42
|
+
},
|
|
43
|
+
text: {
|
|
44
|
+
color: "#404040",
|
|
45
|
+
fontSize: "15px",
|
|
46
|
+
lineHeight: "1.6",
|
|
47
|
+
margin: "0 0 24px"
|
|
48
|
+
},
|
|
49
|
+
button: {
|
|
50
|
+
backgroundColor: TEAL,
|
|
51
|
+
borderRadius: "10px",
|
|
52
|
+
color: "#FFFFFF",
|
|
53
|
+
fontSize: "15px",
|
|
54
|
+
fontWeight: "600",
|
|
55
|
+
padding: "12px 22px",
|
|
56
|
+
textDecoration: "none"
|
|
57
|
+
},
|
|
58
|
+
note: {
|
|
59
|
+
color: MUTED,
|
|
60
|
+
fontSize: "13px",
|
|
61
|
+
lineHeight: "1.6",
|
|
62
|
+
margin: "28px 0 0"
|
|
63
|
+
},
|
|
64
|
+
link: {
|
|
65
|
+
color: TEAL,
|
|
66
|
+
textDecoration: "underline"
|
|
67
|
+
},
|
|
68
|
+
footer: {
|
|
69
|
+
color: MUTED,
|
|
70
|
+
fontSize: "12px",
|
|
71
|
+
lineHeight: "1.6",
|
|
72
|
+
textAlign: "center",
|
|
73
|
+
margin: "24px 0 0"
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
function noteContent(note) {
|
|
77
|
+
if (!note.link) return note.text;
|
|
78
|
+
const { label, url } = note.link;
|
|
79
|
+
return [
|
|
80
|
+
`${note.text} `,
|
|
81
|
+
h(Link, {
|
|
82
|
+
href: url,
|
|
83
|
+
style: styles.link
|
|
84
|
+
}, () => label),
|
|
85
|
+
"."
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
/** The branded email Pairdraw Cloud sends. */
|
|
89
|
+
function emailLayout(props) {
|
|
90
|
+
const { note } = props;
|
|
91
|
+
const site = props.site ? new URL(props.site) : null;
|
|
92
|
+
return h(Html, { lang: "en" }, () => [
|
|
93
|
+
h(Head),
|
|
94
|
+
h(Preview, () => props.preview),
|
|
95
|
+
h(Body, { style: styles.body }, () => [h(Container, { style: styles.card }, () => [
|
|
96
|
+
site ? h(Img, {
|
|
97
|
+
src: new URL(LOGO_PATH, site).href,
|
|
98
|
+
width: 44,
|
|
99
|
+
height: 44,
|
|
100
|
+
alt: "Pairdraw",
|
|
101
|
+
style: styles.logo
|
|
102
|
+
}) : null,
|
|
103
|
+
h(Heading, {
|
|
104
|
+
as: "h1",
|
|
105
|
+
style: styles.heading
|
|
106
|
+
}, () => props.heading),
|
|
107
|
+
h(Text, { style: styles.text }, () => props.message),
|
|
108
|
+
h(Section, () => h(Button, {
|
|
109
|
+
href: props.actionURL,
|
|
110
|
+
style: styles.button
|
|
111
|
+
}, () => props.actionLabel)),
|
|
112
|
+
note ? h(Text, { style: styles.note }, () => noteContent(note)) : null
|
|
113
|
+
]), h(Text, { style: styles.footer }, () => site ? ["Pairdraw, the open-source design editor · ", h(Link, {
|
|
114
|
+
href: site.href,
|
|
115
|
+
style: { color: MUTED }
|
|
116
|
+
}, () => site.host)] : "Pairdraw, the open-source design editor")])
|
|
117
|
+
]);
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/email/templates/layout.ts
|
|
121
|
+
/** Cloud's mail in its branded layout, so people know who wrote. */
|
|
122
|
+
function transactionalEmailLayout(props) {
|
|
123
|
+
const { footer, ...content } = props;
|
|
124
|
+
return emailLayout({
|
|
125
|
+
...content,
|
|
126
|
+
note: footer ? { text: footer } : void 0
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/email/templates/document-invitation.ts
|
|
131
|
+
const DocumentInvitationEmail = defineComponent({
|
|
132
|
+
props: {
|
|
133
|
+
inviterName: {
|
|
134
|
+
type: String,
|
|
135
|
+
required: true
|
|
136
|
+
},
|
|
137
|
+
documentName: {
|
|
138
|
+
type: String,
|
|
139
|
+
required: true
|
|
140
|
+
},
|
|
141
|
+
permissionLabel: {
|
|
142
|
+
type: String,
|
|
143
|
+
required: true
|
|
144
|
+
},
|
|
145
|
+
expiresAt: {
|
|
146
|
+
type: String,
|
|
147
|
+
required: true
|
|
148
|
+
},
|
|
149
|
+
acceptanceURL: {
|
|
150
|
+
type: String,
|
|
151
|
+
required: true
|
|
152
|
+
},
|
|
153
|
+
site: {
|
|
154
|
+
type: String,
|
|
155
|
+
required: false
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
setup(props) {
|
|
159
|
+
return () => transactionalEmailLayout({
|
|
160
|
+
preview: `${props.inviterName} invited you to ${props.permissionLabel} a document`,
|
|
161
|
+
heading: "Pairdraw invitation",
|
|
162
|
+
message: `${props.inviterName} invited you to ${props.permissionLabel} “${props.documentName}”.`,
|
|
163
|
+
actionLabel: "Open document",
|
|
164
|
+
actionURL: props.acceptanceURL,
|
|
165
|
+
footer: `This invitation expires ${props.expiresAt}.`,
|
|
166
|
+
site: props.site
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/email/templates/enrollment.ts
|
|
172
|
+
const EnrollmentEmail = defineComponent({
|
|
173
|
+
props: {
|
|
174
|
+
heading: {
|
|
175
|
+
type: String,
|
|
176
|
+
required: true
|
|
177
|
+
},
|
|
178
|
+
preview: {
|
|
179
|
+
type: String,
|
|
180
|
+
required: true
|
|
181
|
+
},
|
|
182
|
+
message: {
|
|
183
|
+
type: String,
|
|
184
|
+
required: true
|
|
185
|
+
},
|
|
186
|
+
actionLabel: {
|
|
187
|
+
type: String,
|
|
188
|
+
required: true
|
|
189
|
+
},
|
|
190
|
+
actionURL: {
|
|
191
|
+
type: String,
|
|
192
|
+
required: true
|
|
193
|
+
},
|
|
194
|
+
footer: {
|
|
195
|
+
type: String,
|
|
196
|
+
required: false
|
|
197
|
+
},
|
|
198
|
+
site: {
|
|
199
|
+
type: String,
|
|
200
|
+
required: false
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
setup(props) {
|
|
204
|
+
return () => transactionalEmailLayout(props);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
//#endregion
|
|
208
|
+
//#region src/email/render.ts
|
|
209
|
+
function toDraft(component, props, subject) {
|
|
210
|
+
return {
|
|
211
|
+
component,
|
|
212
|
+
props,
|
|
213
|
+
subject
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
const DOCUMENT_PERMISSION_LABELS = {
|
|
217
|
+
edit: "edit",
|
|
218
|
+
comment: "view and comment on",
|
|
219
|
+
view: "view"
|
|
220
|
+
};
|
|
221
|
+
function draftDocumentInvitation(payload) {
|
|
222
|
+
const permissionLabel = DOCUMENT_PERMISSION_LABELS[payload.permission];
|
|
223
|
+
return toDraft(DocumentInvitationEmail, {
|
|
224
|
+
inviterName: payload.inviterName,
|
|
225
|
+
documentName: payload.documentName,
|
|
226
|
+
permissionLabel,
|
|
227
|
+
expiresAt: new Date(payload.expiresAt).toUTCString(),
|
|
228
|
+
acceptanceURL: payload.acceptanceURL
|
|
229
|
+
}, `${payload.inviterName} invited you to ${permissionLabel} ${payload.documentName}`);
|
|
230
|
+
}
|
|
231
|
+
const WORKSPACE_ROLE_LABELS = {
|
|
232
|
+
admin: "manage",
|
|
233
|
+
editor: "edit in",
|
|
234
|
+
viewer: "view"
|
|
235
|
+
};
|
|
236
|
+
function draftWorkspaceInvitation(payload) {
|
|
237
|
+
const action = WORKSPACE_ROLE_LABELS[payload.role];
|
|
238
|
+
return toDraft(EnrollmentEmail, {
|
|
239
|
+
heading: `Join ${payload.workspaceName}`,
|
|
240
|
+
preview: `${payload.inviterName} invited you to ${payload.workspaceName}`,
|
|
241
|
+
message: `${payload.inviterName} invited you to ${action} the workspace “${payload.workspaceName}” on Pairdraw Cloud. You will see its documents on Home once you join.`,
|
|
242
|
+
actionLabel: "Join workspace",
|
|
243
|
+
actionURL: payload.acceptanceURL,
|
|
244
|
+
footer: `This invitation expires ${new Date(payload.expiresAt).toUTCString()}.`
|
|
245
|
+
}, `${payload.inviterName} invited you to ${payload.workspaceName}`);
|
|
246
|
+
}
|
|
247
|
+
const ENROLLMENT_COPY = {
|
|
248
|
+
"enrollment-requested": {
|
|
249
|
+
subject: "We received your Pairdraw Cloud request",
|
|
250
|
+
heading: "Request received",
|
|
251
|
+
preview: "Your Pairdraw Cloud access request is awaiting review.",
|
|
252
|
+
actionLabel: "Open Pairdraw Cloud"
|
|
253
|
+
},
|
|
254
|
+
"enrollment-approved": {
|
|
255
|
+
subject: "Your Pairdraw Cloud access is ready",
|
|
256
|
+
heading: "Access approved",
|
|
257
|
+
preview: "You can now sign in to Pairdraw Cloud.",
|
|
258
|
+
actionLabel: "Sign in"
|
|
259
|
+
},
|
|
260
|
+
"enrollment-rejected": {
|
|
261
|
+
subject: "Your Pairdraw Cloud request was reviewed",
|
|
262
|
+
heading: "Request reviewed",
|
|
263
|
+
preview: "Your current access request was not approved.",
|
|
264
|
+
actionLabel: "Request access again"
|
|
265
|
+
},
|
|
266
|
+
"enrollment-revoked": {
|
|
267
|
+
subject: "Your Pairdraw Cloud access has changed",
|
|
268
|
+
heading: "Access changed",
|
|
269
|
+
preview: "Your Pairdraw Cloud access is no longer active.",
|
|
270
|
+
actionLabel: "Open Pairdraw"
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
function enrollmentCopy(kind, name) {
|
|
274
|
+
const copy = ENROLLMENT_COPY[kind];
|
|
275
|
+
const messages = {
|
|
276
|
+
"enrollment-requested": `Hi ${name}, your request is awaiting manual review.`,
|
|
277
|
+
"enrollment-approved": `Hi ${name}, your access request was approved.`,
|
|
278
|
+
"enrollment-rejected": `Hi ${name}, your current access request was not approved.`,
|
|
279
|
+
"enrollment-revoked": `Hi ${name}, your Cloud access is no longer active.`
|
|
280
|
+
};
|
|
281
|
+
return {
|
|
282
|
+
...copy,
|
|
283
|
+
message: messages[kind]
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
function draftEnrollment(kind, payload) {
|
|
287
|
+
const copy = enrollmentCopy(kind, payload.name);
|
|
288
|
+
return toDraft(EnrollmentEmail, {
|
|
289
|
+
...copy,
|
|
290
|
+
actionURL: payload.actionURL
|
|
291
|
+
}, copy.subject);
|
|
292
|
+
}
|
|
293
|
+
function draftAdminNotification(payload) {
|
|
294
|
+
return toDraft(EnrollmentEmail, {
|
|
295
|
+
heading: "New Cloud access request",
|
|
296
|
+
preview: `${payload.requesterEmail} requested Pairdraw Cloud access.`,
|
|
297
|
+
message: `${payload.requesterName} (${payload.requesterEmail}) requested access. ${payload.reason}`,
|
|
298
|
+
actionLabel: "Review request",
|
|
299
|
+
actionURL: payload.actionURL
|
|
300
|
+
}, "New Pairdraw Cloud access request");
|
|
301
|
+
}
|
|
302
|
+
function draftAuthentication(kind, payload) {
|
|
303
|
+
const copy = {
|
|
304
|
+
"email-verification": payload.purpose === "change" ? {
|
|
305
|
+
subject: "Confirm your new Pairdraw Cloud email",
|
|
306
|
+
heading: "Confirm your new email",
|
|
307
|
+
preview: "One click to move your Pairdraw Cloud account to this address.",
|
|
308
|
+
message: `Hi ${payload.name}, confirm this address to make it your Pairdraw Cloud account’s email. Your old address stays until you do.`,
|
|
309
|
+
actionLabel: "Confirm email",
|
|
310
|
+
footer: "Didn’t ask for this? Ignore this email and nothing changes."
|
|
311
|
+
} : {
|
|
312
|
+
subject: "Confirm your Pairdraw Cloud email",
|
|
313
|
+
heading: "Confirm your email",
|
|
314
|
+
preview: "One click to finish creating your Pairdraw Cloud account.",
|
|
315
|
+
message: `Hi ${payload.name}, confirm this address to finish creating your Pairdraw Cloud account. Then go back to Pairdraw; it signs you in by itself.`,
|
|
316
|
+
actionLabel: "Confirm email",
|
|
317
|
+
footer: "Didn’t create an account? Ignore this email and nothing happens."
|
|
318
|
+
},
|
|
319
|
+
"password-reset": {
|
|
320
|
+
subject: "Reset your Pairdraw Cloud password",
|
|
321
|
+
heading: "Reset your password",
|
|
322
|
+
preview: "Use this secure link to choose a new password.",
|
|
323
|
+
message: `Hi ${payload.name}, use the link below to choose a new password.`,
|
|
324
|
+
actionLabel: "Reset password",
|
|
325
|
+
footer: "Didn’t ask for this? Ignore this email and your password stays the same."
|
|
326
|
+
},
|
|
327
|
+
"password-changed": {
|
|
328
|
+
subject: "Your Pairdraw Cloud password changed",
|
|
329
|
+
heading: "Password changed",
|
|
330
|
+
preview: "Your Pairdraw Cloud password was changed.",
|
|
331
|
+
message: `Hi ${payload.name}, your password was changed. If this was not you, contact your administrator.`,
|
|
332
|
+
actionLabel: "Open Pairdraw Cloud"
|
|
333
|
+
}
|
|
334
|
+
}[kind];
|
|
335
|
+
return toDraft(EnrollmentEmail, {
|
|
336
|
+
...copy,
|
|
337
|
+
actionURL: payload.actionURL ?? "#"
|
|
338
|
+
}, copy.subject);
|
|
339
|
+
}
|
|
340
|
+
function draftEmailChangeRequested(payload) {
|
|
341
|
+
return toDraft(EnrollmentEmail, {
|
|
342
|
+
heading: "Your email is changing",
|
|
343
|
+
preview: `Your Pairdraw Cloud email is changing to ${payload.newEmail}.`,
|
|
344
|
+
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.`,
|
|
345
|
+
actionLabel: "Review your account",
|
|
346
|
+
actionURL: payload.actionURL
|
|
347
|
+
}, "Your Pairdraw Cloud email is changing");
|
|
348
|
+
}
|
|
349
|
+
function draftNewSignIn(payload) {
|
|
350
|
+
const device = payload.desktop ? "the Pairdraw app" : compact([payload.browser, payload.system]).join(" on ") || "an unknown browser";
|
|
351
|
+
const place = payload.ipAddress ? ` from ${payload.ipAddress}` : "";
|
|
352
|
+
return toDraft(EnrollmentEmail, {
|
|
353
|
+
heading: "New sign-in to your account",
|
|
354
|
+
preview: `Your Pairdraw Cloud account was signed in to with ${device}.`,
|
|
355
|
+
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.`,
|
|
356
|
+
actionLabel: "Review sessions",
|
|
357
|
+
actionURL: payload.actionURL
|
|
358
|
+
}, "New sign-in to your Pairdraw Cloud account");
|
|
359
|
+
}
|
|
360
|
+
const TWO_STEP_COPY = {
|
|
361
|
+
"authenticator-on": {
|
|
362
|
+
heading: "Authenticator app turned on",
|
|
363
|
+
message: "an authenticator app now confirms your sign-ins."
|
|
364
|
+
},
|
|
365
|
+
"authenticator-off": {
|
|
366
|
+
heading: "Authenticator app turned off",
|
|
367
|
+
message: "your sign-ins no longer ask for a code from an authenticator app."
|
|
368
|
+
},
|
|
369
|
+
"passkey-added": {
|
|
370
|
+
heading: "Passkey added",
|
|
371
|
+
message: "a passkey was added to your account."
|
|
372
|
+
},
|
|
373
|
+
"passkey-removed": {
|
|
374
|
+
heading: "Passkey removed",
|
|
375
|
+
message: "a passkey was removed from your account."
|
|
376
|
+
},
|
|
377
|
+
"reset-by-administrator": {
|
|
378
|
+
heading: "Two-step sign-in was reset",
|
|
379
|
+
message: "an administrator removed your authenticator app, recovery codes, and passkeys, so you can set them up again."
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
function draftTwoStepChanged(payload) {
|
|
383
|
+
const copy = TWO_STEP_COPY[payload.change];
|
|
384
|
+
return toDraft(EnrollmentEmail, {
|
|
385
|
+
heading: copy.heading,
|
|
386
|
+
preview: `${copy.heading} on your Pairdraw Cloud account.`,
|
|
387
|
+
message: `Hi ${payload.name}, ${copy.message} If this wasn’t you, change your password and contact your administrator.`,
|
|
388
|
+
actionLabel: "Review security",
|
|
389
|
+
actionURL: payload.actionURL
|
|
390
|
+
}, `${copy.heading} on your Pairdraw Cloud account`);
|
|
391
|
+
}
|
|
392
|
+
function draft(content) {
|
|
393
|
+
if (content.kind === "document-invitation") return draftDocumentInvitation(content.payload);
|
|
394
|
+
if (content.kind === "workspace-invitation") return draftWorkspaceInvitation(content.payload);
|
|
395
|
+
if (content.kind === "admin-enrollment-notification") return draftAdminNotification(content.payload);
|
|
396
|
+
if (content.kind === "email-verification" || content.kind === "password-reset" || content.kind === "password-changed") return draftAuthentication(content.kind, content.payload);
|
|
397
|
+
if (content.kind === "email-change-requested") return draftEmailChangeRequested(content.payload);
|
|
398
|
+
if (content.kind === "new-sign-in") return draftNewSignIn(content.payload);
|
|
399
|
+
if (content.kind === "two-step-changed") return draftTwoStepChanged(content.payload);
|
|
400
|
+
return draftEnrollment(content.kind, content.payload);
|
|
401
|
+
}
|
|
402
|
+
async function renderTransactionalEmail(content, options = {}) {
|
|
403
|
+
const { component, props, subject } = draft(content);
|
|
404
|
+
const withSite = {
|
|
405
|
+
...props,
|
|
406
|
+
site: options.site
|
|
407
|
+
};
|
|
408
|
+
const [html, text] = await Promise.all([render(component, withSite), render(component, withSite, { plainText: true })]);
|
|
409
|
+
return {
|
|
410
|
+
subject,
|
|
411
|
+
html,
|
|
412
|
+
text
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
//#endregion
|
|
416
|
+
//#region src/contract/workspaces.ts
|
|
417
|
+
const workspaceRoleSchema = v.picklist([
|
|
418
|
+
"viewer",
|
|
419
|
+
"editor",
|
|
420
|
+
"admin"
|
|
421
|
+
]);
|
|
422
|
+
const workspaceSummarySchema = v.object({
|
|
423
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
424
|
+
name: v.string(),
|
|
425
|
+
slug: v.string(),
|
|
426
|
+
role: workspaceRoleSchema,
|
|
427
|
+
createdAt: v.string(),
|
|
428
|
+
updatedAt: v.string()
|
|
429
|
+
});
|
|
430
|
+
v.object({
|
|
431
|
+
name: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(100)),
|
|
432
|
+
slug: v.optional(v.pipe(v.string(), v.trim(), v.minLength(3), v.maxLength(63), v.regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/)))
|
|
433
|
+
});
|
|
434
|
+
v.object({ workspaces: v.array(workspaceSummarySchema) });
|
|
435
|
+
v.object({ name: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(100)) });
|
|
436
|
+
/** Someone who belongs to a workspace, and what they may do in it. */
|
|
437
|
+
const workspaceMemberSchema = v.object({
|
|
438
|
+
userId: v.string(),
|
|
439
|
+
name: v.string(),
|
|
440
|
+
email: v.string(),
|
|
441
|
+
image: v.nullable(v.string()),
|
|
442
|
+
role: workspaceRoleSchema,
|
|
443
|
+
joinedAt: v.string()
|
|
444
|
+
});
|
|
445
|
+
/** An invitation to join a workspace that has not been accepted yet. */
|
|
446
|
+
const workspaceInvitationSchema = v.object({
|
|
447
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
448
|
+
email: v.string(),
|
|
449
|
+
role: workspaceRoleSchema,
|
|
450
|
+
/** Who sent it; the name is null once their account is gone. */
|
|
451
|
+
invitedBy: v.object({
|
|
452
|
+
id: v.string(),
|
|
453
|
+
name: v.nullable(v.string())
|
|
454
|
+
}),
|
|
455
|
+
invitedAt: v.string(),
|
|
456
|
+
expiresAt: v.string()
|
|
457
|
+
});
|
|
458
|
+
v.object({
|
|
459
|
+
members: v.array(workspaceMemberSchema),
|
|
460
|
+
/** Only administrators see pending invitations. */
|
|
461
|
+
invitations: v.array(workspaceInvitationSchema)
|
|
462
|
+
});
|
|
463
|
+
v.object({
|
|
464
|
+
email: v.pipe(v.string(), v.trim(), v.toLowerCase(), v.email()),
|
|
465
|
+
role: workspaceRoleSchema
|
|
466
|
+
});
|
|
467
|
+
v.object({
|
|
468
|
+
invitation: workspaceInvitationSchema,
|
|
469
|
+
acceptanceURL: v.string()
|
|
470
|
+
});
|
|
471
|
+
v.object({ role: workspaceRoleSchema });
|
|
472
|
+
//#endregion
|
|
473
|
+
//#region src/contract/documents.ts
|
|
474
|
+
const CLOUD_PROTOCOL_MAX_UPLOAD_BYTES = 1073741824;
|
|
475
|
+
const checksumSchema = v.pipe(v.string(), v.regex(/^[A-Za-z0-9+/]{43}=$/));
|
|
476
|
+
/** The most images one revision, or one request for image uploads, may name. */
|
|
477
|
+
const CLOUD_MAX_DOCUMENT_IMAGES = 1e4;
|
|
478
|
+
const imageNameSchema = v.pipe(v.string(), v.regex(/^[A-Za-z0-9._-]{1,128}$/));
|
|
479
|
+
const objectDownloadSchema = v.object({
|
|
480
|
+
url: v.pipe(v.string(), v.url()),
|
|
481
|
+
method: v.literal("GET"),
|
|
482
|
+
headers: v.record(v.string(), v.string()),
|
|
483
|
+
expiresAt: v.string()
|
|
484
|
+
});
|
|
485
|
+
/** An image a stored revision uses, where to download it, and what to check it against. */
|
|
486
|
+
const documentImageDownloadSchema = v.object({
|
|
487
|
+
name: imageNameSchema,
|
|
488
|
+
checksum: checksumSchema,
|
|
489
|
+
byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
490
|
+
download: objectDownloadSchema
|
|
491
|
+
});
|
|
492
|
+
v.object({
|
|
493
|
+
checksum: checksumSchema,
|
|
494
|
+
byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
495
|
+
download: objectDownloadSchema
|
|
496
|
+
});
|
|
497
|
+
v.object({ checksums: v.pipe(v.array(checksumSchema), v.minLength(1), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)) });
|
|
498
|
+
const documentPermissionSchema = v.picklist([
|
|
499
|
+
"view",
|
|
500
|
+
"comment",
|
|
501
|
+
"edit"
|
|
502
|
+
]);
|
|
503
|
+
const documentAccessSourceSchema = v.picklist([
|
|
504
|
+
"owner",
|
|
505
|
+
"workspace",
|
|
506
|
+
"direct-grant"
|
|
507
|
+
]);
|
|
508
|
+
v.object({
|
|
509
|
+
permission: documentPermissionSchema,
|
|
510
|
+
canManageSharing: v.boolean(),
|
|
511
|
+
sources: v.array(documentAccessSourceSchema),
|
|
512
|
+
/**
|
|
513
|
+
* The revision the document holds now, null before its first save; servers from before snapshot
|
|
514
|
+
* links leave it out.
|
|
515
|
+
*/
|
|
516
|
+
currentRevisionId: v.optional(v.nullable(v.pipe(v.string(), v.uuid())))
|
|
517
|
+
});
|
|
518
|
+
const documentSummarySchema = v.object({
|
|
519
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
520
|
+
workspaceId: v.pipe(v.string(), v.uuid()),
|
|
521
|
+
name: v.string(),
|
|
522
|
+
currentRevisionId: v.nullable(v.pipe(v.string(), v.uuid())),
|
|
523
|
+
version: v.number(),
|
|
524
|
+
createdAt: v.string(),
|
|
525
|
+
updatedAt: v.string()
|
|
526
|
+
});
|
|
527
|
+
v.object({
|
|
528
|
+
...documentSummarySchema.entries,
|
|
529
|
+
workspaceName: v.string(),
|
|
530
|
+
permission: documentPermissionSchema,
|
|
531
|
+
sharedBy: v.nullable(v.object({ name: v.string() })),
|
|
532
|
+
sharedAt: v.string()
|
|
533
|
+
});
|
|
534
|
+
v.object({
|
|
535
|
+
document: documentSummarySchema,
|
|
536
|
+
revisionId: v.pipe(v.string(), v.uuid()),
|
|
537
|
+
byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
538
|
+
checksum: checksumSchema,
|
|
539
|
+
contentType: v.string(),
|
|
540
|
+
download: objectDownloadSchema,
|
|
541
|
+
/** The images the stored file leaves out, which a client puts back under their names. */
|
|
542
|
+
images: v.pipe(v.array(documentImageDownloadSchema), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES))
|
|
543
|
+
});
|
|
544
|
+
const cloudActorSchema = v.object({
|
|
545
|
+
userId: v.string(),
|
|
546
|
+
email: v.pipe(v.string(), v.email()),
|
|
547
|
+
name: v.string()
|
|
548
|
+
});
|
|
549
|
+
v.object({ user: cloudActorSchema });
|
|
550
|
+
v.object({
|
|
551
|
+
bytesUsed: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
552
|
+
objectCount: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
553
|
+
documentCount: v.pipe(v.number(), v.integer(), v.minValue(0))
|
|
554
|
+
});
|
|
555
|
+
const createDocumentSchema = v.object({
|
|
556
|
+
id: v.optional(v.pipe(v.string(), v.uuid())),
|
|
557
|
+
name: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(255))
|
|
558
|
+
});
|
|
559
|
+
v.object({
|
|
560
|
+
baseRevisionId: v.nullable(v.pipe(v.string(), v.uuid())),
|
|
561
|
+
byteSize: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(CLOUD_PROTOCOL_MAX_UPLOAD_BYTES)),
|
|
562
|
+
checksum: checksumSchema,
|
|
563
|
+
contentType: v.literal("application/octet-stream")
|
|
564
|
+
});
|
|
565
|
+
const imageSizeSchema = v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(CLOUD_PROTOCOL_MAX_UPLOAD_BYTES));
|
|
566
|
+
/** Where a client puts an object: one presigned PUT, or the parts of a multipart upload. */
|
|
567
|
+
const objectUploadSchema = v.variant("kind", [v.object({
|
|
568
|
+
kind: v.literal("single"),
|
|
569
|
+
url: v.pipe(v.string(), v.url()),
|
|
570
|
+
method: v.literal("PUT"),
|
|
571
|
+
headers: v.record(v.string(), v.string()),
|
|
572
|
+
expiresAt: v.string()
|
|
573
|
+
}), v.object({
|
|
574
|
+
kind: v.literal("multipart"),
|
|
575
|
+
uploadId: v.string(),
|
|
576
|
+
partSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
577
|
+
parts: v.array(v.object({
|
|
578
|
+
partNumber: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
579
|
+
url: v.pipe(v.string(), v.url()),
|
|
580
|
+
method: v.literal("PUT"),
|
|
581
|
+
headers: v.record(v.string(), v.string())
|
|
582
|
+
})),
|
|
583
|
+
expiresAt: v.string()
|
|
584
|
+
})]);
|
|
585
|
+
v.object({
|
|
586
|
+
checksum: checksumSchema,
|
|
587
|
+
uploadId: v.pipe(v.string(), v.uuid()),
|
|
588
|
+
upload: objectUploadSchema
|
|
589
|
+
});
|
|
590
|
+
v.object({ images: v.pipe(v.array(v.object({
|
|
591
|
+
checksum: checksumSchema,
|
|
592
|
+
byteSize: imageSizeSchema
|
|
593
|
+
})), v.minLength(1), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)) });
|
|
594
|
+
const completedUploadPartSchema = v.object({
|
|
595
|
+
partNumber: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(1e4)),
|
|
596
|
+
etag: v.pipe(v.string(), v.minLength(1), v.maxLength(255))
|
|
597
|
+
});
|
|
598
|
+
const commitUploadSchema = v.object({
|
|
599
|
+
checksum: checksumSchema,
|
|
600
|
+
/** The document title captured with this revision; omitted by older clients. */
|
|
601
|
+
name: v.optional(createDocumentSchema.entries.name),
|
|
602
|
+
multipart: v.optional(v.object({
|
|
603
|
+
uploadId: v.pipe(v.string(), v.minLength(1)),
|
|
604
|
+
parts: v.pipe(v.array(completedUploadPartSchema), v.minLength(1), v.maxLength(1e4))
|
|
605
|
+
})),
|
|
606
|
+
/** The images the uploaded file leaves out, each stored in the workspace or uploaded before. */
|
|
607
|
+
images: v.optional(v.pipe(v.array(v.object({
|
|
608
|
+
name: imageNameSchema,
|
|
609
|
+
checksum: checksumSchema
|
|
610
|
+
})), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)), [])
|
|
611
|
+
});
|
|
612
|
+
v.object({ uploads: v.pipe(v.array(v.object({
|
|
613
|
+
uploadId: v.pipe(v.string(), v.uuid()),
|
|
614
|
+
checksum: checksumSchema,
|
|
615
|
+
multipart: commitUploadSchema.entries.multipart
|
|
616
|
+
})), v.minLength(1), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)) });
|
|
617
|
+
//#endregion
|
|
618
|
+
//#region src/email/schema.ts
|
|
619
|
+
const documentInvitationEmailPayloadSchema = v.object({
|
|
620
|
+
inviterName: v.string(),
|
|
621
|
+
documentName: v.string(),
|
|
622
|
+
permission: documentPermissionSchema,
|
|
623
|
+
expiresAt: v.string(),
|
|
624
|
+
acceptanceURL: v.string()
|
|
625
|
+
});
|
|
626
|
+
const workspaceInvitationEmailPayloadSchema = v.object({
|
|
627
|
+
inviterName: v.string(),
|
|
628
|
+
workspaceName: v.string(),
|
|
629
|
+
role: workspaceRoleSchema,
|
|
630
|
+
expiresAt: v.string(),
|
|
631
|
+
acceptanceURL: v.string()
|
|
632
|
+
});
|
|
633
|
+
const enrollmentEmailPayloadSchema = v.object({
|
|
634
|
+
name: v.string(),
|
|
635
|
+
actionURL: v.string()
|
|
636
|
+
});
|
|
637
|
+
const adminEnrollmentNotificationPayloadSchema = v.object({
|
|
638
|
+
requesterEmail: v.string(),
|
|
639
|
+
requesterName: v.string(),
|
|
640
|
+
reason: v.string(),
|
|
641
|
+
actionURL: v.string()
|
|
642
|
+
});
|
|
643
|
+
const authenticationEmailPayloadSchema = v.object({
|
|
644
|
+
name: v.string(),
|
|
645
|
+
actionURL: v.optional(v.string()),
|
|
646
|
+
/** What a verification link confirms: a new account, or a new address for one. */
|
|
647
|
+
purpose: v.optional(v.picklist(["account", "change"]))
|
|
648
|
+
});
|
|
649
|
+
const emailChangeRequestedPayloadSchema = v.object({
|
|
650
|
+
name: v.string(),
|
|
651
|
+
newEmail: v.string(),
|
|
652
|
+
actionURL: v.string()
|
|
653
|
+
});
|
|
654
|
+
const newSignInPayloadSchema = v.object({
|
|
655
|
+
name: v.string(),
|
|
656
|
+
signedInAt: v.string(),
|
|
657
|
+
ipAddress: v.nullable(v.string()),
|
|
658
|
+
browser: v.nullable(v.string()),
|
|
659
|
+
system: v.nullable(v.string()),
|
|
660
|
+
desktop: v.boolean(),
|
|
661
|
+
actionURL: v.string()
|
|
662
|
+
});
|
|
663
|
+
/** What changed about how an account proves it is its owner's. */
|
|
664
|
+
const twoStepChangeSchema = v.picklist([
|
|
665
|
+
"authenticator-on",
|
|
666
|
+
"authenticator-off",
|
|
667
|
+
"passkey-added",
|
|
668
|
+
"passkey-removed",
|
|
669
|
+
"reset-by-administrator"
|
|
670
|
+
]);
|
|
671
|
+
const twoStepChangedPayloadSchema = v.object({
|
|
672
|
+
name: v.string(),
|
|
673
|
+
change: twoStepChangeSchema,
|
|
674
|
+
actionURL: v.string()
|
|
675
|
+
});
|
|
676
|
+
function content(kind, payload) {
|
|
677
|
+
return v.object({
|
|
678
|
+
kind: v.literal(kind),
|
|
679
|
+
payload
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
const transactionalEmailContentSchema = v.variant("kind", [
|
|
683
|
+
content("document-invitation", documentInvitationEmailPayloadSchema),
|
|
684
|
+
content("workspace-invitation", workspaceInvitationEmailPayloadSchema),
|
|
685
|
+
content("enrollment-requested", enrollmentEmailPayloadSchema),
|
|
686
|
+
content("admin-enrollment-notification", adminEnrollmentNotificationPayloadSchema),
|
|
687
|
+
content("enrollment-approved", enrollmentEmailPayloadSchema),
|
|
688
|
+
content("enrollment-rejected", enrollmentEmailPayloadSchema),
|
|
689
|
+
content("enrollment-revoked", enrollmentEmailPayloadSchema),
|
|
690
|
+
content("email-verification", authenticationEmailPayloadSchema),
|
|
691
|
+
content("password-reset", authenticationEmailPayloadSchema),
|
|
692
|
+
content("password-changed", authenticationEmailPayloadSchema),
|
|
693
|
+
content("email-change-requested", emailChangeRequestedPayloadSchema),
|
|
694
|
+
content("new-sign-in", newSignInPayloadSchema),
|
|
695
|
+
content("two-step-changed", twoStepChangedPayloadSchema)
|
|
696
|
+
]);
|
|
697
|
+
//#endregion
|
|
698
|
+
export { renderTransactionalEmail, transactionalEmailContentSchema };
|
|
699
|
+
|
|
700
|
+
//# sourceMappingURL=email.js.map
|