@open-pencil/cloud 0.17.0-beta.5 → 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/dist/client.d.ts +560 -93
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1101 -186
- package/dist/client.js.map +1 -1
- package/dist/contract.d.ts +2 -2
- package/dist/contract.js +2 -2
- package/dist/contract2.js +390 -44
- package/dist/contract2.js.map +1 -1
- package/dist/email.d.ts +366 -3
- package/dist/email.d.ts.map +1 -1
- package/dist/email.js +1403 -556
- package/dist/email.js.map +1 -1
- package/dist/errors.js +16 -3
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +878 -37
- package/dist/index.d.ts.map +1 -1
- package/dist/index2.d.ts +12 -2
- package/dist/index2.d.ts.map +1 -1
- package/dist/listen.mjs +589 -128
- package/dist/listen.mjs.map +1 -1
- package/dist/runtime-cloudflare.d.ts +4 -0
- package/dist/runtime-cloudflare.d.ts.map +1 -1
- package/dist/runtime-cloudflare.js +8689 -6324
- package/dist/runtime-cloudflare.js.map +1 -1
- package/dist/runtime-node.d.mts +10098 -5401
- package/dist/runtime-node.d.mts.map +1 -1
- package/dist/server.d.ts +14078 -7909
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +11723 -9412
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +10658 -8649
- package/dist/server.mjs.map +1 -1
- package/dist/server2.mjs +79 -57
- package/dist/server2.mjs.map +1 -1
- package/package.json +13 -4
- package/src/admin/api/routes.ts +263 -190
- package/src/admin/audit/service.ts +9 -1
- package/src/admin/bootstrap.ts +86 -0
- package/src/admin/documents/service.ts +119 -4
- 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 +9 -3
- package/src/admin/schema.ts +6 -5
- package/src/admin/users/service.ts +173 -16
- package/src/client/api.ts +29 -2
- package/src/client/comments.ts +205 -0
- package/src/client/device-authorization.ts +4 -20
- package/src/client/discovery.ts +4 -2
- 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 +3 -6
- package/src/client/portal/account.ts +20 -2
- package/src/client/portal/administration.ts +52 -5
- package/src/client/portal/request.ts +4 -2
- package/src/client/tour.ts +44 -0
- package/src/client/versions.ts +7 -1
- package/src/contract/account.ts +61 -11
- package/src/contract/admin/index.ts +48 -3
- package/src/contract/billing.ts +73 -4
- package/src/contract/comments.ts +223 -0
- package/src/contract/discovery.ts +47 -19
- package/src/contract/index.ts +10 -0
- package/src/contract/links.ts +5 -0
- package/src/contract/relay.ts +3 -1
- package/src/contract/services.ts +44 -4
- package/src/contract/workspaces.ts +5 -0
- package/src/email/locales/ar.json +28 -0
- package/src/email/locales/de.json +28 -0
- package/src/email/locales/es.json +28 -0
- package/src/email/locales/fr.json +28 -0
- package/src/email/locales/it.json +28 -0
- package/src/email/locales/ja.json +28 -0
- package/src/email/locales/pl.json +28 -0
- package/src/email/locales/pt-br.json +28 -0
- package/src/email/locales/ru.json +28 -0
- package/src/email/locales/zh-cn.json +28 -0
- package/src/email/messages.ts +35 -0
- package/src/email/render.ts +18 -0
- package/src/email/samples.ts +28 -1
- package/src/email/schema.ts +29 -3
- package/src/email/templates/BrandEmail.vue +3 -1
- package/src/email/templates/CommentNotification.vue +39 -0
- package/src/email/templates/EnrollmentInvitation.vue +53 -0
- package/src/email/templates/TwoStepChanged.vue +17 -2
- package/src/email/templates/brand.ts +6 -0
- package/src/errors/posthog.ts +28 -4
- package/src/runtime/cloudflare/email.ts +2 -0
- package/src/runtime/cloudflare/relay/index.ts +21 -6
- package/src/runtime/cloudflare/worker.ts +6 -0
- package/src/runtime/cloudflare/xml.ts +12 -0
- package/src/runtime/node/admin.ts +51 -47
- package/src/runtime/node/email/runtime.ts +1 -0
- package/src/runtime/node/email/transport.ts +1 -0
- package/src/runtime/node/server.ts +8 -2
- package/src/runtime/posthog/errors.ts +3 -1
- package/src/server/account/actions.ts +3 -1
- package/src/server/account/deletion.ts +38 -4
- package/src/server/account/routes.ts +67 -46
- package/src/server/account/tokens.ts +3 -3
- package/src/server/api/router.ts +22 -7
- package/src/server/app/checks.ts +6 -1
- package/src/server/app/cors.ts +44 -0
- package/src/server/app/index.ts +76 -76
- package/src/server/app/routes.ts +14 -5
- package/src/server/app/services.ts +49 -15
- package/src/server/auth/access-control.ts +13 -8
- package/src/server/auth/account.ts +13 -12
- package/src/server/auth/activity.ts +7 -2
- package/src/server/auth/adapter.ts +16 -3
- package/src/server/auth/email.ts +29 -17
- package/src/server/auth/endpoints.ts +4 -0
- package/src/server/auth/factory.ts +83 -64
- package/src/server/auth/index.ts +1 -1
- package/src/server/auth/methods.ts +162 -0
- package/src/server/auth/mfa-assurance.ts +147 -10
- package/src/server/auth/rate-limit.ts +31 -0
- package/src/server/auth/runtime.ts +19 -5
- package/src/server/auth/social-providers.ts +70 -24
- package/src/server/billing/index.ts +2 -0
- package/src/server/billing/notify.ts +55 -0
- package/src/server/billing/seats.ts +17 -0
- package/src/server/billing/tokens.ts +1 -1
- 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/collaboration/relay/connection.ts +7 -2
- package/src/server/collaboration/relay/hub.ts +55 -24
- package/src/server/collaboration/routes.ts +8 -5
- 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/routes.ts +6 -6
- package/src/server/config/deployment.ts +19 -6
- package/src/server/config/index.ts +1 -1
- package/src/server/config/public.ts +19 -6
- package/src/server/config/schema.ts +14 -2
- package/src/server/config/toml/schema.ts +27 -4
- package/src/server/db/index.ts +2 -1
- package/src/server/db/migrate.ts +21 -1
- 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/tables.ts +92 -2
- package/src/server/documents/access.ts +17 -0
- package/src/server/documents/images.ts +6 -1
- package/src/server/documents/routes.ts +12 -12
- package/src/server/documents/service.ts +19 -5
- package/src/server/documents/summary.ts +15 -0
- package/src/server/documents/versions/routes.ts +7 -8
- package/src/server/documents/versions/service.ts +5 -2
- package/src/server/email/service.ts +8 -2
- package/src/server/email/types.ts +1 -0
- package/src/server/errors/index.ts +48 -3
- package/src/server/index.ts +15 -1
- 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/pictures/service.ts +3 -1
- package/src/server/policy/workspace.ts +5 -2
- package/src/server/reports/routes.ts +2 -2
- package/src/server/reports/service.ts +3 -1
- package/src/server/services/routes.ts +2 -2
- package/src/server/sharing/capabilities/service.ts +1 -1
- package/src/server/sharing/document-routes.ts +3 -3
- package/src/server/sharing/invitations/service.ts +3 -4
- package/src/server/sharing/routes.ts +15 -15
- package/src/server/validation.ts +33 -25
- package/src/server/workspaces/members.ts +50 -12
- package/src/server/workspaces/repository.ts +23 -12
- package/src/server/workspaces/routes.ts +8 -8
- package/src/services/app.ts +30 -19
- package/src/services/config.ts +47 -8
- package/src/services/metering.ts +15 -27
- package/src/client/billing.ts +0 -80
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
cloudAdminSessionResponseSchema,
|
|
9
9
|
cloudAdminUserDetailSchema,
|
|
10
10
|
cloudAdminUsersResponseSchema,
|
|
11
|
+
documentDownloadSchema,
|
|
12
|
+
enrollmentInviteResponseSchema,
|
|
11
13
|
enrollmentReviewResponseSchema,
|
|
12
14
|
enrollmentsResponseSchema,
|
|
13
15
|
type CloudAdminAuditFilter,
|
|
@@ -15,6 +17,7 @@ import {
|
|
|
15
17
|
type CloudAdminReportFilter,
|
|
16
18
|
type CloudAdminEmailFilter,
|
|
17
19
|
type CloudAdminUserFilter,
|
|
20
|
+
type CloudAdminUserMethod,
|
|
18
21
|
type EnrollmentStatus
|
|
19
22
|
} from '#cloud/contract'
|
|
20
23
|
|
|
@@ -28,14 +31,19 @@ export type AdminListRequest<Filter extends string> = {
|
|
|
28
31
|
offset?: number
|
|
29
32
|
}
|
|
30
33
|
|
|
34
|
+
/** A count as a query string carries it. */
|
|
35
|
+
function countParameter(count: number | undefined): string | undefined {
|
|
36
|
+
return count === undefined ? undefined : String(count)
|
|
37
|
+
}
|
|
38
|
+
|
|
31
39
|
/** The query string for `request`; an empty search asks for everything. */
|
|
32
40
|
function listQuery<Filter extends string>(request: AdminListRequest<Filter>) {
|
|
33
41
|
return {
|
|
34
42
|
query: {
|
|
35
43
|
search: request.search || undefined,
|
|
36
44
|
filter: request.filter,
|
|
37
|
-
limit: request.limit,
|
|
38
|
-
offset: request.offset
|
|
45
|
+
limit: countParameter(request.limit),
|
|
46
|
+
offset: countParameter(request.offset)
|
|
39
47
|
}
|
|
40
48
|
}
|
|
41
49
|
}
|
|
@@ -69,9 +77,22 @@ export function createAdministrationAPI(call: CloudCall, { admin, api }: PortalR
|
|
|
69
77
|
signal
|
|
70
78
|
)
|
|
71
79
|
},
|
|
72
|
-
|
|
80
|
+
/** Approves every waiting request and sends each the invitation letter (official only). */
|
|
81
|
+
inviteEnrollments(signal?: AbortSignal) {
|
|
82
|
+
return call(
|
|
83
|
+
(options) => admin.enrollments.invite.$post(undefined, options),
|
|
84
|
+
enrollmentInviteResponseSchema,
|
|
85
|
+
signal
|
|
86
|
+
)
|
|
87
|
+
},
|
|
88
|
+
/** A page of people; `method` narrows any filter to those who sign in that way. */
|
|
89
|
+
users(
|
|
90
|
+
request: AdminListRequest<CloudAdminUserFilter> & { method?: CloudAdminUserMethod },
|
|
91
|
+
signal?: AbortSignal
|
|
92
|
+
) {
|
|
93
|
+
const { query } = listQuery(request)
|
|
73
94
|
return call(
|
|
74
|
-
(options) => admin.users.$get(
|
|
95
|
+
(options) => admin.users.$get({ query: { ...query, method: request.method } }, options),
|
|
75
96
|
cloudAdminUsersResponseSchema,
|
|
76
97
|
signal
|
|
77
98
|
)
|
|
@@ -84,7 +105,7 @@ export function createAdministrationAPI(call: CloudCall, { admin, api }: PortalR
|
|
|
84
105
|
)
|
|
85
106
|
},
|
|
86
107
|
userAction(
|
|
87
|
-
action: 'ban' | 'unban' | 'revoke-sessions' | 'reset-two-step' | 'remove-picture',
|
|
108
|
+
action: 'ban' | 'unban' | 'revoke-sessions' | 'reset-two-step' | 'remove-picture' | 'delete',
|
|
88
109
|
userId: string,
|
|
89
110
|
reason?: string,
|
|
90
111
|
signal?: AbortSignal
|
|
@@ -95,6 +116,15 @@ export function createAdministrationAPI(call: CloudCall, { admin, api }: PortalR
|
|
|
95
116
|
signal
|
|
96
117
|
)
|
|
97
118
|
},
|
|
119
|
+
/** Removes one of an account's sign-in methods; the server keeps its last. */
|
|
120
|
+
removeSignInMethod(userId: string, methodId: string, signal?: AbortSignal) {
|
|
121
|
+
return call(
|
|
122
|
+
(options) =>
|
|
123
|
+
admin.users['remove-sign-in-method'].$post({ json: { userId, methodId } }, options),
|
|
124
|
+
adminMutationResponseSchema,
|
|
125
|
+
signal
|
|
126
|
+
)
|
|
127
|
+
},
|
|
98
128
|
setAdmin(userId: string, enabled: boolean, signal?: AbortSignal) {
|
|
99
129
|
return call(
|
|
100
130
|
(options) => admin.users['set-admin'].$post({ json: { userId, enabled } }, options),
|
|
@@ -145,6 +175,23 @@ export function createAdministrationAPI(call: CloudCall, { admin, api }: PortalR
|
|
|
145
175
|
signal
|
|
146
176
|
)
|
|
147
177
|
},
|
|
178
|
+
/**
|
|
179
|
+
* Where a document's thumbnail at `revisionId` is: an image the console shows on the server's
|
|
180
|
+
* own address, so the administrator's session goes with it.
|
|
181
|
+
*/
|
|
182
|
+
documentThumbnailURL(documentId: string, revisionId: string): string {
|
|
183
|
+
return admin.documents[':documentId'].thumbnails[':revisionId']
|
|
184
|
+
.$url({ param: { documentId, revisionId } })
|
|
185
|
+
.toString()
|
|
186
|
+
},
|
|
187
|
+
/** Links to a document's file and images as it is now; the server records the download. */
|
|
188
|
+
downloadDocument(id: string, signal?: AbortSignal) {
|
|
189
|
+
return call(
|
|
190
|
+
(options) => admin.documents[':id'].download.$post({ param: { id } }, options),
|
|
191
|
+
documentDownloadSchema,
|
|
192
|
+
signal
|
|
193
|
+
)
|
|
194
|
+
},
|
|
148
195
|
/** Takes a document down, or puts it back. */
|
|
149
196
|
documentAction(
|
|
150
197
|
id: string,
|
|
@@ -12,6 +12,8 @@ import type { CloudAPI } from '#cloud/server/api'
|
|
|
12
12
|
import { hc } from 'hono/client'
|
|
13
13
|
import * as v from 'valibot'
|
|
14
14
|
|
|
15
|
+
import { anySignal, DEADLINE_MS } from '@open-pencil/std/timing'
|
|
16
|
+
|
|
15
17
|
export type CloudPortalAPIErrorKind =
|
|
16
18
|
| 'authentication-required'
|
|
17
19
|
| 'authorization-required'
|
|
@@ -57,10 +59,10 @@ export type CloudCall = <Output>(
|
|
|
57
59
|
* body is checked against the contract.
|
|
58
60
|
*/
|
|
59
61
|
export function createCloudCall(options: CloudPortalClientOptions = {}): CloudCall {
|
|
60
|
-
const timeoutMs = options.timeoutMs ??
|
|
62
|
+
const timeoutMs = options.timeoutMs ?? DEADLINE_MS.request
|
|
61
63
|
return async (send, schema, callerSignal) => {
|
|
62
64
|
const timeout = AbortSignal.timeout(timeoutMs)
|
|
63
|
-
const signal =
|
|
65
|
+
const signal = anySignal([callerSignal, timeout])
|
|
64
66
|
let response: PortalResponse
|
|
65
67
|
try {
|
|
66
68
|
response = await send({ init: { signal } })
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { anySignal, DEADLINE_MS } from '@open-pencil/std/timing'
|
|
2
|
+
|
|
3
|
+
import { createCloudAPIClient } from './api'
|
|
4
|
+
import { discoverCloud, type CloudFetch } from './discovery'
|
|
5
|
+
import { downloadCloudDocument } from './files'
|
|
6
|
+
|
|
7
|
+
/** The tour a server's gallery names, as one file, and the release it was named for. */
|
|
8
|
+
export type CommunityTour = { name: string; version: string | null; bytes: Uint8Array }
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The tour a Cloud server's community gallery names (`[community] tour`), with its images, as
|
|
12
|
+
* the named version for `version` when the gallery has one, such as the release an older editor
|
|
13
|
+
* is, else as it is now. Null when the server names no tour or its gallery no longer holds it.
|
|
14
|
+
* Requests carry no account, so any page may make them, as the documentation site's landing does.
|
|
15
|
+
*/
|
|
16
|
+
export async function fetchCommunityTour(
|
|
17
|
+
serverURL: string,
|
|
18
|
+
options: { version?: string | null; fetch?: CloudFetch; signal?: AbortSignal } = {}
|
|
19
|
+
): Promise<CommunityTour | null> {
|
|
20
|
+
const base = options.fetch ?? globalThis.fetch
|
|
21
|
+
const fetch: CloudFetch = (input, init) => base(input, { ...init, credentials: 'omit' })
|
|
22
|
+
const discovery = await discoverCloud(serverURL, { fetch, signal: options.signal })
|
|
23
|
+
const tourId = discovery.community?.tourDocumentId
|
|
24
|
+
if (!tourId) return null
|
|
25
|
+
const cloud = createCloudAPIClient(discovery.apiURL, { fetch, signal: options.signal })
|
|
26
|
+
const tour = (await cloud.listCommunityDocuments()).documents.find(
|
|
27
|
+
(document) => document.id === tourId
|
|
28
|
+
)
|
|
29
|
+
if (!tour) return null
|
|
30
|
+
const release = tour.versions.find((version) => version.name === options.version) ?? null
|
|
31
|
+
const download = await cloud.getCommunityDocument(tour.id, release?.id ?? null)
|
|
32
|
+
// Each object from the store is bounded too, its body included, as the API's requests are: a
|
|
33
|
+
// caller such as the docs landing passes no signal and keeps the answer it waits for.
|
|
34
|
+
const bytes = await downloadCloudDocument(
|
|
35
|
+
download.document,
|
|
36
|
+
(input, init) =>
|
|
37
|
+
fetch(input, {
|
|
38
|
+
...init,
|
|
39
|
+
signal: anySignal([init.signal, AbortSignal.timeout(DEADLINE_MS.transfer)])
|
|
40
|
+
}),
|
|
41
|
+
{ signal: options.signal }
|
|
42
|
+
)
|
|
43
|
+
return { name: tour.name, version: download.version?.name ?? null, bytes }
|
|
44
|
+
}
|
package/src/client/versions.ts
CHANGED
|
@@ -32,7 +32,13 @@ export function createVersionRequests(
|
|
|
32
32
|
return parseResponse(
|
|
33
33
|
client.documents[':documentId'].versions.$get({
|
|
34
34
|
param: { documentId },
|
|
35
|
-
query: pickBy(
|
|
35
|
+
query: pickBy(
|
|
36
|
+
{
|
|
37
|
+
before: page.before,
|
|
38
|
+
limit: page.limit === undefined ? undefined : String(page.limit)
|
|
39
|
+
},
|
|
40
|
+
(value) => value !== undefined
|
|
41
|
+
)
|
|
36
42
|
}),
|
|
37
43
|
documentVersionsSchema,
|
|
38
44
|
onDiagnostic
|
package/src/contract/account.ts
CHANGED
|
@@ -3,13 +3,15 @@ import * as v from 'valibot'
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Where an account stands: it may use the server, waits for an administrator, was refused or had
|
|
6
|
-
* its access taken back,
|
|
6
|
+
* its access taken back, has to prove its second step in this session, as after signing in through
|
|
7
|
+
* a linked account such as Google, or has to accept the server's current terms first.
|
|
7
8
|
*/
|
|
8
9
|
export const cloudAccountStateSchema = v.picklist([
|
|
9
10
|
'active',
|
|
10
11
|
'pending',
|
|
11
12
|
'rejected',
|
|
12
13
|
'revoked',
|
|
14
|
+
'two-step',
|
|
13
15
|
'terms'
|
|
14
16
|
])
|
|
15
17
|
export const cloudIdentitySchema = v.object({
|
|
@@ -29,23 +31,64 @@ export const cloudAccountStatusResponseSchema = v.object({
|
|
|
29
31
|
/** Accepting the server's terms: the version the person read, which must be the current one. */
|
|
30
32
|
export const cloudTermsAcceptanceSchema = v.object({ version: v.pipe(v.string(), v.minLength(1)) })
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
/**
|
|
35
|
+
* The providers a person can sign in with besides a password, which this editor has buttons for,
|
|
36
|
+
* in the order it shows them. Every list of providers in Cloud derives from this one.
|
|
37
|
+
*/
|
|
38
|
+
export const CLOUD_SOCIAL_PROVIDERS = ['google', 'apple', 'github'] as const
|
|
39
|
+
export const cloudSocialProviderSchema = v.picklist(CLOUD_SOCIAL_PROVIDERS)
|
|
40
|
+
export type CloudSocialProvider = v.InferOutput<typeof cloudSocialProviderSchema>
|
|
41
|
+
/** Each provider's name, as its owner writes it in every language. */
|
|
42
|
+
export const CLOUD_SOCIAL_PROVIDER_NAMES: Record<CloudSocialProvider, string> = {
|
|
43
|
+
google: 'Google',
|
|
44
|
+
apple: 'Apple',
|
|
45
|
+
github: 'GitHub'
|
|
46
|
+
}
|
|
47
|
+
export const cloudAuthenticationProviderSchema = v.picklist([
|
|
48
|
+
'credential',
|
|
49
|
+
...CLOUD_SOCIAL_PROVIDERS
|
|
50
|
+
])
|
|
33
51
|
export const cloudAuthenticationMethodSchema = v.object({
|
|
34
52
|
id: v.string(),
|
|
35
53
|
provider: cloudAuthenticationProviderSchema,
|
|
36
54
|
createdAt: v.string(),
|
|
37
55
|
canUnlink: v.boolean()
|
|
38
56
|
})
|
|
57
|
+
|
|
58
|
+
/** Whether this editor knows `provider`, so a newer server's other providers can be left out. */
|
|
59
|
+
export function isKnownSocialProvider(provider: string): provider is CloudSocialProvider {
|
|
60
|
+
return (CLOUD_SOCIAL_PROVIDERS as readonly string[]).includes(provider)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Whether `provider` is a way to sign in this editor knows: a password or a known provider. */
|
|
64
|
+
export function isKnownAuthenticationProvider(
|
|
65
|
+
provider: string
|
|
66
|
+
): provider is CloudAuthenticationProvider {
|
|
67
|
+
return provider === 'credential' || isKnownSocialProvider(provider)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A newer server may list a provider this editor has no words or button for: those entries are
|
|
72
|
+
* left out rather than failing the whole response, and anything else malformed still fails.
|
|
73
|
+
*/
|
|
39
74
|
export const cloudAuthenticationMethodsResponseSchema = v.object({
|
|
40
|
-
methods: v.
|
|
41
|
-
|
|
75
|
+
methods: v.pipe(
|
|
76
|
+
v.array(v.looseObject({ provider: v.string() })),
|
|
77
|
+
v.filterItems((method) => isKnownAuthenticationProvider(method.provider)),
|
|
78
|
+
v.array(cloudAuthenticationMethodSchema)
|
|
79
|
+
),
|
|
80
|
+
availableSocialProviders: v.pipe(
|
|
81
|
+
v.array(v.string()),
|
|
82
|
+
v.filterItems(isKnownSocialProvider),
|
|
83
|
+
v.array(cloudSocialProviderSchema)
|
|
84
|
+
)
|
|
42
85
|
})
|
|
43
86
|
export const cloudPasswordChangeSchema = v.object({
|
|
44
87
|
currentPassword: v.string(),
|
|
45
88
|
newPassword: v.string()
|
|
46
89
|
})
|
|
47
90
|
export const cloudSocialLinkSchema = v.object({
|
|
48
|
-
provider:
|
|
91
|
+
provider: cloudSocialProviderSchema,
|
|
49
92
|
callbackURL: v.pipe(v.string(), v.url())
|
|
50
93
|
})
|
|
51
94
|
export const cloudSocialLinkResponseSchema = v.object({ url: v.pipe(v.string(), v.url()) })
|
|
@@ -57,6 +100,7 @@ export const accountSecurityErrorCodeSchema = v.picklist([
|
|
|
57
100
|
'last_authentication_method',
|
|
58
101
|
'session_not_fresh',
|
|
59
102
|
'authentication_method_failed',
|
|
103
|
+
'code_invalid',
|
|
60
104
|
'email_unchanged',
|
|
61
105
|
'email_change_unavailable',
|
|
62
106
|
'current_session',
|
|
@@ -206,21 +250,27 @@ export const cloudEmailChangeSchema = v.object({
|
|
|
206
250
|
})
|
|
207
251
|
|
|
208
252
|
/** How a sign-in was made: the method it used, or the desktop app's approved code. */
|
|
209
|
-
|
|
253
|
+
const SIGN_IN_METHODS = [
|
|
210
254
|
'password',
|
|
211
|
-
|
|
212
|
-
'apple',
|
|
255
|
+
...CLOUD_SOCIAL_PROVIDERS,
|
|
213
256
|
'passkey',
|
|
214
257
|
'two-step',
|
|
215
258
|
'email-link',
|
|
216
259
|
'desktop',
|
|
217
260
|
'other'
|
|
218
|
-
]
|
|
261
|
+
] as const
|
|
262
|
+
export const cloudSignInMethodSchema = v.picklist(SIGN_IN_METHODS)
|
|
263
|
+
/** A method a newer server names that this editor does not know reads as `other`; a value that is
|
|
264
|
+
* not a method name at all still fails. */
|
|
265
|
+
const signInMethodResponseSchema = v.pipe(
|
|
266
|
+
v.string(),
|
|
267
|
+
v.transform((method) => (v.is(cloudSignInMethodSchema, method) ? method : ('other' as const)))
|
|
268
|
+
)
|
|
219
269
|
export const cloudAccountSessionSchema = v.object({
|
|
220
270
|
id: v.string(),
|
|
221
271
|
/** The session this request was made with. */
|
|
222
272
|
current: v.boolean(),
|
|
223
|
-
method: v.nullable(
|
|
273
|
+
method: v.nullable(signInMethodResponseSchema),
|
|
224
274
|
ipAddress: v.nullable(v.string()),
|
|
225
275
|
/** The browser and system the server read from the client's user agent, such as `Chrome 141`. */
|
|
226
276
|
browser: v.nullable(v.string()),
|
|
@@ -235,7 +285,7 @@ export const cloudAccountSessionsResponseSchema = v.object({
|
|
|
235
285
|
export const cloudSessionRevokeSchema = v.object({ sessionId: v.pipe(v.string(), v.minLength(1)) })
|
|
236
286
|
export const cloudSignInSchema = v.object({
|
|
237
287
|
id: v.string(),
|
|
238
|
-
method:
|
|
288
|
+
method: signInMethodResponseSchema,
|
|
239
289
|
ipAddress: v.nullable(v.string()),
|
|
240
290
|
/** The browser and system the server read from the client's user agent, such as `Chrome 141`. */
|
|
241
291
|
browser: v.nullable(v.string()),
|
|
@@ -2,11 +2,13 @@ import { zipObject } from 'es-toolkit'
|
|
|
2
2
|
import * as v from 'valibot'
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
+
CLOUD_SOCIAL_PROVIDERS,
|
|
5
6
|
cloudIdentitySchema,
|
|
6
7
|
cloudAccountSessionSchema,
|
|
7
8
|
cloudPersonSchema,
|
|
8
9
|
cloudSignInSchema
|
|
9
10
|
} from '../account'
|
|
11
|
+
import { documentKindSchema } from '../documents'
|
|
10
12
|
import { documentReportReasonSchema } from '../reports'
|
|
11
13
|
import { workspaceRoleSchema } from '../workspaces'
|
|
12
14
|
|
|
@@ -39,8 +41,14 @@ export const adminErrorCodeSchema = v.picklist([
|
|
|
39
41
|
'invalid_enrollment_transition',
|
|
40
42
|
'last_admin_required',
|
|
41
43
|
'self_admin_action_forbidden',
|
|
44
|
+
// The sign-in method is the account's last, so removing it would lock its owner out.
|
|
45
|
+
'last_authentication_method',
|
|
46
|
+
// Only an account whose request was never approved can be deleted from the console.
|
|
47
|
+
'account_approved',
|
|
42
48
|
'email_regeneration_unavailable',
|
|
43
49
|
'mfa_required',
|
|
50
|
+
// Two-step is on, but this session has not proved it lately; confirming it lets it back in.
|
|
51
|
+
'two_step_unconfirmed',
|
|
44
52
|
'document_not_restorable',
|
|
45
53
|
'workspace_gone'
|
|
46
54
|
])
|
|
@@ -71,6 +79,10 @@ export const enrollmentsResponseSchema = v.object({
|
|
|
71
79
|
...listTotals(enrollmentStatusSchema.options)
|
|
72
80
|
})
|
|
73
81
|
export const enrollmentReviewResponseSchema = v.object({ enrollment: enrollmentSchema })
|
|
82
|
+
/** How many waiting requests were approved with the official deployment's invitation letter. */
|
|
83
|
+
export const enrollmentInviteResponseSchema = v.object({
|
|
84
|
+
invited: v.pipe(v.number(), v.integer(), v.minValue(0))
|
|
85
|
+
})
|
|
74
86
|
|
|
75
87
|
export const cloudAdminSessionResponseSchema = v.object({ user: cloudIdentitySchema })
|
|
76
88
|
|
|
@@ -84,7 +96,14 @@ export const cloudAdminUserSchema = v.object({
|
|
|
84
96
|
twoStep: v.boolean(),
|
|
85
97
|
/** When one of the account's sessions was last used, or null when none is left. */
|
|
86
98
|
lastActiveAt: nullableTimestampSchema,
|
|
87
|
-
workspaceCount: countSchema
|
|
99
|
+
workspaceCount: countSchema,
|
|
100
|
+
/** How the account signs in: `credential` for a password, or a provider such as `google`. */
|
|
101
|
+
methods: v.array(v.string()),
|
|
102
|
+
/**
|
|
103
|
+
* On a server that approves people, where this account's request to join stands: an account
|
|
104
|
+
* exists from its first sign-in, before anyone approved it. Absent where everyone may join.
|
|
105
|
+
*/
|
|
106
|
+
request: v.optional(v.nullable(enrollmentStatusSchema))
|
|
88
107
|
})
|
|
89
108
|
|
|
90
109
|
/** Which accounts a list of people shows. */
|
|
@@ -94,6 +113,8 @@ export const cloudAdminUserFilterSchema = v.picklist([
|
|
|
94
113
|
'suspended',
|
|
95
114
|
'without-two-step'
|
|
96
115
|
])
|
|
116
|
+
/** Narrows a list of people, under any filter, to those who sign in a given way. */
|
|
117
|
+
export const cloudAdminUserMethodSchema = v.picklist(['password', ...CLOUD_SOCIAL_PROVIDERS])
|
|
97
118
|
export const cloudAdminUsersResponseSchema = v.object({
|
|
98
119
|
users: v.array(cloudAdminUserSchema),
|
|
99
120
|
...listTotals(cloudAdminUserFilterSchema.options)
|
|
@@ -104,7 +125,15 @@ export const cloudAdminUserDetailSchema = v.object({
|
|
|
104
125
|
...cloudAdminUserSchema.entries,
|
|
105
126
|
emailVerified: v.boolean()
|
|
106
127
|
}),
|
|
107
|
-
|
|
128
|
+
/** `canRemove`: the account keeps a way in that still works without it. */
|
|
129
|
+
methods: v.array(
|
|
130
|
+
v.object({
|
|
131
|
+
id: v.string(),
|
|
132
|
+
provider: v.string(),
|
|
133
|
+
createdAt: timestampSchema,
|
|
134
|
+
canRemove: v.boolean()
|
|
135
|
+
})
|
|
136
|
+
),
|
|
108
137
|
authenticator: v.boolean(),
|
|
109
138
|
passkeyCount: countSchema,
|
|
110
139
|
sessions: v.array(cloudAccountSessionSchema),
|
|
@@ -172,6 +201,8 @@ export const adminAuditResponseSchema = v.object({
|
|
|
172
201
|
export const cloudAdminDocumentSchema = v.object({
|
|
173
202
|
id: v.string(),
|
|
174
203
|
name: v.string(),
|
|
204
|
+
/** A design or a board. Servers from before send none, and had only designs. */
|
|
205
|
+
kind: v.optional(documentKindSchema, 'design'),
|
|
175
206
|
workspace: v.object({ id: v.string(), name: v.string() }),
|
|
176
207
|
/** Who made it, while the server knows them. */
|
|
177
208
|
owner: v.nullable(v.object({ id: v.string(), name: v.string(), email: v.string() })),
|
|
@@ -186,7 +217,20 @@ export const cloudAdminDocumentSchema = v.object({
|
|
|
186
217
|
* can still restore it. Servers from before Trash send neither.
|
|
187
218
|
*/
|
|
188
219
|
purgedAt: v.optional(nullableTimestampSchema, null),
|
|
189
|
-
destroyedAt: v.optional(nullableTimestampSchema, null)
|
|
220
|
+
destroyedAt: v.optional(nullableTimestampSchema, null),
|
|
221
|
+
/**
|
|
222
|
+
* The saved revision whose thumbnail previews it; null before its first save. Servers from
|
|
223
|
+
* before previews send none.
|
|
224
|
+
*/
|
|
225
|
+
revisionId: v.optional(v.nullable(v.string()), null),
|
|
226
|
+
/**
|
|
227
|
+
* Who beyond its workspace can open it: anyone, in the community gallery, and whoever holds one
|
|
228
|
+
* of its live share links, `editLinks` of which let them edit. Servers from before send none.
|
|
229
|
+
*/
|
|
230
|
+
exposure: v.optional(
|
|
231
|
+
v.object({ community: v.boolean(), links: countSchema, editLinks: countSchema }),
|
|
232
|
+
{ community: false, links: 0, editLinks: 0 }
|
|
233
|
+
)
|
|
190
234
|
})
|
|
191
235
|
/** Which documents a list shows: live ones, or those deleted forever an administrator can restore. */
|
|
192
236
|
export const cloudAdminDocumentFilterSchema = v.picklist(['all', 'reported', 'disabled', 'purged'])
|
|
@@ -236,6 +280,7 @@ export type Enrollment = v.InferOutput<typeof enrollmentSchema>
|
|
|
236
280
|
export type CloudAdminSessionResponse = v.InferOutput<typeof cloudAdminSessionResponseSchema>
|
|
237
281
|
export type CloudAdminUser = v.InferOutput<typeof cloudAdminUserSchema>
|
|
238
282
|
export type CloudAdminUserFilter = v.InferOutput<typeof cloudAdminUserFilterSchema>
|
|
283
|
+
export type CloudAdminUserMethod = v.InferOutput<typeof cloudAdminUserMethodSchema>
|
|
239
284
|
export type CloudAdminEmailFilter = v.InferOutput<typeof cloudAdminEmailFilterSchema>
|
|
240
285
|
export type CloudAdminAuditFilter = v.InferOutput<typeof cloudAdminAuditFilterSchema>
|
|
241
286
|
export type EnrollmentStatus = v.InferOutput<typeof enrollmentStatusSchema>
|
package/src/contract/billing.ts
CHANGED
|
@@ -23,10 +23,32 @@ export const CLOUD_BILLING_TOKEN_AUDIENCE = 'openpencil-billing' as const
|
|
|
23
23
|
*/
|
|
24
24
|
export const CLOUD_ACCOUNT_PLAN_PATH = '/account/plan' as const
|
|
25
25
|
|
|
26
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* The plan page with billing's own pages opening at once: where billing sends someone whose
|
|
28
|
+
* session there ended, so Cloud signs them in to billing again.
|
|
29
|
+
*/
|
|
30
|
+
export const CLOUD_ACCOUNT_BILLING_PATH = `${CLOUD_ACCOUNT_PLAN_PATH}?open=billing` as const
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The billing service's own pages, below the discovered `endpoint`: where Cloud's plan page sends
|
|
34
|
+
* the signed-in person, posting a billing token as the form field `token` to `session`, and the
|
|
35
|
+
* public pricing page. The service answers that post with `303 See Other`, never `307` or `308`,
|
|
36
|
+
* which a browser follows by posting the same body, the token, again to wherever they point.
|
|
37
|
+
*/
|
|
38
|
+
export const CLOUD_BILLING_PAGE_PATHS = {
|
|
39
|
+
session: '/session',
|
|
40
|
+
pricing: '/pricing'
|
|
41
|
+
} as const
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Where the billing service answers, below the discovered `endpoint`. Cloud posts to `seats`,
|
|
45
|
+
* with a billing token for the account as its bearer, whenever the people who can edit in that
|
|
46
|
+
* account's workspaces change; the service reads the count from Cloud's internal API.
|
|
47
|
+
*/
|
|
27
48
|
export const CLOUD_BILLING_API_PATHS = {
|
|
28
49
|
base: '/v1',
|
|
29
50
|
catalog: '/v1/catalog',
|
|
51
|
+
seats: '/v1/seats',
|
|
30
52
|
account: '/v1/account',
|
|
31
53
|
checkout: '/v1/checkout',
|
|
32
54
|
portal: '/v1/portal'
|
|
@@ -38,9 +60,24 @@ const centsSchema = v.pipe(v.number(), v.integer(), v.minValue(0))
|
|
|
38
60
|
const bytesSchema = v.pipe(v.number(), v.integer(), v.minValue(0))
|
|
39
61
|
const creditsSchema = v.pipe(v.number(), v.integer(), v.minValue(0))
|
|
40
62
|
|
|
63
|
+
/**
|
|
64
|
+
* What an account without a plan has: the deployment's free plan, which a pricing page compares
|
|
65
|
+
* the plans with.
|
|
66
|
+
*/
|
|
67
|
+
export const billingFreePlanSchema = v.object({
|
|
68
|
+
/** The storage an account may use, or `null` for no limit. */
|
|
69
|
+
storageBytes: v.nullable(bytesSchema),
|
|
70
|
+
/** Whether the free plan includes services, such as AI and search. */
|
|
71
|
+
services: v.boolean(),
|
|
72
|
+
/** Credits granted each month with services, or `null` for no monthly limit. */
|
|
73
|
+
monthlyCredits: v.nullable(creditsSchema)
|
|
74
|
+
})
|
|
75
|
+
export type BillingFreePlan = v.InferOutput<typeof billingFreePlanSchema>
|
|
76
|
+
|
|
41
77
|
export const cloudBillingDiscoverySchema = v.object({
|
|
42
78
|
endpoint: urlSchema,
|
|
43
|
-
contractVersion: v.literal(CLOUD_BILLING_CONTRACT_VERSION)
|
|
79
|
+
contractVersion: v.literal(CLOUD_BILLING_CONTRACT_VERSION),
|
|
80
|
+
freePlan: v.optional(billingFreePlanSchema)
|
|
44
81
|
})
|
|
45
82
|
export type CloudBillingDiscovery = v.InferOutput<typeof cloudBillingDiscoverySchema>
|
|
46
83
|
|
|
@@ -66,13 +103,45 @@ export const billingTokenClaimsSchema = v.object({
|
|
|
66
103
|
})
|
|
67
104
|
export type BillingTokenClaims = v.InferOutput<typeof billingTokenClaimsSchema>
|
|
68
105
|
|
|
69
|
-
|
|
106
|
+
const seatCountSchema = v.pipe(v.number(), v.integer(), v.minValue(1))
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* A plan priced by the seat: everyone who can edit in the account's workspaces takes one, and the
|
|
110
|
+
* account pays for at least `minimum`. Every seat costs the price of the tier its count reaches,
|
|
111
|
+
* and adds its storage and credits to what the account shares.
|
|
112
|
+
*/
|
|
113
|
+
export const billingSeatPricingSchema = v.object({
|
|
114
|
+
minimum: seatCountSchema,
|
|
115
|
+
/** From the fewest seats up: the first from 1, each later one from more seats. */
|
|
116
|
+
tiers: v.pipe(
|
|
117
|
+
v.array(v.object({ fromSeats: seatCountSchema, unitPriceCents: centsSchema })),
|
|
118
|
+
v.minLength(1),
|
|
119
|
+
v.check((tiers) => tiers[0]?.fromSeats === 1, 'The first seat tier starts at one seat'),
|
|
120
|
+
v.check(
|
|
121
|
+
(tiers) =>
|
|
122
|
+
tiers.every(
|
|
123
|
+
(tier, index) => index === 0 || tier.fromSeats > (tiers[index - 1]?.fromSeats ?? 0)
|
|
124
|
+
),
|
|
125
|
+
'Seat tiers start at more seats each'
|
|
126
|
+
)
|
|
127
|
+
),
|
|
128
|
+
storageBytesPerSeat: bytesSchema,
|
|
129
|
+
monthlyCreditsPerSeat: creditsSchema
|
|
130
|
+
})
|
|
131
|
+
export type BillingSeatPricing = v.InferOutput<typeof billingSeatPricingSchema>
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A plan an account subscribes to, billed every month in US dollars before tax. A plan priced by
|
|
135
|
+
* the seat states its price, storage, and credits at its minimum, so an editor that reads no
|
|
136
|
+
* `seats` still shows what it starts at.
|
|
137
|
+
*/
|
|
70
138
|
export const billingPlanSchema = v.object({
|
|
71
139
|
id: idSchema,
|
|
72
140
|
name: v.pipe(v.string(), v.minLength(1)),
|
|
73
141
|
monthlyPriceCents: centsSchema,
|
|
74
142
|
storageBytes: bytesSchema,
|
|
75
|
-
monthlyCredits: creditsSchema
|
|
143
|
+
monthlyCredits: creditsSchema,
|
|
144
|
+
seats: v.optional(billingSeatPricingSchema)
|
|
76
145
|
})
|
|
77
146
|
export type BillingPlan = v.InferOutput<typeof billingPlanSchema>
|
|
78
147
|
|