@oxy.so/contracts 4.15.0 → 4.17.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/.tsbuildinfo +1 -1
- package/dist/cjs/accountEmail.js +12 -34
- package/dist/cjs/accountGraph.js +22 -320
- package/dist/cjs/agentKeys.js +11 -13
- package/dist/cjs/client/accountEmail.js +48 -0
- package/dist/cjs/client/accountGraph.js +323 -0
- package/dist/cjs/client/agentKeys.js +77 -0
- package/dist/cjs/client/check.js +466 -0
- package/dist/cjs/client/deviceBoot.js +22 -0
- package/dist/cjs/client/deviceDirectory.js +51 -0
- package/dist/cjs/client/deviceSession.js +63 -0
- package/dist/cjs/client/externalIdentity.js +19 -0
- package/dist/cjs/client/identity.js +45 -0
- package/dist/cjs/client/identityLink.js +55 -0
- package/dist/cjs/client/identityProof.js +109 -0
- package/dist/cjs/client/index.js +190 -0
- package/dist/cjs/client/organizations.js +114 -0
- package/dist/cjs/client/products.js +153 -0
- package/dist/cjs/client/recommendations.js +33 -0
- package/dist/cjs/client/reputation.js +41 -0
- package/dist/cjs/client/safety.js +15 -0
- package/dist/cjs/client/sessionStatus.js +23 -0
- package/dist/cjs/client/signIn.js +157 -0
- package/dist/cjs/client/userResponse.js +15 -0
- package/dist/cjs/client/username.js +173 -0
- package/dist/cjs/deviceSession.js +3 -16
- package/dist/cjs/identityLink.js +13 -34
- package/dist/cjs/identityProof.js +18 -106
- package/dist/cjs/index.js +15 -10
- package/dist/cjs/inference/money.js +10 -0
- package/dist/cjs/inference/version.js +1 -1
- package/dist/cjs/organizations.js +21 -41
- package/dist/cjs/products/billing.js +0 -1
- package/dist/cjs/products/checkout.js +1 -14
- package/dist/cjs/products/plans.js +2 -18
- package/dist/cjs/reputation.js +3 -34
- package/dist/cjs/signIn.js +57 -96
- package/dist/cjs/userResponse.js +1 -8
- package/dist/cjs/username.js +23 -158
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/accountEmail.js +4 -32
- package/dist/esm/accountGraph.js +4 -309
- package/dist/esm/agentKeys.js +4 -10
- package/dist/esm/client/accountEmail.js +45 -0
- package/dist/esm/client/accountGraph.js +314 -0
- package/dist/esm/client/agentKeys.js +74 -0
- package/dist/esm/client/check.js +428 -0
- package/dist/esm/client/deviceBoot.js +19 -0
- package/dist/esm/client/deviceDirectory.js +48 -0
- package/dist/esm/client/deviceSession.js +60 -0
- package/dist/esm/client/externalIdentity.js +16 -0
- package/dist/esm/client/identity.js +42 -0
- package/dist/esm/client/identityLink.js +50 -0
- package/dist/esm/client/identityProof.js +104 -0
- package/dist/esm/client/index.js +37 -0
- package/dist/esm/client/organizations.js +111 -0
- package/dist/esm/client/products.js +150 -0
- package/dist/esm/client/recommendations.js +30 -0
- package/dist/esm/client/reputation.js +37 -0
- package/dist/esm/client/safety.js +12 -0
- package/dist/esm/client/sessionStatus.js +20 -0
- package/dist/esm/client/signIn.js +151 -0
- package/dist/esm/client/userResponse.js +12 -0
- package/dist/esm/client/username.js +167 -0
- package/dist/esm/deviceSession.js +1 -15
- package/dist/esm/identityLink.js +4 -27
- package/dist/esm/identityProof.js +4 -99
- package/dist/esm/index.js +2 -2
- package/dist/esm/inference/money.js +10 -0
- package/dist/esm/inference/version.js +1 -1
- package/dist/esm/organizations.js +4 -31
- package/dist/esm/products/billing.js +0 -1
- package/dist/esm/products/checkout.js +0 -13
- package/dist/esm/products/plans.js +1 -17
- package/dist/esm/reputation.js +1 -32
- package/dist/esm/signIn.js +29 -83
- package/dist/esm/userResponse.js +1 -8
- package/dist/esm/username.js +4 -148
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/accountEmail.d.ts +2 -34
- package/dist/types/accountGraph.d.ts +12 -208
- package/dist/types/agency.d.ts +24 -24
- package/dist/types/agentKeys.d.ts +8 -6
- package/dist/types/client/accountEmail.d.ts +44 -0
- package/dist/types/client/accountGraph.d.ts +203 -0
- package/dist/types/client/agentKeys.d.ts +113 -0
- package/dist/types/client/check.d.ts +184 -0
- package/dist/types/client/deviceBoot.d.ts +6 -0
- package/dist/types/client/deviceDirectory.d.ts +134 -0
- package/dist/types/client/deviceSession.d.ts +91 -0
- package/dist/types/client/externalIdentity.d.ts +14 -0
- package/dist/types/client/identity.d.ts +8 -0
- package/dist/types/client/identityLink.d.ts +21 -0
- package/dist/types/client/identityProof.d.ts +73 -0
- package/dist/types/client/index.d.ts +37 -0
- package/dist/types/client/organizations.d.ts +167 -0
- package/dist/types/client/products.d.ts +145 -0
- package/dist/types/client/recommendations.d.ts +27 -0
- package/dist/types/client/reputation.d.ts +28 -0
- package/dist/types/client/safety.d.ts +13 -0
- package/dist/types/client/sessionStatus.d.ts +19 -0
- package/dist/types/client/signIn.d.ts +107 -0
- package/dist/types/client/userResponse.d.ts +7 -0
- package/dist/types/client/username.d.ts +126 -0
- package/dist/types/deviceDirectory.d.ts +28 -28
- package/dist/types/deviceSession.d.ts +1 -12
- package/dist/types/externalIdentity.d.ts +11 -44
- package/dist/types/identityLink.d.ts +3 -11
- package/dist/types/identityProof.d.ts +2 -65
- package/dist/types/index.d.ts +3 -3
- package/dist/types/inference/catalogue.d.ts +7 -7
- package/dist/types/inference/decisions.d.ts +41 -41
- package/dist/types/inference/economics.d.ts +5 -5
- package/dist/types/inference/embeddings.d.ts +16 -16
- package/dist/types/inference/errors.d.ts +8 -8
- package/dist/types/inference/inbox.d.ts +8 -8
- package/dist/types/inference/money.d.ts +17 -8
- package/dist/types/inference/priceVersion.d.ts +12 -12
- package/dist/types/inference/privateAutoExecution.d.ts +6 -6
- package/dist/types/inference/realtime.d.ts +54 -54
- package/dist/types/inference/request.d.ts +28 -28
- package/dist/types/inference/routingPolicy.d.ts +7 -7
- package/dist/types/inference/streamEvents.d.ts +26 -26
- package/dist/types/inference/usage.d.ts +32 -32
- package/dist/types/inference/version.d.ts +1 -1
- package/dist/types/oauth.d.ts +2 -2
- package/dist/types/organizations.d.ts +8 -10
- package/dist/types/products/billing.d.ts +3 -8
- package/dist/types/products/checkout.d.ts +0 -36
- package/dist/types/products/plans.d.ts +5 -102
- package/dist/types/reputation.d.ts +1 -11
- package/dist/types/sessionStatus.d.ts +2 -2
- package/dist/types/signIn.d.ts +74 -76
- package/dist/types/userResponse.d.ts +23 -159
- package/dist/types/username.d.ts +1 -96
- package/package.json +20 -1
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Structural checks for contract values, without Zod.
|
|
4
|
+
*
|
|
5
|
+
* The Zod schemas in this package are the contract, and the API parses with
|
|
6
|
+
* them. A client only needs to know that a response has the shape its type
|
|
7
|
+
* promises, and Zod's object schemas pull Zod's whole runtime into every app
|
|
8
|
+
* that bundles the SDK (~120 KB before compression, evaluated at startup). The
|
|
9
|
+
* checks here give the client the same answers in plain TypeScript.
|
|
10
|
+
*
|
|
11
|
+
* Every check mirrors one Zod 3 schema in this package, and
|
|
12
|
+
* `__tests__/clientChecks.parity.test.ts` runs both over the same inputs and
|
|
13
|
+
* requires the same verdict, the same output and the same failing path. The
|
|
14
|
+
* rules follow Zod 3 exactly:
|
|
15
|
+
*
|
|
16
|
+
* string(...rules) a string; `trim`/`toLowerCase` rewrite it, the other
|
|
17
|
+
* rules test it, in the order given
|
|
18
|
+
* number(...rules) a number that is not NaN (Infinity passes, as in Zod)
|
|
19
|
+
* literal(v) / oneOf `===` one value / one of a fixed set of strings
|
|
20
|
+
* optional(c) `undefined` (or an absent key) passes; `null` does not
|
|
21
|
+
* nullable(c) `null` passes and is kept
|
|
22
|
+
* withDefault(c, v) `undefined` becomes `v`, which is then checked
|
|
23
|
+
* array(c, ...rules) the size rules first, then every element in order
|
|
24
|
+
* object(shape) unknown keys are DROPPED (Zod's default "strip")
|
|
25
|
+
* strictObject(shape) unknown keys FAIL (`.strict()`)
|
|
26
|
+
* looseObject(shape) unknown keys are KEPT (`.passthrough()`)
|
|
27
|
+
* refine(c, test) a further condition, run once `c` passes
|
|
28
|
+
* union / discriminatedUnion as Zod 3 reports them
|
|
29
|
+
*
|
|
30
|
+
* A failure carries the first issue Zod would report and whether Zod would have
|
|
31
|
+
* stopped there (`fatal`: the type was wrong) or kept checking (`fatal: false`:
|
|
32
|
+
* only a rule failed). Only `union` reads the difference, because Zod reports a
|
|
33
|
+
* union through its first "rule failed" option.
|
|
34
|
+
*
|
|
35
|
+
* This module, and everything under `src/client/`, must never import `zod`
|
|
36
|
+
* (`__tests__/clientEntryGraph.test.ts` walks the graph).
|
|
37
|
+
*/
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.ContractCheckError = exports.unknownRecord = exports.boolean = exports.safe = exports.nonnegative = exports.positive = exports.int = exports.datetime = exports.url = exports.email = exports.toLowerCase = exports.trim = void 0;
|
|
40
|
+
exports.minLength = minLength;
|
|
41
|
+
exports.maxLength = maxLength;
|
|
42
|
+
exports.pattern = pattern;
|
|
43
|
+
exports.startsWith = startsWith;
|
|
44
|
+
exports.string = string;
|
|
45
|
+
exports.atLeast = atLeast;
|
|
46
|
+
exports.atMost = atMost;
|
|
47
|
+
exports.number = number;
|
|
48
|
+
exports.literal = literal;
|
|
49
|
+
exports.oneOf = oneOf;
|
|
50
|
+
exports.optional = optional;
|
|
51
|
+
exports.nullable = nullable;
|
|
52
|
+
exports.withDefault = withDefault;
|
|
53
|
+
exports.refine = refine;
|
|
54
|
+
exports.refineAt = refineAt;
|
|
55
|
+
exports.branded = branded;
|
|
56
|
+
exports.minItems = minItems;
|
|
57
|
+
exports.maxItems = maxItems;
|
|
58
|
+
exports.exactItems = exactItems;
|
|
59
|
+
exports.array = array;
|
|
60
|
+
exports.object = object;
|
|
61
|
+
exports.strictObject = strictObject;
|
|
62
|
+
exports.looseObject = looseObject;
|
|
63
|
+
exports.union = union;
|
|
64
|
+
exports.discriminatedUnion = discriminatedUnion;
|
|
65
|
+
exports.formatCheckPath = formatCheckPath;
|
|
66
|
+
exports.checkContract = checkContract;
|
|
67
|
+
exports.parseContract = parseContract;
|
|
68
|
+
exports.exact = exact;
|
|
69
|
+
function ok(value) {
|
|
70
|
+
return { ok: true, value };
|
|
71
|
+
}
|
|
72
|
+
function fail(path, problem, fatal) {
|
|
73
|
+
return { ok: false, issue: { path, ...problem }, fatal };
|
|
74
|
+
}
|
|
75
|
+
function describe(input) {
|
|
76
|
+
if (input === null)
|
|
77
|
+
return 'null';
|
|
78
|
+
if (Array.isArray(input))
|
|
79
|
+
return 'array';
|
|
80
|
+
if (typeof input === 'number' && Number.isNaN(input))
|
|
81
|
+
return 'nan';
|
|
82
|
+
return typeof input;
|
|
83
|
+
}
|
|
84
|
+
/** Zod's wording for a value of the wrong type. */
|
|
85
|
+
function wrongType(path, expected, input) {
|
|
86
|
+
const received = describe(input);
|
|
87
|
+
const message = input === undefined ? 'Required' : `Expected ${expected}, received ${received}`;
|
|
88
|
+
return fail(path, { code: 'invalid_type', message, expected, received }, true);
|
|
89
|
+
}
|
|
90
|
+
/** `'a' | 'b'` — how Zod lists allowed values. */
|
|
91
|
+
function listValues(values, separator = ' | ') {
|
|
92
|
+
return values
|
|
93
|
+
.map((value) => (typeof value === 'string' ? `'${value}'` : String(value)))
|
|
94
|
+
.join(separator);
|
|
95
|
+
}
|
|
96
|
+
function isRecord(input) {
|
|
97
|
+
return typeof input === 'object' && input !== null && !Array.isArray(input);
|
|
98
|
+
}
|
|
99
|
+
exports.trim = { rewrite: (value) => value.trim() };
|
|
100
|
+
exports.toLowerCase = { rewrite: (value) => value.toLowerCase() };
|
|
101
|
+
function minLength(min, message) {
|
|
102
|
+
return {
|
|
103
|
+
test: (value) => value.length >= min,
|
|
104
|
+
code: 'too_small',
|
|
105
|
+
message: message ?? `String must contain at least ${min} character(s)`,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function maxLength(max, message) {
|
|
109
|
+
return {
|
|
110
|
+
test: (value) => value.length <= max,
|
|
111
|
+
code: 'too_big',
|
|
112
|
+
message: message ?? `String must contain at most ${max} character(s)`,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function pattern(regex, message) {
|
|
116
|
+
return {
|
|
117
|
+
test: (value) => {
|
|
118
|
+
regex.lastIndex = 0;
|
|
119
|
+
return regex.test(value);
|
|
120
|
+
},
|
|
121
|
+
code: 'invalid_string',
|
|
122
|
+
message: message ?? 'Invalid',
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function startsWith(prefix) {
|
|
126
|
+
return {
|
|
127
|
+
test: (value) => value.startsWith(prefix),
|
|
128
|
+
code: 'invalid_string',
|
|
129
|
+
message: `Invalid input: must start with "${prefix}"`,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/** Zod 3's `.email()`. */
|
|
133
|
+
const EMAIL = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9-]*\.)+[A-Z]{2,}$/i;
|
|
134
|
+
exports.email = pattern(EMAIL, 'Invalid email');
|
|
135
|
+
/** Zod 3's `.url()`: anything `new URL()` accepts. */
|
|
136
|
+
exports.url = {
|
|
137
|
+
test: (value) => {
|
|
138
|
+
try {
|
|
139
|
+
new URL(value);
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
code: 'invalid_string',
|
|
147
|
+
message: 'Invalid url',
|
|
148
|
+
};
|
|
149
|
+
/** Zod 3's `.datetime()`: ISO 8601 in UTC (`Z`), any sub-second precision, leap days checked. */
|
|
150
|
+
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])))' +
|
|
151
|
+
'T([01]\\d|2[0-3]):[0-5]\\d(:[0-5]\\d(\\.\\d+)?)?(Z)$');
|
|
152
|
+
exports.datetime = pattern(DATETIME, 'Invalid datetime');
|
|
153
|
+
function string(...rules) {
|
|
154
|
+
return (input, path) => {
|
|
155
|
+
if (typeof input !== 'string')
|
|
156
|
+
return wrongType(path, 'string', input);
|
|
157
|
+
let value = input;
|
|
158
|
+
let firstFailure = null;
|
|
159
|
+
for (const rule of rules) {
|
|
160
|
+
if ('rewrite' in rule)
|
|
161
|
+
value = rule.rewrite(value);
|
|
162
|
+
else if (firstFailure === null && !rule.test(value)) {
|
|
163
|
+
firstFailure = { code: rule.code, message: rule.message };
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return firstFailure === null ? ok(value) : fail(path, firstFailure, false);
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/** Zod's `.int()` — reported, as Zod does, as an `invalid_type` that does not stop the parse. */
|
|
170
|
+
const int = (value) => Number.isInteger(value)
|
|
171
|
+
? undefined
|
|
172
|
+
: {
|
|
173
|
+
code: 'invalid_type',
|
|
174
|
+
message: 'Expected integer, received float',
|
|
175
|
+
expected: 'integer',
|
|
176
|
+
received: 'float',
|
|
177
|
+
};
|
|
178
|
+
exports.int = int;
|
|
179
|
+
function atLeast(min) {
|
|
180
|
+
return (value) => value >= min
|
|
181
|
+
? undefined
|
|
182
|
+
: { code: 'too_small', message: `Number must be greater than or equal to ${min}` };
|
|
183
|
+
}
|
|
184
|
+
function atMost(max) {
|
|
185
|
+
return (value) => value <= max
|
|
186
|
+
? undefined
|
|
187
|
+
: { code: 'too_big', message: `Number must be less than or equal to ${max}` };
|
|
188
|
+
}
|
|
189
|
+
/** Zod's `.positive()`. */
|
|
190
|
+
const positive = (value) => value > 0 ? undefined : { code: 'too_small', message: 'Number must be greater than 0' };
|
|
191
|
+
exports.positive = positive;
|
|
192
|
+
/** Zod's `.nonnegative()` (and `.min(0)`). */
|
|
193
|
+
exports.nonnegative = atLeast(0);
|
|
194
|
+
/** Zod's `.safe()`: both bounds, low first. */
|
|
195
|
+
const safe = (value) => atLeast(Number.MIN_SAFE_INTEGER)(value) ?? atMost(Number.MAX_SAFE_INTEGER)(value);
|
|
196
|
+
exports.safe = safe;
|
|
197
|
+
function number(...rules) {
|
|
198
|
+
return (input, path) => {
|
|
199
|
+
if (typeof input !== 'number' || Number.isNaN(input))
|
|
200
|
+
return wrongType(path, 'number', input);
|
|
201
|
+
for (const rule of rules) {
|
|
202
|
+
const problem = rule(input);
|
|
203
|
+
if (problem)
|
|
204
|
+
return fail(path, problem, false);
|
|
205
|
+
}
|
|
206
|
+
return ok(input);
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
const boolean = (input, path) => typeof input === 'boolean' ? ok(input) : wrongType(path, 'boolean', input);
|
|
210
|
+
exports.boolean = boolean;
|
|
211
|
+
function literal(expected) {
|
|
212
|
+
return (input, path) => input === expected
|
|
213
|
+
? ok(expected)
|
|
214
|
+
: fail(path, {
|
|
215
|
+
code: 'invalid_literal',
|
|
216
|
+
message: `Invalid literal value, expected ${JSON.stringify(expected)}`,
|
|
217
|
+
}, true);
|
|
218
|
+
}
|
|
219
|
+
/** One of a fixed set of strings — Zod's `z.enum`. */
|
|
220
|
+
function oneOf(values) {
|
|
221
|
+
return (input, path) => {
|
|
222
|
+
if (typeof input !== 'string')
|
|
223
|
+
return wrongType(path, listValues(values), input);
|
|
224
|
+
return values.includes(input)
|
|
225
|
+
? ok(input)
|
|
226
|
+
: fail(path, {
|
|
227
|
+
code: 'invalid_enum_value',
|
|
228
|
+
message: `Invalid enum value. Expected ${listValues(values)}, received '${input}'`,
|
|
229
|
+
}, true);
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
/* -------------------------------------------------------------------------- */
|
|
233
|
+
/* Wrappers */
|
|
234
|
+
/* -------------------------------------------------------------------------- */
|
|
235
|
+
function optional(inner) {
|
|
236
|
+
return (input, path) => (input === undefined ? ok(undefined) : inner(input, path));
|
|
237
|
+
}
|
|
238
|
+
function nullable(inner) {
|
|
239
|
+
return (input, path) => (input === null ? ok(null) : inner(input, path));
|
|
240
|
+
}
|
|
241
|
+
function withDefault(inner, fallback) {
|
|
242
|
+
return (input, path) => inner(input === undefined ? fallback : input, path);
|
|
243
|
+
}
|
|
244
|
+
/** A further condition on a value `inner` accepted. */
|
|
245
|
+
function refine(inner, test, message) {
|
|
246
|
+
return (input, path) => {
|
|
247
|
+
const checked = inner(input, path);
|
|
248
|
+
if (!checked.ok)
|
|
249
|
+
return checked;
|
|
250
|
+
return test(checked.value) ? checked : fail(path, { code: 'custom', message }, false);
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Zod's `.superRefine()` for the one-issue case: `test` returns the first
|
|
255
|
+
* problem (its path relative to the value) or `undefined`.
|
|
256
|
+
*/
|
|
257
|
+
function refineAt(inner, test) {
|
|
258
|
+
return (input, path) => {
|
|
259
|
+
const checked = inner(input, path);
|
|
260
|
+
if (!checked.ok)
|
|
261
|
+
return checked;
|
|
262
|
+
const problem = test(checked.value);
|
|
263
|
+
return problem
|
|
264
|
+
? fail([...path, ...problem.path], { code: 'custom', message: problem.message }, false)
|
|
265
|
+
: checked;
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
/** Narrows a checked value to a branded contract type (Zod's `.brand()`). */
|
|
269
|
+
function branded(inner) {
|
|
270
|
+
return inner;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* The issues of a container, as Zod 3 orders them: the first one is reported,
|
|
274
|
+
* and the container is fatal when any part of it was.
|
|
275
|
+
*/
|
|
276
|
+
class Failures {
|
|
277
|
+
constructor(first) {
|
|
278
|
+
this.fatal = false;
|
|
279
|
+
this.first = first;
|
|
280
|
+
}
|
|
281
|
+
add(failure) {
|
|
282
|
+
this.first ?? (this.first = failure.issue);
|
|
283
|
+
this.fatal || (this.fatal = failure.fatal);
|
|
284
|
+
}
|
|
285
|
+
result() {
|
|
286
|
+
return this.first ? { ok: false, issue: this.first, fatal: this.fatal } : null;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
function minItems(min) {
|
|
290
|
+
return {
|
|
291
|
+
test: (length) => length >= min,
|
|
292
|
+
code: 'too_small',
|
|
293
|
+
message: `Array must contain at least ${min} element(s)`,
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
function maxItems(max) {
|
|
297
|
+
return {
|
|
298
|
+
test: (length) => length <= max,
|
|
299
|
+
code: 'too_big',
|
|
300
|
+
message: `Array must contain at most ${max} element(s)`,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
/** Zod's `.length(n)`: `too_big` or `too_small`, by which side it missed. */
|
|
304
|
+
function exactItems(count) {
|
|
305
|
+
const message = `Array must contain exactly ${count} element(s)`;
|
|
306
|
+
return [
|
|
307
|
+
{ test: (length) => length <= count, code: 'too_big', message },
|
|
308
|
+
{ test: (length) => length >= count, code: 'too_small', message },
|
|
309
|
+
];
|
|
310
|
+
}
|
|
311
|
+
function array(inner, ...rules) {
|
|
312
|
+
const sizeRules = rules.flat();
|
|
313
|
+
return (input, path) => {
|
|
314
|
+
if (!Array.isArray(input))
|
|
315
|
+
return wrongType(path, 'array', input);
|
|
316
|
+
// Zod reports the size before any element, then every element in order.
|
|
317
|
+
const size = sizeRules.find((rule) => !rule.test(input.length));
|
|
318
|
+
const failures = new Failures(size ? { path, code: size.code, message: size.message } : null);
|
|
319
|
+
const out = [];
|
|
320
|
+
for (let index = 0; index < input.length; index++) {
|
|
321
|
+
const checked = inner(input[index], [...path, index]);
|
|
322
|
+
if (checked.ok)
|
|
323
|
+
out.push(checked.value);
|
|
324
|
+
else
|
|
325
|
+
failures.add(checked);
|
|
326
|
+
}
|
|
327
|
+
return failures.result() ?? ok(out);
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
function objectWith(shape, unknownKeys) {
|
|
331
|
+
const keys = Object.keys(shape);
|
|
332
|
+
return (input, path) => {
|
|
333
|
+
if (!isRecord(input))
|
|
334
|
+
return wrongType(path, 'object', input);
|
|
335
|
+
const failures = new Failures(null);
|
|
336
|
+
const out = {};
|
|
337
|
+
for (const key of keys) {
|
|
338
|
+
const checked = shape[key](input[key], [...path, key]);
|
|
339
|
+
if (!checked.ok)
|
|
340
|
+
failures.add(checked);
|
|
341
|
+
// An optional key the input did not send stays absent rather than
|
|
342
|
+
// appearing as `key: undefined` — what Zod does, and what `in` sees.
|
|
343
|
+
else if (key !== '__proto__' && (checked.value !== undefined || key in input)) {
|
|
344
|
+
out[key] = checked.value;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (unknownKeys !== 'strip') {
|
|
348
|
+
const unknown = [];
|
|
349
|
+
for (const key in input) {
|
|
350
|
+
if (keys.includes(key))
|
|
351
|
+
continue;
|
|
352
|
+
unknown.push(key);
|
|
353
|
+
if (unknownKeys === 'passthrough' && key !== '__proto__' && input[key] !== undefined) {
|
|
354
|
+
out[key] = input[key];
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
if (unknownKeys === 'strict' && unknown.length > 0) {
|
|
358
|
+
const message = `Unrecognized key(s) in object: ${listValues(unknown, ', ')}`;
|
|
359
|
+
failures.add({ issue: { path, code: 'unrecognized_keys', message }, fatal: false });
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return failures.result() ?? ok(out);
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
/** Unknown keys are dropped — Zod's `z.object(shape)`. */
|
|
366
|
+
function object(shape) {
|
|
367
|
+
return objectWith(shape, 'strip');
|
|
368
|
+
}
|
|
369
|
+
/** Unknown keys fail — Zod's `z.object(shape).strict()`. */
|
|
370
|
+
function strictObject(shape) {
|
|
371
|
+
return objectWith(shape, 'strict');
|
|
372
|
+
}
|
|
373
|
+
/** Unknown keys are kept as sent — Zod's `z.object(shape).passthrough()`. */
|
|
374
|
+
function looseObject(shape) {
|
|
375
|
+
return objectWith(shape, 'passthrough');
|
|
376
|
+
}
|
|
377
|
+
/** Any object, every value kept — Zod's `z.record(z.unknown())`. */
|
|
378
|
+
const unknownRecord = (input, path) => {
|
|
379
|
+
if (!isRecord(input))
|
|
380
|
+
return wrongType(path, 'object', input);
|
|
381
|
+
const out = {};
|
|
382
|
+
for (const key in input)
|
|
383
|
+
if (key !== '__proto__')
|
|
384
|
+
out[key] = input[key];
|
|
385
|
+
return ok(out);
|
|
386
|
+
};
|
|
387
|
+
exports.unknownRecord = unknownRecord;
|
|
388
|
+
/* -------------------------------------------------------------------------- */
|
|
389
|
+
/* Unions */
|
|
390
|
+
/* -------------------------------------------------------------------------- */
|
|
391
|
+
/** The first option that passes; else Zod 3's report (the first option that only failed a rule). */
|
|
392
|
+
function union(...options) {
|
|
393
|
+
return (input, path) => {
|
|
394
|
+
let ruleFailure = null;
|
|
395
|
+
for (const option of options) {
|
|
396
|
+
const checked = option(input, path);
|
|
397
|
+
if (checked.ok)
|
|
398
|
+
return checked;
|
|
399
|
+
if (!checked.fatal)
|
|
400
|
+
ruleFailure ?? (ruleFailure = checked);
|
|
401
|
+
}
|
|
402
|
+
return ruleFailure ?? fail(path, { code: 'invalid_union', message: 'Invalid input' }, true);
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
/** Zod 3's `z.discriminatedUnion(key, options)`, with the options keyed by their tag. */
|
|
406
|
+
function discriminatedUnion(key, options) {
|
|
407
|
+
return (input, path) => {
|
|
408
|
+
if (!isRecord(input))
|
|
409
|
+
return wrongType(path, 'object', input);
|
|
410
|
+
const tag = input[key];
|
|
411
|
+
const option = typeof tag === 'string' && Object.prototype.hasOwnProperty.call(options, tag)
|
|
412
|
+
? options[tag]
|
|
413
|
+
: undefined;
|
|
414
|
+
if (!option) {
|
|
415
|
+
const message = `Invalid discriminator value. Expected ${listValues(Object.keys(options))}`;
|
|
416
|
+
return fail([...path, key], { code: 'invalid_union_discriminator', message }, true);
|
|
417
|
+
}
|
|
418
|
+
return option(input, path);
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
/* -------------------------------------------------------------------------- */
|
|
422
|
+
/* Using a check */
|
|
423
|
+
/* -------------------------------------------------------------------------- */
|
|
424
|
+
/** `a.b[0].c` — for messages. */
|
|
425
|
+
function formatCheckPath(path) {
|
|
426
|
+
let out = '';
|
|
427
|
+
for (const part of path) {
|
|
428
|
+
out += typeof part === 'number' ? `[${part}]` : out ? `.${part}` : part;
|
|
429
|
+
}
|
|
430
|
+
return out || '(root)';
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* A value did not have the shape its contract requires. Thrown where a Zod
|
|
434
|
+
* schema's `.parse()` used to throw a `ZodError`; `issues` keeps that error's
|
|
435
|
+
* issue shape (`code`, `path`, `message`), holding the first issue Zod reports.
|
|
436
|
+
*/
|
|
437
|
+
class ContractCheckError extends Error {
|
|
438
|
+
constructor(issue, context) {
|
|
439
|
+
const where = formatCheckPath(issue.path);
|
|
440
|
+
super(`${context ? `${context}: ` : ''}${where}: ${issue.message}`);
|
|
441
|
+
this.name = 'ContractCheckError';
|
|
442
|
+
this.issues = [issue];
|
|
443
|
+
Object.setPrototypeOf(this, ContractCheckError.prototype);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
exports.ContractCheckError = ContractCheckError;
|
|
447
|
+
/** The checked value, or `null` — the twin of `safeParseContract`. */
|
|
448
|
+
function checkContract(check, input) {
|
|
449
|
+
const checked = check(input, []);
|
|
450
|
+
return checked.ok ? checked.value : null;
|
|
451
|
+
}
|
|
452
|
+
/** The checked value; throws {@link ContractCheckError} — the twin of a schema's `.parse()`. */
|
|
453
|
+
function parseContract(check, input, context) {
|
|
454
|
+
const checked = check(input, []);
|
|
455
|
+
if (!checked.ok)
|
|
456
|
+
throw new ContractCheckError(checked.issue, context);
|
|
457
|
+
return checked.value;
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* `exact<DeviceSessionState>()(check)` compiles only when `check` produces
|
|
461
|
+
* exactly `DeviceSessionState` — every key, every optional mark, every literal
|
|
462
|
+
* — so a contract type that changes without its check is a type error here.
|
|
463
|
+
*/
|
|
464
|
+
function exact() {
|
|
465
|
+
return (check) => check;
|
|
466
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The first-party login result check, without Zod. Schemas: `../deviceBoot.ts`.
|
|
4
|
+
*
|
|
5
|
+
* Part of `@oxy.so/contracts/client`: never import `zod` here (see `./check.ts`).
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.loginResultCheck = void 0;
|
|
9
|
+
const check_1 = require("./check");
|
|
10
|
+
const securityAlert = (0, check_1.object)({
|
|
11
|
+
message: (0, check_1.string)(),
|
|
12
|
+
anomalies: (0, check_1.array)((0, check_1.object)({ type: (0, check_1.string)(), reason: (0, check_1.string)(), details: (0, check_1.optional)((0, check_1.string)()) })),
|
|
13
|
+
});
|
|
14
|
+
exports.loginResultCheck = (0, check_1.exact)()((0, check_1.object)({
|
|
15
|
+
sessionId: (0, check_1.string)(),
|
|
16
|
+
deviceId: (0, check_1.string)(),
|
|
17
|
+
expiresAt: (0, check_1.string)(),
|
|
18
|
+
accessToken: (0, check_1.optional)((0, check_1.string)()),
|
|
19
|
+
deviceSecret: (0, check_1.optional)((0, check_1.string)()),
|
|
20
|
+
securityAlert: (0, check_1.optional)(securityAlert),
|
|
21
|
+
user: (0, check_1.object)({ id: (0, check_1.string)(), username: (0, check_1.optional)((0, check_1.string)()), avatar: (0, check_1.optional)((0, check_1.string)()) }),
|
|
22
|
+
}));
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Device-directory checks, without Zod. Schemas: `../deviceDirectory.ts`.
|
|
4
|
+
*
|
|
5
|
+
* Part of `@oxy.so/contracts/client`: never import `zod` here (see `./check.ts`).
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.deviceDirectorySyncCheck = exports.deviceActivateResponseCheck = exports.deviceDirectoryCheck = void 0;
|
|
9
|
+
const accountGraph_1 = require("./accountGraph");
|
|
10
|
+
const check_1 = require("./check");
|
|
11
|
+
const deviceSession_1 = require("./deviceSession");
|
|
12
|
+
const userResponse_1 = require("./userResponse");
|
|
13
|
+
const DEVICE_CONTEXT_RELATIONSHIPS = ['self', 'owner', 'member'];
|
|
14
|
+
const profile = (0, check_1.object)({
|
|
15
|
+
id: (0, check_1.string)((0, check_1.minLength)(1)),
|
|
16
|
+
username: (0, check_1.string)(),
|
|
17
|
+
name: (0, check_1.optional)(userResponse_1.userNameCheck),
|
|
18
|
+
avatar: (0, check_1.optional)((0, check_1.nullable)((0, check_1.string)())),
|
|
19
|
+
color: (0, check_1.optional)((0, check_1.nullable)((0, check_1.string)())),
|
|
20
|
+
});
|
|
21
|
+
const accountContext = (0, check_1.object)({
|
|
22
|
+
id: (0, check_1.string)((0, check_1.minLength)(1)),
|
|
23
|
+
accountId: (0, check_1.string)((0, check_1.minLength)(1)),
|
|
24
|
+
kind: (0, check_1.oneOf)(accountGraph_1.ACCOUNT_KINDS),
|
|
25
|
+
relationship: (0, check_1.oneOf)(DEVICE_CONTEXT_RELATIONSHIPS),
|
|
26
|
+
account: profile,
|
|
27
|
+
onDevice: check_1.boolean,
|
|
28
|
+
available: check_1.boolean,
|
|
29
|
+
active: check_1.boolean,
|
|
30
|
+
lastUsedAt: (0, check_1.nullable)((0, check_1.number)()),
|
|
31
|
+
});
|
|
32
|
+
const principal = (0, check_1.object)({
|
|
33
|
+
id: (0, check_1.string)((0, check_1.minLength)(1)),
|
|
34
|
+
userId: (0, check_1.string)((0, check_1.minLength)(1)),
|
|
35
|
+
authuser: (0, check_1.number)(check_1.int, check_1.nonnegative),
|
|
36
|
+
user: profile,
|
|
37
|
+
contexts: (0, check_1.array)(accountContext),
|
|
38
|
+
});
|
|
39
|
+
exports.deviceDirectoryCheck = (0, check_1.exact)()((0, check_1.object)({
|
|
40
|
+
deviceId: (0, check_1.string)((0, check_1.minLength)(1)),
|
|
41
|
+
revision: (0, check_1.number)(check_1.int, check_1.nonnegative),
|
|
42
|
+
activeContextId: (0, check_1.nullable)((0, check_1.string)()),
|
|
43
|
+
principals: (0, check_1.array)(principal),
|
|
44
|
+
updatedAt: (0, check_1.number)(),
|
|
45
|
+
}));
|
|
46
|
+
exports.deviceActivateResponseCheck = (0, check_1.exact)()((0, check_1.object)({ directory: exports.deviceDirectoryCheck, activeToken: (0, check_1.nullable)(deviceSession_1.activeTokenCheck) }));
|
|
47
|
+
exports.deviceDirectorySyncCheck = (0, check_1.exact)()((0, check_1.object)({
|
|
48
|
+
directory: exports.deviceDirectoryCheck,
|
|
49
|
+
state: deviceSession_1.deviceSessionStateCheck,
|
|
50
|
+
activeToken: (0, check_1.nullable)(deviceSession_1.activeTokenCheck),
|
|
51
|
+
}));
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Device-session checks, without Zod. Schemas: `../deviceSession.ts`.
|
|
4
|
+
*
|
|
5
|
+
* Part of `@oxy.so/contracts/client`: never import `zod` here (see `./check.ts`).
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.deviceJoinCodeResponseCheck = exports.deviceJoinResponseCheck = exports.deviceRegisterResponseCheck = exports.deviceBackgroundCredentialResponseCheck = exports.sessionAccountsChangedEventCheck = exports.deviceTokenMintResponseCheck = exports.deviceSessionSyncCheck = exports.activeTokenCheck = exports.deviceSessionStateCheck = exports.SESSION_ACCOUNTS_CHANGED_EVENT = void 0;
|
|
9
|
+
const check_1 = require("./check");
|
|
10
|
+
/* -------------------------------------------------------------------------- */
|
|
11
|
+
/* Instant cross-app session sync (token-free socket signal) */
|
|
12
|
+
/* -------------------------------------------------------------------------- */
|
|
13
|
+
/**
|
|
14
|
+
* Name of the token-free Socket.IO event emitted to room `user:<userId>` on
|
|
15
|
+
* every DeviceSession mutation that changes what is signed in for that user.
|
|
16
|
+
*
|
|
17
|
+
* This is a pure SIGNAL — it carries NO access token, NO deviceSecret and NO
|
|
18
|
+
* account bodies. A client that receives it re-fetches its authenticated
|
|
19
|
+
* session/account state (`GET /session/device/state`, `GET /accounts`). Unlike
|
|
20
|
+
* `session_state` (scoped to `device:<deviceId>`, i.e. a single origin), this
|
|
21
|
+
* reaches ALL of a user's connected sockets across their devices/origins so
|
|
22
|
+
* every Oxy app reflects an add / switch / signout instantly.
|
|
23
|
+
*/
|
|
24
|
+
exports.SESSION_ACCOUNTS_CHANGED_EVENT = 'session_accounts_changed';
|
|
25
|
+
/* -------------------------------------------------------------------------- */
|
|
26
|
+
/* Response checks */
|
|
27
|
+
/* -------------------------------------------------------------------------- */
|
|
28
|
+
const SESSION_ACCOUNTS_CHANGED_REASONS = ['login', 'add', 'switch', 'signout', 'revoke'];
|
|
29
|
+
const sessionAccount = (0, check_1.object)({
|
|
30
|
+
accountId: (0, check_1.string)(),
|
|
31
|
+
sessionId: (0, check_1.string)(),
|
|
32
|
+
authuser: (0, check_1.number)(check_1.int, check_1.nonnegative),
|
|
33
|
+
operatedByUserId: (0, check_1.optional)((0, check_1.string)()),
|
|
34
|
+
});
|
|
35
|
+
exports.deviceSessionStateCheck = (0, check_1.exact)()((0, check_1.object)({
|
|
36
|
+
deviceId: (0, check_1.string)(),
|
|
37
|
+
accounts: (0, check_1.array)(sessionAccount),
|
|
38
|
+
activeAccountId: (0, check_1.nullable)((0, check_1.string)()),
|
|
39
|
+
revision: (0, check_1.number)(check_1.int, check_1.nonnegative),
|
|
40
|
+
updatedAt: (0, check_1.number)(),
|
|
41
|
+
}));
|
|
42
|
+
exports.activeTokenCheck = (0, check_1.exact)()((0, check_1.object)({ accessToken: (0, check_1.string)(), expiresAt: (0, check_1.string)() }));
|
|
43
|
+
exports.deviceSessionSyncCheck = (0, check_1.exact)()((0, check_1.object)({ state: exports.deviceSessionStateCheck, activeToken: (0, check_1.nullable)(exports.activeTokenCheck) }));
|
|
44
|
+
exports.deviceTokenMintResponseCheck = (0, check_1.exact)()((0, check_1.object)({
|
|
45
|
+
accessToken: (0, check_1.string)(),
|
|
46
|
+
expiresAt: (0, check_1.string)(),
|
|
47
|
+
nextDeviceSecret: (0, check_1.string)(),
|
|
48
|
+
state: exports.deviceSessionStateCheck,
|
|
49
|
+
}));
|
|
50
|
+
exports.sessionAccountsChangedEventCheck = (0, check_1.exact)()((0, check_1.object)({
|
|
51
|
+
userId: (0, check_1.string)(),
|
|
52
|
+
revision: (0, check_1.number)(check_1.int, check_1.nonnegative),
|
|
53
|
+
reason: (0, check_1.oneOf)(SESSION_ACCOUNTS_CHANGED_REASONS),
|
|
54
|
+
}));
|
|
55
|
+
exports.deviceBackgroundCredentialResponseCheck = (0, check_1.exact)()((0, check_1.object)({
|
|
56
|
+
deviceId: (0, check_1.string)((0, check_1.minLength)(1)),
|
|
57
|
+
secret: (0, check_1.string)((0, check_1.minLength)(1)),
|
|
58
|
+
accountId: (0, check_1.string)((0, check_1.minLength)(1)),
|
|
59
|
+
expiresAt: (0, check_1.string)(),
|
|
60
|
+
}));
|
|
61
|
+
exports.deviceRegisterResponseCheck = (0, check_1.exact)()((0, check_1.object)({ deviceId: (0, check_1.string)((0, check_1.minLength)(1)), deviceSecret: (0, check_1.string)((0, check_1.minLength)(1)) }));
|
|
62
|
+
exports.deviceJoinResponseCheck = (0, check_1.exact)()(exports.deviceRegisterResponseCheck);
|
|
63
|
+
exports.deviceJoinCodeResponseCheck = (0, check_1.exact)()((0, check_1.object)({ code: (0, check_1.string)((0, check_1.minLength)(1)), expiresIn: (0, check_1.number)(check_1.int, check_1.positive) }));
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The external-identity reference check, without Zod. Schemas: `../externalIdentity.ts`.
|
|
4
|
+
*
|
|
5
|
+
* Part of `@oxy.so/contracts/client`: never import `zod` here (see `./check.ts`).
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.externalIdentityReferenceCheck = void 0;
|
|
9
|
+
const check_1 = require("./check");
|
|
10
|
+
const required = (0, check_1.string)((0, check_1.minLength)(1));
|
|
11
|
+
/** One Oxy-proven network alias of a profile — the twin of `externalIdentityReferenceSchema`. */
|
|
12
|
+
exports.externalIdentityReferenceCheck = (0, check_1.exact)()((0, check_1.object)({
|
|
13
|
+
canonicalAcct: required,
|
|
14
|
+
network: required,
|
|
15
|
+
protocol: (0, check_1.oneOf)(['activitypub', 'atproto', 'instagram-graph']),
|
|
16
|
+
actorUri: required,
|
|
17
|
+
transportAcct: required,
|
|
18
|
+
sourceUserId: required,
|
|
19
|
+
}));
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The signed-record envelope check, without Zod. Schemas: `../identity.ts`.
|
|
4
|
+
*
|
|
5
|
+
* Part of `@oxy.so/contracts/client`: never import `zod` here (see `./check.ts`).
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.signedRecordEnvelopeCheck = void 0;
|
|
9
|
+
const check_1 = require("./check");
|
|
10
|
+
const CHAIN_FIELDS = ['seq', 'prev', 'collection', 'rkey'];
|
|
11
|
+
/** The twin of `signedRecordEnvelopeSchema`: v2 requires the chain fields, v1 forbids them. */
|
|
12
|
+
exports.signedRecordEnvelopeCheck = (0, check_1.exact)()((0, check_1.refineAt)((0, check_1.object)({
|
|
13
|
+
version: (0, check_1.union)((0, check_1.literal)(1), (0, check_1.literal)(2)),
|
|
14
|
+
type: (0, check_1.string)((0, check_1.minLength)(1)),
|
|
15
|
+
subject: (0, check_1.string)(),
|
|
16
|
+
issuer: (0, check_1.string)(),
|
|
17
|
+
record: check_1.unknownRecord,
|
|
18
|
+
issuedAt: (0, check_1.number)(),
|
|
19
|
+
seq: (0, check_1.optional)((0, check_1.number)(check_1.int, check_1.nonnegative)),
|
|
20
|
+
prev: (0, check_1.optional)((0, check_1.nullable)((0, check_1.string)())),
|
|
21
|
+
collection: (0, check_1.optional)((0, check_1.string)((0, check_1.minLength)(1))),
|
|
22
|
+
rkey: (0, check_1.optional)((0, check_1.string)((0, check_1.minLength)(1))),
|
|
23
|
+
publicKey: (0, check_1.string)(),
|
|
24
|
+
alg: (0, check_1.literal)('ES256K-DER-SHA256'),
|
|
25
|
+
signature: (0, check_1.string)(),
|
|
26
|
+
}), (env) => {
|
|
27
|
+
if (env.version === 2) {
|
|
28
|
+
if (typeof env.seq !== 'number')
|
|
29
|
+
return { path: ['seq'], message: 'v2 envelope requires `seq`' };
|
|
30
|
+
if (env.prev === undefined) {
|
|
31
|
+
return { path: ['prev'], message: 'v2 envelope requires `prev` (use `null` at genesis)' };
|
|
32
|
+
}
|
|
33
|
+
if (typeof env.collection !== 'string') {
|
|
34
|
+
return { path: ['collection'], message: 'v2 envelope requires `collection`' };
|
|
35
|
+
}
|
|
36
|
+
if (typeof env.rkey !== 'string') {
|
|
37
|
+
return { path: ['rkey'], message: 'v2 envelope requires `rkey`' };
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
const carried = CHAIN_FIELDS.find((field) => env[field] !== undefined);
|
|
42
|
+
return carried
|
|
43
|
+
? { path: [carried], message: `v1 envelope must not carry \`${carried}\`` }
|
|
44
|
+
: undefined;
|
|
45
|
+
}));
|