@oxy.so/contracts 5.8.0 → 6.0.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 (219) 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/civic.js +10 -9
  10. package/dist/cjs/client/check.js +61 -53
  11. package/dist/cjs/consoleOnboarding.js +9 -4
  12. package/dist/cjs/contentClaims.js +23 -14
  13. package/dist/cjs/deviceDirectory.js +11 -9
  14. package/dist/cjs/deviceSession.js +27 -25
  15. package/dist/cjs/email/messages.js +20 -18
  16. package/dist/cjs/emailAgentContext.js +11 -9
  17. package/dist/cjs/externalIdentity.js +15 -11
  18. package/dist/cjs/federationInstanceFetch.js +12 -7
  19. package/dist/cjs/identity.js +19 -17
  20. package/dist/cjs/identityLink.js +6 -4
  21. package/dist/cjs/identityProof.js +6 -4
  22. package/dist/cjs/inboxPush.js +5 -4
  23. package/dist/cjs/index.js +15 -6
  24. package/dist/cjs/inference/accountBilling.js +35 -33
  25. package/dist/cjs/inference/aliaModelRelease.js +9 -7
  26. package/dist/cjs/inference/attribution.js +14 -12
  27. package/dist/cjs/inference/catalogue.js +35 -29
  28. package/dist/cjs/inference/economics.js +24 -19
  29. package/dist/cjs/inference/embeddings.js +9 -7
  30. package/dist/cjs/inference/entitlement.js +17 -15
  31. package/dist/cjs/inference/errors.js +15 -8
  32. package/dist/cjs/inference/identifiers.js +33 -21
  33. package/dist/cjs/inference/inbox.js +37 -35
  34. package/dist/cjs/inference/modelDocumentation.js +16 -14
  35. package/dist/cjs/inference/money.js +5 -4
  36. package/dist/cjs/inference/priceVersion.js +10 -5
  37. package/dist/cjs/inference/providerConnection.js +21 -14
  38. package/dist/cjs/inference/realtime.js +88 -47
  39. package/dist/cjs/inference/request.js +27 -25
  40. package/dist/cjs/inference/routingPolicy.js +12 -10
  41. package/dist/cjs/inference/streamEvents.js +22 -16
  42. package/dist/cjs/inference/usage.js +32 -15
  43. package/dist/cjs/keyRecovery.js +8 -6
  44. package/dist/cjs/keyRotation.js +5 -4
  45. package/dist/cjs/linkedAccounts.js +22 -18
  46. package/dist/cjs/moderationReputation.js +29 -27
  47. package/dist/cjs/notifications.js +25 -9
  48. package/dist/cjs/numberChecks.js +45 -0
  49. package/dist/cjs/oauth.js +14 -12
  50. package/dist/cjs/organizations.js +23 -21
  51. package/dist/cjs/products/access.js +10 -8
  52. package/dist/cjs/products/billing.js +10 -8
  53. package/dist/cjs/products/checkout.js +22 -10
  54. package/dist/cjs/products/plans.js +15 -10
  55. package/dist/cjs/protocol.js +6 -5
  56. package/dist/cjs/recommendations.js +27 -19
  57. package/dist/cjs/reputation.js +15 -13
  58. package/dist/cjs/safety.js +43 -27
  59. package/dist/cjs/serviceToken.js +81 -2
  60. package/dist/cjs/sessionRevocation.js +8 -6
  61. package/dist/cjs/signIn.js +42 -24
  62. package/dist/cjs/stickers.js +19 -15
  63. package/dist/cjs/stringChecks.js +70 -0
  64. package/dist/cjs/transparency.js +14 -12
  65. package/dist/cjs/updates.js +24 -22
  66. package/dist/cjs/userInvalidation.js +7 -5
  67. package/dist/cjs/userResponse.js +8 -7
  68. package/dist/cjs/username.js +7 -6
  69. package/dist/esm/accountAccess.js +4 -3
  70. package/dist/esm/accountEmail.js +13 -5
  71. package/dist/esm/accountGraph.js +8 -7
  72. package/dist/esm/accountName.js +3 -2
  73. package/dist/esm/agency.js +90 -33
  74. package/dist/esm/agentKeys.js +21 -17
  75. package/dist/esm/appAssertions.js +11 -10
  76. package/dist/esm/applicationRoles.js +16 -9
  77. package/dist/esm/civic.js +8 -7
  78. package/dist/esm/client/check.js +61 -53
  79. package/dist/esm/consoleOnboarding.js +7 -2
  80. package/dist/esm/contentClaims.js +23 -14
  81. package/dist/esm/deviceDirectory.js +11 -9
  82. package/dist/esm/deviceSession.js +27 -25
  83. package/dist/esm/email/messages.js +18 -16
  84. package/dist/esm/emailAgentContext.js +11 -9
  85. package/dist/esm/externalIdentity.js +15 -11
  86. package/dist/esm/federationInstanceFetch.js +10 -5
  87. package/dist/esm/identity.js +17 -15
  88. package/dist/esm/identityLink.js +6 -4
  89. package/dist/esm/identityProof.js +6 -4
  90. package/dist/esm/inboxPush.js +3 -2
  91. package/dist/esm/index.js +4 -2
  92. package/dist/esm/inference/accountBilling.js +33 -31
  93. package/dist/esm/inference/aliaModelRelease.js +7 -5
  94. package/dist/esm/inference/attribution.js +14 -12
  95. package/dist/esm/inference/catalogue.js +33 -27
  96. package/dist/esm/inference/economics.js +22 -17
  97. package/dist/esm/inference/embeddings.js +9 -7
  98. package/dist/esm/inference/entitlement.js +15 -13
  99. package/dist/esm/inference/errors.js +13 -6
  100. package/dist/esm/inference/identifiers.js +31 -19
  101. package/dist/esm/inference/inbox.js +37 -35
  102. package/dist/esm/inference/modelDocumentation.js +14 -12
  103. package/dist/esm/inference/money.js +3 -2
  104. package/dist/esm/inference/priceVersion.js +8 -3
  105. package/dist/esm/inference/providerConnection.js +19 -12
  106. package/dist/esm/inference/realtime.js +85 -44
  107. package/dist/esm/inference/request.js +25 -23
  108. package/dist/esm/inference/routingPolicy.js +9 -7
  109. package/dist/esm/inference/streamEvents.js +20 -14
  110. package/dist/esm/inference/usage.js +30 -13
  111. package/dist/esm/keyRecovery.js +8 -6
  112. package/dist/esm/keyRotation.js +5 -4
  113. package/dist/esm/linkedAccounts.js +20 -16
  114. package/dist/esm/moderationReputation.js +27 -25
  115. package/dist/esm/notifications.js +23 -7
  116. package/dist/esm/numberChecks.js +41 -0
  117. package/dist/esm/oauth.js +14 -12
  118. package/dist/esm/organizations.js +23 -21
  119. package/dist/esm/products/access.js +10 -8
  120. package/dist/esm/products/billing.js +10 -8
  121. package/dist/esm/products/checkout.js +22 -10
  122. package/dist/esm/products/plans.js +15 -10
  123. package/dist/esm/protocol.js +4 -3
  124. package/dist/esm/recommendations.js +25 -17
  125. package/dist/esm/reputation.js +13 -11
  126. package/dist/esm/safety.js +43 -27
  127. package/dist/esm/serviceToken.js +80 -1
  128. package/dist/esm/sessionRevocation.js +6 -4
  129. package/dist/esm/signIn.js +42 -24
  130. package/dist/esm/stickers.js +17 -13
  131. package/dist/esm/stringChecks.js +63 -0
  132. package/dist/esm/transparency.js +14 -12
  133. package/dist/esm/updates.js +22 -20
  134. package/dist/esm/userInvalidation.js +4 -2
  135. package/dist/esm/userResponse.js +4 -3
  136. package/dist/esm/username.js +3 -2
  137. package/dist/types/accountAccess.d.ts +29 -70
  138. package/dist/types/accountEmail.d.ts +2 -14
  139. package/dist/types/accountGraph.d.ts +179 -171
  140. package/dist/types/accountName.d.ts +1 -1
  141. package/dist/types/accountSubject.d.ts +20 -93
  142. package/dist/types/agency.d.ts +528 -2924
  143. package/dist/types/agentKeys.d.ts +48 -421
  144. package/dist/types/appAssertions.d.ts +56 -210
  145. package/dist/types/applicationRoles.d.ts +30 -276
  146. package/dist/types/avatarCharacter.d.ts +1 -1
  147. package/dist/types/civic.d.ts +1 -13
  148. package/dist/types/client/agentKeys.d.ts +18 -18
  149. package/dist/types/client/appAssertions.d.ts +3 -3
  150. package/dist/types/client/check.d.ts +13 -13
  151. package/dist/types/client/deviceDirectory.d.ts +51 -51
  152. package/dist/types/client/deviceSession.d.ts +14 -14
  153. package/dist/types/client/organizations.d.ts +25 -25
  154. package/dist/types/client/products.d.ts +33 -33
  155. package/dist/types/client/recommendations.d.ts +2 -2
  156. package/dist/types/client/safety.d.ts +45 -45
  157. package/dist/types/client/sessionStatus.d.ts +4 -4
  158. package/dist/types/client/signIn.d.ts +1 -1
  159. package/dist/types/commonsSignIn.d.ts +4 -1
  160. package/dist/types/consoleOnboarding.d.ts +24 -44
  161. package/dist/types/contentClaims.d.ts +24 -180
  162. package/dist/types/deviceDirectory.d.ts +109 -1040
  163. package/dist/types/deviceSession.d.ts +36 -298
  164. package/dist/types/email/messages.d.ts +212 -1793
  165. package/dist/types/emailAgentContext.d.ts +10 -194
  166. package/dist/types/externalIdentity.d.ts +121 -615
  167. package/dist/types/federationInstanceFetch.d.ts +3 -32
  168. package/dist/types/identity.d.ts +15 -92
  169. package/dist/types/identityLink.d.ts +6 -84
  170. package/dist/types/identityProof.d.ts +5 -17
  171. package/dist/types/inboxPush.d.ts +1 -9
  172. package/dist/types/index.d.ts +5 -3
  173. package/dist/types/inference/accountBilling.d.ts +151 -488
  174. package/dist/types/inference/aliaModelRelease.d.ts +42 -439
  175. package/dist/types/inference/attribution.d.ts +75 -104
  176. package/dist/types/inference/catalogue.d.ts +417 -1599
  177. package/dist/types/inference/economics.d.ts +69 -276
  178. package/dist/types/inference/embeddings.d.ts +110 -406
  179. package/dist/types/inference/entitlement.d.ts +80 -335
  180. package/dist/types/inference/errors.d.ts +90 -102
  181. package/dist/types/inference/identifiers.d.ts +12 -4
  182. package/dist/types/inference/inbox.d.ts +105 -420
  183. package/dist/types/inference/modelDocumentation.d.ts +201 -1390
  184. package/dist/types/inference/money.d.ts +65 -32
  185. package/dist/types/inference/priceVersion.d.ts +53 -120
  186. package/dist/types/inference/providerConnection.d.ts +253 -710
  187. package/dist/types/inference/realtime.d.ts +954 -6825
  188. package/dist/types/inference/request.d.ts +300 -2572
  189. package/dist/types/inference/routingPolicy.d.ts +95 -503
  190. package/dist/types/inference/streamEvents.d.ts +253 -721
  191. package/dist/types/inference/usage.d.ts +317 -950
  192. package/dist/types/keyRecovery.d.ts +3 -51
  193. package/dist/types/keyRotation.d.ts +3 -38
  194. package/dist/types/linkedAccounts.d.ts +50 -236
  195. package/dist/types/moderationReputation.d.ts +81 -14
  196. package/dist/types/notifications.d.ts +19 -51
  197. package/dist/types/numberChecks.d.ts +9 -0
  198. package/dist/types/oauth.d.ts +101 -809
  199. package/dist/types/organizations.d.ts +268 -921
  200. package/dist/types/oxyRecordTypes.d.ts +11 -1
  201. package/dist/types/products/access.d.ts +125 -775
  202. package/dist/types/products/billing.d.ts +67 -503
  203. package/dist/types/products/checkout.d.ts +16 -69
  204. package/dist/types/products/plans.d.ts +33 -366
  205. package/dist/types/recommendations.d.ts +76 -389
  206. package/dist/types/reputation.d.ts +37 -5
  207. package/dist/types/safety.d.ts +408 -2048
  208. package/dist/types/serviceToken.d.ts +247 -7
  209. package/dist/types/sessionRevocation.d.ts +2 -17
  210. package/dist/types/sessionStatus.d.ts +27 -115
  211. package/dist/types/signIn.d.ts +53 -553
  212. package/dist/types/stickers.d.ts +67 -819
  213. package/dist/types/stringChecks.d.ts +16 -0
  214. package/dist/types/transparency.d.ts +14 -302
  215. package/dist/types/updates.d.ts +60 -316
  216. package/dist/types/userInvalidation.d.ts +4 -13
  217. package/dist/types/userResponse.d.ts +302 -2400
  218. package/dist/types/username.d.ts +3 -3
  219. package/package.json +2 -2
package/dist/esm/civic.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { utf16MinLength } from './stringChecks.js';
1
2
  /**
2
3
  * Civic / Commons API contracts (Fase 1 — DNI + crypto-owned reputation).
3
4
  *
@@ -68,9 +69,9 @@ export const validationVerdictRecordSchema = z.object({
68
69
  /** Request body for opening a validation request (`POST /civic/validations`). */
69
70
  export const validationOpenRequestSchema = z.object({
70
71
  subjectUserId: z.string(),
71
- actionType: z.string().min(1),
72
- sourceActionId: z.string().min(1),
73
- payload: z.record(z.unknown()),
72
+ actionType: z.string().check(utf16MinLength(1)),
73
+ sourceActionId: z.string().check(utf16MinLength(1)),
74
+ payload: z.record(z.string(), z.unknown()),
74
75
  highValue: z.boolean().optional(),
75
76
  });
76
77
  export const validationOpenResultSchema = z.object({
@@ -82,7 +83,7 @@ export const validationRequestSummarySchema = z.object({
82
83
  id: z.string(),
83
84
  subjectUserId: z.string(),
84
85
  actionType: z.string(),
85
- payload: z.record(z.unknown()),
86
+ payload: z.record(z.string(), z.unknown()),
86
87
  payloadHash: z.string(),
87
88
  status: z.enum(['pending', 'quorum_met', 'validated', 'rejected', 'expired']),
88
89
  highValue: z.boolean(),
@@ -128,8 +129,8 @@ export const vouchResultSchema = z.object({
128
129
  });
129
130
  export const credentialRecordSchema = z.object({
130
131
  about: z.string(),
131
- types: z.array(z.string().min(1)).min(1),
132
- claims: z.record(z.unknown()),
132
+ types: z.array(z.string().check(utf16MinLength(1))).min(1),
133
+ claims: z.record(z.string(), z.unknown()),
133
134
  expiresAt: z.number().optional(),
134
135
  });
135
136
  export const verifiableCredentialResponseSchema = z.object({
@@ -140,7 +141,7 @@ export const verifiableCredentialResponseSchema = z.object({
140
141
  issuerUserId: z.string().optional(),
141
142
  issuerDid: z.string(),
142
143
  types: z.array(z.string()),
143
- claims: z.record(z.unknown()),
144
+ claims: z.record(z.string(), z.unknown()),
144
145
  status: z.enum(['active', 'revoked', 'expired']),
145
146
  issuedAt: z.number(),
146
147
  expiresAt: z.number().optional(),
@@ -7,25 +7,25 @@
7
7
  * that bundles the SDK (~120 KB before compression, evaluated at startup). The
8
8
  * checks here give the client the same answers in plain TypeScript.
9
9
  *
10
- * Every check mirrors one Zod 3 schema in this package, and
10
+ * Every check mirrors one Zod 4 schema in this package, and
11
11
  * `__tests__/clientChecks.parity.test.ts` runs both over the same inputs and
12
12
  * requires the same verdict, the same output and the same failing path. The
13
- * rules follow Zod 3 exactly:
13
+ * rules follow Zod 4 exactly:
14
14
  *
15
15
  * string(...rules) a string; `trim`/`toLowerCase` rewrite it, the other
16
16
  * rules test it, in the order given
17
- * number(...rules) a number that is not NaN (Infinity passes, as in Zod)
17
+ * number(...rules) a finite number
18
18
  * literal(v) / oneOf `===` one value / one of a fixed set of strings
19
19
  * optional(c) `undefined` (or an absent key) passes; `null` does not
20
20
  * nullable(c) `null` passes and is kept
21
21
  * withDefault(c, v) `undefined` becomes `v`, which is then checked
22
- * array(c, ...rules) the size rules first, then every element in order
22
+ * array(c, ...rules) upper bounds before elements, lower bounds afterwards
23
23
  * object(shape) unknown keys are DROPPED (Zod's default "strip")
24
24
  * strictObject(shape) unknown keys FAIL (`.strict()`)
25
25
  * looseObject(shape) unknown keys are KEPT (`.passthrough()`)
26
26
  * refine(c, test) a further condition, run once `c` passes
27
27
  * transform(c, f) `f` rewrites the value once `c` passes
28
- * union / discriminatedUnion as Zod 3 reports them
28
+ * union / discriminatedUnion as Zod 4 reports them
29
29
  *
30
30
  * A failure carries the first issue Zod would report and whether Zod would have
31
31
  * stopped there (`fatal`: the type was wrong) or kept checking (`fatal: false`:
@@ -47,13 +47,15 @@ function describe(input) {
47
47
  if (Array.isArray(input))
48
48
  return 'array';
49
49
  if (typeof input === 'number' && Number.isNaN(input))
50
- return 'nan';
50
+ return 'NaN';
51
+ if (typeof input === 'number' && !Number.isFinite(input))
52
+ return String(input);
51
53
  return typeof input;
52
54
  }
53
55
  /** Zod's wording for a value of the wrong type. */
54
56
  function wrongType(path, expected, input) {
55
57
  const received = describe(input);
56
- const message = input === undefined ? 'Required' : `Expected ${expected}, received ${received}`;
58
+ const message = `Invalid input: expected ${expected}, received ${received === 'object' ? 'Object' : received}`;
57
59
  return fail(path, { code: 'invalid_type', message, expected, received }, true);
58
60
  }
59
61
  /** `'a' | 'b'` — how Zod lists allowed values. */
@@ -71,14 +73,14 @@ export function minLength(min, message) {
71
73
  return {
72
74
  test: (value) => value.length >= min,
73
75
  code: 'too_small',
74
- message: message ?? `String must contain at least ${min} character(s)`,
76
+ message: message ?? `Too small: expected string to have >=${min} characters`,
75
77
  };
76
78
  }
77
79
  export function maxLength(max, message) {
78
80
  return {
79
81
  test: (value) => value.length <= max,
80
82
  code: 'too_big',
81
- message: message ?? `String must contain at most ${max} character(s)`,
83
+ message: message ?? `Too big: expected string to have <=${max} characters`,
82
84
  };
83
85
  }
84
86
  export function pattern(regex, message) {
@@ -87,21 +89,21 @@ export function pattern(regex, message) {
87
89
  regex.lastIndex = 0;
88
90
  return regex.test(value);
89
91
  },
90
- code: 'invalid_string',
91
- message: message ?? 'Invalid',
92
+ code: 'invalid_format',
93
+ message: message ?? `Invalid string: must match pattern ${regex}`,
92
94
  };
93
95
  }
94
96
  export function startsWith(prefix) {
95
97
  return {
96
98
  test: (value) => value.startsWith(prefix),
97
- code: 'invalid_string',
98
- message: `Invalid input: must start with "${prefix}"`,
99
+ code: 'invalid_format',
100
+ message: `Invalid string: must start with "${prefix}"`,
99
101
  };
100
102
  }
101
- /** Zod 3's `.email()`. */
103
+ /** Zod 4's `.email()`. */
102
104
  const EMAIL = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9-]*\.)+[A-Z]{2,}$/i;
103
- export const email = pattern(EMAIL, 'Invalid email');
104
- /** Zod 3's `.url()`: anything `new URL()` accepts. */
105
+ export const email = pattern(EMAIL, 'Invalid email address');
106
+ /** The contract's URL check validates with `new URL()` and preserves the original value. */
105
107
  export const url = {
106
108
  test: (value) => {
107
109
  try {
@@ -112,13 +114,13 @@ export const url = {
112
114
  return false;
113
115
  }
114
116
  },
115
- code: 'invalid_string',
116
- message: 'Invalid url',
117
+ code: 'invalid_format',
118
+ message: 'Invalid URL',
117
119
  };
118
- /** Zod 3's `.datetime()`: ISO 8601 in UTC (`Z`), any sub-second precision, leap days checked. */
120
+ /** Zod 4's `.datetime()`: ISO 8601 in UTC (`Z`), any sub-second precision, leap days checked. */
119
121
  const DATETIME = new RegExp('^((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))' +
120
122
  'T([01]\\d|2[0-3]):[0-5]\\d(:[0-5]\\d(\\.\\d+)?)?(Z)$');
121
- export const datetime = pattern(DATETIME, 'Invalid datetime');
123
+ export const datetime = pattern(DATETIME, 'Invalid ISO datetime');
122
124
  export function string(...rules) {
123
125
  return (input, path) => {
124
126
  if (typeof input !== 'string')
@@ -128,41 +130,41 @@ export function string(...rules) {
128
130
  for (const rule of rules) {
129
131
  if ('rewrite' in rule)
130
132
  value = rule.rewrite(value);
131
- else if (firstFailure === null && !rule.test(value)) {
133
+ if ('test' in rule && firstFailure === null && !rule.test(value)) {
132
134
  firstFailure = { code: rule.code, message: rule.message };
133
135
  }
134
136
  }
135
137
  return firstFailure === null ? ok(value) : fail(path, firstFailure, false);
136
138
  };
137
139
  }
138
- /** Zod's `.int()` — reported, as Zod does, as an `invalid_type` that does not stop the parse. */
140
+ /** Integer validation, separate from the contract's optional safe bounds. */
139
141
  export const int = (value) => Number.isInteger(value)
140
142
  ? undefined
141
143
  : {
142
144
  code: 'invalid_type',
143
- message: 'Expected integer, received float',
144
- expected: 'integer',
145
- received: 'float',
145
+ message: 'Invalid input: expected int, received number',
146
+ expected: 'int',
147
+ received: 'number',
146
148
  };
147
149
  export function atLeast(min) {
148
150
  return (value) => value >= min
149
151
  ? undefined
150
- : { code: 'too_small', message: `Number must be greater than or equal to ${min}` };
152
+ : { code: 'too_small', message: `Too small: expected number to be >=${min}` };
151
153
  }
152
154
  export function atMost(max) {
153
155
  return (value) => value <= max
154
156
  ? undefined
155
- : { code: 'too_big', message: `Number must be less than or equal to ${max}` };
157
+ : { code: 'too_big', message: `Too big: expected number to be <=${max}` };
156
158
  }
157
159
  /** Zod's `.positive()`. */
158
- export const positive = (value) => value > 0 ? undefined : { code: 'too_small', message: 'Number must be greater than 0' };
160
+ export const positive = (value) => value > 0 ? undefined : { code: 'too_small', message: 'Too small: expected number to be >0' };
159
161
  /** Zod's `.nonnegative()` (and `.min(0)`). */
160
162
  export const nonnegative = atLeast(0);
161
- /** Zod's `.safe()`: both bounds, low first. */
163
+ /** The contract's explicit safe-number bounds. */
162
164
  export const safe = (value) => atLeast(Number.MIN_SAFE_INTEGER)(value) ?? atMost(Number.MAX_SAFE_INTEGER)(value);
163
165
  export function number(...rules) {
164
166
  return (input, path) => {
165
- if (typeof input !== 'number' || Number.isNaN(input))
167
+ if (typeof input !== 'number' || !Number.isFinite(input))
166
168
  return wrongType(path, 'number', input);
167
169
  for (const rule of rules) {
168
170
  const problem = rule(input);
@@ -177,20 +179,20 @@ export function literal(expected) {
177
179
  return (input, path) => input === expected
178
180
  ? ok(expected)
179
181
  : fail(path, {
180
- code: 'invalid_literal',
181
- message: `Invalid literal value, expected ${JSON.stringify(expected)}`,
182
+ code: 'invalid_value',
183
+ message: `Invalid input: expected ${JSON.stringify(expected)}`,
182
184
  }, true);
183
185
  }
184
186
  /** One of a fixed set of strings — Zod's `z.enum`. */
185
187
  export function oneOf(values) {
186
188
  return (input, path) => {
187
- if (typeof input !== 'string')
188
- return wrongType(path, listValues(values), input);
189
- return values.includes(input)
189
+ return typeof input === 'string' && values.includes(input)
190
190
  ? ok(input)
191
191
  : fail(path, {
192
- code: 'invalid_enum_value',
193
- message: `Invalid enum value. Expected ${listValues(values)}, received '${input}'`,
192
+ code: 'invalid_value',
193
+ message: values.length === 1
194
+ ? `Invalid input: expected ${JSON.stringify(values[0])}`
195
+ : `Invalid option: expected one of ${values.map((value) => JSON.stringify(value)).join('|')}`,
194
196
  }, true);
195
197
  };
196
198
  }
@@ -242,7 +244,7 @@ export function branded(inner) {
242
244
  return inner;
243
245
  }
244
246
  /**
245
- * The issues of a container, as Zod 3 orders them: the first one is reported,
247
+ * The issues of a container, as Zod 4 orders them: the first one is reported,
246
248
  * and the container is fatal when any part of it was.
247
249
  */
248
250
  class Failures {
@@ -262,22 +264,21 @@ export function minItems(min) {
262
264
  return {
263
265
  test: (length) => length >= min,
264
266
  code: 'too_small',
265
- message: `Array must contain at least ${min} element(s)`,
267
+ message: `Too small: expected array to have >=${min} items`,
266
268
  };
267
269
  }
268
270
  export function maxItems(max) {
269
271
  return {
270
272
  test: (length) => length <= max,
271
273
  code: 'too_big',
272
- message: `Array must contain at most ${max} element(s)`,
274
+ message: `Too big: expected array to have <=${max} items`,
273
275
  };
274
276
  }
275
277
  /** Zod's `.length(n)`: `too_big` or `too_small`, by which side it missed. */
276
278
  export function exactItems(count) {
277
- const message = `Array must contain exactly ${count} element(s)`;
278
279
  return [
279
- { test: (length) => length <= count, code: 'too_big', message },
280
- { test: (length) => length >= count, code: 'too_small', message },
280
+ { ...maxItems(count), message: `Too big: expected array to have exactly ${count} items` },
281
+ { ...minItems(count), message: `Too small: expected array to have exactly ${count} items` },
281
282
  ];
282
283
  }
283
284
  export function array(inner, ...rules) {
@@ -285,9 +286,12 @@ export function array(inner, ...rules) {
285
286
  return (input, path) => {
286
287
  if (!Array.isArray(input))
287
288
  return wrongType(path, 'array', input);
288
- // Zod reports the size before any element, then every element in order.
289
+ // Oversized collections abort before walking any element. Lower bounds
290
+ // are checked after elements, matching the patched Zod parser.
289
291
  const size = sizeRules.find((rule) => !rule.test(input.length));
290
- const failures = new Failures(size ? { path, code: size.code, message: size.message } : null);
292
+ if (size?.code === 'too_big')
293
+ return fail(path, { code: size.code, message: size.message }, true);
294
+ const failures = new Failures(null);
291
295
  const out = [];
292
296
  for (let index = 0; index < input.length; index++) {
293
297
  const checked = inner(input[index], [...path, index]);
@@ -296,6 +300,8 @@ export function array(inner, ...rules) {
296
300
  else
297
301
  failures.add(checked);
298
302
  }
303
+ if (size)
304
+ failures.add({ issue: { path, code: size.code, message: size.message }, fatal: false });
299
305
  return failures.result() ?? ok(out);
300
306
  };
301
307
  }
@@ -327,7 +333,7 @@ function objectWith(shape, unknownKeys) {
327
333
  }
328
334
  }
329
335
  if (unknownKeys === 'strict' && unknown.length > 0) {
330
- const message = `Unrecognized key(s) in object: ${listValues(unknown, ', ')}`;
336
+ const message = `Unrecognized key${unknown.length === 1 ? '' : 's'}: ${unknown.map((key) => JSON.stringify(key)).join(', ')}`;
331
337
  failures.add({ issue: { path, code: 'unrecognized_keys', message }, fatal: false });
332
338
  }
333
339
  }
@@ -349,7 +355,7 @@ export function looseObject(shape) {
349
355
  /** Any object, every value kept — Zod's `z.record(z.unknown())`. */
350
356
  export const unknownRecord = (input, path) => {
351
357
  if (!isRecord(input))
352
- return wrongType(path, 'object', input);
358
+ return wrongType(path, 'record', input);
353
359
  const out = {};
354
360
  for (const key in input)
355
361
  if (key !== '__proto__')
@@ -359,21 +365,23 @@ export const unknownRecord = (input, path) => {
359
365
  /* -------------------------------------------------------------------------- */
360
366
  /* Unions */
361
367
  /* -------------------------------------------------------------------------- */
362
- /** The first option that passes; else Zod 3's report (the first option that only failed a rule). */
368
+ /** The first passing option, or the sole non-aborted option's issue; otherwise a union issue. */
363
369
  export function union(...options) {
364
370
  return (input, path) => {
365
- let ruleFailure = null;
371
+ const ruleFailures = [];
366
372
  for (const option of options) {
367
373
  const checked = option(input, path);
368
374
  if (checked.ok)
369
375
  return checked;
370
376
  if (!checked.fatal)
371
- ruleFailure ?? (ruleFailure = checked);
377
+ ruleFailures.push(checked);
372
378
  }
373
- return ruleFailure ?? fail(path, { code: 'invalid_union', message: 'Invalid input' }, true);
379
+ return ruleFailures.length === 1
380
+ ? ruleFailures[0]
381
+ : fail(path, { code: 'invalid_union', message: 'Invalid input' }, true);
374
382
  };
375
383
  }
376
- /** Zod 3's `z.discriminatedUnion(key, options)`, with the options keyed by their tag. */
384
+ /** Zod 4's `z.discriminatedUnion(key, options)`, with the options keyed by their tag. */
377
385
  export function discriminatedUnion(key, options) {
378
386
  return (input, path) => {
379
387
  if (!isRecord(input))
@@ -384,7 +392,7 @@ export function discriminatedUnion(key, options) {
384
392
  : undefined;
385
393
  if (!option) {
386
394
  const message = `Invalid discriminator value. Expected ${listValues(Object.keys(options))}`;
387
- return fail([...path, key], { code: 'invalid_union_discriminator', message }, true);
395
+ return fail([...path, key], { code: 'invalid_union', message }, true);
388
396
  }
389
397
  return option(input, path);
390
398
  };
@@ -1,3 +1,4 @@
1
+ import { utf16MaxLength, utf16MinLength } from './stringChecks.js';
1
2
  /**
2
3
  * Oxy Console first-run onboarding — the wire contract.
3
4
  *
@@ -28,7 +29,7 @@ export const consoleOnboardingStateSchema = z.object({
28
29
  });
29
30
  /** `POST /console/onboarding/terms`. */
30
31
  export const acceptConsoleTermsInputSchema = z.object({
31
- version: z.string().min(1).max(64),
32
+ version: z.string().check(utf16MinLength(1)).check(utf16MaxLength(64)),
32
33
  adultAcknowledged: z.literal(true),
33
34
  /** Understands the account may be suspended or terminated for violating the AUP/Terms. */
34
35
  aupAcknowledged: z.literal(true),
@@ -38,7 +39,11 @@ export const acceptConsoleTermsInputSchema = z.object({
38
39
  export const CONSOLE_USE_CASE_DESCRIPTION_MAX_LENGTH = 2000;
39
40
  export const saveConsoleUseCasesInputSchema = z.object({
40
41
  /** Optional free text; trimmed, and blank counts as absent. */
41
- description: z.string().trim().max(CONSOLE_USE_CASE_DESCRIPTION_MAX_LENGTH).optional(),
42
+ description: z
43
+ .string()
44
+ .trim()
45
+ .check(utf16MaxLength(CONSOLE_USE_CASE_DESCRIPTION_MAX_LENGTH))
46
+ .optional(),
42
47
  useCases: z
43
48
  .array(consoleUseCaseIdSchema)
44
49
  .max(CONSOLE_USE_CASES.length)
@@ -1,3 +1,4 @@
1
+ import { utf16MaxLength, utf16MinLength } from './stringChecks.js';
1
2
  /**
2
3
  * Content claims (ADR 0043 D10): the public "Report content / rights claim"
3
4
  * intake, `POST /content-claims`, and the staff review of a claim.
@@ -41,7 +42,11 @@ function isHttpsUrl(value) {
41
42
  return false;
42
43
  }
43
44
  }
44
- const httpsUrl = (message) => z.string().trim().max(CONTENT_CLAIM_LIMITS.maxUrlLength, message).refine(isHttpsUrl, message);
45
+ const httpsUrl = (message) => z
46
+ .string()
47
+ .trim()
48
+ .check(utf16MaxLength(CONTENT_CLAIM_LIMITS.maxUrlLength, message))
49
+ .refine(isHttpsUrl, message);
45
50
  /**
46
51
  * `POST /content-claims` — a claim, as the claimant sends it. Strict: an
47
52
  * unknown key is refused rather than dropped.
@@ -58,25 +63,25 @@ export const contentClaimSubmissionSchema = z
58
63
  description: z
59
64
  .string({ message: 'contentClaim.errors.descriptionShort' })
60
65
  .trim()
61
- .min(CONTENT_CLAIM_LIMITS.minDescription, 'contentClaim.errors.descriptionShort')
62
- .max(CONTENT_CLAIM_LIMITS.maxDescription, 'contentClaim.errors.descriptionLong'),
66
+ .check(utf16MinLength(CONTENT_CLAIM_LIMITS.minDescription, 'contentClaim.errors.descriptionShort'))
67
+ .check(utf16MaxLength(CONTENT_CLAIM_LIMITS.maxDescription, 'contentClaim.errors.descriptionLong')),
63
68
  originalWorkUrl: httpsUrl('contentClaim.errors.originalWorkUrl').optional(),
64
69
  claimant: z
65
70
  .object({
66
71
  name: z
67
72
  .string({ message: 'contentClaim.errors.name' })
68
73
  .trim()
69
- .min(1, 'contentClaim.errors.name')
70
- .max(CONTENT_CLAIM_LIMITS.maxName, 'contentClaim.errors.name'),
74
+ .check(utf16MinLength(1, 'contentClaim.errors.name'))
75
+ .check(utf16MaxLength(CONTENT_CLAIM_LIMITS.maxName, 'contentClaim.errors.name')),
71
76
  email: z
72
77
  .string({ message: 'contentClaim.errors.email' })
73
78
  .trim()
74
79
  .email('contentClaim.errors.email')
75
- .max(CONTENT_CLAIM_LIMITS.maxEmail, 'contentClaim.errors.email'),
80
+ .check(utf16MaxLength(CONTENT_CLAIM_LIMITS.maxEmail, 'contentClaim.errors.email')),
76
81
  organization: z
77
82
  .string({ message: 'contentClaim.errors.organization' })
78
83
  .trim()
79
- .max(CONTENT_CLAIM_LIMITS.maxOrganization, 'contentClaim.errors.organization')
84
+ .check(utf16MaxLength(CONTENT_CLAIM_LIMITS.maxOrganization, 'contentClaim.errors.organization'))
80
85
  .optional(),
81
86
  relationship: z.enum(CLAIMANT_RELATIONSHIPS, {
82
87
  message: 'contentClaim.errors.relationship',
@@ -86,18 +91,18 @@ export const contentClaimSubmissionSchema = z
86
91
  statements: z
87
92
  .object({
88
93
  goodFaith: z.literal(true, {
89
- errorMap: () => ({ message: 'contentClaim.errors.goodFaith' }),
94
+ error: () => ({ message: 'contentClaim.errors.goodFaith' }),
90
95
  }),
91
96
  accurate: z.literal(true, {
92
- errorMap: () => ({ message: 'contentClaim.errors.accurate' }),
97
+ error: () => ({ message: 'contentClaim.errors.accurate' }),
93
98
  }),
94
99
  }, { message: 'contentClaim.errors.goodFaith' })
95
100
  .strict(),
96
101
  signature: z
97
102
  .string({ message: 'contentClaim.errors.signature' })
98
103
  .trim()
99
- .min(1, 'contentClaim.errors.signature')
100
- .max(CONTENT_CLAIM_LIMITS.maxName, 'contentClaim.errors.signature'),
104
+ .check(utf16MinLength(1, 'contentClaim.errors.signature'))
105
+ .check(utf16MaxLength(CONTENT_CLAIM_LIMITS.maxName, 'contentClaim.errors.signature')),
101
106
  })
102
107
  .strict();
103
108
  // ---------------------------------------------------------------------------
@@ -149,8 +154,12 @@ export const CONTENT_CLAIM_COUNTER_NOTICE_VALIDATION_KEYS = [
149
154
  'contentClaim.counterNotice.errors.signature',
150
155
  ];
151
156
  const N = CONTENT_CLAIM_COUNTER_NOTICE_LIMITS;
152
- const boundedText = (min, max, message) => z.string({ message }).trim().min(min, message).max(max, message);
153
- const affirmed = (message) => z.literal(true, { errorMap: () => ({ message }) });
157
+ const boundedText = (min, max, message) => z
158
+ .string({ message })
159
+ .trim()
160
+ .check(utf16MinLength(min, message))
161
+ .check(utf16MaxLength(max, message));
162
+ const affirmed = (message) => z.literal(true, { error: () => ({ message }) });
154
163
  /**
155
164
  * `POST /content-claims/counter-notices` — the owner of content a claim took
156
165
  * down disputes it (17 U.S.C. § 512(g)(3)). Signed in: the API answers only
@@ -190,7 +199,7 @@ export const contentClaimCounterNoticeSchema = z
190
199
  .string({ message: 'contentClaim.counterNotice.errors.email' })
191
200
  .trim()
192
201
  .email('contentClaim.counterNotice.errors.email')
193
- .max(N.maxEmail, 'contentClaim.counterNotice.errors.email'),
202
+ .check(utf16MaxLength(N.maxEmail, 'contentClaim.counterNotice.errors.email')),
194
203
  }, { message: 'contentClaim.counterNotice.errors.name' })
195
204
  .strict(),
196
205
  material: z
@@ -1,3 +1,5 @@
1
+ import { integerCheck } from './numberChecks.js';
2
+ import { utf16MinLength } from './stringChecks.js';
1
3
  import { z } from 'zod';
2
4
  import { accountKindSchema } from './accountGraph.js';
3
5
  import { activeTokenSchema, deviceSessionStateSchema } from './deviceSession.js';
@@ -45,7 +47,7 @@ export const deviceContextRelationshipSchema = z.enum(['self', 'owner', 'member'
45
47
  * every installed app reads would widen the profile for no rendering gain.
46
48
  */
47
49
  export const deviceDirectoryProfileSchema = z.object({
48
- id: z.string().min(1),
50
+ id: z.string().check(utf16MinLength(1)),
49
51
  username: z.string(),
50
52
  name: userNameSchema.optional(),
51
53
  avatar: z.string().nullable().optional(),
@@ -87,8 +89,8 @@ export const deviceDirectoryProfileSchema = z.object({
87
89
  * recomputes, so it is spelled out here in full.)
88
90
  */
89
91
  export const deviceAccountContextSchema = z.object({
90
- id: z.string().min(1),
91
- accountId: z.string().min(1),
92
+ id: z.string().check(utf16MinLength(1)),
93
+ accountId: z.string().check(utf16MinLength(1)),
92
94
  kind: accountKindSchema,
93
95
  relationship: deviceContextRelationshipSchema,
94
96
  account: deviceDirectoryProfileSchema,
@@ -106,9 +108,9 @@ export const deviceAccountContextSchema = z.object({
106
108
  * an organization must never consume one.
107
109
  */
108
110
  export const devicePrincipalSchema = z.object({
109
- id: z.string().min(1),
110
- userId: z.string().min(1),
111
- authuser: z.number().int().nonnegative(),
111
+ id: z.string().check(utf16MinLength(1)),
112
+ userId: z.string().check(utf16MinLength(1)),
113
+ authuser: z.number().check(integerCheck()).nonnegative(),
112
114
  user: deviceDirectoryProfileSchema,
113
115
  contexts: z.array(deviceAccountContextSchema),
114
116
  });
@@ -121,8 +123,8 @@ export const devicePrincipalSchema = z.object({
121
123
  * away), not an error.
122
124
  */
123
125
  export const deviceDirectorySchema = z.object({
124
- deviceId: z.string().min(1),
125
- revision: z.number().int().nonnegative(),
126
+ deviceId: z.string().check(utf16MinLength(1)),
127
+ revision: z.number().check(integerCheck()).nonnegative(),
126
128
  activeContextId: z.string().nullable(),
127
129
  principals: z.array(devicePrincipalSchema),
128
130
  updatedAt: z.number(),
@@ -135,7 +137,7 @@ export const deviceDirectorySchema = z.object({
135
137
  * that ambiguity server-side would mean guessing inside an authorization path.
136
138
  */
137
139
  export const deviceActivateRequestSchema = z.object({
138
- contextId: z.string().min(1),
140
+ contextId: z.string().check(utf16MinLength(1)),
139
141
  });
140
142
  /**
141
143
  * Response of `POST /session/device/activate`.