@debugkit/cli 0.0.0-stage → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ var ct=Object.defineProperty;var dt=(r,e)=>{for(var t in e)ct(r,t,{get:e[t],enumerable:!0})};import{DynamoDBClient as Yr}from"@aws-sdk/client-dynamodb";import{DynamoDBDocumentClient as Kr}from"@aws-sdk/lib-dynamodb";import{BatchWriteCommand as lt,GetCommand as pt,PutCommand as ft,QueryCommand as Ve,UpdateCommand as ke}from"@aws-sdk/lib-dynamodb";function Ze(r){let e=new Map;for(let t of r){let s=ut(t),n=e.get(s)??{app:t.app,day:t.day,dimension:t.dimension,key:t.key,errors:0,events:0};t.kind==="error"?n.errors+=t.by:n.events+=t.by,e.set(s,n)}return[...e.values()]}var ut=r=>`${r.day}__${r.dimension}__${encodeURIComponent(r.key)}`;var we=class{constructor(e,t){this.doc=e;this.opts=t}doc;opts;get table(){return this.opts.table}async registerApp(e){await this.doc.send(new ft({TableName:this.table,Item:{pk:"APPS",sk:e}}))}async writeEvents(e){let t=n=>Math.floor(Date.parse(n.receivedAt)/1e3)+(this.opts.retentionDays??30)*86400,s=e.flatMap(n=>{let a=`${n.event.ts}#${n.event.id}`,i={...n,ttl:t(n)},o=[{pk:`APP#${n.app}#EV#${n.day}`,sk:a,...i}];return n.fingerprint&&o.push({pk:`APP#${n.app}#ISSUEEV#${n.fingerprint}`,sk:a,...i}),o});for(let n=0;n<s.length;n+=25){let a={[this.table]:s.slice(n,n+25).map(i=>({PutRequest:{Item:i}}))};for(let i=0;a&&Object.keys(a).length&&i<5;i++)a=(await this.doc.send(new lt({RequestItems:a}))).UnprocessedItems,a&&Object.keys(a).length&&await new Promise(u=>setTimeout(u,50*2**i))}}async upsertIssues(e){await Promise.all(e.map(async t=>{await this.doc.send(new ke({TableName:this.table,Key:{pk:`APP#${t.app}#ISSUE`,sk:t.fingerprint},UpdateExpression:"ADD #count :by SET app = :app, fingerprint = :fp, title = :title, flow = :flow, culprit = :culprit, firstSeen = if_not_exists(firstSeen, :first)",ExpressionAttributeNames:{"#count":"count"},ExpressionAttributeValues:{":by":t.by,":app":t.app,":fp":t.fingerprint,":title":t.title,":flow":t.flow??null,":culprit":t.culprit??null,":first":t.firstTs}})),await this.doc.send(new ke({TableName:this.table,Key:{pk:`APP#${t.app}#ISSUE`,sk:t.fingerprint},UpdateExpression:"SET lastSeen = :ts, lastEvent = :ev",ConditionExpression:"attribute_not_exists(lastSeen) OR lastSeen < :ts",ExpressionAttributeValues:{":ts":t.ts,":ev":t.lastEvent}})).catch(s=>{if(s.name!=="ConditionalCheckFailedException")throw s}),await this.doc.send(new ke({TableName:this.table,Key:{pk:`APP#${t.app}#ISSUE`,sk:t.fingerprint},UpdateExpression:"SET firstSeen = :first",ConditionExpression:"firstSeen > :first",ExpressionAttributeValues:{":first":t.firstTs}})).catch(s=>{if(s.name!=="ConditionalCheckFailedException")throw s})}))}async incrementRollups(e){await Promise.all(Ze(e).map(t=>this.doc.send(new ke({TableName:this.table,Key:{pk:`APP#${t.app}#ROLLUP#${t.dimension}`,sk:`${t.day}#${t.key}`},UpdateExpression:"ADD errors :e, events :v SET app = :app, #day = :day, dimension = :dim, #key = :key",ExpressionAttributeNames:{"#day":"day","#key":"key"},ExpressionAttributeValues:{":e":t.errors,":v":t.events,":app":t.app,":day":t.day,":dim":t.dimension,":key":t.key}}))))}async listApps(){return(await this.queryAll({pk:"APPS"})).map(e=>e.sk).sort()}async listIssues(e,{limit:t=200}={}){return(await this.queryAll({pk:`APP#${e}#ISSUE`})).sort((n,a)=>a.lastSeen.localeCompare(n.lastSeen)).slice(0,t).map(be)}async getIssue(e,t){let s=await this.doc.send(new pt({TableName:this.table,Key:{pk:`APP#${e}#ISSUE`,sk:t}}));return s.Item?be(s.Item):null}async getRollups(e,t,s,n){return(await this.queryAll({pk:`APP#${e}#ROLLUP#${t}`,between:[`${s}#`,`${n}#\uFFFF`]})).map(i=>be(i))}async listIssueEvents(e,t,{limit:s=50}={}){return((await this.doc.send(new Ve({TableName:this.table,KeyConditionExpression:"pk = :pk",ExpressionAttributeValues:{":pk":`APP#${e}#ISSUEEV#${t}`},ScanIndexForward:!1,Limit:s}))).Items??[]).map(a=>be(a))}async queryAll({pk:e,between:t}){let s=[],n;do{let a=await this.doc.send(new Ve({TableName:this.table,KeyConditionExpression:t?"pk = :pk AND sk BETWEEN :a AND :b":"pk = :pk",ExpressionAttributeValues:t?{":pk":e,":a":t[0],":b":t[1]}:{":pk":e},ExclusiveStartKey:n}));s.push(...a.Items??[]),n=a.LastEvaluatedKey}while(n);return s}};function be(r){let{pk:e,sk:t,ttl:s,...n}=r;return n}var d={};dt(d,{BRAND:()=>Vt,DIRTY:()=>q,EMPTY_PATH:()=>gt,INVALID:()=>h,NEVER:()=>wr,OK:()=>E,ParseStatus:()=>w,Schema:()=>_,ZodAny:()=>B,ZodArray:()=>Z,ZodBigInt:()=>H,ZodBoolean:()=>J,ZodBranded:()=>ve,ZodCatch:()=>ae,ZodDate:()=>Y,ZodDefault:()=>ne,ZodDiscriminatedUnion:()=>Te,ZodEffects:()=>O,ZodEnum:()=>re,ZodError:()=>S,ZodFirstPartyTypeKind:()=>y,ZodFunction:()=>Ie,ZodIntersection:()=>X,ZodIssueCode:()=>c,ZodLazy:()=>ee,ZodLiteral:()=>te,ZodMap:()=>me,ZodNaN:()=>ye,ZodNativeEnum:()=>se,ZodNever:()=>A,ZodNull:()=>G,ZodNullable:()=>$,ZodNumber:()=>W,ZodObject:()=>T,ZodOptional:()=>I,ZodParsedType:()=>f,ZodPipeline:()=>_e,ZodPromise:()=>F,ZodReadonly:()=>ie,ZodRecord:()=>Ce,ZodSchema:()=>_,ZodSet:()=>he,ZodString:()=>U,ZodSymbol:()=>pe,ZodTransformer:()=>O,ZodTuple:()=>j,ZodType:()=>_,ZodUndefined:()=>K,ZodUnion:()=>Q,ZodUnknown:()=>M,ZodVoid:()=>fe,addIssueToContext:()=>l,any:()=>Jt,array:()=>Qt,bigint:()=>Bt,boolean:()=>Ke,coerce:()=>br,custom:()=>He,date:()=>Ft,datetimeRegex:()=>qe,defaultErrorMap:()=>P,discriminatedUnion:()=>rr,effect:()=>mr,enum:()=>lr,function:()=>cr,getErrorMap:()=>de,getParsedType:()=>N,instanceof:()=>Lt,intersection:()=>sr,isAborted:()=>Ee,isAsync:()=>ue,isDirty:()=>Se,isValid:()=>L,late:()=>zt,lazy:()=>dr,literal:()=>ur,makeIssue:()=>ge,map:()=>ir,nan:()=>Ut,nativeEnum:()=>pr,never:()=>Kt,null:()=>Ht,nullable:()=>yr,number:()=>Ye,object:()=>Xt,objectUtil:()=>Oe,oboolean:()=>kr,onumber:()=>xr,optional:()=>hr,ostring:()=>_r,pipeline:()=>vr,preprocess:()=>gr,promise:()=>fr,quotelessJson:()=>mt,record:()=>ar,set:()=>or,setErrorMap:()=>yt,strictObject:()=>er,string:()=>Je,symbol:()=>qt,transformer:()=>mr,tuple:()=>nr,undefined:()=>Wt,union:()=>tr,unknown:()=>Yt,util:()=>x,void:()=>Gt});var x;(function(r){r.assertEqual=n=>{};function e(n){}r.assertIs=e;function t(n){throw new Error}r.assertNever=t,r.arrayToEnum=n=>{let a={};for(let i of n)a[i]=i;return a},r.getValidEnumValues=n=>{let a=r.objectKeys(n).filter(o=>typeof n[n[o]]!="number"),i={};for(let o of a)i[o]=n[o];return r.objectValues(i)},r.objectValues=n=>r.objectKeys(n).map(function(a){return n[a]}),r.objectKeys=typeof Object.keys=="function"?n=>Object.keys(n):n=>{let a=[];for(let i in n)Object.prototype.hasOwnProperty.call(n,i)&&a.push(i);return a},r.find=(n,a)=>{for(let i of n)if(a(i))return i},r.isInteger=typeof Number.isInteger=="function"?n=>Number.isInteger(n):n=>typeof n=="number"&&Number.isFinite(n)&&Math.floor(n)===n;function s(n,a=" | "){return n.map(i=>typeof i=="string"?`'${i}'`:i).join(a)}r.joinValues=s,r.jsonStringifyReplacer=(n,a)=>typeof a=="bigint"?a.toString():a})(x||(x={}));var Oe;(function(r){r.mergeShapes=(e,t)=>({...e,...t})})(Oe||(Oe={}));var f=x.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),N=r=>{switch(typeof r){case"undefined":return f.undefined;case"string":return f.string;case"number":return Number.isNaN(r)?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(r)?f.array:r===null?f.null:r.then&&typeof r.then=="function"&&r.catch&&typeof r.catch=="function"?f.promise:typeof Map<"u"&&r instanceof Map?f.map:typeof Set<"u"&&r instanceof Set?f.set:typeof Date<"u"&&r instanceof Date?f.date:f.object;default:return f.unknown}};var c=x.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"]),mt=r=>JSON.stringify(r,null,2).replace(/"([^"]+)":/g,"$1:"),S=class r 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]};let t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){let t=e||function(a){return a.message},s={_errors:[]},n=a=>{for(let i of a.issues)if(i.code==="invalid_union")i.unionErrors.map(n);else if(i.code==="invalid_return_type")n(i.returnTypeError);else if(i.code==="invalid_arguments")n(i.argumentsError);else if(i.path.length===0)s._errors.push(t(i));else{let o=s,u=0;for(;u<i.path.length;){let p=i.path[u];u===i.path.length-1?(o[p]=o[p]||{_errors:[]},o[p]._errors.push(t(i))):o[p]=o[p]||{_errors:[]},o=o[p],u++}}};return n(this),s}static assert(e){if(!(e instanceof r))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,x.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=t=>t.message){let t={},s=[];for(let n of this.issues)if(n.path.length>0){let a=n.path[0];t[a]=t[a]||[],t[a].push(e(n))}else s.push(e(n));return{formErrors:s,fieldErrors:t}}get formErrors(){return this.flatten()}};S.create=r=>new S(r);var ht=(r,e)=>{let t;switch(r.code){case c.invalid_type:r.received===f.undefined?t="Required":t=`Expected ${r.expected}, received ${r.received}`;break;case c.invalid_literal:t=`Invalid literal value, expected ${JSON.stringify(r.expected,x.jsonStringifyReplacer)}`;break;case c.unrecognized_keys:t=`Unrecognized key(s) in object: ${x.joinValues(r.keys,", ")}`;break;case c.invalid_union:t="Invalid input";break;case c.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${x.joinValues(r.options)}`;break;case c.invalid_enum_value:t=`Invalid enum value. Expected ${x.joinValues(r.options)}, received '${r.received}'`;break;case c.invalid_arguments:t="Invalid function arguments";break;case c.invalid_return_type:t="Invalid function return type";break;case c.invalid_date:t="Invalid date";break;case c.invalid_string:typeof r.validation=="object"?"includes"in r.validation?(t=`Invalid input: must include "${r.validation.includes}"`,typeof r.validation.position=="number"&&(t=`${t} at one or more positions greater than or equal to ${r.validation.position}`)):"startsWith"in r.validation?t=`Invalid input: must start with "${r.validation.startsWith}"`:"endsWith"in r.validation?t=`Invalid input: must end with "${r.validation.endsWith}"`:x.assertNever(r.validation):r.validation!=="regex"?t=`Invalid ${r.validation}`:t="Invalid";break;case c.too_small:r.type==="array"?t=`Array must contain ${r.exact?"exactly":r.inclusive?"at least":"more than"} ${r.minimum} element(s)`:r.type==="string"?t=`String must contain ${r.exact?"exactly":r.inclusive?"at least":"over"} ${r.minimum} character(s)`:r.type==="number"?t=`Number must be ${r.exact?"exactly equal to ":r.inclusive?"greater than or equal to ":"greater than "}${r.minimum}`:r.type==="bigint"?t=`Number must be ${r.exact?"exactly equal to ":r.inclusive?"greater than or equal to ":"greater than "}${r.minimum}`:r.type==="date"?t=`Date must be ${r.exact?"exactly equal to ":r.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(r.minimum))}`:t="Invalid input";break;case c.too_big:r.type==="array"?t=`Array must contain ${r.exact?"exactly":r.inclusive?"at most":"less than"} ${r.maximum} element(s)`:r.type==="string"?t=`String must contain ${r.exact?"exactly":r.inclusive?"at most":"under"} ${r.maximum} character(s)`:r.type==="number"?t=`Number must be ${r.exact?"exactly":r.inclusive?"less than or equal to":"less than"} ${r.maximum}`:r.type==="bigint"?t=`BigInt must be ${r.exact?"exactly":r.inclusive?"less than or equal to":"less than"} ${r.maximum}`:r.type==="date"?t=`Date must be ${r.exact?"exactly":r.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(r.maximum))}`:t="Invalid input";break;case c.custom:t="Invalid input";break;case c.invalid_intersection_types:t="Intersection results could not be merged";break;case c.not_multiple_of:t=`Number must be a multiple of ${r.multipleOf}`;break;case c.not_finite:t="Number must be finite";break;default:t=e.defaultError,x.assertNever(r)}return{message:t}},P=ht;var ze=P;function yt(r){ze=r}function de(){return ze}var ge=r=>{let{data:e,path:t,errorMaps:s,issueData:n}=r,a=[...t,...n.path||[]],i={...n,path:a};if(n.message!==void 0)return{...n,path:a,message:n.message};let o="",u=s.filter(p=>!!p).slice().reverse();for(let p of u)o=p(i,{data:e,defaultError:o}).message;return{...n,path:a,message:o}},gt=[];function l(r,e){let t=de(),s=ge({issueData:e,data:r.data,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,t,t===P?void 0:P].filter(n=>!!n)});r.common.issues.push(s)}var w=class r{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,t){let s=[];for(let n of t){if(n.status==="aborted")return h;n.status==="dirty"&&e.dirty(),s.push(n.value)}return{status:e.value,value:s}}static async mergeObjectAsync(e,t){let s=[];for(let n of t){let a=await n.key,i=await n.value;s.push({key:a,value:i})}return r.mergeObjectSync(e,s)}static mergeObjectSync(e,t){let s={};for(let n of t){let{key:a,value:i}=n;if(a.status==="aborted"||i.status==="aborted")return h;a.status==="dirty"&&e.dirty(),i.status==="dirty"&&e.dirty(),a.value!=="__proto__"&&(typeof i.value<"u"||n.alwaysSet)&&(s[a.value]=i.value)}return{status:e.value,value:s}}},h=Object.freeze({status:"aborted"}),q=r=>({status:"dirty",value:r}),E=r=>({status:"valid",value:r}),Ee=r=>r.status==="aborted",Se=r=>r.status==="dirty",L=r=>r.status==="valid",ue=r=>typeof Promise<"u"&&r instanceof Promise;var m;(function(r){r.errToObj=e=>typeof e=="string"?{message:e}:e||{},r.toString=e=>typeof e=="string"?e:e?.message})(m||(m={}));var R=class{constructor(e,t,s,n){this._cachedPath=[],this.parent=e,this.data=t,this._path=s,this._key=n}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}},Le=(r,e)=>{if(L(e))return{success:!0,data:e.value};if(!r.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let t=new S(r.common.issues);return this._error=t,this._error}}};function g(r){if(!r)return{};let{errorMap:e,invalid_type_error:t,required_error:s,description:n}=r;if(e&&(t||s))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:n}:{errorMap:(i,o)=>{let{message:u}=r;return i.code==="invalid_enum_value"?{message:u??o.defaultError}:typeof o.data>"u"?{message:u??s??o.defaultError}:i.code!=="invalid_type"?{message:o.defaultError}:{message:u??t??o.defaultError}},description:n}}var _=class{get description(){return this._def.description}_getType(e){return N(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:N(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new w,ctx:{common:e.parent.common,data:e.data,parsedType:N(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){let t=this._parse(e);if(ue(t))throw new Error("Synchronous parse encountered promise.");return t}_parseAsync(e){let t=this._parse(e);return Promise.resolve(t)}parse(e,t){let s=this.safeParse(e,t);if(s.success)return s.data;throw s.error}safeParse(e,t){let s={common:{issues:[],async:t?.async??!1,contextualErrorMap:t?.errorMap},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:N(e)},n=this._parseSync({data:e,path:s.path,parent:s});return Le(s,n)}"~validate"(e){let t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:N(e)};if(!this["~standard"].async)try{let s=this._parseSync({data:e,path:[],parent:t});return L(s)?{value:s.value}:{issues:t.common.issues}}catch(s){s?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then(s=>L(s)?{value:s.value}:{issues:t.common.issues})}async parseAsync(e,t){let s=await this.safeParseAsync(e,t);if(s.success)return s.data;throw s.error}async safeParseAsync(e,t){let s={common:{issues:[],contextualErrorMap:t?.errorMap,async:!0},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:N(e)},n=this._parse({data:e,path:s.path,parent:s}),a=await(ue(n)?n:Promise.resolve(n));return Le(s,a)}refine(e,t){let s=n=>typeof t=="string"||typeof t>"u"?{message:t}:typeof t=="function"?t(n):t;return this._refinement((n,a)=>{let i=e(n),o=()=>a.addIssue({code:c.custom,...s(n)});return typeof Promise<"u"&&i instanceof Promise?i.then(u=>u?!0:(o(),!1)):i?!0:(o(),!1)})}refinement(e,t){return this._refinement((s,n)=>e(s)?!0:(n.addIssue(typeof t=="function"?t(s,n):t),!1))}_refinement(e){return new O({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:t=>this["~validate"](t)}}optional(){return I.create(this,this._def)}nullable(){return $.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return Z.create(this)}promise(){return F.create(this,this._def)}or(e){return Q.create([this,e],this._def)}and(e){return X.create(this,e,this._def)}transform(e){return new O({...g(this._def),schema:this,typeName:y.ZodEffects,effect:{type:"transform",transform:e}})}default(e){let t=typeof e=="function"?e:()=>e;return new ne({...g(this._def),innerType:this,defaultValue:t,typeName:y.ZodDefault})}brand(){return new ve({typeName:y.ZodBranded,type:this,...g(this._def)})}catch(e){let t=typeof e=="function"?e:()=>e;return new ae({...g(this._def),innerType:this,catchValue:t,typeName:y.ZodCatch})}describe(e){let t=this.constructor;return new t({...this._def,description:e})}pipe(e){return _e.create(this,e)}readonly(){return ie.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}},vt=/^c[^\s-]{8,}$/i,_t=/^[0-9a-z]+$/,xt=/^[0-9A-HJKMNP-TV-Z]{26}$/i,kt=/^[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,bt=/^[a-z0-9_-]{21}$/i,wt=/^[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)?)??$/,St=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Tt="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",Ae,Ct=/^(?:(?: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])$/,It=/^(?:(?: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]))$/,Ot=/^(([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])$/,At=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Nt=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Be="((\\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])))",jt=new RegExp(`^${Be}$`);function Fe(r){let e="[0-5]\\d";r.precision?e=`${e}\\.\\d{${r.precision}}`:r.precision==null&&(e=`${e}(\\.\\d+)?`);let t=r.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${t}`}function $t(r){return new RegExp(`^${Fe(r)}$`)}function qe(r){let e=`${Be}T${Fe(r)}`,t=[];return t.push(r.local?"Z?":"Z"),r.offset&&t.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${t.join("|")})`,new RegExp(`^${e}$`)}function Pt(r,e){return!!((e==="v4"||!e)&&Ct.test(r)||(e==="v6"||!e)&&Rt.test(r))}function Dt(r,e){if(!wt.test(r))return!1;try{let[t]=r.split(".");if(!t)return!1;let s=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(t.length+(4-t.length%4)%4,"="),n=JSON.parse(atob(s));return!(typeof n!="object"||n===null||"typ"in n&&n?.typ!=="JWT"||!n.alg||e&&n.alg!==e)}catch{return!1}}function Mt(r,e){return!!((e==="v4"||!e)&&It.test(r)||(e==="v6"||!e)&&Ot.test(r))}var U=class r extends _{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==f.string){let a=this._getOrReturnCtx(e);return l(a,{code:c.invalid_type,expected:f.string,received:a.parsedType}),h}let s=new w,n;for(let a of this._def.checks)if(a.kind==="min")e.data.length<a.value&&(n=this._getOrReturnCtx(e,n),l(n,{code:c.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&&(n=this._getOrReturnCtx(e,n),l(n,{code:c.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),s.dirty());else if(a.kind==="length"){let i=e.data.length>a.value,o=e.data.length<a.value;(i||o)&&(n=this._getOrReturnCtx(e,n),i?l(n,{code:c.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}):o&&l(n,{code:c.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}),s.dirty())}else if(a.kind==="email")St.test(e.data)||(n=this._getOrReturnCtx(e,n),l(n,{validation:"email",code:c.invalid_string,message:a.message}),s.dirty());else if(a.kind==="emoji")Ae||(Ae=new RegExp(Tt,"u")),Ae.test(e.data)||(n=this._getOrReturnCtx(e,n),l(n,{validation:"emoji",code:c.invalid_string,message:a.message}),s.dirty());else if(a.kind==="uuid")kt.test(e.data)||(n=this._getOrReturnCtx(e,n),l(n,{validation:"uuid",code:c.invalid_string,message:a.message}),s.dirty());else if(a.kind==="nanoid")bt.test(e.data)||(n=this._getOrReturnCtx(e,n),l(n,{validation:"nanoid",code:c.invalid_string,message:a.message}),s.dirty());else if(a.kind==="cuid")vt.test(e.data)||(n=this._getOrReturnCtx(e,n),l(n,{validation:"cuid",code:c.invalid_string,message:a.message}),s.dirty());else if(a.kind==="cuid2")_t.test(e.data)||(n=this._getOrReturnCtx(e,n),l(n,{validation:"cuid2",code:c.invalid_string,message:a.message}),s.dirty());else if(a.kind==="ulid")xt.test(e.data)||(n=this._getOrReturnCtx(e,n),l(n,{validation:"ulid",code:c.invalid_string,message:a.message}),s.dirty());else if(a.kind==="url")try{new URL(e.data)}catch{n=this._getOrReturnCtx(e,n),l(n,{validation:"url",code:c.invalid_string,message:a.message}),s.dirty()}else a.kind==="regex"?(a.regex.lastIndex=0,a.regex.test(e.data)||(n=this._getOrReturnCtx(e,n),l(n,{validation:"regex",code:c.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)||(n=this._getOrReturnCtx(e,n),l(n,{code:c.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)||(n=this._getOrReturnCtx(e,n),l(n,{code:c.invalid_string,validation:{startsWith:a.value},message:a.message}),s.dirty()):a.kind==="endsWith"?e.data.endsWith(a.value)||(n=this._getOrReturnCtx(e,n),l(n,{code:c.invalid_string,validation:{endsWith:a.value},message:a.message}),s.dirty()):a.kind==="datetime"?qe(a).test(e.data)||(n=this._getOrReturnCtx(e,n),l(n,{code:c.invalid_string,validation:"datetime",message:a.message}),s.dirty()):a.kind==="date"?jt.test(e.data)||(n=this._getOrReturnCtx(e,n),l(n,{code:c.invalid_string,validation:"date",message:a.message}),s.dirty()):a.kind==="time"?$t(a).test(e.data)||(n=this._getOrReturnCtx(e,n),l(n,{code:c.invalid_string,validation:"time",message:a.message}),s.dirty()):a.kind==="duration"?Et.test(e.data)||(n=this._getOrReturnCtx(e,n),l(n,{validation:"duration",code:c.invalid_string,message:a.message}),s.dirty()):a.kind==="ip"?Pt(e.data,a.version)||(n=this._getOrReturnCtx(e,n),l(n,{validation:"ip",code:c.invalid_string,message:a.message}),s.dirty()):a.kind==="jwt"?Dt(e.data,a.alg)||(n=this._getOrReturnCtx(e,n),l(n,{validation:"jwt",code:c.invalid_string,message:a.message}),s.dirty()):a.kind==="cidr"?Mt(e.data,a.version)||(n=this._getOrReturnCtx(e,n),l(n,{validation:"cidr",code:c.invalid_string,message:a.message}),s.dirty()):a.kind==="base64"?At.test(e.data)||(n=this._getOrReturnCtx(e,n),l(n,{validation:"base64",code:c.invalid_string,message:a.message}),s.dirty()):a.kind==="base64url"?Nt.test(e.data)||(n=this._getOrReturnCtx(e,n),l(n,{validation:"base64url",code:c.invalid_string,message:a.message}),s.dirty()):x.assertNever(a);return{status:s.value,value:e.data}}_regex(e,t,s){return this.refinement(n=>e.test(n),{validation:t,code:c.invalid_string,...m.errToObj(s)})}_addCheck(e){return new r({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...m.errToObj(e)})}url(e){return this._addCheck({kind:"url",...m.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...m.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...m.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...m.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...m.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...m.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...m.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...m.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...m.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...m.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...m.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...m.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,...m.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,...m.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...m.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...m.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t?.position,...m.errToObj(t?.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...m.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...m.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...m.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...m.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...m.errToObj(t)})}nonempty(e){return this.min(1,m.errToObj(e))}trim(){return new r({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new r({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new r({...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(let t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(let t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}};U.create=r=>new U({checks:[],typeName:y.ZodString,coerce:r?.coerce??!1,...g(r)});function Zt(r,e){let t=(r.toString().split(".")[1]||"").length,s=(e.toString().split(".")[1]||"").length,n=t>s?t:s,a=Number.parseInt(r.toFixed(n).replace(".","")),i=Number.parseInt(e.toFixed(n).replace(".",""));return a%i/10**n}var W=class r extends _{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){let a=this._getOrReturnCtx(e);return l(a,{code:c.invalid_type,expected:f.number,received:a.parsedType}),h}let s,n=new w;for(let a of this._def.checks)a.kind==="int"?x.isInteger(e.data)||(s=this._getOrReturnCtx(e,s),l(s,{code:c.invalid_type,expected:"integer",received:"float",message:a.message}),n.dirty()):a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(s=this._getOrReturnCtx(e,s),l(s,{code:c.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),n.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(s=this._getOrReturnCtx(e,s),l(s,{code:c.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),n.dirty()):a.kind==="multipleOf"?Zt(e.data,a.value)!==0&&(s=this._getOrReturnCtx(e,s),l(s,{code:c.not_multiple_of,multipleOf:a.value,message:a.message}),n.dirty()):a.kind==="finite"?Number.isFinite(e.data)||(s=this._getOrReturnCtx(e,s),l(s,{code:c.not_finite,message:a.message}),n.dirty()):x.assertNever(a);return{status:n.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,m.toString(t))}gt(e,t){return this.setLimit("min",e,!1,m.toString(t))}lte(e,t){return this.setLimit("max",e,!0,m.toString(t))}lt(e,t){return this.setLimit("max",e,!1,m.toString(t))}setLimit(e,t,s,n){return new r({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:s,message:m.toString(n)}]})}_addCheck(e){return new r({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:m.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:m.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:m.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:m.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:m.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:m.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:m.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:m.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:m.toString(e)})}get minValue(){let e=null;for(let t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(let t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&x.isInteger(e.value))}get isFinite(){let e=null,t=null;for(let s of this._def.checks){if(s.kind==="finite"||s.kind==="int"||s.kind==="multipleOf")return!0;s.kind==="min"?(t===null||s.value>t)&&(t=s.value):s.kind==="max"&&(e===null||s.value<e)&&(e=s.value)}return Number.isFinite(t)&&Number.isFinite(e)}};W.create=r=>new W({checks:[],typeName:y.ZodNumber,coerce:r?.coerce||!1,...g(r)});var H=class r extends _{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,n=new w;for(let 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:c.too_small,type:"bigint",minimum:a.value,inclusive:a.inclusive,message:a.message}),n.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(s=this._getOrReturnCtx(e,s),l(s,{code:c.too_big,type:"bigint",maximum:a.value,inclusive:a.inclusive,message:a.message}),n.dirty()):a.kind==="multipleOf"?e.data%a.value!==BigInt(0)&&(s=this._getOrReturnCtx(e,s),l(s,{code:c.not_multiple_of,multipleOf:a.value,message:a.message}),n.dirty()):x.assertNever(a);return{status:n.value,value:e.data}}_getInvalidInput(e){let t=this._getOrReturnCtx(e);return l(t,{code:c.invalid_type,expected:f.bigint,received:t.parsedType}),h}gte(e,t){return this.setLimit("min",e,!0,m.toString(t))}gt(e,t){return this.setLimit("min",e,!1,m.toString(t))}lte(e,t){return this.setLimit("max",e,!0,m.toString(t))}lt(e,t){return this.setLimit("max",e,!1,m.toString(t))}setLimit(e,t,s,n){return new r({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:s,message:m.toString(n)}]})}_addCheck(e){return new r({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:m.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:m.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:m.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:m.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:m.toString(t)})}get minValue(){let e=null;for(let t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(let t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}};H.create=r=>new H({checks:[],typeName:y.ZodBigInt,coerce:r?.coerce??!1,...g(r)});var J=class extends _{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==f.boolean){let s=this._getOrReturnCtx(e);return l(s,{code:c.invalid_type,expected:f.boolean,received:s.parsedType}),h}return E(e.data)}};J.create=r=>new J({typeName:y.ZodBoolean,coerce:r?.coerce||!1,...g(r)});var Y=class r extends _{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==f.date){let a=this._getOrReturnCtx(e);return l(a,{code:c.invalid_type,expected:f.date,received:a.parsedType}),h}if(Number.isNaN(e.data.getTime())){let a=this._getOrReturnCtx(e);return l(a,{code:c.invalid_date}),h}let s=new w,n;for(let a of this._def.checks)a.kind==="min"?e.data.getTime()<a.value&&(n=this._getOrReturnCtx(e,n),l(n,{code:c.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),s.dirty()):a.kind==="max"?e.data.getTime()>a.value&&(n=this._getOrReturnCtx(e,n),l(n,{code:c.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),s.dirty()):x.assertNever(a);return{status:s.value,value:new Date(e.data.getTime())}}_addCheck(e){return new r({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:m.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:m.toString(t)})}get minDate(){let e=null;for(let t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(let t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e!=null?new Date(e):null}};Y.create=r=>new Y({checks:[],coerce:r?.coerce||!1,typeName:y.ZodDate,...g(r)});var pe=class extends _{_parse(e){if(this._getType(e)!==f.symbol){let s=this._getOrReturnCtx(e);return l(s,{code:c.invalid_type,expected:f.symbol,received:s.parsedType}),h}return E(e.data)}};pe.create=r=>new pe({typeName:y.ZodSymbol,...g(r)});var K=class extends _{_parse(e){if(this._getType(e)!==f.undefined){let s=this._getOrReturnCtx(e);return l(s,{code:c.invalid_type,expected:f.undefined,received:s.parsedType}),h}return E(e.data)}};K.create=r=>new K({typeName:y.ZodUndefined,...g(r)});var G=class extends _{_parse(e){if(this._getType(e)!==f.null){let s=this._getOrReturnCtx(e);return l(s,{code:c.invalid_type,expected:f.null,received:s.parsedType}),h}return E(e.data)}};G.create=r=>new G({typeName:y.ZodNull,...g(r)});var B=class extends _{constructor(){super(...arguments),this._any=!0}_parse(e){return E(e.data)}};B.create=r=>new B({typeName:y.ZodAny,...g(r)});var M=class extends _{constructor(){super(...arguments),this._unknown=!0}_parse(e){return E(e.data)}};M.create=r=>new M({typeName:y.ZodUnknown,...g(r)});var A=class extends _{_parse(e){let t=this._getOrReturnCtx(e);return l(t,{code:c.invalid_type,expected:f.never,received:t.parsedType}),h}};A.create=r=>new A({typeName:y.ZodNever,...g(r)});var fe=class extends _{_parse(e){if(this._getType(e)!==f.undefined){let s=this._getOrReturnCtx(e);return l(s,{code:c.invalid_type,expected:f.void,received:s.parsedType}),h}return E(e.data)}};fe.create=r=>new fe({typeName:y.ZodVoid,...g(r)});var Z=class r extends _{_parse(e){let{ctx:t,status:s}=this._processInputParams(e),n=this._def;if(t.parsedType!==f.array)return l(t,{code:c.invalid_type,expected:f.array,received:t.parsedType}),h;if(n.exactLength!==null){let i=t.data.length>n.exactLength.value,o=t.data.length<n.exactLength.value;(i||o)&&(l(t,{code:i?c.too_big:c.too_small,minimum:o?n.exactLength.value:void 0,maximum:i?n.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:n.exactLength.message}),s.dirty())}if(n.minLength!==null&&t.data.length<n.minLength.value&&(l(t,{code:c.too_small,minimum:n.minLength.value,type:"array",inclusive:!0,exact:!1,message:n.minLength.message}),s.dirty()),n.maxLength!==null&&t.data.length>n.maxLength.value&&(l(t,{code:c.too_big,maximum:n.maxLength.value,type:"array",inclusive:!0,exact:!1,message:n.maxLength.message}),s.dirty()),t.common.async)return Promise.all([...t.data].map((i,o)=>n.type._parseAsync(new R(t,i,t.path,o)))).then(i=>w.mergeArray(s,i));let a=[...t.data].map((i,o)=>n.type._parseSync(new R(t,i,t.path,o)));return w.mergeArray(s,a)}get element(){return this._def.type}min(e,t){return new r({...this._def,minLength:{value:e,message:m.toString(t)}})}max(e,t){return new r({...this._def,maxLength:{value:e,message:m.toString(t)}})}length(e,t){return new r({...this._def,exactLength:{value:e,message:m.toString(t)}})}nonempty(e){return this.min(1,e)}};Z.create=(r,e)=>new Z({type:r,minLength:null,maxLength:null,exactLength:null,typeName:y.ZodArray,...g(e)});function le(r){if(r instanceof T){let e={};for(let t in r.shape){let s=r.shape[t];e[t]=I.create(le(s))}return new T({...r._def,shape:()=>e})}else return r instanceof Z?new Z({...r._def,type:le(r.element)}):r instanceof I?I.create(le(r.unwrap())):r instanceof $?$.create(le(r.unwrap())):r instanceof j?j.create(r.items.map(e=>le(e))):r}var T=class r extends _{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let e=this._def.shape(),t=x.objectKeys(e);return this._cached={shape:e,keys:t},this._cached}_parse(e){if(this._getType(e)!==f.object){let p=this._getOrReturnCtx(e);return l(p,{code:c.invalid_type,expected:f.object,received:p.parsedType}),h}let{status:s,ctx:n}=this._processInputParams(e),{shape:a,keys:i}=this._getCached(),o=[];if(!(this._def.catchall instanceof A&&this._def.unknownKeys==="strip"))for(let p in n.data)i.includes(p)||o.push(p);let u=[];for(let p of i){let v=a[p],b=n.data[p];u.push({key:{status:"valid",value:p},value:v._parse(new R(n,b,n.path,p)),alwaysSet:p in n.data})}if(this._def.catchall instanceof A){let p=this._def.unknownKeys;if(p==="passthrough")for(let v of o)u.push({key:{status:"valid",value:v},value:{status:"valid",value:n.data[v]}});else if(p==="strict")o.length>0&&(l(n,{code:c.unrecognized_keys,keys:o}),s.dirty());else if(p!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{let p=this._def.catchall;for(let v of o){let b=n.data[v];u.push({key:{status:"valid",value:v},value:p._parse(new R(n,b,n.path,v)),alwaysSet:v in n.data})}}return n.common.async?Promise.resolve().then(async()=>{let p=[];for(let v of u){let b=await v.key,oe=await v.value;p.push({key:b,value:oe,alwaysSet:v.alwaysSet})}return p}).then(p=>w.mergeObjectSync(s,p)):w.mergeObjectSync(s,u)}get shape(){return this._def.shape()}strict(e){return m.errToObj,new r({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,s)=>{let n=this._def.errorMap?.(t,s).message??s.defaultError;return t.code==="unrecognized_keys"?{message:m.errToObj(e).message??n}:{message:n}}}:{}})}strip(){return new r({...this._def,unknownKeys:"strip"})}passthrough(){return new r({...this._def,unknownKeys:"passthrough"})}extend(e){return new r({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new r({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:y.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new r({...this._def,catchall:e})}pick(e){let t={};for(let s of x.objectKeys(e))e[s]&&this.shape[s]&&(t[s]=this.shape[s]);return new r({...this._def,shape:()=>t})}omit(e){let t={};for(let s of x.objectKeys(this.shape))e[s]||(t[s]=this.shape[s]);return new r({...this._def,shape:()=>t})}deepPartial(){return le(this)}partial(e){let t={};for(let s of x.objectKeys(this.shape)){let n=this.shape[s];e&&!e[s]?t[s]=n:t[s]=n.optional()}return new r({...this._def,shape:()=>t})}required(e){let t={};for(let s of x.objectKeys(this.shape))if(e&&!e[s])t[s]=this.shape[s];else{let a=this.shape[s];for(;a instanceof I;)a=a._def.innerType;t[s]=a}return new r({...this._def,shape:()=>t})}keyof(){return We(x.objectKeys(this.shape))}};T.create=(r,e)=>new T({shape:()=>r,unknownKeys:"strip",catchall:A.create(),typeName:y.ZodObject,...g(e)});T.strictCreate=(r,e)=>new T({shape:()=>r,unknownKeys:"strict",catchall:A.create(),typeName:y.ZodObject,...g(e)});T.lazycreate=(r,e)=>new T({shape:r,unknownKeys:"strip",catchall:A.create(),typeName:y.ZodObject,...g(e)});var Q=class extends _{_parse(e){let{ctx:t}=this._processInputParams(e),s=this._def.options;function n(a){for(let o of a)if(o.result.status==="valid")return o.result;for(let o of a)if(o.result.status==="dirty")return t.common.issues.push(...o.ctx.common.issues),o.result;let i=a.map(o=>new S(o.ctx.common.issues));return l(t,{code:c.invalid_union,unionErrors:i}),h}if(t.common.async)return Promise.all(s.map(async a=>{let i={...t,common:{...t.common,issues:[]},parent:null};return{result:await a._parseAsync({data:t.data,path:t.path,parent:i}),ctx:i}})).then(n);{let a,i=[];for(let u of s){let p={...t,common:{...t.common,issues:[]},parent:null},v=u._parseSync({data:t.data,path:t.path,parent:p});if(v.status==="valid")return v;v.status==="dirty"&&!a&&(a={result:v,ctx:p}),p.common.issues.length&&i.push(p.common.issues)}if(a)return t.common.issues.push(...a.ctx.common.issues),a.result;let o=i.map(u=>new S(u));return l(t,{code:c.invalid_union,unionErrors:o}),h}}get options(){return this._def.options}};Q.create=(r,e)=>new Q({options:r,typeName:y.ZodUnion,...g(e)});var D=r=>r instanceof ee?D(r.schema):r instanceof O?D(r.innerType()):r instanceof te?[r.value]:r instanceof re?r.options:r instanceof se?x.objectValues(r.enum):r instanceof ne?D(r._def.innerType):r instanceof K?[void 0]:r instanceof G?[null]:r instanceof I?[void 0,...D(r.unwrap())]:r instanceof $?[null,...D(r.unwrap())]:r instanceof ve||r instanceof ie?D(r.unwrap()):r instanceof ae?D(r._def.innerType):[],Te=class r extends _{_parse(e){let{ctx:t}=this._processInputParams(e);if(t.parsedType!==f.object)return l(t,{code:c.invalid_type,expected:f.object,received:t.parsedType}),h;let s=this.discriminator,n=t.data[s],a=this.optionsMap.get(n);return a?t.common.async?a._parseAsync({data:t.data,path:t.path,parent:t}):a._parseSync({data:t.data,path:t.path,parent:t}):(l(t,{code:c.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[s]}),h)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,t,s){let n=new Map;for(let a of t){let i=D(a.shape[e]);if(!i.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(let o of i){if(n.has(o))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(o)}`);n.set(o,a)}}return new r({typeName:y.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:n,...g(s)})}};function Ne(r,e){let t=N(r),s=N(e);if(r===e)return{valid:!0,data:r};if(t===f.object&&s===f.object){let n=x.objectKeys(e),a=x.objectKeys(r).filter(o=>n.indexOf(o)!==-1),i={...r,...e};for(let o of a){let u=Ne(r[o],e[o]);if(!u.valid)return{valid:!1};i[o]=u.data}return{valid:!0,data:i}}else if(t===f.array&&s===f.array){if(r.length!==e.length)return{valid:!1};let n=[];for(let a=0;a<r.length;a++){let i=r[a],o=e[a],u=Ne(i,o);if(!u.valid)return{valid:!1};n.push(u.data)}return{valid:!0,data:n}}else return t===f.date&&s===f.date&&+r==+e?{valid:!0,data:r}:{valid:!1}}var X=class extends _{_parse(e){let{status:t,ctx:s}=this._processInputParams(e),n=(a,i)=>{if(Ee(a)||Ee(i))return h;let o=Ne(a.value,i.value);return o.valid?((Se(a)||Se(i))&&t.dirty(),{status:t.value,value:o.data}):(l(s,{code:c.invalid_intersection_types}),h)};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])=>n(a,i)):n(this._def.left._parseSync({data:s.data,path:s.path,parent:s}),this._def.right._parseSync({data:s.data,path:s.path,parent:s}))}};X.create=(r,e,t)=>new X({left:r,right:e,typeName:y.ZodIntersection,...g(t)});var j=class r extends _{_parse(e){let{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==f.array)return l(s,{code:c.invalid_type,expected:f.array,received:s.parsedType}),h;if(s.data.length<this._def.items.length)return l(s,{code:c.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),h;!this._def.rest&&s.data.length>this._def.items.length&&(l(s,{code:c.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());let a=[...s.data].map((i,o)=>{let u=this._def.items[o]||this._def.rest;return u?u._parse(new R(s,i,s.path,o)):null}).filter(i=>!!i);return s.common.async?Promise.all(a).then(i=>w.mergeArray(t,i)):w.mergeArray(t,a)}get items(){return this._def.items}rest(e){return new r({...this._def,rest:e})}};j.create=(r,e)=>{if(!Array.isArray(r))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new j({items:r,typeName:y.ZodTuple,rest:null,...g(e)})};var Ce=class r extends _{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==f.object)return l(s,{code:c.invalid_type,expected:f.object,received:s.parsedType}),h;let n=[],a=this._def.keyType,i=this._def.valueType;for(let o in s.data)n.push({key:a._parse(new R(s,o,s.path,o)),value:i._parse(new R(s,s.data[o],s.path,o)),alwaysSet:o in s.data});return s.common.async?w.mergeObjectAsync(t,n):w.mergeObjectSync(t,n)}get element(){return this._def.valueType}static create(e,t,s){return t instanceof _?new r({keyType:e,valueType:t,typeName:y.ZodRecord,...g(s)}):new r({keyType:U.create(),valueType:e,typeName:y.ZodRecord,...g(t)})}},me=class extends _{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==f.map)return l(s,{code:c.invalid_type,expected:f.map,received:s.parsedType}),h;let n=this._def.keyType,a=this._def.valueType,i=[...s.data.entries()].map(([o,u],p)=>({key:n._parse(new R(s,o,s.path,[p,"key"])),value:a._parse(new R(s,u,s.path,[p,"value"]))}));if(s.common.async){let o=new Map;return Promise.resolve().then(async()=>{for(let u of i){let p=await u.key,v=await u.value;if(p.status==="aborted"||v.status==="aborted")return h;(p.status==="dirty"||v.status==="dirty")&&t.dirty(),o.set(p.value,v.value)}return{status:t.value,value:o}})}else{let o=new Map;for(let u of i){let p=u.key,v=u.value;if(p.status==="aborted"||v.status==="aborted")return h;(p.status==="dirty"||v.status==="dirty")&&t.dirty(),o.set(p.value,v.value)}return{status:t.value,value:o}}}};me.create=(r,e,t)=>new me({valueType:e,keyType:r,typeName:y.ZodMap,...g(t)});var he=class r extends _{_parse(e){let{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==f.set)return l(s,{code:c.invalid_type,expected:f.set,received:s.parsedType}),h;let n=this._def;n.minSize!==null&&s.data.size<n.minSize.value&&(l(s,{code:c.too_small,minimum:n.minSize.value,type:"set",inclusive:!0,exact:!1,message:n.minSize.message}),t.dirty()),n.maxSize!==null&&s.data.size>n.maxSize.value&&(l(s,{code:c.too_big,maximum:n.maxSize.value,type:"set",inclusive:!0,exact:!1,message:n.maxSize.message}),t.dirty());let a=this._def.valueType;function i(u){let p=new Set;for(let v of u){if(v.status==="aborted")return h;v.status==="dirty"&&t.dirty(),p.add(v.value)}return{status:t.value,value:p}}let o=[...s.data.values()].map((u,p)=>a._parse(new R(s,u,s.path,p)));return s.common.async?Promise.all(o).then(u=>i(u)):i(o)}min(e,t){return new r({...this._def,minSize:{value:e,message:m.toString(t)}})}max(e,t){return new r({...this._def,maxSize:{value:e,message:m.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}};he.create=(r,e)=>new he({valueType:r,minSize:null,maxSize:null,typeName:y.ZodSet,...g(e)});var Ie=class r extends _{constructor(){super(...arguments),this.validate=this.implement}_parse(e){let{ctx:t}=this._processInputParams(e);if(t.parsedType!==f.function)return l(t,{code:c.invalid_type,expected:f.function,received:t.parsedType}),h;function s(o,u){return ge({data:o,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,de(),P].filter(p=>!!p),issueData:{code:c.invalid_arguments,argumentsError:u}})}function n(o,u){return ge({data:o,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,de(),P].filter(p=>!!p),issueData:{code:c.invalid_return_type,returnTypeError:u}})}let a={errorMap:t.common.contextualErrorMap},i=t.data;if(this._def.returns instanceof F){let o=this;return E(async function(...u){let p=new S([]),v=await o._def.args.parseAsync(u,a).catch(ce=>{throw p.addIssue(s(u,ce)),p}),b=await Reflect.apply(i,this,v);return await o._def.returns._def.type.parseAsync(b,a).catch(ce=>{throw p.addIssue(n(b,ce)),p})})}else{let o=this;return E(function(...u){let p=o._def.args.safeParse(u,a);if(!p.success)throw new S([s(u,p.error)]);let v=Reflect.apply(i,this,p.data),b=o._def.returns.safeParse(v,a);if(!b.success)throw new S([n(v,b.error)]);return b.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new r({...this._def,args:j.create(e).rest(M.create())})}returns(e){return new r({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,t,s){return new r({args:e||j.create([]).rest(M.create()),returns:t||M.create(),typeName:y.ZodFunction,...g(s)})}},ee=class extends _{get schema(){return this._def.getter()}_parse(e){let{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}};ee.create=(r,e)=>new ee({getter:r,typeName:y.ZodLazy,...g(e)});var te=class extends _{_parse(e){if(e.data!==this._def.value){let t=this._getOrReturnCtx(e);return l(t,{received:t.data,code:c.invalid_literal,expected:this._def.value}),h}return{status:"valid",value:e.data}}get value(){return this._def.value}};te.create=(r,e)=>new te({value:r,typeName:y.ZodLiteral,...g(e)});function We(r,e){return new re({values:r,typeName:y.ZodEnum,...g(e)})}var re=class r extends _{_parse(e){if(typeof e.data!="string"){let t=this._getOrReturnCtx(e),s=this._def.values;return l(t,{expected:x.joinValues(s),received:t.parsedType,code:c.invalid_type}),h}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){let t=this._getOrReturnCtx(e),s=this._def.values;return l(t,{received:t.data,code:c.invalid_enum_value,options:s}),h}return E(e.data)}get options(){return this._def.values}get enum(){let e={};for(let t of this._def.values)e[t]=t;return e}get Values(){let e={};for(let t of this._def.values)e[t]=t;return e}get Enum(){let e={};for(let t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return r.create(e,{...this._def,...t})}exclude(e,t=this._def){return r.create(this.options.filter(s=>!e.includes(s)),{...this._def,...t})}};re.create=We;var se=class extends _{_parse(e){let t=x.getValidEnumValues(this._def.values),s=this._getOrReturnCtx(e);if(s.parsedType!==f.string&&s.parsedType!==f.number){let n=x.objectValues(t);return l(s,{expected:x.joinValues(n),received:s.parsedType,code:c.invalid_type}),h}if(this._cache||(this._cache=new Set(x.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){let n=x.objectValues(t);return l(s,{received:s.data,code:c.invalid_enum_value,options:n}),h}return E(e.data)}get enum(){return this._def.values}};se.create=(r,e)=>new se({values:r,typeName:y.ZodNativeEnum,...g(e)});var F=class extends _{unwrap(){return this._def.type}_parse(e){let{ctx:t}=this._processInputParams(e);if(t.parsedType!==f.promise&&t.common.async===!1)return l(t,{code:c.invalid_type,expected:f.promise,received:t.parsedType}),h;let s=t.parsedType===f.promise?t.data:Promise.resolve(t.data);return E(s.then(n=>this._def.type.parseAsync(n,{path:t.path,errorMap:t.common.contextualErrorMap})))}};F.create=(r,e)=>new F({type:r,typeName:y.ZodPromise,...g(e)});var O=class extends _{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===y.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){let{status:t,ctx:s}=this._processInputParams(e),n=this._def.effect||null,a={addIssue:i=>{l(s,i),i.fatal?t.abort():t.dirty()},get path(){return s.path}};if(a.addIssue=a.addIssue.bind(a),n.type==="preprocess"){let i=n.transform(s.data,a);if(s.common.async)return Promise.resolve(i).then(async o=>{if(t.value==="aborted")return h;let u=await this._def.schema._parseAsync({data:o,path:s.path,parent:s});return u.status==="aborted"?h:u.status==="dirty"?q(u.value):t.value==="dirty"?q(u.value):u});{if(t.value==="aborted")return h;let o=this._def.schema._parseSync({data:i,path:s.path,parent:s});return o.status==="aborted"?h:o.status==="dirty"?q(o.value):t.value==="dirty"?q(o.value):o}}if(n.type==="refinement"){let i=o=>{let u=n.refinement(o,a);if(s.common.async)return Promise.resolve(u);if(u instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return o};if(s.common.async===!1){let o=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});return o.status==="aborted"?h:(o.status==="dirty"&&t.dirty(),i(o.value),{status:t.value,value:o.value})}else return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then(o=>o.status==="aborted"?h:(o.status==="dirty"&&t.dirty(),i(o.value).then(()=>({status:t.value,value:o.value}))))}if(n.type==="transform")if(s.common.async===!1){let i=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});if(!L(i))return h;let o=n.transform(i.value,a);if(o instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:o}}else return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then(i=>L(i)?Promise.resolve(n.transform(i.value,a)).then(o=>({status:t.value,value:o})):h);x.assertNever(n)}};O.create=(r,e,t)=>new O({schema:r,typeName:y.ZodEffects,effect:e,...g(t)});O.createWithPreprocess=(r,e,t)=>new O({schema:e,effect:{type:"preprocess",transform:r},typeName:y.ZodEffects,...g(t)});var I=class extends _{_parse(e){return this._getType(e)===f.undefined?E(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};I.create=(r,e)=>new I({innerType:r,typeName:y.ZodOptional,...g(e)});var $=class extends _{_parse(e){return this._getType(e)===f.null?E(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};$.create=(r,e)=>new $({innerType:r,typeName:y.ZodNullable,...g(e)});var ne=class extends _{_parse(e){let{ctx:t}=this._processInputParams(e),s=t.data;return t.parsedType===f.undefined&&(s=this._def.defaultValue()),this._def.innerType._parse({data:s,path:t.path,parent:t})}removeDefault(){return this._def.innerType}};ne.create=(r,e)=>new ne({innerType:r,typeName:y.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...g(e)});var ae=class extends _{_parse(e){let{ctx:t}=this._processInputParams(e),s={...t,common:{...t.common,issues:[]}},n=this._def.innerType._parse({data:s.data,path:s.path,parent:{...s}});return ue(n)?n.then(a=>({status:"valid",value:a.status==="valid"?a.value:this._def.catchValue({get error(){return new S(s.common.issues)},input:s.data})})):{status:"valid",value:n.status==="valid"?n.value:this._def.catchValue({get error(){return new S(s.common.issues)},input:s.data})}}removeCatch(){return this._def.innerType}};ae.create=(r,e)=>new ae({innerType:r,typeName:y.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...g(e)});var ye=class extends _{_parse(e){if(this._getType(e)!==f.nan){let s=this._getOrReturnCtx(e);return l(s,{code:c.invalid_type,expected:f.nan,received:s.parsedType}),h}return{status:"valid",value:e.data}}};ye.create=r=>new ye({typeName:y.ZodNaN,...g(r)});var Vt=Symbol("zod_brand"),ve=class extends _{_parse(e){let{ctx:t}=this._processInputParams(e),s=t.data;return this._def.type._parse({data:s,path:t.path,parent:t})}unwrap(){return this._def.type}},_e=class r extends _{_parse(e){let{status:t,ctx:s}=this._processInputParams(e);if(s.common.async)return(async()=>{let a=await this._def.in._parseAsync({data:s.data,path:s.path,parent:s});return a.status==="aborted"?h:a.status==="dirty"?(t.dirty(),q(a.value)):this._def.out._parseAsync({data:a.value,path:s.path,parent:s})})();{let n=this._def.in._parseSync({data:s.data,path:s.path,parent:s});return n.status==="aborted"?h:n.status==="dirty"?(t.dirty(),{status:"dirty",value:n.value}):this._def.out._parseSync({data:n.value,path:s.path,parent:s})}}static create(e,t){return new r({in:e,out:t,typeName:y.ZodPipeline})}},ie=class extends _{_parse(e){let t=this._def.innerType._parse(e),s=n=>(L(n)&&(n.value=Object.freeze(n.value)),n);return ue(t)?t.then(n=>s(n)):s(t)}unwrap(){return this._def.innerType}};ie.create=(r,e)=>new ie({innerType:r,typeName:y.ZodReadonly,...g(e)});function Ue(r,e){let t=typeof r=="function"?r(e):typeof r=="string"?{message:r}:r;return typeof t=="string"?{message:t}:t}function He(r,e={},t){return r?B.create().superRefine((s,n)=>{let a=r(s);if(a instanceof Promise)return a.then(i=>{if(!i){let o=Ue(e,s),u=o.fatal??t??!0;n.addIssue({code:"custom",...o,fatal:u})}});if(!a){let i=Ue(e,s),o=i.fatal??t??!0;n.addIssue({code:"custom",...i,fatal:o})}}):B.create()}var zt={object:T.lazycreate},y;(function(r){r.ZodString="ZodString",r.ZodNumber="ZodNumber",r.ZodNaN="ZodNaN",r.ZodBigInt="ZodBigInt",r.ZodBoolean="ZodBoolean",r.ZodDate="ZodDate",r.ZodSymbol="ZodSymbol",r.ZodUndefined="ZodUndefined",r.ZodNull="ZodNull",r.ZodAny="ZodAny",r.ZodUnknown="ZodUnknown",r.ZodNever="ZodNever",r.ZodVoid="ZodVoid",r.ZodArray="ZodArray",r.ZodObject="ZodObject",r.ZodUnion="ZodUnion",r.ZodDiscriminatedUnion="ZodDiscriminatedUnion",r.ZodIntersection="ZodIntersection",r.ZodTuple="ZodTuple",r.ZodRecord="ZodRecord",r.ZodMap="ZodMap",r.ZodSet="ZodSet",r.ZodFunction="ZodFunction",r.ZodLazy="ZodLazy",r.ZodLiteral="ZodLiteral",r.ZodEnum="ZodEnum",r.ZodEffects="ZodEffects",r.ZodNativeEnum="ZodNativeEnum",r.ZodOptional="ZodOptional",r.ZodNullable="ZodNullable",r.ZodDefault="ZodDefault",r.ZodCatch="ZodCatch",r.ZodPromise="ZodPromise",r.ZodBranded="ZodBranded",r.ZodPipeline="ZodPipeline",r.ZodReadonly="ZodReadonly"})(y||(y={}));var Lt=(r,e={message:`Input not instance of ${r.name}`})=>He(t=>t instanceof r,e),Je=U.create,Ye=W.create,Ut=ye.create,Bt=H.create,Ke=J.create,Ft=Y.create,qt=pe.create,Wt=K.create,Ht=G.create,Jt=B.create,Yt=M.create,Kt=A.create,Gt=fe.create,Qt=Z.create,Xt=T.create,er=T.strictCreate,tr=Q.create,rr=Te.create,sr=X.create,nr=j.create,ar=Ce.create,ir=me.create,or=he.create,cr=Ie.create,dr=ee.create,ur=te.create,lr=re.create,pr=se.create,fr=F.create,mr=O.create,hr=I.create,yr=$.create,gr=O.createWithPreprocess,vr=_e.create,_r=()=>Je().optional(),xr=()=>Ye().optional(),kr=()=>Ke().optional(),br={string:(r=>U.create({...r,coerce:!0})),number:(r=>W.create({...r,coerce:!0})),boolean:(r=>J.create({...r,coerce:!0})),bigint:(r=>H.create({...r,coerce:!0})),date:(r=>Y.create({...r,coerce:!0}))};var wr=h;var Er=/^\s*at (?:(.+?) \()?(.+?):(\d+):(\d+)\)?\s*$/,Sr=/^\s*(.*?)@(.+?):(\d+):(\d+)\s*$/,Tr=[/node_modules/,/\bnative\b/,/\[native code\]/,/InternalBytecode/],Cr=/\.(?:js)?bundle\b/;function Ir(r){return r.replace(/^address at /,"")}function Ge(r){if(!r)return[];let e=[];for(let t of r.split(`
2
+ `)){let s=Er.exec(t)??Sr.exec(t);if(!s)continue;let[,n,a,i,o]=s,u=Ir(a??"");if(e.push({fn:n||void 0,file:u,line:Number(i),col:Number(o),inApp:Cr.test(u)?!/^(?:anonymous|eval|global code)$/.test(n??""):!Tr.some(p=>p.test(u))}),e.length>=100)break}return e}var Rr=d.string().min(1).max(64).regex(/^[a-z0-9_]+(\.[a-z0-9_]+)*$/,"flow must be dotted lowercase, e.g. auth.login"),Or=d.record(d.string().max(200)).optional(),je=d.string().datetime({offset:!0}),Ar=d.object({model:d.string().optional(),manufacturer:d.string().optional(),brand:d.string().optional(),type:d.enum(["phone","tablet","desktop","tv","unknown"]).default("unknown"),isEmulator:d.boolean().optional(),memoryMb:d.number().optional(),screen:d.object({width:d.number(),height:d.number(),scale:d.number().optional()}).optional()}),Nr=d.object({name:d.string(),version:d.string().optional()}),jr=d.object({id:d.string().min(1),version:d.string().optional(),build:d.string().optional(),environment:d.string().default("production")}),$r=d.object({name:d.string(),version:d.string().optional(),engine:d.string().optional()}),Pr=d.object({type:d.enum(["wifi","cellular","ethernet","none","unknown"]).default("unknown"),effectiveType:d.string().optional(),isConnected:d.boolean().optional()}),Dr=d.object({app:jr,device:Ar.default({}),os:Nr,runtime:$r,network:Pr.optional(),locale:d.string().optional(),timezone:d.string().optional()}),Mr=d.object({ts:je,category:d.enum(["navigation","network","ui","log","event","custom"]),message:d.string().max(500),level:d.enum(["debug","info","warning","error"]).default("info"),data:d.record(d.union([d.string(),d.number(),d.boolean(),d.null()])).optional()}),Zr=d.object({fn:d.string().optional(),file:d.string().optional(),line:d.number().optional(),col:d.number().optional(),inApp:d.boolean().optional()}),Vr=d.enum(["low","medium","high","critical"]),$e=d.object({id:d.string().min(8).max(64),ts:je,flow:Rr.optional(),step:d.string().max(64).optional(),tags:Or}),zr=$e.extend({type:d.literal("error"),handled:d.boolean().default(!0),severity:Vr.optional(),error:d.object({name:d.string().max(200).default("Error"),message:d.string().max(2e3),stack:d.string().max(2e4).optional(),frames:d.array(Zr).max(100).optional()}),breadcrumbs:d.array(Mr).max(50).optional(),request:d.object({method:d.string().max(10),url:d.string().max(500),status:d.number().int().optional(),durationMs:d.number().optional()}).optional()}),Lr=$e.extend({type:d.literal("event"),name:d.string().min(1).max(100),outcome:d.enum(["success","failure","abandoned"]).optional(),props:d.record(d.union([d.string(),d.number(),d.boolean(),d.null()])).optional()}),Ur=$e.extend({type:d.literal("session"),status:d.enum(["started","errored","crashed"])}),Br=d.discriminatedUnion("type",[zr,Lr,Ur]),Xe=d.object({schema:d.literal(1).default(1),sdk:d.object({name:d.string(),version:d.string()}),context:Dr,user:d.object({id:d.string().optional(),anonymousId:d.string()}).optional(),session:d.object({id:d.string(),startedAt:je}),events:d.array(Br).min(1).max(100)});import{createHash as Fr}from"crypto";function qr(r){return r.replace(/https?:\/\/\S+/g,"<url>").replace(/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi,"<uuid>").replace(/\b[0-9a-f]{16,}\b/gi,"<hex>").replace(/[\w.+-]+@[\w-]+\.[\w.]+/g,"<email>").replace(/\d+(\.\d+)?/g,"<n>").replace(/(["'`]).*?\1/g,"<str>").trim().slice(0,300)}function et(r){if(!r)return"";let e=r.replace(/\/\/&.*$/,"").replace(/[?#].*$/,"").replace(/^[a-z]+:\/\/[^/]+/i,"");if(/\.(?:js)?bundle$/.test(e))return e.replace(/^.*\//,"");for(let t of["/src/","/lib/","/app/"]){let s=e.lastIndexOf(t);if(s>=0){e=e.slice(s+1);break}}return e.replace(/\.[0-9a-f]{6,}\./g,".")}function tt(r){return r?.find(e=>e.inApp!==!1&&e.file)??r?.[0]}function rt(r){let e=tt(r.error.frames);if(!e)return;let t=et(e.file)+(e.line?`:${e.line}`:"");return e.fn?`${e.fn} (${t})`:t}function st(r){let e=tt(r.error.frames),t=r.request,s=t?`${t.method.toUpperCase()} ${t.url} ${t.status?`${Math.floor(t.status/100)}xx`:"failed"}`:e?`${e.fn??"?"}@${et(e.file)}`:qr(r.error.message);return Fr("sha256").update([r.error.name,s,r.flow??""].join("|")).digest("hex").slice(0,24)}function nt(r){return`${r.error.name}: ${r.error.message}`.slice(0,200)}function at(r){let e={};for(let t of(r??"").split(",").map(s=>s.trim()).filter(Boolean)){let[s,n]=t.split(":");s&&n&&(e[s]=n)}return e}var Wr=r=>r.slice(0,10);function Hr(r,e){let t=Date.parse(r),s=e.getTime();return Number.isNaN(t)||t>s+5*6e4||t<s-7*864e5?e.toISOString():new Date(t).toISOString()}function Jr(r){return{...r,os:{...r.os,name:r.os.name.toLowerCase()},runtime:{...r.runtime,name:r.runtime.name.toLowerCase()}}}async function it(r,e,t){let s=t.now?.()??new Date;if(!e||!t.keys[e])return{status:401,body:{ok:!1,error:"invalid ingest key"}};if(Buffer.byteLength(r)>(t.maxBytes??512*1024))return{status:413,body:{ok:!1,error:"payload too large"}};let n;try{n=JSON.parse(r)}catch{return{status:400,body:{ok:!1,error:"invalid json"}}}let a=Xe.safeParse(n);if(!a.success)return{status:400,body:{ok:!1,error:"invalid envelope",issues:a.error.flatten()}};let i=a.data,o=i.context.app.id;if(t.keys[e]!==o&&t.keys[e]!=="*")return{status:403,body:{ok:!1,error:`key not allowed for app ${o}`}};let u=Jr(i.context),p=s.toISOString(),v=[],b=[],oe=new Map;for(let ce of i.events){let k={...ce,ts:Hr(ce.ts,s)};k.type==="error"&&!k.error.frames?.length&&k.error.stack&&(k.error.frames=Ge(k.error.stack));let xe=Wr(k.ts);if(k.type==="session"){b.push({app:o,day:xe,dimension:"session",key:`${u.app.version||"unknown"}|${k.status}`,kind:"event",by:1});continue}let Me=k.type==="error"?"error":"event",V=(C,Re)=>b.push({app:o,day:xe,dimension:C,key:Re||"unknown",kind:Me,by:1}),z;if(k.type==="error"){z=st(k);let C=oe.get(z),Re={app:o,day:xe,fingerprint:z,event:k,context:u,user:i.user,sessionId:i.session.id,receivedAt:p};oe.set(z,{app:o,fingerprint:z,title:nt(k),culprit:rt(k),flow:k.flow,by:(C?.by??0)+1,ts:C&&C.ts>k.ts?C.ts:k.ts,firstTs:C&&C.firstTs<k.ts?C.firstTs:k.ts,lastEvent:C&&C.ts>k.ts?C.lastEvent:Re}),V("issue",z),k.request&&V("endpoint",`${k.request.method.toUpperCase()} ${k.request.url}`),b.push({app:o,day:k.ts.slice(0,13),dimension:"issueHour",key:z,kind:Me,by:1})}V("total","all"),V("flow",k.flow??"untagged"),V("os",`${u.os.name} ${u.os.version??""}`.trim()),V("appVersion",u.app.version),V("deviceModel",u.device.model),k.type==="event"&&k.outcome&&k.flow&&V("flowOutcome",`${k.flow}|${k.outcome}`),v.push({app:o,day:xe,fingerprint:z,event:k,context:u,user:i.user,sessionId:i.session.id,receivedAt:p})}return await t.store.registerApp(o),await Promise.all([v.length?t.store.writeEvents(v):void 0,t.store.upsertIssues([...oe.values()]),t.store.incrementRollups(b)]),{status:202,body:{ok:!0,accepted:i.events.length}}}var Pe={"access-control-allow-origin":"*","access-control-allow-methods":"POST, OPTIONS","access-control-allow-headers":"content-type, x-debug-key","access-control-max-age":"86400"};function ot(r){return async e=>{let t=e.requestContext?.http?.method??e.httpMethod??"POST";if(t==="OPTIONS")return{statusCode:204,headers:Pe,body:""};if(t!=="POST")return De(405,{ok:!1,error:"method not allowed"});let s=Object.fromEntries(Object.entries(e.headers??{}).map(([a,i])=>[a.toLowerCase(),i])),n=e.isBase64Encoded?Buffer.from(e.body??"","base64").toString("utf8"):e.body??"";try{let a=await it(n,s["x-debug-key"],r);return De(a.status,a.body)}catch(a){return console.error("[deBug] ingest failed",a),De(500,{ok:!1,error:"internal"})}}}var De=(r,e)=>({statusCode:r,headers:{...Pe,"content-type":"application/json"},body:JSON.stringify(e)});var Gr=Kr.from(new Yr({}),{marshallOptions:{removeUndefinedValues:!0}}),Hs=ot({store:new we(Gr,{table:process.env.DEBUG_TABLE??"debugkit"}),keys:at(process.env.DEBUG_INGEST_KEYS)});export{Hs as handler};
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@debugkit/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.4.0",
4
+ "description": "Set up deBug in your app: npx @debugkit/cli init (or npx debugkit init once @debugkit/sdk is installed). Deploys ingest to your own cloud, wires the SDK and walks you through the dashboard.",
5
+ "type": "module",
6
+ "bin": {
7
+ "debugkit": "./dist/cli.js"
8
+ },
9
+ "dependencies": {
10
+ "@clack/prompts": "^1.9.0",
11
+ "fflate": "^0.8.3",
12
+ "picocolors": "^1.1.1"
13
+ },
14
+ "optionalDependencies": {
15
+ "@aws-sdk/client-dynamodb": "^3.700.0",
16
+ "@aws-sdk/client-iam": "^3.700.0",
17
+ "@aws-sdk/client-lambda": "^3.700.0",
18
+ "@aws-sdk/client-sts": "^3.700.0",
19
+ "@aws-sdk/credential-providers": "^3.700.0"
20
+ },
21
+ "devDependencies": {
22
+ "@aws-sdk/lib-dynamodb": "^3.700.0",
23
+ "@debugkit/adapters": "^0.4.0",
24
+ "@debugkit/ingest": "^0.4.0",
25
+ "@debugkit/sdk": "^0.4.0"
26
+ },
27
+ "engines": {
28
+ "node": ">=20.12"
29
+ },
30
+ "license": "MIT",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/Abantu-Digital/deBug.git",
34
+ "directory": "packages/cli"
35
+ },
36
+ "files": [
37
+ "dist",
38
+ "README.md"
39
+ ],
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "scripts": {
44
+ "typecheck": "tsc -p .",
45
+ "build": "tsup"
46
+ }
6
47
  }