@open-pencil/cloud 0.17.0-beta.4 → 0.17.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/bin/server.mjs +1 -1
- package/dist/bin/server.mjs.map +1 -1
- package/dist/bin/services.mjs +1 -1
- package/dist/bin/services.mjs.map +1 -1
- package/dist/client.d.ts +783 -47
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1651 -382
- package/dist/client.js.map +1 -1
- package/dist/contract.d.ts +2 -2
- package/dist/contract.js +2 -2
- package/dist/contract2.js +701 -45
- package/dist/contract2.js.map +1 -1
- package/dist/email.d.ts +2138 -34
- package/dist/email.d.ts.map +1 -1
- package/dist/email.js +4343 -306
- package/dist/email.js.map +1 -1
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +61 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +1338 -44
- package/dist/index.d.ts.map +1 -1
- package/dist/index2.d.ts +45 -0
- package/dist/index2.d.ts.map +1 -0
- package/dist/listen.mjs +958 -340
- package/dist/listen.mjs.map +1 -1
- package/dist/runtime-cloudflare.d.ts +93 -0
- package/dist/runtime-cloudflare.d.ts.map +1 -0
- package/dist/runtime-cloudflare.js +18032 -0
- package/dist/runtime-cloudflare.js.map +1 -0
- package/dist/runtime-node.d.mts +12615 -5249
- package/dist/runtime-node.d.mts.map +1 -1
- package/dist/server.d.ts +17367 -8567
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +13587 -7333
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +11601 -5401
- package/dist/server.mjs.map +1 -1
- package/dist/server2.mjs +84 -62
- package/dist/server2.mjs.map +1 -1
- package/package.json +31 -5
- package/src/admin/api/routes.ts +263 -190
- package/src/admin/audit/service.ts +11 -3
- package/src/admin/bootstrap.ts +86 -0
- package/src/admin/documents/service.ts +195 -10
- package/src/admin/email/service.ts +2 -1
- package/src/admin/enrollment/email.ts +17 -3
- package/src/admin/enrollment/service.ts +71 -10
- package/src/admin/errors.ts +5 -0
- package/src/admin/index.ts +1 -0
- package/src/admin/reports/service.ts +15 -3
- package/src/admin/schema.ts +6 -5
- package/src/admin/users/service.ts +173 -16
- package/src/client/api.ts +52 -473
- package/src/client/auth/client.ts +22 -3
- package/src/client/comments.ts +205 -0
- package/src/client/community.ts +40 -0
- package/src/client/device-authorization.ts +4 -20
- package/src/client/discovery.ts +39 -11
- package/src/client/documents.ts +160 -0
- package/src/client/files/archive.ts +60 -0
- package/src/client/files/checksum.ts +7 -0
- package/src/client/files/download.ts +122 -0
- package/src/client/files/images.ts +89 -0
- package/src/client/files/index.ts +15 -0
- package/src/client/files/objects.ts +173 -0
- package/src/client/files/save.ts +79 -0
- package/src/client/index.ts +4 -0
- package/src/client/portal/account.ts +73 -3
- package/src/client/portal/administration.ts +52 -5
- package/src/client/portal/request.ts +6 -2
- package/src/client/response.ts +21 -0
- package/src/client/schema.ts +8 -0
- package/src/client/services.ts +23 -18
- package/src/client/sharing.ts +262 -0
- package/src/client/tour.ts +44 -0
- package/src/client/versions.ts +110 -0
- package/src/contract/account.ts +111 -11
- package/src/contract/admin/index.ts +48 -3
- package/src/contract/billing.ts +235 -0
- package/src/contract/collaboration.ts +5 -0
- package/src/contract/comments.ts +223 -0
- package/src/contract/community.ts +60 -0
- package/src/contract/discovery.ts +94 -5
- package/src/contract/entitlements.ts +10 -0
- package/src/contract/index.ts +64 -5
- package/src/contract/links.ts +62 -4
- package/src/contract/locale.ts +27 -0
- package/src/contract/portal.ts +12 -1
- package/src/contract/relay.ts +3 -1
- package/src/contract/routes.ts +10 -0
- package/src/contract/services.ts +62 -20
- package/src/contract/workspaces.ts +5 -0
- package/src/email/i18n.ts +174 -0
- package/src/email/index.ts +13 -2
- package/src/email/locales/ar.json +169 -0
- package/src/email/locales/de.json +169 -0
- package/src/email/locales/es.json +169 -0
- package/src/email/locales/fr.json +169 -0
- package/src/email/locales/it.json +169 -0
- package/src/email/locales/ja.json +169 -0
- package/src/email/locales/pl.json +169 -0
- package/src/email/locales/pt-br.json +169 -0
- package/src/email/locales/ru.json +169 -0
- package/src/email/locales/zh-cn.json +169 -0
- package/src/email/messages.ts +235 -0
- package/src/email/render.ts +160 -276
- package/src/email/samples.ts +142 -0
- package/src/email/schema.ts +98 -8
- package/src/email/templates/BrandEmail.vue +56 -0
- package/src/email/templates/CommentNotification.vue +39 -0
- package/src/email/templates/DocumentBlocked.vue +45 -0
- package/src/email/templates/DocumentInvitation.vue +24 -0
- package/src/email/templates/DocumentReport.vue +32 -0
- package/src/email/templates/DocumentReportDecided.vue +36 -0
- package/src/email/templates/DocumentReportReceived.vue +18 -0
- package/src/email/templates/DocumentRestored.vue +24 -0
- package/src/email/templates/EmailChangeRequested.vue +24 -0
- package/src/email/templates/EmailRoot.vue +19 -0
- package/src/email/templates/EmailText.vue +9 -0
- package/src/email/templates/EmailVerification.vue +38 -0
- package/src/email/templates/EnrollmentInvitation.vue +53 -0
- package/src/email/templates/EnrollmentNotification.vue +24 -0
- package/src/email/templates/EnrollmentUpdate.vue +52 -0
- package/src/email/templates/NewSignIn.vue +37 -0
- package/src/email/templates/PasswordChanged.vue +22 -0
- package/src/email/templates/PasswordReset.vue +23 -0
- package/src/email/templates/StorageLimitReached.vue +28 -0
- package/src/email/templates/TwoStepChanged.vue +47 -0
- package/src/email/templates/WaitlistConfirmation.vue +29 -0
- package/src/email/templates/WorkspaceInvitation.vue +28 -0
- package/src/email/templates/brand.ts +15 -61
- package/src/email/templates/localization.ts +17 -0
- package/src/errors/index.ts +6 -0
- package/src/{server/errors → errors}/posthog.ts +28 -4
- package/src/global.d.ts +7 -0
- package/src/runtime/cloudflare/email.ts +2 -0
- package/src/runtime/cloudflare/relay/index.ts +28 -7
- package/src/runtime/cloudflare/tsconfig.json +2 -1
- package/src/runtime/cloudflare/worker.ts +14 -1
- package/src/runtime/cloudflare/xml.ts +12 -0
- package/src/runtime/node/admin.ts +51 -47
- package/src/runtime/node/cleanup.ts +5 -1
- package/src/runtime/node/email/runtime.ts +1 -0
- package/src/runtime/node/email/transport.ts +14 -10
- package/src/runtime/node/main.ts +1 -1
- package/src/runtime/node/server.ts +20 -4
- package/src/runtime/node/services/main.ts +1 -1
- package/src/runtime/posthog/errors.ts +5 -2
- package/src/runtime/s3/objects.ts +17 -0
- package/src/runtime/site/community.ts +101 -0
- package/src/runtime/site/server.ts +17 -1
- package/src/server/account/actions.ts +3 -1
- package/src/server/account/deletion.ts +40 -4
- package/src/server/account/routes.ts +305 -253
- package/src/server/account/tokens.ts +57 -0
- package/src/server/api/router.ts +44 -6
- package/src/server/app/checks.ts +89 -0
- package/src/server/app/cors.ts +44 -0
- package/src/server/app/editors.ts +20 -0
- package/src/server/app/index.ts +128 -0
- package/src/server/app/indexing.ts +40 -0
- package/src/server/app/limiters.ts +53 -0
- package/src/server/app/routes.ts +123 -0
- package/src/server/app/services.ts +219 -0
- package/src/server/auth/access-control.ts +13 -8
- package/src/server/auth/access-tokens.ts +62 -0
- package/src/server/auth/account.ts +13 -12
- package/src/server/auth/activity.ts +7 -2
- package/src/server/auth/adapter.ts +36 -3
- package/src/server/auth/email.ts +33 -18
- package/src/server/auth/endpoints.ts +4 -0
- package/src/server/auth/enrollment.ts +116 -0
- package/src/server/auth/factory.ts +165 -189
- package/src/server/auth/index.ts +1 -1
- package/src/server/auth/logger.ts +23 -0
- package/src/server/auth/methods.ts +162 -0
- package/src/server/auth/mfa-assurance.ts +190 -2
- package/src/server/auth/passwords.ts +43 -0
- package/src/server/auth/rate-limit.ts +31 -0
- package/src/server/auth/runtime.ts +19 -5
- package/src/server/auth/session.ts +2 -0
- package/src/server/auth/social-providers.ts +70 -24
- package/src/server/billing/index.ts +8 -0
- package/src/server/billing/notify.ts +55 -0
- package/src/server/billing/routes.ts +27 -0
- package/src/server/billing/seats.ts +17 -0
- package/src/server/billing/tokens.ts +37 -0
- package/src/server/cleanup/configured.ts +16 -3
- package/src/server/cleanup/documents.ts +5 -2
- package/src/server/cleanup/revisions.ts +6 -3
- package/src/server/cleanup/uploads.ts +2 -1
- package/src/server/cleanup/worker.ts +10 -1
- package/src/server/collaboration/relay/connection.ts +7 -2
- package/src/server/collaboration/relay/hub.ts +80 -166
- package/src/server/collaboration/relay/room.ts +154 -0
- package/src/server/collaboration/routes.ts +8 -5
- package/src/server/collaboration/service.ts +21 -2
- package/src/server/comments/index.ts +9 -0
- package/src/server/comments/notify.ts +277 -0
- package/src/server/comments/routes.ts +352 -0
- package/src/server/comments/rows.ts +249 -0
- package/src/server/comments/service.ts +570 -0
- package/src/server/community/index.ts +2 -0
- package/src/server/community/routes.ts +93 -0
- package/src/server/community/service.ts +134 -0
- package/src/server/config/deployment.ts +35 -10
- package/src/server/config/index.ts +2 -2
- package/src/server/config/public.ts +25 -6
- package/src/server/config/schema.ts +53 -293
- package/src/server/config/toml/schema.ts +330 -0
- package/src/server/db/index.ts +3 -1
- package/src/server/db/migrate.ts +33 -1
- package/src/server/db/migrations/009_access_tokens.ts +47 -0
- package/src/server/db/migrations/010_storage_limit_notices.ts +50 -0
- package/src/server/db/migrations/011_account_ids.ts +30 -0
- package/src/server/db/migrations/012_email_locales.ts +34 -0
- package/src/server/db/migrations/013_document_block_emails.ts +40 -0
- package/src/server/db/migrations/014_report_replies.ts +28 -0
- package/src/server/db/migrations/015_comments.ts +57 -0
- package/src/server/db/migrations/016_comment_notifications.ts +76 -0
- package/src/server/db/migrations/017_invitation_emails.ts +19 -0
- package/src/server/db/migrations/018_enrollment_source.ts +17 -0
- package/src/server/db/migrations/schema.ts +26 -1
- package/src/server/db/tables.ts +122 -3
- package/src/server/db/users.ts +22 -0
- package/src/server/documents/access.ts +17 -0
- package/src/server/documents/images.ts +6 -1
- package/src/server/documents/index.ts +1 -1
- package/src/server/documents/limits.ts +7 -1
- package/src/server/documents/routes.ts +12 -12
- package/src/server/documents/service.ts +31 -407
- package/src/server/documents/summary.ts +15 -0
- package/src/server/documents/uploads.ts +450 -0
- package/src/server/documents/versions/routes.ts +7 -8
- package/src/server/documents/versions/service.ts +86 -26
- package/src/server/email/invitations.ts +1 -0
- package/src/server/email/service.ts +39 -6
- package/src/server/email/types.ts +13 -0
- package/src/server/errors/index.ts +49 -12
- package/src/server/index.ts +27 -6
- package/src/server/internal/routes.ts +8 -2
- package/src/server/internal/service.ts +10 -0
- package/src/server/invitations/budget.ts +3 -1
- package/src/server/invitations/index.ts +1 -0
- package/src/server/invitations/links.ts +6 -0
- package/src/server/invitations/types.ts +5 -1
- package/src/server/objects/types.ts +5 -0
- package/src/server/pictures/service.ts +3 -1
- package/src/server/policy/configured.ts +9 -3
- package/src/server/policy/database.ts +13 -2
- package/src/server/policy/policy.ts +39 -12
- package/src/server/policy/service.ts +71 -52
- package/src/server/policy/storage.ts +33 -0
- package/src/server/policy/workspace.ts +5 -2
- package/src/server/quota/index.ts +6 -0
- package/src/server/quota/notices.ts +121 -0
- package/src/server/quota/storage.ts +5 -0
- package/src/server/rate-limit/middleware.ts +4 -0
- package/src/server/reports/index.ts +1 -0
- package/src/server/reports/replies.ts +55 -0
- package/src/server/reports/routes.ts +5 -3
- package/src/server/reports/service.ts +27 -3
- package/src/server/services/routes.ts +2 -2
- package/src/server/sharing/capabilities/service.ts +3 -4
- package/src/server/sharing/document-routes.ts +3 -3
- package/src/server/sharing/invitations/service.ts +17 -8
- package/src/server/sharing/routes.ts +15 -15
- package/src/server/validation.ts +35 -24
- package/src/server/workspaces/members.ts +57 -31
- package/src/server/workspaces/repository.ts +23 -12
- package/src/server/workspaces/routes.ts +8 -8
- package/src/services/app.ts +31 -22
- package/src/services/config.ts +48 -8
- package/src/services/metering.ts +15 -27
- package/src/services/usage.ts +6 -14
- package/src/email/templates/document-invitation.ts +0 -35
- package/src/email/templates/enrollment.ts +0 -27
- package/src/email/templates/layout.ts +0 -18
- package/src/server/app.ts +0 -453
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { cloudEditorVersionSchema } from '#cloud/contract'
|
|
2
|
+
import { deletedPrefixSchema } from '#cloud/server/config/schema'
|
|
3
|
+
import { staticEntitlementsTOMLSchema } from '#cloud/server/policy/schema'
|
|
4
|
+
import * as v from 'valibot'
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* The deployment file, `openpencil-cloud.toml`: what an operator writes, with secrets named by the
|
|
8
|
+
* environment variables that hold them. `../deployment.ts` reads it into the server's configuration.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** PostHog's EU Cloud ingestion host, where OpenPencil's own project is. */
|
|
12
|
+
const POSTHOG_DEFAULT_HOST = 'https://eu.i.posthog.com'
|
|
13
|
+
|
|
14
|
+
const DEFAULT_SECRET_NAMES = {
|
|
15
|
+
databaseURL: 'DATABASE_URL',
|
|
16
|
+
authSecret: 'BETTER_AUTH_SECRET',
|
|
17
|
+
googleClientId: 'GOOGLE_CLIENT_ID',
|
|
18
|
+
googleClientSecret: 'GOOGLE_CLIENT_SECRET',
|
|
19
|
+
applePrivateKey: 'APPLE_PRIVATE_KEY',
|
|
20
|
+
githubClientSecret: 'GITHUB_CLIENT_SECRET',
|
|
21
|
+
s3AccessKeyId: 'S3_ACCESS_KEY_ID',
|
|
22
|
+
s3SecretAccessKey: 'S3_SECRET_ACCESS_KEY',
|
|
23
|
+
s3SessionToken: 'S3_SESSION_TOKEN',
|
|
24
|
+
smtpUser: 'OPENPENCIL_CLOUD_SMTP_USER',
|
|
25
|
+
smtpPassword: 'OPENPENCIL_CLOUD_SMTP_PASSWORD',
|
|
26
|
+
turnstileSecretKey: 'TURNSTILE_SECRET_KEY',
|
|
27
|
+
servicesSigningKey: 'OPENPENCIL_CLOUD_SERVICES_SIGNING_KEY',
|
|
28
|
+
internalServiceToken: 'OPENPENCIL_CLOUD_SERVICE_TOKEN',
|
|
29
|
+
posthogProjectAPIKey: 'POSTHOG_PROJECT_API_KEY'
|
|
30
|
+
} as const
|
|
31
|
+
|
|
32
|
+
const urlSchema = v.pipe(v.string(), v.url())
|
|
33
|
+
const textSchema = v.pipe(v.string(), v.trim(), v.minLength(1))
|
|
34
|
+
const positiveIntegerSchema = v.pipe(v.number(), v.integer(), v.minValue(1))
|
|
35
|
+
const secretReferenceSchema = v.strictObject({ from_env: textSchema })
|
|
36
|
+
const configurableTextSchema = v.union([textSchema, secretReferenceSchema])
|
|
37
|
+
const defaultReference = (name: string) => v.optional(secretReferenceSchema, { from_env: name })
|
|
38
|
+
|
|
39
|
+
const providerSchema = v.strictObject({
|
|
40
|
+
google: v.optional(
|
|
41
|
+
v.strictObject({
|
|
42
|
+
client_id: v.optional(configurableTextSchema, {
|
|
43
|
+
from_env: DEFAULT_SECRET_NAMES.googleClientId
|
|
44
|
+
}),
|
|
45
|
+
client_secret: defaultReference(DEFAULT_SECRET_NAMES.googleClientSecret)
|
|
46
|
+
})
|
|
47
|
+
),
|
|
48
|
+
apple: v.optional(
|
|
49
|
+
v.strictObject({
|
|
50
|
+
client_id: textSchema,
|
|
51
|
+
team_id: textSchema,
|
|
52
|
+
key_id: textSchema,
|
|
53
|
+
private_key: defaultReference(DEFAULT_SECRET_NAMES.applePrivateKey),
|
|
54
|
+
app_bundle_identifier: v.optional(textSchema)
|
|
55
|
+
})
|
|
56
|
+
),
|
|
57
|
+
github: v.optional(
|
|
58
|
+
v.strictObject({
|
|
59
|
+
client_id: configurableTextSchema,
|
|
60
|
+
client_secret: defaultReference(DEFAULT_SECRET_NAMES.githubClientSecret)
|
|
61
|
+
})
|
|
62
|
+
)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
/** Where replies go, when someone reads the email and writes back; `from` otherwise. */
|
|
66
|
+
const replyToSchema = v.optional(v.pipe(v.string(), v.email()))
|
|
67
|
+
|
|
68
|
+
const emailSchema = v.optional(
|
|
69
|
+
v.variant('transport', [
|
|
70
|
+
v.strictObject({ transport: v.literal('none') }),
|
|
71
|
+
v.strictObject({
|
|
72
|
+
transport: v.literal('smtp'),
|
|
73
|
+
from: textSchema,
|
|
74
|
+
reply_to: replyToSchema,
|
|
75
|
+
smtp: v.strictObject({
|
|
76
|
+
host: textSchema,
|
|
77
|
+
port: positiveIntegerSchema,
|
|
78
|
+
secure: v.optional(v.boolean()),
|
|
79
|
+
user: v.optional(secretReferenceSchema, {
|
|
80
|
+
from_env: DEFAULT_SECRET_NAMES.smtpUser
|
|
81
|
+
}),
|
|
82
|
+
password: v.optional(secretReferenceSchema, {
|
|
83
|
+
from_env: DEFAULT_SECRET_NAMES.smtpPassword
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
}),
|
|
87
|
+
v.strictObject({
|
|
88
|
+
transport: v.literal('cloudflare'),
|
|
89
|
+
from: textSchema,
|
|
90
|
+
reply_to: replyToSchema
|
|
91
|
+
})
|
|
92
|
+
]),
|
|
93
|
+
{ transport: 'none' }
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Every table is strict: a key the schema doesn't know, such as one renamed since, stops startup
|
|
98
|
+
* instead of leaving its setting at a default the operator never chose.
|
|
99
|
+
*/
|
|
100
|
+
export const cloudDeploymentConfigSchema = v.strictObject({
|
|
101
|
+
schema_version: v.literal(2),
|
|
102
|
+
deployment: v.strictObject({
|
|
103
|
+
mode: v.picklist(['official', 'self-hosted']),
|
|
104
|
+
public_url: urlSchema,
|
|
105
|
+
indexing: v.optional(v.picklist(['allow', 'deny']), 'deny'),
|
|
106
|
+
trusted_origins: v.optional(v.array(urlSchema), []),
|
|
107
|
+
// The server's editor works with files on this device without signing in to the server.
|
|
108
|
+
local_editor: v.optional(v.boolean(), true),
|
|
109
|
+
listing: v.optional(v.strictObject({ minimum_editor_version: cloudEditorVersionSchema })),
|
|
110
|
+
// How a self-hosted server names itself on its public pages.
|
|
111
|
+
branding: v.optional(
|
|
112
|
+
v.strictObject({
|
|
113
|
+
name: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(80))),
|
|
114
|
+
logo_url: v.optional(urlSchema),
|
|
115
|
+
help_url: v.optional(urlSchema)
|
|
116
|
+
})
|
|
117
|
+
),
|
|
118
|
+
// Older editors ask to be updated, and the server refuses their requests.
|
|
119
|
+
minimum_editor_version: v.optional(cloudEditorVersionSchema)
|
|
120
|
+
}),
|
|
121
|
+
database: v.optional(
|
|
122
|
+
v.strictObject({ url: defaultReference(DEFAULT_SECRET_NAMES.databaseURL) }),
|
|
123
|
+
{
|
|
124
|
+
url: { from_env: DEFAULT_SECRET_NAMES.databaseURL }
|
|
125
|
+
}
|
|
126
|
+
),
|
|
127
|
+
authentication: v.strictObject({
|
|
128
|
+
secret: defaultReference(DEFAULT_SECRET_NAMES.authSecret),
|
|
129
|
+
enrollment: v.optional(
|
|
130
|
+
v.strictObject({
|
|
131
|
+
mode: v.optional(v.picklist(['open', 'approval', 'closed']), 'open'),
|
|
132
|
+
notification_emails: v.optional(v.array(v.pipe(v.string(), v.email())), [])
|
|
133
|
+
}),
|
|
134
|
+
{ mode: 'open', notification_emails: [] }
|
|
135
|
+
),
|
|
136
|
+
email_password: v.optional(
|
|
137
|
+
v.strictObject({
|
|
138
|
+
enabled: v.optional(v.boolean(), false),
|
|
139
|
+
sign_up: v.optional(v.boolean(), true),
|
|
140
|
+
minimum_password_length: v.optional(
|
|
141
|
+
v.pipe(v.number(), v.integer(), v.minValue(8), v.maxValue(128)),
|
|
142
|
+
8
|
|
143
|
+
),
|
|
144
|
+
maximum_password_length: v.optional(
|
|
145
|
+
v.pipe(v.number(), v.integer(), v.minValue(15), v.maxValue(128)),
|
|
146
|
+
128
|
|
147
|
+
),
|
|
148
|
+
verification_link_lifetime_minutes: v.optional(positiveIntegerSchema, 60),
|
|
149
|
+
password_reset_link_lifetime_minutes: v.optional(positiveIntegerSchema, 60),
|
|
150
|
+
compromised_password_check: v.optional(v.boolean(), false)
|
|
151
|
+
}),
|
|
152
|
+
{
|
|
153
|
+
enabled: false,
|
|
154
|
+
sign_up: true,
|
|
155
|
+
minimum_password_length: 8,
|
|
156
|
+
maximum_password_length: 128,
|
|
157
|
+
verification_link_lifetime_minutes: 60,
|
|
158
|
+
password_reset_link_lifetime_minutes: 60,
|
|
159
|
+
compromised_password_check: false
|
|
160
|
+
}
|
|
161
|
+
),
|
|
162
|
+
mfa: v.optional(
|
|
163
|
+
v.strictObject({
|
|
164
|
+
required_for_admins: v.optional(v.boolean(), false),
|
|
165
|
+
totp: v.optional(v.boolean(), false),
|
|
166
|
+
recovery_codes: v.optional(v.boolean(), false),
|
|
167
|
+
trusted_device_lifetime_days: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0)), 14)
|
|
168
|
+
}),
|
|
169
|
+
{
|
|
170
|
+
required_for_admins: false,
|
|
171
|
+
totp: false,
|
|
172
|
+
recovery_codes: false,
|
|
173
|
+
trusted_device_lifetime_days: 14
|
|
174
|
+
}
|
|
175
|
+
),
|
|
176
|
+
// Passkeys belong to public_url's host and origin.
|
|
177
|
+
passkeys: v.optional(
|
|
178
|
+
v.strictObject({
|
|
179
|
+
enabled: v.optional(v.boolean(), false),
|
|
180
|
+
rp_name: v.optional(textSchema, 'OpenPencil Cloud')
|
|
181
|
+
}),
|
|
182
|
+
{ enabled: false, rp_name: 'OpenPencil Cloud' }
|
|
183
|
+
),
|
|
184
|
+
captcha: v.optional(
|
|
185
|
+
v.strictObject({
|
|
186
|
+
provider: v.literal('cloudflare-turnstile'),
|
|
187
|
+
site_key: textSchema,
|
|
188
|
+
secret_key: defaultReference(DEFAULT_SECRET_NAMES.turnstileSecretKey),
|
|
189
|
+
allowed_hostnames: v.optional(v.array(textSchema), [])
|
|
190
|
+
})
|
|
191
|
+
),
|
|
192
|
+
trusted_proxies: v.optional(
|
|
193
|
+
v.strictObject({
|
|
194
|
+
headers: v.optional(v.array(textSchema), []),
|
|
195
|
+
addresses: v.optional(v.array(textSchema), [])
|
|
196
|
+
}),
|
|
197
|
+
{ headers: [], addresses: [] }
|
|
198
|
+
),
|
|
199
|
+
providers: v.optional(providerSchema, {})
|
|
200
|
+
}),
|
|
201
|
+
object_storage: v.strictObject({
|
|
202
|
+
endpoint: urlSchema,
|
|
203
|
+
region: textSchema,
|
|
204
|
+
bucket: textSchema,
|
|
205
|
+
credentials: v.optional(
|
|
206
|
+
v.strictObject({
|
|
207
|
+
access_key_id: defaultReference(DEFAULT_SECRET_NAMES.s3AccessKeyId),
|
|
208
|
+
secret_access_key: defaultReference(DEFAULT_SECRET_NAMES.s3SecretAccessKey),
|
|
209
|
+
session_token: v.optional(secretReferenceSchema, {
|
|
210
|
+
from_env: DEFAULT_SECRET_NAMES.s3SessionToken
|
|
211
|
+
})
|
|
212
|
+
}),
|
|
213
|
+
{
|
|
214
|
+
access_key_id: { from_env: DEFAULT_SECRET_NAMES.s3AccessKeyId },
|
|
215
|
+
secret_access_key: { from_env: DEFAULT_SECRET_NAMES.s3SecretAccessKey }
|
|
216
|
+
}
|
|
217
|
+
),
|
|
218
|
+
force_path_style: v.optional(v.boolean(), true),
|
|
219
|
+
checksum_verification: v.optional(v.picklist(['native', 'metadata']), 'native'),
|
|
220
|
+
server_side_encryption: v.optional(v.picklist(['AES256', 'aws:kms'])),
|
|
221
|
+
kms_key_id: v.optional(textSchema),
|
|
222
|
+
/**
|
|
223
|
+
* Keeps each file cleanup deletes under this prefix, such as `deleted/`, so a database restored
|
|
224
|
+
* to an earlier time still finds it; a lifecycle rule on the prefix expires them.
|
|
225
|
+
*/
|
|
226
|
+
deleted_prefix: v.optional(deletedPrefixSchema),
|
|
227
|
+
maximum_upload_bytes: v.optional(positiveIntegerSchema)
|
|
228
|
+
}),
|
|
229
|
+
collaboration: v.optional(
|
|
230
|
+
v.strictObject({
|
|
231
|
+
relay_url: v.optional(urlSchema),
|
|
232
|
+
maximum_message_bytes: v.optional(positiveIntegerSchema),
|
|
233
|
+
maximum_connections_per_room: v.optional(positiveIntegerSchema)
|
|
234
|
+
}),
|
|
235
|
+
{}
|
|
236
|
+
),
|
|
237
|
+
documents: v.optional(
|
|
238
|
+
v.strictObject({
|
|
239
|
+
retention_days: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0)), 30),
|
|
240
|
+
purge_grace_days: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0)), 7)
|
|
241
|
+
}),
|
|
242
|
+
{ retention_days: 30, purge_grace_days: 7 }
|
|
243
|
+
),
|
|
244
|
+
email: emailSchema,
|
|
245
|
+
workers: v.optional(
|
|
246
|
+
v.strictObject({
|
|
247
|
+
email: v.optional(
|
|
248
|
+
v.strictObject({
|
|
249
|
+
batch_size: v.optional(positiveIntegerSchema, 50),
|
|
250
|
+
interval_ms: v.optional(positiveIntegerSchema, 30_000),
|
|
251
|
+
lease_ms: v.optional(positiveIntegerSchema, 300_000),
|
|
252
|
+
maximum_attempts: v.optional(positiveIntegerSchema, 5)
|
|
253
|
+
}),
|
|
254
|
+
{ batch_size: 50, interval_ms: 30_000, lease_ms: 300_000, maximum_attempts: 5 }
|
|
255
|
+
),
|
|
256
|
+
cleanup: v.optional(
|
|
257
|
+
v.strictObject({
|
|
258
|
+
enabled: v.optional(v.boolean(), true),
|
|
259
|
+
batch_size: v.optional(positiveIntegerSchema, 100),
|
|
260
|
+
interval_ms: v.optional(positiveIntegerSchema, 60_000),
|
|
261
|
+
lease_ms: v.optional(positiveIntegerSchema, 300_000)
|
|
262
|
+
}),
|
|
263
|
+
{ enabled: true, batch_size: 100, interval_ms: 60_000, lease_ms: 300_000 }
|
|
264
|
+
)
|
|
265
|
+
})
|
|
266
|
+
),
|
|
267
|
+
entitlements: v.optional(
|
|
268
|
+
v.variant('source', [
|
|
269
|
+
v.strictObject({ source: v.literal('static'), ...staticEntitlementsTOMLSchema.entries }),
|
|
270
|
+
// The values every account takes until billing or an operator stores its own: the free plan.
|
|
271
|
+
v.strictObject({ source: v.literal('database'), ...staticEntitlementsTOMLSchema.entries })
|
|
272
|
+
])
|
|
273
|
+
),
|
|
274
|
+
services: v.optional(
|
|
275
|
+
v.strictObject({
|
|
276
|
+
endpoint: urlSchema,
|
|
277
|
+
signing_key: defaultReference(DEFAULT_SECRET_NAMES.servicesSigningKey),
|
|
278
|
+
token_lifetime_minutes: v.optional(
|
|
279
|
+
v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(60)),
|
|
280
|
+
10
|
|
281
|
+
)
|
|
282
|
+
})
|
|
283
|
+
),
|
|
284
|
+
billing: v.optional(v.strictObject({ endpoint: urlSchema })),
|
|
285
|
+
internal_api: v.optional(
|
|
286
|
+
v.strictObject({ service_token: defaultReference(DEFAULT_SECRET_NAMES.internalServiceToken) })
|
|
287
|
+
),
|
|
288
|
+
/**
|
|
289
|
+
* Optional: the operator's terms and privacy policy, linked at sign-up and in the portal, and
|
|
290
|
+
* with `require_acceptance`, accepted once per `terms_version` before an account uses the server.
|
|
291
|
+
*/
|
|
292
|
+
legal: v.optional(
|
|
293
|
+
v.strictObject({
|
|
294
|
+
terms_url: v.optional(urlSchema),
|
|
295
|
+
privacy_url: v.optional(urlSchema),
|
|
296
|
+
terms_version: v.optional(textSchema),
|
|
297
|
+
require_acceptance: v.optional(v.boolean(), false),
|
|
298
|
+
abuse_email: v.optional(v.pipe(v.string(), v.email())),
|
|
299
|
+
minimum_age: v.optional(v.pipe(v.number(), v.integer(), v.minValue(13), v.maxValue(21)))
|
|
300
|
+
})
|
|
301
|
+
),
|
|
302
|
+
/**
|
|
303
|
+
* Optional: a workspace whose documents anyone may open read-only, without signing in or a
|
|
304
|
+
* link, as the deployment's community gallery. Everything saved there is public. `tour` names
|
|
305
|
+
* the gallery document the editor opens as its tour, and the docs landing shows.
|
|
306
|
+
*/
|
|
307
|
+
community: v.optional(
|
|
308
|
+
v.strictObject({
|
|
309
|
+
workspace: v.pipe(v.string(), v.uuid()),
|
|
310
|
+
tour: v.optional(v.pipe(v.string(), v.uuid()))
|
|
311
|
+
})
|
|
312
|
+
),
|
|
313
|
+
/** Optional: reports server errors to PostHog error tracking. Leave it out to send nothing. */
|
|
314
|
+
error_tracking: v.optional(
|
|
315
|
+
v.strictObject({
|
|
316
|
+
provider: v.literal('posthog'),
|
|
317
|
+
host: v.optional(urlSchema, POSTHOG_DEFAULT_HOST),
|
|
318
|
+
project_api_key: v.optional(configurableTextSchema, {
|
|
319
|
+
from_env: DEFAULT_SECRET_NAMES.posthogProjectAPIKey
|
|
320
|
+
}),
|
|
321
|
+
/** Send the account and record IDs an error involved; off, reports name neither. */
|
|
322
|
+
include_ids: v.optional(v.boolean(), false)
|
|
323
|
+
})
|
|
324
|
+
)
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
export type CloudDeploymentConfig = v.InferOutput<typeof cloudDeploymentConfigSchema>
|
|
328
|
+
/** Deployment configuration as an operator writes it, before defaults are applied. */
|
|
329
|
+
export type CloudDeploymentInput = v.InferInput<typeof cloudDeploymentConfigSchema>
|
|
330
|
+
export type CloudSecretReference = v.InferOutput<typeof secretReferenceSchema>
|
package/src/server/db/index.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export { createCloudDatabase, type CloudDatabaseOptions } from './database'
|
|
2
|
-
export { migrateCloudDatabase } from './migrate'
|
|
2
|
+
export { migrateCloudDatabase, pendingCloudMigrations } from './migrate'
|
|
3
|
+
export { isBannedNow, userIdText } from './users'
|
|
3
4
|
export type {
|
|
4
5
|
CloudDatabase,
|
|
5
6
|
Document,
|
|
6
7
|
DocumentRevision,
|
|
8
|
+
MFAAssuranceMethod,
|
|
7
9
|
NewDocument,
|
|
8
10
|
NewDocumentRevision,
|
|
9
11
|
NewStorageObject,
|
package/src/server/db/migrate.ts
CHANGED
|
@@ -9,6 +9,16 @@ import * as sharing from './migrations/005_sharing'
|
|
|
9
9
|
import * as operations from './migrations/006_operations'
|
|
10
10
|
import * as trash from './migrations/007_trash'
|
|
11
11
|
import * as terms from './migrations/008_terms'
|
|
12
|
+
import * as accessTokens from './migrations/009_access_tokens'
|
|
13
|
+
import * as storageLimitNotices from './migrations/010_storage_limit_notices'
|
|
14
|
+
import * as accountIds from './migrations/011_account_ids'
|
|
15
|
+
import * as emailLocales from './migrations/012_email_locales'
|
|
16
|
+
import * as documentBlockEmails from './migrations/013_document_block_emails'
|
|
17
|
+
import * as reportReplies from './migrations/014_report_replies'
|
|
18
|
+
import * as comments from './migrations/015_comments'
|
|
19
|
+
import * as commentNotifications from './migrations/016_comment_notifications'
|
|
20
|
+
import * as invitationEmails from './migrations/017_invitation_emails'
|
|
21
|
+
import * as enrollmentSource from './migrations/018_enrollment_source'
|
|
12
22
|
import type { CloudDatabase } from './tables'
|
|
13
23
|
|
|
14
24
|
/**
|
|
@@ -27,7 +37,17 @@ const migrations: Record<string, CloudMigration> = {
|
|
|
27
37
|
'005_sharing': sharing,
|
|
28
38
|
'006_operations': operations,
|
|
29
39
|
'007_trash': trash,
|
|
30
|
-
'008_terms': terms
|
|
40
|
+
'008_terms': terms,
|
|
41
|
+
'009_access_tokens': accessTokens,
|
|
42
|
+
'010_storage_limit_notices': storageLimitNotices,
|
|
43
|
+
'011_account_ids': accountIds,
|
|
44
|
+
'012_email_locales': emailLocales,
|
|
45
|
+
'013_document_block_emails': documentBlockEmails,
|
|
46
|
+
'014_report_replies': reportReplies,
|
|
47
|
+
'015_comments': comments,
|
|
48
|
+
'016_comment_notifications': commentNotifications,
|
|
49
|
+
'017_invitation_emails': invitationEmails,
|
|
50
|
+
'018_enrollment_source': enrollmentSource
|
|
31
51
|
}
|
|
32
52
|
|
|
33
53
|
/** Cloud's migrations, in order. */
|
|
@@ -85,6 +105,18 @@ export async function migrateToLatest(migrator: Migrator, failure: string): Prom
|
|
|
85
105
|
}
|
|
86
106
|
}
|
|
87
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Cloud's migrations this database has not run, in order: none once a deployment of this
|
|
110
|
+
* version has started. A tool that only reads or writes rows checks this instead of migrating,
|
|
111
|
+
* so running it never changes the schema under a server of another version.
|
|
112
|
+
*/
|
|
113
|
+
export async function pendingCloudMigrations(database: Kysely<CloudDatabase>): Promise<string[]> {
|
|
114
|
+
const migrator = new Migrator({ db: database, provider: new CloudMigrationProvider() })
|
|
115
|
+
return (await migrator.getMigrations())
|
|
116
|
+
.filter((migration) => migration.executedAt === undefined)
|
|
117
|
+
.map((migration) => migration.name)
|
|
118
|
+
}
|
|
119
|
+
|
|
88
120
|
export async function migrateCloudDatabase(
|
|
89
121
|
database: Kysely<CloudDatabase>,
|
|
90
122
|
authMigration?: CloudAuthMigration
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { sql, type Kysely } from 'kysely'
|
|
2
|
+
|
|
3
|
+
import { addIndexes, required } from './schema'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Personal access tokens, kept by Better Auth's API-key plugin in the table it would build
|
|
7
|
+
* itself. Cloud builds it here instead, since Better Auth's tables are built only once and a
|
|
8
|
+
* deployment that has them gains this one as any other migration; Better Auth's migration then
|
|
9
|
+
* leaves this plugin's table out (`createBetterAuthAdapter`). It holds each token's SHA-256
|
|
10
|
+
* digest, never the token.
|
|
11
|
+
*/
|
|
12
|
+
export async function up(database: Kysely<unknown>): Promise<void> {
|
|
13
|
+
await database.schema
|
|
14
|
+
.createTable('apikey')
|
|
15
|
+
.addColumn('id', 'uuid', (column) => column.primaryKey().defaultTo(sql`gen_random_uuid()`))
|
|
16
|
+
.addColumn('config_id', 'text', required)
|
|
17
|
+
.addColumn('name', 'text')
|
|
18
|
+
.addColumn('start', 'text')
|
|
19
|
+
.addColumn('reference_id', 'text', required)
|
|
20
|
+
.addColumn('prefix', 'text')
|
|
21
|
+
.addColumn('key', 'text', required)
|
|
22
|
+
.addColumn('refill_interval', 'integer')
|
|
23
|
+
.addColumn('refill_amount', 'integer')
|
|
24
|
+
.addColumn('last_refill_at', 'timestamptz')
|
|
25
|
+
.addColumn('enabled', 'boolean')
|
|
26
|
+
.addColumn('rate_limit_enabled', 'boolean')
|
|
27
|
+
.addColumn('rate_limit_time_window', 'integer')
|
|
28
|
+
.addColumn('rate_limit_max', 'integer')
|
|
29
|
+
.addColumn('request_count', 'integer')
|
|
30
|
+
.addColumn('remaining', 'integer')
|
|
31
|
+
.addColumn('last_request', 'timestamptz')
|
|
32
|
+
.addColumn('expires_at', 'timestamptz')
|
|
33
|
+
.addColumn('created_at', 'timestamptz', required)
|
|
34
|
+
.addColumn('updated_at', 'timestamptz', required)
|
|
35
|
+
.addColumn('permissions', 'text')
|
|
36
|
+
.addColumn('metadata', 'text')
|
|
37
|
+
.execute()
|
|
38
|
+
await addIndexes(database, [
|
|
39
|
+
['apikey', ['config_id']],
|
|
40
|
+
['apikey', ['reference_id']],
|
|
41
|
+
['apikey', ['key']]
|
|
42
|
+
])
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function down(database: Kysely<unknown>): Promise<void> {
|
|
46
|
+
await database.schema.dropTable('apikey').execute()
|
|
47
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely'
|
|
2
|
+
|
|
3
|
+
import { addChecks, now } from './schema'
|
|
4
|
+
|
|
5
|
+
/** Every kind of transactional email, as of this migration. */
|
|
6
|
+
const EMAIL_KINDS = [
|
|
7
|
+
'document-invitation',
|
|
8
|
+
'workspace-invitation',
|
|
9
|
+
'enrollment-requested',
|
|
10
|
+
'admin-enrollment-notification',
|
|
11
|
+
'enrollment-approved',
|
|
12
|
+
'enrollment-rejected',
|
|
13
|
+
'enrollment-revoked',
|
|
14
|
+
'email-verification',
|
|
15
|
+
'password-reset',
|
|
16
|
+
'password-changed',
|
|
17
|
+
'email-change-requested',
|
|
18
|
+
'new-sign-in',
|
|
19
|
+
'two-step-changed',
|
|
20
|
+
'document-report'
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The accounts told their storage is full, so each is told once each time it fills, not on every
|
|
25
|
+
* cleanup pass; a row goes once the account holds less than its plan allows again. Email gains
|
|
26
|
+
* the kind that tells them, which the previous release never writes.
|
|
27
|
+
*/
|
|
28
|
+
export async function up(database: Kysely<unknown>): Promise<void> {
|
|
29
|
+
await database.schema
|
|
30
|
+
.createTable('storage_limit_notice')
|
|
31
|
+
.addColumn('user_id', 'text', (column) => column.primaryKey())
|
|
32
|
+
.addColumn('notified_at', 'timestamptz', now)
|
|
33
|
+
.execute()
|
|
34
|
+
await database.schema
|
|
35
|
+
.alterTable('transactional_email')
|
|
36
|
+
.dropConstraint('transactional_email_kind_check')
|
|
37
|
+
.execute()
|
|
38
|
+
await addChecks(database, [
|
|
39
|
+
['transactional_email', 'kind', [...EMAIL_KINDS, 'storage-limit-reached']]
|
|
40
|
+
])
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function down(database: Kysely<unknown>): Promise<void> {
|
|
44
|
+
await database.schema
|
|
45
|
+
.alterTable('transactional_email')
|
|
46
|
+
.dropConstraint('transactional_email_kind_check')
|
|
47
|
+
.execute()
|
|
48
|
+
await addChecks(database, [['transactional_email', 'kind', EMAIL_KINDS]])
|
|
49
|
+
await database.schema.dropTable('storage_limit_notice').execute()
|
|
50
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { sql, type Kysely } from 'kysely'
|
|
2
|
+
|
|
3
|
+
/** The tables that named accounts by `uuid`, unlike every other table Cloud builds. */
|
|
4
|
+
const TABLES = ['mfa_assurance', 'sign_in', 'user_picture']
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Names accounts by `text` in the last tables that used `uuid`, as `schema.ts` sets for every
|
|
8
|
+
* table Cloud builds. The previous release reads and writes the same strings either way, so it
|
|
9
|
+
* keeps working while this runs.
|
|
10
|
+
*/
|
|
11
|
+
export const contracts = TABLES.map((table) => `${table}.user_id`)
|
|
12
|
+
|
|
13
|
+
export async function up(database: Kysely<unknown>): Promise<void> {
|
|
14
|
+
for (const table of TABLES) {
|
|
15
|
+
await database.schema
|
|
16
|
+
.alterTable(table)
|
|
17
|
+
.alterColumn('user_id', (column) => column.setDataType('text'))
|
|
18
|
+
.execute()
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function down(database: Kysely<unknown>): Promise<void> {
|
|
23
|
+
for (const table of TABLES) {
|
|
24
|
+
await database.schema
|
|
25
|
+
.alterTable(table)
|
|
26
|
+
// Text turns into a UUID only when told to, unlike a UUID into text.
|
|
27
|
+
.alterColumn('user_id', (column) => column.setDataType(sql`uuid using user_id::uuid`))
|
|
28
|
+
.execute()
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely'
|
|
2
|
+
|
|
3
|
+
/** Whether Better Auth's `user` table exists yet, which it doesn't before a server first starts. */
|
|
4
|
+
async function hasUserTable(database: Kysely<unknown>): Promise<boolean> {
|
|
5
|
+
const tables = await database.introspection.getTables()
|
|
6
|
+
return tables.some((table) => table.name === 'user')
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The language Cloud writes to each account in, and the one each queued email is written in,
|
|
11
|
+
* settled when it's queued so a retry reads the same. Email from before this migration is
|
|
12
|
+
* English, as it always was.
|
|
13
|
+
*
|
|
14
|
+
* `user.locale` is a Better Auth field, so a new database gets it from Better Auth's own schema,
|
|
15
|
+
* built after Cloud's migrations. A database that already has that schema never builds it again,
|
|
16
|
+
* so it gets the column here; accounts from before it have no language and read English.
|
|
17
|
+
*/
|
|
18
|
+
export async function up(database: Kysely<unknown>): Promise<void> {
|
|
19
|
+
await database.schema
|
|
20
|
+
.alterTable('transactional_email')
|
|
21
|
+
.addColumn('locale', 'text', (column) => column.notNull().defaultTo('en'))
|
|
22
|
+
.execute()
|
|
23
|
+
if (await hasUserTable(database)) {
|
|
24
|
+
await database.schema
|
|
25
|
+
.alterTable('user')
|
|
26
|
+
.addColumn('locale', 'text', (column) => column.ifNotExists())
|
|
27
|
+
.execute()
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// `user.locale` stays: an earlier release ignores it, and the languages accounts chose aren't lost.
|
|
32
|
+
export async function down(database: Kysely<unknown>): Promise<void> {
|
|
33
|
+
await database.schema.alterTable('transactional_email').dropColumn('locale').execute()
|
|
34
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely'
|
|
2
|
+
|
|
3
|
+
import { replaceChecks } from './schema'
|
|
4
|
+
|
|
5
|
+
/** Every kind of transactional email before this migration. */
|
|
6
|
+
const EMAIL_KINDS = [
|
|
7
|
+
'document-invitation',
|
|
8
|
+
'workspace-invitation',
|
|
9
|
+
'enrollment-requested',
|
|
10
|
+
'admin-enrollment-notification',
|
|
11
|
+
'enrollment-approved',
|
|
12
|
+
'enrollment-rejected',
|
|
13
|
+
'enrollment-revoked',
|
|
14
|
+
'email-verification',
|
|
15
|
+
'password-reset',
|
|
16
|
+
'password-changed',
|
|
17
|
+
'email-change-requested',
|
|
18
|
+
'new-sign-in',
|
|
19
|
+
'two-step-changed',
|
|
20
|
+
'document-report',
|
|
21
|
+
'storage-limit-reached'
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
/** Every kind of transactional email once this migration has run. */
|
|
25
|
+
export const DOCUMENT_BLOCK_EMAIL_KINDS = [...EMAIL_KINDS, 'document-blocked', 'document-restored']
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Email gains the kinds that tell a workspace's owner an administrator blocked one of its
|
|
29
|
+
* documents, and that it is back, which the previous release never writes.
|
|
30
|
+
*/
|
|
31
|
+
export async function up(database: Kysely<unknown>): Promise<void> {
|
|
32
|
+
await replaceChecks(database, 'widen', [
|
|
33
|
+
['transactional_email', 'kind', DOCUMENT_BLOCK_EMAIL_KINDS]
|
|
34
|
+
])
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Narrowing back checks every row, so a rollback refuses while any email of the new kinds is kept.
|
|
38
|
+
export async function down(database: Kysely<unknown>): Promise<void> {
|
|
39
|
+
await replaceChecks(database, 'narrow', [['transactional_email', 'kind', EMAIL_KINDS]])
|
|
40
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely'
|
|
2
|
+
|
|
3
|
+
import { DOCUMENT_BLOCK_EMAIL_KINDS } from './013_document_block_emails'
|
|
4
|
+
import { replaceChecks } from './schema'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Whoever reports a document and leaves an address hears that the report arrived and what the
|
|
8
|
+
* administrators decided. A report keeps the language its reporter's browser asked for, since a
|
|
9
|
+
* guest has no account to say it, and email gains the two kinds, which the previous release
|
|
10
|
+
* never writes.
|
|
11
|
+
*/
|
|
12
|
+
export async function up(database: Kysely<unknown>): Promise<void> {
|
|
13
|
+
await database.schema.alterTable('document_report').addColumn('reply_locale', 'text').execute()
|
|
14
|
+
await replaceChecks(database, 'widen', [
|
|
15
|
+
[
|
|
16
|
+
'transactional_email',
|
|
17
|
+
'kind',
|
|
18
|
+
[...DOCUMENT_BLOCK_EMAIL_KINDS, 'document-report-received', 'document-report-decided']
|
|
19
|
+
]
|
|
20
|
+
])
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function down(database: Kysely<unknown>): Promise<void> {
|
|
24
|
+
await replaceChecks(database, 'narrow', [
|
|
25
|
+
['transactional_email', 'kind', DOCUMENT_BLOCK_EMAIL_KINDS]
|
|
26
|
+
])
|
|
27
|
+
await database.schema.alterTable('document_report').dropColumn('reply_locale').execute()
|
|
28
|
+
}
|