@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
package/src/client/api.ts
CHANGED
|
@@ -1,104 +1,32 @@
|
|
|
1
1
|
import type { CloudFetch } from '#cloud/client/discovery'
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
accountEntitlementsResponseSchema,
|
|
4
4
|
servicesTokenSchema,
|
|
5
|
+
billingTokenSchema,
|
|
5
6
|
cloudSessionSchema,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
createInvitationContinuationSchema,
|
|
9
|
-
documentAccessSchema,
|
|
10
|
-
documentDownloadSchema,
|
|
11
|
-
objectUploadSchema,
|
|
12
|
-
documentGrantSchema,
|
|
13
|
-
documentInvitationSchema,
|
|
14
|
-
documentShareSchema,
|
|
15
|
-
documentSummarySchema,
|
|
16
|
-
documentVersionDownloadSchema,
|
|
17
|
-
documentVersionResponseSchema,
|
|
18
|
-
documentVersionsSchema,
|
|
19
|
-
restoredDocumentSchema,
|
|
20
|
-
sharedDocumentSchema,
|
|
21
|
-
trashSchema,
|
|
22
|
-
invitationContinuationSchema,
|
|
23
|
-
invitationPreviewSchema,
|
|
24
|
-
resolvedDocumentShareSchema,
|
|
25
|
-
type AcceptDocumentInvitationInput,
|
|
7
|
+
sendsTokenSafely,
|
|
8
|
+
type AccountEntitlements,
|
|
26
9
|
type ServicesToken,
|
|
27
|
-
type
|
|
28
|
-
type
|
|
29
|
-
type CollaborationTicket,
|
|
30
|
-
type CreateInvitationContinuationInput,
|
|
31
|
-
type InvitationContinuation,
|
|
32
|
-
type CommitUploadRequest,
|
|
33
|
-
type CreateDocumentRequest,
|
|
34
|
-
type CreateDocumentInvitationInput,
|
|
35
|
-
type CreateDocumentShareInput,
|
|
36
|
-
type CreateUploadInput,
|
|
37
|
-
type DocumentAccess,
|
|
38
|
-
type DocumentDownload,
|
|
39
|
-
type DocumentGrant,
|
|
40
|
-
type DocumentInvitation,
|
|
41
|
-
type DocumentShare,
|
|
42
|
-
type DocumentSummary,
|
|
43
|
-
type DocumentVersion,
|
|
44
|
-
type DocumentVersionDownload,
|
|
45
|
-
type DocumentVersions,
|
|
46
|
-
type DuplicateDocumentVersionInput,
|
|
47
|
-
type SaveDocumentVersionInput,
|
|
48
|
-
type UpdateDocumentVersionInput,
|
|
49
|
-
type SharedDocument,
|
|
50
|
-
type TrashedDocument,
|
|
51
|
-
type InvitationPreview,
|
|
52
|
-
type PutDocumentGrantInput,
|
|
53
|
-
type ResolveDocumentShareInput,
|
|
54
|
-
fileDocumentReportResponseSchema,
|
|
55
|
-
type FileDocumentReportInput,
|
|
56
|
-
type UpdateDocumentShareInput,
|
|
57
|
-
type AcceptedInvitation
|
|
10
|
+
type BillingToken,
|
|
11
|
+
type CloudSession
|
|
58
12
|
} from '#cloud/contract'
|
|
59
13
|
import type { CloudAPI, PublicCloudAPI } from '#cloud/server/api'
|
|
60
|
-
import { pickBy } from 'es-toolkit/object'
|
|
61
14
|
import { hc } from 'hono/client'
|
|
62
15
|
import * as v from 'valibot'
|
|
63
16
|
|
|
17
|
+
import { anySignal, DEADLINE_MS } from '@open-pencil/std/timing'
|
|
18
|
+
|
|
19
|
+
import { createCommentRequests, createSharedCommentRequests } from './comments'
|
|
20
|
+
import { createCommunityRequests } from './community'
|
|
21
|
+
import { createDocumentRequests } from './documents'
|
|
64
22
|
import { createImageRequests } from './images'
|
|
65
23
|
import { CloudAPIError, parseResponse, responseBody, type CloudClientDiagnostic } from './response'
|
|
24
|
+
import { createSharingRequests } from './sharing'
|
|
25
|
+
import { createVersionRequests } from './versions'
|
|
66
26
|
import { createWorkspaceRequests } from './workspaces'
|
|
67
27
|
|
|
68
28
|
export { CloudAPIError, type CloudClientDiagnostic } from './response'
|
|
69
|
-
|
|
70
|
-
const documentsResponseSchema = v.object({ documents: v.array(documentSummarySchema) })
|
|
71
|
-
const sharedDocumentsResponseSchema = v.object({ documents: v.array(sharedDocumentSchema) })
|
|
72
|
-
const documentResponseSchema = v.object({ document: documentSummarySchema })
|
|
73
|
-
const downloadResponseSchema = v.object({ document: documentDownloadSchema })
|
|
74
|
-
const accessResponseSchema = v.object({ access: documentAccessSchema })
|
|
75
|
-
const sharesResponseSchema = v.object({ shares: v.array(documentShareSchema) })
|
|
76
|
-
const shareResponseSchema = v.object({ share: documentShareSchema })
|
|
77
|
-
const shareCapabilityResponseSchema = v.object({
|
|
78
|
-
share: documentShareSchema,
|
|
79
|
-
secret: v.string(),
|
|
80
|
-
path: v.string()
|
|
81
|
-
})
|
|
82
|
-
const grantsResponseSchema = v.object({ grants: v.array(documentGrantSchema) })
|
|
83
|
-
const grantResponseSchema = v.object({ grant: documentGrantSchema })
|
|
84
|
-
const acceptedResponseSchema = v.object({ accepted: acceptedInvitationSchema })
|
|
85
|
-
const invitationPreviewResponseSchema = v.object({ invitation: invitationPreviewSchema })
|
|
86
|
-
const invitationsResponseSchema = v.object({ invitations: v.array(documentInvitationSchema) })
|
|
87
|
-
const invitationCapabilityResponseSchema = v.object({
|
|
88
|
-
invitation: documentInvitationSchema,
|
|
89
|
-
token: v.string()
|
|
90
|
-
})
|
|
91
|
-
const collaborationTicketResponseSchema = v.object({ ticket: collaborationTicketSchema })
|
|
92
|
-
const resolvedShareResponseSchema = v.object({ resolution: resolvedDocumentShareSchema })
|
|
93
|
-
const sharedDocumentResponseSchema = v.object({
|
|
94
|
-
resolution: resolvedDocumentShareSchema,
|
|
95
|
-
document: documentDownloadSchema
|
|
96
|
-
})
|
|
97
|
-
const userLookupResponseSchema = v.object({ user: v.nullable(cloudUserProfileSchema) })
|
|
98
|
-
const uploadResponseSchema = v.object({
|
|
99
|
-
id: v.pipe(v.string(), v.uuid()),
|
|
100
|
-
upload: objectUploadSchema
|
|
101
|
-
})
|
|
29
|
+
export type { CloudUpload } from './documents'
|
|
102
30
|
|
|
103
31
|
export type CloudRequestOptions = {
|
|
104
32
|
fetch?: CloudFetch
|
|
@@ -107,8 +35,6 @@ export type CloudRequestOptions = {
|
|
|
107
35
|
onDiagnostic?: CloudClientDiagnostic
|
|
108
36
|
}
|
|
109
37
|
|
|
110
|
-
export type CloudUpload = v.InferOutput<typeof uploadResponseSchema>
|
|
111
|
-
|
|
112
38
|
function apiURL(baseURL: string): string {
|
|
113
39
|
const url = new URL(baseURL)
|
|
114
40
|
if (url.protocol !== 'https:' && url.protocol !== 'http:') {
|
|
@@ -120,17 +46,38 @@ function apiURL(baseURL: string): string {
|
|
|
120
46
|
return url.href
|
|
121
47
|
}
|
|
122
48
|
|
|
49
|
+
/**
|
|
50
|
+
* How long one Cloud API request may take. Some do real work on the server, such as saving a
|
|
51
|
+
* revision or deleting an account, and bytes go to storage directly, so a JSON call past this has
|
|
52
|
+
* hung rather than run slowly.
|
|
53
|
+
*/
|
|
54
|
+
const API_DEADLINE_MS = DEADLINE_MS.slowRequest
|
|
55
|
+
|
|
56
|
+
/** `fetch`, with each request bounded by its own deadline as well as the caller's signal. */
|
|
57
|
+
function boundedFetch(fetch: CloudFetch = globalThis.fetch): CloudFetch {
|
|
58
|
+
return (input, init) =>
|
|
59
|
+
fetch(input, {
|
|
60
|
+
...init,
|
|
61
|
+
signal: anySignal([init?.signal, AbortSignal.timeout(API_DEADLINE_MS)])
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
123
65
|
export function createCloudAPIClient(baseURL: string, options: CloudRequestOptions = {}) {
|
|
66
|
+
// An access token goes only where nobody between can read it, as services tokens do.
|
|
67
|
+
if (options.accessToken && !sendsTokenSafely(apiURL(baseURL))) {
|
|
68
|
+
throw new CloudAPIError('OpenPencil Cloud takes an access token only over HTTPS', 0)
|
|
69
|
+
}
|
|
124
70
|
const headers = {
|
|
125
71
|
'Content-Type': 'application/json',
|
|
126
72
|
...(options.accessToken ? { Authorization: `Bearer ${options.accessToken}` } : {})
|
|
127
73
|
}
|
|
74
|
+
const fetch = boundedFetch(options.fetch)
|
|
128
75
|
const client = hc<CloudAPI>(apiURL(baseURL), {
|
|
129
|
-
fetch
|
|
76
|
+
fetch,
|
|
130
77
|
init: { credentials: 'include', signal: options.signal, headers }
|
|
131
78
|
})
|
|
132
79
|
const publicClient = hc<PublicCloudAPI>(apiURL(baseURL), {
|
|
133
|
-
fetch
|
|
80
|
+
fetch,
|
|
134
81
|
init: { credentials: 'include', signal: options.signal, headers }
|
|
135
82
|
})
|
|
136
83
|
|
|
@@ -148,395 +95,27 @@ export function createCloudAPIClient(baseURL: string, options: CloudRequestOptio
|
|
|
148
95
|
options.onDiagnostic
|
|
149
96
|
)
|
|
150
97
|
},
|
|
151
|
-
|
|
98
|
+
/** A short-lived token for the deployment's billing, for the signed-in person's own account. */
|
|
99
|
+
async requestBillingToken(): Promise<BillingToken> {
|
|
100
|
+
return parseResponse(client.billing.token.$post(), billingTokenSchema, options.onDiagnostic)
|
|
101
|
+
},
|
|
102
|
+
/** The signed-in account's plan, and the storage its workspaces hold together. */
|
|
103
|
+
async getAccountEntitlements(): Promise<AccountEntitlements> {
|
|
152
104
|
const response = await parseResponse(
|
|
153
|
-
client.
|
|
154
|
-
|
|
155
|
-
}),
|
|
156
|
-
userLookupResponseSchema,
|
|
105
|
+
client.account.entitlements.$get(),
|
|
106
|
+
accountEntitlementsResponseSchema,
|
|
157
107
|
options.onDiagnostic
|
|
158
108
|
)
|
|
159
|
-
return response.
|
|
109
|
+
return response.entitlements
|
|
160
110
|
},
|
|
161
111
|
...createWorkspaceRequests(client, options.onDiagnostic),
|
|
162
112
|
...createImageRequests(client, publicClient, options.onDiagnostic),
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
)
|
|
170
|
-
return response.documents
|
|
171
|
-
},
|
|
172
|
-
async listDocuments(workspaceId: string): Promise<DocumentSummary[]> {
|
|
173
|
-
const response = await parseResponse(
|
|
174
|
-
client.workspaces[':workspaceId'].documents.$get({
|
|
175
|
-
param: { workspaceId }
|
|
176
|
-
}),
|
|
177
|
-
documentsResponseSchema,
|
|
178
|
-
options.onDiagnostic
|
|
179
|
-
)
|
|
180
|
-
return response.documents
|
|
181
|
-
},
|
|
182
|
-
async createDocument(
|
|
183
|
-
workspaceId: string,
|
|
184
|
-
input: CreateDocumentRequest
|
|
185
|
-
): Promise<DocumentSummary> {
|
|
186
|
-
const response = await parseResponse(
|
|
187
|
-
client.workspaces[':workspaceId'].documents.$post({
|
|
188
|
-
param: { workspaceId },
|
|
189
|
-
json: { ...input, kind: input.kind ?? 'design' }
|
|
190
|
-
}),
|
|
191
|
-
documentResponseSchema,
|
|
192
|
-
options.onDiagnostic
|
|
193
|
-
)
|
|
194
|
-
return response.document
|
|
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
|
-
},
|
|
214
|
-
async deleteDocument(documentId: string): Promise<void> {
|
|
215
|
-
await responseBody(
|
|
216
|
-
await client.documents[':documentId'].$delete({ param: { documentId } }),
|
|
217
|
-
options.onDiagnostic
|
|
218
|
-
)
|
|
219
|
-
},
|
|
220
|
-
async getDocument(documentId: string): Promise<DocumentDownload> {
|
|
221
|
-
const response = await parseResponse(
|
|
222
|
-
client.documents[':documentId'].$get({ param: { documentId } }),
|
|
223
|
-
downloadResponseSchema,
|
|
224
|
-
options.onDiagnostic
|
|
225
|
-
)
|
|
226
|
-
return response.document
|
|
227
|
-
},
|
|
228
|
-
async getDocumentAccess(documentId: string): Promise<DocumentAccess> {
|
|
229
|
-
const response = await parseResponse(
|
|
230
|
-
client.documents[':documentId'].access.$get({ param: { documentId } }),
|
|
231
|
-
accessResponseSchema,
|
|
232
|
-
options.onDiagnostic
|
|
233
|
-
)
|
|
234
|
-
return response.access
|
|
235
|
-
},
|
|
236
|
-
async listDocumentShares(documentId: string): Promise<DocumentShare[]> {
|
|
237
|
-
const response = await parseResponse(
|
|
238
|
-
client.documents[':documentId'].shares.$get({ param: { documentId } }),
|
|
239
|
-
sharesResponseSchema,
|
|
240
|
-
options.onDiagnostic
|
|
241
|
-
)
|
|
242
|
-
return response.shares
|
|
243
|
-
},
|
|
244
|
-
async createDocumentShare(documentId: string, input: CreateDocumentShareInput) {
|
|
245
|
-
return parseResponse(
|
|
246
|
-
client.documents[':documentId'].shares.$post({
|
|
247
|
-
param: { documentId },
|
|
248
|
-
json: input
|
|
249
|
-
}),
|
|
250
|
-
shareCapabilityResponseSchema,
|
|
251
|
-
options.onDiagnostic
|
|
252
|
-
)
|
|
253
|
-
},
|
|
254
|
-
async updateDocumentShare(
|
|
255
|
-
documentId: string,
|
|
256
|
-
shareId: string,
|
|
257
|
-
input: UpdateDocumentShareInput
|
|
258
|
-
): Promise<DocumentShare> {
|
|
259
|
-
const response = await parseResponse(
|
|
260
|
-
client.documents[':documentId'].shares[':shareId'].$patch({
|
|
261
|
-
param: { documentId, shareId },
|
|
262
|
-
json: input
|
|
263
|
-
}),
|
|
264
|
-
shareResponseSchema,
|
|
265
|
-
options.onDiagnostic
|
|
266
|
-
)
|
|
267
|
-
return response.share
|
|
268
|
-
},
|
|
269
|
-
async rotateDocumentShare(documentId: string, shareId: string) {
|
|
270
|
-
return parseResponse(
|
|
271
|
-
client.documents[':documentId'].shares[':shareId'].rotate.$post({
|
|
272
|
-
param: { documentId, shareId }
|
|
273
|
-
}),
|
|
274
|
-
shareCapabilityResponseSchema,
|
|
275
|
-
options.onDiagnostic
|
|
276
|
-
)
|
|
277
|
-
},
|
|
278
|
-
async revokeDocumentShare(documentId: string, shareId: string): Promise<void> {
|
|
279
|
-
await responseBody(
|
|
280
|
-
await client.documents[':documentId'].shares[':shareId'].$delete({
|
|
281
|
-
param: { documentId, shareId }
|
|
282
|
-
}),
|
|
283
|
-
options.onDiagnostic
|
|
284
|
-
)
|
|
285
|
-
},
|
|
286
|
-
async listDocumentGrants(documentId: string): Promise<DocumentGrant[]> {
|
|
287
|
-
const response = await parseResponse(
|
|
288
|
-
client.documents[':documentId'].grants.$get({ param: { documentId } }),
|
|
289
|
-
grantsResponseSchema,
|
|
290
|
-
options.onDiagnostic
|
|
291
|
-
)
|
|
292
|
-
return response.grants
|
|
293
|
-
},
|
|
294
|
-
async putDocumentGrant(
|
|
295
|
-
documentId: string,
|
|
296
|
-
userId: string,
|
|
297
|
-
input: PutDocumentGrantInput
|
|
298
|
-
): Promise<DocumentGrant> {
|
|
299
|
-
const response = await parseResponse(
|
|
300
|
-
client.documents[':documentId'].grants[':userId'].$put({
|
|
301
|
-
param: { documentId, userId },
|
|
302
|
-
json: input
|
|
303
|
-
}),
|
|
304
|
-
grantResponseSchema,
|
|
305
|
-
options.onDiagnostic
|
|
306
|
-
)
|
|
307
|
-
return response.grant
|
|
308
|
-
},
|
|
309
|
-
async revokeDocumentGrant(documentId: string, userId: string): Promise<void> {
|
|
310
|
-
await responseBody(
|
|
311
|
-
await client.documents[':documentId'].grants[':userId'].$delete({
|
|
312
|
-
param: { documentId, userId }
|
|
313
|
-
}),
|
|
314
|
-
options.onDiagnostic
|
|
315
|
-
)
|
|
316
|
-
},
|
|
317
|
-
async listDocumentInvitations(documentId: string): Promise<DocumentInvitation[]> {
|
|
318
|
-
const response = await parseResponse(
|
|
319
|
-
client.documents[':documentId'].invitations.$get({ param: { documentId } }),
|
|
320
|
-
invitationsResponseSchema,
|
|
321
|
-
options.onDiagnostic
|
|
322
|
-
)
|
|
323
|
-
return response.invitations
|
|
324
|
-
},
|
|
325
|
-
async createDocumentInvitation(documentId: string, input: CreateDocumentInvitationInput) {
|
|
326
|
-
return parseResponse(
|
|
327
|
-
client.documents[':documentId'].invitations.$post({
|
|
328
|
-
param: { documentId },
|
|
329
|
-
json: input
|
|
330
|
-
}),
|
|
331
|
-
invitationCapabilityResponseSchema,
|
|
332
|
-
options.onDiagnostic
|
|
333
|
-
)
|
|
334
|
-
},
|
|
335
|
-
async createInvitationContinuation(
|
|
336
|
-
input: CreateInvitationContinuationInput
|
|
337
|
-
): Promise<InvitationContinuation> {
|
|
338
|
-
return parseResponse(
|
|
339
|
-
publicClient.invitations.continuations.$post({ json: input }),
|
|
340
|
-
invitationContinuationSchema,
|
|
341
|
-
options.onDiagnostic
|
|
342
|
-
)
|
|
343
|
-
},
|
|
344
|
-
async consumeInvitationContinuation(id: string): Promise<CreateInvitationContinuationInput> {
|
|
345
|
-
return parseResponse(
|
|
346
|
-
publicClient.invitations.continuations[':continuationId'].consume.$post({
|
|
347
|
-
param: { continuationId: id }
|
|
348
|
-
}),
|
|
349
|
-
createInvitationContinuationSchema,
|
|
350
|
-
options.onDiagnostic
|
|
351
|
-
)
|
|
352
|
-
},
|
|
353
|
-
async previewInvitation(
|
|
354
|
-
invitationId: string,
|
|
355
|
-
input: AcceptDocumentInvitationInput
|
|
356
|
-
): Promise<InvitationPreview> {
|
|
357
|
-
const response = await parseResponse(
|
|
358
|
-
publicClient.invitations[':invitationId'].preview.$post({
|
|
359
|
-
param: { invitationId },
|
|
360
|
-
json: input
|
|
361
|
-
}),
|
|
362
|
-
invitationPreviewResponseSchema,
|
|
363
|
-
options.onDiagnostic
|
|
364
|
-
)
|
|
365
|
-
return response.invitation
|
|
366
|
-
},
|
|
367
|
-
/** Accepts a document or workspace invitation, and says which it was. */
|
|
368
|
-
async acceptInvitation(
|
|
369
|
-
invitationId: string,
|
|
370
|
-
input: AcceptDocumentInvitationInput
|
|
371
|
-
): Promise<AcceptedInvitation> {
|
|
372
|
-
const response = await parseResponse(
|
|
373
|
-
client.invitations[':invitationId'].accept.$post({
|
|
374
|
-
param: { invitationId },
|
|
375
|
-
json: input
|
|
376
|
-
}),
|
|
377
|
-
acceptedResponseSchema,
|
|
378
|
-
options.onDiagnostic
|
|
379
|
-
)
|
|
380
|
-
return response.accepted
|
|
381
|
-
},
|
|
382
|
-
async revokeDocumentInvitation(documentId: string, invitationId: string): Promise<void> {
|
|
383
|
-
await responseBody(
|
|
384
|
-
await client.documents[':documentId'].invitations[':invitationId'].$delete({
|
|
385
|
-
param: { documentId, invitationId }
|
|
386
|
-
}),
|
|
387
|
-
options.onDiagnostic
|
|
388
|
-
)
|
|
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
|
-
},
|
|
398
|
-
async resolveDocumentShare(shareId: string, input: ResolveDocumentShareInput) {
|
|
399
|
-
const response = await parseResponse(
|
|
400
|
-
publicClient.shares[':shareId'].resolve.$post({
|
|
401
|
-
param: { shareId },
|
|
402
|
-
json: input
|
|
403
|
-
}),
|
|
404
|
-
resolvedShareResponseSchema,
|
|
405
|
-
options.onDiagnostic
|
|
406
|
-
)
|
|
407
|
-
return response.resolution
|
|
408
|
-
},
|
|
409
|
-
async getSharedDocument(shareId: string, input: ResolveDocumentShareInput) {
|
|
410
|
-
return parseResponse(
|
|
411
|
-
publicClient.shares[':shareId'].document.$post({
|
|
412
|
-
param: { shareId },
|
|
413
|
-
json: input
|
|
414
|
-
}),
|
|
415
|
-
sharedDocumentResponseSchema,
|
|
416
|
-
options.onDiagnostic
|
|
417
|
-
)
|
|
418
|
-
},
|
|
419
|
-
async getSharedCollaborationTicket(
|
|
420
|
-
shareId: string,
|
|
421
|
-
input: ResolveDocumentShareInput
|
|
422
|
-
): Promise<CollaborationTicket> {
|
|
423
|
-
const response = await parseResponse(
|
|
424
|
-
publicClient.shares[':shareId']['collaboration-ticket'].$post({
|
|
425
|
-
param: { shareId },
|
|
426
|
-
json: input
|
|
427
|
-
}),
|
|
428
|
-
collaborationTicketResponseSchema,
|
|
429
|
-
options.onDiagnostic
|
|
430
|
-
)
|
|
431
|
-
return response.ticket
|
|
432
|
-
},
|
|
433
|
-
async getCollaborationTicket(documentId: string): Promise<CollaborationTicket> {
|
|
434
|
-
const response = await parseResponse(
|
|
435
|
-
client.documents[':documentId']['collaboration-ticket'].$post({
|
|
436
|
-
param: { documentId }
|
|
437
|
-
}),
|
|
438
|
-
collaborationTicketResponseSchema,
|
|
439
|
-
options.onDiagnostic
|
|
440
|
-
)
|
|
441
|
-
return response.ticket
|
|
442
|
-
},
|
|
443
|
-
async createUpload(documentId: string, input: CreateUploadInput): Promise<CloudUpload> {
|
|
444
|
-
return parseResponse(
|
|
445
|
-
client.documents[':documentId'].uploads.$post({
|
|
446
|
-
param: { documentId },
|
|
447
|
-
json: input
|
|
448
|
-
}),
|
|
449
|
-
uploadResponseSchema,
|
|
450
|
-
options.onDiagnostic
|
|
451
|
-
)
|
|
452
|
-
},
|
|
453
|
-
async commitUpload(uploadId: string, input: CommitUploadRequest): Promise<DocumentSummary> {
|
|
454
|
-
const response = await parseResponse(
|
|
455
|
-
client.uploads[':uploadId'].commit.$post({
|
|
456
|
-
param: { uploadId },
|
|
457
|
-
json: { ...input, images: input.images ?? [] }
|
|
458
|
-
}),
|
|
459
|
-
documentResponseSchema,
|
|
460
|
-
options.onDiagnostic
|
|
461
|
-
)
|
|
462
|
-
return response.document
|
|
463
|
-
},
|
|
464
|
-
/** A page of the document's version history, newest first. */
|
|
465
|
-
async listDocumentVersions(
|
|
466
|
-
documentId: string,
|
|
467
|
-
page: { before?: string; limit?: number } = {}
|
|
468
|
-
): Promise<DocumentVersions> {
|
|
469
|
-
return parseResponse(
|
|
470
|
-
client.documents[':documentId'].versions.$get({
|
|
471
|
-
param: { documentId },
|
|
472
|
-
query: pickBy(page, (value) => value !== undefined)
|
|
473
|
-
}),
|
|
474
|
-
documentVersionsSchema,
|
|
475
|
-
options.onDiagnostic
|
|
476
|
-
)
|
|
477
|
-
},
|
|
478
|
-
async saveDocumentVersion(
|
|
479
|
-
documentId: string,
|
|
480
|
-
input: SaveDocumentVersionInput
|
|
481
|
-
): Promise<DocumentVersion> {
|
|
482
|
-
const response = await parseResponse(
|
|
483
|
-
client.documents[':documentId'].versions.$post({ param: { documentId }, json: input }),
|
|
484
|
-
documentVersionResponseSchema,
|
|
485
|
-
options.onDiagnostic
|
|
486
|
-
)
|
|
487
|
-
return response.version
|
|
488
|
-
},
|
|
489
|
-
async updateDocumentVersion(
|
|
490
|
-
documentId: string,
|
|
491
|
-
versionId: string,
|
|
492
|
-
input: UpdateDocumentVersionInput
|
|
493
|
-
): Promise<DocumentVersion> {
|
|
494
|
-
const response = await parseResponse(
|
|
495
|
-
client.documents[':documentId'].versions[':versionId'].$patch({
|
|
496
|
-
param: { documentId, versionId },
|
|
497
|
-
json: input
|
|
498
|
-
}),
|
|
499
|
-
documentVersionResponseSchema,
|
|
500
|
-
options.onDiagnostic
|
|
501
|
-
)
|
|
502
|
-
return response.version
|
|
503
|
-
},
|
|
504
|
-
async getDocumentVersion(
|
|
505
|
-
documentId: string,
|
|
506
|
-
versionId: string
|
|
507
|
-
): Promise<DocumentVersionDownload> {
|
|
508
|
-
return parseResponse(
|
|
509
|
-
client.documents[':documentId'].versions[':versionId'].$get({
|
|
510
|
-
param: { documentId, versionId }
|
|
511
|
-
}),
|
|
512
|
-
documentVersionDownloadSchema,
|
|
513
|
-
options.onDiagnostic
|
|
514
|
-
)
|
|
515
|
-
},
|
|
516
|
-
async restoreDocumentVersion(documentId: string, versionId: string) {
|
|
517
|
-
return parseResponse(
|
|
518
|
-
client.documents[':documentId'].versions[':versionId'].restore.$post({
|
|
519
|
-
param: { documentId, versionId }
|
|
520
|
-
}),
|
|
521
|
-
restoredDocumentSchema,
|
|
522
|
-
options.onDiagnostic
|
|
523
|
-
)
|
|
524
|
-
},
|
|
525
|
-
async duplicateDocumentVersion(
|
|
526
|
-
documentId: string,
|
|
527
|
-
versionId: string,
|
|
528
|
-
input: DuplicateDocumentVersionInput
|
|
529
|
-
): Promise<DocumentSummary> {
|
|
530
|
-
const response = await parseResponse(
|
|
531
|
-
client.documents[':documentId'].versions[':versionId'].duplicate.$post({
|
|
532
|
-
param: { documentId, versionId },
|
|
533
|
-
json: input
|
|
534
|
-
}),
|
|
535
|
-
documentResponseSchema,
|
|
536
|
-
options.onDiagnostic
|
|
537
|
-
)
|
|
538
|
-
return response.document
|
|
539
|
-
}
|
|
113
|
+
...createDocumentRequests(client, options.onDiagnostic),
|
|
114
|
+
...createVersionRequests(client, options.onDiagnostic),
|
|
115
|
+
...createCommentRequests(client, options.onDiagnostic),
|
|
116
|
+
...createSharedCommentRequests(publicClient, options.onDiagnostic),
|
|
117
|
+
...createSharingRequests(client, publicClient, options.onDiagnostic),
|
|
118
|
+
...createCommunityRequests(publicClient, options.onDiagnostic)
|
|
540
119
|
}
|
|
541
120
|
}
|
|
542
121
|
|
|
@@ -23,11 +23,20 @@ export type CloudAuthClient = Pick<
|
|
|
23
23
|
| 'getSession'
|
|
24
24
|
| 'signIn'
|
|
25
25
|
| 'signOut'
|
|
26
|
-
| 'signUp'
|
|
27
26
|
| 'sendVerificationEmail'
|
|
28
27
|
| 'requestPasswordReset'
|
|
29
28
|
| 'resetPassword'
|
|
30
29
|
> & {
|
|
30
|
+
signUp: {
|
|
31
|
+
/** Also takes the language the server writes to the account in, a field Cloud adds. */
|
|
32
|
+
email(input: {
|
|
33
|
+
name: string
|
|
34
|
+
email: string
|
|
35
|
+
password: string
|
|
36
|
+
locale: string
|
|
37
|
+
callbackURL?: string
|
|
38
|
+
}): Promise<{ data: unknown; error: { code?: string; status: number } | null }>
|
|
39
|
+
}
|
|
31
40
|
signIn: ReturnType<typeof createAuthClient>['signIn'] & {
|
|
32
41
|
passkey(): Promise<{
|
|
33
42
|
data: unknown
|
|
@@ -157,10 +166,19 @@ export async function signInToCloudWithEmail(
|
|
|
157
166
|
return { ok: true, value: { status: 'signed-in', token: result.data.token } }
|
|
158
167
|
}
|
|
159
168
|
|
|
160
|
-
/**
|
|
169
|
+
/**
|
|
170
|
+
* Creates an account; the server emails a link that opens `verifiedURL` once it is confirmed,
|
|
171
|
+
* written in `locale`, the app's language.
|
|
172
|
+
*/
|
|
161
173
|
export async function signUpToCloudWithEmail(
|
|
162
174
|
discovery: CloudDiscovery,
|
|
163
|
-
input: {
|
|
175
|
+
input: {
|
|
176
|
+
name: string
|
|
177
|
+
email: string
|
|
178
|
+
password: string
|
|
179
|
+
verifiedURL: string
|
|
180
|
+
locale: string
|
|
181
|
+
},
|
|
164
182
|
options: CloudEmailAuthOptions = {}
|
|
165
183
|
): Promise<CloudAuthResult> {
|
|
166
184
|
const result = await createCloudAuthClient(discovery, options)
|
|
@@ -168,6 +186,7 @@ export async function signUpToCloudWithEmail(
|
|
|
168
186
|
name: input.name,
|
|
169
187
|
email: input.email,
|
|
170
188
|
password: input.password,
|
|
189
|
+
locale: input.locale,
|
|
171
190
|
callbackURL: input.verifiedURL
|
|
172
191
|
})
|
|
173
192
|
.catch(() => null)
|