@open-pencil/cloud 0.17.0-beta.4 → 0.17.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/bin/server.mjs +1 -1
- package/dist/bin/server.mjs.map +1 -1
- package/dist/bin/services.mjs +1 -1
- package/dist/bin/services.mjs.map +1 -1
- package/dist/client.d.ts +783 -47
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1651 -382
- package/dist/client.js.map +1 -1
- package/dist/contract.d.ts +2 -2
- package/dist/contract.js +2 -2
- package/dist/contract2.js +701 -45
- package/dist/contract2.js.map +1 -1
- package/dist/email.d.ts +2138 -34
- package/dist/email.d.ts.map +1 -1
- package/dist/email.js +4343 -306
- package/dist/email.js.map +1 -1
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +61 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +1338 -44
- package/dist/index.d.ts.map +1 -1
- package/dist/index2.d.ts +45 -0
- package/dist/index2.d.ts.map +1 -0
- package/dist/listen.mjs +958 -340
- package/dist/listen.mjs.map +1 -1
- package/dist/runtime-cloudflare.d.ts +93 -0
- package/dist/runtime-cloudflare.d.ts.map +1 -0
- package/dist/runtime-cloudflare.js +18032 -0
- package/dist/runtime-cloudflare.js.map +1 -0
- package/dist/runtime-node.d.mts +12615 -5249
- package/dist/runtime-node.d.mts.map +1 -1
- package/dist/server.d.ts +17367 -8567
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +13587 -7333
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +11601 -5401
- package/dist/server.mjs.map +1 -1
- package/dist/server2.mjs +84 -62
- package/dist/server2.mjs.map +1 -1
- package/package.json +31 -5
- package/src/admin/api/routes.ts +263 -190
- package/src/admin/audit/service.ts +11 -3
- package/src/admin/bootstrap.ts +86 -0
- package/src/admin/documents/service.ts +195 -10
- package/src/admin/email/service.ts +2 -1
- package/src/admin/enrollment/email.ts +17 -3
- package/src/admin/enrollment/service.ts +71 -10
- package/src/admin/errors.ts +5 -0
- package/src/admin/index.ts +1 -0
- package/src/admin/reports/service.ts +15 -3
- package/src/admin/schema.ts +6 -5
- package/src/admin/users/service.ts +173 -16
- package/src/client/api.ts +52 -473
- package/src/client/auth/client.ts +22 -3
- package/src/client/comments.ts +205 -0
- package/src/client/community.ts +40 -0
- package/src/client/device-authorization.ts +4 -20
- package/src/client/discovery.ts +39 -11
- package/src/client/documents.ts +160 -0
- package/src/client/files/archive.ts +60 -0
- package/src/client/files/checksum.ts +7 -0
- package/src/client/files/download.ts +122 -0
- package/src/client/files/images.ts +89 -0
- package/src/client/files/index.ts +15 -0
- package/src/client/files/objects.ts +173 -0
- package/src/client/files/save.ts +79 -0
- package/src/client/index.ts +4 -0
- package/src/client/portal/account.ts +73 -3
- package/src/client/portal/administration.ts +52 -5
- package/src/client/portal/request.ts +6 -2
- package/src/client/response.ts +21 -0
- package/src/client/schema.ts +8 -0
- package/src/client/services.ts +23 -18
- package/src/client/sharing.ts +262 -0
- package/src/client/tour.ts +44 -0
- package/src/client/versions.ts +110 -0
- package/src/contract/account.ts +111 -11
- package/src/contract/admin/index.ts +48 -3
- package/src/contract/billing.ts +235 -0
- package/src/contract/collaboration.ts +5 -0
- package/src/contract/comments.ts +223 -0
- package/src/contract/community.ts +60 -0
- package/src/contract/discovery.ts +94 -5
- package/src/contract/entitlements.ts +10 -0
- package/src/contract/index.ts +64 -5
- package/src/contract/links.ts +62 -4
- package/src/contract/locale.ts +27 -0
- package/src/contract/portal.ts +12 -1
- package/src/contract/relay.ts +3 -1
- package/src/contract/routes.ts +10 -0
- package/src/contract/services.ts +62 -20
- package/src/contract/workspaces.ts +5 -0
- package/src/email/i18n.ts +174 -0
- package/src/email/index.ts +13 -2
- package/src/email/locales/ar.json +169 -0
- package/src/email/locales/de.json +169 -0
- package/src/email/locales/es.json +169 -0
- package/src/email/locales/fr.json +169 -0
- package/src/email/locales/it.json +169 -0
- package/src/email/locales/ja.json +169 -0
- package/src/email/locales/pl.json +169 -0
- package/src/email/locales/pt-br.json +169 -0
- package/src/email/locales/ru.json +169 -0
- package/src/email/locales/zh-cn.json +169 -0
- package/src/email/messages.ts +235 -0
- package/src/email/render.ts +160 -276
- package/src/email/samples.ts +142 -0
- package/src/email/schema.ts +98 -8
- package/src/email/templates/BrandEmail.vue +56 -0
- package/src/email/templates/CommentNotification.vue +39 -0
- package/src/email/templates/DocumentBlocked.vue +45 -0
- package/src/email/templates/DocumentInvitation.vue +24 -0
- package/src/email/templates/DocumentReport.vue +32 -0
- package/src/email/templates/DocumentReportDecided.vue +36 -0
- package/src/email/templates/DocumentReportReceived.vue +18 -0
- package/src/email/templates/DocumentRestored.vue +24 -0
- package/src/email/templates/EmailChangeRequested.vue +24 -0
- package/src/email/templates/EmailRoot.vue +19 -0
- package/src/email/templates/EmailText.vue +9 -0
- package/src/email/templates/EmailVerification.vue +38 -0
- package/src/email/templates/EnrollmentInvitation.vue +53 -0
- package/src/email/templates/EnrollmentNotification.vue +24 -0
- package/src/email/templates/EnrollmentUpdate.vue +52 -0
- package/src/email/templates/NewSignIn.vue +37 -0
- package/src/email/templates/PasswordChanged.vue +22 -0
- package/src/email/templates/PasswordReset.vue +23 -0
- package/src/email/templates/StorageLimitReached.vue +28 -0
- package/src/email/templates/TwoStepChanged.vue +47 -0
- package/src/email/templates/WaitlistConfirmation.vue +29 -0
- package/src/email/templates/WorkspaceInvitation.vue +28 -0
- package/src/email/templates/brand.ts +15 -61
- package/src/email/templates/localization.ts +17 -0
- package/src/errors/index.ts +6 -0
- package/src/{server/errors → errors}/posthog.ts +28 -4
- package/src/global.d.ts +7 -0
- package/src/runtime/cloudflare/email.ts +2 -0
- package/src/runtime/cloudflare/relay/index.ts +28 -7
- package/src/runtime/cloudflare/tsconfig.json +2 -1
- package/src/runtime/cloudflare/worker.ts +14 -1
- package/src/runtime/cloudflare/xml.ts +12 -0
- package/src/runtime/node/admin.ts +51 -47
- package/src/runtime/node/cleanup.ts +5 -1
- package/src/runtime/node/email/runtime.ts +1 -0
- package/src/runtime/node/email/transport.ts +14 -10
- package/src/runtime/node/main.ts +1 -1
- package/src/runtime/node/server.ts +20 -4
- package/src/runtime/node/services/main.ts +1 -1
- package/src/runtime/posthog/errors.ts +5 -2
- package/src/runtime/s3/objects.ts +17 -0
- package/src/runtime/site/community.ts +101 -0
- package/src/runtime/site/server.ts +17 -1
- package/src/server/account/actions.ts +3 -1
- package/src/server/account/deletion.ts +40 -4
- package/src/server/account/routes.ts +305 -253
- package/src/server/account/tokens.ts +57 -0
- package/src/server/api/router.ts +44 -6
- package/src/server/app/checks.ts +89 -0
- package/src/server/app/cors.ts +44 -0
- package/src/server/app/editors.ts +20 -0
- package/src/server/app/index.ts +128 -0
- package/src/server/app/indexing.ts +40 -0
- package/src/server/app/limiters.ts +53 -0
- package/src/server/app/routes.ts +123 -0
- package/src/server/app/services.ts +219 -0
- package/src/server/auth/access-control.ts +13 -8
- package/src/server/auth/access-tokens.ts +62 -0
- package/src/server/auth/account.ts +13 -12
- package/src/server/auth/activity.ts +7 -2
- package/src/server/auth/adapter.ts +36 -3
- package/src/server/auth/email.ts +33 -18
- package/src/server/auth/endpoints.ts +4 -0
- package/src/server/auth/enrollment.ts +116 -0
- package/src/server/auth/factory.ts +165 -189
- package/src/server/auth/index.ts +1 -1
- package/src/server/auth/logger.ts +23 -0
- package/src/server/auth/methods.ts +162 -0
- package/src/server/auth/mfa-assurance.ts +190 -2
- package/src/server/auth/passwords.ts +43 -0
- package/src/server/auth/rate-limit.ts +31 -0
- package/src/server/auth/runtime.ts +19 -5
- package/src/server/auth/session.ts +2 -0
- package/src/server/auth/social-providers.ts +70 -24
- package/src/server/billing/index.ts +8 -0
- package/src/server/billing/notify.ts +55 -0
- package/src/server/billing/routes.ts +27 -0
- package/src/server/billing/seats.ts +17 -0
- package/src/server/billing/tokens.ts +37 -0
- package/src/server/cleanup/configured.ts +16 -3
- package/src/server/cleanup/documents.ts +5 -2
- package/src/server/cleanup/revisions.ts +6 -3
- package/src/server/cleanup/uploads.ts +2 -1
- package/src/server/cleanup/worker.ts +10 -1
- package/src/server/collaboration/relay/connection.ts +7 -2
- package/src/server/collaboration/relay/hub.ts +80 -166
- package/src/server/collaboration/relay/room.ts +154 -0
- package/src/server/collaboration/routes.ts +8 -5
- package/src/server/collaboration/service.ts +21 -2
- package/src/server/comments/index.ts +9 -0
- package/src/server/comments/notify.ts +277 -0
- package/src/server/comments/routes.ts +352 -0
- package/src/server/comments/rows.ts +249 -0
- package/src/server/comments/service.ts +570 -0
- package/src/server/community/index.ts +2 -0
- package/src/server/community/routes.ts +93 -0
- package/src/server/community/service.ts +134 -0
- package/src/server/config/deployment.ts +35 -10
- package/src/server/config/index.ts +2 -2
- package/src/server/config/public.ts +25 -6
- package/src/server/config/schema.ts +53 -293
- package/src/server/config/toml/schema.ts +330 -0
- package/src/server/db/index.ts +3 -1
- package/src/server/db/migrate.ts +33 -1
- package/src/server/db/migrations/009_access_tokens.ts +47 -0
- package/src/server/db/migrations/010_storage_limit_notices.ts +50 -0
- package/src/server/db/migrations/011_account_ids.ts +30 -0
- package/src/server/db/migrations/012_email_locales.ts +34 -0
- package/src/server/db/migrations/013_document_block_emails.ts +40 -0
- package/src/server/db/migrations/014_report_replies.ts +28 -0
- package/src/server/db/migrations/015_comments.ts +57 -0
- package/src/server/db/migrations/016_comment_notifications.ts +76 -0
- package/src/server/db/migrations/017_invitation_emails.ts +19 -0
- package/src/server/db/migrations/018_enrollment_source.ts +17 -0
- package/src/server/db/migrations/schema.ts +26 -1
- package/src/server/db/tables.ts +122 -3
- package/src/server/db/users.ts +22 -0
- package/src/server/documents/access.ts +17 -0
- package/src/server/documents/images.ts +6 -1
- package/src/server/documents/index.ts +1 -1
- package/src/server/documents/limits.ts +7 -1
- package/src/server/documents/routes.ts +12 -12
- package/src/server/documents/service.ts +31 -407
- package/src/server/documents/summary.ts +15 -0
- package/src/server/documents/uploads.ts +450 -0
- package/src/server/documents/versions/routes.ts +7 -8
- package/src/server/documents/versions/service.ts +86 -26
- package/src/server/email/invitations.ts +1 -0
- package/src/server/email/service.ts +39 -6
- package/src/server/email/types.ts +13 -0
- package/src/server/errors/index.ts +49 -12
- package/src/server/index.ts +27 -6
- package/src/server/internal/routes.ts +8 -2
- package/src/server/internal/service.ts +10 -0
- package/src/server/invitations/budget.ts +3 -1
- package/src/server/invitations/index.ts +1 -0
- package/src/server/invitations/links.ts +6 -0
- package/src/server/invitations/types.ts +5 -1
- package/src/server/objects/types.ts +5 -0
- package/src/server/pictures/service.ts +3 -1
- package/src/server/policy/configured.ts +9 -3
- package/src/server/policy/database.ts +13 -2
- package/src/server/policy/policy.ts +39 -12
- package/src/server/policy/service.ts +71 -52
- package/src/server/policy/storage.ts +33 -0
- package/src/server/policy/workspace.ts +5 -2
- package/src/server/quota/index.ts +6 -0
- package/src/server/quota/notices.ts +121 -0
- package/src/server/quota/storage.ts +5 -0
- package/src/server/rate-limit/middleware.ts +4 -0
- package/src/server/reports/index.ts +1 -0
- package/src/server/reports/replies.ts +55 -0
- package/src/server/reports/routes.ts +5 -3
- package/src/server/reports/service.ts +27 -3
- package/src/server/services/routes.ts +2 -2
- package/src/server/sharing/capabilities/service.ts +3 -4
- package/src/server/sharing/document-routes.ts +3 -3
- package/src/server/sharing/invitations/service.ts +17 -8
- package/src/server/sharing/routes.ts +15 -15
- package/src/server/validation.ts +35 -24
- package/src/server/workspaces/members.ts +57 -31
- package/src/server/workspaces/repository.ts +23 -12
- package/src/server/workspaces/routes.ts +8 -8
- package/src/services/app.ts +31 -22
- package/src/services/config.ts +48 -8
- package/src/services/metering.ts +15 -27
- package/src/services/usage.ts +6 -14
- package/src/email/templates/document-invitation.ts +0 -35
- package/src/email/templates/enrollment.ts +0 -27
- package/src/email/templates/layout.ts +0 -18
- package/src/server/app.ts +0 -453
package/dist/contract2.js
CHANGED
|
@@ -5,17 +5,21 @@ import { Inflate, deflateSync } from "fflate";
|
|
|
5
5
|
import * as decoding from "lib0/decoding";
|
|
6
6
|
import * as encoding from "lib0/encoding";
|
|
7
7
|
import * as Y from "yjs";
|
|
8
|
+
import compareVersions from "semver/functions/compare.js";
|
|
9
|
+
import parseVersion from "semver/functions/parse.js";
|
|
8
10
|
import { encodeParam, parseURL, withFragment, withQuery } from "ufo";
|
|
9
11
|
//#region src/contract/account.ts
|
|
10
12
|
/**
|
|
11
13
|
* Where an account stands: it may use the server, waits for an administrator, was refused or had
|
|
12
|
-
* its access taken back,
|
|
14
|
+
* its access taken back, has to prove its second step in this session, as after signing in through
|
|
15
|
+
* a linked account such as Google, or has to accept the server's current terms first.
|
|
13
16
|
*/
|
|
14
17
|
const cloudAccountStateSchema = v.picklist([
|
|
15
18
|
"active",
|
|
16
19
|
"pending",
|
|
17
20
|
"rejected",
|
|
18
21
|
"revoked",
|
|
22
|
+
"two-step",
|
|
19
23
|
"terms"
|
|
20
24
|
]);
|
|
21
25
|
const cloudIdentitySchema = v.object({
|
|
@@ -32,27 +36,51 @@ const cloudAccountStatusResponseSchema = v.object({
|
|
|
32
36
|
});
|
|
33
37
|
/** Accepting the server's terms: the version the person read, which must be the current one. */
|
|
34
38
|
const cloudTermsAcceptanceSchema = v.object({ version: v.pipe(v.string(), v.minLength(1)) });
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
/**
|
|
40
|
+
* The providers a person can sign in with besides a password, which this editor has buttons for,
|
|
41
|
+
* in the order it shows them. Every list of providers in Cloud derives from this one.
|
|
42
|
+
*/
|
|
43
|
+
const CLOUD_SOCIAL_PROVIDERS = [
|
|
37
44
|
"google",
|
|
38
|
-
"apple"
|
|
39
|
-
|
|
45
|
+
"apple",
|
|
46
|
+
"github"
|
|
47
|
+
];
|
|
48
|
+
const cloudSocialProviderSchema = v.picklist(CLOUD_SOCIAL_PROVIDERS);
|
|
49
|
+
/** Each provider's name, as its owner writes it in every language. */
|
|
50
|
+
const CLOUD_SOCIAL_PROVIDER_NAMES = {
|
|
51
|
+
google: "Google",
|
|
52
|
+
apple: "Apple",
|
|
53
|
+
github: "GitHub"
|
|
54
|
+
};
|
|
55
|
+
const cloudAuthenticationProviderSchema = v.picklist(["credential", ...CLOUD_SOCIAL_PROVIDERS]);
|
|
40
56
|
const cloudAuthenticationMethodSchema = v.object({
|
|
41
57
|
id: v.string(),
|
|
42
58
|
provider: cloudAuthenticationProviderSchema,
|
|
43
59
|
createdAt: v.string(),
|
|
44
60
|
canUnlink: v.boolean()
|
|
45
61
|
});
|
|
62
|
+
/** Whether this editor knows `provider`, so a newer server's other providers can be left out. */
|
|
63
|
+
function isKnownSocialProvider(provider) {
|
|
64
|
+
return CLOUD_SOCIAL_PROVIDERS.includes(provider);
|
|
65
|
+
}
|
|
66
|
+
/** Whether `provider` is a way to sign in this editor knows: a password or a known provider. */
|
|
67
|
+
function isKnownAuthenticationProvider(provider) {
|
|
68
|
+
return provider === "credential" || isKnownSocialProvider(provider);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A newer server may list a provider this editor has no words or button for: those entries are
|
|
72
|
+
* left out rather than failing the whole response, and anything else malformed still fails.
|
|
73
|
+
*/
|
|
46
74
|
const cloudAuthenticationMethodsResponseSchema = v.object({
|
|
47
|
-
methods: v.array(cloudAuthenticationMethodSchema),
|
|
48
|
-
availableSocialProviders: v.array(v.
|
|
75
|
+
methods: v.pipe(v.array(v.looseObject({ provider: v.string() })), v.filterItems((method) => isKnownAuthenticationProvider(method.provider)), v.array(cloudAuthenticationMethodSchema)),
|
|
76
|
+
availableSocialProviders: v.pipe(v.array(v.string()), v.filterItems(isKnownSocialProvider), v.array(cloudSocialProviderSchema))
|
|
49
77
|
});
|
|
50
78
|
const cloudPasswordChangeSchema = v.object({
|
|
51
79
|
currentPassword: v.string(),
|
|
52
80
|
newPassword: v.string()
|
|
53
81
|
});
|
|
54
82
|
const cloudSocialLinkSchema = v.object({
|
|
55
|
-
provider:
|
|
83
|
+
provider: cloudSocialProviderSchema,
|
|
56
84
|
callbackURL: v.pipe(v.string(), v.url())
|
|
57
85
|
});
|
|
58
86
|
const cloudSocialLinkResponseSchema = v.object({ url: v.pipe(v.string(), v.url()) });
|
|
@@ -64,6 +92,7 @@ const accountSecurityErrorCodeSchema = v.picklist([
|
|
|
64
92
|
"last_authentication_method",
|
|
65
93
|
"session_not_fresh",
|
|
66
94
|
"authentication_method_failed",
|
|
95
|
+
"code_invalid",
|
|
67
96
|
"email_unchanged",
|
|
68
97
|
"email_change_unavailable",
|
|
69
98
|
"current_session",
|
|
@@ -98,6 +127,40 @@ const cloudPasskeySchema = v.object({
|
|
|
98
127
|
});
|
|
99
128
|
const cloudPasskeysResponseSchema = v.object({ passkeys: v.array(cloudPasskeySchema) });
|
|
100
129
|
const cloudPasskeyDeleteSchema = v.object({ id: v.string() });
|
|
130
|
+
/**
|
|
131
|
+
* Personal access tokens: an account's own credentials for scripts and CI, sent as
|
|
132
|
+
* `Authorization: Bearer <token>`. A token acts as its account on the document API only; it never
|
|
133
|
+
* changes how the account is reached, makes other tokens, or reaches administration.
|
|
134
|
+
*/
|
|
135
|
+
const CLOUD_ACCESS_TOKEN_PREFIX = "opc_";
|
|
136
|
+
const CLOUD_ACCESS_TOKEN_NAME_MAX_LENGTH = 64;
|
|
137
|
+
const CLOUD_ACCESS_TOKEN_MAX_DAYS = 365;
|
|
138
|
+
const cloudAccessTokenSchema = v.object({
|
|
139
|
+
id: v.string(),
|
|
140
|
+
name: v.string(),
|
|
141
|
+
/** The token's first characters, prefix included, to tell tokens apart; never the whole token. */
|
|
142
|
+
start: v.nullable(v.string()),
|
|
143
|
+
createdAt: v.string(),
|
|
144
|
+
expiresAt: v.nullable(v.string()),
|
|
145
|
+
lastUsedAt: v.nullable(v.string())
|
|
146
|
+
});
|
|
147
|
+
const cloudAccessTokensResponseSchema = v.object({ tokens: v.array(cloudAccessTokenSchema) });
|
|
148
|
+
const cloudAccessTokenCreateSchema = v.object({
|
|
149
|
+
name: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(64)),
|
|
150
|
+
expiresInDays: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(365))
|
|
151
|
+
});
|
|
152
|
+
/** A new token, the only time the whole of it is shown. */
|
|
153
|
+
const cloudAccessTokenCreatedResponseSchema = v.object({
|
|
154
|
+
token: v.pipe(v.string(), v.startsWith(CLOUD_ACCESS_TOKEN_PREFIX)),
|
|
155
|
+
accessToken: cloudAccessTokenSchema
|
|
156
|
+
});
|
|
157
|
+
const cloudAccessTokenRevokeSchema = v.object({ id: v.pipe(v.string(), v.minLength(1)) });
|
|
158
|
+
function parseCloudAccessTokenCreate(input) {
|
|
159
|
+
return v.parse(cloudAccessTokenCreateSchema, input);
|
|
160
|
+
}
|
|
161
|
+
function parseCloudAccessTokenRevoke(input) {
|
|
162
|
+
return v.parse(cloudAccessTokenRevokeSchema, input);
|
|
163
|
+
}
|
|
101
164
|
function parseCloudTermsAcceptance(input) {
|
|
102
165
|
return v.parse(cloudTermsAcceptanceSchema, input);
|
|
103
166
|
}
|
|
@@ -151,21 +214,24 @@ const cloudEmailChangeSchema = v.object({
|
|
|
151
214
|
callbackURL: v.pipe(v.string(), v.url())
|
|
152
215
|
});
|
|
153
216
|
/** How a sign-in was made: the method it used, or the desktop app's approved code. */
|
|
154
|
-
const
|
|
217
|
+
const SIGN_IN_METHODS = [
|
|
155
218
|
"password",
|
|
156
|
-
|
|
157
|
-
"apple",
|
|
219
|
+
...CLOUD_SOCIAL_PROVIDERS,
|
|
158
220
|
"passkey",
|
|
159
221
|
"two-step",
|
|
160
222
|
"email-link",
|
|
161
223
|
"desktop",
|
|
162
224
|
"other"
|
|
163
|
-
]
|
|
225
|
+
];
|
|
226
|
+
const cloudSignInMethodSchema = v.picklist(SIGN_IN_METHODS);
|
|
227
|
+
/** A method a newer server names that this editor does not know reads as `other`; a value that is
|
|
228
|
+
* not a method name at all still fails. */
|
|
229
|
+
const signInMethodResponseSchema = v.pipe(v.string(), v.transform((method) => v.is(cloudSignInMethodSchema, method) ? method : "other"));
|
|
164
230
|
const cloudAccountSessionSchema = v.object({
|
|
165
231
|
id: v.string(),
|
|
166
232
|
/** The session this request was made with. */
|
|
167
233
|
current: v.boolean(),
|
|
168
|
-
method: v.nullable(
|
|
234
|
+
method: v.nullable(signInMethodResponseSchema),
|
|
169
235
|
ipAddress: v.nullable(v.string()),
|
|
170
236
|
/** The browser and system the server read from the client's user agent, such as `Chrome 141`. */
|
|
171
237
|
browser: v.nullable(v.string()),
|
|
@@ -178,7 +244,7 @@ const cloudAccountSessionsResponseSchema = v.object({ sessions: v.array(cloudAcc
|
|
|
178
244
|
const cloudSessionRevokeSchema = v.object({ sessionId: v.pipe(v.string(), v.minLength(1)) });
|
|
179
245
|
const cloudSignInSchema = v.object({
|
|
180
246
|
id: v.string(),
|
|
181
|
-
method:
|
|
247
|
+
method: signInMethodResponseSchema,
|
|
182
248
|
ipAddress: v.nullable(v.string()),
|
|
183
249
|
/** The browser and system the server read from the client's user agent, such as `Chrome 141`. */
|
|
184
250
|
browser: v.nullable(v.string()),
|
|
@@ -230,6 +296,26 @@ function parseCloudSessionRevoke(input) {
|
|
|
230
296
|
return v.parse(cloudSessionRevokeSchema, input);
|
|
231
297
|
}
|
|
232
298
|
//#endregion
|
|
299
|
+
//#region src/contract/locale.ts
|
|
300
|
+
/** Whether `tag` is a well-formed BCP 47 language tag: `de`, `pt-BR`, `zh-Hant-TW`. */
|
|
301
|
+
function isLanguageTag(tag) {
|
|
302
|
+
try {
|
|
303
|
+
return Intl.getCanonicalLocales(tag).length === 1;
|
|
304
|
+
} catch {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* A language as the app names it, which the server writes email in when it has that language, or
|
|
310
|
+
* the nearest it has, and otherwise in English.
|
|
311
|
+
*/
|
|
312
|
+
const cloudLanguageTagSchema = v.pipe(v.string(), v.maxLength(35), v.check(isLanguageTag, "Not a language tag"));
|
|
313
|
+
/** The language an account's email is written in, as the app last said it uses. */
|
|
314
|
+
const cloudLocaleUpdateSchema = v.object({ locale: cloudLanguageTagSchema });
|
|
315
|
+
function parseCloudLocaleUpdate(input) {
|
|
316
|
+
return v.parse(cloudLocaleUpdateSchema, input);
|
|
317
|
+
}
|
|
318
|
+
//#endregion
|
|
233
319
|
//#region src/contract/services.ts
|
|
234
320
|
/**
|
|
235
321
|
* The contract between editors, Cloud, and the services Cloud advertises: AI models today, and
|
|
@@ -255,13 +341,12 @@ const CLOUD_SERVICES_API_PATHS = {
|
|
|
255
341
|
usage: "/v1/usage",
|
|
256
342
|
search: "/v1/search"
|
|
257
343
|
};
|
|
258
|
-
const urlSchema = v.pipe(v.string(), v.url());
|
|
259
|
-
const creditsSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
344
|
+
const urlSchema$1 = v.pipe(v.string(), v.url());
|
|
345
|
+
const creditsSchema$1 = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
260
346
|
const cloudServicesDiscoverySchema = v.object({
|
|
261
|
-
endpoint: urlSchema,
|
|
347
|
+
endpoint: urlSchema$1,
|
|
262
348
|
contractVersion: v.literal("1")
|
|
263
349
|
});
|
|
264
|
-
const cloudBillingDiscoverySchema = v.object({ portalURL: urlSchema });
|
|
265
350
|
const createServicesTokenSchema = v.object({ workspaceId: v.pipe(v.string(), v.uuid()) });
|
|
266
351
|
function parseCreateServicesToken(input) {
|
|
267
352
|
return v.parse(createServicesTokenSchema, input);
|
|
@@ -272,18 +357,17 @@ const servicesTokenSchema = v.object({
|
|
|
272
357
|
});
|
|
273
358
|
/** What a service may rely on once a token's signature, issuer, audience, and expiry check. */
|
|
274
359
|
const servicesTokenClaimsSchema = v.object({
|
|
275
|
-
iss: urlSchema,
|
|
360
|
+
iss: urlSchema$1,
|
|
276
361
|
aud: v.literal(CLOUD_SERVICES_TOKEN_AUDIENCE),
|
|
277
362
|
sub: v.pipe(v.string(), v.minLength(1)),
|
|
278
363
|
workspaceId: v.pipe(v.string(), v.uuid()),
|
|
279
364
|
/**
|
|
280
365
|
* The account whose credits the request spends: the workspace's owner, whose allowance every
|
|
281
|
-
* workspace they own shares.
|
|
282
|
-
* a relay takes as the workspace's own allowance, as such a Cloud meant.
|
|
366
|
+
* workspace they own shares.
|
|
283
367
|
*/
|
|
284
|
-
accountId: v.
|
|
368
|
+
accountId: v.pipe(v.string(), v.minLength(1)),
|
|
285
369
|
/** Credits the owner's plan grants each month; `null` when Cloud sets no allowance. */
|
|
286
|
-
monthlyCreditAllowance: v.nullable(creditsSchema),
|
|
370
|
+
monthlyCreditAllowance: v.nullable(creditsSchema$1),
|
|
287
371
|
iat: v.pipe(v.number(), v.integer()),
|
|
288
372
|
exp: v.pipe(v.number(), v.integer())
|
|
289
373
|
});
|
|
@@ -291,8 +375,8 @@ const chatModelSchema = v.object({
|
|
|
291
375
|
id: v.pipe(v.string(), v.minLength(1)),
|
|
292
376
|
label: v.pipe(v.string(), v.minLength(1)),
|
|
293
377
|
/** Credits per million input and output tokens. */
|
|
294
|
-
creditsPerMillionInputTokens: creditsSchema,
|
|
295
|
-
creditsPerMillionOutputTokens: creditsSchema,
|
|
378
|
+
creditsPerMillionInputTokens: creditsSchema$1,
|
|
379
|
+
creditsPerMillionOutputTokens: creditsSchema$1,
|
|
296
380
|
contextTokens: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
297
381
|
capabilities: v.object({
|
|
298
382
|
reasoning: v.boolean(),
|
|
@@ -301,19 +385,46 @@ const chatModelSchema = v.object({
|
|
|
301
385
|
})
|
|
302
386
|
});
|
|
303
387
|
/** What one web search costs; a service without search leaves it out of its catalog. */
|
|
304
|
-
const searchPricingSchema = v.object({ creditsPerRequest: creditsSchema });
|
|
305
|
-
const
|
|
388
|
+
const searchPricingSchema = v.object({ creditsPerRequest: creditsSchema$1 });
|
|
389
|
+
const modelIDSchema = v.pipe(v.string(), v.minLength(1));
|
|
390
|
+
/**
|
|
391
|
+
* The model the service recommends for each of the editor's roles: Design runs the chat, Review
|
|
392
|
+
* critiques designs, Fast does quick tasks such as naming conversations, and Vision reads images.
|
|
393
|
+
* An editor signed in to the service with no model of its own yet sets itself up with them, so
|
|
394
|
+
* nobody has to choose one. Vision `null` recommends none, and the editor leaves it unassigned.
|
|
395
|
+
*/
|
|
396
|
+
const roleModelsSchema = v.object({
|
|
397
|
+
design: modelIDSchema,
|
|
398
|
+
review: modelIDSchema,
|
|
399
|
+
fast: modelIDSchema,
|
|
400
|
+
vision: v.nullable(modelIDSchema)
|
|
401
|
+
});
|
|
402
|
+
const serviceCatalogSchema = v.pipe(v.object({
|
|
306
403
|
models: v.array(chatModelSchema),
|
|
307
|
-
defaultModelID:
|
|
404
|
+
defaultModelID: modelIDSchema,
|
|
405
|
+
/**
|
|
406
|
+
* Absent from a service that predates it, or whose default model can't run the chat. Editors
|
|
407
|
+
* then use `defaultModelID` for every role, except Vision when that model reads no images,
|
|
408
|
+
* and set nothing up when it calls no tools.
|
|
409
|
+
*/
|
|
410
|
+
roleModels: v.optional(roleModelsSchema),
|
|
308
411
|
search: v.optional(searchPricingSchema)
|
|
309
|
-
})
|
|
412
|
+
}), v.check(({ models, roleModels }) => {
|
|
413
|
+
if (!roleModels) return true;
|
|
414
|
+
const can = (id, capability) => {
|
|
415
|
+
if (id === null) return true;
|
|
416
|
+
const model = models.find((candidate) => candidate.id === id);
|
|
417
|
+
return model !== void 0 && (capability === null || model.capabilities[capability]);
|
|
418
|
+
};
|
|
419
|
+
return can(roleModels.design, "tools") && can(roleModels.review, null) && can(roleModels.fast, "tools") && can(roleModels.vision, "vision");
|
|
420
|
+
}, "A recommended model is not in the catalog or cannot do its role"));
|
|
310
421
|
const creditBucketSchema = v.object({
|
|
311
422
|
kind: v.picklist([
|
|
312
423
|
"allowance",
|
|
313
424
|
"purchased",
|
|
314
425
|
"grant"
|
|
315
426
|
]),
|
|
316
|
-
remaining: creditsSchema,
|
|
427
|
+
remaining: creditsSchema$1,
|
|
317
428
|
expiresAt: v.nullable(v.pipe(v.string(), v.isoTimestamp()))
|
|
318
429
|
});
|
|
319
430
|
/**
|
|
@@ -322,7 +433,7 @@ const creditBucketSchema = v.object({
|
|
|
322
433
|
*/
|
|
323
434
|
const creditWalletSchema = v.object({
|
|
324
435
|
/** Credits left to spend; `null` when the service sets no limit. */
|
|
325
|
-
balance: v.nullable(creditsSchema),
|
|
436
|
+
balance: v.nullable(creditsSchema$1),
|
|
326
437
|
/** Spent first to last. */
|
|
327
438
|
buckets: v.array(creditBucketSchema)
|
|
328
439
|
});
|
|
@@ -336,7 +447,7 @@ const usageEntrySchema = v.object({
|
|
|
336
447
|
]),
|
|
337
448
|
modelID: v.nullable(v.string()),
|
|
338
449
|
userId: v.pipe(v.string(), v.minLength(1)),
|
|
339
|
-
credits: creditsSchema
|
|
450
|
+
credits: creditsSchema$1
|
|
340
451
|
});
|
|
341
452
|
/** The most results one search returns. */
|
|
342
453
|
const MAX_SEARCH_RESULTS = 10;
|
|
@@ -351,7 +462,7 @@ function parseSearchRequest(input) {
|
|
|
351
462
|
}
|
|
352
463
|
/** One page a search found, with the part of its text that answers the query. */
|
|
353
464
|
const searchResultSchema = v.object({
|
|
354
|
-
url: v.pipe(urlSchema, v.regex(/^https?:\/\//i, "A search result links to an HTTP(S) page")),
|
|
465
|
+
url: v.pipe(urlSchema$1, v.regex(/^https?:\/\//i, "A search result links to an HTTP(S) page")),
|
|
355
466
|
title: v.string(),
|
|
356
467
|
publishedAt: v.nullable(v.pipe(v.string(), v.isoTimestamp())),
|
|
357
468
|
author: v.nullable(v.string()),
|
|
@@ -390,6 +501,179 @@ const SERVICE_ERROR_STATUS = {
|
|
|
390
501
|
capability_unavailable: 404,
|
|
391
502
|
rate_limited: 429
|
|
392
503
|
};
|
|
504
|
+
/**
|
|
505
|
+
* Whether a bearer token may travel to `url`: over HTTPS, or in the clear only to a loopback
|
|
506
|
+
* address, for development. Only literal addresses count, since a name such as `localhost` is
|
|
507
|
+
* whatever the resolver answers. Services and billing tokens act as the account until they expire.
|
|
508
|
+
*/
|
|
509
|
+
function sendsTokenSafely(url) {
|
|
510
|
+
const { protocol, hostname } = new URL(url);
|
|
511
|
+
if (protocol === "https:") return true;
|
|
512
|
+
if (protocol !== "http:") return false;
|
|
513
|
+
return hostname === "[::1]" || /^127(\.\d{1,3}){3}$/.test(hostname);
|
|
514
|
+
}
|
|
515
|
+
//#endregion
|
|
516
|
+
//#region src/contract/billing.ts
|
|
517
|
+
/**
|
|
518
|
+
* The contract between Cloud, its editors, and the billing service a deployment advertises: what
|
|
519
|
+
* plans and credit packs it sells, and where an account buys them or manages what it has. Cloud
|
|
520
|
+
* only advertises the service and signs short-lived tokens for an account; the service talks to
|
|
521
|
+
* the payment provider, and sets the account's entitlements and credits as it is paid.
|
|
522
|
+
*/
|
|
523
|
+
const CLOUD_BILLING_CONTRACT_VERSION = "1";
|
|
524
|
+
/**
|
|
525
|
+
* The `aud` of the tokens Cloud signs for its billing service, with the services' signing key,
|
|
526
|
+
* whose public keys it publishes at `CLOUD_SERVICES_JWKS_PATH`.
|
|
527
|
+
*/
|
|
528
|
+
const CLOUD_BILLING_TOKEN_AUDIENCE = "openpencil-billing";
|
|
529
|
+
/**
|
|
530
|
+
* The page of a Cloud server where the signed-in person sees their plan, buys a plan or credits,
|
|
531
|
+
* and manages what they pay for; editors link to it whenever the server advertises billing.
|
|
532
|
+
*/
|
|
533
|
+
const CLOUD_ACCOUNT_PLAN_PATH = "/account/plan";
|
|
534
|
+
/**
|
|
535
|
+
* The plan page with billing's own pages opening at once: where billing sends someone whose
|
|
536
|
+
* session there ended, so Cloud signs them in to billing again.
|
|
537
|
+
*/
|
|
538
|
+
const CLOUD_ACCOUNT_BILLING_PATH = `${CLOUD_ACCOUNT_PLAN_PATH}?open=billing`;
|
|
539
|
+
/**
|
|
540
|
+
* The billing service's own pages, below the discovered `endpoint`: where Cloud's plan page sends
|
|
541
|
+
* the signed-in person, posting a billing token as the form field `token` to `session`, and the
|
|
542
|
+
* public pricing page. The service answers that post with `303 See Other`, never `307` or `308`,
|
|
543
|
+
* which a browser follows by posting the same body, the token, again to wherever they point.
|
|
544
|
+
*/
|
|
545
|
+
const CLOUD_BILLING_PAGE_PATHS = {
|
|
546
|
+
session: "/session",
|
|
547
|
+
pricing: "/pricing"
|
|
548
|
+
};
|
|
549
|
+
/**
|
|
550
|
+
* Where the billing service answers, below the discovered `endpoint`. Cloud posts to `seats`,
|
|
551
|
+
* with a billing token for the account as its bearer, whenever the people who can edit in that
|
|
552
|
+
* account's workspaces change; the service reads the count from Cloud's internal API.
|
|
553
|
+
*/
|
|
554
|
+
const CLOUD_BILLING_API_PATHS = {
|
|
555
|
+
base: "/v1",
|
|
556
|
+
catalog: "/v1/catalog",
|
|
557
|
+
seats: "/v1/seats",
|
|
558
|
+
account: "/v1/account",
|
|
559
|
+
checkout: "/v1/checkout",
|
|
560
|
+
portal: "/v1/portal"
|
|
561
|
+
};
|
|
562
|
+
const urlSchema = v.pipe(v.string(), v.url());
|
|
563
|
+
const idSchema = v.pipe(v.string(), v.regex(/^[a-z0-9][a-z0-9-]{0,62}$/));
|
|
564
|
+
const centsSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
565
|
+
const bytesSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
566
|
+
const creditsSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
567
|
+
/**
|
|
568
|
+
* What an account without a plan has: the deployment's free plan, which a pricing page compares
|
|
569
|
+
* the plans with.
|
|
570
|
+
*/
|
|
571
|
+
const billingFreePlanSchema = v.object({
|
|
572
|
+
/** The storage an account may use, or `null` for no limit. */
|
|
573
|
+
storageBytes: v.nullable(bytesSchema),
|
|
574
|
+
/** Whether the free plan includes services, such as AI and search. */
|
|
575
|
+
services: v.boolean(),
|
|
576
|
+
/** Credits granted each month with services, or `null` for no monthly limit. */
|
|
577
|
+
monthlyCredits: v.nullable(creditsSchema)
|
|
578
|
+
});
|
|
579
|
+
const cloudBillingDiscoverySchema = v.object({
|
|
580
|
+
endpoint: urlSchema,
|
|
581
|
+
contractVersion: v.literal("1"),
|
|
582
|
+
freePlan: v.optional(billingFreePlanSchema)
|
|
583
|
+
});
|
|
584
|
+
const billingTokenSchema = v.object({
|
|
585
|
+
token: v.pipe(v.string(), v.minLength(1)),
|
|
586
|
+
expiresAt: v.pipe(v.string(), v.isoTimestamp())
|
|
587
|
+
});
|
|
588
|
+
/**
|
|
589
|
+
* What the billing service may rely on once a token's signature, issuer, audience, and expiry
|
|
590
|
+
* check. The account is the signed-in user, who buys and manages only their own plan.
|
|
591
|
+
*/
|
|
592
|
+
const billingTokenClaimsSchema = v.object({
|
|
593
|
+
iss: urlSchema,
|
|
594
|
+
aud: v.literal(CLOUD_BILLING_TOKEN_AUDIENCE),
|
|
595
|
+
/** The account: the Cloud user whose plan and credits these are. */
|
|
596
|
+
sub: v.pipe(v.string(), v.minLength(1)),
|
|
597
|
+
/** Where the payment provider sends receipts and invoices. */
|
|
598
|
+
email: v.pipe(v.string(), v.email()),
|
|
599
|
+
iat: v.pipe(v.number(), v.integer()),
|
|
600
|
+
exp: v.pipe(v.number(), v.integer())
|
|
601
|
+
});
|
|
602
|
+
const seatCountSchema = v.pipe(v.number(), v.integer(), v.minValue(1));
|
|
603
|
+
/**
|
|
604
|
+
* A plan priced by the seat: everyone who can edit in the account's workspaces takes one, and the
|
|
605
|
+
* account pays for at least `minimum`. Every seat costs the price of the tier its count reaches,
|
|
606
|
+
* and adds its storage and credits to what the account shares.
|
|
607
|
+
*/
|
|
608
|
+
const billingSeatPricingSchema = v.object({
|
|
609
|
+
minimum: seatCountSchema,
|
|
610
|
+
/** From the fewest seats up: the first from 1, each later one from more seats. */
|
|
611
|
+
tiers: v.pipe(v.array(v.object({
|
|
612
|
+
fromSeats: seatCountSchema,
|
|
613
|
+
unitPriceCents: centsSchema
|
|
614
|
+
})), v.minLength(1), v.check((tiers) => tiers[0]?.fromSeats === 1, "The first seat tier starts at one seat"), v.check((tiers) => tiers.every((tier, index) => index === 0 || tier.fromSeats > (tiers[index - 1]?.fromSeats ?? 0)), "Seat tiers start at more seats each")),
|
|
615
|
+
storageBytesPerSeat: bytesSchema,
|
|
616
|
+
monthlyCreditsPerSeat: creditsSchema
|
|
617
|
+
});
|
|
618
|
+
/**
|
|
619
|
+
* A plan an account subscribes to, billed every month in US dollars before tax. A plan priced by
|
|
620
|
+
* the seat states its price, storage, and credits at its minimum, so an editor that reads no
|
|
621
|
+
* `seats` still shows what it starts at.
|
|
622
|
+
*/
|
|
623
|
+
const billingPlanSchema = v.object({
|
|
624
|
+
id: idSchema,
|
|
625
|
+
name: v.pipe(v.string(), v.minLength(1)),
|
|
626
|
+
monthlyPriceCents: centsSchema,
|
|
627
|
+
storageBytes: bytesSchema,
|
|
628
|
+
monthlyCredits: creditsSchema,
|
|
629
|
+
seats: v.optional(billingSeatPricingSchema)
|
|
630
|
+
});
|
|
631
|
+
/** Credits an account on a plan buys once, in US dollars before tax. */
|
|
632
|
+
const creditPackSchema = v.object({
|
|
633
|
+
id: idSchema,
|
|
634
|
+
credits: creditsSchema,
|
|
635
|
+
priceCents: centsSchema,
|
|
636
|
+
/** How long the credits last from purchase. */
|
|
637
|
+
validDays: v.pipe(v.number(), v.integer(), v.minValue(1))
|
|
638
|
+
});
|
|
639
|
+
/** What the service sells; an account without a plan has its deployment's free entitlements. */
|
|
640
|
+
const billingCatalogSchema = v.object({
|
|
641
|
+
plans: v.array(billingPlanSchema),
|
|
642
|
+
creditPacks: v.array(creditPackSchema)
|
|
643
|
+
});
|
|
644
|
+
/**
|
|
645
|
+
* The account's subscription as the payment provider holds it, or `null` without one. A
|
|
646
|
+
* `past_due` plan keeps its entitlements while payment is retried.
|
|
647
|
+
*/
|
|
648
|
+
const billingAccountSchema = v.object({ subscription: v.nullable(v.object({
|
|
649
|
+
planId: idSchema,
|
|
650
|
+
status: v.picklist(["active", "past_due"]),
|
|
651
|
+
/** When the current period ends: the next charge, or the end of a cancelled plan. */
|
|
652
|
+
currentPeriodEnd: v.pipe(v.string(), v.isoTimestamp()),
|
|
653
|
+
/** Whether the plan ends at `currentPeriodEnd` instead of renewing. */
|
|
654
|
+
cancelsAtPeriodEnd: v.boolean()
|
|
655
|
+
})) });
|
|
656
|
+
/** What to buy: a plan to subscribe to, or a credit pack. */
|
|
657
|
+
const checkoutRequestSchema = v.union([v.object({ planId: idSchema }), v.object({ creditPackId: idSchema })]);
|
|
658
|
+
/** Where to send the person: the payment provider's checkout or account portal. */
|
|
659
|
+
const billingRedirectSchema = v.object({ url: v.pipe(urlSchema, v.regex(/^https:\/\//i, "Billing sends people to an HTTPS page")) });
|
|
660
|
+
const billingErrorCodeSchema = v.picklist([
|
|
661
|
+
"invalid_request",
|
|
662
|
+
"unauthorized",
|
|
663
|
+
"not_allowed",
|
|
664
|
+
"provider_unavailable"
|
|
665
|
+
]);
|
|
666
|
+
/** The HTTP status billing answers each error with. */
|
|
667
|
+
const BILLING_ERROR_STATUS = {
|
|
668
|
+
invalid_request: 400,
|
|
669
|
+
unauthorized: 401,
|
|
670
|
+
not_allowed: 409,
|
|
671
|
+
provider_unavailable: 502
|
|
672
|
+
};
|
|
673
|
+
const billingErrorSchema = v.object({ error: v.object({
|
|
674
|
+
code: billingErrorCodeSchema,
|
|
675
|
+
message: v.optional(v.string())
|
|
676
|
+
}) });
|
|
393
677
|
//#endregion
|
|
394
678
|
//#region src/contract/documents.ts
|
|
395
679
|
const CLOUD_PROTOCOL_MAX_UPLOAD_BYTES = 1073741824;
|
|
@@ -622,6 +906,11 @@ const collaborationTicketSchema = v.object({
|
|
|
622
906
|
roomKey: v.pipe(v.string(), v.minLength(43), v.maxLength(128)),
|
|
623
907
|
principal: collaborationPrincipalSchema,
|
|
624
908
|
permission: documentPermissionSchema,
|
|
909
|
+
/**
|
|
910
|
+
* Why a peer whose access would let them edit may only view: `storage-limit` when the document's
|
|
911
|
+
* owner holds their whole storage allowance, until they free space or their plan grows.
|
|
912
|
+
*/
|
|
913
|
+
readOnly: v.optional(v.picklist(["storage-limit"])),
|
|
625
914
|
roomEpoch: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
626
915
|
expiresAt: v.string(),
|
|
627
916
|
serverEnforcedWrites: v.boolean(),
|
|
@@ -643,6 +932,11 @@ const workspaceSummarySchema = v.object({
|
|
|
643
932
|
name: v.string(),
|
|
644
933
|
slug: v.string(),
|
|
645
934
|
role: workspaceRoleSchema,
|
|
935
|
+
/**
|
|
936
|
+
* Whether the signed-in account owns the workspace, and so pays for its plan and AI credits.
|
|
937
|
+
* Absent from servers released before it.
|
|
938
|
+
*/
|
|
939
|
+
owner: v.optional(v.boolean()),
|
|
646
940
|
createdAt: v.string(),
|
|
647
941
|
updatedAt: v.string()
|
|
648
942
|
});
|
|
@@ -883,8 +1177,11 @@ const adminErrorCodeSchema = v.picklist([
|
|
|
883
1177
|
"invalid_enrollment_transition",
|
|
884
1178
|
"last_admin_required",
|
|
885
1179
|
"self_admin_action_forbidden",
|
|
1180
|
+
"last_authentication_method",
|
|
1181
|
+
"account_approved",
|
|
886
1182
|
"email_regeneration_unavailable",
|
|
887
1183
|
"mfa_required",
|
|
1184
|
+
"two_step_unconfirmed",
|
|
888
1185
|
"document_not_restorable",
|
|
889
1186
|
"workspace_gone"
|
|
890
1187
|
]);
|
|
@@ -915,6 +1212,8 @@ const enrollmentsResponseSchema = v.object({
|
|
|
915
1212
|
...listTotals(enrollmentStatusSchema.options)
|
|
916
1213
|
});
|
|
917
1214
|
const enrollmentReviewResponseSchema = v.object({ enrollment: enrollmentSchema });
|
|
1215
|
+
/** How many waiting requests were approved with the official deployment's invitation letter. */
|
|
1216
|
+
const enrollmentInviteResponseSchema = v.object({ invited: v.pipe(v.number(), v.integer(), v.minValue(0)) });
|
|
918
1217
|
const cloudAdminSessionResponseSchema = v.object({ user: cloudIdentitySchema });
|
|
919
1218
|
const cloudAdminUserSchema = v.object({
|
|
920
1219
|
...cloudPersonSchema.entries,
|
|
@@ -926,7 +1225,14 @@ const cloudAdminUserSchema = v.object({
|
|
|
926
1225
|
twoStep: v.boolean(),
|
|
927
1226
|
/** When one of the account's sessions was last used, or null when none is left. */
|
|
928
1227
|
lastActiveAt: nullableTimestampSchema,
|
|
929
|
-
workspaceCount: countSchema
|
|
1228
|
+
workspaceCount: countSchema,
|
|
1229
|
+
/** How the account signs in: `credential` for a password, or a provider such as `google`. */
|
|
1230
|
+
methods: v.array(v.string()),
|
|
1231
|
+
/**
|
|
1232
|
+
* On a server that approves people, where this account's request to join stands: an account
|
|
1233
|
+
* exists from its first sign-in, before anyone approved it. Absent where everyone may join.
|
|
1234
|
+
*/
|
|
1235
|
+
request: v.optional(v.nullable(enrollmentStatusSchema))
|
|
930
1236
|
});
|
|
931
1237
|
/** Which accounts a list of people shows. */
|
|
932
1238
|
const cloudAdminUserFilterSchema = v.picklist([
|
|
@@ -935,6 +1241,8 @@ const cloudAdminUserFilterSchema = v.picklist([
|
|
|
935
1241
|
"suspended",
|
|
936
1242
|
"without-two-step"
|
|
937
1243
|
]);
|
|
1244
|
+
/** Narrows a list of people, under any filter, to those who sign in a given way. */
|
|
1245
|
+
const cloudAdminUserMethodSchema = v.picklist(["password", ...CLOUD_SOCIAL_PROVIDERS]);
|
|
938
1246
|
const cloudAdminUsersResponseSchema = v.object({
|
|
939
1247
|
users: v.array(cloudAdminUserSchema),
|
|
940
1248
|
...listTotals(cloudAdminUserFilterSchema.options)
|
|
@@ -944,9 +1252,12 @@ const cloudAdminUserDetailSchema = v.object({
|
|
|
944
1252
|
...cloudAdminUserSchema.entries,
|
|
945
1253
|
emailVerified: v.boolean()
|
|
946
1254
|
}),
|
|
1255
|
+
/** `canRemove`: the account keeps a way in that still works without it. */
|
|
947
1256
|
methods: v.array(v.object({
|
|
1257
|
+
id: v.string(),
|
|
948
1258
|
provider: v.string(),
|
|
949
|
-
createdAt: timestampSchema
|
|
1259
|
+
createdAt: timestampSchema,
|
|
1260
|
+
canRemove: v.boolean()
|
|
950
1261
|
})),
|
|
951
1262
|
authenticator: v.boolean(),
|
|
952
1263
|
passkeyCount: countSchema,
|
|
@@ -1019,6 +1330,8 @@ const adminAuditResponseSchema = v.object({
|
|
|
1019
1330
|
const cloudAdminDocumentSchema = v.object({
|
|
1020
1331
|
id: v.string(),
|
|
1021
1332
|
name: v.string(),
|
|
1333
|
+
/** A design or a board. Servers from before send none, and had only designs. */
|
|
1334
|
+
kind: v.optional(documentKindSchema, "design"),
|
|
1022
1335
|
workspace: v.object({
|
|
1023
1336
|
id: v.string(),
|
|
1024
1337
|
name: v.string()
|
|
@@ -1040,7 +1353,25 @@ const cloudAdminDocumentSchema = v.object({
|
|
|
1040
1353
|
* can still restore it. Servers from before Trash send neither.
|
|
1041
1354
|
*/
|
|
1042
1355
|
purgedAt: v.optional(nullableTimestampSchema, null),
|
|
1043
|
-
destroyedAt: v.optional(nullableTimestampSchema, null)
|
|
1356
|
+
destroyedAt: v.optional(nullableTimestampSchema, null),
|
|
1357
|
+
/**
|
|
1358
|
+
* The saved revision whose thumbnail previews it; null before its first save. Servers from
|
|
1359
|
+
* before previews send none.
|
|
1360
|
+
*/
|
|
1361
|
+
revisionId: v.optional(v.nullable(v.string()), null),
|
|
1362
|
+
/**
|
|
1363
|
+
* Who beyond its workspace can open it: anyone, in the community gallery, and whoever holds one
|
|
1364
|
+
* of its live share links, `editLinks` of which let them edit. Servers from before send none.
|
|
1365
|
+
*/
|
|
1366
|
+
exposure: v.optional(v.object({
|
|
1367
|
+
community: v.boolean(),
|
|
1368
|
+
links: countSchema,
|
|
1369
|
+
editLinks: countSchema
|
|
1370
|
+
}), {
|
|
1371
|
+
community: false,
|
|
1372
|
+
links: 0,
|
|
1373
|
+
editLinks: 0
|
|
1374
|
+
})
|
|
1044
1375
|
});
|
|
1045
1376
|
/** Which documents a list shows: live ones, or those deleted forever an administrator can restore. */
|
|
1046
1377
|
const cloudAdminDocumentFilterSchema = v.picklist([
|
|
@@ -1137,7 +1468,9 @@ const COLLAB_ACTIONS = {
|
|
|
1137
1468
|
agentPreview: "agent-preview",
|
|
1138
1469
|
upload: "upload",
|
|
1139
1470
|
/** From the server only: the document's version history changed, so open lists load it again. */
|
|
1140
|
-
versions: "versions"
|
|
1471
|
+
versions: "versions",
|
|
1472
|
+
/** From the server only: a comment thread changed; the payload is its ID as UTF-8. */
|
|
1473
|
+
comments: "comments"
|
|
1141
1474
|
};
|
|
1142
1475
|
/**
|
|
1143
1476
|
* The most a room message may decode to, compressed or not. A peer's update past it is dropped
|
|
@@ -1470,11 +1803,22 @@ const workspaceEntitlementsSchema = v.object({
|
|
|
1470
1803
|
reservedStorageBytes: v.pipe(v.number(), v.integer(), v.minValue(0))
|
|
1471
1804
|
})
|
|
1472
1805
|
});
|
|
1806
|
+
/**
|
|
1807
|
+
* An account's own plan and the storage its workspaces hold together. A workspace reports the
|
|
1808
|
+
* same for its owner, so the two read alike.
|
|
1809
|
+
*/
|
|
1810
|
+
const accountEntitlementsSchema = workspaceEntitlementsSchema;
|
|
1811
|
+
const accountEntitlementsResponseSchema = v.object({ entitlements: accountEntitlementsSchema });
|
|
1473
1812
|
//#endregion
|
|
1474
1813
|
//#region src/contract/discovery.ts
|
|
1475
1814
|
const CLOUD_PROTOCOL_VERSION = "1";
|
|
1476
1815
|
const CLOUD_DISCOVERY_PATH = "/.well-known/openpencil";
|
|
1477
1816
|
const cloudDeploymentSchema = v.picklist(["official", "self-hosted"]);
|
|
1817
|
+
/**
|
|
1818
|
+
* The server's sign-in providers that this editor knows. A newer server may offer one this editor
|
|
1819
|
+
* has no button for; it is left out rather than failing discovery, so the editor still connects.
|
|
1820
|
+
*/
|
|
1821
|
+
const socialProvidersSchema = v.pipe(v.array(v.string()), v.transform((providers) => providers.filter(isKnownSocialProvider)));
|
|
1478
1822
|
const cloudAuthenticationSchema = v.object({
|
|
1479
1823
|
emailPassword: v.optional(v.object({
|
|
1480
1824
|
signIn: v.boolean(),
|
|
@@ -1485,7 +1829,7 @@ const cloudAuthenticationSchema = v.object({
|
|
|
1485
1829
|
siteKey: v.pipe(v.string(), v.trim(), v.minLength(1))
|
|
1486
1830
|
}))
|
|
1487
1831
|
})),
|
|
1488
|
-
socialProviders:
|
|
1832
|
+
socialProviders: socialProvidersSchema,
|
|
1489
1833
|
enterpriseSSO: v.boolean(),
|
|
1490
1834
|
enrollmentMode: v.optional(v.picklist([
|
|
1491
1835
|
"open",
|
|
@@ -1504,8 +1848,41 @@ const cloudCapabilitiesSchema = v.object({
|
|
|
1504
1848
|
workspaces: v.boolean(),
|
|
1505
1849
|
collaboration: v.boolean()
|
|
1506
1850
|
});
|
|
1507
|
-
/**
|
|
1508
|
-
|
|
1851
|
+
/**
|
|
1852
|
+
* An editor version, as SemVer: a release such as `0.18.0`, or a pre-release such as
|
|
1853
|
+
* `0.18.0-beta.2` or a nightly's `0.18.0-nightly.20261116`.
|
|
1854
|
+
*
|
|
1855
|
+
* Editors before 0.18.0 accept only `major.minor.patch` here and fail discovery on anything else,
|
|
1856
|
+
* so a server names a pre-release minimum only once its minimum is already 0.18.0 or later.
|
|
1857
|
+
*/
|
|
1858
|
+
const cloudEditorVersionSchema = v.pipe(v.string(), v.check(isSemVer, "Expected a SemVer version"));
|
|
1859
|
+
/**
|
|
1860
|
+
* Whether the text is exactly a SemVer version, build metadata included: semver's own parse also
|
|
1861
|
+
* takes a `v` prefix or spaces, which a version here never has.
|
|
1862
|
+
*/
|
|
1863
|
+
function isSemVer(value) {
|
|
1864
|
+
const parsed = parseVersion(value);
|
|
1865
|
+
if (!parsed) return false;
|
|
1866
|
+
const build = parsed.build.length > 0 ? `+${parsed.build.join(".")}` : "";
|
|
1867
|
+
return `${parsed.version}${build}` === value;
|
|
1868
|
+
}
|
|
1869
|
+
/**
|
|
1870
|
+
* The header desktop editors send with each request, naming their version, so a server can refuse
|
|
1871
|
+
* an editor older than its `minimumEditorVersion`. Browser editors leave it out: the server serves
|
|
1872
|
+
* them, and an older server's CORS rules would refuse a header they don't list.
|
|
1873
|
+
*/
|
|
1874
|
+
const CLOUD_EDITOR_VERSION_HEADER = "X-OpenPencil-Editor-Version";
|
|
1875
|
+
/**
|
|
1876
|
+
* Whether `version` is `minimum` or later, in SemVer order: a pre-release comes before its
|
|
1877
|
+
* release, so `0.18.0-beta.2` is not at least `0.18.0`; a release's nightlies come after its
|
|
1878
|
+
* betas and order by date. To admit a release's pre-releases, name the earliest one, such as
|
|
1879
|
+
* `0.18.0-beta.1`, or `0.18.0-nightly.20261116` for nightlies from that day on. A
|
|
1880
|
+
* version that isn't SemVer, on either side, is not at least anything.
|
|
1881
|
+
*/
|
|
1882
|
+
function isEditorVersionAtLeast(version, minimum) {
|
|
1883
|
+
if (!isSemVer(version) || !isSemVer(minimum)) return false;
|
|
1884
|
+
return compareVersions(version, minimum) >= 0;
|
|
1885
|
+
}
|
|
1509
1886
|
/**
|
|
1510
1887
|
* Whether editors offer this server to everyone, and from which editor version on. Only the
|
|
1511
1888
|
* official server's listing is read: it turns the Cloud entry points on without an editor release,
|
|
@@ -1526,6 +1903,26 @@ const cloudLegalDiscoverySchema = v.object({
|
|
|
1526
1903
|
abuseEmail: v.optional(v.pipe(v.string(), v.email())),
|
|
1527
1904
|
minimumAge: v.optional(v.pipe(v.number(), v.integer()))
|
|
1528
1905
|
});
|
|
1906
|
+
/** A web address a page may link or load: `http` or `https` only, never a script or data URL. */
|
|
1907
|
+
const webURLSchema = v.pipe(v.string(), v.url(), v.check((value) => ["http:", "https:"].includes(new URL(value).protocol)));
|
|
1908
|
+
/**
|
|
1909
|
+
* How a self-hosted server names itself on its public pages: the operator's name and logo in the
|
|
1910
|
+
* bar, and where its people get help. The official server is OpenPencil's own and names none.
|
|
1911
|
+
*/
|
|
1912
|
+
const cloudBrandingSchema = v.object({
|
|
1913
|
+
name: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(80))),
|
|
1914
|
+
logoURL: v.optional(webURLSchema),
|
|
1915
|
+
helpURL: v.optional(webURLSchema)
|
|
1916
|
+
});
|
|
1917
|
+
/**
|
|
1918
|
+
* The server's community gallery: the workspace whose documents anyone may open read-only.
|
|
1919
|
+
* Saving to it publishes, so editors never choose it for anyone and say so when it is chosen.
|
|
1920
|
+
* `tourDocumentId` is the gallery document editors open as their tour.
|
|
1921
|
+
*/
|
|
1922
|
+
const cloudCommunityDiscoverySchema = v.object({
|
|
1923
|
+
workspaceId: v.pipe(v.string(), v.uuid()),
|
|
1924
|
+
tourDocumentId: v.optional(v.pipe(v.string(), v.uuid()))
|
|
1925
|
+
});
|
|
1529
1926
|
const cloudDiscoverySchema = v.object({
|
|
1530
1927
|
protocolVersion: v.literal("1"),
|
|
1531
1928
|
deployment: cloudDeploymentSchema,
|
|
@@ -1536,11 +1933,19 @@ const cloudDiscoverySchema = v.object({
|
|
|
1536
1933
|
authentication: cloudAuthenticationSchema,
|
|
1537
1934
|
capabilities: cloudCapabilitiesSchema,
|
|
1538
1935
|
listing: v.optional(cloudListingSchema),
|
|
1936
|
+
/**
|
|
1937
|
+
* The oldest editor version the server works with. Older editors ask to be updated instead of
|
|
1938
|
+
* connecting, and the server refuses their requests.
|
|
1939
|
+
*/
|
|
1940
|
+
minimumEditorVersion: v.optional(cloudEditorVersionSchema),
|
|
1539
1941
|
/** The services editors reach with Cloud-signed tokens; absent when the deployment has none. */
|
|
1540
1942
|
services: v.optional(cloudServicesDiscoverySchema),
|
|
1541
1943
|
/** Where people manage their plan and buy credits; absent when the deployment does not bill. */
|
|
1542
1944
|
billing: v.optional(cloudBillingDiscoverySchema),
|
|
1543
|
-
|
|
1945
|
+
/** The community gallery; absent when the deployment has none. */
|
|
1946
|
+
community: v.optional(cloudCommunityDiscoverySchema),
|
|
1947
|
+
legal: v.optional(cloudLegalDiscoverySchema),
|
|
1948
|
+
branding: v.optional(cloudBrandingSchema)
|
|
1544
1949
|
});
|
|
1545
1950
|
/** The server's own address, where its editor and pages are, from its auth API's. */
|
|
1546
1951
|
function cloudServerOrigin(discovery) {
|
|
@@ -1552,6 +1957,10 @@ function parseCloudDiscovery(input) {
|
|
|
1552
1957
|
//#endregion
|
|
1553
1958
|
//#region src/contract/links.ts
|
|
1554
1959
|
const CLOUD_LINK_PATH = /^\/(invitations|share|documents)\/([^/]+)$/;
|
|
1960
|
+
/** A community document opened in the editor; `/community/:id` alone is its page. */
|
|
1961
|
+
const COMMUNITY_EDITOR_PATH = /^\/community\/([^/]+)\/open$/;
|
|
1962
|
+
/** The server's community gallery: every document in it, each with a page of its own. */
|
|
1963
|
+
const CLOUD_COMMUNITY_PATH = "/community";
|
|
1555
1964
|
/**
|
|
1556
1965
|
* A link on the server's own editor. The server is the link's own address, so the link needs
|
|
1557
1966
|
* nothing else to name it; a secret travels in the fragment, so it never reaches access logs or
|
|
@@ -1582,12 +1991,31 @@ function cloudDocumentPath(documentId) {
|
|
|
1582
1991
|
return `/documents/${encodeParam(documentId)}`;
|
|
1583
1992
|
}
|
|
1584
1993
|
/**
|
|
1994
|
+
* A document of the server's community gallery opened in the editor, `/community/:id/open`, or
|
|
1995
|
+
* one of its named versions with `?version=…`, which anyone opens read-only without signing in.
|
|
1996
|
+
*/
|
|
1997
|
+
function cloudCommunityURL(serverURL, documentId, versionId = null) {
|
|
1998
|
+
return serverLink(serverURL, cloudCommunityPath(documentId), { version: versionId ?? void 0 });
|
|
1999
|
+
}
|
|
2000
|
+
function cloudCommunityPath(documentId) {
|
|
2001
|
+
return `${cloudCommunityPagePath(documentId)}/open`;
|
|
2002
|
+
}
|
|
2003
|
+
/** A community document's page on the server: its preview, versions, and ways to open it. */
|
|
2004
|
+
function cloudCommunityPagePath(documentId) {
|
|
2005
|
+
return `${CLOUD_COMMUNITY_PATH}/${encodeParam(documentId)}`;
|
|
2006
|
+
}
|
|
2007
|
+
/**
|
|
1585
2008
|
* The kind and ID of a Cloud link's path, or null for any other path. The ID is decoded; a broken
|
|
1586
2009
|
* escape such as `%E0` is no link.
|
|
1587
2010
|
*/
|
|
1588
2011
|
function parseCloudLinkPath(pathname) {
|
|
1589
|
-
const
|
|
1590
|
-
|
|
2012
|
+
const community = pathname.match(COMMUNITY_EDITOR_PATH);
|
|
2013
|
+
const [, kind, id] = community ? [
|
|
2014
|
+
pathname,
|
|
2015
|
+
"community",
|
|
2016
|
+
community[1]
|
|
2017
|
+
] : pathname.match(CLOUD_LINK_PATH) ?? [];
|
|
2018
|
+
if (kind !== "invitations" && kind !== "share" && kind !== "documents" && kind !== "community" || !id) return null;
|
|
1591
2019
|
try {
|
|
1592
2020
|
return {
|
|
1593
2021
|
kind,
|
|
@@ -1606,6 +2034,17 @@ function cloudDesktopLinkURL(kind, id, serverURL, secret) {
|
|
|
1606
2034
|
const link = serverLink(serverURL, `/${kind}/${encodeParam(id)}`);
|
|
1607
2035
|
return withFragment(withQuery("openpencil://cloud", { url: link }), secret);
|
|
1608
2036
|
}
|
|
2037
|
+
/**
|
|
2038
|
+
* The desktop app's form of a community document's link, `openpencil://cloud?url=<link>`: the
|
|
2039
|
+
* editor's address for it, with the named version it asks for, if any. It carries no secret.
|
|
2040
|
+
*/
|
|
2041
|
+
function cloudCommunityDesktopLinkURL(documentId, serverURL, versionId = null) {
|
|
2042
|
+
return withQuery("openpencil://cloud", { url: cloudCommunityURL(serverURL, documentId, versionId) });
|
|
2043
|
+
}
|
|
2044
|
+
/** A comment thread on a document, `/documents/:id?comment=…`, which opens it. */
|
|
2045
|
+
function cloudCommentURL(serverURL, documentId, threadId) {
|
|
2046
|
+
return serverLink(serverURL, cloudDocumentPath(documentId), { comment: threadId });
|
|
2047
|
+
}
|
|
1609
2048
|
//#endregion
|
|
1610
2049
|
//#region src/contract/portal.ts
|
|
1611
2050
|
/**
|
|
@@ -1620,8 +2059,14 @@ const CLOUD_PORTAL_PAGE_ROOTS = [
|
|
|
1620
2059
|
"/account",
|
|
1621
2060
|
"/admin"
|
|
1622
2061
|
];
|
|
2062
|
+
/**
|
|
2063
|
+
* The community gallery's pages, which the portal serves too: the gallery at `/community` and a
|
|
2064
|
+
* document's page at `/community/:id`. The editor opens a document at `/community/:id/open`.
|
|
2065
|
+
*/
|
|
2066
|
+
const CLOUD_PORTAL_COMMUNITY_PAGES = ["/community", "/community/:documentId"];
|
|
2067
|
+
const COMMUNITY_PAGE = /^\/community(?:\/[^/]+)?\/?$/;
|
|
1623
2068
|
function isCloudPortalPage(path) {
|
|
1624
|
-
return CLOUD_PORTAL_PAGE_ROOTS.some((root) => path === root || path.startsWith(`${root}/`));
|
|
2069
|
+
return COMMUNITY_PAGE.test(path) || CLOUD_PORTAL_PAGE_ROOTS.some((root) => path === root || path.startsWith(`${root}/`));
|
|
1625
2070
|
}
|
|
1626
2071
|
//#endregion
|
|
1627
2072
|
//#region src/contract/versions.ts
|
|
@@ -1685,6 +2130,217 @@ function parseDuplicateDocumentVersion(input) {
|
|
|
1685
2130
|
return v.parse(duplicateDocumentVersionSchema, input);
|
|
1686
2131
|
}
|
|
1687
2132
|
//#endregion
|
|
1688
|
-
|
|
2133
|
+
//#region src/contract/comments.ts
|
|
2134
|
+
/** The most a comment may say, in characters. */
|
|
2135
|
+
const COMMENT_BODY_MAX_LENGTH = 1e4;
|
|
2136
|
+
/** The most threads one document may hold, resolved ones included. */
|
|
2137
|
+
const MAX_COMMENT_THREADS_PER_DOCUMENT = 5e3;
|
|
2138
|
+
/** The most comments one thread may hold, its first one included. */
|
|
2139
|
+
const MAX_COMMENTS_PER_THREAD = 500;
|
|
2140
|
+
/** The most a page, layer or author name in a comment may hold, in characters. */
|
|
2141
|
+
const COMMENT_NAME_MAX_LENGTH = 255;
|
|
2142
|
+
const ID_MAX_LENGTH = 200;
|
|
2143
|
+
/**
|
|
2144
|
+
* Who wrote a comment: an account, whose name is null once it is deleted, or a name a file gave
|
|
2145
|
+
* when the comment came in with it, which no account vouches for.
|
|
2146
|
+
*/
|
|
2147
|
+
const commentAuthorSchema = v.variant("kind", [v.object({
|
|
2148
|
+
kind: v.literal("user"),
|
|
2149
|
+
id: v.string(),
|
|
2150
|
+
name: v.nullable(v.string())
|
|
2151
|
+
}), v.object({
|
|
2152
|
+
kind: v.literal("imported"),
|
|
2153
|
+
name: v.string()
|
|
2154
|
+
})]);
|
|
2155
|
+
const cloudCommentSchema = v.object({
|
|
2156
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
2157
|
+
author: commentAuthorSchema,
|
|
2158
|
+
/** The agent that wrote it on its author's behalf. */
|
|
2159
|
+
agent: v.nullable(v.string()),
|
|
2160
|
+
/** Markdown, as the editor writes it. */
|
|
2161
|
+
body: v.string(),
|
|
2162
|
+
/** The accounts it names, which hear about it. */
|
|
2163
|
+
mentions: v.array(v.string()),
|
|
2164
|
+
createdAt: v.string(),
|
|
2165
|
+
editedAt: v.nullable(v.string())
|
|
2166
|
+
});
|
|
2167
|
+
/** Where a pin sits, as the editor places it. */
|
|
2168
|
+
const commentAnchorEntries = {
|
|
2169
|
+
pageId: v.pipe(v.string(), v.minLength(1), v.maxLength(ID_MAX_LENGTH)),
|
|
2170
|
+
pageName: v.nullable(v.pipe(v.string(), v.maxLength(255))),
|
|
2171
|
+
/** The top-level layer the pin follows, if any. */
|
|
2172
|
+
nodeId: v.nullable(v.pipe(v.string(), v.minLength(1), v.maxLength(ID_MAX_LENGTH))),
|
|
2173
|
+
nodeName: v.nullable(v.pipe(v.string(), v.maxLength(255))),
|
|
2174
|
+
/** The pin's offset from the layer's top-left corner. */
|
|
2175
|
+
offsetX: v.nullable(v.pipe(v.number(), v.finite())),
|
|
2176
|
+
offsetY: v.nullable(v.pipe(v.number(), v.finite())),
|
|
2177
|
+
/** The pin's canvas position, used once the layer is gone. */
|
|
2178
|
+
x: v.pipe(v.number(), v.finite()),
|
|
2179
|
+
y: v.pipe(v.number(), v.finite())
|
|
2180
|
+
};
|
|
2181
|
+
const commentAnchorSchema = v.object(commentAnchorEntries);
|
|
2182
|
+
const cloudCommentThreadSchema = v.object({
|
|
2183
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
2184
|
+
...commentAnchorEntries,
|
|
2185
|
+
createdAt: v.string(),
|
|
2186
|
+
/** When anything in the thread last changed: a comment, the pin, or whether it is resolved. */
|
|
2187
|
+
updatedAt: v.string(),
|
|
2188
|
+
resolvedAt: v.nullable(v.string()),
|
|
2189
|
+
resolvedBy: v.nullable(v.string()),
|
|
2190
|
+
/** Who started it, or brought it in from a file: they may move its pin and delete it. */
|
|
2191
|
+
createdBy: v.string(),
|
|
2192
|
+
/** Whether someone else wrote in it since the asker last read it; false for a guest. */
|
|
2193
|
+
unread: v.boolean(),
|
|
2194
|
+
/** Oldest first; the first is what started the thread. */
|
|
2195
|
+
comments: v.array(cloudCommentSchema)
|
|
2196
|
+
});
|
|
2197
|
+
/** What the person asking may do with the document's comments. */
|
|
2198
|
+
const commentAccessSchema = v.object({
|
|
2199
|
+
/** Start threads, reply, and change their own comments; anyone signed in who can view. */
|
|
2200
|
+
canComment: v.boolean(),
|
|
2201
|
+
/** Delete anyone's comments; editors. */
|
|
2202
|
+
canModerate: v.boolean(),
|
|
2203
|
+
/** The asker's account, which their own comments name; null for a guest. */
|
|
2204
|
+
accountId: v.nullable(v.string())
|
|
2205
|
+
});
|
|
2206
|
+
const commentThreadsSchema = v.object({
|
|
2207
|
+
threads: v.array(cloudCommentThreadSchema),
|
|
2208
|
+
access: commentAccessSchema
|
|
2209
|
+
});
|
|
2210
|
+
const commentThreadResponseSchema = v.object({ thread: cloudCommentThreadSchema });
|
|
2211
|
+
const bodySchema = v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(COMMENT_BODY_MAX_LENGTH));
|
|
2212
|
+
/** The most accounts one comment names. */
|
|
2213
|
+
const MAX_COMMENT_MENTIONS = 50;
|
|
2214
|
+
/** The accounts a comment names; the server keeps those who can read the document. */
|
|
2215
|
+
const mentionsSchema = v.optional(v.pipe(v.array(v.pipe(v.string(), v.minLength(1), v.maxLength(200))), v.maxLength(50)), []);
|
|
2216
|
+
/** The longest agent name a comment keeps. */
|
|
2217
|
+
const MAX_COMMENT_AGENT_LENGTH = 100;
|
|
2218
|
+
const agentSchema = v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(100)));
|
|
2219
|
+
/**
|
|
2220
|
+
* The ID the editor gave a new thread or comment, so it keeps showing it as the server's, and a
|
|
2221
|
+
* request sent again finds what the first one made.
|
|
2222
|
+
*/
|
|
2223
|
+
const clientIdSchema = v.optional(v.pipe(v.string(), v.uuid()));
|
|
2224
|
+
const createCommentThreadSchema = v.object({
|
|
2225
|
+
id: clientIdSchema,
|
|
2226
|
+
...commentAnchorEntries,
|
|
2227
|
+
body: bodySchema,
|
|
2228
|
+
mentions: mentionsSchema,
|
|
2229
|
+
agent: agentSchema
|
|
2230
|
+
});
|
|
2231
|
+
/** Resolves or reopens a thread, or moves its pin; what is left out stays as it is. */
|
|
2232
|
+
const updateCommentThreadSchema = v.object({
|
|
2233
|
+
resolved: v.optional(v.boolean()),
|
|
2234
|
+
anchor: v.optional(commentAnchorSchema)
|
|
2235
|
+
});
|
|
2236
|
+
const createCommentSchema = v.object({
|
|
2237
|
+
id: clientIdSchema,
|
|
2238
|
+
body: bodySchema,
|
|
2239
|
+
mentions: mentionsSchema,
|
|
2240
|
+
agent: agentSchema
|
|
2241
|
+
});
|
|
2242
|
+
const updateCommentSchema = v.object({
|
|
2243
|
+
body: bodySchema,
|
|
2244
|
+
mentions: mentionsSchema
|
|
2245
|
+
});
|
|
2246
|
+
/** Someone a comment may name: an account that can open the document. */
|
|
2247
|
+
const commentPersonSchema = v.object({
|
|
2248
|
+
id: v.string(),
|
|
2249
|
+
name: v.string(),
|
|
2250
|
+
image: v.nullable(v.string())
|
|
2251
|
+
});
|
|
2252
|
+
const commentPeopleSchema = v.object({ people: v.array(commentPersonSchema) });
|
|
2253
|
+
/** Which comments an account hears about by email. */
|
|
2254
|
+
const commentEmailSettingSchema = v.picklist([
|
|
2255
|
+
"all",
|
|
2256
|
+
"mentions",
|
|
2257
|
+
"off"
|
|
2258
|
+
]);
|
|
2259
|
+
const notificationSettingsSchema = v.object({ commentEmails: commentEmailSettingSchema });
|
|
2260
|
+
/** The most threads, and comments in all, one import brings in. */
|
|
2261
|
+
const MAX_IMPORTED_COMMENT_THREADS = 1e3;
|
|
2262
|
+
const MAX_IMPORTED_COMMENTS = 1e4;
|
|
2263
|
+
/**
|
|
2264
|
+
* Threads a file held when it moved to Cloud. Their authors are names the file gave, which the
|
|
2265
|
+
* server keeps as such; their times are the file's.
|
|
2266
|
+
*/
|
|
2267
|
+
const importCommentThreadsSchema = v.object({ threads: v.pipe(v.array(v.object({
|
|
2268
|
+
...commentAnchorEntries,
|
|
2269
|
+
createdAt: v.pipe(v.string(), v.isoTimestamp()),
|
|
2270
|
+
resolved: v.boolean(),
|
|
2271
|
+
comments: v.pipe(v.array(v.object({
|
|
2272
|
+
authorName: v.pipe(v.string(), v.trim(), v.maxLength(255)),
|
|
2273
|
+
body: bodySchema,
|
|
2274
|
+
createdAt: v.pipe(v.string(), v.isoTimestamp())
|
|
2275
|
+
})), v.minLength(1), v.maxLength(MAX_IMPORTED_COMMENTS))
|
|
2276
|
+
})), v.maxLength(MAX_IMPORTED_COMMENT_THREADS), v.check((threads) => threads.reduce((total, thread) => total + thread.comments.length, 0) <= MAX_IMPORTED_COMMENTS, `An import brings in at most ${MAX_IMPORTED_COMMENTS} comments`)) });
|
|
2277
|
+
/**
|
|
2278
|
+
* The same requests made through a share link: the link's secret rides in the body, as it does
|
|
2279
|
+
* for opening the document, since it must stay out of the address.
|
|
2280
|
+
*/
|
|
2281
|
+
const shareEntries = { share: v.pick(resolveDocumentShareSchema, ["secret"]) };
|
|
2282
|
+
const sharedCommentsRequestSchema = v.object(shareEntries);
|
|
2283
|
+
const sharedCreateCommentThreadSchema = v.object({
|
|
2284
|
+
...shareEntries,
|
|
2285
|
+
...createCommentThreadSchema.entries
|
|
2286
|
+
});
|
|
2287
|
+
const sharedUpdateCommentThreadSchema = v.object({
|
|
2288
|
+
...shareEntries,
|
|
2289
|
+
...updateCommentThreadSchema.entries
|
|
2290
|
+
});
|
|
2291
|
+
const sharedCreateCommentSchema = v.object({
|
|
2292
|
+
...shareEntries,
|
|
2293
|
+
...createCommentSchema.entries
|
|
2294
|
+
});
|
|
2295
|
+
const sharedUpdateCommentSchema = v.object({
|
|
2296
|
+
...shareEntries,
|
|
2297
|
+
...updateCommentSchema.entries
|
|
2298
|
+
});
|
|
2299
|
+
//#endregion
|
|
2300
|
+
//#region src/contract/community.ts
|
|
2301
|
+
/**
|
|
2302
|
+
* Where a community document's thumbnail is served, by its document and revision: the address
|
|
2303
|
+
* changes with each save, so a cached copy never shows an older state.
|
|
2304
|
+
*/
|
|
2305
|
+
const COMMUNITY_THUMBNAIL_PATH = "/api/community/thumbnails";
|
|
2306
|
+
function communityThumbnailPath(documentId, revisionId) {
|
|
2307
|
+
return `${COMMUNITY_THUMBNAIL_PATH}/${documentId}/${revisionId}`;
|
|
2308
|
+
}
|
|
2309
|
+
/** A version of a community document someone named, such as the release it was published for. */
|
|
2310
|
+
const communityVersionSchema = v.object({
|
|
2311
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
2312
|
+
name: v.string(),
|
|
2313
|
+
description: v.nullable(v.string()),
|
|
2314
|
+
createdAt: v.string(),
|
|
2315
|
+
/** Whether the document holds this version now, with nothing changed since it was named. */
|
|
2316
|
+
current: v.boolean()
|
|
2317
|
+
});
|
|
2318
|
+
/**
|
|
2319
|
+
* A document in the deployment's community workspace, which anyone may open read-only: its name,
|
|
2320
|
+
* when it last changed, its thumbnail's path on the server, and its named versions, newest first.
|
|
2321
|
+
*/
|
|
2322
|
+
const communityDocumentSchema = v.object({
|
|
2323
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
2324
|
+
name: v.string(),
|
|
2325
|
+
kind: documentKindSchema,
|
|
2326
|
+
updatedAt: v.string(),
|
|
2327
|
+
revisionId: v.pipe(v.string(), v.uuid()),
|
|
2328
|
+
thumbnailPath: v.string(),
|
|
2329
|
+
versions: v.array(communityVersionSchema)
|
|
2330
|
+
});
|
|
2331
|
+
/** The community workspace's documents, most recently changed first. */
|
|
2332
|
+
const communityDocumentsSchema = v.object({ documents: v.array(communityDocumentSchema) });
|
|
2333
|
+
/** Which state of a community document to open: a named version, or else the latest. */
|
|
2334
|
+
const communityDownloadQuerySchema = v.object({ version: v.optional(v.pipe(v.string(), v.uuid())) });
|
|
2335
|
+
function parseCommunityDownloadQuery(input) {
|
|
2336
|
+
return v.parse(communityDownloadQuerySchema, input);
|
|
2337
|
+
}
|
|
2338
|
+
/** A community document, or one of its named versions, with where to download it. */
|
|
2339
|
+
const communityDownloadSchema = v.object({
|
|
2340
|
+
document: documentDownloadSchema,
|
|
2341
|
+
version: v.nullable(communityVersionSchema)
|
|
2342
|
+
});
|
|
2343
|
+
//#endregion
|
|
2344
|
+
export { BILLING_ERROR_STATUS, CLOUD_ACCESS_TOKEN_MAX_DAYS, CLOUD_ACCESS_TOKEN_NAME_MAX_LENGTH, CLOUD_ACCESS_TOKEN_PREFIX, CLOUD_ACCOUNT_BILLING_PATH, CLOUD_ACCOUNT_PLAN_PATH, CLOUD_API_MAX_BODY_BYTES, CLOUD_BILLING_API_PATHS, CLOUD_BILLING_CONTRACT_VERSION, CLOUD_BILLING_PAGE_PATHS, 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, CLOUD_SOCIAL_PROVIDERS, CLOUD_SOCIAL_PROVIDER_NAMES, COLLAB_ACTIONS, COMMENT_BODY_MAX_LENGTH, COMMENT_NAME_MAX_LENGTH, COMMUNITY_THUMBNAIL_PATH, DOCUMENT_REPORT_DESCRIPTION_MAX, DOCUMENT_VERSION_DESCRIPTION_MAX_LENGTH, DOCUMENT_VERSION_NAME_MAX_LENGTH, MAX_COLLAB_MESSAGE_BYTES, MAX_COMMENTS_PER_THREAD, MAX_COMMENT_AGENT_LENGTH, MAX_COMMENT_MENTIONS, MAX_COMMENT_THREADS_PER_DOCUMENT, MAX_IMPORTED_COMMENTS, MAX_IMPORTED_COMMENT_THREADS, 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, billingFreePlanSchema, billingPlanSchema, billingRedirectSchema, billingSeatPricingSchema, 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, cloudAdminUserMethodSchema, cloudAdminUserSchema, cloudAdminUsersResponseSchema, cloudAuthenticationMethodSchema, cloudAuthenticationMethodsResponseSchema, cloudAuthenticationProviderSchema, cloudAuthenticationSchema, cloudBillingDiscoverySchema, cloudBrandingSchema, cloudCapabilitiesSchema, cloudCommentSchema, cloudCommentThreadSchema, cloudCommentURL, 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, cloudSocialProviderSchema, cloudTermsAcceptanceSchema, cloudUnlinkAuthenticationMethodSchema, cloudUserProfileSchema, collaborationPrincipalSchema, collaborationTicketSchema, commentAccessSchema, commentAnchorSchema, commentAuthorSchema, commentEmailSettingSchema, commentPeopleSchema, commentPersonSchema, commentThreadResponseSchema, commentThreadsSchema, commitImageUploadsSchema, commitUploadSchema, communityDocumentSchema, communityDocumentsSchema, communityDownloadQuerySchema, communityDownloadSchema, communityThumbnailPath, communityVersionSchema, createCommentSchema, createCommentThreadSchema, 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, enrollmentInviteResponseSchema, enrollmentReviewResponseSchema, enrollmentSchema, enrollmentStatusSchema, enrollmentsResponseSchema, fileDocumentReportResponseSchema, fileDocumentReportSchema, imageUploadOfferSchema, importCommentThreadsSchema, invitationContinuationSchema, invitationPreviewSchema, isCloudChecksum, isCloudPortalPage, isEditorVersionAtLeast, isKnownAuthenticationProvider, isKnownSocialProvider, notificationSettingsSchema, 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, roleModelsSchema, saveDocumentVersionSchema, searchPricingSchema, searchRequestSchema, searchResponseSchema, searchResultSchema, sendsTokenSafely, serviceCatalogSchema, serviceErrorCodeSchema, serviceErrorSchema, servicesTokenClaimsSchema, servicesTokenSchema, sharedCommentsRequestSchema, sharedCreateCommentSchema, sharedCreateCommentThreadSchema, sharedDocumentSchema, sharedUpdateCommentSchema, sharedUpdateCommentThreadSchema, transactionalEmailAdminSchema, trashSchema, trashedDocumentSchema, updateCommentSchema, updateCommentThreadSchema, updateDocumentShareSchema, updateDocumentVersionSchema, updateWorkspaceMemberSchema, updateWorkspaceSchema, usageEntrySchema, usagePageSchema, usageQuerySchema, workspaceEntitlementsSchema, workspaceInvitationSchema, workspaceListSchema, workspaceMemberSchema, workspaceMembersSchema, workspaceRoleSchema, workspaceSummarySchema, workspaceUsageSchema };
|
|
1689
2345
|
|
|
1690
2346
|
//# sourceMappingURL=contract2.js.map
|