@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/listen.mjs
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { isValid } from "js-base64";
|
|
1
2
|
import * as v from "valibot";
|
|
2
3
|
import { Inflate, deflateSync } from "fflate";
|
|
3
4
|
import * as decoding from "lib0/decoding";
|
|
4
5
|
import * as encoding from "lib0/encoding";
|
|
5
6
|
import * as Y from "yjs";
|
|
6
|
-
import
|
|
7
|
+
import compareVersions from "semver/functions/compare.js";
|
|
8
|
+
import parseVersion from "semver/functions/parse.js";
|
|
9
|
+
import { sValidator } from "@hono/standard-validator";
|
|
7
10
|
import { sql } from "kysely";
|
|
8
11
|
import { Migrator } from "kysely/migration";
|
|
9
12
|
import { createServer } from "node:http";
|
|
@@ -19,6 +22,242 @@ var __exportAll = (all, no_symbols) => {
|
|
|
19
22
|
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
20
23
|
return target;
|
|
21
24
|
};
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/contract/account.ts
|
|
27
|
+
/**
|
|
28
|
+
* Where an account stands: it may use the server, waits for an administrator, was refused or had
|
|
29
|
+
* its access taken back, has to prove its second step in this session, as after signing in through
|
|
30
|
+
* a linked account such as Google, or has to accept the server's current terms first.
|
|
31
|
+
*/
|
|
32
|
+
const cloudAccountStateSchema = v.picklist([
|
|
33
|
+
"active",
|
|
34
|
+
"pending",
|
|
35
|
+
"rejected",
|
|
36
|
+
"revoked",
|
|
37
|
+
"two-step",
|
|
38
|
+
"terms"
|
|
39
|
+
]);
|
|
40
|
+
const cloudIdentitySchema = v.object({
|
|
41
|
+
userId: v.string(),
|
|
42
|
+
email: v.pipe(v.string(), v.email()),
|
|
43
|
+
name: v.string(),
|
|
44
|
+
/** The account's picture, such as one a social provider gave it. */
|
|
45
|
+
image: v.optional(v.nullable(v.string())),
|
|
46
|
+
deploymentRole: v.optional(v.picklist(["user", "admin"]))
|
|
47
|
+
});
|
|
48
|
+
v.object({
|
|
49
|
+
user: cloudIdentitySchema,
|
|
50
|
+
state: cloudAccountStateSchema
|
|
51
|
+
});
|
|
52
|
+
/** Accepting the server's terms: the version the person read, which must be the current one. */
|
|
53
|
+
const cloudTermsAcceptanceSchema = v.object({ version: v.pipe(v.string(), v.minLength(1)) });
|
|
54
|
+
/**
|
|
55
|
+
* The providers a person can sign in with besides a password, which this editor has buttons for,
|
|
56
|
+
* in the order it shows them. Every list of providers in Cloud derives from this one.
|
|
57
|
+
*/
|
|
58
|
+
const CLOUD_SOCIAL_PROVIDERS = [
|
|
59
|
+
"google",
|
|
60
|
+
"apple",
|
|
61
|
+
"github"
|
|
62
|
+
];
|
|
63
|
+
const cloudSocialProviderSchema = v.picklist(CLOUD_SOCIAL_PROVIDERS);
|
|
64
|
+
/** Each provider's name, as its owner writes it in every language. */
|
|
65
|
+
const CLOUD_SOCIAL_PROVIDER_NAMES = {
|
|
66
|
+
google: "Google",
|
|
67
|
+
apple: "Apple",
|
|
68
|
+
github: "GitHub"
|
|
69
|
+
};
|
|
70
|
+
const cloudAuthenticationProviderSchema = v.picklist(["credential", ...CLOUD_SOCIAL_PROVIDERS]);
|
|
71
|
+
const cloudAuthenticationMethodSchema = v.object({
|
|
72
|
+
id: v.string(),
|
|
73
|
+
provider: cloudAuthenticationProviderSchema,
|
|
74
|
+
createdAt: v.string(),
|
|
75
|
+
canUnlink: v.boolean()
|
|
76
|
+
});
|
|
77
|
+
/** Whether this editor knows `provider`, so a newer server's other providers can be left out. */
|
|
78
|
+
function isKnownSocialProvider(provider) {
|
|
79
|
+
return CLOUD_SOCIAL_PROVIDERS.includes(provider);
|
|
80
|
+
}
|
|
81
|
+
/** Whether `provider` is a way to sign in this editor knows: a password or a known provider. */
|
|
82
|
+
function isKnownAuthenticationProvider(provider) {
|
|
83
|
+
return provider === "credential" || isKnownSocialProvider(provider);
|
|
84
|
+
}
|
|
85
|
+
v.object({
|
|
86
|
+
methods: v.pipe(v.array(v.looseObject({ provider: v.string() })), v.filterItems((method) => isKnownAuthenticationProvider(method.provider)), v.array(cloudAuthenticationMethodSchema)),
|
|
87
|
+
availableSocialProviders: v.pipe(v.array(v.string()), v.filterItems(isKnownSocialProvider), v.array(cloudSocialProviderSchema))
|
|
88
|
+
});
|
|
89
|
+
const cloudPasswordChangeSchema = v.object({
|
|
90
|
+
currentPassword: v.string(),
|
|
91
|
+
newPassword: v.string()
|
|
92
|
+
});
|
|
93
|
+
const cloudSocialLinkSchema = v.object({
|
|
94
|
+
provider: cloudSocialProviderSchema,
|
|
95
|
+
callbackURL: v.pipe(v.string(), v.url())
|
|
96
|
+
});
|
|
97
|
+
v.object({ url: v.pipe(v.string(), v.url()) });
|
|
98
|
+
const cloudUnlinkAuthenticationMethodSchema = v.object({ methodId: v.string() });
|
|
99
|
+
const accountSecurityErrorCodeSchema = v.picklist([
|
|
100
|
+
"current_password_invalid",
|
|
101
|
+
"password_too_short",
|
|
102
|
+
"password_too_long",
|
|
103
|
+
"last_authentication_method",
|
|
104
|
+
"session_not_fresh",
|
|
105
|
+
"authentication_method_failed",
|
|
106
|
+
"code_invalid",
|
|
107
|
+
"email_unchanged",
|
|
108
|
+
"email_change_unavailable",
|
|
109
|
+
"current_session",
|
|
110
|
+
"picture_invalid",
|
|
111
|
+
"account_sole_admin",
|
|
112
|
+
"last_admin_required",
|
|
113
|
+
"terms_changed"
|
|
114
|
+
]);
|
|
115
|
+
v.object({ error: v.object({ code: accountSecurityErrorCodeSchema }) });
|
|
116
|
+
const cloudMFAStatusSchema = v.object({
|
|
117
|
+
required: v.boolean(),
|
|
118
|
+
enabled: v.boolean(),
|
|
119
|
+
totpEnabled: v.boolean(),
|
|
120
|
+
assured: v.boolean(),
|
|
121
|
+
totpAvailable: v.boolean(),
|
|
122
|
+
passkeysAvailable: v.boolean(),
|
|
123
|
+
recoveryCodesAvailable: v.boolean()
|
|
124
|
+
});
|
|
125
|
+
v.object({ mfa: cloudMFAStatusSchema });
|
|
126
|
+
const cloudMFAEnableSchema = v.object({ password: v.optional(v.string()) });
|
|
127
|
+
v.object({
|
|
128
|
+
totpURI: v.string(),
|
|
129
|
+
backupCodes: v.array(v.string())
|
|
130
|
+
});
|
|
131
|
+
const cloudMFAVerifySchema = v.object({ code: v.pipe(v.string(), v.trim(), v.minLength(1)) });
|
|
132
|
+
v.object({ ok: v.literal(true) });
|
|
133
|
+
v.object({ backupCodes: v.array(v.string()) });
|
|
134
|
+
const cloudPasskeySchema = v.object({
|
|
135
|
+
id: v.string(),
|
|
136
|
+
name: v.nullish(v.string()),
|
|
137
|
+
createdAt: v.string()
|
|
138
|
+
});
|
|
139
|
+
v.object({ passkeys: v.array(cloudPasskeySchema) });
|
|
140
|
+
const cloudPasskeyDeleteSchema = v.object({ id: v.string() });
|
|
141
|
+
/**
|
|
142
|
+
* Personal access tokens: an account's own credentials for scripts and CI, sent as
|
|
143
|
+
* `Authorization: Bearer <token>`. A token acts as its account on the document API only; it never
|
|
144
|
+
* changes how the account is reached, makes other tokens, or reaches administration.
|
|
145
|
+
*/
|
|
146
|
+
const CLOUD_ACCESS_TOKEN_PREFIX = "opc_";
|
|
147
|
+
const cloudAccessTokenSchema = v.object({
|
|
148
|
+
id: v.string(),
|
|
149
|
+
name: v.string(),
|
|
150
|
+
/** The token's first characters, prefix included, to tell tokens apart; never the whole token. */
|
|
151
|
+
start: v.nullable(v.string()),
|
|
152
|
+
createdAt: v.string(),
|
|
153
|
+
expiresAt: v.nullable(v.string()),
|
|
154
|
+
lastUsedAt: v.nullable(v.string())
|
|
155
|
+
});
|
|
156
|
+
v.object({ tokens: v.array(cloudAccessTokenSchema) });
|
|
157
|
+
const cloudAccessTokenCreateSchema = v.object({
|
|
158
|
+
name: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(64)),
|
|
159
|
+
expiresInDays: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(365))
|
|
160
|
+
});
|
|
161
|
+
v.object({
|
|
162
|
+
token: v.pipe(v.string(), v.startsWith(CLOUD_ACCESS_TOKEN_PREFIX)),
|
|
163
|
+
accessToken: cloudAccessTokenSchema
|
|
164
|
+
});
|
|
165
|
+
const cloudAccessTokenRevokeSchema = v.object({ id: v.pipe(v.string(), v.minLength(1)) });
|
|
166
|
+
v.object({ ok: v.literal(true) });
|
|
167
|
+
/** Who an account belongs to, as the portal shows it. */
|
|
168
|
+
const cloudPersonSchema = v.object({
|
|
169
|
+
id: v.string(),
|
|
170
|
+
name: v.string(),
|
|
171
|
+
email: v.pipe(v.string(), v.email()),
|
|
172
|
+
/** The address of the account's picture, which the server serves; null shows initials. */
|
|
173
|
+
image: v.nullable(v.string())
|
|
174
|
+
});
|
|
175
|
+
/** What a person can see and change about themselves. */
|
|
176
|
+
const cloudProfileSchema = v.object({
|
|
177
|
+
...cloudPersonSchema.entries,
|
|
178
|
+
createdAt: v.string(),
|
|
179
|
+
/** Whether the server can send the verification a new email address needs. */
|
|
180
|
+
emailChangeAvailable: v.boolean()
|
|
181
|
+
});
|
|
182
|
+
v.object({ profile: cloudProfileSchema });
|
|
183
|
+
const cloudProfileUpdateSchema = v.object({ name: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(100)) });
|
|
184
|
+
/** The largest picture an account may upload, once the page has cropped and shrunk it. */
|
|
185
|
+
const CLOUD_PICTURE_MAX_BYTES = 262144;
|
|
186
|
+
const cloudPictureUploadSchema = v.object({
|
|
187
|
+
/** The picture's PNG or JPEG bytes, in Base64. */
|
|
188
|
+
data: v.pipe(v.string(), v.maxLength(Math.ceil(CLOUD_PICTURE_MAX_BYTES / 3) * 4), v.check((value) => isValid(value))) });
|
|
189
|
+
v.object({ image: v.string() });
|
|
190
|
+
const cloudEmailChangeSchema = v.object({
|
|
191
|
+
newEmail: v.pipe(v.string(), v.trim(), v.toLowerCase(), v.email()),
|
|
192
|
+
callbackURL: v.pipe(v.string(), v.url())
|
|
193
|
+
});
|
|
194
|
+
/** How a sign-in was made: the method it used, or the desktop app's approved code. */
|
|
195
|
+
const SIGN_IN_METHODS = [
|
|
196
|
+
"password",
|
|
197
|
+
...CLOUD_SOCIAL_PROVIDERS,
|
|
198
|
+
"passkey",
|
|
199
|
+
"two-step",
|
|
200
|
+
"email-link",
|
|
201
|
+
"desktop",
|
|
202
|
+
"other"
|
|
203
|
+
];
|
|
204
|
+
const cloudSignInMethodSchema = v.picklist(SIGN_IN_METHODS);
|
|
205
|
+
/** A method a newer server names that this editor does not know reads as `other`; a value that is
|
|
206
|
+
* not a method name at all still fails. */
|
|
207
|
+
const signInMethodResponseSchema = v.pipe(v.string(), v.transform((method) => v.is(cloudSignInMethodSchema, method) ? method : "other"));
|
|
208
|
+
const cloudAccountSessionSchema = v.object({
|
|
209
|
+
id: v.string(),
|
|
210
|
+
/** The session this request was made with. */
|
|
211
|
+
current: v.boolean(),
|
|
212
|
+
method: v.nullable(signInMethodResponseSchema),
|
|
213
|
+
ipAddress: v.nullable(v.string()),
|
|
214
|
+
/** The browser and system the server read from the client's user agent, such as `Chrome 141`. */
|
|
215
|
+
browser: v.nullable(v.string()),
|
|
216
|
+
system: v.nullable(v.string()),
|
|
217
|
+
createdAt: v.string(),
|
|
218
|
+
lastActiveAt: v.string(),
|
|
219
|
+
expiresAt: v.string()
|
|
220
|
+
});
|
|
221
|
+
v.object({ sessions: v.array(cloudAccountSessionSchema) });
|
|
222
|
+
const cloudSessionRevokeSchema = v.object({ sessionId: v.pipe(v.string(), v.minLength(1)) });
|
|
223
|
+
const cloudSignInSchema = v.object({
|
|
224
|
+
id: v.string(),
|
|
225
|
+
method: signInMethodResponseSchema,
|
|
226
|
+
ipAddress: v.nullable(v.string()),
|
|
227
|
+
/** The browser and system the server read from the client's user agent, such as `Chrome 141`. */
|
|
228
|
+
browser: v.nullable(v.string()),
|
|
229
|
+
system: v.nullable(v.string()),
|
|
230
|
+
createdAt: v.string()
|
|
231
|
+
});
|
|
232
|
+
v.object({ signIns: v.array(cloudSignInSchema) });
|
|
233
|
+
/** A workspace an account deletion reads: one it would delete, or one that stops it. */
|
|
234
|
+
const cloudAccountDeletionWorkspaceSchema = v.object({
|
|
235
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
236
|
+
name: v.string()
|
|
237
|
+
});
|
|
238
|
+
/** A document the account would lose, which Download all saves first. */
|
|
239
|
+
const cloudAccountDeletionDocumentSchema = v.object({
|
|
240
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
241
|
+
name: v.string(),
|
|
242
|
+
workspaceName: v.string()
|
|
243
|
+
});
|
|
244
|
+
/**
|
|
245
|
+
* What deleting the account takes: the workspaces only it belongs to, which go with their
|
|
246
|
+
* documents; the ones it leaves to their other members; the ones it alone administers for other
|
|
247
|
+
* members, which stop the deletion until it makes someone else an admin; and the documents it
|
|
248
|
+
* would lose, those workspaces' and the ones it created in workspaces it leaves.
|
|
249
|
+
*/
|
|
250
|
+
const cloudAccountDeletionSchema = v.object({
|
|
251
|
+
/** The account is the deployment's only administrator, which also stops the deletion. */
|
|
252
|
+
lastAdministrator: v.boolean(),
|
|
253
|
+
blockedBy: v.array(cloudAccountDeletionWorkspaceSchema),
|
|
254
|
+
deletes: v.array(cloudAccountDeletionWorkspaceSchema),
|
|
255
|
+
leaves: v.array(cloudAccountDeletionWorkspaceSchema),
|
|
256
|
+
documents: v.array(cloudAccountDeletionDocumentSchema)
|
|
257
|
+
});
|
|
258
|
+
v.object({ deletion: cloudAccountDeletionSchema });
|
|
259
|
+
/** The password, for a session that signed in too long ago to delete the account on its own. */
|
|
260
|
+
const cloudAccountDeleteSchema = v.object({ password: v.optional(v.pipe(v.string(), v.minLength(1))) });
|
|
22
261
|
/** The `aud` of every token Cloud signs for its services. */
|
|
23
262
|
const CLOUD_SERVICES_TOKEN_AUDIENCE = "openpencil-services";
|
|
24
263
|
/** Where Cloud publishes the public keys a service verifies its tokens with. */
|
|
@@ -36,16 +275,12 @@ const CLOUD_SERVICES_API_PATHS = {
|
|
|
36
275
|
search: "/v1/search"
|
|
37
276
|
};
|
|
38
277
|
const urlSchema$1 = v.pipe(v.string(), v.url());
|
|
39
|
-
const creditsSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
278
|
+
const creditsSchema$1 = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
40
279
|
const cloudServicesDiscoverySchema = v.object({
|
|
41
280
|
endpoint: urlSchema$1,
|
|
42
281
|
contractVersion: v.literal("1")
|
|
43
282
|
});
|
|
44
|
-
const cloudBillingDiscoverySchema = v.object({ portalURL: urlSchema$1 });
|
|
45
283
|
const createServicesTokenSchema = v.object({ workspaceId: v.pipe(v.string(), v.uuid()) });
|
|
46
|
-
function parseCreateServicesToken(input) {
|
|
47
|
-
return v.parse(createServicesTokenSchema, input);
|
|
48
|
-
}
|
|
49
284
|
v.object({
|
|
50
285
|
token: v.pipe(v.string(), v.minLength(1)),
|
|
51
286
|
expiresAt: v.pipe(v.string(), v.isoTimestamp())
|
|
@@ -58,12 +293,11 @@ const servicesTokenClaimsSchema = v.object({
|
|
|
58
293
|
workspaceId: v.pipe(v.string(), v.uuid()),
|
|
59
294
|
/**
|
|
60
295
|
* The account whose credits the request spends: the workspace's owner, whose allowance every
|
|
61
|
-
* workspace they own shares.
|
|
62
|
-
* a relay takes as the workspace's own allowance, as such a Cloud meant.
|
|
296
|
+
* workspace they own shares.
|
|
63
297
|
*/
|
|
64
|
-
accountId: v.
|
|
298
|
+
accountId: v.pipe(v.string(), v.minLength(1)),
|
|
65
299
|
/** Credits the owner's plan grants each month; `null` when Cloud sets no allowance. */
|
|
66
|
-
monthlyCreditAllowance: v.nullable(creditsSchema),
|
|
300
|
+
monthlyCreditAllowance: v.nullable(creditsSchema$1),
|
|
67
301
|
iat: v.pipe(v.number(), v.integer()),
|
|
68
302
|
exp: v.pipe(v.number(), v.integer())
|
|
69
303
|
});
|
|
@@ -71,8 +305,8 @@ const chatModelSchema = v.object({
|
|
|
71
305
|
id: v.pipe(v.string(), v.minLength(1)),
|
|
72
306
|
label: v.pipe(v.string(), v.minLength(1)),
|
|
73
307
|
/** Credits per million input and output tokens. */
|
|
74
|
-
creditsPerMillionInputTokens: creditsSchema,
|
|
75
|
-
creditsPerMillionOutputTokens: creditsSchema,
|
|
308
|
+
creditsPerMillionInputTokens: creditsSchema$1,
|
|
309
|
+
creditsPerMillionOutputTokens: creditsSchema$1,
|
|
76
310
|
contextTokens: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
77
311
|
capabilities: v.object({
|
|
78
312
|
reasoning: v.boolean(),
|
|
@@ -81,24 +315,51 @@ const chatModelSchema = v.object({
|
|
|
81
315
|
})
|
|
82
316
|
});
|
|
83
317
|
/** What one web search costs; a service without search leaves it out of its catalog. */
|
|
84
|
-
const searchPricingSchema = v.object({ creditsPerRequest: creditsSchema });
|
|
85
|
-
const
|
|
318
|
+
const searchPricingSchema = v.object({ creditsPerRequest: creditsSchema$1 });
|
|
319
|
+
const modelIDSchema = v.pipe(v.string(), v.minLength(1));
|
|
320
|
+
/**
|
|
321
|
+
* The model the service recommends for each of the editor's roles: Design runs the chat, Review
|
|
322
|
+
* critiques designs, Fast does quick tasks such as naming conversations, and Vision reads images.
|
|
323
|
+
* An editor signed in to the service with no model of its own yet sets itself up with them, so
|
|
324
|
+
* nobody has to choose one. Vision `null` recommends none, and the editor leaves it unassigned.
|
|
325
|
+
*/
|
|
326
|
+
const roleModelsSchema = v.object({
|
|
327
|
+
design: modelIDSchema,
|
|
328
|
+
review: modelIDSchema,
|
|
329
|
+
fast: modelIDSchema,
|
|
330
|
+
vision: v.nullable(modelIDSchema)
|
|
331
|
+
});
|
|
332
|
+
const serviceCatalogSchema = v.pipe(v.object({
|
|
86
333
|
models: v.array(chatModelSchema),
|
|
87
|
-
defaultModelID:
|
|
334
|
+
defaultModelID: modelIDSchema,
|
|
335
|
+
/**
|
|
336
|
+
* Absent from a service that predates it, or whose default model can't run the chat. Editors
|
|
337
|
+
* then use `defaultModelID` for every role, except Vision when that model reads no images,
|
|
338
|
+
* and set nothing up when it calls no tools.
|
|
339
|
+
*/
|
|
340
|
+
roleModels: v.optional(roleModelsSchema),
|
|
88
341
|
search: v.optional(searchPricingSchema)
|
|
89
|
-
})
|
|
342
|
+
}), v.check(({ models, roleModels }) => {
|
|
343
|
+
if (!roleModels) return true;
|
|
344
|
+
const can = (id, capability) => {
|
|
345
|
+
if (id === null) return true;
|
|
346
|
+
const model = models.find((candidate) => candidate.id === id);
|
|
347
|
+
return model !== void 0 && (capability === null || model.capabilities[capability]);
|
|
348
|
+
};
|
|
349
|
+
return can(roleModels.design, "tools") && can(roleModels.review, null) && can(roleModels.fast, "tools") && can(roleModels.vision, "vision");
|
|
350
|
+
}, "A recommended model is not in the catalog or cannot do its role"));
|
|
90
351
|
const creditBucketSchema = v.object({
|
|
91
352
|
kind: v.picklist([
|
|
92
353
|
"allowance",
|
|
93
354
|
"purchased",
|
|
94
355
|
"grant"
|
|
95
356
|
]),
|
|
96
|
-
remaining: creditsSchema,
|
|
357
|
+
remaining: creditsSchema$1,
|
|
97
358
|
expiresAt: v.nullable(v.pipe(v.string(), v.isoTimestamp()))
|
|
98
359
|
});
|
|
99
360
|
v.object({
|
|
100
361
|
/** Credits left to spend; `null` when the service sets no limit. */
|
|
101
|
-
balance: v.nullable(creditsSchema),
|
|
362
|
+
balance: v.nullable(creditsSchema$1),
|
|
102
363
|
/** Spent first to last. */
|
|
103
364
|
buckets: v.array(creditBucketSchema)
|
|
104
365
|
});
|
|
@@ -112,7 +373,7 @@ const usageEntrySchema = v.object({
|
|
|
112
373
|
]),
|
|
113
374
|
modelID: v.nullable(v.string()),
|
|
114
375
|
userId: v.pipe(v.string(), v.minLength(1)),
|
|
115
|
-
credits: creditsSchema
|
|
376
|
+
credits: creditsSchema$1
|
|
116
377
|
});
|
|
117
378
|
v.object({
|
|
118
379
|
query: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(1e3)),
|
|
@@ -128,9 +389,6 @@ const searchResultSchema = v.object({
|
|
|
128
389
|
});
|
|
129
390
|
v.object({ results: v.array(searchResultSchema) });
|
|
130
391
|
const usageQuerySchema = v.object({ cursor: v.optional(v.pipe(v.string(), v.minLength(1))) });
|
|
131
|
-
function parseUsageQuery(input) {
|
|
132
|
-
return v.parse(usageQuerySchema, input);
|
|
133
|
-
}
|
|
134
392
|
v.object({
|
|
135
393
|
entries: v.array(usageEntrySchema),
|
|
136
394
|
next: v.nullable(v.string())
|
|
@@ -159,6 +417,137 @@ const SERVICE_ERROR_STATUS = {
|
|
|
159
417
|
capability_unavailable: 404,
|
|
160
418
|
rate_limited: 429
|
|
161
419
|
};
|
|
420
|
+
/**
|
|
421
|
+
* Whether a bearer token may travel to `url`: over HTTPS, or in the clear only to a loopback
|
|
422
|
+
* address, for development. Only literal addresses count, since a name such as `localhost` is
|
|
423
|
+
* whatever the resolver answers. Services and billing tokens act as the account until they expire.
|
|
424
|
+
*/
|
|
425
|
+
function sendsTokenSafely(url) {
|
|
426
|
+
const { protocol, hostname } = new URL(url);
|
|
427
|
+
if (protocol === "https:") return true;
|
|
428
|
+
if (protocol !== "http:") return false;
|
|
429
|
+
return hostname === "[::1]" || /^127(\.\d{1,3}){3}$/.test(hostname);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* The `aud` of the tokens Cloud signs for its billing service, with the services' signing key,
|
|
433
|
+
* whose public keys it publishes at `CLOUD_SERVICES_JWKS_PATH`.
|
|
434
|
+
*/
|
|
435
|
+
const CLOUD_BILLING_TOKEN_AUDIENCE = "openpencil-billing";
|
|
436
|
+
/**
|
|
437
|
+
* The page of a Cloud server where the signed-in person sees their plan, buys a plan or credits,
|
|
438
|
+
* and manages what they pay for; editors link to it whenever the server advertises billing.
|
|
439
|
+
*/
|
|
440
|
+
const CLOUD_ACCOUNT_PLAN_PATH = "/account/plan";
|
|
441
|
+
/**
|
|
442
|
+
* Where the billing service answers, below the discovered `endpoint`. Cloud posts to `seats`,
|
|
443
|
+
* with a billing token for the account as its bearer, whenever the people who can edit in that
|
|
444
|
+
* account's workspaces change; the service reads the count from Cloud's internal API.
|
|
445
|
+
*/
|
|
446
|
+
const CLOUD_BILLING_API_PATHS = {
|
|
447
|
+
base: "/v1",
|
|
448
|
+
catalog: "/v1/catalog",
|
|
449
|
+
seats: "/v1/seats",
|
|
450
|
+
account: "/v1/account",
|
|
451
|
+
checkout: "/v1/checkout",
|
|
452
|
+
portal: "/v1/portal"
|
|
453
|
+
};
|
|
454
|
+
const urlSchema = v.pipe(v.string(), v.url());
|
|
455
|
+
const idSchema = v.pipe(v.string(), v.regex(/^[a-z0-9][a-z0-9-]{0,62}$/));
|
|
456
|
+
const centsSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
457
|
+
const bytesSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
458
|
+
const creditsSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
459
|
+
/**
|
|
460
|
+
* What an account without a plan has: the deployment's free plan, which a pricing page compares
|
|
461
|
+
* the plans with.
|
|
462
|
+
*/
|
|
463
|
+
const billingFreePlanSchema = v.object({
|
|
464
|
+
/** The storage an account may use, or `null` for no limit. */
|
|
465
|
+
storageBytes: v.nullable(bytesSchema),
|
|
466
|
+
/** Whether the free plan includes services, such as AI and search. */
|
|
467
|
+
services: v.boolean(),
|
|
468
|
+
/** Credits granted each month with services, or `null` for no monthly limit. */
|
|
469
|
+
monthlyCredits: v.nullable(creditsSchema)
|
|
470
|
+
});
|
|
471
|
+
const cloudBillingDiscoverySchema = v.object({
|
|
472
|
+
endpoint: urlSchema,
|
|
473
|
+
contractVersion: v.literal("1"),
|
|
474
|
+
freePlan: v.optional(billingFreePlanSchema)
|
|
475
|
+
});
|
|
476
|
+
v.object({
|
|
477
|
+
token: v.pipe(v.string(), v.minLength(1)),
|
|
478
|
+
expiresAt: v.pipe(v.string(), v.isoTimestamp())
|
|
479
|
+
});
|
|
480
|
+
v.object({
|
|
481
|
+
iss: urlSchema,
|
|
482
|
+
aud: v.literal(CLOUD_BILLING_TOKEN_AUDIENCE),
|
|
483
|
+
/** The account: the Cloud user whose plan and credits these are. */
|
|
484
|
+
sub: v.pipe(v.string(), v.minLength(1)),
|
|
485
|
+
/** Where the payment provider sends receipts and invoices. */
|
|
486
|
+
email: v.pipe(v.string(), v.email()),
|
|
487
|
+
iat: v.pipe(v.number(), v.integer()),
|
|
488
|
+
exp: v.pipe(v.number(), v.integer())
|
|
489
|
+
});
|
|
490
|
+
const seatCountSchema = v.pipe(v.number(), v.integer(), v.minValue(1));
|
|
491
|
+
/**
|
|
492
|
+
* A plan priced by the seat: everyone who can edit in the account's workspaces takes one, and the
|
|
493
|
+
* account pays for at least `minimum`. Every seat costs the price of the tier its count reaches,
|
|
494
|
+
* and adds its storage and credits to what the account shares.
|
|
495
|
+
*/
|
|
496
|
+
const billingSeatPricingSchema = v.object({
|
|
497
|
+
minimum: seatCountSchema,
|
|
498
|
+
/** From the fewest seats up: the first from 1, each later one from more seats. */
|
|
499
|
+
tiers: v.pipe(v.array(v.object({
|
|
500
|
+
fromSeats: seatCountSchema,
|
|
501
|
+
unitPriceCents: centsSchema
|
|
502
|
+
})), 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")),
|
|
503
|
+
storageBytesPerSeat: bytesSchema,
|
|
504
|
+
monthlyCreditsPerSeat: creditsSchema
|
|
505
|
+
});
|
|
506
|
+
/**
|
|
507
|
+
* A plan an account subscribes to, billed every month in US dollars before tax. A plan priced by
|
|
508
|
+
* the seat states its price, storage, and credits at its minimum, so an editor that reads no
|
|
509
|
+
* `seats` still shows what it starts at.
|
|
510
|
+
*/
|
|
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
|
+
seats: v.optional(billingSeatPricingSchema)
|
|
518
|
+
});
|
|
519
|
+
/** Credits an account on a plan buys once, in US dollars before tax. */
|
|
520
|
+
const creditPackSchema = v.object({
|
|
521
|
+
id: idSchema,
|
|
522
|
+
credits: creditsSchema,
|
|
523
|
+
priceCents: centsSchema,
|
|
524
|
+
/** How long the credits last from purchase. */
|
|
525
|
+
validDays: v.pipe(v.number(), v.integer(), v.minValue(1))
|
|
526
|
+
});
|
|
527
|
+
v.object({
|
|
528
|
+
plans: v.array(billingPlanSchema),
|
|
529
|
+
creditPacks: v.array(creditPackSchema)
|
|
530
|
+
});
|
|
531
|
+
v.object({ subscription: v.nullable(v.object({
|
|
532
|
+
planId: idSchema,
|
|
533
|
+
status: v.picklist(["active", "past_due"]),
|
|
534
|
+
/** When the current period ends: the next charge, or the end of a cancelled plan. */
|
|
535
|
+
currentPeriodEnd: v.pipe(v.string(), v.isoTimestamp()),
|
|
536
|
+
/** Whether the plan ends at `currentPeriodEnd` instead of renewing. */
|
|
537
|
+
cancelsAtPeriodEnd: v.boolean()
|
|
538
|
+
})) });
|
|
539
|
+
v.union([v.object({ planId: idSchema }), v.object({ creditPackId: idSchema })]);
|
|
540
|
+
v.object({ url: v.pipe(urlSchema, v.regex(/^https:\/\//i, "Billing sends people to an HTTPS page")) });
|
|
541
|
+
const billingErrorCodeSchema = v.picklist([
|
|
542
|
+
"invalid_request",
|
|
543
|
+
"unauthorized",
|
|
544
|
+
"not_allowed",
|
|
545
|
+
"provider_unavailable"
|
|
546
|
+
]);
|
|
547
|
+
v.object({ error: v.object({
|
|
548
|
+
code: billingErrorCodeSchema,
|
|
549
|
+
message: v.optional(v.string())
|
|
550
|
+
}) });
|
|
162
551
|
//#endregion
|
|
163
552
|
//#region src/contract/documents.ts
|
|
164
553
|
const CLOUD_PROTOCOL_MAX_UPLOAD_BYTES = 1073741824;
|
|
@@ -329,24 +718,6 @@ const commitImageUploadsSchema = v.object({ uploads: v.pipe(v.array(v.object({
|
|
|
329
718
|
checksum: checksumSchema,
|
|
330
719
|
multipart: commitUploadSchema.entries.multipart
|
|
331
720
|
})), v.minLength(1), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)) });
|
|
332
|
-
function parseCreateDocument(input) {
|
|
333
|
-
return v.parse(createDocumentSchema, input);
|
|
334
|
-
}
|
|
335
|
-
function parseCreateUpload(input) {
|
|
336
|
-
return v.parse(createUploadSchema, input);
|
|
337
|
-
}
|
|
338
|
-
function parseRequestImageUploads(input) {
|
|
339
|
-
return v.parse(requestImageUploadsSchema, input);
|
|
340
|
-
}
|
|
341
|
-
function parseCommitImageUploads(input) {
|
|
342
|
-
return v.parse(commitImageUploadsSchema, input);
|
|
343
|
-
}
|
|
344
|
-
function parseRequestImageLinks(input) {
|
|
345
|
-
return v.parse(requestImageLinksSchema, input);
|
|
346
|
-
}
|
|
347
|
-
function parseCommitUpload(input) {
|
|
348
|
-
return v.parse(commitUploadSchema, input);
|
|
349
|
-
}
|
|
350
721
|
//#endregion
|
|
351
722
|
//#region src/contract/relay.ts
|
|
352
723
|
/** Where the relay accepts WebSocket upgrades, under the Cloud API origin. */
|
|
@@ -374,7 +745,9 @@ const COLLAB_ACTIONS = {
|
|
|
374
745
|
agentPreview: "agent-preview",
|
|
375
746
|
upload: "upload",
|
|
376
747
|
/** From the server only: the document's version history changed, so open lists load it again. */
|
|
377
|
-
versions: "versions"
|
|
748
|
+
versions: "versions",
|
|
749
|
+
/** From the server only: a comment thread changed; the payload is its ID as UTF-8. */
|
|
750
|
+
comments: "comments"
|
|
378
751
|
};
|
|
379
752
|
/**
|
|
380
753
|
* The most a room message may decode to, compressed or not. A peer's update past it is dropped
|
|
@@ -621,6 +994,11 @@ function decodeRelayClientFrame(data) {
|
|
|
621
994
|
}
|
|
622
995
|
const CLOUD_DISCOVERY_PATH = "/.well-known/openpencil";
|
|
623
996
|
const cloudDeploymentSchema = v.picklist(["official", "self-hosted"]);
|
|
997
|
+
/**
|
|
998
|
+
* The server's sign-in providers that this editor knows. A newer server may offer one this editor
|
|
999
|
+
* has no button for; it is left out rather than failing discovery, so the editor still connects.
|
|
1000
|
+
*/
|
|
1001
|
+
const socialProvidersSchema = v.pipe(v.array(v.string()), v.transform((providers) => providers.filter(isKnownSocialProvider)));
|
|
624
1002
|
const cloudAuthenticationSchema = v.object({
|
|
625
1003
|
emailPassword: v.optional(v.object({
|
|
626
1004
|
signIn: v.boolean(),
|
|
@@ -631,7 +1009,7 @@ const cloudAuthenticationSchema = v.object({
|
|
|
631
1009
|
siteKey: v.pipe(v.string(), v.trim(), v.minLength(1))
|
|
632
1010
|
}))
|
|
633
1011
|
})),
|
|
634
|
-
socialProviders:
|
|
1012
|
+
socialProviders: socialProvidersSchema,
|
|
635
1013
|
enterpriseSSO: v.boolean(),
|
|
636
1014
|
enrollmentMode: v.optional(v.picklist([
|
|
637
1015
|
"open",
|
|
@@ -650,8 +1028,41 @@ const cloudCapabilitiesSchema = v.object({
|
|
|
650
1028
|
workspaces: v.boolean(),
|
|
651
1029
|
collaboration: v.boolean()
|
|
652
1030
|
});
|
|
653
|
-
/**
|
|
654
|
-
|
|
1031
|
+
/**
|
|
1032
|
+
* An editor version, as SemVer: a release such as `0.18.0`, or a pre-release such as
|
|
1033
|
+
* `0.18.0-beta.2` or a nightly's `0.18.0-nightly.20261116`.
|
|
1034
|
+
*
|
|
1035
|
+
* Editors before 0.18.0 accept only `major.minor.patch` here and fail discovery on anything else,
|
|
1036
|
+
* so a server names a pre-release minimum only once its minimum is already 0.18.0 or later.
|
|
1037
|
+
*/
|
|
1038
|
+
const cloudEditorVersionSchema = v.pipe(v.string(), v.check(isSemVer, "Expected a SemVer version"));
|
|
1039
|
+
/**
|
|
1040
|
+
* Whether the text is exactly a SemVer version, build metadata included: semver's own parse also
|
|
1041
|
+
* takes a `v` prefix or spaces, which a version here never has.
|
|
1042
|
+
*/
|
|
1043
|
+
function isSemVer(value) {
|
|
1044
|
+
const parsed = parseVersion(value);
|
|
1045
|
+
if (!parsed) return false;
|
|
1046
|
+
const build = parsed.build.length > 0 ? `+${parsed.build.join(".")}` : "";
|
|
1047
|
+
return `${parsed.version}${build}` === value;
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* The header desktop editors send with each request, naming their version, so a server can refuse
|
|
1051
|
+
* an editor older than its `minimumEditorVersion`. Browser editors leave it out: the server serves
|
|
1052
|
+
* them, and an older server's CORS rules would refuse a header they don't list.
|
|
1053
|
+
*/
|
|
1054
|
+
const CLOUD_EDITOR_VERSION_HEADER = "X-OpenPencil-Editor-Version";
|
|
1055
|
+
/**
|
|
1056
|
+
* Whether `version` is `minimum` or later, in SemVer order: a pre-release comes before its
|
|
1057
|
+
* release, so `0.18.0-beta.2` is not at least `0.18.0`; a release's nightlies come after its
|
|
1058
|
+
* betas and order by date. To admit a release's pre-releases, name the earliest one, such as
|
|
1059
|
+
* `0.18.0-beta.1`, or `0.18.0-nightly.20261116` for nightlies from that day on. A
|
|
1060
|
+
* version that isn't SemVer, on either side, is not at least anything.
|
|
1061
|
+
*/
|
|
1062
|
+
function isEditorVersionAtLeast(version, minimum) {
|
|
1063
|
+
if (!isSemVer(version) || !isSemVer(minimum)) return false;
|
|
1064
|
+
return compareVersions(version, minimum) >= 0;
|
|
1065
|
+
}
|
|
655
1066
|
/**
|
|
656
1067
|
* Whether editors offer this server to everyone, and from which editor version on. Only the
|
|
657
1068
|
* official server's listing is read: it turns the Cloud entry points on without an editor release,
|
|
@@ -672,6 +1083,26 @@ const cloudLegalDiscoverySchema = v.object({
|
|
|
672
1083
|
abuseEmail: v.optional(v.pipe(v.string(), v.email())),
|
|
673
1084
|
minimumAge: v.optional(v.pipe(v.number(), v.integer()))
|
|
674
1085
|
});
|
|
1086
|
+
/** A web address a page may link or load: `http` or `https` only, never a script or data URL. */
|
|
1087
|
+
const webURLSchema = v.pipe(v.string(), v.url(), v.check((value) => ["http:", "https:"].includes(new URL(value).protocol)));
|
|
1088
|
+
/**
|
|
1089
|
+
* How a self-hosted server names itself on its public pages: the operator's name and logo in the
|
|
1090
|
+
* bar, and where its people get help. The official server is OpenPencil's own and names none.
|
|
1091
|
+
*/
|
|
1092
|
+
const cloudBrandingSchema = v.object({
|
|
1093
|
+
name: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(80))),
|
|
1094
|
+
logoURL: v.optional(webURLSchema),
|
|
1095
|
+
helpURL: v.optional(webURLSchema)
|
|
1096
|
+
});
|
|
1097
|
+
/**
|
|
1098
|
+
* The server's community gallery: the workspace whose documents anyone may open read-only.
|
|
1099
|
+
* Saving to it publishes, so editors never choose it for anyone and say so when it is chosen.
|
|
1100
|
+
* `tourDocumentId` is the gallery document editors open as their tour.
|
|
1101
|
+
*/
|
|
1102
|
+
const cloudCommunityDiscoverySchema = v.object({
|
|
1103
|
+
workspaceId: v.pipe(v.string(), v.uuid()),
|
|
1104
|
+
tourDocumentId: v.optional(v.pipe(v.string(), v.uuid()))
|
|
1105
|
+
});
|
|
675
1106
|
const cloudDiscoverySchema = v.object({
|
|
676
1107
|
protocolVersion: v.literal("1"),
|
|
677
1108
|
deployment: cloudDeploymentSchema,
|
|
@@ -682,32 +1113,37 @@ const cloudDiscoverySchema = v.object({
|
|
|
682
1113
|
authentication: cloudAuthenticationSchema,
|
|
683
1114
|
capabilities: cloudCapabilitiesSchema,
|
|
684
1115
|
listing: v.optional(cloudListingSchema),
|
|
1116
|
+
/**
|
|
1117
|
+
* The oldest editor version the server works with. Older editors ask to be updated instead of
|
|
1118
|
+
* connecting, and the server refuses their requests.
|
|
1119
|
+
*/
|
|
1120
|
+
minimumEditorVersion: v.optional(cloudEditorVersionSchema),
|
|
685
1121
|
/** The services editors reach with Cloud-signed tokens; absent when the deployment has none. */
|
|
686
1122
|
services: v.optional(cloudServicesDiscoverySchema),
|
|
687
1123
|
/** Where people manage their plan and buy credits; absent when the deployment does not bill. */
|
|
688
1124
|
billing: v.optional(cloudBillingDiscoverySchema),
|
|
689
|
-
|
|
1125
|
+
/** The community gallery; absent when the deployment has none. */
|
|
1126
|
+
community: v.optional(cloudCommunityDiscoverySchema),
|
|
1127
|
+
legal: v.optional(cloudLegalDiscoverySchema),
|
|
1128
|
+
branding: v.optional(cloudBrandingSchema)
|
|
690
1129
|
});
|
|
691
1130
|
function parseCloudDiscovery(input) {
|
|
692
1131
|
return v.parse(cloudDiscoverySchema, input);
|
|
693
1132
|
}
|
|
694
1133
|
//#endregion
|
|
695
1134
|
//#region src/server/validation.ts
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
}
|
|
705
|
-
function validatedJSON(parse) {
|
|
706
|
-
return validator("json", (value, context) => parseOrReject(parse, value, context));
|
|
1135
|
+
const invalidRequest = { error: { code: "invalid_request" } };
|
|
1136
|
+
/**
|
|
1137
|
+
* A JSON body through `schema`; handlers read it from `context.req.valid('json')`. A body that
|
|
1138
|
+
* fails it is a 400, never a server error. The route's type takes what the schema accepts and
|
|
1139
|
+
* hands handlers what it outputs, so a typed client may leave out a field with a default.
|
|
1140
|
+
*/
|
|
1141
|
+
function validatedJSON(schema) {
|
|
1142
|
+
return sValidator("json", schema, (result, context) => result.success ? void 0 : context.json(invalidRequest, 400));
|
|
707
1143
|
}
|
|
708
1144
|
/** Query string counterpart of `validatedJSON`. */
|
|
709
|
-
function validatedQuery(
|
|
710
|
-
return
|
|
1145
|
+
function validatedQuery(schema) {
|
|
1146
|
+
return sValidator("query", schema, (result, context) => result.success ? void 0 : context.json(invalidRequest, 400));
|
|
711
1147
|
}
|
|
712
1148
|
/**
|
|
713
1149
|
* A route parameter that names a row by UUID, in lowercase: the database matches any case, but an
|
|
@@ -720,10 +1156,7 @@ const uuidParamSchema = v.pipe(v.string(), v.uuid(), v.toLowerCase());
|
|
|
720
1156
|
* value never reaches the database.
|
|
721
1157
|
*/
|
|
722
1158
|
function validatedParams(schema) {
|
|
723
|
-
return
|
|
724
|
-
const parsed = v.safeParse(schema, value);
|
|
725
|
-
return parsed.success ? parsed.output : context.json({ error: { code: "not_found" } }, 404);
|
|
726
|
-
});
|
|
1159
|
+
return sValidator("param", schema, (result, context) => result.success ? void 0 : context.json({ error: { code: "not_found" } }, 404));
|
|
727
1160
|
}
|
|
728
1161
|
/** A route parameter the server takes as text, such as a user ID, which is not a UUID column. */
|
|
729
1162
|
const textParamSchema = v.pipe(v.string(), v.minLength(1));
|
|
@@ -732,6 +1165,15 @@ const documentVersionParams = validatedParams(v.object({
|
|
|
732
1165
|
documentId: uuidParamSchema,
|
|
733
1166
|
versionId: uuidParamSchema
|
|
734
1167
|
}));
|
|
1168
|
+
const documentThreadParams = validatedParams(v.object({
|
|
1169
|
+
documentId: uuidParamSchema,
|
|
1170
|
+
threadId: uuidParamSchema
|
|
1171
|
+
}));
|
|
1172
|
+
const documentCommentParams = validatedParams(v.object({
|
|
1173
|
+
documentId: uuidParamSchema,
|
|
1174
|
+
threadId: uuidParamSchema,
|
|
1175
|
+
commentId: uuidParamSchema
|
|
1176
|
+
}));
|
|
735
1177
|
const documentShareParams = validatedParams(v.object({
|
|
736
1178
|
documentId: uuidParamSchema,
|
|
737
1179
|
shareId: uuidParamSchema
|
|
@@ -755,6 +1197,20 @@ const workspaceMemberParams = validatedParams(v.object({
|
|
|
755
1197
|
}));
|
|
756
1198
|
const accountParams = validatedParams(v.object({ userId: uuidParamSchema }));
|
|
757
1199
|
const shareParams = validatedParams(v.object({ shareId: uuidParamSchema }));
|
|
1200
|
+
const shareThreadParams = validatedParams(v.object({
|
|
1201
|
+
shareId: uuidParamSchema,
|
|
1202
|
+
threadId: uuidParamSchema
|
|
1203
|
+
}));
|
|
1204
|
+
const shareCommentParams = validatedParams(v.object({
|
|
1205
|
+
shareId: uuidParamSchema,
|
|
1206
|
+
threadId: uuidParamSchema,
|
|
1207
|
+
commentId: uuidParamSchema
|
|
1208
|
+
}));
|
|
1209
|
+
/** A document and one of its revisions, as a thumbnail's address names them. */
|
|
1210
|
+
const documentRevisionParams = validatedParams(v.object({
|
|
1211
|
+
documentId: uuidParamSchema,
|
|
1212
|
+
revisionId: uuidParamSchema
|
|
1213
|
+
}));
|
|
758
1214
|
const invitationParams = validatedParams(v.object({ invitationId: uuidParamSchema }));
|
|
759
1215
|
const invitationContinuationParams = validatedParams(v.object({ continuationId: textParamSchema }));
|
|
760
1216
|
const uploadParams = validatedParams(v.object({ uploadId: uuidParamSchema }));
|
|
@@ -767,14 +1223,14 @@ const pictureParams = validatedParams(v.object({
|
|
|
767
1223
|
}));
|
|
768
1224
|
//#endregion
|
|
769
1225
|
//#region src/server/policy/schema.ts
|
|
770
|
-
const positiveIntegerSchema
|
|
1226
|
+
const positiveIntegerSchema = v.pipe(v.number(), v.integer(), v.minValue(1));
|
|
771
1227
|
const nonNegativeIntegerSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
772
1228
|
const staticEntitlementsSchema = v.object({
|
|
773
1229
|
documents: v.optional(v.object({
|
|
774
|
-
maximumFileBytes: v.optional(positiveIntegerSchema
|
|
1230
|
+
maximumFileBytes: v.optional(positiveIntegerSchema),
|
|
775
1231
|
revisionHistory: v.optional(v.boolean())
|
|
776
1232
|
}), {}),
|
|
777
|
-
storage: v.optional(v.object({ maximumBytes: v.optional(positiveIntegerSchema
|
|
1233
|
+
storage: v.optional(v.object({ maximumBytes: v.optional(positiveIntegerSchema) }), {}),
|
|
778
1234
|
sharing: v.optional(v.object({
|
|
779
1235
|
links: v.optional(v.boolean()),
|
|
780
1236
|
guestView: v.optional(v.boolean()),
|
|
@@ -783,7 +1239,7 @@ const staticEntitlementsSchema = v.object({
|
|
|
783
1239
|
}), {}),
|
|
784
1240
|
collaboration: v.optional(v.object({
|
|
785
1241
|
enabled: v.optional(v.boolean()),
|
|
786
|
-
maximumParticipants: v.optional(positiveIntegerSchema
|
|
1242
|
+
maximumParticipants: v.optional(positiveIntegerSchema)
|
|
787
1243
|
}), {}),
|
|
788
1244
|
services: v.optional(v.object({
|
|
789
1245
|
enabled: v.optional(v.boolean()),
|
|
@@ -792,10 +1248,10 @@ const staticEntitlementsSchema = v.object({
|
|
|
792
1248
|
});
|
|
793
1249
|
const staticEntitlementsTOMLSchema = v.strictObject({
|
|
794
1250
|
documents: v.optional(v.strictObject({
|
|
795
|
-
maximum_file_bytes: v.optional(positiveIntegerSchema
|
|
1251
|
+
maximum_file_bytes: v.optional(positiveIntegerSchema),
|
|
796
1252
|
revision_history: v.optional(v.boolean())
|
|
797
1253
|
})),
|
|
798
|
-
storage: v.optional(v.strictObject({ maximum_bytes: v.optional(positiveIntegerSchema
|
|
1254
|
+
storage: v.optional(v.strictObject({ maximum_bytes: v.optional(positiveIntegerSchema) })),
|
|
799
1255
|
sharing: v.optional(v.strictObject({
|
|
800
1256
|
links: v.optional(v.boolean()),
|
|
801
1257
|
guest_view: v.optional(v.boolean()),
|
|
@@ -804,7 +1260,7 @@ const staticEntitlementsTOMLSchema = v.strictObject({
|
|
|
804
1260
|
})),
|
|
805
1261
|
collaboration: v.optional(v.strictObject({
|
|
806
1262
|
enabled: v.optional(v.boolean()),
|
|
807
|
-
maximum_participants: v.optional(positiveIntegerSchema
|
|
1263
|
+
maximum_participants: v.optional(positiveIntegerSchema)
|
|
808
1264
|
})),
|
|
809
1265
|
services: v.optional(v.strictObject({
|
|
810
1266
|
enabled: v.optional(v.boolean()),
|
|
@@ -835,6 +1291,7 @@ const rawCloudServerConfigSchema = v.object({
|
|
|
835
1291
|
deployment: v.picklist(["official", "self-hosted"]),
|
|
836
1292
|
publicURL: httpURLSchema,
|
|
837
1293
|
listingMinimumEditorVersion: v.optional(cloudEditorVersionSchema),
|
|
1294
|
+
minimumEditorVersion: v.optional(cloudEditorVersionSchema),
|
|
838
1295
|
relayURL: v.optional(websocketURLSchema),
|
|
839
1296
|
technicalLimits: v.optional(v.object({
|
|
840
1297
|
maximumUploadBytes: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(CLOUD_PROTOCOL_MAX_UPLOAD_BYTES)), CLOUD_PROTOCOL_MAX_UPLOAD_BYTES),
|
|
@@ -846,6 +1303,8 @@ const rawCloudServerConfigSchema = v.object({
|
|
|
846
1303
|
maximumConnectionsPerRoom: CLOUD_DEFAULT_MAX_CONNECTIONS_PER_ROOM
|
|
847
1304
|
}),
|
|
848
1305
|
staticEntitlements: v.optional(staticEntitlementsSchema),
|
|
1306
|
+
/** With database entitlements, what an account without stored ones takes, value by value. */
|
|
1307
|
+
defaultEntitlements: v.optional(staticEntitlementsSchema),
|
|
849
1308
|
databaseURL: v.pipe(v.string(), v.url()),
|
|
850
1309
|
authSecret: v.pipe(v.string(), v.minLength(32)),
|
|
851
1310
|
trustedOrigins: v.optional(v.array(httpURLSchema), []),
|
|
@@ -883,6 +1342,8 @@ const rawCloudServerConfigSchema = v.object({
|
|
|
883
1342
|
appleTeamId: optionalTextSchema,
|
|
884
1343
|
appleKeyId: optionalTextSchema,
|
|
885
1344
|
applePrivateKey: optionalTextSchema,
|
|
1345
|
+
githubClientId: optionalTextSchema,
|
|
1346
|
+
githubClientSecret: optionalTextSchema,
|
|
886
1347
|
appleAppBundleIdentifier: optionalTextSchema,
|
|
887
1348
|
s3Endpoint: httpURLSchema,
|
|
888
1349
|
s3Region: v.pipe(v.string(), v.trim(), v.minLength(1)),
|
|
@@ -902,6 +1363,7 @@ const rawCloudServerConfigSchema = v.object({
|
|
|
902
1363
|
smtpUser: optionalTextSchema,
|
|
903
1364
|
smtpPassword: optionalTextSchema,
|
|
904
1365
|
emailFrom: optionalTextSchema,
|
|
1366
|
+
emailReplyTo: v.optional(v.pipe(v.string(), v.email())),
|
|
905
1367
|
emailTransport: v.optional(v.picklist([
|
|
906
1368
|
"none",
|
|
907
1369
|
"smtp",
|
|
@@ -926,7 +1388,8 @@ const rawCloudServerConfigSchema = v.object({
|
|
|
926
1388
|
/** The PKCS #8 PEM of the P-256 key that signs service tokens. */
|
|
927
1389
|
servicesSigningKey: optionalTextSchema,
|
|
928
1390
|
servicesTokenLifetimeSeconds: v.optional(v.pipe(v.number(), v.integer(), v.minValue(60), v.maxValue(3600)), 600),
|
|
929
|
-
|
|
1391
|
+
/** The billing service accounts buy plans and credits from, which discovery advertises. */
|
|
1392
|
+
billingEndpoint: v.optional(httpURLSchema),
|
|
930
1393
|
/** The bearer token services such as billing present to the internal API. */
|
|
931
1394
|
internalServiceToken: v.optional(v.pipe(v.string(), v.minLength(32))),
|
|
932
1395
|
/**
|
|
@@ -942,11 +1405,28 @@ const rawCloudServerConfigSchema = v.object({
|
|
|
942
1405
|
abuseEmail: v.optional(v.pipe(v.string(), v.email())),
|
|
943
1406
|
minimumAge: v.optional(v.pipe(v.number(), v.integer(), v.minValue(13), v.maxValue(21)))
|
|
944
1407
|
})),
|
|
1408
|
+
/**
|
|
1409
|
+
* The workspace whose documents anyone may open read-only, without signing in or a link: the
|
|
1410
|
+
* deployment's community gallery. Without it the server has none.
|
|
1411
|
+
*/
|
|
1412
|
+
community: v.optional(v.object({
|
|
1413
|
+
workspaceId: v.pipe(v.string(), v.uuid()),
|
|
1414
|
+
/** The gallery document editors open as their tour. */
|
|
1415
|
+
tourDocumentId: v.optional(v.pipe(v.string(), v.uuid()))
|
|
1416
|
+
})),
|
|
1417
|
+
/** How a self-hosted server names itself on its public pages. */
|
|
1418
|
+
branding: v.optional(v.object({
|
|
1419
|
+
name: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(80))),
|
|
1420
|
+
logoURL: v.optional(httpURLSchema),
|
|
1421
|
+
helpURL: v.optional(httpURLSchema)
|
|
1422
|
+
})),
|
|
945
1423
|
/** Where server errors are reported; without it the server reports nothing. */
|
|
946
1424
|
errorTracking: v.optional(v.object({
|
|
947
1425
|
provider: v.literal("posthog"),
|
|
948
1426
|
host: httpURLSchema,
|
|
949
|
-
projectAPIKey: v.pipe(v.string(), v.trim(), v.minLength(1))
|
|
1427
|
+
projectAPIKey: v.pipe(v.string(), v.trim(), v.minLength(1)),
|
|
1428
|
+
/** Error reports name the account and records involved; off unless a deployment sets it. */
|
|
1429
|
+
includeIds: v.optional(v.boolean(), false)
|
|
950
1430
|
}))
|
|
951
1431
|
});
|
|
952
1432
|
var CloudConfigError = class extends Error {
|
|
@@ -978,6 +1458,7 @@ function validateAuthenticationConfig(config) {
|
|
|
978
1458
|
"appleKeyId",
|
|
979
1459
|
"applePrivateKey"
|
|
980
1460
|
]);
|
|
1461
|
+
requireTogether(config, "GitHub", ["githubClientId", "githubClientSecret"]);
|
|
981
1462
|
}
|
|
982
1463
|
function validateEmailConfig(config) {
|
|
983
1464
|
requireTogether(config, "SMTP", ["smtpHost", "smtpPort"]);
|
|
@@ -989,8 +1470,10 @@ function validateEmailConfig(config) {
|
|
|
989
1470
|
}
|
|
990
1471
|
function validateServiceConfig(config) {
|
|
991
1472
|
requireTogether(config, "Services", ["servicesEndpoint", "servicesSigningKey"]);
|
|
1473
|
+
if (config.billingEndpoint && !config.servicesSigningKey) throw new CloudConfigError("Billing needs the services signing key to sign its tokens");
|
|
1474
|
+
if (config.billingEndpoint && !config.internalServiceToken) throw new CloudConfigError("Billing needs the internal API to set the plans it sells");
|
|
992
1475
|
if (config.internalServiceToken && config.staticEntitlements) throw new CloudConfigError("The internal API writes database entitlements, which static entitlements would hide");
|
|
993
|
-
|
|
1476
|
+
for (const [name, endpoint] of [["services", config.servicesEndpoint], ["billing", config.billingEndpoint]]) if (endpoint && !sendsTokenSafely(endpoint)) throw new CloudConfigError(`The ${name} endpoint must use HTTPS, or HTTP only to 127.0.0.1 or [::1] for development`);
|
|
994
1477
|
}
|
|
995
1478
|
function validateLegalConfig(config) {
|
|
996
1479
|
const legal = config.legal;
|
|
@@ -1012,229 +1495,6 @@ function parseCloudServerConfig(input) {
|
|
|
1012
1495
|
validateLegalConfig(config);
|
|
1013
1496
|
return config;
|
|
1014
1497
|
}
|
|
1015
|
-
/** PostHog's EU Cloud ingestion host, where OpenPencil's own project is. */
|
|
1016
|
-
const POSTHOG_DEFAULT_HOST = "https://eu.i.posthog.com";
|
|
1017
|
-
const DEFAULT_SECRET_NAMES = {
|
|
1018
|
-
databaseURL: "DATABASE_URL",
|
|
1019
|
-
authSecret: "BETTER_AUTH_SECRET",
|
|
1020
|
-
googleClientId: "GOOGLE_CLIENT_ID",
|
|
1021
|
-
googleClientSecret: "GOOGLE_CLIENT_SECRET",
|
|
1022
|
-
applePrivateKey: "APPLE_PRIVATE_KEY",
|
|
1023
|
-
s3AccessKeyId: "S3_ACCESS_KEY_ID",
|
|
1024
|
-
s3SecretAccessKey: "S3_SECRET_ACCESS_KEY",
|
|
1025
|
-
s3SessionToken: "S3_SESSION_TOKEN",
|
|
1026
|
-
smtpUser: "OPENPENCIL_CLOUD_SMTP_USER",
|
|
1027
|
-
smtpPassword: "OPENPENCIL_CLOUD_SMTP_PASSWORD",
|
|
1028
|
-
turnstileSecretKey: "TURNSTILE_SECRET_KEY",
|
|
1029
|
-
servicesSigningKey: "OPENPENCIL_CLOUD_SERVICES_SIGNING_KEY",
|
|
1030
|
-
internalServiceToken: "OPENPENCIL_CLOUD_SERVICE_TOKEN",
|
|
1031
|
-
posthogProjectAPIKey: "POSTHOG_PROJECT_API_KEY"
|
|
1032
|
-
};
|
|
1033
|
-
const urlSchema = v.pipe(v.string(), v.url());
|
|
1034
|
-
const textSchema = v.pipe(v.string(), v.trim(), v.minLength(1));
|
|
1035
|
-
const positiveIntegerSchema = v.pipe(v.number(), v.integer(), v.minValue(1));
|
|
1036
|
-
const secretReferenceSchema = v.strictObject({ from_env: textSchema });
|
|
1037
|
-
const configurableTextSchema = v.union([textSchema, secretReferenceSchema]);
|
|
1038
|
-
const defaultReference = (name) => v.optional(secretReferenceSchema, { from_env: name });
|
|
1039
|
-
const providerSchema = v.strictObject({
|
|
1040
|
-
google: v.optional(v.strictObject({
|
|
1041
|
-
client_id: v.optional(configurableTextSchema, { from_env: DEFAULT_SECRET_NAMES.googleClientId }),
|
|
1042
|
-
client_secret: defaultReference(DEFAULT_SECRET_NAMES.googleClientSecret)
|
|
1043
|
-
})),
|
|
1044
|
-
apple: v.optional(v.strictObject({
|
|
1045
|
-
client_id: textSchema,
|
|
1046
|
-
team_id: textSchema,
|
|
1047
|
-
key_id: textSchema,
|
|
1048
|
-
private_key: defaultReference(DEFAULT_SECRET_NAMES.applePrivateKey),
|
|
1049
|
-
app_bundle_identifier: v.optional(textSchema)
|
|
1050
|
-
}))
|
|
1051
|
-
});
|
|
1052
|
-
const emailSchema = v.optional(v.variant("transport", [
|
|
1053
|
-
v.strictObject({ transport: v.literal("none") }),
|
|
1054
|
-
v.strictObject({
|
|
1055
|
-
transport: v.literal("smtp"),
|
|
1056
|
-
from: textSchema,
|
|
1057
|
-
smtp: v.strictObject({
|
|
1058
|
-
host: textSchema,
|
|
1059
|
-
port: positiveIntegerSchema,
|
|
1060
|
-
secure: v.optional(v.boolean()),
|
|
1061
|
-
user: v.optional(secretReferenceSchema, { from_env: DEFAULT_SECRET_NAMES.smtpUser }),
|
|
1062
|
-
password: v.optional(secretReferenceSchema, { from_env: DEFAULT_SECRET_NAMES.smtpPassword })
|
|
1063
|
-
})
|
|
1064
|
-
}),
|
|
1065
|
-
v.strictObject({
|
|
1066
|
-
transport: v.literal("cloudflare"),
|
|
1067
|
-
from: textSchema
|
|
1068
|
-
})
|
|
1069
|
-
]), { transport: "none" });
|
|
1070
|
-
/**
|
|
1071
|
-
* Every table is strict: a key the schema doesn't know, such as one renamed since, stops startup
|
|
1072
|
-
* instead of leaving its setting at a default the operator never chose.
|
|
1073
|
-
*/
|
|
1074
|
-
const cloudDeploymentConfigSchema = v.strictObject({
|
|
1075
|
-
schema_version: v.literal(2),
|
|
1076
|
-
deployment: v.strictObject({
|
|
1077
|
-
mode: v.picklist(["official", "self-hosted"]),
|
|
1078
|
-
public_url: urlSchema,
|
|
1079
|
-
indexing: v.optional(v.picklist(["allow", "deny"]), "deny"),
|
|
1080
|
-
trusted_origins: v.optional(v.array(urlSchema), []),
|
|
1081
|
-
local_editor: v.optional(v.boolean(), true),
|
|
1082
|
-
listing: v.optional(v.strictObject({ minimum_editor_version: cloudEditorVersionSchema }))
|
|
1083
|
-
}),
|
|
1084
|
-
database: v.optional(v.strictObject({ url: defaultReference(DEFAULT_SECRET_NAMES.databaseURL) }), { url: { from_env: DEFAULT_SECRET_NAMES.databaseURL } }),
|
|
1085
|
-
authentication: v.strictObject({
|
|
1086
|
-
secret: defaultReference(DEFAULT_SECRET_NAMES.authSecret),
|
|
1087
|
-
enrollment: v.optional(v.strictObject({
|
|
1088
|
-
mode: v.optional(v.picklist([
|
|
1089
|
-
"open",
|
|
1090
|
-
"approval",
|
|
1091
|
-
"closed"
|
|
1092
|
-
]), "open"),
|
|
1093
|
-
notification_emails: v.optional(v.array(v.pipe(v.string(), v.email())), [])
|
|
1094
|
-
}), {
|
|
1095
|
-
mode: "open",
|
|
1096
|
-
notification_emails: []
|
|
1097
|
-
}),
|
|
1098
|
-
email_password: v.optional(v.strictObject({
|
|
1099
|
-
enabled: v.optional(v.boolean(), false),
|
|
1100
|
-
sign_up: v.optional(v.boolean(), true),
|
|
1101
|
-
minimum_password_length: v.optional(v.pipe(v.number(), v.integer(), v.minValue(8), v.maxValue(128)), 8),
|
|
1102
|
-
maximum_password_length: v.optional(v.pipe(v.number(), v.integer(), v.minValue(15), v.maxValue(128)), 128),
|
|
1103
|
-
verification_link_lifetime_minutes: v.optional(positiveIntegerSchema, 60),
|
|
1104
|
-
password_reset_link_lifetime_minutes: v.optional(positiveIntegerSchema, 60),
|
|
1105
|
-
compromised_password_check: v.optional(v.boolean(), false)
|
|
1106
|
-
}), {
|
|
1107
|
-
enabled: false,
|
|
1108
|
-
sign_up: true,
|
|
1109
|
-
minimum_password_length: 8,
|
|
1110
|
-
maximum_password_length: 128,
|
|
1111
|
-
verification_link_lifetime_minutes: 60,
|
|
1112
|
-
password_reset_link_lifetime_minutes: 60,
|
|
1113
|
-
compromised_password_check: false
|
|
1114
|
-
}),
|
|
1115
|
-
mfa: v.optional(v.strictObject({
|
|
1116
|
-
required_for_admins: v.optional(v.boolean(), false),
|
|
1117
|
-
totp: v.optional(v.boolean(), false),
|
|
1118
|
-
recovery_codes: v.optional(v.boolean(), false),
|
|
1119
|
-
trusted_device_lifetime_days: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0)), 14)
|
|
1120
|
-
}), {
|
|
1121
|
-
required_for_admins: false,
|
|
1122
|
-
totp: false,
|
|
1123
|
-
recovery_codes: false,
|
|
1124
|
-
trusted_device_lifetime_days: 14
|
|
1125
|
-
}),
|
|
1126
|
-
passkeys: v.optional(v.strictObject({
|
|
1127
|
-
enabled: v.optional(v.boolean(), false),
|
|
1128
|
-
rp_name: v.optional(textSchema, "OpenPencil Cloud")
|
|
1129
|
-
}), {
|
|
1130
|
-
enabled: false,
|
|
1131
|
-
rp_name: "OpenPencil Cloud"
|
|
1132
|
-
}),
|
|
1133
|
-
captcha: v.optional(v.strictObject({
|
|
1134
|
-
provider: v.literal("cloudflare-turnstile"),
|
|
1135
|
-
site_key: textSchema,
|
|
1136
|
-
secret_key: defaultReference(DEFAULT_SECRET_NAMES.turnstileSecretKey),
|
|
1137
|
-
allowed_hostnames: v.optional(v.array(textSchema), [])
|
|
1138
|
-
})),
|
|
1139
|
-
trusted_proxies: v.optional(v.strictObject({
|
|
1140
|
-
headers: v.optional(v.array(textSchema), []),
|
|
1141
|
-
addresses: v.optional(v.array(textSchema), [])
|
|
1142
|
-
}), {
|
|
1143
|
-
headers: [],
|
|
1144
|
-
addresses: []
|
|
1145
|
-
}),
|
|
1146
|
-
providers: v.optional(providerSchema, {})
|
|
1147
|
-
}),
|
|
1148
|
-
object_storage: v.strictObject({
|
|
1149
|
-
endpoint: urlSchema,
|
|
1150
|
-
region: textSchema,
|
|
1151
|
-
bucket: textSchema,
|
|
1152
|
-
credentials: v.optional(v.strictObject({
|
|
1153
|
-
access_key_id: defaultReference(DEFAULT_SECRET_NAMES.s3AccessKeyId),
|
|
1154
|
-
secret_access_key: defaultReference(DEFAULT_SECRET_NAMES.s3SecretAccessKey),
|
|
1155
|
-
session_token: v.optional(secretReferenceSchema, { from_env: DEFAULT_SECRET_NAMES.s3SessionToken })
|
|
1156
|
-
}), {
|
|
1157
|
-
access_key_id: { from_env: DEFAULT_SECRET_NAMES.s3AccessKeyId },
|
|
1158
|
-
secret_access_key: { from_env: DEFAULT_SECRET_NAMES.s3SecretAccessKey }
|
|
1159
|
-
}),
|
|
1160
|
-
force_path_style: v.optional(v.boolean(), true),
|
|
1161
|
-
checksum_verification: v.optional(v.picklist(["native", "metadata"]), "native"),
|
|
1162
|
-
server_side_encryption: v.optional(v.picklist(["AES256", "aws:kms"])),
|
|
1163
|
-
kms_key_id: v.optional(textSchema),
|
|
1164
|
-
/**
|
|
1165
|
-
* Keeps each file cleanup deletes under this prefix, such as `deleted/`, so a database restored
|
|
1166
|
-
* to an earlier time still finds it; a lifecycle rule on the prefix expires them.
|
|
1167
|
-
*/
|
|
1168
|
-
deleted_prefix: v.optional(deletedPrefixSchema),
|
|
1169
|
-
maximum_upload_bytes: v.optional(positiveIntegerSchema)
|
|
1170
|
-
}),
|
|
1171
|
-
collaboration: v.optional(v.strictObject({
|
|
1172
|
-
relay_url: v.optional(urlSchema),
|
|
1173
|
-
maximum_message_bytes: v.optional(positiveIntegerSchema),
|
|
1174
|
-
maximum_connections_per_room: v.optional(positiveIntegerSchema)
|
|
1175
|
-
}), {}),
|
|
1176
|
-
documents: v.optional(v.strictObject({
|
|
1177
|
-
retention_days: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0)), 30),
|
|
1178
|
-
purge_grace_days: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0)), 7)
|
|
1179
|
-
}), {
|
|
1180
|
-
retention_days: 30,
|
|
1181
|
-
purge_grace_days: 7
|
|
1182
|
-
}),
|
|
1183
|
-
email: emailSchema,
|
|
1184
|
-
workers: v.optional(v.strictObject({
|
|
1185
|
-
email: v.optional(v.strictObject({
|
|
1186
|
-
batch_size: v.optional(positiveIntegerSchema, 50),
|
|
1187
|
-
interval_ms: v.optional(positiveIntegerSchema, 3e4),
|
|
1188
|
-
lease_ms: v.optional(positiveIntegerSchema, 3e5),
|
|
1189
|
-
maximum_attempts: v.optional(positiveIntegerSchema, 5)
|
|
1190
|
-
}), {
|
|
1191
|
-
batch_size: 50,
|
|
1192
|
-
interval_ms: 3e4,
|
|
1193
|
-
lease_ms: 3e5,
|
|
1194
|
-
maximum_attempts: 5
|
|
1195
|
-
}),
|
|
1196
|
-
cleanup: v.optional(v.strictObject({
|
|
1197
|
-
enabled: v.optional(v.boolean(), true),
|
|
1198
|
-
batch_size: v.optional(positiveIntegerSchema, 100),
|
|
1199
|
-
interval_ms: v.optional(positiveIntegerSchema, 6e4),
|
|
1200
|
-
lease_ms: v.optional(positiveIntegerSchema, 3e5)
|
|
1201
|
-
}), {
|
|
1202
|
-
enabled: true,
|
|
1203
|
-
batch_size: 100,
|
|
1204
|
-
interval_ms: 6e4,
|
|
1205
|
-
lease_ms: 3e5
|
|
1206
|
-
})
|
|
1207
|
-
})),
|
|
1208
|
-
entitlements: v.optional(v.variant("source", [v.strictObject({
|
|
1209
|
-
source: v.literal("static"),
|
|
1210
|
-
...staticEntitlementsTOMLSchema.entries
|
|
1211
|
-
}), v.strictObject({ source: v.literal("database") })])),
|
|
1212
|
-
services: v.optional(v.strictObject({
|
|
1213
|
-
endpoint: urlSchema,
|
|
1214
|
-
signing_key: defaultReference(DEFAULT_SECRET_NAMES.servicesSigningKey),
|
|
1215
|
-
token_lifetime_minutes: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(60)), 10)
|
|
1216
|
-
})),
|
|
1217
|
-
billing: v.optional(v.strictObject({ portal_url: urlSchema })),
|
|
1218
|
-
internal_api: v.optional(v.strictObject({ service_token: defaultReference(DEFAULT_SECRET_NAMES.internalServiceToken) })),
|
|
1219
|
-
/**
|
|
1220
|
-
* Optional: the operator's terms and privacy policy, linked at sign-up and in the portal, and
|
|
1221
|
-
* with `require_acceptance`, accepted once per `terms_version` before an account uses the server.
|
|
1222
|
-
*/
|
|
1223
|
-
legal: v.optional(v.strictObject({
|
|
1224
|
-
terms_url: v.optional(urlSchema),
|
|
1225
|
-
privacy_url: v.optional(urlSchema),
|
|
1226
|
-
terms_version: v.optional(textSchema),
|
|
1227
|
-
require_acceptance: v.optional(v.boolean(), false),
|
|
1228
|
-
abuse_email: v.optional(v.pipe(v.string(), v.email())),
|
|
1229
|
-
minimum_age: v.optional(v.pipe(v.number(), v.integer(), v.minValue(13), v.maxValue(21)))
|
|
1230
|
-
})),
|
|
1231
|
-
/** Optional: reports server errors to PostHog error tracking. Leave it out to send nothing. */
|
|
1232
|
-
error_tracking: v.optional(v.strictObject({
|
|
1233
|
-
provider: v.literal("posthog"),
|
|
1234
|
-
host: v.optional(urlSchema, POSTHOG_DEFAULT_HOST),
|
|
1235
|
-
project_api_key: v.optional(configurableTextSchema, { from_env: DEFAULT_SECRET_NAMES.posthogProjectAPIKey })
|
|
1236
|
-
}))
|
|
1237
|
-
});
|
|
1238
1498
|
//#endregion
|
|
1239
1499
|
//#region src/server/db/expressions.ts
|
|
1240
1500
|
const CURRENT_TIMESTAMP = sql`current_timestamp`;
|
|
@@ -1276,6 +1536,27 @@ function withInvitation(table, access) {
|
|
|
1276
1536
|
async function addChecks(database, checks) {
|
|
1277
1537
|
for (const [table, column, values] of checks) await database.schema.alterTable(table).addCheckConstraint(`${table}_${column}_check`, checkColumnIn(column, values)).execute();
|
|
1278
1538
|
}
|
|
1539
|
+
/**
|
|
1540
|
+
* Replaces the values a column may take, as `addChecks` named them. Widening them, as when a
|
|
1541
|
+
* release adds a kind the previous one never writes, adds the check `NOT VALID`: rows already
|
|
1542
|
+
* there passed the narrower one, so PostgreSQL skips scanning them while it holds the table, and
|
|
1543
|
+
* checks every row written from then on. Narrowing them, as a rollback does, checks every row.
|
|
1544
|
+
*/
|
|
1545
|
+
async function replaceChecks(database, change, checks) {
|
|
1546
|
+
for (const [table, column, values] of checks) {
|
|
1547
|
+
const name = `${table}_${column}_check`;
|
|
1548
|
+
await database.schema.alterTable(table).dropConstraint(name).execute();
|
|
1549
|
+
if (change === "narrow") {
|
|
1550
|
+
await addChecks(database, [[
|
|
1551
|
+
table,
|
|
1552
|
+
column,
|
|
1553
|
+
values
|
|
1554
|
+
]]);
|
|
1555
|
+
continue;
|
|
1556
|
+
}
|
|
1557
|
+
await sql`alter table ${sql.table(table)} add constraint ${sql.id(name)} check (${checkColumnIn(column, values)}) not valid`.execute(database);
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1279
1560
|
/** Lookups beyond primary keys and unique columns, as `[table, columns]`; `desc` sorts newest first. */
|
|
1280
1561
|
async function addIndexes(database, indexes) {
|
|
1281
1562
|
for (const [table, columns] of indexes) {
|
|
@@ -1290,11 +1571,11 @@ async function dropTables(database, tables) {
|
|
|
1290
1571
|
//#endregion
|
|
1291
1572
|
//#region src/server/db/migrations/001_accounts.ts
|
|
1292
1573
|
var _001_accounts_exports = /* @__PURE__ */ __exportAll({
|
|
1293
|
-
down: () => down$
|
|
1294
|
-
up: () => up$
|
|
1574
|
+
down: () => down$17,
|
|
1575
|
+
up: () => up$17
|
|
1295
1576
|
});
|
|
1296
1577
|
/** What Cloud keeps about an account beside Better Auth's tables: its plan, sign-ins, and picture. */
|
|
1297
|
-
const TABLES$
|
|
1578
|
+
const TABLES$6 = [
|
|
1298
1579
|
"auth_schema_version",
|
|
1299
1580
|
"account_entitlement",
|
|
1300
1581
|
"mfa_assurance",
|
|
@@ -1302,7 +1583,7 @@ const TABLES$5 = [
|
|
|
1302
1583
|
"user_picture",
|
|
1303
1584
|
"api_rate_limit"
|
|
1304
1585
|
];
|
|
1305
|
-
async function up$
|
|
1586
|
+
async function up$17(database) {
|
|
1306
1587
|
await database.schema.createTable("auth_schema_version").addColumn("id", "text", (column) => column.primaryKey()).addColumn("version", "text", required).addColumn("updated_at", "timestamptz", now).execute();
|
|
1307
1588
|
await database.schema.createTable("account_entitlement").addColumn("user_id", "text", (column) => column.primaryKey()).addColumn("values", "jsonb", required).addColumn("source", "text", required).addColumn("revision", "integer", (column) => column.notNull().defaultTo(1)).addColumn("external_version", "bigint").addColumn("updated_at", "timestamptz", now).execute();
|
|
1308
1589
|
await database.schema.createTable("mfa_assurance").addColumn("session_id", "uuid", (column) => column.primaryKey()).addColumn("user_id", "uuid", required).addColumn("method", "text", required).addColumn("verified_at", "timestamptz", required).execute();
|
|
@@ -1320,22 +1601,22 @@ async function up$7(database) {
|
|
|
1320
1601
|
]]);
|
|
1321
1602
|
await addIndexes(database, [["sign_in", ["user_id", "created_at"]], ["sign_in", ["session_id"]]]);
|
|
1322
1603
|
}
|
|
1323
|
-
async function down$
|
|
1324
|
-
await dropTables(database, TABLES$
|
|
1604
|
+
async function down$17(database) {
|
|
1605
|
+
await dropTables(database, TABLES$6);
|
|
1325
1606
|
}
|
|
1326
1607
|
//#endregion
|
|
1327
1608
|
//#region src/server/db/migrations/002_workspaces.ts
|
|
1328
1609
|
var _002_workspaces_exports = /* @__PURE__ */ __exportAll({
|
|
1329
|
-
down: () => down$
|
|
1330
|
-
up: () => up$
|
|
1610
|
+
down: () => down$16,
|
|
1611
|
+
up: () => up$16
|
|
1331
1612
|
});
|
|
1332
1613
|
/** Workspaces, their members, and the people invited to join. */
|
|
1333
|
-
const TABLES$
|
|
1614
|
+
const TABLES$5 = [
|
|
1334
1615
|
"workspace",
|
|
1335
1616
|
"workspace_member",
|
|
1336
1617
|
"workspace_invitation"
|
|
1337
1618
|
];
|
|
1338
|
-
async function up$
|
|
1619
|
+
async function up$16(database) {
|
|
1339
1620
|
await database.schema.createTable("workspace").addColumn("id", "uuid", (column) => column.primaryKey()).addColumn("name", "text", required).addColumn("slug", "text", (column) => column.notNull().unique()).addColumn("created_by", "text", required).addColumn("owner_id", "text", required).addColumn("created_at", "timestamptz", now).addColumn("updated_at", "timestamptz", now).execute();
|
|
1340
1621
|
await database.schema.createTable("workspace_member").addColumn("workspace_id", "uuid", (column) => column.notNull().references("workspace.id").onDelete("cascade")).addColumn("user_id", "text", required).addColumn("role", "text", required).addColumn("created_at", "timestamptz", now).addPrimaryKeyConstraint("workspace_member_pkey", ["workspace_id", "user_id"]).execute();
|
|
1341
1622
|
await withInvitation(database.schema.createTable("workspace_invitation"), "role").addColumn("workspace_id", "uuid", (column) => column.notNull().references("workspace.id").onDelete("cascade")).execute();
|
|
@@ -1354,37 +1635,37 @@ async function up$6(database) {
|
|
|
1354
1635
|
["workspace_invitation", ["workspace_id", "revoked_at"]]
|
|
1355
1636
|
]);
|
|
1356
1637
|
}
|
|
1357
|
-
async function down$
|
|
1358
|
-
await dropTables(database, TABLES$
|
|
1638
|
+
async function down$16(database) {
|
|
1639
|
+
await dropTables(database, TABLES$5);
|
|
1359
1640
|
}
|
|
1360
1641
|
//#endregion
|
|
1361
1642
|
//#region src/server/db/migrations/003_storage.ts
|
|
1362
1643
|
var _003_storage_exports = /* @__PURE__ */ __exportAll({
|
|
1363
|
-
down: () => down$
|
|
1364
|
-
up: () => up$
|
|
1644
|
+
down: () => down$15,
|
|
1645
|
+
up: () => up$15
|
|
1365
1646
|
});
|
|
1366
1647
|
/** Files in the object store, a workspace's images among them, and how much each workspace uses. */
|
|
1367
|
-
const TABLES$
|
|
1648
|
+
const TABLES$4 = [
|
|
1368
1649
|
"storage_object",
|
|
1369
1650
|
"workspace_storage_usage",
|
|
1370
1651
|
"workspace_image"
|
|
1371
1652
|
];
|
|
1372
|
-
async function up$
|
|
1653
|
+
async function up$15(database) {
|
|
1373
1654
|
await database.schema.createTable("storage_object").addColumn("id", "uuid", (column) => column.primaryKey()).addColumn("object_key", "text", (column) => column.notNull().unique()).addColumn("checksum", "text", required).addColumn("byte_size", "bigint", required).addColumn("content_type", "text", required).addColumn("created_at", "timestamptz", now).execute();
|
|
1374
1655
|
await database.schema.createTable("workspace_storage_usage").addColumn("workspace_id", "uuid", (column) => column.primaryKey().references("workspace.id").onDelete("cascade")).addColumn("committed_bytes", "bigint", (column) => column.notNull().defaultTo(0)).addColumn("updated_at", "timestamptz", now).execute();
|
|
1375
1656
|
await database.schema.createTable("workspace_image").addColumn("workspace_id", "uuid", (column) => column.notNull().references("workspace.id").onDelete("cascade")).addColumn("checksum", "text", required).addColumn("storage_object_id", "uuid", (column) => column.notNull().unique().references("storage_object.id")).addColumn("touched_at", "timestamptz", now).addPrimaryKeyConstraint("workspace_image_pkey", ["workspace_id", "checksum"]).execute();
|
|
1376
1657
|
}
|
|
1377
|
-
async function down$
|
|
1378
|
-
await dropTables(database, TABLES$
|
|
1658
|
+
async function down$15(database) {
|
|
1659
|
+
await dropTables(database, TABLES$4);
|
|
1379
1660
|
}
|
|
1380
1661
|
//#endregion
|
|
1381
1662
|
//#region src/server/db/migrations/004_documents.ts
|
|
1382
1663
|
var _004_documents_exports = /* @__PURE__ */ __exportAll({
|
|
1383
|
-
down: () => down$
|
|
1384
|
-
up: () => up$
|
|
1664
|
+
down: () => down$14,
|
|
1665
|
+
up: () => up$14
|
|
1385
1666
|
});
|
|
1386
1667
|
/** Documents and what they hold: revisions, versions, images, collaboration rooms, and uploads. */
|
|
1387
|
-
const TABLES$
|
|
1668
|
+
const TABLES$3 = [
|
|
1388
1669
|
"document",
|
|
1389
1670
|
"document_revision",
|
|
1390
1671
|
"document_version",
|
|
@@ -1413,7 +1694,7 @@ async function createUploads(database) {
|
|
|
1413
1694
|
await database.schema.createTable("upload").addColumn("id", "uuid", (column) => column.primaryKey()).addColumn("document_id", "uuid", (column) => column.notNull().references("document.id").onDelete("cascade")).addColumn("kind", "text", (column) => column.notNull().defaultTo("revision")).addColumn("base_revision_id", "uuid", (column) => column.references("document_revision.id").onDelete("set null")).addColumn("object_key", "text", (column) => column.notNull().unique()).addColumn("status", "text", required).addColumn("checksum", "text", required).addColumn("byte_size", "bigint", required).addColumn("content_type", "text", required).addColumn("multipart_upload_id", "text").addColumn("created_by", "text", required).addColumn("created_at", "timestamptz", now).addColumn("expires_at", "timestamptz", required).addColumn("finalization_started_at", "timestamptz").addColumn("cleanup_claim_id", "uuid").addColumn("cleanup_claimed_at", "timestamptz").execute();
|
|
1414
1695
|
await database.schema.createTable("upload_storage_reservation").addColumn("id", "uuid", (column) => column.primaryKey()).addColumn("workspace_id", "uuid", (column) => column.notNull().references("workspace.id").onDelete("cascade")).addColumn("upload_id", "uuid", (column) => column.notNull().unique().references("upload.id").onDelete("cascade")).addColumn("bytes", "bigint", required).addColumn("created_at", "timestamptz", now).addColumn("expires_at", "timestamptz", required).addColumn("committed_at", "timestamptz").addColumn("released_at", "timestamptz").execute();
|
|
1415
1696
|
}
|
|
1416
|
-
async function up$
|
|
1697
|
+
async function up$14(database) {
|
|
1417
1698
|
await createRevisions(database);
|
|
1418
1699
|
await createRooms(database);
|
|
1419
1700
|
await createUploads(database);
|
|
@@ -1458,24 +1739,24 @@ async function up$4(database) {
|
|
|
1458
1739
|
["upload", ["status", "expires_at"]]
|
|
1459
1740
|
]);
|
|
1460
1741
|
}
|
|
1461
|
-
async function down$
|
|
1462
|
-
await dropTables(database, TABLES$
|
|
1742
|
+
async function down$14(database) {
|
|
1743
|
+
await dropTables(database, TABLES$3);
|
|
1463
1744
|
}
|
|
1464
1745
|
//#endregion
|
|
1465
1746
|
//#region src/server/db/migrations/005_sharing.ts
|
|
1466
1747
|
var _005_sharing_exports = /* @__PURE__ */ __exportAll({
|
|
1467
|
-
down: () => down$
|
|
1468
|
-
up: () => up$
|
|
1748
|
+
down: () => down$13,
|
|
1749
|
+
up: () => up$13
|
|
1469
1750
|
});
|
|
1470
1751
|
/** Who a document is shared with: people, invitations, links, and the invitations budget. */
|
|
1471
|
-
const TABLES$
|
|
1752
|
+
const TABLES$2 = [
|
|
1472
1753
|
"document_grant",
|
|
1473
1754
|
"document_invitation",
|
|
1474
1755
|
"invitation_continuation",
|
|
1475
1756
|
"document_share",
|
|
1476
1757
|
"invitation_send"
|
|
1477
1758
|
];
|
|
1478
|
-
async function up$
|
|
1759
|
+
async function up$13(database) {
|
|
1479
1760
|
await database.schema.createTable("document_grant").addColumn("id", "uuid", (column) => column.primaryKey()).addColumn("document_id", "uuid", (column) => column.notNull().references("document.id").onDelete("cascade")).addColumn("user_id", "text", required).addColumn("permission", "text", required).addColumn("created_by", "text", required).addColumn("created_at", "timestamptz", now).addColumn("updated_at", "timestamptz", now).addColumn("revoked_at", "timestamptz").addUniqueConstraint("document_grant_document_id_user_id_key", ["document_id", "user_id"]).execute();
|
|
1480
1761
|
await withInvitation(database.schema.createTable("document_invitation"), "permission").addColumn("document_id", "uuid", (column) => column.notNull().references("document.id").onDelete("cascade")).execute();
|
|
1481
1762
|
await database.schema.createTable("invitation_continuation").addColumn("id", "text", (column) => column.primaryKey()).addColumn("invitation_id", "uuid", (column) => column.notNull().references("document_invitation.id").onDelete("cascade")).addColumn("token_encrypted", "text", required).addColumn("created_at", "timestamptz", now).addColumn("expires_at", "timestamptz", required).addColumn("consumed_at", "timestamptz").execute();
|
|
@@ -1507,23 +1788,23 @@ async function up$3(database) {
|
|
|
1507
1788
|
["invitation_send", ["email_normalized", "sent_at"]]
|
|
1508
1789
|
]);
|
|
1509
1790
|
}
|
|
1510
|
-
async function down$
|
|
1511
|
-
await dropTables(database, TABLES$
|
|
1791
|
+
async function down$13(database) {
|
|
1792
|
+
await dropTables(database, TABLES$2);
|
|
1512
1793
|
}
|
|
1513
1794
|
//#endregion
|
|
1514
1795
|
//#region src/server/db/migrations/006_operations.ts
|
|
1515
1796
|
var _006_operations_exports = /* @__PURE__ */ __exportAll({
|
|
1516
|
-
down: () => down$
|
|
1517
|
-
up: () => up$
|
|
1797
|
+
down: () => down$12,
|
|
1798
|
+
up: () => up$12
|
|
1518
1799
|
});
|
|
1519
1800
|
/** Running the deployment: the email outbox, enrollment, reports, and the administrators' log. */
|
|
1520
|
-
const TABLES = [
|
|
1801
|
+
const TABLES$1 = [
|
|
1521
1802
|
"transactional_email",
|
|
1522
1803
|
"enrollment",
|
|
1523
1804
|
"document_report",
|
|
1524
1805
|
"admin_audit_event"
|
|
1525
1806
|
];
|
|
1526
|
-
async function up$
|
|
1807
|
+
async function up$12(database) {
|
|
1527
1808
|
await database.schema.createTable("transactional_email").addColumn("id", "uuid", (column) => column.primaryKey()).addColumn("idempotency_key", "text", (column) => column.notNull().unique()).addColumn("kind", "text", required).addColumn("recipient_email_normalized", "text", required).addColumn("payload_encrypted", "text").addColumn("status", "text", (column) => column.notNull().defaultTo("pending")).addColumn("attempt_count", "integer", (column) => column.notNull().defaultTo(0)).addColumn("next_attempt_at", "timestamptz", now).addColumn("claim_id", "uuid").addColumn("claimed_at", "timestamptz").addColumn("transport", "text").addColumn("transport_message_id", "text").addColumn("last_error_code", "text").addColumn("created_at", "timestamptz", now).addColumn("updated_at", "timestamptz", now).addColumn("accepted_at", "timestamptz").execute();
|
|
1528
1809
|
await database.schema.createTable("enrollment").addColumn("id", "uuid", (column) => column.primaryKey()).addColumn("email_normalized", "text", (column) => column.notNull().unique()).addColumn("name", "text").addColumn("reason", "text").addColumn("status", "text", (column) => column.notNull().defaultTo("pending")).addColumn("request_revision", "integer", (column) => column.notNull().defaultTo(1)).addColumn("requested_at", "timestamptz", now).addColumn("reviewed_at", "timestamptz").addColumn("reviewed_by", "text").addColumn("review_note", "text").addColumn("approved_user_id", "text").execute();
|
|
1529
1810
|
await database.schema.createTable("document_report").addColumn("id", "uuid", (column) => column.primaryKey()).addColumn("document_id", "uuid", (column) => column.notNull().references("document.id").onDelete("cascade")).addColumn("share_id", "uuid").addColumn("reporter_user_id", "text").addColumn("reporter_guest_id", "text").addColumn("reply_email", "text").addColumn("reason", "text", required).addColumn("description", "text", required).addColumn("status", "text", (column) => column.notNull().defaultTo("open")).addColumn("created_at", "timestamptz", now).addColumn("resolved_at", "timestamptz").addColumn("resolved_by", "text").execute();
|
|
@@ -1600,24 +1881,24 @@ async function up$2(database) {
|
|
|
1600
1881
|
["admin_audit_event", ["created_at"]]
|
|
1601
1882
|
]);
|
|
1602
1883
|
}
|
|
1603
|
-
async function down$
|
|
1604
|
-
await dropTables(database, TABLES);
|
|
1884
|
+
async function down$12(database) {
|
|
1885
|
+
await dropTables(database, TABLES$1);
|
|
1605
1886
|
}
|
|
1606
1887
|
//#endregion
|
|
1607
1888
|
//#region src/server/db/migrations/007_trash.ts
|
|
1608
1889
|
var _007_trash_exports = /* @__PURE__ */ __exportAll({
|
|
1609
|
-
down: () => down$
|
|
1610
|
-
up: () => up$
|
|
1890
|
+
down: () => down$11,
|
|
1891
|
+
up: () => up$11
|
|
1611
1892
|
});
|
|
1612
1893
|
/**
|
|
1613
1894
|
* Trash: who deleted a document, and who deleted it forever, when, and the storage that took off
|
|
1614
1895
|
* its workspace's usage while its files wait out the grace before cleanup destroys them.
|
|
1615
1896
|
*/
|
|
1616
|
-
async function up$
|
|
1897
|
+
async function up$11(database) {
|
|
1617
1898
|
await database.schema.alterTable("document").addColumn("deleted_by", "text").addColumn("purged_at", "timestamptz").addColumn("purged_by", "text").addColumn("purged_bytes", "bigint", (column) => column.notNull().defaultTo(0)).execute();
|
|
1618
1899
|
await addIndexes(database, [["document", ["workspace_id", "deleted_at desc"]], ["document", ["purged_at"]]]);
|
|
1619
1900
|
}
|
|
1620
|
-
async function down$
|
|
1901
|
+
async function down$11(database) {
|
|
1621
1902
|
await database.schema.dropIndex("document_purged_at_idx").execute();
|
|
1622
1903
|
await database.schema.dropIndex("document_workspace_id_deleted_at_idx").execute();
|
|
1623
1904
|
await database.schema.alterTable("document").dropColumn("purged_bytes").dropColumn("purged_by").dropColumn("purged_at").dropColumn("deleted_by").execute();
|
|
@@ -1625,15 +1906,342 @@ async function down$1(database) {
|
|
|
1625
1906
|
//#endregion
|
|
1626
1907
|
//#region src/server/db/migrations/008_terms.ts
|
|
1627
1908
|
var _008_terms_exports = /* @__PURE__ */ __exportAll({
|
|
1909
|
+
down: () => down$10,
|
|
1910
|
+
up: () => up$10
|
|
1911
|
+
});
|
|
1912
|
+
/** Which version of the deployment's terms each account accepted, and when. */
|
|
1913
|
+
async function up$10(database) {
|
|
1914
|
+
await database.schema.createTable("terms_acceptance").addColumn("user_id", "text", required).addColumn("version", "text", required).addColumn("accepted_at", "timestamptz", now).addPrimaryKeyConstraint("terms_acceptance_pkey", ["user_id", "version"]).execute();
|
|
1915
|
+
}
|
|
1916
|
+
async function down$10(database) {
|
|
1917
|
+
await database.schema.dropTable("terms_acceptance").execute();
|
|
1918
|
+
}
|
|
1919
|
+
//#endregion
|
|
1920
|
+
//#region src/server/db/migrations/009_access_tokens.ts
|
|
1921
|
+
var _009_access_tokens_exports = /* @__PURE__ */ __exportAll({
|
|
1922
|
+
down: () => down$9,
|
|
1923
|
+
up: () => up$9
|
|
1924
|
+
});
|
|
1925
|
+
/**
|
|
1926
|
+
* Personal access tokens, kept by Better Auth's API-key plugin in the table it would build
|
|
1927
|
+
* itself. Cloud builds it here instead, since Better Auth's tables are built only once and a
|
|
1928
|
+
* deployment that has them gains this one as any other migration; Better Auth's migration then
|
|
1929
|
+
* leaves this plugin's table out (`createBetterAuthAdapter`). It holds each token's SHA-256
|
|
1930
|
+
* digest, never the token.
|
|
1931
|
+
*/
|
|
1932
|
+
async function up$9(database) {
|
|
1933
|
+
await database.schema.createTable("apikey").addColumn("id", "uuid", (column) => column.primaryKey().defaultTo(sql`gen_random_uuid()`)).addColumn("config_id", "text", required).addColumn("name", "text").addColumn("start", "text").addColumn("reference_id", "text", required).addColumn("prefix", "text").addColumn("key", "text", required).addColumn("refill_interval", "integer").addColumn("refill_amount", "integer").addColumn("last_refill_at", "timestamptz").addColumn("enabled", "boolean").addColumn("rate_limit_enabled", "boolean").addColumn("rate_limit_time_window", "integer").addColumn("rate_limit_max", "integer").addColumn("request_count", "integer").addColumn("remaining", "integer").addColumn("last_request", "timestamptz").addColumn("expires_at", "timestamptz").addColumn("created_at", "timestamptz", required).addColumn("updated_at", "timestamptz", required).addColumn("permissions", "text").addColumn("metadata", "text").execute();
|
|
1934
|
+
await addIndexes(database, [
|
|
1935
|
+
["apikey", ["config_id"]],
|
|
1936
|
+
["apikey", ["reference_id"]],
|
|
1937
|
+
["apikey", ["key"]]
|
|
1938
|
+
]);
|
|
1939
|
+
}
|
|
1940
|
+
async function down$9(database) {
|
|
1941
|
+
await database.schema.dropTable("apikey").execute();
|
|
1942
|
+
}
|
|
1943
|
+
//#endregion
|
|
1944
|
+
//#region src/server/db/migrations/010_storage_limit_notices.ts
|
|
1945
|
+
var _010_storage_limit_notices_exports = /* @__PURE__ */ __exportAll({
|
|
1946
|
+
down: () => down$8,
|
|
1947
|
+
up: () => up$8
|
|
1948
|
+
});
|
|
1949
|
+
/** Every kind of transactional email, as of this migration. */
|
|
1950
|
+
const EMAIL_KINDS$1 = [
|
|
1951
|
+
"document-invitation",
|
|
1952
|
+
"workspace-invitation",
|
|
1953
|
+
"enrollment-requested",
|
|
1954
|
+
"admin-enrollment-notification",
|
|
1955
|
+
"enrollment-approved",
|
|
1956
|
+
"enrollment-rejected",
|
|
1957
|
+
"enrollment-revoked",
|
|
1958
|
+
"email-verification",
|
|
1959
|
+
"password-reset",
|
|
1960
|
+
"password-changed",
|
|
1961
|
+
"email-change-requested",
|
|
1962
|
+
"new-sign-in",
|
|
1963
|
+
"two-step-changed",
|
|
1964
|
+
"document-report"
|
|
1965
|
+
];
|
|
1966
|
+
/**
|
|
1967
|
+
* The accounts told their storage is full, so each is told once each time it fills, not on every
|
|
1968
|
+
* cleanup pass; a row goes once the account holds less than its plan allows again. Email gains
|
|
1969
|
+
* the kind that tells them, which the previous release never writes.
|
|
1970
|
+
*/
|
|
1971
|
+
async function up$8(database) {
|
|
1972
|
+
await database.schema.createTable("storage_limit_notice").addColumn("user_id", "text", (column) => column.primaryKey()).addColumn("notified_at", "timestamptz", now).execute();
|
|
1973
|
+
await database.schema.alterTable("transactional_email").dropConstraint("transactional_email_kind_check").execute();
|
|
1974
|
+
await addChecks(database, [[
|
|
1975
|
+
"transactional_email",
|
|
1976
|
+
"kind",
|
|
1977
|
+
[...EMAIL_KINDS$1, "storage-limit-reached"]
|
|
1978
|
+
]]);
|
|
1979
|
+
}
|
|
1980
|
+
async function down$8(database) {
|
|
1981
|
+
await database.schema.alterTable("transactional_email").dropConstraint("transactional_email_kind_check").execute();
|
|
1982
|
+
await addChecks(database, [[
|
|
1983
|
+
"transactional_email",
|
|
1984
|
+
"kind",
|
|
1985
|
+
EMAIL_KINDS$1
|
|
1986
|
+
]]);
|
|
1987
|
+
await database.schema.dropTable("storage_limit_notice").execute();
|
|
1988
|
+
}
|
|
1989
|
+
//#endregion
|
|
1990
|
+
//#region src/server/db/migrations/011_account_ids.ts
|
|
1991
|
+
var _011_account_ids_exports = /* @__PURE__ */ __exportAll({
|
|
1992
|
+
contracts: () => contracts,
|
|
1993
|
+
down: () => down$7,
|
|
1994
|
+
up: () => up$7
|
|
1995
|
+
});
|
|
1996
|
+
/** The tables that named accounts by `uuid`, unlike every other table Cloud builds. */
|
|
1997
|
+
const TABLES = [
|
|
1998
|
+
"mfa_assurance",
|
|
1999
|
+
"sign_in",
|
|
2000
|
+
"user_picture"
|
|
2001
|
+
];
|
|
2002
|
+
/**
|
|
2003
|
+
* Names accounts by `text` in the last tables that used `uuid`, as `schema.ts` sets for every
|
|
2004
|
+
* table Cloud builds. The previous release reads and writes the same strings either way, so it
|
|
2005
|
+
* keeps working while this runs.
|
|
2006
|
+
*/
|
|
2007
|
+
const contracts = TABLES.map((table) => `${table}.user_id`);
|
|
2008
|
+
async function up$7(database) {
|
|
2009
|
+
for (const table of TABLES) await database.schema.alterTable(table).alterColumn("user_id", (column) => column.setDataType("text")).execute();
|
|
2010
|
+
}
|
|
2011
|
+
async function down$7(database) {
|
|
2012
|
+
for (const table of TABLES) await database.schema.alterTable(table).alterColumn("user_id", (column) => column.setDataType(sql`uuid using user_id::uuid`)).execute();
|
|
2013
|
+
}
|
|
2014
|
+
//#endregion
|
|
2015
|
+
//#region src/server/db/migrations/012_email_locales.ts
|
|
2016
|
+
var _012_email_locales_exports = /* @__PURE__ */ __exportAll({
|
|
2017
|
+
down: () => down$6,
|
|
2018
|
+
up: () => up$6
|
|
2019
|
+
});
|
|
2020
|
+
/** Whether Better Auth's `user` table exists yet, which it doesn't before a server first starts. */
|
|
2021
|
+
async function hasUserTable(database) {
|
|
2022
|
+
return (await database.introspection.getTables()).some((table) => table.name === "user");
|
|
2023
|
+
}
|
|
2024
|
+
/**
|
|
2025
|
+
* The language Cloud writes to each account in, and the one each queued email is written in,
|
|
2026
|
+
* settled when it's queued so a retry reads the same. Email from before this migration is
|
|
2027
|
+
* English, as it always was.
|
|
2028
|
+
*
|
|
2029
|
+
* `user.locale` is a Better Auth field, so a new database gets it from Better Auth's own schema,
|
|
2030
|
+
* built after Cloud's migrations. A database that already has that schema never builds it again,
|
|
2031
|
+
* so it gets the column here; accounts from before it have no language and read English.
|
|
2032
|
+
*/
|
|
2033
|
+
async function up$6(database) {
|
|
2034
|
+
await database.schema.alterTable("transactional_email").addColumn("locale", "text", (column) => column.notNull().defaultTo("en")).execute();
|
|
2035
|
+
if (await hasUserTable(database)) await database.schema.alterTable("user").addColumn("locale", "text", (column) => column.ifNotExists()).execute();
|
|
2036
|
+
}
|
|
2037
|
+
async function down$6(database) {
|
|
2038
|
+
await database.schema.alterTable("transactional_email").dropColumn("locale").execute();
|
|
2039
|
+
}
|
|
2040
|
+
//#endregion
|
|
2041
|
+
//#region src/server/db/migrations/013_document_block_emails.ts
|
|
2042
|
+
var _013_document_block_emails_exports = /* @__PURE__ */ __exportAll({
|
|
2043
|
+
DOCUMENT_BLOCK_EMAIL_KINDS: () => DOCUMENT_BLOCK_EMAIL_KINDS,
|
|
2044
|
+
down: () => down$5,
|
|
2045
|
+
up: () => up$5
|
|
2046
|
+
});
|
|
2047
|
+
/** Every kind of transactional email before this migration. */
|
|
2048
|
+
const EMAIL_KINDS = [
|
|
2049
|
+
"document-invitation",
|
|
2050
|
+
"workspace-invitation",
|
|
2051
|
+
"enrollment-requested",
|
|
2052
|
+
"admin-enrollment-notification",
|
|
2053
|
+
"enrollment-approved",
|
|
2054
|
+
"enrollment-rejected",
|
|
2055
|
+
"enrollment-revoked",
|
|
2056
|
+
"email-verification",
|
|
2057
|
+
"password-reset",
|
|
2058
|
+
"password-changed",
|
|
2059
|
+
"email-change-requested",
|
|
2060
|
+
"new-sign-in",
|
|
2061
|
+
"two-step-changed",
|
|
2062
|
+
"document-report",
|
|
2063
|
+
"storage-limit-reached"
|
|
2064
|
+
];
|
|
2065
|
+
/** Every kind of transactional email once this migration has run. */
|
|
2066
|
+
const DOCUMENT_BLOCK_EMAIL_KINDS = [
|
|
2067
|
+
...EMAIL_KINDS,
|
|
2068
|
+
"document-blocked",
|
|
2069
|
+
"document-restored"
|
|
2070
|
+
];
|
|
2071
|
+
/**
|
|
2072
|
+
* Email gains the kinds that tell a workspace's owner an administrator blocked one of its
|
|
2073
|
+
* documents, and that it is back, which the previous release never writes.
|
|
2074
|
+
*/
|
|
2075
|
+
async function up$5(database) {
|
|
2076
|
+
await replaceChecks(database, "widen", [[
|
|
2077
|
+
"transactional_email",
|
|
2078
|
+
"kind",
|
|
2079
|
+
DOCUMENT_BLOCK_EMAIL_KINDS
|
|
2080
|
+
]]);
|
|
2081
|
+
}
|
|
2082
|
+
async function down$5(database) {
|
|
2083
|
+
await replaceChecks(database, "narrow", [[
|
|
2084
|
+
"transactional_email",
|
|
2085
|
+
"kind",
|
|
2086
|
+
EMAIL_KINDS
|
|
2087
|
+
]]);
|
|
2088
|
+
}
|
|
2089
|
+
//#endregion
|
|
2090
|
+
//#region src/server/db/migrations/014_report_replies.ts
|
|
2091
|
+
var _014_report_replies_exports = /* @__PURE__ */ __exportAll({
|
|
2092
|
+
down: () => down$4,
|
|
2093
|
+
up: () => up$4
|
|
2094
|
+
});
|
|
2095
|
+
/**
|
|
2096
|
+
* Whoever reports a document and leaves an address hears that the report arrived and what the
|
|
2097
|
+
* administrators decided. A report keeps the language its reporter's browser asked for, since a
|
|
2098
|
+
* guest has no account to say it, and email gains the two kinds, which the previous release
|
|
2099
|
+
* never writes.
|
|
2100
|
+
*/
|
|
2101
|
+
async function up$4(database) {
|
|
2102
|
+
await database.schema.alterTable("document_report").addColumn("reply_locale", "text").execute();
|
|
2103
|
+
await replaceChecks(database, "widen", [[
|
|
2104
|
+
"transactional_email",
|
|
2105
|
+
"kind",
|
|
2106
|
+
[
|
|
2107
|
+
...DOCUMENT_BLOCK_EMAIL_KINDS,
|
|
2108
|
+
"document-report-received",
|
|
2109
|
+
"document-report-decided"
|
|
2110
|
+
]
|
|
2111
|
+
]]);
|
|
2112
|
+
}
|
|
2113
|
+
async function down$4(database) {
|
|
2114
|
+
await replaceChecks(database, "narrow", [[
|
|
2115
|
+
"transactional_email",
|
|
2116
|
+
"kind",
|
|
2117
|
+
DOCUMENT_BLOCK_EMAIL_KINDS
|
|
2118
|
+
]]);
|
|
2119
|
+
await database.schema.alterTable("document_report").dropColumn("reply_locale").execute();
|
|
2120
|
+
}
|
|
2121
|
+
//#endregion
|
|
2122
|
+
//#region src/server/db/migrations/015_comments.ts
|
|
2123
|
+
var _015_comments_exports = /* @__PURE__ */ __exportAll({
|
|
2124
|
+
down: () => down$3,
|
|
2125
|
+
up: () => up$3
|
|
2126
|
+
});
|
|
2127
|
+
/**
|
|
2128
|
+
* Comments on a Cloud document belong to the server, not to the file: each one keeps who wrote
|
|
2129
|
+
* it as an account, can be deleted for good, and is open to people who may only view. A thread
|
|
2130
|
+
* is the pin and whether it is resolved; its comments are its first message and the replies.
|
|
2131
|
+
*/
|
|
2132
|
+
async function up$3(database) {
|
|
2133
|
+
await database.schema.createTable("comment_thread").addColumn("id", "uuid", (column) => column.primaryKey()).addColumn("document_id", "uuid", (column) => column.notNull().references("document.id").onDelete("cascade")).addColumn("page_id", "text", required).addColumn("page_name", "text").addColumn("node_id", "text").addColumn("node_name", "text").addColumn("offset_x", "double precision").addColumn("offset_y", "double precision").addColumn("x", "double precision", required).addColumn("y", "double precision", required).addColumn("created_by", "text", required).addColumn("created_at", "timestamptz", now).addColumn("updated_at", "timestamptz", now).addColumn("resolved_at", "timestamptz").addColumn("resolved_by", "text").execute();
|
|
2134
|
+
await database.schema.createTable("comment").addColumn("id", "uuid", (column) => column.primaryKey()).addColumn("thread_id", "uuid", (column) => column.notNull().references("comment_thread.id").onDelete("cascade")).addColumn("author_id", "text").addColumn("imported_author_name", "text").addColumn("agent", "text").addColumn("body", "text", required).addColumn("created_at", "timestamptz", now).addColumn("edited_at", "timestamptz").execute();
|
|
2135
|
+
await addIndexes(database, [
|
|
2136
|
+
["comment_thread", ["document_id", "created_at"]],
|
|
2137
|
+
["comment", ["thread_id", "created_at"]],
|
|
2138
|
+
["comment", ["author_id"]]
|
|
2139
|
+
]);
|
|
2140
|
+
}
|
|
2141
|
+
async function down$3(database) {
|
|
2142
|
+
await dropTables(database, ["comment_thread", "comment"]);
|
|
2143
|
+
}
|
|
2144
|
+
//#endregion
|
|
2145
|
+
//#region src/server/db/migrations/016_comment_notifications.ts
|
|
2146
|
+
var _016_comment_notifications_exports = /* @__PURE__ */ __exportAll({
|
|
2147
|
+
COMMENT_EMAIL_KINDS: () => COMMENT_EMAIL_KINDS,
|
|
2148
|
+
COMMENT_EMAIL_SETTINGS: () => COMMENT_EMAIL_SETTINGS,
|
|
2149
|
+
down: () => down$2,
|
|
2150
|
+
up: () => up$2
|
|
2151
|
+
});
|
|
2152
|
+
/** The kinds `014_report_replies` left email with. */
|
|
2153
|
+
const REPORT_REPLY_EMAIL_KINDS = [
|
|
2154
|
+
...DOCUMENT_BLOCK_EMAIL_KINDS,
|
|
2155
|
+
"document-report-received",
|
|
2156
|
+
"document-report-decided"
|
|
2157
|
+
];
|
|
2158
|
+
const COMMENT_EMAIL_SETTINGS = [
|
|
2159
|
+
"all",
|
|
2160
|
+
"mentions",
|
|
2161
|
+
"off"
|
|
2162
|
+
];
|
|
2163
|
+
/** Every kind of transactional email once this migration has run. */
|
|
2164
|
+
const COMMENT_EMAIL_KINDS = [...REPORT_REPLY_EMAIL_KINDS, "comment-notification"];
|
|
2165
|
+
/**
|
|
2166
|
+
* Who a comment names, who has read a thread up to when, and which comments each account hears
|
|
2167
|
+
* about by email: everything in threads it takes part in, only what names it, or nothing. Email
|
|
2168
|
+
* gains the kind that tells someone, which the previous release never writes.
|
|
2169
|
+
*/
|
|
2170
|
+
async function up$2(database) {
|
|
2171
|
+
await database.schema.createTable("comment_mention").addColumn("comment_id", "uuid", (column) => column.notNull().references("comment.id").onDelete("cascade")).addColumn("user_id", "text", required).addColumn("created_at", "timestamptz", now).addPrimaryKeyConstraint("comment_mention_pkey", ["comment_id", "user_id"]).execute();
|
|
2172
|
+
await database.schema.createTable("comment_read").addColumn("user_id", "text", required).addColumn("thread_id", "uuid", (column) => column.notNull().references("comment_thread.id").onDelete("cascade")).addColumn("read_at", "timestamptz", now).addPrimaryKeyConstraint("comment_read_pkey", ["user_id", "thread_id"]).execute();
|
|
2173
|
+
await database.schema.createTable("comment_email").addColumn("id", "uuid", (column) => column.primaryKey()).addColumn("sender_id", "text", required).addColumn("recipient_id", "text", required).addColumn("sent_at", "timestamptz", now).execute();
|
|
2174
|
+
await database.schema.createTable("notification_setting").addColumn("user_id", "text", (column) => column.primaryKey()).addColumn("comment_emails", "text", required).addColumn("updated_at", "timestamptz", now).execute();
|
|
2175
|
+
await addChecks(database, [[
|
|
2176
|
+
"notification_setting",
|
|
2177
|
+
"comment_emails",
|
|
2178
|
+
COMMENT_EMAIL_SETTINGS
|
|
2179
|
+
]]);
|
|
2180
|
+
await addIndexes(database, [
|
|
2181
|
+
["comment_mention", ["user_id"]],
|
|
2182
|
+
["comment_read", ["thread_id"]],
|
|
2183
|
+
["comment_email", ["sender_id", "sent_at"]],
|
|
2184
|
+
["comment_email", ["recipient_id", "sent_at"]]
|
|
2185
|
+
]);
|
|
2186
|
+
await replaceChecks(database, "widen", [[
|
|
2187
|
+
"transactional_email",
|
|
2188
|
+
"kind",
|
|
2189
|
+
COMMENT_EMAIL_KINDS
|
|
2190
|
+
]]);
|
|
2191
|
+
}
|
|
2192
|
+
async function down$2(database) {
|
|
2193
|
+
await replaceChecks(database, "narrow", [[
|
|
2194
|
+
"transactional_email",
|
|
2195
|
+
"kind",
|
|
2196
|
+
REPORT_REPLY_EMAIL_KINDS
|
|
2197
|
+
]]);
|
|
2198
|
+
await dropTables(database, [
|
|
2199
|
+
"comment_mention",
|
|
2200
|
+
"comment_read",
|
|
2201
|
+
"comment_email",
|
|
2202
|
+
"notification_setting"
|
|
2203
|
+
]);
|
|
2204
|
+
}
|
|
2205
|
+
//#endregion
|
|
2206
|
+
//#region src/server/db/migrations/017_invitation_emails.ts
|
|
2207
|
+
var _017_invitation_emails_exports = /* @__PURE__ */ __exportAll({
|
|
2208
|
+
down: () => down$1,
|
|
2209
|
+
up: () => up$1
|
|
2210
|
+
});
|
|
2211
|
+
/**
|
|
2212
|
+
* Email gains the official deployment's invitation letter, which approves a waiting request with a
|
|
2213
|
+
* note from the founder instead of the plain approval; the previous release never writes it.
|
|
2214
|
+
*/
|
|
2215
|
+
async function up$1(database) {
|
|
2216
|
+
await replaceChecks(database, "widen", [[
|
|
2217
|
+
"transactional_email",
|
|
2218
|
+
"kind",
|
|
2219
|
+
[...COMMENT_EMAIL_KINDS, "enrollment-invited"]
|
|
2220
|
+
]]);
|
|
2221
|
+
}
|
|
2222
|
+
async function down$1(database) {
|
|
2223
|
+
await replaceChecks(database, "narrow", [[
|
|
2224
|
+
"transactional_email",
|
|
2225
|
+
"kind",
|
|
2226
|
+
COMMENT_EMAIL_KINDS
|
|
2227
|
+
]]);
|
|
2228
|
+
}
|
|
2229
|
+
//#endregion
|
|
2230
|
+
//#region src/server/db/migrations/018_enrollment_source.ts
|
|
2231
|
+
var _018_enrollment_source_exports = /* @__PURE__ */ __exportAll({
|
|
1628
2232
|
down: () => down,
|
|
1629
2233
|
up: () => up
|
|
1630
2234
|
});
|
|
1631
|
-
/**
|
|
2235
|
+
/**
|
|
2236
|
+
* Where an access request came from: null when the person asked on this server, `waitlist` when an
|
|
2237
|
+
* administrator recorded someone from openpencil.dev's waitlist, whose approval with the invitation
|
|
2238
|
+
* letter thanks them for joining the waitlist rather than for asking. Earlier requests asked here.
|
|
2239
|
+
*/
|
|
1632
2240
|
async function up(database) {
|
|
1633
|
-
await database.schema.
|
|
2241
|
+
await database.schema.alterTable("enrollment").addColumn("source", "text", (column) => column.check(sql`source in ('waitlist')`)).execute();
|
|
1634
2242
|
}
|
|
1635
2243
|
async function down(database) {
|
|
1636
|
-
await database.schema.
|
|
2244
|
+
await database.schema.alterTable("enrollment").dropColumn("source").execute();
|
|
1637
2245
|
}
|
|
1638
2246
|
//#endregion
|
|
1639
2247
|
//#region src/server/db/migrate.ts
|
|
@@ -1645,7 +2253,17 @@ const migrations = {
|
|
|
1645
2253
|
"005_sharing": _005_sharing_exports,
|
|
1646
2254
|
"006_operations": _006_operations_exports,
|
|
1647
2255
|
"007_trash": _007_trash_exports,
|
|
1648
|
-
"008_terms": _008_terms_exports
|
|
2256
|
+
"008_terms": _008_terms_exports,
|
|
2257
|
+
"009_access_tokens": _009_access_tokens_exports,
|
|
2258
|
+
"010_storage_limit_notices": _010_storage_limit_notices_exports,
|
|
2259
|
+
"011_account_ids": _011_account_ids_exports,
|
|
2260
|
+
"012_email_locales": _012_email_locales_exports,
|
|
2261
|
+
"013_document_block_emails": _013_document_block_emails_exports,
|
|
2262
|
+
"014_report_replies": _014_report_replies_exports,
|
|
2263
|
+
"015_comments": _015_comments_exports,
|
|
2264
|
+
"016_comment_notifications": _016_comment_notifications_exports,
|
|
2265
|
+
"017_invitation_emails": _017_invitation_emails_exports,
|
|
2266
|
+
"018_enrollment_source": _018_enrollment_source_exports
|
|
1649
2267
|
};
|
|
1650
2268
|
/** Cloud's migrations, in order. */
|
|
1651
2269
|
var CloudMigrationProvider = class {
|
|
@@ -1713,6 +2331,6 @@ async function listen(fetch, port, hostname) {
|
|
|
1713
2331
|
};
|
|
1714
2332
|
}
|
|
1715
2333
|
//#endregion
|
|
1716
|
-
export { CLOUD_API_MAX_BODY_BYTES, CLOUD_DISCOVERY_PATH, CLOUD_PROTOCOL_MAX_UPLOAD_BYTES, CLOUD_SERVICES_API_PATHS, CLOUD_SERVICES_JWKS_PATH, CLOUD_SERVICES_TOKEN_AUDIENCE, COLLAB_ACTIONS, CURRENT_TIMESTAMP, CloudConfigError, MAX_COLLAB_MESSAGE_BYTES, RELAY_CLOSE, RELAY_DOCUMENT_PARAM, RELAY_HEARTBEAT, RELAY_PATH, RELAY_SERVER_PEER, SERVICE_ERROR_STATUS, __exportAll, accountParams,
|
|
2334
|
+
export { CLOUD_ACCESS_TOKEN_PREFIX, CLOUD_ACCOUNT_PLAN_PATH, CLOUD_API_MAX_BODY_BYTES, CLOUD_BILLING_API_PATHS, CLOUD_BILLING_TOKEN_AUDIENCE, CLOUD_DISCOVERY_PATH, CLOUD_EDITOR_VERSION_HEADER, CLOUD_PICTURE_MAX_BYTES, CLOUD_PROTOCOL_MAX_UPLOAD_BYTES, CLOUD_SERVICES_API_PATHS, CLOUD_SERVICES_JWKS_PATH, CLOUD_SERVICES_TOKEN_AUDIENCE, CLOUD_SOCIAL_PROVIDERS, CLOUD_SOCIAL_PROVIDER_NAMES, COLLAB_ACTIONS, CURRENT_TIMESTAMP, CloudConfigError, MAX_COLLAB_MESSAGE_BYTES, RELAY_CLOSE, RELAY_DOCUMENT_PARAM, RELAY_HEARTBEAT, RELAY_PATH, RELAY_SERVER_PEER, SERVICE_ERROR_STATUS, __exportAll, accountParams, cloudAccessTokenCreateSchema, cloudAccessTokenRevokeSchema, cloudAccountDeleteSchema, cloudAccountSessionSchema, cloudEditorVersionSchema, cloudEmailChangeSchema, cloudIdentitySchema, cloudMFAEnableSchema, cloudMFAVerifySchema, cloudPasskeyDeleteSchema, cloudPasswordChangeSchema, cloudPersonSchema, cloudPictureUploadSchema, cloudProfileUpdateSchema, cloudSessionRevokeSchema, cloudSignInSchema, cloudSocialLinkSchema, cloudTermsAcceptanceSchema, cloudUnlinkAuthenticationMethodSchema, commitImageUploadsSchema, commitUploadSchema, createDocumentSchema, createRelayClientAssembler, createServicesTokenSchema, createUploadSchema, decodeRelayClientFrame, decodeRoomUpdate, defaultRelayURL, deletedPrefixSchema, documentCommentParams, documentDownloadSchema, documentInvitationParams, documentKindSchema, documentParams, documentPermissionSchema, documentRevisionParams, documentShareParams, documentSummarySchema, documentThreadParams, documentUserParams, documentVersionParams, encodeSyncReply, httpURLSchema, idParams, invitationContinuationParams, invitationParams, isEditorVersionAtLeast, isKnownAuthenticationProvider, isKnownSocialProvider, listen, lockForTransaction, migrateCloudDatabase, migrateToLatest, parseCloudDiscovery, parseCloudServerConfig, pictureParams, presenceName, relayServerMessages, requestImageLinksSchema, requestImageUploadsSchema, serviceCatalogSchema, servicesTokenClaimsSchema, shareCommentParams, shareParams, shareThreadParams, staticEntitlementsSchema, staticEntitlementsTOMLSchema, uploadParams, usageQuerySchema, validatedJSON, validatedQuery, workspaceInvitationParams, workspaceMemberParams, workspaceParams };
|
|
1717
2335
|
|
|
1718
2336
|
//# sourceMappingURL=listen.mjs.map
|