@tomato414941/foundation 29.0.0 → 29.0.2

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.
Files changed (2) hide show
  1. package/dist/cli.mjs +1 -1
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -125,7 +125,7 @@ ${c}`:c:"",l=Function,d=`return (input) => {
125
125
  ${c}
126
126
  }`,f;try{f=new l(...s,d)(...a)}catch(p){throw new Re(`this schema (generated code failed to evaluate: ${p.message})`)}return e?.debug&&(f.code=u),f.definite=o.definite,f}function ne(t,e){for(let[o,n]of t.constants)if(n===e)return o;let r=`c${t.constantCounter++}`;return t.constants.set(r,e),r}function Lu(t,e){return t.definite=!1,ne(t,e)}function ee(t){return`v${t.varCounter++}`}function afe(t,e){let r=t._zod.run({value:e,issues:[]},{});if(r&&typeof r.then=="function")return ln;let o=r;return o.issues.length===0?o.value:ln}function Hr(t,e,r,o,n=!0){let i=t.content.length,s=e.constants.size,a=e.constantCounter,c=e.varCounter;try{return Pt(t,e,r,o,n)}catch(u){if(!(u instanceof Re)||!u.islandable)throw u;if(t.content.length=i,e.constants.size>s){let l=Array.from(e.constants.keys()).slice(s);for(let d of l)e.constants.delete(d)}return e.constantCounter=a,e.varCounter=c,cfe(t,e,r,o)}}function cfe(t,e,r,o){e.definite=!1;let n=ne(e,r),i=ne(e,afe),s=ee(e);return t.write(`const ${s} = ${i}(${n}, ${o});`),t.write(`if (${s} === INVALID) return INVALID;`),s}var ufe=new Set(["max_size","min_size","size_equals","max_length","min_length","length_equals"]);function lfe(t,e,r,o){let n=r._zod.def.checks;if(!n||n.length===0)return o;let i=o;for(let s of n){let a=s._zod.def;if(a.when&&!ufe.has(a.check))throw new Re('check with a custom "when" condition');switch(a.check){case"greater_than":dfe(t,e,a,i);break;case"less_than":pfe(t,e,a,i);break;case"multiple_of":ffe(t,e,a,i);break;case"number_format":VV(t,a,i);break;case"min_length":{let c=Ka(a.minimum,"min_length"),u=OR(t,e,i,`${i}.length >= ${c} && ${i}.length < ${a.minimum*2}`);t.write(`if (${u} < ${c}) return INVALID;`);break}case"max_length":{let c=Ka(a.maximum,"max_length"),u=OR(t,e,i,`${i}.length > ${c}`);t.write(`if (${u} > ${c}) return INVALID;`);break}case"length_equals":{let c=Ka(a.length,"length_equals"),u=OR(t,e,i,`${i}.length >= ${c} && ${i}.length <= ${a.length*2}`);t.write(`if (${u} !== ${c}) return INVALID;`);break}case"min_size":t.write(`if (${i}.size < ${Ka(a.minimum,"min_size")}) return INVALID;`);break;case"max_size":t.write(`if (${i}.size > ${Ka(a.maximum,"max_size")}) return INVALID;`);break;case"size_equals":t.write(`if (${i}.size !== ${Ka(a.size,"size_equals")}) return INVALID;`);break;case"string_format":i=HV(t,e,a,i);break;case"custom":i=wfe(t,e,s,i);break;case"bigint_format":mfe(t,a,i);break;case"mime_type":hfe(t,e,a,i);break;case"property":yfe(t,e,a,i);break;case"properties":gfe(t,e,a,i);break;case"overwrite":{let c=ee(e);vfe(t,e,s,i,c),i=c;break}default:throw new Re(`check type ${a.check}`)}}return i}function OR(t,e,r,o){let n=ne(e,Nu),i=ee(e);return t.write(`const ${i} = typeof ${r} === "string" && ${o} ? ${n}(${r}) : ${r}.length;`),i}function Ka(t,e){if(typeof t!="number"||!Number.isFinite(t))throw new Re(`${e} bound of type ${typeof t}`);return`${t}`}function FV(t,e){if(typeof e=="bigint")return`${e}n`;if(typeof e=="number"){if(Number.isNaN(e))throw new Re("comparison check with NaN bound");return`${e}`}if(e instanceof Date){if(Number.isNaN(e.getTime()))throw new Re("comparison check with Invalid Date bound");return ne(t,e)}throw new Re(`comparison check bound of type ${typeof e}`)}function dfe(t,e,r,o){let n=r.inclusive?"<":"<=";t.write(`if (${o} ${n} ${FV(e,r.value)}) return INVALID;`)}function pfe(t,e,r,o){let n=r.inclusive?">":">=";t.write(`if (${o} ${n} ${FV(e,r.value)}) return INVALID;`)}function ffe(t,e,r,o){if(typeof r.value=="bigint"){if(r.value===BigInt(0))throw new Re("multiple_of check with a zero divisor");t.write(`if (${o} % ${r.value}n !== 0n) return INVALID;`)}else{let n=ne(e,Zm);t.write(`if (${n}(${o}, ${Ka(r.value,"multiple_of")}) !== 0) return INVALID;`)}}function VV(t,e,r){let o=e.format;switch(o){case"safeint":t.write(`if (!Number.isSafeInteger(${r})) return INVALID;`);break;case"int32":t.write(`if (!Number.isInteger(${r}) || ${r} < -2147483648 || ${r} > 2147483647) return INVALID;`);break;case"uint32":t.write(`if (!Number.isInteger(${r}) || ${r} < 0 || ${r} > 4294967295) return INVALID;`);break;case"float32":t.write(`if (!Number.isFinite(${r}) || ${r} < -3.4028234663852886e38 || ${r} > 3.4028234663852886e38) return INVALID;`);break;case"float64":t.write(`if (!Number.isFinite(${r})) return INVALID;`);break;default:throw new Re(`number format ${o}`)}}function mfe(t,e,r){let o=e.format;if(o)switch(o){case"int64":t.write(`if (${r} < -9223372036854775808n || ${r} > 9223372036854775807n) return INVALID;`);break;case"uint64":t.write(`if (${r} < 0n || ${r} > 18446744073709551615n) return INVALID;`);break;default:throw new Re(`bigint format ${o}`)}}function hfe(t,e,r,o){let n=r.mime;if(n&&n.length>0){let i=ne(e,new Set(n));t.write(`if (!${i}.has(${o}.type)) return INVALID;`)}}function gfe(t,e,r,o){if(r.when)throw new Re('check with a custom "when" condition');t.write(`if (${o} == null) return INVALID;`);let n=r.shape;for(let i of Reflect.ownKeys(n)){let s=typeof i=="symbol"?ne(e,i):cn(i),a=ee(e);t.write(`const ${a} = ${o}[${s}];`),Hr(t,e,n[i],a,!1)}}function yfe(t,e,r,o){let n=`${o}[${JSON.stringify(r.property)}]`;Pt(t,e,r.schema,n)}function vfe(t,e,r,o,n){let i=r._zod.def.tx;if(!i)throw new Re("overwrite check without a transform function");if(Fu(i))throw new ti("z.compile: async overwrite transforms are not supported");let s=ne(e,i);t.write(`const ${n} = ${s}(${o});`)}function NR(){throw new An}function jR(t){this.issues.push(t)}function wfe(t,e,r,o){let n=r._zod.def;if(n.fn){if(Fu(n.fn))throw new ti("z.compile: async .refine() predicates are not supported");let i=Lu(e,n.fn),s=ne(e,NR),a=ee(e);return t.write(`const ${a} = ${i}(${o});`),t.write(`if (${a} instanceof Promise) ${s}();`),t.write(`if (!${a}) return INVALID;`),o}if(r._zod.check){if(Fu(r._zod.check))throw new ti("z.compile: async .superRefine() / check functions are not supported");let i=r._zod.check,a=Lu(e,u=>{let l={value:u,issues:[],addIssue:jR};return i(l)instanceof Promise&&NR(),l.issues.length===0?l.value:ln}),c=ee(e);return t.write(`const ${c} = ${a}(${o});`),t.write(`if (${c} === INVALID) return INVALID;`),c}throw new Re("custom check without a predicate or check function")}var bfe=new Set(["cidrv4","cuid","cuid2","date","datetime","duration","e164","email","emoji","ends_with","guid","includes","ipv4","ksuid","lowercase","mac","nanoid","regex","starts_with","time","ulid","uppercase","uuid","xid"]);function HV(t,e,r,o,n=!0){let i=r.format;if(i==="base64"){let u=ne(e,lh);return t.write(`if (!${u}(${o})) return INVALID;`),o}if(i==="base64url"){let u=ne(e,Xb);return t.write(`if (!${u}(${o})) return INVALID;`),o}if(i==="jwt"){let u=ne(e,o_),l=ne(e,r.alg??null);return t.write(`if (!${u}(${o}, ${l})) return INVALID;`),o}if(i==="ipv6"){let u=ne(e,uh);return t.write(`if (!${u}(${o})) return INVALID;`),o}if(i==="cidrv6"){let u=ne(e,Zb);return t.write(`if (!${u}(${o})) return INVALID;`),o}if(i==="credit_card"){let u=ne(e,e_);return t.write(`if (!${u}(${o})) return INVALID;`),o}if(i==="iban"){let u=ne(e,r_);return t.write(`if (!${u}(${o})) return INVALID;`),o}let s=r;if(i==="url"||i==="httpurl"||s.normalize||s.hostname!==void 0||s.protocol!==void 0){let u=ne(e,Cb),l=ne(e,r),d=ee(e),f=ee(e);if(t.write(`const ${d} = ${o}.trim();`),t.write(`const ${f} = ${u}(${d}, ${l});`),t.write(`if (typeof ${f} === "number") return INVALID;`),s.hostname!==void 0){let g=ne(e,Ob);t.write(`if (!${g}(${f}, ${l}.hostname)) return INVALID;`)}if(s.protocol!==void 0){let g=ne(e,Nb);t.write(`if (!${g}(${f}, ${l}.protocol)) return INVALID;`)}if(!n)return null;let p=ee(e),m=s.normalize?`${f}.href`:`${ne(e,ch)}(${d})`;return t.write(`const ${p} = ${m};`),p}let a=r.fn;if(a){if(Fu(a))throw new Re(`async string format ${i}`);let u=ne(e,a);return t.write(`if (!${u}(${o})) return INVALID;`),o}if(bfe.has(i)&&r.pattern){let u=ne(e,r.pattern);return t.write(`${u}.lastIndex = 0;`),t.write(`if (!${u}.test(${o})) return INVALID;`),o}let c=r.format;switch(c){case"regex":throw new Re("regex format without a pattern");case"lowercase":t.write(`if (${o} !== ${o}.toLowerCase()) return INVALID;`);break;case"uppercase":t.write(`if (${o} !== ${o}.toUpperCase()) return INVALID;`);break;case"includes":t.write(`if (!${o}.includes(${cn(r.includes)})) return INVALID;`);break;case"starts_with":{let u=r.prefix;t.write(`if (${o}.slice(0, ${u.length}) !== ${cn(u)}) return INVALID;`);break}case"ends_with":{let u=r.suffix;t.write(`if (${o}.slice(-${u.length}) !== ${cn(u)}) return INVALID;`);break}default:throw new Re(`string format ${c}`)}return o}function Pt(t,e,r,o,n=!0){let i=r._zod.def,s=i.type;if(i.coerce)throw new Re(`coercion (z.coerce.${s}())`);let a=n||!!i.checks?.length,c;switch(s){case"string":c=_fe(t,e,r,o,a);break;case"number":c=Sfe(t,r,o);break;case"boolean":c=xfe(t,o);break;case"bigint":c=Efe(t,r,o);break;case"symbol":c=kfe(t,o);break;case"undefined":c=Ife(t,o);break;case"null":c=$fe(t,o);break;case"any":case"unknown":c=o;break;case"never":t.write("return INVALID;"),c=o;break;case"void":c=Afe(t,o);break;case"nan":c=Tfe(t,o);break;case"date":c=Pfe(t,o);break;case"object":c=Rfe(t,e,r,o,a);break;case"optional":c=Cfe(t,e,r,o,a);break;case"nullable":c=Dfe(t,e,r,o,a);break;case"array":c=zfe(t,e,r,o,a);break;case"literal":c=jfe(t,e,r,o);break;case"enum":c=Mfe(t,e,r,o);break;case"readonly":{let u=MV(t,e,r,o),l=ee(e);t.write(`const ${l} = Object.freeze(${u});`),c=l;break}case"success":MV(t,e,r,o),c="true";break;case"default":case"prefault":c=Ufe(t,e,r,o);break;case"nonoptional":c=Lfe(t,e,r,o);break;case"tuple":c=Ffe(t,e,r,o);break;case"union":c=Vfe(t,e,r,o);break;case"intersection":c=Kfe(t,e,r,o);break;case"record":c=qfe(t,e,r,o);break;case"map":c=Wfe(t,e,r,o);break;case"set":c=Jfe(t,e,r,o);break;case"file":c=Gfe(t,o);break;case"template_literal":c=Xfe(t,e,r,o);break;case"lazy":c=Yfe(t,e,r,o);break;case"pipe":c=Qfe(t,e,r,o);break;case"custom":c=eme(t,e,r,o);break;case"transform":c=nme(t,e,r,o);break;case"catch":c=rme(t,e,r,o);break;default:throw new Re(`schema type ${s}`)}return c===null?null:lfe(t,e,r,c)}function _fe(t,e,r,o,n=!0){t.write(`if (typeof ${o} !== "string") return INVALID;`);let i=r._zod.def;return i.format===void 0?o:HV(t,e,i,o,n)}function Sfe(t,e,r){t.write(`if (typeof ${r} !== "number" || !Number.isFinite(${r})) return INVALID;`);let o=e._zod.def;return o.check==="number_format"&&o.format&&VV(t,{format:o.format},r),r}function xfe(t,e){return t.write(`if (typeof ${e} !== "boolean") return INVALID;`),e}function Efe(t,e,r){t.write(`if (typeof ${r} !== "bigint") return INVALID;`);let o=e._zod.def;if(o.format)switch(o.format){case"int64":t.write(`if (${r} < -9223372036854775808n || ${r} > 9223372036854775807n) return INVALID;`);break;case"uint64":t.write(`if (${r} < 0n || ${r} > 18446744073709551615n) return INVALID;`);break}return r}function kfe(t,e){return t.write(`if (typeof ${e} !== "symbol") return INVALID;`),e}function Ife(t,e){return t.write(`if (${e} !== undefined) return INVALID;`),e}function $fe(t,e){return t.write(`if (${e} !== null) return INVALID;`),e}function Afe(t,e){return t.write(`if (${e} !== undefined) return INVALID;`),e}function Tfe(t,e){return t.write(`if (typeof ${e} !== "number" || !Number.isNaN(${e})) return INVALID;`),e}function Pfe(t,e){return t.write(`if (!(${e} instanceof Date) || Number.isNaN(${e}.getTime())) return INVALID;`),e}function Rfe(t,e,r,o,n=!0){let i=r._zod.def;t.write(`if (typeof ${o} !== "object" || ${o} === null || Array.isArray(${o})) return INVALID;`);let s=i.shape,a=Object.keys(s),c=Object.getOwnPropertySymbols(s),u=c.length?[...a,...c]:a,l=b=>typeof b=="symbol"?ne(e,b):cn(b),d=b=>typeof b=="symbol"?`[${l(b)}]`:cn(b),f=s;if(a.includes("__proto__"))throw new Re('object shape key "__proto__"');let p=new Map;for(let b of u){let _=f[b],k=l(b),$=ee(e);if(t.write(`const ${$} = ${o}[${k}];`),_._zod.optin!==void 0){let D=ee(e);t.write(`let ${D} = (() => {`),t.indented(K=>{let te=Hr(K,e,_,$);K.write(`return ${te};`)}),t.write("})();"),_._zod.optout==="optional"?(t.write(`if (${D} === INVALID) {`),t.indented(K=>{K.write(`if (${k} in ${o}) return INVALID;`),K.write(`${D} = undefined;`)}),t.write("}")):t.write(`if (${D} === INVALID) return INVALID;`),p.set(b,D)}else{Nfe(_)&&t.write(`if (!(${k} in ${o})) return INVALID;`);let D=Hr(t,e,_,$,n);D!==null&&p.set(b,D)}}let m=i.catchall,g="none";if(m){let b=m._zod.def.type;if(b==="never"){let _=a.map(k=>`k !== ${cn(k)}`).join(" && ")||"true";t.write(`for (const k in ${o}) {`),t.indented(k=>{k.write(`if (${_}) return INVALID;`)}),t.write("}")}else(b==="unknown"||b==="any")&&!m._zod.def.checks?.length?g="passthrough":g="schema"}let y=ee(e),w=u.some(b=>jV(f[b])||DR(f[b]));if(!n){if(g==="schema"){let b=a.length>0?ne(e,new Set(a)):null;t.write(`for (const k in ${o}) {`),t.indented(_=>{_.write('if (k === "__proto__") continue;'),b&&_.write(`if (${b}.has(k)) continue;`);let k=ee(e);_.write(`const ${k} = ${o}[k];`),Hr(_,e,m,k,!1)}),t.write("}")}return null}if(w){t.write(`const ${y} = {};`);for(let b of u){let _=l(b),k=p.get(b);DR(f[b])?t.write(`if (${_} in ${o}) ${y}[${_}] = ${k};`):jV(f[b])?t.write(`if (${k} !== undefined || ${_} in ${o}) ${y}[${_}] = ${k};`):t.write(`${y}[${_}] = ${k};`)}}else{let b=u.map(_=>`${d(_)}: ${p.get(_)}`).join(", ");t.write(`const ${y} = { ${b} };`)}if(g!=="none"){let b=a.length>0?ne(e,new Set(a)):null;t.write(`for (const k in ${o}) {`),t.indented(_=>{if(_.write('if (k === "__proto__") continue;'),b&&_.write(`if (${b}.has(k)) continue;`),g==="passthrough")_.write(`${y}[k] = ${o}[k];`);else{let k=ee(e);_.write(`const ${k} = ${o}[k];`);let $=Hr(_,e,m,k);_.write(`${y}[k] = ${$};`)}}),t.write("}")}return y}function Cfe(t,e,r,o,n=!0){let i=r._zod.def;if(Ofe(r))return Pt(t,e,i.innerType,o,n);if(i.innerType._zod.optin==="defaulted"){let a=ee(e),c=ee(e);return t.write(`let ${a};`),t.write(`if (${o} === undefined) {`),t.indented(u=>{u.write(`const ${c} = (() => {`),u.indented(l=>{let d=Pt(l,e,i.innerType,o);l.write(`return ${d};`)}),u.write("})();"),u.write(`if (${c} !== INVALID) ${a} = ${c};`)}),t.write("} else {"),t.indented(u=>{let l=Pt(u,e,i.innerType,o);u.write(`${a} = ${l};`)}),t.write("}"),a}let s=n?ee(e):null;return s&&t.write(`let ${s};`),t.write(`if (${o} !== undefined) {`),t.indented(a=>{let c=Pt(a,e,i.innerType,o,n);s&&c!==null&&a.write(`${s} = ${c};`)}),t.write("}"),s}function Ofe(t){return t._zod.traits?.has("$ZodExactOptional")===!0}function Nfe(t){return t._zod.optin===void 0&&Uu(t)}function Uu(t){if(t._zod.def.coerce)return!0;let e=t._zod.def;switch(e.type){case"any":case"unknown":case"undefined":case"void":case"default":case"prefault":case"transform":case"custom":case"lazy":return!0;case"string":case"number":case"boolean":case"bigint":case"symbol":case"null":case"never":case"nan":case"date":case"object":case"array":case"tuple":case"record":case"map":case"set":case"file":case"template_literal":return!1;case"nonoptional":return e.innerType?Uu(e.innerType):!1;case"literal":return!!e.values?.includes(void 0);case"enum":return!!t._zod.values?.has(void 0);case"optional":case"nullable":case"readonly":case"success":return e.innerType?Uu(e.innerType):!0;case"catch":return!0;case"union":return e.options?e.options.some(Uu):!0;case"intersection":return!e.left||!e.right?!0:Uu(e.left)&&Uu(e.right);case"pipe":return e.in?Uu(e.in):!0;default:return!0}}function DR(t){return t._zod.optin==="optional"&&t._zod.optout==="optional"}function jV(t){return(t._zod.optin!=="defaulted"||t._zod.optout==="optional")&&Nd(t)}function Nd(t){let e=t._zod.def;switch(e.type){case"string":case"number":case"boolean":case"bigint":case"symbol":case"null":case"nan":case"date":case"object":case"array":case"tuple":case"record":case"map":case"set":case"file":case"template_literal":case"never":case"success":return!1;case"literal":return!!e.values?.includes(void 0);case"enum":return!!t._zod.values?.has(void 0);case"optional":return!0;case"nullable":case"readonly":case"nonoptional":return e.innerType?Nd(e.innerType):!0;case"union":return e.options?e.options.some(Nd):!0;case"intersection":return!e.left||!e.right||Nd(e.left)||Nd(e.right);case"pipe":return e.out?Nd(e.out):!0;default:return!0}}function Dfe(t,e,r,o,n=!0){let i=r._zod.def,s=n?ee(e):null;return s&&t.write(`let ${s} = null;`),t.write(`if (${o} !== null) {`),t.indented(a=>{let c=Pt(a,e,i.innerType,o,n);s&&c!==null&&a.write(`${s} = ${c};`)}),t.write("}"),s}function MR(t,e,r){for(let[o,n]of hd(e._zod.def.checks))t.write(`if (${r} > ${Ka(o,n._zod.def.check)}) return INVALID;`)}function zfe(t,e,r,o,n=!0){let i=r._zod.def;t.write(`if (!Array.isArray(${o})) return INVALID;`),MR(t,r,`${o}.length`);let s=n?ee(e):null,a=ee(e),c=ee(e);return s&&t.write(`const ${s} = new Array(${o}.length);`),t.write(`for (let ${a} = 0; ${a} < ${o}.length; ${a}++) {`),t.indented(u=>{u.write(`const ${c} = ${o}[${a}];`);let l=Hr(u,e,i.element,c,n);s&&l!==null&&u.write(`${s}[${a}] = ${l};`)}),t.write("}"),s}function jfe(t,e,r,o){let i=r._zod.def.values;if(i.length!==1){let a=ne(e,new Set(i));return t.write(`if (!${a}.has(${o})) return INVALID;`),o}let s=i[0];if(typeof s=="number"&&Number.isNaN(s)){let a=ne(e,new Set(i));return t.write(`if (!${a}.has(${o})) return INVALID;`),o}if(typeof s=="string")t.write(`if (${o} !== ${cn(s)}) return INVALID;`);else if(typeof s=="number"||typeof s=="boolean")t.write(`if (${o} !== ${s}) return INVALID;`);else if(s===null)t.write(`if (${o} !== null) return INVALID;`);else if(s===void 0)t.write(`if (${o} !== undefined) return INVALID;`);else if(typeof s=="bigint")t.write(`if (${o} !== ${s}n) return INVALID;`);else throw new Re(`literal type ${typeof s}`);return o}function Mfe(t,e,r,o){let n=r._zod.values;if(!n)throw new Re("enum schema without enumerated values");let i=ne(e,n);return t.write(`if (!${i}.has(${o})) return INVALID;`),o}function MV(t,e,r,o){let n=r._zod.def;return Pt(t,e,n.innerType,o)}function Ufe(t,e,r,o){let n=r._zod.def,s=Object.getOwnPropertyDescriptor(r._zod.def,"defaultValue")?()=>r._zod.def.defaultValue:void 0;if(r._zod.def.type==="prefault"){if(!s)return Pt(t,e,n.innerType,o);let c=ne(e,s),u=ee(e);return t.write(`let ${u} = ${o};`),t.write(`if (${o} === undefined) ${u} = ${c}();`),Pt(t,e,n.innerType,u)}let a=ee(e);if(s){let c=ne(e,s),u=ne(e,md);t.write(`let ${a};`),t.write(`if (${o} === undefined) {`),t.indented(l=>{l.write(`${a} = ${u}(${c}());`)}),t.write("} else {"),t.indented(l=>{let d=Pt(l,e,n.innerType,o);l.write(`${a} = ${d} === undefined ? ${u}(${c}()) : ${d};`)}),t.write("}")}else t.write(`let ${a};`),t.write(`if (${o} !== undefined) {`),t.indented(c=>{let u=Pt(c,e,n.innerType,o);c.write(`${a} = ${u};`)}),t.write("}");return a}function Lfe(t,e,r,o){let n=r._zod.def,i=Pt(t,e,n.innerType,o),s=ee(e);return t.write(`const ${s} = ${i};`),t.write(`if (${s} === undefined) return INVALID;`),s}function Ffe(t,e,r,o){let n=r._zod.def,i=n.items,s=n.rest;t.write(`if (!Array.isArray(${o})) return INVALID;`);let a=UV(i,"optin"),c=UV(i,"optout");s?t.write(`if (${o}.length < ${a}) return INVALID;`):t.write(`if (${o}.length < ${a} || ${o}.length > ${i.length}) return INVALID;`);let u=ee(e);t.write(`const ${u} = [];`);for(let l=0;l<i.length;l++){let d=i[l];if(l>=c)t.write(`if (${u}.length === ${l}) {`),t.indented(f=>{f.write(`if (${l} < ${o}.length) {`),f.indented(p=>{let m=ee(e);p.write(`const ${m} = ${o}[${l}];`);let g=Hr(p,e,d,m);p.write(`${u}[${l}] = ${g};`)}),f.write("} else {"),f.indented(p=>{if(DR(d)){p.write(`${u}.length = ${l};`);return}let m=ee(e),g=ee(e);p.write(`const ${m} = undefined;`),p.write(`const ${g} = (() => {`),p.indented(y=>{let w=Hr(y,e,d,m);y.write(`return ${w};`)}),p.write("})();"),p.write(`if (${g} === INVALID || ${g} === undefined) ${u}.length = ${l};`),p.write(`else ${u}[${l}] = ${g};`)}),f.write("}")}),t.write("}");else{let f=ee(e);t.write(`const ${f} = ${o}[${l}];`);let p=Hr(t,e,d,f);t.write(`${u}[${l}] = ${p};`)}}if(s){let l=ee(e),d=ee(e);t.write(`for (let ${l} = ${i.length}; ${l} < ${o}.length; ${l}++) {`),t.indented(f=>{f.write(`const ${d} = ${o}[${l}];`);let p=Hr(f,e,s,d);f.write(`${u}[${l}] = ${p};`)}),t.write("}")}return u}function UV(t,e){for(let r=t.length-1;r>=0;r--)if(!(e==="optin"?t[r]._zod.optin!==void 0:t[r]._zod.optout==="optional"))return r+1;return 0}function Vfe(t,e,r,o){let n=r._zod.def,i=n.options;if(n.discriminator)return Hfe(t,e,n,o);if(n.inclusive===!1)throw new Re("exclusive unions (z.xor)");if(i.length===0)return t.write("return INVALID;"),o;if(i.length===1)return Pt(t,e,i[0],o);if(i.every(c=>c._zod.def.type==="literal"&&!c._zod.def.checks?.length)){let c=new Set(i.flatMap(l=>l._zod.def.values)),u=ne(e,c);return t.write(`if (!${u}.has(${o})) return INVALID;`),o}let a=ee(e);t.write(`let ${a};`);for(let c=0;c<i.length;c++){let u=i[c];c===0?t.write(`${a} = (() => {`):t.write(`if (${a} === INVALID) ${a} = (() => {`),t.indented(l=>{let d=Pt(l,e,u,o);l.write(`return ${d};`)}),t.write("})();")}return t.write(`if (${a} === INVALID) return INVALID;`),a}function Hfe(t,e,r,o){if(r.unionFallback)throw new Re("discriminated union with unionFallback");if(r.options.length===0)return t.write("return INVALID;"),o;let n=ee(e),i=ee(e);t.write(`const ${n} = ${o}?.[${cn(r.discriminator)}];`),t.write(`let ${i};`);let s=!0,a=new Set;for(let c of r.options){let u=c._zod.propValues?.[r.discriminator];if(!u||u.size===0)throw new Re("discriminated union option without static discriminator values");for(let f of u){if(a.has(f))throw new Re(`duplicate discriminator value ${String(f)}`);a.add(f)}let l=Array.from(u,f=>Bfe(e,n,f)),d=s?"if":"else if";t.write(`${d} (${l.join(" || ")}) {`),t.indented(f=>{let p=Pt(f,e,c,o);f.write(`${i} = ${p};`)}),t.write("}"),s=!1}return t.write("else { return INVALID; }"),i}function Bfe(t,e,r){if(typeof r=="string")return`${e} === ${cn(r)}`;if(typeof r=="number")return Number.isNaN(r)?`Number.isNaN(${e})`:`${e} === ${r}`;if(typeof r=="boolean")return`${e} === ${r}`;if(r===null)return`${e} === null`;if(r===void 0)return`${e} === undefined`;if(typeof r=="bigint")return`${e} === ${r}n`;if(typeof r=="symbol"){let o=ne(t,r);return`${e} === ${o}`}throw new Re(`literal discriminator value ${String(r)}`)}function Kfe(t,e,r,o){let n=r._zod.def;e.definite=!1;let i=Hr(t,e,n.left,o),s=Hr(t,e,n.right,o),a=ne(e,Id),c=ee(e);return t.write(`const ${c} = ${a}(${i}, ${s});`),t.write(`if (!${c}.valid) return INVALID;`),`${c}.data`}function qfe(t,e,r,o){let n=r._zod.def,i=ne(e,yo);t.write(`if (!${i}(${o})) return INVALID;`);let s=ee(e),a=ee(e),c=ee(e);t.write(`const ${s} = {};`);let u=n,l=u.partial?void 0:n.keyType._zod.values;if(l){let p=[];for(let g of l){if(!(typeof g=="string"||typeof g=="number"||typeof g=="symbol"))throw new Re(`record key value ${String(g)}`);let y=typeof g=="number"?g.toString():g;if(y==="__proto__")throw new Re('record key "__proto__"');p.push(y);let w=ne(e,g),b=Pt(t,e,n.keyType,w),_=ee(e);t.write(`const ${_} = ${o}[${Zfe(e,y)}];`);let k=Hr(t,e,n.valueType,_);t.write(`${s}[${b}] = ${k};`)}let m=ne(e,new Set(p));return t.write(`for (const ${a} in ${o}) {`),t.indented(g=>{g.write(`if (${m}.has(${a})) continue;`),u.mode==="loose"?g.write(`if (${a} !== "__proto__") ${s}[${a}] = ${o}[${a}];`):g.write("return INVALID;")}),t.write("}"),s}let d=n.keyType._zod.def;if(!(d.type==="string"&&d.format===void 0&&!d.coerce&&(d.checks?.length??0)===0)){let p=n.mode==="loose",m=eS(n.keyType);m.definite===!1&&(e.definite=!1);let g=ne(e,m),y=ne(e,ra),w=ee(e);return LV(t,e,o,a,b=>{b.write(`let ${w} = ${g}(${a});`),b.write(`if (${w} === INVALID && typeof ${a} === "string" && ${y}.test(${a})) ${w} = ${g}(Number(${a}));`),p?b.write(`if (${w} === INVALID) { ${s}[${a}] = ${o}[${a}]; continue; }`):b.write(`if (${w} === INVALID) return INVALID;`),b.write(`if (${w} === "__proto__") continue;`);let _=ee(e);b.write(`const ${_} = ${o}[${a}];`);let k=Hr(b,e,n.valueType,_);b.write(`${s}[${w}] = ${k};`)}),s}return LV(t,e,o,a,p=>{p.write(`const ${c} = ${o}[${a}];`);let m=Hr(p,e,n.valueType,c);p.write(`${s}[${a}] = ${m};`)},"return INVALID;"),s}function LV(t,e,r,o,n,i){let s=ne(e,Object.prototype.propertyIsEnumerable),a=ee(e),c=ee(e),u=ee(e);t.write(`const ${a} = Object.getOwnPropertySymbols(${r});`),t.write(`const ${c} = Object.getOwnPropertyNames(${r});`),t.write(`for (let ${u} = 0; ${u} < ${c}.length; ${u}++) {`),t.indented(l=>{l.write(`const ${o} = ${c}[${u}];`),l.write(`if (${o} === "__proto__" || !${s}.call(${r}, ${o})) continue;`),n(l)}),t.write("}"),t.write(`for (let ${u} = 0; ${u} < ${a}.length; ${u}++) {`),t.indented(l=>{l.write(`const ${o} = ${a}[${u}];`),l.write(`if (!${s}.call(${r}, ${o})) continue;`),i?l.write(i):n(l)}),t.write("}")}function Zfe(t,e){return typeof e=="string"?cn(e):ne(t,e)}function Wfe(t,e,r,o){let n=r._zod.def;t.write(`if (!(${o} instanceof Map)) return INVALID;`),MR(t,r,`${o}.size`);let i=ee(e),s=ee(e),a=ee(e);return t.write(`const ${i} = new Map();`),t.write(`for (const [${s}, ${a}] of ${o}) {`),t.indented(c=>{let u=Pt(c,e,n.keyType,s),l=Pt(c,e,n.valueType,a);c.write(`${i}.set(${u}, ${l});`)}),t.write("}"),i}function Jfe(t,e,r,o){let n=r._zod.def;t.write(`if (!(${o} instanceof Set)) return INVALID;`),MR(t,r,`${o}.size`);let i=ee(e),s=ee(e);return t.write(`const ${i} = new Set();`),t.write(`for (const ${s} of ${o}) {`),t.indented(a=>{let c=Pt(a,e,n.valueType,s);a.write(`${i}.add(${c});`)}),t.write("}"),i}function Gfe(t,e){return t.write(`if (!(${e} instanceof File)) return INVALID;`),e}function Xfe(t,e,r,o){t.write(`if (typeof ${o} !== "string") return INVALID;`);let n=r._zod.pattern;if(n){let i=ne(e,n);t.write(`${i}.lastIndex = 0;`),t.write(`if (!${i}.test(${o})) return INVALID;`)}return o}function Yfe(t,e,r,o){let n=r._zod.def,i=Lu(e,n.getter),s=ne(e,{parser:null});t.write(`if (!${s}.parser) {`),t.indented(c=>{c.write(`const inner = ${i}();`),c.write(`${s}.parser = function(input) {`),c.indented(u=>{u.write("const result = inner._zod.run({ value: input, issues: [] }, {});"),u.write("return result.issues.length === 0 ? result.value : INVALID;")}),c.write("};")}),t.write("}");let a=ee(e);return t.write(`const ${a} = ${s}.parser(${o});`),t.write(`if (${a} === INVALID) return INVALID;`),a}function Qfe(t,e,r,o){let n=r._zod.def,i=Pt(t,e,n.in,o);if(n.transform){if(Fu(n.transform))throw new ti("z.compile: async transforms in pipes are not supported");let s=n.transform,c=Lu(e,l=>{let d={value:l,issues:[],addIssue:jR},f=s(l,d);return f instanceof Promise?ln:d.issues.length===0?f:ln}),u=ee(e);return t.write(`const ${u} = ${c}(${i});`),t.write(`if (${u} === INVALID) return INVALID;`),Pt(t,e,n.out,u)}else return Pt(t,e,n.out,i)}function Fu(t){return typeof t=="function"&&(t.constructor.name==="AsyncFunction"||t[Symbol.toStringTag]==="AsyncFunction")}function eme(t,e,r,o){let n=r._zod.def;if(n.fn){if(Fu(n.fn))throw new ti("z.compile: async custom predicates are not supported");let i=Lu(e,n.fn),s=ne(e,NR),a=ee(e);t.write(`const ${a} = ${i}(${o});`),t.write(`if (${a} instanceof Promise) ${s}();`),t.write(`if (!${a}) return INVALID;`)}else throw new Re("custom schema without a predicate function");return o}function tme(t,e,r){let o=t._zod.run({value:r,issues:[]},{});if(o&&typeof o.then=="function")return ln;let n=o;return n.issues.length===0?n.value:e()}function rme(t,e,r,o){let n=r._zod.def;if(!n.catchValue[cb])throw new Re("catch with a callback (only a constant catch value compiles)",!1);let i=ee(e);t.write(`let ${i} = (() => {`),t.indented(u=>{let l=Hr(u,e,n.innerType,o);u.write(`return ${l};`)}),t.write("})();");let s=ne(e,n.innerType),a=Lu(e,n.catchValue),c=ne(e,tme);return t.write(`if (${i} === INVALID) {`),t.indented(u=>{u.write(`${i} = ${c}(${s}, ${a}, ${o});`),u.write(`if (${i} === INVALID) return INVALID;`)}),t.write("}"),i}function nme(t,e,r,o){let n=r._zod.def;if(n.transform){if(Fu(n.transform))throw new ti("z.compile: async transforms are not supported");let i=n.transform,a=Lu(e,u=>{let l={value:u,issues:[],addIssue:jR},d=i(u,l);return d instanceof Promise?ln:l.issues.length===0?d:ln}),c=ee(e);return t.write(`const ${c} = ${a}(${o});`),t.write(`if (${c} === INVALID) return INVALID;`),c}return o}function tS(t){return t.checks&&(t.checks=[...t.checks]),t}function rS(t,e){return new t(tS({type:"string",...N(e)}))}function UR(t,e){return new t(tS({type:"string",coerce:!0,...N(e)}))}function _h(t,e){return new t({type:"string",format:"email",check:"string_format",abort:!1,...N(e)})}function Sh(t,e){return new t({type:"string",format:"guid",check:"string_format",abort:!1,...N(e)})}function xh(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,...N(e)})}function Eh(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...N(e)})}function kh(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...N(e)})}function Ih(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...N(e)})}function Dd(t,e){return new t({type:"string",format:"url",check:"string_format",abort:!1,...N(e)})}function $h(t,e){return new t({type:"string",format:"emoji",check:"string_format",abort:!1,...N(e)})}function Ah(t,e){return new t({type:"string",format:"nanoid",check:"string_format",abort:!1,...N(e)})}function Th(t,e){return new t({type:"string",format:"cuid",check:"string_format",abort:!1,...N(e)})}function Ph(t,e){return new t({type:"string",format:"cuid2",check:"string_format",abort:!1,...N(e)})}function Rh(t,e){return new t({type:"string",format:"ulid",check:"string_format",abort:!1,...N(e)})}function Ch(t,e){return new t({type:"string",format:"xid",check:"string_format",abort:!1,...N(e)})}function Oh(t,e){return new t({type:"string",format:"ksuid",check:"string_format",abort:!1,...N(e)})}function Nh(t,e){return new t({type:"string",format:"ipv4",check:"string_format",abort:!1,...N(e)})}function Dh(t,e){return new t({type:"string",format:"ipv6",check:"string_format",abort:!1,...N(e)})}function nS(t,e){return new t({type:"string",format:"mac",check:"string_format",abort:!1,...N(e)})}function zh(t,e){return new t({type:"string",format:"cidrv4",check:"string_format",abort:!1,...N(e)})}function jh(t,e){return new t({type:"string",format:"cidrv6",check:"string_format",abort:!1,...N(e)})}function Mh(t,e){return new t({type:"string",format:"base64",check:"string_format",abort:!1,...N(e)})}function Uh(t,e){return new t({type:"string",format:"base64url",check:"string_format",abort:!1,...N(e)})}function Lh(t,e){return new t({type:"string",format:"e164",check:"string_format",abort:!1,...N(e)})}function oS(t,e){return new t({type:"string",format:"credit_card",check:"string_format",abort:!1,...N(e)})}function iS(t,e){return new t({type:"string",format:"iban",check:"string_format",abort:!1,...N(e)})}function Fh(t,e){return new t({type:"string",format:"jwt",check:"string_format",abort:!1,...N(e)})}var LR={Any:null,Minute:-1,Second:0,Millisecond:3,Microsecond:6};function Vh(t,e){return new t({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...N(e)})}function Hh(t,e){return new t({type:"string",format:"date",check:"string_format",...N(e)})}function Bh(t,e){return new t({type:"string",format:"time",check:"string_format",precision:null,...N(e)})}function Kh(t,e){return new t({type:"string",format:"duration",check:"string_format",...N(e)})}function sS(t,e){return new t(tS({type:"number",checks:[],...N(e)}))}function FR(t,e){return new t(tS({type:"number",coerce:!0,checks:[],...N(e)}))}function aS(t,e){return new t({type:"number",check:"number_format",abort:!1,format:"safeint",...N(e)})}function cS(t,e){return new t({type:"number",check:"number_format",abort:!1,format:"float32",...N(e)})}function uS(t,e){return new t({type:"number",check:"number_format",abort:!1,format:"float64",...N(e)})}function lS(t,e){return new t({type:"number",check:"number_format",abort:!1,format:"int32",...N(e)})}function dS(t,e){return new t({type:"number",check:"number_format",abort:!1,format:"uint32",...N(e)})}function pS(t,e){return new t({type:"boolean",...N(e)})}function VR(t,e){return new t({type:"boolean",coerce:!0,...N(e)})}function fS(t,e){return new t({type:"bigint",...N(e)})}function HR(t,e){return new t({type:"bigint",coerce:!0,...N(e)})}function mS(t,e){return new t({type:"bigint",check:"bigint_format",abort:!1,format:"int64",...N(e)})}function hS(t,e){return new t({type:"bigint",check:"bigint_format",abort:!1,format:"uint64",...N(e)})}function gS(t,e){return new t({type:"symbol",...N(e)})}function yS(t,e){return new t({type:"undefined",...N(e)})}function vS(t,e){return new t({type:"null",...N(e)})}function wS(t){return new t({type:"any"})}function bS(t){return new t({type:"unknown"})}function _S(t,e){return new t({type:"never",...N(e)})}function SS(t,e){return new t({type:"void",...N(e)})}function xS(t,e){return new t({type:"date",...N(e)})}function BR(t,e){return new t({type:"date",coerce:!0,...N(e)})}function ES(t,e){return new t({type:"nan",...N(e)})}function Gi(t,e){return new Sb({check:"less_than",...N(e),value:t,inclusive:!1})}function Wn(t,e){return new Sb({check:"less_than",...N(e),value:t,inclusive:!0})}function Xi(t,e){return new xb({check:"greater_than",...N(e),value:t,inclusive:!1})}function Jn(t,e){return new xb({check:"greater_than",...N(e),value:t,inclusive:!0})}function kS(t){return Xi(0,t)}function IS(t){return Gi(0,t)}function $S(t){return Wn(0,t)}function AS(t){return Jn(0,t)}function qa(t,e){return new YP({check:"multiple_of",...N(e),value:t})}function Za(t,e){return new tR({check:"max_size",...N(e),maximum:t})}function Yi(t,e){return new rR({check:"min_size",...N(e),minimum:t})}function Vu(t,e){return new nR({check:"size_equals",...N(e),size:t})}function Hu(t,e){return new oR({check:"max_length",...N(e),maximum:t})}function na(t,e){return new iR({check:"min_length",...N(e),minimum:t})}function Bu(t,e){return new sR({check:"length_equals",...N(e),length:t})}function zd(t,e){return new aR({check:"string_format",format:"regex",...N(e),pattern:t})}function jd(t){return new cR({check:"string_format",format:"lowercase",...N(t)})}function Md(t){return new uR({check:"string_format",format:"uppercase",...N(t)})}function Ud(t,e){return new lR({check:"string_format",format:"includes",...N(e),includes:t})}function Ld(t,e){return new dR({check:"string_format",format:"starts_with",...N(e),prefix:t})}function Fd(t,e){return new pR({check:"string_format",format:"ends_with",...N(e),suffix:t})}function TS(t,e,r){return new fR({check:"property",property:t,schema:e,...N(r)})}function Vd(t,e){return new mR({check:"properties",shape:t,...N(e)})}function Hd(t,e){return new hR({check:"mime_type",mime:t,...N(e)})}function ri(t){return new gR({check:"overwrite",tx:t})}function Bd(t){return ri(e=>e.normalize(t))}function Kd(){return ri(t=>t.trim())}function qd(){return ri(t=>t.toLowerCase())}function Zd(){return ri(t=>t.toUpperCase())}function Wd(){return ri(t=>QT(t))}function KR(t,e,r){return new t({type:"array",element:e,...N(r)})}function ome(t,e,r){return new t({type:"union",options:e,...N(r)})}function ime(t,e,r){return new t({type:"union",options:e,inclusive:!1,...N(r)})}function sme(t,e,r,o){return new t({type:"union",options:r,discriminator:e,...N(o)})}function ame(t,e,r){return new t({type:"intersection",left:e,right:r})}function cme(t,e,r,o){let n=r instanceof ae,i=n?o:r,s=n?r:null;return new t({type:"tuple",items:e,rest:s,...N(i)})}function ume(t,e,r,o){return new t({type:"record",keyType:e,valueType:r,...N(o)})}function lme(t,e,r,o){return new t({type:"map",keyType:e,valueType:r,...N(o)})}function dme(t,e,r){return new t({type:"set",valueType:e,...N(r)})}function pme(t,e,r){let o=Array.isArray(e)?Object.fromEntries(e.map(n=>[n,n])):e;return new t({type:"enum",entries:o,...N(r)})}function fme(t,e,r){return new t({type:"enum",entries:e,...N(r)})}function mme(t,e,r){return new t({type:"literal",values:Array.isArray(e)?e:[e],...N(r)})}function PS(t,e){return new t({type:"file",...N(e)})}function hme(t,e){return new t({type:"transform",transform:e})}function gme(t,e){return new t({type:"optional",innerType:e})}function yme(t,e){return new t({type:"nullable",innerType:e})}function vme(t,e,r){return new t({type:"default",innerType:e,get defaultValue(){return typeof r=="function"?r():md(r)}})}function wme(t,e,r){return new t({type:"nonoptional",innerType:e,...N(r)})}function bme(t,e){return new t({type:"success",innerType:e})}function _me(t,e,r){return new t({type:"catch",innerType:e,catchValue:typeof r=="function"?r:sP(r)})}function Sme(t,e,r){return new t({type:"pipe",in:e,out:r})}function xme(t,e){return new t({type:"readonly",innerType:e})}function Eme(t,e,r){return new t({type:"template_literal",parts:e,...N(r)})}function kme(t,e){return new t({type:"lazy",getter:e})}function Ime(t,e){return new t({type:"promise",innerType:e})}function RS(t,e,r){let o=N(r);return o.abort??(o.abort=!0),new t({type:"custom",check:"custom",fn:e,...o})}function CS(t,e,r){return new t({type:"custom",check:"custom",fn:e,...N(r)})}function OS(t,e){let r=BV(o=>(o.addIssue=n=>{if(typeof n=="string")o.issues.push(gd(n,o.value,r._zod.def));else{let i=n;i.fatal&&(i.continue=!1),i.code??(i.code="custom"),"input"in i||(i.input=o.value),i.inst??(i.inst=r),i.continue??(i.continue=!r._zod.def.abort),o.issues.push(gd(i))}},t(o.value,o)),e);return r}function BV(t,e){let r=new ot({check:"custom",...N(e)});return r._zod.check=t,r}function NS(t){let e=new ot({check:"describe"});return e._zod.onattach=[r=>{let o=Sr.get(r)??{};Sr.add(r,{...o,description:t})}],e._zod.check=()=>{},e}function DS(t){let e=new ot({check:"meta"});return e._zod.onattach=[r=>{let o=Sr.get(r)??{};Sr.add(r,{...o,...t})}],e._zod.check=()=>{},e}function zS(t,e){let r=N(e),o=r.truthy??["true","1","yes","on","y","enabled"],n=r.falsy??["false","0","no","off","n","disabled"];r.case!=="sensitive"&&(o=o.map(p=>typeof p=="string"?p.toLowerCase():p),n=n.map(p=>typeof p=="string"?p.toLowerCase():p));let i=new Set(o),s=new Set(n),a=t.Codec??Td,c=t.Boolean??$d,u=t.String??Ba,l=new u({type:"string",error:r.error}),d=new c({type:"boolean",error:r.error}),f=new a({type:"pipe",in:l,out:d,transform:((p,m)=>{let g=p;return r.case!=="sensitive"&&(g=g.toLowerCase()),i.has(g)?!0:s.has(g)?!1:(m.issues.push({code:"invalid_value",expected:"stringbool",values:[...i,...s],input:m.value,inst:f,continue:!1}),{})}),reverseTransform:((p,m)=>p===!0?o[0]||"true":n[0]||"false"),error:r.error});return f._zod.bag.truthy=o,f._zod.bag.falsy=n,f._zod.bag.case=r.case??"insensitive",f}function Wa(t,e,r,o={}){let n=N(o),i={check:"string_format",type:"string",format:e,fn:typeof r=="function"?r:a=>r.test(a),...n};return r instanceof RegExp&&(i.pattern=r),new t(i)}function qh(t,...e){for(let r of e)for(let o of Reflect.ownKeys(r))Object.prototype.propertyIsEnumerable.call(r,o)&&_r(t,o,r[o]);return t}function Ja(t){let e=t?.target??"draft-2020-12";return e==="draft-4"&&(e="draft-04"),e==="draft-7"&&(e="draft-07"),{processors:t.processors??{},metadataRegistry:t?.metadata??Sr,target:e,unrepresentable:t?.unrepresentable??"throw",override:t?.override??(()=>{}),io:t?.io??"output",counter:0,seen:new Map,sharedDefsExtractedFor:void 0,sharedEmitDoneFor:void 0,cycles:t?.cycles??"ref",reused:t?.reused??"inline",intersections:[],deferred:[],external:t?.external??void 0}}function Qt(t,e,r,o,n){let i=typeof e.unrepresentable=="function"?e.unrepresentable({zodSchema:t,path:o.path,message:n}):e.unrepresentable;if(i==="any")return!1;if(i===void 0||i==="throw")throw new Error(n);return Object.assign(r,i),!0}function et(t,e,r={path:[],schemaPath:[]}){var o;let n=t._zod.def,i=e.seen.get(t);if(i)return i.count++,r.schemaPath.includes(t)&&(i.cycle=r.path),i.schema;let s={schema:{},count:1,cycle:void 0,path:r.path};e.seen.set(t,s),e.sharedDefsExtractedFor=void 0,e.sharedEmitDoneFor=void 0;let a=t._zod.toJSONSchema?.();if(a)s.schema=a;else{let l={...r,schemaPath:[...r.schemaPath,t],path:r.path};if(t._zod.processJSONSchema)t._zod.processJSONSchema(e,s.schema,l);else{let f=s.schema,p=e.processors[n.type];if(!p)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${n.type}`);p(t,e,f,l)}let d=t._zod.parent;d&&(s.ref||(s.ref=d),et(d,e,l),e.seen.get(d).isParent=!0)}let c=e.metadataRegistry.get(t);return c&&qh(s.schema,c),e.io==="input"&&dn(t)&&(delete s.schema.examples,delete s.schema.default),e.io==="input"&&"_prefault"in s.schema&&((o=s.schema).default??(o.default=s.schema._prefault)),delete s.schema._prefault,e.seen.get(t).schema}function KV(t){return t.replace(/~/g,"~0").replace(/\//g,"~1")}function Ga(t,e){let r=t.seen.get(e);if(!r)throw new Error("Unprocessed schema. This is a bug in Zod.");if(t.external&&t.sharedDefsExtractedFor===t.external)return;let o=new Map;for(let s of t.seen.entries()){let a=t.metadataRegistry.get(s[0])?.id;if(a){let c=o.get(a);if(c&&c!==s[0])throw new Error(`Duplicate schema id "${a}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);o.set(a,s[0])}}let n=s=>{let a=t.target==="draft-2020-12"?"$defs":"definitions";if(t.external){let d=t.external.registry.get(s[0])?.id,f=t.external.uri??(m=>m);if(d)return{ref:f(d)};let p=s[1].defId??s[1].schema.id??`schema${t.counter++}`;return s[1].defId=p,{defId:p,ref:`${f("__shared")}#/${a}/${KV(p)}`}}let c="#",u=`${c}/${a}/`;if(s[1]===r&&!s[1].schema.id)return{ref:c};let l=s[1].schema.id??`__schema${t.counter++}`;return{defId:l,ref:u+KV(l)}},i=s=>{if(s[1].schema.$ref)return;let a=s[1],{ref:c,defId:u}=n(s);a.def={...a.schema},u&&(a.defId=u);let l=a.schema;for(let d in l)delete l[d];l.$ref=c};if(t.cycles==="throw")for(let s of t.seen.entries()){let a=s[1];if(a.cycle)throw new Error(`Cycle detected: #/${a.cycle?.join("/")}/<root>
127
127
 
128
- Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let s of t.seen.entries()){let a=s[1];if(e===s[0]){i(s);continue}if(t.external){let u=t.external.registry.get(s[0])?.id;if(e!==s[0]&&u){i(s);continue}}if(t.metadataRegistry.get(s[0])?.id){i(s);continue}if(a.cycle){i(s);continue}a.count>1&&t.reused==="ref"&&i(s)}t.external&&(t.sharedDefsExtractedFor=t.external)}function WV(t){let e=t.anyOf;if(!Array.isArray(e)||e.length===0||t.type!==void 0)return;let r=[];for(let o of e){if(!o||typeof o!="object")return;WV(o);let n=Object.keys(o);if(n.length!==1||n[0]!=="type")return;let i=o.type;for(let s of Array.isArray(i)?i:[i]){if(typeof s!="string")return;r.includes(s)||r.push(s)}}delete t.anyOf,t.type=r.length===1?r[0]:r}var JV=new Set(["type","properties","required","additionalProperties"]),qV=["oneOf","anyOf"];function ZV(t){let e=t.additionalProperties;return e===void 0||e===!1||typeof e!="object"||e===null?null:Object.keys(e).length?e:null}function qR(t){let e=[];for(let i of t){if(typeof i!="object"||i.type!=="object")return null;for(let s in i)if(!JV.has(s))return null;e.push(i)}let r={},o=new Set;for(let i of e){for(let s in i.properties){if(Object.prototype.hasOwnProperty.call(r,s))continue;let a=[];for(let u of e){let l=u.properties?.[s]??ZV(u);l!=null&&(a.some(d=>JSON.stringify(d)===JSON.stringify(l))||a.push(l))}let c=a.length===1?a[0]:qR(a)??{allOf:a};_r(r,s,c)}for(let s of i.required??[])o.add(s)}let n={type:"object",properties:r};if(o.size&&(n.required=[...o]),e.every(i=>i.additionalProperties===!1))n.additionalProperties=!1;else{let i=[];for(let s of e){let a=ZV(s);a&&!i.some(c=>JSON.stringify(c)===JSON.stringify(a))&&i.push(a)}i.length===1?n.additionalProperties=i[0]:i.length>1&&(n.additionalProperties={allOf:i})}return n}function $me(t){let e=t.allOf;if(!Array.isArray(e)||e.length<2)return;for(let n of JV)if(n in t)return;let r=e.filter(n=>qV.some(i=>Array.isArray(n[i]))),o=null;if(!r.length)o=qR(e);else{let n=r[0],i=qV.find(c=>Array.isArray(n[c]));if(Object.keys(n).length!==1)return;let s=e.filter(c=>c!==n),a=n[i].map(c=>qR([...s,c]));if(a.some(c=>!c))return;o={[i]:a}}o&&(delete t.allOf,qh(t,o))}function Xa(t,e){let r=t.seen.get(e);if(!r)throw new Error("Unprocessed schema. This is a bug in Zod.");let o=a=>{let c=t.seen.get(a);if(c.ref===null)return;let u=c.def??c.schema,l={...u},d=c.ref;if(c.ref=null,d){o(d);let p=t.seen.get(d),m=p.schema;if(m.$ref&&(t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0")?(u.allOf=u.allOf??[],u.allOf.push(m)):qh(u,m),qh(u,l),a._zod.parent===d)for(let y in u)y==="$ref"||y==="allOf"||y in l||delete u[y];if(m.$ref&&p.def)for(let y in u)y==="$ref"||y==="allOf"||y in p.def&&JSON.stringify(u[y])===JSON.stringify(p.def[y])&&delete u[y]}let f=a._zod.parent;if(f&&f!==d){o(f);let p=t.seen.get(f);if(p?.schema.$ref&&(u.$ref=p.schema.$ref,p.def))for(let m in u)m==="$ref"||m==="allOf"||m in p.def&&JSON.stringify(u[m])===JSON.stringify(p.def[m])&&delete u[m]}t.override({zodSchema:a,jsonSchema:u,path:c.path??[]})};if(!t.external||t.sharedEmitDoneFor!==t.external){for(let a of[...t.seen.entries()].reverse())o(a[0]);if(t.target!=="openapi-3.0")for(let a of t.seen.entries())WV(a[1].def??a[1].schema);for(let a of t.deferred)a();if(t.intersections.length){let a=new Map;for(let c of t.seen.values())for(let u of[c.schema,c.def]){let l=u?.allOf;if(!Array.isArray(l))continue;let d=a.get(l);d?d.push(u):a.set(l,[u])}for(let c of t.intersections)for(let u of a.get(c)??[])$me(u)}}let n={};if(t.target==="draft-2020-12"?n.$schema="https://json-schema.org/draft/2020-12/schema":t.target==="draft-07"?n.$schema="http://json-schema.org/draft-07/schema#":t.target==="draft-04"?n.$schema="http://json-schema.org/draft-04/schema#":t.target,t.external?.uri){let a=t.external.registry.get(e)?.id;if(!a)throw new Error("Schema is missing an `id` property");n.$id=t.external.uri(a)}qh(n,r.defId?r.schema:r.def??r.schema);let i=t.metadataRegistry.get(e)?.id;i!==void 0&&n.id===i&&delete n.id;let s=t.external?.defs??{};if(!t.external||t.sharedEmitDoneFor!==t.external)for(let a of t.seen.entries()){let c=a[1];c.def&&c.defId&&(c.def.id===c.defId&&delete c.def.id,_r(s,c.defId,c.def))}t.external&&(t.sharedEmitDoneFor=t.external),t.external||Object.keys(s).length>0&&(t.target==="draft-2020-12"?n.$defs=s:n.definitions=s);try{let a=JSON.parse(JSON.stringify(n));return Object.defineProperty(a,"~standard",{value:{...e["~standard"],jsonSchema:{input:Jd(e,"input",t.processors),output:Jd(e,"output",t.processors)}},enumerable:!1,writable:!1}),a}catch{throw new Error("Error converting schema to JSON.")}}function dn(t,e){let r=e??{seen:new Set};if(r.seen.has(t))return!1;r.seen.add(t);let o=t._zod.def;if(o.type==="transform")return!0;if(o.type==="array")return dn(o.element,r);if(o.type==="set")return dn(o.valueType,r);if(o.type==="lazy")return dn(o.getter(),r);if(o.type==="promise"||o.type==="optional"||o.type==="nonoptional"||o.type==="nullable"||o.type==="readonly"||o.type==="default"||o.type==="prefault"||o.type==="catch")return dn(o.innerType,r);if(o.type==="intersection")return dn(o.left,r)||dn(o.right,r);if(o.type==="record"||o.type==="map")return dn(o.keyType,r)||dn(o.valueType,r);if(o.type==="pipe")return t._zod.traits.has("$ZodCodec")?!0:dn(o.in,r)||dn(o.out,r);if(o.type==="object"){for(let n in o.shape)if(dn(o.shape[n],r))return!0;return!1}if(o.type==="union"){for(let n of o.options)if(dn(n,r))return!0;return!1}if(o.type==="tuple"){for(let n of o.items)if(dn(n,r))return!0;return!!(o.rest&&dn(o.rest,r))}return!1}var ZR=(t,e={})=>r=>{let o=Ja({...r,processors:e});return et(t,o),Ga(o,t),Xa(o,t)},Jd=(t,e,r={})=>o=>{let{libraryOptions:n,target:i}=o??{},s=Ja({...n??{},target:i,io:e,processors:r});return et(t,s),Ga(s,t),Xa(s,t)};var Gd=(t,e,r)=>{(t[e]===void 0||r>t[e])&&(t[e]=r)},Xd=(t,e,r)=>{(t[e]===void 0||r<t[e])&&(t[e]=r)},GV=(t,e)=>{Gd(t,"minimum",e),Xd(t,"maximum",e)},eH=(t,e)=>{t.multipleOf??(t.multipleOf=[]),t.multipleOf.includes(e)||t.multipleOf.push(e)},tH=(t,e)=>{t.patterns??(t.patterns=new Set),t.patterns.add(e)},rH=(t,e)=>{t.mime=t.mime?t.mime.filter(r=>e.includes(r)):[...e]},nH=(t,e)=>{t.format=e,e.includes("int")&&(t.isInt=!0)},XV=(t,e)=>Gd(t,"minimum",e.minimum),YV=(t,e)=>Xd(t,"maximum",e.maximum),QV=t=>(e,r)=>{nH(e,r.format);let[o,n]=t[r.format];Gd(e,"minimum",o),Xd(e,"maximum",n)},Ame={greater_than:(t,e)=>Gd(t,e.inclusive?"minimum":"exclusiveMinimum",e.value),less_than:(t,e)=>Xd(t,e.inclusive?"maximum":"exclusiveMaximum",e.value),multiple_of:(t,e)=>eH(t,e.value),number_format:QV(Jm),bigint_format:QV(Gm),min_length:XV,max_length:YV,length_equals:(t,e)=>GV(t,e.length),min_size:XV,max_size:YV,size_equals:(t,e)=>GV(t,e.size),string_format:(t,e)=>{nH(t,e.format),e.pattern&&tH(t,e.pattern),(e.format==="base64"||e.format==="base64url")&&(t.contentEncoding=e.format),(e.local||e.precision===-1)&&(t.laxFormat=!0)},mime_type:(t,e)=>rH(t,e.mime)};function er(t){let e={},r=t._zod.def,o=t._zod.traits.has("$ZodCheck")?[t,...r.checks??[]]:r.checks??[];for(let i of o)Ame[i._zod.def.check]?.(e,i._zod.def);let n=t._zod.bag;n.minimum!==void 0&&Gd(e,"minimum",n.minimum),n.exclusiveMinimum!==void 0&&Gd(e,"exclusiveMinimum",n.exclusiveMinimum),n.maximum!==void 0&&Xd(e,"maximum",n.maximum),n.exclusiveMaximum!==void 0&&Xd(e,"exclusiveMaximum",n.exclusiveMaximum),n.multipleOf!==void 0&&eH(e,n.multipleOf),n.format!==void 0&&(e.format??(e.format=n.format),n.format.includes("int")&&(e.isInt=!0)),n.mime&&rH(e,n.mime);for(let i of n.patterns??[])tH(e,i);return e}var Tme={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Pme=new Map([[Jb,CP],[dh,OP]]),oH=t=>Pme.get(t)??t,GR=(t,e,r,o)=>{let n=r;n.type="string";let{minimum:i,maximum:s,format:a,patterns:c,contentEncoding:u,laxFormat:l}=er(t);if(typeof i=="number"&&(n.minLength=i),typeof s=="number"&&(n.maxLength=s),a&&(n.format=Tme[a]??a,n.format===""&&delete n.format,(a==="time"||l)&&delete n.format),u&&(n.contentEncoding=u),c&&c.size>0){let d=[...c].map(oH);d.length===1?n.pattern=d[0].source:d.length>1&&(n.allOf=[...d.map(f=>({...e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0"?{type:"string"}:{},pattern:f.source}))])}},XR=(t,e,r,o)=>{let n=r,{minimum:i,maximum:s,multipleOf:a,exclusiveMaximum:c,exclusiveMinimum:u,isInt:l}=er(t);n.type=l?"integer":"number";let d=typeof u=="number"&&u>=(i??Number.NEGATIVE_INFINITY),f=typeof c=="number"&&c<=(s??Number.POSITIVE_INFINITY),p=e.target==="draft-04"||e.target==="openapi-3.0";if(d?p?(n.minimum=u,n.exclusiveMinimum=!0):n.exclusiveMinimum=u:typeof i=="number"&&(n.minimum=i),f?p?(n.maximum=c,n.exclusiveMaximum=!0):n.exclusiveMaximum=c:typeof s=="number"&&(n.maximum=s),a){let m=new Set;for(let w of a)Number.isFinite(w)&&w!==0?m.add(Math.abs(w)):Qt(t,e,n,o,`A multipleOf divisor of ${w} cannot be represented in JSON Schema`);let[g,...y]=m;g!==void 0&&(n.multipleOf=g),y.length&&(n.allOf=[...n.allOf??[],...y.map(w=>({multipleOf:w}))])}},YR=(t,e,r,o)=>{r.type="boolean"},QR=(t,e,r,o)=>{Qt(t,e,r,o,"BigInt cannot be represented in JSON Schema")},eC=(t,e,r,o)=>{Qt(t,e,r,o,"Symbols cannot be represented in JSON Schema")},tC=(t,e,r,o)=>{e.target==="openapi-3.0"?(r.type="string",r.nullable=!0,r.enum=[null]):r.type="null"},rC=(t,e,r,o)=>{Qt(t,e,r,o,"Undefined cannot be represented in JSON Schema")},nC=(t,e,r,o)=>{Qt(t,e,r,o,"Void cannot be represented in JSON Schema")},oC=(t,e,r,o)=>{r.not={}},iC=(t,e,r,o)=>{},sC=(t,e,r,o)=>{},aC=(t,e,r,o)=>{Qt(t,e,r,o,"Date cannot be represented in JSON Schema")},cC=(t,e,r,o)=>{let n=t._zod.def,i=ld(n.entries);if(i.length===0){r.not={};return}i.every(s=>typeof s=="number")&&(r.type="number"),i.every(s=>typeof s=="string")&&(r.type="string"),r.enum=i},uC=(t,e,r,o)=>{let n=t._zod.def;if(n.values.length===0){r.not={};return}let i=[];for(let s of n.values)if(s===void 0){if(Qt(t,e,r,o,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof s=="bigint"){if(Qt(t,e,r,o,"BigInt literals cannot be represented in JSON Schema"))return;i.push(Number(s))}else i.push(s);if(i.length!==0)if(i.length===1){let s=i[0];r.type=s===null?"null":typeof s,e.target==="draft-04"||e.target==="openapi-3.0"?r.enum=[s]:r.const=s}else i.every(s=>typeof s=="number")&&(r.type="number"),i.every(s=>typeof s=="string")&&(r.type="string"),i.every(s=>typeof s=="boolean")&&(r.type="boolean"),i.every(s=>s===null)&&(r.type="null"),r.enum=i},lC=(t,e,r,o)=>{Qt(t,e,r,o,"NaN cannot be represented in JSON Schema")},dC=(t,e,r,o)=>{let n=r,i=t._zod.pattern;if(!i)throw new Error("Pattern not found in template literal");n.type="string",n.pattern=i.source},pC=(t,e,r,o)=>{let n=r;n.type="string",n.format="binary",n.contentEncoding="binary";let{minimum:i,maximum:s,mime:a}=er(t);i!==void 0&&(n.minLength=i),s!==void 0&&(n.maxLength=s),a&&(a.length===0?n.not={}:a.length===1?n.contentMediaType=a[0]:n.anyOf=a.map(c=>({contentMediaType:c})))},fC=(t,e,r,o)=>{r.type="boolean"},mC=(t,e,r,o)=>{Qt(t,e,r,o,"Custom types cannot be represented in JSON Schema")},hC=(t,e,r,o)=>{Qt(t,e,r,o,"Function types cannot be represented in JSON Schema")},gC=(t,e,r,o)=>{Qt(t,e,r,o,"Transforms cannot be represented in JSON Schema")},yC=(t,e,r,o)=>{Qt(t,e,r,o,"Map cannot be represented in JSON Schema")},vC=(t,e,r,o)=>{Qt(t,e,r,o,"Set cannot be represented in JSON Schema")},wC=(t,e,r,o)=>{let n=r,i=t._zod.def,{minimum:s,maximum:a}=er(t);typeof s=="number"&&(n.minItems=s),typeof a=="number"&&(n.maxItems=a),n.type="array",n.items=et(i.element,e,{...o,path:[...o.path,"items"]})};function Zh(t){let e=t._zod.def;return e.type==="pipe"&&e.in._zod.traits.has("$ZodTransform")?Zh(e.out):e.type==="catch"?Zh(e.innerType):t._zod.optin}var bC=(t,e,r,o)=>{let n=r,i=t._zod.def,s=i.shape;if(Object.getOwnPropertySymbols(s).length&&Qt(t,e,n,o,"Symbol keys cannot be represented in JSON Schema"))return;n.type="object",n.properties={};for(let u in s)_r(n.properties,u,et(s[u],e,{...o,path:[...o.path,"properties",u]}));let c=[];for(let u of Object.keys(s)){let l=i.shape[u];(e.io==="input"?Zh(l)===void 0:l._zod.optout===void 0)&&c.push(u)}c.length>0&&(n.required=c),i.catchall?._zod.def.type==="never"?n.additionalProperties=!1:i.catchall?i.catchall&&(n.additionalProperties=et(i.catchall,e,{...o,path:[...o.path,"additionalProperties"]})):e.io==="output"&&(n.additionalProperties=!1)},MS=(t,e,r,o)=>{let n=t._zod.def,i=n.inclusive===!1,s=n.options.map((a,c)=>et(a,e,{...o,path:[...o.path,i?"oneOf":"anyOf",c]}));i?r.oneOf=s:r.anyOf=s},_C=(t,e,r,o)=>{let n=t._zod.def,i=et(n.left,e,{...o,path:[...o.path,"allOf",0]}),s=et(n.right,e,{...o,path:[...o.path,"allOf",1]}),a=u=>"allOf"in u&&Object.keys(u).length===1,c=[...a(i)?i.allOf:[i],...a(s)?s.allOf:[s]];r.allOf=c,e.intersections.push(c)},SC=(t,e,r,o)=>{let n=r,i=t._zod.def;n.type="array";let s=e.target==="draft-2020-12"?"prefixItems":"items",a=e.target==="draft-2020-12"||e.target==="openapi-3.0"?"items":"additionalItems",c=i.items.map((g,y)=>et(g,e,{...o,path:[...o.path,s,y]})),u=i.rest?et(i.rest,e,{...o,path:[...o.path,a,...e.target==="openapi-3.0"?[i.items.length]:[]]}):null,l=i.items.length;for(;l>0;){let g=i.items[l-1];if(!(e.io==="input"?Zh(g)!==void 0:g._zod.optout==="optional"))break;l--}let d=i.items.length,f=!i.rest;e.target==="draft-2020-12"?(n.prefixItems=c,f?n.items=!1:u&&(n.items=u),l>0&&(n.minItems=l),f&&(n.maxItems=d)):e.target==="openapi-3.0"?(n.items={anyOf:c},u&&n.items.anyOf.push(u),l>0&&(n.minItems=l),f&&(n.maxItems=d)):(n.items=c,f?n.additionalItems=!1:u&&(n.additionalItems=u),l>0&&(n.minItems=l),f&&(n.maxItems=d));let{minimum:p,maximum:m}=er(t);typeof p=="number"&&(n.minItems=p),typeof m=="number"&&(n.maxItems=m)};function WR(t,e,r){if(e.$ref){if(r.has(e))return e;r.add(e);let m=t.get(e)?.def;if(!m)return e;let g=WR(t,m,r);return g===m?e:g}for(let m of["anyOf","oneOf"]){let g=e[m];if(!Array.isArray(g))continue;let y=g.map(w=>WR(t,w,r));y.some((w,b)=>w!==g[b])&&(e={...e,[m]:y})}let o=Array.isArray(e.type)?e.type:[e.type],n=!o.includes("string")&&o.some(m=>m==="number"||m==="integer"),i=e.enum??(e.const!==void 0?[e.const]:void 0);if(!n&&!i?.some(m=>typeof m=="number"))return e;let{minimum:s,maximum:a,exclusiveMinimum:c,exclusiveMaximum:u,multipleOf:l,format:d,id:f,...p}=e;return p.enum?p.enum=p.enum.map(m=>typeof m=="number"?String(m):m):typeof p.const=="number"&&(p.const=String(p.const)),n&&(p.type="string",i||(p.pattern=(o.includes("number")?ra:oh).source)),p}var JR=new WeakMap;function Rme(t){let e=new Map;for(let o of t.seen.values())o.def&&!e.has(o.schema)&&e.set(o.schema,o);let r=new Map;for(let o of JR.get(t)??[]){let n=t.seen.get(o),i=(n?.def??n?.schema)?.propertyNames;if(!i||i===!0||r.has(i))continue;let s=WR(e,i,new Set);s!==i&&r.set(i,s)}if(r.size)for(let o of t.seen.values())for(let n of[o.schema,o.def]){let i=n&&r.get(n.propertyNames);i&&(n.propertyNames=i)}}var xC=(t,e,r,o)=>{let n=r,i=t._zod.def;n.type="object";let s=i.keyType,a=er(s).patterns;if(i.mode==="loose"&&a&&a.size>0){let l=et(i.valueType,e,{...o,path:[...o.path,"patternProperties","*"]});n.patternProperties={};for(let d of a)_r(n.patternProperties,oH(d).source,l)}else{if(e.target==="draft-07"||e.target==="draft-2020-12"){n.propertyNames=et(i.keyType,e,{...o,path:[...o.path,"propertyNames"]});let l=JR.get(e);l||(l=[],JR.set(e,l),e.deferred.push(()=>Rme(e))),l.push(t)}n.additionalProperties=et(i.valueType,e,{...o,path:[...o.path,"additionalProperties"]})}let c=s._zod.values,u=e.io==="input"&&Zh(i.valueType)!==void 0;if(c&&!i.partial&&!u){let l=[...c].filter(d=>typeof d=="string"||typeof d=="number");l.length>0&&(n.required=l.map(String))}},EC=(t,e,r,o)=>{let n=t._zod.def,i=et(n.innerType,e,o),s=e.seen.get(t);e.target==="openapi-3.0"?(s.ref=n.innerType,r.nullable=!0):r.anyOf=[i,{type:"null"}]},kC=(t,e,r,o)=>{let n=t._zod.def;et(n.innerType,e,o);let i=e.seen.get(t);i.ref=n.innerType},IC=Symbol();function iH(t,e,r,o,n){let i=!1,s=JSON.stringify(t,(a,c)=>typeof c!="bigint"?c:(i=!0,null));return i?(Qt(e,r,o,n,"BigInt defaults cannot be represented in JSON Schema"),IC):JSON.parse(s)}var $C=(t,e,r,o)=>{let n=t._zod.def;et(n.innerType,e,o);let i=e.seen.get(t);i.ref=n.innerType;let s=iH(n.defaultValue,t,e,r,o);s!==IC&&(r.default=s)},AC=(t,e,r,o)=>{let n=t._zod.def;et(n.innerType,e,o);let i=e.seen.get(t);if(i.ref=n.innerType,e.io!=="input")return;let s=iH(n.defaultValue,t,e,r,o);s!==IC&&(r._prefault=s)},TC=(t,e,r,o)=>{let n=t._zod.def;et(n.innerType,e,o);let i=e.seen.get(t);i.ref=n.innerType;let s;try{s=n.catchValue(void 0)}catch{Qt(t,e,r,o,"Dynamic catch values are not supported in JSON Schema");return}r.default=s},PC=(t,e,r,o)=>{let n=t._zod.def,i=n.in._zod.traits.has("$ZodTransform"),s=e.io==="input"?i?n.out:n.in:n.out;et(s,e,o);let a=e.seen.get(t);a.ref=s},RC=(t,e,r,o)=>{let n=t._zod.def;et(n.innerType,e,o);let i=e.seen.get(t);i.ref=n.innerType,r.readOnly=!0},CC=(t,e,r,o)=>{let n=t._zod.def;et(n.innerType,e,o);let i=e.seen.get(t);i.ref=n.innerType},US=(t,e,r,o)=>{let n=t._zod.def;et(n.innerType,e,o);let i=e.seen.get(t);i.ref=n.innerType},OC=(t,e,r,o)=>{let n=t._zod.innerType;et(n,e,o);let i=e.seen.get(t);i.ref=n},jS={string:GR,number:XR,boolean:YR,bigint:QR,symbol:eC,null:tC,undefined:rC,void:nC,never:oC,any:iC,unknown:sC,date:aC,enum:cC,literal:uC,nan:lC,template_literal:dC,file:pC,success:fC,custom:mC,function:hC,transform:gC,map:yC,set:vC,array:wC,object:bC,union:MS,intersection:_C,tuple:SC,record:xC,nullable:EC,nonoptional:kC,default:$C,prefault:AC,catch:TC,pipe:PC,readonly:RC,promise:CC,optional:US,lazy:OC};function Ku(t,e){if("_idmap"in t){let o=t,n=Ja({...e,processors:jS}),i={};for(let c of o._idmap.entries()){let[u,l]=c;et(l,n)}let s={},a={registry:o,uri:e?.uri,defs:i};n.external=a;for(let c of o._idmap.entries()){let[u,l]=c;Ga(n,l),_r(s,u,Xa(n,l))}if(Object.keys(i).length>0){let c=n.target==="draft-2020-12"?"$defs":"definitions";s.__shared={[c]:i}}return{schemas:s}}let r=Ja({...e,processors:jS});return et(t,r),Ga(r,t),Xa(r,t)}var LS=class{get metadataRegistry(){return this.ctx.metadataRegistry}get target(){return this.ctx.target}get unrepresentable(){return this.ctx.unrepresentable}get override(){return this.ctx.override}get io(){return this.ctx.io}get counter(){return this.ctx.counter}set counter(e){this.ctx.counter=e}get seen(){return this.ctx.seen}constructor(e){let r=e?.target??"draft-2020-12";r==="draft-4"&&(r="draft-04"),r==="draft-7"&&(r="draft-07"),this.ctx=Ja({processors:jS,target:r,...e?.metadata&&{metadata:e.metadata},...e?.unrepresentable&&{unrepresentable:e.unrepresentable},...e?.override&&{override:e.override},...e?.io&&{io:e.io}})}process(e,r={path:[],schemaPath:[]}){return et(e,this.ctx,r)}emit(e,r){r&&(r.cycles&&(this.ctx.cycles=r.cycles),r.reused&&(this.ctx.reused=r.reused),r.external&&(this.ctx.external=r.external)),this.ctx.sharedDefsExtractedFor=void 0,this.ctx.sharedEmitDoneFor=void 0,Ga(this.ctx,e);let o=Xa(this.ctx,e),{"~standard":n,...i}=o;return i}};var sH={};var ip={};bt(ip,{ZodAny:()=>YC,ZodArray:()=>rO,ZodBase64:()=>ix,ZodBase64URL:()=>sx,ZodBigInt:()=>np,ZodBigIntFormat:()=>ux,ZodBoolean:()=>rp,ZodCIDRv4:()=>nx,ZodCIDRv6:()=>ox,ZodCUID:()=>GS,ZodCUID2:()=>XS,ZodCatch:()=>_O,ZodCodec:()=>rg,ZodCreditCard:()=>ZC,ZodCustom:()=>ng,ZodCustomStringFormat:()=>Zu,ZodDate:()=>Xh,ZodDefault:()=>hO,ZodDiscriminatedUnion:()=>oO,ZodE164:()=>ax,ZodEmail:()=>qS,ZodEmoji:()=>WS,ZodEnum:()=>Qd,ZodExactOptional:()=>px,ZodFile:()=>dO,ZodFunction:()=>RO,ZodGUID:()=>ZS,ZodIBAN:()=>WC,ZodIPv4:()=>tx,ZodIPv6:()=>rx,ZodISODate:()=>Qa,ZodISODateTime:()=>Ya,ZodISODuration:()=>tc,ZodISOTime:()=>ec,ZodInstanceOf:()=>NO,ZodIntersection:()=>iO,ZodJWT:()=>cx,ZodKSUID:()=>ex,ZodLazy:()=>AO,ZodLiteral:()=>lO,ZodMAC:()=>qC,ZodMap:()=>cO,ZodNaN:()=>xO,ZodNanoID:()=>JS,ZodNever:()=>eO,ZodNonOptional:()=>fx,ZodNull:()=>XC,ZodNullable:()=>mO,ZodNumber:()=>tp,ZodNumberFormat:()=>Wu,ZodObject:()=>Yh,ZodOptional:()=>Ju,ZodPipe:()=>tg,ZodPrefault:()=>yO,ZodPreprocess:()=>EO,ZodPromise:()=>PO,ZodReadonly:()=>kO,ZodRecord:()=>Yd,ZodSet:()=>uO,ZodString:()=>ep,ZodStringFormat:()=>st,ZodSuccess:()=>bO,ZodSymbol:()=>JC,ZodTemplateLiteral:()=>$O,ZodTransform:()=>pO,ZodTuple:()=>sO,ZodType:()=>ge,ZodULID:()=>YS,ZodURL:()=>Jh,ZodUUID:()=>Qi,ZodUndefined:()=>GC,ZodUnion:()=>Qh,ZodUnknown:()=>QC,ZodVoid:()=>tO,ZodXID:()=>QS,ZodXor:()=>nO,_ZodString:()=>KS,_default:()=>gO,_function:()=>mB,any:()=>JH,array:()=>Ae,base64:()=>TH,base64url:()=>PH,bigint:()=>BH,boolean:()=>Bt,catch:()=>SO,check:()=>hB,cidrv4:()=>$H,cidrv6:()=>AH,codec:()=>lB,creditCard:()=>CH,cuid:()=>wH,cuid2:()=>bH,currencyCode:()=>MH,custom:()=>mx,date:()=>XH,describe:()=>gB,discriminatedUnion:()=>eg,e164:()=>RH,email:()=>uH,emoji:()=>yH,enum:()=>Er,exactOptional:()=>fO,file:()=>sB,float32:()=>LH,float64:()=>FH,function:()=>mB,guid:()=>lH,hash:()=>UH,hex:()=>jH,hostname:()=>zH,httpUrl:()=>gH,iban:()=>OH,instanceof:()=>vB,int:()=>HS,int32:()=>VH,int64:()=>KH,intersection:()=>op,invertCodec:()=>dB,ipv4:()=>EH,ipv6:()=>IH,json:()=>bB,jwt:()=>NH,keyof:()=>YH,ksuid:()=>xH,lazy:()=>TO,literal:()=>G,looseObject:()=>xr,looseRecord:()=>rB,mac:()=>kH,map:()=>nB,meta:()=>yB,nan:()=>uB,nanoid:()=>vH,nativeEnum:()=>iB,never:()=>lx,nonoptional:()=>wO,null:()=>Gh,nullable:()=>Wh,nullish:()=>aB,number:()=>Ze,object:()=>H,optional:()=>it,partialRecord:()=>tB,pipe:()=>BS,prefault:()=>vO,preprocess:()=>og,promise:()=>fB,readonly:()=>IO,record:()=>at,refine:()=>CO,set:()=>oB,strictObject:()=>QH,string:()=>I,stringFormat:()=>DH,stringbool:()=>wB,success:()=>cB,superRefine:()=>OO,symbol:()=>ZH,templateLiteral:()=>pB,transform:()=>dx,tuple:()=>aO,uint32:()=>HH,uint64:()=>qH,ulid:()=>_H,undefined:()=>WH,union:()=>tt,unknown:()=>dt,url:()=>hH,uuid:()=>dH,uuidv4:()=>pH,uuidv6:()=>fH,uuidv7:()=>mH,void:()=>GH,xid:()=>SH,xor:()=>eB});var FS={};bt(FS,{endsWith:()=>Fd,gt:()=>Xi,gte:()=>Jn,includes:()=>Ud,length:()=>Bu,lowercase:()=>jd,lt:()=>Gi,lte:()=>Wn,maxLength:()=>Hu,maxSize:()=>Za,mime:()=>Hd,minLength:()=>na,minSize:()=>Yi,multipleOf:()=>qa,negative:()=>IS,nonnegative:()=>AS,nonpositive:()=>$S,normalize:()=>Bd,overwrite:()=>ri,positive:()=>kS,properties:()=>Vd,property:()=>TS,regex:()=>zd,size:()=>Vu,slugify:()=>Wd,startsWith:()=>Ld,toLowerCase:()=>qd,toUpperCase:()=>Zd,trim:()=>Kd,uppercase:()=>Md});var aH=new WeakSet([Object.prototype,Error.prototype]);function VS(t,e,r){Object.defineProperty(t,e,{configurable:!0,enumerable:!1,get(){let o=r(this);return Object.defineProperty(this,e,{value:o,configurable:!0,writable:!0}),o},set(o){Object.defineProperty(this,e,{value:o,configurable:!0,writable:!0})}})}var cH=(t,e)=>{pP.init(t,e),t.name="ZodError";let r=Object.getPrototypeOf(t);aH.has(r)||(aH.add(r),VS(r,"format",o=>n=>rh(o,n)),VS(r,"flatten",o=>n=>th(o,n)),VS(r,"addIssue",o=>n=>{o.issues.push(n),o.message=JSON.stringify(o.issues,dd,2)}),VS(r,"addIssues",o=>n=>{o.issues.push(...n),o.message=JSON.stringify(o.issues,dd,2)}),Object.defineProperty(r,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},Ome=S("ZodError",cH),Pn=S("ZodError",cH,void 0,{Parent:Error});var NC=yd(Pn),DC=vd(Pn),zC=wd(Pn),jC=_d(Pn),MC=lb(Pn),UC=db(Pn),LC=pb(Pn),FC=fb(Pn),VC=mb(Pn),HC=hb(Pn),BC=gb(Pn),KC=yb(Pn);function Dme(){lr.localeError||zt(W_())}function qu(){lr.memoizer||zt({memoizer:wh()})}var ge=S("ZodType",(t,e)=>(Dme(),ae.init(t,e),t.def=e,t.type=e.type,t),{check(...t){let e=this.def;return this.clone(A.mergeDefs(e,{checks:[...e.checks??[],...t.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),{parent:!0})},with(...t){return this.check(...t)},clone(t,e){return qe(this,t,e)},brand(){return this},register(t,e){return t.add(this,e),this},refine(t,e){return this.check(CO(t,e))},superRefine(t,e){return this.check(OO(t,e))},overwrite(t){return this.check(ri(t))},optional(){return it(this)},exactOptional(){return fO(this)},nullable(){return Wh(this)},nullish(){return it(Wh(this))},nonoptional(t){return wO(this,t)},array(){return Ae(this)},or(t){return tt([this,t])},and(t){return op(this,t)},transform(t){return BS(this,dx(t))},default(t){return gO(this,t)},prefault(t){return vO(this,t)},catch(t){return SO(this,t)},pipe(t){return BS(this,t)},readonly(){return IO(this)},describe(t){let e=this.clone();return Sr.add(e,{description:t}),e},meta(...t){if(t.length===0)return Sr.get(this);let e=this.clone();return Sr.add(e,t[0]),e},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(t,...e){return e.length===0?t(this):t(this,...e)},get"~standard"(){return A.hide(this,"~standard",{...Ab(this),jsonSchema:{input:Jd(this,"input"),output:Jd(this,"output")}})},set"~standard"(t){A.own(this,"~standard",t)},parse:function t(e,r){return NC(this,e,r,{callee:t})},parseAsync:async function t(e,r){return await DC(this,e,r,{callee:t})},safeParse(t,e){return zC(this,t,e)},async safeParseAsync(t,e){return jC(this,t,e)},get spa(){return this?.safeParseAsync},set spa(t){A.own(this,"spa",t)},validate(t,e){return xd(this,t,e)},validateAsync(t,e){return Ed(this,t,e)},encode:function t(e,r){return MC(this,e,r,{callee:t})},decode:function t(e,r){return UC(this,e,r,{callee:t})},encodeAsync:async function t(e,r){return await LC(this,e,r,{callee:t})},decodeAsync:async function t(e,r){return await FC(this,e,r,{callee:t})},safeEncode(t,e){return VC(this,t,e)},safeDecode(t,e){return HC(this,t,e)},async safeEncodeAsync(t,e){return BC(this,t,e)},async safeDecodeAsync(t,e){return KC(this,t,e)},toJSONSchema(t){return ZR(this,{})(t)},get description(){return Sr.get(this)?.description},get _def(){return this._zod.def}}),KS=S("_ZodString",(t,e)=>{Ba.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>GR(t,r,o,n)},A.derived({format:t=>er(t).format??null,minLength:t=>er(t).minimum??null,maxLength:t=>er(t).maximum??null},{regex(...t){return this.check(zd(...t))},includes(...t){return this.check(Ud(...t))},startsWith(...t){return this.check(Ld(...t))},endsWith(...t){return this.check(Fd(...t))},min(...t){return this.check(na(...t))},max(...t){return this.check(Hu(...t))},length(...t){return this.check(Bu(...t))},nonempty(...t){return this.check(na(1,...t))},lowercase(t){return this.check(jd(t))},uppercase(t){return this.check(Md(t))},trim(){return this.check(Kd())},normalize(...t){return this.check(Bd(...t))},toLowerCase(){return this.check(qd())},toUpperCase(){return this.check(Zd())},slugify(){return this.check(Wd())}})),ep=S("ZodString",(t,e)=>{Ba.init(t,e),KS.init(t,e)},{email(t){return this.check(_h(qS,t))},url(t){return this.check(Dd(Jh,t))},jwt(t){return this.check(Fh(cx,t))},emoji(t){return this.check($h(WS,t))},guid(t){return this.check(Sh(ZS,t))},uuid(t){return this.check(xh(Qi,t))},uuidv4(t){return this.check(Eh(Qi,t))},uuidv6(t){return this.check(kh(Qi,t))},uuidv7(t){return this.check(Ih(Qi,t))},nanoid(t){return this.check(Ah(JS,t))},cuid(t){return this.check(Th(GS,t))},cuid2(t){return this.check(Ph(XS,t))},ulid(t){return this.check(Rh(YS,t))},base64(t){return this.check(Mh(ix,t))},base64url(t){return this.check(Uh(sx,t))},xid(t){return this.check(Ch(QS,t))},ksuid(t){return this.check(Oh(ex,t))},ipv4(t){return this.check(Nh(tx,t))},ipv6(t){return this.check(Dh(rx,t))},cidrv4(t){return this.check(zh(nx,t))},cidrv6(t){return this.check(jh(ox,t))},e164(t){return this.check(Lh(ax,t))},datetime(t){return this.check(Vh(Ya,t))},date(t){return this.check(Hh(Qa,t))},time(t){return this.check(Bh(ec,t))},duration(t){return this.check(Kh(tc,t))}});function I(t){return rS(ep,t)}var st=S("ZodStringFormat",(t,e)=>{Je.init(t,e),KS.init(t,e)}),Ya=S("ZodISODateTime",(t,e)=>{_R.init(t,e),st.init(t,e)}),Qa=S("ZodISODate",(t,e)=>{SR.init(t,e),st.init(t,e)}),ec=S("ZodISOTime",(t,e)=>{xR.init(t,e),st.init(t,e)}),tc=S("ZodISODuration",(t,e)=>{ER.init(t,e),st.init(t,e)}),qS=S("ZodEmail",(t,e)=>{Rb.init(t,e),st.init(t,e)});function uH(t){return _h(qS,t)}var ZS=S("ZodGUID",(t,e)=>{Tb.init(t,e),st.init(t,e)});function lH(t){return Sh(ZS,t)}var Qi=S("ZodUUID",(t,e)=>{Pb.init(t,e),st.init(t,e)});function dH(t){return xh(Qi,t)}function pH(t){return Eh(Qi,t)}function fH(t){return kh(Qi,t)}function mH(t){return Ih(Qi,t)}var Jh=S("ZodURL",(t,e)=>{Db.init(t,e),st.init(t,e)});function hH(t){return Dd(Jh,t)}function gH(t){return Dd(Jh,{protocol:nh,hostname:DP,...A.normalizeParams(t)})}var WS=S("ZodEmoji",(t,e)=>{zb.init(t,e),st.init(t,e)});function yH(t){return $h(WS,t)}var JS=S("ZodNanoID",(t,e)=>{jb.init(t,e),st.init(t,e)});function vH(t){return Ah(JS,t)}var GS=S("ZodCUID",(t,e)=>{Mb.init(t,e),st.init(t,e)});function wH(t){return Th(GS,t)}var XS=S("ZodCUID2",(t,e)=>{Ub.init(t,e),st.init(t,e)});function bH(t){return Ph(XS,t)}var YS=S("ZodULID",(t,e)=>{Lb.init(t,e),st.init(t,e)});function _H(t){return Rh(YS,t)}var QS=S("ZodXID",(t,e)=>{Fb.init(t,e),st.init(t,e)});function SH(t){return Ch(QS,t)}var ex=S("ZodKSUID",(t,e)=>{Vb.init(t,e),st.init(t,e)});function xH(t){return Oh(ex,t)}var tx=S("ZodIPv4",(t,e)=>{Hb.init(t,e),st.init(t,e)});function EH(t){return Nh(tx,t)}var qC=S("ZodMAC",(t,e)=>{Kb.init(t,e),st.init(t,e)});function kH(t){return nS(qC,t)}var rx=S("ZodIPv6",(t,e)=>{Bb.init(t,e),st.init(t,e)});function IH(t){return Dh(rx,t)}var nx=S("ZodCIDRv4",(t,e)=>{qb.init(t,e),st.init(t,e)});function $H(t){return zh(nx,t)}var ox=S("ZodCIDRv6",(t,e)=>{Wb.init(t,e),st.init(t,e)});function AH(t){return jh(ox,t)}var ix=S("ZodBase64",(t,e)=>{Gb.init(t,e),st.init(t,e)});function TH(t){return Mh(ix,t)}var sx=S("ZodBase64URL",(t,e)=>{Yb.init(t,e),st.init(t,e)});function PH(t){return Uh(sx,t)}var ax=S("ZodE164",(t,e)=>{Qb.init(t,e),st.init(t,e)});function RH(t){return Lh(ax,t)}var ZC=S("ZodCreditCard",(t,e)=>{t_.init(t,e),st.init(t,e)});function CH(t){return oS(ZC,t)}var WC=S("ZodIBAN",(t,e)=>{n_.init(t,e),st.init(t,e)});function OH(t){return iS(WC,t)}var cx=S("ZodJWT",(t,e)=>{i_.init(t,e),st.init(t,e)});function NH(t){return Fh(cx,t)}var Zu=S("ZodCustomStringFormat",(t,e)=>{s_.init(t,e),st.init(t,e)});function DH(t,e,r={}){return Wa(Zu,t,e,r)}function zH(t){return Wa(Zu,"hostname",NP,t)}function jH(t){return Wa(Zu,"hex",JP,t)}function MH(t){return Wa(Zu,"currency_code",jP,t)}function UH(t,e){let r=e?.enc??"hex",o=`${t}_${r}`,n=Zn[o];if(!n)throw new Error(`Unrecognized hash format: ${o}`);return Wa(Zu,o,n,e)}var tp=S("ZodNumber",(t,e)=>{ph.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>XR(t,r,o,n),t.isFinite=!0},A.derived({minValue:t=>{let{minimum:e,exclusiveMinimum:r}=er(t);return Math.max(e??Number.NEGATIVE_INFINITY,r??Number.NEGATIVE_INFINITY)},maxValue:t=>{let{maximum:e,exclusiveMaximum:r}=er(t);return Math.min(e??Number.POSITIVE_INFINITY,r??Number.POSITIVE_INFINITY)},isInt:t=>{let{isInt:e,multipleOf:r}=er(t);return!!e||!!r?.some(Number.isSafeInteger)},format:t=>er(t).format??null},{gt(t,e){return this.check(Xi(t,e))},gte(t,e){return this.check(Jn(t,e))},min(t,e){return this.check(Jn(t,e))},lt(t,e){return this.check(Gi(t,e))},lte(t,e){return this.check(Wn(t,e))},max(t,e){return this.check(Wn(t,e))},int(t){return this.check(HS(t))},safe(t){return this.check(HS(t))},positive(t){return this.check(Xi(0,t))},nonnegative(t){return this.check(Jn(0,t))},negative(t){return this.check(Gi(0,t))},nonpositive(t){return this.check(Wn(0,t))},multipleOf(t,e){return this.check(qa(t,e))},step(t,e){return this.check(qa(t,e))},finite(){return this}}));function Ze(t){return sS(tp,t)}var Wu=S("ZodNumberFormat",(t,e)=>{a_.init(t,e),tp.init(t,e)});function HS(t){return aS(Wu,t)}function LH(t){return cS(Wu,t)}function FH(t){return uS(Wu,t)}function VH(t){return lS(Wu,t)}function HH(t){return dS(Wu,t)}var rp=S("ZodBoolean",(t,e)=>{$d.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>YR(t,r,o,n)});function Bt(t){return pS(rp,t)}var np=S("ZodBigInt",(t,e)=>{fh.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>QR(t,r,o,n)},A.derived({minValue:t=>er(t).minimum??null,maxValue:t=>er(t).maximum??null,format:t=>er(t).format??null},{gte(t,e){return this.check(Jn(t,e))},min(t,e){return this.check(Jn(t,e))},gt(t,e){return this.check(Xi(t,e))},lt(t,e){return this.check(Gi(t,e))},lte(t,e){return this.check(Wn(t,e))},max(t,e){return this.check(Wn(t,e))},positive(t){return this.check(Xi(BigInt(0),t))},negative(t){return this.check(Gi(BigInt(0),t))},nonpositive(t){return this.check(Wn(BigInt(0),t))},nonnegative(t){return this.check(Jn(BigInt(0),t))},multipleOf(t,e){return this.check(qa(t,e))}}));function BH(t){return fS(np,t)}var ux=S("ZodBigIntFormat",(t,e)=>{c_.init(t,e),np.init(t,e)});function KH(t){return mS(ux,t)}function qH(t){return hS(ux,t)}var JC=S("ZodSymbol",(t,e)=>{u_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>eC(t,r,o,n)});function ZH(t){return gS(JC,t)}var GC=S("ZodUndefined",(t,e)=>{l_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>rC(t,r,o,n)});function WH(t){return yS(GC,t)}var XC=S("ZodNull",(t,e)=>{d_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>tC(t,r,o,n)});function Gh(t){return vS(XC,t)}var YC=S("ZodAny",(t,e)=>{p_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>iC(t,r,o,n)});function JH(){return wS(YC)}var QC=S("ZodUnknown",(t,e)=>{f_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>sC(t,r,o,n)});function dt(){return bS(QC)}var eO=S("ZodNever",(t,e)=>{m_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>oC(t,r,o,n)});function lx(t){return _S(eO,t)}var tO=S("ZodVoid",(t,e)=>{h_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>nC(t,r,o,n)});function GH(t){return SS(tO,t)}var Xh=S("ZodDate",(t,e)=>{g_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>aC(t,r,o,n),t.min=(r,o)=>t.check(Jn(r,o)),t.max=(r,o)=>t.check(Wn(r,o))},A.derived({minDate:t=>{let{minimum:e}=er(t);return e?new Date(e):null},maxDate:t=>{let{maximum:e}=er(t);return e?new Date(e):null}},{}));function XH(t){return xS(Xh,t)}var rO=S("ZodArray",(t,e)=>{qu(),y_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>wC(t,r,o,n),t.element=e.element},{min(t,e){return this.check(na(t,e))},nonempty(t){return this.check(na(1,t))},max(t,e){return this.check(Hu(t,e))},length(t,e){return this.check(Bu(t,e))},unwrap(){return this.element}});function Ae(t,e){return KR(rO,t,e)}function YH(t){let e=t._zod.def.shape;return Er(Object.keys(e))}var Yh=S("ZodObject",(t,e)=>{qu(),IR.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>bC(t,r,o,n),A.installLazyProp(t,"shape",r=>r._zod.def.shape,!1)},{keyof(){return Er(Object.keys(this._zod.def.shape))},catchall(t){return this.clone(A.mergeDefs(this._zod.def,{catchall:t}))},passthrough(){return this.clone(A.mergeDefs(this._zod.def,{catchall:dt()}))},loose(){return this.clone(A.mergeDefs(this._zod.def,{catchall:dt()}))},strict(){return this.clone(A.mergeDefs(this._zod.def,{catchall:lx()}))},strip(){return this.clone(A.mergeDefs(this._zod.def,{catchall:void 0}))},extend(t){return A.extend(this,t)},safeExtend(t){return A.safeExtend(this,t)},merge(t){return A.merge(this,t)},pick(t){return A.pick(this,t)},omit(t){return A.omit(this,t)},partial(...t){return A.partial(Ju,this,t[0])},exactPartial(...t){return A.partial(px,this,t[0],"exactPartial")},required(...t){return A.required(fx,this,t[0])}});function H(t,e){let r={type:"object",shape:t??{},...A.normalizeParams(e)};return new Yh(r)}function QH(t,e){return new Yh({type:"object",shape:t,catchall:lx(),...A.normalizeParams(e)})}function xr(t,e){return new Yh({type:"object",shape:t,catchall:dt(),...A.normalizeParams(e)})}var Qh=S("ZodUnion",(t,e)=>{Ad.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>MS(t,r,o,n),t.options=e.options});function tt(t,e){return new Qh({type:"union",options:t,...A.normalizeParams(e)})}var nO=S("ZodXor",(t,e)=>{Qh.init(t,e),w_.init(t,e),t._zod.processJSONSchema=(r,o,n)=>MS(t,r,o,n),t.options=e.options});function eB(t,e){return new nO({type:"union",options:t,inclusive:!1,...A.normalizeParams(e)})}var oO=S("ZodDiscriminatedUnion",(t,e)=>{Qh.init(t,e),b_.init(t,e)});function eg(t,e,r){return new oO({type:"union",options:e,discriminator:t,...A.normalizeParams(r)})}var iO=S("ZodIntersection",(t,e)=>{__.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>_C(t,r,o,n)});function op(t,e){return new iO({type:"intersection",left:t,right:e})}var sO=S("ZodTuple",(t,e)=>{qu(),mh.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>SC(t,r,o,n)},{rest(t){return this.clone({...this._zod.def,rest:t})},partial(){let t=this._zod.def;if(t.checks?.length)throw new Error(".partial() cannot be used on tuple schemas containing refinements");return this.clone({...t,items:t.items.map(e=>new Ju({type:"optional",innerType:e}))})}});function aO(t,e,r){let o=e instanceof ae,n=o?r:e,i=o?e:null;return new sO({type:"tuple",items:t,rest:i,...A.normalizeParams(n)})}var Yd=S("ZodRecord",(t,e)=>{qu(),S_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>xC(t,r,o,n),t.keyType=e.keyType,t.valueType=e.valueType});function at(t,e,r){return!e||!e._zod?new Yd({type:"record",keyType:I(),valueType:t,...A.normalizeParams(e)}):new Yd({type:"record",keyType:t,valueType:e,...A.normalizeParams(r)})}function tB(t,e,r){return new Yd({type:"record",keyType:t,valueType:e,...A.normalizeParams(r),partial:!0})}function rB(t,e,r){return new Yd({type:"record",keyType:t,valueType:e,mode:"loose",...A.normalizeParams(r)})}var cO=S("ZodMap",(t,e)=>{qu(),x_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>yC(t,r,o,n),t.keyType=e.keyType,t.valueType=e.valueType,t.min=(...r)=>t.check(Yi(...r)),t.nonempty=r=>t.check(Yi(1,r)),t.max=(...r)=>t.check(Za(...r)),t.size=(...r)=>t.check(Vu(...r))});function nB(t,e,r){return new cO({type:"map",keyType:t,valueType:e,...A.normalizeParams(r)})}var uO=S("ZodSet",(t,e)=>{qu(),E_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>vC(t,r,o,n),t.min=(...r)=>t.check(Yi(...r)),t.nonempty=r=>t.check(Yi(1,r)),t.max=(...r)=>t.check(Za(...r)),t.size=(...r)=>t.check(Vu(...r))});function oB(t,e){return new uO({type:"set",valueType:t,...A.normalizeParams(e)})}var Qd=S("ZodEnum",(t,e)=>{k_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(o,n,i)=>cC(t,o,n,i),t.enum=e.entries,t.options=[...t._zod.values];let r=new Set(Object.keys(e.entries));t.extract=(o,n)=>{let i={};for(let s of o)if(r.has(s))i[s]=e.entries[s];else throw new Error(`Key ${s} not found in enum`);return new Qd({...e,checks:[],...A.normalizeParams(n),entries:i})},t.exclude=(o,n)=>{let i={...e.entries};for(let s of o)if(r.has(s))delete i[s];else throw new Error(`Key ${s} not found in enum`);return new Qd({...e,checks:[],...A.normalizeParams(n),entries:i})}});function Er(t,e){let r=Array.isArray(t)?Object.fromEntries(t.map(o=>[o,o])):t;return new Qd({type:"enum",entries:r,...A.normalizeParams(e)})}function iB(t,e){return new Qd({type:"enum",entries:t,...A.normalizeParams(e)})}var lO=S("ZodLiteral",(t,e)=>{I_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>uC(t,r,o,n),t.values=new Set(e.values),Object.defineProperty(t,"value",{get(){if(e.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return e.values[0]}})});function G(t,e){return new lO({type:"literal",values:Array.isArray(t)?t:[t],...A.normalizeParams(e)})}var dO=S("ZodFile",(t,e)=>{$_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>pC(t,r,o,n),t.min=(r,o)=>t.check(Yi(r,o)),t.max=(r,o)=>t.check(Za(r,o)),t.mime=(r,o)=>t.check(Hd(Array.isArray(r)?r:[r],o))});function sB(t){return PS(dO,t)}var pO=S("ZodTransform",(t,e)=>{qu(),A_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>gC(t,r,o,n),t._zod.parse=(r,o)=>{if(o.direction==="backward")throw new Ha(t.constructor.name);r.addIssue=i=>{if(typeof i=="string")r.issues.push(A.issue(i,r.value,e));else{let s=i;s.fatal&&(s.continue=!1),s.code??(s.code="custom"),"input"in s||(s.input=r.value),s.inst??(s.inst=t),r.issues.push(A.issue(s))}};let n=e.transform(r.value,r);return n instanceof Promise?n.then(i=>(r.value=i,r)):(r.value=n,r)}});function dx(t){return new pO({type:"transform",transform:t})}var Ju=S("ZodOptional",(t,e)=>{hh.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>US(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function it(t){return new Ju({type:"optional",innerType:t})}var px=S("ZodExactOptional",(t,e)=>{T_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>US(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function fO(t){return new px({type:"optional",innerType:t})}var mO=S("ZodNullable",(t,e)=>{P_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>EC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function Wh(t){return new mO({type:"nullable",innerType:t})}function aB(t){return it(Wh(t))}var hO=S("ZodDefault",(t,e)=>{R_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>$C(t,r,o,n),t.unwrap=()=>t._zod.def.innerType,t.removeDefault=t.unwrap});function gO(t,e){return new hO({type:"default",innerType:t,get defaultValue(){return typeof e=="function"?e():A.shallowClone(e)}})}var yO=S("ZodPrefault",(t,e)=>{C_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>AC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function vO(t,e){return new yO({type:"prefault",innerType:t,get defaultValue(){return typeof e=="function"?e():A.shallowClone(e)}})}var fx=S("ZodNonOptional",(t,e)=>{O_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>kC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function wO(t,e){return new fx({type:"nonoptional",innerType:t,...A.normalizeParams(e)})}var bO=S("ZodSuccess",(t,e)=>{N_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>fC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function cB(t){return new bO({type:"success",innerType:t})}var _O=S("ZodCatch",(t,e)=>{D_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>TC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType,t.removeCatch=t.unwrap});function SO(t,e){return new _O({type:"catch",innerType:t,catchValue:typeof e=="function"?e:A.constantCatch(e)})}var xO=S("ZodNaN",(t,e)=>{z_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>lC(t,r,o,n)});function uB(t){return ES(xO,t)}var tg=S("ZodPipe",(t,e)=>{gh.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>PC(t,r,o,n),t.in=e.in,t.out=e.out});function BS(t,e){return new tg({type:"pipe",in:t,out:e})}var rg=S("ZodCodec",(t,e)=>{tg.init(t,e),Td.init(t,e)});function lB(t,e,r){return new rg({type:"pipe",in:t,out:e,transform:r.decode,reverseTransform:r.encode})}function dB(t){let e=t._zod.def;return new rg({type:"pipe",in:e.out,out:e.in,transform:e.reverseTransform,reverseTransform:e.transform})}var EO=S("ZodPreprocess",(t,e)=>{tg.init(t,e),AR.init(t,e)}),kO=S("ZodReadonly",(t,e)=>{j_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>RC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function IO(t){return new kO({type:"readonly",innerType:t})}var $O=S("ZodTemplateLiteral",(t,e)=>{M_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>dC(t,r,o,n)});function pB(t,e){return new $O({type:"template_literal",parts:t,...A.normalizeParams(e)})}var AO=S("ZodLazy",(t,e)=>{Pd.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>OC(t,r,o,n),t.unwrap=()=>t._zod.def.getter()});function TO(t){return new AO({type:"lazy",getter:t})}var PO=S("ZodPromise",(t,e)=>{L_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>CC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function fB(t){return new PO({type:"promise",innerType:t})}var RO=S("ZodFunction",(t,e)=>{U_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>hC(t,r,o,n)});function mB(t){return new RO({type:"function",input:Array.isArray(t?.input)?aO(t?.input):t?.input??Ae(dt()),output:t?.output??dt()})}var ng=S("ZodCustom",(t,e)=>{F_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>mC(t,r,o,n)});function hB(t){let e=new ot({check:"custom"});return e._zod.check=t,e}function mx(t,e){return RS(ng,t??(()=>!0),e)}function CO(t,e={}){return CS(ng,t,e)}function OO(t,e){return OS(t,e)}var gB=NS,yB=DS,NO=S("ZodInstanceOf",(t,e)=>{ng.init(t,e)},{properties(t,e){return this.check(Vd(t,e))}});function vB(t,e={}){let r=new NO({type:"custom",check:"custom",fn:o=>o instanceof t,abort:!0,...A.normalizeParams(e)});return r._zod.bag.Class=t,r._zod.check=o=>{o.value instanceof t||o.issues.push({code:"invalid_type",expected:t.name,input:o.value,inst:r,path:[...r._zod.def.path??[]]})},r}var wB=(...t)=>zS({Codec:rg,Boolean:rp,String:ep},...t);function bB(t){let e=TO(()=>tt([I(t),Ze(),Bt(),Gh(),Ae(e),at(I(),e)]));return e}function og(t,e){return new EO({type:"pipe",in:dx(t),out:e})}var zme={invalid_type:"invalid_type",too_big:"too_big",too_small:"too_small",invalid_format:"invalid_format",not_multiple_of:"not_multiple_of",unrecognized_keys:"unrecognized_keys",invalid_union:"invalid_union",invalid_key:"invalid_key",invalid_element:"invalid_element",invalid_value:"invalid_value",custom:"custom"};function jme(t){zt({customError:t})}function Mme(){return zt().customError}var DO;DO||(DO={});var Gu={};bt(Gu,{ZodISODate:()=>Qa,ZodISODateTime:()=>Ya,ZodISODuration:()=>tc,ZodISOTime:()=>ec,date:()=>Lme,datetime:()=>Ume,duration:()=>Vme,time:()=>Fme});function Ume(t){return Vh(Ya,t)}function Lme(t){return Hh(Qa,t)}function Fme(t){return Bh(ec,t)}function Vme(t){return Kh(tc,t)}var V={...ip,...FS,iso:Gu},Hme=new Set(["$schema","$ref","$defs","definitions","$id","id","$comment","$anchor","$vocabulary","$dynamicRef","$dynamicAnchor","type","enum","const","anyOf","oneOf","allOf","not","properties","required","additionalProperties","patternProperties","propertyNames","minProperties","maxProperties","items","prefixItems","additionalItems","minItems","maxItems","uniqueItems","contains","minContains","maxContains","minLength","maxLength","pattern","format","minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf","description","default","contentEncoding","contentMediaType","contentSchema","unevaluatedItems","unevaluatedProperties","if","then","else","dependentSchemas","dependentRequired","nullable","readOnly"]);function Bme(t,e){let r=t.$schema;return r==="https://json-schema.org/draft/2020-12/schema"?"draft-2020-12":r==="http://json-schema.org/draft-07/schema#"?"draft-7":r==="http://json-schema.org/draft-04/schema#"?"draft-4":e??"draft-2020-12"}function _B(t,e){return t.map((r,o)=>o<e?r:r.optional())}function Kme(t){return t.replace(/~1/g,"/").replace(/~0/g,"~")}function qme(t,e){if(!t.startsWith("#"))throw new Error("External $ref is not supported, only local refs (#/...) are allowed");let r=t.slice(1).split("/").filter(Boolean);if(r.length===0)return e.rootSchema;let o=e.version==="draft-2020-12"?"$defs":"definitions";if(r[0]===o){let n=r[1]===void 0?void 0:Kme(r[1]);if(!n||!e.defs[n])throw new Error(`Reference not found: ${t}`);return e.defs[n]}throw new Error(`Reference not found: ${t}`)}function Zme(t,e){return V.transform(o=>o).check(o=>{let n=o.value;if(typeof n!="object"||n===null||Array.isArray(n))return;let i=Object.getOwnPropertyNames(n);if(e.minProperties!==void 0&&i.length<e.minProperties&&o.issues.push({origin:"object",code:"too_small",minimum:e.minProperties,inclusive:!0,message:`Too small: expected object to have >=${e.minProperties} properties`,input:n,inst:t,continue:!0}),e.maxProperties!==void 0&&i.length>e.maxProperties&&o.issues.push({origin:"object",code:"too_big",maximum:e.maxProperties,inclusive:!0,message:`Too big: expected object to have <=${e.maxProperties} properties`,input:n,inst:t,continue:!0}),e.keySchema)for(let s of i){let a=e.keySchema.safeParse(s);a.success||o.issues.push({code:"invalid_key",origin:"record",issues:a.error.issues,input:s,path:[s],continue:!0})}}).pipe(t)}function zO(t,e){if(t===null)return"z";let r=typeof t;if(r!=="object"){if(r==="number"&&Number.isNaN(t))return null;let o=String(t);return`${r[0]}${o.length}:${o}`}if(e.has(t))return null;e.add(t);try{if(Array.isArray(t)){let i=[];for(let s of t){let a=zO(s,e);if(a===null)return null;i.push(a)}return`a${i.length}:[${i.join(",")}]`}let o=Object.keys(t).sort(),n=[];for(let i of o){let s=zO(t[i],e);if(s===null)return null;n.push(`${i.length}:${i}=${s}`)}return`o${n.length}:{${n.join(",")}}`}finally{e.delete(t)}}var Wme=new Set(["items","prefixItems","additionalItems","additionalProperties","contains","propertyNames","not","if","then","else","allOf","anyOf","oneOf","unevaluatedItems","unevaluatedProperties","contentSchema"]),Jme=new Set(["properties","patternProperties","dependentSchemas","dependencies","$defs","definitions"]);function ig(t){return typeof t!="object"||t===null?!1:Array.isArray(t)?t.some(ig):typeof t.$ref=="string"?!0:Object.entries(t).some(([e,r])=>Wme.has(e)?ig(r):!Jme.has(e)||typeof r!="object"||r===null?!1:Object.values(r).some(ig))}function SB(t){return t===1?"element":"elements"}function Gme(t,e){return V.transform(o=>o).check(o=>{let n=o.value;if(Array.isArray(n)){if(e.uniqueItems===!0){let i=new Map;for(let s=0;s<n.length;s++){let a=zO(n[s],new Set);if(a===null)continue;let c=i.get(a);if(c===void 0){i.set(a,s);continue}o.issues.push({code:"custom",message:`Array items must be unique: element at index ${s} duplicates the one at index ${c}`,input:n,path:[s],continue:!0})}}if(e.containsSchema){let i=e.minContains??1,s=e.maxContains!==void 0?e.maxContains+1:Number.POSITIVE_INFINITY,a=0;for(let c of n)if(e.containsSchema.safeParse(c).success&&++a>=s)break;a<i&&o.issues.push({code:"custom",message:`Array must contain at least ${i} matching ${SB(i)}; found ${a}`,input:n,continue:!0}),e.maxContains!==void 0&&a>e.maxContains&&o.issues.push({code:"custom",message:`Array must contain at most ${e.maxContains} matching ${SB(e.maxContains)}`,input:n,continue:!0})}}}).pipe(t)}function xB(t,e){if(t!==!1)return t===void 0||t===!0?V.any():pn(t,e)}var Xme=/^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/;function EB(t,e){if(t.not!==void 0){if(typeof t.not=="object"&&Object.keys(t.not).length===0)return V.never();throw new Error("not is not supported in Zod (except { not: {} } for never)")}if(t.unevaluatedItems!==void 0)throw new Error("unevaluatedItems is not supported");if(t.unevaluatedProperties!==void 0)throw new Error("unevaluatedProperties is not supported");if(t.if!==void 0||t.then!==void 0||t.else!==void 0)throw new Error("Conditional schemas (if/then/else) are not supported");if(t.dependentSchemas!==void 0||t.dependentRequired!==void 0)throw new Error("dependentSchemas and dependentRequired are not supported");if(t.$ref){let n=t.$ref;if(e.refs.has(n))return e.refs.get(n);if(e.processing.has(n))return V.lazy(()=>{if(!e.refs.has(n))throw new Error(`Circular reference not resolved: ${n}`);return e.refs.get(n)});e.processing.add(n);let i=qme(n,e),s=pn(i,e);return e.refs.set(n,s),e.processing.delete(n),s}if(t.enum!==void 0){let n=t.enum;if(e.version==="openapi-3.0"&&t.nullable===!0&&n.length===1&&n[0]===null)return V.null();if(n.length===0)return V.never();if(n.length===1)return V.literal(n[0]);if(n.every(s=>typeof s=="string"))return V.enum(n);let i=n.map(s=>V.literal(s));return i.length<2?i[0]:V.union([i[0],i[1],...i.slice(2)])}if(t.const!==void 0)return V.literal(t.const);let r=t.type;if(Array.isArray(r)){let n=r.map(i=>{let s={...t,type:i};return EB(s,e)});return n.length===0?V.never():n.length===1?n[0]:V.union(n)}if(!r)return V.any();let o;switch(r){case"string":{let n=V.string();if(t.format){let i=t.format;i==="email"?n=n.check(V.email()):i==="uri"||i==="uri-reference"?n=n.check(V.url()):i==="uuid"||i==="guid"?n=n.check(V.uuid()):i==="date-time"?n=n.check(V.iso.datetime({offset:!0})):i==="date"?n=n.check(V.iso.date()):i==="time"?n=n.check(V.regex(Xme)):i==="duration"?n=n.check(V.iso.duration()):i==="hostname"?n=n.check(V.hostname()):i==="ipv4"?n=n.check(V.ipv4()):i==="ipv6"?n=n.check(V.ipv6()):i==="mac"?n=n.check(V.mac()):i==="cidr"?n=n.check(V.cidrv4()):i==="cidr-v6"?n=n.check(V.cidrv6()):i==="base64"?n=n.check(V.base64()):i==="base64url"?n=n.check(V.base64url()):i==="e164"?n=n.check(V.e164()):i==="credit_card"?n=n.check(V.creditCard()):i==="iban"?n=n.check(V.iban()):i==="jwt"?n=n.check(V.jwt()):i==="emoji"?n=n.check(V.emoji()):i==="nanoid"?n=n.check(V.nanoid()):i==="cuid"?n=n.check(V.cuid()):i==="cuid2"?n=n.check(V.cuid2()):i==="ulid"?n=n.check(V.ulid()):i==="xid"?n=n.check(V.xid()):i==="ksuid"&&(n=n.check(V.ksuid()))}typeof t.minLength=="number"&&(n=n.min(t.minLength)),typeof t.maxLength=="number"&&(n=n.max(t.maxLength)),t.pattern&&(n=n.regex(new RegExp(t.pattern))),o=n;break}case"number":case"integer":{let n=r==="integer"?V.number().int():V.number();typeof t.minimum=="number"&&t.exclusiveMinimum!==!0&&(n=n.min(t.minimum)),typeof t.maximum=="number"&&t.exclusiveMaximum!==!0&&(n=n.max(t.maximum)),typeof t.exclusiveMinimum=="number"?n=n.gt(t.exclusiveMinimum):t.exclusiveMinimum===!0&&typeof t.minimum=="number"&&(n=n.gt(t.minimum)),typeof t.exclusiveMaximum=="number"?n=n.lt(t.exclusiveMaximum):t.exclusiveMaximum===!0&&typeof t.maximum=="number"&&(n=n.lt(t.maximum)),typeof t.multipleOf=="number"&&(n=n.multipleOf(t.multipleOf)),o=n;break}case"boolean":{o=V.boolean();break}case"null":{o=V.null();break}case"object":{let n={},i=t.properties||{},s=new Set(t.required||[]),a=typeof t.additionalProperties=="object"?pn(t.additionalProperties,e):void 0;for(let[d,f]of Object.entries(i)){let p=pn(f,e);_r(n,d,s.has(d)?p:p.optional())}if(t.patternProperties){let d=t.patternProperties,f=Object.keys(d),p=[];for(let g of f){let y=pn(d[g],e),w=V.string().regex(new RegExp(g));p.push(V.looseRecord(w,y))}let m=[];if(Object.keys(n).length>0&&m.push(V.object(n).passthrough()),m.push(...p),m.length===0)o=V.object({}).passthrough();else if(m.length===1)o=m[0];else{let g=V.intersection(m[0],m[1]);for(let y=2;y<m.length;y++)g=V.intersection(g,m[y]);o=g}if(t.additionalProperties===!1){let g=Object.keys(n),y=f.map(b=>new RegExp(b)),w=o;o=o.check(b=>{if(!yo(b.value))return;let _=[];for(let k of Object.keys(b.value))g.includes(k)||y.some($=>$.test(k))||_.push(k);_.length&&b.issues.push({code:"unrecognized_keys",keys:_,input:b.value,inst:w})})}}else{let d=V.object(n);t.additionalProperties===!1?o=d.strict():a?o=d.catchall(a):o=d.passthrough()}let c=t.propertyNames!==void 0&&t.propertyNames!==!0,u=typeof t.minProperties=="number"?t.minProperties:void 0,l=typeof t.maxProperties=="number"?t.maxProperties:void 0;if(c||u!==void 0||l!==void 0){let d;if(c){let f=typeof t.propertyNames=="object"&&t.propertyNames.type===void 0?{type:"string",...t.propertyNames}:t.propertyNames;d=pn(f,e)}o=Zme(o,{keySchema:d,minProperties:u,maxProperties:l})}break}case"array":{let n=t.prefixItems,i=t.items;if(n&&Array.isArray(n)){let s=typeof t.minItems=="number"?t.minItems:0,a=n.map(d=>pn(d,e)),c=_B(a,s),u=Array.isArray(i)?void 0:xB(i,e),l=V.tuple(c);o=u?l.rest(u):l,typeof t.minItems=="number"&&(o=o.check(V.minLength(t.minItems))),typeof t.maxItems=="number"&&(o=o.check(V.maxLength(t.maxItems)))}else if(Array.isArray(i)){let s=typeof t.minItems=="number"?t.minItems:0,a=i.map(d=>pn(d,e)),c=_B(a,s),u=xB(t.additionalItems,e),l=V.tuple(c);o=u?l.rest(u):l,typeof t.minItems=="number"&&(o=o.check(V.minLength(t.minItems))),typeof t.maxItems=="number"&&(o=o.check(V.maxLength(t.maxItems)))}else if(i!==void 0){let s=pn(i,e),a=V.array(s);typeof t.minItems=="number"&&(a=a.min(t.minItems)),typeof t.maxItems=="number"&&(a=a.max(t.maxItems)),o=a}else o=V.array(V.any());(t.uniqueItems===!0||t.contains!==void 0)&&(o=Gme(o,{uniqueItems:t.uniqueItems===!0,containsSchema:t.contains!==void 0?pn(t.contains,e):void 0,minContains:typeof t.minContains=="number"?t.minContains:void 0,maxContains:typeof t.maxContains=="number"?t.maxContains:void 0}));break}default:throw new Error(`Unsupported type: ${r}`)}return o}function pn(t,e){if(typeof t=="boolean")return t?V.any():V.never();let r=EB(t,e),o=t.type||t.enum!==void 0||t.const!==void 0;if(t.anyOf&&Array.isArray(t.anyOf)){let a=t.anyOf.map(u=>pn(u,e)),c=V.union(a);r=o?V.intersection(r,c):c}if(t.oneOf&&Array.isArray(t.oneOf)){let a=t.oneOf.map(u=>pn(u,e)),c=V.xor(a);r=o?V.intersection(r,c):c}if(t.allOf&&Array.isArray(t.allOf))if(t.allOf.length===0)r=o?r:V.any();else{let a=o?r:pn(t.allOf[0],e),c=o?0:1;for(let u=c;u<t.allOf.length;u++)a=V.intersection(a,pn(t.allOf[u],e));r=a}t.nullable===!0&&e.version==="openapi-3.0"&&(r=V.nullable(r)),t.readOnly===!0&&(r=V.readonly(r)),t.default!==void 0&&(r=r.default(t.default));let n={},i=["$id","id","$comment","$anchor","$vocabulary","$dynamicRef","$dynamicAnchor"];for(let a of i)a in t&&(n[a]=t[a]);let s=["contentEncoding","contentMediaType","contentSchema"];for(let a of s)a in t&&(n[a]=t[a]);if(t.type==="object"&&t.$ref===void 0){t.propertyNames!==void 0&&!ig(t.propertyNames)&&(n.propertyNames=t.propertyNames);for(let a of["minProperties","maxProperties"])t[a]!==void 0&&(n[a]=t[a])}if(t.type==="array"&&t.$ref===void 0){t.contains!==void 0&&!ig(t.contains)&&(n.contains=t.contains);for(let a of["uniqueItems","minContains","maxContains"])t[a]!==void 0&&(n[a]=t[a])}for(let a of Object.keys(t))Hme.has(a)||_r(n,a,t[a]);return Object.keys(n).length>0&&e.registry.add(r,n),t.description&&(r=r.describe(t.description)),r}function kB(t,e){if(typeof t=="boolean")return t?V.any():V.never();let r;try{r=JSON.parse(JSON.stringify(t))}catch{throw new Error("fromJSONSchema input is not valid JSON (possibly cyclic); use $defs/$ref for recursive schemas")}let o=Bme(r,e?.defaultTarget),n=r.$defs||r.definitions||{},i={version:o,defs:n,refs:new Map,processing:new Set,rootSchema:r,registry:e?.registry??Sr};return pn(r,i)}var IB=Symbol("z.visit/resolving");function sg(t,e){let r=typeof e=="function"?e:(s,a)=>{let c=e[s._zod.def.type];return c?c(s,a):s},o=new Map;function n(s){let a=o.get(s);if(a===IB)return new Pd({type:"lazy",getter:()=>o.get(s)});if(a!==void 0)return a;o.set(s,IB);let c=i(s),u=r(c,c!==s);return o.set(s,u),u}function i(s){let a=s._zod.def,c=a.type;switch(c){case"object":{let u=a.shape,l=Object.keys(u),d=!1,f={};for(let m of l){let g=n(u[m]);g!==u[m]&&(d=!0),f[m]=g}let p=a.catchall;return a.catchall&&(p=n(a.catchall),p!==a.catchall&&(d=!0)),d?qe(s,{...a,shape:f,catchall:p}):s}case"array":{let u=n(a.element);return u===a.element?s:qe(s,{...a,element:u})}case"tuple":{let u=a.items,l=!1,d=[];for(let p of u){let m=n(p);m!==p&&(l=!0),d.push(m)}let f=a.rest;return a.rest&&(f=n(a.rest),f!==a.rest&&(l=!0)),l?qe(s,{...a,items:d,rest:f}):s}case"record":case"map":{let u=n(a.keyType),l=n(a.valueType);return u===a.keyType&&l===a.valueType?s:qe(s,{...a,keyType:u,valueType:l})}case"set":{let u=n(a.valueType);return u===a.valueType?s:qe(s,{...a,valueType:u})}case"union":{let u=a.options,l=!1,d=[];for(let f of u){let p=n(f);p!==f&&(l=!0),d.push(p)}return l?qe(s,{...a,options:d}):s}case"intersection":{let u=n(a.left),l=n(a.right);return u===a.left&&l===a.right?s:qe(s,{...a,left:u,right:l})}case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":{let u=n(a.innerType);return u===a.innerType?s:qe(s,{...a,innerType:u})}case"pipe":{let u=n(a.in),l=n(a.out);return u===a.in&&l===a.out?s:qe(s,{...a,in:u,out:l})}case"function":{let u=n(a.input),l=n(a.output);return u===a.input&&l===a.output?s:qe(s,{...a,input:u,output:l})}case"lazy":{let u=a.getter,{_cachedInner:l,...d}=a;return qe(s,{...d,getter:()=>n(u())})}case"template_literal":case"string":case"number":case"int":case"boolean":case"bigint":case"symbol":case"undefined":case"null":case"void":case"never":case"any":case"unknown":case"date":case"nan":case"enum":case"literal":case"file":case"transform":case"custom":return s;default:return s}}return n(t)}function $B(t){return sg(t,{object:e=>e.partial(),union:e=>{let r=e._zod.def;return r.discriminator===void 0?e:tt(r.options)}})}function Yme(t,e){if(!e?.length)return t;let r=t._zod.def;return qe(t,go(r,{checks:[...r.checks??[],...e]}),{parent:!0})}function AB(t){return Yme(t.out,t.checks)}function Qme(t){return t.in._zod.traits.has("$ZodTransform")?AB(t):t.in}function TB(t){return sg(t,{pipe:e=>Qme(e._zod.def),default:(e,r)=>r?it(e._zod.def.innerType):e,catch:(e,r)=>r?e._zod.def.innerType:e})}function PB(t){return sg(t,{pipe:e=>AB(e._zod.def),prefault:(e,r)=>r?e._zod.def.innerType:e})}var jO={};bt(jO,{bigint:()=>nhe,boolean:()=>rhe,date:()=>ohe,number:()=>the,string:()=>ehe});function ehe(t){return UR(ep,t)}function the(t){return FR(tp,t)}function rhe(t){return VR(rp,t)}function nhe(t){return HR(np,t)}function ohe(t){return BR(Xh,t)}var ag={name:"@tomato414941/foundation",version:"29.0.0",description:"Manage Foundation resources and use them in local commands.",type:"module",engines:{node:">=24"},bin:{foundation:"dist/cli.mjs"},files:["dist/cli.mjs"],repository:{type:"git",url:"git+https://github.com/tomato414941/foundation.git",directory:"cli"},publishConfig:{access:"public",registry:"https://registry.npmjs.org/"},license:"MIT"};typeof window<"u"&&h.config({jitless:!0});function RB(t){let e=/^(ssh-ed25519|ssh-rsa|ecdsa-sha2-nistp(?:256|384|521))[ \t]+([A-Za-z0-9+/]+={0,2})(?:[ \t]+[^\r\n\0]*)?$/.exec(t.trim());if(!e)return null;try{let r=Uint8Array.from(atob(e[2]),a=>a.charCodeAt(0)),o=new DataView(r.buffer),n=0,i=()=>{if(n+4>r.length)throw new Error("Invalid SSH key.");let a=o.getUint32(n);if(n+=4,n+a>r.length)throw new Error("Invalid SSH key.");let c=r.subarray(n,n+a);return n+=a,c},s=a=>new TextDecoder().decode(a);if(s(i())!==e[1])return null;if(e[1]==="ssh-ed25519"){if(i().length!==32)return null}else if(e[1]==="ssh-rsa"){let a=i(),c=i();if(!a.length||c.length<256||c.length>1025)return null}else{let a=s(i()),c=i(),u={nistp256:65,nistp384:97,nistp521:133};if(e[1]!=="ecdsa-sha2-"+a||c[0]!==4||c.length!==u[a])return null}return n===r.length?r:null}catch{return null}}var cg=h.string().trim().max(8192).refine(t=>RB(t)!==null,"Use an OpenSSH public key from a .pub file.");function MO(t){if(!RB(t))throw new Error("Use an OpenSSH public key from a .pub file.");let[e,r]=t.trim().split(/[ \t]+/);return{algorithm:e,key:r,publicKey:e+" "+r}}var sp=h.string().max(32).regex(/^[a-z_][a-z0-9_-]*$/,"Use a lowercase account name."),hx=h.string().min(1).max(253).regex(/^[A-Za-z0-9_.:]+(?:-[A-Za-z0-9_.:]+)*$/,"Use a host name or IP address."),gx=h.string().min(1).max(1024).regex(/^[A-Za-z0-9._/%-]+$/).refine(t=>!t.split("/").includes("..")&&!/%(?!u)/.test(t)&&!t.endsWith("/"),"Use a file path, with %u for the account."),RFe=h.string().min(1).max(500).regex(/^[A-Za-z0-9.:*?/!_-]+(?:,[A-Za-z0-9.:*?/!_-]+)*$/,"Use comma-separated host or address patterns."),yx=h.string().regex(/^SHA256:[A-Za-z0-9+/]{43}$/);var ap=new TextEncoder,cp=new TextDecoder,CB=new TextDecoder("utf-8",{fatal:!0}),vx=2**32;function fn(...t){let e=t.reduce((n,{length:i})=>n+i,0),r=new Uint8Array(e),o=0;for(let n of t)r.set(n,o),o+=n.length;return r}function UO(t,e,r){if(e<0||e>=vx)throw new RangeError(`value must be >= 0 and <= ${vx-1}. Received ${e}`);t.set([e>>>24,e>>>16,e>>>8,e&255],r)}function LO(t){let e=Math.floor(t/vx),r=t%vx,o=new Uint8Array(8);return UO(o,e,0),UO(o,r,4),o}function wx(t){let e=new Uint8Array(4);return UO(e,t),e}var she=/[^\x00-\x7f]/;function kr(t){if(typeof t=="string"&&t.length>=128){if(she.test(t))throw new TypeError("non-ASCII string encountered in encode()");return ap.encode(t)}let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++){let o=t.charCodeAt(r);if(o>127)throw new TypeError("non-ASCII string encountered in encode()");e[r]=o}return e}function OB(t,e=!1){if(Uint8Array.prototype.toBase64)return t.toBase64({alphabet:e?"base64url":"base64",omitPadding:e});let r=32768,o=[];for(let i=0;i<t.length;i+=r)o.push(String.fromCharCode.apply(null,t.subarray(i,i+r)));let n=btoa(o.join(""));return e?n.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_"):n}function NB(t,e=!1){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(t,{alphabet:e?"base64url":"base64"});if(e){if(t.includes("+")||t.includes("/"))throw new TypeError("Invalid base64url");t=t.replace(/-/g,"+").replace(/_/g,"/")}let r=atob(t),o=new Uint8Array(r.length);for(let n=0;n<r.length;n++)o[n]=r.charCodeAt(n);return o}async function bx(t,e){let r=`SHA-${t.slice(-3)}`;return new Uint8Array(await crypto.subtle.digest(r,e))}var oa=class extends Error{static code="ERR_JOSE_GENERIC";code="ERR_JOSE_GENERIC";constructor(e,r){super(e,r),this.name=this.constructor.name,Error.captureStackTrace?.(this,this.constructor)}};var Xu=class extends oa{static code="ERR_JOSE_ALG_NOT_ALLOWED";code="ERR_JOSE_ALG_NOT_ALLOWED"},ct=class extends oa{static code="ERR_JOSE_NOT_SUPPORTED";code="ERR_JOSE_NOT_SUPPORTED"},rc=class extends oa{static code="ERR_JWE_DECRYPTION_FAILED";code="ERR_JWE_DECRYPTION_FAILED";constructor(e="decryption operation failed",r){super(e,r)}},U=class extends oa{static code="ERR_JWE_INVALID";code="ERR_JWE_INVALID"},kt=class extends oa{static code="ERR_JWS_INVALID";code="ERR_JWS_INVALID"};var ug=class extends oa{static code="ERR_JWK_INVALID";code="ERR_JWK_INVALID"};var _x=class extends oa{static code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";constructor(e="signature verification failed",r){super(e,r)}};var ahe="The input to be decoded is not correctly encoded.";function Yu(t){try{return NB(typeof t=="string"?t:cp.decode(t),!0)}catch(e){throw new TypeError(ahe,{cause:e})}}function Rt(t){return OB(typeof t=="string"?ap.encode(t):t,!0)}function Gn(t,e){if(!(t instanceof Uint8Array))throw new TypeError(`${e} must be an instance of Uint8Array`)}function Zt(t){if(typeof t!="object"||t===null||Object.prototype.toString.call(t)!=="[object Object]")return!1;let e=Object.getPrototypeOf(t);return e===null||Object.getPrototypeOf(e)===null}function nc(...t){let e=new Set;for(let r of t)if(r)for(let o of Object.keys(r)){if(e.has(o))return!1;e.add(o)}return!0}function wo(t,e){if(t!==void 0)throw new TypeError(`${e} can only be called once`)}function Rn(t,e,r){try{return Yu(t)}catch{throw new r(`Failed to base64url decode the ${e}`)}}function Sx(t,e,r){try{return kr(t)}catch{throw new r(`The ${e} is not a valid base64url string`)}}function up(t,e,r){let o;try{o=JSON.parse(CB.decode(Yu(t)))}catch{throw new e(r)}if(!Zt(o))throw new e(r);return o}var xx={__proto__:null,b64:!0},Ex={__proto__:null};function lg(t,e){if(e!==void 0&&(!Array.isArray(e)||e.some(r=>typeof r!="string")))throw new TypeError(`"${t}" option must be an array of strings`);return e===void 0?void 0:new Set(e)}function kx(t,e){let{crit:r}=e??{};if(Array.isArray(r)&&new Set(r).size!==r.length)throw new t('"crit" (Critical) Header Parameter MUST NOT contain duplicate values')}function oc(t,e,r,o,n){if(n.crit!==void 0&&o?.crit===void 0)throw new t('"crit" (Critical) Header Parameter MUST be integrity protected');if(!o||o.crit===void 0)return[];if(!Array.isArray(o.crit)||o.crit.length===0||o.crit.some(s=>typeof s!="string"||s.length===0))throw new t('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');let i=r===void 0?e:{__proto__:null,...r,...e};for(let s of o.crit){if(!(s in i))throw new ct(`Extension Header Parameter "${s}" is not recognized`);if(!Object.hasOwn(n,s)||n[s]===void 0)throw new t(`Extension Header Parameter "${s}" is missing`);if(i[s]&&(!Object.hasOwn(o,s)||o[s]===void 0))throw new t(`Extension Header Parameter "${s}" MUST be integrity protected`)}return o.crit}function Ix(t,e){if(e.includes("b64")){let r=t.b64;if(typeof r!="boolean")throw new kt('The "b64" (base64url-encode payload) Header Parameter must be a boolean');return r}return!0}function Qu(t,e){let r,o;try{r=JSON.stringify(e),o=JSON.parse(r)}catch(n){throw new t("JOSE Header is not valid JSON",{cause:n})}if(!Zt(o))throw new t("JOSE Header is not a JSON object");return[o,r]}var che=t=>t[Symbol.toStringTag],uhe=(t,e,r)=>{let{alg:o}=t;if(e.use!==void 0){let n=r==="sign"||r==="verify"?"sig":"enc";if(e.use!==n)throw new TypeError(`Invalid key for this operation, its "use" must be "${n}" when present`)}if(e.alg!==void 0&&e.alg!==o)throw new TypeError(`Invalid key for this operation, its "alg" must be "${o}" when present`);if(Array.isArray(e.key_ops)){let n=r==="encrypt"||r==="decrypt"?t.ops?.[r==="encrypt"?0:1]:r;if(n&&!e.key_ops.includes(n))throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${n}" when present`)}};async function oi(t,e,r){let{alg:o,secret:n}=t,i=r==="decrypt"||r==="sign";if(n&&e instanceof Uint8Array)return e;let s,a;if(Zt(e)){if(s=qO(e),typeof s.kty!="string")throw DB(o,e,n);if(!(n?s.kty==="oct"&&typeof s.k=="string":s.kty!=="oct"&&(i?s.kty==="AKP"&&typeof s.priv=="string"||typeof s.d=="string":s.d===void 0&&s.priv===void 0)))throw new TypeError(n?'JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present':`JSON Web Key for this operation must be a ${i?"private":"public"} JWK`);if(uhe(t,s,r),s.kty==="oct")return Yu(s.k);if(!Object.isFrozen(e)){let{key_ops:l}=e;Array.isArray(l)&&Object.freeze(l),Object.freeze(e)}}else{if(!HO(e))throw DB(o,e,n);let l=n?"secret":i?"private":"public";if(e.type!==l&&(n||["secret","public","private"].includes(e.type)))throw new TypeError(`${che(e)} instances must be of type "${l}" for the ${o} algorithm`);if(ic(e))return e;if(a=e,a.type==="secret")return a.export()}FO||=new WeakMap;let c=e,u=FO.get(c);if(u?.[o])return u[o];if(u||FO.set(c,u={}),a&&typeof a.toCryptoKey=="function"){let l=a.type==="public",d=lhe[a.asymmetricKeyDetails?.namedCurve],f=t.resolve?.({crv:d,asymmetricKeyType:a.asymmetricKeyType})??t.subtle;return u[o]=a.toCryptoKey(f,l,t.usages[l?0:1])}return s??=a.export({format:"jwk"}),s.alg=o,u[o]=await dp(t,s)}var FO,lhe={__proto__:null,prime256v1:"P-256",secp384r1:"P-384",secp521r1:"P-521"};function Ax(t){if(!ic(t))throw new Error("CryptoKey instance expected")}var ic=t=>{if(t?.[Symbol.toStringTag]==="CryptoKey")return!0;try{return t instanceof CryptoKey}catch{return!1}},VO=t=>t?.[Symbol.toStringTag]==="KeyObject",HO=t=>ic(t)||VO(t);function zB(t,e,...r){if(r.length>2){let o=r.pop();t+=`one of type ${r.join(", ")}, or ${o}.`}else r.length===2?t+=`one of type ${r[0]} or ${r[1]}.`:t+=`of type ${r[0]}.`;return e==null?t+=` Received ${e}`:typeof e=="function"&&e.name?t+=` Received function ${e.name}`:typeof e=="object"&&e!=null&&e.constructor?.name&&(t+=` Received an instance of ${e.constructor.name}`),t}var ia=(t,...e)=>zB("Key must be ",t,...e);function DB(t,e,r){let o=["CryptoKey","KeyObject","JSON Web Key"];return r&&o.push("Uint8Array"),new TypeError(zB(`Key for the ${t} algorithm must be `,e,...o))}var $x=(t,e="algorithm.name")=>new TypeError(`CryptoKey does not support this operation, its ${e} must be ${t}`);function BO(t,e){if(e&&!t.usages.includes(e))throw new TypeError(`CryptoKey does not support this operation, its usages must include ${e}.`)}function lp(t,e){let{modulusLength:r}=e.algorithm;if(typeof r!="number"||r<2048)throw new TypeError(`${t} requires key modulusLength to be 2048 bits or larger`)}function KO(t,e,r){let o=t.algorithm;if(o.name!==e.name)throw $x(e.name);if(e.hash&&o.hash?.name!==e.hash)throw $x(e.hash,"algorithm.hash");if(e.namedCurve&&o.namedCurve!==e.namedCurve)throw $x(e.namedCurve,"algorithm.namedCurve");if(e.length!==void 0&&o.length!==e.length)throw $x(e.length,"algorithm.length");BO(t,r)}function Tx(t){return{__proto__:null,...t}}function qO(t){let e=Tx(t);if(e.ext!==void 0&&typeof e.ext!="boolean")throw new TypeError('"ext" (Extractable) Parameter must be a boolean');if(e.key_ops!==void 0){let r=e.key_ops,o=Array.isArray(r)?[...r]:void 0;if(!o||o.some(n=>typeof n!="string")||new Set(o).size!==o.length)throw new TypeError('"key_ops" (Key Operations) Parameter must be an array of unique strings');e.key_ops=o}return e}function Px(t){if(t!==void 0&&typeof t!="boolean")throw new TypeError('"extractable" option must be a boolean');return t}async function dp(t,e,r){if(!t.kty.includes(e.kty))throw new ct('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');let o=t.resolve?.({kty:e.kty,crv:e.crv})??t.subtle,n=!!(e.d||e.priv),i={...e,ext:r??e.ext};return i.kty!=="AKP"&&delete i.alg,delete i.use,crypto.subtle.importKey("jwk",i,o,i.ext??!n,e.key_ops??t.usages[n?1:0])}async function ii(t,e,r,o=!1){return t instanceof Uint8Array&&(t=await crypto.subtle.importKey("raw",t,e,o,[r])),KO(t,e,r),t}var el=t=>crypto.getRandomValues(new Uint8Array(t.cekBits>>3));function Rx(t,e){let r=t.byteLength<<3;if(r!==e)throw new U(`Invalid Content Encryption Key length. Expected ${e} bits, got ${r} bits`)}var dhe=t=>crypto.getRandomValues(new Uint8Array(t.ivBits>>3));function jB(t,e){if(e.length<<3!==t.ivBits)throw new U("Invalid Initialization Vector length")}async function MB(t,e,r){if(!(e instanceof Uint8Array))throw new TypeError(ia(e,"Uint8Array"));let o=t.cekBits>>1,n=await crypto.subtle.importKey("raw",e.subarray(o>>3),"AES-CBC",!1,[r]),i=await crypto.subtle.importKey("raw",e.subarray(0,o>>3),{hash:`SHA-${o<<1}`,name:"HMAC"},!1,["sign"]);return[n,i,o]}async function UB(t,e,r){return new Uint8Array((await crypto.subtle.sign("HMAC",t,e)).slice(0,r>>3))}async function phe(t,e,r,o,n){let[i,s,a]=await MB(t,r,"encrypt"),c=new Uint8Array(await crypto.subtle.encrypt({iv:o,name:"AES-CBC"},i,e)),u=fn(n,o,c,LO(n.length*8)),l=await UB(s,u,a);return{ciphertext:c,tag:l,iv:o}}async function fhe(t,e){let r={name:"HMAC",hash:"SHA-256"},o=await crypto.subtle.generateKey(r,!1,["sign","verify"]),n=await crypto.subtle.sign(r,o,t);return crypto.subtle.verify(r,o,n,e)}async function mhe(t,e,r,o,n,i){let[s,a,c]=await MB(t,e,"decrypt"),u=fn(i,o,r,LO(i.length*8)),l=await UB(a,u,c);try{if(await fhe(n,l))return new Uint8Array(await crypto.subtle.decrypt({iv:o,name:"AES-CBC"},s,r))}catch{}throw new rc}async function Cx(t,e,r,o,n){if(!ic(r)&&!(r instanceof Uint8Array))throw new TypeError(ia(r,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(o?jB(t,o):o=dhe(t),r instanceof Uint8Array&&Rx(r,t.cekBits),t.cbc)return phe(t,e,r,o,n);let i=await ii(r,t.subtle,"encrypt"),s=new Uint8Array(await crypto.subtle.encrypt({additionalData:n,iv:o,name:"AES-GCM",tagLength:128},i,e));return{ciphertext:s.subarray(0,-16),tag:s.subarray(-16),iv:o}}async function Ox(t,e,r,o,n,i){if(!ic(e)&&!(e instanceof Uint8Array))throw new TypeError(ia(e,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(!o)throw new U("JWE Initialization Vector missing");if(!n)throw new U("JWE Authentication Tag missing");if(!t.cbc&&n.length!==16)throw new U("Invalid Authentication Tag length");if(jB(t,o),e instanceof Uint8Array&&Rx(e,t.cekBits),t.cbc)return mhe(t,e,r,o,n,i);let s=await ii(e,t.subtle,"decrypt");try{return new Uint8Array(await crypto.subtle.decrypt({additionalData:i,iv:o,name:"AES-GCM",tagLength:128},s,fn(r,n)))}catch{throw new rc}}function dg(t){let e={__proto__:null};for(let r in t)e[r]={...t[r],alg:r};return e}var hhe=[["encrypt","wrapKey"],["decrypt","unwrapKey"]],ghe=[[],["deriveBits"]],zx=[[],[]];function Nx(t){return{kty:["RSA"],mode:"key-encryption",subtle:{name:"RSA-OAEP",hash:`SHA-${t}`},usages:hhe,ops:["wrapKey","unwrapKey"]}}function Dx(t){return{kty:["EC","OKP"],mode:t,subtle:{name:"ECDH"},resolve:({kty:e,crv:r,asymmetricKeyType:o})=>{if(r==="X25519"||o==="x25519")return{name:"X25519"};if(e==="OKP")throw new ct('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');return{name:"ECDH",namedCurve:r}},usages:ghe,ops:[void 0,"deriveBits"]}}function pp(t,e=!1){return{kty:["oct"],mode:"key-wrapping",secret:!0,subtle:{name:e?"AES-GCM":"AES-KW",length:t},usages:zx,ops:e?["encrypt","decrypt"]:["wrapKey","unwrapKey"]}}function ZO(){return{kty:["oct"],mode:"key-wrapping",secret:!0,subtle:{name:"PBKDF2"},usages:zx,ops:["deriveBits","deriveBits"]}}var sa=dg({dir:{kty:["oct"],mode:"direct-encryption",secret:!0,subtle:{name:"AES-GCM"},usages:zx,ops:["encrypt","decrypt"]},"RSA-OAEP":Nx(1),"RSA-OAEP-256":Nx(256),"RSA-OAEP-384":Nx(384),"RSA-OAEP-512":Nx(512),"ECDH-ES":Dx("direct-key-agreement"),"ECDH-ES+A128KW":Dx("key-agreement-with-key-wrapping"),"ECDH-ES+A192KW":Dx("key-agreement-with-key-wrapping"),"ECDH-ES+A256KW":Dx("key-agreement-with-key-wrapping"),A128KW:pp(128),A192KW:pp(192),A256KW:pp(256),A128GCMKW:pp(128,!0),A192GCMKW:pp(192,!0),A256GCMKW:pp(256,!0),"PBES2-HS256+A128KW":ZO(),"PBES2-HS384+A192KW":ZO(),"PBES2-HS512+A256KW":ZO()}),yhe=["encrypt","decrypt"];function fp(t,e=!1){return{kty:["oct"],secret:!0,subtle:{name:e?"AES-CBC":"AES-GCM",length:t},usages:zx,ops:yhe,cekBits:t,ivBits:e?128:96,cbc:e}}var vhe=dg({A128GCM:fp(128),A192GCM:fp(192),A256GCM:fp(256),"A128CBC-HS256":fp(256,!0),"A192CBC-HS384":fp(384,!0),"A256CBC-HS512":fp(512,!0)});function LB(t,e){throw new ct(`Invalid or unsupported "${t}" (JWE ${e}) header value`)}function si(t){return(typeof t=="string"?sa[t]:void 0)??LB("alg","Algorithm")}function ai(t){return t.mode==="key-wrapping"||t.mode==="key-encryption"||t.mode==="key-agreement-with-key-wrapping"}function tl(t){return(typeof t=="string"?vhe[t]:void 0)??LB("enc","Encryption Algorithm")}function FB(t,e){if(t.algorithm.name!=="ECDH"&&t.algorithm.name!=="X25519")throw new TypeError("CryptoKey does not support this operation, its algorithm.name must be ECDH or X25519");BO(t,e)}async function whe(t,e,r){let o=await ii(e,si(t).subtle,"wrapKey",!0),n=await crypto.subtle.importKey("raw",r,{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.wrapKey("raw",n,o,"AES-KW"))}async function bhe(t,e,r){let o=await ii(e,si(t).subtle,"unwrapKey",!0),n=await crypto.subtle.unwrapKey("raw",r,o,"AES-KW",{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.exportKey("raw",n))}function HB(t,e,r){KO(e,si(t).subtle,r),lp(t,e)}async function BB(t,e,r,o){if(!(t instanceof Uint8Array)||t.length<8)throw new U("PBES2 Salt Input must be 8 or more octets");if(!Number.isSafeInteger(r)||Math.sign(r)!==1)throw new U("PBES2 Count Input must be a positive integer");let n=fn(kr(e),Uint8Array.of(0),t),i=parseInt(e.slice(13,16),10),s={hash:`SHA-${e.slice(8,11)}`,iterations:r,name:"PBKDF2",salt:n},a=await ii(o,si(e).subtle,"deriveBits");return new Uint8Array(await crypto.subtle.deriveBits(s,a,i))}function WO(t){return fn(wx(t.length),t)}async function _he(t,e,r){let o=e>>3,n=32,i=Math.ceil(o/n),s=new Uint8Array(i*n);for(let a=1;a<=i;a++){let c=await bx("sha256",fn(wx(a),t,r));s.set(c,(a-1)*n)}return s.slice(0,o)}async function KB(t,e,r,o,n=new Uint8Array,i=new Uint8Array){FB(t),FB(e,"deriveBits");let s=fn(WO(kr(r)),WO(n),WO(i),wx(o)),a=new Uint8Array(await crypto.subtle.deriveBits({name:t.algorithm.name,public:t},e,t.algorithm.name==="X25519"?256:Math.ceil(parseInt(t.algorithm.namedCurve.slice(-3),10)/8)<<3));return _he(a,o,s)}function qB(t){Ax(t);let e=t.algorithm.namedCurve;if(e!=="P-256"&&e!=="P-384"&&e!=="P-521"&&t.algorithm.name!=="X25519")throw new ct("ECDH with the provided key is not allowed or not supported by your javascript runtime")}function jx(t,e){let r=t[e];if(r!==void 0){if(typeof r!="string")throw new U(`JOSE Header "${e}" (Agreement Party${e==="apu"?"U":"V"}Info) invalid`);return Rn(r,e,U)}}function ZB(t,e){if(!(t===void 0||e===void 0||t.byteLength!==e.byteLength)){for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return;throw new U('JOSE Header "apu" and "apv" values must be distinct')}}function She(t){if(t===void 0)throw new U("JWE Encrypted Key missing")}function VB(t){if(t!==void 0)throw new U("Encountered unexpected JWE Encrypted Key")}function xhe(t){if(t!==void 0&&t!==1/0&&(!Number.isSafeInteger(t)||t<1))throw new TypeError("maxPBES2Count must be a positive safe integer or Infinity")}async function WB(t,e,r,o,n,i){let{alg:s}=t,a=t.mode;if(a==="direct-encryption")return VB(o),r;let c=a==="direct-key-agreement";switch(c?VB(o):She(o),t.subtle.name){case"ECDH":{let{epk:u}=n;if(!Zt(u)||["d","k","p","q","dp","dq","qi","oth","priv"].some(m=>Object.hasOwn(u,m)))throw new U('JOSE Header "epk" (Ephemeral Public Key) missing or invalid');qB(r);let l=await dp(t,u),d=jx(n,"apu"),f=jx(n,"apv");ZB(d,f);let p=await KB(l,r,c?e.alg:s,c?e.cekBits:parseInt(s.slice(-5,-2),10),d,f);if(c)return p;r=p;break}case"RSA-OAEP":return Ax(r),HB(s,r,"decrypt"),new Uint8Array(await crypto.subtle.decrypt("RSA-OAEP",r,o));case"PBKDF2":{if(typeof n.p2c!="number")throw new U('JOSE Header "p2c" (PBES2 Count) missing or invalid');xhe(i);let u=i??1e4;if(n.p2c>u)throw new U('JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds');if(typeof n.p2s!="string")throw new U('JOSE Header "p2s" (PBES2 Salt) missing or invalid');let l=Rn(n.p2s,"p2s",U);r=await BB(l,s,n.p2c,r);break}case"AES-GCM":{if(typeof n.iv!="string")throw new U('JOSE Header "iv" (Initialization Vector) missing or invalid');if(typeof n.tag!="string")throw new U('JOSE Header "tag" (Authentication Tag) missing or invalid');let u=Rn(n.iv,"iv",U),l=Rn(n.tag,"tag",U);if(u.byteLength!==12)throw new U("Invalid Initialization Vector length");if(l.byteLength!==16)throw new U("Invalid Authentication Tag length");return Ox(tl(s.slice(0,-2)),r,o,u,l,new Uint8Array)}}return bhe(s.slice(-6),r,o)}async function Mx(t,e,r,o,n,i={}){let{alg:s,mode:a}=t,c=ai(t);if(n!==void 0&&!c)throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${s}`);let u=await oi(a==="direct-encryption"?e:t,r,"encrypt");if(a==="direct-encryption")return[u,void 0,void 0];let l=c?n??el(e):void 0;l&&Rx(l,e.cekBits);let d,f;switch(t.subtle.name){case"ECDH":{qB(u);let{apu:p,apv:m}=i;p!==void 0&&Gn(p,'"apu"'),m!==void 0&&Gn(m,'"apv"');let g=p??jx(o,"apu"),y=m??jx(o,"apv");ZB(g,y);let w;i.epk!==void 0?w=await oi(t,i.epk,"decrypt"):w=(await crypto.subtle.generateKey(u.algorithm,!0,["deriveBits"])).privateKey;let b=crypto.subtle,_=w;if(!_.extractable){if(typeof b.getPublicKey!="function")throw new TypeError('CryptoKey for "epk" must be extractable');_=await b.getPublicKey(w,[])}let{x:k,y:$,crv:D,kty:K}=await b.exportKey("jwk",_),te=a==="direct-key-agreement",Ie=await KB(u,w,te?e.alg:s,te?e.cekBits:parseInt(s.slice(-5,-2),10),g,y),xe={x:k,crv:D,kty:K};if(K==="EC"&&(xe.y=$),f={epk:xe},p!==void 0&&(f.apu=Rt(p)),m!==void 0&&(f.apv=Rt(m)),te)return[Ie,void 0,f];u=Ie;break}case"RSA-OAEP":{Ax(u),HB(s,u,"encrypt"),d=new Uint8Array(await crypto.subtle.encrypt("RSA-OAEP",u,l));break}case"PBKDF2":{let{p2c:p=2048,p2s:m=crypto.getRandomValues(new Uint8Array(16))}=i;u=await BB(m,s,p,u),f={p2c:p,p2s:Rt(m)};break}case"AES-GCM":{let p=i.iv===void 0?crypto.getRandomValues(new Uint8Array(12)):i.iv;if(!(p instanceof Uint8Array))throw new TypeError('"iv" must be an instance of Uint8Array');let m=await Cx(tl(s.slice(0,-2)),l,u,p,new Uint8Array);d=m.ciphertext,f={iv:Rt(m.iv),tag:Rt(m.tag)}}}if(d??=await whe(s.slice(-6),u,l),!(d instanceof Uint8Array)||!d.byteLength)throw new TypeError("JWE key management algorithm did not produce an Encrypted Key");return[l,d,f]}function Ux(t,e){if(t.zip!==void 0&&t.zip!=="DEF")throw new ct('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');if(t.zip!==void 0&&!e?.zip)throw new U('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.')}function JB(t){if(typeof globalThis[t]>"u")throw new ct(`JWE "zip" (Compression Algorithm) Header Parameter requires the ${t} API.`)}async function GB(t,e,r=1/0){let o=t.writable.getWriter();o.write(e).catch(()=>{}),o.close().catch(()=>{});let n=[],i=0,s=t.readable.getReader();for(;;){let{value:a,done:c}=await s.read();if(c)break;if(n.push(a),i+=a.byteLength,r!==1/0&&i>r)throw new U("Decompressed plaintext exceeded the configured limit")}return fn(...n)}async function XB(t){return JB("CompressionStream"),GB(new CompressionStream("deflate-raw"),t)}async function YB(t,e){return JB("DecompressionStream"),GB(new DecompressionStream("deflate-raw"),t,e)}function QB(t){let{aad:e,ciphertext:r,iv:o,protected:n,tag:i,unprotected:s}=t;if(o!==void 0&&(typeof o!="string"||!o))throw new U("JWE Initialization Vector incorrect type");if(typeof r!="string")throw new U("JWE Ciphertext missing or incorrect type");if(i!==void 0&&(typeof i!="string"||!i))throw new U("JWE Authentication Tag incorrect type");if(n!==void 0&&typeof n!="string")throw new U("JWE Protected Header incorrect type");if(e!==void 0&&(typeof e!="string"||!e))throw new U("JWE AAD incorrect type");if(s!==void 0&&!Zt(s))throw new U("JWE Shared Unprotected Header incorrect type");return{aad:e,ciphertext:r,iv:o,protected:n,tag:i,unprotected:s===void 0?void 0:{...s}}}function eK(t){let e,r;try{let{header:o}=t;if(Zt(o)){r=o.alg;let i=Object.keys(o);i.includes("alg")||(r=void 0),e=Object.fromEntries(i.map(s=>[s,s==="alg"?r:o[s]]))}else e=o;let{encrypted_key:n}=t;return[{encrypted_key:n,header:e},r]}catch(o){return[void 0,r,o]}}function tK(t){let{encrypted_key:e,header:r}=t;if(e!==void 0&&typeof e!="string")throw new U("JWE Encrypted Key incorrect type");if(r!==void 0&&!Zt(r))throw new U("JWE Per-Recipient Unprotected Header incorrect type");if(t.protected===void 0&&r===void 0&&t.unprotected===void 0)throw new U("JOSE Header missing")}function JO(t){let{protected:e,ciphertext:r,iv:o,tag:n,aad:i}=t,s;return e!==void 0&&(s=up(e,U,"JWE Protected Header is invalid")),[s,Rn(r,"ciphertext",U),o!==void 0?Rn(o,"iv",U):void 0,n!==void 0?Rn(n,"tag",U):void 0,Sx((e??"")+(i!==void 0?`.${i}`:""),"aad",U)]}function Lx(t){return[t&&lg("keyManagementAlgorithms",t.keyManagementAlgorithms),t&&lg("contentEncryptionAlgorithms",t.contentEncryptionAlgorithms),t?.crit,t?.maxPBES2Count,t?.maxDecompressedLength]}async function GO(t,e,r,o=JO(t)){let[n,i,s,a,c]=o,{header:u,unprotected:l,aad:d}=t,f;if(u!==void 0||l!==void 0){if(!nc(n,u,l))throw new U("JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint");f={...n,...u,...l}}else f=n??{};let[p,m,g,y,w]=e,{encrypted_key:b}=t;oc(U,Ex,g,n,f),Ux(f,n);let{alg:_,enc:k}=f;if(typeof _!="string"||!_)throw new U("missing JWE Algorithm (alg) in JWE Header");let $=sa[_];if(b===""&&(!$||!ai($)))throw new U("JWE Encrypted Key incorrect type");let D=$?.mode==="integrated-encryption";if(!D&&(typeof k!="string"||!k))throw new U("missing JWE Encryption Algorithm (enc) in JWE Header");if(p&&!p.has(_)||!p&&_.startsWith("PBES2"))throw new Xu('"alg" (Algorithm) Header Parameter value not allowed');let K;if(D){if(k!==void 0)throw new U('JWE "enc" (Encryption Algorithm) Header Parameter must not be present for integrated encryption');if(s?.byteLength)throw new U("JWE Initialization Vector must be empty for integrated encryption");if(a?.byteLength)throw new U("JWE Authentication Tag must be empty for integrated encryption")}else{if(m&&!m.has(k))throw new Xu('"enc" (Encryption Algorithm) Header Parameter value not allowed');K=tl(k)}let te;if(b!==void 0)try{te=Rn(b,"encrypted_key",U)}catch($e){if(!$||!ai($))throw $e;te=new Uint8Array}let Ie=!1;typeof r=="function"&&(r=await r(n,t),Ie=!0);let xe=$??si(_);ai(xe)&&te===void 0&&(te=new Uint8Array);let Qe=await oi(xe.mode==="direct-encryption"?K:xe,r,"decrypt"),Ve;if(xe.mode==="integrated-encryption")Ve=await xe.decrypt(Qe,te,i,c,n,f);else{let $e=K,J;try{J=await WB(xe,$e,Qe,te,f,y),ai(xe)&&J instanceof Uint8Array&&J.byteLength<<3!==$e.cekBits&&(J=el($e))}catch(Tt){if(Tt instanceof TypeError||Tt instanceof U||Tt instanceof ct)throw Tt;J=el($e)}Ve=await Ox($e,J,i,s,a,c)}if(f.zip==="DEF"){let $e=w??25e4;if($e===0)throw new ct('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');if($e!==1/0&&(!Number.isSafeInteger($e)||$e<1))throw new TypeError("maxDecompressedLength must be 0, a positive safe integer, or Infinity");Ve=await YB(Ve,$e).catch(J=>{throw J instanceof U?J:new U("Failed to decompress plaintext",{cause:J})})}return{plaintext:Ve,...n&&{protectedHeader:n},...d!==void 0&&{additionalAuthenticatedData:Rn(d,"aad",U)},...l&&{sharedUnprotectedHeader:l},...u&&{unprotectedHeader:u},...Ie&&{key:Qe}}}async function rK(t,e,r){if(t instanceof Uint8Array&&(t=cp.decode(t)),typeof t!="string")throw new U("Compact JWE must be a string or Uint8Array");let{0:o,1:n,2:i,3:s,4:a,length:c}=t.split(".");if(c!==5)throw new U("Invalid Compact JWE");return GO({ciphertext:s,iv:i||void 0,protected:o,tag:a||void 0,encrypted_key:n||void 0},e,r)}async function pg(t,e,r){return rK(t,Lx(r),e)}async function XO(t,e,r){if(!Zt(t))throw new U("General JWE must be an object");let o=t.recipients;if(!Array.isArray(o))throw new U("JWE Recipients missing or incorrect type");let n=Array.from(o);if(!n.every(Zt))throw new U("JWE Recipients missing or incorrect type");if(!n.length)throw new U("JWE Recipients has no members");let i,s,a;try{i=Lx(r),s=QB(t),a=JO(s)}catch{throw new rc}let c=n.map(u=>eK(u));if(n.length>1)for(let[,u]of c){let l=a[0]?.alg??u??s.unprotected?.alg,d=typeof l=="string"?sa[l]:void 0;if(d&&!ai(d))throw new U(`"${l}" alg may only have a single recipient`)}for(let[u]of c)if(u)try{let l={...s,...u};return tK(l),await GO(l,i,e,a)}catch{}throw new rc}function Fx(t,e,r){if(!nc(t,e,r))throw new U("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint")}function YO(t,e,r=!1){if(!t[1]&&!t[2]&&!t[3])throw new U("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");e!==void 0&&(t[8]=e?.crit);let[,o,n,i,s,a,c,u,l]=t;if(s!==void 0&&Gn(s,"JWE Additional Authenticated Data"),a!==void 0&&Gn(a,"JWE Content Encryption Key"),c!==void 0&&Gn(c,"JWE Initialization Vector"),!r&&o!==void 0&&(o=Qu(U,o)[0],t[1]=o),n!==void 0&&(n=Qu(U,n)[0],t[2]=n),!r&&i!==void 0&&(i=Qu(U,i)[0],t[3]=i),u!==void 0&&!Zt(u))throw new TypeError("JWE Key Management Parameters must be an object");Fx(o,n,i);let d={...o,...n,...i};kx(U,o),oc(U,Ex,l,o,d),Ux(d,o);let{alg:f,enc:p}=d;if(typeof f!="string"||!f)throw new U('JWE "alg" (Algorithm) Header Parameter missing or invalid');let m=sa[f];if(m?.mode==="integrated-encryption"){if(p!==void 0)throw new U('JWE "enc" (Encryption Algorithm) Header Parameter must not be present for integrated encryption');if(a!==void 0)throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${f}`);if(c!==void 0)throw new TypeError(`setInitializationVector cannot be called with JWE "alg" (Algorithm) Header ${f}`);return[d,void 0,m]}if(typeof p!="string"||!p)throw new U('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');return[d,tl(p),m]}async function QO(t,e,r){let[o,n,i]=e,[s,a,c,u,l,d,f,p,,m]=t,g=a,y=c,w=i??si(o.alg),b,_,k;w.mode==="integrated-encryption"?k=await oi(w,r,"encrypt"):[k,b,_]=await Mx(w,n,r,o,d,p),_&&(m?y=y?{...y,..._}:_:g=g?{...g,..._}:_,Fx(g,y,u));let $=g?Rt(JSON.stringify(g)):"",D=l?.byteLength?Rt(l):void 0,K=kr(D?`${$}.${D}`:$),te=s;o.zip==="DEF"&&(te=await XB(te).catch($e=>{throw new U("Failed to compress plaintext",{cause:$e})}));let Ie,xe,Qe;w.mode==="integrated-encryption"?[b,Ie]=await w.encrypt(k,te,K,g,o,p):{ciphertext:Ie,tag:xe,iv:Qe}=await Cx(n,te,k,f,K);let Ve={ciphertext:Rt(Ie)};return Qe&&(Ve.iv=Rt(Qe)),xe&&(Ve.tag=Rt(xe)),b?.byteLength&&(Ve.encrypted_key=Rt(b)),D&&(Ve.aad=D),g&&(Ve.protected=$),u&&(Ve.unprotected=u),y&&(Ve.header=y),Ve}async function nK(t,e,r){return QO(t,YO(t,r),e)}function oK(t){return[t.protected,t.encrypted_key,t.iv,t.ciphertext,t.tag].join(".")}var eN=class{#e;state;constructor(e,r,o){this.#e=e,this.state=[void 0,void 0,r,o]}setUnprotectedHeader(e){return wo(this.state[0],"setUnprotectedHeader"),this.state[0]=e,this}setKeyManagementParameters(e){return wo(this.state[1],"setKeyManagementParameters"),this.state[1]=e,this}addRecipient(...e){return this.#e.addRecipient(...e)}encrypt(...e){return this.#e.encrypt(...e)}done(){return this.#e}},fg=class{#e;#t=[];#r;#n;#o;constructor(e){this.#e=e}addRecipient(e,r){let o=new eN(this,e,r?.crit);return this.#t.push(o),o}setProtectedHeader(e){return wo(this.#r,"setProtectedHeader"),this.#r=e,this}setSharedUnprotectedHeader(e){return wo(this.#n,"setSharedUnprotectedHeader"),this.#n=e,this}setAdditionalAuthenticatedData(e){return this.#o=e,this}async encrypt(){if(!this.#t.length)throw new U("at least one recipient must be added");Gn(this.#e,"plaintext");let e=this.#t.length>1,r,o=this.#r,n=this.#n,i=[];for(let m of this.#t){let[g,y,w,b]=m.state,_=[this.#e,o,g,n,this.#o,void 0,void 0,y,b,e],k=YO(_,void 0,i.length>0);i.length||(o=_[1],n=_[3]),i.push([_,k,w]);let[{alg:$,enc:D},,K]=k;if(e&&K&&!ai(K))throw new U(`"${$}" alg may only have a single recipient`);if(!r)r=D;else if(r!==D)throw new U('JWE "enc" (Encryption Algorithm) Header Parameter must be the same for all recipients')}for(let[,m]of i)m[2]??=si(m[0].alg);let[s,a,c]=i[0],u=e?el(a[1]):void 0;s[5]=u;let{encrypted_key:l,header:d,...f}=await QO(s,a,c),p={...f,recipients:[{}]};l&&(p.recipients[0].encrypted_key=l),d&&(p.recipients[0].header=d);for(let m=1;m<i.length;m++){let[g,[y,w,b],_]=i[m],k=g[2],[,$,D]=await Mx(b,w,_,y,u,g[7]),K={encrypted_key:Rt($)};if(k||D){let te={...k,...D};D&&Fx(g[1],te,g[3]),K.header=te}p.recipients.push(K)}return p}};var mg=[["verify"],["sign"]];function tN(t){let e={name:"HMAC",hash:`SHA-${t}`};return{kty:["oct"],secret:!0,subtle:e,signing:e,usages:mg}}function mp(t,e){let r={name:e?"RSA-PSS":"RSASSA-PKCS1-v1_5",hash:`SHA-${t}`};return{kty:["RSA"],subtle:r,signing:e?{...r,saltLength:e}:r,usages:mg,minRsaBits:2048}}function rN(t,e){return{kty:["EC"],crv:t,subtle:{name:"ECDSA",namedCurve:t},signing:{name:"ECDSA",hash:`SHA-${e}`},usages:mg}}function iK(){let t={name:"Ed25519"};return{kty:["OKP"],crv:"Ed25519",subtle:t,signing:t,usages:mg}}function nN(t){let e={name:`ML-DSA-${t}`};return{kty:["AKP"],subtle:e,signing:e,usages:mg}}var oN=dg({HS256:tN(256),HS384:tN(384),HS512:tN(512),RS256:mp(256),RS384:mp(384),RS512:mp(512),PS256:mp(256,32),PS384:mp(384,48),PS512:mp(512,64),ES256:rN("P-256",256),ES384:rN("P-384",384),ES512:rN("P-521",512),EdDSA:iK(),Ed25519:iK(),"ML-DSA-44":nN(44),"ML-DSA-65":nN(65),"ML-DSA-87":nN(87)});function Vx(t){let e=typeof t=="string"?oN[t]:void 0;if(!e)throw new ct(`alg ${t} is not supported either by JOSE or your javascript runtime`);return e}function sK(t){return[t&&lg("algorithms",t.algorithms),t?.crit]}function Ehe(t){return t===void 0?{}:up(t,kt,"JWS Protected Header is invalid")}function khe(t){try{return kr(t)}catch{throw new kt("JWS Compact Serialization payload must use only ASCII characters")}}async function Ihe(t,e,r,o,n){let{protected:i,header:s,payload:a}=t,c=n??Ehe(i);if(!nc(c,s))throw new kt("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");let u={...c,...s},l=Ix(c,oc(kt,xx,e[1],c,u)),{alg:d}=u;if(typeof d!="string"||!d)throw new kt('JWS "alg" (Algorithm) Header Parameter missing or invalid');if(e[0]&&!e[0].has(d))throw new Xu('"alg" (Algorithm) Header Parameter value not allowed');if(l){if(typeof a!="string")throw new kt("JWS Payload must be a string")}else if(typeof a!="string"&&!(a instanceof Uint8Array))throw new kt("JWS Payload must be a string or an Uint8Array instance");let f=l||typeof a!="string"?a:o(a),p=!1;typeof r=="function"&&(r=await r(c,t),p=!0);let m=Vx(d),g=fn(i!==void 0?kr(i):new Uint8Array,kr("."),typeof f=="string"?e[2]??=Sx(f,"payload",kt):f),y=Rn(t.signature,"signature",kt),w=await oi(m,r,"verify"),b=await ii(w,m.subtle,"verify");m.minRsaBits&&lp(m.alg,b);let _=!1;try{_=await crypto.subtle.verify(m.signing,b,y,g)}catch{}if(!_)throw new _x;let k={payload:typeof f=="string"?Rn(f,"payload",kt):f};return i!==void 0&&(k.protectedHeader=c),s!==void 0&&(k.unprotectedHeader=s),p?[{...k,key:w},l]:[k,l]}async function aK(t,e,r){if(t instanceof Uint8Array&&(t=cp.decode(t)),typeof t!="string")throw new kt("Compact JWS must be a string or Uint8Array");let{0:o,1:n,2:i,length:s}=t.split(".");if(s!==3)throw new kt("Invalid Compact JWS");return Ihe({payload:n,protected:o,signature:i},e,r,khe)}async function iN(t,e,r){let[o]=await aK(t,sK(r),e);return o}var hp=class{#e;constructor(e){Gn(e,"plaintext"),this.#e=[e]}setContentEncryptionKey(e){return wo(this.#e[5],"setContentEncryptionKey"),this.#e[5]=e,this}setInitializationVector(e){return wo(this.#e[6],"setInitializationVector"),this.#e[6]=e,this}setProtectedHeader(e){return wo(this.#e[1],"setProtectedHeader"),this.#e[1]=e,this}setKeyManagementParameters(e){return wo(this.#e[7],"setKeyManagementParameters"),this.#e[7]=e,this}async encrypt(e,r){return oK(await nK([...this.#e],e,r))}};async function $he(t,e,r){let[o,n,i,s]=t,a="";if(n!==void 0){let w=Qu(kt,n);n=w[0],a=Rt(w[1])}if(i!==void 0&&(i=Qu(kt,i)[0]),!n&&!i)throw new kt("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");if(!nc(n,i))throw new kt("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");let c={...n,...i};kx(kt,n);let u=Ix(n,oc(kt,xx,s,n,c));u||r?.();let{alg:l}=c;if(typeof l!="string"||!l)throw new kt('JWS "alg" (Algorithm) Header Parameter missing or invalid');let d=Vx(l),f="",p=o,m;if(u){let w=t[4];w?(f=w[0]??=Rt(o),p=w[1]??=kr(f)):(f=Rt(o),m=ap.encode(`${a}.${f}`))}m??=fn(kr(a),kr("."),p);let g=await ii(await oi(d,e,"sign"),d.subtle,"sign");d.minRsaBits&&lp(d.alg,g);let y={signature:Rt(new Uint8Array(await crypto.subtle.sign(d.signing,g,m))),payload:f};return n&&(y.protected=a),i&&(y.header=i),[y,u]}async function cK(t,e,r,o,n){let[i]=await $he([t,e,void 0,r],o,n);return`${i.protected}.${i.payload}.${i.signature}`}var hg=class{#e;#t;constructor(e){Gn(e,"payload"),this.#e=e}setProtectedHeader(e){return wo(this.#t,"setProtectedHeader"),this.#t=e,this}async sign(e,r){return cK(this.#e,this.#t,r?.crit,e,()=>{throw new TypeError("use the flattened module for creating JWS with b64: false")})}};var sN='"alg" (Algorithm)';function aN(t='JWK "alg" (Algorithm) Parameter'){throw new ct(`Invalid or unsupported ${t} value`)}function gg(t,e){return(typeof t=="string"?oN[t]??sa[t]:void 0)??aN(e)}async function sc(t){if(VO(t))if(t.type==="secret")t=t.export();else return t.export({format:"jwk"});if(t instanceof Uint8Array)return{kty:"oct",k:Rt(t)};if(!ic(t))throw new TypeError(ia(t,"CryptoKey","KeyObject","Uint8Array"));if(!t.extractable)throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");let e=await crypto.subtle.exportKey("jwk",t);delete e.ext,delete e.key_ops,delete e.use,e.kty!=="AKP"&&delete e.alg;for(let r of Object.keys(e))e[r]===void 0&&delete e[r];return e}var aa=(t,e)=>{if(typeof t!="string"||!t)throw new ug(`${e} missing or invalid`)};async function cN(t,e){let r;if(Zt(t)){if(r=Tx(t),typeof r.kty!="string")throw new TypeError(ia(t,"CryptoKey","KeyObject","JSON Web Key"))}else if(HO(t))r=Tx(await sc(t));else throw new TypeError(ia(t,"CryptoKey","KeyObject","JSON Web Key"));if(e??="sha256",e!=="sha256"&&e!=="sha384"&&e!=="sha512")throw new TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');let o;switch(r.kty){case"AKP":aa(r.alg,'"alg" (Algorithm) Parameter'),aa(r.pub,'"pub" (Public key) Parameter'),o={alg:r.alg,kty:r.kty,pub:r.pub};break;case"EC":aa(r.crv,'"crv" (Curve) Parameter'),aa(r.x,'"x" (X Coordinate) Parameter'),aa(r.y,'"y" (Y Coordinate) Parameter'),o={crv:r.crv,kty:r.kty,x:r.x,y:r.y};break;case"OKP":aa(r.crv,'"crv" (Subtype of Key Pair) Parameter'),aa(r.x,'"x" (Public Key) Parameter'),o={crv:r.crv,kty:r.kty,x:r.x};break;case"RSA":aa(r.e,'"e" (Exponent) Parameter'),aa(r.n,'"n" (Modulus) Parameter'),o={e:r.e,kty:r.kty,n:r.n};break;case"oct":if(typeof r.k!="string")throw new ug('"k" (Key Value) Parameter missing or invalid');o={k:r.k,kty:r.kty};break;default:throw new ct('"kty" (Key Type) Parameter missing or unsupported')}let n=kr(JSON.stringify(o));return Rt(await bx(e,n))}async function bo(t,e,r){if(!Zt(t))throw new TypeError("JWK must be an object");let o=qO(t),n=Px(r?.extractable),{alg:i}=o;if(e??=i,o.kty!=="oct"&&!e)throw new TypeError('"alg" argument is required when "jwk.alg" is not present');switch(o.kty){case"oct":if(typeof o.k!="string")throw new TypeError('missing "k" (Key Value) Parameter value');return Yu(o.k);case"AKP":{if(typeof i!="string"||!i)throw new TypeError('missing "alg" (Algorithm) Parameter value');if(e!==i)throw new TypeError("JWK alg and alg option value mismatch");return dp(gg(e),o,n)}case"RSA":case"EC":case"OKP":return dp(gg(e),o,n);default:throw new ct('Unsupported "kty" (Key Type) Parameter value')}}function uN(t){let e;if(typeof t=="string"){let o=t.split(".");(o.length===3||o.length===5)&&([e]=o)}else if(typeof t=="object"&&t)if("protected"in t)e=t.protected;else throw new TypeError("Token does not contain a Protected Header");let r="Invalid Token or Protected Header formatting";if(typeof e!="string"||!e)throw new TypeError(r);return up(e,TypeError,r)}function Ahe(t){let e=t?.modulusLength??2048;if(typeof e!="number"||!Number.isInteger(e)||e<2048)throw new ct("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");return e}async function yg(t,e){let r=Px(e?.extractable),o=gg(t,sN);o.secret&&aN(sN);let n;if(o.resolve){let i=e?.crv??"P-256";if(!["P-256","P-384","P-521","X25519"].includes(i))throw new ct("Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, and X25519");n=o.resolve({crv:i})}else{if(o.crv!==void 0&&e?.crv!==void 0&&e.crv!==o.crv)throw new ct(`Invalid or unsupported crv option provided, the only supported value for ${t} is ${o.crv}`);n=o.kty[0]==="RSA"?{...o.subtle,publicExponent:Uint8Array.of(1,0,1),modulusLength:Ahe(e)}:o.subtle}return crypto.subtle.generateKey(n,r??!1,[...o.usages[1],...o.usages[0]])}var pK=h.string().regex(/^[a-z]{2}(?:-gov)?-[a-z]+-\d$/),fK=h.string().max(2e3).regex(/^arn:aws(?:-us-gov|-cn)?:iam::\d{12}:role\/.+/),uK=h.string().min(1).max(128),lK=h.string().min(1).max(16384),The=h.discriminatedUnion("kind",[h.object({kind:h.literal("access_key"),accessKeyId:uK,secretAccessKey:lK}).strict(),h.object({kind:h.literal("session"),accessKeyId:uK,secretAccessKey:lK,sessionToken:h.string().min(1).max(16384),expiresAt:h.number().int().positive().max(Number.MAX_SAFE_INTEGER)}).strict(),h.object({kind:h.literal("environment")}).strict()]),Phe=h.object({arn:fK,externalId:h.string().min(2).max(1224).regex(/^[\w+=,.@:\/-]+$/).optional()}).strict(),ca=h.object({authentication:The,region:pK,role:Phe.optional()}).strict(),Hx=h.object({accountId:h.string().regex(/^\d{12}$/),principalId:h.string().min(1).max(256),arn:h.string().max(2e3).regex(/^arn:aws(?:-us-gov|-cn)?:(?:iam|sts)::\d{12}:.+/)}).strict(),Bx=ca.extend({sourceIdentity:Hx.optional(),identity:Hx.optional()}).strict();function gp(t){return t.includes(":assumed-role/")?t.slice(0,t.lastIndexOf("/")):t}function dK(t){return{...t,arn:gp(t.arn)}}function mK(t){return{authentication:t.authentication.kind,region:t.region,role:t.role??null,...t.sourceIdentity?{sourceIdentity:dK(t.sourceIdentity)}:{},...t.identity?{identity:dK(t.identity)}:{}}}var Kx=h.object({authentication:h.enum(["access_key","session","environment"]),region:pK,sourceAccountId:h.string().regex(/^\d{12}$/).optional(),sourceArn:h.string().max(2e3).optional(),roleArn:fK.optional(),expiresAt:h.number().int().positive().optional()}).strict();function hK(t){return{authentication:t.authentication.kind,region:t.region,...t.sourceIdentity?{sourceAccountId:t.sourceIdentity.accountId,sourceArn:t.sourceIdentity.arn}:{},...t.role?{roleArn:t.role.arn}:{},...t.authentication.kind==="session"?{expiresAt:t.authentication.expiresAt}:{}}}var gK=h.object({method:h.enum(["GET","POST","PUT","DELETE","PATCH"]),path:h.string().min(1).max(1e3).regex(/^\/[^\s\u0000]*$/)}).strict(),vg=h.object({account:h.string().min(1),identities:h.array(h.string()),user:h.string().nullable(),description:h.string().nullable(),roles:h.array(h.string()).nullable(),credentialId:h.number().int().positive(),rules:h.array(gK),allowedIPs:h.array(h.string()).nullable(),expiresAt:h.number().nullable()}).strict();function yK(t){return t.map(e=>{let r=e.match(/^(GET|POST|PUT|DELETE|PATCH) (\/[^\s\u0000]*)$/);if(!r)throw new Error("Use one HTTP method and API path for each OVH permission.");return gK.parse({method:r[1],path:r[2]})})}typeof window<"u"&&h.config({jitless:!0});var E=h.uuid(),me=h.string().trim().min(1).max(200).regex(/^[^\u0000-\u001f\u007f]+$/u),Ne=h.iso.datetime(),Xn=h.json(),tr=h.record(h.string(),Xn),vK=h.enum(["ja","en"]),wK=h.enum(["read","create","update","delete","share","transfer","reveal","use","manage_credentials","manage_billing","export"]);var bK=h.enum(["variable","connection","service","method","app","object","keyring","ssh_key","ssh_host"]),mn=h.object({kty:h.literal("EC"),crv:h.literal("P-256"),x:h.string().min(40).max(50),y:h.string().min(40).max(50)}).strict(),Rhe=h.object({alg:h.literal("dir"),enc:h.literal("A256GCM"),sub:E}).strict(),_g=h.string().max(16384).regex(/^[A-Za-z0-9_-]+\.\.[A-Za-z0-9_-]{16}\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]{22}$/).refine(t=>{try{return Rhe.safeParse(uN(t)).success}catch{return!1}},"Use an A256GCM JWE for the wrapped encryption key.").brand(),dr=h.object({protected:h.string().max(2048),iv:h.string().max(64),ciphertext:h.string().max(2e6),tag:h.string().max(64),aad:h.string().max(2048).optional(),recipients:h.array(h.object({encrypted_key:h.string().max(2048),header:h.object({kid:E,epk:mn.optional(),alg:h.string().optional()}).passthrough()})).min(1).max(100)}).strict(),fHe=h.object({id:E,name:me,publicKey:mn}),nl=h.object({id:E,name:me,owner:h.object({id:E,name:me}).nullable(),createdAt:Ne,permissions:h.array(wK),createKinds:h.array(bK),publicKey:mn.nullable()}),_K=h.object({id:E,kind:h.enum(["passkey","email","key"]),name:h.string(),createdAt:Ne,lastUsedAt:Ne.nullable(),expiresAt:Ne.nullable(),canOpen:h.boolean()}),lN=h.string().regex(/^[a-z][a-z_]*[a-z]$/).max(64),Che=h.object({subjectId:E,relation:lN,objectId:E}).strict(),SK=h.enum(["principal",...bK.options]),xK=Che.extend({objectType:SK,subjectName:me,objectName:me,createdAt:Ne}),mHe=h.object({error:h.object({code:h.string(),message:h.string(),details:Xn.optional()})}),hHe=h.object({ok:h.literal(!0)}),Ohe=h.object({value:h.string().min(1).max(200),label:h.string().min(1).max(200),values:h.record(h.string().regex(/^[a-zA-Z][a-zA-Z0-9_]*$/),h.string()).default({})}).strict(),Wx=h.object({name:h.string().regex(/^[a-zA-Z][a-zA-Z0-9_]*$/),label:h.string(),secret:h.boolean().optional(),inputType:h.enum(["text","password","file"]).optional(),required:h.boolean().optional(),placeholder:h.string().optional(),note:h.string().optional(),pattern:h.string().optional(),choices:h.array(Ohe).min(1).max(100).optional(),defaultValue:h.string().max(1e3).optional(),when:h.object({field:h.string(),values:h.array(h.string()).min(1)}).strict().optional(),visibility:h.enum(["application","connection"]).optional()}).superRefine((t,e)=>{let r=t.choices??[];new Set(r.map(o=>o.value)).size!==r.length&&e.addIssue({code:"custom",path:["choices"],message:"Use a unique value for each choice."})}),dN=h.record(h.string().regex(/^[A-Z_][A-Z0-9_]*$/),h.string()),Nhe=h.record(h.string().regex(/^[A-Z_][A-Z0-9_]*$/),h.union([h.string(),h.array(h.union([h.string().max(8192),h.object({pointer:h.string().max(1e3)}).strict()])).min(1).max(32)])),pN=h.object({values:h.array(h.object({id:h.string(),name:h.string(),description:h.string().optional()})).optional(),default:h.array(h.string()).default([]),required:h.array(h.string()).optional(),separator:h.string().default(" "),docs:h.url().optional()}),rl=h.string().min(1).max(4096),Zx=h.union([h.string(),h.array(h.string()).min(1)]),Cn="urn:ietf:params:oauth:grant-type:device_code",Dhe=h.object({browserTokenExchange:h.enum(["available","unavailable","unknown"]).optional(),application:h.enum(["required","implicit"]).default("required"),grantType:h.enum(["authorization_code","client_credentials",Cn]).optional(),issuer:h.url().optional(),registrationUrl:h.url().optional(),authorizeUrl:rl.optional(),deviceAuthorizationUrl:rl.optional(),tokenUrl:rl,identity:h.object({url:rl.optional(),from:h.enum(["token","app"]).optional(),method:h.enum(["GET","POST"]).default("GET"),id:Zx.default("/id"),name:Zx.default("/name"),headers:h.record(h.string(),h.string()).default({})}).optional(),clientAuth:h.enum(["body","basic","none"]).default("body"),pkce:h.boolean().default(!0),tokenFormat:h.enum(["form","json"]).default("form"),okPointer:h.string().optional(),authorizeParams:h.record(h.string(),h.string()).default({}),tokenParams:h.record(h.string(),h.string()).default({}),defaults:h.record(h.string(),h.string()).default({}),scopes:pN.default({default:[],separator:" "}),fields:h.array(Wx).default([]),outputs:dN.default({ACCESS_TOKEN:"/accessToken"}),adapter:h.string().regex(/^[a-z][a-z0-9_-]{0,99}$/).optional(),keep:h.array(h.string()).default([]),hint:h.string().optional()}).refine(t=>t.grantType==="client_credentials"||t.grantType===Cn||!!t.authorizeUrl,{path:["authorizeUrl"],message:"An authorization code flow requires an authorization URL."}).refine(t=>t.grantType!==Cn||!!t.deviceAuthorizationUrl,{path:["deviceAuthorizationUrl"],message:"A device flow requires a device authorization URL."}),zhe=h.object({fields:h.array(Wx).min(1),outputs:Nhe,resolver:h.literal("vultr-role").optional(),bindFields:h.boolean().optional(),constants:h.record(h.string().regex(/^[a-zA-Z][a-zA-Z0-9_]*$/),h.string()).optional(),files:h.array(h.string().regex(/^[A-Z_][A-Z0-9_]*$/)).max(32).optional(),account:h.object({field:h.string().regex(/^[a-zA-Z][a-zA-Z0-9_]*$/),pointer:h.string().max(1e3)}).strict().optional(),identity:h.object({url:rl,headers:h.record(h.string(),h.string()),id:Zx,name:Zx}).strict().optional(),console:h.url().optional(),instructions:h.string().optional(),hint:h.string().optional()}).superRefine((t,e)=>{t.files?.some(r=>!Object.hasOwn(t.outputs,r))&&e.addIssue({code:"custom",path:["files"],message:"Deliver only declared outputs as files."}),t.account&&!t.fields.some(r=>r.name===t.account.field)&&e.addIssue({code:"custom",path:["account"],message:"Read the account from a declared field."})}),fN=h.enum(["oauth","token","aws","ovh","approval"]),jhe=h.object({hint:h.string().optional()}).strict(),Mhe=h.object({authorization:h.enum(["api_key","consumer_key"]),apiBaseUrl:rl,fields:h.array(Wx).min(1),scopes:pN.default({default:[],separator:`
128
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let s of t.seen.entries()){let a=s[1];if(e===s[0]){i(s);continue}if(t.external){let u=t.external.registry.get(s[0])?.id;if(e!==s[0]&&u){i(s);continue}}if(t.metadataRegistry.get(s[0])?.id){i(s);continue}if(a.cycle){i(s);continue}a.count>1&&t.reused==="ref"&&i(s)}t.external&&(t.sharedDefsExtractedFor=t.external)}function WV(t){let e=t.anyOf;if(!Array.isArray(e)||e.length===0||t.type!==void 0)return;let r=[];for(let o of e){if(!o||typeof o!="object")return;WV(o);let n=Object.keys(o);if(n.length!==1||n[0]!=="type")return;let i=o.type;for(let s of Array.isArray(i)?i:[i]){if(typeof s!="string")return;r.includes(s)||r.push(s)}}delete t.anyOf,t.type=r.length===1?r[0]:r}var JV=new Set(["type","properties","required","additionalProperties"]),qV=["oneOf","anyOf"];function ZV(t){let e=t.additionalProperties;return e===void 0||e===!1||typeof e!="object"||e===null?null:Object.keys(e).length?e:null}function qR(t){let e=[];for(let i of t){if(typeof i!="object"||i.type!=="object")return null;for(let s in i)if(!JV.has(s))return null;e.push(i)}let r={},o=new Set;for(let i of e){for(let s in i.properties){if(Object.prototype.hasOwnProperty.call(r,s))continue;let a=[];for(let u of e){let l=u.properties?.[s]??ZV(u);l!=null&&(a.some(d=>JSON.stringify(d)===JSON.stringify(l))||a.push(l))}let c=a.length===1?a[0]:qR(a)??{allOf:a};_r(r,s,c)}for(let s of i.required??[])o.add(s)}let n={type:"object",properties:r};if(o.size&&(n.required=[...o]),e.every(i=>i.additionalProperties===!1))n.additionalProperties=!1;else{let i=[];for(let s of e){let a=ZV(s);a&&!i.some(c=>JSON.stringify(c)===JSON.stringify(a))&&i.push(a)}i.length===1?n.additionalProperties=i[0]:i.length>1&&(n.additionalProperties={allOf:i})}return n}function $me(t){let e=t.allOf;if(!Array.isArray(e)||e.length<2)return;for(let n of JV)if(n in t)return;let r=e.filter(n=>qV.some(i=>Array.isArray(n[i]))),o=null;if(!r.length)o=qR(e);else{let n=r[0],i=qV.find(c=>Array.isArray(n[c]));if(Object.keys(n).length!==1)return;let s=e.filter(c=>c!==n),a=n[i].map(c=>qR([...s,c]));if(a.some(c=>!c))return;o={[i]:a}}o&&(delete t.allOf,qh(t,o))}function Xa(t,e){let r=t.seen.get(e);if(!r)throw new Error("Unprocessed schema. This is a bug in Zod.");let o=a=>{let c=t.seen.get(a);if(c.ref===null)return;let u=c.def??c.schema,l={...u},d=c.ref;if(c.ref=null,d){o(d);let p=t.seen.get(d),m=p.schema;if(m.$ref&&(t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0")?(u.allOf=u.allOf??[],u.allOf.push(m)):qh(u,m),qh(u,l),a._zod.parent===d)for(let y in u)y==="$ref"||y==="allOf"||y in l||delete u[y];if(m.$ref&&p.def)for(let y in u)y==="$ref"||y==="allOf"||y in p.def&&JSON.stringify(u[y])===JSON.stringify(p.def[y])&&delete u[y]}let f=a._zod.parent;if(f&&f!==d){o(f);let p=t.seen.get(f);if(p?.schema.$ref&&(u.$ref=p.schema.$ref,p.def))for(let m in u)m==="$ref"||m==="allOf"||m in p.def&&JSON.stringify(u[m])===JSON.stringify(p.def[m])&&delete u[m]}t.override({zodSchema:a,jsonSchema:u,path:c.path??[]})};if(!t.external||t.sharedEmitDoneFor!==t.external){for(let a of[...t.seen.entries()].reverse())o(a[0]);if(t.target!=="openapi-3.0")for(let a of t.seen.entries())WV(a[1].def??a[1].schema);for(let a of t.deferred)a();if(t.intersections.length){let a=new Map;for(let c of t.seen.values())for(let u of[c.schema,c.def]){let l=u?.allOf;if(!Array.isArray(l))continue;let d=a.get(l);d?d.push(u):a.set(l,[u])}for(let c of t.intersections)for(let u of a.get(c)??[])$me(u)}}let n={};if(t.target==="draft-2020-12"?n.$schema="https://json-schema.org/draft/2020-12/schema":t.target==="draft-07"?n.$schema="http://json-schema.org/draft-07/schema#":t.target==="draft-04"?n.$schema="http://json-schema.org/draft-04/schema#":t.target,t.external?.uri){let a=t.external.registry.get(e)?.id;if(!a)throw new Error("Schema is missing an `id` property");n.$id=t.external.uri(a)}qh(n,r.defId?r.schema:r.def??r.schema);let i=t.metadataRegistry.get(e)?.id;i!==void 0&&n.id===i&&delete n.id;let s=t.external?.defs??{};if(!t.external||t.sharedEmitDoneFor!==t.external)for(let a of t.seen.entries()){let c=a[1];c.def&&c.defId&&(c.def.id===c.defId&&delete c.def.id,_r(s,c.defId,c.def))}t.external&&(t.sharedEmitDoneFor=t.external),t.external||Object.keys(s).length>0&&(t.target==="draft-2020-12"?n.$defs=s:n.definitions=s);try{let a=JSON.parse(JSON.stringify(n));return Object.defineProperty(a,"~standard",{value:{...e["~standard"],jsonSchema:{input:Jd(e,"input",t.processors),output:Jd(e,"output",t.processors)}},enumerable:!1,writable:!1}),a}catch{throw new Error("Error converting schema to JSON.")}}function dn(t,e){let r=e??{seen:new Set};if(r.seen.has(t))return!1;r.seen.add(t);let o=t._zod.def;if(o.type==="transform")return!0;if(o.type==="array")return dn(o.element,r);if(o.type==="set")return dn(o.valueType,r);if(o.type==="lazy")return dn(o.getter(),r);if(o.type==="promise"||o.type==="optional"||o.type==="nonoptional"||o.type==="nullable"||o.type==="readonly"||o.type==="default"||o.type==="prefault"||o.type==="catch")return dn(o.innerType,r);if(o.type==="intersection")return dn(o.left,r)||dn(o.right,r);if(o.type==="record"||o.type==="map")return dn(o.keyType,r)||dn(o.valueType,r);if(o.type==="pipe")return t._zod.traits.has("$ZodCodec")?!0:dn(o.in,r)||dn(o.out,r);if(o.type==="object"){for(let n in o.shape)if(dn(o.shape[n],r))return!0;return!1}if(o.type==="union"){for(let n of o.options)if(dn(n,r))return!0;return!1}if(o.type==="tuple"){for(let n of o.items)if(dn(n,r))return!0;return!!(o.rest&&dn(o.rest,r))}return!1}var ZR=(t,e={})=>r=>{let o=Ja({...r,processors:e});return et(t,o),Ga(o,t),Xa(o,t)},Jd=(t,e,r={})=>o=>{let{libraryOptions:n,target:i}=o??{},s=Ja({...n??{},target:i,io:e,processors:r});return et(t,s),Ga(s,t),Xa(s,t)};var Gd=(t,e,r)=>{(t[e]===void 0||r>t[e])&&(t[e]=r)},Xd=(t,e,r)=>{(t[e]===void 0||r<t[e])&&(t[e]=r)},GV=(t,e)=>{Gd(t,"minimum",e),Xd(t,"maximum",e)},eH=(t,e)=>{t.multipleOf??(t.multipleOf=[]),t.multipleOf.includes(e)||t.multipleOf.push(e)},tH=(t,e)=>{t.patterns??(t.patterns=new Set),t.patterns.add(e)},rH=(t,e)=>{t.mime=t.mime?t.mime.filter(r=>e.includes(r)):[...e]},nH=(t,e)=>{t.format=e,e.includes("int")&&(t.isInt=!0)},XV=(t,e)=>Gd(t,"minimum",e.minimum),YV=(t,e)=>Xd(t,"maximum",e.maximum),QV=t=>(e,r)=>{nH(e,r.format);let[o,n]=t[r.format];Gd(e,"minimum",o),Xd(e,"maximum",n)},Ame={greater_than:(t,e)=>Gd(t,e.inclusive?"minimum":"exclusiveMinimum",e.value),less_than:(t,e)=>Xd(t,e.inclusive?"maximum":"exclusiveMaximum",e.value),multiple_of:(t,e)=>eH(t,e.value),number_format:QV(Jm),bigint_format:QV(Gm),min_length:XV,max_length:YV,length_equals:(t,e)=>GV(t,e.length),min_size:XV,max_size:YV,size_equals:(t,e)=>GV(t,e.size),string_format:(t,e)=>{nH(t,e.format),e.pattern&&tH(t,e.pattern),(e.format==="base64"||e.format==="base64url")&&(t.contentEncoding=e.format),(e.local||e.precision===-1)&&(t.laxFormat=!0)},mime_type:(t,e)=>rH(t,e.mime)};function er(t){let e={},r=t._zod.def,o=t._zod.traits.has("$ZodCheck")?[t,...r.checks??[]]:r.checks??[];for(let i of o)Ame[i._zod.def.check]?.(e,i._zod.def);let n=t._zod.bag;n.minimum!==void 0&&Gd(e,"minimum",n.minimum),n.exclusiveMinimum!==void 0&&Gd(e,"exclusiveMinimum",n.exclusiveMinimum),n.maximum!==void 0&&Xd(e,"maximum",n.maximum),n.exclusiveMaximum!==void 0&&Xd(e,"exclusiveMaximum",n.exclusiveMaximum),n.multipleOf!==void 0&&eH(e,n.multipleOf),n.format!==void 0&&(e.format??(e.format=n.format),n.format.includes("int")&&(e.isInt=!0)),n.mime&&rH(e,n.mime);for(let i of n.patterns??[])tH(e,i);return e}var Tme={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Pme=new Map([[Jb,CP],[dh,OP]]),oH=t=>Pme.get(t)??t,GR=(t,e,r,o)=>{let n=r;n.type="string";let{minimum:i,maximum:s,format:a,patterns:c,contentEncoding:u,laxFormat:l}=er(t);if(typeof i=="number"&&(n.minLength=i),typeof s=="number"&&(n.maxLength=s),a&&(n.format=Tme[a]??a,n.format===""&&delete n.format,(a==="time"||l)&&delete n.format),u&&(n.contentEncoding=u),c&&c.size>0){let d=[...c].map(oH);d.length===1?n.pattern=d[0].source:d.length>1&&(n.allOf=[...d.map(f=>({...e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0"?{type:"string"}:{},pattern:f.source}))])}},XR=(t,e,r,o)=>{let n=r,{minimum:i,maximum:s,multipleOf:a,exclusiveMaximum:c,exclusiveMinimum:u,isInt:l}=er(t);n.type=l?"integer":"number";let d=typeof u=="number"&&u>=(i??Number.NEGATIVE_INFINITY),f=typeof c=="number"&&c<=(s??Number.POSITIVE_INFINITY),p=e.target==="draft-04"||e.target==="openapi-3.0";if(d?p?(n.minimum=u,n.exclusiveMinimum=!0):n.exclusiveMinimum=u:typeof i=="number"&&(n.minimum=i),f?p?(n.maximum=c,n.exclusiveMaximum=!0):n.exclusiveMaximum=c:typeof s=="number"&&(n.maximum=s),a){let m=new Set;for(let w of a)Number.isFinite(w)&&w!==0?m.add(Math.abs(w)):Qt(t,e,n,o,`A multipleOf divisor of ${w} cannot be represented in JSON Schema`);let[g,...y]=m;g!==void 0&&(n.multipleOf=g),y.length&&(n.allOf=[...n.allOf??[],...y.map(w=>({multipleOf:w}))])}},YR=(t,e,r,o)=>{r.type="boolean"},QR=(t,e,r,o)=>{Qt(t,e,r,o,"BigInt cannot be represented in JSON Schema")},eC=(t,e,r,o)=>{Qt(t,e,r,o,"Symbols cannot be represented in JSON Schema")},tC=(t,e,r,o)=>{e.target==="openapi-3.0"?(r.type="string",r.nullable=!0,r.enum=[null]):r.type="null"},rC=(t,e,r,o)=>{Qt(t,e,r,o,"Undefined cannot be represented in JSON Schema")},nC=(t,e,r,o)=>{Qt(t,e,r,o,"Void cannot be represented in JSON Schema")},oC=(t,e,r,o)=>{r.not={}},iC=(t,e,r,o)=>{},sC=(t,e,r,o)=>{},aC=(t,e,r,o)=>{Qt(t,e,r,o,"Date cannot be represented in JSON Schema")},cC=(t,e,r,o)=>{let n=t._zod.def,i=ld(n.entries);if(i.length===0){r.not={};return}i.every(s=>typeof s=="number")&&(r.type="number"),i.every(s=>typeof s=="string")&&(r.type="string"),r.enum=i},uC=(t,e,r,o)=>{let n=t._zod.def;if(n.values.length===0){r.not={};return}let i=[];for(let s of n.values)if(s===void 0){if(Qt(t,e,r,o,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof s=="bigint"){if(Qt(t,e,r,o,"BigInt literals cannot be represented in JSON Schema"))return;i.push(Number(s))}else i.push(s);if(i.length!==0)if(i.length===1){let s=i[0];r.type=s===null?"null":typeof s,e.target==="draft-04"||e.target==="openapi-3.0"?r.enum=[s]:r.const=s}else i.every(s=>typeof s=="number")&&(r.type="number"),i.every(s=>typeof s=="string")&&(r.type="string"),i.every(s=>typeof s=="boolean")&&(r.type="boolean"),i.every(s=>s===null)&&(r.type="null"),r.enum=i},lC=(t,e,r,o)=>{Qt(t,e,r,o,"NaN cannot be represented in JSON Schema")},dC=(t,e,r,o)=>{let n=r,i=t._zod.pattern;if(!i)throw new Error("Pattern not found in template literal");n.type="string",n.pattern=i.source},pC=(t,e,r,o)=>{let n=r;n.type="string",n.format="binary",n.contentEncoding="binary";let{minimum:i,maximum:s,mime:a}=er(t);i!==void 0&&(n.minLength=i),s!==void 0&&(n.maxLength=s),a&&(a.length===0?n.not={}:a.length===1?n.contentMediaType=a[0]:n.anyOf=a.map(c=>({contentMediaType:c})))},fC=(t,e,r,o)=>{r.type="boolean"},mC=(t,e,r,o)=>{Qt(t,e,r,o,"Custom types cannot be represented in JSON Schema")},hC=(t,e,r,o)=>{Qt(t,e,r,o,"Function types cannot be represented in JSON Schema")},gC=(t,e,r,o)=>{Qt(t,e,r,o,"Transforms cannot be represented in JSON Schema")},yC=(t,e,r,o)=>{Qt(t,e,r,o,"Map cannot be represented in JSON Schema")},vC=(t,e,r,o)=>{Qt(t,e,r,o,"Set cannot be represented in JSON Schema")},wC=(t,e,r,o)=>{let n=r,i=t._zod.def,{minimum:s,maximum:a}=er(t);typeof s=="number"&&(n.minItems=s),typeof a=="number"&&(n.maxItems=a),n.type="array",n.items=et(i.element,e,{...o,path:[...o.path,"items"]})};function Zh(t){let e=t._zod.def;return e.type==="pipe"&&e.in._zod.traits.has("$ZodTransform")?Zh(e.out):e.type==="catch"?Zh(e.innerType):t._zod.optin}var bC=(t,e,r,o)=>{let n=r,i=t._zod.def,s=i.shape;if(Object.getOwnPropertySymbols(s).length&&Qt(t,e,n,o,"Symbol keys cannot be represented in JSON Schema"))return;n.type="object",n.properties={};for(let u in s)_r(n.properties,u,et(s[u],e,{...o,path:[...o.path,"properties",u]}));let c=[];for(let u of Object.keys(s)){let l=i.shape[u];(e.io==="input"?Zh(l)===void 0:l._zod.optout===void 0)&&c.push(u)}c.length>0&&(n.required=c),i.catchall?._zod.def.type==="never"?n.additionalProperties=!1:i.catchall?i.catchall&&(n.additionalProperties=et(i.catchall,e,{...o,path:[...o.path,"additionalProperties"]})):e.io==="output"&&(n.additionalProperties=!1)},MS=(t,e,r,o)=>{let n=t._zod.def,i=n.inclusive===!1,s=n.options.map((a,c)=>et(a,e,{...o,path:[...o.path,i?"oneOf":"anyOf",c]}));i?r.oneOf=s:r.anyOf=s},_C=(t,e,r,o)=>{let n=t._zod.def,i=et(n.left,e,{...o,path:[...o.path,"allOf",0]}),s=et(n.right,e,{...o,path:[...o.path,"allOf",1]}),a=u=>"allOf"in u&&Object.keys(u).length===1,c=[...a(i)?i.allOf:[i],...a(s)?s.allOf:[s]];r.allOf=c,e.intersections.push(c)},SC=(t,e,r,o)=>{let n=r,i=t._zod.def;n.type="array";let s=e.target==="draft-2020-12"?"prefixItems":"items",a=e.target==="draft-2020-12"||e.target==="openapi-3.0"?"items":"additionalItems",c=i.items.map((g,y)=>et(g,e,{...o,path:[...o.path,s,y]})),u=i.rest?et(i.rest,e,{...o,path:[...o.path,a,...e.target==="openapi-3.0"?[i.items.length]:[]]}):null,l=i.items.length;for(;l>0;){let g=i.items[l-1];if(!(e.io==="input"?Zh(g)!==void 0:g._zod.optout==="optional"))break;l--}let d=i.items.length,f=!i.rest;e.target==="draft-2020-12"?(n.prefixItems=c,f?n.items=!1:u&&(n.items=u),l>0&&(n.minItems=l),f&&(n.maxItems=d)):e.target==="openapi-3.0"?(n.items={anyOf:c},u&&n.items.anyOf.push(u),l>0&&(n.minItems=l),f&&(n.maxItems=d)):(n.items=c,f?n.additionalItems=!1:u&&(n.additionalItems=u),l>0&&(n.minItems=l),f&&(n.maxItems=d));let{minimum:p,maximum:m}=er(t);typeof p=="number"&&(n.minItems=p),typeof m=="number"&&(n.maxItems=m)};function WR(t,e,r){if(e.$ref){if(r.has(e))return e;r.add(e);let m=t.get(e)?.def;if(!m)return e;let g=WR(t,m,r);return g===m?e:g}for(let m of["anyOf","oneOf"]){let g=e[m];if(!Array.isArray(g))continue;let y=g.map(w=>WR(t,w,r));y.some((w,b)=>w!==g[b])&&(e={...e,[m]:y})}let o=Array.isArray(e.type)?e.type:[e.type],n=!o.includes("string")&&o.some(m=>m==="number"||m==="integer"),i=e.enum??(e.const!==void 0?[e.const]:void 0);if(!n&&!i?.some(m=>typeof m=="number"))return e;let{minimum:s,maximum:a,exclusiveMinimum:c,exclusiveMaximum:u,multipleOf:l,format:d,id:f,...p}=e;return p.enum?p.enum=p.enum.map(m=>typeof m=="number"?String(m):m):typeof p.const=="number"&&(p.const=String(p.const)),n&&(p.type="string",i||(p.pattern=(o.includes("number")?ra:oh).source)),p}var JR=new WeakMap;function Rme(t){let e=new Map;for(let o of t.seen.values())o.def&&!e.has(o.schema)&&e.set(o.schema,o);let r=new Map;for(let o of JR.get(t)??[]){let n=t.seen.get(o),i=(n?.def??n?.schema)?.propertyNames;if(!i||i===!0||r.has(i))continue;let s=WR(e,i,new Set);s!==i&&r.set(i,s)}if(r.size)for(let o of t.seen.values())for(let n of[o.schema,o.def]){let i=n&&r.get(n.propertyNames);i&&(n.propertyNames=i)}}var xC=(t,e,r,o)=>{let n=r,i=t._zod.def;n.type="object";let s=i.keyType,a=er(s).patterns;if(i.mode==="loose"&&a&&a.size>0){let l=et(i.valueType,e,{...o,path:[...o.path,"patternProperties","*"]});n.patternProperties={};for(let d of a)_r(n.patternProperties,oH(d).source,l)}else{if(e.target==="draft-07"||e.target==="draft-2020-12"){n.propertyNames=et(i.keyType,e,{...o,path:[...o.path,"propertyNames"]});let l=JR.get(e);l||(l=[],JR.set(e,l),e.deferred.push(()=>Rme(e))),l.push(t)}n.additionalProperties=et(i.valueType,e,{...o,path:[...o.path,"additionalProperties"]})}let c=s._zod.values,u=e.io==="input"&&Zh(i.valueType)!==void 0;if(c&&!i.partial&&!u){let l=[...c].filter(d=>typeof d=="string"||typeof d=="number");l.length>0&&(n.required=l.map(String))}},EC=(t,e,r,o)=>{let n=t._zod.def,i=et(n.innerType,e,o),s=e.seen.get(t);e.target==="openapi-3.0"?(s.ref=n.innerType,r.nullable=!0):r.anyOf=[i,{type:"null"}]},kC=(t,e,r,o)=>{let n=t._zod.def;et(n.innerType,e,o);let i=e.seen.get(t);i.ref=n.innerType},IC=Symbol();function iH(t,e,r,o,n){let i=!1,s=JSON.stringify(t,(a,c)=>typeof c!="bigint"?c:(i=!0,null));return i?(Qt(e,r,o,n,"BigInt defaults cannot be represented in JSON Schema"),IC):JSON.parse(s)}var $C=(t,e,r,o)=>{let n=t._zod.def;et(n.innerType,e,o);let i=e.seen.get(t);i.ref=n.innerType;let s=iH(n.defaultValue,t,e,r,o);s!==IC&&(r.default=s)},AC=(t,e,r,o)=>{let n=t._zod.def;et(n.innerType,e,o);let i=e.seen.get(t);if(i.ref=n.innerType,e.io!=="input")return;let s=iH(n.defaultValue,t,e,r,o);s!==IC&&(r._prefault=s)},TC=(t,e,r,o)=>{let n=t._zod.def;et(n.innerType,e,o);let i=e.seen.get(t);i.ref=n.innerType;let s;try{s=n.catchValue(void 0)}catch{Qt(t,e,r,o,"Dynamic catch values are not supported in JSON Schema");return}r.default=s},PC=(t,e,r,o)=>{let n=t._zod.def,i=n.in._zod.traits.has("$ZodTransform"),s=e.io==="input"?i?n.out:n.in:n.out;et(s,e,o);let a=e.seen.get(t);a.ref=s},RC=(t,e,r,o)=>{let n=t._zod.def;et(n.innerType,e,o);let i=e.seen.get(t);i.ref=n.innerType,r.readOnly=!0},CC=(t,e,r,o)=>{let n=t._zod.def;et(n.innerType,e,o);let i=e.seen.get(t);i.ref=n.innerType},US=(t,e,r,o)=>{let n=t._zod.def;et(n.innerType,e,o);let i=e.seen.get(t);i.ref=n.innerType},OC=(t,e,r,o)=>{let n=t._zod.innerType;et(n,e,o);let i=e.seen.get(t);i.ref=n},jS={string:GR,number:XR,boolean:YR,bigint:QR,symbol:eC,null:tC,undefined:rC,void:nC,never:oC,any:iC,unknown:sC,date:aC,enum:cC,literal:uC,nan:lC,template_literal:dC,file:pC,success:fC,custom:mC,function:hC,transform:gC,map:yC,set:vC,array:wC,object:bC,union:MS,intersection:_C,tuple:SC,record:xC,nullable:EC,nonoptional:kC,default:$C,prefault:AC,catch:TC,pipe:PC,readonly:RC,promise:CC,optional:US,lazy:OC};function Ku(t,e){if("_idmap"in t){let o=t,n=Ja({...e,processors:jS}),i={};for(let c of o._idmap.entries()){let[u,l]=c;et(l,n)}let s={},a={registry:o,uri:e?.uri,defs:i};n.external=a;for(let c of o._idmap.entries()){let[u,l]=c;Ga(n,l),_r(s,u,Xa(n,l))}if(Object.keys(i).length>0){let c=n.target==="draft-2020-12"?"$defs":"definitions";s.__shared={[c]:i}}return{schemas:s}}let r=Ja({...e,processors:jS});return et(t,r),Ga(r,t),Xa(r,t)}var LS=class{get metadataRegistry(){return this.ctx.metadataRegistry}get target(){return this.ctx.target}get unrepresentable(){return this.ctx.unrepresentable}get override(){return this.ctx.override}get io(){return this.ctx.io}get counter(){return this.ctx.counter}set counter(e){this.ctx.counter=e}get seen(){return this.ctx.seen}constructor(e){let r=e?.target??"draft-2020-12";r==="draft-4"&&(r="draft-04"),r==="draft-7"&&(r="draft-07"),this.ctx=Ja({processors:jS,target:r,...e?.metadata&&{metadata:e.metadata},...e?.unrepresentable&&{unrepresentable:e.unrepresentable},...e?.override&&{override:e.override},...e?.io&&{io:e.io}})}process(e,r={path:[],schemaPath:[]}){return et(e,this.ctx,r)}emit(e,r){r&&(r.cycles&&(this.ctx.cycles=r.cycles),r.reused&&(this.ctx.reused=r.reused),r.external&&(this.ctx.external=r.external)),this.ctx.sharedDefsExtractedFor=void 0,this.ctx.sharedEmitDoneFor=void 0,Ga(this.ctx,e);let o=Xa(this.ctx,e),{"~standard":n,...i}=o;return i}};var sH={};var ip={};bt(ip,{ZodAny:()=>YC,ZodArray:()=>rO,ZodBase64:()=>ix,ZodBase64URL:()=>sx,ZodBigInt:()=>np,ZodBigIntFormat:()=>ux,ZodBoolean:()=>rp,ZodCIDRv4:()=>nx,ZodCIDRv6:()=>ox,ZodCUID:()=>GS,ZodCUID2:()=>XS,ZodCatch:()=>_O,ZodCodec:()=>rg,ZodCreditCard:()=>ZC,ZodCustom:()=>ng,ZodCustomStringFormat:()=>Zu,ZodDate:()=>Xh,ZodDefault:()=>hO,ZodDiscriminatedUnion:()=>oO,ZodE164:()=>ax,ZodEmail:()=>qS,ZodEmoji:()=>WS,ZodEnum:()=>Qd,ZodExactOptional:()=>px,ZodFile:()=>dO,ZodFunction:()=>RO,ZodGUID:()=>ZS,ZodIBAN:()=>WC,ZodIPv4:()=>tx,ZodIPv6:()=>rx,ZodISODate:()=>Qa,ZodISODateTime:()=>Ya,ZodISODuration:()=>tc,ZodISOTime:()=>ec,ZodInstanceOf:()=>NO,ZodIntersection:()=>iO,ZodJWT:()=>cx,ZodKSUID:()=>ex,ZodLazy:()=>AO,ZodLiteral:()=>lO,ZodMAC:()=>qC,ZodMap:()=>cO,ZodNaN:()=>xO,ZodNanoID:()=>JS,ZodNever:()=>eO,ZodNonOptional:()=>fx,ZodNull:()=>XC,ZodNullable:()=>mO,ZodNumber:()=>tp,ZodNumberFormat:()=>Wu,ZodObject:()=>Yh,ZodOptional:()=>Ju,ZodPipe:()=>tg,ZodPrefault:()=>yO,ZodPreprocess:()=>EO,ZodPromise:()=>PO,ZodReadonly:()=>kO,ZodRecord:()=>Yd,ZodSet:()=>uO,ZodString:()=>ep,ZodStringFormat:()=>st,ZodSuccess:()=>bO,ZodSymbol:()=>JC,ZodTemplateLiteral:()=>$O,ZodTransform:()=>pO,ZodTuple:()=>sO,ZodType:()=>ge,ZodULID:()=>YS,ZodURL:()=>Jh,ZodUUID:()=>Qi,ZodUndefined:()=>GC,ZodUnion:()=>Qh,ZodUnknown:()=>QC,ZodVoid:()=>tO,ZodXID:()=>QS,ZodXor:()=>nO,_ZodString:()=>KS,_default:()=>gO,_function:()=>mB,any:()=>JH,array:()=>Ae,base64:()=>TH,base64url:()=>PH,bigint:()=>BH,boolean:()=>Bt,catch:()=>SO,check:()=>hB,cidrv4:()=>$H,cidrv6:()=>AH,codec:()=>lB,creditCard:()=>CH,cuid:()=>wH,cuid2:()=>bH,currencyCode:()=>MH,custom:()=>mx,date:()=>XH,describe:()=>gB,discriminatedUnion:()=>eg,e164:()=>RH,email:()=>uH,emoji:()=>yH,enum:()=>Er,exactOptional:()=>fO,file:()=>sB,float32:()=>LH,float64:()=>FH,function:()=>mB,guid:()=>lH,hash:()=>UH,hex:()=>jH,hostname:()=>zH,httpUrl:()=>gH,iban:()=>OH,instanceof:()=>vB,int:()=>HS,int32:()=>VH,int64:()=>KH,intersection:()=>op,invertCodec:()=>dB,ipv4:()=>EH,ipv6:()=>IH,json:()=>bB,jwt:()=>NH,keyof:()=>YH,ksuid:()=>xH,lazy:()=>TO,literal:()=>G,looseObject:()=>xr,looseRecord:()=>rB,mac:()=>kH,map:()=>nB,meta:()=>yB,nan:()=>uB,nanoid:()=>vH,nativeEnum:()=>iB,never:()=>lx,nonoptional:()=>wO,null:()=>Gh,nullable:()=>Wh,nullish:()=>aB,number:()=>Ze,object:()=>H,optional:()=>it,partialRecord:()=>tB,pipe:()=>BS,prefault:()=>vO,preprocess:()=>og,promise:()=>fB,readonly:()=>IO,record:()=>at,refine:()=>CO,set:()=>oB,strictObject:()=>QH,string:()=>I,stringFormat:()=>DH,stringbool:()=>wB,success:()=>cB,superRefine:()=>OO,symbol:()=>ZH,templateLiteral:()=>pB,transform:()=>dx,tuple:()=>aO,uint32:()=>HH,uint64:()=>qH,ulid:()=>_H,undefined:()=>WH,union:()=>tt,unknown:()=>dt,url:()=>hH,uuid:()=>dH,uuidv4:()=>pH,uuidv6:()=>fH,uuidv7:()=>mH,void:()=>GH,xid:()=>SH,xor:()=>eB});var FS={};bt(FS,{endsWith:()=>Fd,gt:()=>Xi,gte:()=>Jn,includes:()=>Ud,length:()=>Bu,lowercase:()=>jd,lt:()=>Gi,lte:()=>Wn,maxLength:()=>Hu,maxSize:()=>Za,mime:()=>Hd,minLength:()=>na,minSize:()=>Yi,multipleOf:()=>qa,negative:()=>IS,nonnegative:()=>AS,nonpositive:()=>$S,normalize:()=>Bd,overwrite:()=>ri,positive:()=>kS,properties:()=>Vd,property:()=>TS,regex:()=>zd,size:()=>Vu,slugify:()=>Wd,startsWith:()=>Ld,toLowerCase:()=>qd,toUpperCase:()=>Zd,trim:()=>Kd,uppercase:()=>Md});var aH=new WeakSet([Object.prototype,Error.prototype]);function VS(t,e,r){Object.defineProperty(t,e,{configurable:!0,enumerable:!1,get(){let o=r(this);return Object.defineProperty(this,e,{value:o,configurable:!0,writable:!0}),o},set(o){Object.defineProperty(this,e,{value:o,configurable:!0,writable:!0})}})}var cH=(t,e)=>{pP.init(t,e),t.name="ZodError";let r=Object.getPrototypeOf(t);aH.has(r)||(aH.add(r),VS(r,"format",o=>n=>rh(o,n)),VS(r,"flatten",o=>n=>th(o,n)),VS(r,"addIssue",o=>n=>{o.issues.push(n),o.message=JSON.stringify(o.issues,dd,2)}),VS(r,"addIssues",o=>n=>{o.issues.push(...n),o.message=JSON.stringify(o.issues,dd,2)}),Object.defineProperty(r,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},Ome=S("ZodError",cH),Pn=S("ZodError",cH,void 0,{Parent:Error});var NC=yd(Pn),DC=vd(Pn),zC=wd(Pn),jC=_d(Pn),MC=lb(Pn),UC=db(Pn),LC=pb(Pn),FC=fb(Pn),VC=mb(Pn),HC=hb(Pn),BC=gb(Pn),KC=yb(Pn);function Dme(){lr.localeError||zt(W_())}function qu(){lr.memoizer||zt({memoizer:wh()})}var ge=S("ZodType",(t,e)=>(Dme(),ae.init(t,e),t.def=e,t.type=e.type,t),{check(...t){let e=this.def;return this.clone(A.mergeDefs(e,{checks:[...e.checks??[],...t.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),{parent:!0})},with(...t){return this.check(...t)},clone(t,e){return qe(this,t,e)},brand(){return this},register(t,e){return t.add(this,e),this},refine(t,e){return this.check(CO(t,e))},superRefine(t,e){return this.check(OO(t,e))},overwrite(t){return this.check(ri(t))},optional(){return it(this)},exactOptional(){return fO(this)},nullable(){return Wh(this)},nullish(){return it(Wh(this))},nonoptional(t){return wO(this,t)},array(){return Ae(this)},or(t){return tt([this,t])},and(t){return op(this,t)},transform(t){return BS(this,dx(t))},default(t){return gO(this,t)},prefault(t){return vO(this,t)},catch(t){return SO(this,t)},pipe(t){return BS(this,t)},readonly(){return IO(this)},describe(t){let e=this.clone();return Sr.add(e,{description:t}),e},meta(...t){if(t.length===0)return Sr.get(this);let e=this.clone();return Sr.add(e,t[0]),e},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(t,...e){return e.length===0?t(this):t(this,...e)},get"~standard"(){return A.hide(this,"~standard",{...Ab(this),jsonSchema:{input:Jd(this,"input"),output:Jd(this,"output")}})},set"~standard"(t){A.own(this,"~standard",t)},parse:function t(e,r){return NC(this,e,r,{callee:t})},parseAsync:async function t(e,r){return await DC(this,e,r,{callee:t})},safeParse(t,e){return zC(this,t,e)},async safeParseAsync(t,e){return jC(this,t,e)},get spa(){return this?.safeParseAsync},set spa(t){A.own(this,"spa",t)},validate(t,e){return xd(this,t,e)},validateAsync(t,e){return Ed(this,t,e)},encode:function t(e,r){return MC(this,e,r,{callee:t})},decode:function t(e,r){return UC(this,e,r,{callee:t})},encodeAsync:async function t(e,r){return await LC(this,e,r,{callee:t})},decodeAsync:async function t(e,r){return await FC(this,e,r,{callee:t})},safeEncode(t,e){return VC(this,t,e)},safeDecode(t,e){return HC(this,t,e)},async safeEncodeAsync(t,e){return BC(this,t,e)},async safeDecodeAsync(t,e){return KC(this,t,e)},toJSONSchema(t){return ZR(this,{})(t)},get description(){return Sr.get(this)?.description},get _def(){return this._zod.def}}),KS=S("_ZodString",(t,e)=>{Ba.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>GR(t,r,o,n)},A.derived({format:t=>er(t).format??null,minLength:t=>er(t).minimum??null,maxLength:t=>er(t).maximum??null},{regex(...t){return this.check(zd(...t))},includes(...t){return this.check(Ud(...t))},startsWith(...t){return this.check(Ld(...t))},endsWith(...t){return this.check(Fd(...t))},min(...t){return this.check(na(...t))},max(...t){return this.check(Hu(...t))},length(...t){return this.check(Bu(...t))},nonempty(...t){return this.check(na(1,...t))},lowercase(t){return this.check(jd(t))},uppercase(t){return this.check(Md(t))},trim(){return this.check(Kd())},normalize(...t){return this.check(Bd(...t))},toLowerCase(){return this.check(qd())},toUpperCase(){return this.check(Zd())},slugify(){return this.check(Wd())}})),ep=S("ZodString",(t,e)=>{Ba.init(t,e),KS.init(t,e)},{email(t){return this.check(_h(qS,t))},url(t){return this.check(Dd(Jh,t))},jwt(t){return this.check(Fh(cx,t))},emoji(t){return this.check($h(WS,t))},guid(t){return this.check(Sh(ZS,t))},uuid(t){return this.check(xh(Qi,t))},uuidv4(t){return this.check(Eh(Qi,t))},uuidv6(t){return this.check(kh(Qi,t))},uuidv7(t){return this.check(Ih(Qi,t))},nanoid(t){return this.check(Ah(JS,t))},cuid(t){return this.check(Th(GS,t))},cuid2(t){return this.check(Ph(XS,t))},ulid(t){return this.check(Rh(YS,t))},base64(t){return this.check(Mh(ix,t))},base64url(t){return this.check(Uh(sx,t))},xid(t){return this.check(Ch(QS,t))},ksuid(t){return this.check(Oh(ex,t))},ipv4(t){return this.check(Nh(tx,t))},ipv6(t){return this.check(Dh(rx,t))},cidrv4(t){return this.check(zh(nx,t))},cidrv6(t){return this.check(jh(ox,t))},e164(t){return this.check(Lh(ax,t))},datetime(t){return this.check(Vh(Ya,t))},date(t){return this.check(Hh(Qa,t))},time(t){return this.check(Bh(ec,t))},duration(t){return this.check(Kh(tc,t))}});function I(t){return rS(ep,t)}var st=S("ZodStringFormat",(t,e)=>{Je.init(t,e),KS.init(t,e)}),Ya=S("ZodISODateTime",(t,e)=>{_R.init(t,e),st.init(t,e)}),Qa=S("ZodISODate",(t,e)=>{SR.init(t,e),st.init(t,e)}),ec=S("ZodISOTime",(t,e)=>{xR.init(t,e),st.init(t,e)}),tc=S("ZodISODuration",(t,e)=>{ER.init(t,e),st.init(t,e)}),qS=S("ZodEmail",(t,e)=>{Rb.init(t,e),st.init(t,e)});function uH(t){return _h(qS,t)}var ZS=S("ZodGUID",(t,e)=>{Tb.init(t,e),st.init(t,e)});function lH(t){return Sh(ZS,t)}var Qi=S("ZodUUID",(t,e)=>{Pb.init(t,e),st.init(t,e)});function dH(t){return xh(Qi,t)}function pH(t){return Eh(Qi,t)}function fH(t){return kh(Qi,t)}function mH(t){return Ih(Qi,t)}var Jh=S("ZodURL",(t,e)=>{Db.init(t,e),st.init(t,e)});function hH(t){return Dd(Jh,t)}function gH(t){return Dd(Jh,{protocol:nh,hostname:DP,...A.normalizeParams(t)})}var WS=S("ZodEmoji",(t,e)=>{zb.init(t,e),st.init(t,e)});function yH(t){return $h(WS,t)}var JS=S("ZodNanoID",(t,e)=>{jb.init(t,e),st.init(t,e)});function vH(t){return Ah(JS,t)}var GS=S("ZodCUID",(t,e)=>{Mb.init(t,e),st.init(t,e)});function wH(t){return Th(GS,t)}var XS=S("ZodCUID2",(t,e)=>{Ub.init(t,e),st.init(t,e)});function bH(t){return Ph(XS,t)}var YS=S("ZodULID",(t,e)=>{Lb.init(t,e),st.init(t,e)});function _H(t){return Rh(YS,t)}var QS=S("ZodXID",(t,e)=>{Fb.init(t,e),st.init(t,e)});function SH(t){return Ch(QS,t)}var ex=S("ZodKSUID",(t,e)=>{Vb.init(t,e),st.init(t,e)});function xH(t){return Oh(ex,t)}var tx=S("ZodIPv4",(t,e)=>{Hb.init(t,e),st.init(t,e)});function EH(t){return Nh(tx,t)}var qC=S("ZodMAC",(t,e)=>{Kb.init(t,e),st.init(t,e)});function kH(t){return nS(qC,t)}var rx=S("ZodIPv6",(t,e)=>{Bb.init(t,e),st.init(t,e)});function IH(t){return Dh(rx,t)}var nx=S("ZodCIDRv4",(t,e)=>{qb.init(t,e),st.init(t,e)});function $H(t){return zh(nx,t)}var ox=S("ZodCIDRv6",(t,e)=>{Wb.init(t,e),st.init(t,e)});function AH(t){return jh(ox,t)}var ix=S("ZodBase64",(t,e)=>{Gb.init(t,e),st.init(t,e)});function TH(t){return Mh(ix,t)}var sx=S("ZodBase64URL",(t,e)=>{Yb.init(t,e),st.init(t,e)});function PH(t){return Uh(sx,t)}var ax=S("ZodE164",(t,e)=>{Qb.init(t,e),st.init(t,e)});function RH(t){return Lh(ax,t)}var ZC=S("ZodCreditCard",(t,e)=>{t_.init(t,e),st.init(t,e)});function CH(t){return oS(ZC,t)}var WC=S("ZodIBAN",(t,e)=>{n_.init(t,e),st.init(t,e)});function OH(t){return iS(WC,t)}var cx=S("ZodJWT",(t,e)=>{i_.init(t,e),st.init(t,e)});function NH(t){return Fh(cx,t)}var Zu=S("ZodCustomStringFormat",(t,e)=>{s_.init(t,e),st.init(t,e)});function DH(t,e,r={}){return Wa(Zu,t,e,r)}function zH(t){return Wa(Zu,"hostname",NP,t)}function jH(t){return Wa(Zu,"hex",JP,t)}function MH(t){return Wa(Zu,"currency_code",jP,t)}function UH(t,e){let r=e?.enc??"hex",o=`${t}_${r}`,n=Zn[o];if(!n)throw new Error(`Unrecognized hash format: ${o}`);return Wa(Zu,o,n,e)}var tp=S("ZodNumber",(t,e)=>{ph.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>XR(t,r,o,n),t.isFinite=!0},A.derived({minValue:t=>{let{minimum:e,exclusiveMinimum:r}=er(t);return Math.max(e??Number.NEGATIVE_INFINITY,r??Number.NEGATIVE_INFINITY)},maxValue:t=>{let{maximum:e,exclusiveMaximum:r}=er(t);return Math.min(e??Number.POSITIVE_INFINITY,r??Number.POSITIVE_INFINITY)},isInt:t=>{let{isInt:e,multipleOf:r}=er(t);return!!e||!!r?.some(Number.isSafeInteger)},format:t=>er(t).format??null},{gt(t,e){return this.check(Xi(t,e))},gte(t,e){return this.check(Jn(t,e))},min(t,e){return this.check(Jn(t,e))},lt(t,e){return this.check(Gi(t,e))},lte(t,e){return this.check(Wn(t,e))},max(t,e){return this.check(Wn(t,e))},int(t){return this.check(HS(t))},safe(t){return this.check(HS(t))},positive(t){return this.check(Xi(0,t))},nonnegative(t){return this.check(Jn(0,t))},negative(t){return this.check(Gi(0,t))},nonpositive(t){return this.check(Wn(0,t))},multipleOf(t,e){return this.check(qa(t,e))},step(t,e){return this.check(qa(t,e))},finite(){return this}}));function Ze(t){return sS(tp,t)}var Wu=S("ZodNumberFormat",(t,e)=>{a_.init(t,e),tp.init(t,e)});function HS(t){return aS(Wu,t)}function LH(t){return cS(Wu,t)}function FH(t){return uS(Wu,t)}function VH(t){return lS(Wu,t)}function HH(t){return dS(Wu,t)}var rp=S("ZodBoolean",(t,e)=>{$d.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>YR(t,r,o,n)});function Bt(t){return pS(rp,t)}var np=S("ZodBigInt",(t,e)=>{fh.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>QR(t,r,o,n)},A.derived({minValue:t=>er(t).minimum??null,maxValue:t=>er(t).maximum??null,format:t=>er(t).format??null},{gte(t,e){return this.check(Jn(t,e))},min(t,e){return this.check(Jn(t,e))},gt(t,e){return this.check(Xi(t,e))},lt(t,e){return this.check(Gi(t,e))},lte(t,e){return this.check(Wn(t,e))},max(t,e){return this.check(Wn(t,e))},positive(t){return this.check(Xi(BigInt(0),t))},negative(t){return this.check(Gi(BigInt(0),t))},nonpositive(t){return this.check(Wn(BigInt(0),t))},nonnegative(t){return this.check(Jn(BigInt(0),t))},multipleOf(t,e){return this.check(qa(t,e))}}));function BH(t){return fS(np,t)}var ux=S("ZodBigIntFormat",(t,e)=>{c_.init(t,e),np.init(t,e)});function KH(t){return mS(ux,t)}function qH(t){return hS(ux,t)}var JC=S("ZodSymbol",(t,e)=>{u_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>eC(t,r,o,n)});function ZH(t){return gS(JC,t)}var GC=S("ZodUndefined",(t,e)=>{l_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>rC(t,r,o,n)});function WH(t){return yS(GC,t)}var XC=S("ZodNull",(t,e)=>{d_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>tC(t,r,o,n)});function Gh(t){return vS(XC,t)}var YC=S("ZodAny",(t,e)=>{p_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>iC(t,r,o,n)});function JH(){return wS(YC)}var QC=S("ZodUnknown",(t,e)=>{f_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>sC(t,r,o,n)});function dt(){return bS(QC)}var eO=S("ZodNever",(t,e)=>{m_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>oC(t,r,o,n)});function lx(t){return _S(eO,t)}var tO=S("ZodVoid",(t,e)=>{h_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>nC(t,r,o,n)});function GH(t){return SS(tO,t)}var Xh=S("ZodDate",(t,e)=>{g_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>aC(t,r,o,n),t.min=(r,o)=>t.check(Jn(r,o)),t.max=(r,o)=>t.check(Wn(r,o))},A.derived({minDate:t=>{let{minimum:e}=er(t);return e?new Date(e):null},maxDate:t=>{let{maximum:e}=er(t);return e?new Date(e):null}},{}));function XH(t){return xS(Xh,t)}var rO=S("ZodArray",(t,e)=>{qu(),y_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>wC(t,r,o,n),t.element=e.element},{min(t,e){return this.check(na(t,e))},nonempty(t){return this.check(na(1,t))},max(t,e){return this.check(Hu(t,e))},length(t,e){return this.check(Bu(t,e))},unwrap(){return this.element}});function Ae(t,e){return KR(rO,t,e)}function YH(t){let e=t._zod.def.shape;return Er(Object.keys(e))}var Yh=S("ZodObject",(t,e)=>{qu(),IR.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>bC(t,r,o,n),A.installLazyProp(t,"shape",r=>r._zod.def.shape,!1)},{keyof(){return Er(Object.keys(this._zod.def.shape))},catchall(t){return this.clone(A.mergeDefs(this._zod.def,{catchall:t}))},passthrough(){return this.clone(A.mergeDefs(this._zod.def,{catchall:dt()}))},loose(){return this.clone(A.mergeDefs(this._zod.def,{catchall:dt()}))},strict(){return this.clone(A.mergeDefs(this._zod.def,{catchall:lx()}))},strip(){return this.clone(A.mergeDefs(this._zod.def,{catchall:void 0}))},extend(t){return A.extend(this,t)},safeExtend(t){return A.safeExtend(this,t)},merge(t){return A.merge(this,t)},pick(t){return A.pick(this,t)},omit(t){return A.omit(this,t)},partial(...t){return A.partial(Ju,this,t[0])},exactPartial(...t){return A.partial(px,this,t[0],"exactPartial")},required(...t){return A.required(fx,this,t[0])}});function H(t,e){let r={type:"object",shape:t??{},...A.normalizeParams(e)};return new Yh(r)}function QH(t,e){return new Yh({type:"object",shape:t,catchall:lx(),...A.normalizeParams(e)})}function xr(t,e){return new Yh({type:"object",shape:t,catchall:dt(),...A.normalizeParams(e)})}var Qh=S("ZodUnion",(t,e)=>{Ad.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>MS(t,r,o,n),t.options=e.options});function tt(t,e){return new Qh({type:"union",options:t,...A.normalizeParams(e)})}var nO=S("ZodXor",(t,e)=>{Qh.init(t,e),w_.init(t,e),t._zod.processJSONSchema=(r,o,n)=>MS(t,r,o,n),t.options=e.options});function eB(t,e){return new nO({type:"union",options:t,inclusive:!1,...A.normalizeParams(e)})}var oO=S("ZodDiscriminatedUnion",(t,e)=>{Qh.init(t,e),b_.init(t,e)});function eg(t,e,r){return new oO({type:"union",options:e,discriminator:t,...A.normalizeParams(r)})}var iO=S("ZodIntersection",(t,e)=>{__.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>_C(t,r,o,n)});function op(t,e){return new iO({type:"intersection",left:t,right:e})}var sO=S("ZodTuple",(t,e)=>{qu(),mh.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>SC(t,r,o,n)},{rest(t){return this.clone({...this._zod.def,rest:t})},partial(){let t=this._zod.def;if(t.checks?.length)throw new Error(".partial() cannot be used on tuple schemas containing refinements");return this.clone({...t,items:t.items.map(e=>new Ju({type:"optional",innerType:e}))})}});function aO(t,e,r){let o=e instanceof ae,n=o?r:e,i=o?e:null;return new sO({type:"tuple",items:t,rest:i,...A.normalizeParams(n)})}var Yd=S("ZodRecord",(t,e)=>{qu(),S_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>xC(t,r,o,n),t.keyType=e.keyType,t.valueType=e.valueType});function at(t,e,r){return!e||!e._zod?new Yd({type:"record",keyType:I(),valueType:t,...A.normalizeParams(e)}):new Yd({type:"record",keyType:t,valueType:e,...A.normalizeParams(r)})}function tB(t,e,r){return new Yd({type:"record",keyType:t,valueType:e,...A.normalizeParams(r),partial:!0})}function rB(t,e,r){return new Yd({type:"record",keyType:t,valueType:e,mode:"loose",...A.normalizeParams(r)})}var cO=S("ZodMap",(t,e)=>{qu(),x_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>yC(t,r,o,n),t.keyType=e.keyType,t.valueType=e.valueType,t.min=(...r)=>t.check(Yi(...r)),t.nonempty=r=>t.check(Yi(1,r)),t.max=(...r)=>t.check(Za(...r)),t.size=(...r)=>t.check(Vu(...r))});function nB(t,e,r){return new cO({type:"map",keyType:t,valueType:e,...A.normalizeParams(r)})}var uO=S("ZodSet",(t,e)=>{qu(),E_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>vC(t,r,o,n),t.min=(...r)=>t.check(Yi(...r)),t.nonempty=r=>t.check(Yi(1,r)),t.max=(...r)=>t.check(Za(...r)),t.size=(...r)=>t.check(Vu(...r))});function oB(t,e){return new uO({type:"set",valueType:t,...A.normalizeParams(e)})}var Qd=S("ZodEnum",(t,e)=>{k_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(o,n,i)=>cC(t,o,n,i),t.enum=e.entries,t.options=[...t._zod.values];let r=new Set(Object.keys(e.entries));t.extract=(o,n)=>{let i={};for(let s of o)if(r.has(s))i[s]=e.entries[s];else throw new Error(`Key ${s} not found in enum`);return new Qd({...e,checks:[],...A.normalizeParams(n),entries:i})},t.exclude=(o,n)=>{let i={...e.entries};for(let s of o)if(r.has(s))delete i[s];else throw new Error(`Key ${s} not found in enum`);return new Qd({...e,checks:[],...A.normalizeParams(n),entries:i})}});function Er(t,e){let r=Array.isArray(t)?Object.fromEntries(t.map(o=>[o,o])):t;return new Qd({type:"enum",entries:r,...A.normalizeParams(e)})}function iB(t,e){return new Qd({type:"enum",entries:t,...A.normalizeParams(e)})}var lO=S("ZodLiteral",(t,e)=>{I_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>uC(t,r,o,n),t.values=new Set(e.values),Object.defineProperty(t,"value",{get(){if(e.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return e.values[0]}})});function G(t,e){return new lO({type:"literal",values:Array.isArray(t)?t:[t],...A.normalizeParams(e)})}var dO=S("ZodFile",(t,e)=>{$_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>pC(t,r,o,n),t.min=(r,o)=>t.check(Yi(r,o)),t.max=(r,o)=>t.check(Za(r,o)),t.mime=(r,o)=>t.check(Hd(Array.isArray(r)?r:[r],o))});function sB(t){return PS(dO,t)}var pO=S("ZodTransform",(t,e)=>{qu(),A_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>gC(t,r,o,n),t._zod.parse=(r,o)=>{if(o.direction==="backward")throw new Ha(t.constructor.name);r.addIssue=i=>{if(typeof i=="string")r.issues.push(A.issue(i,r.value,e));else{let s=i;s.fatal&&(s.continue=!1),s.code??(s.code="custom"),"input"in s||(s.input=r.value),s.inst??(s.inst=t),r.issues.push(A.issue(s))}};let n=e.transform(r.value,r);return n instanceof Promise?n.then(i=>(r.value=i,r)):(r.value=n,r)}});function dx(t){return new pO({type:"transform",transform:t})}var Ju=S("ZodOptional",(t,e)=>{hh.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>US(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function it(t){return new Ju({type:"optional",innerType:t})}var px=S("ZodExactOptional",(t,e)=>{T_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>US(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function fO(t){return new px({type:"optional",innerType:t})}var mO=S("ZodNullable",(t,e)=>{P_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>EC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function Wh(t){return new mO({type:"nullable",innerType:t})}function aB(t){return it(Wh(t))}var hO=S("ZodDefault",(t,e)=>{R_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>$C(t,r,o,n),t.unwrap=()=>t._zod.def.innerType,t.removeDefault=t.unwrap});function gO(t,e){return new hO({type:"default",innerType:t,get defaultValue(){return typeof e=="function"?e():A.shallowClone(e)}})}var yO=S("ZodPrefault",(t,e)=>{C_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>AC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function vO(t,e){return new yO({type:"prefault",innerType:t,get defaultValue(){return typeof e=="function"?e():A.shallowClone(e)}})}var fx=S("ZodNonOptional",(t,e)=>{O_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>kC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function wO(t,e){return new fx({type:"nonoptional",innerType:t,...A.normalizeParams(e)})}var bO=S("ZodSuccess",(t,e)=>{N_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>fC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function cB(t){return new bO({type:"success",innerType:t})}var _O=S("ZodCatch",(t,e)=>{D_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>TC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType,t.removeCatch=t.unwrap});function SO(t,e){return new _O({type:"catch",innerType:t,catchValue:typeof e=="function"?e:A.constantCatch(e)})}var xO=S("ZodNaN",(t,e)=>{z_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>lC(t,r,o,n)});function uB(t){return ES(xO,t)}var tg=S("ZodPipe",(t,e)=>{gh.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>PC(t,r,o,n),t.in=e.in,t.out=e.out});function BS(t,e){return new tg({type:"pipe",in:t,out:e})}var rg=S("ZodCodec",(t,e)=>{tg.init(t,e),Td.init(t,e)});function lB(t,e,r){return new rg({type:"pipe",in:t,out:e,transform:r.decode,reverseTransform:r.encode})}function dB(t){let e=t._zod.def;return new rg({type:"pipe",in:e.out,out:e.in,transform:e.reverseTransform,reverseTransform:e.transform})}var EO=S("ZodPreprocess",(t,e)=>{tg.init(t,e),AR.init(t,e)}),kO=S("ZodReadonly",(t,e)=>{j_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>RC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function IO(t){return new kO({type:"readonly",innerType:t})}var $O=S("ZodTemplateLiteral",(t,e)=>{M_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>dC(t,r,o,n)});function pB(t,e){return new $O({type:"template_literal",parts:t,...A.normalizeParams(e)})}var AO=S("ZodLazy",(t,e)=>{Pd.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>OC(t,r,o,n),t.unwrap=()=>t._zod.def.getter()});function TO(t){return new AO({type:"lazy",getter:t})}var PO=S("ZodPromise",(t,e)=>{L_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>CC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function fB(t){return new PO({type:"promise",innerType:t})}var RO=S("ZodFunction",(t,e)=>{U_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>hC(t,r,o,n)});function mB(t){return new RO({type:"function",input:Array.isArray(t?.input)?aO(t?.input):t?.input??Ae(dt()),output:t?.output??dt()})}var ng=S("ZodCustom",(t,e)=>{F_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>mC(t,r,o,n)});function hB(t){let e=new ot({check:"custom"});return e._zod.check=t,e}function mx(t,e){return RS(ng,t??(()=>!0),e)}function CO(t,e={}){return CS(ng,t,e)}function OO(t,e){return OS(t,e)}var gB=NS,yB=DS,NO=S("ZodInstanceOf",(t,e)=>{ng.init(t,e)},{properties(t,e){return this.check(Vd(t,e))}});function vB(t,e={}){let r=new NO({type:"custom",check:"custom",fn:o=>o instanceof t,abort:!0,...A.normalizeParams(e)});return r._zod.bag.Class=t,r._zod.check=o=>{o.value instanceof t||o.issues.push({code:"invalid_type",expected:t.name,input:o.value,inst:r,path:[...r._zod.def.path??[]]})},r}var wB=(...t)=>zS({Codec:rg,Boolean:rp,String:ep},...t);function bB(t){let e=TO(()=>tt([I(t),Ze(),Bt(),Gh(),Ae(e),at(I(),e)]));return e}function og(t,e){return new EO({type:"pipe",in:dx(t),out:e})}var zme={invalid_type:"invalid_type",too_big:"too_big",too_small:"too_small",invalid_format:"invalid_format",not_multiple_of:"not_multiple_of",unrecognized_keys:"unrecognized_keys",invalid_union:"invalid_union",invalid_key:"invalid_key",invalid_element:"invalid_element",invalid_value:"invalid_value",custom:"custom"};function jme(t){zt({customError:t})}function Mme(){return zt().customError}var DO;DO||(DO={});var Gu={};bt(Gu,{ZodISODate:()=>Qa,ZodISODateTime:()=>Ya,ZodISODuration:()=>tc,ZodISOTime:()=>ec,date:()=>Lme,datetime:()=>Ume,duration:()=>Vme,time:()=>Fme});function Ume(t){return Vh(Ya,t)}function Lme(t){return Hh(Qa,t)}function Fme(t){return Bh(ec,t)}function Vme(t){return Kh(tc,t)}var V={...ip,...FS,iso:Gu},Hme=new Set(["$schema","$ref","$defs","definitions","$id","id","$comment","$anchor","$vocabulary","$dynamicRef","$dynamicAnchor","type","enum","const","anyOf","oneOf","allOf","not","properties","required","additionalProperties","patternProperties","propertyNames","minProperties","maxProperties","items","prefixItems","additionalItems","minItems","maxItems","uniqueItems","contains","minContains","maxContains","minLength","maxLength","pattern","format","minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf","description","default","contentEncoding","contentMediaType","contentSchema","unevaluatedItems","unevaluatedProperties","if","then","else","dependentSchemas","dependentRequired","nullable","readOnly"]);function Bme(t,e){let r=t.$schema;return r==="https://json-schema.org/draft/2020-12/schema"?"draft-2020-12":r==="http://json-schema.org/draft-07/schema#"?"draft-7":r==="http://json-schema.org/draft-04/schema#"?"draft-4":e??"draft-2020-12"}function _B(t,e){return t.map((r,o)=>o<e?r:r.optional())}function Kme(t){return t.replace(/~1/g,"/").replace(/~0/g,"~")}function qme(t,e){if(!t.startsWith("#"))throw new Error("External $ref is not supported, only local refs (#/...) are allowed");let r=t.slice(1).split("/").filter(Boolean);if(r.length===0)return e.rootSchema;let o=e.version==="draft-2020-12"?"$defs":"definitions";if(r[0]===o){let n=r[1]===void 0?void 0:Kme(r[1]);if(!n||!e.defs[n])throw new Error(`Reference not found: ${t}`);return e.defs[n]}throw new Error(`Reference not found: ${t}`)}function Zme(t,e){return V.transform(o=>o).check(o=>{let n=o.value;if(typeof n!="object"||n===null||Array.isArray(n))return;let i=Object.getOwnPropertyNames(n);if(e.minProperties!==void 0&&i.length<e.minProperties&&o.issues.push({origin:"object",code:"too_small",minimum:e.minProperties,inclusive:!0,message:`Too small: expected object to have >=${e.minProperties} properties`,input:n,inst:t,continue:!0}),e.maxProperties!==void 0&&i.length>e.maxProperties&&o.issues.push({origin:"object",code:"too_big",maximum:e.maxProperties,inclusive:!0,message:`Too big: expected object to have <=${e.maxProperties} properties`,input:n,inst:t,continue:!0}),e.keySchema)for(let s of i){let a=e.keySchema.safeParse(s);a.success||o.issues.push({code:"invalid_key",origin:"record",issues:a.error.issues,input:s,path:[s],continue:!0})}}).pipe(t)}function zO(t,e){if(t===null)return"z";let r=typeof t;if(r!=="object"){if(r==="number"&&Number.isNaN(t))return null;let o=String(t);return`${r[0]}${o.length}:${o}`}if(e.has(t))return null;e.add(t);try{if(Array.isArray(t)){let i=[];for(let s of t){let a=zO(s,e);if(a===null)return null;i.push(a)}return`a${i.length}:[${i.join(",")}]`}let o=Object.keys(t).sort(),n=[];for(let i of o){let s=zO(t[i],e);if(s===null)return null;n.push(`${i.length}:${i}=${s}`)}return`o${n.length}:{${n.join(",")}}`}finally{e.delete(t)}}var Wme=new Set(["items","prefixItems","additionalItems","additionalProperties","contains","propertyNames","not","if","then","else","allOf","anyOf","oneOf","unevaluatedItems","unevaluatedProperties","contentSchema"]),Jme=new Set(["properties","patternProperties","dependentSchemas","dependencies","$defs","definitions"]);function ig(t){return typeof t!="object"||t===null?!1:Array.isArray(t)?t.some(ig):typeof t.$ref=="string"?!0:Object.entries(t).some(([e,r])=>Wme.has(e)?ig(r):!Jme.has(e)||typeof r!="object"||r===null?!1:Object.values(r).some(ig))}function SB(t){return t===1?"element":"elements"}function Gme(t,e){return V.transform(o=>o).check(o=>{let n=o.value;if(Array.isArray(n)){if(e.uniqueItems===!0){let i=new Map;for(let s=0;s<n.length;s++){let a=zO(n[s],new Set);if(a===null)continue;let c=i.get(a);if(c===void 0){i.set(a,s);continue}o.issues.push({code:"custom",message:`Array items must be unique: element at index ${s} duplicates the one at index ${c}`,input:n,path:[s],continue:!0})}}if(e.containsSchema){let i=e.minContains??1,s=e.maxContains!==void 0?e.maxContains+1:Number.POSITIVE_INFINITY,a=0;for(let c of n)if(e.containsSchema.safeParse(c).success&&++a>=s)break;a<i&&o.issues.push({code:"custom",message:`Array must contain at least ${i} matching ${SB(i)}; found ${a}`,input:n,continue:!0}),e.maxContains!==void 0&&a>e.maxContains&&o.issues.push({code:"custom",message:`Array must contain at most ${e.maxContains} matching ${SB(e.maxContains)}`,input:n,continue:!0})}}}).pipe(t)}function xB(t,e){if(t!==!1)return t===void 0||t===!0?V.any():pn(t,e)}var Xme=/^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/;function EB(t,e){if(t.not!==void 0){if(typeof t.not=="object"&&Object.keys(t.not).length===0)return V.never();throw new Error("not is not supported in Zod (except { not: {} } for never)")}if(t.unevaluatedItems!==void 0)throw new Error("unevaluatedItems is not supported");if(t.unevaluatedProperties!==void 0)throw new Error("unevaluatedProperties is not supported");if(t.if!==void 0||t.then!==void 0||t.else!==void 0)throw new Error("Conditional schemas (if/then/else) are not supported");if(t.dependentSchemas!==void 0||t.dependentRequired!==void 0)throw new Error("dependentSchemas and dependentRequired are not supported");if(t.$ref){let n=t.$ref;if(e.refs.has(n))return e.refs.get(n);if(e.processing.has(n))return V.lazy(()=>{if(!e.refs.has(n))throw new Error(`Circular reference not resolved: ${n}`);return e.refs.get(n)});e.processing.add(n);let i=qme(n,e),s=pn(i,e);return e.refs.set(n,s),e.processing.delete(n),s}if(t.enum!==void 0){let n=t.enum;if(e.version==="openapi-3.0"&&t.nullable===!0&&n.length===1&&n[0]===null)return V.null();if(n.length===0)return V.never();if(n.length===1)return V.literal(n[0]);if(n.every(s=>typeof s=="string"))return V.enum(n);let i=n.map(s=>V.literal(s));return i.length<2?i[0]:V.union([i[0],i[1],...i.slice(2)])}if(t.const!==void 0)return V.literal(t.const);let r=t.type;if(Array.isArray(r)){let n=r.map(i=>{let s={...t,type:i};return EB(s,e)});return n.length===0?V.never():n.length===1?n[0]:V.union(n)}if(!r)return V.any();let o;switch(r){case"string":{let n=V.string();if(t.format){let i=t.format;i==="email"?n=n.check(V.email()):i==="uri"||i==="uri-reference"?n=n.check(V.url()):i==="uuid"||i==="guid"?n=n.check(V.uuid()):i==="date-time"?n=n.check(V.iso.datetime({offset:!0})):i==="date"?n=n.check(V.iso.date()):i==="time"?n=n.check(V.regex(Xme)):i==="duration"?n=n.check(V.iso.duration()):i==="hostname"?n=n.check(V.hostname()):i==="ipv4"?n=n.check(V.ipv4()):i==="ipv6"?n=n.check(V.ipv6()):i==="mac"?n=n.check(V.mac()):i==="cidr"?n=n.check(V.cidrv4()):i==="cidr-v6"?n=n.check(V.cidrv6()):i==="base64"?n=n.check(V.base64()):i==="base64url"?n=n.check(V.base64url()):i==="e164"?n=n.check(V.e164()):i==="credit_card"?n=n.check(V.creditCard()):i==="iban"?n=n.check(V.iban()):i==="jwt"?n=n.check(V.jwt()):i==="emoji"?n=n.check(V.emoji()):i==="nanoid"?n=n.check(V.nanoid()):i==="cuid"?n=n.check(V.cuid()):i==="cuid2"?n=n.check(V.cuid2()):i==="ulid"?n=n.check(V.ulid()):i==="xid"?n=n.check(V.xid()):i==="ksuid"&&(n=n.check(V.ksuid()))}typeof t.minLength=="number"&&(n=n.min(t.minLength)),typeof t.maxLength=="number"&&(n=n.max(t.maxLength)),t.pattern&&(n=n.regex(new RegExp(t.pattern))),o=n;break}case"number":case"integer":{let n=r==="integer"?V.number().int():V.number();typeof t.minimum=="number"&&t.exclusiveMinimum!==!0&&(n=n.min(t.minimum)),typeof t.maximum=="number"&&t.exclusiveMaximum!==!0&&(n=n.max(t.maximum)),typeof t.exclusiveMinimum=="number"?n=n.gt(t.exclusiveMinimum):t.exclusiveMinimum===!0&&typeof t.minimum=="number"&&(n=n.gt(t.minimum)),typeof t.exclusiveMaximum=="number"?n=n.lt(t.exclusiveMaximum):t.exclusiveMaximum===!0&&typeof t.maximum=="number"&&(n=n.lt(t.maximum)),typeof t.multipleOf=="number"&&(n=n.multipleOf(t.multipleOf)),o=n;break}case"boolean":{o=V.boolean();break}case"null":{o=V.null();break}case"object":{let n={},i=t.properties||{},s=new Set(t.required||[]),a=typeof t.additionalProperties=="object"?pn(t.additionalProperties,e):void 0;for(let[d,f]of Object.entries(i)){let p=pn(f,e);_r(n,d,s.has(d)?p:p.optional())}if(t.patternProperties){let d=t.patternProperties,f=Object.keys(d),p=[];for(let g of f){let y=pn(d[g],e),w=V.string().regex(new RegExp(g));p.push(V.looseRecord(w,y))}let m=[];if(Object.keys(n).length>0&&m.push(V.object(n).passthrough()),m.push(...p),m.length===0)o=V.object({}).passthrough();else if(m.length===1)o=m[0];else{let g=V.intersection(m[0],m[1]);for(let y=2;y<m.length;y++)g=V.intersection(g,m[y]);o=g}if(t.additionalProperties===!1){let g=Object.keys(n),y=f.map(b=>new RegExp(b)),w=o;o=o.check(b=>{if(!yo(b.value))return;let _=[];for(let k of Object.keys(b.value))g.includes(k)||y.some($=>$.test(k))||_.push(k);_.length&&b.issues.push({code:"unrecognized_keys",keys:_,input:b.value,inst:w})})}}else{let d=V.object(n);t.additionalProperties===!1?o=d.strict():a?o=d.catchall(a):o=d.passthrough()}let c=t.propertyNames!==void 0&&t.propertyNames!==!0,u=typeof t.minProperties=="number"?t.minProperties:void 0,l=typeof t.maxProperties=="number"?t.maxProperties:void 0;if(c||u!==void 0||l!==void 0){let d;if(c){let f=typeof t.propertyNames=="object"&&t.propertyNames.type===void 0?{type:"string",...t.propertyNames}:t.propertyNames;d=pn(f,e)}o=Zme(o,{keySchema:d,minProperties:u,maxProperties:l})}break}case"array":{let n=t.prefixItems,i=t.items;if(n&&Array.isArray(n)){let s=typeof t.minItems=="number"?t.minItems:0,a=n.map(d=>pn(d,e)),c=_B(a,s),u=Array.isArray(i)?void 0:xB(i,e),l=V.tuple(c);o=u?l.rest(u):l,typeof t.minItems=="number"&&(o=o.check(V.minLength(t.minItems))),typeof t.maxItems=="number"&&(o=o.check(V.maxLength(t.maxItems)))}else if(Array.isArray(i)){let s=typeof t.minItems=="number"?t.minItems:0,a=i.map(d=>pn(d,e)),c=_B(a,s),u=xB(t.additionalItems,e),l=V.tuple(c);o=u?l.rest(u):l,typeof t.minItems=="number"&&(o=o.check(V.minLength(t.minItems))),typeof t.maxItems=="number"&&(o=o.check(V.maxLength(t.maxItems)))}else if(i!==void 0){let s=pn(i,e),a=V.array(s);typeof t.minItems=="number"&&(a=a.min(t.minItems)),typeof t.maxItems=="number"&&(a=a.max(t.maxItems)),o=a}else o=V.array(V.any());(t.uniqueItems===!0||t.contains!==void 0)&&(o=Gme(o,{uniqueItems:t.uniqueItems===!0,containsSchema:t.contains!==void 0?pn(t.contains,e):void 0,minContains:typeof t.minContains=="number"?t.minContains:void 0,maxContains:typeof t.maxContains=="number"?t.maxContains:void 0}));break}default:throw new Error(`Unsupported type: ${r}`)}return o}function pn(t,e){if(typeof t=="boolean")return t?V.any():V.never();let r=EB(t,e),o=t.type||t.enum!==void 0||t.const!==void 0;if(t.anyOf&&Array.isArray(t.anyOf)){let a=t.anyOf.map(u=>pn(u,e)),c=V.union(a);r=o?V.intersection(r,c):c}if(t.oneOf&&Array.isArray(t.oneOf)){let a=t.oneOf.map(u=>pn(u,e)),c=V.xor(a);r=o?V.intersection(r,c):c}if(t.allOf&&Array.isArray(t.allOf))if(t.allOf.length===0)r=o?r:V.any();else{let a=o?r:pn(t.allOf[0],e),c=o?0:1;for(let u=c;u<t.allOf.length;u++)a=V.intersection(a,pn(t.allOf[u],e));r=a}t.nullable===!0&&e.version==="openapi-3.0"&&(r=V.nullable(r)),t.readOnly===!0&&(r=V.readonly(r)),t.default!==void 0&&(r=r.default(t.default));let n={},i=["$id","id","$comment","$anchor","$vocabulary","$dynamicRef","$dynamicAnchor"];for(let a of i)a in t&&(n[a]=t[a]);let s=["contentEncoding","contentMediaType","contentSchema"];for(let a of s)a in t&&(n[a]=t[a]);if(t.type==="object"&&t.$ref===void 0){t.propertyNames!==void 0&&!ig(t.propertyNames)&&(n.propertyNames=t.propertyNames);for(let a of["minProperties","maxProperties"])t[a]!==void 0&&(n[a]=t[a])}if(t.type==="array"&&t.$ref===void 0){t.contains!==void 0&&!ig(t.contains)&&(n.contains=t.contains);for(let a of["uniqueItems","minContains","maxContains"])t[a]!==void 0&&(n[a]=t[a])}for(let a of Object.keys(t))Hme.has(a)||_r(n,a,t[a]);return Object.keys(n).length>0&&e.registry.add(r,n),t.description&&(r=r.describe(t.description)),r}function kB(t,e){if(typeof t=="boolean")return t?V.any():V.never();let r;try{r=JSON.parse(JSON.stringify(t))}catch{throw new Error("fromJSONSchema input is not valid JSON (possibly cyclic); use $defs/$ref for recursive schemas")}let o=Bme(r,e?.defaultTarget),n=r.$defs||r.definitions||{},i={version:o,defs:n,refs:new Map,processing:new Set,rootSchema:r,registry:e?.registry??Sr};return pn(r,i)}var IB=Symbol("z.visit/resolving");function sg(t,e){let r=typeof e=="function"?e:(s,a)=>{let c=e[s._zod.def.type];return c?c(s,a):s},o=new Map;function n(s){let a=o.get(s);if(a===IB)return new Pd({type:"lazy",getter:()=>o.get(s)});if(a!==void 0)return a;o.set(s,IB);let c=i(s),u=r(c,c!==s);return o.set(s,u),u}function i(s){let a=s._zod.def,c=a.type;switch(c){case"object":{let u=a.shape,l=Object.keys(u),d=!1,f={};for(let m of l){let g=n(u[m]);g!==u[m]&&(d=!0),f[m]=g}let p=a.catchall;return a.catchall&&(p=n(a.catchall),p!==a.catchall&&(d=!0)),d?qe(s,{...a,shape:f,catchall:p}):s}case"array":{let u=n(a.element);return u===a.element?s:qe(s,{...a,element:u})}case"tuple":{let u=a.items,l=!1,d=[];for(let p of u){let m=n(p);m!==p&&(l=!0),d.push(m)}let f=a.rest;return a.rest&&(f=n(a.rest),f!==a.rest&&(l=!0)),l?qe(s,{...a,items:d,rest:f}):s}case"record":case"map":{let u=n(a.keyType),l=n(a.valueType);return u===a.keyType&&l===a.valueType?s:qe(s,{...a,keyType:u,valueType:l})}case"set":{let u=n(a.valueType);return u===a.valueType?s:qe(s,{...a,valueType:u})}case"union":{let u=a.options,l=!1,d=[];for(let f of u){let p=n(f);p!==f&&(l=!0),d.push(p)}return l?qe(s,{...a,options:d}):s}case"intersection":{let u=n(a.left),l=n(a.right);return u===a.left&&l===a.right?s:qe(s,{...a,left:u,right:l})}case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":{let u=n(a.innerType);return u===a.innerType?s:qe(s,{...a,innerType:u})}case"pipe":{let u=n(a.in),l=n(a.out);return u===a.in&&l===a.out?s:qe(s,{...a,in:u,out:l})}case"function":{let u=n(a.input),l=n(a.output);return u===a.input&&l===a.output?s:qe(s,{...a,input:u,output:l})}case"lazy":{let u=a.getter,{_cachedInner:l,...d}=a;return qe(s,{...d,getter:()=>n(u())})}case"template_literal":case"string":case"number":case"int":case"boolean":case"bigint":case"symbol":case"undefined":case"null":case"void":case"never":case"any":case"unknown":case"date":case"nan":case"enum":case"literal":case"file":case"transform":case"custom":return s;default:return s}}return n(t)}function $B(t){return sg(t,{object:e=>e.partial(),union:e=>{let r=e._zod.def;return r.discriminator===void 0?e:tt(r.options)}})}function Yme(t,e){if(!e?.length)return t;let r=t._zod.def;return qe(t,go(r,{checks:[...r.checks??[],...e]}),{parent:!0})}function AB(t){return Yme(t.out,t.checks)}function Qme(t){return t.in._zod.traits.has("$ZodTransform")?AB(t):t.in}function TB(t){return sg(t,{pipe:e=>Qme(e._zod.def),default:(e,r)=>r?it(e._zod.def.innerType):e,catch:(e,r)=>r?e._zod.def.innerType:e})}function PB(t){return sg(t,{pipe:e=>AB(e._zod.def),prefault:(e,r)=>r?e._zod.def.innerType:e})}var jO={};bt(jO,{bigint:()=>nhe,boolean:()=>rhe,date:()=>ohe,number:()=>the,string:()=>ehe});function ehe(t){return UR(ep,t)}function the(t){return FR(tp,t)}function rhe(t){return VR(rp,t)}function nhe(t){return HR(np,t)}function ohe(t){return BR(Xh,t)}var ag={name:"@tomato414941/foundation",version:"29.0.2",description:"Manage Foundation resources and use them in local commands.",type:"module",engines:{node:">=24"},bin:{foundation:"dist/cli.mjs"},files:["dist/cli.mjs"],repository:{type:"git",url:"git+https://github.com/tomato414941/foundation.git",directory:"cli"},publishConfig:{access:"public",registry:"https://registry.npmjs.org/"},license:"MIT"};typeof window<"u"&&h.config({jitless:!0});function RB(t){let e=/^(ssh-ed25519|ssh-rsa|ecdsa-sha2-nistp(?:256|384|521))[ \t]+([A-Za-z0-9+/]+={0,2})(?:[ \t]+[^\r\n\0]*)?$/.exec(t.trim());if(!e)return null;try{let r=Uint8Array.from(atob(e[2]),a=>a.charCodeAt(0)),o=new DataView(r.buffer),n=0,i=()=>{if(n+4>r.length)throw new Error("Invalid SSH key.");let a=o.getUint32(n);if(n+=4,n+a>r.length)throw new Error("Invalid SSH key.");let c=r.subarray(n,n+a);return n+=a,c},s=a=>new TextDecoder().decode(a);if(s(i())!==e[1])return null;if(e[1]==="ssh-ed25519"){if(i().length!==32)return null}else if(e[1]==="ssh-rsa"){let a=i(),c=i();if(!a.length||c.length<256||c.length>1025)return null}else{let a=s(i()),c=i(),u={nistp256:65,nistp384:97,nistp521:133};if(e[1]!=="ecdsa-sha2-"+a||c[0]!==4||c.length!==u[a])return null}return n===r.length?r:null}catch{return null}}var cg=h.string().trim().max(8192).refine(t=>RB(t)!==null,"Use an OpenSSH public key from a .pub file.");function MO(t){if(!RB(t))throw new Error("Use an OpenSSH public key from a .pub file.");let[e,r]=t.trim().split(/[ \t]+/);return{algorithm:e,key:r,publicKey:e+" "+r}}var sp=h.string().max(32).regex(/^[a-z_][a-z0-9_-]*$/,"Use a lowercase account name."),hx=h.string().min(1).max(253).regex(/^[A-Za-z0-9_.:]+(?:-[A-Za-z0-9_.:]+)*$/,"Use a host name or IP address."),gx=h.string().min(1).max(1024).regex(/^[A-Za-z0-9._/%-]+$/).refine(t=>!t.split("/").includes("..")&&!/%(?!u)/.test(t)&&!t.endsWith("/"),"Use a file path, with %u for the account."),RFe=h.string().min(1).max(500).regex(/^[A-Za-z0-9.:*?/!_-]+(?:,[A-Za-z0-9.:*?/!_-]+)*$/,"Use comma-separated host or address patterns."),yx=h.string().regex(/^SHA256:[A-Za-z0-9+/]{43}$/);var ap=new TextEncoder,cp=new TextDecoder,CB=new TextDecoder("utf-8",{fatal:!0}),vx=2**32;function fn(...t){let e=t.reduce((n,{length:i})=>n+i,0),r=new Uint8Array(e),o=0;for(let n of t)r.set(n,o),o+=n.length;return r}function UO(t,e,r){if(e<0||e>=vx)throw new RangeError(`value must be >= 0 and <= ${vx-1}. Received ${e}`);t.set([e>>>24,e>>>16,e>>>8,e&255],r)}function LO(t){let e=Math.floor(t/vx),r=t%vx,o=new Uint8Array(8);return UO(o,e,0),UO(o,r,4),o}function wx(t){let e=new Uint8Array(4);return UO(e,t),e}var she=/[^\x00-\x7f]/;function kr(t){if(typeof t=="string"&&t.length>=128){if(she.test(t))throw new TypeError("non-ASCII string encountered in encode()");return ap.encode(t)}let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++){let o=t.charCodeAt(r);if(o>127)throw new TypeError("non-ASCII string encountered in encode()");e[r]=o}return e}function OB(t,e=!1){if(Uint8Array.prototype.toBase64)return t.toBase64({alphabet:e?"base64url":"base64",omitPadding:e});let r=32768,o=[];for(let i=0;i<t.length;i+=r)o.push(String.fromCharCode.apply(null,t.subarray(i,i+r)));let n=btoa(o.join(""));return e?n.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_"):n}function NB(t,e=!1){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(t,{alphabet:e?"base64url":"base64"});if(e){if(t.includes("+")||t.includes("/"))throw new TypeError("Invalid base64url");t=t.replace(/-/g,"+").replace(/_/g,"/")}let r=atob(t),o=new Uint8Array(r.length);for(let n=0;n<r.length;n++)o[n]=r.charCodeAt(n);return o}async function bx(t,e){let r=`SHA-${t.slice(-3)}`;return new Uint8Array(await crypto.subtle.digest(r,e))}var oa=class extends Error{static code="ERR_JOSE_GENERIC";code="ERR_JOSE_GENERIC";constructor(e,r){super(e,r),this.name=this.constructor.name,Error.captureStackTrace?.(this,this.constructor)}};var Xu=class extends oa{static code="ERR_JOSE_ALG_NOT_ALLOWED";code="ERR_JOSE_ALG_NOT_ALLOWED"},ct=class extends oa{static code="ERR_JOSE_NOT_SUPPORTED";code="ERR_JOSE_NOT_SUPPORTED"},rc=class extends oa{static code="ERR_JWE_DECRYPTION_FAILED";code="ERR_JWE_DECRYPTION_FAILED";constructor(e="decryption operation failed",r){super(e,r)}},U=class extends oa{static code="ERR_JWE_INVALID";code="ERR_JWE_INVALID"},kt=class extends oa{static code="ERR_JWS_INVALID";code="ERR_JWS_INVALID"};var ug=class extends oa{static code="ERR_JWK_INVALID";code="ERR_JWK_INVALID"};var _x=class extends oa{static code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";constructor(e="signature verification failed",r){super(e,r)}};var ahe="The input to be decoded is not correctly encoded.";function Yu(t){try{return NB(typeof t=="string"?t:cp.decode(t),!0)}catch(e){throw new TypeError(ahe,{cause:e})}}function Rt(t){return OB(typeof t=="string"?ap.encode(t):t,!0)}function Gn(t,e){if(!(t instanceof Uint8Array))throw new TypeError(`${e} must be an instance of Uint8Array`)}function Zt(t){if(typeof t!="object"||t===null||Object.prototype.toString.call(t)!=="[object Object]")return!1;let e=Object.getPrototypeOf(t);return e===null||Object.getPrototypeOf(e)===null}function nc(...t){let e=new Set;for(let r of t)if(r)for(let o of Object.keys(r)){if(e.has(o))return!1;e.add(o)}return!0}function wo(t,e){if(t!==void 0)throw new TypeError(`${e} can only be called once`)}function Rn(t,e,r){try{return Yu(t)}catch{throw new r(`Failed to base64url decode the ${e}`)}}function Sx(t,e,r){try{return kr(t)}catch{throw new r(`The ${e} is not a valid base64url string`)}}function up(t,e,r){let o;try{o=JSON.parse(CB.decode(Yu(t)))}catch{throw new e(r)}if(!Zt(o))throw new e(r);return o}var xx={__proto__:null,b64:!0},Ex={__proto__:null};function lg(t,e){if(e!==void 0&&(!Array.isArray(e)||e.some(r=>typeof r!="string")))throw new TypeError(`"${t}" option must be an array of strings`);return e===void 0?void 0:new Set(e)}function kx(t,e){let{crit:r}=e??{};if(Array.isArray(r)&&new Set(r).size!==r.length)throw new t('"crit" (Critical) Header Parameter MUST NOT contain duplicate values')}function oc(t,e,r,o,n){if(n.crit!==void 0&&o?.crit===void 0)throw new t('"crit" (Critical) Header Parameter MUST be integrity protected');if(!o||o.crit===void 0)return[];if(!Array.isArray(o.crit)||o.crit.length===0||o.crit.some(s=>typeof s!="string"||s.length===0))throw new t('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');let i=r===void 0?e:{__proto__:null,...r,...e};for(let s of o.crit){if(!(s in i))throw new ct(`Extension Header Parameter "${s}" is not recognized`);if(!Object.hasOwn(n,s)||n[s]===void 0)throw new t(`Extension Header Parameter "${s}" is missing`);if(i[s]&&(!Object.hasOwn(o,s)||o[s]===void 0))throw new t(`Extension Header Parameter "${s}" MUST be integrity protected`)}return o.crit}function Ix(t,e){if(e.includes("b64")){let r=t.b64;if(typeof r!="boolean")throw new kt('The "b64" (base64url-encode payload) Header Parameter must be a boolean');return r}return!0}function Qu(t,e){let r,o;try{r=JSON.stringify(e),o=JSON.parse(r)}catch(n){throw new t("JOSE Header is not valid JSON",{cause:n})}if(!Zt(o))throw new t("JOSE Header is not a JSON object");return[o,r]}var che=t=>t[Symbol.toStringTag],uhe=(t,e,r)=>{let{alg:o}=t;if(e.use!==void 0){let n=r==="sign"||r==="verify"?"sig":"enc";if(e.use!==n)throw new TypeError(`Invalid key for this operation, its "use" must be "${n}" when present`)}if(e.alg!==void 0&&e.alg!==o)throw new TypeError(`Invalid key for this operation, its "alg" must be "${o}" when present`);if(Array.isArray(e.key_ops)){let n=r==="encrypt"||r==="decrypt"?t.ops?.[r==="encrypt"?0:1]:r;if(n&&!e.key_ops.includes(n))throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${n}" when present`)}};async function oi(t,e,r){let{alg:o,secret:n}=t,i=r==="decrypt"||r==="sign";if(n&&e instanceof Uint8Array)return e;let s,a;if(Zt(e)){if(s=qO(e),typeof s.kty!="string")throw DB(o,e,n);if(!(n?s.kty==="oct"&&typeof s.k=="string":s.kty!=="oct"&&(i?s.kty==="AKP"&&typeof s.priv=="string"||typeof s.d=="string":s.d===void 0&&s.priv===void 0)))throw new TypeError(n?'JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present':`JSON Web Key for this operation must be a ${i?"private":"public"} JWK`);if(uhe(t,s,r),s.kty==="oct")return Yu(s.k);if(!Object.isFrozen(e)){let{key_ops:l}=e;Array.isArray(l)&&Object.freeze(l),Object.freeze(e)}}else{if(!HO(e))throw DB(o,e,n);let l=n?"secret":i?"private":"public";if(e.type!==l&&(n||["secret","public","private"].includes(e.type)))throw new TypeError(`${che(e)} instances must be of type "${l}" for the ${o} algorithm`);if(ic(e))return e;if(a=e,a.type==="secret")return a.export()}FO||=new WeakMap;let c=e,u=FO.get(c);if(u?.[o])return u[o];if(u||FO.set(c,u={}),a&&typeof a.toCryptoKey=="function"){let l=a.type==="public",d=lhe[a.asymmetricKeyDetails?.namedCurve],f=t.resolve?.({crv:d,asymmetricKeyType:a.asymmetricKeyType})??t.subtle;return u[o]=a.toCryptoKey(f,l,t.usages[l?0:1])}return s??=a.export({format:"jwk"}),s.alg=o,u[o]=await dp(t,s)}var FO,lhe={__proto__:null,prime256v1:"P-256",secp384r1:"P-384",secp521r1:"P-521"};function Ax(t){if(!ic(t))throw new Error("CryptoKey instance expected")}var ic=t=>{if(t?.[Symbol.toStringTag]==="CryptoKey")return!0;try{return t instanceof CryptoKey}catch{return!1}},VO=t=>t?.[Symbol.toStringTag]==="KeyObject",HO=t=>ic(t)||VO(t);function zB(t,e,...r){if(r.length>2){let o=r.pop();t+=`one of type ${r.join(", ")}, or ${o}.`}else r.length===2?t+=`one of type ${r[0]} or ${r[1]}.`:t+=`of type ${r[0]}.`;return e==null?t+=` Received ${e}`:typeof e=="function"&&e.name?t+=` Received function ${e.name}`:typeof e=="object"&&e!=null&&e.constructor?.name&&(t+=` Received an instance of ${e.constructor.name}`),t}var ia=(t,...e)=>zB("Key must be ",t,...e);function DB(t,e,r){let o=["CryptoKey","KeyObject","JSON Web Key"];return r&&o.push("Uint8Array"),new TypeError(zB(`Key for the ${t} algorithm must be `,e,...o))}var $x=(t,e="algorithm.name")=>new TypeError(`CryptoKey does not support this operation, its ${e} must be ${t}`);function BO(t,e){if(e&&!t.usages.includes(e))throw new TypeError(`CryptoKey does not support this operation, its usages must include ${e}.`)}function lp(t,e){let{modulusLength:r}=e.algorithm;if(typeof r!="number"||r<2048)throw new TypeError(`${t} requires key modulusLength to be 2048 bits or larger`)}function KO(t,e,r){let o=t.algorithm;if(o.name!==e.name)throw $x(e.name);if(e.hash&&o.hash?.name!==e.hash)throw $x(e.hash,"algorithm.hash");if(e.namedCurve&&o.namedCurve!==e.namedCurve)throw $x(e.namedCurve,"algorithm.namedCurve");if(e.length!==void 0&&o.length!==e.length)throw $x(e.length,"algorithm.length");BO(t,r)}function Tx(t){return{__proto__:null,...t}}function qO(t){let e=Tx(t);if(e.ext!==void 0&&typeof e.ext!="boolean")throw new TypeError('"ext" (Extractable) Parameter must be a boolean');if(e.key_ops!==void 0){let r=e.key_ops,o=Array.isArray(r)?[...r]:void 0;if(!o||o.some(n=>typeof n!="string")||new Set(o).size!==o.length)throw new TypeError('"key_ops" (Key Operations) Parameter must be an array of unique strings');e.key_ops=o}return e}function Px(t){if(t!==void 0&&typeof t!="boolean")throw new TypeError('"extractable" option must be a boolean');return t}async function dp(t,e,r){if(!t.kty.includes(e.kty))throw new ct('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');let o=t.resolve?.({kty:e.kty,crv:e.crv})??t.subtle,n=!!(e.d||e.priv),i={...e,ext:r??e.ext};return i.kty!=="AKP"&&delete i.alg,delete i.use,crypto.subtle.importKey("jwk",i,o,i.ext??!n,e.key_ops??t.usages[n?1:0])}async function ii(t,e,r,o=!1){return t instanceof Uint8Array&&(t=await crypto.subtle.importKey("raw",t,e,o,[r])),KO(t,e,r),t}var el=t=>crypto.getRandomValues(new Uint8Array(t.cekBits>>3));function Rx(t,e){let r=t.byteLength<<3;if(r!==e)throw new U(`Invalid Content Encryption Key length. Expected ${e} bits, got ${r} bits`)}var dhe=t=>crypto.getRandomValues(new Uint8Array(t.ivBits>>3));function jB(t,e){if(e.length<<3!==t.ivBits)throw new U("Invalid Initialization Vector length")}async function MB(t,e,r){if(!(e instanceof Uint8Array))throw new TypeError(ia(e,"Uint8Array"));let o=t.cekBits>>1,n=await crypto.subtle.importKey("raw",e.subarray(o>>3),"AES-CBC",!1,[r]),i=await crypto.subtle.importKey("raw",e.subarray(0,o>>3),{hash:`SHA-${o<<1}`,name:"HMAC"},!1,["sign"]);return[n,i,o]}async function UB(t,e,r){return new Uint8Array((await crypto.subtle.sign("HMAC",t,e)).slice(0,r>>3))}async function phe(t,e,r,o,n){let[i,s,a]=await MB(t,r,"encrypt"),c=new Uint8Array(await crypto.subtle.encrypt({iv:o,name:"AES-CBC"},i,e)),u=fn(n,o,c,LO(n.length*8)),l=await UB(s,u,a);return{ciphertext:c,tag:l,iv:o}}async function fhe(t,e){let r={name:"HMAC",hash:"SHA-256"},o=await crypto.subtle.generateKey(r,!1,["sign","verify"]),n=await crypto.subtle.sign(r,o,t);return crypto.subtle.verify(r,o,n,e)}async function mhe(t,e,r,o,n,i){let[s,a,c]=await MB(t,e,"decrypt"),u=fn(i,o,r,LO(i.length*8)),l=await UB(a,u,c);try{if(await fhe(n,l))return new Uint8Array(await crypto.subtle.decrypt({iv:o,name:"AES-CBC"},s,r))}catch{}throw new rc}async function Cx(t,e,r,o,n){if(!ic(r)&&!(r instanceof Uint8Array))throw new TypeError(ia(r,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(o?jB(t,o):o=dhe(t),r instanceof Uint8Array&&Rx(r,t.cekBits),t.cbc)return phe(t,e,r,o,n);let i=await ii(r,t.subtle,"encrypt"),s=new Uint8Array(await crypto.subtle.encrypt({additionalData:n,iv:o,name:"AES-GCM",tagLength:128},i,e));return{ciphertext:s.subarray(0,-16),tag:s.subarray(-16),iv:o}}async function Ox(t,e,r,o,n,i){if(!ic(e)&&!(e instanceof Uint8Array))throw new TypeError(ia(e,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(!o)throw new U("JWE Initialization Vector missing");if(!n)throw new U("JWE Authentication Tag missing");if(!t.cbc&&n.length!==16)throw new U("Invalid Authentication Tag length");if(jB(t,o),e instanceof Uint8Array&&Rx(e,t.cekBits),t.cbc)return mhe(t,e,r,o,n,i);let s=await ii(e,t.subtle,"decrypt");try{return new Uint8Array(await crypto.subtle.decrypt({additionalData:i,iv:o,name:"AES-GCM",tagLength:128},s,fn(r,n)))}catch{throw new rc}}function dg(t){let e={__proto__:null};for(let r in t)e[r]={...t[r],alg:r};return e}var hhe=[["encrypt","wrapKey"],["decrypt","unwrapKey"]],ghe=[[],["deriveBits"]],zx=[[],[]];function Nx(t){return{kty:["RSA"],mode:"key-encryption",subtle:{name:"RSA-OAEP",hash:`SHA-${t}`},usages:hhe,ops:["wrapKey","unwrapKey"]}}function Dx(t){return{kty:["EC","OKP"],mode:t,subtle:{name:"ECDH"},resolve:({kty:e,crv:r,asymmetricKeyType:o})=>{if(r==="X25519"||o==="x25519")return{name:"X25519"};if(e==="OKP")throw new ct('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');return{name:"ECDH",namedCurve:r}},usages:ghe,ops:[void 0,"deriveBits"]}}function pp(t,e=!1){return{kty:["oct"],mode:"key-wrapping",secret:!0,subtle:{name:e?"AES-GCM":"AES-KW",length:t},usages:zx,ops:e?["encrypt","decrypt"]:["wrapKey","unwrapKey"]}}function ZO(){return{kty:["oct"],mode:"key-wrapping",secret:!0,subtle:{name:"PBKDF2"},usages:zx,ops:["deriveBits","deriveBits"]}}var sa=dg({dir:{kty:["oct"],mode:"direct-encryption",secret:!0,subtle:{name:"AES-GCM"},usages:zx,ops:["encrypt","decrypt"]},"RSA-OAEP":Nx(1),"RSA-OAEP-256":Nx(256),"RSA-OAEP-384":Nx(384),"RSA-OAEP-512":Nx(512),"ECDH-ES":Dx("direct-key-agreement"),"ECDH-ES+A128KW":Dx("key-agreement-with-key-wrapping"),"ECDH-ES+A192KW":Dx("key-agreement-with-key-wrapping"),"ECDH-ES+A256KW":Dx("key-agreement-with-key-wrapping"),A128KW:pp(128),A192KW:pp(192),A256KW:pp(256),A128GCMKW:pp(128,!0),A192GCMKW:pp(192,!0),A256GCMKW:pp(256,!0),"PBES2-HS256+A128KW":ZO(),"PBES2-HS384+A192KW":ZO(),"PBES2-HS512+A256KW":ZO()}),yhe=["encrypt","decrypt"];function fp(t,e=!1){return{kty:["oct"],secret:!0,subtle:{name:e?"AES-CBC":"AES-GCM",length:t},usages:zx,ops:yhe,cekBits:t,ivBits:e?128:96,cbc:e}}var vhe=dg({A128GCM:fp(128),A192GCM:fp(192),A256GCM:fp(256),"A128CBC-HS256":fp(256,!0),"A192CBC-HS384":fp(384,!0),"A256CBC-HS512":fp(512,!0)});function LB(t,e){throw new ct(`Invalid or unsupported "${t}" (JWE ${e}) header value`)}function si(t){return(typeof t=="string"?sa[t]:void 0)??LB("alg","Algorithm")}function ai(t){return t.mode==="key-wrapping"||t.mode==="key-encryption"||t.mode==="key-agreement-with-key-wrapping"}function tl(t){return(typeof t=="string"?vhe[t]:void 0)??LB("enc","Encryption Algorithm")}function FB(t,e){if(t.algorithm.name!=="ECDH"&&t.algorithm.name!=="X25519")throw new TypeError("CryptoKey does not support this operation, its algorithm.name must be ECDH or X25519");BO(t,e)}async function whe(t,e,r){let o=await ii(e,si(t).subtle,"wrapKey",!0),n=await crypto.subtle.importKey("raw",r,{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.wrapKey("raw",n,o,"AES-KW"))}async function bhe(t,e,r){let o=await ii(e,si(t).subtle,"unwrapKey",!0),n=await crypto.subtle.unwrapKey("raw",r,o,"AES-KW",{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.exportKey("raw",n))}function HB(t,e,r){KO(e,si(t).subtle,r),lp(t,e)}async function BB(t,e,r,o){if(!(t instanceof Uint8Array)||t.length<8)throw new U("PBES2 Salt Input must be 8 or more octets");if(!Number.isSafeInteger(r)||Math.sign(r)!==1)throw new U("PBES2 Count Input must be a positive integer");let n=fn(kr(e),Uint8Array.of(0),t),i=parseInt(e.slice(13,16),10),s={hash:`SHA-${e.slice(8,11)}`,iterations:r,name:"PBKDF2",salt:n},a=await ii(o,si(e).subtle,"deriveBits");return new Uint8Array(await crypto.subtle.deriveBits(s,a,i))}function WO(t){return fn(wx(t.length),t)}async function _he(t,e,r){let o=e>>3,n=32,i=Math.ceil(o/n),s=new Uint8Array(i*n);for(let a=1;a<=i;a++){let c=await bx("sha256",fn(wx(a),t,r));s.set(c,(a-1)*n)}return s.slice(0,o)}async function KB(t,e,r,o,n=new Uint8Array,i=new Uint8Array){FB(t),FB(e,"deriveBits");let s=fn(WO(kr(r)),WO(n),WO(i),wx(o)),a=new Uint8Array(await crypto.subtle.deriveBits({name:t.algorithm.name,public:t},e,t.algorithm.name==="X25519"?256:Math.ceil(parseInt(t.algorithm.namedCurve.slice(-3),10)/8)<<3));return _he(a,o,s)}function qB(t){Ax(t);let e=t.algorithm.namedCurve;if(e!=="P-256"&&e!=="P-384"&&e!=="P-521"&&t.algorithm.name!=="X25519")throw new ct("ECDH with the provided key is not allowed or not supported by your javascript runtime")}function jx(t,e){let r=t[e];if(r!==void 0){if(typeof r!="string")throw new U(`JOSE Header "${e}" (Agreement Party${e==="apu"?"U":"V"}Info) invalid`);return Rn(r,e,U)}}function ZB(t,e){if(!(t===void 0||e===void 0||t.byteLength!==e.byteLength)){for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return;throw new U('JOSE Header "apu" and "apv" values must be distinct')}}function She(t){if(t===void 0)throw new U("JWE Encrypted Key missing")}function VB(t){if(t!==void 0)throw new U("Encountered unexpected JWE Encrypted Key")}function xhe(t){if(t!==void 0&&t!==1/0&&(!Number.isSafeInteger(t)||t<1))throw new TypeError("maxPBES2Count must be a positive safe integer or Infinity")}async function WB(t,e,r,o,n,i){let{alg:s}=t,a=t.mode;if(a==="direct-encryption")return VB(o),r;let c=a==="direct-key-agreement";switch(c?VB(o):She(o),t.subtle.name){case"ECDH":{let{epk:u}=n;if(!Zt(u)||["d","k","p","q","dp","dq","qi","oth","priv"].some(m=>Object.hasOwn(u,m)))throw new U('JOSE Header "epk" (Ephemeral Public Key) missing or invalid');qB(r);let l=await dp(t,u),d=jx(n,"apu"),f=jx(n,"apv");ZB(d,f);let p=await KB(l,r,c?e.alg:s,c?e.cekBits:parseInt(s.slice(-5,-2),10),d,f);if(c)return p;r=p;break}case"RSA-OAEP":return Ax(r),HB(s,r,"decrypt"),new Uint8Array(await crypto.subtle.decrypt("RSA-OAEP",r,o));case"PBKDF2":{if(typeof n.p2c!="number")throw new U('JOSE Header "p2c" (PBES2 Count) missing or invalid');xhe(i);let u=i??1e4;if(n.p2c>u)throw new U('JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds');if(typeof n.p2s!="string")throw new U('JOSE Header "p2s" (PBES2 Salt) missing or invalid');let l=Rn(n.p2s,"p2s",U);r=await BB(l,s,n.p2c,r);break}case"AES-GCM":{if(typeof n.iv!="string")throw new U('JOSE Header "iv" (Initialization Vector) missing or invalid');if(typeof n.tag!="string")throw new U('JOSE Header "tag" (Authentication Tag) missing or invalid');let u=Rn(n.iv,"iv",U),l=Rn(n.tag,"tag",U);if(u.byteLength!==12)throw new U("Invalid Initialization Vector length");if(l.byteLength!==16)throw new U("Invalid Authentication Tag length");return Ox(tl(s.slice(0,-2)),r,o,u,l,new Uint8Array)}}return bhe(s.slice(-6),r,o)}async function Mx(t,e,r,o,n,i={}){let{alg:s,mode:a}=t,c=ai(t);if(n!==void 0&&!c)throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${s}`);let u=await oi(a==="direct-encryption"?e:t,r,"encrypt");if(a==="direct-encryption")return[u,void 0,void 0];let l=c?n??el(e):void 0;l&&Rx(l,e.cekBits);let d,f;switch(t.subtle.name){case"ECDH":{qB(u);let{apu:p,apv:m}=i;p!==void 0&&Gn(p,'"apu"'),m!==void 0&&Gn(m,'"apv"');let g=p??jx(o,"apu"),y=m??jx(o,"apv");ZB(g,y);let w;i.epk!==void 0?w=await oi(t,i.epk,"decrypt"):w=(await crypto.subtle.generateKey(u.algorithm,!0,["deriveBits"])).privateKey;let b=crypto.subtle,_=w;if(!_.extractable){if(typeof b.getPublicKey!="function")throw new TypeError('CryptoKey for "epk" must be extractable');_=await b.getPublicKey(w,[])}let{x:k,y:$,crv:D,kty:K}=await b.exportKey("jwk",_),te=a==="direct-key-agreement",Ie=await KB(u,w,te?e.alg:s,te?e.cekBits:parseInt(s.slice(-5,-2),10),g,y),xe={x:k,crv:D,kty:K};if(K==="EC"&&(xe.y=$),f={epk:xe},p!==void 0&&(f.apu=Rt(p)),m!==void 0&&(f.apv=Rt(m)),te)return[Ie,void 0,f];u=Ie;break}case"RSA-OAEP":{Ax(u),HB(s,u,"encrypt"),d=new Uint8Array(await crypto.subtle.encrypt("RSA-OAEP",u,l));break}case"PBKDF2":{let{p2c:p=2048,p2s:m=crypto.getRandomValues(new Uint8Array(16))}=i;u=await BB(m,s,p,u),f={p2c:p,p2s:Rt(m)};break}case"AES-GCM":{let p=i.iv===void 0?crypto.getRandomValues(new Uint8Array(12)):i.iv;if(!(p instanceof Uint8Array))throw new TypeError('"iv" must be an instance of Uint8Array');let m=await Cx(tl(s.slice(0,-2)),l,u,p,new Uint8Array);d=m.ciphertext,f={iv:Rt(m.iv),tag:Rt(m.tag)}}}if(d??=await whe(s.slice(-6),u,l),!(d instanceof Uint8Array)||!d.byteLength)throw new TypeError("JWE key management algorithm did not produce an Encrypted Key");return[l,d,f]}function Ux(t,e){if(t.zip!==void 0&&t.zip!=="DEF")throw new ct('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');if(t.zip!==void 0&&!e?.zip)throw new U('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.')}function JB(t){if(typeof globalThis[t]>"u")throw new ct(`JWE "zip" (Compression Algorithm) Header Parameter requires the ${t} API.`)}async function GB(t,e,r=1/0){let o=t.writable.getWriter();o.write(e).catch(()=>{}),o.close().catch(()=>{});let n=[],i=0,s=t.readable.getReader();for(;;){let{value:a,done:c}=await s.read();if(c)break;if(n.push(a),i+=a.byteLength,r!==1/0&&i>r)throw new U("Decompressed plaintext exceeded the configured limit")}return fn(...n)}async function XB(t){return JB("CompressionStream"),GB(new CompressionStream("deflate-raw"),t)}async function YB(t,e){return JB("DecompressionStream"),GB(new DecompressionStream("deflate-raw"),t,e)}function QB(t){let{aad:e,ciphertext:r,iv:o,protected:n,tag:i,unprotected:s}=t;if(o!==void 0&&(typeof o!="string"||!o))throw new U("JWE Initialization Vector incorrect type");if(typeof r!="string")throw new U("JWE Ciphertext missing or incorrect type");if(i!==void 0&&(typeof i!="string"||!i))throw new U("JWE Authentication Tag incorrect type");if(n!==void 0&&typeof n!="string")throw new U("JWE Protected Header incorrect type");if(e!==void 0&&(typeof e!="string"||!e))throw new U("JWE AAD incorrect type");if(s!==void 0&&!Zt(s))throw new U("JWE Shared Unprotected Header incorrect type");return{aad:e,ciphertext:r,iv:o,protected:n,tag:i,unprotected:s===void 0?void 0:{...s}}}function eK(t){let e,r;try{let{header:o}=t;if(Zt(o)){r=o.alg;let i=Object.keys(o);i.includes("alg")||(r=void 0),e=Object.fromEntries(i.map(s=>[s,s==="alg"?r:o[s]]))}else e=o;let{encrypted_key:n}=t;return[{encrypted_key:n,header:e},r]}catch(o){return[void 0,r,o]}}function tK(t){let{encrypted_key:e,header:r}=t;if(e!==void 0&&typeof e!="string")throw new U("JWE Encrypted Key incorrect type");if(r!==void 0&&!Zt(r))throw new U("JWE Per-Recipient Unprotected Header incorrect type");if(t.protected===void 0&&r===void 0&&t.unprotected===void 0)throw new U("JOSE Header missing")}function JO(t){let{protected:e,ciphertext:r,iv:o,tag:n,aad:i}=t,s;return e!==void 0&&(s=up(e,U,"JWE Protected Header is invalid")),[s,Rn(r,"ciphertext",U),o!==void 0?Rn(o,"iv",U):void 0,n!==void 0?Rn(n,"tag",U):void 0,Sx((e??"")+(i!==void 0?`.${i}`:""),"aad",U)]}function Lx(t){return[t&&lg("keyManagementAlgorithms",t.keyManagementAlgorithms),t&&lg("contentEncryptionAlgorithms",t.contentEncryptionAlgorithms),t?.crit,t?.maxPBES2Count,t?.maxDecompressedLength]}async function GO(t,e,r,o=JO(t)){let[n,i,s,a,c]=o,{header:u,unprotected:l,aad:d}=t,f;if(u!==void 0||l!==void 0){if(!nc(n,u,l))throw new U("JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint");f={...n,...u,...l}}else f=n??{};let[p,m,g,y,w]=e,{encrypted_key:b}=t;oc(U,Ex,g,n,f),Ux(f,n);let{alg:_,enc:k}=f;if(typeof _!="string"||!_)throw new U("missing JWE Algorithm (alg) in JWE Header");let $=sa[_];if(b===""&&(!$||!ai($)))throw new U("JWE Encrypted Key incorrect type");let D=$?.mode==="integrated-encryption";if(!D&&(typeof k!="string"||!k))throw new U("missing JWE Encryption Algorithm (enc) in JWE Header");if(p&&!p.has(_)||!p&&_.startsWith("PBES2"))throw new Xu('"alg" (Algorithm) Header Parameter value not allowed');let K;if(D){if(k!==void 0)throw new U('JWE "enc" (Encryption Algorithm) Header Parameter must not be present for integrated encryption');if(s?.byteLength)throw new U("JWE Initialization Vector must be empty for integrated encryption");if(a?.byteLength)throw new U("JWE Authentication Tag must be empty for integrated encryption")}else{if(m&&!m.has(k))throw new Xu('"enc" (Encryption Algorithm) Header Parameter value not allowed');K=tl(k)}let te;if(b!==void 0)try{te=Rn(b,"encrypted_key",U)}catch($e){if(!$||!ai($))throw $e;te=new Uint8Array}let Ie=!1;typeof r=="function"&&(r=await r(n,t),Ie=!0);let xe=$??si(_);ai(xe)&&te===void 0&&(te=new Uint8Array);let Qe=await oi(xe.mode==="direct-encryption"?K:xe,r,"decrypt"),Ve;if(xe.mode==="integrated-encryption")Ve=await xe.decrypt(Qe,te,i,c,n,f);else{let $e=K,J;try{J=await WB(xe,$e,Qe,te,f,y),ai(xe)&&J instanceof Uint8Array&&J.byteLength<<3!==$e.cekBits&&(J=el($e))}catch(Tt){if(Tt instanceof TypeError||Tt instanceof U||Tt instanceof ct)throw Tt;J=el($e)}Ve=await Ox($e,J,i,s,a,c)}if(f.zip==="DEF"){let $e=w??25e4;if($e===0)throw new ct('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');if($e!==1/0&&(!Number.isSafeInteger($e)||$e<1))throw new TypeError("maxDecompressedLength must be 0, a positive safe integer, or Infinity");Ve=await YB(Ve,$e).catch(J=>{throw J instanceof U?J:new U("Failed to decompress plaintext",{cause:J})})}return{plaintext:Ve,...n&&{protectedHeader:n},...d!==void 0&&{additionalAuthenticatedData:Rn(d,"aad",U)},...l&&{sharedUnprotectedHeader:l},...u&&{unprotectedHeader:u},...Ie&&{key:Qe}}}async function rK(t,e,r){if(t instanceof Uint8Array&&(t=cp.decode(t)),typeof t!="string")throw new U("Compact JWE must be a string or Uint8Array");let{0:o,1:n,2:i,3:s,4:a,length:c}=t.split(".");if(c!==5)throw new U("Invalid Compact JWE");return GO({ciphertext:s,iv:i||void 0,protected:o,tag:a||void 0,encrypted_key:n||void 0},e,r)}async function pg(t,e,r){return rK(t,Lx(r),e)}async function XO(t,e,r){if(!Zt(t))throw new U("General JWE must be an object");let o=t.recipients;if(!Array.isArray(o))throw new U("JWE Recipients missing or incorrect type");let n=Array.from(o);if(!n.every(Zt))throw new U("JWE Recipients missing or incorrect type");if(!n.length)throw new U("JWE Recipients has no members");let i,s,a;try{i=Lx(r),s=QB(t),a=JO(s)}catch{throw new rc}let c=n.map(u=>eK(u));if(n.length>1)for(let[,u]of c){let l=a[0]?.alg??u??s.unprotected?.alg,d=typeof l=="string"?sa[l]:void 0;if(d&&!ai(d))throw new U(`"${l}" alg may only have a single recipient`)}for(let[u]of c)if(u)try{let l={...s,...u};return tK(l),await GO(l,i,e,a)}catch{}throw new rc}function Fx(t,e,r){if(!nc(t,e,r))throw new U("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint")}function YO(t,e,r=!1){if(!t[1]&&!t[2]&&!t[3])throw new U("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");e!==void 0&&(t[8]=e?.crit);let[,o,n,i,s,a,c,u,l]=t;if(s!==void 0&&Gn(s,"JWE Additional Authenticated Data"),a!==void 0&&Gn(a,"JWE Content Encryption Key"),c!==void 0&&Gn(c,"JWE Initialization Vector"),!r&&o!==void 0&&(o=Qu(U,o)[0],t[1]=o),n!==void 0&&(n=Qu(U,n)[0],t[2]=n),!r&&i!==void 0&&(i=Qu(U,i)[0],t[3]=i),u!==void 0&&!Zt(u))throw new TypeError("JWE Key Management Parameters must be an object");Fx(o,n,i);let d={...o,...n,...i};kx(U,o),oc(U,Ex,l,o,d),Ux(d,o);let{alg:f,enc:p}=d;if(typeof f!="string"||!f)throw new U('JWE "alg" (Algorithm) Header Parameter missing or invalid');let m=sa[f];if(m?.mode==="integrated-encryption"){if(p!==void 0)throw new U('JWE "enc" (Encryption Algorithm) Header Parameter must not be present for integrated encryption');if(a!==void 0)throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${f}`);if(c!==void 0)throw new TypeError(`setInitializationVector cannot be called with JWE "alg" (Algorithm) Header ${f}`);return[d,void 0,m]}if(typeof p!="string"||!p)throw new U('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');return[d,tl(p),m]}async function QO(t,e,r){let[o,n,i]=e,[s,a,c,u,l,d,f,p,,m]=t,g=a,y=c,w=i??si(o.alg),b,_,k;w.mode==="integrated-encryption"?k=await oi(w,r,"encrypt"):[k,b,_]=await Mx(w,n,r,o,d,p),_&&(m?y=y?{...y,..._}:_:g=g?{...g,..._}:_,Fx(g,y,u));let $=g?Rt(JSON.stringify(g)):"",D=l?.byteLength?Rt(l):void 0,K=kr(D?`${$}.${D}`:$),te=s;o.zip==="DEF"&&(te=await XB(te).catch($e=>{throw new U("Failed to compress plaintext",{cause:$e})}));let Ie,xe,Qe;w.mode==="integrated-encryption"?[b,Ie]=await w.encrypt(k,te,K,g,o,p):{ciphertext:Ie,tag:xe,iv:Qe}=await Cx(n,te,k,f,K);let Ve={ciphertext:Rt(Ie)};return Qe&&(Ve.iv=Rt(Qe)),xe&&(Ve.tag=Rt(xe)),b?.byteLength&&(Ve.encrypted_key=Rt(b)),D&&(Ve.aad=D),g&&(Ve.protected=$),u&&(Ve.unprotected=u),y&&(Ve.header=y),Ve}async function nK(t,e,r){return QO(t,YO(t,r),e)}function oK(t){return[t.protected,t.encrypted_key,t.iv,t.ciphertext,t.tag].join(".")}var eN=class{#e;state;constructor(e,r,o){this.#e=e,this.state=[void 0,void 0,r,o]}setUnprotectedHeader(e){return wo(this.state[0],"setUnprotectedHeader"),this.state[0]=e,this}setKeyManagementParameters(e){return wo(this.state[1],"setKeyManagementParameters"),this.state[1]=e,this}addRecipient(...e){return this.#e.addRecipient(...e)}encrypt(...e){return this.#e.encrypt(...e)}done(){return this.#e}},fg=class{#e;#t=[];#r;#n;#o;constructor(e){this.#e=e}addRecipient(e,r){let o=new eN(this,e,r?.crit);return this.#t.push(o),o}setProtectedHeader(e){return wo(this.#r,"setProtectedHeader"),this.#r=e,this}setSharedUnprotectedHeader(e){return wo(this.#n,"setSharedUnprotectedHeader"),this.#n=e,this}setAdditionalAuthenticatedData(e){return this.#o=e,this}async encrypt(){if(!this.#t.length)throw new U("at least one recipient must be added");Gn(this.#e,"plaintext");let e=this.#t.length>1,r,o=this.#r,n=this.#n,i=[];for(let m of this.#t){let[g,y,w,b]=m.state,_=[this.#e,o,g,n,this.#o,void 0,void 0,y,b,e],k=YO(_,void 0,i.length>0);i.length||(o=_[1],n=_[3]),i.push([_,k,w]);let[{alg:$,enc:D},,K]=k;if(e&&K&&!ai(K))throw new U(`"${$}" alg may only have a single recipient`);if(!r)r=D;else if(r!==D)throw new U('JWE "enc" (Encryption Algorithm) Header Parameter must be the same for all recipients')}for(let[,m]of i)m[2]??=si(m[0].alg);let[s,a,c]=i[0],u=e?el(a[1]):void 0;s[5]=u;let{encrypted_key:l,header:d,...f}=await QO(s,a,c),p={...f,recipients:[{}]};l&&(p.recipients[0].encrypted_key=l),d&&(p.recipients[0].header=d);for(let m=1;m<i.length;m++){let[g,[y,w,b],_]=i[m],k=g[2],[,$,D]=await Mx(b,w,_,y,u,g[7]),K={encrypted_key:Rt($)};if(k||D){let te={...k,...D};D&&Fx(g[1],te,g[3]),K.header=te}p.recipients.push(K)}return p}};var mg=[["verify"],["sign"]];function tN(t){let e={name:"HMAC",hash:`SHA-${t}`};return{kty:["oct"],secret:!0,subtle:e,signing:e,usages:mg}}function mp(t,e){let r={name:e?"RSA-PSS":"RSASSA-PKCS1-v1_5",hash:`SHA-${t}`};return{kty:["RSA"],subtle:r,signing:e?{...r,saltLength:e}:r,usages:mg,minRsaBits:2048}}function rN(t,e){return{kty:["EC"],crv:t,subtle:{name:"ECDSA",namedCurve:t},signing:{name:"ECDSA",hash:`SHA-${e}`},usages:mg}}function iK(){let t={name:"Ed25519"};return{kty:["OKP"],crv:"Ed25519",subtle:t,signing:t,usages:mg}}function nN(t){let e={name:`ML-DSA-${t}`};return{kty:["AKP"],subtle:e,signing:e,usages:mg}}var oN=dg({HS256:tN(256),HS384:tN(384),HS512:tN(512),RS256:mp(256),RS384:mp(384),RS512:mp(512),PS256:mp(256,32),PS384:mp(384,48),PS512:mp(512,64),ES256:rN("P-256",256),ES384:rN("P-384",384),ES512:rN("P-521",512),EdDSA:iK(),Ed25519:iK(),"ML-DSA-44":nN(44),"ML-DSA-65":nN(65),"ML-DSA-87":nN(87)});function Vx(t){let e=typeof t=="string"?oN[t]:void 0;if(!e)throw new ct(`alg ${t} is not supported either by JOSE or your javascript runtime`);return e}function sK(t){return[t&&lg("algorithms",t.algorithms),t?.crit]}function Ehe(t){return t===void 0?{}:up(t,kt,"JWS Protected Header is invalid")}function khe(t){try{return kr(t)}catch{throw new kt("JWS Compact Serialization payload must use only ASCII characters")}}async function Ihe(t,e,r,o,n){let{protected:i,header:s,payload:a}=t,c=n??Ehe(i);if(!nc(c,s))throw new kt("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");let u={...c,...s},l=Ix(c,oc(kt,xx,e[1],c,u)),{alg:d}=u;if(typeof d!="string"||!d)throw new kt('JWS "alg" (Algorithm) Header Parameter missing or invalid');if(e[0]&&!e[0].has(d))throw new Xu('"alg" (Algorithm) Header Parameter value not allowed');if(l){if(typeof a!="string")throw new kt("JWS Payload must be a string")}else if(typeof a!="string"&&!(a instanceof Uint8Array))throw new kt("JWS Payload must be a string or an Uint8Array instance");let f=l||typeof a!="string"?a:o(a),p=!1;typeof r=="function"&&(r=await r(c,t),p=!0);let m=Vx(d),g=fn(i!==void 0?kr(i):new Uint8Array,kr("."),typeof f=="string"?e[2]??=Sx(f,"payload",kt):f),y=Rn(t.signature,"signature",kt),w=await oi(m,r,"verify"),b=await ii(w,m.subtle,"verify");m.minRsaBits&&lp(m.alg,b);let _=!1;try{_=await crypto.subtle.verify(m.signing,b,y,g)}catch{}if(!_)throw new _x;let k={payload:typeof f=="string"?Rn(f,"payload",kt):f};return i!==void 0&&(k.protectedHeader=c),s!==void 0&&(k.unprotectedHeader=s),p?[{...k,key:w},l]:[k,l]}async function aK(t,e,r){if(t instanceof Uint8Array&&(t=cp.decode(t)),typeof t!="string")throw new kt("Compact JWS must be a string or Uint8Array");let{0:o,1:n,2:i,length:s}=t.split(".");if(s!==3)throw new kt("Invalid Compact JWS");return Ihe({payload:n,protected:o,signature:i},e,r,khe)}async function iN(t,e,r){let[o]=await aK(t,sK(r),e);return o}var hp=class{#e;constructor(e){Gn(e,"plaintext"),this.#e=[e]}setContentEncryptionKey(e){return wo(this.#e[5],"setContentEncryptionKey"),this.#e[5]=e,this}setInitializationVector(e){return wo(this.#e[6],"setInitializationVector"),this.#e[6]=e,this}setProtectedHeader(e){return wo(this.#e[1],"setProtectedHeader"),this.#e[1]=e,this}setKeyManagementParameters(e){return wo(this.#e[7],"setKeyManagementParameters"),this.#e[7]=e,this}async encrypt(e,r){return oK(await nK([...this.#e],e,r))}};async function $he(t,e,r){let[o,n,i,s]=t,a="";if(n!==void 0){let w=Qu(kt,n);n=w[0],a=Rt(w[1])}if(i!==void 0&&(i=Qu(kt,i)[0]),!n&&!i)throw new kt("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");if(!nc(n,i))throw new kt("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");let c={...n,...i};kx(kt,n);let u=Ix(n,oc(kt,xx,s,n,c));u||r?.();let{alg:l}=c;if(typeof l!="string"||!l)throw new kt('JWS "alg" (Algorithm) Header Parameter missing or invalid');let d=Vx(l),f="",p=o,m;if(u){let w=t[4];w?(f=w[0]??=Rt(o),p=w[1]??=kr(f)):(f=Rt(o),m=ap.encode(`${a}.${f}`))}m??=fn(kr(a),kr("."),p);let g=await ii(await oi(d,e,"sign"),d.subtle,"sign");d.minRsaBits&&lp(d.alg,g);let y={signature:Rt(new Uint8Array(await crypto.subtle.sign(d.signing,g,m))),payload:f};return n&&(y.protected=a),i&&(y.header=i),[y,u]}async function cK(t,e,r,o,n){let[i]=await $he([t,e,void 0,r],o,n);return`${i.protected}.${i.payload}.${i.signature}`}var hg=class{#e;#t;constructor(e){Gn(e,"payload"),this.#e=e}setProtectedHeader(e){return wo(this.#t,"setProtectedHeader"),this.#t=e,this}async sign(e,r){return cK(this.#e,this.#t,r?.crit,e,()=>{throw new TypeError("use the flattened module for creating JWS with b64: false")})}};var sN='"alg" (Algorithm)';function aN(t='JWK "alg" (Algorithm) Parameter'){throw new ct(`Invalid or unsupported ${t} value`)}function gg(t,e){return(typeof t=="string"?oN[t]??sa[t]:void 0)??aN(e)}async function sc(t){if(VO(t))if(t.type==="secret")t=t.export();else return t.export({format:"jwk"});if(t instanceof Uint8Array)return{kty:"oct",k:Rt(t)};if(!ic(t))throw new TypeError(ia(t,"CryptoKey","KeyObject","Uint8Array"));if(!t.extractable)throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");let e=await crypto.subtle.exportKey("jwk",t);delete e.ext,delete e.key_ops,delete e.use,e.kty!=="AKP"&&delete e.alg;for(let r of Object.keys(e))e[r]===void 0&&delete e[r];return e}var aa=(t,e)=>{if(typeof t!="string"||!t)throw new ug(`${e} missing or invalid`)};async function cN(t,e){let r;if(Zt(t)){if(r=Tx(t),typeof r.kty!="string")throw new TypeError(ia(t,"CryptoKey","KeyObject","JSON Web Key"))}else if(HO(t))r=Tx(await sc(t));else throw new TypeError(ia(t,"CryptoKey","KeyObject","JSON Web Key"));if(e??="sha256",e!=="sha256"&&e!=="sha384"&&e!=="sha512")throw new TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');let o;switch(r.kty){case"AKP":aa(r.alg,'"alg" (Algorithm) Parameter'),aa(r.pub,'"pub" (Public key) Parameter'),o={alg:r.alg,kty:r.kty,pub:r.pub};break;case"EC":aa(r.crv,'"crv" (Curve) Parameter'),aa(r.x,'"x" (X Coordinate) Parameter'),aa(r.y,'"y" (Y Coordinate) Parameter'),o={crv:r.crv,kty:r.kty,x:r.x,y:r.y};break;case"OKP":aa(r.crv,'"crv" (Subtype of Key Pair) Parameter'),aa(r.x,'"x" (Public Key) Parameter'),o={crv:r.crv,kty:r.kty,x:r.x};break;case"RSA":aa(r.e,'"e" (Exponent) Parameter'),aa(r.n,'"n" (Modulus) Parameter'),o={e:r.e,kty:r.kty,n:r.n};break;case"oct":if(typeof r.k!="string")throw new ug('"k" (Key Value) Parameter missing or invalid');o={k:r.k,kty:r.kty};break;default:throw new ct('"kty" (Key Type) Parameter missing or unsupported')}let n=kr(JSON.stringify(o));return Rt(await bx(e,n))}async function bo(t,e,r){if(!Zt(t))throw new TypeError("JWK must be an object");let o=qO(t),n=Px(r?.extractable),{alg:i}=o;if(e??=i,o.kty!=="oct"&&!e)throw new TypeError('"alg" argument is required when "jwk.alg" is not present');switch(o.kty){case"oct":if(typeof o.k!="string")throw new TypeError('missing "k" (Key Value) Parameter value');return Yu(o.k);case"AKP":{if(typeof i!="string"||!i)throw new TypeError('missing "alg" (Algorithm) Parameter value');if(e!==i)throw new TypeError("JWK alg and alg option value mismatch");return dp(gg(e),o,n)}case"RSA":case"EC":case"OKP":return dp(gg(e),o,n);default:throw new ct('Unsupported "kty" (Key Type) Parameter value')}}function uN(t){let e;if(typeof t=="string"){let o=t.split(".");(o.length===3||o.length===5)&&([e]=o)}else if(typeof t=="object"&&t)if("protected"in t)e=t.protected;else throw new TypeError("Token does not contain a Protected Header");let r="Invalid Token or Protected Header formatting";if(typeof e!="string"||!e)throw new TypeError(r);return up(e,TypeError,r)}function Ahe(t){let e=t?.modulusLength??2048;if(typeof e!="number"||!Number.isInteger(e)||e<2048)throw new ct("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");return e}async function yg(t,e){let r=Px(e?.extractable),o=gg(t,sN);o.secret&&aN(sN);let n;if(o.resolve){let i=e?.crv??"P-256";if(!["P-256","P-384","P-521","X25519"].includes(i))throw new ct("Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, and X25519");n=o.resolve({crv:i})}else{if(o.crv!==void 0&&e?.crv!==void 0&&e.crv!==o.crv)throw new ct(`Invalid or unsupported crv option provided, the only supported value for ${t} is ${o.crv}`);n=o.kty[0]==="RSA"?{...o.subtle,publicExponent:Uint8Array.of(1,0,1),modulusLength:Ahe(e)}:o.subtle}return crypto.subtle.generateKey(n,r??!1,[...o.usages[1],...o.usages[0]])}var pK=h.string().regex(/^[a-z]{2}(?:-gov)?-[a-z]+-\d$/),fK=h.string().max(2e3).regex(/^arn:aws(?:-us-gov|-cn)?:iam::\d{12}:role\/.+/),uK=h.string().min(1).max(128),lK=h.string().min(1).max(16384),The=h.discriminatedUnion("kind",[h.object({kind:h.literal("access_key"),accessKeyId:uK,secretAccessKey:lK}).strict(),h.object({kind:h.literal("session"),accessKeyId:uK,secretAccessKey:lK,sessionToken:h.string().min(1).max(16384),expiresAt:h.number().int().positive().max(Number.MAX_SAFE_INTEGER)}).strict(),h.object({kind:h.literal("environment")}).strict()]),Phe=h.object({arn:fK,externalId:h.string().min(2).max(1224).regex(/^[\w+=,.@:\/-]+$/).optional()}).strict(),ca=h.object({authentication:The,region:pK,role:Phe.optional()}).strict(),Hx=h.object({accountId:h.string().regex(/^\d{12}$/),principalId:h.string().min(1).max(256),arn:h.string().max(2e3).regex(/^arn:aws(?:-us-gov|-cn)?:(?:iam|sts)::\d{12}:.+/)}).strict(),Bx=ca.extend({sourceIdentity:Hx.optional(),identity:Hx.optional()}).strict();function gp(t){return t.includes(":assumed-role/")?t.slice(0,t.lastIndexOf("/")):t}function dK(t){return{...t,arn:gp(t.arn)}}function mK(t){return{authentication:t.authentication.kind,region:t.region,role:t.role??null,...t.sourceIdentity?{sourceIdentity:dK(t.sourceIdentity)}:{},...t.identity?{identity:dK(t.identity)}:{}}}var Kx=h.object({authentication:h.enum(["access_key","session","environment"]),region:pK,sourceAccountId:h.string().regex(/^\d{12}$/).optional(),sourceArn:h.string().max(2e3).optional(),roleArn:fK.optional(),expiresAt:h.number().int().positive().optional()}).strict();function hK(t){return{authentication:t.authentication.kind,region:t.region,...t.sourceIdentity?{sourceAccountId:t.sourceIdentity.accountId,sourceArn:t.sourceIdentity.arn}:{},...t.role?{roleArn:t.role.arn}:{},...t.authentication.kind==="session"?{expiresAt:t.authentication.expiresAt}:{}}}var gK=h.object({method:h.enum(["GET","POST","PUT","DELETE","PATCH"]),path:h.string().min(1).max(1e3).regex(/^\/[^\s\u0000]*$/)}).strict(),vg=h.object({account:h.string().min(1),identities:h.array(h.string()),user:h.string().nullable(),description:h.string().nullable(),roles:h.array(h.string()).nullable(),credentialId:h.number().int().positive(),rules:h.array(gK),allowedIPs:h.array(h.string()).nullable(),expiresAt:h.number().nullable()}).strict();function yK(t){return t.map(e=>{let r=e.match(/^(GET|POST|PUT|DELETE|PATCH) (\/[^\s\u0000]*)$/);if(!r)throw new Error("Use one HTTP method and API path for each OVH permission.");return gK.parse({method:r[1],path:r[2]})})}typeof window<"u"&&h.config({jitless:!0});var E=h.uuid(),me=h.string().trim().min(1).max(200).regex(/^[^\u0000-\u001f\u007f]+$/u),Ne=h.iso.datetime(),Xn=h.json(),tr=h.record(h.string(),Xn),vK=h.enum(["ja","en"]),wK=h.enum(["read","create","update","delete","share","transfer","reveal","use","manage_credentials","manage_billing","export"]);var bK=h.enum(["variable","connection","service","method","app","object","keyring","ssh_key","ssh_host"]),mn=h.object({kty:h.literal("EC"),crv:h.literal("P-256"),x:h.string().min(40).max(50),y:h.string().min(40).max(50)}).strict(),Rhe=h.object({alg:h.literal("dir"),enc:h.literal("A256GCM"),sub:E}).strict(),_g=h.string().max(16384).regex(/^[A-Za-z0-9_-]+\.\.[A-Za-z0-9_-]{16}\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]{22}$/).refine(t=>{try{return Rhe.safeParse(uN(t)).success}catch{return!1}},"Use an A256GCM JWE for the wrapped encryption key.").brand(),dr=h.object({protected:h.string().max(2048),iv:h.string().max(64),ciphertext:h.string().max(2e6),tag:h.string().max(64),aad:h.string().max(2048).optional(),recipients:h.array(h.object({encrypted_key:h.string().max(2048),header:h.object({kid:E,epk:mn.optional(),alg:h.string().optional()}).passthrough()})).min(1).max(100)}).strict(),fHe=h.object({id:E,name:me,publicKey:mn}),nl=h.object({id:E,name:me,owner:h.object({id:E,name:me}).nullable(),createdAt:Ne,permissions:h.array(wK),createKinds:h.array(bK),publicKey:mn.nullable()}),_K=h.object({id:E,kind:h.enum(["passkey","email","key"]),name:h.string(),createdAt:Ne,lastUsedAt:Ne.nullable(),expiresAt:Ne.nullable(),canOpen:h.boolean()}),lN=h.string().regex(/^[a-z][a-z_]*[a-z]$/).max(64),Che=h.object({subjectId:E,relation:lN,objectId:E}).strict(),SK=h.enum(["principal",...bK.options]),xK=Che.extend({objectType:SK,subjectName:me,objectName:me,createdAt:Ne}),mHe=h.object({error:h.object({code:h.string(),message:h.string(),details:Xn.optional()})}),hHe=h.object({ok:h.literal(!0)}),Ohe=h.object({value:h.string().min(1).max(200),label:h.string().min(1).max(200),values:h.record(h.string().regex(/^[a-zA-Z][a-zA-Z0-9_]*$/),h.string()).default({})}).strict(),Wx=h.object({name:h.string().regex(/^[a-zA-Z][a-zA-Z0-9_]*$/),label:h.string(),secret:h.boolean().optional(),inputType:h.enum(["text","password","file"]).optional(),required:h.boolean().optional(),placeholder:h.string().optional(),note:h.string().optional(),pattern:h.string().optional(),choices:h.array(Ohe).min(1).max(100).optional(),defaultValue:h.string().max(1e3).optional(),when:h.object({field:h.string(),values:h.array(h.string()).min(1)}).strict().optional(),visibility:h.enum(["application","connection"]).optional()}).superRefine((t,e)=>{let r=t.choices??[];new Set(r.map(o=>o.value)).size!==r.length&&e.addIssue({code:"custom",path:["choices"],message:"Use a unique value for each choice."})}),dN=h.record(h.string().regex(/^[A-Z_][A-Z0-9_]*$/),h.string()),Nhe=h.record(h.string().regex(/^[A-Z_][A-Z0-9_]*$/),h.union([h.string(),h.array(h.union([h.string().max(8192),h.object({pointer:h.string().max(1e3)}).strict()])).min(1).max(32)])),pN=h.object({values:h.array(h.object({id:h.string(),name:h.string(),description:h.string().optional()})).optional(),default:h.array(h.string()).default([]),required:h.array(h.string()).optional(),separator:h.string().default(" "),docs:h.url().optional()}),rl=h.string().min(1).max(4096),Zx=h.union([h.string(),h.array(h.string()).min(1)]),Cn="urn:ietf:params:oauth:grant-type:device_code",Dhe=h.object({browserTokenExchange:h.enum(["available","unavailable","unknown"]).optional(),application:h.enum(["required","implicit"]).default("required"),grantType:h.enum(["authorization_code","client_credentials",Cn]).optional(),issuer:h.url().optional(),registrationUrl:h.url().optional(),authorizeUrl:rl.optional(),deviceAuthorizationUrl:rl.optional(),tokenUrl:rl,identity:h.object({url:rl.optional(),from:h.enum(["token","app"]).optional(),method:h.enum(["GET","POST"]).default("GET"),id:Zx.default("/id"),name:Zx.default("/name"),headers:h.record(h.string(),h.string()).default({})}).optional(),clientAuth:h.enum(["body","basic","none"]).default("body"),pkce:h.boolean().default(!0),tokenFormat:h.enum(["form","json"]).default("form"),okPointer:h.string().optional(),authorizeParams:h.record(h.string(),h.string()).default({}),tokenParams:h.record(h.string(),h.string()).default({}),defaults:h.record(h.string(),h.string()).default({}),scopes:pN.default({default:[],separator:" "}),fields:h.array(Wx).default([]),outputs:dN.default({ACCESS_TOKEN:"/accessToken"}),adapter:h.string().regex(/^[a-z][a-z0-9_-]{0,99}$/).optional(),keep:h.array(h.string()).default([]),hint:h.string().optional()}).refine(t=>t.grantType==="client_credentials"||t.grantType===Cn||!!t.authorizeUrl,{path:["authorizeUrl"],message:"An authorization code flow requires an authorization URL."}).refine(t=>t.grantType!==Cn||!!t.deviceAuthorizationUrl,{path:["deviceAuthorizationUrl"],message:"A device flow requires a device authorization URL."}),zhe=h.object({fields:h.array(Wx).min(1),outputs:Nhe,resolver:h.literal("vultr-role").optional(),bindFields:h.boolean().optional(),constants:h.record(h.string().regex(/^[a-zA-Z][a-zA-Z0-9_]*$/),h.string()).optional(),files:h.array(h.string().regex(/^[A-Z_][A-Z0-9_]*$/)).max(32).optional(),account:h.object({field:h.string().regex(/^[a-zA-Z][a-zA-Z0-9_]*$/),pointer:h.string().max(1e3)}).strict().optional(),identity:h.object({url:rl,headers:h.record(h.string(),h.string()),id:Zx,name:Zx}).strict().optional(),console:h.url().optional(),instructions:h.string().optional(),hint:h.string().optional()}).superRefine((t,e)=>{t.files?.some(r=>!Object.hasOwn(t.outputs,r))&&e.addIssue({code:"custom",path:["files"],message:"Deliver only declared outputs as files."}),t.account&&!t.fields.some(r=>r.name===t.account.field)&&e.addIssue({code:"custom",path:["account"],message:"Read the account from a declared field."})}),fN=h.enum(["oauth","token","aws","ovh","approval"]),jhe=h.object({hint:h.string().optional()}).strict(),Mhe=h.object({authorization:h.enum(["api_key","consumer_key"]),apiBaseUrl:rl,fields:h.array(Wx).min(1),scopes:pN.default({default:[],separator:`
129
129
  `}),outputs:dN,hint:h.string().optional()}).strict(),Sg={name:me,docs:h.url().optional(),console:rl.optional(),preparation:h.object({scopeSelection:h.enum(["optional","required","hidden"]).default("optional"),instructions:h.array(h.union([h.string().max(2e3),h.object({ja:h.string().max(2e3),en:h.string().max(2e3)}).strict()])).max(10).default([]),docs:h.boolean().default(!1)}).strict().optional()},Jx=h.object({...Sg,kind:h.literal("oauth"),config:Dhe}).strict(),Gx=h.object({...Sg,kind:h.literal("token"),config:zhe}).strict(),Xx=h.object({...Sg,kind:h.literal("aws"),config:jhe}).strict(),Yx=h.object({...Sg,kind:h.literal("ovh"),config:Mhe}).strict(),Qx=h.object({...Sg,kind:h.literal("approval"),config:h.object({adapter:h.literal("runpod-flash"),fields:h.array(Wx).default([]),scopes:pN.default({default:[],separator:" "}),outputs:dN,hint:h.string().optional()}).strict()}).strict(),ac=h.discriminatedUnion("kind",[Jx,Gx,Xx,Yx,Qx]),wg={id:h.string().min(1),builtin:h.boolean(),availability:h.enum(["ready","app-required","unavailable"]),defaultName:me,registration:h.object({kind:h.enum(["input","authorization"]),device:h.enum(["browser","cli"]),browserExchange:h.enum(["available","unavailable","unknown"]),tokenAlternatives:h.array(h.string())}).strict()},_o=h.discriminatedUnion("kind",[Jx.extend(wg),Gx.extend(wg),Xx.extend(wg),Yx.extend(wg),Qx.extend(wg)]),bg=h.string().regex(/^[a-z][a-z0-9_-]{0,79}$/),mN=h.object({name:me,logo:h.string().regex(/^[a-z0-9-]+$/).optional(),api:h.url().optional(),docs:h.url().optional(),console:h.url().optional(),targets:h.array(h.object({id:bg,name:me,api:h.url().optional(),methods:h.array(bg).min(1)}).strict()).max(32).optional()}).strict(),Uhe=mN.extend({methods:h.record(bg,h.string().min(1))}).strict(),EK=mN.extend({methods:h.record(bg,h.union([h.string().min(1),ac]))}).strict(),kK=mN.extend({id:h.string(),builtin:h.boolean(),methods:h.record(bg,_o)}),Lhe=h.object({id:E,output:h.string().min(1).max(100).optional()}).strict(),IK=t=>/^[A-Za-z_][A-Za-z0-9_]*$/.test(t)&&!/^(FOUNDATION_|LD_|DYLD_)|^(NODE_OPTIONS|BASH_ENV|ENV|PYTHONSTARTUP|GIT_CONFIG_COUNT|GIT_CONFIG_SYSTEM)$/u.test(t),$K=h.object({name:h.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/),source:Lhe,format:h.enum(["text","file","json"]).optional(),pointer:h.string().optional()}).strict(),ua={id:E,ownerId:E,name:me,createdAt:Ne,updatedAt:Ne,version:h.number().int().positive(),permissions:h.array(wK)},hN={recipients:h.array(E).default([]),custodyRevision:h.number().int().positive().nullable().default(null)},Fhe=h.object({...ua,kind:h.literal("variable"),data:h.object({...hN,bytes:h.number().int().nonnegative()})}),Vhe=h.object({...ua,kind:h.literal("connection"),data:h.object({...hN,methodId:h.string(),fields:h.record(h.string(),h.string()).default({}),settings:h.array(h.object({name:h.string(),label:h.string(),value:h.string()})).default([]),methodName:h.string(),methodKind:fN,services:h.array(h.object({id:h.string(),name:me})).default([]),account:h.string(),accountId:h.string().nullable().default(null),accountVerified:h.boolean().default(!1),scopes:h.array(h.string()),scopesStatus:h.enum(["unknown","requested","reported"]).default("unknown"),outputs:h.array(h.string()),state:h.enum(["ready","reconnect","review","disconnecting","uncertain"]),appId:E.nullable(),generation:E.optional(),authorizationDigest:h.string().optional(),aws:Kx.optional(),ovh:vg.optional()})}),Hhe=h.object({...ua,kind:h.literal("service"),data:Uhe}),Bhe=h.object({...ua,kind:h.literal("method"),data:ac}),Khe=h.object({...ua,kind:h.literal("app"),data:h.object({...hN,methodId:h.string(),clientId:h.string(),fields:h.record(h.string(),h.string()).default({}),generation:E.optional()})}),qhe=h.object({...ua,kind:h.literal("object"),data:h.object({size:h.number().int().nonnegative(),contentType:h.string()})}),Zhe=h.object({...ua,kind:h.literal("keyring"),data:h.object({revision:h.number().int().positive(),signature:h.string()})}),Whe=h.object({publicKey:cg,algorithm:h.string(),fingerprint:yx,purpose:h.string().max(500),privateKeyId:E.nullable(),revokedAt:Ne.nullable()}),Jhe=h.object({...ua,kind:h.literal("ssh_key"),data:Whe}),Ghe=h.object({address:hx,port:h.number().int().min(1).max(65535),hostKeys:h.array(cg).min(1).max(16),authorizedKeysFile:gx}),Xhe=h.object({...ua,kind:h.literal("ssh_host"),data:Ghe}),pt=h.discriminatedUnion("kind",[Fhe,Vhe,Hhe,Bhe,Khe,qhe,Zhe,Jhe,Xhe]),gHe=h.discriminatedUnion("kind",[h.object({kind:h.literal("service"),name:me,definition:EK}).strict(),h.object({kind:h.literal("method"),name:me,definition:ac}).strict()]),yHe=h.object({version:h.number().int().positive(),name:me.optional(),definition:h.union([EK,ac]).optional()}).strict(),So=h.object({name:h.string().regex(/^[a-z][a-z0-9]*(?:\.[a-z][a-z0-9]*)+$/),input:tr}).strict(),gN=So.extend({inputs:h.array(h.object({pointer:h.string(),label:h.string().min(1).max(100),secret:h.boolean().default(!1),multiline:h.boolean().default(!1),site:h.url().optional()}).strict()).max(16).default([])}),e0=h.object({ja:h.string(),en:h.string()}).strict(),qx=h.object({id:E,name:me}),AK=h.discriminatedUnion("kind",[h.object({kind:h.literal("line"),subject:qx,relation:lN,object:qx}),h.object({kind:h.literal("transfer"),item:qx,to:qx})]),vHe=h.object({id:E,name:me,publicKey:mn,state:h.enum(["pending","approving","approved"]),principalId:E.nullable(),createdAt:Ne,expiresAt:Ne}),wHe=h.object({available:h.boolean(),required:h.boolean(),active:h.boolean(),payer:nl.pick({id:!0,name:!0}).nullable()}),bHe=h.object({storageBytes:h.number().nonnegative(),storageLimit:h.number().positive(),month:h.string()}),_He=h.object({id:h.string(),actorId:E.nullable(),action:h.string(),targetId:E.nullable(),createdAt:Ne,details:tr}),SHe=h.object({returnUrl:h.url().optional(),refreshUrl:h.url().optional()}).strict(),rr=t=>h.object({items:h.array(t),next:h.string().nullable().default(null)}),xHe=h.object({id:E}),EHe=h.object({owner:E}),Yhe=h.object({limit:h.coerce.number().int().min(1).max(200).default(100),after:h.string().optional()}),kHe=Yhe.extend({object:E.optional(),subject:E.optional(),relation:lN.optional(),objectType:SK.optional()}).refine(t=>!!t.object!=!!t.subject,"Choose the object or the subject of the lines.");var Qhe=new TextEncoder,ege=new TextDecoder,xg="ECDH-ES+A256KW",yN="A256GCM",yt=t=>Qhe.encode(t),jt=t=>ege.decode(t);function la(t){let e="";for(let r=0;r<t.length;r+=8192)e+=String.fromCharCode(...t.subarray(r,r+8192));return btoa(e).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"")}function t0(t){return Uint8Array.from(atob(t.replaceAll("-","+").replaceAll("_","/")),e=>e.charCodeAt(0))}async function r0(){let t=await yg(xg,{crv:"P-256",extractable:!0});return{publicKey:mn.parse(await sc(t.publicKey)),privateKey:await sc(t.privateKey)}}async function ol(t,e,r){if(!e.length||new Set(e.map(n=>n.id)).size!==e.length)throw new Error("Recipients must be distinct and nonempty.");let o=new fg(t).setProtectedHeader({enc:yN}).setAdditionalAuthenticatedData(yt(r));for(let n of e)o.addRecipient(await bo(n.publicKey,xg)).setUnprotectedHeader({alg:xg,kid:n.id});return dr.parse(await o.encrypt())}async function On(t,e,r,o){if(t.aad!==la(yt(o)))throw new Error("The encrypted content belongs to a different item.");let n=t.recipients.find(a=>a.header.kid===r);if(!n)throw new Error("This principal cannot decrypt the content.");let i=e instanceof CryptoKey?e:await bo(e,xg);return(await XO({...t,recipients:[n]},i,{keyManagementAlgorithms:[xg],contentEncryptionAlgorithms:[yN]})).plaintext}async function tge(t){let e=await crypto.subtle.importKey("raw",new Uint8Array(t),"HKDF",!1,["deriveBits"]);return new Uint8Array(await crypto.subtle.deriveBits({name:"HKDF",hash:"SHA-256",salt:yt("Foundation"),info:yt("passkey encryption key")},e,256))}async function TK(t,e,r){let o=await pg(t,await tge(e),{keyManagementAlgorithms:["dir"],contentEncryptionAlgorithms:[yN]});if(o.protectedHeader.sub!==r)throw new Error("The key belongs to a different principal.");return JSON.parse(jt(o.plaintext))}var Br=h.string().regex(/^[A-Za-z0-9_-]{43}$/),Mt=h.string().min(100).max(4e6),PK=mn.extend({d:h.string().regex(/^[A-Za-z0-9_-]{43}$/)}),il=h.object({encryption:PK,signing:PK}).strict(),Kr=h.object({id:E,principalId:E,generation:h.number().int().positive(),previous:Br.nullable(),encryption:mn,signing:mn}).strict();function j(t){if(t===null||typeof t=="boolean"||typeof t=="number"&&Number.isFinite(t)||typeof t=="string"&&!/[\uD800-\uDFFF]/u.test(t))return JSON.stringify(t);if(Array.isArray(t))return"["+Array.from(t,j).join(",")+"]";if(t&&typeof t=="object"&&Object.getPrototypeOf(t)===Object.prototype)return"{"+Object.keys(t).sort().map(e=>{if(/[\uD800-\uDFFF]/u.test(e))throw new Error("Use Unicode property names.");return JSON.stringify(e)+":"+j(t[e])}).join(",")+"}";throw new Error("Use finite numbers, Unicode strings, arrays, and plain JSON objects.")}async function xo(t){return cN(mn.parse({kty:t.kty,crv:t.crv,x:t.x,y:t.y}),"sha256")}async function rt(t){return la(new Uint8Array(await crypto.subtle.digest("SHA-256",yt(j(t)))))}async function cc(t){let e=new Uint8Array(await crypto.subtle.digest("SHA-256",yt(j(t))));return"sha256:"+Array.from(e,r=>r.toString(16).padStart(2,"0")).join("")}async function n0(){let[t,e]=await Promise.all([r0(),yg("ES256",{crv:"P-256",extractable:!0})]),r=await sc(e.privateKey);return il.parse({encryption:t.privateKey,signing:r})}function yp(t){return mn.parse({kty:t.kty,crv:t.crv,x:t.x,y:t.y})}function o0(t,e){return Kr.parse({id:crypto.randomUUID(),principalId:t,generation:1,previous:null,encryption:yp(e.encryption),signing:yp(e.signing)})}async function or(t,e,r){let o=e instanceof CryptoKey?e:await bo(e,"ES256");return new hg(yt(j(t))).setProtectedHeader({alg:"ES256",typ:"foundation."+r+"+jws"}).sign(o)}async function Yn(t,e,r,o){if(j(await vN(e,r,o))!==j(t))throw new Error("The signature does not authorize this content.")}async function vN(t,e,r){let o=await iN(t,await bo(mn.parse(e),"ES256"),{algorithms:["ES256"]});if(o.protectedHeader.typ!=="foundation."+r+"+jws"||Object.keys(o.protectedHeader).some(s=>!["alg","typ"].includes(s)))throw new Error("The signature does not authorize this content.");let n=new TextDecoder("utf-8",{fatal:!0}).decode(o.payload),i=JSON.parse(n);if(j(i)!==n)throw new Error("Sign canonical JSON content.");return i}var nr=h.object({binding:Kr,signature:Mt}).strict(),i0=h.object({previous:nr,replacement:nr,previousSignature:Mt}).strict();async function Eg(t,e,r){let o=t;for(let n of[...r].sort((i,s)=>i.replacement.binding.generation-s.replacement.binding.generation)){if(j(n.previous.binding)!==j(o))continue;let i=n.replacement.binding;if(i.principalId!==o.principalId||i.id===o.id||i.generation!==o.generation+1||i.previous!==await rt(o))return!1;if(await vp(n.previous),await vp(n.replacement),await Yn(i,n.previousSignature,o.signing,"key-replacement"),o=i,j(o)===j(e))return!0}return!1}async function wp(t,e){if(await uc(t),await xo(e.encryption)!==await xo(t.encryption)||await xo(e.signing)!==await xo(t.signing))throw new Error("The private keys do not match this identity.");return{binding:t,signature:await or(t,e.signing,"key-binding")}}async function uc(t){let e=Kr.parse(t);if(e.generation===1!=(e.previous===null))throw new Error("Link each replacement key to its preceding binding.");if(await xo(e.encryption)===await xo(e.signing))throw new Error("Use separate encryption and signing keys.");await bo(e.encryption,"ECDH-ES+A256KW"),await bo(e.signing,"ES256")}async function vp(t){let{binding:e,signature:r}=nr.parse(t);return await uc(e),await Yn(e,r,e.signing,"key-binding"),e}var rge=h.object({requestedAt:Ne,readyAt:Ne}).strict(),nge=h.object({email:h.boolean(),storage:h.boolean(),payments:h.boolean()}),s0=h.object({principal:nl.nullable(),credentialId:E.nullable(),wrappedKey:_g.nullable(),requestId:E.nullable(),keyReset:rge.nullable(),server:h.object({name:me}),features:nge,principals:h.array(nl)}),MHe=h.object({email:h.email().max(254),returnTo:h.string().max(2048).optional(),locale:vK.default("ja"),principalId:E.optional()}).strict(),UHe=h.object({intent:h.enum(["register","authenticate"]),name:me.optional(),principalId:E.optional(),credentialId:E.optional(),returnTo:h.string().max(2048).optional()}).strict(),LHe=h.object({challengeId:E,credential:h.json(),binding:nr.optional(),existingPublicKey:mn.optional(),wrappedKey:_g.optional()}).strict(),FHe=h.object({binding:nr,wrappedKey:_g}).strict();import{createInterface as ige}from"node:readline/promises";var CK=h.object({action:h.string().regex(/^[a-z][a-zA-Z]*(\.[a-z][a-zA-Z]*)+$/).max(64),principalId:E}).catchall(Xn),OK=h.enum(["signature","decryption","email","passkey"]),oge=h.object({confirmationId:E,principalId:E,credentialId:E,bindingId:E.nullable(),operation:h.string(),nonce:h.string()}).strict(),RK=h.object({id:E,operation:CK,methods:h.array(OK),state:h.enum(["pending","confirmed","held"]),expiresAt:Ne,challenge:oge,sealed:dr.nullable()}).strict(),qHe=h.discriminatedUnion("method",[h.object({method:h.literal("signature"),signature:Mt}).strict(),h.object({method:h.literal("decryption"),secret:h.string().min(1).max(200)}).strict(),h.object({method:h.literal("email"),code:h.string().min(1).max(32)}).strict(),h.object({method:h.literal("passkey"),credential:h.json()}).strict()]),NK=h.object({operation:CK,methods:h.array(OK)}),DK="foundation-confirmation",zK=["confirmation_required","confirmation_invalid"],jK=(t,e)=>or(t.challenge,e,"operation-confirmation"),MK=t=>"operation-confirmation:"+t;async function UK(t,e,r){let o=await t.json("/api/confirmations",{method:"POST",body:{operation:e.operation}},RK);return await t.json("/api/confirmations/"+o.id+"/proof",{method:"POST",body:await r(o,t)},RK),o.id}var ci=class extends Error{constructor(r,o,n,i){super(n);this.code=r;this.status=o;this.details=i}code;status;details},es=class{constructor(e){this.identity=e}identity;async response(e,r={}){if(!e.startsWith("/api/")||e.includes("\\")||/[\u0000-\u001f]/.test(e))throw new Error("Use a path beginning with /api/.");let o=new URL(e,this.identity.origin);if(o.origin!==this.identity.origin)throw new Error("Use a path on the configured Foundation origin.");let n;try{n=await fetch(o,{method:r.method??"GET",headers:{authorization:"Bearer "+this.identity.token,...r.confirmation?{[DK]:r.confirmation}:{},...r.raw?{"content-type":"application/octet-stream"}:r.body!==void 0?{"content-type":"application/json"}:{}},body:r.raw?new Uint8Array(r.raw):r.body!==void 0?JSON.stringify(r.body):void 0,redirect:"error",signal:AbortSignal.any([AbortSignal.timeout(9e4),...r.signal?[r.signal]:[]])})}catch{throw new Error("Could not reach Foundation. Check the origin and your network connection.")}if(!n.ok){let i;try{i=h.object({error:h.object({code:h.string(),message:h.string(),details:h.unknown().optional()})}).parse(await n.json())}catch{throw new ci("http_error",n.status,"Foundation returned HTTP "+n.status+".")}let s=NK.safeParse(i.error.details);if(!r.confirmation&&zK.includes(i.error.code)&&s.success)return this.response(e,{...r,confirmation:await this.confirm(s.data)});throw new ci(i.error.code,n.status,i.error.message,i.error.details)}return n}confirm(e){return UK(this,e,async r=>{let{keys:o,binding:n}=this.identity;if(r.methods.includes("signature")&&o&&n?.id===r.challenge.bindingId)return{method:"signature",signature:await jK(r,o.signing)};if(r.methods.includes("decryption")&&o&&r.sealed)return{method:"decryption",secret:jt(await On(r.sealed,o.encryption,r.id,MK(r.id)))};if(r.methods.includes("email")&&process.stdin.isTTY&&process.stderr.isTTY){let{email:i}=await this.json("/api/confirmations/"+r.id+"/email",{method:"POST",body:{}}),s=ige({input:process.stdin,output:process.stderr});try{return{method:"email",code:await s.question("Enter the confirmation code sent to "+i+": ")}}finally{s.close()}}throw new ci("confirmation_required",403,"Prove confirmation "+r.id+" with "+r.methods.join(" or ")+" through /api/confirmations/"+r.id+", then send the same request again with it (foundation api --confirmation "+r.id+").",{...e,confirmationId:r.id})})}async json(e,r={},o){let n=await this.response(e,r),i=n.status===204?null:await n.json();return o?o.parse(i):i}async session(){return this.json("/api/session",{},s0)}};import{rm as Tge,stat as Pge}from"node:fs/promises";import{dirname as Rge,join as PN}from"node:path";import{chmod as sge,lstat as age,mkdir as cge,open as wN,readFile as FK,rename as uge,rm as lge}from"node:fs/promises";import{dirname as dge,join as bN,resolve as pge}from"node:path";import{homedir as fge}from"node:os";import{randomUUID as mge}from"node:crypto";var _N=h.object({origin:h.url(),principalId:h.uuid(),token:h.string().min(20),keys:il.nullable(),binding:Kr.nullable()}).strict().refine(t=>!!t.keys==!!t.binding&&(!t.binding||t.binding.principalId===t.principalId),"Use the keys bound to this identity."),VK=h.object({current:h.uuid(),identities:h.array(_N).min(1)}).strict().refine(t=>t.identities.some(e=>e.principalId===t.current),"The current identity is missing.");function ui(){return bN(process.env.XDG_CONFIG_HOME||bN(fge(),".config"),"foundation","identity.json")}function bp(t=process.env.FOUNDATION_ORIGIN||"https://foundationsystems.app"){let e;try{e=new URL(t)}catch{throw new Error("Set FOUNDATION_ORIGIN to an HTTPS origin.")}if(e.username||e.password||e.pathname!=="/"||e.search||e.hash||e.protocol!=="https:"&&!(e.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(e.hostname)))throw new Error("Use an HTTPS origin, or HTTP on localhost.");return e.origin}async function SN(){try{let t=ui(),e=await age(t);if(!e.isFile()||e.isSymbolicLink())throw new Error("The identity must be a regular file.");return process.platform!=="win32"&&e.mode&63&&await sge(t,384),VK.parse(JSON.parse(await FK(t,"utf8")))}catch(t){if(t instanceof Error&&"code"in t&&t.code==="ENOENT")return;throw new Error("The saved identity could not be read. Check its contents and permissions.")}}async function HK(){let t=await SN();return(t?.identities??[]).map(e=>({...e,current:e.principalId===t.current}))}async function BK(t){let e=await SN();if(!e?.identities.some(r=>r.principalId===t))throw new Error("No saved identity has principal "+t+". Run foundation identity list.");await da(ui(),JSON.stringify({...e,current:t},null,2)+`
130
130
  `,!0)}async function KK(t,e){let r=process.env.FOUNDATION_TOKEN,o=e||(r?void 0:process.env.FOUNDATION_PRINCIPAL_ID),n=await SN(),i;if(n){if(i=n.identities.find(a=>a.principalId===(o??n.current)),o&&!i&&!r)throw new Error("No saved identity has principal "+o+". Run foundation identity list.")}else if(o&&!r)throw new Error("Run foundation login to sign in on this machine.");let s=bp(t||process.env.FOUNDATION_ORIGIN||i?.origin);if(r){if(t&&process.env.FOUNDATION_ORIGIN&&s!==bp(process.env.FOUNDATION_ORIGIN))throw new Error("The environment identity belongs to a different origin.");let a=process.env.FOUNDATION_PRINCIPAL_ID,c=process.env.FOUNDATION_PRIVATE_KEYS,u=process.env.FOUNDATION_KEY_BINDING;if(!a)throw new Error("FOUNDATION_TOKEN requires FOUNDATION_PRINCIPAL_ID.");try{return _N.parse({origin:s,principalId:a,token:r,keys:c?JSON.parse(Buffer.from(c,"base64url").toString("utf8")):null,binding:u?JSON.parse(Buffer.from(u,"base64url").toString("utf8")):null})}catch{throw new Error("The Foundation environment identity is invalid.")}}if(!i)throw new Error("Run foundation login to sign in on this machine.");if(s!==bp(i.origin))throw new Error("This identity belongs to another origin. Use a separate XDG_CONFIG_HOME to initialize another server.");return{...i,origin:s}}async function _p(t){let e=ui(),r;try{r=VK.parse(JSON.parse(await FK(e,"utf8")))}catch(i){if(!(i instanceof Error&&"code"in i&&i.code==="ENOENT"))throw new Error("The saved identity could not be read. Check its contents and permissions.")}let o=_N.parse(t),n=(r?.identities??[]).filter(i=>!(i.origin===o.origin&&i.principalId===o.principalId));await da(e,JSON.stringify({current:o.principalId,identities:[...n,o]},null,2)+`
131
131
  `,!!r)}async function LK(t){if(process.platform==="win32")return;let e=await wN(t,"r");try{await e.sync()}finally{await e.close()}}async function da(t,e,r){let o=pge(t),n=dge(o);if(await cge(n,{recursive:!0,mode:448}),!r){let s=await wN(o,"wx",384);try{await s.writeFile(e),await s.sync()}finally{await s.close()}await LK(n);return}let i=bN(n,".foundation-"+mge());try{let s=await wN(i,"wx",384);try{await s.writeFile(e),await s.sync()}finally{await s.close()}await uge(i,o),await LK(n)}finally{await lge(i,{force:!0})}}import{lstat as hge,mkdir as qK,readFile as gge,readdir as ZK,rm as yge}from"node:fs/promises";import{join as Sp}from"node:path";var xN=h.string().regex(/^(refresh|checkpoint|identity)_[A-Za-z0-9_-]{1,100}$/),WK=t=>xN.safeParse(t).success,lc=class{constructor(e,r,o,n){this.directory=e;this.origin=r;this.binding=o;this.privateKeys=n}directory;origin;binding;privateKeys;indexing;context(e){return j({purpose:"executor-journal",origin:this.origin,bindingId:this.binding.id,id:xN.parse(e)})}async read(e){let r=this.context(e),o=Sp(this.directory,e+".json");try{let n=await hge(o);if(!n.isFile()||n.isSymbolicLink()||process.platform!=="win32"&&n.mode&63)throw new Error("The execution journal must use private regular files.");let i=h.string().max(32e6).parse(JSON.parse(await gge(o,"utf8"))),s=await pg(i,await bo(this.privateKeys.encryption,"ECDH-ES+A256KW"),{keyManagementAlgorithms:["ECDH-ES+A256KW"],contentEncryptionAlgorithms:["A256GCM"]});if(s.protectedHeader.kid!==this.binding.id||s.protectedHeader.ctx!==r)throw new Error("The journal entry belongs to another operation.");let a=JSON.parse(jt(s.plaintext));if(a.context!==r)throw new Error("The journal entry belongs to another operation.");return await Yn({context:r,value:a.value},a.signature,this.binding.signing,"journal"),a.value}catch(n){if(n instanceof Error&&"code"in n&&n.code==="ENOENT")return null;throw n}}async writeEntry(e,r){let o=this.context(e),n={context:o,value:r},i=await or(n,this.privateKeys.signing,"journal"),s=yt(j({...n,signature:i}));if(s.byteLength>2e7)throw new Error("The execution record is too large.");let a=await new hp(s).setProtectedHeader({alg:"ECDH-ES+A256KW",enc:"A256GCM",kid:this.binding.id,ctx:o}).encrypt(await bo(this.binding.encryption,"ECDH-ES+A256KW"));await qK(this.directory,{recursive:!0,mode:448}),await da(Sp(this.directory,e+".json"),j(a),!0)}delivery(e){return e.startsWith("refresh_")}delivered(e){return!!e&&typeof e=="object"&&"delivered"in e&&e.delivered===!0}async markPending(e){await qK(Sp(this.directory,"pending"),{recursive:!0,mode:448}),await da(Sp(this.directory,"pending",xN.parse(e)),"",!0)}index(){return this.indexing??=(async()=>{let e="checkpoint_pending_index";if(!await this.read(e)){for(let r of await this.keys("")){if(!this.delivery(r))continue;let o=await this.read(r);o&&!this.delivered(o)&&await this.markPending(r)}await this.writeEntry(e,{version:1})}})()}async write(e,r){await this.index();let o=this.delivered(r);this.delivery(e)&&!o&&await this.markPending(e),await this.writeEntry(e,r),this.delivery(e)&&o&&await yge(Sp(this.directory,"pending",e),{force:!0})}async pending(e){await this.index();let r;try{r=await ZK(Sp(this.directory,"pending"),{withFileTypes:!0})}catch(o){if(o instanceof Error&&"code"in o&&o.code==="ENOENT")return[];throw o}return r.filter(o=>o.isFile()&&o.name.startsWith(e)&&WK(o.name)).map(o=>o.name)}async keys(e){let r;try{r=await ZK(this.directory,{withFileTypes:!0})}catch(o){if(o instanceof Error&&"code"in o&&o.code==="ENOENT")return[];throw o}return r.filter(o=>o.isFile()&&o.name.startsWith(e)&&o.name.endsWith(".json")&&WK(o.name.slice(0,-5))).map(o=>o.name.slice(0,-5))}};var a0=h.url().refine(t=>{let e=new URL(t);return e.origin===t&&!e.username&&!e.password&&(e.protocol==="https:"||e.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(e.hostname))},"Use an HTTPS origin, or HTTP on localhost."),ut={value:"03546b17-fa44-409f-b151-8da1a398b324",tokenSet:"7d4b64dd-4546-4acb-8e96-91f864bccea6",clientCredential:"714fc044-2cce-4f3f-a477-281ee64fe632"},EN=h.enum([ut.value,ut.tokenSet,ut.clientCredential]),GK=1e6,XK=t=>t===ut.tokenSet,Nn=h.object({format:h.literal(3),origin:a0,id:E,ownerId:E,contentType:EN,revision:h.number().int().positive(),authorities:h.array(Kr).min(1).max(100),readers:h.array(Kr).min(1).max(100),observers:h.array(E).max(100).optional()}).strict(),JK=h.object({ownerId:E,authorities:h.array(Kr).min(1).max(100)}).strict(),YK=h.object({origin:a0,id:E,revision:h.number().int().positive(),from:JK,to:JK,policyDigest:Br,previous:Br.nullable(),signerId:E}).strict(),kN=YK.extend({signature:Mt}),IN=16,QK=h.array(kN).max(IN),Ir=h.object({policy:Nn,authorityId:E,authorization:Mt,lineage:QK.optional(),materialRevision:h.number().int().positive(),updatedAt:Ne,metadata:tr,sealed:dr,signerId:E,signature:Mt}).strict(),sl=t=>({ownerId:t.ownerId,authorities:t.authorities});async function $N(t,e=[]){let r;for(let o of e){let{signature:n,...i}=o;if(o.origin!==t.origin||o.id!==t.id||o.revision>t.revision||r&&(o.revision<=r.revision||j(r.to)!==j(o.from))||o.previous!==(r?await rt(r):null))throw new Error("Keep the signed chain of authority changes for this item.");let s=o.from.authorities.find(a=>a.id===o.signerId);if(!s)throw new Error("Only an existing authority can hand over this item.");await Yn(i,n,s.signing,"authority-handoff"),r=o}if(r&&j(r.to)!==j(sl(t)))throw new Error("Use the authorities approved by the latest handoff.")}function xp(t){let e=t.policy.authorities.find(n=>n.id===t.authorityId);if(e)return e;let r=t.lineage?.at(-1),o=r?.revision===t.policy.revision?r.from.authorities.find(n=>n.id===t.authorityId):void 0;if(!o||o.id!==r?.signerId)throw new Error("The policy must be signed by an approved authority.");return o}function eq(t,e){if(t.id!==e.policy.id||t.origin!==e.policy.origin||t.contentType!==e.policy.contentType)return!1;let r=j(sl(t));return r===j(sl(e.policy))?!0:!!e.lineage?.some(o=>o.revision>t.revision&&j(o.from)===r)}async function vge(t,e,r,o){let n=[...t?.lineage??[]];if(t&&j(sl(t.policy))!==j(sl(e))){if(!t.policy.authorities.some(s=>j(s)===j(r))||t.policy.id!==e.id||t.policy.origin!==e.origin||t.policy.contentType!==e.contentType||e.revision!==t.policy.revision+1)throw new Error("An existing authority must approve this handoff at the next policy revision.");let i=YK.parse({origin:e.origin,id:e.id,revision:e.revision,from:sl(t.policy),to:sl(e),policyDigest:await rt(e),previous:n.length?await rt(n.at(-1)):null,signerId:r.id});n.push({...i,signature:await or(i,o.signing,"authority-handoff")})}return n.length?{lineage:QK.parse(n)}:{}}async function tq(t){let e=Nn.parse(t),r=new Map;for(let o of[...e.authorities,...e.readers]){await uc(o);let n=j(o);if(r.has(o.id)&&r.get(o.id)!==n)throw new Error("Each key binding must identify the same keys throughout a policy.");r.set(o.id,n)}for(let o of[e.readers,e.authorities])if(new Set(o.map(n=>n.id)).size!==o.length)throw new Error("Choose distinct key bindings.");for(let o of e.authorities)if(!e.readers.some(n=>n.id===o.id))throw new Error("A policy authority must be able to open its content.");return e}async function al(t,e){return j({purpose:"resource",policyDigest:await rt(t),materialRevision:e})}async function Ep(t,e,r,o,n,i,s){if(t.byteLength>GK)throw new Error("The content exceeds its storage limit.");let a=await tq(e),c=await vge(s,a,o,n);if(!a.authorities.some(f=>j(f)===j(o))&&c.lineage?.at(-1)?.revision!==a.revision)throw new Error("Only a policy authority can replace its content.");let u=await ol(t,a.readers.map(f=>({id:f.id,publicKey:f.encryption})),await al(a,r)),l={policy:a,...c,authorityId:o.id,authorization:await or(a,n.signing,"access-policy"),materialRevision:r,updatedAt:new Date().toISOString(),metadata:i??(a.contentType===ut.value?{bytes:t.byteLength}:{}),sealed:u,signerId:o.id},d=Ir.parse({...l,signature:await or(l,n.signing,"resource")});return await dc(d),d}async function dc(t){let e=Ir.parse(t),{signature:r,...o}=e;await tq(e.policy),await $N(e.policy,e.lineage);let n=xp(e),i=e.lineage?.at(-1);if(i?.revision===e.policy.revision&&i.policyDigest!==await rt(e.policy))throw new Error("The handoff approves a different access policy.");await Yn(e.policy,e.authorization,n.signing,"access-policy");let s=(e.signerId===n.id?n:void 0)??e.policy.authorities.find(u=>u.id===e.signerId)??(XK(e.policy.contentType)?e.policy.readers.find(u=>u.id===e.signerId):void 0);if(!s||Date.parse(e.updatedAt)>Date.now()+3e4)throw new Error("The signer cannot replace this content.");await Yn(o,r,s.signing,"resource");let a=e.policy.readers.map(u=>u.id).sort(),c=e.sealed.recipients.map(u=>u.header.kid).sort();if(j(a)!==j(c)||e.sealed.aad!==la(yt(await al(e.policy,e.materialRevision))))throw new Error("Encrypt content for exactly the readers its policy names.");return e}async function rq(t,e,r,o,n=t.metadata){let i=await dc(t);if(!XK(i.policy.contentType)||!i.policy.readers.some(f=>j(f)===j(r)))throw new Error("Only a reader of this connection can renew it.");if(e.byteLength>GK)throw new Error("The content exceeds its storage limit.");let s=i.materialRevision+1,a=await ol(e,i.policy.readers.map(f=>({id:f.id,publicKey:f.encryption})),await al(i.policy,s)),{signature:c,...u}=i,l={...u,materialRevision:s,updatedAt:new Date().toISOString(),metadata:n,sealed:a,signerId:r.id},d={...l,signature:await or(l,o.signing,"resource")};return await dc(d),d}async function Qn(t,e,r){let o=await dc(t);if(!o.policy.readers.some(n=>j(n)===j(e)))throw new Error("This identity cannot reveal the content.");return On(o.sealed,r,e.id,await al(o.policy,o.materialRevision))}var wge=h.object({binding:Kr,verifiedAt:Ne}).strict(),AN=h.object({origin:h.url(),ownerId:E,signerId:E,revision:h.number().int().positive(),keys:h.array(wge).max(1e3)}).strict(),bge=h.object({version:h.number().int().positive(),signature:Mt}).strict(),TN=h.object({keyring:bge.nullable()}).strict(),EBe=h.object({version:h.number().int().positive().nullable(),signature:Mt}).strict();function c0(t,e){return or(AN.parse(t),e,"keyring")}function nq(t){return AN.parse(JSON.parse(jt(t0(t.split(".")[1]??""))))}async function u0(t,e){let r=AN.parse(await vN(t,e.signing,"keyring"));if(r.signerId!==e.id)throw new Error("Another identity signed this keyring.");return r}var oq=h.enum(["content","keyring"]),OBe=h.object({id:E,replacement:nr,previousSignature:Mt,handoff:dr}).strict(),iq=h.object({replacement:i0,handoff:dr}).strict(),sq=h.discriminatedUnion("kind",[h.object({kind:h.literal("content"),content:Ir}).strict(),h.object({kind:h.literal("keyring"),signature:Mt}).strict()]),NBe=h.object({sourceDigest:Br,payload:sq,signature:Mt}).strict(),DBe=h.object({sourceDigest:Br,payload:sq}).strict(),aq=h.record(h.string(),h.unknown()),_ge=h.object({kind:oq,id:E,name:me.nullable(),sourceDigest:Br,state:h.enum(["pending","prepared","stale"]),signers:h.array(E).nullable(),source:aq.nullable()}),cq=h.object({rotation:h.object({id:E,principalId:E,previous:nr,replacement:nr,previousSignature:Mt}).strict(),kind:oq,id:E,name:me,sourceDigest:Br,source:aq}).strict(),Sge=h.object({kind:h.string(),id:E,reason:h.string()}),l0=h.object({id:E,principalId:E,state:h.enum(["preparing","committed","cancelled"]),previous:nr,replacement:nr,previousSignature:Mt,handoff:dr,createdAt:Ne,finishedAt:Ne.nullable(),total:h.number().int().nonnegative(),prepared:h.number().int().nonnegative(),blockers:h.array(Sge),items:h.array(_ge),next:h.string().nullable()});function xge(t,e,r){let o=n=>{if(n.id!==e.id)return n;if(j(n)!==j(e))throw new Error("Use the exact previous key binding.");return r};return Nn.parse({...t,revision:t.revision+1,readers:t.readers.map(o),authorities:t.authorities.map(o)})}async function uq(t,e,r,o,n,i){let s=await Qn(t,o,n.encryption),a=await Ep(s,xge(t.policy,e,r),t.materialRevision+1,o,n,t.metadata,t);if(o.id!==e.id)return a;if(!i)throw new Error("Keep the replacement keys before preparing rotated content.");let{signature:c,...u}=a,l={...u,authorityId:r.id,signerId:r.id,authorization:await or(a.policy,i.signing,"access-policy")};return dc({...l,signature:await or(l,i.signing,"resource")})}async function Ege(t,e,r,o,n,i){return{rotationId:t,principalId:e,replacementId:r,itemId:o,sourceDigest:n,payloadDigest:await rt(i)}}async function kge(t,e,r,o,n,i,s){return{sourceDigest:n,payload:i,signature:await or(await Ege(t,e,r,o,n,i),s,"key-rotation-preparation")}}var lq=t=>"key-handoff:"+t.principalId+":"+t.id;function Ige(t,e,r){return ol(yt(JSON.stringify(r)),[{id:t.id,publicKey:t.encryption}],lq(e))}async function dq(t,e,r){let{replacement:o,handoff:n}=iq.parse(t);if(j(o.previous.binding)!==j(e))throw new Error("This key handoff follows other keys.");let i=o.replacement.binding;if(!await Eg(e,i,[o]))throw new Error("The previous keys did not authorize these replacement keys.");let s=il.parse(JSON.parse(jt(await On(n,r,e.id,lq(i)))));return await wp(i,s),{binding:i,keys:s}}async function pq(t,e){let r=E.parse("binding"in e?e.binding.principalId:e.principalId),o="/api/principals/"+r+"/key-handoffs",n="binding"in e?e.binding:null,i=e.keys,s=null;for(let a=0;a<=32;a++){let{binding:c}=await t.json("/api/identities/"+r+"/binding",{},nr);if(n?j(c)===j(n):await xo(c.encryption)===await xo(yp(e.keys.encryption)))return s?{binding:c,keys:s}:null;if(n&&c.generation<=n.generation||a===32)throw new kg("The keys of this identity were made again. Sign in with a passkey that holds them.");let u=await t.json(n?o+"/"+E.parse(n.id):o+"?"+new URLSearchParams({encryption:await xo(yp(e.keys.encryption))}),{},iq),l=n??u.replacement.previous.binding;if(!n&&await xo(l.encryption)!==await xo(yp(e.keys.encryption)))throw new Error("This key handoff follows other keys.");let d=await dq(u,l,i.encryption);({binding:n}=d),i=s=d.keys}return null}var kg=class extends Error{code="keys_replaced";constructor(e){super(e)}},$ge=h.object({rotation:l0.nullable()});async function fq(t,e){let{binding:r,keys:o}=e,n=E.parse(r.principalId),i="/api/principals/"+n+"/key-rotations",{rotation:s}=await t.json(i,{},$ge),a;if(s)a=await dq({replacement:{previous:s.previous,replacement:s.replacement,previousSignature:s.previousSignature},handoff:s.handoff},r,o.encryption);else{let u=await n0(),l={...o0(n,u),generation:r.generation+1,previous:await rt(r)};a={binding:l,keys:u},s=await t.json(i,{method:"POST",body:{id:crypto.randomUUID(),replacement:await wp(l,u),previousSignature:await or(l,o.signing,"key-replacement"),handoff:await Ige(r,l,u)}},l0)}let c=i+"/"+E.parse(s.id);for(let u=0;u<5;u++){let l=[],d=null,f=[];do{let p=await t.json(c+"?"+new URLSearchParams({limit:"100",...d?{after:d}:{}}),{},l0);f=p.blockers.filter(m=>m.reason==="authority_history_full");for(let m of p.items){if(m.state==="prepared"||f.some(y=>y.id===m.id))continue;if(m.signers){l.push(m);continue}let g=await Age(m,r,a,o);await t.json(c+"/items/"+m.kind+"/"+m.id,{method:"PUT",body:await kge(s.id,n,a.binding.id,m.id,m.sourceDigest,g,o.signing)})}d=p.next}while(d);if(f.length)return{state:"blocked",rotationId:s.id,blockers:f};if(l.length)return{state:"waiting",rotationId:s.id,waiting:l.map(p=>({kind:p.kind,id:p.id,name:p.name,signers:p.signers}))};try{return await t.json(c+"/commit",{method:"POST"},l0),{state:"committed",...a}}catch(p){if(!(p&&typeof p=="object"&&"code"in p&&["rotation_not_ready","rotation_busy","changed"].includes(String(p.code))))throw p}}throw new Error("The items kept changing during the key rotation. Try again later.")}async function Age(t,e,r,o){let n=t.source;if(!n)throw new Error("This identity cannot read an item it must prepare.");switch(t.kind){case"content":return{kind:t.kind,content:await uq(Ir.parse(n.content),e,r.binding,e,o,r.keys)};case"keyring":{let i=await u0(String(n.signature),e);return{kind:"keyring",signature:await c0({...i,signerId:r.binding.id,revision:i.revision+1,keys:i.keys.map(s=>s.binding.id===e.id?{...s,binding:r.binding}:s)},r.keys.signing)}}}}async function mq(t,e,r){let o=t.rotation.previous.binding,n=t.rotation.replacement.binding,i=t.source;if(t.kind==="content")return{kind:t.kind,content:await uq(Ir.parse(i.content),o,n,e,r)};throw new Error("Only the rotating identity prepares this item.")}var hq=t=>PN(Rge(ui()),"custody",t.id),Cge=t=>Pge(t).then(()=>!0,()=>!1);async function gq(t,e,r){let o=hq(e.binding),n=hq(r.binding);if(!await Cge(o))return;let i=async s=>{let a=new lc(PN(o,s),t,e.binding,e.keys),c=new lc(PN(n,s),t,r.binding,r.keys);for(let u of await a.keys("")){let l=await a.read(u);l!==null&&await c.write(u,l)}};for(let s of["client","connections"])await i(s);await Tge(o,{recursive:!0,force:!0})}async function yq(t){if(!t.keys||!t.binding)return t;let e;try{e=await pq(new es(t),{binding:t.binding,keys:t.keys})}catch(o){if(!(o instanceof kg))throw o;return process.stderr.write("foundation: "+o.message+`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomato414941/foundation",
3
- "version": "29.0.0",
3
+ "version": "29.0.2",
4
4
  "description": "Manage Foundation resources and use them in local commands.",
5
5
  "type": "module",
6
6
  "engines": {