@chaos-maker/core 0.4.0 → 0.5.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.
- package/README.md +91 -9
- package/dist/chaos-config.schema.json +1314 -0
- package/dist/chaos-config.schema.notes.md +32 -0
- package/dist/chaos-maker.cjs +23 -5
- package/dist/chaos-maker.js +3476 -2247
- package/dist/chaos-maker.umd.js +23 -5
- package/dist/sw.js +1 -1
- package/dist/sw.mjs +808 -454
- package/dist/types/ChaosMaker.d.ts +41 -0
- package/dist/types/builder.d.ts +24 -0
- package/dist/types/config.d.ts +82 -14
- package/dist/types/debug.d.ts +58 -0
- package/dist/types/errors.d.ts +14 -2
- package/dist/types/events.d.ts +59 -1
- package/dist/types/groups.d.ts +71 -0
- package/dist/types/index.d.ts +30 -5
- package/dist/types/interceptors/domAssailant.d.ts +2 -1
- package/dist/types/interceptors/eventSource.d.ts +2 -1
- package/dist/types/interceptors/networkFetch.d.ts +2 -1
- package/dist/types/interceptors/networkXHR.d.ts +2 -1
- package/dist/types/interceptors/websocket.d.ts +2 -1
- package/dist/types/presets.d.ts +63 -2
- package/dist/types/sw-bridge-source.d.ts +3 -1
- package/dist/types/sw.d.ts +7 -0
- package/dist/types/utils.d.ts +46 -1
- package/dist/types/validation-deprecation.d.ts +7 -0
- package/dist/types/validation-format.d.ts +10 -0
- package/dist/types/validation-strip.d.ts +11 -0
- package/dist/types/validation-types.d.ts +34 -0
- package/dist/types/validation.d.ts +52 -0
- package/package.json +5 -3
package/dist/chaos-maker.umd.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
(function(R,x){typeof exports=="object"&&typeof module<"u"?x(exports):typeof define=="function"&&define.amd?define(["exports"],x):(R=typeof globalThis<"u"?globalThis:R||self,x(R.ChaosMaker={}))})(this,(function(R){"use strict";var bn=Object.defineProperty;var kn=(R,x,ce)=>x in R?bn(R,x,{enumerable:!0,configurable:!0,writable:!0,value:ce}):R[x]=ce;var L=(R,x,ce)=>kn(R,typeof x!="symbol"?x+"":x,ce);var x;(function(r){r.assertEqual=s=>{};function e(s){}r.assertIs=e;function t(s){throw new Error}r.assertNever=t,r.arrayToEnum=s=>{const a={};for(const o of s)a[o]=o;return a},r.getValidEnumValues=s=>{const a=r.objectKeys(s).filter(i=>typeof s[s[i]]!="number"),o={};for(const i of a)o[i]=s[i];return r.objectValues(o)},r.objectValues=s=>r.objectKeys(s).map(function(a){return s[a]}),r.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const a=[];for(const o in s)Object.prototype.hasOwnProperty.call(s,o)&&a.push(o);return a},r.find=(s,a)=>{for(const o of s)if(a(o))return o},r.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&Number.isFinite(s)&&Math.floor(s)===s;function n(s,a=" | "){return s.map(o=>typeof o=="string"?`'${o}'`:o).join(a)}r.joinValues=n,r.jsonStringifyReplacer=(s,a)=>typeof a=="bigint"?a.toString():a})(x||(x={}));var ce;(function(r){r.mergeShapes=(e,t)=>({...e,...t})})(ce||(ce={}));const g=x.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),re=r=>{switch(typeof r){case"undefined":return g.undefined;case"string":return g.string;case"number":return Number.isNaN(r)?g.nan:g.number;case"boolean":return g.boolean;case"function":return g.function;case"bigint":return g.bigint;case"symbol":return g.symbol;case"object":return Array.isArray(r)?g.array:r===null?g.null:r.then&&typeof r.then=="function"&&r.catch&&typeof r.catch=="function"?g.promise:typeof Map<"u"&&r instanceof Map?g.map:typeof Set<"u"&&r instanceof Set?g.set:typeof Date<"u"&&r instanceof Date?g.date:g.object;default:return g.unknown}},d=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"]);class Y extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=n=>{this.issues=[...this.issues,n]},this.addIssues=(n=[])=>{this.issues=[...this.issues,...n]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(a){return a.message},n={_errors:[]},s=a=>{for(const o of a.issues)if(o.code==="invalid_union")o.unionErrors.map(s);else if(o.code==="invalid_return_type")s(o.returnTypeError);else if(o.code==="invalid_arguments")s(o.argumentsError);else if(o.path.length===0)n._errors.push(t(o));else{let i=n,u=0;for(;u<o.path.length;){const y=o.path[u];u===o.path.length-1?(i[y]=i[y]||{_errors:[]},i[y]._errors.push(t(o))):i[y]=i[y]||{_errors:[]},i=i[y],u++}}};return s(this),n}static assert(e){if(!(e instanceof Y))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){const t={},n=[];for(const s of this.issues)if(s.path.length>0){const a=s.path[0];t[a]=t[a]||[],t[a].push(e(s))}else n.push(e(s));return{formErrors:n,fieldErrors:t}}get formErrors(){return this.flatten()}}Y.create=r=>new Y(r);const Fe=(r,e)=>{let t;switch(r.code){case d.invalid_type:r.received===g.undefined?t="Required":t=`Expected ${r.expected}, received ${r.received}`;break;case d.invalid_literal:t=`Invalid literal value, expected ${JSON.stringify(r.expected,x.jsonStringifyReplacer)}`;break;case d.unrecognized_keys:t=`Unrecognized key(s) in object: ${x.joinValues(r.keys,", ")}`;break;case d.invalid_union:t="Invalid input";break;case d.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${x.joinValues(r.options)}`;break;case d.invalid_enum_value:t=`Invalid enum value. Expected ${x.joinValues(r.options)}, received '${r.received}'`;break;case d.invalid_arguments:t="Invalid function arguments";break;case d.invalid_return_type:t="Invalid function return type";break;case d.invalid_date:t="Invalid date";break;case d.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 d.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 d.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 d.custom:t="Invalid input";break;case d.invalid_intersection_types:t="Intersection results could not be merged";break;case d.not_multiple_of:t=`Number must be a multiple of ${r.multipleOf}`;break;case d.not_finite:t="Number must be finite";break;default:t=e.defaultError,x.assertNever(r)}return{message:t}};let Ut=Fe;function Wt(){return Ut}const Bt=r=>{const{data:e,path:t,errorMaps:n,issueData:s}=r,a=[...t,...s.path||[]],o={...s,path:a};if(s.message!==void 0)return{...s,path:a,message:s.message};let i="";const u=n.filter(y=>!!y).slice().reverse();for(const y of u)i=y(o,{data:e,defaultError:i}).message;return{...s,path:a,message:i}};function p(r,e){const t=Wt(),n=Bt({issueData:e,data:r.data,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,t,t===Fe?void 0:Fe].filter(s=>!!s)});r.common.issues.push(n)}class Z{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,t){const n=[];for(const s of t){if(s.status==="aborted")return w;s.status==="dirty"&&e.dirty(),n.push(s.value)}return{status:e.value,value:n}}static async mergeObjectAsync(e,t){const n=[];for(const s of t){const a=await s.key,o=await s.value;n.push({key:a,value:o})}return Z.mergeObjectSync(e,n)}static mergeObjectSync(e,t){const n={};for(const s of t){const{key:a,value:o}=s;if(a.status==="aborted"||o.status==="aborted")return w;a.status==="dirty"&&e.dirty(),o.status==="dirty"&&e.dirty(),a.value!=="__proto__"&&(typeof o.value<"u"||s.alwaysSet)&&(n[a.value]=o.value)}return{status:e.value,value:n}}}const w=Object.freeze({status:"aborted"}),_e=r=>({status:"dirty",value:r}),B=r=>({status:"valid",value:r}),ot=r=>r.status==="aborted",ct=r=>r.status==="dirty",de=r=>r.status==="valid",Ne=r=>typeof Promise<"u"&&r instanceof Promise;var v;(function(r){r.errToObj=e=>typeof e=="string"?{message:e}:e||{},r.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(v||(v={}));class X{constructor(e,t,n,s){this._cachedPath=[],this.parent=e,this.data=t,this._path=n,this._key=s}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 ut=(r,e)=>{if(de(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;const t=new Y(r.common.issues);return this._error=t,this._error}}};function S(r){if(!r)return{};const{errorMap:e,invalid_type_error:t,required_error:n,description:s}=r;if(e&&(t||n))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:s}:{errorMap:(o,i)=>{const{message:u}=r;return o.code==="invalid_enum_value"?{message:u??i.defaultError}:typeof i.data>"u"?{message:u??n??i.defaultError}:o.code!=="invalid_type"?{message:i.defaultError}:{message:u??t??i.defaultError}},description:s}}class N{get description(){return this._def.description}_getType(e){return re(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:re(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new Z,ctx:{common:e.parent.common,data:e.data,parsedType:re(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(Ne(t))throw new Error("Synchronous parse encountered promise.");return t}_parseAsync(e){const t=this._parse(e);return Promise.resolve(t)}parse(e,t){const n=this.safeParse(e,t);if(n.success)return n.data;throw n.error}safeParse(e,t){const n={common:{issues:[],async:(t==null?void 0:t.async)??!1,contextualErrorMap:t==null?void 0:t.errorMap},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:re(e)},s=this._parseSync({data:e,path:n.path,parent:n});return ut(n,s)}"~validate"(e){var n,s;const t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:re(e)};if(!this["~standard"].async)try{const a=this._parseSync({data:e,path:[],parent:t});return de(a)?{value:a.value}:{issues:t.common.issues}}catch(a){(s=(n=a==null?void 0:a.message)==null?void 0:n.toLowerCase())!=null&&s.includes("encountered")&&(this["~standard"].async=!0),t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then(a=>de(a)?{value:a.value}:{issues:t.common.issues})}async parseAsync(e,t){const n=await this.safeParseAsync(e,t);if(n.success)return n.data;throw n.error}async safeParseAsync(e,t){const n={common:{issues:[],contextualErrorMap:t==null?void 0:t.errorMap,async:!0},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:re(e)},s=this._parse({data:e,path:n.path,parent:n}),a=await(Ne(s)?s:Promise.resolve(s));return ut(n,a)}refine(e,t){const n=s=>typeof t=="string"||typeof t>"u"?{message:t}:typeof t=="function"?t(s):t;return this._refinement((s,a)=>{const o=e(s),i=()=>a.addIssue({code:d.custom,...n(s)});return typeof Promise<"u"&&o instanceof Promise?o.then(u=>u?!0:(i(),!1)):o?!0:(i(),!1)})}refinement(e,t){return this._refinement((n,s)=>e(n)?!0:(s.addIssue(typeof t=="function"?t(n,s):t),!1))}_refinement(e){return new me({schema:this,typeName:k.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 se.create(this,this._def)}nullable(){return ye.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return Q.create(this)}promise(){return Pe.create(this,this._def)}or(e){return Re.create([this,e],this._def)}and(e){return Me.create(this,e,this._def)}transform(e){return new me({...S(this._def),schema:this,typeName:k.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new Be({...S(this._def),innerType:this,defaultValue:t,typeName:k.ZodDefault})}brand(){return new mr({typeName:k.ZodBranded,type:this,...S(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new He({...S(this._def),innerType:this,catchValue:t,typeName:k.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return Ge.create(this,e)}readonly(){return Xe.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Ht=/^c[^\s-]{8,}$/i,Gt=/^[0-9a-z]+$/,Xt=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Qt=/^[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,Jt=/^[a-z0-9_-]{21}$/i,Yt=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Kt=/^[-+]?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)?)??$/,er=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,tr="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Ue;const rr=/^(?:(?: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])$/,nr=/^(?:(?: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])$/,sr=/^(([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]))$/,ar=/^(([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])$/,ir=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,or=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,lt="((\\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])))",cr=new RegExp(`^${lt}$`);function dt(r){let e="[0-5]\\d";r.precision?e=`${e}\\.\\d{${r.precision}}`:r.precision==null&&(e=`${e}(\\.\\d+)?`);const t=r.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${t}`}function ur(r){return new RegExp(`^${dt(r)}$`)}function lr(r){let e=`${lt}T${dt(r)}`;const t=[];return t.push(r.local?"Z?":"Z"),r.offset&&t.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${t.join("|")})`,new RegExp(`^${e}$`)}function dr(r,e){return!!((e==="v4"||!e)&&rr.test(r)||(e==="v6"||!e)&&sr.test(r))}function fr(r,e){if(!Yt.test(r))return!1;try{const[t]=r.split(".");if(!t)return!1;const n=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(t.length+(4-t.length%4)%4,"="),s=JSON.parse(atob(n));return!(typeof s!="object"||s===null||"typ"in s&&(s==null?void 0:s.typ)!=="JWT"||!s.alg||e&&s.alg!==e)}catch{return!1}}function hr(r,e){return!!((e==="v4"||!e)&&nr.test(r)||(e==="v6"||!e)&&ar.test(r))}class K extends N{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==g.string){const a=this._getOrReturnCtx(e);return p(a,{code:d.invalid_type,expected:g.string,received:a.parsedType}),w}const n=new Z;let s;for(const a of this._def.checks)if(a.kind==="min")e.data.length<a.value&&(s=this._getOrReturnCtx(e,s),p(s,{code:d.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),n.dirty());else if(a.kind==="max")e.data.length>a.value&&(s=this._getOrReturnCtx(e,s),p(s,{code:d.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),n.dirty());else if(a.kind==="length"){const o=e.data.length>a.value,i=e.data.length<a.value;(o||i)&&(s=this._getOrReturnCtx(e,s),o?p(s,{code:d.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}):i&&p(s,{code:d.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}),n.dirty())}else if(a.kind==="email")er.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"email",code:d.invalid_string,message:a.message}),n.dirty());else if(a.kind==="emoji")Ue||(Ue=new RegExp(tr,"u")),Ue.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"emoji",code:d.invalid_string,message:a.message}),n.dirty());else if(a.kind==="uuid")Qt.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"uuid",code:d.invalid_string,message:a.message}),n.dirty());else if(a.kind==="nanoid")Jt.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"nanoid",code:d.invalid_string,message:a.message}),n.dirty());else if(a.kind==="cuid")Ht.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"cuid",code:d.invalid_string,message:a.message}),n.dirty());else if(a.kind==="cuid2")Gt.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"cuid2",code:d.invalid_string,message:a.message}),n.dirty());else if(a.kind==="ulid")Xt.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"ulid",code:d.invalid_string,message:a.message}),n.dirty());else if(a.kind==="url")try{new URL(e.data)}catch{s=this._getOrReturnCtx(e,s),p(s,{validation:"url",code:d.invalid_string,message:a.message}),n.dirty()}else a.kind==="regex"?(a.regex.lastIndex=0,a.regex.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"regex",code:d.invalid_string,message:a.message}),n.dirty())):a.kind==="trim"?e.data=e.data.trim():a.kind==="includes"?e.data.includes(a.value,a.position)||(s=this._getOrReturnCtx(e,s),p(s,{code:d.invalid_string,validation:{includes:a.value,position:a.position},message:a.message}),n.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)||(s=this._getOrReturnCtx(e,s),p(s,{code:d.invalid_string,validation:{startsWith:a.value},message:a.message}),n.dirty()):a.kind==="endsWith"?e.data.endsWith(a.value)||(s=this._getOrReturnCtx(e,s),p(s,{code:d.invalid_string,validation:{endsWith:a.value},message:a.message}),n.dirty()):a.kind==="datetime"?lr(a).test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{code:d.invalid_string,validation:"datetime",message:a.message}),n.dirty()):a.kind==="date"?cr.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{code:d.invalid_string,validation:"date",message:a.message}),n.dirty()):a.kind==="time"?ur(a).test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{code:d.invalid_string,validation:"time",message:a.message}),n.dirty()):a.kind==="duration"?Kt.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"duration",code:d.invalid_string,message:a.message}),n.dirty()):a.kind==="ip"?dr(e.data,a.version)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"ip",code:d.invalid_string,message:a.message}),n.dirty()):a.kind==="jwt"?fr(e.data,a.alg)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"jwt",code:d.invalid_string,message:a.message}),n.dirty()):a.kind==="cidr"?hr(e.data,a.version)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"cidr",code:d.invalid_string,message:a.message}),n.dirty()):a.kind==="base64"?ir.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"base64",code:d.invalid_string,message:a.message}),n.dirty()):a.kind==="base64url"?or.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"base64url",code:d.invalid_string,message:a.message}),n.dirty()):x.assertNever(a);return{status:n.value,value:e.data}}_regex(e,t,n){return this.refinement(s=>e.test(s),{validation:t,code:d.invalid_string,...v.errToObj(n)})}_addCheck(e){return new K({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...v.errToObj(e)})}url(e){return this._addCheck({kind:"url",...v.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...v.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...v.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...v.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...v.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...v.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...v.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...v.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...v.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...v.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...v.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...v.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==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,offset:(e==null?void 0:e.offset)??!1,local:(e==null?void 0:e.local)??!1,...v.errToObj(e==null?void 0: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==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,...v.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...v.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...v.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t==null?void 0:t.position,...v.errToObj(t==null?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...v.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...v.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...v.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...v.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...v.errToObj(t)})}nonempty(e){return this.min(1,v.errToObj(e))}trim(){return new K({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new K({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new K({...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 t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}K.create=r=>new K({checks:[],typeName:k.ZodString,coerce:(r==null?void 0:r.coerce)??!1,...S(r)});function pr(r,e){const t=(r.toString().split(".")[1]||"").length,n=(e.toString().split(".")[1]||"").length,s=t>n?t:n,a=Number.parseInt(r.toFixed(s).replace(".","")),o=Number.parseInt(e.toFixed(s).replace(".",""));return a%o/10**s}class fe extends N{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)!==g.number){const a=this._getOrReturnCtx(e);return p(a,{code:d.invalid_type,expected:g.number,received:a.parsedType}),w}let n;const s=new Z;for(const a of this._def.checks)a.kind==="int"?x.isInteger(e.data)||(n=this._getOrReturnCtx(e,n),p(n,{code:d.invalid_type,expected:"integer",received:"float",message:a.message}),s.dirty()):a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(n=this._getOrReturnCtx(e,n),p(n,{code:d.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),s.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(n=this._getOrReturnCtx(e,n),p(n,{code:d.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),s.dirty()):a.kind==="multipleOf"?pr(e.data,a.value)!==0&&(n=this._getOrReturnCtx(e,n),p(n,{code:d.not_multiple_of,multipleOf:a.value,message:a.message}),s.dirty()):a.kind==="finite"?Number.isFinite(e.data)||(n=this._getOrReturnCtx(e,n),p(n,{code:d.not_finite,message:a.message}),s.dirty()):x.assertNever(a);return{status:s.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,v.toString(t))}gt(e,t){return this.setLimit("min",e,!1,v.toString(t))}lte(e,t){return this.setLimit("max",e,!0,v.toString(t))}lt(e,t){return this.setLimit("max",e,!1,v.toString(t))}setLimit(e,t,n,s){return new fe({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:n,message:v.toString(s)}]})}_addCheck(e){return new fe({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:v.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:v.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:v.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:v.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:v.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:v.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:v.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:v.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:v.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const 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(const n of this._def.checks){if(n.kind==="finite"||n.kind==="int"||n.kind==="multipleOf")return!0;n.kind==="min"?(t===null||n.value>t)&&(t=n.value):n.kind==="max"&&(e===null||n.value<e)&&(e=n.value)}return Number.isFinite(t)&&Number.isFinite(e)}}fe.create=r=>new fe({checks:[],typeName:k.ZodNumber,coerce:(r==null?void 0:r.coerce)||!1,...S(r)});class be extends N{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)!==g.bigint)return this._getInvalidInput(e);let n;const s=new Z;for(const a of this._def.checks)a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(n=this._getOrReturnCtx(e,n),p(n,{code:d.too_small,type:"bigint",minimum:a.value,inclusive:a.inclusive,message:a.message}),s.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(n=this._getOrReturnCtx(e,n),p(n,{code:d.too_big,type:"bigint",maximum:a.value,inclusive:a.inclusive,message:a.message}),s.dirty()):a.kind==="multipleOf"?e.data%a.value!==BigInt(0)&&(n=this._getOrReturnCtx(e,n),p(n,{code:d.not_multiple_of,multipleOf:a.value,message:a.message}),s.dirty()):x.assertNever(a);return{status:s.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return p(t,{code:d.invalid_type,expected:g.bigint,received:t.parsedType}),w}gte(e,t){return this.setLimit("min",e,!0,v.toString(t))}gt(e,t){return this.setLimit("min",e,!1,v.toString(t))}lte(e,t){return this.setLimit("max",e,!0,v.toString(t))}lt(e,t){return this.setLimit("max",e,!1,v.toString(t))}setLimit(e,t,n,s){return new be({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:n,message:v.toString(s)}]})}_addCheck(e){return new be({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:v.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:v.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:v.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:v.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:v.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}be.create=r=>new be({checks:[],typeName:k.ZodBigInt,coerce:(r==null?void 0:r.coerce)??!1,...S(r)});class ft extends N{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==g.boolean){const n=this._getOrReturnCtx(e);return p(n,{code:d.invalid_type,expected:g.boolean,received:n.parsedType}),w}return B(e.data)}}ft.create=r=>new ft({typeName:k.ZodBoolean,coerce:(r==null?void 0:r.coerce)||!1,...S(r)});class Ae extends N{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==g.date){const a=this._getOrReturnCtx(e);return p(a,{code:d.invalid_type,expected:g.date,received:a.parsedType}),w}if(Number.isNaN(e.data.getTime())){const a=this._getOrReturnCtx(e);return p(a,{code:d.invalid_date}),w}const n=new Z;let s;for(const a of this._def.checks)a.kind==="min"?e.data.getTime()<a.value&&(s=this._getOrReturnCtx(e,s),p(s,{code:d.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),n.dirty()):a.kind==="max"?e.data.getTime()>a.value&&(s=this._getOrReturnCtx(e,s),p(s,{code:d.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),n.dirty()):x.assertNever(a);return{status:n.value,value:new Date(e.data.getTime())}}_addCheck(e){return new Ae({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:v.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:v.toString(t)})}get minDate(){let e=null;for(const 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(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e!=null?new Date(e):null}}Ae.create=r=>new Ae({checks:[],coerce:(r==null?void 0:r.coerce)||!1,typeName:k.ZodDate,...S(r)});class ht extends N{_parse(e){if(this._getType(e)!==g.symbol){const n=this._getOrReturnCtx(e);return p(n,{code:d.invalid_type,expected:g.symbol,received:n.parsedType}),w}return B(e.data)}}ht.create=r=>new ht({typeName:k.ZodSymbol,...S(r)});class pt extends N{_parse(e){if(this._getType(e)!==g.undefined){const n=this._getOrReturnCtx(e);return p(n,{code:d.invalid_type,expected:g.undefined,received:n.parsedType}),w}return B(e.data)}}pt.create=r=>new pt({typeName:k.ZodUndefined,...S(r)});class mt extends N{_parse(e){if(this._getType(e)!==g.null){const n=this._getOrReturnCtx(e);return p(n,{code:d.invalid_type,expected:g.null,received:n.parsedType}),w}return B(e.data)}}mt.create=r=>new mt({typeName:k.ZodNull,...S(r)});class ke extends N{constructor(){super(...arguments),this._any=!0}_parse(e){return B(e.data)}}ke.create=r=>new ke({typeName:k.ZodAny,...S(r)});class yt extends N{constructor(){super(...arguments),this._unknown=!0}_parse(e){return B(e.data)}}yt.create=r=>new yt({typeName:k.ZodUnknown,...S(r)});class ne extends N{_parse(e){const t=this._getOrReturnCtx(e);return p(t,{code:d.invalid_type,expected:g.never,received:t.parsedType}),w}}ne.create=r=>new ne({typeName:k.ZodNever,...S(r)});class gt extends N{_parse(e){if(this._getType(e)!==g.undefined){const n=this._getOrReturnCtx(e);return p(n,{code:d.invalid_type,expected:g.void,received:n.parsedType}),w}return B(e.data)}}gt.create=r=>new gt({typeName:k.ZodVoid,...S(r)});class Q extends N{_parse(e){const{ctx:t,status:n}=this._processInputParams(e),s=this._def;if(t.parsedType!==g.array)return p(t,{code:d.invalid_type,expected:g.array,received:t.parsedType}),w;if(s.exactLength!==null){const o=t.data.length>s.exactLength.value,i=t.data.length<s.exactLength.value;(o||i)&&(p(t,{code:o?d.too_big:d.too_small,minimum:i?s.exactLength.value:void 0,maximum:o?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),n.dirty())}if(s.minLength!==null&&t.data.length<s.minLength.value&&(p(t,{code:d.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),n.dirty()),s.maxLength!==null&&t.data.length>s.maxLength.value&&(p(t,{code:d.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),n.dirty()),t.common.async)return Promise.all([...t.data].map((o,i)=>s.type._parseAsync(new X(t,o,t.path,i)))).then(o=>Z.mergeArray(n,o));const a=[...t.data].map((o,i)=>s.type._parseSync(new X(t,o,t.path,i)));return Z.mergeArray(n,a)}get element(){return this._def.type}min(e,t){return new Q({...this._def,minLength:{value:e,message:v.toString(t)}})}max(e,t){return new Q({...this._def,maxLength:{value:e,message:v.toString(t)}})}length(e,t){return new Q({...this._def,exactLength:{value:e,message:v.toString(t)}})}nonempty(e){return this.min(1,e)}}Q.create=(r,e)=>new Q({type:r,minLength:null,maxLength:null,exactLength:null,typeName:k.ZodArray,...S(e)});function he(r){if(r instanceof M){const e={};for(const t in r.shape){const n=r.shape[t];e[t]=se.create(he(n))}return new M({...r._def,shape:()=>e})}else return r instanceof Q?new Q({...r._def,type:he(r.element)}):r instanceof se?se.create(he(r.unwrap())):r instanceof ye?ye.create(he(r.unwrap())):r instanceof ue?ue.create(r.items.map(e=>he(e))):r}class M extends N{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(),t=x.objectKeys(e);return this._cached={shape:e,keys:t},this._cached}_parse(e){if(this._getType(e)!==g.object){const y=this._getOrReturnCtx(e);return p(y,{code:d.invalid_type,expected:g.object,received:y.parsedType}),w}const{status:n,ctx:s}=this._processInputParams(e),{shape:a,keys:o}=this._getCached(),i=[];if(!(this._def.catchall instanceof ne&&this._def.unknownKeys==="strip"))for(const y in s.data)o.includes(y)||i.push(y);const u=[];for(const y of o){const C=a[y],j=s.data[y];u.push({key:{status:"valid",value:y},value:C._parse(new X(s,j,s.path,y)),alwaysSet:y in s.data})}if(this._def.catchall instanceof ne){const y=this._def.unknownKeys;if(y==="passthrough")for(const C of i)u.push({key:{status:"valid",value:C},value:{status:"valid",value:s.data[C]}});else if(y==="strict")i.length>0&&(p(s,{code:d.unrecognized_keys,keys:i}),n.dirty());else if(y!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const y=this._def.catchall;for(const C of i){const j=s.data[C];u.push({key:{status:"valid",value:C},value:y._parse(new X(s,j,s.path,C)),alwaysSet:C in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const y=[];for(const C of u){const j=await C.key,U=await C.value;y.push({key:j,value:U,alwaysSet:C.alwaysSet})}return y}).then(y=>Z.mergeObjectSync(n,y)):Z.mergeObjectSync(n,u)}get shape(){return this._def.shape()}strict(e){return v.errToObj,new M({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,n)=>{var a,o;const s=((o=(a=this._def).errorMap)==null?void 0:o.call(a,t,n).message)??n.defaultError;return t.code==="unrecognized_keys"?{message:v.errToObj(e).message??s}:{message:s}}}:{}})}strip(){return new M({...this._def,unknownKeys:"strip"})}passthrough(){return new M({...this._def,unknownKeys:"passthrough"})}extend(e){return new M({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new M({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:k.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new M({...this._def,catchall:e})}pick(e){const t={};for(const n of x.objectKeys(e))e[n]&&this.shape[n]&&(t[n]=this.shape[n]);return new M({...this._def,shape:()=>t})}omit(e){const t={};for(const n of x.objectKeys(this.shape))e[n]||(t[n]=this.shape[n]);return new M({...this._def,shape:()=>t})}deepPartial(){return he(this)}partial(e){const t={};for(const n of x.objectKeys(this.shape)){const s=this.shape[n];e&&!e[n]?t[n]=s:t[n]=s.optional()}return new M({...this._def,shape:()=>t})}required(e){const t={};for(const n of x.objectKeys(this.shape))if(e&&!e[n])t[n]=this.shape[n];else{let a=this.shape[n];for(;a instanceof se;)a=a._def.innerType;t[n]=a}return new M({...this._def,shape:()=>t})}keyof(){return kt(x.objectKeys(this.shape))}}M.create=(r,e)=>new M({shape:()=>r,unknownKeys:"strip",catchall:ne.create(),typeName:k.ZodObject,...S(e)}),M.strictCreate=(r,e)=>new M({shape:()=>r,unknownKeys:"strict",catchall:ne.create(),typeName:k.ZodObject,...S(e)}),M.lazycreate=(r,e)=>new M({shape:r,unknownKeys:"strip",catchall:ne.create(),typeName:k.ZodObject,...S(e)});class Re extends N{_parse(e){const{ctx:t}=this._processInputParams(e),n=this._def.options;function s(a){for(const i of a)if(i.result.status==="valid")return i.result;for(const i of a)if(i.result.status==="dirty")return t.common.issues.push(...i.ctx.common.issues),i.result;const o=a.map(i=>new Y(i.ctx.common.issues));return p(t,{code:d.invalid_union,unionErrors:o}),w}if(t.common.async)return Promise.all(n.map(async a=>{const o={...t,common:{...t.common,issues:[]},parent:null};return{result:await a._parseAsync({data:t.data,path:t.path,parent:o}),ctx:o}})).then(s);{let a;const o=[];for(const u of n){const y={...t,common:{...t.common,issues:[]},parent:null},C=u._parseSync({data:t.data,path:t.path,parent:y});if(C.status==="valid")return C;C.status==="dirty"&&!a&&(a={result:C,ctx:y}),y.common.issues.length&&o.push(y.common.issues)}if(a)return t.common.issues.push(...a.ctx.common.issues),a.result;const i=o.map(u=>new Y(u));return p(t,{code:d.invalid_union,unionErrors:i}),w}}get options(){return this._def.options}}Re.create=(r,e)=>new Re({options:r,typeName:k.ZodUnion,...S(e)});function We(r,e){const t=re(r),n=re(e);if(r===e)return{valid:!0,data:r};if(t===g.object&&n===g.object){const s=x.objectKeys(e),a=x.objectKeys(r).filter(i=>s.indexOf(i)!==-1),o={...r,...e};for(const i of a){const u=We(r[i],e[i]);if(!u.valid)return{valid:!1};o[i]=u.data}return{valid:!0,data:o}}else if(t===g.array&&n===g.array){if(r.length!==e.length)return{valid:!1};const s=[];for(let a=0;a<r.length;a++){const o=r[a],i=e[a],u=We(o,i);if(!u.valid)return{valid:!1};s.push(u.data)}return{valid:!0,data:s}}else return t===g.date&&n===g.date&&+r==+e?{valid:!0,data:r}:{valid:!1}}class Me extends N{_parse(e){const{status:t,ctx:n}=this._processInputParams(e),s=(a,o)=>{if(ot(a)||ot(o))return w;const i=We(a.value,o.value);return i.valid?((ct(a)||ct(o))&&t.dirty(),{status:t.value,value:i.data}):(p(n,{code:d.invalid_intersection_types}),w)};return n.common.async?Promise.all([this._def.left._parseAsync({data:n.data,path:n.path,parent:n}),this._def.right._parseAsync({data:n.data,path:n.path,parent:n})]).then(([a,o])=>s(a,o)):s(this._def.left._parseSync({data:n.data,path:n.path,parent:n}),this._def.right._parseSync({data:n.data,path:n.path,parent:n}))}}Me.create=(r,e,t)=>new Me({left:r,right:e,typeName:k.ZodIntersection,...S(t)});class ue extends N{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==g.array)return p(n,{code:d.invalid_type,expected:g.array,received:n.parsedType}),w;if(n.data.length<this._def.items.length)return p(n,{code:d.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),w;!this._def.rest&&n.data.length>this._def.items.length&&(p(n,{code:d.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const a=[...n.data].map((o,i)=>{const u=this._def.items[i]||this._def.rest;return u?u._parse(new X(n,o,n.path,i)):null}).filter(o=>!!o);return n.common.async?Promise.all(a).then(o=>Z.mergeArray(t,o)):Z.mergeArray(t,a)}get items(){return this._def.items}rest(e){return new ue({...this._def,rest:e})}}ue.create=(r,e)=>{if(!Array.isArray(r))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new ue({items:r,typeName:k.ZodTuple,rest:null,...S(e)})};class Le extends N{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==g.object)return p(n,{code:d.invalid_type,expected:g.object,received:n.parsedType}),w;const s=[],a=this._def.keyType,o=this._def.valueType;for(const i in n.data)s.push({key:a._parse(new X(n,i,n.path,i)),value:o._parse(new X(n,n.data[i],n.path,i)),alwaysSet:i in n.data});return n.common.async?Z.mergeObjectAsync(t,s):Z.mergeObjectSync(t,s)}get element(){return this._def.valueType}static create(e,t,n){return t instanceof N?new Le({keyType:e,valueType:t,typeName:k.ZodRecord,...S(n)}):new Le({keyType:K.create(),valueType:e,typeName:k.ZodRecord,...S(t)})}}class vt extends N{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==g.map)return p(n,{code:d.invalid_type,expected:g.map,received:n.parsedType}),w;const s=this._def.keyType,a=this._def.valueType,o=[...n.data.entries()].map(([i,u],y)=>({key:s._parse(new X(n,i,n.path,[y,"key"])),value:a._parse(new X(n,u,n.path,[y,"value"]))}));if(n.common.async){const i=new Map;return Promise.resolve().then(async()=>{for(const u of o){const y=await u.key,C=await u.value;if(y.status==="aborted"||C.status==="aborted")return w;(y.status==="dirty"||C.status==="dirty")&&t.dirty(),i.set(y.value,C.value)}return{status:t.value,value:i}})}else{const i=new Map;for(const u of o){const y=u.key,C=u.value;if(y.status==="aborted"||C.status==="aborted")return w;(y.status==="dirty"||C.status==="dirty")&&t.dirty(),i.set(y.value,C.value)}return{status:t.value,value:i}}}}vt.create=(r,e,t)=>new vt({valueType:e,keyType:r,typeName:k.ZodMap,...S(t)});class we extends N{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==g.set)return p(n,{code:d.invalid_type,expected:g.set,received:n.parsedType}),w;const s=this._def;s.minSize!==null&&n.data.size<s.minSize.value&&(p(n,{code:d.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),t.dirty()),s.maxSize!==null&&n.data.size>s.maxSize.value&&(p(n,{code:d.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),t.dirty());const a=this._def.valueType;function o(u){const y=new Set;for(const C of u){if(C.status==="aborted")return w;C.status==="dirty"&&t.dirty(),y.add(C.value)}return{status:t.value,value:y}}const i=[...n.data.values()].map((u,y)=>a._parse(new X(n,u,n.path,y)));return n.common.async?Promise.all(i).then(u=>o(u)):o(i)}min(e,t){return new we({...this._def,minSize:{value:e,message:v.toString(t)}})}max(e,t){return new we({...this._def,maxSize:{value:e,message:v.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}we.create=(r,e)=>new we({valueType:r,minSize:null,maxSize:null,typeName:k.ZodSet,...S(e)});class _t extends N{get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}_t.create=(r,e)=>new _t({getter:r,typeName:k.ZodLazy,...S(e)});class bt extends N{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return p(t,{received:t.data,code:d.invalid_literal,expected:this._def.value}),w}return{status:"valid",value:e.data}}get value(){return this._def.value}}bt.create=(r,e)=>new bt({value:r,typeName:k.ZodLiteral,...S(e)});function kt(r,e){return new pe({values:r,typeName:k.ZodEnum,...S(e)})}class pe extends N{_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),n=this._def.values;return p(t,{expected:x.joinValues(n),received:t.parsedType,code:d.invalid_type}),w}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){const t=this._getOrReturnCtx(e),n=this._def.values;return p(t,{received:t.data,code:d.invalid_enum_value,options:n}),w}return B(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return pe.create(e,{...this._def,...t})}exclude(e,t=this._def){return pe.create(this.options.filter(n=>!e.includes(n)),{...this._def,...t})}}pe.create=kt;class wt extends N{_parse(e){const t=x.getValidEnumValues(this._def.values),n=this._getOrReturnCtx(e);if(n.parsedType!==g.string&&n.parsedType!==g.number){const s=x.objectValues(t);return p(n,{expected:x.joinValues(s),received:n.parsedType,code:d.invalid_type}),w}if(this._cache||(this._cache=new Set(x.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){const s=x.objectValues(t);return p(n,{received:n.data,code:d.invalid_enum_value,options:s}),w}return B(e.data)}get enum(){return this._def.values}}wt.create=(r,e)=>new wt({values:r,typeName:k.ZodNativeEnum,...S(e)});class Pe extends N{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==g.promise&&t.common.async===!1)return p(t,{code:d.invalid_type,expected:g.promise,received:t.parsedType}),w;const n=t.parsedType===g.promise?t.data:Promise.resolve(t.data);return B(n.then(s=>this._def.type.parseAsync(s,{path:t.path,errorMap:t.common.contextualErrorMap})))}}Pe.create=(r,e)=>new Pe({type:r,typeName:k.ZodPromise,...S(e)});class me extends N{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===k.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:n}=this._processInputParams(e),s=this._def.effect||null,a={addIssue:o=>{p(n,o),o.fatal?t.abort():t.dirty()},get path(){return n.path}};if(a.addIssue=a.addIssue.bind(a),s.type==="preprocess"){const o=s.transform(n.data,a);if(n.common.async)return Promise.resolve(o).then(async i=>{if(t.value==="aborted")return w;const u=await this._def.schema._parseAsync({data:i,path:n.path,parent:n});return u.status==="aborted"?w:u.status==="dirty"||t.value==="dirty"?_e(u.value):u});{if(t.value==="aborted")return w;const i=this._def.schema._parseSync({data:o,path:n.path,parent:n});return i.status==="aborted"?w:i.status==="dirty"||t.value==="dirty"?_e(i.value):i}}if(s.type==="refinement"){const o=i=>{const u=s.refinement(i,a);if(n.common.async)return Promise.resolve(u);if(u instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return i};if(n.common.async===!1){const i=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});return i.status==="aborted"?w:(i.status==="dirty"&&t.dirty(),o(i.value),{status:t.value,value:i.value})}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(i=>i.status==="aborted"?w:(i.status==="dirty"&&t.dirty(),o(i.value).then(()=>({status:t.value,value:i.value}))))}if(s.type==="transform")if(n.common.async===!1){const o=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});if(!de(o))return w;const i=s.transform(o.value,a);if(i instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:i}}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(o=>de(o)?Promise.resolve(s.transform(o.value,a)).then(i=>({status:t.value,value:i})):w);x.assertNever(s)}}me.create=(r,e,t)=>new me({schema:r,typeName:k.ZodEffects,effect:e,...S(t)}),me.createWithPreprocess=(r,e,t)=>new me({schema:e,effect:{type:"preprocess",transform:r},typeName:k.ZodEffects,...S(t)});class se extends N{_parse(e){return this._getType(e)===g.undefined?B(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}se.create=(r,e)=>new se({innerType:r,typeName:k.ZodOptional,...S(e)});class ye extends N{_parse(e){return this._getType(e)===g.null?B(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}ye.create=(r,e)=>new ye({innerType:r,typeName:k.ZodNullable,...S(e)});class Be extends N{_parse(e){const{ctx:t}=this._processInputParams(e);let n=t.data;return t.parsedType===g.undefined&&(n=this._def.defaultValue()),this._def.innerType._parse({data:n,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}Be.create=(r,e)=>new Be({innerType:r,typeName:k.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...S(e)});class He extends N{_parse(e){const{ctx:t}=this._processInputParams(e),n={...t,common:{...t.common,issues:[]}},s=this._def.innerType._parse({data:n.data,path:n.path,parent:{...n}});return Ne(s)?s.then(a=>({status:"valid",value:a.status==="valid"?a.value:this._def.catchValue({get error(){return new Y(n.common.issues)},input:n.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new Y(n.common.issues)},input:n.data})}}removeCatch(){return this._def.innerType}}He.create=(r,e)=>new He({innerType:r,typeName:k.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...S(e)});class xt extends N{_parse(e){if(this._getType(e)!==g.nan){const n=this._getOrReturnCtx(e);return p(n,{code:d.invalid_type,expected:g.nan,received:n.parsedType}),w}return{status:"valid",value:e.data}}}xt.create=r=>new xt({typeName:k.ZodNaN,...S(r)});class mr extends N{_parse(e){const{ctx:t}=this._processInputParams(e),n=t.data;return this._def.type._parse({data:n,path:t.path,parent:t})}unwrap(){return this._def.type}}class Ge extends N{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.common.async)return(async()=>{const a=await this._def.in._parseAsync({data:n.data,path:n.path,parent:n});return a.status==="aborted"?w:a.status==="dirty"?(t.dirty(),_e(a.value)):this._def.out._parseAsync({data:a.value,path:n.path,parent:n})})();{const s=this._def.in._parseSync({data:n.data,path:n.path,parent:n});return s.status==="aborted"?w:s.status==="dirty"?(t.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:n.path,parent:n})}}static create(e,t){return new Ge({in:e,out:t,typeName:k.ZodPipeline})}}class Xe extends N{_parse(e){const t=this._def.innerType._parse(e),n=s=>(de(s)&&(s.value=Object.freeze(s.value)),s);return Ne(t)?t.then(s=>n(s)):n(t)}unwrap(){return this._def.innerType}}Xe.create=(r,e)=>new Xe({innerType:r,typeName:k.ZodReadonly,...S(e)});function Ct(r,e){const t=typeof r=="function"?r(e):typeof r=="string"?{message:r}:r;return typeof t=="string"?{message:t}:t}function yr(r,e={},t){return r?ke.create().superRefine((n,s)=>{const a=r(n);if(a instanceof Promise)return a.then(o=>{if(!o){const i=Ct(e,n),u=i.fatal??t??!0;s.addIssue({code:"custom",...i,fatal:u})}});if(!a){const o=Ct(e,n),i=o.fatal??t??!0;s.addIssue({code:"custom",...o,fatal:i})}}):ke.create()}var k;(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"})(k||(k={}));const gr=(r,e={message:`Input not instance of ${r.name}`})=>yr(t=>t instanceof r,e),$=K.create,H=fe.create;ke.create,ne.create;const D=Q.create,P=M.create,vr=Re.create;Me.create,ue.create;const _r=Le.create,xe=pe.create;Pe.create,se.create,ye.create;class St extends Error{constructor(t){const n=`Invalid ChaosConfig:
|
|
2
|
-
${
|
|
3
|
-
`)}`;super(n);L(this,"issues");this.name="ChaosConfigError",this.issues=t}}const z=H().min(0,"Probability must be >= 0").max(1,"Probability must be <= 1"),Tt=H().int().min(1),V={onNth:Tt.optional(),everyNth:Tt.optional(),afterN:H().int().min(0).optional()},F=[r=>[r.onNth,r.everyNth,r.afterN].filter(e=>e!==void 0).length<=1,{message:"Only one of onNth, everyNth, or afterN may be set on a single rule"}],br=vr([$().min(1,"graphqlOperation must not be empty"),gr(RegExp).refine(r=>!r.global&&!r.sticky,{message:"graphqlOperation RegExp must not use global (g) or sticky (y) flags due to lastIndex mutation"})]),Ce={urlPattern:$().min(1,"urlPattern must not be empty"),methods:D($()).optional(),graphqlOperation:br.optional()},kr=P({...Ce,statusCode:H().int().min(100).max(599),probability:z,body:$().optional(),statusText:$().optional(),headers:_r($()).optional(),...V}).strict().refine(...F),wr=P({...Ce,delayMs:H().min(0,"delayMs must be >= 0"),probability:z,...V}).strict().refine(...F),xr=P({...Ce,probability:z,timeout:H().min(0,"timeout must be >= 0").optional(),...V}).strict().refine(...F),Cr=P({...Ce,probability:z,strategy:xe(["truncate","malformed-json","empty","wrong-type"]),...V}).strict().refine(...F),Sr=P({...Ce,probability:z,...V}).strict().refine(...F),Tr=P({failures:D(kr).optional(),latencies:D(wr).optional(),aborts:D(xr).optional(),corruptions:D(Cr).optional(),cors:D(Sr).optional()}).strict(),Er=P({selector:$().min(1,"selector must not be empty"),action:xe(["disable","hide","remove"]),probability:z}).strict(),Or=P({assaults:D(Er).optional()}).strict(),Qe=xe(["inbound","outbound","both"]),Nr=P({urlPattern:$().min(1,"urlPattern must not be empty"),direction:Qe,probability:z,...V}).strict().refine(...F),Ar=P({urlPattern:$().min(1,"urlPattern must not be empty"),direction:Qe,delayMs:H().min(0,"delayMs must be >= 0"),probability:z,...V}).strict().refine(...F),Rr=P({urlPattern:$().min(1,"urlPattern must not be empty"),direction:Qe,strategy:xe(["truncate","malformed-json","empty","wrong-type"]),probability:z,...V}).strict().refine(...F),Mr=H().int().refine(r=>r===1e3||r>=3e3&&r<=4999,{message:"code must be 1000 or in the range 3000-4999"}),Lr=$().refine(r=>new TextEncoder().encode(r).length<=123,{message:"reason must be <= 123 UTF-8 bytes"}),Pr=P({urlPattern:$().min(1,"urlPattern must not be empty"),code:Mr.optional(),reason:Lr.optional(),afterMs:H().min(0,"afterMs must be >= 0").optional(),probability:z,...V}).strict().refine(...F),jr=P({drops:D(Nr).optional(),delays:D(Ar).optional(),corruptions:D(Rr).optional(),closes:D(Pr).optional()}).strict(),Je=$().min(1,"eventType must not be empty"),Ir=P({urlPattern:$().min(1,"urlPattern must not be empty"),eventType:Je.optional(),probability:z,...V}).strict().refine(...F),$r=P({urlPattern:$().min(1,"urlPattern must not be empty"),eventType:Je.optional(),delayMs:H().min(0,"delayMs must be >= 0"),probability:z,...V}).strict().refine(...F),Zr=P({urlPattern:$().min(1,"urlPattern must not be empty"),eventType:Je.optional(),strategy:xe(["truncate","malformed-json","empty","wrong-type"]),probability:z,...V}).strict().refine(...F),Dr=P({urlPattern:$().min(1,"urlPattern must not be empty"),afterMs:H().min(0,"afterMs must be >= 0").optional(),probability:z,...V}).strict().refine(...F),qr=P({drops:D(Ir).optional(),delays:D($r).optional(),corruptions:D(Zr).optional(),closes:D(Dr).optional()}).strict(),zr=P({network:Tr.optional(),ui:Or.optional(),websocket:jr.optional(),sse:qr.optional(),seed:H().int("Seed must be an integer").optional()}).strict();function Et(r){const e=zr.safeParse(r);if(!e.success){const t=e.error.issues.map(n=>`${n.path.join(".")}: ${n.message}`);throw new St(t)}return e.data}function Vr(r){let e=r|0;return()=>{e=e+1831565813|0;let t=Math.imul(e^e>>>15,1|e);return t=t+Math.imul(t^t>>>7,61|t)^t,((t^t>>>14)>>>0)/4294967296}}function Ot(){return Math.random()*4294967296>>>0}function Nt(r){const e=r??Ot();return{random:Vr(e),seed:e}}class At{constructor(e=2e3){L(this,"listeners",new Map);L(this,"log",[]);this.maxLogEntries=e}on(e,t){this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t)}off(e,t){var n;(n=this.listeners.get(e))==null||n.delete(t)}emit(e){this.log.push(e),this.log.length>this.maxLogEntries&&this.log.shift(),this.notify(this.listeners.get(e.type),e),this.notify(this.listeners.get("*"),e)}getLog(){return[...this.log]}clearLog(){this.log=[]}notify(e,t){if(e)for(const n of e)try{n(t)}catch{}}}function q(r,e){return e()<r}function ae(r,e){const t=(e.get(r)??0)+1;return e.set(r,t),t}function ie(r,e){return r.onNth!==void 0?e===r.onNth:r.everyNth!==void 0?e%r.everyNth===0:r.afterN!==void 0?e>r.afterN:!0}function oe(r,e){return e==="*"?!0:r.includes(e)}function Ye(r,e){switch(e){case"truncate":return r.slice(0,Math.max(0,Math.floor(r.length/2)));case"malformed-json":return`${r}"}`;case"empty":return"";case"wrong-type":return"<html><body>Unexpected HTML</body></html>"}}function Ke(r){const e=r.replace(/#[^\r\n]*/g," "),t=/\b(?:query|mutation|subscription)\s+([A-Za-z_][A-Za-z0-9_]*)/.exec(e);return(t==null?void 0:t[1])??null}function Fr(r){try{return JSON.parse(r)}catch{return}}function Rt(r){if(!r||typeof r!="object")return{isGraphQL:!1,operationName:null};if(Array.isArray(r))return r.length===0?{isGraphQL:!1,operationName:null}:Rt(r[0]);const e=r,t=typeof e.query=="string",n=typeof e.operationName=="string";return!t&&!n?{isGraphQL:!1,operationName:null}:n&&e.operationName.length>0?{isGraphQL:!0,operationName:e.operationName}:t?{isGraphQL:!0,operationName:Ke(e.query)}:{isGraphQL:!0,operationName:null}}function Ur(r){let e;try{e=new URL(r,"http://_chaos-maker.invalid")}catch{return{kind:"not-graphql"}}const t=e.searchParams.get("operationName"),n=e.searchParams.get("query");return t&&t.length>0?{kind:"extracted",operationName:t}:n&&n.length>0?{kind:"extracted",operationName:Ke(n)}:{kind:"not-graphql"}}function et(r,e,t,n){const s=r.toUpperCase();if(s==="POST"){if(t!==null){const a=Fr(t);if(a===void 0)return{kind:"not-graphql"};const{isGraphQL:o,operationName:i}=Rt(a);return o?{kind:"extracted",operationName:i}:{kind:"not-graphql"}}return n?{kind:"unparseable"}:{kind:"not-graphql"}}return s==="GET"?Ur(e):{kind:"not-graphql"}}function Mt(r,e){return e===null?!1:typeof r=="string"?r===e:((r.global||r.sticky)&&(r.lastIndex=0),r.test(e))}function je(r,e){return r?e.kind==="not-graphql"?{kind:"no-match"}:e.kind==="unparseable"?{kind:"unparseable"}:Mt(r,e.operationName)?{kind:"match",operationName:e.operationName}:{kind:"no-match"}:e.kind==="extracted"?{kind:"skip-no-constraint",operationName:e.operationName}:{kind:"skip-no-constraint",operationName:null}}function Ie(r){return typeof Request<"u"&&r instanceof Request}function Wr(r){return Ie(r)?r.url:r.toString()}function Br(r,e){return e!=null&&e.method?e.method.toUpperCase():Ie(r)?r.method.toUpperCase():"GET"}function Hr(r,e){if(e!=null&&e.signal)return e.signal;if(Ie(r))return r.signal}function Gr(){if(typeof DOMException<"u")return new DOMException("The user aborted a request.","AbortError");const r=new Error("The user aborted a request.");return r.name="AbortError",r}function Xr(r,e){if(!e)return r;const t=new AbortController,n=i=>{o(),t.signal.aborted||t.abort(i.reason)},s=()=>n(r),a=()=>n(e),o=()=>{r.removeEventListener("abort",s),e.removeEventListener("abort",a)};return r.aborted?(n(r),t.signal):e.aborted?(n(e),t.signal):(r.addEventListener("abort",s,{once:!0}),e.addEventListener("abort",a,{once:!0}),t.signal)}function Qr(r,e){return e?{...r??{},signal:e}:r}async function Jr(r,e){const t=e==null?void 0:e.body;if(t!=null){if(typeof t=="string")return{text:t,unparseable:!1};if(typeof URLSearchParams<"u"&&t instanceof URLSearchParams)return{text:t.toString(),unparseable:!1};if(typeof Blob<"u"&&t instanceof Blob){if(!(t.type===""||/json|text|graphql/i.test(t.type)))return{text:null,unparseable:!0};try{return{text:await t.text(),unparseable:!1}}catch{return{text:null,unparseable:!0}}}return{text:null,unparseable:!0}}if(Ie(r)){if(r.body===null)return{text:null,unparseable:!1};try{return{text:await r.clone().text(),unparseable:!1}}catch{return{text:null,unparseable:!0}}}return{text:null,unparseable:!1}}function Se(r,e,t,n,s){r==null||r.emit({type:e,timestamp:Date.now(),applied:!1,detail:{url:t,method:n,...s,reason:"graphql-body-unparseable"}})}function $e(r,e,t,n,s){if(!oe(e,r.urlPattern))return{proceed:!1,outcome:null};if(r.methods&&!r.methods.includes(t))return{proceed:!1,outcome:null};const a=je(r.graphqlOperation,n);if(a.kind==="no-match"||a.kind==="unparseable")return{proceed:!1,outcome:a};const o=ae(r,s);return ie(r,o)?{proceed:!0,outcome:a}:{proceed:!1,outcome:a}}function Te(r){return r?r.kind==="match"||r.kind==="skip-no-constraint"?r.operationName?{operationName:r.operationName}:{}:{}:{}}function Lt(r,e,t,n,s,a){r==null||r.emit({type:"network:abort",timestamp:Date.now(),applied:s,detail:{url:t,method:n,timeoutMs:e.timeout,...Te(a)}})}function Ze(r,e,t,n,s,a){r==null||r.emit({type:"network:corruption",timestamp:Date.now(),applied:s,detail:{url:t,method:n,strategy:e.strategy,...Te(a)}})}function Yr(r){return r.graphqlOperation!==void 0}function Kr(r,e,t,n,s=new Map){return async(a,o)=>{var T,E,O,I;const i=Wr(a),u=Br(a,o),y=Hr(a,o),C=(()=>{const h=[e.failures,e.latencies,e.aborts,e.corruptions,e.cors];for(const A of h)if(A!=null&&A.some(Yr))return!0;return!1})();let j={kind:"not-graphql"};if(C){const h=await Jr(a,o);j=et(u,i,h.text,h.unparseable)}if(e.cors)for(const h of e.cors){if(!oe(i,h.urlPattern)||h.methods&&!h.methods.includes(u))continue;const A=je(h.graphqlOperation,j);if(A.kind==="no-match")continue;if(A.kind==="unparseable"){Se(n,"network:cors",i,u,{});continue}const G=ae(h,s);if(!ie(h,G))continue;const te=q(h.probability,t);if(n==null||n.emit({type:"network:cors",timestamp:Date.now(),applied:te,detail:{url:i,method:u,...Te(A)}}),te){console.debug(`[chaos-maker] CORS block: ${u} ${i}`);const le=new TypeError("Failed to fetch");throw le.stack="",le}}let U=null,ee=null,W,f,c=!1;const l=h=>{!U||c||(c=!0,f&&(clearTimeout(f),f=void 0),Lt(n,U,i,u,h,ee))};if(e.aborts)for(const h of e.aborts){const A=$e(h,i,u,j,s);if(!A.proceed){((T=A.outcome)==null?void 0:T.kind)==="unparseable"&&Se(n,"network:abort",i,u,{timeoutMs:h.timeout});continue}if(!q(h.probability,t)){Lt(n,h,i,u,!1,A.outcome);continue}console.warn(`CHAOS: Aborting ${u} ${i} after ${h.timeout||0}ms`),U=h,ee=A.outcome;const te=new AbortController;W=Xr(te.signal,y);const le=()=>{c||(l(!0),te.abort(Gr()))};h.timeout?f=setTimeout(le,h.timeout):le();break}if(U)try{const h=await r(a,Qr(o,W));return l(!1),h}catch(h){throw l(!1),h}if(e.failures)for(const h of e.failures){const A=$e(h,i,u,j,s);if(!A.proceed){((E=A.outcome)==null?void 0:E.kind)==="unparseable"&&Se(n,"network:failure",i,u,{statusCode:h.statusCode});continue}const G=q(h.probability,t);if(n==null||n.emit({type:"network:failure",timestamp:Date.now(),applied:G,detail:{url:i,method:u,statusCode:h.statusCode,...Te(A.outcome)}}),G){console.warn(`CHAOS: Forcing ${h.statusCode} for ${u} ${i}`);const te=h.body??JSON.stringify({error:"Chaos Maker Attack!"}),le=h.headers??{};return new Response(te,{status:h.statusCode,statusText:h.statusText??"Service Unavailable (Chaos)",headers:le})}}if(e.latencies)for(const h of e.latencies){const A=$e(h,i,u,j,s);if(!A.proceed){((O=A.outcome)==null?void 0:O.kind)==="unparseable"&&Se(n,"network:latency",i,u,{delayMs:h.delayMs});continue}const G=q(h.probability,t);n==null||n.emit({type:"network:latency",timestamp:Date.now(),applied:G,detail:{url:i,method:u,delayMs:h.delayMs,...Te(A.outcome)}}),G&&(console.warn(`CHAOS: Adding ${h.delayMs}ms latency to ${u} ${i}`),await new Promise(te=>setTimeout(te,h.delayMs)))}let m=null,_=null;if(e.corruptions)for(const h of e.corruptions){const A=$e(h,i,u,j,s);if(!A.proceed){((I=A.outcome)==null?void 0:I.kind)==="unparseable"&&Se(n,"network:corruption",i,u,{strategy:h.strategy});continue}if(!q(h.probability,t)){Ze(n,h,i,u,!1,A.outcome);continue}m=h,_=A.outcome;break}let b;try{b=await r(a,o)}catch(h){throw m&&Ze(n,m,i,u,!1,_),h}if(!m)return b;try{console.warn(`CHAOS: Corrupting response for ${u} ${i} with strategy: ${m.strategy}`);const h=await b.text(),A=Ye(h,m.strategy);return Ze(n,m,i,u,!0,_),new Response(A,{status:b.status,statusText:b.statusText,headers:b.headers})}catch(h){throw Ze(n,m,i,u,!1,_),h}}}function en(r){return r==null?{text:null,unparseable:!1}:typeof r=="string"?{text:r,unparseable:!1}:typeof URLSearchParams<"u"&&r instanceof URLSearchParams?{text:r.toString(),unparseable:!1}:{text:null,unparseable:!0}}function tn(r){return r.graphqlOperation!==void 0}function rn(r){const e=[r.failures,r.latencies,r.aborts,r.corruptions,r.cors];for(const t of e)if(t!=null&&t.some(tn))return!0;return!1}function Ee(r,e,t,n,s){r==null||r.emit({type:e,timestamp:Date.now(),applied:!1,detail:{url:t,method:n,...s,reason:"graphql-body-unparseable"}})}function De(r,e,t,n,s){if(!oe(e,r.urlPattern))return{proceed:!1,outcome:null};if(r.methods&&!r.methods.includes(t))return{proceed:!1,outcome:null};const a=je(r.graphqlOperation,n);if(a.kind==="no-match"||a.kind==="unparseable")return{proceed:!1,outcome:a};const o=ae(r,s);return ie(r,o)?{proceed:!0,outcome:a}:{proceed:!1,outcome:a}}function Oe(r){return r?r.kind==="match"||r.kind==="skip-no-constraint"?r.operationName?{operationName:r.operationName}:{}:{}:{}}function Pt(r,e,t,n,s,a){r==null||r.emit({type:"network:abort",timestamp:Date.now(),applied:s,detail:{url:t,method:n,timeoutMs:e.timeout,...Oe(a)}})}function jt(r,e,t,n,s,a){r==null||r.emit({type:"network:corruption",timestamp:Date.now(),applied:s,detail:{url:t,method:n,strategy:e.strategy,...Oe(a)}})}function nn(r,e,t,n,s=new Map){const a=rn(e);return function(o){var U,ee,W,f;const i=this._chaos_url,u=this._chaos_method;let y={kind:"not-graphql"};if(a){const c=en(o);y=et(u,i,c.text,c.unparseable)}if(e.cors)for(const c of e.cors){if(!oe(i,c.urlPattern)||c.methods&&!c.methods.includes(u))continue;const l=je(c.graphqlOperation,y);if(l.kind==="no-match")continue;if(l.kind==="unparseable"){Ee(n,"network:cors",i,u,{});continue}const m=ae(c,s);if(!ie(c,m))continue;const _=q(c.probability,t);if(n==null||n.emit({type:"network:cors",timestamp:Date.now(),applied:_,detail:{url:i,method:u,...Oe(l)}}),_){console.debug(`[chaos-maker] CORS block: ${u} ${i}`),Object.defineProperty(this,"status",{value:0}),Object.defineProperty(this,"statusText",{value:""}),this.dispatchEvent(new Event("error")),this.dispatchEvent(new Event("loadend"));return}}if(e.aborts)for(const c of e.aborts){const l=De(c,i,u,y,s);if(!l.proceed){((U=l.outcome)==null?void 0:U.kind)==="unparseable"&&Ee(n,"network:abort",i,u,{timeoutMs:c.timeout});continue}if(!q(c.probability,t)){Pt(n,c,i,u,!1,l.outcome);continue}console.warn(`CHAOS: Aborting ${u} ${i} after ${c.timeout||0}ms`);let _=!1,b;const T=()=>{b&&(clearTimeout(b),b=void 0),typeof this.removeEventListener=="function"&&this.removeEventListener("loadend",O)},E=h=>{_||(_=!0,T(),Pt(n,c,i,u,h,l.outcome))},O=()=>{E(!1)},I=()=>{_||(E(!0),this.abort())};typeof this.addEventListener=="function"&&this.addEventListener("loadend",O);try{r.call(this,o)}catch(h){throw E(!1),h}if(_)return;c.timeout?b=setTimeout(I,c.timeout):I();return}if(e.failures)for(const c of e.failures){const l=De(c,i,u,y,s);if(!l.proceed){((ee=l.outcome)==null?void 0:ee.kind)==="unparseable"&&Ee(n,"network:failure",i,u,{statusCode:c.statusCode});continue}const m=q(c.probability,t);if(n==null||n.emit({type:"network:failure",timestamp:Date.now(),applied:m,detail:{url:i,method:u,statusCode:c.statusCode,...Oe(l.outcome)}}),m){console.warn(`CHAOS: Forcing ${c.statusCode} for ${u} ${i}`),Object.defineProperty(this,"status",{value:c.statusCode}),Object.defineProperty(this,"statusText",{value:c.statusText??"Service Unavailable (Chaos)"});const _=c.body??JSON.stringify({error:"Chaos Maker Attack!"});Object.defineProperty(this,"responseText",{value:_,configurable:!0});const b=c.headers??{};Object.defineProperty(this,"getResponseHeader",{value:T=>{const E=Object.keys(b).find(O=>O.toLowerCase()===T.toLowerCase());return E?b[E]:null},configurable:!0}),Object.defineProperty(this,"getAllResponseHeaders",{value:()=>Object.entries(b).map(([T,E])=>`${T}: ${E}`).join(`\r
|
|
4
|
-
`),configurable:!0}),this.dispatchEvent(new Event("error")),this.dispatchEvent(new Event("load")),this.dispatchEvent(new Event("loadend"));return}}let C=null,j=null;if(e.corruptions)for(const c of e.corruptions){const l=De(c,i,u,y,s);if(!l.proceed){((W=l.outcome)==null?void 0:W.kind)==="unparseable"&&Ee(n,"network:corruption",i,u,{strategy:c.strategy});continue}if(!q(c.probability,t)){jt(n,c,i,u,!1,l.outcome);continue}C=c,j=l.outcome;break}if(C){let c=!1,l=null;const m=()=>{typeof this.removeEventListener=="function"&&(this.removeEventListener("error",T),this.removeEventListener("abort",T),this.removeEventListener("loadend",E))},_=O=>{c||(c=!0,jt(n,C,i,u,O,j),m())},b=()=>{if(l!==null)return l;delete this.responseText;try{const O=this.responseText;return typeof O!="string"?(Object.defineProperty(this,"responseText",{value:O,configurable:!0}),_(!1),O):(l=Ye(O,C.strategy),Object.defineProperty(this,"responseText",{value:l,configurable:!0}),_(!0),l)}catch(O){throw _(!1),O}},T=()=>{_(!1)},E=()=>{if(!c)try{b()}catch{}};typeof this.addEventListener=="function"&&(this.addEventListener("error",T),this.addEventListener("abort",T),this.addEventListener("loadend",E)),Object.defineProperty(this,"responseText",{get(){return b()},configurable:!0})}if(e.latencies)for(const c of e.latencies){const l=De(c,i,u,y,s);if(!l.proceed){((f=l.outcome)==null?void 0:f.kind)==="unparseable"&&Ee(n,"network:latency",i,u,{delayMs:c.delayMs});continue}const m=q(c.probability,t);if(n==null||n.emit({type:"network:latency",timestamp:Date.now(),applied:m,detail:{url:i,method:u,delayMs:c.delayMs,...Oe(l.outcome)}}),m){console.warn(`CHAOS: Adding ${c.delayMs}ms latency to ${u} ${i}`),setTimeout(()=>{r.call(this,o)},c.delayMs);return}}r.call(this,o)}}function sn(r){return function(e,t){this._chaos_url=t.toString(),this._chaos_method=e.toUpperCase(),r.call(this,e,t)}}function tt(r,e,t,n){const s=q(e.probability,t);if(n==null||n.emit({type:"ui:assault",timestamp:Date.now(),applied:s,detail:{selector:e.selector,action:e.action}}),!!s){console.warn(`CHAOS: Applying action '${e.action}' to element:`,r);try{switch(e.action){case"disable":"disabled"in r&&(r.disabled=!0);break;case"hide":r.style.display="none";break;case"remove":r.remove();break}}catch(a){console.error("Chaos Maker failed to assault element:",a,r)}}}function an(r,e,t,n){if(r.nodeType!==Node.ELEMENT_NODE||!e.assaults)return;const s=r;for(const a of e.assaults)try{s.matches(a.selector)&&tt(s,a,t,n),s.querySelectorAll(a.selector).forEach(o=>{tt(o,a,t,n)})}catch(o){console.error(`Chaos Maker: Invalid selector '${a.selector}'`,o)}}function on(r,e,t){if(r.assaults){console.log("CHAOS: Running initial DOM scan for existing elements...");for(const s of r.assaults)try{document.querySelectorAll(s.selector).forEach(a=>{tt(a,s,e,t)})}catch(a){console.error(`Chaos Maker: Invalid selector in initial scan '${s.selector}'`,a)}}return new MutationObserver(s=>{for(const a of s)a.type==="childList"&&a.addedNodes.forEach(o=>an(o,r,e,t))})}const It=Symbol.for("chaos-maker.websocket.intercepted");function cn(r,e){return r==="both"?!0:r===e}function $t(r){return typeof r=="string"?"text":"binary"}function Zt(r,e){switch(e){case"truncate":return r.slice(0,Math.max(0,Math.floor(r.length/2)));case"malformed-json":return`${r}"}`;case"empty":return"";case"wrong-type":return"<html><body>Unexpected HTML</body></html>"}}function Dt(r,e){if(e==="malformed-json"||e==="wrong-type")return null;if(e==="empty")return typeof Blob<"u"&&r instanceof Blob?new Blob([]):r instanceof ArrayBuffer?new ArrayBuffer(0):new Uint8Array(0);if(typeof Blob<"u"&&r instanceof Blob)return r.slice(0,Math.max(0,Math.floor(r.size/2)));if(r instanceof ArrayBuffer)return r.slice(0,Math.max(0,Math.floor(r.byteLength/2)));const t=r,n=Math.max(0,Math.floor(t.byteLength/2));return new Uint8Array(t.buffer.slice(t.byteOffset,t.byteOffset+n))}function ge(r,e,t,n,s){if(!r)return null;for(const a of r){if(!oe(e,a.urlPattern)||!cn(a.direction,t))continue;const o=ae(a,s);if(ie(a,o)&&q(a.probability,n))return a}return null}function qe(r,e,t,n,s){r.emit({type:"websocket:drop",timestamp:Date.now(),applied:!0,detail:{url:e,direction:t,payloadType:n,...s?{reason:s}:{}}})}function qt(r,e,t,n,s){r.emit({type:"websocket:delay",timestamp:Date.now(),applied:!0,detail:{url:e,direction:t,payloadType:n,delayMs:s}})}function ve(r,e,t,n,s,a,o){r.emit({type:"websocket:corrupt",timestamp:Date.now(),applied:a,detail:{url:e,direction:t,payloadType:n,strategy:s,...o?{reason:o}:{}}})}function un(r,e,t,n){r.emit({type:"websocket:close",timestamp:Date.now(),applied:!0,detail:{url:e,closeCode:t,closeReason:n}})}function ln(r,e,t,n,s){const a=new Map;let o=!0;const i=(f,c)=>{let l=a.get(f);l||(l=new Set,a.set(f,l)),l.add(c)},u=(f,c)=>{var l;(l=a.get(f))==null||l.delete(c)},y=(f,c)=>{const l=a.get(f);if(l){for(const m of l)clearTimeout(m.handle),m.kind==="delay"&&qe(t,m.url,m.direction,m.payloadType,c);a.delete(f)}},C=(f,c,l)=>{const m=new MessageEvent("message",{data:l,origin:c.origin,lastEventId:c.lastEventId,source:c.source,ports:Array.from(c.ports??[])});m[It]=!0,f.dispatchEvent(m)},j=(f,c,l,m)=>{if(!o)return{handled:!1,data:l};const _="outbound",b=$t(l);if(ge(e.drops,c,_,n,s))return qe(t,c,_,b),{handled:!0,data:l};let T=l;const E=ge(e.corruptions,c,_,n,s);if(E)if(b==="text")T=Zt(T,E.strategy),ve(t,c,_,b,E.strategy,!0);else{const I=Dt(T,E.strategy);I===null?ve(t,c,_,b,E.strategy,!1,"incompatible-payload-type"):(T=I,ve(t,c,_,b,E.strategy,!0))}const O=ge(e.delays,c,_,n,s);if(O){qt(t,c,_,b,O.delayMs);const I={kind:"delay",handle:setTimeout(()=>{u(f,I);try{m(T)}catch{}},O.delayMs),url:c,direction:_,payloadType:b};return i(f,I),{handled:!0,data:T}}return{handled:!1,data:T}},U=(f,c)=>{f.addEventListener("message",l=>{const m=l;if(m[It]||!o)return;const _="inbound",b=$t(m.data);if(ge(e.drops,c,_,n,s)){m.stopImmediatePropagation(),qe(t,c,_,b);return}let T=m.data,E=!1;const O=ge(e.corruptions,c,_,n,s);if(O)if(b==="text")T=Zt(T,O.strategy),E=!0,ve(t,c,_,b,O.strategy,!0);else{const h=Dt(T,O.strategy);h===null?ve(t,c,_,b,O.strategy,!1,"incompatible-payload-type"):(T=h,E=!0,ve(t,c,_,b,O.strategy,!0))}const I=ge(e.delays,c,_,n,s);if(I){m.stopImmediatePropagation(),qt(t,c,_,b,I.delayMs);const h={kind:"delay",handle:setTimeout(()=>{u(f,h),C(f,m,T)},I.delayMs),url:c,direction:_,payloadType:b};i(f,h);return}E&&(m.stopImmediatePropagation(),C(f,m,T))})},ee=(f,c)=>{if(e.closes)for(const l of e.closes){if(!oe(c,l.urlPattern))continue;const m=ae(l,s);if(!ie(l,m)||!q(l.probability,n))continue;const _=l.code??1e3,b=l.reason??"Chaos Maker close",T=l.afterMs??0,E=()=>{if(o){y(f,"close-interrupt"),un(t,c,_,b);try{f.close(_,b)}catch{try{f.close()}catch{}}}};if(T<=0)f.readyState===f.OPEN?E():f.addEventListener("open",E,{once:!0});else{const O=()=>{const I={kind:"close",handle:setTimeout(E,T)};i(f,I)};f.readyState===f.OPEN?O():f.addEventListener("open",O,{once:!0})}return}};function W(f,c){const l=new r(f,c),m=typeof f=="string"?f:f.toString(),_=l.send.bind(l);return l.send=function(T){const E=j(l,m,T,_);E.handled||_(E.data)},U(l,m),ee(l,m),l}Object.defineProperty(W,"prototype",{value:r.prototype,writable:!1});for(const f of["CONNECTING","OPEN","CLOSING","CLOSED"])W[f]=r[f];return{Wrapped:W,uninstall(){o=!1;for(const[,f]of a)for(const c of f)clearTimeout(c.handle),c.kind==="delay"&&qe(t,c.url,c.direction,c.payloadType,"stop-during-delay");a.clear()}}}const zt=Symbol.for("chaos-maker.eventsource.intercepted");function dn(r,e){return r===void 0||r==="*"?!0:r===e}function rt(r,e,t,n,s){if(!r)return null;for(const a of r){if(!oe(e,a.urlPattern)||!dn(a.eventType,t))continue;const o=ae(a,s);if(ie(a,o)&&q(a.probability,n))return a}return null}function nt(r,e,t,n){r.emit({type:"sse:drop",timestamp:Date.now(),applied:!0,detail:{url:e,eventType:t,...n?{reason:n}:{}}})}function fn(r,e,t,n){r.emit({type:"sse:delay",timestamp:Date.now(),applied:!0,detail:{url:e,eventType:t,delayMs:n}})}function hn(r,e,t,n){r.emit({type:"sse:corrupt",timestamp:Date.now(),applied:!0,detail:{url:e,eventType:t,strategy:n}})}function pn(r,e,t){r.emit({type:"sse:close",timestamp:Date.now(),applied:!0,detail:{url:e,reason:t}})}function mn(r,e,t,n,s){const a=new Map;let o=!0;const i=(f,c)=>{let l=a.get(f);l||(l=new Set,a.set(f,l)),l.add(c)},u=(f,c)=>{var l;(l=a.get(f))==null||l.delete(c)},y=(f,c)=>{const l=a.get(f);if(l){for(const m of l)clearTimeout(m.handle),m.kind==="delay"&&nt(t,m.url,m.eventType,c);a.delete(f)}},C=(f,c,l)=>{const m=new MessageEvent(c.type||"message",{data:l,origin:c.origin,lastEventId:c.lastEventId});m[zt]=!0,f.dispatchEvent(m)},j=(f,c,l)=>{if(l[zt]||!o)return;const m=l.type||"message";if(rt(e.drops,c,m,n,s)){l.stopImmediatePropagation(),nt(t,c,m);return}let _=typeof l.data=="string"?l.data:String(l.data),b=!1;const T=rt(e.corruptions,c,m,n,s);T&&(_=Ye(_,T.strategy),b=!0,hn(t,c,m,T.strategy));const E=rt(e.delays,c,m,n,s);if(E){l.stopImmediatePropagation(),fn(t,c,m,E.delayMs);const O={kind:"delay",handle:setTimeout(()=>{u(f,O),o&&f.readyState!==f.CLOSED&&C(f,l,_)},E.delayMs),url:c,eventType:m};i(f,O);return}b&&(l.stopImmediatePropagation(),C(f,l,_))},U=f=>{if(!e.closes)return null;for(const c of e.closes){if(!oe(f,c.urlPattern))continue;const l=ae(c,s);if(ie(c,l)&&q(c.probability,n))return c}return null},ee=(f,c)=>{const l=U(c);if(!l)return;const m=l.afterMs??0,_=()=>{if(o){y(f,"close-interrupt"),pn(t,c,"chaos-maker-close");try{f.close()}catch{}try{f.dispatchEvent(new Event("error"))}catch{}}};if(m<=0){const b={kind:"close",handle:setTimeout(_,0)};i(f,b)}else{const b={kind:"close",handle:setTimeout(_,m)};i(f,b)}};function W(f,c){const l=new r(f,c),m=typeof f=="string"?f:f.toString(),_=h=>{j(l,m,h)},b=new Set,T=l.addEventListener.bind(l),E=h=>{b.has(h)||(b.add(h),T(h,_,{capture:!0}))};E("message");const O=h=>{if(h)for(const A of h)A.eventType&&A.eventType!=="*"&&A.eventType!=="message"&&E(A.eventType)};O(e.drops),O(e.delays),O(e.corruptions);const I=(h,A,G)=>{h!=="open"&&h!=="error"&&E(h),T(h,A,G)};return l.addEventListener=I,ee(l,m),l}Object.defineProperty(W,"prototype",{value:r.prototype,writable:!1});for(const f of["CONNECTING","OPEN","CLOSED"])W[f]=r[f];return{Wrapped:W,uninstall(){o=!1;for(const[,f]of a)for(const c of f)clearTimeout(c.handle),c.kind==="delay"&&nt(t,c.url,c.eventType,"stop-during-delay");a.clear()}}}class st{constructor(e,t={}){L(this,"config");L(this,"emitter");L(this,"random");L(this,"seed");L(this,"running",!1);L(this,"target");L(this,"originalFetch");L(this,"originalXhrSend");L(this,"originalXhrOpen");L(this,"domObserver");L(this,"originalWebSocket");L(this,"webSocketHandle");L(this,"originalEventSource");L(this,"eventSourceHandle");L(this,"requestCounters",new Map);this.config=Et(e),this.emitter=new At;const n=Nt(e.seed);this.random=n.random,this.seed=n.seed,this.target=t.target??globalThis,console.log(`Chaos Maker initialized (seed: ${this.seed})`)}getSeed(){return this.seed}on(e,t){this.emitter.on(e,t)}off(e,t){this.emitter.off(e,t)}getLog(){return this.emitter.getLog()}clearLog(){this.emitter.clearLog()}start(){if(this.running){console.warn("Chaos Maker is already running. Call stop() first.");return}this.requestCounters.clear(),this.running=!0,console.log("🛠️ Chaos Maker ENGAGED 🛠️");const e=this.target;this.config.network&&(typeof e.fetch=="function"&&(this.originalFetch=e.fetch,e.fetch=Kr(this.originalFetch.bind(e),this.config.network,this.random,this.emitter,this.requestCounters)),typeof e.XMLHttpRequest=="function"&&(this.originalXhrOpen=e.XMLHttpRequest.prototype.open,e.XMLHttpRequest.prototype.open=sn(this.originalXhrOpen),this.originalXhrSend=e.XMLHttpRequest.prototype.send,e.XMLHttpRequest.prototype.send=nn(this.originalXhrSend,this.config.network,this.random,this.emitter,this.requestCounters))),this.config.ui&&(typeof document>"u"||typeof MutationObserver>"u"?console.warn("Chaos Maker: UI config ignored — no DOM available in current context."):(this.domObserver=on(this.config.ui,this.random,this.emitter),this.domObserver.observe(document.body,{childList:!0,subtree:!0}),console.log("UI Assailant is now observing the DOM."))),this.config.websocket&&typeof e.WebSocket<"u"&&(this.originalWebSocket=e.WebSocket,this.webSocketHandle=ln(this.originalWebSocket,this.config.websocket,this.emitter,this.random,this.requestCounters),e.WebSocket=this.webSocketHandle.Wrapped),this.config.sse&&typeof e.EventSource<"u"&&(this.originalEventSource=e.EventSource,this.eventSourceHandle=mn(this.originalEventSource,this.config.sse,this.emitter,this.random,this.requestCounters),e.EventSource=this.eventSourceHandle.Wrapped)}stop(){this.running=!1,console.log("🛑 Chaos Maker DISENGAGED 🛑");const e=this.target;this.originalFetch&&(e.fetch=this.originalFetch),this.originalXhrSend&&typeof e.XMLHttpRequest=="function"&&(e.XMLHttpRequest.prototype.send=this.originalXhrSend),this.originalXhrOpen&&typeof e.XMLHttpRequest=="function"&&(e.XMLHttpRequest.prototype.open=this.originalXhrOpen),this.domObserver&&(this.domObserver.disconnect(),console.log("UI Assailant has stopped observing.")),this.originalWebSocket&&(e.WebSocket=this.originalWebSocket,this.originalWebSocket=void 0),this.webSocketHandle&&(this.webSocketHandle.uninstall(),this.webSocketHandle=void 0),this.originalEventSource&&(e.EventSource=this.originalEventSource,this.originalEventSource=void 0),this.eventSourceHandle&&(this.eventSourceHandle.uninstall(),this.eventSourceHandle=void 0)}}function at(r){if(r===null||typeof r!="object")return r;if(r instanceof RegExp)return new RegExp(r.source,r.flags);if(Array.isArray(r))return r.map(t=>at(t));const e={};for(const[t,n]of Object.entries(r))e[t]=at(n);return e}function Vt(r){return at(r)}class yn{constructor(e){L(this,"config");this.config=e?Vt(e):{network:{},ui:{},websocket:{},sse:{}},this.config.network||(this.config.network={}),this.config.ui||(this.config.ui={}),this.config.websocket||(this.config.websocket={}),this.config.sse||(this.config.sse={})}failRequests(e,t,n,s,a,o,i){return this.config.network.failures||(this.config.network.failures=[]),this.config.network.failures.push({urlPattern:e,statusCode:t,probability:n,methods:s,body:a,headers:o,...i}),this}addLatency(e,t,n,s,a){return this.config.network.latencies||(this.config.network.latencies=[]),this.config.network.latencies.push({urlPattern:e,delayMs:t,probability:n,methods:s,...a}),this}abortRequests(e,t,n,s,a){return this.config.network.aborts||(this.config.network.aborts=[]),this.config.network.aborts.push({urlPattern:e,probability:t,timeout:n,methods:s,...a}),this}corruptResponses(e,t,n,s,a){return this.config.network.corruptions||(this.config.network.corruptions=[]),this.config.network.corruptions.push({urlPattern:e,strategy:t,probability:n,methods:s,...a}),this}simulateCors(e,t,n,s){return this.config.network.cors||(this.config.network.cors=[]),this.config.network.cors.push({urlPattern:e,probability:t,methods:n,...s}),this}failRequestsOnNth(e,t,n,s){return this.failRequests(e,t,1,s,void 0,void 0,{onNth:n})}addLatencyOnNth(e,t,n,s){return this.addLatency(e,t,1,s,{onNth:n})}abortRequestsOnNth(e,t,n,s){return this.abortRequests(e,1,n,s,{onNth:t})}corruptResponsesOnNth(e,t,n,s){return this.corruptResponses(e,t,1,s,{onNth:n})}simulateCorsOnNth(e,t,n){return this.simulateCors(e,1,n,{onNth:t})}failRequestsEveryNth(e,t,n,s){return this.failRequests(e,t,1,s,void 0,void 0,{everyNth:n})}addLatencyEveryNth(e,t,n,s){return this.addLatency(e,t,1,s,{everyNth:n})}abortRequestsEveryNth(e,t,n,s){return this.abortRequests(e,1,n,s,{everyNth:t})}corruptResponsesEveryNth(e,t,n,s){return this.corruptResponses(e,t,1,s,{everyNth:n})}simulateCorsEveryNth(e,t,n){return this.simulateCors(e,1,n,{everyNth:t})}failRequestsAfterN(e,t,n,s){return this.failRequests(e,t,1,s,void 0,void 0,{afterN:n})}addLatencyAfterN(e,t,n,s){return this.addLatency(e,t,1,s,{afterN:n})}abortRequestsAfterN(e,t,n,s){return this.abortRequests(e,1,n,s,{afterN:t})}corruptResponsesAfterN(e,t,n,s){return this.corruptResponses(e,t,1,s,{afterN:n})}simulateCorsAfterN(e,t,n){return this.simulateCors(e,1,n,{afterN:t})}assaultUi(e,t,n){return this.config.ui.assaults||(this.config.ui.assaults=[]),this.config.ui.assaults.push({selector:e,action:t,probability:n}),this}dropMessages(e,t,n,s){return this.config.websocket.drops||(this.config.websocket.drops=[]),this.config.websocket.drops.push({urlPattern:e,direction:t,probability:n,...s}),this}delayMessages(e,t,n,s,a){return this.config.websocket.delays||(this.config.websocket.delays=[]),this.config.websocket.delays.push({urlPattern:e,direction:t,delayMs:n,probability:s,...a}),this}corruptMessages(e,t,n,s,a){return this.config.websocket.corruptions||(this.config.websocket.corruptions=[]),this.config.websocket.corruptions.push({urlPattern:e,direction:t,strategy:n,probability:s,...a}),this}closeConnection(e,t,n,s){return this.config.websocket.closes||(this.config.websocket.closes=[]),this.config.websocket.closes.push({urlPattern:e,probability:t,...n,...s}),this}dropMessagesOnNth(e,t,n){return this.dropMessages(e,t,1,{onNth:n})}delayMessagesOnNth(e,t,n,s){return this.delayMessages(e,t,n,1,{onNth:s})}failGraphQLOperation(e,t,n,s="*"){return this.config.network.failures||(this.config.network.failures=[]),this.config.network.failures.push({urlPattern:s,statusCode:t,probability:n,graphqlOperation:e}),this}delayGraphQLOperation(e,t,n,s="*"){return this.config.network.latencies||(this.config.network.latencies=[]),this.config.network.latencies.push({urlPattern:s,delayMs:t,probability:n,graphqlOperation:e}),this}dropSSE(e,t,n,s){return this.config.sse.drops||(this.config.sse.drops=[]),this.config.sse.drops.push({urlPattern:e,probability:t,...n?{eventType:n}:{},...s}),this}delaySSE(e,t,n,s,a){return this.config.sse.delays||(this.config.sse.delays=[]),this.config.sse.delays.push({urlPattern:e,delayMs:t,probability:n,...s?{eventType:s}:{},...a}),this}corruptSSE(e,t,n,s,a){return this.config.sse.corruptions||(this.config.sse.corruptions=[]),this.config.sse.corruptions.push({urlPattern:e,strategy:t,probability:n,...s?{eventType:s}:{},...a}),this}closeSSE(e,t,n,s){return this.config.sse.closes||(this.config.sse.closes=[]),this.config.sse.closes.push({urlPattern:e,probability:t,...n,...s}),this}withSeed(e){return this.config.seed=e,this}build(){return Vt(this.config)}}const J="*";function Ft(r){if(r&&typeof r=="object"&&!Object.isFrozen(r)){Object.freeze(r);for(const e of Object.values(r))Ft(e)}return r}const gn=Ft({unstableApi:{network:{failures:[{urlPattern:"/api/",statusCode:500,probability:.1}],latencies:[{urlPattern:"/api/",delayMs:1e3,probability:.2}]}},slowNetwork:{network:{latencies:[{urlPattern:J,delayMs:2e3,probability:1}]}},offlineMode:{network:{cors:[{urlPattern:J,probability:1}]}},flakyConnection:{network:{aborts:[{urlPattern:J,probability:.05}],latencies:[{urlPattern:J,delayMs:3e3,probability:.1}]}},degradedUi:{ui:{assaults:[{selector:"button",action:"disable",probability:.2},{selector:"a",action:"hide",probability:.1}]}},unreliableWebSocket:{websocket:{drops:[{urlPattern:J,direction:"both",probability:.1}],delays:[{urlPattern:J,direction:"inbound",delayMs:500,probability:1}],corruptions:[{urlPattern:J,direction:"inbound",strategy:"truncate",probability:.05}]}},unreliableEventStream:{sse:{drops:[{urlPattern:J,probability:.05}],delays:[{urlPattern:J,delayMs:200,probability:1}],closes:[{urlPattern:J,probability:.02,afterMs:2e3}]}}}),ze="__chaosMakerRegExp";function vn(r){if(r===null||typeof r!="object")return!1;const e=r,t=Object.keys(e);if(t.length!==1||t[0]!==ze)return!1;const n=e[ze];if(!n||typeof n!="object")return!1;const s=n;for(const a of Object.keys(s))if(a!=="source"&&a!=="flags")return!1;return typeof s.source=="string"&&typeof s.flags=="string"}function it(r){if(r===null||typeof r!="object")return r;if(r instanceof RegExp)return{[ze]:{source:r.source,flags:r.flags}};if(Array.isArray(r))return r.map(t=>it(t));const e={};for(const[t,n]of Object.entries(r))e[t]=it(n);return e}function Ve(r){if(r===null||typeof r!="object"||r instanceof RegExp)return r;if(vn(r)){const{source:t,flags:n}=r[ze];try{return new RegExp(t,n)}catch(s){return console.warn(`[chaos-maker] deserializeForTransport: invalid RegExp { source: ${JSON.stringify(t)}, flags: ${JSON.stringify(n)} } — ${s.message}`),r}}if(Array.isArray(r))return r.map(t=>Ve(t));const e={};for(const[t,n]of Object.entries(r))e[t]=Ve(n);return e}const _n=`
|
|
1
|
+
(function(T,S){typeof exports=="object"&&typeof module<"u"?S(exports):typeof define=="function"&&define.amd?define(["exports"],S):(T=typeof globalThis<"u"?globalThis:T||self,S(T.ChaosMaker={}))})(this,(function(T){"use strict";var ia=Object.defineProperty;var ca=(T,S,pe)=>S in T?ia(T,S,{enumerable:!0,configurable:!0,writable:!0,value:pe}):T[S]=pe;var R=(T,S,pe)=>ca(T,typeof S!="symbol"?S+"":S,pe);var S;(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 o of r)a[o]=o;return a},t.getValidEnumValues=r=>{const a=t.objectKeys(r).filter(i=>typeof r[r[i]]!="number"),o={};for(const i of a)o[i]=r[i];return t.objectValues(o)},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 o in r)Object.prototype.hasOwnProperty.call(r,o)&&a.push(o);return a},t.find=(r,a)=>{for(const o of r)if(a(o))return o},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(o=>typeof o=="string"?`'${o}'`:o).join(a)}t.joinValues=s,t.jsonStringifyReplacer=(r,a)=>typeof a=="bigint"?a.toString():a})(S||(S={}));var pe;(function(t){t.mergeShapes=(e,n)=>({...e,...n})})(pe||(pe={}));const m=S.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),le=t=>{switch(typeof t){case"undefined":return m.undefined;case"string":return m.string;case"number":return Number.isNaN(t)?m.nan:m.number;case"boolean":return m.boolean;case"function":return m.function;case"bigint":return m.bigint;case"symbol":return m.symbol;case"object":return Array.isArray(t)?m.array:t===null?m.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?m.promise:typeof Map<"u"&&t instanceof Map?m.map:typeof Set<"u"&&t instanceof Set?m.set:typeof Date<"u"&&t instanceof Date?m.date:m.object;default:return m.unknown}},h=S.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 oe 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 o of a.issues)if(o.code==="invalid_union")o.unionErrors.map(r);else if(o.code==="invalid_return_type")r(o.returnTypeError);else if(o.code==="invalid_arguments")r(o.argumentsError);else if(o.path.length===0)s._errors.push(n(o));else{let i=s,c=0;for(;c<o.path.length;){const u=o.path[c];c===o.path.length-1?(i[u]=i[u]||{_errors:[]},i[u]._errors.push(n(o))):i[u]=i[u]||{_errors:[]},i=i[u],c++}}};return r(this),s}static assert(e){if(!(e instanceof oe))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,S.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()}}oe.create=t=>new oe(t);const at=(t,e)=>{let n;switch(t.code){case h.invalid_type:t.received===m.undefined?n="Required":n=`Expected ${t.expected}, received ${t.received}`;break;case h.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(t.expected,S.jsonStringifyReplacer)}`;break;case h.unrecognized_keys:n=`Unrecognized key(s) in object: ${S.joinValues(t.keys,", ")}`;break;case h.invalid_union:n="Invalid input";break;case h.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${S.joinValues(t.options)}`;break;case h.invalid_enum_value:n=`Invalid enum value. Expected ${S.joinValues(t.options)}, received '${t.received}'`;break;case h.invalid_arguments:n="Invalid function arguments";break;case h.invalid_return_type:n="Invalid function return type";break;case h.invalid_date:n="Invalid date";break;case h.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}"`:S.assertNever(t.validation):t.validation!=="regex"?n=`Invalid ${t.validation}`:n="Invalid";break;case h.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 h.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 h.custom:n="Invalid input";break;case h.invalid_intersection_types:n="Intersection results could not be merged";break;case h.not_multiple_of:n=`Number must be a multiple of ${t.multipleOf}`;break;case h.not_finite:n="Number must be finite";break;default:n=e.defaultError,S.assertNever(t)}return{message:n}};let cs=at;function us(){return cs}const ls=t=>{const{data:e,path:n,errorMaps:s,issueData:r}=t,a=[...n,...r.path||[]],o={...r,path:a};if(r.message!==void 0)return{...r,path:a,message:r.message};let i="";const c=s.filter(u=>!!u).slice().reverse();for(const u of c)i=u(o,{data:e,defaultError:i}).message;return{...r,path:a,message:i}};function g(t,e){const n=us(),s=ls({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,n,n===at?void 0:at].filter(r=>!!r)});t.common.issues.push(s)}class V{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 x;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,o=await r.value;s.push({key:a,value:o})}return V.mergeObjectSync(e,s)}static mergeObjectSync(e,n){const s={};for(const r of n){const{key:a,value:o}=r;if(a.status==="aborted"||o.status==="aborted")return x;a.status==="dirty"&&e.dirty(),o.status==="dirty"&&e.dirty(),a.value!=="__proto__"&&(typeof o.value<"u"||r.alwaysSet)&&(s[a.value]=o.value)}return{status:e.value,value:s}}}const x=Object.freeze({status:"aborted"}),Ne=t=>({status:"dirty",value:t}),Q=t=>({status:"valid",value:t}),Pt=t=>t.status==="aborted",$t=t=>t.status==="dirty",be=t=>t.status==="valid",Ue=t=>typeof Promise<"u"&&t instanceof Promise;var b;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(b||(b={}));class se{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 Lt=(t,e)=>{if(be(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 oe(t.common.issues);return this._error=n,this._error}}};function C(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:(o,i)=>{const{message:c}=t;return o.code==="invalid_enum_value"?{message:c??i.defaultError}:typeof i.data>"u"?{message:c??s??i.defaultError}:o.code!=="invalid_type"?{message:i.defaultError}:{message:c??n??i.defaultError}},description:r}}class M{get description(){return this._def.description}_getType(e){return le(e.data)}_getOrReturnCtx(e,n){return n||{common:e.parent.common,data:e.data,parsedType:le(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new V,ctx:{common:e.parent.common,data:e.data,parsedType:le(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const n=this._parse(e);if(Ue(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==null?void 0:n.async)??!1,contextualErrorMap:n==null?void 0:n.errorMap},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:le(e)},r=this._parseSync({data:e,path:s.path,parent:s});return Lt(s,r)}"~validate"(e){var s,r;const n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:le(e)};if(!this["~standard"].async)try{const a=this._parseSync({data:e,path:[],parent:n});return be(a)?{value:a.value}:{issues:n.common.issues}}catch(a){(r=(s=a==null?void 0:a.message)==null?void 0:s.toLowerCase())!=null&&r.includes("encountered")&&(this["~standard"].async=!0),n.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:n}).then(a=>be(a)?{value:a.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==null?void 0:n.errorMap,async:!0},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:le(e)},r=this._parse({data:e,path:s.path,parent:s}),a=await(Ue(r)?r:Promise.resolve(r));return Lt(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 o=e(r),i=()=>a.addIssue({code:h.custom,...s(r)});return typeof Promise<"u"&&o instanceof Promise?o.then(c=>c?!0:(i(),!1)):o?!0:(i(),!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 we({schema:this,typeName:w.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 fe.create(this,this._def)}nullable(){return xe.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return re.create(this)}promise(){return Fe.create(this,this._def)}or(e){return qe.create([this,e],this._def)}and(e){return Ve.create(this,e,this._def)}transform(e){return new we({...C(this._def),schema:this,typeName:w.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const n=typeof e=="function"?e:()=>e;return new lt({...C(this._def),innerType:this,defaultValue:n,typeName:w.ZodDefault})}brand(){return new js({typeName:w.ZodBranded,type:this,...C(this._def)})}catch(e){const n=typeof e=="function"?e:()=>e;return new dt({...C(this._def),innerType:this,catchValue:n,typeName:w.ZodCatch})}describe(e){const n=this.constructor;return new n({...this._def,description:e})}pipe(e){return ft.create(this,e)}readonly(){return ht.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const ds=/^c[^\s-]{8,}$/i,fs=/^[0-9a-z]+$/,hs=/^[0-9A-HJKMNP-TV-Z]{26}$/i,ps=/^[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,gs=/^[a-z0-9_-]{21}$/i,ys=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,ms=/^[-+]?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)?)??$/,bs=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,vs="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let ot;const _s=/^(?:(?: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])$/,ks=/^(?:(?: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])$/,ws=/^(([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]))$/,xs=/^(([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])$/,Ss=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Cs=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,It="((\\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])))",Es=new RegExp(`^${It}$`);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 Ns(t){return new RegExp(`^${Dt(t)}$`)}function Ts(t){let e=`${It}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 Os(t,e){return!!((e==="v4"||!e)&&_s.test(t)||(e==="v6"||!e)&&ws.test(t))}function Ms(t,e){if(!ys.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==null?void 0:r.typ)!=="JWT"||!r.alg||e&&r.alg!==e)}catch{return!1}}function Rs(t,e){return!!((e==="v4"||!e)&&ks.test(t)||(e==="v6"||!e)&&xs.test(t))}class ie extends M{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==m.string){const a=this._getOrReturnCtx(e);return g(a,{code:h.invalid_type,expected:m.string,received:a.parsedType}),x}const s=new V;let r;for(const a of this._def.checks)if(a.kind==="min")e.data.length<a.value&&(r=this._getOrReturnCtx(e,r),g(r,{code:h.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),g(r,{code:h.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),s.dirty());else if(a.kind==="length"){const o=e.data.length>a.value,i=e.data.length<a.value;(o||i)&&(r=this._getOrReturnCtx(e,r),o?g(r,{code:h.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}):i&&g(r,{code:h.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}),s.dirty())}else if(a.kind==="email")bs.test(e.data)||(r=this._getOrReturnCtx(e,r),g(r,{validation:"email",code:h.invalid_string,message:a.message}),s.dirty());else if(a.kind==="emoji")ot||(ot=new RegExp(vs,"u")),ot.test(e.data)||(r=this._getOrReturnCtx(e,r),g(r,{validation:"emoji",code:h.invalid_string,message:a.message}),s.dirty());else if(a.kind==="uuid")ps.test(e.data)||(r=this._getOrReturnCtx(e,r),g(r,{validation:"uuid",code:h.invalid_string,message:a.message}),s.dirty());else if(a.kind==="nanoid")gs.test(e.data)||(r=this._getOrReturnCtx(e,r),g(r,{validation:"nanoid",code:h.invalid_string,message:a.message}),s.dirty());else if(a.kind==="cuid")ds.test(e.data)||(r=this._getOrReturnCtx(e,r),g(r,{validation:"cuid",code:h.invalid_string,message:a.message}),s.dirty());else if(a.kind==="cuid2")fs.test(e.data)||(r=this._getOrReturnCtx(e,r),g(r,{validation:"cuid2",code:h.invalid_string,message:a.message}),s.dirty());else if(a.kind==="ulid")hs.test(e.data)||(r=this._getOrReturnCtx(e,r),g(r,{validation:"ulid",code:h.invalid_string,message:a.message}),s.dirty());else if(a.kind==="url")try{new URL(e.data)}catch{r=this._getOrReturnCtx(e,r),g(r,{validation:"url",code:h.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),g(r,{validation:"regex",code:h.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),g(r,{code:h.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),g(r,{code:h.invalid_string,validation:{startsWith:a.value},message:a.message}),s.dirty()):a.kind==="endsWith"?e.data.endsWith(a.value)||(r=this._getOrReturnCtx(e,r),g(r,{code:h.invalid_string,validation:{endsWith:a.value},message:a.message}),s.dirty()):a.kind==="datetime"?Ts(a).test(e.data)||(r=this._getOrReturnCtx(e,r),g(r,{code:h.invalid_string,validation:"datetime",message:a.message}),s.dirty()):a.kind==="date"?Es.test(e.data)||(r=this._getOrReturnCtx(e,r),g(r,{code:h.invalid_string,validation:"date",message:a.message}),s.dirty()):a.kind==="time"?Ns(a).test(e.data)||(r=this._getOrReturnCtx(e,r),g(r,{code:h.invalid_string,validation:"time",message:a.message}),s.dirty()):a.kind==="duration"?ms.test(e.data)||(r=this._getOrReturnCtx(e,r),g(r,{validation:"duration",code:h.invalid_string,message:a.message}),s.dirty()):a.kind==="ip"?Os(e.data,a.version)||(r=this._getOrReturnCtx(e,r),g(r,{validation:"ip",code:h.invalid_string,message:a.message}),s.dirty()):a.kind==="jwt"?Ms(e.data,a.alg)||(r=this._getOrReturnCtx(e,r),g(r,{validation:"jwt",code:h.invalid_string,message:a.message}),s.dirty()):a.kind==="cidr"?Rs(e.data,a.version)||(r=this._getOrReturnCtx(e,r),g(r,{validation:"cidr",code:h.invalid_string,message:a.message}),s.dirty()):a.kind==="base64"?Ss.test(e.data)||(r=this._getOrReturnCtx(e,r),g(r,{validation:"base64",code:h.invalid_string,message:a.message}),s.dirty()):a.kind==="base64url"?Cs.test(e.data)||(r=this._getOrReturnCtx(e,r),g(r,{validation:"base64url",code:h.invalid_string,message:a.message}),s.dirty()):S.assertNever(a);return{status:s.value,value:e.data}}_regex(e,n,s){return this.refinement(r=>e.test(r),{validation:n,code:h.invalid_string,...b.errToObj(s)})}_addCheck(e){return new ie({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...b.errToObj(e)})}url(e){return this._addCheck({kind:"url",...b.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...b.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...b.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...b.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...b.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...b.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...b.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...b.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...b.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...b.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...b.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...b.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==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,offset:(e==null?void 0:e.offset)??!1,local:(e==null?void 0:e.local)??!1,...b.errToObj(e==null?void 0: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==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,...b.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...b.errToObj(e)})}regex(e,n){return this._addCheck({kind:"regex",regex:e,...b.errToObj(n)})}includes(e,n){return this._addCheck({kind:"includes",value:e,position:n==null?void 0:n.position,...b.errToObj(n==null?void 0:n.message)})}startsWith(e,n){return this._addCheck({kind:"startsWith",value:e,...b.errToObj(n)})}endsWith(e,n){return this._addCheck({kind:"endsWith",value:e,...b.errToObj(n)})}min(e,n){return this._addCheck({kind:"min",value:e,...b.errToObj(n)})}max(e,n){return this._addCheck({kind:"max",value:e,...b.errToObj(n)})}length(e,n){return this._addCheck({kind:"length",value:e,...b.errToObj(n)})}nonempty(e){return this.min(1,b.errToObj(e))}trim(){return new ie({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new ie({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new ie({...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}}ie.create=t=>new ie({checks:[],typeName:w.ZodString,coerce:(t==null?void 0:t.coerce)??!1,...C(t)});function As(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(".","")),o=Number.parseInt(e.toFixed(r).replace(".",""));return a%o/10**r}class ve extends M{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)!==m.number){const a=this._getOrReturnCtx(e);return g(a,{code:h.invalid_type,expected:m.number,received:a.parsedType}),x}let s;const r=new V;for(const a of this._def.checks)a.kind==="int"?S.isInteger(e.data)||(s=this._getOrReturnCtx(e,s),g(s,{code:h.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),g(s,{code:h.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),g(s,{code:h.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),r.dirty()):a.kind==="multipleOf"?As(e.data,a.value)!==0&&(s=this._getOrReturnCtx(e,s),g(s,{code:h.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):a.kind==="finite"?Number.isFinite(e.data)||(s=this._getOrReturnCtx(e,s),g(s,{code:h.not_finite,message:a.message}),r.dirty()):S.assertNever(a);return{status:r.value,value:e.data}}gte(e,n){return this.setLimit("min",e,!0,b.toString(n))}gt(e,n){return this.setLimit("min",e,!1,b.toString(n))}lte(e,n){return this.setLimit("max",e,!0,b.toString(n))}lt(e,n){return this.setLimit("max",e,!1,b.toString(n))}setLimit(e,n,s,r){return new ve({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:s,message:b.toString(r)}]})}_addCheck(e){return new ve({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:b.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:b.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:b.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:b.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:b.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:b.toString(n)})}finite(e){return this._addCheck({kind:"finite",message:b.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:b.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:b.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"&&S.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)}}ve.create=t=>new ve({checks:[],typeName:w.ZodNumber,coerce:(t==null?void 0:t.coerce)||!1,...C(t)});class Te extends M{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)!==m.bigint)return this._getInvalidInput(e);let s;const r=new V;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),g(s,{code:h.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),g(s,{code:h.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),g(s,{code:h.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):S.assertNever(a);return{status:r.value,value:e.data}}_getInvalidInput(e){const n=this._getOrReturnCtx(e);return g(n,{code:h.invalid_type,expected:m.bigint,received:n.parsedType}),x}gte(e,n){return this.setLimit("min",e,!0,b.toString(n))}gt(e,n){return this.setLimit("min",e,!1,b.toString(n))}lte(e,n){return this.setLimit("max",e,!0,b.toString(n))}lt(e,n){return this.setLimit("max",e,!1,b.toString(n))}setLimit(e,n,s,r){return new Te({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:s,message:b.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:b.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:b.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:b.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:b.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:b.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:w.ZodBigInt,coerce:(t==null?void 0:t.coerce)??!1,...C(t)});class it extends M{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==m.boolean){const s=this._getOrReturnCtx(e);return g(s,{code:h.invalid_type,expected:m.boolean,received:s.parsedType}),x}return Q(e.data)}}it.create=t=>new it({typeName:w.ZodBoolean,coerce:(t==null?void 0:t.coerce)||!1,...C(t)});class We extends M{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==m.date){const a=this._getOrReturnCtx(e);return g(a,{code:h.invalid_type,expected:m.date,received:a.parsedType}),x}if(Number.isNaN(e.data.getTime())){const a=this._getOrReturnCtx(e);return g(a,{code:h.invalid_date}),x}const s=new V;let r;for(const a of this._def.checks)a.kind==="min"?e.data.getTime()<a.value&&(r=this._getOrReturnCtx(e,r),g(r,{code:h.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),g(r,{code:h.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),s.dirty()):S.assertNever(a);return{status:s.value,value:new Date(e.data.getTime())}}_addCheck(e){return new We({...this._def,checks:[...this._def.checks,e]})}min(e,n){return this._addCheck({kind:"min",value:e.getTime(),message:b.toString(n)})}max(e,n){return this._addCheck({kind:"max",value:e.getTime(),message:b.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}}We.create=t=>new We({checks:[],coerce:(t==null?void 0:t.coerce)||!1,typeName:w.ZodDate,...C(t)});class Zt extends M{_parse(e){if(this._getType(e)!==m.symbol){const s=this._getOrReturnCtx(e);return g(s,{code:h.invalid_type,expected:m.symbol,received:s.parsedType}),x}return Q(e.data)}}Zt.create=t=>new Zt({typeName:w.ZodSymbol,...C(t)});class Gt extends M{_parse(e){if(this._getType(e)!==m.undefined){const s=this._getOrReturnCtx(e);return g(s,{code:h.invalid_type,expected:m.undefined,received:s.parsedType}),x}return Q(e.data)}}Gt.create=t=>new Gt({typeName:w.ZodUndefined,...C(t)});class Ut extends M{_parse(e){if(this._getType(e)!==m.null){const s=this._getOrReturnCtx(e);return g(s,{code:h.invalid_type,expected:m.null,received:s.parsedType}),x}return Q(e.data)}}Ut.create=t=>new Ut({typeName:w.ZodNull,...C(t)});class Oe extends M{constructor(){super(...arguments),this._any=!0}_parse(e){return Q(e.data)}}Oe.create=t=>new Oe({typeName:w.ZodAny,...C(t)});class Wt extends M{constructor(){super(...arguments),this._unknown=!0}_parse(e){return Q(e.data)}}Wt.create=t=>new Wt({typeName:w.ZodUnknown,...C(t)});class de extends M{_parse(e){const n=this._getOrReturnCtx(e);return g(n,{code:h.invalid_type,expected:m.never,received:n.parsedType}),x}}de.create=t=>new de({typeName:w.ZodNever,...C(t)});class qt extends M{_parse(e){if(this._getType(e)!==m.undefined){const s=this._getOrReturnCtx(e);return g(s,{code:h.invalid_type,expected:m.void,received:s.parsedType}),x}return Q(e.data)}}qt.create=t=>new qt({typeName:w.ZodVoid,...C(t)});class re extends M{_parse(e){const{ctx:n,status:s}=this._processInputParams(e),r=this._def;if(n.parsedType!==m.array)return g(n,{code:h.invalid_type,expected:m.array,received:n.parsedType}),x;if(r.exactLength!==null){const o=n.data.length>r.exactLength.value,i=n.data.length<r.exactLength.value;(o||i)&&(g(n,{code:o?h.too_big:h.too_small,minimum:i?r.exactLength.value:void 0,maximum:o?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&&(g(n,{code:h.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&&(g(n,{code:h.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((o,i)=>r.type._parseAsync(new se(n,o,n.path,i)))).then(o=>V.mergeArray(s,o));const a=[...n.data].map((o,i)=>r.type._parseSync(new se(n,o,n.path,i)));return V.mergeArray(s,a)}get element(){return this._def.type}min(e,n){return new re({...this._def,minLength:{value:e,message:b.toString(n)}})}max(e,n){return new re({...this._def,maxLength:{value:e,message:b.toString(n)}})}length(e,n){return new re({...this._def,exactLength:{value:e,message:b.toString(n)}})}nonempty(e){return this.min(1,e)}}re.create=(t,e)=>new re({type:t,minLength:null,maxLength:null,exactLength:null,typeName:w.ZodArray,...C(e)});function _e(t){if(t instanceof D){const e={};for(const n in t.shape){const s=t.shape[n];e[n]=fe.create(_e(s))}return new D({...t._def,shape:()=>e})}else return t instanceof re?new re({...t._def,type:_e(t.element)}):t instanceof fe?fe.create(_e(t.unwrap())):t instanceof xe?xe.create(_e(t.unwrap())):t instanceof ge?ge.create(t.items.map(e=>_e(e))):t}class D extends M{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=S.objectKeys(e);return this._cached={shape:e,keys:n},this._cached}_parse(e){if(this._getType(e)!==m.object){const u=this._getOrReturnCtx(e);return g(u,{code:h.invalid_type,expected:m.object,received:u.parsedType}),x}const{status:s,ctx:r}=this._processInputParams(e),{shape:a,keys:o}=this._getCached(),i=[];if(!(this._def.catchall instanceof de&&this._def.unknownKeys==="strip"))for(const u in r.data)o.includes(u)||i.push(u);const c=[];for(const u of o){const v=a[u],j=r.data[u];c.push({key:{status:"valid",value:u},value:v._parse(new se(r,j,r.path,u)),alwaysSet:u in r.data})}if(this._def.catchall instanceof de){const u=this._def.unknownKeys;if(u==="passthrough")for(const v of i)c.push({key:{status:"valid",value:v},value:{status:"valid",value:r.data[v]}});else if(u==="strict")i.length>0&&(g(r,{code:h.unrecognized_keys,keys:i}),s.dirty());else if(u!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const u=this._def.catchall;for(const v of i){const j=r.data[v];c.push({key:{status:"valid",value:v},value:u._parse(new se(r,j,r.path,v)),alwaysSet:v in r.data})}}return r.common.async?Promise.resolve().then(async()=>{const u=[];for(const v of c){const j=await v.key,$=await v.value;u.push({key:j,value:$,alwaysSet:v.alwaysSet})}return u}).then(u=>V.mergeObjectSync(s,u)):V.mergeObjectSync(s,c)}get shape(){return this._def.shape()}strict(e){return b.errToObj,new D({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(n,s)=>{var a,o;const r=((o=(a=this._def).errorMap)==null?void 0:o.call(a,n,s).message)??s.defaultError;return n.code==="unrecognized_keys"?{message:b.errToObj(e).message??r}:{message:r}}}:{}})}strip(){return new D({...this._def,unknownKeys:"strip"})}passthrough(){return new D({...this._def,unknownKeys:"passthrough"})}extend(e){return new D({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new D({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:w.ZodObject})}setKey(e,n){return this.augment({[e]:n})}catchall(e){return new D({...this._def,catchall:e})}pick(e){const n={};for(const s of S.objectKeys(e))e[s]&&this.shape[s]&&(n[s]=this.shape[s]);return new D({...this._def,shape:()=>n})}omit(e){const n={};for(const s of S.objectKeys(this.shape))e[s]||(n[s]=this.shape[s]);return new D({...this._def,shape:()=>n})}deepPartial(){return _e(this)}partial(e){const n={};for(const s of S.objectKeys(this.shape)){const r=this.shape[s];e&&!e[s]?n[s]=r:n[s]=r.optional()}return new D({...this._def,shape:()=>n})}required(e){const n={};for(const s of S.objectKeys(this.shape))if(e&&!e[s])n[s]=this.shape[s];else{let a=this.shape[s];for(;a instanceof fe;)a=a._def.innerType;n[s]=a}return new D({...this._def,shape:()=>n})}keyof(){return Ft(S.objectKeys(this.shape))}}D.create=(t,e)=>new D({shape:()=>t,unknownKeys:"strip",catchall:de.create(),typeName:w.ZodObject,...C(e)}),D.strictCreate=(t,e)=>new D({shape:()=>t,unknownKeys:"strict",catchall:de.create(),typeName:w.ZodObject,...C(e)}),D.lazycreate=(t,e)=>new D({shape:t,unknownKeys:"strip",catchall:de.create(),typeName:w.ZodObject,...C(e)});class qe extends M{_parse(e){const{ctx:n}=this._processInputParams(e),s=this._def.options;function r(a){for(const i of a)if(i.result.status==="valid")return i.result;for(const i of a)if(i.result.status==="dirty")return n.common.issues.push(...i.ctx.common.issues),i.result;const o=a.map(i=>new oe(i.ctx.common.issues));return g(n,{code:h.invalid_union,unionErrors:o}),x}if(n.common.async)return Promise.all(s.map(async a=>{const o={...n,common:{...n.common,issues:[]},parent:null};return{result:await a._parseAsync({data:n.data,path:n.path,parent:o}),ctx:o}})).then(r);{let a;const o=[];for(const c of s){const u={...n,common:{...n.common,issues:[]},parent:null},v=c._parseSync({data:n.data,path:n.path,parent:u});if(v.status==="valid")return v;v.status==="dirty"&&!a&&(a={result:v,ctx:u}),u.common.issues.length&&o.push(u.common.issues)}if(a)return n.common.issues.push(...a.ctx.common.issues),a.result;const i=o.map(c=>new oe(c));return g(n,{code:h.invalid_union,unionErrors:i}),x}}get options(){return this._def.options}}qe.create=(t,e)=>new qe({options:t,typeName:w.ZodUnion,...C(e)});function ct(t,e){const n=le(t),s=le(e);if(t===e)return{valid:!0,data:t};if(n===m.object&&s===m.object){const r=S.objectKeys(e),a=S.objectKeys(t).filter(i=>r.indexOf(i)!==-1),o={...t,...e};for(const i of a){const c=ct(t[i],e[i]);if(!c.valid)return{valid:!1};o[i]=c.data}return{valid:!0,data:o}}else if(n===m.array&&s===m.array){if(t.length!==e.length)return{valid:!1};const r=[];for(let a=0;a<t.length;a++){const o=t[a],i=e[a],c=ct(o,i);if(!c.valid)return{valid:!1};r.push(c.data)}return{valid:!0,data:r}}else return n===m.date&&s===m.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}class Ve extends M{_parse(e){const{status:n,ctx:s}=this._processInputParams(e),r=(a,o)=>{if(Pt(a)||Pt(o))return x;const i=ct(a.value,o.value);return i.valid?(($t(a)||$t(o))&&n.dirty(),{status:n.value,value:i.data}):(g(s,{code:h.invalid_intersection_types}),x)};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,o])=>r(a,o)):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}))}}Ve.create=(t,e,n)=>new Ve({left:t,right:e,typeName:w.ZodIntersection,...C(n)});class ge extends M{_parse(e){const{status:n,ctx:s}=this._processInputParams(e);if(s.parsedType!==m.array)return g(s,{code:h.invalid_type,expected:m.array,received:s.parsedType}),x;if(s.data.length<this._def.items.length)return g(s,{code:h.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),x;!this._def.rest&&s.data.length>this._def.items.length&&(g(s,{code:h.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const a=[...s.data].map((o,i)=>{const c=this._def.items[i]||this._def.rest;return c?c._parse(new se(s,o,s.path,i)):null}).filter(o=>!!o);return s.common.async?Promise.all(a).then(o=>V.mergeArray(n,o)):V.mergeArray(n,a)}get items(){return this._def.items}rest(e){return new ge({...this._def,rest:e})}}ge.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new ge({items:t,typeName:w.ZodTuple,rest:null,...C(e)})};class ze extends M{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!==m.object)return g(s,{code:h.invalid_type,expected:m.object,received:s.parsedType}),x;const r=[],a=this._def.keyType,o=this._def.valueType;for(const i in s.data)r.push({key:a._parse(new se(s,i,s.path,i)),value:o._parse(new se(s,s.data[i],s.path,i)),alwaysSet:i in s.data});return s.common.async?V.mergeObjectAsync(n,r):V.mergeObjectSync(n,r)}get element(){return this._def.valueType}static create(e,n,s){return n instanceof M?new ze({keyType:e,valueType:n,typeName:w.ZodRecord,...C(s)}):new ze({keyType:ie.create(),valueType:e,typeName:w.ZodRecord,...C(n)})}}class Vt extends M{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!==m.map)return g(s,{code:h.invalid_type,expected:m.map,received:s.parsedType}),x;const r=this._def.keyType,a=this._def.valueType,o=[...s.data.entries()].map(([i,c],u)=>({key:r._parse(new se(s,i,s.path,[u,"key"])),value:a._parse(new se(s,c,s.path,[u,"value"]))}));if(s.common.async){const i=new Map;return Promise.resolve().then(async()=>{for(const c of o){const u=await c.key,v=await c.value;if(u.status==="aborted"||v.status==="aborted")return x;(u.status==="dirty"||v.status==="dirty")&&n.dirty(),i.set(u.value,v.value)}return{status:n.value,value:i}})}else{const i=new Map;for(const c of o){const u=c.key,v=c.value;if(u.status==="aborted"||v.status==="aborted")return x;(u.status==="dirty"||v.status==="dirty")&&n.dirty(),i.set(u.value,v.value)}return{status:n.value,value:i}}}}Vt.create=(t,e,n)=>new Vt({valueType:e,keyType:t,typeName:w.ZodMap,...C(n)});class Me extends M{_parse(e){const{status:n,ctx:s}=this._processInputParams(e);if(s.parsedType!==m.set)return g(s,{code:h.invalid_type,expected:m.set,received:s.parsedType}),x;const r=this._def;r.minSize!==null&&s.data.size<r.minSize.value&&(g(s,{code:h.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&&(g(s,{code:h.too_big,maximum:r.maxSize.value,type:"set",inclusive:!0,exact:!1,message:r.maxSize.message}),n.dirty());const a=this._def.valueType;function o(c){const u=new Set;for(const v of c){if(v.status==="aborted")return x;v.status==="dirty"&&n.dirty(),u.add(v.value)}return{status:n.value,value:u}}const i=[...s.data.values()].map((c,u)=>a._parse(new se(s,c,s.path,u)));return s.common.async?Promise.all(i).then(c=>o(c)):o(i)}min(e,n){return new Me({...this._def,minSize:{value:e,message:b.toString(n)}})}max(e,n){return new Me({...this._def,maxSize:{value:e,message:b.toString(n)}})}size(e,n){return this.min(e,n).max(e,n)}nonempty(e){return this.min(1,e)}}Me.create=(t,e)=>new Me({valueType:t,minSize:null,maxSize:null,typeName:w.ZodSet,...C(e)});class zt extends M{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})}}zt.create=(t,e)=>new zt({getter:t,typeName:w.ZodLazy,...C(e)});class ut extends M{_parse(e){if(e.data!==this._def.value){const n=this._getOrReturnCtx(e);return g(n,{received:n.data,code:h.invalid_literal,expected:this._def.value}),x}return{status:"valid",value:e.data}}get value(){return this._def.value}}ut.create=(t,e)=>new ut({value:t,typeName:w.ZodLiteral,...C(e)});function Ft(t,e){return new ke({values:t,typeName:w.ZodEnum,...C(e)})}class ke extends M{_parse(e){if(typeof e.data!="string"){const n=this._getOrReturnCtx(e),s=this._def.values;return g(n,{expected:S.joinValues(s),received:n.parsedType,code:h.invalid_type}),x}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 g(n,{received:n.data,code:h.invalid_enum_value,options:s}),x}return Q(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 ke.create(e,{...this._def,...n})}exclude(e,n=this._def){return ke.create(this.options.filter(s=>!e.includes(s)),{...this._def,...n})}}ke.create=Ft;class Bt extends M{_parse(e){const n=S.getValidEnumValues(this._def.values),s=this._getOrReturnCtx(e);if(s.parsedType!==m.string&&s.parsedType!==m.number){const r=S.objectValues(n);return g(s,{expected:S.joinValues(r),received:s.parsedType,code:h.invalid_type}),x}if(this._cache||(this._cache=new Set(S.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){const r=S.objectValues(n);return g(s,{received:s.data,code:h.invalid_enum_value,options:r}),x}return Q(e.data)}get enum(){return this._def.values}}Bt.create=(t,e)=>new Bt({values:t,typeName:w.ZodNativeEnum,...C(e)});class Fe extends M{unwrap(){return this._def.type}_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==m.promise&&n.common.async===!1)return g(n,{code:h.invalid_type,expected:m.promise,received:n.parsedType}),x;const s=n.parsedType===m.promise?n.data:Promise.resolve(n.data);return Q(s.then(r=>this._def.type.parseAsync(r,{path:n.path,errorMap:n.common.contextualErrorMap})))}}Fe.create=(t,e)=>new Fe({type:t,typeName:w.ZodPromise,...C(e)});class we extends M{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===w.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:o=>{g(s,o),o.fatal?n.abort():n.dirty()},get path(){return s.path}};if(a.addIssue=a.addIssue.bind(a),r.type==="preprocess"){const o=r.transform(s.data,a);if(s.common.async)return Promise.resolve(o).then(async i=>{if(n.value==="aborted")return x;const c=await this._def.schema._parseAsync({data:i,path:s.path,parent:s});return c.status==="aborted"?x:c.status==="dirty"||n.value==="dirty"?Ne(c.value):c});{if(n.value==="aborted")return x;const i=this._def.schema._parseSync({data:o,path:s.path,parent:s});return i.status==="aborted"?x:i.status==="dirty"||n.value==="dirty"?Ne(i.value):i}}if(r.type==="refinement"){const o=i=>{const c=r.refinement(i,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 i};if(s.common.async===!1){const i=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});return i.status==="aborted"?x:(i.status==="dirty"&&n.dirty(),o(i.value),{status:n.value,value:i.value})}else return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then(i=>i.status==="aborted"?x:(i.status==="dirty"&&n.dirty(),o(i.value).then(()=>({status:n.value,value:i.value}))))}if(r.type==="transform")if(s.common.async===!1){const o=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});if(!be(o))return x;const i=r.transform(o.value,a);if(i instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:i}}else return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then(o=>be(o)?Promise.resolve(r.transform(o.value,a)).then(i=>({status:n.value,value:i})):x);S.assertNever(r)}}we.create=(t,e,n)=>new we({schema:t,typeName:w.ZodEffects,effect:e,...C(n)}),we.createWithPreprocess=(t,e,n)=>new we({schema:e,effect:{type:"preprocess",transform:t},typeName:w.ZodEffects,...C(n)});class fe extends M{_parse(e){return this._getType(e)===m.undefined?Q(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}fe.create=(t,e)=>new fe({innerType:t,typeName:w.ZodOptional,...C(e)});class xe extends M{_parse(e){return this._getType(e)===m.null?Q(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}xe.create=(t,e)=>new xe({innerType:t,typeName:w.ZodNullable,...C(e)});class lt extends M{_parse(e){const{ctx:n}=this._processInputParams(e);let s=n.data;return n.parsedType===m.undefined&&(s=this._def.defaultValue()),this._def.innerType._parse({data:s,path:n.path,parent:n})}removeDefault(){return this._def.innerType}}lt.create=(t,e)=>new lt({innerType:t,typeName:w.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...C(e)});class dt extends M{_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 Ue(r)?r.then(a=>({status:"valid",value:a.status==="valid"?a.value:this._def.catchValue({get error(){return new oe(s.common.issues)},input:s.data})})):{status:"valid",value:r.status==="valid"?r.value:this._def.catchValue({get error(){return new oe(s.common.issues)},input:s.data})}}removeCatch(){return this._def.innerType}}dt.create=(t,e)=>new dt({innerType:t,typeName:w.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...C(e)});class Ht extends M{_parse(e){if(this._getType(e)!==m.nan){const s=this._getOrReturnCtx(e);return g(s,{code:h.invalid_type,expected:m.nan,received:s.parsedType}),x}return{status:"valid",value:e.data}}}Ht.create=t=>new Ht({typeName:w.ZodNaN,...C(t)});class js extends M{_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 ft extends M{_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"?x:a.status==="dirty"?(n.dirty(),Ne(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"?x: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 ft({in:e,out:n,typeName:w.ZodPipeline})}}class ht extends M{_parse(e){const n=this._def.innerType._parse(e),s=r=>(be(r)&&(r.value=Object.freeze(r.value)),r);return Ue(n)?n.then(r=>s(r)):s(n)}unwrap(){return this._def.innerType}}ht.create=(t,e)=>new ht({innerType:t,typeName:w.ZodReadonly,...C(e)});function Yt(t,e){const n=typeof t=="function"?t(e):typeof t=="string"?{message:t}:t;return typeof n=="string"?{message:n}:n}function Ps(t,e={},n){return t?Oe.create().superRefine((s,r)=>{const a=t(s);if(a instanceof Promise)return a.then(o=>{if(!o){const i=Yt(e,s),c=i.fatal??n??!0;r.addIssue({code:"custom",...i,fatal:c})}});if(!a){const o=Yt(e,s),i=o.fatal??n??!0;r.addIssue({code:"custom",...o,fatal:i})}}):Oe.create()}var w;(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"})(w||(w={}));const $s=(t,e={message:`Input not instance of ${t.name}`})=>Ps(n=>n instanceof t,e),Z=ie.create,J=ve.create,pt=it.create;Oe.create,de.create;const U=re.create,I=D.create,Kt=qe.create;Ve.create,ge.create;const Xt=ze.create,Ls=ut.create,Re=ke.create;Fe.create,fe.create,xe.create;const Is={network:{failures:"network.failure",latencies:"network.latency",aborts:"network.abort",corruptions:"network.corruption",cors:"network.cors"},ui:{assaults:"ui.assault"},websocket:{drops:"websocket.drop",delays:"websocket.delay",corruptions:"websocket.corrupt",closes:"websocket.close"},sse:{drops:"sse.drop",delays:"sse.delay",corruptions:"sse.corrupt",closes:"sse.close"}};function Ds(t){if(t.length===0)return"top-level";const e=t[0];if(e==="groups")return"group";if(e==="presets"||e==="customPresets")return"preset";if(typeof e=="string"){const n=Is[e];if(n&&typeof t[1]=="string"){const s=n[t[1]];if(s)return s}}return"top-level"}function Zs(t){let e="";for(const n of t)typeof n=="number"?e+=`[${n}]`:e+=e.length===0?n:`.${n}`;return e}function Qt(t,e=80){return t.length<=e?t:`${t.slice(0,e-1)}…`}function Gs(t){try{return t===void 0?"undefined":JSON.stringify(t)??String(t)}catch{return"<unserializable>"}}function Us(t){switch(t.code){case h.unrecognized_keys:return"unknown_field";case h.invalid_type:return t.received==="undefined"?"missing_field":"invalid_type";case h.too_small:return"value_too_small";case h.too_big:return"value_too_large";case h.invalid_enum_value:return"invalid_enum";case h.invalid_string:return"invalid_string";case h.invalid_union:case h.invalid_union_discriminator:return"invalid_type";case h.custom:{const e=t.message.toLowerCase();return e.includes("mutually exclusive")||e.includes("only one of")?"mutually_exclusive":e.includes("duplicate")?"duplicate":e.includes("regexp")||e.includes("flag")?"invalid_regex":"custom"}default:return"custom"}}function Ws(t){switch(t.code){case h.invalid_type:return t.expected;case h.too_small:return t.type==="number"?`>= ${t.minimum}`:t.type==="string"?`length >= ${t.minimum}`:t.type==="array"?`length >= ${t.minimum}`:`>= ${t.minimum}`;case h.too_big:return t.type==="number"?`<= ${t.maximum}`:t.type==="string"?`length <= ${t.maximum}`:t.type==="array"?`length <= ${t.maximum}`:`<= ${t.maximum}`;case h.invalid_enum_value:return t.options.map(e=>JSON.stringify(e)).join("|");case h.unrecognized_keys:return"no extra keys";default:return}}function qs(t){if(t.code===h.invalid_type)return t.received;if(t.code===h.invalid_enum_value)return Qt(Gs(t.received));if(t.code===h.unrecognized_keys)return Qt(t.keys.map(e=>JSON.stringify(e)).join(", "))}function Jt(t){return{path:Zs(t.path),code:Us(t),ruleType:Ds(t.path),message:t.message,expected:Ws(t),received:qs(t)}}function Vs(t){return[...t].sort((e,n)=>e.path<n.path?-1:e.path>n.path?1:e.code<n.code?-1:e.code>n.code?1:0)}function zs(t,e={}){const n=e.maxIssues??50,s=t.slice(0,n),r=Math.max(0,t.length-n),a=s.map(o=>{let i=`[${o.ruleType}] ${o.path||"<root>"} (${o.code}): ${o.message}`;return o.expected!==void 0&&(i+=`, expected ${o.expected}`),o.received!==void 0&&(i+=`, received ${o.received}`),i});return r>0&&a.push(`... and ${r} more`),`Invalid ChaosConfig:
|
|
2
|
+
${a.map(o=>` - ${o}`).join(`
|
|
3
|
+
`)}`}class ye extends Error{constructor(n){const s=Fs(n)?n.map(a=>({path:"",code:"legacy",ruleType:"top-level",message:a})):n,r=Vs(s);super(zs(r,{maxIssues:50}));R(this,"issues");this.name="ChaosConfigError",this.issues=r}get messages(){return this.issues.map(n=>`${n.path||"<root>"}: ${n.message}`)}}function Fs(t){return t.length>0&&typeof t[0]=="string"}const Ae="default";class en{constructor(){R(this,"groups",new Map);R(this,"gatedEmitted",new Set)}ensure(e,n){const s=this.groups.get(e);if(s)return n!=null&&n.explicit&&(s.explicit=!0),(n==null?void 0:n.enabled)!==void 0&&(s.enabled=n.enabled),s;const r={name:e,enabled:(n==null?void 0:n.enabled)??!0,explicit:(n==null?void 0:n.explicit)??!1};return this.groups.set(e,r),r}setEnabled(e,n){this.ensure(e).enabled=n,this.gatedEmitted.clear()}isActive(e){return this.ensure(e??Ae).enabled}shouldEmitGated(e){return this.gatedEmitted.has(e)?!1:(this.gatedEmitted.add(e),!0)}has(e){return this.groups.has(e)}remove(e,n,s){if(e===Ae)return!1;if(!(s!=null&&s.force)&&n.has(e))throw new Error(`[chaos-maker] Cannot remove group '${e}': still referenced by one or more rules. Pass { force: true } to override.`);const r=this.groups.delete(e);return r&&this.gatedEmitted.delete(e),r}list(){return[...this.groups.values()].map(e=>({...e}))}getSnapshot(){const e={};for(const n of this.groups.values())e[n.name]=n.enabled;return e}}function je(t){if(t===null||typeof t!="object")return t;if(t instanceof RegExp)return new RegExp(t.source,t.flags);if(Array.isArray(t))return t.map(n=>je(n));const e={};for(const[n,s]of Object.entries(t))e[n]=je(s);return e}function z(t,e){return e()<t}function te(t,e){const n=(e.get(t)??0)+1;return e.set(t,n),n}function ne(t,e){return t.onNth!==void 0?e===t.onNth:t.everyNth!==void 0?e%t.everyNth===0:t.afterN!==void 0?e>t.afterN:!0}function me(t,e){return e==="*"?!0:t.includes(e)}function gt(t,e){switch(e){case"truncate":return t.slice(0,Math.max(0,Math.floor(t.length/2)));case"malformed-json":return`${t}"}`;case"empty":return"";case"wrong-type":return"<html><body>Unexpected HTML</body></html>"}}function F(t,e,n,s){if(!e||e.isActive(t.group))return!0;const r=t.group??Ae;return e.shouldEmitGated(r)&&n&&n.emit({type:"rule-group:gated",timestamp:Date.now(),applied:!1,detail:{...s,groupName:r}}),n==null||n.debug("rule-skip-group",{...s,groupName:r},t),!1}function tn(t,e){var s,r,a,o,i,c,u,v,j,$,Y,ee,q,p;const n=l=>{if(l)for(const f of l)e(f)};n((s=t.network)==null?void 0:s.failures),n((r=t.network)==null?void 0:r.latencies),n((a=t.network)==null?void 0:a.aborts),n((o=t.network)==null?void 0:o.corruptions),n((i=t.network)==null?void 0:i.cors),n((c=t.ui)==null?void 0:c.assaults),n((u=t.websocket)==null?void 0:u.drops),n((v=t.websocket)==null?void 0:v.delays),n((j=t.websocket)==null?void 0:j.corruptions),n(($=t.websocket)==null?void 0:$.closes),n((Y=t.sse)==null?void 0:Y.drops),n((ee=t.sse)==null?void 0:ee.delays),n((q=t.sse)==null?void 0:q.corruptions),n((p=t.sse)==null?void 0:p.closes)}const ae="*",Be={network:{latencies:[{urlPattern:ae,delayMs:2e3,probability:1}]}},He={network:{aborts:[{urlPattern:ae,probability:.05}],latencies:[{urlPattern:ae,delayMs:3e3,probability:.1}]}},Ye={network:{cors:[{urlPattern:ae,probability:1}]}},Ke={network:{failures:[{urlPattern:"/api/",statusCode:500,probability:.1}],latencies:[{urlPattern:"/api/",delayMs:1e3,probability:.2}]}},yt={ui:{assaults:[{selector:"button",action:"disable",probability:.2},{selector:"a",action:"hide",probability:.1}]}},mt={websocket:{drops:[{urlPattern:ae,direction:"both",probability:.1}],delays:[{urlPattern:ae,direction:"inbound",delayMs:500,probability:1}],corruptions:[{urlPattern:ae,direction:"inbound",strategy:"truncate",probability:.05}]}},bt={sse:{drops:[{urlPattern:ae,probability:.05}],delays:[{urlPattern:ae,delayMs:200,probability:1}],closes:[{urlPattern:ae,probability:.02,afterMs:2e3}]}};function nn(t){if(t&&typeof t=="object"&&!Object.isFrozen(t)){Object.freeze(t);for(const e of Object.values(t))nn(e)}return t}[Be,He,Ye,Ke,yt,mt,bt].forEach(nn);const sn=Object.freeze([{name:"unstableApi",config:Ke},{name:"slowNetwork",config:Be},{name:"offlineMode",config:Ye},{name:"flakyConnection",config:He},{name:"degradedUi",config:yt},{name:"unreliableWebSocket",config:mt},{name:"unreliableEventStream",config:bt},{name:"slow-api",config:Be},{name:"flaky-api",config:He},{name:"offline-mode",config:Ye},{name:"high-latency",config:Ke}].map(t=>Object.freeze(t)));function vt(t){const e=t.trim();if(!e)throw new Error("[chaos-maker] preset name cannot be empty");return e}class rn{constructor(e=sn){R(this,"map",new Map);for(const n of e)this.register(n)}register(e){const n=vt(e.name);if(this.map.has(n))throw new Error(`[chaos-maker] preset '${n}' already registered`);this.map.set(n,e.config)}registerAll(e){if(e)for(const[n,s]of Object.entries(e))this.register({name:n,config:s})}has(e){return this.map.has(vt(e))}get(e){const n=vt(e),s=this.map.get(n);if(!s)throw new Error(`[chaos-maker] preset '${n}' is not registered. Known: ${this.list().join(", ")}`);return s}list(){return[...this.map.keys()]}}function an(t,e){var n,s,r;for(const a of["network","ui","websocket","sse"]){const o=e[a];if(!o)continue;const i=t[a]??(t[a]={});for(const[c,u]of Object.entries(o)){if(!Array.isArray(u)){let v;try{const j=u===null?"null":((n=u==null?void 0:u.constructor)==null?void 0:n.name)??typeof u,$=((s=JSON.stringify(u))==null?void 0:s.slice(0,80))??"<unserializable>";v=`${j} ${$}`}catch{v=`${typeof u} <unserializable>`}throw new Error(`[chaos-maker] internal: preset slice category '${a}.${c}' must be an array (got ${v}). Update appendSlice when adding non-array category fields.`)}(i[c]??(i[c]=[])).push(...u)}}(r=e.groups)!=null&&r.length&&(t.groups??(t.groups=[])).push(...e.groups)}function on(t,e){const n=new Set,s=new Set,r=[];for(const i of t.presets??[]){const c=i.trim();if(!c||n.has(c))continue;n.add(c);const u=e.get(c);s.has(u)||(s.add(u),r.push(u))}const a={};for(const i of r)an(a,je(i));const o=je(t);return delete o.presets,delete o.customPresets,o.seed!==void 0&&(a.seed=o.seed),o.debug!==void 0&&(a.debug=o.debug),an(a,o),a}const Bs=Object.freeze({unstableApi:Ke,slowNetwork:Be,offlineMode:Ye,flakyConnection:He,degradedUi:yt,unreliableWebSocket:mt,unreliableEventStream:bt}),cn=new Map;function Hs(t,e){if(cn.size===0)return;const n=t;for(const[s,r]of cn){if(n[s]===void 0)continue;const a={path:s,code:"deprecated",ruleType:"top-level",message:r.message};e&&e(a);try{console.warn(`[chaos-maker] deprecated: ${s} — ${r.message}`)}catch{}}}const Pe=["urlPattern","methods","graphqlOperation","probability","onNth","everyNth","afterN","group"],Ys=new Set([...Pe,"statusCode","body","statusText","headers"]),Ks=new Set([...Pe,"delayMs"]),Xs=new Set([...Pe,"timeout"]),Qs=new Set([...Pe,"strategy"]),Js=new Set(Pe),er=new Set(["selector","action","probability","group"]),tr=new Set(["urlPattern","direction","probability","onNth","everyNth","afterN","group"]),nr=new Set(["urlPattern","direction","delayMs","probability","onNth","everyNth","afterN","group"]),sr=new Set(["urlPattern","direction","strategy","probability","onNth","everyNth","afterN","group"]),rr=new Set(["urlPattern","code","reason","afterMs","probability","onNth","everyNth","afterN","group"]),ar=new Set(["urlPattern","eventType","probability","onNth","everyNth","afterN","group"]),or=new Set(["urlPattern","eventType","delayMs","probability","onNth","everyNth","afterN","group"]),ir=new Set(["urlPattern","eventType","strategy","probability","onNth","everyNth","afterN","group"]),cr=new Set(["urlPattern","afterMs","probability","onNth","everyNth","afterN","group"]),un=new Set(["name","enabled"]),ln={failures:Ys,latencies:Ks,aborts:Xs,corruptions:Qs,cors:Js},dn={assaults:er},fn={drops:tr,delays:nr,corruptions:sr,closes:rr},hn={drops:ar,delays:or,corruptions:ir,closes:cr},pn=new Set(["network","ui","websocket","sse","groups","presets","customPresets","seed","debug","schemaVersion"]),Xe={network:new Set(Object.keys(ln)),ui:new Set(Object.keys(dn)),websocket:new Set(Object.keys(fn)),sse:new Set(Object.keys(hn))},he={network:ln,ui:dn,websocket:fn,sse:hn};function gn(t,e){const n={};if(!t||typeof t!="object")return n;const s=t;for(const r of Object.keys(s))e.has(r)&&(n[r]=s[r]);return n}function ur(t,e){return Array.isArray(t)?t.map(n=>gn(n,e)):[]}function yn(t,e,n){const s={};if(!t||typeof t!="object")return s;const r=t;for(const a of Object.keys(r)){if(!n.has(a))continue;const o=e[a];o&&(s[a]=ur(r[a],o))}return s}function mn(t){return Array.isArray(t)?t.map(e=>gn(e,un)):[]}function lr(t){const e={};if(!t||typeof t!="object")return e;const n=t;for(const s of Object.keys(he))n[s]!==void 0&&(e[s]=yn(n[s],he[s],Xe[s]));return n.groups!==void 0&&(e.groups=mn(n.groups)),e}function dr(t){const e={};if(!t||typeof t!="object")return e;const n=t;for(const s of Object.keys(n))if(pn.has(s))if(s in he)e[s]=yn(n[s],he[s],Xe[s]);else if(s==="groups")e[s]=mn(n[s]);else if(s==="customPresets"){const r=n[s];if(r&&typeof r=="object"){const a={};for(const[o,i]of Object.entries(r))a[o]=lr(i);e[s]=a}}else e[s]=n[s];return e}function fr(t){const e=[];return hr(t,"",e),e.sort()}function hr(t,e,n){if(!(!t||typeof t!="object")){const s=t;for(const r of Object.keys(s)){if(!pn.has(r)){n.push(r);continue}r in he?bn(s[r],r,he[r],Xe[r],n):r==="groups"?vn(s[r],"groups",n):r==="customPresets"&&pr(s[r],n)}}}function bn(t,e,n,s,r){if(!t||typeof t!="object")return;const a=t;for(const o of Object.keys(a)){const i=`${e}.${o}`;if(!s.has(o)){r.push(i);continue}const c=n[o];c&&Array.isArray(a[o])&&a[o].forEach((u,v)=>{if(!u||typeof u!="object")return;const j=u;for(const $ of Object.keys(j))c.has($)||r.push(`${i}[${v}].${$}`)})}}function vn(t,e,n){Array.isArray(t)&&t.forEach((s,r)=>{if(!s||typeof s!="object")return;const a=s;for(const o of Object.keys(a))un.has(o)||n.push(`${e}[${r}].${o}`)})}function pr(t,e){if(!(!t||typeof t!="object"))for(const[n,s]of Object.entries(t)){if(!s||typeof s!="object")continue;const r=s;for(const a of Object.keys(r)){if(a==="groups"){vn(r[a],`customPresets.${n}.groups`,e);continue}if(!(a in he)){e.push(`customPresets.${n}.${a}`);continue}bn(r[a],`customPresets.${n}.${a}`,he[a],Xe[a],e)}}}function L(t,e){return e==="strict"?t.strict():t.passthrough()}const B=J().min(0,"Probability must be >= 0").max(1,"Probability must be <= 1"),_n=J().int().min(1),K={onNth:_n.optional(),everyNth:_n.optional(),afterN:J().int().min(0).optional()},H={group:Z().trim().min(1,"group must not be empty").optional()},X=[t=>[t.onNth,t.everyNth,t.afterN].filter(e=>e!==void 0).length<=1,{message:"Only one of onNth, everyNth, or afterN may be set on a single rule"}],gr=Kt([Z().min(1,"graphqlOperation must not be empty"),$s(RegExp).refine(t=>!t.global&&!t.sticky,{message:"graphqlOperation RegExp must not use global (g) or sticky (y) flags due to lastIndex mutation"})]),$e={urlPattern:Z().min(1,"urlPattern must not be empty"),methods:U(Z()).optional(),graphqlOperation:gr.optional()},kn=t=>L(I({...$e,statusCode:J().int().min(100).max(599),probability:B,body:Z().optional(),statusText:Z().optional(),headers:Xt(Z()).optional(),...K,...H}),t).refine(...X),wn=t=>L(I({...$e,delayMs:J().min(0,"delayMs must be >= 0"),probability:B,...K,...H}),t).refine(...X),xn=t=>L(I({...$e,probability:B,timeout:J().min(0,"timeout must be >= 0").optional(),...K,...H}),t).refine(...X),Sn=t=>L(I({...$e,probability:B,strategy:Re(["truncate","malformed-json","empty","wrong-type"]),...K,...H}),t).refine(...X),Cn=t=>L(I({...$e,probability:B,...K,...H}),t).refine(...X),yr=t=>L(I({failures:U(kn(t)).optional(),latencies:U(wn(t)).optional(),aborts:U(xn(t)).optional(),corruptions:U(Sn(t)).optional(),cors:U(Cn(t)).optional()}),t),En=t=>L(I({selector:Z().min(1,"selector must not be empty"),action:Re(["disable","hide","remove"]),probability:B,...H}),t),mr=t=>L(I({assaults:U(En(t)).optional()}),t),_t=Re(["inbound","outbound","both"]),Nn=t=>L(I({urlPattern:Z().min(1,"urlPattern must not be empty"),direction:_t,probability:B,...K,...H}),t).refine(...X),Tn=t=>L(I({urlPattern:Z().min(1,"urlPattern must not be empty"),direction:_t,delayMs:J().min(0,"delayMs must be >= 0"),probability:B,...K,...H}),t).refine(...X),On=t=>L(I({urlPattern:Z().min(1,"urlPattern must not be empty"),direction:_t,strategy:Re(["truncate","malformed-json","empty","wrong-type"]),probability:B,...K,...H}),t).refine(...X),br=J().int().refine(t=>t===1e3||t>=3e3&&t<=4999,{message:"code must be 1000 or in the range 3000-4999"}),vr=Z().refine(t=>new TextEncoder().encode(t).length<=123,{message:"reason must be <= 123 UTF-8 bytes"}),Mn=t=>L(I({urlPattern:Z().min(1,"urlPattern must not be empty"),code:br.optional(),reason:vr.optional(),afterMs:J().min(0,"afterMs must be >= 0").optional(),probability:B,...K,...H}),t).refine(...X),_r=t=>L(I({drops:U(Nn(t)).optional(),delays:U(Tn(t)).optional(),corruptions:U(On(t)).optional(),closes:U(Mn(t)).optional()}),t),kt=Z().min(1,"eventType must not be empty"),Rn=t=>L(I({urlPattern:Z().min(1,"urlPattern must not be empty"),eventType:kt.optional(),probability:B,...K,...H}),t).refine(...X),An=t=>L(I({urlPattern:Z().min(1,"urlPattern must not be empty"),eventType:kt.optional(),delayMs:J().min(0,"delayMs must be >= 0"),probability:B,...K,...H}),t).refine(...X),jn=t=>L(I({urlPattern:Z().min(1,"urlPattern must not be empty"),eventType:kt.optional(),strategy:Re(["truncate","malformed-json","empty","wrong-type"]),probability:B,...K,...H}),t).refine(...X),Pn=t=>L(I({urlPattern:Z().min(1,"urlPattern must not be empty"),afterMs:J().min(0,"afterMs must be >= 0").optional(),probability:B,...K,...H}),t).refine(...X),kr=t=>L(I({drops:U(Rn(t)).optional(),delays:U(An(t)).optional(),corruptions:U(jn(t)).optional(),closes:U(Pn(t)).optional()}),t),$n=t=>L(I({name:Z().trim().min(1,"group name must not be empty"),enabled:pt().optional()}),t),wr=t=>U($n(t)).superRefine((e,n)=>{const s=new Set;for(const[r,a]of e.entries()){const o=a.name.trim();if(s.has(o)){n.addIssue({code:h.custom,message:"duplicate group name after normalization",path:[r,"name"]});continue}s.add(o)}}),xr=t=>Kt([pt(),L(I({enabled:pt()}),t)]),wt=t=>L(I({network:yr(t).optional(),ui:mr(t).optional(),websocket:_r(t).optional(),sse:kr(t).optional(),groups:wr(t).optional()}),t),Ln=Z().trim().min(1,"preset name must not be empty"),Sr=U(Ln).transform(t=>{const e=new Set,n=[];for(const s of t){const r=s.trim();e.has(r)||(e.add(r),n.push(r))}return n}),In=t=>L(wt(t).extend({presets:Sr.optional(),customPresets:Xt(Ln,wt(t)).optional(),seed:J().int("Seed must be an integer").optional(),debug:xr(t).optional(),schemaVersion:Ls(1).optional()}),t),xt=In("strict"),Dn=In("passthrough");wt("strict"),kn("strict"),wn("strict"),xn("strict"),Sn("strict"),Cn("strict"),En("strict"),Nn("strict"),Tn("strict"),On("strict"),Mn("strict"),Rn("strict"),An("strict"),jn("strict"),Pn("strict"),$n("strict");const Cr={network:{failures:"network.failure",latencies:"network.latency",aborts:"network.abort",corruptions:"network.corruption",cors:"network.cors"},ui:{assaults:"ui.assault"},websocket:{drops:"websocket.drop",delays:"websocket.delay",corruptions:"websocket.corrupt",closes:"websocket.close"},sse:{drops:"sse.drop",delays:"sse.delay",corruptions:"sse.corrupt",closes:"sse.close"}},Zn=Symbol.for("chaos-maker.validated"),St=1;function Er(t,e){return!t||typeof t!="object"?!1:t[Zn]===e}function Nr(t,e){return Object.defineProperty(t,Zn,{value:e,enumerable:!1,writable:!1,configurable:!1}),t}function Gn(t){const e=xt.safeParse(t);if(!e.success)throw new ye(e.error.issues.map(Jt));return e.data}function Un(t,e={}){const n=e.unknownFields??"reject",r=(n==="reject"?xt:Dn).safeParse(t);if(!r.success)throw new ye(r.error.issues.map(Jt));let a=r.data;if(n==="warn"||n==="ignore"){if(n==="warn"){const i=fr(t);if(i.length>0)try{console.warn(`[chaos-maker] unknown config fields ignored: ${i.join(", ")}`)}catch{}}a=dr(a)}let o;try{const i=new rn;i.registerAll(a.customPresets),o=on(a,i)}catch(i){if(i instanceof ye)throw i;const c=i.message;let u="custom";throw c.includes("not registered")?u="unknown_preset":c.includes("already registered")&&(u="preset_collision"),new ye([{path:"presets",code:u,ruleType:"preset",message:c}])}return Gn(o)}function Tr(t,e){const n=[],s=(r,a,o)=>{const i=e[r];if(!i)return;let c;try{c=i(a,{ruleType:r,path:o})}catch(u){n.push({path:o,code:"custom",ruleType:r,message:`customValidator threw: ${u.message}`});return}Array.isArray(c)&&n.push(...c)};for(const[r,a]of Object.entries(Cr)){const o=t[r];if(o)for(const[i,c]of Object.entries(a)){if(!c)continue;const u=o[i];Array.isArray(u)&&u.forEach((v,j)=>{s(c,v,`${r}.${i}[${j}]`)})}}return Array.isArray(t.groups)&&t.groups.forEach((r,a)=>{s("group",r,`groups[${a}]`)}),e["top-level"]&&s("top-level",t,""),n}function Ct(t,e={}){if(typeof t=="object"&&t!==null){const r=t.schemaVersion;if(r!==void 0&&r!==1)throw new ye([{path:"schemaVersion",code:"unknown_schema_version",ruleType:"top-level",message:`unsupported schemaVersion: ${JSON.stringify(r)} (this build supports 1)`,expected:"1",received:JSON.stringify(r)}])}if(!e.unknownFields&&!e.onDeprecation&&!e.customValidators&&Er(t,St))return t;const s=Un(t,{unknownFields:e.unknownFields});if(Hs(s,e.onDeprecation),e.customValidators){const r=Tr(s,e.customValidators);if(r.length>0)throw new ye(r)}return Nr(s,St)}function Or(t){let e=t|0;return()=>{e=e+1831565813|0;let n=Math.imul(e^e>>>15,1|e);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}function Wn(){return Math.random()*4294967296>>>0}function qn(t){const e=t??Wn();return{random:Or(e),seed:e}}class Vn{constructor(e=2e3){R(this,"listeners",new Map);R(this,"log",[]);R(this,"logger");R(this,"ruleIds");this.maxLogEntries=e}on(e,n){this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(n)}off(e,n){var s;(s=this.listeners.get(e))==null||s.delete(n)}emit(e){this.log.push(e),this.log.length>this.maxLogEntries&&this.log.shift(),this.notify(this.listeners.get(e.type),e),this.notify(this.listeners.get("*"),e)}setLogger(e){this.logger=e}setRuleIds(e){this.ruleIds=e}debug(e,n,s){var i;if(!this.logger)return;const r=s?(i=this.ruleIds)==null?void 0:i.get(s):void 0,a=r?{...n,ruleType:r.ruleType,ruleId:r.ruleId}:n,o=this.logger.log(e,a);o&&this.emit(o)}getLog(){return[...this.log]}clearLog(){this.log=[]}notify(e,n){if(e)for(const s of e)try{s(n)}catch{}}}function Et(t){const e=t.replace(/#[^\r\n]*/g," "),n=/\b(?:query|mutation|subscription)\s+([A-Za-z_][A-Za-z0-9_]*)/.exec(e);return(n==null?void 0:n[1])??null}function Mr(t){try{return JSON.parse(t)}catch{return}}function zn(t){if(!t||typeof t!="object")return{isGraphQL:!1,operationName:null};if(Array.isArray(t))return t.length===0?{isGraphQL:!1,operationName:null}:zn(t[0]);const e=t,n=typeof e.query=="string",s=typeof e.operationName=="string";return!n&&!s?{isGraphQL:!1,operationName:null}:s&&e.operationName.length>0?{isGraphQL:!0,operationName:e.operationName}:n?{isGraphQL:!0,operationName:Et(e.query)}:{isGraphQL:!0,operationName:null}}function Rr(t){let e;try{e=new URL(t,"http://_chaos-maker.invalid")}catch{return{kind:"not-graphql"}}const n=e.searchParams.get("operationName"),s=e.searchParams.get("query");return n&&n.length>0?{kind:"extracted",operationName:n}:s&&s.length>0?{kind:"extracted",operationName:Et(s)}:{kind:"not-graphql"}}function Nt(t,e,n,s){const r=t.toUpperCase();if(r==="POST"){if(n!==null){const a=Mr(n);if(a===void 0)return{kind:"not-graphql"};const{isGraphQL:o,operationName:i}=zn(a);return o?{kind:"extracted",operationName:i}:{kind:"not-graphql"}}return s?{kind:"unparseable"}:{kind:"not-graphql"}}return r==="GET"?Rr(e):{kind:"not-graphql"}}function Fn(t,e){return e===null?!1:typeof t=="string"?t===e:((t.global||t.sticky)&&(t.lastIndex=0),t.test(e))}function Tt(t,e){return t?e.kind==="not-graphql"?{kind:"no-match"}:e.kind==="unparseable"?{kind:"unparseable"}:Fn(t,e.operationName)?{kind:"match",operationName:e.operationName}:{kind:"no-match"}:e.kind==="extracted"?{kind:"skip-no-constraint",operationName:e.operationName}:{kind:"skip-no-constraint",operationName:null}}function Qe(t){return typeof Request<"u"&&t instanceof Request}function Ar(t){return Qe(t)?t.url:t.toString()}function jr(t,e){return e!=null&&e.method?e.method.toUpperCase():Qe(t)?t.method.toUpperCase():"GET"}function Pr(t,e){if(e!=null&&e.signal)return e.signal;if(Qe(t))return t.signal}function $r(){if(typeof DOMException<"u")return new DOMException("The user aborted a request.","AbortError");const t=new Error("The user aborted a request.");return t.name="AbortError",t}function Lr(t,e){if(!e)return t;const n=new AbortController,s=i=>{o(),n.signal.aborted||n.abort(i.reason)},r=()=>s(t),a=()=>s(e),o=()=>{t.removeEventListener("abort",r),e.removeEventListener("abort",a)};return t.aborted?(s(t),n.signal):e.aborted?(s(e),n.signal):(t.addEventListener("abort",r,{once:!0}),e.addEventListener("abort",a,{once:!0}),n.signal)}function Ir(t,e){return e?{...t??{},signal:e}:t}async function Dr(t,e){const n=e==null?void 0:e.body;if(n!=null){if(typeof n=="string")return{text:n,unparseable:!1};if(typeof URLSearchParams<"u"&&n instanceof URLSearchParams)return{text:n.toString(),unparseable:!1};if(typeof Blob<"u"&&n instanceof Blob){if(!(n.type===""||/json|text|graphql/i.test(n.type)))return{text:null,unparseable:!0};try{return{text:await n.text(),unparseable:!1}}catch{return{text:null,unparseable:!0}}}return{text:null,unparseable:!0}}if(Qe(t)){if(t.body===null)return{text:null,unparseable:!1};try{return{text:await t.clone().text(),unparseable:!1}}catch{return{text:null,unparseable:!0}}}return{text:null,unparseable:!1}}function Le(t,e,n,s,r){t==null||t.emit({type:e,timestamp:Date.now(),applied:!1,detail:{url:n,method:s,...r,reason:"graphql-body-unparseable"}})}function Ie(t,e,n,s){if(!me(e,t.urlPattern))return{proceed:!1,outcome:null};if(t.methods&&!t.methods.includes(n))return{proceed:!1,outcome:null};const r=Tt(t.graphqlOperation,s);return r.kind==="no-match"?{proceed:!1,outcome:r}:{proceed:!0,outcome:r}}function De(t){return t?t.kind==="match"||t.kind==="skip-no-constraint"?t.operationName?{operationName:t.operationName}:{}:{}:{}}function Bn(t,e,n,s,r,a){t==null||t.emit({type:"network:abort",timestamp:Date.now(),applied:r,detail:{url:n,method:s,timeoutMs:e.timeout,...De(a)}})}function Je(t,e,n,s,r,a){t==null||t.emit({type:"network:corruption",timestamp:Date.now(),applied:r,detail:{url:n,method:s,strategy:e.strategy,...De(a)}})}function Zr(t){return t.graphqlOperation!==void 0}function Gr(t,e,n,s,r=new Map,a){return async(o,i)=>{var E,N,O,G,P;const c=Ar(o),u=jr(o,i),v=Pr(o,i),j=(()=>{const d=[e.failures,e.latencies,e.aborts,e.corruptions,e.cors];for(const A of d)if(A!=null&&A.some(Zr))return!0;return!1})();let $={kind:"not-graphql"};if(j){const d=await Dr(o,i);$=Nt(u,c,d.text,d.unparseable)}if(e.cors)for(const d of e.cors){s==null||s.debug("rule-evaluating",{url:c,method:u},d);const A=Ie(d,c,u,$);if(!A.proceed){s==null||s.debug("rule-skip-match",{url:c,method:u},d);continue}s==null||s.debug("rule-matched",{url:c,method:u},d);const ce=te(d,r);if(!ne(d,ce)){s==null||s.debug("rule-skip-counting",{url:c,method:u},d);continue}if(!F(d,a,s,{url:c,method:u}))continue;const W=z(d.probability,n);if(((E=A.outcome)==null?void 0:E.kind)==="unparseable"){W&&Le(s,"network:cors",c,u,{});continue}if(s==null||s.emit({type:"network:cors",timestamp:Date.now(),applied:W,detail:{url:c,method:u,...De(A.outcome)}}),!W){s==null||s.debug("rule-skip-probability",{url:c,method:u},d);continue}s==null||s.debug("rule-applied",{url:c,method:u},d);const ue=new TypeError("Failed to fetch");throw ue.stack="",ue}let Y=null,ee=null,q,p,l=!1;const f=d=>{!Y||l||(l=!0,p&&(clearTimeout(p),p=void 0),Bn(s,Y,c,u,d,ee))};if(e.aborts)for(const d of e.aborts){s==null||s.debug("rule-evaluating",{url:c,method:u,timeoutMs:d.timeout},d);const A=Ie(d,c,u,$);if(!A.proceed){s==null||s.debug("rule-skip-match",{url:c,method:u,timeoutMs:d.timeout},d);continue}s==null||s.debug("rule-matched",{url:c,method:u,timeoutMs:d.timeout},d);const ce=te(d,r);if(!ne(d,ce)){s==null||s.debug("rule-skip-counting",{url:c,method:u,timeoutMs:d.timeout},d);continue}if(!F(d,a,s,{url:c,method:u,timeoutMs:d.timeout}))continue;const W=z(d.probability,n);if(((N=A.outcome)==null?void 0:N.kind)==="unparseable"){W&&Le(s,"network:abort",c,u,{timeoutMs:d.timeout});continue}if(!W){s==null||s.debug("rule-skip-probability",{url:c,method:u,timeoutMs:d.timeout},d),Bn(s,d,c,u,!1,A.outcome);continue}s==null||s.debug("rule-applied",{url:c,method:u,timeoutMs:d.timeout},d),console.warn(`CHAOS: Aborting ${u} ${c} after ${d.timeout||0}ms`),Y=d,ee=A.outcome;const ue=new AbortController;q=Lr(ue.signal,v);const rt=()=>{l||(f(!0),ue.abort($r()))};d.timeout?p=setTimeout(rt,d.timeout):rt();break}if(Y)try{const d=await t(o,Ir(i,q));return f(!1),d}catch(d){throw f(!1),d}if(e.failures)for(const d of e.failures){s==null||s.debug("rule-evaluating",{url:c,method:u,statusCode:d.statusCode},d);const A=Ie(d,c,u,$);if(!A.proceed){s==null||s.debug("rule-skip-match",{url:c,method:u,statusCode:d.statusCode},d);continue}s==null||s.debug("rule-matched",{url:c,method:u,statusCode:d.statusCode},d);const ce=te(d,r);if(!ne(d,ce)){s==null||s.debug("rule-skip-counting",{url:c,method:u,statusCode:d.statusCode},d);continue}if(!F(d,a,s,{url:c,method:u,statusCode:d.statusCode}))continue;const W=z(d.probability,n);if(((O=A.outcome)==null?void 0:O.kind)==="unparseable"){W&&Le(s,"network:failure",c,u,{statusCode:d.statusCode});continue}if(s==null||s.emit({type:"network:failure",timestamp:Date.now(),applied:W,detail:{url:c,method:u,statusCode:d.statusCode,...De(A.outcome)}}),!W){s==null||s.debug("rule-skip-probability",{url:c,method:u,statusCode:d.statusCode},d);continue}s==null||s.debug("rule-applied",{url:c,method:u,statusCode:d.statusCode},d),console.warn(`CHAOS: Forcing ${d.statusCode} for ${u} ${c}`);const ue=d.body??JSON.stringify({error:"Chaos Maker Attack!"}),rt=d.headers??{};return new Response(ue,{status:d.statusCode,statusText:d.statusText??"Service Unavailable (Chaos)",headers:rt})}if(e.latencies)for(const d of e.latencies){s==null||s.debug("rule-evaluating",{url:c,method:u,delayMs:d.delayMs},d);const A=Ie(d,c,u,$);if(!A.proceed){s==null||s.debug("rule-skip-match",{url:c,method:u,delayMs:d.delayMs},d);continue}s==null||s.debug("rule-matched",{url:c,method:u,delayMs:d.delayMs},d);const ce=te(d,r);if(!ne(d,ce)){s==null||s.debug("rule-skip-counting",{url:c,method:u,delayMs:d.delayMs},d);continue}if(!F(d,a,s,{url:c,method:u,delayMs:d.delayMs}))continue;const W=z(d.probability,n);if(((G=A.outcome)==null?void 0:G.kind)==="unparseable"){W&&Le(s,"network:latency",c,u,{delayMs:d.delayMs});continue}if(s==null||s.emit({type:"network:latency",timestamp:Date.now(),applied:W,detail:{url:c,method:u,delayMs:d.delayMs,...De(A.outcome)}}),!W){s==null||s.debug("rule-skip-probability",{url:c,method:u,delayMs:d.delayMs},d);continue}s==null||s.debug("rule-applied",{url:c,method:u,delayMs:d.delayMs},d),console.warn(`CHAOS: Adding ${d.delayMs}ms latency to ${u} ${c}`),await new Promise(ue=>setTimeout(ue,d.delayMs))}let y=null,_=null;if(e.corruptions)for(const d of e.corruptions){s==null||s.debug("rule-evaluating",{url:c,method:u,strategy:d.strategy},d);const A=Ie(d,c,u,$);if(!A.proceed){s==null||s.debug("rule-skip-match",{url:c,method:u,strategy:d.strategy},d);continue}s==null||s.debug("rule-matched",{url:c,method:u,strategy:d.strategy},d);const ce=te(d,r);if(!ne(d,ce)){s==null||s.debug("rule-skip-counting",{url:c,method:u,strategy:d.strategy},d);continue}if(!F(d,a,s,{url:c,method:u,strategy:d.strategy}))continue;const W=z(d.probability,n);if(((P=A.outcome)==null?void 0:P.kind)==="unparseable"){W&&Le(s,"network:corruption",c,u,{strategy:d.strategy});continue}if(!W){s==null||s.debug("rule-skip-probability",{url:c,method:u,strategy:d.strategy},d),Je(s,d,c,u,!1,A.outcome);continue}s==null||s.debug("rule-applied",{url:c,method:u,strategy:d.strategy},d),y=d,_=A.outcome;break}let k;try{k=await t(o,i)}catch(d){throw y&&Je(s,y,c,u,!1,_),d}if(!y)return k;try{console.warn(`CHAOS: Corrupting response for ${u} ${c} with strategy: ${y.strategy}`);const d=await k.text(),A=gt(d,y.strategy);return Je(s,y,c,u,!0,_),new Response(A,{status:k.status,statusText:k.statusText,headers:k.headers})}catch(d){throw Je(s,y,c,u,!1,_),d}}}function Ur(t){return t==null?{text:null,unparseable:!1}:typeof t=="string"?{text:t,unparseable:!1}:typeof URLSearchParams<"u"&&t instanceof URLSearchParams?{text:t.toString(),unparseable:!1}:{text:null,unparseable:!0}}function Wr(t){return t.graphqlOperation!==void 0}function qr(t){const e=[t.failures,t.latencies,t.aborts,t.corruptions,t.cors];for(const n of e)if(n!=null&&n.some(Wr))return!0;return!1}function Ze(t,e,n,s,r){t==null||t.emit({type:e,timestamp:Date.now(),applied:!1,detail:{url:n,method:s,...r,reason:"graphql-body-unparseable"}})}function et(t,e,n,s,r){if(!me(e,t.urlPattern))return{proceed:!1,outcome:null};if(t.methods&&!t.methods.includes(n))return{proceed:!1,outcome:null};const a=Tt(t.graphqlOperation,s);if(a.kind==="no-match"||a.kind==="unparseable")return{proceed:!1,outcome:a};const o=te(t,r);return ne(t,o)?{proceed:!0,outcome:a}:{proceed:!1,outcome:a}}function Ge(t){return t?t.kind==="match"||t.kind==="skip-no-constraint"?t.operationName?{operationName:t.operationName}:{}:{}:{}}function Hn(t,e,n,s,r,a){t==null||t.emit({type:"network:abort",timestamp:Date.now(),applied:r,detail:{url:n,method:s,timeoutMs:e.timeout,...Ge(a)}})}function Yn(t,e,n,s,r,a){t==null||t.emit({type:"network:corruption",timestamp:Date.now(),applied:r,detail:{url:n,method:s,strategy:e.strategy,...Ge(a)}})}function Vr(t,e,n,s,r=new Map,a){const o=qr(e);return function(i){var Y,ee,q,p;const c=this._chaos_url,u=this._chaos_method;let v={kind:"not-graphql"};if(o){const l=Ur(i);v=Nt(u,c,l.text,l.unparseable)}if(e.cors)for(const l of e.cors){if(s==null||s.debug("rule-evaluating",{url:c,method:u},l),!me(c,l.urlPattern)){s==null||s.debug("rule-skip-match",{url:c,method:u},l);continue}if(l.methods&&!l.methods.includes(u)){s==null||s.debug("rule-skip-match",{url:c,method:u},l);continue}const f=Tt(l.graphqlOperation,v);if(f.kind==="no-match"){s==null||s.debug("rule-skip-match",{url:c,method:u},l);continue}if(f.kind==="unparseable"){Ze(s,"network:cors",c,u,{});continue}s==null||s.debug("rule-matched",{url:c,method:u},l);const y=te(l,r);if(!ne(l,y)){s==null||s.debug("rule-skip-counting",{url:c,method:u},l);continue}if(!F(l,a,s,{url:c,method:u}))continue;const _=z(l.probability,n);if(s==null||s.emit({type:"network:cors",timestamp:Date.now(),applied:_,detail:{url:c,method:u,...Ge(f)}}),!_){s==null||s.debug("rule-skip-probability",{url:c,method:u},l);continue}s==null||s.debug("rule-applied",{url:c,method:u},l),Object.defineProperty(this,"status",{value:0}),Object.defineProperty(this,"statusText",{value:""}),this.dispatchEvent(new Event("error")),this.dispatchEvent(new Event("loadend"));return}if(e.aborts)for(const l of e.aborts){s==null||s.debug("rule-evaluating",{url:c,method:u,timeoutMs:l.timeout},l);const f=et(l,c,u,v,r);if(!f.proceed){((Y=f.outcome)==null?void 0:Y.kind)==="unparseable"?Ze(s,"network:abort",c,u,{timeoutMs:l.timeout}):s==null||s.debug("rule-skip-match",{url:c,method:u,timeoutMs:l.timeout},l);continue}if(s==null||s.debug("rule-matched",{url:c,method:u,timeoutMs:l.timeout},l),!F(l,a,s,{url:c,method:u,timeoutMs:l.timeout}))continue;if(!z(l.probability,n)){s==null||s.debug("rule-skip-probability",{url:c,method:u,timeoutMs:l.timeout},l),Hn(s,l,c,u,!1,f.outcome);continue}s==null||s.debug("rule-applied",{url:c,method:u,timeoutMs:l.timeout},l),console.warn(`CHAOS: Aborting ${u} ${c} after ${l.timeout||0}ms`);let _=!1,k;const E=()=>{k&&(clearTimeout(k),k=void 0),typeof this.removeEventListener=="function"&&this.removeEventListener("loadend",O)},N=P=>{_||(_=!0,E(),Hn(s,l,c,u,P,f.outcome))},O=()=>{N(!1)},G=()=>{_||(N(!0),this.abort())};typeof this.addEventListener=="function"&&this.addEventListener("loadend",O);try{t.call(this,i)}catch(P){throw N(!1),P}if(_)return;l.timeout?k=setTimeout(G,l.timeout):G();return}if(e.failures)for(const l of e.failures){s==null||s.debug("rule-evaluating",{url:c,method:u,statusCode:l.statusCode},l);const f=et(l,c,u,v,r);if(!f.proceed){((ee=f.outcome)==null?void 0:ee.kind)==="unparseable"?Ze(s,"network:failure",c,u,{statusCode:l.statusCode}):s==null||s.debug("rule-skip-match",{url:c,method:u,statusCode:l.statusCode},l);continue}if(s==null||s.debug("rule-matched",{url:c,method:u,statusCode:l.statusCode},l),!F(l,a,s,{url:c,method:u,statusCode:l.statusCode}))continue;const y=z(l.probability,n);if(s==null||s.emit({type:"network:failure",timestamp:Date.now(),applied:y,detail:{url:c,method:u,statusCode:l.statusCode,...Ge(f.outcome)}}),!y){s==null||s.debug("rule-skip-probability",{url:c,method:u,statusCode:l.statusCode},l);continue}s==null||s.debug("rule-applied",{url:c,method:u,statusCode:l.statusCode},l),console.warn(`CHAOS: Forcing ${l.statusCode} for ${u} ${c}`),Object.defineProperty(this,"status",{value:l.statusCode}),Object.defineProperty(this,"statusText",{value:l.statusText??"Service Unavailable (Chaos)"});const _=l.body??JSON.stringify({error:"Chaos Maker Attack!"});Object.defineProperty(this,"responseText",{value:_,configurable:!0});const k=l.headers??{};Object.defineProperty(this,"getResponseHeader",{value:E=>{const N=Object.keys(k).find(O=>O.toLowerCase()===E.toLowerCase());return N?k[N]:null},configurable:!0}),Object.defineProperty(this,"getAllResponseHeaders",{value:()=>Object.entries(k).map(([E,N])=>`${E}: ${N}`).join(`\r
|
|
4
|
+
`),configurable:!0}),this.dispatchEvent(new Event("load")),this.dispatchEvent(new Event("loadend"));return}let j=null,$=null;if(e.corruptions)for(const l of e.corruptions){s==null||s.debug("rule-evaluating",{url:c,method:u,strategy:l.strategy},l);const f=et(l,c,u,v,r);if(!f.proceed){((q=f.outcome)==null?void 0:q.kind)==="unparseable"?Ze(s,"network:corruption",c,u,{strategy:l.strategy}):s==null||s.debug("rule-skip-match",{url:c,method:u,strategy:l.strategy},l);continue}if(s==null||s.debug("rule-matched",{url:c,method:u,strategy:l.strategy},l),!F(l,a,s,{url:c,method:u,strategy:l.strategy}))continue;if(!z(l.probability,n)){s==null||s.debug("rule-skip-probability",{url:c,method:u,strategy:l.strategy},l),Yn(s,l,c,u,!1,f.outcome);continue}s==null||s.debug("rule-applied",{url:c,method:u,strategy:l.strategy},l),j=l,$=f.outcome;break}if(j){let l=!1,f=null;const y=()=>{typeof this.removeEventListener=="function"&&(this.removeEventListener("error",E),this.removeEventListener("abort",E),this.removeEventListener("loadend",N))},_=O=>{l||(l=!0,Yn(s,j,c,u,O,$),y())},k=()=>{if(f!==null)return f;delete this.responseText;try{const O=this.responseText;return typeof O!="string"?(Object.defineProperty(this,"responseText",{value:O,configurable:!0}),_(!1),O):(f=gt(O,j.strategy),Object.defineProperty(this,"responseText",{value:f,configurable:!0}),_(!0),f)}catch(O){throw _(!1),O}},E=()=>{_(!1)},N=()=>{if(!l)try{k()}catch{}};typeof this.addEventListener=="function"&&(this.addEventListener("error",E),this.addEventListener("abort",E),this.addEventListener("loadend",N)),Object.defineProperty(this,"responseText",{get(){return k()},configurable:!0})}if(e.latencies)for(const l of e.latencies){s==null||s.debug("rule-evaluating",{url:c,method:u,delayMs:l.delayMs},l);const f=et(l,c,u,v,r);if(!f.proceed){((p=f.outcome)==null?void 0:p.kind)==="unparseable"?Ze(s,"network:latency",c,u,{delayMs:l.delayMs}):s==null||s.debug("rule-skip-match",{url:c,method:u,delayMs:l.delayMs},l);continue}if(s==null||s.debug("rule-matched",{url:c,method:u,delayMs:l.delayMs},l),!F(l,a,s,{url:c,method:u,delayMs:l.delayMs}))continue;const y=z(l.probability,n);if(s==null||s.emit({type:"network:latency",timestamp:Date.now(),applied:y,detail:{url:c,method:u,delayMs:l.delayMs,...Ge(f.outcome)}}),!y){s==null||s.debug("rule-skip-probability",{url:c,method:u,delayMs:l.delayMs},l);continue}s==null||s.debug("rule-applied",{url:c,method:u,delayMs:l.delayMs},l),console.warn(`CHAOS: Adding ${l.delayMs}ms latency to ${u} ${c}`),setTimeout(()=>{t.call(this,i)},l.delayMs);return}t.call(this,i)}}function zr(t){return function(e,n){this._chaos_url=n.toString(),this._chaos_method=e.toUpperCase(),t.call(this,e,n)}}function Ot(t,e,n,s,r){if(s==null||s.debug("rule-evaluating",{selector:e.selector,action:e.action},e),s==null||s.debug("rule-matched",{selector:e.selector,action:e.action},e),!F(e,r,s,{selector:e.selector,action:e.action}))return;const a=z(e.probability,n);if(s==null||s.emit({type:"ui:assault",timestamp:Date.now(),applied:a,detail:{selector:e.selector,action:e.action}}),!a){s==null||s.debug("rule-skip-probability",{selector:e.selector,action:e.action},e);return}s==null||s.debug("rule-applied",{selector:e.selector,action:e.action},e),console.warn(`CHAOS: Applying action '${e.action}' to element:`,t);try{switch(e.action){case"disable":"disabled"in t&&(t.disabled=!0);break;case"hide":t.style.display="none";break;case"remove":t.remove();break}}catch(o){console.error("Chaos Maker failed to assault element:",o,t)}}function Fr(t,e,n,s,r){if(t.nodeType!==Node.ELEMENT_NODE||!e.assaults)return;const a=t;for(const o of e.assaults)try{a.matches(o.selector)&&Ot(a,o,n,s,r),a.querySelectorAll(o.selector).forEach(i=>{Ot(i,o,n,s,r)})}catch(i){console.error(`Chaos Maker: Invalid selector '${o.selector}'`,i)}}function Br(t,e,n,s){if(t.assaults){console.log("CHAOS: Running initial DOM scan for existing elements...");for(const a of t.assaults)try{document.querySelectorAll(a.selector).forEach(o=>{Ot(o,a,e,n,s)})}catch(o){console.error(`Chaos Maker: Invalid selector in initial scan '${a.selector}'`,o)}}return new MutationObserver(a=>{for(const o of a)o.type==="childList"&&o.addedNodes.forEach(i=>Fr(i,t,e,n,s))})}const Kn=Symbol.for("chaos-maker.websocket.intercepted");function Hr(t,e){return t==="both"?!0:t===e}function Xn(t){return typeof t=="string"?"text":"binary"}function Qn(t,e){switch(e){case"truncate":return t.slice(0,Math.max(0,Math.floor(t.length/2)));case"malformed-json":return`${t}"}`;case"empty":return"";case"wrong-type":return"<html><body>Unexpected HTML</body></html>"}}function Jn(t,e){if(e==="malformed-json"||e==="wrong-type")return null;if(e==="empty")return typeof Blob<"u"&&t instanceof Blob?new Blob([]):t instanceof ArrayBuffer?new ArrayBuffer(0):new Uint8Array(0);if(typeof Blob<"u"&&t instanceof Blob)return t.slice(0,Math.max(0,Math.floor(t.size/2)));if(t instanceof ArrayBuffer)return t.slice(0,Math.max(0,Math.floor(t.byteLength/2)));const n=t,s=Math.max(0,Math.floor(n.byteLength/2));return new Uint8Array(n.buffer.slice(n.byteOffset,n.byteOffset+s))}function Se(t,e,n,s,r,a,o){if(!t)return null;for(const i of t){if(o==null||o.debug("rule-evaluating",{url:e,direction:n},i),!me(e,i.urlPattern)){o==null||o.debug("rule-skip-match",{url:e,direction:n},i);continue}if(!Hr(i.direction,n)){o==null||o.debug("rule-skip-match",{url:e,direction:n},i);continue}o==null||o.debug("rule-matched",{url:e,direction:n},i);const c=te(i,r);if(!ne(i,c)){o==null||o.debug("rule-skip-counting",{url:e,direction:n},i);continue}if(F(i,a,o,{url:e,direction:n})){if(!z(i.probability,s)){o==null||o.debug("rule-skip-probability",{url:e,direction:n},i);continue}return o==null||o.debug("rule-applied",{url:e,direction:n},i),i}}return null}function tt(t,e,n,s,r){t.emit({type:"websocket:drop",timestamp:Date.now(),applied:!0,detail:{url:e,direction:n,payloadType:s,...r?{reason:r}:{}}})}function es(t,e,n,s,r){t.emit({type:"websocket:delay",timestamp:Date.now(),applied:!0,detail:{url:e,direction:n,payloadType:s,delayMs:r}})}function Ce(t,e,n,s,r,a,o){t.emit({type:"websocket:corrupt",timestamp:Date.now(),applied:a,detail:{url:e,direction:n,payloadType:s,strategy:r,...o?{reason:o}:{}}})}function Yr(t,e,n,s){t.emit({type:"websocket:close",timestamp:Date.now(),applied:!0,detail:{url:e,closeCode:n,closeReason:s}})}function Kr(t,e,n,s,r,a){const o=new Map;let i=!0;const c=(p,l)=>{let f=o.get(p);f||(f=new Set,o.set(p,f)),f.add(l)},u=(p,l)=>{var f;(f=o.get(p))==null||f.delete(l)},v=(p,l)=>{const f=o.get(p);if(f){for(const y of f)clearTimeout(y.handle),y.kind==="delay"&&tt(n,y.url,y.direction,y.payloadType,l);o.delete(p)}},j=(p,l,f)=>{const y=new MessageEvent("message",{data:f,origin:l.origin,lastEventId:l.lastEventId,source:l.source,ports:Array.from(l.ports??[])});y[Kn]=!0,p.dispatchEvent(y)},$=(p,l,f,y)=>{if(!i)return{handled:!1,data:f};const _="outbound",k=Xn(f);if(Se(e.drops,l,_,s,r,a,n))return tt(n,l,_,k),{handled:!0,data:f};let E=f;const N=Se(e.corruptions,l,_,s,r,a,n);if(N)if(k==="text")E=Qn(E,N.strategy),Ce(n,l,_,k,N.strategy,!0);else{const G=Jn(E,N.strategy);G===null?Ce(n,l,_,k,N.strategy,!1,"incompatible-payload-type"):(E=G,Ce(n,l,_,k,N.strategy,!0))}const O=Se(e.delays,l,_,s,r,a,n);if(O){es(n,l,_,k,O.delayMs);const G={kind:"delay",handle:setTimeout(()=>{u(p,G);try{y(E)}catch{}},O.delayMs),url:l,direction:_,payloadType:k};return c(p,G),{handled:!0,data:E}}return{handled:!1,data:E}},Y=(p,l)=>{p.addEventListener("message",f=>{const y=f;if(y[Kn]||!i)return;const _="inbound",k=Xn(y.data);if(Se(e.drops,l,_,s,r,a,n)){y.stopImmediatePropagation(),tt(n,l,_,k);return}let E=y.data,N=!1;const O=Se(e.corruptions,l,_,s,r,a,n);if(O)if(k==="text")E=Qn(E,O.strategy),N=!0,Ce(n,l,_,k,O.strategy,!0);else{const P=Jn(E,O.strategy);P===null?Ce(n,l,_,k,O.strategy,!1,"incompatible-payload-type"):(E=P,N=!0,Ce(n,l,_,k,O.strategy,!0))}const G=Se(e.delays,l,_,s,r,a,n);if(G){y.stopImmediatePropagation(),es(n,l,_,k,G.delayMs);const P={kind:"delay",handle:setTimeout(()=>{u(p,P),j(p,y,E)},G.delayMs),url:l,direction:_,payloadType:k};c(p,P);return}N&&(y.stopImmediatePropagation(),j(p,y,E))})},ee=(p,l)=>{if(e.closes)for(const f of e.closes){if(n.debug("rule-evaluating",{url:l},f),!me(l,f.urlPattern)){n.debug("rule-skip-match",{url:l},f);continue}n.debug("rule-matched",{url:l},f);const y=te(f,r);if(!ne(f,y)){n.debug("rule-skip-counting",{url:l},f);continue}if(!F(f,a,n,{url:l}))continue;if(!z(f.probability,s)){n.debug("rule-skip-probability",{url:l},f);continue}n.debug("rule-applied",{url:l},f);const _=f.code??1e3,k=f.reason??"Chaos Maker close",E=f.afterMs??0,N=()=>{if(i){v(p,"close-interrupt"),Yr(n,l,_,k);try{p.close(_,k)}catch{try{p.close()}catch{}}}};if(E<=0)p.readyState===p.OPEN?N():p.addEventListener("open",N,{once:!0});else{const O=()=>{const G={kind:"close",handle:setTimeout(N,E)};c(p,G)};p.readyState===p.OPEN?O():p.addEventListener("open",O,{once:!0})}return}};function q(p,l){const f=new t(p,l),y=typeof p=="string"?p:p.toString(),_=f.send.bind(f);return f.send=function(E){const N=$(f,y,E,_);N.handled||_(N.data)},Y(f,y),ee(f,y),f}Object.defineProperty(q,"prototype",{value:t.prototype,writable:!1});for(const p of["CONNECTING","OPEN","CLOSING","CLOSED"])q[p]=t[p];return{Wrapped:q,uninstall(){i=!1;for(const[,p]of o)for(const l of p)clearTimeout(l.handle),l.kind==="delay"&&tt(n,l.url,l.direction,l.payloadType,"stop-during-delay");o.clear()}}}const ts=Symbol.for("chaos-maker.eventsource.intercepted");function Xr(t,e){return t===void 0||t==="*"?!0:t===e}function Mt(t,e,n,s,r,a,o){if(!t)return null;for(const i of t){if(o==null||o.debug("rule-evaluating",{url:e,eventType:n},i),!me(e,i.urlPattern)){o==null||o.debug("rule-skip-match",{url:e,eventType:n},i);continue}if(!Xr(i.eventType,n)){o==null||o.debug("rule-skip-match",{url:e,eventType:n},i);continue}o==null||o.debug("rule-matched",{url:e,eventType:n},i);const c=te(i,r);if(!ne(i,c)){o==null||o.debug("rule-skip-counting",{url:e,eventType:n},i);continue}if(F(i,a,o,{url:e,eventType:n})){if(!z(i.probability,s)){o==null||o.debug("rule-skip-probability",{url:e,eventType:n},i);continue}return o==null||o.debug("rule-applied",{url:e,eventType:n},i),i}}return null}function Rt(t,e,n,s){t.emit({type:"sse:drop",timestamp:Date.now(),applied:!0,detail:{url:e,eventType:n,...s?{reason:s}:{}}})}function Qr(t,e,n,s){t.emit({type:"sse:delay",timestamp:Date.now(),applied:!0,detail:{url:e,eventType:n,delayMs:s}})}function Jr(t,e,n,s){t.emit({type:"sse:corrupt",timestamp:Date.now(),applied:!0,detail:{url:e,eventType:n,strategy:s}})}function ea(t,e,n){t.emit({type:"sse:close",timestamp:Date.now(),applied:!0,detail:{url:e,reason:n}})}function ta(t,e,n,s,r,a){const o=new Map;let i=!0;const c=(p,l)=>{let f=o.get(p);f||(f=new Set,o.set(p,f)),f.add(l)},u=(p,l)=>{var f;(f=o.get(p))==null||f.delete(l)},v=(p,l)=>{const f=o.get(p);if(f){for(const y of f)clearTimeout(y.handle),y.kind==="delay"&&Rt(n,y.url,y.eventType,l);o.delete(p)}},j=(p,l,f)=>{const y=new MessageEvent(l.type||"message",{data:f,origin:l.origin,lastEventId:l.lastEventId});y[ts]=!0,p.dispatchEvent(y)},$=(p,l,f)=>{if(f[ts]||!i)return;const y=f.type||"message";if(Mt(e.drops,l,y,s,r,a,n)){f.stopImmediatePropagation(),Rt(n,l,y);return}let _=typeof f.data=="string"?f.data:String(f.data),k=!1;const E=Mt(e.corruptions,l,y,s,r,a,n);E&&(_=gt(_,E.strategy),k=!0,Jr(n,l,y,E.strategy));const N=Mt(e.delays,l,y,s,r,a,n);if(N){f.stopImmediatePropagation(),Qr(n,l,y,N.delayMs);const O={kind:"delay",handle:setTimeout(()=>{u(p,O),i&&p.readyState!==p.CLOSED&&j(p,f,_)},N.delayMs),url:l,eventType:y};c(p,O);return}k&&(f.stopImmediatePropagation(),j(p,f,_))},Y=p=>{if(!e.closes)return null;for(const l of e.closes){if(n.debug("rule-evaluating",{url:p},l),!me(p,l.urlPattern)){n.debug("rule-skip-match",{url:p},l);continue}n.debug("rule-matched",{url:p},l);const f=te(l,r);if(!ne(l,f)){n.debug("rule-skip-counting",{url:p},l);continue}if(F(l,a,n,{url:p})){if(!z(l.probability,s)){n.debug("rule-skip-probability",{url:p},l);continue}return n.debug("rule-applied",{url:p},l),l}}return null},ee=(p,l)=>{const f=Y(l);if(!f)return;const y=f.afterMs??0,_=()=>{if(i){v(p,"close-interrupt"),ea(n,l,"chaos-maker-close");try{p.close()}catch{}try{p.dispatchEvent(new Event("error"))}catch{}}};if(y<=0){const k={kind:"close",handle:setTimeout(_,0)};c(p,k)}else{const k={kind:"close",handle:setTimeout(_,y)};c(p,k)}};function q(p,l){const f=new t(p,l),y=typeof p=="string"?p:p.toString(),_=P=>{$(f,y,P)},k=new Set,E=f.addEventListener.bind(f),N=P=>{k.has(P)||(k.add(P),E(P,_,{capture:!0}))};N("message");const O=P=>{if(P)for(const d of P)d.eventType&&d.eventType!=="*"&&d.eventType!=="message"&&N(d.eventType)};O(e.drops),O(e.delays),O(e.corruptions);const G=(P,d,A)=>{P!=="open"&&P!=="error"&&N(P),E(P,d,A)};return f.addEventListener=G,ee(f,y),f}Object.defineProperty(q,"prototype",{value:t.prototype,writable:!1});for(const p of["CONNECTING","OPEN","CLOSED"])q[p]=t[p];return{Wrapped:q,uninstall(){i=!1;for(const[,p]of o)for(const l of p)clearTimeout(l.handle),l.kind==="delay"&&Rt(n,l.url,l.eventType,"stop-during-delay");o.clear()}}}function ns(t){return t===void 0?{enabled:!1}:typeof t=="boolean"?{enabled:t}:{enabled:t.enabled}}const na=[{pick:t=>{var e;return(e=t.network)==null?void 0:e.failures},ruleType:"failure"},{pick:t=>{var e;return(e=t.network)==null?void 0:e.latencies},ruleType:"latency"},{pick:t=>{var e;return(e=t.network)==null?void 0:e.aborts},ruleType:"abort"},{pick:t=>{var e;return(e=t.network)==null?void 0:e.corruptions},ruleType:"corruption"},{pick:t=>{var e;return(e=t.network)==null?void 0:e.cors},ruleType:"cors"},{pick:t=>{var e;return(e=t.ui)==null?void 0:e.assaults},ruleType:"ui-assault"},{pick:t=>{var e;return(e=t.websocket)==null?void 0:e.drops},ruleType:"ws-drop"},{pick:t=>{var e;return(e=t.websocket)==null?void 0:e.delays},ruleType:"ws-delay"},{pick:t=>{var e;return(e=t.websocket)==null?void 0:e.corruptions},ruleType:"ws-corrupt"},{pick:t=>{var e;return(e=t.websocket)==null?void 0:e.closes},ruleType:"ws-close"},{pick:t=>{var e;return(e=t.sse)==null?void 0:e.drops},ruleType:"sse-drop"},{pick:t=>{var e;return(e=t.sse)==null?void 0:e.delays},ruleType:"sse-delay"},{pick:t=>{var e;return(e=t.sse)==null?void 0:e.corruptions},ruleType:"sse-corrupt"},{pick:t=>{var e;return(e=t.sse)==null?void 0:e.closes},ruleType:"sse-close"}];function ss(t){const e=new WeakMap;for(const{pick:n,ruleType:s}of na){const r=n(t);r&&r.forEach((a,o)=>{e.set(a,{ruleType:s,ruleId:`${s}#${o}`})})}return e}function rs(t,e){const n=[];return e.ruleId&&n.push(`rule=${e.ruleId}`),e.phase&&n.push(e.phase),e.method&&n.push(e.method),e.url&&n.push(e.url),e.statusCode!==void 0&&n.push(`-> ${e.statusCode}`),e.delayMs!==void 0&&n.push(`+${e.delayMs}ms`),e.direction&&n.push(e.direction),e.eventType&&n.push(`event=${e.eventType}`),e.selector&&n.push(`selector=${e.selector}`),e.action&&n.push(`action=${e.action}`),e.strategy&&n.push(`strategy=${e.strategy}`),e.groupName&&n.push(`group=${e.groupName}`),e.reason&&n.push(`reason=${e.reason}`),n.length===0?t:`${t}: ${n.join(" ")}`}class as{constructor(e,n="page"){this.opts=e,this.target=n}isEnabled(){return this.opts.enabled}log(e,n){if(!this.opts.enabled)return null;const s={...n,stage:e},r={type:"debug",timestamp:Date.now(),applied:!1,detail:s};if(typeof console<"u"&&typeof console.debug=="function"){const a=this.target==="sw"?"[Chaos SW]":"[Chaos]";try{console.debug(`${a} ${rs(e,s)}`)}catch{}}return r}}function Ee(t){const e=t.trim();if(!e)throw new Error("[chaos-maker] Group name cannot be empty");return e}class At{constructor(e,n={}){R(this,"config");R(this,"emitter");R(this,"random");R(this,"seed");R(this,"running",!1);R(this,"target");R(this,"originalFetch");R(this,"originalXhrSend");R(this,"originalXhrOpen");R(this,"domObserver");R(this,"originalWebSocket");R(this,"webSocketHandle");R(this,"originalEventSource");R(this,"eventSourceHandle");R(this,"requestCounters",new Map);R(this,"groups");R(this,"ruleIds");R(this,"logger");this.config=Ct(e,n.validation),this.emitter=new Vn;const s=qn(this.config.seed);this.random=s.random,this.seed=s.seed,this.target=n.target??globalThis,this.groups=new en;for(const a of this.config.groups??[])this.groups.ensure(a.name,{enabled:a.enabled??!0,explicit:!0});this.seedGroupsFromRules(),this.groups.ensure(Ae,{enabled:!0});const r=ns(this.config.debug);r.enabled&&(this.ruleIds=ss(this.config),this.emitter.setRuleIds(this.ruleIds),this.logger=new as(r,"page"),this.emitter.setLogger(this.logger)),console.log(`Chaos Maker initialized (seed: ${this.seed})`)}seedGroupsFromRules(){tn(this.config,e=>{e.group&&this.groups.ensure(e.group)})}collectReferencedGroups(){const e=new Set;return tn(this.config,n=>{n.group&&e.add(n.group)}),e}getSeed(){return this.seed}on(e,n){this.emitter.on(e,n)}off(e,n){this.emitter.off(e,n)}getLog(){return this.emitter.getLog()}clearLog(){this.emitter.clearLog()}enableGroup(e){const n=Ee(e);this.groups.setEnabled(n,!0),this.emitter.emit({type:"rule-group:enabled",timestamp:Date.now(),applied:!0,detail:{groupName:n}}),this.emitter.debug("lifecycle",{phase:"engine:group-toggled",groupName:n,enabled:!0})}disableGroup(e){const n=Ee(e);this.groups.setEnabled(n,!1),this.emitter.emit({type:"rule-group:disabled",timestamp:Date.now(),applied:!0,detail:{groupName:n}}),this.emitter.debug("lifecycle",{phase:"engine:group-toggled",groupName:n,enabled:!1})}createGroup(e,n){const s=Ee(e);this.groups.ensure(s,{...n,explicit:!0})}removeGroup(e,n){const s=Ee(e);return this.groups.remove(s,this.collectReferencedGroups(),n)}hasGroup(e){const n=Ee(e);return this.groups.has(n)}getGroupState(e){const n=Ee(e);return this.groups.isActive(n)}getGroupsSnapshot(){return this.groups.getSnapshot()}listGroups(){return this.groups.list()}start(){if(this.running){console.warn("Chaos Maker is already running. Call stop() first.");return}this.requestCounters.clear(),this.running=!0,console.log("🛠️ Chaos Maker ENGAGED 🛠️"),this.emitter.debug("lifecycle",{phase:"engine:start"});const e=this.target;this.config.network&&(typeof e.fetch=="function"&&(this.originalFetch=e.fetch,e.fetch=Gr(this.originalFetch.bind(e),this.config.network,this.random,this.emitter,this.requestCounters,this.groups)),typeof e.XMLHttpRequest=="function"&&(this.originalXhrOpen=e.XMLHttpRequest.prototype.open,e.XMLHttpRequest.prototype.open=zr(this.originalXhrOpen),this.originalXhrSend=e.XMLHttpRequest.prototype.send,e.XMLHttpRequest.prototype.send=Vr(this.originalXhrSend,this.config.network,this.random,this.emitter,this.requestCounters,this.groups))),this.config.ui&&(typeof document>"u"||typeof MutationObserver>"u"?console.warn("Chaos Maker: UI config ignored — no DOM available in current context."):(this.domObserver=Br(this.config.ui,this.random,this.emitter,this.groups),this.domObserver.observe(document.body,{childList:!0,subtree:!0}),console.log("UI Assailant is now observing the DOM."))),this.config.websocket&&typeof e.WebSocket<"u"&&(this.originalWebSocket=e.WebSocket,this.webSocketHandle=Kr(this.originalWebSocket,this.config.websocket,this.emitter,this.random,this.requestCounters,this.groups),e.WebSocket=this.webSocketHandle.Wrapped),this.config.sse&&typeof e.EventSource<"u"&&(this.originalEventSource=e.EventSource,this.eventSourceHandle=ta(this.originalEventSource,this.config.sse,this.emitter,this.random,this.requestCounters,this.groups),e.EventSource=this.eventSourceHandle.Wrapped)}stop(){this.running=!1,console.log("🛑 Chaos Maker DISENGAGED 🛑"),this.emitter.debug("lifecycle",{phase:"engine:stop"});const e=this.target;this.originalFetch&&(e.fetch=this.originalFetch),this.originalXhrSend&&typeof e.XMLHttpRequest=="function"&&(e.XMLHttpRequest.prototype.send=this.originalXhrSend),this.originalXhrOpen&&typeof e.XMLHttpRequest=="function"&&(e.XMLHttpRequest.prototype.open=this.originalXhrOpen),this.domObserver&&(this.domObserver.disconnect(),console.log("UI Assailant has stopped observing.")),this.originalWebSocket&&(e.WebSocket=this.originalWebSocket,this.originalWebSocket=void 0),this.webSocketHandle&&(this.webSocketHandle.uninstall(),this.webSocketHandle=void 0),this.originalEventSource&&(e.EventSource=this.originalEventSource,this.originalEventSource=void 0),this.eventSourceHandle&&(this.eventSourceHandle.uninstall(),this.eventSourceHandle=void 0)}}function os(t){return je(t)}function is(t){const e=t.trim();if(!e)throw new Error("[chaos-maker] Group name cannot be empty");return e}function sa(t){const e=t.trim();if(!e)throw new Error("[chaos-maker] preset name cannot be empty");return e}class ra{constructor(e){R(this,"config");R(this,"pendingGroup");R(this,"pendingPresets",[]);this.config=e?os(e):{network:{},ui:{},websocket:{},sse:{}},this.config.network||(this.config.network={}),this.config.ui||(this.config.ui={}),this.config.websocket||(this.config.websocket={}),this.config.sse||(this.config.sse={})}inGroup(e){return this.pendingGroup=is(e),this}defineGroup(e,n){this.config.groups||(this.config.groups=[]);const s={name:is(e)};return(n==null?void 0:n.enabled)!==void 0&&(s.enabled=n.enabled),this.config.groups.push(s),this}withGroup(e){const n=this.pendingGroup;return this.pendingGroup=void 0,n?{...e,group:n}:e}failRequests(e,n,s,r,a,o,i){return this.config.network.failures||(this.config.network.failures=[]),this.config.network.failures.push(this.withGroup({urlPattern:e,statusCode:n,probability:s,methods:r,body:a,headers:o,...i})),this}addLatency(e,n,s,r,a){return this.config.network.latencies||(this.config.network.latencies=[]),this.config.network.latencies.push(this.withGroup({urlPattern:e,delayMs:n,probability:s,methods:r,...a})),this}abortRequests(e,n,s,r,a){return this.config.network.aborts||(this.config.network.aborts=[]),this.config.network.aborts.push(this.withGroup({urlPattern:e,probability:n,timeout:s,methods:r,...a})),this}corruptResponses(e,n,s,r,a){return this.config.network.corruptions||(this.config.network.corruptions=[]),this.config.network.corruptions.push(this.withGroup({urlPattern:e,strategy:n,probability:s,methods:r,...a})),this}simulateCors(e,n,s,r){return this.config.network.cors||(this.config.network.cors=[]),this.config.network.cors.push(this.withGroup({urlPattern:e,probability:n,methods:s,...r})),this}failRequestsOnNth(e,n,s,r){return this.failRequests(e,n,1,r,void 0,void 0,{onNth:s})}addLatencyOnNth(e,n,s,r){return this.addLatency(e,n,1,r,{onNth:s})}abortRequestsOnNth(e,n,s,r){return this.abortRequests(e,1,s,r,{onNth:n})}corruptResponsesOnNth(e,n,s,r){return this.corruptResponses(e,n,1,r,{onNth:s})}simulateCorsOnNth(e,n,s){return this.simulateCors(e,1,s,{onNth:n})}failRequestsEveryNth(e,n,s,r){return this.failRequests(e,n,1,r,void 0,void 0,{everyNth:s})}addLatencyEveryNth(e,n,s,r){return this.addLatency(e,n,1,r,{everyNth:s})}abortRequestsEveryNth(e,n,s,r){return this.abortRequests(e,1,s,r,{everyNth:n})}corruptResponsesEveryNth(e,n,s,r){return this.corruptResponses(e,n,1,r,{everyNth:s})}simulateCorsEveryNth(e,n,s){return this.simulateCors(e,1,s,{everyNth:n})}failRequestsAfterN(e,n,s,r){return this.failRequests(e,n,1,r,void 0,void 0,{afterN:s})}addLatencyAfterN(e,n,s,r){return this.addLatency(e,n,1,r,{afterN:s})}abortRequestsAfterN(e,n,s,r){return this.abortRequests(e,1,s,r,{afterN:n})}corruptResponsesAfterN(e,n,s,r){return this.corruptResponses(e,n,1,r,{afterN:s})}simulateCorsAfterN(e,n,s){return this.simulateCors(e,1,s,{afterN:n})}assaultUi(e,n,s){return this.config.ui.assaults||(this.config.ui.assaults=[]),this.config.ui.assaults.push(this.withGroup({selector:e,action:n,probability:s})),this}dropMessages(e,n,s,r){return this.config.websocket.drops||(this.config.websocket.drops=[]),this.config.websocket.drops.push(this.withGroup({urlPattern:e,direction:n,probability:s,...r})),this}delayMessages(e,n,s,r,a){return this.config.websocket.delays||(this.config.websocket.delays=[]),this.config.websocket.delays.push(this.withGroup({urlPattern:e,direction:n,delayMs:s,probability:r,...a})),this}corruptMessages(e,n,s,r,a){return this.config.websocket.corruptions||(this.config.websocket.corruptions=[]),this.config.websocket.corruptions.push(this.withGroup({urlPattern:e,direction:n,strategy:s,probability:r,...a})),this}closeConnection(e,n,s,r){return this.config.websocket.closes||(this.config.websocket.closes=[]),this.config.websocket.closes.push(this.withGroup({urlPattern:e,probability:n,...s,...r})),this}dropMessagesOnNth(e,n,s){return this.dropMessages(e,n,1,{onNth:s})}delayMessagesOnNth(e,n,s,r){return this.delayMessages(e,n,s,1,{onNth:r})}failGraphQLOperation(e,n,s,r="*"){return this.config.network.failures||(this.config.network.failures=[]),this.config.network.failures.push(this.withGroup({urlPattern:r,statusCode:n,probability:s,graphqlOperation:e})),this}delayGraphQLOperation(e,n,s,r="*"){return this.config.network.latencies||(this.config.network.latencies=[]),this.config.network.latencies.push(this.withGroup({urlPattern:r,delayMs:n,probability:s,graphqlOperation:e})),this}dropSSE(e,n,s,r){return this.config.sse.drops||(this.config.sse.drops=[]),this.config.sse.drops.push(this.withGroup({urlPattern:e,probability:n,...s?{eventType:s}:{},...r})),this}delaySSE(e,n,s,r,a){return this.config.sse.delays||(this.config.sse.delays=[]),this.config.sse.delays.push(this.withGroup({urlPattern:e,delayMs:n,probability:s,...r?{eventType:r}:{},...a})),this}corruptSSE(e,n,s,r,a){return this.config.sse.corruptions||(this.config.sse.corruptions=[]),this.config.sse.corruptions.push(this.withGroup({urlPattern:e,strategy:n,probability:s,...r?{eventType:r}:{},...a})),this}closeSSE(e,n,s,r){return this.config.sse.closes||(this.config.sse.closes=[]),this.config.sse.closes.push(this.withGroup({urlPattern:e,probability:n,...s,...r})),this}withSeed(e){return this.config.seed=e,this}withDebug(e=!0){return this.config.debug=e,this}usePreset(e){const n=sa(e);return this.pendingPresets.includes(n)||this.pendingPresets.push(n),this}build(){const e=os(this.config),n=[],s=new Set;for(const r of[...e.presets??[],...this.pendingPresets])s.has(r)||(s.add(r),n.push(r));return n.length?e.presets=n:delete e.presets,e}}const nt="__chaosMakerRegExp";function aa(t){if(t===null||typeof t!="object")return!1;const e=t,n=Object.keys(e);if(n.length!==1||n[0]!==nt)return!1;const s=e[nt];if(!s||typeof s!="object")return!1;const r=s;for(const a of Object.keys(r))if(a!=="source"&&a!=="flags")return!1;return typeof r.source=="string"&&typeof r.flags=="string"}function jt(t){if(t===null||typeof t!="object")return t;if(t instanceof RegExp)return{[nt]:{source:t.source,flags:t.flags}};if(Array.isArray(t))return t.map(n=>jt(n));const e={};for(const[n,s]of Object.entries(t))e[n]=jt(s);return e}function st(t){if(t===null||typeof t!="object"||t instanceof RegExp)return t;if(aa(t)){const{source:n,flags:s}=t[nt];try{return new RegExp(n,s)}catch(r){return console.warn(`[chaos-maker] deserializeForTransport: invalid RegExp { source: ${JSON.stringify(n)}, flags: ${JSON.stringify(s)} } — ${r.message}`),t}}if(Array.isArray(t))return t.map(n=>st(n));const e={};for(const[n,s]of Object.entries(t))e[n]=st(s);return e}const oa=`
|
|
5
5
|
(function installChaosMakerSWBridge() {
|
|
6
6
|
if (typeof window === 'undefined') return;
|
|
7
7
|
if (window.__chaosMakerSWBridgeInstalled) return;
|
|
@@ -76,6 +76,13 @@ ${t.map(s=>` - ${s}`).join(`
|
|
|
76
76
|
|
|
77
77
|
window.__chaosMakerSWBridge = {
|
|
78
78
|
apply: function (cfg, timeoutMs) {
|
|
79
|
+
// Defensive: page-side adapters validate before calling apply. The
|
|
80
|
+
// page-side bundle deliberately excludes Zod, so a null/primitive/
|
|
81
|
+
// array/wildly-wrong payload throws here instead of silently posting
|
|
82
|
+
// garbage to the SW. \`typeof [] === 'object'\` so reject arrays too.
|
|
83
|
+
if (!cfg || typeof cfg !== 'object' || Array.isArray(cfg)) {
|
|
84
|
+
return Promise.reject(new Error('[chaos-maker] bridge.apply: config must be an object'));
|
|
85
|
+
}
|
|
79
86
|
// Stash cfg BEFORE awaiting ack — intentional. If the first ack times
|
|
80
87
|
// out (e.g. SW still installing), the controllerchange listener above
|
|
81
88
|
// will retry with this config once the new SW claims the page. Caller
|
|
@@ -92,6 +99,17 @@ ${t.map(s=>` - ${s}`).join(`
|
|
|
92
99
|
}
|
|
93
100
|
return postViaPort(navigator.serviceWorker.controller, { __chaosMakerStop: true }, timeoutMs);
|
|
94
101
|
},
|
|
102
|
+
toggleGroup: function (name, enabled, timeoutMs) {
|
|
103
|
+
if (!('serviceWorker' in navigator) || !navigator.serviceWorker.controller) {
|
|
104
|
+
return Promise.reject(new Error('[chaos-maker] no SW controller — call injectSWChaos before toggleGroup'));
|
|
105
|
+
}
|
|
106
|
+
var t = (typeof timeoutMs === 'number' && timeoutMs > 0) ? timeoutMs : 2000;
|
|
107
|
+
return postViaPort(
|
|
108
|
+
navigator.serviceWorker.controller,
|
|
109
|
+
{ __chaosMakerToggleGroup: { name: String(name), enabled: !!enabled } },
|
|
110
|
+
t,
|
|
111
|
+
);
|
|
112
|
+
},
|
|
95
113
|
getLocalLog: function () { return log.slice(); },
|
|
96
114
|
clearLocalLog: function () { log.length = 0; },
|
|
97
115
|
getRemoteLog: function (timeoutMs) {
|
|
@@ -107,4 +125,4 @@ ${t.map(s=>` - ${s}`).join(`
|
|
|
107
125
|
|
|
108
126
|
addSwListeners();
|
|
109
127
|
})();
|
|
110
|
-
`;if(typeof window<"u"){window.ChaosMaker=
|
|
128
|
+
`;if(typeof window<"u"){window.ChaosMaker=At;const t={instance:null,start:e=>{t.instance&&(t.instance.stop(),t.instance=null);try{const n=st(e),s=new At(n);return s.start(),t.instance=s,{success:!0,message:"Chaos started"}}catch(n){return console.error("Chaos Utils Error:",n),{success:!1,message:n.message}}},stop:()=>t.instance?(t.instance.stop(),t.instance=null,{success:!0,message:"Chaos stopped"}):{success:!1,message:"No chaos instance to stop"},getLog:()=>t.instance?t.instance.getLog():[],getSeed:()=>t.instance?t.instance.getSeed():null,enableGroup:e=>{if(!t.instance)return{success:!1,message:"No chaos instance"};try{return t.instance.enableGroup(e),{success:!0,message:`Group '${e}' enabled`}}catch(n){return{success:!1,message:(n==null?void 0:n.message)??String(n)}}},disableGroup:e=>{if(!t.instance)return{success:!1,message:"No chaos instance"};try{return t.instance.disableGroup(e),{success:!0,message:`Group '${e}' disabled`}}catch(n){return{success:!1,message:(n==null?void 0:n.message)??String(n)}}},createGroup:(e,n)=>{if(!t.instance)return{success:!1,message:"No chaos instance"};try{return t.instance.createGroup(e,n),{success:!0,message:`Group '${e}' created`}}catch(s){return{success:!1,message:(s==null?void 0:s.message)??String(s)}}},getGroupState:e=>{if(!t.instance)return null;try{return t.instance.getGroupState(e)}catch{return null}},validate:(e,n)=>Ct(e,n)};if(window.chaosUtils=t,window.__CHAOS_CONFIG__)try{const e=window.__CHAOS_CONFIG__;t.start(e),delete window.__CHAOS_CONFIG__}catch(e){console.error("ChaosMaker auto-start failed:",e)}}T.BUILT_IN_PRESETS=sn,T.ChaosConfigBuilder=ra,T.ChaosConfigError=ye,T.ChaosEventEmitter=Vn,T.ChaosMaker=At,T.DEFAULT_GROUP_NAME=Ae,T.Logger=as,T.PresetRegistry=rn,T.RuleGroupRegistry=en,T.SW_BRIDGE_SOURCE=oa,T.VALIDATOR_BRAND_VERSION=St,T.buildRuleIdMap=ss,T.chaosConfigSchemaPassthrough=Dn,T.chaosConfigSchemaStrict=xt,T.createPrng=qn,T.deserializeForTransport=st,T.expandPresets=on,T.extractGraphQLOperation=Nt,T.formatDebugMessage=rs,T.generateSeed=Wn,T.normalizeDebugOption=ns,T.operationNameMatches=Fn,T.parseOperationFromQueryString=Et,T.prepareChaosConfig=Un,T.presets=Bs,T.serializeForTransport=jt,T.validateChaosConfig=Ct,T.validateConfig=Gn,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})}));
|