@enlitt/protocol 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +15 -2
- package/dist/admin.d.cts +353 -0
- package/dist/admin.d.ts +354 -0
- package/dist/admin.d.ts.map +1 -0
- package/dist/authentication.d.cts +8 -0
- package/dist/authentication.d.ts +9 -0
- package/dist/authentication.d.ts.map +1 -0
- package/dist/canonical-integer.d.cts +48 -0
- package/dist/canonical-integer.d.ts +49 -0
- package/dist/canonical-integer.d.ts.map +1 -0
- package/dist/compatibility.d.cts +23 -0
- package/dist/compatibility.d.ts +24 -0
- package/dist/compatibility.d.ts.map +1 -0
- package/dist/contract.d.cts +67 -0
- package/dist/contract.d.ts +68 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/dashboard.d.cts +1030 -0
- package/dist/dashboard.d.ts +1031 -0
- package/dist/dashboard.d.ts.map +1 -0
- package/dist/errors.d.cts +112 -0
- package/dist/errors.d.ts +113 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/idempotency.d.cts +79 -0
- package/dist/idempotency.d.ts +80 -0
- package/dist/idempotency.d.ts.map +1 -0
- package/dist/index.cjs +4806 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +31 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4624 -0
- package/dist/index.js.map +1 -0
- package/dist/premium-operations.d.cts +84 -0
- package/dist/premium-operations.d.ts +85 -0
- package/dist/premium-operations.d.ts.map +1 -0
- package/dist/response-stream.d.cts +246 -0
- package/dist/response-stream.d.ts +247 -0
- package/dist/response-stream.d.ts.map +1 -0
- package/dist/responses.d.cts +233 -0
- package/dist/responses.d.ts +234 -0
- package/dist/responses.d.ts.map +1 -0
- package/dist/usage.d.cts +11 -0
- package/dist/usage.d.ts +12 -0
- package/dist/usage.d.ts.map +1 -0
- package/generated/contract.json +482 -0
- package/package.json +51 -3
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,4806 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/canonical-integer.ts
|
|
4
|
+
var CANONICAL_INTEGER = /^(?:0|[1-9][0-9]*)$/;
|
|
5
|
+
var CanonicalIntegerError = class extends Error {
|
|
6
|
+
name = "CanonicalIntegerError";
|
|
7
|
+
};
|
|
8
|
+
function isCanonicalIntegerString(value) {
|
|
9
|
+
return typeof value === "string" && CANONICAL_INTEGER.test(value);
|
|
10
|
+
}
|
|
11
|
+
function parseCanonicalInteger(value, field = "amount") {
|
|
12
|
+
if (typeof value !== "string") {
|
|
13
|
+
throw new CanonicalIntegerError(
|
|
14
|
+
`${field} must be a canonical base-10 integer string, not ${typeof value}`
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
if (!CANONICAL_INTEGER.test(value)) {
|
|
18
|
+
throw new CanonicalIntegerError(
|
|
19
|
+
`${field} must be digits only with no sign, fraction, exponent, or leading zero`
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
return BigInt(value);
|
|
23
|
+
}
|
|
24
|
+
function parsePositiveCanonicalInteger(value, field = "amount") {
|
|
25
|
+
const parsed = parseCanonicalInteger(value, field);
|
|
26
|
+
if (parsed <= 0n) {
|
|
27
|
+
throw new CanonicalIntegerError(`${field} must be strictly positive`);
|
|
28
|
+
}
|
|
29
|
+
return parsed;
|
|
30
|
+
}
|
|
31
|
+
function formatCanonicalInteger(value, field = "amount") {
|
|
32
|
+
if (typeof value !== "bigint") {
|
|
33
|
+
throw new CanonicalIntegerError(`${field} must be a bigint to serialize exactly`);
|
|
34
|
+
}
|
|
35
|
+
if (value < 0n) {
|
|
36
|
+
throw new CanonicalIntegerError(`${field} must not be negative`);
|
|
37
|
+
}
|
|
38
|
+
return value.toString(10);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/compatibility.ts
|
|
42
|
+
var ENLITT_API_VERSION = "2026-10-05";
|
|
43
|
+
var ENLITT_VERSION_HEADER = "Enlitt-Version";
|
|
44
|
+
var UNKNOWN_ENUM_VALUE = "other";
|
|
45
|
+
var UNRECOGNIZED_ERROR_CODE = "unrecognized";
|
|
46
|
+
|
|
47
|
+
// src/errors.ts
|
|
48
|
+
var ENLITT_ERROR_TYPES = [
|
|
49
|
+
"authentication_error",
|
|
50
|
+
"permission_error",
|
|
51
|
+
"invalid_request_error",
|
|
52
|
+
"insufficient_credits_error",
|
|
53
|
+
"rate_limit_error",
|
|
54
|
+
"conflict_error",
|
|
55
|
+
"server_error"
|
|
56
|
+
];
|
|
57
|
+
function definition(input) {
|
|
58
|
+
return Object.freeze(input);
|
|
59
|
+
}
|
|
60
|
+
var forbidden = {
|
|
61
|
+
retryAfter: "forbidden",
|
|
62
|
+
authorizeUrl: "forbidden",
|
|
63
|
+
admissibleMaxCharge: "forbidden",
|
|
64
|
+
limitRule: "forbidden"
|
|
65
|
+
};
|
|
66
|
+
var ENLITT_ERROR_CODES = Object.freeze({
|
|
67
|
+
personal_login_required: definition({
|
|
68
|
+
type: "authentication_error",
|
|
69
|
+
status: 401,
|
|
70
|
+
retryable: false,
|
|
71
|
+
...forbidden
|
|
72
|
+
}),
|
|
73
|
+
admin_authentication_required: definition({
|
|
74
|
+
type: "authentication_error",
|
|
75
|
+
status: 401,
|
|
76
|
+
retryable: false,
|
|
77
|
+
...forbidden
|
|
78
|
+
}),
|
|
79
|
+
dashboard_login_required: definition({
|
|
80
|
+
type: "authentication_error",
|
|
81
|
+
status: 401,
|
|
82
|
+
retryable: false,
|
|
83
|
+
...forbidden
|
|
84
|
+
}),
|
|
85
|
+
spending_limit_exceeded: definition({
|
|
86
|
+
type: "insufficient_credits_error",
|
|
87
|
+
status: 403,
|
|
88
|
+
retryable: false,
|
|
89
|
+
retryAfter: "forbidden",
|
|
90
|
+
authorizeUrl: "allowed",
|
|
91
|
+
admissibleMaxCharge: "forbidden",
|
|
92
|
+
limitRule: "required"
|
|
93
|
+
}),
|
|
94
|
+
premium_balance_exhausted: definition({
|
|
95
|
+
type: "insufficient_credits_error",
|
|
96
|
+
status: 403,
|
|
97
|
+
retryable: false,
|
|
98
|
+
retryAfter: "forbidden",
|
|
99
|
+
authorizeUrl: "allowed",
|
|
100
|
+
admissibleMaxCharge: "allowed",
|
|
101
|
+
limitRule: "forbidden"
|
|
102
|
+
}),
|
|
103
|
+
standard_balance_exhausted: definition({
|
|
104
|
+
type: "insufficient_credits_error",
|
|
105
|
+
status: 403,
|
|
106
|
+
retryable: false,
|
|
107
|
+
retryAfter: "forbidden",
|
|
108
|
+
authorizeUrl: "allowed",
|
|
109
|
+
admissibleMaxCharge: "forbidden",
|
|
110
|
+
limitRule: "forbidden"
|
|
111
|
+
}),
|
|
112
|
+
subscription_inactive: definition({
|
|
113
|
+
type: "insufficient_credits_error",
|
|
114
|
+
status: 403,
|
|
115
|
+
retryable: false,
|
|
116
|
+
retryAfter: "forbidden",
|
|
117
|
+
authorizeUrl: "allowed",
|
|
118
|
+
admissibleMaxCharge: "forbidden",
|
|
119
|
+
limitRule: "forbidden"
|
|
120
|
+
}),
|
|
121
|
+
rate_limit_exceeded: definition({
|
|
122
|
+
type: "rate_limit_error",
|
|
123
|
+
status: 429,
|
|
124
|
+
retryable: true,
|
|
125
|
+
...forbidden,
|
|
126
|
+
retryAfter: "required"
|
|
127
|
+
}),
|
|
128
|
+
conflict_error: definition({ type: "conflict_error", status: 409, retryable: false, ...forbidden }),
|
|
129
|
+
operation_in_progress: definition({ type: "conflict_error", status: 409, retryable: false, ...forbidden }),
|
|
130
|
+
idempotency_replay_unavailable: definition({
|
|
131
|
+
type: "conflict_error",
|
|
132
|
+
status: 409,
|
|
133
|
+
retryable: false,
|
|
134
|
+
...forbidden
|
|
135
|
+
}),
|
|
136
|
+
invalid_value: definition({ type: "invalid_request_error", status: 400, retryable: false, ...forbidden }),
|
|
137
|
+
unsupported_parameter: definition({
|
|
138
|
+
type: "invalid_request_error",
|
|
139
|
+
status: 400,
|
|
140
|
+
retryable: false,
|
|
141
|
+
...forbidden
|
|
142
|
+
}),
|
|
143
|
+
unsupported_value: definition({
|
|
144
|
+
type: "invalid_request_error",
|
|
145
|
+
status: 400,
|
|
146
|
+
retryable: false,
|
|
147
|
+
...forbidden
|
|
148
|
+
}),
|
|
149
|
+
invalid_api_key: definition({ type: "authentication_error", status: 401, retryable: false, ...forbidden }),
|
|
150
|
+
reauthentication_required: definition({
|
|
151
|
+
type: "authentication_error",
|
|
152
|
+
status: 401,
|
|
153
|
+
retryable: false,
|
|
154
|
+
...forbidden
|
|
155
|
+
}),
|
|
156
|
+
payment_declined: definition({
|
|
157
|
+
type: "invalid_request_error",
|
|
158
|
+
status: 402,
|
|
159
|
+
retryable: false,
|
|
160
|
+
...forbidden
|
|
161
|
+
}),
|
|
162
|
+
invalid_sign_in_code: definition({
|
|
163
|
+
type: "invalid_request_error",
|
|
164
|
+
status: 400,
|
|
165
|
+
retryable: false,
|
|
166
|
+
...forbidden
|
|
167
|
+
}),
|
|
168
|
+
insufficient_permissions: definition({ type: "permission_error", status: 403, retryable: false, ...forbidden }),
|
|
169
|
+
not_found: definition({ type: "invalid_request_error", status: 404, retryable: false, ...forbidden }),
|
|
170
|
+
request_too_large: definition({ type: "invalid_request_error", status: 413, retryable: false, ...forbidden }),
|
|
171
|
+
server_error: definition({ type: "server_error", status: 500, retryable: true, ...forbidden }),
|
|
172
|
+
provider_error: definition({ type: "server_error", status: 502, retryable: true, ...forbidden }),
|
|
173
|
+
business_selection_required: definition({
|
|
174
|
+
type: "invalid_request_error",
|
|
175
|
+
status: 409,
|
|
176
|
+
retryable: false,
|
|
177
|
+
...forbidden
|
|
178
|
+
}),
|
|
179
|
+
bot_verification_failed: definition({ type: "permission_error", status: 403, retryable: false, ...forbidden }),
|
|
180
|
+
phone_verification_required: definition({
|
|
181
|
+
type: "permission_error",
|
|
182
|
+
status: 403,
|
|
183
|
+
retryable: false,
|
|
184
|
+
...forbidden
|
|
185
|
+
}),
|
|
186
|
+
invalid_phone_code: definition({
|
|
187
|
+
type: "invalid_request_error",
|
|
188
|
+
status: 400,
|
|
189
|
+
retryable: false,
|
|
190
|
+
...forbidden
|
|
191
|
+
}),
|
|
192
|
+
phone_number_not_supported: definition({
|
|
193
|
+
type: "invalid_request_error",
|
|
194
|
+
status: 400,
|
|
195
|
+
retryable: false,
|
|
196
|
+
...forbidden
|
|
197
|
+
}),
|
|
198
|
+
phone_number_unavailable: definition({ type: "conflict_error", status: 409, retryable: false, ...forbidden }),
|
|
199
|
+
// A business name is already held by another business (case-insensitive, any status).
|
|
200
|
+
business_name_unavailable: definition({ type: "conflict_error", status: 409, retryable: false, ...forbidden }),
|
|
201
|
+
// The four device-flow answers of `POST /v1/cli/token`. Polling again after
|
|
202
|
+
// `authorization_pending` or `slow_down` is the flow itself, not an HTTP
|
|
203
|
+
// retry, so all four are non-retryable.
|
|
204
|
+
authorization_pending: definition({
|
|
205
|
+
type: "invalid_request_error",
|
|
206
|
+
status: 400,
|
|
207
|
+
retryable: false,
|
|
208
|
+
...forbidden
|
|
209
|
+
}),
|
|
210
|
+
slow_down: definition({ type: "invalid_request_error", status: 400, retryable: false, ...forbidden }),
|
|
211
|
+
access_denied: definition({ type: "invalid_request_error", status: 400, retryable: false, ...forbidden }),
|
|
212
|
+
expired_token: definition({ type: "invalid_request_error", status: 400, retryable: false, ...forbidden })
|
|
213
|
+
});
|
|
214
|
+
var ENLITT_ERROR_CODE_NAMES = Object.freeze(
|
|
215
|
+
Object.keys(ENLITT_ERROR_CODES)
|
|
216
|
+
);
|
|
217
|
+
var ENLITT_ERROR_CODE = Object.freeze(
|
|
218
|
+
Object.fromEntries(ENLITT_ERROR_CODE_NAMES.map((code) => [code, code]))
|
|
219
|
+
);
|
|
220
|
+
function isEnlittErrorCode(value) {
|
|
221
|
+
return typeof value === "string" && Object.hasOwn(ENLITT_ERROR_CODES, value);
|
|
222
|
+
}
|
|
223
|
+
function getEnlittErrorDefinition(code) {
|
|
224
|
+
return ENLITT_ERROR_CODES[code];
|
|
225
|
+
}
|
|
226
|
+
var EnlittErrorContractViolation = class extends Error {
|
|
227
|
+
name = "EnlittErrorContractViolation";
|
|
228
|
+
};
|
|
229
|
+
function renderEnlittError(input) {
|
|
230
|
+
if (!isEnlittErrorCode(input.code)) {
|
|
231
|
+
throw new EnlittErrorContractViolation(`Unknown Enlitt error code: ${String(input.code)}`);
|
|
232
|
+
}
|
|
233
|
+
const record = ENLITT_ERROR_CODES[input.code];
|
|
234
|
+
const headers = {};
|
|
235
|
+
if (record.retryAfter === "required") {
|
|
236
|
+
if (!Number.isInteger(input.retryAfterSeconds) || (input.retryAfterSeconds ?? -1) < 0) {
|
|
237
|
+
throw new EnlittErrorContractViolation(`${input.code} requires a nonnegative integer retryAfterSeconds`);
|
|
238
|
+
}
|
|
239
|
+
headers["retry-after"] = String(input.retryAfterSeconds);
|
|
240
|
+
} else if (input.retryAfterSeconds !== void 0) {
|
|
241
|
+
throw new EnlittErrorContractViolation(`${input.code} must not carry Retry-After`);
|
|
242
|
+
}
|
|
243
|
+
if (input.authorizeUrl !== void 0 && record.authorizeUrl === "forbidden") {
|
|
244
|
+
throw new EnlittErrorContractViolation(`${input.code} must not carry authorize_url`);
|
|
245
|
+
}
|
|
246
|
+
if (input.admissibleMaxChargeNanoUsd !== void 0 && record.admissibleMaxCharge === "forbidden") {
|
|
247
|
+
throw new EnlittErrorContractViolation(`${input.code} must not carry admissible_max_charge_nano_usd`);
|
|
248
|
+
}
|
|
249
|
+
if (record.admissibleMaxCharge === "allowed" && input.admissibleMaxChargeNanoUsd === void 0) {
|
|
250
|
+
throw new EnlittErrorContractViolation(`${input.code} requires admissible_max_charge_nano_usd`);
|
|
251
|
+
}
|
|
252
|
+
if (input.admissibleMaxChargeNanoUsd !== void 0 && !isCanonicalIntegerString(input.admissibleMaxChargeNanoUsd)) {
|
|
253
|
+
throw new EnlittErrorContractViolation("admissible_max_charge_nano_usd must be canonical");
|
|
254
|
+
}
|
|
255
|
+
if (record.limitRule === "required") {
|
|
256
|
+
if (typeof input.limitRule !== "string" || input.limitRule.length === 0 || input.limitRule.length > 64) {
|
|
257
|
+
throw new EnlittErrorContractViolation(`${input.code} requires a bounded limitRule`);
|
|
258
|
+
}
|
|
259
|
+
} else if (input.limitRule !== void 0) {
|
|
260
|
+
throw new EnlittErrorContractViolation(`${input.code} must not carry limit_rule`);
|
|
261
|
+
}
|
|
262
|
+
const extension = {};
|
|
263
|
+
if (input.authorizeUrl !== void 0) extension.authorize_url = input.authorizeUrl;
|
|
264
|
+
if (input.admissibleMaxChargeNanoUsd !== void 0) {
|
|
265
|
+
extension.admissible_max_charge_nano_usd = input.admissibleMaxChargeNanoUsd;
|
|
266
|
+
}
|
|
267
|
+
if (input.limitRule !== void 0) extension.limit_rule = input.limitRule;
|
|
268
|
+
const error = {
|
|
269
|
+
message: input.message,
|
|
270
|
+
type: record.type,
|
|
271
|
+
param: input.param ?? null,
|
|
272
|
+
code: input.code,
|
|
273
|
+
...Object.keys(extension).length > 0 ? { enlitt: Object.freeze(extension) } : {}
|
|
274
|
+
};
|
|
275
|
+
return Object.freeze({
|
|
276
|
+
status: record.status,
|
|
277
|
+
headers: Object.freeze(headers),
|
|
278
|
+
body: Object.freeze({ error: Object.freeze(error) }),
|
|
279
|
+
retryable: record.retryable
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
function isPlainObject(value) {
|
|
283
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
284
|
+
}
|
|
285
|
+
function parseErrorEnvelope(body) {
|
|
286
|
+
if (!isPlainObject(body) || !isPlainObject(body.error)) return null;
|
|
287
|
+
const error = body.error;
|
|
288
|
+
if (typeof error.message !== "string") return null;
|
|
289
|
+
if (typeof error.type === "string") {
|
|
290
|
+
if (!(typeof error.param === "string" || error.param === null)) return null;
|
|
291
|
+
return {
|
|
292
|
+
code: error.code,
|
|
293
|
+
message: error.message,
|
|
294
|
+
type: error.type,
|
|
295
|
+
extension: isPlainObject(error.enlitt) ? error.enlitt : void 0
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
if (typeof error.code !== "string" || typeof body.request_id !== "string") return null;
|
|
299
|
+
return { code: error.code, message: error.message, type: null, extension: void 0 };
|
|
300
|
+
}
|
|
301
|
+
function hasRecognizableErrorCode(value) {
|
|
302
|
+
return typeof value === "string" && /^[a-z][a-z0-9_]{0,63}$/.test(value);
|
|
303
|
+
}
|
|
304
|
+
function isAllowedAuthorizeUrl(value) {
|
|
305
|
+
if (typeof value !== "string") return false;
|
|
306
|
+
try {
|
|
307
|
+
const url = new URL(value);
|
|
308
|
+
if (url.protocol === "https:") return true;
|
|
309
|
+
return url.protocol === "http:" && (url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "[::1]");
|
|
310
|
+
} catch {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function classifyEnlittErrorResponse(status, body) {
|
|
315
|
+
const envelope = parseErrorEnvelope(body);
|
|
316
|
+
if (envelope === null) return null;
|
|
317
|
+
const rawCode = hasRecognizableErrorCode(envelope.code) ? envelope.code : UNRECOGNIZED_ERROR_CODE;
|
|
318
|
+
const recognized = isEnlittErrorCode(rawCode);
|
|
319
|
+
const definition2 = recognized ? ENLITT_ERROR_CODES[rawCode] : void 0;
|
|
320
|
+
const creditRefusal = definition2?.type === "insufficient_credits_error" || !definition2 && envelope.type === "insufficient_credits_error";
|
|
321
|
+
const retryable = definition2?.retryable ?? (creditRefusal ? false : status >= 500 && status <= 599);
|
|
322
|
+
const result = {
|
|
323
|
+
code: rawCode,
|
|
324
|
+
recognized,
|
|
325
|
+
status,
|
|
326
|
+
type: envelope.type,
|
|
327
|
+
retryable,
|
|
328
|
+
creditRefusal,
|
|
329
|
+
message: envelope.message.slice(0, 512)
|
|
330
|
+
};
|
|
331
|
+
if (envelope.extension !== void 0 && (definition2?.authorizeUrl === "allowed" || !definition2 && creditRefusal) && isAllowedAuthorizeUrl(envelope.extension.authorize_url)) {
|
|
332
|
+
result.authorizeUrl = envelope.extension.authorize_url;
|
|
333
|
+
}
|
|
334
|
+
if (definition2?.admissibleMaxCharge === "allowed" && isCanonicalIntegerString(envelope.extension?.admissible_max_charge_nano_usd)) {
|
|
335
|
+
result.admissibleMaxChargeNanoUsd = envelope.extension.admissible_max_charge_nano_usd;
|
|
336
|
+
}
|
|
337
|
+
if (definition2?.limitRule === "required") {
|
|
338
|
+
const rule = envelope.extension?.limit_rule;
|
|
339
|
+
if (typeof rule !== "string" || rule.length === 0 || rule.length > 64) return null;
|
|
340
|
+
result.limitRule = rule;
|
|
341
|
+
}
|
|
342
|
+
return result;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// src/authentication.ts
|
|
346
|
+
var COOKIE_VALUE = /^[\x21\x23-\x2b\x2d-\x3a\x3c-\x5b\x5d-\x7e]{1,4096}$/;
|
|
347
|
+
var SUBJECT = /^[A-Za-z0-9_-]{1,255}$/;
|
|
348
|
+
function validateAuthorizationExchangeResponse(payload, options) {
|
|
349
|
+
const invalid3 = (param) => ({
|
|
350
|
+
ok: false,
|
|
351
|
+
error: { code: ENLITT_ERROR_CODE.invalid_value, param, message: "Invalid authorization exchange response" }
|
|
352
|
+
});
|
|
353
|
+
if (typeof payload !== "object" || payload === null || Array.isArray(payload)) return invalid3("body");
|
|
354
|
+
const body = payload;
|
|
355
|
+
if (options?.mode !== "tolerant") {
|
|
356
|
+
for (const key of Object.keys(body)) {
|
|
357
|
+
if (key !== "session_token" && key !== "subject") return invalid3(key);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (typeof body.session_token !== "string" || !COOKIE_VALUE.test(body.session_token)) {
|
|
361
|
+
return invalid3("session_token");
|
|
362
|
+
}
|
|
363
|
+
if (typeof body.subject !== "string" || !SUBJECT.test(body.subject)) return invalid3("subject");
|
|
364
|
+
return { ok: true, value: { session_token: body.session_token, subject: body.subject } };
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// src/idempotency.ts
|
|
368
|
+
var IDEMPOTENCY_KEY_MIN_LENGTH = 16;
|
|
369
|
+
var IDEMPOTENCY_KEY_MAX_LENGTH = 255;
|
|
370
|
+
var IDEMPOTENCY_KEY_MIN_RETENTION_DAYS = 30;
|
|
371
|
+
var VISIBLE_ASCII = /^[\x21-\x7e]+$/;
|
|
372
|
+
var IdempotencyKeyError = class extends Error {
|
|
373
|
+
name = "IdempotencyKeyError";
|
|
374
|
+
};
|
|
375
|
+
function isValidIdempotencyKey(value) {
|
|
376
|
+
return typeof value === "string" && value.length >= IDEMPOTENCY_KEY_MIN_LENGTH && value.length <= IDEMPOTENCY_KEY_MAX_LENGTH && VISIBLE_ASCII.test(value);
|
|
377
|
+
}
|
|
378
|
+
function assertIdempotencyKey(value) {
|
|
379
|
+
if (typeof value !== "string") {
|
|
380
|
+
throw new IdempotencyKeyError("Idempotency-Key is required");
|
|
381
|
+
}
|
|
382
|
+
if (value.length < IDEMPOTENCY_KEY_MIN_LENGTH || value.length > IDEMPOTENCY_KEY_MAX_LENGTH) {
|
|
383
|
+
throw new IdempotencyKeyError(
|
|
384
|
+
`Idempotency-Key must be between ${IDEMPOTENCY_KEY_MIN_LENGTH} and ${IDEMPOTENCY_KEY_MAX_LENGTH} characters`
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
if (!VISIBLE_ASCII.test(value)) {
|
|
388
|
+
throw new IdempotencyKeyError("Idempotency-Key must contain only visible ASCII characters");
|
|
389
|
+
}
|
|
390
|
+
return value;
|
|
391
|
+
}
|
|
392
|
+
function classifyIdempotentRequest(input) {
|
|
393
|
+
const { prior } = input;
|
|
394
|
+
if (prior === null) {
|
|
395
|
+
return { kind: "new" };
|
|
396
|
+
}
|
|
397
|
+
if (prior.requestFingerprint !== input.requestFingerprint) {
|
|
398
|
+
return { kind: "conflict", code: "conflict_error" };
|
|
399
|
+
}
|
|
400
|
+
if (prior.status === "active") {
|
|
401
|
+
return {
|
|
402
|
+
kind: "in_progress",
|
|
403
|
+
code: "operation_in_progress",
|
|
404
|
+
operationId: prior.operationId
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
return {
|
|
408
|
+
kind: "replay_unavailable",
|
|
409
|
+
code: "idempotency_replay_unavailable",
|
|
410
|
+
operationId: prior.operationId
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// src/responses.ts
|
|
415
|
+
var ENLITT_STANDARD_MODEL = "enlitt-standard";
|
|
416
|
+
function ok(value) {
|
|
417
|
+
return { ok: true, value };
|
|
418
|
+
}
|
|
419
|
+
function unsupportedParameter(param, message) {
|
|
420
|
+
return { ok: false, error: { code: ENLITT_ERROR_CODE.unsupported_parameter, param, message } };
|
|
421
|
+
}
|
|
422
|
+
function unsupportedValue(param, message) {
|
|
423
|
+
return { ok: false, error: { code: ENLITT_ERROR_CODE.unsupported_value, param, message } };
|
|
424
|
+
}
|
|
425
|
+
function invalidValue(param, message) {
|
|
426
|
+
return { ok: false, error: { code: ENLITT_ERROR_CODE.invalid_value, param, message } };
|
|
427
|
+
}
|
|
428
|
+
function isPlainObject2(value) {
|
|
429
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
430
|
+
}
|
|
431
|
+
function validateJsonSchema(value, param) {
|
|
432
|
+
if (!isPlainObject2(value)) return invalidValue(param, "must be a JSON Schema object");
|
|
433
|
+
return ok(value);
|
|
434
|
+
}
|
|
435
|
+
var MAX_TOOLS = 64;
|
|
436
|
+
var MAX_IMAGES = 16;
|
|
437
|
+
var MAX_IMAGE_BYTES = 4 * 1024 * 1024;
|
|
438
|
+
var MAX_IMAGE_DIMENSION = 4096;
|
|
439
|
+
function ensureOnlyKeys(value, allowed, param) {
|
|
440
|
+
for (const key of Object.keys(value)) {
|
|
441
|
+
if (!allowed.has(key)) return unsupportedParameter(param ? `${param}.${key}` : key, `"${key}" is not accepted`);
|
|
442
|
+
}
|
|
443
|
+
return void 0;
|
|
444
|
+
}
|
|
445
|
+
function decodeBase64(value) {
|
|
446
|
+
if (value.length === 0 || value.length % 4 !== 0 || !/^[A-Za-z0-9+/]+={0,2}$/.test(value)) return void 0;
|
|
447
|
+
try {
|
|
448
|
+
return Uint8Array.from(atob(value), (character) => character.charCodeAt(0));
|
|
449
|
+
} catch {
|
|
450
|
+
return void 0;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
function pngDimensions(bytes) {
|
|
454
|
+
const signature = [137, 80, 78, 71, 13, 10, 26, 10];
|
|
455
|
+
if (bytes.length < 24 || signature.some((byte, index) => bytes[index] !== byte)) return void 0;
|
|
456
|
+
if (String.fromCharCode(...bytes.slice(12, 16)) !== "IHDR") return void 0;
|
|
457
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
458
|
+
return [view.getUint32(16), view.getUint32(20)];
|
|
459
|
+
}
|
|
460
|
+
function jpegDimensions(bytes) {
|
|
461
|
+
if (bytes.length < 4 || bytes[0] !== 255 || bytes[1] !== 216) return void 0;
|
|
462
|
+
const sofMarkers = /* @__PURE__ */ new Set([192, 193, 194, 195, 197, 198, 199, 201, 202, 203, 205, 206, 207]);
|
|
463
|
+
let offset = 2;
|
|
464
|
+
while (offset + 3 < bytes.length) {
|
|
465
|
+
while (bytes[offset] === 255) offset += 1;
|
|
466
|
+
const marker = bytes[offset++];
|
|
467
|
+
if (marker === void 0 || marker === 217 || marker === 218) return void 0;
|
|
468
|
+
const length = (bytes[offset] ?? 0) << 8 | (bytes[offset + 1] ?? 0);
|
|
469
|
+
if (length < 2 || offset + length > bytes.length) return void 0;
|
|
470
|
+
if (sofMarkers.has(marker)) {
|
|
471
|
+
if (length < 7) return void 0;
|
|
472
|
+
return [(bytes[offset + 5] ?? 0) << 8 | (bytes[offset + 6] ?? 0), (bytes[offset + 3] ?? 0) << 8 | (bytes[offset + 4] ?? 0)];
|
|
473
|
+
}
|
|
474
|
+
offset += length;
|
|
475
|
+
}
|
|
476
|
+
return void 0;
|
|
477
|
+
}
|
|
478
|
+
function validateImageSource(value, param) {
|
|
479
|
+
if (!isPlainObject2(value)) return invalidValue(param, "must be an image source object");
|
|
480
|
+
const type = value.type;
|
|
481
|
+
if (type === "url") {
|
|
482
|
+
const keys = ensureOnlyKeys(value, /* @__PURE__ */ new Set(["type", "url"]), param);
|
|
483
|
+
if (keys) return keys;
|
|
484
|
+
if (typeof value.url !== "string") return invalidValue(`${param}.url`, "must be a string");
|
|
485
|
+
try {
|
|
486
|
+
if (new URL(value.url).protocol !== "https:") return invalidValue(`${param}.url`, "must be an absolute HTTPS URL");
|
|
487
|
+
} catch {
|
|
488
|
+
return invalidValue(`${param}.url`, "must be an absolute HTTPS URL");
|
|
489
|
+
}
|
|
490
|
+
return ok({ type: "url", url: value.url });
|
|
491
|
+
}
|
|
492
|
+
if (type === "base64") {
|
|
493
|
+
const keys = ensureOnlyKeys(value, /* @__PURE__ */ new Set(["type", "media_type", "data"]), param);
|
|
494
|
+
if (keys) return keys;
|
|
495
|
+
if (value.media_type !== "image/png" && value.media_type !== "image/jpeg") {
|
|
496
|
+
return unsupportedValue(`${param}.media_type`, 'must be "image/png" or "image/jpeg"');
|
|
497
|
+
}
|
|
498
|
+
if (typeof value.data !== "string") return invalidValue(`${param}.data`, "must be a base64 string");
|
|
499
|
+
const bytes = decodeBase64(value.data);
|
|
500
|
+
if (!bytes) return invalidValue(`${param}.data`, "must be canonical base64 image data");
|
|
501
|
+
if (bytes.byteLength > MAX_IMAGE_BYTES) return invalidValue(`${param}.data`, `decoded image must not exceed ${MAX_IMAGE_BYTES} bytes`);
|
|
502
|
+
const dimensions = value.media_type === "image/png" ? pngDimensions(bytes) : jpegDimensions(bytes);
|
|
503
|
+
if (!dimensions) return invalidValue(`${param}.data`, `must contain a valid ${value.media_type} header with dimensions`);
|
|
504
|
+
if (dimensions[0] < 1 || dimensions[1] < 1 || dimensions[0] > MAX_IMAGE_DIMENSION || dimensions[1] > MAX_IMAGE_DIMENSION) {
|
|
505
|
+
return invalidValue(`${param}.data`, `image dimensions must be between 1 and ${MAX_IMAGE_DIMENSION} pixels`);
|
|
506
|
+
}
|
|
507
|
+
return ok({ type: "base64", media_type: value.media_type, data: value.data });
|
|
508
|
+
}
|
|
509
|
+
if (typeof type !== "string") return invalidValue(`${param}.type`, "must be a string");
|
|
510
|
+
return unsupportedValue(`${param}.type`, `unknown image source type "${type}"`);
|
|
511
|
+
}
|
|
512
|
+
function validateUserPart(value, param) {
|
|
513
|
+
if (!isPlainObject2(value)) return invalidValue(param, "must be a content part object");
|
|
514
|
+
const type = value.type;
|
|
515
|
+
if (typeof type !== "string") return invalidValue(`${param}.type`, "content part type must be a string");
|
|
516
|
+
if (type === "text") {
|
|
517
|
+
const keys = ensureOnlyKeys(value, /* @__PURE__ */ new Set(["type", "text"]), param);
|
|
518
|
+
if (keys) return keys;
|
|
519
|
+
if (typeof value.text !== "string" || value.text.length === 0) return invalidValue(`${param}.text`, "must be a non-empty string");
|
|
520
|
+
return ok({ type: "text", text: value.text });
|
|
521
|
+
}
|
|
522
|
+
if (type === "image") {
|
|
523
|
+
const keys = ensureOnlyKeys(value, /* @__PURE__ */ new Set(["type", "source"]), param);
|
|
524
|
+
if (keys) return keys;
|
|
525
|
+
const source = validateImageSource(value.source, `${param}.source`);
|
|
526
|
+
return source.ok ? ok({ type: "image", source: source.value }) : source;
|
|
527
|
+
}
|
|
528
|
+
return unsupportedValue(`${param}.type`, `unknown content part type "${type}"`);
|
|
529
|
+
}
|
|
530
|
+
function validateFunctionTool(value, param) {
|
|
531
|
+
if (!isPlainObject2(value)) return invalidValue(param, "must be a function tool object");
|
|
532
|
+
const keys = ensureOnlyKeys(value, /* @__PURE__ */ new Set(["name", "description", "input_schema"]), param);
|
|
533
|
+
if (keys) return keys;
|
|
534
|
+
const name = value.name;
|
|
535
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
536
|
+
return invalidValue(`${param}.name`, "must be a non-empty string");
|
|
537
|
+
}
|
|
538
|
+
const description = value.description;
|
|
539
|
+
if (description !== void 0 && typeof description !== "string") {
|
|
540
|
+
return invalidValue(`${param}.description`, "must be a string");
|
|
541
|
+
}
|
|
542
|
+
const schemaResult = validateJsonSchema(value.input_schema, `${param}.input_schema`);
|
|
543
|
+
if (!schemaResult.ok) return schemaResult;
|
|
544
|
+
const tool = {
|
|
545
|
+
name,
|
|
546
|
+
input_schema: schemaResult.value
|
|
547
|
+
};
|
|
548
|
+
if (description !== void 0) tool.description = description;
|
|
549
|
+
return ok(tool);
|
|
550
|
+
}
|
|
551
|
+
function validateFunctionTools(value, param) {
|
|
552
|
+
if (!Array.isArray(value)) return invalidValue(param, "must be an array of function tools");
|
|
553
|
+
if (value.length > MAX_TOOLS) return invalidValue(param, `must not contain more than ${MAX_TOOLS} tools`);
|
|
554
|
+
const tools = [];
|
|
555
|
+
for (const [index, item] of value.entries()) {
|
|
556
|
+
const result = validateFunctionTool(item, `${param}[${index}]`);
|
|
557
|
+
if (!result.ok) return result;
|
|
558
|
+
tools.push(result.value);
|
|
559
|
+
}
|
|
560
|
+
return ok(tools);
|
|
561
|
+
}
|
|
562
|
+
var CALLER_METADATA_LIMITS = Object.freeze({
|
|
563
|
+
maxEntries: 16,
|
|
564
|
+
maxKeyLength: 64,
|
|
565
|
+
maxValueLength: 512,
|
|
566
|
+
reservedKeyPrefix: "enlitt_"
|
|
567
|
+
});
|
|
568
|
+
function validateCallerMetadata(value, param = "metadata") {
|
|
569
|
+
if (!isPlainObject2(value)) return invalidValue(param, "must be an object of string values");
|
|
570
|
+
const entries = Object.entries(value);
|
|
571
|
+
if (entries.length > CALLER_METADATA_LIMITS.maxEntries) {
|
|
572
|
+
return invalidValue(param, `must not have more than ${CALLER_METADATA_LIMITS.maxEntries} entries`);
|
|
573
|
+
}
|
|
574
|
+
const metadata = {};
|
|
575
|
+
for (const [key, entryValue] of entries) {
|
|
576
|
+
if (key.length > CALLER_METADATA_LIMITS.maxKeyLength) {
|
|
577
|
+
return invalidValue(
|
|
578
|
+
`${param}.${key}`,
|
|
579
|
+
`key must not exceed ${CALLER_METADATA_LIMITS.maxKeyLength} characters`
|
|
580
|
+
);
|
|
581
|
+
}
|
|
582
|
+
if (key.startsWith(CALLER_METADATA_LIMITS.reservedKeyPrefix)) {
|
|
583
|
+
return invalidValue(`${param}.${key}`, `key must not begin with "${CALLER_METADATA_LIMITS.reservedKeyPrefix}"`);
|
|
584
|
+
}
|
|
585
|
+
if (typeof entryValue !== "string") {
|
|
586
|
+
return invalidValue(`${param}.${key}`, "value must be a string");
|
|
587
|
+
}
|
|
588
|
+
if (entryValue.length > CALLER_METADATA_LIMITS.maxValueLength) {
|
|
589
|
+
return invalidValue(
|
|
590
|
+
`${param}.${key}`,
|
|
591
|
+
`value must not exceed ${CALLER_METADATA_LIMITS.maxValueLength} characters`
|
|
592
|
+
);
|
|
593
|
+
}
|
|
594
|
+
metadata[key] = entryValue;
|
|
595
|
+
}
|
|
596
|
+
return ok(metadata);
|
|
597
|
+
}
|
|
598
|
+
var ACCEPTED_REQUEST_FIELDS = /* @__PURE__ */ new Set(["model", "messages", "tools", "max_output_tokens", "stream", "metadata"]);
|
|
599
|
+
function validateMessages(value) {
|
|
600
|
+
if (!Array.isArray(value) || value.length === 0) return invalidValue("messages", "must be a non-empty array");
|
|
601
|
+
const messages = [];
|
|
602
|
+
const toolCalls = /* @__PURE__ */ new Set();
|
|
603
|
+
const toolResults = /* @__PURE__ */ new Set();
|
|
604
|
+
let imageCount = 0;
|
|
605
|
+
for (const [index, item] of value.entries()) {
|
|
606
|
+
const param = `messages[${index}]`;
|
|
607
|
+
if (!isPlainObject2(item)) return invalidValue(param, "must be a message object");
|
|
608
|
+
const role = item.role;
|
|
609
|
+
if (role === "system") {
|
|
610
|
+
const keys = ensureOnlyKeys(item, /* @__PURE__ */ new Set(["role", "content"]), param);
|
|
611
|
+
if (keys) return keys;
|
|
612
|
+
if (typeof item.content !== "string" || item.content.length === 0) return invalidValue(`${param}.content`, "must be a non-empty string");
|
|
613
|
+
messages.push({ role, content: item.content });
|
|
614
|
+
continue;
|
|
615
|
+
}
|
|
616
|
+
if (role === "user") {
|
|
617
|
+
const keys = ensureOnlyKeys(item, /* @__PURE__ */ new Set(["role", "content"]), param);
|
|
618
|
+
if (keys) return keys;
|
|
619
|
+
if (!Array.isArray(item.content) || item.content.length === 0) return invalidValue(`${param}.content`, "must be a non-empty array");
|
|
620
|
+
const parts = [];
|
|
621
|
+
for (const [partIndex, rawPart] of item.content.entries()) {
|
|
622
|
+
const part = validateUserPart(rawPart, `${param}.content[${partIndex}]`);
|
|
623
|
+
if (!part.ok) return part;
|
|
624
|
+
if (part.value.type === "image" && ++imageCount > MAX_IMAGES) return invalidValue("messages", `must not contain more than ${MAX_IMAGES} images`);
|
|
625
|
+
parts.push(part.value);
|
|
626
|
+
}
|
|
627
|
+
messages.push({ role, content: parts });
|
|
628
|
+
continue;
|
|
629
|
+
}
|
|
630
|
+
if (role === "assistant") {
|
|
631
|
+
const keys = ensureOnlyKeys(item, /* @__PURE__ */ new Set(["role", "content", "tool_calls"]), param);
|
|
632
|
+
if (keys) return keys;
|
|
633
|
+
const content = item.content;
|
|
634
|
+
if (content !== void 0 && (typeof content !== "string" || content.length === 0)) return invalidValue(`${param}.content`, "must be a non-empty string");
|
|
635
|
+
const rawCalls = item.tool_calls;
|
|
636
|
+
if (rawCalls !== void 0 && (!Array.isArray(rawCalls) || rawCalls.length === 0)) return invalidValue(`${param}.tool_calls`, "must be a non-empty array");
|
|
637
|
+
if (content === void 0 && rawCalls === void 0) return invalidValue(param, "assistant message must have content or tool_calls");
|
|
638
|
+
const calls = [];
|
|
639
|
+
if (Array.isArray(rawCalls)) {
|
|
640
|
+
for (const [callIndex, rawCall] of rawCalls.entries()) {
|
|
641
|
+
const callParam = `${param}.tool_calls[${callIndex}]`;
|
|
642
|
+
if (!isPlainObject2(rawCall)) return invalidValue(callParam, "must be a tool call object");
|
|
643
|
+
const callKeys = ensureOnlyKeys(rawCall, /* @__PURE__ */ new Set(["id", "name", "arguments"]), callParam);
|
|
644
|
+
if (callKeys) return callKeys;
|
|
645
|
+
if (typeof rawCall.id !== "string" || rawCall.id.length === 0) return invalidValue(`${callParam}.id`, "must be a non-empty string");
|
|
646
|
+
if (toolCalls.has(rawCall.id)) return invalidValue(`${callParam}.id`, "must be unique within the request");
|
|
647
|
+
if (typeof rawCall.name !== "string" || rawCall.name.length === 0) return invalidValue(`${callParam}.name`, "must be a non-empty string");
|
|
648
|
+
if (typeof rawCall.arguments !== "string") return invalidValue(`${callParam}.arguments`, "must be a string");
|
|
649
|
+
toolCalls.add(rawCall.id);
|
|
650
|
+
calls.push({ id: rawCall.id, name: rawCall.name, arguments: rawCall.arguments });
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
const message = { role };
|
|
654
|
+
if (content !== void 0) message.content = content;
|
|
655
|
+
if (rawCalls !== void 0) message.tool_calls = calls;
|
|
656
|
+
messages.push(message);
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
if (role === "tool") {
|
|
660
|
+
const keys = ensureOnlyKeys(item, /* @__PURE__ */ new Set(["role", "tool_call_id", "content"]), param);
|
|
661
|
+
if (keys) return keys;
|
|
662
|
+
if (typeof item.tool_call_id !== "string" || item.tool_call_id.length === 0) return invalidValue(`${param}.tool_call_id`, "must be a non-empty string");
|
|
663
|
+
if (!toolCalls.has(item.tool_call_id)) return invalidValue(`${param}.tool_call_id`, "must reference an earlier assistant tool call");
|
|
664
|
+
if (toolResults.has(item.tool_call_id)) return invalidValue(`${param}.tool_call_id`, "may appear only once");
|
|
665
|
+
if (typeof item.content !== "string" || item.content.length === 0) return invalidValue(`${param}.content`, "must be a non-empty string");
|
|
666
|
+
toolResults.add(item.tool_call_id);
|
|
667
|
+
messages.push({ role, tool_call_id: item.tool_call_id, content: item.content });
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
670
|
+
if (typeof role !== "string") return invalidValue(`${param}.role`, "must be a string");
|
|
671
|
+
return unsupportedValue(`${param}.role`, `unknown message role "${role}"`);
|
|
672
|
+
}
|
|
673
|
+
return ok(messages);
|
|
674
|
+
}
|
|
675
|
+
function validateEnlittStandardRequest(value) {
|
|
676
|
+
if (!isPlainObject2(value)) return invalidValue("body", "request body must be a JSON object");
|
|
677
|
+
for (const key of Object.keys(value)) {
|
|
678
|
+
if (!ACCEPTED_REQUEST_FIELDS.has(key)) {
|
|
679
|
+
return unsupportedParameter(key, `"${key}" is not accepted by this surface`);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
const modelValue = value.model;
|
|
683
|
+
if (typeof modelValue !== "string") return invalidValue("model", "model is required");
|
|
684
|
+
if (modelValue !== ENLITT_STANDARD_MODEL) {
|
|
685
|
+
return unsupportedValue("model", `model must be "${ENLITT_STANDARD_MODEL}"`);
|
|
686
|
+
}
|
|
687
|
+
const messages = validateMessages(value.messages);
|
|
688
|
+
if (!messages.ok) return messages;
|
|
689
|
+
const request = {
|
|
690
|
+
model: ENLITT_STANDARD_MODEL,
|
|
691
|
+
messages: messages.value
|
|
692
|
+
};
|
|
693
|
+
const tools = value.tools;
|
|
694
|
+
if (tools !== void 0) {
|
|
695
|
+
const toolsResult = validateFunctionTools(tools, "tools");
|
|
696
|
+
if (!toolsResult.ok) return toolsResult;
|
|
697
|
+
request.tools = toolsResult.value;
|
|
698
|
+
}
|
|
699
|
+
const maxOutputTokens = value.max_output_tokens;
|
|
700
|
+
if (maxOutputTokens !== void 0) {
|
|
701
|
+
if (typeof maxOutputTokens !== "number" || !Number.isInteger(maxOutputTokens) || maxOutputTokens <= 0) {
|
|
702
|
+
return invalidValue("max_output_tokens", "must be a positive integer");
|
|
703
|
+
}
|
|
704
|
+
request.max_output_tokens = maxOutputTokens;
|
|
705
|
+
}
|
|
706
|
+
const stream = value.stream;
|
|
707
|
+
if (stream !== void 0) {
|
|
708
|
+
if (typeof stream !== "boolean") return invalidValue("stream", "must be a boolean");
|
|
709
|
+
request.stream = stream;
|
|
710
|
+
}
|
|
711
|
+
const metadata = value.metadata;
|
|
712
|
+
if (metadata !== void 0) {
|
|
713
|
+
const metadataResult = validateCallerMetadata(metadata, "metadata");
|
|
714
|
+
if (!metadataResult.ok) return metadataResult;
|
|
715
|
+
request.metadata = metadataResult.value;
|
|
716
|
+
}
|
|
717
|
+
return ok(request);
|
|
718
|
+
}
|
|
719
|
+
var RESPONSE_STATUSES = Object.freeze([
|
|
720
|
+
"completed",
|
|
721
|
+
"failed",
|
|
722
|
+
"in_progress",
|
|
723
|
+
"cancelled",
|
|
724
|
+
"queued",
|
|
725
|
+
"incomplete"
|
|
726
|
+
]);
|
|
727
|
+
var RESPONSE_STATUS_SET = new Set(RESPONSE_STATUSES);
|
|
728
|
+
var RESPONSE_INCOMPLETE_REASONS = Object.freeze(["max_output_tokens"]);
|
|
729
|
+
var RESPONSE_INCOMPLETE_REASON_SET = new Set(RESPONSE_INCOMPLETE_REASONS);
|
|
730
|
+
var RESPONSE_ITEM_STATUSES = Object.freeze(["in_progress", "completed", "incomplete"]);
|
|
731
|
+
var ITEM_STATUSES = new Set(RESPONSE_ITEM_STATUSES);
|
|
732
|
+
function isTolerant(options) {
|
|
733
|
+
return options?.mode === "tolerant";
|
|
734
|
+
}
|
|
735
|
+
function rejectResponseUnknownKeys(value, allowed, param, options) {
|
|
736
|
+
if (isTolerant(options)) return void 0;
|
|
737
|
+
for (const key of Object.keys(value)) {
|
|
738
|
+
if (!allowed.has(key)) return invalidValue(param ? `${param}.${key}` : key, `unknown response field "${key}"`);
|
|
739
|
+
}
|
|
740
|
+
return void 0;
|
|
741
|
+
}
|
|
742
|
+
function readableMember(value, members, param, options) {
|
|
743
|
+
if (typeof value !== "string") return invalidValue(param, "must be a string");
|
|
744
|
+
if (members.has(value)) return ok(value);
|
|
745
|
+
return isTolerant(options) ? ok(UNKNOWN_ENUM_VALUE) : unsupportedValue(param, `unknown value "${value}"`);
|
|
746
|
+
}
|
|
747
|
+
function validateOutputTextPart(value, param, options) {
|
|
748
|
+
if (!isPlainObject2(value)) return invalidValue(param, "must be a content part object");
|
|
749
|
+
if (value.type !== "output_text") {
|
|
750
|
+
if (isTolerant(options) && typeof value.type === "string" && value.type.length <= 64) {
|
|
751
|
+
return ok({ unknown: true, type: value.type });
|
|
752
|
+
}
|
|
753
|
+
return unsupportedValue(`${param}.type`, `unknown output content part type "${String(value.type)}"`);
|
|
754
|
+
}
|
|
755
|
+
const keys = rejectResponseUnknownKeys(value, /* @__PURE__ */ new Set(["type", "text"]), param, options);
|
|
756
|
+
if (keys) return keys;
|
|
757
|
+
const text = value.text;
|
|
758
|
+
if (typeof text !== "string") return invalidValue(`${param}.text`, "must be a string");
|
|
759
|
+
return ok({ type: "output_text", text });
|
|
760
|
+
}
|
|
761
|
+
function validateResponseOutputItem(value, param, options) {
|
|
762
|
+
if (!isPlainObject2(value)) return invalidValue(param, "must be an output item object");
|
|
763
|
+
const type = value.type;
|
|
764
|
+
if (typeof type !== "string") return invalidValue(`${param}.type`, "must be a string");
|
|
765
|
+
if (type !== "message" && type !== "function_call") {
|
|
766
|
+
if (isTolerant(options) && type.length <= 64) return ok({ unknown: true, type });
|
|
767
|
+
return unsupportedValue(`${param}.type`, `unknown output item type "${type}"`);
|
|
768
|
+
}
|
|
769
|
+
const id = value.id;
|
|
770
|
+
if (typeof id !== "string") return invalidValue(`${param}.id`, "must be a string");
|
|
771
|
+
const statusResult = readableMember(value.status, ITEM_STATUSES, `${param}.status`, options);
|
|
772
|
+
if (!statusResult.ok) return statusResult;
|
|
773
|
+
const status = statusResult.value;
|
|
774
|
+
switch (type) {
|
|
775
|
+
case "message": {
|
|
776
|
+
const keys = rejectResponseUnknownKeys(value, /* @__PURE__ */ new Set(["type", "id", "role", "status", "content"]), param, options);
|
|
777
|
+
if (keys) return keys;
|
|
778
|
+
if (value.role !== "assistant") return invalidValue(`${param}.role`, 'must be "assistant"');
|
|
779
|
+
const content = value.content;
|
|
780
|
+
if (!Array.isArray(content)) return invalidValue(`${param}.content`, "must be an array");
|
|
781
|
+
const parts = [];
|
|
782
|
+
for (const [index, part] of content.entries()) {
|
|
783
|
+
const partResult = validateOutputTextPart(part, `${param}.content[${index}]`, options);
|
|
784
|
+
if (!partResult.ok) return partResult;
|
|
785
|
+
parts.push(partResult.value);
|
|
786
|
+
}
|
|
787
|
+
return ok({
|
|
788
|
+
type: "message",
|
|
789
|
+
id,
|
|
790
|
+
role: "assistant",
|
|
791
|
+
status,
|
|
792
|
+
content: parts
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
case "function_call": {
|
|
796
|
+
const keys = rejectResponseUnknownKeys(value, /* @__PURE__ */ new Set(["type", "id", "call_id", "name", "arguments", "status"]), param, options);
|
|
797
|
+
if (keys) return keys;
|
|
798
|
+
const callId = value.call_id;
|
|
799
|
+
if (typeof callId !== "string") return invalidValue(`${param}.call_id`, "must be a string");
|
|
800
|
+
const name = value.name;
|
|
801
|
+
if (typeof name !== "string") return invalidValue(`${param}.name`, "must be a string");
|
|
802
|
+
const args = value.arguments;
|
|
803
|
+
if (typeof args !== "string") return invalidValue(`${param}.arguments`, "must be a string");
|
|
804
|
+
return ok({
|
|
805
|
+
type: "function_call",
|
|
806
|
+
id,
|
|
807
|
+
call_id: callId,
|
|
808
|
+
name,
|
|
809
|
+
arguments: args,
|
|
810
|
+
status
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
function validateOpenAIResponse(value, options) {
|
|
816
|
+
if (!isPlainObject2(value)) return invalidValue("body", "response must be a JSON object");
|
|
817
|
+
const rootKeys = rejectResponseUnknownKeys(value, /* @__PURE__ */ new Set([
|
|
818
|
+
"id",
|
|
819
|
+
"object",
|
|
820
|
+
"created_at",
|
|
821
|
+
"completed_at",
|
|
822
|
+
"status",
|
|
823
|
+
"error",
|
|
824
|
+
"incomplete_details",
|
|
825
|
+
"model",
|
|
826
|
+
"output",
|
|
827
|
+
"output_text",
|
|
828
|
+
"usage",
|
|
829
|
+
"metadata"
|
|
830
|
+
]), "", options);
|
|
831
|
+
if (rootKeys) return rootKeys;
|
|
832
|
+
const id = value.id;
|
|
833
|
+
if (typeof id !== "string") return invalidValue("id", "must be a string");
|
|
834
|
+
if (value.object !== "response") return invalidValue("object", 'must be "response"');
|
|
835
|
+
const createdAt = value.created_at;
|
|
836
|
+
if (typeof createdAt !== "number" || !Number.isInteger(createdAt)) {
|
|
837
|
+
return invalidValue("created_at", "must be an integer");
|
|
838
|
+
}
|
|
839
|
+
const completedAt = value.completed_at;
|
|
840
|
+
if (completedAt !== void 0 && (typeof completedAt !== "number" || !Number.isInteger(completedAt))) {
|
|
841
|
+
return invalidValue("completed_at", "must be an integer");
|
|
842
|
+
}
|
|
843
|
+
const statusResult = readableMember(value.status, RESPONSE_STATUS_SET, "status", options);
|
|
844
|
+
if (!statusResult.ok) return statusResult;
|
|
845
|
+
const status = statusResult.value;
|
|
846
|
+
const errorField = value.error;
|
|
847
|
+
if (errorField !== null) {
|
|
848
|
+
if (!isPlainObject2(errorField)) return invalidValue("error", "must be null or an object");
|
|
849
|
+
const keys = rejectResponseUnknownKeys(errorField, /* @__PURE__ */ new Set(["code", "message"]), "error", options);
|
|
850
|
+
if (keys) return keys;
|
|
851
|
+
if (typeof errorField.code !== "string") return invalidValue("error.code", "must be a string");
|
|
852
|
+
if (typeof errorField.message !== "string") return invalidValue("error.message", "must be a string");
|
|
853
|
+
}
|
|
854
|
+
const incompleteDetails = value.incomplete_details;
|
|
855
|
+
let incompleteReason;
|
|
856
|
+
if (incompleteDetails !== null) {
|
|
857
|
+
if (!isPlainObject2(incompleteDetails)) {
|
|
858
|
+
return invalidValue("incomplete_details", "must be null or an object");
|
|
859
|
+
}
|
|
860
|
+
const keys = rejectResponseUnknownKeys(incompleteDetails, /* @__PURE__ */ new Set(["reason"]), "incomplete_details", options);
|
|
861
|
+
if (keys) return keys;
|
|
862
|
+
const reasonResult = readableMember(incompleteDetails.reason, RESPONSE_INCOMPLETE_REASON_SET, "incomplete_details.reason", options);
|
|
863
|
+
if (!reasonResult.ok) return reasonResult;
|
|
864
|
+
incompleteReason = reasonResult.value;
|
|
865
|
+
}
|
|
866
|
+
const model = value.model;
|
|
867
|
+
if (model !== ENLITT_STANDARD_MODEL) {
|
|
868
|
+
return unsupportedValue("model", `model must be "${ENLITT_STANDARD_MODEL}"`);
|
|
869
|
+
}
|
|
870
|
+
const outputValue = value.output;
|
|
871
|
+
if (!Array.isArray(outputValue)) return invalidValue("output", "must be an array");
|
|
872
|
+
const output = [];
|
|
873
|
+
for (const [index, item] of outputValue.entries()) {
|
|
874
|
+
const result = validateResponseOutputItem(item, `output[${index}]`, options);
|
|
875
|
+
if (!result.ok) return result;
|
|
876
|
+
output.push(result.value);
|
|
877
|
+
}
|
|
878
|
+
const outputText = value.output_text;
|
|
879
|
+
if (outputText !== void 0 && typeof outputText !== "string") {
|
|
880
|
+
return invalidValue("output_text", "must be a string");
|
|
881
|
+
}
|
|
882
|
+
const usageValue = value.usage;
|
|
883
|
+
let usage;
|
|
884
|
+
if (usageValue !== void 0) {
|
|
885
|
+
if (!isPlainObject2(usageValue)) return invalidValue("usage", "must be an object");
|
|
886
|
+
const usageKeys = rejectResponseUnknownKeys(usageValue, /* @__PURE__ */ new Set(["input_tokens", "input_tokens_details", "output_tokens", "output_tokens_details", "total_tokens"]), "usage", options);
|
|
887
|
+
if (usageKeys) return usageKeys;
|
|
888
|
+
const inputTokens = usageValue.input_tokens;
|
|
889
|
+
const outputTokens = usageValue.output_tokens;
|
|
890
|
+
const totalTokens = usageValue.total_tokens;
|
|
891
|
+
if (typeof inputTokens !== "number" || !Number.isInteger(inputTokens)) {
|
|
892
|
+
return invalidValue("usage.input_tokens", "must be an integer");
|
|
893
|
+
}
|
|
894
|
+
if (typeof outputTokens !== "number" || !Number.isInteger(outputTokens)) {
|
|
895
|
+
return invalidValue("usage.output_tokens", "must be an integer");
|
|
896
|
+
}
|
|
897
|
+
if (typeof totalTokens !== "number" || !Number.isInteger(totalTokens)) {
|
|
898
|
+
return invalidValue("usage.total_tokens", "must be an integer");
|
|
899
|
+
}
|
|
900
|
+
usage = { input_tokens: inputTokens, output_tokens: outputTokens, total_tokens: totalTokens };
|
|
901
|
+
if (usageValue.input_tokens_details !== void 0) {
|
|
902
|
+
if (!isPlainObject2(usageValue.input_tokens_details)) return invalidValue("usage.input_tokens_details", "must be an object");
|
|
903
|
+
const detailKeys = rejectResponseUnknownKeys(usageValue.input_tokens_details, /* @__PURE__ */ new Set(["cached_tokens"]), "usage.input_tokens_details", options);
|
|
904
|
+
if (detailKeys) return detailKeys;
|
|
905
|
+
if (usageValue.input_tokens_details.cached_tokens !== void 0 && (typeof usageValue.input_tokens_details.cached_tokens !== "number" || !Number.isInteger(usageValue.input_tokens_details.cached_tokens))) return invalidValue("usage.input_tokens_details.cached_tokens", "must be an integer");
|
|
906
|
+
usage = { ...usage, input_tokens_details: usageValue.input_tokens_details.cached_tokens === void 0 ? {} : { cached_tokens: usageValue.input_tokens_details.cached_tokens } };
|
|
907
|
+
}
|
|
908
|
+
if (usageValue.output_tokens_details !== void 0) {
|
|
909
|
+
if (!isPlainObject2(usageValue.output_tokens_details)) return invalidValue("usage.output_tokens_details", "must be an object");
|
|
910
|
+
const detailKeys = rejectResponseUnknownKeys(usageValue.output_tokens_details, /* @__PURE__ */ new Set(["reasoning_tokens"]), "usage.output_tokens_details", options);
|
|
911
|
+
if (detailKeys) return detailKeys;
|
|
912
|
+
if (usageValue.output_tokens_details.reasoning_tokens !== void 0 && (typeof usageValue.output_tokens_details.reasoning_tokens !== "number" || !Number.isInteger(usageValue.output_tokens_details.reasoning_tokens))) return invalidValue("usage.output_tokens_details.reasoning_tokens", "must be an integer");
|
|
913
|
+
usage = { ...usage, output_tokens_details: usageValue.output_tokens_details.reasoning_tokens === void 0 ? {} : { reasoning_tokens: usageValue.output_tokens_details.reasoning_tokens } };
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
const metadataValue = value.metadata;
|
|
917
|
+
if (!isPlainObject2(metadataValue)) return invalidValue("metadata", "must be an object of string values");
|
|
918
|
+
const metadata = {};
|
|
919
|
+
for (const [key, entryValue] of Object.entries(metadataValue)) {
|
|
920
|
+
if (typeof entryValue !== "string") return invalidValue(`metadata.${key}`, "value must be a string");
|
|
921
|
+
metadata[key] = entryValue;
|
|
922
|
+
}
|
|
923
|
+
const response = {
|
|
924
|
+
id,
|
|
925
|
+
object: "response",
|
|
926
|
+
created_at: createdAt,
|
|
927
|
+
status,
|
|
928
|
+
error: errorField === null ? null : { code: errorField.code, message: errorField.message },
|
|
929
|
+
incomplete_details: incompleteDetails === null ? null : { reason: incompleteReason },
|
|
930
|
+
model: ENLITT_STANDARD_MODEL,
|
|
931
|
+
output,
|
|
932
|
+
metadata
|
|
933
|
+
};
|
|
934
|
+
if (completedAt !== void 0) response.completed_at = completedAt;
|
|
935
|
+
if (outputText !== void 0) response.output_text = outputText;
|
|
936
|
+
if (usage !== void 0) response.usage = usage;
|
|
937
|
+
return ok(response);
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
// src/premium-operations.ts
|
|
941
|
+
function ok2(value) {
|
|
942
|
+
return { ok: true, value };
|
|
943
|
+
}
|
|
944
|
+
function fail(code, param, message) {
|
|
945
|
+
return { ok: false, error: { code, param, message } };
|
|
946
|
+
}
|
|
947
|
+
function invalidValue2(param, message) {
|
|
948
|
+
return fail(ENLITT_ERROR_CODE.invalid_value, param, message);
|
|
949
|
+
}
|
|
950
|
+
function unsupportedParameter2(param, message) {
|
|
951
|
+
return fail(ENLITT_ERROR_CODE.unsupported_parameter, param, message);
|
|
952
|
+
}
|
|
953
|
+
function unsupportedValue2(param, message) {
|
|
954
|
+
return fail(ENLITT_ERROR_CODE.unsupported_value, param, message);
|
|
955
|
+
}
|
|
956
|
+
function isPlainObject3(value) {
|
|
957
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
958
|
+
}
|
|
959
|
+
function rejectUnknownFields(value, param, allowed) {
|
|
960
|
+
for (const key of Object.keys(value)) {
|
|
961
|
+
if (!allowed.includes(key)) {
|
|
962
|
+
const field = param === "body" ? key : `${param}.${key}`;
|
|
963
|
+
return unsupportedParameter2(field, `"${field}" is not accepted by this surface`);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
return ok2(void 0);
|
|
967
|
+
}
|
|
968
|
+
var RFC3339_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|z|[+-]\d{2}:\d{2})$/;
|
|
969
|
+
var VISIBLE_ASCII2 = /^[\x21-\x7e]+$/;
|
|
970
|
+
function expectRfc3339(value, param) {
|
|
971
|
+
if (typeof value !== "string" || !RFC3339_PATTERN.test(value)) {
|
|
972
|
+
return invalidValue2(param, "must be an RFC 3339 timestamp");
|
|
973
|
+
}
|
|
974
|
+
return ok2(value);
|
|
975
|
+
}
|
|
976
|
+
function expectNonNegativeSafeInteger(value, param) {
|
|
977
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
|
|
978
|
+
return invalidValue2(param, "must be a nonnegative safe integer");
|
|
979
|
+
}
|
|
980
|
+
return ok2(value);
|
|
981
|
+
}
|
|
982
|
+
function expectCanonicalNanoUsd(value, param, maxDigits) {
|
|
983
|
+
if (!isCanonicalIntegerString(value)) {
|
|
984
|
+
return invalidValue2(param, "must be a canonical nonnegative NANOUSD integer string");
|
|
985
|
+
}
|
|
986
|
+
if (maxDigits !== void 0 && value.length > maxDigits) {
|
|
987
|
+
return invalidValue2(param, `must not exceed ${maxDigits} digits`);
|
|
988
|
+
}
|
|
989
|
+
return ok2(value);
|
|
990
|
+
}
|
|
991
|
+
var PREMIUM_OPERATION_MAX_CHARGE_NANO_USD = "100000000000";
|
|
992
|
+
var PREMIUM_TERMINAL_CHARGE_MAX_DIGITS = 30;
|
|
993
|
+
var PREMIUM_OPERATION_BILLING_VALUES = Object.freeze(["managed"]);
|
|
994
|
+
var PREMIUM_TERMINAL_STATUSES = Object.freeze(["completed", "failed", "canceled"]);
|
|
995
|
+
function rejectUnknownResponseFields(value, param, allowed, options) {
|
|
996
|
+
return options?.mode === "tolerant" ? ok2(void 0) : rejectUnknownFields(value, param, allowed);
|
|
997
|
+
}
|
|
998
|
+
function validateProvider(value, param) {
|
|
999
|
+
if (!isPlainObject3(value)) return invalidValue2(param, "must be a provider object");
|
|
1000
|
+
const unknown = rejectUnknownFields(value, param, ["id", "model"]);
|
|
1001
|
+
if (!unknown.ok) return unknown;
|
|
1002
|
+
if (typeof value.id !== "string") return invalidValue2(`${param}.id`, "must be a string");
|
|
1003
|
+
if (typeof value.model !== "string") return invalidValue2(`${param}.model`, "must be a string");
|
|
1004
|
+
return ok2({ id: value.id, model: value.model });
|
|
1005
|
+
}
|
|
1006
|
+
function validateBeginPremiumOperationRequest(value) {
|
|
1007
|
+
if (!isPlainObject3(value)) return invalidValue2("body", "request body must be a JSON object");
|
|
1008
|
+
const unknown = rejectUnknownFields(value, "body", [
|
|
1009
|
+
"mode",
|
|
1010
|
+
"max_charge_nano_usd",
|
|
1011
|
+
"reporting_deadline_ms",
|
|
1012
|
+
"provider",
|
|
1013
|
+
"metadata"
|
|
1014
|
+
]);
|
|
1015
|
+
if (!unknown.ok) return unknown;
|
|
1016
|
+
if (value.mode !== "premium") {
|
|
1017
|
+
return typeof value.mode === "string" ? unsupportedValue2("mode", 'must be "premium"') : invalidValue2("mode", 'must be "premium"');
|
|
1018
|
+
}
|
|
1019
|
+
const maxCharge = expectCanonicalNanoUsd(value.max_charge_nano_usd, "max_charge_nano_usd");
|
|
1020
|
+
if (!maxCharge.ok) return maxCharge;
|
|
1021
|
+
if (BigInt(maxCharge.value) > BigInt(PREMIUM_OPERATION_MAX_CHARGE_NANO_USD)) {
|
|
1022
|
+
return invalidValue2("max_charge_nano_usd", "exceeds the deployed maximum single-call charge");
|
|
1023
|
+
}
|
|
1024
|
+
const provider = validateProvider(value.provider, "provider");
|
|
1025
|
+
if (!provider.ok) return provider;
|
|
1026
|
+
const request = { mode: "premium", max_charge_nano_usd: maxCharge.value, provider: provider.value };
|
|
1027
|
+
if (value.reporting_deadline_ms !== void 0) {
|
|
1028
|
+
const deadline = expectNonNegativeSafeInteger(value.reporting_deadline_ms, "reporting_deadline_ms");
|
|
1029
|
+
if (!deadline.ok || deadline.value === 0) {
|
|
1030
|
+
return !deadline.ok ? deadline : invalidValue2("reporting_deadline_ms", "must be a positive safe integer");
|
|
1031
|
+
}
|
|
1032
|
+
request.reporting_deadline_ms = deadline.value;
|
|
1033
|
+
}
|
|
1034
|
+
if (value.metadata !== void 0) {
|
|
1035
|
+
const metadata = validateCallerMetadata(value.metadata, "metadata");
|
|
1036
|
+
if (!metadata.ok) return metadata;
|
|
1037
|
+
request.metadata = metadata.value;
|
|
1038
|
+
}
|
|
1039
|
+
return ok2(request);
|
|
1040
|
+
}
|
|
1041
|
+
function validateBeginPremiumOperationResponse(value, options) {
|
|
1042
|
+
if (!isPlainObject3(value)) return invalidValue2("body", "response body must be a JSON object");
|
|
1043
|
+
const unknown = rejectUnknownResponseFields(value, "body", [
|
|
1044
|
+
"operation_id",
|
|
1045
|
+
"billing",
|
|
1046
|
+
"report_terminal",
|
|
1047
|
+
"effective_max_charge_nano_usd",
|
|
1048
|
+
"reserved_nano_usd",
|
|
1049
|
+
"terminal_deadline"
|
|
1050
|
+
], options);
|
|
1051
|
+
if (!unknown.ok) return unknown;
|
|
1052
|
+
if (typeof value.operation_id !== "string") return invalidValue2("operation_id", "must be a string");
|
|
1053
|
+
if (typeof value.billing !== "string") return invalidValue2("billing", "must be a string");
|
|
1054
|
+
const billing = value.billing === "managed" ? value.billing : options?.mode === "tolerant" ? UNKNOWN_ENUM_VALUE : void 0;
|
|
1055
|
+
if (billing === void 0) return unsupportedValue2("billing", 'must be "managed"');
|
|
1056
|
+
if (value.report_terminal !== true) return invalidValue2("report_terminal", "must be true");
|
|
1057
|
+
const effective = expectCanonicalNanoUsd(value.effective_max_charge_nano_usd, "effective_max_charge_nano_usd");
|
|
1058
|
+
if (!effective.ok) return effective;
|
|
1059
|
+
const reserved = expectCanonicalNanoUsd(value.reserved_nano_usd, "reserved_nano_usd");
|
|
1060
|
+
if (!reserved.ok) return reserved;
|
|
1061
|
+
const deadline = expectRfc3339(value.terminal_deadline, "terminal_deadline");
|
|
1062
|
+
if (!deadline.ok) return deadline;
|
|
1063
|
+
return ok2({
|
|
1064
|
+
operation_id: value.operation_id,
|
|
1065
|
+
billing,
|
|
1066
|
+
report_terminal: true,
|
|
1067
|
+
effective_max_charge_nano_usd: effective.value,
|
|
1068
|
+
reserved_nano_usd: reserved.value,
|
|
1069
|
+
terminal_deadline: deadline.value
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
function validateUsage(value, param) {
|
|
1073
|
+
if (!isPlainObject3(value)) return invalidValue2(param, "must be a usage object");
|
|
1074
|
+
const unknown = rejectUnknownFields(value, param, [
|
|
1075
|
+
"input_tokens",
|
|
1076
|
+
"output_tokens",
|
|
1077
|
+
"cached_input_tokens",
|
|
1078
|
+
"reasoning_tokens"
|
|
1079
|
+
]);
|
|
1080
|
+
if (!unknown.ok) return unknown;
|
|
1081
|
+
const usage = {};
|
|
1082
|
+
for (const key of ["input_tokens", "output_tokens", "cached_input_tokens", "reasoning_tokens"]) {
|
|
1083
|
+
if (value[key] === void 0) continue;
|
|
1084
|
+
const tokens = expectNonNegativeSafeInteger(value[key], `${param}.${key}`);
|
|
1085
|
+
if (!tokens.ok) return tokens;
|
|
1086
|
+
usage[key] = tokens.value;
|
|
1087
|
+
}
|
|
1088
|
+
return ok2(usage);
|
|
1089
|
+
}
|
|
1090
|
+
function validateDelivery(value, param) {
|
|
1091
|
+
if (!isPlainObject3(value)) return invalidValue2(param, "must be a delivery object");
|
|
1092
|
+
const unknown = rejectUnknownFields(value, param, ["output_started", "output_completed"]);
|
|
1093
|
+
if (!unknown.ok) return unknown;
|
|
1094
|
+
if (typeof value.output_started !== "boolean") return invalidValue2(`${param}.output_started`, "must be a boolean");
|
|
1095
|
+
if (typeof value.output_completed !== "boolean") return invalidValue2(`${param}.output_completed`, "must be a boolean");
|
|
1096
|
+
return ok2({ output_started: value.output_started, output_completed: value.output_completed });
|
|
1097
|
+
}
|
|
1098
|
+
function validateTiming(value, param) {
|
|
1099
|
+
if (!isPlainObject3(value)) return invalidValue2(param, "must be a timing object");
|
|
1100
|
+
const unknown = rejectUnknownFields(value, param, ["started_at", "ended_at"]);
|
|
1101
|
+
if (!unknown.ok) return unknown;
|
|
1102
|
+
const started = expectRfc3339(value.started_at, `${param}.started_at`);
|
|
1103
|
+
if (!started.ok) return started;
|
|
1104
|
+
const ended = expectRfc3339(value.ended_at, `${param}.ended_at`);
|
|
1105
|
+
if (!ended.ok) return ended;
|
|
1106
|
+
return ok2({ started_at: started.value, ended_at: ended.value });
|
|
1107
|
+
}
|
|
1108
|
+
function validateReportPremiumTerminalRequest(value) {
|
|
1109
|
+
if (!isPlainObject3(value)) return invalidValue2("body", "request body must be a JSON object");
|
|
1110
|
+
const unknown = rejectUnknownFields(value, "body", [
|
|
1111
|
+
"report_id",
|
|
1112
|
+
"status",
|
|
1113
|
+
"charge_nano_usd",
|
|
1114
|
+
"usage",
|
|
1115
|
+
"finish_reason",
|
|
1116
|
+
"provider_response_id",
|
|
1117
|
+
"delivery",
|
|
1118
|
+
"timing",
|
|
1119
|
+
"error_category"
|
|
1120
|
+
]);
|
|
1121
|
+
if (!unknown.ok) return unknown;
|
|
1122
|
+
if (typeof value.report_id !== "string" || value.report_id.length < 16 || value.report_id.length > 255 || !VISIBLE_ASCII2.test(value.report_id)) {
|
|
1123
|
+
return invalidValue2("report_id", "must be 16\u2013255 visible ASCII characters");
|
|
1124
|
+
}
|
|
1125
|
+
if (typeof value.status !== "string") return invalidValue2("status", "must be a terminal status string");
|
|
1126
|
+
if (value.status !== "completed" && value.status !== "failed" && value.status !== "canceled") {
|
|
1127
|
+
return unsupportedValue2("status", "must be completed, failed, or canceled");
|
|
1128
|
+
}
|
|
1129
|
+
const charge = expectCanonicalNanoUsd(
|
|
1130
|
+
value.charge_nano_usd,
|
|
1131
|
+
"charge_nano_usd",
|
|
1132
|
+
PREMIUM_TERMINAL_CHARGE_MAX_DIGITS
|
|
1133
|
+
);
|
|
1134
|
+
if (!charge.ok) return charge;
|
|
1135
|
+
const request = { report_id: value.report_id, status: value.status, charge_nano_usd: charge.value };
|
|
1136
|
+
if (value.usage !== void 0) {
|
|
1137
|
+
const usage = validateUsage(value.usage, "usage");
|
|
1138
|
+
if (!usage.ok) return usage;
|
|
1139
|
+
request.usage = usage.value;
|
|
1140
|
+
}
|
|
1141
|
+
for (const key of ["finish_reason", "provider_response_id"]) {
|
|
1142
|
+
if (value[key] === void 0) continue;
|
|
1143
|
+
if (typeof value[key] !== "string") return invalidValue2(key, "must be a string");
|
|
1144
|
+
request[key] = value[key];
|
|
1145
|
+
}
|
|
1146
|
+
if (value.delivery !== void 0) {
|
|
1147
|
+
const delivery = validateDelivery(value.delivery, "delivery");
|
|
1148
|
+
if (!delivery.ok) return delivery;
|
|
1149
|
+
request.delivery = delivery.value;
|
|
1150
|
+
}
|
|
1151
|
+
if (value.timing !== void 0) {
|
|
1152
|
+
const timing = validateTiming(value.timing, "timing");
|
|
1153
|
+
if (!timing.ok) return timing;
|
|
1154
|
+
request.timing = timing.value;
|
|
1155
|
+
}
|
|
1156
|
+
if (value.error_category !== void 0) {
|
|
1157
|
+
if (typeof value.error_category !== "string") {
|
|
1158
|
+
return invalidValue2("error_category", "must be a string");
|
|
1159
|
+
}
|
|
1160
|
+
const categories = /* @__PURE__ */ new Set([
|
|
1161
|
+
"provider",
|
|
1162
|
+
"timeout",
|
|
1163
|
+
"network",
|
|
1164
|
+
"invalid_request",
|
|
1165
|
+
"canceled",
|
|
1166
|
+
"unknown"
|
|
1167
|
+
]);
|
|
1168
|
+
if (!categories.has(value.error_category)) {
|
|
1169
|
+
return unsupportedValue2("error_category", "must be a supported error category");
|
|
1170
|
+
}
|
|
1171
|
+
request.error_category = value.error_category;
|
|
1172
|
+
}
|
|
1173
|
+
return ok2(request);
|
|
1174
|
+
}
|
|
1175
|
+
function validateReportPremiumTerminalResponse(value, options) {
|
|
1176
|
+
if (!isPlainObject3(value)) return invalidValue2("body", "response body must be a JSON object");
|
|
1177
|
+
const unknown = rejectUnknownResponseFields(value, "body", ["operation_id", "status", "idempotent_replay", "settlement"], options);
|
|
1178
|
+
if (!unknown.ok) return unknown;
|
|
1179
|
+
if (typeof value.operation_id !== "string") return invalidValue2("operation_id", "must be a string");
|
|
1180
|
+
if (typeof value.status !== "string") return invalidValue2("status", "must be a terminal status string");
|
|
1181
|
+
const status = value.status === "completed" || value.status === "failed" || value.status === "canceled" ? value.status : options?.mode === "tolerant" ? UNKNOWN_ENUM_VALUE : void 0;
|
|
1182
|
+
if (status === void 0) return unsupportedValue2("status", "must be completed, failed, or canceled");
|
|
1183
|
+
if (typeof value.idempotent_replay !== "boolean") return invalidValue2("idempotent_replay", "must be a boolean");
|
|
1184
|
+
if (!isPlainObject3(value.settlement)) return invalidValue2("settlement", "must be a settlement object");
|
|
1185
|
+
const settlementUnknown = rejectUnknownResponseFields(value.settlement, "settlement", [
|
|
1186
|
+
"captured_nano_usd",
|
|
1187
|
+
"released_nano_usd",
|
|
1188
|
+
"business_earnings_nano_usd"
|
|
1189
|
+
], options);
|
|
1190
|
+
if (!settlementUnknown.ok) return settlementUnknown;
|
|
1191
|
+
const captured = expectCanonicalNanoUsd(value.settlement.captured_nano_usd, "settlement.captured_nano_usd");
|
|
1192
|
+
if (!captured.ok) return captured;
|
|
1193
|
+
const released = expectCanonicalNanoUsd(value.settlement.released_nano_usd, "settlement.released_nano_usd");
|
|
1194
|
+
if (!released.ok) return released;
|
|
1195
|
+
const earnings = expectCanonicalNanoUsd(
|
|
1196
|
+
value.settlement.business_earnings_nano_usd,
|
|
1197
|
+
"settlement.business_earnings_nano_usd"
|
|
1198
|
+
);
|
|
1199
|
+
if (!earnings.ok) return earnings;
|
|
1200
|
+
return ok2({
|
|
1201
|
+
operation_id: value.operation_id,
|
|
1202
|
+
status,
|
|
1203
|
+
idempotent_replay: value.idempotent_replay,
|
|
1204
|
+
settlement: {
|
|
1205
|
+
captured_nano_usd: captured.value,
|
|
1206
|
+
released_nano_usd: released.value,
|
|
1207
|
+
business_earnings_nano_usd: earnings.value
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
// src/usage.ts
|
|
1213
|
+
function invalid(param, message) {
|
|
1214
|
+
return { ok: false, error: { code: ENLITT_ERROR_CODE.invalid_value, param, message } };
|
|
1215
|
+
}
|
|
1216
|
+
function isObject(value) {
|
|
1217
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1218
|
+
}
|
|
1219
|
+
function rejectUnknown(value, allowed, param, options) {
|
|
1220
|
+
if (options?.mode !== "tolerant") {
|
|
1221
|
+
for (const key of Object.keys(value)) {
|
|
1222
|
+
if (!allowed.includes(key)) return invalid(param ? `${param}.${key}` : key, `unknown response field "${key}"`);
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
return { ok: true, value: void 0 };
|
|
1226
|
+
}
|
|
1227
|
+
function validateAvailability(value, param, options) {
|
|
1228
|
+
if (!isObject(value)) return invalid(param, "must be an object");
|
|
1229
|
+
const keys = rejectUnknown(value, ["remaining_percent", "limit_cap_nano_usd"], param, options);
|
|
1230
|
+
if (!keys.ok) return keys;
|
|
1231
|
+
if (typeof value.remaining_percent !== "number" || !Number.isInteger(value.remaining_percent) || value.remaining_percent < 0 || value.remaining_percent > 100) {
|
|
1232
|
+
return invalid(`${param}.remaining_percent`, "must be an integer from 0 through 100");
|
|
1233
|
+
}
|
|
1234
|
+
if (!isCanonicalIntegerString(value.limit_cap_nano_usd)) {
|
|
1235
|
+
return invalid(`${param}.limit_cap_nano_usd`, "must be a canonical nonnegative NANOUSD integer string");
|
|
1236
|
+
}
|
|
1237
|
+
return { ok: true, value: { remaining_percent: value.remaining_percent, limit_cap_nano_usd: value.limit_cap_nano_usd } };
|
|
1238
|
+
}
|
|
1239
|
+
function validateUsageResponse(value, options) {
|
|
1240
|
+
if (!isObject(value)) return invalid("body", "response body must be a JSON object");
|
|
1241
|
+
const keys = rejectUnknown(value, ["standard", "premium"], "", options);
|
|
1242
|
+
if (!keys.ok) return keys;
|
|
1243
|
+
const standard = validateAvailability(value.standard, "standard", options);
|
|
1244
|
+
if (!standard.ok) return standard;
|
|
1245
|
+
const premium = validateAvailability(value.premium, "premium", options);
|
|
1246
|
+
if (!premium.ok) return premium;
|
|
1247
|
+
return { ok: true, value: { standard: standard.value, premium: premium.value } };
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
// src/dashboard.ts
|
|
1251
|
+
var responseParseMode = "strict";
|
|
1252
|
+
function ok3(value) {
|
|
1253
|
+
return { ok: true, value };
|
|
1254
|
+
}
|
|
1255
|
+
function fail2(code, param, message) {
|
|
1256
|
+
return { ok: false, error: { code, param, message } };
|
|
1257
|
+
}
|
|
1258
|
+
function invalidValue3(param, message) {
|
|
1259
|
+
return fail2(ENLITT_ERROR_CODE.invalid_value, param, message);
|
|
1260
|
+
}
|
|
1261
|
+
function unsupportedParameter3(param, message) {
|
|
1262
|
+
return fail2(ENLITT_ERROR_CODE.unsupported_parameter, param, message);
|
|
1263
|
+
}
|
|
1264
|
+
function isPlainObject4(value) {
|
|
1265
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1266
|
+
}
|
|
1267
|
+
function withResponseOptions(value, options, parse) {
|
|
1268
|
+
const previousMode = responseParseMode;
|
|
1269
|
+
responseParseMode = options?.mode ?? previousMode;
|
|
1270
|
+
try {
|
|
1271
|
+
const result = parse();
|
|
1272
|
+
if (!result.ok || responseParseMode === "tolerant") return result;
|
|
1273
|
+
const unknown = findUnknownResponseField(value, result.value, "body");
|
|
1274
|
+
return unknown === null ? result : unsupportedParameter3(unknown, `"${unknown}" is not accepted by this response`);
|
|
1275
|
+
} finally {
|
|
1276
|
+
responseParseMode = previousMode;
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
function findUnknownResponseField(value, parsed, param) {
|
|
1280
|
+
if (Array.isArray(value) && Array.isArray(parsed)) {
|
|
1281
|
+
for (const [index, item] of value.entries()) {
|
|
1282
|
+
const unknown = findUnknownResponseField(item, parsed[index], `${param}[${index}]`);
|
|
1283
|
+
if (unknown !== null) return unknown;
|
|
1284
|
+
}
|
|
1285
|
+
return null;
|
|
1286
|
+
}
|
|
1287
|
+
if (!isPlainObject4(value) || !isPlainObject4(parsed)) return null;
|
|
1288
|
+
for (const [key, item] of Object.entries(value)) {
|
|
1289
|
+
if (!(key in parsed)) return `${param}.${key}`;
|
|
1290
|
+
const unknown = findUnknownResponseField(item, parsed[key], `${param}.${key}`);
|
|
1291
|
+
if (unknown !== null) return unknown;
|
|
1292
|
+
}
|
|
1293
|
+
return null;
|
|
1294
|
+
}
|
|
1295
|
+
var RFC3339_PATTERN2 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|z|[+-]\d{2}:\d{2})$/;
|
|
1296
|
+
var CALENDAR_DAY_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
|
1297
|
+
function expectRfc33392(value, param) {
|
|
1298
|
+
if (typeof value !== "string" || !RFC3339_PATTERN2.test(value)) {
|
|
1299
|
+
return invalidValue3(param, "must be an RFC 3339 timestamp");
|
|
1300
|
+
}
|
|
1301
|
+
return ok3(value);
|
|
1302
|
+
}
|
|
1303
|
+
function expectNullableRfc3339(value, param) {
|
|
1304
|
+
if (value === null) return ok3(null);
|
|
1305
|
+
return expectRfc33392(value, param);
|
|
1306
|
+
}
|
|
1307
|
+
function expectOptionalRfc3339(value, param) {
|
|
1308
|
+
if (value === void 0) return ok3(void 0);
|
|
1309
|
+
return expectRfc33392(value, param);
|
|
1310
|
+
}
|
|
1311
|
+
function expectCalendarDay(value, param) {
|
|
1312
|
+
if (typeof value !== "string" || !CALENDAR_DAY_PATTERN.test(value)) {
|
|
1313
|
+
return invalidValue3(param, "must be a YYYY-MM-DD calendar day");
|
|
1314
|
+
}
|
|
1315
|
+
return ok3(value);
|
|
1316
|
+
}
|
|
1317
|
+
function expectString(value, param) {
|
|
1318
|
+
if (typeof value !== "string") return invalidValue3(param, "must be a string");
|
|
1319
|
+
return ok3(value);
|
|
1320
|
+
}
|
|
1321
|
+
function expectOptionalString(value, param) {
|
|
1322
|
+
if (value === void 0) return ok3(void 0);
|
|
1323
|
+
return expectString(value, param);
|
|
1324
|
+
}
|
|
1325
|
+
function expectNullableString(value, param) {
|
|
1326
|
+
if (value === null) return ok3(null);
|
|
1327
|
+
return expectString(value, param);
|
|
1328
|
+
}
|
|
1329
|
+
function expectBoolean(value, param) {
|
|
1330
|
+
if (typeof value !== "boolean") return invalidValue3(param, "must be a boolean");
|
|
1331
|
+
return ok3(value);
|
|
1332
|
+
}
|
|
1333
|
+
function expectInteger(value, param) {
|
|
1334
|
+
if (typeof value !== "number" || !Number.isInteger(value)) {
|
|
1335
|
+
return invalidValue3(param, "must be an integer");
|
|
1336
|
+
}
|
|
1337
|
+
return ok3(value);
|
|
1338
|
+
}
|
|
1339
|
+
function expectNonNegativeInteger(value, param) {
|
|
1340
|
+
const result = expectInteger(value, param);
|
|
1341
|
+
if (!result.ok) return result;
|
|
1342
|
+
if (result.value < 0) return invalidValue3(param, "must be a nonnegative integer");
|
|
1343
|
+
return result;
|
|
1344
|
+
}
|
|
1345
|
+
function expectCanonicalAmount(value, param) {
|
|
1346
|
+
if (!isCanonicalIntegerString(value)) {
|
|
1347
|
+
return invalidValue3(param, "must be a canonical base-10 integer string");
|
|
1348
|
+
}
|
|
1349
|
+
return ok3(value);
|
|
1350
|
+
}
|
|
1351
|
+
function expectNullableCanonicalAmount(value, param) {
|
|
1352
|
+
if (value === null) return ok3(null);
|
|
1353
|
+
return expectCanonicalAmount(value, param);
|
|
1354
|
+
}
|
|
1355
|
+
function expectOptionalCanonicalAmount(value, param) {
|
|
1356
|
+
if (value === void 0) return ok3(void 0);
|
|
1357
|
+
return expectCanonicalAmount(value, param);
|
|
1358
|
+
}
|
|
1359
|
+
function expectPositiveCanonicalAmount(value, param) {
|
|
1360
|
+
const result = expectCanonicalAmount(value, param);
|
|
1361
|
+
if (!result.ok) return result;
|
|
1362
|
+
if (BigInt(result.value) <= 0n) return invalidValue3(param, "must be strictly positive");
|
|
1363
|
+
return result;
|
|
1364
|
+
}
|
|
1365
|
+
function expectNonNegativeCanonicalAmount(value, param) {
|
|
1366
|
+
return expectCanonicalAmount(value, param);
|
|
1367
|
+
}
|
|
1368
|
+
function expectLiteral(value, options, param) {
|
|
1369
|
+
if (typeof value === "string") {
|
|
1370
|
+
for (const option of options) {
|
|
1371
|
+
if (option === value) return ok3(option);
|
|
1372
|
+
}
|
|
1373
|
+
if (responseParseMode === "tolerant") return ok3(UNKNOWN_ENUM_VALUE);
|
|
1374
|
+
}
|
|
1375
|
+
return invalidValue3(param, `must be one of: ${options.join(", ")}`);
|
|
1376
|
+
}
|
|
1377
|
+
function expectNullableLiteral(value, options, param) {
|
|
1378
|
+
if (value === null) return ok3(null);
|
|
1379
|
+
return expectLiteral(value, options, param);
|
|
1380
|
+
}
|
|
1381
|
+
function rejectUnknownKeys(value, allowed) {
|
|
1382
|
+
for (const key of Object.keys(value)) {
|
|
1383
|
+
if (!allowed.includes(key)) {
|
|
1384
|
+
return unsupportedParameter3(key, `"${key}" is not accepted by this route`);
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
return ok3(void 0);
|
|
1388
|
+
}
|
|
1389
|
+
function rejectUnknownResponseKeys(value, allowed) {
|
|
1390
|
+
return responseParseMode === "tolerant" ? ok3(void 0) : rejectUnknownKeys(value, allowed);
|
|
1391
|
+
}
|
|
1392
|
+
var PLAN_INTERVALS = ["month", "year"];
|
|
1393
|
+
function validateSubscriptionPlanSummary(value, param = "plan", options) {
|
|
1394
|
+
return withResponseOptions(value, options, () => validateSubscriptionPlanSummaryShape(value, param));
|
|
1395
|
+
}
|
|
1396
|
+
function validateSubscriptionPlanSummaryShape(value, param) {
|
|
1397
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
1398
|
+
const id = expectString(value.id, `${param}.id`);
|
|
1399
|
+
if (!id.ok) return id;
|
|
1400
|
+
const displayName = expectString(value.display_name, `${param}.display_name`);
|
|
1401
|
+
if (!displayName.ok) return displayName;
|
|
1402
|
+
const isFree = expectBoolean(value.is_free, `${param}.is_free`);
|
|
1403
|
+
if (!isFree.ok) return isFree;
|
|
1404
|
+
const priceMinorUnits = expectCanonicalAmount(
|
|
1405
|
+
value.price_minor_units,
|
|
1406
|
+
`${param}.price_minor_units`
|
|
1407
|
+
);
|
|
1408
|
+
if (!priceMinorUnits.ok) return priceMinorUnits;
|
|
1409
|
+
const currency = expectString(value.currency, `${param}.currency`);
|
|
1410
|
+
if (!currency.ok) return currency;
|
|
1411
|
+
const interval = expectLiteral(value.interval, PLAN_INTERVALS, `${param}.interval`);
|
|
1412
|
+
if (!interval.ok) return interval;
|
|
1413
|
+
const catalogVersion = expectString(value.catalog_version, `${param}.catalog_version`);
|
|
1414
|
+
if (!catalogVersion.ok) return catalogVersion;
|
|
1415
|
+
return ok3({
|
|
1416
|
+
id: id.value,
|
|
1417
|
+
display_name: displayName.value,
|
|
1418
|
+
is_free: isFree.value,
|
|
1419
|
+
price_minor_units: priceMinorUnits.value,
|
|
1420
|
+
currency: currency.value,
|
|
1421
|
+
interval: interval.value,
|
|
1422
|
+
catalog_version: catalogVersion.value
|
|
1423
|
+
});
|
|
1424
|
+
}
|
|
1425
|
+
var SERVICE_TIERS = ["normal", "reduced", "minimum"];
|
|
1426
|
+
function validatePersonalStandardUsage(value, param) {
|
|
1427
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
1428
|
+
const used = expectCanonicalAmount(value.used, `${param}.used`);
|
|
1429
|
+
if (!used.ok) return used;
|
|
1430
|
+
const reserved = expectCanonicalAmount(value.reserved, `${param}.reserved`);
|
|
1431
|
+
if (!reserved.ok) return reserved;
|
|
1432
|
+
const limit = expectNullableCanonicalAmount(value.limit, `${param}.limit`);
|
|
1433
|
+
if (!limit.ok) return limit;
|
|
1434
|
+
const serviceTier = expectNullableLiteral(
|
|
1435
|
+
value.service_tier,
|
|
1436
|
+
SERVICE_TIERS,
|
|
1437
|
+
`${param}.service_tier`
|
|
1438
|
+
);
|
|
1439
|
+
if (!serviceTier.ok) return serviceTier;
|
|
1440
|
+
return ok3({
|
|
1441
|
+
used: used.value,
|
|
1442
|
+
reserved: reserved.value,
|
|
1443
|
+
limit: limit.value,
|
|
1444
|
+
service_tier: serviceTier.value
|
|
1445
|
+
});
|
|
1446
|
+
}
|
|
1447
|
+
function validatePersonalPremiumUsage(value, param) {
|
|
1448
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
1449
|
+
const used = expectCanonicalAmount(value.used, `${param}.used`);
|
|
1450
|
+
if (!used.ok) return used;
|
|
1451
|
+
const reserved = expectCanonicalAmount(value.reserved, `${param}.reserved`);
|
|
1452
|
+
if (!reserved.ok) return reserved;
|
|
1453
|
+
const limit = expectCanonicalAmount(value.limit, `${param}.limit`);
|
|
1454
|
+
if (!limit.ok) return limit;
|
|
1455
|
+
return ok3({ used: used.value, reserved: reserved.value, limit: limit.value });
|
|
1456
|
+
}
|
|
1457
|
+
function validatePersonalUsagePeriod(value, param = "usage", options) {
|
|
1458
|
+
return withResponseOptions(value, options, () => validatePersonalUsagePeriodShape(value, param));
|
|
1459
|
+
}
|
|
1460
|
+
function validatePersonalUsagePeriodShape(value, param) {
|
|
1461
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
1462
|
+
const periodStart = expectRfc33392(value.period_start, `${param}.period_start`);
|
|
1463
|
+
if (!periodStart.ok) return periodStart;
|
|
1464
|
+
const periodEnd = expectRfc33392(value.period_end, `${param}.period_end`);
|
|
1465
|
+
if (!periodEnd.ok) return periodEnd;
|
|
1466
|
+
const plan = validateSubscriptionPlanSummaryShape(value.plan, `${param}.plan`);
|
|
1467
|
+
if (!plan.ok) return plan;
|
|
1468
|
+
const standard = validatePersonalStandardUsage(value.standard, `${param}.standard`);
|
|
1469
|
+
if (!standard.ok) return standard;
|
|
1470
|
+
const premium = validatePersonalPremiumUsage(value.premium, `${param}.premium`);
|
|
1471
|
+
if (!premium.ok) return premium;
|
|
1472
|
+
return ok3({
|
|
1473
|
+
period_start: periodStart.value,
|
|
1474
|
+
period_end: periodEnd.value,
|
|
1475
|
+
plan: plan.value,
|
|
1476
|
+
standard: standard.value,
|
|
1477
|
+
premium: premium.value
|
|
1478
|
+
});
|
|
1479
|
+
}
|
|
1480
|
+
function validatePersonalUsagePeriodOrNull(value, param) {
|
|
1481
|
+
if (value === null) return ok3(null);
|
|
1482
|
+
return validatePersonalUsagePeriodShape(value, param);
|
|
1483
|
+
}
|
|
1484
|
+
function validatePersonalDashboardAccount(value) {
|
|
1485
|
+
if (!isPlainObject4(value)) return invalidValue3("account", "must be an object");
|
|
1486
|
+
const type = expectLiteral(value.type, ["user"], "account.type");
|
|
1487
|
+
if (!type.ok) return type;
|
|
1488
|
+
const id = expectString(value.id, "account.id");
|
|
1489
|
+
if (!id.ok) return id;
|
|
1490
|
+
const email = expectString(value.email, "account.email");
|
|
1491
|
+
if (!email.ok) return email;
|
|
1492
|
+
const displayName = expectOptionalString(value.display_name, "account.display_name");
|
|
1493
|
+
if (!displayName.ok) return displayName;
|
|
1494
|
+
return ok3({
|
|
1495
|
+
id: id.value,
|
|
1496
|
+
type: type.value,
|
|
1497
|
+
email: email.value,
|
|
1498
|
+
...displayName.value !== void 0 ? { display_name: displayName.value } : {}
|
|
1499
|
+
});
|
|
1500
|
+
}
|
|
1501
|
+
function validatePersonalDashboardSettings(value) {
|
|
1502
|
+
if (!isPlainObject4(value)) return invalidValue3("settings", "must be an object");
|
|
1503
|
+
const limit = expectNonNegativeCanonicalAmount(
|
|
1504
|
+
value.new_application_premium_per_call_limit,
|
|
1505
|
+
"settings.new_application_premium_per_call_limit"
|
|
1506
|
+
);
|
|
1507
|
+
if (!limit.ok) return limit;
|
|
1508
|
+
return ok3({ new_application_premium_per_call_limit: limit.value });
|
|
1509
|
+
}
|
|
1510
|
+
var SUBSCRIPTION_STATUSES = ["active", "past_due", "canceled", "suspended"];
|
|
1511
|
+
var CHANGE_MODES = ["checkout", "change", "locked", "unavailable"];
|
|
1512
|
+
var LOCKED_DOWNGRADE_MODES = ["checkout", "change"];
|
|
1513
|
+
function validatePersonalDashboardSubscription(value, options) {
|
|
1514
|
+
return withResponseOptions(value, options, () => validatePersonalDashboardSubscriptionShape(value));
|
|
1515
|
+
}
|
|
1516
|
+
function validatePersonalDashboardSubscriptionShape(value) {
|
|
1517
|
+
if (!isPlainObject4(value)) return invalidValue3("subscription", "must be an object");
|
|
1518
|
+
const status = expectLiteral(value.status, SUBSCRIPTION_STATUSES, "subscription.status");
|
|
1519
|
+
if (!status.ok) return status;
|
|
1520
|
+
const changeMode = expectLiteral(value.change_mode, CHANGE_MODES, "subscription.change_mode");
|
|
1521
|
+
if (!changeMode.ok) return changeMode;
|
|
1522
|
+
if (status.value === "suspended") {
|
|
1523
|
+
if (value.plan !== void 0)
|
|
1524
|
+
return invalidValue3("subscription.plan", "must be absent when status is suspended");
|
|
1525
|
+
if (value.current_period_end !== void 0) {
|
|
1526
|
+
return invalidValue3(
|
|
1527
|
+
"subscription.current_period_end",
|
|
1528
|
+
"must be absent when status is suspended"
|
|
1529
|
+
);
|
|
1530
|
+
}
|
|
1531
|
+
if (changeMode.value !== "unavailable") {
|
|
1532
|
+
return invalidValue3(
|
|
1533
|
+
"subscription.change_mode",
|
|
1534
|
+
'must be "unavailable" when status is suspended'
|
|
1535
|
+
);
|
|
1536
|
+
}
|
|
1537
|
+
} else if (status.value !== UNKNOWN_ENUM_VALUE && value.plan === void 0) {
|
|
1538
|
+
return invalidValue3("subscription.plan", "must be present for every non-suspended status");
|
|
1539
|
+
}
|
|
1540
|
+
const plan = value.plan === void 0 ? ok3(void 0) : validateSubscriptionPlanSummaryShape(value.plan, "subscription.plan");
|
|
1541
|
+
if (!plan.ok) return plan;
|
|
1542
|
+
const pendingPlan = value.pending_plan === void 0 ? ok3(void 0) : validateSubscriptionPlanSummaryShape(value.pending_plan, "subscription.pending_plan");
|
|
1543
|
+
if (!pendingPlan.ok) return pendingPlan;
|
|
1544
|
+
const currentPeriodEnd = expectOptionalRfc3339(
|
|
1545
|
+
value.current_period_end,
|
|
1546
|
+
"subscription.current_period_end"
|
|
1547
|
+
);
|
|
1548
|
+
if (!currentPeriodEnd.ok) return currentPeriodEnd;
|
|
1549
|
+
let lockedDowngrade;
|
|
1550
|
+
if (value.locked_downgrade !== void 0) {
|
|
1551
|
+
const mode = expectLiteral(
|
|
1552
|
+
value.locked_downgrade,
|
|
1553
|
+
LOCKED_DOWNGRADE_MODES,
|
|
1554
|
+
"subscription.locked_downgrade"
|
|
1555
|
+
);
|
|
1556
|
+
if (!mode.ok) return mode;
|
|
1557
|
+
const known = changeMode.value;
|
|
1558
|
+
if (known !== "locked" && known !== UNKNOWN_ENUM_VALUE) {
|
|
1559
|
+
return invalidValue3(
|
|
1560
|
+
"subscription.locked_downgrade",
|
|
1561
|
+
'must be absent unless change_mode is "locked"'
|
|
1562
|
+
);
|
|
1563
|
+
}
|
|
1564
|
+
lockedDowngrade = mode.value;
|
|
1565
|
+
}
|
|
1566
|
+
return ok3({
|
|
1567
|
+
status: status.value,
|
|
1568
|
+
change_mode: changeMode.value,
|
|
1569
|
+
...lockedDowngrade !== void 0 ? { locked_downgrade: lockedDowngrade } : {},
|
|
1570
|
+
...plan.value !== void 0 ? { plan: plan.value } : {},
|
|
1571
|
+
...pendingPlan.value !== void 0 ? { pending_plan: pendingPlan.value } : {},
|
|
1572
|
+
...currentPeriodEnd.value !== void 0 ? { current_period_end: currentPeriodEnd.value } : {}
|
|
1573
|
+
});
|
|
1574
|
+
}
|
|
1575
|
+
function validatePersonalPaymentMethod(value) {
|
|
1576
|
+
if (!isPlainObject4(value)) return invalidValue3("payment_method", "must be an object");
|
|
1577
|
+
const provider = expectString(value.provider, "payment_method.provider");
|
|
1578
|
+
if (!provider.ok) return provider;
|
|
1579
|
+
const brand = expectOptionalString(value.brand, "payment_method.brand");
|
|
1580
|
+
if (!brand.ok) return brand;
|
|
1581
|
+
const last4 = expectOptionalString(value.last4, "payment_method.last4");
|
|
1582
|
+
if (!last4.ok) return last4;
|
|
1583
|
+
const expiresMonth = value.expires_month === void 0 ? ok3(void 0) : expectInteger(value.expires_month, "payment_method.expires_month");
|
|
1584
|
+
if (!expiresMonth.ok) return expiresMonth;
|
|
1585
|
+
const expiresYear = value.expires_year === void 0 ? ok3(void 0) : expectInteger(value.expires_year, "payment_method.expires_year");
|
|
1586
|
+
if (!expiresYear.ok) return expiresYear;
|
|
1587
|
+
return ok3({
|
|
1588
|
+
provider: provider.value,
|
|
1589
|
+
...brand.value !== void 0 ? { brand: brand.value } : {},
|
|
1590
|
+
...last4.value !== void 0 ? { last4: last4.value } : {},
|
|
1591
|
+
...expiresMonth.value !== void 0 ? { expires_month: expiresMonth.value } : {},
|
|
1592
|
+
...expiresYear.value !== void 0 ? { expires_year: expiresYear.value } : {}
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1595
|
+
function validatePaymentMethodSetupResponse(value, options) {
|
|
1596
|
+
return withResponseOptions(value, options, () => validatePaymentMethodSetupResponseShape(value));
|
|
1597
|
+
}
|
|
1598
|
+
function validatePaymentMethodSetupResponseShape(value) {
|
|
1599
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
1600
|
+
const clientSecret = expectString(value.client_secret, "client_secret");
|
|
1601
|
+
if (!clientSecret.ok) return clientSecret;
|
|
1602
|
+
return ok3({ client_secret: clientSecret.value });
|
|
1603
|
+
}
|
|
1604
|
+
function validatePersonalExtraCredits(value) {
|
|
1605
|
+
if (!isPlainObject4(value)) return invalidValue3("extra_credits", "must be an object");
|
|
1606
|
+
const validateAmount = (candidate, param) => {
|
|
1607
|
+
if (!isPlainObject4(candidate)) return invalidValue3(param, "must be an object");
|
|
1608
|
+
const remaining = expectNonNegativeCanonicalAmount(candidate.remaining, `${param}.remaining`);
|
|
1609
|
+
if (!remaining.ok) return remaining;
|
|
1610
|
+
const reserved = expectNonNegativeCanonicalAmount(candidate.reserved, `${param}.reserved`);
|
|
1611
|
+
if (!reserved.ok) return reserved;
|
|
1612
|
+
return ok3({ remaining: remaining.value, reserved: reserved.value });
|
|
1613
|
+
};
|
|
1614
|
+
const standard = validateAmount(value.standard, "extra_credits.standard");
|
|
1615
|
+
if (!standard.ok) return standard;
|
|
1616
|
+
const premium = validateAmount(value.premium, "extra_credits.premium");
|
|
1617
|
+
if (!premium.ok) return premium;
|
|
1618
|
+
return ok3({ standard: standard.value, premium: premium.value });
|
|
1619
|
+
}
|
|
1620
|
+
function validatePersonalDashboard(value, options) {
|
|
1621
|
+
return withResponseOptions(value, options, () => validatePersonalDashboardShape(value));
|
|
1622
|
+
}
|
|
1623
|
+
function validatePersonalDashboardShape(value) {
|
|
1624
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
1625
|
+
const account = validatePersonalDashboardAccount(value.account);
|
|
1626
|
+
if (!account.ok) return account;
|
|
1627
|
+
const usage = validatePersonalUsagePeriodOrNull(value.usage, "usage");
|
|
1628
|
+
if (!usage.ok) return usage;
|
|
1629
|
+
const extraCredits = value.extra_credits === null ? ok3(null) : validatePersonalExtraCredits(value.extra_credits);
|
|
1630
|
+
if (!extraCredits.ok) return extraCredits;
|
|
1631
|
+
const settings = validatePersonalDashboardSettings(value.settings);
|
|
1632
|
+
if (!settings.ok) return settings;
|
|
1633
|
+
const subscription = validatePersonalDashboardSubscriptionShape(value.subscription);
|
|
1634
|
+
if (!subscription.ok) return subscription;
|
|
1635
|
+
const paymentMethod = value.payment_method === void 0 ? ok3(void 0) : validatePersonalPaymentMethod(value.payment_method);
|
|
1636
|
+
if (!paymentMethod.ok) return paymentMethod;
|
|
1637
|
+
if (subscription.value.status !== UNKNOWN_ENUM_VALUE && usage.value === null && subscription.value.status !== "suspended") {
|
|
1638
|
+
return invalidValue3("usage", "must be non-null unless subscription.status is suspended");
|
|
1639
|
+
}
|
|
1640
|
+
if (usage.value !== null && subscription.value.status === "suspended") {
|
|
1641
|
+
return invalidValue3("usage", "must be null when subscription.status is suspended");
|
|
1642
|
+
}
|
|
1643
|
+
if (usage.value === null !== (extraCredits.value === null)) {
|
|
1644
|
+
return invalidValue3("extra_credits", "must be null exactly when usage is null");
|
|
1645
|
+
}
|
|
1646
|
+
return ok3({
|
|
1647
|
+
account: account.value,
|
|
1648
|
+
usage: usage.value,
|
|
1649
|
+
extra_credits: extraCredits.value,
|
|
1650
|
+
settings: settings.value,
|
|
1651
|
+
subscription: subscription.value,
|
|
1652
|
+
...paymentMethod.value !== void 0 ? { payment_method: paymentMethod.value } : {}
|
|
1653
|
+
});
|
|
1654
|
+
}
|
|
1655
|
+
function validatePatchPersonalSettingsRequest(value) {
|
|
1656
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
1657
|
+
const rejected = rejectUnknownKeys(value, ["new_application_premium_per_call_limit"]);
|
|
1658
|
+
if (!rejected.ok) return rejected;
|
|
1659
|
+
if (value.new_application_premium_per_call_limit === void 0) return ok3({});
|
|
1660
|
+
const limit = expectNonNegativeCanonicalAmount(
|
|
1661
|
+
value.new_application_premium_per_call_limit,
|
|
1662
|
+
"new_application_premium_per_call_limit"
|
|
1663
|
+
);
|
|
1664
|
+
if (!limit.ok) return limit;
|
|
1665
|
+
return ok3({ new_application_premium_per_call_limit: limit.value });
|
|
1666
|
+
}
|
|
1667
|
+
var APPLICATION_ENVIRONMENTS = ["test", "live"];
|
|
1668
|
+
function validateApplicationLimits(value, param = "limits", options) {
|
|
1669
|
+
return withResponseOptions(value, options, () => validateApplicationLimitsShape(value, param));
|
|
1670
|
+
}
|
|
1671
|
+
function validateRateTuple(value, param) {
|
|
1672
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
1673
|
+
const rejected = rejectUnknownResponseKeys(value, ["credits", "period_minutes"]);
|
|
1674
|
+
if (!rejected.ok) return rejected;
|
|
1675
|
+
const credits = expectNonNegativeCanonicalAmount(value.credits, `${param}.credits`);
|
|
1676
|
+
if (!credits.ok) return credits;
|
|
1677
|
+
const periodMinutes = expectNonNegativeInteger(value.period_minutes, `${param}.period_minutes`);
|
|
1678
|
+
if (!periodMinutes.ok) return periodMinutes;
|
|
1679
|
+
if (periodMinutes.value < 1) return invalidValue3(`${param}.period_minutes`, "must be positive");
|
|
1680
|
+
return ok3({ credits: credits.value, period_minutes: periodMinutes.value });
|
|
1681
|
+
}
|
|
1682
|
+
function validateApplicationLimitsShape(value, param) {
|
|
1683
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
1684
|
+
const rejected = rejectUnknownResponseKeys(value, ["standard_per_call", "premium_per_call", "rate"]);
|
|
1685
|
+
if (!rejected.ok) return rejected;
|
|
1686
|
+
const standardPerCall = expectNonNegativeCanonicalAmount(
|
|
1687
|
+
value.standard_per_call,
|
|
1688
|
+
`${param}.standard_per_call`
|
|
1689
|
+
);
|
|
1690
|
+
if (!standardPerCall.ok) return standardPerCall;
|
|
1691
|
+
const premiumPerCall = expectNonNegativeCanonicalAmount(
|
|
1692
|
+
value.premium_per_call,
|
|
1693
|
+
`${param}.premium_per_call`
|
|
1694
|
+
);
|
|
1695
|
+
if (!premiumPerCall.ok) return premiumPerCall;
|
|
1696
|
+
const rate = value.rate;
|
|
1697
|
+
if (!isPlainObject4(rate)) return invalidValue3(`${param}.rate`, "must be an object");
|
|
1698
|
+
const rateRejected = rejectUnknownResponseKeys(rate, ["standard", "premium"]);
|
|
1699
|
+
if (!rateRejected.ok) return rateRejected;
|
|
1700
|
+
const standard = validateRateTuple(rate.standard, `${param}.rate.standard`);
|
|
1701
|
+
if (!standard.ok) return standard;
|
|
1702
|
+
const premium = validateRateTuple(rate.premium, `${param}.rate.premium`);
|
|
1703
|
+
if (!premium.ok) return premium;
|
|
1704
|
+
return ok3({
|
|
1705
|
+
standard_per_call: standardPerCall.value,
|
|
1706
|
+
premium_per_call: premiumPerCall.value,
|
|
1707
|
+
rate: { standard: standard.value, premium: premium.value }
|
|
1708
|
+
});
|
|
1709
|
+
}
|
|
1710
|
+
function validateConsentLimitsBody(value) {
|
|
1711
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
1712
|
+
const rejected = rejectUnknownKeys(value, ["limits"]);
|
|
1713
|
+
if (!rejected.ok) return rejected;
|
|
1714
|
+
const limits = value.limits;
|
|
1715
|
+
if (!isPlainObject4(limits)) return invalidValue3("limits", "must be an object");
|
|
1716
|
+
const nested = rejectUnknownKeys(limits, ["standard_per_call", "premium_per_call"]);
|
|
1717
|
+
if (!nested.ok) return nested;
|
|
1718
|
+
const premiumPerCall = expectNonNegativeCanonicalAmount(
|
|
1719
|
+
limits.premium_per_call,
|
|
1720
|
+
"limits.premium_per_call"
|
|
1721
|
+
);
|
|
1722
|
+
if (!premiumPerCall.ok) return premiumPerCall;
|
|
1723
|
+
if (limits.standard_per_call === void 0) {
|
|
1724
|
+
return ok3({ limits: { premium_per_call: premiumPerCall.value } });
|
|
1725
|
+
}
|
|
1726
|
+
const standardPerCall = expectNonNegativeCanonicalAmount(
|
|
1727
|
+
limits.standard_per_call,
|
|
1728
|
+
"limits.standard_per_call"
|
|
1729
|
+
);
|
|
1730
|
+
if (!standardPerCall.ok) return standardPerCall;
|
|
1731
|
+
return ok3({
|
|
1732
|
+
limits: { premium_per_call: premiumPerCall.value, standard_per_call: standardPerCall.value }
|
|
1733
|
+
});
|
|
1734
|
+
}
|
|
1735
|
+
function validatePersonalApplicationSummary(value, param) {
|
|
1736
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
1737
|
+
const id = expectString(value.id, `${param}.id`);
|
|
1738
|
+
if (!id.ok) return id;
|
|
1739
|
+
const name = expectString(value.name, `${param}.name`);
|
|
1740
|
+
if (!name.ok) return name;
|
|
1741
|
+
const iconUrl = expectOptionalString(value.icon_url, `${param}.icon_url`);
|
|
1742
|
+
if (!iconUrl.ok) return iconUrl;
|
|
1743
|
+
const description = expectOptionalString(value.description, `${param}.description`);
|
|
1744
|
+
if (!description.ok) return description;
|
|
1745
|
+
const businessDisplayName = expectString(
|
|
1746
|
+
value.business_display_name,
|
|
1747
|
+
`${param}.business_display_name`
|
|
1748
|
+
);
|
|
1749
|
+
if (!businessDisplayName.ok) return businessDisplayName;
|
|
1750
|
+
const environment = expectLiteral(
|
|
1751
|
+
value.environment,
|
|
1752
|
+
APPLICATION_ENVIRONMENTS,
|
|
1753
|
+
`${param}.environment`
|
|
1754
|
+
);
|
|
1755
|
+
if (!environment.ok) return environment;
|
|
1756
|
+
const limits = validateApplicationLimitsShape(value.limits, `${param}.limits`);
|
|
1757
|
+
if (!limits.ok) return limits;
|
|
1758
|
+
const authorizedAt = expectRfc33392(value.authorized_at, `${param}.authorized_at`);
|
|
1759
|
+
if (!authorizedAt.ok) return authorizedAt;
|
|
1760
|
+
const lastAuthorizedAt = expectRfc33392(value.last_authorized_at, `${param}.last_authorized_at`);
|
|
1761
|
+
if (!lastAuthorizedAt.ok) return lastAuthorizedAt;
|
|
1762
|
+
const revokedAt = value.revoked_at === null ? ok3(null) : expectRfc33392(value.revoked_at, `${param}.revoked_at`);
|
|
1763
|
+
if (!revokedAt.ok) return revokedAt;
|
|
1764
|
+
return ok3({
|
|
1765
|
+
id: id.value,
|
|
1766
|
+
name: name.value,
|
|
1767
|
+
...iconUrl.value !== void 0 ? { icon_url: iconUrl.value } : {},
|
|
1768
|
+
...description.value !== void 0 ? { description: description.value } : {},
|
|
1769
|
+
business_display_name: businessDisplayName.value,
|
|
1770
|
+
environment: environment.value,
|
|
1771
|
+
limits: limits.value,
|
|
1772
|
+
authorized_at: authorizedAt.value,
|
|
1773
|
+
last_authorized_at: lastAuthorizedAt.value,
|
|
1774
|
+
revoked_at: revokedAt.value
|
|
1775
|
+
});
|
|
1776
|
+
}
|
|
1777
|
+
function validatePersonalApplicationListItem(value, param) {
|
|
1778
|
+
const summary = validatePersonalApplicationSummary(value, param);
|
|
1779
|
+
if (!summary.ok) return summary;
|
|
1780
|
+
const raw = value;
|
|
1781
|
+
if (!isPlainObject4(raw.totals)) return invalidValue3(`${param}.totals`, "must be an object");
|
|
1782
|
+
const totals = raw.totals;
|
|
1783
|
+
const standardRequests = expectNonNegativeInteger(
|
|
1784
|
+
totals.standard_requests,
|
|
1785
|
+
`${param}.totals.standard_requests`
|
|
1786
|
+
);
|
|
1787
|
+
if (!standardRequests.ok) return standardRequests;
|
|
1788
|
+
const premiumRequests = expectNonNegativeInteger(
|
|
1789
|
+
totals.premium_requests,
|
|
1790
|
+
`${param}.totals.premium_requests`
|
|
1791
|
+
);
|
|
1792
|
+
if (!premiumRequests.ok) return premiumRequests;
|
|
1793
|
+
const standardUnitsUsed = expectCanonicalAmount(
|
|
1794
|
+
totals.standard_units_used,
|
|
1795
|
+
`${param}.totals.standard_units_used`
|
|
1796
|
+
);
|
|
1797
|
+
if (!standardUnitsUsed.ok) return standardUnitsUsed;
|
|
1798
|
+
const premiumUnitsUsed = expectCanonicalAmount(
|
|
1799
|
+
totals.premium_units_used,
|
|
1800
|
+
`${param}.totals.premium_units_used`
|
|
1801
|
+
);
|
|
1802
|
+
if (!premiumUnitsUsed.ok) return premiumUnitsUsed;
|
|
1803
|
+
return ok3({
|
|
1804
|
+
...summary.value,
|
|
1805
|
+
totals: {
|
|
1806
|
+
standard_requests: standardRequests.value,
|
|
1807
|
+
premium_requests: premiumRequests.value,
|
|
1808
|
+
standard_units_used: standardUnitsUsed.value,
|
|
1809
|
+
premium_units_used: premiumUnitsUsed.value
|
|
1810
|
+
}
|
|
1811
|
+
});
|
|
1812
|
+
}
|
|
1813
|
+
function validatePersonalApplicationsPage(value, options) {
|
|
1814
|
+
return withResponseOptions(value, options, () => validatePersonalApplicationsPageShape(value));
|
|
1815
|
+
}
|
|
1816
|
+
function validatePersonalApplicationsPageShape(value) {
|
|
1817
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
1818
|
+
if (!Array.isArray(value.applications)) return invalidValue3("applications", "must be an array");
|
|
1819
|
+
const applications = [];
|
|
1820
|
+
for (const [index, item] of value.applications.entries()) {
|
|
1821
|
+
const result = validatePersonalApplicationListItem(item, `applications[${index}]`);
|
|
1822
|
+
if (!result.ok) return result;
|
|
1823
|
+
applications.push(result.value);
|
|
1824
|
+
}
|
|
1825
|
+
const range = validateDashboardRange(value.range, "range");
|
|
1826
|
+
if (!range.ok) return range;
|
|
1827
|
+
const nextCursor = expectNullableString(value.next_cursor, "next_cursor");
|
|
1828
|
+
if (!nextCursor.ok) return nextCursor;
|
|
1829
|
+
return ok3({ applications, range: range.value, next_cursor: nextCursor.value });
|
|
1830
|
+
}
|
|
1831
|
+
var PERSONAL_APPLICATION_CALL_SORTS = ["time", "charge"];
|
|
1832
|
+
var PERSONAL_APPLICATION_CALLS_DEFAULT_LIMIT = 10;
|
|
1833
|
+
var PERSONAL_APPLICATION_CALLS_MAX_LIMIT = 50;
|
|
1834
|
+
var PERSONAL_APPLICATION_CALL_CREDIT_TYPES = ["standard", "premium"];
|
|
1835
|
+
var PERSONAL_APPLICATION_CALL_STATUSES = [
|
|
1836
|
+
"pending",
|
|
1837
|
+
"running",
|
|
1838
|
+
"completed",
|
|
1839
|
+
"failed",
|
|
1840
|
+
"canceled",
|
|
1841
|
+
"expired"
|
|
1842
|
+
];
|
|
1843
|
+
function expectNullableNonNegativeInteger(value, param) {
|
|
1844
|
+
if (value === null) return ok3(null);
|
|
1845
|
+
return expectNonNegativeInteger(value, param);
|
|
1846
|
+
}
|
|
1847
|
+
function validatePersonalApplicationCall(value, param) {
|
|
1848
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
1849
|
+
const id = expectString(value.id, `${param}.id`);
|
|
1850
|
+
if (!id.ok) return id;
|
|
1851
|
+
const creditType = expectLiteral(
|
|
1852
|
+
value.credit_type,
|
|
1853
|
+
PERSONAL_APPLICATION_CALL_CREDIT_TYPES,
|
|
1854
|
+
`${param}.credit_type`
|
|
1855
|
+
);
|
|
1856
|
+
if (!creditType.ok) return creditType;
|
|
1857
|
+
const status = expectLiteral(
|
|
1858
|
+
value.status,
|
|
1859
|
+
PERSONAL_APPLICATION_CALL_STATUSES,
|
|
1860
|
+
`${param}.status`
|
|
1861
|
+
);
|
|
1862
|
+
if (!status.ok) return status;
|
|
1863
|
+
const unitsUsed = expectCanonicalAmount(value.units_used, `${param}.units_used`);
|
|
1864
|
+
if (!unitsUsed.ok) return unitsUsed;
|
|
1865
|
+
const unitsReserved = expectCanonicalAmount(value.units_reserved, `${param}.units_reserved`);
|
|
1866
|
+
if (!unitsReserved.ok) return unitsReserved;
|
|
1867
|
+
const createdAt = expectRfc33392(value.created_at, `${param}.created_at`);
|
|
1868
|
+
if (!createdAt.ok) return createdAt;
|
|
1869
|
+
const terminalAt = expectNullableRfc3339(value.terminal_at, `${param}.terminal_at`);
|
|
1870
|
+
if (!terminalAt.ok) return terminalAt;
|
|
1871
|
+
const streamed = expectBoolean(value.streamed, `${param}.streamed`);
|
|
1872
|
+
if (!streamed.ok) return streamed;
|
|
1873
|
+
const modelId = expectNullableString(value.model_id, `${param}.model_id`);
|
|
1874
|
+
if (!modelId.ok) return modelId;
|
|
1875
|
+
const inputTokens = expectNullableNonNegativeInteger(
|
|
1876
|
+
value.input_tokens,
|
|
1877
|
+
`${param}.input_tokens`
|
|
1878
|
+
);
|
|
1879
|
+
if (!inputTokens.ok) return inputTokens;
|
|
1880
|
+
const outputTokens = expectNullableNonNegativeInteger(
|
|
1881
|
+
value.output_tokens,
|
|
1882
|
+
`${param}.output_tokens`
|
|
1883
|
+
);
|
|
1884
|
+
if (!outputTokens.ok) return outputTokens;
|
|
1885
|
+
const finishReason = expectNullableString(value.finish_reason, `${param}.finish_reason`);
|
|
1886
|
+
if (!finishReason.ok) return finishReason;
|
|
1887
|
+
const errorCategory = expectNullableString(value.error_category, `${param}.error_category`);
|
|
1888
|
+
if (!errorCategory.ok) return errorCategory;
|
|
1889
|
+
return ok3({
|
|
1890
|
+
id: id.value,
|
|
1891
|
+
credit_type: creditType.value,
|
|
1892
|
+
status: status.value,
|
|
1893
|
+
units_used: unitsUsed.value,
|
|
1894
|
+
units_reserved: unitsReserved.value,
|
|
1895
|
+
created_at: createdAt.value,
|
|
1896
|
+
terminal_at: terminalAt.value,
|
|
1897
|
+
streamed: streamed.value,
|
|
1898
|
+
model_id: modelId.value,
|
|
1899
|
+
input_tokens: inputTokens.value,
|
|
1900
|
+
output_tokens: outputTokens.value,
|
|
1901
|
+
finish_reason: finishReason.value,
|
|
1902
|
+
error_category: errorCategory.value
|
|
1903
|
+
});
|
|
1904
|
+
}
|
|
1905
|
+
function validatePersonalApplicationCallPage(value, options) {
|
|
1906
|
+
return withResponseOptions(value, options, () => {
|
|
1907
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
1908
|
+
if (!Array.isArray(value.calls)) return invalidValue3("calls", "must be an array");
|
|
1909
|
+
const calls = [];
|
|
1910
|
+
for (const [index, item] of value.calls.entries()) {
|
|
1911
|
+
const result = validatePersonalApplicationCall(item, `calls[${index}]`);
|
|
1912
|
+
if (!result.ok) return result;
|
|
1913
|
+
calls.push(result.value);
|
|
1914
|
+
}
|
|
1915
|
+
const page = expectInteger(value.page, "page");
|
|
1916
|
+
if (!page.ok) return page;
|
|
1917
|
+
if (page.value < 1) return invalidValue3("page", "must be a positive integer");
|
|
1918
|
+
const pageCount = expectInteger(value.page_count, "page_count");
|
|
1919
|
+
if (!pageCount.ok) return pageCount;
|
|
1920
|
+
if (pageCount.value < 1) return invalidValue3("page_count", "must be a positive integer");
|
|
1921
|
+
const total = expectNonNegativeInteger(value.total, "total");
|
|
1922
|
+
if (!total.ok) return total;
|
|
1923
|
+
return ok3({ calls, page: page.value, page_count: pageCount.value, total: total.value });
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
1926
|
+
function validatePersonalApplicationCallsQuery(query) {
|
|
1927
|
+
const sort = query.sort === void 0 || query.sort === null ? ok3("time") : expectLiteral(query.sort, PERSONAL_APPLICATION_CALL_SORTS, "sort");
|
|
1928
|
+
if (!sort.ok) return sort;
|
|
1929
|
+
let page = 1;
|
|
1930
|
+
if (query.page !== void 0 && query.page !== null) {
|
|
1931
|
+
if (!/^\d+$/.test(query.page)) return invalidValue3("page", "must be a positive integer");
|
|
1932
|
+
page = Number(query.page);
|
|
1933
|
+
if (!Number.isSafeInteger(page) || page < 1) return invalidValue3("page", "must be a positive integer");
|
|
1934
|
+
}
|
|
1935
|
+
let limit = PERSONAL_APPLICATION_CALLS_DEFAULT_LIMIT;
|
|
1936
|
+
if (query.limit !== void 0 && query.limit !== null) {
|
|
1937
|
+
if (!/^\d+$/.test(query.limit)) return invalidValue3("limit", "must be a positive integer");
|
|
1938
|
+
limit = Number(query.limit);
|
|
1939
|
+
if (limit < 1 || limit > PERSONAL_APPLICATION_CALLS_MAX_LIMIT) {
|
|
1940
|
+
return invalidValue3("limit", `must be between 1 and ${PERSONAL_APPLICATION_CALLS_MAX_LIMIT}`);
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
return ok3({ sort: sort.value, page, limit });
|
|
1944
|
+
}
|
|
1945
|
+
function validatePersonalApplicationUsageDay(value, param) {
|
|
1946
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
1947
|
+
const day = expectCalendarDay(value.day, `${param}.day`);
|
|
1948
|
+
if (!day.ok) return day;
|
|
1949
|
+
const standardRequests = expectNonNegativeInteger(
|
|
1950
|
+
value.standard_requests,
|
|
1951
|
+
`${param}.standard_requests`
|
|
1952
|
+
);
|
|
1953
|
+
if (!standardRequests.ok) return standardRequests;
|
|
1954
|
+
const premiumRequests = expectNonNegativeInteger(
|
|
1955
|
+
value.premium_requests,
|
|
1956
|
+
`${param}.premium_requests`
|
|
1957
|
+
);
|
|
1958
|
+
if (!premiumRequests.ok) return premiumRequests;
|
|
1959
|
+
const standardUnitsUsed = expectCanonicalAmount(
|
|
1960
|
+
value.standard_units_used,
|
|
1961
|
+
`${param}.standard_units_used`
|
|
1962
|
+
);
|
|
1963
|
+
if (!standardUnitsUsed.ok) return standardUnitsUsed;
|
|
1964
|
+
const premiumUnitsUsed = expectCanonicalAmount(
|
|
1965
|
+
value.premium_units_used,
|
|
1966
|
+
`${param}.premium_units_used`
|
|
1967
|
+
);
|
|
1968
|
+
if (!premiumUnitsUsed.ok) return premiumUnitsUsed;
|
|
1969
|
+
return ok3({
|
|
1970
|
+
day: day.value,
|
|
1971
|
+
standard_requests: standardRequests.value,
|
|
1972
|
+
premium_requests: premiumRequests.value,
|
|
1973
|
+
standard_units_used: standardUnitsUsed.value,
|
|
1974
|
+
premium_units_used: premiumUnitsUsed.value
|
|
1975
|
+
});
|
|
1976
|
+
}
|
|
1977
|
+
function validateDashboardRange(value, param) {
|
|
1978
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
1979
|
+
const from = expectRfc33392(value.from, `${param}.from`);
|
|
1980
|
+
if (!from.ok) return from;
|
|
1981
|
+
const to = expectRfc33392(value.to, `${param}.to`);
|
|
1982
|
+
if (!to.ok) return to;
|
|
1983
|
+
const timezone = expectLiteral(value.timezone, ["UTC"], `${param}.timezone`);
|
|
1984
|
+
if (!timezone.ok) return timezone;
|
|
1985
|
+
return ok3({ from: from.value, to: to.value, timezone: timezone.value });
|
|
1986
|
+
}
|
|
1987
|
+
function validatePersonalApplicationUsage(value) {
|
|
1988
|
+
if (!isPlainObject4(value)) return invalidValue3("usage", "must be an object");
|
|
1989
|
+
const range = validateDashboardRange(value.range, "usage.range");
|
|
1990
|
+
if (!range.ok) return range;
|
|
1991
|
+
const dataFreshAt = expectRfc33392(value.data_fresh_at, "usage.data_fresh_at");
|
|
1992
|
+
if (!dataFreshAt.ok) return dataFreshAt;
|
|
1993
|
+
if (!Array.isArray(value.daily)) return invalidValue3("usage.daily", "must be an array");
|
|
1994
|
+
const daily = [];
|
|
1995
|
+
for (const [index, item] of value.daily.entries()) {
|
|
1996
|
+
const result = validatePersonalApplicationUsageDay(item, `usage.daily[${index}]`);
|
|
1997
|
+
if (!result.ok) return result;
|
|
1998
|
+
daily.push(result.value);
|
|
1999
|
+
}
|
|
2000
|
+
return ok3({ range: range.value, data_fresh_at: dataFreshAt.value, daily });
|
|
2001
|
+
}
|
|
2002
|
+
function validateApplicationCostProfile(value, param = "cost_profile", options) {
|
|
2003
|
+
return withResponseOptions(value, options, () => validateApplicationCostProfileShape(value, param));
|
|
2004
|
+
}
|
|
2005
|
+
function validateApplicationCostProfileShape(value, param) {
|
|
2006
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
2007
|
+
const disclosed = expectBoolean(value.disclosed, `${param}.disclosed`);
|
|
2008
|
+
if (!disclosed.ok) return disclosed;
|
|
2009
|
+
const usesPremium = expectBoolean(value.uses_premium, `${param}.uses_premium`);
|
|
2010
|
+
if (!usesPremium.ok) return usesPremium;
|
|
2011
|
+
const median = expectOptionalCanonicalAmount(
|
|
2012
|
+
value.median_premium_units_per_charged_call,
|
|
2013
|
+
`${param}.median_premium_units_per_charged_call`
|
|
2014
|
+
);
|
|
2015
|
+
if (!median.ok) return median;
|
|
2016
|
+
const p90 = expectOptionalCanonicalAmount(
|
|
2017
|
+
value.p90_premium_units_per_charged_call,
|
|
2018
|
+
`${param}.p90_premium_units_per_charged_call`
|
|
2019
|
+
);
|
|
2020
|
+
if (!p90.ok) return p90;
|
|
2021
|
+
const max = expectOptionalCanonicalAmount(
|
|
2022
|
+
value.max_premium_units_per_charged_call,
|
|
2023
|
+
`${param}.max_premium_units_per_charged_call`
|
|
2024
|
+
);
|
|
2025
|
+
if (!max.ok) return max;
|
|
2026
|
+
const estimated = expectOptionalCanonicalAmount(
|
|
2027
|
+
value.estimated_premium_units_per_charged_call,
|
|
2028
|
+
`${param}.estimated_premium_units_per_charged_call`
|
|
2029
|
+
);
|
|
2030
|
+
if (!estimated.ok) return estimated;
|
|
2031
|
+
const windowStart = expectRfc33392(value.window_start, `${param}.window_start`);
|
|
2032
|
+
if (!windowStart.ok) return windowStart;
|
|
2033
|
+
const windowEnd = expectRfc33392(value.window_end, `${param}.window_end`);
|
|
2034
|
+
if (!windowEnd.ok) return windowEnd;
|
|
2035
|
+
const computedAt = expectRfc33392(value.computed_at, `${param}.computed_at`);
|
|
2036
|
+
if (!computedAt.ok) return computedAt;
|
|
2037
|
+
const present = [median.value, p90.value, max.value].filter((figure) => figure !== void 0).length;
|
|
2038
|
+
if (disclosed.value === false && present > 0) {
|
|
2039
|
+
return invalidValue3(param, "the three figures must be absent when disclosed is false");
|
|
2040
|
+
}
|
|
2041
|
+
if (disclosed.value === true && present !== 3) {
|
|
2042
|
+
return invalidValue3(param, "the three figures must all be present when disclosed is true");
|
|
2043
|
+
}
|
|
2044
|
+
if (disclosed.value === true && estimated.value !== void 0) {
|
|
2045
|
+
return invalidValue3(param, "the estimate must be absent when disclosed is true");
|
|
2046
|
+
}
|
|
2047
|
+
return ok3({
|
|
2048
|
+
disclosed: disclosed.value,
|
|
2049
|
+
uses_premium: usesPremium.value,
|
|
2050
|
+
...median.value !== void 0 ? { median_premium_units_per_charged_call: median.value } : {},
|
|
2051
|
+
...p90.value !== void 0 ? { p90_premium_units_per_charged_call: p90.value } : {},
|
|
2052
|
+
...max.value !== void 0 ? { max_premium_units_per_charged_call: max.value } : {},
|
|
2053
|
+
...estimated.value !== void 0 ? { estimated_premium_units_per_charged_call: estimated.value } : {},
|
|
2054
|
+
window_start: windowStart.value,
|
|
2055
|
+
window_end: windowEnd.value,
|
|
2056
|
+
computed_at: computedAt.value
|
|
2057
|
+
});
|
|
2058
|
+
}
|
|
2059
|
+
function validatePersonalApplicationDetail(value, options) {
|
|
2060
|
+
return withResponseOptions(value, options, () => validatePersonalApplicationDetailShape(value));
|
|
2061
|
+
}
|
|
2062
|
+
function validatePersonalApplicationDetailShape(value) {
|
|
2063
|
+
const summary = validatePersonalApplicationSummary(value, "application");
|
|
2064
|
+
if (!summary.ok) return summary;
|
|
2065
|
+
if (!isPlainObject4(value)) return invalidValue3("application", "must be an object");
|
|
2066
|
+
const usage = validatePersonalApplicationUsage(value.usage);
|
|
2067
|
+
if (!usage.ok) return usage;
|
|
2068
|
+
const costProfile = validateApplicationCostProfileShape(value.cost_profile, "cost_profile");
|
|
2069
|
+
if (!costProfile.ok) return costProfile;
|
|
2070
|
+
return ok3({ ...summary.value, usage: usage.value, cost_profile: costProfile.value });
|
|
2071
|
+
}
|
|
2072
|
+
function validatePatchPersonalApplicationLimitRequest(value) {
|
|
2073
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
2074
|
+
const rejected = rejectUnknownKeys(value, ["limits"]);
|
|
2075
|
+
if (!rejected.ok) return rejected;
|
|
2076
|
+
const limits = value.limits;
|
|
2077
|
+
if (!isPlainObject4(limits)) return invalidValue3("limits", "must be an object");
|
|
2078
|
+
const nested = rejectUnknownKeys(limits, ["standard_per_call", "premium_per_call"]);
|
|
2079
|
+
if (!nested.ok) return nested;
|
|
2080
|
+
const standard = limits.standard_per_call === void 0 ? ok3(void 0) : expectNonNegativeCanonicalAmount(limits.standard_per_call, "limits.standard_per_call");
|
|
2081
|
+
if (!standard.ok) return standard;
|
|
2082
|
+
const premium = limits.premium_per_call === void 0 ? ok3(void 0) : expectNonNegativeCanonicalAmount(limits.premium_per_call, "limits.premium_per_call");
|
|
2083
|
+
if (!premium.ok) return premium;
|
|
2084
|
+
if (standard.value === void 0 && premium.value === void 0) {
|
|
2085
|
+
return invalidValue3("limits", "must carry standard_per_call, premium_per_call, or both");
|
|
2086
|
+
}
|
|
2087
|
+
return ok3({
|
|
2088
|
+
limits: {
|
|
2089
|
+
...standard.value !== void 0 ? { standard_per_call: standard.value } : {},
|
|
2090
|
+
...premium.value !== void 0 ? { premium_per_call: premium.value } : {}
|
|
2091
|
+
}
|
|
2092
|
+
});
|
|
2093
|
+
}
|
|
2094
|
+
var CONTACT_TYPES = ["email", "phone"];
|
|
2095
|
+
function validatePersonalContact(value, options) {
|
|
2096
|
+
return withResponseOptions(value, options, () => validatePersonalContactShape(value));
|
|
2097
|
+
}
|
|
2098
|
+
function validatePersonalContactShape(value) {
|
|
2099
|
+
if (!isPlainObject4(value)) return invalidValue3("contact", "must be an object");
|
|
2100
|
+
const id = expectString(value.id, "contact.id");
|
|
2101
|
+
if (!id.ok) return id;
|
|
2102
|
+
const contactType = expectLiteral(value.contact_type, CONTACT_TYPES, "contact.contact_type");
|
|
2103
|
+
if (!contactType.ok) return contactType;
|
|
2104
|
+
const displayValue = expectString(value.display_value, "contact.display_value");
|
|
2105
|
+
if (!displayValue.ok) return displayValue;
|
|
2106
|
+
const verifiedAt = expectRfc33392(value.verified_at, "contact.verified_at");
|
|
2107
|
+
if (!verifiedAt.ok) return verifiedAt;
|
|
2108
|
+
return ok3({
|
|
2109
|
+
id: id.value,
|
|
2110
|
+
contact_type: contactType.value,
|
|
2111
|
+
display_value: displayValue.value,
|
|
2112
|
+
verified_at: verifiedAt.value
|
|
2113
|
+
});
|
|
2114
|
+
}
|
|
2115
|
+
function validatePersonalContactsList(value, options) {
|
|
2116
|
+
return withResponseOptions(value, options, () => validatePersonalContactsListShape(value));
|
|
2117
|
+
}
|
|
2118
|
+
function validatePersonalContactsListShape(value) {
|
|
2119
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
2120
|
+
if (!Array.isArray(value.contacts)) return invalidValue3("contacts", "must be an array");
|
|
2121
|
+
const contacts = [];
|
|
2122
|
+
for (const item of value.contacts) {
|
|
2123
|
+
const result = validatePersonalContact(item);
|
|
2124
|
+
if (!result.ok) return result;
|
|
2125
|
+
contacts.push(result.value);
|
|
2126
|
+
}
|
|
2127
|
+
return ok3({ contacts });
|
|
2128
|
+
}
|
|
2129
|
+
function readTurnstileToken(value) {
|
|
2130
|
+
return value.turnstile_token;
|
|
2131
|
+
}
|
|
2132
|
+
function validateStartContactVerificationRequest(value) {
|
|
2133
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
2134
|
+
const rejected = rejectUnknownKeys(value, ["contact_type", "value", "turnstile_token"]);
|
|
2135
|
+
if (!rejected.ok) return rejected;
|
|
2136
|
+
const contactType = expectLiteral(value.contact_type, CONTACT_TYPES, "contact_type");
|
|
2137
|
+
if (!contactType.ok) return contactType;
|
|
2138
|
+
const rawValue = expectString(value.value, "value");
|
|
2139
|
+
if (!rawValue.ok) return rawValue;
|
|
2140
|
+
return ok3({
|
|
2141
|
+
contact_type: contactType.value,
|
|
2142
|
+
value: rawValue.value,
|
|
2143
|
+
turnstile_token: readTurnstileToken(value)
|
|
2144
|
+
});
|
|
2145
|
+
}
|
|
2146
|
+
function validateContactChallenge(value, options) {
|
|
2147
|
+
return withResponseOptions(value, options, () => validateContactChallengeShape(value));
|
|
2148
|
+
}
|
|
2149
|
+
function validateContactChallengeShape(value) {
|
|
2150
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
2151
|
+
const challengeId = expectString(value.challenge_id, "challenge_id");
|
|
2152
|
+
if (!challengeId.ok) return challengeId;
|
|
2153
|
+
const contactType = expectLiteral(value.contact_type, CONTACT_TYPES, "contact_type");
|
|
2154
|
+
if (!contactType.ok) return contactType;
|
|
2155
|
+
const expiresAt = expectRfc33392(value.expires_at, "expires_at");
|
|
2156
|
+
if (!expiresAt.ok) return expiresAt;
|
|
2157
|
+
return ok3({
|
|
2158
|
+
challenge_id: challengeId.value,
|
|
2159
|
+
contact_type: contactType.value,
|
|
2160
|
+
expires_at: expiresAt.value
|
|
2161
|
+
});
|
|
2162
|
+
}
|
|
2163
|
+
function validateVerifyContactRequest(value) {
|
|
2164
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
2165
|
+
const rejected = rejectUnknownKeys(value, ["challenge_id", "code"]);
|
|
2166
|
+
if (!rejected.ok) return rejected;
|
|
2167
|
+
const challengeId = expectString(value.challenge_id, "challenge_id");
|
|
2168
|
+
if (!challengeId.ok) return challengeId;
|
|
2169
|
+
const code = expectString(value.code, "code");
|
|
2170
|
+
if (!code.ok) return code;
|
|
2171
|
+
return ok3({ challenge_id: challengeId.value, code: code.value });
|
|
2172
|
+
}
|
|
2173
|
+
function validateConsentApplication(value) {
|
|
2174
|
+
if (!isPlainObject4(value)) return invalidValue3("application", "must be an object");
|
|
2175
|
+
const id = expectString(value.id, "application.id");
|
|
2176
|
+
if (!id.ok) return id;
|
|
2177
|
+
const name = expectString(value.name, "application.name");
|
|
2178
|
+
if (!name.ok) return name;
|
|
2179
|
+
const iconUrl = expectOptionalString(value.icon_url, "application.icon_url");
|
|
2180
|
+
if (!iconUrl.ok) return iconUrl;
|
|
2181
|
+
const description = expectOptionalString(value.description, "application.description");
|
|
2182
|
+
if (!description.ok) return description;
|
|
2183
|
+
const businessDisplayName = expectString(
|
|
2184
|
+
value.business_display_name,
|
|
2185
|
+
"application.business_display_name"
|
|
2186
|
+
);
|
|
2187
|
+
if (!businessDisplayName.ok) return businessDisplayName;
|
|
2188
|
+
const environment = expectLiteral(
|
|
2189
|
+
value.environment,
|
|
2190
|
+
APPLICATION_ENVIRONMENTS,
|
|
2191
|
+
"application.environment"
|
|
2192
|
+
);
|
|
2193
|
+
if (!environment.ok) return environment;
|
|
2194
|
+
return ok3({
|
|
2195
|
+
id: id.value,
|
|
2196
|
+
name: name.value,
|
|
2197
|
+
...iconUrl.value !== void 0 ? { icon_url: iconUrl.value } : {},
|
|
2198
|
+
...description.value !== void 0 ? { description: description.value } : {},
|
|
2199
|
+
business_display_name: businessDisplayName.value,
|
|
2200
|
+
environment: environment.value
|
|
2201
|
+
});
|
|
2202
|
+
}
|
|
2203
|
+
function validateConsentInfo(value, options) {
|
|
2204
|
+
return withResponseOptions(value, options, () => validateConsentInfoShape(value));
|
|
2205
|
+
}
|
|
2206
|
+
function validateConsentInfoShape(value) {
|
|
2207
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
2208
|
+
const application = validateConsentApplication(value.application);
|
|
2209
|
+
if (!application.ok) return application;
|
|
2210
|
+
const costProfile = validateApplicationCostProfile(value.cost_profile);
|
|
2211
|
+
if (!costProfile.ok) return costProfile;
|
|
2212
|
+
const prefill = validateApplicationLimitsShape(value.prefill_limits, "prefill_limits");
|
|
2213
|
+
if (!prefill.ok) return prefill;
|
|
2214
|
+
const existing = value.existing_limits === void 0 ? ok3(void 0) : validateApplicationLimitsShape(value.existing_limits, "existing_limits");
|
|
2215
|
+
if (!existing.ok) return existing;
|
|
2216
|
+
const isReauthorization = expectBoolean(value.is_reauthorization, "is_reauthorization");
|
|
2217
|
+
if (!isReauthorization.ok) return isReauthorization;
|
|
2218
|
+
return ok3({
|
|
2219
|
+
application: application.value,
|
|
2220
|
+
cost_profile: costProfile.value,
|
|
2221
|
+
prefill_limits: prefill.value,
|
|
2222
|
+
...existing.value !== void 0 ? { existing_limits: existing.value } : {},
|
|
2223
|
+
is_reauthorization: isReauthorization.value
|
|
2224
|
+
});
|
|
2225
|
+
}
|
|
2226
|
+
function validateConsentCompletionRequest(value) {
|
|
2227
|
+
return validateConsentLimitsBody(value);
|
|
2228
|
+
}
|
|
2229
|
+
function validateConsentCompletion(value, options) {
|
|
2230
|
+
return withResponseOptions(value, options, () => validateConsentCompletionShape(value));
|
|
2231
|
+
}
|
|
2232
|
+
function validateConsentCompletionShape(value) {
|
|
2233
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
2234
|
+
const resumeUrl = expectString(value.resume_url, "resume_url");
|
|
2235
|
+
if (!resumeUrl.ok) return resumeUrl;
|
|
2236
|
+
return ok3({ resume_url: resumeUrl.value });
|
|
2237
|
+
}
|
|
2238
|
+
function validateConsentDenial(value, options) {
|
|
2239
|
+
return withResponseOptions(value, options, () => validateConsentDenialShape(value));
|
|
2240
|
+
}
|
|
2241
|
+
function validateConsentDenialShape(value) {
|
|
2242
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
2243
|
+
const redirectUrl = expectNullableString(value.redirect_url, "redirect_url");
|
|
2244
|
+
if (!redirectUrl.ok) return redirectUrl;
|
|
2245
|
+
return ok3({ redirect_url: redirectUrl.value });
|
|
2246
|
+
}
|
|
2247
|
+
function validatePlanCatalogLimits(value, param) {
|
|
2248
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
2249
|
+
const rejected = rejectUnknownResponseKeys(value, ["requests_per_minute", "default_max_output_tokens"]);
|
|
2250
|
+
if (!rejected.ok) return rejected;
|
|
2251
|
+
const requestsPerMinute = expectInteger(
|
|
2252
|
+
value.requests_per_minute,
|
|
2253
|
+
`${param}.requests_per_minute`
|
|
2254
|
+
);
|
|
2255
|
+
if (!requestsPerMinute.ok) return requestsPerMinute;
|
|
2256
|
+
if (requestsPerMinute.value <= 0) {
|
|
2257
|
+
return invalidValue3(`${param}.requests_per_minute`, "must be a positive integer");
|
|
2258
|
+
}
|
|
2259
|
+
const defaultMaxOutputTokens = expectInteger(
|
|
2260
|
+
value.default_max_output_tokens,
|
|
2261
|
+
`${param}.default_max_output_tokens`
|
|
2262
|
+
);
|
|
2263
|
+
if (!defaultMaxOutputTokens.ok) return defaultMaxOutputTokens;
|
|
2264
|
+
if (defaultMaxOutputTokens.value <= 0) {
|
|
2265
|
+
return invalidValue3(`${param}.default_max_output_tokens`, "must be a positive integer");
|
|
2266
|
+
}
|
|
2267
|
+
return ok3({
|
|
2268
|
+
requests_per_minute: requestsPerMinute.value,
|
|
2269
|
+
default_max_output_tokens: defaultMaxOutputTokens.value
|
|
2270
|
+
});
|
|
2271
|
+
}
|
|
2272
|
+
function validateSubscriptionPlanEntry(value, param) {
|
|
2273
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
2274
|
+
const id = expectString(value.id, `${param}.id`);
|
|
2275
|
+
if (!id.ok) return id;
|
|
2276
|
+
const displayName = expectString(value.display_name, `${param}.display_name`);
|
|
2277
|
+
if (!displayName.ok) return displayName;
|
|
2278
|
+
const includedPremium = expectCanonicalAmount(
|
|
2279
|
+
value.included_premium_credit_units,
|
|
2280
|
+
`${param}.included_premium_credit_units`
|
|
2281
|
+
);
|
|
2282
|
+
if (!includedPremium.ok) return includedPremium;
|
|
2283
|
+
if (!("included_standard_credit_units" in value)) {
|
|
2284
|
+
return invalidValue3(
|
|
2285
|
+
`${param}.included_standard_credit_units`,
|
|
2286
|
+
"must be present, as a string or null"
|
|
2287
|
+
);
|
|
2288
|
+
}
|
|
2289
|
+
const includedStandard = expectNullableCanonicalAmount(
|
|
2290
|
+
value.included_standard_credit_units,
|
|
2291
|
+
`${param}.included_standard_credit_units`
|
|
2292
|
+
);
|
|
2293
|
+
if (!includedStandard.ok) return includedStandard;
|
|
2294
|
+
const priceMinorUnits = expectCanonicalAmount(
|
|
2295
|
+
value.price_minor_units,
|
|
2296
|
+
`${param}.price_minor_units`
|
|
2297
|
+
);
|
|
2298
|
+
if (!priceMinorUnits.ok) return priceMinorUnits;
|
|
2299
|
+
const currency = expectString(value.currency, `${param}.currency`);
|
|
2300
|
+
if (!currency.ok) return currency;
|
|
2301
|
+
const interval = expectLiteral(value.interval, PLAN_INTERVALS, `${param}.interval`);
|
|
2302
|
+
if (!interval.ok) return interval;
|
|
2303
|
+
const isFree = expectBoolean(value.is_free, `${param}.is_free`);
|
|
2304
|
+
if (!isFree.ok) return isFree;
|
|
2305
|
+
const limits = validatePlanCatalogLimits(value.limits, `${param}.limits`);
|
|
2306
|
+
if (!limits.ok) return limits;
|
|
2307
|
+
const catalogVersion = expectString(value.catalog_version, `${param}.catalog_version`);
|
|
2308
|
+
if (!catalogVersion.ok) return catalogVersion;
|
|
2309
|
+
return ok3({
|
|
2310
|
+
id: id.value,
|
|
2311
|
+
display_name: displayName.value,
|
|
2312
|
+
included_premium_credit_units: includedPremium.value,
|
|
2313
|
+
included_standard_credit_units: includedStandard.value,
|
|
2314
|
+
price_minor_units: priceMinorUnits.value,
|
|
2315
|
+
currency: currency.value,
|
|
2316
|
+
interval: interval.value,
|
|
2317
|
+
is_free: isFree.value,
|
|
2318
|
+
limits: limits.value,
|
|
2319
|
+
catalog_version: catalogVersion.value
|
|
2320
|
+
});
|
|
2321
|
+
}
|
|
2322
|
+
function validateCreditBundleEntry(value, param) {
|
|
2323
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
2324
|
+
const id = expectString(value.id, `${param}.id`);
|
|
2325
|
+
if (!id.ok) return id;
|
|
2326
|
+
const displayName = expectString(value.display_name, `${param}.display_name`);
|
|
2327
|
+
if (!displayName.ok) return displayName;
|
|
2328
|
+
const premium = expectCanonicalAmount(
|
|
2329
|
+
value.premium_credit_units,
|
|
2330
|
+
`${param}.premium_credit_units`
|
|
2331
|
+
);
|
|
2332
|
+
if (!premium.ok) return premium;
|
|
2333
|
+
const standard = expectCanonicalAmount(
|
|
2334
|
+
value.standard_credit_units,
|
|
2335
|
+
`${param}.standard_credit_units`
|
|
2336
|
+
);
|
|
2337
|
+
if (!standard.ok) return standard;
|
|
2338
|
+
const price = expectCanonicalAmount(value.price_minor_units, `${param}.price_minor_units`);
|
|
2339
|
+
if (!price.ok) return price;
|
|
2340
|
+
const currency = expectString(value.currency, `${param}.currency`);
|
|
2341
|
+
if (!currency.ok) return currency;
|
|
2342
|
+
const version = expectString(value.catalog_version, `${param}.catalog_version`);
|
|
2343
|
+
if (!version.ok) return version;
|
|
2344
|
+
return {
|
|
2345
|
+
ok: true,
|
|
2346
|
+
value: {
|
|
2347
|
+
id: id.value,
|
|
2348
|
+
display_name: displayName.value,
|
|
2349
|
+
premium_credit_units: premium.value,
|
|
2350
|
+
standard_credit_units: standard.value,
|
|
2351
|
+
price_minor_units: price.value,
|
|
2352
|
+
currency: currency.value,
|
|
2353
|
+
catalog_version: version.value
|
|
2354
|
+
}
|
|
2355
|
+
};
|
|
2356
|
+
}
|
|
2357
|
+
function validateSubscriptionPlanCatalog(value, options) {
|
|
2358
|
+
return withResponseOptions(value, options, () => validateSubscriptionPlanCatalogShape(value));
|
|
2359
|
+
}
|
|
2360
|
+
function validateSubscriptionPlanCatalogShape(value) {
|
|
2361
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
2362
|
+
const catalogVersion = expectString(value.catalog_version, "catalog_version");
|
|
2363
|
+
if (!catalogVersion.ok) return catalogVersion;
|
|
2364
|
+
if (!Array.isArray(value.plans)) return invalidValue3("plans", "must be an array");
|
|
2365
|
+
if (!Array.isArray(value.bundles)) return invalidValue3("bundles", "must be an array");
|
|
2366
|
+
const plans = [];
|
|
2367
|
+
let freeCount = 0;
|
|
2368
|
+
for (const [index, item] of value.plans.entries()) {
|
|
2369
|
+
const result = validateSubscriptionPlanEntry(item, `plans[${index}]`);
|
|
2370
|
+
if (!result.ok) return result;
|
|
2371
|
+
if (result.value.is_free) freeCount += 1;
|
|
2372
|
+
plans.push(result.value);
|
|
2373
|
+
}
|
|
2374
|
+
if (freeCount !== 1) return invalidValue3("plans", "exactly one entry must have is_free: true");
|
|
2375
|
+
const bundles = [];
|
|
2376
|
+
for (const [index, item] of value.bundles.entries()) {
|
|
2377
|
+
const result = validateCreditBundleEntry(item, `bundles[${index}]`);
|
|
2378
|
+
if (!result.ok) return result;
|
|
2379
|
+
bundles.push(result.value);
|
|
2380
|
+
}
|
|
2381
|
+
return ok3({ catalog_version: catalogVersion.value, plans, bundles });
|
|
2382
|
+
}
|
|
2383
|
+
function validateSubscriptionSelectionRequest(value) {
|
|
2384
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
2385
|
+
const rejected = rejectUnknownKeys(value, ["plan_id", "catalog_version"]);
|
|
2386
|
+
if (!rejected.ok) return rejected;
|
|
2387
|
+
const planId = expectString(value.plan_id, "plan_id");
|
|
2388
|
+
if (!planId.ok) return planId;
|
|
2389
|
+
const catalogVersion = expectString(value.catalog_version, "catalog_version");
|
|
2390
|
+
if (!catalogVersion.ok) return catalogVersion;
|
|
2391
|
+
return ok3({ plan_id: planId.value, catalog_version: catalogVersion.value });
|
|
2392
|
+
}
|
|
2393
|
+
var GIFT_CODE_MAX_LENGTH = 64;
|
|
2394
|
+
function validateRedeemGiftCodeRequest(value) {
|
|
2395
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
2396
|
+
const rejected = rejectUnknownKeys(value, ["code"]);
|
|
2397
|
+
if (!rejected.ok) return rejected;
|
|
2398
|
+
const code = expectString(value.code, "code");
|
|
2399
|
+
if (!code.ok) return code;
|
|
2400
|
+
if (code.value.length < 1 || code.value.length > GIFT_CODE_MAX_LENGTH) {
|
|
2401
|
+
return invalidValue3("code", `must be 1 to ${GIFT_CODE_MAX_LENGTH} characters`);
|
|
2402
|
+
}
|
|
2403
|
+
return ok3({ code: code.value });
|
|
2404
|
+
}
|
|
2405
|
+
function validateCreditsCheckoutRequest(value) {
|
|
2406
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
2407
|
+
const rejected = rejectUnknownKeys(value, ["bundle_id", "catalog_version"]);
|
|
2408
|
+
if (!rejected.ok) return rejected;
|
|
2409
|
+
const bundleId = expectString(value.bundle_id, "bundle_id");
|
|
2410
|
+
if (!bundleId.ok) return bundleId;
|
|
2411
|
+
const catalogVersion = expectString(value.catalog_version, "catalog_version");
|
|
2412
|
+
if (!catalogVersion.ok) return catalogVersion;
|
|
2413
|
+
return ok3({ bundle_id: bundleId.value, catalog_version: catalogVersion.value });
|
|
2414
|
+
}
|
|
2415
|
+
function validateDashboardCheckoutResponse(value, options) {
|
|
2416
|
+
return withResponseOptions(value, options, () => validateDashboardCheckoutResponseShape(value));
|
|
2417
|
+
}
|
|
2418
|
+
function validateDashboardCheckoutResponseShape(value) {
|
|
2419
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
2420
|
+
const transactionId = expectString(value.transaction_id, "transaction_id");
|
|
2421
|
+
if (!transactionId.ok) return transactionId;
|
|
2422
|
+
const redirectUrl = expectString(value.redirect_url, "redirect_url");
|
|
2423
|
+
if (!redirectUrl.ok) return redirectUrl;
|
|
2424
|
+
return ok3({ transaction_id: transactionId.value, redirect_url: redirectUrl.value });
|
|
2425
|
+
}
|
|
2426
|
+
function validateCreditsCheckoutResponse(value, options) {
|
|
2427
|
+
return withResponseOptions(value, options, () => validateCreditsCheckoutResponseShape(value));
|
|
2428
|
+
}
|
|
2429
|
+
function validateCreditsCheckoutResponseShape(value) {
|
|
2430
|
+
const shared = validateDashboardCheckoutResponseShape(value);
|
|
2431
|
+
if (!shared.ok) return shared;
|
|
2432
|
+
const orderId = expectString(value.order_id, "order_id");
|
|
2433
|
+
if (!orderId.ok) return orderId;
|
|
2434
|
+
return ok3({ ...shared.value, order_id: orderId.value });
|
|
2435
|
+
}
|
|
2436
|
+
var ORDER_KINDS = ["subscription", "bundle"];
|
|
2437
|
+
var ORDER_STATUSES = [
|
|
2438
|
+
"pending",
|
|
2439
|
+
"active",
|
|
2440
|
+
"refund_pending",
|
|
2441
|
+
"refunded",
|
|
2442
|
+
"failed",
|
|
2443
|
+
"expired"
|
|
2444
|
+
];
|
|
2445
|
+
var REFUND_ELIGIBILITY = ["full", "half", "none"];
|
|
2446
|
+
var REFUND_REASONS = [
|
|
2447
|
+
"unused",
|
|
2448
|
+
"within_usage_threshold",
|
|
2449
|
+
"usage_threshold_exceeded",
|
|
2450
|
+
"window_expired",
|
|
2451
|
+
"not_active",
|
|
2452
|
+
"gift"
|
|
2453
|
+
];
|
|
2454
|
+
function validateDashboardRefundQuote(value, param) {
|
|
2455
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
2456
|
+
const eligibility = expectLiteral(value.eligibility, REFUND_ELIGIBILITY, `${param}.eligibility`);
|
|
2457
|
+
if (!eligibility.ok) return eligibility;
|
|
2458
|
+
const amount2 = expectCanonicalAmount(value.refund_minor_units, `${param}.refund_minor_units`);
|
|
2459
|
+
if (!amount2.ok) return amount2;
|
|
2460
|
+
const currency = expectString(value.currency, `${param}.currency`);
|
|
2461
|
+
if (!currency.ok) return currency;
|
|
2462
|
+
const reason = expectLiteral(value.reason, REFUND_REASONS, `${param}.reason`);
|
|
2463
|
+
if (!reason.ok) return reason;
|
|
2464
|
+
return ok3({
|
|
2465
|
+
eligibility: eligibility.value,
|
|
2466
|
+
refund_minor_units: amount2.value,
|
|
2467
|
+
currency: currency.value,
|
|
2468
|
+
reason: reason.value
|
|
2469
|
+
});
|
|
2470
|
+
}
|
|
2471
|
+
function validateDashboardPurchaseOrderSummary(value, param = "body", options) {
|
|
2472
|
+
return withResponseOptions(value, options, () => validateDashboardPurchaseOrderSummaryShape(value, param));
|
|
2473
|
+
}
|
|
2474
|
+
function validateDashboardPurchaseOrderSummaryShape(value, param) {
|
|
2475
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
2476
|
+
const id = expectString(value.id, `${param}.id`);
|
|
2477
|
+
if (!id.ok) return id;
|
|
2478
|
+
const kind = expectLiteral(value.kind, ORDER_KINDS, `${param}.kind`);
|
|
2479
|
+
if (!kind.ok) return kind;
|
|
2480
|
+
const productId = expectString(value.product_id, `${param}.product_id`);
|
|
2481
|
+
if (!productId.ok) return productId;
|
|
2482
|
+
const productVersion = expectString(
|
|
2483
|
+
value.product_catalog_version,
|
|
2484
|
+
`${param}.product_catalog_version`
|
|
2485
|
+
);
|
|
2486
|
+
if (!productVersion.ok) return productVersion;
|
|
2487
|
+
const displayName = expectString(value.product_display_name, `${param}.product_display_name`);
|
|
2488
|
+
if (!displayName.ok) return displayName;
|
|
2489
|
+
const status = expectLiteral(value.status, ORDER_STATUSES, `${param}.status`);
|
|
2490
|
+
if (!status.ok) return status;
|
|
2491
|
+
const paid = expectCanonicalAmount(value.paid_minor_units, `${param}.paid_minor_units`);
|
|
2492
|
+
if (!paid.ok) return paid;
|
|
2493
|
+
const currency = expectString(value.currency, `${param}.currency`);
|
|
2494
|
+
if (!currency.ok) return currency;
|
|
2495
|
+
const purchasedAt = expectNullableRfc3339(value.purchased_at, `${param}.purchased_at`);
|
|
2496
|
+
if (!purchasedAt.ok) return purchasedAt;
|
|
2497
|
+
const until = expectRfc33392(value.refundable_until, `${param}.refundable_until`);
|
|
2498
|
+
if (!until.ok) return until;
|
|
2499
|
+
const refund = validateDashboardRefundQuote(value.refund, `${param}.refund`);
|
|
2500
|
+
if (!refund.ok) return refund;
|
|
2501
|
+
return ok3({
|
|
2502
|
+
id: id.value,
|
|
2503
|
+
kind: kind.value,
|
|
2504
|
+
product_id: productId.value,
|
|
2505
|
+
product_catalog_version: productVersion.value,
|
|
2506
|
+
product_display_name: displayName.value,
|
|
2507
|
+
status: status.value,
|
|
2508
|
+
paid_minor_units: paid.value,
|
|
2509
|
+
currency: currency.value,
|
|
2510
|
+
purchased_at: purchasedAt.value,
|
|
2511
|
+
refundable_until: until.value,
|
|
2512
|
+
refund: refund.value
|
|
2513
|
+
});
|
|
2514
|
+
}
|
|
2515
|
+
function validateDashboardPurchaseOrderPage(value, options) {
|
|
2516
|
+
return withResponseOptions(value, options, () => validateDashboardPurchaseOrderPageShape(value));
|
|
2517
|
+
}
|
|
2518
|
+
function validateDashboardPurchaseOrderPageShape(value) {
|
|
2519
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
2520
|
+
if (!Array.isArray(value.orders)) return invalidValue3("orders", "must be an array");
|
|
2521
|
+
const orders = [];
|
|
2522
|
+
for (const [index, candidate] of value.orders.entries()) {
|
|
2523
|
+
const order = validateDashboardPurchaseOrderSummaryShape(candidate, `orders[${index}]`);
|
|
2524
|
+
if (!order.ok) return order;
|
|
2525
|
+
orders.push(order.value);
|
|
2526
|
+
}
|
|
2527
|
+
const cursor = expectNullableString(value.next_cursor, "next_cursor");
|
|
2528
|
+
if (!cursor.ok) return cursor;
|
|
2529
|
+
return ok3({ orders, next_cursor: cursor.value });
|
|
2530
|
+
}
|
|
2531
|
+
function validatePersonalPeriodPage(value, options) {
|
|
2532
|
+
return withResponseOptions(value, options, () => validatePersonalPeriodPageShape(value));
|
|
2533
|
+
}
|
|
2534
|
+
function validatePersonalPeriodPageShape(value) {
|
|
2535
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
2536
|
+
if (!Array.isArray(value.periods)) return invalidValue3("periods", "must be an array");
|
|
2537
|
+
const periods = [];
|
|
2538
|
+
for (const [index, candidate] of value.periods.entries()) {
|
|
2539
|
+
const param = `periods[${index}]`;
|
|
2540
|
+
if (!isPlainObject4(candidate)) return invalidValue3(param, "must be an object");
|
|
2541
|
+
const start = expectRfc33392(candidate.period_start, `${param}.period_start`);
|
|
2542
|
+
if (!start.ok) return start;
|
|
2543
|
+
const end = expectRfc33392(candidate.period_end, `${param}.period_end`);
|
|
2544
|
+
if (!end.ok) return end;
|
|
2545
|
+
const plan = validateSubscriptionPlanSummaryShape(candidate.plan, `${param}.plan`);
|
|
2546
|
+
if (!plan.ok) return plan;
|
|
2547
|
+
periods.push({ period_start: start.value, period_end: end.value, plan: plan.value });
|
|
2548
|
+
}
|
|
2549
|
+
const cursor = expectNullableString(value.next_cursor, "next_cursor");
|
|
2550
|
+
if (!cursor.ok) return cursor;
|
|
2551
|
+
return ok3({ periods, next_cursor: cursor.value });
|
|
2552
|
+
}
|
|
2553
|
+
var API_KEY_SCOPES = ["model", "reporting"];
|
|
2554
|
+
var API_KEY_SCOPE_LABELS = {
|
|
2555
|
+
model: {
|
|
2556
|
+
label: "App key",
|
|
2557
|
+
description: "Lets one app's server sign users in and make AI calls for them. Tied to one app and one environment."
|
|
2558
|
+
},
|
|
2559
|
+
reporting: {
|
|
2560
|
+
label: "Read-only key",
|
|
2561
|
+
description: "Reads your business stats and earnings for scripts and automation. Can't make AI calls or change anything."
|
|
2562
|
+
}
|
|
2563
|
+
};
|
|
2564
|
+
var UNKNOWN_API_KEY_SCOPE_LABEL = "Key";
|
|
2565
|
+
var API_KEY_STATUSES = ["active", "revoked", "expired"];
|
|
2566
|
+
function validateApiKeyMetadata(value, param = "key", options) {
|
|
2567
|
+
return withResponseOptions(value, options, () => validateApiKeyMetadataShape(value, param));
|
|
2568
|
+
}
|
|
2569
|
+
function validateApiKeyMetadataShape(value, param) {
|
|
2570
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
2571
|
+
if ("secret" in value || "key" in value || "raw_key" in value) {
|
|
2572
|
+
return invalidValue3(param, "must not carry a raw key");
|
|
2573
|
+
}
|
|
2574
|
+
const id = expectString(value.id, `${param}.id`);
|
|
2575
|
+
if (!id.ok) return id;
|
|
2576
|
+
const name = expectString(value.name, `${param}.name`);
|
|
2577
|
+
if (!name.ok) return name;
|
|
2578
|
+
const prefix = expectString(value.prefix, `${param}.prefix`);
|
|
2579
|
+
if (!prefix.ok) return prefix;
|
|
2580
|
+
const scope = expectLiteral(value.scope, API_KEY_SCOPES, `${param}.scope`);
|
|
2581
|
+
if (!scope.ok) return scope;
|
|
2582
|
+
const applicationId = expectNullableString(value.application_id, `${param}.application_id`);
|
|
2583
|
+
if (!applicationId.ok) return applicationId;
|
|
2584
|
+
const environment = expectNullableLiteral(
|
|
2585
|
+
value.environment,
|
|
2586
|
+
APPLICATION_ENVIRONMENTS,
|
|
2587
|
+
`${param}.environment`
|
|
2588
|
+
);
|
|
2589
|
+
if (!environment.ok) return environment;
|
|
2590
|
+
const status = expectLiteral(value.status, API_KEY_STATUSES, `${param}.status`);
|
|
2591
|
+
if (!status.ok) return status;
|
|
2592
|
+
const createdAt = expectRfc33392(value.created_at, `${param}.created_at`);
|
|
2593
|
+
if (!createdAt.ok) return createdAt;
|
|
2594
|
+
const expiresAt = expectNullableRfc3339(value.expires_at, `${param}.expires_at`);
|
|
2595
|
+
if (!expiresAt.ok) return expiresAt;
|
|
2596
|
+
const lastUsedAt = expectNullableRfc3339(value.last_used_at, `${param}.last_used_at`);
|
|
2597
|
+
if (!lastUsedAt.ok) return lastUsedAt;
|
|
2598
|
+
const shouldBeNull = scope.value === "reporting";
|
|
2599
|
+
if (shouldBeNull && (applicationId.value !== null || environment.value !== null)) {
|
|
2600
|
+
return invalidValue3(
|
|
2601
|
+
param,
|
|
2602
|
+
"application_id and environment must be null on a reporting-scope key"
|
|
2603
|
+
);
|
|
2604
|
+
}
|
|
2605
|
+
if (scope.value !== UNKNOWN_ENUM_VALUE && !shouldBeNull && (applicationId.value === null || environment.value === null)) {
|
|
2606
|
+
return invalidValue3(
|
|
2607
|
+
param,
|
|
2608
|
+
"application_id and environment must be non-null on a model-scope key"
|
|
2609
|
+
);
|
|
2610
|
+
}
|
|
2611
|
+
return ok3({
|
|
2612
|
+
id: id.value,
|
|
2613
|
+
name: name.value,
|
|
2614
|
+
prefix: prefix.value,
|
|
2615
|
+
scope: scope.value,
|
|
2616
|
+
application_id: applicationId.value,
|
|
2617
|
+
environment: environment.value,
|
|
2618
|
+
status: status.value,
|
|
2619
|
+
created_at: createdAt.value,
|
|
2620
|
+
expires_at: expiresAt.value,
|
|
2621
|
+
last_used_at: lastUsedAt.value
|
|
2622
|
+
});
|
|
2623
|
+
}
|
|
2624
|
+
function validateApiKeyMetadataArray(value, param) {
|
|
2625
|
+
if (!Array.isArray(value)) return invalidValue3(param, "must be an array");
|
|
2626
|
+
const keys = [];
|
|
2627
|
+
for (const [index, item] of value.entries()) {
|
|
2628
|
+
const result = validateApiKeyMetadata(item, `${param}[${index}]`);
|
|
2629
|
+
if (!result.ok) return result;
|
|
2630
|
+
keys.push(result.value);
|
|
2631
|
+
}
|
|
2632
|
+
return ok3(keys);
|
|
2633
|
+
}
|
|
2634
|
+
function validateApiKeyMetadataList(value, options) {
|
|
2635
|
+
return withResponseOptions(value, options, () => validateApiKeyMetadataArray(value, "body"));
|
|
2636
|
+
}
|
|
2637
|
+
function validateBusinessDailyVisitor(value, param) {
|
|
2638
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
2639
|
+
const date = expectCalendarDay(value.date, `${param}.date`);
|
|
2640
|
+
if (!date.ok) return date;
|
|
2641
|
+
const count = expectNonNegativeInteger(value.count, `${param}.count`);
|
|
2642
|
+
if (!count.ok) return count;
|
|
2643
|
+
return ok3({ date: date.value, count: count.value });
|
|
2644
|
+
}
|
|
2645
|
+
function validateBusinessDailyUsage(value, param) {
|
|
2646
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
2647
|
+
const date = expectCalendarDay(value.date, `${param}.date`);
|
|
2648
|
+
if (!date.ok) return date;
|
|
2649
|
+
const standard = expectNonNegativeInteger(value.standard_requests, `${param}.standard_requests`);
|
|
2650
|
+
if (!standard.ok) return standard;
|
|
2651
|
+
const premium = expectNonNegativeInteger(value.premium_requests, `${param}.premium_requests`);
|
|
2652
|
+
if (!premium.ok) return premium;
|
|
2653
|
+
const earnings = expectCanonicalAmount(
|
|
2654
|
+
value.premium_earnings_nano_usd,
|
|
2655
|
+
`${param}.premium_earnings_nano_usd`
|
|
2656
|
+
);
|
|
2657
|
+
if (!earnings.ok) return earnings;
|
|
2658
|
+
return ok3({
|
|
2659
|
+
date: date.value,
|
|
2660
|
+
standard_requests: standard.value,
|
|
2661
|
+
premium_requests: premium.value,
|
|
2662
|
+
premium_earnings_nano_usd: earnings.value
|
|
2663
|
+
});
|
|
2664
|
+
}
|
|
2665
|
+
function validateBusinessApplicationUsageBucket(value, param) {
|
|
2666
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
2667
|
+
const requests = expectNonNegativeInteger(value.requests, `${param}.requests`);
|
|
2668
|
+
if (!requests.ok) return requests;
|
|
2669
|
+
const usedNanoUsd = expectCanonicalAmount(
|
|
2670
|
+
value.used_nano_usd,
|
|
2671
|
+
`${param}.used_nano_usd`
|
|
2672
|
+
);
|
|
2673
|
+
if (!usedNanoUsd.ok) return usedNanoUsd;
|
|
2674
|
+
return ok3({ requests: requests.value, used_nano_usd: usedNanoUsd.value });
|
|
2675
|
+
}
|
|
2676
|
+
function validateBusinessApplicationPremiumUsageBucket(value, param) {
|
|
2677
|
+
const base = validateBusinessApplicationUsageBucket(value, param);
|
|
2678
|
+
if (!base.ok) return base;
|
|
2679
|
+
const record = value;
|
|
2680
|
+
const earningsNanoUsd = expectCanonicalAmount(
|
|
2681
|
+
record.earnings_nano_usd,
|
|
2682
|
+
`${param}.earnings_nano_usd`
|
|
2683
|
+
);
|
|
2684
|
+
if (!earningsNanoUsd.ok) return earningsNanoUsd;
|
|
2685
|
+
return ok3({ ...base.value, earnings_nano_usd: earningsNanoUsd.value });
|
|
2686
|
+
}
|
|
2687
|
+
function validateBusinessApplicationUsage(value, param) {
|
|
2688
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
2689
|
+
const standard = validateBusinessApplicationUsageBucket(value.standard, `${param}.standard`);
|
|
2690
|
+
if (!standard.ok) return standard;
|
|
2691
|
+
const premium = validateBusinessApplicationPremiumUsageBucket(value.premium, `${param}.premium`);
|
|
2692
|
+
if (!premium.ok) return premium;
|
|
2693
|
+
return ok3({ standard: standard.value, premium: premium.value });
|
|
2694
|
+
}
|
|
2695
|
+
var APPLICATION_STATUSES = ["active", "suspended", "closed"];
|
|
2696
|
+
function validateBusinessApplicationSummary(value, param) {
|
|
2697
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
2698
|
+
const id = expectString(value.id, `${param}.id`);
|
|
2699
|
+
if (!id.ok) return id;
|
|
2700
|
+
const name = expectString(value.name, `${param}.name`);
|
|
2701
|
+
if (!name.ok) return name;
|
|
2702
|
+
const environment = expectLiteral(
|
|
2703
|
+
value.environment,
|
|
2704
|
+
APPLICATION_ENVIRONMENTS,
|
|
2705
|
+
`${param}.environment`
|
|
2706
|
+
);
|
|
2707
|
+
if (!environment.ok) return environment;
|
|
2708
|
+
const status = expectLiteral(value.status, APPLICATION_STATUSES, `${param}.status`);
|
|
2709
|
+
if (!status.ok) return status;
|
|
2710
|
+
const clientId = expectString(value.client_id, `${param}.client_id`);
|
|
2711
|
+
if (!clientId.ok) return clientId;
|
|
2712
|
+
const iconUrl = expectOptionalString(value.icon_url, `${param}.icon_url`);
|
|
2713
|
+
if (!iconUrl.ok) return iconUrl;
|
|
2714
|
+
const createdAt = expectRfc33392(value.created_at, `${param}.created_at`);
|
|
2715
|
+
if (!createdAt.ok) return createdAt;
|
|
2716
|
+
const apiKeys = validateApiKeyMetadataArray(value.api_keys, `${param}.api_keys`);
|
|
2717
|
+
if (!apiKeys.ok) return apiKeys;
|
|
2718
|
+
if (!Array.isArray(value.daily_visitors))
|
|
2719
|
+
return invalidValue3(`${param}.daily_visitors`, "must be an array");
|
|
2720
|
+
const dailyVisitors = [];
|
|
2721
|
+
for (const [index, item] of value.daily_visitors.entries()) {
|
|
2722
|
+
const result = validateBusinessDailyVisitor(item, `${param}.daily_visitors[${index}]`);
|
|
2723
|
+
if (!result.ok) return result;
|
|
2724
|
+
dailyVisitors.push(result.value);
|
|
2725
|
+
}
|
|
2726
|
+
const visitors = expectNonNegativeInteger(value.visitors, `${param}.visitors`);
|
|
2727
|
+
if (!visitors.ok) return visitors;
|
|
2728
|
+
const usage = validateBusinessApplicationUsage(value.usage, `${param}.usage`);
|
|
2729
|
+
if (!usage.ok) return usage;
|
|
2730
|
+
return ok3({
|
|
2731
|
+
id: id.value,
|
|
2732
|
+
name: name.value,
|
|
2733
|
+
environment: environment.value,
|
|
2734
|
+
status: status.value,
|
|
2735
|
+
client_id: clientId.value,
|
|
2736
|
+
...iconUrl.value !== void 0 ? { icon_url: iconUrl.value } : {},
|
|
2737
|
+
created_at: createdAt.value,
|
|
2738
|
+
api_keys: apiKeys.value,
|
|
2739
|
+
daily_visitors: dailyVisitors,
|
|
2740
|
+
visitors: visitors.value,
|
|
2741
|
+
usage: usage.value
|
|
2742
|
+
});
|
|
2743
|
+
}
|
|
2744
|
+
function validateBusinessDashboardBusiness(value) {
|
|
2745
|
+
if (!isPlainObject4(value)) return invalidValue3("business", "must be an object");
|
|
2746
|
+
const id = expectString(value.id, "business.id");
|
|
2747
|
+
if (!id.ok) return id;
|
|
2748
|
+
const name = expectString(value.name, "business.name");
|
|
2749
|
+
if (!name.ok) return name;
|
|
2750
|
+
const email = expectOptionalString(value.email, "business.email");
|
|
2751
|
+
if (!email.ok) return email;
|
|
2752
|
+
return ok3({
|
|
2753
|
+
id: id.value,
|
|
2754
|
+
name: name.value,
|
|
2755
|
+
...email.value !== void 0 ? { email: email.value } : {}
|
|
2756
|
+
});
|
|
2757
|
+
}
|
|
2758
|
+
function validateBusinessEarnings(value) {
|
|
2759
|
+
if (!isPlainObject4(value)) return invalidValue3("earnings", "must be an object");
|
|
2760
|
+
const rejected = rejectUnknownResponseKeys(value, [
|
|
2761
|
+
"earnings_nano_usd",
|
|
2762
|
+
"payout_pending_nano_usd",
|
|
2763
|
+
"display_currency"
|
|
2764
|
+
]);
|
|
2765
|
+
if (!rejected.ok) return rejected;
|
|
2766
|
+
const earningsNanoUsd = expectCanonicalAmount(
|
|
2767
|
+
value.earnings_nano_usd,
|
|
2768
|
+
"earnings.earnings_nano_usd"
|
|
2769
|
+
);
|
|
2770
|
+
if (!earningsNanoUsd.ok) return earningsNanoUsd;
|
|
2771
|
+
const payoutPendingNanoUsd = expectCanonicalAmount(
|
|
2772
|
+
value.payout_pending_nano_usd,
|
|
2773
|
+
"earnings.payout_pending_nano_usd"
|
|
2774
|
+
);
|
|
2775
|
+
if (!payoutPendingNanoUsd.ok) return payoutPendingNanoUsd;
|
|
2776
|
+
const displayCurrency = expectLiteral(value.display_currency, ["USD"], "earnings.display_currency");
|
|
2777
|
+
if (!displayCurrency.ok) return displayCurrency;
|
|
2778
|
+
return ok3({
|
|
2779
|
+
earnings_nano_usd: earningsNanoUsd.value,
|
|
2780
|
+
payout_pending_nano_usd: payoutPendingNanoUsd.value,
|
|
2781
|
+
display_currency: displayCurrency.value
|
|
2782
|
+
});
|
|
2783
|
+
}
|
|
2784
|
+
var CONNECTED_ACCOUNT_STATUSES = [
|
|
2785
|
+
"none",
|
|
2786
|
+
"onboarding",
|
|
2787
|
+
"restricted",
|
|
2788
|
+
"enabled",
|
|
2789
|
+
"rejected"
|
|
2790
|
+
];
|
|
2791
|
+
var PAYOUT_BLOCKED_REASONS = [
|
|
2792
|
+
"payout_blocked",
|
|
2793
|
+
"below_minimum",
|
|
2794
|
+
"outstanding_deficit",
|
|
2795
|
+
"tax_details_required",
|
|
2796
|
+
"payout_account_incomplete",
|
|
2797
|
+
"monthly_payout_taken",
|
|
2798
|
+
"payout_pending"
|
|
2799
|
+
];
|
|
2800
|
+
var BUSINESS_PERMISSIONS = [
|
|
2801
|
+
"stats.view",
|
|
2802
|
+
"apps.manage",
|
|
2803
|
+
"keys.manage",
|
|
2804
|
+
"payouts.manage",
|
|
2805
|
+
"payout_billing.manage",
|
|
2806
|
+
"members.manage",
|
|
2807
|
+
"ownership.transfer"
|
|
2808
|
+
];
|
|
2809
|
+
var BUSINESS_ROLE_NAMES = ["owner", "admin", "developer", "viewer"];
|
|
2810
|
+
function validateBusinessPermission(value, param = "permission", options) {
|
|
2811
|
+
return withResponseOptions(value, options, () => expectLiteral(value, BUSINESS_PERMISSIONS, param));
|
|
2812
|
+
}
|
|
2813
|
+
function validateBusinessRole(value, param = "role", options) {
|
|
2814
|
+
return withResponseOptions(value, options, () => expectLiteral(value, BUSINESS_ROLE_NAMES, param));
|
|
2815
|
+
}
|
|
2816
|
+
function validateBusinessPayoutInfo(value) {
|
|
2817
|
+
if (!isPlainObject4(value)) return invalidValue3("payout", "must be an object");
|
|
2818
|
+
const eligible = expectBoolean(value.eligible, "payout.eligible");
|
|
2819
|
+
if (!eligible.ok) return eligible;
|
|
2820
|
+
const connectedAccountStatus = expectLiteral(
|
|
2821
|
+
value.connected_account_status,
|
|
2822
|
+
CONNECTED_ACCOUNT_STATUSES,
|
|
2823
|
+
"payout.connected_account_status"
|
|
2824
|
+
);
|
|
2825
|
+
if (!connectedAccountStatus.ok) return connectedAccountStatus;
|
|
2826
|
+
const policyCodeVersion = expectString(value.policy_code_version, "payout.policy_code_version");
|
|
2827
|
+
if (!policyCodeVersion.ok) return policyCodeVersion;
|
|
2828
|
+
const minimumAvailable = expectCanonicalAmount(
|
|
2829
|
+
value.minimum_available_nano_usd,
|
|
2830
|
+
"payout.minimum_available_nano_usd"
|
|
2831
|
+
);
|
|
2832
|
+
if (!minimumAvailable.ok) return minimumAvailable;
|
|
2833
|
+
const nextEligibleAt = expectNullableRfc3339(value.next_eligible_at, "payout.next_eligible_at");
|
|
2834
|
+
if (!nextEligibleAt.ok) return nextEligibleAt;
|
|
2835
|
+
const blockedReason = value.blocked_reason === void 0 ? ok3(void 0) : expectLiteral(value.blocked_reason, PAYOUT_BLOCKED_REASONS, "payout.blocked_reason");
|
|
2836
|
+
if (!blockedReason.ok) return blockedReason;
|
|
2837
|
+
if (eligible.value && blockedReason.value !== void 0) {
|
|
2838
|
+
return invalidValue3("payout.blocked_reason", "must be absent when eligible is true");
|
|
2839
|
+
}
|
|
2840
|
+
if (!eligible.value && blockedReason.value === void 0) {
|
|
2841
|
+
return invalidValue3("payout.blocked_reason", "must be present when eligible is false");
|
|
2842
|
+
}
|
|
2843
|
+
return ok3({
|
|
2844
|
+
eligible: eligible.value,
|
|
2845
|
+
connected_account_status: connectedAccountStatus.value,
|
|
2846
|
+
policy_code_version: policyCodeVersion.value,
|
|
2847
|
+
minimum_available_nano_usd: minimumAvailable.value,
|
|
2848
|
+
next_eligible_at: nextEligibleAt.value,
|
|
2849
|
+
...blockedReason.value !== void 0 ? { blocked_reason: blockedReason.value } : {}
|
|
2850
|
+
});
|
|
2851
|
+
}
|
|
2852
|
+
function validateBusinessTraffic(value, param) {
|
|
2853
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
2854
|
+
if (!Array.isArray(value.daily_visitors))
|
|
2855
|
+
return invalidValue3(`${param}.daily_visitors`, "must be an array");
|
|
2856
|
+
const dailyVisitors = [];
|
|
2857
|
+
for (const [index, item] of value.daily_visitors.entries()) {
|
|
2858
|
+
const result = validateBusinessDailyVisitor(item, `${param}.daily_visitors[${index}]`);
|
|
2859
|
+
if (!result.ok) return result;
|
|
2860
|
+
dailyVisitors.push(result.value);
|
|
2861
|
+
}
|
|
2862
|
+
if (!Array.isArray(value.daily_usage))
|
|
2863
|
+
return invalidValue3(`${param}.daily_usage`, "must be an array");
|
|
2864
|
+
const dailyUsage = [];
|
|
2865
|
+
for (const [index, item] of value.daily_usage.entries()) {
|
|
2866
|
+
const result = validateBusinessDailyUsage(item, `${param}.daily_usage[${index}]`);
|
|
2867
|
+
if (!result.ok) return result;
|
|
2868
|
+
dailyUsage.push(result.value);
|
|
2869
|
+
}
|
|
2870
|
+
const usage = validateBusinessApplicationUsage(value.usage, `${param}.usage`);
|
|
2871
|
+
if (!usage.ok) return usage;
|
|
2872
|
+
return ok3({ daily_visitors: dailyVisitors, daily_usage: dailyUsage, usage: usage.value });
|
|
2873
|
+
}
|
|
2874
|
+
var BUSINESS_PAYOUT_STATUSES = ["pending", "completed", "failed", "canceled"];
|
|
2875
|
+
function validateBusinessPayoutRecord(value, param) {
|
|
2876
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
2877
|
+
const rejected = rejectUnknownResponseKeys(value, [
|
|
2878
|
+
"id",
|
|
2879
|
+
"amount_nano_usd",
|
|
2880
|
+
"status",
|
|
2881
|
+
"requested_at",
|
|
2882
|
+
"settled_at"
|
|
2883
|
+
]);
|
|
2884
|
+
if (!rejected.ok) return rejected;
|
|
2885
|
+
const id = expectString(value.id, `${param}.id`);
|
|
2886
|
+
if (!id.ok) return id;
|
|
2887
|
+
const amount2 = expectPositiveCanonicalAmount(value.amount_nano_usd, `${param}.amount_nano_usd`);
|
|
2888
|
+
if (!amount2.ok) return amount2;
|
|
2889
|
+
const status = expectLiteral(value.status, BUSINESS_PAYOUT_STATUSES, `${param}.status`);
|
|
2890
|
+
if (!status.ok) return status;
|
|
2891
|
+
const requestedAt = expectRfc33392(value.requested_at, `${param}.requested_at`);
|
|
2892
|
+
if (!requestedAt.ok) return requestedAt;
|
|
2893
|
+
const settledAt = expectNullableRfc3339(value.settled_at, `${param}.settled_at`);
|
|
2894
|
+
if (!settledAt.ok) return settledAt;
|
|
2895
|
+
if (status.value === "pending" !== (settledAt.value === null)) {
|
|
2896
|
+
return invalidValue3(`${param}.settled_at`, "must be null exactly while the payout is pending");
|
|
2897
|
+
}
|
|
2898
|
+
return ok3({
|
|
2899
|
+
id: id.value,
|
|
2900
|
+
amount_nano_usd: amount2.value,
|
|
2901
|
+
status: status.value,
|
|
2902
|
+
requested_at: requestedAt.value,
|
|
2903
|
+
settled_at: settledAt.value
|
|
2904
|
+
});
|
|
2905
|
+
}
|
|
2906
|
+
function validateBusinessPayoutList(value, options) {
|
|
2907
|
+
return withResponseOptions(value, options, () => {
|
|
2908
|
+
if (!isPlainObject4(value)) return invalidValue3("payouts", "must be an object");
|
|
2909
|
+
if (!Array.isArray(value.payouts)) return invalidValue3("payouts", "must be an array");
|
|
2910
|
+
const payouts = [];
|
|
2911
|
+
for (const [index, item] of value.payouts.entries()) {
|
|
2912
|
+
const result = validateBusinessPayoutRecord(item, `payouts[${index}]`);
|
|
2913
|
+
if (!result.ok) return result;
|
|
2914
|
+
payouts.push(result.value);
|
|
2915
|
+
}
|
|
2916
|
+
const nextCursor = expectNullableString(value.next_cursor, "next_cursor");
|
|
2917
|
+
if (!nextCursor.ok) return nextCursor;
|
|
2918
|
+
return ok3({ payouts, next_cursor: nextCursor.value });
|
|
2919
|
+
});
|
|
2920
|
+
}
|
|
2921
|
+
function validateBusinessDashboardInfo(value, options) {
|
|
2922
|
+
return withResponseOptions(value, options, () => validateBusinessDashboardInfoShape(value));
|
|
2923
|
+
}
|
|
2924
|
+
function validateBusinessDashboardInfoShape(value) {
|
|
2925
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
2926
|
+
const business = validateBusinessDashboardBusiness(value.business);
|
|
2927
|
+
if (!business.ok) return business;
|
|
2928
|
+
const earnings = validateBusinessEarnings(value.earnings);
|
|
2929
|
+
if (!earnings.ok) return earnings;
|
|
2930
|
+
const payout = validateBusinessPayoutInfo(value.payout);
|
|
2931
|
+
if (!payout.ok) return payout;
|
|
2932
|
+
const traffic = validateBusinessTraffic(value.traffic, "traffic");
|
|
2933
|
+
if (!traffic.ok) return traffic;
|
|
2934
|
+
if (!Array.isArray(value.applications)) return invalidValue3("applications", "must be an array");
|
|
2935
|
+
const applications = [];
|
|
2936
|
+
for (const [index, item] of value.applications.entries()) {
|
|
2937
|
+
const result = validateBusinessApplicationSummary(item, `applications[${index}]`);
|
|
2938
|
+
if (!result.ok) return result;
|
|
2939
|
+
applications.push(result.value);
|
|
2940
|
+
}
|
|
2941
|
+
const nextCursor = expectNullableString(value.next_cursor, "next_cursor");
|
|
2942
|
+
if (!nextCursor.ok) return nextCursor;
|
|
2943
|
+
const range = validateDashboardRange(value.range, "range");
|
|
2944
|
+
if (!range.ok) return range;
|
|
2945
|
+
const dataFreshAt = expectRfc33392(value.data_fresh_at, "data_fresh_at");
|
|
2946
|
+
if (!dataFreshAt.ok) return dataFreshAt;
|
|
2947
|
+
return ok3({
|
|
2948
|
+
business: business.value,
|
|
2949
|
+
earnings: earnings.value,
|
|
2950
|
+
payout: payout.value,
|
|
2951
|
+
traffic: traffic.value,
|
|
2952
|
+
applications,
|
|
2953
|
+
next_cursor: nextCursor.value,
|
|
2954
|
+
range: range.value,
|
|
2955
|
+
data_fresh_at: dataFreshAt.value
|
|
2956
|
+
});
|
|
2957
|
+
}
|
|
2958
|
+
function parseAbsoluteUrl(value) {
|
|
2959
|
+
try {
|
|
2960
|
+
return new URL(value);
|
|
2961
|
+
} catch {
|
|
2962
|
+
return null;
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
2965
|
+
function isLoopbackHost(hostname) {
|
|
2966
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1";
|
|
2967
|
+
}
|
|
2968
|
+
function validateRedirectUri(value, param) {
|
|
2969
|
+
if (typeof value !== "string") return invalidValue3(param, "must be a string");
|
|
2970
|
+
const url = parseAbsoluteUrl(value);
|
|
2971
|
+
if (url === null) return invalidValue3(param, "must be an absolute URI");
|
|
2972
|
+
if (url.hash !== "") return invalidValue3(param, "must not carry a fragment");
|
|
2973
|
+
if (url.username !== "" || url.password !== "")
|
|
2974
|
+
return invalidValue3(param, "must not carry userinfo");
|
|
2975
|
+
if (url.hostname.includes("*")) return invalidValue3(param, "must not carry a wildcard host");
|
|
2976
|
+
if (url.protocol !== "https:" && !isLoopbackHost(url.hostname)) {
|
|
2977
|
+
return invalidValue3(param, "must use https except on a loopback host");
|
|
2978
|
+
}
|
|
2979
|
+
return ok3(value);
|
|
2980
|
+
}
|
|
2981
|
+
function validateAllowedOrigin(value, param) {
|
|
2982
|
+
if (typeof value !== "string") return invalidValue3(param, "must be a string");
|
|
2983
|
+
const url = parseAbsoluteUrl(value);
|
|
2984
|
+
if (url === null) return invalidValue3(param, "must be an absolute origin");
|
|
2985
|
+
if (url.hash !== "") return invalidValue3(param, "must not carry a fragment");
|
|
2986
|
+
if (url.search !== "") return invalidValue3(param, "must not carry a query");
|
|
2987
|
+
if (url.pathname !== "" && url.pathname !== "/")
|
|
2988
|
+
return invalidValue3(param, "must not carry a path");
|
|
2989
|
+
if (url.username !== "" || url.password !== "")
|
|
2990
|
+
return invalidValue3(param, "must not carry userinfo");
|
|
2991
|
+
if (url.hostname.includes("*")) return invalidValue3(param, "must not carry a wildcard host");
|
|
2992
|
+
if (url.protocol !== "https:" && !isLoopbackHost(url.hostname)) {
|
|
2993
|
+
return invalidValue3(param, "must use https except on a loopback host");
|
|
2994
|
+
}
|
|
2995
|
+
return ok3(value);
|
|
2996
|
+
}
|
|
2997
|
+
function validateUniqueStringList(value, param, each) {
|
|
2998
|
+
if (!Array.isArray(value)) return invalidValue3(param, "must be an array");
|
|
2999
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3000
|
+
const items = [];
|
|
3001
|
+
for (const [index, item] of value.entries()) {
|
|
3002
|
+
const result = each(item, `${param}[${index}]`);
|
|
3003
|
+
if (!result.ok) return result;
|
|
3004
|
+
if (seen.has(result.value))
|
|
3005
|
+
return invalidValue3(`${param}[${index}]`, "must not duplicate another entry");
|
|
3006
|
+
seen.add(result.value);
|
|
3007
|
+
items.push(result.value);
|
|
3008
|
+
}
|
|
3009
|
+
return ok3(items);
|
|
3010
|
+
}
|
|
3011
|
+
function validateCreateBusinessApplicationRequest(value) {
|
|
3012
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3013
|
+
const rejected = rejectUnknownKeys(value, [
|
|
3014
|
+
"name",
|
|
3015
|
+
"environment",
|
|
3016
|
+
"redirect_uris",
|
|
3017
|
+
"allowed_origins",
|
|
3018
|
+
"icon_url",
|
|
3019
|
+
"description",
|
|
3020
|
+
"estimated_avg_charge_nano_usd"
|
|
3021
|
+
]);
|
|
3022
|
+
if (!rejected.ok) return rejected;
|
|
3023
|
+
const name = expectString(value.name, "name");
|
|
3024
|
+
if (!name.ok) return name;
|
|
3025
|
+
const environment = expectLiteral(value.environment, APPLICATION_ENVIRONMENTS, "environment");
|
|
3026
|
+
if (!environment.ok) return environment;
|
|
3027
|
+
const redirectUris = validateUniqueStringList(
|
|
3028
|
+
value.redirect_uris,
|
|
3029
|
+
"redirect_uris",
|
|
3030
|
+
validateRedirectUri
|
|
3031
|
+
);
|
|
3032
|
+
if (!redirectUris.ok) return redirectUris;
|
|
3033
|
+
const allowedOrigins = validateUniqueStringList(
|
|
3034
|
+
value.allowed_origins,
|
|
3035
|
+
"allowed_origins",
|
|
3036
|
+
validateAllowedOrigin
|
|
3037
|
+
);
|
|
3038
|
+
if (!allowedOrigins.ok) return allowedOrigins;
|
|
3039
|
+
const iconUrl = expectOptionalString(value.icon_url, "icon_url");
|
|
3040
|
+
if (!iconUrl.ok) return iconUrl;
|
|
3041
|
+
const description = expectOptionalString(value.description, "description");
|
|
3042
|
+
if (!description.ok) return description;
|
|
3043
|
+
const estimate = value.estimated_avg_charge_nano_usd === void 0 ? ok3(void 0) : expectPositiveCanonicalAmount(
|
|
3044
|
+
value.estimated_avg_charge_nano_usd,
|
|
3045
|
+
"estimated_avg_charge_nano_usd"
|
|
3046
|
+
);
|
|
3047
|
+
if (!estimate.ok) return estimate;
|
|
3048
|
+
return ok3({
|
|
3049
|
+
name: name.value,
|
|
3050
|
+
environment: environment.value,
|
|
3051
|
+
redirect_uris: redirectUris.value,
|
|
3052
|
+
allowed_origins: allowedOrigins.value,
|
|
3053
|
+
...iconUrl.value !== void 0 ? { icon_url: iconUrl.value } : {},
|
|
3054
|
+
...description.value !== void 0 ? { description: description.value } : {},
|
|
3055
|
+
...estimate.value !== void 0 ? { estimated_avg_charge_nano_usd: estimate.value } : {}
|
|
3056
|
+
});
|
|
3057
|
+
}
|
|
3058
|
+
function validateUpdateBusinessApplicationRequest(value) {
|
|
3059
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3060
|
+
if ("environment" in value) {
|
|
3061
|
+
return unsupportedParameter3(
|
|
3062
|
+
"environment",
|
|
3063
|
+
"environment is fixed at creation and cannot be changed"
|
|
3064
|
+
);
|
|
3065
|
+
}
|
|
3066
|
+
const rejected = rejectUnknownKeys(value, [
|
|
3067
|
+
"name",
|
|
3068
|
+
"redirect_uris",
|
|
3069
|
+
"allowed_origins",
|
|
3070
|
+
"icon_url",
|
|
3071
|
+
"description",
|
|
3072
|
+
"estimated_avg_charge_nano_usd"
|
|
3073
|
+
]);
|
|
3074
|
+
if (!rejected.ok) return rejected;
|
|
3075
|
+
const result = {};
|
|
3076
|
+
if (value.name !== void 0) {
|
|
3077
|
+
const name = expectString(value.name, "name");
|
|
3078
|
+
if (!name.ok) return name;
|
|
3079
|
+
result.name = name.value;
|
|
3080
|
+
}
|
|
3081
|
+
if (value.redirect_uris !== void 0) {
|
|
3082
|
+
const redirectUris = validateUniqueStringList(
|
|
3083
|
+
value.redirect_uris,
|
|
3084
|
+
"redirect_uris",
|
|
3085
|
+
validateRedirectUri
|
|
3086
|
+
);
|
|
3087
|
+
if (!redirectUris.ok) return redirectUris;
|
|
3088
|
+
result.redirect_uris = redirectUris.value;
|
|
3089
|
+
}
|
|
3090
|
+
if (value.allowed_origins !== void 0) {
|
|
3091
|
+
const allowedOrigins = validateUniqueStringList(
|
|
3092
|
+
value.allowed_origins,
|
|
3093
|
+
"allowed_origins",
|
|
3094
|
+
validateAllowedOrigin
|
|
3095
|
+
);
|
|
3096
|
+
if (!allowedOrigins.ok) return allowedOrigins;
|
|
3097
|
+
result.allowed_origins = allowedOrigins.value;
|
|
3098
|
+
}
|
|
3099
|
+
if (value.icon_url !== void 0) {
|
|
3100
|
+
const iconUrl = expectNullableString(value.icon_url, "icon_url");
|
|
3101
|
+
if (!iconUrl.ok) return iconUrl;
|
|
3102
|
+
result.icon_url = iconUrl.value;
|
|
3103
|
+
}
|
|
3104
|
+
if (value.description !== void 0) {
|
|
3105
|
+
const description = expectNullableString(value.description, "description");
|
|
3106
|
+
if (!description.ok) return description;
|
|
3107
|
+
result.description = description.value;
|
|
3108
|
+
}
|
|
3109
|
+
if (value.estimated_avg_charge_nano_usd !== void 0) {
|
|
3110
|
+
const estimate = value.estimated_avg_charge_nano_usd === null ? ok3(null) : expectPositiveCanonicalAmount(
|
|
3111
|
+
value.estimated_avg_charge_nano_usd,
|
|
3112
|
+
"estimated_avg_charge_nano_usd"
|
|
3113
|
+
);
|
|
3114
|
+
if (!estimate.ok) return estimate;
|
|
3115
|
+
result.estimated_avg_charge_nano_usd = estimate.value;
|
|
3116
|
+
}
|
|
3117
|
+
return ok3(result);
|
|
3118
|
+
}
|
|
3119
|
+
function validateBusinessApplicationAnalyticsDay(value, param) {
|
|
3120
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
3121
|
+
const day = expectCalendarDay(value.day, `${param}.day`);
|
|
3122
|
+
if (!day.ok) return day;
|
|
3123
|
+
const dailyVisitors = expectNonNegativeInteger(value.daily_visitors, `${param}.daily_visitors`);
|
|
3124
|
+
if (!dailyVisitors.ok) return dailyVisitors;
|
|
3125
|
+
const standardRequests = expectNonNegativeInteger(
|
|
3126
|
+
value.standard_requests,
|
|
3127
|
+
`${param}.standard_requests`
|
|
3128
|
+
);
|
|
3129
|
+
if (!standardRequests.ok) return standardRequests;
|
|
3130
|
+
const premiumRequests = expectNonNegativeInteger(
|
|
3131
|
+
value.premium_requests,
|
|
3132
|
+
`${param}.premium_requests`
|
|
3133
|
+
);
|
|
3134
|
+
if (!premiumRequests.ok) return premiumRequests;
|
|
3135
|
+
const standardUsedNanoUsd = expectCanonicalAmount(
|
|
3136
|
+
value.standard_used_nano_usd,
|
|
3137
|
+
`${param}.standard_used_nano_usd`
|
|
3138
|
+
);
|
|
3139
|
+
if (!standardUsedNanoUsd.ok) return standardUsedNanoUsd;
|
|
3140
|
+
const premiumUsedNanoUsd = expectCanonicalAmount(
|
|
3141
|
+
value.premium_used_nano_usd,
|
|
3142
|
+
`${param}.premium_used_nano_usd`
|
|
3143
|
+
);
|
|
3144
|
+
if (!premiumUsedNanoUsd.ok) return premiumUsedNanoUsd;
|
|
3145
|
+
const businessEarningsNanoUsd = expectCanonicalAmount(
|
|
3146
|
+
value.business_earnings_nano_usd,
|
|
3147
|
+
`${param}.business_earnings_nano_usd`
|
|
3148
|
+
);
|
|
3149
|
+
if (!businessEarningsNanoUsd.ok) return businessEarningsNanoUsd;
|
|
3150
|
+
return ok3({
|
|
3151
|
+
day: day.value,
|
|
3152
|
+
daily_visitors: dailyVisitors.value,
|
|
3153
|
+
standard_requests: standardRequests.value,
|
|
3154
|
+
premium_requests: premiumRequests.value,
|
|
3155
|
+
standard_used_nano_usd: standardUsedNanoUsd.value,
|
|
3156
|
+
premium_used_nano_usd: premiumUsedNanoUsd.value,
|
|
3157
|
+
business_earnings_nano_usd: businessEarningsNanoUsd.value
|
|
3158
|
+
});
|
|
3159
|
+
}
|
|
3160
|
+
function validateBusinessApplicationAnalytics(value) {
|
|
3161
|
+
if (!isPlainObject4(value)) return invalidValue3("analytics", "must be an object");
|
|
3162
|
+
const range = validateDashboardRange(value.range, "analytics.range");
|
|
3163
|
+
if (!range.ok) return range;
|
|
3164
|
+
if (!Array.isArray(value.days)) return invalidValue3("analytics.days", "must be an array");
|
|
3165
|
+
const days = [];
|
|
3166
|
+
for (const [index, item] of value.days.entries()) {
|
|
3167
|
+
const result = validateBusinessApplicationAnalyticsDay(item, `analytics.days[${index}]`);
|
|
3168
|
+
if (!result.ok) return result;
|
|
3169
|
+
days.push(result.value);
|
|
3170
|
+
}
|
|
3171
|
+
const nextCursor = expectNullableString(value.next_cursor, "analytics.next_cursor");
|
|
3172
|
+
if (!nextCursor.ok) return nextCursor;
|
|
3173
|
+
return ok3({ range: range.value, days, next_cursor: nextCursor.value });
|
|
3174
|
+
}
|
|
3175
|
+
function validateBusinessApplicationInfo(value, param = "info", options) {
|
|
3176
|
+
return withResponseOptions(value, options, () => validateBusinessApplicationInfoShape(value, param));
|
|
3177
|
+
}
|
|
3178
|
+
function validateBusinessApplicationInfoShape(value, param) {
|
|
3179
|
+
if (value === null) return ok3(null);
|
|
3180
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object or null");
|
|
3181
|
+
const rejected = rejectUnknownResponseKeys(value, [
|
|
3182
|
+
"icon_url",
|
|
3183
|
+
"description",
|
|
3184
|
+
"estimated_avg_charge_nano_usd"
|
|
3185
|
+
]);
|
|
3186
|
+
if (!rejected.ok) return rejected;
|
|
3187
|
+
const iconUrl = expectOptionalString(value.icon_url, `${param}.icon_url`);
|
|
3188
|
+
if (!iconUrl.ok) return iconUrl;
|
|
3189
|
+
const description = expectOptionalString(value.description, `${param}.description`);
|
|
3190
|
+
if (!description.ok) return description;
|
|
3191
|
+
const estimate = expectOptionalCanonicalAmount(
|
|
3192
|
+
value.estimated_avg_charge_nano_usd,
|
|
3193
|
+
`${param}.estimated_avg_charge_nano_usd`
|
|
3194
|
+
);
|
|
3195
|
+
if (!estimate.ok) return estimate;
|
|
3196
|
+
return ok3({
|
|
3197
|
+
...iconUrl.value !== void 0 ? { icon_url: iconUrl.value } : {},
|
|
3198
|
+
...description.value !== void 0 ? { description: description.value } : {},
|
|
3199
|
+
...estimate.value !== void 0 ? { estimated_avg_charge_nano_usd: estimate.value } : {}
|
|
3200
|
+
});
|
|
3201
|
+
}
|
|
3202
|
+
function validateBusinessApplicationDetail(value, options) {
|
|
3203
|
+
return withResponseOptions(value, options, () => validateBusinessApplicationDetailShape(value));
|
|
3204
|
+
}
|
|
3205
|
+
function validateBusinessApplicationDetailShape(value) {
|
|
3206
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3207
|
+
const id = expectString(value.id, "id");
|
|
3208
|
+
if (!id.ok) return id;
|
|
3209
|
+
const clientId = expectString(value.client_id, "client_id");
|
|
3210
|
+
if (!clientId.ok) return clientId;
|
|
3211
|
+
const name = expectString(value.name, "name");
|
|
3212
|
+
if (!name.ok) return name;
|
|
3213
|
+
const environment = expectLiteral(value.environment, APPLICATION_ENVIRONMENTS, "environment");
|
|
3214
|
+
if (!environment.ok) return environment;
|
|
3215
|
+
const status = expectLiteral(value.status, APPLICATION_STATUSES, "status");
|
|
3216
|
+
if (!status.ok) return status;
|
|
3217
|
+
const info = validateBusinessApplicationInfoShape(value.info, "info");
|
|
3218
|
+
if (!info.ok) return info;
|
|
3219
|
+
const redirectUris = validateUniqueStringList(
|
|
3220
|
+
value.redirect_uris,
|
|
3221
|
+
"redirect_uris",
|
|
3222
|
+
validateRedirectUri
|
|
3223
|
+
);
|
|
3224
|
+
if (!redirectUris.ok) return redirectUris;
|
|
3225
|
+
const allowedOrigins = validateUniqueStringList(
|
|
3226
|
+
value.allowed_origins,
|
|
3227
|
+
"allowed_origins",
|
|
3228
|
+
validateAllowedOrigin
|
|
3229
|
+
);
|
|
3230
|
+
if (!allowedOrigins.ok) return allowedOrigins;
|
|
3231
|
+
const createdAt = expectRfc33392(value.created_at, "created_at");
|
|
3232
|
+
if (!createdAt.ok) return createdAt;
|
|
3233
|
+
const analytics = validateBusinessApplicationAnalytics(value.analytics);
|
|
3234
|
+
if (!analytics.ok) return analytics;
|
|
3235
|
+
const apiKeys = validateApiKeyMetadataArray(value.api_keys, "api_keys");
|
|
3236
|
+
if (!apiKeys.ok) return apiKeys;
|
|
3237
|
+
return ok3({
|
|
3238
|
+
id: id.value,
|
|
3239
|
+
client_id: clientId.value,
|
|
3240
|
+
name: name.value,
|
|
3241
|
+
environment: environment.value,
|
|
3242
|
+
status: status.value,
|
|
3243
|
+
info: info.value,
|
|
3244
|
+
redirect_uris: redirectUris.value,
|
|
3245
|
+
allowed_origins: allowedOrigins.value,
|
|
3246
|
+
created_at: createdAt.value,
|
|
3247
|
+
analytics: analytics.value,
|
|
3248
|
+
api_keys: apiKeys.value
|
|
3249
|
+
});
|
|
3250
|
+
}
|
|
3251
|
+
function validateCreateBusinessKeyRequest(value) {
|
|
3252
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3253
|
+
const rejected = rejectUnknownKeys(value, ["scope", "name", "application_id", "expires_at"]);
|
|
3254
|
+
if (!rejected.ok) return rejected;
|
|
3255
|
+
const scope = expectLiteral(value.scope, API_KEY_SCOPES, "scope");
|
|
3256
|
+
if (!scope.ok) return scope;
|
|
3257
|
+
const name = expectString(value.name, "name");
|
|
3258
|
+
if (!name.ok) return name;
|
|
3259
|
+
const applicationId = expectOptionalString(value.application_id, "application_id");
|
|
3260
|
+
if (!applicationId.ok) return applicationId;
|
|
3261
|
+
const expiresAt = expectOptionalRfc3339(value.expires_at, "expires_at");
|
|
3262
|
+
if (!expiresAt.ok) return expiresAt;
|
|
3263
|
+
if (scope.value === "model" && applicationId.value === void 0) {
|
|
3264
|
+
return invalidValue3("application_id", 'is required when scope is "model"');
|
|
3265
|
+
}
|
|
3266
|
+
if (scope.value === "reporting" && applicationId.value !== void 0) {
|
|
3267
|
+
return unsupportedParameter3("application_id", 'must not be present when scope is "reporting"');
|
|
3268
|
+
}
|
|
3269
|
+
return ok3({
|
|
3270
|
+
scope: scope.value,
|
|
3271
|
+
name: name.value,
|
|
3272
|
+
...applicationId.value !== void 0 ? { application_id: applicationId.value } : {},
|
|
3273
|
+
...expiresAt.value !== void 0 ? { expires_at: expiresAt.value } : {}
|
|
3274
|
+
});
|
|
3275
|
+
}
|
|
3276
|
+
function validateCreateBusinessKeyResponse(value, options) {
|
|
3277
|
+
return withResponseOptions(value, options, () => validateCreateBusinessKeyResponseShape(value));
|
|
3278
|
+
}
|
|
3279
|
+
function validateCreateBusinessKeyResponseShape(value) {
|
|
3280
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3281
|
+
const metadata = validateApiKeyMetadata(value.metadata, "metadata");
|
|
3282
|
+
if (!metadata.ok) return metadata;
|
|
3283
|
+
const secret = expectString(value.secret, "secret");
|
|
3284
|
+
if (!secret.ok) return secret;
|
|
3285
|
+
return ok3({ metadata: metadata.value, secret: secret.value });
|
|
3286
|
+
}
|
|
3287
|
+
function validateCreateBusinessPayoutRequest(value) {
|
|
3288
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3289
|
+
const rejected = rejectUnknownKeys(value, ["amount_nano_usd"]);
|
|
3290
|
+
if (!rejected.ok) return rejected;
|
|
3291
|
+
const amount2 = expectPositiveCanonicalAmount(value.amount_nano_usd, "amount_nano_usd");
|
|
3292
|
+
if (!amount2.ok) return amount2;
|
|
3293
|
+
return ok3({ amount_nano_usd: amount2.value });
|
|
3294
|
+
}
|
|
3295
|
+
function validateBusinessPayoutAccountOnboardingResponse(value, options) {
|
|
3296
|
+
return withResponseOptions(value, options, () => validateBusinessPayoutAccountOnboardingResponseShape(value));
|
|
3297
|
+
}
|
|
3298
|
+
function validateBusinessPayoutAccountOnboardingResponseShape(value) {
|
|
3299
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3300
|
+
const url = expectString(value.url, "url");
|
|
3301
|
+
if (!url.ok) return url;
|
|
3302
|
+
const expiresAt = expectRfc33392(value.expires_at, "expires_at");
|
|
3303
|
+
if (!expiresAt.ok) return expiresAt;
|
|
3304
|
+
return ok3({ url: url.value, expires_at: expiresAt.value });
|
|
3305
|
+
}
|
|
3306
|
+
function validateEmptyRequestBody(value) {
|
|
3307
|
+
if (value === void 0) return ok3({});
|
|
3308
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be empty");
|
|
3309
|
+
const keys = Object.keys(value);
|
|
3310
|
+
if (keys.length > 0) {
|
|
3311
|
+
return unsupportedParameter3(
|
|
3312
|
+
keys[0],
|
|
3313
|
+
`"${keys[0]}" is not accepted by this route, which takes no body`
|
|
3314
|
+
);
|
|
3315
|
+
}
|
|
3316
|
+
return ok3({});
|
|
3317
|
+
}
|
|
3318
|
+
function expectAssignableBusinessRole(value, param) {
|
|
3319
|
+
const role = expectLiteral(value, BUSINESS_ROLE_NAMES, param);
|
|
3320
|
+
if (!role.ok) return role;
|
|
3321
|
+
if (role.value === "owner") return invalidValue3(param, 'must not be "owner"');
|
|
3322
|
+
return ok3(role.value);
|
|
3323
|
+
}
|
|
3324
|
+
function validateBusinessPermissions(value, param) {
|
|
3325
|
+
if (!Array.isArray(value)) return invalidValue3(param, "must be an array");
|
|
3326
|
+
const permissions = [];
|
|
3327
|
+
let previousKnownPermissionIndex = -1;
|
|
3328
|
+
for (const [index, item] of value.entries()) {
|
|
3329
|
+
const permission = expectLiteral(item, BUSINESS_PERMISSIONS, `${param}[${index}]`);
|
|
3330
|
+
if (!permission.ok) return permission;
|
|
3331
|
+
const permissionIndex = BUSINESS_PERMISSIONS.indexOf(permission.value);
|
|
3332
|
+
if (permissionIndex !== -1) {
|
|
3333
|
+
if (permissionIndex <= previousKnownPermissionIndex) {
|
|
3334
|
+
return invalidValue3(param, "must contain declared permissions at most once and in declared order");
|
|
3335
|
+
}
|
|
3336
|
+
previousKnownPermissionIndex = permissionIndex;
|
|
3337
|
+
}
|
|
3338
|
+
permissions.push(permission.value);
|
|
3339
|
+
}
|
|
3340
|
+
return ok3(permissions);
|
|
3341
|
+
}
|
|
3342
|
+
function validateBusinessAccessActiveBusiness(value) {
|
|
3343
|
+
if (!isPlainObject4(value)) return invalidValue3("active_business", "must be an object");
|
|
3344
|
+
const id = expectString(value.id, "active_business.id");
|
|
3345
|
+
if (!id.ok) return id;
|
|
3346
|
+
const name = expectString(value.name, "active_business.name");
|
|
3347
|
+
if (!name.ok) return name;
|
|
3348
|
+
const createdAt = expectRfc33392(value.created_at, "active_business.created_at");
|
|
3349
|
+
if (!createdAt.ok) return createdAt;
|
|
3350
|
+
const role = expectLiteral(value.role, BUSINESS_ROLE_NAMES, "active_business.role");
|
|
3351
|
+
if (!role.ok) return role;
|
|
3352
|
+
const permissions = validateBusinessPermissions(value.permissions, "active_business.permissions");
|
|
3353
|
+
if (!permissions.ok) return permissions;
|
|
3354
|
+
return ok3({ id: id.value, name: name.value, created_at: createdAt.value, role: role.value, permissions: permissions.value });
|
|
3355
|
+
}
|
|
3356
|
+
function validateBusinessAccessBusiness(value, param) {
|
|
3357
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
3358
|
+
const id = expectString(value.id, `${param}.id`);
|
|
3359
|
+
if (!id.ok) return id;
|
|
3360
|
+
const name = expectString(value.name, `${param}.name`);
|
|
3361
|
+
if (!name.ok) return name;
|
|
3362
|
+
const role = expectLiteral(value.role, BUSINESS_ROLE_NAMES, `${param}.role`);
|
|
3363
|
+
if (!role.ok) return role;
|
|
3364
|
+
const status = expectLiteral(value.status, APPLICATION_STATUSES, `${param}.status`);
|
|
3365
|
+
if (!status.ok) return status;
|
|
3366
|
+
return ok3({ id: id.value, name: name.value, role: role.value, status: status.value });
|
|
3367
|
+
}
|
|
3368
|
+
function validatePendingBusinessInvitation(value, param) {
|
|
3369
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
3370
|
+
const id = expectString(value.id, `${param}.id`);
|
|
3371
|
+
if (!id.ok) return id;
|
|
3372
|
+
const businessId = expectString(value.business_id, `${param}.business_id`);
|
|
3373
|
+
if (!businessId.ok) return businessId;
|
|
3374
|
+
const businessName = expectString(value.business_name, `${param}.business_name`);
|
|
3375
|
+
if (!businessName.ok) return businessName;
|
|
3376
|
+
const role = expectLiteral(value.role, BUSINESS_ROLE_NAMES, `${param}.role`);
|
|
3377
|
+
if (!role.ok) return role;
|
|
3378
|
+
if (role.value === "owner") return invalidValue3(`${param}.role`, 'must not be "owner"');
|
|
3379
|
+
const invitedBy = expectNullableString(value.invited_by_email, `${param}.invited_by_email`);
|
|
3380
|
+
if (!invitedBy.ok) return invitedBy;
|
|
3381
|
+
const expiresAt = expectRfc33392(value.expires_at, `${param}.expires_at`);
|
|
3382
|
+
if (!expiresAt.ok) return expiresAt;
|
|
3383
|
+
return ok3({
|
|
3384
|
+
id: id.value,
|
|
3385
|
+
business_id: businessId.value,
|
|
3386
|
+
business_name: businessName.value,
|
|
3387
|
+
role: role.value,
|
|
3388
|
+
invited_by_email: invitedBy.value,
|
|
3389
|
+
expires_at: expiresAt.value
|
|
3390
|
+
});
|
|
3391
|
+
}
|
|
3392
|
+
function validateBusinessAccess(value, options) {
|
|
3393
|
+
return withResponseOptions(value, options, () => validateBusinessAccessShape(value));
|
|
3394
|
+
}
|
|
3395
|
+
function validateBusinessAccessShape(value) {
|
|
3396
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3397
|
+
if (!isPlainObject4(value.login)) return invalidValue3("login", "must be an object");
|
|
3398
|
+
const loginEmail = expectString(value.login.email, "login.email");
|
|
3399
|
+
if (!loginEmail.ok) return loginEmail;
|
|
3400
|
+
const ownsBusiness = expectBoolean(value.owns_business, "owns_business");
|
|
3401
|
+
if (!ownsBusiness.ok) return ownsBusiness;
|
|
3402
|
+
const active = value.active_business === null ? ok3(null) : validateBusinessAccessActiveBusiness(value.active_business);
|
|
3403
|
+
if (!active.ok) return active;
|
|
3404
|
+
if (!Array.isArray(value.businesses)) return invalidValue3("businesses", "must be an array");
|
|
3405
|
+
const businesses = [];
|
|
3406
|
+
for (const [index, item] of value.businesses.entries()) {
|
|
3407
|
+
const business = validateBusinessAccessBusiness(item, `businesses[${index}]`);
|
|
3408
|
+
if (!business.ok) return business;
|
|
3409
|
+
businesses.push(business.value);
|
|
3410
|
+
}
|
|
3411
|
+
if (!Array.isArray(value.pending_invitations)) {
|
|
3412
|
+
return invalidValue3("pending_invitations", "must be an array");
|
|
3413
|
+
}
|
|
3414
|
+
const invitations = [];
|
|
3415
|
+
for (const [index, item] of value.pending_invitations.entries()) {
|
|
3416
|
+
const invitation = validatePendingBusinessInvitation(item, `pending_invitations[${index}]`);
|
|
3417
|
+
if (!invitation.ok) return invitation;
|
|
3418
|
+
invitations.push(invitation.value);
|
|
3419
|
+
}
|
|
3420
|
+
return ok3({
|
|
3421
|
+
login: { email: loginEmail.value },
|
|
3422
|
+
owns_business: ownsBusiness.value,
|
|
3423
|
+
active_business: active.value,
|
|
3424
|
+
businesses,
|
|
3425
|
+
pending_invitations: invitations
|
|
3426
|
+
});
|
|
3427
|
+
}
|
|
3428
|
+
function validateBusinessMember(value, param) {
|
|
3429
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
3430
|
+
const id = expectString(value.id, `${param}.id`);
|
|
3431
|
+
if (!id.ok) return id;
|
|
3432
|
+
const email = expectString(value.email, `${param}.email`);
|
|
3433
|
+
if (!email.ok) return email;
|
|
3434
|
+
const role = expectAssignableBusinessRole(value.role, `${param}.role`);
|
|
3435
|
+
if (!role.ok) return role;
|
|
3436
|
+
const joinedAt = expectRfc33392(value.joined_at, `${param}.joined_at`);
|
|
3437
|
+
if (!joinedAt.ok) return joinedAt;
|
|
3438
|
+
const isYou = expectBoolean(value.is_you, `${param}.is_you`);
|
|
3439
|
+
if (!isYou.ok) return isYou;
|
|
3440
|
+
return ok3({ id: id.value, email: email.value, role: role.value, joined_at: joinedAt.value, is_you: isYou.value });
|
|
3441
|
+
}
|
|
3442
|
+
function validateBusinessMemberInvitation(value, param) {
|
|
3443
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
3444
|
+
const id = expectString(value.id, `${param}.id`);
|
|
3445
|
+
if (!id.ok) return id;
|
|
3446
|
+
const email = expectString(value.email, `${param}.email`);
|
|
3447
|
+
if (!email.ok) return email;
|
|
3448
|
+
const role = expectAssignableBusinessRole(value.role, `${param}.role`);
|
|
3449
|
+
if (!role.ok) return role;
|
|
3450
|
+
const invitedBy = expectNullableString(value.invited_by_email, `${param}.invited_by_email`);
|
|
3451
|
+
if (!invitedBy.ok) return invitedBy;
|
|
3452
|
+
const createdAt = expectRfc33392(value.created_at, `${param}.created_at`);
|
|
3453
|
+
if (!createdAt.ok) return createdAt;
|
|
3454
|
+
const expiresAt = expectRfc33392(value.expires_at, `${param}.expires_at`);
|
|
3455
|
+
if (!expiresAt.ok) return expiresAt;
|
|
3456
|
+
return ok3({
|
|
3457
|
+
id: id.value,
|
|
3458
|
+
email: email.value,
|
|
3459
|
+
role: role.value,
|
|
3460
|
+
invited_by_email: invitedBy.value,
|
|
3461
|
+
created_at: createdAt.value,
|
|
3462
|
+
expires_at: expiresAt.value
|
|
3463
|
+
});
|
|
3464
|
+
}
|
|
3465
|
+
function validateBusinessMemberList(value, options) {
|
|
3466
|
+
return withResponseOptions(value, options, () => validateBusinessMemberListShape(value));
|
|
3467
|
+
}
|
|
3468
|
+
function validateBusinessMemberListShape(value) {
|
|
3469
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3470
|
+
if (!isPlainObject4(value.owner)) return invalidValue3("owner", "must be an object");
|
|
3471
|
+
const ownerEmail = expectString(value.owner.email, "owner.email");
|
|
3472
|
+
if (!ownerEmail.ok) return ownerEmail;
|
|
3473
|
+
const ownerIsYou = expectBoolean(value.owner.is_you, "owner.is_you");
|
|
3474
|
+
if (!ownerIsYou.ok) return ownerIsYou;
|
|
3475
|
+
if (!Array.isArray(value.members)) return invalidValue3("members", "must be an array");
|
|
3476
|
+
const members = [];
|
|
3477
|
+
for (const [index, item] of value.members.entries()) {
|
|
3478
|
+
const member = validateBusinessMember(item, `members[${index}]`);
|
|
3479
|
+
if (!member.ok) return member;
|
|
3480
|
+
members.push(member.value);
|
|
3481
|
+
}
|
|
3482
|
+
if (!Array.isArray(value.invitations)) return invalidValue3("invitations", "must be an array");
|
|
3483
|
+
const invitations = [];
|
|
3484
|
+
for (const [index, item] of value.invitations.entries()) {
|
|
3485
|
+
const invitation = validateBusinessMemberInvitation(item, `invitations[${index}]`);
|
|
3486
|
+
if (!invitation.ok) return invitation;
|
|
3487
|
+
invitations.push(invitation.value);
|
|
3488
|
+
}
|
|
3489
|
+
return ok3({ owner: { email: ownerEmail.value, is_you: ownerIsYou.value }, members, invitations });
|
|
3490
|
+
}
|
|
3491
|
+
function validateBusinessInvitationResult(value, options) {
|
|
3492
|
+
return withResponseOptions(value, options, () => validateBusinessInvitationResultShape(value));
|
|
3493
|
+
}
|
|
3494
|
+
function validateBusinessInvitationResultShape(value) {
|
|
3495
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3496
|
+
const invitation = validateBusinessMemberInvitation(value.invitation, "invitation");
|
|
3497
|
+
if (!invitation.ok) return invitation;
|
|
3498
|
+
const delivery = expectLiteral(value.email_delivery, ["sent", "failed"], "email_delivery");
|
|
3499
|
+
if (!delivery.ok) return delivery;
|
|
3500
|
+
return ok3({ invitation: invitation.value, email_delivery: delivery.value });
|
|
3501
|
+
}
|
|
3502
|
+
function validateCreateBusinessRequest(value) {
|
|
3503
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3504
|
+
const unknown = rejectUnknownKeys(value, ["name"]);
|
|
3505
|
+
if (!unknown.ok) return unknown;
|
|
3506
|
+
const name = expectString(value.name, "name");
|
|
3507
|
+
if (!name.ok) return name;
|
|
3508
|
+
const trimmed = name.value.trim();
|
|
3509
|
+
const characters = Array.from(trimmed);
|
|
3510
|
+
if (characters.length === 0 || characters.length > 100 || characters.some((character) => character <= "" || character === "\x7F")) {
|
|
3511
|
+
return invalidValue3("name", "must be 1\u2013100 trimmed characters with no control character");
|
|
3512
|
+
}
|
|
3513
|
+
return ok3({ name: trimmed });
|
|
3514
|
+
}
|
|
3515
|
+
function validateSelectActiveBusinessRequest(value) {
|
|
3516
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3517
|
+
const unknown = rejectUnknownKeys(value, ["business_id"]);
|
|
3518
|
+
if (!unknown.ok) return unknown;
|
|
3519
|
+
const businessId = expectString(value.business_id, "business_id");
|
|
3520
|
+
if (!businessId.ok) return businessId;
|
|
3521
|
+
return ok3({ business_id: businessId.value });
|
|
3522
|
+
}
|
|
3523
|
+
function validateBusinessInvitationRequest(value) {
|
|
3524
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3525
|
+
const unknown = rejectUnknownKeys(value, ["email", "role"]);
|
|
3526
|
+
if (!unknown.ok) return unknown;
|
|
3527
|
+
const email = expectEmailAddress(value.email, "email");
|
|
3528
|
+
if (!email.ok) return email;
|
|
3529
|
+
const role = expectAssignableBusinessRole(value.role, "role");
|
|
3530
|
+
if (!role.ok) return role;
|
|
3531
|
+
return ok3({ email: email.value, role: role.value });
|
|
3532
|
+
}
|
|
3533
|
+
function validateChangeBusinessMemberRoleRequest(value) {
|
|
3534
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3535
|
+
const unknown = rejectUnknownKeys(value, ["role"]);
|
|
3536
|
+
if (!unknown.ok) return unknown;
|
|
3537
|
+
const role = expectAssignableBusinessRole(value.role, "role");
|
|
3538
|
+
if (!role.ok) return role;
|
|
3539
|
+
return ok3({ role: role.value });
|
|
3540
|
+
}
|
|
3541
|
+
function validateTransferBusinessOwnershipRequest(value) {
|
|
3542
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3543
|
+
const unknown = rejectUnknownKeys(value, ["member_id"]);
|
|
3544
|
+
if (!unknown.ok) return unknown;
|
|
3545
|
+
const memberId = expectString(value.member_id, "member_id");
|
|
3546
|
+
if (!memberId.ok) return memberId;
|
|
3547
|
+
return ok3({ member_id: memberId.value });
|
|
3548
|
+
}
|
|
3549
|
+
function validateStartBusinessLoginEmailChangeRequest(value) {
|
|
3550
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3551
|
+
const unknown = rejectUnknownKeys(value, ["email", "turnstile_token"]);
|
|
3552
|
+
if (!unknown.ok) return unknown;
|
|
3553
|
+
const email = expectEmailAddress(value.email, "email");
|
|
3554
|
+
if (!email.ok) return email;
|
|
3555
|
+
return ok3({ email: email.value, turnstile_token: readTurnstileToken(value) });
|
|
3556
|
+
}
|
|
3557
|
+
function validateBusinessLoginEmailChallenge(value, options) {
|
|
3558
|
+
return withResponseOptions(value, options, () => {
|
|
3559
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3560
|
+
const challengeId = expectString(value.challenge_id, "challenge_id");
|
|
3561
|
+
if (!challengeId.ok) return challengeId;
|
|
3562
|
+
const resendAfter = expectNonNegativeInteger(value.resend_after_seconds, "resend_after_seconds");
|
|
3563
|
+
if (!resendAfter.ok) return resendAfter;
|
|
3564
|
+
return ok3({ challenge_id: challengeId.value, resend_after_seconds: resendAfter.value });
|
|
3565
|
+
});
|
|
3566
|
+
}
|
|
3567
|
+
function validateVerifyBusinessLoginEmailChangeRequest(value) {
|
|
3568
|
+
return validateVerifyContactRequest(value);
|
|
3569
|
+
}
|
|
3570
|
+
var EMAIL_SIGN_IN_ACCOUNT_TYPES = ["user", "business"];
|
|
3571
|
+
var EMAIL_SIGN_IN_MAX_EMAIL_LENGTH = 254;
|
|
3572
|
+
var EMAIL_SYNTAX = /^[^\s@,;<>"\\]+@[^\s@,;<>"\\.]+(\.[^\s@,;<>"\\.]+)+$/;
|
|
3573
|
+
var SIGN_IN_CODE_SYNTAX = /^[0-9]{6}$/;
|
|
3574
|
+
function expectEmailAddress(value, param) {
|
|
3575
|
+
const text = expectString(value, param);
|
|
3576
|
+
if (!text.ok) return text;
|
|
3577
|
+
if (text.value.length > EMAIL_SIGN_IN_MAX_EMAIL_LENGTH) {
|
|
3578
|
+
return invalidValue3(param, `must be at most ${EMAIL_SIGN_IN_MAX_EMAIL_LENGTH} characters`);
|
|
3579
|
+
}
|
|
3580
|
+
if (!EMAIL_SYNTAX.test(text.value)) {
|
|
3581
|
+
return invalidValue3(param, "must be an email address");
|
|
3582
|
+
}
|
|
3583
|
+
return text;
|
|
3584
|
+
}
|
|
3585
|
+
function validateEmailSignInSendRequest(value) {
|
|
3586
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3587
|
+
const rejected = rejectUnknownKeys(value, ["email", "account_type", "turnstile_token"]);
|
|
3588
|
+
if (!rejected.ok) return rejected;
|
|
3589
|
+
const email = expectEmailAddress(value.email, "email");
|
|
3590
|
+
if (!email.ok) return email;
|
|
3591
|
+
const accountType = expectLiteral(
|
|
3592
|
+
value.account_type,
|
|
3593
|
+
EMAIL_SIGN_IN_ACCOUNT_TYPES,
|
|
3594
|
+
"account_type"
|
|
3595
|
+
);
|
|
3596
|
+
if (!accountType.ok) return accountType;
|
|
3597
|
+
return ok3({
|
|
3598
|
+
email: email.value,
|
|
3599
|
+
account_type: accountType.value,
|
|
3600
|
+
turnstile_token: readTurnstileToken(value)
|
|
3601
|
+
});
|
|
3602
|
+
}
|
|
3603
|
+
function validateEmailSignInVerifyRequest(value) {
|
|
3604
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3605
|
+
const rejected = rejectUnknownKeys(value, ["email", "account_type", "code"]);
|
|
3606
|
+
if (!rejected.ok) return rejected;
|
|
3607
|
+
const email = expectEmailAddress(value.email, "email");
|
|
3608
|
+
if (!email.ok) return email;
|
|
3609
|
+
const accountType = expectLiteral(
|
|
3610
|
+
value.account_type,
|
|
3611
|
+
EMAIL_SIGN_IN_ACCOUNT_TYPES,
|
|
3612
|
+
"account_type"
|
|
3613
|
+
);
|
|
3614
|
+
if (!accountType.ok) return accountType;
|
|
3615
|
+
const code = expectString(value.code, "code");
|
|
3616
|
+
if (!code.ok) return code;
|
|
3617
|
+
if (!SIGN_IN_CODE_SYNTAX.test(code.value)) {
|
|
3618
|
+
return invalidValue3("code", "must be exactly six digits");
|
|
3619
|
+
}
|
|
3620
|
+
return ok3({ email: email.value, account_type: accountType.value, code: code.value });
|
|
3621
|
+
}
|
|
3622
|
+
function validateEmailSignInSent(value, options) {
|
|
3623
|
+
return withResponseOptions(value, options, () => validateEmailSignInSentShape(value));
|
|
3624
|
+
}
|
|
3625
|
+
function validateEmailSignInSentShape(value) {
|
|
3626
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3627
|
+
const status = expectLiteral(value.status, ["sent"], "status");
|
|
3628
|
+
if (!status.ok) return status;
|
|
3629
|
+
const resendAfter = expectNonNegativeInteger(value.resend_after_seconds, "resend_after_seconds");
|
|
3630
|
+
if (!resendAfter.ok) return resendAfter;
|
|
3631
|
+
return ok3({ status: status.value, resend_after_seconds: resendAfter.value });
|
|
3632
|
+
}
|
|
3633
|
+
function validateEmailSignInCompleted(value, options) {
|
|
3634
|
+
return withResponseOptions(value, options, () => validateEmailSignInCompletedShape(value));
|
|
3635
|
+
}
|
|
3636
|
+
function validateEmailSignInCompletedShape(value) {
|
|
3637
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3638
|
+
const status = expectLiteral(value.status, ["signed_in"], "status");
|
|
3639
|
+
if (!status.ok) return status;
|
|
3640
|
+
const accountType = expectLiteral(
|
|
3641
|
+
value.account_type,
|
|
3642
|
+
EMAIL_SIGN_IN_ACCOUNT_TYPES,
|
|
3643
|
+
"account_type"
|
|
3644
|
+
);
|
|
3645
|
+
if (!accountType.ok) return accountType;
|
|
3646
|
+
const registered = expectBoolean(value.registered, "registered");
|
|
3647
|
+
if (!registered.ok) return registered;
|
|
3648
|
+
const phoneRequired = expectBoolean(
|
|
3649
|
+
value.phone_verification_required,
|
|
3650
|
+
"phone_verification_required"
|
|
3651
|
+
);
|
|
3652
|
+
if (!phoneRequired.ok) return phoneRequired;
|
|
3653
|
+
return ok3({
|
|
3654
|
+
status: status.value,
|
|
3655
|
+
account_type: accountType.value,
|
|
3656
|
+
registered: registered.value,
|
|
3657
|
+
phone_verification_required: phoneRequired.value
|
|
3658
|
+
});
|
|
3659
|
+
}
|
|
3660
|
+
var PHONE_NUMBER_MAX_LENGTH = 32;
|
|
3661
|
+
var PHONE_CODE_SYNTAX = /^[0-9]{6}$/;
|
|
3662
|
+
function expectPhoneNumber(value, param) {
|
|
3663
|
+
const text = expectString(value, param);
|
|
3664
|
+
if (!text.ok) return text;
|
|
3665
|
+
if (text.value.length > PHONE_NUMBER_MAX_LENGTH) {
|
|
3666
|
+
return invalidValue3(param, `must be at most ${PHONE_NUMBER_MAX_LENGTH} characters`);
|
|
3667
|
+
}
|
|
3668
|
+
return text;
|
|
3669
|
+
}
|
|
3670
|
+
function validatePhoneVerificationSendRequest(value) {
|
|
3671
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3672
|
+
const rejected = rejectUnknownKeys(value, ["phone_number", "turnstile_token"]);
|
|
3673
|
+
if (!rejected.ok) return rejected;
|
|
3674
|
+
const phoneNumber = expectPhoneNumber(value.phone_number, "phone_number");
|
|
3675
|
+
if (!phoneNumber.ok) return phoneNumber;
|
|
3676
|
+
return ok3({
|
|
3677
|
+
phone_number: phoneNumber.value,
|
|
3678
|
+
turnstile_token: readTurnstileToken(value)
|
|
3679
|
+
});
|
|
3680
|
+
}
|
|
3681
|
+
function validatePhoneVerificationVerifyRequest(value) {
|
|
3682
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3683
|
+
const rejected = rejectUnknownKeys(value, ["phone_number", "code"]);
|
|
3684
|
+
if (!rejected.ok) return rejected;
|
|
3685
|
+
const phoneNumber = expectPhoneNumber(value.phone_number, "phone_number");
|
|
3686
|
+
if (!phoneNumber.ok) return phoneNumber;
|
|
3687
|
+
const code = expectString(value.code, "code");
|
|
3688
|
+
if (!code.ok) return code;
|
|
3689
|
+
if (!PHONE_CODE_SYNTAX.test(code.value)) {
|
|
3690
|
+
return invalidValue3("code", "must be exactly six digits");
|
|
3691
|
+
}
|
|
3692
|
+
return ok3({ phone_number: phoneNumber.value, code: code.value });
|
|
3693
|
+
}
|
|
3694
|
+
function validatePhoneVerificationSent(value, options) {
|
|
3695
|
+
return withResponseOptions(value, options, () => validatePhoneVerificationSentShape(value));
|
|
3696
|
+
}
|
|
3697
|
+
function validatePhoneVerificationSentShape(value) {
|
|
3698
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3699
|
+
const status = expectLiteral(value.status, ["sent"], "status");
|
|
3700
|
+
if (!status.ok) return status;
|
|
3701
|
+
const resendAfter = expectNonNegativeInteger(value.resend_after_seconds, "resend_after_seconds");
|
|
3702
|
+
if (!resendAfter.ok) return resendAfter;
|
|
3703
|
+
return ok3({ status: status.value, resend_after_seconds: resendAfter.value });
|
|
3704
|
+
}
|
|
3705
|
+
function validatePhoneVerificationCompleted(value, options) {
|
|
3706
|
+
return withResponseOptions(
|
|
3707
|
+
value,
|
|
3708
|
+
options,
|
|
3709
|
+
() => validatePhoneVerificationCompletedShape(value)
|
|
3710
|
+
);
|
|
3711
|
+
}
|
|
3712
|
+
function validatePhoneVerificationCompletedShape(value) {
|
|
3713
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3714
|
+
const status = expectLiteral(value.status, ["verified"], "status");
|
|
3715
|
+
if (!status.ok) return status;
|
|
3716
|
+
const registered = expectBoolean(value.registered, "registered");
|
|
3717
|
+
if (!registered.ok) return registered;
|
|
3718
|
+
return ok3({ status: status.value, registered: registered.value });
|
|
3719
|
+
}
|
|
3720
|
+
function validateRedeemGiftCodeResponse(value, options) {
|
|
3721
|
+
return validatePersonalDashboard(value, options);
|
|
3722
|
+
}
|
|
3723
|
+
var CLI_AUTHORIZATION_KINDS = ["login", "step_up"];
|
|
3724
|
+
var CLI_DEVICE_LABEL_MAX_LENGTH = 64;
|
|
3725
|
+
var CLI_USER_CODE_ALPHABET = "BCDFGHJKLMNPQRSTVWXZ";
|
|
3726
|
+
var CLI_USER_CODE_LENGTH = 8;
|
|
3727
|
+
function normalizeCliUserCode(value) {
|
|
3728
|
+
const compact = value.toUpperCase().replace(/[\s-]/g, "");
|
|
3729
|
+
if (compact.length !== CLI_USER_CODE_LENGTH) return null;
|
|
3730
|
+
for (const character of compact) {
|
|
3731
|
+
if (!CLI_USER_CODE_ALPHABET.includes(character)) return null;
|
|
3732
|
+
}
|
|
3733
|
+
return `${compact.slice(0, 4)}-${compact.slice(4)}`;
|
|
3734
|
+
}
|
|
3735
|
+
function expectCliUserCode(value, param) {
|
|
3736
|
+
if (typeof value !== "string" || normalizeCliUserCode(value) !== value) {
|
|
3737
|
+
return invalidValue3(param, "must be a XXXX-XXXX CLI user code");
|
|
3738
|
+
}
|
|
3739
|
+
return ok3(value);
|
|
3740
|
+
}
|
|
3741
|
+
function expectBusinessReference(value, param) {
|
|
3742
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
3743
|
+
const id = expectString(value.id, `${param}.id`);
|
|
3744
|
+
if (!id.ok) return id;
|
|
3745
|
+
const name = expectString(value.name, `${param}.name`);
|
|
3746
|
+
if (!name.ok) return name;
|
|
3747
|
+
return ok3({ id: id.value, name: name.value });
|
|
3748
|
+
}
|
|
3749
|
+
function validateStartCliAuthorizationRequest(value) {
|
|
3750
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3751
|
+
const unknown = rejectUnknownKeys(value, ["kind", "device_label"]);
|
|
3752
|
+
if (!unknown.ok) return unknown;
|
|
3753
|
+
const kind = expectLiteral(value.kind, CLI_AUTHORIZATION_KINDS, "kind");
|
|
3754
|
+
if (!kind.ok) return kind;
|
|
3755
|
+
const label = expectString(value.device_label, "device_label");
|
|
3756
|
+
if (!label.ok) return label;
|
|
3757
|
+
const trimmed = label.value.trim();
|
|
3758
|
+
const characters = Array.from(trimmed);
|
|
3759
|
+
if (characters.length === 0 || characters.length > CLI_DEVICE_LABEL_MAX_LENGTH || characters.some((character) => character <= "" || character === "\x7F")) {
|
|
3760
|
+
return invalidValue3(
|
|
3761
|
+
"device_label",
|
|
3762
|
+
`must be 1\u2013${CLI_DEVICE_LABEL_MAX_LENGTH} trimmed characters with no control character`
|
|
3763
|
+
);
|
|
3764
|
+
}
|
|
3765
|
+
return ok3({ kind: kind.value, device_label: trimmed });
|
|
3766
|
+
}
|
|
3767
|
+
function validateStartedCliAuthorization(value, options) {
|
|
3768
|
+
return withResponseOptions(value, options, () => {
|
|
3769
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3770
|
+
const deviceCode = expectString(value.device_code, "device_code");
|
|
3771
|
+
if (!deviceCode.ok) return deviceCode;
|
|
3772
|
+
if (deviceCode.value.length === 0) return invalidValue3("device_code", "must not be empty");
|
|
3773
|
+
const userCode = expectCliUserCode(value.user_code, "user_code");
|
|
3774
|
+
if (!userCode.ok) return userCode;
|
|
3775
|
+
const uri = expectString(value.verification_uri, "verification_uri");
|
|
3776
|
+
if (!uri.ok) return uri;
|
|
3777
|
+
const complete = expectString(value.verification_uri_complete, "verification_uri_complete");
|
|
3778
|
+
if (!complete.ok) return complete;
|
|
3779
|
+
const expiresIn = expectNonNegativeInteger(value.expires_in, "expires_in");
|
|
3780
|
+
if (!expiresIn.ok) return expiresIn;
|
|
3781
|
+
const interval = expectNonNegativeInteger(value.interval, "interval");
|
|
3782
|
+
if (!interval.ok) return interval;
|
|
3783
|
+
return ok3({
|
|
3784
|
+
device_code: deviceCode.value,
|
|
3785
|
+
user_code: userCode.value,
|
|
3786
|
+
verification_uri: uri.value,
|
|
3787
|
+
verification_uri_complete: complete.value,
|
|
3788
|
+
expires_in: expiresIn.value,
|
|
3789
|
+
interval: interval.value
|
|
3790
|
+
});
|
|
3791
|
+
});
|
|
3792
|
+
}
|
|
3793
|
+
function validateCliTokenRequest(value) {
|
|
3794
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3795
|
+
const unknown = rejectUnknownKeys(value, ["device_code"]);
|
|
3796
|
+
if (!unknown.ok) return unknown;
|
|
3797
|
+
const deviceCode = expectString(value.device_code, "device_code");
|
|
3798
|
+
if (!deviceCode.ok) return deviceCode;
|
|
3799
|
+
if (deviceCode.value.length === 0 || deviceCode.value.length > 256) {
|
|
3800
|
+
return invalidValue3("device_code", "must be 1\u2013256 characters");
|
|
3801
|
+
}
|
|
3802
|
+
return ok3({ device_code: deviceCode.value });
|
|
3803
|
+
}
|
|
3804
|
+
function validateCliTokenGrant(value, options) {
|
|
3805
|
+
return withResponseOptions(value, options, () => {
|
|
3806
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3807
|
+
if (value.kind === "step_up") {
|
|
3808
|
+
const at = expectRfc33392(value.reauthenticated_at, "reauthenticated_at");
|
|
3809
|
+
if (!at.ok) return at;
|
|
3810
|
+
return ok3({ kind: "step_up", reauthenticated_at: at.value });
|
|
3811
|
+
}
|
|
3812
|
+
if (value.kind !== "login") return invalidValue3("kind", "must be one of: login, step_up");
|
|
3813
|
+
const token = expectString(value.token, "token");
|
|
3814
|
+
if (!token.ok) return token;
|
|
3815
|
+
if (token.value.length === 0) return invalidValue3("token", "must not be empty");
|
|
3816
|
+
const expiresAt = expectRfc33392(value.token_expires_at, "token_expires_at");
|
|
3817
|
+
if (!expiresAt.ok) return expiresAt;
|
|
3818
|
+
const credentialId = expectString(value.credential_id, "credential_id");
|
|
3819
|
+
if (!credentialId.ok) return credentialId;
|
|
3820
|
+
const business = expectBusinessReference(value.business, "business");
|
|
3821
|
+
if (!business.ok) return business;
|
|
3822
|
+
if (!isPlainObject4(value.login)) return invalidValue3("login", "must be an object");
|
|
3823
|
+
const email = expectString(value.login.email, "login.email");
|
|
3824
|
+
if (!email.ok) return email;
|
|
3825
|
+
return ok3({
|
|
3826
|
+
kind: "login",
|
|
3827
|
+
token: token.value,
|
|
3828
|
+
token_expires_at: expiresAt.value,
|
|
3829
|
+
credential_id: credentialId.value,
|
|
3830
|
+
business: business.value,
|
|
3831
|
+
login: { email: email.value }
|
|
3832
|
+
});
|
|
3833
|
+
});
|
|
3834
|
+
}
|
|
3835
|
+
function validateCliAuthorizationView(value, options) {
|
|
3836
|
+
return withResponseOptions(value, options, () => {
|
|
3837
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3838
|
+
const userCode = expectCliUserCode(value.user_code, "user_code");
|
|
3839
|
+
if (!userCode.ok) return userCode;
|
|
3840
|
+
const kind = expectLiteral(value.kind, CLI_AUTHORIZATION_KINDS, "kind");
|
|
3841
|
+
if (!kind.ok) return kind;
|
|
3842
|
+
const label = expectString(value.device_label, "device_label");
|
|
3843
|
+
if (!label.ok) return label;
|
|
3844
|
+
const expiresAt = expectRfc33392(value.expires_at, "expires_at");
|
|
3845
|
+
if (!expiresAt.ok) return expiresAt;
|
|
3846
|
+
const business = value.business === null ? ok3(null) : expectBusinessReference(value.business, "business");
|
|
3847
|
+
if (!business.ok) return business;
|
|
3848
|
+
return ok3({
|
|
3849
|
+
user_code: userCode.value,
|
|
3850
|
+
kind: kind.value,
|
|
3851
|
+
device_label: label.value,
|
|
3852
|
+
expires_at: expiresAt.value,
|
|
3853
|
+
business: business.value
|
|
3854
|
+
});
|
|
3855
|
+
});
|
|
3856
|
+
}
|
|
3857
|
+
function validateCliCredentialSummary(value, param) {
|
|
3858
|
+
if (!isPlainObject4(value)) return invalidValue3(param, "must be an object");
|
|
3859
|
+
if ("token" in value || "token_hash" in value) {
|
|
3860
|
+
return invalidValue3(param, "must not carry a token");
|
|
3861
|
+
}
|
|
3862
|
+
const id = expectString(value.id, `${param}.id`);
|
|
3863
|
+
if (!id.ok) return id;
|
|
3864
|
+
const label = expectString(value.device_label, `${param}.device_label`);
|
|
3865
|
+
if (!label.ok) return label;
|
|
3866
|
+
const business = expectBusinessReference(value.business, `${param}.business`);
|
|
3867
|
+
if (!business.ok) return business;
|
|
3868
|
+
const approvedAt = expectRfc33392(value.approved_at, `${param}.approved_at`);
|
|
3869
|
+
if (!approvedAt.ok) return approvedAt;
|
|
3870
|
+
const lastUsedAt = expectNullableRfc3339(value.last_used_at, `${param}.last_used_at`);
|
|
3871
|
+
if (!lastUsedAt.ok) return lastUsedAt;
|
|
3872
|
+
const expiresAt = expectRfc33392(value.expires_at, `${param}.expires_at`);
|
|
3873
|
+
if (!expiresAt.ok) return expiresAt;
|
|
3874
|
+
return ok3({
|
|
3875
|
+
id: id.value,
|
|
3876
|
+
device_label: label.value,
|
|
3877
|
+
business: business.value,
|
|
3878
|
+
approved_at: approvedAt.value,
|
|
3879
|
+
last_used_at: lastUsedAt.value,
|
|
3880
|
+
expires_at: expiresAt.value
|
|
3881
|
+
});
|
|
3882
|
+
}
|
|
3883
|
+
function validateCliCredentialList(value, options) {
|
|
3884
|
+
return withResponseOptions(value, options, () => {
|
|
3885
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
3886
|
+
if (!Array.isArray(value.credentials)) return invalidValue3("credentials", "must be an array");
|
|
3887
|
+
const credentials = [];
|
|
3888
|
+
for (const [index, item] of value.credentials.entries()) {
|
|
3889
|
+
const credential = validateCliCredentialSummary(item, `credentials[${index}]`);
|
|
3890
|
+
if (!credential.ok) return credential;
|
|
3891
|
+
credentials.push(credential.value);
|
|
3892
|
+
}
|
|
3893
|
+
return ok3({ credentials });
|
|
3894
|
+
});
|
|
3895
|
+
}
|
|
3896
|
+
function validateBusinessKeyListQuery(query) {
|
|
3897
|
+
const scopeRaw = query.scope ?? void 0;
|
|
3898
|
+
const applicationRaw = query.application_id ?? void 0;
|
|
3899
|
+
let scope;
|
|
3900
|
+
if (scopeRaw !== void 0) {
|
|
3901
|
+
if (scopeRaw !== "model" && scopeRaw !== "reporting") {
|
|
3902
|
+
return invalidValue3("scope", "must be one of: model, reporting");
|
|
3903
|
+
}
|
|
3904
|
+
scope = scopeRaw;
|
|
3905
|
+
}
|
|
3906
|
+
if (applicationRaw?.length === 0) {
|
|
3907
|
+
return invalidValue3("application_id", "must not be empty");
|
|
3908
|
+
}
|
|
3909
|
+
if (applicationRaw !== void 0 && scope === "reporting") {
|
|
3910
|
+
return invalidValue3("application_id", "must be absent when scope is reporting");
|
|
3911
|
+
}
|
|
3912
|
+
return ok3({
|
|
3913
|
+
...scope === void 0 ? {} : { scope },
|
|
3914
|
+
...applicationRaw === void 0 ? {} : { application_id: applicationRaw }
|
|
3915
|
+
});
|
|
3916
|
+
}
|
|
3917
|
+
|
|
3918
|
+
// src/response-stream.ts
|
|
3919
|
+
var RESPONSE_STREAM_EVENT_TYPES = Object.freeze({
|
|
3920
|
+
"response.created": Object.freeze({ terminal: false }),
|
|
3921
|
+
"response.in_progress": Object.freeze({ terminal: false }),
|
|
3922
|
+
"response.output_item.added": Object.freeze({ terminal: false }),
|
|
3923
|
+
"response.output_item.done": Object.freeze({ terminal: false }),
|
|
3924
|
+
"response.content_part.added": Object.freeze({ terminal: false }),
|
|
3925
|
+
"response.content_part.done": Object.freeze({ terminal: false }),
|
|
3926
|
+
"response.output_text.delta": Object.freeze({ terminal: false }),
|
|
3927
|
+
"response.output_text.done": Object.freeze({ terminal: false }),
|
|
3928
|
+
"response.function_call_arguments.delta": Object.freeze({ terminal: false }),
|
|
3929
|
+
"response.function_call_arguments.done": Object.freeze({ terminal: false }),
|
|
3930
|
+
"response.completed": Object.freeze({ terminal: true }),
|
|
3931
|
+
"response.incomplete": Object.freeze({ terminal: true }),
|
|
3932
|
+
"response.failed": Object.freeze({ terminal: true })
|
|
3933
|
+
});
|
|
3934
|
+
var RESPONSE_STREAM_EVENT_TYPE_NAMES = Object.freeze(
|
|
3935
|
+
Object.keys(RESPONSE_STREAM_EVENT_TYPES)
|
|
3936
|
+
);
|
|
3937
|
+
function isResponseStreamEventType(value) {
|
|
3938
|
+
return typeof value === "string" && Object.hasOwn(RESPONSE_STREAM_EVENT_TYPES, value);
|
|
3939
|
+
}
|
|
3940
|
+
function isTerminalResponseStreamEventType(type) {
|
|
3941
|
+
return RESPONSE_STREAM_EVENT_TYPES[type].terminal;
|
|
3942
|
+
}
|
|
3943
|
+
function ok4(value) {
|
|
3944
|
+
return { ok: true, value };
|
|
3945
|
+
}
|
|
3946
|
+
function invalidValue4(param, message) {
|
|
3947
|
+
return { ok: false, error: { code: ENLITT_ERROR_CODE.invalid_value, param, message } };
|
|
3948
|
+
}
|
|
3949
|
+
function unsupportedValue3(param, message) {
|
|
3950
|
+
return { ok: false, error: { code: ENLITT_ERROR_CODE.unsupported_value, param, message } };
|
|
3951
|
+
}
|
|
3952
|
+
function isPlainObject5(value) {
|
|
3953
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3954
|
+
}
|
|
3955
|
+
function validateSequenceNumber(value, param) {
|
|
3956
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
|
|
3957
|
+
return invalidValue4(param, "must be a nonnegative integer");
|
|
3958
|
+
}
|
|
3959
|
+
return ok4(value);
|
|
3960
|
+
}
|
|
3961
|
+
function validateStringField(value, param) {
|
|
3962
|
+
if (typeof value !== "string") return invalidValue4(param, "must be a string");
|
|
3963
|
+
return ok4(value);
|
|
3964
|
+
}
|
|
3965
|
+
function validateIntegerField(value, param) {
|
|
3966
|
+
if (typeof value !== "number" || !Number.isInteger(value)) return invalidValue4(param, "must be an integer");
|
|
3967
|
+
return ok4(value);
|
|
3968
|
+
}
|
|
3969
|
+
function isTolerant2(options) {
|
|
3970
|
+
return options?.mode === "tolerant";
|
|
3971
|
+
}
|
|
3972
|
+
function validateOnlyEventKeys(value, allowed, options) {
|
|
3973
|
+
if (isTolerant2(options)) return ok4(void 0);
|
|
3974
|
+
for (const key of Object.keys(value)) {
|
|
3975
|
+
if (!allowed.includes(key)) return invalidValue4(key, `unknown stream event field "${key}"`);
|
|
3976
|
+
}
|
|
3977
|
+
return ok4(void 0);
|
|
3978
|
+
}
|
|
3979
|
+
function validateResponseStreamEvent(value, options) {
|
|
3980
|
+
if (!isPlainObject5(value)) return invalidValue4("body", "stream event must be a JSON object");
|
|
3981
|
+
const type = value.type;
|
|
3982
|
+
if (typeof type !== "string") return invalidValue4("type", "must be a string");
|
|
3983
|
+
const sequenceResult = validateSequenceNumber(value.sequence_number, "sequence_number");
|
|
3984
|
+
if (!sequenceResult.ok) return sequenceResult;
|
|
3985
|
+
const sequence_number = sequenceResult.value;
|
|
3986
|
+
if (!isResponseStreamEventType(type)) {
|
|
3987
|
+
if (type.length > 64) return invalidValue4("type", "must not exceed 64 characters");
|
|
3988
|
+
if (isTolerant2(options)) return ok4({ unknown: true, type, sequence_number });
|
|
3989
|
+
return unsupportedValue3("type", `unknown stream event type "${type}"`);
|
|
3990
|
+
}
|
|
3991
|
+
switch (type) {
|
|
3992
|
+
case "response.created":
|
|
3993
|
+
case "response.in_progress":
|
|
3994
|
+
case "response.completed":
|
|
3995
|
+
case "response.incomplete":
|
|
3996
|
+
case "response.failed": {
|
|
3997
|
+
const keysResult = validateOnlyEventKeys(value, ["type", "sequence_number", "response"], options);
|
|
3998
|
+
if (!keysResult.ok) return keysResult;
|
|
3999
|
+
const responseResult = validateOpenAIResponse(value.response, options);
|
|
4000
|
+
if (!responseResult.ok) return responseResult;
|
|
4001
|
+
return ok4({ type, sequence_number, response: responseResult.value });
|
|
4002
|
+
}
|
|
4003
|
+
case "response.output_item.added":
|
|
4004
|
+
case "response.output_item.done": {
|
|
4005
|
+
const keysResult = validateOnlyEventKeys(value, ["type", "sequence_number", "output_index", "item"], options);
|
|
4006
|
+
if (!keysResult.ok) return keysResult;
|
|
4007
|
+
const outputIndexResult = validateIntegerField(value.output_index, "output_index");
|
|
4008
|
+
if (!outputIndexResult.ok) return outputIndexResult;
|
|
4009
|
+
const itemResult = validateResponseOutputItem(value.item, "item", options);
|
|
4010
|
+
if (!itemResult.ok) return itemResult;
|
|
4011
|
+
return ok4({
|
|
4012
|
+
type,
|
|
4013
|
+
sequence_number,
|
|
4014
|
+
output_index: outputIndexResult.value,
|
|
4015
|
+
item: itemResult.value
|
|
4016
|
+
});
|
|
4017
|
+
}
|
|
4018
|
+
case "response.content_part.added":
|
|
4019
|
+
case "response.content_part.done": {
|
|
4020
|
+
const keysResult = validateOnlyEventKeys(
|
|
4021
|
+
value,
|
|
4022
|
+
["type", "sequence_number", "item_id", "output_index", "content_index", "part"],
|
|
4023
|
+
options
|
|
4024
|
+
);
|
|
4025
|
+
if (!keysResult.ok) return keysResult;
|
|
4026
|
+
const itemIdResult = validateStringField(value.item_id, "item_id");
|
|
4027
|
+
if (!itemIdResult.ok) return itemIdResult;
|
|
4028
|
+
const outputIndexResult = validateIntegerField(value.output_index, "output_index");
|
|
4029
|
+
if (!outputIndexResult.ok) return outputIndexResult;
|
|
4030
|
+
const contentIndexResult = validateIntegerField(value.content_index, "content_index");
|
|
4031
|
+
if (!contentIndexResult.ok) return contentIndexResult;
|
|
4032
|
+
const partResult = validateOutputTextPart(value.part, "part", options);
|
|
4033
|
+
if (!partResult.ok) return partResult;
|
|
4034
|
+
return ok4({
|
|
4035
|
+
type,
|
|
4036
|
+
sequence_number,
|
|
4037
|
+
item_id: itemIdResult.value,
|
|
4038
|
+
output_index: outputIndexResult.value,
|
|
4039
|
+
content_index: contentIndexResult.value,
|
|
4040
|
+
part: partResult.value
|
|
4041
|
+
});
|
|
4042
|
+
}
|
|
4043
|
+
case "response.output_text.delta": {
|
|
4044
|
+
const keysResult = validateOnlyEventKeys(
|
|
4045
|
+
value,
|
|
4046
|
+
["type", "sequence_number", "item_id", "output_index", "content_index", "delta"],
|
|
4047
|
+
options
|
|
4048
|
+
);
|
|
4049
|
+
if (!keysResult.ok) return keysResult;
|
|
4050
|
+
const itemIdResult = validateStringField(value.item_id, "item_id");
|
|
4051
|
+
if (!itemIdResult.ok) return itemIdResult;
|
|
4052
|
+
const outputIndexResult = validateIntegerField(value.output_index, "output_index");
|
|
4053
|
+
if (!outputIndexResult.ok) return outputIndexResult;
|
|
4054
|
+
const contentIndexResult = validateIntegerField(value.content_index, "content_index");
|
|
4055
|
+
if (!contentIndexResult.ok) return contentIndexResult;
|
|
4056
|
+
const deltaResult = validateStringField(value.delta, "delta");
|
|
4057
|
+
if (!deltaResult.ok) return deltaResult;
|
|
4058
|
+
return ok4({
|
|
4059
|
+
type,
|
|
4060
|
+
sequence_number,
|
|
4061
|
+
item_id: itemIdResult.value,
|
|
4062
|
+
output_index: outputIndexResult.value,
|
|
4063
|
+
content_index: contentIndexResult.value,
|
|
4064
|
+
delta: deltaResult.value
|
|
4065
|
+
});
|
|
4066
|
+
}
|
|
4067
|
+
case "response.output_text.done": {
|
|
4068
|
+
const keysResult = validateOnlyEventKeys(
|
|
4069
|
+
value,
|
|
4070
|
+
["type", "sequence_number", "item_id", "output_index", "content_index", "text"],
|
|
4071
|
+
options
|
|
4072
|
+
);
|
|
4073
|
+
if (!keysResult.ok) return keysResult;
|
|
4074
|
+
const itemIdResult = validateStringField(value.item_id, "item_id");
|
|
4075
|
+
if (!itemIdResult.ok) return itemIdResult;
|
|
4076
|
+
const outputIndexResult = validateIntegerField(value.output_index, "output_index");
|
|
4077
|
+
if (!outputIndexResult.ok) return outputIndexResult;
|
|
4078
|
+
const contentIndexResult = validateIntegerField(value.content_index, "content_index");
|
|
4079
|
+
if (!contentIndexResult.ok) return contentIndexResult;
|
|
4080
|
+
const textResult = validateStringField(value.text, "text");
|
|
4081
|
+
if (!textResult.ok) return textResult;
|
|
4082
|
+
return ok4({
|
|
4083
|
+
type,
|
|
4084
|
+
sequence_number,
|
|
4085
|
+
item_id: itemIdResult.value,
|
|
4086
|
+
output_index: outputIndexResult.value,
|
|
4087
|
+
content_index: contentIndexResult.value,
|
|
4088
|
+
text: textResult.value
|
|
4089
|
+
});
|
|
4090
|
+
}
|
|
4091
|
+
case "response.function_call_arguments.delta": {
|
|
4092
|
+
const keysResult = validateOnlyEventKeys(
|
|
4093
|
+
value,
|
|
4094
|
+
["type", "sequence_number", "item_id", "output_index", "delta"],
|
|
4095
|
+
options
|
|
4096
|
+
);
|
|
4097
|
+
if (!keysResult.ok) return keysResult;
|
|
4098
|
+
const itemIdResult = validateStringField(value.item_id, "item_id");
|
|
4099
|
+
if (!itemIdResult.ok) return itemIdResult;
|
|
4100
|
+
const outputIndexResult = validateIntegerField(value.output_index, "output_index");
|
|
4101
|
+
if (!outputIndexResult.ok) return outputIndexResult;
|
|
4102
|
+
const deltaResult = validateStringField(value.delta, "delta");
|
|
4103
|
+
if (!deltaResult.ok) return deltaResult;
|
|
4104
|
+
return ok4({
|
|
4105
|
+
type,
|
|
4106
|
+
sequence_number,
|
|
4107
|
+
item_id: itemIdResult.value,
|
|
4108
|
+
output_index: outputIndexResult.value,
|
|
4109
|
+
delta: deltaResult.value
|
|
4110
|
+
});
|
|
4111
|
+
}
|
|
4112
|
+
case "response.function_call_arguments.done": {
|
|
4113
|
+
const keysResult = validateOnlyEventKeys(
|
|
4114
|
+
value,
|
|
4115
|
+
["type", "sequence_number", "item_id", "output_index", "arguments"],
|
|
4116
|
+
options
|
|
4117
|
+
);
|
|
4118
|
+
if (!keysResult.ok) return keysResult;
|
|
4119
|
+
const itemIdResult = validateStringField(value.item_id, "item_id");
|
|
4120
|
+
if (!itemIdResult.ok) return itemIdResult;
|
|
4121
|
+
const outputIndexResult = validateIntegerField(value.output_index, "output_index");
|
|
4122
|
+
if (!outputIndexResult.ok) return outputIndexResult;
|
|
4123
|
+
const argsResult = validateStringField(value.arguments, "arguments");
|
|
4124
|
+
if (!argsResult.ok) return argsResult;
|
|
4125
|
+
return ok4({
|
|
4126
|
+
type,
|
|
4127
|
+
sequence_number,
|
|
4128
|
+
item_id: itemIdResult.value,
|
|
4129
|
+
output_index: outputIndexResult.value,
|
|
4130
|
+
arguments: argsResult.value
|
|
4131
|
+
});
|
|
4132
|
+
}
|
|
4133
|
+
}
|
|
4134
|
+
}
|
|
4135
|
+
function checkResponseStreamOrdering(events) {
|
|
4136
|
+
if (events.length === 0 || events[0]?.type !== "response.created") {
|
|
4137
|
+
return { ok: false, violation: { kind: "missing_first_created" } };
|
|
4138
|
+
}
|
|
4139
|
+
let lastSequenceNumber = -Infinity;
|
|
4140
|
+
let sawTerminal = false;
|
|
4141
|
+
for (const [index, event] of events.entries()) {
|
|
4142
|
+
if (sawTerminal) {
|
|
4143
|
+
return { ok: false, violation: { kind: "event_after_terminal", index } };
|
|
4144
|
+
}
|
|
4145
|
+
if (event.sequence_number <= lastSequenceNumber) {
|
|
4146
|
+
return { ok: false, violation: { kind: "non_monotonic_sequence", index } };
|
|
4147
|
+
}
|
|
4148
|
+
lastSequenceNumber = event.sequence_number;
|
|
4149
|
+
if (isResponseStreamEventType(event.type) && isTerminalResponseStreamEventType(event.type)) {
|
|
4150
|
+
sawTerminal = true;
|
|
4151
|
+
}
|
|
4152
|
+
}
|
|
4153
|
+
if (!sawTerminal) {
|
|
4154
|
+
return { ok: false, violation: { kind: "missing_terminal" } };
|
|
4155
|
+
}
|
|
4156
|
+
return { ok: true };
|
|
4157
|
+
}
|
|
4158
|
+
|
|
4159
|
+
// src/contract.ts
|
|
4160
|
+
var WIRE_CONTRACT_FORMAT = 1;
|
|
4161
|
+
var WIRE_CLOSED_SETS = Object.freeze({
|
|
4162
|
+
"api_key.scope": API_KEY_SCOPES,
|
|
4163
|
+
"api_key.status": API_KEY_STATUSES,
|
|
4164
|
+
"application.environment": APPLICATION_ENVIRONMENTS,
|
|
4165
|
+
"application.status": APPLICATION_STATUSES,
|
|
4166
|
+
"cli_authorization.kind": CLI_AUTHORIZATION_KINDS,
|
|
4167
|
+
"contact.type": CONTACT_TYPES,
|
|
4168
|
+
"email_sign_in.account_type": EMAIL_SIGN_IN_ACCOUNT_TYPES,
|
|
4169
|
+
"order.kind": ORDER_KINDS,
|
|
4170
|
+
"order.refund.eligibility": REFUND_ELIGIBILITY,
|
|
4171
|
+
"order.refund.reason": REFUND_REASONS,
|
|
4172
|
+
"order.status": ORDER_STATUSES,
|
|
4173
|
+
"payout.blocked_reason": PAYOUT_BLOCKED_REASONS,
|
|
4174
|
+
"payout.connected_account_status": CONNECTED_ACCOUNT_STATUSES,
|
|
4175
|
+
"personal_application_call.credit_type": PERSONAL_APPLICATION_CALL_CREDIT_TYPES,
|
|
4176
|
+
"personal_application_call.sort": PERSONAL_APPLICATION_CALL_SORTS,
|
|
4177
|
+
"personal_application_call.status": PERSONAL_APPLICATION_CALL_STATUSES,
|
|
4178
|
+
"plan.interval": PLAN_INTERVALS,
|
|
4179
|
+
"premium_operation.billing": PREMIUM_OPERATION_BILLING_VALUES,
|
|
4180
|
+
"premium_terminal.status": PREMIUM_TERMINAL_STATUSES,
|
|
4181
|
+
"response.incomplete_details.reason": RESPONSE_INCOMPLETE_REASONS,
|
|
4182
|
+
"response.output_item.status": RESPONSE_ITEM_STATUSES,
|
|
4183
|
+
"response.status": RESPONSE_STATUSES,
|
|
4184
|
+
"response_stream.type": RESPONSE_STREAM_EVENT_TYPE_NAMES,
|
|
4185
|
+
"subscription.change_mode": CHANGE_MODES,
|
|
4186
|
+
"subscription.locked_downgrade": LOCKED_DOWNGRADE_MODES,
|
|
4187
|
+
"subscription.service_tier": SERVICE_TIERS,
|
|
4188
|
+
"subscription.status": SUBSCRIPTION_STATUSES
|
|
4189
|
+
});
|
|
4190
|
+
function buildWireContract() {
|
|
4191
|
+
return {
|
|
4192
|
+
contract_format: WIRE_CONTRACT_FORMAT,
|
|
4193
|
+
api_version: ENLITT_API_VERSION,
|
|
4194
|
+
version_header: ENLITT_VERSION_HEADER,
|
|
4195
|
+
unknown_enum_value: UNKNOWN_ENUM_VALUE,
|
|
4196
|
+
unrecognized_error_code: UNRECOGNIZED_ERROR_CODE,
|
|
4197
|
+
idempotency_key: {
|
|
4198
|
+
min_length: IDEMPOTENCY_KEY_MIN_LENGTH,
|
|
4199
|
+
max_length: IDEMPOTENCY_KEY_MAX_LENGTH,
|
|
4200
|
+
min_retention_days: IDEMPOTENCY_KEY_MIN_RETENTION_DAYS
|
|
4201
|
+
},
|
|
4202
|
+
error_types: ENLITT_ERROR_TYPES,
|
|
4203
|
+
error_codes: Object.fromEntries(Object.entries(ENLITT_ERROR_CODES).map(([code, definition2]) => [code, {
|
|
4204
|
+
type: definition2.type,
|
|
4205
|
+
http_status: definition2.status,
|
|
4206
|
+
retryable: definition2.retryable,
|
|
4207
|
+
retry_after: definition2.retryAfter,
|
|
4208
|
+
authorize_url: definition2.authorizeUrl,
|
|
4209
|
+
admissible_max_charge: definition2.admissibleMaxCharge,
|
|
4210
|
+
limit_rule: definition2.limitRule
|
|
4211
|
+
}])),
|
|
4212
|
+
closed_sets: WIRE_CLOSED_SETS
|
|
4213
|
+
};
|
|
4214
|
+
}
|
|
4215
|
+
function sortRecord(value) {
|
|
4216
|
+
return Object.fromEntries(Object.keys(value).sort().map((key) => [key, value[key]]));
|
|
4217
|
+
}
|
|
4218
|
+
function serializeWireContract(contract) {
|
|
4219
|
+
return `${JSON.stringify({ ...contract, error_codes: sortRecord(contract.error_codes), closed_sets: sortRecord(contract.closed_sets) }, null, 2)}
|
|
4220
|
+
`;
|
|
4221
|
+
}
|
|
4222
|
+
var FIXTURE_ENDPOINTS = Object.freeze({
|
|
4223
|
+
"create-response": { method: "POST", path: "/v1/responses", validateRequest: validateEnlittStandardRequest, validateResponse: validateOpenAIResponse },
|
|
4224
|
+
"begin-operation": { method: "POST", path: "/v1/enlitt/operations", validateRequest: validateBeginPremiumOperationRequest, validateResponse: validateBeginPremiumOperationResponse },
|
|
4225
|
+
"report-terminal": { method: "POST", path: "/v1/enlitt/operations/{operation_id}/terminal", validateRequest: validateReportPremiumTerminalRequest, validateResponse: validateReportPremiumTerminalResponse },
|
|
4226
|
+
usage: { method: "GET", path: "/v1/enlitt/usage", validateRequest: null, validateResponse: validateUsageResponse },
|
|
4227
|
+
"business-info": { method: "GET", path: "/v1/business/info", validateRequest: null, validateResponse: validateBusinessDashboardInfo }
|
|
4228
|
+
});
|
|
4229
|
+
|
|
4230
|
+
// src/admin.ts
|
|
4231
|
+
var ADMIN_READ_COMMANDS = [
|
|
4232
|
+
"inspect.user",
|
|
4233
|
+
"inspect.business",
|
|
4234
|
+
"inspect.app",
|
|
4235
|
+
"inspect.order",
|
|
4236
|
+
"inspect.call",
|
|
4237
|
+
"inspect.txn",
|
|
4238
|
+
"sql",
|
|
4239
|
+
"log",
|
|
4240
|
+
"report.platform"
|
|
4241
|
+
];
|
|
4242
|
+
var ADMIN_WRITE_COMMANDS = [
|
|
4243
|
+
"refund.cash",
|
|
4244
|
+
"refund.manual",
|
|
4245
|
+
"refund.mark_paid",
|
|
4246
|
+
"refund.cancel_manual",
|
|
4247
|
+
"credits.grant",
|
|
4248
|
+
"plan.set",
|
|
4249
|
+
"plan.reset",
|
|
4250
|
+
"status.suspend",
|
|
4251
|
+
"status.unsuspend",
|
|
4252
|
+
"payout.block",
|
|
4253
|
+
"payout.unblock",
|
|
4254
|
+
"payout.create",
|
|
4255
|
+
"payout.execute",
|
|
4256
|
+
"gift.create",
|
|
4257
|
+
"gift.revoke",
|
|
4258
|
+
"account.set_email",
|
|
4259
|
+
"account.release_phone",
|
|
4260
|
+
"account.set_app_limits",
|
|
4261
|
+
"account.set_default_limit"
|
|
4262
|
+
];
|
|
4263
|
+
var ADMIN_COMMAND_NAMES = [...ADMIN_READ_COMMANDS, ...ADMIN_WRITE_COMMANDS];
|
|
4264
|
+
var ADMIN_ACTION_KINDS = ["read", "write"];
|
|
4265
|
+
var ADMIN_ACTION_STATUSES = ["started", "succeeded", "failed"];
|
|
4266
|
+
var ADMIN_SUBJECTS = ["user", "business", "app"];
|
|
4267
|
+
var ADMIN_REASON_MAX_LENGTH = 1e3;
|
|
4268
|
+
var ADMIN_SQL_MAX_LENGTH = 2e4;
|
|
4269
|
+
var ADMIN_SQL_MAX_LIMIT = 1e3;
|
|
4270
|
+
var ADMIN_LOG_MAX_LIMIT = 200;
|
|
4271
|
+
var ADMIN_SUSPEND_MAX_DAYS = 3650;
|
|
4272
|
+
var ADMIN_REPORT_MAX_DAYS = 90;
|
|
4273
|
+
var ADMIN_REPORT_DEFAULT_DAYS = 7;
|
|
4274
|
+
var PLATFORM_REPORT_UNITS = ["count", "nano_usd", "usd_cents", "milli_credits"];
|
|
4275
|
+
var ADMIN_REQUEST_MAX_BYTES = 64 * 1024;
|
|
4276
|
+
function isAdminCommandName(value) {
|
|
4277
|
+
return typeof value === "string" && ADMIN_COMMAND_NAMES.includes(value);
|
|
4278
|
+
}
|
|
4279
|
+
function adminCommandKind(command) {
|
|
4280
|
+
return ADMIN_READ_COMMANDS.includes(command) ? "read" : "write";
|
|
4281
|
+
}
|
|
4282
|
+
var lenient = false;
|
|
4283
|
+
function ok5(value) {
|
|
4284
|
+
return { ok: true, value };
|
|
4285
|
+
}
|
|
4286
|
+
function fail3(code, param, message) {
|
|
4287
|
+
return { ok: false, error: { code, param, message } };
|
|
4288
|
+
}
|
|
4289
|
+
function invalid2(param, message) {
|
|
4290
|
+
return fail3(ENLITT_ERROR_CODE.invalid_value, param, message);
|
|
4291
|
+
}
|
|
4292
|
+
function isObject2(value) {
|
|
4293
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4294
|
+
}
|
|
4295
|
+
var RFC3339 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|z|[+-]\d{2}:\d{2})$/;
|
|
4296
|
+
var UUID = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
4297
|
+
var str = (max = 512) => (value, param) => {
|
|
4298
|
+
if (typeof value !== "string") return invalid2(param, "must be a string");
|
|
4299
|
+
if (value.length < 1 || value.length > max)
|
|
4300
|
+
return invalid2(param, `must be 1 to ${max} characters`);
|
|
4301
|
+
return ok5(value);
|
|
4302
|
+
};
|
|
4303
|
+
var amount = (value, param) => isCanonicalIntegerString(value) ? ok5(value) : invalid2(param, "must be a canonical base-10 integer string");
|
|
4304
|
+
var positiveAmount = (value, param) => {
|
|
4305
|
+
const parsed = amount(value, param);
|
|
4306
|
+
if (!parsed.ok) return parsed;
|
|
4307
|
+
return BigInt(parsed.value) > 0n ? parsed : invalid2(param, "must be strictly positive");
|
|
4308
|
+
};
|
|
4309
|
+
var rfc3339 = (value, param) => typeof value === "string" && RFC3339.test(value) ? ok5(value) : invalid2(param, "must be an RFC 3339 timestamp");
|
|
4310
|
+
var bool = (value, param) => typeof value === "boolean" ? ok5(value) : invalid2(param, "must be a boolean");
|
|
4311
|
+
var intRange = (min, max) => (value, param) => {
|
|
4312
|
+
if (typeof value !== "number" || !Number.isInteger(value))
|
|
4313
|
+
return invalid2(param, "must be an integer");
|
|
4314
|
+
if (value < min || value > max) return invalid2(param, `must be between ${min} and ${max}`);
|
|
4315
|
+
return ok5(value);
|
|
4316
|
+
};
|
|
4317
|
+
var oneOf = (options) => (value, param) => {
|
|
4318
|
+
if (typeof value === "string") {
|
|
4319
|
+
if (options.includes(value)) return ok5(value);
|
|
4320
|
+
if (lenient) return ok5(UNKNOWN_ENUM_VALUE);
|
|
4321
|
+
}
|
|
4322
|
+
return invalid2(param, `must be one of: ${options.join(", ")}`);
|
|
4323
|
+
};
|
|
4324
|
+
var exactly = (expected) => (value, param) => value === expected ? ok5(expected) : invalid2(param, `must be ${JSON.stringify(expected)}`);
|
|
4325
|
+
var nullable = (inner) => (value, param) => value === null ? ok5(null) : inner(value, param);
|
|
4326
|
+
var optional = (inner) => ({ optional: inner });
|
|
4327
|
+
var object = (members) => (value, param) => {
|
|
4328
|
+
const at = (key) => param === "" ? key : `${param}.${key}`;
|
|
4329
|
+
if (!isObject2(value)) return invalid2(param === "" ? "body" : param, "must be an object");
|
|
4330
|
+
if (!lenient) {
|
|
4331
|
+
for (const key of Object.keys(value)) {
|
|
4332
|
+
if (!(key in members))
|
|
4333
|
+
return fail3(ENLITT_ERROR_CODE.unsupported_parameter, at(key), `"${key}" is not accepted`);
|
|
4334
|
+
}
|
|
4335
|
+
}
|
|
4336
|
+
const out = {};
|
|
4337
|
+
for (const [key, member] of Object.entries(members)) {
|
|
4338
|
+
const present = Object.prototype.hasOwnProperty.call(value, key);
|
|
4339
|
+
if (typeof member !== "function" && !present) continue;
|
|
4340
|
+
const check = typeof member === "function" ? member : member.optional;
|
|
4341
|
+
const parsed = check(value[key], at(key));
|
|
4342
|
+
if (!parsed.ok) return parsed;
|
|
4343
|
+
out[key] = parsed.value;
|
|
4344
|
+
}
|
|
4345
|
+
return ok5(out);
|
|
4346
|
+
};
|
|
4347
|
+
var arrayOf = (item) => (value, param) => {
|
|
4348
|
+
if (!Array.isArray(value)) return invalid2(param, "must be an array");
|
|
4349
|
+
const out = [];
|
|
4350
|
+
for (const [index, entry] of value.entries()) {
|
|
4351
|
+
const parsed = item(entry, `${param}[${index}]`);
|
|
4352
|
+
if (!parsed.ok) return parsed;
|
|
4353
|
+
out.push(parsed.value);
|
|
4354
|
+
}
|
|
4355
|
+
return ok5(out);
|
|
4356
|
+
};
|
|
4357
|
+
var freeObject = (value, param) => isObject2(value) ? ok5(value) : invalid2(param, "must be an object");
|
|
4358
|
+
var idOrEmail = (value, param) => {
|
|
4359
|
+
const parsed = object({ id: optional(str()), email: optional(str(320)) })(value, param);
|
|
4360
|
+
if (!parsed.ok) return parsed;
|
|
4361
|
+
const count = Number("id" in parsed.value) + Number("email" in parsed.value);
|
|
4362
|
+
return count === 1 ? parsed : invalid2("args", 'must carry exactly one of "id" and "email"');
|
|
4363
|
+
};
|
|
4364
|
+
var idArgs = object({ id: str() });
|
|
4365
|
+
var subjectArgs = object({ subject: oneOf(ADMIN_SUBJECTS), id: str() });
|
|
4366
|
+
var limitsShape = object({
|
|
4367
|
+
standard_per_call: optional(amount),
|
|
4368
|
+
premium_per_call: optional(amount)
|
|
4369
|
+
});
|
|
4370
|
+
var ARG_CHECKS = {
|
|
4371
|
+
"inspect.user": idOrEmail,
|
|
4372
|
+
"inspect.business": idOrEmail,
|
|
4373
|
+
"inspect.app": idArgs,
|
|
4374
|
+
"inspect.order": idArgs,
|
|
4375
|
+
"inspect.call": idArgs,
|
|
4376
|
+
"inspect.txn": idArgs,
|
|
4377
|
+
sql: object({
|
|
4378
|
+
sql: str(ADMIN_SQL_MAX_LENGTH),
|
|
4379
|
+
limit: optional(intRange(1, ADMIN_SQL_MAX_LIMIT))
|
|
4380
|
+
}),
|
|
4381
|
+
log: object({
|
|
4382
|
+
operator: optional(str()),
|
|
4383
|
+
target_id: optional(str()),
|
|
4384
|
+
limit: optional(intRange(1, ADMIN_LOG_MAX_LIMIT)),
|
|
4385
|
+
cursor: optional(str())
|
|
4386
|
+
}),
|
|
4387
|
+
"report.platform": object({ days: optional(intRange(1, ADMIN_REPORT_MAX_DAYS)) }),
|
|
4388
|
+
"refund.cash": object({ order_id: str(), amount_minor_units: nullable(positiveAmount) }),
|
|
4389
|
+
"refund.manual": object({ order_id: str(), amount_minor_units: positiveAmount }),
|
|
4390
|
+
"refund.mark_paid": object({ transaction_id: str(), bank_reference: str() }),
|
|
4391
|
+
"refund.cancel_manual": object({ transaction_id: str() }),
|
|
4392
|
+
"credits.grant": object({
|
|
4393
|
+
user_id: str(),
|
|
4394
|
+
standard_units: amount,
|
|
4395
|
+
premium_units: amount,
|
|
4396
|
+
call_id: nullable(str())
|
|
4397
|
+
}),
|
|
4398
|
+
"plan.set": object({ user_id: str(), plan_id: str(), catalog_version: str() }),
|
|
4399
|
+
"plan.reset": object({ user_id: str() }),
|
|
4400
|
+
"status.suspend": object({
|
|
4401
|
+
subject: oneOf(ADMIN_SUBJECTS),
|
|
4402
|
+
id: str(),
|
|
4403
|
+
days: nullable(intRange(1, ADMIN_SUSPEND_MAX_DAYS))
|
|
4404
|
+
}),
|
|
4405
|
+
"status.unsuspend": subjectArgs,
|
|
4406
|
+
"payout.block": object({ business_id: str() }),
|
|
4407
|
+
"payout.unblock": object({ business_id: str() }),
|
|
4408
|
+
"payout.create": object({ business_id: str(), nano_usd: positiveAmount }),
|
|
4409
|
+
"payout.execute": object({ transaction_id: str() }),
|
|
4410
|
+
"gift.create": object({
|
|
4411
|
+
product_kind: oneOf(["subscription", "bundle"]),
|
|
4412
|
+
product_id: str(),
|
|
4413
|
+
catalog_version: str(),
|
|
4414
|
+
expires_at: nullable(rfc3339)
|
|
4415
|
+
}),
|
|
4416
|
+
"gift.revoke": object({ gift_code_id: str() }),
|
|
4417
|
+
"account.set_email": object({ auth_user_id: str(), email: str(320) }),
|
|
4418
|
+
"account.release_phone": object({ user_id: str() }),
|
|
4419
|
+
"account.set_app_limits": object({ user_id: str(), application_id: str(), limits: limitsShape }),
|
|
4420
|
+
"account.set_default_limit": object({ user_id: str(), premium_per_call: amount })
|
|
4421
|
+
};
|
|
4422
|
+
var actionSummary = object({
|
|
4423
|
+
action_id: str(),
|
|
4424
|
+
operator: str(),
|
|
4425
|
+
command: str(),
|
|
4426
|
+
kind: oneOf(ADMIN_ACTION_KINDS),
|
|
4427
|
+
reason: nullable(str(ADMIN_REASON_MAX_LENGTH)),
|
|
4428
|
+
status: oneOf(ADMIN_ACTION_STATUSES),
|
|
4429
|
+
target_type: nullable(str()),
|
|
4430
|
+
target_id: nullable(str()),
|
|
4431
|
+
error_code: nullable(str()),
|
|
4432
|
+
created_at: rfc3339,
|
|
4433
|
+
finished_at: nullable(rfc3339)
|
|
4434
|
+
});
|
|
4435
|
+
var anyString = (value, param) => typeof value === "string" ? ok5(value) : invalid2(param, "must be a string");
|
|
4436
|
+
var signedAmount = (value, param) => typeof value === "string" && /^(0|-?[1-9][0-9]*)$/.test(value) ? ok5(value) : invalid2(param, "must be a canonical base-10 integer string");
|
|
4437
|
+
var platformReport = object({
|
|
4438
|
+
environment: anyString,
|
|
4439
|
+
window_start: rfc3339,
|
|
4440
|
+
window_end: rfc3339,
|
|
4441
|
+
sections: arrayOf(
|
|
4442
|
+
object({
|
|
4443
|
+
title: anyString,
|
|
4444
|
+
rows: arrayOf(
|
|
4445
|
+
object({
|
|
4446
|
+
label: anyString,
|
|
4447
|
+
unit: oneOf(PLATFORM_REPORT_UNITS),
|
|
4448
|
+
window: nullable(signedAmount),
|
|
4449
|
+
total: signedAmount
|
|
4450
|
+
})
|
|
4451
|
+
)
|
|
4452
|
+
})
|
|
4453
|
+
)
|
|
4454
|
+
});
|
|
4455
|
+
var subscriptionBlock = (value, param) => {
|
|
4456
|
+
const parsed = validatePersonalDashboardSubscription(value, {
|
|
4457
|
+
mode: lenient ? "tolerant" : "strict"
|
|
4458
|
+
});
|
|
4459
|
+
return parsed.ok ? parsed : invalid2(param, parsed.error.message);
|
|
4460
|
+
};
|
|
4461
|
+
var RESULT_CHECKS = {
|
|
4462
|
+
"inspect.user": freeObject,
|
|
4463
|
+
"inspect.business": freeObject,
|
|
4464
|
+
"inspect.app": freeObject,
|
|
4465
|
+
"inspect.order": freeObject,
|
|
4466
|
+
"inspect.call": freeObject,
|
|
4467
|
+
"inspect.txn": freeObject,
|
|
4468
|
+
sql: object({
|
|
4469
|
+
columns: arrayOf(anyString),
|
|
4470
|
+
rows: arrayOf(
|
|
4471
|
+
(value, param) => Array.isArray(value) ? ok5(value) : invalid2(param, "must be an array")
|
|
4472
|
+
),
|
|
4473
|
+
truncated: bool
|
|
4474
|
+
}),
|
|
4475
|
+
log: object({ actions: arrayOf(actionSummary), next_cursor: nullable(anyString) }),
|
|
4476
|
+
"report.platform": platformReport,
|
|
4477
|
+
"refund.cash": object({
|
|
4478
|
+
order_id: anyString,
|
|
4479
|
+
refunds: arrayOf(
|
|
4480
|
+
object({ transaction_id: anyString, amount_minor_units: amount, status: anyString })
|
|
4481
|
+
),
|
|
4482
|
+
remaining_minor_units: amount
|
|
4483
|
+
}),
|
|
4484
|
+
"refund.manual": object({ transaction_id: anyString, status: exactly("pending") }),
|
|
4485
|
+
"refund.mark_paid": object({ transaction_id: anyString, status: exactly("completed") }),
|
|
4486
|
+
"refund.cancel_manual": object({ transaction_id: anyString, status: exactly("canceled") }),
|
|
4487
|
+
"credits.grant": object({
|
|
4488
|
+
transaction_id: anyString,
|
|
4489
|
+
extra_credit: object({ standard_units: amount, premium_units: amount })
|
|
4490
|
+
}),
|
|
4491
|
+
"plan.set": object({ subscription: subscriptionBlock }),
|
|
4492
|
+
"plan.reset": object({
|
|
4493
|
+
subscription: subscriptionBlock,
|
|
4494
|
+
period_start: rfc3339,
|
|
4495
|
+
period_end: rfc3339
|
|
4496
|
+
}),
|
|
4497
|
+
"status.suspend": object({
|
|
4498
|
+
subject: oneOf(ADMIN_SUBJECTS),
|
|
4499
|
+
id: anyString,
|
|
4500
|
+
status: exactly("suspended"),
|
|
4501
|
+
suspended_until: nullable(rfc3339),
|
|
4502
|
+
billing: nullable(
|
|
4503
|
+
object({
|
|
4504
|
+
refunds: arrayOf(
|
|
4505
|
+
object({
|
|
4506
|
+
order_id: anyString,
|
|
4507
|
+
outcome: oneOf(["refunded", "under_review", "refused", "ineligible"]),
|
|
4508
|
+
refund_minor_units: amount,
|
|
4509
|
+
reason: anyString
|
|
4510
|
+
})
|
|
4511
|
+
),
|
|
4512
|
+
subscription_canceled: bool
|
|
4513
|
+
})
|
|
4514
|
+
)
|
|
4515
|
+
}),
|
|
4516
|
+
"status.unsuspend": object({
|
|
4517
|
+
subject: oneOf(ADMIN_SUBJECTS),
|
|
4518
|
+
id: anyString,
|
|
4519
|
+
status: exactly("active")
|
|
4520
|
+
}),
|
|
4521
|
+
"payout.block": object({ business_id: anyString, payout_blocked: bool }),
|
|
4522
|
+
"payout.unblock": object({ business_id: anyString, payout_blocked: bool }),
|
|
4523
|
+
"payout.create": object({
|
|
4524
|
+
transaction_id: anyString,
|
|
4525
|
+
nano_usd: amount,
|
|
4526
|
+
status: exactly("pending")
|
|
4527
|
+
}),
|
|
4528
|
+
"payout.execute": object({ transaction_id: anyString, status: anyString }),
|
|
4529
|
+
"gift.create": object({ gift_code_id: anyString, code: nullable(anyString) }),
|
|
4530
|
+
"gift.revoke": object({ gift_code_id: anyString, status: exactly("revoked") }),
|
|
4531
|
+
"account.set_email": object({ auth_user_id: anyString, email: anyString }),
|
|
4532
|
+
"account.release_phone": object({ user_id: anyString, phone_released: exactly(true) }),
|
|
4533
|
+
"account.set_app_limits": object({ application_id: anyString, limits: limitsShape }),
|
|
4534
|
+
"account.set_default_limit": object({
|
|
4535
|
+
user_id: anyString,
|
|
4536
|
+
new_application_premium_per_call_limit: amount
|
|
4537
|
+
})
|
|
4538
|
+
};
|
|
4539
|
+
function validateAdminCommandArgs(command, args) {
|
|
4540
|
+
const parsed = ARG_CHECKS[command](args, "args");
|
|
4541
|
+
return parsed.ok ? parsed : parsed;
|
|
4542
|
+
}
|
|
4543
|
+
function validateAdminCommandResult(command, result, options) {
|
|
4544
|
+
const parsed = withMode(options, () => RESULT_CHECKS[command](result, "result"));
|
|
4545
|
+
return parsed.ok ? parsed : parsed;
|
|
4546
|
+
}
|
|
4547
|
+
function withMode(options, run) {
|
|
4548
|
+
const previous = lenient;
|
|
4549
|
+
lenient = options?.mode === "tolerant";
|
|
4550
|
+
try {
|
|
4551
|
+
return run();
|
|
4552
|
+
} finally {
|
|
4553
|
+
lenient = previous;
|
|
4554
|
+
}
|
|
4555
|
+
}
|
|
4556
|
+
function validateAdminActionRequest(value) {
|
|
4557
|
+
if (!isObject2(value)) return invalid2("body", "must be an object");
|
|
4558
|
+
for (const key of Object.keys(value)) {
|
|
4559
|
+
if (!["action_id", "command", "args", "reason"].includes(key)) {
|
|
4560
|
+
return fail3(
|
|
4561
|
+
ENLITT_ERROR_CODE.unsupported_parameter,
|
|
4562
|
+
key,
|
|
4563
|
+
`"${key}" is not accepted by this route`
|
|
4564
|
+
);
|
|
4565
|
+
}
|
|
4566
|
+
}
|
|
4567
|
+
const actionId = value.action_id;
|
|
4568
|
+
if (typeof actionId !== "string" || !UUID.test(actionId))
|
|
4569
|
+
return invalid2("action_id", "must be a UUID");
|
|
4570
|
+
const command = value.command;
|
|
4571
|
+
if (!isAdminCommandName(command)) {
|
|
4572
|
+
return invalid2("command", `must be one of: ${ADMIN_COMMAND_NAMES.join(", ")}`);
|
|
4573
|
+
}
|
|
4574
|
+
if (!Object.prototype.hasOwnProperty.call(value, "reason")) {
|
|
4575
|
+
return invalid2("reason", "is required and must be a string or null");
|
|
4576
|
+
}
|
|
4577
|
+
const reason = nullable(str(ADMIN_REASON_MAX_LENGTH))(value.reason, "reason");
|
|
4578
|
+
if (!reason.ok) return reason;
|
|
4579
|
+
if (adminCommandKind(command) === "write" && reason.value === null) {
|
|
4580
|
+
return invalid2(
|
|
4581
|
+
"reason",
|
|
4582
|
+
`is required (1 to ${ADMIN_REASON_MAX_LENGTH} characters) for ${command}`
|
|
4583
|
+
);
|
|
4584
|
+
}
|
|
4585
|
+
const args = validateAdminCommandArgs(command, value.args);
|
|
4586
|
+
if (!args.ok) return args;
|
|
4587
|
+
return ok5({ action_id: actionId, command, args: args.value, reason: reason.value });
|
|
4588
|
+
}
|
|
4589
|
+
function validateAdminActionResponse(value, options) {
|
|
4590
|
+
return withMode(options, () => {
|
|
4591
|
+
const head = object({
|
|
4592
|
+
action_id: anyString,
|
|
4593
|
+
command: anyString,
|
|
4594
|
+
status: exactly("succeeded"),
|
|
4595
|
+
replayed: bool,
|
|
4596
|
+
result: freeObject
|
|
4597
|
+
})(value, "");
|
|
4598
|
+
if (!head.ok) return head;
|
|
4599
|
+
const command = head.value.command;
|
|
4600
|
+
if (isAdminCommandName(command)) {
|
|
4601
|
+
const result = RESULT_CHECKS[command](head.value.result, "result");
|
|
4602
|
+
if (!result.ok) return result;
|
|
4603
|
+
return ok5({ ...head.value, result: result.value });
|
|
4604
|
+
}
|
|
4605
|
+
if (!lenient) return invalid2("command", `must be one of: ${ADMIN_COMMAND_NAMES.join(", ")}`);
|
|
4606
|
+
return ok5(head.value);
|
|
4607
|
+
});
|
|
4608
|
+
}
|
|
4609
|
+
function validateAdminActionErrorResponse(value, options) {
|
|
4610
|
+
return withMode(options, () => {
|
|
4611
|
+
const parsed = object({
|
|
4612
|
+
error: object({ code: anyString, message: anyString, param: optional(anyString) }),
|
|
4613
|
+
request_id: anyString,
|
|
4614
|
+
action_id: optional(anyString)
|
|
4615
|
+
})(value, "");
|
|
4616
|
+
return parsed.ok ? parsed : parsed;
|
|
4617
|
+
});
|
|
4618
|
+
}
|
|
4619
|
+
function validateAdminActionSummary(value, options) {
|
|
4620
|
+
const parsed = withMode(options, () => actionSummary(value, "body"));
|
|
4621
|
+
return parsed.ok ? parsed : parsed;
|
|
4622
|
+
}
|
|
4623
|
+
|
|
4624
|
+
exports.ADMIN_ACTION_KINDS = ADMIN_ACTION_KINDS;
|
|
4625
|
+
exports.ADMIN_ACTION_STATUSES = ADMIN_ACTION_STATUSES;
|
|
4626
|
+
exports.ADMIN_COMMAND_NAMES = ADMIN_COMMAND_NAMES;
|
|
4627
|
+
exports.ADMIN_LOG_MAX_LIMIT = ADMIN_LOG_MAX_LIMIT;
|
|
4628
|
+
exports.ADMIN_READ_COMMANDS = ADMIN_READ_COMMANDS;
|
|
4629
|
+
exports.ADMIN_REASON_MAX_LENGTH = ADMIN_REASON_MAX_LENGTH;
|
|
4630
|
+
exports.ADMIN_REPORT_DEFAULT_DAYS = ADMIN_REPORT_DEFAULT_DAYS;
|
|
4631
|
+
exports.ADMIN_REPORT_MAX_DAYS = ADMIN_REPORT_MAX_DAYS;
|
|
4632
|
+
exports.ADMIN_REQUEST_MAX_BYTES = ADMIN_REQUEST_MAX_BYTES;
|
|
4633
|
+
exports.ADMIN_SQL_MAX_LENGTH = ADMIN_SQL_MAX_LENGTH;
|
|
4634
|
+
exports.ADMIN_SQL_MAX_LIMIT = ADMIN_SQL_MAX_LIMIT;
|
|
4635
|
+
exports.ADMIN_SUBJECTS = ADMIN_SUBJECTS;
|
|
4636
|
+
exports.ADMIN_SUSPEND_MAX_DAYS = ADMIN_SUSPEND_MAX_DAYS;
|
|
4637
|
+
exports.ADMIN_WRITE_COMMANDS = ADMIN_WRITE_COMMANDS;
|
|
4638
|
+
exports.API_KEY_SCOPES = API_KEY_SCOPES;
|
|
4639
|
+
exports.API_KEY_SCOPE_LABELS = API_KEY_SCOPE_LABELS;
|
|
4640
|
+
exports.API_KEY_STATUSES = API_KEY_STATUSES;
|
|
4641
|
+
exports.APPLICATION_ENVIRONMENTS = APPLICATION_ENVIRONMENTS;
|
|
4642
|
+
exports.APPLICATION_STATUSES = APPLICATION_STATUSES;
|
|
4643
|
+
exports.BUSINESS_PERMISSIONS = BUSINESS_PERMISSIONS;
|
|
4644
|
+
exports.BUSINESS_ROLE_NAMES = BUSINESS_ROLE_NAMES;
|
|
4645
|
+
exports.CALLER_METADATA_LIMITS = CALLER_METADATA_LIMITS;
|
|
4646
|
+
exports.CHANGE_MODES = CHANGE_MODES;
|
|
4647
|
+
exports.CLI_AUTHORIZATION_KINDS = CLI_AUTHORIZATION_KINDS;
|
|
4648
|
+
exports.CLI_DEVICE_LABEL_MAX_LENGTH = CLI_DEVICE_LABEL_MAX_LENGTH;
|
|
4649
|
+
exports.CLI_USER_CODE_ALPHABET = CLI_USER_CODE_ALPHABET;
|
|
4650
|
+
exports.CONNECTED_ACCOUNT_STATUSES = CONNECTED_ACCOUNT_STATUSES;
|
|
4651
|
+
exports.CONTACT_TYPES = CONTACT_TYPES;
|
|
4652
|
+
exports.CanonicalIntegerError = CanonicalIntegerError;
|
|
4653
|
+
exports.EMAIL_SIGN_IN_ACCOUNT_TYPES = EMAIL_SIGN_IN_ACCOUNT_TYPES;
|
|
4654
|
+
exports.EMAIL_SIGN_IN_MAX_EMAIL_LENGTH = EMAIL_SIGN_IN_MAX_EMAIL_LENGTH;
|
|
4655
|
+
exports.ENLITT_API_VERSION = ENLITT_API_VERSION;
|
|
4656
|
+
exports.ENLITT_ERROR_CODE = ENLITT_ERROR_CODE;
|
|
4657
|
+
exports.ENLITT_ERROR_CODES = ENLITT_ERROR_CODES;
|
|
4658
|
+
exports.ENLITT_ERROR_CODE_NAMES = ENLITT_ERROR_CODE_NAMES;
|
|
4659
|
+
exports.ENLITT_ERROR_TYPES = ENLITT_ERROR_TYPES;
|
|
4660
|
+
exports.ENLITT_STANDARD_MODEL = ENLITT_STANDARD_MODEL;
|
|
4661
|
+
exports.ENLITT_VERSION_HEADER = ENLITT_VERSION_HEADER;
|
|
4662
|
+
exports.EnlittErrorContractViolation = EnlittErrorContractViolation;
|
|
4663
|
+
exports.FIXTURE_ENDPOINTS = FIXTURE_ENDPOINTS;
|
|
4664
|
+
exports.GIFT_CODE_MAX_LENGTH = GIFT_CODE_MAX_LENGTH;
|
|
4665
|
+
exports.IDEMPOTENCY_KEY_MAX_LENGTH = IDEMPOTENCY_KEY_MAX_LENGTH;
|
|
4666
|
+
exports.IDEMPOTENCY_KEY_MIN_LENGTH = IDEMPOTENCY_KEY_MIN_LENGTH;
|
|
4667
|
+
exports.IDEMPOTENCY_KEY_MIN_RETENTION_DAYS = IDEMPOTENCY_KEY_MIN_RETENTION_DAYS;
|
|
4668
|
+
exports.IdempotencyKeyError = IdempotencyKeyError;
|
|
4669
|
+
exports.LOCKED_DOWNGRADE_MODES = LOCKED_DOWNGRADE_MODES;
|
|
4670
|
+
exports.ORDER_KINDS = ORDER_KINDS;
|
|
4671
|
+
exports.ORDER_STATUSES = ORDER_STATUSES;
|
|
4672
|
+
exports.PAYOUT_BLOCKED_REASONS = PAYOUT_BLOCKED_REASONS;
|
|
4673
|
+
exports.PERSONAL_APPLICATION_CALLS_DEFAULT_LIMIT = PERSONAL_APPLICATION_CALLS_DEFAULT_LIMIT;
|
|
4674
|
+
exports.PERSONAL_APPLICATION_CALLS_MAX_LIMIT = PERSONAL_APPLICATION_CALLS_MAX_LIMIT;
|
|
4675
|
+
exports.PERSONAL_APPLICATION_CALL_SORTS = PERSONAL_APPLICATION_CALL_SORTS;
|
|
4676
|
+
exports.PHONE_NUMBER_MAX_LENGTH = PHONE_NUMBER_MAX_LENGTH;
|
|
4677
|
+
exports.PLAN_INTERVALS = PLAN_INTERVALS;
|
|
4678
|
+
exports.PLATFORM_REPORT_UNITS = PLATFORM_REPORT_UNITS;
|
|
4679
|
+
exports.PREMIUM_OPERATION_BILLING_VALUES = PREMIUM_OPERATION_BILLING_VALUES;
|
|
4680
|
+
exports.PREMIUM_TERMINAL_STATUSES = PREMIUM_TERMINAL_STATUSES;
|
|
4681
|
+
exports.REFUND_ELIGIBILITY = REFUND_ELIGIBILITY;
|
|
4682
|
+
exports.REFUND_REASONS = REFUND_REASONS;
|
|
4683
|
+
exports.RESPONSE_INCOMPLETE_REASONS = RESPONSE_INCOMPLETE_REASONS;
|
|
4684
|
+
exports.RESPONSE_ITEM_STATUSES = RESPONSE_ITEM_STATUSES;
|
|
4685
|
+
exports.RESPONSE_STATUSES = RESPONSE_STATUSES;
|
|
4686
|
+
exports.RESPONSE_STREAM_EVENT_TYPES = RESPONSE_STREAM_EVENT_TYPES;
|
|
4687
|
+
exports.RESPONSE_STREAM_EVENT_TYPE_NAMES = RESPONSE_STREAM_EVENT_TYPE_NAMES;
|
|
4688
|
+
exports.SERVICE_TIERS = SERVICE_TIERS;
|
|
4689
|
+
exports.SUBSCRIPTION_STATUSES = SUBSCRIPTION_STATUSES;
|
|
4690
|
+
exports.UNKNOWN_API_KEY_SCOPE_LABEL = UNKNOWN_API_KEY_SCOPE_LABEL;
|
|
4691
|
+
exports.UNKNOWN_ENUM_VALUE = UNKNOWN_ENUM_VALUE;
|
|
4692
|
+
exports.UNRECOGNIZED_ERROR_CODE = UNRECOGNIZED_ERROR_CODE;
|
|
4693
|
+
exports.WIRE_CLOSED_SETS = WIRE_CLOSED_SETS;
|
|
4694
|
+
exports.WIRE_CONTRACT_FORMAT = WIRE_CONTRACT_FORMAT;
|
|
4695
|
+
exports.adminCommandKind = adminCommandKind;
|
|
4696
|
+
exports.assertIdempotencyKey = assertIdempotencyKey;
|
|
4697
|
+
exports.buildWireContract = buildWireContract;
|
|
4698
|
+
exports.checkResponseStreamOrdering = checkResponseStreamOrdering;
|
|
4699
|
+
exports.classifyEnlittErrorResponse = classifyEnlittErrorResponse;
|
|
4700
|
+
exports.classifyIdempotentRequest = classifyIdempotentRequest;
|
|
4701
|
+
exports.formatCanonicalInteger = formatCanonicalInteger;
|
|
4702
|
+
exports.getEnlittErrorDefinition = getEnlittErrorDefinition;
|
|
4703
|
+
exports.isAdminCommandName = isAdminCommandName;
|
|
4704
|
+
exports.isCanonicalIntegerString = isCanonicalIntegerString;
|
|
4705
|
+
exports.isEnlittErrorCode = isEnlittErrorCode;
|
|
4706
|
+
exports.isResponseStreamEventType = isResponseStreamEventType;
|
|
4707
|
+
exports.isTerminalResponseStreamEventType = isTerminalResponseStreamEventType;
|
|
4708
|
+
exports.isValidIdempotencyKey = isValidIdempotencyKey;
|
|
4709
|
+
exports.normalizeCliUserCode = normalizeCliUserCode;
|
|
4710
|
+
exports.parseCanonicalInteger = parseCanonicalInteger;
|
|
4711
|
+
exports.parsePositiveCanonicalInteger = parsePositiveCanonicalInteger;
|
|
4712
|
+
exports.renderEnlittError = renderEnlittError;
|
|
4713
|
+
exports.serializeWireContract = serializeWireContract;
|
|
4714
|
+
exports.validateAdminActionErrorResponse = validateAdminActionErrorResponse;
|
|
4715
|
+
exports.validateAdminActionRequest = validateAdminActionRequest;
|
|
4716
|
+
exports.validateAdminActionResponse = validateAdminActionResponse;
|
|
4717
|
+
exports.validateAdminActionSummary = validateAdminActionSummary;
|
|
4718
|
+
exports.validateAdminCommandArgs = validateAdminCommandArgs;
|
|
4719
|
+
exports.validateAdminCommandResult = validateAdminCommandResult;
|
|
4720
|
+
exports.validateApiKeyMetadata = validateApiKeyMetadata;
|
|
4721
|
+
exports.validateApiKeyMetadataList = validateApiKeyMetadataList;
|
|
4722
|
+
exports.validateApplicationCostProfile = validateApplicationCostProfile;
|
|
4723
|
+
exports.validateApplicationLimits = validateApplicationLimits;
|
|
4724
|
+
exports.validateAuthorizationExchangeResponse = validateAuthorizationExchangeResponse;
|
|
4725
|
+
exports.validateBeginPremiumOperationRequest = validateBeginPremiumOperationRequest;
|
|
4726
|
+
exports.validateBeginPremiumOperationResponse = validateBeginPremiumOperationResponse;
|
|
4727
|
+
exports.validateBusinessAccess = validateBusinessAccess;
|
|
4728
|
+
exports.validateBusinessApplicationDetail = validateBusinessApplicationDetail;
|
|
4729
|
+
exports.validateBusinessApplicationInfo = validateBusinessApplicationInfo;
|
|
4730
|
+
exports.validateBusinessDashboardInfo = validateBusinessDashboardInfo;
|
|
4731
|
+
exports.validateBusinessInvitationRequest = validateBusinessInvitationRequest;
|
|
4732
|
+
exports.validateBusinessInvitationResult = validateBusinessInvitationResult;
|
|
4733
|
+
exports.validateBusinessKeyListQuery = validateBusinessKeyListQuery;
|
|
4734
|
+
exports.validateBusinessLoginEmailChallenge = validateBusinessLoginEmailChallenge;
|
|
4735
|
+
exports.validateBusinessMemberList = validateBusinessMemberList;
|
|
4736
|
+
exports.validateBusinessPayoutAccountOnboardingResponse = validateBusinessPayoutAccountOnboardingResponse;
|
|
4737
|
+
exports.validateBusinessPayoutList = validateBusinessPayoutList;
|
|
4738
|
+
exports.validateBusinessPermission = validateBusinessPermission;
|
|
4739
|
+
exports.validateBusinessRole = validateBusinessRole;
|
|
4740
|
+
exports.validateCallerMetadata = validateCallerMetadata;
|
|
4741
|
+
exports.validateChangeBusinessMemberRoleRequest = validateChangeBusinessMemberRoleRequest;
|
|
4742
|
+
exports.validateCliAuthorizationView = validateCliAuthorizationView;
|
|
4743
|
+
exports.validateCliCredentialList = validateCliCredentialList;
|
|
4744
|
+
exports.validateCliTokenGrant = validateCliTokenGrant;
|
|
4745
|
+
exports.validateCliTokenRequest = validateCliTokenRequest;
|
|
4746
|
+
exports.validateConsentCompletion = validateConsentCompletion;
|
|
4747
|
+
exports.validateConsentCompletionRequest = validateConsentCompletionRequest;
|
|
4748
|
+
exports.validateConsentDenial = validateConsentDenial;
|
|
4749
|
+
exports.validateConsentInfo = validateConsentInfo;
|
|
4750
|
+
exports.validateContactChallenge = validateContactChallenge;
|
|
4751
|
+
exports.validateCreateBusinessApplicationRequest = validateCreateBusinessApplicationRequest;
|
|
4752
|
+
exports.validateCreateBusinessKeyRequest = validateCreateBusinessKeyRequest;
|
|
4753
|
+
exports.validateCreateBusinessKeyResponse = validateCreateBusinessKeyResponse;
|
|
4754
|
+
exports.validateCreateBusinessPayoutRequest = validateCreateBusinessPayoutRequest;
|
|
4755
|
+
exports.validateCreateBusinessRequest = validateCreateBusinessRequest;
|
|
4756
|
+
exports.validateCreditsCheckoutRequest = validateCreditsCheckoutRequest;
|
|
4757
|
+
exports.validateCreditsCheckoutResponse = validateCreditsCheckoutResponse;
|
|
4758
|
+
exports.validateDashboardCheckoutResponse = validateDashboardCheckoutResponse;
|
|
4759
|
+
exports.validateDashboardPurchaseOrderPage = validateDashboardPurchaseOrderPage;
|
|
4760
|
+
exports.validateDashboardPurchaseOrderSummary = validateDashboardPurchaseOrderSummary;
|
|
4761
|
+
exports.validateEmailSignInCompleted = validateEmailSignInCompleted;
|
|
4762
|
+
exports.validateEmailSignInSendRequest = validateEmailSignInSendRequest;
|
|
4763
|
+
exports.validateEmailSignInSent = validateEmailSignInSent;
|
|
4764
|
+
exports.validateEmailSignInVerifyRequest = validateEmailSignInVerifyRequest;
|
|
4765
|
+
exports.validateEmptyRequestBody = validateEmptyRequestBody;
|
|
4766
|
+
exports.validateEnlittStandardRequest = validateEnlittStandardRequest;
|
|
4767
|
+
exports.validateOpenAIResponse = validateOpenAIResponse;
|
|
4768
|
+
exports.validateOutputTextPart = validateOutputTextPart;
|
|
4769
|
+
exports.validatePatchPersonalApplicationLimitRequest = validatePatchPersonalApplicationLimitRequest;
|
|
4770
|
+
exports.validatePatchPersonalSettingsRequest = validatePatchPersonalSettingsRequest;
|
|
4771
|
+
exports.validatePaymentMethodSetupResponse = validatePaymentMethodSetupResponse;
|
|
4772
|
+
exports.validatePersonalApplicationCallPage = validatePersonalApplicationCallPage;
|
|
4773
|
+
exports.validatePersonalApplicationCallsQuery = validatePersonalApplicationCallsQuery;
|
|
4774
|
+
exports.validatePersonalApplicationDetail = validatePersonalApplicationDetail;
|
|
4775
|
+
exports.validatePersonalApplicationsPage = validatePersonalApplicationsPage;
|
|
4776
|
+
exports.validatePersonalContact = validatePersonalContact;
|
|
4777
|
+
exports.validatePersonalContactsList = validatePersonalContactsList;
|
|
4778
|
+
exports.validatePersonalDashboard = validatePersonalDashboard;
|
|
4779
|
+
exports.validatePersonalDashboardSubscription = validatePersonalDashboardSubscription;
|
|
4780
|
+
exports.validatePersonalPeriodPage = validatePersonalPeriodPage;
|
|
4781
|
+
exports.validatePersonalUsagePeriod = validatePersonalUsagePeriod;
|
|
4782
|
+
exports.validatePhoneVerificationCompleted = validatePhoneVerificationCompleted;
|
|
4783
|
+
exports.validatePhoneVerificationSendRequest = validatePhoneVerificationSendRequest;
|
|
4784
|
+
exports.validatePhoneVerificationSent = validatePhoneVerificationSent;
|
|
4785
|
+
exports.validatePhoneVerificationVerifyRequest = validatePhoneVerificationVerifyRequest;
|
|
4786
|
+
exports.validateRedeemGiftCodeRequest = validateRedeemGiftCodeRequest;
|
|
4787
|
+
exports.validateRedeemGiftCodeResponse = validateRedeemGiftCodeResponse;
|
|
4788
|
+
exports.validateReportPremiumTerminalRequest = validateReportPremiumTerminalRequest;
|
|
4789
|
+
exports.validateReportPremiumTerminalResponse = validateReportPremiumTerminalResponse;
|
|
4790
|
+
exports.validateResponseOutputItem = validateResponseOutputItem;
|
|
4791
|
+
exports.validateResponseStreamEvent = validateResponseStreamEvent;
|
|
4792
|
+
exports.validateSelectActiveBusinessRequest = validateSelectActiveBusinessRequest;
|
|
4793
|
+
exports.validateStartBusinessLoginEmailChangeRequest = validateStartBusinessLoginEmailChangeRequest;
|
|
4794
|
+
exports.validateStartCliAuthorizationRequest = validateStartCliAuthorizationRequest;
|
|
4795
|
+
exports.validateStartContactVerificationRequest = validateStartContactVerificationRequest;
|
|
4796
|
+
exports.validateStartedCliAuthorization = validateStartedCliAuthorization;
|
|
4797
|
+
exports.validateSubscriptionPlanCatalog = validateSubscriptionPlanCatalog;
|
|
4798
|
+
exports.validateSubscriptionPlanSummary = validateSubscriptionPlanSummary;
|
|
4799
|
+
exports.validateSubscriptionSelectionRequest = validateSubscriptionSelectionRequest;
|
|
4800
|
+
exports.validateTransferBusinessOwnershipRequest = validateTransferBusinessOwnershipRequest;
|
|
4801
|
+
exports.validateUpdateBusinessApplicationRequest = validateUpdateBusinessApplicationRequest;
|
|
4802
|
+
exports.validateUsageResponse = validateUsageResponse;
|
|
4803
|
+
exports.validateVerifyBusinessLoginEmailChangeRequest = validateVerifyBusinessLoginEmailChangeRequest;
|
|
4804
|
+
exports.validateVerifyContactRequest = validateVerifyContactRequest;
|
|
4805
|
+
//# sourceMappingURL=index.cjs.map
|
|
4806
|
+
//# sourceMappingURL=index.cjs.map
|