@open-pencil/cloud 0.17.0-beta.5 → 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/dist/client.d.ts +560 -93
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1101 -186
- package/dist/client.js.map +1 -1
- package/dist/contract.d.ts +2 -2
- package/dist/contract.js +2 -2
- package/dist/contract2.js +390 -44
- package/dist/contract2.js.map +1 -1
- package/dist/email.d.ts +366 -3
- package/dist/email.d.ts.map +1 -1
- package/dist/email.js +1403 -556
- package/dist/email.js.map +1 -1
- package/dist/errors.js +16 -3
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +878 -37
- package/dist/index.d.ts.map +1 -1
- package/dist/index2.d.ts +12 -2
- package/dist/index2.d.ts.map +1 -1
- package/dist/listen.mjs +589 -128
- package/dist/listen.mjs.map +1 -1
- package/dist/runtime-cloudflare.d.ts +4 -0
- package/dist/runtime-cloudflare.d.ts.map +1 -1
- package/dist/runtime-cloudflare.js +8689 -6324
- package/dist/runtime-cloudflare.js.map +1 -1
- package/dist/runtime-node.d.mts +10098 -5401
- package/dist/runtime-node.d.mts.map +1 -1
- package/dist/server.d.ts +14078 -7909
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +11723 -9412
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +10658 -8649
- package/dist/server.mjs.map +1 -1
- package/dist/server2.mjs +79 -57
- package/dist/server2.mjs.map +1 -1
- package/package.json +13 -4
- package/src/admin/api/routes.ts +263 -190
- package/src/admin/audit/service.ts +9 -1
- package/src/admin/bootstrap.ts +86 -0
- package/src/admin/documents/service.ts +119 -4
- 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 +9 -3
- package/src/admin/schema.ts +6 -5
- package/src/admin/users/service.ts +173 -16
- package/src/client/api.ts +29 -2
- package/src/client/comments.ts +205 -0
- package/src/client/device-authorization.ts +4 -20
- package/src/client/discovery.ts +4 -2
- 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 +3 -6
- package/src/client/portal/account.ts +20 -2
- package/src/client/portal/administration.ts +52 -5
- package/src/client/portal/request.ts +4 -2
- package/src/client/tour.ts +44 -0
- package/src/client/versions.ts +7 -1
- package/src/contract/account.ts +61 -11
- package/src/contract/admin/index.ts +48 -3
- package/src/contract/billing.ts +73 -4
- package/src/contract/comments.ts +223 -0
- package/src/contract/discovery.ts +47 -19
- package/src/contract/index.ts +10 -0
- package/src/contract/links.ts +5 -0
- package/src/contract/relay.ts +3 -1
- package/src/contract/services.ts +44 -4
- package/src/contract/workspaces.ts +5 -0
- package/src/email/locales/ar.json +28 -0
- package/src/email/locales/de.json +28 -0
- package/src/email/locales/es.json +28 -0
- package/src/email/locales/fr.json +28 -0
- package/src/email/locales/it.json +28 -0
- package/src/email/locales/ja.json +28 -0
- package/src/email/locales/pl.json +28 -0
- package/src/email/locales/pt-br.json +28 -0
- package/src/email/locales/ru.json +28 -0
- package/src/email/locales/zh-cn.json +28 -0
- package/src/email/messages.ts +35 -0
- package/src/email/render.ts +18 -0
- package/src/email/samples.ts +28 -1
- package/src/email/schema.ts +29 -3
- package/src/email/templates/BrandEmail.vue +3 -1
- package/src/email/templates/CommentNotification.vue +39 -0
- package/src/email/templates/EnrollmentInvitation.vue +53 -0
- package/src/email/templates/TwoStepChanged.vue +17 -2
- package/src/email/templates/brand.ts +6 -0
- package/src/errors/posthog.ts +28 -4
- package/src/runtime/cloudflare/email.ts +2 -0
- package/src/runtime/cloudflare/relay/index.ts +21 -6
- package/src/runtime/cloudflare/worker.ts +6 -0
- package/src/runtime/cloudflare/xml.ts +12 -0
- package/src/runtime/node/admin.ts +51 -47
- package/src/runtime/node/email/runtime.ts +1 -0
- package/src/runtime/node/email/transport.ts +1 -0
- package/src/runtime/node/server.ts +8 -2
- package/src/runtime/posthog/errors.ts +3 -1
- package/src/server/account/actions.ts +3 -1
- package/src/server/account/deletion.ts +38 -4
- package/src/server/account/routes.ts +67 -46
- package/src/server/account/tokens.ts +3 -3
- package/src/server/api/router.ts +22 -7
- package/src/server/app/checks.ts +6 -1
- package/src/server/app/cors.ts +44 -0
- package/src/server/app/index.ts +76 -76
- package/src/server/app/routes.ts +14 -5
- package/src/server/app/services.ts +49 -15
- package/src/server/auth/access-control.ts +13 -8
- package/src/server/auth/account.ts +13 -12
- package/src/server/auth/activity.ts +7 -2
- package/src/server/auth/adapter.ts +16 -3
- package/src/server/auth/email.ts +29 -17
- package/src/server/auth/endpoints.ts +4 -0
- package/src/server/auth/factory.ts +83 -64
- package/src/server/auth/index.ts +1 -1
- package/src/server/auth/methods.ts +162 -0
- package/src/server/auth/mfa-assurance.ts +147 -10
- package/src/server/auth/rate-limit.ts +31 -0
- package/src/server/auth/runtime.ts +19 -5
- package/src/server/auth/social-providers.ts +70 -24
- package/src/server/billing/index.ts +2 -0
- package/src/server/billing/notify.ts +55 -0
- package/src/server/billing/seats.ts +17 -0
- package/src/server/billing/tokens.ts +1 -1
- 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/collaboration/relay/connection.ts +7 -2
- package/src/server/collaboration/relay/hub.ts +55 -24
- package/src/server/collaboration/routes.ts +8 -5
- 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/routes.ts +6 -6
- package/src/server/config/deployment.ts +19 -6
- package/src/server/config/index.ts +1 -1
- package/src/server/config/public.ts +19 -6
- package/src/server/config/schema.ts +14 -2
- package/src/server/config/toml/schema.ts +27 -4
- package/src/server/db/index.ts +2 -1
- package/src/server/db/migrate.ts +21 -1
- 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/tables.ts +92 -2
- package/src/server/documents/access.ts +17 -0
- package/src/server/documents/images.ts +6 -1
- package/src/server/documents/routes.ts +12 -12
- package/src/server/documents/service.ts +19 -5
- package/src/server/documents/summary.ts +15 -0
- package/src/server/documents/versions/routes.ts +7 -8
- package/src/server/documents/versions/service.ts +5 -2
- package/src/server/email/service.ts +8 -2
- package/src/server/email/types.ts +1 -0
- package/src/server/errors/index.ts +48 -3
- package/src/server/index.ts +15 -1
- 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/pictures/service.ts +3 -1
- package/src/server/policy/workspace.ts +5 -2
- package/src/server/reports/routes.ts +2 -2
- package/src/server/reports/service.ts +3 -1
- package/src/server/services/routes.ts +2 -2
- package/src/server/sharing/capabilities/service.ts +1 -1
- package/src/server/sharing/document-routes.ts +3 -3
- package/src/server/sharing/invitations/service.ts +3 -4
- package/src/server/sharing/routes.ts +15 -15
- package/src/server/validation.ts +33 -25
- package/src/server/workspaces/members.ts +50 -12
- package/src/server/workspaces/repository.ts +23 -12
- package/src/server/workspaces/routes.ts +8 -8
- package/src/services/app.ts +30 -19
- package/src/services/config.ts +47 -8
- package/src/services/metering.ts +15 -27
- package/src/client/billing.ts +0 -80
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. */
|
|
@@ -42,9 +281,6 @@ const cloudServicesDiscoverySchema = v.object({
|
|
|
42
281
|
contractVersion: v.literal("1")
|
|
43
282
|
});
|
|
44
283
|
const createServicesTokenSchema = v.object({ workspaceId: v.pipe(v.string(), v.uuid()) });
|
|
45
|
-
function parseCreateServicesToken(input) {
|
|
46
|
-
return v.parse(createServicesTokenSchema, input);
|
|
47
|
-
}
|
|
48
284
|
v.object({
|
|
49
285
|
token: v.pipe(v.string(), v.minLength(1)),
|
|
50
286
|
expiresAt: v.pipe(v.string(), v.isoTimestamp())
|
|
@@ -80,11 +316,38 @@ const chatModelSchema = v.object({
|
|
|
80
316
|
});
|
|
81
317
|
/** What one web search costs; a service without search leaves it out of its catalog. */
|
|
82
318
|
const searchPricingSchema = v.object({ creditsPerRequest: creditsSchema$1 });
|
|
83
|
-
const
|
|
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({
|
|
84
333
|
models: v.array(chatModelSchema),
|
|
85
|
-
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),
|
|
86
341
|
search: v.optional(searchPricingSchema)
|
|
87
|
-
})
|
|
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"));
|
|
88
351
|
const creditBucketSchema = v.object({
|
|
89
352
|
kind: v.picklist([
|
|
90
353
|
"allowance",
|
|
@@ -126,9 +389,6 @@ const searchResultSchema = v.object({
|
|
|
126
389
|
});
|
|
127
390
|
v.object({ results: v.array(searchResultSchema) });
|
|
128
391
|
const usageQuerySchema = v.object({ cursor: v.optional(v.pipe(v.string(), v.minLength(1))) });
|
|
129
|
-
function parseUsageQuery(input) {
|
|
130
|
-
return v.parse(usageQuerySchema, input);
|
|
131
|
-
}
|
|
132
392
|
v.object({
|
|
133
393
|
entries: v.array(usageEntrySchema),
|
|
134
394
|
next: v.nullable(v.string())
|
|
@@ -178,14 +438,40 @@ const CLOUD_BILLING_TOKEN_AUDIENCE = "openpencil-billing";
|
|
|
178
438
|
* and manages what they pay for; editors link to it whenever the server advertises billing.
|
|
179
439
|
*/
|
|
180
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
|
+
};
|
|
181
454
|
const urlSchema = v.pipe(v.string(), v.url());
|
|
182
455
|
const idSchema = v.pipe(v.string(), v.regex(/^[a-z0-9][a-z0-9-]{0,62}$/));
|
|
183
456
|
const centsSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
184
457
|
const bytesSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
185
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
|
+
});
|
|
186
471
|
const cloudBillingDiscoverySchema = v.object({
|
|
187
472
|
endpoint: urlSchema,
|
|
188
|
-
contractVersion: v.literal("1")
|
|
473
|
+
contractVersion: v.literal("1"),
|
|
474
|
+
freePlan: v.optional(billingFreePlanSchema)
|
|
189
475
|
});
|
|
190
476
|
v.object({
|
|
191
477
|
token: v.pipe(v.string(), v.minLength(1)),
|
|
@@ -201,13 +487,34 @@ v.object({
|
|
|
201
487
|
iat: v.pipe(v.number(), v.integer()),
|
|
202
488
|
exp: v.pipe(v.number(), v.integer())
|
|
203
489
|
});
|
|
204
|
-
|
|
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
|
+
*/
|
|
205
511
|
const billingPlanSchema = v.object({
|
|
206
512
|
id: idSchema,
|
|
207
513
|
name: v.pipe(v.string(), v.minLength(1)),
|
|
208
514
|
monthlyPriceCents: centsSchema,
|
|
209
515
|
storageBytes: bytesSchema,
|
|
210
|
-
monthlyCredits: creditsSchema
|
|
516
|
+
monthlyCredits: creditsSchema,
|
|
517
|
+
seats: v.optional(billingSeatPricingSchema)
|
|
211
518
|
});
|
|
212
519
|
/** Credits an account on a plan buys once, in US dollars before tax. */
|
|
213
520
|
const creditPackSchema = v.object({
|
|
@@ -411,24 +718,6 @@ const commitImageUploadsSchema = v.object({ uploads: v.pipe(v.array(v.object({
|
|
|
411
718
|
checksum: checksumSchema,
|
|
412
719
|
multipart: commitUploadSchema.entries.multipart
|
|
413
720
|
})), v.minLength(1), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)) });
|
|
414
|
-
function parseCreateDocument(input) {
|
|
415
|
-
return v.parse(createDocumentSchema, input);
|
|
416
|
-
}
|
|
417
|
-
function parseCreateUpload(input) {
|
|
418
|
-
return v.parse(createUploadSchema, input);
|
|
419
|
-
}
|
|
420
|
-
function parseRequestImageUploads(input) {
|
|
421
|
-
return v.parse(requestImageUploadsSchema, input);
|
|
422
|
-
}
|
|
423
|
-
function parseCommitImageUploads(input) {
|
|
424
|
-
return v.parse(commitImageUploadsSchema, input);
|
|
425
|
-
}
|
|
426
|
-
function parseRequestImageLinks(input) {
|
|
427
|
-
return v.parse(requestImageLinksSchema, input);
|
|
428
|
-
}
|
|
429
|
-
function parseCommitUpload(input) {
|
|
430
|
-
return v.parse(commitUploadSchema, input);
|
|
431
|
-
}
|
|
432
721
|
//#endregion
|
|
433
722
|
//#region src/contract/relay.ts
|
|
434
723
|
/** Where the relay accepts WebSocket upgrades, under the Cloud API origin. */
|
|
@@ -456,7 +745,9 @@ const COLLAB_ACTIONS = {
|
|
|
456
745
|
agentPreview: "agent-preview",
|
|
457
746
|
upload: "upload",
|
|
458
747
|
/** From the server only: the document's version history changed, so open lists load it again. */
|
|
459
|
-
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"
|
|
460
751
|
};
|
|
461
752
|
/**
|
|
462
753
|
* The most a room message may decode to, compressed or not. A peer's update past it is dropped
|
|
@@ -703,6 +994,11 @@ function decodeRelayClientFrame(data) {
|
|
|
703
994
|
}
|
|
704
995
|
const CLOUD_DISCOVERY_PATH = "/.well-known/openpencil";
|
|
705
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)));
|
|
706
1002
|
const cloudAuthenticationSchema = v.object({
|
|
707
1003
|
emailPassword: v.optional(v.object({
|
|
708
1004
|
signIn: v.boolean(),
|
|
@@ -713,7 +1009,7 @@ const cloudAuthenticationSchema = v.object({
|
|
|
713
1009
|
siteKey: v.pipe(v.string(), v.trim(), v.minLength(1))
|
|
714
1010
|
}))
|
|
715
1011
|
})),
|
|
716
|
-
socialProviders:
|
|
1012
|
+
socialProviders: socialProvidersSchema,
|
|
717
1013
|
enterpriseSSO: v.boolean(),
|
|
718
1014
|
enrollmentMode: v.optional(v.picklist([
|
|
719
1015
|
"open",
|
|
@@ -732,31 +1028,40 @@ const cloudCapabilitiesSchema = v.object({
|
|
|
732
1028
|
workspaces: v.boolean(),
|
|
733
1029
|
collaboration: v.boolean()
|
|
734
1030
|
});
|
|
735
|
-
/**
|
|
736
|
-
|
|
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
|
+
}
|
|
737
1049
|
/**
|
|
738
1050
|
* The header desktop editors send with each request, naming their version, so a server can refuse
|
|
739
1051
|
* an editor older than its `minimumEditorVersion`. Browser editors leave it out: the server serves
|
|
740
1052
|
* them, and an older server's CORS rules would refuse a header they don't list.
|
|
741
1053
|
*/
|
|
742
1054
|
const CLOUD_EDITOR_VERSION_HEADER = "X-OpenPencil-Editor-Version";
|
|
743
|
-
function editorVersionParts(version) {
|
|
744
|
-
const match = /^(\d+)\.(\d+)\.(\d+)/.exec(version);
|
|
745
|
-
return match ? match.slice(1).map(Number) : null;
|
|
746
|
-
}
|
|
747
1055
|
/**
|
|
748
|
-
* Whether `version` is `minimum` or later,
|
|
749
|
-
*
|
|
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.
|
|
750
1061
|
*/
|
|
751
1062
|
function isEditorVersionAtLeast(version, minimum) {
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
if (!have || !need) return false;
|
|
755
|
-
for (let index = 0; index < need.length; index++) {
|
|
756
|
-
const difference = (have[index] ?? 0) - (need[index] ?? 0);
|
|
757
|
-
if (difference !== 0) return difference > 0;
|
|
758
|
-
}
|
|
759
|
-
return true;
|
|
1063
|
+
if (!isSemVer(version) || !isSemVer(minimum)) return false;
|
|
1064
|
+
return compareVersions(version, minimum) >= 0;
|
|
760
1065
|
}
|
|
761
1066
|
/**
|
|
762
1067
|
* Whether editors offer this server to everyone, and from which editor version on. Only the
|
|
@@ -792,8 +1097,12 @@ const cloudBrandingSchema = v.object({
|
|
|
792
1097
|
/**
|
|
793
1098
|
* The server's community gallery: the workspace whose documents anyone may open read-only.
|
|
794
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.
|
|
795
1101
|
*/
|
|
796
|
-
const cloudCommunityDiscoverySchema = v.object({
|
|
1102
|
+
const cloudCommunityDiscoverySchema = v.object({
|
|
1103
|
+
workspaceId: v.pipe(v.string(), v.uuid()),
|
|
1104
|
+
tourDocumentId: v.optional(v.pipe(v.string(), v.uuid()))
|
|
1105
|
+
});
|
|
797
1106
|
const cloudDiscoverySchema = v.object({
|
|
798
1107
|
protocolVersion: v.literal("1"),
|
|
799
1108
|
deployment: cloudDeploymentSchema,
|
|
@@ -823,21 +1132,18 @@ function parseCloudDiscovery(input) {
|
|
|
823
1132
|
}
|
|
824
1133
|
//#endregion
|
|
825
1134
|
//#region src/server/validation.ts
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
}
|
|
835
|
-
function validatedJSON(parse) {
|
|
836
|
-
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));
|
|
837
1143
|
}
|
|
838
1144
|
/** Query string counterpart of `validatedJSON`. */
|
|
839
|
-
function validatedQuery(
|
|
840
|
-
return
|
|
1145
|
+
function validatedQuery(schema) {
|
|
1146
|
+
return sValidator("query", schema, (result, context) => result.success ? void 0 : context.json(invalidRequest, 400));
|
|
841
1147
|
}
|
|
842
1148
|
/**
|
|
843
1149
|
* A route parameter that names a row by UUID, in lowercase: the database matches any case, but an
|
|
@@ -850,10 +1156,7 @@ const uuidParamSchema = v.pipe(v.string(), v.uuid(), v.toLowerCase());
|
|
|
850
1156
|
* value never reaches the database.
|
|
851
1157
|
*/
|
|
852
1158
|
function validatedParams(schema) {
|
|
853
|
-
return
|
|
854
|
-
const parsed = v.safeParse(schema, value);
|
|
855
|
-
return parsed.success ? parsed.output : context.json({ error: { code: "not_found" } }, 404);
|
|
856
|
-
});
|
|
1159
|
+
return sValidator("param", schema, (result, context) => result.success ? void 0 : context.json({ error: { code: "not_found" } }, 404));
|
|
857
1160
|
}
|
|
858
1161
|
/** A route parameter the server takes as text, such as a user ID, which is not a UUID column. */
|
|
859
1162
|
const textParamSchema = v.pipe(v.string(), v.minLength(1));
|
|
@@ -862,6 +1165,15 @@ const documentVersionParams = validatedParams(v.object({
|
|
|
862
1165
|
documentId: uuidParamSchema,
|
|
863
1166
|
versionId: uuidParamSchema
|
|
864
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
|
+
}));
|
|
865
1177
|
const documentShareParams = validatedParams(v.object({
|
|
866
1178
|
documentId: uuidParamSchema,
|
|
867
1179
|
shareId: uuidParamSchema
|
|
@@ -885,7 +1197,17 @@ const workspaceMemberParams = validatedParams(v.object({
|
|
|
885
1197
|
}));
|
|
886
1198
|
const accountParams = validatedParams(v.object({ userId: uuidParamSchema }));
|
|
887
1199
|
const shareParams = validatedParams(v.object({ shareId: uuidParamSchema }));
|
|
888
|
-
const
|
|
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({
|
|
889
1211
|
documentId: uuidParamSchema,
|
|
890
1212
|
revisionId: uuidParamSchema
|
|
891
1213
|
}));
|
|
@@ -1020,6 +1342,8 @@ const rawCloudServerConfigSchema = v.object({
|
|
|
1020
1342
|
appleTeamId: optionalTextSchema,
|
|
1021
1343
|
appleKeyId: optionalTextSchema,
|
|
1022
1344
|
applePrivateKey: optionalTextSchema,
|
|
1345
|
+
githubClientId: optionalTextSchema,
|
|
1346
|
+
githubClientSecret: optionalTextSchema,
|
|
1023
1347
|
appleAppBundleIdentifier: optionalTextSchema,
|
|
1024
1348
|
s3Endpoint: httpURLSchema,
|
|
1025
1349
|
s3Region: v.pipe(v.string(), v.trim(), v.minLength(1)),
|
|
@@ -1039,6 +1363,7 @@ const rawCloudServerConfigSchema = v.object({
|
|
|
1039
1363
|
smtpUser: optionalTextSchema,
|
|
1040
1364
|
smtpPassword: optionalTextSchema,
|
|
1041
1365
|
emailFrom: optionalTextSchema,
|
|
1366
|
+
emailReplyTo: v.optional(v.pipe(v.string(), v.email())),
|
|
1042
1367
|
emailTransport: v.optional(v.picklist([
|
|
1043
1368
|
"none",
|
|
1044
1369
|
"smtp",
|
|
@@ -1084,7 +1409,11 @@ const rawCloudServerConfigSchema = v.object({
|
|
|
1084
1409
|
* The workspace whose documents anyone may open read-only, without signing in or a link: the
|
|
1085
1410
|
* deployment's community gallery. Without it the server has none.
|
|
1086
1411
|
*/
|
|
1087
|
-
community: v.optional(v.object({
|
|
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
|
+
})),
|
|
1088
1417
|
/** How a self-hosted server names itself on its public pages. */
|
|
1089
1418
|
branding: v.optional(v.object({
|
|
1090
1419
|
name: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(80))),
|
|
@@ -1095,7 +1424,9 @@ const rawCloudServerConfigSchema = v.object({
|
|
|
1095
1424
|
errorTracking: v.optional(v.object({
|
|
1096
1425
|
provider: v.literal("posthog"),
|
|
1097
1426
|
host: httpURLSchema,
|
|
1098
|
-
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)
|
|
1099
1430
|
}))
|
|
1100
1431
|
});
|
|
1101
1432
|
var CloudConfigError = class extends Error {
|
|
@@ -1127,6 +1458,7 @@ function validateAuthenticationConfig(config) {
|
|
|
1127
1458
|
"appleKeyId",
|
|
1128
1459
|
"applePrivateKey"
|
|
1129
1460
|
]);
|
|
1461
|
+
requireTogether(config, "GitHub", ["githubClientId", "githubClientSecret"]);
|
|
1130
1462
|
}
|
|
1131
1463
|
function validateEmailConfig(config) {
|
|
1132
1464
|
requireTogether(config, "SMTP", ["smtpHost", "smtpPort"]);
|
|
@@ -1239,8 +1571,8 @@ async function dropTables(database, tables) {
|
|
|
1239
1571
|
//#endregion
|
|
1240
1572
|
//#region src/server/db/migrations/001_accounts.ts
|
|
1241
1573
|
var _001_accounts_exports = /* @__PURE__ */ __exportAll({
|
|
1242
|
-
down: () => down$
|
|
1243
|
-
up: () => up$
|
|
1574
|
+
down: () => down$17,
|
|
1575
|
+
up: () => up$17
|
|
1244
1576
|
});
|
|
1245
1577
|
/** What Cloud keeps about an account beside Better Auth's tables: its plan, sign-ins, and picture. */
|
|
1246
1578
|
const TABLES$6 = [
|
|
@@ -1251,7 +1583,7 @@ const TABLES$6 = [
|
|
|
1251
1583
|
"user_picture",
|
|
1252
1584
|
"api_rate_limit"
|
|
1253
1585
|
];
|
|
1254
|
-
async function up$
|
|
1586
|
+
async function up$17(database) {
|
|
1255
1587
|
await database.schema.createTable("auth_schema_version").addColumn("id", "text", (column) => column.primaryKey()).addColumn("version", "text", required).addColumn("updated_at", "timestamptz", now).execute();
|
|
1256
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();
|
|
1257
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();
|
|
@@ -1269,14 +1601,14 @@ async function up$13(database) {
|
|
|
1269
1601
|
]]);
|
|
1270
1602
|
await addIndexes(database, [["sign_in", ["user_id", "created_at"]], ["sign_in", ["session_id"]]]);
|
|
1271
1603
|
}
|
|
1272
|
-
async function down$
|
|
1604
|
+
async function down$17(database) {
|
|
1273
1605
|
await dropTables(database, TABLES$6);
|
|
1274
1606
|
}
|
|
1275
1607
|
//#endregion
|
|
1276
1608
|
//#region src/server/db/migrations/002_workspaces.ts
|
|
1277
1609
|
var _002_workspaces_exports = /* @__PURE__ */ __exportAll({
|
|
1278
|
-
down: () => down$
|
|
1279
|
-
up: () => up$
|
|
1610
|
+
down: () => down$16,
|
|
1611
|
+
up: () => up$16
|
|
1280
1612
|
});
|
|
1281
1613
|
/** Workspaces, their members, and the people invited to join. */
|
|
1282
1614
|
const TABLES$5 = [
|
|
@@ -1284,7 +1616,7 @@ const TABLES$5 = [
|
|
|
1284
1616
|
"workspace_member",
|
|
1285
1617
|
"workspace_invitation"
|
|
1286
1618
|
];
|
|
1287
|
-
async function up$
|
|
1619
|
+
async function up$16(database) {
|
|
1288
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();
|
|
1289
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();
|
|
1290
1622
|
await withInvitation(database.schema.createTable("workspace_invitation"), "role").addColumn("workspace_id", "uuid", (column) => column.notNull().references("workspace.id").onDelete("cascade")).execute();
|
|
@@ -1303,14 +1635,14 @@ async function up$12(database) {
|
|
|
1303
1635
|
["workspace_invitation", ["workspace_id", "revoked_at"]]
|
|
1304
1636
|
]);
|
|
1305
1637
|
}
|
|
1306
|
-
async function down$
|
|
1638
|
+
async function down$16(database) {
|
|
1307
1639
|
await dropTables(database, TABLES$5);
|
|
1308
1640
|
}
|
|
1309
1641
|
//#endregion
|
|
1310
1642
|
//#region src/server/db/migrations/003_storage.ts
|
|
1311
1643
|
var _003_storage_exports = /* @__PURE__ */ __exportAll({
|
|
1312
|
-
down: () => down$
|
|
1313
|
-
up: () => up$
|
|
1644
|
+
down: () => down$15,
|
|
1645
|
+
up: () => up$15
|
|
1314
1646
|
});
|
|
1315
1647
|
/** Files in the object store, a workspace's images among them, and how much each workspace uses. */
|
|
1316
1648
|
const TABLES$4 = [
|
|
@@ -1318,19 +1650,19 @@ const TABLES$4 = [
|
|
|
1318
1650
|
"workspace_storage_usage",
|
|
1319
1651
|
"workspace_image"
|
|
1320
1652
|
];
|
|
1321
|
-
async function up$
|
|
1653
|
+
async function up$15(database) {
|
|
1322
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();
|
|
1323
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();
|
|
1324
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();
|
|
1325
1657
|
}
|
|
1326
|
-
async function down$
|
|
1658
|
+
async function down$15(database) {
|
|
1327
1659
|
await dropTables(database, TABLES$4);
|
|
1328
1660
|
}
|
|
1329
1661
|
//#endregion
|
|
1330
1662
|
//#region src/server/db/migrations/004_documents.ts
|
|
1331
1663
|
var _004_documents_exports = /* @__PURE__ */ __exportAll({
|
|
1332
|
-
down: () => down$
|
|
1333
|
-
up: () => up$
|
|
1664
|
+
down: () => down$14,
|
|
1665
|
+
up: () => up$14
|
|
1334
1666
|
});
|
|
1335
1667
|
/** Documents and what they hold: revisions, versions, images, collaboration rooms, and uploads. */
|
|
1336
1668
|
const TABLES$3 = [
|
|
@@ -1362,7 +1694,7 @@ async function createUploads(database) {
|
|
|
1362
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();
|
|
1363
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();
|
|
1364
1696
|
}
|
|
1365
|
-
async function up$
|
|
1697
|
+
async function up$14(database) {
|
|
1366
1698
|
await createRevisions(database);
|
|
1367
1699
|
await createRooms(database);
|
|
1368
1700
|
await createUploads(database);
|
|
@@ -1407,14 +1739,14 @@ async function up$10(database) {
|
|
|
1407
1739
|
["upload", ["status", "expires_at"]]
|
|
1408
1740
|
]);
|
|
1409
1741
|
}
|
|
1410
|
-
async function down$
|
|
1742
|
+
async function down$14(database) {
|
|
1411
1743
|
await dropTables(database, TABLES$3);
|
|
1412
1744
|
}
|
|
1413
1745
|
//#endregion
|
|
1414
1746
|
//#region src/server/db/migrations/005_sharing.ts
|
|
1415
1747
|
var _005_sharing_exports = /* @__PURE__ */ __exportAll({
|
|
1416
|
-
down: () => down$
|
|
1417
|
-
up: () => up$
|
|
1748
|
+
down: () => down$13,
|
|
1749
|
+
up: () => up$13
|
|
1418
1750
|
});
|
|
1419
1751
|
/** Who a document is shared with: people, invitations, links, and the invitations budget. */
|
|
1420
1752
|
const TABLES$2 = [
|
|
@@ -1424,7 +1756,7 @@ const TABLES$2 = [
|
|
|
1424
1756
|
"document_share",
|
|
1425
1757
|
"invitation_send"
|
|
1426
1758
|
];
|
|
1427
|
-
async function up$
|
|
1759
|
+
async function up$13(database) {
|
|
1428
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();
|
|
1429
1761
|
await withInvitation(database.schema.createTable("document_invitation"), "permission").addColumn("document_id", "uuid", (column) => column.notNull().references("document.id").onDelete("cascade")).execute();
|
|
1430
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();
|
|
@@ -1456,14 +1788,14 @@ async function up$9(database) {
|
|
|
1456
1788
|
["invitation_send", ["email_normalized", "sent_at"]]
|
|
1457
1789
|
]);
|
|
1458
1790
|
}
|
|
1459
|
-
async function down$
|
|
1791
|
+
async function down$13(database) {
|
|
1460
1792
|
await dropTables(database, TABLES$2);
|
|
1461
1793
|
}
|
|
1462
1794
|
//#endregion
|
|
1463
1795
|
//#region src/server/db/migrations/006_operations.ts
|
|
1464
1796
|
var _006_operations_exports = /* @__PURE__ */ __exportAll({
|
|
1465
|
-
down: () => down$
|
|
1466
|
-
up: () => up$
|
|
1797
|
+
down: () => down$12,
|
|
1798
|
+
up: () => up$12
|
|
1467
1799
|
});
|
|
1468
1800
|
/** Running the deployment: the email outbox, enrollment, reports, and the administrators' log. */
|
|
1469
1801
|
const TABLES$1 = [
|
|
@@ -1472,7 +1804,7 @@ const TABLES$1 = [
|
|
|
1472
1804
|
"document_report",
|
|
1473
1805
|
"admin_audit_event"
|
|
1474
1806
|
];
|
|
1475
|
-
async function up$
|
|
1807
|
+
async function up$12(database) {
|
|
1476
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();
|
|
1477
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();
|
|
1478
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();
|
|
@@ -1549,24 +1881,24 @@ async function up$8(database) {
|
|
|
1549
1881
|
["admin_audit_event", ["created_at"]]
|
|
1550
1882
|
]);
|
|
1551
1883
|
}
|
|
1552
|
-
async function down$
|
|
1884
|
+
async function down$12(database) {
|
|
1553
1885
|
await dropTables(database, TABLES$1);
|
|
1554
1886
|
}
|
|
1555
1887
|
//#endregion
|
|
1556
1888
|
//#region src/server/db/migrations/007_trash.ts
|
|
1557
1889
|
var _007_trash_exports = /* @__PURE__ */ __exportAll({
|
|
1558
|
-
down: () => down$
|
|
1559
|
-
up: () => up$
|
|
1890
|
+
down: () => down$11,
|
|
1891
|
+
up: () => up$11
|
|
1560
1892
|
});
|
|
1561
1893
|
/**
|
|
1562
1894
|
* Trash: who deleted a document, and who deleted it forever, when, and the storage that took off
|
|
1563
1895
|
* its workspace's usage while its files wait out the grace before cleanup destroys them.
|
|
1564
1896
|
*/
|
|
1565
|
-
async function up$
|
|
1897
|
+
async function up$11(database) {
|
|
1566
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();
|
|
1567
1899
|
await addIndexes(database, [["document", ["workspace_id", "deleted_at desc"]], ["document", ["purged_at"]]]);
|
|
1568
1900
|
}
|
|
1569
|
-
async function down$
|
|
1901
|
+
async function down$11(database) {
|
|
1570
1902
|
await database.schema.dropIndex("document_purged_at_idx").execute();
|
|
1571
1903
|
await database.schema.dropIndex("document_workspace_id_deleted_at_idx").execute();
|
|
1572
1904
|
await database.schema.alterTable("document").dropColumn("purged_bytes").dropColumn("purged_by").dropColumn("purged_at").dropColumn("deleted_by").execute();
|
|
@@ -1574,21 +1906,21 @@ async function down$7(database) {
|
|
|
1574
1906
|
//#endregion
|
|
1575
1907
|
//#region src/server/db/migrations/008_terms.ts
|
|
1576
1908
|
var _008_terms_exports = /* @__PURE__ */ __exportAll({
|
|
1577
|
-
down: () => down$
|
|
1578
|
-
up: () => up$
|
|
1909
|
+
down: () => down$10,
|
|
1910
|
+
up: () => up$10
|
|
1579
1911
|
});
|
|
1580
1912
|
/** Which version of the deployment's terms each account accepted, and when. */
|
|
1581
|
-
async function up$
|
|
1913
|
+
async function up$10(database) {
|
|
1582
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();
|
|
1583
1915
|
}
|
|
1584
|
-
async function down$
|
|
1916
|
+
async function down$10(database) {
|
|
1585
1917
|
await database.schema.dropTable("terms_acceptance").execute();
|
|
1586
1918
|
}
|
|
1587
1919
|
//#endregion
|
|
1588
1920
|
//#region src/server/db/migrations/009_access_tokens.ts
|
|
1589
1921
|
var _009_access_tokens_exports = /* @__PURE__ */ __exportAll({
|
|
1590
|
-
down: () => down$
|
|
1591
|
-
up: () => up$
|
|
1922
|
+
down: () => down$9,
|
|
1923
|
+
up: () => up$9
|
|
1592
1924
|
});
|
|
1593
1925
|
/**
|
|
1594
1926
|
* Personal access tokens, kept by Better Auth's API-key plugin in the table it would build
|
|
@@ -1597,7 +1929,7 @@ var _009_access_tokens_exports = /* @__PURE__ */ __exportAll({
|
|
|
1597
1929
|
* leaves this plugin's table out (`createBetterAuthAdapter`). It holds each token's SHA-256
|
|
1598
1930
|
* digest, never the token.
|
|
1599
1931
|
*/
|
|
1600
|
-
async function up$
|
|
1932
|
+
async function up$9(database) {
|
|
1601
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();
|
|
1602
1934
|
await addIndexes(database, [
|
|
1603
1935
|
["apikey", ["config_id"]],
|
|
@@ -1605,14 +1937,14 @@ async function up$5(database) {
|
|
|
1605
1937
|
["apikey", ["key"]]
|
|
1606
1938
|
]);
|
|
1607
1939
|
}
|
|
1608
|
-
async function down$
|
|
1940
|
+
async function down$9(database) {
|
|
1609
1941
|
await database.schema.dropTable("apikey").execute();
|
|
1610
1942
|
}
|
|
1611
1943
|
//#endregion
|
|
1612
1944
|
//#region src/server/db/migrations/010_storage_limit_notices.ts
|
|
1613
1945
|
var _010_storage_limit_notices_exports = /* @__PURE__ */ __exportAll({
|
|
1614
|
-
down: () => down$
|
|
1615
|
-
up: () => up$
|
|
1946
|
+
down: () => down$8,
|
|
1947
|
+
up: () => up$8
|
|
1616
1948
|
});
|
|
1617
1949
|
/** Every kind of transactional email, as of this migration. */
|
|
1618
1950
|
const EMAIL_KINDS$1 = [
|
|
@@ -1636,7 +1968,7 @@ const EMAIL_KINDS$1 = [
|
|
|
1636
1968
|
* cleanup pass; a row goes once the account holds less than its plan allows again. Email gains
|
|
1637
1969
|
* the kind that tells them, which the previous release never writes.
|
|
1638
1970
|
*/
|
|
1639
|
-
async function up$
|
|
1971
|
+
async function up$8(database) {
|
|
1640
1972
|
await database.schema.createTable("storage_limit_notice").addColumn("user_id", "text", (column) => column.primaryKey()).addColumn("notified_at", "timestamptz", now).execute();
|
|
1641
1973
|
await database.schema.alterTable("transactional_email").dropConstraint("transactional_email_kind_check").execute();
|
|
1642
1974
|
await addChecks(database, [[
|
|
@@ -1645,7 +1977,7 @@ async function up$4(database) {
|
|
|
1645
1977
|
[...EMAIL_KINDS$1, "storage-limit-reached"]
|
|
1646
1978
|
]]);
|
|
1647
1979
|
}
|
|
1648
|
-
async function down$
|
|
1980
|
+
async function down$8(database) {
|
|
1649
1981
|
await database.schema.alterTable("transactional_email").dropConstraint("transactional_email_kind_check").execute();
|
|
1650
1982
|
await addChecks(database, [[
|
|
1651
1983
|
"transactional_email",
|
|
@@ -1658,8 +1990,8 @@ async function down$4(database) {
|
|
|
1658
1990
|
//#region src/server/db/migrations/011_account_ids.ts
|
|
1659
1991
|
var _011_account_ids_exports = /* @__PURE__ */ __exportAll({
|
|
1660
1992
|
contracts: () => contracts,
|
|
1661
|
-
down: () => down$
|
|
1662
|
-
up: () => up$
|
|
1993
|
+
down: () => down$7,
|
|
1994
|
+
up: () => up$7
|
|
1663
1995
|
});
|
|
1664
1996
|
/** The tables that named accounts by `uuid`, unlike every other table Cloud builds. */
|
|
1665
1997
|
const TABLES = [
|
|
@@ -1673,17 +2005,17 @@ const TABLES = [
|
|
|
1673
2005
|
* keeps working while this runs.
|
|
1674
2006
|
*/
|
|
1675
2007
|
const contracts = TABLES.map((table) => `${table}.user_id`);
|
|
1676
|
-
async function up$
|
|
2008
|
+
async function up$7(database) {
|
|
1677
2009
|
for (const table of TABLES) await database.schema.alterTable(table).alterColumn("user_id", (column) => column.setDataType("text")).execute();
|
|
1678
2010
|
}
|
|
1679
|
-
async function down$
|
|
2011
|
+
async function down$7(database) {
|
|
1680
2012
|
for (const table of TABLES) await database.schema.alterTable(table).alterColumn("user_id", (column) => column.setDataType(sql`uuid using user_id::uuid`)).execute();
|
|
1681
2013
|
}
|
|
1682
2014
|
//#endregion
|
|
1683
2015
|
//#region src/server/db/migrations/012_email_locales.ts
|
|
1684
2016
|
var _012_email_locales_exports = /* @__PURE__ */ __exportAll({
|
|
1685
|
-
down: () => down$
|
|
1686
|
-
up: () => up$
|
|
2017
|
+
down: () => down$6,
|
|
2018
|
+
up: () => up$6
|
|
1687
2019
|
});
|
|
1688
2020
|
/** Whether Better Auth's `user` table exists yet, which it doesn't before a server first starts. */
|
|
1689
2021
|
async function hasUserTable(database) {
|
|
@@ -1698,19 +2030,19 @@ async function hasUserTable(database) {
|
|
|
1698
2030
|
* built after Cloud's migrations. A database that already has that schema never builds it again,
|
|
1699
2031
|
* so it gets the column here; accounts from before it have no language and read English.
|
|
1700
2032
|
*/
|
|
1701
|
-
async function up$
|
|
2033
|
+
async function up$6(database) {
|
|
1702
2034
|
await database.schema.alterTable("transactional_email").addColumn("locale", "text", (column) => column.notNull().defaultTo("en")).execute();
|
|
1703
2035
|
if (await hasUserTable(database)) await database.schema.alterTable("user").addColumn("locale", "text", (column) => column.ifNotExists()).execute();
|
|
1704
2036
|
}
|
|
1705
|
-
async function down$
|
|
2037
|
+
async function down$6(database) {
|
|
1706
2038
|
await database.schema.alterTable("transactional_email").dropColumn("locale").execute();
|
|
1707
2039
|
}
|
|
1708
2040
|
//#endregion
|
|
1709
2041
|
//#region src/server/db/migrations/013_document_block_emails.ts
|
|
1710
2042
|
var _013_document_block_emails_exports = /* @__PURE__ */ __exportAll({
|
|
1711
2043
|
DOCUMENT_BLOCK_EMAIL_KINDS: () => DOCUMENT_BLOCK_EMAIL_KINDS,
|
|
1712
|
-
down: () => down$
|
|
1713
|
-
up: () => up$
|
|
2044
|
+
down: () => down$5,
|
|
2045
|
+
up: () => up$5
|
|
1714
2046
|
});
|
|
1715
2047
|
/** Every kind of transactional email before this migration. */
|
|
1716
2048
|
const EMAIL_KINDS = [
|
|
@@ -1740,14 +2072,14 @@ const DOCUMENT_BLOCK_EMAIL_KINDS = [
|
|
|
1740
2072
|
* Email gains the kinds that tell a workspace's owner an administrator blocked one of its
|
|
1741
2073
|
* documents, and that it is back, which the previous release never writes.
|
|
1742
2074
|
*/
|
|
1743
|
-
async function up$
|
|
2075
|
+
async function up$5(database) {
|
|
1744
2076
|
await replaceChecks(database, "widen", [[
|
|
1745
2077
|
"transactional_email",
|
|
1746
2078
|
"kind",
|
|
1747
2079
|
DOCUMENT_BLOCK_EMAIL_KINDS
|
|
1748
2080
|
]]);
|
|
1749
2081
|
}
|
|
1750
|
-
async function down$
|
|
2082
|
+
async function down$5(database) {
|
|
1751
2083
|
await replaceChecks(database, "narrow", [[
|
|
1752
2084
|
"transactional_email",
|
|
1753
2085
|
"kind",
|
|
@@ -1757,8 +2089,8 @@ async function down$1(database) {
|
|
|
1757
2089
|
//#endregion
|
|
1758
2090
|
//#region src/server/db/migrations/014_report_replies.ts
|
|
1759
2091
|
var _014_report_replies_exports = /* @__PURE__ */ __exportAll({
|
|
1760
|
-
down: () => down,
|
|
1761
|
-
up: () => up
|
|
2092
|
+
down: () => down$4,
|
|
2093
|
+
up: () => up$4
|
|
1762
2094
|
});
|
|
1763
2095
|
/**
|
|
1764
2096
|
* Whoever reports a document and leaves an address hears that the report arrived and what the
|
|
@@ -1766,7 +2098,7 @@ var _014_report_replies_exports = /* @__PURE__ */ __exportAll({
|
|
|
1766
2098
|
* guest has no account to say it, and email gains the two kinds, which the previous release
|
|
1767
2099
|
* never writes.
|
|
1768
2100
|
*/
|
|
1769
|
-
async function up(database) {
|
|
2101
|
+
async function up$4(database) {
|
|
1770
2102
|
await database.schema.alterTable("document_report").addColumn("reply_locale", "text").execute();
|
|
1771
2103
|
await replaceChecks(database, "widen", [[
|
|
1772
2104
|
"transactional_email",
|
|
@@ -1778,7 +2110,7 @@ async function up(database) {
|
|
|
1778
2110
|
]
|
|
1779
2111
|
]]);
|
|
1780
2112
|
}
|
|
1781
|
-
async function down(database) {
|
|
2113
|
+
async function down$4(database) {
|
|
1782
2114
|
await replaceChecks(database, "narrow", [[
|
|
1783
2115
|
"transactional_email",
|
|
1784
2116
|
"kind",
|
|
@@ -1787,6 +2119,131 @@ async function down(database) {
|
|
|
1787
2119
|
await database.schema.alterTable("document_report").dropColumn("reply_locale").execute();
|
|
1788
2120
|
}
|
|
1789
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({
|
|
2232
|
+
down: () => down,
|
|
2233
|
+
up: () => up
|
|
2234
|
+
});
|
|
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
|
+
*/
|
|
2240
|
+
async function up(database) {
|
|
2241
|
+
await database.schema.alterTable("enrollment").addColumn("source", "text", (column) => column.check(sql`source in ('waitlist')`)).execute();
|
|
2242
|
+
}
|
|
2243
|
+
async function down(database) {
|
|
2244
|
+
await database.schema.alterTable("enrollment").dropColumn("source").execute();
|
|
2245
|
+
}
|
|
2246
|
+
//#endregion
|
|
1790
2247
|
//#region src/server/db/migrate.ts
|
|
1791
2248
|
const migrations = {
|
|
1792
2249
|
"001_accounts": _001_accounts_exports,
|
|
@@ -1802,7 +2259,11 @@ const migrations = {
|
|
|
1802
2259
|
"011_account_ids": _011_account_ids_exports,
|
|
1803
2260
|
"012_email_locales": _012_email_locales_exports,
|
|
1804
2261
|
"013_document_block_emails": _013_document_block_emails_exports,
|
|
1805
|
-
"014_report_replies": _014_report_replies_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
|
|
1806
2267
|
};
|
|
1807
2268
|
/** Cloud's migrations, in order. */
|
|
1808
2269
|
var CloudMigrationProvider = class {
|
|
@@ -1870,6 +2331,6 @@ async function listen(fetch, port, hostname) {
|
|
|
1870
2331
|
};
|
|
1871
2332
|
}
|
|
1872
2333
|
//#endregion
|
|
1873
|
-
export { CLOUD_ACCOUNT_PLAN_PATH, CLOUD_API_MAX_BODY_BYTES, CLOUD_BILLING_TOKEN_AUDIENCE, CLOUD_DISCOVERY_PATH, CLOUD_EDITOR_VERSION_HEADER, 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, cloudEditorVersionSchema,
|
|
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 };
|
|
1874
2335
|
|
|
1875
2336
|
//# sourceMappingURL=listen.mjs.map
|