@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,205 @@
|
|
|
1
|
+
import {
|
|
2
|
+
commentPeopleSchema,
|
|
3
|
+
commentThreadResponseSchema,
|
|
4
|
+
notificationSettingsSchema,
|
|
5
|
+
commentThreadsSchema,
|
|
6
|
+
type CloudCommentThread,
|
|
7
|
+
type CommentPerson,
|
|
8
|
+
type NotificationSettings,
|
|
9
|
+
type CommentThreads,
|
|
10
|
+
type CreateCommentInput,
|
|
11
|
+
type CreateCommentThreadInput,
|
|
12
|
+
type ImportCommentThreadsInput,
|
|
13
|
+
type UpdateCommentInput,
|
|
14
|
+
type UpdateCommentThreadInput
|
|
15
|
+
} from '#cloud/contract'
|
|
16
|
+
import type { CloudAPI, PublicCloudAPI } from '#cloud/server/api'
|
|
17
|
+
import type { hc } from 'hono/client'
|
|
18
|
+
import * as v from 'valibot'
|
|
19
|
+
|
|
20
|
+
import { parseResponse, type CloudClientDiagnostic, type CloudResponse } from './response'
|
|
21
|
+
|
|
22
|
+
/** A thread after deleting one of its comments; null once the thread went with its first. */
|
|
23
|
+
const threadOrGoneSchema = v.nullable(commentThreadResponseSchema)
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* What every way of reaching a document's comments does, through membership or a link: the app
|
|
27
|
+
* talks to one without asking which it is.
|
|
28
|
+
*/
|
|
29
|
+
export type CloudCommentRequests = {
|
|
30
|
+
list(): Promise<CommentThreads>
|
|
31
|
+
get(threadId: string): Promise<CloudCommentThread>
|
|
32
|
+
createThread(input: CreateCommentThreadInput): Promise<CloudCommentThread>
|
|
33
|
+
updateThread(threadId: string, input: UpdateCommentThreadInput): Promise<CloudCommentThread>
|
|
34
|
+
deleteThread(threadId: string): Promise<void>
|
|
35
|
+
reply(threadId: string, input: CreateCommentInput): Promise<CloudCommentThread>
|
|
36
|
+
updateComment(
|
|
37
|
+
threadId: string,
|
|
38
|
+
commentId: string,
|
|
39
|
+
input: UpdateCommentInput
|
|
40
|
+
): Promise<CloudCommentThread>
|
|
41
|
+
deleteComment(threadId: string, commentId: string): Promise<CloudCommentThread | null>
|
|
42
|
+
/** Records that the signed-in account read the thread as it is now. */
|
|
43
|
+
markRead(threadId: string): Promise<void>
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function thread(request: Promise<CloudResponse>, onDiagnostic?: CloudClientDiagnostic) {
|
|
47
|
+
return (await parseResponse(request, commentThreadResponseSchema, onDiagnostic)).thread
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function threadOrGone(request: Promise<CloudResponse>, onDiagnostic?: CloudClientDiagnostic) {
|
|
51
|
+
return (await parseResponse(request, threadOrGoneSchema, onDiagnostic))?.thread ?? null
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Comment requests for documents people reach through membership or a direct grant. */
|
|
55
|
+
export function createCommentRequests(
|
|
56
|
+
client: ReturnType<typeof hc<CloudAPI>>,
|
|
57
|
+
onDiagnostic?: CloudClientDiagnostic
|
|
58
|
+
) {
|
|
59
|
+
return {
|
|
60
|
+
/** The comments of a document the signed-in account can open. */
|
|
61
|
+
documentComments(documentId: string): CloudCommentRequests {
|
|
62
|
+
const threads = client.documents[':documentId'].threads
|
|
63
|
+
const one = threads[':threadId']
|
|
64
|
+
const comment = one.comments[':commentId']
|
|
65
|
+
return {
|
|
66
|
+
list: () =>
|
|
67
|
+
parseResponse(
|
|
68
|
+
threads.$get({ param: { documentId } }),
|
|
69
|
+
commentThreadsSchema,
|
|
70
|
+
onDiagnostic
|
|
71
|
+
),
|
|
72
|
+
get: (threadId) => thread(one.$get({ param: { documentId, threadId } }), onDiagnostic),
|
|
73
|
+
createThread: (json) =>
|
|
74
|
+
thread(threads.$post({ param: { documentId }, json }), onDiagnostic),
|
|
75
|
+
updateThread: (threadId, json) =>
|
|
76
|
+
thread(one.$patch({ param: { documentId, threadId }, json }), onDiagnostic),
|
|
77
|
+
deleteThread: async (threadId) => {
|
|
78
|
+
await parseResponse(
|
|
79
|
+
one.$delete({ param: { documentId, threadId } }),
|
|
80
|
+
v.null(),
|
|
81
|
+
onDiagnostic
|
|
82
|
+
)
|
|
83
|
+
},
|
|
84
|
+
reply: (threadId, json) =>
|
|
85
|
+
thread(one.comments.$post({ param: { documentId, threadId }, json }), onDiagnostic),
|
|
86
|
+
updateComment: (threadId, commentId, json) =>
|
|
87
|
+
thread(
|
|
88
|
+
comment.$patch({ param: { documentId, threadId, commentId }, json }),
|
|
89
|
+
onDiagnostic
|
|
90
|
+
),
|
|
91
|
+
deleteComment: (threadId, commentId) =>
|
|
92
|
+
threadOrGone(
|
|
93
|
+
comment.$delete({ param: { documentId, threadId, commentId } }),
|
|
94
|
+
onDiagnostic
|
|
95
|
+
),
|
|
96
|
+
markRead: async (threadId) => {
|
|
97
|
+
await parseResponse(
|
|
98
|
+
one.read.$post({ param: { documentId, threadId } }),
|
|
99
|
+
v.null(),
|
|
100
|
+
onDiagnostic
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
/** Whom the signed-in account may name in a document's comments. */
|
|
107
|
+
async commentPeople(documentId: string): Promise<CommentPerson[]> {
|
|
108
|
+
const response = await parseResponse(
|
|
109
|
+
client.documents[':documentId'].threads.people.$get({ param: { documentId } }),
|
|
110
|
+
commentPeopleSchema,
|
|
111
|
+
onDiagnostic
|
|
112
|
+
)
|
|
113
|
+
return response.people
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
/** Which comments the signed-in account hears about by email. */
|
|
117
|
+
notificationSettings(): Promise<NotificationSettings> {
|
|
118
|
+
return parseResponse(
|
|
119
|
+
client.account.notifications.$get(),
|
|
120
|
+
notificationSettingsSchema,
|
|
121
|
+
onDiagnostic
|
|
122
|
+
)
|
|
123
|
+
},
|
|
124
|
+
setNotificationSettings(json: NotificationSettings): Promise<NotificationSettings> {
|
|
125
|
+
return parseResponse(
|
|
126
|
+
client.account.notifications.$put({ json }),
|
|
127
|
+
notificationSettingsSchema,
|
|
128
|
+
onDiagnostic
|
|
129
|
+
)
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
/** Brings a file's threads into a document that just moved to Cloud. */
|
|
133
|
+
async importCommentThreads(
|
|
134
|
+
documentId: string,
|
|
135
|
+
json: ImportCommentThreadsInput
|
|
136
|
+
): Promise<CommentThreads> {
|
|
137
|
+
return parseResponse(
|
|
138
|
+
client.documents[':documentId'].threads.import.$post({ param: { documentId }, json }),
|
|
139
|
+
commentThreadsSchema,
|
|
140
|
+
onDiagnostic
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Comment requests through a share link, whose secret every request carries in its body. */
|
|
147
|
+
export function createSharedCommentRequests(
|
|
148
|
+
publicClient: ReturnType<typeof hc<PublicCloudAPI>>,
|
|
149
|
+
onDiagnostic?: CloudClientDiagnostic
|
|
150
|
+
) {
|
|
151
|
+
return {
|
|
152
|
+
sharedComments(shareId: string, secret: string): CloudCommentRequests {
|
|
153
|
+
const share = { secret }
|
|
154
|
+
const threads = publicClient.shares[':shareId'].threads
|
|
155
|
+
const one = threads[':threadId']
|
|
156
|
+
const comment = one.comments[':commentId']
|
|
157
|
+
return {
|
|
158
|
+
list: () =>
|
|
159
|
+
parseResponse(
|
|
160
|
+
threads.list.$post({ param: { shareId }, json: { share } }),
|
|
161
|
+
commentThreadsSchema,
|
|
162
|
+
onDiagnostic
|
|
163
|
+
),
|
|
164
|
+
get: (threadId) =>
|
|
165
|
+
thread(one.get.$post({ param: { shareId, threadId }, json: { share } }), onDiagnostic),
|
|
166
|
+
createThread: (input) =>
|
|
167
|
+
thread(threads.$post({ param: { shareId }, json: { share, ...input } }), onDiagnostic),
|
|
168
|
+
updateThread: (threadId, input) =>
|
|
169
|
+
thread(
|
|
170
|
+
one.$patch({ param: { shareId, threadId }, json: { share, ...input } }),
|
|
171
|
+
onDiagnostic
|
|
172
|
+
),
|
|
173
|
+
deleteThread: async (threadId) => {
|
|
174
|
+
await parseResponse(
|
|
175
|
+
one.$delete({ param: { shareId, threadId }, json: { share } }),
|
|
176
|
+
v.null(),
|
|
177
|
+
onDiagnostic
|
|
178
|
+
)
|
|
179
|
+
},
|
|
180
|
+
reply: (threadId, input) =>
|
|
181
|
+
thread(
|
|
182
|
+
one.comments.$post({ param: { shareId, threadId }, json: { share, ...input } }),
|
|
183
|
+
onDiagnostic
|
|
184
|
+
),
|
|
185
|
+
updateComment: (threadId, commentId, input) =>
|
|
186
|
+
thread(
|
|
187
|
+
comment.$patch({ param: { shareId, threadId, commentId }, json: { share, ...input } }),
|
|
188
|
+
onDiagnostic
|
|
189
|
+
),
|
|
190
|
+
deleteComment: (threadId, commentId) =>
|
|
191
|
+
threadOrGone(
|
|
192
|
+
comment.$delete({ param: { shareId, threadId, commentId }, json: { share } }),
|
|
193
|
+
onDiagnostic
|
|
194
|
+
),
|
|
195
|
+
markRead: async (threadId) => {
|
|
196
|
+
await parseResponse(
|
|
197
|
+
one.read.$post({ param: { shareId, threadId }, json: { share } }),
|
|
198
|
+
v.null(),
|
|
199
|
+
onDiagnostic
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
communityDocumentsSchema,
|
|
3
|
+
communityDownloadSchema,
|
|
4
|
+
type CommunityDocuments,
|
|
5
|
+
type CommunityDownload
|
|
6
|
+
} from '#cloud/contract'
|
|
7
|
+
import type { PublicCloudAPI } from '#cloud/server/api'
|
|
8
|
+
import type { hc } from 'hono/client'
|
|
9
|
+
|
|
10
|
+
import { parseResponse, type CloudClientDiagnostic } from './response'
|
|
11
|
+
|
|
12
|
+
/** The server’s community gallery, which anyone may open without signing in. */
|
|
13
|
+
export function createCommunityRequests(
|
|
14
|
+
publicClient: ReturnType<typeof hc<PublicCloudAPI>>,
|
|
15
|
+
onDiagnostic?: CloudClientDiagnostic
|
|
16
|
+
) {
|
|
17
|
+
return {
|
|
18
|
+
/** The gallery's documents, most recently changed first. */
|
|
19
|
+
async listCommunityDocuments(): Promise<CommunityDocuments> {
|
|
20
|
+
return parseResponse(publicClient.community.$get(), communityDocumentsSchema, onDiagnostic)
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* A document of the server's community gallery as it is now, or one of its named versions,
|
|
24
|
+
* which anyone may open without signing in.
|
|
25
|
+
*/
|
|
26
|
+
async getCommunityDocument(
|
|
27
|
+
documentId: string,
|
|
28
|
+
versionId: string | null = null
|
|
29
|
+
): Promise<CommunityDownload> {
|
|
30
|
+
return parseResponse(
|
|
31
|
+
publicClient.community[':documentId'].document.$get({
|
|
32
|
+
param: { documentId },
|
|
33
|
+
query: versionId ? { version: versionId } : {}
|
|
34
|
+
}),
|
|
35
|
+
communityDownloadSchema,
|
|
36
|
+
onDiagnostic
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -2,6 +2,8 @@ import type { CloudDiscovery } from '#cloud/contract'
|
|
|
2
2
|
import { joinURL } from 'ufo'
|
|
3
3
|
import * as v from 'valibot'
|
|
4
4
|
|
|
5
|
+
import { sleep } from '@open-pencil/std/timing'
|
|
6
|
+
|
|
5
7
|
import type { CloudFetch } from './discovery'
|
|
6
8
|
|
|
7
9
|
const deviceCodeSchema = v.object({
|
|
@@ -41,24 +43,6 @@ export type CloudDevicePollingOptions = {
|
|
|
41
43
|
sleep?: (milliseconds: number, signal?: AbortSignal) => Promise<void>
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
function abortableSleep(milliseconds: number, signal?: AbortSignal): Promise<void> {
|
|
45
|
-
return new Promise<void>((resolve, reject) => {
|
|
46
|
-
const timeout = setTimeout(resolve, milliseconds)
|
|
47
|
-
signal?.addEventListener(
|
|
48
|
-
'abort',
|
|
49
|
-
() => {
|
|
50
|
-
clearTimeout(timeout)
|
|
51
|
-
reject(
|
|
52
|
-
signal.reason instanceof Error
|
|
53
|
-
? signal.reason
|
|
54
|
-
: new DOMException('Authorization cancelled', 'AbortError')
|
|
55
|
-
)
|
|
56
|
-
},
|
|
57
|
-
{ once: true }
|
|
58
|
-
)
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
|
|
62
46
|
function authEndpoint(discovery: CloudDiscovery, path: string): string {
|
|
63
47
|
return joinURL(discovery.authURL, path)
|
|
64
48
|
}
|
|
@@ -93,12 +77,12 @@ export async function pollCloudDeviceToken(
|
|
|
93
77
|
): Promise<CloudDeviceToken> {
|
|
94
78
|
const request = options.fetch ?? globalThis.fetch
|
|
95
79
|
const now = options.now ?? Date.now
|
|
96
|
-
const
|
|
80
|
+
const wait = options.sleep ?? sleep
|
|
97
81
|
const expiresAt = now() + authorization.expires_in * 1000
|
|
98
82
|
let interval = authorization.interval * 1000
|
|
99
83
|
while (now() < expiresAt) {
|
|
100
84
|
options.signal?.throwIfAborted()
|
|
101
|
-
await
|
|
85
|
+
await wait(interval, options.signal)
|
|
102
86
|
if (now() >= expiresAt) break
|
|
103
87
|
const response = await request(authEndpoint(discovery, 'device/token'), {
|
|
104
88
|
method: 'POST',
|
package/src/client/discovery.ts
CHANGED
|
@@ -2,24 +2,35 @@ import {
|
|
|
2
2
|
CLOUD_DISCOVERY_PATH,
|
|
3
3
|
CLOUD_PROTOCOL_VERSION,
|
|
4
4
|
cloudDiscoverySchema,
|
|
5
|
+
isEditorVersionAtLeast,
|
|
5
6
|
type CloudDiscovery
|
|
6
7
|
} from '#cloud/contract'
|
|
7
8
|
import * as v from 'valibot'
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
import { anySignal, DEADLINE_MS } from '@open-pencil/std/timing'
|
|
11
|
+
|
|
12
|
+
const DISCOVERY_TIMEOUT_MS = DEADLINE_MS.request
|
|
10
13
|
|
|
11
14
|
export type CloudFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>
|
|
12
15
|
|
|
13
16
|
export type DiscoverCloudOptions = {
|
|
14
17
|
fetch?: CloudFetch
|
|
15
18
|
signal?: AbortSignal
|
|
19
|
+
/** The editor's own version, checked against the server's minimum. */
|
|
20
|
+
editorVersion?: string
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
/**
|
|
19
24
|
* Why a server could not be used: the address is not a web address, nothing answered, something
|
|
20
|
-
* answered but not as OpenPencil Cloud,
|
|
25
|
+
* answered but not as OpenPencil Cloud, the server is older than this editor supports, or this
|
|
26
|
+
* editor is older than the server supports.
|
|
21
27
|
*/
|
|
22
|
-
export type CloudDiscoveryFailure =
|
|
28
|
+
export type CloudDiscoveryFailure =
|
|
29
|
+
| 'invalid-address'
|
|
30
|
+
| 'unreachable'
|
|
31
|
+
| 'not-cloud'
|
|
32
|
+
| 'server-outdated'
|
|
33
|
+
| 'editor-outdated'
|
|
23
34
|
|
|
24
35
|
export class CloudClientError extends Error {
|
|
25
36
|
constructor(
|
|
@@ -55,21 +66,38 @@ function discoveryURL(serverURL: string): URL {
|
|
|
55
66
|
return url
|
|
56
67
|
}
|
|
57
68
|
|
|
58
|
-
|
|
69
|
+
/** Which side is behind when the server speaks another protocol, or null when it doesn't. */
|
|
70
|
+
function protocolMismatch(version: string): CloudDiscoveryFailure | null {
|
|
71
|
+
if (version === CLOUD_PROTOCOL_VERSION) return null
|
|
72
|
+
return Number(version) > Number(CLOUD_PROTOCOL_VERSION) ? 'editor-outdated' : 'server-outdated'
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function parseDiscoveryBody(text: string, editorVersion: string | undefined): CloudDiscovery {
|
|
59
76
|
const body = v.safeParse(discoveryBodySchema, text)
|
|
60
77
|
if (!body.success) {
|
|
61
78
|
throw new CloudClientError('OpenPencil server discovery is not JSON', body.issues, 'not-cloud')
|
|
62
79
|
}
|
|
63
80
|
const discovery = v.safeParse(cloudDiscoverySchema, body.output)
|
|
64
|
-
if (discovery.success)
|
|
81
|
+
if (discovery.success) {
|
|
82
|
+
const minimum = discovery.output.minimumEditorVersion
|
|
83
|
+
if (minimum && editorVersion && !isEditorVersionAtLeast(editorVersion, minimum)) {
|
|
84
|
+
throw new CloudClientError(
|
|
85
|
+
`OpenPencil server needs editor ${minimum} or later`,
|
|
86
|
+
undefined,
|
|
87
|
+
'editor-outdated'
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
return discovery.output
|
|
91
|
+
}
|
|
65
92
|
const protocol = v.safeParse(protocolSchema, body.output)
|
|
66
|
-
const
|
|
93
|
+
const version = protocol.success ? protocol.output.protocolVersion : null
|
|
94
|
+
const mismatch = version === null ? null : protocolMismatch(version)
|
|
67
95
|
throw new CloudClientError(
|
|
68
|
-
|
|
69
|
-
? `OpenPencil server speaks protocol ${
|
|
96
|
+
mismatch
|
|
97
|
+
? `OpenPencil server speaks protocol ${version}`
|
|
70
98
|
: 'OpenPencil server discovery is invalid',
|
|
71
99
|
discovery.issues,
|
|
72
|
-
|
|
100
|
+
mismatch ?? 'not-cloud'
|
|
73
101
|
)
|
|
74
102
|
}
|
|
75
103
|
|
|
@@ -79,7 +107,7 @@ export async function discoverCloud(
|
|
|
79
107
|
): Promise<CloudDiscovery> {
|
|
80
108
|
const fetchImplementation = options.fetch ?? globalThis.fetch
|
|
81
109
|
const timeoutSignal = AbortSignal.timeout(DISCOVERY_TIMEOUT_MS)
|
|
82
|
-
const signal =
|
|
110
|
+
const signal = anySignal([options.signal, timeoutSignal])
|
|
83
111
|
|
|
84
112
|
try {
|
|
85
113
|
const response = await fetchImplementation(discoveryURL(serverURL), {
|
|
@@ -94,7 +122,7 @@ export async function discoverCloud(
|
|
|
94
122
|
response.status >= 500 ? 'unreachable' : 'not-cloud'
|
|
95
123
|
)
|
|
96
124
|
}
|
|
97
|
-
return parseDiscoveryBody(await response.text())
|
|
125
|
+
return parseDiscoveryBody(await response.text(), options.editorVersion)
|
|
98
126
|
} catch (error) {
|
|
99
127
|
if (error instanceof CloudClientError) throw error
|
|
100
128
|
if (signal.aborted) {
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cloudUserProfileSchema,
|
|
3
|
+
documentAccessSchema,
|
|
4
|
+
documentDownloadSchema,
|
|
5
|
+
objectUploadSchema,
|
|
6
|
+
documentSummarySchema,
|
|
7
|
+
sharedDocumentSchema,
|
|
8
|
+
trashSchema,
|
|
9
|
+
type CloudUserProfile,
|
|
10
|
+
type CollaborationTicket,
|
|
11
|
+
type CommitUploadRequest,
|
|
12
|
+
type CreateDocumentRequest,
|
|
13
|
+
type CreateUploadInput,
|
|
14
|
+
type DocumentAccess,
|
|
15
|
+
type DocumentDownload,
|
|
16
|
+
type DocumentSummary,
|
|
17
|
+
type SharedDocument,
|
|
18
|
+
type TrashedDocument
|
|
19
|
+
} from '#cloud/contract'
|
|
20
|
+
import type { CloudAPI } from '#cloud/server/api'
|
|
21
|
+
import type { hc } from 'hono/client'
|
|
22
|
+
import * as v from 'valibot'
|
|
23
|
+
|
|
24
|
+
import { parseResponse, responseBody, type CloudClientDiagnostic } from './response'
|
|
25
|
+
import { collaborationTicketResponseSchema, documentResponseSchema } from './schema'
|
|
26
|
+
|
|
27
|
+
const documentsResponseSchema = v.object({ documents: v.array(documentSummarySchema) })
|
|
28
|
+
const sharedDocumentsResponseSchema = v.object({ documents: v.array(sharedDocumentSchema) })
|
|
29
|
+
const downloadResponseSchema = v.object({ document: documentDownloadSchema })
|
|
30
|
+
const accessResponseSchema = v.object({ access: documentAccessSchema })
|
|
31
|
+
const userLookupResponseSchema = v.object({ user: v.nullable(cloudUserProfileSchema) })
|
|
32
|
+
const uploadResponseSchema = v.object({
|
|
33
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
34
|
+
upload: objectUploadSchema
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
export type CloudUpload = v.InferOutput<typeof uploadResponseSchema>
|
|
38
|
+
|
|
39
|
+
/** Documents: listing and creating them, Trash, downloads, uploads, and collaboration tickets. */
|
|
40
|
+
export function createDocumentRequests(
|
|
41
|
+
client: ReturnType<typeof hc<CloudAPI>>,
|
|
42
|
+
onDiagnostic?: CloudClientDiagnostic
|
|
43
|
+
) {
|
|
44
|
+
return {
|
|
45
|
+
async getUserProfile(documentId: string, userId: string): Promise<CloudUserProfile | null> {
|
|
46
|
+
const response = await parseResponse(
|
|
47
|
+
client.documents[':documentId'].users[':userId'].$get({
|
|
48
|
+
param: { documentId, userId }
|
|
49
|
+
}),
|
|
50
|
+
userLookupResponseSchema,
|
|
51
|
+
onDiagnostic
|
|
52
|
+
)
|
|
53
|
+
return response.user
|
|
54
|
+
},
|
|
55
|
+
/** Documents shared with the person directly, outside their workspaces. */
|
|
56
|
+
async listSharedDocuments(): Promise<SharedDocument[]> {
|
|
57
|
+
const response = await parseResponse(
|
|
58
|
+
client['shared-documents'].$get(),
|
|
59
|
+
sharedDocumentsResponseSchema,
|
|
60
|
+
onDiagnostic
|
|
61
|
+
)
|
|
62
|
+
return response.documents
|
|
63
|
+
},
|
|
64
|
+
async listDocuments(workspaceId: string): Promise<DocumentSummary[]> {
|
|
65
|
+
const response = await parseResponse(
|
|
66
|
+
client.workspaces[':workspaceId'].documents.$get({
|
|
67
|
+
param: { workspaceId }
|
|
68
|
+
}),
|
|
69
|
+
documentsResponseSchema,
|
|
70
|
+
onDiagnostic
|
|
71
|
+
)
|
|
72
|
+
return response.documents
|
|
73
|
+
},
|
|
74
|
+
async createDocument(
|
|
75
|
+
workspaceId: string,
|
|
76
|
+
input: CreateDocumentRequest
|
|
77
|
+
): Promise<DocumentSummary> {
|
|
78
|
+
const response = await parseResponse(
|
|
79
|
+
client.workspaces[':workspaceId'].documents.$post({
|
|
80
|
+
param: { workspaceId },
|
|
81
|
+
json: { ...input, kind: input.kind ?? 'design' }
|
|
82
|
+
}),
|
|
83
|
+
documentResponseSchema,
|
|
84
|
+
onDiagnostic
|
|
85
|
+
)
|
|
86
|
+
return response.document
|
|
87
|
+
},
|
|
88
|
+
/** Documents in Trash the person may restore, across their workspaces, newest first. */
|
|
89
|
+
async listTrash(): Promise<TrashedDocument[]> {
|
|
90
|
+
const response = await parseResponse(client.trash.$get(), trashSchema, onDiagnostic)
|
|
91
|
+
return response.documents
|
|
92
|
+
},
|
|
93
|
+
async restoreDocument(documentId: string): Promise<void> {
|
|
94
|
+
await responseBody(
|
|
95
|
+
await client.trash[':documentId'].restore.$post({ param: { documentId } }),
|
|
96
|
+
onDiagnostic
|
|
97
|
+
)
|
|
98
|
+
},
|
|
99
|
+
/** Deletes a document in Trash for good. */
|
|
100
|
+
async purgeDocument(documentId: string): Promise<void> {
|
|
101
|
+
await responseBody(
|
|
102
|
+
await client.trash[':documentId'].$delete({ param: { documentId } }),
|
|
103
|
+
onDiagnostic
|
|
104
|
+
)
|
|
105
|
+
},
|
|
106
|
+
async deleteDocument(documentId: string): Promise<void> {
|
|
107
|
+
await responseBody(
|
|
108
|
+
await client.documents[':documentId'].$delete({ param: { documentId } }),
|
|
109
|
+
onDiagnostic
|
|
110
|
+
)
|
|
111
|
+
},
|
|
112
|
+
async getDocument(documentId: string): Promise<DocumentDownload> {
|
|
113
|
+
const response = await parseResponse(
|
|
114
|
+
client.documents[':documentId'].$get({ param: { documentId } }),
|
|
115
|
+
downloadResponseSchema,
|
|
116
|
+
onDiagnostic
|
|
117
|
+
)
|
|
118
|
+
return response.document
|
|
119
|
+
},
|
|
120
|
+
async getDocumentAccess(documentId: string): Promise<DocumentAccess> {
|
|
121
|
+
const response = await parseResponse(
|
|
122
|
+
client.documents[':documentId'].access.$get({ param: { documentId } }),
|
|
123
|
+
accessResponseSchema,
|
|
124
|
+
onDiagnostic
|
|
125
|
+
)
|
|
126
|
+
return response.access
|
|
127
|
+
},
|
|
128
|
+
async getCollaborationTicket(documentId: string): Promise<CollaborationTicket> {
|
|
129
|
+
const response = await parseResponse(
|
|
130
|
+
client.documents[':documentId']['collaboration-ticket'].$post({
|
|
131
|
+
param: { documentId }
|
|
132
|
+
}),
|
|
133
|
+
collaborationTicketResponseSchema,
|
|
134
|
+
onDiagnostic
|
|
135
|
+
)
|
|
136
|
+
return response.ticket
|
|
137
|
+
},
|
|
138
|
+
async createUpload(documentId: string, input: CreateUploadInput): Promise<CloudUpload> {
|
|
139
|
+
return parseResponse(
|
|
140
|
+
client.documents[':documentId'].uploads.$post({
|
|
141
|
+
param: { documentId },
|
|
142
|
+
json: input
|
|
143
|
+
}),
|
|
144
|
+
uploadResponseSchema,
|
|
145
|
+
onDiagnostic
|
|
146
|
+
)
|
|
147
|
+
},
|
|
148
|
+
async commitUpload(uploadId: string, input: CommitUploadRequest): Promise<DocumentSummary> {
|
|
149
|
+
const response = await parseResponse(
|
|
150
|
+
client.uploads[':uploadId'].commit.$post({
|
|
151
|
+
param: { uploadId },
|
|
152
|
+
json: { ...input, images: input.images ?? [] }
|
|
153
|
+
}),
|
|
154
|
+
documentResponseSchema,
|
|
155
|
+
onDiagnostic
|
|
156
|
+
)
|
|
157
|
+
return response.document
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { CLOUD_IMAGE_NAME_PATTERN } from '#cloud/contract'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
readStreamBytes,
|
|
5
|
+
readZipDirectory,
|
|
6
|
+
zipEntryContents,
|
|
7
|
+
zipStream,
|
|
8
|
+
type ZipEntry,
|
|
9
|
+
type ZipStreamEntry
|
|
10
|
+
} from '@open-pencil/fig'
|
|
11
|
+
|
|
12
|
+
/** Where a `.fig` archive keeps its images, each under the name its paints refer to. */
|
|
13
|
+
const IMAGE_ENTRY_PREFIX = 'images/'
|
|
14
|
+
|
|
15
|
+
/** An image a `.fig` archive holds, as Cloud stores it apart from the file. */
|
|
16
|
+
export type CloudDocumentImage = { name: string; bytes: Uint8Array }
|
|
17
|
+
|
|
18
|
+
function archiveEntry(bytes: Uint8Array, entry: ZipEntry): ZipStreamEntry {
|
|
19
|
+
return { name: entry.name, data: zipEntryContents(bytes, entry), deflate: entry.method !== 0 }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The archive without its images, and the images, as views of `bytes`. A file that is not a zip
|
|
24
|
+
* archive, or holds no images, comes back whole; an image under a name Cloud does not store
|
|
25
|
+
* apart stays inside.
|
|
26
|
+
*/
|
|
27
|
+
export async function splitCloudDocument(
|
|
28
|
+
bytes: Uint8Array
|
|
29
|
+
): Promise<{ lean: Uint8Array; images: CloudDocumentImage[] }> {
|
|
30
|
+
const entries = readZipDirectory(bytes)
|
|
31
|
+
if (!entries) return { lean: bytes, images: [] }
|
|
32
|
+
const images: CloudDocumentImage[] = []
|
|
33
|
+
const rest: ZipStreamEntry[] = []
|
|
34
|
+
for (const entry of entries) {
|
|
35
|
+
const name = entry.name.startsWith(IMAGE_ENTRY_PREFIX)
|
|
36
|
+
? entry.name.slice(IMAGE_ENTRY_PREFIX.length)
|
|
37
|
+
: null
|
|
38
|
+
// An empty image, or one under a name Cloud does not take, stays inside the file.
|
|
39
|
+
if (name && CLOUD_IMAGE_NAME_PATTERN.test(name) && entry.size > 0) {
|
|
40
|
+
images.push({ name, bytes: zipEntryContents(bytes, entry) })
|
|
41
|
+
} else rest.push(archiveEntry(bytes, entry))
|
|
42
|
+
}
|
|
43
|
+
if (images.length === 0) return { lean: bytes, images }
|
|
44
|
+
return { lean: await readStreamBytes(zipStream(rest)), images }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The archive with its images put back under their names; the lean archive when there are none. */
|
|
48
|
+
export async function assembleCloudDocument(
|
|
49
|
+
lean: Uint8Array,
|
|
50
|
+
images: CloudDocumentImage[]
|
|
51
|
+
): Promise<Uint8Array> {
|
|
52
|
+
const entries = images.length === 0 ? null : readZipDirectory(lean)
|
|
53
|
+
if (!entries) return lean
|
|
54
|
+
return readStreamBytes(
|
|
55
|
+
zipStream([
|
|
56
|
+
...entries.map((entry) => archiveEntry(lean, entry)),
|
|
57
|
+
...images.map((image) => ({ name: `${IMAGE_ENTRY_PREFIX}${image.name}`, data: image.bytes }))
|
|
58
|
+
])
|
|
59
|
+
)
|
|
60
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { sha256 } from '@noble/hashes/sha2.js'
|
|
2
|
+
import { fromUint8Array } from 'js-base64'
|
|
3
|
+
|
|
4
|
+
/** The SHA-256 of `bytes`, in Base64, as Cloud checks an upload against it. */
|
|
5
|
+
export async function cloudChecksum(bytes: Uint8Array): Promise<string> {
|
|
6
|
+
return fromUint8Array(sha256(bytes))
|
|
7
|
+
}
|