@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.
- package/dist/cjs/accountAccess.js +6 -5
- package/dist/cjs/accountEmail.js +13 -5
- package/dist/cjs/accountGraph.js +10 -9
- package/dist/cjs/accountName.js +3 -2
- package/dist/cjs/agency.js +91 -34
- package/dist/cjs/agentKeys.js +21 -17
- package/dist/cjs/appAssertions.js +14 -13
- package/dist/cjs/applicationRoles.js +19 -12
- package/dist/cjs/civic.js +10 -9
- package/dist/cjs/client/check.js +61 -53
- package/dist/cjs/consoleOnboarding.js +9 -4
- package/dist/cjs/contentClaims.js +23 -14
- package/dist/cjs/deviceDirectory.js +11 -9
- package/dist/cjs/deviceSession.js +27 -25
- package/dist/cjs/email/messages.js +20 -18
- package/dist/cjs/emailAgentContext.js +11 -9
- package/dist/cjs/externalIdentity.js +15 -11
- package/dist/cjs/federationInstanceFetch.js +12 -7
- package/dist/cjs/identity.js +19 -17
- package/dist/cjs/identityLink.js +6 -4
- package/dist/cjs/identityProof.js +6 -4
- package/dist/cjs/inboxPush.js +5 -4
- package/dist/cjs/index.js +15 -6
- package/dist/cjs/inference/accountBilling.js +35 -33
- package/dist/cjs/inference/aliaModelRelease.js +9 -7
- package/dist/cjs/inference/attribution.js +14 -12
- package/dist/cjs/inference/catalogue.js +35 -29
- package/dist/cjs/inference/economics.js +24 -19
- package/dist/cjs/inference/embeddings.js +9 -7
- package/dist/cjs/inference/entitlement.js +17 -15
- package/dist/cjs/inference/errors.js +15 -8
- package/dist/cjs/inference/identifiers.js +33 -21
- package/dist/cjs/inference/inbox.js +37 -35
- package/dist/cjs/inference/modelDocumentation.js +16 -14
- package/dist/cjs/inference/money.js +5 -4
- package/dist/cjs/inference/priceVersion.js +10 -5
- package/dist/cjs/inference/providerConnection.js +21 -14
- package/dist/cjs/inference/realtime.js +88 -47
- package/dist/cjs/inference/request.js +27 -25
- package/dist/cjs/inference/routingPolicy.js +12 -10
- package/dist/cjs/inference/streamEvents.js +22 -16
- package/dist/cjs/inference/usage.js +32 -15
- package/dist/cjs/keyRecovery.js +8 -6
- package/dist/cjs/keyRotation.js +5 -4
- package/dist/cjs/linkedAccounts.js +22 -18
- package/dist/cjs/moderationReputation.js +29 -27
- package/dist/cjs/notifications.js +25 -9
- package/dist/cjs/numberChecks.js +45 -0
- package/dist/cjs/oauth.js +14 -12
- package/dist/cjs/organizations.js +23 -21
- package/dist/cjs/products/access.js +10 -8
- package/dist/cjs/products/billing.js +10 -8
- package/dist/cjs/products/checkout.js +22 -10
- package/dist/cjs/products/plans.js +15 -10
- package/dist/cjs/protocol.js +6 -5
- package/dist/cjs/recommendations.js +27 -19
- package/dist/cjs/reputation.js +15 -13
- package/dist/cjs/safety.js +43 -27
- package/dist/cjs/serviceToken.js +81 -2
- package/dist/cjs/sessionRevocation.js +8 -6
- package/dist/cjs/signIn.js +42 -24
- package/dist/cjs/stickers.js +19 -15
- package/dist/cjs/stringChecks.js +70 -0
- package/dist/cjs/transparency.js +14 -12
- package/dist/cjs/updates.js +24 -22
- package/dist/cjs/userInvalidation.js +7 -5
- package/dist/cjs/userResponse.js +8 -7
- package/dist/cjs/username.js +7 -6
- package/dist/esm/accountAccess.js +4 -3
- package/dist/esm/accountEmail.js +13 -5
- package/dist/esm/accountGraph.js +8 -7
- package/dist/esm/accountName.js +3 -2
- package/dist/esm/agency.js +90 -33
- package/dist/esm/agentKeys.js +21 -17
- package/dist/esm/appAssertions.js +11 -10
- package/dist/esm/applicationRoles.js +16 -9
- package/dist/esm/civic.js +8 -7
- package/dist/esm/client/check.js +61 -53
- package/dist/esm/consoleOnboarding.js +7 -2
- package/dist/esm/contentClaims.js +23 -14
- package/dist/esm/deviceDirectory.js +11 -9
- package/dist/esm/deviceSession.js +27 -25
- package/dist/esm/email/messages.js +18 -16
- package/dist/esm/emailAgentContext.js +11 -9
- package/dist/esm/externalIdentity.js +15 -11
- package/dist/esm/federationInstanceFetch.js +10 -5
- package/dist/esm/identity.js +17 -15
- package/dist/esm/identityLink.js +6 -4
- package/dist/esm/identityProof.js +6 -4
- package/dist/esm/inboxPush.js +3 -2
- package/dist/esm/index.js +4 -2
- package/dist/esm/inference/accountBilling.js +33 -31
- package/dist/esm/inference/aliaModelRelease.js +7 -5
- package/dist/esm/inference/attribution.js +14 -12
- package/dist/esm/inference/catalogue.js +33 -27
- package/dist/esm/inference/economics.js +22 -17
- package/dist/esm/inference/embeddings.js +9 -7
- package/dist/esm/inference/entitlement.js +15 -13
- package/dist/esm/inference/errors.js +13 -6
- package/dist/esm/inference/identifiers.js +31 -19
- package/dist/esm/inference/inbox.js +37 -35
- package/dist/esm/inference/modelDocumentation.js +14 -12
- package/dist/esm/inference/money.js +3 -2
- package/dist/esm/inference/priceVersion.js +8 -3
- package/dist/esm/inference/providerConnection.js +19 -12
- package/dist/esm/inference/realtime.js +85 -44
- package/dist/esm/inference/request.js +25 -23
- package/dist/esm/inference/routingPolicy.js +9 -7
- package/dist/esm/inference/streamEvents.js +20 -14
- package/dist/esm/inference/usage.js +30 -13
- package/dist/esm/keyRecovery.js +8 -6
- package/dist/esm/keyRotation.js +5 -4
- package/dist/esm/linkedAccounts.js +20 -16
- package/dist/esm/moderationReputation.js +27 -25
- package/dist/esm/notifications.js +23 -7
- package/dist/esm/numberChecks.js +41 -0
- package/dist/esm/oauth.js +14 -12
- package/dist/esm/organizations.js +23 -21
- package/dist/esm/products/access.js +10 -8
- package/dist/esm/products/billing.js +10 -8
- package/dist/esm/products/checkout.js +22 -10
- package/dist/esm/products/plans.js +15 -10
- package/dist/esm/protocol.js +4 -3
- package/dist/esm/recommendations.js +25 -17
- package/dist/esm/reputation.js +13 -11
- package/dist/esm/safety.js +43 -27
- package/dist/esm/serviceToken.js +80 -1
- package/dist/esm/sessionRevocation.js +6 -4
- package/dist/esm/signIn.js +42 -24
- package/dist/esm/stickers.js +17 -13
- package/dist/esm/stringChecks.js +63 -0
- package/dist/esm/transparency.js +14 -12
- package/dist/esm/updates.js +22 -20
- package/dist/esm/userInvalidation.js +4 -2
- package/dist/esm/userResponse.js +4 -3
- package/dist/esm/username.js +3 -2
- package/dist/types/accountAccess.d.ts +29 -70
- package/dist/types/accountEmail.d.ts +2 -14
- package/dist/types/accountGraph.d.ts +179 -171
- package/dist/types/accountName.d.ts +1 -1
- package/dist/types/accountSubject.d.ts +20 -93
- package/dist/types/agency.d.ts +528 -2924
- package/dist/types/agentKeys.d.ts +48 -421
- package/dist/types/appAssertions.d.ts +56 -210
- package/dist/types/applicationRoles.d.ts +30 -276
- package/dist/types/avatarCharacter.d.ts +1 -1
- package/dist/types/civic.d.ts +1 -13
- package/dist/types/client/agentKeys.d.ts +18 -18
- package/dist/types/client/appAssertions.d.ts +3 -3
- package/dist/types/client/check.d.ts +13 -13
- package/dist/types/client/deviceDirectory.d.ts +51 -51
- package/dist/types/client/deviceSession.d.ts +14 -14
- package/dist/types/client/organizations.d.ts +25 -25
- package/dist/types/client/products.d.ts +33 -33
- package/dist/types/client/recommendations.d.ts +2 -2
- package/dist/types/client/safety.d.ts +45 -45
- package/dist/types/client/sessionStatus.d.ts +4 -4
- package/dist/types/client/signIn.d.ts +1 -1
- package/dist/types/commonsSignIn.d.ts +4 -1
- package/dist/types/consoleOnboarding.d.ts +24 -44
- package/dist/types/contentClaims.d.ts +24 -180
- package/dist/types/deviceDirectory.d.ts +109 -1040
- package/dist/types/deviceSession.d.ts +36 -298
- package/dist/types/email/messages.d.ts +212 -1793
- package/dist/types/emailAgentContext.d.ts +10 -194
- package/dist/types/externalIdentity.d.ts +121 -615
- package/dist/types/federationInstanceFetch.d.ts +3 -32
- package/dist/types/identity.d.ts +15 -92
- package/dist/types/identityLink.d.ts +6 -84
- package/dist/types/identityProof.d.ts +5 -17
- package/dist/types/inboxPush.d.ts +1 -9
- package/dist/types/index.d.ts +5 -3
- package/dist/types/inference/accountBilling.d.ts +151 -488
- package/dist/types/inference/aliaModelRelease.d.ts +42 -439
- package/dist/types/inference/attribution.d.ts +75 -104
- package/dist/types/inference/catalogue.d.ts +417 -1599
- package/dist/types/inference/economics.d.ts +69 -276
- package/dist/types/inference/embeddings.d.ts +110 -406
- package/dist/types/inference/entitlement.d.ts +80 -335
- package/dist/types/inference/errors.d.ts +90 -102
- package/dist/types/inference/identifiers.d.ts +12 -4
- package/dist/types/inference/inbox.d.ts +105 -420
- package/dist/types/inference/modelDocumentation.d.ts +201 -1390
- package/dist/types/inference/money.d.ts +65 -32
- package/dist/types/inference/priceVersion.d.ts +53 -120
- package/dist/types/inference/providerConnection.d.ts +253 -710
- package/dist/types/inference/realtime.d.ts +954 -6825
- package/dist/types/inference/request.d.ts +300 -2572
- package/dist/types/inference/routingPolicy.d.ts +95 -503
- package/dist/types/inference/streamEvents.d.ts +253 -721
- package/dist/types/inference/usage.d.ts +317 -950
- package/dist/types/keyRecovery.d.ts +3 -51
- package/dist/types/keyRotation.d.ts +3 -38
- package/dist/types/linkedAccounts.d.ts +50 -236
- package/dist/types/moderationReputation.d.ts +81 -14
- package/dist/types/notifications.d.ts +19 -51
- package/dist/types/numberChecks.d.ts +9 -0
- package/dist/types/oauth.d.ts +101 -809
- package/dist/types/organizations.d.ts +268 -921
- package/dist/types/oxyRecordTypes.d.ts +11 -1
- package/dist/types/products/access.d.ts +125 -775
- package/dist/types/products/billing.d.ts +67 -503
- package/dist/types/products/checkout.d.ts +16 -69
- package/dist/types/products/plans.d.ts +33 -366
- package/dist/types/recommendations.d.ts +76 -389
- package/dist/types/reputation.d.ts +37 -5
- package/dist/types/safety.d.ts +408 -2048
- package/dist/types/serviceToken.d.ts +247 -7
- package/dist/types/sessionRevocation.d.ts +2 -17
- package/dist/types/sessionStatus.d.ts +27 -115
- package/dist/types/signIn.d.ts +53 -553
- package/dist/types/stickers.d.ts +67 -819
- package/dist/types/stringChecks.d.ts +16 -0
- package/dist/types/transparency.d.ts +14 -302
- package/dist/types/updates.d.ts +60 -316
- package/dist/types/userInvalidation.d.ts +4 -13
- package/dist/types/userResponse.d.ts +302 -2400
- package/dist/types/username.d.ts +3 -3
- 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().
|
|
72
|
-
sourceActionId: z.string().
|
|
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().
|
|
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(),
|
package/dist/esm/client/check.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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)
|
|
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
|
|
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 '
|
|
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
|
|
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 ?? `
|
|
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 ?? `
|
|
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: '
|
|
91
|
-
message: message ??
|
|
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: '
|
|
98
|
-
message: `Invalid
|
|
99
|
+
code: 'invalid_format',
|
|
100
|
+
message: `Invalid string: must start with "${prefix}"`,
|
|
99
101
|
};
|
|
100
102
|
}
|
|
101
|
-
/** Zod
|
|
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
|
-
/**
|
|
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: '
|
|
116
|
-
message: 'Invalid
|
|
117
|
+
code: 'invalid_format',
|
|
118
|
+
message: 'Invalid URL',
|
|
117
119
|
};
|
|
118
|
-
/** Zod
|
|
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
|
-
|
|
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
|
-
/**
|
|
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: '
|
|
144
|
-
expected: '
|
|
145
|
-
received: '
|
|
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: `
|
|
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: `
|
|
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: '
|
|
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
|
-
/**
|
|
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.
|
|
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: '
|
|
181
|
-
message: `Invalid
|
|
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
|
-
|
|
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: '
|
|
193
|
-
message:
|
|
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
|
|
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: `
|
|
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: `
|
|
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
|
-
{
|
|
280
|
-
{
|
|
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
|
-
//
|
|
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
|
-
|
|
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
|
|
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, '
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
377
|
+
ruleFailures.push(checked);
|
|
372
378
|
}
|
|
373
|
-
return
|
|
379
|
+
return ruleFailures.length === 1
|
|
380
|
+
? ruleFailures[0]
|
|
381
|
+
: fail(path, { code: 'invalid_union', message: 'Invalid input' }, true);
|
|
374
382
|
};
|
|
375
383
|
}
|
|
376
|
-
/** Zod
|
|
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: '
|
|
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().
|
|
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
|
|
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
|
|
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
|
-
.
|
|
62
|
-
.
|
|
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
|
-
.
|
|
70
|
-
.
|
|
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
|
-
.
|
|
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
|
-
.
|
|
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
|
-
|
|
94
|
+
error: () => ({ message: 'contentClaim.errors.goodFaith' }),
|
|
90
95
|
}),
|
|
91
96
|
accurate: z.literal(true, {
|
|
92
|
-
|
|
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
|
-
.
|
|
100
|
-
.
|
|
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
|
|
153
|
-
|
|
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
|
-
.
|
|
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().
|
|
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().
|
|
91
|
-
accountId: z.string().
|
|
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().
|
|
110
|
-
userId: z.string().
|
|
111
|
-
authuser: z.number().
|
|
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().
|
|
125
|
-
revision: z.number().
|
|
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().
|
|
140
|
+
contextId: z.string().check(utf16MinLength(1)),
|
|
139
141
|
});
|
|
140
142
|
/**
|
|
141
143
|
* Response of `POST /session/device/activate`.
|