@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/contract2.js CHANGED
@@ -7,11 +7,16 @@ import * as encoding from "lib0/encoding";
7
7
  import * as Y from "yjs";
8
8
  import { encodeParam, parseURL, withFragment, withQuery } from "ufo";
9
9
  //#region src/contract/account.ts
10
+ /**
11
+ * Where an account stands: it may use the server, waits for an administrator, was refused or had
12
+ * its access taken back, or has to accept the server's current terms first.
13
+ */
10
14
  const cloudAccountStateSchema = v.picklist([
11
15
  "active",
12
16
  "pending",
13
17
  "rejected",
14
- "revoked"
18
+ "revoked",
19
+ "terms"
15
20
  ]);
16
21
  const cloudIdentitySchema = v.object({
17
22
  userId: v.string(),
@@ -25,6 +30,8 @@ const cloudAccountStatusResponseSchema = v.object({
25
30
  user: cloudIdentitySchema,
26
31
  state: cloudAccountStateSchema
27
32
  });
33
+ /** Accepting the server's terms: the version the person read, which must be the current one. */
34
+ const cloudTermsAcceptanceSchema = v.object({ version: v.pipe(v.string(), v.minLength(1)) });
28
35
  const cloudAuthenticationProviderSchema = v.picklist([
29
36
  "credential",
30
37
  "google",
@@ -60,7 +67,10 @@ const accountSecurityErrorCodeSchema = v.picklist([
60
67
  "email_unchanged",
61
68
  "email_change_unavailable",
62
69
  "current_session",
63
- "picture_invalid"
70
+ "picture_invalid",
71
+ "account_sole_admin",
72
+ "last_admin_required",
73
+ "terms_changed"
64
74
  ]);
65
75
  const accountSecurityErrorResponseSchema = v.object({ error: v.object({ code: accountSecurityErrorCodeSchema }) });
66
76
  const cloudMFAStatusSchema = v.object({
@@ -88,6 +98,9 @@ const cloudPasskeySchema = v.object({
88
98
  });
89
99
  const cloudPasskeysResponseSchema = v.object({ passkeys: v.array(cloudPasskeySchema) });
90
100
  const cloudPasskeyDeleteSchema = v.object({ id: v.string() });
101
+ function parseCloudTermsAcceptance(input) {
102
+ return v.parse(cloudTermsAcceptanceSchema, input);
103
+ }
91
104
  function parseCloudMFAEnable(input) {
92
105
  return v.parse(cloudMFAEnableSchema, input);
93
106
  }
@@ -173,6 +186,34 @@ const cloudSignInSchema = v.object({
173
186
  createdAt: v.string()
174
187
  });
175
188
  const cloudSignInsResponseSchema = v.object({ signIns: v.array(cloudSignInSchema) });
189
+ /** A workspace an account deletion reads: one it would delete, or one that stops it. */
190
+ const cloudAccountDeletionWorkspaceSchema = v.object({
191
+ id: v.pipe(v.string(), v.uuid()),
192
+ name: v.string()
193
+ });
194
+ /** A document the account would lose, which Download all saves first. */
195
+ const cloudAccountDeletionDocumentSchema = v.object({
196
+ id: v.pipe(v.string(), v.uuid()),
197
+ name: v.string(),
198
+ workspaceName: v.string()
199
+ });
200
+ /**
201
+ * What deleting the account takes: the workspaces only it belongs to, which go with their
202
+ * documents; the ones it leaves to their other members; the ones it alone administers for other
203
+ * members, which stop the deletion until it makes someone else an admin; and the documents it
204
+ * would lose, those workspaces' and the ones it created in workspaces it leaves.
205
+ */
206
+ const cloudAccountDeletionSchema = v.object({
207
+ /** The account is the deployment's only administrator, which also stops the deletion. */
208
+ lastAdministrator: v.boolean(),
209
+ blockedBy: v.array(cloudAccountDeletionWorkspaceSchema),
210
+ deletes: v.array(cloudAccountDeletionWorkspaceSchema),
211
+ leaves: v.array(cloudAccountDeletionWorkspaceSchema),
212
+ documents: v.array(cloudAccountDeletionDocumentSchema)
213
+ });
214
+ const cloudAccountDeletionResponseSchema = v.object({ deletion: cloudAccountDeletionSchema });
215
+ /** The password, for a session that signed in too long ago to delete the account on its own. */
216
+ const cloudAccountDeleteSchema = v.object({ password: v.optional(v.pipe(v.string(), v.minLength(1))) });
176
217
  function parseCloudProfileUpdate(input) {
177
218
  return v.parse(cloudProfileUpdateSchema, input);
178
219
  }
@@ -182,60 +223,71 @@ function parseCloudPictureUpload(input) {
182
223
  function parseCloudEmailChange(input) {
183
224
  return v.parse(cloudEmailChangeSchema, input);
184
225
  }
226
+ function parseCloudAccountDelete(input) {
227
+ return v.parse(cloudAccountDeleteSchema, input);
228
+ }
185
229
  function parseCloudSessionRevoke(input) {
186
230
  return v.parse(cloudSessionRevokeSchema, input);
187
231
  }
188
232
  //#endregion
189
- //#region src/contract/ai.ts
233
+ //#region src/contract/services.ts
190
234
  /**
191
- * The contract between editors, Cloud, and an AI service. Cloud only advertises the service and
192
- * signs short-lived tokens for it; the service, official or self-hosted, proxies models and keeps
193
- * the credit wallet. It is versioned apart from the Cloud protocol so a service can change without
194
- * a Cloud release.
235
+ * The contract between editors, Cloud, and the services Cloud advertises: AI models today, and
236
+ * other paid capabilities such as image generation and search as they arrive. Cloud only
237
+ * advertises the service and signs short-lived tokens for it; the service, official or
238
+ * self-hosted, calls the providers and keeps the credit wallet. It is versioned apart from the
239
+ * Cloud protocol so a service can change without a Cloud release.
195
240
  */
196
- const CLOUD_AI_CONTRACT_VERSION = "1";
197
- /** The `aud` of every token Cloud signs for an AI service. */
198
- const CLOUD_AI_TOKEN_AUDIENCE = "openpencil-ai";
199
- /** Where Cloud publishes the public keys an AI service verifies its tokens with. */
200
- const CLOUD_AI_JWKS_PATH = "/.well-known/jwks.json";
241
+ const CLOUD_SERVICES_CONTRACT_VERSION = "1";
242
+ /** The `aud` of every token Cloud signs for its services. */
243
+ const CLOUD_SERVICES_TOKEN_AUDIENCE = "openpencil-services";
244
+ /** Where Cloud publishes the public keys a service verifies its tokens with. */
245
+ const CLOUD_SERVICES_JWKS_PATH = "/.well-known/jwks.json";
201
246
  /**
202
247
  * Where a service answers, below the discovered `endpoint`. Model requests follow the OpenAI chat
203
248
  * completions API, so an OpenAI-compatible client takes `${endpoint}${base}` as its base URL.
204
249
  */
205
- const CLOUD_AI_API_PATHS = {
250
+ const CLOUD_SERVICES_API_PATHS = {
206
251
  base: "/v1",
207
252
  chatCompletions: "/v1/chat/completions",
208
253
  catalog: "/v1/catalog",
209
254
  wallet: "/v1/wallet",
210
- usage: "/v1/usage"
255
+ usage: "/v1/usage",
256
+ search: "/v1/search"
211
257
  };
212
258
  const urlSchema = v.pipe(v.string(), v.url());
213
259
  const creditsSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
214
- const cloudAIDiscoverySchema = v.object({
260
+ const cloudServicesDiscoverySchema = v.object({
215
261
  endpoint: urlSchema,
216
262
  contractVersion: v.literal("1")
217
263
  });
218
264
  const cloudBillingDiscoverySchema = v.object({ portalURL: urlSchema });
219
- const createAITokenSchema = v.object({ workspaceId: v.pipe(v.string(), v.uuid()) });
220
- function parseCreateAIToken(input) {
221
- return v.parse(createAITokenSchema, input);
265
+ const createServicesTokenSchema = v.object({ workspaceId: v.pipe(v.string(), v.uuid()) });
266
+ function parseCreateServicesToken(input) {
267
+ return v.parse(createServicesTokenSchema, input);
222
268
  }
223
- const aiTokenSchema = v.object({
269
+ const servicesTokenSchema = v.object({
224
270
  token: v.pipe(v.string(), v.minLength(1)),
225
271
  expiresAt: v.pipe(v.string(), v.isoTimestamp())
226
272
  });
227
- /** What an AI service may rely on once a token's signature, issuer, audience, and expiry check. */
228
- const aiTokenClaimsSchema = v.object({
273
+ /** What a service may rely on once a token's signature, issuer, audience, and expiry check. */
274
+ const servicesTokenClaimsSchema = v.object({
229
275
  iss: urlSchema,
230
- aud: v.literal(CLOUD_AI_TOKEN_AUDIENCE),
276
+ aud: v.literal(CLOUD_SERVICES_TOKEN_AUDIENCE),
231
277
  sub: v.pipe(v.string(), v.minLength(1)),
232
278
  workspaceId: v.pipe(v.string(), v.uuid()),
233
- /** Credits the workspace's plan grants each month; `null` when Cloud sets no allowance. */
279
+ /**
280
+ * The account whose credits the request spends: the workspace's owner, whose allowance every
281
+ * workspace they own shares. Absent from tokens a Cloud from before account plans issued, which
282
+ * a relay takes as the workspace's own allowance, as such a Cloud meant.
283
+ */
284
+ accountId: v.optional(v.pipe(v.string(), v.minLength(1))),
285
+ /** Credits the owner's plan grants each month; `null` when Cloud sets no allowance. */
234
286
  monthlyCreditAllowance: v.nullable(creditsSchema),
235
287
  iat: v.pipe(v.number(), v.integer()),
236
288
  exp: v.pipe(v.number(), v.integer())
237
289
  });
238
- const aiModelSchema = v.object({
290
+ const chatModelSchema = v.object({
239
291
  id: v.pipe(v.string(), v.minLength(1)),
240
292
  label: v.pipe(v.string(), v.minLength(1)),
241
293
  /** Credits per million input and output tokens. */
@@ -248,11 +300,14 @@ const aiModelSchema = v.object({
248
300
  tools: v.boolean()
249
301
  })
250
302
  });
251
- const aiCatalogSchema = v.object({
252
- models: v.array(aiModelSchema),
253
- defaultModelID: v.pipe(v.string(), v.minLength(1))
303
+ /** What one web search costs; a service without search leaves it out of its catalog. */
304
+ const searchPricingSchema = v.object({ creditsPerRequest: creditsSchema });
305
+ const serviceCatalogSchema = v.object({
306
+ models: v.array(chatModelSchema),
307
+ defaultModelID: v.pipe(v.string(), v.minLength(1)),
308
+ search: v.optional(searchPricingSchema)
254
309
  });
255
- const aiCreditBucketSchema = v.object({
310
+ const creditBucketSchema = v.object({
256
311
  kind: v.picklist([
257
312
  "allowance",
258
313
  "purchased",
@@ -265,13 +320,13 @@ const aiCreditBucketSchema = v.object({
265
320
  * A service records a request's charge before the request's answer ends, so a wallet read after
266
321
  * an answer includes what it cost.
267
322
  */
268
- const aiWalletSchema = v.object({
323
+ const creditWalletSchema = v.object({
269
324
  /** Credits left to spend; `null` when the service sets no limit. */
270
325
  balance: v.nullable(creditsSchema),
271
326
  /** Spent first to last. */
272
- buckets: v.array(aiCreditBucketSchema)
327
+ buckets: v.array(creditBucketSchema)
273
328
  });
274
- const aiUsageEntrySchema = v.object({
329
+ const usageEntrySchema = v.object({
275
330
  id: v.pipe(v.string(), v.minLength(1)),
276
331
  createdAt: v.pipe(v.string(), v.isoTimestamp()),
277
332
  kind: v.picklist([
@@ -283,34 +338,300 @@ const aiUsageEntrySchema = v.object({
283
338
  userId: v.pipe(v.string(), v.minLength(1)),
284
339
  credits: creditsSchema
285
340
  });
286
- const aiUsageQuerySchema = v.object({ cursor: v.optional(v.pipe(v.string(), v.minLength(1))) });
287
- function parseAIUsageQuery(input) {
288
- return v.parse(aiUsageQuerySchema, input);
341
+ /** The most results one search returns. */
342
+ const MAX_SEARCH_RESULTS = 10;
343
+ /** The longest query a search takes, in characters. */
344
+ const MAX_SEARCH_QUERY_LENGTH = 1e3;
345
+ const searchRequestSchema = v.object({
346
+ query: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(MAX_SEARCH_QUERY_LENGTH)),
347
+ numResults: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(10)), 5)
348
+ });
349
+ function parseSearchRequest(input) {
350
+ return v.parse(searchRequestSchema, input);
351
+ }
352
+ /** One page a search found, with the part of its text that answers the query. */
353
+ const searchResultSchema = v.object({
354
+ url: v.pipe(urlSchema, v.regex(/^https?:\/\//i, "A search result links to an HTTP(S) page")),
355
+ title: v.string(),
356
+ publishedAt: v.nullable(v.pipe(v.string(), v.isoTimestamp())),
357
+ author: v.nullable(v.string()),
358
+ text: v.string()
359
+ });
360
+ const searchResponseSchema = v.object({ results: v.array(searchResultSchema) });
361
+ const usageQuerySchema = v.object({ cursor: v.optional(v.pipe(v.string(), v.minLength(1))) });
362
+ function parseUsageQuery(input) {
363
+ return v.parse(usageQuerySchema, input);
289
364
  }
290
- const aiUsagePageSchema = v.object({
291
- entries: v.array(aiUsageEntrySchema),
365
+ const usagePageSchema = v.object({
366
+ entries: v.array(usageEntrySchema),
292
367
  next: v.nullable(v.string())
293
368
  });
294
- /** Errors an AI service answers with, beside the upstream model's own. */
295
- const aiErrorCodeSchema = v.picklist([
369
+ /** Errors a service answers with, beside the upstream provider's own. */
370
+ const serviceErrorCodeSchema = v.picklist([
371
+ "invalid_request",
296
372
  "unauthorized",
297
373
  "insufficient_credits",
298
374
  "model_not_allowed",
375
+ "capability_unavailable",
299
376
  "rate_limited"
300
377
  ]);
301
- const aiErrorSchema = v.object({ error: v.object({
302
- code: aiErrorCodeSchema,
378
+ const serviceErrorSchema = v.object({ error: v.object({
379
+ code: serviceErrorCodeSchema,
303
380
  message: v.optional(v.string()),
304
381
  /** With `insufficient_credits`: when the workspace's allowance renews, if the service knows. */
305
382
  resetsAt: v.optional(v.pipe(v.string(), v.isoTimestamp()))
306
383
  }) });
307
- const AI_ERROR_STATUS = {
384
+ const SERVICE_ERROR_STATUS = {
385
+ invalid_request: 400,
308
386
  unauthorized: 401,
309
387
  insufficient_credits: 402,
310
388
  model_not_allowed: 403,
389
+ /** A capability, such as search, the service does not offer. */
390
+ capability_unavailable: 404,
311
391
  rate_limited: 429
312
392
  };
313
393
  //#endregion
394
+ //#region src/contract/documents.ts
395
+ const CLOUD_PROTOCOL_MAX_UPLOAD_BYTES = 1073741824;
396
+ const checksumSchema = v.pipe(v.string(), v.regex(/^[A-Za-z0-9+/]{43}=$/));
397
+ /** Whether a value is a SHA-256 checksum as the server names stored objects, base64 encoded. */
398
+ function isCloudChecksum(value) {
399
+ return v.is(checksumSchema, value);
400
+ }
401
+ /** The most images one revision, or one request for image uploads, may name. */
402
+ const CLOUD_MAX_DOCUMENT_IMAGES = 1e4;
403
+ /**
404
+ * The most a Cloud API request body may hold; a server refuses anything past it before reading
405
+ * it. Files go to the object store, never through the API, so only lists grow large: a save's
406
+ * images fit with room to spare, and a client commits image uploads, whose part lists can run
407
+ * long, in batches under half of it.
408
+ */
409
+ const CLOUD_API_MAX_BODY_BYTES = 8388608;
410
+ /**
411
+ * An image's name inside a `.fig` file that Cloud stores apart from it: the SHA-1 Figma names it
412
+ * by, or an older plain name. A client leaves images under other names inside the file.
413
+ */
414
+ const CLOUD_IMAGE_NAME_PATTERN = /^[A-Za-z0-9._-]{1,128}$/;
415
+ const imageNameSchema = v.pipe(v.string(), v.regex(CLOUD_IMAGE_NAME_PATTERN));
416
+ const objectDownloadSchema = v.object({
417
+ url: v.pipe(v.string(), v.url()),
418
+ method: v.literal("GET"),
419
+ headers: v.record(v.string(), v.string()),
420
+ expiresAt: v.string()
421
+ });
422
+ /** An image a stored revision uses, where to download it, and what to check it against. */
423
+ const documentImageDownloadSchema = v.object({
424
+ name: imageNameSchema,
425
+ checksum: checksumSchema,
426
+ byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
427
+ download: objectDownloadSchema
428
+ });
429
+ /** Where to download an image a document uses, found by its checksum. */
430
+ const documentImageLinkSchema = v.object({
431
+ checksum: checksumSchema,
432
+ byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
433
+ download: objectDownloadSchema
434
+ });
435
+ /** The images a live room names, by checksum, that a peer needs links for. */
436
+ const requestImageLinksSchema = v.object({ checksums: v.pipe(v.array(checksumSchema), v.minLength(1), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)) });
437
+ const documentPermissionSchema = v.picklist(["view", "edit"]);
438
+ const documentAccessSourceSchema = v.picklist([
439
+ "owner",
440
+ "workspace",
441
+ "direct-grant"
442
+ ]);
443
+ const documentAccessSchema = v.object({
444
+ permission: documentPermissionSchema,
445
+ canManageSharing: v.boolean(),
446
+ sources: v.array(documentAccessSourceSchema)
447
+ });
448
+ /** What a document is: a Figma design or a FigJam board, which the file it stores says too. */
449
+ const documentKindSchema = v.picklist(["design", "board"]);
450
+ const documentSummarySchema = v.object({
451
+ id: v.pipe(v.string(), v.uuid()),
452
+ workspaceId: v.pipe(v.string(), v.uuid()),
453
+ name: v.string(),
454
+ /** A design unless said otherwise; servers from before boards list no kind. */
455
+ kind: v.optional(documentKindSchema, "design"),
456
+ currentRevisionId: v.nullable(v.pipe(v.string(), v.uuid())),
457
+ version: v.number(),
458
+ createdAt: v.string(),
459
+ updatedAt: v.string()
460
+ });
461
+ /** A document someone granted the person directly, in a workspace they are not a member of. */
462
+ const sharedDocumentSchema = v.object({
463
+ ...documentSummarySchema.entries,
464
+ workspaceName: v.string(),
465
+ permission: documentPermissionSchema,
466
+ sharedBy: v.nullable(v.object({ name: v.string() })),
467
+ sharedAt: v.string()
468
+ });
469
+ /**
470
+ * A document in Trash the person may restore: who deleted it and when, and when it goes for good.
471
+ * `canPurge` says whether they may also delete it for good before then.
472
+ */
473
+ const trashedDocumentSchema = v.object({
474
+ id: v.pipe(v.string(), v.uuid()),
475
+ workspaceId: v.pipe(v.string(), v.uuid()),
476
+ workspaceName: v.string(),
477
+ name: v.string(),
478
+ kind: v.optional(documentKindSchema, "design"),
479
+ deletedAt: v.string(),
480
+ deletedBy: v.nullable(v.object({ name: v.string() })),
481
+ purgeAt: v.string(),
482
+ canPurge: v.boolean()
483
+ });
484
+ const trashSchema = v.object({ documents: v.array(trashedDocumentSchema) });
485
+ const documentDownloadSchema = v.object({
486
+ document: documentSummarySchema,
487
+ revisionId: v.pipe(v.string(), v.uuid()),
488
+ byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
489
+ checksum: checksumSchema,
490
+ contentType: v.string(),
491
+ download: objectDownloadSchema,
492
+ /** The images the stored file leaves out, which a client puts back under their names. */
493
+ images: v.pipe(v.array(documentImageDownloadSchema), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES))
494
+ });
495
+ const cloudActorSchema = v.object({
496
+ userId: v.string(),
497
+ email: v.pipe(v.string(), v.email()),
498
+ name: v.string()
499
+ });
500
+ const cloudSessionSchema = v.object({ user: cloudActorSchema });
501
+ const workspaceUsageSchema = v.object({
502
+ bytesUsed: v.pipe(v.number(), v.integer(), v.minValue(0)),
503
+ objectCount: v.pipe(v.number(), v.integer(), v.minValue(0)),
504
+ documentCount: v.pipe(v.number(), v.integer(), v.minValue(0))
505
+ });
506
+ const CLOUD_DOCUMENT_NAME_MAX_LENGTH = 255;
507
+ const createDocumentSchema = v.object({
508
+ id: v.optional(v.pipe(v.string(), v.uuid())),
509
+ name: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(255)),
510
+ /** A design unless said otherwise; older clients create only designs. */
511
+ kind: v.optional(documentKindSchema, "design")
512
+ });
513
+ const createUploadSchema = v.object({
514
+ baseRevisionId: v.nullable(v.pipe(v.string(), v.uuid())),
515
+ byteSize: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(CLOUD_PROTOCOL_MAX_UPLOAD_BYTES)),
516
+ checksum: checksumSchema,
517
+ contentType: v.literal("application/octet-stream")
518
+ });
519
+ const imageSizeSchema = v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(CLOUD_PROTOCOL_MAX_UPLOAD_BYTES));
520
+ /** Where a client puts an object: one presigned PUT, or the parts of a multipart upload. */
521
+ const objectUploadSchema = v.variant("kind", [v.object({
522
+ kind: v.literal("single"),
523
+ url: v.pipe(v.string(), v.url()),
524
+ method: v.literal("PUT"),
525
+ headers: v.record(v.string(), v.string()),
526
+ expiresAt: v.string()
527
+ }), v.object({
528
+ kind: v.literal("multipart"),
529
+ uploadId: v.string(),
530
+ partSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
531
+ parts: v.array(v.object({
532
+ partNumber: v.pipe(v.number(), v.integer(), v.minValue(1)),
533
+ url: v.pipe(v.string(), v.url()),
534
+ method: v.literal("PUT"),
535
+ headers: v.record(v.string(), v.string())
536
+ })),
537
+ expiresAt: v.string()
538
+ })]);
539
+ /** An upload the server offers for an image the workspace lacks. */
540
+ const imageUploadOfferSchema = v.object({
541
+ checksum: checksumSchema,
542
+ uploadId: v.pipe(v.string(), v.uuid()),
543
+ upload: objectUploadSchema
544
+ });
545
+ /** The images a save will refer to; the server answers with uploads for those it lacks. */
546
+ const requestImageUploadsSchema = v.object({ images: v.pipe(v.array(v.object({
547
+ checksum: checksumSchema,
548
+ byteSize: imageSizeSchema
549
+ })), v.minLength(1), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)) });
550
+ const completedUploadPartSchema = v.object({
551
+ partNumber: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(1e4)),
552
+ etag: v.pipe(v.string(), v.minLength(1), v.maxLength(255))
553
+ });
554
+ const commitUploadSchema = v.object({
555
+ checksum: checksumSchema,
556
+ /** The document title captured with this revision; omitted by older clients. */
557
+ name: v.optional(createDocumentSchema.entries.name),
558
+ /** What the uploaded file is, which the document takes; omitted by older clients. */
559
+ kind: v.optional(documentKindSchema),
560
+ multipart: v.optional(v.object({
561
+ uploadId: v.pipe(v.string(), v.minLength(1)),
562
+ parts: v.pipe(v.array(completedUploadPartSchema), v.minLength(1), v.maxLength(1e4))
563
+ })),
564
+ /** The images the uploaded file leaves out, each stored in the workspace or uploaded before. */
565
+ images: v.optional(v.pipe(v.array(v.object({
566
+ name: imageNameSchema,
567
+ checksum: checksumSchema
568
+ })), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)), [])
569
+ });
570
+ /** The image uploads a save asked for, committed together once their bytes are in place. */
571
+ const commitImageUploadsSchema = v.object({ uploads: v.pipe(v.array(v.object({
572
+ uploadId: v.pipe(v.string(), v.uuid()),
573
+ checksum: checksumSchema,
574
+ multipart: commitUploadSchema.entries.multipart
575
+ })), v.minLength(1), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)) });
576
+ function parseCreateDocument(input) {
577
+ return v.parse(createDocumentSchema, input);
578
+ }
579
+ function parseCreateUpload(input) {
580
+ return v.parse(createUploadSchema, input);
581
+ }
582
+ function parseRequestImageUploads(input) {
583
+ return v.parse(requestImageUploadsSchema, input);
584
+ }
585
+ function parseCommitImageUploads(input) {
586
+ return v.parse(commitImageUploadsSchema, input);
587
+ }
588
+ function parseRequestImageLinks(input) {
589
+ return v.parse(requestImageLinksSchema, input);
590
+ }
591
+ function parseCommitUpload(input) {
592
+ return v.parse(commitUploadSchema, input);
593
+ }
594
+ //#endregion
595
+ //#region src/contract/collaboration.ts
596
+ const collaborationPrincipalSchema = v.variant("kind", [v.object({
597
+ kind: v.literal("user"),
598
+ userId: v.string(),
599
+ name: v.string(),
600
+ email: v.pipe(v.string(), v.email())
601
+ }), v.object({
602
+ kind: v.literal("guest"),
603
+ guestId: v.string(),
604
+ name: v.string()
605
+ })]);
606
+ /**
607
+ * Who the relay verified a peer to be, as it writes into that peer's presence under `cloud`, so
608
+ * other peers can trust it over what the peer says of itself.
609
+ */
610
+ const cloudPresenceSchema = v.object({
611
+ kind: v.picklist(["user", "guest"]),
612
+ id: v.string(),
613
+ name: v.string(),
614
+ permission: documentPermissionSchema
615
+ });
616
+ const collaborationTicketSchema = v.object({
617
+ token: v.string(),
618
+ provider: v.optional(v.picklist(["trystero", "relay"])),
619
+ serverURL: v.optional(v.pipe(v.string(), v.url())),
620
+ documentId: v.pipe(v.string(), v.uuid()),
621
+ roomId: v.string(),
622
+ roomKey: v.pipe(v.string(), v.minLength(43), v.maxLength(128)),
623
+ principal: collaborationPrincipalSchema,
624
+ permission: documentPermissionSchema,
625
+ roomEpoch: v.pipe(v.number(), v.integer(), v.minValue(0)),
626
+ expiresAt: v.string(),
627
+ serverEnforcedWrites: v.boolean(),
628
+ /**
629
+ * Whether the relay answers `RELAY_HEARTBEAT`. A relay from before it takes a ping for a
630
+ * malformed frame and turns the peer away, so editors ask only a relay that says it answers.
631
+ */
632
+ relayHeartbeat: v.optional(v.boolean(), false)
633
+ });
634
+ //#endregion
314
635
  //#region src/contract/workspaces.ts
315
636
  const workspaceRoleSchema = v.picklist([
316
637
  "viewer",
@@ -381,31 +702,191 @@ function parseUpdateWorkspaceMember(input) {
381
702
  return v.parse(updateWorkspaceMemberSchema, input);
382
703
  }
383
704
  //#endregion
384
- //#region src/contract/admin/index.ts
385
- const timestampSchema = v.pipe(v.string(), v.isoTimestamp());
386
- const nullableTimestampSchema = v.nullable(timestampSchema);
387
- const countSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
388
- /**
389
- * What every admin list answers besides its rows: how many rows match the search and filter
390
- * across every page, and how many match the search under each filter.
391
- */
392
- function listTotals(filters) {
393
- return {
394
- total: countSchema,
395
- counts: v.object(zipObject(filters, filters.map(() => countSchema)))
396
- };
397
- }
398
- const adminErrorCodeSchema = v.picklist([
399
- "bad_request",
400
- "unauthorized",
401
- "forbidden",
705
+ //#region src/contract/sharing.ts
706
+ const documentShareSchema = v.object({
707
+ id: v.pipe(v.string(), v.uuid()),
708
+ documentId: v.pipe(v.string(), v.uuid()),
709
+ permission: documentPermissionSchema,
710
+ roomEpoch: v.pipe(v.number(), v.integer(), v.minValue(0)),
711
+ createdBy: v.string(),
712
+ createdAt: v.string(),
713
+ updatedAt: v.string(),
714
+ expiresAt: v.nullable(v.string()),
715
+ revokedAt: v.nullable(v.string()),
716
+ lastUsedAt: v.nullable(v.string())
717
+ });
718
+ /** When a link stops working, as an ISO timestamp; `null` keeps it working until revoked. */
719
+ const shareExpirySchema = v.optional(v.nullable(v.pipe(v.string(), v.isoTimestamp())));
720
+ const createDocumentShareSchema = v.object({
721
+ permission: documentPermissionSchema,
722
+ expiresAt: shareExpirySchema
723
+ });
724
+ const updateDocumentShareSchema = v.object({
725
+ permission: v.optional(documentPermissionSchema),
726
+ expiresAt: shareExpirySchema
727
+ });
728
+ const resolveDocumentShareSchema = v.object({
729
+ secret: v.pipe(v.string(), v.minLength(32), v.maxLength(128)),
730
+ guestName: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(80))),
731
+ guestId: v.optional(v.pipe(v.string(), v.minLength(16), v.maxLength(128)))
732
+ });
733
+ /** A guest's request for the links of images a shared document's live room names. */
734
+ const requestSharedImageLinksSchema = v.object({
735
+ ...resolveDocumentShareSchema.entries,
736
+ ...requestImageLinksSchema.entries
737
+ });
738
+ function parseRequestSharedImageLinks(input) {
739
+ return v.parse(requestSharedImageLinksSchema, input);
740
+ }
741
+ const resolvedDocumentShareSchema = v.object({
742
+ documentId: v.pipe(v.string(), v.uuid()),
743
+ /** What this person may do; a guest on an edit link may only view where guests may not edit. */
744
+ permission: documentPermissionSchema,
745
+ /** What the link lets someone signed in to the server do. */
746
+ linkPermission: documentPermissionSchema,
747
+ principal: collaborationPrincipalSchema,
748
+ roomEpoch: v.pipe(v.number(), v.integer(), v.minValue(0))
749
+ });
750
+ const cloudUserProfileSchema = v.object({
751
+ id: v.string(),
752
+ name: v.string(),
753
+ email: v.pipe(v.string(), v.email()),
754
+ image: v.nullable(v.pipe(v.string(), v.url()))
755
+ });
756
+ const documentGrantSchema = v.object({
757
+ id: v.pipe(v.string(), v.uuid()),
758
+ documentId: v.pipe(v.string(), v.uuid()),
759
+ userId: v.string(),
760
+ permission: documentPermissionSchema,
761
+ createdBy: v.string(),
762
+ createdAt: v.string(),
763
+ updatedAt: v.string()
764
+ });
765
+ /** What accepting an invitation gave: access to a document, or a place in a workspace. */
766
+ const acceptedInvitationSchema = v.variant("kind", [v.object({
767
+ kind: v.literal("document"),
768
+ grant: documentGrantSchema
769
+ }), v.object({
770
+ kind: v.literal("workspace"),
771
+ workspaceId: v.pipe(v.string(), v.uuid()),
772
+ role: workspaceRoleSchema
773
+ })]);
774
+ const putDocumentGrantSchema = v.object({ permission: documentPermissionSchema });
775
+ const createDocumentInvitationSchema = v.object({
776
+ email: v.pipe(v.string(), v.trim(), v.toLowerCase(), v.email()),
777
+ permission: documentPermissionSchema
778
+ });
779
+ const acceptDocumentInvitationSchema = v.object({ token: v.pipe(v.string(), v.minLength(32), v.maxLength(128)) });
780
+ const createInvitationContinuationSchema = v.object({
781
+ invitationId: v.pipe(v.string(), v.uuid()),
782
+ token: v.pipe(v.string(), v.minLength(32), v.maxLength(128))
783
+ });
784
+ const invitationContinuationSchema = v.object({ id: v.pipe(v.string(), v.minLength(16), v.maxLength(128)) });
785
+ const invitationPreviewFields = {
786
+ inviterName: v.string(),
787
+ expiresAt: v.string(),
788
+ recipientHint: v.string()
789
+ };
790
+ /** What an invitation link opens: one document, or a whole workspace. */
791
+ const invitationPreviewSchema = v.variant("kind", [v.object({
792
+ kind: v.literal("document"),
793
+ documentName: v.string(),
794
+ permission: documentPermissionSchema,
795
+ ...invitationPreviewFields
796
+ }), v.object({
797
+ kind: v.literal("workspace"),
798
+ workspaceName: v.string(),
799
+ role: workspaceRoleSchema,
800
+ ...invitationPreviewFields
801
+ })]);
802
+ const documentInvitationSchema = v.object({
803
+ id: v.pipe(v.string(), v.uuid()),
804
+ documentId: v.pipe(v.string(), v.uuid()),
805
+ email: v.pipe(v.string(), v.email()),
806
+ permission: documentPermissionSchema,
807
+ invitedBy: v.string(),
808
+ invitedAt: v.string(),
809
+ expiresAt: v.string(),
810
+ acceptedAt: v.nullable(v.string())
811
+ });
812
+ function parseCreateInvitationContinuation(input) {
813
+ return v.parse(createInvitationContinuationSchema, input);
814
+ }
815
+ function parseCreateDocumentShare(input) {
816
+ return v.parse(createDocumentShareSchema, input);
817
+ }
818
+ function parseUpdateDocumentShare(input) {
819
+ return v.parse(updateDocumentShareSchema, input);
820
+ }
821
+ function parseResolveDocumentShare(input) {
822
+ return v.parse(resolveDocumentShareSchema, input);
823
+ }
824
+ function parsePutDocumentGrant(input) {
825
+ return v.parse(putDocumentGrantSchema, input);
826
+ }
827
+ function parseCreateDocumentInvitation(input) {
828
+ return v.parse(createDocumentInvitationSchema, input);
829
+ }
830
+ function parseAcceptDocumentInvitation(input) {
831
+ return v.parse(acceptDocumentInvitationSchema, input);
832
+ }
833
+ //#endregion
834
+ //#region src/contract/reports.ts
835
+ /** Why someone reports a document shared with them. */
836
+ const documentReportReasonSchema = v.picklist([
837
+ "spam-phishing",
838
+ "illegal",
839
+ "copyright",
840
+ "harassment",
841
+ "other"
842
+ ]);
843
+ /** How long a report's description may be. */
844
+ const DOCUMENT_REPORT_DESCRIPTION_MAX = 2e3;
845
+ /**
846
+ * A report about a document someone opened from a share link: the link's secret proves they can
847
+ * see it, as resolving the link does, and a guest names themselves as they do there.
848
+ */
849
+ const fileDocumentReportSchema = v.object({
850
+ secret: resolveDocumentShareSchema.entries.secret,
851
+ guestId: resolveDocumentShareSchema.entries.guestId,
852
+ reason: documentReportReasonSchema,
853
+ description: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(DOCUMENT_REPORT_DESCRIPTION_MAX)),
854
+ /** Where an administrator may answer; optional, and never shown to the document's people. */
855
+ replyEmail: v.optional(v.pipe(v.string(), v.trim(), v.toLowerCase(), v.email(), v.maxLength(254)))
856
+ });
857
+ function parseFileDocumentReport(input) {
858
+ return v.parse(fileDocumentReportSchema, input);
859
+ }
860
+ /** What filing a report answers: that it arrived, and nothing about the document. */
861
+ const fileDocumentReportResponseSchema = v.object({ received: v.literal(true) });
862
+ //#endregion
863
+ //#region src/contract/admin/index.ts
864
+ const timestampSchema = v.pipe(v.string(), v.isoTimestamp());
865
+ const nullableTimestampSchema = v.nullable(timestampSchema);
866
+ const countSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
867
+ /**
868
+ * What every admin list answers besides its rows: how many rows match the search and filter
869
+ * across every page, and how many match the search under each filter.
870
+ */
871
+ function listTotals(filters) {
872
+ return {
873
+ total: countSchema,
874
+ counts: v.object(zipObject(filters, filters.map(() => countSchema)))
875
+ };
876
+ }
877
+ const adminErrorCodeSchema = v.picklist([
878
+ "bad_request",
879
+ "unauthorized",
880
+ "forbidden",
402
881
  "not_found",
403
882
  "rate_limited",
404
883
  "invalid_enrollment_transition",
405
884
  "last_admin_required",
406
885
  "self_admin_action_forbidden",
407
886
  "email_regeneration_unavailable",
408
- "mfa_required"
887
+ "mfa_required",
888
+ "document_not_restorable",
889
+ "workspace_gone"
409
890
  ]);
410
891
  const adminErrorResponseSchema = v.object({ error: v.object({ code: adminErrorCodeSchema }) });
411
892
  const enrollmentStatusSchema = v.picklist([
@@ -512,259 +993,122 @@ const auditPartySchema = v.object({
512
993
  });
513
994
  const adminAuditEventSchema = v.object({
514
995
  id: v.string(),
515
- actor: auditPartySchema,
516
- action: v.string(),
517
- /** What the event is about: an account, an access request, or an email. */
518
- subject: v.object({
519
- ...auditPartySchema.entries,
520
- type: v.string()
521
- }),
522
- metadata: v.unknown(),
523
- createdAt: timestampSchema
524
- });
525
- /** Which events a list of activity shows, by what they are about. */
526
- const cloudAdminAuditFilterSchema = v.picklist([
527
- "all",
528
- "accounts",
529
- "requests",
530
- "email"
531
- ]);
532
- const adminAuditResponseSchema = v.object({
533
- events: v.array(adminAuditEventSchema),
534
- ...listTotals(cloudAdminAuditFilterSchema.options)
535
- });
536
- const adminOperationsResponseSchema = v.object({
537
- deployment: v.picklist(["official", "self-hosted"]),
538
- enrollmentMode: v.picklist([
539
- "open",
540
- "approval",
541
- "closed"
542
- ]),
543
- emailTransport: v.picklist([
544
- "none",
545
- "smtp",
546
- "cloudflare"
547
- ]),
548
- pendingEnrollment: v.pipe(v.number(), v.integer(), v.minValue(0)),
549
- pendingEmail: v.pipe(v.number(), v.integer(), v.minValue(0)),
550
- failedEmail: v.pipe(v.number(), v.integer(), v.minValue(0)),
551
- accounts: countSchema,
552
- workspaces: countSchema,
553
- documents: countSchema,
554
- storedBytes: countSchema
555
- });
556
- //#endregion
557
- //#region src/contract/documents.ts
558
- const CLOUD_PROTOCOL_MAX_UPLOAD_BYTES = 1073741824;
559
- const checksumSchema = v.pipe(v.string(), v.regex(/^[A-Za-z0-9+/]{43}=$/));
560
- /** Whether a value is a SHA-256 checksum as the server names stored objects, base64 encoded. */
561
- function isCloudChecksum(value) {
562
- return v.is(checksumSchema, value);
563
- }
564
- /** The most images one revision, or one request for image uploads, may name. */
565
- const CLOUD_MAX_DOCUMENT_IMAGES = 1e4;
566
- /**
567
- * An image's name inside a `.fig` file that Cloud stores apart from it: the SHA-1 Figma names it
568
- * by, or an older plain name. A client leaves images under other names inside the file.
569
- */
570
- const CLOUD_IMAGE_NAME_PATTERN = /^[A-Za-z0-9._-]{1,128}$/;
571
- const imageNameSchema = v.pipe(v.string(), v.regex(CLOUD_IMAGE_NAME_PATTERN));
572
- const objectDownloadSchema = v.object({
573
- url: v.pipe(v.string(), v.url()),
574
- method: v.literal("GET"),
575
- headers: v.record(v.string(), v.string()),
576
- expiresAt: v.string()
577
- });
578
- /** An image a stored revision uses, where to download it, and what to check it against. */
579
- const documentImageDownloadSchema = v.object({
580
- name: imageNameSchema,
581
- checksum: checksumSchema,
582
- byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
583
- download: objectDownloadSchema
584
- });
585
- /** Where to download an image a document uses, found by its checksum. */
586
- const documentImageLinkSchema = v.object({
587
- checksum: checksumSchema,
588
- byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
589
- download: objectDownloadSchema
590
- });
591
- /** The images a live room names, by checksum, that a peer needs links for. */
592
- const requestImageLinksSchema = v.object({ checksums: v.pipe(v.array(checksumSchema), v.minLength(1), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)) });
593
- const documentPermissionSchema = v.picklist(["view", "edit"]);
594
- const documentAccessSourceSchema = v.picklist([
595
- "owner",
596
- "workspace",
597
- "direct-grant"
598
- ]);
599
- const documentAccessSchema = v.object({
600
- permission: documentPermissionSchema,
601
- canManageSharing: v.boolean(),
602
- sources: v.array(documentAccessSourceSchema)
603
- });
604
- /** What a document is: a Figma design or a FigJam board, which the file it stores says too. */
605
- const documentKindSchema = v.picklist(["design", "board"]);
606
- const documentSummarySchema = v.object({
607
- id: v.pipe(v.string(), v.uuid()),
608
- workspaceId: v.pipe(v.string(), v.uuid()),
609
- name: v.string(),
610
- /** A design unless said otherwise; servers from before boards list no kind. */
611
- kind: v.optional(documentKindSchema, "design"),
612
- currentRevisionId: v.nullable(v.pipe(v.string(), v.uuid())),
613
- version: v.number(),
614
- createdAt: v.string(),
615
- updatedAt: v.string()
616
- });
617
- /** A document someone granted the person directly, in a workspace they are not a member of. */
618
- const sharedDocumentSchema = v.object({
619
- ...documentSummarySchema.entries,
620
- workspaceName: v.string(),
621
- permission: documentPermissionSchema,
622
- sharedBy: v.nullable(v.object({ name: v.string() })),
623
- sharedAt: v.string()
624
- });
625
- const documentDownloadSchema = v.object({
626
- document: documentSummarySchema,
627
- revisionId: v.pipe(v.string(), v.uuid()),
628
- byteSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
629
- checksum: checksumSchema,
630
- contentType: v.string(),
631
- download: objectDownloadSchema,
632
- /** The images the stored file leaves out, which a client puts back under their names. */
633
- images: v.pipe(v.array(documentImageDownloadSchema), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES))
634
- });
635
- const cloudActorSchema = v.object({
636
- userId: v.string(),
637
- email: v.pipe(v.string(), v.email()),
638
- name: v.string()
639
- });
640
- const cloudSessionSchema = v.object({ user: cloudActorSchema });
641
- const workspaceUsageSchema = v.object({
642
- bytesUsed: v.pipe(v.number(), v.integer(), v.minValue(0)),
643
- objectCount: v.pipe(v.number(), v.integer(), v.minValue(0)),
644
- documentCount: v.pipe(v.number(), v.integer(), v.minValue(0))
645
- });
646
- const CLOUD_DOCUMENT_NAME_MAX_LENGTH = 255;
647
- const createDocumentSchema = v.object({
648
- id: v.optional(v.pipe(v.string(), v.uuid())),
649
- name: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(255)),
650
- /** A design unless said otherwise; older clients create only designs. */
651
- kind: v.optional(documentKindSchema, "design")
652
- });
653
- const createUploadSchema = v.object({
654
- baseRevisionId: v.nullable(v.pipe(v.string(), v.uuid())),
655
- byteSize: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(CLOUD_PROTOCOL_MAX_UPLOAD_BYTES)),
656
- checksum: checksumSchema,
657
- contentType: v.literal("application/octet-stream")
658
- });
659
- const imageSizeSchema = v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(CLOUD_PROTOCOL_MAX_UPLOAD_BYTES));
660
- /** Where a client puts an object: one presigned PUT, or the parts of a multipart upload. */
661
- const objectUploadSchema = v.variant("kind", [v.object({
662
- kind: v.literal("single"),
663
- url: v.pipe(v.string(), v.url()),
664
- method: v.literal("PUT"),
665
- headers: v.record(v.string(), v.string()),
666
- expiresAt: v.string()
667
- }), v.object({
668
- kind: v.literal("multipart"),
669
- uploadId: v.string(),
670
- partSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
671
- parts: v.array(v.object({
672
- partNumber: v.pipe(v.number(), v.integer(), v.minValue(1)),
673
- url: v.pipe(v.string(), v.url()),
674
- method: v.literal("PUT"),
675
- headers: v.record(v.string(), v.string())
676
- })),
677
- expiresAt: v.string()
678
- })]);
679
- /** An upload the server offers for an image the workspace lacks. */
680
- const imageUploadOfferSchema = v.object({
681
- checksum: checksumSchema,
682
- uploadId: v.pipe(v.string(), v.uuid()),
683
- upload: objectUploadSchema
684
- });
685
- /** The images a save will refer to; the server answers with uploads for those it lacks. */
686
- const requestImageUploadsSchema = v.object({ images: v.pipe(v.array(v.object({
687
- checksum: checksumSchema,
688
- byteSize: imageSizeSchema
689
- })), v.minLength(1), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)) });
690
- const completedUploadPartSchema = v.object({
691
- partNumber: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(1e4)),
692
- etag: v.pipe(v.string(), v.minLength(1), v.maxLength(255))
996
+ actor: auditPartySchema,
997
+ action: v.string(),
998
+ /** What the event is about: an account, an access request, an email, or a document. */
999
+ subject: v.object({
1000
+ ...auditPartySchema.entries,
1001
+ type: v.string()
1002
+ }),
1003
+ metadata: v.unknown(),
1004
+ createdAt: timestampSchema
693
1005
  });
694
- const commitUploadSchema = v.object({
695
- checksum: checksumSchema,
696
- /** The document title captured with this revision; omitted by older clients. */
697
- name: v.optional(createDocumentSchema.entries.name),
698
- /** What the uploaded file is, which the document takes; omitted by older clients. */
699
- kind: v.optional(documentKindSchema),
700
- multipart: v.optional(v.object({
701
- uploadId: v.pipe(v.string(), v.minLength(1)),
702
- parts: v.pipe(v.array(completedUploadPartSchema), v.minLength(1), v.maxLength(1e4))
703
- })),
704
- /** The images the uploaded file leaves out, each stored in the workspace or uploaded before. */
705
- images: v.optional(v.pipe(v.array(v.object({
706
- name: imageNameSchema,
707
- checksum: checksumSchema
708
- })), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)), [])
1006
+ /** Which events a list of activity shows, by what they are about. */
1007
+ const cloudAdminAuditFilterSchema = v.picklist([
1008
+ "all",
1009
+ "accounts",
1010
+ "requests",
1011
+ "email",
1012
+ "documents"
1013
+ ]);
1014
+ const adminAuditResponseSchema = v.object({
1015
+ events: v.array(adminAuditEventSchema),
1016
+ ...listTotals(cloudAdminAuditFilterSchema.options)
709
1017
  });
710
- /** The image uploads a save asked for, committed together once their bytes are in place. */
711
- const commitImageUploadsSchema = v.object({ uploads: v.pipe(v.array(v.object({
712
- uploadId: v.pipe(v.string(), v.uuid()),
713
- checksum: checksumSchema,
714
- multipart: commitUploadSchema.entries.multipart
715
- })), v.minLength(1), v.maxLength(CLOUD_MAX_DOCUMENT_IMAGES)) });
716
- function parseCreateDocument(input) {
717
- return v.parse(createDocumentSchema, input);
718
- }
719
- function parseCreateUpload(input) {
720
- return v.parse(createUploadSchema, input);
721
- }
722
- function parseRequestImageUploads(input) {
723
- return v.parse(requestImageUploadsSchema, input);
724
- }
725
- function parseCommitImageUploads(input) {
726
- return v.parse(commitImageUploadsSchema, input);
727
- }
728
- function parseRequestImageLinks(input) {
729
- return v.parse(requestImageLinksSchema, input);
730
- }
731
- function parseCommitUpload(input) {
732
- return v.parse(commitUploadSchema, input);
733
- }
734
- //#endregion
735
- //#region src/contract/collaboration.ts
736
- const collaborationPrincipalSchema = v.variant("kind", [v.object({
737
- kind: v.literal("user"),
738
- userId: v.string(),
739
- name: v.string(),
740
- email: v.pipe(v.string(), v.email())
741
- }), v.object({
742
- kind: v.literal("guest"),
743
- guestId: v.string(),
744
- name: v.string()
745
- })]);
746
- /**
747
- * Who the relay verified a peer to be, as it writes into that peer's presence under `cloud`, so
748
- * other peers can trust it over what the peer says of itself.
749
- */
750
- const cloudPresenceSchema = v.object({
751
- kind: v.picklist(["user", "guest"]),
1018
+ /** A document as the console shows it: where it lives, who made it, and whether it is taken down. */
1019
+ const cloudAdminDocumentSchema = v.object({
752
1020
  id: v.string(),
753
1021
  name: v.string(),
754
- permission: documentPermissionSchema
1022
+ workspace: v.object({
1023
+ id: v.string(),
1024
+ name: v.string()
1025
+ }),
1026
+ /** Who made it, while the server knows them. */
1027
+ owner: v.nullable(v.object({
1028
+ id: v.string(),
1029
+ name: v.string(),
1030
+ email: v.string()
1031
+ })),
1032
+ createdAt: timestampSchema,
1033
+ updatedAt: timestampSchema,
1034
+ disabledAt: nullableTimestampSchema,
1035
+ disabledReason: v.nullable(v.string()),
1036
+ /** Reports about it still waiting for a decision. */
1037
+ openReports: countSchema,
1038
+ /**
1039
+ * When someone deleted it forever, and when cleanup destroys it; until then an administrator
1040
+ * can still restore it. Servers from before Trash send neither.
1041
+ */
1042
+ purgedAt: v.optional(nullableTimestampSchema, null),
1043
+ destroyedAt: v.optional(nullableTimestampSchema, null)
1044
+ });
1045
+ /** Which documents a list shows: live ones, or those deleted forever an administrator can restore. */
1046
+ const cloudAdminDocumentFilterSchema = v.picklist([
1047
+ "all",
1048
+ "reported",
1049
+ "disabled",
1050
+ "purged"
1051
+ ]);
1052
+ const cloudAdminDocumentsResponseSchema = v.object({
1053
+ documents: v.array(cloudAdminDocumentSchema),
1054
+ ...listTotals(cloudAdminDocumentFilterSchema.options)
1055
+ });
1056
+ const cloudAdminReportStatusSchema = v.picklist([
1057
+ "open",
1058
+ "dismissed",
1059
+ "actioned"
1060
+ ]);
1061
+ const cloudAdminReportSchema = v.object({
1062
+ id: v.string(),
1063
+ reason: documentReportReasonSchema,
1064
+ description: v.string(),
1065
+ status: cloudAdminReportStatusSchema,
1066
+ /** The account that filed it, or null for a guest. */
1067
+ reporter: v.nullable(v.object({
1068
+ id: v.string(),
1069
+ name: v.nullable(v.string())
1070
+ })),
1071
+ replyEmail: v.nullable(v.string()),
1072
+ createdAt: timestampSchema,
1073
+ resolvedAt: nullableTimestampSchema,
1074
+ document: cloudAdminDocumentSchema,
1075
+ /** The link it was opened from, and whether that link still works. */
1076
+ share: v.nullable(v.object({
1077
+ id: v.string(),
1078
+ revoked: v.boolean()
1079
+ }))
755
1080
  });
756
- const collaborationTicketSchema = v.object({
757
- token: v.string(),
758
- provider: v.optional(v.picklist(["trystero", "relay"])),
759
- serverURL: v.optional(v.pipe(v.string(), v.url())),
760
- documentId: v.pipe(v.string(), v.uuid()),
761
- roomId: v.string(),
762
- roomKey: v.pipe(v.string(), v.minLength(43), v.maxLength(128)),
763
- principal: collaborationPrincipalSchema,
764
- permission: documentPermissionSchema,
765
- roomEpoch: v.pipe(v.number(), v.integer(), v.minValue(0)),
766
- expiresAt: v.string(),
767
- serverEnforcedWrites: v.boolean()
1081
+ /** Which reports a list shows, by where they stand. */
1082
+ const cloudAdminReportFilterSchema = v.picklist([
1083
+ "open",
1084
+ "actioned",
1085
+ "dismissed",
1086
+ "all"
1087
+ ]);
1088
+ const cloudAdminReportsResponseSchema = v.object({
1089
+ reports: v.array(cloudAdminReportSchema),
1090
+ ...listTotals(cloudAdminReportFilterSchema.options)
1091
+ });
1092
+ const adminOperationsResponseSchema = v.object({
1093
+ deployment: v.picklist(["official", "self-hosted"]),
1094
+ enrollmentMode: v.picklist([
1095
+ "open",
1096
+ "approval",
1097
+ "closed"
1098
+ ]),
1099
+ emailTransport: v.picklist([
1100
+ "none",
1101
+ "smtp",
1102
+ "cloudflare"
1103
+ ]),
1104
+ pendingEnrollment: v.pipe(v.number(), v.integer(), v.minValue(0)),
1105
+ openReports: countSchema,
1106
+ pendingEmail: v.pipe(v.number(), v.integer(), v.minValue(0)),
1107
+ failedEmail: v.pipe(v.number(), v.integer(), v.minValue(0)),
1108
+ accounts: countSchema,
1109
+ workspaces: countSchema,
1110
+ documents: countSchema,
1111
+ storedBytes: countSchema
768
1112
  });
769
1113
  //#endregion
770
1114
  //#region src/contract/relay.ts
@@ -859,6 +1203,14 @@ const RELAY_CLOSE = {
859
1203
  /** The document was restored to a version, so its room started over under a new ID. */
860
1204
  restored: 4410
861
1205
  };
1206
+ /**
1207
+ * The text a peer sends to learn whether the relay still hears it, and the relay's answer. Relay
1208
+ * frames are binary, so neither is taken for one, and a Durable Object answers without waking.
1209
+ */
1210
+ const RELAY_HEARTBEAT = {
1211
+ ping: "ping",
1212
+ pong: "pong"
1213
+ };
862
1214
  const CLIENT_AUTH = 0;
863
1215
  const CLIENT_MESSAGE = 1;
864
1216
  const CLIENT_FRAGMENT = 2;
@@ -1105,7 +1457,7 @@ const workspaceEntitlementsSchema = v.object({
1105
1457
  guestPresence: v.boolean(),
1106
1458
  collaboration: v.boolean(),
1107
1459
  revisionHistory: v.boolean(),
1108
- cloudAI: v.optional(v.boolean(), false)
1460
+ cloudServices: v.optional(v.boolean(), false)
1109
1461
  }),
1110
1462
  limits: v.object({
1111
1463
  maximumFileBytes: v.pipe(v.number(), v.integer(), v.minValue(1)),
@@ -1160,6 +1512,20 @@ const cloudEditorVersionSchema = v.pipe(v.string(), v.regex(/^\d+\.\d+\.\d+$/));
1160
1512
  * and an editor older than the minimum keeps them hidden.
1161
1513
  */
1162
1514
  const cloudListingSchema = v.object({ minimumEditorVersion: cloudEditorVersionSchema });
1515
+ const legalURLSchema = v.pipe(v.string(), v.url());
1516
+ /**
1517
+ * The operator's legal links, which clients show at sign-up and in account pages. A server that
1518
+ * names none shows none; `requireAcceptance` means an account accepts `termsVersion` before it uses
1519
+ * the server.
1520
+ */
1521
+ const cloudLegalDiscoverySchema = v.object({
1522
+ termsURL: v.optional(legalURLSchema),
1523
+ privacyURL: v.optional(legalURLSchema),
1524
+ termsVersion: v.optional(v.string()),
1525
+ requireAcceptance: v.boolean(),
1526
+ abuseEmail: v.optional(v.pipe(v.string(), v.email())),
1527
+ minimumAge: v.optional(v.pipe(v.number(), v.integer()))
1528
+ });
1163
1529
  const cloudDiscoverySchema = v.object({
1164
1530
  protocolVersion: v.literal("1"),
1165
1531
  deployment: cloudDeploymentSchema,
@@ -1170,10 +1536,11 @@ const cloudDiscoverySchema = v.object({
1170
1536
  authentication: cloudAuthenticationSchema,
1171
1537
  capabilities: cloudCapabilitiesSchema,
1172
1538
  listing: v.optional(cloudListingSchema),
1173
- /** The AI service editors reach with Cloud-signed tokens; absent when the deployment has none. */
1174
- ai: v.optional(cloudAIDiscoverySchema),
1539
+ /** The services editors reach with Cloud-signed tokens; absent when the deployment has none. */
1540
+ services: v.optional(cloudServicesDiscoverySchema),
1175
1541
  /** Where people manage their plan and buy credits; absent when the deployment does not bill. */
1176
- billing: v.optional(cloudBillingDiscoverySchema)
1542
+ billing: v.optional(cloudBillingDiscoverySchema),
1543
+ legal: v.optional(cloudLegalDiscoverySchema)
1177
1544
  });
1178
1545
  /** The server's own address, where its editor and pages are, from its auth API's. */
1179
1546
  function cloudServerOrigin(discovery) {
@@ -1183,136 +1550,6 @@ function parseCloudDiscovery(input) {
1183
1550
  return v.parse(cloudDiscoverySchema, input);
1184
1551
  }
1185
1552
  //#endregion
1186
- //#region src/contract/sharing.ts
1187
- const documentShareSchema = v.object({
1188
- id: v.pipe(v.string(), v.uuid()),
1189
- documentId: v.pipe(v.string(), v.uuid()),
1190
- permission: documentPermissionSchema,
1191
- roomEpoch: v.pipe(v.number(), v.integer(), v.minValue(0)),
1192
- createdBy: v.string(),
1193
- createdAt: v.string(),
1194
- updatedAt: v.string(),
1195
- expiresAt: v.nullable(v.string()),
1196
- revokedAt: v.nullable(v.string()),
1197
- lastUsedAt: v.nullable(v.string())
1198
- });
1199
- /** When a link stops working, as an ISO timestamp; `null` keeps it working until revoked. */
1200
- const shareExpirySchema = v.optional(v.nullable(v.pipe(v.string(), v.isoTimestamp())));
1201
- const createDocumentShareSchema = v.object({
1202
- permission: documentPermissionSchema,
1203
- expiresAt: shareExpirySchema
1204
- });
1205
- const updateDocumentShareSchema = v.object({
1206
- permission: v.optional(documentPermissionSchema),
1207
- expiresAt: shareExpirySchema
1208
- });
1209
- const resolveDocumentShareSchema = v.object({
1210
- secret: v.pipe(v.string(), v.minLength(32), v.maxLength(128)),
1211
- guestName: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(80))),
1212
- guestId: v.optional(v.pipe(v.string(), v.minLength(16), v.maxLength(128)))
1213
- });
1214
- /** A guest's request for the links of images a shared document's live room names. */
1215
- const requestSharedImageLinksSchema = v.object({
1216
- ...resolveDocumentShareSchema.entries,
1217
- ...requestImageLinksSchema.entries
1218
- });
1219
- function parseRequestSharedImageLinks(input) {
1220
- return v.parse(requestSharedImageLinksSchema, input);
1221
- }
1222
- const resolvedDocumentShareSchema = v.object({
1223
- documentId: v.pipe(v.string(), v.uuid()),
1224
- permission: documentPermissionSchema,
1225
- principal: collaborationPrincipalSchema,
1226
- roomEpoch: v.pipe(v.number(), v.integer(), v.minValue(0))
1227
- });
1228
- const cloudUserProfileSchema = v.object({
1229
- id: v.string(),
1230
- name: v.string(),
1231
- email: v.pipe(v.string(), v.email()),
1232
- image: v.nullable(v.pipe(v.string(), v.url()))
1233
- });
1234
- const documentGrantSchema = v.object({
1235
- id: v.pipe(v.string(), v.uuid()),
1236
- documentId: v.pipe(v.string(), v.uuid()),
1237
- userId: v.string(),
1238
- permission: documentPermissionSchema,
1239
- createdBy: v.string(),
1240
- createdAt: v.string(),
1241
- updatedAt: v.string()
1242
- });
1243
- /** What accepting an invitation gave: access to a document, or a place in a workspace. */
1244
- const acceptedInvitationSchema = v.variant("kind", [v.object({
1245
- kind: v.literal("document"),
1246
- grant: documentGrantSchema
1247
- }), v.object({
1248
- kind: v.literal("workspace"),
1249
- workspaceId: v.pipe(v.string(), v.uuid()),
1250
- role: workspaceRoleSchema
1251
- })]);
1252
- const lookupCloudUserSchema = v.object({ email: v.pipe(v.string(), v.trim(), v.toLowerCase(), v.email()) });
1253
- const putDocumentGrantSchema = v.object({ permission: documentPermissionSchema });
1254
- const createDocumentInvitationSchema = v.object({
1255
- email: v.pipe(v.string(), v.trim(), v.toLowerCase(), v.email()),
1256
- permission: documentPermissionSchema
1257
- });
1258
- const acceptDocumentInvitationSchema = v.object({ token: v.pipe(v.string(), v.minLength(32), v.maxLength(128)) });
1259
- const createInvitationContinuationSchema = v.object({
1260
- invitationId: v.pipe(v.string(), v.uuid()),
1261
- token: v.pipe(v.string(), v.minLength(32), v.maxLength(128))
1262
- });
1263
- const invitationContinuationSchema = v.object({ id: v.pipe(v.string(), v.minLength(16), v.maxLength(128)) });
1264
- const invitationPreviewFields = {
1265
- inviterName: v.string(),
1266
- expiresAt: v.string(),
1267
- recipientHint: v.string()
1268
- };
1269
- /** What an invitation link opens: one document, or a whole workspace. */
1270
- const invitationPreviewSchema = v.variant("kind", [v.object({
1271
- kind: v.literal("document"),
1272
- documentName: v.string(),
1273
- permission: documentPermissionSchema,
1274
- ...invitationPreviewFields
1275
- }), v.object({
1276
- kind: v.literal("workspace"),
1277
- workspaceName: v.string(),
1278
- role: workspaceRoleSchema,
1279
- ...invitationPreviewFields
1280
- })]);
1281
- const documentInvitationSchema = v.object({
1282
- id: v.pipe(v.string(), v.uuid()),
1283
- documentId: v.pipe(v.string(), v.uuid()),
1284
- email: v.pipe(v.string(), v.email()),
1285
- permission: documentPermissionSchema,
1286
- invitedBy: v.string(),
1287
- invitedAt: v.string(),
1288
- expiresAt: v.string(),
1289
- acceptedAt: v.nullable(v.string())
1290
- });
1291
- function parseCreateInvitationContinuation(input) {
1292
- return v.parse(createInvitationContinuationSchema, input);
1293
- }
1294
- function parseLookupCloudUser(input) {
1295
- return v.parse(lookupCloudUserSchema, input);
1296
- }
1297
- function parseCreateDocumentShare(input) {
1298
- return v.parse(createDocumentShareSchema, input);
1299
- }
1300
- function parseUpdateDocumentShare(input) {
1301
- return v.parse(updateDocumentShareSchema, input);
1302
- }
1303
- function parseResolveDocumentShare(input) {
1304
- return v.parse(resolveDocumentShareSchema, input);
1305
- }
1306
- function parsePutDocumentGrant(input) {
1307
- return v.parse(putDocumentGrantSchema, input);
1308
- }
1309
- function parseCreateDocumentInvitation(input) {
1310
- return v.parse(createDocumentInvitationSchema, input);
1311
- }
1312
- function parseAcceptDocumentInvitation(input) {
1313
- return v.parse(acceptDocumentInvitationSchema, input);
1314
- }
1315
- //#endregion
1316
1553
  //#region src/contract/links.ts
1317
1554
  const CLOUD_LINK_PATH = /^\/(invitations|share|documents)\/([^/]+)$/;
1318
1555
  /**
@@ -1448,6 +1685,6 @@ function parseDuplicateDocumentVersion(input) {
1448
1685
  return v.parse(duplicateDocumentVersionSchema, input);
1449
1686
  }
1450
1687
  //#endregion
1451
- export { AI_ERROR_STATUS, CLOUD_AI_API_PATHS, CLOUD_AI_CONTRACT_VERSION, CLOUD_AI_JWKS_PATH, CLOUD_AI_TOKEN_AUDIENCE, CLOUD_DISCOVERY_PATH, CLOUD_DOCUMENT_NAME_MAX_LENGTH, CLOUD_IMAGE_NAME_PATTERN, CLOUD_MAX_DOCUMENT_IMAGES, CLOUD_PICTURE_MAX_BYTES, CLOUD_PICTURE_SIZE, CLOUD_PORTAL_PAGE_ROOTS, CLOUD_PROTOCOL_MAX_UPLOAD_BYTES, CLOUD_PROTOCOL_VERSION, COLLAB_ACTIONS, DOCUMENT_VERSION_DESCRIPTION_MAX_LENGTH, DOCUMENT_VERSION_NAME_MAX_LENGTH, MAX_COLLAB_MESSAGE_BYTES, MAX_PRESENCE_NAME_LENGTH, RELAY_CLOSE, RELAY_DOCUMENT_PARAM, RELAY_FORWARDING_BYTES, RELAY_FRAGMENT_BYTES, RELAY_MINIMUM_MESSAGE_BYTES, RELAY_PATH, RELAY_SERVER_PEER, acceptDocumentInvitationSchema, acceptedInvitationSchema, accountSecurityErrorCodeSchema, accountSecurityErrorResponseSchema, adminAuditEventSchema, adminAuditResponseSchema, adminEmailResponseSchema, adminErrorCodeSchema, adminErrorResponseSchema, adminMutationResponseSchema, adminOperationsResponseSchema, aiCatalogSchema, aiCreditBucketSchema, aiErrorCodeSchema, aiErrorSchema, aiModelSchema, aiTokenClaimsSchema, aiTokenSchema, aiUsageEntrySchema, aiUsagePageSchema, aiUsageQuerySchema, aiWalletSchema, cloudAIDiscoverySchema, cloudAccountMutationResponseSchema, cloudAccountSessionSchema, cloudAccountSessionsResponseSchema, cloudAccountStateSchema, cloudAccountStatusResponseSchema, cloudActorSchema, cloudAdminAuditFilterSchema, cloudAdminEmailFilterSchema, cloudAdminSessionResponseSchema, cloudAdminUserDetailSchema, cloudAdminUserFilterSchema, cloudAdminUserSchema, cloudAdminUsersResponseSchema, cloudAuthenticationMethodSchema, cloudAuthenticationMethodsResponseSchema, cloudAuthenticationProviderSchema, cloudAuthenticationSchema, cloudBillingDiscoverySchema, cloudCapabilitiesSchema, cloudDeploymentSchema, cloudDesktopLinkURL, cloudDiscoverySchema, cloudDocumentPath, cloudDocumentURL, cloudEditorVersionSchema, cloudEmailChangeSchema, cloudIdentitySchema, cloudInvitationURL, cloudListingSchema, cloudMFAEnableResponseSchema, cloudMFAEnableSchema, cloudMFARecoveryCodesResponseSchema, cloudMFAStatusResponseSchema, cloudMFAStatusSchema, cloudMFAVerifyResponseSchema, cloudMFAVerifySchema, cloudPasskeyDeleteSchema, cloudPasskeySchema, cloudPasskeysResponseSchema, cloudPasswordChangeSchema, cloudPersonSchema, cloudPictureResponseSchema, cloudPictureUploadSchema, cloudPresenceSchema, cloudProfileResponseSchema, cloudProfileSchema, cloudProfileUpdateSchema, cloudServerOrigin, cloudSessionRevokeSchema, cloudSessionSchema, cloudShareURL, cloudSignInMethodSchema, cloudSignInSchema, cloudSignInsResponseSchema, cloudSocialLinkResponseSchema, cloudSocialLinkSchema, cloudUnlinkAuthenticationMethodSchema, cloudUserProfileSchema, collaborationPrincipalSchema, collaborationTicketSchema, commitImageUploadsSchema, commitUploadSchema, createAITokenSchema, createDocumentInvitationSchema, createDocumentSchema, createDocumentShareSchema, createInvitationContinuationSchema, createRelayClientAssembler, createRelayServerAssembler, createUploadSchema, createWorkspaceInvitationSchema, createWorkspaceSchema, createdWorkspaceInvitationSchema, decodeRelayClientFrame, decodeRelayServerFrame, decodeRoomUpdate, defaultRelayURL, documentAccessSchema, documentAccessSourceSchema, documentDownloadSchema, documentGrantSchema, documentImageDownloadSchema, documentImageLinkSchema, documentInvitationSchema, documentPermissionSchema, documentShareSchema, documentSummarySchema, documentVersionDownloadSchema, documentVersionKindSchema, documentVersionResponseSchema, documentVersionSchema, documentVersionsSchema, duplicateDocumentVersionSchema, encodeRelayClientFrame, encodeRelayServerFrame, encodeSyncReply, enrollmentReviewResponseSchema, enrollmentSchema, enrollmentStatusSchema, enrollmentsResponseSchema, imageUploadOfferSchema, invitationContinuationSchema, invitationPreviewSchema, isCloudChecksum, isCloudPortalPage, lookupCloudUserSchema, objectUploadSchema, parseAIUsageQuery, parseAcceptDocumentInvitation, parseCloudDiscovery, parseCloudEmailChange, parseCloudLinkPath, parseCloudMFAEnable, parseCloudMFAVerify, parseCloudPasskeyDelete, parseCloudPasswordChange, parseCloudPictureUpload, parseCloudProfileUpdate, parseCloudSessionRevoke, parseCloudSocialLink, parseCloudUnlinkAuthenticationMethod, parseCommitImageUploads, parseCommitUpload, parseCreateAIToken, parseCreateDocument, parseCreateDocumentInvitation, parseCreateDocumentShare, parseCreateInvitationContinuation, parseCreateUpload, parseCreateWorkspace, parseCreateWorkspaceInvitation, parseDuplicateDocumentVersion, parseLookupCloudUser, parsePutDocumentGrant, parseRequestImageLinks, parseRequestImageUploads, parseRequestSharedImageLinks, parseResolveDocumentShare, parseSaveDocumentVersion, parseUpdateDocumentShare, parseUpdateDocumentVersion, parseUpdateWorkspace, parseUpdateWorkspaceMember, presenceName, putDocumentGrantSchema, relayClientMessages, relayServerMessages, requestImageLinksSchema, requestImageUploadsSchema, requestSharedImageLinksSchema, resolveDocumentShareSchema, resolvedDocumentShareSchema, restoredDocumentSchema, saveDocumentVersionSchema, sharedDocumentSchema, transactionalEmailAdminSchema, updateDocumentShareSchema, updateDocumentVersionSchema, updateWorkspaceMemberSchema, updateWorkspaceSchema, workspaceEntitlementsSchema, workspaceInvitationSchema, workspaceListSchema, workspaceMemberSchema, workspaceMembersSchema, workspaceRoleSchema, workspaceSummarySchema, workspaceUsageSchema };
1688
+ export { CLOUD_API_MAX_BODY_BYTES, CLOUD_DISCOVERY_PATH, CLOUD_DOCUMENT_NAME_MAX_LENGTH, CLOUD_IMAGE_NAME_PATTERN, CLOUD_MAX_DOCUMENT_IMAGES, CLOUD_PICTURE_MAX_BYTES, CLOUD_PICTURE_SIZE, CLOUD_PORTAL_PAGE_ROOTS, CLOUD_PROTOCOL_MAX_UPLOAD_BYTES, CLOUD_PROTOCOL_VERSION, CLOUD_SERVICES_API_PATHS, CLOUD_SERVICES_CONTRACT_VERSION, CLOUD_SERVICES_JWKS_PATH, CLOUD_SERVICES_TOKEN_AUDIENCE, COLLAB_ACTIONS, DOCUMENT_REPORT_DESCRIPTION_MAX, DOCUMENT_VERSION_DESCRIPTION_MAX_LENGTH, DOCUMENT_VERSION_NAME_MAX_LENGTH, MAX_COLLAB_MESSAGE_BYTES, MAX_PRESENCE_NAME_LENGTH, MAX_SEARCH_QUERY_LENGTH, MAX_SEARCH_RESULTS, RELAY_CLOSE, RELAY_DOCUMENT_PARAM, RELAY_FORWARDING_BYTES, RELAY_FRAGMENT_BYTES, RELAY_HEARTBEAT, RELAY_MINIMUM_MESSAGE_BYTES, RELAY_PATH, RELAY_SERVER_PEER, SERVICE_ERROR_STATUS, acceptDocumentInvitationSchema, acceptedInvitationSchema, accountSecurityErrorCodeSchema, accountSecurityErrorResponseSchema, adminAuditEventSchema, adminAuditResponseSchema, adminEmailResponseSchema, adminErrorCodeSchema, adminErrorResponseSchema, adminMutationResponseSchema, adminOperationsResponseSchema, chatModelSchema, cloudAccountDeleteSchema, cloudAccountDeletionDocumentSchema, cloudAccountDeletionResponseSchema, cloudAccountDeletionSchema, cloudAccountDeletionWorkspaceSchema, cloudAccountMutationResponseSchema, cloudAccountSessionSchema, cloudAccountSessionsResponseSchema, cloudAccountStateSchema, cloudAccountStatusResponseSchema, cloudActorSchema, cloudAdminAuditFilterSchema, cloudAdminDocumentFilterSchema, cloudAdminDocumentSchema, cloudAdminDocumentsResponseSchema, cloudAdminEmailFilterSchema, cloudAdminReportFilterSchema, cloudAdminReportSchema, cloudAdminReportStatusSchema, cloudAdminReportsResponseSchema, cloudAdminSessionResponseSchema, cloudAdminUserDetailSchema, cloudAdminUserFilterSchema, cloudAdminUserSchema, cloudAdminUsersResponseSchema, cloudAuthenticationMethodSchema, cloudAuthenticationMethodsResponseSchema, cloudAuthenticationProviderSchema, cloudAuthenticationSchema, cloudBillingDiscoverySchema, cloudCapabilitiesSchema, cloudDeploymentSchema, cloudDesktopLinkURL, cloudDiscoverySchema, cloudDocumentPath, cloudDocumentURL, cloudEditorVersionSchema, cloudEmailChangeSchema, cloudIdentitySchema, cloudInvitationURL, cloudLegalDiscoverySchema, cloudListingSchema, cloudMFAEnableResponseSchema, cloudMFAEnableSchema, cloudMFARecoveryCodesResponseSchema, cloudMFAStatusResponseSchema, cloudMFAStatusSchema, cloudMFAVerifyResponseSchema, cloudMFAVerifySchema, cloudPasskeyDeleteSchema, cloudPasskeySchema, cloudPasskeysResponseSchema, cloudPasswordChangeSchema, cloudPersonSchema, cloudPictureResponseSchema, cloudPictureUploadSchema, cloudPresenceSchema, cloudProfileResponseSchema, cloudProfileSchema, cloudProfileUpdateSchema, cloudServerOrigin, cloudServicesDiscoverySchema, cloudSessionRevokeSchema, cloudSessionSchema, cloudShareURL, cloudSignInMethodSchema, cloudSignInSchema, cloudSignInsResponseSchema, cloudSocialLinkResponseSchema, cloudSocialLinkSchema, cloudTermsAcceptanceSchema, cloudUnlinkAuthenticationMethodSchema, cloudUserProfileSchema, collaborationPrincipalSchema, collaborationTicketSchema, commitImageUploadsSchema, commitUploadSchema, createDocumentInvitationSchema, createDocumentSchema, createDocumentShareSchema, createInvitationContinuationSchema, createRelayClientAssembler, createRelayServerAssembler, createServicesTokenSchema, createUploadSchema, createWorkspaceInvitationSchema, createWorkspaceSchema, createdWorkspaceInvitationSchema, creditBucketSchema, creditWalletSchema, decodeRelayClientFrame, decodeRelayServerFrame, decodeRoomUpdate, defaultRelayURL, documentAccessSchema, documentAccessSourceSchema, documentDownloadSchema, documentGrantSchema, documentImageDownloadSchema, documentImageLinkSchema, documentInvitationSchema, documentPermissionSchema, documentReportReasonSchema, documentShareSchema, documentSummarySchema, documentVersionDownloadSchema, documentVersionKindSchema, documentVersionResponseSchema, documentVersionSchema, documentVersionsSchema, duplicateDocumentVersionSchema, encodeRelayClientFrame, encodeRelayServerFrame, encodeSyncReply, enrollmentReviewResponseSchema, enrollmentSchema, enrollmentStatusSchema, enrollmentsResponseSchema, fileDocumentReportResponseSchema, fileDocumentReportSchema, imageUploadOfferSchema, invitationContinuationSchema, invitationPreviewSchema, isCloudChecksum, isCloudPortalPage, objectUploadSchema, parseAcceptDocumentInvitation, parseCloudAccountDelete, parseCloudDiscovery, parseCloudEmailChange, parseCloudLinkPath, parseCloudMFAEnable, parseCloudMFAVerify, parseCloudPasskeyDelete, parseCloudPasswordChange, parseCloudPictureUpload, parseCloudProfileUpdate, parseCloudSessionRevoke, parseCloudSocialLink, parseCloudTermsAcceptance, parseCloudUnlinkAuthenticationMethod, parseCommitImageUploads, parseCommitUpload, parseCreateDocument, parseCreateDocumentInvitation, parseCreateDocumentShare, parseCreateInvitationContinuation, parseCreateServicesToken, parseCreateUpload, parseCreateWorkspace, parseCreateWorkspaceInvitation, parseDuplicateDocumentVersion, parseFileDocumentReport, parsePutDocumentGrant, parseRequestImageLinks, parseRequestImageUploads, parseRequestSharedImageLinks, parseResolveDocumentShare, parseSaveDocumentVersion, parseSearchRequest, parseUpdateDocumentShare, parseUpdateDocumentVersion, parseUpdateWorkspace, parseUpdateWorkspaceMember, parseUsageQuery, presenceName, putDocumentGrantSchema, relayClientMessages, relayServerMessages, requestImageLinksSchema, requestImageUploadsSchema, requestSharedImageLinksSchema, resolveDocumentShareSchema, resolvedDocumentShareSchema, restoredDocumentSchema, saveDocumentVersionSchema, searchPricingSchema, searchRequestSchema, searchResponseSchema, searchResultSchema, serviceCatalogSchema, serviceErrorCodeSchema, serviceErrorSchema, servicesTokenClaimsSchema, servicesTokenSchema, sharedDocumentSchema, transactionalEmailAdminSchema, trashSchema, trashedDocumentSchema, updateDocumentShareSchema, updateDocumentVersionSchema, updateWorkspaceMemberSchema, updateWorkspaceSchema, usageEntrySchema, usagePageSchema, usageQuerySchema, workspaceEntitlementsSchema, workspaceInvitationSchema, workspaceListSchema, workspaceMemberSchema, workspaceMembersSchema, workspaceRoleSchema, workspaceSummarySchema, workspaceUsageSchema };
1452
1689
 
1453
1690
  //# sourceMappingURL=contract2.js.map