@open-pencil/cloud 0.0.0-stage → 0.17.0-beta.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 +1520 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +1917 -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 +1453 -0
- package/dist/contract2.js.map +1 -0
- package/dist/email.d.ts +169 -0
- package/dist/email.d.ts.map +1 -0
- package/dist/email.js +670 -0
- package/dist/email.js.map +1 -0
- package/dist/index.d.ts +1755 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/listen.mjs +1881 -0
- package/dist/listen.mjs.map +1 -0
- package/dist/runtime-node.d.mts +10040 -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 +12792 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +8475 -0
- package/dist/server.js.map +1 -0
- package/dist/server.mjs +8324 -0
- package/dist/server.mjs.map +1 -0
- package/dist/server2.mjs +505 -0
- package/dist/server2.mjs.map +1 -0
- package/package.json +124 -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 +28 -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 +528 -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/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/discovery.ts +81 -0
- package/src/contract/documents.ts +265 -0
- package/src/contract/entitlements.ts +28 -0
- package/src/contract/index.ts +204 -0
- package/src/contract/links.ts +87 -0
- package/src/contract/portal.ts +11 -0
- package/src/contract/relay.ts +368 -0
- package/src/contract/sharing.ts +191 -0
- package/src/contract/versions.ts +87 -0
- package/src/contract/workspaces.ts +100 -0
- package/src/email/index.ts +14 -0
- package/src/email/render.ts +276 -0
- package/src/email/schema.ts +144 -0
- package/src/email/templates/brand.ts +105 -0
- package/src/email/templates/document-invitation.ts +35 -0
- package/src/email/templates/enrollment.ts +27 -0
- package/src/email/templates/layout.ts +18 -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 +160 -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 +43 -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 +121 -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 +117 -0
- package/src/server/api/types.ts +7 -0
- package/src/server/app.ts +375 -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 +232 -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 +53 -0
- package/src/server/collaboration/relay/awareness.ts +104 -0
- package/src/server/collaboration/relay/documents.ts +39 -0
- package/src/server/collaboration/relay/hub.ts +524 -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 +188 -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_document_kind.ts +19 -0
- package/src/server/db/migrations/helpers.ts +78 -0
- package/src/server/db/tables.ts +394 -0
- package/src/server/documents/access.ts +103 -0
- package/src/server/documents/errors.ts +16 -0
- package/src/server/documents/images.ts +407 -0
- package/src/server/documents/index.ts +14 -0
- package/src/server/documents/limits.ts +57 -0
- package/src/server/documents/repository.ts +141 -0
- package/src/server/documents/routes.ts +239 -0
- package/src/server/documents/service.ts +597 -0
- package/src/server/documents/summary.ts +37 -0
- package/src/server/documents/types.ts +14 -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 +397 -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 +245 -0
- package/src/server/email/types.ts +56 -0
- package/src/server/email/worker.ts +33 -0
- package/src/server/index.ts +279 -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/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 +262 -0
- package/src/server/sharing/continuation.ts +85 -0
- package/src/server/sharing/contracts.ts +80 -0
- package/src/server/sharing/crypto.ts +48 -0
- package/src/server/sharing/document-routes.ts +41 -0
- package/src/server/sharing/errors.ts +12 -0
- package/src/server/sharing/grants/service.ts +79 -0
- package/src/server/sharing/http.ts +41 -0
- package/src/server/sharing/index.ts +39 -0
- package/src/server/sharing/invitations/service.ts +315 -0
- package/src/server/sharing/policy.ts +44 -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,14 @@
|
|
|
1
|
+
export { renderTransactionalEmail } from './render'
|
|
2
|
+
export { emailLayout, type EmailLayoutProps } from './templates/brand'
|
|
3
|
+
export { transactionalEmailContentSchema } from './schema'
|
|
4
|
+
export type {
|
|
5
|
+
AdminEnrollmentNotificationPayload,
|
|
6
|
+
DocumentInvitationEmailPayload,
|
|
7
|
+
EnrollmentEmailPayload,
|
|
8
|
+
RenderedTransactionalEmail,
|
|
9
|
+
TransactionalEmailContent,
|
|
10
|
+
TransactionalEmailKind,
|
|
11
|
+
TransactionalEmailMessage,
|
|
12
|
+
TransactionalEmailPayloadByKind,
|
|
13
|
+
TwoStepChange
|
|
14
|
+
} from './schema'
|
|
@@ -0,0 +1,276 @@
|
|
|
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
|
+
async function rendered(
|
|
22
|
+
component: Parameters<typeof render>[0],
|
|
23
|
+
props: Record<string, string | undefined>,
|
|
24
|
+
subject: string
|
|
25
|
+
): Promise<RenderedTransactionalEmail> {
|
|
26
|
+
const [html, text] = await Promise.all([
|
|
27
|
+
render(component, props),
|
|
28
|
+
render(component, props, { plainText: true })
|
|
29
|
+
])
|
|
30
|
+
return { subject, html, text }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function renderDocumentInvitation(payload: DocumentInvitationEmailPayload) {
|
|
34
|
+
const permissionLabel = payload.permission === 'edit' ? 'edit' : 'view'
|
|
35
|
+
return rendered(
|
|
36
|
+
DocumentInvitationEmail,
|
|
37
|
+
{
|
|
38
|
+
inviterName: payload.inviterName,
|
|
39
|
+
documentName: payload.documentName,
|
|
40
|
+
permissionLabel,
|
|
41
|
+
expiresAt: new Date(payload.expiresAt).toUTCString(),
|
|
42
|
+
acceptanceURL: payload.acceptanceURL
|
|
43
|
+
},
|
|
44
|
+
`${payload.inviterName} invited you to ${permissionLabel} ${payload.documentName}`
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const WORKSPACE_ROLE_LABELS = { admin: 'manage', editor: 'edit in', viewer: 'view' } as const
|
|
49
|
+
|
|
50
|
+
async function renderWorkspaceInvitation(payload: WorkspaceInvitationEmailPayload) {
|
|
51
|
+
const action = WORKSPACE_ROLE_LABELS[payload.role]
|
|
52
|
+
return rendered(
|
|
53
|
+
EnrollmentEmail,
|
|
54
|
+
{
|
|
55
|
+
heading: `Join ${payload.workspaceName}`,
|
|
56
|
+
preview: `${payload.inviterName} invited you to ${payload.workspaceName}`,
|
|
57
|
+
message: `${payload.inviterName} invited you to ${action} the workspace “${payload.workspaceName}” on OpenPencil Cloud. You will see its documents on Home once you join.`,
|
|
58
|
+
actionLabel: 'Join workspace',
|
|
59
|
+
actionURL: payload.acceptanceURL,
|
|
60
|
+
footer: `This invitation expires ${new Date(payload.expiresAt).toUTCString()}.`
|
|
61
|
+
},
|
|
62
|
+
`${payload.inviterName} invited you to ${payload.workspaceName}`
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
type EnrollmentMessageKind = Exclude<
|
|
67
|
+
TransactionalEmailKind,
|
|
68
|
+
| 'document-invitation'
|
|
69
|
+
| 'workspace-invitation'
|
|
70
|
+
| 'admin-enrollment-notification'
|
|
71
|
+
| 'email-verification'
|
|
72
|
+
| 'password-reset'
|
|
73
|
+
| 'password-changed'
|
|
74
|
+
| 'email-change-requested'
|
|
75
|
+
| 'new-sign-in'
|
|
76
|
+
| 'two-step-changed'
|
|
77
|
+
>
|
|
78
|
+
|
|
79
|
+
type EnrollmentCopy = {
|
|
80
|
+
subject: string
|
|
81
|
+
heading: string
|
|
82
|
+
preview: string
|
|
83
|
+
message: string
|
|
84
|
+
actionLabel: string
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const ENROLLMENT_COPY: Record<EnrollmentMessageKind, Omit<EnrollmentCopy, 'message'>> = {
|
|
88
|
+
'enrollment-requested': {
|
|
89
|
+
subject: 'We received your OpenPencil Cloud request',
|
|
90
|
+
heading: 'Request received',
|
|
91
|
+
preview: 'Your OpenPencil Cloud access request is awaiting review.',
|
|
92
|
+
actionLabel: 'Open OpenPencil Cloud'
|
|
93
|
+
},
|
|
94
|
+
'enrollment-approved': {
|
|
95
|
+
subject: 'Your OpenPencil Cloud access is ready',
|
|
96
|
+
heading: 'Access approved',
|
|
97
|
+
preview: 'You can now sign in to OpenPencil Cloud.',
|
|
98
|
+
actionLabel: 'Sign in'
|
|
99
|
+
},
|
|
100
|
+
'enrollment-rejected': {
|
|
101
|
+
subject: 'Your OpenPencil Cloud request was reviewed',
|
|
102
|
+
heading: 'Request reviewed',
|
|
103
|
+
preview: 'Your current access request was not approved.',
|
|
104
|
+
actionLabel: 'Request access again'
|
|
105
|
+
},
|
|
106
|
+
'enrollment-revoked': {
|
|
107
|
+
subject: 'Your OpenPencil Cloud access has changed',
|
|
108
|
+
heading: 'Access changed',
|
|
109
|
+
preview: 'Your OpenPencil Cloud access is no longer active.',
|
|
110
|
+
actionLabel: 'Open OpenPencil'
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function enrollmentCopy(kind: EnrollmentMessageKind, name: string): EnrollmentCopy {
|
|
115
|
+
const copy = ENROLLMENT_COPY[kind]
|
|
116
|
+
const messages: Record<EnrollmentMessageKind, string> = {
|
|
117
|
+
'enrollment-requested': `Hi ${name}, your request is awaiting manual review.`,
|
|
118
|
+
'enrollment-approved': `Hi ${name}, your access request was approved.`,
|
|
119
|
+
'enrollment-rejected': `Hi ${name}, your current access request was not approved.`,
|
|
120
|
+
'enrollment-revoked': `Hi ${name}, your Cloud access is no longer active.`
|
|
121
|
+
}
|
|
122
|
+
return { ...copy, message: messages[kind] }
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function renderEnrollment(kind: EnrollmentMessageKind, payload: EnrollmentEmailPayload) {
|
|
126
|
+
const copy = enrollmentCopy(kind, payload.name)
|
|
127
|
+
return rendered(EnrollmentEmail, { ...copy, actionURL: payload.actionURL }, copy.subject)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function renderAdminNotification(payload: AdminEnrollmentNotificationPayload) {
|
|
131
|
+
return rendered(
|
|
132
|
+
EnrollmentEmail,
|
|
133
|
+
{
|
|
134
|
+
heading: 'New Cloud access request',
|
|
135
|
+
preview: `${payload.requesterEmail} requested OpenPencil Cloud access.`,
|
|
136
|
+
message: `${payload.requesterName} (${payload.requesterEmail}) requested access. ${payload.reason}`,
|
|
137
|
+
actionLabel: 'Review request',
|
|
138
|
+
actionURL: payload.actionURL
|
|
139
|
+
},
|
|
140
|
+
'New OpenPencil Cloud access request'
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function renderAuthentication(
|
|
145
|
+
kind: 'email-verification' | 'password-reset' | 'password-changed',
|
|
146
|
+
payload: AuthenticationEmailPayload
|
|
147
|
+
) {
|
|
148
|
+
const copy = {
|
|
149
|
+
'email-verification':
|
|
150
|
+
payload.purpose === 'change'
|
|
151
|
+
? {
|
|
152
|
+
subject: 'Confirm your new OpenPencil Cloud email',
|
|
153
|
+
heading: 'Confirm your new email',
|
|
154
|
+
preview: 'One click to move your OpenPencil Cloud account to this address.',
|
|
155
|
+
message: `Hi ${payload.name}, confirm this address to make it your OpenPencil Cloud account’s email. Your old address stays until you do.`,
|
|
156
|
+
actionLabel: 'Confirm email',
|
|
157
|
+
footer: 'Didn’t ask for this? Ignore this email and nothing changes.'
|
|
158
|
+
}
|
|
159
|
+
: {
|
|
160
|
+
subject: 'Confirm your OpenPencil Cloud email',
|
|
161
|
+
heading: 'Confirm your email',
|
|
162
|
+
preview: 'One click to finish creating your OpenPencil Cloud account.',
|
|
163
|
+
message: `Hi ${payload.name}, confirm this address to finish creating your OpenPencil Cloud account. Then go back to OpenPencil; it signs you in by itself.`,
|
|
164
|
+
actionLabel: 'Confirm email',
|
|
165
|
+
footer: 'Didn’t create an account? Ignore this email and nothing happens.'
|
|
166
|
+
},
|
|
167
|
+
'password-reset': {
|
|
168
|
+
subject: 'Reset your OpenPencil Cloud password',
|
|
169
|
+
heading: 'Reset your password',
|
|
170
|
+
preview: 'Use this secure link to choose a new password.',
|
|
171
|
+
message: `Hi ${payload.name}, use the link below to choose a new password.`,
|
|
172
|
+
actionLabel: 'Reset password',
|
|
173
|
+
footer: 'Didn’t ask for this? Ignore this email and your password stays the same.'
|
|
174
|
+
},
|
|
175
|
+
'password-changed': {
|
|
176
|
+
subject: 'Your OpenPencil Cloud password changed',
|
|
177
|
+
heading: 'Password changed',
|
|
178
|
+
preview: 'Your OpenPencil Cloud password was changed.',
|
|
179
|
+
message: `Hi ${payload.name}, your password was changed. If this was not you, contact your administrator.`,
|
|
180
|
+
actionLabel: 'Open OpenPencil Cloud'
|
|
181
|
+
}
|
|
182
|
+
}[kind]
|
|
183
|
+
return rendered(EnrollmentEmail, { ...copy, actionURL: payload.actionURL ?? '#' }, copy.subject)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async function renderEmailChangeRequested(payload: EmailChangeRequestedPayload) {
|
|
187
|
+
return rendered(
|
|
188
|
+
EnrollmentEmail,
|
|
189
|
+
{
|
|
190
|
+
heading: 'Your email is changing',
|
|
191
|
+
preview: `Your OpenPencil Cloud email is changing to ${payload.newEmail}.`,
|
|
192
|
+
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.`,
|
|
193
|
+
actionLabel: 'Review your account',
|
|
194
|
+
actionURL: payload.actionURL
|
|
195
|
+
},
|
|
196
|
+
'Your OpenPencil Cloud email is changing'
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async function renderNewSignIn(payload: NewSignInPayload) {
|
|
201
|
+
const device = payload.desktop
|
|
202
|
+
? 'the OpenPencil app'
|
|
203
|
+
: compact([payload.browser, payload.system]).join(' on ') || 'an unknown browser'
|
|
204
|
+
const place = payload.ipAddress ? ` from ${payload.ipAddress}` : ''
|
|
205
|
+
return rendered(
|
|
206
|
+
EnrollmentEmail,
|
|
207
|
+
{
|
|
208
|
+
heading: 'New sign-in to your account',
|
|
209
|
+
preview: `Your OpenPencil Cloud account was signed in to with ${device}.`,
|
|
210
|
+
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.`,
|
|
211
|
+
actionLabel: 'Review sessions',
|
|
212
|
+
actionURL: payload.actionURL
|
|
213
|
+
},
|
|
214
|
+
'New sign-in to your OpenPencil Cloud account'
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const TWO_STEP_COPY: Record<TwoStepChange, { heading: string; message: string }> = {
|
|
219
|
+
'authenticator-on': {
|
|
220
|
+
heading: 'Authenticator app turned on',
|
|
221
|
+
message: 'an authenticator app now confirms your sign-ins.'
|
|
222
|
+
},
|
|
223
|
+
'authenticator-off': {
|
|
224
|
+
heading: 'Authenticator app turned off',
|
|
225
|
+
message: 'your sign-ins no longer ask for a code from an authenticator app.'
|
|
226
|
+
},
|
|
227
|
+
'passkey-added': {
|
|
228
|
+
heading: 'Passkey added',
|
|
229
|
+
message: 'a passkey was added to your account.'
|
|
230
|
+
},
|
|
231
|
+
'passkey-removed': {
|
|
232
|
+
heading: 'Passkey removed',
|
|
233
|
+
message: 'a passkey was removed from your account.'
|
|
234
|
+
},
|
|
235
|
+
'reset-by-administrator': {
|
|
236
|
+
heading: 'Two-step sign-in was reset',
|
|
237
|
+
message:
|
|
238
|
+
'an administrator removed your authenticator app, recovery codes, and passkeys, so you can set them up again.'
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async function renderTwoStepChanged(payload: TwoStepChangedPayload) {
|
|
243
|
+
const copy = TWO_STEP_COPY[payload.change]
|
|
244
|
+
return rendered(
|
|
245
|
+
EnrollmentEmail,
|
|
246
|
+
{
|
|
247
|
+
heading: copy.heading,
|
|
248
|
+
preview: `${copy.heading} on your OpenPencil Cloud account.`,
|
|
249
|
+
message: `Hi ${payload.name}, ${copy.message} If this wasn’t you, change your password and contact your administrator.`,
|
|
250
|
+
actionLabel: 'Review security',
|
|
251
|
+
actionURL: payload.actionURL
|
|
252
|
+
},
|
|
253
|
+
`${copy.heading} on your OpenPencil Cloud account`
|
|
254
|
+
)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export async function renderTransactionalEmail(
|
|
258
|
+
content: TransactionalEmailContent
|
|
259
|
+
): Promise<RenderedTransactionalEmail> {
|
|
260
|
+
if (content.kind === 'document-invitation') return renderDocumentInvitation(content.payload)
|
|
261
|
+
if (content.kind === 'workspace-invitation') return renderWorkspaceInvitation(content.payload)
|
|
262
|
+
if (content.kind === 'admin-enrollment-notification') {
|
|
263
|
+
return renderAdminNotification(content.payload)
|
|
264
|
+
}
|
|
265
|
+
if (
|
|
266
|
+
content.kind === 'email-verification' ||
|
|
267
|
+
content.kind === 'password-reset' ||
|
|
268
|
+
content.kind === 'password-changed'
|
|
269
|
+
) {
|
|
270
|
+
return renderAuthentication(content.kind, content.payload)
|
|
271
|
+
}
|
|
272
|
+
if (content.kind === 'email-change-requested') return renderEmailChangeRequested(content.payload)
|
|
273
|
+
if (content.kind === 'new-sign-in') return renderNewSignIn(content.payload)
|
|
274
|
+
if (content.kind === 'two-step-changed') return renderTwoStepChanged(content.payload)
|
|
275
|
+
return renderEnrollment(content.kind, content.payload)
|
|
276
|
+
}
|
|
@@ -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
|
+
export 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,105 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Body,
|
|
3
|
+
Button,
|
|
4
|
+
Container,
|
|
5
|
+
Head,
|
|
6
|
+
Heading,
|
|
7
|
+
// eslint-disable-next-line open-pencil/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
|
+
/** The ivory app-icon tile, served as PNG because mail clients do not draw SVG. */
|
|
18
|
+
const LOGO_URL = 'https://openpencil.dev/brand/app-icon-1024.png'
|
|
19
|
+
const SITE_URL = 'https://openpencil.dev'
|
|
20
|
+
|
|
21
|
+
const FONT = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif'
|
|
22
|
+
const INK = '#171717'
|
|
23
|
+
const MUTED = '#6B6B6B'
|
|
24
|
+
/** Deep teal from the mark; white text on it passes WCAG AA. */
|
|
25
|
+
const TEAL = '#0A6C65'
|
|
26
|
+
|
|
27
|
+
const styles = {
|
|
28
|
+
body: { backgroundColor: '#F5F5EF', fontFamily: FONT, margin: '0', padding: '40px 16px' },
|
|
29
|
+
card: {
|
|
30
|
+
maxWidth: '480px',
|
|
31
|
+
margin: '0 auto',
|
|
32
|
+
padding: '40px',
|
|
33
|
+
backgroundColor: '#FFFFFF',
|
|
34
|
+
borderRadius: '16px',
|
|
35
|
+
border: '1px solid #E7E5DC'
|
|
36
|
+
},
|
|
37
|
+
logo: { borderRadius: '10px', margin: '0 0 28px' },
|
|
38
|
+
heading: {
|
|
39
|
+
color: INK,
|
|
40
|
+
fontSize: '22px',
|
|
41
|
+
fontWeight: '600',
|
|
42
|
+
lineHeight: '1.3',
|
|
43
|
+
margin: '0 0 12px'
|
|
44
|
+
},
|
|
45
|
+
text: { color: '#404040', fontSize: '15px', lineHeight: '1.6', margin: '0 0 24px' },
|
|
46
|
+
button: {
|
|
47
|
+
backgroundColor: TEAL,
|
|
48
|
+
borderRadius: '10px',
|
|
49
|
+
color: '#FFFFFF',
|
|
50
|
+
fontSize: '15px',
|
|
51
|
+
fontWeight: '600',
|
|
52
|
+
padding: '12px 22px',
|
|
53
|
+
textDecoration: 'none'
|
|
54
|
+
},
|
|
55
|
+
note: { color: MUTED, fontSize: '13px', lineHeight: '1.6', margin: '28px 0 0' },
|
|
56
|
+
link: { color: TEAL, textDecoration: 'underline' },
|
|
57
|
+
footer: {
|
|
58
|
+
color: MUTED,
|
|
59
|
+
fontSize: '12px',
|
|
60
|
+
lineHeight: '1.6',
|
|
61
|
+
textAlign: 'center' as const,
|
|
62
|
+
margin: '24px 0 0'
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type EmailLayoutProps = {
|
|
67
|
+
/** The line mail clients show beside the subject. */
|
|
68
|
+
preview: string
|
|
69
|
+
heading: string
|
|
70
|
+
message: string
|
|
71
|
+
actionLabel: string
|
|
72
|
+
actionURL: string
|
|
73
|
+
/** Small print under the button, with an optional link at its end. */
|
|
74
|
+
note?: { text: string; link?: { label: string; url: string } }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function noteContent(note: NonNullable<EmailLayoutProps['note']>) {
|
|
78
|
+
if (!note.link) return note.text
|
|
79
|
+
const { label, url } = note.link
|
|
80
|
+
return [`${note.text} `, h(Link, { href: url, style: styles.link }, () => label), '.']
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The branded email every OpenPencil service sends: the waitlist and Cloud alike. */
|
|
84
|
+
export function emailLayout(props: EmailLayoutProps): VNode {
|
|
85
|
+
const { note } = props
|
|
86
|
+
return h(HTML, { lang: 'en' }, () => [
|
|
87
|
+
h(Head),
|
|
88
|
+
h(Preview, () => props.preview),
|
|
89
|
+
h(Body, { style: styles.body }, () => [
|
|
90
|
+
h(Container, { style: styles.card }, () => [
|
|
91
|
+
h(Img, { src: LOGO_URL, width: 44, height: 44, alt: 'OpenPencil', style: styles.logo }),
|
|
92
|
+
h(Heading, { as: 'h1', style: styles.heading }, () => props.heading),
|
|
93
|
+
h(Text, { style: styles.text }, () => props.message),
|
|
94
|
+
h(Section, () =>
|
|
95
|
+
h(Button, { href: props.actionURL, style: styles.button }, () => props.actionLabel)
|
|
96
|
+
),
|
|
97
|
+
note ? h(Text, { style: styles.note }, () => noteContent(note)) : null
|
|
98
|
+
]),
|
|
99
|
+
h(Text, { style: styles.footer }, () => [
|
|
100
|
+
'OpenPencil, the open-source design editor · ',
|
|
101
|
+
h(Link, { href: SITE_URL, style: { color: MUTED } }, () => 'openpencil.dev')
|
|
102
|
+
])
|
|
103
|
+
])
|
|
104
|
+
])
|
|
105
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { defineComponent, type PropType } from 'vue'
|
|
2
|
+
|
|
3
|
+
import { transactionalEmailLayout } from './layout'
|
|
4
|
+
|
|
5
|
+
export type DocumentInvitationEmailProps = {
|
|
6
|
+
inviterName: string
|
|
7
|
+
documentName: string
|
|
8
|
+
permissionLabel: string
|
|
9
|
+
expiresAt: string
|
|
10
|
+
acceptanceURL: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const DocumentInvitationEmail = defineComponent({
|
|
14
|
+
props: {
|
|
15
|
+
inviterName: { type: String, required: true },
|
|
16
|
+
documentName: { type: String, required: true },
|
|
17
|
+
permissionLabel: { type: String, required: true },
|
|
18
|
+
expiresAt: { type: String, required: true },
|
|
19
|
+
acceptanceURL: { type: String, required: true }
|
|
20
|
+
} satisfies Record<
|
|
21
|
+
keyof DocumentInvitationEmailProps,
|
|
22
|
+
{ type: PropType<string>; required: true }
|
|
23
|
+
>,
|
|
24
|
+
setup(props) {
|
|
25
|
+
return () =>
|
|
26
|
+
transactionalEmailLayout({
|
|
27
|
+
preview: `${props.inviterName} invited you to ${props.permissionLabel} a document`,
|
|
28
|
+
heading: 'OpenPencil invitation',
|
|
29
|
+
message: `${props.inviterName} invited you to ${props.permissionLabel} “${props.documentName}”.`,
|
|
30
|
+
actionLabel: 'Open document',
|
|
31
|
+
actionURL: props.acceptanceURL,
|
|
32
|
+
footer: `This invitation expires ${props.expiresAt}.`
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
})
|