@open-pencil/cloud 0.17.0-beta.2 → 0.17.0-beta.5
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 +3 -2
- package/dist/bin/server.mjs +1 -1
- package/dist/bin/server.mjs.map +1 -1
- package/dist/bin/{ai-relay.mjs → services.mjs} +9 -9
- package/dist/bin/services.mjs.map +1 -0
- package/dist/client.d.ts +525 -66
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1257 -654
- package/dist/client.js.map +1 -1
- package/dist/contract.d.ts +2 -2
- package/dist/contract.js +2 -2
- package/dist/contract2.js +1028 -481
- package/dist/contract2.js.map +1 -1
- package/dist/email.d.ts +1780 -31
- package/dist/email.d.ts.map +1 -1
- package/dist/email.js +3556 -325
- package/dist/email.js.map +1 -1
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +48 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +929 -72
- package/dist/index.d.ts.map +1 -1
- package/dist/index2.d.ts +35 -0
- package/dist/index2.d.ts.map +1 -0
- package/dist/listen.mjs +802 -927
- package/dist/listen.mjs.map +1 -1
- package/dist/runtime-cloudflare.d.ts +89 -0
- package/dist/runtime-cloudflare.d.ts.map +1 -0
- package/dist/runtime-cloudflare.js +15667 -0
- package/dist/runtime-cloudflare.js.map +1 -0
- package/dist/runtime-node.d.mts +7166 -3101
- 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 +6525 -2205
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +12500 -7613
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +8625 -2878
- package/dist/server.mjs.map +1 -1
- package/dist/server2.mjs +101 -79
- package/dist/server2.mjs.map +1 -1
- package/package.json +27 -9
- package/src/admin/api/routes.ts +59 -0
- package/src/admin/audit/service.ts +27 -8
- package/src/admin/documents/service.ts +431 -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 +153 -0
- package/src/admin/schema.ts +6 -0
- package/src/client/api.ts +28 -461
- package/src/client/auth/client.ts +22 -3
- package/src/client/auth/navigation.ts +6 -5
- package/src/client/billing.ts +80 -0
- package/src/client/community.ts +40 -0
- package/src/client/discovery.ts +35 -9
- package/src/client/documents.ts +160 -0
- package/src/client/index.ts +14 -7
- package/src/client/portal/account.ts +79 -2
- package/src/client/portal/administration.ts +56 -0
- package/src/client/portal/request.ts +2 -0
- package/src/client/response.ts +21 -0
- package/src/client/schema.ts +8 -0
- package/src/client/services.ts +118 -0
- package/src/client/sharing.ts +262 -0
- package/src/client/versions.ts +104 -0
- package/src/contract/account.ts +108 -2
- package/src/contract/admin/index.ts +67 -3
- package/src/contract/billing.ts +166 -0
- package/src/contract/collaboration.ts +11 -1
- package/src/contract/community.ts +60 -0
- package/src/contract/discovery.ts +83 -4
- package/src/contract/documents.ts +27 -0
- package/src/contract/entitlements.ts +12 -2
- package/src/contract/index.ts +114 -39
- package/src/contract/links.ts +57 -4
- package/src/contract/locale.ts +27 -0
- package/src/contract/portal.ts +12 -1
- package/src/contract/relay.ts +6 -0
- package/src/contract/reports.ts +42 -0
- package/src/contract/routes.ts +10 -0
- package/src/contract/services.ts +235 -0
- package/src/contract/sharing.ts +3 -9
- package/src/email/i18n.ts +174 -0
- package/src/email/index.ts +13 -2
- package/src/email/locales/ar.json +141 -0
- package/src/email/locales/de.json +141 -0
- package/src/email/locales/es.json +141 -0
- package/src/email/locales/fr.json +141 -0
- package/src/email/locales/it.json +141 -0
- package/src/email/locales/ja.json +141 -0
- package/src/email/locales/pl.json +141 -0
- package/src/email/locales/pt-br.json +141 -0
- package/src/email/locales/ru.json +141 -0
- package/src/email/locales/zh-cn.json +141 -0
- package/src/email/messages.ts +200 -0
- package/src/email/render.ts +138 -246
- package/src/email/samples.ts +115 -0
- package/src/email/schema.ts +79 -5
- package/src/email/templates/BrandEmail.vue +54 -0
- package/src/email/templates/DocumentBlocked.vue +45 -0
- package/src/email/templates/DocumentInvitation.vue +24 -0
- package/src/email/templates/DocumentReport.vue +32 -0
- package/src/email/templates/DocumentReportDecided.vue +36 -0
- package/src/email/templates/DocumentReportReceived.vue +18 -0
- package/src/email/templates/DocumentRestored.vue +24 -0
- package/src/email/templates/EmailChangeRequested.vue +24 -0
- package/src/email/templates/EmailRoot.vue +19 -0
- package/src/email/templates/EmailText.vue +9 -0
- package/src/email/templates/EmailVerification.vue +38 -0
- package/src/email/templates/EnrollmentNotification.vue +24 -0
- package/src/email/templates/EnrollmentUpdate.vue +52 -0
- package/src/email/templates/NewSignIn.vue +37 -0
- package/src/email/templates/PasswordChanged.vue +22 -0
- package/src/email/templates/PasswordReset.vue +23 -0
- package/src/email/templates/StorageLimitReached.vue +28 -0
- package/src/email/templates/TwoStepChanged.vue +32 -0
- package/src/email/templates/WaitlistConfirmation.vue +29 -0
- package/src/email/templates/WorkspaceInvitation.vue +28 -0
- package/src/email/templates/brand.ts +9 -61
- package/src/email/templates/localization.ts +17 -0
- package/src/errors/index.ts +6 -0
- package/src/errors/posthog.ts +80 -0
- package/src/global.d.ts +7 -0
- 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 +69 -15
- package/src/runtime/cloudflare/tsconfig.json +2 -1
- package/src/runtime/cloudflare/worker.ts +46 -13
- package/src/runtime/node/application.ts +5 -3
- package/src/runtime/node/bootstrap.ts +15 -4
- package/src/runtime/node/cleanup.ts +20 -3
- package/src/runtime/node/email/transport.ts +13 -10
- package/src/runtime/node/entitlements/main.ts +14 -11
- package/src/runtime/node/index.ts +1 -1
- package/src/runtime/node/main.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 +50 -16
- package/src/runtime/node/{ai-relay → services}/main.ts +7 -7
- 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 -30
- package/src/runtime/s3/objects.ts +41 -1
- package/src/runtime/site/community.ts +101 -0
- package/src/runtime/site/server.ts +49 -6
- package/src/server/account/actions.ts +5 -0
- package/src/server/account/deletion.ts +304 -0
- package/src/server/account/routes.ts +281 -206
- package/src/server/account/terms.ts +42 -0
- package/src/server/account/tokens.ts +57 -0
- package/src/server/api/router.ts +32 -5
- package/src/server/api/types.ts +2 -0
- package/src/server/app/checks.ts +84 -0
- package/src/server/app/editors.ts +20 -0
- package/src/server/app/index.ts +128 -0
- package/src/server/app/indexing.ts +40 -0
- package/src/server/app/limiters.ts +53 -0
- package/src/server/app/routes.ts +114 -0
- package/src/server/app/services.ts +185 -0
- package/src/server/auth/access-control.ts +63 -0
- package/src/server/auth/access-tokens.ts +62 -0
- package/src/server/auth/adapter.ts +32 -1
- package/src/server/auth/email.ts +4 -1
- package/src/server/auth/endpoints.ts +5 -1
- package/src/server/auth/enrollment.ts +116 -0
- package/src/server/auth/factory.ts +116 -132
- package/src/server/auth/index.ts +10 -1
- package/src/server/auth/logger.ts +23 -0
- package/src/server/auth/mfa-assurance.ts +51 -0
- package/src/server/auth/passwords.ts +43 -0
- package/src/server/auth/session.ts +2 -0
- package/src/server/billing/index.ts +6 -0
- package/src/server/billing/routes.ts +27 -0
- package/src/server/billing/tokens.ts +37 -0
- package/src/server/cleanup/configured.ts +27 -7
- 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 +15 -3
- 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 +77 -122
- package/src/server/collaboration/relay/log.ts +5 -2
- package/src/server/collaboration/relay/room.ts +154 -0
- package/src/server/collaboration/service.ts +48 -33
- package/src/server/community/index.ts +2 -0
- package/src/server/community/routes.ts +93 -0
- package/src/server/community/service.ts +134 -0
- package/src/server/config/deployment.ts +41 -9
- package/src/server/config/index.ts +1 -1
- package/src/server/config/public.ts +11 -4
- package/src/server/config/schema.ts +91 -277
- package/src/server/config/toml/schema.ts +307 -0
- package/src/server/db/expressions.ts +15 -1
- package/src/server/db/index.ts +1 -0
- package/src/server/db/migrate.ts +46 -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/009_access_tokens.ts +47 -0
- package/src/server/db/migrations/010_storage_limit_notices.ts +50 -0
- package/src/server/db/migrations/011_account_ids.ts +30 -0
- package/src/server/db/migrations/012_email_locales.ts +34 -0
- package/src/server/db/migrations/013_document_block_emails.ts +40 -0
- package/src/server/db/migrations/014_report_replies.ts +28 -0
- package/src/server/db/migrations/schema.ts +96 -0
- package/src/server/db/tables.ts +82 -4
- package/src/server/db/users.ts +22 -0
- 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/index.ts +1 -1
- package/src/server/documents/limits.ts +14 -8
- 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 +30 -406
- package/src/server/documents/summary.ts +1 -0
- package/src/server/documents/trash.ts +203 -0
- package/src/server/documents/uploads.ts +450 -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 +94 -28
- package/src/server/email/invitations.ts +1 -0
- package/src/server/email/service.ts +31 -4
- package/src/server/email/types.ts +12 -0
- package/src/server/errors/index.ts +51 -16
- package/src/server/index.ts +52 -16
- 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/invitations/types.ts +5 -1
- package/src/server/logging.ts +76 -0
- package/src/server/objects/types.ts +5 -0
- package/src/server/pictures/service.ts +2 -1
- package/src/server/policy/configured.ts +9 -3
- package/src/server/policy/database.ts +52 -27
- package/src/server/policy/index.ts +2 -1
- package/src/server/policy/keys.ts +5 -2
- package/src/server/policy/policy.ts +40 -12
- package/src/server/policy/schema.ts +2 -2
- package/src/server/policy/service.ts +78 -56
- package/src/server/policy/static.ts +5 -5
- package/src/server/policy/storage.ts +33 -0
- package/src/server/policy/workspace.ts +41 -0
- package/src/server/quota/index.ts +6 -0
- package/src/server/quota/notices.ts +121 -0
- package/src/server/quota/reconcile.ts +2 -0
- package/src/server/quota/storage.ts +74 -31
- package/src/server/rate-limit/cleanup.ts +17 -5
- package/src/server/rate-limit/middleware.ts +6 -2
- package/src/server/reports/index.ts +9 -0
- package/src/server/reports/replies.ts +55 -0
- package/src/server/reports/routes.ts +39 -0
- package/src/server/reports/service.ts +145 -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 -23
- package/src/server/sharing/grants/service.ts +11 -18
- package/src/server/sharing/http.ts +4 -0
- package/src/server/sharing/invitations/service.ts +35 -15
- 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 +4 -0
- package/src/server/workspaces/index.ts +1 -0
- package/src/server/workspaces/members.ts +91 -52
- package/src/server/workspaces/repository.ts +2 -1
- package/src/server/workspaces/routes.ts +4 -0
- package/src/{ai-relay → services}/app.ts +46 -44
- package/src/{ai-relay → services}/config.ts +26 -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 +35 -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/client/ai.ts +0 -96
- package/src/contract/ai.ts +0 -150
- package/src/email/templates/document-invitation.ts +0 -35
- package/src/email/templates/enrollment.ts +0 -27
- package/src/email/templates/layout.ts +0 -18
- package/src/server/ai/errors.ts +0 -7
- package/src/server/ai/index.ts +0 -4
- package/src/server/ai/routes.ts +0 -43
- package/src/server/app.ts +0 -379
- 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/dist/contract2.js
CHANGED
|
@@ -7,11 +7,16 @@ import * as encoding from "lib0/encoding";
|
|
|
7
7
|
import * as Y from "yjs";
|
|
8
8
|
import { encodeParam, parseURL, withFragment, withQuery } from "ufo";
|
|
9
9
|
//#region src/contract/account.ts
|
|
10
|
+
/**
|
|
11
|
+
* Where an account stands: it may use the server, waits for an administrator, was refused or had
|
|
12
|
+
* its access taken back, or has to accept the server's current terms first.
|
|
13
|
+
*/
|
|
10
14
|
const cloudAccountStateSchema = v.picklist([
|
|
11
15
|
"active",
|
|
12
16
|
"pending",
|
|
13
17
|
"rejected",
|
|
14
|
-
"revoked"
|
|
18
|
+
"revoked",
|
|
19
|
+
"terms"
|
|
15
20
|
]);
|
|
16
21
|
const cloudIdentitySchema = v.object({
|
|
17
22
|
userId: v.string(),
|
|
@@ -25,6 +30,8 @@ const cloudAccountStatusResponseSchema = v.object({
|
|
|
25
30
|
user: cloudIdentitySchema,
|
|
26
31
|
state: cloudAccountStateSchema
|
|
27
32
|
});
|
|
33
|
+
/** Accepting the server's terms: the version the person read, which must be the current one. */
|
|
34
|
+
const cloudTermsAcceptanceSchema = v.object({ version: v.pipe(v.string(), v.minLength(1)) });
|
|
28
35
|
const cloudAuthenticationProviderSchema = v.picklist([
|
|
29
36
|
"credential",
|
|
30
37
|
"google",
|
|
@@ -60,7 +67,10 @@ const accountSecurityErrorCodeSchema = v.picklist([
|
|
|
60
67
|
"email_unchanged",
|
|
61
68
|
"email_change_unavailable",
|
|
62
69
|
"current_session",
|
|
63
|
-
"picture_invalid"
|
|
70
|
+
"picture_invalid",
|
|
71
|
+
"account_sole_admin",
|
|
72
|
+
"last_admin_required",
|
|
73
|
+
"terms_changed"
|
|
64
74
|
]);
|
|
65
75
|
const accountSecurityErrorResponseSchema = v.object({ error: v.object({ code: accountSecurityErrorCodeSchema }) });
|
|
66
76
|
const cloudMFAStatusSchema = v.object({
|
|
@@ -88,6 +98,43 @@ const cloudPasskeySchema = v.object({
|
|
|
88
98
|
});
|
|
89
99
|
const cloudPasskeysResponseSchema = v.object({ passkeys: v.array(cloudPasskeySchema) });
|
|
90
100
|
const cloudPasskeyDeleteSchema = v.object({ id: v.string() });
|
|
101
|
+
/**
|
|
102
|
+
* Personal access tokens: an account's own credentials for scripts and CI, sent as
|
|
103
|
+
* `Authorization: Bearer <token>`. A token acts as its account on the document API only; it never
|
|
104
|
+
* changes how the account is reached, makes other tokens, or reaches administration.
|
|
105
|
+
*/
|
|
106
|
+
const CLOUD_ACCESS_TOKEN_PREFIX = "opc_";
|
|
107
|
+
const CLOUD_ACCESS_TOKEN_NAME_MAX_LENGTH = 64;
|
|
108
|
+
const CLOUD_ACCESS_TOKEN_MAX_DAYS = 365;
|
|
109
|
+
const cloudAccessTokenSchema = v.object({
|
|
110
|
+
id: v.string(),
|
|
111
|
+
name: v.string(),
|
|
112
|
+
/** The token's first characters, prefix included, to tell tokens apart; never the whole token. */
|
|
113
|
+
start: v.nullable(v.string()),
|
|
114
|
+
createdAt: v.string(),
|
|
115
|
+
expiresAt: v.nullable(v.string()),
|
|
116
|
+
lastUsedAt: v.nullable(v.string())
|
|
117
|
+
});
|
|
118
|
+
const cloudAccessTokensResponseSchema = v.object({ tokens: v.array(cloudAccessTokenSchema) });
|
|
119
|
+
const cloudAccessTokenCreateSchema = v.object({
|
|
120
|
+
name: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(64)),
|
|
121
|
+
expiresInDays: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(365))
|
|
122
|
+
});
|
|
123
|
+
/** A new token, the only time the whole of it is shown. */
|
|
124
|
+
const cloudAccessTokenCreatedResponseSchema = v.object({
|
|
125
|
+
token: v.pipe(v.string(), v.startsWith(CLOUD_ACCESS_TOKEN_PREFIX)),
|
|
126
|
+
accessToken: cloudAccessTokenSchema
|
|
127
|
+
});
|
|
128
|
+
const cloudAccessTokenRevokeSchema = v.object({ id: v.pipe(v.string(), v.minLength(1)) });
|
|
129
|
+
function parseCloudAccessTokenCreate(input) {
|
|
130
|
+
return v.parse(cloudAccessTokenCreateSchema, input);
|
|
131
|
+
}
|
|
132
|
+
function parseCloudAccessTokenRevoke(input) {
|
|
133
|
+
return v.parse(cloudAccessTokenRevokeSchema, input);
|
|
134
|
+
}
|
|
135
|
+
function parseCloudTermsAcceptance(input) {
|
|
136
|
+
return v.parse(cloudTermsAcceptanceSchema, input);
|
|
137
|
+
}
|
|
91
138
|
function parseCloudMFAEnable(input) {
|
|
92
139
|
return v.parse(cloudMFAEnableSchema, input);
|
|
93
140
|
}
|
|
@@ -173,6 +220,34 @@ const cloudSignInSchema = v.object({
|
|
|
173
220
|
createdAt: v.string()
|
|
174
221
|
});
|
|
175
222
|
const cloudSignInsResponseSchema = v.object({ signIns: v.array(cloudSignInSchema) });
|
|
223
|
+
/** A workspace an account deletion reads: one it would delete, or one that stops it. */
|
|
224
|
+
const cloudAccountDeletionWorkspaceSchema = v.object({
|
|
225
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
226
|
+
name: v.string()
|
|
227
|
+
});
|
|
228
|
+
/** A document the account would lose, which Download all saves first. */
|
|
229
|
+
const cloudAccountDeletionDocumentSchema = v.object({
|
|
230
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
231
|
+
name: v.string(),
|
|
232
|
+
workspaceName: v.string()
|
|
233
|
+
});
|
|
234
|
+
/**
|
|
235
|
+
* What deleting the account takes: the workspaces only it belongs to, which go with their
|
|
236
|
+
* documents; the ones it leaves to their other members; the ones it alone administers for other
|
|
237
|
+
* members, which stop the deletion until it makes someone else an admin; and the documents it
|
|
238
|
+
* would lose, those workspaces' and the ones it created in workspaces it leaves.
|
|
239
|
+
*/
|
|
240
|
+
const cloudAccountDeletionSchema = v.object({
|
|
241
|
+
/** The account is the deployment's only administrator, which also stops the deletion. */
|
|
242
|
+
lastAdministrator: v.boolean(),
|
|
243
|
+
blockedBy: v.array(cloudAccountDeletionWorkspaceSchema),
|
|
244
|
+
deletes: v.array(cloudAccountDeletionWorkspaceSchema),
|
|
245
|
+
leaves: v.array(cloudAccountDeletionWorkspaceSchema),
|
|
246
|
+
documents: v.array(cloudAccountDeletionDocumentSchema)
|
|
247
|
+
});
|
|
248
|
+
const cloudAccountDeletionResponseSchema = v.object({ deletion: cloudAccountDeletionSchema });
|
|
249
|
+
/** The password, for a session that signed in too long ago to delete the account on its own. */
|
|
250
|
+
const cloudAccountDeleteSchema = v.object({ password: v.optional(v.pipe(v.string(), v.minLength(1))) });
|
|
176
251
|
function parseCloudProfileUpdate(input) {
|
|
177
252
|
return v.parse(cloudProfileUpdateSchema, input);
|
|
178
253
|
}
|
|
@@ -182,65 +257,94 @@ function parseCloudPictureUpload(input) {
|
|
|
182
257
|
function parseCloudEmailChange(input) {
|
|
183
258
|
return v.parse(cloudEmailChangeSchema, input);
|
|
184
259
|
}
|
|
260
|
+
function parseCloudAccountDelete(input) {
|
|
261
|
+
return v.parse(cloudAccountDeleteSchema, input);
|
|
262
|
+
}
|
|
185
263
|
function parseCloudSessionRevoke(input) {
|
|
186
264
|
return v.parse(cloudSessionRevokeSchema, input);
|
|
187
265
|
}
|
|
188
266
|
//#endregion
|
|
189
|
-
//#region src/contract/
|
|
267
|
+
//#region src/contract/locale.ts
|
|
268
|
+
/** Whether `tag` is a well-formed BCP 47 language tag: `de`, `pt-BR`, `zh-Hant-TW`. */
|
|
269
|
+
function isLanguageTag(tag) {
|
|
270
|
+
try {
|
|
271
|
+
return Intl.getCanonicalLocales(tag).length === 1;
|
|
272
|
+
} catch {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* A language as the app names it, which the server writes email in when it has that language, or
|
|
278
|
+
* the nearest it has, and otherwise in English.
|
|
279
|
+
*/
|
|
280
|
+
const cloudLanguageTagSchema = v.pipe(v.string(), v.maxLength(35), v.check(isLanguageTag, "Not a language tag"));
|
|
281
|
+
/** The language an account's email is written in, as the app last said it uses. */
|
|
282
|
+
const cloudLocaleUpdateSchema = v.object({ locale: cloudLanguageTagSchema });
|
|
283
|
+
function parseCloudLocaleUpdate(input) {
|
|
284
|
+
return v.parse(cloudLocaleUpdateSchema, input);
|
|
285
|
+
}
|
|
286
|
+
//#endregion
|
|
287
|
+
//#region src/contract/services.ts
|
|
190
288
|
/**
|
|
191
|
-
* The contract between editors, Cloud, and
|
|
192
|
-
*
|
|
193
|
-
* the
|
|
194
|
-
*
|
|
289
|
+
* The contract between editors, Cloud, and the services Cloud advertises: AI models today, and
|
|
290
|
+
* other paid capabilities such as image generation and search as they arrive. Cloud only
|
|
291
|
+
* advertises the service and signs short-lived tokens for it; the service, official or
|
|
292
|
+
* self-hosted, calls the providers and keeps the credit wallet. It is versioned apart from the
|
|
293
|
+
* Cloud protocol so a service can change without a Cloud release.
|
|
195
294
|
*/
|
|
196
|
-
const
|
|
197
|
-
/** The `aud` of every token Cloud signs for
|
|
198
|
-
const
|
|
199
|
-
/** Where Cloud publishes the public keys
|
|
200
|
-
const
|
|
295
|
+
const CLOUD_SERVICES_CONTRACT_VERSION = "1";
|
|
296
|
+
/** The `aud` of every token Cloud signs for its services. */
|
|
297
|
+
const CLOUD_SERVICES_TOKEN_AUDIENCE = "openpencil-services";
|
|
298
|
+
/** Where Cloud publishes the public keys a service verifies its tokens with. */
|
|
299
|
+
const CLOUD_SERVICES_JWKS_PATH = "/.well-known/jwks.json";
|
|
201
300
|
/**
|
|
202
301
|
* Where a service answers, below the discovered `endpoint`. Model requests follow the OpenAI chat
|
|
203
302
|
* completions API, so an OpenAI-compatible client takes `${endpoint}${base}` as its base URL.
|
|
204
303
|
*/
|
|
205
|
-
const
|
|
304
|
+
const CLOUD_SERVICES_API_PATHS = {
|
|
206
305
|
base: "/v1",
|
|
207
306
|
chatCompletions: "/v1/chat/completions",
|
|
208
307
|
catalog: "/v1/catalog",
|
|
209
308
|
wallet: "/v1/wallet",
|
|
210
|
-
usage: "/v1/usage"
|
|
309
|
+
usage: "/v1/usage",
|
|
310
|
+
search: "/v1/search"
|
|
211
311
|
};
|
|
212
|
-
const urlSchema = v.pipe(v.string(), v.url());
|
|
213
|
-
const creditsSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
214
|
-
const
|
|
215
|
-
endpoint: urlSchema,
|
|
312
|
+
const urlSchema$1 = v.pipe(v.string(), v.url());
|
|
313
|
+
const creditsSchema$1 = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
314
|
+
const cloudServicesDiscoverySchema = v.object({
|
|
315
|
+
endpoint: urlSchema$1,
|
|
216
316
|
contractVersion: v.literal("1")
|
|
217
317
|
});
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
return v.parse(createAITokenSchema, input);
|
|
318
|
+
const createServicesTokenSchema = v.object({ workspaceId: v.pipe(v.string(), v.uuid()) });
|
|
319
|
+
function parseCreateServicesToken(input) {
|
|
320
|
+
return v.parse(createServicesTokenSchema, input);
|
|
222
321
|
}
|
|
223
|
-
const
|
|
322
|
+
const servicesTokenSchema = v.object({
|
|
224
323
|
token: v.pipe(v.string(), v.minLength(1)),
|
|
225
324
|
expiresAt: v.pipe(v.string(), v.isoTimestamp())
|
|
226
325
|
});
|
|
227
|
-
/** What
|
|
228
|
-
const
|
|
229
|
-
iss: urlSchema,
|
|
230
|
-
aud: v.literal(
|
|
326
|
+
/** What a service may rely on once a token's signature, issuer, audience, and expiry check. */
|
|
327
|
+
const servicesTokenClaimsSchema = v.object({
|
|
328
|
+
iss: urlSchema$1,
|
|
329
|
+
aud: v.literal(CLOUD_SERVICES_TOKEN_AUDIENCE),
|
|
231
330
|
sub: v.pipe(v.string(), v.minLength(1)),
|
|
232
331
|
workspaceId: v.pipe(v.string(), v.uuid()),
|
|
233
|
-
/**
|
|
234
|
-
|
|
332
|
+
/**
|
|
333
|
+
* The account whose credits the request spends: the workspace's owner, whose allowance every
|
|
334
|
+
* workspace they own shares.
|
|
335
|
+
*/
|
|
336
|
+
accountId: v.pipe(v.string(), v.minLength(1)),
|
|
337
|
+
/** Credits the owner's plan grants each month; `null` when Cloud sets no allowance. */
|
|
338
|
+
monthlyCreditAllowance: v.nullable(creditsSchema$1),
|
|
235
339
|
iat: v.pipe(v.number(), v.integer()),
|
|
236
340
|
exp: v.pipe(v.number(), v.integer())
|
|
237
341
|
});
|
|
238
|
-
const
|
|
342
|
+
const chatModelSchema = v.object({
|
|
239
343
|
id: v.pipe(v.string(), v.minLength(1)),
|
|
240
344
|
label: v.pipe(v.string(), v.minLength(1)),
|
|
241
345
|
/** Credits per million input and output tokens. */
|
|
242
|
-
creditsPerMillionInputTokens: creditsSchema,
|
|
243
|
-
creditsPerMillionOutputTokens: creditsSchema,
|
|
346
|
+
creditsPerMillionInputTokens: creditsSchema$1,
|
|
347
|
+
creditsPerMillionOutputTokens: creditsSchema$1,
|
|
244
348
|
contextTokens: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
245
349
|
capabilities: v.object({
|
|
246
350
|
reasoning: v.boolean(),
|
|
@@ -248,30 +352,33 @@ const aiModelSchema = v.object({
|
|
|
248
352
|
tools: v.boolean()
|
|
249
353
|
})
|
|
250
354
|
});
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
355
|
+
/** What one web search costs; a service without search leaves it out of its catalog. */
|
|
356
|
+
const searchPricingSchema = v.object({ creditsPerRequest: creditsSchema$1 });
|
|
357
|
+
const serviceCatalogSchema = v.object({
|
|
358
|
+
models: v.array(chatModelSchema),
|
|
359
|
+
defaultModelID: v.pipe(v.string(), v.minLength(1)),
|
|
360
|
+
search: v.optional(searchPricingSchema)
|
|
254
361
|
});
|
|
255
|
-
const
|
|
362
|
+
const creditBucketSchema = v.object({
|
|
256
363
|
kind: v.picklist([
|
|
257
364
|
"allowance",
|
|
258
365
|
"purchased",
|
|
259
366
|
"grant"
|
|
260
367
|
]),
|
|
261
|
-
remaining: creditsSchema,
|
|
368
|
+
remaining: creditsSchema$1,
|
|
262
369
|
expiresAt: v.nullable(v.pipe(v.string(), v.isoTimestamp()))
|
|
263
370
|
});
|
|
264
371
|
/**
|
|
265
372
|
* A service records a request's charge before the request's answer ends, so a wallet read after
|
|
266
373
|
* an answer includes what it cost.
|
|
267
374
|
*/
|
|
268
|
-
const
|
|
375
|
+
const creditWalletSchema = v.object({
|
|
269
376
|
/** Credits left to spend; `null` when the service sets no limit. */
|
|
270
|
-
balance: v.nullable(creditsSchema),
|
|
377
|
+
balance: v.nullable(creditsSchema$1),
|
|
271
378
|
/** Spent first to last. */
|
|
272
|
-
buckets: v.array(
|
|
379
|
+
buckets: v.array(creditBucketSchema)
|
|
273
380
|
});
|
|
274
|
-
const
|
|
381
|
+
const usageEntrySchema = v.object({
|
|
275
382
|
id: v.pipe(v.string(), v.minLength(1)),
|
|
276
383
|
createdAt: v.pipe(v.string(), v.isoTimestamp()),
|
|
277
384
|
kind: v.picklist([
|
|
@@ -281,325 +388,233 @@ const aiUsageEntrySchema = v.object({
|
|
|
281
388
|
]),
|
|
282
389
|
modelID: v.nullable(v.string()),
|
|
283
390
|
userId: v.pipe(v.string(), v.minLength(1)),
|
|
284
|
-
credits: creditsSchema
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
391
|
+
credits: creditsSchema$1
|
|
392
|
+
});
|
|
393
|
+
/** The most results one search returns. */
|
|
394
|
+
const MAX_SEARCH_RESULTS = 10;
|
|
395
|
+
/** The longest query a search takes, in characters. */
|
|
396
|
+
const MAX_SEARCH_QUERY_LENGTH = 1e3;
|
|
397
|
+
const searchRequestSchema = v.object({
|
|
398
|
+
query: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(MAX_SEARCH_QUERY_LENGTH)),
|
|
399
|
+
numResults: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(10)), 5)
|
|
400
|
+
});
|
|
401
|
+
function parseSearchRequest(input) {
|
|
402
|
+
return v.parse(searchRequestSchema, input);
|
|
403
|
+
}
|
|
404
|
+
/** One page a search found, with the part of its text that answers the query. */
|
|
405
|
+
const searchResultSchema = v.object({
|
|
406
|
+
url: v.pipe(urlSchema$1, v.regex(/^https?:\/\//i, "A search result links to an HTTP(S) page")),
|
|
407
|
+
title: v.string(),
|
|
408
|
+
publishedAt: v.nullable(v.pipe(v.string(), v.isoTimestamp())),
|
|
409
|
+
author: v.nullable(v.string()),
|
|
410
|
+
text: v.string()
|
|
411
|
+
});
|
|
412
|
+
const searchResponseSchema = v.object({ results: v.array(searchResultSchema) });
|
|
413
|
+
const usageQuerySchema = v.object({ cursor: v.optional(v.pipe(v.string(), v.minLength(1))) });
|
|
414
|
+
function parseUsageQuery(input) {
|
|
415
|
+
return v.parse(usageQuerySchema, input);
|
|
289
416
|
}
|
|
290
|
-
const
|
|
291
|
-
entries: v.array(
|
|
417
|
+
const usagePageSchema = v.object({
|
|
418
|
+
entries: v.array(usageEntrySchema),
|
|
292
419
|
next: v.nullable(v.string())
|
|
293
420
|
});
|
|
294
|
-
/** Errors
|
|
295
|
-
const
|
|
421
|
+
/** Errors a service answers with, beside the upstream provider's own. */
|
|
422
|
+
const serviceErrorCodeSchema = v.picklist([
|
|
423
|
+
"invalid_request",
|
|
296
424
|
"unauthorized",
|
|
297
425
|
"insufficient_credits",
|
|
298
426
|
"model_not_allowed",
|
|
427
|
+
"capability_unavailable",
|
|
299
428
|
"rate_limited"
|
|
300
429
|
]);
|
|
301
|
-
const
|
|
302
|
-
code:
|
|
430
|
+
const serviceErrorSchema = v.object({ error: v.object({
|
|
431
|
+
code: serviceErrorCodeSchema,
|
|
303
432
|
message: v.optional(v.string()),
|
|
304
433
|
/** With `insufficient_credits`: when the workspace's allowance renews, if the service knows. */
|
|
305
434
|
resetsAt: v.optional(v.pipe(v.string(), v.isoTimestamp()))
|
|
306
435
|
}) });
|
|
307
|
-
const
|
|
436
|
+
const SERVICE_ERROR_STATUS = {
|
|
437
|
+
invalid_request: 400,
|
|
308
438
|
unauthorized: 401,
|
|
309
439
|
insufficient_credits: 402,
|
|
310
440
|
model_not_allowed: 403,
|
|
441
|
+
/** A capability, such as search, the service does not offer. */
|
|
442
|
+
capability_unavailable: 404,
|
|
311
443
|
rate_limited: 429
|
|
312
444
|
};
|
|
445
|
+
/**
|
|
446
|
+
* Whether a bearer token may travel to `url`: over HTTPS, or in the clear only to a loopback
|
|
447
|
+
* address, for development. Only literal addresses count, since a name such as `localhost` is
|
|
448
|
+
* whatever the resolver answers. Services and billing tokens act as the account until they expire.
|
|
449
|
+
*/
|
|
450
|
+
function sendsTokenSafely(url) {
|
|
451
|
+
const { protocol, hostname } = new URL(url);
|
|
452
|
+
if (protocol === "https:") return true;
|
|
453
|
+
if (protocol !== "http:") return false;
|
|
454
|
+
return hostname === "[::1]" || /^127(\.\d{1,3}){3}$/.test(hostname);
|
|
455
|
+
}
|
|
313
456
|
//#endregion
|
|
314
|
-
//#region src/contract/
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
/** Who sent it; the name is null once their account is gone. */
|
|
349
|
-
invitedBy: v.object({
|
|
350
|
-
id: v.string(),
|
|
351
|
-
name: v.nullable(v.string())
|
|
352
|
-
}),
|
|
353
|
-
invitedAt: v.string(),
|
|
354
|
-
expiresAt: v.string()
|
|
457
|
+
//#region src/contract/billing.ts
|
|
458
|
+
/**
|
|
459
|
+
* The contract between Cloud, its editors, and the billing service a deployment advertises: what
|
|
460
|
+
* plans and credit packs it sells, and where an account buys them or manages what it has. Cloud
|
|
461
|
+
* only advertises the service and signs short-lived tokens for an account; the service talks to
|
|
462
|
+
* the payment provider, and sets the account's entitlements and credits as it is paid.
|
|
463
|
+
*/
|
|
464
|
+
const CLOUD_BILLING_CONTRACT_VERSION = "1";
|
|
465
|
+
/**
|
|
466
|
+
* The `aud` of the tokens Cloud signs for its billing service, with the services' signing key,
|
|
467
|
+
* whose public keys it publishes at `CLOUD_SERVICES_JWKS_PATH`.
|
|
468
|
+
*/
|
|
469
|
+
const CLOUD_BILLING_TOKEN_AUDIENCE = "openpencil-billing";
|
|
470
|
+
/**
|
|
471
|
+
* The page of a Cloud server where the signed-in person sees their plan, buys a plan or credits,
|
|
472
|
+
* and manages what they pay for; editors link to it whenever the server advertises billing.
|
|
473
|
+
*/
|
|
474
|
+
const CLOUD_ACCOUNT_PLAN_PATH = "/account/plan";
|
|
475
|
+
/** Where the billing service answers, below the discovered `endpoint`. */
|
|
476
|
+
const CLOUD_BILLING_API_PATHS = {
|
|
477
|
+
base: "/v1",
|
|
478
|
+
catalog: "/v1/catalog",
|
|
479
|
+
account: "/v1/account",
|
|
480
|
+
checkout: "/v1/checkout",
|
|
481
|
+
portal: "/v1/portal"
|
|
482
|
+
};
|
|
483
|
+
const urlSchema = v.pipe(v.string(), v.url());
|
|
484
|
+
const idSchema = v.pipe(v.string(), v.regex(/^[a-z0-9][a-z0-9-]{0,62}$/));
|
|
485
|
+
const centsSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
486
|
+
const bytesSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
487
|
+
const creditsSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
488
|
+
const cloudBillingDiscoverySchema = v.object({
|
|
489
|
+
endpoint: urlSchema,
|
|
490
|
+
contractVersion: v.literal("1")
|
|
355
491
|
});
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
invitations: v.array(workspaceInvitationSchema)
|
|
492
|
+
const billingTokenSchema = v.object({
|
|
493
|
+
token: v.pipe(v.string(), v.minLength(1)),
|
|
494
|
+
expiresAt: v.pipe(v.string(), v.isoTimestamp())
|
|
360
495
|
});
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
496
|
+
/**
|
|
497
|
+
* What the billing service may rely on once a token's signature, issuer, audience, and expiry
|
|
498
|
+
* check. The account is the signed-in user, who buys and manages only their own plan.
|
|
499
|
+
*/
|
|
500
|
+
const billingTokenClaimsSchema = v.object({
|
|
501
|
+
iss: urlSchema,
|
|
502
|
+
aud: v.literal(CLOUD_BILLING_TOKEN_AUDIENCE),
|
|
503
|
+
/** The account: the Cloud user whose plan and credits these are. */
|
|
504
|
+
sub: v.pipe(v.string(), v.minLength(1)),
|
|
505
|
+
/** Where the payment provider sends receipts and invoices. */
|
|
506
|
+
email: v.pipe(v.string(), v.email()),
|
|
507
|
+
iat: v.pipe(v.number(), v.integer()),
|
|
508
|
+
exp: v.pipe(v.number(), v.integer())
|
|
364
509
|
});
|
|
365
|
-
/** A
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
510
|
+
/** A plan an account subscribes to, billed every month in US dollars before tax. */
|
|
511
|
+
const billingPlanSchema = v.object({
|
|
512
|
+
id: idSchema,
|
|
513
|
+
name: v.pipe(v.string(), v.minLength(1)),
|
|
514
|
+
monthlyPriceCents: centsSchema,
|
|
515
|
+
storageBytes: bytesSchema,
|
|
516
|
+
monthlyCredits: creditsSchema
|
|
517
|
+
});
|
|
518
|
+
/** Credits an account on a plan buys once, in US dollars before tax. */
|
|
519
|
+
const creditPackSchema = v.object({
|
|
520
|
+
id: idSchema,
|
|
521
|
+
credits: creditsSchema,
|
|
522
|
+
priceCents: centsSchema,
|
|
523
|
+
/** How long the credits last from purchase. */
|
|
524
|
+
validDays: v.pipe(v.number(), v.integer(), v.minValue(1))
|
|
525
|
+
});
|
|
526
|
+
/** What the service sells; an account without a plan has its deployment's free entitlements. */
|
|
527
|
+
const billingCatalogSchema = v.object({
|
|
528
|
+
plans: v.array(billingPlanSchema),
|
|
529
|
+
creditPacks: v.array(creditPackSchema)
|
|
369
530
|
});
|
|
370
|
-
const updateWorkspaceMemberSchema = v.object({ role: workspaceRoleSchema });
|
|
371
|
-
function parseCreateWorkspace(input) {
|
|
372
|
-
return v.parse(createWorkspaceSchema, input);
|
|
373
|
-
}
|
|
374
|
-
function parseUpdateWorkspace(input) {
|
|
375
|
-
return v.parse(updateWorkspaceSchema, input);
|
|
376
|
-
}
|
|
377
|
-
function parseCreateWorkspaceInvitation(input) {
|
|
378
|
-
return v.parse(createWorkspaceInvitationSchema, input);
|
|
379
|
-
}
|
|
380
|
-
function parseUpdateWorkspaceMember(input) {
|
|
381
|
-
return v.parse(updateWorkspaceMemberSchema, input);
|
|
382
|
-
}
|
|
383
|
-
//#endregion
|
|
384
|
-
//#region src/contract/admin/index.ts
|
|
385
|
-
const timestampSchema = v.pipe(v.string(), v.isoTimestamp());
|
|
386
|
-
const nullableTimestampSchema = v.nullable(timestampSchema);
|
|
387
|
-
const countSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
388
531
|
/**
|
|
389
|
-
*
|
|
390
|
-
*
|
|
532
|
+
* The account's subscription as the payment provider holds it, or `null` without one. A
|
|
533
|
+
* `past_due` plan keeps its entitlements while payment is retried.
|
|
391
534
|
*/
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
535
|
+
const billingAccountSchema = v.object({ subscription: v.nullable(v.object({
|
|
536
|
+
planId: idSchema,
|
|
537
|
+
status: v.picklist(["active", "past_due"]),
|
|
538
|
+
/** When the current period ends: the next charge, or the end of a cancelled plan. */
|
|
539
|
+
currentPeriodEnd: v.pipe(v.string(), v.isoTimestamp()),
|
|
540
|
+
/** Whether the plan ends at `currentPeriodEnd` instead of renewing. */
|
|
541
|
+
cancelsAtPeriodEnd: v.boolean()
|
|
542
|
+
})) });
|
|
543
|
+
/** What to buy: a plan to subscribe to, or a credit pack. */
|
|
544
|
+
const checkoutRequestSchema = v.union([v.object({ planId: idSchema }), v.object({ creditPackId: idSchema })]);
|
|
545
|
+
/** Where to send the person: the payment provider's checkout or account portal. */
|
|
546
|
+
const billingRedirectSchema = v.object({ url: v.pipe(urlSchema, v.regex(/^https:\/\//i, "Billing sends people to an HTTPS page")) });
|
|
547
|
+
const billingErrorCodeSchema = v.picklist([
|
|
548
|
+
"invalid_request",
|
|
400
549
|
"unauthorized",
|
|
401
|
-
"
|
|
402
|
-
"
|
|
403
|
-
"rate_limited",
|
|
404
|
-
"invalid_enrollment_transition",
|
|
405
|
-
"last_admin_required",
|
|
406
|
-
"self_admin_action_forbidden",
|
|
407
|
-
"email_regeneration_unavailable",
|
|
408
|
-
"mfa_required"
|
|
550
|
+
"not_allowed",
|
|
551
|
+
"provider_unavailable"
|
|
409
552
|
]);
|
|
410
|
-
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
553
|
+
/** The HTTP status billing answers each error with. */
|
|
554
|
+
const BILLING_ERROR_STATUS = {
|
|
555
|
+
invalid_request: 400,
|
|
556
|
+
unauthorized: 401,
|
|
557
|
+
not_allowed: 409,
|
|
558
|
+
provider_unavailable: 502
|
|
559
|
+
};
|
|
560
|
+
const billingErrorSchema = v.object({ error: v.object({
|
|
561
|
+
code: billingErrorCodeSchema,
|
|
562
|
+
message: v.optional(v.string())
|
|
563
|
+
}) });
|
|
564
|
+
//#endregion
|
|
565
|
+
//#region src/contract/documents.ts
|
|
566
|
+
const CLOUD_PROTOCOL_MAX_UPLOAD_BYTES = 1073741824;
|
|
567
|
+
const checksumSchema = v.pipe(v.string(), v.regex(/^[A-Za-z0-9+/]{43}=$/));
|
|
568
|
+
/** Whether a value is a SHA-256 checksum as the server names stored objects, base64 encoded. */
|
|
569
|
+
function isCloudChecksum(value) {
|
|
570
|
+
return v.is(checksumSchema, value);
|
|
571
|
+
}
|
|
572
|
+
/** The most images one revision, or one request for image uploads, may name. */
|
|
573
|
+
const CLOUD_MAX_DOCUMENT_IMAGES = 1e4;
|
|
574
|
+
/**
|
|
575
|
+
* The most a Cloud API request body may hold; a server refuses anything past it before reading
|
|
576
|
+
* it. Files go to the object store, never through the API, so only lists grow large: a save's
|
|
577
|
+
* images fit with room to spare, and a client commits image uploads, whose part lists can run
|
|
578
|
+
* long, in batches under half of it.
|
|
579
|
+
*/
|
|
580
|
+
const CLOUD_API_MAX_BODY_BYTES = 8388608;
|
|
581
|
+
/**
|
|
582
|
+
* An image's name inside a `.fig` file that Cloud stores apart from it: the SHA-1 Figma names it
|
|
583
|
+
* by, or an older plain name. A client leaves images under other names inside the file.
|
|
584
|
+
*/
|
|
585
|
+
const CLOUD_IMAGE_NAME_PATTERN = /^[A-Za-z0-9._-]{1,128}$/;
|
|
586
|
+
const imageNameSchema = v.pipe(v.string(), v.regex(CLOUD_IMAGE_NAME_PATTERN));
|
|
587
|
+
const objectDownloadSchema = v.object({
|
|
588
|
+
url: v.pipe(v.string(), v.url()),
|
|
589
|
+
method: v.literal("GET"),
|
|
590
|
+
headers: v.record(v.string(), v.string()),
|
|
591
|
+
expiresAt: v.string()
|
|
431
592
|
});
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
593
|
+
/** An image a stored revision uses, where to download it, and what to check it against. */
|
|
594
|
+
const documentImageDownloadSchema = v.object({
|
|
595
|
+
name: imageNameSchema,
|
|
596
|
+
checksum: checksumSchema,
|
|
597
|
+
byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
598
|
+
download: objectDownloadSchema
|
|
435
599
|
});
|
|
436
|
-
|
|
437
|
-
const
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
banned: v.nullable(v.boolean()),
|
|
442
|
-
banReason: v.optional(v.nullable(v.string())),
|
|
443
|
-
createdAt: timestampSchema,
|
|
444
|
-
/** An authenticator app or a passkey confirms this account's sign-ins. */
|
|
445
|
-
twoStep: v.boolean(),
|
|
446
|
-
/** When one of the account's sessions was last used, or null when none is left. */
|
|
447
|
-
lastActiveAt: nullableTimestampSchema,
|
|
448
|
-
workspaceCount: countSchema
|
|
600
|
+
/** Where to download an image a document uses, found by its checksum. */
|
|
601
|
+
const documentImageLinkSchema = v.object({
|
|
602
|
+
checksum: checksumSchema,
|
|
603
|
+
byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
604
|
+
download: objectDownloadSchema
|
|
449
605
|
});
|
|
450
|
-
/**
|
|
451
|
-
const
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
"
|
|
455
|
-
"
|
|
606
|
+
/** The images a live room names, by checksum, that a peer needs links for. */
|
|
607
|
+
const requestImageLinksSchema = v.object({ checksums: v.pipe(v.array(checksumSchema), v.minLength(1), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)) });
|
|
608
|
+
const documentPermissionSchema = v.picklist(["view", "edit"]);
|
|
609
|
+
const documentAccessSourceSchema = v.picklist([
|
|
610
|
+
"owner",
|
|
611
|
+
"workspace",
|
|
612
|
+
"direct-grant"
|
|
456
613
|
]);
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
const cloudAdminUserDetailSchema = v.object({
|
|
462
|
-
user: v.object({
|
|
463
|
-
...cloudAdminUserSchema.entries,
|
|
464
|
-
emailVerified: v.boolean()
|
|
465
|
-
}),
|
|
466
|
-
methods: v.array(v.object({
|
|
467
|
-
provider: v.string(),
|
|
468
|
-
createdAt: timestampSchema
|
|
469
|
-
})),
|
|
470
|
-
authenticator: v.boolean(),
|
|
471
|
-
passkeyCount: countSchema,
|
|
472
|
-
sessions: v.array(cloudAccountSessionSchema),
|
|
473
|
-
signIns: v.array(cloudSignInSchema),
|
|
474
|
-
workspaces: v.array(v.object({
|
|
475
|
-
id: v.string(),
|
|
476
|
-
name: v.string(),
|
|
477
|
-
role: workspaceRoleSchema,
|
|
478
|
-
memberCount: countSchema,
|
|
479
|
-
joinedAt: timestampSchema
|
|
480
|
-
}))
|
|
481
|
-
});
|
|
482
|
-
const adminMutationResponseSchema = v.object({ ok: v.literal(true) });
|
|
483
|
-
const transactionalEmailAdminSchema = v.object({
|
|
484
|
-
id: v.string(),
|
|
485
|
-
kind: v.string(),
|
|
486
|
-
recipientEmailNormalized: v.pipe(v.string(), v.email()),
|
|
487
|
-
status: v.string(),
|
|
488
|
-
attemptCount: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
489
|
-
nextAttemptAt: timestampSchema,
|
|
490
|
-
transport: v.nullable(v.string()),
|
|
491
|
-
transportMessageId: v.nullable(v.string()),
|
|
492
|
-
lastErrorCode: v.nullable(v.string()),
|
|
493
|
-
createdAt: timestampSchema,
|
|
494
|
-
acceptedAt: nullableTimestampSchema,
|
|
495
|
-
regeneratable: v.boolean()
|
|
496
|
-
});
|
|
497
|
-
/** Which messages a list of email shows, by how their delivery went. */
|
|
498
|
-
const cloudAdminEmailFilterSchema = v.picklist([
|
|
499
|
-
"all",
|
|
500
|
-
"sent",
|
|
501
|
-
"waiting",
|
|
502
|
-
"failed"
|
|
503
|
-
]);
|
|
504
|
-
const adminEmailResponseSchema = v.object({
|
|
505
|
-
messages: v.array(transactionalEmailAdminSchema),
|
|
506
|
-
...listTotals(cloudAdminEmailFilterSchema.options)
|
|
507
|
-
});
|
|
508
|
-
/** Who or what an event names; `name` is null once the server no longer knows it. */
|
|
509
|
-
const auditPartySchema = v.object({
|
|
510
|
-
id: v.string(),
|
|
511
|
-
name: v.nullable(v.string())
|
|
512
|
-
});
|
|
513
|
-
const adminAuditEventSchema = v.object({
|
|
514
|
-
id: v.string(),
|
|
515
|
-
actor: auditPartySchema,
|
|
516
|
-
action: v.string(),
|
|
517
|
-
/** What the event is about: an account, an access request, or an email. */
|
|
518
|
-
subject: v.object({
|
|
519
|
-
...auditPartySchema.entries,
|
|
520
|
-
type: v.string()
|
|
521
|
-
}),
|
|
522
|
-
metadata: v.unknown(),
|
|
523
|
-
createdAt: timestampSchema
|
|
524
|
-
});
|
|
525
|
-
/** Which events a list of activity shows, by what they are about. */
|
|
526
|
-
const cloudAdminAuditFilterSchema = v.picklist([
|
|
527
|
-
"all",
|
|
528
|
-
"accounts",
|
|
529
|
-
"requests",
|
|
530
|
-
"email"
|
|
531
|
-
]);
|
|
532
|
-
const adminAuditResponseSchema = v.object({
|
|
533
|
-
events: v.array(adminAuditEventSchema),
|
|
534
|
-
...listTotals(cloudAdminAuditFilterSchema.options)
|
|
535
|
-
});
|
|
536
|
-
const adminOperationsResponseSchema = v.object({
|
|
537
|
-
deployment: v.picklist(["official", "self-hosted"]),
|
|
538
|
-
enrollmentMode: v.picklist([
|
|
539
|
-
"open",
|
|
540
|
-
"approval",
|
|
541
|
-
"closed"
|
|
542
|
-
]),
|
|
543
|
-
emailTransport: v.picklist([
|
|
544
|
-
"none",
|
|
545
|
-
"smtp",
|
|
546
|
-
"cloudflare"
|
|
547
|
-
]),
|
|
548
|
-
pendingEnrollment: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
549
|
-
pendingEmail: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
550
|
-
failedEmail: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
551
|
-
accounts: countSchema,
|
|
552
|
-
workspaces: countSchema,
|
|
553
|
-
documents: countSchema,
|
|
554
|
-
storedBytes: countSchema
|
|
555
|
-
});
|
|
556
|
-
//#endregion
|
|
557
|
-
//#region src/contract/documents.ts
|
|
558
|
-
const CLOUD_PROTOCOL_MAX_UPLOAD_BYTES = 1073741824;
|
|
559
|
-
const checksumSchema = v.pipe(v.string(), v.regex(/^[A-Za-z0-9+/]{43}=$/));
|
|
560
|
-
/** Whether a value is a SHA-256 checksum as the server names stored objects, base64 encoded. */
|
|
561
|
-
function isCloudChecksum(value) {
|
|
562
|
-
return v.is(checksumSchema, value);
|
|
563
|
-
}
|
|
564
|
-
/** The most images one revision, or one request for image uploads, may name. */
|
|
565
|
-
const CLOUD_MAX_DOCUMENT_IMAGES = 1e4;
|
|
566
|
-
/**
|
|
567
|
-
* An image's name inside a `.fig` file that Cloud stores apart from it: the SHA-1 Figma names it
|
|
568
|
-
* by, or an older plain name. A client leaves images under other names inside the file.
|
|
569
|
-
*/
|
|
570
|
-
const CLOUD_IMAGE_NAME_PATTERN = /^[A-Za-z0-9._-]{1,128}$/;
|
|
571
|
-
const imageNameSchema = v.pipe(v.string(), v.regex(CLOUD_IMAGE_NAME_PATTERN));
|
|
572
|
-
const objectDownloadSchema = v.object({
|
|
573
|
-
url: v.pipe(v.string(), v.url()),
|
|
574
|
-
method: v.literal("GET"),
|
|
575
|
-
headers: v.record(v.string(), v.string()),
|
|
576
|
-
expiresAt: v.string()
|
|
577
|
-
});
|
|
578
|
-
/** An image a stored revision uses, where to download it, and what to check it against. */
|
|
579
|
-
const documentImageDownloadSchema = v.object({
|
|
580
|
-
name: imageNameSchema,
|
|
581
|
-
checksum: checksumSchema,
|
|
582
|
-
byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
583
|
-
download: objectDownloadSchema
|
|
584
|
-
});
|
|
585
|
-
/** Where to download an image a document uses, found by its checksum. */
|
|
586
|
-
const documentImageLinkSchema = v.object({
|
|
587
|
-
checksum: checksumSchema,
|
|
588
|
-
byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
589
|
-
download: objectDownloadSchema
|
|
590
|
-
});
|
|
591
|
-
/** The images a live room names, by checksum, that a peer needs links for. */
|
|
592
|
-
const requestImageLinksSchema = v.object({ checksums: v.pipe(v.array(checksumSchema), v.minLength(1), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)) });
|
|
593
|
-
const documentPermissionSchema = v.picklist(["view", "edit"]);
|
|
594
|
-
const documentAccessSourceSchema = v.picklist([
|
|
595
|
-
"owner",
|
|
596
|
-
"workspace",
|
|
597
|
-
"direct-grant"
|
|
598
|
-
]);
|
|
599
|
-
const documentAccessSchema = v.object({
|
|
600
|
-
permission: documentPermissionSchema,
|
|
601
|
-
canManageSharing: v.boolean(),
|
|
602
|
-
sources: v.array(documentAccessSourceSchema)
|
|
614
|
+
const documentAccessSchema = v.object({
|
|
615
|
+
permission: documentPermissionSchema,
|
|
616
|
+
canManageSharing: v.boolean(),
|
|
617
|
+
sources: v.array(documentAccessSourceSchema)
|
|
603
618
|
});
|
|
604
619
|
/** What a document is: a Figma design or a FigJam board, which the file it stores says too. */
|
|
605
620
|
const documentKindSchema = v.picklist(["design", "board"]);
|
|
@@ -622,6 +637,22 @@ const sharedDocumentSchema = v.object({
|
|
|
622
637
|
sharedBy: v.nullable(v.object({ name: v.string() })),
|
|
623
638
|
sharedAt: v.string()
|
|
624
639
|
});
|
|
640
|
+
/**
|
|
641
|
+
* A document in Trash the person may restore: who deleted it and when, and when it goes for good.
|
|
642
|
+
* `canPurge` says whether they may also delete it for good before then.
|
|
643
|
+
*/
|
|
644
|
+
const trashedDocumentSchema = v.object({
|
|
645
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
646
|
+
workspaceId: v.pipe(v.string(), v.uuid()),
|
|
647
|
+
workspaceName: v.string(),
|
|
648
|
+
name: v.string(),
|
|
649
|
+
kind: v.optional(documentKindSchema, "design"),
|
|
650
|
+
deletedAt: v.string(),
|
|
651
|
+
deletedBy: v.nullable(v.object({ name: v.string() })),
|
|
652
|
+
purgeAt: v.string(),
|
|
653
|
+
canPurge: v.boolean()
|
|
654
|
+
});
|
|
655
|
+
const trashSchema = v.object({ documents: v.array(trashedDocumentSchema) });
|
|
625
656
|
const documentDownloadSchema = v.object({
|
|
626
657
|
document: documentSummarySchema,
|
|
627
658
|
revisionId: v.pipe(v.string(), v.uuid()),
|
|
@@ -751,20 +782,509 @@ const cloudPresenceSchema = v.object({
|
|
|
751
782
|
kind: v.picklist(["user", "guest"]),
|
|
752
783
|
id: v.string(),
|
|
753
784
|
name: v.string(),
|
|
754
|
-
permission: documentPermissionSchema
|
|
785
|
+
permission: documentPermissionSchema
|
|
786
|
+
});
|
|
787
|
+
const collaborationTicketSchema = v.object({
|
|
788
|
+
token: v.string(),
|
|
789
|
+
provider: v.optional(v.picklist(["trystero", "relay"])),
|
|
790
|
+
serverURL: v.optional(v.pipe(v.string(), v.url())),
|
|
791
|
+
documentId: v.pipe(v.string(), v.uuid()),
|
|
792
|
+
roomId: v.string(),
|
|
793
|
+
roomKey: v.pipe(v.string(), v.minLength(43), v.maxLength(128)),
|
|
794
|
+
principal: collaborationPrincipalSchema,
|
|
795
|
+
permission: documentPermissionSchema,
|
|
796
|
+
/**
|
|
797
|
+
* Why a peer whose access would let them edit may only view: `storage-limit` when the document's
|
|
798
|
+
* owner holds their whole storage allowance, until they free space or their plan grows.
|
|
799
|
+
*/
|
|
800
|
+
readOnly: v.optional(v.picklist(["storage-limit"])),
|
|
801
|
+
roomEpoch: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
802
|
+
expiresAt: v.string(),
|
|
803
|
+
serverEnforcedWrites: v.boolean(),
|
|
804
|
+
/**
|
|
805
|
+
* Whether the relay answers `RELAY_HEARTBEAT`. A relay from before it takes a ping for a
|
|
806
|
+
* malformed frame and turns the peer away, so editors ask only a relay that says it answers.
|
|
807
|
+
*/
|
|
808
|
+
relayHeartbeat: v.optional(v.boolean(), false)
|
|
809
|
+
});
|
|
810
|
+
//#endregion
|
|
811
|
+
//#region src/contract/workspaces.ts
|
|
812
|
+
const workspaceRoleSchema = v.picklist([
|
|
813
|
+
"viewer",
|
|
814
|
+
"editor",
|
|
815
|
+
"admin"
|
|
816
|
+
]);
|
|
817
|
+
const workspaceSummarySchema = v.object({
|
|
818
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
819
|
+
name: v.string(),
|
|
820
|
+
slug: v.string(),
|
|
821
|
+
role: workspaceRoleSchema,
|
|
822
|
+
createdAt: v.string(),
|
|
823
|
+
updatedAt: v.string()
|
|
824
|
+
});
|
|
825
|
+
const createWorkspaceSchema = v.object({
|
|
826
|
+
name: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(100)),
|
|
827
|
+
slug: v.optional(v.pipe(v.string(), v.trim(), v.minLength(3), v.maxLength(63), v.regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/)))
|
|
828
|
+
});
|
|
829
|
+
const workspaceListSchema = v.object({ workspaces: v.array(workspaceSummarySchema) });
|
|
830
|
+
const updateWorkspaceSchema = v.object({ name: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(100)) });
|
|
831
|
+
/** Someone who belongs to a workspace, and what they may do in it. */
|
|
832
|
+
const workspaceMemberSchema = v.object({
|
|
833
|
+
userId: v.string(),
|
|
834
|
+
name: v.string(),
|
|
835
|
+
email: v.string(),
|
|
836
|
+
image: v.nullable(v.string()),
|
|
837
|
+
role: workspaceRoleSchema,
|
|
838
|
+
joinedAt: v.string()
|
|
839
|
+
});
|
|
840
|
+
/** An invitation to join a workspace that has not been accepted yet. */
|
|
841
|
+
const workspaceInvitationSchema = v.object({
|
|
842
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
843
|
+
email: v.string(),
|
|
844
|
+
role: workspaceRoleSchema,
|
|
845
|
+
/** Who sent it; the name is null once their account is gone. */
|
|
846
|
+
invitedBy: v.object({
|
|
847
|
+
id: v.string(),
|
|
848
|
+
name: v.nullable(v.string())
|
|
849
|
+
}),
|
|
850
|
+
invitedAt: v.string(),
|
|
851
|
+
expiresAt: v.string()
|
|
852
|
+
});
|
|
853
|
+
const workspaceMembersSchema = v.object({
|
|
854
|
+
members: v.array(workspaceMemberSchema),
|
|
855
|
+
/** Only administrators see pending invitations. */
|
|
856
|
+
invitations: v.array(workspaceInvitationSchema)
|
|
857
|
+
});
|
|
858
|
+
const createWorkspaceInvitationSchema = v.object({
|
|
859
|
+
email: v.pipe(v.string(), v.trim(), v.toLowerCase(), v.email()),
|
|
860
|
+
role: workspaceRoleSchema
|
|
861
|
+
});
|
|
862
|
+
/** A new invitation and its link, for an administrator to pass on when email is off. */
|
|
863
|
+
const createdWorkspaceInvitationSchema = v.object({
|
|
864
|
+
invitation: workspaceInvitationSchema,
|
|
865
|
+
acceptanceURL: v.string()
|
|
866
|
+
});
|
|
867
|
+
const updateWorkspaceMemberSchema = v.object({ role: workspaceRoleSchema });
|
|
868
|
+
function parseCreateWorkspace(input) {
|
|
869
|
+
return v.parse(createWorkspaceSchema, input);
|
|
870
|
+
}
|
|
871
|
+
function parseUpdateWorkspace(input) {
|
|
872
|
+
return v.parse(updateWorkspaceSchema, input);
|
|
873
|
+
}
|
|
874
|
+
function parseCreateWorkspaceInvitation(input) {
|
|
875
|
+
return v.parse(createWorkspaceInvitationSchema, input);
|
|
876
|
+
}
|
|
877
|
+
function parseUpdateWorkspaceMember(input) {
|
|
878
|
+
return v.parse(updateWorkspaceMemberSchema, input);
|
|
879
|
+
}
|
|
880
|
+
//#endregion
|
|
881
|
+
//#region src/contract/sharing.ts
|
|
882
|
+
const documentShareSchema = v.object({
|
|
883
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
884
|
+
documentId: v.pipe(v.string(), v.uuid()),
|
|
885
|
+
permission: documentPermissionSchema,
|
|
886
|
+
roomEpoch: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
887
|
+
createdBy: v.string(),
|
|
888
|
+
createdAt: v.string(),
|
|
889
|
+
updatedAt: v.string(),
|
|
890
|
+
expiresAt: v.nullable(v.string()),
|
|
891
|
+
revokedAt: v.nullable(v.string()),
|
|
892
|
+
lastUsedAt: v.nullable(v.string())
|
|
893
|
+
});
|
|
894
|
+
/** When a link stops working, as an ISO timestamp; `null` keeps it working until revoked. */
|
|
895
|
+
const shareExpirySchema = v.optional(v.nullable(v.pipe(v.string(), v.isoTimestamp())));
|
|
896
|
+
const createDocumentShareSchema = v.object({
|
|
897
|
+
permission: documentPermissionSchema,
|
|
898
|
+
expiresAt: shareExpirySchema
|
|
899
|
+
});
|
|
900
|
+
const updateDocumentShareSchema = v.object({
|
|
901
|
+
permission: v.optional(documentPermissionSchema),
|
|
902
|
+
expiresAt: shareExpirySchema
|
|
903
|
+
});
|
|
904
|
+
const resolveDocumentShareSchema = v.object({
|
|
905
|
+
secret: v.pipe(v.string(), v.minLength(32), v.maxLength(128)),
|
|
906
|
+
guestName: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(80))),
|
|
907
|
+
guestId: v.optional(v.pipe(v.string(), v.minLength(16), v.maxLength(128)))
|
|
908
|
+
});
|
|
909
|
+
/** A guest's request for the links of images a shared document's live room names. */
|
|
910
|
+
const requestSharedImageLinksSchema = v.object({
|
|
911
|
+
...resolveDocumentShareSchema.entries,
|
|
912
|
+
...requestImageLinksSchema.entries
|
|
913
|
+
});
|
|
914
|
+
function parseRequestSharedImageLinks(input) {
|
|
915
|
+
return v.parse(requestSharedImageLinksSchema, input);
|
|
916
|
+
}
|
|
917
|
+
const resolvedDocumentShareSchema = v.object({
|
|
918
|
+
documentId: v.pipe(v.string(), v.uuid()),
|
|
919
|
+
/** What this person may do; a guest on an edit link may only view where guests may not edit. */
|
|
920
|
+
permission: documentPermissionSchema,
|
|
921
|
+
/** What the link lets someone signed in to the server do. */
|
|
922
|
+
linkPermission: documentPermissionSchema,
|
|
923
|
+
principal: collaborationPrincipalSchema,
|
|
924
|
+
roomEpoch: v.pipe(v.number(), v.integer(), v.minValue(0))
|
|
925
|
+
});
|
|
926
|
+
const cloudUserProfileSchema = v.object({
|
|
927
|
+
id: v.string(),
|
|
928
|
+
name: v.string(),
|
|
929
|
+
email: v.pipe(v.string(), v.email()),
|
|
930
|
+
image: v.nullable(v.pipe(v.string(), v.url()))
|
|
931
|
+
});
|
|
932
|
+
const documentGrantSchema = v.object({
|
|
933
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
934
|
+
documentId: v.pipe(v.string(), v.uuid()),
|
|
935
|
+
userId: v.string(),
|
|
936
|
+
permission: documentPermissionSchema,
|
|
937
|
+
createdBy: v.string(),
|
|
938
|
+
createdAt: v.string(),
|
|
939
|
+
updatedAt: v.string()
|
|
940
|
+
});
|
|
941
|
+
/** What accepting an invitation gave: access to a document, or a place in a workspace. */
|
|
942
|
+
const acceptedInvitationSchema = v.variant("kind", [v.object({
|
|
943
|
+
kind: v.literal("document"),
|
|
944
|
+
grant: documentGrantSchema
|
|
945
|
+
}), v.object({
|
|
946
|
+
kind: v.literal("workspace"),
|
|
947
|
+
workspaceId: v.pipe(v.string(), v.uuid()),
|
|
948
|
+
role: workspaceRoleSchema
|
|
949
|
+
})]);
|
|
950
|
+
const putDocumentGrantSchema = v.object({ permission: documentPermissionSchema });
|
|
951
|
+
const createDocumentInvitationSchema = v.object({
|
|
952
|
+
email: v.pipe(v.string(), v.trim(), v.toLowerCase(), v.email()),
|
|
953
|
+
permission: documentPermissionSchema
|
|
954
|
+
});
|
|
955
|
+
const acceptDocumentInvitationSchema = v.object({ token: v.pipe(v.string(), v.minLength(32), v.maxLength(128)) });
|
|
956
|
+
const createInvitationContinuationSchema = v.object({
|
|
957
|
+
invitationId: v.pipe(v.string(), v.uuid()),
|
|
958
|
+
token: v.pipe(v.string(), v.minLength(32), v.maxLength(128))
|
|
959
|
+
});
|
|
960
|
+
const invitationContinuationSchema = v.object({ id: v.pipe(v.string(), v.minLength(16), v.maxLength(128)) });
|
|
961
|
+
const invitationPreviewFields = {
|
|
962
|
+
inviterName: v.string(),
|
|
963
|
+
expiresAt: v.string(),
|
|
964
|
+
recipientHint: v.string()
|
|
965
|
+
};
|
|
966
|
+
/** What an invitation link opens: one document, or a whole workspace. */
|
|
967
|
+
const invitationPreviewSchema = v.variant("kind", [v.object({
|
|
968
|
+
kind: v.literal("document"),
|
|
969
|
+
documentName: v.string(),
|
|
970
|
+
permission: documentPermissionSchema,
|
|
971
|
+
...invitationPreviewFields
|
|
972
|
+
}), v.object({
|
|
973
|
+
kind: v.literal("workspace"),
|
|
974
|
+
workspaceName: v.string(),
|
|
975
|
+
role: workspaceRoleSchema,
|
|
976
|
+
...invitationPreviewFields
|
|
977
|
+
})]);
|
|
978
|
+
const documentInvitationSchema = v.object({
|
|
979
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
980
|
+
documentId: v.pipe(v.string(), v.uuid()),
|
|
981
|
+
email: v.pipe(v.string(), v.email()),
|
|
982
|
+
permission: documentPermissionSchema,
|
|
983
|
+
invitedBy: v.string(),
|
|
984
|
+
invitedAt: v.string(),
|
|
985
|
+
expiresAt: v.string(),
|
|
986
|
+
acceptedAt: v.nullable(v.string())
|
|
987
|
+
});
|
|
988
|
+
function parseCreateInvitationContinuation(input) {
|
|
989
|
+
return v.parse(createInvitationContinuationSchema, input);
|
|
990
|
+
}
|
|
991
|
+
function parseCreateDocumentShare(input) {
|
|
992
|
+
return v.parse(createDocumentShareSchema, input);
|
|
993
|
+
}
|
|
994
|
+
function parseUpdateDocumentShare(input) {
|
|
995
|
+
return v.parse(updateDocumentShareSchema, input);
|
|
996
|
+
}
|
|
997
|
+
function parseResolveDocumentShare(input) {
|
|
998
|
+
return v.parse(resolveDocumentShareSchema, input);
|
|
999
|
+
}
|
|
1000
|
+
function parsePutDocumentGrant(input) {
|
|
1001
|
+
return v.parse(putDocumentGrantSchema, input);
|
|
1002
|
+
}
|
|
1003
|
+
function parseCreateDocumentInvitation(input) {
|
|
1004
|
+
return v.parse(createDocumentInvitationSchema, input);
|
|
1005
|
+
}
|
|
1006
|
+
function parseAcceptDocumentInvitation(input) {
|
|
1007
|
+
return v.parse(acceptDocumentInvitationSchema, input);
|
|
1008
|
+
}
|
|
1009
|
+
//#endregion
|
|
1010
|
+
//#region src/contract/reports.ts
|
|
1011
|
+
/** Why someone reports a document shared with them. */
|
|
1012
|
+
const documentReportReasonSchema = v.picklist([
|
|
1013
|
+
"spam-phishing",
|
|
1014
|
+
"illegal",
|
|
1015
|
+
"copyright",
|
|
1016
|
+
"harassment",
|
|
1017
|
+
"other"
|
|
1018
|
+
]);
|
|
1019
|
+
/** How long a report's description may be. */
|
|
1020
|
+
const DOCUMENT_REPORT_DESCRIPTION_MAX = 2e3;
|
|
1021
|
+
/**
|
|
1022
|
+
* A report about a document someone opened from a share link: the link's secret proves they can
|
|
1023
|
+
* see it, as resolving the link does, and a guest names themselves as they do there.
|
|
1024
|
+
*/
|
|
1025
|
+
const fileDocumentReportSchema = v.object({
|
|
1026
|
+
secret: resolveDocumentShareSchema.entries.secret,
|
|
1027
|
+
guestId: resolveDocumentShareSchema.entries.guestId,
|
|
1028
|
+
reason: documentReportReasonSchema,
|
|
1029
|
+
description: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(DOCUMENT_REPORT_DESCRIPTION_MAX)),
|
|
1030
|
+
/** Where an administrator may answer; optional, and never shown to the document's people. */
|
|
1031
|
+
replyEmail: v.optional(v.pipe(v.string(), v.trim(), v.toLowerCase(), v.email(), v.maxLength(254)))
|
|
1032
|
+
});
|
|
1033
|
+
function parseFileDocumentReport(input) {
|
|
1034
|
+
return v.parse(fileDocumentReportSchema, input);
|
|
1035
|
+
}
|
|
1036
|
+
/** What filing a report answers: that it arrived, and nothing about the document. */
|
|
1037
|
+
const fileDocumentReportResponseSchema = v.object({ received: v.literal(true) });
|
|
1038
|
+
//#endregion
|
|
1039
|
+
//#region src/contract/admin/index.ts
|
|
1040
|
+
const timestampSchema = v.pipe(v.string(), v.isoTimestamp());
|
|
1041
|
+
const nullableTimestampSchema = v.nullable(timestampSchema);
|
|
1042
|
+
const countSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
1043
|
+
/**
|
|
1044
|
+
* What every admin list answers besides its rows: how many rows match the search and filter
|
|
1045
|
+
* across every page, and how many match the search under each filter.
|
|
1046
|
+
*/
|
|
1047
|
+
function listTotals(filters) {
|
|
1048
|
+
return {
|
|
1049
|
+
total: countSchema,
|
|
1050
|
+
counts: v.object(zipObject(filters, filters.map(() => countSchema)))
|
|
1051
|
+
};
|
|
1052
|
+
}
|
|
1053
|
+
const adminErrorCodeSchema = v.picklist([
|
|
1054
|
+
"bad_request",
|
|
1055
|
+
"unauthorized",
|
|
1056
|
+
"forbidden",
|
|
1057
|
+
"not_found",
|
|
1058
|
+
"rate_limited",
|
|
1059
|
+
"invalid_enrollment_transition",
|
|
1060
|
+
"last_admin_required",
|
|
1061
|
+
"self_admin_action_forbidden",
|
|
1062
|
+
"email_regeneration_unavailable",
|
|
1063
|
+
"mfa_required",
|
|
1064
|
+
"document_not_restorable",
|
|
1065
|
+
"workspace_gone"
|
|
1066
|
+
]);
|
|
1067
|
+
const adminErrorResponseSchema = v.object({ error: v.object({ code: adminErrorCodeSchema }) });
|
|
1068
|
+
const enrollmentStatusSchema = v.picklist([
|
|
1069
|
+
"pending",
|
|
1070
|
+
"approved",
|
|
1071
|
+
"rejected",
|
|
1072
|
+
"revoked"
|
|
1073
|
+
]);
|
|
1074
|
+
const enrollmentSchema = v.object({
|
|
1075
|
+
id: v.string(),
|
|
1076
|
+
email: v.pipe(v.string(), v.email()),
|
|
1077
|
+
name: v.nullable(v.string()),
|
|
1078
|
+
reason: v.nullable(v.string()),
|
|
1079
|
+
status: enrollmentStatusSchema,
|
|
1080
|
+
requestedAt: timestampSchema,
|
|
1081
|
+
reviewedAt: nullableTimestampSchema,
|
|
1082
|
+
reviewedBy: v.nullable(v.string()),
|
|
1083
|
+
/** The reviewer's name, in lists, while the server still knows them. */
|
|
1084
|
+
reviewerName: v.optional(v.nullable(v.string())),
|
|
1085
|
+
reviewNote: v.nullable(v.string()),
|
|
1086
|
+
approvedUserId: v.nullable(v.string()),
|
|
1087
|
+
requestRevision: v.pipe(v.number(), v.integer(), v.minValue(1))
|
|
1088
|
+
});
|
|
1089
|
+
const enrollmentsResponseSchema = v.object({
|
|
1090
|
+
enrollments: v.array(enrollmentSchema),
|
|
1091
|
+
...listTotals(enrollmentStatusSchema.options)
|
|
1092
|
+
});
|
|
1093
|
+
const enrollmentReviewResponseSchema = v.object({ enrollment: enrollmentSchema });
|
|
1094
|
+
const cloudAdminSessionResponseSchema = v.object({ user: cloudIdentitySchema });
|
|
1095
|
+
const cloudAdminUserSchema = v.object({
|
|
1096
|
+
...cloudPersonSchema.entries,
|
|
1097
|
+
role: v.optional(v.string()),
|
|
1098
|
+
banned: v.nullable(v.boolean()),
|
|
1099
|
+
banReason: v.optional(v.nullable(v.string())),
|
|
1100
|
+
createdAt: timestampSchema,
|
|
1101
|
+
/** An authenticator app or a passkey confirms this account's sign-ins. */
|
|
1102
|
+
twoStep: v.boolean(),
|
|
1103
|
+
/** When one of the account's sessions was last used, or null when none is left. */
|
|
1104
|
+
lastActiveAt: nullableTimestampSchema,
|
|
1105
|
+
workspaceCount: countSchema
|
|
1106
|
+
});
|
|
1107
|
+
/** Which accounts a list of people shows. */
|
|
1108
|
+
const cloudAdminUserFilterSchema = v.picklist([
|
|
1109
|
+
"all",
|
|
1110
|
+
"administrators",
|
|
1111
|
+
"suspended",
|
|
1112
|
+
"without-two-step"
|
|
1113
|
+
]);
|
|
1114
|
+
const cloudAdminUsersResponseSchema = v.object({
|
|
1115
|
+
users: v.array(cloudAdminUserSchema),
|
|
1116
|
+
...listTotals(cloudAdminUserFilterSchema.options)
|
|
1117
|
+
});
|
|
1118
|
+
const cloudAdminUserDetailSchema = v.object({
|
|
1119
|
+
user: v.object({
|
|
1120
|
+
...cloudAdminUserSchema.entries,
|
|
1121
|
+
emailVerified: v.boolean()
|
|
1122
|
+
}),
|
|
1123
|
+
methods: v.array(v.object({
|
|
1124
|
+
provider: v.string(),
|
|
1125
|
+
createdAt: timestampSchema
|
|
1126
|
+
})),
|
|
1127
|
+
authenticator: v.boolean(),
|
|
1128
|
+
passkeyCount: countSchema,
|
|
1129
|
+
sessions: v.array(cloudAccountSessionSchema),
|
|
1130
|
+
signIns: v.array(cloudSignInSchema),
|
|
1131
|
+
workspaces: v.array(v.object({
|
|
1132
|
+
id: v.string(),
|
|
1133
|
+
name: v.string(),
|
|
1134
|
+
role: workspaceRoleSchema,
|
|
1135
|
+
memberCount: countSchema,
|
|
1136
|
+
joinedAt: timestampSchema
|
|
1137
|
+
}))
|
|
1138
|
+
});
|
|
1139
|
+
const adminMutationResponseSchema = v.object({ ok: v.literal(true) });
|
|
1140
|
+
const transactionalEmailAdminSchema = v.object({
|
|
1141
|
+
id: v.string(),
|
|
1142
|
+
kind: v.string(),
|
|
1143
|
+
recipientEmailNormalized: v.pipe(v.string(), v.email()),
|
|
1144
|
+
status: v.string(),
|
|
1145
|
+
attemptCount: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
1146
|
+
nextAttemptAt: timestampSchema,
|
|
1147
|
+
transport: v.nullable(v.string()),
|
|
1148
|
+
transportMessageId: v.nullable(v.string()),
|
|
1149
|
+
lastErrorCode: v.nullable(v.string()),
|
|
1150
|
+
createdAt: timestampSchema,
|
|
1151
|
+
acceptedAt: nullableTimestampSchema,
|
|
1152
|
+
regeneratable: v.boolean()
|
|
1153
|
+
});
|
|
1154
|
+
/** Which messages a list of email shows, by how their delivery went. */
|
|
1155
|
+
const cloudAdminEmailFilterSchema = v.picklist([
|
|
1156
|
+
"all",
|
|
1157
|
+
"sent",
|
|
1158
|
+
"waiting",
|
|
1159
|
+
"failed"
|
|
1160
|
+
]);
|
|
1161
|
+
const adminEmailResponseSchema = v.object({
|
|
1162
|
+
messages: v.array(transactionalEmailAdminSchema),
|
|
1163
|
+
...listTotals(cloudAdminEmailFilterSchema.options)
|
|
1164
|
+
});
|
|
1165
|
+
/** Who or what an event names; `name` is null once the server no longer knows it. */
|
|
1166
|
+
const auditPartySchema = v.object({
|
|
1167
|
+
id: v.string(),
|
|
1168
|
+
name: v.nullable(v.string())
|
|
1169
|
+
});
|
|
1170
|
+
const adminAuditEventSchema = v.object({
|
|
1171
|
+
id: v.string(),
|
|
1172
|
+
actor: auditPartySchema,
|
|
1173
|
+
action: v.string(),
|
|
1174
|
+
/** What the event is about: an account, an access request, an email, or a document. */
|
|
1175
|
+
subject: v.object({
|
|
1176
|
+
...auditPartySchema.entries,
|
|
1177
|
+
type: v.string()
|
|
1178
|
+
}),
|
|
1179
|
+
metadata: v.unknown(),
|
|
1180
|
+
createdAt: timestampSchema
|
|
1181
|
+
});
|
|
1182
|
+
/** Which events a list of activity shows, by what they are about. */
|
|
1183
|
+
const cloudAdminAuditFilterSchema = v.picklist([
|
|
1184
|
+
"all",
|
|
1185
|
+
"accounts",
|
|
1186
|
+
"requests",
|
|
1187
|
+
"email",
|
|
1188
|
+
"documents"
|
|
1189
|
+
]);
|
|
1190
|
+
const adminAuditResponseSchema = v.object({
|
|
1191
|
+
events: v.array(adminAuditEventSchema),
|
|
1192
|
+
...listTotals(cloudAdminAuditFilterSchema.options)
|
|
1193
|
+
});
|
|
1194
|
+
/** A document as the console shows it: where it lives, who made it, and whether it is taken down. */
|
|
1195
|
+
const cloudAdminDocumentSchema = v.object({
|
|
1196
|
+
id: v.string(),
|
|
1197
|
+
name: v.string(),
|
|
1198
|
+
workspace: v.object({
|
|
1199
|
+
id: v.string(),
|
|
1200
|
+
name: v.string()
|
|
1201
|
+
}),
|
|
1202
|
+
/** Who made it, while the server knows them. */
|
|
1203
|
+
owner: v.nullable(v.object({
|
|
1204
|
+
id: v.string(),
|
|
1205
|
+
name: v.string(),
|
|
1206
|
+
email: v.string()
|
|
1207
|
+
})),
|
|
1208
|
+
createdAt: timestampSchema,
|
|
1209
|
+
updatedAt: timestampSchema,
|
|
1210
|
+
disabledAt: nullableTimestampSchema,
|
|
1211
|
+
disabledReason: v.nullable(v.string()),
|
|
1212
|
+
/** Reports about it still waiting for a decision. */
|
|
1213
|
+
openReports: countSchema,
|
|
1214
|
+
/**
|
|
1215
|
+
* When someone deleted it forever, and when cleanup destroys it; until then an administrator
|
|
1216
|
+
* can still restore it. Servers from before Trash send neither.
|
|
1217
|
+
*/
|
|
1218
|
+
purgedAt: v.optional(nullableTimestampSchema, null),
|
|
1219
|
+
destroyedAt: v.optional(nullableTimestampSchema, null)
|
|
1220
|
+
});
|
|
1221
|
+
/** Which documents a list shows: live ones, or those deleted forever an administrator can restore. */
|
|
1222
|
+
const cloudAdminDocumentFilterSchema = v.picklist([
|
|
1223
|
+
"all",
|
|
1224
|
+
"reported",
|
|
1225
|
+
"disabled",
|
|
1226
|
+
"purged"
|
|
1227
|
+
]);
|
|
1228
|
+
const cloudAdminDocumentsResponseSchema = v.object({
|
|
1229
|
+
documents: v.array(cloudAdminDocumentSchema),
|
|
1230
|
+
...listTotals(cloudAdminDocumentFilterSchema.options)
|
|
1231
|
+
});
|
|
1232
|
+
const cloudAdminReportStatusSchema = v.picklist([
|
|
1233
|
+
"open",
|
|
1234
|
+
"dismissed",
|
|
1235
|
+
"actioned"
|
|
1236
|
+
]);
|
|
1237
|
+
const cloudAdminReportSchema = v.object({
|
|
1238
|
+
id: v.string(),
|
|
1239
|
+
reason: documentReportReasonSchema,
|
|
1240
|
+
description: v.string(),
|
|
1241
|
+
status: cloudAdminReportStatusSchema,
|
|
1242
|
+
/** The account that filed it, or null for a guest. */
|
|
1243
|
+
reporter: v.nullable(v.object({
|
|
1244
|
+
id: v.string(),
|
|
1245
|
+
name: v.nullable(v.string())
|
|
1246
|
+
})),
|
|
1247
|
+
replyEmail: v.nullable(v.string()),
|
|
1248
|
+
createdAt: timestampSchema,
|
|
1249
|
+
resolvedAt: nullableTimestampSchema,
|
|
1250
|
+
document: cloudAdminDocumentSchema,
|
|
1251
|
+
/** The link it was opened from, and whether that link still works. */
|
|
1252
|
+
share: v.nullable(v.object({
|
|
1253
|
+
id: v.string(),
|
|
1254
|
+
revoked: v.boolean()
|
|
1255
|
+
}))
|
|
755
1256
|
});
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
1257
|
+
/** Which reports a list shows, by where they stand. */
|
|
1258
|
+
const cloudAdminReportFilterSchema = v.picklist([
|
|
1259
|
+
"open",
|
|
1260
|
+
"actioned",
|
|
1261
|
+
"dismissed",
|
|
1262
|
+
"all"
|
|
1263
|
+
]);
|
|
1264
|
+
const cloudAdminReportsResponseSchema = v.object({
|
|
1265
|
+
reports: v.array(cloudAdminReportSchema),
|
|
1266
|
+
...listTotals(cloudAdminReportFilterSchema.options)
|
|
1267
|
+
});
|
|
1268
|
+
const adminOperationsResponseSchema = v.object({
|
|
1269
|
+
deployment: v.picklist(["official", "self-hosted"]),
|
|
1270
|
+
enrollmentMode: v.picklist([
|
|
1271
|
+
"open",
|
|
1272
|
+
"approval",
|
|
1273
|
+
"closed"
|
|
1274
|
+
]),
|
|
1275
|
+
emailTransport: v.picklist([
|
|
1276
|
+
"none",
|
|
1277
|
+
"smtp",
|
|
1278
|
+
"cloudflare"
|
|
1279
|
+
]),
|
|
1280
|
+
pendingEnrollment: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
1281
|
+
openReports: countSchema,
|
|
1282
|
+
pendingEmail: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
1283
|
+
failedEmail: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
1284
|
+
accounts: countSchema,
|
|
1285
|
+
workspaces: countSchema,
|
|
1286
|
+
documents: countSchema,
|
|
1287
|
+
storedBytes: countSchema
|
|
768
1288
|
});
|
|
769
1289
|
//#endregion
|
|
770
1290
|
//#region src/contract/relay.ts
|
|
@@ -859,6 +1379,14 @@ const RELAY_CLOSE = {
|
|
|
859
1379
|
/** The document was restored to a version, so its room started over under a new ID. */
|
|
860
1380
|
restored: 4410
|
|
861
1381
|
};
|
|
1382
|
+
/**
|
|
1383
|
+
* The text a peer sends to learn whether the relay still hears it, and the relay's answer. Relay
|
|
1384
|
+
* frames are binary, so neither is taken for one, and a Durable Object answers without waking.
|
|
1385
|
+
*/
|
|
1386
|
+
const RELAY_HEARTBEAT = {
|
|
1387
|
+
ping: "ping",
|
|
1388
|
+
pong: "pong"
|
|
1389
|
+
};
|
|
862
1390
|
const CLIENT_AUTH = 0;
|
|
863
1391
|
const CLIENT_MESSAGE = 1;
|
|
864
1392
|
const CLIENT_FRAGMENT = 2;
|
|
@@ -1105,7 +1633,7 @@ const workspaceEntitlementsSchema = v.object({
|
|
|
1105
1633
|
guestPresence: v.boolean(),
|
|
1106
1634
|
collaboration: v.boolean(),
|
|
1107
1635
|
revisionHistory: v.boolean(),
|
|
1108
|
-
|
|
1636
|
+
cloudServices: v.optional(v.boolean(), false)
|
|
1109
1637
|
}),
|
|
1110
1638
|
limits: v.object({
|
|
1111
1639
|
maximumFileBytes: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
@@ -1118,6 +1646,12 @@ const workspaceEntitlementsSchema = v.object({
|
|
|
1118
1646
|
reservedStorageBytes: v.pipe(v.number(), v.integer(), v.minValue(0))
|
|
1119
1647
|
})
|
|
1120
1648
|
});
|
|
1649
|
+
/**
|
|
1650
|
+
* An account's own plan and the storage its workspaces hold together. A workspace reports the
|
|
1651
|
+
* same for its owner, so the two read alike.
|
|
1652
|
+
*/
|
|
1653
|
+
const accountEntitlementsSchema = workspaceEntitlementsSchema;
|
|
1654
|
+
const accountEntitlementsResponseSchema = v.object({ entitlements: accountEntitlementsSchema });
|
|
1121
1655
|
//#endregion
|
|
1122
1656
|
//#region src/contract/discovery.ts
|
|
1123
1657
|
const CLOUD_PROTOCOL_VERSION = "1";
|
|
@@ -1155,11 +1689,65 @@ const cloudCapabilitiesSchema = v.object({
|
|
|
1155
1689
|
/** A released editor version, `major.minor.patch`. */
|
|
1156
1690
|
const cloudEditorVersionSchema = v.pipe(v.string(), v.regex(/^\d+\.\d+\.\d+$/));
|
|
1157
1691
|
/**
|
|
1692
|
+
* The header desktop editors send with each request, naming their version, so a server can refuse
|
|
1693
|
+
* an editor older than its `minimumEditorVersion`. Browser editors leave it out: the server serves
|
|
1694
|
+
* them, and an older server's CORS rules would refuse a header they don't list.
|
|
1695
|
+
*/
|
|
1696
|
+
const CLOUD_EDITOR_VERSION_HEADER = "X-OpenPencil-Editor-Version";
|
|
1697
|
+
function editorVersionParts(version) {
|
|
1698
|
+
const match = /^(\d+)\.(\d+)\.(\d+)/.exec(version);
|
|
1699
|
+
return match ? match.slice(1).map(Number) : null;
|
|
1700
|
+
}
|
|
1701
|
+
/**
|
|
1702
|
+
* Whether `version` is `minimum` or later, comparing `major.minor.patch` numerically; a prerelease
|
|
1703
|
+
* counts as its release. A version that isn't one, on either side, is not at least anything.
|
|
1704
|
+
*/
|
|
1705
|
+
function isEditorVersionAtLeast(version, minimum) {
|
|
1706
|
+
const have = editorVersionParts(version);
|
|
1707
|
+
const need = editorVersionParts(minimum);
|
|
1708
|
+
if (!have || !need) return false;
|
|
1709
|
+
for (let index = 0; index < need.length; index++) {
|
|
1710
|
+
const difference = (have[index] ?? 0) - (need[index] ?? 0);
|
|
1711
|
+
if (difference !== 0) return difference > 0;
|
|
1712
|
+
}
|
|
1713
|
+
return true;
|
|
1714
|
+
}
|
|
1715
|
+
/**
|
|
1158
1716
|
* Whether editors offer this server to everyone, and from which editor version on. Only the
|
|
1159
1717
|
* official server's listing is read: it turns the Cloud entry points on without an editor release,
|
|
1160
1718
|
* and an editor older than the minimum keeps them hidden.
|
|
1161
1719
|
*/
|
|
1162
1720
|
const cloudListingSchema = v.object({ minimumEditorVersion: cloudEditorVersionSchema });
|
|
1721
|
+
const legalURLSchema = v.pipe(v.string(), v.url());
|
|
1722
|
+
/**
|
|
1723
|
+
* The operator's legal links, which clients show at sign-up and in account pages. A server that
|
|
1724
|
+
* names none shows none; `requireAcceptance` means an account accepts `termsVersion` before it uses
|
|
1725
|
+
* the server.
|
|
1726
|
+
*/
|
|
1727
|
+
const cloudLegalDiscoverySchema = v.object({
|
|
1728
|
+
termsURL: v.optional(legalURLSchema),
|
|
1729
|
+
privacyURL: v.optional(legalURLSchema),
|
|
1730
|
+
termsVersion: v.optional(v.string()),
|
|
1731
|
+
requireAcceptance: v.boolean(),
|
|
1732
|
+
abuseEmail: v.optional(v.pipe(v.string(), v.email())),
|
|
1733
|
+
minimumAge: v.optional(v.pipe(v.number(), v.integer()))
|
|
1734
|
+
});
|
|
1735
|
+
/** A web address a page may link or load: `http` or `https` only, never a script or data URL. */
|
|
1736
|
+
const webURLSchema = v.pipe(v.string(), v.url(), v.check((value) => ["http:", "https:"].includes(new URL(value).protocol)));
|
|
1737
|
+
/**
|
|
1738
|
+
* How a self-hosted server names itself on its public pages: the operator's name and logo in the
|
|
1739
|
+
* bar, and where its people get help. The official server is OpenPencil's own and names none.
|
|
1740
|
+
*/
|
|
1741
|
+
const cloudBrandingSchema = v.object({
|
|
1742
|
+
name: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(80))),
|
|
1743
|
+
logoURL: v.optional(webURLSchema),
|
|
1744
|
+
helpURL: v.optional(webURLSchema)
|
|
1745
|
+
});
|
|
1746
|
+
/**
|
|
1747
|
+
* The server's community gallery: the workspace whose documents anyone may open read-only.
|
|
1748
|
+
* Saving to it publishes, so editors never choose it for anyone and say so when it is chosen.
|
|
1749
|
+
*/
|
|
1750
|
+
const cloudCommunityDiscoverySchema = v.object({ workspaceId: v.pipe(v.string(), v.uuid()) });
|
|
1163
1751
|
const cloudDiscoverySchema = v.object({
|
|
1164
1752
|
protocolVersion: v.literal("1"),
|
|
1165
1753
|
deployment: cloudDeploymentSchema,
|
|
@@ -1170,10 +1758,19 @@ const cloudDiscoverySchema = v.object({
|
|
|
1170
1758
|
authentication: cloudAuthenticationSchema,
|
|
1171
1759
|
capabilities: cloudCapabilitiesSchema,
|
|
1172
1760
|
listing: v.optional(cloudListingSchema),
|
|
1173
|
-
/**
|
|
1174
|
-
|
|
1761
|
+
/**
|
|
1762
|
+
* The oldest editor version the server works with. Older editors ask to be updated instead of
|
|
1763
|
+
* connecting, and the server refuses their requests.
|
|
1764
|
+
*/
|
|
1765
|
+
minimumEditorVersion: v.optional(cloudEditorVersionSchema),
|
|
1766
|
+
/** The services editors reach with Cloud-signed tokens; absent when the deployment has none. */
|
|
1767
|
+
services: v.optional(cloudServicesDiscoverySchema),
|
|
1175
1768
|
/** Where people manage their plan and buy credits; absent when the deployment does not bill. */
|
|
1176
|
-
billing: v.optional(cloudBillingDiscoverySchema)
|
|
1769
|
+
billing: v.optional(cloudBillingDiscoverySchema),
|
|
1770
|
+
/** The community gallery; absent when the deployment has none. */
|
|
1771
|
+
community: v.optional(cloudCommunityDiscoverySchema),
|
|
1772
|
+
legal: v.optional(cloudLegalDiscoverySchema),
|
|
1773
|
+
branding: v.optional(cloudBrandingSchema)
|
|
1177
1774
|
});
|
|
1178
1775
|
/** The server's own address, where its editor and pages are, from its auth API's. */
|
|
1179
1776
|
function cloudServerOrigin(discovery) {
|
|
@@ -1183,138 +1780,12 @@ function parseCloudDiscovery(input) {
|
|
|
1183
1780
|
return v.parse(cloudDiscoverySchema, input);
|
|
1184
1781
|
}
|
|
1185
1782
|
//#endregion
|
|
1186
|
-
//#region src/contract/sharing.ts
|
|
1187
|
-
const documentShareSchema = v.object({
|
|
1188
|
-
id: v.pipe(v.string(), v.uuid()),
|
|
1189
|
-
documentId: v.pipe(v.string(), v.uuid()),
|
|
1190
|
-
permission: documentPermissionSchema,
|
|
1191
|
-
roomEpoch: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
1192
|
-
createdBy: v.string(),
|
|
1193
|
-
createdAt: v.string(),
|
|
1194
|
-
updatedAt: v.string(),
|
|
1195
|
-
expiresAt: v.nullable(v.string()),
|
|
1196
|
-
revokedAt: v.nullable(v.string()),
|
|
1197
|
-
lastUsedAt: v.nullable(v.string())
|
|
1198
|
-
});
|
|
1199
|
-
/** When a link stops working, as an ISO timestamp; `null` keeps it working until revoked. */
|
|
1200
|
-
const shareExpirySchema = v.optional(v.nullable(v.pipe(v.string(), v.isoTimestamp())));
|
|
1201
|
-
const createDocumentShareSchema = v.object({
|
|
1202
|
-
permission: documentPermissionSchema,
|
|
1203
|
-
expiresAt: shareExpirySchema
|
|
1204
|
-
});
|
|
1205
|
-
const updateDocumentShareSchema = v.object({
|
|
1206
|
-
permission: v.optional(documentPermissionSchema),
|
|
1207
|
-
expiresAt: shareExpirySchema
|
|
1208
|
-
});
|
|
1209
|
-
const resolveDocumentShareSchema = v.object({
|
|
1210
|
-
secret: v.pipe(v.string(), v.minLength(32), v.maxLength(128)),
|
|
1211
|
-
guestName: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(80))),
|
|
1212
|
-
guestId: v.optional(v.pipe(v.string(), v.minLength(16), v.maxLength(128)))
|
|
1213
|
-
});
|
|
1214
|
-
/** A guest's request for the links of images a shared document's live room names. */
|
|
1215
|
-
const requestSharedImageLinksSchema = v.object({
|
|
1216
|
-
...resolveDocumentShareSchema.entries,
|
|
1217
|
-
...requestImageLinksSchema.entries
|
|
1218
|
-
});
|
|
1219
|
-
function parseRequestSharedImageLinks(input) {
|
|
1220
|
-
return v.parse(requestSharedImageLinksSchema, input);
|
|
1221
|
-
}
|
|
1222
|
-
const resolvedDocumentShareSchema = v.object({
|
|
1223
|
-
documentId: v.pipe(v.string(), v.uuid()),
|
|
1224
|
-
permission: documentPermissionSchema,
|
|
1225
|
-
principal: collaborationPrincipalSchema,
|
|
1226
|
-
roomEpoch: v.pipe(v.number(), v.integer(), v.minValue(0))
|
|
1227
|
-
});
|
|
1228
|
-
const cloudUserProfileSchema = v.object({
|
|
1229
|
-
id: v.string(),
|
|
1230
|
-
name: v.string(),
|
|
1231
|
-
email: v.pipe(v.string(), v.email()),
|
|
1232
|
-
image: v.nullable(v.pipe(v.string(), v.url()))
|
|
1233
|
-
});
|
|
1234
|
-
const documentGrantSchema = v.object({
|
|
1235
|
-
id: v.pipe(v.string(), v.uuid()),
|
|
1236
|
-
documentId: v.pipe(v.string(), v.uuid()),
|
|
1237
|
-
userId: v.string(),
|
|
1238
|
-
permission: documentPermissionSchema,
|
|
1239
|
-
createdBy: v.string(),
|
|
1240
|
-
createdAt: v.string(),
|
|
1241
|
-
updatedAt: v.string()
|
|
1242
|
-
});
|
|
1243
|
-
/** What accepting an invitation gave: access to a document, or a place in a workspace. */
|
|
1244
|
-
const acceptedInvitationSchema = v.variant("kind", [v.object({
|
|
1245
|
-
kind: v.literal("document"),
|
|
1246
|
-
grant: documentGrantSchema
|
|
1247
|
-
}), v.object({
|
|
1248
|
-
kind: v.literal("workspace"),
|
|
1249
|
-
workspaceId: v.pipe(v.string(), v.uuid()),
|
|
1250
|
-
role: workspaceRoleSchema
|
|
1251
|
-
})]);
|
|
1252
|
-
const lookupCloudUserSchema = v.object({ email: v.pipe(v.string(), v.trim(), v.toLowerCase(), v.email()) });
|
|
1253
|
-
const putDocumentGrantSchema = v.object({ permission: documentPermissionSchema });
|
|
1254
|
-
const createDocumentInvitationSchema = v.object({
|
|
1255
|
-
email: v.pipe(v.string(), v.trim(), v.toLowerCase(), v.email()),
|
|
1256
|
-
permission: documentPermissionSchema
|
|
1257
|
-
});
|
|
1258
|
-
const acceptDocumentInvitationSchema = v.object({ token: v.pipe(v.string(), v.minLength(32), v.maxLength(128)) });
|
|
1259
|
-
const createInvitationContinuationSchema = v.object({
|
|
1260
|
-
invitationId: v.pipe(v.string(), v.uuid()),
|
|
1261
|
-
token: v.pipe(v.string(), v.minLength(32), v.maxLength(128))
|
|
1262
|
-
});
|
|
1263
|
-
const invitationContinuationSchema = v.object({ id: v.pipe(v.string(), v.minLength(16), v.maxLength(128)) });
|
|
1264
|
-
const invitationPreviewFields = {
|
|
1265
|
-
inviterName: v.string(),
|
|
1266
|
-
expiresAt: v.string(),
|
|
1267
|
-
recipientHint: v.string()
|
|
1268
|
-
};
|
|
1269
|
-
/** What an invitation link opens: one document, or a whole workspace. */
|
|
1270
|
-
const invitationPreviewSchema = v.variant("kind", [v.object({
|
|
1271
|
-
kind: v.literal("document"),
|
|
1272
|
-
documentName: v.string(),
|
|
1273
|
-
permission: documentPermissionSchema,
|
|
1274
|
-
...invitationPreviewFields
|
|
1275
|
-
}), v.object({
|
|
1276
|
-
kind: v.literal("workspace"),
|
|
1277
|
-
workspaceName: v.string(),
|
|
1278
|
-
role: workspaceRoleSchema,
|
|
1279
|
-
...invitationPreviewFields
|
|
1280
|
-
})]);
|
|
1281
|
-
const documentInvitationSchema = v.object({
|
|
1282
|
-
id: v.pipe(v.string(), v.uuid()),
|
|
1283
|
-
documentId: v.pipe(v.string(), v.uuid()),
|
|
1284
|
-
email: v.pipe(v.string(), v.email()),
|
|
1285
|
-
permission: documentPermissionSchema,
|
|
1286
|
-
invitedBy: v.string(),
|
|
1287
|
-
invitedAt: v.string(),
|
|
1288
|
-
expiresAt: v.string(),
|
|
1289
|
-
acceptedAt: v.nullable(v.string())
|
|
1290
|
-
});
|
|
1291
|
-
function parseCreateInvitationContinuation(input) {
|
|
1292
|
-
return v.parse(createInvitationContinuationSchema, input);
|
|
1293
|
-
}
|
|
1294
|
-
function parseLookupCloudUser(input) {
|
|
1295
|
-
return v.parse(lookupCloudUserSchema, input);
|
|
1296
|
-
}
|
|
1297
|
-
function parseCreateDocumentShare(input) {
|
|
1298
|
-
return v.parse(createDocumentShareSchema, input);
|
|
1299
|
-
}
|
|
1300
|
-
function parseUpdateDocumentShare(input) {
|
|
1301
|
-
return v.parse(updateDocumentShareSchema, input);
|
|
1302
|
-
}
|
|
1303
|
-
function parseResolveDocumentShare(input) {
|
|
1304
|
-
return v.parse(resolveDocumentShareSchema, input);
|
|
1305
|
-
}
|
|
1306
|
-
function parsePutDocumentGrant(input) {
|
|
1307
|
-
return v.parse(putDocumentGrantSchema, input);
|
|
1308
|
-
}
|
|
1309
|
-
function parseCreateDocumentInvitation(input) {
|
|
1310
|
-
return v.parse(createDocumentInvitationSchema, input);
|
|
1311
|
-
}
|
|
1312
|
-
function parseAcceptDocumentInvitation(input) {
|
|
1313
|
-
return v.parse(acceptDocumentInvitationSchema, input);
|
|
1314
|
-
}
|
|
1315
|
-
//#endregion
|
|
1316
1783
|
//#region src/contract/links.ts
|
|
1317
1784
|
const CLOUD_LINK_PATH = /^\/(invitations|share|documents)\/([^/]+)$/;
|
|
1785
|
+
/** A community document opened in the editor; `/community/:id` alone is its page. */
|
|
1786
|
+
const COMMUNITY_EDITOR_PATH = /^\/community\/([^/]+)\/open$/;
|
|
1787
|
+
/** The server's community gallery: every document in it, each with a page of its own. */
|
|
1788
|
+
const CLOUD_COMMUNITY_PATH = "/community";
|
|
1318
1789
|
/**
|
|
1319
1790
|
* A link on the server's own editor. The server is the link's own address, so the link needs
|
|
1320
1791
|
* nothing else to name it; a secret travels in the fragment, so it never reaches access logs or
|
|
@@ -1345,12 +1816,31 @@ function cloudDocumentPath(documentId) {
|
|
|
1345
1816
|
return `/documents/${encodeParam(documentId)}`;
|
|
1346
1817
|
}
|
|
1347
1818
|
/**
|
|
1819
|
+
* A document of the server's community gallery opened in the editor, `/community/:id/open`, or
|
|
1820
|
+
* one of its named versions with `?version=…`, which anyone opens read-only without signing in.
|
|
1821
|
+
*/
|
|
1822
|
+
function cloudCommunityURL(serverURL, documentId, versionId = null) {
|
|
1823
|
+
return serverLink(serverURL, cloudCommunityPath(documentId), { version: versionId ?? void 0 });
|
|
1824
|
+
}
|
|
1825
|
+
function cloudCommunityPath(documentId) {
|
|
1826
|
+
return `${cloudCommunityPagePath(documentId)}/open`;
|
|
1827
|
+
}
|
|
1828
|
+
/** A community document's page on the server: its preview, versions, and ways to open it. */
|
|
1829
|
+
function cloudCommunityPagePath(documentId) {
|
|
1830
|
+
return `${CLOUD_COMMUNITY_PATH}/${encodeParam(documentId)}`;
|
|
1831
|
+
}
|
|
1832
|
+
/**
|
|
1348
1833
|
* The kind and ID of a Cloud link's path, or null for any other path. The ID is decoded; a broken
|
|
1349
1834
|
* escape such as `%E0` is no link.
|
|
1350
1835
|
*/
|
|
1351
1836
|
function parseCloudLinkPath(pathname) {
|
|
1352
|
-
const
|
|
1353
|
-
|
|
1837
|
+
const community = pathname.match(COMMUNITY_EDITOR_PATH);
|
|
1838
|
+
const [, kind, id] = community ? [
|
|
1839
|
+
pathname,
|
|
1840
|
+
"community",
|
|
1841
|
+
community[1]
|
|
1842
|
+
] : pathname.match(CLOUD_LINK_PATH) ?? [];
|
|
1843
|
+
if (kind !== "invitations" && kind !== "share" && kind !== "documents" && kind !== "community" || !id) return null;
|
|
1354
1844
|
try {
|
|
1355
1845
|
return {
|
|
1356
1846
|
kind,
|
|
@@ -1369,6 +1859,13 @@ function cloudDesktopLinkURL(kind, id, serverURL, secret) {
|
|
|
1369
1859
|
const link = serverLink(serverURL, `/${kind}/${encodeParam(id)}`);
|
|
1370
1860
|
return withFragment(withQuery("openpencil://cloud", { url: link }), secret);
|
|
1371
1861
|
}
|
|
1862
|
+
/**
|
|
1863
|
+
* The desktop app's form of a community document's link, `openpencil://cloud?url=<link>`: the
|
|
1864
|
+
* editor's address for it, with the named version it asks for, if any. It carries no secret.
|
|
1865
|
+
*/
|
|
1866
|
+
function cloudCommunityDesktopLinkURL(documentId, serverURL, versionId = null) {
|
|
1867
|
+
return withQuery("openpencil://cloud", { url: cloudCommunityURL(serverURL, documentId, versionId) });
|
|
1868
|
+
}
|
|
1372
1869
|
//#endregion
|
|
1373
1870
|
//#region src/contract/portal.ts
|
|
1374
1871
|
/**
|
|
@@ -1383,8 +1880,14 @@ const CLOUD_PORTAL_PAGE_ROOTS = [
|
|
|
1383
1880
|
"/account",
|
|
1384
1881
|
"/admin"
|
|
1385
1882
|
];
|
|
1883
|
+
/**
|
|
1884
|
+
* The community gallery's pages, which the portal serves too: the gallery at `/community` and a
|
|
1885
|
+
* document's page at `/community/:id`. The editor opens a document at `/community/:id/open`.
|
|
1886
|
+
*/
|
|
1887
|
+
const CLOUD_PORTAL_COMMUNITY_PAGES = ["/community", "/community/:documentId"];
|
|
1888
|
+
const COMMUNITY_PAGE = /^\/community(?:\/[^/]+)?\/?$/;
|
|
1386
1889
|
function isCloudPortalPage(path) {
|
|
1387
|
-
return CLOUD_PORTAL_PAGE_ROOTS.some((root) => path === root || path.startsWith(`${root}/`));
|
|
1890
|
+
return COMMUNITY_PAGE.test(path) || CLOUD_PORTAL_PAGE_ROOTS.some((root) => path === root || path.startsWith(`${root}/`));
|
|
1388
1891
|
}
|
|
1389
1892
|
//#endregion
|
|
1390
1893
|
//#region src/contract/versions.ts
|
|
@@ -1448,6 +1951,50 @@ function parseDuplicateDocumentVersion(input) {
|
|
|
1448
1951
|
return v.parse(duplicateDocumentVersionSchema, input);
|
|
1449
1952
|
}
|
|
1450
1953
|
//#endregion
|
|
1451
|
-
|
|
1954
|
+
//#region src/contract/community.ts
|
|
1955
|
+
/**
|
|
1956
|
+
* Where a community document's thumbnail is served, by its document and revision: the address
|
|
1957
|
+
* changes with each save, so a cached copy never shows an older state.
|
|
1958
|
+
*/
|
|
1959
|
+
const COMMUNITY_THUMBNAIL_PATH = "/api/community/thumbnails";
|
|
1960
|
+
function communityThumbnailPath(documentId, revisionId) {
|
|
1961
|
+
return `${COMMUNITY_THUMBNAIL_PATH}/${documentId}/${revisionId}`;
|
|
1962
|
+
}
|
|
1963
|
+
/** A version of a community document someone named, such as the release it was published for. */
|
|
1964
|
+
const communityVersionSchema = v.object({
|
|
1965
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
1966
|
+
name: v.string(),
|
|
1967
|
+
description: v.nullable(v.string()),
|
|
1968
|
+
createdAt: v.string(),
|
|
1969
|
+
/** Whether the document holds this version now, with nothing changed since it was named. */
|
|
1970
|
+
current: v.boolean()
|
|
1971
|
+
});
|
|
1972
|
+
/**
|
|
1973
|
+
* A document in the deployment's community workspace, which anyone may open read-only: its name,
|
|
1974
|
+
* when it last changed, its thumbnail's path on the server, and its named versions, newest first.
|
|
1975
|
+
*/
|
|
1976
|
+
const communityDocumentSchema = v.object({
|
|
1977
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
1978
|
+
name: v.string(),
|
|
1979
|
+
kind: documentKindSchema,
|
|
1980
|
+
updatedAt: v.string(),
|
|
1981
|
+
revisionId: v.pipe(v.string(), v.uuid()),
|
|
1982
|
+
thumbnailPath: v.string(),
|
|
1983
|
+
versions: v.array(communityVersionSchema)
|
|
1984
|
+
});
|
|
1985
|
+
/** The community workspace's documents, most recently changed first. */
|
|
1986
|
+
const communityDocumentsSchema = v.object({ documents: v.array(communityDocumentSchema) });
|
|
1987
|
+
/** Which state of a community document to open: a named version, or else the latest. */
|
|
1988
|
+
const communityDownloadQuerySchema = v.object({ version: v.optional(v.pipe(v.string(), v.uuid())) });
|
|
1989
|
+
function parseCommunityDownloadQuery(input) {
|
|
1990
|
+
return v.parse(communityDownloadQuerySchema, input);
|
|
1991
|
+
}
|
|
1992
|
+
/** A community document, or one of its named versions, with where to download it. */
|
|
1993
|
+
const communityDownloadSchema = v.object({
|
|
1994
|
+
document: documentDownloadSchema,
|
|
1995
|
+
version: v.nullable(communityVersionSchema)
|
|
1996
|
+
});
|
|
1997
|
+
//#endregion
|
|
1998
|
+
export { BILLING_ERROR_STATUS, CLOUD_ACCESS_TOKEN_MAX_DAYS, CLOUD_ACCESS_TOKEN_NAME_MAX_LENGTH, CLOUD_ACCESS_TOKEN_PREFIX, CLOUD_ACCOUNT_PLAN_PATH, CLOUD_API_MAX_BODY_BYTES, CLOUD_BILLING_API_PATHS, CLOUD_BILLING_CONTRACT_VERSION, CLOUD_BILLING_TOKEN_AUDIENCE, CLOUD_COMMUNITY_PATH, CLOUD_DISCOVERY_PATH, CLOUD_DOCUMENT_NAME_MAX_LENGTH, CLOUD_EDITOR_VERSION_HEADER, CLOUD_IMAGE_NAME_PATTERN, CLOUD_MAX_DOCUMENT_IMAGES, CLOUD_PICTURE_MAX_BYTES, CLOUD_PICTURE_SIZE, CLOUD_PORTAL_COMMUNITY_PAGES, CLOUD_PORTAL_PAGE_ROOTS, CLOUD_PROTOCOL_MAX_UPLOAD_BYTES, CLOUD_PROTOCOL_VERSION, CLOUD_SERVICES_API_PATHS, CLOUD_SERVICES_CONTRACT_VERSION, CLOUD_SERVICES_JWKS_PATH, CLOUD_SERVICES_TOKEN_AUDIENCE, COLLAB_ACTIONS, COMMUNITY_THUMBNAIL_PATH, DOCUMENT_REPORT_DESCRIPTION_MAX, DOCUMENT_VERSION_DESCRIPTION_MAX_LENGTH, DOCUMENT_VERSION_NAME_MAX_LENGTH, MAX_COLLAB_MESSAGE_BYTES, MAX_PRESENCE_NAME_LENGTH, MAX_SEARCH_QUERY_LENGTH, MAX_SEARCH_RESULTS, RELAY_CLOSE, RELAY_DOCUMENT_PARAM, RELAY_FORWARDING_BYTES, RELAY_FRAGMENT_BYTES, RELAY_HEARTBEAT, RELAY_MINIMUM_MESSAGE_BYTES, RELAY_PATH, RELAY_SERVER_PEER, SERVICE_ERROR_STATUS, acceptDocumentInvitationSchema, acceptedInvitationSchema, accountEntitlementsResponseSchema, accountEntitlementsSchema, accountSecurityErrorCodeSchema, accountSecurityErrorResponseSchema, adminAuditEventSchema, adminAuditResponseSchema, adminEmailResponseSchema, adminErrorCodeSchema, adminErrorResponseSchema, adminMutationResponseSchema, adminOperationsResponseSchema, billingAccountSchema, billingCatalogSchema, billingErrorCodeSchema, billingErrorSchema, billingPlanSchema, billingRedirectSchema, billingTokenClaimsSchema, billingTokenSchema, chatModelSchema, checkoutRequestSchema, cloudAccessTokenCreateSchema, cloudAccessTokenCreatedResponseSchema, cloudAccessTokenRevokeSchema, cloudAccessTokenSchema, cloudAccessTokensResponseSchema, cloudAccountDeleteSchema, cloudAccountDeletionDocumentSchema, cloudAccountDeletionResponseSchema, cloudAccountDeletionSchema, cloudAccountDeletionWorkspaceSchema, cloudAccountMutationResponseSchema, cloudAccountSessionSchema, cloudAccountSessionsResponseSchema, cloudAccountStateSchema, cloudAccountStatusResponseSchema, cloudActorSchema, cloudAdminAuditFilterSchema, cloudAdminDocumentFilterSchema, cloudAdminDocumentSchema, cloudAdminDocumentsResponseSchema, cloudAdminEmailFilterSchema, cloudAdminReportFilterSchema, cloudAdminReportSchema, cloudAdminReportStatusSchema, cloudAdminReportsResponseSchema, cloudAdminSessionResponseSchema, cloudAdminUserDetailSchema, cloudAdminUserFilterSchema, cloudAdminUserSchema, cloudAdminUsersResponseSchema, cloudAuthenticationMethodSchema, cloudAuthenticationMethodsResponseSchema, cloudAuthenticationProviderSchema, cloudAuthenticationSchema, cloudBillingDiscoverySchema, cloudBrandingSchema, cloudCapabilitiesSchema, cloudCommunityDesktopLinkURL, cloudCommunityDiscoverySchema, cloudCommunityPagePath, cloudCommunityPath, cloudCommunityURL, cloudDeploymentSchema, cloudDesktopLinkURL, cloudDiscoverySchema, cloudDocumentPath, cloudDocumentURL, cloudEditorVersionSchema, cloudEmailChangeSchema, cloudIdentitySchema, cloudInvitationURL, cloudLanguageTagSchema, cloudLegalDiscoverySchema, cloudListingSchema, cloudLocaleUpdateSchema, cloudMFAEnableResponseSchema, cloudMFAEnableSchema, cloudMFARecoveryCodesResponseSchema, cloudMFAStatusResponseSchema, cloudMFAStatusSchema, cloudMFAVerifyResponseSchema, cloudMFAVerifySchema, cloudPasskeyDeleteSchema, cloudPasskeySchema, cloudPasskeysResponseSchema, cloudPasswordChangeSchema, cloudPersonSchema, cloudPictureResponseSchema, cloudPictureUploadSchema, cloudPresenceSchema, cloudProfileResponseSchema, cloudProfileSchema, cloudProfileUpdateSchema, cloudServerOrigin, cloudServicesDiscoverySchema, cloudSessionRevokeSchema, cloudSessionSchema, cloudShareURL, cloudSignInMethodSchema, cloudSignInSchema, cloudSignInsResponseSchema, cloudSocialLinkResponseSchema, cloudSocialLinkSchema, cloudTermsAcceptanceSchema, cloudUnlinkAuthenticationMethodSchema, cloudUserProfileSchema, collaborationPrincipalSchema, collaborationTicketSchema, commitImageUploadsSchema, commitUploadSchema, communityDocumentSchema, communityDocumentsSchema, communityDownloadQuerySchema, communityDownloadSchema, communityThumbnailPath, communityVersionSchema, createDocumentInvitationSchema, createDocumentSchema, createDocumentShareSchema, createInvitationContinuationSchema, createRelayClientAssembler, createRelayServerAssembler, createServicesTokenSchema, createUploadSchema, createWorkspaceInvitationSchema, createWorkspaceSchema, createdWorkspaceInvitationSchema, creditBucketSchema, creditPackSchema, creditWalletSchema, decodeRelayClientFrame, decodeRelayServerFrame, decodeRoomUpdate, defaultRelayURL, documentAccessSchema, documentAccessSourceSchema, documentDownloadSchema, documentGrantSchema, documentImageDownloadSchema, documentImageLinkSchema, documentInvitationSchema, documentPermissionSchema, documentReportReasonSchema, documentShareSchema, documentSummarySchema, documentVersionDownloadSchema, documentVersionKindSchema, documentVersionResponseSchema, documentVersionSchema, documentVersionsSchema, duplicateDocumentVersionSchema, encodeRelayClientFrame, encodeRelayServerFrame, encodeSyncReply, enrollmentReviewResponseSchema, enrollmentSchema, enrollmentStatusSchema, enrollmentsResponseSchema, fileDocumentReportResponseSchema, fileDocumentReportSchema, imageUploadOfferSchema, invitationContinuationSchema, invitationPreviewSchema, isCloudChecksum, isCloudPortalPage, isEditorVersionAtLeast, objectUploadSchema, parseAcceptDocumentInvitation, parseCloudAccessTokenCreate, parseCloudAccessTokenRevoke, parseCloudAccountDelete, parseCloudDiscovery, parseCloudEmailChange, parseCloudLinkPath, parseCloudLocaleUpdate, parseCloudMFAEnable, parseCloudMFAVerify, parseCloudPasskeyDelete, parseCloudPasswordChange, parseCloudPictureUpload, parseCloudProfileUpdate, parseCloudSessionRevoke, parseCloudSocialLink, parseCloudTermsAcceptance, parseCloudUnlinkAuthenticationMethod, parseCommitImageUploads, parseCommitUpload, parseCommunityDownloadQuery, parseCreateDocument, parseCreateDocumentInvitation, parseCreateDocumentShare, parseCreateInvitationContinuation, parseCreateServicesToken, parseCreateUpload, parseCreateWorkspace, parseCreateWorkspaceInvitation, parseDuplicateDocumentVersion, parseFileDocumentReport, parsePutDocumentGrant, parseRequestImageLinks, parseRequestImageUploads, parseRequestSharedImageLinks, parseResolveDocumentShare, parseSaveDocumentVersion, parseSearchRequest, parseUpdateDocumentShare, parseUpdateDocumentVersion, parseUpdateWorkspace, parseUpdateWorkspaceMember, parseUsageQuery, presenceName, putDocumentGrantSchema, relayClientMessages, relayServerMessages, requestImageLinksSchema, requestImageUploadsSchema, requestSharedImageLinksSchema, resolveDocumentShareSchema, resolvedDocumentShareSchema, restoredDocumentSchema, saveDocumentVersionSchema, searchPricingSchema, searchRequestSchema, searchResponseSchema, searchResultSchema, sendsTokenSafely, serviceCatalogSchema, serviceErrorCodeSchema, serviceErrorSchema, servicesTokenClaimsSchema, servicesTokenSchema, sharedDocumentSchema, transactionalEmailAdminSchema, trashSchema, trashedDocumentSchema, updateDocumentShareSchema, updateDocumentVersionSchema, updateWorkspaceMemberSchema, updateWorkspaceSchema, usageEntrySchema, usagePageSchema, usageQuerySchema, workspaceEntitlementsSchema, workspaceInvitationSchema, workspaceListSchema, workspaceMemberSchema, workspaceMembersSchema, workspaceRoleSchema, workspaceSummarySchema, workspaceUsageSchema };
|
|
1452
1999
|
|
|
1453
2000
|
//# sourceMappingURL=contract2.js.map
|