@open-pencil/cloud 0.17.0-beta.4 → 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/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 +783 -47
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1651 -382
- package/dist/client.js.map +1 -1
- package/dist/contract.d.ts +2 -2
- package/dist/contract.js +2 -2
- package/dist/contract2.js +701 -45
- package/dist/contract2.js.map +1 -1
- package/dist/email.d.ts +2138 -34
- package/dist/email.d.ts.map +1 -1
- package/dist/email.js +4343 -306
- package/dist/email.js.map +1 -1
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +61 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +1338 -44
- package/dist/index.d.ts.map +1 -1
- package/dist/index2.d.ts +45 -0
- package/dist/index2.d.ts.map +1 -0
- package/dist/listen.mjs +958 -340
- package/dist/listen.mjs.map +1 -1
- package/dist/runtime-cloudflare.d.ts +93 -0
- package/dist/runtime-cloudflare.d.ts.map +1 -0
- package/dist/runtime-cloudflare.js +18032 -0
- package/dist/runtime-cloudflare.js.map +1 -0
- package/dist/runtime-node.d.mts +12615 -5249
- package/dist/runtime-node.d.mts.map +1 -1
- package/dist/server.d.ts +17367 -8567
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +13587 -7333
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +11601 -5401
- package/dist/server.mjs.map +1 -1
- package/dist/server2.mjs +84 -62
- package/dist/server2.mjs.map +1 -1
- package/package.json +31 -5
- package/src/admin/api/routes.ts +263 -190
- package/src/admin/audit/service.ts +11 -3
- package/src/admin/bootstrap.ts +86 -0
- package/src/admin/documents/service.ts +195 -10
- 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 +15 -3
- package/src/admin/schema.ts +6 -5
- package/src/admin/users/service.ts +173 -16
- package/src/client/api.ts +52 -473
- package/src/client/auth/client.ts +22 -3
- package/src/client/comments.ts +205 -0
- package/src/client/community.ts +40 -0
- package/src/client/device-authorization.ts +4 -20
- package/src/client/discovery.ts +39 -11
- package/src/client/documents.ts +160 -0
- 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 +4 -0
- package/src/client/portal/account.ts +73 -3
- package/src/client/portal/administration.ts +52 -5
- package/src/client/portal/request.ts +6 -2
- 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/tour.ts +44 -0
- package/src/client/versions.ts +110 -0
- package/src/contract/account.ts +111 -11
- package/src/contract/admin/index.ts +48 -3
- package/src/contract/billing.ts +235 -0
- package/src/contract/collaboration.ts +5 -0
- package/src/contract/comments.ts +223 -0
- package/src/contract/community.ts +60 -0
- package/src/contract/discovery.ts +94 -5
- package/src/contract/entitlements.ts +10 -0
- package/src/contract/index.ts +64 -5
- package/src/contract/links.ts +62 -4
- package/src/contract/locale.ts +27 -0
- package/src/contract/portal.ts +12 -1
- package/src/contract/relay.ts +3 -1
- package/src/contract/routes.ts +10 -0
- package/src/contract/services.ts +62 -20
- package/src/contract/workspaces.ts +5 -0
- package/src/email/i18n.ts +174 -0
- package/src/email/index.ts +13 -2
- package/src/email/locales/ar.json +169 -0
- package/src/email/locales/de.json +169 -0
- package/src/email/locales/es.json +169 -0
- package/src/email/locales/fr.json +169 -0
- package/src/email/locales/it.json +169 -0
- package/src/email/locales/ja.json +169 -0
- package/src/email/locales/pl.json +169 -0
- package/src/email/locales/pt-br.json +169 -0
- package/src/email/locales/ru.json +169 -0
- package/src/email/locales/zh-cn.json +169 -0
- package/src/email/messages.ts +235 -0
- package/src/email/render.ts +160 -276
- package/src/email/samples.ts +142 -0
- package/src/email/schema.ts +98 -8
- package/src/email/templates/BrandEmail.vue +56 -0
- package/src/email/templates/CommentNotification.vue +39 -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/EnrollmentInvitation.vue +53 -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 +47 -0
- package/src/email/templates/WaitlistConfirmation.vue +29 -0
- package/src/email/templates/WorkspaceInvitation.vue +28 -0
- package/src/email/templates/brand.ts +15 -61
- package/src/email/templates/localization.ts +17 -0
- package/src/errors/index.ts +6 -0
- package/src/{server/errors → errors}/posthog.ts +28 -4
- package/src/global.d.ts +7 -0
- package/src/runtime/cloudflare/email.ts +2 -0
- package/src/runtime/cloudflare/relay/index.ts +28 -7
- package/src/runtime/cloudflare/tsconfig.json +2 -1
- package/src/runtime/cloudflare/worker.ts +14 -1
- package/src/runtime/cloudflare/xml.ts +12 -0
- package/src/runtime/node/admin.ts +51 -47
- package/src/runtime/node/cleanup.ts +5 -1
- package/src/runtime/node/email/runtime.ts +1 -0
- package/src/runtime/node/email/transport.ts +14 -10
- package/src/runtime/node/main.ts +1 -1
- package/src/runtime/node/server.ts +20 -4
- package/src/runtime/node/services/main.ts +1 -1
- package/src/runtime/posthog/errors.ts +5 -2
- 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/actions.ts +3 -1
- package/src/server/account/deletion.ts +40 -4
- package/src/server/account/routes.ts +305 -253
- package/src/server/account/tokens.ts +57 -0
- package/src/server/api/router.ts +44 -6
- package/src/server/app/checks.ts +89 -0
- package/src/server/app/cors.ts +44 -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 +123 -0
- package/src/server/app/services.ts +219 -0
- package/src/server/auth/access-control.ts +13 -8
- package/src/server/auth/access-tokens.ts +62 -0
- package/src/server/auth/account.ts +13 -12
- package/src/server/auth/activity.ts +7 -2
- package/src/server/auth/adapter.ts +36 -3
- package/src/server/auth/email.ts +33 -18
- package/src/server/auth/endpoints.ts +4 -0
- package/src/server/auth/enrollment.ts +116 -0
- package/src/server/auth/factory.ts +165 -189
- package/src/server/auth/index.ts +1 -1
- package/src/server/auth/logger.ts +23 -0
- package/src/server/auth/methods.ts +162 -0
- package/src/server/auth/mfa-assurance.ts +190 -2
- package/src/server/auth/passwords.ts +43 -0
- package/src/server/auth/rate-limit.ts +31 -0
- package/src/server/auth/runtime.ts +19 -5
- package/src/server/auth/session.ts +2 -0
- package/src/server/auth/social-providers.ts +70 -24
- package/src/server/billing/index.ts +8 -0
- package/src/server/billing/notify.ts +55 -0
- package/src/server/billing/routes.ts +27 -0
- package/src/server/billing/seats.ts +17 -0
- package/src/server/billing/tokens.ts +37 -0
- package/src/server/cleanup/configured.ts +16 -3
- 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/cleanup/worker.ts +10 -1
- package/src/server/collaboration/relay/connection.ts +7 -2
- package/src/server/collaboration/relay/hub.ts +80 -166
- package/src/server/collaboration/relay/room.ts +154 -0
- package/src/server/collaboration/routes.ts +8 -5
- package/src/server/collaboration/service.ts +21 -2
- 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/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 +35 -10
- package/src/server/config/index.ts +2 -2
- package/src/server/config/public.ts +25 -6
- package/src/server/config/schema.ts +53 -293
- package/src/server/config/toml/schema.ts +330 -0
- package/src/server/db/index.ts +3 -1
- package/src/server/db/migrate.ts +33 -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/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/migrations/schema.ts +26 -1
- package/src/server/db/tables.ts +122 -3
- package/src/server/db/users.ts +22 -0
- package/src/server/documents/access.ts +17 -0
- package/src/server/documents/images.ts +6 -1
- package/src/server/documents/index.ts +1 -1
- package/src/server/documents/limits.ts +7 -1
- package/src/server/documents/routes.ts +12 -12
- package/src/server/documents/service.ts +31 -407
- package/src/server/documents/summary.ts +15 -0
- package/src/server/documents/uploads.ts +450 -0
- package/src/server/documents/versions/routes.ts +7 -8
- package/src/server/documents/versions/service.ts +86 -26
- package/src/server/email/invitations.ts +1 -0
- package/src/server/email/service.ts +39 -6
- package/src/server/email/types.ts +13 -0
- package/src/server/errors/index.ts +49 -12
- package/src/server/index.ts +27 -6
- 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/invitations/types.ts +5 -1
- package/src/server/objects/types.ts +5 -0
- package/src/server/pictures/service.ts +3 -1
- 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/policy/workspace.ts +5 -2
- 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 +5 -3
- package/src/server/reports/service.ts +27 -3
- package/src/server/services/routes.ts +2 -2
- package/src/server/sharing/capabilities/service.ts +3 -4
- package/src/server/sharing/document-routes.ts +3 -3
- package/src/server/sharing/invitations/service.ts +17 -8
- package/src/server/sharing/routes.ts +15 -15
- package/src/server/validation.ts +35 -24
- package/src/server/workspaces/members.ts +57 -31
- package/src/server/workspaces/repository.ts +23 -12
- package/src/server/workspaces/routes.ts +8 -8
- package/src/services/app.ts +31 -22
- package/src/services/config.ts +48 -8
- package/src/services/metering.ts +15 -27
- 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
|
@@ -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()
|
|
@@ -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
|
)
|
|
@@ -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,
|
|
@@ -77,16 +78,19 @@ export function createNodemailerInvitationDelivery(
|
|
|
77
78
|
const transport = createNodemailerTransactionalEmailTransport(options)
|
|
78
79
|
return {
|
|
79
80
|
async sendDocumentInvitation(message: DocumentInvitationMessage): Promise<void> {
|
|
80
|
-
const rendered = await renderTransactionalEmail(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
81
|
+
const rendered = await renderTransactionalEmail(
|
|
82
|
+
{
|
|
83
|
+
kind: 'document-invitation',
|
|
84
|
+
payload: {
|
|
85
|
+
inviterName: message.inviterName,
|
|
86
|
+
documentName: message.documentName,
|
|
87
|
+
permission: message.permission,
|
|
88
|
+
expiresAt: message.expiresAt,
|
|
89
|
+
acceptanceURL: message.acceptanceURL
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
message.locale
|
|
93
|
+
)
|
|
90
94
|
await transport.send({
|
|
91
95
|
deliveryId: message.deliveryId,
|
|
92
96
|
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,
|
|
@@ -115,8 +125,12 @@ async function startConfiguredServer(
|
|
|
115
125
|
store: createCollaborationStateStore(database, objects),
|
|
116
126
|
maximumMessageBytes: config.technicalLimits.maximumCollaborationMessageBytes,
|
|
117
127
|
maximumConnectionsPerRoom: config.technicalLimits.maximumConnectionsPerRoom,
|
|
118
|
-
onError: (message, error) =>
|
|
119
|
-
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
|
+
}),
|
|
120
134
|
...relayDocumentLookups(database, policy, config.deployment)
|
|
121
135
|
})
|
|
122
136
|
const app = createCloudApp({
|
|
@@ -132,6 +146,8 @@ async function startConfiguredServer(
|
|
|
132
146
|
onDocumentRestored: (documentId) => relay.startOver(documentId),
|
|
133
147
|
onDocumentTakenDown: (documentId) => relay.closeDocument(documentId),
|
|
134
148
|
onDocumentVersionsChanged: (documentId) => relay.announceVersions(documentId),
|
|
149
|
+
onDocumentCommentsChanged: (documentId, threadId) =>
|
|
150
|
+
relay.announceComments(documentId, threadId),
|
|
135
151
|
reportError,
|
|
136
152
|
forwardedRequestId: proxyRequestId
|
|
137
153
|
})
|
|
@@ -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. */
|
|
@@ -8,7 +9,8 @@ export type CloudRuntimeName = 'node' | 'cloudflare'
|
|
|
8
9
|
/**
|
|
9
10
|
* Reports server errors to the PostHog project the deployment's `[error_tracking]` names, or
|
|
10
11
|
* returns nothing when it names none. Reports carry the runtime, the deployment, and where the
|
|
11
|
-
* 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.
|
|
12
14
|
*/
|
|
13
15
|
export function createCloudErrorReporter(
|
|
14
16
|
config: CloudServerConfig,
|
|
@@ -26,6 +28,7 @@ export function createCloudErrorReporter(
|
|
|
26
28
|
cloud_host: new URL(config.publicURL).host
|
|
27
29
|
},
|
|
28
30
|
sourceProperty: 'cloud_source',
|
|
31
|
+
includeIds: tracking.includeIds,
|
|
29
32
|
logName: 'Cloud',
|
|
30
33
|
fetch: options.fetch
|
|
31
34
|
})
|
|
@@ -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
|
|
@@ -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,26 @@ 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()
|
|
297
|
+
// Personal access tokens have no key to cascade from, since Cloud builds their table.
|
|
298
|
+
await transaction.deleteFrom('apikey').where('referenceId', '=', user.id).execute()
|
|
263
299
|
await transaction
|
|
264
300
|
.deleteFrom('enrollment')
|
|
265
301
|
.where('emailNormalized', '=', normalizeEnrollmentEmail(user.email))
|