@open-pencil/cloud 0.17.0-beta.4 → 0.17.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +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 +296 -27
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +649 -295
- package/dist/client.js.map +1 -1
- package/dist/contract.d.ts +2 -2
- package/dist/contract.js +2 -2
- package/dist/contract2.js +331 -21
- package/dist/contract2.js.map +1 -1
- package/dist/email.d.ts +1773 -32
- package/dist/email.d.ts.map +1 -1
- package/dist/email.js +3478 -288
- package/dist/email.js.map +1 -1
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +48 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +466 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index2.d.ts +35 -0
- package/dist/index2.d.ts.map +1 -0
- package/dist/listen.mjs +447 -290
- package/dist/listen.mjs.map +1 -1
- package/dist/runtime-cloudflare.d.ts +89 -0
- package/dist/runtime-cloudflare.d.ts.map +1 -0
- package/dist/runtime-cloudflare.js +15667 -0
- package/dist/runtime-cloudflare.js.map +1 -0
- package/dist/runtime-node.d.mts +2963 -294
- package/dist/runtime-node.d.mts.map +1 -1
- package/dist/server.d.ts +3473 -842
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +12187 -8244
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +7739 -3548
- package/dist/server.mjs.map +1 -1
- package/dist/server2.mjs +5 -5
- package/dist/server2.mjs.map +1 -1
- package/package.json +22 -5
- package/src/admin/audit/service.ts +2 -2
- package/src/admin/documents/service.ts +76 -6
- package/src/admin/reports/service.ts +7 -1
- package/src/client/api.ts +23 -471
- package/src/client/auth/client.ts +22 -3
- package/src/client/billing.ts +80 -0
- package/src/client/community.ts +40 -0
- package/src/client/discovery.ts +35 -9
- package/src/client/documents.ts +160 -0
- package/src/client/index.ts +7 -0
- package/src/client/portal/account.ts +54 -2
- package/src/client/portal/request.ts +2 -0
- package/src/client/response.ts +21 -0
- package/src/client/schema.ts +8 -0
- package/src/client/services.ts +23 -18
- package/src/client/sharing.ts +262 -0
- package/src/client/versions.ts +104 -0
- package/src/contract/account.ts +50 -0
- package/src/contract/billing.ts +166 -0
- package/src/contract/collaboration.ts +5 -0
- package/src/contract/community.ts +60 -0
- package/src/contract/discovery.ts +63 -2
- package/src/contract/entitlements.ts +10 -0
- package/src/contract/index.ts +54 -5
- package/src/contract/links.ts +57 -4
- package/src/contract/locale.ts +27 -0
- package/src/contract/portal.ts +12 -1
- package/src/contract/routes.ts +10 -0
- package/src/contract/services.ts +18 -16
- package/src/email/i18n.ts +174 -0
- package/src/email/index.ts +13 -2
- package/src/email/locales/ar.json +141 -0
- package/src/email/locales/de.json +141 -0
- package/src/email/locales/es.json +141 -0
- package/src/email/locales/fr.json +141 -0
- package/src/email/locales/it.json +141 -0
- package/src/email/locales/ja.json +141 -0
- package/src/email/locales/pl.json +141 -0
- package/src/email/locales/pt-br.json +141 -0
- package/src/email/locales/ru.json +141 -0
- package/src/email/locales/zh-cn.json +141 -0
- package/src/email/messages.ts +200 -0
- package/src/email/render.ts +142 -276
- package/src/email/samples.ts +115 -0
- package/src/email/schema.ts +70 -6
- package/src/email/templates/BrandEmail.vue +54 -0
- package/src/email/templates/DocumentBlocked.vue +45 -0
- package/src/email/templates/DocumentInvitation.vue +24 -0
- package/src/email/templates/DocumentReport.vue +32 -0
- package/src/email/templates/DocumentReportDecided.vue +36 -0
- package/src/email/templates/DocumentReportReceived.vue +18 -0
- package/src/email/templates/DocumentRestored.vue +24 -0
- package/src/email/templates/EmailChangeRequested.vue +24 -0
- package/src/email/templates/EmailRoot.vue +19 -0
- package/src/email/templates/EmailText.vue +9 -0
- package/src/email/templates/EmailVerification.vue +38 -0
- package/src/email/templates/EnrollmentNotification.vue +24 -0
- package/src/email/templates/EnrollmentUpdate.vue +52 -0
- package/src/email/templates/NewSignIn.vue +37 -0
- package/src/email/templates/PasswordChanged.vue +22 -0
- package/src/email/templates/PasswordReset.vue +23 -0
- package/src/email/templates/StorageLimitReached.vue +28 -0
- package/src/email/templates/TwoStepChanged.vue +32 -0
- package/src/email/templates/WaitlistConfirmation.vue +29 -0
- package/src/email/templates/WorkspaceInvitation.vue +28 -0
- package/src/email/templates/brand.ts +9 -61
- package/src/email/templates/localization.ts +17 -0
- package/src/errors/index.ts +6 -0
- package/src/global.d.ts +7 -0
- package/src/runtime/cloudflare/relay/index.ts +7 -1
- package/src/runtime/cloudflare/tsconfig.json +2 -1
- package/src/runtime/cloudflare/worker.ts +8 -1
- package/src/runtime/node/cleanup.ts +5 -1
- package/src/runtime/node/email/transport.ts +13 -10
- package/src/runtime/node/main.ts +1 -1
- package/src/runtime/node/server.ts +12 -2
- package/src/runtime/node/services/main.ts +1 -1
- package/src/runtime/posthog/errors.ts +2 -1
- 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/deletion.ts +2 -0
- package/src/server/account/routes.ts +271 -240
- package/src/server/account/tokens.ts +57 -0
- package/src/server/api/router.ts +23 -0
- package/src/server/app/checks.ts +84 -0
- package/src/server/app/editors.ts +20 -0
- package/src/server/app/index.ts +128 -0
- package/src/server/app/indexing.ts +40 -0
- package/src/server/app/limiters.ts +53 -0
- package/src/server/app/routes.ts +114 -0
- package/src/server/app/services.ts +185 -0
- package/src/server/auth/access-tokens.ts +62 -0
- package/src/server/auth/adapter.ts +21 -1
- package/src/server/auth/email.ts +4 -1
- package/src/server/auth/enrollment.ts +116 -0
- package/src/server/auth/factory.ts +88 -131
- package/src/server/auth/logger.ts +23 -0
- package/src/server/auth/mfa-assurance.ts +51 -0
- package/src/server/auth/passwords.ts +43 -0
- package/src/server/auth/session.ts +2 -0
- package/src/server/billing/index.ts +6 -0
- package/src/server/billing/routes.ts +27 -0
- package/src/server/billing/tokens.ts +37 -0
- package/src/server/cleanup/configured.ts +16 -3
- package/src/server/cleanup/worker.ts +10 -1
- package/src/server/collaboration/relay/hub.ts +25 -142
- package/src/server/collaboration/relay/room.ts +154 -0
- package/src/server/collaboration/service.ts +21 -2
- 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 +17 -5
- package/src/server/config/index.ts +1 -1
- package/src/server/config/public.ts +7 -1
- package/src/server/config/schema.ts +40 -292
- package/src/server/config/toml/schema.ts +307 -0
- package/src/server/db/index.ts +1 -0
- package/src/server/db/migrate.ts +13 -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/schema.ts +26 -1
- package/src/server/db/tables.ts +30 -1
- package/src/server/db/users.ts +22 -0
- package/src/server/documents/index.ts +1 -1
- package/src/server/documents/limits.ts +7 -1
- package/src/server/documents/service.ts +12 -402
- package/src/server/documents/uploads.ts +450 -0
- package/src/server/documents/versions/service.ts +81 -24
- package/src/server/email/invitations.ts +1 -0
- package/src/server/email/service.ts +31 -4
- package/src/server/email/types.ts +12 -0
- package/src/server/errors/index.ts +1 -9
- package/src/server/index.ts +12 -5
- package/src/server/invitations/types.ts +5 -1
- package/src/server/objects/types.ts +5 -0
- 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/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 +3 -1
- package/src/server/reports/service.ts +24 -2
- package/src/server/sharing/capabilities/service.ts +2 -3
- package/src/server/sharing/invitations/service.ts +14 -4
- package/src/server/validation.ts +3 -0
- package/src/server/workspaces/members.ts +7 -19
- package/src/services/app.ts +1 -3
- package/src/services/config.ts +1 -0
- 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/src/{server/errors → errors}/posthog.ts +0 -0
package/dist/listen.mjs
CHANGED
|
@@ -36,12 +36,11 @@ const CLOUD_SERVICES_API_PATHS = {
|
|
|
36
36
|
search: "/v1/search"
|
|
37
37
|
};
|
|
38
38
|
const urlSchema$1 = v.pipe(v.string(), v.url());
|
|
39
|
-
const creditsSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
39
|
+
const creditsSchema$1 = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
40
40
|
const cloudServicesDiscoverySchema = v.object({
|
|
41
41
|
endpoint: urlSchema$1,
|
|
42
42
|
contractVersion: v.literal("1")
|
|
43
43
|
});
|
|
44
|
-
const cloudBillingDiscoverySchema = v.object({ portalURL: urlSchema$1 });
|
|
45
44
|
const createServicesTokenSchema = v.object({ workspaceId: v.pipe(v.string(), v.uuid()) });
|
|
46
45
|
function parseCreateServicesToken(input) {
|
|
47
46
|
return v.parse(createServicesTokenSchema, input);
|
|
@@ -58,12 +57,11 @@ const servicesTokenClaimsSchema = v.object({
|
|
|
58
57
|
workspaceId: v.pipe(v.string(), v.uuid()),
|
|
59
58
|
/**
|
|
60
59
|
* 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.
|
|
60
|
+
* workspace they own shares.
|
|
63
61
|
*/
|
|
64
|
-
accountId: v.
|
|
62
|
+
accountId: v.pipe(v.string(), v.minLength(1)),
|
|
65
63
|
/** Credits the owner's plan grants each month; `null` when Cloud sets no allowance. */
|
|
66
|
-
monthlyCreditAllowance: v.nullable(creditsSchema),
|
|
64
|
+
monthlyCreditAllowance: v.nullable(creditsSchema$1),
|
|
67
65
|
iat: v.pipe(v.number(), v.integer()),
|
|
68
66
|
exp: v.pipe(v.number(), v.integer())
|
|
69
67
|
});
|
|
@@ -71,8 +69,8 @@ const chatModelSchema = v.object({
|
|
|
71
69
|
id: v.pipe(v.string(), v.minLength(1)),
|
|
72
70
|
label: v.pipe(v.string(), v.minLength(1)),
|
|
73
71
|
/** Credits per million input and output tokens. */
|
|
74
|
-
creditsPerMillionInputTokens: creditsSchema,
|
|
75
|
-
creditsPerMillionOutputTokens: creditsSchema,
|
|
72
|
+
creditsPerMillionInputTokens: creditsSchema$1,
|
|
73
|
+
creditsPerMillionOutputTokens: creditsSchema$1,
|
|
76
74
|
contextTokens: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
77
75
|
capabilities: v.object({
|
|
78
76
|
reasoning: v.boolean(),
|
|
@@ -81,7 +79,7 @@ const chatModelSchema = v.object({
|
|
|
81
79
|
})
|
|
82
80
|
});
|
|
83
81
|
/** What one web search costs; a service without search leaves it out of its catalog. */
|
|
84
|
-
const searchPricingSchema = v.object({ creditsPerRequest: creditsSchema });
|
|
82
|
+
const searchPricingSchema = v.object({ creditsPerRequest: creditsSchema$1 });
|
|
85
83
|
const serviceCatalogSchema = v.object({
|
|
86
84
|
models: v.array(chatModelSchema),
|
|
87
85
|
defaultModelID: v.pipe(v.string(), v.minLength(1)),
|
|
@@ -93,12 +91,12 @@ const creditBucketSchema = v.object({
|
|
|
93
91
|
"purchased",
|
|
94
92
|
"grant"
|
|
95
93
|
]),
|
|
96
|
-
remaining: creditsSchema,
|
|
94
|
+
remaining: creditsSchema$1,
|
|
97
95
|
expiresAt: v.nullable(v.pipe(v.string(), v.isoTimestamp()))
|
|
98
96
|
});
|
|
99
97
|
v.object({
|
|
100
98
|
/** Credits left to spend; `null` when the service sets no limit. */
|
|
101
|
-
balance: v.nullable(creditsSchema),
|
|
99
|
+
balance: v.nullable(creditsSchema$1),
|
|
102
100
|
/** Spent first to last. */
|
|
103
101
|
buckets: v.array(creditBucketSchema)
|
|
104
102
|
});
|
|
@@ -112,7 +110,7 @@ const usageEntrySchema = v.object({
|
|
|
112
110
|
]),
|
|
113
111
|
modelID: v.nullable(v.string()),
|
|
114
112
|
userId: v.pipe(v.string(), v.minLength(1)),
|
|
115
|
-
credits: creditsSchema
|
|
113
|
+
credits: creditsSchema$1
|
|
116
114
|
});
|
|
117
115
|
v.object({
|
|
118
116
|
query: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(1e3)),
|
|
@@ -159,6 +157,90 @@ const SERVICE_ERROR_STATUS = {
|
|
|
159
157
|
capability_unavailable: 404,
|
|
160
158
|
rate_limited: 429
|
|
161
159
|
};
|
|
160
|
+
/**
|
|
161
|
+
* Whether a bearer token may travel to `url`: over HTTPS, or in the clear only to a loopback
|
|
162
|
+
* address, for development. Only literal addresses count, since a name such as `localhost` is
|
|
163
|
+
* whatever the resolver answers. Services and billing tokens act as the account until they expire.
|
|
164
|
+
*/
|
|
165
|
+
function sendsTokenSafely(url) {
|
|
166
|
+
const { protocol, hostname } = new URL(url);
|
|
167
|
+
if (protocol === "https:") return true;
|
|
168
|
+
if (protocol !== "http:") return false;
|
|
169
|
+
return hostname === "[::1]" || /^127(\.\d{1,3}){3}$/.test(hostname);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* The `aud` of the tokens Cloud signs for its billing service, with the services' signing key,
|
|
173
|
+
* whose public keys it publishes at `CLOUD_SERVICES_JWKS_PATH`.
|
|
174
|
+
*/
|
|
175
|
+
const CLOUD_BILLING_TOKEN_AUDIENCE = "openpencil-billing";
|
|
176
|
+
/**
|
|
177
|
+
* The page of a Cloud server where the signed-in person sees their plan, buys a plan or credits,
|
|
178
|
+
* and manages what they pay for; editors link to it whenever the server advertises billing.
|
|
179
|
+
*/
|
|
180
|
+
const CLOUD_ACCOUNT_PLAN_PATH = "/account/plan";
|
|
181
|
+
const urlSchema = v.pipe(v.string(), v.url());
|
|
182
|
+
const idSchema = v.pipe(v.string(), v.regex(/^[a-z0-9][a-z0-9-]{0,62}$/));
|
|
183
|
+
const centsSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
184
|
+
const bytesSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
185
|
+
const creditsSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
186
|
+
const cloudBillingDiscoverySchema = v.object({
|
|
187
|
+
endpoint: urlSchema,
|
|
188
|
+
contractVersion: v.literal("1")
|
|
189
|
+
});
|
|
190
|
+
v.object({
|
|
191
|
+
token: v.pipe(v.string(), v.minLength(1)),
|
|
192
|
+
expiresAt: v.pipe(v.string(), v.isoTimestamp())
|
|
193
|
+
});
|
|
194
|
+
v.object({
|
|
195
|
+
iss: urlSchema,
|
|
196
|
+
aud: v.literal(CLOUD_BILLING_TOKEN_AUDIENCE),
|
|
197
|
+
/** The account: the Cloud user whose plan and credits these are. */
|
|
198
|
+
sub: v.pipe(v.string(), v.minLength(1)),
|
|
199
|
+
/** Where the payment provider sends receipts and invoices. */
|
|
200
|
+
email: v.pipe(v.string(), v.email()),
|
|
201
|
+
iat: v.pipe(v.number(), v.integer()),
|
|
202
|
+
exp: v.pipe(v.number(), v.integer())
|
|
203
|
+
});
|
|
204
|
+
/** A plan an account subscribes to, billed every month in US dollars before tax. */
|
|
205
|
+
const billingPlanSchema = v.object({
|
|
206
|
+
id: idSchema,
|
|
207
|
+
name: v.pipe(v.string(), v.minLength(1)),
|
|
208
|
+
monthlyPriceCents: centsSchema,
|
|
209
|
+
storageBytes: bytesSchema,
|
|
210
|
+
monthlyCredits: creditsSchema
|
|
211
|
+
});
|
|
212
|
+
/** Credits an account on a plan buys once, in US dollars before tax. */
|
|
213
|
+
const creditPackSchema = v.object({
|
|
214
|
+
id: idSchema,
|
|
215
|
+
credits: creditsSchema,
|
|
216
|
+
priceCents: centsSchema,
|
|
217
|
+
/** How long the credits last from purchase. */
|
|
218
|
+
validDays: v.pipe(v.number(), v.integer(), v.minValue(1))
|
|
219
|
+
});
|
|
220
|
+
v.object({
|
|
221
|
+
plans: v.array(billingPlanSchema),
|
|
222
|
+
creditPacks: v.array(creditPackSchema)
|
|
223
|
+
});
|
|
224
|
+
v.object({ subscription: v.nullable(v.object({
|
|
225
|
+
planId: idSchema,
|
|
226
|
+
status: v.picklist(["active", "past_due"]),
|
|
227
|
+
/** When the current period ends: the next charge, or the end of a cancelled plan. */
|
|
228
|
+
currentPeriodEnd: v.pipe(v.string(), v.isoTimestamp()),
|
|
229
|
+
/** Whether the plan ends at `currentPeriodEnd` instead of renewing. */
|
|
230
|
+
cancelsAtPeriodEnd: v.boolean()
|
|
231
|
+
})) });
|
|
232
|
+
v.union([v.object({ planId: idSchema }), v.object({ creditPackId: idSchema })]);
|
|
233
|
+
v.object({ url: v.pipe(urlSchema, v.regex(/^https:\/\//i, "Billing sends people to an HTTPS page")) });
|
|
234
|
+
const billingErrorCodeSchema = v.picklist([
|
|
235
|
+
"invalid_request",
|
|
236
|
+
"unauthorized",
|
|
237
|
+
"not_allowed",
|
|
238
|
+
"provider_unavailable"
|
|
239
|
+
]);
|
|
240
|
+
v.object({ error: v.object({
|
|
241
|
+
code: billingErrorCodeSchema,
|
|
242
|
+
message: v.optional(v.string())
|
|
243
|
+
}) });
|
|
162
244
|
//#endregion
|
|
163
245
|
//#region src/contract/documents.ts
|
|
164
246
|
const CLOUD_PROTOCOL_MAX_UPLOAD_BYTES = 1073741824;
|
|
@@ -653,6 +735,30 @@ const cloudCapabilitiesSchema = v.object({
|
|
|
653
735
|
/** A released editor version, `major.minor.patch`. */
|
|
654
736
|
const cloudEditorVersionSchema = v.pipe(v.string(), v.regex(/^\d+\.\d+\.\d+$/));
|
|
655
737
|
/**
|
|
738
|
+
* The header desktop editors send with each request, naming their version, so a server can refuse
|
|
739
|
+
* an editor older than its `minimumEditorVersion`. Browser editors leave it out: the server serves
|
|
740
|
+
* them, and an older server's CORS rules would refuse a header they don't list.
|
|
741
|
+
*/
|
|
742
|
+
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
|
+
/**
|
|
748
|
+
* Whether `version` is `minimum` or later, comparing `major.minor.patch` numerically; a prerelease
|
|
749
|
+
* counts as its release. A version that isn't one, on either side, is not at least anything.
|
|
750
|
+
*/
|
|
751
|
+
function isEditorVersionAtLeast(version, minimum) {
|
|
752
|
+
const have = editorVersionParts(version);
|
|
753
|
+
const need = editorVersionParts(minimum);
|
|
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;
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
656
762
|
* Whether editors offer this server to everyone, and from which editor version on. Only the
|
|
657
763
|
* official server's listing is read: it turns the Cloud entry points on without an editor release,
|
|
658
764
|
* and an editor older than the minimum keeps them hidden.
|
|
@@ -672,6 +778,22 @@ const cloudLegalDiscoverySchema = v.object({
|
|
|
672
778
|
abuseEmail: v.optional(v.pipe(v.string(), v.email())),
|
|
673
779
|
minimumAge: v.optional(v.pipe(v.number(), v.integer()))
|
|
674
780
|
});
|
|
781
|
+
/** A web address a page may link or load: `http` or `https` only, never a script or data URL. */
|
|
782
|
+
const webURLSchema = v.pipe(v.string(), v.url(), v.check((value) => ["http:", "https:"].includes(new URL(value).protocol)));
|
|
783
|
+
/**
|
|
784
|
+
* How a self-hosted server names itself on its public pages: the operator's name and logo in the
|
|
785
|
+
* bar, and where its people get help. The official server is OpenPencil's own and names none.
|
|
786
|
+
*/
|
|
787
|
+
const cloudBrandingSchema = v.object({
|
|
788
|
+
name: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(80))),
|
|
789
|
+
logoURL: v.optional(webURLSchema),
|
|
790
|
+
helpURL: v.optional(webURLSchema)
|
|
791
|
+
});
|
|
792
|
+
/**
|
|
793
|
+
* The server's community gallery: the workspace whose documents anyone may open read-only.
|
|
794
|
+
* Saving to it publishes, so editors never choose it for anyone and say so when it is chosen.
|
|
795
|
+
*/
|
|
796
|
+
const cloudCommunityDiscoverySchema = v.object({ workspaceId: v.pipe(v.string(), v.uuid()) });
|
|
675
797
|
const cloudDiscoverySchema = v.object({
|
|
676
798
|
protocolVersion: v.literal("1"),
|
|
677
799
|
deployment: cloudDeploymentSchema,
|
|
@@ -682,11 +804,19 @@ const cloudDiscoverySchema = v.object({
|
|
|
682
804
|
authentication: cloudAuthenticationSchema,
|
|
683
805
|
capabilities: cloudCapabilitiesSchema,
|
|
684
806
|
listing: v.optional(cloudListingSchema),
|
|
807
|
+
/**
|
|
808
|
+
* The oldest editor version the server works with. Older editors ask to be updated instead of
|
|
809
|
+
* connecting, and the server refuses their requests.
|
|
810
|
+
*/
|
|
811
|
+
minimumEditorVersion: v.optional(cloudEditorVersionSchema),
|
|
685
812
|
/** The services editors reach with Cloud-signed tokens; absent when the deployment has none. */
|
|
686
813
|
services: v.optional(cloudServicesDiscoverySchema),
|
|
687
814
|
/** Where people manage their plan and buy credits; absent when the deployment does not bill. */
|
|
688
815
|
billing: v.optional(cloudBillingDiscoverySchema),
|
|
689
|
-
|
|
816
|
+
/** The community gallery; absent when the deployment has none. */
|
|
817
|
+
community: v.optional(cloudCommunityDiscoverySchema),
|
|
818
|
+
legal: v.optional(cloudLegalDiscoverySchema),
|
|
819
|
+
branding: v.optional(cloudBrandingSchema)
|
|
690
820
|
});
|
|
691
821
|
function parseCloudDiscovery(input) {
|
|
692
822
|
return v.parse(cloudDiscoverySchema, input);
|
|
@@ -755,6 +885,10 @@ const workspaceMemberParams = validatedParams(v.object({
|
|
|
755
885
|
}));
|
|
756
886
|
const accountParams = validatedParams(v.object({ userId: uuidParamSchema }));
|
|
757
887
|
const shareParams = validatedParams(v.object({ shareId: uuidParamSchema }));
|
|
888
|
+
const communityThumbnailParams = validatedParams(v.object({
|
|
889
|
+
documentId: uuidParamSchema,
|
|
890
|
+
revisionId: uuidParamSchema
|
|
891
|
+
}));
|
|
758
892
|
const invitationParams = validatedParams(v.object({ invitationId: uuidParamSchema }));
|
|
759
893
|
const invitationContinuationParams = validatedParams(v.object({ continuationId: textParamSchema }));
|
|
760
894
|
const uploadParams = validatedParams(v.object({ uploadId: uuidParamSchema }));
|
|
@@ -767,14 +901,14 @@ const pictureParams = validatedParams(v.object({
|
|
|
767
901
|
}));
|
|
768
902
|
//#endregion
|
|
769
903
|
//#region src/server/policy/schema.ts
|
|
770
|
-
const positiveIntegerSchema
|
|
904
|
+
const positiveIntegerSchema = v.pipe(v.number(), v.integer(), v.minValue(1));
|
|
771
905
|
const nonNegativeIntegerSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
772
906
|
const staticEntitlementsSchema = v.object({
|
|
773
907
|
documents: v.optional(v.object({
|
|
774
|
-
maximumFileBytes: v.optional(positiveIntegerSchema
|
|
908
|
+
maximumFileBytes: v.optional(positiveIntegerSchema),
|
|
775
909
|
revisionHistory: v.optional(v.boolean())
|
|
776
910
|
}), {}),
|
|
777
|
-
storage: v.optional(v.object({ maximumBytes: v.optional(positiveIntegerSchema
|
|
911
|
+
storage: v.optional(v.object({ maximumBytes: v.optional(positiveIntegerSchema) }), {}),
|
|
778
912
|
sharing: v.optional(v.object({
|
|
779
913
|
links: v.optional(v.boolean()),
|
|
780
914
|
guestView: v.optional(v.boolean()),
|
|
@@ -783,7 +917,7 @@ const staticEntitlementsSchema = v.object({
|
|
|
783
917
|
}), {}),
|
|
784
918
|
collaboration: v.optional(v.object({
|
|
785
919
|
enabled: v.optional(v.boolean()),
|
|
786
|
-
maximumParticipants: v.optional(positiveIntegerSchema
|
|
920
|
+
maximumParticipants: v.optional(positiveIntegerSchema)
|
|
787
921
|
}), {}),
|
|
788
922
|
services: v.optional(v.object({
|
|
789
923
|
enabled: v.optional(v.boolean()),
|
|
@@ -792,10 +926,10 @@ const staticEntitlementsSchema = v.object({
|
|
|
792
926
|
});
|
|
793
927
|
const staticEntitlementsTOMLSchema = v.strictObject({
|
|
794
928
|
documents: v.optional(v.strictObject({
|
|
795
|
-
maximum_file_bytes: v.optional(positiveIntegerSchema
|
|
929
|
+
maximum_file_bytes: v.optional(positiveIntegerSchema),
|
|
796
930
|
revision_history: v.optional(v.boolean())
|
|
797
931
|
})),
|
|
798
|
-
storage: v.optional(v.strictObject({ maximum_bytes: v.optional(positiveIntegerSchema
|
|
932
|
+
storage: v.optional(v.strictObject({ maximum_bytes: v.optional(positiveIntegerSchema) })),
|
|
799
933
|
sharing: v.optional(v.strictObject({
|
|
800
934
|
links: v.optional(v.boolean()),
|
|
801
935
|
guest_view: v.optional(v.boolean()),
|
|
@@ -804,7 +938,7 @@ const staticEntitlementsTOMLSchema = v.strictObject({
|
|
|
804
938
|
})),
|
|
805
939
|
collaboration: v.optional(v.strictObject({
|
|
806
940
|
enabled: v.optional(v.boolean()),
|
|
807
|
-
maximum_participants: v.optional(positiveIntegerSchema
|
|
941
|
+
maximum_participants: v.optional(positiveIntegerSchema)
|
|
808
942
|
})),
|
|
809
943
|
services: v.optional(v.strictObject({
|
|
810
944
|
enabled: v.optional(v.boolean()),
|
|
@@ -835,6 +969,7 @@ const rawCloudServerConfigSchema = v.object({
|
|
|
835
969
|
deployment: v.picklist(["official", "self-hosted"]),
|
|
836
970
|
publicURL: httpURLSchema,
|
|
837
971
|
listingMinimumEditorVersion: v.optional(cloudEditorVersionSchema),
|
|
972
|
+
minimumEditorVersion: v.optional(cloudEditorVersionSchema),
|
|
838
973
|
relayURL: v.optional(websocketURLSchema),
|
|
839
974
|
technicalLimits: v.optional(v.object({
|
|
840
975
|
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 +981,8 @@ const rawCloudServerConfigSchema = v.object({
|
|
|
846
981
|
maximumConnectionsPerRoom: CLOUD_DEFAULT_MAX_CONNECTIONS_PER_ROOM
|
|
847
982
|
}),
|
|
848
983
|
staticEntitlements: v.optional(staticEntitlementsSchema),
|
|
984
|
+
/** With database entitlements, what an account without stored ones takes, value by value. */
|
|
985
|
+
defaultEntitlements: v.optional(staticEntitlementsSchema),
|
|
849
986
|
databaseURL: v.pipe(v.string(), v.url()),
|
|
850
987
|
authSecret: v.pipe(v.string(), v.minLength(32)),
|
|
851
988
|
trustedOrigins: v.optional(v.array(httpURLSchema), []),
|
|
@@ -926,7 +1063,8 @@ const rawCloudServerConfigSchema = v.object({
|
|
|
926
1063
|
/** The PKCS #8 PEM of the P-256 key that signs service tokens. */
|
|
927
1064
|
servicesSigningKey: optionalTextSchema,
|
|
928
1065
|
servicesTokenLifetimeSeconds: v.optional(v.pipe(v.number(), v.integer(), v.minValue(60), v.maxValue(3600)), 600),
|
|
929
|
-
|
|
1066
|
+
/** The billing service accounts buy plans and credits from, which discovery advertises. */
|
|
1067
|
+
billingEndpoint: v.optional(httpURLSchema),
|
|
930
1068
|
/** The bearer token services such as billing present to the internal API. */
|
|
931
1069
|
internalServiceToken: v.optional(v.pipe(v.string(), v.minLength(32))),
|
|
932
1070
|
/**
|
|
@@ -942,6 +1080,17 @@ const rawCloudServerConfigSchema = v.object({
|
|
|
942
1080
|
abuseEmail: v.optional(v.pipe(v.string(), v.email())),
|
|
943
1081
|
minimumAge: v.optional(v.pipe(v.number(), v.integer(), v.minValue(13), v.maxValue(21)))
|
|
944
1082
|
})),
|
|
1083
|
+
/**
|
|
1084
|
+
* The workspace whose documents anyone may open read-only, without signing in or a link: the
|
|
1085
|
+
* deployment's community gallery. Without it the server has none.
|
|
1086
|
+
*/
|
|
1087
|
+
community: v.optional(v.object({ workspaceId: v.pipe(v.string(), v.uuid()) })),
|
|
1088
|
+
/** How a self-hosted server names itself on its public pages. */
|
|
1089
|
+
branding: v.optional(v.object({
|
|
1090
|
+
name: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(80))),
|
|
1091
|
+
logoURL: v.optional(httpURLSchema),
|
|
1092
|
+
helpURL: v.optional(httpURLSchema)
|
|
1093
|
+
})),
|
|
945
1094
|
/** Where server errors are reported; without it the server reports nothing. */
|
|
946
1095
|
errorTracking: v.optional(v.object({
|
|
947
1096
|
provider: v.literal("posthog"),
|
|
@@ -989,8 +1138,10 @@ function validateEmailConfig(config) {
|
|
|
989
1138
|
}
|
|
990
1139
|
function validateServiceConfig(config) {
|
|
991
1140
|
requireTogether(config, "Services", ["servicesEndpoint", "servicesSigningKey"]);
|
|
1141
|
+
if (config.billingEndpoint && !config.servicesSigningKey) throw new CloudConfigError("Billing needs the services signing key to sign its tokens");
|
|
1142
|
+
if (config.billingEndpoint && !config.internalServiceToken) throw new CloudConfigError("Billing needs the internal API to set the plans it sells");
|
|
992
1143
|
if (config.internalServiceToken && config.staticEntitlements) throw new CloudConfigError("The internal API writes database entitlements, which static entitlements would hide");
|
|
993
|
-
|
|
1144
|
+
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
1145
|
}
|
|
995
1146
|
function validateLegalConfig(config) {
|
|
996
1147
|
const legal = config.legal;
|
|
@@ -1012,229 +1163,6 @@ function parseCloudServerConfig(input) {
|
|
|
1012
1163
|
validateLegalConfig(config);
|
|
1013
1164
|
return config;
|
|
1014
1165
|
}
|
|
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
1166
|
//#endregion
|
|
1239
1167
|
//#region src/server/db/expressions.ts
|
|
1240
1168
|
const CURRENT_TIMESTAMP = sql`current_timestamp`;
|
|
@@ -1276,6 +1204,27 @@ function withInvitation(table, access) {
|
|
|
1276
1204
|
async function addChecks(database, checks) {
|
|
1277
1205
|
for (const [table, column, values] of checks) await database.schema.alterTable(table).addCheckConstraint(`${table}_${column}_check`, checkColumnIn(column, values)).execute();
|
|
1278
1206
|
}
|
|
1207
|
+
/**
|
|
1208
|
+
* Replaces the values a column may take, as `addChecks` named them. Widening them, as when a
|
|
1209
|
+
* release adds a kind the previous one never writes, adds the check `NOT VALID`: rows already
|
|
1210
|
+
* there passed the narrower one, so PostgreSQL skips scanning them while it holds the table, and
|
|
1211
|
+
* checks every row written from then on. Narrowing them, as a rollback does, checks every row.
|
|
1212
|
+
*/
|
|
1213
|
+
async function replaceChecks(database, change, checks) {
|
|
1214
|
+
for (const [table, column, values] of checks) {
|
|
1215
|
+
const name = `${table}_${column}_check`;
|
|
1216
|
+
await database.schema.alterTable(table).dropConstraint(name).execute();
|
|
1217
|
+
if (change === "narrow") {
|
|
1218
|
+
await addChecks(database, [[
|
|
1219
|
+
table,
|
|
1220
|
+
column,
|
|
1221
|
+
values
|
|
1222
|
+
]]);
|
|
1223
|
+
continue;
|
|
1224
|
+
}
|
|
1225
|
+
await sql`alter table ${sql.table(table)} add constraint ${sql.id(name)} check (${checkColumnIn(column, values)}) not valid`.execute(database);
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1279
1228
|
/** Lookups beyond primary keys and unique columns, as `[table, columns]`; `desc` sorts newest first. */
|
|
1280
1229
|
async function addIndexes(database, indexes) {
|
|
1281
1230
|
for (const [table, columns] of indexes) {
|
|
@@ -1290,11 +1239,11 @@ async function dropTables(database, tables) {
|
|
|
1290
1239
|
//#endregion
|
|
1291
1240
|
//#region src/server/db/migrations/001_accounts.ts
|
|
1292
1241
|
var _001_accounts_exports = /* @__PURE__ */ __exportAll({
|
|
1293
|
-
down: () => down$
|
|
1294
|
-
up: () => up$
|
|
1242
|
+
down: () => down$13,
|
|
1243
|
+
up: () => up$13
|
|
1295
1244
|
});
|
|
1296
1245
|
/** What Cloud keeps about an account beside Better Auth's tables: its plan, sign-ins, and picture. */
|
|
1297
|
-
const TABLES$
|
|
1246
|
+
const TABLES$6 = [
|
|
1298
1247
|
"auth_schema_version",
|
|
1299
1248
|
"account_entitlement",
|
|
1300
1249
|
"mfa_assurance",
|
|
@@ -1302,7 +1251,7 @@ const TABLES$5 = [
|
|
|
1302
1251
|
"user_picture",
|
|
1303
1252
|
"api_rate_limit"
|
|
1304
1253
|
];
|
|
1305
|
-
async function up$
|
|
1254
|
+
async function up$13(database) {
|
|
1306
1255
|
await database.schema.createTable("auth_schema_version").addColumn("id", "text", (column) => column.primaryKey()).addColumn("version", "text", required).addColumn("updated_at", "timestamptz", now).execute();
|
|
1307
1256
|
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
1257
|
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 +1269,22 @@ async function up$7(database) {
|
|
|
1320
1269
|
]]);
|
|
1321
1270
|
await addIndexes(database, [["sign_in", ["user_id", "created_at"]], ["sign_in", ["session_id"]]]);
|
|
1322
1271
|
}
|
|
1323
|
-
async function down$
|
|
1324
|
-
await dropTables(database, TABLES$
|
|
1272
|
+
async function down$13(database) {
|
|
1273
|
+
await dropTables(database, TABLES$6);
|
|
1325
1274
|
}
|
|
1326
1275
|
//#endregion
|
|
1327
1276
|
//#region src/server/db/migrations/002_workspaces.ts
|
|
1328
1277
|
var _002_workspaces_exports = /* @__PURE__ */ __exportAll({
|
|
1329
|
-
down: () => down$
|
|
1330
|
-
up: () => up$
|
|
1278
|
+
down: () => down$12,
|
|
1279
|
+
up: () => up$12
|
|
1331
1280
|
});
|
|
1332
1281
|
/** Workspaces, their members, and the people invited to join. */
|
|
1333
|
-
const TABLES$
|
|
1282
|
+
const TABLES$5 = [
|
|
1334
1283
|
"workspace",
|
|
1335
1284
|
"workspace_member",
|
|
1336
1285
|
"workspace_invitation"
|
|
1337
1286
|
];
|
|
1338
|
-
async function up$
|
|
1287
|
+
async function up$12(database) {
|
|
1339
1288
|
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
1289
|
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
1290
|
await withInvitation(database.schema.createTable("workspace_invitation"), "role").addColumn("workspace_id", "uuid", (column) => column.notNull().references("workspace.id").onDelete("cascade")).execute();
|
|
@@ -1354,37 +1303,37 @@ async function up$6(database) {
|
|
|
1354
1303
|
["workspace_invitation", ["workspace_id", "revoked_at"]]
|
|
1355
1304
|
]);
|
|
1356
1305
|
}
|
|
1357
|
-
async function down$
|
|
1358
|
-
await dropTables(database, TABLES$
|
|
1306
|
+
async function down$12(database) {
|
|
1307
|
+
await dropTables(database, TABLES$5);
|
|
1359
1308
|
}
|
|
1360
1309
|
//#endregion
|
|
1361
1310
|
//#region src/server/db/migrations/003_storage.ts
|
|
1362
1311
|
var _003_storage_exports = /* @__PURE__ */ __exportAll({
|
|
1363
|
-
down: () => down$
|
|
1364
|
-
up: () => up$
|
|
1312
|
+
down: () => down$11,
|
|
1313
|
+
up: () => up$11
|
|
1365
1314
|
});
|
|
1366
1315
|
/** Files in the object store, a workspace's images among them, and how much each workspace uses. */
|
|
1367
|
-
const TABLES$
|
|
1316
|
+
const TABLES$4 = [
|
|
1368
1317
|
"storage_object",
|
|
1369
1318
|
"workspace_storage_usage",
|
|
1370
1319
|
"workspace_image"
|
|
1371
1320
|
];
|
|
1372
|
-
async function up$
|
|
1321
|
+
async function up$11(database) {
|
|
1373
1322
|
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
1323
|
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
1324
|
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
1325
|
}
|
|
1377
|
-
async function down$
|
|
1378
|
-
await dropTables(database, TABLES$
|
|
1326
|
+
async function down$11(database) {
|
|
1327
|
+
await dropTables(database, TABLES$4);
|
|
1379
1328
|
}
|
|
1380
1329
|
//#endregion
|
|
1381
1330
|
//#region src/server/db/migrations/004_documents.ts
|
|
1382
1331
|
var _004_documents_exports = /* @__PURE__ */ __exportAll({
|
|
1383
|
-
down: () => down$
|
|
1384
|
-
up: () => up$
|
|
1332
|
+
down: () => down$10,
|
|
1333
|
+
up: () => up$10
|
|
1385
1334
|
});
|
|
1386
1335
|
/** Documents and what they hold: revisions, versions, images, collaboration rooms, and uploads. */
|
|
1387
|
-
const TABLES$
|
|
1336
|
+
const TABLES$3 = [
|
|
1388
1337
|
"document",
|
|
1389
1338
|
"document_revision",
|
|
1390
1339
|
"document_version",
|
|
@@ -1413,7 +1362,7 @@ async function createUploads(database) {
|
|
|
1413
1362
|
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
1363
|
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
1364
|
}
|
|
1416
|
-
async function up$
|
|
1365
|
+
async function up$10(database) {
|
|
1417
1366
|
await createRevisions(database);
|
|
1418
1367
|
await createRooms(database);
|
|
1419
1368
|
await createUploads(database);
|
|
@@ -1458,24 +1407,24 @@ async function up$4(database) {
|
|
|
1458
1407
|
["upload", ["status", "expires_at"]]
|
|
1459
1408
|
]);
|
|
1460
1409
|
}
|
|
1461
|
-
async function down$
|
|
1462
|
-
await dropTables(database, TABLES$
|
|
1410
|
+
async function down$10(database) {
|
|
1411
|
+
await dropTables(database, TABLES$3);
|
|
1463
1412
|
}
|
|
1464
1413
|
//#endregion
|
|
1465
1414
|
//#region src/server/db/migrations/005_sharing.ts
|
|
1466
1415
|
var _005_sharing_exports = /* @__PURE__ */ __exportAll({
|
|
1467
|
-
down: () => down$
|
|
1468
|
-
up: () => up$
|
|
1416
|
+
down: () => down$9,
|
|
1417
|
+
up: () => up$9
|
|
1469
1418
|
});
|
|
1470
1419
|
/** Who a document is shared with: people, invitations, links, and the invitations budget. */
|
|
1471
|
-
const TABLES$
|
|
1420
|
+
const TABLES$2 = [
|
|
1472
1421
|
"document_grant",
|
|
1473
1422
|
"document_invitation",
|
|
1474
1423
|
"invitation_continuation",
|
|
1475
1424
|
"document_share",
|
|
1476
1425
|
"invitation_send"
|
|
1477
1426
|
];
|
|
1478
|
-
async function up$
|
|
1427
|
+
async function up$9(database) {
|
|
1479
1428
|
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
1429
|
await withInvitation(database.schema.createTable("document_invitation"), "permission").addColumn("document_id", "uuid", (column) => column.notNull().references("document.id").onDelete("cascade")).execute();
|
|
1481
1430
|
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 +1456,23 @@ async function up$3(database) {
|
|
|
1507
1456
|
["invitation_send", ["email_normalized", "sent_at"]]
|
|
1508
1457
|
]);
|
|
1509
1458
|
}
|
|
1510
|
-
async function down$
|
|
1511
|
-
await dropTables(database, TABLES$
|
|
1459
|
+
async function down$9(database) {
|
|
1460
|
+
await dropTables(database, TABLES$2);
|
|
1512
1461
|
}
|
|
1513
1462
|
//#endregion
|
|
1514
1463
|
//#region src/server/db/migrations/006_operations.ts
|
|
1515
1464
|
var _006_operations_exports = /* @__PURE__ */ __exportAll({
|
|
1516
|
-
down: () => down$
|
|
1517
|
-
up: () => up$
|
|
1465
|
+
down: () => down$8,
|
|
1466
|
+
up: () => up$8
|
|
1518
1467
|
});
|
|
1519
1468
|
/** Running the deployment: the email outbox, enrollment, reports, and the administrators' log. */
|
|
1520
|
-
const TABLES = [
|
|
1469
|
+
const TABLES$1 = [
|
|
1521
1470
|
"transactional_email",
|
|
1522
1471
|
"enrollment",
|
|
1523
1472
|
"document_report",
|
|
1524
1473
|
"admin_audit_event"
|
|
1525
1474
|
];
|
|
1526
|
-
async function up$
|
|
1475
|
+
async function up$8(database) {
|
|
1527
1476
|
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
1477
|
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
1478
|
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 +1549,24 @@ async function up$2(database) {
|
|
|
1600
1549
|
["admin_audit_event", ["created_at"]]
|
|
1601
1550
|
]);
|
|
1602
1551
|
}
|
|
1603
|
-
async function down$
|
|
1604
|
-
await dropTables(database, TABLES);
|
|
1552
|
+
async function down$8(database) {
|
|
1553
|
+
await dropTables(database, TABLES$1);
|
|
1605
1554
|
}
|
|
1606
1555
|
//#endregion
|
|
1607
1556
|
//#region src/server/db/migrations/007_trash.ts
|
|
1608
1557
|
var _007_trash_exports = /* @__PURE__ */ __exportAll({
|
|
1609
|
-
down: () => down$
|
|
1610
|
-
up: () => up$
|
|
1558
|
+
down: () => down$7,
|
|
1559
|
+
up: () => up$7
|
|
1611
1560
|
});
|
|
1612
1561
|
/**
|
|
1613
1562
|
* Trash: who deleted a document, and who deleted it forever, when, and the storage that took off
|
|
1614
1563
|
* its workspace's usage while its files wait out the grace before cleanup destroys them.
|
|
1615
1564
|
*/
|
|
1616
|
-
async function up$
|
|
1565
|
+
async function up$7(database) {
|
|
1617
1566
|
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
1567
|
await addIndexes(database, [["document", ["workspace_id", "deleted_at desc"]], ["document", ["purged_at"]]]);
|
|
1619
1568
|
}
|
|
1620
|
-
async function down$
|
|
1569
|
+
async function down$7(database) {
|
|
1621
1570
|
await database.schema.dropIndex("document_purged_at_idx").execute();
|
|
1622
1571
|
await database.schema.dropIndex("document_workspace_id_deleted_at_idx").execute();
|
|
1623
1572
|
await database.schema.alterTable("document").dropColumn("purged_bytes").dropColumn("purged_by").dropColumn("purged_at").dropColumn("deleted_by").execute();
|
|
@@ -1625,15 +1574,217 @@ async function down$1(database) {
|
|
|
1625
1574
|
//#endregion
|
|
1626
1575
|
//#region src/server/db/migrations/008_terms.ts
|
|
1627
1576
|
var _008_terms_exports = /* @__PURE__ */ __exportAll({
|
|
1577
|
+
down: () => down$6,
|
|
1578
|
+
up: () => up$6
|
|
1579
|
+
});
|
|
1580
|
+
/** Which version of the deployment's terms each account accepted, and when. */
|
|
1581
|
+
async function up$6(database) {
|
|
1582
|
+
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
|
+
}
|
|
1584
|
+
async function down$6(database) {
|
|
1585
|
+
await database.schema.dropTable("terms_acceptance").execute();
|
|
1586
|
+
}
|
|
1587
|
+
//#endregion
|
|
1588
|
+
//#region src/server/db/migrations/009_access_tokens.ts
|
|
1589
|
+
var _009_access_tokens_exports = /* @__PURE__ */ __exportAll({
|
|
1590
|
+
down: () => down$5,
|
|
1591
|
+
up: () => up$5
|
|
1592
|
+
});
|
|
1593
|
+
/**
|
|
1594
|
+
* Personal access tokens, kept by Better Auth's API-key plugin in the table it would build
|
|
1595
|
+
* itself. Cloud builds it here instead, since Better Auth's tables are built only once and a
|
|
1596
|
+
* deployment that has them gains this one as any other migration; Better Auth's migration then
|
|
1597
|
+
* leaves this plugin's table out (`createBetterAuthAdapter`). It holds each token's SHA-256
|
|
1598
|
+
* digest, never the token.
|
|
1599
|
+
*/
|
|
1600
|
+
async function up$5(database) {
|
|
1601
|
+
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
|
+
await addIndexes(database, [
|
|
1603
|
+
["apikey", ["config_id"]],
|
|
1604
|
+
["apikey", ["reference_id"]],
|
|
1605
|
+
["apikey", ["key"]]
|
|
1606
|
+
]);
|
|
1607
|
+
}
|
|
1608
|
+
async function down$5(database) {
|
|
1609
|
+
await database.schema.dropTable("apikey").execute();
|
|
1610
|
+
}
|
|
1611
|
+
//#endregion
|
|
1612
|
+
//#region src/server/db/migrations/010_storage_limit_notices.ts
|
|
1613
|
+
var _010_storage_limit_notices_exports = /* @__PURE__ */ __exportAll({
|
|
1614
|
+
down: () => down$4,
|
|
1615
|
+
up: () => up$4
|
|
1616
|
+
});
|
|
1617
|
+
/** Every kind of transactional email, as of this migration. */
|
|
1618
|
+
const EMAIL_KINDS$1 = [
|
|
1619
|
+
"document-invitation",
|
|
1620
|
+
"workspace-invitation",
|
|
1621
|
+
"enrollment-requested",
|
|
1622
|
+
"admin-enrollment-notification",
|
|
1623
|
+
"enrollment-approved",
|
|
1624
|
+
"enrollment-rejected",
|
|
1625
|
+
"enrollment-revoked",
|
|
1626
|
+
"email-verification",
|
|
1627
|
+
"password-reset",
|
|
1628
|
+
"password-changed",
|
|
1629
|
+
"email-change-requested",
|
|
1630
|
+
"new-sign-in",
|
|
1631
|
+
"two-step-changed",
|
|
1632
|
+
"document-report"
|
|
1633
|
+
];
|
|
1634
|
+
/**
|
|
1635
|
+
* The accounts told their storage is full, so each is told once each time it fills, not on every
|
|
1636
|
+
* cleanup pass; a row goes once the account holds less than its plan allows again. Email gains
|
|
1637
|
+
* the kind that tells them, which the previous release never writes.
|
|
1638
|
+
*/
|
|
1639
|
+
async function up$4(database) {
|
|
1640
|
+
await database.schema.createTable("storage_limit_notice").addColumn("user_id", "text", (column) => column.primaryKey()).addColumn("notified_at", "timestamptz", now).execute();
|
|
1641
|
+
await database.schema.alterTable("transactional_email").dropConstraint("transactional_email_kind_check").execute();
|
|
1642
|
+
await addChecks(database, [[
|
|
1643
|
+
"transactional_email",
|
|
1644
|
+
"kind",
|
|
1645
|
+
[...EMAIL_KINDS$1, "storage-limit-reached"]
|
|
1646
|
+
]]);
|
|
1647
|
+
}
|
|
1648
|
+
async function down$4(database) {
|
|
1649
|
+
await database.schema.alterTable("transactional_email").dropConstraint("transactional_email_kind_check").execute();
|
|
1650
|
+
await addChecks(database, [[
|
|
1651
|
+
"transactional_email",
|
|
1652
|
+
"kind",
|
|
1653
|
+
EMAIL_KINDS$1
|
|
1654
|
+
]]);
|
|
1655
|
+
await database.schema.dropTable("storage_limit_notice").execute();
|
|
1656
|
+
}
|
|
1657
|
+
//#endregion
|
|
1658
|
+
//#region src/server/db/migrations/011_account_ids.ts
|
|
1659
|
+
var _011_account_ids_exports = /* @__PURE__ */ __exportAll({
|
|
1660
|
+
contracts: () => contracts,
|
|
1661
|
+
down: () => down$3,
|
|
1662
|
+
up: () => up$3
|
|
1663
|
+
});
|
|
1664
|
+
/** The tables that named accounts by `uuid`, unlike every other table Cloud builds. */
|
|
1665
|
+
const TABLES = [
|
|
1666
|
+
"mfa_assurance",
|
|
1667
|
+
"sign_in",
|
|
1668
|
+
"user_picture"
|
|
1669
|
+
];
|
|
1670
|
+
/**
|
|
1671
|
+
* Names accounts by `text` in the last tables that used `uuid`, as `schema.ts` sets for every
|
|
1672
|
+
* table Cloud builds. The previous release reads and writes the same strings either way, so it
|
|
1673
|
+
* keeps working while this runs.
|
|
1674
|
+
*/
|
|
1675
|
+
const contracts = TABLES.map((table) => `${table}.user_id`);
|
|
1676
|
+
async function up$3(database) {
|
|
1677
|
+
for (const table of TABLES) await database.schema.alterTable(table).alterColumn("user_id", (column) => column.setDataType("text")).execute();
|
|
1678
|
+
}
|
|
1679
|
+
async function down$3(database) {
|
|
1680
|
+
for (const table of TABLES) await database.schema.alterTable(table).alterColumn("user_id", (column) => column.setDataType(sql`uuid using user_id::uuid`)).execute();
|
|
1681
|
+
}
|
|
1682
|
+
//#endregion
|
|
1683
|
+
//#region src/server/db/migrations/012_email_locales.ts
|
|
1684
|
+
var _012_email_locales_exports = /* @__PURE__ */ __exportAll({
|
|
1685
|
+
down: () => down$2,
|
|
1686
|
+
up: () => up$2
|
|
1687
|
+
});
|
|
1688
|
+
/** Whether Better Auth's `user` table exists yet, which it doesn't before a server first starts. */
|
|
1689
|
+
async function hasUserTable(database) {
|
|
1690
|
+
return (await database.introspection.getTables()).some((table) => table.name === "user");
|
|
1691
|
+
}
|
|
1692
|
+
/**
|
|
1693
|
+
* The language Cloud writes to each account in, and the one each queued email is written in,
|
|
1694
|
+
* settled when it's queued so a retry reads the same. Email from before this migration is
|
|
1695
|
+
* English, as it always was.
|
|
1696
|
+
*
|
|
1697
|
+
* `user.locale` is a Better Auth field, so a new database gets it from Better Auth's own schema,
|
|
1698
|
+
* built after Cloud's migrations. A database that already has that schema never builds it again,
|
|
1699
|
+
* so it gets the column here; accounts from before it have no language and read English.
|
|
1700
|
+
*/
|
|
1701
|
+
async function up$2(database) {
|
|
1702
|
+
await database.schema.alterTable("transactional_email").addColumn("locale", "text", (column) => column.notNull().defaultTo("en")).execute();
|
|
1703
|
+
if (await hasUserTable(database)) await database.schema.alterTable("user").addColumn("locale", "text", (column) => column.ifNotExists()).execute();
|
|
1704
|
+
}
|
|
1705
|
+
async function down$2(database) {
|
|
1706
|
+
await database.schema.alterTable("transactional_email").dropColumn("locale").execute();
|
|
1707
|
+
}
|
|
1708
|
+
//#endregion
|
|
1709
|
+
//#region src/server/db/migrations/013_document_block_emails.ts
|
|
1710
|
+
var _013_document_block_emails_exports = /* @__PURE__ */ __exportAll({
|
|
1711
|
+
DOCUMENT_BLOCK_EMAIL_KINDS: () => DOCUMENT_BLOCK_EMAIL_KINDS,
|
|
1712
|
+
down: () => down$1,
|
|
1713
|
+
up: () => up$1
|
|
1714
|
+
});
|
|
1715
|
+
/** Every kind of transactional email before this migration. */
|
|
1716
|
+
const EMAIL_KINDS = [
|
|
1717
|
+
"document-invitation",
|
|
1718
|
+
"workspace-invitation",
|
|
1719
|
+
"enrollment-requested",
|
|
1720
|
+
"admin-enrollment-notification",
|
|
1721
|
+
"enrollment-approved",
|
|
1722
|
+
"enrollment-rejected",
|
|
1723
|
+
"enrollment-revoked",
|
|
1724
|
+
"email-verification",
|
|
1725
|
+
"password-reset",
|
|
1726
|
+
"password-changed",
|
|
1727
|
+
"email-change-requested",
|
|
1728
|
+
"new-sign-in",
|
|
1729
|
+
"two-step-changed",
|
|
1730
|
+
"document-report",
|
|
1731
|
+
"storage-limit-reached"
|
|
1732
|
+
];
|
|
1733
|
+
/** Every kind of transactional email once this migration has run. */
|
|
1734
|
+
const DOCUMENT_BLOCK_EMAIL_KINDS = [
|
|
1735
|
+
...EMAIL_KINDS,
|
|
1736
|
+
"document-blocked",
|
|
1737
|
+
"document-restored"
|
|
1738
|
+
];
|
|
1739
|
+
/**
|
|
1740
|
+
* Email gains the kinds that tell a workspace's owner an administrator blocked one of its
|
|
1741
|
+
* documents, and that it is back, which the previous release never writes.
|
|
1742
|
+
*/
|
|
1743
|
+
async function up$1(database) {
|
|
1744
|
+
await replaceChecks(database, "widen", [[
|
|
1745
|
+
"transactional_email",
|
|
1746
|
+
"kind",
|
|
1747
|
+
DOCUMENT_BLOCK_EMAIL_KINDS
|
|
1748
|
+
]]);
|
|
1749
|
+
}
|
|
1750
|
+
async function down$1(database) {
|
|
1751
|
+
await replaceChecks(database, "narrow", [[
|
|
1752
|
+
"transactional_email",
|
|
1753
|
+
"kind",
|
|
1754
|
+
EMAIL_KINDS
|
|
1755
|
+
]]);
|
|
1756
|
+
}
|
|
1757
|
+
//#endregion
|
|
1758
|
+
//#region src/server/db/migrations/014_report_replies.ts
|
|
1759
|
+
var _014_report_replies_exports = /* @__PURE__ */ __exportAll({
|
|
1628
1760
|
down: () => down,
|
|
1629
1761
|
up: () => up
|
|
1630
1762
|
});
|
|
1631
|
-
/**
|
|
1763
|
+
/**
|
|
1764
|
+
* Whoever reports a document and leaves an address hears that the report arrived and what the
|
|
1765
|
+
* administrators decided. A report keeps the language its reporter's browser asked for, since a
|
|
1766
|
+
* guest has no account to say it, and email gains the two kinds, which the previous release
|
|
1767
|
+
* never writes.
|
|
1768
|
+
*/
|
|
1632
1769
|
async function up(database) {
|
|
1633
|
-
await database.schema.
|
|
1770
|
+
await database.schema.alterTable("document_report").addColumn("reply_locale", "text").execute();
|
|
1771
|
+
await replaceChecks(database, "widen", [[
|
|
1772
|
+
"transactional_email",
|
|
1773
|
+
"kind",
|
|
1774
|
+
[
|
|
1775
|
+
...DOCUMENT_BLOCK_EMAIL_KINDS,
|
|
1776
|
+
"document-report-received",
|
|
1777
|
+
"document-report-decided"
|
|
1778
|
+
]
|
|
1779
|
+
]]);
|
|
1634
1780
|
}
|
|
1635
1781
|
async function down(database) {
|
|
1636
|
-
await database
|
|
1782
|
+
await replaceChecks(database, "narrow", [[
|
|
1783
|
+
"transactional_email",
|
|
1784
|
+
"kind",
|
|
1785
|
+
DOCUMENT_BLOCK_EMAIL_KINDS
|
|
1786
|
+
]]);
|
|
1787
|
+
await database.schema.alterTable("document_report").dropColumn("reply_locale").execute();
|
|
1637
1788
|
}
|
|
1638
1789
|
//#endregion
|
|
1639
1790
|
//#region src/server/db/migrate.ts
|
|
@@ -1645,7 +1796,13 @@ const migrations = {
|
|
|
1645
1796
|
"005_sharing": _005_sharing_exports,
|
|
1646
1797
|
"006_operations": _006_operations_exports,
|
|
1647
1798
|
"007_trash": _007_trash_exports,
|
|
1648
|
-
"008_terms": _008_terms_exports
|
|
1799
|
+
"008_terms": _008_terms_exports,
|
|
1800
|
+
"009_access_tokens": _009_access_tokens_exports,
|
|
1801
|
+
"010_storage_limit_notices": _010_storage_limit_notices_exports,
|
|
1802
|
+
"011_account_ids": _011_account_ids_exports,
|
|
1803
|
+
"012_email_locales": _012_email_locales_exports,
|
|
1804
|
+
"013_document_block_emails": _013_document_block_emails_exports,
|
|
1805
|
+
"014_report_replies": _014_report_replies_exports
|
|
1649
1806
|
};
|
|
1650
1807
|
/** Cloud's migrations, in order. */
|
|
1651
1808
|
var CloudMigrationProvider = class {
|
|
@@ -1713,6 +1870,6 @@ async function listen(fetch, port, hostname) {
|
|
|
1713
1870
|
};
|
|
1714
1871
|
}
|
|
1715
1872
|
//#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,
|
|
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, communityThumbnailParams, createRelayClientAssembler, decodeRelayClientFrame, decodeRoomUpdate, defaultRelayURL, deletedPrefixSchema, documentDownloadSchema, documentInvitationParams, documentKindSchema, documentParams, documentPermissionSchema, documentShareParams, documentSummarySchema, documentUserParams, documentVersionParams, encodeSyncReply, httpURLSchema, idParams, invitationContinuationParams, invitationParams, isEditorVersionAtLeast, listen, lockForTransaction, migrateCloudDatabase, migrateToLatest, parseCloudDiscovery, parseCloudServerConfig, parseCommitImageUploads, parseCommitUpload, parseCreateDocument, parseCreateServicesToken, parseCreateUpload, parseRequestImageLinks, parseRequestImageUploads, parseUsageQuery, pictureParams, presenceName, relayServerMessages, requestImageLinksSchema, serviceCatalogSchema, servicesTokenClaimsSchema, shareParams, staticEntitlementsSchema, staticEntitlementsTOMLSchema, uploadParams, validatedJSON, validatedQuery, workspaceInvitationParams, workspaceMemberParams, workspaceParams };
|
|
1717
1874
|
|
|
1718
1875
|
//# sourceMappingURL=listen.mjs.map
|