passkey-magic 0.1.0

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