@open-pencil/cloud 0.0.0-stage → 0.17.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/LICENSE-MIT +21 -0
- package/NOTICE +7 -0
- package/README.md +37 -2
- package/dist/bin/ai-relay.d.mts +1 -0
- package/dist/bin/ai-relay.mjs +31 -0
- package/dist/bin/ai-relay.mjs.map +1 -0
- package/dist/bin/server.d.mts +1 -0
- package/dist/bin/server.mjs +29 -0
- package/dist/bin/server.mjs.map +1 -0
- package/dist/client.d.ts +1520 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +1917 -0
- package/dist/client.js.map +1 -0
- package/dist/contract.d.ts +2 -0
- package/dist/contract.js +2 -0
- package/dist/contract2.js +1453 -0
- package/dist/contract2.js.map +1 -0
- package/dist/email.d.ts +169 -0
- package/dist/email.d.ts.map +1 -0
- package/dist/email.js +670 -0
- package/dist/email.js.map +1 -0
- package/dist/index.d.ts +1755 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/listen.mjs +1881 -0
- package/dist/listen.mjs.map +1 -0
- package/dist/runtime-node.d.mts +10040 -0
- package/dist/runtime-node.d.mts.map +1 -0
- package/dist/runtime-node.mjs +32 -0
- package/dist/runtime-node.mjs.map +1 -0
- package/dist/server.d.ts +12792 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +8475 -0
- package/dist/server.js.map +1 -0
- package/dist/server.mjs +8324 -0
- package/dist/server.mjs.map +1 -0
- package/dist/server2.mjs +505 -0
- package/dist/server2.mjs.map +1 -0
- package/package.json +124 -4
- package/src/admin/api/routes.ts +223 -0
- package/src/admin/api/security.ts +12 -0
- package/src/admin/audit/service.ts +138 -0
- package/src/admin/email/service.ts +140 -0
- package/src/admin/enrollment/email.ts +77 -0
- package/src/admin/enrollment/service.ts +308 -0
- package/src/admin/errors.ts +20 -0
- package/src/admin/index.ts +19 -0
- package/src/admin/list.ts +61 -0
- package/src/admin/operations/service.ts +70 -0
- package/src/admin/schema.ts +28 -0
- package/src/admin/users/service.ts +369 -0
- package/src/ai-relay/app.ts +251 -0
- package/src/ai-relay/config.ts +120 -0
- package/src/ai-relay/db/index.ts +10 -0
- package/src/ai-relay/db/migrate.ts +32 -0
- package/src/ai-relay/db/migrations/001_usage.ts +26 -0
- package/src/ai-relay/db/schema.ts +20 -0
- package/src/ai-relay/index.ts +18 -0
- package/src/ai-relay/metering.ts +68 -0
- package/src/ai-relay/usage.ts +115 -0
- package/src/client/ai.ts +96 -0
- package/src/client/api.ts +528 -0
- package/src/client/auth/client.ts +188 -0
- package/src/client/auth/failure.ts +54 -0
- package/src/client/auth/navigation.ts +45 -0
- package/src/client/device-authorization.ts +134 -0
- package/src/client/discovery.ts +105 -0
- package/src/client/images.ts +81 -0
- package/src/client/index.ts +53 -0
- package/src/client/portal/account.ts +183 -0
- package/src/client/portal/administration.ts +130 -0
- package/src/client/portal/client.ts +18 -0
- package/src/client/portal/request.ts +115 -0
- package/src/client/response.ts +51 -0
- package/src/client/workspaces.ts +142 -0
- package/src/contract/account.ts +204 -0
- package/src/contract/admin/index.ts +187 -0
- package/src/contract/ai.ts +150 -0
- package/src/contract/collaboration.ts +45 -0
- package/src/contract/discovery.ts +81 -0
- package/src/contract/documents.ts +265 -0
- package/src/contract/entitlements.ts +28 -0
- package/src/contract/index.ts +204 -0
- package/src/contract/links.ts +87 -0
- package/src/contract/portal.ts +11 -0
- package/src/contract/relay.ts +368 -0
- package/src/contract/sharing.ts +191 -0
- package/src/contract/versions.ts +87 -0
- package/src/contract/workspaces.ts +100 -0
- package/src/email/index.ts +14 -0
- package/src/email/render.ts +276 -0
- package/src/email/schema.ts +144 -0
- package/src/email/templates/brand.ts +105 -0
- package/src/email/templates/document-invitation.ts +35 -0
- package/src/email/templates/enrollment.ts +27 -0
- package/src/email/templates/layout.ts +18 -0
- package/src/runtime/cloudflare/email.ts +70 -0
- package/src/runtime/cloudflare/environment.ts +57 -0
- package/src/runtime/cloudflare/index.ts +3 -0
- package/src/runtime/cloudflare/relay.ts +136 -0
- package/src/runtime/cloudflare/site.ts +13 -0
- package/src/runtime/cloudflare/tsconfig.json +21 -0
- package/src/runtime/cloudflare/worker.ts +160 -0
- package/src/runtime/node/admin.ts +59 -0
- package/src/runtime/node/ai-relay/main.ts +35 -0
- package/src/runtime/node/ai-relay/server.ts +63 -0
- package/src/runtime/node/application.ts +50 -0
- package/src/runtime/node/bootstrap.ts +22 -0
- package/src/runtime/node/cleanup.ts +24 -0
- package/src/runtime/node/command.ts +17 -0
- package/src/runtime/node/config.ts +16 -0
- package/src/runtime/node/email/runtime.ts +43 -0
- package/src/runtime/node/email/transport.ts +112 -0
- package/src/runtime/node/entitlements/main.ts +41 -0
- package/src/runtime/node/entitlements/refusal.ts +15 -0
- package/src/runtime/node/index.ts +25 -0
- package/src/runtime/node/listen.ts +35 -0
- package/src/runtime/node/main.ts +29 -0
- package/src/runtime/node/migrate.ts +13 -0
- package/src/runtime/node/quota-reconcile.ts +9 -0
- package/src/runtime/node/relay.ts +54 -0
- package/src/runtime/node/server.ts +121 -0
- package/src/runtime/node/site.ts +64 -0
- package/src/runtime/postgres/database.ts +19 -0
- package/src/runtime/s3/objects.ts +244 -0
- package/src/runtime/site/server.ts +82 -0
- package/src/server/account/actions.ts +66 -0
- package/src/server/account/routes.ts +300 -0
- package/src/server/ai/errors.ts +7 -0
- package/src/server/ai/index.ts +4 -0
- package/src/server/ai/keys.ts +43 -0
- package/src/server/ai/routes.ts +43 -0
- package/src/server/ai/service.ts +70 -0
- package/src/server/api/index.ts +8 -0
- package/src/server/api/router.ts +117 -0
- package/src/server/api/types.ts +7 -0
- package/src/server/app.ts +375 -0
- package/src/server/auth/account.ts +73 -0
- package/src/server/auth/activity.ts +213 -0
- package/src/server/auth/adapter.ts +79 -0
- package/src/server/auth/email.ts +125 -0
- package/src/server/auth/endpoints.ts +57 -0
- package/src/server/auth/factory.ts +583 -0
- package/src/server/auth/index.ts +17 -0
- package/src/server/auth/mfa-assurance.ts +55 -0
- package/src/server/auth/runtime.ts +26 -0
- package/src/server/auth/session.ts +19 -0
- package/src/server/auth/social-providers.ts +55 -0
- package/src/server/auth/user-agent.ts +16 -0
- package/src/server/auth/workspace-access.ts +23 -0
- package/src/server/cleanup/configured.ts +38 -0
- package/src/server/cleanup/documents.ts +231 -0
- package/src/server/cleanup/index.ts +29 -0
- package/src/server/cleanup/objects.ts +27 -0
- package/src/server/cleanup/revisions.ts +232 -0
- package/src/server/cleanup/uploads.ts +129 -0
- package/src/server/cleanup/worker.ts +79 -0
- package/src/server/collaboration/index.ts +28 -0
- package/src/server/collaboration/relay/authorize.ts +53 -0
- package/src/server/collaboration/relay/awareness.ts +104 -0
- package/src/server/collaboration/relay/documents.ts +39 -0
- package/src/server/collaboration/relay/hub.ts +524 -0
- package/src/server/collaboration/relay/index.ts +15 -0
- package/src/server/collaboration/relay/persistence.ts +48 -0
- package/src/server/collaboration/routes.ts +77 -0
- package/src/server/collaboration/service.ts +188 -0
- package/src/server/config/deployment.ts +178 -0
- package/src/server/config/index.ts +20 -0
- package/src/server/config/limits.ts +8 -0
- package/src/server/config/public.ts +66 -0
- package/src/server/config/schema.ts +512 -0
- package/src/server/db/database.ts +15 -0
- package/src/server/db/expressions.ts +13 -0
- package/src/server/db/index.ts +21 -0
- package/src/server/db/migrate.ts +177 -0
- package/src/server/db/migrations/001_foundation.ts +164 -0
- package/src/server/db/migrations/002_upload_cleanup_claims.ts +34 -0
- package/src/server/db/migrations/003_document_cleanup_claims.ts +23 -0
- package/src/server/db/migrations/004_document_sharing.ts +82 -0
- package/src/server/db/migrations/005_document_collaboration_epoch.ts +13 -0
- package/src/server/db/migrations/006_invitation_continuation.ts +27 -0
- package/src/server/db/migrations/007_collaboration_state.ts +25 -0
- package/src/server/db/migrations/008_storage_reservations.ts +37 -0
- package/src/server/db/migrations/009_workspace_entitlements.ts +22 -0
- package/src/server/db/migrations/010_upload_finalization.ts +22 -0
- package/src/server/db/migrations/011_upload_finalization_lease.ts +12 -0
- package/src/server/db/migrations/012_transactional_email.ts +48 -0
- package/src/server/db/migrations/013_admin_enrollment.ts +54 -0
- package/src/server/db/migrations/014_enrollment_email_kinds.ts +30 -0
- package/src/server/db/migrations/015_cloud_rate_limit.ts +22 -0
- package/src/server/db/migrations/016_auth_schema.ts +16 -0
- package/src/server/db/migrations/017_authentication_email_kinds.ts +32 -0
- package/src/server/db/migrations/018_authentication_mfa.ts +78 -0
- package/src/server/db/migrations/019_better_auth_account_issuer.ts +42 -0
- package/src/server/db/migrations/020_workspace_invitations.ts +57 -0
- package/src/server/db/migrations/021_document_versions.ts +66 -0
- package/src/server/db/migrations/022_entitlement_external_version.ts +17 -0
- package/src/server/db/migrations/023_document_images.ts +61 -0
- package/src/server/db/migrations/024_account_activity.ts +66 -0
- package/src/server/db/migrations/025_table_names.ts +58 -0
- package/src/server/db/migrations/026_user_picture.ts +30 -0
- package/src/server/db/migrations/027_document_kind.ts +19 -0
- package/src/server/db/migrations/helpers.ts +78 -0
- package/src/server/db/tables.ts +394 -0
- package/src/server/documents/access.ts +103 -0
- package/src/server/documents/errors.ts +16 -0
- package/src/server/documents/images.ts +407 -0
- package/src/server/documents/index.ts +14 -0
- package/src/server/documents/limits.ts +57 -0
- package/src/server/documents/repository.ts +141 -0
- package/src/server/documents/routes.ts +239 -0
- package/src/server/documents/service.ts +597 -0
- package/src/server/documents/summary.ts +37 -0
- package/src/server/documents/types.ts +14 -0
- package/src/server/documents/versions/checkpoint.ts +98 -0
- package/src/server/documents/versions/history.ts +25 -0
- package/src/server/documents/versions/index.ts +4 -0
- package/src/server/documents/versions/routes.ts +112 -0
- package/src/server/documents/versions/service.ts +397 -0
- package/src/server/email/crypto.ts +57 -0
- package/src/server/email/index.ts +18 -0
- package/src/server/email/invitations.ts +30 -0
- package/src/server/email/service.ts +245 -0
- package/src/server/email/types.ts +56 -0
- package/src/server/email/worker.ts +33 -0
- package/src/server/index.ts +279 -0
- package/src/server/internal/index.ts +8 -0
- package/src/server/internal/routes.ts +41 -0
- package/src/server/internal/schema.ts +10 -0
- package/src/server/internal/service.ts +44 -0
- package/src/server/invitations/index.ts +6 -0
- package/src/server/invitations/types.ts +30 -0
- package/src/server/objects/index.ts +16 -0
- package/src/server/objects/types.ts +81 -0
- package/src/server/pictures/index.ts +9 -0
- package/src/server/pictures/provider.ts +61 -0
- package/src/server/pictures/routes.ts +21 -0
- package/src/server/pictures/service.ts +235 -0
- package/src/server/policy/configured.ts +23 -0
- package/src/server/policy/database.ts +108 -0
- package/src/server/policy/entitlements.ts +29 -0
- package/src/server/policy/index.ts +17 -0
- package/src/server/policy/keys.ts +23 -0
- package/src/server/policy/policy.ts +117 -0
- package/src/server/policy/provider.ts +67 -0
- package/src/server/policy/schema.ts +69 -0
- package/src/server/policy/service.ts +85 -0
- package/src/server/policy/static.ts +62 -0
- package/src/server/quota/index.ts +7 -0
- package/src/server/quota/reconcile.ts +61 -0
- package/src/server/quota/storage.ts +165 -0
- package/src/server/rate-limit/cleanup.ts +16 -0
- package/src/server/rate-limit/index.ts +12 -0
- package/src/server/rate-limit/keys.ts +38 -0
- package/src/server/rate-limit/middleware.ts +137 -0
- package/src/server/rate-limit/postgres.ts +79 -0
- package/src/server/sharing/access.ts +29 -0
- package/src/server/sharing/actor.ts +12 -0
- package/src/server/sharing/capabilities/service.ts +262 -0
- package/src/server/sharing/continuation.ts +85 -0
- package/src/server/sharing/contracts.ts +80 -0
- package/src/server/sharing/crypto.ts +48 -0
- package/src/server/sharing/document-routes.ts +41 -0
- package/src/server/sharing/errors.ts +12 -0
- package/src/server/sharing/grants/service.ts +79 -0
- package/src/server/sharing/http.ts +41 -0
- package/src/server/sharing/index.ts +39 -0
- package/src/server/sharing/invitations/service.ts +315 -0
- package/src/server/sharing/policy.ts +44 -0
- package/src/server/sharing/routes.ts +251 -0
- package/src/server/sharing/service.ts +117 -0
- package/src/server/validation.ts +24 -0
- package/src/server/worker/interval.ts +23 -0
- package/src/server/worker/periodic.ts +42 -0
- package/src/server/workspaces/index.ts +16 -0
- package/src/server/workspaces/members.ts +502 -0
- package/src/server/workspaces/repository.ts +91 -0
- package/src/server/workspaces/routes.ts +198 -0
- package/src/server/workspaces/service.ts +84 -0
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CLOUD_PROTOCOL_MAX_UPLOAD_BYTES,
|
|
3
|
+
cloudEditorVersionSchema,
|
|
4
|
+
RELAY_MINIMUM_MESSAGE_BYTES
|
|
5
|
+
} from '#cloud/contract'
|
|
6
|
+
import { staticEntitlementsSchema, staticEntitlementsTOMLSchema } from '#cloud/server/policy/schema'
|
|
7
|
+
import * as v from 'valibot'
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
CLOUD_DEFAULT_MAX_COLLABORATION_MESSAGE_BYTES,
|
|
11
|
+
CLOUD_DEFAULT_MAX_CONNECTIONS_PER_ROOM
|
|
12
|
+
} from './limits'
|
|
13
|
+
|
|
14
|
+
export const httpURLSchema = v.pipe(
|
|
15
|
+
v.string(),
|
|
16
|
+
v.url(),
|
|
17
|
+
v.check((value) => {
|
|
18
|
+
const protocol = new URL(value).protocol
|
|
19
|
+
return protocol === 'https:' || protocol === 'http:'
|
|
20
|
+
}, 'URL must use HTTP or HTTPS')
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
const websocketURLSchema = v.pipe(
|
|
24
|
+
v.string(),
|
|
25
|
+
v.url(),
|
|
26
|
+
v.check((value) => {
|
|
27
|
+
const protocol = new URL(value).protocol
|
|
28
|
+
return protocol === 'ws:' || protocol === 'wss:'
|
|
29
|
+
}, 'URL must use WS or WSS')
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
const optionalTextSchema = v.optional(v.pipe(v.string(), v.trim(), v.minLength(1)))
|
|
33
|
+
|
|
34
|
+
const rawCloudServerConfigSchema = v.object({
|
|
35
|
+
deployment: v.picklist(['official', 'self-hosted']),
|
|
36
|
+
publicURL: httpURLSchema,
|
|
37
|
+
listingMinimumEditorVersion: v.optional(cloudEditorVersionSchema),
|
|
38
|
+
relayURL: v.optional(websocketURLSchema),
|
|
39
|
+
technicalLimits: v.optional(
|
|
40
|
+
v.object({
|
|
41
|
+
maximumUploadBytes: v.optional(
|
|
42
|
+
v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(CLOUD_PROTOCOL_MAX_UPLOAD_BYTES)),
|
|
43
|
+
CLOUD_PROTOCOL_MAX_UPLOAD_BYTES
|
|
44
|
+
),
|
|
45
|
+
maximumCollaborationMessageBytes: v.optional(
|
|
46
|
+
v.pipe(v.number(), v.integer(), v.minValue(RELAY_MINIMUM_MESSAGE_BYTES)),
|
|
47
|
+
CLOUD_DEFAULT_MAX_COLLABORATION_MESSAGE_BYTES
|
|
48
|
+
),
|
|
49
|
+
maximumConnectionsPerRoom: v.optional(
|
|
50
|
+
v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
51
|
+
CLOUD_DEFAULT_MAX_CONNECTIONS_PER_ROOM
|
|
52
|
+
)
|
|
53
|
+
}),
|
|
54
|
+
{
|
|
55
|
+
maximumUploadBytes: CLOUD_PROTOCOL_MAX_UPLOAD_BYTES,
|
|
56
|
+
maximumCollaborationMessageBytes: CLOUD_DEFAULT_MAX_COLLABORATION_MESSAGE_BYTES,
|
|
57
|
+
maximumConnectionsPerRoom: CLOUD_DEFAULT_MAX_CONNECTIONS_PER_ROOM
|
|
58
|
+
}
|
|
59
|
+
),
|
|
60
|
+
staticEntitlements: v.optional(staticEntitlementsSchema),
|
|
61
|
+
databaseURL: v.pipe(v.string(), v.url()),
|
|
62
|
+
authSecret: v.pipe(v.string(), v.minLength(32)),
|
|
63
|
+
trustedOrigins: v.optional(v.array(httpURLSchema), []),
|
|
64
|
+
/** The server's editor works with files on this device without signing in to the server. */
|
|
65
|
+
localEditor: v.optional(v.boolean(), true),
|
|
66
|
+
authTrustedIPHeaders: v.optional(v.array(v.pipe(v.string(), v.trim(), v.minLength(1))), []),
|
|
67
|
+
authTrustedProxies: v.optional(v.array(v.pipe(v.string(), v.trim(), v.minLength(1))), []),
|
|
68
|
+
enrollmentMode: v.optional(v.picklist(['open', 'approval', 'closed']), 'open'),
|
|
69
|
+
indexingPolicy: v.optional(v.picklist(['allow', 'deny']), 'deny'),
|
|
70
|
+
enrollmentAdminNotificationEmails: v.optional(
|
|
71
|
+
v.array(v.pipe(v.string(), v.trim(), v.email())),
|
|
72
|
+
[]
|
|
73
|
+
),
|
|
74
|
+
emailPasswordEnabled: v.optional(v.boolean(), false),
|
|
75
|
+
emailPasswordSignUpEnabled: v.optional(v.boolean(), true),
|
|
76
|
+
emailPasswordMinimumLength: v.optional(
|
|
77
|
+
v.pipe(v.number(), v.integer(), v.minValue(8), v.maxValue(128)),
|
|
78
|
+
8
|
|
79
|
+
),
|
|
80
|
+
emailPasswordMaximumLength: v.optional(
|
|
81
|
+
v.pipe(v.number(), v.integer(), v.minValue(15), v.maxValue(128)),
|
|
82
|
+
128
|
|
83
|
+
),
|
|
84
|
+
emailVerificationExpiresIn: v.optional(v.pipe(v.number(), v.integer(), v.minValue(60)), 3600),
|
|
85
|
+
passwordResetExpiresIn: v.optional(v.pipe(v.number(), v.integer(), v.minValue(60)), 3600),
|
|
86
|
+
compromisedPasswordCheck: v.optional(v.boolean(), false),
|
|
87
|
+
deploymentAdminMFARequired: v.optional(v.boolean(), false),
|
|
88
|
+
totpEnabled: v.optional(v.boolean(), false),
|
|
89
|
+
passkeysEnabled: v.optional(v.boolean(), false),
|
|
90
|
+
recoveryCodesEnabled: v.optional(v.boolean(), false),
|
|
91
|
+
mfaTrustedDeviceDays: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0)), 14),
|
|
92
|
+
passkeyRPName: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1)), 'OpenPencil Cloud'),
|
|
93
|
+
captchaProvider: v.optional(v.literal('cloudflare-turnstile')),
|
|
94
|
+
captchaSiteKey: optionalTextSchema,
|
|
95
|
+
captchaSecretKey: optionalTextSchema,
|
|
96
|
+
captchaAllowedHostnames: v.optional(v.array(v.pipe(v.string(), v.trim(), v.minLength(1))), []),
|
|
97
|
+
googleClientId: optionalTextSchema,
|
|
98
|
+
googleClientSecret: optionalTextSchema,
|
|
99
|
+
appleClientId: optionalTextSchema,
|
|
100
|
+
appleTeamId: optionalTextSchema,
|
|
101
|
+
appleKeyId: optionalTextSchema,
|
|
102
|
+
applePrivateKey: optionalTextSchema,
|
|
103
|
+
appleAppBundleIdentifier: optionalTextSchema,
|
|
104
|
+
s3Endpoint: httpURLSchema,
|
|
105
|
+
s3Region: v.pipe(v.string(), v.trim(), v.minLength(1)),
|
|
106
|
+
s3Bucket: v.pipe(v.string(), v.trim(), v.minLength(1)),
|
|
107
|
+
s3AccessKeyId: v.pipe(v.string(), v.trim(), v.minLength(1)),
|
|
108
|
+
s3SecretAccessKey: v.pipe(v.string(), v.minLength(1)),
|
|
109
|
+
s3SessionToken: optionalTextSchema,
|
|
110
|
+
s3ForcePathStyle: v.optional(v.boolean(), true),
|
|
111
|
+
s3ChecksumVerification: v.optional(v.picklist(['native', 'metadata']), 'native'),
|
|
112
|
+
s3ServerSideEncryption: v.optional(v.picklist(['AES256', 'aws:kms'])),
|
|
113
|
+
s3KmsKeyId: optionalTextSchema,
|
|
114
|
+
smtpHost: optionalTextSchema,
|
|
115
|
+
smtpPort: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(65_535))),
|
|
116
|
+
smtpSecure: v.optional(v.boolean()),
|
|
117
|
+
smtpUser: optionalTextSchema,
|
|
118
|
+
smtpPassword: optionalTextSchema,
|
|
119
|
+
emailFrom: optionalTextSchema,
|
|
120
|
+
emailTransport: v.optional(v.picklist(['none', 'smtp', 'cloudflare']), 'none'),
|
|
121
|
+
emailBatchSize: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(1000)), 50),
|
|
122
|
+
emailIntervalMs: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1000)), 30_000),
|
|
123
|
+
emailLeaseDurationMs: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1000)), 5 * 60_000),
|
|
124
|
+
emailMaximumAttempts: v.optional(
|
|
125
|
+
v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(20)),
|
|
126
|
+
5
|
|
127
|
+
),
|
|
128
|
+
cleanupEnabled: v.optional(v.boolean(), true),
|
|
129
|
+
cleanupBatchSize: v.optional(
|
|
130
|
+
v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(1000)),
|
|
131
|
+
100
|
|
132
|
+
),
|
|
133
|
+
cleanupIntervalMs: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1000)), 60_000),
|
|
134
|
+
cleanupLeaseDurationMs: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1000)), 5 * 60_000),
|
|
135
|
+
documentRetentionMs: v.optional(
|
|
136
|
+
v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
137
|
+
30 * 24 * 60 * 60_000
|
|
138
|
+
),
|
|
139
|
+
/** The AI service editors reach with tokens this server signs; see `src/contract/ai.ts`. */
|
|
140
|
+
aiEndpoint: v.optional(httpURLSchema),
|
|
141
|
+
/** The PKCS #8 PEM of the P-256 key that signs AI service tokens. */
|
|
142
|
+
aiSigningKey: optionalTextSchema,
|
|
143
|
+
aiTokenLifetimeSeconds: v.optional(
|
|
144
|
+
v.pipe(v.number(), v.integer(), v.minValue(60), v.maxValue(60 * 60)),
|
|
145
|
+
10 * 60
|
|
146
|
+
),
|
|
147
|
+
billingPortalURL: v.optional(httpURLSchema),
|
|
148
|
+
/** The bearer token services such as billing present to the internal API. */
|
|
149
|
+
internalServiceToken: v.optional(v.pipe(v.string(), v.minLength(32)))
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
export type CloudServerConfig = v.InferOutput<typeof rawCloudServerConfigSchema>
|
|
153
|
+
|
|
154
|
+
export class CloudConfigError extends Error {
|
|
155
|
+
constructor(message: string) {
|
|
156
|
+
super(message)
|
|
157
|
+
this.name = 'CloudConfigError'
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function requireTogether(
|
|
162
|
+
config: CloudServerConfig,
|
|
163
|
+
label: string,
|
|
164
|
+
fields: Array<keyof CloudServerConfig>
|
|
165
|
+
): void {
|
|
166
|
+
const configured = fields.filter((field) => Boolean(config[field]))
|
|
167
|
+
if (configured.length !== 0 && configured.length !== fields.length) {
|
|
168
|
+
throw new CloudConfigError(`${label} configuration must provide ${fields.join(', ')}`)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function validateAuthenticationConfig(config: CloudServerConfig): void {
|
|
173
|
+
if (config.emailPasswordMinimumLength > config.emailPasswordMaximumLength) {
|
|
174
|
+
throw new CloudConfigError('Minimum password length cannot exceed maximum password length')
|
|
175
|
+
}
|
|
176
|
+
if (config.emailPasswordEnabled && config.emailTransport === 'none') {
|
|
177
|
+
throw new CloudConfigError(
|
|
178
|
+
'Email and password authentication requires transactional email delivery'
|
|
179
|
+
)
|
|
180
|
+
}
|
|
181
|
+
if (config.deploymentAdminMFARequired && !config.totpEnabled && !config.passkeysEnabled) {
|
|
182
|
+
throw new CloudConfigError('Deployment administrator MFA requires TOTP or passkeys')
|
|
183
|
+
}
|
|
184
|
+
if (config.recoveryCodesEnabled && !config.totpEnabled) {
|
|
185
|
+
throw new CloudConfigError('MFA recovery codes require TOTP')
|
|
186
|
+
}
|
|
187
|
+
requireTogether(config, 'CAPTCHA', ['captchaProvider', 'captchaSiteKey', 'captchaSecretKey'])
|
|
188
|
+
if (
|
|
189
|
+
config.deployment === 'official' &&
|
|
190
|
+
config.emailPasswordEnabled &&
|
|
191
|
+
config.emailPasswordSignUpEnabled &&
|
|
192
|
+
(!config.compromisedPasswordCheck || !config.captchaProvider)
|
|
193
|
+
) {
|
|
194
|
+
throw new CloudConfigError(
|
|
195
|
+
'Official email and password sign-up requires compromised-password checks and CAPTCHA'
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
requireTogether(config, 'Google', ['googleClientId', 'googleClientSecret'])
|
|
199
|
+
requireTogether(config, 'Apple', [
|
|
200
|
+
'appleClientId',
|
|
201
|
+
'appleTeamId',
|
|
202
|
+
'appleKeyId',
|
|
203
|
+
'applePrivateKey'
|
|
204
|
+
])
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function validateEmailConfig(config: CloudServerConfig): void {
|
|
208
|
+
requireTogether(config, 'SMTP', ['smtpHost', 'smtpPort'])
|
|
209
|
+
requireTogether(config, 'SMTP authentication', ['smtpUser', 'smtpPassword'])
|
|
210
|
+
if (config.emailTransport === 'smtp' && !config.smtpHost) {
|
|
211
|
+
throw new CloudConfigError('SMTP email transport requires SMTP configuration')
|
|
212
|
+
}
|
|
213
|
+
if (config.smtpHost && config.emailTransport !== 'smtp') {
|
|
214
|
+
throw new CloudConfigError('SMTP configuration requires the smtp email transport')
|
|
215
|
+
}
|
|
216
|
+
if (config.emailTransport !== 'none' && !config.emailFrom) {
|
|
217
|
+
throw new CloudConfigError('Transactional email delivery requires an email from address')
|
|
218
|
+
}
|
|
219
|
+
if (config.deployment === 'official' && config.smtpHost && config.smtpSecure === false) {
|
|
220
|
+
throw new CloudConfigError('Official SMTP delivery must use a secure connection')
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function validateServiceConfig(config: CloudServerConfig): void {
|
|
225
|
+
requireTogether(config, 'AI service', ['aiEndpoint', 'aiSigningKey'])
|
|
226
|
+
if (config.internalServiceToken && config.staticEntitlements) {
|
|
227
|
+
throw new CloudConfigError(
|
|
228
|
+
'The internal API writes database entitlements, which static entitlements would hide'
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
if (
|
|
232
|
+
config.deployment === 'official' &&
|
|
233
|
+
config.aiEndpoint &&
|
|
234
|
+
new URL(config.aiEndpoint).protocol !== 'https:'
|
|
235
|
+
) {
|
|
236
|
+
throw new CloudConfigError('Official AI service endpoint must use HTTPS')
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function validateObjectStorageConfig(config: CloudServerConfig): void {
|
|
241
|
+
if (config.s3KmsKeyId && config.s3ServerSideEncryption !== 'aws:kms') {
|
|
242
|
+
throw new CloudConfigError('S3 KMS key ID requires aws:kms server-side encryption')
|
|
243
|
+
}
|
|
244
|
+
const endpointHost = new URL(config.s3Endpoint).hostname
|
|
245
|
+
if (!endpointHost.endsWith('.r2.cloudflarestorage.com')) return
|
|
246
|
+
if (config.s3Region !== 'auto') {
|
|
247
|
+
throw new CloudConfigError('Cloudflare R2 S3 region must be auto')
|
|
248
|
+
}
|
|
249
|
+
if (config.s3ForcePathStyle) {
|
|
250
|
+
throw new CloudConfigError('Cloudflare R2 S3 endpoint must disable path-style requests')
|
|
251
|
+
}
|
|
252
|
+
if (config.s3ChecksumVerification !== 'metadata') {
|
|
253
|
+
throw new CloudConfigError('Cloudflare R2 checksum verification must use metadata')
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export function parseCloudServerConfig(input: unknown): CloudServerConfig {
|
|
258
|
+
const config = v.parse(rawCloudServerConfigSchema, input)
|
|
259
|
+
validateAuthenticationConfig(config)
|
|
260
|
+
validateEmailConfig(config)
|
|
261
|
+
validateServiceConfig(config)
|
|
262
|
+
validateObjectStorageConfig(config)
|
|
263
|
+
return config
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const DEFAULT_SECRET_NAMES = {
|
|
267
|
+
databaseURL: 'DATABASE_URL',
|
|
268
|
+
authSecret: 'BETTER_AUTH_SECRET',
|
|
269
|
+
googleClientId: 'GOOGLE_CLIENT_ID',
|
|
270
|
+
googleClientSecret: 'GOOGLE_CLIENT_SECRET',
|
|
271
|
+
applePrivateKey: 'APPLE_PRIVATE_KEY',
|
|
272
|
+
s3AccessKeyId: 'S3_ACCESS_KEY_ID',
|
|
273
|
+
s3SecretAccessKey: 'S3_SECRET_ACCESS_KEY',
|
|
274
|
+
s3SessionToken: 'S3_SESSION_TOKEN',
|
|
275
|
+
smtpUser: 'OPENPENCIL_CLOUD_SMTP_USER',
|
|
276
|
+
smtpPassword: 'OPENPENCIL_CLOUD_SMTP_PASSWORD',
|
|
277
|
+
turnstileSecretKey: 'TURNSTILE_SECRET_KEY',
|
|
278
|
+
aiSigningKey: 'OPENPENCIL_CLOUD_AI_SIGNING_KEY',
|
|
279
|
+
internalServiceToken: 'OPENPENCIL_CLOUD_SERVICE_TOKEN'
|
|
280
|
+
} as const
|
|
281
|
+
|
|
282
|
+
const urlSchema = v.pipe(v.string(), v.url())
|
|
283
|
+
const textSchema = v.pipe(v.string(), v.trim(), v.minLength(1))
|
|
284
|
+
const positiveIntegerSchema = v.pipe(v.number(), v.integer(), v.minValue(1))
|
|
285
|
+
const secretReferenceSchema = v.strictObject({ from_env: textSchema })
|
|
286
|
+
const configurableTextSchema = v.union([textSchema, secretReferenceSchema])
|
|
287
|
+
const defaultReference = (name: string) => v.optional(secretReferenceSchema, { from_env: name })
|
|
288
|
+
|
|
289
|
+
const providerSchema = v.strictObject({
|
|
290
|
+
google: v.optional(
|
|
291
|
+
v.strictObject({
|
|
292
|
+
client_id: v.optional(configurableTextSchema, {
|
|
293
|
+
from_env: DEFAULT_SECRET_NAMES.googleClientId
|
|
294
|
+
}),
|
|
295
|
+
client_secret: defaultReference(DEFAULT_SECRET_NAMES.googleClientSecret)
|
|
296
|
+
})
|
|
297
|
+
),
|
|
298
|
+
apple: v.optional(
|
|
299
|
+
v.strictObject({
|
|
300
|
+
client_id: textSchema,
|
|
301
|
+
team_id: textSchema,
|
|
302
|
+
key_id: textSchema,
|
|
303
|
+
private_key: defaultReference(DEFAULT_SECRET_NAMES.applePrivateKey),
|
|
304
|
+
app_bundle_identifier: v.optional(textSchema)
|
|
305
|
+
})
|
|
306
|
+
)
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
const emailSchema = v.optional(
|
|
310
|
+
v.variant('transport', [
|
|
311
|
+
v.strictObject({ transport: v.literal('none') }),
|
|
312
|
+
v.strictObject({
|
|
313
|
+
transport: v.literal('smtp'),
|
|
314
|
+
from: textSchema,
|
|
315
|
+
smtp: v.strictObject({
|
|
316
|
+
host: textSchema,
|
|
317
|
+
port: positiveIntegerSchema,
|
|
318
|
+
secure: v.optional(v.boolean()),
|
|
319
|
+
user: v.optional(secretReferenceSchema, {
|
|
320
|
+
from_env: DEFAULT_SECRET_NAMES.smtpUser
|
|
321
|
+
}),
|
|
322
|
+
password: v.optional(secretReferenceSchema, {
|
|
323
|
+
from_env: DEFAULT_SECRET_NAMES.smtpPassword
|
|
324
|
+
})
|
|
325
|
+
})
|
|
326
|
+
}),
|
|
327
|
+
v.strictObject({ transport: v.literal('cloudflare'), from: textSchema })
|
|
328
|
+
]),
|
|
329
|
+
{ transport: 'none' }
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Every table is strict: a key the schema doesn't know, such as one renamed since, stops startup
|
|
334
|
+
* instead of leaving its setting at a default the operator never chose.
|
|
335
|
+
*/
|
|
336
|
+
export const cloudDeploymentConfigSchema = v.strictObject({
|
|
337
|
+
schema_version: v.literal(2),
|
|
338
|
+
deployment: v.strictObject({
|
|
339
|
+
mode: v.picklist(['official', 'self-hosted']),
|
|
340
|
+
public_url: urlSchema,
|
|
341
|
+
indexing: v.optional(v.picklist(['allow', 'deny']), 'deny'),
|
|
342
|
+
trusted_origins: v.optional(v.array(urlSchema), []),
|
|
343
|
+
// The server's editor works with files on this device without signing in to the server.
|
|
344
|
+
local_editor: v.optional(v.boolean(), true),
|
|
345
|
+
listing: v.optional(v.strictObject({ minimum_editor_version: cloudEditorVersionSchema }))
|
|
346
|
+
}),
|
|
347
|
+
database: v.optional(
|
|
348
|
+
v.strictObject({ url: defaultReference(DEFAULT_SECRET_NAMES.databaseURL) }),
|
|
349
|
+
{
|
|
350
|
+
url: { from_env: DEFAULT_SECRET_NAMES.databaseURL }
|
|
351
|
+
}
|
|
352
|
+
),
|
|
353
|
+
authentication: v.strictObject({
|
|
354
|
+
secret: defaultReference(DEFAULT_SECRET_NAMES.authSecret),
|
|
355
|
+
enrollment: v.optional(
|
|
356
|
+
v.strictObject({
|
|
357
|
+
mode: v.optional(v.picklist(['open', 'approval', 'closed']), 'open'),
|
|
358
|
+
notification_emails: v.optional(v.array(v.pipe(v.string(), v.email())), [])
|
|
359
|
+
}),
|
|
360
|
+
{ mode: 'open', notification_emails: [] }
|
|
361
|
+
),
|
|
362
|
+
email_password: v.optional(
|
|
363
|
+
v.strictObject({
|
|
364
|
+
enabled: v.optional(v.boolean(), false),
|
|
365
|
+
sign_up: v.optional(v.boolean(), true),
|
|
366
|
+
minimum_password_length: v.optional(
|
|
367
|
+
v.pipe(v.number(), v.integer(), v.minValue(8), v.maxValue(128)),
|
|
368
|
+
8
|
|
369
|
+
),
|
|
370
|
+
maximum_password_length: v.optional(
|
|
371
|
+
v.pipe(v.number(), v.integer(), v.minValue(15), v.maxValue(128)),
|
|
372
|
+
128
|
|
373
|
+
),
|
|
374
|
+
verification_link_lifetime_minutes: v.optional(positiveIntegerSchema, 60),
|
|
375
|
+
password_reset_link_lifetime_minutes: v.optional(positiveIntegerSchema, 60),
|
|
376
|
+
compromised_password_check: v.optional(v.boolean(), false)
|
|
377
|
+
}),
|
|
378
|
+
{
|
|
379
|
+
enabled: false,
|
|
380
|
+
sign_up: true,
|
|
381
|
+
minimum_password_length: 8,
|
|
382
|
+
maximum_password_length: 128,
|
|
383
|
+
verification_link_lifetime_minutes: 60,
|
|
384
|
+
password_reset_link_lifetime_minutes: 60,
|
|
385
|
+
compromised_password_check: false
|
|
386
|
+
}
|
|
387
|
+
),
|
|
388
|
+
mfa: v.optional(
|
|
389
|
+
v.strictObject({
|
|
390
|
+
required_for_admins: v.optional(v.boolean(), false),
|
|
391
|
+
totp: v.optional(v.boolean(), false),
|
|
392
|
+
recovery_codes: v.optional(v.boolean(), false),
|
|
393
|
+
trusted_device_lifetime_days: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0)), 14)
|
|
394
|
+
}),
|
|
395
|
+
{
|
|
396
|
+
required_for_admins: false,
|
|
397
|
+
totp: false,
|
|
398
|
+
recovery_codes: false,
|
|
399
|
+
trusted_device_lifetime_days: 14
|
|
400
|
+
}
|
|
401
|
+
),
|
|
402
|
+
// Passkeys belong to public_url's host and origin.
|
|
403
|
+
passkeys: v.optional(
|
|
404
|
+
v.strictObject({
|
|
405
|
+
enabled: v.optional(v.boolean(), false),
|
|
406
|
+
rp_name: v.optional(textSchema, 'OpenPencil Cloud')
|
|
407
|
+
}),
|
|
408
|
+
{ enabled: false, rp_name: 'OpenPencil Cloud' }
|
|
409
|
+
),
|
|
410
|
+
captcha: v.optional(
|
|
411
|
+
v.strictObject({
|
|
412
|
+
provider: v.literal('cloudflare-turnstile'),
|
|
413
|
+
site_key: textSchema,
|
|
414
|
+
secret_key: defaultReference(DEFAULT_SECRET_NAMES.turnstileSecretKey),
|
|
415
|
+
allowed_hostnames: v.optional(v.array(textSchema), [])
|
|
416
|
+
})
|
|
417
|
+
),
|
|
418
|
+
trusted_proxies: v.optional(
|
|
419
|
+
v.strictObject({
|
|
420
|
+
headers: v.optional(v.array(textSchema), []),
|
|
421
|
+
addresses: v.optional(v.array(textSchema), [])
|
|
422
|
+
}),
|
|
423
|
+
{ headers: [], addresses: [] }
|
|
424
|
+
),
|
|
425
|
+
providers: v.optional(providerSchema, {})
|
|
426
|
+
}),
|
|
427
|
+
object_storage: v.strictObject({
|
|
428
|
+
endpoint: urlSchema,
|
|
429
|
+
region: textSchema,
|
|
430
|
+
bucket: textSchema,
|
|
431
|
+
credentials: v.optional(
|
|
432
|
+
v.strictObject({
|
|
433
|
+
access_key_id: defaultReference(DEFAULT_SECRET_NAMES.s3AccessKeyId),
|
|
434
|
+
secret_access_key: defaultReference(DEFAULT_SECRET_NAMES.s3SecretAccessKey),
|
|
435
|
+
session_token: v.optional(secretReferenceSchema, {
|
|
436
|
+
from_env: DEFAULT_SECRET_NAMES.s3SessionToken
|
|
437
|
+
})
|
|
438
|
+
}),
|
|
439
|
+
{
|
|
440
|
+
access_key_id: { from_env: DEFAULT_SECRET_NAMES.s3AccessKeyId },
|
|
441
|
+
secret_access_key: { from_env: DEFAULT_SECRET_NAMES.s3SecretAccessKey }
|
|
442
|
+
}
|
|
443
|
+
),
|
|
444
|
+
force_path_style: v.optional(v.boolean(), true),
|
|
445
|
+
checksum_verification: v.optional(v.picklist(['native', 'metadata']), 'native'),
|
|
446
|
+
server_side_encryption: v.optional(v.picklist(['AES256', 'aws:kms'])),
|
|
447
|
+
kms_key_id: v.optional(textSchema),
|
|
448
|
+
maximum_upload_bytes: v.optional(positiveIntegerSchema)
|
|
449
|
+
}),
|
|
450
|
+
collaboration: v.optional(
|
|
451
|
+
v.strictObject({
|
|
452
|
+
relay_url: v.optional(urlSchema),
|
|
453
|
+
maximum_message_bytes: v.optional(positiveIntegerSchema),
|
|
454
|
+
maximum_connections_per_room: v.optional(positiveIntegerSchema)
|
|
455
|
+
}),
|
|
456
|
+
{}
|
|
457
|
+
),
|
|
458
|
+
documents: v.optional(
|
|
459
|
+
v.strictObject({
|
|
460
|
+
retention_days: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0)), 30)
|
|
461
|
+
}),
|
|
462
|
+
{ retention_days: 30 }
|
|
463
|
+
),
|
|
464
|
+
email: emailSchema,
|
|
465
|
+
workers: v.optional(
|
|
466
|
+
v.strictObject({
|
|
467
|
+
email: v.optional(
|
|
468
|
+
v.strictObject({
|
|
469
|
+
batch_size: v.optional(positiveIntegerSchema, 50),
|
|
470
|
+
interval_ms: v.optional(positiveIntegerSchema, 30_000),
|
|
471
|
+
lease_ms: v.optional(positiveIntegerSchema, 300_000),
|
|
472
|
+
maximum_attempts: v.optional(positiveIntegerSchema, 5)
|
|
473
|
+
}),
|
|
474
|
+
{ batch_size: 50, interval_ms: 30_000, lease_ms: 300_000, maximum_attempts: 5 }
|
|
475
|
+
),
|
|
476
|
+
cleanup: v.optional(
|
|
477
|
+
v.strictObject({
|
|
478
|
+
enabled: v.optional(v.boolean(), true),
|
|
479
|
+
batch_size: v.optional(positiveIntegerSchema, 100),
|
|
480
|
+
interval_ms: v.optional(positiveIntegerSchema, 60_000),
|
|
481
|
+
lease_ms: v.optional(positiveIntegerSchema, 300_000)
|
|
482
|
+
}),
|
|
483
|
+
{ enabled: true, batch_size: 100, interval_ms: 60_000, lease_ms: 300_000 }
|
|
484
|
+
)
|
|
485
|
+
})
|
|
486
|
+
),
|
|
487
|
+
entitlements: v.optional(
|
|
488
|
+
v.variant('source', [
|
|
489
|
+
v.strictObject({ source: v.literal('static'), ...staticEntitlementsTOMLSchema.entries }),
|
|
490
|
+
v.strictObject({ source: v.literal('database') })
|
|
491
|
+
])
|
|
492
|
+
),
|
|
493
|
+
ai: v.optional(
|
|
494
|
+
v.strictObject({
|
|
495
|
+
endpoint: urlSchema,
|
|
496
|
+
signing_key: defaultReference(DEFAULT_SECRET_NAMES.aiSigningKey),
|
|
497
|
+
token_lifetime_minutes: v.optional(
|
|
498
|
+
v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(60)),
|
|
499
|
+
10
|
|
500
|
+
)
|
|
501
|
+
})
|
|
502
|
+
),
|
|
503
|
+
billing: v.optional(v.strictObject({ portal_url: urlSchema })),
|
|
504
|
+
internal_api: v.optional(
|
|
505
|
+
v.strictObject({ service_token: defaultReference(DEFAULT_SECRET_NAMES.internalServiceToken) })
|
|
506
|
+
)
|
|
507
|
+
})
|
|
508
|
+
|
|
509
|
+
export type CloudDeploymentConfig = v.InferOutput<typeof cloudDeploymentConfigSchema>
|
|
510
|
+
/** Deployment configuration as an operator writes it, before defaults are applied. */
|
|
511
|
+
export type CloudDeploymentInput = v.InferInput<typeof cloudDeploymentConfigSchema>
|
|
512
|
+
export type CloudSecretReference = v.InferOutput<typeof secretReferenceSchema>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Dialect } from 'kysely'
|
|
2
|
+
import { CamelCasePlugin, Kysely } from 'kysely'
|
|
3
|
+
|
|
4
|
+
import type { CloudDatabase } from './tables'
|
|
5
|
+
|
|
6
|
+
export type CloudDatabaseOptions = {
|
|
7
|
+
dialect: Dialect
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function createCloudDatabase(options: CloudDatabaseOptions): Kysely<CloudDatabase> {
|
|
11
|
+
return new Kysely<CloudDatabase>({
|
|
12
|
+
dialect: options.dialect,
|
|
13
|
+
plugins: [new CamelCasePlugin()]
|
|
14
|
+
})
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { sql, type Expression } from 'kysely'
|
|
2
|
+
|
|
3
|
+
export const CURRENT_TIMESTAMP = sql<Date>`current_timestamp`
|
|
4
|
+
export const EMPTY_JSON_OBJECT = sql`'{}'::jsonb`
|
|
5
|
+
|
|
6
|
+
const CHECK_VALUE_PATTERN = /^[a-z][a-z0-9-]*$/
|
|
7
|
+
|
|
8
|
+
export function checkColumnIn(column: string, values: readonly string[]): Expression<boolean> {
|
|
9
|
+
if (values.length === 0 || values.some((value) => !CHECK_VALUE_PATTERN.test(value))) {
|
|
10
|
+
throw new Error('Check constraint values must be non-empty lowercase identifiers')
|
|
11
|
+
}
|
|
12
|
+
return sql<boolean>`${sql.ref(column)} in (${sql.join(values.map((value) => sql.lit(value)))})`
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { createCloudDatabase, type CloudDatabaseOptions } from './database'
|
|
2
|
+
export { migrateCloudDatabase } from './migrate'
|
|
3
|
+
export type {
|
|
4
|
+
CloudDatabase,
|
|
5
|
+
Document,
|
|
6
|
+
DocumentRevision,
|
|
7
|
+
NewDocument,
|
|
8
|
+
NewDocumentRevision,
|
|
9
|
+
NewStorageObject,
|
|
10
|
+
NewTransactionalEmail,
|
|
11
|
+
NewUpload,
|
|
12
|
+
NewWorkspace,
|
|
13
|
+
StorageObject,
|
|
14
|
+
TransactionalEmail,
|
|
15
|
+
TransactionalEmailStatus,
|
|
16
|
+
Upload,
|
|
17
|
+
UploadStatus,
|
|
18
|
+
UserPictureFormat,
|
|
19
|
+
Workspace,
|
|
20
|
+
WorkspaceUpdate
|
|
21
|
+
} from './tables'
|