@open-pencil/cloud 0.17.0-beta.5 → 0.17.0-beta.7

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.
Files changed (188) hide show
  1. package/dist/client.d.ts +560 -93
  2. package/dist/client.d.ts.map +1 -1
  3. package/dist/client.js +1101 -186
  4. package/dist/client.js.map +1 -1
  5. package/dist/contract.d.ts +2 -2
  6. package/dist/contract.js +2 -2
  7. package/dist/contract2.js +390 -44
  8. package/dist/contract2.js.map +1 -1
  9. package/dist/email.d.ts +366 -3
  10. package/dist/email.d.ts.map +1 -1
  11. package/dist/email.js +1403 -556
  12. package/dist/email.js.map +1 -1
  13. package/dist/errors.js +16 -3
  14. package/dist/errors.js.map +1 -1
  15. package/dist/index.d.ts +878 -37
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index2.d.ts +12 -2
  18. package/dist/index2.d.ts.map +1 -1
  19. package/dist/listen.mjs +589 -128
  20. package/dist/listen.mjs.map +1 -1
  21. package/dist/runtime-cloudflare.d.ts +4 -0
  22. package/dist/runtime-cloudflare.d.ts.map +1 -1
  23. package/dist/runtime-cloudflare.js +8690 -6325
  24. package/dist/runtime-cloudflare.js.map +1 -1
  25. package/dist/runtime-node.d.mts +10098 -5401
  26. package/dist/runtime-node.d.mts.map +1 -1
  27. package/dist/server.d.ts +13807 -7638
  28. package/dist/server.d.ts.map +1 -1
  29. package/dist/server.js +11723 -9412
  30. package/dist/server.js.map +1 -1
  31. package/dist/server.mjs +10659 -8650
  32. package/dist/server.mjs.map +1 -1
  33. package/dist/server2.mjs +79 -57
  34. package/dist/server2.mjs.map +1 -1
  35. package/package.json +13 -4
  36. package/src/admin/api/routes.ts +263 -190
  37. package/src/admin/audit/service.ts +9 -1
  38. package/src/admin/bootstrap.ts +86 -0
  39. package/src/admin/documents/service.ts +119 -4
  40. package/src/admin/email/service.ts +2 -1
  41. package/src/admin/enrollment/email.ts +17 -3
  42. package/src/admin/enrollment/service.ts +71 -10
  43. package/src/admin/errors.ts +5 -0
  44. package/src/admin/index.ts +1 -0
  45. package/src/admin/reports/service.ts +9 -3
  46. package/src/admin/schema.ts +6 -5
  47. package/src/admin/users/service.ts +173 -16
  48. package/src/client/api.ts +29 -2
  49. package/src/client/comments.ts +205 -0
  50. package/src/client/device-authorization.ts +4 -20
  51. package/src/client/discovery.ts +4 -2
  52. package/src/client/files/archive.ts +60 -0
  53. package/src/client/files/checksum.ts +7 -0
  54. package/src/client/files/download.ts +122 -0
  55. package/src/client/files/images.ts +89 -0
  56. package/src/client/files/index.ts +15 -0
  57. package/src/client/files/objects.ts +173 -0
  58. package/src/client/files/save.ts +79 -0
  59. package/src/client/index.ts +3 -6
  60. package/src/client/portal/account.ts +20 -2
  61. package/src/client/portal/administration.ts +52 -5
  62. package/src/client/portal/request.ts +4 -2
  63. package/src/client/tour.ts +44 -0
  64. package/src/client/versions.ts +7 -1
  65. package/src/contract/account.ts +61 -11
  66. package/src/contract/admin/index.ts +48 -3
  67. package/src/contract/billing.ts +73 -4
  68. package/src/contract/comments.ts +223 -0
  69. package/src/contract/discovery.ts +47 -19
  70. package/src/contract/index.ts +10 -0
  71. package/src/contract/links.ts +5 -0
  72. package/src/contract/relay.ts +3 -1
  73. package/src/contract/services.ts +44 -4
  74. package/src/contract/workspaces.ts +5 -0
  75. package/src/email/locales/ar.json +28 -0
  76. package/src/email/locales/de.json +28 -0
  77. package/src/email/locales/es.json +28 -0
  78. package/src/email/locales/fr.json +28 -0
  79. package/src/email/locales/it.json +28 -0
  80. package/src/email/locales/ja.json +28 -0
  81. package/src/email/locales/pl.json +28 -0
  82. package/src/email/locales/pt-br.json +28 -0
  83. package/src/email/locales/ru.json +28 -0
  84. package/src/email/locales/zh-cn.json +28 -0
  85. package/src/email/messages.ts +35 -0
  86. package/src/email/render.ts +18 -0
  87. package/src/email/samples.ts +28 -1
  88. package/src/email/schema.ts +29 -3
  89. package/src/email/templates/BrandEmail.vue +3 -1
  90. package/src/email/templates/CommentNotification.vue +39 -0
  91. package/src/email/templates/EnrollmentInvitation.vue +53 -0
  92. package/src/email/templates/TwoStepChanged.vue +17 -2
  93. package/src/email/templates/brand.ts +6 -0
  94. package/src/errors/posthog.ts +28 -4
  95. package/src/runtime/cloudflare/email.ts +2 -0
  96. package/src/runtime/cloudflare/relay/index.ts +21 -6
  97. package/src/runtime/cloudflare/worker.ts +6 -0
  98. package/src/runtime/cloudflare/xml.ts +12 -0
  99. package/src/runtime/node/admin.ts +51 -47
  100. package/src/runtime/node/email/runtime.ts +1 -0
  101. package/src/runtime/node/email/transport.ts +1 -0
  102. package/src/runtime/node/server.ts +8 -2
  103. package/src/runtime/posthog/errors.ts +3 -1
  104. package/src/runtime/site/server.ts +4 -1
  105. package/src/server/account/actions.ts +3 -1
  106. package/src/server/account/deletion.ts +38 -4
  107. package/src/server/account/routes.ts +67 -46
  108. package/src/server/account/tokens.ts +3 -3
  109. package/src/server/api/router.ts +22 -7
  110. package/src/server/app/checks.ts +6 -1
  111. package/src/server/app/cors.ts +44 -0
  112. package/src/server/app/index.ts +76 -76
  113. package/src/server/app/routes.ts +14 -5
  114. package/src/server/app/services.ts +49 -15
  115. package/src/server/auth/access-control.ts +13 -8
  116. package/src/server/auth/account.ts +13 -12
  117. package/src/server/auth/activity.ts +7 -2
  118. package/src/server/auth/adapter.ts +16 -3
  119. package/src/server/auth/email.ts +29 -17
  120. package/src/server/auth/endpoints.ts +4 -0
  121. package/src/server/auth/factory.ts +83 -64
  122. package/src/server/auth/index.ts +1 -1
  123. package/src/server/auth/methods.ts +162 -0
  124. package/src/server/auth/mfa-assurance.ts +147 -10
  125. package/src/server/auth/rate-limit.ts +31 -0
  126. package/src/server/auth/runtime.ts +19 -5
  127. package/src/server/auth/social-providers.ts +70 -24
  128. package/src/server/billing/index.ts +2 -0
  129. package/src/server/billing/notify.ts +55 -0
  130. package/src/server/billing/seats.ts +17 -0
  131. package/src/server/billing/tokens.ts +1 -1
  132. package/src/server/cleanup/documents.ts +5 -2
  133. package/src/server/cleanup/revisions.ts +6 -3
  134. package/src/server/cleanup/uploads.ts +2 -1
  135. package/src/server/collaboration/relay/connection.ts +7 -2
  136. package/src/server/collaboration/relay/hub.ts +55 -24
  137. package/src/server/collaboration/routes.ts +8 -5
  138. package/src/server/comments/index.ts +9 -0
  139. package/src/server/comments/notify.ts +277 -0
  140. package/src/server/comments/routes.ts +352 -0
  141. package/src/server/comments/rows.ts +249 -0
  142. package/src/server/comments/service.ts +570 -0
  143. package/src/server/community/routes.ts +6 -6
  144. package/src/server/config/deployment.ts +19 -6
  145. package/src/server/config/index.ts +1 -1
  146. package/src/server/config/public.ts +19 -6
  147. package/src/server/config/schema.ts +14 -2
  148. package/src/server/config/toml/schema.ts +27 -4
  149. package/src/server/db/index.ts +2 -1
  150. package/src/server/db/migrate.ts +21 -1
  151. package/src/server/db/migrations/015_comments.ts +57 -0
  152. package/src/server/db/migrations/016_comment_notifications.ts +76 -0
  153. package/src/server/db/migrations/017_invitation_emails.ts +19 -0
  154. package/src/server/db/migrations/018_enrollment_source.ts +17 -0
  155. package/src/server/db/tables.ts +92 -2
  156. package/src/server/documents/access.ts +17 -0
  157. package/src/server/documents/images.ts +6 -1
  158. package/src/server/documents/routes.ts +12 -12
  159. package/src/server/documents/service.ts +19 -5
  160. package/src/server/documents/summary.ts +15 -0
  161. package/src/server/documents/versions/routes.ts +7 -8
  162. package/src/server/documents/versions/service.ts +5 -2
  163. package/src/server/email/service.ts +8 -2
  164. package/src/server/email/types.ts +1 -0
  165. package/src/server/errors/index.ts +48 -3
  166. package/src/server/index.ts +15 -1
  167. package/src/server/internal/routes.ts +8 -2
  168. package/src/server/internal/service.ts +10 -0
  169. package/src/server/invitations/budget.ts +3 -1
  170. package/src/server/invitations/index.ts +1 -0
  171. package/src/server/invitations/links.ts +6 -0
  172. package/src/server/pictures/service.ts +3 -1
  173. package/src/server/policy/workspace.ts +5 -2
  174. package/src/server/reports/routes.ts +2 -2
  175. package/src/server/reports/service.ts +3 -1
  176. package/src/server/services/routes.ts +2 -2
  177. package/src/server/sharing/capabilities/service.ts +1 -1
  178. package/src/server/sharing/document-routes.ts +3 -3
  179. package/src/server/sharing/invitations/service.ts +3 -4
  180. package/src/server/sharing/routes.ts +15 -15
  181. package/src/server/validation.ts +33 -25
  182. package/src/server/workspaces/members.ts +50 -12
  183. package/src/server/workspaces/repository.ts +23 -12
  184. package/src/server/workspaces/routes.ts +8 -8
  185. package/src/services/app.ts +30 -19
  186. package/src/services/config.ts +47 -8
  187. package/src/services/metering.ts +15 -27
  188. 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
- users(request: AdminListRequest<CloudAdminUserFilter>, signal?: AbortSignal) {
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(listQuery(request), options),
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 ?? 10_000
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 = callerSignal ? AbortSignal.any([callerSignal, timeout]) : timeout
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
+ }
@@ -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(page, (value) => value !== undefined)
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
@@ -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, or has to accept the server's current terms first.
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
- export const cloudAuthenticationProviderSchema = v.picklist(['credential', 'google', 'apple'])
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.array(cloudAuthenticationMethodSchema),
41
- availableSocialProviders: v.array(v.picklist(['google', 'apple']))
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: v.picklist(['google', 'apple']),
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
- export const cloudSignInMethodSchema = v.picklist([
253
+ const SIGN_IN_METHODS = [
210
254
  'password',
211
- 'google',
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(cloudSignInMethodSchema),
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: cloudSignInMethodSchema,
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
- methods: v.array(v.object({ provider: v.string(), createdAt: timestampSchema })),
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>
@@ -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
- /** Where the billing service answers, below the discovered `endpoint`. */
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
- /** A plan an account subscribes to, billed every month in US dollars before tax. */
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