@open-pencil/cloud 0.17.0-beta.1 → 0.17.0-beta.4

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 (235) hide show
  1. package/README.md +1 -1
  2. package/dist/bin/{ai-relay.mjs → services.mjs} +8 -8
  3. package/dist/bin/services.mjs.map +1 -0
  4. package/dist/client.d.ts +236 -46
  5. package/dist/client.d.ts.map +1 -1
  6. package/dist/client.js +649 -400
  7. package/dist/client.js.map +1 -1
  8. package/dist/contract.d.ts +2 -2
  9. package/dist/contract.js +2 -2
  10. package/dist/contract2.js +680 -443
  11. package/dist/contract2.js.map +1 -1
  12. package/dist/email.d.ts +9 -1
  13. package/dist/email.d.ts.map +1 -1
  14. package/dist/email.js +99 -58
  15. package/dist/email.js.map +1 -1
  16. package/dist/index.d.ts +468 -64
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/listen.mjs +575 -738
  19. package/dist/listen.mjs.map +1 -1
  20. package/dist/runtime-node.d.mts +6564 -2934
  21. package/dist/runtime-node.d.mts.map +1 -1
  22. package/dist/runtime-node.mjs +6 -5
  23. package/dist/runtime-node.mjs.map +1 -1
  24. package/dist/server.d.ts +8931 -4198
  25. package/dist/server.d.ts.map +1 -1
  26. package/dist/server.js +5260 -3859
  27. package/dist/server.js.map +1 -1
  28. package/dist/server.mjs +5686 -3736
  29. package/dist/server.mjs.map +1 -1
  30. package/dist/server2.mjs +101 -79
  31. package/dist/server2.mjs.map +1 -1
  32. package/package.json +9 -6
  33. package/src/admin/api/routes.ts +103 -33
  34. package/src/admin/audit/service.ts +25 -6
  35. package/src/admin/documents/service.ts +361 -0
  36. package/src/admin/errors.ts +9 -1
  37. package/src/admin/index.ts +6 -0
  38. package/src/admin/operations/service.ts +7 -0
  39. package/src/admin/reports/service.ts +147 -0
  40. package/src/admin/schema.ts +6 -0
  41. package/src/client/api.ts +36 -21
  42. package/src/client/auth/navigation.ts +6 -5
  43. package/src/client/index.ts +7 -7
  44. package/src/client/portal/account.ts +25 -0
  45. package/src/client/portal/administration.ts +56 -0
  46. package/src/client/{ai.ts → services.ts} +44 -27
  47. package/src/contract/account.ts +58 -2
  48. package/src/contract/admin/index.ts +67 -3
  49. package/src/contract/collaboration.ts +6 -1
  50. package/src/contract/discovery.ts +22 -4
  51. package/src/contract/documents.ts +27 -0
  52. package/src/contract/entitlements.ts +2 -2
  53. package/src/contract/index.ts +63 -37
  54. package/src/contract/relay.ts +6 -0
  55. package/src/contract/reports.ts +42 -0
  56. package/src/contract/services.ts +233 -0
  57. package/src/contract/sharing.ts +3 -9
  58. package/src/email/render.ts +26 -0
  59. package/src/email/schema.ts +11 -1
  60. package/src/email/templates/brand.ts +1 -1
  61. package/src/runtime/cloudflare/environment.ts +31 -6
  62. package/src/runtime/cloudflare/index.ts +1 -1
  63. package/src/runtime/cloudflare/logging.ts +15 -0
  64. package/src/runtime/cloudflare/maintenance.ts +31 -0
  65. package/src/runtime/cloudflare/relay/index.ts +176 -0
  66. package/src/runtime/cloudflare/relay/sockets.ts +112 -0
  67. package/src/runtime/cloudflare/worker.ts +89 -26
  68. package/src/runtime/node/application.ts +5 -3
  69. package/src/runtime/node/bootstrap.ts +20 -4
  70. package/src/runtime/node/cleanup.ts +16 -3
  71. package/src/runtime/node/entitlements/main.ts +14 -11
  72. package/src/runtime/node/index.ts +1 -1
  73. package/src/runtime/node/migrate.ts +5 -1
  74. package/src/runtime/node/relay.ts +8 -2
  75. package/src/runtime/node/request-id.ts +13 -0
  76. package/src/runtime/node/server.ts +71 -15
  77. package/src/runtime/node/{ai-relay → services}/main.ts +6 -6
  78. package/src/runtime/node/{ai-relay → services}/server.ts +18 -18
  79. package/src/runtime/postgres/database.ts +20 -1
  80. package/src/runtime/posthog/errors.ts +32 -0
  81. package/src/runtime/s3/objects.ts +50 -1
  82. package/src/runtime/site/server.ts +33 -4
  83. package/src/server/account/actions.ts +5 -0
  84. package/src/server/account/deletion.ts +302 -0
  85. package/src/server/account/routes.ts +47 -3
  86. package/src/server/account/terms.ts +42 -0
  87. package/src/server/api/router.ts +12 -7
  88. package/src/server/api/types.ts +9 -0
  89. package/src/server/app.ts +93 -15
  90. package/src/server/auth/access-control.ts +63 -0
  91. package/src/server/auth/adapter.ts +11 -0
  92. package/src/server/auth/endpoints.ts +5 -1
  93. package/src/server/auth/factory.ts +30 -3
  94. package/src/server/auth/index.ts +10 -1
  95. package/src/server/cleanup/configured.ts +12 -5
  96. package/src/server/cleanup/documents.ts +165 -71
  97. package/src/server/cleanup/objects.ts +10 -2
  98. package/src/server/cleanup/revisions.ts +24 -7
  99. package/src/server/cleanup/uploads.ts +8 -2
  100. package/src/server/cleanup/worker.ts +5 -2
  101. package/src/server/collaboration/index.ts +3 -0
  102. package/src/server/collaboration/relay/connection.ts +196 -0
  103. package/src/server/collaboration/relay/documents.ts +13 -10
  104. package/src/server/collaboration/relay/hub.ts +279 -195
  105. package/src/server/collaboration/relay/index.ts +3 -1
  106. package/src/server/collaboration/relay/log.ts +79 -0
  107. package/src/server/collaboration/relay/persistence.ts +147 -22
  108. package/src/server/collaboration/relay/resume.ts +28 -0
  109. package/src/server/collaboration/routes.ts +27 -16
  110. package/src/server/collaboration/service.ts +27 -31
  111. package/src/server/config/deployment.ts +35 -4
  112. package/src/server/config/public.ts +5 -4
  113. package/src/server/config/schema.ts +104 -16
  114. package/src/server/db/expressions.ts +15 -1
  115. package/src/server/db/migrate.ts +34 -114
  116. package/src/server/db/migrations/001_accounts.ts +79 -0
  117. package/src/server/db/migrations/002_workspaces.ts +48 -0
  118. package/src/server/db/migrations/003_storage.ts +44 -0
  119. package/src/server/db/migrations/004_documents.ts +193 -0
  120. package/src/server/db/migrations/005_sharing.ts +95 -0
  121. package/src/server/db/migrations/006_operations.ts +110 -0
  122. package/src/server/db/migrations/007_trash.ts +33 -0
  123. package/src/server/db/migrations/008_terms.ts +18 -0
  124. package/src/server/db/migrations/schema.ts +71 -0
  125. package/src/server/db/tables.ts +70 -7
  126. package/src/server/documents/access.ts +66 -55
  127. package/src/server/documents/errors.ts +7 -0
  128. package/src/server/documents/images.ts +2 -1
  129. package/src/server/documents/limits.ts +9 -9
  130. package/src/server/documents/purge.ts +75 -0
  131. package/src/server/documents/repository.ts +2 -0
  132. package/src/server/documents/routes.ts +132 -80
  133. package/src/server/documents/service.ts +18 -4
  134. package/src/server/documents/summary.ts +1 -0
  135. package/src/server/documents/trash.ts +203 -0
  136. package/src/server/documents/versions/checkpoint.ts +2 -1
  137. package/src/server/documents/versions/history.ts +11 -7
  138. package/src/server/documents/versions/routes.ts +36 -25
  139. package/src/server/documents/versions/service.ts +22 -4
  140. package/src/server/errors/index.ts +99 -0
  141. package/src/server/errors/posthog.ts +80 -0
  142. package/src/server/index.ts +56 -16
  143. package/src/server/internal/index.ts +3 -3
  144. package/src/server/internal/routes.ts +7 -15
  145. package/src/server/internal/schema.ts +1 -1
  146. package/src/server/internal/service.ts +17 -23
  147. package/src/server/invitations/budget.ts +66 -0
  148. package/src/server/invitations/index.ts +1 -0
  149. package/src/server/logging.ts +76 -0
  150. package/src/server/objects/types.ts +12 -0
  151. package/src/server/pictures/routes.ts +4 -2
  152. package/src/server/pictures/service.ts +2 -1
  153. package/src/server/policy/database.ts +39 -25
  154. package/src/server/policy/index.ts +2 -1
  155. package/src/server/policy/keys.ts +5 -2
  156. package/src/server/policy/policy.ts +1 -0
  157. package/src/server/policy/schema.ts +2 -2
  158. package/src/server/policy/service.ts +12 -9
  159. package/src/server/policy/static.ts +5 -5
  160. package/src/server/policy/workspace.ts +41 -0
  161. package/src/server/quota/reconcile.ts +2 -0
  162. package/src/server/quota/storage.ts +69 -31
  163. package/src/server/rate-limit/cleanup.ts +17 -5
  164. package/src/server/rate-limit/index.ts +4 -1
  165. package/src/server/rate-limit/middleware.ts +100 -12
  166. package/src/server/reports/index.ts +8 -0
  167. package/src/server/reports/routes.ts +37 -0
  168. package/src/server/reports/service.ts +123 -0
  169. package/src/server/services/errors.ts +7 -0
  170. package/src/server/services/index.ts +8 -0
  171. package/src/server/{ai → services}/keys.ts +11 -11
  172. package/src/server/services/routes.ts +47 -0
  173. package/src/server/{ai/service.ts → services/tokens.ts} +23 -20
  174. package/src/server/sharing/capabilities/service.ts +68 -22
  175. package/src/server/sharing/document-routes.ts +30 -22
  176. package/src/server/sharing/grants/service.ts +11 -18
  177. package/src/server/sharing/http.ts +4 -0
  178. package/src/server/sharing/invitations/service.ts +21 -11
  179. package/src/server/sharing/policy.ts +9 -14
  180. package/src/server/sharing/routes.ts +108 -85
  181. package/src/server/sharing/service.ts +1 -17
  182. package/src/server/validation.ts +59 -2
  183. package/src/server/workspaces/index.ts +1 -0
  184. package/src/server/workspaces/members.ts +89 -38
  185. package/src/server/workspaces/repository.ts +2 -1
  186. package/src/server/workspaces/routes.ts +67 -45
  187. package/src/{ai-relay → services}/app.ts +48 -44
  188. package/src/{ai-relay → services}/config.ts +25 -19
  189. package/src/services/db/index.ts +10 -0
  190. package/src/services/db/migrate.ts +37 -0
  191. package/src/{ai-relay/db/migrations/001_usage.ts → services/db/migrations/001_baseline.ts} +18 -7
  192. package/src/services/db/schema.ts +22 -0
  193. package/src/services/index.ts +18 -0
  194. package/src/{ai-relay → services}/metering.ts +2 -2
  195. package/src/{ai-relay → services}/usage.ts +43 -19
  196. package/dist/bin/ai-relay.mjs.map +0 -1
  197. package/src/ai-relay/db/index.ts +0 -10
  198. package/src/ai-relay/db/migrate.ts +0 -32
  199. package/src/ai-relay/db/schema.ts +0 -20
  200. package/src/ai-relay/index.ts +0 -18
  201. package/src/contract/ai.ts +0 -150
  202. package/src/runtime/cloudflare/relay.ts +0 -136
  203. package/src/server/ai/errors.ts +0 -7
  204. package/src/server/ai/index.ts +0 -4
  205. package/src/server/ai/routes.ts +0 -43
  206. package/src/server/auth/workspace-access.ts +0 -23
  207. package/src/server/db/migrations/001_foundation.ts +0 -164
  208. package/src/server/db/migrations/002_upload_cleanup_claims.ts +0 -34
  209. package/src/server/db/migrations/003_document_cleanup_claims.ts +0 -23
  210. package/src/server/db/migrations/004_document_sharing.ts +0 -82
  211. package/src/server/db/migrations/005_document_collaboration_epoch.ts +0 -13
  212. package/src/server/db/migrations/006_invitation_continuation.ts +0 -27
  213. package/src/server/db/migrations/007_collaboration_state.ts +0 -25
  214. package/src/server/db/migrations/008_storage_reservations.ts +0 -37
  215. package/src/server/db/migrations/009_workspace_entitlements.ts +0 -22
  216. package/src/server/db/migrations/010_upload_finalization.ts +0 -22
  217. package/src/server/db/migrations/011_upload_finalization_lease.ts +0 -12
  218. package/src/server/db/migrations/012_transactional_email.ts +0 -48
  219. package/src/server/db/migrations/013_admin_enrollment.ts +0 -54
  220. package/src/server/db/migrations/014_enrollment_email_kinds.ts +0 -30
  221. package/src/server/db/migrations/015_cloud_rate_limit.ts +0 -22
  222. package/src/server/db/migrations/016_auth_schema.ts +0 -16
  223. package/src/server/db/migrations/017_authentication_email_kinds.ts +0 -32
  224. package/src/server/db/migrations/018_authentication_mfa.ts +0 -78
  225. package/src/server/db/migrations/019_better_auth_account_issuer.ts +0 -42
  226. package/src/server/db/migrations/020_workspace_invitations.ts +0 -57
  227. package/src/server/db/migrations/021_document_versions.ts +0 -66
  228. package/src/server/db/migrations/022_entitlement_external_version.ts +0 -17
  229. package/src/server/db/migrations/023_document_images.ts +0 -61
  230. package/src/server/db/migrations/024_account_activity.ts +0 -66
  231. package/src/server/db/migrations/025_table_names.ts +0 -58
  232. package/src/server/db/migrations/026_user_picture.ts +0 -30
  233. package/src/server/db/migrations/027_document_kind.ts +0 -19
  234. package/src/server/db/migrations/helpers.ts +0 -78
  235. /package/dist/bin/{ai-relay.d.mts → services.d.mts} +0 -0
package/dist/client.js CHANGED
@@ -2,17 +2,22 @@ import { isValid } from "js-base64";
2
2
  import * as v from "valibot";
3
3
  import { zipObject } from "es-toolkit";
4
4
  import { joinURL, withQuery, withoutFragment } from "ufo";
5
- import { pickBy } from "es-toolkit/object";
6
5
  import { hc } from "hono/client";
6
+ import { pickBy } from "es-toolkit/object";
7
7
  import { passkeyClient } from "@better-auth/passkey/client";
8
8
  import { createAuthClient } from "better-auth/client";
9
9
  import { deviceAuthorizationClient, twoFactorClient } from "better-auth/client/plugins";
10
10
  //#region src/contract/account.ts
11
+ /**
12
+ * Where an account stands: it may use the server, waits for an administrator, was refused or had
13
+ * its access taken back, or has to accept the server's current terms first.
14
+ */
11
15
  const cloudAccountStateSchema = v.picklist([
12
16
  "active",
13
17
  "pending",
14
18
  "rejected",
15
- "revoked"
19
+ "revoked",
20
+ "terms"
16
21
  ]);
17
22
  const cloudIdentitySchema = v.object({
18
23
  userId: v.string(),
@@ -26,6 +31,7 @@ const cloudAccountStatusResponseSchema = v.object({
26
31
  user: cloudIdentitySchema,
27
32
  state: cloudAccountStateSchema
28
33
  });
34
+ v.object({ version: v.pipe(v.string(), v.minLength(1)) });
29
35
  const cloudAuthenticationProviderSchema = v.picklist([
30
36
  "credential",
31
37
  "google",
@@ -61,7 +67,10 @@ const accountSecurityErrorCodeSchema = v.picklist([
61
67
  "email_unchanged",
62
68
  "email_change_unavailable",
63
69
  "current_session",
64
- "picture_invalid"
70
+ "picture_invalid",
71
+ "account_sole_admin",
72
+ "last_admin_required",
73
+ "terms_changed"
65
74
  ]);
66
75
  const accountSecurityErrorResponseSchema = v.object({ error: v.object({ code: accountSecurityErrorCodeSchema }) });
67
76
  const cloudMFAStatusSchema = v.object({
@@ -152,42 +161,76 @@ const cloudSignInSchema = v.object({
152
161
  createdAt: v.string()
153
162
  });
154
163
  const cloudSignInsResponseSchema = v.object({ signIns: v.array(cloudSignInSchema) });
155
- /** The `aud` of every token Cloud signs for an AI service. */
156
- const CLOUD_AI_TOKEN_AUDIENCE = "openpencil-ai";
164
+ /** A workspace an account deletion reads: one it would delete, or one that stops it. */
165
+ const cloudAccountDeletionWorkspaceSchema = v.object({
166
+ id: v.pipe(v.string(), v.uuid()),
167
+ name: v.string()
168
+ });
169
+ /** A document the account would lose, which Download all saves first. */
170
+ const cloudAccountDeletionDocumentSchema = v.object({
171
+ id: v.pipe(v.string(), v.uuid()),
172
+ name: v.string(),
173
+ workspaceName: v.string()
174
+ });
175
+ /**
176
+ * What deleting the account takes: the workspaces only it belongs to, which go with their
177
+ * documents; the ones it leaves to their other members; the ones it alone administers for other
178
+ * members, which stop the deletion until it makes someone else an admin; and the documents it
179
+ * would lose, those workspaces' and the ones it created in workspaces it leaves.
180
+ */
181
+ const cloudAccountDeletionSchema = v.object({
182
+ /** The account is the deployment's only administrator, which also stops the deletion. */
183
+ lastAdministrator: v.boolean(),
184
+ blockedBy: v.array(cloudAccountDeletionWorkspaceSchema),
185
+ deletes: v.array(cloudAccountDeletionWorkspaceSchema),
186
+ leaves: v.array(cloudAccountDeletionWorkspaceSchema),
187
+ documents: v.array(cloudAccountDeletionDocumentSchema)
188
+ });
189
+ const cloudAccountDeletionResponseSchema = v.object({ deletion: cloudAccountDeletionSchema });
190
+ v.object({ password: v.optional(v.pipe(v.string(), v.minLength(1))) });
191
+ /** The `aud` of every token Cloud signs for its services. */
192
+ const CLOUD_SERVICES_TOKEN_AUDIENCE = "openpencil-services";
157
193
  /**
158
194
  * Where a service answers, below the discovered `endpoint`. Model requests follow the OpenAI chat
159
195
  * completions API, so an OpenAI-compatible client takes `${endpoint}${base}` as its base URL.
160
196
  */
161
- const CLOUD_AI_API_PATHS = {
197
+ const CLOUD_SERVICES_API_PATHS = {
162
198
  base: "/v1",
163
199
  chatCompletions: "/v1/chat/completions",
164
200
  catalog: "/v1/catalog",
165
201
  wallet: "/v1/wallet",
166
- usage: "/v1/usage"
202
+ usage: "/v1/usage",
203
+ search: "/v1/search"
167
204
  };
168
205
  const urlSchema = v.pipe(v.string(), v.url());
169
206
  const creditsSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
170
- const cloudAIDiscoverySchema = v.object({
207
+ const cloudServicesDiscoverySchema = v.object({
171
208
  endpoint: urlSchema,
172
209
  contractVersion: v.literal("1")
173
210
  });
174
211
  const cloudBillingDiscoverySchema = v.object({ portalURL: urlSchema });
175
212
  v.object({ workspaceId: v.pipe(v.string(), v.uuid()) });
176
- const aiTokenSchema = v.object({
213
+ const servicesTokenSchema = v.object({
177
214
  token: v.pipe(v.string(), v.minLength(1)),
178
215
  expiresAt: v.pipe(v.string(), v.isoTimestamp())
179
216
  });
180
217
  v.object({
181
218
  iss: urlSchema,
182
- aud: v.literal(CLOUD_AI_TOKEN_AUDIENCE),
219
+ aud: v.literal(CLOUD_SERVICES_TOKEN_AUDIENCE),
183
220
  sub: v.pipe(v.string(), v.minLength(1)),
184
221
  workspaceId: v.pipe(v.string(), v.uuid()),
185
- /** Credits the workspace's plan grants each month; `null` when Cloud sets no allowance. */
222
+ /**
223
+ * The account whose credits the request spends: the workspace's owner, whose allowance every
224
+ * workspace they own shares. Absent from tokens a Cloud from before account plans issued, which
225
+ * a relay takes as the workspace's own allowance, as such a Cloud meant.
226
+ */
227
+ accountId: v.optional(v.pipe(v.string(), v.minLength(1))),
228
+ /** Credits the owner's plan grants each month; `null` when Cloud sets no allowance. */
186
229
  monthlyCreditAllowance: v.nullable(creditsSchema),
187
230
  iat: v.pipe(v.number(), v.integer()),
188
231
  exp: v.pipe(v.number(), v.integer())
189
232
  });
190
- const aiModelSchema = v.object({
233
+ const chatModelSchema = v.object({
191
234
  id: v.pipe(v.string(), v.minLength(1)),
192
235
  label: v.pipe(v.string(), v.minLength(1)),
193
236
  /** Credits per million input and output tokens. */
@@ -200,11 +243,14 @@ const aiModelSchema = v.object({
200
243
  tools: v.boolean()
201
244
  })
202
245
  });
203
- const aiCatalogSchema = v.object({
204
- models: v.array(aiModelSchema),
205
- defaultModelID: v.pipe(v.string(), v.minLength(1))
246
+ /** What one web search costs; a service without search leaves it out of its catalog. */
247
+ const searchPricingSchema = v.object({ creditsPerRequest: creditsSchema });
248
+ const serviceCatalogSchema = v.object({
249
+ models: v.array(chatModelSchema),
250
+ defaultModelID: v.pipe(v.string(), v.minLength(1)),
251
+ search: v.optional(searchPricingSchema)
206
252
  });
207
- const aiCreditBucketSchema = v.object({
253
+ const creditBucketSchema = v.object({
208
254
  kind: v.picklist([
209
255
  "allowance",
210
256
  "purchased",
@@ -217,13 +263,13 @@ const aiCreditBucketSchema = v.object({
217
263
  * A service records a request's charge before the request's answer ends, so a wallet read after
218
264
  * an answer includes what it cost.
219
265
  */
220
- const aiWalletSchema = v.object({
266
+ const creditWalletSchema = v.object({
221
267
  /** Credits left to spend; `null` when the service sets no limit. */
222
268
  balance: v.nullable(creditsSchema),
223
269
  /** Spent first to last. */
224
- buckets: v.array(aiCreditBucketSchema)
270
+ buckets: v.array(creditBucketSchema)
225
271
  });
226
- const aiUsageEntrySchema = v.object({
272
+ const usageEntrySchema = v.object({
227
273
  id: v.pipe(v.string(), v.minLength(1)),
228
274
  createdAt: v.pipe(v.string(), v.isoTimestamp()),
229
275
  kind: v.picklist([
@@ -235,25 +281,240 @@ const aiUsageEntrySchema = v.object({
235
281
  userId: v.pipe(v.string(), v.minLength(1)),
236
282
  credits: creditsSchema
237
283
  });
284
+ v.object({
285
+ query: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(1e3)),
286
+ numResults: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(10)), 5)
287
+ });
288
+ /** One page a search found, with the part of its text that answers the query. */
289
+ const searchResultSchema = v.object({
290
+ url: v.pipe(urlSchema, v.regex(/^https?:\/\//i, "A search result links to an HTTP(S) page")),
291
+ title: v.string(),
292
+ publishedAt: v.nullable(v.pipe(v.string(), v.isoTimestamp())),
293
+ author: v.nullable(v.string()),
294
+ text: v.string()
295
+ });
296
+ const searchResponseSchema = v.object({ results: v.array(searchResultSchema) });
238
297
  v.object({ cursor: v.optional(v.pipe(v.string(), v.minLength(1))) });
239
298
  v.object({
240
- entries: v.array(aiUsageEntrySchema),
299
+ entries: v.array(usageEntrySchema),
241
300
  next: v.nullable(v.string())
242
301
  });
243
- /** Errors an AI service answers with, beside the upstream model's own. */
244
- const aiErrorCodeSchema = v.picklist([
302
+ /** Errors a service answers with, beside the upstream provider's own. */
303
+ const serviceErrorCodeSchema = v.picklist([
304
+ "invalid_request",
245
305
  "unauthorized",
246
306
  "insufficient_credits",
247
307
  "model_not_allowed",
308
+ "capability_unavailable",
248
309
  "rate_limited"
249
310
  ]);
250
- const aiErrorSchema = v.object({ error: v.object({
251
- code: aiErrorCodeSchema,
311
+ const serviceErrorSchema = v.object({ error: v.object({
312
+ code: serviceErrorCodeSchema,
252
313
  message: v.optional(v.string()),
253
314
  /** With `insufficient_credits`: when the workspace's allowance renews, if the service knows. */
254
315
  resetsAt: v.optional(v.pipe(v.string(), v.isoTimestamp()))
255
316
  }) });
256
317
  //#endregion
318
+ //#region src/contract/documents.ts
319
+ const CLOUD_PROTOCOL_MAX_UPLOAD_BYTES = 1073741824;
320
+ const checksumSchema = v.pipe(v.string(), v.regex(/^[A-Za-z0-9+/]{43}=$/));
321
+ /** The most images one revision, or one request for image uploads, may name. */
322
+ const CLOUD_MAX_DOCUMENT_IMAGES = 1e4;
323
+ const imageNameSchema = v.pipe(v.string(), v.regex(/^[A-Za-z0-9._-]{1,128}$/));
324
+ const objectDownloadSchema = v.object({
325
+ url: v.pipe(v.string(), v.url()),
326
+ method: v.literal("GET"),
327
+ headers: v.record(v.string(), v.string()),
328
+ expiresAt: v.string()
329
+ });
330
+ /** An image a stored revision uses, where to download it, and what to check it against. */
331
+ const documentImageDownloadSchema = v.object({
332
+ name: imageNameSchema,
333
+ checksum: checksumSchema,
334
+ byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
335
+ download: objectDownloadSchema
336
+ });
337
+ /** Where to download an image a document uses, found by its checksum. */
338
+ const documentImageLinkSchema = v.object({
339
+ checksum: checksumSchema,
340
+ byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
341
+ download: objectDownloadSchema
342
+ });
343
+ /** The images a live room names, by checksum, that a peer needs links for. */
344
+ const requestImageLinksSchema = v.object({ checksums: v.pipe(v.array(checksumSchema), v.minLength(1), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)) });
345
+ const documentPermissionSchema = v.picklist(["view", "edit"]);
346
+ const documentAccessSourceSchema = v.picklist([
347
+ "owner",
348
+ "workspace",
349
+ "direct-grant"
350
+ ]);
351
+ const documentAccessSchema = v.object({
352
+ permission: documentPermissionSchema,
353
+ canManageSharing: v.boolean(),
354
+ sources: v.array(documentAccessSourceSchema)
355
+ });
356
+ /** What a document is: a Figma design or a FigJam board, which the file it stores says too. */
357
+ const documentKindSchema = v.picklist(["design", "board"]);
358
+ const documentSummarySchema = v.object({
359
+ id: v.pipe(v.string(), v.uuid()),
360
+ workspaceId: v.pipe(v.string(), v.uuid()),
361
+ name: v.string(),
362
+ /** A design unless said otherwise; servers from before boards list no kind. */
363
+ kind: v.optional(documentKindSchema, "design"),
364
+ currentRevisionId: v.nullable(v.pipe(v.string(), v.uuid())),
365
+ version: v.number(),
366
+ createdAt: v.string(),
367
+ updatedAt: v.string()
368
+ });
369
+ /** A document someone granted the person directly, in a workspace they are not a member of. */
370
+ const sharedDocumentSchema = v.object({
371
+ ...documentSummarySchema.entries,
372
+ workspaceName: v.string(),
373
+ permission: documentPermissionSchema,
374
+ sharedBy: v.nullable(v.object({ name: v.string() })),
375
+ sharedAt: v.string()
376
+ });
377
+ /**
378
+ * A document in Trash the person may restore: who deleted it and when, and when it goes for good.
379
+ * `canPurge` says whether they may also delete it for good before then.
380
+ */
381
+ const trashedDocumentSchema = v.object({
382
+ id: v.pipe(v.string(), v.uuid()),
383
+ workspaceId: v.pipe(v.string(), v.uuid()),
384
+ workspaceName: v.string(),
385
+ name: v.string(),
386
+ kind: v.optional(documentKindSchema, "design"),
387
+ deletedAt: v.string(),
388
+ deletedBy: v.nullable(v.object({ name: v.string() })),
389
+ purgeAt: v.string(),
390
+ canPurge: v.boolean()
391
+ });
392
+ const trashSchema = v.object({ documents: v.array(trashedDocumentSchema) });
393
+ const documentDownloadSchema = v.object({
394
+ document: documentSummarySchema,
395
+ revisionId: v.pipe(v.string(), v.uuid()),
396
+ byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
397
+ checksum: checksumSchema,
398
+ contentType: v.string(),
399
+ download: objectDownloadSchema,
400
+ /** The images the stored file leaves out, which a client puts back under their names. */
401
+ images: v.pipe(v.array(documentImageDownloadSchema), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES))
402
+ });
403
+ const cloudActorSchema = v.object({
404
+ userId: v.string(),
405
+ email: v.pipe(v.string(), v.email()),
406
+ name: v.string()
407
+ });
408
+ const cloudSessionSchema = v.object({ user: cloudActorSchema });
409
+ const workspaceUsageSchema = v.object({
410
+ bytesUsed: v.pipe(v.number(), v.integer(), v.minValue(0)),
411
+ objectCount: v.pipe(v.number(), v.integer(), v.minValue(0)),
412
+ documentCount: v.pipe(v.number(), v.integer(), v.minValue(0))
413
+ });
414
+ const createDocumentSchema = v.object({
415
+ id: v.optional(v.pipe(v.string(), v.uuid())),
416
+ name: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(255)),
417
+ /** A design unless said otherwise; older clients create only designs. */
418
+ kind: v.optional(documentKindSchema, "design")
419
+ });
420
+ v.object({
421
+ baseRevisionId: v.nullable(v.pipe(v.string(), v.uuid())),
422
+ byteSize: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(CLOUD_PROTOCOL_MAX_UPLOAD_BYTES)),
423
+ checksum: checksumSchema,
424
+ contentType: v.literal("application/octet-stream")
425
+ });
426
+ const imageSizeSchema = v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(CLOUD_PROTOCOL_MAX_UPLOAD_BYTES));
427
+ /** Where a client puts an object: one presigned PUT, or the parts of a multipart upload. */
428
+ const objectUploadSchema = v.variant("kind", [v.object({
429
+ kind: v.literal("single"),
430
+ url: v.pipe(v.string(), v.url()),
431
+ method: v.literal("PUT"),
432
+ headers: v.record(v.string(), v.string()),
433
+ expiresAt: v.string()
434
+ }), v.object({
435
+ kind: v.literal("multipart"),
436
+ uploadId: v.string(),
437
+ partSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
438
+ parts: v.array(v.object({
439
+ partNumber: v.pipe(v.number(), v.integer(), v.minValue(1)),
440
+ url: v.pipe(v.string(), v.url()),
441
+ method: v.literal("PUT"),
442
+ headers: v.record(v.string(), v.string())
443
+ })),
444
+ expiresAt: v.string()
445
+ })]);
446
+ /** An upload the server offers for an image the workspace lacks. */
447
+ const imageUploadOfferSchema = v.object({
448
+ checksum: checksumSchema,
449
+ uploadId: v.pipe(v.string(), v.uuid()),
450
+ upload: objectUploadSchema
451
+ });
452
+ v.object({ images: v.pipe(v.array(v.object({
453
+ checksum: checksumSchema,
454
+ byteSize: imageSizeSchema
455
+ })), v.minLength(1), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)) });
456
+ const completedUploadPartSchema = v.object({
457
+ partNumber: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(1e4)),
458
+ etag: v.pipe(v.string(), v.minLength(1), v.maxLength(255))
459
+ });
460
+ const commitUploadSchema = v.object({
461
+ checksum: checksumSchema,
462
+ /** The document title captured with this revision; omitted by older clients. */
463
+ name: v.optional(createDocumentSchema.entries.name),
464
+ /** What the uploaded file is, which the document takes; omitted by older clients. */
465
+ kind: v.optional(documentKindSchema),
466
+ multipart: v.optional(v.object({
467
+ uploadId: v.pipe(v.string(), v.minLength(1)),
468
+ parts: v.pipe(v.array(completedUploadPartSchema), v.minLength(1), v.maxLength(1e4))
469
+ })),
470
+ /** The images the uploaded file leaves out, each stored in the workspace or uploaded before. */
471
+ images: v.optional(v.pipe(v.array(v.object({
472
+ name: imageNameSchema,
473
+ checksum: checksumSchema
474
+ })), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)), [])
475
+ });
476
+ v.object({ uploads: v.pipe(v.array(v.object({
477
+ uploadId: v.pipe(v.string(), v.uuid()),
478
+ checksum: checksumSchema,
479
+ multipart: commitUploadSchema.entries.multipart
480
+ })), v.minLength(1), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)) });
481
+ //#endregion
482
+ //#region src/contract/collaboration.ts
483
+ const collaborationPrincipalSchema = v.variant("kind", [v.object({
484
+ kind: v.literal("user"),
485
+ userId: v.string(),
486
+ name: v.string(),
487
+ email: v.pipe(v.string(), v.email())
488
+ }), v.object({
489
+ kind: v.literal("guest"),
490
+ guestId: v.string(),
491
+ name: v.string()
492
+ })]);
493
+ v.object({
494
+ kind: v.picklist(["user", "guest"]),
495
+ id: v.string(),
496
+ name: v.string(),
497
+ permission: documentPermissionSchema
498
+ });
499
+ const collaborationTicketSchema = v.object({
500
+ token: v.string(),
501
+ provider: v.optional(v.picklist(["trystero", "relay"])),
502
+ serverURL: v.optional(v.pipe(v.string(), v.url())),
503
+ documentId: v.pipe(v.string(), v.uuid()),
504
+ roomId: v.string(),
505
+ roomKey: v.pipe(v.string(), v.minLength(43), v.maxLength(128)),
506
+ principal: collaborationPrincipalSchema,
507
+ permission: documentPermissionSchema,
508
+ roomEpoch: v.pipe(v.number(), v.integer(), v.minValue(0)),
509
+ expiresAt: v.string(),
510
+ serverEnforcedWrites: v.boolean(),
511
+ /**
512
+ * Whether the relay answers `RELAY_HEARTBEAT`. A relay from before it takes a ping for a
513
+ * malformed frame and turns the peer away, so editors ask only a relay that says it answers.
514
+ */
515
+ relayHeartbeat: v.optional(v.boolean(), false)
516
+ });
517
+ //#endregion
257
518
  //#region src/contract/workspaces.ts
258
519
  const workspaceRoleSchema = v.picklist([
259
520
  "viewer",
@@ -312,6 +573,130 @@ const createdWorkspaceInvitationSchema = v.object({
312
573
  });
313
574
  v.object({ role: workspaceRoleSchema });
314
575
  //#endregion
576
+ //#region src/contract/sharing.ts
577
+ const documentShareSchema = v.object({
578
+ id: v.pipe(v.string(), v.uuid()),
579
+ documentId: v.pipe(v.string(), v.uuid()),
580
+ permission: documentPermissionSchema,
581
+ roomEpoch: v.pipe(v.number(), v.integer(), v.minValue(0)),
582
+ createdBy: v.string(),
583
+ createdAt: v.string(),
584
+ updatedAt: v.string(),
585
+ expiresAt: v.nullable(v.string()),
586
+ revokedAt: v.nullable(v.string()),
587
+ lastUsedAt: v.nullable(v.string())
588
+ });
589
+ /** When a link stops working, as an ISO timestamp; `null` keeps it working until revoked. */
590
+ const shareExpirySchema = v.optional(v.nullable(v.pipe(v.string(), v.isoTimestamp())));
591
+ v.object({
592
+ permission: documentPermissionSchema,
593
+ expiresAt: shareExpirySchema
594
+ });
595
+ v.object({
596
+ permission: v.optional(documentPermissionSchema),
597
+ expiresAt: shareExpirySchema
598
+ });
599
+ const resolveDocumentShareSchema = v.object({
600
+ secret: v.pipe(v.string(), v.minLength(32), v.maxLength(128)),
601
+ guestName: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(80))),
602
+ guestId: v.optional(v.pipe(v.string(), v.minLength(16), v.maxLength(128)))
603
+ });
604
+ v.object({
605
+ ...resolveDocumentShareSchema.entries,
606
+ ...requestImageLinksSchema.entries
607
+ });
608
+ const resolvedDocumentShareSchema = v.object({
609
+ documentId: v.pipe(v.string(), v.uuid()),
610
+ /** What this person may do; a guest on an edit link may only view where guests may not edit. */
611
+ permission: documentPermissionSchema,
612
+ /** What the link lets someone signed in to the server do. */
613
+ linkPermission: documentPermissionSchema,
614
+ principal: collaborationPrincipalSchema,
615
+ roomEpoch: v.pipe(v.number(), v.integer(), v.minValue(0))
616
+ });
617
+ const cloudUserProfileSchema = v.object({
618
+ id: v.string(),
619
+ name: v.string(),
620
+ email: v.pipe(v.string(), v.email()),
621
+ image: v.nullable(v.pipe(v.string(), v.url()))
622
+ });
623
+ const documentGrantSchema = v.object({
624
+ id: v.pipe(v.string(), v.uuid()),
625
+ documentId: v.pipe(v.string(), v.uuid()),
626
+ userId: v.string(),
627
+ permission: documentPermissionSchema,
628
+ createdBy: v.string(),
629
+ createdAt: v.string(),
630
+ updatedAt: v.string()
631
+ });
632
+ /** What accepting an invitation gave: access to a document, or a place in a workspace. */
633
+ const acceptedInvitationSchema = v.variant("kind", [v.object({
634
+ kind: v.literal("document"),
635
+ grant: documentGrantSchema
636
+ }), v.object({
637
+ kind: v.literal("workspace"),
638
+ workspaceId: v.pipe(v.string(), v.uuid()),
639
+ role: workspaceRoleSchema
640
+ })]);
641
+ v.object({ permission: documentPermissionSchema });
642
+ v.object({
643
+ email: v.pipe(v.string(), v.trim(), v.toLowerCase(), v.email()),
644
+ permission: documentPermissionSchema
645
+ });
646
+ v.object({ token: v.pipe(v.string(), v.minLength(32), v.maxLength(128)) });
647
+ const createInvitationContinuationSchema = v.object({
648
+ invitationId: v.pipe(v.string(), v.uuid()),
649
+ token: v.pipe(v.string(), v.minLength(32), v.maxLength(128))
650
+ });
651
+ const invitationContinuationSchema = v.object({ id: v.pipe(v.string(), v.minLength(16), v.maxLength(128)) });
652
+ const invitationPreviewFields = {
653
+ inviterName: v.string(),
654
+ expiresAt: v.string(),
655
+ recipientHint: v.string()
656
+ };
657
+ /** What an invitation link opens: one document, or a whole workspace. */
658
+ const invitationPreviewSchema = v.variant("kind", [v.object({
659
+ kind: v.literal("document"),
660
+ documentName: v.string(),
661
+ permission: documentPermissionSchema,
662
+ ...invitationPreviewFields
663
+ }), v.object({
664
+ kind: v.literal("workspace"),
665
+ workspaceName: v.string(),
666
+ role: workspaceRoleSchema,
667
+ ...invitationPreviewFields
668
+ })]);
669
+ const documentInvitationSchema = v.object({
670
+ id: v.pipe(v.string(), v.uuid()),
671
+ documentId: v.pipe(v.string(), v.uuid()),
672
+ email: v.pipe(v.string(), v.email()),
673
+ permission: documentPermissionSchema,
674
+ invitedBy: v.string(),
675
+ invitedAt: v.string(),
676
+ expiresAt: v.string(),
677
+ acceptedAt: v.nullable(v.string())
678
+ });
679
+ //#endregion
680
+ //#region src/contract/reports.ts
681
+ /** Why someone reports a document shared with them. */
682
+ const documentReportReasonSchema = v.picklist([
683
+ "spam-phishing",
684
+ "illegal",
685
+ "copyright",
686
+ "harassment",
687
+ "other"
688
+ ]);
689
+ v.object({
690
+ secret: resolveDocumentShareSchema.entries.secret,
691
+ guestId: resolveDocumentShareSchema.entries.guestId,
692
+ reason: documentReportReasonSchema,
693
+ description: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(2e3)),
694
+ /** Where an administrator may answer; optional, and never shown to the document's people. */
695
+ replyEmail: v.optional(v.pipe(v.string(), v.trim(), v.toLowerCase(), v.email(), v.maxLength(254)))
696
+ });
697
+ /** What filing a report answers: that it arrived, and nothing about the document. */
698
+ const fileDocumentReportResponseSchema = v.object({ received: v.literal(true) });
699
+ //#endregion
315
700
  //#region src/contract/admin/index.ts
316
701
  const timestampSchema = v.pipe(v.string(), v.isoTimestamp());
317
702
  const nullableTimestampSchema = v.nullable(timestampSchema);
@@ -336,7 +721,9 @@ const adminErrorCodeSchema = v.picklist([
336
721
  "last_admin_required",
337
722
  "self_admin_action_forbidden",
338
723
  "email_regeneration_unavailable",
339
- "mfa_required"
724
+ "mfa_required",
725
+ "document_not_restorable",
726
+ "workspace_gone"
340
727
  ]);
341
728
  const adminErrorResponseSchema = v.object({ error: v.object({ code: adminErrorCodeSchema }) });
342
729
  const enrollmentStatusSchema = v.picklist([
@@ -415,253 +802,150 @@ const transactionalEmailAdminSchema = v.object({
415
802
  id: v.string(),
416
803
  kind: v.string(),
417
804
  recipientEmailNormalized: v.pipe(v.string(), v.email()),
418
- status: v.string(),
419
- attemptCount: v.pipe(v.number(), v.integer(), v.minValue(0)),
420
- nextAttemptAt: timestampSchema,
421
- transport: v.nullable(v.string()),
422
- transportMessageId: v.nullable(v.string()),
423
- lastErrorCode: v.nullable(v.string()),
424
- createdAt: timestampSchema,
425
- acceptedAt: nullableTimestampSchema,
426
- regeneratable: v.boolean()
427
- });
428
- /** Which messages a list of email shows, by how their delivery went. */
429
- const cloudAdminEmailFilterSchema = v.picklist([
430
- "all",
431
- "sent",
432
- "waiting",
433
- "failed"
434
- ]);
435
- const adminEmailResponseSchema = v.object({
436
- messages: v.array(transactionalEmailAdminSchema),
437
- ...listTotals(cloudAdminEmailFilterSchema.options)
438
- });
439
- /** Who or what an event names; `name` is null once the server no longer knows it. */
440
- const auditPartySchema = v.object({
441
- id: v.string(),
442
- name: v.nullable(v.string())
443
- });
444
- const adminAuditEventSchema = v.object({
445
- id: v.string(),
446
- actor: auditPartySchema,
447
- action: v.string(),
448
- /** What the event is about: an account, an access request, or an email. */
449
- subject: v.object({
450
- ...auditPartySchema.entries,
451
- type: v.string()
452
- }),
453
- metadata: v.unknown(),
454
- createdAt: timestampSchema
455
- });
456
- /** Which events a list of activity shows, by what they are about. */
457
- const cloudAdminAuditFilterSchema = v.picklist([
458
- "all",
459
- "accounts",
460
- "requests",
461
- "email"
462
- ]);
463
- const adminAuditResponseSchema = v.object({
464
- events: v.array(adminAuditEventSchema),
465
- ...listTotals(cloudAdminAuditFilterSchema.options)
466
- });
467
- const adminOperationsResponseSchema = v.object({
468
- deployment: v.picklist(["official", "self-hosted"]),
469
- enrollmentMode: v.picklist([
470
- "open",
471
- "approval",
472
- "closed"
473
- ]),
474
- emailTransport: v.picklist([
475
- "none",
476
- "smtp",
477
- "cloudflare"
478
- ]),
479
- pendingEnrollment: v.pipe(v.number(), v.integer(), v.minValue(0)),
480
- pendingEmail: v.pipe(v.number(), v.integer(), v.minValue(0)),
481
- failedEmail: v.pipe(v.number(), v.integer(), v.minValue(0)),
482
- accounts: countSchema,
483
- workspaces: countSchema,
484
- documents: countSchema,
485
- storedBytes: countSchema
486
- });
487
- //#endregion
488
- //#region src/contract/documents.ts
489
- const CLOUD_PROTOCOL_MAX_UPLOAD_BYTES = 1073741824;
490
- const checksumSchema = v.pipe(v.string(), v.regex(/^[A-Za-z0-9+/]{43}=$/));
491
- /** The most images one revision, or one request for image uploads, may name. */
492
- const CLOUD_MAX_DOCUMENT_IMAGES = 1e4;
493
- const imageNameSchema = v.pipe(v.string(), v.regex(/^[A-Za-z0-9._-]{1,128}$/));
494
- const objectDownloadSchema = v.object({
495
- url: v.pipe(v.string(), v.url()),
496
- method: v.literal("GET"),
497
- headers: v.record(v.string(), v.string()),
498
- expiresAt: v.string()
499
- });
500
- /** An image a stored revision uses, where to download it, and what to check it against. */
501
- const documentImageDownloadSchema = v.object({
502
- name: imageNameSchema,
503
- checksum: checksumSchema,
504
- byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
505
- download: objectDownloadSchema
506
- });
507
- /** Where to download an image a document uses, found by its checksum. */
508
- const documentImageLinkSchema = v.object({
509
- checksum: checksumSchema,
510
- byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
511
- download: objectDownloadSchema
512
- });
513
- /** The images a live room names, by checksum, that a peer needs links for. */
514
- const requestImageLinksSchema = v.object({ checksums: v.pipe(v.array(checksumSchema), v.minLength(1), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)) });
515
- const documentPermissionSchema = v.picklist(["view", "edit"]);
516
- const documentAccessSourceSchema = v.picklist([
517
- "owner",
518
- "workspace",
519
- "direct-grant"
520
- ]);
521
- const documentAccessSchema = v.object({
522
- permission: documentPermissionSchema,
523
- canManageSharing: v.boolean(),
524
- sources: v.array(documentAccessSourceSchema)
525
- });
526
- /** What a document is: a Figma design or a FigJam board, which the file it stores says too. */
527
- const documentKindSchema = v.picklist(["design", "board"]);
528
- const documentSummarySchema = v.object({
529
- id: v.pipe(v.string(), v.uuid()),
530
- workspaceId: v.pipe(v.string(), v.uuid()),
531
- name: v.string(),
532
- /** A design unless said otherwise; servers from before boards list no kind. */
533
- kind: v.optional(documentKindSchema, "design"),
534
- currentRevisionId: v.nullable(v.pipe(v.string(), v.uuid())),
535
- version: v.number(),
536
- createdAt: v.string(),
537
- updatedAt: v.string()
538
- });
539
- /** A document someone granted the person directly, in a workspace they are not a member of. */
540
- const sharedDocumentSchema = v.object({
541
- ...documentSummarySchema.entries,
542
- workspaceName: v.string(),
543
- permission: documentPermissionSchema,
544
- sharedBy: v.nullable(v.object({ name: v.string() })),
545
- sharedAt: v.string()
546
- });
547
- const documentDownloadSchema = v.object({
548
- document: documentSummarySchema,
549
- revisionId: v.pipe(v.string(), v.uuid()),
550
- byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
551
- checksum: checksumSchema,
552
- contentType: v.string(),
553
- download: objectDownloadSchema,
554
- /** The images the stored file leaves out, which a client puts back under their names. */
555
- images: v.pipe(v.array(documentImageDownloadSchema), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES))
556
- });
557
- const cloudActorSchema = v.object({
558
- userId: v.string(),
559
- email: v.pipe(v.string(), v.email()),
560
- name: v.string()
561
- });
562
- const cloudSessionSchema = v.object({ user: cloudActorSchema });
563
- const workspaceUsageSchema = v.object({
564
- bytesUsed: v.pipe(v.number(), v.integer(), v.minValue(0)),
565
- objectCount: v.pipe(v.number(), v.integer(), v.minValue(0)),
566
- documentCount: v.pipe(v.number(), v.integer(), v.minValue(0))
567
- });
568
- const createDocumentSchema = v.object({
569
- id: v.optional(v.pipe(v.string(), v.uuid())),
570
- name: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(255)),
571
- /** A design unless said otherwise; older clients create only designs. */
572
- kind: v.optional(documentKindSchema, "design")
573
- });
574
- v.object({
575
- baseRevisionId: v.nullable(v.pipe(v.string(), v.uuid())),
576
- byteSize: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(CLOUD_PROTOCOL_MAX_UPLOAD_BYTES)),
577
- checksum: checksumSchema,
578
- contentType: v.literal("application/octet-stream")
579
- });
580
- const imageSizeSchema = v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(CLOUD_PROTOCOL_MAX_UPLOAD_BYTES));
581
- /** Where a client puts an object: one presigned PUT, or the parts of a multipart upload. */
582
- const objectUploadSchema = v.variant("kind", [v.object({
583
- kind: v.literal("single"),
584
- url: v.pipe(v.string(), v.url()),
585
- method: v.literal("PUT"),
586
- headers: v.record(v.string(), v.string()),
587
- expiresAt: v.string()
588
- }), v.object({
589
- kind: v.literal("multipart"),
590
- uploadId: v.string(),
591
- partSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
592
- parts: v.array(v.object({
593
- partNumber: v.pipe(v.number(), v.integer(), v.minValue(1)),
594
- url: v.pipe(v.string(), v.url()),
595
- method: v.literal("PUT"),
596
- headers: v.record(v.string(), v.string())
597
- })),
598
- expiresAt: v.string()
599
- })]);
600
- /** An upload the server offers for an image the workspace lacks. */
601
- const imageUploadOfferSchema = v.object({
602
- checksum: checksumSchema,
603
- uploadId: v.pipe(v.string(), v.uuid()),
604
- upload: objectUploadSchema
805
+ status: v.string(),
806
+ attemptCount: v.pipe(v.number(), v.integer(), v.minValue(0)),
807
+ nextAttemptAt: timestampSchema,
808
+ transport: v.nullable(v.string()),
809
+ transportMessageId: v.nullable(v.string()),
810
+ lastErrorCode: v.nullable(v.string()),
811
+ createdAt: timestampSchema,
812
+ acceptedAt: nullableTimestampSchema,
813
+ regeneratable: v.boolean()
605
814
  });
606
- v.object({ images: v.pipe(v.array(v.object({
607
- checksum: checksumSchema,
608
- byteSize: imageSizeSchema
609
- })), v.minLength(1), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)) });
610
- const completedUploadPartSchema = v.object({
611
- partNumber: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(1e4)),
612
- etag: v.pipe(v.string(), v.minLength(1), v.maxLength(255))
815
+ /** Which messages a list of email shows, by how their delivery went. */
816
+ const cloudAdminEmailFilterSchema = v.picklist([
817
+ "all",
818
+ "sent",
819
+ "waiting",
820
+ "failed"
821
+ ]);
822
+ const adminEmailResponseSchema = v.object({
823
+ messages: v.array(transactionalEmailAdminSchema),
824
+ ...listTotals(cloudAdminEmailFilterSchema.options)
613
825
  });
614
- const commitUploadSchema = v.object({
615
- checksum: checksumSchema,
616
- /** The document title captured with this revision; omitted by older clients. */
617
- name: v.optional(createDocumentSchema.entries.name),
618
- /** What the uploaded file is, which the document takes; omitted by older clients. */
619
- kind: v.optional(documentKindSchema),
620
- multipart: v.optional(v.object({
621
- uploadId: v.pipe(v.string(), v.minLength(1)),
622
- parts: v.pipe(v.array(completedUploadPartSchema), v.minLength(1), v.maxLength(1e4))
623
- })),
624
- /** The images the uploaded file leaves out, each stored in the workspace or uploaded before. */
625
- images: v.optional(v.pipe(v.array(v.object({
626
- name: imageNameSchema,
627
- checksum: checksumSchema
628
- })), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)), [])
826
+ /** Who or what an event names; `name` is null once the server no longer knows it. */
827
+ const auditPartySchema = v.object({
828
+ id: v.string(),
829
+ name: v.nullable(v.string())
629
830
  });
630
- v.object({ uploads: v.pipe(v.array(v.object({
631
- uploadId: v.pipe(v.string(), v.uuid()),
632
- checksum: checksumSchema,
633
- multipart: commitUploadSchema.entries.multipart
634
- })), v.minLength(1), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)) });
635
- //#endregion
636
- //#region src/contract/collaboration.ts
637
- const collaborationPrincipalSchema = v.variant("kind", [v.object({
638
- kind: v.literal("user"),
639
- userId: v.string(),
640
- name: v.string(),
641
- email: v.pipe(v.string(), v.email())
642
- }), v.object({
643
- kind: v.literal("guest"),
644
- guestId: v.string(),
645
- name: v.string()
646
- })]);
647
- v.object({
648
- kind: v.picklist(["user", "guest"]),
831
+ const adminAuditEventSchema = v.object({
832
+ id: v.string(),
833
+ actor: auditPartySchema,
834
+ action: v.string(),
835
+ /** What the event is about: an account, an access request, an email, or a document. */
836
+ subject: v.object({
837
+ ...auditPartySchema.entries,
838
+ type: v.string()
839
+ }),
840
+ metadata: v.unknown(),
841
+ createdAt: timestampSchema
842
+ });
843
+ /** Which events a list of activity shows, by what they are about. */
844
+ const cloudAdminAuditFilterSchema = v.picklist([
845
+ "all",
846
+ "accounts",
847
+ "requests",
848
+ "email",
849
+ "documents"
850
+ ]);
851
+ const adminAuditResponseSchema = v.object({
852
+ events: v.array(adminAuditEventSchema),
853
+ ...listTotals(cloudAdminAuditFilterSchema.options)
854
+ });
855
+ /** A document as the console shows it: where it lives, who made it, and whether it is taken down. */
856
+ const cloudAdminDocumentSchema = v.object({
649
857
  id: v.string(),
650
858
  name: v.string(),
651
- permission: documentPermissionSchema
859
+ workspace: v.object({
860
+ id: v.string(),
861
+ name: v.string()
862
+ }),
863
+ /** Who made it, while the server knows them. */
864
+ owner: v.nullable(v.object({
865
+ id: v.string(),
866
+ name: v.string(),
867
+ email: v.string()
868
+ })),
869
+ createdAt: timestampSchema,
870
+ updatedAt: timestampSchema,
871
+ disabledAt: nullableTimestampSchema,
872
+ disabledReason: v.nullable(v.string()),
873
+ /** Reports about it still waiting for a decision. */
874
+ openReports: countSchema,
875
+ /**
876
+ * When someone deleted it forever, and when cleanup destroys it; until then an administrator
877
+ * can still restore it. Servers from before Trash send neither.
878
+ */
879
+ purgedAt: v.optional(nullableTimestampSchema, null),
880
+ destroyedAt: v.optional(nullableTimestampSchema, null)
881
+ });
882
+ /** Which documents a list shows: live ones, or those deleted forever an administrator can restore. */
883
+ const cloudAdminDocumentFilterSchema = v.picklist([
884
+ "all",
885
+ "reported",
886
+ "disabled",
887
+ "purged"
888
+ ]);
889
+ const cloudAdminDocumentsResponseSchema = v.object({
890
+ documents: v.array(cloudAdminDocumentSchema),
891
+ ...listTotals(cloudAdminDocumentFilterSchema.options)
892
+ });
893
+ const cloudAdminReportStatusSchema = v.picklist([
894
+ "open",
895
+ "dismissed",
896
+ "actioned"
897
+ ]);
898
+ const cloudAdminReportSchema = v.object({
899
+ id: v.string(),
900
+ reason: documentReportReasonSchema,
901
+ description: v.string(),
902
+ status: cloudAdminReportStatusSchema,
903
+ /** The account that filed it, or null for a guest. */
904
+ reporter: v.nullable(v.object({
905
+ id: v.string(),
906
+ name: v.nullable(v.string())
907
+ })),
908
+ replyEmail: v.nullable(v.string()),
909
+ createdAt: timestampSchema,
910
+ resolvedAt: nullableTimestampSchema,
911
+ document: cloudAdminDocumentSchema,
912
+ /** The link it was opened from, and whether that link still works. */
913
+ share: v.nullable(v.object({
914
+ id: v.string(),
915
+ revoked: v.boolean()
916
+ }))
652
917
  });
653
- const collaborationTicketSchema = v.object({
654
- token: v.string(),
655
- provider: v.optional(v.picklist(["trystero", "relay"])),
656
- serverURL: v.optional(v.pipe(v.string(), v.url())),
657
- documentId: v.pipe(v.string(), v.uuid()),
658
- roomId: v.string(),
659
- roomKey: v.pipe(v.string(), v.minLength(43), v.maxLength(128)),
660
- principal: collaborationPrincipalSchema,
661
- permission: documentPermissionSchema,
662
- roomEpoch: v.pipe(v.number(), v.integer(), v.minValue(0)),
663
- expiresAt: v.string(),
664
- serverEnforcedWrites: v.boolean()
918
+ /** Which reports a list shows, by where they stand. */
919
+ const cloudAdminReportFilterSchema = v.picklist([
920
+ "open",
921
+ "actioned",
922
+ "dismissed",
923
+ "all"
924
+ ]);
925
+ const cloudAdminReportsResponseSchema = v.object({
926
+ reports: v.array(cloudAdminReportSchema),
927
+ ...listTotals(cloudAdminReportFilterSchema.options)
928
+ });
929
+ const adminOperationsResponseSchema = v.object({
930
+ deployment: v.picklist(["official", "self-hosted"]),
931
+ enrollmentMode: v.picklist([
932
+ "open",
933
+ "approval",
934
+ "closed"
935
+ ]),
936
+ emailTransport: v.picklist([
937
+ "none",
938
+ "smtp",
939
+ "cloudflare"
940
+ ]),
941
+ pendingEnrollment: v.pipe(v.number(), v.integer(), v.minValue(0)),
942
+ openReports: countSchema,
943
+ pendingEmail: v.pipe(v.number(), v.integer(), v.minValue(0)),
944
+ failedEmail: v.pipe(v.number(), v.integer(), v.minValue(0)),
945
+ accounts: countSchema,
946
+ workspaces: countSchema,
947
+ documents: countSchema,
948
+ storedBytes: countSchema
665
949
  });
666
950
  //#endregion
667
951
  //#region src/contract/entitlements.ts
@@ -673,7 +957,7 @@ const workspaceEntitlementsSchema = v.object({
673
957
  guestPresence: v.boolean(),
674
958
  collaboration: v.boolean(),
675
959
  revisionHistory: v.boolean(),
676
- cloudAI: v.optional(v.boolean(), false)
960
+ cloudServices: v.optional(v.boolean(), false)
677
961
  }),
678
962
  limits: v.object({
679
963
  maximumFileBytes: v.pipe(v.number(), v.integer(), v.minValue(1)),
@@ -725,6 +1009,20 @@ const cloudEditorVersionSchema = v.pipe(v.string(), v.regex(/^\d+\.\d+\.\d+$/));
725
1009
  * and an editor older than the minimum keeps them hidden.
726
1010
  */
727
1011
  const cloudListingSchema = v.object({ minimumEditorVersion: cloudEditorVersionSchema });
1012
+ const legalURLSchema = v.pipe(v.string(), v.url());
1013
+ /**
1014
+ * The operator's legal links, which clients show at sign-up and in account pages. A server that
1015
+ * names none shows none; `requireAcceptance` means an account accepts `termsVersion` before it uses
1016
+ * the server.
1017
+ */
1018
+ const cloudLegalDiscoverySchema = v.object({
1019
+ termsURL: v.optional(legalURLSchema),
1020
+ privacyURL: v.optional(legalURLSchema),
1021
+ termsVersion: v.optional(v.string()),
1022
+ requireAcceptance: v.boolean(),
1023
+ abuseEmail: v.optional(v.pipe(v.string(), v.email())),
1024
+ minimumAge: v.optional(v.pipe(v.number(), v.integer()))
1025
+ });
728
1026
  const cloudDiscoverySchema = v.object({
729
1027
  protocolVersion: v.literal("1"),
730
1028
  deployment: cloudDeploymentSchema,
@@ -735,117 +1033,16 @@ const cloudDiscoverySchema = v.object({
735
1033
  authentication: cloudAuthenticationSchema,
736
1034
  capabilities: cloudCapabilitiesSchema,
737
1035
  listing: v.optional(cloudListingSchema),
738
- /** The AI service editors reach with Cloud-signed tokens; absent when the deployment has none. */
739
- ai: v.optional(cloudAIDiscoverySchema),
1036
+ /** The services editors reach with Cloud-signed tokens; absent when the deployment has none. */
1037
+ services: v.optional(cloudServicesDiscoverySchema),
740
1038
  /** Where people manage their plan and buy credits; absent when the deployment does not bill. */
741
- billing: v.optional(cloudBillingDiscoverySchema)
1039
+ billing: v.optional(cloudBillingDiscoverySchema),
1040
+ legal: v.optional(cloudLegalDiscoverySchema)
742
1041
  });
743
1042
  /** The server's own address, where its editor and pages are, from its auth API's. */
744
1043
  function cloudServerOrigin(discovery) {
745
1044
  return new URL(discovery.authURL).origin;
746
1045
  }
747
- //#endregion
748
- //#region src/contract/sharing.ts
749
- const documentShareSchema = v.object({
750
- id: v.pipe(v.string(), v.uuid()),
751
- documentId: v.pipe(v.string(), v.uuid()),
752
- permission: documentPermissionSchema,
753
- roomEpoch: v.pipe(v.number(), v.integer(), v.minValue(0)),
754
- createdBy: v.string(),
755
- createdAt: v.string(),
756
- updatedAt: v.string(),
757
- expiresAt: v.nullable(v.string()),
758
- revokedAt: v.nullable(v.string()),
759
- lastUsedAt: v.nullable(v.string())
760
- });
761
- /** When a link stops working, as an ISO timestamp; `null` keeps it working until revoked. */
762
- const shareExpirySchema = v.optional(v.nullable(v.pipe(v.string(), v.isoTimestamp())));
763
- v.object({
764
- permission: documentPermissionSchema,
765
- expiresAt: shareExpirySchema
766
- });
767
- v.object({
768
- permission: v.optional(documentPermissionSchema),
769
- expiresAt: shareExpirySchema
770
- });
771
- const resolveDocumentShareSchema = v.object({
772
- secret: v.pipe(v.string(), v.minLength(32), v.maxLength(128)),
773
- guestName: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(80))),
774
- guestId: v.optional(v.pipe(v.string(), v.minLength(16), v.maxLength(128)))
775
- });
776
- v.object({
777
- ...resolveDocumentShareSchema.entries,
778
- ...requestImageLinksSchema.entries
779
- });
780
- const resolvedDocumentShareSchema = v.object({
781
- documentId: v.pipe(v.string(), v.uuid()),
782
- permission: documentPermissionSchema,
783
- principal: collaborationPrincipalSchema,
784
- roomEpoch: v.pipe(v.number(), v.integer(), v.minValue(0))
785
- });
786
- const cloudUserProfileSchema = v.object({
787
- id: v.string(),
788
- name: v.string(),
789
- email: v.pipe(v.string(), v.email()),
790
- image: v.nullable(v.pipe(v.string(), v.url()))
791
- });
792
- const documentGrantSchema = v.object({
793
- id: v.pipe(v.string(), v.uuid()),
794
- documentId: v.pipe(v.string(), v.uuid()),
795
- userId: v.string(),
796
- permission: documentPermissionSchema,
797
- createdBy: v.string(),
798
- createdAt: v.string(),
799
- updatedAt: v.string()
800
- });
801
- /** What accepting an invitation gave: access to a document, or a place in a workspace. */
802
- const acceptedInvitationSchema = v.variant("kind", [v.object({
803
- kind: v.literal("document"),
804
- grant: documentGrantSchema
805
- }), v.object({
806
- kind: v.literal("workspace"),
807
- workspaceId: v.pipe(v.string(), v.uuid()),
808
- role: workspaceRoleSchema
809
- })]);
810
- v.object({ email: v.pipe(v.string(), v.trim(), v.toLowerCase(), v.email()) });
811
- v.object({ permission: documentPermissionSchema });
812
- v.object({
813
- email: v.pipe(v.string(), v.trim(), v.toLowerCase(), v.email()),
814
- permission: documentPermissionSchema
815
- });
816
- v.object({ token: v.pipe(v.string(), v.minLength(32), v.maxLength(128)) });
817
- const createInvitationContinuationSchema = v.object({
818
- invitationId: v.pipe(v.string(), v.uuid()),
819
- token: v.pipe(v.string(), v.minLength(32), v.maxLength(128))
820
- });
821
- const invitationContinuationSchema = v.object({ id: v.pipe(v.string(), v.minLength(16), v.maxLength(128)) });
822
- const invitationPreviewFields = {
823
- inviterName: v.string(),
824
- expiresAt: v.string(),
825
- recipientHint: v.string()
826
- };
827
- /** What an invitation link opens: one document, or a whole workspace. */
828
- const invitationPreviewSchema = v.variant("kind", [v.object({
829
- kind: v.literal("document"),
830
- documentName: v.string(),
831
- permission: documentPermissionSchema,
832
- ...invitationPreviewFields
833
- }), v.object({
834
- kind: v.literal("workspace"),
835
- workspaceName: v.string(),
836
- role: workspaceRoleSchema,
837
- ...invitationPreviewFields
838
- })]);
839
- const documentInvitationSchema = v.object({
840
- id: v.pipe(v.string(), v.uuid()),
841
- documentId: v.pipe(v.string(), v.uuid()),
842
- email: v.pipe(v.string(), v.email()),
843
- permission: documentPermissionSchema,
844
- invitedBy: v.string(),
845
- invitedAt: v.string(),
846
- expiresAt: v.string(),
847
- acceptedAt: v.nullable(v.string())
848
- });
849
1046
  const DOCUMENT_VERSION_DESCRIPTION_MAX_LENGTH = 1e3;
850
1047
  /** A checkpoint the server kept on its own, or a version someone named. */
851
1048
  const documentVersionKindSchema = v.picklist(["checkpoint", "named"]);
@@ -893,13 +1090,13 @@ const restoredDocumentSchema = v.object({
893
1090
  version: documentVersionSchema
894
1091
  });
895
1092
  //#endregion
896
- //#region src/client/ai.ts
897
- var CloudAIError = class extends Error {
1093
+ //#region src/client/services.ts
1094
+ var CloudServiceError = class extends Error {
898
1095
  status;
899
1096
  code;
900
- name = "CloudAIError";
1097
+ name = "CloudServiceError";
901
1098
  constructor(status, code) {
902
- super(`OpenPencil AI request failed with HTTP ${status}`);
1099
+ super(`OpenPencil services request failed with HTTP ${status}`);
903
1100
  this.status = status;
904
1101
  this.code = code;
905
1102
  }
@@ -914,7 +1111,7 @@ function replayable(input, body) {
914
1111
  * by a key Cloud has since replaced, is dropped and a request that can be replayed is sent once
915
1112
  * more with a new one.
916
1113
  */
917
- function cloudAIFetch(tokens, fetch) {
1114
+ function cloudServicesFetch(tokens, fetch) {
918
1115
  const send = async (input, init, token) => {
919
1116
  const headers = new Headers(init?.headers);
920
1117
  headers.set("Authorization", `Bearer ${token}`);
@@ -932,28 +1129,33 @@ function cloudAIFetch(tokens, fetch) {
932
1129
  return send(input, init, await tokens.token());
933
1130
  };
934
1131
  }
935
- const errorBodySchema = v.pipe(v.string(), v.parseJson(), aiErrorSchema);
1132
+ const errorBodySchema = v.pipe(v.string(), v.parseJson(), serviceErrorSchema);
936
1133
  async function parsed(response, schema) {
937
1134
  const text = await response.text();
938
1135
  if (!response.ok) {
939
1136
  const error = v.safeParse(errorBodySchema, text);
940
- throw new CloudAIError(response.status, error.success ? error.output.error.code : void 0);
1137
+ throw new CloudServiceError(response.status, error.success ? error.output.error.code : void 0);
941
1138
  }
942
1139
  return v.parse(v.pipe(v.string(), v.parseJson(), schema), text);
943
1140
  }
944
- /** The AI service a Cloud advertises: its model API base URL, catalog, and the wallet. */
945
- function createCloudAIClient(options) {
1141
+ /** The services a Cloud advertises: the model API base URL, catalog, wallet, and search. */
1142
+ function createCloudServicesClient(options) {
946
1143
  const endpoint = options.endpoint.replace(/\/+$/, "");
947
- const fetch = cloudAIFetch(options.tokens, options.fetch);
1144
+ const fetch = cloudServicesFetch(options.tokens, options.fetch);
1145
+ const { v1 } = hc(endpoint, { fetch });
948
1146
  return {
949
1147
  /** The base URL an OpenAI-compatible client sends chat completions below. */
950
- modelBaseURL: `${endpoint}${CLOUD_AI_API_PATHS.base}`,
1148
+ modelBaseURL: `${endpoint}${CLOUD_SERVICES_API_PATHS.base}`,
951
1149
  fetch,
952
1150
  async catalog() {
953
- return parsed(await fetch(`${endpoint}${CLOUD_AI_API_PATHS.catalog}`), aiCatalogSchema);
1151
+ return parsed(await v1.catalog.$get(), serviceCatalogSchema);
954
1152
  },
955
1153
  async wallet() {
956
- return parsed(await fetch(`${endpoint}${CLOUD_AI_API_PATHS.wallet}`), aiWalletSchema);
1154
+ return parsed(await v1.wallet.$get(), creditWalletSchema);
1155
+ },
1156
+ /** A web search, charged to the workspace; only when the catalog lists `search`. */
1157
+ async search(input) {
1158
+ return parsed(await v1.search.$post({ json: input }), searchResponseSchema);
957
1159
  }
958
1160
  };
959
1161
  }
@@ -966,13 +1168,13 @@ function cloudEditorReturnURL(discovery, value) {
966
1168
  return withoutFragment(destination.href);
967
1169
  }
968
1170
  /**
969
- * The server's sign-in page, coming back to `returnURL` on its editor afterwards. A `provider`
970
- * starts that provider's sign-in at once, while the server's pages still handle two-step sign-in
971
- * and approval before the return.
1171
+ * The server's sign-in page, or with `page` its sign-up page, coming back to `returnURL` on its
1172
+ * editor afterwards. A `provider` starts that provider's sign-in at once, while the server's pages
1173
+ * still handle two-step sign-in and approval before the return.
972
1174
  */
973
- function cloudSignInURL(discovery, returnURL, provider) {
1175
+ function cloudSignInURL(discovery, returnURL, provider, page = "sign-in") {
974
1176
  const offered = provider && discovery.authentication.socialProviders.includes(provider);
975
- return withQuery(new URL("/auth/sign-in", discovery.authURL).href, {
1177
+ return withQuery(new URL(`/auth/${page}`, discovery.authURL).href, {
976
1178
  redirect: withQuery("/auth/return", { editor: cloudEditorReturnURL(discovery, returnURL) }),
977
1179
  provider: offered ? provider : void 0
978
1180
  });
@@ -1192,15 +1394,9 @@ function createCloudAPIClient(baseURL, options = {}) {
1192
1394
  if (response.status === 401) return null;
1193
1395
  return v.parse(cloudSessionSchema, await responseBody(response, options.onDiagnostic));
1194
1396
  },
1195
- /** A short-lived token for the deployment's AI service, on the workspace's behalf. */
1196
- async requestAIToken(workspaceId) {
1197
- return parseResponse(client.ai.token.$post({ json: { workspaceId } }), aiTokenSchema, options.onDiagnostic);
1198
- },
1199
- async lookupUser(documentId, input) {
1200
- return (await parseResponse(client.documents[":documentId"].users.lookup.$post({
1201
- param: { documentId },
1202
- json: input
1203
- }), userLookupResponseSchema, options.onDiagnostic)).user;
1397
+ /** A short-lived token for the deployment's services, on the workspace's behalf. */
1398
+ async requestServicesToken(workspaceId) {
1399
+ return parseResponse(client.services.token.$post({ json: { workspaceId } }), servicesTokenSchema, options.onDiagnostic);
1204
1400
  },
1205
1401
  async getUserProfile(documentId, userId) {
1206
1402
  return (await parseResponse(client.documents[":documentId"].users[":userId"].$get({ param: {
@@ -1226,6 +1422,17 @@ function createCloudAPIClient(baseURL, options = {}) {
1226
1422
  }
1227
1423
  }), documentResponseSchema, options.onDiagnostic)).document;
1228
1424
  },
1425
+ /** Documents in Trash the person may restore, across their workspaces, newest first. */
1426
+ async listTrash() {
1427
+ return (await parseResponse(client.trash.$get(), trashSchema, options.onDiagnostic)).documents;
1428
+ },
1429
+ async restoreDocument(documentId) {
1430
+ await responseBody(await client.trash[":documentId"].restore.$post({ param: { documentId } }), options.onDiagnostic);
1431
+ },
1432
+ /** Deletes a document in Trash for good. */
1433
+ async purgeDocument(documentId) {
1434
+ await responseBody(await client.trash[":documentId"].$delete({ param: { documentId } }), options.onDiagnostic);
1435
+ },
1229
1436
  async deleteDocument(documentId) {
1230
1437
  await responseBody(await client.documents[":documentId"].$delete({ param: { documentId } }), options.onDiagnostic);
1231
1438
  },
@@ -1317,6 +1524,13 @@ function createCloudAPIClient(baseURL, options = {}) {
1317
1524
  invitationId
1318
1525
  } }), options.onDiagnostic);
1319
1526
  },
1527
+ /** Reports the document a share link opens to the server's administrators. */
1528
+ async fileDocumentReport(shareId, input) {
1529
+ await parseResponse(publicClient.shares[":shareId"].reports.$post({
1530
+ param: { shareId },
1531
+ json: input
1532
+ }), fileDocumentReportResponseSchema, options.onDiagnostic);
1533
+ },
1320
1534
  async resolveDocumentShare(shareId, input) {
1321
1535
  return (await parseResponse(publicClient.shares[":shareId"].resolve.$post({
1322
1536
  param: { shareId },
@@ -1701,6 +1915,10 @@ function createAccountAPI(call, { account }) {
1701
1915
  accountStatus(signal) {
1702
1916
  return call((options) => account.status.$get(void 0, options), cloudAccountStatusResponseSchema, signal);
1703
1917
  },
1918
+ /** Accepts the server's terms at `version`, the one its discovery names. */
1919
+ acceptTerms(version, signal) {
1920
+ return call((options) => account.terms.$post({ json: { version } }, options), cloudAccountMutationResponseSchema, signal);
1921
+ },
1704
1922
  authenticationMethods(signal) {
1705
1923
  return call((options) => account.authentication.$get(void 0, options), cloudAuthenticationMethodsResponseSchema, signal);
1706
1924
  },
@@ -1772,6 +1990,14 @@ function createAccountAPI(call, { account }) {
1772
1990
  signIns(signal) {
1773
1991
  return call((options) => account["sign-ins"].$get(void 0, options), cloudSignInsResponseSchema, signal);
1774
1992
  },
1993
+ /** What deleting the account takes, and the workspaces that stop it. */
1994
+ accountDeletion(signal) {
1995
+ return call((options) => account.deletion.$get(void 0, options), cloudAccountDeletionResponseSchema, signal);
1996
+ },
1997
+ /** Deletes the account; a session that signed in a while ago gives its password. */
1998
+ deleteAccount(password, signal) {
1999
+ return call((options) => account.delete.$post({ json: { password } }, options), cloudAccountMutationResponseSchema, signal);
2000
+ },
1775
2001
  unlinkAuthenticationMethod(methodId, signal) {
1776
2002
  return call((options) => account.authentication.unlink.$post({ json: { methodId } }, options), cloudAccountMutationResponseSchema, signal);
1777
2003
  }
@@ -1829,6 +2055,29 @@ function createAdministrationAPI(call, { admin, api }) {
1829
2055
  audit(request, signal) {
1830
2056
  return call((options) => admin.audit.$get(listQuery(request), options), adminAuditResponseSchema, signal);
1831
2057
  },
2058
+ reports(request, signal) {
2059
+ return call((options) => admin.reports.$get(listQuery(request), options), cloudAdminReportsResponseSchema, signal);
2060
+ },
2061
+ /** Closes a report: dismissed, or acted on outside a takedown. */
2062
+ resolveReport(id, action, signal) {
2063
+ return call((options) => admin.reports[":id"][action].$post({ param: { id } }, options), adminMutationResponseSchema, signal);
2064
+ },
2065
+ documents(request, signal) {
2066
+ return call((options) => admin.documents.$get(listQuery(request), options), cloudAdminDocumentsResponseSchema, signal);
2067
+ },
2068
+ /** Takes a document down, or puts it back. */
2069
+ documentAction(id, action, reason, signal) {
2070
+ return call((options) => {
2071
+ if (action === "disable") return admin.documents[":id"].disable.$post({
2072
+ param: { id },
2073
+ json: { reason }
2074
+ }, options);
2075
+ return action === "enable" ? admin.documents[":id"].enable.$post({ param: { id } }, options) : admin.documents[":id"].undelete.$post({ param: { id } }, options);
2076
+ }, adminMutationResponseSchema, signal);
2077
+ },
2078
+ revokeShare(id, signal) {
2079
+ return call((options) => admin.shares[":id"].revoke.$post({ param: { id } }, options), adminMutationResponseSchema, signal);
2080
+ },
1832
2081
  operations(signal) {
1833
2082
  return call((options) => admin.operations.$get(void 0, options), adminOperationsResponseSchema, signal);
1834
2083
  }
@@ -1912,6 +2161,6 @@ function createCloudPortalClient(options = {}) {
1912
2161
  };
1913
2162
  }
1914
2163
  //#endregion
1915
- export { CloudAIError, CloudAPIError, CloudClientError, CloudDeviceAuthorizationError, CloudPortalAPIError, cloudAIFetch, cloudAuthFailure, cloudEditorReturnURL, cloudRedirectPath, cloudSignInURL, createCloudAIClient, createCloudAPIClient, createCloudAuthClient, createCloudPortalClient, discoverCloud, pollCloudDeviceToken, requestCloudDeviceAuthorization, resendCloudVerification, signInToCloud, signInToCloudWithEmail, signOutFromCloud, signUpToCloudWithEmail };
2164
+ export { CloudAPIError, CloudClientError, CloudDeviceAuthorizationError, CloudPortalAPIError, CloudServiceError, cloudAuthFailure, cloudEditorReturnURL, cloudRedirectPath, cloudServicesFetch, cloudSignInURL, createCloudAPIClient, createCloudAuthClient, createCloudPortalClient, createCloudServicesClient, discoverCloud, pollCloudDeviceToken, requestCloudDeviceAuthorization, resendCloudVerification, signInToCloud, signInToCloudWithEmail, signOutFromCloud, signUpToCloudWithEmail };
1916
2165
 
1917
2166
  //# sourceMappingURL=client.js.map