@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,57 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely'
|
|
2
|
+
|
|
3
|
+
import { addIndexes, dropTables, now, required } from './schema'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Comments on a Cloud document belong to the server, not to the file: each one keeps who wrote
|
|
7
|
+
* it as an account, can be deleted for good, and is open to people who may only view. A thread
|
|
8
|
+
* is the pin and whether it is resolved; its comments are its first message and the replies.
|
|
9
|
+
*/
|
|
10
|
+
export async function up(database: Kysely<unknown>): Promise<void> {
|
|
11
|
+
await database.schema
|
|
12
|
+
.createTable('comment_thread')
|
|
13
|
+
.addColumn('id', 'uuid', (column) => column.primaryKey())
|
|
14
|
+
.addColumn('document_id', 'uuid', (column) =>
|
|
15
|
+
column.notNull().references('document.id').onDelete('cascade')
|
|
16
|
+
)
|
|
17
|
+
.addColumn('page_id', 'text', required)
|
|
18
|
+
// The page and layer names when the pin was placed, for a file written without the layer.
|
|
19
|
+
.addColumn('page_name', 'text')
|
|
20
|
+
.addColumn('node_id', 'text')
|
|
21
|
+
.addColumn('node_name', 'text')
|
|
22
|
+
.addColumn('offset_x', 'double precision')
|
|
23
|
+
.addColumn('offset_y', 'double precision')
|
|
24
|
+
.addColumn('x', 'double precision', required)
|
|
25
|
+
.addColumn('y', 'double precision', required)
|
|
26
|
+
.addColumn('created_by', 'text', required)
|
|
27
|
+
.addColumn('created_at', 'timestamptz', now)
|
|
28
|
+
.addColumn('updated_at', 'timestamptz', now)
|
|
29
|
+
.addColumn('resolved_at', 'timestamptz')
|
|
30
|
+
.addColumn('resolved_by', 'text')
|
|
31
|
+
.execute()
|
|
32
|
+
await database.schema
|
|
33
|
+
.createTable('comment')
|
|
34
|
+
.addColumn('id', 'uuid', (column) => column.primaryKey())
|
|
35
|
+
.addColumn('thread_id', 'uuid', (column) =>
|
|
36
|
+
column.notNull().references('comment_thread.id').onDelete('cascade')
|
|
37
|
+
)
|
|
38
|
+
// The account that wrote it. A comment brought in from a file has none and keeps the name
|
|
39
|
+
// the file gave instead, which no one vouches for.
|
|
40
|
+
.addColumn('author_id', 'text')
|
|
41
|
+
.addColumn('imported_author_name', 'text')
|
|
42
|
+
// The agent that wrote it on its author's behalf, if one did.
|
|
43
|
+
.addColumn('agent', 'text')
|
|
44
|
+
.addColumn('body', 'text', required)
|
|
45
|
+
.addColumn('created_at', 'timestamptz', now)
|
|
46
|
+
.addColumn('edited_at', 'timestamptz')
|
|
47
|
+
.execute()
|
|
48
|
+
await addIndexes(database, [
|
|
49
|
+
['comment_thread', ['document_id', 'created_at']],
|
|
50
|
+
['comment', ['thread_id', 'created_at']],
|
|
51
|
+
['comment', ['author_id']]
|
|
52
|
+
])
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function down(database: Kysely<unknown>): Promise<void> {
|
|
56
|
+
await dropTables(database, ['comment_thread', 'comment'])
|
|
57
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely'
|
|
2
|
+
|
|
3
|
+
import { DOCUMENT_BLOCK_EMAIL_KINDS } from './013_document_block_emails'
|
|
4
|
+
import { addChecks, addIndexes, dropTables, now, replaceChecks, required } from './schema'
|
|
5
|
+
|
|
6
|
+
/** The kinds `014_report_replies` left email with. */
|
|
7
|
+
const REPORT_REPLY_EMAIL_KINDS = [
|
|
8
|
+
...DOCUMENT_BLOCK_EMAIL_KINDS,
|
|
9
|
+
'document-report-received',
|
|
10
|
+
'document-report-decided'
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
export const COMMENT_EMAIL_SETTINGS = ['all', 'mentions', 'off']
|
|
14
|
+
|
|
15
|
+
/** Every kind of transactional email once this migration has run. */
|
|
16
|
+
export const COMMENT_EMAIL_KINDS = [...REPORT_REPLY_EMAIL_KINDS, 'comment-notification']
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Who a comment names, who has read a thread up to when, and which comments each account hears
|
|
20
|
+
* about by email: everything in threads it takes part in, only what names it, or nothing. Email
|
|
21
|
+
* gains the kind that tells someone, which the previous release never writes.
|
|
22
|
+
*/
|
|
23
|
+
export async function up(database: Kysely<unknown>): Promise<void> {
|
|
24
|
+
await database.schema
|
|
25
|
+
.createTable('comment_mention')
|
|
26
|
+
.addColumn('comment_id', 'uuid', (column) =>
|
|
27
|
+
column.notNull().references('comment.id').onDelete('cascade')
|
|
28
|
+
)
|
|
29
|
+
.addColumn('user_id', 'text', required)
|
|
30
|
+
.addColumn('created_at', 'timestamptz', now)
|
|
31
|
+
.addPrimaryKeyConstraint('comment_mention_pkey', ['comment_id', 'user_id'])
|
|
32
|
+
.execute()
|
|
33
|
+
await database.schema
|
|
34
|
+
.createTable('comment_read')
|
|
35
|
+
.addColumn('user_id', 'text', required)
|
|
36
|
+
.addColumn('thread_id', 'uuid', (column) =>
|
|
37
|
+
column.notNull().references('comment_thread.id').onDelete('cascade')
|
|
38
|
+
)
|
|
39
|
+
.addColumn('read_at', 'timestamptz', now)
|
|
40
|
+
.addPrimaryKeyConstraint('comment_read_pkey', ['user_id', 'thread_id'])
|
|
41
|
+
.execute()
|
|
42
|
+
// An email sent about a comment, for each day's budget: who wrote it, and to whom.
|
|
43
|
+
await database.schema
|
|
44
|
+
.createTable('comment_email')
|
|
45
|
+
.addColumn('id', 'uuid', (column) => column.primaryKey())
|
|
46
|
+
.addColumn('sender_id', 'text', required)
|
|
47
|
+
.addColumn('recipient_id', 'text', required)
|
|
48
|
+
.addColumn('sent_at', 'timestamptz', now)
|
|
49
|
+
.execute()
|
|
50
|
+
await database.schema
|
|
51
|
+
.createTable('notification_setting')
|
|
52
|
+
.addColumn('user_id', 'text', (column) => column.primaryKey())
|
|
53
|
+
.addColumn('comment_emails', 'text', required)
|
|
54
|
+
.addColumn('updated_at', 'timestamptz', now)
|
|
55
|
+
.execute()
|
|
56
|
+
await addChecks(database, [['notification_setting', 'comment_emails', COMMENT_EMAIL_SETTINGS]])
|
|
57
|
+
await addIndexes(database, [
|
|
58
|
+
['comment_mention', ['user_id']],
|
|
59
|
+
['comment_read', ['thread_id']],
|
|
60
|
+
['comment_email', ['sender_id', 'sent_at']],
|
|
61
|
+
['comment_email', ['recipient_id', 'sent_at']]
|
|
62
|
+
])
|
|
63
|
+
await replaceChecks(database, 'widen', [['transactional_email', 'kind', COMMENT_EMAIL_KINDS]])
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function down(database: Kysely<unknown>): Promise<void> {
|
|
67
|
+
await replaceChecks(database, 'narrow', [
|
|
68
|
+
['transactional_email', 'kind', REPORT_REPLY_EMAIL_KINDS]
|
|
69
|
+
])
|
|
70
|
+
await dropTables(database, [
|
|
71
|
+
'comment_mention',
|
|
72
|
+
'comment_read',
|
|
73
|
+
'comment_email',
|
|
74
|
+
'notification_setting'
|
|
75
|
+
])
|
|
76
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely'
|
|
2
|
+
|
|
3
|
+
import { COMMENT_EMAIL_KINDS } from './016_comment_notifications'
|
|
4
|
+
import { replaceChecks } from './schema'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Email gains the official deployment's invitation letter, which approves a waiting request with a
|
|
8
|
+
* note from the founder instead of the plain approval; the previous release never writes it.
|
|
9
|
+
*/
|
|
10
|
+
export async function up(database: Kysely<unknown>): Promise<void> {
|
|
11
|
+
await replaceChecks(database, 'widen', [
|
|
12
|
+
['transactional_email', 'kind', [...COMMENT_EMAIL_KINDS, 'enrollment-invited']]
|
|
13
|
+
])
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Narrowing back checks every row, so a rollback refuses while an invitation letter is kept.
|
|
17
|
+
export async function down(database: Kysely<unknown>): Promise<void> {
|
|
18
|
+
await replaceChecks(database, 'narrow', [['transactional_email', 'kind', COMMENT_EMAIL_KINDS]])
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { sql, type Kysely } from 'kysely'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Where an access request came from: null when the person asked on this server, `waitlist` when an
|
|
5
|
+
* administrator recorded someone from openpencil.dev's waitlist, whose approval with the invitation
|
|
6
|
+
* letter thanks them for joining the waitlist rather than for asking. Earlier requests asked here.
|
|
7
|
+
*/
|
|
8
|
+
export async function up(database: Kysely<unknown>): Promise<void> {
|
|
9
|
+
await database.schema
|
|
10
|
+
.alterTable('enrollment')
|
|
11
|
+
.addColumn('source', 'text', (column) => column.check(sql`source in ('waitlist')`))
|
|
12
|
+
.execute()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function down(database: Kysely<unknown>): Promise<void> {
|
|
16
|
+
await database.schema.alterTable('enrollment').dropColumn('source').execute()
|
|
17
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { checkColumnIn, CURRENT_TIMESTAMP } from '#cloud/server/db/expressions'
|
|
2
|
-
import type
|
|
2
|
+
import { sql, type ColumnDefinitionBuilder, type CreateTableBuilder, type Kysely } from 'kysely'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* What Cloud's migrations build tables with. Names follow PostgreSQL's own: `<table>_pkey`,
|
|
@@ -45,6 +45,31 @@ export async function addChecks(
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Replaces the values a column may take, as `addChecks` named them. Widening them, as when a
|
|
50
|
+
* release adds a kind the previous one never writes, adds the check `NOT VALID`: rows already
|
|
51
|
+
* there passed the narrower one, so PostgreSQL skips scanning them while it holds the table, and
|
|
52
|
+
* checks every row written from then on. Narrowing them, as a rollback does, checks every row.
|
|
53
|
+
*/
|
|
54
|
+
export async function replaceChecks(
|
|
55
|
+
database: Kysely<unknown>,
|
|
56
|
+
change: 'widen' | 'narrow',
|
|
57
|
+
checks: readonly (readonly [table: string, column: string, values: readonly string[]])[]
|
|
58
|
+
): Promise<void> {
|
|
59
|
+
for (const [table, column, values] of checks) {
|
|
60
|
+
const name = `${table}_${column}_check`
|
|
61
|
+
await database.schema.alterTable(table).dropConstraint(name).execute()
|
|
62
|
+
if (change === 'narrow') {
|
|
63
|
+
await addChecks(database, [[table, column, values]])
|
|
64
|
+
continue
|
|
65
|
+
}
|
|
66
|
+
// Kysely builds no `NOT VALID`, so this one statement is written out.
|
|
67
|
+
await sql`alter table ${sql.table(table)} add constraint ${sql.id(name)} check (${checkColumnIn(column, values)}) not valid`.execute(
|
|
68
|
+
database
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
48
73
|
/** Lookups beyond primary keys and unique columns, as `[table, columns]`; `desc` sorts newest first. */
|
|
49
74
|
export async function addIndexes(
|
|
50
75
|
database: Kysely<unknown>,
|
package/src/server/db/tables.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import type { EnrollmentStatus } from '#cloud/admin/enrollment/service'
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type {
|
|
3
|
+
CloudSignInMethod,
|
|
4
|
+
CommentEmailSetting,
|
|
5
|
+
DocumentPermission,
|
|
6
|
+
WorkspaceRole
|
|
7
|
+
} from '#cloud/contract'
|
|
8
|
+
import type {
|
|
9
|
+
EmailLocale,
|
|
10
|
+
TransactionalEmailKind,
|
|
11
|
+
TransactionalEmailPayloadByKind
|
|
12
|
+
} from '#cloud/email'
|
|
4
13
|
import type { Account, Session } from 'better-auth'
|
|
5
14
|
import type { ColumnType, Generated, Insertable, Selectable, Updateable } from 'kysely'
|
|
6
15
|
|
|
@@ -108,6 +117,66 @@ export interface DocumentTable {
|
|
|
108
117
|
}
|
|
109
118
|
|
|
110
119
|
/** A report someone filed about a document shared with them by link; see migration 032. */
|
|
120
|
+
/** A comment pin on a document: where it sits, and whether it is resolved. */
|
|
121
|
+
export interface CommentThreadTable {
|
|
122
|
+
id: string
|
|
123
|
+
documentId: string
|
|
124
|
+
pageId: string
|
|
125
|
+
pageName: string | null
|
|
126
|
+
nodeId: string | null
|
|
127
|
+
nodeName: string | null
|
|
128
|
+
offsetX: number | null
|
|
129
|
+
offsetY: number | null
|
|
130
|
+
x: number
|
|
131
|
+
y: number
|
|
132
|
+
createdBy: string
|
|
133
|
+
createdAt: TimestampColumn
|
|
134
|
+
updatedAt: TimestampColumn
|
|
135
|
+
resolvedAt: TimestampColumn | null
|
|
136
|
+
resolvedBy: string | null
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** A thread's first message or a reply to it. */
|
|
140
|
+
export interface CommentTable {
|
|
141
|
+
id: string
|
|
142
|
+
threadId: string
|
|
143
|
+
/** Null only for a comment brought in from a file, which has `importedAuthorName` instead. */
|
|
144
|
+
authorId: string | null
|
|
145
|
+
importedAuthorName: string | null
|
|
146
|
+
agent: string | null
|
|
147
|
+
body: string
|
|
148
|
+
createdAt: TimestampColumn
|
|
149
|
+
editedAt: TimestampColumn | null
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Someone a comment names, by account. */
|
|
153
|
+
export interface CommentMentionTable {
|
|
154
|
+
commentId: string
|
|
155
|
+
userId: string
|
|
156
|
+
createdAt: TimestampColumn
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** How far an account has read a thread. */
|
|
160
|
+
export interface CommentReadTable {
|
|
161
|
+
userId: string
|
|
162
|
+
threadId: string
|
|
163
|
+
readAt: TimestampColumn
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** An email sent about a comment, counted against each day's budget. */
|
|
167
|
+
export interface CommentEmailTable {
|
|
168
|
+
id: string
|
|
169
|
+
senderId: string
|
|
170
|
+
recipientId: string
|
|
171
|
+
sentAt: TimestampColumn
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface NotificationSettingTable {
|
|
175
|
+
userId: string
|
|
176
|
+
commentEmails: CommentEmailSetting
|
|
177
|
+
updatedAt: TimestampColumn
|
|
178
|
+
}
|
|
179
|
+
|
|
111
180
|
export interface DocumentReportTable {
|
|
112
181
|
id: string
|
|
113
182
|
documentId: string
|
|
@@ -115,6 +184,8 @@ export interface DocumentReportTable {
|
|
|
115
184
|
reporterUserId: string | null
|
|
116
185
|
reporterGuestId: string | null
|
|
117
186
|
replyEmail: string | null
|
|
187
|
+
/** The language to reply in when the reporter has no account that chose one. */
|
|
188
|
+
replyLocale: Generated<EmailLocale | null>
|
|
118
189
|
reason: 'spam-phishing' | 'illegal' | 'copyright' | 'harassment' | 'other'
|
|
119
190
|
description: string
|
|
120
191
|
status: Generated<'open' | 'dismissed' | 'actioned'>
|
|
@@ -206,10 +277,23 @@ export interface AuthUserTable {
|
|
|
206
277
|
banExpires: TimestampColumn | null
|
|
207
278
|
/** Unset on accounts that never turned two-step sign-in on. */
|
|
208
279
|
twoFactorEnabled: Generated<boolean | null>
|
|
280
|
+
/** The language Cloud writes to the account in; unset is English. */
|
|
281
|
+
locale: Generated<EmailLocale | null>
|
|
209
282
|
createdAt: TimestampColumn
|
|
210
283
|
updatedAt: TimestampColumn
|
|
211
284
|
}
|
|
212
285
|
|
|
286
|
+
/** Better Auth's API keys, which are Cloud's personal access tokens; the plugin owns the rest. */
|
|
287
|
+
export interface AccessTokenTable {
|
|
288
|
+
id: string
|
|
289
|
+
referenceId: string
|
|
290
|
+
name: string | null
|
|
291
|
+
start: string | null
|
|
292
|
+
expiresAt: TimestampColumn | null
|
|
293
|
+
lastRequest: TimestampColumn | null
|
|
294
|
+
createdAt: TimestampColumn
|
|
295
|
+
}
|
|
296
|
+
|
|
213
297
|
export interface TwoFactorTable {
|
|
214
298
|
id: string
|
|
215
299
|
secret: string
|
|
@@ -234,13 +318,29 @@ export interface PasskeyTable {
|
|
|
234
318
|
aaguid: string | null
|
|
235
319
|
}
|
|
236
320
|
|
|
321
|
+
/**
|
|
322
|
+
* How a session proved its second step: a code, a recovery code, a passkey, or for a desktop app,
|
|
323
|
+
* a device sign-in that only a session which proved it could approve.
|
|
324
|
+
*/
|
|
325
|
+
export type MFAAssuranceMethod = 'totp' | 'recovery-code' | 'passkey' | 'device'
|
|
326
|
+
|
|
237
327
|
export interface MFAAssuranceTable {
|
|
238
328
|
sessionId: string
|
|
239
329
|
userId: string
|
|
240
|
-
method:
|
|
330
|
+
method: MFAAssuranceMethod
|
|
241
331
|
verifiedAt: TimestampColumn
|
|
242
332
|
}
|
|
243
333
|
|
|
334
|
+
/** Better Auth's keyed values, which also hold an administrator's sign-in blocks. */
|
|
335
|
+
export interface VerificationTable {
|
|
336
|
+
id: string
|
|
337
|
+
identifier: string
|
|
338
|
+
value: string
|
|
339
|
+
expiresAt: TimestampColumn
|
|
340
|
+
createdAt: TimestampColumn
|
|
341
|
+
updatedAt: TimestampColumn
|
|
342
|
+
}
|
|
343
|
+
|
|
244
344
|
export interface SignInTable {
|
|
245
345
|
id: string
|
|
246
346
|
userId: string
|
|
@@ -312,6 +412,12 @@ export interface AccountEntitlementTable {
|
|
|
312
412
|
updatedAt: TimestampColumn
|
|
313
413
|
}
|
|
314
414
|
|
|
415
|
+
/** An account told its storage is full; see `createStorageLimitNoticeService`. */
|
|
416
|
+
export interface StorageLimitNoticeTable {
|
|
417
|
+
userId: string
|
|
418
|
+
notifiedAt: TimestampColumn
|
|
419
|
+
}
|
|
420
|
+
|
|
315
421
|
export interface WorkspaceStorageUsageTable {
|
|
316
422
|
workspaceId: string
|
|
317
423
|
committedBytes: number
|
|
@@ -337,6 +443,8 @@ export interface TransactionalEmailTable {
|
|
|
337
443
|
kind: TransactionalEmailKind
|
|
338
444
|
recipientEmailNormalized: string
|
|
339
445
|
payloadEncrypted: string | null
|
|
446
|
+
/** The language the email is written in. */
|
|
447
|
+
locale: Generated<EmailLocale>
|
|
340
448
|
status: TransactionalEmailStatus
|
|
341
449
|
attemptCount: Generated<number>
|
|
342
450
|
nextAttemptAt: TimestampColumn
|
|
@@ -364,6 +472,8 @@ export interface EnrollmentTable {
|
|
|
364
472
|
reviewNote: string | null
|
|
365
473
|
requestRevision: Generated<number>
|
|
366
474
|
approvedUserId: string | null
|
|
475
|
+
/** `waitlist` for someone an administrator recorded from openpencil.dev's waitlist. */
|
|
476
|
+
source: ColumnType<'waitlist' | null, 'waitlist' | null | undefined, 'waitlist' | null>
|
|
367
477
|
}
|
|
368
478
|
|
|
369
479
|
export interface APIRateLimitTable {
|
|
@@ -404,8 +514,10 @@ export interface CloudDatabase {
|
|
|
404
514
|
passkey: PasskeyTable
|
|
405
515
|
mfaAssurance: MFAAssuranceTable
|
|
406
516
|
signIn: SignInTable
|
|
517
|
+
verification: VerificationTable
|
|
407
518
|
userPicture: UserPictureTable
|
|
408
519
|
user: AuthUserTable
|
|
520
|
+
apikey: AccessTokenTable
|
|
409
521
|
authSchemaVersion: AuthSchemaVersionTable
|
|
410
522
|
enrollment: EnrollmentTable
|
|
411
523
|
apiRateLimit: APIRateLimitTable
|
|
@@ -428,11 +540,18 @@ export interface CloudDatabase {
|
|
|
428
540
|
accountEntitlement: AccountEntitlementTable
|
|
429
541
|
termsAcceptance: TermsAcceptanceTable
|
|
430
542
|
workspaceStorageUsage: WorkspaceStorageUsageTable
|
|
543
|
+
storageLimitNotice: StorageLimitNoticeTable
|
|
431
544
|
transactionalEmail: TransactionalEmailTable
|
|
432
545
|
uploadStorageReservation: UploadStorageReservationTable
|
|
433
546
|
upload: UploadTable
|
|
434
547
|
invitationSend: InvitationSendTable
|
|
435
548
|
documentReport: DocumentReportTable
|
|
549
|
+
commentThread: CommentThreadTable
|
|
550
|
+
comment: CommentTable
|
|
551
|
+
commentMention: CommentMentionTable
|
|
552
|
+
commentRead: CommentReadTable
|
|
553
|
+
commentEmail: CommentEmailTable
|
|
554
|
+
notificationSetting: NotificationSettingTable
|
|
436
555
|
}
|
|
437
556
|
|
|
438
557
|
export type NewTransactionalEmail = Insertable<TransactionalEmailTable>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ExpressionBuilder } from 'kysely'
|
|
2
|
+
|
|
3
|
+
import type { CloudDatabase } from './tables'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `user.id` as text, the form every other table keeps account IDs in, such as a document's
|
|
7
|
+
* `createdBy`, so the two can be compared.
|
|
8
|
+
*/
|
|
9
|
+
export function userIdText(expression: ExpressionBuilder<CloudDatabase, 'user'>) {
|
|
10
|
+
return expression.cast<string>(expression.ref('user.id'), 'text')
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Whether the user row in scope is banned, by a ban that has not run out. */
|
|
14
|
+
export function isBannedNow(expression: ExpressionBuilder<CloudDatabase, 'user'>) {
|
|
15
|
+
return expression.and([
|
|
16
|
+
expression('user.banned', '=', true),
|
|
17
|
+
expression.or([
|
|
18
|
+
expression('user.banExpires', 'is', null),
|
|
19
|
+
expression('user.banExpires', '>', new Date())
|
|
20
|
+
])
|
|
21
|
+
])
|
|
22
|
+
}
|
|
@@ -88,6 +88,23 @@ export async function resolveDocumentAccess(
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
/**
|
|
92
|
+
* What the user may do with a live document's comments, or undefined when they may not read it:
|
|
93
|
+
* everyone who can read may comment, and those who can edit may delete anyone's comments.
|
|
94
|
+
*/
|
|
95
|
+
export async function resolveDocumentCommentAccess(
|
|
96
|
+
database: AccessDatabase,
|
|
97
|
+
userId: string,
|
|
98
|
+
documentId: string
|
|
99
|
+
): Promise<{ canComment: boolean; canModerate: boolean } | undefined> {
|
|
100
|
+
const grants = await documentAccessGrants(database, userId, documentId)
|
|
101
|
+
if (!grantsAllow(grants, { document: ['read'] })) return undefined
|
|
102
|
+
return {
|
|
103
|
+
canComment: grantsAllow(grants, { document: ['comment'] }),
|
|
104
|
+
canModerate: grantsAllow(grants, { document: ['moderate'] })
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
91
108
|
export function canEditDocument(access: DocumentAccess): boolean {
|
|
92
109
|
return access.permission === 'edit'
|
|
93
110
|
}
|
|
@@ -12,13 +12,18 @@ import type { StorageQuotaService } from '#cloud/server/quota'
|
|
|
12
12
|
import { uniq, uniqBy } from 'es-toolkit'
|
|
13
13
|
import type { Kysely, Transaction } from 'kysely'
|
|
14
14
|
|
|
15
|
+
import { DAY_MS, MINUTE_MS } from '@open-pencil/std/timing'
|
|
16
|
+
|
|
15
17
|
/** Images are stored as the bytes their file holds, whatever format those are. */
|
|
16
18
|
export const IMAGE_CONTENT_TYPE = 'application/octet-stream'
|
|
17
19
|
|
|
18
20
|
type Executor = Kysely<CloudDatabase> | Transaction<CloudDatabase>
|
|
19
21
|
|
|
20
22
|
/** An image no revision has used for this long may be released; a save uploads first. */
|
|
21
|
-
export const IMAGE_RELEASE_GRACE_MS =
|
|
23
|
+
export const IMAGE_RELEASE_GRACE_MS = DAY_MS
|
|
24
|
+
|
|
25
|
+
/** How long a link to download a revision or its images works. */
|
|
26
|
+
export const DOWNLOAD_LIFETIME_MS = 5 * MINUTE_MS
|
|
22
27
|
|
|
23
28
|
/**
|
|
24
29
|
* The images a workspace's documents use, each stored once under the SHA-256 the object store
|
|
@@ -4,7 +4,7 @@ export {
|
|
|
4
4
|
resolveDocumentAccess,
|
|
5
5
|
type AccessDatabase
|
|
6
6
|
} from './access'
|
|
7
|
-
export { createDocumentRoutes, type DocumentRouteEnvironment } from './routes'
|
|
7
|
+
export { createDocumentRoutes, documentDomainError, type DocumentRouteEnvironment } from './routes'
|
|
8
8
|
export {
|
|
9
9
|
DocumentConflictError,
|
|
10
10
|
DocumentForbiddenError,
|
|
@@ -4,12 +4,15 @@ import { DocumentForbiddenError, DocumentNotFoundError } from '#cloud/server/doc
|
|
|
4
4
|
import type { DocumentServiceOptions } from '#cloud/server/documents/service'
|
|
5
5
|
import { documentSummary, getDocumentSummaryRow } from '#cloud/server/documents/summary'
|
|
6
6
|
import { CLOUD_FEATURE_KEYS } from '#cloud/server/policy/keys'
|
|
7
|
+
import { storageLimitReached } from '#cloud/server/policy/storage'
|
|
7
8
|
import { workspacePolicyContext } from '#cloud/server/policy/workspace'
|
|
9
|
+
import { StorageQuotaExceededError } from '#cloud/server/quota'
|
|
8
10
|
import type { Kysely } from 'kysely'
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* The document `userId` may write to, and how large one file and its owner's storage may be for
|
|
12
|
-
* this save: technical limits, tightened by the owner's plan.
|
|
14
|
+
* this save: technical limits, tightened by the owner's plan. An owner who holds their whole
|
|
15
|
+
* storage allowance or more is read-only, so nothing of theirs takes a save, however small.
|
|
13
16
|
*/
|
|
14
17
|
export async function writableDocument(
|
|
15
18
|
database: Kysely<CloudDatabase>,
|
|
@@ -30,6 +33,9 @@ export async function writableDocument(
|
|
|
30
33
|
{ actorId: userId, deploymentMode: 'self-hosted' }
|
|
31
34
|
)
|
|
32
35
|
if (!policyContext) throw new DocumentNotFoundError()
|
|
36
|
+
if (await storageLimitReached(database, options.policy, { documentId })) {
|
|
37
|
+
throw new StorageQuotaExceededError('The owner holds their whole storage allowance')
|
|
38
|
+
}
|
|
33
39
|
const technicalMaximum = options.technicalMaximumUploadBytes ?? Number.MAX_SAFE_INTEGER
|
|
34
40
|
const maximumFileBytes = Math.min(
|
|
35
41
|
technicalMaximum,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
commitImageUploadsSchema,
|
|
3
|
+
commitUploadSchema,
|
|
4
|
+
createDocumentSchema,
|
|
5
|
+
createUploadSchema,
|
|
6
|
+
requestImageLinksSchema,
|
|
7
|
+
requestImageUploadsSchema
|
|
8
8
|
} from '#cloud/contract'
|
|
9
9
|
import type { CloudActor } from '#cloud/server/auth'
|
|
10
10
|
import type { CloudDatabase } from '#cloud/server/db'
|
|
@@ -162,7 +162,7 @@ export function createDocumentRoutes(
|
|
|
162
162
|
.post(
|
|
163
163
|
'/workspaces/:workspaceId/documents',
|
|
164
164
|
workspaceParams,
|
|
165
|
-
validatedJSON(
|
|
165
|
+
validatedJSON(createDocumentSchema),
|
|
166
166
|
async (context) => {
|
|
167
167
|
try {
|
|
168
168
|
const document = await service.create(
|
|
@@ -211,7 +211,7 @@ export function createDocumentRoutes(
|
|
|
211
211
|
.post(
|
|
212
212
|
'/documents/:documentId/uploads',
|
|
213
213
|
documentParams,
|
|
214
|
-
validatedJSON(
|
|
214
|
+
validatedJSON(createUploadSchema),
|
|
215
215
|
(context) =>
|
|
216
216
|
documentResponse(context, async () =>
|
|
217
217
|
context.json(
|
|
@@ -227,7 +227,7 @@ export function createDocumentRoutes(
|
|
|
227
227
|
.post(
|
|
228
228
|
'/documents/:documentId/images/commit',
|
|
229
229
|
documentParams,
|
|
230
|
-
validatedJSON(
|
|
230
|
+
validatedJSON(commitImageUploadsSchema),
|
|
231
231
|
(context) =>
|
|
232
232
|
documentResponse(context, async () => {
|
|
233
233
|
await service.commitImageUploads(
|
|
@@ -241,7 +241,7 @@ export function createDocumentRoutes(
|
|
|
241
241
|
.post(
|
|
242
242
|
'/documents/:documentId/images/links',
|
|
243
243
|
documentParams,
|
|
244
|
-
validatedJSON(
|
|
244
|
+
validatedJSON(requestImageLinksSchema),
|
|
245
245
|
(context) =>
|
|
246
246
|
documentResponse(context, async () =>
|
|
247
247
|
context.json(
|
|
@@ -256,7 +256,7 @@ export function createDocumentRoutes(
|
|
|
256
256
|
.post(
|
|
257
257
|
'/documents/:documentId/images',
|
|
258
258
|
documentParams,
|
|
259
|
-
validatedJSON(
|
|
259
|
+
validatedJSON(requestImageUploadsSchema),
|
|
260
260
|
(context) =>
|
|
261
261
|
documentResponse(context, async () =>
|
|
262
262
|
context.json(
|
|
@@ -272,7 +272,7 @@ export function createDocumentRoutes(
|
|
|
272
272
|
.post(
|
|
273
273
|
'/uploads/:uploadId/commit',
|
|
274
274
|
uploadParams,
|
|
275
|
-
validatedJSON(
|
|
275
|
+
validatedJSON(commitUploadSchema),
|
|
276
276
|
async (context) => {
|
|
277
277
|
try {
|
|
278
278
|
const document = await service.commitUpload(
|