@pairdraw/cloud 0.0.0-stage → 0.16.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 +1578 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +2008 -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 +1673 -0
- package/dist/contract2.js.map +1 -0
- package/dist/email.d.ts +155 -0
- package/dist/email.d.ts.map +1 -0
- package/dist/email.js +700 -0
- package/dist/email.js.map +1 -0
- package/dist/index.d.ts +1945 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/listen.mjs +1905 -0
- package/dist/listen.mjs.map +1 -0
- package/dist/runtime-node.d.mts +10715 -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 +13772 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +8856 -0
- package/dist/server.js.map +1 -0
- package/dist/server.mjs +8836 -0
- package/dist/server.mjs.map +1 -0
- package/dist/server2.mjs +505 -0
- package/dist/server2.mjs.map +1 -0
- package/package.json +132 -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 +26 -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 +530 -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/profiles.ts +79 -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/comments.ts +149 -0
- package/src/contract/discovery.ts +81 -0
- package/src/contract/documents.ts +263 -0
- package/src/contract/entitlements.ts +28 -0
- package/src/contract/index.ts +210 -0
- package/src/contract/links.ts +108 -0
- package/src/contract/portal.ts +11 -0
- package/src/contract/profiles.ts +88 -0
- package/src/contract/relay.ts +370 -0
- package/src/contract/sharing.ts +215 -0
- package/src/contract/versions.ts +87 -0
- package/src/contract/workspaces.ts +100 -0
- package/src/email/index.ts +13 -0
- package/src/email/render.ts +304 -0
- package/src/email/schema.ts +144 -0
- package/src/email/templates/brand.ts +125 -0
- package/src/email/templates/document-invitation.ts +39 -0
- package/src/email/templates/enrollment.ts +30 -0
- package/src/email/templates/layout.ts +20 -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 +161 -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 +44 -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 +119 -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 +129 -0
- package/src/server/api/types.ts +7 -0
- package/src/server/app.ts +385 -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 +246 -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 +54 -0
- package/src/server/collaboration/relay/awareness.ts +104 -0
- package/src/server/collaboration/relay/comments.ts +86 -0
- package/src/server/collaboration/relay/documents.ts +39 -0
- package/src/server/collaboration/relay/hub.ts +567 -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 +190 -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_sharing_comments_snapshots_profiles.ts +74 -0
- package/src/server/db/migrations/helpers.ts +78 -0
- package/src/server/db/tables.ts +399 -0
- package/src/server/documents/access.ts +103 -0
- package/src/server/documents/errors.ts +16 -0
- package/src/server/documents/images.ts +405 -0
- package/src/server/documents/index.ts +14 -0
- package/src/server/documents/limits.ts +57 -0
- package/src/server/documents/repository.ts +131 -0
- package/src/server/documents/routes.ts +239 -0
- package/src/server/documents/service.ts +607 -0
- package/src/server/documents/summary.ts +36 -0
- package/src/server/documents/types.ts +13 -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 +396 -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 +247 -0
- package/src/server/email/types.ts +56 -0
- package/src/server/email/worker.ts +33 -0
- package/src/server/index.ts +288 -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/profiles/index.ts +12 -0
- package/src/server/profiles/routes.ts +103 -0
- package/src/server/profiles/service.ts +266 -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 +318 -0
- package/src/server/sharing/continuation.ts +83 -0
- package/src/server/sharing/contracts.ts +82 -0
- package/src/server/sharing/crypto.ts +48 -0
- package/src/server/sharing/document-routes.ts +41 -0
- package/src/server/sharing/errors.ts +20 -0
- package/src/server/sharing/grants/service.ts +79 -0
- package/src/server/sharing/http.ts +45 -0
- package/src/server/sharing/index.ts +40 -0
- package/src/server/sharing/invitations/service.ts +315 -0
- package/src/server/sharing/policy.ts +42 -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,45 @@
|
|
|
1
|
+
import * as v from 'valibot'
|
|
2
|
+
|
|
3
|
+
import { documentPermissionSchema } from './documents'
|
|
4
|
+
|
|
5
|
+
export const collaborationPrincipalSchema = v.variant('kind', [
|
|
6
|
+
v.object({
|
|
7
|
+
kind: v.literal('user'),
|
|
8
|
+
userId: v.string(),
|
|
9
|
+
name: v.string(),
|
|
10
|
+
email: v.pipe(v.string(), v.email())
|
|
11
|
+
}),
|
|
12
|
+
v.object({
|
|
13
|
+
kind: v.literal('guest'),
|
|
14
|
+
guestId: v.string(),
|
|
15
|
+
name: v.string()
|
|
16
|
+
})
|
|
17
|
+
])
|
|
18
|
+
export type CollaborationPrincipal = v.InferOutput<typeof collaborationPrincipalSchema>
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Who the relay verified a peer to be, as it writes into that peer's presence under `cloud`, so
|
|
22
|
+
* other peers can trust it over what the peer says of itself.
|
|
23
|
+
*/
|
|
24
|
+
export const cloudPresenceSchema = v.object({
|
|
25
|
+
kind: v.picklist(['user', 'guest']),
|
|
26
|
+
id: v.string(),
|
|
27
|
+
name: v.string(),
|
|
28
|
+
permission: documentPermissionSchema
|
|
29
|
+
})
|
|
30
|
+
export type CloudPresence = v.InferOutput<typeof cloudPresenceSchema>
|
|
31
|
+
|
|
32
|
+
export const collaborationTicketSchema = v.object({
|
|
33
|
+
token: v.string(),
|
|
34
|
+
provider: v.optional(v.picklist(['trystero', 'relay'])),
|
|
35
|
+
serverURL: v.optional(v.pipe(v.string(), v.url())),
|
|
36
|
+
documentId: v.pipe(v.string(), v.uuid()),
|
|
37
|
+
roomId: v.string(),
|
|
38
|
+
roomKey: v.pipe(v.string(), v.minLength(43), v.maxLength(128)),
|
|
39
|
+
principal: collaborationPrincipalSchema,
|
|
40
|
+
permission: documentPermissionSchema,
|
|
41
|
+
roomEpoch: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
42
|
+
expiresAt: v.string(),
|
|
43
|
+
serverEnforcedWrites: v.boolean()
|
|
44
|
+
})
|
|
45
|
+
export type CollaborationTicket = v.InferOutput<typeof collaborationTicketSchema>
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { isEqual, omitBy } from 'es-toolkit'
|
|
2
|
+
import * as v from 'valibot'
|
|
3
|
+
import * as Y from 'yjs'
|
|
4
|
+
|
|
5
|
+
import type { CommentReply, CommentThread } from '@pairdraw/scene-graph'
|
|
6
|
+
import { commentThreadsSchema } from '@pairdraw/scene-graph/comments'
|
|
7
|
+
|
|
8
|
+
import { RELAY_MINIMUM_MESSAGE_BYTES } from './relay'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The room map that holds a document's comment threads by ID. Each thread is a map of its fields,
|
|
12
|
+
* and its `replies` field a map of replies by ID, so people commenting at once all keep theirs.
|
|
13
|
+
*/
|
|
14
|
+
export const ROOM_COMMENT_THREADS = 'commentThreads'
|
|
15
|
+
|
|
16
|
+
/** The most threads one message on the comment channel may carry. */
|
|
17
|
+
export const MAX_RELAYED_COMMENT_THREADS = 20
|
|
18
|
+
/**
|
|
19
|
+
* The most bytes one message on the comment channel carries: well under the smallest message
|
|
20
|
+
* limit a relay may set, with room for framing, so a commenter's message never closes its socket.
|
|
21
|
+
*/
|
|
22
|
+
export const MAX_RELAYED_COMMENT_BYTES = RELAY_MINIMUM_MESSAGE_BYTES - 64 * 1024
|
|
23
|
+
/** The longest comment or reply the relay writes for a commenter, in characters. */
|
|
24
|
+
export const MAX_RELAYED_COMMENT_TEXT = 10_000
|
|
25
|
+
/** The most replies a thread a commenter sends may hold. */
|
|
26
|
+
export const MAX_RELAYED_COMMENT_REPLIES = 500
|
|
27
|
+
|
|
28
|
+
const commentRelayMessageSchema = v.object({
|
|
29
|
+
threads: v.pipe(
|
|
30
|
+
v.array(v.unknown()),
|
|
31
|
+
v.minLength(1),
|
|
32
|
+
v.maxLength(MAX_RELAYED_COMMENT_THREADS),
|
|
33
|
+
v.transform((items): CommentThread[] => {
|
|
34
|
+
// Threads that cannot be read are left out, as files and rooms leave them out.
|
|
35
|
+
const parsed = v.safeParse(commentThreadsSchema, items)
|
|
36
|
+
return parsed.success ? parsed.output : []
|
|
37
|
+
})
|
|
38
|
+
)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
/** A commenter's changed threads, as it sends them on the relay's comment channel. */
|
|
42
|
+
export function encodeCommentRelayMessage(threads: readonly CommentThread[]): Uint8Array {
|
|
43
|
+
return new TextEncoder().encode(JSON.stringify({ threads }))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Bytes `encodeCommentRelayMessage` adds around its threads: `{"threads":[` and `]}`. */
|
|
47
|
+
const COMMENT_MESSAGE_FRAMING_BYTES = encodeCommentRelayMessage([]).byteLength
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Packs threads into as few comment channel messages as fit `MAX_RELAYED_COMMENT_THREADS` and
|
|
51
|
+
* `MAX_RELAYED_COMMENT_BYTES`. A thread too large for a message of its own cannot be sent; it is
|
|
52
|
+
* returned in `oversized` instead.
|
|
53
|
+
*/
|
|
54
|
+
export function packCommentRelayMessages(threads: readonly CommentThread[]): {
|
|
55
|
+
messages: Uint8Array[]
|
|
56
|
+
oversized: CommentThread[]
|
|
57
|
+
} {
|
|
58
|
+
const encoder = new TextEncoder()
|
|
59
|
+
const messages: Uint8Array[] = []
|
|
60
|
+
const oversized: CommentThread[] = []
|
|
61
|
+
let batch: CommentThread[] = []
|
|
62
|
+
let bytes = COMMENT_MESSAGE_FRAMING_BYTES
|
|
63
|
+
const flush = () => {
|
|
64
|
+
if (batch.length > 0) messages.push(encodeCommentRelayMessage(batch))
|
|
65
|
+
batch = []
|
|
66
|
+
bytes = COMMENT_MESSAGE_FRAMING_BYTES
|
|
67
|
+
}
|
|
68
|
+
for (const thread of threads) {
|
|
69
|
+
const size = encoder.encode(JSON.stringify(thread)).byteLength
|
|
70
|
+
if (COMMENT_MESSAGE_FRAMING_BYTES + size > MAX_RELAYED_COMMENT_BYTES) {
|
|
71
|
+
oversized.push(thread)
|
|
72
|
+
continue
|
|
73
|
+
}
|
|
74
|
+
// Threads after the first are separated by a comma.
|
|
75
|
+
const added = size + (batch.length > 0 ? 1 : 0)
|
|
76
|
+
if (batch.length >= MAX_RELAYED_COMMENT_THREADS || bytes + added > MAX_RELAYED_COMMENT_BYTES) {
|
|
77
|
+
flush()
|
|
78
|
+
bytes += size
|
|
79
|
+
} else {
|
|
80
|
+
bytes += added
|
|
81
|
+
}
|
|
82
|
+
batch.push(thread)
|
|
83
|
+
}
|
|
84
|
+
flush()
|
|
85
|
+
return { messages, oversized }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The threads a comment channel message carries, or null when it is not one. */
|
|
89
|
+
export function decodeCommentRelayMessage(data: Uint8Array): CommentThread[] | null {
|
|
90
|
+
let text: string
|
|
91
|
+
try {
|
|
92
|
+
text = new TextDecoder('utf-8', { fatal: true, ignoreBOM: false }).decode(data)
|
|
93
|
+
} catch {
|
|
94
|
+
return null
|
|
95
|
+
}
|
|
96
|
+
const parsed = v.safeParse(v.pipe(v.string(), v.parseJson(), commentRelayMessageSchema), text)
|
|
97
|
+
return parsed.success ? parsed.output.threads : null
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function byCreatedAt(first: CommentReply, second: CommentReply): number {
|
|
101
|
+
return first.createdAt.localeCompare(second.createdAt)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** A thread as the room holds it, read as files are; null when there is none or it is unreadable. */
|
|
105
|
+
export function readRoomCommentThread(threads: Y.Map<unknown>, id: string): CommentThread | null {
|
|
106
|
+
const record = threads.get(id)
|
|
107
|
+
if (!(record instanceof Y.Map)) return null
|
|
108
|
+
const json: unknown = record.toJSON()
|
|
109
|
+
if (typeof json !== 'object' || json === null) return null
|
|
110
|
+
const replies: unknown = Reflect.get(json, 'replies')
|
|
111
|
+
const listed =
|
|
112
|
+
typeof replies === 'object' && replies !== null ? Object.values(replies) : ([] as unknown[])
|
|
113
|
+
const parsed = v.safeParse(commentThreadsSchema, [{ ...json, replies: listed }])
|
|
114
|
+
const thread = parsed.success ? parsed.output[0] : undefined
|
|
115
|
+
return thread ? { ...thread, replies: thread.replies.toSorted(byCreatedAt) } : null
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Writes a thread into the room in the layout editors write it: its fields one by one, and its
|
|
120
|
+
* replies keyed by ID, changing only what differs so a field another peer changed keeps its change.
|
|
121
|
+
*/
|
|
122
|
+
export function writeRoomCommentThread(threads: Y.Map<unknown>, thread: CommentThread): void {
|
|
123
|
+
let record = threads.get(thread.id)
|
|
124
|
+
if (!(record instanceof Y.Map)) {
|
|
125
|
+
record = new Y.Map<unknown>()
|
|
126
|
+
threads.set(thread.id, record)
|
|
127
|
+
}
|
|
128
|
+
const target = record as Y.Map<unknown>
|
|
129
|
+
const { replies, ...fields } = thread
|
|
130
|
+
const entries = new Map<string, unknown>(Object.entries(fields))
|
|
131
|
+
for (const key of Array.from(target.keys())) {
|
|
132
|
+
if (key !== 'replies' && !entries.has(key)) target.delete(key)
|
|
133
|
+
}
|
|
134
|
+
for (const [key, value] of entries) {
|
|
135
|
+
if (value === undefined) {
|
|
136
|
+
if (target.has(key)) target.delete(key)
|
|
137
|
+
} else if (!isEqual(target.get(key), value)) target.set(key, structuredClone(value))
|
|
138
|
+
}
|
|
139
|
+
let byId = target.get('replies')
|
|
140
|
+
if (!(byId instanceof Y.Map)) {
|
|
141
|
+
byId = new Y.Map<unknown>()
|
|
142
|
+
target.set('replies', byId)
|
|
143
|
+
}
|
|
144
|
+
const replyMap = byId as Y.Map<unknown>
|
|
145
|
+
for (const reply of replies) {
|
|
146
|
+
const value = omitBy(reply, (field) => field === undefined)
|
|
147
|
+
if (!isEqual(replyMap.get(reply.id), value)) replyMap.set(reply.id, structuredClone(value))
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as v from 'valibot'
|
|
2
|
+
|
|
3
|
+
import { cloudAIDiscoverySchema, cloudBillingDiscoverySchema } from './ai'
|
|
4
|
+
|
|
5
|
+
export const CLOUD_PROTOCOL_VERSION = '1' as const
|
|
6
|
+
export const CLOUD_DISCOVERY_PATH = '/.well-known/pairdraw' as const
|
|
7
|
+
|
|
8
|
+
export const cloudDeploymentSchema = v.picklist(['official', 'self-hosted'])
|
|
9
|
+
export type CloudDeployment = v.InferOutput<typeof cloudDeploymentSchema>
|
|
10
|
+
|
|
11
|
+
export const cloudAuthenticationSchema = v.object({
|
|
12
|
+
emailPassword: v.optional(
|
|
13
|
+
v.object({
|
|
14
|
+
signIn: v.boolean(),
|
|
15
|
+
signUp: v.boolean(),
|
|
16
|
+
minimumPasswordLength: v.pipe(v.number(), v.integer(), v.minValue(8)),
|
|
17
|
+
captcha: v.optional(
|
|
18
|
+
v.object({
|
|
19
|
+
provider: v.literal('cloudflare-turnstile'),
|
|
20
|
+
siteKey: v.pipe(v.string(), v.trim(), v.minLength(1))
|
|
21
|
+
})
|
|
22
|
+
)
|
|
23
|
+
})
|
|
24
|
+
),
|
|
25
|
+
socialProviders: v.array(v.picklist(['apple', 'google'])),
|
|
26
|
+
enterpriseSSO: v.boolean(),
|
|
27
|
+
enrollmentMode: v.optional(v.picklist(['open', 'approval', 'closed']), 'open'),
|
|
28
|
+
mfa: v.optional(
|
|
29
|
+
v.object({
|
|
30
|
+
deploymentAdminRequired: v.boolean(),
|
|
31
|
+
totp: v.boolean(),
|
|
32
|
+
passkeys: v.boolean(),
|
|
33
|
+
recoveryCodes: v.boolean()
|
|
34
|
+
})
|
|
35
|
+
)
|
|
36
|
+
})
|
|
37
|
+
export type CloudAuthentication = v.InferOutput<typeof cloudAuthenticationSchema>
|
|
38
|
+
|
|
39
|
+
export const cloudCapabilitiesSchema = v.object({
|
|
40
|
+
documents: v.boolean(),
|
|
41
|
+
workspaces: v.boolean(),
|
|
42
|
+
collaboration: v.boolean()
|
|
43
|
+
})
|
|
44
|
+
export type CloudCapabilities = v.InferOutput<typeof cloudCapabilitiesSchema>
|
|
45
|
+
|
|
46
|
+
/** A released editor version, `major.minor.patch`. */
|
|
47
|
+
export const cloudEditorVersionSchema = v.pipe(v.string(), v.regex(/^\d+\.\d+\.\d+$/))
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Whether editors offer this server to everyone, and from which editor version on. Only the
|
|
51
|
+
* official server's listing is read: it turns the Cloud entry points on without an editor release,
|
|
52
|
+
* and an editor older than the minimum keeps them hidden.
|
|
53
|
+
*/
|
|
54
|
+
export const cloudListingSchema = v.object({ minimumEditorVersion: cloudEditorVersionSchema })
|
|
55
|
+
export type CloudListing = v.InferOutput<typeof cloudListingSchema>
|
|
56
|
+
|
|
57
|
+
export const cloudDiscoverySchema = v.object({
|
|
58
|
+
protocolVersion: v.literal(CLOUD_PROTOCOL_VERSION),
|
|
59
|
+
deployment: cloudDeploymentSchema,
|
|
60
|
+
apiURL: v.pipe(v.string(), v.url()),
|
|
61
|
+
authURL: v.pipe(v.string(), v.url()),
|
|
62
|
+
/** Whether the server's own editor works with files on this device without signing in. */
|
|
63
|
+
localEditor: v.optional(v.boolean(), true),
|
|
64
|
+
authentication: cloudAuthenticationSchema,
|
|
65
|
+
capabilities: cloudCapabilitiesSchema,
|
|
66
|
+
listing: v.optional(cloudListingSchema),
|
|
67
|
+
/** The AI service editors reach with Cloud-signed tokens; absent when the deployment has none. */
|
|
68
|
+
ai: v.optional(cloudAIDiscoverySchema),
|
|
69
|
+
/** Where people manage their plan and buy credits; absent when the deployment does not bill. */
|
|
70
|
+
billing: v.optional(cloudBillingDiscoverySchema)
|
|
71
|
+
})
|
|
72
|
+
export type CloudDiscovery = v.InferOutput<typeof cloudDiscoverySchema>
|
|
73
|
+
|
|
74
|
+
/** The server's own address, where its editor and pages are, from its auth API's. */
|
|
75
|
+
export function cloudServerOrigin(discovery: CloudDiscovery): string {
|
|
76
|
+
return new URL(discovery.authURL).origin
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function parseCloudDiscovery(input: unknown): CloudDiscovery {
|
|
80
|
+
return v.parse(cloudDiscoverySchema, input)
|
|
81
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import * as v from 'valibot'
|
|
2
|
+
|
|
3
|
+
export const CLOUD_PROTOCOL_MAX_UPLOAD_BYTES = 1024 * 1024 * 1024
|
|
4
|
+
|
|
5
|
+
const checksumSchema = v.pipe(v.string(), v.regex(/^[A-Za-z0-9+/]{43}=$/))
|
|
6
|
+
|
|
7
|
+
/** Whether a value is a SHA-256 checksum as the server names stored objects, base64 encoded. */
|
|
8
|
+
export function isCloudChecksum(value: string): boolean {
|
|
9
|
+
return v.is(checksumSchema, value)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** The most images one revision, or one request for image uploads, may name. */
|
|
13
|
+
export const CLOUD_MAX_DOCUMENT_IMAGES = 10_000
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* An image's name inside a `.fig` file that Cloud stores apart from it: the SHA-1 Figma names it
|
|
17
|
+
* by, or an older plain name. A client leaves images under other names inside the file.
|
|
18
|
+
*/
|
|
19
|
+
export const CLOUD_IMAGE_NAME_PATTERN = /^[A-Za-z0-9._-]{1,128}$/
|
|
20
|
+
const imageNameSchema = v.pipe(v.string(), v.regex(CLOUD_IMAGE_NAME_PATTERN))
|
|
21
|
+
|
|
22
|
+
const objectDownloadSchema = v.object({
|
|
23
|
+
url: v.pipe(v.string(), v.url()),
|
|
24
|
+
method: v.literal('GET'),
|
|
25
|
+
headers: v.record(v.string(), v.string()),
|
|
26
|
+
expiresAt: v.string()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
/** An image a stored revision uses, where to download it, and what to check it against. */
|
|
30
|
+
export const documentImageDownloadSchema = v.object({
|
|
31
|
+
name: imageNameSchema,
|
|
32
|
+
checksum: checksumSchema,
|
|
33
|
+
byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
34
|
+
download: objectDownloadSchema
|
|
35
|
+
})
|
|
36
|
+
export type DocumentImageDownload = v.InferOutput<typeof documentImageDownloadSchema>
|
|
37
|
+
|
|
38
|
+
/** Where to download an image a document uses, found by its checksum. */
|
|
39
|
+
export const documentImageLinkSchema = v.object({
|
|
40
|
+
checksum: checksumSchema,
|
|
41
|
+
byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
42
|
+
download: objectDownloadSchema
|
|
43
|
+
})
|
|
44
|
+
export type DocumentImageLink = v.InferOutput<typeof documentImageLinkSchema>
|
|
45
|
+
|
|
46
|
+
/** The images a live room names, by checksum, that a peer needs links for. */
|
|
47
|
+
export const requestImageLinksSchema = v.object({
|
|
48
|
+
checksums: v.pipe(v.array(checksumSchema), v.minLength(1), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES))
|
|
49
|
+
})
|
|
50
|
+
export type RequestImageLinksInput = v.InferOutput<typeof requestImageLinksSchema>
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* What someone may do with a document: look at it, look at it and comment, or edit it. Commenters
|
|
54
|
+
* join its room read-only and send comments through the relay's comment channel.
|
|
55
|
+
*/
|
|
56
|
+
export const DOCUMENT_PERMISSIONS = ['view', 'comment', 'edit'] as const
|
|
57
|
+
export const documentPermissionSchema = v.picklist(DOCUMENT_PERMISSIONS)
|
|
58
|
+
export type DocumentPermission = v.InferOutput<typeof documentPermissionSchema>
|
|
59
|
+
|
|
60
|
+
export const documentAccessSourceSchema = v.picklist(['owner', 'workspace', 'direct-grant'])
|
|
61
|
+
export type DocumentAccessSource = v.InferOutput<typeof documentAccessSourceSchema>
|
|
62
|
+
|
|
63
|
+
export const documentAccessSchema = v.object({
|
|
64
|
+
permission: documentPermissionSchema,
|
|
65
|
+
canManageSharing: v.boolean(),
|
|
66
|
+
sources: v.array(documentAccessSourceSchema),
|
|
67
|
+
/**
|
|
68
|
+
* The revision the document holds now, null before its first save; servers from before snapshot
|
|
69
|
+
* links leave it out.
|
|
70
|
+
*/
|
|
71
|
+
currentRevisionId: v.optional(v.nullable(v.pipe(v.string(), v.uuid())))
|
|
72
|
+
})
|
|
73
|
+
export type DocumentAccess = v.InferOutput<typeof documentAccessSchema>
|
|
74
|
+
|
|
75
|
+
export const documentSummarySchema = v.object({
|
|
76
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
77
|
+
workspaceId: v.pipe(v.string(), v.uuid()),
|
|
78
|
+
name: v.string(),
|
|
79
|
+
currentRevisionId: v.nullable(v.pipe(v.string(), v.uuid())),
|
|
80
|
+
version: v.number(),
|
|
81
|
+
createdAt: v.string(),
|
|
82
|
+
updatedAt: v.string()
|
|
83
|
+
})
|
|
84
|
+
export type DocumentSummary = v.InferOutput<typeof documentSummarySchema>
|
|
85
|
+
|
|
86
|
+
/** A document someone granted the person directly, in a workspace they are not a member of. */
|
|
87
|
+
export const sharedDocumentSchema = v.object({
|
|
88
|
+
...documentSummarySchema.entries,
|
|
89
|
+
workspaceName: v.string(),
|
|
90
|
+
permission: documentPermissionSchema,
|
|
91
|
+
sharedBy: v.nullable(v.object({ name: v.string() })),
|
|
92
|
+
sharedAt: v.string()
|
|
93
|
+
})
|
|
94
|
+
export type SharedDocument = v.InferOutput<typeof sharedDocumentSchema>
|
|
95
|
+
|
|
96
|
+
export const documentDownloadSchema = v.object({
|
|
97
|
+
document: documentSummarySchema,
|
|
98
|
+
revisionId: v.pipe(v.string(), v.uuid()),
|
|
99
|
+
byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
100
|
+
checksum: checksumSchema,
|
|
101
|
+
contentType: v.string(),
|
|
102
|
+
download: objectDownloadSchema,
|
|
103
|
+
/** The images the stored file leaves out, which a client puts back under their names. */
|
|
104
|
+
images: v.pipe(v.array(documentImageDownloadSchema), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES))
|
|
105
|
+
})
|
|
106
|
+
export type DocumentDownload = v.InferOutput<typeof documentDownloadSchema>
|
|
107
|
+
|
|
108
|
+
export const cloudActorSchema = v.object({
|
|
109
|
+
userId: v.string(),
|
|
110
|
+
email: v.pipe(v.string(), v.email()),
|
|
111
|
+
name: v.string()
|
|
112
|
+
})
|
|
113
|
+
export type CloudActorContract = v.InferOutput<typeof cloudActorSchema>
|
|
114
|
+
|
|
115
|
+
export const cloudSessionSchema = v.object({ user: cloudActorSchema })
|
|
116
|
+
export type CloudSession = v.InferOutput<typeof cloudSessionSchema>
|
|
117
|
+
|
|
118
|
+
export const workspaceUsageSchema = v.object({
|
|
119
|
+
bytesUsed: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
120
|
+
objectCount: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
121
|
+
documentCount: v.pipe(v.number(), v.integer(), v.minValue(0))
|
|
122
|
+
})
|
|
123
|
+
export type WorkspaceUsage = v.InferOutput<typeof workspaceUsageSchema>
|
|
124
|
+
|
|
125
|
+
export const CLOUD_DOCUMENT_NAME_MAX_LENGTH = 255
|
|
126
|
+
|
|
127
|
+
export const createDocumentSchema = v.object({
|
|
128
|
+
id: v.optional(v.pipe(v.string(), v.uuid())),
|
|
129
|
+
name: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(CLOUD_DOCUMENT_NAME_MAX_LENGTH))
|
|
130
|
+
})
|
|
131
|
+
export type CreateDocumentInput = v.InferOutput<typeof createDocumentSchema>
|
|
132
|
+
|
|
133
|
+
export const createUploadSchema = v.object({
|
|
134
|
+
baseRevisionId: v.nullable(v.pipe(v.string(), v.uuid())),
|
|
135
|
+
byteSize: v.pipe(
|
|
136
|
+
v.number(),
|
|
137
|
+
v.integer(),
|
|
138
|
+
v.minValue(1),
|
|
139
|
+
v.maxValue(CLOUD_PROTOCOL_MAX_UPLOAD_BYTES)
|
|
140
|
+
),
|
|
141
|
+
checksum: checksumSchema,
|
|
142
|
+
contentType: v.literal('application/octet-stream')
|
|
143
|
+
})
|
|
144
|
+
export type CreateUploadInput = v.InferOutput<typeof createUploadSchema>
|
|
145
|
+
|
|
146
|
+
const imageSizeSchema = v.pipe(
|
|
147
|
+
v.number(),
|
|
148
|
+
v.integer(),
|
|
149
|
+
v.minValue(1),
|
|
150
|
+
v.maxValue(CLOUD_PROTOCOL_MAX_UPLOAD_BYTES)
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
/** Where a client puts an object: one presigned PUT, or the parts of a multipart upload. */
|
|
154
|
+
export const objectUploadSchema = v.variant('kind', [
|
|
155
|
+
v.object({
|
|
156
|
+
kind: v.literal('single'),
|
|
157
|
+
url: v.pipe(v.string(), v.url()),
|
|
158
|
+
method: v.literal('PUT'),
|
|
159
|
+
headers: v.record(v.string(), v.string()),
|
|
160
|
+
expiresAt: v.string()
|
|
161
|
+
}),
|
|
162
|
+
v.object({
|
|
163
|
+
kind: v.literal('multipart'),
|
|
164
|
+
uploadId: v.string(),
|
|
165
|
+
partSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
166
|
+
parts: v.array(
|
|
167
|
+
v.object({
|
|
168
|
+
partNumber: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
169
|
+
url: v.pipe(v.string(), v.url()),
|
|
170
|
+
method: v.literal('PUT'),
|
|
171
|
+
headers: v.record(v.string(), v.string())
|
|
172
|
+
})
|
|
173
|
+
),
|
|
174
|
+
expiresAt: v.string()
|
|
175
|
+
})
|
|
176
|
+
])
|
|
177
|
+
export type ObjectUploadTarget = v.InferOutput<typeof objectUploadSchema>
|
|
178
|
+
|
|
179
|
+
/** An upload the server offers for an image the workspace lacks. */
|
|
180
|
+
export const imageUploadOfferSchema = v.object({
|
|
181
|
+
checksum: checksumSchema,
|
|
182
|
+
uploadId: v.pipe(v.string(), v.uuid()),
|
|
183
|
+
upload: objectUploadSchema
|
|
184
|
+
})
|
|
185
|
+
export type ImageUploadOffer = v.InferOutput<typeof imageUploadOfferSchema>
|
|
186
|
+
|
|
187
|
+
/** The images a save will refer to; the server answers with uploads for those it lacks. */
|
|
188
|
+
export const requestImageUploadsSchema = v.object({
|
|
189
|
+
images: v.pipe(
|
|
190
|
+
v.array(v.object({ checksum: checksumSchema, byteSize: imageSizeSchema })),
|
|
191
|
+
v.minLength(1),
|
|
192
|
+
v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)
|
|
193
|
+
)
|
|
194
|
+
})
|
|
195
|
+
export type RequestImageUploadsInput = v.InferOutput<typeof requestImageUploadsSchema>
|
|
196
|
+
|
|
197
|
+
const completedUploadPartSchema = v.object({
|
|
198
|
+
partNumber: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(10_000)),
|
|
199
|
+
etag: v.pipe(v.string(), v.minLength(1), v.maxLength(255))
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
export const commitUploadSchema = v.object({
|
|
203
|
+
checksum: checksumSchema,
|
|
204
|
+
/** The document title captured with this revision; omitted by older clients. */
|
|
205
|
+
name: v.optional(createDocumentSchema.entries.name),
|
|
206
|
+
multipart: v.optional(
|
|
207
|
+
v.object({
|
|
208
|
+
uploadId: v.pipe(v.string(), v.minLength(1)),
|
|
209
|
+
parts: v.pipe(v.array(completedUploadPartSchema), v.minLength(1), v.maxLength(10_000))
|
|
210
|
+
})
|
|
211
|
+
),
|
|
212
|
+
/** The images the uploaded file leaves out, each stored in the workspace or uploaded before. */
|
|
213
|
+
images: v.optional(
|
|
214
|
+
v.pipe(
|
|
215
|
+
v.array(v.object({ name: imageNameSchema, checksum: checksumSchema })),
|
|
216
|
+
v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)
|
|
217
|
+
),
|
|
218
|
+
[]
|
|
219
|
+
)
|
|
220
|
+
})
|
|
221
|
+
export type CommitUploadInput = v.InferOutput<typeof commitUploadSchema>
|
|
222
|
+
|
|
223
|
+
/** The image uploads a save asked for, committed together once their bytes are in place. */
|
|
224
|
+
export const commitImageUploadsSchema = v.object({
|
|
225
|
+
uploads: v.pipe(
|
|
226
|
+
v.array(
|
|
227
|
+
v.object({
|
|
228
|
+
uploadId: v.pipe(v.string(), v.uuid()),
|
|
229
|
+
checksum: checksumSchema,
|
|
230
|
+
multipart: commitUploadSchema.entries.multipart
|
|
231
|
+
})
|
|
232
|
+
),
|
|
233
|
+
v.minLength(1),
|
|
234
|
+
v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)
|
|
235
|
+
)
|
|
236
|
+
})
|
|
237
|
+
export type CommitImageUploadsInput = v.InferOutput<typeof commitImageUploadsSchema>
|
|
238
|
+
/** A commit as a client sends it, which may leave out the images a whole file holds itself. */
|
|
239
|
+
export type CommitUploadRequest = v.InferInput<typeof commitUploadSchema>
|
|
240
|
+
|
|
241
|
+
export function parseCreateDocument(input: unknown): CreateDocumentInput {
|
|
242
|
+
return v.parse(createDocumentSchema, input)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function parseCreateUpload(input: unknown): CreateUploadInput {
|
|
246
|
+
return v.parse(createUploadSchema, input)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export function parseRequestImageUploads(input: unknown): RequestImageUploadsInput {
|
|
250
|
+
return v.parse(requestImageUploadsSchema, input)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export function parseCommitImageUploads(input: unknown): CommitImageUploadsInput {
|
|
254
|
+
return v.parse(commitImageUploadsSchema, input)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export function parseRequestImageLinks(input: unknown): RequestImageLinksInput {
|
|
258
|
+
return v.parse(requestImageLinksSchema, input)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export function parseCommitUpload(input: unknown): CommitUploadInput {
|
|
262
|
+
return v.parse(commitUploadSchema, input)
|
|
263
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as v from 'valibot'
|
|
2
|
+
|
|
3
|
+
export const workspaceEntitlementsSchema = v.object({
|
|
4
|
+
features: v.object({
|
|
5
|
+
links: v.boolean(),
|
|
6
|
+
guestView: v.boolean(),
|
|
7
|
+
guestEdit: v.boolean(),
|
|
8
|
+
guestPresence: v.boolean(),
|
|
9
|
+
collaboration: v.boolean(),
|
|
10
|
+
revisionHistory: v.boolean(),
|
|
11
|
+
// Optional so editors keep reading servers released before the AI service.
|
|
12
|
+
cloudAI: v.optional(v.boolean(), false)
|
|
13
|
+
}),
|
|
14
|
+
limits: v.object({
|
|
15
|
+
maximumFileBytes: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
16
|
+
maximumStorageBytes: v.nullable(v.pipe(v.number(), v.integer(), v.minValue(1))),
|
|
17
|
+
maximumParticipants: v.nullable(v.pipe(v.number(), v.integer(), v.minValue(1))),
|
|
18
|
+
monthlyCreditAllowance: v.optional(
|
|
19
|
+
v.nullable(v.pipe(v.number(), v.integer(), v.minValue(0))),
|
|
20
|
+
null
|
|
21
|
+
)
|
|
22
|
+
}),
|
|
23
|
+
usage: v.object({
|
|
24
|
+
committedStorageBytes: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
25
|
+
reservedStorageBytes: v.pipe(v.number(), v.integer(), v.minValue(0))
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
export type WorkspaceEntitlements = v.InferOutput<typeof workspaceEntitlementsSchema>
|