@stackone/connect-sdk 1.33.0 → 1.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,4140 @@
1
+ import { HttpClientManager, HttpErrorMessages, isSuccessStatusCode } from "@stackone/transport";
2
+ import { match } from "path-to-regexp";
3
+ import { AUTHENTICATION_SCHEMA, COMPOSITE_ID_LATEST_VERSION, CoreError, StepFunctionName, StepFunctionsFactory, decodeCompositeId, encodeCompositeId, expandCursor, isCompositeId, isCursorEmpty, minifyCursor, updateCursor } from "@stackone/core";
4
+ import { isMissing, isNumber, isObject, isString, notMissing } from "@stackone/utils";
5
+ import { parse } from "yaml";
6
+ import { safeEvaluate, safeEvaluateRecord } from "@stackone/expressions";
7
+
8
+ //#region src/blocks/createBlock.ts
9
+ const createBlock = async ({ inputs, context, operation, credentials, nextCursor, logger, getHttpClient = async () => HttpClientManager.getInstance() }) => {
10
+ const httpClient = await getHttpClient();
11
+ return {
12
+ inputs,
13
+ fieldConfigs: [],
14
+ context,
15
+ operation,
16
+ credentials,
17
+ nextCursor,
18
+ httpClient,
19
+ logger
20
+ };
21
+ };
22
+
23
+ //#endregion
24
+ //#region src/connectors/operations.ts
25
+ const getOperationFromUrl = (connector, url, method) => {
26
+ const httpMethod = method.toUpperCase();
27
+ if (!connector.operations) return void 0;
28
+ const validOperationUrls = Object.keys(connector.operations);
29
+ const test = testMatcher(url, httpMethod, validOperationUrls);
30
+ if (!test) return void 0;
31
+ return {
32
+ operation: connector.operations?.[test.path],
33
+ params: test.params
34
+ };
35
+ };
36
+ const removeLeadingAndTrailingSlashes = (path) => {
37
+ const withoutLeadingSlash = path.startsWith("/") ? path.slice(1) : path;
38
+ const withoutTrailingSlash = withoutLeadingSlash.endsWith("/") ? withoutLeadingSlash.slice(0, -1) : withoutLeadingSlash;
39
+ return withoutTrailingSlash;
40
+ };
41
+ const testMatcher = (url, method, routes) => {
42
+ const path = removeLeadingAndTrailingSlashes(url);
43
+ for (const r of routes) if (r.startsWith(method)) {
44
+ const cleanRoute = r.replace(`${method} `, "").trim();
45
+ const fn = match(removeLeadingAndTrailingSlashes(cleanRoute));
46
+ const res = fn(removeLeadingAndTrailingSlashes(path));
47
+ if (res !== false) return {
48
+ path: r,
49
+ params: res.params
50
+ };
51
+ }
52
+ return void 0;
53
+ };
54
+
55
+ //#endregion
56
+ //#region ../../node_modules/zod/v4/core/core.js
57
+ /** A special constant with type `never` */
58
+ const NEVER = Object.freeze({ status: "aborted" });
59
+ function $constructor(name, initializer$2, params) {
60
+ function init(inst, def) {
61
+ var _a;
62
+ Object.defineProperty(inst, "_zod", {
63
+ value: inst._zod ?? {},
64
+ enumerable: false
65
+ });
66
+ (_a = inst._zod).traits ?? (_a.traits = /* @__PURE__ */ new Set());
67
+ inst._zod.traits.add(name);
68
+ initializer$2(inst, def);
69
+ for (const k in _.prototype) if (!(k in inst)) Object.defineProperty(inst, k, { value: _.prototype[k].bind(inst) });
70
+ inst._zod.constr = _;
71
+ inst._zod.def = def;
72
+ }
73
+ const Parent = params?.Parent ?? Object;
74
+ class Definition extends Parent {}
75
+ Object.defineProperty(Definition, "name", { value: name });
76
+ function _(def) {
77
+ var _a;
78
+ const inst = params?.Parent ? new Definition() : this;
79
+ init(inst, def);
80
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
81
+ for (const fn of inst._zod.deferred) fn();
82
+ return inst;
83
+ }
84
+ Object.defineProperty(_, "init", { value: init });
85
+ Object.defineProperty(_, Symbol.hasInstance, { value: (inst) => {
86
+ if (params?.Parent && inst instanceof params.Parent) return true;
87
+ return inst?._zod?.traits?.has(name);
88
+ } });
89
+ Object.defineProperty(_, "name", { value: name });
90
+ return _;
91
+ }
92
+ const $brand = Symbol("zod_brand");
93
+ var $ZodAsyncError = class extends Error {
94
+ constructor() {
95
+ super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
96
+ }
97
+ };
98
+ const globalConfig = {};
99
+ function config(newConfig) {
100
+ if (newConfig) Object.assign(globalConfig, newConfig);
101
+ return globalConfig;
102
+ }
103
+
104
+ //#endregion
105
+ //#region ../../node_modules/zod/v4/core/util.js
106
+ function getEnumValues(entries) {
107
+ const numericValues = Object.values(entries).filter((v) => typeof v === "number");
108
+ const values = Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
109
+ return values;
110
+ }
111
+ function jsonStringifyReplacer(_, value) {
112
+ if (typeof value === "bigint") return value.toString();
113
+ return value;
114
+ }
115
+ function cached(getter) {
116
+ const set = false;
117
+ return { get value() {
118
+ {
119
+ const value = getter();
120
+ Object.defineProperty(this, "value", { value });
121
+ return value;
122
+ }
123
+ } };
124
+ }
125
+ function nullish(input) {
126
+ return input === null || input === void 0;
127
+ }
128
+ function cleanRegex(source) {
129
+ const start = source.startsWith("^") ? 1 : 0;
130
+ const end = source.endsWith("$") ? source.length - 1 : source.length;
131
+ return source.slice(start, end);
132
+ }
133
+ function floatSafeRemainder(val, step) {
134
+ const valDecCount = (val.toString().split(".")[1] || "").length;
135
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
136
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
137
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
138
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
139
+ return valInt % stepInt / 10 ** decCount;
140
+ }
141
+ function defineLazy(object$1, key, getter) {
142
+ const set = false;
143
+ Object.defineProperty(object$1, key, {
144
+ get() {
145
+ {
146
+ const value = getter();
147
+ object$1[key] = value;
148
+ return value;
149
+ }
150
+ },
151
+ set(v) {
152
+ Object.defineProperty(object$1, key, { value: v });
153
+ },
154
+ configurable: true
155
+ });
156
+ }
157
+ function assignProp(target, prop, value) {
158
+ Object.defineProperty(target, prop, {
159
+ value,
160
+ writable: true,
161
+ enumerable: true,
162
+ configurable: true
163
+ });
164
+ }
165
+ function esc(str) {
166
+ return JSON.stringify(str);
167
+ }
168
+ const captureStackTrace = Error.captureStackTrace ? Error.captureStackTrace : (..._args) => {};
169
+ function isObject$1(data) {
170
+ return typeof data === "object" && data !== null && !Array.isArray(data);
171
+ }
172
+ const allowsEval = cached(() => {
173
+ if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) return false;
174
+ try {
175
+ const F = Function;
176
+ new F("");
177
+ return true;
178
+ } catch (_) {
179
+ return false;
180
+ }
181
+ });
182
+ function isPlainObject(o) {
183
+ if (isObject$1(o) === false) return false;
184
+ const ctor = o.constructor;
185
+ if (ctor === void 0) return true;
186
+ const prot = ctor.prototype;
187
+ if (isObject$1(prot) === false) return false;
188
+ if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) return false;
189
+ return true;
190
+ }
191
+ const propertyKeyTypes = new Set([
192
+ "string",
193
+ "number",
194
+ "symbol"
195
+ ]);
196
+ function escapeRegex(str) {
197
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
198
+ }
199
+ function clone(inst, def, params) {
200
+ const cl = new inst._zod.constr(def ?? inst._zod.def);
201
+ if (!def || params?.parent) cl._zod.parent = inst;
202
+ return cl;
203
+ }
204
+ function normalizeParams(_params) {
205
+ const params = _params;
206
+ if (!params) return {};
207
+ if (typeof params === "string") return { error: () => params };
208
+ if (params?.message !== void 0) {
209
+ if (params?.error !== void 0) throw new Error("Cannot specify both `message` and `error` params");
210
+ params.error = params.message;
211
+ }
212
+ delete params.message;
213
+ if (typeof params.error === "string") return {
214
+ ...params,
215
+ error: () => params.error
216
+ };
217
+ return params;
218
+ }
219
+ function optionalKeys(shape) {
220
+ return Object.keys(shape).filter((k) => {
221
+ return shape[k]._zod.optin === "optional" && shape[k]._zod.optout === "optional";
222
+ });
223
+ }
224
+ const NUMBER_FORMAT_RANGES = {
225
+ safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
226
+ int32: [-2147483648, 2147483647],
227
+ uint32: [0, 4294967295],
228
+ float32: [-34028234663852886e22, 34028234663852886e22],
229
+ float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
230
+ };
231
+ function pick(schema, mask) {
232
+ const newShape = {};
233
+ const currDef = schema._zod.def;
234
+ for (const key in mask) {
235
+ if (!(key in currDef.shape)) throw new Error(`Unrecognized key: "${key}"`);
236
+ if (!mask[key]) continue;
237
+ newShape[key] = currDef.shape[key];
238
+ }
239
+ return clone(schema, {
240
+ ...schema._zod.def,
241
+ shape: newShape,
242
+ checks: []
243
+ });
244
+ }
245
+ function omit(schema, mask) {
246
+ const newShape = { ...schema._zod.def.shape };
247
+ const currDef = schema._zod.def;
248
+ for (const key in mask) {
249
+ if (!(key in currDef.shape)) throw new Error(`Unrecognized key: "${key}"`);
250
+ if (!mask[key]) continue;
251
+ delete newShape[key];
252
+ }
253
+ return clone(schema, {
254
+ ...schema._zod.def,
255
+ shape: newShape,
256
+ checks: []
257
+ });
258
+ }
259
+ function extend(schema, shape) {
260
+ if (!isPlainObject(shape)) throw new Error("Invalid input to extend: expected a plain object");
261
+ const def = {
262
+ ...schema._zod.def,
263
+ get shape() {
264
+ const _shape = {
265
+ ...schema._zod.def.shape,
266
+ ...shape
267
+ };
268
+ assignProp(this, "shape", _shape);
269
+ return _shape;
270
+ },
271
+ checks: []
272
+ };
273
+ return clone(schema, def);
274
+ }
275
+ function merge(a, b) {
276
+ return clone(a, {
277
+ ...a._zod.def,
278
+ get shape() {
279
+ const _shape = {
280
+ ...a._zod.def.shape,
281
+ ...b._zod.def.shape
282
+ };
283
+ assignProp(this, "shape", _shape);
284
+ return _shape;
285
+ },
286
+ catchall: b._zod.def.catchall,
287
+ checks: []
288
+ });
289
+ }
290
+ function partial(Class, schema, mask) {
291
+ const oldShape = schema._zod.def.shape;
292
+ const shape = { ...oldShape };
293
+ if (mask) for (const key in mask) {
294
+ if (!(key in oldShape)) throw new Error(`Unrecognized key: "${key}"`);
295
+ if (!mask[key]) continue;
296
+ shape[key] = Class ? new Class({
297
+ type: "optional",
298
+ innerType: oldShape[key]
299
+ }) : oldShape[key];
300
+ }
301
+ else for (const key in oldShape) shape[key] = Class ? new Class({
302
+ type: "optional",
303
+ innerType: oldShape[key]
304
+ }) : oldShape[key];
305
+ return clone(schema, {
306
+ ...schema._zod.def,
307
+ shape,
308
+ checks: []
309
+ });
310
+ }
311
+ function required(Class, schema, mask) {
312
+ const oldShape = schema._zod.def.shape;
313
+ const shape = { ...oldShape };
314
+ if (mask) for (const key in mask) {
315
+ if (!(key in shape)) throw new Error(`Unrecognized key: "${key}"`);
316
+ if (!mask[key]) continue;
317
+ shape[key] = new Class({
318
+ type: "nonoptional",
319
+ innerType: oldShape[key]
320
+ });
321
+ }
322
+ else for (const key in oldShape) shape[key] = new Class({
323
+ type: "nonoptional",
324
+ innerType: oldShape[key]
325
+ });
326
+ return clone(schema, {
327
+ ...schema._zod.def,
328
+ shape,
329
+ checks: []
330
+ });
331
+ }
332
+ function aborted(x, startIndex = 0) {
333
+ for (let i = startIndex; i < x.issues.length; i++) if (x.issues[i]?.continue !== true) return true;
334
+ return false;
335
+ }
336
+ function prefixIssues(path, issues) {
337
+ return issues.map((iss) => {
338
+ var _a;
339
+ (_a = iss).path ?? (_a.path = []);
340
+ iss.path.unshift(path);
341
+ return iss;
342
+ });
343
+ }
344
+ function unwrapMessage(message) {
345
+ return typeof message === "string" ? message : message?.message;
346
+ }
347
+ function finalizeIssue(iss, ctx, config$1) {
348
+ const full = {
349
+ ...iss,
350
+ path: iss.path ?? []
351
+ };
352
+ if (!iss.message) {
353
+ const message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config$1.customError?.(iss)) ?? unwrapMessage(config$1.localeError?.(iss)) ?? "Invalid input";
354
+ full.message = message;
355
+ }
356
+ delete full.inst;
357
+ delete full.continue;
358
+ if (!ctx?.reportInput) delete full.input;
359
+ return full;
360
+ }
361
+ function getLengthableOrigin(input) {
362
+ if (Array.isArray(input)) return "array";
363
+ if (typeof input === "string") return "string";
364
+ return "unknown";
365
+ }
366
+ function issue(...args) {
367
+ const [iss, input, inst] = args;
368
+ if (typeof iss === "string") return {
369
+ message: iss,
370
+ code: "custom",
371
+ input,
372
+ inst
373
+ };
374
+ return { ...iss };
375
+ }
376
+
377
+ //#endregion
378
+ //#region ../../node_modules/zod/v4/core/errors.js
379
+ const initializer$1 = (inst, def) => {
380
+ inst.name = "$ZodError";
381
+ Object.defineProperty(inst, "_zod", {
382
+ value: inst._zod,
383
+ enumerable: false
384
+ });
385
+ Object.defineProperty(inst, "issues", {
386
+ value: def,
387
+ enumerable: false
388
+ });
389
+ Object.defineProperty(inst, "message", {
390
+ get() {
391
+ return JSON.stringify(def, jsonStringifyReplacer, 2);
392
+ },
393
+ enumerable: true
394
+ });
395
+ };
396
+ const $ZodError = $constructor("$ZodError", initializer$1);
397
+ const $ZodRealError = $constructor("$ZodError", initializer$1, { Parent: Error });
398
+ function flattenError(error, mapper = (issue$1) => issue$1.message) {
399
+ const fieldErrors = {};
400
+ const formErrors = [];
401
+ for (const sub of error.issues) if (sub.path.length > 0) {
402
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
403
+ fieldErrors[sub.path[0]].push(mapper(sub));
404
+ } else formErrors.push(mapper(sub));
405
+ return {
406
+ formErrors,
407
+ fieldErrors
408
+ };
409
+ }
410
+ function formatError(error, _mapper) {
411
+ const mapper = _mapper || function(issue$1) {
412
+ return issue$1.message;
413
+ };
414
+ const fieldErrors = { _errors: [] };
415
+ const processError = (error$1) => {
416
+ for (const issue$1 of error$1.issues) if (issue$1.code === "invalid_union" && issue$1.errors.length) issue$1.errors.map((issues) => processError({ issues }));
417
+ else if (issue$1.code === "invalid_key") processError({ issues: issue$1.issues });
418
+ else if (issue$1.code === "invalid_element") processError({ issues: issue$1.issues });
419
+ else if (issue$1.path.length === 0) fieldErrors._errors.push(mapper(issue$1));
420
+ else {
421
+ let curr = fieldErrors;
422
+ let i = 0;
423
+ while (i < issue$1.path.length) {
424
+ const el = issue$1.path[i];
425
+ const terminal = i === issue$1.path.length - 1;
426
+ if (!terminal) curr[el] = curr[el] || { _errors: [] };
427
+ else {
428
+ curr[el] = curr[el] || { _errors: [] };
429
+ curr[el]._errors.push(mapper(issue$1));
430
+ }
431
+ curr = curr[el];
432
+ i++;
433
+ }
434
+ }
435
+ };
436
+ processError(error);
437
+ return fieldErrors;
438
+ }
439
+
440
+ //#endregion
441
+ //#region ../../node_modules/zod/v4/core/parse.js
442
+ const _parse = (_Err) => (schema, value, _ctx, _params) => {
443
+ const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
444
+ const result = schema._zod.run({
445
+ value,
446
+ issues: []
447
+ }, ctx);
448
+ if (result instanceof Promise) throw new $ZodAsyncError();
449
+ if (result.issues.length) {
450
+ const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
451
+ captureStackTrace(e, _params?.callee);
452
+ throw e;
453
+ }
454
+ return result.value;
455
+ };
456
+ const parse$2 = /* @__PURE__ */ _parse($ZodRealError);
457
+ const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
458
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
459
+ let result = schema._zod.run({
460
+ value,
461
+ issues: []
462
+ }, ctx);
463
+ if (result instanceof Promise) result = await result;
464
+ if (result.issues.length) {
465
+ const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
466
+ captureStackTrace(e, params?.callee);
467
+ throw e;
468
+ }
469
+ return result.value;
470
+ };
471
+ const parseAsync$1 = /* @__PURE__ */ _parseAsync($ZodRealError);
472
+ const _safeParse = (_Err) => (schema, value, _ctx) => {
473
+ const ctx = _ctx ? {
474
+ ..._ctx,
475
+ async: false
476
+ } : { async: false };
477
+ const result = schema._zod.run({
478
+ value,
479
+ issues: []
480
+ }, ctx);
481
+ if (result instanceof Promise) throw new $ZodAsyncError();
482
+ return result.issues.length ? {
483
+ success: false,
484
+ error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
485
+ } : {
486
+ success: true,
487
+ data: result.value
488
+ };
489
+ };
490
+ const safeParse$1 = /* @__PURE__ */ _safeParse($ZodRealError);
491
+ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
492
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
493
+ let result = schema._zod.run({
494
+ value,
495
+ issues: []
496
+ }, ctx);
497
+ if (result instanceof Promise) result = await result;
498
+ return result.issues.length ? {
499
+ success: false,
500
+ error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
501
+ } : {
502
+ success: true,
503
+ data: result.value
504
+ };
505
+ };
506
+ const safeParseAsync$1 = /* @__PURE__ */ _safeParseAsync($ZodRealError);
507
+
508
+ //#endregion
509
+ //#region ../../node_modules/zod/v4/core/regexes.js
510
+ const cuid = /^[cC][^\s-]{8,}$/;
511
+ const cuid2 = /^[0-9a-z]+$/;
512
+ const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
513
+ const xid = /^[0-9a-vA-V]{20}$/;
514
+ const ksuid = /^[A-Za-z0-9]{27}$/;
515
+ const nanoid = /^[a-zA-Z0-9_-]{21}$/;
516
+ /** ISO 8601-1 duration regex. Does not support the 8601-2 extensions like negative durations or fractional/negative components. */
517
+ const duration$1 = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
518
+ /** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
519
+ const guid = /^([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})$/;
520
+ /** Returns a regex for validating an RFC 4122 UUID.
521
+ *
522
+ * @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
523
+ const uuid = (version$1) => {
524
+ if (!version$1) return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$/;
525
+ return /* @__PURE__ */ new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version$1}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
526
+ };
527
+ /** Practical email validation */
528
+ const email = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
529
+ const _emoji$1 = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
530
+ function emoji() {
531
+ return new RegExp(_emoji$1, "u");
532
+ }
533
+ const ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
534
+ const ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})$/;
535
+ const cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
536
+ const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
537
+ const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
538
+ const base64url = /^[A-Za-z0-9_-]*$/;
539
+ const hostname = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
540
+ const e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
541
+ const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
542
+ const date$1 = /* @__PURE__ */ new RegExp(`^${dateSource}$`);
543
+ function timeSource(args) {
544
+ const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
545
+ const regex = typeof args.precision === "number" ? args.precision === -1 ? `${hhmm}` : args.precision === 0 ? `${hhmm}:[0-5]\\d` : `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}` : `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
546
+ return regex;
547
+ }
548
+ function time$1(args) {
549
+ return /* @__PURE__ */ new RegExp(`^${timeSource(args)}$`);
550
+ }
551
+ function datetime$1(args) {
552
+ const time$2 = timeSource({ precision: args.precision });
553
+ const opts = ["Z"];
554
+ if (args.local) opts.push("");
555
+ if (args.offset) opts.push(`([+-]\\d{2}:\\d{2})`);
556
+ const timeRegex = `${time$2}(?:${opts.join("|")})`;
557
+ return /* @__PURE__ */ new RegExp(`^${dateSource}T(?:${timeRegex})$`);
558
+ }
559
+ const string$1 = (params) => {
560
+ const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
561
+ return /* @__PURE__ */ new RegExp(`^${regex}$`);
562
+ };
563
+ const integer = /^\d+$/;
564
+ const number$1 = /^-?\d+(?:\.\d+)?/i;
565
+ const boolean$1 = /true|false/i;
566
+ const lowercase = /^[^A-Z]*$/;
567
+ const uppercase = /^[^a-z]*$/;
568
+
569
+ //#endregion
570
+ //#region ../../node_modules/zod/v4/core/checks.js
571
+ const $ZodCheck = /* @__PURE__ */ $constructor("$ZodCheck", (inst, def) => {
572
+ var _a;
573
+ inst._zod ?? (inst._zod = {});
574
+ inst._zod.def = def;
575
+ (_a = inst._zod).onattach ?? (_a.onattach = []);
576
+ });
577
+ const numericOriginMap = {
578
+ number: "number",
579
+ bigint: "bigint",
580
+ object: "date"
581
+ };
582
+ const $ZodCheckLessThan = /* @__PURE__ */ $constructor("$ZodCheckLessThan", (inst, def) => {
583
+ $ZodCheck.init(inst, def);
584
+ const origin = numericOriginMap[typeof def.value];
585
+ inst._zod.onattach.push((inst$1) => {
586
+ const bag = inst$1._zod.bag;
587
+ const curr = (def.inclusive ? bag.maximum : bag.exclusiveMaximum) ?? Number.POSITIVE_INFINITY;
588
+ if (def.value < curr) if (def.inclusive) bag.maximum = def.value;
589
+ else bag.exclusiveMaximum = def.value;
590
+ });
591
+ inst._zod.check = (payload) => {
592
+ if (def.inclusive ? payload.value <= def.value : payload.value < def.value) return;
593
+ payload.issues.push({
594
+ origin,
595
+ code: "too_big",
596
+ maximum: def.value,
597
+ input: payload.value,
598
+ inclusive: def.inclusive,
599
+ inst,
600
+ continue: !def.abort
601
+ });
602
+ };
603
+ });
604
+ const $ZodCheckGreaterThan = /* @__PURE__ */ $constructor("$ZodCheckGreaterThan", (inst, def) => {
605
+ $ZodCheck.init(inst, def);
606
+ const origin = numericOriginMap[typeof def.value];
607
+ inst._zod.onattach.push((inst$1) => {
608
+ const bag = inst$1._zod.bag;
609
+ const curr = (def.inclusive ? bag.minimum : bag.exclusiveMinimum) ?? Number.NEGATIVE_INFINITY;
610
+ if (def.value > curr) if (def.inclusive) bag.minimum = def.value;
611
+ else bag.exclusiveMinimum = def.value;
612
+ });
613
+ inst._zod.check = (payload) => {
614
+ if (def.inclusive ? payload.value >= def.value : payload.value > def.value) return;
615
+ payload.issues.push({
616
+ origin,
617
+ code: "too_small",
618
+ minimum: def.value,
619
+ input: payload.value,
620
+ inclusive: def.inclusive,
621
+ inst,
622
+ continue: !def.abort
623
+ });
624
+ };
625
+ });
626
+ const $ZodCheckMultipleOf = /* @__PURE__ */ $constructor("$ZodCheckMultipleOf", (inst, def) => {
627
+ $ZodCheck.init(inst, def);
628
+ inst._zod.onattach.push((inst$1) => {
629
+ var _a;
630
+ (_a = inst$1._zod.bag).multipleOf ?? (_a.multipleOf = def.value);
631
+ });
632
+ inst._zod.check = (payload) => {
633
+ if (typeof payload.value !== typeof def.value) throw new Error("Cannot mix number and bigint in multiple_of check.");
634
+ const isMultiple = typeof payload.value === "bigint" ? payload.value % def.value === BigInt(0) : floatSafeRemainder(payload.value, def.value) === 0;
635
+ if (isMultiple) return;
636
+ payload.issues.push({
637
+ origin: typeof payload.value,
638
+ code: "not_multiple_of",
639
+ divisor: def.value,
640
+ input: payload.value,
641
+ inst,
642
+ continue: !def.abort
643
+ });
644
+ };
645
+ });
646
+ const $ZodCheckNumberFormat = /* @__PURE__ */ $constructor("$ZodCheckNumberFormat", (inst, def) => {
647
+ $ZodCheck.init(inst, def);
648
+ def.format = def.format || "float64";
649
+ const isInt = def.format?.includes("int");
650
+ const origin = isInt ? "int" : "number";
651
+ const [minimum, maximum] = NUMBER_FORMAT_RANGES[def.format];
652
+ inst._zod.onattach.push((inst$1) => {
653
+ const bag = inst$1._zod.bag;
654
+ bag.format = def.format;
655
+ bag.minimum = minimum;
656
+ bag.maximum = maximum;
657
+ if (isInt) bag.pattern = integer;
658
+ });
659
+ inst._zod.check = (payload) => {
660
+ const input = payload.value;
661
+ if (isInt) {
662
+ if (!Number.isInteger(input)) {
663
+ payload.issues.push({
664
+ expected: origin,
665
+ format: def.format,
666
+ code: "invalid_type",
667
+ input,
668
+ inst
669
+ });
670
+ return;
671
+ }
672
+ if (!Number.isSafeInteger(input)) {
673
+ if (input > 0) payload.issues.push({
674
+ input,
675
+ code: "too_big",
676
+ maximum: Number.MAX_SAFE_INTEGER,
677
+ note: "Integers must be within the safe integer range.",
678
+ inst,
679
+ origin,
680
+ continue: !def.abort
681
+ });
682
+ else payload.issues.push({
683
+ input,
684
+ code: "too_small",
685
+ minimum: Number.MIN_SAFE_INTEGER,
686
+ note: "Integers must be within the safe integer range.",
687
+ inst,
688
+ origin,
689
+ continue: !def.abort
690
+ });
691
+ return;
692
+ }
693
+ }
694
+ if (input < minimum) payload.issues.push({
695
+ origin: "number",
696
+ input,
697
+ code: "too_small",
698
+ minimum,
699
+ inclusive: true,
700
+ inst,
701
+ continue: !def.abort
702
+ });
703
+ if (input > maximum) payload.issues.push({
704
+ origin: "number",
705
+ input,
706
+ code: "too_big",
707
+ maximum,
708
+ inst
709
+ });
710
+ };
711
+ });
712
+ const $ZodCheckMaxLength = /* @__PURE__ */ $constructor("$ZodCheckMaxLength", (inst, def) => {
713
+ $ZodCheck.init(inst, def);
714
+ inst._zod.when = (payload) => {
715
+ const val = payload.value;
716
+ return !nullish(val) && val.length !== void 0;
717
+ };
718
+ inst._zod.onattach.push((inst$1) => {
719
+ const curr = inst$1._zod.bag.maximum ?? Number.POSITIVE_INFINITY;
720
+ if (def.maximum < curr) inst$1._zod.bag.maximum = def.maximum;
721
+ });
722
+ inst._zod.check = (payload) => {
723
+ const input = payload.value;
724
+ const length = input.length;
725
+ if (length <= def.maximum) return;
726
+ const origin = getLengthableOrigin(input);
727
+ payload.issues.push({
728
+ origin,
729
+ code: "too_big",
730
+ maximum: def.maximum,
731
+ inclusive: true,
732
+ input,
733
+ inst,
734
+ continue: !def.abort
735
+ });
736
+ };
737
+ });
738
+ const $ZodCheckMinLength = /* @__PURE__ */ $constructor("$ZodCheckMinLength", (inst, def) => {
739
+ $ZodCheck.init(inst, def);
740
+ inst._zod.when = (payload) => {
741
+ const val = payload.value;
742
+ return !nullish(val) && val.length !== void 0;
743
+ };
744
+ inst._zod.onattach.push((inst$1) => {
745
+ const curr = inst$1._zod.bag.minimum ?? Number.NEGATIVE_INFINITY;
746
+ if (def.minimum > curr) inst$1._zod.bag.minimum = def.minimum;
747
+ });
748
+ inst._zod.check = (payload) => {
749
+ const input = payload.value;
750
+ const length = input.length;
751
+ if (length >= def.minimum) return;
752
+ const origin = getLengthableOrigin(input);
753
+ payload.issues.push({
754
+ origin,
755
+ code: "too_small",
756
+ minimum: def.minimum,
757
+ inclusive: true,
758
+ input,
759
+ inst,
760
+ continue: !def.abort
761
+ });
762
+ };
763
+ });
764
+ const $ZodCheckLengthEquals = /* @__PURE__ */ $constructor("$ZodCheckLengthEquals", (inst, def) => {
765
+ $ZodCheck.init(inst, def);
766
+ inst._zod.when = (payload) => {
767
+ const val = payload.value;
768
+ return !nullish(val) && val.length !== void 0;
769
+ };
770
+ inst._zod.onattach.push((inst$1) => {
771
+ const bag = inst$1._zod.bag;
772
+ bag.minimum = def.length;
773
+ bag.maximum = def.length;
774
+ bag.length = def.length;
775
+ });
776
+ inst._zod.check = (payload) => {
777
+ const input = payload.value;
778
+ const length = input.length;
779
+ if (length === def.length) return;
780
+ const origin = getLengthableOrigin(input);
781
+ const tooBig = length > def.length;
782
+ payload.issues.push({
783
+ origin,
784
+ ...tooBig ? {
785
+ code: "too_big",
786
+ maximum: def.length
787
+ } : {
788
+ code: "too_small",
789
+ minimum: def.length
790
+ },
791
+ inclusive: true,
792
+ exact: true,
793
+ input: payload.value,
794
+ inst,
795
+ continue: !def.abort
796
+ });
797
+ };
798
+ });
799
+ const $ZodCheckStringFormat = /* @__PURE__ */ $constructor("$ZodCheckStringFormat", (inst, def) => {
800
+ var _a, _b;
801
+ $ZodCheck.init(inst, def);
802
+ inst._zod.onattach.push((inst$1) => {
803
+ const bag = inst$1._zod.bag;
804
+ bag.format = def.format;
805
+ if (def.pattern) {
806
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
807
+ bag.patterns.add(def.pattern);
808
+ }
809
+ });
810
+ if (def.pattern) (_a = inst._zod).check ?? (_a.check = (payload) => {
811
+ def.pattern.lastIndex = 0;
812
+ if (def.pattern.test(payload.value)) return;
813
+ payload.issues.push({
814
+ origin: "string",
815
+ code: "invalid_format",
816
+ format: def.format,
817
+ input: payload.value,
818
+ ...def.pattern ? { pattern: def.pattern.toString() } : {},
819
+ inst,
820
+ continue: !def.abort
821
+ });
822
+ });
823
+ else (_b = inst._zod).check ?? (_b.check = () => {});
824
+ });
825
+ const $ZodCheckRegex = /* @__PURE__ */ $constructor("$ZodCheckRegex", (inst, def) => {
826
+ $ZodCheckStringFormat.init(inst, def);
827
+ inst._zod.check = (payload) => {
828
+ def.pattern.lastIndex = 0;
829
+ if (def.pattern.test(payload.value)) return;
830
+ payload.issues.push({
831
+ origin: "string",
832
+ code: "invalid_format",
833
+ format: "regex",
834
+ input: payload.value,
835
+ pattern: def.pattern.toString(),
836
+ inst,
837
+ continue: !def.abort
838
+ });
839
+ };
840
+ });
841
+ const $ZodCheckLowerCase = /* @__PURE__ */ $constructor("$ZodCheckLowerCase", (inst, def) => {
842
+ def.pattern ?? (def.pattern = lowercase);
843
+ $ZodCheckStringFormat.init(inst, def);
844
+ });
845
+ const $ZodCheckUpperCase = /* @__PURE__ */ $constructor("$ZodCheckUpperCase", (inst, def) => {
846
+ def.pattern ?? (def.pattern = uppercase);
847
+ $ZodCheckStringFormat.init(inst, def);
848
+ });
849
+ const $ZodCheckIncludes = /* @__PURE__ */ $constructor("$ZodCheckIncludes", (inst, def) => {
850
+ $ZodCheck.init(inst, def);
851
+ const escapedRegex = escapeRegex(def.includes);
852
+ const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
853
+ def.pattern = pattern;
854
+ inst._zod.onattach.push((inst$1) => {
855
+ const bag = inst$1._zod.bag;
856
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
857
+ bag.patterns.add(pattern);
858
+ });
859
+ inst._zod.check = (payload) => {
860
+ if (payload.value.includes(def.includes, def.position)) return;
861
+ payload.issues.push({
862
+ origin: "string",
863
+ code: "invalid_format",
864
+ format: "includes",
865
+ includes: def.includes,
866
+ input: payload.value,
867
+ inst,
868
+ continue: !def.abort
869
+ });
870
+ };
871
+ });
872
+ const $ZodCheckStartsWith = /* @__PURE__ */ $constructor("$ZodCheckStartsWith", (inst, def) => {
873
+ $ZodCheck.init(inst, def);
874
+ const pattern = /* @__PURE__ */ new RegExp(`^${escapeRegex(def.prefix)}.*`);
875
+ def.pattern ?? (def.pattern = pattern);
876
+ inst._zod.onattach.push((inst$1) => {
877
+ const bag = inst$1._zod.bag;
878
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
879
+ bag.patterns.add(pattern);
880
+ });
881
+ inst._zod.check = (payload) => {
882
+ if (payload.value.startsWith(def.prefix)) return;
883
+ payload.issues.push({
884
+ origin: "string",
885
+ code: "invalid_format",
886
+ format: "starts_with",
887
+ prefix: def.prefix,
888
+ input: payload.value,
889
+ inst,
890
+ continue: !def.abort
891
+ });
892
+ };
893
+ });
894
+ const $ZodCheckEndsWith = /* @__PURE__ */ $constructor("$ZodCheckEndsWith", (inst, def) => {
895
+ $ZodCheck.init(inst, def);
896
+ const pattern = /* @__PURE__ */ new RegExp(`.*${escapeRegex(def.suffix)}$`);
897
+ def.pattern ?? (def.pattern = pattern);
898
+ inst._zod.onattach.push((inst$1) => {
899
+ const bag = inst$1._zod.bag;
900
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
901
+ bag.patterns.add(pattern);
902
+ });
903
+ inst._zod.check = (payload) => {
904
+ if (payload.value.endsWith(def.suffix)) return;
905
+ payload.issues.push({
906
+ origin: "string",
907
+ code: "invalid_format",
908
+ format: "ends_with",
909
+ suffix: def.suffix,
910
+ input: payload.value,
911
+ inst,
912
+ continue: !def.abort
913
+ });
914
+ };
915
+ });
916
+ const $ZodCheckOverwrite = /* @__PURE__ */ $constructor("$ZodCheckOverwrite", (inst, def) => {
917
+ $ZodCheck.init(inst, def);
918
+ inst._zod.check = (payload) => {
919
+ payload.value = def.tx(payload.value);
920
+ };
921
+ });
922
+
923
+ //#endregion
924
+ //#region ../../node_modules/zod/v4/core/doc.js
925
+ var Doc = class {
926
+ constructor(args = []) {
927
+ this.content = [];
928
+ this.indent = 0;
929
+ if (this) this.args = args;
930
+ }
931
+ indented(fn) {
932
+ this.indent += 1;
933
+ fn(this);
934
+ this.indent -= 1;
935
+ }
936
+ write(arg) {
937
+ if (typeof arg === "function") {
938
+ arg(this, { execution: "sync" });
939
+ arg(this, { execution: "async" });
940
+ return;
941
+ }
942
+ const content = arg;
943
+ const lines = content.split("\n").filter((x) => x);
944
+ const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
945
+ const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
946
+ for (const line of dedented) this.content.push(line);
947
+ }
948
+ compile() {
949
+ const F = Function;
950
+ const args = this?.args;
951
+ const content = this?.content ?? [``];
952
+ const lines = [...content.map((x) => ` ${x}`)];
953
+ return new F(...args, lines.join("\n"));
954
+ }
955
+ };
956
+
957
+ //#endregion
958
+ //#region ../../node_modules/zod/v4/core/versions.js
959
+ const version = {
960
+ major: 4,
961
+ minor: 0,
962
+ patch: 0
963
+ };
964
+
965
+ //#endregion
966
+ //#region ../../node_modules/zod/v4/core/schemas.js
967
+ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
968
+ var _a;
969
+ inst ?? (inst = {});
970
+ inst._zod.def = def;
971
+ inst._zod.bag = inst._zod.bag || {};
972
+ inst._zod.version = version;
973
+ const checks = [...inst._zod.def.checks ?? []];
974
+ if (inst._zod.traits.has("$ZodCheck")) checks.unshift(inst);
975
+ for (const ch of checks) for (const fn of ch._zod.onattach) fn(inst);
976
+ if (checks.length === 0) {
977
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
978
+ inst._zod.deferred?.push(() => {
979
+ inst._zod.run = inst._zod.parse;
980
+ });
981
+ } else {
982
+ const runChecks = (payload, checks$1, ctx) => {
983
+ let isAborted = aborted(payload);
984
+ let asyncResult;
985
+ for (const ch of checks$1) {
986
+ if (ch._zod.when) {
987
+ const shouldRun = ch._zod.when(payload);
988
+ if (!shouldRun) continue;
989
+ } else if (isAborted) continue;
990
+ const currLen = payload.issues.length;
991
+ const _ = ch._zod.check(payload);
992
+ if (_ instanceof Promise && ctx?.async === false) throw new $ZodAsyncError();
993
+ if (asyncResult || _ instanceof Promise) asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
994
+ await _;
995
+ const nextLen = payload.issues.length;
996
+ if (nextLen === currLen) return;
997
+ if (!isAborted) isAborted = aborted(payload, currLen);
998
+ });
999
+ else {
1000
+ const nextLen = payload.issues.length;
1001
+ if (nextLen === currLen) continue;
1002
+ if (!isAborted) isAborted = aborted(payload, currLen);
1003
+ }
1004
+ }
1005
+ if (asyncResult) return asyncResult.then(() => {
1006
+ return payload;
1007
+ });
1008
+ return payload;
1009
+ };
1010
+ inst._zod.run = (payload, ctx) => {
1011
+ const result = inst._zod.parse(payload, ctx);
1012
+ if (result instanceof Promise) {
1013
+ if (ctx.async === false) throw new $ZodAsyncError();
1014
+ return result.then((result$1) => runChecks(result$1, checks, ctx));
1015
+ }
1016
+ return runChecks(result, checks, ctx);
1017
+ };
1018
+ }
1019
+ inst["~standard"] = {
1020
+ validate: (value) => {
1021
+ try {
1022
+ const r = safeParse$1(inst, value);
1023
+ return r.success ? { value: r.data } : { issues: r.error?.issues };
1024
+ } catch (_) {
1025
+ return safeParseAsync$1(inst, value).then((r) => r.success ? { value: r.data } : { issues: r.error?.issues });
1026
+ }
1027
+ },
1028
+ vendor: "zod",
1029
+ version: 1
1030
+ };
1031
+ });
1032
+ const $ZodString = /* @__PURE__ */ $constructor("$ZodString", (inst, def) => {
1033
+ $ZodType.init(inst, def);
1034
+ inst._zod.pattern = [...inst?._zod.bag?.patterns ?? []].pop() ?? string$1(inst._zod.bag);
1035
+ inst._zod.parse = (payload, _) => {
1036
+ if (def.coerce) try {
1037
+ payload.value = String(payload.value);
1038
+ } catch (_$1) {}
1039
+ if (typeof payload.value === "string") return payload;
1040
+ payload.issues.push({
1041
+ expected: "string",
1042
+ code: "invalid_type",
1043
+ input: payload.value,
1044
+ inst
1045
+ });
1046
+ return payload;
1047
+ };
1048
+ });
1049
+ const $ZodStringFormat = /* @__PURE__ */ $constructor("$ZodStringFormat", (inst, def) => {
1050
+ $ZodCheckStringFormat.init(inst, def);
1051
+ $ZodString.init(inst, def);
1052
+ });
1053
+ const $ZodGUID = /* @__PURE__ */ $constructor("$ZodGUID", (inst, def) => {
1054
+ def.pattern ?? (def.pattern = guid);
1055
+ $ZodStringFormat.init(inst, def);
1056
+ });
1057
+ const $ZodUUID = /* @__PURE__ */ $constructor("$ZodUUID", (inst, def) => {
1058
+ if (def.version) {
1059
+ const versionMap = {
1060
+ v1: 1,
1061
+ v2: 2,
1062
+ v3: 3,
1063
+ v4: 4,
1064
+ v5: 5,
1065
+ v6: 6,
1066
+ v7: 7,
1067
+ v8: 8
1068
+ };
1069
+ const v = versionMap[def.version];
1070
+ if (v === void 0) throw new Error(`Invalid UUID version: "${def.version}"`);
1071
+ def.pattern ?? (def.pattern = uuid(v));
1072
+ } else def.pattern ?? (def.pattern = uuid());
1073
+ $ZodStringFormat.init(inst, def);
1074
+ });
1075
+ const $ZodEmail = /* @__PURE__ */ $constructor("$ZodEmail", (inst, def) => {
1076
+ def.pattern ?? (def.pattern = email);
1077
+ $ZodStringFormat.init(inst, def);
1078
+ });
1079
+ const $ZodURL = /* @__PURE__ */ $constructor("$ZodURL", (inst, def) => {
1080
+ $ZodStringFormat.init(inst, def);
1081
+ inst._zod.check = (payload) => {
1082
+ try {
1083
+ const orig = payload.value;
1084
+ const url = new URL(orig);
1085
+ const href = url.href;
1086
+ if (def.hostname) {
1087
+ def.hostname.lastIndex = 0;
1088
+ if (!def.hostname.test(url.hostname)) payload.issues.push({
1089
+ code: "invalid_format",
1090
+ format: "url",
1091
+ note: "Invalid hostname",
1092
+ pattern: hostname.source,
1093
+ input: payload.value,
1094
+ inst,
1095
+ continue: !def.abort
1096
+ });
1097
+ }
1098
+ if (def.protocol) {
1099
+ def.protocol.lastIndex = 0;
1100
+ if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) payload.issues.push({
1101
+ code: "invalid_format",
1102
+ format: "url",
1103
+ note: "Invalid protocol",
1104
+ pattern: def.protocol.source,
1105
+ input: payload.value,
1106
+ inst,
1107
+ continue: !def.abort
1108
+ });
1109
+ }
1110
+ if (!orig.endsWith("/") && href.endsWith("/")) payload.value = href.slice(0, -1);
1111
+ else payload.value = href;
1112
+ return;
1113
+ } catch (_) {
1114
+ payload.issues.push({
1115
+ code: "invalid_format",
1116
+ format: "url",
1117
+ input: payload.value,
1118
+ inst,
1119
+ continue: !def.abort
1120
+ });
1121
+ }
1122
+ };
1123
+ });
1124
+ const $ZodEmoji = /* @__PURE__ */ $constructor("$ZodEmoji", (inst, def) => {
1125
+ def.pattern ?? (def.pattern = emoji());
1126
+ $ZodStringFormat.init(inst, def);
1127
+ });
1128
+ const $ZodNanoID = /* @__PURE__ */ $constructor("$ZodNanoID", (inst, def) => {
1129
+ def.pattern ?? (def.pattern = nanoid);
1130
+ $ZodStringFormat.init(inst, def);
1131
+ });
1132
+ const $ZodCUID = /* @__PURE__ */ $constructor("$ZodCUID", (inst, def) => {
1133
+ def.pattern ?? (def.pattern = cuid);
1134
+ $ZodStringFormat.init(inst, def);
1135
+ });
1136
+ const $ZodCUID2 = /* @__PURE__ */ $constructor("$ZodCUID2", (inst, def) => {
1137
+ def.pattern ?? (def.pattern = cuid2);
1138
+ $ZodStringFormat.init(inst, def);
1139
+ });
1140
+ const $ZodULID = /* @__PURE__ */ $constructor("$ZodULID", (inst, def) => {
1141
+ def.pattern ?? (def.pattern = ulid);
1142
+ $ZodStringFormat.init(inst, def);
1143
+ });
1144
+ const $ZodXID = /* @__PURE__ */ $constructor("$ZodXID", (inst, def) => {
1145
+ def.pattern ?? (def.pattern = xid);
1146
+ $ZodStringFormat.init(inst, def);
1147
+ });
1148
+ const $ZodKSUID = /* @__PURE__ */ $constructor("$ZodKSUID", (inst, def) => {
1149
+ def.pattern ?? (def.pattern = ksuid);
1150
+ $ZodStringFormat.init(inst, def);
1151
+ });
1152
+ const $ZodISODateTime = /* @__PURE__ */ $constructor("$ZodISODateTime", (inst, def) => {
1153
+ def.pattern ?? (def.pattern = datetime$1(def));
1154
+ $ZodStringFormat.init(inst, def);
1155
+ });
1156
+ const $ZodISODate = /* @__PURE__ */ $constructor("$ZodISODate", (inst, def) => {
1157
+ def.pattern ?? (def.pattern = date$1);
1158
+ $ZodStringFormat.init(inst, def);
1159
+ });
1160
+ const $ZodISOTime = /* @__PURE__ */ $constructor("$ZodISOTime", (inst, def) => {
1161
+ def.pattern ?? (def.pattern = time$1(def));
1162
+ $ZodStringFormat.init(inst, def);
1163
+ });
1164
+ const $ZodISODuration = /* @__PURE__ */ $constructor("$ZodISODuration", (inst, def) => {
1165
+ def.pattern ?? (def.pattern = duration$1);
1166
+ $ZodStringFormat.init(inst, def);
1167
+ });
1168
+ const $ZodIPv4 = /* @__PURE__ */ $constructor("$ZodIPv4", (inst, def) => {
1169
+ def.pattern ?? (def.pattern = ipv4);
1170
+ $ZodStringFormat.init(inst, def);
1171
+ inst._zod.onattach.push((inst$1) => {
1172
+ const bag = inst$1._zod.bag;
1173
+ bag.format = `ipv4`;
1174
+ });
1175
+ });
1176
+ const $ZodIPv6 = /* @__PURE__ */ $constructor("$ZodIPv6", (inst, def) => {
1177
+ def.pattern ?? (def.pattern = ipv6);
1178
+ $ZodStringFormat.init(inst, def);
1179
+ inst._zod.onattach.push((inst$1) => {
1180
+ const bag = inst$1._zod.bag;
1181
+ bag.format = `ipv6`;
1182
+ });
1183
+ inst._zod.check = (payload) => {
1184
+ try {
1185
+ new URL(`http://[${payload.value}]`);
1186
+ } catch {
1187
+ payload.issues.push({
1188
+ code: "invalid_format",
1189
+ format: "ipv6",
1190
+ input: payload.value,
1191
+ inst,
1192
+ continue: !def.abort
1193
+ });
1194
+ }
1195
+ };
1196
+ });
1197
+ const $ZodCIDRv4 = /* @__PURE__ */ $constructor("$ZodCIDRv4", (inst, def) => {
1198
+ def.pattern ?? (def.pattern = cidrv4);
1199
+ $ZodStringFormat.init(inst, def);
1200
+ });
1201
+ const $ZodCIDRv6 = /* @__PURE__ */ $constructor("$ZodCIDRv6", (inst, def) => {
1202
+ def.pattern ?? (def.pattern = cidrv6);
1203
+ $ZodStringFormat.init(inst, def);
1204
+ inst._zod.check = (payload) => {
1205
+ const [address, prefix] = payload.value.split("/");
1206
+ try {
1207
+ if (!prefix) throw new Error();
1208
+ const prefixNum = Number(prefix);
1209
+ if (`${prefixNum}` !== prefix) throw new Error();
1210
+ if (prefixNum < 0 || prefixNum > 128) throw new Error();
1211
+ new URL(`http://[${address}]`);
1212
+ } catch {
1213
+ payload.issues.push({
1214
+ code: "invalid_format",
1215
+ format: "cidrv6",
1216
+ input: payload.value,
1217
+ inst,
1218
+ continue: !def.abort
1219
+ });
1220
+ }
1221
+ };
1222
+ });
1223
+ function isValidBase64(data) {
1224
+ if (data === "") return true;
1225
+ if (data.length % 4 !== 0) return false;
1226
+ try {
1227
+ atob(data);
1228
+ return true;
1229
+ } catch {
1230
+ return false;
1231
+ }
1232
+ }
1233
+ const $ZodBase64 = /* @__PURE__ */ $constructor("$ZodBase64", (inst, def) => {
1234
+ def.pattern ?? (def.pattern = base64);
1235
+ $ZodStringFormat.init(inst, def);
1236
+ inst._zod.onattach.push((inst$1) => {
1237
+ inst$1._zod.bag.contentEncoding = "base64";
1238
+ });
1239
+ inst._zod.check = (payload) => {
1240
+ if (isValidBase64(payload.value)) return;
1241
+ payload.issues.push({
1242
+ code: "invalid_format",
1243
+ format: "base64",
1244
+ input: payload.value,
1245
+ inst,
1246
+ continue: !def.abort
1247
+ });
1248
+ };
1249
+ });
1250
+ function isValidBase64URL(data) {
1251
+ if (!base64url.test(data)) return false;
1252
+ const base64$1 = data.replace(/[-_]/g, (c) => c === "-" ? "+" : "/");
1253
+ const padded = base64$1.padEnd(Math.ceil(base64$1.length / 4) * 4, "=");
1254
+ return isValidBase64(padded);
1255
+ }
1256
+ const $ZodBase64URL = /* @__PURE__ */ $constructor("$ZodBase64URL", (inst, def) => {
1257
+ def.pattern ?? (def.pattern = base64url);
1258
+ $ZodStringFormat.init(inst, def);
1259
+ inst._zod.onattach.push((inst$1) => {
1260
+ inst$1._zod.bag.contentEncoding = "base64url";
1261
+ });
1262
+ inst._zod.check = (payload) => {
1263
+ if (isValidBase64URL(payload.value)) return;
1264
+ payload.issues.push({
1265
+ code: "invalid_format",
1266
+ format: "base64url",
1267
+ input: payload.value,
1268
+ inst,
1269
+ continue: !def.abort
1270
+ });
1271
+ };
1272
+ });
1273
+ const $ZodE164 = /* @__PURE__ */ $constructor("$ZodE164", (inst, def) => {
1274
+ def.pattern ?? (def.pattern = e164);
1275
+ $ZodStringFormat.init(inst, def);
1276
+ });
1277
+ function isValidJWT(token, algorithm = null) {
1278
+ try {
1279
+ const tokensParts = token.split(".");
1280
+ if (tokensParts.length !== 3) return false;
1281
+ const [header] = tokensParts;
1282
+ if (!header) return false;
1283
+ const parsedHeader = JSON.parse(atob(header));
1284
+ if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT") return false;
1285
+ if (!parsedHeader.alg) return false;
1286
+ if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm)) return false;
1287
+ return true;
1288
+ } catch {
1289
+ return false;
1290
+ }
1291
+ }
1292
+ const $ZodJWT = /* @__PURE__ */ $constructor("$ZodJWT", (inst, def) => {
1293
+ $ZodStringFormat.init(inst, def);
1294
+ inst._zod.check = (payload) => {
1295
+ if (isValidJWT(payload.value, def.alg)) return;
1296
+ payload.issues.push({
1297
+ code: "invalid_format",
1298
+ format: "jwt",
1299
+ input: payload.value,
1300
+ inst,
1301
+ continue: !def.abort
1302
+ });
1303
+ };
1304
+ });
1305
+ const $ZodNumber = /* @__PURE__ */ $constructor("$ZodNumber", (inst, def) => {
1306
+ $ZodType.init(inst, def);
1307
+ inst._zod.pattern = inst._zod.bag.pattern ?? number$1;
1308
+ inst._zod.parse = (payload, _ctx) => {
1309
+ if (def.coerce) try {
1310
+ payload.value = Number(payload.value);
1311
+ } catch (_) {}
1312
+ const input = payload.value;
1313
+ if (typeof input === "number" && !Number.isNaN(input) && Number.isFinite(input)) return payload;
1314
+ const received = typeof input === "number" ? Number.isNaN(input) ? "NaN" : !Number.isFinite(input) ? "Infinity" : void 0 : void 0;
1315
+ payload.issues.push({
1316
+ expected: "number",
1317
+ code: "invalid_type",
1318
+ input,
1319
+ inst,
1320
+ ...received ? { received } : {}
1321
+ });
1322
+ return payload;
1323
+ };
1324
+ });
1325
+ const $ZodNumberFormat = /* @__PURE__ */ $constructor("$ZodNumber", (inst, def) => {
1326
+ $ZodCheckNumberFormat.init(inst, def);
1327
+ $ZodNumber.init(inst, def);
1328
+ });
1329
+ const $ZodBoolean = /* @__PURE__ */ $constructor("$ZodBoolean", (inst, def) => {
1330
+ $ZodType.init(inst, def);
1331
+ inst._zod.pattern = boolean$1;
1332
+ inst._zod.parse = (payload, _ctx) => {
1333
+ if (def.coerce) try {
1334
+ payload.value = Boolean(payload.value);
1335
+ } catch (_) {}
1336
+ const input = payload.value;
1337
+ if (typeof input === "boolean") return payload;
1338
+ payload.issues.push({
1339
+ expected: "boolean",
1340
+ code: "invalid_type",
1341
+ input,
1342
+ inst
1343
+ });
1344
+ return payload;
1345
+ };
1346
+ });
1347
+ const $ZodAny = /* @__PURE__ */ $constructor("$ZodAny", (inst, def) => {
1348
+ $ZodType.init(inst, def);
1349
+ inst._zod.parse = (payload) => payload;
1350
+ });
1351
+ const $ZodUnknown = /* @__PURE__ */ $constructor("$ZodUnknown", (inst, def) => {
1352
+ $ZodType.init(inst, def);
1353
+ inst._zod.parse = (payload) => payload;
1354
+ });
1355
+ const $ZodNever = /* @__PURE__ */ $constructor("$ZodNever", (inst, def) => {
1356
+ $ZodType.init(inst, def);
1357
+ inst._zod.parse = (payload, _ctx) => {
1358
+ payload.issues.push({
1359
+ expected: "never",
1360
+ code: "invalid_type",
1361
+ input: payload.value,
1362
+ inst
1363
+ });
1364
+ return payload;
1365
+ };
1366
+ });
1367
+ function handleArrayResult(result, final, index) {
1368
+ if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
1369
+ final.value[index] = result.value;
1370
+ }
1371
+ const $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
1372
+ $ZodType.init(inst, def);
1373
+ inst._zod.parse = (payload, ctx) => {
1374
+ const input = payload.value;
1375
+ if (!Array.isArray(input)) {
1376
+ payload.issues.push({
1377
+ expected: "array",
1378
+ code: "invalid_type",
1379
+ input,
1380
+ inst
1381
+ });
1382
+ return payload;
1383
+ }
1384
+ payload.value = Array(input.length);
1385
+ const proms = [];
1386
+ for (let i = 0; i < input.length; i++) {
1387
+ const item = input[i];
1388
+ const result = def.element._zod.run({
1389
+ value: item,
1390
+ issues: []
1391
+ }, ctx);
1392
+ if (result instanceof Promise) proms.push(result.then((result$1) => handleArrayResult(result$1, payload, i)));
1393
+ else handleArrayResult(result, payload, i);
1394
+ }
1395
+ if (proms.length) return Promise.all(proms).then(() => payload);
1396
+ return payload;
1397
+ };
1398
+ });
1399
+ function handleObjectResult(result, final, key) {
1400
+ if (result.issues.length) final.issues.push(...prefixIssues(key, result.issues));
1401
+ final.value[key] = result.value;
1402
+ }
1403
+ function handleOptionalObjectResult(result, final, key, input) {
1404
+ if (result.issues.length) if (input[key] === void 0) if (key in input) final.value[key] = void 0;
1405
+ else final.value[key] = result.value;
1406
+ else final.issues.push(...prefixIssues(key, result.issues));
1407
+ else if (result.value === void 0) {
1408
+ if (key in input) final.value[key] = void 0;
1409
+ } else final.value[key] = result.value;
1410
+ }
1411
+ const $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
1412
+ $ZodType.init(inst, def);
1413
+ const _normalized = cached(() => {
1414
+ const keys = Object.keys(def.shape);
1415
+ for (const k of keys) if (!(def.shape[k] instanceof $ZodType)) throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
1416
+ const okeys = optionalKeys(def.shape);
1417
+ return {
1418
+ shape: def.shape,
1419
+ keys,
1420
+ keySet: new Set(keys),
1421
+ numKeys: keys.length,
1422
+ optionalKeys: new Set(okeys)
1423
+ };
1424
+ });
1425
+ defineLazy(inst._zod, "propValues", () => {
1426
+ const shape = def.shape;
1427
+ const propValues = {};
1428
+ for (const key in shape) {
1429
+ const field = shape[key]._zod;
1430
+ if (field.values) {
1431
+ propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
1432
+ for (const v of field.values) propValues[key].add(v);
1433
+ }
1434
+ }
1435
+ return propValues;
1436
+ });
1437
+ const generateFastpass = (shape) => {
1438
+ const doc = new Doc([
1439
+ "shape",
1440
+ "payload",
1441
+ "ctx"
1442
+ ]);
1443
+ const normalized = _normalized.value;
1444
+ const parseStr = (key) => {
1445
+ const k = esc(key);
1446
+ return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
1447
+ };
1448
+ doc.write(`const input = payload.value;`);
1449
+ const ids = Object.create(null);
1450
+ let counter = 0;
1451
+ for (const key of normalized.keys) ids[key] = `key_${counter++}`;
1452
+ doc.write(`const newResult = {}`);
1453
+ for (const key of normalized.keys) if (normalized.optionalKeys.has(key)) {
1454
+ const id = ids[key];
1455
+ doc.write(`const ${id} = ${parseStr(key)};`);
1456
+ const k = esc(key);
1457
+ doc.write(`
1458
+ if (${id}.issues.length) {
1459
+ if (input[${k}] === undefined) {
1460
+ if (${k} in input) {
1461
+ newResult[${k}] = undefined;
1462
+ }
1463
+ } else {
1464
+ payload.issues = payload.issues.concat(
1465
+ ${id}.issues.map((iss) => ({
1466
+ ...iss,
1467
+ path: iss.path ? [${k}, ...iss.path] : [${k}],
1468
+ }))
1469
+ );
1470
+ }
1471
+ } else if (${id}.value === undefined) {
1472
+ if (${k} in input) newResult[${k}] = undefined;
1473
+ } else {
1474
+ newResult[${k}] = ${id}.value;
1475
+ }
1476
+ `);
1477
+ } else {
1478
+ const id = ids[key];
1479
+ doc.write(`const ${id} = ${parseStr(key)};`);
1480
+ doc.write(`
1481
+ if (${id}.issues.length) payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
1482
+ ...iss,
1483
+ path: iss.path ? [${esc(key)}, ...iss.path] : [${esc(key)}]
1484
+ })));`);
1485
+ doc.write(`newResult[${esc(key)}] = ${id}.value`);
1486
+ }
1487
+ doc.write(`payload.value = newResult;`);
1488
+ doc.write(`return payload;`);
1489
+ const fn = doc.compile();
1490
+ return (payload, ctx) => fn(shape, payload, ctx);
1491
+ };
1492
+ let fastpass;
1493
+ const isObject$2 = isObject$1;
1494
+ const jit = !globalConfig.jitless;
1495
+ const allowsEval$1 = allowsEval;
1496
+ const fastEnabled = jit && allowsEval$1.value;
1497
+ const catchall = def.catchall;
1498
+ let value;
1499
+ inst._zod.parse = (payload, ctx) => {
1500
+ value ?? (value = _normalized.value);
1501
+ const input = payload.value;
1502
+ if (!isObject$2(input)) {
1503
+ payload.issues.push({
1504
+ expected: "object",
1505
+ code: "invalid_type",
1506
+ input,
1507
+ inst
1508
+ });
1509
+ return payload;
1510
+ }
1511
+ const proms = [];
1512
+ if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
1513
+ if (!fastpass) fastpass = generateFastpass(def.shape);
1514
+ payload = fastpass(payload, ctx);
1515
+ } else {
1516
+ payload.value = {};
1517
+ const shape = value.shape;
1518
+ for (const key of value.keys) {
1519
+ const el = shape[key];
1520
+ const r = el._zod.run({
1521
+ value: input[key],
1522
+ issues: []
1523
+ }, ctx);
1524
+ const isOptional = el._zod.optin === "optional" && el._zod.optout === "optional";
1525
+ if (r instanceof Promise) proms.push(r.then((r$1) => isOptional ? handleOptionalObjectResult(r$1, payload, key, input) : handleObjectResult(r$1, payload, key)));
1526
+ else if (isOptional) handleOptionalObjectResult(r, payload, key, input);
1527
+ else handleObjectResult(r, payload, key);
1528
+ }
1529
+ }
1530
+ if (!catchall) return proms.length ? Promise.all(proms).then(() => payload) : payload;
1531
+ const unrecognized = [];
1532
+ const keySet = value.keySet;
1533
+ const _catchall = catchall._zod;
1534
+ const t = _catchall.def.type;
1535
+ for (const key of Object.keys(input)) {
1536
+ if (keySet.has(key)) continue;
1537
+ if (t === "never") {
1538
+ unrecognized.push(key);
1539
+ continue;
1540
+ }
1541
+ const r = _catchall.run({
1542
+ value: input[key],
1543
+ issues: []
1544
+ }, ctx);
1545
+ if (r instanceof Promise) proms.push(r.then((r$1) => handleObjectResult(r$1, payload, key)));
1546
+ else handleObjectResult(r, payload, key);
1547
+ }
1548
+ if (unrecognized.length) payload.issues.push({
1549
+ code: "unrecognized_keys",
1550
+ keys: unrecognized,
1551
+ input,
1552
+ inst
1553
+ });
1554
+ if (!proms.length) return payload;
1555
+ return Promise.all(proms).then(() => {
1556
+ return payload;
1557
+ });
1558
+ };
1559
+ });
1560
+ function handleUnionResults(results, final, inst, ctx) {
1561
+ for (const result of results) if (result.issues.length === 0) {
1562
+ final.value = result.value;
1563
+ return final;
1564
+ }
1565
+ final.issues.push({
1566
+ code: "invalid_union",
1567
+ input: final.value,
1568
+ inst,
1569
+ errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
1570
+ });
1571
+ return final;
1572
+ }
1573
+ const $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
1574
+ $ZodType.init(inst, def);
1575
+ defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : void 0);
1576
+ defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : void 0);
1577
+ defineLazy(inst._zod, "values", () => {
1578
+ if (def.options.every((o) => o._zod.values)) return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
1579
+ return void 0;
1580
+ });
1581
+ defineLazy(inst._zod, "pattern", () => {
1582
+ if (def.options.every((o) => o._zod.pattern)) {
1583
+ const patterns = def.options.map((o) => o._zod.pattern);
1584
+ return /* @__PURE__ */ new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
1585
+ }
1586
+ return void 0;
1587
+ });
1588
+ inst._zod.parse = (payload, ctx) => {
1589
+ let async = false;
1590
+ const results = [];
1591
+ for (const option of def.options) {
1592
+ const result = option._zod.run({
1593
+ value: payload.value,
1594
+ issues: []
1595
+ }, ctx);
1596
+ if (result instanceof Promise) {
1597
+ results.push(result);
1598
+ async = true;
1599
+ } else {
1600
+ if (result.issues.length === 0) return result;
1601
+ results.push(result);
1602
+ }
1603
+ }
1604
+ if (!async) return handleUnionResults(results, payload, inst, ctx);
1605
+ return Promise.all(results).then((results$1) => {
1606
+ return handleUnionResults(results$1, payload, inst, ctx);
1607
+ });
1608
+ };
1609
+ });
1610
+ const $ZodDiscriminatedUnion = /* @__PURE__ */ $constructor("$ZodDiscriminatedUnion", (inst, def) => {
1611
+ $ZodUnion.init(inst, def);
1612
+ const _super = inst._zod.parse;
1613
+ defineLazy(inst._zod, "propValues", () => {
1614
+ const propValues = {};
1615
+ for (const option of def.options) {
1616
+ const pv = option._zod.propValues;
1617
+ if (!pv || Object.keys(pv).length === 0) throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
1618
+ for (const [k, v] of Object.entries(pv)) {
1619
+ if (!propValues[k]) propValues[k] = /* @__PURE__ */ new Set();
1620
+ for (const val of v) propValues[k].add(val);
1621
+ }
1622
+ }
1623
+ return propValues;
1624
+ });
1625
+ const disc = cached(() => {
1626
+ const opts = def.options;
1627
+ const map = /* @__PURE__ */ new Map();
1628
+ for (const o of opts) {
1629
+ const values = o._zod.propValues[def.discriminator];
1630
+ if (!values || values.size === 0) throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
1631
+ for (const v of values) {
1632
+ if (map.has(v)) throw new Error(`Duplicate discriminator value "${String(v)}"`);
1633
+ map.set(v, o);
1634
+ }
1635
+ }
1636
+ return map;
1637
+ });
1638
+ inst._zod.parse = (payload, ctx) => {
1639
+ const input = payload.value;
1640
+ if (!isObject$1(input)) {
1641
+ payload.issues.push({
1642
+ code: "invalid_type",
1643
+ expected: "object",
1644
+ input,
1645
+ inst
1646
+ });
1647
+ return payload;
1648
+ }
1649
+ const opt = disc.value.get(input?.[def.discriminator]);
1650
+ if (opt) return opt._zod.run(payload, ctx);
1651
+ if (def.unionFallback) return _super(payload, ctx);
1652
+ payload.issues.push({
1653
+ code: "invalid_union",
1654
+ errors: [],
1655
+ note: "No matching discriminator",
1656
+ input,
1657
+ path: [def.discriminator],
1658
+ inst
1659
+ });
1660
+ return payload;
1661
+ };
1662
+ });
1663
+ const $ZodIntersection = /* @__PURE__ */ $constructor("$ZodIntersection", (inst, def) => {
1664
+ $ZodType.init(inst, def);
1665
+ inst._zod.parse = (payload, ctx) => {
1666
+ const input = payload.value;
1667
+ const left = def.left._zod.run({
1668
+ value: input,
1669
+ issues: []
1670
+ }, ctx);
1671
+ const right = def.right._zod.run({
1672
+ value: input,
1673
+ issues: []
1674
+ }, ctx);
1675
+ const async = left instanceof Promise || right instanceof Promise;
1676
+ if (async) return Promise.all([left, right]).then(([left$1, right$1]) => {
1677
+ return handleIntersectionResults(payload, left$1, right$1);
1678
+ });
1679
+ return handleIntersectionResults(payload, left, right);
1680
+ };
1681
+ });
1682
+ function mergeValues(a, b) {
1683
+ if (a === b) return {
1684
+ valid: true,
1685
+ data: a
1686
+ };
1687
+ if (a instanceof Date && b instanceof Date && +a === +b) return {
1688
+ valid: true,
1689
+ data: a
1690
+ };
1691
+ if (isPlainObject(a) && isPlainObject(b)) {
1692
+ const bKeys = Object.keys(b);
1693
+ const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
1694
+ const newObj = {
1695
+ ...a,
1696
+ ...b
1697
+ };
1698
+ for (const key of sharedKeys) {
1699
+ const sharedValue = mergeValues(a[key], b[key]);
1700
+ if (!sharedValue.valid) return {
1701
+ valid: false,
1702
+ mergeErrorPath: [key, ...sharedValue.mergeErrorPath]
1703
+ };
1704
+ newObj[key] = sharedValue.data;
1705
+ }
1706
+ return {
1707
+ valid: true,
1708
+ data: newObj
1709
+ };
1710
+ }
1711
+ if (Array.isArray(a) && Array.isArray(b)) {
1712
+ if (a.length !== b.length) return {
1713
+ valid: false,
1714
+ mergeErrorPath: []
1715
+ };
1716
+ const newArray = [];
1717
+ for (let index = 0; index < a.length; index++) {
1718
+ const itemA = a[index];
1719
+ const itemB = b[index];
1720
+ const sharedValue = mergeValues(itemA, itemB);
1721
+ if (!sharedValue.valid) return {
1722
+ valid: false,
1723
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath]
1724
+ };
1725
+ newArray.push(sharedValue.data);
1726
+ }
1727
+ return {
1728
+ valid: true,
1729
+ data: newArray
1730
+ };
1731
+ }
1732
+ return {
1733
+ valid: false,
1734
+ mergeErrorPath: []
1735
+ };
1736
+ }
1737
+ function handleIntersectionResults(result, left, right) {
1738
+ if (left.issues.length) result.issues.push(...left.issues);
1739
+ if (right.issues.length) result.issues.push(...right.issues);
1740
+ if (aborted(result)) return result;
1741
+ const merged = mergeValues(left.value, right.value);
1742
+ if (!merged.valid) throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`);
1743
+ result.value = merged.data;
1744
+ return result;
1745
+ }
1746
+ const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
1747
+ $ZodType.init(inst, def);
1748
+ inst._zod.parse = (payload, ctx) => {
1749
+ const input = payload.value;
1750
+ if (!isPlainObject(input)) {
1751
+ payload.issues.push({
1752
+ expected: "record",
1753
+ code: "invalid_type",
1754
+ input,
1755
+ inst
1756
+ });
1757
+ return payload;
1758
+ }
1759
+ const proms = [];
1760
+ if (def.keyType._zod.values) {
1761
+ const values = def.keyType._zod.values;
1762
+ payload.value = {};
1763
+ for (const key of values) if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
1764
+ const result = def.valueType._zod.run({
1765
+ value: input[key],
1766
+ issues: []
1767
+ }, ctx);
1768
+ if (result instanceof Promise) proms.push(result.then((result$1) => {
1769
+ if (result$1.issues.length) payload.issues.push(...prefixIssues(key, result$1.issues));
1770
+ payload.value[key] = result$1.value;
1771
+ }));
1772
+ else {
1773
+ if (result.issues.length) payload.issues.push(...prefixIssues(key, result.issues));
1774
+ payload.value[key] = result.value;
1775
+ }
1776
+ }
1777
+ let unrecognized;
1778
+ for (const key in input) if (!values.has(key)) {
1779
+ unrecognized = unrecognized ?? [];
1780
+ unrecognized.push(key);
1781
+ }
1782
+ if (unrecognized && unrecognized.length > 0) payload.issues.push({
1783
+ code: "unrecognized_keys",
1784
+ input,
1785
+ inst,
1786
+ keys: unrecognized
1787
+ });
1788
+ } else {
1789
+ payload.value = {};
1790
+ for (const key of Reflect.ownKeys(input)) {
1791
+ if (key === "__proto__") continue;
1792
+ const keyResult = def.keyType._zod.run({
1793
+ value: key,
1794
+ issues: []
1795
+ }, ctx);
1796
+ if (keyResult instanceof Promise) throw new Error("Async schemas not supported in object keys currently");
1797
+ if (keyResult.issues.length) {
1798
+ payload.issues.push({
1799
+ origin: "record",
1800
+ code: "invalid_key",
1801
+ issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx, config())),
1802
+ input: key,
1803
+ path: [key],
1804
+ inst
1805
+ });
1806
+ payload.value[keyResult.value] = keyResult.value;
1807
+ continue;
1808
+ }
1809
+ const result = def.valueType._zod.run({
1810
+ value: input[key],
1811
+ issues: []
1812
+ }, ctx);
1813
+ if (result instanceof Promise) proms.push(result.then((result$1) => {
1814
+ if (result$1.issues.length) payload.issues.push(...prefixIssues(key, result$1.issues));
1815
+ payload.value[keyResult.value] = result$1.value;
1816
+ }));
1817
+ else {
1818
+ if (result.issues.length) payload.issues.push(...prefixIssues(key, result.issues));
1819
+ payload.value[keyResult.value] = result.value;
1820
+ }
1821
+ }
1822
+ }
1823
+ if (proms.length) return Promise.all(proms).then(() => payload);
1824
+ return payload;
1825
+ };
1826
+ });
1827
+ const $ZodEnum = /* @__PURE__ */ $constructor("$ZodEnum", (inst, def) => {
1828
+ $ZodType.init(inst, def);
1829
+ const values = getEnumValues(def.entries);
1830
+ inst._zod.values = new Set(values);
1831
+ inst._zod.pattern = /* @__PURE__ */ new RegExp(`^(${values.filter((k) => propertyKeyTypes.has(typeof k)).map((o) => typeof o === "string" ? escapeRegex(o) : o.toString()).join("|")})$`);
1832
+ inst._zod.parse = (payload, _ctx) => {
1833
+ const input = payload.value;
1834
+ if (inst._zod.values.has(input)) return payload;
1835
+ payload.issues.push({
1836
+ code: "invalid_value",
1837
+ values,
1838
+ input,
1839
+ inst
1840
+ });
1841
+ return payload;
1842
+ };
1843
+ });
1844
+ const $ZodLiteral = /* @__PURE__ */ $constructor("$ZodLiteral", (inst, def) => {
1845
+ $ZodType.init(inst, def);
1846
+ inst._zod.values = new Set(def.values);
1847
+ inst._zod.pattern = /* @__PURE__ */ new RegExp(`^(${def.values.map((o) => typeof o === "string" ? escapeRegex(o) : o ? o.toString() : String(o)).join("|")})$`);
1848
+ inst._zod.parse = (payload, _ctx) => {
1849
+ const input = payload.value;
1850
+ if (inst._zod.values.has(input)) return payload;
1851
+ payload.issues.push({
1852
+ code: "invalid_value",
1853
+ values: def.values,
1854
+ input,
1855
+ inst
1856
+ });
1857
+ return payload;
1858
+ };
1859
+ });
1860
+ const $ZodTransform = /* @__PURE__ */ $constructor("$ZodTransform", (inst, def) => {
1861
+ $ZodType.init(inst, def);
1862
+ inst._zod.parse = (payload, _ctx) => {
1863
+ const _out = def.transform(payload.value, payload);
1864
+ if (_ctx.async) {
1865
+ const output = _out instanceof Promise ? _out : Promise.resolve(_out);
1866
+ return output.then((output$1) => {
1867
+ payload.value = output$1;
1868
+ return payload;
1869
+ });
1870
+ }
1871
+ if (_out instanceof Promise) throw new $ZodAsyncError();
1872
+ payload.value = _out;
1873
+ return payload;
1874
+ };
1875
+ });
1876
+ const $ZodOptional = /* @__PURE__ */ $constructor("$ZodOptional", (inst, def) => {
1877
+ $ZodType.init(inst, def);
1878
+ inst._zod.optin = "optional";
1879
+ inst._zod.optout = "optional";
1880
+ defineLazy(inst._zod, "values", () => {
1881
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, void 0]) : void 0;
1882
+ });
1883
+ defineLazy(inst._zod, "pattern", () => {
1884
+ const pattern = def.innerType._zod.pattern;
1885
+ return pattern ? /* @__PURE__ */ new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
1886
+ });
1887
+ inst._zod.parse = (payload, ctx) => {
1888
+ if (def.innerType._zod.optin === "optional") return def.innerType._zod.run(payload, ctx);
1889
+ if (payload.value === void 0) return payload;
1890
+ return def.innerType._zod.run(payload, ctx);
1891
+ };
1892
+ });
1893
+ const $ZodNullable = /* @__PURE__ */ $constructor("$ZodNullable", (inst, def) => {
1894
+ $ZodType.init(inst, def);
1895
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1896
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1897
+ defineLazy(inst._zod, "pattern", () => {
1898
+ const pattern = def.innerType._zod.pattern;
1899
+ return pattern ? /* @__PURE__ */ new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : void 0;
1900
+ });
1901
+ defineLazy(inst._zod, "values", () => {
1902
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : void 0;
1903
+ });
1904
+ inst._zod.parse = (payload, ctx) => {
1905
+ if (payload.value === null) return payload;
1906
+ return def.innerType._zod.run(payload, ctx);
1907
+ };
1908
+ });
1909
+ const $ZodDefault = /* @__PURE__ */ $constructor("$ZodDefault", (inst, def) => {
1910
+ $ZodType.init(inst, def);
1911
+ inst._zod.optin = "optional";
1912
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1913
+ inst._zod.parse = (payload, ctx) => {
1914
+ if (payload.value === void 0) {
1915
+ payload.value = def.defaultValue;
1916
+ /**
1917
+ * $ZodDefault always returns the default value immediately.
1918
+ * It doesn't pass the default value into the validator ("prefault"). There's no reason to pass the default value through validation. The validity of the default is enforced by TypeScript statically. Otherwise, it's the responsibility of the user to ensure the default is valid. In the case of pipes with divergent in/out types, you can specify the default on the `in` schema of your ZodPipe to set a "prefault" for the pipe. */
1919
+ return payload;
1920
+ }
1921
+ const result = def.innerType._zod.run(payload, ctx);
1922
+ if (result instanceof Promise) return result.then((result$1) => handleDefaultResult(result$1, def));
1923
+ return handleDefaultResult(result, def);
1924
+ };
1925
+ });
1926
+ function handleDefaultResult(payload, def) {
1927
+ if (payload.value === void 0) payload.value = def.defaultValue;
1928
+ return payload;
1929
+ }
1930
+ const $ZodPrefault = /* @__PURE__ */ $constructor("$ZodPrefault", (inst, def) => {
1931
+ $ZodType.init(inst, def);
1932
+ inst._zod.optin = "optional";
1933
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1934
+ inst._zod.parse = (payload, ctx) => {
1935
+ if (payload.value === void 0) payload.value = def.defaultValue;
1936
+ return def.innerType._zod.run(payload, ctx);
1937
+ };
1938
+ });
1939
+ const $ZodNonOptional = /* @__PURE__ */ $constructor("$ZodNonOptional", (inst, def) => {
1940
+ $ZodType.init(inst, def);
1941
+ defineLazy(inst._zod, "values", () => {
1942
+ const v = def.innerType._zod.values;
1943
+ return v ? new Set([...v].filter((x) => x !== void 0)) : void 0;
1944
+ });
1945
+ inst._zod.parse = (payload, ctx) => {
1946
+ const result = def.innerType._zod.run(payload, ctx);
1947
+ if (result instanceof Promise) return result.then((result$1) => handleNonOptionalResult(result$1, inst));
1948
+ return handleNonOptionalResult(result, inst);
1949
+ };
1950
+ });
1951
+ function handleNonOptionalResult(payload, inst) {
1952
+ if (!payload.issues.length && payload.value === void 0) payload.issues.push({
1953
+ code: "invalid_type",
1954
+ expected: "nonoptional",
1955
+ input: payload.value,
1956
+ inst
1957
+ });
1958
+ return payload;
1959
+ }
1960
+ const $ZodCatch = /* @__PURE__ */ $constructor("$ZodCatch", (inst, def) => {
1961
+ $ZodType.init(inst, def);
1962
+ inst._zod.optin = "optional";
1963
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1964
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1965
+ inst._zod.parse = (payload, ctx) => {
1966
+ const result = def.innerType._zod.run(payload, ctx);
1967
+ if (result instanceof Promise) return result.then((result$1) => {
1968
+ payload.value = result$1.value;
1969
+ if (result$1.issues.length) {
1970
+ payload.value = def.catchValue({
1971
+ ...payload,
1972
+ error: { issues: result$1.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
1973
+ input: payload.value
1974
+ });
1975
+ payload.issues = [];
1976
+ }
1977
+ return payload;
1978
+ });
1979
+ payload.value = result.value;
1980
+ if (result.issues.length) {
1981
+ payload.value = def.catchValue({
1982
+ ...payload,
1983
+ error: { issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
1984
+ input: payload.value
1985
+ });
1986
+ payload.issues = [];
1987
+ }
1988
+ return payload;
1989
+ };
1990
+ });
1991
+ const $ZodPipe = /* @__PURE__ */ $constructor("$ZodPipe", (inst, def) => {
1992
+ $ZodType.init(inst, def);
1993
+ defineLazy(inst._zod, "values", () => def.in._zod.values);
1994
+ defineLazy(inst._zod, "optin", () => def.in._zod.optin);
1995
+ defineLazy(inst._zod, "optout", () => def.out._zod.optout);
1996
+ inst._zod.parse = (payload, ctx) => {
1997
+ const left = def.in._zod.run(payload, ctx);
1998
+ if (left instanceof Promise) return left.then((left$1) => handlePipeResult(left$1, def, ctx));
1999
+ return handlePipeResult(left, def, ctx);
2000
+ };
2001
+ });
2002
+ function handlePipeResult(left, def, ctx) {
2003
+ if (aborted(left)) return left;
2004
+ return def.out._zod.run({
2005
+ value: left.value,
2006
+ issues: left.issues
2007
+ }, ctx);
2008
+ }
2009
+ const $ZodReadonly = /* @__PURE__ */ $constructor("$ZodReadonly", (inst, def) => {
2010
+ $ZodType.init(inst, def);
2011
+ defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
2012
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2013
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
2014
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
2015
+ inst._zod.parse = (payload, ctx) => {
2016
+ const result = def.innerType._zod.run(payload, ctx);
2017
+ if (result instanceof Promise) return result.then(handleReadonlyResult);
2018
+ return handleReadonlyResult(result);
2019
+ };
2020
+ });
2021
+ function handleReadonlyResult(payload) {
2022
+ payload.value = Object.freeze(payload.value);
2023
+ return payload;
2024
+ }
2025
+ const $ZodCustom = /* @__PURE__ */ $constructor("$ZodCustom", (inst, def) => {
2026
+ $ZodCheck.init(inst, def);
2027
+ $ZodType.init(inst, def);
2028
+ inst._zod.parse = (payload, _) => {
2029
+ return payload;
2030
+ };
2031
+ inst._zod.check = (payload) => {
2032
+ const input = payload.value;
2033
+ const r = def.fn(input);
2034
+ if (r instanceof Promise) return r.then((r$1) => handleRefineResult(r$1, payload, input, inst));
2035
+ handleRefineResult(r, payload, input, inst);
2036
+ return;
2037
+ };
2038
+ });
2039
+ function handleRefineResult(result, payload, input, inst) {
2040
+ if (!result) {
2041
+ const _iss = {
2042
+ code: "custom",
2043
+ input,
2044
+ inst,
2045
+ path: [...inst._zod.def.path ?? []],
2046
+ continue: !inst._zod.def.abort
2047
+ };
2048
+ if (inst._zod.def.params) _iss.params = inst._zod.def.params;
2049
+ payload.issues.push(issue(_iss));
2050
+ }
2051
+ }
2052
+
2053
+ //#endregion
2054
+ //#region ../../node_modules/zod/v4/core/registries.js
2055
+ const $output = Symbol("ZodOutput");
2056
+ const $input = Symbol("ZodInput");
2057
+ var $ZodRegistry = class {
2058
+ constructor() {
2059
+ this._map = /* @__PURE__ */ new WeakMap();
2060
+ this._idmap = /* @__PURE__ */ new Map();
2061
+ }
2062
+ add(schema, ..._meta) {
2063
+ const meta = _meta[0];
2064
+ this._map.set(schema, meta);
2065
+ if (meta && typeof meta === "object" && "id" in meta) {
2066
+ if (this._idmap.has(meta.id)) throw new Error(`ID ${meta.id} already exists in the registry`);
2067
+ this._idmap.set(meta.id, schema);
2068
+ }
2069
+ return this;
2070
+ }
2071
+ remove(schema) {
2072
+ this._map.delete(schema);
2073
+ return this;
2074
+ }
2075
+ get(schema) {
2076
+ const p = schema._zod.parent;
2077
+ if (p) {
2078
+ const pm = { ...this.get(p) ?? {} };
2079
+ delete pm.id;
2080
+ return {
2081
+ ...pm,
2082
+ ...this._map.get(schema)
2083
+ };
2084
+ }
2085
+ return this._map.get(schema);
2086
+ }
2087
+ has(schema) {
2088
+ return this._map.has(schema);
2089
+ }
2090
+ };
2091
+ function registry() {
2092
+ return new $ZodRegistry();
2093
+ }
2094
+ const globalRegistry = /* @__PURE__ */ registry();
2095
+
2096
+ //#endregion
2097
+ //#region ../../node_modules/zod/v4/core/api.js
2098
+ function _string(Class, params) {
2099
+ return new Class({
2100
+ type: "string",
2101
+ ...normalizeParams(params)
2102
+ });
2103
+ }
2104
+ function _email(Class, params) {
2105
+ return new Class({
2106
+ type: "string",
2107
+ format: "email",
2108
+ check: "string_format",
2109
+ abort: false,
2110
+ ...normalizeParams(params)
2111
+ });
2112
+ }
2113
+ function _guid(Class, params) {
2114
+ return new Class({
2115
+ type: "string",
2116
+ format: "guid",
2117
+ check: "string_format",
2118
+ abort: false,
2119
+ ...normalizeParams(params)
2120
+ });
2121
+ }
2122
+ function _uuid(Class, params) {
2123
+ return new Class({
2124
+ type: "string",
2125
+ format: "uuid",
2126
+ check: "string_format",
2127
+ abort: false,
2128
+ ...normalizeParams(params)
2129
+ });
2130
+ }
2131
+ function _uuidv4(Class, params) {
2132
+ return new Class({
2133
+ type: "string",
2134
+ format: "uuid",
2135
+ check: "string_format",
2136
+ abort: false,
2137
+ version: "v4",
2138
+ ...normalizeParams(params)
2139
+ });
2140
+ }
2141
+ function _uuidv6(Class, params) {
2142
+ return new Class({
2143
+ type: "string",
2144
+ format: "uuid",
2145
+ check: "string_format",
2146
+ abort: false,
2147
+ version: "v6",
2148
+ ...normalizeParams(params)
2149
+ });
2150
+ }
2151
+ function _uuidv7(Class, params) {
2152
+ return new Class({
2153
+ type: "string",
2154
+ format: "uuid",
2155
+ check: "string_format",
2156
+ abort: false,
2157
+ version: "v7",
2158
+ ...normalizeParams(params)
2159
+ });
2160
+ }
2161
+ function _url(Class, params) {
2162
+ return new Class({
2163
+ type: "string",
2164
+ format: "url",
2165
+ check: "string_format",
2166
+ abort: false,
2167
+ ...normalizeParams(params)
2168
+ });
2169
+ }
2170
+ function _emoji(Class, params) {
2171
+ return new Class({
2172
+ type: "string",
2173
+ format: "emoji",
2174
+ check: "string_format",
2175
+ abort: false,
2176
+ ...normalizeParams(params)
2177
+ });
2178
+ }
2179
+ function _nanoid(Class, params) {
2180
+ return new Class({
2181
+ type: "string",
2182
+ format: "nanoid",
2183
+ check: "string_format",
2184
+ abort: false,
2185
+ ...normalizeParams(params)
2186
+ });
2187
+ }
2188
+ function _cuid(Class, params) {
2189
+ return new Class({
2190
+ type: "string",
2191
+ format: "cuid",
2192
+ check: "string_format",
2193
+ abort: false,
2194
+ ...normalizeParams(params)
2195
+ });
2196
+ }
2197
+ function _cuid2(Class, params) {
2198
+ return new Class({
2199
+ type: "string",
2200
+ format: "cuid2",
2201
+ check: "string_format",
2202
+ abort: false,
2203
+ ...normalizeParams(params)
2204
+ });
2205
+ }
2206
+ function _ulid(Class, params) {
2207
+ return new Class({
2208
+ type: "string",
2209
+ format: "ulid",
2210
+ check: "string_format",
2211
+ abort: false,
2212
+ ...normalizeParams(params)
2213
+ });
2214
+ }
2215
+ function _xid(Class, params) {
2216
+ return new Class({
2217
+ type: "string",
2218
+ format: "xid",
2219
+ check: "string_format",
2220
+ abort: false,
2221
+ ...normalizeParams(params)
2222
+ });
2223
+ }
2224
+ function _ksuid(Class, params) {
2225
+ return new Class({
2226
+ type: "string",
2227
+ format: "ksuid",
2228
+ check: "string_format",
2229
+ abort: false,
2230
+ ...normalizeParams(params)
2231
+ });
2232
+ }
2233
+ function _ipv4(Class, params) {
2234
+ return new Class({
2235
+ type: "string",
2236
+ format: "ipv4",
2237
+ check: "string_format",
2238
+ abort: false,
2239
+ ...normalizeParams(params)
2240
+ });
2241
+ }
2242
+ function _ipv6(Class, params) {
2243
+ return new Class({
2244
+ type: "string",
2245
+ format: "ipv6",
2246
+ check: "string_format",
2247
+ abort: false,
2248
+ ...normalizeParams(params)
2249
+ });
2250
+ }
2251
+ function _cidrv4(Class, params) {
2252
+ return new Class({
2253
+ type: "string",
2254
+ format: "cidrv4",
2255
+ check: "string_format",
2256
+ abort: false,
2257
+ ...normalizeParams(params)
2258
+ });
2259
+ }
2260
+ function _cidrv6(Class, params) {
2261
+ return new Class({
2262
+ type: "string",
2263
+ format: "cidrv6",
2264
+ check: "string_format",
2265
+ abort: false,
2266
+ ...normalizeParams(params)
2267
+ });
2268
+ }
2269
+ function _base64(Class, params) {
2270
+ return new Class({
2271
+ type: "string",
2272
+ format: "base64",
2273
+ check: "string_format",
2274
+ abort: false,
2275
+ ...normalizeParams(params)
2276
+ });
2277
+ }
2278
+ function _base64url(Class, params) {
2279
+ return new Class({
2280
+ type: "string",
2281
+ format: "base64url",
2282
+ check: "string_format",
2283
+ abort: false,
2284
+ ...normalizeParams(params)
2285
+ });
2286
+ }
2287
+ function _e164(Class, params) {
2288
+ return new Class({
2289
+ type: "string",
2290
+ format: "e164",
2291
+ check: "string_format",
2292
+ abort: false,
2293
+ ...normalizeParams(params)
2294
+ });
2295
+ }
2296
+ function _jwt(Class, params) {
2297
+ return new Class({
2298
+ type: "string",
2299
+ format: "jwt",
2300
+ check: "string_format",
2301
+ abort: false,
2302
+ ...normalizeParams(params)
2303
+ });
2304
+ }
2305
+ function _isoDateTime(Class, params) {
2306
+ return new Class({
2307
+ type: "string",
2308
+ format: "datetime",
2309
+ check: "string_format",
2310
+ offset: false,
2311
+ local: false,
2312
+ precision: null,
2313
+ ...normalizeParams(params)
2314
+ });
2315
+ }
2316
+ function _isoDate(Class, params) {
2317
+ return new Class({
2318
+ type: "string",
2319
+ format: "date",
2320
+ check: "string_format",
2321
+ ...normalizeParams(params)
2322
+ });
2323
+ }
2324
+ function _isoTime(Class, params) {
2325
+ return new Class({
2326
+ type: "string",
2327
+ format: "time",
2328
+ check: "string_format",
2329
+ precision: null,
2330
+ ...normalizeParams(params)
2331
+ });
2332
+ }
2333
+ function _isoDuration(Class, params) {
2334
+ return new Class({
2335
+ type: "string",
2336
+ format: "duration",
2337
+ check: "string_format",
2338
+ ...normalizeParams(params)
2339
+ });
2340
+ }
2341
+ function _number(Class, params) {
2342
+ return new Class({
2343
+ type: "number",
2344
+ checks: [],
2345
+ ...normalizeParams(params)
2346
+ });
2347
+ }
2348
+ function _int(Class, params) {
2349
+ return new Class({
2350
+ type: "number",
2351
+ check: "number_format",
2352
+ abort: false,
2353
+ format: "safeint",
2354
+ ...normalizeParams(params)
2355
+ });
2356
+ }
2357
+ function _boolean(Class, params) {
2358
+ return new Class({
2359
+ type: "boolean",
2360
+ ...normalizeParams(params)
2361
+ });
2362
+ }
2363
+ function _any(Class) {
2364
+ return new Class({ type: "any" });
2365
+ }
2366
+ function _unknown(Class) {
2367
+ return new Class({ type: "unknown" });
2368
+ }
2369
+ function _never(Class, params) {
2370
+ return new Class({
2371
+ type: "never",
2372
+ ...normalizeParams(params)
2373
+ });
2374
+ }
2375
+ function _lt(value, params) {
2376
+ return new $ZodCheckLessThan({
2377
+ check: "less_than",
2378
+ ...normalizeParams(params),
2379
+ value,
2380
+ inclusive: false
2381
+ });
2382
+ }
2383
+ function _lte(value, params) {
2384
+ return new $ZodCheckLessThan({
2385
+ check: "less_than",
2386
+ ...normalizeParams(params),
2387
+ value,
2388
+ inclusive: true
2389
+ });
2390
+ }
2391
+ function _gt(value, params) {
2392
+ return new $ZodCheckGreaterThan({
2393
+ check: "greater_than",
2394
+ ...normalizeParams(params),
2395
+ value,
2396
+ inclusive: false
2397
+ });
2398
+ }
2399
+ function _gte(value, params) {
2400
+ return new $ZodCheckGreaterThan({
2401
+ check: "greater_than",
2402
+ ...normalizeParams(params),
2403
+ value,
2404
+ inclusive: true
2405
+ });
2406
+ }
2407
+ function _multipleOf(value, params) {
2408
+ return new $ZodCheckMultipleOf({
2409
+ check: "multiple_of",
2410
+ ...normalizeParams(params),
2411
+ value
2412
+ });
2413
+ }
2414
+ function _maxLength(maximum, params) {
2415
+ const ch = new $ZodCheckMaxLength({
2416
+ check: "max_length",
2417
+ ...normalizeParams(params),
2418
+ maximum
2419
+ });
2420
+ return ch;
2421
+ }
2422
+ function _minLength(minimum, params) {
2423
+ return new $ZodCheckMinLength({
2424
+ check: "min_length",
2425
+ ...normalizeParams(params),
2426
+ minimum
2427
+ });
2428
+ }
2429
+ function _length(length, params) {
2430
+ return new $ZodCheckLengthEquals({
2431
+ check: "length_equals",
2432
+ ...normalizeParams(params),
2433
+ length
2434
+ });
2435
+ }
2436
+ function _regex(pattern, params) {
2437
+ return new $ZodCheckRegex({
2438
+ check: "string_format",
2439
+ format: "regex",
2440
+ ...normalizeParams(params),
2441
+ pattern
2442
+ });
2443
+ }
2444
+ function _lowercase(params) {
2445
+ return new $ZodCheckLowerCase({
2446
+ check: "string_format",
2447
+ format: "lowercase",
2448
+ ...normalizeParams(params)
2449
+ });
2450
+ }
2451
+ function _uppercase(params) {
2452
+ return new $ZodCheckUpperCase({
2453
+ check: "string_format",
2454
+ format: "uppercase",
2455
+ ...normalizeParams(params)
2456
+ });
2457
+ }
2458
+ function _includes(includes, params) {
2459
+ return new $ZodCheckIncludes({
2460
+ check: "string_format",
2461
+ format: "includes",
2462
+ ...normalizeParams(params),
2463
+ includes
2464
+ });
2465
+ }
2466
+ function _startsWith(prefix, params) {
2467
+ return new $ZodCheckStartsWith({
2468
+ check: "string_format",
2469
+ format: "starts_with",
2470
+ ...normalizeParams(params),
2471
+ prefix
2472
+ });
2473
+ }
2474
+ function _endsWith(suffix, params) {
2475
+ return new $ZodCheckEndsWith({
2476
+ check: "string_format",
2477
+ format: "ends_with",
2478
+ ...normalizeParams(params),
2479
+ suffix
2480
+ });
2481
+ }
2482
+ function _overwrite(tx) {
2483
+ return new $ZodCheckOverwrite({
2484
+ check: "overwrite",
2485
+ tx
2486
+ });
2487
+ }
2488
+ function _normalize(form) {
2489
+ return _overwrite((input) => input.normalize(form));
2490
+ }
2491
+ function _trim() {
2492
+ return _overwrite((input) => input.trim());
2493
+ }
2494
+ function _toLowerCase() {
2495
+ return _overwrite((input) => input.toLowerCase());
2496
+ }
2497
+ function _toUpperCase() {
2498
+ return _overwrite((input) => input.toUpperCase());
2499
+ }
2500
+ function _array(Class, element, params) {
2501
+ return new Class({
2502
+ type: "array",
2503
+ element,
2504
+ ...normalizeParams(params)
2505
+ });
2506
+ }
2507
+ function _refine(Class, fn, _params) {
2508
+ const schema = new Class({
2509
+ type: "custom",
2510
+ check: "custom",
2511
+ fn,
2512
+ ...normalizeParams(_params)
2513
+ });
2514
+ return schema;
2515
+ }
2516
+
2517
+ //#endregion
2518
+ //#region ../../node_modules/zod/v4/classic/iso.js
2519
+ const ZodISODateTime = /* @__PURE__ */ $constructor("ZodISODateTime", (inst, def) => {
2520
+ $ZodISODateTime.init(inst, def);
2521
+ ZodStringFormat.init(inst, def);
2522
+ });
2523
+ function datetime(params) {
2524
+ return _isoDateTime(ZodISODateTime, params);
2525
+ }
2526
+ const ZodISODate = /* @__PURE__ */ $constructor("ZodISODate", (inst, def) => {
2527
+ $ZodISODate.init(inst, def);
2528
+ ZodStringFormat.init(inst, def);
2529
+ });
2530
+ function date(params) {
2531
+ return _isoDate(ZodISODate, params);
2532
+ }
2533
+ const ZodISOTime = /* @__PURE__ */ $constructor("ZodISOTime", (inst, def) => {
2534
+ $ZodISOTime.init(inst, def);
2535
+ ZodStringFormat.init(inst, def);
2536
+ });
2537
+ function time(params) {
2538
+ return _isoTime(ZodISOTime, params);
2539
+ }
2540
+ const ZodISODuration = /* @__PURE__ */ $constructor("ZodISODuration", (inst, def) => {
2541
+ $ZodISODuration.init(inst, def);
2542
+ ZodStringFormat.init(inst, def);
2543
+ });
2544
+ function duration(params) {
2545
+ return _isoDuration(ZodISODuration, params);
2546
+ }
2547
+
2548
+ //#endregion
2549
+ //#region ../../node_modules/zod/v4/classic/errors.js
2550
+ const initializer = (inst, issues) => {
2551
+ $ZodError.init(inst, issues);
2552
+ inst.name = "ZodError";
2553
+ Object.defineProperties(inst, {
2554
+ format: { value: (mapper) => formatError(inst, mapper) },
2555
+ flatten: { value: (mapper) => flattenError(inst, mapper) },
2556
+ addIssue: { value: (issue$1) => inst.issues.push(issue$1) },
2557
+ addIssues: { value: (issues$1) => inst.issues.push(...issues$1) },
2558
+ isEmpty: { get() {
2559
+ return inst.issues.length === 0;
2560
+ } }
2561
+ });
2562
+ };
2563
+ const ZodError = $constructor("ZodError", initializer);
2564
+ const ZodRealError = $constructor("ZodError", initializer, { Parent: Error });
2565
+
2566
+ //#endregion
2567
+ //#region ../../node_modules/zod/v4/classic/parse.js
2568
+ const parse$1 = /* @__PURE__ */ _parse(ZodRealError);
2569
+ const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
2570
+ const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
2571
+ const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
2572
+
2573
+ //#endregion
2574
+ //#region ../../node_modules/zod/v4/classic/schemas.js
2575
+ const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
2576
+ $ZodType.init(inst, def);
2577
+ inst.def = def;
2578
+ Object.defineProperty(inst, "_def", { value: def });
2579
+ inst.check = (...checks) => {
2580
+ return inst.clone({
2581
+ ...def,
2582
+ checks: [...def.checks ?? [], ...checks.map((ch) => typeof ch === "function" ? { _zod: {
2583
+ check: ch,
2584
+ def: { check: "custom" },
2585
+ onattach: []
2586
+ } } : ch)]
2587
+ });
2588
+ };
2589
+ inst.clone = (def$1, params) => clone(inst, def$1, params);
2590
+ inst.brand = () => inst;
2591
+ inst.register = (reg, meta) => {
2592
+ reg.add(inst, meta);
2593
+ return inst;
2594
+ };
2595
+ inst.parse = (data, params) => parse$1(inst, data, params, { callee: inst.parse });
2596
+ inst.safeParse = (data, params) => safeParse(inst, data, params);
2597
+ inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
2598
+ inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
2599
+ inst.spa = inst.safeParseAsync;
2600
+ inst.refine = (check$1, params) => inst.check(refine(check$1, params));
2601
+ inst.superRefine = (refinement) => inst.check(superRefine(refinement));
2602
+ inst.overwrite = (fn) => inst.check(_overwrite(fn));
2603
+ inst.optional = () => optional(inst);
2604
+ inst.nullable = () => nullable(inst);
2605
+ inst.nullish = () => optional(nullable(inst));
2606
+ inst.nonoptional = (params) => nonoptional(inst, params);
2607
+ inst.array = () => array(inst);
2608
+ inst.or = (arg) => union([inst, arg]);
2609
+ inst.and = (arg) => intersection(inst, arg);
2610
+ inst.transform = (tx) => pipe(inst, transform(tx));
2611
+ inst.default = (def$1) => _default(inst, def$1);
2612
+ inst.prefault = (def$1) => prefault(inst, def$1);
2613
+ inst.catch = (params) => _catch(inst, params);
2614
+ inst.pipe = (target) => pipe(inst, target);
2615
+ inst.readonly = () => readonly(inst);
2616
+ inst.describe = (description) => {
2617
+ const cl = inst.clone();
2618
+ globalRegistry.add(cl, { description });
2619
+ return cl;
2620
+ };
2621
+ Object.defineProperty(inst, "description", {
2622
+ get() {
2623
+ return globalRegistry.get(inst)?.description;
2624
+ },
2625
+ configurable: true
2626
+ });
2627
+ inst.meta = (...args) => {
2628
+ if (args.length === 0) return globalRegistry.get(inst);
2629
+ const cl = inst.clone();
2630
+ globalRegistry.add(cl, args[0]);
2631
+ return cl;
2632
+ };
2633
+ inst.isOptional = () => inst.safeParse(void 0).success;
2634
+ inst.isNullable = () => inst.safeParse(null).success;
2635
+ return inst;
2636
+ });
2637
+ /** @internal */
2638
+ const _ZodString = /* @__PURE__ */ $constructor("_ZodString", (inst, def) => {
2639
+ $ZodString.init(inst, def);
2640
+ ZodType.init(inst, def);
2641
+ const bag = inst._zod.bag;
2642
+ inst.format = bag.format ?? null;
2643
+ inst.minLength = bag.minimum ?? null;
2644
+ inst.maxLength = bag.maximum ?? null;
2645
+ inst.regex = (...args) => inst.check(_regex(...args));
2646
+ inst.includes = (...args) => inst.check(_includes(...args));
2647
+ inst.startsWith = (...args) => inst.check(_startsWith(...args));
2648
+ inst.endsWith = (...args) => inst.check(_endsWith(...args));
2649
+ inst.min = (...args) => inst.check(_minLength(...args));
2650
+ inst.max = (...args) => inst.check(_maxLength(...args));
2651
+ inst.length = (...args) => inst.check(_length(...args));
2652
+ inst.nonempty = (...args) => inst.check(_minLength(1, ...args));
2653
+ inst.lowercase = (params) => inst.check(_lowercase(params));
2654
+ inst.uppercase = (params) => inst.check(_uppercase(params));
2655
+ inst.trim = () => inst.check(_trim());
2656
+ inst.normalize = (...args) => inst.check(_normalize(...args));
2657
+ inst.toLowerCase = () => inst.check(_toLowerCase());
2658
+ inst.toUpperCase = () => inst.check(_toUpperCase());
2659
+ });
2660
+ const ZodString = /* @__PURE__ */ $constructor("ZodString", (inst, def) => {
2661
+ $ZodString.init(inst, def);
2662
+ _ZodString.init(inst, def);
2663
+ inst.email = (params) => inst.check(_email(ZodEmail, params));
2664
+ inst.url = (params) => inst.check(_url(ZodURL, params));
2665
+ inst.jwt = (params) => inst.check(_jwt(ZodJWT, params));
2666
+ inst.emoji = (params) => inst.check(_emoji(ZodEmoji, params));
2667
+ inst.guid = (params) => inst.check(_guid(ZodGUID, params));
2668
+ inst.uuid = (params) => inst.check(_uuid(ZodUUID, params));
2669
+ inst.uuidv4 = (params) => inst.check(_uuidv4(ZodUUID, params));
2670
+ inst.uuidv6 = (params) => inst.check(_uuidv6(ZodUUID, params));
2671
+ inst.uuidv7 = (params) => inst.check(_uuidv7(ZodUUID, params));
2672
+ inst.nanoid = (params) => inst.check(_nanoid(ZodNanoID, params));
2673
+ inst.guid = (params) => inst.check(_guid(ZodGUID, params));
2674
+ inst.cuid = (params) => inst.check(_cuid(ZodCUID, params));
2675
+ inst.cuid2 = (params) => inst.check(_cuid2(ZodCUID2, params));
2676
+ inst.ulid = (params) => inst.check(_ulid(ZodULID, params));
2677
+ inst.base64 = (params) => inst.check(_base64(ZodBase64, params));
2678
+ inst.base64url = (params) => inst.check(_base64url(ZodBase64URL, params));
2679
+ inst.xid = (params) => inst.check(_xid(ZodXID, params));
2680
+ inst.ksuid = (params) => inst.check(_ksuid(ZodKSUID, params));
2681
+ inst.ipv4 = (params) => inst.check(_ipv4(ZodIPv4, params));
2682
+ inst.ipv6 = (params) => inst.check(_ipv6(ZodIPv6, params));
2683
+ inst.cidrv4 = (params) => inst.check(_cidrv4(ZodCIDRv4, params));
2684
+ inst.cidrv6 = (params) => inst.check(_cidrv6(ZodCIDRv6, params));
2685
+ inst.e164 = (params) => inst.check(_e164(ZodE164, params));
2686
+ inst.datetime = (params) => inst.check(datetime(params));
2687
+ inst.date = (params) => inst.check(date(params));
2688
+ inst.time = (params) => inst.check(time(params));
2689
+ inst.duration = (params) => inst.check(duration(params));
2690
+ });
2691
+ function string(params) {
2692
+ return _string(ZodString, params);
2693
+ }
2694
+ const ZodStringFormat = /* @__PURE__ */ $constructor("ZodStringFormat", (inst, def) => {
2695
+ $ZodStringFormat.init(inst, def);
2696
+ _ZodString.init(inst, def);
2697
+ });
2698
+ const ZodEmail = /* @__PURE__ */ $constructor("ZodEmail", (inst, def) => {
2699
+ $ZodEmail.init(inst, def);
2700
+ ZodStringFormat.init(inst, def);
2701
+ });
2702
+ const ZodGUID = /* @__PURE__ */ $constructor("ZodGUID", (inst, def) => {
2703
+ $ZodGUID.init(inst, def);
2704
+ ZodStringFormat.init(inst, def);
2705
+ });
2706
+ const ZodUUID = /* @__PURE__ */ $constructor("ZodUUID", (inst, def) => {
2707
+ $ZodUUID.init(inst, def);
2708
+ ZodStringFormat.init(inst, def);
2709
+ });
2710
+ const ZodURL = /* @__PURE__ */ $constructor("ZodURL", (inst, def) => {
2711
+ $ZodURL.init(inst, def);
2712
+ ZodStringFormat.init(inst, def);
2713
+ });
2714
+ const ZodEmoji = /* @__PURE__ */ $constructor("ZodEmoji", (inst, def) => {
2715
+ $ZodEmoji.init(inst, def);
2716
+ ZodStringFormat.init(inst, def);
2717
+ });
2718
+ const ZodNanoID = /* @__PURE__ */ $constructor("ZodNanoID", (inst, def) => {
2719
+ $ZodNanoID.init(inst, def);
2720
+ ZodStringFormat.init(inst, def);
2721
+ });
2722
+ const ZodCUID = /* @__PURE__ */ $constructor("ZodCUID", (inst, def) => {
2723
+ $ZodCUID.init(inst, def);
2724
+ ZodStringFormat.init(inst, def);
2725
+ });
2726
+ const ZodCUID2 = /* @__PURE__ */ $constructor("ZodCUID2", (inst, def) => {
2727
+ $ZodCUID2.init(inst, def);
2728
+ ZodStringFormat.init(inst, def);
2729
+ });
2730
+ const ZodULID = /* @__PURE__ */ $constructor("ZodULID", (inst, def) => {
2731
+ $ZodULID.init(inst, def);
2732
+ ZodStringFormat.init(inst, def);
2733
+ });
2734
+ const ZodXID = /* @__PURE__ */ $constructor("ZodXID", (inst, def) => {
2735
+ $ZodXID.init(inst, def);
2736
+ ZodStringFormat.init(inst, def);
2737
+ });
2738
+ const ZodKSUID = /* @__PURE__ */ $constructor("ZodKSUID", (inst, def) => {
2739
+ $ZodKSUID.init(inst, def);
2740
+ ZodStringFormat.init(inst, def);
2741
+ });
2742
+ const ZodIPv4 = /* @__PURE__ */ $constructor("ZodIPv4", (inst, def) => {
2743
+ $ZodIPv4.init(inst, def);
2744
+ ZodStringFormat.init(inst, def);
2745
+ });
2746
+ const ZodIPv6 = /* @__PURE__ */ $constructor("ZodIPv6", (inst, def) => {
2747
+ $ZodIPv6.init(inst, def);
2748
+ ZodStringFormat.init(inst, def);
2749
+ });
2750
+ const ZodCIDRv4 = /* @__PURE__ */ $constructor("ZodCIDRv4", (inst, def) => {
2751
+ $ZodCIDRv4.init(inst, def);
2752
+ ZodStringFormat.init(inst, def);
2753
+ });
2754
+ const ZodCIDRv6 = /* @__PURE__ */ $constructor("ZodCIDRv6", (inst, def) => {
2755
+ $ZodCIDRv6.init(inst, def);
2756
+ ZodStringFormat.init(inst, def);
2757
+ });
2758
+ const ZodBase64 = /* @__PURE__ */ $constructor("ZodBase64", (inst, def) => {
2759
+ $ZodBase64.init(inst, def);
2760
+ ZodStringFormat.init(inst, def);
2761
+ });
2762
+ const ZodBase64URL = /* @__PURE__ */ $constructor("ZodBase64URL", (inst, def) => {
2763
+ $ZodBase64URL.init(inst, def);
2764
+ ZodStringFormat.init(inst, def);
2765
+ });
2766
+ const ZodE164 = /* @__PURE__ */ $constructor("ZodE164", (inst, def) => {
2767
+ $ZodE164.init(inst, def);
2768
+ ZodStringFormat.init(inst, def);
2769
+ });
2770
+ const ZodJWT = /* @__PURE__ */ $constructor("ZodJWT", (inst, def) => {
2771
+ $ZodJWT.init(inst, def);
2772
+ ZodStringFormat.init(inst, def);
2773
+ });
2774
+ const ZodNumber = /* @__PURE__ */ $constructor("ZodNumber", (inst, def) => {
2775
+ $ZodNumber.init(inst, def);
2776
+ ZodType.init(inst, def);
2777
+ inst.gt = (value, params) => inst.check(_gt(value, params));
2778
+ inst.gte = (value, params) => inst.check(_gte(value, params));
2779
+ inst.min = (value, params) => inst.check(_gte(value, params));
2780
+ inst.lt = (value, params) => inst.check(_lt(value, params));
2781
+ inst.lte = (value, params) => inst.check(_lte(value, params));
2782
+ inst.max = (value, params) => inst.check(_lte(value, params));
2783
+ inst.int = (params) => inst.check(int(params));
2784
+ inst.safe = (params) => inst.check(int(params));
2785
+ inst.positive = (params) => inst.check(_gt(0, params));
2786
+ inst.nonnegative = (params) => inst.check(_gte(0, params));
2787
+ inst.negative = (params) => inst.check(_lt(0, params));
2788
+ inst.nonpositive = (params) => inst.check(_lte(0, params));
2789
+ inst.multipleOf = (value, params) => inst.check(_multipleOf(value, params));
2790
+ inst.step = (value, params) => inst.check(_multipleOf(value, params));
2791
+ inst.finite = () => inst;
2792
+ const bag = inst._zod.bag;
2793
+ inst.minValue = Math.max(bag.minimum ?? Number.NEGATIVE_INFINITY, bag.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null;
2794
+ inst.maxValue = Math.min(bag.maximum ?? Number.POSITIVE_INFINITY, bag.exclusiveMaximum ?? Number.POSITIVE_INFINITY) ?? null;
2795
+ inst.isInt = (bag.format ?? "").includes("int") || Number.isSafeInteger(bag.multipleOf ?? .5);
2796
+ inst.isFinite = true;
2797
+ inst.format = bag.format ?? null;
2798
+ });
2799
+ function number(params) {
2800
+ return _number(ZodNumber, params);
2801
+ }
2802
+ const ZodNumberFormat = /* @__PURE__ */ $constructor("ZodNumberFormat", (inst, def) => {
2803
+ $ZodNumberFormat.init(inst, def);
2804
+ ZodNumber.init(inst, def);
2805
+ });
2806
+ function int(params) {
2807
+ return _int(ZodNumberFormat, params);
2808
+ }
2809
+ const ZodBoolean = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
2810
+ $ZodBoolean.init(inst, def);
2811
+ ZodType.init(inst, def);
2812
+ });
2813
+ function boolean(params) {
2814
+ return _boolean(ZodBoolean, params);
2815
+ }
2816
+ const ZodAny = /* @__PURE__ */ $constructor("ZodAny", (inst, def) => {
2817
+ $ZodAny.init(inst, def);
2818
+ ZodType.init(inst, def);
2819
+ });
2820
+ function any() {
2821
+ return _any(ZodAny);
2822
+ }
2823
+ const ZodUnknown = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
2824
+ $ZodUnknown.init(inst, def);
2825
+ ZodType.init(inst, def);
2826
+ });
2827
+ function unknown() {
2828
+ return _unknown(ZodUnknown);
2829
+ }
2830
+ const ZodNever = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
2831
+ $ZodNever.init(inst, def);
2832
+ ZodType.init(inst, def);
2833
+ });
2834
+ function never(params) {
2835
+ return _never(ZodNever, params);
2836
+ }
2837
+ const ZodArray = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
2838
+ $ZodArray.init(inst, def);
2839
+ ZodType.init(inst, def);
2840
+ inst.element = def.element;
2841
+ inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
2842
+ inst.nonempty = (params) => inst.check(_minLength(1, params));
2843
+ inst.max = (maxLength, params) => inst.check(_maxLength(maxLength, params));
2844
+ inst.length = (len, params) => inst.check(_length(len, params));
2845
+ inst.unwrap = () => inst.element;
2846
+ });
2847
+ function array(element, params) {
2848
+ return _array(ZodArray, element, params);
2849
+ }
2850
+ const ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
2851
+ $ZodObject.init(inst, def);
2852
+ ZodType.init(inst, def);
2853
+ defineLazy(inst, "shape", () => def.shape);
2854
+ inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
2855
+ inst.catchall = (catchall) => inst.clone({
2856
+ ...inst._zod.def,
2857
+ catchall
2858
+ });
2859
+ inst.passthrough = () => inst.clone({
2860
+ ...inst._zod.def,
2861
+ catchall: unknown()
2862
+ });
2863
+ inst.loose = () => inst.clone({
2864
+ ...inst._zod.def,
2865
+ catchall: unknown()
2866
+ });
2867
+ inst.strict = () => inst.clone({
2868
+ ...inst._zod.def,
2869
+ catchall: never()
2870
+ });
2871
+ inst.strip = () => inst.clone({
2872
+ ...inst._zod.def,
2873
+ catchall: void 0
2874
+ });
2875
+ inst.extend = (incoming) => {
2876
+ return extend(inst, incoming);
2877
+ };
2878
+ inst.merge = (other) => merge(inst, other);
2879
+ inst.pick = (mask) => pick(inst, mask);
2880
+ inst.omit = (mask) => omit(inst, mask);
2881
+ inst.partial = (...args) => partial(ZodOptional, inst, args[0]);
2882
+ inst.required = (...args) => required(ZodNonOptional, inst, args[0]);
2883
+ });
2884
+ function object(shape, params) {
2885
+ const def = {
2886
+ type: "object",
2887
+ get shape() {
2888
+ assignProp(this, "shape", { ...shape });
2889
+ return this.shape;
2890
+ },
2891
+ ...normalizeParams(params)
2892
+ };
2893
+ return new ZodObject(def);
2894
+ }
2895
+ const ZodUnion = /* @__PURE__ */ $constructor("ZodUnion", (inst, def) => {
2896
+ $ZodUnion.init(inst, def);
2897
+ ZodType.init(inst, def);
2898
+ inst.options = def.options;
2899
+ });
2900
+ function union(options, params) {
2901
+ return new ZodUnion({
2902
+ type: "union",
2903
+ options,
2904
+ ...normalizeParams(params)
2905
+ });
2906
+ }
2907
+ const ZodDiscriminatedUnion = /* @__PURE__ */ $constructor("ZodDiscriminatedUnion", (inst, def) => {
2908
+ ZodUnion.init(inst, def);
2909
+ $ZodDiscriminatedUnion.init(inst, def);
2910
+ });
2911
+ function discriminatedUnion(discriminator, options, params) {
2912
+ return new ZodDiscriminatedUnion({
2913
+ type: "union",
2914
+ options,
2915
+ discriminator,
2916
+ ...normalizeParams(params)
2917
+ });
2918
+ }
2919
+ const ZodIntersection = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
2920
+ $ZodIntersection.init(inst, def);
2921
+ ZodType.init(inst, def);
2922
+ });
2923
+ function intersection(left, right) {
2924
+ return new ZodIntersection({
2925
+ type: "intersection",
2926
+ left,
2927
+ right
2928
+ });
2929
+ }
2930
+ const ZodRecord = /* @__PURE__ */ $constructor("ZodRecord", (inst, def) => {
2931
+ $ZodRecord.init(inst, def);
2932
+ ZodType.init(inst, def);
2933
+ inst.keyType = def.keyType;
2934
+ inst.valueType = def.valueType;
2935
+ });
2936
+ function record(keyType, valueType, params) {
2937
+ return new ZodRecord({
2938
+ type: "record",
2939
+ keyType,
2940
+ valueType,
2941
+ ...normalizeParams(params)
2942
+ });
2943
+ }
2944
+ const ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
2945
+ $ZodEnum.init(inst, def);
2946
+ ZodType.init(inst, def);
2947
+ inst.enum = def.entries;
2948
+ inst.options = Object.values(def.entries);
2949
+ const keys = new Set(Object.keys(def.entries));
2950
+ inst.extract = (values, params) => {
2951
+ const newEntries = {};
2952
+ for (const value of values) if (keys.has(value)) newEntries[value] = def.entries[value];
2953
+ else throw new Error(`Key ${value} not found in enum`);
2954
+ return new ZodEnum({
2955
+ ...def,
2956
+ checks: [],
2957
+ ...normalizeParams(params),
2958
+ entries: newEntries
2959
+ });
2960
+ };
2961
+ inst.exclude = (values, params) => {
2962
+ const newEntries = { ...def.entries };
2963
+ for (const value of values) if (keys.has(value)) delete newEntries[value];
2964
+ else throw new Error(`Key ${value} not found in enum`);
2965
+ return new ZodEnum({
2966
+ ...def,
2967
+ checks: [],
2968
+ ...normalizeParams(params),
2969
+ entries: newEntries
2970
+ });
2971
+ };
2972
+ });
2973
+ function _enum(values, params) {
2974
+ const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
2975
+ return new ZodEnum({
2976
+ type: "enum",
2977
+ entries,
2978
+ ...normalizeParams(params)
2979
+ });
2980
+ }
2981
+ const ZodLiteral = /* @__PURE__ */ $constructor("ZodLiteral", (inst, def) => {
2982
+ $ZodLiteral.init(inst, def);
2983
+ ZodType.init(inst, def);
2984
+ inst.values = new Set(def.values);
2985
+ Object.defineProperty(inst, "value", { get() {
2986
+ if (def.values.length > 1) throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");
2987
+ return def.values[0];
2988
+ } });
2989
+ });
2990
+ function literal(value, params) {
2991
+ return new ZodLiteral({
2992
+ type: "literal",
2993
+ values: Array.isArray(value) ? value : [value],
2994
+ ...normalizeParams(params)
2995
+ });
2996
+ }
2997
+ const ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
2998
+ $ZodTransform.init(inst, def);
2999
+ ZodType.init(inst, def);
3000
+ inst._zod.parse = (payload, _ctx) => {
3001
+ payload.addIssue = (issue$1) => {
3002
+ if (typeof issue$1 === "string") payload.issues.push(issue(issue$1, payload.value, def));
3003
+ else {
3004
+ const _issue = issue$1;
3005
+ if (_issue.fatal) _issue.continue = false;
3006
+ _issue.code ?? (_issue.code = "custom");
3007
+ _issue.input ?? (_issue.input = payload.value);
3008
+ _issue.inst ?? (_issue.inst = inst);
3009
+ _issue.continue ?? (_issue.continue = true);
3010
+ payload.issues.push(issue(_issue));
3011
+ }
3012
+ };
3013
+ const output = def.transform(payload.value, payload);
3014
+ if (output instanceof Promise) return output.then((output$1) => {
3015
+ payload.value = output$1;
3016
+ return payload;
3017
+ });
3018
+ payload.value = output;
3019
+ return payload;
3020
+ };
3021
+ });
3022
+ function transform(fn) {
3023
+ return new ZodTransform({
3024
+ type: "transform",
3025
+ transform: fn
3026
+ });
3027
+ }
3028
+ const ZodOptional = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
3029
+ $ZodOptional.init(inst, def);
3030
+ ZodType.init(inst, def);
3031
+ inst.unwrap = () => inst._zod.def.innerType;
3032
+ });
3033
+ function optional(innerType) {
3034
+ return new ZodOptional({
3035
+ type: "optional",
3036
+ innerType
3037
+ });
3038
+ }
3039
+ const ZodNullable = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
3040
+ $ZodNullable.init(inst, def);
3041
+ ZodType.init(inst, def);
3042
+ inst.unwrap = () => inst._zod.def.innerType;
3043
+ });
3044
+ function nullable(innerType) {
3045
+ return new ZodNullable({
3046
+ type: "nullable",
3047
+ innerType
3048
+ });
3049
+ }
3050
+ const ZodDefault = /* @__PURE__ */ $constructor("ZodDefault", (inst, def) => {
3051
+ $ZodDefault.init(inst, def);
3052
+ ZodType.init(inst, def);
3053
+ inst.unwrap = () => inst._zod.def.innerType;
3054
+ inst.removeDefault = inst.unwrap;
3055
+ });
3056
+ function _default(innerType, defaultValue) {
3057
+ return new ZodDefault({
3058
+ type: "default",
3059
+ innerType,
3060
+ get defaultValue() {
3061
+ return typeof defaultValue === "function" ? defaultValue() : defaultValue;
3062
+ }
3063
+ });
3064
+ }
3065
+ const ZodPrefault = /* @__PURE__ */ $constructor("ZodPrefault", (inst, def) => {
3066
+ $ZodPrefault.init(inst, def);
3067
+ ZodType.init(inst, def);
3068
+ inst.unwrap = () => inst._zod.def.innerType;
3069
+ });
3070
+ function prefault(innerType, defaultValue) {
3071
+ return new ZodPrefault({
3072
+ type: "prefault",
3073
+ innerType,
3074
+ get defaultValue() {
3075
+ return typeof defaultValue === "function" ? defaultValue() : defaultValue;
3076
+ }
3077
+ });
3078
+ }
3079
+ const ZodNonOptional = /* @__PURE__ */ $constructor("ZodNonOptional", (inst, def) => {
3080
+ $ZodNonOptional.init(inst, def);
3081
+ ZodType.init(inst, def);
3082
+ inst.unwrap = () => inst._zod.def.innerType;
3083
+ });
3084
+ function nonoptional(innerType, params) {
3085
+ return new ZodNonOptional({
3086
+ type: "nonoptional",
3087
+ innerType,
3088
+ ...normalizeParams(params)
3089
+ });
3090
+ }
3091
+ const ZodCatch = /* @__PURE__ */ $constructor("ZodCatch", (inst, def) => {
3092
+ $ZodCatch.init(inst, def);
3093
+ ZodType.init(inst, def);
3094
+ inst.unwrap = () => inst._zod.def.innerType;
3095
+ inst.removeCatch = inst.unwrap;
3096
+ });
3097
+ function _catch(innerType, catchValue) {
3098
+ return new ZodCatch({
3099
+ type: "catch",
3100
+ innerType,
3101
+ catchValue: typeof catchValue === "function" ? catchValue : () => catchValue
3102
+ });
3103
+ }
3104
+ const ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
3105
+ $ZodPipe.init(inst, def);
3106
+ ZodType.init(inst, def);
3107
+ inst.in = def.in;
3108
+ inst.out = def.out;
3109
+ });
3110
+ function pipe(in_, out) {
3111
+ return new ZodPipe({
3112
+ type: "pipe",
3113
+ in: in_,
3114
+ out
3115
+ });
3116
+ }
3117
+ const ZodReadonly = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
3118
+ $ZodReadonly.init(inst, def);
3119
+ ZodType.init(inst, def);
3120
+ });
3121
+ function readonly(innerType) {
3122
+ return new ZodReadonly({
3123
+ type: "readonly",
3124
+ innerType
3125
+ });
3126
+ }
3127
+ const ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
3128
+ $ZodCustom.init(inst, def);
3129
+ ZodType.init(inst, def);
3130
+ });
3131
+ function check(fn, params) {
3132
+ const ch = new $ZodCheck({
3133
+ check: "custom",
3134
+ ...normalizeParams(params)
3135
+ });
3136
+ ch._zod.check = fn;
3137
+ return ch;
3138
+ }
3139
+ function refine(fn, _params = {}) {
3140
+ return _refine(ZodCustom, fn, _params);
3141
+ }
3142
+ function superRefine(fn, params) {
3143
+ const ch = check((payload) => {
3144
+ payload.addIssue = (issue$1) => {
3145
+ if (typeof issue$1 === "string") payload.issues.push(issue(issue$1, payload.value, ch._zod.def));
3146
+ else {
3147
+ const _issue = issue$1;
3148
+ if (_issue.fatal) _issue.continue = false;
3149
+ _issue.code ?? (_issue.code = "custom");
3150
+ _issue.input ?? (_issue.input = payload.value);
3151
+ _issue.inst ?? (_issue.inst = ch);
3152
+ _issue.continue ?? (_issue.continue = !ch._zod.def.abort);
3153
+ payload.issues.push(issue(_issue));
3154
+ }
3155
+ };
3156
+ return fn(payload.value, payload);
3157
+ }, params);
3158
+ return ch;
3159
+ }
3160
+
3161
+ //#endregion
3162
+ //#region src/connectors/constants.ts
3163
+ const DEFAULT_PAGE_SIZE = 25;
3164
+
3165
+ //#endregion
3166
+ //#region src/connectors/responses.ts
3167
+ const getDefaultSuccessOperationResponse = (operationType) => {
3168
+ switch (operationType) {
3169
+ case "list": return {
3170
+ statusCode: 200,
3171
+ description: "The list of records was retrieved."
3172
+ };
3173
+ case "get": return {
3174
+ statusCode: 200,
3175
+ description: "The record with the given identifier was retrieved."
3176
+ };
3177
+ case "create": return {
3178
+ statusCode: 201,
3179
+ description: "The record was created successfully."
3180
+ };
3181
+ case "update": return {
3182
+ statusCode: 200,
3183
+ description: "The record was updated successfully."
3184
+ };
3185
+ case "delete": return {
3186
+ statusCode: 204,
3187
+ description: "The record was deleted successfully."
3188
+ };
3189
+ case "custom": return {
3190
+ statusCode: 200,
3191
+ description: "The operation was executed successfully."
3192
+ };
3193
+ case "unknown": return { statusCode: 200 };
3194
+ default: throw new Error(`Unknown operation type: ${operationType}`);
3195
+ }
3196
+ };
3197
+ const getDefaultErrorOperationResponses = () => {
3198
+ const defaultErrorStatusCodes = {
3199
+ 400: {
3200
+ statusCode: 400,
3201
+ description: "Invalid request."
3202
+ },
3203
+ 401: {
3204
+ statusCode: 401,
3205
+ description: "Unauthorized access."
3206
+ },
3207
+ 403: {
3208
+ statusCode: 403,
3209
+ description: "Forbidden."
3210
+ },
3211
+ 404: {
3212
+ statusCode: 404,
3213
+ description: "Resource not found."
3214
+ },
3215
+ 500: {
3216
+ statusCode: 500,
3217
+ description: "Server error while executing the request."
3218
+ }
3219
+ };
3220
+ return defaultErrorStatusCodes;
3221
+ };
3222
+
3223
+ //#endregion
3224
+ //#region src/connectors/schemas.ts
3225
+ const BASE_AUTH_FIELD = {
3226
+ key: string(),
3227
+ label: string(),
3228
+ required: boolean().optional().default(false),
3229
+ secret: boolean().optional().default(false),
3230
+ readOnly: boolean().optional().default(false),
3231
+ placeholder: string().optional(),
3232
+ description: string().optional(),
3233
+ tooltip: string().optional()
3234
+ };
3235
+ const AUTHENTICATION_FIELD_SCHEMA = discriminatedUnion("type", [object({
3236
+ ...BASE_AUTH_FIELD,
3237
+ type: _enum(["text", "password"])
3238
+ }), object({
3239
+ ...BASE_AUTH_FIELD,
3240
+ type: literal("select"),
3241
+ options: object({
3242
+ value: string(),
3243
+ label: string()
3244
+ }).array()
3245
+ })]);
3246
+ const OPERATION_SCHEMA = object({
3247
+ operationId: string(),
3248
+ categories: string().array(),
3249
+ operationType: _enum([
3250
+ "list",
3251
+ "get",
3252
+ "create",
3253
+ "update",
3254
+ "delete",
3255
+ "custom",
3256
+ "unknown"
3257
+ ]),
3258
+ schema: string().optional(),
3259
+ entrypointUrl: string().optional(),
3260
+ entrypointHttpMethod: string().optional(),
3261
+ description: string(),
3262
+ responses: object({
3263
+ statusCode: number(),
3264
+ description: string()
3265
+ }).array().optional(),
3266
+ inputs: object({
3267
+ name: string(),
3268
+ type: string(),
3269
+ required: boolean(),
3270
+ description: string(),
3271
+ in: string()
3272
+ }).array().optional(),
3273
+ cursor: object({
3274
+ enabled: boolean(),
3275
+ pageSize: number()
3276
+ }).optional(),
3277
+ compositeIdentifiers: object({
3278
+ enabled: boolean(),
3279
+ version: number().optional(),
3280
+ fields: object({
3281
+ targetFieldKey: string(),
3282
+ remote: string().optional(),
3283
+ components: string().array()
3284
+ }).array().optional()
3285
+ }).optional(),
3286
+ scheduledJobs: object({
3287
+ enabled: boolean(),
3288
+ type: _enum(["data_sync"]),
3289
+ schedule: string(),
3290
+ description: string(),
3291
+ requestParams: object({
3292
+ fields: string().array().optional(),
3293
+ expand: string().array().optional(),
3294
+ filter: record(string(), string()).optional()
3295
+ }).optional(),
3296
+ syncFilter: object({
3297
+ name: _enum(["updated_after", "created_after"]),
3298
+ initialLoopbackPeriod: string(),
3299
+ incrementalLoopbackPeriod: string()
3300
+ }).optional()
3301
+ }).array().optional(),
3302
+ fieldConfigs: object({
3303
+ targetFieldKey: string(),
3304
+ alias: string().optional(),
3305
+ expression: string(),
3306
+ type: _enum([
3307
+ "string",
3308
+ "number",
3309
+ "boolean",
3310
+ "datetime_string",
3311
+ "enum"
3312
+ ]),
3313
+ custom: boolean().default(false),
3314
+ hidden: boolean().default(false),
3315
+ enumMapper: object({ matcher: _enum([
3316
+ "country_alpha2code_by_alpha2code",
3317
+ "country_alpha3code_by_alpha3code",
3318
+ "country_code_by_country_code",
3319
+ "country_name_by_country_name",
3320
+ "country_name_by_alpha3code",
3321
+ "country_name_by_alpha2code",
3322
+ "country_name_by_country_code",
3323
+ "country_alpha3code_by_alpha2code",
3324
+ "country_alpha3code_by_country_name",
3325
+ "country_alpha3code_by_country_code",
3326
+ "country_alpha2code_by_alpha3code",
3327
+ "country_alpha2code_by_country_name",
3328
+ "country_alpha2code_by_country_code",
3329
+ "country_code_by_alpha2code",
3330
+ "country_code_by_alpha3code",
3331
+ "country_code_by_country_name",
3332
+ "country_subdivisions_by_alpha2code",
3333
+ "country_subdivision_code_by_subdivision_name",
3334
+ "country_alpha2code_by_citizenship",
3335
+ "country_subdivision_name_by_subdivision_code"
3336
+ ]).or(object({
3337
+ matchExpression: string(),
3338
+ value: string()
3339
+ }).array()) }).optional()
3340
+ }).array().optional(),
3341
+ steps: object({
3342
+ stepId: string(),
3343
+ description: string(),
3344
+ stepFunction: object({
3345
+ functionName: string(),
3346
+ version: string().optional(),
3347
+ parameters: record(string(), unknown())
3348
+ }),
3349
+ condition: string().optional(),
3350
+ ignoreError: boolean().optional()
3351
+ }).array(),
3352
+ result: string().or(record(string(), unknown())).optional()
3353
+ });
3354
+ const CONNECTOR_YAML_SCHEMA = object({
3355
+ StackOne: string(),
3356
+ info: object({
3357
+ title: string(),
3358
+ version: string(),
3359
+ key: string(),
3360
+ description: string().optional()
3361
+ }),
3362
+ baseUrl: string(),
3363
+ authentication: record(string(), object({
3364
+ type: string(),
3365
+ label: string(),
3366
+ authorization: AUTHENTICATION_SCHEMA,
3367
+ environments: object({
3368
+ key: string(),
3369
+ name: string()
3370
+ }).array(),
3371
+ support: object({
3372
+ link: string(),
3373
+ description: string().optional()
3374
+ }),
3375
+ configFields: AUTHENTICATION_FIELD_SCHEMA.array().optional(),
3376
+ setupFields: AUTHENTICATION_FIELD_SCHEMA.array().optional(),
3377
+ testOperationsIds: string().array().optional()
3378
+ })).array().optional(),
3379
+ operations: OPERATION_SCHEMA.array().optional()
3380
+ });
3381
+
3382
+ //#endregion
3383
+ //#region src/connectors/parsers.ts
3384
+ function parseYamlConnector(yamlFileContents) {
3385
+ try {
3386
+ const yamlConnector = parse(yamlFileContents);
3387
+ const parsedYamlConnector = CONNECTOR_YAML_SCHEMA.parse(yamlConnector);
3388
+ const newJsonConnector = {
3389
+ title: parsedYamlConnector.info.title,
3390
+ version: parsedYamlConnector.info.version,
3391
+ key: parsedYamlConnector.info.key,
3392
+ description: parsedYamlConnector.info.description
3393
+ };
3394
+ const authentication = buildAuthenticationFromYaml(parsedYamlConnector);
3395
+ const baseRequestParams = {
3396
+ baseUrl: parsedYamlConnector.baseUrl,
3397
+ authentication: stripAuthenticationSetup(authentication)
3398
+ };
3399
+ const newOperations = buildOperationsFromYaml(parsedYamlConnector, baseRequestParams);
3400
+ newJsonConnector.operations = newOperations;
3401
+ newJsonConnector.authentication = authentication;
3402
+ if (notMissing(newOperations)) newJsonConnector.categories = getConnectorCategoriesFromOperations(Object.values(newOperations));
3403
+ return newJsonConnector;
3404
+ } catch (error) {
3405
+ throw new Error(`Error parsing YAML file: ${error.message}`);
3406
+ }
3407
+ }
3408
+ const stripAuthenticationSetup = (authentication) => {
3409
+ const result = {};
3410
+ for (const [key, value] of Object.entries(authentication)) if (value && typeof value === "object") {
3411
+ const { setupFields: _setupFields, configFields: _configFields, support: _support, testOperationsIds: _testOperationsIds,...rest } = value;
3412
+ result[key] = stripAuthenticationSetup(rest);
3413
+ } else result[key] = value;
3414
+ return result;
3415
+ };
3416
+ const getConnectorCategoriesFromOperations = (operations) => {
3417
+ const categoriesSet = operations.reduce((acc, op) => {
3418
+ for (const category of op.categories) acc.add(category);
3419
+ return acc;
3420
+ }, /* @__PURE__ */ new Set());
3421
+ return Array.from(categoriesSet);
3422
+ };
3423
+ const buildAuthenticationFromYaml = (parsedYamlConnector) => {
3424
+ const authentication = {};
3425
+ for (const auth of parsedYamlConnector.authentication ?? []) {
3426
+ const [authKey] = Object.keys(auth);
3427
+ const authConfig = auth[authKey].environments.reduce((acc, env) => {
3428
+ const { key, name } = env;
3429
+ const { environments: _envs,...authConfig$1 } = auth[authKey];
3430
+ acc[key] = {
3431
+ ...authConfig$1,
3432
+ envKey: key,
3433
+ envName: name
3434
+ };
3435
+ return acc;
3436
+ }, {});
3437
+ authentication[authKey] = authConfig;
3438
+ }
3439
+ return authentication;
3440
+ };
3441
+ const buildOperationKey = (op) => {
3442
+ return op.entrypointUrl && op.entrypointHttpMethod ? `${op.entrypointHttpMethod.toUpperCase()} ${op.entrypointUrl}` : void 0;
3443
+ };
3444
+ const inferOperationKey = (op) => {
3445
+ return op.operationType === "list" ? `GET /${op.schema}` : `GET /${op.schema}/:id`;
3446
+ };
3447
+ const inferEntrypointUrl = (op) => {
3448
+ return op.operationType === "list" ? `/${op.schema}` : `/${op.schema}/:id`;
3449
+ };
3450
+ const buildOperationResponses = (op) => {
3451
+ const defaultOperationResponses = {
3452
+ success: getDefaultSuccessOperationResponse(op.operationType),
3453
+ errors: getDefaultErrorOperationResponses()
3454
+ };
3455
+ const operationResponses = op.responses?.reduce((acc, response) => {
3456
+ const isSuccess = isSuccessStatusCode(response.statusCode);
3457
+ if (isSuccess) acc.success = {
3458
+ statusCode: response.statusCode,
3459
+ description: response.description
3460
+ };
3461
+ else acc.errors[response.statusCode] = {
3462
+ statusCode: response.statusCode,
3463
+ description: response.description
3464
+ };
3465
+ return acc;
3466
+ }, defaultOperationResponses);
3467
+ return operationResponses ?? defaultOperationResponses;
3468
+ };
3469
+ const buildOperationsFromYaml = (parsedYamlConnector, baseRequestParams) => {
3470
+ const newOperations = parsedYamlConnector.operations?.reduce((acc, op) => {
3471
+ const operationKey = buildOperationKey(op);
3472
+ const inferredOperationKey = inferOperationKey(op);
3473
+ const inferredEntrypointUrl = inferEntrypointUrl(op);
3474
+ const operationResponses = buildOperationResponses(op);
3475
+ const cursorConfig = buildCursorConfig(op);
3476
+ const inputs = op.inputs || [];
3477
+ if (cursorConfig.enabled) inputs?.push({
3478
+ type: "string",
3479
+ name: "page_size",
3480
+ in: "query",
3481
+ required: false,
3482
+ description: "Number of items to return per page"
3483
+ });
3484
+ acc[operationKey ?? inferredOperationKey] = {
3485
+ id: op.operationId,
3486
+ categories: op.categories,
3487
+ description: op.description,
3488
+ operationType: op.operationType,
3489
+ entrypointUrl: op.entrypointUrl ?? inferredEntrypointUrl,
3490
+ entrypointHttpMethod: op.entrypointHttpMethod ?? "get",
3491
+ responses: operationResponses,
3492
+ cursor: cursorConfig,
3493
+ compositeIdentifiers: parseCompositeIdentifiersConfig(op),
3494
+ scheduledJobs: parseScheduledJobConfig(op),
3495
+ inputs,
3496
+ steps: op.steps.reduce((acc$1, step) => {
3497
+ acc$1[step.stepId] = {
3498
+ id: step.stepId,
3499
+ description: step.description,
3500
+ condition: step.condition,
3501
+ ignoreError: step.ignoreError,
3502
+ stepFunction: {
3503
+ functionName: step.stepFunction.functionName,
3504
+ version: step.stepFunction.version,
3505
+ params: {
3506
+ ...step.stepFunction.parameters,
3507
+ ...getDefaultRequestStepFunctionsParams(step.stepFunction.functionName, baseRequestParams, step.stepFunction.parameters),
3508
+ ...step.stepFunction.functionName === "map_fields" || step.stepFunction.functionName === "typecast" ? { fields: op.fieldConfigs } : {}
3509
+ }
3510
+ }
3511
+ };
3512
+ return acc$1;
3513
+ }, {}),
3514
+ result: op.result
3515
+ };
3516
+ return acc;
3517
+ }, {});
3518
+ return newOperations;
3519
+ };
3520
+ const parseOperationInputs = (operation, inputs) => {
3521
+ if (!operation.inputs) return {};
3522
+ const inputSchema = createSchemaByFieldLocation(operation.inputs);
3523
+ const parsedInputs = inputSchema.parse(inputs);
3524
+ return {
3525
+ ...parsedInputs.headers ?? {},
3526
+ ...parsedInputs.query ?? {},
3527
+ ...parsedInputs.path ?? {},
3528
+ ...parsedInputs.body ?? {}
3529
+ };
3530
+ };
3531
+ const createDynamicSchema = (fields) => {
3532
+ const schemaObj = {};
3533
+ fields.forEach((field) => {
3534
+ let fieldSchema;
3535
+ switch (field.type.toLowerCase()) {
3536
+ case "string":
3537
+ fieldSchema = string();
3538
+ break;
3539
+ case "number":
3540
+ fieldSchema = number();
3541
+ break;
3542
+ case "boolean":
3543
+ fieldSchema = boolean();
3544
+ break;
3545
+ default: fieldSchema = any();
3546
+ }
3547
+ schemaObj[field.name] = field.required ? fieldSchema : fieldSchema.optional();
3548
+ });
3549
+ return object(schemaObj);
3550
+ };
3551
+ const createSchemaByFieldLocation = (fields) => {
3552
+ const pathFields = fields.filter((field) => field.in === "path");
3553
+ const queryFields = fields.filter((field) => field.in === "query");
3554
+ const bodyFields = fields.filter((field) => field.in === "body");
3555
+ const headersFields = fields.filter((field) => field.in === "headers");
3556
+ return object({
3557
+ path: createDynamicSchema(pathFields).optional(),
3558
+ query: createDynamicSchema(queryFields).optional(),
3559
+ body: createDynamicSchema(bodyFields).optional(),
3560
+ headers: createDynamicSchema(headersFields).optional()
3561
+ });
3562
+ };
3563
+ const buildCursorConfig = (op) => {
3564
+ const isListOperation = op.operationType === "list";
3565
+ const cursorConfig = op.cursor ?? {
3566
+ enabled: isListOperation,
3567
+ pageSize: DEFAULT_PAGE_SIZE
3568
+ };
3569
+ return {
3570
+ enabled: cursorConfig.enabled && isListOperation,
3571
+ pageSize: cursorConfig.pageSize
3572
+ };
3573
+ };
3574
+ const parseCompositeIdentifiersConfig = (op) => {
3575
+ if (isMissing(op.compositeIdentifiers)) {
3576
+ const identifierFieldConfig = op.fieldConfigs?.find((fieldConfig) => fieldConfig.targetFieldKey === "id");
3577
+ const defaultIdentifierFields = notMissing(identifierFieldConfig) ? [{
3578
+ targetFieldKey: identifierFieldConfig.targetFieldKey,
3579
+ remote: "id",
3580
+ components: [{
3581
+ name: identifierFieldConfig.targetFieldKey,
3582
+ alias: identifierFieldConfig.alias
3583
+ }]
3584
+ }] : void 0;
3585
+ return {
3586
+ enabled: true,
3587
+ version: COMPOSITE_ID_LATEST_VERSION,
3588
+ fields: defaultIdentifierFields
3589
+ };
3590
+ }
3591
+ const mappedFields = [];
3592
+ for (const field of op.compositeIdentifiers?.fields ?? []) {
3593
+ const fieldComponents = field.components.map((component) => {
3594
+ const componentDetail = op.fieldConfigs?.find((fieldConfig) => fieldConfig.targetFieldKey === component);
3595
+ return {
3596
+ name: component,
3597
+ alias: componentDetail?.alias
3598
+ };
3599
+ });
3600
+ mappedFields.push({
3601
+ targetFieldKey: field.targetFieldKey,
3602
+ remote: field.remote,
3603
+ components: fieldComponents
3604
+ });
3605
+ }
3606
+ return {
3607
+ enabled: op.compositeIdentifiers.enabled,
3608
+ version: op.compositeIdentifiers.version,
3609
+ fields: mappedFields.length > 0 ? mappedFields : void 0
3610
+ };
3611
+ };
3612
+ const parseScheduledJobConfig = (op) => {
3613
+ if (isMissing(op.scheduledJobs)) return void 0;
3614
+ return op.scheduledJobs;
3615
+ };
3616
+ const getDefaultRequestStepFunctionsParams = (stepFunctionName, baseRequestParams, functionParams = {}) => {
3617
+ if (stepFunctionName === "request" || stepFunctionName === "paginated_request") {
3618
+ const defaultCustomErrors = [{
3619
+ receivedStatus: 500,
3620
+ targetStatus: 502
3621
+ }];
3622
+ const functionCustomErrors = functionParams.customErrors && Array.isArray(functionParams.customErrors) ? functionParams.customErrors : [];
3623
+ const mergedCustomErrors = [...functionCustomErrors, ...defaultCustomErrors];
3624
+ return {
3625
+ ...baseRequestParams,
3626
+ customErrors: mergedCustomErrors
3627
+ };
3628
+ } else return {};
3629
+ };
3630
+
3631
+ //#endregion
3632
+ //#region src/errors/connectSDKErrors.ts
3633
+ var ConnectSDKError = class ConnectSDKError extends Error {
3634
+ errorType;
3635
+ context;
3636
+ constructor(errorType, context, message) {
3637
+ super(message);
3638
+ this.name = "ConnectSDKError";
3639
+ this.errorType = errorType;
3640
+ this.context = context;
3641
+ if (Error.captureStackTrace) Error.captureStackTrace(this, ConnectSDKError);
3642
+ }
3643
+ toString() {
3644
+ return `${this.name} [${this.errorType}]: ${this.message}`;
3645
+ }
3646
+ };
3647
+ var ConnectorParseError = class extends ConnectSDKError {
3648
+ constructor(context, message) {
3649
+ super("CONNECTOR_PARSE_ERROR", context, message);
3650
+ this.name = "ConnectorParseError";
3651
+ }
3652
+ };
3653
+ var MissingOperationError = class extends ConnectSDKError {
3654
+ constructor(context, message) {
3655
+ super("MISSING_OPERATION_ERROR", context, message);
3656
+ this.name = "MissingOperationError";
3657
+ }
3658
+ };
3659
+ var InvalidOperationInputsError = class extends ConnectSDKError {
3660
+ constructor(context, message) {
3661
+ super("INVALID_OPERATION_INPUTS_ERROR", context, message);
3662
+ this.name = "InvalidOperationInputsError";
3663
+ }
3664
+ };
3665
+ var InvalidCursorError = class extends ConnectSDKError {
3666
+ constructor(context, message) {
3667
+ super("INVALID_CURSOR_ERROR", context, message);
3668
+ this.name = "InvalidCursorError";
3669
+ }
3670
+ };
3671
+
3672
+ //#endregion
3673
+ //#region src/runners/executeStepFunctions.ts
3674
+ const executeStepFunction = async ({ block, stepFunctionName, params, buildStepFunction = StepFunctionsFactory.build }) => {
3675
+ const stepFunction = buildStepFunction({ functionName: stepFunctionName }).fn;
3676
+ const result = await stepFunction({
3677
+ block,
3678
+ params
3679
+ });
3680
+ const stepSnaphot = stepFunctionName === StepFunctionName.MAP_FIELDS ? { [StepFunctionName.MAP_FIELDS.toString()]: {
3681
+ output: { data: result.block.result },
3682
+ errors: result.errors,
3683
+ successful: result.successful
3684
+ } } : {};
3685
+ return {
3686
+ ...result.block,
3687
+ steps: {
3688
+ ...result?.block?.steps ?? {},
3689
+ ...stepSnaphot
3690
+ }
3691
+ };
3692
+ };
3693
+
3694
+ //#endregion
3695
+ //#region src/blocks/createBlockContext.ts
3696
+ const createBlockContext = ({ category, connectorKey, connectorVersion, authConfigKey, environment = "production", operation, accountSecureId, projectSecureId }) => {
3697
+ return {
3698
+ projectSecureId,
3699
+ accountSecureId,
3700
+ connectorKey,
3701
+ connectorVersion,
3702
+ category,
3703
+ service: "",
3704
+ resource: "",
3705
+ schema: operation?.schema?.key,
3706
+ operationType: operation?.operationType ?? "unknown",
3707
+ authenticationType: authConfigKey,
3708
+ environment
3709
+ };
3710
+ };
3711
+
3712
+ //#endregion
3713
+ //#region src/compositeIds/inputs.ts
3714
+ const decodeInputCompositeIdentifiers = (block) => {
3715
+ const compositeIdsConfig = block.operation?.compositeIdentifiers;
3716
+ const blockInputs = { ...block.inputs ?? {} };
3717
+ if (!compositeIdsConfig?.enabled || isMissing(blockInputs)) return block;
3718
+ const aliases = compositeIdsConfig.fields?.reduce((acc, field) => {
3719
+ field.components.forEach((component) => {
3720
+ if (component.alias) acc[component.name] = component.alias;
3721
+ });
3722
+ return acc;
3723
+ }, {});
3724
+ const identifierConfig = {
3725
+ version: compositeIdsConfig.version ?? COMPOSITE_ID_LATEST_VERSION,
3726
+ aliases
3727
+ };
3728
+ processLevel(blockInputs, identifierConfig, block.logger);
3729
+ return {
3730
+ ...block,
3731
+ inputs: blockInputs
3732
+ };
3733
+ };
3734
+ const processLevel = (input, compositeIdentifierConfig, logger) => {
3735
+ for (const key in input) {
3736
+ const value = input[key];
3737
+ if (typeof value === "string" || Array.isArray(value) && value.every((item) => typeof item === "string")) processCompositeId(value, key, input, compositeIdentifierConfig, logger);
3738
+ else if (Array.isArray(value)) for (const item of value) processLevel(item, compositeIdentifierConfig, logger);
3739
+ else if (typeof value === "object" && value !== null) processLevel(value, compositeIdentifierConfig, logger);
3740
+ }
3741
+ };
3742
+ const processInputElements = (inputArray, key, compositeIdentifierConfig, logger) => {
3743
+ const compositeIdComponents = [];
3744
+ const nonCompositeIds = [];
3745
+ for (const inputElement of inputArray) try {
3746
+ const extractedComponents = decodeCompositeId(inputElement, compositeIdentifierConfig);
3747
+ compositeIdComponents.push(extractedComponents);
3748
+ } catch (e) {
3749
+ logger?.debug({
3750
+ message: `Received ${key} with invalid composite ID, assuming it is not a composite ID`,
3751
+ category: "processCompositeId",
3752
+ context: {
3753
+ key,
3754
+ inputElement,
3755
+ compositeIdentifierConfig,
3756
+ error: e
3757
+ }
3758
+ });
3759
+ nonCompositeIds.push(inputElement);
3760
+ }
3761
+ return {
3762
+ compositeIdComponents,
3763
+ nonCompositeIds
3764
+ };
3765
+ };
3766
+ const setDecodedIds = (parentRecord, key, compositeIdComponents, isInputArray) => {
3767
+ const multipleIdsComponents = compositeIdComponents.filter((component) => Object.keys(component).length > 1);
3768
+ if (multipleIdsComponents.length > 0) parentRecord.decoded_ids = {
3769
+ ...parentRecord.decoded_ids ?? {},
3770
+ [key]: isInputArray ? multipleIdsComponents : multipleIdsComponents[0]
3771
+ };
3772
+ };
3773
+ const shouldSimplifyComponent = (component) => {
3774
+ const values = Object.values(component);
3775
+ return values.length === 1 && (typeof values[0] === "string" || typeof values[0] === "number");
3776
+ };
3777
+ const setSimplifiedIds = (parentRecord, key, compositeIdComponents, nonCompositeIds, isInputArray) => {
3778
+ if (!compositeIdComponents.every(shouldSimplifyComponent)) return;
3779
+ if (isInputArray) parentRecord[key] = [...compositeIdComponents.map((component) => Object.values(component)[0]), ...nonCompositeIds];
3780
+ else if (compositeIdComponents.length > 0) parentRecord[key] = Object.values(compositeIdComponents[0])[0];
3781
+ };
3782
+ const handleCompositeIdError = (error, key, logger) => {
3783
+ if (error instanceof CoreError && error.type === "COMPOSITE_ID_MISSING_HEADER_ERROR") logger?.debug({ message: `Received ${key} with no composite ID header, assuming it is not a composite ID` });
3784
+ else logger?.warning({
3785
+ message: `Error processing composite ID for ${key}, ignoring it`,
3786
+ error
3787
+ });
3788
+ };
3789
+ const processCompositeId = (input, key, parentRecord, compositeIdentifierConfig, logger) => {
3790
+ try {
3791
+ const isInputArray = Array.isArray(input);
3792
+ const inputArray = isInputArray ? input : [input];
3793
+ if (inputArray.length === 0) return;
3794
+ const { compositeIdComponents, nonCompositeIds } = processInputElements(inputArray, key, compositeIdentifierConfig, logger);
3795
+ setDecodedIds(parentRecord, key, compositeIdComponents, isInputArray);
3796
+ setSimplifiedIds(parentRecord, key, compositeIdComponents, nonCompositeIds, isInputArray);
3797
+ } catch (e) {
3798
+ handleCompositeIdError(e, key, logger);
3799
+ }
3800
+ };
3801
+
3802
+ //#endregion
3803
+ //#region src/compositeIds/outputs.ts
3804
+ const REMOTE_FIELD_PREFIX = "remote_";
3805
+ const encodeResultCompositeIdentifiers = (block) => {
3806
+ const compositeIdsConfig = block.operation?.compositeIdentifiers;
3807
+ if (!compositeIdsConfig?.enabled) return block;
3808
+ const outputDataKey = "data";
3809
+ const dataOutput = block.outputs?.[outputDataKey];
3810
+ if (isMissing(dataOutput)) return block;
3811
+ const newData = Array.isArray(dataOutput) ? dataOutput.map((item) => mapCompositeIds(item, compositeIdsConfig)) : mapCompositeIds(dataOutput, compositeIdsConfig);
3812
+ return {
3813
+ ...block,
3814
+ outputs: {
3815
+ ...block.outputs ?? {},
3816
+ [outputDataKey]: newData
3817
+ }
3818
+ };
3819
+ };
3820
+ const mapCompositeIds = (data, config$1) => {
3821
+ const dataEncodedFromConfig = mapConfiguredCompositeIds(data, config$1);
3822
+ const encodedData = mapCompositeIdsFromInference(dataEncodedFromConfig);
3823
+ return {
3824
+ ...data,
3825
+ ...isObject(encodedData) ? encodedData : {}
3826
+ };
3827
+ };
3828
+ const mapConfiguredCompositeIds = (data, config$1) => {
3829
+ const version$1 = config$1.version ?? COMPOSITE_ID_LATEST_VERSION;
3830
+ const newData = {};
3831
+ config$1.fields?.forEach((field) => {
3832
+ const aliasesMap = {};
3833
+ const components = [];
3834
+ field.components.forEach((component) => {
3835
+ if (component.alias) aliasesMap[component.name] = component.alias;
3836
+ components.push({
3837
+ key: component.name,
3838
+ value: data[component.name]
3839
+ });
3840
+ });
3841
+ const identifier = components.length === 1 ? components[0] : { identifiers: components };
3842
+ const idConfig = {
3843
+ version: version$1,
3844
+ aliases: Object.keys(aliasesMap).length > 0 ? aliasesMap : void 0
3845
+ };
3846
+ const compositeId = encodeCompositeId(identifier, idConfig);
3847
+ newData[field.targetFieldKey] = compositeId;
3848
+ if (field.remote) newData[`${REMOTE_FIELD_PREFIX}${field.remote}`] = data[field.remote];
3849
+ });
3850
+ return {
3851
+ ...data,
3852
+ ...newData
3853
+ };
3854
+ };
3855
+ const isIdField = (key) => {
3856
+ return key === "id" || /.+_id(s)?$/.test(key);
3857
+ };
3858
+ const isValidStringArray = (value) => {
3859
+ return Array.isArray(value) && value.every((v) => isString(v) && v.length > 0);
3860
+ };
3861
+ const shouldSkipEncoding = (value, key) => {
3862
+ return isCompositeId(value) || key.startsWith(REMOTE_FIELD_PREFIX);
3863
+ };
3864
+ const encodeStringValue = (key, value) => {
3865
+ try {
3866
+ return encodeCompositeId({
3867
+ key,
3868
+ value
3869
+ }, { version: COMPOSITE_ID_LATEST_VERSION });
3870
+ } catch {
3871
+ return value;
3872
+ }
3873
+ };
3874
+ const processStringArrayField = (key, value, result) => {
3875
+ const encodedArray = value.map((v) => {
3876
+ if (isString(v) && v.length > 0 && !isCompositeId(v)) return encodeStringValue(key, v);
3877
+ return v;
3878
+ });
3879
+ result[key] = encodedArray;
3880
+ result[`${REMOTE_FIELD_PREFIX}${key}`] = value;
3881
+ };
3882
+ const processStringField = (key, value, result) => {
3883
+ if (shouldSkipEncoding(value, key)) return;
3884
+ const compositeId = encodeCompositeId({
3885
+ key,
3886
+ value
3887
+ }, { version: COMPOSITE_ID_LATEST_VERSION });
3888
+ result[key] = compositeId;
3889
+ result[`remote_${key}`] = value;
3890
+ };
3891
+ const processIdField = (key, value, result) => {
3892
+ if (isValidStringArray(value)) processStringArrayField(key, value, result);
3893
+ else if (isString(value) && value.length > 0) processStringField(key, value, result);
3894
+ };
3895
+ const mapCompositeIdsFromInference = (data) => {
3896
+ if (Array.isArray(data)) return data.map((item) => mapCompositeIdsFromInference(item));
3897
+ if (!isObject(data)) return data;
3898
+ const result = { ...data };
3899
+ for (const [key, value] of Object.entries(data)) {
3900
+ if (isObject(value) || Array.isArray(value) && value.length > 0 && isObject(value[0])) result[key] = mapCompositeIdsFromInference(value);
3901
+ if (isIdField(key)) processIdField(key, value, result);
3902
+ }
3903
+ return result;
3904
+ };
3905
+
3906
+ //#endregion
3907
+ //#region src/pagination/utils.ts
3908
+ const getPageSize = (block, defaultValue) => {
3909
+ const inputPageSize = Number(block.inputs?.page_size);
3910
+ const pageSize = notMissing(block.inputs?.page_size) && isNumber(inputPageSize) && !Number.isNaN(inputPageSize) ? inputPageSize : block.operation?.cursor?.pageSize ?? defaultValue;
3911
+ return pageSize;
3912
+ };
3913
+
3914
+ //#endregion
3915
+ //#region src/pagination/virtualPagination.ts
3916
+ const virtualPaginateResult = (result, pageSize, steps, cursor) => {
3917
+ const data = isMissing(result) ? void 0 : result.data;
3918
+ const resultStepIndex = Object.keys(steps).length + 1;
3919
+ const emptyCursor = isCursorEmpty({
3920
+ cursor,
3921
+ ignoreStepIndex: resultStepIndex
3922
+ });
3923
+ if (!isObject(result) || isMissing(data) || (data?.length ?? 0) <= pageSize) return {
3924
+ result,
3925
+ next: notMissing(cursor) && !emptyCursor ? minifyCursor(cursor) : null
3926
+ };
3927
+ const pageNumber = cursor?.remote?.[resultStepIndex]?.pageNumber ?? 1;
3928
+ const startIndex = (pageNumber - 1) * pageSize;
3929
+ const endIndex = startIndex + pageSize;
3930
+ const slicedData = data.slice(startIndex, endIndex);
3931
+ const hasMorePages = data.length > endIndex || !emptyCursor;
3932
+ const pageCursor = updateCursor({
3933
+ cursor,
3934
+ stepIndex: resultStepIndex,
3935
+ pageNumber: pageNumber + 1
3936
+ });
3937
+ return {
3938
+ result: {
3939
+ ...result,
3940
+ data: slicedData
3941
+ },
3942
+ next: hasMorePages ? minifyCursor(pageCursor) : null
3943
+ };
3944
+ };
3945
+
3946
+ //#endregion
3947
+ //#region src/runners/runStepOperation.ts
3948
+ const runStepOperation = async ({ block, buildStepFunction = StepFunctionsFactory.build, virtualPaginateResultFn = virtualPaginateResult, encodeResultCompositeIds = encodeResultCompositeIdentifiers, decodeInputCompositeIds = decodeInputCompositeIdentifiers }) => {
3949
+ const decodeBlock = decodeInputCompositeIds(block);
3950
+ const resultBlock = await executeStepsWorkflow({
3951
+ block: decodeBlock,
3952
+ buildStepFunction,
3953
+ virtualPaginateResultFn
3954
+ });
3955
+ return encodeResultCompositeIds(resultBlock);
3956
+ };
3957
+ const shouldSkipStepDueToCondition = (step, block) => {
3958
+ return step.condition ? !safeEvaluate(step.condition, block) : false;
3959
+ };
3960
+ const buildStepParams = (step, blockAcc, stepIndex) => {
3961
+ const fn = step.stepFunction;
3962
+ return blockAcc.operation?.cursor.enabled ? {
3963
+ ...fn.params ?? {},
3964
+ cursor: {
3965
+ token: blockAcc.nextCursor?.remote?.[stepIndex]?.providerPageCursor,
3966
+ position: blockAcc.nextCursor?.remote?.[stepIndex]?.position
3967
+ }
3968
+ } : fn.params ?? {};
3969
+ };
3970
+ const handleStepFailure = (blockAcc, stepId, functionOutput, step, state) => {
3971
+ const updatedBlock = addStepResultToBlock({
3972
+ block: blockAcc,
3973
+ stepId,
3974
+ successful: false,
3975
+ functionOutput
3976
+ });
3977
+ const ignoreError = step.ignoreError ?? false;
3978
+ if (!ignoreError) {
3979
+ state.hasFatalError = true;
3980
+ state.errorStatusCode ??= functionOutput.output?.statusCode ?? 500;
3981
+ }
3982
+ return updatedBlock;
3983
+ };
3984
+ const executeStep = async (stepId, stepIndex, stepsToExecute, blockAcc, state, context) => {
3985
+ const step = stepsToExecute[stepId];
3986
+ const fn = step.stepFunction;
3987
+ const stepFunction = context.buildStepFunction({
3988
+ functionName: fn.functionName,
3989
+ version: fn.version,
3990
+ validateSchemas: true
3991
+ }).fn;
3992
+ if (shouldSkipStepDueToCondition(step, blockAcc)) return addStepResultToBlock({
3993
+ block: blockAcc,
3994
+ stepId,
3995
+ successful: true,
3996
+ skipped: true,
3997
+ message: "Step skipped due to condition not met."
3998
+ });
3999
+ if (state.hasFatalError) return addStepResultToBlock({
4000
+ block: blockAcc,
4001
+ stepId,
4002
+ successful: false,
4003
+ skipped: true,
4004
+ message: "Step skipped due to previous error."
4005
+ });
4006
+ const fnParams = buildStepParams(step, blockAcc, stepIndex);
4007
+ const functionOutput = await stepFunction({
4008
+ block: blockAcc,
4009
+ params: fnParams
4010
+ });
4011
+ if (functionOutput.successful === false) return handleStepFailure(blockAcc, stepId, functionOutput, step, state);
4012
+ const updatedCursor = blockAcc.operation?.cursor.enabled ? updateCursor({
4013
+ cursor: blockAcc.nextCursor,
4014
+ stepIndex,
4015
+ providerPageCursor: functionOutput.output?.next,
4016
+ position: functionOutput.output?.position
4017
+ }) : void 0;
4018
+ return addStepResultToBlock({
4019
+ block: {
4020
+ ...functionOutput.block,
4021
+ nextCursor: updatedCursor
4022
+ },
4023
+ stepId,
4024
+ functionOutput
4025
+ });
4026
+ };
4027
+ const buildFinalResponse = (block, blockAcc, state, result, finalData) => {
4028
+ const isSuccessful = !state.hasFatalError;
4029
+ const finalStatusCode = isSuccessful ? block.operation?.responses.success.statusCode ?? 200 : state.errorStatusCode ?? 500;
4030
+ const outputs = notMissing(finalData) && isObject(finalData.result) ? {
4031
+ next: finalData.next,
4032
+ ...finalData.result
4033
+ } : result;
4034
+ return {
4035
+ ...blockAcc,
4036
+ outputs,
4037
+ response: {
4038
+ successful: isSuccessful,
4039
+ statusCode: finalStatusCode,
4040
+ message: !isSuccessful ? block.operation?.responses?.errors?.[finalStatusCode]?.description ?? HttpErrorMessages?.[finalStatusCode] ?? "Error while processing the request" : void 0
4041
+ }
4042
+ };
4043
+ };
4044
+ const executeStepsWorkflow = async ({ block, buildStepFunction = StepFunctionsFactory.build, virtualPaginateResultFn = virtualPaginateResult }) => {
4045
+ const stepsToExecute = block.operation?.steps || {};
4046
+ let blockAcc = { ...block };
4047
+ const stepsIds = Object.keys(stepsToExecute);
4048
+ const pageSize = getPageSize(block, DEFAULT_PAGE_SIZE);
4049
+ const state = {
4050
+ hasFatalError: false,
4051
+ errorStatusCode: null
4052
+ };
4053
+ const context = {
4054
+ block,
4055
+ buildStepFunction,
4056
+ virtualPaginateResultFn
4057
+ };
4058
+ for (const [stepIndex, stepId] of stepsIds.entries()) blockAcc = await executeStep(stepId, stepIndex, stepsToExecute, blockAcc, state, context);
4059
+ const result = block.operation?.result ? evaluateResult(block.operation.result, blockAcc) : void 0;
4060
+ const finalData = block.operation?.cursor.enabled ? virtualPaginateResultFn(result, pageSize, stepsToExecute, blockAcc.nextCursor) : void 0;
4061
+ return buildFinalResponse(block, blockAcc, state, result, finalData);
4062
+ };
4063
+ const evaluateResult = (result, block) => {
4064
+ if (isObject(result)) return safeEvaluateRecord(result, block);
4065
+ return safeEvaluate(result, block);
4066
+ };
4067
+ const addStepResultToBlock = ({ block, stepId, successful, functionOutput, skipped, message }) => {
4068
+ return {
4069
+ ...block,
4070
+ steps: {
4071
+ ...block.steps,
4072
+ [stepId]: {
4073
+ successful: successful ?? functionOutput?.successful ?? false,
4074
+ errors: functionOutput?.errors,
4075
+ output: functionOutput?.output,
4076
+ skipped,
4077
+ message
4078
+ }
4079
+ }
4080
+ };
4081
+ };
4082
+
4083
+ //#endregion
4084
+ //#region src/runners/runConnectorOperation.ts
4085
+ const runConnectorOperation = async ({ account, connector, category, path, method = "get", queryParams, body, headers, logger, parseConnector = parseYamlConnector, getOperationFromUrlFn = getOperationFromUrl, parseOperationInputsFn = parseOperationInputs, createBlockContextFn = createBlockContext, createBlockFn = createBlock, runStepOperationFn = runStepOperation }) => {
4086
+ const authConfigKey = account.authConfigKey;
4087
+ const environment = account.environment ?? "production";
4088
+ const accountSecureId = account.secureId;
4089
+ const projectSecureId = account.projectSecureId;
4090
+ const credentials = account.credentials;
4091
+ const blockContext = createBlockContextFn({
4092
+ category,
4093
+ connectorKey: account.providerKey,
4094
+ connectorVersion: account.providerVersion,
4095
+ authConfigKey,
4096
+ environment,
4097
+ accountSecureId,
4098
+ projectSecureId
4099
+ });
4100
+ let parsedConnector;
4101
+ try {
4102
+ parsedConnector = isString(connector) ? parseConnector(connector) : connector;
4103
+ } catch {
4104
+ throw new ConnectorParseError(blockContext, "Error while parsing connector");
4105
+ }
4106
+ const matchingOperation = getOperationFromUrlFn(parsedConnector, path, method);
4107
+ if (isMissing(matchingOperation)) throw new MissingOperationError(blockContext, "No matching operation found");
4108
+ blockContext.operationType = matchingOperation.operation.operationType;
4109
+ blockContext.schema = matchingOperation.operation.schema?.key;
4110
+ const expandedCursor = processCursor(queryParams, blockContext);
4111
+ let operationInputs;
4112
+ try {
4113
+ operationInputs = parseOperationInputsFn(matchingOperation.operation, {
4114
+ query: queryParams,
4115
+ body,
4116
+ headers,
4117
+ path: matchingOperation.params
4118
+ });
4119
+ } catch {
4120
+ throw new InvalidOperationInputsError(blockContext, "Error while parsing operation inputs");
4121
+ }
4122
+ const block = await createBlockFn({
4123
+ inputs: operationInputs,
4124
+ context: blockContext,
4125
+ operation: matchingOperation.operation,
4126
+ credentials,
4127
+ nextCursor: expandedCursor,
4128
+ logger
4129
+ });
4130
+ return await runStepOperationFn({ block });
4131
+ };
4132
+ const processCursor = (queryParams, blockContext) => {
4133
+ const nextCursor = queryParams?.["next"];
4134
+ const expandedCursor = notMissing(nextCursor) && blockContext.operationType === "list" ? expandCursor(nextCursor) : void 0;
4135
+ if (expandedCursor === null) throw new InvalidCursorError(blockContext, `Invalid cursor.`);
4136
+ return expandedCursor;
4137
+ };
4138
+
4139
+ //#endregion
4140
+ export { ConnectSDKError, createBlock, executeStepFunction, getOperationFromUrl, parseOperationInputs, parseYamlConnector, runConnectorOperation, runStepOperation };