@finatic/client 0.9.5 → 0.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,28 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var pRetry = require('p-retry');
4
- var z = require('zod');
5
3
  var globalAxios = require('axios');
6
4
 
7
- function _interopNamespaceDefault(e) {
8
- var n = Object.create(null);
9
- if (e) {
10
- Object.keys(e).forEach(function (k) {
11
- if (k !== 'default') {
12
- var d = Object.getOwnPropertyDescriptor(e, k);
13
- Object.defineProperty(n, k, d.get ? d : {
14
- enumerable: true,
15
- get: function () { return e[k]; }
16
- });
17
- }
18
- });
19
- }
20
- n.default = e;
21
- return Object.freeze(n);
22
- }
23
-
24
- var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
25
-
26
5
  /**
27
6
  * Request ID generator utility.
28
7
  *
@@ -44,6 +23,264 @@ function generateRequestId() {
44
23
  });
45
24
  }
46
25
 
26
+ const objectToString = Object.prototype.toString;
27
+
28
+ const isError = value => objectToString.call(value) === '[object Error]';
29
+
30
+ const errorMessages = new Set([
31
+ 'network error', // Chrome
32
+ 'Failed to fetch', // Chrome
33
+ 'NetworkError when attempting to fetch resource.', // Firefox
34
+ 'The Internet connection appears to be offline.', // Safari 16
35
+ 'Network request failed', // `cross-fetch`
36
+ 'fetch failed', // Undici (Node.js)
37
+ 'terminated', // Undici (Node.js)
38
+ ' A network error occurred.', // Bun (WebKit)
39
+ 'Network connection lost', // Cloudflare Workers (fetch)
40
+ ]);
41
+
42
+ function isNetworkError(error) {
43
+ const isValid = error
44
+ && isError(error)
45
+ && error.name === 'TypeError'
46
+ && typeof error.message === 'string';
47
+
48
+ if (!isValid) {
49
+ return false;
50
+ }
51
+
52
+ const {message, stack} = error;
53
+
54
+ // Safari 17+ has generic message but no stack for network errors
55
+ if (message === 'Load failed') {
56
+ return stack === undefined
57
+ // Sentry adds its own stack trace to the fetch error, so also check for that
58
+ || '__sentry_captured__' in error;
59
+ }
60
+
61
+ // Deno network errors start with specific text
62
+ if (message.startsWith('error sending request for url')) {
63
+ return true;
64
+ }
65
+
66
+ // Standard network error messages
67
+ return errorMessages.has(message);
68
+ }
69
+
70
+ function validateRetries(retries) {
71
+ if (typeof retries === 'number') {
72
+ if (retries < 0) {
73
+ throw new TypeError('Expected `retries` to be a non-negative number.');
74
+ }
75
+
76
+ if (Number.isNaN(retries)) {
77
+ throw new TypeError('Expected `retries` to be a valid number or Infinity, got NaN.');
78
+ }
79
+ } else if (retries !== undefined) {
80
+ throw new TypeError('Expected `retries` to be a number or Infinity.');
81
+ }
82
+ }
83
+
84
+ function validateNumberOption(name, value, {min = 0, allowInfinity = false} = {}) {
85
+ if (value === undefined) {
86
+ return;
87
+ }
88
+
89
+ if (typeof value !== 'number' || Number.isNaN(value)) {
90
+ throw new TypeError(`Expected \`${name}\` to be a number${allowInfinity ? ' or Infinity' : ''}.`);
91
+ }
92
+
93
+ if (!allowInfinity && !Number.isFinite(value)) {
94
+ throw new TypeError(`Expected \`${name}\` to be a finite number.`);
95
+ }
96
+
97
+ if (value < min) {
98
+ throw new TypeError(`Expected \`${name}\` to be \u2265 ${min}.`);
99
+ }
100
+ }
101
+
102
+ class AbortError extends Error {
103
+ constructor(message) {
104
+ super();
105
+
106
+ if (message instanceof Error) {
107
+ this.originalError = message;
108
+ ({message} = message);
109
+ } else {
110
+ this.originalError = new Error(message);
111
+ this.originalError.stack = this.stack;
112
+ }
113
+
114
+ this.name = 'AbortError';
115
+ this.message = message;
116
+ }
117
+ }
118
+
119
+ function calculateDelay(retriesConsumed, options) {
120
+ const attempt = Math.max(1, retriesConsumed + 1);
121
+ const random = options.randomize ? (Math.random() + 1) : 1;
122
+
123
+ let timeout = Math.round(random * options.minTimeout * (options.factor ** (attempt - 1)));
124
+ timeout = Math.min(timeout, options.maxTimeout);
125
+
126
+ return timeout;
127
+ }
128
+
129
+ function calculateRemainingTime(start, max) {
130
+ if (!Number.isFinite(max)) {
131
+ return max;
132
+ }
133
+
134
+ return max - (performance.now() - start);
135
+ }
136
+
137
+ async function onAttemptFailure({error, attemptNumber, retriesConsumed, startTime, options}) {
138
+ const normalizedError = error instanceof Error
139
+ ? error
140
+ : new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`);
141
+
142
+ if (normalizedError instanceof AbortError) {
143
+ throw normalizedError.originalError;
144
+ }
145
+
146
+ const retriesLeft = Number.isFinite(options.retries)
147
+ ? Math.max(0, options.retries - retriesConsumed)
148
+ : options.retries;
149
+
150
+ const maxRetryTime = options.maxRetryTime ?? Number.POSITIVE_INFINITY;
151
+
152
+ const context = Object.freeze({
153
+ error: normalizedError,
154
+ attemptNumber,
155
+ retriesLeft,
156
+ retriesConsumed,
157
+ });
158
+
159
+ await options.onFailedAttempt(context);
160
+
161
+ if (calculateRemainingTime(startTime, maxRetryTime) <= 0) {
162
+ throw normalizedError;
163
+ }
164
+
165
+ const consumeRetry = await options.shouldConsumeRetry(context);
166
+
167
+ const remainingTime = calculateRemainingTime(startTime, maxRetryTime);
168
+
169
+ if (remainingTime <= 0 || retriesLeft <= 0) {
170
+ throw normalizedError;
171
+ }
172
+
173
+ if (normalizedError instanceof TypeError && !isNetworkError(normalizedError)) {
174
+ if (consumeRetry) {
175
+ throw normalizedError;
176
+ }
177
+
178
+ options.signal?.throwIfAborted();
179
+ return false;
180
+ }
181
+
182
+ if (!await options.shouldRetry(context)) {
183
+ throw normalizedError;
184
+ }
185
+
186
+ if (!consumeRetry) {
187
+ options.signal?.throwIfAborted();
188
+ return false;
189
+ }
190
+
191
+ const delayTime = calculateDelay(retriesConsumed, options);
192
+ const finalDelay = Math.min(delayTime, remainingTime);
193
+
194
+ if (finalDelay > 0) {
195
+ await new Promise((resolve, reject) => {
196
+ const onAbort = () => {
197
+ clearTimeout(timeoutToken);
198
+ options.signal?.removeEventListener('abort', onAbort);
199
+ reject(options.signal.reason);
200
+ };
201
+
202
+ const timeoutToken = setTimeout(() => {
203
+ options.signal?.removeEventListener('abort', onAbort);
204
+ resolve();
205
+ }, finalDelay);
206
+
207
+ if (options.unref) {
208
+ timeoutToken.unref?.();
209
+ }
210
+
211
+ options.signal?.addEventListener('abort', onAbort, {once: true});
212
+ });
213
+ }
214
+
215
+ options.signal?.throwIfAborted();
216
+
217
+ return true;
218
+ }
219
+
220
+ async function pRetry(input, options = {}) {
221
+ options = {...options};
222
+
223
+ validateRetries(options.retries);
224
+
225
+ if (Object.hasOwn(options, 'forever')) {
226
+ throw new Error('The `forever` option is no longer supported. For many use-cases, you can set `retries: Infinity` instead.');
227
+ }
228
+
229
+ options.retries ??= 10;
230
+ options.factor ??= 2;
231
+ options.minTimeout ??= 1000;
232
+ options.maxTimeout ??= Number.POSITIVE_INFINITY;
233
+ options.maxRetryTime ??= Number.POSITIVE_INFINITY;
234
+ options.randomize ??= false;
235
+ options.onFailedAttempt ??= () => {};
236
+ options.shouldRetry ??= () => true;
237
+ options.shouldConsumeRetry ??= () => true;
238
+
239
+ // Validate numeric options and normalize edge cases
240
+ validateNumberOption('factor', options.factor, {min: 0, allowInfinity: false});
241
+ validateNumberOption('minTimeout', options.minTimeout, {min: 0, allowInfinity: false});
242
+ validateNumberOption('maxTimeout', options.maxTimeout, {min: 0, allowInfinity: true});
243
+ validateNumberOption('maxRetryTime', options.maxRetryTime, {min: 0, allowInfinity: true});
244
+
245
+ // Treat non-positive factor as 1 to avoid zero backoff or negative behavior
246
+ if (!(options.factor > 0)) {
247
+ options.factor = 1;
248
+ }
249
+
250
+ options.signal?.throwIfAborted();
251
+
252
+ let attemptNumber = 0;
253
+ let retriesConsumed = 0;
254
+ const startTime = performance.now();
255
+
256
+ while (Number.isFinite(options.retries) ? retriesConsumed <= options.retries : true) {
257
+ attemptNumber++;
258
+
259
+ try {
260
+ options.signal?.throwIfAborted();
261
+
262
+ const result = await input(attemptNumber);
263
+
264
+ options.signal?.throwIfAborted();
265
+
266
+ return result;
267
+ } catch (error) {
268
+ if (await onAttemptFailure({
269
+ error,
270
+ attemptNumber,
271
+ retriesConsumed,
272
+ startTime,
273
+ options,
274
+ })) {
275
+ retriesConsumed++;
276
+ }
277
+ }
278
+ }
279
+
280
+ // Should not reach here, but in case it does, throw an error
281
+ throw new Error('Retry attempts exhausted without throwing an error.');
282
+ }
283
+
47
284
  /**
48
285
  * Retry utility with p-retry package (Phase 2B).
49
286
  *
@@ -79,11 +316,11 @@ async function retryApiCall(fn, options = {}, config) {
79
316
  const statusCode = error?.response?.status || error?.statusCode || error?.status;
80
317
  // Don't retry if status code doesn't match retry list
81
318
  if (statusCode && !opts.retryOnStatus.includes(statusCode)) {
82
- throw new pRetry.AbortError(error);
319
+ throw new AbortError(error);
83
320
  }
84
321
  // Check for network errors
85
322
  if (!statusCode && !opts.retryOnNetworkError) {
86
- throw new pRetry.AbortError(error);
323
+ throw new AbortError(error);
87
324
  }
88
325
  // Re-throw to trigger retry
89
326
  throw error;
@@ -4529,167 +4766,3044 @@ class SessionWrapper {
4529
4766
  }
4530
4767
  }
4531
4768
 
4532
- /**
4533
- * Input validation utility with zod package (Phase 2B).
4534
- *
4535
- * Generated - do not edit directly.
4536
- */
4537
- /**
4538
- * Validate parameters using zod schema.
4539
- */
4540
- function validateParams(schema, params, config) {
4541
- if (!config?.validationEnabled) {
4542
- return params;
4543
- }
4544
- try {
4545
- return schema.parse(params);
4546
- }
4547
- catch (error) {
4548
- if (error instanceof z__namespace.ZodError) {
4549
- const message = `Validation failed: ${error.issues.map((e) => `${e.path.join('.')}: ${e.message}`).join(', ')}`;
4550
- if (config?.validationStrict) {
4551
- throw new ValidationError(message);
4552
- }
4553
- else {
4554
- console.warn(`[Validation Warning] ${message}`);
4555
- return params;
4556
- }
4769
+ /** A special constant with type `never` */
4770
+ function $constructor(name, initializer, params) {
4771
+ function init(inst, def) {
4772
+ if (!inst._zod) {
4773
+ Object.defineProperty(inst, "_zod", {
4774
+ value: {
4775
+ def,
4776
+ constr: _,
4777
+ traits: new Set(),
4778
+ },
4779
+ enumerable: false,
4780
+ });
4557
4781
  }
4558
- throw error;
4559
- }
4782
+ if (inst._zod.traits.has(name)) {
4783
+ return;
4784
+ }
4785
+ inst._zod.traits.add(name);
4786
+ initializer(inst, def);
4787
+ // support prototype modifications
4788
+ const proto = _.prototype;
4789
+ const keys = Object.keys(proto);
4790
+ for (let i = 0; i < keys.length; i++) {
4791
+ const k = keys[i];
4792
+ if (!(k in inst)) {
4793
+ inst[k] = proto[k].bind(inst);
4794
+ }
4795
+ }
4796
+ }
4797
+ // doesn't work if Parent has a constructor with arguments
4798
+ const Parent = params?.Parent ?? Object;
4799
+ class Definition extends Parent {
4800
+ }
4801
+ Object.defineProperty(Definition, "name", { value: name });
4802
+ function _(def) {
4803
+ var _a;
4804
+ const inst = params?.Parent ? new Definition() : this;
4805
+ init(inst, def);
4806
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
4807
+ for (const fn of inst._zod.deferred) {
4808
+ fn();
4809
+ }
4810
+ return inst;
4811
+ }
4812
+ Object.defineProperty(_, "init", { value: init });
4813
+ Object.defineProperty(_, Symbol.hasInstance, {
4814
+ value: (inst) => {
4815
+ if (params?.Parent && inst instanceof params.Parent)
4816
+ return true;
4817
+ return inst?._zod?.traits?.has(name);
4818
+ },
4819
+ });
4820
+ Object.defineProperty(_, "name", { value: name });
4821
+ return _;
4560
4822
  }
4561
- /**
4562
- * Create a number schema with min/max constraints.
4563
- */
4564
- function numberSchema(min, max, defaultVal) {
4565
- let schema = z__namespace.number();
4566
- if (min !== undefined)
4567
- schema = schema.min(min);
4568
- if (max !== undefined)
4569
- schema = schema.max(max);
4570
- if (defaultVal !== undefined) {
4571
- // Use .default() which automatically makes the field optional
4572
- // This avoids the ZodUnion issue with .optional().default()
4573
- schema = schema.default(defaultVal);
4823
+ class $ZodAsyncError extends Error {
4824
+ constructor() {
4825
+ super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
4574
4826
  }
4575
- return schema;
4576
4827
  }
4577
- /**
4578
- * Create a string schema with length constraints.
4579
- */
4580
- function stringSchema(min, max, defaultVal) {
4581
- let schema = z__namespace.string();
4582
- if (min !== undefined)
4583
- schema = schema.min(min);
4584
- if (max !== undefined)
4585
- schema = schema.max(max);
4586
- if (defaultVal !== undefined) {
4587
- // Use .default() which automatically makes the field optional
4588
- // This avoids the ZodUnion issue with .optional().default()
4589
- schema = schema.default(defaultVal);
4828
+ class $ZodEncodeError extends Error {
4829
+ constructor(name) {
4830
+ super(`Encountered unidirectional transform during encode: ${name}`);
4831
+ this.name = "ZodEncodeError";
4590
4832
  }
4591
- return schema;
4833
+ }
4834
+ const globalConfig = {};
4835
+ function config(newConfig) {
4836
+ return globalConfig;
4592
4837
  }
4593
4838
 
4594
- /**
4595
- * URL utility functions for portal URL manipulation.
4596
- *
4597
- * Generated - do not edit directly.
4598
- */
4599
- /**
4600
- * Append theme parameters to a portal URL.
4601
- * @param baseUrl The base portal URL (may already have query parameters)
4602
- * @param theme The theme configuration (preset string or custom object)
4603
- * @returns The portal URL with theme parameters appended
4604
- */
4605
- function appendThemeToURL(baseUrl, theme) {
4606
- if (!theme) {
4607
- return baseUrl;
4839
+ // functions
4840
+ function jsonStringifyReplacer(_, value) {
4841
+ if (typeof value === "bigint")
4842
+ return value.toString();
4843
+ return value;
4844
+ }
4845
+ function nullish(input) {
4846
+ return input === null || input === undefined;
4847
+ }
4848
+ function cleanRegex(source) {
4849
+ const start = source.startsWith("^") ? 1 : 0;
4850
+ const end = source.endsWith("$") ? source.length - 1 : source.length;
4851
+ return source.slice(start, end);
4852
+ }
4853
+ function floatSafeRemainder(val, step) {
4854
+ const valDecCount = (val.toString().split(".")[1] || "").length;
4855
+ const stepString = step.toString();
4856
+ let stepDecCount = (stepString.split(".")[1] || "").length;
4857
+ if (stepDecCount === 0 && /\d?e-\d?/.test(stepString)) {
4858
+ const match = stepString.match(/\d?e-(\d?)/);
4859
+ if (match?.[1]) {
4860
+ stepDecCount = Number.parseInt(match[1]);
4861
+ }
4862
+ }
4863
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
4864
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
4865
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
4866
+ return (valInt % stepInt) / 10 ** decCount;
4867
+ }
4868
+ const EVALUATING = Symbol("evaluating");
4869
+ function defineLazy(object, key, getter) {
4870
+ let value = undefined;
4871
+ Object.defineProperty(object, key, {
4872
+ get() {
4873
+ if (value === EVALUATING) {
4874
+ // Circular reference detected, return undefined to break the cycle
4875
+ return undefined;
4876
+ }
4877
+ if (value === undefined) {
4878
+ value = EVALUATING;
4879
+ value = getter();
4880
+ }
4881
+ return value;
4882
+ },
4883
+ set(v) {
4884
+ Object.defineProperty(object, key, {
4885
+ value: v,
4886
+ // configurable: true,
4887
+ });
4888
+ // object[key] = v;
4889
+ },
4890
+ configurable: true,
4891
+ });
4892
+ }
4893
+ function mergeDefs(...defs) {
4894
+ const mergedDescriptors = {};
4895
+ for (const def of defs) {
4896
+ const descriptors = Object.getOwnPropertyDescriptors(def);
4897
+ Object.assign(mergedDescriptors, descriptors);
4608
4898
  }
4609
- try {
4610
- const url = new URL(baseUrl);
4611
- if (typeof theme === 'string') {
4612
- // Preset theme
4613
- url.searchParams.set('theme', theme);
4614
- }
4615
- else if (theme.preset) {
4616
- // Preset theme from object
4617
- url.searchParams.set('theme', theme.preset);
4618
- }
4619
- else if (theme.custom) {
4620
- // Custom theme
4621
- const encodedTheme = btoa(JSON.stringify(theme.custom));
4622
- url.searchParams.set('theme', 'custom');
4623
- url.searchParams.set('themeObject', encodedTheme);
4899
+ return Object.defineProperties({}, mergedDescriptors);
4900
+ }
4901
+ function slugify(input) {
4902
+ return input
4903
+ .toLowerCase()
4904
+ .trim()
4905
+ .replace(/[^\w\s-]/g, "")
4906
+ .replace(/[\s_-]+/g, "-")
4907
+ .replace(/^-+|-+$/g, "");
4908
+ }
4909
+ const captureStackTrace = ("captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => { });
4910
+ function isObject(data) {
4911
+ return typeof data === "object" && data !== null && !Array.isArray(data);
4912
+ }
4913
+ function isPlainObject(o) {
4914
+ if (isObject(o) === false)
4915
+ return false;
4916
+ // modified constructor
4917
+ const ctor = o.constructor;
4918
+ if (ctor === undefined)
4919
+ return true;
4920
+ if (typeof ctor !== "function")
4921
+ return true;
4922
+ // modified prototype
4923
+ const prot = ctor.prototype;
4924
+ if (isObject(prot) === false)
4925
+ return false;
4926
+ // ctor doesn't have static `isPrototypeOf`
4927
+ if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) {
4928
+ return false;
4929
+ }
4930
+ return true;
4931
+ }
4932
+ function shallowClone(o) {
4933
+ if (isPlainObject(o))
4934
+ return { ...o };
4935
+ if (Array.isArray(o))
4936
+ return [...o];
4937
+ return o;
4938
+ }
4939
+ function escapeRegex(str) {
4940
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4941
+ }
4942
+ // zod-specific utils
4943
+ function clone(inst, def, params) {
4944
+ const cl = new inst._zod.constr(def ?? inst._zod.def);
4945
+ if (!def || params?.parent)
4946
+ cl._zod.parent = inst;
4947
+ return cl;
4948
+ }
4949
+ function normalizeParams(_params) {
4950
+ const params = _params;
4951
+ if (!params)
4952
+ return {};
4953
+ if (typeof params === "string")
4954
+ return { error: () => params };
4955
+ if (params?.message !== undefined) {
4956
+ if (params?.error !== undefined)
4957
+ throw new Error("Cannot specify both `message` and `error` params");
4958
+ params.error = params.message;
4959
+ }
4960
+ delete params.message;
4961
+ if (typeof params.error === "string")
4962
+ return { ...params, error: () => params.error };
4963
+ return params;
4964
+ }
4965
+ const NUMBER_FORMAT_RANGES = {
4966
+ safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
4967
+ int32: [-2147483648, 2147483647],
4968
+ uint32: [0, 4294967295],
4969
+ float32: [-34028234663852886e22, 3.4028234663852886e38],
4970
+ float64: [-Number.MAX_VALUE, Number.MAX_VALUE],
4971
+ };
4972
+ // invalid_type | too_big | too_small | invalid_format | not_multiple_of | unrecognized_keys | invalid_union | invalid_key | invalid_element | invalid_value | custom
4973
+ function aborted(x, startIndex = 0) {
4974
+ if (x.aborted === true)
4975
+ return true;
4976
+ for (let i = startIndex; i < x.issues.length; i++) {
4977
+ if (x.issues[i]?.continue !== true) {
4978
+ return true;
4624
4979
  }
4625
- return url.toString();
4626
- }
4627
- catch (error) {
4628
- // If URL parsing fails, return original URL
4629
- return baseUrl;
4630
4980
  }
4981
+ return false;
4631
4982
  }
4632
- /**
4633
- * Append broker filter parameters to a portal URL.
4634
- * @param baseUrl The base portal URL (may already have query parameters)
4635
- * @param brokerNames Array of broker names/IDs to filter by
4636
- * @returns The portal URL with broker filter parameters appended
4637
- */
4638
- function appendBrokerFilterToURL(baseUrl, brokerNames) {
4639
- if (!brokerNames || brokerNames.length === 0) {
4640
- return baseUrl;
4641
- }
4642
- try {
4643
- const url = new URL(baseUrl);
4644
- const encodedBrokers = btoa(JSON.stringify(brokerNames));
4645
- url.searchParams.set('brokers', encodedBrokers);
4646
- return url.toString();
4647
- }
4648
- catch (error) {
4649
- // If URL parsing fails, return original URL
4650
- return baseUrl;
4983
+ function prefixIssues(path, issues) {
4984
+ return issues.map((iss) => {
4985
+ var _a;
4986
+ (_a = iss).path ?? (_a.path = []);
4987
+ iss.path.unshift(path);
4988
+ return iss;
4989
+ });
4990
+ }
4991
+ function unwrapMessage(message) {
4992
+ return typeof message === "string" ? message : message?.message;
4993
+ }
4994
+ function finalizeIssue(iss, ctx, config) {
4995
+ const full = { ...iss, path: iss.path ?? [] };
4996
+ // for backwards compatibility
4997
+ if (!iss.message) {
4998
+ const message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ??
4999
+ unwrapMessage(ctx?.error?.(iss)) ??
5000
+ unwrapMessage(config.customError?.(iss)) ??
5001
+ unwrapMessage(config.localeError?.(iss)) ??
5002
+ "Invalid input";
5003
+ full.message = message;
5004
+ }
5005
+ // delete (full as any).def;
5006
+ delete full.inst;
5007
+ delete full.continue;
5008
+ if (!ctx?.reportInput) {
5009
+ delete full.input;
5010
+ }
5011
+ return full;
5012
+ }
5013
+ function getLengthableOrigin(input) {
5014
+ if (Array.isArray(input))
5015
+ return "array";
5016
+ if (typeof input === "string")
5017
+ return "string";
5018
+ return "unknown";
5019
+ }
5020
+ function issue(...args) {
5021
+ const [iss, input, inst] = args;
5022
+ if (typeof iss === "string") {
5023
+ return {
5024
+ message: iss,
5025
+ code: "custom",
5026
+ input,
5027
+ inst,
5028
+ };
4651
5029
  }
5030
+ return { ...iss };
4652
5031
  }
4653
5032
 
4654
- /**
4655
- * EventEmitter utility for Client SDK.
4656
- *
4657
- * Generated - do not edit directly.
4658
- */
4659
- class EventEmitter {
4660
- constructor() {
4661
- this.events = new Map();
4662
- }
4663
- on(event, callback) {
4664
- if (!this.events.has(event)) {
4665
- this.events.set(event, new Set());
5033
+ const initializer$1 = (inst, def) => {
5034
+ inst.name = "$ZodError";
5035
+ Object.defineProperty(inst, "_zod", {
5036
+ value: inst._zod,
5037
+ enumerable: false,
5038
+ });
5039
+ Object.defineProperty(inst, "issues", {
5040
+ value: def,
5041
+ enumerable: false,
5042
+ });
5043
+ inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
5044
+ Object.defineProperty(inst, "toString", {
5045
+ value: () => inst.message,
5046
+ enumerable: false,
5047
+ });
5048
+ };
5049
+ const $ZodError = $constructor("$ZodError", initializer$1);
5050
+ const $ZodRealError = $constructor("$ZodError", initializer$1, { Parent: Error });
5051
+ function flattenError(error, mapper = (issue) => issue.message) {
5052
+ const fieldErrors = {};
5053
+ const formErrors = [];
5054
+ for (const sub of error.issues) {
5055
+ if (sub.path.length > 0) {
5056
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
5057
+ fieldErrors[sub.path[0]].push(mapper(sub));
4666
5058
  }
4667
- this.events.get(event).add(callback);
4668
- }
4669
- off(event, callback) {
4670
- if (this.events.has(event)) {
4671
- this.events.get(event).delete(callback);
5059
+ else {
5060
+ formErrors.push(mapper(sub));
4672
5061
  }
4673
5062
  }
4674
- once(event, callback) {
4675
- const onceCallback = (...args) => {
4676
- callback(...args);
4677
- this.off(event, onceCallback);
4678
- };
4679
- this.on(event, onceCallback);
4680
- }
4681
- emit(event, ...args) {
4682
- if (this.events.has(event)) {
4683
- this.events.get(event).forEach(callback => {
4684
- try {
4685
- callback(...args);
4686
- }
4687
- catch (error) {
4688
- // Silently handle errors in event handlers
4689
- console.error(`Error in event handler for ${event}:`, error);
4690
- }
4691
- });
4692
- }
5063
+ return { formErrors, fieldErrors };
5064
+ }
5065
+ function formatError(error, mapper = (issue) => issue.message) {
5066
+ const fieldErrors = { _errors: [] };
5067
+ const processError = (error) => {
5068
+ for (const issue of error.issues) {
5069
+ if (issue.code === "invalid_union" && issue.errors.length) {
5070
+ issue.errors.map((issues) => processError({ issues }));
5071
+ }
5072
+ else if (issue.code === "invalid_key") {
5073
+ processError({ issues: issue.issues });
5074
+ }
5075
+ else if (issue.code === "invalid_element") {
5076
+ processError({ issues: issue.issues });
5077
+ }
5078
+ else if (issue.path.length === 0) {
5079
+ fieldErrors._errors.push(mapper(issue));
5080
+ }
5081
+ else {
5082
+ let curr = fieldErrors;
5083
+ let i = 0;
5084
+ while (i < issue.path.length) {
5085
+ const el = issue.path[i];
5086
+ const terminal = i === issue.path.length - 1;
5087
+ if (!terminal) {
5088
+ curr[el] = curr[el] || { _errors: [] };
5089
+ }
5090
+ else {
5091
+ curr[el] = curr[el] || { _errors: [] };
5092
+ curr[el]._errors.push(mapper(issue));
5093
+ }
5094
+ curr = curr[el];
5095
+ i++;
5096
+ }
5097
+ }
5098
+ }
5099
+ };
5100
+ processError(error);
5101
+ return fieldErrors;
5102
+ }
5103
+
5104
+ const _parse = (_Err) => (schema, value, _ctx, _params) => {
5105
+ const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
5106
+ const result = schema._zod.run({ value, issues: [] }, ctx);
5107
+ if (result instanceof Promise) {
5108
+ throw new $ZodAsyncError();
5109
+ }
5110
+ if (result.issues.length) {
5111
+ const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
5112
+ captureStackTrace(e, _params?.callee);
5113
+ throw e;
5114
+ }
5115
+ return result.value;
5116
+ };
5117
+ const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
5118
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
5119
+ let result = schema._zod.run({ value, issues: [] }, ctx);
5120
+ if (result instanceof Promise)
5121
+ result = await result;
5122
+ if (result.issues.length) {
5123
+ const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
5124
+ captureStackTrace(e, params?.callee);
5125
+ throw e;
5126
+ }
5127
+ return result.value;
5128
+ };
5129
+ const _safeParse = (_Err) => (schema, value, _ctx) => {
5130
+ const ctx = _ctx ? { ..._ctx, async: false } : { async: false };
5131
+ const result = schema._zod.run({ value, issues: [] }, ctx);
5132
+ if (result instanceof Promise) {
5133
+ throw new $ZodAsyncError();
5134
+ }
5135
+ return result.issues.length
5136
+ ? {
5137
+ success: false,
5138
+ error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
5139
+ }
5140
+ : { success: true, data: result.value };
5141
+ };
5142
+ const safeParse$1 = /* @__PURE__*/ _safeParse($ZodRealError);
5143
+ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
5144
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
5145
+ let result = schema._zod.run({ value, issues: [] }, ctx);
5146
+ if (result instanceof Promise)
5147
+ result = await result;
5148
+ return result.issues.length
5149
+ ? {
5150
+ success: false,
5151
+ error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
5152
+ }
5153
+ : { success: true, data: result.value };
5154
+ };
5155
+ const safeParseAsync$1 = /* @__PURE__*/ _safeParseAsync($ZodRealError);
5156
+ const _encode = (_Err) => (schema, value, _ctx) => {
5157
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
5158
+ return _parse(_Err)(schema, value, ctx);
5159
+ };
5160
+ const _decode = (_Err) => (schema, value, _ctx) => {
5161
+ return _parse(_Err)(schema, value, _ctx);
5162
+ };
5163
+ const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
5164
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
5165
+ return _parseAsync(_Err)(schema, value, ctx);
5166
+ };
5167
+ const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
5168
+ return _parseAsync(_Err)(schema, value, _ctx);
5169
+ };
5170
+ const _safeEncode = (_Err) => (schema, value, _ctx) => {
5171
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
5172
+ return _safeParse(_Err)(schema, value, ctx);
5173
+ };
5174
+ const _safeDecode = (_Err) => (schema, value, _ctx) => {
5175
+ return _safeParse(_Err)(schema, value, _ctx);
5176
+ };
5177
+ const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
5178
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
5179
+ return _safeParseAsync(_Err)(schema, value, ctx);
5180
+ };
5181
+ const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
5182
+ return _safeParseAsync(_Err)(schema, value, _ctx);
5183
+ };
5184
+
5185
+ const cuid = /^[cC][^\s-]{8,}$/;
5186
+ const cuid2 = /^[0-9a-z]+$/;
5187
+ const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
5188
+ const xid = /^[0-9a-vA-V]{20}$/;
5189
+ const ksuid = /^[A-Za-z0-9]{27}$/;
5190
+ const nanoid = /^[a-zA-Z0-9_-]{21}$/;
5191
+ /** ISO 8601-1 duration regex. Does not support the 8601-2 extensions like negative durations or fractional/negative components. */
5192
+ 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)?)?)$/;
5193
+ /** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
5194
+ 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})$/;
5195
+ /** Returns a regex for validating an RFC 9562/4122 UUID.
5196
+ *
5197
+ * @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
5198
+ const uuid = (version) => {
5199
+ if (!version)
5200
+ 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)$/;
5201
+ 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})$`);
5202
+ };
5203
+ /** Practical email validation */
5204
+ const email = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
5205
+ // from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
5206
+ const _emoji$1 = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
5207
+ function emoji() {
5208
+ return new RegExp(_emoji$1, "u");
5209
+ }
5210
+ 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])$/;
5211
+ 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}|:))$/;
5212
+ 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])$/;
5213
+ 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])$/;
5214
+ // https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
5215
+ const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
5216
+ const base64url = /^[A-Za-z0-9_-]*$/;
5217
+ // https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces)
5218
+ const e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
5219
+ // 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])))`;
5220
+ 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])))`;
5221
+ const date$1 = /*@__PURE__*/ new RegExp(`^${dateSource}$`);
5222
+ function timeSource(args) {
5223
+ const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
5224
+ const regex = typeof args.precision === "number"
5225
+ ? args.precision === -1
5226
+ ? `${hhmm}`
5227
+ : args.precision === 0
5228
+ ? `${hhmm}:[0-5]\\d`
5229
+ : `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}`
5230
+ : `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
5231
+ return regex;
5232
+ }
5233
+ function time$1(args) {
5234
+ return new RegExp(`^${timeSource(args)}$`);
5235
+ }
5236
+ // Adapted from https://stackoverflow.com/a/3143231
5237
+ function datetime$1(args) {
5238
+ const time = timeSource({ precision: args.precision });
5239
+ const opts = ["Z"];
5240
+ if (args.local)
5241
+ opts.push("");
5242
+ // if (args.offset) opts.push(`([+-]\\d{2}:\\d{2})`);
5243
+ if (args.offset)
5244
+ opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
5245
+ const timeRegex = `${time}(?:${opts.join("|")})`;
5246
+ return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
5247
+ }
5248
+ const string$1 = (params) => {
5249
+ const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
5250
+ return new RegExp(`^${regex}$`);
5251
+ };
5252
+ const integer = /^-?\d+$/;
5253
+ const number$1 = /^-?\d+(?:\.\d+)?/;
5254
+ // regex for string with no uppercase letters
5255
+ const lowercase = /^[^A-Z]*$/;
5256
+ // regex for string with no lowercase letters
5257
+ const uppercase = /^[^a-z]*$/;
5258
+
5259
+ // import { $ZodType } from "./schemas.js";
5260
+ const $ZodCheck = /*@__PURE__*/ $constructor("$ZodCheck", (inst, def) => {
5261
+ var _a;
5262
+ inst._zod ?? (inst._zod = {});
5263
+ inst._zod.def = def;
5264
+ (_a = inst._zod).onattach ?? (_a.onattach = []);
5265
+ });
5266
+ const numericOriginMap = {
5267
+ number: "number",
5268
+ bigint: "bigint",
5269
+ object: "date",
5270
+ };
5271
+ const $ZodCheckLessThan = /*@__PURE__*/ $constructor("$ZodCheckLessThan", (inst, def) => {
5272
+ $ZodCheck.init(inst, def);
5273
+ const origin = numericOriginMap[typeof def.value];
5274
+ inst._zod.onattach.push((inst) => {
5275
+ const bag = inst._zod.bag;
5276
+ const curr = (def.inclusive ? bag.maximum : bag.exclusiveMaximum) ?? Number.POSITIVE_INFINITY;
5277
+ if (def.value < curr) {
5278
+ if (def.inclusive)
5279
+ bag.maximum = def.value;
5280
+ else
5281
+ bag.exclusiveMaximum = def.value;
5282
+ }
5283
+ });
5284
+ inst._zod.check = (payload) => {
5285
+ if (def.inclusive ? payload.value <= def.value : payload.value < def.value) {
5286
+ return;
5287
+ }
5288
+ payload.issues.push({
5289
+ origin,
5290
+ code: "too_big",
5291
+ maximum: def.value,
5292
+ input: payload.value,
5293
+ inclusive: def.inclusive,
5294
+ inst,
5295
+ continue: !def.abort,
5296
+ });
5297
+ };
5298
+ });
5299
+ const $ZodCheckGreaterThan = /*@__PURE__*/ $constructor("$ZodCheckGreaterThan", (inst, def) => {
5300
+ $ZodCheck.init(inst, def);
5301
+ const origin = numericOriginMap[typeof def.value];
5302
+ inst._zod.onattach.push((inst) => {
5303
+ const bag = inst._zod.bag;
5304
+ const curr = (def.inclusive ? bag.minimum : bag.exclusiveMinimum) ?? Number.NEGATIVE_INFINITY;
5305
+ if (def.value > curr) {
5306
+ if (def.inclusive)
5307
+ bag.minimum = def.value;
5308
+ else
5309
+ bag.exclusiveMinimum = def.value;
5310
+ }
5311
+ });
5312
+ inst._zod.check = (payload) => {
5313
+ if (def.inclusive ? payload.value >= def.value : payload.value > def.value) {
5314
+ return;
5315
+ }
5316
+ payload.issues.push({
5317
+ origin,
5318
+ code: "too_small",
5319
+ minimum: def.value,
5320
+ input: payload.value,
5321
+ inclusive: def.inclusive,
5322
+ inst,
5323
+ continue: !def.abort,
5324
+ });
5325
+ };
5326
+ });
5327
+ const $ZodCheckMultipleOf =
5328
+ /*@__PURE__*/ $constructor("$ZodCheckMultipleOf", (inst, def) => {
5329
+ $ZodCheck.init(inst, def);
5330
+ inst._zod.onattach.push((inst) => {
5331
+ var _a;
5332
+ (_a = inst._zod.bag).multipleOf ?? (_a.multipleOf = def.value);
5333
+ });
5334
+ inst._zod.check = (payload) => {
5335
+ if (typeof payload.value !== typeof def.value)
5336
+ throw new Error("Cannot mix number and bigint in multiple_of check.");
5337
+ const isMultiple = typeof payload.value === "bigint"
5338
+ ? payload.value % def.value === BigInt(0)
5339
+ : floatSafeRemainder(payload.value, def.value) === 0;
5340
+ if (isMultiple)
5341
+ return;
5342
+ payload.issues.push({
5343
+ origin: typeof payload.value,
5344
+ code: "not_multiple_of",
5345
+ divisor: def.value,
5346
+ input: payload.value,
5347
+ inst,
5348
+ continue: !def.abort,
5349
+ });
5350
+ };
5351
+ });
5352
+ const $ZodCheckNumberFormat = /*@__PURE__*/ $constructor("$ZodCheckNumberFormat", (inst, def) => {
5353
+ $ZodCheck.init(inst, def); // no format checks
5354
+ def.format = def.format || "float64";
5355
+ const isInt = def.format?.includes("int");
5356
+ const origin = isInt ? "int" : "number";
5357
+ const [minimum, maximum] = NUMBER_FORMAT_RANGES[def.format];
5358
+ inst._zod.onattach.push((inst) => {
5359
+ const bag = inst._zod.bag;
5360
+ bag.format = def.format;
5361
+ bag.minimum = minimum;
5362
+ bag.maximum = maximum;
5363
+ if (isInt)
5364
+ bag.pattern = integer;
5365
+ });
5366
+ inst._zod.check = (payload) => {
5367
+ const input = payload.value;
5368
+ if (isInt) {
5369
+ if (!Number.isInteger(input)) {
5370
+ // invalid_format issue
5371
+ // payload.issues.push({
5372
+ // expected: def.format,
5373
+ // format: def.format,
5374
+ // code: "invalid_format",
5375
+ // input,
5376
+ // inst,
5377
+ // });
5378
+ // invalid_type issue
5379
+ payload.issues.push({
5380
+ expected: origin,
5381
+ format: def.format,
5382
+ code: "invalid_type",
5383
+ continue: false,
5384
+ input,
5385
+ inst,
5386
+ });
5387
+ return;
5388
+ // not_multiple_of issue
5389
+ // payload.issues.push({
5390
+ // code: "not_multiple_of",
5391
+ // origin: "number",
5392
+ // input,
5393
+ // inst,
5394
+ // divisor: 1,
5395
+ // });
5396
+ }
5397
+ if (!Number.isSafeInteger(input)) {
5398
+ if (input > 0) {
5399
+ // too_big
5400
+ payload.issues.push({
5401
+ input,
5402
+ code: "too_big",
5403
+ maximum: Number.MAX_SAFE_INTEGER,
5404
+ note: "Integers must be within the safe integer range.",
5405
+ inst,
5406
+ origin,
5407
+ continue: !def.abort,
5408
+ });
5409
+ }
5410
+ else {
5411
+ // too_small
5412
+ payload.issues.push({
5413
+ input,
5414
+ code: "too_small",
5415
+ minimum: Number.MIN_SAFE_INTEGER,
5416
+ note: "Integers must be within the safe integer range.",
5417
+ inst,
5418
+ origin,
5419
+ continue: !def.abort,
5420
+ });
5421
+ }
5422
+ return;
5423
+ }
5424
+ }
5425
+ if (input < minimum) {
5426
+ payload.issues.push({
5427
+ origin: "number",
5428
+ input,
5429
+ code: "too_small",
5430
+ minimum,
5431
+ inclusive: true,
5432
+ inst,
5433
+ continue: !def.abort,
5434
+ });
5435
+ }
5436
+ if (input > maximum) {
5437
+ payload.issues.push({
5438
+ origin: "number",
5439
+ input,
5440
+ code: "too_big",
5441
+ maximum,
5442
+ inst,
5443
+ });
5444
+ }
5445
+ };
5446
+ });
5447
+ const $ZodCheckMaxLength = /*@__PURE__*/ $constructor("$ZodCheckMaxLength", (inst, def) => {
5448
+ var _a;
5449
+ $ZodCheck.init(inst, def);
5450
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
5451
+ const val = payload.value;
5452
+ return !nullish(val) && val.length !== undefined;
5453
+ });
5454
+ inst._zod.onattach.push((inst) => {
5455
+ const curr = (inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY);
5456
+ if (def.maximum < curr)
5457
+ inst._zod.bag.maximum = def.maximum;
5458
+ });
5459
+ inst._zod.check = (payload) => {
5460
+ const input = payload.value;
5461
+ const length = input.length;
5462
+ if (length <= def.maximum)
5463
+ return;
5464
+ const origin = getLengthableOrigin(input);
5465
+ payload.issues.push({
5466
+ origin,
5467
+ code: "too_big",
5468
+ maximum: def.maximum,
5469
+ inclusive: true,
5470
+ input,
5471
+ inst,
5472
+ continue: !def.abort,
5473
+ });
5474
+ };
5475
+ });
5476
+ const $ZodCheckMinLength = /*@__PURE__*/ $constructor("$ZodCheckMinLength", (inst, def) => {
5477
+ var _a;
5478
+ $ZodCheck.init(inst, def);
5479
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
5480
+ const val = payload.value;
5481
+ return !nullish(val) && val.length !== undefined;
5482
+ });
5483
+ inst._zod.onattach.push((inst) => {
5484
+ const curr = (inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY);
5485
+ if (def.minimum > curr)
5486
+ inst._zod.bag.minimum = def.minimum;
5487
+ });
5488
+ inst._zod.check = (payload) => {
5489
+ const input = payload.value;
5490
+ const length = input.length;
5491
+ if (length >= def.minimum)
5492
+ return;
5493
+ const origin = getLengthableOrigin(input);
5494
+ payload.issues.push({
5495
+ origin,
5496
+ code: "too_small",
5497
+ minimum: def.minimum,
5498
+ inclusive: true,
5499
+ input,
5500
+ inst,
5501
+ continue: !def.abort,
5502
+ });
5503
+ };
5504
+ });
5505
+ const $ZodCheckLengthEquals = /*@__PURE__*/ $constructor("$ZodCheckLengthEquals", (inst, def) => {
5506
+ var _a;
5507
+ $ZodCheck.init(inst, def);
5508
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
5509
+ const val = payload.value;
5510
+ return !nullish(val) && val.length !== undefined;
5511
+ });
5512
+ inst._zod.onattach.push((inst) => {
5513
+ const bag = inst._zod.bag;
5514
+ bag.minimum = def.length;
5515
+ bag.maximum = def.length;
5516
+ bag.length = def.length;
5517
+ });
5518
+ inst._zod.check = (payload) => {
5519
+ const input = payload.value;
5520
+ const length = input.length;
5521
+ if (length === def.length)
5522
+ return;
5523
+ const origin = getLengthableOrigin(input);
5524
+ const tooBig = length > def.length;
5525
+ payload.issues.push({
5526
+ origin,
5527
+ ...(tooBig ? { code: "too_big", maximum: def.length } : { code: "too_small", minimum: def.length }),
5528
+ inclusive: true,
5529
+ exact: true,
5530
+ input: payload.value,
5531
+ inst,
5532
+ continue: !def.abort,
5533
+ });
5534
+ };
5535
+ });
5536
+ const $ZodCheckStringFormat = /*@__PURE__*/ $constructor("$ZodCheckStringFormat", (inst, def) => {
5537
+ var _a, _b;
5538
+ $ZodCheck.init(inst, def);
5539
+ inst._zod.onattach.push((inst) => {
5540
+ const bag = inst._zod.bag;
5541
+ bag.format = def.format;
5542
+ if (def.pattern) {
5543
+ bag.patterns ?? (bag.patterns = new Set());
5544
+ bag.patterns.add(def.pattern);
5545
+ }
5546
+ });
5547
+ if (def.pattern)
5548
+ (_a = inst._zod).check ?? (_a.check = (payload) => {
5549
+ def.pattern.lastIndex = 0;
5550
+ if (def.pattern.test(payload.value))
5551
+ return;
5552
+ payload.issues.push({
5553
+ origin: "string",
5554
+ code: "invalid_format",
5555
+ format: def.format,
5556
+ input: payload.value,
5557
+ ...(def.pattern ? { pattern: def.pattern.toString() } : {}),
5558
+ inst,
5559
+ continue: !def.abort,
5560
+ });
5561
+ });
5562
+ else
5563
+ (_b = inst._zod).check ?? (_b.check = () => { });
5564
+ });
5565
+ const $ZodCheckRegex = /*@__PURE__*/ $constructor("$ZodCheckRegex", (inst, def) => {
5566
+ $ZodCheckStringFormat.init(inst, def);
5567
+ inst._zod.check = (payload) => {
5568
+ def.pattern.lastIndex = 0;
5569
+ if (def.pattern.test(payload.value))
5570
+ return;
5571
+ payload.issues.push({
5572
+ origin: "string",
5573
+ code: "invalid_format",
5574
+ format: "regex",
5575
+ input: payload.value,
5576
+ pattern: def.pattern.toString(),
5577
+ inst,
5578
+ continue: !def.abort,
5579
+ });
5580
+ };
5581
+ });
5582
+ const $ZodCheckLowerCase = /*@__PURE__*/ $constructor("$ZodCheckLowerCase", (inst, def) => {
5583
+ def.pattern ?? (def.pattern = lowercase);
5584
+ $ZodCheckStringFormat.init(inst, def);
5585
+ });
5586
+ const $ZodCheckUpperCase = /*@__PURE__*/ $constructor("$ZodCheckUpperCase", (inst, def) => {
5587
+ def.pattern ?? (def.pattern = uppercase);
5588
+ $ZodCheckStringFormat.init(inst, def);
5589
+ });
5590
+ const $ZodCheckIncludes = /*@__PURE__*/ $constructor("$ZodCheckIncludes", (inst, def) => {
5591
+ $ZodCheck.init(inst, def);
5592
+ const escapedRegex = escapeRegex(def.includes);
5593
+ const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
5594
+ def.pattern = pattern;
5595
+ inst._zod.onattach.push((inst) => {
5596
+ const bag = inst._zod.bag;
5597
+ bag.patterns ?? (bag.patterns = new Set());
5598
+ bag.patterns.add(pattern);
5599
+ });
5600
+ inst._zod.check = (payload) => {
5601
+ if (payload.value.includes(def.includes, def.position))
5602
+ return;
5603
+ payload.issues.push({
5604
+ origin: "string",
5605
+ code: "invalid_format",
5606
+ format: "includes",
5607
+ includes: def.includes,
5608
+ input: payload.value,
5609
+ inst,
5610
+ continue: !def.abort,
5611
+ });
5612
+ };
5613
+ });
5614
+ const $ZodCheckStartsWith = /*@__PURE__*/ $constructor("$ZodCheckStartsWith", (inst, def) => {
5615
+ $ZodCheck.init(inst, def);
5616
+ const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
5617
+ def.pattern ?? (def.pattern = pattern);
5618
+ inst._zod.onattach.push((inst) => {
5619
+ const bag = inst._zod.bag;
5620
+ bag.patterns ?? (bag.patterns = new Set());
5621
+ bag.patterns.add(pattern);
5622
+ });
5623
+ inst._zod.check = (payload) => {
5624
+ if (payload.value.startsWith(def.prefix))
5625
+ return;
5626
+ payload.issues.push({
5627
+ origin: "string",
5628
+ code: "invalid_format",
5629
+ format: "starts_with",
5630
+ prefix: def.prefix,
5631
+ input: payload.value,
5632
+ inst,
5633
+ continue: !def.abort,
5634
+ });
5635
+ };
5636
+ });
5637
+ const $ZodCheckEndsWith = /*@__PURE__*/ $constructor("$ZodCheckEndsWith", (inst, def) => {
5638
+ $ZodCheck.init(inst, def);
5639
+ const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
5640
+ def.pattern ?? (def.pattern = pattern);
5641
+ inst._zod.onattach.push((inst) => {
5642
+ const bag = inst._zod.bag;
5643
+ bag.patterns ?? (bag.patterns = new Set());
5644
+ bag.patterns.add(pattern);
5645
+ });
5646
+ inst._zod.check = (payload) => {
5647
+ if (payload.value.endsWith(def.suffix))
5648
+ return;
5649
+ payload.issues.push({
5650
+ origin: "string",
5651
+ code: "invalid_format",
5652
+ format: "ends_with",
5653
+ suffix: def.suffix,
5654
+ input: payload.value,
5655
+ inst,
5656
+ continue: !def.abort,
5657
+ });
5658
+ };
5659
+ });
5660
+ const $ZodCheckOverwrite = /*@__PURE__*/ $constructor("$ZodCheckOverwrite", (inst, def) => {
5661
+ $ZodCheck.init(inst, def);
5662
+ inst._zod.check = (payload) => {
5663
+ payload.value = def.tx(payload.value);
5664
+ };
5665
+ });
5666
+
5667
+ const version = {
5668
+ major: 4,
5669
+ minor: 1,
5670
+ patch: 13,
5671
+ };
5672
+
5673
+ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
5674
+ var _a;
5675
+ inst ?? (inst = {});
5676
+ inst._zod.def = def; // set _def property
5677
+ inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
5678
+ inst._zod.version = version;
5679
+ const checks = [...(inst._zod.def.checks ?? [])];
5680
+ // if inst is itself a checks.$ZodCheck, run it as a check
5681
+ if (inst._zod.traits.has("$ZodCheck")) {
5682
+ checks.unshift(inst);
5683
+ }
5684
+ for (const ch of checks) {
5685
+ for (const fn of ch._zod.onattach) {
5686
+ fn(inst);
5687
+ }
5688
+ }
5689
+ if (checks.length === 0) {
5690
+ // deferred initializer
5691
+ // inst._zod.parse is not yet defined
5692
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
5693
+ inst._zod.deferred?.push(() => {
5694
+ inst._zod.run = inst._zod.parse;
5695
+ });
5696
+ }
5697
+ else {
5698
+ const runChecks = (payload, checks, ctx) => {
5699
+ let isAborted = aborted(payload);
5700
+ let asyncResult;
5701
+ for (const ch of checks) {
5702
+ if (ch._zod.def.when) {
5703
+ const shouldRun = ch._zod.def.when(payload);
5704
+ if (!shouldRun)
5705
+ continue;
5706
+ }
5707
+ else if (isAborted) {
5708
+ continue;
5709
+ }
5710
+ const currLen = payload.issues.length;
5711
+ const _ = ch._zod.check(payload);
5712
+ if (_ instanceof Promise && ctx?.async === false) {
5713
+ throw new $ZodAsyncError();
5714
+ }
5715
+ if (asyncResult || _ instanceof Promise) {
5716
+ asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
5717
+ await _;
5718
+ const nextLen = payload.issues.length;
5719
+ if (nextLen === currLen)
5720
+ return;
5721
+ if (!isAborted)
5722
+ isAborted = aborted(payload, currLen);
5723
+ });
5724
+ }
5725
+ else {
5726
+ const nextLen = payload.issues.length;
5727
+ if (nextLen === currLen)
5728
+ continue;
5729
+ if (!isAborted)
5730
+ isAborted = aborted(payload, currLen);
5731
+ }
5732
+ }
5733
+ if (asyncResult) {
5734
+ return asyncResult.then(() => {
5735
+ return payload;
5736
+ });
5737
+ }
5738
+ return payload;
5739
+ };
5740
+ // const handleChecksResult = (
5741
+ // checkResult: ParsePayload,
5742
+ // originalResult: ParsePayload,
5743
+ // ctx: ParseContextInternal
5744
+ // ): util.MaybeAsync<ParsePayload> => {
5745
+ // // if the checks mutated the value && there are no issues, re-parse the result
5746
+ // if (checkResult.value !== originalResult.value && !checkResult.issues.length)
5747
+ // return inst._zod.parse(checkResult, ctx);
5748
+ // return originalResult;
5749
+ // };
5750
+ const handleCanaryResult = (canary, payload, ctx) => {
5751
+ // abort if the canary is aborted
5752
+ if (aborted(canary)) {
5753
+ canary.aborted = true;
5754
+ return canary;
5755
+ }
5756
+ // run checks first, then
5757
+ const checkResult = runChecks(payload, checks, ctx);
5758
+ if (checkResult instanceof Promise) {
5759
+ if (ctx.async === false)
5760
+ throw new $ZodAsyncError();
5761
+ return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
5762
+ }
5763
+ return inst._zod.parse(checkResult, ctx);
5764
+ };
5765
+ inst._zod.run = (payload, ctx) => {
5766
+ if (ctx.skipChecks) {
5767
+ return inst._zod.parse(payload, ctx);
5768
+ }
5769
+ if (ctx.direction === "backward") {
5770
+ // run canary
5771
+ // initial pass (no checks)
5772
+ const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
5773
+ if (canary instanceof Promise) {
5774
+ return canary.then((canary) => {
5775
+ return handleCanaryResult(canary, payload, ctx);
5776
+ });
5777
+ }
5778
+ return handleCanaryResult(canary, payload, ctx);
5779
+ }
5780
+ // forward
5781
+ const result = inst._zod.parse(payload, ctx);
5782
+ if (result instanceof Promise) {
5783
+ if (ctx.async === false)
5784
+ throw new $ZodAsyncError();
5785
+ return result.then((result) => runChecks(result, checks, ctx));
5786
+ }
5787
+ return runChecks(result, checks, ctx);
5788
+ };
5789
+ }
5790
+ inst["~standard"] = {
5791
+ validate: (value) => {
5792
+ try {
5793
+ const r = safeParse$1(inst, value);
5794
+ return r.success ? { value: r.data } : { issues: r.error?.issues };
5795
+ }
5796
+ catch (_) {
5797
+ return safeParseAsync$1(inst, value).then((r) => (r.success ? { value: r.data } : { issues: r.error?.issues }));
5798
+ }
5799
+ },
5800
+ vendor: "zod",
5801
+ version: 1,
5802
+ };
5803
+ });
5804
+ const $ZodString = /*@__PURE__*/ $constructor("$ZodString", (inst, def) => {
5805
+ $ZodType.init(inst, def);
5806
+ inst._zod.pattern = [...(inst?._zod.bag?.patterns ?? [])].pop() ?? string$1(inst._zod.bag);
5807
+ inst._zod.parse = (payload, _) => {
5808
+ if (def.coerce)
5809
+ try {
5810
+ payload.value = String(payload.value);
5811
+ }
5812
+ catch (_) { }
5813
+ if (typeof payload.value === "string")
5814
+ return payload;
5815
+ payload.issues.push({
5816
+ expected: "string",
5817
+ code: "invalid_type",
5818
+ input: payload.value,
5819
+ inst,
5820
+ });
5821
+ return payload;
5822
+ };
5823
+ });
5824
+ const $ZodStringFormat = /*@__PURE__*/ $constructor("$ZodStringFormat", (inst, def) => {
5825
+ // check initialization must come first
5826
+ $ZodCheckStringFormat.init(inst, def);
5827
+ $ZodString.init(inst, def);
5828
+ });
5829
+ const $ZodGUID = /*@__PURE__*/ $constructor("$ZodGUID", (inst, def) => {
5830
+ def.pattern ?? (def.pattern = guid);
5831
+ $ZodStringFormat.init(inst, def);
5832
+ });
5833
+ const $ZodUUID = /*@__PURE__*/ $constructor("$ZodUUID", (inst, def) => {
5834
+ if (def.version) {
5835
+ const versionMap = {
5836
+ v1: 1,
5837
+ v2: 2,
5838
+ v3: 3,
5839
+ v4: 4,
5840
+ v5: 5,
5841
+ v6: 6,
5842
+ v7: 7,
5843
+ v8: 8,
5844
+ };
5845
+ const v = versionMap[def.version];
5846
+ if (v === undefined)
5847
+ throw new Error(`Invalid UUID version: "${def.version}"`);
5848
+ def.pattern ?? (def.pattern = uuid(v));
5849
+ }
5850
+ else
5851
+ def.pattern ?? (def.pattern = uuid());
5852
+ $ZodStringFormat.init(inst, def);
5853
+ });
5854
+ const $ZodEmail = /*@__PURE__*/ $constructor("$ZodEmail", (inst, def) => {
5855
+ def.pattern ?? (def.pattern = email);
5856
+ $ZodStringFormat.init(inst, def);
5857
+ });
5858
+ const $ZodURL = /*@__PURE__*/ $constructor("$ZodURL", (inst, def) => {
5859
+ $ZodStringFormat.init(inst, def);
5860
+ inst._zod.check = (payload) => {
5861
+ try {
5862
+ // Trim whitespace from input
5863
+ const trimmed = payload.value.trim();
5864
+ // @ts-ignore
5865
+ const url = new URL(trimmed);
5866
+ if (def.hostname) {
5867
+ def.hostname.lastIndex = 0;
5868
+ if (!def.hostname.test(url.hostname)) {
5869
+ payload.issues.push({
5870
+ code: "invalid_format",
5871
+ format: "url",
5872
+ note: "Invalid hostname",
5873
+ pattern: def.hostname.source,
5874
+ input: payload.value,
5875
+ inst,
5876
+ continue: !def.abort,
5877
+ });
5878
+ }
5879
+ }
5880
+ if (def.protocol) {
5881
+ def.protocol.lastIndex = 0;
5882
+ if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) {
5883
+ payload.issues.push({
5884
+ code: "invalid_format",
5885
+ format: "url",
5886
+ note: "Invalid protocol",
5887
+ pattern: def.protocol.source,
5888
+ input: payload.value,
5889
+ inst,
5890
+ continue: !def.abort,
5891
+ });
5892
+ }
5893
+ }
5894
+ // Set the output value based on normalize flag
5895
+ if (def.normalize) {
5896
+ // Use normalized URL
5897
+ payload.value = url.href;
5898
+ }
5899
+ else {
5900
+ // Preserve the original input (trimmed)
5901
+ payload.value = trimmed;
5902
+ }
5903
+ return;
5904
+ }
5905
+ catch (_) {
5906
+ payload.issues.push({
5907
+ code: "invalid_format",
5908
+ format: "url",
5909
+ input: payload.value,
5910
+ inst,
5911
+ continue: !def.abort,
5912
+ });
5913
+ }
5914
+ };
5915
+ });
5916
+ const $ZodEmoji = /*@__PURE__*/ $constructor("$ZodEmoji", (inst, def) => {
5917
+ def.pattern ?? (def.pattern = emoji());
5918
+ $ZodStringFormat.init(inst, def);
5919
+ });
5920
+ const $ZodNanoID = /*@__PURE__*/ $constructor("$ZodNanoID", (inst, def) => {
5921
+ def.pattern ?? (def.pattern = nanoid);
5922
+ $ZodStringFormat.init(inst, def);
5923
+ });
5924
+ const $ZodCUID = /*@__PURE__*/ $constructor("$ZodCUID", (inst, def) => {
5925
+ def.pattern ?? (def.pattern = cuid);
5926
+ $ZodStringFormat.init(inst, def);
5927
+ });
5928
+ const $ZodCUID2 = /*@__PURE__*/ $constructor("$ZodCUID2", (inst, def) => {
5929
+ def.pattern ?? (def.pattern = cuid2);
5930
+ $ZodStringFormat.init(inst, def);
5931
+ });
5932
+ const $ZodULID = /*@__PURE__*/ $constructor("$ZodULID", (inst, def) => {
5933
+ def.pattern ?? (def.pattern = ulid);
5934
+ $ZodStringFormat.init(inst, def);
5935
+ });
5936
+ const $ZodXID = /*@__PURE__*/ $constructor("$ZodXID", (inst, def) => {
5937
+ def.pattern ?? (def.pattern = xid);
5938
+ $ZodStringFormat.init(inst, def);
5939
+ });
5940
+ const $ZodKSUID = /*@__PURE__*/ $constructor("$ZodKSUID", (inst, def) => {
5941
+ def.pattern ?? (def.pattern = ksuid);
5942
+ $ZodStringFormat.init(inst, def);
5943
+ });
5944
+ const $ZodISODateTime = /*@__PURE__*/ $constructor("$ZodISODateTime", (inst, def) => {
5945
+ def.pattern ?? (def.pattern = datetime$1(def));
5946
+ $ZodStringFormat.init(inst, def);
5947
+ });
5948
+ const $ZodISODate = /*@__PURE__*/ $constructor("$ZodISODate", (inst, def) => {
5949
+ def.pattern ?? (def.pattern = date$1);
5950
+ $ZodStringFormat.init(inst, def);
5951
+ });
5952
+ const $ZodISOTime = /*@__PURE__*/ $constructor("$ZodISOTime", (inst, def) => {
5953
+ def.pattern ?? (def.pattern = time$1(def));
5954
+ $ZodStringFormat.init(inst, def);
5955
+ });
5956
+ const $ZodISODuration = /*@__PURE__*/ $constructor("$ZodISODuration", (inst, def) => {
5957
+ def.pattern ?? (def.pattern = duration$1);
5958
+ $ZodStringFormat.init(inst, def);
5959
+ });
5960
+ const $ZodIPv4 = /*@__PURE__*/ $constructor("$ZodIPv4", (inst, def) => {
5961
+ def.pattern ?? (def.pattern = ipv4);
5962
+ $ZodStringFormat.init(inst, def);
5963
+ inst._zod.bag.format = `ipv4`;
5964
+ });
5965
+ const $ZodIPv6 = /*@__PURE__*/ $constructor("$ZodIPv6", (inst, def) => {
5966
+ def.pattern ?? (def.pattern = ipv6);
5967
+ $ZodStringFormat.init(inst, def);
5968
+ inst._zod.bag.format = `ipv6`;
5969
+ inst._zod.check = (payload) => {
5970
+ try {
5971
+ // @ts-ignore
5972
+ new URL(`http://[${payload.value}]`);
5973
+ // return;
5974
+ }
5975
+ catch {
5976
+ payload.issues.push({
5977
+ code: "invalid_format",
5978
+ format: "ipv6",
5979
+ input: payload.value,
5980
+ inst,
5981
+ continue: !def.abort,
5982
+ });
5983
+ }
5984
+ };
5985
+ });
5986
+ const $ZodCIDRv4 = /*@__PURE__*/ $constructor("$ZodCIDRv4", (inst, def) => {
5987
+ def.pattern ?? (def.pattern = cidrv4);
5988
+ $ZodStringFormat.init(inst, def);
5989
+ });
5990
+ const $ZodCIDRv6 = /*@__PURE__*/ $constructor("$ZodCIDRv6", (inst, def) => {
5991
+ def.pattern ?? (def.pattern = cidrv6); // not used for validation
5992
+ $ZodStringFormat.init(inst, def);
5993
+ inst._zod.check = (payload) => {
5994
+ const parts = payload.value.split("/");
5995
+ try {
5996
+ if (parts.length !== 2)
5997
+ throw new Error();
5998
+ const [address, prefix] = parts;
5999
+ if (!prefix)
6000
+ throw new Error();
6001
+ const prefixNum = Number(prefix);
6002
+ if (`${prefixNum}` !== prefix)
6003
+ throw new Error();
6004
+ if (prefixNum < 0 || prefixNum > 128)
6005
+ throw new Error();
6006
+ // @ts-ignore
6007
+ new URL(`http://[${address}]`);
6008
+ }
6009
+ catch {
6010
+ payload.issues.push({
6011
+ code: "invalid_format",
6012
+ format: "cidrv6",
6013
+ input: payload.value,
6014
+ inst,
6015
+ continue: !def.abort,
6016
+ });
6017
+ }
6018
+ };
6019
+ });
6020
+ ////////////////////////////// ZodBase64 //////////////////////////////
6021
+ function isValidBase64(data) {
6022
+ if (data === "")
6023
+ return true;
6024
+ if (data.length % 4 !== 0)
6025
+ return false;
6026
+ try {
6027
+ // @ts-ignore
6028
+ atob(data);
6029
+ return true;
6030
+ }
6031
+ catch {
6032
+ return false;
6033
+ }
6034
+ }
6035
+ const $ZodBase64 = /*@__PURE__*/ $constructor("$ZodBase64", (inst, def) => {
6036
+ def.pattern ?? (def.pattern = base64);
6037
+ $ZodStringFormat.init(inst, def);
6038
+ inst._zod.bag.contentEncoding = "base64";
6039
+ inst._zod.check = (payload) => {
6040
+ if (isValidBase64(payload.value))
6041
+ return;
6042
+ payload.issues.push({
6043
+ code: "invalid_format",
6044
+ format: "base64",
6045
+ input: payload.value,
6046
+ inst,
6047
+ continue: !def.abort,
6048
+ });
6049
+ };
6050
+ });
6051
+ ////////////////////////////// ZodBase64 //////////////////////////////
6052
+ function isValidBase64URL(data) {
6053
+ if (!base64url.test(data))
6054
+ return false;
6055
+ const base64 = data.replace(/[-_]/g, (c) => (c === "-" ? "+" : "/"));
6056
+ const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
6057
+ return isValidBase64(padded);
6058
+ }
6059
+ const $ZodBase64URL = /*@__PURE__*/ $constructor("$ZodBase64URL", (inst, def) => {
6060
+ def.pattern ?? (def.pattern = base64url);
6061
+ $ZodStringFormat.init(inst, def);
6062
+ inst._zod.bag.contentEncoding = "base64url";
6063
+ inst._zod.check = (payload) => {
6064
+ if (isValidBase64URL(payload.value))
6065
+ return;
6066
+ payload.issues.push({
6067
+ code: "invalid_format",
6068
+ format: "base64url",
6069
+ input: payload.value,
6070
+ inst,
6071
+ continue: !def.abort,
6072
+ });
6073
+ };
6074
+ });
6075
+ const $ZodE164 = /*@__PURE__*/ $constructor("$ZodE164", (inst, def) => {
6076
+ def.pattern ?? (def.pattern = e164);
6077
+ $ZodStringFormat.init(inst, def);
6078
+ });
6079
+ ////////////////////////////// ZodJWT //////////////////////////////
6080
+ function isValidJWT(token, algorithm = null) {
6081
+ try {
6082
+ const tokensParts = token.split(".");
6083
+ if (tokensParts.length !== 3)
6084
+ return false;
6085
+ const [header] = tokensParts;
6086
+ if (!header)
6087
+ return false;
6088
+ // @ts-ignore
6089
+ const parsedHeader = JSON.parse(atob(header));
6090
+ if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT")
6091
+ return false;
6092
+ if (!parsedHeader.alg)
6093
+ return false;
6094
+ if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm))
6095
+ return false;
6096
+ return true;
6097
+ }
6098
+ catch {
6099
+ return false;
6100
+ }
6101
+ }
6102
+ const $ZodJWT = /*@__PURE__*/ $constructor("$ZodJWT", (inst, def) => {
6103
+ $ZodStringFormat.init(inst, def);
6104
+ inst._zod.check = (payload) => {
6105
+ if (isValidJWT(payload.value, def.alg))
6106
+ return;
6107
+ payload.issues.push({
6108
+ code: "invalid_format",
6109
+ format: "jwt",
6110
+ input: payload.value,
6111
+ inst,
6112
+ continue: !def.abort,
6113
+ });
6114
+ };
6115
+ });
6116
+ const $ZodNumber = /*@__PURE__*/ $constructor("$ZodNumber", (inst, def) => {
6117
+ $ZodType.init(inst, def);
6118
+ inst._zod.pattern = inst._zod.bag.pattern ?? number$1;
6119
+ inst._zod.parse = (payload, _ctx) => {
6120
+ if (def.coerce)
6121
+ try {
6122
+ payload.value = Number(payload.value);
6123
+ }
6124
+ catch (_) { }
6125
+ const input = payload.value;
6126
+ if (typeof input === "number" && !Number.isNaN(input) && Number.isFinite(input)) {
6127
+ return payload;
6128
+ }
6129
+ const received = typeof input === "number"
6130
+ ? Number.isNaN(input)
6131
+ ? "NaN"
6132
+ : !Number.isFinite(input)
6133
+ ? "Infinity"
6134
+ : undefined
6135
+ : undefined;
6136
+ payload.issues.push({
6137
+ expected: "number",
6138
+ code: "invalid_type",
6139
+ input,
6140
+ inst,
6141
+ ...(received ? { received } : {}),
6142
+ });
6143
+ return payload;
6144
+ };
6145
+ });
6146
+ const $ZodNumberFormat = /*@__PURE__*/ $constructor("$ZodNumberFormat", (inst, def) => {
6147
+ $ZodCheckNumberFormat.init(inst, def);
6148
+ $ZodNumber.init(inst, def); // no format checks
6149
+ });
6150
+ function handleArrayResult(result, final, index) {
6151
+ if (result.issues.length) {
6152
+ final.issues.push(...prefixIssues(index, result.issues));
6153
+ }
6154
+ final.value[index] = result.value;
6155
+ }
6156
+ const $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def) => {
6157
+ $ZodType.init(inst, def);
6158
+ inst._zod.parse = (payload, ctx) => {
6159
+ const input = payload.value;
6160
+ if (!Array.isArray(input)) {
6161
+ payload.issues.push({
6162
+ expected: "array",
6163
+ code: "invalid_type",
6164
+ input,
6165
+ inst,
6166
+ });
6167
+ return payload;
6168
+ }
6169
+ payload.value = Array(input.length);
6170
+ const proms = [];
6171
+ for (let i = 0; i < input.length; i++) {
6172
+ const item = input[i];
6173
+ const result = def.element._zod.run({
6174
+ value: item,
6175
+ issues: [],
6176
+ }, ctx);
6177
+ if (result instanceof Promise) {
6178
+ proms.push(result.then((result) => handleArrayResult(result, payload, i)));
6179
+ }
6180
+ else {
6181
+ handleArrayResult(result, payload, i);
6182
+ }
6183
+ }
6184
+ if (proms.length) {
6185
+ return Promise.all(proms).then(() => payload);
6186
+ }
6187
+ return payload; //handleArrayResultsAsync(parseResults, final);
6188
+ };
6189
+ });
6190
+ function handleUnionResults(results, final, inst, ctx) {
6191
+ for (const result of results) {
6192
+ if (result.issues.length === 0) {
6193
+ final.value = result.value;
6194
+ return final;
6195
+ }
6196
+ }
6197
+ const nonaborted = results.filter((r) => !aborted(r));
6198
+ if (nonaborted.length === 1) {
6199
+ final.value = nonaborted[0].value;
6200
+ return nonaborted[0];
6201
+ }
6202
+ final.issues.push({
6203
+ code: "invalid_union",
6204
+ input: final.value,
6205
+ inst,
6206
+ errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
6207
+ });
6208
+ return final;
6209
+ }
6210
+ const $ZodUnion = /*@__PURE__*/ $constructor("$ZodUnion", (inst, def) => {
6211
+ $ZodType.init(inst, def);
6212
+ defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : undefined);
6213
+ defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : undefined);
6214
+ defineLazy(inst._zod, "values", () => {
6215
+ if (def.options.every((o) => o._zod.values)) {
6216
+ return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
6217
+ }
6218
+ return undefined;
6219
+ });
6220
+ defineLazy(inst._zod, "pattern", () => {
6221
+ if (def.options.every((o) => o._zod.pattern)) {
6222
+ const patterns = def.options.map((o) => o._zod.pattern);
6223
+ return new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
6224
+ }
6225
+ return undefined;
6226
+ });
6227
+ const single = def.options.length === 1;
6228
+ const first = def.options[0]._zod.run;
6229
+ inst._zod.parse = (payload, ctx) => {
6230
+ if (single) {
6231
+ return first(payload, ctx);
6232
+ }
6233
+ let async = false;
6234
+ const results = [];
6235
+ for (const option of def.options) {
6236
+ const result = option._zod.run({
6237
+ value: payload.value,
6238
+ issues: [],
6239
+ }, ctx);
6240
+ if (result instanceof Promise) {
6241
+ results.push(result);
6242
+ async = true;
6243
+ }
6244
+ else {
6245
+ if (result.issues.length === 0)
6246
+ return result;
6247
+ results.push(result);
6248
+ }
6249
+ }
6250
+ if (!async)
6251
+ return handleUnionResults(results, payload, inst, ctx);
6252
+ return Promise.all(results).then((results) => {
6253
+ return handleUnionResults(results, payload, inst, ctx);
6254
+ });
6255
+ };
6256
+ });
6257
+ const $ZodIntersection = /*@__PURE__*/ $constructor("$ZodIntersection", (inst, def) => {
6258
+ $ZodType.init(inst, def);
6259
+ inst._zod.parse = (payload, ctx) => {
6260
+ const input = payload.value;
6261
+ const left = def.left._zod.run({ value: input, issues: [] }, ctx);
6262
+ const right = def.right._zod.run({ value: input, issues: [] }, ctx);
6263
+ const async = left instanceof Promise || right instanceof Promise;
6264
+ if (async) {
6265
+ return Promise.all([left, right]).then(([left, right]) => {
6266
+ return handleIntersectionResults(payload, left, right);
6267
+ });
6268
+ }
6269
+ return handleIntersectionResults(payload, left, right);
6270
+ };
6271
+ });
6272
+ function mergeValues(a, b) {
6273
+ // const aType = parse.t(a);
6274
+ // const bType = parse.t(b);
6275
+ if (a === b) {
6276
+ return { valid: true, data: a };
6277
+ }
6278
+ if (a instanceof Date && b instanceof Date && +a === +b) {
6279
+ return { valid: true, data: a };
6280
+ }
6281
+ if (isPlainObject(a) && isPlainObject(b)) {
6282
+ const bKeys = Object.keys(b);
6283
+ const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
6284
+ const newObj = { ...a, ...b };
6285
+ for (const key of sharedKeys) {
6286
+ const sharedValue = mergeValues(a[key], b[key]);
6287
+ if (!sharedValue.valid) {
6288
+ return {
6289
+ valid: false,
6290
+ mergeErrorPath: [key, ...sharedValue.mergeErrorPath],
6291
+ };
6292
+ }
6293
+ newObj[key] = sharedValue.data;
6294
+ }
6295
+ return { valid: true, data: newObj };
6296
+ }
6297
+ if (Array.isArray(a) && Array.isArray(b)) {
6298
+ if (a.length !== b.length) {
6299
+ return { valid: false, mergeErrorPath: [] };
6300
+ }
6301
+ const newArray = [];
6302
+ for (let index = 0; index < a.length; index++) {
6303
+ const itemA = a[index];
6304
+ const itemB = b[index];
6305
+ const sharedValue = mergeValues(itemA, itemB);
6306
+ if (!sharedValue.valid) {
6307
+ return {
6308
+ valid: false,
6309
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath],
6310
+ };
6311
+ }
6312
+ newArray.push(sharedValue.data);
6313
+ }
6314
+ return { valid: true, data: newArray };
6315
+ }
6316
+ return { valid: false, mergeErrorPath: [] };
6317
+ }
6318
+ function handleIntersectionResults(result, left, right) {
6319
+ if (left.issues.length) {
6320
+ result.issues.push(...left.issues);
6321
+ }
6322
+ if (right.issues.length) {
6323
+ result.issues.push(...right.issues);
6324
+ }
6325
+ if (aborted(result))
6326
+ return result;
6327
+ const merged = mergeValues(left.value, right.value);
6328
+ if (!merged.valid) {
6329
+ throw new Error(`Unmergable intersection. Error path: ` + `${JSON.stringify(merged.mergeErrorPath)}`);
6330
+ }
6331
+ result.value = merged.data;
6332
+ return result;
6333
+ }
6334
+ const $ZodTransform = /*@__PURE__*/ $constructor("$ZodTransform", (inst, def) => {
6335
+ $ZodType.init(inst, def);
6336
+ inst._zod.parse = (payload, ctx) => {
6337
+ if (ctx.direction === "backward") {
6338
+ throw new $ZodEncodeError(inst.constructor.name);
6339
+ }
6340
+ const _out = def.transform(payload.value, payload);
6341
+ if (ctx.async) {
6342
+ const output = _out instanceof Promise ? _out : Promise.resolve(_out);
6343
+ return output.then((output) => {
6344
+ payload.value = output;
6345
+ return payload;
6346
+ });
6347
+ }
6348
+ if (_out instanceof Promise) {
6349
+ throw new $ZodAsyncError();
6350
+ }
6351
+ payload.value = _out;
6352
+ return payload;
6353
+ };
6354
+ });
6355
+ function handleOptionalResult(result, input) {
6356
+ if (result.issues.length && input === undefined) {
6357
+ return { issues: [], value: undefined };
6358
+ }
6359
+ return result;
6360
+ }
6361
+ const $ZodOptional = /*@__PURE__*/ $constructor("$ZodOptional", (inst, def) => {
6362
+ $ZodType.init(inst, def);
6363
+ inst._zod.optin = "optional";
6364
+ inst._zod.optout = "optional";
6365
+ defineLazy(inst._zod, "values", () => {
6366
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, undefined]) : undefined;
6367
+ });
6368
+ defineLazy(inst._zod, "pattern", () => {
6369
+ const pattern = def.innerType._zod.pattern;
6370
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)})?$`) : undefined;
6371
+ });
6372
+ inst._zod.parse = (payload, ctx) => {
6373
+ if (def.innerType._zod.optin === "optional") {
6374
+ const result = def.innerType._zod.run(payload, ctx);
6375
+ if (result instanceof Promise)
6376
+ return result.then((r) => handleOptionalResult(r, payload.value));
6377
+ return handleOptionalResult(result, payload.value);
6378
+ }
6379
+ if (payload.value === undefined) {
6380
+ return payload;
6381
+ }
6382
+ return def.innerType._zod.run(payload, ctx);
6383
+ };
6384
+ });
6385
+ const $ZodNullable = /*@__PURE__*/ $constructor("$ZodNullable", (inst, def) => {
6386
+ $ZodType.init(inst, def);
6387
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
6388
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
6389
+ defineLazy(inst._zod, "pattern", () => {
6390
+ const pattern = def.innerType._zod.pattern;
6391
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : undefined;
6392
+ });
6393
+ defineLazy(inst._zod, "values", () => {
6394
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : undefined;
6395
+ });
6396
+ inst._zod.parse = (payload, ctx) => {
6397
+ // Forward direction (decode): allow null to pass through
6398
+ if (payload.value === null)
6399
+ return payload;
6400
+ return def.innerType._zod.run(payload, ctx);
6401
+ };
6402
+ });
6403
+ const $ZodDefault = /*@__PURE__*/ $constructor("$ZodDefault", (inst, def) => {
6404
+ $ZodType.init(inst, def);
6405
+ // inst._zod.qin = "true";
6406
+ inst._zod.optin = "optional";
6407
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
6408
+ inst._zod.parse = (payload, ctx) => {
6409
+ if (ctx.direction === "backward") {
6410
+ return def.innerType._zod.run(payload, ctx);
6411
+ }
6412
+ // Forward direction (decode): apply defaults for undefined input
6413
+ if (payload.value === undefined) {
6414
+ payload.value = def.defaultValue;
6415
+ /**
6416
+ * $ZodDefault returns the default value immediately in forward direction.
6417
+ * 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. */
6418
+ return payload;
6419
+ }
6420
+ // Forward direction: continue with default handling
6421
+ const result = def.innerType._zod.run(payload, ctx);
6422
+ if (result instanceof Promise) {
6423
+ return result.then((result) => handleDefaultResult(result, def));
6424
+ }
6425
+ return handleDefaultResult(result, def);
6426
+ };
6427
+ });
6428
+ function handleDefaultResult(payload, def) {
6429
+ if (payload.value === undefined) {
6430
+ payload.value = def.defaultValue;
6431
+ }
6432
+ return payload;
6433
+ }
6434
+ const $ZodPrefault = /*@__PURE__*/ $constructor("$ZodPrefault", (inst, def) => {
6435
+ $ZodType.init(inst, def);
6436
+ inst._zod.optin = "optional";
6437
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
6438
+ inst._zod.parse = (payload, ctx) => {
6439
+ if (ctx.direction === "backward") {
6440
+ return def.innerType._zod.run(payload, ctx);
6441
+ }
6442
+ // Forward direction (decode): apply prefault for undefined input
6443
+ if (payload.value === undefined) {
6444
+ payload.value = def.defaultValue;
6445
+ }
6446
+ return def.innerType._zod.run(payload, ctx);
6447
+ };
6448
+ });
6449
+ const $ZodNonOptional = /*@__PURE__*/ $constructor("$ZodNonOptional", (inst, def) => {
6450
+ $ZodType.init(inst, def);
6451
+ defineLazy(inst._zod, "values", () => {
6452
+ const v = def.innerType._zod.values;
6453
+ return v ? new Set([...v].filter((x) => x !== undefined)) : undefined;
6454
+ });
6455
+ inst._zod.parse = (payload, ctx) => {
6456
+ const result = def.innerType._zod.run(payload, ctx);
6457
+ if (result instanceof Promise) {
6458
+ return result.then((result) => handleNonOptionalResult(result, inst));
6459
+ }
6460
+ return handleNonOptionalResult(result, inst);
6461
+ };
6462
+ });
6463
+ function handleNonOptionalResult(payload, inst) {
6464
+ if (!payload.issues.length && payload.value === undefined) {
6465
+ payload.issues.push({
6466
+ code: "invalid_type",
6467
+ expected: "nonoptional",
6468
+ input: payload.value,
6469
+ inst,
6470
+ });
6471
+ }
6472
+ return payload;
6473
+ }
6474
+ const $ZodCatch = /*@__PURE__*/ $constructor("$ZodCatch", (inst, def) => {
6475
+ $ZodType.init(inst, def);
6476
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
6477
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
6478
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
6479
+ inst._zod.parse = (payload, ctx) => {
6480
+ if (ctx.direction === "backward") {
6481
+ return def.innerType._zod.run(payload, ctx);
6482
+ }
6483
+ // Forward direction (decode): apply catch logic
6484
+ const result = def.innerType._zod.run(payload, ctx);
6485
+ if (result instanceof Promise) {
6486
+ return result.then((result) => {
6487
+ payload.value = result.value;
6488
+ if (result.issues.length) {
6489
+ payload.value = def.catchValue({
6490
+ ...payload,
6491
+ error: {
6492
+ issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())),
6493
+ },
6494
+ input: payload.value,
6495
+ });
6496
+ payload.issues = [];
6497
+ }
6498
+ return payload;
6499
+ });
6500
+ }
6501
+ payload.value = result.value;
6502
+ if (result.issues.length) {
6503
+ payload.value = def.catchValue({
6504
+ ...payload,
6505
+ error: {
6506
+ issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())),
6507
+ },
6508
+ input: payload.value,
6509
+ });
6510
+ payload.issues = [];
6511
+ }
6512
+ return payload;
6513
+ };
6514
+ });
6515
+ const $ZodPipe = /*@__PURE__*/ $constructor("$ZodPipe", (inst, def) => {
6516
+ $ZodType.init(inst, def);
6517
+ defineLazy(inst._zod, "values", () => def.in._zod.values);
6518
+ defineLazy(inst._zod, "optin", () => def.in._zod.optin);
6519
+ defineLazy(inst._zod, "optout", () => def.out._zod.optout);
6520
+ defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
6521
+ inst._zod.parse = (payload, ctx) => {
6522
+ if (ctx.direction === "backward") {
6523
+ const right = def.out._zod.run(payload, ctx);
6524
+ if (right instanceof Promise) {
6525
+ return right.then((right) => handlePipeResult(right, def.in, ctx));
6526
+ }
6527
+ return handlePipeResult(right, def.in, ctx);
6528
+ }
6529
+ const left = def.in._zod.run(payload, ctx);
6530
+ if (left instanceof Promise) {
6531
+ return left.then((left) => handlePipeResult(left, def.out, ctx));
6532
+ }
6533
+ return handlePipeResult(left, def.out, ctx);
6534
+ };
6535
+ });
6536
+ function handlePipeResult(left, next, ctx) {
6537
+ if (left.issues.length) {
6538
+ // prevent further checks
6539
+ left.aborted = true;
6540
+ return left;
6541
+ }
6542
+ return next._zod.run({ value: left.value, issues: left.issues }, ctx);
6543
+ }
6544
+ const $ZodReadonly = /*@__PURE__*/ $constructor("$ZodReadonly", (inst, def) => {
6545
+ $ZodType.init(inst, def);
6546
+ defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
6547
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
6548
+ defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
6549
+ defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
6550
+ inst._zod.parse = (payload, ctx) => {
6551
+ if (ctx.direction === "backward") {
6552
+ return def.innerType._zod.run(payload, ctx);
6553
+ }
6554
+ const result = def.innerType._zod.run(payload, ctx);
6555
+ if (result instanceof Promise) {
6556
+ return result.then(handleReadonlyResult);
6557
+ }
6558
+ return handleReadonlyResult(result);
6559
+ };
6560
+ });
6561
+ function handleReadonlyResult(payload) {
6562
+ payload.value = Object.freeze(payload.value);
6563
+ return payload;
6564
+ }
6565
+ const $ZodCustom = /*@__PURE__*/ $constructor("$ZodCustom", (inst, def) => {
6566
+ $ZodCheck.init(inst, def);
6567
+ $ZodType.init(inst, def);
6568
+ inst._zod.parse = (payload, _) => {
6569
+ return payload;
6570
+ };
6571
+ inst._zod.check = (payload) => {
6572
+ const input = payload.value;
6573
+ const r = def.fn(input);
6574
+ if (r instanceof Promise) {
6575
+ return r.then((r) => handleRefineResult(r, payload, input, inst));
6576
+ }
6577
+ handleRefineResult(r, payload, input, inst);
6578
+ return;
6579
+ };
6580
+ });
6581
+ function handleRefineResult(result, payload, input, inst) {
6582
+ if (!result) {
6583
+ const _iss = {
6584
+ code: "custom",
6585
+ input,
6586
+ inst, // incorporates params.error into issue reporting
6587
+ path: [...(inst._zod.def.path ?? [])], // incorporates params.error into issue reporting
6588
+ continue: !inst._zod.def.abort,
6589
+ // params: inst._zod.def.params,
6590
+ };
6591
+ if (inst._zod.def.params)
6592
+ _iss.params = inst._zod.def.params;
6593
+ payload.issues.push(issue(_iss));
6594
+ }
6595
+ }
6596
+
6597
+ var _a;
6598
+ class $ZodRegistry {
6599
+ constructor() {
6600
+ this._map = new WeakMap();
6601
+ this._idmap = new Map();
6602
+ }
6603
+ add(schema, ..._meta) {
6604
+ const meta = _meta[0];
6605
+ this._map.set(schema, meta);
6606
+ if (meta && typeof meta === "object" && "id" in meta) {
6607
+ if (this._idmap.has(meta.id)) {
6608
+ throw new Error(`ID ${meta.id} already exists in the registry`);
6609
+ }
6610
+ this._idmap.set(meta.id, schema);
6611
+ }
6612
+ return this;
6613
+ }
6614
+ clear() {
6615
+ this._map = new WeakMap();
6616
+ this._idmap = new Map();
6617
+ return this;
6618
+ }
6619
+ remove(schema) {
6620
+ const meta = this._map.get(schema);
6621
+ if (meta && typeof meta === "object" && "id" in meta) {
6622
+ this._idmap.delete(meta.id);
6623
+ }
6624
+ this._map.delete(schema);
6625
+ return this;
6626
+ }
6627
+ get(schema) {
6628
+ // return this._map.get(schema) as any;
6629
+ // inherit metadata
6630
+ const p = schema._zod.parent;
6631
+ if (p) {
6632
+ const pm = { ...(this.get(p) ?? {}) };
6633
+ delete pm.id; // do not inherit id
6634
+ const f = { ...pm, ...this._map.get(schema) };
6635
+ return Object.keys(f).length ? f : undefined;
6636
+ }
6637
+ return this._map.get(schema);
6638
+ }
6639
+ has(schema) {
6640
+ return this._map.has(schema);
6641
+ }
6642
+ }
6643
+ // registries
6644
+ function registry() {
6645
+ return new $ZodRegistry();
6646
+ }
6647
+ (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
6648
+ const globalRegistry = globalThis.__zod_globalRegistry;
6649
+
6650
+ function _string(Class, params) {
6651
+ return new Class({
6652
+ type: "string",
6653
+ ...normalizeParams(params),
6654
+ });
6655
+ }
6656
+ function _email(Class, params) {
6657
+ return new Class({
6658
+ type: "string",
6659
+ format: "email",
6660
+ check: "string_format",
6661
+ abort: false,
6662
+ ...normalizeParams(params),
6663
+ });
6664
+ }
6665
+ function _guid(Class, params) {
6666
+ return new Class({
6667
+ type: "string",
6668
+ format: "guid",
6669
+ check: "string_format",
6670
+ abort: false,
6671
+ ...normalizeParams(params),
6672
+ });
6673
+ }
6674
+ function _uuid(Class, params) {
6675
+ return new Class({
6676
+ type: "string",
6677
+ format: "uuid",
6678
+ check: "string_format",
6679
+ abort: false,
6680
+ ...normalizeParams(params),
6681
+ });
6682
+ }
6683
+ function _uuidv4(Class, params) {
6684
+ return new Class({
6685
+ type: "string",
6686
+ format: "uuid",
6687
+ check: "string_format",
6688
+ abort: false,
6689
+ version: "v4",
6690
+ ...normalizeParams(params),
6691
+ });
6692
+ }
6693
+ function _uuidv6(Class, params) {
6694
+ return new Class({
6695
+ type: "string",
6696
+ format: "uuid",
6697
+ check: "string_format",
6698
+ abort: false,
6699
+ version: "v6",
6700
+ ...normalizeParams(params),
6701
+ });
6702
+ }
6703
+ function _uuidv7(Class, params) {
6704
+ return new Class({
6705
+ type: "string",
6706
+ format: "uuid",
6707
+ check: "string_format",
6708
+ abort: false,
6709
+ version: "v7",
6710
+ ...normalizeParams(params),
6711
+ });
6712
+ }
6713
+ function _url(Class, params) {
6714
+ return new Class({
6715
+ type: "string",
6716
+ format: "url",
6717
+ check: "string_format",
6718
+ abort: false,
6719
+ ...normalizeParams(params),
6720
+ });
6721
+ }
6722
+ function _emoji(Class, params) {
6723
+ return new Class({
6724
+ type: "string",
6725
+ format: "emoji",
6726
+ check: "string_format",
6727
+ abort: false,
6728
+ ...normalizeParams(params),
6729
+ });
6730
+ }
6731
+ function _nanoid(Class, params) {
6732
+ return new Class({
6733
+ type: "string",
6734
+ format: "nanoid",
6735
+ check: "string_format",
6736
+ abort: false,
6737
+ ...normalizeParams(params),
6738
+ });
6739
+ }
6740
+ function _cuid(Class, params) {
6741
+ return new Class({
6742
+ type: "string",
6743
+ format: "cuid",
6744
+ check: "string_format",
6745
+ abort: false,
6746
+ ...normalizeParams(params),
6747
+ });
6748
+ }
6749
+ function _cuid2(Class, params) {
6750
+ return new Class({
6751
+ type: "string",
6752
+ format: "cuid2",
6753
+ check: "string_format",
6754
+ abort: false,
6755
+ ...normalizeParams(params),
6756
+ });
6757
+ }
6758
+ function _ulid(Class, params) {
6759
+ return new Class({
6760
+ type: "string",
6761
+ format: "ulid",
6762
+ check: "string_format",
6763
+ abort: false,
6764
+ ...normalizeParams(params),
6765
+ });
6766
+ }
6767
+ function _xid(Class, params) {
6768
+ return new Class({
6769
+ type: "string",
6770
+ format: "xid",
6771
+ check: "string_format",
6772
+ abort: false,
6773
+ ...normalizeParams(params),
6774
+ });
6775
+ }
6776
+ function _ksuid(Class, params) {
6777
+ return new Class({
6778
+ type: "string",
6779
+ format: "ksuid",
6780
+ check: "string_format",
6781
+ abort: false,
6782
+ ...normalizeParams(params),
6783
+ });
6784
+ }
6785
+ function _ipv4(Class, params) {
6786
+ return new Class({
6787
+ type: "string",
6788
+ format: "ipv4",
6789
+ check: "string_format",
6790
+ abort: false,
6791
+ ...normalizeParams(params),
6792
+ });
6793
+ }
6794
+ function _ipv6(Class, params) {
6795
+ return new Class({
6796
+ type: "string",
6797
+ format: "ipv6",
6798
+ check: "string_format",
6799
+ abort: false,
6800
+ ...normalizeParams(params),
6801
+ });
6802
+ }
6803
+ function _cidrv4(Class, params) {
6804
+ return new Class({
6805
+ type: "string",
6806
+ format: "cidrv4",
6807
+ check: "string_format",
6808
+ abort: false,
6809
+ ...normalizeParams(params),
6810
+ });
6811
+ }
6812
+ function _cidrv6(Class, params) {
6813
+ return new Class({
6814
+ type: "string",
6815
+ format: "cidrv6",
6816
+ check: "string_format",
6817
+ abort: false,
6818
+ ...normalizeParams(params),
6819
+ });
6820
+ }
6821
+ function _base64(Class, params) {
6822
+ return new Class({
6823
+ type: "string",
6824
+ format: "base64",
6825
+ check: "string_format",
6826
+ abort: false,
6827
+ ...normalizeParams(params),
6828
+ });
6829
+ }
6830
+ function _base64url(Class, params) {
6831
+ return new Class({
6832
+ type: "string",
6833
+ format: "base64url",
6834
+ check: "string_format",
6835
+ abort: false,
6836
+ ...normalizeParams(params),
6837
+ });
6838
+ }
6839
+ function _e164(Class, params) {
6840
+ return new Class({
6841
+ type: "string",
6842
+ format: "e164",
6843
+ check: "string_format",
6844
+ abort: false,
6845
+ ...normalizeParams(params),
6846
+ });
6847
+ }
6848
+ function _jwt(Class, params) {
6849
+ return new Class({
6850
+ type: "string",
6851
+ format: "jwt",
6852
+ check: "string_format",
6853
+ abort: false,
6854
+ ...normalizeParams(params),
6855
+ });
6856
+ }
6857
+ function _isoDateTime(Class, params) {
6858
+ return new Class({
6859
+ type: "string",
6860
+ format: "datetime",
6861
+ check: "string_format",
6862
+ offset: false,
6863
+ local: false,
6864
+ precision: null,
6865
+ ...normalizeParams(params),
6866
+ });
6867
+ }
6868
+ function _isoDate(Class, params) {
6869
+ return new Class({
6870
+ type: "string",
6871
+ format: "date",
6872
+ check: "string_format",
6873
+ ...normalizeParams(params),
6874
+ });
6875
+ }
6876
+ function _isoTime(Class, params) {
6877
+ return new Class({
6878
+ type: "string",
6879
+ format: "time",
6880
+ check: "string_format",
6881
+ precision: null,
6882
+ ...normalizeParams(params),
6883
+ });
6884
+ }
6885
+ function _isoDuration(Class, params) {
6886
+ return new Class({
6887
+ type: "string",
6888
+ format: "duration",
6889
+ check: "string_format",
6890
+ ...normalizeParams(params),
6891
+ });
6892
+ }
6893
+ function _number(Class, params) {
6894
+ return new Class({
6895
+ type: "number",
6896
+ checks: [],
6897
+ ...normalizeParams(params),
6898
+ });
6899
+ }
6900
+ function _int(Class, params) {
6901
+ return new Class({
6902
+ type: "number",
6903
+ check: "number_format",
6904
+ abort: false,
6905
+ format: "safeint",
6906
+ ...normalizeParams(params),
6907
+ });
6908
+ }
6909
+ function _lt(value, params) {
6910
+ return new $ZodCheckLessThan({
6911
+ check: "less_than",
6912
+ ...normalizeParams(params),
6913
+ value,
6914
+ inclusive: false,
6915
+ });
6916
+ }
6917
+ function _lte(value, params) {
6918
+ return new $ZodCheckLessThan({
6919
+ check: "less_than",
6920
+ ...normalizeParams(params),
6921
+ value,
6922
+ inclusive: true,
6923
+ });
6924
+ }
6925
+ function _gt(value, params) {
6926
+ return new $ZodCheckGreaterThan({
6927
+ check: "greater_than",
6928
+ ...normalizeParams(params),
6929
+ value,
6930
+ inclusive: false,
6931
+ });
6932
+ }
6933
+ function _gte(value, params) {
6934
+ return new $ZodCheckGreaterThan({
6935
+ check: "greater_than",
6936
+ ...normalizeParams(params),
6937
+ value,
6938
+ inclusive: true,
6939
+ });
6940
+ }
6941
+ function _multipleOf(value, params) {
6942
+ return new $ZodCheckMultipleOf({
6943
+ check: "multiple_of",
6944
+ ...normalizeParams(params),
6945
+ value,
6946
+ });
6947
+ }
6948
+ function _maxLength(maximum, params) {
6949
+ const ch = new $ZodCheckMaxLength({
6950
+ check: "max_length",
6951
+ ...normalizeParams(params),
6952
+ maximum,
6953
+ });
6954
+ return ch;
6955
+ }
6956
+ function _minLength(minimum, params) {
6957
+ return new $ZodCheckMinLength({
6958
+ check: "min_length",
6959
+ ...normalizeParams(params),
6960
+ minimum,
6961
+ });
6962
+ }
6963
+ function _length(length, params) {
6964
+ return new $ZodCheckLengthEquals({
6965
+ check: "length_equals",
6966
+ ...normalizeParams(params),
6967
+ length,
6968
+ });
6969
+ }
6970
+ function _regex(pattern, params) {
6971
+ return new $ZodCheckRegex({
6972
+ check: "string_format",
6973
+ format: "regex",
6974
+ ...normalizeParams(params),
6975
+ pattern,
6976
+ });
6977
+ }
6978
+ function _lowercase(params) {
6979
+ return new $ZodCheckLowerCase({
6980
+ check: "string_format",
6981
+ format: "lowercase",
6982
+ ...normalizeParams(params),
6983
+ });
6984
+ }
6985
+ function _uppercase(params) {
6986
+ return new $ZodCheckUpperCase({
6987
+ check: "string_format",
6988
+ format: "uppercase",
6989
+ ...normalizeParams(params),
6990
+ });
6991
+ }
6992
+ function _includes(includes, params) {
6993
+ return new $ZodCheckIncludes({
6994
+ check: "string_format",
6995
+ format: "includes",
6996
+ ...normalizeParams(params),
6997
+ includes,
6998
+ });
6999
+ }
7000
+ function _startsWith(prefix, params) {
7001
+ return new $ZodCheckStartsWith({
7002
+ check: "string_format",
7003
+ format: "starts_with",
7004
+ ...normalizeParams(params),
7005
+ prefix,
7006
+ });
7007
+ }
7008
+ function _endsWith(suffix, params) {
7009
+ return new $ZodCheckEndsWith({
7010
+ check: "string_format",
7011
+ format: "ends_with",
7012
+ ...normalizeParams(params),
7013
+ suffix,
7014
+ });
7015
+ }
7016
+ function _overwrite(tx) {
7017
+ return new $ZodCheckOverwrite({
7018
+ check: "overwrite",
7019
+ tx,
7020
+ });
7021
+ }
7022
+ // normalize
7023
+ function _normalize(form) {
7024
+ return _overwrite((input) => input.normalize(form));
7025
+ }
7026
+ // trim
7027
+ function _trim() {
7028
+ return _overwrite((input) => input.trim());
7029
+ }
7030
+ // toLowerCase
7031
+ function _toLowerCase() {
7032
+ return _overwrite((input) => input.toLowerCase());
7033
+ }
7034
+ // toUpperCase
7035
+ function _toUpperCase() {
7036
+ return _overwrite((input) => input.toUpperCase());
7037
+ }
7038
+ // slugify
7039
+ function _slugify() {
7040
+ return _overwrite((input) => slugify(input));
7041
+ }
7042
+ function _array(Class, element, params) {
7043
+ return new Class({
7044
+ type: "array",
7045
+ element,
7046
+ // get element() {
7047
+ // return element;
7048
+ // },
7049
+ ...normalizeParams(params),
7050
+ });
7051
+ }
7052
+ // same as _custom but defaults to abort:false
7053
+ function _refine(Class, fn, _params) {
7054
+ const schema = new Class({
7055
+ type: "custom",
7056
+ check: "custom",
7057
+ fn: fn,
7058
+ ...normalizeParams(_params),
7059
+ });
7060
+ return schema;
7061
+ }
7062
+ function _superRefine(fn) {
7063
+ const ch = _check((payload) => {
7064
+ payload.addIssue = (issue$1) => {
7065
+ if (typeof issue$1 === "string") {
7066
+ payload.issues.push(issue(issue$1, payload.value, ch._zod.def));
7067
+ }
7068
+ else {
7069
+ // for Zod 3 backwards compatibility
7070
+ const _issue = issue$1;
7071
+ if (_issue.fatal)
7072
+ _issue.continue = false;
7073
+ _issue.code ?? (_issue.code = "custom");
7074
+ _issue.input ?? (_issue.input = payload.value);
7075
+ _issue.inst ?? (_issue.inst = ch);
7076
+ _issue.continue ?? (_issue.continue = !ch._zod.def.abort); // abort is always undefined, so this is always true...
7077
+ payload.issues.push(issue(_issue));
7078
+ }
7079
+ };
7080
+ return fn(payload.value, payload);
7081
+ });
7082
+ return ch;
7083
+ }
7084
+ function _check(fn, params) {
7085
+ const ch = new $ZodCheck({
7086
+ check: "custom",
7087
+ ...normalizeParams(params),
7088
+ });
7089
+ ch._zod.check = fn;
7090
+ return ch;
7091
+ }
7092
+
7093
+ const ZodISODateTime = /*@__PURE__*/ $constructor("ZodISODateTime", (inst, def) => {
7094
+ $ZodISODateTime.init(inst, def);
7095
+ ZodStringFormat.init(inst, def);
7096
+ });
7097
+ function datetime(params) {
7098
+ return _isoDateTime(ZodISODateTime, params);
7099
+ }
7100
+ const ZodISODate = /*@__PURE__*/ $constructor("ZodISODate", (inst, def) => {
7101
+ $ZodISODate.init(inst, def);
7102
+ ZodStringFormat.init(inst, def);
7103
+ });
7104
+ function date(params) {
7105
+ return _isoDate(ZodISODate, params);
7106
+ }
7107
+ const ZodISOTime = /*@__PURE__*/ $constructor("ZodISOTime", (inst, def) => {
7108
+ $ZodISOTime.init(inst, def);
7109
+ ZodStringFormat.init(inst, def);
7110
+ });
7111
+ function time(params) {
7112
+ return _isoTime(ZodISOTime, params);
7113
+ }
7114
+ const ZodISODuration = /*@__PURE__*/ $constructor("ZodISODuration", (inst, def) => {
7115
+ $ZodISODuration.init(inst, def);
7116
+ ZodStringFormat.init(inst, def);
7117
+ });
7118
+ function duration(params) {
7119
+ return _isoDuration(ZodISODuration, params);
7120
+ }
7121
+
7122
+ const initializer = (inst, issues) => {
7123
+ $ZodError.init(inst, issues);
7124
+ inst.name = "ZodError";
7125
+ Object.defineProperties(inst, {
7126
+ format: {
7127
+ value: (mapper) => formatError(inst, mapper),
7128
+ // enumerable: false,
7129
+ },
7130
+ flatten: {
7131
+ value: (mapper) => flattenError(inst, mapper),
7132
+ // enumerable: false,
7133
+ },
7134
+ addIssue: {
7135
+ value: (issue) => {
7136
+ inst.issues.push(issue);
7137
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
7138
+ },
7139
+ // enumerable: false,
7140
+ },
7141
+ addIssues: {
7142
+ value: (issues) => {
7143
+ inst.issues.push(...issues);
7144
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
7145
+ },
7146
+ // enumerable: false,
7147
+ },
7148
+ isEmpty: {
7149
+ get() {
7150
+ return inst.issues.length === 0;
7151
+ },
7152
+ // enumerable: false,
7153
+ },
7154
+ });
7155
+ // Object.defineProperty(inst, "isEmpty", {
7156
+ // get() {
7157
+ // return inst.issues.length === 0;
7158
+ // },
7159
+ // });
7160
+ };
7161
+ const ZodError = $constructor("ZodError", initializer);
7162
+ const ZodRealError = $constructor("ZodError", initializer, {
7163
+ Parent: Error,
7164
+ });
7165
+ // /** @deprecated Use `z.core.$ZodErrorMapCtx` instead. */
7166
+ // export type ErrorMapCtx = core.$ZodErrorMapCtx;
7167
+
7168
+ const parse = /* @__PURE__ */ _parse(ZodRealError);
7169
+ const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
7170
+ const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
7171
+ const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
7172
+ // Codec functions
7173
+ const encode = /* @__PURE__ */ _encode(ZodRealError);
7174
+ const decode = /* @__PURE__ */ _decode(ZodRealError);
7175
+ const encodeAsync = /* @__PURE__ */ _encodeAsync(ZodRealError);
7176
+ const decodeAsync = /* @__PURE__ */ _decodeAsync(ZodRealError);
7177
+ const safeEncode = /* @__PURE__ */ _safeEncode(ZodRealError);
7178
+ const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
7179
+ const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
7180
+ const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
7181
+
7182
+ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
7183
+ $ZodType.init(inst, def);
7184
+ inst.def = def;
7185
+ inst.type = def.type;
7186
+ Object.defineProperty(inst, "_def", { value: def });
7187
+ // base methods
7188
+ inst.check = (...checks) => {
7189
+ return inst.clone(mergeDefs(def, {
7190
+ checks: [
7191
+ ...(def.checks ?? []),
7192
+ ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch),
7193
+ ],
7194
+ }));
7195
+ };
7196
+ inst.clone = (def, params) => clone(inst, def, params);
7197
+ inst.brand = () => inst;
7198
+ inst.register = ((reg, meta) => {
7199
+ reg.add(inst, meta);
7200
+ return inst;
7201
+ });
7202
+ // parsing
7203
+ inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
7204
+ inst.safeParse = (data, params) => safeParse(inst, data, params);
7205
+ inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
7206
+ inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
7207
+ inst.spa = inst.safeParseAsync;
7208
+ // encoding/decoding
7209
+ inst.encode = (data, params) => encode(inst, data, params);
7210
+ inst.decode = (data, params) => decode(inst, data, params);
7211
+ inst.encodeAsync = async (data, params) => encodeAsync(inst, data, params);
7212
+ inst.decodeAsync = async (data, params) => decodeAsync(inst, data, params);
7213
+ inst.safeEncode = (data, params) => safeEncode(inst, data, params);
7214
+ inst.safeDecode = (data, params) => safeDecode(inst, data, params);
7215
+ inst.safeEncodeAsync = async (data, params) => safeEncodeAsync(inst, data, params);
7216
+ inst.safeDecodeAsync = async (data, params) => safeDecodeAsync(inst, data, params);
7217
+ // refinements
7218
+ inst.refine = (check, params) => inst.check(refine(check, params));
7219
+ inst.superRefine = (refinement) => inst.check(superRefine(refinement));
7220
+ inst.overwrite = (fn) => inst.check(_overwrite(fn));
7221
+ // wrappers
7222
+ inst.optional = () => optional(inst);
7223
+ inst.nullable = () => nullable(inst);
7224
+ inst.nullish = () => optional(nullable(inst));
7225
+ inst.nonoptional = (params) => nonoptional(inst, params);
7226
+ inst.array = () => array(inst);
7227
+ inst.or = (arg) => union([inst, arg]);
7228
+ inst.and = (arg) => intersection(inst, arg);
7229
+ inst.transform = (tx) => pipe(inst, transform(tx));
7230
+ inst.default = (def) => _default(inst, def);
7231
+ inst.prefault = (def) => prefault(inst, def);
7232
+ // inst.coalesce = (def, params) => coalesce(inst, def, params);
7233
+ inst.catch = (params) => _catch(inst, params);
7234
+ inst.pipe = (target) => pipe(inst, target);
7235
+ inst.readonly = () => readonly(inst);
7236
+ // meta
7237
+ inst.describe = (description) => {
7238
+ const cl = inst.clone();
7239
+ globalRegistry.add(cl, { description });
7240
+ return cl;
7241
+ };
7242
+ Object.defineProperty(inst, "description", {
7243
+ get() {
7244
+ return globalRegistry.get(inst)?.description;
7245
+ },
7246
+ configurable: true,
7247
+ });
7248
+ inst.meta = (...args) => {
7249
+ if (args.length === 0) {
7250
+ return globalRegistry.get(inst);
7251
+ }
7252
+ const cl = inst.clone();
7253
+ globalRegistry.add(cl, args[0]);
7254
+ return cl;
7255
+ };
7256
+ // helpers
7257
+ inst.isOptional = () => inst.safeParse(undefined).success;
7258
+ inst.isNullable = () => inst.safeParse(null).success;
7259
+ return inst;
7260
+ });
7261
+ /** @internal */
7262
+ const _ZodString = /*@__PURE__*/ $constructor("_ZodString", (inst, def) => {
7263
+ $ZodString.init(inst, def);
7264
+ ZodType.init(inst, def);
7265
+ const bag = inst._zod.bag;
7266
+ inst.format = bag.format ?? null;
7267
+ inst.minLength = bag.minimum ?? null;
7268
+ inst.maxLength = bag.maximum ?? null;
7269
+ // validations
7270
+ inst.regex = (...args) => inst.check(_regex(...args));
7271
+ inst.includes = (...args) => inst.check(_includes(...args));
7272
+ inst.startsWith = (...args) => inst.check(_startsWith(...args));
7273
+ inst.endsWith = (...args) => inst.check(_endsWith(...args));
7274
+ inst.min = (...args) => inst.check(_minLength(...args));
7275
+ inst.max = (...args) => inst.check(_maxLength(...args));
7276
+ inst.length = (...args) => inst.check(_length(...args));
7277
+ inst.nonempty = (...args) => inst.check(_minLength(1, ...args));
7278
+ inst.lowercase = (params) => inst.check(_lowercase(params));
7279
+ inst.uppercase = (params) => inst.check(_uppercase(params));
7280
+ // transforms
7281
+ inst.trim = () => inst.check(_trim());
7282
+ inst.normalize = (...args) => inst.check(_normalize(...args));
7283
+ inst.toLowerCase = () => inst.check(_toLowerCase());
7284
+ inst.toUpperCase = () => inst.check(_toUpperCase());
7285
+ inst.slugify = () => inst.check(_slugify());
7286
+ });
7287
+ const ZodString = /*@__PURE__*/ $constructor("ZodString", (inst, def) => {
7288
+ $ZodString.init(inst, def);
7289
+ _ZodString.init(inst, def);
7290
+ inst.email = (params) => inst.check(_email(ZodEmail, params));
7291
+ inst.url = (params) => inst.check(_url(ZodURL, params));
7292
+ inst.jwt = (params) => inst.check(_jwt(ZodJWT, params));
7293
+ inst.emoji = (params) => inst.check(_emoji(ZodEmoji, params));
7294
+ inst.guid = (params) => inst.check(_guid(ZodGUID, params));
7295
+ inst.uuid = (params) => inst.check(_uuid(ZodUUID, params));
7296
+ inst.uuidv4 = (params) => inst.check(_uuidv4(ZodUUID, params));
7297
+ inst.uuidv6 = (params) => inst.check(_uuidv6(ZodUUID, params));
7298
+ inst.uuidv7 = (params) => inst.check(_uuidv7(ZodUUID, params));
7299
+ inst.nanoid = (params) => inst.check(_nanoid(ZodNanoID, params));
7300
+ inst.guid = (params) => inst.check(_guid(ZodGUID, params));
7301
+ inst.cuid = (params) => inst.check(_cuid(ZodCUID, params));
7302
+ inst.cuid2 = (params) => inst.check(_cuid2(ZodCUID2, params));
7303
+ inst.ulid = (params) => inst.check(_ulid(ZodULID, params));
7304
+ inst.base64 = (params) => inst.check(_base64(ZodBase64, params));
7305
+ inst.base64url = (params) => inst.check(_base64url(ZodBase64URL, params));
7306
+ inst.xid = (params) => inst.check(_xid(ZodXID, params));
7307
+ inst.ksuid = (params) => inst.check(_ksuid(ZodKSUID, params));
7308
+ inst.ipv4 = (params) => inst.check(_ipv4(ZodIPv4, params));
7309
+ inst.ipv6 = (params) => inst.check(_ipv6(ZodIPv6, params));
7310
+ inst.cidrv4 = (params) => inst.check(_cidrv4(ZodCIDRv4, params));
7311
+ inst.cidrv6 = (params) => inst.check(_cidrv6(ZodCIDRv6, params));
7312
+ inst.e164 = (params) => inst.check(_e164(ZodE164, params));
7313
+ // iso
7314
+ inst.datetime = (params) => inst.check(datetime(params));
7315
+ inst.date = (params) => inst.check(date(params));
7316
+ inst.time = (params) => inst.check(time(params));
7317
+ inst.duration = (params) => inst.check(duration(params));
7318
+ });
7319
+ function string(params) {
7320
+ return _string(ZodString, params);
7321
+ }
7322
+ const ZodStringFormat = /*@__PURE__*/ $constructor("ZodStringFormat", (inst, def) => {
7323
+ $ZodStringFormat.init(inst, def);
7324
+ _ZodString.init(inst, def);
7325
+ });
7326
+ const ZodEmail = /*@__PURE__*/ $constructor("ZodEmail", (inst, def) => {
7327
+ // ZodStringFormat.init(inst, def);
7328
+ $ZodEmail.init(inst, def);
7329
+ ZodStringFormat.init(inst, def);
7330
+ });
7331
+ const ZodGUID = /*@__PURE__*/ $constructor("ZodGUID", (inst, def) => {
7332
+ // ZodStringFormat.init(inst, def);
7333
+ $ZodGUID.init(inst, def);
7334
+ ZodStringFormat.init(inst, def);
7335
+ });
7336
+ const ZodUUID = /*@__PURE__*/ $constructor("ZodUUID", (inst, def) => {
7337
+ // ZodStringFormat.init(inst, def);
7338
+ $ZodUUID.init(inst, def);
7339
+ ZodStringFormat.init(inst, def);
7340
+ });
7341
+ const ZodURL = /*@__PURE__*/ $constructor("ZodURL", (inst, def) => {
7342
+ // ZodStringFormat.init(inst, def);
7343
+ $ZodURL.init(inst, def);
7344
+ ZodStringFormat.init(inst, def);
7345
+ });
7346
+ const ZodEmoji = /*@__PURE__*/ $constructor("ZodEmoji", (inst, def) => {
7347
+ // ZodStringFormat.init(inst, def);
7348
+ $ZodEmoji.init(inst, def);
7349
+ ZodStringFormat.init(inst, def);
7350
+ });
7351
+ const ZodNanoID = /*@__PURE__*/ $constructor("ZodNanoID", (inst, def) => {
7352
+ // ZodStringFormat.init(inst, def);
7353
+ $ZodNanoID.init(inst, def);
7354
+ ZodStringFormat.init(inst, def);
7355
+ });
7356
+ const ZodCUID = /*@__PURE__*/ $constructor("ZodCUID", (inst, def) => {
7357
+ // ZodStringFormat.init(inst, def);
7358
+ $ZodCUID.init(inst, def);
7359
+ ZodStringFormat.init(inst, def);
7360
+ });
7361
+ const ZodCUID2 = /*@__PURE__*/ $constructor("ZodCUID2", (inst, def) => {
7362
+ // ZodStringFormat.init(inst, def);
7363
+ $ZodCUID2.init(inst, def);
7364
+ ZodStringFormat.init(inst, def);
7365
+ });
7366
+ const ZodULID = /*@__PURE__*/ $constructor("ZodULID", (inst, def) => {
7367
+ // ZodStringFormat.init(inst, def);
7368
+ $ZodULID.init(inst, def);
7369
+ ZodStringFormat.init(inst, def);
7370
+ });
7371
+ const ZodXID = /*@__PURE__*/ $constructor("ZodXID", (inst, def) => {
7372
+ // ZodStringFormat.init(inst, def);
7373
+ $ZodXID.init(inst, def);
7374
+ ZodStringFormat.init(inst, def);
7375
+ });
7376
+ const ZodKSUID = /*@__PURE__*/ $constructor("ZodKSUID", (inst, def) => {
7377
+ // ZodStringFormat.init(inst, def);
7378
+ $ZodKSUID.init(inst, def);
7379
+ ZodStringFormat.init(inst, def);
7380
+ });
7381
+ const ZodIPv4 = /*@__PURE__*/ $constructor("ZodIPv4", (inst, def) => {
7382
+ // ZodStringFormat.init(inst, def);
7383
+ $ZodIPv4.init(inst, def);
7384
+ ZodStringFormat.init(inst, def);
7385
+ });
7386
+ const ZodIPv6 = /*@__PURE__*/ $constructor("ZodIPv6", (inst, def) => {
7387
+ // ZodStringFormat.init(inst, def);
7388
+ $ZodIPv6.init(inst, def);
7389
+ ZodStringFormat.init(inst, def);
7390
+ });
7391
+ const ZodCIDRv4 = /*@__PURE__*/ $constructor("ZodCIDRv4", (inst, def) => {
7392
+ $ZodCIDRv4.init(inst, def);
7393
+ ZodStringFormat.init(inst, def);
7394
+ });
7395
+ const ZodCIDRv6 = /*@__PURE__*/ $constructor("ZodCIDRv6", (inst, def) => {
7396
+ $ZodCIDRv6.init(inst, def);
7397
+ ZodStringFormat.init(inst, def);
7398
+ });
7399
+ const ZodBase64 = /*@__PURE__*/ $constructor("ZodBase64", (inst, def) => {
7400
+ // ZodStringFormat.init(inst, def);
7401
+ $ZodBase64.init(inst, def);
7402
+ ZodStringFormat.init(inst, def);
7403
+ });
7404
+ const ZodBase64URL = /*@__PURE__*/ $constructor("ZodBase64URL", (inst, def) => {
7405
+ // ZodStringFormat.init(inst, def);
7406
+ $ZodBase64URL.init(inst, def);
7407
+ ZodStringFormat.init(inst, def);
7408
+ });
7409
+ const ZodE164 = /*@__PURE__*/ $constructor("ZodE164", (inst, def) => {
7410
+ // ZodStringFormat.init(inst, def);
7411
+ $ZodE164.init(inst, def);
7412
+ ZodStringFormat.init(inst, def);
7413
+ });
7414
+ const ZodJWT = /*@__PURE__*/ $constructor("ZodJWT", (inst, def) => {
7415
+ // ZodStringFormat.init(inst, def);
7416
+ $ZodJWT.init(inst, def);
7417
+ ZodStringFormat.init(inst, def);
7418
+ });
7419
+ const ZodNumber = /*@__PURE__*/ $constructor("ZodNumber", (inst, def) => {
7420
+ $ZodNumber.init(inst, def);
7421
+ ZodType.init(inst, def);
7422
+ inst.gt = (value, params) => inst.check(_gt(value, params));
7423
+ inst.gte = (value, params) => inst.check(_gte(value, params));
7424
+ inst.min = (value, params) => inst.check(_gte(value, params));
7425
+ inst.lt = (value, params) => inst.check(_lt(value, params));
7426
+ inst.lte = (value, params) => inst.check(_lte(value, params));
7427
+ inst.max = (value, params) => inst.check(_lte(value, params));
7428
+ inst.int = (params) => inst.check(int(params));
7429
+ inst.safe = (params) => inst.check(int(params));
7430
+ inst.positive = (params) => inst.check(_gt(0, params));
7431
+ inst.nonnegative = (params) => inst.check(_gte(0, params));
7432
+ inst.negative = (params) => inst.check(_lt(0, params));
7433
+ inst.nonpositive = (params) => inst.check(_lte(0, params));
7434
+ inst.multipleOf = (value, params) => inst.check(_multipleOf(value, params));
7435
+ inst.step = (value, params) => inst.check(_multipleOf(value, params));
7436
+ // inst.finite = (params) => inst.check(core.finite(params));
7437
+ inst.finite = () => inst;
7438
+ const bag = inst._zod.bag;
7439
+ inst.minValue =
7440
+ Math.max(bag.minimum ?? Number.NEGATIVE_INFINITY, bag.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null;
7441
+ inst.maxValue =
7442
+ Math.min(bag.maximum ?? Number.POSITIVE_INFINITY, bag.exclusiveMaximum ?? Number.POSITIVE_INFINITY) ?? null;
7443
+ inst.isInt = (bag.format ?? "").includes("int") || Number.isSafeInteger(bag.multipleOf ?? 0.5);
7444
+ inst.isFinite = true;
7445
+ inst.format = bag.format ?? null;
7446
+ });
7447
+ function number(params) {
7448
+ return _number(ZodNumber, params);
7449
+ }
7450
+ const ZodNumberFormat = /*@__PURE__*/ $constructor("ZodNumberFormat", (inst, def) => {
7451
+ $ZodNumberFormat.init(inst, def);
7452
+ ZodNumber.init(inst, def);
7453
+ });
7454
+ function int(params) {
7455
+ return _int(ZodNumberFormat, params);
7456
+ }
7457
+ const ZodArray = /*@__PURE__*/ $constructor("ZodArray", (inst, def) => {
7458
+ $ZodArray.init(inst, def);
7459
+ ZodType.init(inst, def);
7460
+ inst.element = def.element;
7461
+ inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
7462
+ inst.nonempty = (params) => inst.check(_minLength(1, params));
7463
+ inst.max = (maxLength, params) => inst.check(_maxLength(maxLength, params));
7464
+ inst.length = (len, params) => inst.check(_length(len, params));
7465
+ inst.unwrap = () => inst.element;
7466
+ });
7467
+ function array(element, params) {
7468
+ return _array(ZodArray, element, params);
7469
+ }
7470
+ const ZodUnion = /*@__PURE__*/ $constructor("ZodUnion", (inst, def) => {
7471
+ $ZodUnion.init(inst, def);
7472
+ ZodType.init(inst, def);
7473
+ inst.options = def.options;
7474
+ });
7475
+ function union(options, params) {
7476
+ return new ZodUnion({
7477
+ type: "union",
7478
+ options: options,
7479
+ ...normalizeParams(params),
7480
+ });
7481
+ }
7482
+ const ZodIntersection = /*@__PURE__*/ $constructor("ZodIntersection", (inst, def) => {
7483
+ $ZodIntersection.init(inst, def);
7484
+ ZodType.init(inst, def);
7485
+ });
7486
+ function intersection(left, right) {
7487
+ return new ZodIntersection({
7488
+ type: "intersection",
7489
+ left: left,
7490
+ right: right,
7491
+ });
7492
+ }
7493
+ const ZodTransform = /*@__PURE__*/ $constructor("ZodTransform", (inst, def) => {
7494
+ $ZodTransform.init(inst, def);
7495
+ ZodType.init(inst, def);
7496
+ inst._zod.parse = (payload, _ctx) => {
7497
+ if (_ctx.direction === "backward") {
7498
+ throw new $ZodEncodeError(inst.constructor.name);
7499
+ }
7500
+ payload.addIssue = (issue$1) => {
7501
+ if (typeof issue$1 === "string") {
7502
+ payload.issues.push(issue(issue$1, payload.value, def));
7503
+ }
7504
+ else {
7505
+ // for Zod 3 backwards compatibility
7506
+ const _issue = issue$1;
7507
+ if (_issue.fatal)
7508
+ _issue.continue = false;
7509
+ _issue.code ?? (_issue.code = "custom");
7510
+ _issue.input ?? (_issue.input = payload.value);
7511
+ _issue.inst ?? (_issue.inst = inst);
7512
+ // _issue.continue ??= true;
7513
+ payload.issues.push(issue(_issue));
7514
+ }
7515
+ };
7516
+ const output = def.transform(payload.value, payload);
7517
+ if (output instanceof Promise) {
7518
+ return output.then((output) => {
7519
+ payload.value = output;
7520
+ return payload;
7521
+ });
7522
+ }
7523
+ payload.value = output;
7524
+ return payload;
7525
+ };
7526
+ });
7527
+ function transform(fn) {
7528
+ return new ZodTransform({
7529
+ type: "transform",
7530
+ transform: fn,
7531
+ });
7532
+ }
7533
+ const ZodOptional = /*@__PURE__*/ $constructor("ZodOptional", (inst, def) => {
7534
+ $ZodOptional.init(inst, def);
7535
+ ZodType.init(inst, def);
7536
+ inst.unwrap = () => inst._zod.def.innerType;
7537
+ });
7538
+ function optional(innerType) {
7539
+ return new ZodOptional({
7540
+ type: "optional",
7541
+ innerType: innerType,
7542
+ });
7543
+ }
7544
+ const ZodNullable = /*@__PURE__*/ $constructor("ZodNullable", (inst, def) => {
7545
+ $ZodNullable.init(inst, def);
7546
+ ZodType.init(inst, def);
7547
+ inst.unwrap = () => inst._zod.def.innerType;
7548
+ });
7549
+ function nullable(innerType) {
7550
+ return new ZodNullable({
7551
+ type: "nullable",
7552
+ innerType: innerType,
7553
+ });
7554
+ }
7555
+ const ZodDefault = /*@__PURE__*/ $constructor("ZodDefault", (inst, def) => {
7556
+ $ZodDefault.init(inst, def);
7557
+ ZodType.init(inst, def);
7558
+ inst.unwrap = () => inst._zod.def.innerType;
7559
+ inst.removeDefault = inst.unwrap;
7560
+ });
7561
+ function _default(innerType, defaultValue) {
7562
+ return new ZodDefault({
7563
+ type: "default",
7564
+ innerType: innerType,
7565
+ get defaultValue() {
7566
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
7567
+ },
7568
+ });
7569
+ }
7570
+ const ZodPrefault = /*@__PURE__*/ $constructor("ZodPrefault", (inst, def) => {
7571
+ $ZodPrefault.init(inst, def);
7572
+ ZodType.init(inst, def);
7573
+ inst.unwrap = () => inst._zod.def.innerType;
7574
+ });
7575
+ function prefault(innerType, defaultValue) {
7576
+ return new ZodPrefault({
7577
+ type: "prefault",
7578
+ innerType: innerType,
7579
+ get defaultValue() {
7580
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
7581
+ },
7582
+ });
7583
+ }
7584
+ const ZodNonOptional = /*@__PURE__*/ $constructor("ZodNonOptional", (inst, def) => {
7585
+ $ZodNonOptional.init(inst, def);
7586
+ ZodType.init(inst, def);
7587
+ inst.unwrap = () => inst._zod.def.innerType;
7588
+ });
7589
+ function nonoptional(innerType, params) {
7590
+ return new ZodNonOptional({
7591
+ type: "nonoptional",
7592
+ innerType: innerType,
7593
+ ...normalizeParams(params),
7594
+ });
7595
+ }
7596
+ const ZodCatch = /*@__PURE__*/ $constructor("ZodCatch", (inst, def) => {
7597
+ $ZodCatch.init(inst, def);
7598
+ ZodType.init(inst, def);
7599
+ inst.unwrap = () => inst._zod.def.innerType;
7600
+ inst.removeCatch = inst.unwrap;
7601
+ });
7602
+ function _catch(innerType, catchValue) {
7603
+ return new ZodCatch({
7604
+ type: "catch",
7605
+ innerType: innerType,
7606
+ catchValue: (typeof catchValue === "function" ? catchValue : () => catchValue),
7607
+ });
7608
+ }
7609
+ const ZodPipe = /*@__PURE__*/ $constructor("ZodPipe", (inst, def) => {
7610
+ $ZodPipe.init(inst, def);
7611
+ ZodType.init(inst, def);
7612
+ inst.in = def.in;
7613
+ inst.out = def.out;
7614
+ });
7615
+ function pipe(in_, out) {
7616
+ return new ZodPipe({
7617
+ type: "pipe",
7618
+ in: in_,
7619
+ out: out,
7620
+ // ...util.normalizeParams(params),
7621
+ });
7622
+ }
7623
+ const ZodReadonly = /*@__PURE__*/ $constructor("ZodReadonly", (inst, def) => {
7624
+ $ZodReadonly.init(inst, def);
7625
+ ZodType.init(inst, def);
7626
+ inst.unwrap = () => inst._zod.def.innerType;
7627
+ });
7628
+ function readonly(innerType) {
7629
+ return new ZodReadonly({
7630
+ type: "readonly",
7631
+ innerType: innerType,
7632
+ });
7633
+ }
7634
+ const ZodCustom = /*@__PURE__*/ $constructor("ZodCustom", (inst, def) => {
7635
+ $ZodCustom.init(inst, def);
7636
+ ZodType.init(inst, def);
7637
+ });
7638
+ function refine(fn, _params = {}) {
7639
+ return _refine(ZodCustom, fn, _params);
7640
+ }
7641
+ // superRefine
7642
+ function superRefine(fn) {
7643
+ return _superRefine(fn);
7644
+ }
7645
+
7646
+ /**
7647
+ * Input validation utility with zod package (Phase 2B).
7648
+ *
7649
+ * Generated - do not edit directly.
7650
+ */
7651
+ /**
7652
+ * Validate parameters using zod schema.
7653
+ */
7654
+ function validateParams(schema, params, config) {
7655
+ if (!config?.validationEnabled) {
7656
+ return params;
7657
+ }
7658
+ try {
7659
+ return schema.parse(params);
7660
+ }
7661
+ catch (error) {
7662
+ if (error instanceof ZodError) {
7663
+ const message = `Validation failed: ${error.issues.map((e) => `${e.path.join('.')}: ${e.message}`).join(', ')}`;
7664
+ if (config?.validationStrict) {
7665
+ throw new ValidationError(message);
7666
+ }
7667
+ else {
7668
+ console.warn(`[Validation Warning] ${message}`);
7669
+ return params;
7670
+ }
7671
+ }
7672
+ throw error;
7673
+ }
7674
+ }
7675
+ /**
7676
+ * Create a number schema with min/max constraints.
7677
+ */
7678
+ function numberSchema(min, max, defaultVal) {
7679
+ let schema = number();
7680
+ if (min !== undefined)
7681
+ schema = schema.min(min);
7682
+ if (max !== undefined)
7683
+ schema = schema.max(max);
7684
+ if (defaultVal !== undefined) {
7685
+ // Use .default() which automatically makes the field optional
7686
+ // This avoids the ZodUnion issue with .optional().default()
7687
+ schema = schema.default(defaultVal);
7688
+ }
7689
+ return schema;
7690
+ }
7691
+ /**
7692
+ * Create a string schema with length constraints.
7693
+ */
7694
+ function stringSchema(min, max, defaultVal) {
7695
+ let schema = string();
7696
+ if (min !== undefined)
7697
+ schema = schema.min(min);
7698
+ if (max !== undefined)
7699
+ schema = schema.max(max);
7700
+ if (defaultVal !== undefined) {
7701
+ // Use .default() which automatically makes the field optional
7702
+ // This avoids the ZodUnion issue with .optional().default()
7703
+ schema = schema.default(defaultVal);
7704
+ }
7705
+ return schema;
7706
+ }
7707
+
7708
+ /**
7709
+ * URL utility functions for portal URL manipulation.
7710
+ *
7711
+ * Generated - do not edit directly.
7712
+ */
7713
+ /**
7714
+ * Append theme parameters to a portal URL.
7715
+ * @param baseUrl The base portal URL (may already have query parameters)
7716
+ * @param theme The theme configuration (preset string or custom object)
7717
+ * @returns The portal URL with theme parameters appended
7718
+ */
7719
+ function appendThemeToURL(baseUrl, theme) {
7720
+ if (!theme) {
7721
+ return baseUrl;
7722
+ }
7723
+ try {
7724
+ const url = new URL(baseUrl);
7725
+ if (typeof theme === 'string') {
7726
+ // Preset theme
7727
+ url.searchParams.set('theme', theme);
7728
+ }
7729
+ else if (theme.preset) {
7730
+ // Preset theme from object
7731
+ url.searchParams.set('theme', theme.preset);
7732
+ }
7733
+ else if (theme.custom) {
7734
+ // Custom theme
7735
+ const encodedTheme = btoa(JSON.stringify(theme.custom));
7736
+ url.searchParams.set('theme', 'custom');
7737
+ url.searchParams.set('themeObject', encodedTheme);
7738
+ }
7739
+ return url.toString();
7740
+ }
7741
+ catch (error) {
7742
+ // If URL parsing fails, return original URL
7743
+ return baseUrl;
7744
+ }
7745
+ }
7746
+ /**
7747
+ * Append broker filter parameters to a portal URL.
7748
+ * @param baseUrl The base portal URL (may already have query parameters)
7749
+ * @param brokerNames Array of broker names/IDs to filter by
7750
+ * @returns The portal URL with broker filter parameters appended
7751
+ */
7752
+ function appendBrokerFilterToURL(baseUrl, brokerNames) {
7753
+ if (!brokerNames || brokerNames.length === 0) {
7754
+ return baseUrl;
7755
+ }
7756
+ try {
7757
+ const url = new URL(baseUrl);
7758
+ const encodedBrokers = btoa(JSON.stringify(brokerNames));
7759
+ url.searchParams.set('brokers', encodedBrokers);
7760
+ return url.toString();
7761
+ }
7762
+ catch (error) {
7763
+ // If URL parsing fails, return original URL
7764
+ return baseUrl;
7765
+ }
7766
+ }
7767
+
7768
+ /**
7769
+ * EventEmitter utility for Client SDK.
7770
+ *
7771
+ * Generated - do not edit directly.
7772
+ */
7773
+ class EventEmitter {
7774
+ constructor() {
7775
+ this.events = new Map();
7776
+ }
7777
+ on(event, callback) {
7778
+ if (!this.events.has(event)) {
7779
+ this.events.set(event, new Set());
7780
+ }
7781
+ this.events.get(event).add(callback);
7782
+ }
7783
+ off(event, callback) {
7784
+ if (this.events.has(event)) {
7785
+ this.events.get(event).delete(callback);
7786
+ }
7787
+ }
7788
+ once(event, callback) {
7789
+ const onceCallback = (...args) => {
7790
+ callback(...args);
7791
+ this.off(event, onceCallback);
7792
+ };
7793
+ this.on(event, onceCallback);
7794
+ }
7795
+ emit(event, ...args) {
7796
+ if (this.events.has(event)) {
7797
+ this.events.get(event).forEach(callback => {
7798
+ try {
7799
+ callback(...args);
7800
+ }
7801
+ catch (error) {
7802
+ // Silently handle errors in event handlers
7803
+ console.error(`Error in event handler for ${event}:`, error);
7804
+ }
7805
+ });
7806
+ }
4693
7807
  }
4694
7808
  removeAllListeners(event) {
4695
7809
  if (event) {
@@ -5303,54 +8417,6 @@ const SessionApiFp = function (configuration) {
5303
8417
  },
5304
8418
  };
5305
8419
  };
5306
- /**
5307
- * SessionApi - factory interface
5308
- */
5309
- const SessionApiFactory = function (configuration, basePath, axios) {
5310
- const localVarFp = SessionApiFp(configuration);
5311
- return {
5312
- /**
5313
- * Get a portal URL with token for a session. The session must be in ACTIVE or AUTHENTICATING state and the request must come from the same device that initiated the session. Device info is automatically validated from the request.
5314
- * @summary Get Portal Url
5315
- * @param {SessionApiGetPortalUrlApiV1SessionPortalGetRequest} requestParameters Request parameters.
5316
- * @param {*} [options] Override http request option.
5317
- * @throws {RequiredError}
5318
- */
5319
- getPortalUrlApiV1SessionPortalGet(requestParameters, options) {
5320
- return localVarFp.getPortalUrlApiV1SessionPortalGet(requestParameters.sessionId, options).then((request) => request(axios, basePath));
5321
- },
5322
- /**
5323
- * Get user information and fresh tokens for a completed session. This endpoint is designed for server SDKs to retrieve user information and authentication tokens after successful OTP verification. Security: - Requires valid session in ACTIVE state - Validates device fingerprint binding - Generates fresh tokens (not returning stored ones) - Only accessible to authenticated sessions with user_id - Validates that header session_id matches path session_id
5324
- * @summary Get Session User
5325
- * @param {SessionApiGetSessionUserApiV1SessionSessionIdUserGetRequest} requestParameters Request parameters.
5326
- * @param {*} [options] Override http request option.
5327
- * @throws {RequiredError}
5328
- */
5329
- getSessionUserApiV1SessionSessionIdUserGet(requestParameters, options) {
5330
- return localVarFp.getSessionUserApiV1SessionSessionIdUserGet(requestParameters.sessionId, requestParameters.xSessionId, options).then((request) => request(axios, basePath));
5331
- },
5332
- /**
5333
- * Initialize a new session with company API key.
5334
- * @summary Init Session
5335
- * @param {SessionApiInitSessionApiV1SessionInitPostRequest} requestParameters Request parameters.
5336
- * @param {*} [options] Override http request option.
5337
- * @throws {RequiredError}
5338
- */
5339
- initSessionApiV1SessionInitPost(requestParameters, options) {
5340
- return localVarFp.initSessionApiV1SessionInitPost(requestParameters.xApiKey, options).then((request) => request(axios, basePath));
5341
- },
5342
- /**
5343
- * Start a session with a one-time token.
5344
- * @summary Start Session
5345
- * @param {SessionApiStartSessionApiV1SessionStartPostRequest} requestParameters Request parameters.
5346
- * @param {*} [options] Override http request option.
5347
- * @throws {RequiredError}
5348
- */
5349
- startSessionApiV1SessionStartPost(requestParameters, options) {
5350
- return localVarFp.startSessionApiV1SessionStartPost(requestParameters.oneTimeToken, requestParameters.sessionStartRequest, options).then((request) => request(axios, basePath));
5351
- },
5352
- };
5353
- };
5354
8420
  /**
5355
8421
  * SessionApi - object-oriented interface
5356
8422
  */
@@ -6235,132 +9301,6 @@ const BrokersApiFp = function (configuration) {
6235
9301
  },
6236
9302
  };
6237
9303
  };
6238
- /**
6239
- * BrokersApi - factory interface
6240
- */
6241
- const BrokersApiFactory = function (configuration, basePath, axios) {
6242
- const localVarFp = BrokersApiFp(configuration);
6243
- return {
6244
- /**
6245
- * Remove a company\'s access to a broker connection. If the company is the only one with access, the entire connection is deleted. If other companies have access, only the company\'s access is removed.
6246
- * @summary Disconnect Company From Broker
6247
- * @param {BrokersApiDisconnectCompanyFromBrokerApiV1BrokersDisconnectCompanyConnectionIdDeleteRequest} requestParameters Request parameters.
6248
- * @param {*} [options] Override http request option.
6249
- * @throws {RequiredError}
6250
- */
6251
- disconnectCompanyFromBrokerApiV1BrokersDisconnectCompanyConnectionIdDelete(requestParameters, options) {
6252
- return localVarFp.disconnectCompanyFromBrokerApiV1BrokersDisconnectCompanyConnectionIdDelete(requestParameters.connectionId, options).then((request) => request(axios, basePath));
6253
- },
6254
- /**
6255
- * Get accounts for all authorized broker connections. This endpoint is accessible from the portal and uses session-only authentication. Returns accounts from connections the company has read access to.
6256
- * @summary Get Accounts
6257
- * @param {BrokersApiGetAccountsApiV1BrokersDataAccountsGetRequest} requestParameters Request parameters.
6258
- * @param {*} [options] Override http request option.
6259
- * @throws {RequiredError}
6260
- */
6261
- getAccountsApiV1BrokersDataAccountsGet(requestParameters = {}, options) {
6262
- return localVarFp.getAccountsApiV1BrokersDataAccountsGet(requestParameters.brokerId, requestParameters.connectionId, requestParameters.accountType, requestParameters.status, requestParameters.currency, requestParameters.limit, requestParameters.offset, requestParameters.includeMetadata, options).then((request) => request(axios, basePath));
6263
- },
6264
- /**
6265
- * Get balances for all authorized broker connections. This endpoint is accessible from the portal and uses session-only authentication. Returns balances from connections the company has read access to.
6266
- * @summary Get Balances
6267
- * @param {BrokersApiGetBalancesApiV1BrokersDataBalancesGetRequest} requestParameters Request parameters.
6268
- * @param {*} [options] Override http request option.
6269
- * @throws {RequiredError}
6270
- */
6271
- getBalancesApiV1BrokersDataBalancesGet(requestParameters = {}, options) {
6272
- return localVarFp.getBalancesApiV1BrokersDataBalancesGet(requestParameters.brokerId, requestParameters.connectionId, requestParameters.accountId, requestParameters.isEndOfDaySnapshot, requestParameters.limit, requestParameters.offset, requestParameters.balanceCreatedAfter, requestParameters.balanceCreatedBefore, requestParameters.includeMetadata, options).then((request) => request(axios, basePath));
6273
- },
6274
- /**
6275
- * Get all available brokers. This is a fast operation that returns a cached list of available brokers. The list is loaded once at startup and never changes during runtime. Returns ------- FinaticResponse[list[BrokerInfo]] list of available brokers with their metadata.
6276
- * @summary Get Brokers
6277
- * @param {*} [options] Override http request option.
6278
- * @throws {RequiredError}
6279
- */
6280
- getBrokersApiV1BrokersGet(options) {
6281
- return localVarFp.getBrokersApiV1BrokersGet(options).then((request) => request(axios, basePath));
6282
- },
6283
- /**
6284
- * Get order events for a specific order. This endpoint returns all lifecycle events for the specified order.
6285
- * @summary Get Order Events
6286
- * @param {BrokersApiGetOrderEventsApiV1BrokersDataOrdersOrderIdEventsGetRequest} requestParameters Request parameters.
6287
- * @param {*} [options] Override http request option.
6288
- * @throws {RequiredError}
6289
- */
6290
- getOrderEventsApiV1BrokersDataOrdersOrderIdEventsGet(requestParameters, options) {
6291
- return localVarFp.getOrderEventsApiV1BrokersDataOrdersOrderIdEventsGet(requestParameters.orderId, requestParameters.connectionId, requestParameters.limit, requestParameters.offset, requestParameters.includeMetadata, options).then((request) => request(axios, basePath));
6292
- },
6293
- /**
6294
- * Get order fills for a specific order. This endpoint returns all execution fills for the specified order.
6295
- * @summary Get Order Fills
6296
- * @param {BrokersApiGetOrderFillsApiV1BrokersDataOrdersOrderIdFillsGetRequest} requestParameters Request parameters.
6297
- * @param {*} [options] Override http request option.
6298
- * @throws {RequiredError}
6299
- */
6300
- getOrderFillsApiV1BrokersDataOrdersOrderIdFillsGet(requestParameters, options) {
6301
- return localVarFp.getOrderFillsApiV1BrokersDataOrdersOrderIdFillsGet(requestParameters.orderId, requestParameters.connectionId, requestParameters.limit, requestParameters.offset, requestParameters.includeMetadata, options).then((request) => request(axios, basePath));
6302
- },
6303
- /**
6304
- * Get order groups. This endpoint returns order groups that contain multiple orders.
6305
- * @summary Get Order Groups
6306
- * @param {BrokersApiGetOrderGroupsApiV1BrokersDataOrdersGroupsGetRequest} requestParameters Request parameters.
6307
- * @param {*} [options] Override http request option.
6308
- * @throws {RequiredError}
6309
- */
6310
- getOrderGroupsApiV1BrokersDataOrdersGroupsGet(requestParameters = {}, options) {
6311
- return localVarFp.getOrderGroupsApiV1BrokersDataOrdersGroupsGet(requestParameters.brokerId, requestParameters.connectionId, requestParameters.limit, requestParameters.offset, requestParameters.createdAfter, requestParameters.createdBefore, requestParameters.includeMetadata, options).then((request) => request(axios, basePath));
6312
- },
6313
- /**
6314
- * Get orders for all authorized broker connections. This endpoint is accessible from the portal and uses session-only authentication. Returns orders from connections the company has read access to.
6315
- * @summary Get Orders
6316
- * @param {BrokersApiGetOrdersApiV1BrokersDataOrdersGetRequest} requestParameters Request parameters.
6317
- * @param {*} [options] Override http request option.
6318
- * @throws {RequiredError}
6319
- */
6320
- getOrdersApiV1BrokersDataOrdersGet(requestParameters = {}, options) {
6321
- return localVarFp.getOrdersApiV1BrokersDataOrdersGet(requestParameters.brokerId, requestParameters.connectionId, requestParameters.accountId, requestParameters.symbol, requestParameters.orderStatus, requestParameters.side, requestParameters.assetType, requestParameters.limit, requestParameters.offset, requestParameters.createdAfter, requestParameters.createdBefore, requestParameters.includeMetadata, options).then((request) => request(axios, basePath));
6322
- },
6323
- /**
6324
- * Get position lot fills for a specific lot. This endpoint returns all fills associated with a specific position lot.
6325
- * @summary Get Position Lot Fills
6326
- * @param {BrokersApiGetPositionLotFillsApiV1BrokersDataPositionsLotsLotIdFillsGetRequest} requestParameters Request parameters.
6327
- * @param {*} [options] Override http request option.
6328
- * @throws {RequiredError}
6329
- */
6330
- getPositionLotFillsApiV1BrokersDataPositionsLotsLotIdFillsGet(requestParameters, options) {
6331
- return localVarFp.getPositionLotFillsApiV1BrokersDataPositionsLotsLotIdFillsGet(requestParameters.lotId, requestParameters.connectionId, requestParameters.limit, requestParameters.offset, options).then((request) => request(axios, basePath));
6332
- },
6333
- /**
6334
- * Get position lots (tax lots for positions). This endpoint returns tax lots for positions, which are used for tax reporting. Each lot tracks when a position was opened/closed and at what prices.
6335
- * @summary Get Position Lots
6336
- * @param {BrokersApiGetPositionLotsApiV1BrokersDataPositionsLotsGetRequest} requestParameters Request parameters.
6337
- * @param {*} [options] Override http request option.
6338
- * @throws {RequiredError}
6339
- */
6340
- getPositionLotsApiV1BrokersDataPositionsLotsGet(requestParameters = {}, options) {
6341
- return localVarFp.getPositionLotsApiV1BrokersDataPositionsLotsGet(requestParameters.brokerId, requestParameters.connectionId, requestParameters.accountId, requestParameters.symbol, requestParameters.positionId, requestParameters.limit, requestParameters.offset, options).then((request) => request(axios, basePath));
6342
- },
6343
- /**
6344
- * Get positions for all authorized broker connections. This endpoint is accessible from the portal and uses session-only authentication. Returns positions from connections the company has read access to.
6345
- * @summary Get Positions
6346
- * @param {BrokersApiGetPositionsApiV1BrokersDataPositionsGetRequest} requestParameters Request parameters.
6347
- * @param {*} [options] Override http request option.
6348
- * @throws {RequiredError}
6349
- */
6350
- getPositionsApiV1BrokersDataPositionsGet(requestParameters = {}, options) {
6351
- return localVarFp.getPositionsApiV1BrokersDataPositionsGet(requestParameters.brokerId, requestParameters.connectionId, requestParameters.accountId, requestParameters.symbol, requestParameters.side, requestParameters.assetType, requestParameters.positionStatus, requestParameters.limit, requestParameters.offset, requestParameters.updatedAfter, requestParameters.updatedBefore, requestParameters.includeMetadata, options).then((request) => request(axios, basePath));
6352
- },
6353
- /**
6354
- * List all broker connections for the current user with permissions. This endpoint is accessible from the portal and uses session-only authentication. Returns connections that the user has any permissions for, including the current company\'s permissions (read/write) for each connection.
6355
- * @summary List Broker Connections
6356
- * @param {*} [options] Override http request option.
6357
- * @throws {RequiredError}
6358
- */
6359
- listBrokerConnectionsApiV1BrokersConnectionsGet(options) {
6360
- return localVarFp.listBrokerConnectionsApiV1BrokersConnectionsGet(options).then((request) => request(axios, basePath));
6361
- },
6362
- };
6363
- };
6364
9304
  /**
6365
9305
  * BrokersApi - object-oriented interface
6366
9306
  */
@@ -6597,34 +9537,6 @@ const CompanyApiFp = function (configuration) {
6597
9537
  },
6598
9538
  };
6599
9539
  };
6600
- /**
6601
- * CompanyApi - factory interface
6602
- */
6603
- const CompanyApiFactory = function (configuration, basePath, axios) {
6604
- const localVarFp = CompanyApiFp(configuration);
6605
- return {
6606
- /**
6607
- * Get public company details by ID (no user check, no sensitive data).
6608
- * @summary Get Company
6609
- * @param {CompanyApiGetCompanyApiV1CompanyCompanyIdGetRequest} requestParameters Request parameters.
6610
- * @param {*} [options] Override http request option.
6611
- * @throws {RequiredError}
6612
- */
6613
- getCompanyApiV1CompanyCompanyIdGet(requestParameters, options) {
6614
- return localVarFp.getCompanyApiV1CompanyCompanyIdGet(requestParameters.companyId, options).then((request) => request(axios, basePath));
6615
- },
6616
- /**
6617
- * Get public company details by ID (no user check, no sensitive data).
6618
- * @summary Get Company
6619
- * @param {CompanyApiGetCompanyApiV1CompanyCompanyIdGet0Request} requestParameters Request parameters.
6620
- * @param {*} [options] Override http request option.
6621
- * @throws {RequiredError}
6622
- */
6623
- getCompanyApiV1CompanyCompanyIdGet_1(requestParameters, options) {
6624
- return localVarFp.getCompanyApiV1CompanyCompanyIdGet_1(requestParameters.companyId, options).then((request) => request(axios, basePath));
6625
- },
6626
- };
6627
- };
6628
9540
  /**
6629
9541
  * CompanyApi - object-oriented interface
6630
9542
  */
@@ -9105,25 +12017,13 @@ class FinaticConnect extends FinaticConnect$1 {
9105
12017
  FinaticConnect.__CUSTOM_CLASS__ = true;
9106
12018
 
9107
12019
  exports.ApiError = ApiError;
9108
- exports.BrokersApi = BrokersApi;
9109
- exports.BrokersApiAxiosParamCreator = BrokersApiAxiosParamCreator;
9110
- exports.BrokersApiFactory = BrokersApiFactory;
9111
- exports.BrokersApiFp = BrokersApiFp;
9112
12020
  exports.BrokersWrapper = BrokersWrapper;
9113
- exports.CompanyApi = CompanyApi;
9114
- exports.CompanyApiAxiosParamCreator = CompanyApiAxiosParamCreator;
9115
- exports.CompanyApiFactory = CompanyApiFactory;
9116
- exports.CompanyApiFp = CompanyApiFp;
9117
12021
  exports.CompanyWrapper = CompanyWrapper;
9118
12022
  exports.Configuration = Configuration;
9119
12023
  exports.EventEmitter = EventEmitter;
9120
12024
  exports.FinaticConnect = FinaticConnect;
9121
12025
  exports.FinaticError = FinaticError;
9122
12026
  exports.PaginatedData = PaginatedData;
9123
- exports.SessionApi = SessionApi;
9124
- exports.SessionApiAxiosParamCreator = SessionApiAxiosParamCreator;
9125
- exports.SessionApiFactory = SessionApiFactory;
9126
- exports.SessionApiFp = SessionApiFp;
9127
12027
  exports.SessionWrapper = SessionWrapper;
9128
12028
  exports.ValidationError = ValidationError;
9129
12029
  exports.addErrorInterceptor = addErrorInterceptor;