@oxy.so/contracts 5.8.0 → 6.1.0

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 (231) hide show
  1. package/dist/cjs/accountAccess.js +6 -5
  2. package/dist/cjs/accountEmail.js +13 -5
  3. package/dist/cjs/accountGraph.js +10 -9
  4. package/dist/cjs/accountName.js +3 -2
  5. package/dist/cjs/agency.js +91 -34
  6. package/dist/cjs/agentKeys.js +21 -17
  7. package/dist/cjs/appAssertions.js +14 -13
  8. package/dist/cjs/applicationRoles.js +19 -12
  9. package/dist/cjs/campaignAttribution.js +28 -0
  10. package/dist/cjs/civic.js +10 -9
  11. package/dist/cjs/client/campaignAttribution.js +14 -0
  12. package/dist/cjs/client/check.js +61 -53
  13. package/dist/cjs/client/index.js +7 -1
  14. package/dist/cjs/client/language.js +7 -0
  15. package/dist/cjs/consoleOnboarding.js +9 -4
  16. package/dist/cjs/contentClaims.js +23 -14
  17. package/dist/cjs/deviceDirectory.js +11 -9
  18. package/dist/cjs/deviceSession.js +27 -25
  19. package/dist/cjs/email/messages.js +20 -18
  20. package/dist/cjs/emailAgentContext.js +11 -9
  21. package/dist/cjs/externalIdentity.js +15 -11
  22. package/dist/cjs/federationInstanceFetch.js +12 -7
  23. package/dist/cjs/identity.js +19 -17
  24. package/dist/cjs/identityLink.js +6 -4
  25. package/dist/cjs/identityProof.js +6 -4
  26. package/dist/cjs/inboxPush.js +5 -4
  27. package/dist/cjs/index.js +17 -6
  28. package/dist/cjs/inference/accountBilling.js +35 -33
  29. package/dist/cjs/inference/aliaModelRelease.js +9 -7
  30. package/dist/cjs/inference/attribution.js +14 -12
  31. package/dist/cjs/inference/catalogue.js +35 -29
  32. package/dist/cjs/inference/economics.js +24 -19
  33. package/dist/cjs/inference/embeddings.js +9 -7
  34. package/dist/cjs/inference/entitlement.js +17 -15
  35. package/dist/cjs/inference/errors.js +15 -8
  36. package/dist/cjs/inference/identifiers.js +33 -21
  37. package/dist/cjs/inference/inbox.js +37 -35
  38. package/dist/cjs/inference/modelDocumentation.js +16 -14
  39. package/dist/cjs/inference/money.js +5 -4
  40. package/dist/cjs/inference/priceVersion.js +10 -5
  41. package/dist/cjs/inference/providerConnection.js +21 -14
  42. package/dist/cjs/inference/realtime.js +88 -47
  43. package/dist/cjs/inference/request.js +27 -25
  44. package/dist/cjs/inference/routingPolicy.js +12 -10
  45. package/dist/cjs/inference/streamEvents.js +22 -16
  46. package/dist/cjs/inference/usage.js +32 -15
  47. package/dist/cjs/keyRecovery.js +8 -6
  48. package/dist/cjs/keyRotation.js +5 -4
  49. package/dist/cjs/linkedAccounts.js +22 -18
  50. package/dist/cjs/moderationReputation.js +29 -27
  51. package/dist/cjs/notifications.js +25 -9
  52. package/dist/cjs/numberChecks.js +45 -0
  53. package/dist/cjs/oauth.js +14 -12
  54. package/dist/cjs/organizations.js +23 -21
  55. package/dist/cjs/products/access.js +10 -8
  56. package/dist/cjs/products/billing.js +10 -8
  57. package/dist/cjs/products/checkout.js +22 -10
  58. package/dist/cjs/products/plans.js +15 -10
  59. package/dist/cjs/protocol.js +6 -5
  60. package/dist/cjs/recommendations.js +27 -19
  61. package/dist/cjs/reputation.js +15 -13
  62. package/dist/cjs/safety.js +43 -27
  63. package/dist/cjs/serviceToken.js +81 -2
  64. package/dist/cjs/sessionRevocation.js +8 -6
  65. package/dist/cjs/signIn.js +50 -24
  66. package/dist/cjs/stickers.js +19 -15
  67. package/dist/cjs/stringChecks.js +70 -0
  68. package/dist/cjs/transparency.js +14 -12
  69. package/dist/cjs/updates.js +24 -22
  70. package/dist/cjs/userInvalidation.js +7 -5
  71. package/dist/cjs/userResponse.js +8 -7
  72. package/dist/cjs/username.js +7 -6
  73. package/dist/esm/accountAccess.js +4 -3
  74. package/dist/esm/accountEmail.js +13 -5
  75. package/dist/esm/accountGraph.js +8 -7
  76. package/dist/esm/accountName.js +3 -2
  77. package/dist/esm/agency.js +90 -33
  78. package/dist/esm/agentKeys.js +21 -17
  79. package/dist/esm/appAssertions.js +11 -10
  80. package/dist/esm/applicationRoles.js +16 -9
  81. package/dist/esm/campaignAttribution.js +25 -0
  82. package/dist/esm/civic.js +8 -7
  83. package/dist/esm/client/campaignAttribution.js +10 -0
  84. package/dist/esm/client/check.js +61 -53
  85. package/dist/esm/client/index.js +2 -0
  86. package/dist/esm/client/language.js +4 -0
  87. package/dist/esm/consoleOnboarding.js +7 -2
  88. package/dist/esm/contentClaims.js +23 -14
  89. package/dist/esm/deviceDirectory.js +11 -9
  90. package/dist/esm/deviceSession.js +27 -25
  91. package/dist/esm/email/messages.js +18 -16
  92. package/dist/esm/emailAgentContext.js +11 -9
  93. package/dist/esm/externalIdentity.js +15 -11
  94. package/dist/esm/federationInstanceFetch.js +10 -5
  95. package/dist/esm/identity.js +17 -15
  96. package/dist/esm/identityLink.js +6 -4
  97. package/dist/esm/identityProof.js +6 -4
  98. package/dist/esm/inboxPush.js +3 -2
  99. package/dist/esm/index.js +5 -2
  100. package/dist/esm/inference/accountBilling.js +33 -31
  101. package/dist/esm/inference/aliaModelRelease.js +7 -5
  102. package/dist/esm/inference/attribution.js +14 -12
  103. package/dist/esm/inference/catalogue.js +33 -27
  104. package/dist/esm/inference/economics.js +22 -17
  105. package/dist/esm/inference/embeddings.js +9 -7
  106. package/dist/esm/inference/entitlement.js +15 -13
  107. package/dist/esm/inference/errors.js +13 -6
  108. package/dist/esm/inference/identifiers.js +31 -19
  109. package/dist/esm/inference/inbox.js +37 -35
  110. package/dist/esm/inference/modelDocumentation.js +14 -12
  111. package/dist/esm/inference/money.js +3 -2
  112. package/dist/esm/inference/priceVersion.js +8 -3
  113. package/dist/esm/inference/providerConnection.js +19 -12
  114. package/dist/esm/inference/realtime.js +85 -44
  115. package/dist/esm/inference/request.js +25 -23
  116. package/dist/esm/inference/routingPolicy.js +9 -7
  117. package/dist/esm/inference/streamEvents.js +20 -14
  118. package/dist/esm/inference/usage.js +30 -13
  119. package/dist/esm/keyRecovery.js +8 -6
  120. package/dist/esm/keyRotation.js +5 -4
  121. package/dist/esm/linkedAccounts.js +20 -16
  122. package/dist/esm/moderationReputation.js +27 -25
  123. package/dist/esm/notifications.js +23 -7
  124. package/dist/esm/numberChecks.js +41 -0
  125. package/dist/esm/oauth.js +14 -12
  126. package/dist/esm/organizations.js +23 -21
  127. package/dist/esm/products/access.js +10 -8
  128. package/dist/esm/products/billing.js +10 -8
  129. package/dist/esm/products/checkout.js +22 -10
  130. package/dist/esm/products/plans.js +15 -10
  131. package/dist/esm/protocol.js +4 -3
  132. package/dist/esm/recommendations.js +25 -17
  133. package/dist/esm/reputation.js +13 -11
  134. package/dist/esm/safety.js +43 -27
  135. package/dist/esm/serviceToken.js +80 -1
  136. package/dist/esm/sessionRevocation.js +6 -4
  137. package/dist/esm/signIn.js +50 -24
  138. package/dist/esm/stickers.js +17 -13
  139. package/dist/esm/stringChecks.js +63 -0
  140. package/dist/esm/transparency.js +14 -12
  141. package/dist/esm/updates.js +22 -20
  142. package/dist/esm/userInvalidation.js +4 -2
  143. package/dist/esm/userResponse.js +4 -3
  144. package/dist/esm/username.js +3 -2
  145. package/dist/types/accountAccess.d.ts +29 -70
  146. package/dist/types/accountEmail.d.ts +2 -14
  147. package/dist/types/accountGraph.d.ts +179 -171
  148. package/dist/types/accountName.d.ts +1 -1
  149. package/dist/types/accountSubject.d.ts +20 -93
  150. package/dist/types/agency.d.ts +528 -2924
  151. package/dist/types/agentKeys.d.ts +48 -421
  152. package/dist/types/appAssertions.d.ts +56 -210
  153. package/dist/types/applicationRoles.d.ts +30 -276
  154. package/dist/types/avatarCharacter.d.ts +1 -1
  155. package/dist/types/campaignAttribution.d.ts +10 -0
  156. package/dist/types/civic.d.ts +1 -13
  157. package/dist/types/client/agentKeys.d.ts +18 -18
  158. package/dist/types/client/appAssertions.d.ts +3 -3
  159. package/dist/types/client/campaignAttribution.d.ts +12 -0
  160. package/dist/types/client/check.d.ts +13 -13
  161. package/dist/types/client/deviceDirectory.d.ts +51 -51
  162. package/dist/types/client/deviceSession.d.ts +14 -14
  163. package/dist/types/client/index.d.ts +3 -0
  164. package/dist/types/client/language.d.ts +2 -0
  165. package/dist/types/client/organizations.d.ts +25 -25
  166. package/dist/types/client/products.d.ts +33 -33
  167. package/dist/types/client/recommendations.d.ts +2 -2
  168. package/dist/types/client/safety.d.ts +45 -45
  169. package/dist/types/client/sessionStatus.d.ts +4 -4
  170. package/dist/types/client/signIn.d.ts +1 -1
  171. package/dist/types/commonsSignIn.d.ts +4 -1
  172. package/dist/types/consoleOnboarding.d.ts +24 -44
  173. package/dist/types/contentClaims.d.ts +24 -180
  174. package/dist/types/deviceDirectory.d.ts +109 -1040
  175. package/dist/types/deviceSession.d.ts +36 -298
  176. package/dist/types/email/messages.d.ts +212 -1793
  177. package/dist/types/emailAgentContext.d.ts +10 -194
  178. package/dist/types/externalIdentity.d.ts +121 -615
  179. package/dist/types/federationInstanceFetch.d.ts +3 -32
  180. package/dist/types/identity.d.ts +15 -92
  181. package/dist/types/identityLink.d.ts +6 -84
  182. package/dist/types/identityProof.d.ts +5 -17
  183. package/dist/types/inboxPush.d.ts +1 -9
  184. package/dist/types/index.d.ts +7 -3
  185. package/dist/types/inference/accountBilling.d.ts +151 -488
  186. package/dist/types/inference/aliaModelRelease.d.ts +42 -439
  187. package/dist/types/inference/attribution.d.ts +75 -104
  188. package/dist/types/inference/catalogue.d.ts +417 -1599
  189. package/dist/types/inference/economics.d.ts +69 -276
  190. package/dist/types/inference/embeddings.d.ts +110 -406
  191. package/dist/types/inference/entitlement.d.ts +80 -335
  192. package/dist/types/inference/errors.d.ts +90 -102
  193. package/dist/types/inference/identifiers.d.ts +12 -4
  194. package/dist/types/inference/inbox.d.ts +105 -420
  195. package/dist/types/inference/modelDocumentation.d.ts +201 -1390
  196. package/dist/types/inference/money.d.ts +65 -32
  197. package/dist/types/inference/priceVersion.d.ts +53 -120
  198. package/dist/types/inference/providerConnection.d.ts +253 -710
  199. package/dist/types/inference/realtime.d.ts +954 -6825
  200. package/dist/types/inference/request.d.ts +300 -2572
  201. package/dist/types/inference/routingPolicy.d.ts +95 -503
  202. package/dist/types/inference/streamEvents.d.ts +253 -721
  203. package/dist/types/inference/usage.d.ts +317 -950
  204. package/dist/types/keyRecovery.d.ts +3 -51
  205. package/dist/types/keyRotation.d.ts +3 -38
  206. package/dist/types/linkedAccounts.d.ts +50 -236
  207. package/dist/types/moderationReputation.d.ts +81 -14
  208. package/dist/types/notifications.d.ts +19 -51
  209. package/dist/types/numberChecks.d.ts +9 -0
  210. package/dist/types/oauth.d.ts +101 -809
  211. package/dist/types/organizations.d.ts +268 -921
  212. package/dist/types/oxyRecordTypes.d.ts +11 -1
  213. package/dist/types/products/access.d.ts +125 -775
  214. package/dist/types/products/billing.d.ts +67 -503
  215. package/dist/types/products/checkout.d.ts +16 -69
  216. package/dist/types/products/plans.d.ts +33 -366
  217. package/dist/types/recommendations.d.ts +76 -389
  218. package/dist/types/reputation.d.ts +37 -5
  219. package/dist/types/safety.d.ts +408 -2048
  220. package/dist/types/serviceToken.d.ts +247 -7
  221. package/dist/types/sessionRevocation.d.ts +2 -17
  222. package/dist/types/sessionStatus.d.ts +27 -115
  223. package/dist/types/signIn.d.ts +62 -553
  224. package/dist/types/stickers.d.ts +67 -819
  225. package/dist/types/stringChecks.d.ts +16 -0
  226. package/dist/types/transparency.d.ts +14 -302
  227. package/dist/types/updates.d.ts +60 -316
  228. package/dist/types/userInvalidation.d.ts +4 -13
  229. package/dist/types/userResponse.d.ts +302 -2400
  230. package/dist/types/username.d.ts +3 -3
  231. package/package.json +6 -4
@@ -1,3 +1,5 @@
1
+ import { integerCheck, safeNumberCheck } from '../numberChecks.js';
2
+ import { utf16MaxLength, utf16MinLength } from '../stringChecks.js';
1
3
  /**
2
4
  * The reserve → settle → refund protocol.
3
5
  *
@@ -54,12 +56,12 @@ export const usageReservationRequestSchema = z.object({
54
56
  /** Units already determined by the request itself, e.g. input tokens. */
55
57
  knownUnits: z.array(usageQuantitySchema).default([]),
56
58
  /** The ceiling on generated output, when the request set one. */
57
- maxOutputTokens: z.number().int().positive().safe().optional(),
59
+ maxOutputTokens: z.number().check(integerCheck()).positive().check(safeNumberCheck()).optional(),
58
60
  /** The price version of the most expensive route the policy permits. */
59
- ceilingPriceVersionId: z.string().min(1).max(128),
61
+ ceilingPriceVersionId: z.string().check(utf16MinLength(1)).check(utf16MaxLength(128)),
60
62
  maxAmount: exactDecimalSchema,
61
63
  currency: currencyCodeSchema,
62
- expiresInSeconds: z.number().int().positive().max(86400),
64
+ expiresInSeconds: z.number().check(integerCheck()).positive().max(86400),
63
65
  });
64
66
  /** Lifecycle of a hold. Terminal states are `settled`, `released`, `expired`. */
65
67
  export const usageReservationStatusSchema = z.enum(['held', 'settled', 'released', 'expired']);
@@ -74,17 +76,17 @@ export const usageReservationSchema = z
74
76
  .object({
75
77
  /** See `version.ts`: read back by the edge and the Console on its own. */
76
78
  schemaVersion: z.literal(1),
77
- reservationId: z.string().min(1).max(128),
79
+ reservationId: z.string().check(utf16MinLength(1)).check(utf16MaxLength(128)),
78
80
  idempotencyKey: idempotencyKeySchema,
79
81
  attribution: inferenceAttributionSchema,
80
82
  status: usageReservationStatusSchema,
81
83
  reservedAmount: exactDecimalSchema,
82
84
  currency: currencyCodeSchema,
83
- ceilingPriceVersionId: z.string().min(1).max(128),
85
+ ceilingPriceVersionId: z.string().check(utf16MinLength(1)).check(utf16MaxLength(128)),
84
86
  createdAt: inferenceTimestampSchema,
85
87
  expiresAt: inferenceTimestampSchema,
86
88
  /** The receipt that consumed this hold. Present exactly when `settled`. */
87
- settledReceiptId: z.string().min(1).max(128).optional(),
89
+ settledReceiptId: z.string().check(utf16MinLength(1)).check(utf16MaxLength(128)).optional(),
88
90
  })
89
91
  .superRefine((reservation, ctx) => {
90
92
  if (reservation.status === 'settled' && reservation.settledReceiptId === undefined) {
@@ -169,7 +171,7 @@ export const normalizedUsageReportSchema = z
169
171
  /** Exact Kaana deployment that attempted the request; never inferred from names. */
170
172
  deploymentId: deploymentIdSchema,
171
173
  /** How many allowed route switches occurred while serving this request. */
172
- routeSwitches: z.number().int().nonnegative().max(100),
174
+ routeSwitches: z.number().check(integerCheck()).nonnegative().max(100),
173
175
  /**
174
176
  * The funding tier of the platform key that served the final attempt, as
175
177
  * the data plane states it (ADR 0038). Absent when the key's economics
@@ -180,7 +182,12 @@ export const normalizedUsageReportSchema = z
180
182
  fundingTier: inferenceFundingTierSchema.optional(),
181
183
  startedAt: inferenceTimestampSchema,
182
184
  completedAt: inferenceTimestampSchema,
183
- timeToFirstTokenMs: z.number().int().nonnegative().safe().optional(),
185
+ timeToFirstTokenMs: z
186
+ .number()
187
+ .check(integerCheck())
188
+ .nonnegative()
189
+ .check(safeNumberCheck())
190
+ .optional(),
184
191
  })
185
192
  .superRefine((report, ctx) => {
186
193
  // Compared as instants: two spellings of one moment sort differently as text.
@@ -226,9 +233,9 @@ export const usageReceiptSchema = z
226
233
  .object({
227
234
  /** See `version.ts`: returned to customers by `GET /v1/generations/:id`. */
228
235
  schemaVersion: z.literal(1),
229
- receiptId: z.string().min(1).max(128),
236
+ receiptId: z.string().check(utf16MinLength(1)).check(utf16MaxLength(128)),
230
237
  /** The hold this settled against. Absent for a charge with no reservation. */
231
- reservationId: z.string().min(1).max(128).optional(),
238
+ reservationId: z.string().check(utf16MinLength(1)).check(utf16MaxLength(128)).optional(),
232
239
  idempotencyKey: idempotencyKeySchema,
233
240
  attribution: inferenceAttributionSchema,
234
241
  outcome: inferenceRequestOutcomeSchema,
@@ -270,8 +277,18 @@ export const usageReceiptSchema = z
270
277
  * ledger accounts and only the second one is visible on an invoice.
271
278
  */
272
279
  export const usageRefundSubjectSchema = z.discriminatedUnion('kind', [
273
- z.object({ kind: z.literal('reservation'), reservationId: z.string().min(1).max(128) }).strict(),
274
- z.object({ kind: z.literal('receipt'), receiptId: z.string().min(1).max(128) }).strict(),
280
+ z
281
+ .object({
282
+ kind: z.literal('reservation'),
283
+ reservationId: z.string().check(utf16MinLength(1)).check(utf16MaxLength(128)),
284
+ })
285
+ .strict(),
286
+ z
287
+ .object({
288
+ kind: z.literal('receipt'),
289
+ receiptId: z.string().check(utf16MinLength(1)).check(utf16MaxLength(128)),
290
+ })
291
+ .strict(),
275
292
  ]);
276
293
  /** Why money was given back or a hold was released. */
277
294
  export const usageRefundReasonSchema = z.enum([
@@ -300,7 +317,7 @@ export const usageRefundSchema = z
300
317
  .object({
301
318
  /** See `version.ts`: a ledger record read back on its own. */
302
319
  schemaVersion: z.literal(1),
303
- refundId: z.string().min(1).max(128),
320
+ refundId: z.string().check(utf16MinLength(1)).check(utf16MaxLength(128)),
304
321
  idempotencyKey: idempotencyKeySchema,
305
322
  attribution: inferenceAttributionSchema,
306
323
  subject: usageRefundSubjectSchema,
@@ -1,3 +1,5 @@
1
+ import { integerCheck } from './numberChecks.js';
2
+ import { utf16MinLength } from './stringChecks.js';
1
3
  /**
2
4
  * Encrypted off-device identity backup contract (b3 Feature 1).
3
5
  *
@@ -54,13 +56,13 @@ export const backupLookupIdSchema = z
54
56
  * - `createdAt` — ISO-8601 creation timestamp.
55
57
  */
56
58
  export const encryptedBackupEnvelopeSchema = z.object({
57
- version: z.number().int().positive(),
59
+ version: z.number().check(integerCheck()).positive(),
58
60
  algorithm: z.literal('xchacha20poly1305'),
59
- kdfInfo: z.string().min(1),
60
- nonce: z.string().trim().min(1),
61
- ciphertext: z.string().trim().min(1),
62
- publicKeyHint: z.string().trim().min(1),
63
- createdAt: z.string().trim().min(1),
61
+ kdfInfo: z.string().check(utf16MinLength(1)),
62
+ nonce: z.string().trim().check(utf16MinLength(1)),
63
+ ciphertext: z.string().trim().check(utf16MinLength(1)),
64
+ publicKeyHint: z.string().trim().check(utf16MinLength(1)),
65
+ createdAt: z.string().trim().check(utf16MinLength(1)),
64
66
  });
65
67
  /**
66
68
  * Request body of `POST /identity/backup` — the envelope PLUS the raw
@@ -1,3 +1,4 @@
1
+ import { utf16MinLength } from './stringChecks.js';
1
2
  /**
2
3
  * Key-rotation contract (b3 Feature 3 — key rotation + last-credential replacement).
3
4
  *
@@ -51,11 +52,11 @@ export const rotateKeyChallengeResponseSchema = z.object({
51
52
  * key Y.
52
53
  */
53
54
  export const rotateKeyCompleteRequestSchema = z.object({
54
- newPublicKey: z.string().trim().min(1),
55
- challenge: z.string().trim().min(1),
56
- signature: z.string().trim().min(1),
55
+ newPublicKey: z.string().trim().check(utf16MinLength(1)),
56
+ challenge: z.string().trim().check(utf16MinLength(1)),
57
+ signature: z.string().trim().check(utf16MinLength(1)),
57
58
  /** Proof-of-possession: the NEW key signs the rotate_key_new payload. */
58
- newKeyProof: z.string().trim().min(1),
59
+ newKeyProof: z.string().trim().check(utf16MinLength(1)),
59
60
  timestamp: z.number(),
60
61
  /**
61
62
  * When true, all OTHER active sessions for the account are revoked after a
@@ -1,3 +1,4 @@
1
+ import { isoDateTime, urlCheck, utf16MaxLength, utf16MinLength } from './stringChecks.js';
1
2
  /**
2
3
  * Wire contract for Oxy linked accounts — external accounts (any Mastodon-API
3
4
  * server, Bluesky) a LOCAL Oxy user has proven they own by completing an OAuth
@@ -24,16 +25,16 @@ export const linkedAccountNetworkSchema = z.enum(LINKED_ACCOUNT_NETWORKS);
24
25
  */
25
26
  export const startLinkedAccountRequestSchema = z
26
27
  .object({
27
- instance: z.string().trim().min(1).max(320).optional(),
28
- handle: z.string().trim().min(1).max(320).optional(),
29
- clientId: z.string().trim().min(1).max(256),
30
- returnTo: z.string().trim().min(1).max(2048),
28
+ instance: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(320)).optional(),
29
+ handle: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(320)).optional(),
30
+ clientId: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(256)),
31
+ returnTo: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(2048)),
31
32
  })
32
33
  .strict();
33
34
  export const startLinkedAccountResponseSchema = z
34
35
  .object({
35
- authorizeUrl: z.string().url(),
36
- expiresAt: z.string().datetime(),
36
+ authorizeUrl: z.string().check(urlCheck()),
37
+ expiresAt: z.string().check(isoDateTime()),
37
38
  })
38
39
  .strict();
39
40
  /**
@@ -43,22 +44,22 @@ export const startLinkedAccountResponseSchema = z
43
44
  * other user it is refused (403) and burned.
44
45
  */
45
46
  export const completeLinkedAccountRequestSchema = z
46
- .object({ code: z.string().trim().min(1).max(256) })
47
+ .object({ code: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(256)) })
47
48
  .strict();
48
49
  /** One live linked account, as its owner sees it. */
49
50
  export const linkedAccountSchema = z
50
51
  .object({
51
- id: z.string().min(1),
52
+ id: z.string().check(utf16MinLength(1)),
52
53
  network: linkedAccountNetworkSchema,
53
54
  /** `username@domain` for ActivityPub; the DID for atproto. */
54
- accountKey: z.string().min(1),
55
+ accountKey: z.string().check(utf16MinLength(1)),
55
56
  /** ActivityPub actor id, or the DID for atproto. */
56
- actorUri: z.string().min(1),
57
- handle: z.string().min(1),
58
- host: z.string().min(1),
57
+ actorUri: z.string().check(utf16MinLength(1)),
58
+ handle: z.string().check(utf16MinLength(1)),
59
+ host: z.string().check(utf16MinLength(1)),
59
60
  proofMethod: z.literal('oauth'),
60
- verifiedAt: z.string().datetime(),
61
- createdAt: z.string().datetime(),
61
+ verifiedAt: z.string().check(isoDateTime()),
62
+ createdAt: z.string().check(isoDateTime()),
62
63
  })
63
64
  .strict();
64
65
  export const completeLinkedAccountResponseSchema = z
@@ -74,10 +75,13 @@ export const linkedAccountListResponseSchema = z
74
75
  * content Oxy federated in before the account was linked.
75
76
  */
76
77
  export const serviceLinkedAccountSchema = linkedAccountSchema
77
- .extend({ federatedUserId: z.string().min(1).nullable() })
78
+ .extend({ federatedUserId: z.string().check(utf16MinLength(1)).nullable() })
78
79
  .strict();
79
80
  export const serviceLinkedAccountListResponseSchema = z
80
- .object({ userId: z.string().min(1), linkedAccounts: z.array(serviceLinkedAccountSchema) })
81
+ .object({
82
+ userId: z.string().check(utf16MinLength(1)),
83
+ linkedAccounts: z.array(serviceLinkedAccountSchema),
84
+ })
81
85
  .strict();
82
86
  /**
83
87
  * Error codes the callback appends as `?link_error=<code>` to `returnTo`. An
@@ -1,3 +1,5 @@
1
+ import { integerCheck } from './numberChecks.js';
2
+ import { utf16MaxLength, utf16MinLength } from './stringChecks.js';
1
3
  /**
2
4
  * Oxy Trust — the moderation reputation bridge (CrowdSource → Oxy Trust).
3
5
  *
@@ -167,45 +169,45 @@ export const MODERATION_EFFECT_SKIP_REASONS = [
167
169
  ];
168
170
  export const moderationEffectSkipReasonSchema = z.enum(MODERATION_EFFECT_SKIP_REASONS);
169
171
  export const moderationFindingSchema = z.object({
170
- code: z.string().trim().min(1).max(200),
172
+ code: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(200)),
171
173
  severity: moderationSeveritySchema,
172
174
  scope: moderationFindingScopeSchema,
173
175
  attribution: moderationAttributionSchema,
174
- family: z.string().trim().min(1).max(100),
176
+ family: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(100)),
175
177
  });
176
178
  export const moderationDecisionEventSubjectSchema = z.object({
177
179
  principalType: z.literal('oxy_user'),
178
- principalId: z.string().trim().min(1),
179
- bindingProofId: z.string().trim().min(1),
180
+ principalId: z.string().trim().check(utf16MinLength(1)),
181
+ bindingProofId: z.string().trim().check(utf16MinLength(1)),
180
182
  });
181
183
  export const moderationPolicyVersionsSchema = z.object({
182
- universal: z.string().trim().min(1).max(100),
183
- application: z.string().trim().min(1).max(100),
184
- oxyConduct: z.string().trim().min(1).max(100),
184
+ universal: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(100)),
185
+ application: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(100)),
186
+ oxyConduct: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(100)),
185
187
  });
186
188
  export const moderationDecisionEventSchema = z.object({
187
- eventId: z.string().trim().min(1).max(200),
188
- reportedApplicationId: z.string().trim().min(1).max(200),
189
- type: z.string().trim().min(1).max(200),
190
- caseId: z.string().trim().min(1).max(200),
191
- incidentId: z.string().trim().min(1).max(200),
192
- decisionId: z.string().trim().min(1).max(200),
193
- decisionRevision: z.number().int().min(1),
189
+ eventId: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(200)),
190
+ reportedApplicationId: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(200)),
191
+ type: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(200)),
192
+ caseId: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(200)),
193
+ incidentId: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(200)),
194
+ decisionId: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(200)),
195
+ decisionRevision: z.number().check(integerCheck()).min(1),
194
196
  subject: moderationDecisionEventSubjectSchema,
195
197
  findings: z.array(moderationFindingSchema).min(1).max(20),
196
198
  decisionStatus: moderationDecisionStatusSchema,
197
199
  policyVersions: moderationPolicyVersionsSchema,
198
- occurredAt: z.string().trim().min(1),
199
- proofHash: z.string().trim().min(1).max(200),
200
+ occurredAt: z.string().trim().check(utf16MinLength(1)),
201
+ proofHash: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(200)),
200
202
  });
201
203
  export const finalizeModerationDecisionSchema = z.object({
202
- decisionId: z.string().trim().min(1).max(200),
203
- decisionRevision: z.number().int().min(1),
204
+ decisionId: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(200)),
205
+ decisionRevision: z.number().check(integerCheck()).min(1),
204
206
  });
205
207
  export const reverseModerationEffectSchema = z.object({
206
- decisionId: z.string().trim().min(1).max(200),
207
- decisionRevision: z.number().int().min(1),
208
- reason: z.string().trim().min(1).max(500),
208
+ decisionId: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(200)),
209
+ decisionRevision: z.number().check(integerCheck()).min(1),
210
+ reason: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(500)),
209
211
  });
210
212
  export const moderationEffectSchema = z.object({
211
213
  id: z.string(),
@@ -240,8 +242,8 @@ export const reverseModerationEffectResultSchema = z.object({
240
242
  idempotent: z.boolean(),
241
243
  });
242
244
  export const registerIdentityBindingSchema = z.object({
243
- localPrincipalId: z.string().trim().min(1).max(200),
244
- userProofToken: z.string().trim().min(1),
245
+ localPrincipalId: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(200)),
246
+ userProofToken: z.string().trim().check(utf16MinLength(1)),
245
247
  });
246
248
  export const identityBindingSchema = z.object({
247
249
  id: z.string(),
@@ -276,8 +278,8 @@ export const reputationReportingSchema = z.object({
276
278
  });
277
279
  export const reputationReviewingSchema = z.object({
278
280
  globalReliability: z.number(),
279
- categoryReliability: z.record(z.number()),
280
- languageReliability: z.record(z.number()),
281
+ categoryReliability: z.record(z.string(), z.number()),
282
+ languageReliability: z.record(z.string(), z.number()),
281
283
  });
282
284
  export const reputationContextualInfluenceSchema = z.object({
283
285
  reportPriorityWeight: z.number(),
@@ -1,3 +1,4 @@
1
+ import { utf16MaxLength, utf16MinLength } from './stringChecks.js';
1
2
  /**
2
3
  * The closed set of Oxy in-app notification types — owned here so the API's
3
4
  * CHECK constraint (`notifications.type`), its request validation and the SDK
@@ -48,14 +49,29 @@ export const OXY_NOTIFICATION_URL_MAX = 2048;
48
49
  */
49
50
  export const createOxyNotificationRequestSchema = z
50
51
  .object({
51
- recipientId: z.string().min(1),
52
- actorId: z.string().min(1),
52
+ recipientId: z.string().check(utf16MinLength(1)),
53
+ actorId: z.string().check(utf16MinLength(1)),
53
54
  type: z.enum(OXY_NOTIFICATION_TYPES),
54
- entityId: z.string().min(1),
55
+ entityId: z.string().check(utf16MinLength(1)),
55
56
  entityType: z.enum(OXY_NOTIFICATION_ENTITY_TYPES),
56
- title: z.string().trim().min(1).max(OXY_SYSTEM_NOTIFICATION_TITLE_MAX).optional(),
57
- message: z.string().trim().min(1).max(OXY_SYSTEM_NOTIFICATION_MESSAGE_MAX).optional(),
58
- url: z.string().trim().min(1).max(OXY_NOTIFICATION_URL_MAX).optional(),
57
+ title: z
58
+ .string()
59
+ .trim()
60
+ .check(utf16MinLength(1))
61
+ .check(utf16MaxLength(OXY_SYSTEM_NOTIFICATION_TITLE_MAX))
62
+ .optional(),
63
+ message: z
64
+ .string()
65
+ .trim()
66
+ .check(utf16MinLength(1))
67
+ .check(utf16MaxLength(OXY_SYSTEM_NOTIFICATION_MESSAGE_MAX))
68
+ .optional(),
69
+ url: z
70
+ .string()
71
+ .trim()
72
+ .check(utf16MinLength(1))
73
+ .check(utf16MaxLength(OXY_NOTIFICATION_URL_MAX))
74
+ .optional(),
59
75
  data: z.record(z.string(), z.unknown()).optional(),
60
76
  })
61
77
  .superRefine((value, context) => {
@@ -113,5 +129,5 @@ export const OXY_SYSTEM_NOTIFICATION_PUSH_TYPE = 'oxy_system_notification';
113
129
  */
114
130
  export const oxySystemNotificationPushDataSchema = z.object({
115
131
  type: z.literal(OXY_SYSTEM_NOTIFICATION_PUSH_TYPE),
116
- notificationId: z.string().min(1).max(64),
132
+ notificationId: z.string().check(utf16MinLength(1)).check(utf16MaxLength(64)),
117
133
  });
@@ -0,0 +1,41 @@
1
+ import { z } from 'zod';
2
+ /** Integer validation does not add a safe-number ceiling unless the contract requests one. */
3
+ export function integerCheck(message) {
4
+ const check = z.check((context) => {
5
+ if (Number.isInteger(context.value))
6
+ return;
7
+ context.issues.push({
8
+ code: 'invalid_type',
9
+ expected: 'int',
10
+ input: context.value,
11
+ continue: true,
12
+ ...(message ? { message: typeof message === 'string' ? message : message.message } : {}),
13
+ });
14
+ });
15
+ check._zod.onattach.push((schema) => {
16
+ schema._zod.bag.format = 'integer';
17
+ });
18
+ return check;
19
+ }
20
+ /** Existing `.safe()` contracts bound a number independently of integer validation. */
21
+ export function safeNumberCheck(message) {
22
+ const check = z.check((context) => {
23
+ const common = {
24
+ origin: 'number',
25
+ input: context.value,
26
+ inclusive: true,
27
+ continue: true,
28
+ ...(message ? { message: typeof message === 'string' ? message : message.message } : {}),
29
+ };
30
+ if (context.value < Number.MIN_SAFE_INTEGER)
31
+ context.issues.push({ ...common, code: 'too_small', minimum: Number.MIN_SAFE_INTEGER });
32
+ if (context.value > Number.MAX_SAFE_INTEGER)
33
+ context.issues.push({ ...common, code: 'too_big', maximum: Number.MAX_SAFE_INTEGER });
34
+ });
35
+ check._zod.onattach.push((schema) => {
36
+ const bag = schema._zod.bag;
37
+ bag.minimum = Math.max(typeof bag.minimum === 'number' ? bag.minimum : -Infinity, Number.MIN_SAFE_INTEGER);
38
+ bag.maximum = Math.min(typeof bag.maximum === 'number' ? bag.maximum : Infinity, Number.MAX_SAFE_INTEGER);
39
+ });
40
+ return check;
41
+ }
package/dist/esm/oauth.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { integerCheck } from './numberChecks.js';
2
+ import { urlCheck, utf16MinLength } from './stringChecks.js';
1
3
  import { z } from 'zod';
2
4
  import { catalogToolSchema } from './agency.js';
3
5
  import { publicApplicationSchema } from './sessionStatus.js';
@@ -58,10 +60,10 @@ export const oauthConsentDecisionSchema = z.discriminatedUnion('consentRequired'
58
60
  * code was issued against is the one it registered.
59
61
  */
60
62
  export const oauthAuthorizeCodeResponseSchema = z.object({
61
- code: z.string().min(1),
63
+ code: z.string().check(utf16MinLength(1)),
62
64
  state: z.string().nullable(),
63
65
  redirectUri: z.string(),
64
- expiresIn: z.number().int().positive(),
66
+ expiresIn: z.number().check(integerCheck()).positive(),
65
67
  });
66
68
  /**
67
69
  * Display-safe identity of a dynamically registered external MCP client.
@@ -70,7 +72,7 @@ export const oauthAuthorizeCodeResponseSchema = z.object({
70
72
  */
71
73
  export const mcpOAuthClientApplicationSchema = publicApplicationSchema
72
74
  .extend({
73
- clientId: z.string().min(1),
75
+ clientId: z.string().check(utf16MinLength(1)),
74
76
  })
75
77
  .strict();
76
78
  /**
@@ -78,8 +80,8 @@ export const mcpOAuthClientApplicationSchema = publicApplicationSchema
78
80
  * Every field is picked from the canonical catalog tool schema so consent can
79
81
  * never maintain a second tool description or effect classification.
80
82
  */
81
- export const mcpOAuthWriteActionSchema = catalogToolSchema
82
- .innerType()
83
+ export const mcpOAuthWriteActionSchema = z
84
+ .object(catalogToolSchema.shape)
83
85
  .pick({
84
86
  name: true,
85
87
  version: true,
@@ -98,20 +100,20 @@ export const mcpOAuthConsentContextSchema = z
98
100
  client: mcpOAuthClientApplicationSchema,
99
101
  account: z
100
102
  .object({
101
- id: z.string().min(1),
102
- displayName: z.string().min(1).optional(),
103
- handle: z.string().min(1).optional(),
104
- avatar: z.string().min(1).optional(),
103
+ id: z.string().check(utf16MinLength(1)),
104
+ displayName: z.string().check(utf16MinLength(1)).optional(),
105
+ handle: z.string().check(utf16MinLength(1)).optional(),
106
+ avatar: z.string().check(utf16MinLength(1)).optional(),
105
107
  })
106
108
  .strict(),
107
109
  resource: z
108
110
  .object({
109
- appId: z.string().min(1),
110
- uri: z.string().url(),
111
+ appId: z.string().check(utf16MinLength(1)),
112
+ uri: z.string().check(urlCheck()),
111
113
  application: publicApplicationSchema,
112
114
  })
113
115
  .strict(),
114
- capabilities: z.array(z.string().min(1)).min(1),
116
+ capabilities: z.array(z.string().check(utf16MinLength(1))).min(1),
115
117
  writeActions: z.array(mcpOAuthWriteActionSchema),
116
118
  })
117
119
  .strict();
@@ -1,16 +1,18 @@
1
+ import { integerCheck } from './numberChecks.js';
2
+ import { isoDateTime, urlCheck, utf16MaxLength, utf16MinLength } from './stringChecks.js';
1
3
  import { z } from 'zod';
2
4
  import { accountTitleSchema } from './accountName.js';
3
5
  // The Zod-free half of this contract lives in `./client/` (`@oxy.so/contracts/client`);
4
6
  // it is re-exported here so the root entry is unchanged.
5
7
  import { ORGANIZATION_TYPES, ORGANIZATION_STATUSES, ORGANIZATION_CLAIM_STATUSES, ORGANIZATION_ALIAS_KINDS, ORGANIZATION_CLAIM_DECISIONS, ORGANIZATION_ERROR_CODES, } from './client/organizations.js';
6
8
  export { ORGANIZATION_TYPES, ORGANIZATION_STATUSES, ORGANIZATION_CLAIM_STATUSES, ORGANIZATION_ALIAS_KINDS, ORGANIZATION_CLAIM_DECISIONS, ORGANIZATION_NAME_MAX_LENGTH, ORGANIZATION_ERROR_CODES, } from './client/organizations.js';
7
- const id = z.string().min(1).max(128);
8
- const optionalText = (max) => z.string().trim().min(1).max(max).nullable().optional();
9
+ const id = z.string().check(utf16MinLength(1)).check(utf16MaxLength(128));
10
+ const optionalText = (max) => z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(max)).nullable().optional();
9
11
  export const organizationAliasSchema = z
10
12
  .object({
11
- alias: z.string().trim().min(1).max(300),
13
+ alias: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(300)),
12
14
  kind: z.enum(ORGANIZATION_ALIAS_KINDS),
13
- language: z.string().min(2).max(35).optional(),
15
+ language: z.string().check(utf16MinLength(2)).check(utf16MaxLength(35)).optional(),
14
16
  })
15
17
  .strict();
16
18
  /** An organization is named by the title policy every non-personal account uses. */
@@ -22,8 +24,8 @@ export const createOrganizationSchema = z
22
24
  legalName: optionalText(300),
23
25
  websiteUrl: z
24
26
  .string()
25
- .url()
26
- .max(2048)
27
+ .check(urlCheck())
28
+ .check(utf16MaxLength(2048))
27
29
  .refine((value) => /^https?:\/\//.test(value), 'Use HTTP or HTTPS')
28
30
  .nullable()
29
31
  .optional(),
@@ -49,16 +51,16 @@ export const organizationSchema = createOrganizationSchema
49
51
  claimStatus: z.enum(ORGANIZATION_CLAIM_STATUSES),
50
52
  status: z.enum(ORGANIZATION_STATUSES),
51
53
  mergedIntoAccountId: id.nullable(),
52
- createdAt: z.string().datetime(),
53
- updatedAt: z.string().datetime(),
54
+ createdAt: z.string().check(isoDateTime()),
55
+ updatedAt: z.string().check(isoDateTime()),
54
56
  })
55
57
  .strict();
56
58
  export const organizationSearchSchema = z
57
59
  .object({
58
- query: z.string().trim().max(200).default(''),
60
+ query: z.string().trim().check(utf16MaxLength(200)).default(''),
59
61
  organizationType: z.enum(ORGANIZATION_TYPES).optional(),
60
- limit: z.coerce.number().int().min(1).max(50).default(20),
61
- cursor: z.string().min(1).max(2048).optional(),
62
+ limit: z.coerce.number().check(integerCheck()).min(1).max(50).default(20),
63
+ cursor: z.string().check(utf16MinLength(1)).check(utf16MaxLength(2048)).optional(),
62
64
  })
63
65
  .strict();
64
66
  export const organizationListSchema = z
@@ -73,7 +75,7 @@ export const organizationBatchSchema = z
73
75
  .strict();
74
76
  export const organizationClaimInputSchema = z
75
77
  .object({
76
- evidenceReference: z.string().trim().min(1).max(1000),
78
+ evidenceReference: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(1000)),
77
79
  })
78
80
  .strict();
79
81
  export const organizationClaimSchema = z
@@ -82,21 +84,21 @@ export const organizationClaimSchema = z
82
84
  accountId: id,
83
85
  claimantUserId: id,
84
86
  status: z.enum(ORGANIZATION_CLAIM_DECISIONS),
85
- createdAt: z.string().datetime(),
87
+ createdAt: z.string().check(isoDateTime()),
86
88
  })
87
89
  .strict();
88
90
  export const organizationClaimDetailSchema = organizationClaimSchema
89
91
  .extend({
90
92
  evidenceReference: z.string(),
91
93
  reviewEvidenceReference: z.string().nullable(),
92
- reviewedAt: z.string().datetime().nullable(),
94
+ reviewedAt: z.string().check(isoDateTime()).nullable(),
93
95
  })
94
96
  .strict();
95
97
  export const organizationClaimListQuerySchema = z
96
98
  .object({
97
99
  status: z.enum(ORGANIZATION_CLAIM_DECISIONS).optional(),
98
- limit: z.coerce.number().int().min(1).max(50).default(20),
99
- cursor: z.string().min(1).max(2048).optional(),
100
+ limit: z.coerce.number().check(integerCheck()).min(1).max(50).default(20),
101
+ cursor: z.string().check(utf16MinLength(1)).check(utf16MaxLength(2048)).optional(),
100
102
  })
101
103
  .strict();
102
104
  export const organizationClaimListSchema = z
@@ -105,16 +107,16 @@ export const organizationClaimListSchema = z
105
107
  export const organizationClaimReviewSchema = z
106
108
  .object({
107
109
  decision: z.enum(['approved', 'rejected']),
108
- evidenceReference: z.string().trim().min(1).max(1000),
110
+ evidenceReference: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(1000)),
109
111
  })
110
112
  .strict();
111
113
  export const organizationExternalInputSchema = z
112
114
  .object({
113
115
  namespace: z.string().regex(/^[a-z][a-z0-9_-]{0,63}$/),
114
- externalId: z.string().min(1).max(256),
116
+ externalId: z.string().check(utf16MinLength(1)).check(utf16MaxLength(256)),
115
117
  accountId: id.optional(),
116
118
  organization: createOrganizationSchema,
117
- evidenceReference: z.string().trim().min(1).max(1000),
119
+ evidenceReference: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(1000)),
118
120
  avatarFileId: id.optional(),
119
121
  })
120
122
  .strict();
@@ -146,7 +148,7 @@ export const organizationExternalResolutionSchema = z.object({ accountId: id }).
146
148
  export const organizationMergeSchema = z
147
149
  .object({
148
150
  targetAccountId: id,
149
- evidenceReference: z.string().trim().min(1).max(1000),
151
+ evidenceReference: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(1000)),
150
152
  })
151
153
  .strict();
152
154
  export const organizationErrorSchema = z
@@ -167,7 +169,7 @@ export const organizationCurationSchema = z
167
169
  .object({
168
170
  changes: updateOrganizationSchema.optional(),
169
171
  status: z.enum(['active', 'inactive', 'suppressed']).optional(),
170
- evidenceReference: z.string().trim().min(1).max(1000),
172
+ evidenceReference: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(1000)),
171
173
  })
172
174
  .strict()
173
175
  .refine((input) => input.changes !== undefined || input.status !== undefined, 'At least one change is required');