@oxy.so/contracts 5.7.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 (227) 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/client/consoleOnboarding.js +24 -0
  12. package/dist/cjs/client/index.js +7 -3
  13. package/dist/cjs/client/safety.js +9 -1
  14. package/dist/cjs/consoleOnboarding.js +56 -0
  15. package/dist/cjs/contentClaims.js +23 -14
  16. package/dist/cjs/deviceDirectory.js +11 -9
  17. package/dist/cjs/deviceSession.js +27 -25
  18. package/dist/cjs/email/messages.js +20 -18
  19. package/dist/cjs/emailAgentContext.js +11 -9
  20. package/dist/cjs/externalIdentity.js +15 -11
  21. package/dist/cjs/federationInstanceFetch.js +12 -7
  22. package/dist/cjs/identity.js +19 -17
  23. package/dist/cjs/identityLink.js +6 -4
  24. package/dist/cjs/identityProof.js +6 -4
  25. package/dist/cjs/inboxPush.js +5 -4
  26. package/dist/cjs/index.js +16 -6
  27. package/dist/cjs/inference/accountBilling.js +35 -33
  28. package/dist/cjs/inference/aliaModelRelease.js +9 -7
  29. package/dist/cjs/inference/attribution.js +14 -12
  30. package/dist/cjs/inference/catalogue.js +35 -29
  31. package/dist/cjs/inference/economics.js +24 -19
  32. package/dist/cjs/inference/embeddings.js +9 -7
  33. package/dist/cjs/inference/entitlement.js +17 -15
  34. package/dist/cjs/inference/errors.js +15 -8
  35. package/dist/cjs/inference/identifiers.js +33 -21
  36. package/dist/cjs/inference/inbox.js +37 -35
  37. package/dist/cjs/inference/modelDocumentation.js +16 -14
  38. package/dist/cjs/inference/money.js +5 -4
  39. package/dist/cjs/inference/priceVersion.js +10 -5
  40. package/dist/cjs/inference/providerConnection.js +21 -14
  41. package/dist/cjs/inference/realtime.js +88 -47
  42. package/dist/cjs/inference/request.js +27 -25
  43. package/dist/cjs/inference/routingPolicy.js +12 -10
  44. package/dist/cjs/inference/streamEvents.js +22 -16
  45. package/dist/cjs/inference/usage.js +32 -15
  46. package/dist/cjs/keyRecovery.js +8 -6
  47. package/dist/cjs/keyRotation.js +5 -4
  48. package/dist/cjs/linkedAccounts.js +22 -18
  49. package/dist/cjs/moderationReputation.js +29 -27
  50. package/dist/cjs/notifications.js +25 -9
  51. package/dist/cjs/numberChecks.js +45 -0
  52. package/dist/cjs/oauth.js +14 -12
  53. package/dist/cjs/organizations.js +23 -21
  54. package/dist/cjs/products/access.js +10 -8
  55. package/dist/cjs/products/billing.js +10 -8
  56. package/dist/cjs/products/checkout.js +22 -10
  57. package/dist/cjs/products/plans.js +15 -10
  58. package/dist/cjs/protocol.js +6 -5
  59. package/dist/cjs/recommendations.js +27 -19
  60. package/dist/cjs/reputation.js +15 -13
  61. package/dist/cjs/safety.js +46 -29
  62. package/dist/cjs/serviceToken.js +81 -2
  63. package/dist/cjs/sessionRevocation.js +8 -6
  64. package/dist/cjs/signIn.js +42 -24
  65. package/dist/cjs/stickers.js +19 -15
  66. package/dist/cjs/stringChecks.js +70 -0
  67. package/dist/cjs/transparency.js +14 -12
  68. package/dist/cjs/updates.js +24 -22
  69. package/dist/cjs/userInvalidation.js +7 -5
  70. package/dist/cjs/userResponse.js +8 -7
  71. package/dist/cjs/username.js +7 -6
  72. package/dist/esm/accountAccess.js +4 -3
  73. package/dist/esm/accountEmail.js +13 -5
  74. package/dist/esm/accountGraph.js +8 -7
  75. package/dist/esm/accountName.js +3 -2
  76. package/dist/esm/agency.js +90 -33
  77. package/dist/esm/agentKeys.js +21 -17
  78. package/dist/esm/appAssertions.js +11 -10
  79. package/dist/esm/applicationRoles.js +16 -9
  80. package/dist/esm/civic.js +8 -7
  81. package/dist/esm/client/check.js +61 -53
  82. package/dist/esm/client/consoleOnboarding.js +21 -0
  83. package/dist/esm/client/index.js +2 -1
  84. package/dist/esm/client/safety.js +8 -0
  85. package/dist/esm/consoleOnboarding.js +51 -0
  86. package/dist/esm/contentClaims.js +23 -14
  87. package/dist/esm/deviceDirectory.js +11 -9
  88. package/dist/esm/deviceSession.js +27 -25
  89. package/dist/esm/email/messages.js +18 -16
  90. package/dist/esm/emailAgentContext.js +11 -9
  91. package/dist/esm/externalIdentity.js +15 -11
  92. package/dist/esm/federationInstanceFetch.js +10 -5
  93. package/dist/esm/identity.js +17 -15
  94. package/dist/esm/identityLink.js +6 -4
  95. package/dist/esm/identityProof.js +6 -4
  96. package/dist/esm/inboxPush.js +3 -2
  97. package/dist/esm/index.js +5 -2
  98. package/dist/esm/inference/accountBilling.js +33 -31
  99. package/dist/esm/inference/aliaModelRelease.js +7 -5
  100. package/dist/esm/inference/attribution.js +14 -12
  101. package/dist/esm/inference/catalogue.js +33 -27
  102. package/dist/esm/inference/economics.js +22 -17
  103. package/dist/esm/inference/embeddings.js +9 -7
  104. package/dist/esm/inference/entitlement.js +15 -13
  105. package/dist/esm/inference/errors.js +13 -6
  106. package/dist/esm/inference/identifiers.js +31 -19
  107. package/dist/esm/inference/inbox.js +37 -35
  108. package/dist/esm/inference/modelDocumentation.js +14 -12
  109. package/dist/esm/inference/money.js +3 -2
  110. package/dist/esm/inference/priceVersion.js +8 -3
  111. package/dist/esm/inference/providerConnection.js +19 -12
  112. package/dist/esm/inference/realtime.js +85 -44
  113. package/dist/esm/inference/request.js +25 -23
  114. package/dist/esm/inference/routingPolicy.js +9 -7
  115. package/dist/esm/inference/streamEvents.js +20 -14
  116. package/dist/esm/inference/usage.js +30 -13
  117. package/dist/esm/keyRecovery.js +8 -6
  118. package/dist/esm/keyRotation.js +5 -4
  119. package/dist/esm/linkedAccounts.js +20 -16
  120. package/dist/esm/moderationReputation.js +27 -25
  121. package/dist/esm/notifications.js +23 -7
  122. package/dist/esm/numberChecks.js +41 -0
  123. package/dist/esm/oauth.js +14 -12
  124. package/dist/esm/organizations.js +23 -21
  125. package/dist/esm/products/access.js +10 -8
  126. package/dist/esm/products/billing.js +10 -8
  127. package/dist/esm/products/checkout.js +22 -10
  128. package/dist/esm/products/plans.js +15 -10
  129. package/dist/esm/protocol.js +4 -3
  130. package/dist/esm/recommendations.js +25 -17
  131. package/dist/esm/reputation.js +13 -11
  132. package/dist/esm/safety.js +45 -29
  133. package/dist/esm/serviceToken.js +80 -1
  134. package/dist/esm/sessionRevocation.js +6 -4
  135. package/dist/esm/signIn.js +42 -24
  136. package/dist/esm/stickers.js +17 -13
  137. package/dist/esm/stringChecks.js +63 -0
  138. package/dist/esm/transparency.js +14 -12
  139. package/dist/esm/updates.js +22 -20
  140. package/dist/esm/userInvalidation.js +4 -2
  141. package/dist/esm/userResponse.js +4 -3
  142. package/dist/esm/username.js +3 -2
  143. package/dist/types/accountAccess.d.ts +29 -70
  144. package/dist/types/accountEmail.d.ts +2 -14
  145. package/dist/types/accountGraph.d.ts +179 -171
  146. package/dist/types/accountName.d.ts +1 -1
  147. package/dist/types/accountSubject.d.ts +20 -93
  148. package/dist/types/agency.d.ts +528 -2924
  149. package/dist/types/agentKeys.d.ts +48 -421
  150. package/dist/types/appAssertions.d.ts +56 -210
  151. package/dist/types/applicationRoles.d.ts +30 -276
  152. package/dist/types/avatarCharacter.d.ts +1 -1
  153. package/dist/types/civic.d.ts +1 -13
  154. package/dist/types/client/agentKeys.d.ts +18 -18
  155. package/dist/types/client/appAssertions.d.ts +3 -3
  156. package/dist/types/client/check.d.ts +13 -13
  157. package/dist/types/client/consoleOnboarding.d.ts +16 -0
  158. package/dist/types/client/deviceDirectory.d.ts +51 -51
  159. package/dist/types/client/deviceSession.d.ts +14 -14
  160. package/dist/types/client/index.d.ts +2 -1
  161. package/dist/types/client/organizations.d.ts +25 -25
  162. package/dist/types/client/products.d.ts +33 -33
  163. package/dist/types/client/recommendations.d.ts +2 -2
  164. package/dist/types/client/safety.d.ts +53 -45
  165. package/dist/types/client/sessionStatus.d.ts +4 -4
  166. package/dist/types/client/signIn.d.ts +1 -1
  167. package/dist/types/commonsSignIn.d.ts +4 -1
  168. package/dist/types/consoleOnboarding.d.ts +57 -0
  169. package/dist/types/contentClaims.d.ts +24 -180
  170. package/dist/types/deviceDirectory.d.ts +109 -1040
  171. package/dist/types/deviceSession.d.ts +36 -298
  172. package/dist/types/email/messages.d.ts +212 -1793
  173. package/dist/types/emailAgentContext.d.ts +10 -194
  174. package/dist/types/externalIdentity.d.ts +121 -615
  175. package/dist/types/federationInstanceFetch.d.ts +3 -32
  176. package/dist/types/identity.d.ts +15 -92
  177. package/dist/types/identityLink.d.ts +6 -84
  178. package/dist/types/identityProof.d.ts +5 -17
  179. package/dist/types/inboxPush.d.ts +1 -9
  180. package/dist/types/index.d.ts +6 -3
  181. package/dist/types/inference/accountBilling.d.ts +151 -488
  182. package/dist/types/inference/aliaModelRelease.d.ts +42 -439
  183. package/dist/types/inference/attribution.d.ts +75 -104
  184. package/dist/types/inference/catalogue.d.ts +417 -1599
  185. package/dist/types/inference/economics.d.ts +69 -276
  186. package/dist/types/inference/embeddings.d.ts +110 -406
  187. package/dist/types/inference/entitlement.d.ts +80 -335
  188. package/dist/types/inference/errors.d.ts +90 -102
  189. package/dist/types/inference/identifiers.d.ts +12 -4
  190. package/dist/types/inference/inbox.d.ts +105 -420
  191. package/dist/types/inference/modelDocumentation.d.ts +201 -1390
  192. package/dist/types/inference/money.d.ts +65 -32
  193. package/dist/types/inference/priceVersion.d.ts +53 -120
  194. package/dist/types/inference/providerConnection.d.ts +253 -710
  195. package/dist/types/inference/realtime.d.ts +954 -6825
  196. package/dist/types/inference/request.d.ts +300 -2572
  197. package/dist/types/inference/routingPolicy.d.ts +95 -503
  198. package/dist/types/inference/streamEvents.d.ts +253 -721
  199. package/dist/types/inference/usage.d.ts +317 -950
  200. package/dist/types/keyRecovery.d.ts +3 -51
  201. package/dist/types/keyRotation.d.ts +3 -38
  202. package/dist/types/linkedAccounts.d.ts +50 -236
  203. package/dist/types/moderationReputation.d.ts +81 -14
  204. package/dist/types/notifications.d.ts +19 -51
  205. package/dist/types/numberChecks.d.ts +9 -0
  206. package/dist/types/oauth.d.ts +101 -809
  207. package/dist/types/organizations.d.ts +268 -921
  208. package/dist/types/oxyRecordTypes.d.ts +11 -1
  209. package/dist/types/products/access.d.ts +125 -775
  210. package/dist/types/products/billing.d.ts +67 -503
  211. package/dist/types/products/checkout.d.ts +16 -69
  212. package/dist/types/products/plans.d.ts +33 -366
  213. package/dist/types/recommendations.d.ts +76 -389
  214. package/dist/types/reputation.d.ts +37 -5
  215. package/dist/types/safety.d.ts +410 -2050
  216. package/dist/types/serviceToken.d.ts +247 -7
  217. package/dist/types/sessionRevocation.d.ts +2 -17
  218. package/dist/types/sessionStatus.d.ts +27 -115
  219. package/dist/types/signIn.d.ts +53 -553
  220. package/dist/types/stickers.d.ts +67 -819
  221. package/dist/types/stringChecks.d.ts +16 -0
  222. package/dist/types/transparency.d.ts +14 -302
  223. package/dist/types/updates.d.ts +60 -316
  224. package/dist/types/userInvalidation.d.ts +4 -13
  225. package/dist/types/userResponse.d.ts +302 -2400
  226. package/dist/types/username.d.ts +3 -3
  227. package/package.json +3 -4
@@ -1,7 +1,8 @@
1
+ import { isoDateTime, utf16MaxLength, utf16MinLength } from './stringChecks.js';
1
2
  import { z } from 'zod';
2
3
  /** Omitted means the existing grant; an explicit set only narrows that authority. */
3
4
  export const serviceTokenScopesSchema = z
4
- .array(z.string().trim().min(1).max(128))
5
+ .array(z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(128)))
5
6
  .min(1)
6
7
  .max(100)
7
8
  .refine((scopes) => new Set(scopes).size === scopes.length, 'Requested scopes must be unique')
@@ -9,3 +10,81 @@ export const serviceTokenScopesSchema = z
9
10
  export const serviceTokenOptionsSchema = z
10
11
  .object({ scopes: serviceTokenScopesSchema.optional() })
11
12
  .strict();
13
+ /** First-party authority is issued only to an attested, live Oxy workload. */
14
+ export const serviceAuthoritySchema = z.enum(['first_party', 'external']);
15
+ const resourceIdentity = {
16
+ active: z.literal(true),
17
+ accountId: z.string().check(utf16MinLength(1)),
18
+ applicationId: z.string().check(utf16MinLength(1)),
19
+ credentialId: z.string().check(utf16MinLength(1)),
20
+ environment: z.enum(['production', 'staging', 'development']),
21
+ audience: z.string().check(utf16MinLength(1)),
22
+ expiresAt: z.string().check(isoDateTime()),
23
+ };
24
+ /** No scope list exists in the internal authority variant. */
25
+ export const firstPartyServicePrincipalSchema = z.object({
26
+ ...resourceIdentity,
27
+ authority: z.literal('first_party'),
28
+ scopes: z.never().optional(),
29
+ });
30
+ export const externalServicePrincipalSchema = z.object({
31
+ ...resourceIdentity,
32
+ authority: z.literal('external'),
33
+ scopes: z.array(z.string().check(utf16MinLength(1))),
34
+ });
35
+ export const servicePrincipalSchema = z.discriminatedUnion('authority', [
36
+ firstPartyServicePrincipalSchema,
37
+ externalServicePrincipalSchema,
38
+ ]);
39
+ export const serviceIntrospectionSchema = z.union([
40
+ z.object({ active: z.literal(false) }),
41
+ servicePrincipalSchema,
42
+ ]);
43
+ /** A resource receiver introspects services, external keys and human sessions distinctly. */
44
+ const sessionIdentity = {
45
+ active: z.literal(true),
46
+ kind: z.literal('session'),
47
+ permissions: z.array(z.string()),
48
+ accountId: z.string().check(utf16MinLength(1)),
49
+ requesterAccountId: z.string().check(utf16MinLength(1)),
50
+ effectiveAccountId: z.string().check(utf16MinLength(1)),
51
+ expiresAt: z.string().check(isoDateTime()),
52
+ };
53
+ export const resourcePrincipalSchema = z.union([
54
+ firstPartyServicePrincipalSchema.extend({
55
+ kind: z.literal('service'),
56
+ permissions: z.array(z.string()),
57
+ }),
58
+ externalServicePrincipalSchema.extend({
59
+ kind: z.literal('service'),
60
+ permissions: z.array(z.string()),
61
+ }),
62
+ z.object({
63
+ active: z.literal(true),
64
+ kind: z.literal('key'),
65
+ expiresAt: z.string().check(isoDateTime()).optional(),
66
+ permissions: z.array(z.string()),
67
+ authority: z.literal('external'),
68
+ accountId: z.string().check(utf16MinLength(1)),
69
+ applicationId: z.string().check(utf16MinLength(1)),
70
+ credentialId: z.string().check(utf16MinLength(1)),
71
+ environment: z.enum(['production', 'staging', 'development']),
72
+ scopes: z.array(z.string().check(utf16MinLength(1))),
73
+ }),
74
+ z.object({
75
+ ...sessionIdentity,
76
+ authority: z.literal('first_party'),
77
+ applicationId: z.null(),
78
+ scopes: z.never().optional(),
79
+ }),
80
+ z.object({
81
+ ...sessionIdentity,
82
+ authority: z.literal('external'),
83
+ applicationId: z.string().check(utf16MinLength(1)),
84
+ scopes: z.array(z.string().check(utf16MinLength(1))),
85
+ }),
86
+ ]);
87
+ export const resourceIntrospectionSchema = z.union([
88
+ z.object({ active: z.literal(false) }),
89
+ resourcePrincipalSchema,
90
+ ]);
@@ -1,3 +1,5 @@
1
+ import { integerCheck } from './numberChecks.js';
2
+ import { utf16MaxLength, utf16MinLength } from './stringChecks.js';
1
3
  /**
2
4
  * Canonical contract for the session-revocation feed: oxy-api telling every
3
5
  * connected Oxy backend that a session stopped being valid.
@@ -74,13 +76,13 @@ export const OXY_SERVICE_EVENTS_FORBIDDEN = 'service_events_forbidden';
74
76
  */
75
77
  export const oxySessionRevocationEventSchema = z.object({
76
78
  /** The session that ended; absent for a revocation of every session of `userId`. */
77
- sessionId: z.string().min(1).max(256).optional(),
79
+ sessionId: z.string().check(utf16MinLength(1)).check(utf16MaxLength(256)).optional(),
78
80
  /** The account the session (or sessions) spoke as. */
79
- userId: z.string().min(1).max(256),
81
+ userId: z.string().check(utf16MinLength(1)).check(utf16MaxLength(256)),
80
82
  /** Publisher's epoch-ms timestamp. Diagnostic only. */
81
- at: z.number().int().nonnegative(),
83
+ at: z.number().check(integerCheck()).nonnegative(),
82
84
  });
83
85
  /** The heartbeat payload. */
84
86
  export const oxyServiceEventsHeartbeatSchema = z.object({
85
- at: z.number().int().nonnegative(),
87
+ at: z.number().check(integerCheck()).nonnegative(),
86
88
  });
@@ -1,3 +1,5 @@
1
+ import { integerCheck } from './numberChecks.js';
2
+ import { utf16MaxLength, utf16MinLength } from './stringChecks.js';
1
3
  /**
2
4
  * Signing in: an email code or link, an optional password,
3
5
  * and an optional authenticator app (TOTP) as a second factor.
@@ -46,23 +48,39 @@ const sixDigits = z
46
48
  */
47
49
  const opaqueTokenSchema = emailTicketSchema;
48
50
  /** A username or an email. */
49
- export const signInIdentifierSchema = z.string().trim().min(1).max(254);
51
+ export const signInIdentifierSchema = z
52
+ .string()
53
+ .trim()
54
+ .check(utf16MinLength(1))
55
+ .check(utf16MaxLength(254));
50
56
  /** A password as typed. Its policy applies only when one is set. */
51
- export const passwordInputSchema = z.string().min(1).max(PASSWORD_MAX_LENGTH);
57
+ export const passwordInputSchema = z
58
+ .string()
59
+ .check(utf16MinLength(1))
60
+ .check(utf16MaxLength(PASSWORD_MAX_LENGTH));
52
61
  /** A new password. */
53
62
  export const newPasswordSchema = z
54
63
  .string()
55
- .min(PASSWORD_MIN_LENGTH, `password must be at least ${PASSWORD_MIN_LENGTH} characters`)
56
- .max(PASSWORD_MAX_LENGTH, `password must be at most ${PASSWORD_MAX_LENGTH} characters`);
64
+ .check(utf16MinLength(PASSWORD_MIN_LENGTH, `password must be at least ${PASSWORD_MIN_LENGTH} characters`))
65
+ .check(utf16MaxLength(PASSWORD_MAX_LENGTH, `password must be at most ${PASSWORD_MAX_LENGTH} characters`));
57
66
  /**
58
67
  * An authenticator code (6 digits) or a backup code (10 characters, with or
59
68
  * without its dash). Normalised server-side.
60
69
  */
61
- export const secondFactorCodeSchema = z.string().trim().min(TOTP_DIGITS).max(16);
70
+ export const secondFactorCodeSchema = z
71
+ .string()
72
+ .trim()
73
+ .check(utf16MinLength(TOTP_DIGITS))
74
+ .check(utf16MaxLength(16));
62
75
  /** The device-session fields every body that ends in a session may carry. */
63
76
  const sessionEnvelope = {
64
- deviceName: z.string().trim().min(1).max(120).optional(),
65
- deviceFingerprint: z.string().trim().min(1).max(256).optional(),
77
+ deviceName: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(120)).optional(),
78
+ deviceFingerprint: z
79
+ .string()
80
+ .trim()
81
+ .check(utf16MinLength(1))
82
+ .check(utf16MaxLength(256))
83
+ .optional(),
66
84
  /** Proof of the browser's shared device; invalid → the session gets its own. */
67
85
  device: deviceProofSchema.optional(),
68
86
  };
@@ -75,9 +93,9 @@ export const emailSignInStartRequestSchema = z
75
93
  })
76
94
  .strict();
77
95
  export const emailSignInStartResponseSchema = z.object({
78
- requestId: z.string().min(1).max(64),
96
+ requestId: z.string().check(utf16MinLength(1)).check(utf16MaxLength(64)),
79
97
  requestSecret: opaqueTokenSchema,
80
- expiresAt: z.number().int().positive(),
98
+ expiresAt: z.number().check(integerCheck()).positive(),
81
99
  retryLater: z.literal(true).optional(),
82
100
  });
83
101
  /**
@@ -100,7 +118,7 @@ export const emailSignInCodeSchema = z
100
118
  /** `POST /auth/signin/email/confirm` — the code from the email. */
101
119
  export const emailSignInConfirmRequestSchema = z
102
120
  .object({
103
- requestId: z.string().trim().min(1).max(64),
121
+ requestId: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(64)),
104
122
  requestSecret: opaqueTokenSchema,
105
123
  code: emailSignInCodeSchema,
106
124
  ...sessionEnvelope,
@@ -109,7 +127,7 @@ export const emailSignInConfirmRequestSchema = z
109
127
  /** `POST /auth/signin/email/collect` — the dialog asks whether its link was opened. */
110
128
  export const emailSignInCollectRequestSchema = z
111
129
  .object({
112
- requestId: z.string().trim().min(1).max(64),
130
+ requestId: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(64)),
113
131
  requestSecret: opaqueTokenSchema,
114
132
  ...sessionEnvelope,
115
133
  })
@@ -147,7 +165,7 @@ export const secondFactorSignInRequestSchema = z
147
165
  /** `POST /auth/signup` — the account, from a username and a confirmed email. */
148
166
  export const signUpRequestSchema = z
149
167
  .object({
150
- username: z.string().trim().min(1).max(60),
168
+ username: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(60)),
151
169
  email: emailAddressSchema,
152
170
  /** The ticket `POST /auth/email/verify/confirm` (purpose `signup`) returned. */
153
171
  emailTicket: emailTicketSchema,
@@ -157,29 +175,29 @@ export const signUpRequestSchema = z
157
175
  export const secondFactorRequiredSchema = z.object({
158
176
  secondFactorRequired: z.literal(true),
159
177
  challengeId: opaqueTokenSchema,
160
- expiresAt: z.number().int().positive(),
178
+ expiresAt: z.number().check(integerCheck()).positive(),
161
179
  });
162
180
  export const emailSignInPendingSchema = z.object({
163
181
  status: z.literal('pending'),
164
- expiresAt: z.number().int().positive(),
182
+ expiresAt: z.number().check(integerCheck()).positive(),
165
183
  });
166
184
  export const emailSignInAccountOptionSchema = z.object({
167
- id: z.string().min(1).max(64),
168
- username: z.string().min(1).optional(),
169
- displayName: z.string().min(1).optional(),
170
- avatar: z.string().min(1).optional(),
185
+ id: z.string().check(utf16MinLength(1)).check(utf16MaxLength(64)),
186
+ username: z.string().check(utf16MinLength(1)).optional(),
187
+ displayName: z.string().check(utf16MinLength(1)).optional(),
188
+ avatar: z.string().check(utf16MinLength(1)).optional(),
171
189
  });
172
190
  export const emailSignInChooseAccountSchema = z.object({
173
191
  chooseAccount: z.literal(true),
174
192
  accounts: z.array(emailSignInAccountOptionSchema).min(2).max(EMAIL_ACCOUNTS_MAX),
175
- expiresAt: z.number().int().positive(),
193
+ expiresAt: z.number().check(integerCheck()).positive(),
176
194
  });
177
195
  /** `POST /auth/signin/email/choose` — the account, from those {@link EmailSignInChooseAccount} listed. */
178
196
  export const emailSignInChooseRequestSchema = z
179
197
  .object({
180
- requestId: z.string().trim().min(1).max(64),
198
+ requestId: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(64)),
181
199
  requestSecret: opaqueTokenSchema,
182
- userId: z.string().trim().min(1).max(64),
200
+ userId: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(64)),
183
201
  ...sessionEnvelope,
184
202
  })
185
203
  .strict();
@@ -196,7 +214,7 @@ export const reauthProofSchema = z
196
214
  password: passwordInputSchema.optional(),
197
215
  emailCode: z
198
216
  .object({
199
- verificationId: z.string().trim().min(1).max(64),
217
+ verificationId: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(64)),
200
218
  code: sixDigits,
201
219
  })
202
220
  .strict()
@@ -233,7 +251,7 @@ export const emailChangeStartRequestSchema = z.object({ email: emailAddressSchem
233
251
  export const emailSetRequestSchema = z
234
252
  .object({
235
253
  email: emailAddressSchema,
236
- verificationId: z.string().trim().min(1).max(64),
254
+ verificationId: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(64)),
237
255
  code: sixDigits,
238
256
  reauth: reauthProofSchema,
239
257
  })
@@ -242,7 +260,7 @@ export const signInMethodsSchema = z.object({
242
260
  hasEmail: z.boolean(),
243
261
  hasPassword: z.boolean(),
244
262
  totpEnabled: z.boolean(),
245
- backupCodesRemaining: z.number().int().min(0),
263
+ backupCodesRemaining: z.number().check(integerCheck()).min(0),
246
264
  });
247
265
  export const totpEnrollResponseSchema = z.object({
248
266
  secret: z.string().regex(/^[A-Z2-7]+$/),
@@ -1,3 +1,5 @@
1
+ import { integerCheck } from './numberChecks.js';
2
+ import { urlCheck, utf16MaxLength, utf16MinLength } from './stringChecks.js';
1
3
  /**
2
4
  * Stickers — the wire shape of Oxy's shared sticker catalogue.
3
5
  *
@@ -59,17 +61,17 @@ export const stickerSha256Schema = z
59
61
  /** A pack's public URL segment. */
60
62
  export const stickerPackSlugSchema = z
61
63
  .string()
62
- .min(2)
63
- .max(64)
64
+ .check(utf16MinLength(2))
65
+ .check(utf16MaxLength(64))
64
66
  .regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, 'slug must be lowercase words joined by hyphens');
65
- export const stickerIdSchema = z.string().min(1).max(64);
67
+ export const stickerIdSchema = z.string().check(utf16MinLength(1)).check(utf16MaxLength(64));
66
68
  export const stickerPackStatusSchema = z.enum(['draft', 'published', 'archived']);
67
69
  /** One stored file: where to fetch it and the hash its bytes must have. */
68
70
  export const stickerFileSchema = z.object({
69
- url: z.string().url(),
71
+ url: z.string().check(urlCheck()),
70
72
  sha256: stickerSha256Schema,
71
73
  mime: z.string(),
72
- bytes: z.number().int().nonnegative(),
74
+ bytes: z.number().check(integerCheck()).nonnegative(),
73
75
  });
74
76
  /* -------------------------------------------------------------------------- */
75
77
  /* Catalogue */
@@ -79,8 +81,8 @@ export const stickerSchema = z.object({
79
81
  packId: z.string(),
80
82
  emoji: z.array(z.string()).min(1),
81
83
  keywords: z.array(z.string()),
82
- size: z.number().int().positive(),
83
- durationMs: z.number().int().positive(),
84
+ size: z.number().check(integerCheck()).positive(),
85
+ durationMs: z.number().check(integerCheck()).positive(),
84
86
  /** The Lottie JSON. */
85
87
  animation: stickerFileSchema,
86
88
  /** A static image of the same sticker. */
@@ -95,7 +97,7 @@ export const stickerPackSummarySchema = z.object({
95
97
  author: z.string().nullable(),
96
98
  status: stickerPackStatusSchema,
97
99
  publishedAt: z.string().nullable(),
98
- stickerCount: z.number().int().nonnegative(),
100
+ stickerCount: z.number().check(integerCheck()).nonnegative(),
99
101
  /** The first sticker, drawn as the pack's cover. Null for an empty draft. */
100
102
  cover: stickerSchema.nullable(),
101
103
  });
@@ -117,7 +119,7 @@ export const installedStickerPackSchema = stickerPackSchema.extend({
117
119
  */
118
120
  export const stickerRefSchema = z.object({
119
121
  stickerId: stickerIdSchema,
120
- packId: z.string().min(1).max(64),
122
+ packId: z.string().check(utf16MinLength(1)).check(utf16MaxLength(64)),
121
123
  sha256: stickerSha256Schema,
122
124
  });
123
125
  /* -------------------------------------------------------------------------- */
@@ -133,14 +135,16 @@ export const resolveStickersResponseSchema = z.object({
133
135
  });
134
136
  /** PATCH /stickers/me/packs/order — the installed pack ids, first to last. */
135
137
  export const reorderStickerPacksRequestSchema = z.object({
136
- packIds: z.array(z.string().min(1).max(64)).max(STICKER_MAX_INSTALLED_PACKS),
138
+ packIds: z
139
+ .array(z.string().check(utf16MinLength(1)).check(utf16MaxLength(64)))
140
+ .max(STICKER_MAX_INSTALLED_PACKS),
137
141
  });
138
142
  /** POST /stickers/admin/packs */
139
143
  export const createStickerPackRequestSchema = z.object({
140
144
  slug: stickerPackSlugSchema,
141
- title: z.string().trim().min(1).max(64),
142
- description: z.string().trim().max(500).nullish(),
143
- author: z.string().trim().max(64).nullish(),
145
+ title: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(64)),
146
+ description: z.string().trim().check(utf16MaxLength(500)).nullish(),
147
+ author: z.string().trim().check(utf16MaxLength(64)).nullish(),
144
148
  });
145
149
  /** PATCH /stickers/admin/packs/:packId */
146
150
  export const updateStickerPackRequestSchema = createStickerPackRequestSchema
@@ -0,0 +1,63 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Oxy text limits count UTF-16 units. Each factory owns its check and retains
4
+ * native metadata for standard JSON Schema and OpenAPI consumers.
5
+ */
6
+ function stringLengthCheck(kind, value, message) {
7
+ const check = kind === 'min'
8
+ ? z.minLength(value, message)
9
+ : kind === 'max'
10
+ ? z.maxLength(value, message)
11
+ : z.length(value, message);
12
+ check._zod.check = (context) => {
13
+ const length = context.value.length;
14
+ const tooSmall = kind !== 'max' && length < value;
15
+ const tooBig = kind !== 'min' && length > value;
16
+ if (!tooSmall && !tooBig)
17
+ return;
18
+ context.issues.push({
19
+ origin: 'string',
20
+ ...(tooSmall
21
+ ? { code: 'too_small', minimum: value }
22
+ : { code: 'too_big', maximum: value }),
23
+ inclusive: true,
24
+ ...(kind === 'length' ? { exact: true } : {}),
25
+ input: context.value,
26
+ inst: check,
27
+ continue: true,
28
+ });
29
+ };
30
+ return check;
31
+ }
32
+ export function utf16MinLength(minimum, message) {
33
+ return stringLengthCheck('min', minimum, message);
34
+ }
35
+ export function utf16MaxLength(maximum, message) {
36
+ return stringLengthCheck('max', maximum, message);
37
+ }
38
+ export function utf16Length(length, message) {
39
+ return stringLengthCheck('length', length, message);
40
+ }
41
+ /** Oxy timestamps retain optional seconds, fractional precision and existing offset syntax. */
42
+ export function isoDateTime(options = {}) {
43
+ const params = typeof options === 'string' ? { message: options } : options;
44
+ const precision = params.precision;
45
+ const date = z.regexes.date.source.slice(1, -1);
46
+ const fraction = precision ? `\\.\\d{${precision}}` : precision == null ? '(\\.\\d+)?' : '';
47
+ const seconds = `(:[0-5]\\d${fraction})${precision ? '+' : '?'}`;
48
+ const zone = `${params.local ? 'Z?' : 'Z'}${params.offset ? '|[+-]\\d{2}:?\\d{2}' : ''}`;
49
+ const expression = new RegExp(`^${date}T([01]\\d|2[0-3]):[0-5]\\d${seconds}(${zone})$`);
50
+ return z.stringFormat('datetime', expression, params);
51
+ }
52
+ /** Validate a URL without normalizing the value returned by the API contract. */
53
+ export function urlCheck(message) {
54
+ return z.stringFormat('url', (value) => {
55
+ try {
56
+ new URL(value);
57
+ return true;
58
+ }
59
+ catch {
60
+ return false;
61
+ }
62
+ }, message);
63
+ }
@@ -1,3 +1,5 @@
1
+ import { integerCheck } from './numberChecks.js';
2
+ import { utf16MinLength } from './stringChecks.js';
1
3
  import { z } from 'zod';
2
4
  /**
3
5
  * Transparency log — the public wire contract of the checkpoint surface.
@@ -31,19 +33,19 @@ const hexDigestSchema = z
31
33
  */
32
34
  export const transparencyCheckpointSignatureSchema = z.object({
33
35
  /** Uncompressed hex public key of the signer. */
34
- publicKey: z.string().min(1),
36
+ publicKey: z.string().check(utf16MinLength(1)),
35
37
  alg: z.literal('ES256K-DER-SHA256'),
36
38
  /** DER-encoded hex secp256k1 signature over the checkpoint signing input. */
37
- signature: z.string().min(1),
39
+ signature: z.string().check(utf16MinLength(1)),
38
40
  });
39
41
  /** Where a checkpoint root was published on a public chain. */
40
42
  export const transparencyAnchorSchema = z.object({
41
43
  /** Chain/network identifier, e.g. `faircoin-main`. */
42
- network: z.string().min(1),
43
- txid: z.string().min(1),
44
- confirmations: z.number().int().nonnegative(),
44
+ network: z.string().check(utf16MinLength(1)),
45
+ txid: z.string().check(utf16MinLength(1)),
46
+ confirmations: z.number().check(integerCheck()).nonnegative(),
45
47
  /** When the anchoring transaction was broadcast (ms epoch). */
46
- anchoredAt: z.number().int().positive(),
48
+ anchoredAt: z.number().check(integerCheck()).positive(),
47
49
  });
48
50
  /**
49
51
  * A published checkpoint.
@@ -54,11 +56,11 @@ export const transparencyAnchorSchema = z.object({
54
56
  * normal, temporary state rather than an error.
55
57
  */
56
58
  export const transparencyCheckpointSchema = z.object({
57
- index: z.number().int().nonnegative(),
59
+ index: z.number().check(integerCheck()).nonnegative(),
58
60
  /** End of the committed period (ms epoch). */
59
- periodEnd: z.number().int().positive(),
61
+ periodEnd: z.number().check(integerCheck()).positive(),
60
62
  /** Number of subjects (leaves) committed. */
61
- treeSize: z.number().int().nonnegative(),
63
+ treeSize: z.number().check(integerCheck()).nonnegative(),
62
64
  root: hexDigestSchema,
63
65
  /** Hash of the previous checkpoint; `null` only at genesis. */
64
66
  prevCheckpointHash: hexDigestSchema.nullable(),
@@ -74,11 +76,11 @@ export const transparencyCheckpointSchema = z.object({
74
76
  */
75
77
  export const transparencyInclusionProofSchema = z.object({
76
78
  checkpoint: transparencyCheckpointSchema,
77
- subjectDid: z.string().min(1),
78
- seq: z.number().int().nonnegative(),
79
+ subjectDid: z.string().check(utf16MinLength(1)),
80
+ seq: z.number().check(integerCheck()).nonnegative(),
79
81
  headRecordId: hexDigestSchema,
80
82
  leaf: hexDigestSchema,
81
- leafIndex: z.number().int().nonnegative(),
83
+ leafIndex: z.number().check(integerCheck()).nonnegative(),
82
84
  /** Audit path, leaf-adjacent sibling first; empty for a single-leaf tree. */
83
85
  proof: z.array(hexDigestSchema),
84
86
  });
@@ -1,3 +1,5 @@
1
+ import { integerCheck } from './numberChecks.js';
2
+ import { utf16MaxLength, utf16MinLength } from './stringChecks.js';
1
3
  /**
2
4
  * Oxy Updates (self-hosted expo-updates protocol) — publish/admin API contracts.
3
5
  *
@@ -44,13 +46,13 @@ export const sha256HexSchema = z
44
46
  */
45
47
  export const channelNameSchema = z
46
48
  .string()
47
- .min(1)
48
- .max(100)
49
+ .check(utf16MinLength(1))
50
+ .check(utf16MaxLength(100))
49
51
  .regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/, 'channel name must be a URL-safe slug');
50
52
  /** A runtime version string (expo-updates `runtimeVersion`, e.g. an appVersion). */
51
- export const runtimeVersionSchema = z.string().min(1).max(255);
53
+ export const runtimeVersionSchema = z.string().check(utf16MinLength(1)).check(utf16MaxLength(255));
52
54
  /** A rollout percentage: 0 rolls out to nobody, 100 to everybody. */
53
- export const rolloutPercentSchema = z.number().int().min(0).max(100);
55
+ export const rolloutPercentSchema = z.number().check(integerCheck()).min(0).max(100);
54
56
  /* -------------------------------------------------------------------------- */
55
57
  /* Assets: init + complete */
56
58
  /* -------------------------------------------------------------------------- */
@@ -61,8 +63,8 @@ export const rolloutPercentSchema = z.number().int().min(0).max(100);
61
63
  */
62
64
  export const assetInitItemSchema = z.object({
63
65
  sha256: sha256HexSchema,
64
- contentType: z.string().min(1).max(255),
65
- size: z.number().int().positive(),
66
+ contentType: z.string().check(utf16MinLength(1)).check(utf16MaxLength(255)),
67
+ size: z.number().check(integerCheck()).positive(),
66
68
  });
67
69
  /**
68
70
  * `POST /updates/v1/assets/init` request. Declares the full asset set of an
@@ -70,7 +72,7 @@ export const assetInitItemSchema = z.object({
70
72
  * already hold (content-addressed dedup — unchanged assets are never re-uploaded).
71
73
  */
72
74
  export const assetInitRequestSchema = z.object({
73
- applicationId: z.string().min(1),
75
+ applicationId: z.string().check(utf16MinLength(1)),
74
76
  assets: z.array(assetInitItemSchema).min(1).max(2000),
75
77
  });
76
78
  /** One presigned upload the client must PUT its bytes to before completing. */
@@ -106,14 +108,14 @@ export const assetInitResponseSchema = z.object({
106
108
  * `uploaded`; an object that is absent or size-mismatched is rejected.
107
109
  */
108
110
  export const assetCompleteRequestSchema = z.object({
109
- applicationId: z.string().min(1),
111
+ applicationId: z.string().check(utf16MinLength(1)),
110
112
  sha256s: z.array(sha256HexSchema).min(1).max(2000),
111
113
  });
112
114
  /** Per-asset verification outcome from `assets/complete`. */
113
115
  export const assetCompleteResultItemSchema = z.object({
114
116
  sha256: sha256HexSchema,
115
117
  status: updateAssetStatusSchema,
116
- size: z.number().int().nonnegative(),
118
+ size: z.number().check(integerCheck()).nonnegative(),
117
119
  });
118
120
  export const assetCompleteResponseSchema = z.object({
119
121
  assets: z.array(assetCompleteResultItemSchema),
@@ -129,8 +131,8 @@ export const assetCompleteResponseSchema = z.object({
129
131
  export const updateAssetRefSchema = z.object({
130
132
  sha256: sha256HexSchema,
131
133
  /** expo-export asset key (md5 basename) — how app code references the asset. */
132
- key: z.string().min(1),
133
- contentType: z.string().min(1),
134
+ key: z.string().check(utf16MinLength(1)),
135
+ contentType: z.string().check(utf16MinLength(1)),
134
136
  /** Suggested file extension including the leading dot (e.g. `.js`, `.png`). */
135
137
  fileExtension: z.string().optional(),
136
138
  });
@@ -141,7 +143,7 @@ export const updateAssetRefSchema = z.object({
141
143
  * MUST carry `expoClient` so `Constants.expoConfig` works after an OTA update.
142
144
  */
143
145
  export const createUpdateRequestSchema = z.object({
144
- applicationId: z.string().min(1),
146
+ applicationId: z.string().check(utf16MinLength(1)),
145
147
  channel: channelNameSchema,
146
148
  runtimeVersion: runtimeVersionSchema,
147
149
  platform: updatePlatformSchema,
@@ -159,11 +161,11 @@ export const createUpdateRequestSchema = z.object({
159
161
  /** Initial rollout percentage (default 100 — full rollout). */
160
162
  rolloutPercent: rolloutPercentSchema.optional(),
161
163
  /** Git commit the bundle was built from (audit / console display). */
162
- gitCommit: z.string().max(100).optional(),
164
+ gitCommit: z.string().check(utf16MaxLength(100)).optional(),
163
165
  /** Git branch the bundle was built from (audit / console display). */
164
- gitBranch: z.string().max(200).optional(),
166
+ gitBranch: z.string().check(utf16MaxLength(200)).optional(),
165
167
  /** Human-readable publish message (console display). */
166
- message: z.string().max(500).optional(),
168
+ message: z.string().check(utf16MaxLength(500)).optional(),
167
169
  });
168
170
  export const updateSchema = z.object({
169
171
  id: z.string(),
@@ -213,7 +215,7 @@ export const updateListResponseSchema = z.object({
213
215
  * update (if any) becomes head again. Nothing is deleted.
214
216
  */
215
217
  export const rollbackRequestSchema = z.object({
216
- applicationId: z.string().min(1),
218
+ applicationId: z.string().check(utf16MinLength(1)),
217
219
  runtimeVersion: runtimeVersionSchema,
218
220
  platform: updatePlatformSchema,
219
221
  });
@@ -223,7 +225,7 @@ export const rollbackRequestSchema = z.object({
223
225
  * fall back to the update embedded in their binary.
224
226
  */
225
227
  export const rollbackToEmbeddedRequestSchema = z.object({
226
- applicationId: z.string().min(1),
228
+ applicationId: z.string().check(utf16MinLength(1)),
227
229
  runtimeVersion: runtimeVersionSchema,
228
230
  platform: updatePlatformSchema,
229
231
  });
@@ -233,8 +235,8 @@ export const rollbackToEmbeddedRequestSchema = z.object({
233
235
  * UUID) pointing at the SAME assets. `toChannel` defaults to the path channel.
234
236
  */
235
237
  export const promoteRequestSchema = z.object({
236
- applicationId: z.string().min(1),
237
- updateId: z.string().min(1),
238
+ applicationId: z.string().check(utf16MinLength(1)),
239
+ updateId: z.string().check(utf16MinLength(1)),
238
240
  /** Target channel to promote into. Defaults to the path `:channel`. */
239
241
  toChannel: channelNameSchema.optional(),
240
242
  /** Rollout percentage for the promoted update (default 100). */
@@ -242,6 +244,6 @@ export const promoteRequestSchema = z.object({
242
244
  });
243
245
  /** `PATCH /updates/v1/updates/:updateId` request — adjust a rollout in place. */
244
246
  export const updateRolloutPatchSchema = z.object({
245
- applicationId: z.string().min(1),
247
+ applicationId: z.string().check(utf16MinLength(1)),
246
248
  rolloutPercent: rolloutPercentSchema,
247
249
  });
@@ -1,3 +1,5 @@
1
+ import { integerCheck } from './numberChecks.js';
2
+ import { utf16MinLength } from './stringChecks.js';
1
3
  /**
2
4
  * Canonical contract for the Oxy user-invalidation broadcast.
3
5
  *
@@ -77,9 +79,9 @@ export function isPublishedOxyUserChangeReason(reason) {
77
79
  */
78
80
  export const oxyUserInvalidationEventSchema = z.object({
79
81
  /** The Oxy user whose record changed. */
80
- userId: z.string().min(1),
82
+ userId: z.string().check(utf16MinLength(1)),
81
83
  /** Why it changed. Only broadcast reasons appear on the wire. */
82
84
  reason: z.enum(OXY_PUBLISHED_USER_CHANGE_REASONS),
83
85
  /** Publisher's epoch-ms timestamp. Diagnostic only. */
84
- at: z.number().int().nonnegative(),
86
+ at: z.number().check(integerCheck()).nonnegative(),
85
87
  });
@@ -1,3 +1,4 @@
1
+ import { isoDateTime } from './stringChecks.js';
1
2
  /**
2
3
  * Canonical API user-response contracts.
3
4
  *
@@ -234,7 +235,7 @@ export const userResponseSchema = z
234
235
  personalization: z
235
236
  .object({
236
237
  mentionMono: z
237
- .object({ allowed: z.boolean(), expiresAt: z.string().datetime().nullable() })
238
+ .object({ allowed: z.boolean(), expiresAt: z.string().check(isoDateTime()).nullable() })
238
239
  .strict(),
239
240
  })
240
241
  .strict()
@@ -289,12 +290,12 @@ export const userProfileUpdateSchema = z
289
290
  */
290
291
  languages: z.array(z.string()).optional(),
291
292
  accountExpiresAfterInactivityDays: z.number().nullable().optional(),
292
- notificationPreferences: z.record(z.unknown()).optional(),
293
+ notificationPreferences: z.record(z.string(), z.unknown()).optional(),
293
294
  userPreferences: z
294
295
  .object({ displayCurrency: z.enum(['USD', 'EUR', 'FAIR']).optional() })
295
296
  .catchall(z.unknown())
296
297
  .optional(),
297
- privacySettings: z.record(z.unknown()).optional(),
298
+ privacySettings: z.record(z.string(), z.unknown()).optional(),
298
299
  /**
299
300
  * Portable theme preference. Written through the same `PUT /users/me`
300
301
  * settings-update path as `languages`/`userPreferences`.