@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,450 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CommitImageUploadsInput,
|
|
3
|
+
CommitUploadInput,
|
|
4
|
+
CreateUploadInput,
|
|
5
|
+
DocumentSummary,
|
|
6
|
+
ImageUploadOffer,
|
|
7
|
+
RequestImageUploadsInput
|
|
8
|
+
} from '#cloud/contract'
|
|
9
|
+
import type { CloudDatabase } from '#cloud/server/db'
|
|
10
|
+
import { canEditDocument, resolveDocumentAccess } from '#cloud/server/documents/access'
|
|
11
|
+
import {
|
|
12
|
+
DocumentConflictError,
|
|
13
|
+
DocumentForbiddenError,
|
|
14
|
+
DocumentNotFoundError,
|
|
15
|
+
UploadInvalidError
|
|
16
|
+
} from '#cloud/server/documents/errors'
|
|
17
|
+
import type { DocumentImages } from '#cloud/server/documents/images'
|
|
18
|
+
import { writableDocument } from '#cloud/server/documents/limits'
|
|
19
|
+
import { findDocument } from '#cloud/server/documents/repository'
|
|
20
|
+
import type { DocumentServiceOptions } from '#cloud/server/documents/service'
|
|
21
|
+
import type { CreateDocumentUploadResult } from '#cloud/server/documents/types'
|
|
22
|
+
import { announceVersions, recordCheckpoint } from '#cloud/server/documents/versions/checkpoint'
|
|
23
|
+
import type { ObjectStore, StoredObject } from '#cloud/server/objects'
|
|
24
|
+
import { storageLimitReached } from '#cloud/server/policy/storage'
|
|
25
|
+
import { StorageQuotaExceededError, type StorageQuotaService } from '#cloud/server/quota'
|
|
26
|
+
import { isUndefined, limitAsync, omitBy, uniq, uniqBy } from 'es-toolkit'
|
|
27
|
+
import type { Kysely, Transaction } from 'kysely'
|
|
28
|
+
|
|
29
|
+
const UPLOAD_LIFETIME_MS = 15 * 60 * 1000
|
|
30
|
+
/** How many of a save's images are checked and landed at once. */
|
|
31
|
+
const IMAGE_COMMIT_CONCURRENCY = 8
|
|
32
|
+
|
|
33
|
+
/** Whether the stored object is the file the upload declared, which the commit names again. */
|
|
34
|
+
function matchesUpload(
|
|
35
|
+
stored: { checksum: string; byteSize: number; contentType: string },
|
|
36
|
+
upload: { checksum: string; byteSize: number | string | bigint; contentType: string }
|
|
37
|
+
): boolean {
|
|
38
|
+
return (
|
|
39
|
+
stored.checksum === upload.checksum &&
|
|
40
|
+
stored.byteSize === Number(upload.byteSize) &&
|
|
41
|
+
stored.contentType === upload.contentType
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Saving a document: uploads of a new revision and of the images it names, reserved against the
|
|
47
|
+
* workspace's storage, then committed once the store holds what each declared, landing the
|
|
48
|
+
* revision as the document's current one.
|
|
49
|
+
*/
|
|
50
|
+
export function createDocumentUploads(
|
|
51
|
+
database: Kysely<CloudDatabase>,
|
|
52
|
+
objects: ObjectStore,
|
|
53
|
+
{
|
|
54
|
+
quota,
|
|
55
|
+
images,
|
|
56
|
+
options
|
|
57
|
+
}: {
|
|
58
|
+
quota: StorageQuotaService
|
|
59
|
+
images: DocumentImages
|
|
60
|
+
options: Pick<
|
|
61
|
+
DocumentServiceOptions,
|
|
62
|
+
'policy' | 'technicalMaximumUploadBytes' | 'onVersionsChanged'
|
|
63
|
+
>
|
|
64
|
+
}
|
|
65
|
+
) {
|
|
66
|
+
/**
|
|
67
|
+
* Refuses to land an upload once its document's owner holds their whole storage allowance, as
|
|
68
|
+
* when their plan shrank after the upload was offered; an upload already landed is not landed
|
|
69
|
+
* again, so retrying one stays as it was.
|
|
70
|
+
*/
|
|
71
|
+
async function refuseAtStorageLimit(documentId: string): Promise<void> {
|
|
72
|
+
if (await storageLimitReached(database, options.policy, { documentId })) {
|
|
73
|
+
throw new StorageQuotaExceededError('The owner holds their whole storage allowance')
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Makes a committed upload the document's current revision, unless it already was, and records
|
|
79
|
+
* the checkpoint the save adds, if any. Whether the history gained one.
|
|
80
|
+
*/
|
|
81
|
+
async function landRevision(
|
|
82
|
+
transaction: Transaction<CloudDatabase>,
|
|
83
|
+
{
|
|
84
|
+
userId,
|
|
85
|
+
uploadId,
|
|
86
|
+
upload,
|
|
87
|
+
stored,
|
|
88
|
+
revisionId,
|
|
89
|
+
storageObjectId,
|
|
90
|
+
images: revisionImages,
|
|
91
|
+
name,
|
|
92
|
+
kind
|
|
93
|
+
}: {
|
|
94
|
+
userId: string
|
|
95
|
+
uploadId: string
|
|
96
|
+
upload: {
|
|
97
|
+
documentId: string
|
|
98
|
+
workspaceId: string
|
|
99
|
+
baseRevisionId: string | null
|
|
100
|
+
objectKey: string
|
|
101
|
+
}
|
|
102
|
+
stored: { checksum: string; byteSize: number; contentType: string }
|
|
103
|
+
revisionId: string
|
|
104
|
+
storageObjectId: string
|
|
105
|
+
images: CommitUploadInput['images']
|
|
106
|
+
name: CommitUploadInput['name']
|
|
107
|
+
kind: CommitUploadInput['kind']
|
|
108
|
+
}
|
|
109
|
+
): Promise<boolean> {
|
|
110
|
+
const lockedUpload = await transaction
|
|
111
|
+
.selectFrom('upload')
|
|
112
|
+
.select('status')
|
|
113
|
+
.where('id', '=', uploadId)
|
|
114
|
+
.forUpdate()
|
|
115
|
+
.executeTakeFirstOrThrow()
|
|
116
|
+
if (lockedUpload.status === 'committed') return false
|
|
117
|
+
if (lockedUpload.status !== 'finalizing') throw new UploadInvalidError()
|
|
118
|
+
const document = await transaction
|
|
119
|
+
.selectFrom('document')
|
|
120
|
+
.select(['currentRevisionId'])
|
|
121
|
+
.where('id', '=', upload.documentId)
|
|
122
|
+
.forUpdate()
|
|
123
|
+
.executeTakeFirstOrThrow()
|
|
124
|
+
if (document.currentRevisionId !== upload.baseRevisionId) {
|
|
125
|
+
throw new DocumentConflictError()
|
|
126
|
+
}
|
|
127
|
+
await transaction
|
|
128
|
+
.insertInto('storageObject')
|
|
129
|
+
.values({
|
|
130
|
+
id: storageObjectId,
|
|
131
|
+
objectKey: upload.objectKey,
|
|
132
|
+
checksum: stored.checksum,
|
|
133
|
+
byteSize: stored.byteSize,
|
|
134
|
+
contentType: stored.contentType
|
|
135
|
+
})
|
|
136
|
+
.execute()
|
|
137
|
+
await transaction
|
|
138
|
+
.insertInto('documentRevision')
|
|
139
|
+
.values({
|
|
140
|
+
id: revisionId,
|
|
141
|
+
documentId: upload.documentId,
|
|
142
|
+
parentRevisionId: upload.baseRevisionId,
|
|
143
|
+
storageObjectId,
|
|
144
|
+
createdBy: userId
|
|
145
|
+
})
|
|
146
|
+
.execute()
|
|
147
|
+
const attached = await images.attachInTransaction(transaction, {
|
|
148
|
+
workspaceId: upload.workspaceId,
|
|
149
|
+
revisionId,
|
|
150
|
+
images: revisionImages
|
|
151
|
+
})
|
|
152
|
+
if (!attached) throw new UploadInvalidError()
|
|
153
|
+
await transaction
|
|
154
|
+
.updateTable('document')
|
|
155
|
+
.set({
|
|
156
|
+
// A revision may also retitle its document, or say the file it holds is a board.
|
|
157
|
+
...omitBy({ name, kind }, isUndefined),
|
|
158
|
+
currentRevisionId: revisionId,
|
|
159
|
+
version: (expression) => expression('version', '+', 1)
|
|
160
|
+
})
|
|
161
|
+
.where('id', '=', upload.documentId)
|
|
162
|
+
.execute()
|
|
163
|
+
const checkpointed = await recordCheckpoint(transaction, {
|
|
164
|
+
documentId: upload.documentId,
|
|
165
|
+
previousRevisionId: document.currentRevisionId,
|
|
166
|
+
revisionId,
|
|
167
|
+
userId,
|
|
168
|
+
now: new Date()
|
|
169
|
+
})
|
|
170
|
+
await transaction
|
|
171
|
+
.updateTable('upload')
|
|
172
|
+
.set({ status: 'committed', finalizationStartedAt: null })
|
|
173
|
+
.where('id', '=', uploadId)
|
|
174
|
+
.execute()
|
|
175
|
+
await quota.commitInTransaction(transaction, uploadId)
|
|
176
|
+
return checkpointed
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** What committing an upload reads of it and its document. */
|
|
180
|
+
function selectUploads() {
|
|
181
|
+
return database
|
|
182
|
+
.selectFrom('upload')
|
|
183
|
+
.innerJoin('document', 'document.id', 'upload.documentId')
|
|
184
|
+
.select([
|
|
185
|
+
'upload.id',
|
|
186
|
+
'upload.documentId',
|
|
187
|
+
'upload.kind',
|
|
188
|
+
'document.workspaceId',
|
|
189
|
+
'upload.baseRevisionId',
|
|
190
|
+
'upload.objectKey',
|
|
191
|
+
'upload.checksum',
|
|
192
|
+
'upload.byteSize',
|
|
193
|
+
'upload.contentType',
|
|
194
|
+
'upload.multipartUploadId',
|
|
195
|
+
'upload.status',
|
|
196
|
+
'upload.expiresAt'
|
|
197
|
+
])
|
|
198
|
+
}
|
|
199
|
+
type UploadRow = Awaited<ReturnType<ReturnType<typeof selectUploads>['executeTakeFirstOrThrow']>>
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Claims a pending upload, completes it when it came in parts, checks the store holds the file
|
|
203
|
+
* it declared, and lands it with `land`. An upload that fails goes back to pending, so its
|
|
204
|
+
* commit can be tried again.
|
|
205
|
+
*/
|
|
206
|
+
async function finalizeUpload<T>(
|
|
207
|
+
upload: UploadRow,
|
|
208
|
+
multipart: CommitUploadInput['multipart'],
|
|
209
|
+
land: (stored: StoredObject) => Promise<T>
|
|
210
|
+
): Promise<T> {
|
|
211
|
+
if (upload.status !== 'pending' || new Date(upload.expiresAt).getTime() <= Date.now()) {
|
|
212
|
+
throw new UploadInvalidError()
|
|
213
|
+
}
|
|
214
|
+
const claimed = await database
|
|
215
|
+
.updateTable('upload')
|
|
216
|
+
.set({ status: 'finalizing', finalizationStartedAt: new Date() })
|
|
217
|
+
.where('id', '=', upload.id)
|
|
218
|
+
.where('status', '=', 'pending')
|
|
219
|
+
.returning('id')
|
|
220
|
+
.executeTakeFirst()
|
|
221
|
+
if (!claimed) throw new UploadInvalidError()
|
|
222
|
+
try {
|
|
223
|
+
if (multipart) {
|
|
224
|
+
if (
|
|
225
|
+
!objects.capabilities.multipartUpload ||
|
|
226
|
+
multipart.uploadId !== upload.multipartUploadId
|
|
227
|
+
) {
|
|
228
|
+
throw new UploadInvalidError()
|
|
229
|
+
}
|
|
230
|
+
await objects.completeUpload({
|
|
231
|
+
key: upload.objectKey,
|
|
232
|
+
uploadId: multipart.uploadId,
|
|
233
|
+
parts: multipart.parts
|
|
234
|
+
})
|
|
235
|
+
}
|
|
236
|
+
const stored = await objects.head(upload.objectKey)
|
|
237
|
+
if (!stored || !matchesUpload(stored, upload)) throw new UploadInvalidError()
|
|
238
|
+
return await land(stored)
|
|
239
|
+
} catch (error) {
|
|
240
|
+
await database
|
|
241
|
+
.updateTable('upload')
|
|
242
|
+
.set({ status: 'pending', finalizationStartedAt: null })
|
|
243
|
+
.where('id', '=', upload.id)
|
|
244
|
+
.where('status', '=', 'finalizing')
|
|
245
|
+
.execute()
|
|
246
|
+
throw error
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function landImage(upload: UploadRow, stored: StoredObject): Promise<void> {
|
|
251
|
+
return database.transaction().execute((transaction) =>
|
|
252
|
+
images.landInTransaction(transaction, {
|
|
253
|
+
uploadId: upload.id,
|
|
254
|
+
workspaceId: upload.workspaceId,
|
|
255
|
+
objectKey: upload.objectKey,
|
|
256
|
+
stored
|
|
257
|
+
})
|
|
258
|
+
)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async function commitUpload(
|
|
262
|
+
userId: string,
|
|
263
|
+
uploadId: string,
|
|
264
|
+
input: CommitUploadInput
|
|
265
|
+
): Promise<DocumentSummary> {
|
|
266
|
+
const upload = await selectUploads()
|
|
267
|
+
.where('upload.id', '=', uploadId)
|
|
268
|
+
.where('upload.createdBy', '=', userId)
|
|
269
|
+
.executeTakeFirst()
|
|
270
|
+
if (!upload) throw new DocumentNotFoundError()
|
|
271
|
+
const access = await resolveDocumentAccess(database, userId, upload.documentId)
|
|
272
|
+
if (!access) throw new DocumentNotFoundError()
|
|
273
|
+
if (!canEditDocument(access)) throw new DocumentForbiddenError()
|
|
274
|
+
if (input.checksum !== upload.checksum) throw new UploadInvalidError()
|
|
275
|
+
if (upload.status !== 'committed') {
|
|
276
|
+
await refuseAtStorageLimit(upload.documentId)
|
|
277
|
+
const checkpointed =
|
|
278
|
+
upload.kind === 'image'
|
|
279
|
+
? await finalizeUpload(upload, input.multipart, (stored) =>
|
|
280
|
+
landImage(upload, stored).then(() => false)
|
|
281
|
+
)
|
|
282
|
+
: await finalizeUpload(upload, input.multipart, (stored) =>
|
|
283
|
+
database.transaction().execute((transaction) =>
|
|
284
|
+
landRevision(transaction, {
|
|
285
|
+
userId,
|
|
286
|
+
uploadId,
|
|
287
|
+
upload,
|
|
288
|
+
stored,
|
|
289
|
+
revisionId: crypto.randomUUID(),
|
|
290
|
+
storageObjectId: crypto.randomUUID(),
|
|
291
|
+
images: input.images,
|
|
292
|
+
name: input.name,
|
|
293
|
+
kind: input.kind
|
|
294
|
+
})
|
|
295
|
+
)
|
|
296
|
+
)
|
|
297
|
+
if (checkpointed) announceVersions(options.onVersionsChanged, upload.documentId)
|
|
298
|
+
}
|
|
299
|
+
const document = await findDocument(database, userId, upload.documentId)
|
|
300
|
+
if (!document) throw new DocumentNotFoundError()
|
|
301
|
+
return document
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return {
|
|
305
|
+
async createUpload(
|
|
306
|
+
userId: string,
|
|
307
|
+
documentId: string,
|
|
308
|
+
input: CreateUploadInput
|
|
309
|
+
): Promise<CreateDocumentUploadResult> {
|
|
310
|
+
const { document, maximumFileBytes, maximumStorageBytes } = await writableDocument(
|
|
311
|
+
database,
|
|
312
|
+
options,
|
|
313
|
+
userId,
|
|
314
|
+
documentId
|
|
315
|
+
)
|
|
316
|
+
if (document.currentRevisionId !== input.baseRevisionId) throw new DocumentConflictError()
|
|
317
|
+
if (input.byteSize > maximumFileBytes) throw new UploadInvalidError()
|
|
318
|
+
const uploadId = crypto.randomUUID()
|
|
319
|
+
const objectKey = `documents/${document.workspaceId}/${documentId}/uploads/${uploadId}.fig`
|
|
320
|
+
const expiresAt = new Date(Date.now() + UPLOAD_LIFETIME_MS)
|
|
321
|
+
await database.transaction().execute(async (transaction) => {
|
|
322
|
+
await transaction
|
|
323
|
+
.insertInto('upload')
|
|
324
|
+
.values({
|
|
325
|
+
id: uploadId,
|
|
326
|
+
documentId,
|
|
327
|
+
baseRevisionId: input.baseRevisionId,
|
|
328
|
+
objectKey,
|
|
329
|
+
checksum: input.checksum,
|
|
330
|
+
byteSize: input.byteSize,
|
|
331
|
+
contentType: input.contentType,
|
|
332
|
+
multipartUploadId: null,
|
|
333
|
+
status: 'pending',
|
|
334
|
+
finalizationStartedAt: null,
|
|
335
|
+
createdBy: userId,
|
|
336
|
+
expiresAt
|
|
337
|
+
})
|
|
338
|
+
.execute()
|
|
339
|
+
await quota.reserveInTransaction(transaction, {
|
|
340
|
+
workspaceId: document.workspaceId,
|
|
341
|
+
uploadId,
|
|
342
|
+
bytes: input.byteSize,
|
|
343
|
+
expiresAt,
|
|
344
|
+
maximumBytes: maximumStorageBytes
|
|
345
|
+
})
|
|
346
|
+
})
|
|
347
|
+
let objectUpload
|
|
348
|
+
try {
|
|
349
|
+
objectUpload = await objects.createUpload({
|
|
350
|
+
key: objectKey,
|
|
351
|
+
byteSize: input.byteSize,
|
|
352
|
+
checksum: input.checksum,
|
|
353
|
+
contentType: input.contentType,
|
|
354
|
+
expiresAt
|
|
355
|
+
})
|
|
356
|
+
} catch (error) {
|
|
357
|
+
await quota.release(uploadId)
|
|
358
|
+
await database
|
|
359
|
+
.updateTable('upload')
|
|
360
|
+
.set({ status: 'abandoned' })
|
|
361
|
+
.where('id', '=', uploadId)
|
|
362
|
+
.execute()
|
|
363
|
+
throw error
|
|
364
|
+
}
|
|
365
|
+
if (objectUpload.kind === 'multipart') {
|
|
366
|
+
await database
|
|
367
|
+
.updateTable('upload')
|
|
368
|
+
.set({ multipartUploadId: objectUpload.uploadId })
|
|
369
|
+
.where('id', '=', uploadId)
|
|
370
|
+
.execute()
|
|
371
|
+
}
|
|
372
|
+
return { id: uploadId, upload: objectUpload }
|
|
373
|
+
},
|
|
374
|
+
|
|
375
|
+
/** Uploads for the images a save of the document will name that its workspace lacks. */
|
|
376
|
+
async requestImageUploads(
|
|
377
|
+
userId: string,
|
|
378
|
+
documentId: string,
|
|
379
|
+
input: RequestImageUploadsInput
|
|
380
|
+
): Promise<{ uploads: ImageUploadOffer[] }> {
|
|
381
|
+
const { document, maximumFileBytes, maximumStorageBytes } = await writableDocument(
|
|
382
|
+
database,
|
|
383
|
+
options,
|
|
384
|
+
userId,
|
|
385
|
+
documentId
|
|
386
|
+
)
|
|
387
|
+
if (input.images.some((image) => image.byteSize > maximumFileBytes)) {
|
|
388
|
+
throw new UploadInvalidError()
|
|
389
|
+
}
|
|
390
|
+
return {
|
|
391
|
+
uploads: await images.requestUploads({
|
|
392
|
+
userId,
|
|
393
|
+
documentId,
|
|
394
|
+
workspaceId: document.workspaceId,
|
|
395
|
+
images: input.images,
|
|
396
|
+
expiresAt: new Date(Date.now() + UPLOAD_LIFETIME_MS),
|
|
397
|
+
maximumBytes: maximumStorageBytes
|
|
398
|
+
})
|
|
399
|
+
}
|
|
400
|
+
},
|
|
401
|
+
commitUpload,
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Commits the image uploads a save asked for in one request, however many there are: each
|
|
405
|
+
* must be an image upload this person made for the document.
|
|
406
|
+
*/
|
|
407
|
+
async commitImageUploads(
|
|
408
|
+
userId: string,
|
|
409
|
+
documentId: string,
|
|
410
|
+
uploads: CommitImageUploadsInput['uploads']
|
|
411
|
+
): Promise<void> {
|
|
412
|
+
const access = await resolveDocumentAccess(database, userId, documentId)
|
|
413
|
+
if (!access) throw new DocumentNotFoundError()
|
|
414
|
+
if (!canEditDocument(access)) throw new DocumentForbiddenError()
|
|
415
|
+
const ids = uniq(uploads.map((upload) => upload.uploadId))
|
|
416
|
+
const rows = new Map(
|
|
417
|
+
(
|
|
418
|
+
await selectUploads()
|
|
419
|
+
.where('upload.id', 'in', ids)
|
|
420
|
+
.where('upload.documentId', '=', documentId)
|
|
421
|
+
.where('upload.createdBy', '=', userId)
|
|
422
|
+
.execute()
|
|
423
|
+
).map((row) => [row.id, row])
|
|
424
|
+
)
|
|
425
|
+
if (rows.size !== ids.length || [...rows.values()].some((row) => row.kind !== 'image')) {
|
|
426
|
+
throw new UploadInvalidError()
|
|
427
|
+
}
|
|
428
|
+
for (const commit of uploads) {
|
|
429
|
+
if (rows.get(commit.uploadId)?.checksum !== commit.checksum) throw new UploadInvalidError()
|
|
430
|
+
}
|
|
431
|
+
if ([...rows.values()].some((row) => row.status !== 'committed')) {
|
|
432
|
+
await refuseAtStorageLimit(documentId)
|
|
433
|
+
}
|
|
434
|
+
// Each image is its own object, so a few are checked and landed at once, each once however
|
|
435
|
+
// often the request names it.
|
|
436
|
+
const land = limitAsync(
|
|
437
|
+
(upload: UploadRow, multipart: CommitUploadInput['multipart']) =>
|
|
438
|
+
finalizeUpload(upload, multipart, (stored) => landImage(upload, stored)),
|
|
439
|
+
IMAGE_COMMIT_CONCURRENCY
|
|
440
|
+
)
|
|
441
|
+
await Promise.all(
|
|
442
|
+
uniqBy(uploads, (commit) => commit.uploadId).map(async (commit) => {
|
|
443
|
+
const upload = rows.get(commit.uploadId)
|
|
444
|
+
if (!upload) throw new UploadInvalidError()
|
|
445
|
+
if (upload.status !== 'committed') await land(upload, commit.multipart)
|
|
446
|
+
})
|
|
447
|
+
)
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
duplicateDocumentVersionSchema,
|
|
3
|
+
saveDocumentVersionSchema,
|
|
4
|
+
updateDocumentVersionSchema
|
|
5
5
|
} from '#cloud/contract'
|
|
6
6
|
import { documentDomainError, type DocumentRouteEnvironment } from '#cloud/server/documents/routes'
|
|
7
7
|
import {
|
|
@@ -19,7 +19,6 @@ const pageSchema = v.object({
|
|
|
19
19
|
before: v.optional(v.pipe(v.string(), v.uuid())),
|
|
20
20
|
limit: v.optional(v.pipe(v.string(), v.toNumber(), v.integer(), v.minValue(1)))
|
|
21
21
|
})
|
|
22
|
-
const parsePage = (input: unknown) => v.parse(pageSchema, input)
|
|
23
22
|
|
|
24
23
|
async function answer(context: Context, run: () => Promise<Response>): Promise<Response> {
|
|
25
24
|
try {
|
|
@@ -34,7 +33,7 @@ async function answer(context: Context, run: () => Promise<Response>): Promise<R
|
|
|
34
33
|
/** A document's version history: listing, naming, opening, restoring, and duplicating versions. */
|
|
35
34
|
export function createDocumentVersionRoutes(service: DocumentVersionService) {
|
|
36
35
|
return new Hono<DocumentRouteEnvironment>()
|
|
37
|
-
.get('/documents/:documentId/versions', documentParams, validatedQuery(
|
|
36
|
+
.get('/documents/:documentId/versions', documentParams, validatedQuery(pageSchema), (context) =>
|
|
38
37
|
answer(context, async () =>
|
|
39
38
|
context.json(
|
|
40
39
|
await service.list(
|
|
@@ -48,7 +47,7 @@ export function createDocumentVersionRoutes(service: DocumentVersionService) {
|
|
|
48
47
|
.post(
|
|
49
48
|
'/documents/:documentId/versions',
|
|
50
49
|
documentParams,
|
|
51
|
-
validatedJSON(
|
|
50
|
+
validatedJSON(saveDocumentVersionSchema),
|
|
52
51
|
(context) =>
|
|
53
52
|
answer(context, async () =>
|
|
54
53
|
context.json(
|
|
@@ -66,7 +65,7 @@ export function createDocumentVersionRoutes(service: DocumentVersionService) {
|
|
|
66
65
|
.patch(
|
|
67
66
|
'/documents/:documentId/versions/:versionId',
|
|
68
67
|
documentVersionParams,
|
|
69
|
-
validatedJSON(
|
|
68
|
+
validatedJSON(updateDocumentVersionSchema),
|
|
70
69
|
(context) =>
|
|
71
70
|
answer(context, async () =>
|
|
72
71
|
context.json({
|
|
@@ -104,7 +103,7 @@ export function createDocumentVersionRoutes(service: DocumentVersionService) {
|
|
|
104
103
|
.post(
|
|
105
104
|
'/documents/:documentId/versions/:versionId/duplicate',
|
|
106
105
|
documentVersionParams,
|
|
107
|
-
validatedJSON(
|
|
106
|
+
validatedJSON(duplicateDocumentVersionSchema),
|
|
108
107
|
(context) =>
|
|
109
108
|
answer(context, async () =>
|
|
110
109
|
context.json(
|
|
@@ -8,10 +8,14 @@ import type {
|
|
|
8
8
|
UpdateDocumentVersionInput
|
|
9
9
|
} from '#cloud/contract'
|
|
10
10
|
import { workspaceRoleCan } from '#cloud/server/auth/access-control'
|
|
11
|
-
import type
|
|
11
|
+
import { userIdText, type CloudDatabase } from '#cloud/server/db'
|
|
12
12
|
import { canEditDocument, resolveDocumentAccess } from '#cloud/server/documents/access'
|
|
13
13
|
import { DocumentForbiddenError, DocumentNotFoundError } from '#cloud/server/documents/errors'
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
copyRevisionImages,
|
|
16
|
+
DOWNLOAD_LIFETIME_MS,
|
|
17
|
+
revisionImageDownloads
|
|
18
|
+
} from '#cloud/server/documents/images'
|
|
15
19
|
import { findDocument, insertDocument, workspaceRole } from '#cloud/server/documents/repository'
|
|
16
20
|
import { documentSummary, getDocumentSummaryRow } from '#cloud/server/documents/summary'
|
|
17
21
|
import { logCloud, loggedError } from '#cloud/server/logging'
|
|
@@ -23,7 +27,6 @@ import type { Kysely, Transaction } from 'kysely'
|
|
|
23
27
|
import { announceVersions, keepRevision } from './checkpoint'
|
|
24
28
|
import { historyStart } from './history'
|
|
25
29
|
|
|
26
|
-
const DOWNLOAD_LIFETIME_MS = 5 * 60 * 1000
|
|
27
30
|
const DEFAULT_PAGE_SIZE = 50
|
|
28
31
|
const MAXIMUM_PAGE_SIZE = 100
|
|
29
32
|
|
|
@@ -73,15 +76,7 @@ export function createDocumentVersionService(
|
|
|
73
76
|
function versions() {
|
|
74
77
|
return database
|
|
75
78
|
.selectFrom('documentVersion')
|
|
76
|
-
.leftJoin('user', (join) =>
|
|
77
|
-
join.on((expression) =>
|
|
78
|
-
expression(
|
|
79
|
-
expression.cast(expression.ref('user.id'), 'text'),
|
|
80
|
-
'=',
|
|
81
|
-
expression.ref('documentVersion.createdBy')
|
|
82
|
-
)
|
|
83
|
-
)
|
|
84
|
-
)
|
|
79
|
+
.leftJoin('user', (join) => join.onRef(userIdText, '=', 'documentVersion.createdBy'))
|
|
85
80
|
.select([
|
|
86
81
|
'documentVersion.id',
|
|
87
82
|
'documentVersion.revisionId',
|
|
@@ -145,6 +140,41 @@ export function createDocumentVersionService(
|
|
|
145
140
|
return stored
|
|
146
141
|
}
|
|
147
142
|
|
|
143
|
+
/** A document's history for a caller that already let the reader in, and where it starts. */
|
|
144
|
+
async function sharedHistory(documentId: string) {
|
|
145
|
+
const document = await getDocumentSummaryRow(database, documentId)
|
|
146
|
+
if (!document) throw new DocumentNotFoundError()
|
|
147
|
+
const start = await historyStart(
|
|
148
|
+
database,
|
|
149
|
+
options.policy,
|
|
150
|
+
deploymentMode,
|
|
151
|
+
document.workspaceId,
|
|
152
|
+
new Date()
|
|
153
|
+
)
|
|
154
|
+
return { document, start }
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** A version's stored file, with where to download it and the images it names. */
|
|
158
|
+
async function downloadVersion(
|
|
159
|
+
document: Awaited<ReturnType<typeof sharedHistory>>['document'],
|
|
160
|
+
version: VersionRow
|
|
161
|
+
): Promise<DocumentVersionDownload> {
|
|
162
|
+
const stored = await storedRevision(database, version.revisionId)
|
|
163
|
+
const expiresAt = new Date(Date.now() + DOWNLOAD_LIFETIME_MS)
|
|
164
|
+
return {
|
|
165
|
+
document: {
|
|
166
|
+
document: documentSummary(document),
|
|
167
|
+
revisionId: version.revisionId,
|
|
168
|
+
byteSize: Number(stored.byteSize),
|
|
169
|
+
checksum: stored.checksum,
|
|
170
|
+
contentType: stored.contentType,
|
|
171
|
+
download: await objects.createDownload({ key: stored.objectKey, expiresAt }),
|
|
172
|
+
images: await revisionImageDownloads(database, objects, version.revisionId, expiresAt)
|
|
173
|
+
},
|
|
174
|
+
version: versionOf(version, document.currentRevisionId)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
148
178
|
return {
|
|
149
179
|
async list(
|
|
150
180
|
userId: string,
|
|
@@ -242,21 +272,51 @@ export function createDocumentVersionService(
|
|
|
242
272
|
versionId: string
|
|
243
273
|
): Promise<DocumentVersionDownload> {
|
|
244
274
|
const { document, start } = await openHistory(userId, documentId, false)
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
275
|
+
return downloadVersion(document, await findVersion(documentId, versionId, start))
|
|
276
|
+
},
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* The named versions of several documents of one workspace, newest first, each list keyed by
|
|
280
|
+
* its document, for a caller that already let the reader in, such as the community gallery;
|
|
281
|
+
* the workspace's history limit still applies, and one query reads them all.
|
|
282
|
+
*/
|
|
283
|
+
async namedSharedIn(
|
|
284
|
+
workspaceId: string,
|
|
285
|
+
documents: { id: string; currentRevisionId: string | null }[]
|
|
286
|
+
): Promise<Map<string, DocumentVersion[]>> {
|
|
287
|
+
const named = new Map(documents.map((document) => [document.id, [] as DocumentVersion[]]))
|
|
288
|
+
if (documents.length === 0) return named
|
|
289
|
+
const start = await historyStart(
|
|
290
|
+
database,
|
|
291
|
+
options.policy,
|
|
292
|
+
deploymentMode,
|
|
293
|
+
workspaceId,
|
|
294
|
+
new Date()
|
|
295
|
+
)
|
|
296
|
+
let query = versions()
|
|
297
|
+
.select('documentVersion.documentId')
|
|
298
|
+
.where('documentVersion.documentId', 'in', [...named.keys()])
|
|
299
|
+
.where('documentVersion.kind', '=', 'named')
|
|
300
|
+
if (start) query = query.where('documentVersion.createdAt', '>=', start)
|
|
301
|
+
const rows = await query.orderBy('documentVersion.createdAt', 'desc').execute()
|
|
302
|
+
const current = new Map(
|
|
303
|
+
documents.map((document) => [document.id, document.currentRevisionId])
|
|
304
|
+
)
|
|
305
|
+
for (const row of rows) {
|
|
306
|
+
named.get(row.documentId)?.push(versionOf(row, current.get(row.documentId) ?? null))
|
|
259
307
|
}
|
|
308
|
+
return named
|
|
309
|
+
},
|
|
310
|
+
|
|
311
|
+
/** A named version with where to download it, for a caller that already let the reader in. */
|
|
312
|
+
async downloadNamedShared(
|
|
313
|
+
documentId: string,
|
|
314
|
+
versionId: string
|
|
315
|
+
): Promise<DocumentVersionDownload> {
|
|
316
|
+
const { document, start } = await sharedHistory(documentId)
|
|
317
|
+
const version = await findVersion(documentId, versionId, start)
|
|
318
|
+
if (version.kind !== 'named') throw new DocumentNotFoundError()
|
|
319
|
+
return downloadVersion(document, version)
|
|
260
320
|
},
|
|
261
321
|
|
|
262
322
|
/**
|
|
@@ -15,6 +15,7 @@ export function createInvitationOutbox(email: TransactionalEmailService): Invita
|
|
|
15
15
|
idempotencyKey: `document-invitation/${message.deliveryId}`,
|
|
16
16
|
kind: 'document-invitation',
|
|
17
17
|
recipientEmail: message.recipientEmail,
|
|
18
|
+
fallbackLocale: message.locale,
|
|
18
19
|
payload: {
|
|
19
20
|
inviterName: message.inviterName,
|
|
20
21
|
documentName: message.documentName,
|