@open-pencil/cloud 0.17.0-beta.4 → 0.17.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/bin/server.mjs +1 -1
- package/dist/bin/server.mjs.map +1 -1
- package/dist/bin/services.mjs +1 -1
- package/dist/bin/services.mjs.map +1 -1
- package/dist/client.d.ts +296 -27
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +649 -295
- package/dist/client.js.map +1 -1
- package/dist/contract.d.ts +2 -2
- package/dist/contract.js +2 -2
- package/dist/contract2.js +331 -21
- package/dist/contract2.js.map +1 -1
- package/dist/email.d.ts +1773 -32
- package/dist/email.d.ts.map +1 -1
- package/dist/email.js +3478 -288
- package/dist/email.js.map +1 -1
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +48 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +466 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index2.d.ts +35 -0
- package/dist/index2.d.ts.map +1 -0
- package/dist/listen.mjs +447 -290
- package/dist/listen.mjs.map +1 -1
- package/dist/runtime-cloudflare.d.ts +89 -0
- package/dist/runtime-cloudflare.d.ts.map +1 -0
- package/dist/runtime-cloudflare.js +15667 -0
- package/dist/runtime-cloudflare.js.map +1 -0
- package/dist/runtime-node.d.mts +2963 -294
- package/dist/runtime-node.d.mts.map +1 -1
- package/dist/server.d.ts +3473 -842
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +12187 -8244
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +7739 -3548
- package/dist/server.mjs.map +1 -1
- package/dist/server2.mjs +5 -5
- package/dist/server2.mjs.map +1 -1
- package/package.json +22 -5
- package/src/admin/audit/service.ts +2 -2
- package/src/admin/documents/service.ts +76 -6
- package/src/admin/reports/service.ts +7 -1
- package/src/client/api.ts +23 -471
- package/src/client/auth/client.ts +22 -3
- package/src/client/billing.ts +80 -0
- package/src/client/community.ts +40 -0
- package/src/client/discovery.ts +35 -9
- package/src/client/documents.ts +160 -0
- package/src/client/index.ts +7 -0
- package/src/client/portal/account.ts +54 -2
- package/src/client/portal/request.ts +2 -0
- package/src/client/response.ts +21 -0
- package/src/client/schema.ts +8 -0
- package/src/client/services.ts +23 -18
- package/src/client/sharing.ts +262 -0
- package/src/client/versions.ts +104 -0
- package/src/contract/account.ts +50 -0
- package/src/contract/billing.ts +166 -0
- package/src/contract/collaboration.ts +5 -0
- package/src/contract/community.ts +60 -0
- package/src/contract/discovery.ts +63 -2
- package/src/contract/entitlements.ts +10 -0
- package/src/contract/index.ts +54 -5
- package/src/contract/links.ts +57 -4
- package/src/contract/locale.ts +27 -0
- package/src/contract/portal.ts +12 -1
- package/src/contract/routes.ts +10 -0
- package/src/contract/services.ts +18 -16
- package/src/email/i18n.ts +174 -0
- package/src/email/index.ts +13 -2
- package/src/email/locales/ar.json +141 -0
- package/src/email/locales/de.json +141 -0
- package/src/email/locales/es.json +141 -0
- package/src/email/locales/fr.json +141 -0
- package/src/email/locales/it.json +141 -0
- package/src/email/locales/ja.json +141 -0
- package/src/email/locales/pl.json +141 -0
- package/src/email/locales/pt-br.json +141 -0
- package/src/email/locales/ru.json +141 -0
- package/src/email/locales/zh-cn.json +141 -0
- package/src/email/messages.ts +200 -0
- package/src/email/render.ts +142 -276
- package/src/email/samples.ts +115 -0
- package/src/email/schema.ts +70 -6
- package/src/email/templates/BrandEmail.vue +54 -0
- package/src/email/templates/DocumentBlocked.vue +45 -0
- package/src/email/templates/DocumentInvitation.vue +24 -0
- package/src/email/templates/DocumentReport.vue +32 -0
- package/src/email/templates/DocumentReportDecided.vue +36 -0
- package/src/email/templates/DocumentReportReceived.vue +18 -0
- package/src/email/templates/DocumentRestored.vue +24 -0
- package/src/email/templates/EmailChangeRequested.vue +24 -0
- package/src/email/templates/EmailRoot.vue +19 -0
- package/src/email/templates/EmailText.vue +9 -0
- package/src/email/templates/EmailVerification.vue +38 -0
- package/src/email/templates/EnrollmentNotification.vue +24 -0
- package/src/email/templates/EnrollmentUpdate.vue +52 -0
- package/src/email/templates/NewSignIn.vue +37 -0
- package/src/email/templates/PasswordChanged.vue +22 -0
- package/src/email/templates/PasswordReset.vue +23 -0
- package/src/email/templates/StorageLimitReached.vue +28 -0
- package/src/email/templates/TwoStepChanged.vue +32 -0
- package/src/email/templates/WaitlistConfirmation.vue +29 -0
- package/src/email/templates/WorkspaceInvitation.vue +28 -0
- package/src/email/templates/brand.ts +9 -61
- package/src/email/templates/localization.ts +17 -0
- package/src/errors/index.ts +6 -0
- package/src/global.d.ts +7 -0
- package/src/runtime/cloudflare/relay/index.ts +7 -1
- package/src/runtime/cloudflare/tsconfig.json +2 -1
- package/src/runtime/cloudflare/worker.ts +8 -1
- package/src/runtime/node/cleanup.ts +5 -1
- package/src/runtime/node/email/transport.ts +13 -10
- package/src/runtime/node/main.ts +1 -1
- package/src/runtime/node/server.ts +12 -2
- package/src/runtime/node/services/main.ts +1 -1
- package/src/runtime/posthog/errors.ts +2 -1
- package/src/runtime/s3/objects.ts +17 -0
- package/src/runtime/site/community.ts +101 -0
- package/src/runtime/site/server.ts +17 -1
- package/src/server/account/deletion.ts +2 -0
- package/src/server/account/routes.ts +271 -240
- package/src/server/account/tokens.ts +57 -0
- package/src/server/api/router.ts +23 -0
- package/src/server/app/checks.ts +84 -0
- package/src/server/app/editors.ts +20 -0
- package/src/server/app/index.ts +128 -0
- package/src/server/app/indexing.ts +40 -0
- package/src/server/app/limiters.ts +53 -0
- package/src/server/app/routes.ts +114 -0
- package/src/server/app/services.ts +185 -0
- package/src/server/auth/access-tokens.ts +62 -0
- package/src/server/auth/adapter.ts +21 -1
- package/src/server/auth/email.ts +4 -1
- package/src/server/auth/enrollment.ts +116 -0
- package/src/server/auth/factory.ts +88 -131
- package/src/server/auth/logger.ts +23 -0
- package/src/server/auth/mfa-assurance.ts +51 -0
- package/src/server/auth/passwords.ts +43 -0
- package/src/server/auth/session.ts +2 -0
- package/src/server/billing/index.ts +6 -0
- package/src/server/billing/routes.ts +27 -0
- package/src/server/billing/tokens.ts +37 -0
- package/src/server/cleanup/configured.ts +16 -3
- package/src/server/cleanup/worker.ts +10 -1
- package/src/server/collaboration/relay/hub.ts +25 -142
- package/src/server/collaboration/relay/room.ts +154 -0
- package/src/server/collaboration/service.ts +21 -2
- package/src/server/community/index.ts +2 -0
- package/src/server/community/routes.ts +93 -0
- package/src/server/community/service.ts +134 -0
- package/src/server/config/deployment.ts +17 -5
- package/src/server/config/index.ts +1 -1
- package/src/server/config/public.ts +7 -1
- package/src/server/config/schema.ts +40 -292
- package/src/server/config/toml/schema.ts +307 -0
- package/src/server/db/index.ts +1 -0
- package/src/server/db/migrate.ts +13 -1
- package/src/server/db/migrations/009_access_tokens.ts +47 -0
- package/src/server/db/migrations/010_storage_limit_notices.ts +50 -0
- package/src/server/db/migrations/011_account_ids.ts +30 -0
- package/src/server/db/migrations/012_email_locales.ts +34 -0
- package/src/server/db/migrations/013_document_block_emails.ts +40 -0
- package/src/server/db/migrations/014_report_replies.ts +28 -0
- package/src/server/db/migrations/schema.ts +26 -1
- package/src/server/db/tables.ts +30 -1
- package/src/server/db/users.ts +22 -0
- package/src/server/documents/index.ts +1 -1
- package/src/server/documents/limits.ts +7 -1
- package/src/server/documents/service.ts +12 -402
- package/src/server/documents/uploads.ts +450 -0
- package/src/server/documents/versions/service.ts +81 -24
- package/src/server/email/invitations.ts +1 -0
- package/src/server/email/service.ts +31 -4
- package/src/server/email/types.ts +12 -0
- package/src/server/errors/index.ts +1 -9
- package/src/server/index.ts +12 -5
- package/src/server/invitations/types.ts +5 -1
- package/src/server/objects/types.ts +5 -0
- package/src/server/policy/configured.ts +9 -3
- package/src/server/policy/database.ts +13 -2
- package/src/server/policy/policy.ts +39 -12
- package/src/server/policy/service.ts +71 -52
- package/src/server/policy/storage.ts +33 -0
- package/src/server/quota/index.ts +6 -0
- package/src/server/quota/notices.ts +121 -0
- package/src/server/quota/storage.ts +5 -0
- package/src/server/rate-limit/middleware.ts +4 -0
- package/src/server/reports/index.ts +1 -0
- package/src/server/reports/replies.ts +55 -0
- package/src/server/reports/routes.ts +3 -1
- package/src/server/reports/service.ts +24 -2
- package/src/server/sharing/capabilities/service.ts +2 -3
- package/src/server/sharing/invitations/service.ts +14 -4
- package/src/server/validation.ts +3 -0
- package/src/server/workspaces/members.ts +7 -19
- package/src/services/app.ts +1 -3
- package/src/services/config.ts +1 -0
- package/src/services/usage.ts +6 -14
- package/src/email/templates/document-invitation.ts +0 -35
- package/src/email/templates/enrollment.ts +0 -27
- package/src/email/templates/layout.ts +0 -18
- package/src/server/app.ts +0 -453
- /package/src/{server/errors → errors}/posthog.ts +0 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { TwoStepChange, TwoStepChangedPayload } from '../schema'
|
|
3
|
+
import BrandEmail from './BrandEmail.vue'
|
|
4
|
+
import EmailText from './EmailText.vue'
|
|
5
|
+
import { greeting, useEmailLocalization } from './localization'
|
|
6
|
+
|
|
7
|
+
/** How the account proves it's its owner's changed: an authenticator app or a passkey. */
|
|
8
|
+
const { payload } = defineProps<{ payload: TwoStepChangedPayload }>()
|
|
9
|
+
|
|
10
|
+
const localization = useEmailLocalization()
|
|
11
|
+
const { t } = localization
|
|
12
|
+
const changes: Record<TwoStepChange, { heading: string; message: string }> = {
|
|
13
|
+
'authenticator-on': { heading: t.authenticatorOnHeading, message: t.authenticatorOn },
|
|
14
|
+
'authenticator-off': { heading: t.authenticatorOffHeading, message: t.authenticatorOff },
|
|
15
|
+
'passkey-added': { heading: t.passkeyAddedHeading, message: t.passkeyAdded },
|
|
16
|
+
'passkey-removed': { heading: t.passkeyRemovedHeading, message: t.passkeyRemoved },
|
|
17
|
+
'reset-by-administrator': { heading: t.twoStepResetHeading, message: t.twoStepReset }
|
|
18
|
+
}
|
|
19
|
+
const change = changes[payload.change]
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<template>
|
|
23
|
+
<BrandEmail
|
|
24
|
+
:preview="change.message"
|
|
25
|
+
:heading="change.heading"
|
|
26
|
+
:action="{ label: t.reviewSecurity, url: payload.actionURL }"
|
|
27
|
+
>
|
|
28
|
+
<EmailText>{{ greeting(localization, payload.name) }}</EmailText>
|
|
29
|
+
<EmailText>{{ change.message }}</EmailText>
|
|
30
|
+
<EmailText>{{ t.twoStepNotYou }}</EmailText>
|
|
31
|
+
</BrandEmail>
|
|
32
|
+
</template>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { Link } from '@vue-email/components'
|
|
3
|
+
|
|
4
|
+
import { styles } from './brand'
|
|
5
|
+
import BrandEmail from './BrandEmail.vue'
|
|
6
|
+
import EmailText from './EmailText.vue'
|
|
7
|
+
import { useEmailLocalization } from './localization'
|
|
8
|
+
|
|
9
|
+
/** Asks a waitlist sign-up to confirm its address; its links carry the sign-up's token only. */
|
|
10
|
+
const { confirmURL, leaveURL } = defineProps<{ confirmURL: string; leaveURL: string }>()
|
|
11
|
+
|
|
12
|
+
const { t } = useEmailLocalization()
|
|
13
|
+
// The translation places the link inside its sentence, where `{link}` is.
|
|
14
|
+
const [beforeLink = '', afterLink = ''] = t.waitlistNote.split('{link}')
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<template>
|
|
18
|
+
<BrandEmail
|
|
19
|
+
:preview="t.waitlistPreview"
|
|
20
|
+
:heading="t.waitlistHeading"
|
|
21
|
+
:action="{ label: t.waitlistAction, url: confirmURL }"
|
|
22
|
+
>
|
|
23
|
+
<EmailText>{{ t.waitlist }}</EmailText>
|
|
24
|
+
<template #note>
|
|
25
|
+
{{ beforeLink }}<Link :href="leaveURL" :style="styles.link">{{ t.waitlistLeave }}</Link
|
|
26
|
+
>{{ afterLink }}
|
|
27
|
+
</template>
|
|
28
|
+
</BrandEmail>
|
|
29
|
+
</template>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { WorkspaceInvitationEmailPayload } from '../schema'
|
|
3
|
+
import BrandEmail from './BrandEmail.vue'
|
|
4
|
+
import EmailText from './EmailText.vue'
|
|
5
|
+
import { useEmailLocalization } from './localization'
|
|
6
|
+
|
|
7
|
+
const { payload } = defineProps<{ payload: WorkspaceInvitationEmailPayload }>()
|
|
8
|
+
|
|
9
|
+
const { t, dateTime } = useEmailLocalization()
|
|
10
|
+
const names = { inviter: payload.inviterName ?? t.someone, workspace: payload.workspaceName }
|
|
11
|
+
const message = {
|
|
12
|
+
admin: t.workspaceInvitationAdmin,
|
|
13
|
+
editor: t.workspaceInvitationEditor,
|
|
14
|
+
viewer: t.workspaceInvitationViewer
|
|
15
|
+
}[payload.role](names)
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<template>
|
|
19
|
+
<BrandEmail
|
|
20
|
+
:preview="t.workspaceInvitationSubject(names)"
|
|
21
|
+
:heading="t.workspaceInvitationHeading(names)"
|
|
22
|
+
:action="{ label: t.workspaceInvitationAction, url: payload.acceptanceURL }"
|
|
23
|
+
>
|
|
24
|
+
<EmailText>{{ message }}</EmailText>
|
|
25
|
+
<EmailText>{{ t.workspaceInvitationHome }}</EmailText>
|
|
26
|
+
<template #note>{{ t.invitationExpires({ date: dateTime(payload.expiresAt) }) }}</template>
|
|
27
|
+
</BrandEmail>
|
|
28
|
+
</template>
|
|
@@ -1,22 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Body,
|
|
3
|
-
Button,
|
|
4
|
-
Container,
|
|
5
|
-
Head,
|
|
6
|
-
Heading,
|
|
7
|
-
// eslint-disable-next-line @open-pencil/structure/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'
|
|
1
|
+
/** The brand every OpenPencil email shares, from the waitlist to Cloud: its colors and type. */
|
|
16
2
|
|
|
17
3
|
/** 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'
|
|
4
|
+
export const LOGO_URL = 'https://openpencil.dev/brand/app-icon-1024.png'
|
|
5
|
+
export const SITE_URL = 'https://openpencil.dev'
|
|
20
6
|
|
|
21
7
|
const FONT = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif'
|
|
22
8
|
const INK = '#171717'
|
|
@@ -24,7 +10,8 @@ const MUTED = '#6B6B6B'
|
|
|
24
10
|
/** Deep teal from the mark; white text on it passes WCAG AA. */
|
|
25
11
|
const TEAL = '#0A6C65'
|
|
26
12
|
|
|
27
|
-
|
|
13
|
+
/** Inline styles, since mail clients drop most stylesheets. */
|
|
14
|
+
export const styles = {
|
|
28
15
|
body: { backgroundColor: '#F5F5EF', fontFamily: FONT, margin: '0', padding: '40px 16px' },
|
|
29
16
|
card: {
|
|
30
17
|
maxWidth: '480px',
|
|
@@ -42,7 +29,8 @@ const styles = {
|
|
|
42
29
|
lineHeight: '1.3',
|
|
43
30
|
margin: '0 0 12px'
|
|
44
31
|
},
|
|
45
|
-
text: { color: '#404040', fontSize: '15px', lineHeight: '1.6', margin: '0 0
|
|
32
|
+
text: { color: '#404040', fontSize: '15px', lineHeight: '1.6', margin: '0 0 16px' },
|
|
33
|
+
action: { paddingTop: '8px' },
|
|
46
34
|
button: {
|
|
47
35
|
backgroundColor: TEAL,
|
|
48
36
|
borderRadius: '10px',
|
|
@@ -60,46 +48,6 @@ const styles = {
|
|
|
60
48
|
lineHeight: '1.6',
|
|
61
49
|
textAlign: 'center' as const,
|
|
62
50
|
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
|
-
])
|
|
51
|
+
},
|
|
52
|
+
footerLink: { color: MUTED }
|
|
105
53
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { inject, type InjectionKey } from 'vue'
|
|
2
|
+
|
|
3
|
+
import type { EmailLocalization } from '../i18n'
|
|
4
|
+
|
|
5
|
+
/** The reader's language, which every email and its layout write in. */
|
|
6
|
+
export const EMAIL_LOCALIZATION: InjectionKey<EmailLocalization> = Symbol('email-localization')
|
|
7
|
+
|
|
8
|
+
export function useEmailLocalization(): EmailLocalization {
|
|
9
|
+
const localization = inject(EMAIL_LOCALIZATION)
|
|
10
|
+
if (!localization) throw new Error('An email renders inside EmailRoot, which gives its language')
|
|
11
|
+
return localization
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** "Hi Ada," or, when the account has no name, "Hi,". */
|
|
15
|
+
export function greeting({ t }: EmailLocalization, name: string | null): string {
|
|
16
|
+
return name ? t.greeting({ name }) : t.greetingWithoutName
|
|
17
|
+
}
|
package/src/global.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Single-file components as plain TypeScript sees them; vue-tsc reads the components themselves
|
|
2
|
+
// (`bun run typecheck`).
|
|
3
|
+
declare module '*.vue' {
|
|
4
|
+
import type { DefineComponent } from 'vue'
|
|
5
|
+
const component: DefineComponent<object, object, unknown>
|
|
6
|
+
export default component
|
|
7
|
+
}
|
|
@@ -27,6 +27,12 @@ export interface CollaborationRelayRPC extends DurableObject<CloudflareCloudEnvi
|
|
|
27
27
|
announceVersions(documentId: string): Promise<void>
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/** The Durable Object class a Worker exports for collaboration rooms. */
|
|
31
|
+
export type CollaborationRelayObjectClass = new (
|
|
32
|
+
ctx: DurableObjectState,
|
|
33
|
+
env: CloudflareCloudEnvironment
|
|
34
|
+
) => CollaborationRelayRPC
|
|
35
|
+
|
|
30
36
|
const documentIdSchema = v.pipe(v.string(), v.uuid())
|
|
31
37
|
|
|
32
38
|
/**
|
|
@@ -99,7 +105,7 @@ function configuredRelay(
|
|
|
99
105
|
*/
|
|
100
106
|
export function createCloudflareRelayObject(
|
|
101
107
|
prepare: (env: CloudflareCloudEnvironment) => Promise<PreparedCloudflareCloud>
|
|
102
|
-
) {
|
|
108
|
+
): CollaborationRelayObjectClass {
|
|
103
109
|
return class CollaborationRelayObject
|
|
104
110
|
extends DurableObject<CloudflareCloudEnvironment>
|
|
105
111
|
implements CollaborationRelayRPC
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"skipLibCheck": true,
|
|
14
14
|
"types": ["@cloudflare/workers-types"],
|
|
15
15
|
"paths": {
|
|
16
|
-
"#cloud/*": ["../../*"]
|
|
16
|
+
"#cloud/*": ["../../*"],
|
|
17
|
+
"@open-pencil/cloud/runtime/cloudflare": ["./index.ts"]
|
|
17
18
|
}
|
|
18
19
|
},
|
|
19
20
|
"include": ["./**/*.ts", "../../../deploy/**/*.ts"],
|
|
@@ -130,7 +130,14 @@ async function runScheduled(
|
|
|
130
130
|
if (config.cleanupEnabled) {
|
|
131
131
|
const policy = createConfiguredCloudPolicy(config, database)
|
|
132
132
|
await runCleanup(
|
|
133
|
-
createCleanupServices(
|
|
133
|
+
createCleanupServices(
|
|
134
|
+
config,
|
|
135
|
+
database,
|
|
136
|
+
objects,
|
|
137
|
+
policy,
|
|
138
|
+
services.reporter,
|
|
139
|
+
services.transport ? services.email : undefined
|
|
140
|
+
),
|
|
134
141
|
cleanupPassOptions(config)
|
|
135
142
|
)
|
|
136
143
|
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
} from '#cloud/server'
|
|
12
12
|
|
|
13
13
|
import { loadNodeCloudServerConfig } from './config'
|
|
14
|
+
import { createNodeTransactionalEmailRuntime } from './email/runtime'
|
|
14
15
|
|
|
15
16
|
const config = await loadNodeCloudServerConfig(process.env)
|
|
16
17
|
// A sweep may take longer than a request should.
|
|
@@ -21,13 +22,16 @@ const database = createPostgresCloudDatabase({
|
|
|
21
22
|
const objects = createS3ObjectStore(config)
|
|
22
23
|
try {
|
|
23
24
|
const policy = createConfiguredCloudPolicy(config, database)
|
|
25
|
+
// Queued here, sent by the server's email worker.
|
|
26
|
+
const { email, transport } = createNodeTransactionalEmailRuntime(config, database)
|
|
24
27
|
const result = await runCleanup(
|
|
25
28
|
createCleanupServices(
|
|
26
29
|
config,
|
|
27
30
|
database,
|
|
28
31
|
objects,
|
|
29
32
|
policy,
|
|
30
|
-
createLoggingErrorReporter(writeJSONLine, createCloudErrorReporter(config, 'node'))
|
|
33
|
+
createLoggingErrorReporter(writeJSONLine, createCloudErrorReporter(config, 'node')),
|
|
34
|
+
transport ? email : undefined
|
|
31
35
|
),
|
|
32
36
|
cleanupPassOptions(config)
|
|
33
37
|
)
|
|
@@ -77,16 +77,19 @@ export function createNodemailerInvitationDelivery(
|
|
|
77
77
|
const transport = createNodemailerTransactionalEmailTransport(options)
|
|
78
78
|
return {
|
|
79
79
|
async sendDocumentInvitation(message: DocumentInvitationMessage): Promise<void> {
|
|
80
|
-
const rendered = await renderTransactionalEmail(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
80
|
+
const rendered = await renderTransactionalEmail(
|
|
81
|
+
{
|
|
82
|
+
kind: 'document-invitation',
|
|
83
|
+
payload: {
|
|
84
|
+
inviterName: message.inviterName,
|
|
85
|
+
documentName: message.documentName,
|
|
86
|
+
permission: message.permission,
|
|
87
|
+
expiresAt: message.expiresAt,
|
|
88
|
+
acceptanceURL: message.acceptanceURL
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
message.locale
|
|
92
|
+
)
|
|
90
93
|
await transport.send({
|
|
91
94
|
deliveryId: message.deliveryId,
|
|
92
95
|
from: options.from,
|
package/src/runtime/node/main.ts
CHANGED
|
@@ -13,7 +13,7 @@ if (process.argv.includes('--help') || process.argv.includes('-h')) {
|
|
|
13
13
|
OPENPENCIL_CLOUD_DEV_SITE_URL
|
|
14
14
|
a Vite dev server to serve them from instead (cloud:dev)
|
|
15
15
|
PORT, HOST where to listen (default 8787 on 0.0.0.0)
|
|
16
|
-
plus the secrets the TOML names. See https://openpencil.dev/
|
|
16
|
+
plus the secrets the TOML names. See https://openpencil.dev/cloud/self-hosting/
|
|
17
17
|
`)
|
|
18
18
|
process.exit(0)
|
|
19
19
|
}
|
|
@@ -87,7 +87,10 @@ async function startConfiguredServer(
|
|
|
87
87
|
invitationOutbox,
|
|
88
88
|
transport: emailTransport
|
|
89
89
|
} = createNodeTransactionalEmailRuntime(config, database)
|
|
90
|
-
|
|
90
|
+
// The adapter that serves for as long as the server runs checks the schema once it starts.
|
|
91
|
+
const { auth, enrollment } = createCloudAuthenticationRuntime(config, database, email, {
|
|
92
|
+
validateSchema: true
|
|
93
|
+
})
|
|
91
94
|
const policy = createConfiguredCloudPolicy(config, database)
|
|
92
95
|
// Cleanup sweeps may run longer than a request should, so they have a connection of their own
|
|
93
96
|
// without the statement timeout.
|
|
@@ -99,7 +102,14 @@ async function startConfiguredServer(
|
|
|
99
102
|
: undefined
|
|
100
103
|
const cleanup = cleanupDatabase
|
|
101
104
|
? startCleanupWorker(
|
|
102
|
-
createCleanupServices(
|
|
105
|
+
createCleanupServices(
|
|
106
|
+
config,
|
|
107
|
+
cleanupDatabase,
|
|
108
|
+
objects,
|
|
109
|
+
policy,
|
|
110
|
+
reportError,
|
|
111
|
+
emailTransport ? email : undefined
|
|
112
|
+
),
|
|
103
113
|
{
|
|
104
114
|
...cleanupPassOptions(config),
|
|
105
115
|
intervalMs: config.cleanupIntervalMs,
|
|
@@ -11,7 +11,7 @@ if (process.argv.includes('--help') || process.argv.includes('-h')) {
|
|
|
11
11
|
environment:
|
|
12
12
|
OPENPENCIL_SERVICES_CONFIG the services TOML file (required)
|
|
13
13
|
PORT, HOST where to listen (default 8788 on 0.0.0.0)
|
|
14
|
-
plus the secrets the TOML names. See https://openpencil.dev/
|
|
14
|
+
plus the secrets the TOML names. See https://openpencil.dev/cloud/self-hosting/
|
|
15
15
|
`)
|
|
16
16
|
process.exit(0)
|
|
17
17
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { createPostHogErrorReporter } from '#cloud/errors'
|
|
1
2
|
import type { CloudServerConfig } from '#cloud/server'
|
|
2
|
-
import {
|
|
3
|
+
import type { CloudErrorReporter } from '#cloud/server/errors'
|
|
3
4
|
import type { PostHogOptions } from 'posthog-node'
|
|
4
5
|
|
|
5
6
|
/** Which runtime serves the deployment, as its error reports name it. */
|
|
@@ -288,6 +288,23 @@ export function createS3ObjectStore(config: CloudServerConfig): ObjectStore {
|
|
|
288
288
|
if (isNotFoundError(error)) return null
|
|
289
289
|
throw error
|
|
290
290
|
}
|
|
291
|
+
},
|
|
292
|
+
|
|
293
|
+
async readRange(key, start, endExclusive) {
|
|
294
|
+
if (endExclusive <= start) return new Uint8Array()
|
|
295
|
+
try {
|
|
296
|
+
const object = await client.send(
|
|
297
|
+
new GetObjectCommand({
|
|
298
|
+
Bucket: config.s3Bucket,
|
|
299
|
+
Key: key,
|
|
300
|
+
Range: `bytes=${start}-${endExclusive - 1}`
|
|
301
|
+
})
|
|
302
|
+
)
|
|
303
|
+
return object.Body ? await object.Body.transformToByteArray() : null
|
|
304
|
+
} catch (error) {
|
|
305
|
+
if (isNotFoundError(error)) return null
|
|
306
|
+
throw error
|
|
307
|
+
}
|
|
291
308
|
}
|
|
292
309
|
}
|
|
293
310
|
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CLOUD_COMMUNITY_PATH,
|
|
3
|
+
cloudCommunityPagePath,
|
|
4
|
+
communityDocumentsSchema,
|
|
5
|
+
type CommunityDocument
|
|
6
|
+
} from '#cloud/contract'
|
|
7
|
+
// eslint-disable-next-line @open-pencil/structure/no-mixed-case-acronym-identifiers -- Upstream export spelling.
|
|
8
|
+
import { createHead, transformHtmlTemplate as transformHTMLTemplate } from 'unhead/server'
|
|
9
|
+
import * as v from 'valibot'
|
|
10
|
+
|
|
11
|
+
/** What a community page says about itself to link previews and search engines. */
|
|
12
|
+
export type PageMeta = {
|
|
13
|
+
title: string
|
|
14
|
+
description: string
|
|
15
|
+
url: string
|
|
16
|
+
image?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type API = { fetch(request: Request): Response | Promise<Response> }
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Why a community page shows no tags: there is no gallery or no such document (404), or the API
|
|
23
|
+
* could not answer, such as when it limited the visitor, whose status and retry advice the page
|
|
24
|
+
* keeps.
|
|
25
|
+
*/
|
|
26
|
+
export type CommunityPageFailure = { status: number; retryAfter: string | null }
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The gallery's documents, read through the server's own API as the visitor asked for the page,
|
|
30
|
+
* so the request counts against the visitor's limits, or why they could not be read.
|
|
31
|
+
*/
|
|
32
|
+
async function communityDocuments(
|
|
33
|
+
api: API,
|
|
34
|
+
page: Request
|
|
35
|
+
): Promise<CommunityDocument[] | CommunityPageFailure> {
|
|
36
|
+
const url = new URL(`/api${CLOUD_COMMUNITY_PATH}`, page.url)
|
|
37
|
+
const response = await api.fetch(new Request(url, { headers: page.headers }))
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
return { status: response.status, retryAfter: response.headers.get('Retry-After') }
|
|
40
|
+
}
|
|
41
|
+
const body = v.safeParse(communityDocumentsSchema, await response.json())
|
|
42
|
+
return body.success ? body.output.documents : { status: 502, retryAfter: null }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const NOT_FOUND: CommunityPageFailure = { status: 404, retryAfter: null }
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The tags for the gallery, or for one of its documents when `documentId` names one, or why the
|
|
49
|
+
* page has none: no gallery or no such document, or an API that could not answer.
|
|
50
|
+
*/
|
|
51
|
+
export async function communityPageMeta(
|
|
52
|
+
api: API,
|
|
53
|
+
page: Request,
|
|
54
|
+
documentId: string | undefined
|
|
55
|
+
): Promise<PageMeta | CommunityPageFailure> {
|
|
56
|
+
const documents = await communityDocuments(api, page)
|
|
57
|
+
if (!Array.isArray(documents)) return documents
|
|
58
|
+
const { origin, host } = new URL(page.url)
|
|
59
|
+
if (documentId === undefined) {
|
|
60
|
+
const first = documents.at(0)
|
|
61
|
+
return {
|
|
62
|
+
title: `Community · ${host}`,
|
|
63
|
+
description: 'Files to open, explore, and copy into your own workspace.',
|
|
64
|
+
url: new URL(CLOUD_COMMUNITY_PATH, origin).href,
|
|
65
|
+
image: first ? new URL(first.thumbnailPath, origin).href : undefined
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const document = documents.find((entry) => entry.id === documentId)
|
|
69
|
+
if (!document) return NOT_FOUND
|
|
70
|
+
return {
|
|
71
|
+
title: `${document.name} · Community · ${host}`,
|
|
72
|
+
description:
|
|
73
|
+
document.versions.at(0)?.description ??
|
|
74
|
+
`${document.name}, a file to open in OpenPencil and copy into your own workspace.`,
|
|
75
|
+
url: new URL(cloudCommunityPagePath(document.id), origin).href,
|
|
76
|
+
image: new URL(document.thumbnailPath, origin).href
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The page with the gallery's title, description, preview, and canonical address in its head. */
|
|
81
|
+
export async function withPageMeta(html: string, meta: PageMeta): Promise<string> {
|
|
82
|
+
const head = createHead()
|
|
83
|
+
head.push({
|
|
84
|
+
title: meta.title,
|
|
85
|
+
meta: [
|
|
86
|
+
{ name: 'description', content: meta.description },
|
|
87
|
+
{ property: 'og:type', content: 'website' },
|
|
88
|
+
{ property: 'og:title', content: meta.title },
|
|
89
|
+
{ property: 'og:description', content: meta.description },
|
|
90
|
+
{ property: 'og:url', content: meta.url },
|
|
91
|
+
...(meta.image
|
|
92
|
+
? [
|
|
93
|
+
{ property: 'og:image', content: meta.image },
|
|
94
|
+
{ name: 'twitter:card', content: 'summary_large_image' }
|
|
95
|
+
]
|
|
96
|
+
: [])
|
|
97
|
+
],
|
|
98
|
+
link: [{ rel: 'canonical', href: meta.url }]
|
|
99
|
+
})
|
|
100
|
+
return transformHTMLTemplate(head, html)
|
|
101
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CLOUD_PORTAL_PAGE_ROOTS } from '#cloud/contract'
|
|
1
|
+
import { CLOUD_PORTAL_COMMUNITY_PAGES, CLOUD_PORTAL_PAGE_ROOTS } from '#cloud/contract'
|
|
2
2
|
import {
|
|
3
3
|
cloudErrorHandler,
|
|
4
4
|
cloudRequestId,
|
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
} from '#cloud/server'
|
|
9
9
|
import { Hono } from 'hono'
|
|
10
10
|
|
|
11
|
+
import { communityPageMeta, withPageMeta } from './community'
|
|
12
|
+
|
|
11
13
|
/** A file of the Cloud site (`bun run build:cloud`): the editor and the portal. */
|
|
12
14
|
export type SiteFile = {
|
|
13
15
|
body: ReadableStream | Uint8Array<ArrayBuffer>
|
|
@@ -85,6 +87,20 @@ export function createCloudServer(
|
|
|
85
87
|
const page = await site(PORTAL_PAGE, c.req.raw)
|
|
86
88
|
return page ? c.body(page.body, 200, PAGE_HEADERS) : c.notFound()
|
|
87
89
|
})
|
|
90
|
+
// The gallery's pages say what they show to link previews and search engines, which read the
|
|
91
|
+
// page as served rather than as its script draws it.
|
|
92
|
+
server.on(['GET', 'HEAD'], [...CLOUD_PORTAL_COMMUNITY_PAGES], async (c) => {
|
|
93
|
+
const page = await site(PORTAL_PAGE, c.req.raw)
|
|
94
|
+
if (!page) return c.notFound()
|
|
95
|
+
const meta = await communityPageMeta(api, c.req.raw, c.req.param('documentId'))
|
|
96
|
+
const html = await new Response(page.body).text()
|
|
97
|
+
if ('title' in meta) return c.body(await withPageMeta(html, meta), 200, PAGE_HEADERS)
|
|
98
|
+
// The page still loads and says what went wrong; the status and retry advice stay the API's.
|
|
99
|
+
const headers = meta.retryAfter
|
|
100
|
+
? { ...PAGE_HEADERS, 'Retry-After': meta.retryAfter }
|
|
101
|
+
: PAGE_HEADERS
|
|
102
|
+
return new Response(html, { status: meta.status, headers })
|
|
103
|
+
})
|
|
88
104
|
server.on(['GET', 'HEAD'], '*', async (c, next) => {
|
|
89
105
|
await next()
|
|
90
106
|
if (c.res.status !== 404) return
|
|
@@ -260,6 +260,8 @@ export function createAccountDeletionService(database: Kysely<CloudDatabase>) {
|
|
|
260
260
|
] as const) {
|
|
261
261
|
await transaction.deleteFrom(table).where('userId', '=', user.id).execute()
|
|
262
262
|
}
|
|
263
|
+
// Personal access tokens have no key to cascade from, since Cloud builds their table.
|
|
264
|
+
await transaction.deleteFrom('apikey').where('referenceId', '=', user.id).execute()
|
|
263
265
|
await transaction
|
|
264
266
|
.deleteFrom('enrollment')
|
|
265
267
|
.where('emailNormalized', '=', normalizeEnrollmentEmail(user.email))
|