UNPKG

@getopenpay/openpay-js

Version:

Accept payments through OpenPay, right on your site

1 lines 753 kB
(function(Ye,$e){typeof exports=="object"&&typeof module<"u"?$e(exports):typeof define=="function"&&define.amd?define(["exports"],$e):(Ye=typeof globalThis<"u"?globalThis:Ye||self,$e(Ye.OpenPay={}))})(this,(function(exports){"use strict";function _mergeNamespaces(S,T){for(var A=0;A<T.length;A++){const O=T[A];if(typeof O!="string"&&!Array.isArray(O)){for(const P in O)if(P!=="default"&&!(P in S)){const R=Object.getOwnPropertyDescriptor(O,P);R&&Object.defineProperty(S,P,R.get?R:{enumerable:!0,get:()=>O[P]})}}}return Object.freeze(Object.defineProperty(S,Symbol.toStringTag,{value:"Module"}))}var MessageType;(function(S){S.Call="call",S.Reply="reply",S.Syn="syn",S.SynAck="synAck",S.Ack="ack"})(MessageType||(MessageType={}));var Resolution;(function(S){S.Fulfilled="fulfilled",S.Rejected="rejected"})(Resolution||(Resolution={}));var ErrorCode;(function(S){S.ConnectionDestroyed="ConnectionDestroyed",S.ConnectionTimeout="ConnectionTimeout",S.NoIframeSrc="NoIframeSrc"})(ErrorCode||(ErrorCode={}));var NativeErrorName;(function(S){S.DataCloneError="DataCloneError"})(NativeErrorName||(NativeErrorName={}));var NativeEventType;(function(S){S.Message="message"})(NativeEventType||(NativeEventType={}));const createDestructor=(S,T)=>{const A=[];let O=!1;return{destroy(P){O||(O=!0,T(`${S}: Destroying connection`),A.forEach(R=>{R(P)}))},onDestroy(P){O?P():A.push(P)}}},createLogger=S=>(...T)=>{S&&console.log("[Penpal]",...T)},DEFAULT_PORT_BY_PROTOCOL={"http:":"80","https:":"443"},URL_REGEX=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/,opaqueOriginSchemes=["file:","data:"],getOriginFromSrc=S=>{if(S&&opaqueOriginSchemes.find(D=>S.startsWith(D)))return"null";const T=document.location,A=URL_REGEX.exec(S);let O,P,R;A?(O=A[1]?A[1]:T.protocol,P=A[2],R=A[4]):(O=T.protocol,P=T.hostname,R=T.port);const M=R&&R!==DEFAULT_PORT_BY_PROTOCOL[O]?`:${R}`:"";return`${O}//${P}${M}`},serializeError=({name:S,message:T,stack:A})=>({name:S,message:T,stack:A}),deserializeError=S=>{const T=new Error;return Object.keys(S).forEach(A=>T[A]=S[A]),T},connectCallReceiver=(S,T,A)=>{const{localName:O,local:P,remote:R,originForSending:M,originForReceiving:D}=S;let U=!1;const C=L=>{if(L.source!==R||L.data.penpal!==MessageType.Call)return;if(D!=="*"&&L.origin!==D){A(`${O} received message from origin ${L.origin} which did not match expected origin ${D}`);return}const y=L.data,{methodName:_,args:N,id:I}=y;A(`${O}: Received ${_}() call`);const x=V=>k=>{if(A(`${O}: Sending ${_}() reply`),U){A(`${O}: Unable to send ${_}() reply due to destroyed connection`);return}const B={penpal:MessageType.Reply,id:I,resolution:V,returnValue:k};V===Resolution.Rejected&&k instanceof Error&&(B.returnValue=serializeError(k),B.returnValueIsError=!0);try{R.postMessage(B,M)}catch(W){if(W.name===NativeErrorName.DataCloneError){const oe={penpal:MessageType.Reply,id:I,resolution:Resolution.Rejected,returnValue:serializeError(W),returnValueIsError:!0};R.postMessage(oe,M)}throw W}};new Promise(V=>V(T[_].apply(T,N))).then(x(Resolution.Fulfilled),x(Resolution.Rejected))};return P.addEventListener(NativeEventType.Message,C),()=>{U=!0,P.removeEventListener(NativeEventType.Message,C)}};let id=0;const generateId=()=>++id,KEY_PATH_DELIMITER=".",keyPathToSegments=S=>S?S.split(KEY_PATH_DELIMITER):[],segmentsToKeyPath=S=>S.join(KEY_PATH_DELIMITER),createKeyPath=(S,T)=>{const A=keyPathToSegments(T||"");return A.push(S),segmentsToKeyPath(A)},setAtKeyPath=(S,T,A)=>{const O=keyPathToSegments(T);return O.reduce((P,R,M)=>(typeof P[R]>"u"&&(P[R]={}),M===O.length-1&&(P[R]=A),P[R]),S),S},serializeMethods=(S,T)=>{const A={};return Object.keys(S).forEach(O=>{const P=S[O],R=createKeyPath(O,T);typeof P=="object"&&Object.assign(A,serializeMethods(P,R)),typeof P=="function"&&(A[R]=P)}),A},deserializeMethods=S=>{const T={};for(const A in S)setAtKeyPath(T,A,S[A]);return T},connectCallSender=(S,T,A,O,P)=>{const{localName:R,local:M,remote:D,originForSending:U,originForReceiving:C}=T;let L=!1;P(`${R}: Connecting call sender`);const y=N=>(...I)=>{P(`${R}: Sending ${N}() call`);let x;try{D.closed&&(x=!0)}catch{x=!0}if(x&&O(),L){const V=new Error(`Unable to send ${N}() call due to destroyed connection`);throw V.code=ErrorCode.ConnectionDestroyed,V}return new Promise((V,k)=>{const B=generateId(),W=te=>{if(te.source!==D||te.data.penpal!==MessageType.Reply||te.data.id!==B)return;if(C!=="*"&&te.origin!==C){P(`${R} received message from origin ${te.origin} which did not match expected origin ${C}`);return}const fe=te.data;P(`${R}: Received ${N}() reply`),M.removeEventListener(NativeEventType.Message,W);let Fe=fe.returnValue;fe.returnValueIsError&&(Fe=deserializeError(Fe)),(fe.resolution===Resolution.Fulfilled?V:k)(Fe)};M.addEventListener(NativeEventType.Message,W);const oe={penpal:MessageType.Call,id:B,methodName:N,args:I};D.postMessage(oe,U)})},_=A.reduce((N,I)=>(N[I]=y(I),N),{});return Object.assign(S,deserializeMethods(_)),()=>{L=!0}},handleAckMessageFactory=(S,T,A,O,P)=>{const{destroy:R,onDestroy:M}=O;let D,U;const C={};return L=>{if(T!=="*"&&L.origin!==T){P(`Parent: Handshake - Received ACK message from origin ${L.origin} which did not match expected origin ${T}`);return}P("Parent: Handshake - Received ACK");const y={localName:"Parent",local:window,remote:L.source,originForSending:A,originForReceiving:T};D&&D(),D=connectCallReceiver(y,S,P),M(D),U&&U.forEach(N=>{delete C[N]}),U=L.data.methodNames;const _=connectCallSender(C,y,U,R,P);return M(_),C}},handleSynMessageFactory=(S,T,A,O)=>P=>{if(!P.source)return;if(A!=="*"&&P.origin!==A){S(`Parent: Handshake - Received SYN message from origin ${P.origin} which did not match expected origin ${A}`);return}S("Parent: Handshake - Received SYN, responding with SYN-ACK");const R={penpal:MessageType.SynAck,methodNames:Object.keys(T)};P.source.postMessage(R,O)},CHECK_IFRAME_IN_DOC_INTERVAL=6e4,monitorIframeRemoval=(S,T)=>{const{destroy:A,onDestroy:O}=T,P=setInterval(()=>{S.isConnected||(clearInterval(P),A())},CHECK_IFRAME_IN_DOC_INTERVAL);O(()=>{clearInterval(P)})},startConnectionTimeout=(S,T)=>{let A;return S!==void 0&&(A=window.setTimeout(()=>{const O=new Error(`Connection timed out after ${S}ms`);O.code=ErrorCode.ConnectionTimeout,T(O)},S)),()=>{clearTimeout(A)}},validateIframeHasSrcOrSrcDoc=S=>{if(!S.src&&!S.srcdoc){const T=new Error("Iframe must have src or srcdoc property defined.");throw T.code=ErrorCode.NoIframeSrc,T}},connectToChild=S=>{let{iframe:T,methods:A={},childOrigin:O,timeout:P,debug:R=!1}=S;const M=createLogger(R),D=createDestructor("Parent",M),{onDestroy:U,destroy:C}=D;O||(validateIframeHasSrcOrSrcDoc(T),O=getOriginFromSrc(T.src));const L=O==="null"?"*":O,y=serializeMethods(A),_=handleSynMessageFactory(M,y,O,L),N=handleAckMessageFactory(y,O,L,D,M);return{promise:new Promise((x,V)=>{const k=startConnectionTimeout(P,C),B=W=>{if(!(W.source!==T.contentWindow||!W.data)){if(W.data.penpal===MessageType.Syn){_(W);return}if(W.data.penpal===MessageType.Ack){const oe=N(W);oe&&(k(),x(oe));return}}};window.addEventListener(NativeEventType.Message,B),M("Parent: Awaiting handshake"),monitorIframeRemoval(T,D),U(W=>{window.removeEventListener(NativeEventType.Message,B),W&&V(W)})}),destroy(){C()}}};function fixProto(S,T){var A=Object.setPrototypeOf;A?A(S,T):S.__proto__=T}function fixStack(S,T){T===void 0&&(T=S.constructor);var A=Error.captureStackTrace;A&&A(S,T)}var __extends$9=(function(){var S=function(A,O){return S=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(P,R){P.__proto__=R}||function(P,R){for(var M in R)Object.prototype.hasOwnProperty.call(R,M)&&(P[M]=R[M])},S(A,O)};return function(T,A){if(typeof A!="function"&&A!==null)throw new TypeError("Class extends value "+String(A)+" is not a constructor or null");S(T,A);function O(){this.constructor=T}T.prototype=A===null?Object.create(A):(O.prototype=A.prototype,new O)}})(),CustomError=(function(S){__extends$9(T,S);function T(A,O){var P=this.constructor,R=S.call(this,A,O)||this;return Object.defineProperty(R,"name",{value:P.name,enumerable:!1,configurable:!0}),fixProto(R,P.prototype),fixStack(R),R}return T})(Error),util;(function(S){S.assertEqual=P=>{};function T(P){}S.assertIs=T;function A(P){throw new Error}S.assertNever=A,S.arrayToEnum=P=>{const R={};for(const M of P)R[M]=M;return R},S.getValidEnumValues=P=>{const R=S.objectKeys(P).filter(D=>typeof P[P[D]]!="number"),M={};for(const D of R)M[D]=P[D];return S.objectValues(M)},S.objectValues=P=>S.objectKeys(P).map(function(R){return P[R]}),S.objectKeys=typeof Object.keys=="function"?P=>Object.keys(P):P=>{const R=[];for(const M in P)Object.prototype.hasOwnProperty.call(P,M)&&R.push(M);return R},S.find=(P,R)=>{for(const M of P)if(R(M))return M},S.isInteger=typeof Number.isInteger=="function"?P=>Number.isInteger(P):P=>typeof P=="number"&&Number.isFinite(P)&&Math.floor(P)===P;function O(P,R=" | "){return P.map(M=>typeof M=="string"?`'${M}'`:M).join(R)}S.joinValues=O,S.jsonStringifyReplacer=(P,R)=>typeof R=="bigint"?R.toString():R})(util||(util={}));var objectUtil;(function(S){S.mergeShapes=(T,A)=>({...T,...A})})(objectUtil||(objectUtil={}));const ZodParsedType=util.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),getParsedType=S=>{switch(typeof S){case"undefined":return ZodParsedType.undefined;case"string":return ZodParsedType.string;case"number":return Number.isNaN(S)?ZodParsedType.nan:ZodParsedType.number;case"boolean":return ZodParsedType.boolean;case"function":return ZodParsedType.function;case"bigint":return ZodParsedType.bigint;case"symbol":return ZodParsedType.symbol;case"object":return Array.isArray(S)?ZodParsedType.array:S===null?ZodParsedType.null:S.then&&typeof S.then=="function"&&S.catch&&typeof S.catch=="function"?ZodParsedType.promise:typeof Map<"u"&&S instanceof Map?ZodParsedType.map:typeof Set<"u"&&S instanceof Set?ZodParsedType.set:typeof Date<"u"&&S instanceof Date?ZodParsedType.date:ZodParsedType.object;default:return ZodParsedType.unknown}},ZodIssueCode=util.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class ZodError extends Error{get errors(){return this.issues}constructor(T){super(),this.issues=[],this.addIssue=O=>{this.issues=[...this.issues,O]},this.addIssues=(O=[])=>{this.issues=[...this.issues,...O]};const A=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,A):this.__proto__=A,this.name="ZodError",this.issues=T}format(T){const A=T||function(R){return R.message},O={_errors:[]},P=R=>{for(const M of R.issues)if(M.code==="invalid_union")M.unionErrors.map(P);else if(M.code==="invalid_return_type")P(M.returnTypeError);else if(M.code==="invalid_arguments")P(M.argumentsError);else if(M.path.length===0)O._errors.push(A(M));else{let D=O,U=0;for(;U<M.path.length;){const C=M.path[U];U===M.path.length-1?(D[C]=D[C]||{_errors:[]},D[C]._errors.push(A(M))):D[C]=D[C]||{_errors:[]},D=D[C],U++}}};return P(this),O}static assert(T){if(!(T instanceof ZodError))throw new Error(`Not a ZodError: ${T}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,util.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(T=A=>A.message){const A={},O=[];for(const P of this.issues)if(P.path.length>0){const R=P.path[0];A[R]=A[R]||[],A[R].push(T(P))}else O.push(T(P));return{formErrors:O,fieldErrors:A}}get formErrors(){return this.flatten()}}ZodError.create=S=>new ZodError(S);const errorMap=(S,T)=>{let A;switch(S.code){case ZodIssueCode.invalid_type:S.received===ZodParsedType.undefined?A="Required":A=`Expected ${S.expected}, received ${S.received}`;break;case ZodIssueCode.invalid_literal:A=`Invalid literal value, expected ${JSON.stringify(S.expected,util.jsonStringifyReplacer)}`;break;case ZodIssueCode.unrecognized_keys:A=`Unrecognized key(s) in object: ${util.joinValues(S.keys,", ")}`;break;case ZodIssueCode.invalid_union:A="Invalid input";break;case ZodIssueCode.invalid_union_discriminator:A=`Invalid discriminator value. Expected ${util.joinValues(S.options)}`;break;case ZodIssueCode.invalid_enum_value:A=`Invalid enum value. Expected ${util.joinValues(S.options)}, received '${S.received}'`;break;case ZodIssueCode.invalid_arguments:A="Invalid function arguments";break;case ZodIssueCode.invalid_return_type:A="Invalid function return type";break;case ZodIssueCode.invalid_date:A="Invalid date";break;case ZodIssueCode.invalid_string:typeof S.validation=="object"?"includes"in S.validation?(A=`Invalid input: must include "${S.validation.includes}"`,typeof S.validation.position=="number"&&(A=`${A} at one or more positions greater than or equal to ${S.validation.position}`)):"startsWith"in S.validation?A=`Invalid input: must start with "${S.validation.startsWith}"`:"endsWith"in S.validation?A=`Invalid input: must end with "${S.validation.endsWith}"`:util.assertNever(S.validation):S.validation!=="regex"?A=`Invalid ${S.validation}`:A="Invalid";break;case ZodIssueCode.too_small:S.type==="array"?A=`Array must contain ${S.exact?"exactly":S.inclusive?"at least":"more than"} ${S.minimum} element(s)`:S.type==="string"?A=`String must contain ${S.exact?"exactly":S.inclusive?"at least":"over"} ${S.minimum} character(s)`:S.type==="number"?A=`Number must be ${S.exact?"exactly equal to ":S.inclusive?"greater than or equal to ":"greater than "}${S.minimum}`:S.type==="bigint"?A=`Number must be ${S.exact?"exactly equal to ":S.inclusive?"greater than or equal to ":"greater than "}${S.minimum}`:S.type==="date"?A=`Date must be ${S.exact?"exactly equal to ":S.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(S.minimum))}`:A="Invalid input";break;case ZodIssueCode.too_big:S.type==="array"?A=`Array must contain ${S.exact?"exactly":S.inclusive?"at most":"less than"} ${S.maximum} element(s)`:S.type==="string"?A=`String must contain ${S.exact?"exactly":S.inclusive?"at most":"under"} ${S.maximum} character(s)`:S.type==="number"?A=`Number must be ${S.exact?"exactly":S.inclusive?"less than or equal to":"less than"} ${S.maximum}`:S.type==="bigint"?A=`BigInt must be ${S.exact?"exactly":S.inclusive?"less than or equal to":"less than"} ${S.maximum}`:S.type==="date"?A=`Date must be ${S.exact?"exactly":S.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(S.maximum))}`:A="Invalid input";break;case ZodIssueCode.custom:A="Invalid input";break;case ZodIssueCode.invalid_intersection_types:A="Intersection results could not be merged";break;case ZodIssueCode.not_multiple_of:A=`Number must be a multiple of ${S.multipleOf}`;break;case ZodIssueCode.not_finite:A="Number must be finite";break;default:A=T.defaultError,util.assertNever(S)}return{message:A}};let overrideErrorMap=errorMap;function getErrorMap(){return overrideErrorMap}const makeIssue=S=>{const{data:T,path:A,errorMaps:O,issueData:P}=S,R=[...A,...P.path||[]],M={...P,path:R};if(P.message!==void 0)return{...P,path:R,message:P.message};let D="";const U=O.filter(C=>!!C).slice().reverse();for(const C of U)D=C(M,{data:T,defaultError:D}).message;return{...P,path:R,message:D}};function addIssueToContext(S,T){const A=getErrorMap(),O=makeIssue({issueData:T,data:S.data,path:S.path,errorMaps:[S.common.contextualErrorMap,S.schemaErrorMap,A,A===errorMap?void 0:errorMap].filter(P=>!!P)});S.common.issues.push(O)}class ParseStatus{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(T,A){const O=[];for(const P of A){if(P.status==="aborted")return INVALID;P.status==="dirty"&&T.dirty(),O.push(P.value)}return{status:T.value,value:O}}static async mergeObjectAsync(T,A){const O=[];for(const P of A){const R=await P.key,M=await P.value;O.push({key:R,value:M})}return ParseStatus.mergeObjectSync(T,O)}static mergeObjectSync(T,A){const O={};for(const P of A){const{key:R,value:M}=P;if(R.status==="aborted"||M.status==="aborted")return INVALID;R.status==="dirty"&&T.dirty(),M.status==="dirty"&&T.dirty(),R.value!=="__proto__"&&(typeof M.value<"u"||P.alwaysSet)&&(O[R.value]=M.value)}return{status:T.value,value:O}}}const INVALID=Object.freeze({status:"aborted"}),DIRTY=S=>({status:"dirty",value:S}),OK=S=>({status:"valid",value:S}),isAborted=S=>S.status==="aborted",isDirty=S=>S.status==="dirty",isValid=S=>S.status==="valid",isAsync=S=>typeof Promise<"u"&&S instanceof Promise;var errorUtil;(function(S){S.errToObj=T=>typeof T=="string"?{message:T}:T||{},S.toString=T=>typeof T=="string"?T:T?.message})(errorUtil||(errorUtil={}));class ParseInputLazyPath{constructor(T,A,O,P){this._cachedPath=[],this.parent=T,this.data=A,this._path=O,this._key=P}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const handleResult=(S,T)=>{if(isValid(T))return{success:!0,data:T.value};if(!S.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const A=new ZodError(S.common.issues);return this._error=A,this._error}}};function processCreateParams(S){if(!S)return{};const{errorMap:T,invalid_type_error:A,required_error:O,description:P}=S;if(T&&(A||O))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return T?{errorMap:T,description:P}:{errorMap:(M,D)=>{const{message:U}=S;return M.code==="invalid_enum_value"?{message:U??D.defaultError}:typeof D.data>"u"?{message:U??O??D.defaultError}:M.code!=="invalid_type"?{message:D.defaultError}:{message:U??A??D.defaultError}},description:P}}class ZodType{get description(){return this._def.description}_getType(T){return getParsedType(T.data)}_getOrReturnCtx(T,A){return A||{common:T.parent.common,data:T.data,parsedType:getParsedType(T.data),schemaErrorMap:this._def.errorMap,path:T.path,parent:T.parent}}_processInputParams(T){return{status:new ParseStatus,ctx:{common:T.parent.common,data:T.data,parsedType:getParsedType(T.data),schemaErrorMap:this._def.errorMap,path:T.path,parent:T.parent}}}_parseSync(T){const A=this._parse(T);if(isAsync(A))throw new Error("Synchronous parse encountered promise.");return A}_parseAsync(T){const A=this._parse(T);return Promise.resolve(A)}parse(T,A){const O=this.safeParse(T,A);if(O.success)return O.data;throw O.error}safeParse(T,A){const O={common:{issues:[],async:A?.async??!1,contextualErrorMap:A?.errorMap},path:A?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:T,parsedType:getParsedType(T)},P=this._parseSync({data:T,path:O.path,parent:O});return handleResult(O,P)}"~validate"(T){const A={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:T,parsedType:getParsedType(T)};if(!this["~standard"].async)try{const O=this._parseSync({data:T,path:[],parent:A});return isValid(O)?{value:O.value}:{issues:A.common.issues}}catch(O){O?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),A.common={issues:[],async:!0}}return this._parseAsync({data:T,path:[],parent:A}).then(O=>isValid(O)?{value:O.value}:{issues:A.common.issues})}async parseAsync(T,A){const O=await this.safeParseAsync(T,A);if(O.success)return O.data;throw O.error}async safeParseAsync(T,A){const O={common:{issues:[],contextualErrorMap:A?.errorMap,async:!0},path:A?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:T,parsedType:getParsedType(T)},P=this._parse({data:T,path:O.path,parent:O}),R=await(isAsync(P)?P:Promise.resolve(P));return handleResult(O,R)}refine(T,A){const O=P=>typeof A=="string"||typeof A>"u"?{message:A}:typeof A=="function"?A(P):A;return this._refinement((P,R)=>{const M=T(P),D=()=>R.addIssue({code:ZodIssueCode.custom,...O(P)});return typeof Promise<"u"&&M instanceof Promise?M.then(U=>U?!0:(D(),!1)):M?!0:(D(),!1)})}refinement(T,A){return this._refinement((O,P)=>T(O)?!0:(P.addIssue(typeof A=="function"?A(O,P):A),!1))}_refinement(T){return new ZodEffects({schema:this,typeName:ZodFirstPartyTypeKind.ZodEffects,effect:{type:"refinement",refinement:T}})}superRefine(T){return this._refinement(T)}constructor(T){this.spa=this.safeParseAsync,this._def=T,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:A=>this["~validate"](A)}}optional(){return ZodOptional.create(this,this._def)}nullable(){return ZodNullable.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return ZodArray.create(this)}promise(){return ZodPromise.create(this,this._def)}or(T){return ZodUnion.create([this,T],this._def)}and(T){return ZodIntersection.create(this,T,this._def)}transform(T){return new ZodEffects({...processCreateParams(this._def),schema:this,typeName:ZodFirstPartyTypeKind.ZodEffects,effect:{type:"transform",transform:T}})}default(T){const A=typeof T=="function"?T:()=>T;return new ZodDefault({...processCreateParams(this._def),innerType:this,defaultValue:A,typeName:ZodFirstPartyTypeKind.ZodDefault})}brand(){return new ZodBranded({typeName:ZodFirstPartyTypeKind.ZodBranded,type:this,...processCreateParams(this._def)})}catch(T){const A=typeof T=="function"?T:()=>T;return new ZodCatch({...processCreateParams(this._def),innerType:this,catchValue:A,typeName:ZodFirstPartyTypeKind.ZodCatch})}describe(T){const A=this.constructor;return new A({...this._def,description:T})}pipe(T){return ZodPipeline.create(this,T)}readonly(){return ZodReadonly.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const cuidRegex=/^c[^\s-]{8,}$/i,cuid2Regex=/^[0-9a-z]+$/,ulidRegex=/^[0-9A-HJKMNP-TV-Z]{26}$/i,uuidRegex=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,nanoidRegex=/^[a-z0-9_-]{21}$/i,jwtRegex=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,durationRegex=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,emailRegex=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,_emojiRegex="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let emojiRegex;const ipv4Regex=/^(?:(?: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])$/,ipv4CidrRegex=/^(?:(?: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])\/(3[0-2]|[12]?[0-9])$/,ipv6Regex=/^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,ipv6CidrRegex=/^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,base64Regex=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,base64urlRegex=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,dateRegexSource="((\\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])))",dateRegex=new RegExp(`^${dateRegexSource}$`);function timeRegexSource(S){let T="[0-5]\\d";S.precision?T=`${T}\\.\\d{${S.precision}}`:S.precision==null&&(T=`${T}(\\.\\d+)?`);const A=S.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${T})${A}`}function timeRegex(S){return new RegExp(`^${timeRegexSource(S)}$`)}function datetimeRegex(S){let T=`${dateRegexSource}T${timeRegexSource(S)}`;const A=[];return A.push(S.local?"Z?":"Z"),S.offset&&A.push("([+-]\\d{2}:?\\d{2})"),T=`${T}(${A.join("|")})`,new RegExp(`^${T}$`)}function isValidIP(S,T){return!!((T==="v4"||!T)&&ipv4Regex.test(S)||(T==="v6"||!T)&&ipv6Regex.test(S))}function isValidJWT(S,T){if(!jwtRegex.test(S))return!1;try{const[A]=S.split(".");if(!A)return!1;const O=A.replace(/-/g,"+").replace(/_/g,"/").padEnd(A.length+(4-A.length%4)%4,"="),P=JSON.parse(atob(O));return!(typeof P!="object"||P===null||"typ"in P&&P?.typ!=="JWT"||!P.alg||T&&P.alg!==T)}catch{return!1}}function isValidCidr(S,T){return!!((T==="v4"||!T)&&ipv4CidrRegex.test(S)||(T==="v6"||!T)&&ipv6CidrRegex.test(S))}class ZodString extends ZodType{_parse(T){if(this._def.coerce&&(T.data=String(T.data)),this._getType(T)!==ZodParsedType.string){const R=this._getOrReturnCtx(T);return addIssueToContext(R,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.string,received:R.parsedType}),INVALID}const O=new ParseStatus;let P;for(const R of this._def.checks)if(R.kind==="min")T.data.length<R.value&&(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{code:ZodIssueCode.too_small,minimum:R.value,type:"string",inclusive:!0,exact:!1,message:R.message}),O.dirty());else if(R.kind==="max")T.data.length>R.value&&(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{code:ZodIssueCode.too_big,maximum:R.value,type:"string",inclusive:!0,exact:!1,message:R.message}),O.dirty());else if(R.kind==="length"){const M=T.data.length>R.value,D=T.data.length<R.value;(M||D)&&(P=this._getOrReturnCtx(T,P),M?addIssueToContext(P,{code:ZodIssueCode.too_big,maximum:R.value,type:"string",inclusive:!0,exact:!0,message:R.message}):D&&addIssueToContext(P,{code:ZodIssueCode.too_small,minimum:R.value,type:"string",inclusive:!0,exact:!0,message:R.message}),O.dirty())}else if(R.kind==="email")emailRegex.test(T.data)||(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{validation:"email",code:ZodIssueCode.invalid_string,message:R.message}),O.dirty());else if(R.kind==="emoji")emojiRegex||(emojiRegex=new RegExp(_emojiRegex,"u")),emojiRegex.test(T.data)||(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{validation:"emoji",code:ZodIssueCode.invalid_string,message:R.message}),O.dirty());else if(R.kind==="uuid")uuidRegex.test(T.data)||(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{validation:"uuid",code:ZodIssueCode.invalid_string,message:R.message}),O.dirty());else if(R.kind==="nanoid")nanoidRegex.test(T.data)||(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{validation:"nanoid",code:ZodIssueCode.invalid_string,message:R.message}),O.dirty());else if(R.kind==="cuid")cuidRegex.test(T.data)||(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{validation:"cuid",code:ZodIssueCode.invalid_string,message:R.message}),O.dirty());else if(R.kind==="cuid2")cuid2Regex.test(T.data)||(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{validation:"cuid2",code:ZodIssueCode.invalid_string,message:R.message}),O.dirty());else if(R.kind==="ulid")ulidRegex.test(T.data)||(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{validation:"ulid",code:ZodIssueCode.invalid_string,message:R.message}),O.dirty());else if(R.kind==="url")try{new URL(T.data)}catch{P=this._getOrReturnCtx(T,P),addIssueToContext(P,{validation:"url",code:ZodIssueCode.invalid_string,message:R.message}),O.dirty()}else R.kind==="regex"?(R.regex.lastIndex=0,R.regex.test(T.data)||(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{validation:"regex",code:ZodIssueCode.invalid_string,message:R.message}),O.dirty())):R.kind==="trim"?T.data=T.data.trim():R.kind==="includes"?T.data.includes(R.value,R.position)||(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{code:ZodIssueCode.invalid_string,validation:{includes:R.value,position:R.position},message:R.message}),O.dirty()):R.kind==="toLowerCase"?T.data=T.data.toLowerCase():R.kind==="toUpperCase"?T.data=T.data.toUpperCase():R.kind==="startsWith"?T.data.startsWith(R.value)||(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{code:ZodIssueCode.invalid_string,validation:{startsWith:R.value},message:R.message}),O.dirty()):R.kind==="endsWith"?T.data.endsWith(R.value)||(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{code:ZodIssueCode.invalid_string,validation:{endsWith:R.value},message:R.message}),O.dirty()):R.kind==="datetime"?datetimeRegex(R).test(T.data)||(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{code:ZodIssueCode.invalid_string,validation:"datetime",message:R.message}),O.dirty()):R.kind==="date"?dateRegex.test(T.data)||(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{code:ZodIssueCode.invalid_string,validation:"date",message:R.message}),O.dirty()):R.kind==="time"?timeRegex(R).test(T.data)||(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{code:ZodIssueCode.invalid_string,validation:"time",message:R.message}),O.dirty()):R.kind==="duration"?durationRegex.test(T.data)||(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{validation:"duration",code:ZodIssueCode.invalid_string,message:R.message}),O.dirty()):R.kind==="ip"?isValidIP(T.data,R.version)||(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{validation:"ip",code:ZodIssueCode.invalid_string,message:R.message}),O.dirty()):R.kind==="jwt"?isValidJWT(T.data,R.alg)||(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{validation:"jwt",code:ZodIssueCode.invalid_string,message:R.message}),O.dirty()):R.kind==="cidr"?isValidCidr(T.data,R.version)||(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{validation:"cidr",code:ZodIssueCode.invalid_string,message:R.message}),O.dirty()):R.kind==="base64"?base64Regex.test(T.data)||(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{validation:"base64",code:ZodIssueCode.invalid_string,message:R.message}),O.dirty()):R.kind==="base64url"?base64urlRegex.test(T.data)||(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{validation:"base64url",code:ZodIssueCode.invalid_string,message:R.message}),O.dirty()):util.assertNever(R);return{status:O.value,value:T.data}}_regex(T,A,O){return this.refinement(P=>T.test(P),{validation:A,code:ZodIssueCode.invalid_string,...errorUtil.errToObj(O)})}_addCheck(T){return new ZodString({...this._def,checks:[...this._def.checks,T]})}email(T){return this._addCheck({kind:"email",...errorUtil.errToObj(T)})}url(T){return this._addCheck({kind:"url",...errorUtil.errToObj(T)})}emoji(T){return this._addCheck({kind:"emoji",...errorUtil.errToObj(T)})}uuid(T){return this._addCheck({kind:"uuid",...errorUtil.errToObj(T)})}nanoid(T){return this._addCheck({kind:"nanoid",...errorUtil.errToObj(T)})}cuid(T){return this._addCheck({kind:"cuid",...errorUtil.errToObj(T)})}cuid2(T){return this._addCheck({kind:"cuid2",...errorUtil.errToObj(T)})}ulid(T){return this._addCheck({kind:"ulid",...errorUtil.errToObj(T)})}base64(T){return this._addCheck({kind:"base64",...errorUtil.errToObj(T)})}base64url(T){return this._addCheck({kind:"base64url",...errorUtil.errToObj(T)})}jwt(T){return this._addCheck({kind:"jwt",...errorUtil.errToObj(T)})}ip(T){return this._addCheck({kind:"ip",...errorUtil.errToObj(T)})}cidr(T){return this._addCheck({kind:"cidr",...errorUtil.errToObj(T)})}datetime(T){return typeof T=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:T}):this._addCheck({kind:"datetime",precision:typeof T?.precision>"u"?null:T?.precision,offset:T?.offset??!1,local:T?.local??!1,...errorUtil.errToObj(T?.message)})}date(T){return this._addCheck({kind:"date",message:T})}time(T){return typeof T=="string"?this._addCheck({kind:"time",precision:null,message:T}):this._addCheck({kind:"time",precision:typeof T?.precision>"u"?null:T?.precision,...errorUtil.errToObj(T?.message)})}duration(T){return this._addCheck({kind:"duration",...errorUtil.errToObj(T)})}regex(T,A){return this._addCheck({kind:"regex",regex:T,...errorUtil.errToObj(A)})}includes(T,A){return this._addCheck({kind:"includes",value:T,position:A?.position,...errorUtil.errToObj(A?.message)})}startsWith(T,A){return this._addCheck({kind:"startsWith",value:T,...errorUtil.errToObj(A)})}endsWith(T,A){return this._addCheck({kind:"endsWith",value:T,...errorUtil.errToObj(A)})}min(T,A){return this._addCheck({kind:"min",value:T,...errorUtil.errToObj(A)})}max(T,A){return this._addCheck({kind:"max",value:T,...errorUtil.errToObj(A)})}length(T,A){return this._addCheck({kind:"length",value:T,...errorUtil.errToObj(A)})}nonempty(T){return this.min(1,errorUtil.errToObj(T))}trim(){return new ZodString({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new ZodString({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new ZodString({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(T=>T.kind==="datetime")}get isDate(){return!!this._def.checks.find(T=>T.kind==="date")}get isTime(){return!!this._def.checks.find(T=>T.kind==="time")}get isDuration(){return!!this._def.checks.find(T=>T.kind==="duration")}get isEmail(){return!!this._def.checks.find(T=>T.kind==="email")}get isURL(){return!!this._def.checks.find(T=>T.kind==="url")}get isEmoji(){return!!this._def.checks.find(T=>T.kind==="emoji")}get isUUID(){return!!this._def.checks.find(T=>T.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(T=>T.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(T=>T.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(T=>T.kind==="cuid2")}get isULID(){return!!this._def.checks.find(T=>T.kind==="ulid")}get isIP(){return!!this._def.checks.find(T=>T.kind==="ip")}get isCIDR(){return!!this._def.checks.find(T=>T.kind==="cidr")}get isBase64(){return!!this._def.checks.find(T=>T.kind==="base64")}get isBase64url(){return!!this._def.checks.find(T=>T.kind==="base64url")}get minLength(){let T=null;for(const A of this._def.checks)A.kind==="min"&&(T===null||A.value>T)&&(T=A.value);return T}get maxLength(){let T=null;for(const A of this._def.checks)A.kind==="max"&&(T===null||A.value<T)&&(T=A.value);return T}}ZodString.create=S=>new ZodString({checks:[],typeName:ZodFirstPartyTypeKind.ZodString,coerce:S?.coerce??!1,...processCreateParams(S)});function floatSafeRemainder(S,T){const A=(S.toString().split(".")[1]||"").length,O=(T.toString().split(".")[1]||"").length,P=A>O?A:O,R=Number.parseInt(S.toFixed(P).replace(".","")),M=Number.parseInt(T.toFixed(P).replace(".",""));return R%M/10**P}class ZodNumber extends ZodType{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(T){if(this._def.coerce&&(T.data=Number(T.data)),this._getType(T)!==ZodParsedType.number){const R=this._getOrReturnCtx(T);return addIssueToContext(R,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.number,received:R.parsedType}),INVALID}let O;const P=new ParseStatus;for(const R of this._def.checks)R.kind==="int"?util.isInteger(T.data)||(O=this._getOrReturnCtx(T,O),addIssueToContext(O,{code:ZodIssueCode.invalid_type,expected:"integer",received:"float",message:R.message}),P.dirty()):R.kind==="min"?(R.inclusive?T.data<R.value:T.data<=R.value)&&(O=this._getOrReturnCtx(T,O),addIssueToContext(O,{code:ZodIssueCode.too_small,minimum:R.value,type:"number",inclusive:R.inclusive,exact:!1,message:R.message}),P.dirty()):R.kind==="max"?(R.inclusive?T.data>R.value:T.data>=R.value)&&(O=this._getOrReturnCtx(T,O),addIssueToContext(O,{code:ZodIssueCode.too_big,maximum:R.value,type:"number",inclusive:R.inclusive,exact:!1,message:R.message}),P.dirty()):R.kind==="multipleOf"?floatSafeRemainder(T.data,R.value)!==0&&(O=this._getOrReturnCtx(T,O),addIssueToContext(O,{code:ZodIssueCode.not_multiple_of,multipleOf:R.value,message:R.message}),P.dirty()):R.kind==="finite"?Number.isFinite(T.data)||(O=this._getOrReturnCtx(T,O),addIssueToContext(O,{code:ZodIssueCode.not_finite,message:R.message}),P.dirty()):util.assertNever(R);return{status:P.value,value:T.data}}gte(T,A){return this.setLimit("min",T,!0,errorUtil.toString(A))}gt(T,A){return this.setLimit("min",T,!1,errorUtil.toString(A))}lte(T,A){return this.setLimit("max",T,!0,errorUtil.toString(A))}lt(T,A){return this.setLimit("max",T,!1,errorUtil.toString(A))}setLimit(T,A,O,P){return new ZodNumber({...this._def,checks:[...this._def.checks,{kind:T,value:A,inclusive:O,message:errorUtil.toString(P)}]})}_addCheck(T){return new ZodNumber({...this._def,checks:[...this._def.checks,T]})}int(T){return this._addCheck({kind:"int",message:errorUtil.toString(T)})}positive(T){return this._addCheck({kind:"min",value:0,inclusive:!1,message:errorUtil.toString(T)})}negative(T){return this._addCheck({kind:"max",value:0,inclusive:!1,message:errorUtil.toString(T)})}nonpositive(T){return this._addCheck({kind:"max",value:0,inclusive:!0,message:errorUtil.toString(T)})}nonnegative(T){return this._addCheck({kind:"min",value:0,inclusive:!0,message:errorUtil.toString(T)})}multipleOf(T,A){return this._addCheck({kind:"multipleOf",value:T,message:errorUtil.toString(A)})}finite(T){return this._addCheck({kind:"finite",message:errorUtil.toString(T)})}safe(T){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:errorUtil.toString(T)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:errorUtil.toString(T)})}get minValue(){let T=null;for(const A of this._def.checks)A.kind==="min"&&(T===null||A.value>T)&&(T=A.value);return T}get maxValue(){let T=null;for(const A of this._def.checks)A.kind==="max"&&(T===null||A.value<T)&&(T=A.value);return T}get isInt(){return!!this._def.checks.find(T=>T.kind==="int"||T.kind==="multipleOf"&&util.isInteger(T.value))}get isFinite(){let T=null,A=null;for(const O of this._def.checks){if(O.kind==="finite"||O.kind==="int"||O.kind==="multipleOf")return!0;O.kind==="min"?(A===null||O.value>A)&&(A=O.value):O.kind==="max"&&(T===null||O.value<T)&&(T=O.value)}return Number.isFinite(A)&&Number.isFinite(T)}}ZodNumber.create=S=>new ZodNumber({checks:[],typeName:ZodFirstPartyTypeKind.ZodNumber,coerce:S?.coerce||!1,...processCreateParams(S)});class ZodBigInt extends ZodType{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(T){if(this._def.coerce)try{T.data=BigInt(T.data)}catch{return this._getInvalidInput(T)}if(this._getType(T)!==ZodParsedType.bigint)return this._getInvalidInput(T);let O;const P=new ParseStatus;for(const R of this._def.checks)R.kind==="min"?(R.inclusive?T.data<R.value:T.data<=R.value)&&(O=this._getOrReturnCtx(T,O),addIssueToContext(O,{code:ZodIssueCode.too_small,type:"bigint",minimum:R.value,inclusive:R.inclusive,message:R.message}),P.dirty()):R.kind==="max"?(R.inclusive?T.data>R.value:T.data>=R.value)&&(O=this._getOrReturnCtx(T,O),addIssueToContext(O,{code:ZodIssueCode.too_big,type:"bigint",maximum:R.value,inclusive:R.inclusive,message:R.message}),P.dirty()):R.kind==="multipleOf"?T.data%R.value!==BigInt(0)&&(O=this._getOrReturnCtx(T,O),addIssueToContext(O,{code:ZodIssueCode.not_multiple_of,multipleOf:R.value,message:R.message}),P.dirty()):util.assertNever(R);return{status:P.value,value:T.data}}_getInvalidInput(T){const A=this._getOrReturnCtx(T);return addIssueToContext(A,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.bigint,received:A.parsedType}),INVALID}gte(T,A){return this.setLimit("min",T,!0,errorUtil.toString(A))}gt(T,A){return this.setLimit("min",T,!1,errorUtil.toString(A))}lte(T,A){return this.setLimit("max",T,!0,errorUtil.toString(A))}lt(T,A){return this.setLimit("max",T,!1,errorUtil.toString(A))}setLimit(T,A,O,P){return new ZodBigInt({...this._def,checks:[...this._def.checks,{kind:T,value:A,inclusive:O,message:errorUtil.toString(P)}]})}_addCheck(T){return new ZodBigInt({...this._def,checks:[...this._def.checks,T]})}positive(T){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:errorUtil.toString(T)})}negative(T){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:errorUtil.toString(T)})}nonpositive(T){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:errorUtil.toString(T)})}nonnegative(T){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:errorUtil.toString(T)})}multipleOf(T,A){return this._addCheck({kind:"multipleOf",value:T,message:errorUtil.toString(A)})}get minValue(){let T=null;for(const A of this._def.checks)A.kind==="min"&&(T===null||A.value>T)&&(T=A.value);return T}get maxValue(){let T=null;for(const A of this._def.checks)A.kind==="max"&&(T===null||A.value<T)&&(T=A.value);return T}}ZodBigInt.create=S=>new ZodBigInt({checks:[],typeName:ZodFirstPartyTypeKind.ZodBigInt,coerce:S?.coerce??!1,...processCreateParams(S)});class ZodBoolean extends ZodType{_parse(T){if(this._def.coerce&&(T.data=!!T.data),this._getType(T)!==ZodParsedType.boolean){const O=this._getOrReturnCtx(T);return addIssueToContext(O,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.boolean,received:O.parsedType}),INVALID}return OK(T.data)}}ZodBoolean.create=S=>new ZodBoolean({typeName:ZodFirstPartyTypeKind.ZodBoolean,coerce:S?.coerce||!1,...processCreateParams(S)});class ZodDate extends ZodType{_parse(T){if(this._def.coerce&&(T.data=new Date(T.data)),this._getType(T)!==ZodParsedType.date){const R=this._getOrReturnCtx(T);return addIssueToContext(R,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.date,received:R.parsedType}),INVALID}if(Number.isNaN(T.data.getTime())){const R=this._getOrReturnCtx(T);return addIssueToContext(R,{code:ZodIssueCode.invalid_date}),INVALID}const O=new ParseStatus;let P;for(const R of this._def.checks)R.kind==="min"?T.data.getTime()<R.value&&(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{code:ZodIssueCode.too_small,message:R.message,inclusive:!0,exact:!1,minimum:R.value,type:"date"}),O.dirty()):R.kind==="max"?T.data.getTime()>R.value&&(P=this._getOrReturnCtx(T,P),addIssueToContext(P,{code:ZodIssueCode.too_big,message:R.message,inclusive:!0,exact:!1,maximum:R.value,type:"date"}),O.dirty()):util.assertNever(R);return{status:O.value,value:new Date(T.data.getTime())}}_addCheck(T){return new ZodDate({...this._def,checks:[...this._def.checks,T]})}min(T,A){return this._addCheck({kind:"min",value:T.getTime(),message:errorUtil.toString(A)})}max(T,A){return this._addCheck({kind:"max",value:T.getTime(),message:errorUtil.toString(A)})}get minDate(){let T=null;for(const A of this._def.checks)A.kind==="min"&&(T===null||A.value>T)&&(T=A.value);return T!=null?new Date(T):null}get maxDate(){let T=null;for(const A of this._def.checks)A.kind==="max"&&(T===null||A.value<T)&&(T=A.value);return T!=null?new Date(T):null}}ZodDate.create=S=>new ZodDate({checks:[],coerce:S?.coerce||!1,typeName:ZodFirstPartyTypeKind.ZodDate,...processCreateParams(S)});class ZodSymbol extends ZodType{_parse(T){if(this._getType(T)!==ZodParsedType.symbol){const O=this._getOrReturnCtx(T);return addIssueToContext(O,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.symbol,received:O.parsedType}),INVALID}return OK(T.data)}}ZodSymbol.create=S=>new ZodSymbol({typeName:ZodFirstPartyTypeKind.ZodSymbol,...processCreateParams(S)});class ZodUndefined extends ZodType{_parse(T){if(this._getType(T)!==ZodParsedType.undefined){const O=this._getOrReturnCtx(T);return addIssueToContext(O,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.undefined,received:O.parsedType}),INVALID}return OK(T.data)}}ZodUndefined.create=S=>new ZodUndefined({typeName:ZodFirstPartyTypeKind.ZodUndefined,...processCreateParams(S)});class ZodNull extends ZodType{_parse(T){if(this._getType(T)!==ZodParsedType.null){const O=this._getOrReturnCtx(T);return addIssueToContext(O,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.null,received:O.parsedType}),INVALID}return OK(T.data)}}ZodNull.create=S=>new ZodNull({typeName:ZodFirstPartyTypeKind.ZodNull,...processCreateParams(S)});class ZodAny extends ZodType{constructor(){super(...arguments),this._any=!0}_parse(T){return OK(T.data)}}ZodAny.create=S=>new ZodAny({typeName:ZodFirstPartyTypeKind.ZodAny,...processCreateParams(S)});class ZodUnknown extends ZodType{constructor(){super(...arguments),this._unknown=!0}_parse(T){return OK(T.data)}}ZodUnknown.create=S=>new ZodUnknown({typeName:ZodFirstPartyTypeKind.ZodUnknown,...processCreateParams(S)});class ZodNever extends ZodType{_parse(T){const A=this._getOrReturnCtx(T);return addIssueToContext(A,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.never,received:A.parsedType}),INVALID}}ZodNever.create=S=>new ZodNever({typeName:ZodFirstPartyTypeKind.ZodNever,...processCreateParams(S)});class ZodVoid extends ZodType{_parse(T){if(this._getType(T)!==ZodParsedType.undefined){const O=this._getOrReturnCtx(T);return addIssueToContext(O,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.void,received:O.parsedType}),INVALID}return OK(T.data)}}ZodVoid.create=S=>new ZodVoid({typeName:ZodFirstPartyTypeKind.ZodVoid,...processCreateParams(S)});class ZodArray extends ZodType{_parse(T){const{ctx:A,status:O}=this._processInputParams(T),P=this._def;if(A.parsedType!==ZodParsedType.array)return addIssueToContext(A,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.array,received:A.parsedType}),INVALID;if(P.exactLength!==null){const M=A.data.length>P.exactLength.value,D=A.data.length<P.exactLength.value;(M||D)&&(addIssueToContext(A,{code:M?ZodIssueCode.too_big:ZodIssueCode.too_small,minimum:D?P.exactLength.value:void 0,maximum:M?P.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:P.exactLength.message}),O.dirty())}if(P.minLength!==null&&A.data.length<P.minLength.value&&(addIssueToContext(A,{code:ZodIssueCode.too_small,minimum:P.minLength.value,type:"array",inclusive:!0,exact:!1,message:P.minLength.message}),O.dirty()),P.maxLength!==null&&A.data.length>P.maxLength.value&&(addIssueToContext(A,{code:ZodIssueCode.too_big,maximum:P.maxLength.value,type:"array",inclusive:!0,exact:!1,message:P.maxLength.message}),O.dirty()),A.common.async)return Promise.all([...A.data].map((M,D)=>P.type._parseAsync(new ParseInputLazyPath(A,M,A.path,D)))).then(M=>ParseStatus.mergeArray(O,M));const R=[...A.data].map((M,D)=>P.type._parseSync(new ParseInputLazyPath(A,M,A.path,D)));return ParseStatus.mergeArray(O,R)}get element(){return this._def.type}min(T,A){return new ZodArray({...this._def,minLength:{value:T,message:errorUtil.toString(A)}})}max(T,A){return new ZodArray({...this._def,maxLength:{value:T,message:errorUtil.toString(A)}})}length(T,A){return new ZodArray({...this._def,exactLength:{value:T,message:errorUtil.toString(A)}})}nonempty(T){return this.min(1,T)}}ZodArray.create=(S,T)=>new ZodArray({type:S,minLength:null,maxLength:null,exactLength:null,typeName:ZodFirstPartyTypeKind.ZodArray,...processCreateParams(T)});function deepPartialify(S){if(S instanceof ZodObject){const T={};for(const A in S.shape){const O=S.shape[A];T[A]=ZodOptional.create(deepPartialify(O))}return new ZodObject({...S._def,shape:()=>T})}else return S instanceof ZodArray?new ZodArray({...S._def,type:deepPartialify(S.element)}):S instanceof ZodOptional?ZodOptional.create(deepPartialify(S.unwrap())):S instanceof ZodNullable?ZodNullable.create(deepPartialify(S.unwrap())):S instanceof ZodTuple?ZodTuple.create(S.items.map(T=>deepPartialify(T))):S}class ZodObject extends ZodType{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const T=this._def.shape(),A=util.objectKeys(T);return this._cached={shape:T,keys:A},this._cached}_parse(T){if(this._getType(T)!==ZodParsedType.object){const C=this._getOrReturnCtx(T);return addIssueToContext(C,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.object,received:C.parsedType}),INVALID}const{status:O,ctx:P}=this._processInputParams(T),{shape:R,keys:M}=this._getCached(),D=[];if(!(this._def.catchall instanceof ZodNever&&this._def.unknownKeys==="strip"))for(const C in P.data)M.includes(C)||D.push(C);const U=[];for(const C of M){const L=R[C],y=P.data[C];U.push({key:{status:"valid",value:C},value:L._parse(new ParseInputLazyPath(P,y,P.path,C)),alwaysSet:C in P.data})}if(this._def.catchall instanceof ZodNever){const C=this._def.unknownKeys;if(C==="passthrough")for(const L of D)U.push({key:{status:"valid",value:L},value:{status:"valid",value:P.data[L]}});else if(C==="strict")D.length>0&&(addIssueToContext(P,{code:ZodIssueCode.unrecognized_keys,keys:D}),O.dirty());else if(C!=="strip")throw new Error("Interna