@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,223 @@
|
|
|
1
|
+
import * as v from 'valibot'
|
|
2
|
+
|
|
3
|
+
import { resolveDocumentShareSchema } from './sharing'
|
|
4
|
+
|
|
5
|
+
/** The most a comment may say, in characters. */
|
|
6
|
+
export const COMMENT_BODY_MAX_LENGTH = 10_000
|
|
7
|
+
/** The most threads one document may hold, resolved ones included. */
|
|
8
|
+
export const MAX_COMMENT_THREADS_PER_DOCUMENT = 5_000
|
|
9
|
+
/** The most comments one thread may hold, its first one included. */
|
|
10
|
+
export const MAX_COMMENTS_PER_THREAD = 500
|
|
11
|
+
/** The most a page, layer or author name in a comment may hold, in characters. */
|
|
12
|
+
export const COMMENT_NAME_MAX_LENGTH = 255
|
|
13
|
+
const ID_MAX_LENGTH = 200
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Who wrote a comment: an account, whose name is null once it is deleted, or a name a file gave
|
|
17
|
+
* when the comment came in with it, which no account vouches for.
|
|
18
|
+
*/
|
|
19
|
+
export const commentAuthorSchema = v.variant('kind', [
|
|
20
|
+
v.object({ kind: v.literal('user'), id: v.string(), name: v.nullable(v.string()) }),
|
|
21
|
+
v.object({ kind: v.literal('imported'), name: v.string() })
|
|
22
|
+
])
|
|
23
|
+
export type CommentAuthor = v.InferOutput<typeof commentAuthorSchema>
|
|
24
|
+
|
|
25
|
+
export const cloudCommentSchema = v.object({
|
|
26
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
27
|
+
author: commentAuthorSchema,
|
|
28
|
+
/** The agent that wrote it on its author's behalf. */
|
|
29
|
+
agent: v.nullable(v.string()),
|
|
30
|
+
/** Markdown, as the editor writes it. */
|
|
31
|
+
body: v.string(),
|
|
32
|
+
/** The accounts it names, which hear about it. */
|
|
33
|
+
mentions: v.array(v.string()),
|
|
34
|
+
createdAt: v.string(),
|
|
35
|
+
editedAt: v.nullable(v.string())
|
|
36
|
+
})
|
|
37
|
+
export type CloudComment = v.InferOutput<typeof cloudCommentSchema>
|
|
38
|
+
|
|
39
|
+
/** Where a pin sits, as the editor places it. */
|
|
40
|
+
const commentAnchorEntries = {
|
|
41
|
+
pageId: v.pipe(v.string(), v.minLength(1), v.maxLength(ID_MAX_LENGTH)),
|
|
42
|
+
pageName: v.nullable(v.pipe(v.string(), v.maxLength(COMMENT_NAME_MAX_LENGTH))),
|
|
43
|
+
/** The top-level layer the pin follows, if any. */
|
|
44
|
+
nodeId: v.nullable(v.pipe(v.string(), v.minLength(1), v.maxLength(ID_MAX_LENGTH))),
|
|
45
|
+
nodeName: v.nullable(v.pipe(v.string(), v.maxLength(COMMENT_NAME_MAX_LENGTH))),
|
|
46
|
+
/** The pin's offset from the layer's top-left corner. */
|
|
47
|
+
offsetX: v.nullable(v.pipe(v.number(), v.finite())),
|
|
48
|
+
offsetY: v.nullable(v.pipe(v.number(), v.finite())),
|
|
49
|
+
/** The pin's canvas position, used once the layer is gone. */
|
|
50
|
+
x: v.pipe(v.number(), v.finite()),
|
|
51
|
+
y: v.pipe(v.number(), v.finite())
|
|
52
|
+
}
|
|
53
|
+
export const commentAnchorSchema = v.object(commentAnchorEntries)
|
|
54
|
+
export type CommentAnchor = v.InferOutput<typeof commentAnchorSchema>
|
|
55
|
+
|
|
56
|
+
export const cloudCommentThreadSchema = v.object({
|
|
57
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
58
|
+
...commentAnchorEntries,
|
|
59
|
+
createdAt: v.string(),
|
|
60
|
+
/** When anything in the thread last changed: a comment, the pin, or whether it is resolved. */
|
|
61
|
+
updatedAt: v.string(),
|
|
62
|
+
resolvedAt: v.nullable(v.string()),
|
|
63
|
+
resolvedBy: v.nullable(v.string()),
|
|
64
|
+
/** Who started it, or brought it in from a file: they may move its pin and delete it. */
|
|
65
|
+
createdBy: v.string(),
|
|
66
|
+
/** Whether someone else wrote in it since the asker last read it; false for a guest. */
|
|
67
|
+
unread: v.boolean(),
|
|
68
|
+
/** Oldest first; the first is what started the thread. */
|
|
69
|
+
comments: v.array(cloudCommentSchema)
|
|
70
|
+
})
|
|
71
|
+
export type CloudCommentThread = v.InferOutput<typeof cloudCommentThreadSchema>
|
|
72
|
+
|
|
73
|
+
/** What the person asking may do with the document's comments. */
|
|
74
|
+
export const commentAccessSchema = v.object({
|
|
75
|
+
/** Start threads, reply, and change their own comments; anyone signed in who can view. */
|
|
76
|
+
canComment: v.boolean(),
|
|
77
|
+
/** Delete anyone's comments; editors. */
|
|
78
|
+
canModerate: v.boolean(),
|
|
79
|
+
/** The asker's account, which their own comments name; null for a guest. */
|
|
80
|
+
accountId: v.nullable(v.string())
|
|
81
|
+
})
|
|
82
|
+
export type CommentAccess = v.InferOutput<typeof commentAccessSchema>
|
|
83
|
+
|
|
84
|
+
export const commentThreadsSchema = v.object({
|
|
85
|
+
threads: v.array(cloudCommentThreadSchema),
|
|
86
|
+
access: commentAccessSchema
|
|
87
|
+
})
|
|
88
|
+
export type CommentThreads = v.InferOutput<typeof commentThreadsSchema>
|
|
89
|
+
|
|
90
|
+
export const commentThreadResponseSchema = v.object({ thread: cloudCommentThreadSchema })
|
|
91
|
+
|
|
92
|
+
const bodySchema = v.pipe(
|
|
93
|
+
v.string(),
|
|
94
|
+
v.trim(),
|
|
95
|
+
v.minLength(1),
|
|
96
|
+
v.maxLength(COMMENT_BODY_MAX_LENGTH)
|
|
97
|
+
)
|
|
98
|
+
/** The most accounts one comment names. */
|
|
99
|
+
export const MAX_COMMENT_MENTIONS = 50
|
|
100
|
+
/** The accounts a comment names; the server keeps those who can read the document. */
|
|
101
|
+
const mentionsSchema = v.optional(
|
|
102
|
+
v.pipe(
|
|
103
|
+
v.array(v.pipe(v.string(), v.minLength(1), v.maxLength(200))),
|
|
104
|
+
v.maxLength(MAX_COMMENT_MENTIONS)
|
|
105
|
+
),
|
|
106
|
+
[]
|
|
107
|
+
)
|
|
108
|
+
/** The longest agent name a comment keeps. */
|
|
109
|
+
export const MAX_COMMENT_AGENT_LENGTH = 100
|
|
110
|
+
const agentSchema = v.optional(
|
|
111
|
+
v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(MAX_COMMENT_AGENT_LENGTH))
|
|
112
|
+
)
|
|
113
|
+
/**
|
|
114
|
+
* The ID the editor gave a new thread or comment, so it keeps showing it as the server's, and a
|
|
115
|
+
* request sent again finds what the first one made.
|
|
116
|
+
*/
|
|
117
|
+
const clientIdSchema = v.optional(v.pipe(v.string(), v.uuid()))
|
|
118
|
+
|
|
119
|
+
export const createCommentThreadSchema = v.object({
|
|
120
|
+
id: clientIdSchema,
|
|
121
|
+
...commentAnchorEntries,
|
|
122
|
+
body: bodySchema,
|
|
123
|
+
mentions: mentionsSchema,
|
|
124
|
+
agent: agentSchema
|
|
125
|
+
})
|
|
126
|
+
export type CreateCommentThreadInput = v.InferOutput<typeof createCommentThreadSchema>
|
|
127
|
+
|
|
128
|
+
/** Resolves or reopens a thread, or moves its pin; what is left out stays as it is. */
|
|
129
|
+
export const updateCommentThreadSchema = v.object({
|
|
130
|
+
resolved: v.optional(v.boolean()),
|
|
131
|
+
anchor: v.optional(commentAnchorSchema)
|
|
132
|
+
})
|
|
133
|
+
export type UpdateCommentThreadInput = v.InferOutput<typeof updateCommentThreadSchema>
|
|
134
|
+
|
|
135
|
+
export const createCommentSchema = v.object({
|
|
136
|
+
id: clientIdSchema,
|
|
137
|
+
body: bodySchema,
|
|
138
|
+
mentions: mentionsSchema,
|
|
139
|
+
agent: agentSchema
|
|
140
|
+
})
|
|
141
|
+
export type CreateCommentInput = v.InferOutput<typeof createCommentSchema>
|
|
142
|
+
|
|
143
|
+
export const updateCommentSchema = v.object({ body: bodySchema, mentions: mentionsSchema })
|
|
144
|
+
export type UpdateCommentInput = v.InferOutput<typeof updateCommentSchema>
|
|
145
|
+
|
|
146
|
+
/** Someone a comment may name: an account that can open the document. */
|
|
147
|
+
export const commentPersonSchema = v.object({
|
|
148
|
+
id: v.string(),
|
|
149
|
+
name: v.string(),
|
|
150
|
+
image: v.nullable(v.string())
|
|
151
|
+
})
|
|
152
|
+
export type CommentPerson = v.InferOutput<typeof commentPersonSchema>
|
|
153
|
+
export const commentPeopleSchema = v.object({ people: v.array(commentPersonSchema) })
|
|
154
|
+
|
|
155
|
+
/** Which comments an account hears about by email. */
|
|
156
|
+
export const commentEmailSettingSchema = v.picklist(['all', 'mentions', 'off'])
|
|
157
|
+
export type CommentEmailSetting = v.InferOutput<typeof commentEmailSettingSchema>
|
|
158
|
+
export const notificationSettingsSchema = v.object({ commentEmails: commentEmailSettingSchema })
|
|
159
|
+
export type NotificationSettings = v.InferOutput<typeof notificationSettingsSchema>
|
|
160
|
+
|
|
161
|
+
/** The most threads, and comments in all, one import brings in. */
|
|
162
|
+
export const MAX_IMPORTED_COMMENT_THREADS = 1_000
|
|
163
|
+
export const MAX_IMPORTED_COMMENTS = 10_000
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Threads a file held when it moved to Cloud. Their authors are names the file gave, which the
|
|
167
|
+
* server keeps as such; their times are the file's.
|
|
168
|
+
*/
|
|
169
|
+
export const importCommentThreadsSchema = v.object({
|
|
170
|
+
threads: v.pipe(
|
|
171
|
+
v.array(
|
|
172
|
+
v.object({
|
|
173
|
+
...commentAnchorEntries,
|
|
174
|
+
createdAt: v.pipe(v.string(), v.isoTimestamp()),
|
|
175
|
+
resolved: v.boolean(),
|
|
176
|
+
// A file's thread comes in whole, however long; only new replies keep to the limit.
|
|
177
|
+
comments: v.pipe(
|
|
178
|
+
v.array(
|
|
179
|
+
v.object({
|
|
180
|
+
authorName: v.pipe(v.string(), v.trim(), v.maxLength(COMMENT_NAME_MAX_LENGTH)),
|
|
181
|
+
body: bodySchema,
|
|
182
|
+
createdAt: v.pipe(v.string(), v.isoTimestamp())
|
|
183
|
+
})
|
|
184
|
+
),
|
|
185
|
+
v.minLength(1),
|
|
186
|
+
v.maxLength(MAX_IMPORTED_COMMENTS)
|
|
187
|
+
)
|
|
188
|
+
})
|
|
189
|
+
),
|
|
190
|
+
v.maxLength(MAX_IMPORTED_COMMENT_THREADS),
|
|
191
|
+
v.check(
|
|
192
|
+
(threads) =>
|
|
193
|
+
threads.reduce((total, thread) => total + thread.comments.length, 0) <=
|
|
194
|
+
MAX_IMPORTED_COMMENTS,
|
|
195
|
+
`An import brings in at most ${MAX_IMPORTED_COMMENTS} comments`
|
|
196
|
+
)
|
|
197
|
+
)
|
|
198
|
+
})
|
|
199
|
+
export type ImportCommentThreadsInput = v.InferOutput<typeof importCommentThreadsSchema>
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* The same requests made through a share link: the link's secret rides in the body, as it does
|
|
203
|
+
* for opening the document, since it must stay out of the address.
|
|
204
|
+
*/
|
|
205
|
+
const shareEntries = { share: v.pick(resolveDocumentShareSchema, ['secret']) }
|
|
206
|
+
export const sharedCommentsRequestSchema = v.object(shareEntries)
|
|
207
|
+
export const sharedCreateCommentThreadSchema = v.object({
|
|
208
|
+
...shareEntries,
|
|
209
|
+
...createCommentThreadSchema.entries
|
|
210
|
+
})
|
|
211
|
+
export const sharedUpdateCommentThreadSchema = v.object({
|
|
212
|
+
...shareEntries,
|
|
213
|
+
...updateCommentThreadSchema.entries
|
|
214
|
+
})
|
|
215
|
+
export const sharedCreateCommentSchema = v.object({
|
|
216
|
+
...shareEntries,
|
|
217
|
+
...createCommentSchema.entries
|
|
218
|
+
})
|
|
219
|
+
export const sharedUpdateCommentSchema = v.object({
|
|
220
|
+
...shareEntries,
|
|
221
|
+
...updateCommentSchema.entries
|
|
222
|
+
})
|
|
223
|
+
export type SharedCommentsRequest = v.InferOutput<typeof sharedCommentsRequestSchema>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as v from 'valibot'
|
|
2
|
+
|
|
3
|
+
import { documentDownloadSchema, documentKindSchema } from './documents'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Where a community document's thumbnail is served, by its document and revision: the address
|
|
7
|
+
* changes with each save, so a cached copy never shows an older state.
|
|
8
|
+
*/
|
|
9
|
+
export const COMMUNITY_THUMBNAIL_PATH = '/api/community/thumbnails'
|
|
10
|
+
|
|
11
|
+
export function communityThumbnailPath(documentId: string, revisionId: string): string {
|
|
12
|
+
return `${COMMUNITY_THUMBNAIL_PATH}/${documentId}/${revisionId}`
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** A version of a community document someone named, such as the release it was published for. */
|
|
16
|
+
export const communityVersionSchema = v.object({
|
|
17
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
18
|
+
name: v.string(),
|
|
19
|
+
description: v.nullable(v.string()),
|
|
20
|
+
createdAt: v.string(),
|
|
21
|
+
/** Whether the document holds this version now, with nothing changed since it was named. */
|
|
22
|
+
current: v.boolean()
|
|
23
|
+
})
|
|
24
|
+
export type CommunityVersion = v.InferOutput<typeof communityVersionSchema>
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A document in the deployment's community workspace, which anyone may open read-only: its name,
|
|
28
|
+
* when it last changed, its thumbnail's path on the server, and its named versions, newest first.
|
|
29
|
+
*/
|
|
30
|
+
export const communityDocumentSchema = v.object({
|
|
31
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
32
|
+
name: v.string(),
|
|
33
|
+
kind: documentKindSchema,
|
|
34
|
+
updatedAt: v.string(),
|
|
35
|
+
revisionId: v.pipe(v.string(), v.uuid()),
|
|
36
|
+
thumbnailPath: v.string(),
|
|
37
|
+
versions: v.array(communityVersionSchema)
|
|
38
|
+
})
|
|
39
|
+
export type CommunityDocument = v.InferOutput<typeof communityDocumentSchema>
|
|
40
|
+
|
|
41
|
+
/** The community workspace's documents, most recently changed first. */
|
|
42
|
+
export const communityDocumentsSchema = v.object({ documents: v.array(communityDocumentSchema) })
|
|
43
|
+
export type CommunityDocuments = v.InferOutput<typeof communityDocumentsSchema>
|
|
44
|
+
|
|
45
|
+
/** Which state of a community document to open: a named version, or else the latest. */
|
|
46
|
+
export const communityDownloadQuerySchema = v.object({
|
|
47
|
+
version: v.optional(v.pipe(v.string(), v.uuid()))
|
|
48
|
+
})
|
|
49
|
+
export type CommunityDownloadQuery = v.InferOutput<typeof communityDownloadQuerySchema>
|
|
50
|
+
|
|
51
|
+
export function parseCommunityDownloadQuery(input: unknown): CommunityDownloadQuery {
|
|
52
|
+
return v.parse(communityDownloadQuerySchema, input)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** A community document, or one of its named versions, with where to download it. */
|
|
56
|
+
export const communityDownloadSchema = v.object({
|
|
57
|
+
document: documentDownloadSchema,
|
|
58
|
+
version: v.nullable(communityVersionSchema)
|
|
59
|
+
})
|
|
60
|
+
export type CommunityDownload = v.InferOutput<typeof communityDownloadSchema>
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import compareVersions from 'semver/functions/compare.js'
|
|
2
|
+
import parseVersion from 'semver/functions/parse.js'
|
|
1
3
|
import * as v from 'valibot'
|
|
2
4
|
|
|
3
|
-
import {
|
|
5
|
+
import { isKnownSocialProvider } from './account'
|
|
6
|
+
import { cloudBillingDiscoverySchema } from './billing'
|
|
7
|
+
import { cloudServicesDiscoverySchema } from './services'
|
|
4
8
|
|
|
5
9
|
export const CLOUD_PROTOCOL_VERSION = '1' as const
|
|
6
10
|
export const CLOUD_DISCOVERY_PATH = '/.well-known/openpencil' as const
|
|
@@ -8,6 +12,15 @@ export const CLOUD_DISCOVERY_PATH = '/.well-known/openpencil' as const
|
|
|
8
12
|
export const cloudDeploymentSchema = v.picklist(['official', 'self-hosted'])
|
|
9
13
|
export type CloudDeployment = v.InferOutput<typeof cloudDeploymentSchema>
|
|
10
14
|
|
|
15
|
+
/**
|
|
16
|
+
* The server's sign-in providers that this editor knows. A newer server may offer one this editor
|
|
17
|
+
* has no button for; it is left out rather than failing discovery, so the editor still connects.
|
|
18
|
+
*/
|
|
19
|
+
const socialProvidersSchema = v.pipe(
|
|
20
|
+
v.array(v.string()),
|
|
21
|
+
v.transform((providers) => providers.filter(isKnownSocialProvider))
|
|
22
|
+
)
|
|
23
|
+
|
|
11
24
|
export const cloudAuthenticationSchema = v.object({
|
|
12
25
|
emailPassword: v.optional(
|
|
13
26
|
v.object({
|
|
@@ -22,7 +35,7 @@ export const cloudAuthenticationSchema = v.object({
|
|
|
22
35
|
)
|
|
23
36
|
})
|
|
24
37
|
),
|
|
25
|
-
socialProviders:
|
|
38
|
+
socialProviders: socialProvidersSchema,
|
|
26
39
|
enterpriseSSO: v.boolean(),
|
|
27
40
|
enrollmentMode: v.optional(v.picklist(['open', 'approval', 'closed']), 'open'),
|
|
28
41
|
mfa: v.optional(
|
|
@@ -43,8 +56,47 @@ export const cloudCapabilitiesSchema = v.object({
|
|
|
43
56
|
})
|
|
44
57
|
export type CloudCapabilities = v.InferOutput<typeof cloudCapabilitiesSchema>
|
|
45
58
|
|
|
46
|
-
/**
|
|
47
|
-
|
|
59
|
+
/**
|
|
60
|
+
* An editor version, as SemVer: a release such as `0.18.0`, or a pre-release such as
|
|
61
|
+
* `0.18.0-beta.2` or a nightly's `0.18.0-nightly.20261116`.
|
|
62
|
+
*
|
|
63
|
+
* Editors before 0.18.0 accept only `major.minor.patch` here and fail discovery on anything else,
|
|
64
|
+
* so a server names a pre-release minimum only once its minimum is already 0.18.0 or later.
|
|
65
|
+
*/
|
|
66
|
+
export const cloudEditorVersionSchema = v.pipe(
|
|
67
|
+
v.string(),
|
|
68
|
+
v.check(isSemVer, 'Expected a SemVer version')
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Whether the text is exactly a SemVer version, build metadata included: semver's own parse also
|
|
73
|
+
* takes a `v` prefix or spaces, which a version here never has.
|
|
74
|
+
*/
|
|
75
|
+
function isSemVer(value: string): boolean {
|
|
76
|
+
const parsed = parseVersion(value)
|
|
77
|
+
if (!parsed) return false
|
|
78
|
+
const build = parsed.build.length > 0 ? `+${parsed.build.join('.')}` : ''
|
|
79
|
+
return `${parsed.version}${build}` === value
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The header desktop editors send with each request, naming their version, so a server can refuse
|
|
84
|
+
* an editor older than its `minimumEditorVersion`. Browser editors leave it out: the server serves
|
|
85
|
+
* them, and an older server's CORS rules would refuse a header they don't list.
|
|
86
|
+
*/
|
|
87
|
+
export const CLOUD_EDITOR_VERSION_HEADER = 'X-OpenPencil-Editor-Version' as const
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Whether `version` is `minimum` or later, in SemVer order: a pre-release comes before its
|
|
91
|
+
* release, so `0.18.0-beta.2` is not at least `0.18.0`; a release's nightlies come after its
|
|
92
|
+
* betas and order by date. To admit a release's pre-releases, name the earliest one, such as
|
|
93
|
+
* `0.18.0-beta.1`, or `0.18.0-nightly.20261116` for nightlies from that day on. A
|
|
94
|
+
* version that isn't SemVer, on either side, is not at least anything.
|
|
95
|
+
*/
|
|
96
|
+
export function isEditorVersionAtLeast(version: string, minimum: string): boolean {
|
|
97
|
+
if (!isSemVer(version) || !isSemVer(minimum)) return false
|
|
98
|
+
return compareVersions(version, minimum) >= 0
|
|
99
|
+
}
|
|
48
100
|
|
|
49
101
|
/**
|
|
50
102
|
* Whether editors offer this server to everyone, and from which editor version on. Only the
|
|
@@ -71,6 +123,35 @@ export const cloudLegalDiscoverySchema = v.object({
|
|
|
71
123
|
})
|
|
72
124
|
export type CloudLegalDiscovery = v.InferOutput<typeof cloudLegalDiscoverySchema>
|
|
73
125
|
|
|
126
|
+
/** A web address a page may link or load: `http` or `https` only, never a script or data URL. */
|
|
127
|
+
const webURLSchema = v.pipe(
|
|
128
|
+
v.string(),
|
|
129
|
+
v.url(),
|
|
130
|
+
v.check((value) => ['http:', 'https:'].includes(new URL(value).protocol))
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* How a self-hosted server names itself on its public pages: the operator's name and logo in the
|
|
135
|
+
* bar, and where its people get help. The official server is OpenPencil's own and names none.
|
|
136
|
+
*/
|
|
137
|
+
export const cloudBrandingSchema = v.object({
|
|
138
|
+
name: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(80))),
|
|
139
|
+
logoURL: v.optional(webURLSchema),
|
|
140
|
+
helpURL: v.optional(webURLSchema)
|
|
141
|
+
})
|
|
142
|
+
export type CloudBranding = v.InferOutput<typeof cloudBrandingSchema>
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* The server's community gallery: the workspace whose documents anyone may open read-only.
|
|
146
|
+
* Saving to it publishes, so editors never choose it for anyone and say so when it is chosen.
|
|
147
|
+
* `tourDocumentId` is the gallery document editors open as their tour.
|
|
148
|
+
*/
|
|
149
|
+
export const cloudCommunityDiscoverySchema = v.object({
|
|
150
|
+
workspaceId: v.pipe(v.string(), v.uuid()),
|
|
151
|
+
tourDocumentId: v.optional(v.pipe(v.string(), v.uuid()))
|
|
152
|
+
})
|
|
153
|
+
export type CloudCommunityDiscovery = v.InferOutput<typeof cloudCommunityDiscoverySchema>
|
|
154
|
+
|
|
74
155
|
export const cloudDiscoverySchema = v.object({
|
|
75
156
|
protocolVersion: v.literal(CLOUD_PROTOCOL_VERSION),
|
|
76
157
|
deployment: cloudDeploymentSchema,
|
|
@@ -81,11 +162,19 @@ export const cloudDiscoverySchema = v.object({
|
|
|
81
162
|
authentication: cloudAuthenticationSchema,
|
|
82
163
|
capabilities: cloudCapabilitiesSchema,
|
|
83
164
|
listing: v.optional(cloudListingSchema),
|
|
165
|
+
/**
|
|
166
|
+
* The oldest editor version the server works with. Older editors ask to be updated instead of
|
|
167
|
+
* connecting, and the server refuses their requests.
|
|
168
|
+
*/
|
|
169
|
+
minimumEditorVersion: v.optional(cloudEditorVersionSchema),
|
|
84
170
|
/** The services editors reach with Cloud-signed tokens; absent when the deployment has none. */
|
|
85
171
|
services: v.optional(cloudServicesDiscoverySchema),
|
|
86
172
|
/** Where people manage their plan and buy credits; absent when the deployment does not bill. */
|
|
87
173
|
billing: v.optional(cloudBillingDiscoverySchema),
|
|
88
|
-
|
|
174
|
+
/** The community gallery; absent when the deployment has none. */
|
|
175
|
+
community: v.optional(cloudCommunityDiscoverySchema),
|
|
176
|
+
legal: v.optional(cloudLegalDiscoverySchema),
|
|
177
|
+
branding: v.optional(cloudBrandingSchema)
|
|
89
178
|
})
|
|
90
179
|
export type CloudDiscovery = v.InferOutput<typeof cloudDiscoverySchema>
|
|
91
180
|
|
|
@@ -26,3 +26,13 @@ export const workspaceEntitlementsSchema = v.object({
|
|
|
26
26
|
})
|
|
27
27
|
})
|
|
28
28
|
export type WorkspaceEntitlements = v.InferOutput<typeof workspaceEntitlementsSchema>
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* An account's own plan and the storage its workspaces hold together. A workspace reports the
|
|
32
|
+
* same for its owner, so the two read alike.
|
|
33
|
+
*/
|
|
34
|
+
export const accountEntitlementsSchema = workspaceEntitlementsSchema
|
|
35
|
+
export type AccountEntitlements = WorkspaceEntitlements
|
|
36
|
+
export const accountEntitlementsResponseSchema = v.object({
|
|
37
|
+
entitlements: accountEntitlementsSchema
|
|
38
|
+
})
|
package/src/contract/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from './account'
|
|
2
|
+
export * from './locale'
|
|
2
3
|
export {
|
|
3
4
|
SERVICE_ERROR_STATUS,
|
|
5
|
+
roleModelsSchema,
|
|
4
6
|
serviceCatalogSchema,
|
|
5
7
|
creditBucketSchema,
|
|
6
8
|
serviceErrorCodeSchema,
|
|
@@ -23,11 +25,11 @@ export {
|
|
|
23
25
|
CLOUD_SERVICES_JWKS_PATH,
|
|
24
26
|
CLOUD_SERVICES_TOKEN_AUDIENCE,
|
|
25
27
|
cloudServicesDiscoverySchema,
|
|
26
|
-
cloudBillingDiscoverySchema,
|
|
27
28
|
createServicesTokenSchema,
|
|
28
29
|
parseUsageQuery,
|
|
29
30
|
parseSearchRequest,
|
|
30
31
|
parseCreateServicesToken,
|
|
32
|
+
type RoleModels,
|
|
31
33
|
type ServiceCatalog,
|
|
32
34
|
type CreditBucket,
|
|
33
35
|
type ServiceError,
|
|
@@ -45,11 +47,48 @@ export {
|
|
|
45
47
|
type SearchResult,
|
|
46
48
|
type SearchResponse,
|
|
47
49
|
type CloudServicesDiscovery,
|
|
48
|
-
type CloudBillingDiscovery,
|
|
49
50
|
type CreateServicesTokenInput,
|
|
50
51
|
type CloudServicesAPI,
|
|
51
|
-
type CloudServicesSchema
|
|
52
|
+
type CloudServicesSchema,
|
|
53
|
+
sendsTokenSafely
|
|
52
54
|
} from './services'
|
|
55
|
+
export {
|
|
56
|
+
BILLING_ERROR_STATUS,
|
|
57
|
+
CLOUD_ACCOUNT_BILLING_PATH,
|
|
58
|
+
CLOUD_ACCOUNT_PLAN_PATH,
|
|
59
|
+
CLOUD_BILLING_API_PATHS,
|
|
60
|
+
CLOUD_BILLING_PAGE_PATHS,
|
|
61
|
+
CLOUD_BILLING_CONTRACT_VERSION,
|
|
62
|
+
CLOUD_BILLING_TOKEN_AUDIENCE,
|
|
63
|
+
billingAccountSchema,
|
|
64
|
+
billingCatalogSchema,
|
|
65
|
+
billingErrorCodeSchema,
|
|
66
|
+
billingErrorSchema,
|
|
67
|
+
billingFreePlanSchema,
|
|
68
|
+
billingPlanSchema,
|
|
69
|
+
billingSeatPricingSchema,
|
|
70
|
+
billingRedirectSchema,
|
|
71
|
+
billingTokenClaimsSchema,
|
|
72
|
+
billingTokenSchema,
|
|
73
|
+
checkoutRequestSchema,
|
|
74
|
+
cloudBillingDiscoverySchema,
|
|
75
|
+
creditPackSchema,
|
|
76
|
+
type BillingAccount,
|
|
77
|
+
type BillingCatalog,
|
|
78
|
+
type BillingError,
|
|
79
|
+
type BillingErrorCode,
|
|
80
|
+
type BillingFreePlan,
|
|
81
|
+
type BillingPlan,
|
|
82
|
+
type BillingSeatPricing,
|
|
83
|
+
type BillingRedirect,
|
|
84
|
+
type BillingToken,
|
|
85
|
+
type BillingTokenClaims,
|
|
86
|
+
type CheckoutRequest,
|
|
87
|
+
type CloudBillingAPI,
|
|
88
|
+
type CloudBillingDiscovery,
|
|
89
|
+
type CloudBillingSchema,
|
|
90
|
+
type CreditPack
|
|
91
|
+
} from './billing'
|
|
53
92
|
export * from './admin'
|
|
54
93
|
export {
|
|
55
94
|
cloudPresenceSchema,
|
|
@@ -60,22 +99,34 @@ export {
|
|
|
60
99
|
type CollaborationTicket
|
|
61
100
|
} from './collaboration'
|
|
62
101
|
export * from './relay'
|
|
63
|
-
export {
|
|
102
|
+
export {
|
|
103
|
+
accountEntitlementsResponseSchema,
|
|
104
|
+
accountEntitlementsSchema,
|
|
105
|
+
workspaceEntitlementsSchema,
|
|
106
|
+
type AccountEntitlements,
|
|
107
|
+
type WorkspaceEntitlements
|
|
108
|
+
} from './entitlements'
|
|
64
109
|
export {
|
|
65
110
|
CLOUD_DISCOVERY_PATH,
|
|
111
|
+
CLOUD_EDITOR_VERSION_HEADER,
|
|
66
112
|
CLOUD_PROTOCOL_VERSION,
|
|
67
113
|
cloudAuthenticationSchema,
|
|
114
|
+
cloudBrandingSchema,
|
|
68
115
|
cloudCapabilitiesSchema,
|
|
69
116
|
cloudDeploymentSchema,
|
|
117
|
+
cloudCommunityDiscoverySchema,
|
|
70
118
|
cloudDiscoverySchema,
|
|
71
119
|
cloudEditorVersionSchema,
|
|
72
120
|
cloudLegalDiscoverySchema,
|
|
73
121
|
cloudListingSchema,
|
|
74
122
|
cloudServerOrigin,
|
|
123
|
+
isEditorVersionAtLeast,
|
|
75
124
|
parseCloudDiscovery,
|
|
76
125
|
type CloudAuthentication,
|
|
126
|
+
type CloudBranding,
|
|
77
127
|
type CloudCapabilities,
|
|
78
128
|
type CloudDeployment,
|
|
129
|
+
type CloudCommunityDiscovery,
|
|
79
130
|
type CloudDiscovery,
|
|
80
131
|
type CloudLegalDiscovery,
|
|
81
132
|
type CloudListing
|
|
@@ -208,17 +259,25 @@ export {
|
|
|
208
259
|
type WorkspaceSummary
|
|
209
260
|
} from './workspaces'
|
|
210
261
|
export {
|
|
262
|
+
CLOUD_COMMUNITY_PATH,
|
|
263
|
+
cloudCommunityDesktopLinkURL,
|
|
264
|
+
cloudCommunityPagePath,
|
|
211
265
|
cloudDesktopLinkURL,
|
|
212
266
|
cloudDocumentPath,
|
|
267
|
+
cloudCommentURL,
|
|
213
268
|
cloudDocumentURL,
|
|
214
269
|
cloudInvitationURL,
|
|
215
270
|
cloudShareURL,
|
|
216
271
|
parseCloudLinkPath,
|
|
272
|
+
cloudCommunityPath,
|
|
273
|
+
cloudCommunityURL,
|
|
217
274
|
type CloudLinkKind,
|
|
218
275
|
type CloudLinkPathKind
|
|
219
276
|
} from './links'
|
|
220
|
-
export { CLOUD_PORTAL_PAGE_ROOTS, isCloudPortalPage } from './portal'
|
|
277
|
+
export { CLOUD_PORTAL_COMMUNITY_PAGES, CLOUD_PORTAL_PAGE_ROOTS, isCloudPortalPage } from './portal'
|
|
221
278
|
export * from './versions'
|
|
279
|
+
export * from './comments'
|
|
280
|
+
export * from './community'
|
|
222
281
|
export {
|
|
223
282
|
DOCUMENT_REPORT_DESCRIPTION_MAX,
|
|
224
283
|
documentReportReasonSchema,
|
package/src/contract/links.ts
CHANGED
|
@@ -3,10 +3,18 @@ import { encodeParam, parseURL, withFragment, withQuery } from 'ufo'
|
|
|
3
3
|
/** The two kinds of Cloud link that carry a secret: invitations and documents shared by link. */
|
|
4
4
|
export type CloudLinkKind = 'invitations' | 'share'
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Every kind of Cloud link: those that carry a secret, a document's address for members, and a
|
|
8
|
+
* document of the server's community gallery, which anyone may open.
|
|
9
|
+
*/
|
|
10
|
+
export type CloudLinkPathKind = CloudLinkKind | 'documents' | 'community'
|
|
8
11
|
|
|
9
12
|
const CLOUD_LINK_PATH = /^\/(invitations|share|documents)\/([^/]+)$/
|
|
13
|
+
/** A community document opened in the editor; `/community/:id` alone is its page. */
|
|
14
|
+
const COMMUNITY_EDITOR_PATH = /^\/community\/([^/]+)\/open$/
|
|
15
|
+
|
|
16
|
+
/** The server's community gallery: every document in it, each with a page of its own. */
|
|
17
|
+
export const CLOUD_COMMUNITY_PATH = '/community'
|
|
10
18
|
|
|
11
19
|
/**
|
|
12
20
|
* A link on the server's own editor. The server is the link's own address, so the link needs
|
|
@@ -55,6 +63,29 @@ export function cloudDocumentPath(documentId: string): string {
|
|
|
55
63
|
return `/documents/${encodeParam(documentId)}`
|
|
56
64
|
}
|
|
57
65
|
|
|
66
|
+
/**
|
|
67
|
+
* A document of the server's community gallery opened in the editor, `/community/:id/open`, or
|
|
68
|
+
* one of its named versions with `?version=…`, which anyone opens read-only without signing in.
|
|
69
|
+
*/
|
|
70
|
+
export function cloudCommunityURL(
|
|
71
|
+
serverURL: string,
|
|
72
|
+
documentId: string,
|
|
73
|
+
versionId: string | null = null
|
|
74
|
+
): string {
|
|
75
|
+
return serverLink(serverURL, cloudCommunityPath(documentId), {
|
|
76
|
+
version: versionId ?? undefined
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function cloudCommunityPath(documentId: string): string {
|
|
81
|
+
return `${cloudCommunityPagePath(documentId)}/open`
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** A community document's page on the server: its preview, versions, and ways to open it. */
|
|
85
|
+
export function cloudCommunityPagePath(documentId: string): string {
|
|
86
|
+
return `${CLOUD_COMMUNITY_PATH}/${encodeParam(documentId)}`
|
|
87
|
+
}
|
|
88
|
+
|
|
58
89
|
/**
|
|
59
90
|
* The kind and ID of a Cloud link's path, or null for any other path. The ID is decoded; a broken
|
|
60
91
|
* escape such as `%E0` is no link.
|
|
@@ -62,8 +93,16 @@ export function cloudDocumentPath(documentId: string): string {
|
|
|
62
93
|
export function parseCloudLinkPath(
|
|
63
94
|
pathname: string
|
|
64
95
|
): { kind: CloudLinkPathKind; id: string } | null {
|
|
65
|
-
const
|
|
66
|
-
|
|
96
|
+
const community = pathname.match(COMMUNITY_EDITOR_PATH)
|
|
97
|
+
const [, kind, id] = community
|
|
98
|
+
? [pathname, 'community' as const, community[1]]
|
|
99
|
+
: (pathname.match(CLOUD_LINK_PATH) ?? [])
|
|
100
|
+
if (
|
|
101
|
+
(kind !== 'invitations' && kind !== 'share' && kind !== 'documents' && kind !== 'community') ||
|
|
102
|
+
!id
|
|
103
|
+
) {
|
|
104
|
+
return null
|
|
105
|
+
}
|
|
67
106
|
try {
|
|
68
107
|
return { kind, id: decodeURIComponent(id) }
|
|
69
108
|
} catch {
|
|
@@ -85,3 +124,22 @@ export function cloudDesktopLinkURL(
|
|
|
85
124
|
const link = serverLink(serverURL, `/${kind}/${encodeParam(id)}`)
|
|
86
125
|
return withFragment(withQuery('openpencil://cloud', { url: link }), secret)
|
|
87
126
|
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The desktop app's form of a community document's link, `openpencil://cloud?url=<link>`: the
|
|
130
|
+
* editor's address for it, with the named version it asks for, if any. It carries no secret.
|
|
131
|
+
*/
|
|
132
|
+
export function cloudCommunityDesktopLinkURL(
|
|
133
|
+
documentId: string,
|
|
134
|
+
serverURL: string,
|
|
135
|
+
versionId: string | null = null
|
|
136
|
+
): string {
|
|
137
|
+
return withQuery('openpencil://cloud', {
|
|
138
|
+
url: cloudCommunityURL(serverURL, documentId, versionId)
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** A comment thread on a document, `/documents/:id?comment=…`, which opens it. */
|
|
143
|
+
export function cloudCommentURL(serverURL: string, documentId: string, threadId: string): string {
|
|
144
|
+
return serverLink(serverURL, cloudDocumentPath(documentId), { comment: threadId })
|
|
145
|
+
}
|