@open-pencil/cloud 0.17.0-beta.2 → 0.17.0-beta.4
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 +1 -1
- package/dist/bin/{ai-relay.mjs → services.mjs} +8 -8
- package/dist/bin/services.mjs.map +1 -0
- package/dist/client.d.ts +236 -46
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +649 -400
- package/dist/client.js.map +1 -1
- package/dist/contract.d.ts +2 -2
- package/dist/contract.js +2 -2
- package/dist/contract2.js +680 -443
- package/dist/contract2.js.map +1 -1
- package/dist/email.d.ts +9 -1
- package/dist/email.d.ts.map +1 -1
- package/dist/email.js +99 -58
- package/dist/email.js.map +1 -1
- package/dist/index.d.ts +469 -65
- package/dist/index.d.ts.map +1 -1
- package/dist/listen.mjs +505 -787
- package/dist/listen.mjs.map +1 -1
- package/dist/runtime-node.d.mts +3920 -2524
- package/dist/runtime-node.d.mts.map +1 -1
- package/dist/runtime-node.mjs +6 -5
- package/dist/runtime-node.mjs.map +1 -1
- package/dist/server.d.ts +3586 -1897
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +5216 -4272
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +5179 -3623
- package/dist/server.mjs.map +1 -1
- package/dist/server2.mjs +101 -79
- package/dist/server2.mjs.map +1 -1
- package/package.json +7 -6
- package/src/admin/api/routes.ts +59 -0
- package/src/admin/audit/service.ts +25 -6
- package/src/admin/documents/service.ts +361 -0
- package/src/admin/errors.ts +9 -1
- package/src/admin/index.ts +6 -0
- package/src/admin/operations/service.ts +7 -0
- package/src/admin/reports/service.ts +147 -0
- package/src/admin/schema.ts +6 -0
- package/src/client/api.ts +36 -21
- package/src/client/auth/navigation.ts +6 -5
- package/src/client/index.ts +7 -7
- package/src/client/portal/account.ts +25 -0
- package/src/client/portal/administration.ts +56 -0
- package/src/client/{ai.ts → services.ts} +44 -27
- package/src/contract/account.ts +58 -2
- package/src/contract/admin/index.ts +67 -3
- package/src/contract/collaboration.ts +6 -1
- package/src/contract/discovery.ts +22 -4
- package/src/contract/documents.ts +27 -0
- package/src/contract/entitlements.ts +2 -2
- package/src/contract/index.ts +63 -37
- package/src/contract/relay.ts +6 -0
- package/src/contract/reports.ts +42 -0
- package/src/contract/services.ts +233 -0
- package/src/contract/sharing.ts +3 -9
- package/src/email/render.ts +26 -0
- package/src/email/schema.ts +11 -1
- package/src/email/templates/brand.ts +1 -1
- package/src/runtime/cloudflare/environment.ts +22 -11
- package/src/runtime/cloudflare/index.ts +1 -1
- package/src/runtime/cloudflare/logging.ts +15 -0
- package/src/runtime/cloudflare/maintenance.ts +31 -0
- package/src/runtime/cloudflare/relay/index.ts +62 -14
- package/src/runtime/cloudflare/worker.ts +39 -13
- package/src/runtime/node/application.ts +5 -3
- package/src/runtime/node/bootstrap.ts +15 -4
- package/src/runtime/node/cleanup.ts +16 -3
- package/src/runtime/node/entitlements/main.ts +14 -11
- package/src/runtime/node/index.ts +1 -1
- package/src/runtime/node/migrate.ts +5 -1
- package/src/runtime/node/relay.ts +8 -2
- package/src/runtime/node/request-id.ts +13 -0
- package/src/runtime/node/server.ts +39 -15
- package/src/runtime/node/{ai-relay → services}/main.ts +6 -6
- package/src/runtime/node/{ai-relay → services}/server.ts +18 -18
- package/src/runtime/postgres/database.ts +20 -1
- package/src/runtime/posthog/errors.ts +15 -31
- package/src/runtime/s3/objects.ts +24 -1
- package/src/runtime/site/server.ts +32 -5
- package/src/server/account/actions.ts +5 -0
- package/src/server/account/deletion.ts +302 -0
- package/src/server/account/routes.ts +47 -3
- package/src/server/account/terms.ts +42 -0
- package/src/server/api/router.ts +9 -5
- package/src/server/api/types.ts +2 -0
- package/src/server/app.ts +90 -16
- package/src/server/auth/access-control.ts +63 -0
- package/src/server/auth/adapter.ts +11 -0
- package/src/server/auth/endpoints.ts +5 -1
- package/src/server/auth/factory.ts +30 -3
- package/src/server/auth/index.ts +10 -1
- package/src/server/cleanup/configured.ts +12 -5
- package/src/server/cleanup/documents.ts +165 -71
- package/src/server/cleanup/revisions.ts +16 -5
- package/src/server/cleanup/uploads.ts +8 -2
- package/src/server/cleanup/worker.ts +5 -2
- package/src/server/collaboration/relay/connection.ts +4 -3
- package/src/server/collaboration/relay/documents.ts +13 -10
- package/src/server/collaboration/relay/hub.ts +97 -25
- package/src/server/collaboration/relay/log.ts +5 -2
- package/src/server/collaboration/service.ts +27 -31
- package/src/server/config/deployment.ts +24 -4
- package/src/server/config/public.ts +5 -4
- package/src/server/config/schema.ts +82 -16
- package/src/server/db/expressions.ts +15 -1
- package/src/server/db/migrate.ts +34 -116
- package/src/server/db/migrations/001_accounts.ts +79 -0
- package/src/server/db/migrations/002_workspaces.ts +48 -0
- package/src/server/db/migrations/003_storage.ts +44 -0
- package/src/server/db/migrations/004_documents.ts +193 -0
- package/src/server/db/migrations/005_sharing.ts +95 -0
- package/src/server/db/migrations/006_operations.ts +110 -0
- package/src/server/db/migrations/007_trash.ts +33 -0
- package/src/server/db/migrations/008_terms.ts +18 -0
- package/src/server/db/migrations/schema.ts +71 -0
- package/src/server/db/tables.ts +52 -3
- package/src/server/documents/access.ts +66 -55
- package/src/server/documents/errors.ts +7 -0
- package/src/server/documents/images.ts +2 -1
- package/src/server/documents/limits.ts +9 -9
- package/src/server/documents/purge.ts +75 -0
- package/src/server/documents/repository.ts +2 -0
- package/src/server/documents/routes.ts +26 -0
- package/src/server/documents/service.ts +18 -4
- package/src/server/documents/summary.ts +1 -0
- package/src/server/documents/trash.ts +203 -0
- package/src/server/documents/versions/checkpoint.ts +2 -1
- package/src/server/documents/versions/history.ts +11 -7
- package/src/server/documents/versions/service.ts +13 -4
- package/src/server/errors/index.ts +59 -16
- package/src/server/errors/posthog.ts +80 -0
- package/src/server/index.ts +46 -17
- package/src/server/internal/index.ts +3 -3
- package/src/server/internal/routes.ts +7 -10
- package/src/server/internal/schema.ts +1 -1
- package/src/server/internal/service.ts +17 -23
- package/src/server/invitations/budget.ts +66 -0
- package/src/server/invitations/index.ts +1 -0
- package/src/server/logging.ts +76 -0
- package/src/server/pictures/service.ts +2 -1
- package/src/server/policy/database.ts +39 -25
- package/src/server/policy/index.ts +2 -1
- package/src/server/policy/keys.ts +5 -2
- package/src/server/policy/policy.ts +1 -0
- package/src/server/policy/schema.ts +2 -2
- package/src/server/policy/service.ts +12 -9
- package/src/server/policy/static.ts +5 -5
- package/src/server/policy/workspace.ts +41 -0
- package/src/server/quota/reconcile.ts +2 -0
- package/src/server/quota/storage.ts +69 -31
- package/src/server/rate-limit/cleanup.ts +17 -5
- package/src/server/rate-limit/middleware.ts +2 -2
- package/src/server/reports/index.ts +8 -0
- package/src/server/reports/routes.ts +37 -0
- package/src/server/reports/service.ts +123 -0
- package/src/server/services/errors.ts +7 -0
- package/src/server/services/index.ts +8 -0
- package/src/server/{ai → services}/keys.ts +11 -11
- package/src/server/services/routes.ts +47 -0
- package/src/server/{ai/service.ts → services/tokens.ts} +23 -20
- package/src/server/sharing/capabilities/service.ts +68 -22
- package/src/server/sharing/grants/service.ts +11 -18
- package/src/server/sharing/http.ts +4 -0
- package/src/server/sharing/invitations/service.ts +21 -11
- package/src/server/sharing/policy.ts +9 -14
- package/src/server/sharing/routes.ts +0 -16
- package/src/server/sharing/service.ts +1 -17
- package/src/server/validation.ts +1 -0
- package/src/server/workspaces/index.ts +1 -0
- package/src/server/workspaces/members.ts +89 -38
- package/src/server/workspaces/repository.ts +2 -1
- package/src/server/workspaces/routes.ts +4 -0
- package/src/{ai-relay → services}/app.ts +48 -44
- package/src/{ai-relay → services}/config.ts +25 -19
- package/src/services/db/index.ts +10 -0
- package/src/services/db/migrate.ts +37 -0
- package/src/{ai-relay/db/migrations/001_usage.ts → services/db/migrations/001_baseline.ts} +18 -7
- package/src/services/db/schema.ts +22 -0
- package/src/services/index.ts +18 -0
- package/src/{ai-relay → services}/metering.ts +2 -2
- package/src/{ai-relay → services}/usage.ts +43 -19
- package/dist/bin/ai-relay.mjs.map +0 -1
- package/src/ai-relay/db/index.ts +0 -10
- package/src/ai-relay/db/migrate.ts +0 -32
- package/src/ai-relay/db/schema.ts +0 -20
- package/src/ai-relay/index.ts +0 -18
- package/src/contract/ai.ts +0 -150
- package/src/server/ai/errors.ts +0 -7
- package/src/server/ai/index.ts +0 -4
- package/src/server/ai/routes.ts +0 -43
- package/src/server/auth/workspace-access.ts +0 -23
- package/src/server/db/migrations/001_foundation.ts +0 -164
- package/src/server/db/migrations/002_upload_cleanup_claims.ts +0 -34
- package/src/server/db/migrations/003_document_cleanup_claims.ts +0 -23
- package/src/server/db/migrations/004_document_sharing.ts +0 -82
- package/src/server/db/migrations/005_document_collaboration_epoch.ts +0 -13
- package/src/server/db/migrations/006_invitation_continuation.ts +0 -27
- package/src/server/db/migrations/007_collaboration_state.ts +0 -25
- package/src/server/db/migrations/008_storage_reservations.ts +0 -37
- package/src/server/db/migrations/009_workspace_entitlements.ts +0 -22
- package/src/server/db/migrations/010_upload_finalization.ts +0 -22
- package/src/server/db/migrations/011_upload_finalization_lease.ts +0 -12
- package/src/server/db/migrations/012_transactional_email.ts +0 -48
- package/src/server/db/migrations/013_admin_enrollment.ts +0 -54
- package/src/server/db/migrations/014_enrollment_email_kinds.ts +0 -30
- package/src/server/db/migrations/015_cloud_rate_limit.ts +0 -22
- package/src/server/db/migrations/016_auth_schema.ts +0 -16
- package/src/server/db/migrations/017_authentication_email_kinds.ts +0 -32
- package/src/server/db/migrations/018_authentication_mfa.ts +0 -78
- package/src/server/db/migrations/019_better_auth_account_issuer.ts +0 -42
- package/src/server/db/migrations/020_workspace_invitations.ts +0 -57
- package/src/server/db/migrations/021_document_versions.ts +0 -66
- package/src/server/db/migrations/022_entitlement_external_version.ts +0 -17
- package/src/server/db/migrations/023_document_images.ts +0 -61
- package/src/server/db/migrations/024_account_activity.ts +0 -66
- package/src/server/db/migrations/025_table_names.ts +0 -58
- package/src/server/db/migrations/026_user_picture.ts +0 -30
- package/src/server/db/migrations/027_document_kind.ts +0 -19
- package/src/server/db/migrations/028_collaboration_updates.ts +0 -84
- package/src/server/db/migrations/helpers.ts +0 -78
- /package/dist/bin/{ai-relay.d.mts → services.d.mts} +0 -0
package/src/contract/sharing.ts
CHANGED
|
@@ -53,7 +53,10 @@ export function parseRequestSharedImageLinks(input: unknown): RequestSharedImage
|
|
|
53
53
|
|
|
54
54
|
export const resolvedDocumentShareSchema = v.object({
|
|
55
55
|
documentId: v.pipe(v.string(), v.uuid()),
|
|
56
|
+
/** What this person may do; a guest on an edit link may only view where guests may not edit. */
|
|
56
57
|
permission: documentPermissionSchema,
|
|
58
|
+
/** What the link lets someone signed in to the server do. */
|
|
59
|
+
linkPermission: documentPermissionSchema,
|
|
57
60
|
principal: collaborationPrincipalSchema,
|
|
58
61
|
roomEpoch: v.pipe(v.number(), v.integer(), v.minValue(0))
|
|
59
62
|
})
|
|
@@ -89,11 +92,6 @@ export const acceptedInvitationSchema = v.variant('kind', [
|
|
|
89
92
|
])
|
|
90
93
|
export type AcceptedInvitation = v.InferOutput<typeof acceptedInvitationSchema>
|
|
91
94
|
|
|
92
|
-
export const lookupCloudUserSchema = v.object({
|
|
93
|
-
email: v.pipe(v.string(), v.trim(), v.toLowerCase(), v.email())
|
|
94
|
-
})
|
|
95
|
-
export type LookupCloudUserInput = v.InferOutput<typeof lookupCloudUserSchema>
|
|
96
|
-
|
|
97
95
|
export const putDocumentGrantSchema = v.object({ permission: documentPermissionSchema })
|
|
98
96
|
export type PutDocumentGrantInput = v.InferOutput<typeof putDocumentGrantSchema>
|
|
99
97
|
|
|
@@ -162,10 +160,6 @@ export function parseCreateInvitationContinuation(
|
|
|
162
160
|
return v.parse(createInvitationContinuationSchema, input)
|
|
163
161
|
}
|
|
164
162
|
|
|
165
|
-
export function parseLookupCloudUser(input: unknown): LookupCloudUserInput {
|
|
166
|
-
return v.parse(lookupCloudUserSchema, input)
|
|
167
|
-
}
|
|
168
|
-
|
|
169
163
|
export function parseCreateDocumentShare(input: unknown): CreateDocumentShareInput {
|
|
170
164
|
return v.parse(createDocumentShareSchema, input)
|
|
171
165
|
}
|
package/src/email/render.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
AdminEnrollmentNotificationPayload,
|
|
6
6
|
AuthenticationEmailPayload,
|
|
7
7
|
DocumentInvitationEmailPayload,
|
|
8
|
+
DocumentReportPayload,
|
|
8
9
|
EmailChangeRequestedPayload,
|
|
9
10
|
EnrollmentEmailPayload,
|
|
10
11
|
NewSignInPayload,
|
|
@@ -74,6 +75,7 @@ type EnrollmentMessageKind = Exclude<
|
|
|
74
75
|
| 'email-change-requested'
|
|
75
76
|
| 'new-sign-in'
|
|
76
77
|
| 'two-step-changed'
|
|
78
|
+
| 'document-report'
|
|
77
79
|
>
|
|
78
80
|
|
|
79
81
|
type EnrollmentCopy = {
|
|
@@ -141,6 +143,29 @@ async function renderAdminNotification(payload: AdminEnrollmentNotificationPaylo
|
|
|
141
143
|
)
|
|
142
144
|
}
|
|
143
145
|
|
|
146
|
+
const REPORT_REASON_LABELS: Record<string, string> = {
|
|
147
|
+
'spam-phishing': 'spam or phishing',
|
|
148
|
+
illegal: 'illegal content',
|
|
149
|
+
copyright: 'copyright',
|
|
150
|
+
harassment: 'harassment',
|
|
151
|
+
other: 'something else'
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function renderDocumentReport(payload: DocumentReportPayload) {
|
|
155
|
+
const reason = REPORT_REASON_LABELS[payload.reason] ?? payload.reason
|
|
156
|
+
return rendered(
|
|
157
|
+
EnrollmentEmail,
|
|
158
|
+
{
|
|
159
|
+
heading: 'A shared document was reported',
|
|
160
|
+
preview: `“${payload.documentName}” was reported for ${reason}.`,
|
|
161
|
+
message: `Someone who opened “${payload.documentName}” from a share link reported it for ${reason}: ${payload.description}`,
|
|
162
|
+
actionLabel: 'Review report',
|
|
163
|
+
actionURL: payload.actionURL
|
|
164
|
+
},
|
|
165
|
+
'A shared OpenPencil Cloud document was reported'
|
|
166
|
+
)
|
|
167
|
+
}
|
|
168
|
+
|
|
144
169
|
async function renderAuthentication(
|
|
145
170
|
kind: 'email-verification' | 'password-reset' | 'password-changed',
|
|
146
171
|
payload: AuthenticationEmailPayload
|
|
@@ -272,5 +297,6 @@ export async function renderTransactionalEmail(
|
|
|
272
297
|
if (content.kind === 'email-change-requested') return renderEmailChangeRequested(content.payload)
|
|
273
298
|
if (content.kind === 'new-sign-in') return renderNewSignIn(content.payload)
|
|
274
299
|
if (content.kind === 'two-step-changed') return renderTwoStepChanged(content.payload)
|
|
300
|
+
if (content.kind === 'document-report') return renderDocumentReport(content.payload)
|
|
275
301
|
return renderEnrollment(content.kind, content.payload)
|
|
276
302
|
}
|
package/src/email/schema.ts
CHANGED
|
@@ -15,6 +15,7 @@ export type TransactionalEmailKind =
|
|
|
15
15
|
| 'email-change-requested'
|
|
16
16
|
| 'new-sign-in'
|
|
17
17
|
| 'two-step-changed'
|
|
18
|
+
| 'document-report'
|
|
18
19
|
|
|
19
20
|
const documentInvitationEmailPayloadSchema = v.object({
|
|
20
21
|
inviterName: v.string(),
|
|
@@ -44,6 +45,13 @@ const adminEnrollmentNotificationPayloadSchema = v.object({
|
|
|
44
45
|
actionURL: v.string()
|
|
45
46
|
})
|
|
46
47
|
|
|
48
|
+
const documentReportPayloadSchema = v.object({
|
|
49
|
+
documentName: v.string(),
|
|
50
|
+
reason: v.string(),
|
|
51
|
+
description: v.string(),
|
|
52
|
+
actionURL: v.string()
|
|
53
|
+
})
|
|
54
|
+
|
|
47
55
|
const authenticationEmailPayloadSchema = v.object({
|
|
48
56
|
name: v.string(),
|
|
49
57
|
actionURL: v.optional(v.string()),
|
|
@@ -102,7 +110,8 @@ export const transactionalEmailContentSchema = v.variant('kind', [
|
|
|
102
110
|
content('password-changed', authenticationEmailPayloadSchema),
|
|
103
111
|
content('email-change-requested', emailChangeRequestedPayloadSchema),
|
|
104
112
|
content('new-sign-in', newSignInPayloadSchema),
|
|
105
|
-
content('two-step-changed', twoStepChangedPayloadSchema)
|
|
113
|
+
content('two-step-changed', twoStepChangedPayloadSchema),
|
|
114
|
+
content('document-report', documentReportPayloadSchema)
|
|
106
115
|
])
|
|
107
116
|
|
|
108
117
|
/** A transactional email's kind with the payload that kind renders. */
|
|
@@ -142,3 +151,4 @@ export type RenderedTransactionalEmail = {
|
|
|
142
151
|
html: string
|
|
143
152
|
text: string
|
|
144
153
|
}
|
|
154
|
+
export type DocumentReportPayload = v.InferOutput<typeof documentReportPayloadSchema>
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
Container,
|
|
5
5
|
Head,
|
|
6
6
|
Heading,
|
|
7
|
-
// eslint-disable-next-line open-pencil/no-mixed-case-acronym-identifiers -- Upstream export spelling.
|
|
7
|
+
// eslint-disable-next-line @open-pencil/structure/no-mixed-case-acronym-identifiers -- Upstream export spelling.
|
|
8
8
|
Html as HTML,
|
|
9
9
|
Img,
|
|
10
10
|
Link,
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createCloudErrorReporter } from '#cloud/runtime/posthog/errors'
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
createLoggingErrorReporter,
|
|
4
|
+
loadServicesSigningKey,
|
|
4
5
|
parseCloudDeploymentTOML,
|
|
5
|
-
type
|
|
6
|
+
type ServicesSigningKey,
|
|
6
7
|
type CloudEnvironment,
|
|
7
8
|
type CloudErrorReporter,
|
|
8
9
|
type CloudServerConfig
|
|
9
10
|
} from '#cloud/server'
|
|
10
11
|
|
|
12
|
+
import { writeWorkersLogLine } from './logging'
|
|
11
13
|
import type { CollaborationRelayRPC } from './relay'
|
|
12
14
|
|
|
13
15
|
/** The bindings `deploy/cloudflare/wrangler.jsonc` gives the Worker and its relay objects. */
|
|
@@ -27,9 +29,9 @@ export type CloudflareCloudEnvironment = CloudflareCloudBindings & Record<string
|
|
|
27
29
|
|
|
28
30
|
export type PreparedCloudflareCloud = {
|
|
29
31
|
config: CloudServerConfig
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
reportError: CloudErrorReporter
|
|
32
|
+
servicesSigningKey: ServicesSigningKey | undefined
|
|
33
|
+
/** Logs errors, and sends them to error tracking when the deployment configures it. */
|
|
34
|
+
reportError: CloudErrorReporter
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
/** The Worker's string variables and secrets, with `DATABASE_URL` from Hyperdrive. */
|
|
@@ -43,9 +45,12 @@ function configEnvironment(env: CloudflareCloudEnvironment): CloudEnvironment {
|
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
|
-
* Reads the deployment TOML once per isolate: its config and
|
|
48
|
+
* Reads the deployment TOML once per isolate: its config and services signing key stay the same for the
|
|
47
49
|
* Worker's lifetime. A failure is not kept, so the next request tries again.
|
|
48
50
|
*/
|
|
51
|
+
/** Logs errors from before a config parsed, which has no error tracking to send them to. */
|
|
52
|
+
const logOnly = createLoggingErrorReporter(writeWorkersLogLine)
|
|
53
|
+
|
|
49
54
|
export function cloudflareCloudSetup(source: string) {
|
|
50
55
|
let prepared: Promise<PreparedCloudflareCloud> | null = null
|
|
51
56
|
/** Set once an attempt's config parses, so its later setup steps that fail can be reported. */
|
|
@@ -55,8 +60,11 @@ export function cloudflareCloudSetup(source: string) {
|
|
|
55
60
|
// An attempt whose config fails to parse has no project to report to, not an earlier one's.
|
|
56
61
|
reportError = undefined
|
|
57
62
|
const config = parseCloudDeploymentTOML(source, configEnvironment(env))
|
|
58
|
-
reportError =
|
|
59
|
-
|
|
63
|
+
reportError = createLoggingErrorReporter(
|
|
64
|
+
writeWorkersLogLine,
|
|
65
|
+
createCloudErrorReporter(config, 'cloudflare')
|
|
66
|
+
)
|
|
67
|
+
return { config, servicesSigningKey: await loadServicesSigningKey(config), reportError }
|
|
60
68
|
})().catch((error: unknown) => {
|
|
61
69
|
prepared = null
|
|
62
70
|
throw error
|
|
@@ -65,7 +73,10 @@ export function cloudflareCloudSetup(source: string) {
|
|
|
65
73
|
}
|
|
66
74
|
return {
|
|
67
75
|
prepare,
|
|
68
|
-
/**
|
|
69
|
-
|
|
76
|
+
/**
|
|
77
|
+
* The reporter of the latest attempt once its config parsed, which also sends to error tracking
|
|
78
|
+
* when the config has it; before that, one that only logs.
|
|
79
|
+
*/
|
|
80
|
+
reporter: () => reportError ?? logOnly
|
|
70
81
|
}
|
|
71
82
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { createCloudflareEmailTransport, type CloudflareEmailBinding } from './email'
|
|
2
2
|
export type { CloudflareCloudBindings, CloudflareCloudEnvironment } from './environment'
|
|
3
|
-
export { createCloudflareCloud } from './worker'
|
|
3
|
+
export { createCloudflareCloud, type CloudflareCloudOptions } from './worker'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CloudLogWriter, ForwardedRequestId } from '#cloud/server'
|
|
2
|
+
|
|
3
|
+
/** Workers Logs indexes the keys of an object passed to `console`, so the line goes as one. */
|
|
4
|
+
export const writeWorkersLogLine: CloudLogWriter = (line) => {
|
|
5
|
+
console[line.level](line)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** Cloudflare's ray ID, such as `8f1e2d3c4b5a6978-FRA`. */
|
|
9
|
+
const RAY_ID = /^[0-9a-f]{16}(-[A-Z]{3})?$/
|
|
10
|
+
|
|
11
|
+
/** Names a request by the ray ID Cloudflare's edge set on it, which a client cannot choose. */
|
|
12
|
+
export const cloudflareRayId: ForwardedRequestId = (headers) => {
|
|
13
|
+
const ray = headers.get('cf-ray')
|
|
14
|
+
return ray && RAY_ID.test(ray) ? ray : undefined
|
|
15
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { cloudflareRayId } from './logging'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The Worker variable that takes a deployment off the air, as the Deploy Cloud workflow's
|
|
5
|
+
* `maintenance` input sets it: every request answers 503 and scheduled cleanup does nothing, while
|
|
6
|
+
* the deploy itself restarts the rooms' objects and closes their sockets. A database restore runs
|
|
7
|
+
* under it (deploy/openpencil/README.md).
|
|
8
|
+
*/
|
|
9
|
+
export const MAINTENANCE_VARIABLE = 'OPENPENCIL_CLOUD_MAINTENANCE'
|
|
10
|
+
|
|
11
|
+
export function inMaintenance(env: Record<string, unknown>): boolean {
|
|
12
|
+
return env[MAINTENANCE_VARIABLE] === 'on'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** How a relay socket open when maintenance began is closed: the service restarts. */
|
|
16
|
+
export const MAINTENANCE_CLOSE_CODE = 1012
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* What every request gets meanwhile; clients retry, and nothing reaches the database. It names the
|
|
20
|
+
* request as other responses do, by its ray ID.
|
|
21
|
+
*/
|
|
22
|
+
export function maintenanceResponse(request: Request): Response {
|
|
23
|
+
return new Response('OpenPencil Cloud is down for maintenance.', {
|
|
24
|
+
status: 503,
|
|
25
|
+
headers: {
|
|
26
|
+
'Content-Type': 'text/plain; charset=utf-8',
|
|
27
|
+
'Retry-After': '300',
|
|
28
|
+
'X-Request-Id': cloudflareRayId(request.headers) ?? crypto.randomUUID()
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RELAY_DOCUMENT_PARAM } from '#cloud/contract'
|
|
1
|
+
import { RELAY_DOCUMENT_PARAM, RELAY_HEARTBEAT } from '#cloud/contract'
|
|
2
2
|
import { createPostgresCloudDatabase } from '#cloud/runtime/postgres/database'
|
|
3
3
|
import { createS3ObjectStore } from '#cloud/runtime/s3/objects'
|
|
4
4
|
import {
|
|
@@ -14,36 +14,55 @@ import type { Context } from 'hono'
|
|
|
14
14
|
import * as v from 'valibot'
|
|
15
15
|
|
|
16
16
|
import type { CloudflareCloudEnvironment, PreparedCloudflareCloud } from '../environment'
|
|
17
|
+
import { inMaintenance, MAINTENANCE_CLOSE_CODE, maintenanceResponse } from '../maintenance'
|
|
17
18
|
import { createRelaySockets } from './sockets'
|
|
18
19
|
|
|
19
20
|
/** What the Worker calls on a document's relay object. */
|
|
20
21
|
export interface CollaborationRelayRPC extends DurableObject<CloudflareCloudEnvironment> {
|
|
21
22
|
/** Ends the document's live rooms after a restore, without saving them. */
|
|
22
23
|
startOver(documentId: string): Promise<void>
|
|
24
|
+
/** Ends a taken-down document's live rooms, saving them. */
|
|
25
|
+
closeDocument(documentId: string): Promise<void>
|
|
23
26
|
/** Tells the document's live rooms its version history changed. */
|
|
24
27
|
announceVersions(documentId: string): Promise<void>
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
const documentIdSchema = v.pipe(v.string(), v.uuid())
|
|
28
31
|
|
|
29
|
-
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
/**
|
|
33
|
+
* The most a room's document may hold on Cloudflare. A Durable Object has 128 MB of memory for
|
|
34
|
+
* the document, the update joining it, and the snapshot written from it, so a room past this is
|
|
35
|
+
* turned away and its editors save without one.
|
|
36
|
+
*/
|
|
37
|
+
export const CLOUDFLARE_MAXIMUM_ROOM_BYTES = 32 * 1024 * 1024
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The document's relay object. With a jurisdiction, objects are created and keep their storage
|
|
41
|
+
* only inside it; an object named outside one is a different object, so a deployment never
|
|
42
|
+
* changes its jurisdiction while rooms are live.
|
|
43
|
+
*/
|
|
44
|
+
export function relayFor(
|
|
45
|
+
env: CloudflareCloudEnvironment,
|
|
46
|
+
documentId: string,
|
|
47
|
+
jurisdiction?: DurableObjectJurisdiction
|
|
48
|
+
) {
|
|
49
|
+
const namespace = jurisdiction ? env.RELAY.jurisdiction(jurisdiction) : env.RELAY
|
|
50
|
+
return namespace.get(namespace.idFromName(documentId))
|
|
32
51
|
}
|
|
33
52
|
|
|
34
53
|
/**
|
|
35
54
|
* Sends a relay socket to its document's relay object. The ticket's URL names the document; the
|
|
36
55
|
* object refuses tickets for any other.
|
|
37
56
|
*/
|
|
38
|
-
export
|
|
39
|
-
c: Context<{ Bindings: CloudflareCloudEnvironment }>
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
|
|
57
|
+
export function relayRoute(jurisdiction?: DurableObjectJurisdiction) {
|
|
58
|
+
return async (c: Context<{ Bindings: CloudflareCloudEnvironment }>): Promise<Response> => {
|
|
59
|
+
if (c.req.header('Upgrade')?.toLowerCase() !== 'websocket') {
|
|
60
|
+
return c.text('Expected a WebSocket upgrade', 426)
|
|
61
|
+
}
|
|
62
|
+
const documentId = c.req.query(RELAY_DOCUMENT_PARAM)
|
|
63
|
+
if (!v.is(documentIdSchema, documentId)) return c.text('Missing document', 400)
|
|
64
|
+
return relayFor(c.env, documentId, jurisdiction).fetch(c.req.raw)
|
|
43
65
|
}
|
|
44
|
-
const documentId = c.req.query(RELAY_DOCUMENT_PARAM)
|
|
45
|
-
if (!v.is(documentIdSchema, documentId)) return c.text('Missing document', 400)
|
|
46
|
-
return relayFor(c.env, documentId).fetch(c.req.raw)
|
|
47
66
|
}
|
|
48
67
|
|
|
49
68
|
/** The relay over the deployment's PostgreSQL and object store. */
|
|
@@ -52,12 +71,17 @@ function configuredRelay(
|
|
|
52
71
|
documentId: string,
|
|
53
72
|
onError: (message: string, error: unknown) => void
|
|
54
73
|
): CollaborationRelay {
|
|
55
|
-
|
|
74
|
+
// Hyperdrive keeps no session settings and ends queries past its own limit.
|
|
75
|
+
const database = createPostgresCloudDatabase({
|
|
76
|
+
connectionString: config.databaseURL,
|
|
77
|
+
statementTimeoutMs: null
|
|
78
|
+
})
|
|
56
79
|
return createCollaborationRelay({
|
|
57
80
|
authSecret: config.authSecret,
|
|
58
81
|
documentId,
|
|
59
82
|
store: createCollaborationStateStore(database, createS3ObjectStore(config)),
|
|
60
83
|
maximumMessageBytes: config.technicalLimits.maximumCollaborationMessageBytes,
|
|
84
|
+
maximumRoomBytes: CLOUDFLARE_MAXIMUM_ROOM_BYTES,
|
|
61
85
|
maximumConnectionsPerRoom: config.technicalLimits.maximumConnectionsPerRoom,
|
|
62
86
|
onError,
|
|
63
87
|
...relayDocumentLookups(
|
|
@@ -80,6 +104,14 @@ export function createCloudflareRelayObject(
|
|
|
80
104
|
extends DurableObject<CloudflareCloudEnvironment>
|
|
81
105
|
implements CollaborationRelayRPC
|
|
82
106
|
{
|
|
107
|
+
constructor(ctx: DurableObjectState, env: CloudflareCloudEnvironment) {
|
|
108
|
+
super(ctx, env)
|
|
109
|
+
// Peers check the relay still hears them; the runtime answers without waking the object.
|
|
110
|
+
ctx.setWebSocketAutoResponse(
|
|
111
|
+
new WebSocketRequestResponsePair(RELAY_HEARTBEAT.ping, RELAY_HEARTBEAT.pong)
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
|
|
83
115
|
readonly #sockets = createRelaySockets({
|
|
84
116
|
sockets: () => this.ctx.getWebSockets(),
|
|
85
117
|
createRelay: async (documentId) => {
|
|
@@ -92,8 +124,9 @@ export function createCloudflareRelayObject(
|
|
|
92
124
|
}
|
|
93
125
|
})
|
|
94
126
|
|
|
95
|
-
/** Accepts a socket that `
|
|
127
|
+
/** Accepts a socket that `relayRoute` sent here. */
|
|
96
128
|
override async fetch(request: Request): Promise<Response> {
|
|
129
|
+
if (inMaintenance(this.env)) return maintenanceResponse(request)
|
|
97
130
|
const documentId = new URL(request.url).searchParams.get(RELAY_DOCUMENT_PARAM)
|
|
98
131
|
if (!v.is(documentIdSchema, documentId)) return new Response(null, { status: 400 })
|
|
99
132
|
const relay = await this.#sockets.open(documentId)
|
|
@@ -104,14 +137,24 @@ export function createCloudflareRelayObject(
|
|
|
104
137
|
}
|
|
105
138
|
|
|
106
139
|
override async webSocketMessage(socket: WebSocket, message: string | ArrayBuffer) {
|
|
140
|
+
// A socket from before maintenance began reaches the room no more: its editor reconnects
|
|
141
|
+
// once maintenance ends, and nothing it sends meanwhile is written.
|
|
142
|
+
if (inMaintenance(this.env)) {
|
|
143
|
+
socket.close(MAINTENANCE_CLOSE_CODE, 'Down for maintenance')
|
|
144
|
+
return
|
|
145
|
+
}
|
|
107
146
|
await this.#sockets.message(socket, message)
|
|
108
147
|
}
|
|
109
148
|
|
|
149
|
+
// Under maintenance a closing socket leaves its room as it is: closing the room would save
|
|
150
|
+
// its state into a database that may be mid-restore.
|
|
110
151
|
override async webSocketClose(socket: WebSocket) {
|
|
152
|
+
if (inMaintenance(this.env)) return
|
|
111
153
|
await this.#sockets.closed(socket)
|
|
112
154
|
}
|
|
113
155
|
|
|
114
156
|
override async webSocketError(socket: WebSocket) {
|
|
157
|
+
if (inMaintenance(this.env)) return
|
|
115
158
|
await this.#sockets.closed(socket)
|
|
116
159
|
}
|
|
117
160
|
|
|
@@ -120,6 +163,11 @@ export function createCloudflareRelayObject(
|
|
|
120
163
|
;(await this.#sockets.open(documentId)).startOver(documentId)
|
|
121
164
|
}
|
|
122
165
|
|
|
166
|
+
async closeDocument(documentId: string) {
|
|
167
|
+
if (!this.#sockets.active) return
|
|
168
|
+
;(await this.#sockets.open(documentId)).closeDocument(documentId)
|
|
169
|
+
}
|
|
170
|
+
|
|
123
171
|
async announceVersions(documentId: string) {
|
|
124
172
|
if (!this.#sockets.active) return
|
|
125
173
|
;(await this.#sockets.open(documentId)).announceVersions(documentId)
|
|
@@ -5,6 +5,7 @@ import { createCloudServer } from '#cloud/runtime/site/server'
|
|
|
5
5
|
import {
|
|
6
6
|
cleanupPassOptions,
|
|
7
7
|
cloudErrorHandler,
|
|
8
|
+
cloudRequestId,
|
|
8
9
|
createCleanupServices,
|
|
9
10
|
createCloudApp,
|
|
10
11
|
createCloudAuthenticationRuntime,
|
|
@@ -25,7 +26,9 @@ import {
|
|
|
25
26
|
type CloudflareCloudEnvironment,
|
|
26
27
|
type PreparedCloudflareCloud
|
|
27
28
|
} from './environment'
|
|
28
|
-
import {
|
|
29
|
+
import { cloudflareRayId } from './logging'
|
|
30
|
+
import { inMaintenance, maintenanceResponse } from './maintenance'
|
|
31
|
+
import { createCloudflareRelayObject, relayFor, relayRoute } from './relay'
|
|
29
32
|
import { assetSiteFiles } from './site'
|
|
30
33
|
|
|
31
34
|
function emailTransport({ config }: PreparedCloudflareCloud, env: CloudflareCloudEnvironment) {
|
|
@@ -60,7 +63,11 @@ function cloudServices(
|
|
|
60
63
|
const reporter = keptAlive(prepared.reportError, context)
|
|
61
64
|
const reportError = (message: string, error: unknown, source: CloudErrorSource) =>
|
|
62
65
|
reportCloudError(reporter, message, error, { source })
|
|
63
|
-
|
|
66
|
+
// Hyperdrive keeps no session settings and ends queries past its own limit.
|
|
67
|
+
const database = createPostgresCloudDatabase({
|
|
68
|
+
connectionString: config.databaseURL,
|
|
69
|
+
statementTimeoutMs: null
|
|
70
|
+
})
|
|
64
71
|
const objects = createS3ObjectStore(config)
|
|
65
72
|
const transport = emailTransport(prepared, env)
|
|
66
73
|
const queued = createTransactionalEmailService(database, {
|
|
@@ -81,7 +88,7 @@ function cloudServices(
|
|
|
81
88
|
const background: Promise<unknown>[] = []
|
|
82
89
|
const runInBackground = (task: Promise<unknown>) => {
|
|
83
90
|
background.push(
|
|
84
|
-
task.catch((error: unknown) => reportError('Background work failed
|
|
91
|
+
task.catch((error: unknown) => reportError('Background work failed', error, 'background'))
|
|
85
92
|
)
|
|
86
93
|
}
|
|
87
94
|
const deliver = () =>
|
|
@@ -104,7 +111,7 @@ function cloudServices(
|
|
|
104
111
|
context.waitUntil(
|
|
105
112
|
Promise.allSettled(background)
|
|
106
113
|
.then(() => (enqueued && transport ? deliver() : undefined))
|
|
107
|
-
.catch((error: unknown) => reportError('Sending email failed
|
|
114
|
+
.catch((error: unknown) => reportError('Sending email failed', error, 'email'))
|
|
108
115
|
.then(() => database.destroy())
|
|
109
116
|
)
|
|
110
117
|
}
|
|
@@ -123,7 +130,7 @@ async function runScheduled(
|
|
|
123
130
|
if (config.cleanupEnabled) {
|
|
124
131
|
const policy = createConfiguredCloudPolicy(config, database)
|
|
125
132
|
await runCleanup(
|
|
126
|
-
createCleanupServices(config, database, objects, policy),
|
|
133
|
+
createCleanupServices(config, database, objects, policy, services.reporter),
|
|
127
134
|
cleanupPassOptions(config)
|
|
128
135
|
)
|
|
129
136
|
}
|
|
@@ -138,13 +145,27 @@ async function runScheduled(
|
|
|
138
145
|
* API, the editor, and the portal per request, a Durable Object per document runs its collaboration rooms, and a
|
|
139
146
|
* Cron Trigger runs cleanup and retries email.
|
|
140
147
|
*/
|
|
141
|
-
export
|
|
148
|
+
export type CloudflareCloudOptions = {
|
|
149
|
+
/**
|
|
150
|
+
* Where collaboration rooms' Durable Objects run and keep their storage, such as `eu` for a
|
|
151
|
+
* deployment whose data stays in the EU; by default, near whoever opens the room first.
|
|
152
|
+
*/
|
|
153
|
+
relayJurisdiction?: DurableObjectJurisdiction
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function createCloudflareCloud(
|
|
157
|
+
configSource: string,
|
|
158
|
+
{ relayJurisdiction }: CloudflareCloudOptions = {}
|
|
159
|
+
) {
|
|
142
160
|
const { prepare, reporter } = cloudflareCloudSetup(configSource)
|
|
161
|
+
const relay = (env: CloudflareCloudEnvironment, documentId: string) =>
|
|
162
|
+
relayFor(env, documentId, relayJurisdiction)
|
|
143
163
|
|
|
144
164
|
const router = new Hono<{ Bindings: CloudflareCloudEnvironment }>()
|
|
145
165
|
// Setup, relay routing, and the runtime around the app; the app reports its own errors.
|
|
146
166
|
.onError((error, c) => cloudErrorHandler(keptAlive(reporter(), c.executionCtx))(error, c))
|
|
147
|
-
.
|
|
167
|
+
.use('*', cloudRequestId(cloudflareRayId))
|
|
168
|
+
.get(RELAY_PATH, relayRoute(relayJurisdiction))
|
|
148
169
|
.all('*', async (c) => {
|
|
149
170
|
const prepared = await prepare(c.env)
|
|
150
171
|
const services = cloudServices(prepared, c.env, c.executionCtx)
|
|
@@ -162,13 +183,16 @@ export function createCloudflareCloud(configSource: string) {
|
|
|
162
183
|
invitationOutbox: transport ? createInvitationOutbox(email) : undefined,
|
|
163
184
|
transactionalEmail: email,
|
|
164
185
|
enrollment,
|
|
165
|
-
|
|
186
|
+
servicesSigningKey: prepared.servicesSigningKey,
|
|
166
187
|
relayURL: config.relayURL ?? defaultRelayURL(config.publicURL),
|
|
167
188
|
onDocumentRestored: (documentId) =>
|
|
168
|
-
runInBackground(
|
|
189
|
+
runInBackground(relay(c.env, documentId).startOver(documentId)),
|
|
190
|
+
onDocumentTakenDown: (documentId) =>
|
|
191
|
+
runInBackground(relay(c.env, documentId).closeDocument(documentId)),
|
|
169
192
|
onDocumentVersionsChanged: (documentId) =>
|
|
170
|
-
runInBackground(
|
|
171
|
-
reportError: services.reporter
|
|
193
|
+
runInBackground(relay(c.env, documentId).announceVersions(documentId)),
|
|
194
|
+
reportError: services.reporter,
|
|
195
|
+
forwardedRequestId: cloudflareRayId
|
|
172
196
|
})
|
|
173
197
|
return await createCloudServer(app, {
|
|
174
198
|
site: assetSiteFiles(c.env.ASSETS),
|
|
@@ -181,13 +205,15 @@ export function createCloudflareCloud(configSource: string) {
|
|
|
181
205
|
})
|
|
182
206
|
|
|
183
207
|
const worker: ExportedHandler<CloudflareCloudEnvironment> = {
|
|
184
|
-
fetch: (request, env, context) =>
|
|
208
|
+
fetch: (request, env, context) =>
|
|
209
|
+
inMaintenance(env) ? maintenanceResponse(request) : router.fetch(request, env, context),
|
|
185
210
|
|
|
186
211
|
async scheduled(_controller, env, context) {
|
|
212
|
+
if (inMaintenance(env)) return
|
|
187
213
|
try {
|
|
188
214
|
await runScheduled(await prepare(env), env, context)
|
|
189
215
|
} catch (error) {
|
|
190
|
-
await reportCloudError(reporter(), 'Scheduled run failed
|
|
216
|
+
await reportCloudError(reporter(), 'Scheduled run failed', error, { source: 'scheduled' })
|
|
191
217
|
throw error
|
|
192
218
|
}
|
|
193
219
|
}
|
|
@@ -3,7 +3,7 @@ import { createS3ObjectStore } from '#cloud/runtime/s3/objects'
|
|
|
3
3
|
import {
|
|
4
4
|
createCloudAuthenticationRuntime,
|
|
5
5
|
createCloudApp,
|
|
6
|
-
|
|
6
|
+
loadServicesSigningKey,
|
|
7
7
|
type CloudApp,
|
|
8
8
|
type CloudEnvironment,
|
|
9
9
|
type CloudServerConfig,
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
|
|
13
13
|
import { loadNodeCloudServerConfig } from './config'
|
|
14
14
|
import { createNodeTransactionalEmailRuntime } from './email/runtime'
|
|
15
|
+
import { proxyRequestId } from './request-id'
|
|
15
16
|
|
|
16
17
|
export type NodeCloudApplicationOptions = {
|
|
17
18
|
environment?: CloudEnvironment
|
|
@@ -29,7 +30,7 @@ export async function createNodeCloudApplication(
|
|
|
29
30
|
}> {
|
|
30
31
|
const environment = options.environment ?? process.env
|
|
31
32
|
const config = await loadNodeCloudServerConfig(environment)
|
|
32
|
-
const
|
|
33
|
+
const servicesSigningKey = await loadServicesSigningKey(config)
|
|
33
34
|
const database = createPostgresCloudDatabase({
|
|
34
35
|
connectionString: options.databaseURL ?? config.databaseURL
|
|
35
36
|
})
|
|
@@ -44,7 +45,8 @@ export async function createNodeCloudApplication(
|
|
|
44
45
|
invitationOutbox,
|
|
45
46
|
transactionalEmail: email,
|
|
46
47
|
enrollment,
|
|
47
|
-
|
|
48
|
+
servicesSigningKey,
|
|
49
|
+
forwardedRequestId: proxyRequestId
|
|
48
50
|
})
|
|
49
51
|
return { app, config, database, objects, email }
|
|
50
52
|
}
|
|
@@ -7,12 +7,23 @@ import {
|
|
|
7
7
|
|
|
8
8
|
import { loadNodeCloudServerConfig } from './config'
|
|
9
9
|
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* The deployment's database, migrated to this version before anything uses it. Migrations run
|
|
12
|
+
* on a connection of their own without the statement timeout, since one may rewrite a large table.
|
|
13
|
+
*/
|
|
11
14
|
export async function migratedNodeCloudDatabase(config: CloudServerConfig) {
|
|
15
|
+
const migrating = createPostgresCloudDatabase({
|
|
16
|
+
connectionString: config.databaseURL,
|
|
17
|
+
statementTimeoutMs: null
|
|
18
|
+
})
|
|
19
|
+
try {
|
|
20
|
+
const auth = createBetterAuthAdapter(config, migrating)
|
|
21
|
+
await migrateCloudDatabase(migrating, { run: auth.migrate, schemaVersion: auth.schemaVersion })
|
|
22
|
+
} finally {
|
|
23
|
+
await migrating.destroy()
|
|
24
|
+
}
|
|
12
25
|
const database = createPostgresCloudDatabase({ connectionString: config.databaseURL })
|
|
13
|
-
|
|
14
|
-
await migrateCloudDatabase(database, { run: auth.migrate, schemaVersion: auth.schemaVersion })
|
|
15
|
-
return { database, auth }
|
|
26
|
+
return { database, auth: createBetterAuthAdapter(config, database) }
|
|
16
27
|
}
|
|
17
28
|
|
|
18
29
|
export async function createMigratedNodeCloudDatabase(
|
|
@@ -1,21 +1,34 @@
|
|
|
1
1
|
import { createPostgresCloudDatabase } from '#cloud/runtime/postgres/database'
|
|
2
|
+
import { createCloudErrorReporter } from '#cloud/runtime/posthog/errors'
|
|
2
3
|
import { createS3ObjectStore } from '#cloud/runtime/s3/objects'
|
|
3
4
|
import {
|
|
4
5
|
cleanupPassOptions,
|
|
5
6
|
createCleanupServices,
|
|
6
7
|
createConfiguredCloudPolicy,
|
|
7
|
-
|
|
8
|
+
createLoggingErrorReporter,
|
|
9
|
+
runCleanup,
|
|
10
|
+
writeJSONLine
|
|
8
11
|
} from '#cloud/server'
|
|
9
12
|
|
|
10
13
|
import { loadNodeCloudServerConfig } from './config'
|
|
11
14
|
|
|
12
15
|
const config = await loadNodeCloudServerConfig(process.env)
|
|
13
|
-
|
|
16
|
+
// A sweep may take longer than a request should.
|
|
17
|
+
const database = createPostgresCloudDatabase({
|
|
18
|
+
connectionString: config.databaseURL,
|
|
19
|
+
statementTimeoutMs: null
|
|
20
|
+
})
|
|
14
21
|
const objects = createS3ObjectStore(config)
|
|
15
22
|
try {
|
|
16
23
|
const policy = createConfiguredCloudPolicy(config, database)
|
|
17
24
|
const result = await runCleanup(
|
|
18
|
-
createCleanupServices(
|
|
25
|
+
createCleanupServices(
|
|
26
|
+
config,
|
|
27
|
+
database,
|
|
28
|
+
objects,
|
|
29
|
+
policy,
|
|
30
|
+
createLoggingErrorReporter(writeJSONLine, createCloudErrorReporter(config, 'node'))
|
|
31
|
+
),
|
|
19
32
|
cleanupPassOptions(config)
|
|
20
33
|
)
|
|
21
34
|
console.log(JSON.stringify(result))
|