@open-pencil/cloud 0.17.0-beta.5 → 0.17.0-beta.6
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/dist/client.d.ts +560 -93
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1101 -186
- package/dist/client.js.map +1 -1
- package/dist/contract.d.ts +2 -2
- package/dist/contract.js +2 -2
- package/dist/contract2.js +390 -44
- package/dist/contract2.js.map +1 -1
- package/dist/email.d.ts +366 -3
- package/dist/email.d.ts.map +1 -1
- package/dist/email.js +1403 -556
- package/dist/email.js.map +1 -1
- package/dist/errors.js +16 -3
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +878 -37
- package/dist/index.d.ts.map +1 -1
- package/dist/index2.d.ts +12 -2
- package/dist/index2.d.ts.map +1 -1
- package/dist/listen.mjs +589 -128
- package/dist/listen.mjs.map +1 -1
- package/dist/runtime-cloudflare.d.ts +4 -0
- package/dist/runtime-cloudflare.d.ts.map +1 -1
- package/dist/runtime-cloudflare.js +8689 -6324
- package/dist/runtime-cloudflare.js.map +1 -1
- package/dist/runtime-node.d.mts +10098 -5401
- package/dist/runtime-node.d.mts.map +1 -1
- package/dist/server.d.ts +14078 -7909
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +11723 -9412
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +10658 -8649
- package/dist/server.mjs.map +1 -1
- package/dist/server2.mjs +79 -57
- package/dist/server2.mjs.map +1 -1
- package/package.json +13 -4
- package/src/admin/api/routes.ts +263 -190
- package/src/admin/audit/service.ts +9 -1
- package/src/admin/bootstrap.ts +86 -0
- package/src/admin/documents/service.ts +119 -4
- package/src/admin/email/service.ts +2 -1
- package/src/admin/enrollment/email.ts +17 -3
- package/src/admin/enrollment/service.ts +71 -10
- package/src/admin/errors.ts +5 -0
- package/src/admin/index.ts +1 -0
- package/src/admin/reports/service.ts +9 -3
- package/src/admin/schema.ts +6 -5
- package/src/admin/users/service.ts +173 -16
- package/src/client/api.ts +29 -2
- package/src/client/comments.ts +205 -0
- package/src/client/device-authorization.ts +4 -20
- package/src/client/discovery.ts +4 -2
- package/src/client/files/archive.ts +60 -0
- package/src/client/files/checksum.ts +7 -0
- package/src/client/files/download.ts +122 -0
- package/src/client/files/images.ts +89 -0
- package/src/client/files/index.ts +15 -0
- package/src/client/files/objects.ts +173 -0
- package/src/client/files/save.ts +79 -0
- package/src/client/index.ts +3 -6
- package/src/client/portal/account.ts +20 -2
- package/src/client/portal/administration.ts +52 -5
- package/src/client/portal/request.ts +4 -2
- package/src/client/tour.ts +44 -0
- package/src/client/versions.ts +7 -1
- package/src/contract/account.ts +61 -11
- package/src/contract/admin/index.ts +48 -3
- package/src/contract/billing.ts +73 -4
- package/src/contract/comments.ts +223 -0
- package/src/contract/discovery.ts +47 -19
- package/src/contract/index.ts +10 -0
- package/src/contract/links.ts +5 -0
- package/src/contract/relay.ts +3 -1
- package/src/contract/services.ts +44 -4
- package/src/contract/workspaces.ts +5 -0
- package/src/email/locales/ar.json +28 -0
- package/src/email/locales/de.json +28 -0
- package/src/email/locales/es.json +28 -0
- package/src/email/locales/fr.json +28 -0
- package/src/email/locales/it.json +28 -0
- package/src/email/locales/ja.json +28 -0
- package/src/email/locales/pl.json +28 -0
- package/src/email/locales/pt-br.json +28 -0
- package/src/email/locales/ru.json +28 -0
- package/src/email/locales/zh-cn.json +28 -0
- package/src/email/messages.ts +35 -0
- package/src/email/render.ts +18 -0
- package/src/email/samples.ts +28 -1
- package/src/email/schema.ts +29 -3
- package/src/email/templates/BrandEmail.vue +3 -1
- package/src/email/templates/CommentNotification.vue +39 -0
- package/src/email/templates/EnrollmentInvitation.vue +53 -0
- package/src/email/templates/TwoStepChanged.vue +17 -2
- package/src/email/templates/brand.ts +6 -0
- package/src/errors/posthog.ts +28 -4
- package/src/runtime/cloudflare/email.ts +2 -0
- package/src/runtime/cloudflare/relay/index.ts +21 -6
- package/src/runtime/cloudflare/worker.ts +6 -0
- package/src/runtime/cloudflare/xml.ts +12 -0
- package/src/runtime/node/admin.ts +51 -47
- package/src/runtime/node/email/runtime.ts +1 -0
- package/src/runtime/node/email/transport.ts +1 -0
- package/src/runtime/node/server.ts +8 -2
- package/src/runtime/posthog/errors.ts +3 -1
- package/src/server/account/actions.ts +3 -1
- package/src/server/account/deletion.ts +38 -4
- package/src/server/account/routes.ts +67 -46
- package/src/server/account/tokens.ts +3 -3
- package/src/server/api/router.ts +22 -7
- package/src/server/app/checks.ts +6 -1
- package/src/server/app/cors.ts +44 -0
- package/src/server/app/index.ts +76 -76
- package/src/server/app/routes.ts +14 -5
- package/src/server/app/services.ts +49 -15
- package/src/server/auth/access-control.ts +13 -8
- package/src/server/auth/account.ts +13 -12
- package/src/server/auth/activity.ts +7 -2
- package/src/server/auth/adapter.ts +16 -3
- package/src/server/auth/email.ts +29 -17
- package/src/server/auth/endpoints.ts +4 -0
- package/src/server/auth/factory.ts +83 -64
- package/src/server/auth/index.ts +1 -1
- package/src/server/auth/methods.ts +162 -0
- package/src/server/auth/mfa-assurance.ts +147 -10
- package/src/server/auth/rate-limit.ts +31 -0
- package/src/server/auth/runtime.ts +19 -5
- package/src/server/auth/social-providers.ts +70 -24
- package/src/server/billing/index.ts +2 -0
- package/src/server/billing/notify.ts +55 -0
- package/src/server/billing/seats.ts +17 -0
- package/src/server/billing/tokens.ts +1 -1
- package/src/server/cleanup/documents.ts +5 -2
- package/src/server/cleanup/revisions.ts +6 -3
- package/src/server/cleanup/uploads.ts +2 -1
- package/src/server/collaboration/relay/connection.ts +7 -2
- package/src/server/collaboration/relay/hub.ts +55 -24
- package/src/server/collaboration/routes.ts +8 -5
- package/src/server/comments/index.ts +9 -0
- package/src/server/comments/notify.ts +277 -0
- package/src/server/comments/routes.ts +352 -0
- package/src/server/comments/rows.ts +249 -0
- package/src/server/comments/service.ts +570 -0
- package/src/server/community/routes.ts +6 -6
- package/src/server/config/deployment.ts +19 -6
- package/src/server/config/index.ts +1 -1
- package/src/server/config/public.ts +19 -6
- package/src/server/config/schema.ts +14 -2
- package/src/server/config/toml/schema.ts +27 -4
- package/src/server/db/index.ts +2 -1
- package/src/server/db/migrate.ts +21 -1
- package/src/server/db/migrations/015_comments.ts +57 -0
- package/src/server/db/migrations/016_comment_notifications.ts +76 -0
- package/src/server/db/migrations/017_invitation_emails.ts +19 -0
- package/src/server/db/migrations/018_enrollment_source.ts +17 -0
- package/src/server/db/tables.ts +92 -2
- package/src/server/documents/access.ts +17 -0
- package/src/server/documents/images.ts +6 -1
- package/src/server/documents/routes.ts +12 -12
- package/src/server/documents/service.ts +19 -5
- package/src/server/documents/summary.ts +15 -0
- package/src/server/documents/versions/routes.ts +7 -8
- package/src/server/documents/versions/service.ts +5 -2
- package/src/server/email/service.ts +8 -2
- package/src/server/email/types.ts +1 -0
- package/src/server/errors/index.ts +48 -3
- package/src/server/index.ts +15 -1
- package/src/server/internal/routes.ts +8 -2
- package/src/server/internal/service.ts +10 -0
- package/src/server/invitations/budget.ts +3 -1
- package/src/server/invitations/index.ts +1 -0
- package/src/server/invitations/links.ts +6 -0
- package/src/server/pictures/service.ts +3 -1
- package/src/server/policy/workspace.ts +5 -2
- package/src/server/reports/routes.ts +2 -2
- package/src/server/reports/service.ts +3 -1
- package/src/server/services/routes.ts +2 -2
- package/src/server/sharing/capabilities/service.ts +1 -1
- package/src/server/sharing/document-routes.ts +3 -3
- package/src/server/sharing/invitations/service.ts +3 -4
- package/src/server/sharing/routes.ts +15 -15
- package/src/server/validation.ts +33 -25
- package/src/server/workspaces/members.ts +50 -12
- package/src/server/workspaces/repository.ts +23 -12
- package/src/server/workspaces/routes.ts +8 -8
- package/src/services/app.ts +30 -19
- package/src/services/config.ts +47 -8
- package/src/services/metering.ts +15 -27
- package/src/client/billing.ts +0 -80
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { Link } from '@vue-email/components'
|
|
3
|
+
|
|
4
|
+
import type { CommentNotificationPayload } from '../schema'
|
|
5
|
+
import { styles } from './brand'
|
|
6
|
+
import BrandEmail from './BrandEmail.vue'
|
|
7
|
+
import EmailText from './EmailText.vue'
|
|
8
|
+
import { greeting, useEmailLocalization } from './localization'
|
|
9
|
+
|
|
10
|
+
/** To someone a comment names, or who takes part in its thread: who wrote what, and where. */
|
|
11
|
+
const { payload } = defineProps<{ payload: CommentNotificationPayload }>()
|
|
12
|
+
|
|
13
|
+
const localization = useEmailLocalization()
|
|
14
|
+
const { t } = localization
|
|
15
|
+
const words = {
|
|
16
|
+
author: payload.authorName ?? t.commentSomeone,
|
|
17
|
+
document: payload.documentName
|
|
18
|
+
}
|
|
19
|
+
const lead = payload.reason === 'mention' ? t.commentMention(words) : t.commentReply(words)
|
|
20
|
+
// The translation places the link inside its sentence, where `{link}` is.
|
|
21
|
+
const [beforeLink = '', afterLink = ''] = t.commentSettings.split('{link}')
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<template>
|
|
25
|
+
<BrandEmail
|
|
26
|
+
:preview="payload.excerpt"
|
|
27
|
+
:heading="payload.reason === 'mention' ? t.commentMentionHeading : t.commentReplyHeading"
|
|
28
|
+
:action="{ label: t.openComment, url: payload.actionURL }"
|
|
29
|
+
>
|
|
30
|
+
<EmailText>{{ greeting(localization, payload.name) }}</EmailText>
|
|
31
|
+
<EmailText>{{ lead }}</EmailText>
|
|
32
|
+
<EmailText>“{{ payload.excerpt }}”</EmailText>
|
|
33
|
+
<template #note>
|
|
34
|
+
{{ beforeLink
|
|
35
|
+
}}<Link :href="payload.settingsURL" :style="styles.link">{{ t.commentSettingsLink }}</Link
|
|
36
|
+
>{{ afterLink }}
|
|
37
|
+
</template>
|
|
38
|
+
</BrandEmail>
|
|
39
|
+
</template>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { Link } from '@vue-email/components'
|
|
3
|
+
|
|
4
|
+
import type { EnrollmentEmailPayload } from '../schema'
|
|
5
|
+
import { BUG_REPORT_URL, DESKTOP_BETA_URL, styles } from './brand'
|
|
6
|
+
import BrandEmail from './BrandEmail.vue'
|
|
7
|
+
import EmailText from './EmailText.vue'
|
|
8
|
+
import { greeting, useEmailLocalization } from './localization'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A letter from OpenPencil's founder to someone who asked for the official Cloud before it opened,
|
|
12
|
+
* or joined its waitlist on openpencil.dev: thanks for waiting, it is a beta, and where to say what
|
|
13
|
+
* breaks. Replies reach a person, through the deployment's reply address. The waitlist gave no
|
|
14
|
+
* name, so its letter opens with the thanks rather than a greeting.
|
|
15
|
+
*/
|
|
16
|
+
const { payload } = defineProps<{ payload: EnrollmentEmailPayload }>()
|
|
17
|
+
|
|
18
|
+
const localization = useEmailLocalization()
|
|
19
|
+
const { t } = localization
|
|
20
|
+
// Each translation places its link inside the sentence, where `{link}` is.
|
|
21
|
+
// The waitlist letter already says Cloud is open, so its beta paragraph starts at the beta.
|
|
22
|
+
const beta = payload.waitlist ? t.invitationWaitlistBeta : t.invitationBeta
|
|
23
|
+
const [beforeIssue = '', afterIssue = ''] = beta.split('{link}')
|
|
24
|
+
const [beforeDownload = '', afterDownload = ''] = t.invitationDesktop.split('{link}')
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<template>
|
|
28
|
+
<BrandEmail
|
|
29
|
+
:preview="payload.waitlist ? t.invitationWaitlistPreview : t.invitationPreview"
|
|
30
|
+
:heading="t.invitationHeading"
|
|
31
|
+
:action="{ label: t.invitationAction, url: payload.actionURL }"
|
|
32
|
+
>
|
|
33
|
+
<EmailText v-if="payload.waitlist">{{ t.invitationWaitlistThanks }}</EmailText>
|
|
34
|
+
<template v-else>
|
|
35
|
+
<EmailText>{{ greeting(localization, payload.name) }}</EmailText>
|
|
36
|
+
<EmailText>{{ t.invitationThanks }}</EmailText>
|
|
37
|
+
</template>
|
|
38
|
+
<EmailText>
|
|
39
|
+
{{ beforeIssue
|
|
40
|
+
}}<Link :href="BUG_REPORT_URL" :style="styles.link">{{ t.invitationIssueLink }}</Link
|
|
41
|
+
>{{ afterIssue }}
|
|
42
|
+
</EmailText>
|
|
43
|
+
<EmailText>
|
|
44
|
+
{{ beforeDownload
|
|
45
|
+
}}<Link :href="DESKTOP_BETA_URL" :style="styles.link">{{ t.invitationDownloadLink }}</Link
|
|
46
|
+
>{{ afterDownload }}
|
|
47
|
+
</EmailText>
|
|
48
|
+
<template #signature>
|
|
49
|
+
{{ t.invitationSignatureName }}<br />
|
|
50
|
+
{{ t.invitationSignatureRole }}
|
|
51
|
+
</template>
|
|
52
|
+
</BrandEmail>
|
|
53
|
+
</template>
|
|
@@ -1,20 +1,35 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { CLOUD_SOCIAL_PROVIDER_NAMES, isKnownSocialProvider } from '#cloud/contract'
|
|
3
|
+
|
|
2
4
|
import type { TwoStepChange, TwoStepChangedPayload } from '../schema'
|
|
3
5
|
import BrandEmail from './BrandEmail.vue'
|
|
4
6
|
import EmailText from './EmailText.vue'
|
|
5
7
|
import { greeting, useEmailLocalization } from './localization'
|
|
6
8
|
|
|
7
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* How the account proves it's its owner's changed: an authenticator app, a passkey, or a way to
|
|
11
|
+
* sign in an administrator removed.
|
|
12
|
+
*/
|
|
8
13
|
const { payload } = defineProps<{ payload: TwoStepChangedPayload }>()
|
|
9
14
|
|
|
10
15
|
const localization = useEmailLocalization()
|
|
11
16
|
const { t } = localization
|
|
17
|
+
// Provider names stay as their owners write them; a password is named in the reader's words.
|
|
18
|
+
function methodName(provider: string): string {
|
|
19
|
+
if (provider === 'credential') return t.signInMethodPassword
|
|
20
|
+
return isKnownSocialProvider(provider) ? CLOUD_SOCIAL_PROVIDER_NAMES[provider] : provider
|
|
21
|
+
}
|
|
22
|
+
const method = payload.method ? methodName(payload.method) : ''
|
|
12
23
|
const changes: Record<TwoStepChange, { heading: string; message: string }> = {
|
|
13
24
|
'authenticator-on': { heading: t.authenticatorOnHeading, message: t.authenticatorOn },
|
|
14
25
|
'authenticator-off': { heading: t.authenticatorOffHeading, message: t.authenticatorOff },
|
|
15
26
|
'passkey-added': { heading: t.passkeyAddedHeading, message: t.passkeyAdded },
|
|
16
27
|
'passkey-removed': { heading: t.passkeyRemovedHeading, message: t.passkeyRemoved },
|
|
17
|
-
'reset-by-administrator': { heading: t.twoStepResetHeading, message: t.twoStepReset }
|
|
28
|
+
'reset-by-administrator': { heading: t.twoStepResetHeading, message: t.twoStepReset },
|
|
29
|
+
'sign-in-method-removed': {
|
|
30
|
+
heading: t.signInMethodRemovedHeading,
|
|
31
|
+
message: t.signInMethodRemoved({ method })
|
|
32
|
+
}
|
|
18
33
|
}
|
|
19
34
|
const change = changes[payload.change]
|
|
20
35
|
</script>
|
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
/** The ivory app-icon tile, served as PNG because mail clients do not draw SVG. */
|
|
4
4
|
export const LOGO_URL = 'https://openpencil.dev/brand/app-icon-1024.png'
|
|
5
5
|
export const SITE_URL = 'https://openpencil.dev'
|
|
6
|
+
/** The download page's beta section, with the newest desktop beta's installers. */
|
|
7
|
+
export const DESKTOP_BETA_URL = 'https://openpencil.dev/download#beta'
|
|
8
|
+
/** The repository's bug report form. */
|
|
9
|
+
export const BUG_REPORT_URL =
|
|
10
|
+
'https://github.com/open-pencil/open-pencil/issues/new?template=bug_report.yml'
|
|
6
11
|
|
|
7
12
|
const FONT = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif'
|
|
8
13
|
const INK = '#171717'
|
|
@@ -40,6 +45,7 @@ export const styles = {
|
|
|
40
45
|
padding: '12px 22px',
|
|
41
46
|
textDecoration: 'none'
|
|
42
47
|
},
|
|
48
|
+
signature: { color: '#404040', fontSize: '15px', lineHeight: '1.6', margin: '28px 0 0' },
|
|
43
49
|
note: { color: MUTED, fontSize: '13px', lineHeight: '1.6', margin: '28px 0 0' },
|
|
44
50
|
link: { color: TEAL, textDecoration: 'underline' },
|
|
45
51
|
footer: {
|
package/src/errors/posthog.ts
CHANGED
|
@@ -9,6 +9,10 @@ export type ErrorReportContext<Source extends string = string> = {
|
|
|
9
9
|
requestId?: string
|
|
10
10
|
/** What failed, as the server's log says it; not sent to PostHog, whose report has the error. */
|
|
11
11
|
message?: string
|
|
12
|
+
/** The signed-in user the error happened for, by account ID. */
|
|
13
|
+
userId?: string
|
|
14
|
+
/** The records involved, by kind, such as `{ documentId }`; IDs only, never their contents. */
|
|
15
|
+
resources?: Readonly<Record<string, string>>
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
/** Sends a caught error where it is seen; it never rejects. */
|
|
@@ -17,12 +21,27 @@ export type ErrorReporter<Source extends string = string> = (
|
|
|
17
21
|
context: ErrorReportContext<Source>
|
|
18
22
|
) => Promise<void>
|
|
19
23
|
|
|
24
|
+
/** A record kind as PostHog's properties name it: `documentId` as `document_id`. */
|
|
25
|
+
function propertyName(kind: string): string {
|
|
26
|
+
return kind.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The context's record IDs as report properties. */
|
|
30
|
+
function resourceProperties(resources: Readonly<Record<string, string>> = {}) {
|
|
31
|
+
return Object.fromEntries(Object.entries(resources).map(([kind, id]) => [propertyName(kind), id]))
|
|
32
|
+
}
|
|
33
|
+
|
|
20
34
|
export type PostHogErrorReporterOptions = {
|
|
21
35
|
/** The project API key, or how to read it; a key that cannot be read yet is read again later. */
|
|
22
36
|
key: string | (() => Promise<string>)
|
|
23
37
|
host: string
|
|
24
|
-
/** Sent with every report: which service and deployment report
|
|
38
|
+
/** Sent with every report: which service and deployment report. */
|
|
25
39
|
properties: Record<string, string>
|
|
40
|
+
/**
|
|
41
|
+
* Also send the context's account and record IDs: the user as the report's `distinct_id`, the
|
|
42
|
+
* records as `document_id` and the like. Off, a report names neither, as it always did.
|
|
43
|
+
*/
|
|
44
|
+
includeIds?: boolean
|
|
26
45
|
/** The property that names the context's `source`, such as `cloud_source`. */
|
|
27
46
|
sourceProperty: string
|
|
28
47
|
/** Names the service in its own log, such as `Cloud`. */
|
|
@@ -33,7 +52,8 @@ export type PostHogErrorReporterOptions = {
|
|
|
33
52
|
/**
|
|
34
53
|
* Reports errors to PostHog error tracking, each as it is caught, as a `$exception` with no person
|
|
35
54
|
* profile and no GeoIP. A report carries `properties`, the source, and a request's method and
|
|
36
|
-
* matched route and ID;
|
|
55
|
+
* matched route and ID; with `includeIds`, also the account and record IDs involved. Never a name,
|
|
56
|
+
* an email, an address, or what a request carried.
|
|
37
57
|
*/
|
|
38
58
|
export function createPostHogErrorReporter<Source extends string>(
|
|
39
59
|
options: PostHogErrorReporterOptions
|
|
@@ -65,13 +85,17 @@ export function createPostHogErrorReporter<Source extends string>(
|
|
|
65
85
|
return async (error, context) => {
|
|
66
86
|
try {
|
|
67
87
|
const client = await posthog()
|
|
88
|
+
const ids = options.includeIds === true
|
|
68
89
|
// Undefined request fields are left out of the event's JSON.
|
|
69
|
-
await client.captureExceptionImmediate(error, undefined, {
|
|
90
|
+
await client.captureExceptionImmediate(error, ids ? context.userId : undefined, {
|
|
70
91
|
...options.properties,
|
|
71
92
|
[options.sourceProperty]: context.source,
|
|
72
93
|
http_method: context.method,
|
|
73
94
|
http_route: context.route,
|
|
74
|
-
request_id: context.requestId
|
|
95
|
+
request_id: context.requestId,
|
|
96
|
+
...(ids ? resourceProperties(context.resources) : {}),
|
|
97
|
+
// A user's ID names the report's user, never a person profile in PostHog.
|
|
98
|
+
$process_person_profile: false
|
|
75
99
|
})
|
|
76
100
|
} catch (failure) {
|
|
77
101
|
console.error(`[${logName}] Reporting an error failed:`, failure)
|
|
@@ -10,6 +10,7 @@ export type CloudflareEmailBinding = {
|
|
|
10
10
|
send(message: {
|
|
11
11
|
to: string
|
|
12
12
|
from: string
|
|
13
|
+
replyTo?: string
|
|
13
14
|
subject: string
|
|
14
15
|
html: string
|
|
15
16
|
text: string
|
|
@@ -50,6 +51,7 @@ export function createCloudflareEmailTransport(
|
|
|
50
51
|
const result = await binding.send({
|
|
51
52
|
to: message.to,
|
|
52
53
|
from: message.from,
|
|
54
|
+
...(message.replyTo ? { replyTo: message.replyTo } : {}),
|
|
53
55
|
subject: message.subject,
|
|
54
56
|
html: message.html,
|
|
55
57
|
text: message.text,
|
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
createConfiguredCloudPolicy,
|
|
8
8
|
relayDocumentLookups,
|
|
9
9
|
reportCloudError,
|
|
10
|
-
type CollaborationRelay
|
|
10
|
+
type CollaborationRelay,
|
|
11
|
+
type CollaborationRelayOptions
|
|
11
12
|
} from '#cloud/server'
|
|
12
13
|
import { DurableObject } from 'cloudflare:workers'
|
|
13
14
|
import type { Context } from 'hono'
|
|
@@ -25,6 +26,8 @@ export interface CollaborationRelayRPC extends DurableObject<CloudflareCloudEnvi
|
|
|
25
26
|
closeDocument(documentId: string): Promise<void>
|
|
26
27
|
/** Tells the document's live rooms its version history changed. */
|
|
27
28
|
announceVersions(documentId: string): Promise<void>
|
|
29
|
+
/** Tells the document's live rooms one of its comment threads changed. */
|
|
30
|
+
announceComments(documentId: string, threadId: string): Promise<void>
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
/** The Durable Object class a Worker exports for collaboration rooms. */
|
|
@@ -75,7 +78,7 @@ export function relayRoute(jurisdiction?: DurableObjectJurisdiction) {
|
|
|
75
78
|
function configuredRelay(
|
|
76
79
|
{ config }: PreparedCloudflareCloud,
|
|
77
80
|
documentId: string,
|
|
78
|
-
onError:
|
|
81
|
+
onError: NonNullable<CollaborationRelayOptions['onError']>
|
|
79
82
|
): CollaborationRelay {
|
|
80
83
|
// Hyperdrive keeps no session settings and ends queries past its own limit.
|
|
81
84
|
const database = createPostgresCloudDatabase({
|
|
@@ -122,10 +125,17 @@ export function createCloudflareRelayObject(
|
|
|
122
125
|
sockets: () => this.ctx.getWebSockets(),
|
|
123
126
|
createRelay: async (documentId) => {
|
|
124
127
|
const prepared = await prepare(this.env)
|
|
125
|
-
return configuredRelay(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
)
|
|
128
|
+
return configuredRelay(
|
|
129
|
+
prepared,
|
|
130
|
+
documentId,
|
|
131
|
+
(message, error, { userId, ...resources } = {}) =>
|
|
132
|
+
this.ctx.waitUntil(
|
|
133
|
+
reportCloudError(prepared.reportError, message, error, {
|
|
134
|
+
source: 'relay',
|
|
135
|
+
resources,
|
|
136
|
+
...(userId && { userId })
|
|
137
|
+
})
|
|
138
|
+
)
|
|
129
139
|
)
|
|
130
140
|
}
|
|
131
141
|
})
|
|
@@ -178,5 +188,10 @@ export function createCloudflareRelayObject(
|
|
|
178
188
|
if (!this.#sockets.active) return
|
|
179
189
|
;(await this.#sockets.open(documentId)).announceVersions(documentId)
|
|
180
190
|
}
|
|
191
|
+
|
|
192
|
+
async announceComments(documentId: string, threadId: string) {
|
|
193
|
+
if (!this.#sockets.active) return
|
|
194
|
+
;(await this.#sockets.open(documentId)).announceComments(documentId, threadId)
|
|
195
|
+
}
|
|
181
196
|
}
|
|
182
197
|
}
|
|
@@ -30,6 +30,7 @@ import { cloudflareRayId } from './logging'
|
|
|
30
30
|
import { inMaintenance, maintenanceResponse } from './maintenance'
|
|
31
31
|
import { createCloudflareRelayObject, relayFor, relayRoute } from './relay'
|
|
32
32
|
import { assetSiteFiles } from './site'
|
|
33
|
+
import { provideXMLParser } from './xml'
|
|
33
34
|
|
|
34
35
|
function emailTransport({ config }: PreparedCloudflareCloud, env: CloudflareCloudEnvironment) {
|
|
35
36
|
if (config.emailTransport !== 'cloudflare') return undefined
|
|
@@ -73,6 +74,7 @@ function cloudServices(
|
|
|
73
74
|
const queued = createTransactionalEmailService(database, {
|
|
74
75
|
encryptionSecret: config.authSecret,
|
|
75
76
|
from: config.emailFrom ?? '',
|
|
77
|
+
replyTo: config.emailReplyTo,
|
|
76
78
|
transport
|
|
77
79
|
})
|
|
78
80
|
// Mail is sent once the request is done rather than by a polling worker, so sign-in links
|
|
@@ -164,6 +166,7 @@ export function createCloudflareCloud(
|
|
|
164
166
|
configSource: string,
|
|
165
167
|
{ relayJurisdiction }: CloudflareCloudOptions = {}
|
|
166
168
|
) {
|
|
169
|
+
provideXMLParser()
|
|
167
170
|
const { prepare, reporter } = cloudflareCloudSetup(configSource)
|
|
168
171
|
const relay = (env: CloudflareCloudEnvironment, documentId: string) =>
|
|
169
172
|
relayFor(env, documentId, relayJurisdiction)
|
|
@@ -198,6 +201,9 @@ export function createCloudflareCloud(
|
|
|
198
201
|
runInBackground(relay(c.env, documentId).closeDocument(documentId)),
|
|
199
202
|
onDocumentVersionsChanged: (documentId) =>
|
|
200
203
|
runInBackground(relay(c.env, documentId).announceVersions(documentId)),
|
|
204
|
+
onDocumentCommentsChanged: (documentId, threadId) =>
|
|
205
|
+
runInBackground(relay(c.env, documentId).announceComments(documentId, threadId)),
|
|
206
|
+
runInBackground,
|
|
201
207
|
reportError: services.reporter,
|
|
202
208
|
forwardedRequestId: cloudflareRayId
|
|
203
209
|
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DOMParser, Node } from '@xmldom/xmldom'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Gives the AWS SDK the XML parser it reads S3's answers with. Wrangler bundles the SDK's browser
|
|
5
|
+
* build, which parses XML with the browser's `DOMParser` and `Node`; workerd has neither, so every
|
|
6
|
+
* S3 error would surface as a `ReferenceError` instead of its code. A runtime that has a
|
|
7
|
+
* `DOMParser` keeps its own.
|
|
8
|
+
*/
|
|
9
|
+
export function provideXMLParser(): void {
|
|
10
|
+
if ('DOMParser' in globalThis) return
|
|
11
|
+
Object.assign(globalThis, { DOMParser, Node })
|
|
12
|
+
}
|
|
@@ -1,58 +1,62 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { createPostgresCloudDatabase } from '#cloud/runtime/postgres/database'
|
|
4
|
+
import {
|
|
5
|
+
approveEnrollmentByEmail,
|
|
6
|
+
createEnrollmentService,
|
|
7
|
+
grantDeploymentAdminByEmail,
|
|
8
|
+
pendingCloudMigrations
|
|
9
|
+
} from '#cloud/server'
|
|
4
10
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Approves a person and makes them a deployment administrator, for a deployment that has none
|
|
13
|
+
* to do it in the console, or records a request for access, as if they had asked here, for an
|
|
14
|
+
* administrator to review in the console; `request` sends no email, and `--waitlist` marks someone
|
|
15
|
+
* from openpencil.dev's waitlist, whose approval with the invitation letter thanks them for joining
|
|
16
|
+
* it. It needs only the database,
|
|
17
|
+
* through `DATABASE_URL`, and refuses one this version's server has not migrated, rather than
|
|
18
|
+
* migrating it under another version.
|
|
19
|
+
*/
|
|
20
|
+
const args = process.argv.slice(2)
|
|
21
|
+
const waitlist = args.includes('--waitlist')
|
|
22
|
+
const [operation, email, ...nameWords] = args.filter((arg) => arg !== '--waitlist')
|
|
23
|
+
if ((operation !== 'approve' && operation !== 'grant' && operation !== 'request') || !email) {
|
|
24
|
+
throw new Error('Usage: admin <approve|grant|request> <email> [name] [--waitlist]')
|
|
8
25
|
}
|
|
26
|
+
if (waitlist && operation !== 'request') throw new Error('--waitlist only marks a request')
|
|
27
|
+
const connectionString = process.env.DATABASE_URL
|
|
28
|
+
if (!connectionString) throw new Error('DATABASE_URL must name the deployment database')
|
|
9
29
|
|
|
10
|
-
const
|
|
30
|
+
const database = createPostgresCloudDatabase({ connectionString })
|
|
11
31
|
try {
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
reviewedAt: new Date(),
|
|
31
|
-
reviewedBy: 'cli-bootstrap',
|
|
32
|
-
reviewNote: 'Approved through CLI bootstrap'
|
|
33
|
-
})
|
|
32
|
+
const pending = await pendingCloudMigrations(database)
|
|
33
|
+
if (pending.length > 0) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
`The database has not run ${pending.join(', ')}; deploy this version or run migrate first`
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
if (operation === 'request') {
|
|
39
|
+
const outcome = await createEnrollmentService(database).request({
|
|
40
|
+
email,
|
|
41
|
+
name: nameWords.join(' '),
|
|
42
|
+
...(waitlist && { source: 'waitlist' as const })
|
|
43
|
+
})
|
|
44
|
+
// An address already waiting or approved keeps its request, so it is not marked as waitlist.
|
|
45
|
+
console.log(
|
|
46
|
+
JSON.stringify(
|
|
47
|
+
outcome === 'recorded'
|
|
48
|
+
? { requested: email, ...(waitlist && { waitlist }) }
|
|
49
|
+
: { unchanged: email }
|
|
34
50
|
)
|
|
35
|
-
|
|
36
|
-
console.log(JSON.stringify({ approved: normalized }))
|
|
51
|
+
)
|
|
37
52
|
} else {
|
|
38
|
-
|
|
39
|
-
.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
.insertInto('adminAuditEvent')
|
|
46
|
-
.values({
|
|
47
|
-
id: crypto.randomUUID(),
|
|
48
|
-
actorUserId: 'cli-bootstrap',
|
|
49
|
-
action: 'user.admin-granted',
|
|
50
|
-
subjectType: 'user',
|
|
51
|
-
subjectId: user.id,
|
|
52
|
-
metadata: { email: normalized }
|
|
53
|
-
})
|
|
54
|
-
.execute()
|
|
55
|
-
console.log(JSON.stringify({ admin: normalized, userId: user.id }))
|
|
53
|
+
console.log(
|
|
54
|
+
JSON.stringify(
|
|
55
|
+
operation === 'approve'
|
|
56
|
+
? { approved: await approveEnrollmentByEmail(database, email) }
|
|
57
|
+
: await grantDeploymentAdminByEmail(database, email)
|
|
58
|
+
)
|
|
59
|
+
)
|
|
56
60
|
}
|
|
57
61
|
} finally {
|
|
58
62
|
await database.destroy()
|
|
@@ -20,6 +20,7 @@ export function createNodemailerTransactionalEmailTransport(
|
|
|
20
20
|
async send(message) {
|
|
21
21
|
const result = (await options.transporter.sendMail({
|
|
22
22
|
from: message.from,
|
|
23
|
+
replyTo: message.replyTo,
|
|
23
24
|
to: message.to,
|
|
24
25
|
subject: message.subject,
|
|
25
26
|
html: message.html,
|
|
@@ -125,8 +125,12 @@ async function startConfiguredServer(
|
|
|
125
125
|
store: createCollaborationStateStore(database, objects),
|
|
126
126
|
maximumMessageBytes: config.technicalLimits.maximumCollaborationMessageBytes,
|
|
127
127
|
maximumConnectionsPerRoom: config.technicalLimits.maximumConnectionsPerRoom,
|
|
128
|
-
onError: (message, error) =>
|
|
129
|
-
void reportCloudError(reportError, message, error, {
|
|
128
|
+
onError: (message, error, { userId, ...resources } = {}) =>
|
|
129
|
+
void reportCloudError(reportError, message, error, {
|
|
130
|
+
source: 'relay',
|
|
131
|
+
resources,
|
|
132
|
+
...(userId && { userId })
|
|
133
|
+
}),
|
|
130
134
|
...relayDocumentLookups(database, policy, config.deployment)
|
|
131
135
|
})
|
|
132
136
|
const app = createCloudApp({
|
|
@@ -142,6 +146,8 @@ async function startConfiguredServer(
|
|
|
142
146
|
onDocumentRestored: (documentId) => relay.startOver(documentId),
|
|
143
147
|
onDocumentTakenDown: (documentId) => relay.closeDocument(documentId),
|
|
144
148
|
onDocumentVersionsChanged: (documentId) => relay.announceVersions(documentId),
|
|
149
|
+
onDocumentCommentsChanged: (documentId, threadId) =>
|
|
150
|
+
relay.announceComments(documentId, threadId),
|
|
145
151
|
reportError,
|
|
146
152
|
forwardedRequestId: proxyRequestId
|
|
147
153
|
})
|
|
@@ -9,7 +9,8 @@ export type CloudRuntimeName = 'node' | 'cloudflare'
|
|
|
9
9
|
/**
|
|
10
10
|
* Reports server errors to the PostHog project the deployment's `[error_tracking]` names, or
|
|
11
11
|
* returns nothing when it names none. Reports carry the runtime, the deployment, and where the
|
|
12
|
-
* error was caught,
|
|
12
|
+
* error was caught, and the account and record IDs involved when `include_ids` is set; never a
|
|
13
|
+
* name, an email, an address, or what a request carried.
|
|
13
14
|
*/
|
|
14
15
|
export function createCloudErrorReporter(
|
|
15
16
|
config: CloudServerConfig,
|
|
@@ -27,6 +28,7 @@ export function createCloudErrorReporter(
|
|
|
27
28
|
cloud_host: new URL(config.publicURL).host
|
|
28
29
|
},
|
|
29
30
|
sourceProperty: 'cloud_source',
|
|
31
|
+
includeIds: tracking.includeIds,
|
|
30
32
|
logName: 'Cloud',
|
|
31
33
|
fetch: options.fetch
|
|
32
34
|
})
|
|
@@ -16,7 +16,9 @@ const ACCOUNT_SECURITY_ERROR_CODES: Record<string, AccountSecurityErrorCode> = {
|
|
|
16
16
|
LAST_ADMIN_REQUIRED: 'last_admin_required',
|
|
17
17
|
CHANGE_EMAIL_DISABLED: 'email_change_unavailable',
|
|
18
18
|
CURRENT_SESSION: 'current_session',
|
|
19
|
-
EMAIL_UNCHANGED: 'email_unchanged'
|
|
19
|
+
EMAIL_UNCHANGED: 'email_unchanged',
|
|
20
|
+
// A second factor's code that does not match (`verifySecondFactor`).
|
|
21
|
+
INVALID_CODE: 'code_invalid'
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
async function accountAction<Value>(operation: () => Promise<Value>, context: Context) {
|
|
@@ -157,13 +157,33 @@ export function createAccountDeletionService(database: Kysely<CloudDatabase>) {
|
|
|
157
157
|
/**
|
|
158
158
|
* Removes everything Cloud keeps about the account, in one transaction, or refuses with
|
|
159
159
|
* `AccountDeletionBlockedError` and changes nothing. Its workspaces are locked first, so nobody
|
|
160
|
-
* joins one, changes a role in one, or adds a document to one while it decides.
|
|
160
|
+
* joins one, changes a role in one, or adds a document to one while it decides. `before` runs
|
|
161
|
+
* first in that transaction, with the account's row locked and read again, as an
|
|
162
|
+
* administrator's check and audit entry do; a throw from it changes nothing. The address is the
|
|
163
|
+
* locked one, so a change that lands meanwhile cannot leave another address's request behind.
|
|
161
164
|
*/
|
|
162
|
-
async remove(
|
|
165
|
+
async remove(
|
|
166
|
+
account: { id: string },
|
|
167
|
+
options: {
|
|
168
|
+
before?: (
|
|
169
|
+
transaction: Transaction<CloudDatabase>,
|
|
170
|
+
user: { id: string; email: string; name: string; role: string | null }
|
|
171
|
+
) => Promise<void>
|
|
172
|
+
} = {}
|
|
173
|
+
): Promise<void> {
|
|
163
174
|
await database.transaction().execute(async (transaction) => {
|
|
164
|
-
|
|
175
|
+
// The administrators' rows lock first, in one order for every deletion, so two
|
|
176
|
+
// administrators deleting themselves at once wait for each other rather than deadlock.
|
|
177
|
+
if (await lastAdministrator(transaction, account.id, true)) {
|
|
165
178
|
throw new AccountLastAdministratorError()
|
|
166
179
|
}
|
|
180
|
+
const user = await transaction
|
|
181
|
+
.selectFrom('user')
|
|
182
|
+
.select(['id', 'email', 'name', 'role'])
|
|
183
|
+
.where('id', '=', account.id)
|
|
184
|
+
.forUpdate()
|
|
185
|
+
.executeTakeFirstOrThrow()
|
|
186
|
+
await options.before?.(transaction, user)
|
|
167
187
|
const workspaceIds = await transaction
|
|
168
188
|
.selectFrom('workspaceMember')
|
|
169
189
|
.select('workspaceId')
|
|
@@ -256,10 +276,24 @@ export function createAccountDeletionService(database: Kysely<CloudDatabase>) {
|
|
|
256
276
|
'termsAcceptance',
|
|
257
277
|
'userPicture',
|
|
258
278
|
'signIn',
|
|
259
|
-
'mfaAssurance'
|
|
279
|
+
'mfaAssurance',
|
|
280
|
+
'notificationSetting',
|
|
281
|
+
'commentRead',
|
|
282
|
+
'commentMention'
|
|
260
283
|
] as const) {
|
|
261
284
|
await transaction.deleteFrom(table).where('userId', '=', user.id).execute()
|
|
262
285
|
}
|
|
286
|
+
// Comments the account wrote stay, nameless, in the threads others keep; what it was
|
|
287
|
+
// emailed about them goes.
|
|
288
|
+
await transaction
|
|
289
|
+
.deleteFrom('commentEmail')
|
|
290
|
+
.where((expression) =>
|
|
291
|
+
expression.or([
|
|
292
|
+
expression('senderId', '=', user.id),
|
|
293
|
+
expression('recipientId', '=', user.id)
|
|
294
|
+
])
|
|
295
|
+
)
|
|
296
|
+
.execute()
|
|
263
297
|
// Personal access tokens have no key to cascade from, since Cloud builds their table.
|
|
264
298
|
await transaction.deleteFrom('apikey').where('referenceId', '=', user.id).execute()
|
|
265
299
|
await transaction
|