@open-pencil/cloud 0.17.0-beta.1 → 0.17.0-beta.4
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 +1 -1
- package/dist/bin/{ai-relay.mjs → services.mjs} +8 -8
- package/dist/bin/services.mjs.map +1 -0
- package/dist/client.d.ts +236 -46
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +649 -400
- package/dist/client.js.map +1 -1
- package/dist/contract.d.ts +2 -2
- package/dist/contract.js +2 -2
- package/dist/contract2.js +680 -443
- package/dist/contract2.js.map +1 -1
- package/dist/email.d.ts +9 -1
- package/dist/email.d.ts.map +1 -1
- package/dist/email.js +99 -58
- package/dist/email.js.map +1 -1
- package/dist/index.d.ts +468 -64
- package/dist/index.d.ts.map +1 -1
- package/dist/listen.mjs +575 -738
- package/dist/listen.mjs.map +1 -1
- package/dist/runtime-node.d.mts +6564 -2934
- package/dist/runtime-node.d.mts.map +1 -1
- package/dist/runtime-node.mjs +6 -5
- package/dist/runtime-node.mjs.map +1 -1
- package/dist/server.d.ts +8931 -4198
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +5260 -3859
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +5686 -3736
- package/dist/server.mjs.map +1 -1
- package/dist/server2.mjs +101 -79
- package/dist/server2.mjs.map +1 -1
- package/package.json +9 -6
- package/src/admin/api/routes.ts +103 -33
- package/src/admin/audit/service.ts +25 -6
- package/src/admin/documents/service.ts +361 -0
- package/src/admin/errors.ts +9 -1
- package/src/admin/index.ts +6 -0
- package/src/admin/operations/service.ts +7 -0
- package/src/admin/reports/service.ts +147 -0
- package/src/admin/schema.ts +6 -0
- package/src/client/api.ts +36 -21
- package/src/client/auth/navigation.ts +6 -5
- package/src/client/index.ts +7 -7
- package/src/client/portal/account.ts +25 -0
- package/src/client/portal/administration.ts +56 -0
- package/src/client/{ai.ts → services.ts} +44 -27
- package/src/contract/account.ts +58 -2
- package/src/contract/admin/index.ts +67 -3
- package/src/contract/collaboration.ts +6 -1
- package/src/contract/discovery.ts +22 -4
- package/src/contract/documents.ts +27 -0
- package/src/contract/entitlements.ts +2 -2
- package/src/contract/index.ts +63 -37
- package/src/contract/relay.ts +6 -0
- package/src/contract/reports.ts +42 -0
- package/src/contract/services.ts +233 -0
- package/src/contract/sharing.ts +3 -9
- package/src/email/render.ts +26 -0
- package/src/email/schema.ts +11 -1
- package/src/email/templates/brand.ts +1 -1
- package/src/runtime/cloudflare/environment.ts +31 -6
- package/src/runtime/cloudflare/index.ts +1 -1
- package/src/runtime/cloudflare/logging.ts +15 -0
- package/src/runtime/cloudflare/maintenance.ts +31 -0
- package/src/runtime/cloudflare/relay/index.ts +176 -0
- package/src/runtime/cloudflare/relay/sockets.ts +112 -0
- package/src/runtime/cloudflare/worker.ts +89 -26
- package/src/runtime/node/application.ts +5 -3
- package/src/runtime/node/bootstrap.ts +20 -4
- package/src/runtime/node/cleanup.ts +16 -3
- package/src/runtime/node/entitlements/main.ts +14 -11
- package/src/runtime/node/index.ts +1 -1
- package/src/runtime/node/migrate.ts +5 -1
- package/src/runtime/node/relay.ts +8 -2
- package/src/runtime/node/request-id.ts +13 -0
- package/src/runtime/node/server.ts +71 -15
- package/src/runtime/node/{ai-relay → services}/main.ts +6 -6
- package/src/runtime/node/{ai-relay → services}/server.ts +18 -18
- package/src/runtime/postgres/database.ts +20 -1
- package/src/runtime/posthog/errors.ts +32 -0
- package/src/runtime/s3/objects.ts +50 -1
- package/src/runtime/site/server.ts +33 -4
- package/src/server/account/actions.ts +5 -0
- package/src/server/account/deletion.ts +302 -0
- package/src/server/account/routes.ts +47 -3
- package/src/server/account/terms.ts +42 -0
- package/src/server/api/router.ts +12 -7
- package/src/server/api/types.ts +9 -0
- package/src/server/app.ts +93 -15
- package/src/server/auth/access-control.ts +63 -0
- package/src/server/auth/adapter.ts +11 -0
- package/src/server/auth/endpoints.ts +5 -1
- package/src/server/auth/factory.ts +30 -3
- package/src/server/auth/index.ts +10 -1
- package/src/server/cleanup/configured.ts +12 -5
- package/src/server/cleanup/documents.ts +165 -71
- package/src/server/cleanup/objects.ts +10 -2
- package/src/server/cleanup/revisions.ts +24 -7
- package/src/server/cleanup/uploads.ts +8 -2
- package/src/server/cleanup/worker.ts +5 -2
- package/src/server/collaboration/index.ts +3 -0
- package/src/server/collaboration/relay/connection.ts +196 -0
- package/src/server/collaboration/relay/documents.ts +13 -10
- package/src/server/collaboration/relay/hub.ts +279 -195
- package/src/server/collaboration/relay/index.ts +3 -1
- package/src/server/collaboration/relay/log.ts +79 -0
- package/src/server/collaboration/relay/persistence.ts +147 -22
- package/src/server/collaboration/relay/resume.ts +28 -0
- package/src/server/collaboration/routes.ts +27 -16
- package/src/server/collaboration/service.ts +27 -31
- package/src/server/config/deployment.ts +35 -4
- package/src/server/config/public.ts +5 -4
- package/src/server/config/schema.ts +104 -16
- package/src/server/db/expressions.ts +15 -1
- package/src/server/db/migrate.ts +34 -114
- package/src/server/db/migrations/001_accounts.ts +79 -0
- package/src/server/db/migrations/002_workspaces.ts +48 -0
- package/src/server/db/migrations/003_storage.ts +44 -0
- package/src/server/db/migrations/004_documents.ts +193 -0
- package/src/server/db/migrations/005_sharing.ts +95 -0
- package/src/server/db/migrations/006_operations.ts +110 -0
- package/src/server/db/migrations/007_trash.ts +33 -0
- package/src/server/db/migrations/008_terms.ts +18 -0
- package/src/server/db/migrations/schema.ts +71 -0
- package/src/server/db/tables.ts +70 -7
- package/src/server/documents/access.ts +66 -55
- package/src/server/documents/errors.ts +7 -0
- package/src/server/documents/images.ts +2 -1
- package/src/server/documents/limits.ts +9 -9
- package/src/server/documents/purge.ts +75 -0
- package/src/server/documents/repository.ts +2 -0
- package/src/server/documents/routes.ts +132 -80
- package/src/server/documents/service.ts +18 -4
- package/src/server/documents/summary.ts +1 -0
- package/src/server/documents/trash.ts +203 -0
- package/src/server/documents/versions/checkpoint.ts +2 -1
- package/src/server/documents/versions/history.ts +11 -7
- package/src/server/documents/versions/routes.ts +36 -25
- package/src/server/documents/versions/service.ts +22 -4
- package/src/server/errors/index.ts +99 -0
- package/src/server/errors/posthog.ts +80 -0
- package/src/server/index.ts +56 -16
- package/src/server/internal/index.ts +3 -3
- package/src/server/internal/routes.ts +7 -15
- package/src/server/internal/schema.ts +1 -1
- package/src/server/internal/service.ts +17 -23
- package/src/server/invitations/budget.ts +66 -0
- package/src/server/invitations/index.ts +1 -0
- package/src/server/logging.ts +76 -0
- package/src/server/objects/types.ts +12 -0
- package/src/server/pictures/routes.ts +4 -2
- package/src/server/pictures/service.ts +2 -1
- package/src/server/policy/database.ts +39 -25
- package/src/server/policy/index.ts +2 -1
- package/src/server/policy/keys.ts +5 -2
- package/src/server/policy/policy.ts +1 -0
- package/src/server/policy/schema.ts +2 -2
- package/src/server/policy/service.ts +12 -9
- package/src/server/policy/static.ts +5 -5
- package/src/server/policy/workspace.ts +41 -0
- package/src/server/quota/reconcile.ts +2 -0
- package/src/server/quota/storage.ts +69 -31
- package/src/server/rate-limit/cleanup.ts +17 -5
- package/src/server/rate-limit/index.ts +4 -1
- package/src/server/rate-limit/middleware.ts +100 -12
- package/src/server/reports/index.ts +8 -0
- package/src/server/reports/routes.ts +37 -0
- package/src/server/reports/service.ts +123 -0
- package/src/server/services/errors.ts +7 -0
- package/src/server/services/index.ts +8 -0
- package/src/server/{ai → services}/keys.ts +11 -11
- package/src/server/services/routes.ts +47 -0
- package/src/server/{ai/service.ts → services/tokens.ts} +23 -20
- package/src/server/sharing/capabilities/service.ts +68 -22
- package/src/server/sharing/document-routes.ts +30 -22
- package/src/server/sharing/grants/service.ts +11 -18
- package/src/server/sharing/http.ts +4 -0
- package/src/server/sharing/invitations/service.ts +21 -11
- package/src/server/sharing/policy.ts +9 -14
- package/src/server/sharing/routes.ts +108 -85
- package/src/server/sharing/service.ts +1 -17
- package/src/server/validation.ts +59 -2
- package/src/server/workspaces/index.ts +1 -0
- package/src/server/workspaces/members.ts +89 -38
- package/src/server/workspaces/repository.ts +2 -1
- package/src/server/workspaces/routes.ts +67 -45
- package/src/{ai-relay → services}/app.ts +48 -44
- package/src/{ai-relay → services}/config.ts +25 -19
- package/src/services/db/index.ts +10 -0
- package/src/services/db/migrate.ts +37 -0
- package/src/{ai-relay/db/migrations/001_usage.ts → services/db/migrations/001_baseline.ts} +18 -7
- package/src/services/db/schema.ts +22 -0
- package/src/services/index.ts +18 -0
- package/src/{ai-relay → services}/metering.ts +2 -2
- package/src/{ai-relay → services}/usage.ts +43 -19
- package/dist/bin/ai-relay.mjs.map +0 -1
- package/src/ai-relay/db/index.ts +0 -10
- package/src/ai-relay/db/migrate.ts +0 -32
- package/src/ai-relay/db/schema.ts +0 -20
- package/src/ai-relay/index.ts +0 -18
- package/src/contract/ai.ts +0 -150
- package/src/runtime/cloudflare/relay.ts +0 -136
- package/src/server/ai/errors.ts +0 -7
- package/src/server/ai/index.ts +0 -4
- package/src/server/ai/routes.ts +0 -43
- package/src/server/auth/workspace-access.ts +0 -23
- package/src/server/db/migrations/001_foundation.ts +0 -164
- package/src/server/db/migrations/002_upload_cleanup_claims.ts +0 -34
- package/src/server/db/migrations/003_document_cleanup_claims.ts +0 -23
- package/src/server/db/migrations/004_document_sharing.ts +0 -82
- package/src/server/db/migrations/005_document_collaboration_epoch.ts +0 -13
- package/src/server/db/migrations/006_invitation_continuation.ts +0 -27
- package/src/server/db/migrations/007_collaboration_state.ts +0 -25
- package/src/server/db/migrations/008_storage_reservations.ts +0 -37
- package/src/server/db/migrations/009_workspace_entitlements.ts +0 -22
- package/src/server/db/migrations/010_upload_finalization.ts +0 -22
- package/src/server/db/migrations/011_upload_finalization_lease.ts +0 -12
- package/src/server/db/migrations/012_transactional_email.ts +0 -48
- package/src/server/db/migrations/013_admin_enrollment.ts +0 -54
- package/src/server/db/migrations/014_enrollment_email_kinds.ts +0 -30
- package/src/server/db/migrations/015_cloud_rate_limit.ts +0 -22
- package/src/server/db/migrations/016_auth_schema.ts +0 -16
- package/src/server/db/migrations/017_authentication_email_kinds.ts +0 -32
- package/src/server/db/migrations/018_authentication_mfa.ts +0 -78
- package/src/server/db/migrations/019_better_auth_account_issuer.ts +0 -42
- package/src/server/db/migrations/020_workspace_invitations.ts +0 -57
- package/src/server/db/migrations/021_document_versions.ts +0 -66
- package/src/server/db/migrations/022_entitlement_external_version.ts +0 -17
- package/src/server/db/migrations/023_document_images.ts +0 -61
- package/src/server/db/migrations/024_account_activity.ts +0 -66
- package/src/server/db/migrations/025_table_names.ts +0 -58
- package/src/server/db/migrations/026_user_picture.ts +0 -30
- package/src/server/db/migrations/027_document_kind.ts +0 -19
- package/src/server/db/migrations/helpers.ts +0 -78
- /package/dist/bin/{ai-relay.d.mts → services.d.mts} +0 -0
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import { AdminDomainError } from '#cloud/admin/errors'
|
|
2
|
+
import {
|
|
3
|
+
containsPattern,
|
|
4
|
+
countEachFilter,
|
|
5
|
+
listSearch,
|
|
6
|
+
listWindow,
|
|
7
|
+
type AdminListQuery,
|
|
8
|
+
type ListFilters
|
|
9
|
+
} from '#cloud/admin/list'
|
|
10
|
+
import { isUUID } from '#cloud/admin/schema'
|
|
11
|
+
import {
|
|
12
|
+
cloudAdminDocumentFilterSchema,
|
|
13
|
+
type CloudAdminDocument,
|
|
14
|
+
type CloudAdminDocumentFilter
|
|
15
|
+
} from '#cloud/contract'
|
|
16
|
+
import type { CloudDatabase } from '#cloud/server/db'
|
|
17
|
+
import { unmarkPurged } from '#cloud/server/documents/purge'
|
|
18
|
+
import { dateString } from '#cloud/server/sharing/contracts'
|
|
19
|
+
import { uniq } from 'es-toolkit'
|
|
20
|
+
import type { ExpressionBuilder, Kysely, Transaction } from 'kysely'
|
|
21
|
+
|
|
22
|
+
type DocumentExpression = ExpressionBuilder<CloudDatabase, 'document'>
|
|
23
|
+
|
|
24
|
+
/** Whether reports about the document are still waiting for a decision. */
|
|
25
|
+
const reported = (expression: DocumentExpression) =>
|
|
26
|
+
expression.exists(
|
|
27
|
+
expression
|
|
28
|
+
.selectFrom('documentReport')
|
|
29
|
+
.select('documentReport.id')
|
|
30
|
+
.whereRef('documentReport.documentId', '=', 'document.id')
|
|
31
|
+
.where('documentReport.status', '=', 'open')
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
const live = (expression: DocumentExpression) => expression('document.deletedAt', 'is', null)
|
|
35
|
+
|
|
36
|
+
const FILTERS: ListFilters<CloudAdminDocumentFilter, 'document'> = {
|
|
37
|
+
all: live,
|
|
38
|
+
reported: (expression) => expression.and([live(expression), reported(expression)]),
|
|
39
|
+
disabled: (expression) =>
|
|
40
|
+
expression.and([live(expression), expression('document.disabledAt', 'is not', null)]),
|
|
41
|
+
purged: (expression) => expression('document.purgedAt', 'is not', null)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* What the console lists: live documents, and those deleted forever an administrator can still
|
|
46
|
+
* restore, inside the grace and not yet being destroyed.
|
|
47
|
+
*/
|
|
48
|
+
function listable(graceSince: Date) {
|
|
49
|
+
return (expression: DocumentExpression) =>
|
|
50
|
+
expression.or([
|
|
51
|
+
live(expression),
|
|
52
|
+
expression.and([
|
|
53
|
+
expression('document.purgedAt', '>', graceSince),
|
|
54
|
+
expression('document.cleanupClaimId', 'is', null)
|
|
55
|
+
])
|
|
56
|
+
])
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Documents whose name, ID, or maker's name or email has the search in it. */
|
|
60
|
+
function searchCondition(search: string) {
|
|
61
|
+
const pattern = containsPattern(search)
|
|
62
|
+
return (expression: DocumentExpression) =>
|
|
63
|
+
expression.or([
|
|
64
|
+
expression('document.name', 'ilike', pattern),
|
|
65
|
+
expression(expression.cast('document.id', 'text'), '=', search.toLowerCase()),
|
|
66
|
+
expression.exists(
|
|
67
|
+
expression
|
|
68
|
+
.selectFrom('user')
|
|
69
|
+
.select('user.id')
|
|
70
|
+
.where((inner) =>
|
|
71
|
+
inner(inner.cast('user.id', 'text'), '=', inner.ref('document.createdBy'))
|
|
72
|
+
)
|
|
73
|
+
.where((inner) =>
|
|
74
|
+
inner.or([inner('user.email', 'ilike', pattern), inner('user.name', 'ilike', pattern)])
|
|
75
|
+
)
|
|
76
|
+
)
|
|
77
|
+
])
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The documents with these IDs as the console shows them, in no particular order; with
|
|
82
|
+
* `purgeGraceMs`, when cleanup destroys one deleted forever.
|
|
83
|
+
*/
|
|
84
|
+
export async function adminDocuments(
|
|
85
|
+
database: Kysely<CloudDatabase>,
|
|
86
|
+
documentIds: readonly string[],
|
|
87
|
+
purgeGraceMs?: number
|
|
88
|
+
): Promise<Map<string, CloudAdminDocument>> {
|
|
89
|
+
const ids = uniq(documentIds).filter(isUUID)
|
|
90
|
+
if (ids.length === 0) return new Map()
|
|
91
|
+
const rows = await database
|
|
92
|
+
.selectFrom('document')
|
|
93
|
+
.innerJoin('workspace', 'workspace.id', 'document.workspaceId')
|
|
94
|
+
.select((expression) => [
|
|
95
|
+
'document.id',
|
|
96
|
+
'document.name',
|
|
97
|
+
'document.createdBy',
|
|
98
|
+
'document.createdAt',
|
|
99
|
+
'document.updatedAt',
|
|
100
|
+
'document.disabledAt',
|
|
101
|
+
'document.disabledReason',
|
|
102
|
+
'document.purgedAt',
|
|
103
|
+
'workspace.id as workspaceId',
|
|
104
|
+
'workspace.name as workspaceName',
|
|
105
|
+
expression
|
|
106
|
+
.selectFrom('documentReport')
|
|
107
|
+
.select((inner) => inner.fn.countAll<string>().as('count'))
|
|
108
|
+
.whereRef('documentReport.documentId', '=', 'document.id')
|
|
109
|
+
.where('documentReport.status', '=', 'open')
|
|
110
|
+
.as('openReports')
|
|
111
|
+
])
|
|
112
|
+
.where('document.id', 'in', ids)
|
|
113
|
+
.execute()
|
|
114
|
+
const ownerIds = uniq(rows.map((row) => row.createdBy)).filter(isUUID)
|
|
115
|
+
const owners = ownerIds.length
|
|
116
|
+
? await database
|
|
117
|
+
.selectFrom('user')
|
|
118
|
+
.select(['id', 'name', 'email'])
|
|
119
|
+
.where('id', 'in', ownerIds)
|
|
120
|
+
.execute()
|
|
121
|
+
: []
|
|
122
|
+
const ownerById = new Map(owners.map((owner) => [owner.id, owner]))
|
|
123
|
+
return new Map(
|
|
124
|
+
rows.map((row) => [
|
|
125
|
+
row.id,
|
|
126
|
+
{
|
|
127
|
+
id: row.id,
|
|
128
|
+
name: row.name,
|
|
129
|
+
workspace: { id: row.workspaceId, name: row.workspaceName },
|
|
130
|
+
owner: ownerById.get(row.createdBy) ?? null,
|
|
131
|
+
createdAt: dateString(row.createdAt) ?? '',
|
|
132
|
+
updatedAt: dateString(row.updatedAt) ?? '',
|
|
133
|
+
disabledAt: dateString(row.disabledAt),
|
|
134
|
+
disabledReason: row.disabledReason,
|
|
135
|
+
openReports: Number(row.openReports ?? 0),
|
|
136
|
+
purgedAt: dateString(row.purgedAt),
|
|
137
|
+
destroyedAt:
|
|
138
|
+
row.purgedAt === null || purgeGraceMs === undefined
|
|
139
|
+
? null
|
|
140
|
+
: new Date(new Date(row.purgedAt).getTime() + purgeGraceMs).toISOString()
|
|
141
|
+
}
|
|
142
|
+
])
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
type AuditDatabase = Kysely<CloudDatabase> | Transaction<CloudDatabase>
|
|
147
|
+
|
|
148
|
+
/** Records an administrator's action on a document, a link, or a report. */
|
|
149
|
+
export async function auditContentAction(
|
|
150
|
+
database: AuditDatabase,
|
|
151
|
+
actorId: string,
|
|
152
|
+
action: string,
|
|
153
|
+
subject: { type: 'document' | 'document-share' | 'document-report'; id: string },
|
|
154
|
+
metadata: Record<string, unknown> = {}
|
|
155
|
+
): Promise<void> {
|
|
156
|
+
await database
|
|
157
|
+
.insertInto('adminAuditEvent')
|
|
158
|
+
.values({
|
|
159
|
+
id: crypto.randomUUID(),
|
|
160
|
+
actorUserId: actorId,
|
|
161
|
+
action,
|
|
162
|
+
subjectType: subject.type,
|
|
163
|
+
subjectId: subject.id,
|
|
164
|
+
metadata
|
|
165
|
+
})
|
|
166
|
+
.execute()
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** A document that is not deleted, held until the transaction ends; none is not found. */
|
|
170
|
+
function lockedDocument(transaction: Transaction<CloudDatabase>, documentId: string) {
|
|
171
|
+
return transaction
|
|
172
|
+
.selectFrom('document')
|
|
173
|
+
.select(['id', 'disabledAt'])
|
|
174
|
+
.where('id', '=', documentId)
|
|
175
|
+
.where('deletedAt', 'is', null)
|
|
176
|
+
.forUpdate()
|
|
177
|
+
.executeTakeFirstOrThrow()
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export type AdminDocumentServiceOptions = {
|
|
181
|
+
/**
|
|
182
|
+
* Ends a taken-down document's live rooms, saving them, so a takedown reaches open tabs at once
|
|
183
|
+
* and a restore loses no edit.
|
|
184
|
+
*/
|
|
185
|
+
closeRooms?: (documentId: string) => void
|
|
186
|
+
/** How long a document deleted forever waits before cleanup destroys it; 0 when not given. */
|
|
187
|
+
purgeGraceMs?: number
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function createAdminDocumentService(
|
|
191
|
+
database: Kysely<CloudDatabase>,
|
|
192
|
+
options: AdminDocumentServiceOptions = {}
|
|
193
|
+
) {
|
|
194
|
+
const purgeGraceMs = options.purgeGraceMs ?? 0
|
|
195
|
+
const graceSince = (now: Date) => new Date(now.getTime() - purgeGraceMs)
|
|
196
|
+
return {
|
|
197
|
+
/** A page of documents, newest change first, and how many match the search under each filter. */
|
|
198
|
+
async list(query: AdminListQuery<CloudAdminDocumentFilter> = {}) {
|
|
199
|
+
const search = listSearch(query)
|
|
200
|
+
const filter = query.filter ?? 'all'
|
|
201
|
+
const { limit, offset } = listWindow(query)
|
|
202
|
+
let searched = database.selectFrom('document').where(listable(graceSince(new Date())))
|
|
203
|
+
if (search) searched = searched.where(searchCondition(search))
|
|
204
|
+
const counts = await countEachFilter(
|
|
205
|
+
searched,
|
|
206
|
+
cloudAdminDocumentFilterSchema.options,
|
|
207
|
+
FILTERS
|
|
208
|
+
)
|
|
209
|
+
const page = await searched
|
|
210
|
+
.where(FILTERS[filter])
|
|
211
|
+
.select('document.id')
|
|
212
|
+
.orderBy('document.updatedAt', 'desc')
|
|
213
|
+
.orderBy('document.id')
|
|
214
|
+
.limit(limit)
|
|
215
|
+
.offset(offset)
|
|
216
|
+
.execute()
|
|
217
|
+
const documents = await adminDocuments(
|
|
218
|
+
database,
|
|
219
|
+
page.map((row) => row.id),
|
|
220
|
+
purgeGraceMs
|
|
221
|
+
)
|
|
222
|
+
return {
|
|
223
|
+
documents: page.flatMap((row) => documents.get(row.id) ?? []),
|
|
224
|
+
total: counts[filter],
|
|
225
|
+
counts
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Takes a document down: it opens for nobody, its owner included, its links stop working,
|
|
231
|
+
* and its live rooms close, saved. Its open reports count as acted on. Nothing is deleted and
|
|
232
|
+
* its collaboration epoch stays, so enabling it gives everything back, live edits included.
|
|
233
|
+
*/
|
|
234
|
+
async disable(actorId: string, documentId: string, reason: string | undefined): Promise<void> {
|
|
235
|
+
await database.transaction().execute(async (transaction) => {
|
|
236
|
+
const document = await lockedDocument(transaction, documentId)
|
|
237
|
+
if (document.disabledAt) return
|
|
238
|
+
await transaction
|
|
239
|
+
.updateTable('document')
|
|
240
|
+
.set({ disabledAt: new Date(), disabledReason: reason ?? null })
|
|
241
|
+
.where('id', '=', documentId)
|
|
242
|
+
.execute()
|
|
243
|
+
await transaction
|
|
244
|
+
.updateTable('documentReport')
|
|
245
|
+
.set({ status: 'actioned', resolvedAt: new Date(), resolvedBy: actorId })
|
|
246
|
+
.where('documentId', '=', documentId)
|
|
247
|
+
.where('status', '=', 'open')
|
|
248
|
+
.execute()
|
|
249
|
+
await auditContentAction(
|
|
250
|
+
transaction,
|
|
251
|
+
actorId,
|
|
252
|
+
'document.disabled',
|
|
253
|
+
{ type: 'document', id: documentId },
|
|
254
|
+
reason ? { reason } : {}
|
|
255
|
+
)
|
|
256
|
+
})
|
|
257
|
+
options.closeRooms?.(documentId)
|
|
258
|
+
},
|
|
259
|
+
|
|
260
|
+
/** Puts a document taken down back where it was. */
|
|
261
|
+
async enable(actorId: string, documentId: string): Promise<void> {
|
|
262
|
+
await database.transaction().execute(async (transaction) => {
|
|
263
|
+
const document = await lockedDocument(transaction, documentId)
|
|
264
|
+
if (!document.disabledAt) return
|
|
265
|
+
await transaction
|
|
266
|
+
.updateTable('document')
|
|
267
|
+
.set({ disabledAt: null, disabledReason: null })
|
|
268
|
+
.where('id', '=', documentId)
|
|
269
|
+
.execute()
|
|
270
|
+
await auditContentAction(transaction, actorId, 'document.enabled', {
|
|
271
|
+
type: 'document',
|
|
272
|
+
id: documentId
|
|
273
|
+
})
|
|
274
|
+
})
|
|
275
|
+
},
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Brings back a document someone deleted forever, while its grace lasts: it is live again in
|
|
279
|
+
* its workspace, not in Trash, and counts toward the workspace's storage again, over its plan
|
|
280
|
+
* or not. A document cleanup is destroying, or whose workspace has nobody left in it, can't be.
|
|
281
|
+
*/
|
|
282
|
+
async undelete(actorId: string, documentId: string, now = new Date()): Promise<void> {
|
|
283
|
+
await database.transaction().execute(async (transaction) => {
|
|
284
|
+
const document = await transaction
|
|
285
|
+
.selectFrom('document')
|
|
286
|
+
.select(['id', 'workspaceId', 'purgedAt', 'purgedBytes', 'cleanupClaimId'])
|
|
287
|
+
.where('id', '=', documentId)
|
|
288
|
+
.forUpdate()
|
|
289
|
+
.executeTakeFirst()
|
|
290
|
+
// Cleanup may have destroyed it since the list was loaded.
|
|
291
|
+
if (
|
|
292
|
+
!document ||
|
|
293
|
+
document.purgedAt === null ||
|
|
294
|
+
document.cleanupClaimId !== null ||
|
|
295
|
+
new Date(document.purgedAt) <= graceSince(now)
|
|
296
|
+
) {
|
|
297
|
+
throw new AdminDomainError(
|
|
298
|
+
'document_not_restorable',
|
|
299
|
+
'Only a document deleted forever, inside its grace, can be restored'
|
|
300
|
+
)
|
|
301
|
+
}
|
|
302
|
+
const member = await transaction
|
|
303
|
+
.selectFrom('workspaceMember')
|
|
304
|
+
.select('userId')
|
|
305
|
+
.where('workspaceId', '=', document.workspaceId)
|
|
306
|
+
.limit(1)
|
|
307
|
+
.executeTakeFirst()
|
|
308
|
+
if (!member) {
|
|
309
|
+
throw new AdminDomainError('workspace_gone', 'The document’s workspace has nobody in it')
|
|
310
|
+
}
|
|
311
|
+
await unmarkPurged(transaction, {
|
|
312
|
+
id: document.id,
|
|
313
|
+
workspaceId: document.workspaceId,
|
|
314
|
+
purgedBytes: Number(document.purgedBytes)
|
|
315
|
+
})
|
|
316
|
+
await auditContentAction(
|
|
317
|
+
transaction,
|
|
318
|
+
actorId,
|
|
319
|
+
'document.undeleted',
|
|
320
|
+
{ type: 'document', id: documentId },
|
|
321
|
+
{ workspaceId: document.workspaceId }
|
|
322
|
+
)
|
|
323
|
+
})
|
|
324
|
+
},
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Revokes a share link for good, as its owner can: the collaboration epoch moves on, so the
|
|
328
|
+
* link's guests lose their tickets, while members keep editing.
|
|
329
|
+
*/
|
|
330
|
+
async revokeShare(actorId: string, shareId: string): Promise<void> {
|
|
331
|
+
await database.transaction().execute(async (transaction) => {
|
|
332
|
+
const share = await transaction
|
|
333
|
+
.selectFrom('documentShare')
|
|
334
|
+
.select(['id', 'documentId', 'revokedAt'])
|
|
335
|
+
.where('id', '=', shareId)
|
|
336
|
+
.forUpdate()
|
|
337
|
+
.executeTakeFirstOrThrow()
|
|
338
|
+
if (share.revokedAt) return
|
|
339
|
+
await transaction
|
|
340
|
+
.updateTable('documentShare')
|
|
341
|
+
.set({ revokedAt: new Date(), updatedAt: new Date() })
|
|
342
|
+
.where('id', '=', shareId)
|
|
343
|
+
.execute()
|
|
344
|
+
await transaction
|
|
345
|
+
.updateTable('document')
|
|
346
|
+
.set((expression) => ({ collaborationEpoch: expression('collaborationEpoch', '+', 1) }))
|
|
347
|
+
.where('id', '=', share.documentId)
|
|
348
|
+
.execute()
|
|
349
|
+
await auditContentAction(
|
|
350
|
+
transaction,
|
|
351
|
+
actorId,
|
|
352
|
+
'document-share.revoked',
|
|
353
|
+
{ type: 'document-share', id: shareId },
|
|
354
|
+
{ documentId: share.documentId }
|
|
355
|
+
)
|
|
356
|
+
})
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
export type AdminDocumentService = ReturnType<typeof createAdminDocumentService>
|
package/src/admin/errors.ts
CHANGED
|
@@ -4,6 +4,8 @@ export type AdminErrorCode =
|
|
|
4
4
|
| 'self_admin_action_forbidden'
|
|
5
5
|
| 'email_regeneration_unavailable'
|
|
6
6
|
| 'mfa_required'
|
|
7
|
+
| 'document_not_restorable'
|
|
8
|
+
| 'workspace_gone'
|
|
7
9
|
|
|
8
10
|
export class AdminDomainError extends Error {
|
|
9
11
|
override readonly name = 'AdminDomainError'
|
|
@@ -15,6 +17,12 @@ export class AdminDomainError extends Error {
|
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
19
|
|
|
20
|
+
const CONFLICTS = new Set<AdminErrorCode>([
|
|
21
|
+
'invalid_enrollment_transition',
|
|
22
|
+
'document_not_restorable',
|
|
23
|
+
'workspace_gone'
|
|
24
|
+
])
|
|
25
|
+
|
|
18
26
|
export function adminErrorStatus(error: AdminDomainError): 400 | 409 {
|
|
19
|
-
return error.code
|
|
27
|
+
return CONFLICTS.has(error.code) ? 409 : 400
|
|
20
28
|
}
|
package/src/admin/index.ts
CHANGED
|
@@ -17,3 +17,9 @@ export {
|
|
|
17
17
|
} from './enrollment/service'
|
|
18
18
|
export { createAdminOperationsService, type AdminOperationsService } from './operations/service'
|
|
19
19
|
export { createAdminUserService, type AdminUserService } from './users/service'
|
|
20
|
+
export {
|
|
21
|
+
createAdminDocumentService,
|
|
22
|
+
type AdminDocumentService,
|
|
23
|
+
type AdminDocumentServiceOptions
|
|
24
|
+
} from './documents/service'
|
|
25
|
+
export { createAdminReportService, type AdminReportService } from './reports/service'
|
|
@@ -19,6 +19,7 @@ export function createAdminOperationsService(
|
|
|
19
19
|
async summary() {
|
|
20
20
|
const [
|
|
21
21
|
pendingEnrollment,
|
|
22
|
+
openReports,
|
|
22
23
|
pendingEmail,
|
|
23
24
|
failedEmail,
|
|
24
25
|
accounts,
|
|
@@ -31,6 +32,11 @@ export function createAdminOperationsService(
|
|
|
31
32
|
.select(({ fn }) => fn.countAll<number>().as('count'))
|
|
32
33
|
.where('status', '=', 'pending')
|
|
33
34
|
.executeTakeFirstOrThrow(),
|
|
35
|
+
database
|
|
36
|
+
.selectFrom('documentReport')
|
|
37
|
+
.select(({ fn }) => fn.countAll<number>().as('count'))
|
|
38
|
+
.where('status', '=', 'open')
|
|
39
|
+
.executeTakeFirstOrThrow(),
|
|
34
40
|
emailCount('pending'),
|
|
35
41
|
emailCount('failed'),
|
|
36
42
|
database
|
|
@@ -56,6 +62,7 @@ export function createAdminOperationsService(
|
|
|
56
62
|
enrollmentMode: config.enrollmentMode,
|
|
57
63
|
emailTransport: config.emailTransport,
|
|
58
64
|
pendingEnrollment: Number(pendingEnrollment.count),
|
|
65
|
+
openReports: Number(openReports.count),
|
|
59
66
|
pendingEmail,
|
|
60
67
|
failedEmail,
|
|
61
68
|
accounts: Number(accounts.count),
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { adminDocuments, auditContentAction } from '#cloud/admin/documents/service'
|
|
2
|
+
import {
|
|
3
|
+
containsPattern,
|
|
4
|
+
countEachFilter,
|
|
5
|
+
listSearch,
|
|
6
|
+
listWindow,
|
|
7
|
+
type AdminListQuery,
|
|
8
|
+
type ListFilters
|
|
9
|
+
} from '#cloud/admin/list'
|
|
10
|
+
import { isUUID } from '#cloud/admin/schema'
|
|
11
|
+
import {
|
|
12
|
+
cloudAdminReportFilterSchema,
|
|
13
|
+
type CloudAdminReport,
|
|
14
|
+
type CloudAdminReportFilter
|
|
15
|
+
} from '#cloud/contract'
|
|
16
|
+
import type { CloudDatabase } from '#cloud/server/db'
|
|
17
|
+
import { dateString } from '#cloud/server/sharing/contracts'
|
|
18
|
+
import { uniq } from 'es-toolkit'
|
|
19
|
+
import type { ExpressionBuilder, Kysely } from 'kysely'
|
|
20
|
+
|
|
21
|
+
type ReportExpression = ExpressionBuilder<CloudDatabase, 'documentReport'>
|
|
22
|
+
|
|
23
|
+
const FILTERS: ListFilters<CloudAdminReportFilter, 'documentReport'> = {
|
|
24
|
+
open: (expression) => expression('documentReport.status', '=', 'open'),
|
|
25
|
+
actioned: (expression) => expression('documentReport.status', '=', 'actioned'),
|
|
26
|
+
dismissed: (expression) => expression('documentReport.status', '=', 'dismissed'),
|
|
27
|
+
all: (expression) => expression.lit(true)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Reports whose description, reply address, or document's name has the search in it. */
|
|
31
|
+
function searchCondition(search: string) {
|
|
32
|
+
const pattern = containsPattern(search)
|
|
33
|
+
return (expression: ReportExpression) =>
|
|
34
|
+
expression.or([
|
|
35
|
+
expression('documentReport.description', 'ilike', pattern),
|
|
36
|
+
expression('documentReport.replyEmail', 'ilike', pattern),
|
|
37
|
+
expression.exists(
|
|
38
|
+
expression
|
|
39
|
+
.selectFrom('document')
|
|
40
|
+
.select('document.id')
|
|
41
|
+
.whereRef('document.id', '=', 'documentReport.documentId')
|
|
42
|
+
.where('document.name', 'ilike', pattern)
|
|
43
|
+
)
|
|
44
|
+
])
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function createAdminReportService(database: Kysely<CloudDatabase>) {
|
|
48
|
+
return {
|
|
49
|
+
/** A page of reports, newest first, and how many match the search under each filter. */
|
|
50
|
+
async list(query: AdminListQuery<CloudAdminReportFilter> = {}) {
|
|
51
|
+
const search = listSearch(query)
|
|
52
|
+
const filter = query.filter ?? 'open'
|
|
53
|
+
const { limit, offset } = listWindow(query)
|
|
54
|
+
let searched = database.selectFrom('documentReport')
|
|
55
|
+
if (search) searched = searched.where(searchCondition(search))
|
|
56
|
+
const counts = await countEachFilter(searched, cloudAdminReportFilterSchema.options, FILTERS)
|
|
57
|
+
const rows = await searched
|
|
58
|
+
.where(FILTERS[filter])
|
|
59
|
+
.selectAll()
|
|
60
|
+
.orderBy('createdAt', 'desc')
|
|
61
|
+
.orderBy('id', 'desc')
|
|
62
|
+
.limit(limit)
|
|
63
|
+
.offset(offset)
|
|
64
|
+
.execute()
|
|
65
|
+
const shareIds = uniq(rows.flatMap((row) => (row.shareId ? [row.shareId] : [])))
|
|
66
|
+
const reporterIds = uniq(
|
|
67
|
+
rows.flatMap((row) => (row.reporterUserId ? [row.reporterUserId] : []))
|
|
68
|
+
).filter(isUUID)
|
|
69
|
+
const [documents, shares, reporters] = await Promise.all([
|
|
70
|
+
adminDocuments(
|
|
71
|
+
database,
|
|
72
|
+
rows.map((row) => row.documentId)
|
|
73
|
+
),
|
|
74
|
+
shareIds.length
|
|
75
|
+
? database
|
|
76
|
+
.selectFrom('documentShare')
|
|
77
|
+
.select(['id', 'revokedAt'])
|
|
78
|
+
.where('id', 'in', shareIds)
|
|
79
|
+
.execute()
|
|
80
|
+
: [],
|
|
81
|
+
reporterIds.length
|
|
82
|
+
? database
|
|
83
|
+
.selectFrom('user')
|
|
84
|
+
.select(['id', 'name'])
|
|
85
|
+
.where('id', 'in', reporterIds)
|
|
86
|
+
.execute()
|
|
87
|
+
: []
|
|
88
|
+
])
|
|
89
|
+
const revoked = new Map(shares.map((share) => [share.id, share.revokedAt !== null]))
|
|
90
|
+
const reporterNames = new Map(reporters.map((reporter) => [reporter.id, reporter.name]))
|
|
91
|
+
const reports: CloudAdminReport[] = rows.flatMap((row) => {
|
|
92
|
+
const document = documents.get(row.documentId)
|
|
93
|
+
if (!document) return []
|
|
94
|
+
return [
|
|
95
|
+
{
|
|
96
|
+
id: row.id,
|
|
97
|
+
reason: row.reason,
|
|
98
|
+
description: row.description,
|
|
99
|
+
status: row.status,
|
|
100
|
+
reporter: row.reporterUserId
|
|
101
|
+
? { id: row.reporterUserId, name: reporterNames.get(row.reporterUserId) ?? null }
|
|
102
|
+
: null,
|
|
103
|
+
replyEmail: row.replyEmail,
|
|
104
|
+
createdAt: dateString(row.createdAt) ?? '',
|
|
105
|
+
resolvedAt: dateString(row.resolvedAt),
|
|
106
|
+
document,
|
|
107
|
+
share: row.shareId
|
|
108
|
+
? { id: row.shareId, revoked: revoked.get(row.shareId) ?? true }
|
|
109
|
+
: null
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
})
|
|
113
|
+
return { reports, total: counts[filter], counts }
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
/** Closes an open report, as dismissed or as acted on; a closed one stays as it was. */
|
|
117
|
+
async resolve(
|
|
118
|
+
actorId: string,
|
|
119
|
+
reportId: string,
|
|
120
|
+
status: 'dismissed' | 'actioned'
|
|
121
|
+
): Promise<void> {
|
|
122
|
+
await database.transaction().execute(async (transaction) => {
|
|
123
|
+
const report = await transaction
|
|
124
|
+
.selectFrom('documentReport')
|
|
125
|
+
.select(['id', 'status', 'documentId'])
|
|
126
|
+
.where('id', '=', reportId)
|
|
127
|
+
.forUpdate()
|
|
128
|
+
.executeTakeFirstOrThrow()
|
|
129
|
+
if (report.status !== 'open') return
|
|
130
|
+
await transaction
|
|
131
|
+
.updateTable('documentReport')
|
|
132
|
+
.set({ status, resolvedAt: new Date(), resolvedBy: actorId })
|
|
133
|
+
.where('id', '=', reportId)
|
|
134
|
+
.execute()
|
|
135
|
+
await auditContentAction(
|
|
136
|
+
transaction,
|
|
137
|
+
actorId,
|
|
138
|
+
`document-report.${status}`,
|
|
139
|
+
{ type: 'document-report', id: reportId },
|
|
140
|
+
{ documentId: report.documentId }
|
|
141
|
+
)
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export type AdminReportService = ReturnType<typeof createAdminReportService>
|
package/src/admin/schema.ts
CHANGED
|
@@ -21,8 +21,14 @@ export const userMutationSchema = v.object({
|
|
|
21
21
|
reason: v.optional(v.pipe(v.string(), v.trim(), v.maxLength(500)))
|
|
22
22
|
})
|
|
23
23
|
|
|
24
|
+
/** Why an administrator takes a document down, which the audit log keeps. */
|
|
25
|
+
export const documentTakedownSchema = v.object({
|
|
26
|
+
reason: v.optional(v.pipe(v.string(), v.trim(), v.maxLength(500)))
|
|
27
|
+
})
|
|
28
|
+
|
|
24
29
|
export type EnrollmentReview = v.InferOutput<typeof enrollmentReviewSchema>
|
|
25
30
|
|
|
26
31
|
export const parseEnrollmentReview = (input: unknown) => v.parse(enrollmentReviewSchema, input)
|
|
27
32
|
export const parseUserMutation = (input: unknown) => v.parse(userMutationSchema, input)
|
|
28
33
|
export const parseUserRoleMutation = (input: unknown) => v.parse(userRoleMutationSchema, input)
|
|
34
|
+
export const parseDocumentTakedown = (input: unknown) => v.parse(documentTakedownSchema, input)
|
package/src/client/api.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CloudFetch } from '#cloud/client/discovery'
|
|
2
2
|
import {
|
|
3
3
|
acceptedInvitationSchema,
|
|
4
|
-
|
|
4
|
+
servicesTokenSchema,
|
|
5
5
|
cloudSessionSchema,
|
|
6
6
|
cloudUserProfileSchema,
|
|
7
7
|
collaborationTicketSchema,
|
|
@@ -18,11 +18,12 @@ import {
|
|
|
18
18
|
documentVersionsSchema,
|
|
19
19
|
restoredDocumentSchema,
|
|
20
20
|
sharedDocumentSchema,
|
|
21
|
+
trashSchema,
|
|
21
22
|
invitationContinuationSchema,
|
|
22
23
|
invitationPreviewSchema,
|
|
23
24
|
resolvedDocumentShareSchema,
|
|
24
25
|
type AcceptDocumentInvitationInput,
|
|
25
|
-
type
|
|
26
|
+
type ServicesToken,
|
|
26
27
|
type CloudSession,
|
|
27
28
|
type CloudUserProfile,
|
|
28
29
|
type CollaborationTicket,
|
|
@@ -46,10 +47,12 @@ import {
|
|
|
46
47
|
type SaveDocumentVersionInput,
|
|
47
48
|
type UpdateDocumentVersionInput,
|
|
48
49
|
type SharedDocument,
|
|
50
|
+
type TrashedDocument,
|
|
49
51
|
type InvitationPreview,
|
|
50
|
-
type LookupCloudUserInput,
|
|
51
52
|
type PutDocumentGrantInput,
|
|
52
53
|
type ResolveDocumentShareInput,
|
|
54
|
+
fileDocumentReportResponseSchema,
|
|
55
|
+
type FileDocumentReportInput,
|
|
53
56
|
type UpdateDocumentShareInput,
|
|
54
57
|
type AcceptedInvitation
|
|
55
58
|
} from '#cloud/contract'
|
|
@@ -137,28 +140,14 @@ export function createCloudAPIClient(baseURL: string, options: CloudRequestOptio
|
|
|
137
140
|
if (response.status === 401) return null
|
|
138
141
|
return v.parse(cloudSessionSchema, await responseBody(response, options.onDiagnostic))
|
|
139
142
|
},
|
|
140
|
-
/** A short-lived token for the deployment's
|
|
141
|
-
async
|
|
143
|
+
/** A short-lived token for the deployment's services, on the workspace's behalf. */
|
|
144
|
+
async requestServicesToken(workspaceId: string): Promise<ServicesToken> {
|
|
142
145
|
return parseResponse(
|
|
143
|
-
client.
|
|
144
|
-
|
|
146
|
+
client.services.token.$post({ json: { workspaceId } }),
|
|
147
|
+
servicesTokenSchema,
|
|
145
148
|
options.onDiagnostic
|
|
146
149
|
)
|
|
147
150
|
},
|
|
148
|
-
async lookupUser(
|
|
149
|
-
documentId: string,
|
|
150
|
-
input: LookupCloudUserInput
|
|
151
|
-
): Promise<CloudUserProfile | null> {
|
|
152
|
-
const response = await parseResponse(
|
|
153
|
-
client.documents[':documentId'].users.lookup.$post({
|
|
154
|
-
param: { documentId },
|
|
155
|
-
json: input
|
|
156
|
-
}),
|
|
157
|
-
userLookupResponseSchema,
|
|
158
|
-
options.onDiagnostic
|
|
159
|
-
)
|
|
160
|
-
return response.user
|
|
161
|
-
},
|
|
162
151
|
async getUserProfile(documentId: string, userId: string): Promise<CloudUserProfile | null> {
|
|
163
152
|
const response = await parseResponse(
|
|
164
153
|
client.documents[':documentId'].users[':userId'].$get({
|
|
@@ -204,6 +193,24 @@ export function createCloudAPIClient(baseURL: string, options: CloudRequestOptio
|
|
|
204
193
|
)
|
|
205
194
|
return response.document
|
|
206
195
|
},
|
|
196
|
+
/** Documents in Trash the person may restore, across their workspaces, newest first. */
|
|
197
|
+
async listTrash(): Promise<TrashedDocument[]> {
|
|
198
|
+
const response = await parseResponse(client.trash.$get(), trashSchema, options.onDiagnostic)
|
|
199
|
+
return response.documents
|
|
200
|
+
},
|
|
201
|
+
async restoreDocument(documentId: string): Promise<void> {
|
|
202
|
+
await responseBody(
|
|
203
|
+
await client.trash[':documentId'].restore.$post({ param: { documentId } }),
|
|
204
|
+
options.onDiagnostic
|
|
205
|
+
)
|
|
206
|
+
},
|
|
207
|
+
/** Deletes a document in Trash for good. */
|
|
208
|
+
async purgeDocument(documentId: string): Promise<void> {
|
|
209
|
+
await responseBody(
|
|
210
|
+
await client.trash[':documentId'].$delete({ param: { documentId } }),
|
|
211
|
+
options.onDiagnostic
|
|
212
|
+
)
|
|
213
|
+
},
|
|
207
214
|
async deleteDocument(documentId: string): Promise<void> {
|
|
208
215
|
await responseBody(
|
|
209
216
|
await client.documents[':documentId'].$delete({ param: { documentId } }),
|
|
@@ -380,6 +387,14 @@ export function createCloudAPIClient(baseURL: string, options: CloudRequestOptio
|
|
|
380
387
|
options.onDiagnostic
|
|
381
388
|
)
|
|
382
389
|
},
|
|
390
|
+
/** Reports the document a share link opens to the server's administrators. */
|
|
391
|
+
async fileDocumentReport(shareId: string, input: FileDocumentReportInput): Promise<void> {
|
|
392
|
+
await parseResponse(
|
|
393
|
+
publicClient.shares[':shareId'].reports.$post({ param: { shareId }, json: input }),
|
|
394
|
+
fileDocumentReportResponseSchema,
|
|
395
|
+
options.onDiagnostic
|
|
396
|
+
)
|
|
397
|
+
},
|
|
383
398
|
async resolveDocumentShare(shareId: string, input: ResolveDocumentShareInput) {
|
|
384
399
|
const response = await parseResponse(
|
|
385
400
|
publicClient.shares[':shareId'].resolve.$post({
|