@authhero/cloudflare-adapter 2.17.20 → 2.17.22
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/cloudflare-adapter.cjs +33 -33
- package/dist/cloudflare-adapter.mjs +976 -1200
- package/package.json +3 -3
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const xt=require("@authhero/adapter-interfaces"),kt=require("wretch");function wt(t,e){var n={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(n[s]=t[s]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,s=Object.getOwnPropertySymbols(t);r<s.length;r++)e.indexOf(s[r])<0&&Object.prototype.propertyIsEnumerable.call(t,s[r])&&(n[s[r]]=t[s[r]]);return n}function Tt(t,e){var n;return((n=t?._def)===null||n===void 0?void 0:n.typeName)===e}function le(t,e){const n=t.ZodType.prototype[e];t.ZodType.prototype[e]=function(...s){const r=n.apply(this,s);return r._def.openapi=this._def.openapi,r}}function St(t){if(typeof t.ZodType.prototype.openapi<"u")return;t.ZodType.prototype.openapi=function(r,a){var i,o,c,d,h,x;const S=typeof r=="string"?a:r,w=S??{},{param:A}=w,Y=wt(w,["param"]),k=Object.assign(Object.assign({},(i=this._def.openapi)===null||i===void 0?void 0:i._internal),typeof r=="string"?{refId:r}:void 0),V=Object.assign(Object.assign(Object.assign({},(o=this._def.openapi)===null||o===void 0?void 0:o.metadata),Y),!((d=(c=this._def.openapi)===null||c===void 0?void 0:c.metadata)===null||d===void 0)&&d.param||A?{param:Object.assign(Object.assign({},(x=(h=this._def.openapi)===null||h===void 0?void 0:h.metadata)===null||x===void 0?void 0:x.param),A)}:void 0),O=new this.constructor(Object.assign(Object.assign({},this._def),{openapi:Object.assign(Object.assign({},Object.keys(k).length>0?{_internal:k}:void 0),Object.keys(V).length>0?{metadata:V}:void 0)}));if(Tt(this,"ZodObject")){const D=this.extend;O.extend=function(...K){var G,ue,Pe,Ve,ze,Be,Fe;const Ue=D.apply(this,K);return Ue._def.openapi={_internal:{extendedFrom:!((ue=(G=this._def.openapi)===null||G===void 0?void 0:G._internal)===null||ue===void 0)&&ue.refId?{refId:(Ve=(Pe=this._def.openapi)===null||Pe===void 0?void 0:Pe._internal)===null||Ve===void 0?void 0:Ve.refId,schema:this}:(Be=(ze=this._def.openapi)===null||ze===void 0?void 0:ze._internal)===null||Be===void 0?void 0:Be.extendedFrom},metadata:(Fe=Ue._def.openapi)===null||Fe===void 0?void 0:Fe.metadata},Ue}}return O},le(t,"optional"),le(t,"nullable"),le(t,"default"),le(t,"transform"),le(t,"refine");const e=t.ZodObject.prototype.deepPartial;t.ZodObject.prototype.deepPartial=function(){const r=this._def.shape(),a=e.apply(this),i=a._def.shape();return Object.entries(i).forEach(([o,c])=>{var d,h;c._def.openapi=(h=(d=r[o])===null||d===void 0?void 0:d._def)===null||h===void 0?void 0:h.openapi}),a._def.openapi=void 0,a};const n=t.ZodObject.prototype.pick;t.ZodObject.prototype.pick=function(...r){const a=n.apply(this,r);return a._def.openapi=void 0,a};const s=t.ZodObject.prototype.omit;t.ZodObject.prototype.omit=function(...r){const a=s.apply(this,r);return a._def.openapi=void 0,a}}var fe=class extends Error{res;status;constructor(t=500,e){super(e?.message,{cause:e?.cause}),this.res=e?.res,this.status=t}getResponse(){return this.res?new Response(this.res.body,{status:this.status,headers:this.res.headers}):new Response(this.message,{status:this.status})}};new Set(".\\+*[^]$()");var b;(function(t){t.assertEqual=r=>{};function e(r){}t.assertIs=e;function n(r){throw new Error}t.assertNever=n,t.arrayToEnum=r=>{const a={};for(const i of r)a[i]=i;return a},t.getValidEnumValues=r=>{const a=t.objectKeys(r).filter(o=>typeof r[r[o]]!="number"),i={};for(const o of a)i[o]=r[o];return t.objectValues(i)},t.objectValues=r=>t.objectKeys(r).map(function(a){return r[a]}),t.objectKeys=typeof Object.keys=="function"?r=>Object.keys(r):r=>{const a=[];for(const i in r)Object.prototype.hasOwnProperty.call(r,i)&&a.push(i);return a},t.find=(r,a)=>{for(const i of r)if(a(i))return i},t.isInteger=typeof Number.isInteger=="function"?r=>Number.isInteger(r):r=>typeof r=="number"&&Number.isFinite(r)&&Math.floor(r)===r;function s(r,a=" | "){return r.map(i=>typeof i=="string"?`'${i}'`:i).join(a)}t.joinValues=s,t.jsonStringifyReplacer=(r,a)=>typeof a=="bigint"?a.toString():a})(b||(b={}));var Qe;(function(t){t.mergeShapes=(e,n)=>({...e,...n})})(Qe||(Qe={}));const f=b.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),B=t=>{switch(typeof t){case"undefined":return f.undefined;case"string":return f.string;case"number":return Number.isNaN(t)?f.nan:f.number;case"boolean":return f.boolean;case"function":return f.function;case"bigint":return f.bigint;case"symbol":return f.symbol;case"object":return Array.isArray(t)?f.array:t===null?f.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?f.promise:typeof Map<"u"&&t instanceof Map?f.map:typeof Set<"u"&&t instanceof Set?f.set:typeof Date<"u"&&t instanceof Date?f.date:f.object;default:return f.unknown}},u=b.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"]),Et=t=>JSON.stringify(t,null,2).replace(/"([^"]+)":/g,"$1:");class N extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=s=>{this.issues=[...this.issues,s]},this.addIssues=(s=[])=>{this.issues=[...this.issues,...s]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=e}format(e){const n=e||function(a){return a.message},s={_errors:[]},r=a=>{for(const i of a.issues)if(i.code==="invalid_union")i.unionErrors.map(r);else if(i.code==="invalid_return_type")r(i.returnTypeError);else if(i.code==="invalid_arguments")r(i.argumentsError);else if(i.path.length===0)s._errors.push(n(i));else{let o=s,c=0;for(;c<i.path.length;){const d=i.path[c];c===i.path.length-1?(o[d]=o[d]||{_errors:[]},o[d]._errors.push(n(i))):o[d]=o[d]||{_errors:[]},o=o[d],c++}}};return r(this),s}static assert(e){if(!(e instanceof N))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,b.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=n=>n.message){const n={},s=[];for(const r of this.issues)if(r.path.length>0){const a=r.path[0];n[a]=n[a]||[],n[a].push(e(r))}else s.push(e(r));return{formErrors:s,fieldErrors:n}}get formErrors(){return this.flatten()}}N.create=t=>new N(t);const oe=(t,e)=>{let n;switch(t.code){case u.invalid_type:t.received===f.undefined?n="Required":n=`Expected ${t.expected}, received ${t.received}`;break;case u.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(t.expected,b.jsonStringifyReplacer)}`;break;case u.unrecognized_keys:n=`Unrecognized key(s) in object: ${b.joinValues(t.keys,", ")}`;break;case u.invalid_union:n="Invalid input";break;case u.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${b.joinValues(t.options)}`;break;case u.invalid_enum_value:n=`Invalid enum value. Expected ${b.joinValues(t.options)}, received '${t.received}'`;break;case u.invalid_arguments:n="Invalid function arguments";break;case u.invalid_return_type:n="Invalid function return type";break;case u.invalid_date:n="Invalid date";break;case u.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(n=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?n=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?n=`Invalid input: must end with "${t.validation.endsWith}"`:b.assertNever(t.validation):t.validation!=="regex"?n=`Invalid ${t.validation}`:n="Invalid";break;case u.too_small:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="bigint"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:n="Invalid input";break;case u.too_big:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?n=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:n="Invalid input";break;case u.custom:n="Invalid input";break;case u.invalid_intersection_types:n="Intersection results could not be merged";break;case u.not_multiple_of:n=`Number must be a multiple of ${t.multipleOf}`;break;case u.not_finite:n="Number must be finite";break;default:n=e.defaultError,b.assertNever(t)}return{message:n}};let ot=oe;function Ct(t){ot=t}function Ne(){return ot}const Re=t=>{const{data:e,path:n,errorMaps:s,issueData:r}=t,a=[...n,...r.path||[]],i={...r,path:a};if(r.message!==void 0)return{...r,path:a,message:r.message};let o="";const c=s.filter(d=>!!d).slice().reverse();for(const d of c)o=d(i,{data:e,defaultError:o}).message;return{...r,path:a,message:o}},At=[];function l(t,e){const n=Ne(),s=Re({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,n,n===oe?void 0:oe].filter(r=>!!r)});t.common.issues.push(s)}class E{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,n){const s=[];for(const r of n){if(r.status==="aborted")return m;r.status==="dirty"&&e.dirty(),s.push(r.value)}return{status:e.value,value:s}}static async mergeObjectAsync(e,n){const s=[];for(const r of n){const a=await r.key,i=await r.value;s.push({key:a,value:i})}return E.mergeObjectSync(e,s)}static mergeObjectSync(e,n){const s={};for(const r of n){const{key:a,value:i}=r;if(a.status==="aborted"||i.status==="aborted")return m;a.status==="dirty"&&e.dirty(),i.status==="dirty"&&e.dirty(),a.value!=="__proto__"&&(typeof i.value<"u"||r.alwaysSet)&&(s[a.value]=i.value)}return{status:e.value,value:s}}}const m=Object.freeze({status:"aborted"}),ae=t=>({status:"dirty",value:t}),C=t=>({status:"valid",value:t}),He=t=>t.status==="aborted",Je=t=>t.status==="dirty",ee=t=>t.status==="valid",he=t=>typeof Promise<"u"&&t instanceof Promise;var p;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e?.message})(p||(p={}));class M{constructor(e,n,s,r){this._cachedPath=[],this.parent=e,this.data=n,this._path=s,this._key=r}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 tt=(t,e)=>{if(ee(e))return{success:!0,data:e.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const n=new N(t.common.issues);return this._error=n,this._error}}};function _(t){if(!t)return{};const{errorMap:e,invalid_type_error:n,required_error:s,description:r}=t;if(e&&(n||s))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:r}:{errorMap:(i,o)=>{const{message:c}=t;return i.code==="invalid_enum_value"?{message:c??o.defaultError}:typeof o.data>"u"?{message:c??s??o.defaultError}:i.code!=="invalid_type"?{message:o.defaultError}:{message:c??n??o.defaultError}},description:r}}class v{get description(){return this._def.description}_getType(e){return B(e.data)}_getOrReturnCtx(e,n){return n||{common:e.parent.common,data:e.data,parsedType:B(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new E,ctx:{common:e.parent.common,data:e.data,parsedType:B(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const n=this._parse(e);if(he(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(e){const n=this._parse(e);return Promise.resolve(n)}parse(e,n){const s=this.safeParse(e,n);if(s.success)return s.data;throw s.error}safeParse(e,n){const s={common:{issues:[],async:n?.async??!1,contextualErrorMap:n?.errorMap},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:B(e)},r=this._parseSync({data:e,path:s.path,parent:s});return tt(s,r)}"~validate"(e){const n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:B(e)};if(!this["~standard"].async)try{const s=this._parseSync({data:e,path:[],parent:n});return ee(s)?{value:s.value}:{issues:n.common.issues}}catch(s){s?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),n.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:n}).then(s=>ee(s)?{value:s.value}:{issues:n.common.issues})}async parseAsync(e,n){const s=await this.safeParseAsync(e,n);if(s.success)return s.data;throw s.error}async safeParseAsync(e,n){const s={common:{issues:[],contextualErrorMap:n?.errorMap,async:!0},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:B(e)},r=this._parse({data:e,path:s.path,parent:s}),a=await(he(r)?r:Promise.resolve(r));return tt(s,a)}refine(e,n){const s=r=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(r):n;return this._refinement((r,a)=>{const i=e(r),o=()=>a.addIssue({code:u.custom,...s(r)});return typeof Promise<"u"&&i instanceof Promise?i.then(c=>c?!0:(o(),!1)):i?!0:(o(),!1)})}refinement(e,n){return this._refinement((s,r)=>e(s)?!0:(r.addIssue(typeof n=="function"?n(s,r):n),!1))}_refinement(e){return new j({schema:this,typeName:y.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,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:n=>this["~validate"](n)}}optional(){return L.create(this,this._def)}nullable(){return J.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return I.create(this)}promise(){return de.create(this,this._def)}or(e){return _e.create([this,e],this._def)}and(e){return ge.create(this,e,this._def)}transform(e){return new j({..._(this._def),schema:this,typeName:y.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const n=typeof e=="function"?e:()=>e;return new we({..._(this._def),innerType:this,defaultValue:n,typeName:y.ZodDefault})}brand(){return new Xe({typeName:y.ZodBranded,type:this,..._(this._def)})}catch(e){const n=typeof e=="function"?e:()=>e;return new Te({..._(this._def),innerType:this,catchValue:n,typeName:y.ZodCatch})}describe(e){const n=this.constructor;return new n({...this._def,description:e})}pipe(e){return Ce.create(this,e)}readonly(){return Se.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Ot=/^c[^\s-]{8,}$/i,Nt=/^[0-9a-z]+$/,Rt=/^[0-9A-HJKMNP-TV-Z]{26}$/i,$t=/^[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,It=/^[a-z0-9_-]{21}$/i,jt=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Zt=/^[-+]?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)?)??$/,Dt=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Lt="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let qe;const Mt=/^(?:(?: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])$/,Pt=/^(?:(?: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])$/,Vt=/^(([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]))$/,zt=/^(([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])$/,Bt=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Ft=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,ct="((\\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])))",Ut=new RegExp(`^${ct}$`);function dt(t){let e="[0-5]\\d";t.precision?e=`${e}\\.\\d{${t.precision}}`:t.precision==null&&(e=`${e}(\\.\\d+)?`);const n=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${n}`}function qt(t){return new RegExp(`^${dt(t)}$`)}function ut(t){let e=`${ct}T${dt(t)}`;const n=[];return n.push(t.local?"Z?":"Z"),t.offset&&n.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${n.join("|")})`,new RegExp(`^${e}$`)}function Wt(t,e){return!!((e==="v4"||!e)&&Mt.test(t)||(e==="v6"||!e)&&Vt.test(t))}function Qt(t,e){if(!jt.test(t))return!1;try{const[n]=t.split(".");if(!n)return!1;const s=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(n.length+(4-n.length%4)%4,"="),r=JSON.parse(atob(s));return!(typeof r!="object"||r===null||"typ"in r&&r?.typ!=="JWT"||!r.alg||e&&r.alg!==e)}catch{return!1}}function Ht(t,e){return!!((e==="v4"||!e)&&Pt.test(t)||(e==="v6"||!e)&&zt.test(t))}class $ extends v{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==f.string){const a=this._getOrReturnCtx(e);return l(a,{code:u.invalid_type,expected:f.string,received:a.parsedType}),m}const s=new E;let r;for(const a of this._def.checks)if(a.kind==="min")e.data.length<a.value&&(r=this._getOrReturnCtx(e,r),l(r,{code:u.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),s.dirty());else if(a.kind==="max")e.data.length>a.value&&(r=this._getOrReturnCtx(e,r),l(r,{code:u.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),s.dirty());else if(a.kind==="length"){const i=e.data.length>a.value,o=e.data.length<a.value;(i||o)&&(r=this._getOrReturnCtx(e,r),i?l(r,{code:u.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}):o&&l(r,{code:u.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}),s.dirty())}else if(a.kind==="email")Dt.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"email",code:u.invalid_string,message:a.message}),s.dirty());else if(a.kind==="emoji")qe||(qe=new RegExp(Lt,"u")),qe.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"emoji",code:u.invalid_string,message:a.message}),s.dirty());else if(a.kind==="uuid")$t.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"uuid",code:u.invalid_string,message:a.message}),s.dirty());else if(a.kind==="nanoid")It.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"nanoid",code:u.invalid_string,message:a.message}),s.dirty());else if(a.kind==="cuid")Ot.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"cuid",code:u.invalid_string,message:a.message}),s.dirty());else if(a.kind==="cuid2")Nt.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"cuid2",code:u.invalid_string,message:a.message}),s.dirty());else if(a.kind==="ulid")Rt.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"ulid",code:u.invalid_string,message:a.message}),s.dirty());else if(a.kind==="url")try{new URL(e.data)}catch{r=this._getOrReturnCtx(e,r),l(r,{validation:"url",code:u.invalid_string,message:a.message}),s.dirty()}else a.kind==="regex"?(a.regex.lastIndex=0,a.regex.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"regex",code:u.invalid_string,message:a.message}),s.dirty())):a.kind==="trim"?e.data=e.data.trim():a.kind==="includes"?e.data.includes(a.value,a.position)||(r=this._getOrReturnCtx(e,r),l(r,{code:u.invalid_string,validation:{includes:a.value,position:a.position},message:a.message}),s.dirty()):a.kind==="toLowerCase"?e.data=e.data.toLowerCase():a.kind==="toUpperCase"?e.data=e.data.toUpperCase():a.kind==="startsWith"?e.data.startsWith(a.value)||(r=this._getOrReturnCtx(e,r),l(r,{code:u.invalid_string,validation:{startsWith:a.value},message:a.message}),s.dirty()):a.kind==="endsWith"?e.data.endsWith(a.value)||(r=this._getOrReturnCtx(e,r),l(r,{code:u.invalid_string,validation:{endsWith:a.value},message:a.message}),s.dirty()):a.kind==="datetime"?ut(a).test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{code:u.invalid_string,validation:"datetime",message:a.message}),s.dirty()):a.kind==="date"?Ut.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{code:u.invalid_string,validation:"date",message:a.message}),s.dirty()):a.kind==="time"?qt(a).test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{code:u.invalid_string,validation:"time",message:a.message}),s.dirty()):a.kind==="duration"?Zt.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"duration",code:u.invalid_string,message:a.message}),s.dirty()):a.kind==="ip"?Wt(e.data,a.version)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"ip",code:u.invalid_string,message:a.message}),s.dirty()):a.kind==="jwt"?Qt(e.data,a.alg)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"jwt",code:u.invalid_string,message:a.message}),s.dirty()):a.kind==="cidr"?Ht(e.data,a.version)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"cidr",code:u.invalid_string,message:a.message}),s.dirty()):a.kind==="base64"?Bt.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"base64",code:u.invalid_string,message:a.message}),s.dirty()):a.kind==="base64url"?Ft.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"base64url",code:u.invalid_string,message:a.message}),s.dirty()):b.assertNever(a);return{status:s.value,value:e.data}}_regex(e,n,s){return this.refinement(r=>e.test(r),{validation:n,code:u.invalid_string,...p.errToObj(s)})}_addCheck(e){return new $({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...p.errToObj(e)})}url(e){return this._addCheck({kind:"url",...p.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...p.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...p.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...p.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...p.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...p.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...p.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...p.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...p.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...p.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...p.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...p.errToObj(e)})}datetime(e){return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof e?.precision>"u"?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...p.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof e?.precision>"u"?null:e?.precision,...p.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...p.errToObj(e)})}regex(e,n){return this._addCheck({kind:"regex",regex:e,...p.errToObj(n)})}includes(e,n){return this._addCheck({kind:"includes",value:e,position:n?.position,...p.errToObj(n?.message)})}startsWith(e,n){return this._addCheck({kind:"startsWith",value:e,...p.errToObj(n)})}endsWith(e,n){return this._addCheck({kind:"endsWith",value:e,...p.errToObj(n)})}min(e,n){return this._addCheck({kind:"min",value:e,...p.errToObj(n)})}max(e,n){return this._addCheck({kind:"max",value:e,...p.errToObj(n)})}length(e,n){return this._addCheck({kind:"length",value:e,...p.errToObj(n)})}nonempty(e){return this.min(1,p.errToObj(e))}trim(){return new $({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new $({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new $({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxLength(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}}$.create=t=>new $({checks:[],typeName:y.ZodString,coerce:t?.coerce??!1,..._(t)});function Jt(t,e){const n=(t.toString().split(".")[1]||"").length,s=(e.toString().split(".")[1]||"").length,r=n>s?n:s,a=Number.parseInt(t.toFixed(r).replace(".","")),i=Number.parseInt(e.toFixed(r).replace(".",""));return a%i/10**r}class W extends v{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==f.number){const a=this._getOrReturnCtx(e);return l(a,{code:u.invalid_type,expected:f.number,received:a.parsedType}),m}let s;const r=new E;for(const a of this._def.checks)a.kind==="int"?b.isInteger(e.data)||(s=this._getOrReturnCtx(e,s),l(s,{code:u.invalid_type,expected:"integer",received:"float",message:a.message}),r.dirty()):a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(s=this._getOrReturnCtx(e,s),l(s,{code:u.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),r.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(s=this._getOrReturnCtx(e,s),l(s,{code:u.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),r.dirty()):a.kind==="multipleOf"?Jt(e.data,a.value)!==0&&(s=this._getOrReturnCtx(e,s),l(s,{code:u.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):a.kind==="finite"?Number.isFinite(e.data)||(s=this._getOrReturnCtx(e,s),l(s,{code:u.not_finite,message:a.message}),r.dirty()):b.assertNever(a);return{status:r.value,value:e.data}}gte(e,n){return this.setLimit("min",e,!0,p.toString(n))}gt(e,n){return this.setLimit("min",e,!1,p.toString(n))}lte(e,n){return this.setLimit("max",e,!0,p.toString(n))}lt(e,n){return this.setLimit("max",e,!1,p.toString(n))}setLimit(e,n,s,r){return new W({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:s,message:p.toString(r)}]})}_addCheck(e){return new W({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:p.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:p.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:p.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:p.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:p.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:p.toString(n)})}finite(e){return this._addCheck({kind:"finite",message:p.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:p.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:p.toString(e)})}get minValue(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&b.isInteger(e.value))}get isFinite(){let e=null,n=null;for(const s of this._def.checks){if(s.kind==="finite"||s.kind==="int"||s.kind==="multipleOf")return!0;s.kind==="min"?(n===null||s.value>n)&&(n=s.value):s.kind==="max"&&(e===null||s.value<e)&&(e=s.value)}return Number.isFinite(n)&&Number.isFinite(e)}}W.create=t=>new W({checks:[],typeName:y.ZodNumber,coerce:t?.coerce||!1,..._(t)});class Q extends v{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==f.bigint)return this._getInvalidInput(e);let s;const r=new E;for(const a of this._def.checks)a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(s=this._getOrReturnCtx(e,s),l(s,{code:u.too_small,type:"bigint",minimum:a.value,inclusive:a.inclusive,message:a.message}),r.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(s=this._getOrReturnCtx(e,s),l(s,{code:u.too_big,type:"bigint",maximum:a.value,inclusive:a.inclusive,message:a.message}),r.dirty()):a.kind==="multipleOf"?e.data%a.value!==BigInt(0)&&(s=this._getOrReturnCtx(e,s),l(s,{code:u.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):b.assertNever(a);return{status:r.value,value:e.data}}_getInvalidInput(e){const n=this._getOrReturnCtx(e);return l(n,{code:u.invalid_type,expected:f.bigint,received:n.parsedType}),m}gte(e,n){return this.setLimit("min",e,!0,p.toString(n))}gt(e,n){return this.setLimit("min",e,!1,p.toString(n))}lte(e,n){return this.setLimit("max",e,!0,p.toString(n))}lt(e,n){return this.setLimit("max",e,!1,p.toString(n))}setLimit(e,n,s,r){return new Q({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:s,message:p.toString(r)}]})}_addCheck(e){return new Q({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:p.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:p.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:p.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:p.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:p.toString(n)})}get minValue(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}}Q.create=t=>new Q({checks:[],typeName:y.ZodBigInt,coerce:t?.coerce??!1,..._(t)});class pe extends v{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==f.boolean){const s=this._getOrReturnCtx(e);return l(s,{code:u.invalid_type,expected:f.boolean,received:s.parsedType}),m}return C(e.data)}}pe.create=t=>new pe({typeName:y.ZodBoolean,coerce:t?.coerce||!1,..._(t)});class te extends v{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==f.date){const a=this._getOrReturnCtx(e);return l(a,{code:u.invalid_type,expected:f.date,received:a.parsedType}),m}if(Number.isNaN(e.data.getTime())){const a=this._getOrReturnCtx(e);return l(a,{code:u.invalid_date}),m}const s=new E;let r;for(const a of this._def.checks)a.kind==="min"?e.data.getTime()<a.value&&(r=this._getOrReturnCtx(e,r),l(r,{code:u.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),s.dirty()):a.kind==="max"?e.data.getTime()>a.value&&(r=this._getOrReturnCtx(e,r),l(r,{code:u.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),s.dirty()):b.assertNever(a);return{status:s.value,value:new Date(e.data.getTime())}}_addCheck(e){return new te({...this._def,checks:[...this._def.checks,e]})}min(e,n){return this._addCheck({kind:"min",value:e.getTime(),message:p.toString(n)})}max(e,n){return this._addCheck({kind:"max",value:e.getTime(),message:p.toString(n)})}get minDate(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e!=null?new Date(e):null}}te.create=t=>new te({checks:[],coerce:t?.coerce||!1,typeName:y.ZodDate,..._(t)});class $e extends v{_parse(e){if(this._getType(e)!==f.symbol){const s=this._getOrReturnCtx(e);return l(s,{code:u.invalid_type,expected:f.symbol,received:s.parsedType}),m}return C(e.data)}}$e.create=t=>new $e({typeName:y.ZodSymbol,..._(t)});class me extends v{_parse(e){if(this._getType(e)!==f.undefined){const s=this._getOrReturnCtx(e);return l(s,{code:u.invalid_type,expected:f.undefined,received:s.parsedType}),m}return C(e.data)}}me.create=t=>new me({typeName:y.ZodUndefined,..._(t)});class ye extends v{_parse(e){if(this._getType(e)!==f.null){const s=this._getOrReturnCtx(e);return l(s,{code:u.invalid_type,expected:f.null,received:s.parsedType}),m}return C(e.data)}}ye.create=t=>new ye({typeName:y.ZodNull,..._(t)});class ce extends v{constructor(){super(...arguments),this._any=!0}_parse(e){return C(e.data)}}ce.create=t=>new ce({typeName:y.ZodAny,..._(t)});class X extends v{constructor(){super(...arguments),this._unknown=!0}_parse(e){return C(e.data)}}X.create=t=>new X({typeName:y.ZodUnknown,..._(t)});class U extends v{_parse(e){const n=this._getOrReturnCtx(e);return l(n,{code:u.invalid_type,expected:f.never,received:n.parsedType}),m}}U.create=t=>new U({typeName:y.ZodNever,..._(t)});class Ie extends v{_parse(e){if(this._getType(e)!==f.undefined){const s=this._getOrReturnCtx(e);return l(s,{code:u.invalid_type,expected:f.void,received:s.parsedType}),m}return C(e.data)}}Ie.create=t=>new Ie({typeName:y.ZodVoid,..._(t)});class I extends v{_parse(e){const{ctx:n,status:s}=this._processInputParams(e),r=this._def;if(n.parsedType!==f.array)return l(n,{code:u.invalid_type,expected:f.array,received:n.parsedType}),m;if(r.exactLength!==null){const i=n.data.length>r.exactLength.value,o=n.data.length<r.exactLength.value;(i||o)&&(l(n,{code:i?u.too_big:u.too_small,minimum:o?r.exactLength.value:void 0,maximum:i?r.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:r.exactLength.message}),s.dirty())}if(r.minLength!==null&&n.data.length<r.minLength.value&&(l(n,{code:u.too_small,minimum:r.minLength.value,type:"array",inclusive:!0,exact:!1,message:r.minLength.message}),s.dirty()),r.maxLength!==null&&n.data.length>r.maxLength.value&&(l(n,{code:u.too_big,maximum:r.maxLength.value,type:"array",inclusive:!0,exact:!1,message:r.maxLength.message}),s.dirty()),n.common.async)return Promise.all([...n.data].map((i,o)=>r.type._parseAsync(new M(n,i,n.path,o)))).then(i=>E.mergeArray(s,i));const a=[...n.data].map((i,o)=>r.type._parseSync(new M(n,i,n.path,o)));return E.mergeArray(s,a)}get element(){return this._def.type}min(e,n){return new I({...this._def,minLength:{value:e,message:p.toString(n)}})}max(e,n){return new I({...this._def,maxLength:{value:e,message:p.toString(n)}})}length(e,n){return new I({...this._def,exactLength:{value:e,message:p.toString(n)}})}nonempty(e){return this.min(1,e)}}I.create=(t,e)=>new I({type:t,minLength:null,maxLength:null,exactLength:null,typeName:y.ZodArray,..._(e)});function re(t){if(t instanceof T){const e={};for(const n in t.shape){const s=t.shape[n];e[n]=L.create(re(s))}return new T({...t._def,shape:()=>e})}else return t instanceof I?new I({...t._def,type:re(t.element)}):t instanceof L?L.create(re(t.unwrap())):t instanceof J?J.create(re(t.unwrap())):t instanceof P?P.create(t.items.map(e=>re(e))):t}class T extends v{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),n=b.objectKeys(e);return this._cached={shape:e,keys:n},this._cached}_parse(e){if(this._getType(e)!==f.object){const d=this._getOrReturnCtx(e);return l(d,{code:u.invalid_type,expected:f.object,received:d.parsedType}),m}const{status:s,ctx:r}=this._processInputParams(e),{shape:a,keys:i}=this._getCached(),o=[];if(!(this._def.catchall instanceof U&&this._def.unknownKeys==="strip"))for(const d in r.data)i.includes(d)||o.push(d);const c=[];for(const d of i){const h=a[d],x=r.data[d];c.push({key:{status:"valid",value:d},value:h._parse(new M(r,x,r.path,d)),alwaysSet:d in r.data})}if(this._def.catchall instanceof U){const d=this._def.unknownKeys;if(d==="passthrough")for(const h of o)c.push({key:{status:"valid",value:h},value:{status:"valid",value:r.data[h]}});else if(d==="strict")o.length>0&&(l(r,{code:u.unrecognized_keys,keys:o}),s.dirty());else if(d!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const d=this._def.catchall;for(const h of o){const x=r.data[h];c.push({key:{status:"valid",value:h},value:d._parse(new M(r,x,r.path,h)),alwaysSet:h in r.data})}}return r.common.async?Promise.resolve().then(async()=>{const d=[];for(const h of c){const x=await h.key,S=await h.value;d.push({key:x,value:S,alwaysSet:h.alwaysSet})}return d}).then(d=>E.mergeObjectSync(s,d)):E.mergeObjectSync(s,c)}get shape(){return this._def.shape()}strict(e){return p.errToObj,new T({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(n,s)=>{const r=this._def.errorMap?.(n,s).message??s.defaultError;return n.code==="unrecognized_keys"?{message:p.errToObj(e).message??r}:{message:r}}}:{}})}strip(){return new T({...this._def,unknownKeys:"strip"})}passthrough(){return new T({...this._def,unknownKeys:"passthrough"})}extend(e){return new T({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new T({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:y.ZodObject})}setKey(e,n){return this.augment({[e]:n})}catchall(e){return new T({...this._def,catchall:e})}pick(e){const n={};for(const s of b.objectKeys(e))e[s]&&this.shape[s]&&(n[s]=this.shape[s]);return new T({...this._def,shape:()=>n})}omit(e){const n={};for(const s of b.objectKeys(this.shape))e[s]||(n[s]=this.shape[s]);return new T({...this._def,shape:()=>n})}deepPartial(){return re(this)}partial(e){const n={};for(const s of b.objectKeys(this.shape)){const r=this.shape[s];e&&!e[s]?n[s]=r:n[s]=r.optional()}return new T({...this._def,shape:()=>n})}required(e){const n={};for(const s of b.objectKeys(this.shape))if(e&&!e[s])n[s]=this.shape[s];else{let a=this.shape[s];for(;a instanceof L;)a=a._def.innerType;n[s]=a}return new T({...this._def,shape:()=>n})}keyof(){return lt(b.objectKeys(this.shape))}}T.create=(t,e)=>new T({shape:()=>t,unknownKeys:"strip",catchall:U.create(),typeName:y.ZodObject,..._(e)});T.strictCreate=(t,e)=>new T({shape:()=>t,unknownKeys:"strict",catchall:U.create(),typeName:y.ZodObject,..._(e)});T.lazycreate=(t,e)=>new T({shape:t,unknownKeys:"strip",catchall:U.create(),typeName:y.ZodObject,..._(e)});class _e extends v{_parse(e){const{ctx:n}=this._processInputParams(e),s=this._def.options;function r(a){for(const o of a)if(o.result.status==="valid")return o.result;for(const o of a)if(o.result.status==="dirty")return n.common.issues.push(...o.ctx.common.issues),o.result;const i=a.map(o=>new N(o.ctx.common.issues));return l(n,{code:u.invalid_union,unionErrors:i}),m}if(n.common.async)return Promise.all(s.map(async a=>{const i={...n,common:{...n.common,issues:[]},parent:null};return{result:await a._parseAsync({data:n.data,path:n.path,parent:i}),ctx:i}})).then(r);{let a;const i=[];for(const c of s){const d={...n,common:{...n.common,issues:[]},parent:null},h=c._parseSync({data:n.data,path:n.path,parent:d});if(h.status==="valid")return h;h.status==="dirty"&&!a&&(a={result:h,ctx:d}),d.common.issues.length&&i.push(d.common.issues)}if(a)return n.common.issues.push(...a.ctx.common.issues),a.result;const o=i.map(c=>new N(c));return l(n,{code:u.invalid_union,unionErrors:o}),m}}get options(){return this._def.options}}_e.create=(t,e)=>new _e({options:t,typeName:y.ZodUnion,..._(e)});const z=t=>t instanceof be?z(t.schema):t instanceof j?z(t.innerType()):t instanceof xe?[t.value]:t instanceof H?t.options:t instanceof ke?b.objectValues(t.enum):t instanceof we?z(t._def.innerType):t instanceof me?[void 0]:t instanceof ye?[null]:t instanceof L?[void 0,...z(t.unwrap())]:t instanceof J?[null,...z(t.unwrap())]:t instanceof Xe||t instanceof Se?z(t.unwrap()):t instanceof Te?z(t._def.innerType):[];class Me extends v{_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==f.object)return l(n,{code:u.invalid_type,expected:f.object,received:n.parsedType}),m;const s=this.discriminator,r=n.data[s],a=this.optionsMap.get(r);return a?n.common.async?a._parseAsync({data:n.data,path:n.path,parent:n}):a._parseSync({data:n.data,path:n.path,parent:n}):(l(n,{code:u.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[s]}),m)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,n,s){const r=new Map;for(const a of n){const i=z(a.shape[e]);if(!i.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const o of i){if(r.has(o))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(o)}`);r.set(o,a)}}return new Me({typeName:y.ZodDiscriminatedUnion,discriminator:e,options:n,optionsMap:r,..._(s)})}}function Ye(t,e){const n=B(t),s=B(e);if(t===e)return{valid:!0,data:t};if(n===f.object&&s===f.object){const r=b.objectKeys(e),a=b.objectKeys(t).filter(o=>r.indexOf(o)!==-1),i={...t,...e};for(const o of a){const c=Ye(t[o],e[o]);if(!c.valid)return{valid:!1};i[o]=c.data}return{valid:!0,data:i}}else if(n===f.array&&s===f.array){if(t.length!==e.length)return{valid:!1};const r=[];for(let a=0;a<t.length;a++){const i=t[a],o=e[a],c=Ye(i,o);if(!c.valid)return{valid:!1};r.push(c.data)}return{valid:!0,data:r}}else return n===f.date&&s===f.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}class ge extends v{_parse(e){const{status:n,ctx:s}=this._processInputParams(e),r=(a,i)=>{if(He(a)||He(i))return m;const o=Ye(a.value,i.value);return o.valid?((Je(a)||Je(i))&&n.dirty(),{status:n.value,value:o.data}):(l(s,{code:u.invalid_intersection_types}),m)};return s.common.async?Promise.all([this._def.left._parseAsync({data:s.data,path:s.path,parent:s}),this._def.right._parseAsync({data:s.data,path:s.path,parent:s})]).then(([a,i])=>r(a,i)):r(this._def.left._parseSync({data:s.data,path:s.path,parent:s}),this._def.right._parseSync({data:s.data,path:s.path,parent:s}))}}ge.create=(t,e,n)=>new ge({left:t,right:e,typeName:y.ZodIntersection,..._(n)});class P extends v{_parse(e){const{status:n,ctx:s}=this._processInputParams(e);if(s.parsedType!==f.array)return l(s,{code:u.invalid_type,expected:f.array,received:s.parsedType}),m;if(s.data.length<this._def.items.length)return l(s,{code:u.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),m;!this._def.rest&&s.data.length>this._def.items.length&&(l(s,{code:u.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const a=[...s.data].map((i,o)=>{const c=this._def.items[o]||this._def.rest;return c?c._parse(new M(s,i,s.path,o)):null}).filter(i=>!!i);return s.common.async?Promise.all(a).then(i=>E.mergeArray(n,i)):E.mergeArray(n,a)}get items(){return this._def.items}rest(e){return new P({...this._def,rest:e})}}P.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new P({items:t,typeName:y.ZodTuple,rest:null,..._(e)})};class ve extends v{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:n,ctx:s}=this._processInputParams(e);if(s.parsedType!==f.object)return l(s,{code:u.invalid_type,expected:f.object,received:s.parsedType}),m;const r=[],a=this._def.keyType,i=this._def.valueType;for(const o in s.data)r.push({key:a._parse(new M(s,o,s.path,o)),value:i._parse(new M(s,s.data[o],s.path,o)),alwaysSet:o in s.data});return s.common.async?E.mergeObjectAsync(n,r):E.mergeObjectSync(n,r)}get element(){return this._def.valueType}static create(e,n,s){return n instanceof v?new ve({keyType:e,valueType:n,typeName:y.ZodRecord,..._(s)}):new ve({keyType:$.create(),valueType:e,typeName:y.ZodRecord,..._(n)})}}class je extends v{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:n,ctx:s}=this._processInputParams(e);if(s.parsedType!==f.map)return l(s,{code:u.invalid_type,expected:f.map,received:s.parsedType}),m;const r=this._def.keyType,a=this._def.valueType,i=[...s.data.entries()].map(([o,c],d)=>({key:r._parse(new M(s,o,s.path,[d,"key"])),value:a._parse(new M(s,c,s.path,[d,"value"]))}));if(s.common.async){const o=new Map;return Promise.resolve().then(async()=>{for(const c of i){const d=await c.key,h=await c.value;if(d.status==="aborted"||h.status==="aborted")return m;(d.status==="dirty"||h.status==="dirty")&&n.dirty(),o.set(d.value,h.value)}return{status:n.value,value:o}})}else{const o=new Map;for(const c of i){const d=c.key,h=c.value;if(d.status==="aborted"||h.status==="aborted")return m;(d.status==="dirty"||h.status==="dirty")&&n.dirty(),o.set(d.value,h.value)}return{status:n.value,value:o}}}}je.create=(t,e,n)=>new je({valueType:e,keyType:t,typeName:y.ZodMap,..._(n)});class ne extends v{_parse(e){const{status:n,ctx:s}=this._processInputParams(e);if(s.parsedType!==f.set)return l(s,{code:u.invalid_type,expected:f.set,received:s.parsedType}),m;const r=this._def;r.minSize!==null&&s.data.size<r.minSize.value&&(l(s,{code:u.too_small,minimum:r.minSize.value,type:"set",inclusive:!0,exact:!1,message:r.minSize.message}),n.dirty()),r.maxSize!==null&&s.data.size>r.maxSize.value&&(l(s,{code:u.too_big,maximum:r.maxSize.value,type:"set",inclusive:!0,exact:!1,message:r.maxSize.message}),n.dirty());const a=this._def.valueType;function i(c){const d=new Set;for(const h of c){if(h.status==="aborted")return m;h.status==="dirty"&&n.dirty(),d.add(h.value)}return{status:n.value,value:d}}const o=[...s.data.values()].map((c,d)=>a._parse(new M(s,c,s.path,d)));return s.common.async?Promise.all(o).then(c=>i(c)):i(o)}min(e,n){return new ne({...this._def,minSize:{value:e,message:p.toString(n)}})}max(e,n){return new ne({...this._def,maxSize:{value:e,message:p.toString(n)}})}size(e,n){return this.min(e,n).max(e,n)}nonempty(e){return this.min(1,e)}}ne.create=(t,e)=>new ne({valueType:t,minSize:null,maxSize:null,typeName:y.ZodSet,..._(e)});class ie extends v{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==f.function)return l(n,{code:u.invalid_type,expected:f.function,received:n.parsedType}),m;function s(o,c){return Re({data:o,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,Ne(),oe].filter(d=>!!d),issueData:{code:u.invalid_arguments,argumentsError:c}})}function r(o,c){return Re({data:o,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,Ne(),oe].filter(d=>!!d),issueData:{code:u.invalid_return_type,returnTypeError:c}})}const a={errorMap:n.common.contextualErrorMap},i=n.data;if(this._def.returns instanceof de){const o=this;return C(async function(...c){const d=new N([]),h=await o._def.args.parseAsync(c,a).catch(w=>{throw d.addIssue(s(c,w)),d}),x=await Reflect.apply(i,this,h);return await o._def.returns._def.type.parseAsync(x,a).catch(w=>{throw d.addIssue(r(x,w)),d})})}else{const o=this;return C(function(...c){const d=o._def.args.safeParse(c,a);if(!d.success)throw new N([s(c,d.error)]);const h=Reflect.apply(i,this,d.data),x=o._def.returns.safeParse(h,a);if(!x.success)throw new N([r(h,x.error)]);return x.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new ie({...this._def,args:P.create(e).rest(X.create())})}returns(e){return new ie({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,n,s){return new ie({args:e||P.create([]).rest(X.create()),returns:n||X.create(),typeName:y.ZodFunction,..._(s)})}}class be extends v{get schema(){return this._def.getter()}_parse(e){const{ctx:n}=this._processInputParams(e);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}}be.create=(t,e)=>new be({getter:t,typeName:y.ZodLazy,..._(e)});class xe extends v{_parse(e){if(e.data!==this._def.value){const n=this._getOrReturnCtx(e);return l(n,{received:n.data,code:u.invalid_literal,expected:this._def.value}),m}return{status:"valid",value:e.data}}get value(){return this._def.value}}xe.create=(t,e)=>new xe({value:t,typeName:y.ZodLiteral,..._(e)});function lt(t,e){return new H({values:t,typeName:y.ZodEnum,..._(e)})}class H extends v{_parse(e){if(typeof e.data!="string"){const n=this._getOrReturnCtx(e),s=this._def.values;return l(n,{expected:b.joinValues(s),received:n.parsedType,code:u.invalid_type}),m}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){const n=this._getOrReturnCtx(e),s=this._def.values;return l(n,{received:n.data,code:u.invalid_enum_value,options:s}),m}return C(e.data)}get options(){return this._def.values}get enum(){const e={};for(const n of this._def.values)e[n]=n;return e}get Values(){const e={};for(const n of this._def.values)e[n]=n;return e}get Enum(){const e={};for(const n of this._def.values)e[n]=n;return e}extract(e,n=this._def){return H.create(e,{...this._def,...n})}exclude(e,n=this._def){return H.create(this.options.filter(s=>!e.includes(s)),{...this._def,...n})}}H.create=lt;class ke extends v{_parse(e){const n=b.getValidEnumValues(this._def.values),s=this._getOrReturnCtx(e);if(s.parsedType!==f.string&&s.parsedType!==f.number){const r=b.objectValues(n);return l(s,{expected:b.joinValues(r),received:s.parsedType,code:u.invalid_type}),m}if(this._cache||(this._cache=new Set(b.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){const r=b.objectValues(n);return l(s,{received:s.data,code:u.invalid_enum_value,options:r}),m}return C(e.data)}get enum(){return this._def.values}}ke.create=(t,e)=>new ke({values:t,typeName:y.ZodNativeEnum,..._(e)});class de extends v{unwrap(){return this._def.type}_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==f.promise&&n.common.async===!1)return l(n,{code:u.invalid_type,expected:f.promise,received:n.parsedType}),m;const s=n.parsedType===f.promise?n.data:Promise.resolve(n.data);return C(s.then(r=>this._def.type.parseAsync(r,{path:n.path,errorMap:n.common.contextualErrorMap})))}}de.create=(t,e)=>new de({type:t,typeName:y.ZodPromise,..._(e)});class j extends v{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===y.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:n,ctx:s}=this._processInputParams(e),r=this._def.effect||null,a={addIssue:i=>{l(s,i),i.fatal?n.abort():n.dirty()},get path(){return s.path}};if(a.addIssue=a.addIssue.bind(a),r.type==="preprocess"){const i=r.transform(s.data,a);if(s.common.async)return Promise.resolve(i).then(async o=>{if(n.value==="aborted")return m;const c=await this._def.schema._parseAsync({data:o,path:s.path,parent:s});return c.status==="aborted"?m:c.status==="dirty"||n.value==="dirty"?ae(c.value):c});{if(n.value==="aborted")return m;const o=this._def.schema._parseSync({data:i,path:s.path,parent:s});return o.status==="aborted"?m:o.status==="dirty"||n.value==="dirty"?ae(o.value):o}}if(r.type==="refinement"){const i=o=>{const c=r.refinement(o,a);if(s.common.async)return Promise.resolve(c);if(c instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return o};if(s.common.async===!1){const o=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});return o.status==="aborted"?m:(o.status==="dirty"&&n.dirty(),i(o.value),{status:n.value,value:o.value})}else return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then(o=>o.status==="aborted"?m:(o.status==="dirty"&&n.dirty(),i(o.value).then(()=>({status:n.value,value:o.value}))))}if(r.type==="transform")if(s.common.async===!1){const i=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});if(!ee(i))return m;const o=r.transform(i.value,a);if(o instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:o}}else return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then(i=>ee(i)?Promise.resolve(r.transform(i.value,a)).then(o=>({status:n.value,value:o})):m);b.assertNever(r)}}j.create=(t,e,n)=>new j({schema:t,typeName:y.ZodEffects,effect:e,..._(n)});j.createWithPreprocess=(t,e,n)=>new j({schema:e,effect:{type:"preprocess",transform:t},typeName:y.ZodEffects,..._(n)});class L extends v{_parse(e){return this._getType(e)===f.undefined?C(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}L.create=(t,e)=>new L({innerType:t,typeName:y.ZodOptional,..._(e)});class J extends v{_parse(e){return this._getType(e)===f.null?C(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}J.create=(t,e)=>new J({innerType:t,typeName:y.ZodNullable,..._(e)});class we extends v{_parse(e){const{ctx:n}=this._processInputParams(e);let s=n.data;return n.parsedType===f.undefined&&(s=this._def.defaultValue()),this._def.innerType._parse({data:s,path:n.path,parent:n})}removeDefault(){return this._def.innerType}}we.create=(t,e)=>new we({innerType:t,typeName:y.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,..._(e)});class Te extends v{_parse(e){const{ctx:n}=this._processInputParams(e),s={...n,common:{...n.common,issues:[]}},r=this._def.innerType._parse({data:s.data,path:s.path,parent:{...s}});return he(r)?r.then(a=>({status:"valid",value:a.status==="valid"?a.value:this._def.catchValue({get error(){return new N(s.common.issues)},input:s.data})})):{status:"valid",value:r.status==="valid"?r.value:this._def.catchValue({get error(){return new N(s.common.issues)},input:s.data})}}removeCatch(){return this._def.innerType}}Te.create=(t,e)=>new Te({innerType:t,typeName:y.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,..._(e)});class Ze extends v{_parse(e){if(this._getType(e)!==f.nan){const s=this._getOrReturnCtx(e);return l(s,{code:u.invalid_type,expected:f.nan,received:s.parsedType}),m}return{status:"valid",value:e.data}}}Ze.create=t=>new Ze({typeName:y.ZodNaN,..._(t)});const Yt=Symbol("zod_brand");class Xe extends v{_parse(e){const{ctx:n}=this._processInputParams(e),s=n.data;return this._def.type._parse({data:s,path:n.path,parent:n})}unwrap(){return this._def.type}}class Ce extends v{_parse(e){const{status:n,ctx:s}=this._processInputParams(e);if(s.common.async)return(async()=>{const a=await this._def.in._parseAsync({data:s.data,path:s.path,parent:s});return a.status==="aborted"?m:a.status==="dirty"?(n.dirty(),ae(a.value)):this._def.out._parseAsync({data:a.value,path:s.path,parent:s})})();{const r=this._def.in._parseSync({data:s.data,path:s.path,parent:s});return r.status==="aborted"?m:r.status==="dirty"?(n.dirty(),{status:"dirty",value:r.value}):this._def.out._parseSync({data:r.value,path:s.path,parent:s})}}static create(e,n){return new Ce({in:e,out:n,typeName:y.ZodPipeline})}}class Se extends v{_parse(e){const n=this._def.innerType._parse(e),s=r=>(ee(r)&&(r.value=Object.freeze(r.value)),r);return he(n)?n.then(r=>s(r)):s(n)}unwrap(){return this._def.innerType}}Se.create=(t,e)=>new Se({innerType:t,typeName:y.ZodReadonly,..._(e)});function nt(t,e){const n=typeof t=="function"?t(e):typeof t=="string"?{message:t}:t;return typeof n=="string"?{message:n}:n}function ft(t,e={},n){return t?ce.create().superRefine((s,r)=>{const a=t(s);if(a instanceof Promise)return a.then(i=>{if(!i){const o=nt(e,s),c=o.fatal??n??!0;r.addIssue({code:"custom",...o,fatal:c})}});if(!a){const i=nt(e,s),o=i.fatal??n??!0;r.addIssue({code:"custom",...i,fatal:o})}}):ce.create()}const Kt={object:T.lazycreate};var y;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(y||(y={}));const Gt=(t,e={message:`Input not instance of ${t.name}`})=>ft(n=>n instanceof t,e),g=$.create,et=W.create,Xt=Ze.create,en=Q.create,Ae=pe.create,tn=te.create,nn=$e.create,sn=me.create,rn=ye.create,an=ce.create,on=X.create,cn=U.create,dn=Ie.create,R=I.create,Z=T.create,un=T.strictCreate,ln=_e.create,fn=Me.create,hn=ge.create,pn=P.create,ht=ve.create,mn=je.create,yn=ne.create,_n=ie.create,gn=be.create,vn=xe.create,bn=H.create,xn=ke.create,kn=de.create,st=j.create,wn=L.create,Tn=J.create,Sn=j.createWithPreprocess,En=Ce.create,Cn=()=>g().optional(),An=()=>et().optional(),On=()=>Ae().optional(),Nn={string:(t=>$.create({...t,coerce:!0})),number:(t=>W.create({...t,coerce:!0})),boolean:(t=>pe.create({...t,coerce:!0})),bigint:(t=>Q.create({...t,coerce:!0})),date:(t=>te.create({...t,coerce:!0}))},Rn=m,$n=Object.freeze(Object.defineProperty({__proto__:null,BRAND:Yt,DIRTY:ae,EMPTY_PATH:At,INVALID:m,NEVER:Rn,OK:C,ParseStatus:E,Schema:v,ZodAny:ce,ZodArray:I,ZodBigInt:Q,ZodBoolean:pe,ZodBranded:Xe,ZodCatch:Te,ZodDate:te,ZodDefault:we,ZodDiscriminatedUnion:Me,ZodEffects:j,ZodEnum:H,ZodError:N,get ZodFirstPartyTypeKind(){return y},ZodFunction:ie,ZodIntersection:ge,ZodIssueCode:u,ZodLazy:be,ZodLiteral:xe,ZodMap:je,ZodNaN:Ze,ZodNativeEnum:ke,ZodNever:U,ZodNull:ye,ZodNullable:J,ZodNumber:W,ZodObject:T,ZodOptional:L,ZodParsedType:f,ZodPipeline:Ce,ZodPromise:de,ZodReadonly:Se,ZodRecord:ve,ZodSchema:v,ZodSet:ne,ZodString:$,ZodSymbol:$e,ZodTransformer:j,ZodTuple:P,ZodType:v,ZodUndefined:me,ZodUnion:_e,ZodUnknown:X,ZodVoid:Ie,addIssueToContext:l,any:an,array:R,bigint:en,boolean:Ae,coerce:Nn,custom:ft,date:tn,datetimeRegex:ut,defaultErrorMap:oe,discriminatedUnion:fn,effect:st,enum:bn,function:_n,getErrorMap:Ne,getParsedType:B,instanceof:Gt,intersection:hn,isAborted:He,isAsync:he,isDirty:Je,isValid:ee,late:Kt,lazy:gn,literal:vn,makeIssue:Re,map:mn,nan:Xt,nativeEnum:xn,never:cn,null:rn,nullable:Tn,number:et,object:Z,get objectUtil(){return Qe},oboolean:On,onumber:An,optional:wn,ostring:Cn,pipeline:En,preprocess:Sn,promise:kn,quotelessJson:Et,record:ht,set:yn,setErrorMap:Ct,strictObject:un,string:g,symbol:nn,transformer:st,tuple:pn,undefined:sn,union:ln,unknown:on,get util(){return b},void:dn},Symbol.toStringTag,{value:"Module"}));St($n);const In=(t,e)=>e.skipDedupe||e.method!=="GET",jn=(t,e)=>e.method+"@"+t,Zn=t=>t.clone(),Dn=({skip:t=In,key:e=jn,resolver:n=Zn}={})=>{const s=new Map;return r=>(a,i)=>{if(t(a,i))return r(a,i);const o=e(a,i);if(!s.has(o))s.set(o,[]);else return new Promise((c,d)=>{s.get(o).push([c,d])});try{return r(a,i).then(c=>(s.get(o).forEach(([d])=>d(n(c))),s.delete(o),c)).catch(c=>{throw s.get(o).forEach(([,d])=>d(c)),s.delete(o),c})}catch(c){return s.delete(o),Promise.reject(c)}}},Ln=(t,e)=>t*e,Mn=t=>t&&(t.ok||t.status>=400&&t.status<500),Pn=({delayTimer:t=500,delayRamp:e=Ln,maxAttempts:n=10,until:s=Mn,onRetry:r=null,retryOnNetworkError:a=!1,resolveWithLatestResponse:i=!1,skip:o}={})=>c=>(d,h)=>{let x=0;if(o&&o(d,h))return c(d,h);const S=(w,A)=>Promise.resolve(s(w,A)).then(Y=>Y?w&&i?w:A?Promise.reject(A):w:(x++,!n||x<=n?new Promise(k=>{const V=e(t,x);setTimeout(()=>{typeof r=="function"?Promise.resolve(r({response:w,error:A,url:d,attempt:x,options:h})).then((O={})=>{var D,K;k(c((D=O&&O.url)!==null&&D!==void 0?D:d,(K=O&&O.options)!==null&&K!==void 0?K:h))}):k(c(d,h))},V)}).then(S).catch(k=>{if(!a)throw k;return S(null,k)}):w&&i?w:Promise.reject(A||new Error("Number of attempts exceeded."))));return c(d,h).then(S).catch(w=>{if(!a)throw w;return S(null,w)})},De=Z({code:et(),message:g()}),Vn=Z({message:g()}),zn=Z({emails:R(g()).optional(),http_body:g().optional(),http_url:g().optional(),txt_name:g().optional(),txt_value:g().optional()}),Bn=Z({ciphers:R(g()).optional(),early_hints:g().optional(),http2:g().optional(),min_tls_version:g().optional(),tls_1_3:g().optional()}),Fn=Z({id:g(),bundle_method:g().optional(),certificate_authority:g(),custom_certificate:g().optional(),custom_csr_id:g().optional(),custom_key:g().optional(),expires_on:g().optional(),hosts:R(g()).optional(),issuer:g().optional(),method:g(),serial_number:g().optional(),settings:Bn.optional(),signature:g().optional(),type:g(),uploaded_on:g().optional(),validation_errors:R(Vn).optional(),validation_records:R(zn).optional(),wildcard:Ae()}),Un=Z({name:g(),type:g(),value:g()}),qn=Z({http_body:g().optional(),http_url:g().optional()}),pt=Z({id:g(),ssl:Fn,hostname:g(),custom_metadata:ht(g()).optional(),custom_origin_server:g().optional(),custom_origin_sni:g().optional(),ownership_verification:Un.optional(),ownership_verification_http:qn.optional(),status:g(),verification_errors:R(g()).optional(),created_at:g()}),Oe=Z({errors:R(De),messages:R(De),success:Ae(),result:pt});Z({errors:R(De),messages:R(De),success:Ae(),result:R(pt)});function se(t){return kt(`https://api.cloudflare.com/client/v4/zones/${t.zoneId}`).headers({"X-Auth-Email":t.authEmail,"X-Auth-Key":t.authKey,"Content-Type":"application/json"}).middlewares([Pn(),Dn()])}function We(t){const e=[];if(t.ssl.validation_records)for(const n of t.ssl.validation_records)n.txt_name&&n.txt_value&&e.push({name:"txt",record:n.txt_value,domain:n.txt_name});return t.ownership_verification&&e.push({name:"txt",record:t.ownership_verification.value,domain:t.ownership_verification.name}),{custom_domain_id:t.id,domain:t.hostname,primary:t.primary,status:t.status==="active"?"ready":"pending",type:"auth0_managed_certs",verification:{methods:R(xt.verificationMethodsSchema).parse(e)}}}function Wn(t){return{create:async(e,n)=>{const{result:s,errors:r,success:a}=Oe.parse(await se(t).post({hostname:n.domain,ssl:{method:"txt",type:"dv"},custom_metadata:t.enterprise?{tenant_id:e}:void 0},"/custom_hostnames").json());if(!a)throw new Error(JSON.stringify(r));const i=We({...s,primary:!1});return await t.customDomainAdapter.create(e,{custom_domain_id:i.custom_domain_id,domain:i.domain,type:i.type}),i},get:async(e,n)=>{const s=await t.customDomainAdapter.get(e,n);if(!s)throw new fe(404);const r=await se(t).get(`/custom_hostnames/${encodeURIComponent(n)}`).json(),{result:a,errors:i,success:o}=Oe.parse(r);if(!o)throw new fe(503,{message:JSON.stringify(i)});if(t.enterprise&&a.custom_metadata?.tenant_id!==e)throw new fe(404);return We({...s,...a})},getByDomain:async e=>t.customDomainAdapter.getByDomain(e),list:async e=>{const n=await t.customDomainAdapter.list(e);return(await Promise.all(n.map(async r=>{try{const a=await se(t).get(`/custom_hostnames/${encodeURIComponent(r.custom_domain_id)}`).json(),{result:i,success:o}=Oe.parse(a);return!o||t.enterprise&&i.custom_metadata?.tenant_id!==e?null:We({...r,...i})}catch{return null}}))).filter(r=>r!==null)},remove:async(e,n)=>{if(t.enterprise){const{result:r,success:a}=Oe.parse(await se(t).get(`/custom_hostnames/${encodeURIComponent(n)}`).json());if(!a||r.custom_metadata?.tenant_id!==e)throw new fe(404)}const s=await se(t).delete(`/custom_hostnames/${encodeURIComponent(n)}`).res();return s.ok&&await t.customDomainAdapter.remove(e,n),s.ok},update:async(e,n,s)=>{const r=await se(t).patch(s,`/custom_hostnames/${encodeURIComponent(n)}`).res();if(!r.ok)throw new fe(503,{message:await r.text()});return t.customDomainAdapter.update(e,n,s)}}}class Qn{constructor(e){this.config=e}cache=null;async getCache(){if(this.cache)return this.cache;if(typeof caches>"u")throw new Error("caches API is not available - CloudflareCache should only be used in Cloudflare Workers");return this.config.cacheName?this.cache=await caches.open(this.config.cacheName):this.cache=caches.default,this.cache}getKey(e){return this.config.keyPrefix?`${this.config.keyPrefix}:${e}`:e}createRequest(e){return new Request(`https://cache.internal/${this.getKey(e)}`)}async get(e){try{const n=await this.getCache(),s=this.createRequest(e),r=await n.match(s);if(!r)return null;const a=await r.json();return a.expiresAt&&new Date(a.expiresAt)<new Date?(await this.delete(e),null):a.value}catch(n){return console.error(`CloudflareCache: get error for key ${e}:`,n),null}}async set(e,n,s){try{const r=await this.getCache(),a=s??this.config.defaultTtlSeconds,i=a!==void 0,o=i?Math.max(0,a):0,c={value:n,expiresAt:i?new Date(Date.now()+(o>0?o*1e3:-1)).toISOString():void 0,cachedAt:new Date().toISOString()},d=this.createRequest(e),h={"Content-Type":"application/json"};i&&o>0&&(h["Cache-Control"]=`max-age=${o}`);const x=new Response(JSON.stringify(c),{headers:h});await r.put(d,x)}catch(r){console.error(`CloudflareCache: set error for key ${e}:`,r)}}async delete(e){try{const n=await this.getCache(),s=this.createRequest(e);return await n.delete(s)}catch(n){return console.error(`CloudflareCache: delete error for key ${e}:`,n),!1}}async clear(){console.warn("CloudflareCache.clear() is not implemented - Cloudflare Cache API does not support clearing all entries")}}function Hn(t={}){const e={defaultTtlSeconds:300,keyPrefix:"authhero",...t};return new Qn(e)}const Jn="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let mt=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=Jn[n[t]&63];return e};async function Ke(t,e){const n=t.timeout||3e4,s=new AbortController,r=setTimeout(()=>s.abort(),n);try{const a=`https://api.sql.cloudflarestorage.com/api/v1/accounts/${t.accountId}/r2-sql/query/${t.warehouseName}`,i=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t.authToken}`},body:JSON.stringify({query:e}),signal:s.signal});if(!i.ok)throw new Error(`R2 SQL query failed: ${i.status} ${i.statusText}`);const o=await i.json();if(!o.success&&o.errors)throw new Error(`R2 SQL error: ${o.errors.join(", ")}`);return o.data||o.result?.data||[]}finally{clearTimeout(r)}}function Le(t){return`'${t.replace(/'/g,"''")}'`}function q(t){return`"${t.replace(/"/g,'""')}"`}function yt(t){const e=n=>{if(!n)return"";try{return JSON.parse(n)}catch{return n}};return{type:t.type,date:t.date,description:t.description,ip:t.ip,user_agent:t.user_agent,details:e(t.details),isMobile:!!t.isMobile,user_id:t.user_id,user_name:t.user_name,connection:t.connection,connection_id:t.connection_id,client_id:t.client_id,client_name:t.client_name,audience:t.audience,scope:t.scope,strategy:t.strategy,strategy_type:t.strategy_type,hostname:t.hostname,auth0_client:e(t.auth0_client),log_id:t.id,location_info:t.country_code||t.city_name||t.latitude||t.longitude||t.time_zone||t.continent_code?{country_code:t.country_code||"",city_name:t.city_name||"",latitude:t.latitude||"",longitude:t.longitude||"",time_zone:t.time_zone||"",continent_code:t.continent_code||""}:void 0}}function Yn(t){return async(e,n)=>{const s=n.log_id||mt(),r={...n,log_id:s};return await Kn(t,e,r),r}}async function Kn(t,e,n){const s=a=>a?JSON.stringify(a):void 0,r={id:n.log_id,tenant_id:e,type:n.type,date:n.date,description:n.description?.substring(0,256),ip:n.ip,user_agent:n.user_agent,details:s(n.details)?.substring(0,8192),isMobile:n.isMobile?1:0,user_id:n.user_id,user_name:n.user_name,connection:n.connection,connection_id:n.connection_id,client_id:n.client_id,client_name:n.client_name,audience:n.audience,scope:n.scope,strategy:n.strategy,strategy_type:n.strategy_type,hostname:n.hostname,auth0_client:s(n.auth0_client),log_id:n.log_id,country_code:n.location_info?.country_code,city_name:n.location_info?.city_name,latitude:n.location_info?.latitude,longitude:n.location_info?.longitude,time_zone:n.location_info?.time_zone,continent_code:n.location_info?.continent_code};try{if(t.pipelineBinding)await t.pipelineBinding.send([r]);else if(t.pipelineEndpoint){const a=t.timeout||3e4,i=new AbortController,o=setTimeout(()=>i.abort(),a);try{const c=await fetch(t.pipelineEndpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([r]),signal:i.signal});if(!c.ok)throw new Error(`Pipeline ingestion failed: ${c.status} ${c.statusText}`)}finally{clearTimeout(o)}}else throw new Error("Either pipelineEndpoint or pipelineBinding must be configured")}catch(a){throw console.error("Failed to send log to Pipeline:",a),a}}function Gn(t){return async(e,n)=>{const s=t.namespace||"default",r=t.tableName||"logs",a=`
|
|
2
|
-
SELECT * FROM ${
|
|
3
|
-
WHERE tenant_id = ${
|
|
4
|
-
AND id = ${
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const pt=require("@authhero/adapter-interfaces"),mt=require("wretch");function yt(t,e){var n={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(n[s]=t[s]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,s=Object.getOwnPropertySymbols(t);r<s.length;r++)e.indexOf(s[r])<0&&Object.prototype.propertyIsEnumerable.call(t,s[r])&&(n[s[r]]=t[s[r]]);return n}function _t(t,e){var n;return((n=t?._def)===null||n===void 0?void 0:n.typeName)===e}function re(t,e){const n=t.ZodType.prototype[e];t.ZodType.prototype[e]=function(...s){const r=n.apply(this,s);return r._def.openapi=this._def.openapi,r}}function gt(t){if(typeof t.ZodType.prototype.openapi<"u")return;t.ZodType.prototype.openapi=function(r,a){var i,o,c,u,p,k;const T=typeof r=="string"?a:r,S=T??{},{param:C}=S,U=yt(S,["param"]),x=Object.assign(Object.assign({},(i=this._def.openapi)===null||i===void 0?void 0:i._internal),typeof r=="string"?{refId:r}:void 0),L=Object.assign(Object.assign(Object.assign({},(o=this._def.openapi)===null||o===void 0?void 0:o.metadata),U),!((u=(c=this._def.openapi)===null||c===void 0?void 0:c.metadata)===null||u===void 0)&&u.param||C?{param:Object.assign(Object.assign({},(k=(p=this._def.openapi)===null||p===void 0?void 0:p.metadata)===null||k===void 0?void 0:k.param),C)}:void 0),O=new this.constructor(Object.assign(Object.assign({},this._def),{openapi:Object.assign(Object.assign({},Object.keys(x).length>0?{_internal:x}:void 0),Object.keys(L).length>0?{metadata:L}:void 0)}));if(_t(this,"ZodObject")){const I=this.extend;O.extend=function(...W){var Q,se,we,Se,Te,Ee,Ce;const Oe=I.apply(this,W);return Oe._def.openapi={_internal:{extendedFrom:!((se=(Q=this._def.openapi)===null||Q===void 0?void 0:Q._internal)===null||se===void 0)&&se.refId?{refId:(Se=(we=this._def.openapi)===null||we===void 0?void 0:we._internal)===null||Se===void 0?void 0:Se.refId,schema:this}:(Ee=(Te=this._def.openapi)===null||Te===void 0?void 0:Te._internal)===null||Ee===void 0?void 0:Ee.extendedFrom},metadata:(Ce=Oe._def.openapi)===null||Ce===void 0?void 0:Ce.metadata},Oe}}return O},re(t,"optional"),re(t,"nullable"),re(t,"default"),re(t,"transform"),re(t,"refine");const e=t.ZodObject.prototype.deepPartial;t.ZodObject.prototype.deepPartial=function(){const r=this._def.shape(),a=e.apply(this),i=a._def.shape();return Object.entries(i).forEach(([o,c])=>{var u,p;c._def.openapi=(p=(u=r[o])===null||u===void 0?void 0:u._def)===null||p===void 0?void 0:p.openapi}),a._def.openapi=void 0,a};const n=t.ZodObject.prototype.pick;t.ZodObject.prototype.pick=function(...r){const a=n.apply(this,r);return a._def.openapi=void 0,a};const s=t.ZodObject.prototype.omit;t.ZodObject.prototype.omit=function(...r){const a=s.apply(this,r);return a._def.openapi=void 0,a}}var ae=class extends Error{res;status;constructor(t=500,e){super(e?.message,{cause:e?.cause}),this.res=e?.res,this.status=t}getResponse(){return this.res?new Response(this.res.body,{status:this.status,headers:this.res.headers}):new Response(this.message,{status:this.status})}};new Set(".\\+*[^]$()");var b;(function(t){t.assertEqual=r=>{};function e(r){}t.assertIs=e;function n(r){throw new Error}t.assertNever=n,t.arrayToEnum=r=>{const a={};for(const i of r)a[i]=i;return a},t.getValidEnumValues=r=>{const a=t.objectKeys(r).filter(o=>typeof r[r[o]]!="number"),i={};for(const o of a)i[o]=r[o];return t.objectValues(i)},t.objectValues=r=>t.objectKeys(r).map(function(a){return r[a]}),t.objectKeys=typeof Object.keys=="function"?r=>Object.keys(r):r=>{const a=[];for(const i in r)Object.prototype.hasOwnProperty.call(r,i)&&a.push(i);return a},t.find=(r,a)=>{for(const i of r)if(a(i))return i},t.isInteger=typeof Number.isInteger=="function"?r=>Number.isInteger(r):r=>typeof r=="number"&&Number.isFinite(r)&&Math.floor(r)===r;function s(r,a=" | "){return r.map(i=>typeof i=="string"?`'${i}'`:i).join(a)}t.joinValues=s,t.jsonStringifyReplacer=(r,a)=>typeof a=="bigint"?a.toString():a})(b||(b={}));var Re;(function(t){t.mergeShapes=(e,n)=>({...e,...n})})(Re||(Re={}));const h=b.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),P=t=>{switch(typeof t){case"undefined":return h.undefined;case"string":return h.string;case"number":return Number.isNaN(t)?h.nan:h.number;case"boolean":return h.boolean;case"function":return h.function;case"bigint":return h.bigint;case"symbol":return h.symbol;case"object":return Array.isArray(t)?h.array:t===null?h.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?h.promise:typeof Map<"u"&&t instanceof Map?h.map:typeof Set<"u"&&t instanceof Set?h.set:typeof Date<"u"&&t instanceof Date?h.date:h.object;default:return h.unknown}},d=b.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 Z extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=s=>{this.issues=[...this.issues,s]},this.addIssues=(s=[])=>{this.issues=[...this.issues,...s]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=e}format(e){const n=e||function(a){return a.message},s={_errors:[]},r=a=>{for(const i of a.issues)if(i.code==="invalid_union")i.unionErrors.map(r);else if(i.code==="invalid_return_type")r(i.returnTypeError);else if(i.code==="invalid_arguments")r(i.argumentsError);else if(i.path.length===0)s._errors.push(n(i));else{let o=s,c=0;for(;c<i.path.length;){const u=i.path[c];c===i.path.length-1?(o[u]=o[u]||{_errors:[]},o[u]._errors.push(n(i))):o[u]=o[u]||{_errors:[]},o=o[u],c++}}};return r(this),s}static assert(e){if(!(e instanceof Z))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,b.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=n=>n.message){const n={},s=[];for(const r of this.issues)if(r.path.length>0){const a=r.path[0];n[a]=n[a]||[],n[a].push(e(r))}else s.push(e(r));return{formErrors:s,fieldErrors:n}}get formErrors(){return this.flatten()}}Z.create=t=>new Z(t);const pe=(t,e)=>{let n;switch(t.code){case d.invalid_type:t.received===h.undefined?n="Required":n=`Expected ${t.expected}, received ${t.received}`;break;case d.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(t.expected,b.jsonStringifyReplacer)}`;break;case d.unrecognized_keys:n=`Unrecognized key(s) in object: ${b.joinValues(t.keys,", ")}`;break;case d.invalid_union:n="Invalid input";break;case d.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${b.joinValues(t.options)}`;break;case d.invalid_enum_value:n=`Invalid enum value. Expected ${b.joinValues(t.options)}, received '${t.received}'`;break;case d.invalid_arguments:n="Invalid function arguments";break;case d.invalid_return_type:n="Invalid function return type";break;case d.invalid_date:n="Invalid date";break;case d.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(n=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?n=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?n=`Invalid input: must end with "${t.validation.endsWith}"`:b.assertNever(t.validation):t.validation!=="regex"?n=`Invalid ${t.validation}`:n="Invalid";break;case d.too_small:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="bigint"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:n="Invalid input";break;case d.too_big:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?n=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:n="Invalid input";break;case d.custom:n="Invalid input";break;case d.invalid_intersection_types:n="Intersection results could not be merged";break;case d.not_multiple_of:n=`Number must be a multiple of ${t.multipleOf}`;break;case d.not_finite:n="Number must be finite";break;default:n=e.defaultError,b.assertNever(t)}return{message:n}};let vt=pe;function Ge(){return vt}const Xe=t=>{const{data:e,path:n,errorMaps:s,issueData:r}=t,a=[...n,...r.path||[]],i={...r,path:a};if(r.message!==void 0)return{...r,path:a,message:r.message};let o="";const c=s.filter(u=>!!u).slice().reverse();for(const u of c)o=u(i,{data:e,defaultError:o}).message;return{...r,path:a,message:o}};function l(t,e){const n=Ge(),s=Xe({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,n,n===pe?void 0:pe].filter(r=>!!r)});t.common.issues.push(s)}class E{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,n){const s=[];for(const r of n){if(r.status==="aborted")return y;r.status==="dirty"&&e.dirty(),s.push(r.value)}return{status:e.value,value:s}}static async mergeObjectAsync(e,n){const s=[];for(const r of n){const a=await r.key,i=await r.value;s.push({key:a,value:i})}return E.mergeObjectSync(e,s)}static mergeObjectSync(e,n){const s={};for(const r of n){const{key:a,value:i}=r;if(a.status==="aborted"||i.status==="aborted")return y;a.status==="dirty"&&e.dirty(),i.status==="dirty"&&e.dirty(),a.value!=="__proto__"&&(typeof i.value<"u"||r.alwaysSet)&&(s[a.value]=i.value)}return{status:e.value,value:s}}}const y=Object.freeze({status:"aborted"}),ee=t=>({status:"dirty",value:t}),N=t=>({status:"valid",value:t}),$e=t=>t.status==="aborted",Ie=t=>t.status==="dirty",H=t=>t.status==="valid",ie=t=>typeof Promise<"u"&&t instanceof Promise;var f;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e?.message})(f||(f={}));class D{constructor(e,n,s,r){this._cachedPath=[],this.parent=e,this.data=n,this._path=s,this._key=r}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 He=(t,e)=>{if(H(e))return{success:!0,data:e.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const n=new Z(t.common.issues);return this._error=n,this._error}}};function g(t){if(!t)return{};const{errorMap:e,invalid_type_error:n,required_error:s,description:r}=t;if(e&&(n||s))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:r}:{errorMap:(i,o)=>{const{message:c}=t;return i.code==="invalid_enum_value"?{message:c??o.defaultError}:typeof o.data>"u"?{message:c??s??o.defaultError}:i.code!=="invalid_type"?{message:o.defaultError}:{message:c??n??o.defaultError}},description:r}}class v{get description(){return this._def.description}_getType(e){return P(e.data)}_getOrReturnCtx(e,n){return n||{common:e.parent.common,data:e.data,parsedType:P(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new E,ctx:{common:e.parent.common,data:e.data,parsedType:P(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const n=this._parse(e);if(ie(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(e){const n=this._parse(e);return Promise.resolve(n)}parse(e,n){const s=this.safeParse(e,n);if(s.success)return s.data;throw s.error}safeParse(e,n){const s={common:{issues:[],async:n?.async??!1,contextualErrorMap:n?.errorMap},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:P(e)},r=this._parseSync({data:e,path:s.path,parent:s});return He(s,r)}"~validate"(e){const n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:P(e)};if(!this["~standard"].async)try{const s=this._parseSync({data:e,path:[],parent:n});return H(s)?{value:s.value}:{issues:n.common.issues}}catch(s){s?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),n.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:n}).then(s=>H(s)?{value:s.value}:{issues:n.common.issues})}async parseAsync(e,n){const s=await this.safeParseAsync(e,n);if(s.success)return s.data;throw s.error}async safeParseAsync(e,n){const s={common:{issues:[],contextualErrorMap:n?.errorMap,async:!0},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:P(e)},r=this._parse({data:e,path:s.path,parent:s}),a=await(ie(r)?r:Promise.resolve(r));return He(s,a)}refine(e,n){const s=r=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(r):n;return this._refinement((r,a)=>{const i=e(r),o=()=>a.addIssue({code:d.custom,...s(r)});return typeof Promise<"u"&&i instanceof Promise?i.then(c=>c?!0:(o(),!1)):i?!0:(o(),!1)})}refinement(e,n){return this._refinement((s,r)=>e(s)?!0:(r.addIssue(typeof n=="function"?n(s,r):n),!1))}_refinement(e){return new F({schema:this,typeName:m.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,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:n=>this["~validate"](n)}}optional(){return V.create(this,this._def)}nullable(){return K.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return R.create(this)}promise(){return le.create(this,this._def)}or(e){return ce.create([this,e],this._def)}and(e){return de.create(this,e,this._def)}transform(e){return new F({...g(this._def),schema:this,typeName:m.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const n=typeof e=="function"?e:()=>e;return new ye({...g(this._def),innerType:this,defaultValue:n,typeName:m.ZodDefault})}brand(){return new rt({typeName:m.ZodBranded,type:this,...g(this._def)})}catch(e){const n=typeof e=="function"?e:()=>e;return new _e({...g(this._def),innerType:this,catchValue:n,typeName:m.ZodCatch})}describe(e){const n=this.constructor;return new n({...this._def,description:e})}pipe(e){return xe.create(this,e)}readonly(){return ge.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const bt=/^c[^\s-]{8,}$/i,xt=/^[0-9a-z]+$/,kt=/^[0-9A-HJKMNP-TV-Z]{26}$/i,wt=/^[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,St=/^[a-z0-9_-]{21}$/i,Tt=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Et=/^[-+]?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)?)??$/,Ct=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Ot="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Ae;const At=/^(?:(?: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])$/,Nt=/^(?:(?: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])$/,Rt=/^(([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]))$/,$t=/^(([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])$/,It=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,jt=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,et="((\\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])))",Zt=new RegExp(`^${et}$`);function tt(t){let e="[0-5]\\d";t.precision?e=`${e}\\.\\d{${t.precision}}`:t.precision==null&&(e=`${e}(\\.\\d+)?`);const n=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${n}`}function Dt(t){return new RegExp(`^${tt(t)}$`)}function nt(t){let e=`${et}T${tt(t)}`;const n=[];return n.push(t.local?"Z?":"Z"),t.offset&&n.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${n.join("|")})`,new RegExp(`^${e}$`)}function Lt(t,e){return!!((e==="v4"||!e)&&At.test(t)||(e==="v6"||!e)&&Rt.test(t))}function Pt(t,e){if(!Tt.test(t))return!1;try{const[n]=t.split(".");if(!n)return!1;const s=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(n.length+(4-n.length%4)%4,"="),r=JSON.parse(atob(s));return!(typeof r!="object"||r===null||"typ"in r&&r?.typ!=="JWT"||!r.alg||e&&r.alg!==e)}catch{return!1}}function Mt(t,e){return!!((e==="v4"||!e)&&Nt.test(t)||(e==="v6"||!e)&&$t.test(t))}class j extends v{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==h.string){const a=this._getOrReturnCtx(e);return l(a,{code:d.invalid_type,expected:h.string,received:a.parsedType}),y}const s=new E;let r;for(const a of this._def.checks)if(a.kind==="min")e.data.length<a.value&&(r=this._getOrReturnCtx(e,r),l(r,{code:d.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),s.dirty());else if(a.kind==="max")e.data.length>a.value&&(r=this._getOrReturnCtx(e,r),l(r,{code:d.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),s.dirty());else if(a.kind==="length"){const i=e.data.length>a.value,o=e.data.length<a.value;(i||o)&&(r=this._getOrReturnCtx(e,r),i?l(r,{code:d.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}):o&&l(r,{code:d.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}),s.dirty())}else if(a.kind==="email")Ct.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"email",code:d.invalid_string,message:a.message}),s.dirty());else if(a.kind==="emoji")Ae||(Ae=new RegExp(Ot,"u")),Ae.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"emoji",code:d.invalid_string,message:a.message}),s.dirty());else if(a.kind==="uuid")wt.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"uuid",code:d.invalid_string,message:a.message}),s.dirty());else if(a.kind==="nanoid")St.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"nanoid",code:d.invalid_string,message:a.message}),s.dirty());else if(a.kind==="cuid")bt.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"cuid",code:d.invalid_string,message:a.message}),s.dirty());else if(a.kind==="cuid2")xt.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"cuid2",code:d.invalid_string,message:a.message}),s.dirty());else if(a.kind==="ulid")kt.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"ulid",code:d.invalid_string,message:a.message}),s.dirty());else if(a.kind==="url")try{new URL(e.data)}catch{r=this._getOrReturnCtx(e,r),l(r,{validation:"url",code:d.invalid_string,message:a.message}),s.dirty()}else a.kind==="regex"?(a.regex.lastIndex=0,a.regex.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"regex",code:d.invalid_string,message:a.message}),s.dirty())):a.kind==="trim"?e.data=e.data.trim():a.kind==="includes"?e.data.includes(a.value,a.position)||(r=this._getOrReturnCtx(e,r),l(r,{code:d.invalid_string,validation:{includes:a.value,position:a.position},message:a.message}),s.dirty()):a.kind==="toLowerCase"?e.data=e.data.toLowerCase():a.kind==="toUpperCase"?e.data=e.data.toUpperCase():a.kind==="startsWith"?e.data.startsWith(a.value)||(r=this._getOrReturnCtx(e,r),l(r,{code:d.invalid_string,validation:{startsWith:a.value},message:a.message}),s.dirty()):a.kind==="endsWith"?e.data.endsWith(a.value)||(r=this._getOrReturnCtx(e,r),l(r,{code:d.invalid_string,validation:{endsWith:a.value},message:a.message}),s.dirty()):a.kind==="datetime"?nt(a).test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{code:d.invalid_string,validation:"datetime",message:a.message}),s.dirty()):a.kind==="date"?Zt.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{code:d.invalid_string,validation:"date",message:a.message}),s.dirty()):a.kind==="time"?Dt(a).test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{code:d.invalid_string,validation:"time",message:a.message}),s.dirty()):a.kind==="duration"?Et.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"duration",code:d.invalid_string,message:a.message}),s.dirty()):a.kind==="ip"?Lt(e.data,a.version)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"ip",code:d.invalid_string,message:a.message}),s.dirty()):a.kind==="jwt"?Pt(e.data,a.alg)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"jwt",code:d.invalid_string,message:a.message}),s.dirty()):a.kind==="cidr"?Mt(e.data,a.version)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"cidr",code:d.invalid_string,message:a.message}),s.dirty()):a.kind==="base64"?It.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"base64",code:d.invalid_string,message:a.message}),s.dirty()):a.kind==="base64url"?jt.test(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{validation:"base64url",code:d.invalid_string,message:a.message}),s.dirty()):b.assertNever(a);return{status:s.value,value:e.data}}_regex(e,n,s){return this.refinement(r=>e.test(r),{validation:n,code:d.invalid_string,...f.errToObj(s)})}_addCheck(e){return new j({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...f.errToObj(e)})}url(e){return this._addCheck({kind:"url",...f.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...f.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...f.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...f.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...f.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...f.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...f.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...f.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...f.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...f.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...f.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...f.errToObj(e)})}datetime(e){return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof e?.precision>"u"?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...f.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof e?.precision>"u"?null:e?.precision,...f.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...f.errToObj(e)})}regex(e,n){return this._addCheck({kind:"regex",regex:e,...f.errToObj(n)})}includes(e,n){return this._addCheck({kind:"includes",value:e,position:n?.position,...f.errToObj(n?.message)})}startsWith(e,n){return this._addCheck({kind:"startsWith",value:e,...f.errToObj(n)})}endsWith(e,n){return this._addCheck({kind:"endsWith",value:e,...f.errToObj(n)})}min(e,n){return this._addCheck({kind:"min",value:e,...f.errToObj(n)})}max(e,n){return this._addCheck({kind:"max",value:e,...f.errToObj(n)})}length(e,n){return this._addCheck({kind:"length",value:e,...f.errToObj(n)})}nonempty(e){return this.min(1,f.errToObj(e))}trim(){return new j({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new j({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new j({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxLength(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}}j.create=t=>new j({checks:[],typeName:m.ZodString,coerce:t?.coerce??!1,...g(t)});function Vt(t,e){const n=(t.toString().split(".")[1]||"").length,s=(e.toString().split(".")[1]||"").length,r=n>s?n:s,a=Number.parseInt(t.toFixed(r).replace(".","")),i=Number.parseInt(e.toFixed(r).replace(".",""));return a%i/10**r}class J extends v{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==h.number){const a=this._getOrReturnCtx(e);return l(a,{code:d.invalid_type,expected:h.number,received:a.parsedType}),y}let s;const r=new E;for(const a of this._def.checks)a.kind==="int"?b.isInteger(e.data)||(s=this._getOrReturnCtx(e,s),l(s,{code:d.invalid_type,expected:"integer",received:"float",message:a.message}),r.dirty()):a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(s=this._getOrReturnCtx(e,s),l(s,{code:d.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),r.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(s=this._getOrReturnCtx(e,s),l(s,{code:d.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),r.dirty()):a.kind==="multipleOf"?Vt(e.data,a.value)!==0&&(s=this._getOrReturnCtx(e,s),l(s,{code:d.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):a.kind==="finite"?Number.isFinite(e.data)||(s=this._getOrReturnCtx(e,s),l(s,{code:d.not_finite,message:a.message}),r.dirty()):b.assertNever(a);return{status:r.value,value:e.data}}gte(e,n){return this.setLimit("min",e,!0,f.toString(n))}gt(e,n){return this.setLimit("min",e,!1,f.toString(n))}lte(e,n){return this.setLimit("max",e,!0,f.toString(n))}lt(e,n){return this.setLimit("max",e,!1,f.toString(n))}setLimit(e,n,s,r){return new J({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:s,message:f.toString(r)}]})}_addCheck(e){return new J({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:f.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:f.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:f.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:f.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:f.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:f.toString(n)})}finite(e){return this._addCheck({kind:"finite",message:f.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:f.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:f.toString(e)})}get minValue(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&b.isInteger(e.value))}get isFinite(){let e=null,n=null;for(const s of this._def.checks){if(s.kind==="finite"||s.kind==="int"||s.kind==="multipleOf")return!0;s.kind==="min"?(n===null||s.value>n)&&(n=s.value):s.kind==="max"&&(e===null||s.value<e)&&(e=s.value)}return Number.isFinite(n)&&Number.isFinite(e)}}J.create=t=>new J({checks:[],typeName:m.ZodNumber,coerce:t?.coerce||!1,...g(t)});class te extends v{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==h.bigint)return this._getInvalidInput(e);let s;const r=new E;for(const a of this._def.checks)a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(s=this._getOrReturnCtx(e,s),l(s,{code:d.too_small,type:"bigint",minimum:a.value,inclusive:a.inclusive,message:a.message}),r.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(s=this._getOrReturnCtx(e,s),l(s,{code:d.too_big,type:"bigint",maximum:a.value,inclusive:a.inclusive,message:a.message}),r.dirty()):a.kind==="multipleOf"?e.data%a.value!==BigInt(0)&&(s=this._getOrReturnCtx(e,s),l(s,{code:d.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):b.assertNever(a);return{status:r.value,value:e.data}}_getInvalidInput(e){const n=this._getOrReturnCtx(e);return l(n,{code:d.invalid_type,expected:h.bigint,received:n.parsedType}),y}gte(e,n){return this.setLimit("min",e,!0,f.toString(n))}gt(e,n){return this.setLimit("min",e,!1,f.toString(n))}lte(e,n){return this.setLimit("max",e,!0,f.toString(n))}lt(e,n){return this.setLimit("max",e,!1,f.toString(n))}setLimit(e,n,s,r){return new te({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:s,message:f.toString(r)}]})}_addCheck(e){return new te({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:f.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:f.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:f.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:f.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:f.toString(n)})}get minValue(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}}te.create=t=>new te({checks:[],typeName:m.ZodBigInt,coerce:t?.coerce??!1,...g(t)});class me extends v{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==h.boolean){const s=this._getOrReturnCtx(e);return l(s,{code:d.invalid_type,expected:h.boolean,received:s.parsedType}),y}return N(e.data)}}me.create=t=>new me({typeName:m.ZodBoolean,coerce:t?.coerce||!1,...g(t)});class oe extends v{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==h.date){const a=this._getOrReturnCtx(e);return l(a,{code:d.invalid_type,expected:h.date,received:a.parsedType}),y}if(Number.isNaN(e.data.getTime())){const a=this._getOrReturnCtx(e);return l(a,{code:d.invalid_date}),y}const s=new E;let r;for(const a of this._def.checks)a.kind==="min"?e.data.getTime()<a.value&&(r=this._getOrReturnCtx(e,r),l(r,{code:d.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),s.dirty()):a.kind==="max"?e.data.getTime()>a.value&&(r=this._getOrReturnCtx(e,r),l(r,{code:d.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),s.dirty()):b.assertNever(a);return{status:s.value,value:new Date(e.data.getTime())}}_addCheck(e){return new oe({...this._def,checks:[...this._def.checks,e]})}min(e,n){return this._addCheck({kind:"min",value:e.getTime(),message:f.toString(n)})}max(e,n){return this._addCheck({kind:"max",value:e.getTime(),message:f.toString(n)})}get minDate(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e!=null?new Date(e):null}}oe.create=t=>new oe({checks:[],coerce:t?.coerce||!1,typeName:m.ZodDate,...g(t)});class je extends v{_parse(e){if(this._getType(e)!==h.symbol){const s=this._getOrReturnCtx(e);return l(s,{code:d.invalid_type,expected:h.symbol,received:s.parsedType}),y}return N(e.data)}}je.create=t=>new je({typeName:m.ZodSymbol,...g(t)});class Ze extends v{_parse(e){if(this._getType(e)!==h.undefined){const s=this._getOrReturnCtx(e);return l(s,{code:d.invalid_type,expected:h.undefined,received:s.parsedType}),y}return N(e.data)}}Ze.create=t=>new Ze({typeName:m.ZodUndefined,...g(t)});class De extends v{_parse(e){if(this._getType(e)!==h.null){const s=this._getOrReturnCtx(e);return l(s,{code:d.invalid_type,expected:h.null,received:s.parsedType}),y}return N(e.data)}}De.create=t=>new De({typeName:m.ZodNull,...g(t)});class Le extends v{constructor(){super(...arguments),this._any=!0}_parse(e){return N(e.data)}}Le.create=t=>new Le({typeName:m.ZodAny,...g(t)});class Pe extends v{constructor(){super(...arguments),this._unknown=!0}_parse(e){return N(e.data)}}Pe.create=t=>new Pe({typeName:m.ZodUnknown,...g(t)});class z extends v{_parse(e){const n=this._getOrReturnCtx(e);return l(n,{code:d.invalid_type,expected:h.never,received:n.parsedType}),y}}z.create=t=>new z({typeName:m.ZodNever,...g(t)});class Me extends v{_parse(e){if(this._getType(e)!==h.undefined){const s=this._getOrReturnCtx(e);return l(s,{code:d.invalid_type,expected:h.void,received:s.parsedType}),y}return N(e.data)}}Me.create=t=>new Me({typeName:m.ZodVoid,...g(t)});class R extends v{_parse(e){const{ctx:n,status:s}=this._processInputParams(e),r=this._def;if(n.parsedType!==h.array)return l(n,{code:d.invalid_type,expected:h.array,received:n.parsedType}),y;if(r.exactLength!==null){const i=n.data.length>r.exactLength.value,o=n.data.length<r.exactLength.value;(i||o)&&(l(n,{code:i?d.too_big:d.too_small,minimum:o?r.exactLength.value:void 0,maximum:i?r.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:r.exactLength.message}),s.dirty())}if(r.minLength!==null&&n.data.length<r.minLength.value&&(l(n,{code:d.too_small,minimum:r.minLength.value,type:"array",inclusive:!0,exact:!1,message:r.minLength.message}),s.dirty()),r.maxLength!==null&&n.data.length>r.maxLength.value&&(l(n,{code:d.too_big,maximum:r.maxLength.value,type:"array",inclusive:!0,exact:!1,message:r.maxLength.message}),s.dirty()),n.common.async)return Promise.all([...n.data].map((i,o)=>r.type._parseAsync(new D(n,i,n.path,o)))).then(i=>E.mergeArray(s,i));const a=[...n.data].map((i,o)=>r.type._parseSync(new D(n,i,n.path,o)));return E.mergeArray(s,a)}get element(){return this._def.type}min(e,n){return new R({...this._def,minLength:{value:e,message:f.toString(n)}})}max(e,n){return new R({...this._def,maxLength:{value:e,message:f.toString(n)}})}length(e,n){return new R({...this._def,exactLength:{value:e,message:f.toString(n)}})}nonempty(e){return this.min(1,e)}}R.create=(t,e)=>new R({type:t,minLength:null,maxLength:null,exactLength:null,typeName:m.ZodArray,...g(e)});function X(t){if(t instanceof w){const e={};for(const n in t.shape){const s=t.shape[n];e[n]=V.create(X(s))}return new w({...t._def,shape:()=>e})}else return t instanceof R?new R({...t._def,type:X(t.element)}):t instanceof V?V.create(X(t.unwrap())):t instanceof K?K.create(X(t.unwrap())):t instanceof q?q.create(t.items.map(e=>X(e))):t}class w extends v{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),n=b.objectKeys(e);return this._cached={shape:e,keys:n},this._cached}_parse(e){if(this._getType(e)!==h.object){const u=this._getOrReturnCtx(e);return l(u,{code:d.invalid_type,expected:h.object,received:u.parsedType}),y}const{status:s,ctx:r}=this._processInputParams(e),{shape:a,keys:i}=this._getCached(),o=[];if(!(this._def.catchall instanceof z&&this._def.unknownKeys==="strip"))for(const u in r.data)i.includes(u)||o.push(u);const c=[];for(const u of i){const p=a[u],k=r.data[u];c.push({key:{status:"valid",value:u},value:p._parse(new D(r,k,r.path,u)),alwaysSet:u in r.data})}if(this._def.catchall instanceof z){const u=this._def.unknownKeys;if(u==="passthrough")for(const p of o)c.push({key:{status:"valid",value:p},value:{status:"valid",value:r.data[p]}});else if(u==="strict")o.length>0&&(l(r,{code:d.unrecognized_keys,keys:o}),s.dirty());else if(u!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const u=this._def.catchall;for(const p of o){const k=r.data[p];c.push({key:{status:"valid",value:p},value:u._parse(new D(r,k,r.path,p)),alwaysSet:p in r.data})}}return r.common.async?Promise.resolve().then(async()=>{const u=[];for(const p of c){const k=await p.key,T=await p.value;u.push({key:k,value:T,alwaysSet:p.alwaysSet})}return u}).then(u=>E.mergeObjectSync(s,u)):E.mergeObjectSync(s,c)}get shape(){return this._def.shape()}strict(e){return f.errToObj,new w({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(n,s)=>{const r=this._def.errorMap?.(n,s).message??s.defaultError;return n.code==="unrecognized_keys"?{message:f.errToObj(e).message??r}:{message:r}}}:{}})}strip(){return new w({...this._def,unknownKeys:"strip"})}passthrough(){return new w({...this._def,unknownKeys:"passthrough"})}extend(e){return new w({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new w({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:m.ZodObject})}setKey(e,n){return this.augment({[e]:n})}catchall(e){return new w({...this._def,catchall:e})}pick(e){const n={};for(const s of b.objectKeys(e))e[s]&&this.shape[s]&&(n[s]=this.shape[s]);return new w({...this._def,shape:()=>n})}omit(e){const n={};for(const s of b.objectKeys(this.shape))e[s]||(n[s]=this.shape[s]);return new w({...this._def,shape:()=>n})}deepPartial(){return X(this)}partial(e){const n={};for(const s of b.objectKeys(this.shape)){const r=this.shape[s];e&&!e[s]?n[s]=r:n[s]=r.optional()}return new w({...this._def,shape:()=>n})}required(e){const n={};for(const s of b.objectKeys(this.shape))if(e&&!e[s])n[s]=this.shape[s];else{let a=this.shape[s];for(;a instanceof V;)a=a._def.innerType;n[s]=a}return new w({...this._def,shape:()=>n})}keyof(){return st(b.objectKeys(this.shape))}}w.create=(t,e)=>new w({shape:()=>t,unknownKeys:"strip",catchall:z.create(),typeName:m.ZodObject,...g(e)});w.strictCreate=(t,e)=>new w({shape:()=>t,unknownKeys:"strict",catchall:z.create(),typeName:m.ZodObject,...g(e)});w.lazycreate=(t,e)=>new w({shape:t,unknownKeys:"strip",catchall:z.create(),typeName:m.ZodObject,...g(e)});class ce extends v{_parse(e){const{ctx:n}=this._processInputParams(e),s=this._def.options;function r(a){for(const o of a)if(o.result.status==="valid")return o.result;for(const o of a)if(o.result.status==="dirty")return n.common.issues.push(...o.ctx.common.issues),o.result;const i=a.map(o=>new Z(o.ctx.common.issues));return l(n,{code:d.invalid_union,unionErrors:i}),y}if(n.common.async)return Promise.all(s.map(async a=>{const i={...n,common:{...n.common,issues:[]},parent:null};return{result:await a._parseAsync({data:n.data,path:n.path,parent:i}),ctx:i}})).then(r);{let a;const i=[];for(const c of s){const u={...n,common:{...n.common,issues:[]},parent:null},p=c._parseSync({data:n.data,path:n.path,parent:u});if(p.status==="valid")return p;p.status==="dirty"&&!a&&(a={result:p,ctx:u}),u.common.issues.length&&i.push(u.common.issues)}if(a)return n.common.issues.push(...a.ctx.common.issues),a.result;const o=i.map(c=>new Z(c));return l(n,{code:d.invalid_union,unionErrors:o}),y}}get options(){return this._def.options}}ce.create=(t,e)=>new ce({options:t,typeName:m.ZodUnion,...g(e)});function Ve(t,e){const n=P(t),s=P(e);if(t===e)return{valid:!0,data:t};if(n===h.object&&s===h.object){const r=b.objectKeys(e),a=b.objectKeys(t).filter(o=>r.indexOf(o)!==-1),i={...t,...e};for(const o of a){const c=Ve(t[o],e[o]);if(!c.valid)return{valid:!1};i[o]=c.data}return{valid:!0,data:i}}else if(n===h.array&&s===h.array){if(t.length!==e.length)return{valid:!1};const r=[];for(let a=0;a<t.length;a++){const i=t[a],o=e[a],c=Ve(i,o);if(!c.valid)return{valid:!1};r.push(c.data)}return{valid:!0,data:r}}else return n===h.date&&s===h.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}class de extends v{_parse(e){const{status:n,ctx:s}=this._processInputParams(e),r=(a,i)=>{if($e(a)||$e(i))return y;const o=Ve(a.value,i.value);return o.valid?((Ie(a)||Ie(i))&&n.dirty(),{status:n.value,value:o.data}):(l(s,{code:d.invalid_intersection_types}),y)};return s.common.async?Promise.all([this._def.left._parseAsync({data:s.data,path:s.path,parent:s}),this._def.right._parseAsync({data:s.data,path:s.path,parent:s})]).then(([a,i])=>r(a,i)):r(this._def.left._parseSync({data:s.data,path:s.path,parent:s}),this._def.right._parseSync({data:s.data,path:s.path,parent:s}))}}de.create=(t,e,n)=>new de({left:t,right:e,typeName:m.ZodIntersection,...g(n)});class q extends v{_parse(e){const{status:n,ctx:s}=this._processInputParams(e);if(s.parsedType!==h.array)return l(s,{code:d.invalid_type,expected:h.array,received:s.parsedType}),y;if(s.data.length<this._def.items.length)return l(s,{code:d.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),y;!this._def.rest&&s.data.length>this._def.items.length&&(l(s,{code:d.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const a=[...s.data].map((i,o)=>{const c=this._def.items[o]||this._def.rest;return c?c._parse(new D(s,i,s.path,o)):null}).filter(i=>!!i);return s.common.async?Promise.all(a).then(i=>E.mergeArray(n,i)):E.mergeArray(n,a)}get items(){return this._def.items}rest(e){return new q({...this._def,rest:e})}}q.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new q({items:t,typeName:m.ZodTuple,rest:null,...g(e)})};class ue extends v{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:n,ctx:s}=this._processInputParams(e);if(s.parsedType!==h.object)return l(s,{code:d.invalid_type,expected:h.object,received:s.parsedType}),y;const r=[],a=this._def.keyType,i=this._def.valueType;for(const o in s.data)r.push({key:a._parse(new D(s,o,s.path,o)),value:i._parse(new D(s,s.data[o],s.path,o)),alwaysSet:o in s.data});return s.common.async?E.mergeObjectAsync(n,r):E.mergeObjectSync(n,r)}get element(){return this._def.valueType}static create(e,n,s){return n instanceof v?new ue({keyType:e,valueType:n,typeName:m.ZodRecord,...g(s)}):new ue({keyType:j.create(),valueType:e,typeName:m.ZodRecord,...g(n)})}}class ze extends v{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:n,ctx:s}=this._processInputParams(e);if(s.parsedType!==h.map)return l(s,{code:d.invalid_type,expected:h.map,received:s.parsedType}),y;const r=this._def.keyType,a=this._def.valueType,i=[...s.data.entries()].map(([o,c],u)=>({key:r._parse(new D(s,o,s.path,[u,"key"])),value:a._parse(new D(s,c,s.path,[u,"value"]))}));if(s.common.async){const o=new Map;return Promise.resolve().then(async()=>{for(const c of i){const u=await c.key,p=await c.value;if(u.status==="aborted"||p.status==="aborted")return y;(u.status==="dirty"||p.status==="dirty")&&n.dirty(),o.set(u.value,p.value)}return{status:n.value,value:o}})}else{const o=new Map;for(const c of i){const u=c.key,p=c.value;if(u.status==="aborted"||p.status==="aborted")return y;(u.status==="dirty"||p.status==="dirty")&&n.dirty(),o.set(u.value,p.value)}return{status:n.value,value:o}}}}ze.create=(t,e,n)=>new ze({valueType:e,keyType:t,typeName:m.ZodMap,...g(n)});class ne extends v{_parse(e){const{status:n,ctx:s}=this._processInputParams(e);if(s.parsedType!==h.set)return l(s,{code:d.invalid_type,expected:h.set,received:s.parsedType}),y;const r=this._def;r.minSize!==null&&s.data.size<r.minSize.value&&(l(s,{code:d.too_small,minimum:r.minSize.value,type:"set",inclusive:!0,exact:!1,message:r.minSize.message}),n.dirty()),r.maxSize!==null&&s.data.size>r.maxSize.value&&(l(s,{code:d.too_big,maximum:r.maxSize.value,type:"set",inclusive:!0,exact:!1,message:r.maxSize.message}),n.dirty());const a=this._def.valueType;function i(c){const u=new Set;for(const p of c){if(p.status==="aborted")return y;p.status==="dirty"&&n.dirty(),u.add(p.value)}return{status:n.value,value:u}}const o=[...s.data.values()].map((c,u)=>a._parse(new D(s,c,s.path,u)));return s.common.async?Promise.all(o).then(c=>i(c)):i(o)}min(e,n){return new ne({...this._def,minSize:{value:e,message:f.toString(n)}})}max(e,n){return new ne({...this._def,maxSize:{value:e,message:f.toString(n)}})}size(e,n){return this.min(e,n).max(e,n)}nonempty(e){return this.min(1,e)}}ne.create=(t,e)=>new ne({valueType:t,minSize:null,maxSize:null,typeName:m.ZodSet,...g(e)});class Be extends v{get schema(){return this._def.getter()}_parse(e){const{ctx:n}=this._processInputParams(e);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}}Be.create=(t,e)=>new Be({getter:t,typeName:m.ZodLazy,...g(e)});class qe extends v{_parse(e){if(e.data!==this._def.value){const n=this._getOrReturnCtx(e);return l(n,{received:n.data,code:d.invalid_literal,expected:this._def.value}),y}return{status:"valid",value:e.data}}get value(){return this._def.value}}qe.create=(t,e)=>new qe({value:t,typeName:m.ZodLiteral,...g(e)});function st(t,e){return new Y({values:t,typeName:m.ZodEnum,...g(e)})}class Y extends v{_parse(e){if(typeof e.data!="string"){const n=this._getOrReturnCtx(e),s=this._def.values;return l(n,{expected:b.joinValues(s),received:n.parsedType,code:d.invalid_type}),y}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){const n=this._getOrReturnCtx(e),s=this._def.values;return l(n,{received:n.data,code:d.invalid_enum_value,options:s}),y}return N(e.data)}get options(){return this._def.values}get enum(){const e={};for(const n of this._def.values)e[n]=n;return e}get Values(){const e={};for(const n of this._def.values)e[n]=n;return e}get Enum(){const e={};for(const n of this._def.values)e[n]=n;return e}extract(e,n=this._def){return Y.create(e,{...this._def,...n})}exclude(e,n=this._def){return Y.create(this.options.filter(s=>!e.includes(s)),{...this._def,...n})}}Y.create=st;class Fe extends v{_parse(e){const n=b.getValidEnumValues(this._def.values),s=this._getOrReturnCtx(e);if(s.parsedType!==h.string&&s.parsedType!==h.number){const r=b.objectValues(n);return l(s,{expected:b.joinValues(r),received:s.parsedType,code:d.invalid_type}),y}if(this._cache||(this._cache=new Set(b.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){const r=b.objectValues(n);return l(s,{received:s.data,code:d.invalid_enum_value,options:r}),y}return N(e.data)}get enum(){return this._def.values}}Fe.create=(t,e)=>new Fe({values:t,typeName:m.ZodNativeEnum,...g(e)});class le extends v{unwrap(){return this._def.type}_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==h.promise&&n.common.async===!1)return l(n,{code:d.invalid_type,expected:h.promise,received:n.parsedType}),y;const s=n.parsedType===h.promise?n.data:Promise.resolve(n.data);return N(s.then(r=>this._def.type.parseAsync(r,{path:n.path,errorMap:n.common.contextualErrorMap})))}}le.create=(t,e)=>new le({type:t,typeName:m.ZodPromise,...g(e)});class F extends v{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===m.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:n,ctx:s}=this._processInputParams(e),r=this._def.effect||null,a={addIssue:i=>{l(s,i),i.fatal?n.abort():n.dirty()},get path(){return s.path}};if(a.addIssue=a.addIssue.bind(a),r.type==="preprocess"){const i=r.transform(s.data,a);if(s.common.async)return Promise.resolve(i).then(async o=>{if(n.value==="aborted")return y;const c=await this._def.schema._parseAsync({data:o,path:s.path,parent:s});return c.status==="aborted"?y:c.status==="dirty"||n.value==="dirty"?ee(c.value):c});{if(n.value==="aborted")return y;const o=this._def.schema._parseSync({data:i,path:s.path,parent:s});return o.status==="aborted"?y:o.status==="dirty"||n.value==="dirty"?ee(o.value):o}}if(r.type==="refinement"){const i=o=>{const c=r.refinement(o,a);if(s.common.async)return Promise.resolve(c);if(c instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return o};if(s.common.async===!1){const o=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});return o.status==="aborted"?y:(o.status==="dirty"&&n.dirty(),i(o.value),{status:n.value,value:o.value})}else return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then(o=>o.status==="aborted"?y:(o.status==="dirty"&&n.dirty(),i(o.value).then(()=>({status:n.value,value:o.value}))))}if(r.type==="transform")if(s.common.async===!1){const i=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});if(!H(i))return y;const o=r.transform(i.value,a);if(o instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:o}}else return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then(i=>H(i)?Promise.resolve(r.transform(i.value,a)).then(o=>({status:n.value,value:o})):y);b.assertNever(r)}}F.create=(t,e,n)=>new F({schema:t,typeName:m.ZodEffects,effect:e,...g(n)});F.createWithPreprocess=(t,e,n)=>new F({schema:e,effect:{type:"preprocess",transform:t},typeName:m.ZodEffects,...g(n)});class V extends v{_parse(e){return this._getType(e)===h.undefined?N(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}V.create=(t,e)=>new V({innerType:t,typeName:m.ZodOptional,...g(e)});class K extends v{_parse(e){return this._getType(e)===h.null?N(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}K.create=(t,e)=>new K({innerType:t,typeName:m.ZodNullable,...g(e)});class ye extends v{_parse(e){const{ctx:n}=this._processInputParams(e);let s=n.data;return n.parsedType===h.undefined&&(s=this._def.defaultValue()),this._def.innerType._parse({data:s,path:n.path,parent:n})}removeDefault(){return this._def.innerType}}ye.create=(t,e)=>new ye({innerType:t,typeName:m.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...g(e)});class _e extends v{_parse(e){const{ctx:n}=this._processInputParams(e),s={...n,common:{...n.common,issues:[]}},r=this._def.innerType._parse({data:s.data,path:s.path,parent:{...s}});return ie(r)?r.then(a=>({status:"valid",value:a.status==="valid"?a.value:this._def.catchValue({get error(){return new Z(s.common.issues)},input:s.data})})):{status:"valid",value:r.status==="valid"?r.value:this._def.catchValue({get error(){return new Z(s.common.issues)},input:s.data})}}removeCatch(){return this._def.innerType}}_e.create=(t,e)=>new _e({innerType:t,typeName:m.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...g(e)});class Ue extends v{_parse(e){if(this._getType(e)!==h.nan){const s=this._getOrReturnCtx(e);return l(s,{code:d.invalid_type,expected:h.nan,received:s.parsedType}),y}return{status:"valid",value:e.data}}}Ue.create=t=>new Ue({typeName:m.ZodNaN,...g(t)});class rt extends v{_parse(e){const{ctx:n}=this._processInputParams(e),s=n.data;return this._def.type._parse({data:s,path:n.path,parent:n})}unwrap(){return this._def.type}}class xe extends v{_parse(e){const{status:n,ctx:s}=this._processInputParams(e);if(s.common.async)return(async()=>{const a=await this._def.in._parseAsync({data:s.data,path:s.path,parent:s});return a.status==="aborted"?y:a.status==="dirty"?(n.dirty(),ee(a.value)):this._def.out._parseAsync({data:a.value,path:s.path,parent:s})})();{const r=this._def.in._parseSync({data:s.data,path:s.path,parent:s});return r.status==="aborted"?y:r.status==="dirty"?(n.dirty(),{status:"dirty",value:r.value}):this._def.out._parseSync({data:r.value,path:s.path,parent:s})}}static create(e,n){return new xe({in:e,out:n,typeName:m.ZodPipeline})}}class ge extends v{_parse(e){const n=this._def.innerType._parse(e),s=r=>(H(r)&&(r.value=Object.freeze(r.value)),r);return ie(n)?n.then(r=>s(r)):s(n)}unwrap(){return this._def.innerType}}ge.create=(t,e)=>new ge({innerType:t,typeName:m.ZodReadonly,...g(e)});var m;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(m||(m={}));const _=j.create,at=J.create,ke=me.create;z.create;const A=R.create,$=w.create;ce.create;de.create;q.create;const it=ue.create;Y.create;le.create;V.create;K.create;const zt=Object.freeze(Object.defineProperty({__proto__:null,DIRTY:ee,INVALID:y,OK:N,ParseStatus:E,Schema:v,ZodAny:Le,ZodArray:R,ZodBigInt:te,ZodBoolean:me,ZodBranded:rt,ZodCatch:_e,ZodDate:oe,ZodDefault:ye,ZodEffects:F,ZodEnum:Y,ZodError:Z,get ZodFirstPartyTypeKind(){return m},ZodIntersection:de,ZodIssueCode:d,ZodLazy:Be,ZodLiteral:qe,ZodMap:ze,ZodNaN:Ue,ZodNativeEnum:Fe,ZodNever:z,ZodNull:De,ZodNullable:K,ZodNumber:J,ZodObject:w,ZodOptional:V,ZodParsedType:h,ZodPipeline:xe,ZodPromise:le,ZodReadonly:ge,ZodRecord:ue,ZodSchema:v,ZodSet:ne,ZodString:j,ZodSymbol:je,ZodTransformer:F,ZodTuple:q,ZodType:v,ZodUndefined:Ze,ZodUnion:ce,ZodUnknown:Pe,ZodVoid:Me,addIssueToContext:l,array:A,boolean:ke,datetimeRegex:nt,defaultErrorMap:pe,getErrorMap:Ge,getParsedType:P,isAborted:$e,isAsync:ie,isDirty:Ie,isValid:H,makeIssue:Xe,number:at,object:$,get objectUtil(){return Re},record:it,string:_,get util(){return b}},Symbol.toStringTag,{value:"Module"}));gt(zt);const Bt=(t,e)=>e.skipDedupe||e.method!=="GET",qt=(t,e)=>e.method+"@"+t,Ft=t=>t.clone(),Ut=({skip:t=Bt,key:e=qt,resolver:n=Ft}={})=>{const s=new Map;return r=>(a,i)=>{if(t(a,i))return r(a,i);const o=e(a,i);if(!s.has(o))s.set(o,[]);else return new Promise((c,u)=>{s.get(o).push([c,u])});try{return r(a,i).then(c=>(s.get(o).forEach(([u])=>u(n(c))),s.delete(o),c)).catch(c=>{throw s.get(o).forEach(([,u])=>u(c)),s.delete(o),c})}catch(c){return s.delete(o),Promise.reject(c)}}},Wt=(t,e)=>t*e,Qt=t=>t&&(t.ok||t.status>=400&&t.status<500),Ht=({delayTimer:t=500,delayRamp:e=Wt,maxAttempts:n=10,until:s=Qt,onRetry:r=null,retryOnNetworkError:a=!1,resolveWithLatestResponse:i=!1,skip:o}={})=>c=>(u,p)=>{let k=0;if(o&&o(u,p))return c(u,p);const T=(S,C)=>Promise.resolve(s(S,C)).then(U=>U?S&&i?S:C?Promise.reject(C):S:(k++,!n||k<=n?new Promise(x=>{const L=e(t,k);setTimeout(()=>{typeof r=="function"?Promise.resolve(r({response:S,error:C,url:u,attempt:k,options:p})).then((O={})=>{var I,W;x(c((I=O&&O.url)!==null&&I!==void 0?I:u,(W=O&&O.options)!==null&&W!==void 0?W:p))}):x(c(u,p))},L)}).then(T).catch(x=>{if(!a)throw x;return T(null,x)}):S&&i?S:Promise.reject(C||new Error("Number of attempts exceeded."))));return c(u,p).then(T).catch(S=>{if(!a)throw S;return T(null,S)})},ve=$({code:at(),message:_()}),Jt=$({message:_()}),Yt=$({emails:A(_()).optional(),http_body:_().optional(),http_url:_().optional(),txt_name:_().optional(),txt_value:_().optional()}),Kt=$({ciphers:A(_()).optional(),early_hints:_().optional(),http2:_().optional(),min_tls_version:_().optional(),tls_1_3:_().optional()}),Gt=$({id:_(),bundle_method:_().optional(),certificate_authority:_(),custom_certificate:_().optional(),custom_csr_id:_().optional(),custom_key:_().optional(),expires_on:_().optional(),hosts:A(_()).optional(),issuer:_().optional(),method:_(),serial_number:_().optional(),settings:Kt.optional(),signature:_().optional(),type:_(),uploaded_on:_().optional(),validation_errors:A(Jt).optional(),validation_records:A(Yt).optional(),wildcard:ke()}),Xt=$({name:_(),type:_(),value:_()}),en=$({http_body:_().optional(),http_url:_().optional()}),ot=$({id:_(),ssl:Gt,hostname:_(),custom_metadata:it(_()).optional(),custom_origin_server:_().optional(),custom_origin_sni:_().optional(),ownership_verification:Xt.optional(),ownership_verification_http:en.optional(),status:_(),verification_errors:A(_()).optional(),created_at:_()}),fe=$({errors:A(ve),messages:A(ve),success:ke(),result:ot});$({errors:A(ve),messages:A(ve),success:ke(),result:A(ot)});function G(t){return mt(`https://api.cloudflare.com/client/v4/zones/${t.zoneId}`).headers({"X-Auth-Email":t.authEmail,"X-Auth-Key":t.authKey,"Content-Type":"application/json"}).middlewares([Ht(),Ut()])}function Ne(t){const e=[];if(t.ssl.validation_records)for(const n of t.ssl.validation_records)n.txt_name&&n.txt_value&&e.push({name:"txt",record:n.txt_value,domain:n.txt_name});return t.ownership_verification&&e.push({name:"txt",record:t.ownership_verification.value,domain:t.ownership_verification.name}),{custom_domain_id:t.id,domain:t.hostname,primary:t.primary,status:t.status==="active"?"ready":"pending",type:"auth0_managed_certs",verification:{methods:A(pt.verificationMethodsSchema).parse(e)}}}function tn(t){return{create:async(e,n)=>{const{result:s,errors:r,success:a}=fe.parse(await G(t).post({hostname:n.domain,ssl:{method:"txt",type:"dv"},custom_metadata:t.enterprise?{tenant_id:e}:void 0},"/custom_hostnames").json());if(!a)throw new Error(JSON.stringify(r));const i=Ne({...s,primary:!1});return await t.customDomainAdapter.create(e,{custom_domain_id:i.custom_domain_id,domain:i.domain,type:i.type}),i},get:async(e,n)=>{const s=await t.customDomainAdapter.get(e,n);if(!s)throw new ae(404);const r=await G(t).get(`/custom_hostnames/${encodeURIComponent(n)}`).json(),{result:a,errors:i,success:o}=fe.parse(r);if(!o)throw new ae(503,{message:JSON.stringify(i)});if(t.enterprise&&a.custom_metadata?.tenant_id!==e)throw new ae(404);return Ne({...s,...a})},getByDomain:async e=>t.customDomainAdapter.getByDomain(e),list:async e=>{const n=await t.customDomainAdapter.list(e);return(await Promise.all(n.map(async r=>{try{const a=await G(t).get(`/custom_hostnames/${encodeURIComponent(r.custom_domain_id)}`).json(),{result:i,success:o}=fe.parse(a);return!o||t.enterprise&&i.custom_metadata?.tenant_id!==e?null:Ne({...r,...i})}catch{return null}}))).filter(r=>r!==null)},remove:async(e,n)=>{if(t.enterprise){const{result:r,success:a}=fe.parse(await G(t).get(`/custom_hostnames/${encodeURIComponent(n)}`).json());if(!a||r.custom_metadata?.tenant_id!==e)throw new ae(404)}const s=await G(t).delete(`/custom_hostnames/${encodeURIComponent(n)}`).res();return s.ok&&await t.customDomainAdapter.remove(e,n),s.ok},update:async(e,n,s)=>{const r=await G(t).patch(s,`/custom_hostnames/${encodeURIComponent(n)}`).res();if(!r.ok)throw new ae(503,{message:await r.text()});return t.customDomainAdapter.update(e,n,s)}}}class nn{constructor(e){this.config=e}cache=null;async getCache(){if(this.cache)return this.cache;if(typeof caches>"u")throw new Error("caches API is not available - CloudflareCache should only be used in Cloudflare Workers");return this.config.cacheName?this.cache=await caches.open(this.config.cacheName):this.cache=caches.default,this.cache}getKey(e){return this.config.keyPrefix?`${this.config.keyPrefix}:${e}`:e}createRequest(e){return new Request(`https://cache.internal/${this.getKey(e)}`)}async get(e){try{const n=await this.getCache(),s=this.createRequest(e),r=await n.match(s);if(!r)return null;const a=await r.json();return a.expiresAt&&new Date(a.expiresAt)<new Date?(await this.delete(e),null):a.value}catch(n){return console.error(`CloudflareCache: get error for key ${e}:`,n),null}}async set(e,n,s){try{const r=await this.getCache(),a=s??this.config.defaultTtlSeconds,i=a!==void 0,o=i?Math.max(0,a):0,c={value:n,expiresAt:i?new Date(Date.now()+(o>0?o*1e3:-1)).toISOString():void 0,cachedAt:new Date().toISOString()},u=this.createRequest(e),p={"Content-Type":"application/json"};i&&o>0&&(p["Cache-Control"]=`max-age=${o}`);const k=new Response(JSON.stringify(c),{headers:p});await r.put(u,k)}catch(r){console.error(`CloudflareCache: set error for key ${e}:`,r)}}async delete(e){try{const n=await this.getCache(),s=this.createRequest(e);return await n.delete(s)}catch(n){return console.error(`CloudflareCache: delete error for key ${e}:`,n),!1}}async clear(){console.warn("CloudflareCache.clear() is not implemented - Cloudflare Cache API does not support clearing all entries")}}function sn(t={}){const e={defaultTtlSeconds:300,keyPrefix:"authhero",...t};return new nn(e)}const rn="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let ct=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=rn[n[t]&63];return e};async function We(t,e){const n=t.timeout||3e4,s=new AbortController,r=setTimeout(()=>s.abort(),n);try{const a=`https://api.sql.cloudflarestorage.com/api/v1/accounts/${t.accountId}/r2-sql/query/${t.warehouseName}`,i=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t.authToken}`},body:JSON.stringify({query:e}),signal:s.signal});if(!i.ok)throw new Error(`R2 SQL query failed: ${i.status} ${i.statusText}`);const o=await i.json();if(!o.success&&o.errors)throw new Error(`R2 SQL error: ${o.errors.join(", ")}`);return o.data||o.result?.data||[]}finally{clearTimeout(r)}}function be(t){return`'${t.replace(/'/g,"''")}'`}function B(t){return`"${t.replace(/"/g,'""')}"`}function dt(t){const e=n=>{if(!n)return"";try{return JSON.parse(n)}catch{return n}};return{type:t.type,date:t.date,description:t.description,ip:t.ip,user_agent:t.user_agent,details:e(t.details),isMobile:!!t.isMobile,user_id:t.user_id,user_name:t.user_name,connection:t.connection,connection_id:t.connection_id,client_id:t.client_id,client_name:t.client_name,audience:t.audience,scope:t.scope,strategy:t.strategy,strategy_type:t.strategy_type,hostname:t.hostname,auth0_client:e(t.auth0_client),log_id:t.id,location_info:t.country_code||t.city_name||t.latitude||t.longitude||t.time_zone||t.continent_code?{country_code:t.country_code||"",city_name:t.city_name||"",latitude:t.latitude||"",longitude:t.longitude||"",time_zone:t.time_zone||"",continent_code:t.continent_code||""}:void 0}}function an(t){return async(e,n)=>{const s=n.log_id||ct(),r={...n,log_id:s};return await on(t,e,r),r}}async function on(t,e,n){const s=a=>a?JSON.stringify(a):void 0,r={id:n.log_id,tenant_id:e,type:n.type,date:n.date,description:n.description?.substring(0,256),ip:n.ip,user_agent:n.user_agent,details:s(n.details)?.substring(0,8192),isMobile:n.isMobile?1:0,user_id:n.user_id,user_name:n.user_name,connection:n.connection,connection_id:n.connection_id,client_id:n.client_id,client_name:n.client_name,audience:n.audience,scope:n.scope,strategy:n.strategy,strategy_type:n.strategy_type,hostname:n.hostname,auth0_client:s(n.auth0_client),log_id:n.log_id,country_code:n.location_info?.country_code,city_name:n.location_info?.city_name,latitude:n.location_info?.latitude,longitude:n.location_info?.longitude,time_zone:n.location_info?.time_zone,continent_code:n.location_info?.continent_code};try{if(t.pipelineBinding)await t.pipelineBinding.send([r]);else if(t.pipelineEndpoint){const a=t.timeout||3e4,i=new AbortController,o=setTimeout(()=>i.abort(),a);try{const c=await fetch(t.pipelineEndpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([r]),signal:i.signal});if(!c.ok)throw new Error(`Pipeline ingestion failed: ${c.status} ${c.statusText}`)}finally{clearTimeout(o)}}else throw new Error("Either pipelineEndpoint or pipelineBinding must be configured")}catch(a){throw console.error("Failed to send log to Pipeline:",a),a}}function cn(t){return async(e,n)=>{const s=t.namespace||"default",r=t.tableName||"logs",a=`
|
|
2
|
+
SELECT * FROM ${B(s)}.${B(r)}
|
|
3
|
+
WHERE tenant_id = ${be(e)}
|
|
4
|
+
AND id = ${be(n)}
|
|
5
5
|
LIMIT 1
|
|
6
|
-
`,i=await
|
|
7
|
-
SELECT * FROM ${
|
|
8
|
-
WHERE ${
|
|
9
|
-
${
|
|
10
|
-
${
|
|
11
|
-
`,
|
|
12
|
-
SELECT COUNT(*) as count FROM ${
|
|
13
|
-
WHERE ${
|
|
14
|
-
`,
|
|
6
|
+
`,i=await We(t,a);if(i.length===0)return null;const o=i[0];return o?dt(o):null}}function dn(t){const e={};return(t.match(/(\w+):(\S+)/g)||[]).forEach(s=>{const[r,a]=s.split(":");r&&a&&(e[r]=a)}),e}function un(t){const e=[];for(const[n,s]of Object.entries(t)){const r=n.replace(/[^a-zA-Z0-9_]/g,"");r&&s&&e.push(`${B(r)} = ${be(s)}`)}return e}function ln(t){return async(e,n={})=>{const{page:s=0,per_page:r=50,include_totals:a=!1,sort:i,q:o}=n,c=t.namespace||"default",u=t.tableName||"logs",p=[`tenant_id = ${be(e)}`];if(o){const Q=dn(o);p.push(...un(Q))}const k=p.join(" AND ");let T="ORDER BY date DESC";if(i&&i.sort_by){const Q=i.sort_by.replace(/[^a-zA-Z0-9_]/g,""),se=i.sort_order==="asc"?"ASC":"DESC";T=`ORDER BY ${B(Q)} ${se}`}const S=s*r,C=`LIMIT ${r} OFFSET ${S}`,U=`
|
|
7
|
+
SELECT * FROM ${B(c)}.${B(u)}
|
|
8
|
+
WHERE ${k}
|
|
9
|
+
${T}
|
|
10
|
+
${C}
|
|
11
|
+
`,L=(await We(t,U)).map(dt);if(!a)return{logs:L,start:0,limit:0,length:0};const O=`
|
|
12
|
+
SELECT COUNT(*) as count FROM ${B(c)}.${B(u)}
|
|
13
|
+
WHERE ${k}
|
|
14
|
+
`,W=(await We(t,O))[0]?.count||0;return{logs:L,start:S,limit:r,length:Number(W)}}}function hn(){return{async getDaily(){throw new Error("Stats queries are not supported by R2 SQL logs adapter. Use Analytics Engine or Kysely adapter instead.")},async getActiveUsers(){throw new Error("Stats queries are not supported by R2 SQL logs adapter. Use Analytics Engine or Kysely adapter instead.")}}}function ut(t){const e=!!t.pipelineEndpoint,n=!!t.pipelineBinding;if(!e&&!n)throw new Error('R2 SQL logs adapter requires one of: "pipelineEndpoint" or "pipelineBinding"');if(!t.authToken)throw new Error('R2 SQL logs adapter requires "authToken" configuration');if(!t.warehouseName)throw new Error('R2 SQL logs adapter requires "warehouseName" configuration');return{create:an(t),list:ln(t),get:cn(t)}}async function he(t,e){const n=t.timeout||3e4,s=new AbortController,r=setTimeout(()=>s.abort(),n);try{const a=`https://api.cloudflare.com/client/v4/accounts/${t.accountId}/analytics_engine/sql`,i=await fetch(a,{method:"POST",headers:{"Content-Type":"text/plain",Authorization:`Bearer ${t.apiToken}`},body:e,signal:s.signal});if(!i.ok){const c=await i.text();throw new Error(`Analytics Engine query failed: ${i.status} ${i.statusText} - ${c}`)}const o=await i.json();if(!o.success&&o.errors&&o.errors.length>0)throw new Error(`Analytics Engine error: ${o.errors.map(c=>c.message).join(", ")}`);return o.data||[]}finally{clearTimeout(r)}}function M(t){return`'${t.replace(/'/g,"''").replace(/\\/g,"\\\\")}'`}function Qe(t){return`"${t.replace(/"/g,'""')}"`}function lt(t){const e=r=>{if(r)try{return JSON.parse(r)}catch{return}},n=t.double2||t.timestamp,s=n?new Date(n).toISOString():"";return{log_id:t.blob1,type:t.blob3,date:s,description:t.blob4,ip:t.blob5,user_agent:t.blob6,user_id:t.blob7,user_name:t.blob8,connection:t.blob9,connection_id:t.blob10,client_id:t.blob11,client_name:t.blob12,audience:t.blob13,scope:t.blob14,strategy:t.blob15,strategy_type:t.blob16,hostname:t.blob17,details:e(t.blob18),auth0_client:e(t.blob19),location_info:e(t.blob20),isMobile:t.double1===1}}function fn(t){return async(e,n)=>{const s=n.log_id||ct(),r={...n,log_id:s};return pn(t,e,r),r}}function pn(t,e,n){if(!t.analyticsEngineBinding){console.error("Analytics Engine binding not configured");return}const s=a=>a==null?"":typeof a=="string"?a:JSON.stringify(a),r=(a,i=1024)=>a.substring(0,i);try{t.analyticsEngineBinding.writeDataPoint({blobs:[r(n.log_id),r(e),r(n.type||""),r(n.description||""),r(n.ip||""),r(n.user_agent||""),r(n.user_id||""),r(n.user_name||""),r(n.connection||""),r(n.connection_id||""),r(n.client_id||""),r(n.client_name||""),r(n.audience||""),r(n.scope||""),r(n.strategy||""),r(n.strategy_type||""),r(n.hostname||""),r(s(n.details)),r(s(n.auth0_client)),r(s(n.location_info))],doubles:[n.isMobile?1:0,new Date(n.date).getTime()],indexes:[e.substring(0,96)]})}catch(a){console.error("Failed to write log to Analytics Engine:",a)}}function mn(t){return async(e,n)=>{const s=t.dataset||"authhero_logs",r=`
|
|
15
15
|
SELECT *
|
|
16
|
-
FROM ${
|
|
17
|
-
WHERE index1 = ${
|
|
18
|
-
AND blob1 = ${
|
|
16
|
+
FROM ${Qe(s)}
|
|
17
|
+
WHERE index1 = ${M(e)}
|
|
18
|
+
AND blob1 = ${M(n)}
|
|
19
19
|
LIMIT 1
|
|
20
|
-
`,a=await
|
|
20
|
+
`,a=await he(t,r);return a.length===0||!a[0]?null:lt(a[0])}}function yn(t){const e={};return(t.match(/(\w+):(\S+)/g)||[]).forEach(s=>{const r=s.indexOf(":"),a=s.substring(0,r),i=s.substring(r+1);a&&i&&(e[a]=i)}),e}function ht(t){return{log_id:"blob1",tenant_id:"blob2",type:"blob3",description:"blob4",ip:"blob5",user_agent:"blob6",user_id:"blob7",user_name:"blob8",connection:"blob9",connection_id:"blob10",client_id:"blob11",client_name:"blob12",audience:"blob13",scope:"blob14",strategy:"blob15",strategy_type:"blob16",hostname:"blob17"}[t]||null}function _n(t){const e=[];for(const[n,s]of Object.entries(t)){const r=ht(n);r&&s&&e.push(`${r} = ${M(s)}`)}return e}function gn(t){if(t==="date")return"double2";const e=ht(t);return e||"timestamp"}function vn(t){return async(e,n={})=>{const{page:s=0,per_page:r=50,include_totals:a=!1,sort:i,q:o}=n,c=t.dataset||"authhero_logs",u=[`index1 = ${M(e)}`];if(o){const O=yn(o);u.push(..._n(O))}const p=u.join(" AND ");let k="ORDER BY timestamp DESC";if(i&&i.sort_by){const O=gn(i.sort_by),I=i.sort_order==="asc"?"ASC":"DESC";k=`ORDER BY ${O} ${I}`}const T=s*r,S=`LIMIT ${r} OFFSET ${T}`,C=`
|
|
21
21
|
SELECT *
|
|
22
|
-
FROM ${
|
|
23
|
-
WHERE ${
|
|
24
|
-
${
|
|
25
|
-
${
|
|
26
|
-
`,
|
|
22
|
+
FROM ${Qe(c)}
|
|
23
|
+
WHERE ${p}
|
|
24
|
+
${k}
|
|
25
|
+
${S}
|
|
26
|
+
`,x=(await he(t,C)).map(lt);if(!a)return{logs:x,start:0,limit:0,length:0};const L=`
|
|
27
27
|
SELECT count() as count
|
|
28
|
-
FROM ${
|
|
29
|
-
WHERE ${
|
|
30
|
-
`;try{const
|
|
28
|
+
FROM ${Qe(c)}
|
|
29
|
+
WHERE ${p}
|
|
30
|
+
`;try{const I=(await he(t,L))[0]?.count||0;return{logs:x,start:T,limit:r,length:Number(I)}}catch{return{logs:x,start:T,limit:r,length:x.length}}}}const Je=["s","seacft","seccft","sepft","sertft","ssa"],bn=["pwd_leak","signup_pwd_leak","reset_pwd_leak"];function Ye(t){return`${t.slice(0,4)}-${t.slice(4,6)}-${t.slice(6,8)}`}function Ke(t){return t.toISOString().split("T")[0]}function xn(t){const e=t.dataset||"authhero_logs";return{async getDaily(n,s={}){const{from:r,to:a}=s,i=new Date,o=new Date(i);o.setDate(o.getDate()-30);const c=r?Ye(r):Ke(o),u=a?Ye(a):Ke(i),p=new Date(`${c}T00:00:00Z`).getTime(),k=new Date(`${u}T23:59:59.999Z`).getTime(),T=Je.map(x=>M(x)).join(", "),S=bn.map(x=>M(x)).join(", "),C=`
|
|
31
31
|
SELECT
|
|
32
32
|
toDate(toDateTime(double2 / 1000)) AS date,
|
|
33
|
-
SUM(CASE WHEN blob3 IN (${
|
|
33
|
+
SUM(CASE WHEN blob3 IN (${T}) THEN 1 ELSE 0 END) AS logins,
|
|
34
34
|
SUM(CASE WHEN blob3 = 'ss' THEN 1 ELSE 0 END) AS signups,
|
|
35
|
-
SUM(CASE WHEN blob3 IN (${
|
|
35
|
+
SUM(CASE WHEN blob3 IN (${S}) THEN 1 ELSE 0 END) AS leaked_passwords,
|
|
36
36
|
MIN(double2) AS first_event,
|
|
37
37
|
MAX(double2) AS last_event
|
|
38
38
|
FROM "${e}"
|
|
39
|
-
WHERE index1 = ${
|
|
40
|
-
AND double2 >= ${
|
|
41
|
-
AND double2 <= ${
|
|
39
|
+
WHERE index1 = ${M(n)}
|
|
40
|
+
AND double2 >= ${p}
|
|
41
|
+
AND double2 <= ${k}
|
|
42
42
|
GROUP BY date
|
|
43
43
|
ORDER BY date ASC
|
|
44
|
-
`;return(await
|
|
44
|
+
`;return(await he(t,C)).map(x=>({date:String(x.date),logins:Number(x.logins)||0,signups:Number(x.signups)||0,leaked_passwords:Number(x.leaked_passwords)||0,created_at:x.first_event?new Date(Number(x.first_event)).toISOString():new Date().toISOString(),updated_at:x.last_event?new Date(Number(x.last_event)).toISOString():new Date().toISOString()}))},async getActiveUsers(n){const s=new Date;s.setDate(s.getDate()-30);const r=s.getTime(),a=Je.map(u=>M(u)).join(", "),i=`
|
|
45
45
|
SELECT COUNT(DISTINCT blob7) AS count
|
|
46
46
|
FROM "${e}"
|
|
47
|
-
WHERE index1 = ${
|
|
47
|
+
WHERE index1 = ${M(n)}
|
|
48
48
|
AND double2 >= ${r}
|
|
49
49
|
AND blob3 IN (${a})
|
|
50
50
|
AND blob7 IS NOT NULL
|
|
51
51
|
AND blob7 != ''
|
|
52
|
-
`,c=(await
|
|
52
|
+
`,c=(await he(t,i))[0];return c&&c.count!==void 0&&Number(c.count)||0}}}function ft(t){return t.analyticsEngineBinding||console.warn("Analytics Engine: No binding configured. Logs will not be written to Analytics Engine."),(!t.accountId||!t.apiToken)&&console.warn("Analytics Engine: accountId and apiToken are required for querying logs via SQL API."),{create:fn(t),list:vn(t),get:mn(t)}}function kn(){return{async getGeoInfo(t){try{const e=t["cf-ipcountry"],n=t["cf-ipcity"],s=t["cf-iplatitude"],r=t["cf-iplongitude"],a=t["cf-timezone"],i=t["cf-ipcontinent"];return e?{country_code:e,city_name:n||"",latitude:s||"",longitude:r||"",time_zone:a||"",continent_code:i||""}:null}catch(e){return console.warn("Failed to get geo info from Cloudflare headers:",e),null}}}}function wn(t){const e={customDomains:tn(t),cache:sn({...t.cacheName&&{cacheName:t.cacheName},...t.defaultTtlSeconds!==void 0&&{defaultTtlSeconds:t.defaultTtlSeconds},...t.keyPrefix&&{keyPrefix:t.keyPrefix}}),geo:kn()};return t.r2SqlLogs?e.logs=ut(t.r2SqlLogs):t.analyticsEngineLogs&&(e.logs=ft(t.analyticsEngineLogs)),e}exports.createAnalyticsEngineLogsAdapter=ft;exports.createAnalyticsEngineStatsAdapter=xn;exports.createR2SQLLogsAdapter=ut;exports.createR2SQLStatsAdapter=hn;exports.default=wn;
|