@pairdraw/cloud 0.0.0-stage → 0.16.0
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 +120 -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
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import * as v from 'valibot'
|
|
2
|
+
|
|
3
|
+
export const workspaceRoleSchema = v.picklist(['viewer', 'editor', 'admin'])
|
|
4
|
+
export type WorkspaceRole = v.InferOutput<typeof workspaceRoleSchema>
|
|
5
|
+
|
|
6
|
+
export const workspaceSummarySchema = v.object({
|
|
7
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
8
|
+
name: v.string(),
|
|
9
|
+
slug: v.string(),
|
|
10
|
+
role: workspaceRoleSchema,
|
|
11
|
+
createdAt: v.string(),
|
|
12
|
+
updatedAt: v.string()
|
|
13
|
+
})
|
|
14
|
+
export type WorkspaceSummary = v.InferOutput<typeof workspaceSummarySchema>
|
|
15
|
+
|
|
16
|
+
export const createWorkspaceSchema = v.object({
|
|
17
|
+
name: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(100)),
|
|
18
|
+
slug: v.optional(
|
|
19
|
+
v.pipe(
|
|
20
|
+
v.string(),
|
|
21
|
+
v.trim(),
|
|
22
|
+
v.minLength(3),
|
|
23
|
+
v.maxLength(63),
|
|
24
|
+
v.regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/)
|
|
25
|
+
)
|
|
26
|
+
)
|
|
27
|
+
})
|
|
28
|
+
export type CreateWorkspaceInput = v.InferOutput<typeof createWorkspaceSchema>
|
|
29
|
+
|
|
30
|
+
export const workspaceListSchema = v.object({
|
|
31
|
+
workspaces: v.array(workspaceSummarySchema)
|
|
32
|
+
})
|
|
33
|
+
export type WorkspaceList = v.InferOutput<typeof workspaceListSchema>
|
|
34
|
+
|
|
35
|
+
export const updateWorkspaceSchema = v.object({
|
|
36
|
+
name: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(100))
|
|
37
|
+
})
|
|
38
|
+
export type UpdateWorkspaceInput = v.InferOutput<typeof updateWorkspaceSchema>
|
|
39
|
+
|
|
40
|
+
/** Someone who belongs to a workspace, and what they may do in it. */
|
|
41
|
+
export const workspaceMemberSchema = v.object({
|
|
42
|
+
userId: v.string(),
|
|
43
|
+
name: v.string(),
|
|
44
|
+
email: v.string(),
|
|
45
|
+
image: v.nullable(v.string()),
|
|
46
|
+
role: workspaceRoleSchema,
|
|
47
|
+
joinedAt: v.string()
|
|
48
|
+
})
|
|
49
|
+
export type WorkspaceMember = v.InferOutput<typeof workspaceMemberSchema>
|
|
50
|
+
|
|
51
|
+
/** An invitation to join a workspace that has not been accepted yet. */
|
|
52
|
+
export const workspaceInvitationSchema = v.object({
|
|
53
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
54
|
+
email: v.string(),
|
|
55
|
+
role: workspaceRoleSchema,
|
|
56
|
+
/** Who sent it; the name is null once their account is gone. */
|
|
57
|
+
invitedBy: v.object({ id: v.string(), name: v.nullable(v.string()) }),
|
|
58
|
+
invitedAt: v.string(),
|
|
59
|
+
expiresAt: v.string()
|
|
60
|
+
})
|
|
61
|
+
export type WorkspaceInvitation = v.InferOutput<typeof workspaceInvitationSchema>
|
|
62
|
+
|
|
63
|
+
export const workspaceMembersSchema = v.object({
|
|
64
|
+
members: v.array(workspaceMemberSchema),
|
|
65
|
+
/** Only administrators see pending invitations. */
|
|
66
|
+
invitations: v.array(workspaceInvitationSchema)
|
|
67
|
+
})
|
|
68
|
+
export type WorkspaceMembers = v.InferOutput<typeof workspaceMembersSchema>
|
|
69
|
+
|
|
70
|
+
export const createWorkspaceInvitationSchema = v.object({
|
|
71
|
+
email: v.pipe(v.string(), v.trim(), v.toLowerCase(), v.email()),
|
|
72
|
+
role: workspaceRoleSchema
|
|
73
|
+
})
|
|
74
|
+
export type CreateWorkspaceInvitationInput = v.InferOutput<typeof createWorkspaceInvitationSchema>
|
|
75
|
+
|
|
76
|
+
/** A new invitation and its link, for an administrator to pass on when email is off. */
|
|
77
|
+
export const createdWorkspaceInvitationSchema = v.object({
|
|
78
|
+
invitation: workspaceInvitationSchema,
|
|
79
|
+
acceptanceURL: v.string()
|
|
80
|
+
})
|
|
81
|
+
export type CreatedWorkspaceInvitation = v.InferOutput<typeof createdWorkspaceInvitationSchema>
|
|
82
|
+
|
|
83
|
+
export const updateWorkspaceMemberSchema = v.object({ role: workspaceRoleSchema })
|
|
84
|
+
export type UpdateWorkspaceMemberInput = v.InferOutput<typeof updateWorkspaceMemberSchema>
|
|
85
|
+
|
|
86
|
+
export function parseCreateWorkspace(input: unknown): CreateWorkspaceInput {
|
|
87
|
+
return v.parse(createWorkspaceSchema, input)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function parseUpdateWorkspace(input: unknown): UpdateWorkspaceInput {
|
|
91
|
+
return v.parse(updateWorkspaceSchema, input)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function parseCreateWorkspaceInvitation(input: unknown): CreateWorkspaceInvitationInput {
|
|
95
|
+
return v.parse(createWorkspaceInvitationSchema, input)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function parseUpdateWorkspaceMember(input: unknown): UpdateWorkspaceMemberInput {
|
|
99
|
+
return v.parse(updateWorkspaceMemberSchema, input)
|
|
100
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { renderTransactionalEmail } from './render'
|
|
2
|
+
export { transactionalEmailContentSchema } from './schema'
|
|
3
|
+
export type {
|
|
4
|
+
AdminEnrollmentNotificationPayload,
|
|
5
|
+
DocumentInvitationEmailPayload,
|
|
6
|
+
EnrollmentEmailPayload,
|
|
7
|
+
RenderedTransactionalEmail,
|
|
8
|
+
TransactionalEmailContent,
|
|
9
|
+
TransactionalEmailKind,
|
|
10
|
+
TransactionalEmailMessage,
|
|
11
|
+
TransactionalEmailPayloadByKind,
|
|
12
|
+
TwoStepChange
|
|
13
|
+
} from './schema'
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { render } from '@vue-email/render'
|
|
2
|
+
import { compact } from 'es-toolkit'
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
AdminEnrollmentNotificationPayload,
|
|
6
|
+
AuthenticationEmailPayload,
|
|
7
|
+
DocumentInvitationEmailPayload,
|
|
8
|
+
EmailChangeRequestedPayload,
|
|
9
|
+
EnrollmentEmailPayload,
|
|
10
|
+
NewSignInPayload,
|
|
11
|
+
RenderedTransactionalEmail,
|
|
12
|
+
TransactionalEmailContent,
|
|
13
|
+
TransactionalEmailKind,
|
|
14
|
+
TwoStepChange,
|
|
15
|
+
TwoStepChangedPayload,
|
|
16
|
+
WorkspaceInvitationEmailPayload
|
|
17
|
+
} from './schema'
|
|
18
|
+
import { DocumentInvitationEmail } from './templates/document-invitation'
|
|
19
|
+
import { EnrollmentEmail } from './templates/enrollment'
|
|
20
|
+
|
|
21
|
+
/** An email's template, its props, and its subject, before rendering. */
|
|
22
|
+
type EmailDraft = {
|
|
23
|
+
component: Parameters<typeof render>[0]
|
|
24
|
+
props: Record<string, string | undefined>
|
|
25
|
+
subject: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function toDraft(
|
|
29
|
+
component: EmailDraft['component'],
|
|
30
|
+
props: EmailDraft['props'],
|
|
31
|
+
subject: string
|
|
32
|
+
): EmailDraft {
|
|
33
|
+
return { component, props, subject }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const DOCUMENT_PERMISSION_LABELS = {
|
|
37
|
+
edit: 'edit',
|
|
38
|
+
comment: 'view and comment on',
|
|
39
|
+
view: 'view'
|
|
40
|
+
} as const
|
|
41
|
+
|
|
42
|
+
function draftDocumentInvitation(payload: DocumentInvitationEmailPayload) {
|
|
43
|
+
const permissionLabel = DOCUMENT_PERMISSION_LABELS[payload.permission]
|
|
44
|
+
return toDraft(
|
|
45
|
+
DocumentInvitationEmail,
|
|
46
|
+
{
|
|
47
|
+
inviterName: payload.inviterName,
|
|
48
|
+
documentName: payload.documentName,
|
|
49
|
+
permissionLabel,
|
|
50
|
+
expiresAt: new Date(payload.expiresAt).toUTCString(),
|
|
51
|
+
acceptanceURL: payload.acceptanceURL
|
|
52
|
+
},
|
|
53
|
+
`${payload.inviterName} invited you to ${permissionLabel} ${payload.documentName}`
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const WORKSPACE_ROLE_LABELS = { admin: 'manage', editor: 'edit in', viewer: 'view' } as const
|
|
58
|
+
|
|
59
|
+
function draftWorkspaceInvitation(payload: WorkspaceInvitationEmailPayload) {
|
|
60
|
+
const action = WORKSPACE_ROLE_LABELS[payload.role]
|
|
61
|
+
return toDraft(
|
|
62
|
+
EnrollmentEmail,
|
|
63
|
+
{
|
|
64
|
+
heading: `Join ${payload.workspaceName}`,
|
|
65
|
+
preview: `${payload.inviterName} invited you to ${payload.workspaceName}`,
|
|
66
|
+
message: `${payload.inviterName} invited you to ${action} the workspace “${payload.workspaceName}” on Pairdraw Cloud. You will see its documents on Home once you join.`,
|
|
67
|
+
actionLabel: 'Join workspace',
|
|
68
|
+
actionURL: payload.acceptanceURL,
|
|
69
|
+
footer: `This invitation expires ${new Date(payload.expiresAt).toUTCString()}.`
|
|
70
|
+
},
|
|
71
|
+
`${payload.inviterName} invited you to ${payload.workspaceName}`
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
type EnrollmentMessageKind = Exclude<
|
|
76
|
+
TransactionalEmailKind,
|
|
77
|
+
| 'document-invitation'
|
|
78
|
+
| 'workspace-invitation'
|
|
79
|
+
| 'admin-enrollment-notification'
|
|
80
|
+
| 'email-verification'
|
|
81
|
+
| 'password-reset'
|
|
82
|
+
| 'password-changed'
|
|
83
|
+
| 'email-change-requested'
|
|
84
|
+
| 'new-sign-in'
|
|
85
|
+
| 'two-step-changed'
|
|
86
|
+
>
|
|
87
|
+
|
|
88
|
+
type EnrollmentCopy = {
|
|
89
|
+
subject: string
|
|
90
|
+
heading: string
|
|
91
|
+
preview: string
|
|
92
|
+
message: string
|
|
93
|
+
actionLabel: string
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const ENROLLMENT_COPY: Record<EnrollmentMessageKind, Omit<EnrollmentCopy, 'message'>> = {
|
|
97
|
+
'enrollment-requested': {
|
|
98
|
+
subject: 'We received your Pairdraw Cloud request',
|
|
99
|
+
heading: 'Request received',
|
|
100
|
+
preview: 'Your Pairdraw Cloud access request is awaiting review.',
|
|
101
|
+
actionLabel: 'Open Pairdraw Cloud'
|
|
102
|
+
},
|
|
103
|
+
'enrollment-approved': {
|
|
104
|
+
subject: 'Your Pairdraw Cloud access is ready',
|
|
105
|
+
heading: 'Access approved',
|
|
106
|
+
preview: 'You can now sign in to Pairdraw Cloud.',
|
|
107
|
+
actionLabel: 'Sign in'
|
|
108
|
+
},
|
|
109
|
+
'enrollment-rejected': {
|
|
110
|
+
subject: 'Your Pairdraw Cloud request was reviewed',
|
|
111
|
+
heading: 'Request reviewed',
|
|
112
|
+
preview: 'Your current access request was not approved.',
|
|
113
|
+
actionLabel: 'Request access again'
|
|
114
|
+
},
|
|
115
|
+
'enrollment-revoked': {
|
|
116
|
+
subject: 'Your Pairdraw Cloud access has changed',
|
|
117
|
+
heading: 'Access changed',
|
|
118
|
+
preview: 'Your Pairdraw Cloud access is no longer active.',
|
|
119
|
+
actionLabel: 'Open Pairdraw'
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function enrollmentCopy(kind: EnrollmentMessageKind, name: string): EnrollmentCopy {
|
|
124
|
+
const copy = ENROLLMENT_COPY[kind]
|
|
125
|
+
const messages: Record<EnrollmentMessageKind, string> = {
|
|
126
|
+
'enrollment-requested': `Hi ${name}, your request is awaiting manual review.`,
|
|
127
|
+
'enrollment-approved': `Hi ${name}, your access request was approved.`,
|
|
128
|
+
'enrollment-rejected': `Hi ${name}, your current access request was not approved.`,
|
|
129
|
+
'enrollment-revoked': `Hi ${name}, your Cloud access is no longer active.`
|
|
130
|
+
}
|
|
131
|
+
return { ...copy, message: messages[kind] }
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function draftEnrollment(kind: EnrollmentMessageKind, payload: EnrollmentEmailPayload) {
|
|
135
|
+
const copy = enrollmentCopy(kind, payload.name)
|
|
136
|
+
return toDraft(EnrollmentEmail, { ...copy, actionURL: payload.actionURL }, copy.subject)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function draftAdminNotification(payload: AdminEnrollmentNotificationPayload) {
|
|
140
|
+
return toDraft(
|
|
141
|
+
EnrollmentEmail,
|
|
142
|
+
{
|
|
143
|
+
heading: 'New Cloud access request',
|
|
144
|
+
preview: `${payload.requesterEmail} requested Pairdraw Cloud access.`,
|
|
145
|
+
message: `${payload.requesterName} (${payload.requesterEmail}) requested access. ${payload.reason}`,
|
|
146
|
+
actionLabel: 'Review request',
|
|
147
|
+
actionURL: payload.actionURL
|
|
148
|
+
},
|
|
149
|
+
'New Pairdraw Cloud access request'
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function draftAuthentication(
|
|
154
|
+
kind: 'email-verification' | 'password-reset' | 'password-changed',
|
|
155
|
+
payload: AuthenticationEmailPayload
|
|
156
|
+
) {
|
|
157
|
+
const copy = {
|
|
158
|
+
'email-verification':
|
|
159
|
+
payload.purpose === 'change'
|
|
160
|
+
? {
|
|
161
|
+
subject: 'Confirm your new Pairdraw Cloud email',
|
|
162
|
+
heading: 'Confirm your new email',
|
|
163
|
+
preview: 'One click to move your Pairdraw Cloud account to this address.',
|
|
164
|
+
message: `Hi ${payload.name}, confirm this address to make it your Pairdraw Cloud account’s email. Your old address stays until you do.`,
|
|
165
|
+
actionLabel: 'Confirm email',
|
|
166
|
+
footer: 'Didn’t ask for this? Ignore this email and nothing changes.'
|
|
167
|
+
}
|
|
168
|
+
: {
|
|
169
|
+
subject: 'Confirm your Pairdraw Cloud email',
|
|
170
|
+
heading: 'Confirm your email',
|
|
171
|
+
preview: 'One click to finish creating your Pairdraw Cloud account.',
|
|
172
|
+
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.`,
|
|
173
|
+
actionLabel: 'Confirm email',
|
|
174
|
+
footer: 'Didn’t create an account? Ignore this email and nothing happens.'
|
|
175
|
+
},
|
|
176
|
+
'password-reset': {
|
|
177
|
+
subject: 'Reset your Pairdraw Cloud password',
|
|
178
|
+
heading: 'Reset your password',
|
|
179
|
+
preview: 'Use this secure link to choose a new password.',
|
|
180
|
+
message: `Hi ${payload.name}, use the link below to choose a new password.`,
|
|
181
|
+
actionLabel: 'Reset password',
|
|
182
|
+
footer: 'Didn’t ask for this? Ignore this email and your password stays the same.'
|
|
183
|
+
},
|
|
184
|
+
'password-changed': {
|
|
185
|
+
subject: 'Your Pairdraw Cloud password changed',
|
|
186
|
+
heading: 'Password changed',
|
|
187
|
+
preview: 'Your Pairdraw Cloud password was changed.',
|
|
188
|
+
message: `Hi ${payload.name}, your password was changed. If this was not you, contact your administrator.`,
|
|
189
|
+
actionLabel: 'Open Pairdraw Cloud'
|
|
190
|
+
}
|
|
191
|
+
}[kind]
|
|
192
|
+
return toDraft(EnrollmentEmail, { ...copy, actionURL: payload.actionURL ?? '#' }, copy.subject)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function draftEmailChangeRequested(payload: EmailChangeRequestedPayload) {
|
|
196
|
+
return toDraft(
|
|
197
|
+
EnrollmentEmail,
|
|
198
|
+
{
|
|
199
|
+
heading: 'Your email is changing',
|
|
200
|
+
preview: `Your Pairdraw Cloud email is changing to ${payload.newEmail}.`,
|
|
201
|
+
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.`,
|
|
202
|
+
actionLabel: 'Review your account',
|
|
203
|
+
actionURL: payload.actionURL
|
|
204
|
+
},
|
|
205
|
+
'Your Pairdraw Cloud email is changing'
|
|
206
|
+
)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function draftNewSignIn(payload: NewSignInPayload) {
|
|
210
|
+
const device = payload.desktop
|
|
211
|
+
? 'the Pairdraw app'
|
|
212
|
+
: compact([payload.browser, payload.system]).join(' on ') || 'an unknown browser'
|
|
213
|
+
const place = payload.ipAddress ? ` from ${payload.ipAddress}` : ''
|
|
214
|
+
return toDraft(
|
|
215
|
+
EnrollmentEmail,
|
|
216
|
+
{
|
|
217
|
+
heading: 'New sign-in to your account',
|
|
218
|
+
preview: `Your Pairdraw Cloud account was signed in to with ${device}.`,
|
|
219
|
+
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.`,
|
|
220
|
+
actionLabel: 'Review sessions',
|
|
221
|
+
actionURL: payload.actionURL
|
|
222
|
+
},
|
|
223
|
+
'New sign-in to your Pairdraw Cloud account'
|
|
224
|
+
)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const TWO_STEP_COPY: Record<TwoStepChange, { heading: string; message: string }> = {
|
|
228
|
+
'authenticator-on': {
|
|
229
|
+
heading: 'Authenticator app turned on',
|
|
230
|
+
message: 'an authenticator app now confirms your sign-ins.'
|
|
231
|
+
},
|
|
232
|
+
'authenticator-off': {
|
|
233
|
+
heading: 'Authenticator app turned off',
|
|
234
|
+
message: 'your sign-ins no longer ask for a code from an authenticator app.'
|
|
235
|
+
},
|
|
236
|
+
'passkey-added': {
|
|
237
|
+
heading: 'Passkey added',
|
|
238
|
+
message: 'a passkey was added to your account.'
|
|
239
|
+
},
|
|
240
|
+
'passkey-removed': {
|
|
241
|
+
heading: 'Passkey removed',
|
|
242
|
+
message: 'a passkey was removed from your account.'
|
|
243
|
+
},
|
|
244
|
+
'reset-by-administrator': {
|
|
245
|
+
heading: 'Two-step sign-in was reset',
|
|
246
|
+
message:
|
|
247
|
+
'an administrator removed your authenticator app, recovery codes, and passkeys, so you can set them up again.'
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function draftTwoStepChanged(payload: TwoStepChangedPayload) {
|
|
252
|
+
const copy = TWO_STEP_COPY[payload.change]
|
|
253
|
+
return toDraft(
|
|
254
|
+
EnrollmentEmail,
|
|
255
|
+
{
|
|
256
|
+
heading: copy.heading,
|
|
257
|
+
preview: `${copy.heading} on your Pairdraw Cloud account.`,
|
|
258
|
+
message: `Hi ${payload.name}, ${copy.message} If this wasn’t you, change your password and contact your administrator.`,
|
|
259
|
+
actionLabel: 'Review security',
|
|
260
|
+
actionURL: payload.actionURL
|
|
261
|
+
},
|
|
262
|
+
`${copy.heading} on your Pairdraw Cloud account`
|
|
263
|
+
)
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function draft(content: TransactionalEmailContent): EmailDraft {
|
|
267
|
+
if (content.kind === 'document-invitation') return draftDocumentInvitation(content.payload)
|
|
268
|
+
if (content.kind === 'workspace-invitation') return draftWorkspaceInvitation(content.payload)
|
|
269
|
+
if (content.kind === 'admin-enrollment-notification') {
|
|
270
|
+
return draftAdminNotification(content.payload)
|
|
271
|
+
}
|
|
272
|
+
if (
|
|
273
|
+
content.kind === 'email-verification' ||
|
|
274
|
+
content.kind === 'password-reset' ||
|
|
275
|
+
content.kind === 'password-changed'
|
|
276
|
+
) {
|
|
277
|
+
return draftAuthentication(content.kind, content.payload)
|
|
278
|
+
}
|
|
279
|
+
if (content.kind === 'email-change-requested') return draftEmailChangeRequested(content.payload)
|
|
280
|
+
if (content.kind === 'new-sign-in') return draftNewSignIn(content.payload)
|
|
281
|
+
if (content.kind === 'two-step-changed') return draftTwoStepChanged(content.payload)
|
|
282
|
+
return draftEnrollment(content.kind, content.payload)
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export type TransactionalEmailOptions = {
|
|
286
|
+
/**
|
|
287
|
+
* The sending server's public address: its site serves the logo, and the footer links to it.
|
|
288
|
+
* Without it the email carries neither.
|
|
289
|
+
*/
|
|
290
|
+
site?: string
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export async function renderTransactionalEmail(
|
|
294
|
+
content: TransactionalEmailContent,
|
|
295
|
+
options: TransactionalEmailOptions = {}
|
|
296
|
+
): Promise<RenderedTransactionalEmail> {
|
|
297
|
+
const { component, props, subject } = draft(content)
|
|
298
|
+
const withSite = { ...props, site: options.site }
|
|
299
|
+
const [html, text] = await Promise.all([
|
|
300
|
+
render(component, withSite),
|
|
301
|
+
render(component, withSite, { plainText: true })
|
|
302
|
+
])
|
|
303
|
+
return { subject, html, text }
|
|
304
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { documentPermissionSchema, workspaceRoleSchema } from '#cloud/contract'
|
|
2
|
+
import * as v from 'valibot'
|
|
3
|
+
|
|
4
|
+
export type TransactionalEmailKind =
|
|
5
|
+
| 'document-invitation'
|
|
6
|
+
| 'workspace-invitation'
|
|
7
|
+
| 'enrollment-requested'
|
|
8
|
+
| 'admin-enrollment-notification'
|
|
9
|
+
| 'enrollment-approved'
|
|
10
|
+
| 'enrollment-rejected'
|
|
11
|
+
| 'enrollment-revoked'
|
|
12
|
+
| 'email-verification'
|
|
13
|
+
| 'password-reset'
|
|
14
|
+
| 'password-changed'
|
|
15
|
+
| 'email-change-requested'
|
|
16
|
+
| 'new-sign-in'
|
|
17
|
+
| 'two-step-changed'
|
|
18
|
+
|
|
19
|
+
const documentInvitationEmailPayloadSchema = v.object({
|
|
20
|
+
inviterName: v.string(),
|
|
21
|
+
documentName: v.string(),
|
|
22
|
+
permission: documentPermissionSchema,
|
|
23
|
+
expiresAt: v.string(),
|
|
24
|
+
acceptanceURL: v.string()
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const workspaceInvitationEmailPayloadSchema = v.object({
|
|
28
|
+
inviterName: v.string(),
|
|
29
|
+
workspaceName: v.string(),
|
|
30
|
+
role: workspaceRoleSchema,
|
|
31
|
+
expiresAt: v.string(),
|
|
32
|
+
acceptanceURL: v.string()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const enrollmentEmailPayloadSchema = v.object({
|
|
36
|
+
name: v.string(),
|
|
37
|
+
actionURL: v.string()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const adminEnrollmentNotificationPayloadSchema = v.object({
|
|
41
|
+
requesterEmail: v.string(),
|
|
42
|
+
requesterName: v.string(),
|
|
43
|
+
reason: v.string(),
|
|
44
|
+
actionURL: v.string()
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const authenticationEmailPayloadSchema = v.object({
|
|
48
|
+
name: v.string(),
|
|
49
|
+
actionURL: v.optional(v.string()),
|
|
50
|
+
/** What a verification link confirms: a new account, or a new address for one. */
|
|
51
|
+
purpose: v.optional(v.picklist(['account', 'change']))
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const emailChangeRequestedPayloadSchema = v.object({
|
|
55
|
+
name: v.string(),
|
|
56
|
+
newEmail: v.string(),
|
|
57
|
+
actionURL: v.string()
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
const newSignInPayloadSchema = v.object({
|
|
61
|
+
name: v.string(),
|
|
62
|
+
signedInAt: v.string(),
|
|
63
|
+
ipAddress: v.nullable(v.string()),
|
|
64
|
+
browser: v.nullable(v.string()),
|
|
65
|
+
system: v.nullable(v.string()),
|
|
66
|
+
desktop: v.boolean(),
|
|
67
|
+
actionURL: v.string()
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
/** What changed about how an account proves it is its owner's. */
|
|
71
|
+
const twoStepChangeSchema = v.picklist([
|
|
72
|
+
'authenticator-on',
|
|
73
|
+
'authenticator-off',
|
|
74
|
+
'passkey-added',
|
|
75
|
+
'passkey-removed',
|
|
76
|
+
'reset-by-administrator'
|
|
77
|
+
])
|
|
78
|
+
|
|
79
|
+
const twoStepChangedPayloadSchema = v.object({
|
|
80
|
+
name: v.string(),
|
|
81
|
+
change: twoStepChangeSchema,
|
|
82
|
+
actionURL: v.string()
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
function content<const Kind extends TransactionalEmailKind, Payload extends v.GenericSchema>(
|
|
86
|
+
kind: Kind,
|
|
87
|
+
payload: Payload
|
|
88
|
+
) {
|
|
89
|
+
return v.object({ kind: v.literal(kind), payload })
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export const transactionalEmailContentSchema = v.variant('kind', [
|
|
93
|
+
content('document-invitation', documentInvitationEmailPayloadSchema),
|
|
94
|
+
content('workspace-invitation', workspaceInvitationEmailPayloadSchema),
|
|
95
|
+
content('enrollment-requested', enrollmentEmailPayloadSchema),
|
|
96
|
+
content('admin-enrollment-notification', adminEnrollmentNotificationPayloadSchema),
|
|
97
|
+
content('enrollment-approved', enrollmentEmailPayloadSchema),
|
|
98
|
+
content('enrollment-rejected', enrollmentEmailPayloadSchema),
|
|
99
|
+
content('enrollment-revoked', enrollmentEmailPayloadSchema),
|
|
100
|
+
content('email-verification', authenticationEmailPayloadSchema),
|
|
101
|
+
content('password-reset', authenticationEmailPayloadSchema),
|
|
102
|
+
content('password-changed', authenticationEmailPayloadSchema),
|
|
103
|
+
content('email-change-requested', emailChangeRequestedPayloadSchema),
|
|
104
|
+
content('new-sign-in', newSignInPayloadSchema),
|
|
105
|
+
content('two-step-changed', twoStepChangedPayloadSchema)
|
|
106
|
+
])
|
|
107
|
+
|
|
108
|
+
/** A transactional email's kind with the payload that kind renders. */
|
|
109
|
+
export type TransactionalEmailContent = v.InferOutput<typeof transactionalEmailContentSchema>
|
|
110
|
+
|
|
111
|
+
export type DocumentInvitationEmailPayload = v.InferOutput<
|
|
112
|
+
typeof documentInvitationEmailPayloadSchema
|
|
113
|
+
>
|
|
114
|
+
export type WorkspaceInvitationEmailPayload = v.InferOutput<
|
|
115
|
+
typeof workspaceInvitationEmailPayloadSchema
|
|
116
|
+
>
|
|
117
|
+
export type EnrollmentEmailPayload = v.InferOutput<typeof enrollmentEmailPayloadSchema>
|
|
118
|
+
export type AdminEnrollmentNotificationPayload = v.InferOutput<
|
|
119
|
+
typeof adminEnrollmentNotificationPayloadSchema
|
|
120
|
+
>
|
|
121
|
+
export type AuthenticationEmailPayload = v.InferOutput<typeof authenticationEmailPayloadSchema>
|
|
122
|
+
export type EmailChangeRequestedPayload = v.InferOutput<typeof emailChangeRequestedPayloadSchema>
|
|
123
|
+
export type NewSignInPayload = v.InferOutput<typeof newSignInPayloadSchema>
|
|
124
|
+
export type TwoStepChange = v.InferOutput<typeof twoStepChangeSchema>
|
|
125
|
+
export type TwoStepChangedPayload = v.InferOutput<typeof twoStepChangedPayloadSchema>
|
|
126
|
+
|
|
127
|
+
export type TransactionalEmailPayloadByKind = {
|
|
128
|
+
[Kind in TransactionalEmailKind]: Extract<TransactionalEmailContent, { kind: Kind }>['payload']
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export type TransactionalEmailMessage<
|
|
132
|
+
Kind extends TransactionalEmailKind = TransactionalEmailKind
|
|
133
|
+
> = {
|
|
134
|
+
id: string
|
|
135
|
+
kind: Kind
|
|
136
|
+
recipientEmail: string
|
|
137
|
+
payload: TransactionalEmailPayloadByKind[Kind]
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export type RenderedTransactionalEmail = {
|
|
141
|
+
subject: string
|
|
142
|
+
html: string
|
|
143
|
+
text: string
|
|
144
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Body,
|
|
3
|
+
Button,
|
|
4
|
+
Container,
|
|
5
|
+
Head,
|
|
6
|
+
Heading,
|
|
7
|
+
// eslint-disable-next-line pairdraw/no-mixed-case-acronym-identifiers -- Upstream export spelling.
|
|
8
|
+
Html as HTML,
|
|
9
|
+
Img,
|
|
10
|
+
Link,
|
|
11
|
+
Preview,
|
|
12
|
+
Section,
|
|
13
|
+
Text
|
|
14
|
+
} from '@vue-email/components'
|
|
15
|
+
import { h, type VNode } from 'vue'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The ivory app-icon tile on the server's own site, which serves it beside the editor; PNG because
|
|
19
|
+
* mail clients do not draw SVG.
|
|
20
|
+
*/
|
|
21
|
+
const LOGO_PATH = '/brand/app-icon-1024.png'
|
|
22
|
+
|
|
23
|
+
const FONT = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif'
|
|
24
|
+
const INK = '#171717'
|
|
25
|
+
const MUTED = '#6B6B6B'
|
|
26
|
+
/** Deep teal from the mark; white text on it passes WCAG AA. */
|
|
27
|
+
const TEAL = '#0A6C65'
|
|
28
|
+
|
|
29
|
+
const styles = {
|
|
30
|
+
body: { backgroundColor: '#F5F5EF', fontFamily: FONT, margin: '0', padding: '40px 16px' },
|
|
31
|
+
card: {
|
|
32
|
+
maxWidth: '480px',
|
|
33
|
+
margin: '0 auto',
|
|
34
|
+
padding: '40px',
|
|
35
|
+
backgroundColor: '#FFFFFF',
|
|
36
|
+
borderRadius: '16px',
|
|
37
|
+
border: '1px solid #E7E5DC'
|
|
38
|
+
},
|
|
39
|
+
logo: { borderRadius: '10px', margin: '0 0 28px' },
|
|
40
|
+
heading: {
|
|
41
|
+
color: INK,
|
|
42
|
+
fontSize: '22px',
|
|
43
|
+
fontWeight: '600',
|
|
44
|
+
lineHeight: '1.3',
|
|
45
|
+
margin: '0 0 12px'
|
|
46
|
+
},
|
|
47
|
+
text: { color: '#404040', fontSize: '15px', lineHeight: '1.6', margin: '0 0 24px' },
|
|
48
|
+
button: {
|
|
49
|
+
backgroundColor: TEAL,
|
|
50
|
+
borderRadius: '10px',
|
|
51
|
+
color: '#FFFFFF',
|
|
52
|
+
fontSize: '15px',
|
|
53
|
+
fontWeight: '600',
|
|
54
|
+
padding: '12px 22px',
|
|
55
|
+
textDecoration: 'none'
|
|
56
|
+
},
|
|
57
|
+
note: { color: MUTED, fontSize: '13px', lineHeight: '1.6', margin: '28px 0 0' },
|
|
58
|
+
link: { color: TEAL, textDecoration: 'underline' },
|
|
59
|
+
footer: {
|
|
60
|
+
color: MUTED,
|
|
61
|
+
fontSize: '12px',
|
|
62
|
+
lineHeight: '1.6',
|
|
63
|
+
textAlign: 'center' as const,
|
|
64
|
+
margin: '24px 0 0'
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type EmailLayoutProps = {
|
|
69
|
+
/** The line mail clients show beside the subject. */
|
|
70
|
+
preview: string
|
|
71
|
+
heading: string
|
|
72
|
+
message: string
|
|
73
|
+
actionLabel: string
|
|
74
|
+
actionURL: string
|
|
75
|
+
/** Small print under the button, with an optional link at its end. */
|
|
76
|
+
note?: { text: string; link?: { label: string; url: string } }
|
|
77
|
+
/**
|
|
78
|
+
* The public address of the server that sends the email, whose site serves the logo and which
|
|
79
|
+
* the footer links to. Without it the email shows neither, so it never points anywhere else.
|
|
80
|
+
*/
|
|
81
|
+
site?: string
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function noteContent(note: NonNullable<EmailLayoutProps['note']>) {
|
|
85
|
+
if (!note.link) return note.text
|
|
86
|
+
const { label, url } = note.link
|
|
87
|
+
return [`${note.text} `, h(Link, { href: url, style: styles.link }, () => label), '.']
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The branded email Pairdraw Cloud sends. */
|
|
91
|
+
export function emailLayout(props: EmailLayoutProps): VNode {
|
|
92
|
+
const { note } = props
|
|
93
|
+
const site = props.site ? new URL(props.site) : null
|
|
94
|
+
return h(HTML, { lang: 'en' }, () => [
|
|
95
|
+
h(Head),
|
|
96
|
+
h(Preview, () => props.preview),
|
|
97
|
+
h(Body, { style: styles.body }, () => [
|
|
98
|
+
h(Container, { style: styles.card }, () => [
|
|
99
|
+
site
|
|
100
|
+
? h(Img, {
|
|
101
|
+
src: new URL(LOGO_PATH, site).href,
|
|
102
|
+
width: 44,
|
|
103
|
+
height: 44,
|
|
104
|
+
alt: 'Pairdraw',
|
|
105
|
+
style: styles.logo
|
|
106
|
+
})
|
|
107
|
+
: null,
|
|
108
|
+
h(Heading, { as: 'h1', style: styles.heading }, () => props.heading),
|
|
109
|
+
h(Text, { style: styles.text }, () => props.message),
|
|
110
|
+
h(Section, () =>
|
|
111
|
+
h(Button, { href: props.actionURL, style: styles.button }, () => props.actionLabel)
|
|
112
|
+
),
|
|
113
|
+
note ? h(Text, { style: styles.note }, () => noteContent(note)) : null
|
|
114
|
+
]),
|
|
115
|
+
h(Text, { style: styles.footer }, () =>
|
|
116
|
+
site
|
|
117
|
+
? [
|
|
118
|
+
'Pairdraw, the open-source design editor · ',
|
|
119
|
+
h(Link, { href: site.href, style: { color: MUTED } }, () => site.host)
|
|
120
|
+
]
|
|
121
|
+
: 'Pairdraw, the open-source design editor'
|
|
122
|
+
)
|
|
123
|
+
])
|
|
124
|
+
])
|
|
125
|
+
}
|