@tomato414941/foundation 29.0.1 → 29.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +1 -1
- 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 Du(t,e){return t.definite=!1,ne(t,e)}function ee(t){return`v${t.varCounter++}`}function Wpe(t,e){let r=t._zod.run({value:e,issues:[]},{});if(r&&typeof r.then=="function")return un;let o=r;return o.issues.length===0?o.value:un}function Lr(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,Jpe(t,e,r,o)}}function Jpe(t,e,r,o){e.definite=!1;let n=ne(e,r),i=ne(e,Wpe),s=ee(e);return t.write(`const ${s} = ${i}(${n}, ${o});`),t.write(`if (${s} === INVALID) return INVALID;`),s}var Gpe=new Set(["max_size","min_size","size_equals","max_length","min_length","length_equals"]);function Xpe(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&&!Gpe.has(a.check))throw new Re('check with a custom "when" condition');switch(a.check){case"greater_than":Ype(t,e,a,i);break;case"less_than":Qpe(t,e,a,i);break;case"multiple_of":efe(t,e,a,i);break;case"number_format":OV(t,a,i);break;case"min_length":{let c=Ha(a.minimum,"min_length"),u=PR(t,e,i,`${i}.length >= ${c} && ${i}.length < ${a.minimum*2}`);t.write(`if (${u} < ${c}) return INVALID;`);break}case"max_length":{let c=Ha(a.maximum,"max_length"),u=PR(t,e,i,`${i}.length > ${c}`);t.write(`if (${u} > ${c}) return INVALID;`);break}case"length_equals":{let c=Ha(a.length,"length_equals"),u=PR(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 < ${Ha(a.minimum,"min_size")}) return INVALID;`);break;case"max_size":t.write(`if (${i}.size > ${Ha(a.maximum,"max_size")}) return INVALID;`);break;case"size_equals":t.write(`if (${i}.size !== ${Ha(a.size,"size_equals")}) return INVALID;`);break;case"string_format":i=NV(t,e,a,i);break;case"custom":i=sfe(t,e,s,i);break;case"bigint_format":tfe(t,a,i);break;case"mime_type":rfe(t,e,a,i);break;case"property":ofe(t,e,a,i);break;case"properties":nfe(t,e,a,i);break;case"overwrite":{let c=ee(e);ife(t,e,s,i,c),i=c;break}default:throw new Re(`check type ${a.check}`)}}return i}function PR(t,e,r,o){let n=ne(e,Tu),i=ee(e);return t.write(`const ${i} = typeof ${r} === "string" && ${o} ? ${n}(${r}) : ${r}.length;`),i}function Ha(t,e){if(typeof t!="number"||!Number.isFinite(t))throw new Re(`${e} bound of type ${typeof t}`);return`${t}`}function CV(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 Ype(t,e,r,o){let n=r.inclusive?"<":"<=";t.write(`if (${o} ${n} ${CV(e,r.value)}) return INVALID;`)}function Qpe(t,e,r,o){let n=r.inclusive?">":">=";t.write(`if (${o} ${n} ${CV(e,r.value)}) return INVALID;`)}function efe(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,Bm);t.write(`if (${n}(${o}, ${Ha(r.value,"multiple_of")}) !== 0) return INVALID;`)}}function OV(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 tfe(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 rfe(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 nfe(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):an(i),a=ee(e);t.write(`const ${a} = ${o}[${s}];`),Lr(t,e,n[i],a,!1)}}function ofe(t,e,r,o){let n=`${o}[${JSON.stringify(r.property)}]`;Pt(t,e,r.schema,n)}function ife(t,e,r,o,n){let i=r._zod.def.tx;if(!i)throw new Re("overwrite check without a transform function");if(zu(i))throw new Yo("z.compile: async overwrite transforms are not supported");let s=ne(e,i);t.write(`const ${n} = ${s}(${o});`)}function RR(){throw new In}function NR(t){this.issues.push(t)}function sfe(t,e,r,o){let n=r._zod.def;if(n.fn){if(zu(n.fn))throw new Yo("z.compile: async .refine() predicates are not supported");let i=Du(e,n.fn),s=ne(e,RR),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(zu(r._zod.check))throw new Yo("z.compile: async .superRefine() / check functions are not supported");let i=r._zod.check,a=Du(e,u=>{let l={value:u,issues:[],addIssue:NR};return i(l)instanceof Promise&&RR(),l.issues.length===0?l.value:un}),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 afe=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 NV(t,e,r,o,n=!0){let i=r.format;if(i==="base64"){let u=ne(e,ah);return t.write(`if (!${u}(${o})) return INVALID;`),o}if(i==="base64url"){let u=ne(e,Wb);return t.write(`if (!${u}(${o})) return INVALID;`),o}if(i==="jwt"){let u=ne(e,t_),l=ne(e,r.alg??null);return t.write(`if (!${u}(${o}, ${l})) return INVALID;`),o}if(i==="ipv6"){let u=ne(e,sh);return t.write(`if (!${u}(${o})) return INVALID;`),o}if(i==="cidrv6"){let u=ne(e,Bb);return t.write(`if (!${u}(${o})) return INVALID;`),o}if(i==="credit_card"){let u=ne(e,Xb);return t.write(`if (!${u}(${o})) return INVALID;`),o}if(i==="iban"){let u=ne(e,Qb);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,Tb),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,Pb);t.write(`if (!${g}(${f}, ${l}.hostname)) return INVALID;`)}if(s.protocol!==void 0){let g=ne(e,Rb);t.write(`if (!${g}(${f}, ${l}.protocol)) return INVALID;`)}if(!n)return null;let p=ee(e),m=s.normalize?`${f}.href`:`${ne(e,ih)}(${d})`;return t.write(`const ${p} = ${m};`),p}let a=r.fn;if(a){if(zu(a))throw new Re(`async string format ${i}`);let u=ne(e,a);return t.write(`if (!${u}(${o})) return INVALID;`),o}if(afe.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(${an(r.includes)})) return INVALID;`);break;case"starts_with":{let u=r.prefix;t.write(`if (${o}.slice(0, ${u.length}) !== ${an(u)}) return INVALID;`);break}case"ends_with":{let u=r.suffix;t.write(`if (${o}.slice(-${u.length}) !== ${an(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=cfe(t,e,r,o,a);break;case"number":c=ufe(t,r,o);break;case"boolean":c=lfe(t,o);break;case"bigint":c=dfe(t,r,o);break;case"symbol":c=pfe(t,o);break;case"undefined":c=ffe(t,o);break;case"null":c=mfe(t,o);break;case"any":case"unknown":c=o;break;case"never":t.write("return INVALID;"),c=o;break;case"void":c=hfe(t,o);break;case"nan":c=gfe(t,o);break;case"date":c=yfe(t,o);break;case"object":c=vfe(t,e,r,o,a);break;case"optional":c=wfe(t,e,r,o,a);break;case"nullable":c=Sfe(t,e,r,o,a);break;case"array":c=xfe(t,e,r,o,a);break;case"literal":c=Efe(t,e,r,o);break;case"enum":c=kfe(t,e,r,o);break;case"readonly":{let u=TV(t,e,r,o),l=ee(e);t.write(`const ${l} = Object.freeze(${u});`),c=l;break}case"success":TV(t,e,r,o),c="true";break;case"default":case"prefault":c=Ife(t,e,r,o);break;case"nonoptional":c=$fe(t,e,r,o);break;case"tuple":c=Afe(t,e,r,o);break;case"union":c=Tfe(t,e,r,o);break;case"intersection":c=Cfe(t,e,r,o);break;case"record":c=Ofe(t,e,r,o);break;case"map":c=Dfe(t,e,r,o);break;case"set":c=zfe(t,e,r,o);break;case"file":c=jfe(t,o);break;case"template_literal":c=Mfe(t,e,r,o);break;case"lazy":c=Ufe(t,e,r,o);break;case"pipe":c=Lfe(t,e,r,o);break;case"custom":c=Ffe(t,e,r,o);break;case"transform":c=Bfe(t,e,r,o);break;case"catch":c=Hfe(t,e,r,o);break;default:throw new Re(`schema type ${s}`)}return c===null?null:Xpe(t,e,r,c)}function cfe(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:NV(t,e,i,o,n)}function ufe(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&&OV(t,{format:o.format},r),r}function lfe(t,e){return t.write(`if (typeof ${e} !== "boolean") return INVALID;`),e}function dfe(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 pfe(t,e){return t.write(`if (typeof ${e} !== "symbol") return INVALID;`),e}function ffe(t,e){return t.write(`if (${e} !== undefined) return INVALID;`),e}function mfe(t,e){return t.write(`if (${e} !== null) return INVALID;`),e}function hfe(t,e){return t.write(`if (${e} !== undefined) return INVALID;`),e}function gfe(t,e){return t.write(`if (typeof ${e} !== "number" || !Number.isNaN(${e})) return INVALID;`),e}function yfe(t,e){return t.write(`if (!(${e} instanceof Date) || Number.isNaN(${e}.getTime())) return INVALID;`),e}function vfe(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):an(b),d=b=>typeof b=="symbol"?`[${l(b)}]`:an(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=Lr(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{_fe(_)&&t.write(`if (!(${k} in ${o})) return INVALID;`);let D=Lr(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 !== ${an(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=>AV(f[b])||CR(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];`),Lr(_,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);CR(f[b])?t.write(`if (${_} in ${o}) ${y}[${_}] = ${k};`):AV(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 $=Lr(_,e,m,k);_.write(`${y}[k] = ${$};`)}}),t.write("}")}return y}function wfe(t,e,r,o,n=!0){let i=r._zod.def;if(bfe(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 bfe(t){return t._zod.traits?.has("$ZodExactOptional")===!0}function _fe(t){return t._zod.optin===void 0&&Nu(t)}function Nu(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?Nu(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?Nu(e.innerType):!0;case"catch":return!0;case"union":return e.options?e.options.some(Nu):!0;case"intersection":return!e.left||!e.right?!0:Nu(e.left)&&Nu(e.right);case"pipe":return e.in?Nu(e.in):!0;default:return!0}}function CR(t){return t._zod.optin==="optional"&&t._zod.optout==="optional"}function AV(t){return(t._zod.optin!=="defaulted"||t._zod.optout==="optional")&&Ad(t)}function Ad(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?Ad(e.innerType):!0;case"union":return e.options?e.options.some(Ad):!0;case"intersection":return!e.left||!e.right||Ad(e.left)||Ad(e.right);case"pipe":return e.out?Ad(e.out):!0;default:return!0}}function Sfe(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 DR(t,e,r){for(let[o,n]of ud(e._zod.def.checks))t.write(`if (${r} > ${Ha(o,n._zod.def.check)}) return INVALID;`)}function xfe(t,e,r,o,n=!0){let i=r._zod.def;t.write(`if (!Array.isArray(${o})) return INVALID;`),DR(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=Lr(u,e,i.element,c,n);s&&l!==null&&u.write(`${s}[${a}] = ${l};`)}),t.write("}"),s}function Efe(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} !== ${an(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 kfe(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 TV(t,e,r,o){let n=r._zod.def;return Pt(t,e,n.innerType,o)}function Ife(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,cd);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 $fe(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 Afe(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=PV(i,"optin"),c=PV(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=Lr(p,e,d,m);p.write(`${u}[${l}] = ${g};`)}),f.write("} else {"),f.indented(p=>{if(CR(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=Lr(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=Lr(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=Lr(f,e,s,d);f.write(`${u}[${l}] = ${p};`)}),t.write("}")}return u}function PV(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 Tfe(t,e,r,o){let n=r._zod.def,i=n.options;if(n.discriminator)return Pfe(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 Pfe(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}?.[${an(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=>Rfe(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 Rfe(t,e,r){if(typeof r=="string")return`${e} === ${an(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 Cfe(t,e,r,o){let n=r._zod.def;e.definite=!1;let i=Lr(t,e,n.left,o),s=Lr(t,e,n.right,o),a=ne(e,bd),c=ee(e);return t.write(`const ${c} = ${a}(${i}, ${s});`),t.write(`if (!${c}.valid) return INVALID;`),`${c}.data`}function Ofe(t,e,r,o){let n=r._zod.def,i=ne(e,mo);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}[${Nfe(e,y)}];`);let k=Lr(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=X_(n.keyType);m.definite===!1&&(e.definite=!1);let g=ne(e,m),y=ne(e,ta),w=ee(e);return RV(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=Lr(b,e,n.valueType,_);b.write(`${s}[${w}] = ${k};`)}),s}return RV(t,e,o,a,p=>{p.write(`const ${c} = ${o}[${a}];`);let m=Lr(p,e,n.valueType,c);p.write(`${s}[${a}] = ${m};`)},"return INVALID;"),s}function RV(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 Nfe(t,e){return typeof e=="string"?an(e):ne(t,e)}function Dfe(t,e,r,o){let n=r._zod.def;t.write(`if (!(${o} instanceof Map)) return INVALID;`),DR(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 zfe(t,e,r,o){let n=r._zod.def;t.write(`if (!(${o} instanceof Set)) return INVALID;`),DR(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 jfe(t,e){return t.write(`if (!(${e} instanceof File)) return INVALID;`),e}function Mfe(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 Ufe(t,e,r,o){let n=r._zod.def,i=Du(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 Lfe(t,e,r,o){let n=r._zod.def,i=Pt(t,e,n.in,o);if(n.transform){if(zu(n.transform))throw new Yo("z.compile: async transforms in pipes are not supported");let s=n.transform,c=Du(e,l=>{let d={value:l,issues:[],addIssue:NR},f=s(l,d);return f instanceof Promise?un:d.issues.length===0?f:un}),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 zu(t){return typeof t=="function"&&(t.constructor.name==="AsyncFunction"||t[Symbol.toStringTag]==="AsyncFunction")}function Ffe(t,e,r,o){let n=r._zod.def;if(n.fn){if(zu(n.fn))throw new Yo("z.compile: async custom predicates are not supported");let i=Du(e,n.fn),s=ne(e,RR),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 Vfe(t,e,r){let o=t._zod.run({value:r,issues:[]},{});if(o&&typeof o.then=="function")return un;let n=o;return n.issues.length===0?n.value:e()}function Hfe(t,e,r,o){let n=r._zod.def;if(!n.catchValue[ib])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=Lr(u,e,n.innerType,o);u.write(`return ${l};`)}),t.write("})();");let s=ne(e,n.innerType),a=Du(e,n.catchValue),c=ne(e,Vfe);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 Bfe(t,e,r,o){let n=r._zod.def;if(n.transform){if(zu(n.transform))throw new Yo("z.compile: async transforms are not supported");let i=n.transform,a=Du(e,u=>{let l={value:u,issues:[],addIssue:NR},d=i(u,l);return d instanceof Promise?un:l.issues.length===0?d:un}),c=ee(e);return t.write(`const ${c} = ${a}(${o});`),t.write(`if (${c} === INVALID) return INVALID;`),c}return o}function Y_(t){return t.checks&&(t.checks=[...t.checks]),t}function Q_(t,e){return new t(Y_({type:"string",...N(e)}))}function zR(t,e){return new t(Y_({type:"string",coerce:!0,...N(e)}))}function vh(t,e){return new t({type:"string",format:"email",check:"string_format",abort:!1,...N(e)})}function wh(t,e){return new t({type:"string",format:"guid",check:"string_format",abort:!1,...N(e)})}function bh(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,...N(e)})}function _h(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...N(e)})}function Sh(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...N(e)})}function xh(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...N(e)})}function Td(t,e){return new t({type:"string",format:"url",check:"string_format",abort:!1,...N(e)})}function Eh(t,e){return new t({type:"string",format:"emoji",check:"string_format",abort:!1,...N(e)})}function kh(t,e){return new t({type:"string",format:"nanoid",check:"string_format",abort:!1,...N(e)})}function Ih(t,e){return new t({type:"string",format:"cuid",check:"string_format",abort:!1,...N(e)})}function $h(t,e){return new t({type:"string",format:"cuid2",check:"string_format",abort:!1,...N(e)})}function Ah(t,e){return new t({type:"string",format:"ulid",check:"string_format",abort:!1,...N(e)})}function Th(t,e){return new t({type:"string",format:"xid",check:"string_format",abort:!1,...N(e)})}function Ph(t,e){return new t({type:"string",format:"ksuid",check:"string_format",abort:!1,...N(e)})}function Rh(t,e){return new t({type:"string",format:"ipv4",check:"string_format",abort:!1,...N(e)})}function Ch(t,e){return new t({type:"string",format:"ipv6",check:"string_format",abort:!1,...N(e)})}function eS(t,e){return new t({type:"string",format:"mac",check:"string_format",abort:!1,...N(e)})}function Oh(t,e){return new t({type:"string",format:"cidrv4",check:"string_format",abort:!1,...N(e)})}function Nh(t,e){return new t({type:"string",format:"cidrv6",check:"string_format",abort:!1,...N(e)})}function Dh(t,e){return new t({type:"string",format:"base64",check:"string_format",abort:!1,...N(e)})}function zh(t,e){return new t({type:"string",format:"base64url",check:"string_format",abort:!1,...N(e)})}function jh(t,e){return new t({type:"string",format:"e164",check:"string_format",abort:!1,...N(e)})}function tS(t,e){return new t({type:"string",format:"credit_card",check:"string_format",abort:!1,...N(e)})}function rS(t,e){return new t({type:"string",format:"iban",check:"string_format",abort:!1,...N(e)})}function Mh(t,e){return new t({type:"string",format:"jwt",check:"string_format",abort:!1,...N(e)})}var jR={Any:null,Minute:-1,Second:0,Millisecond:3,Microsecond:6};function Uh(t,e){return new t({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...N(e)})}function Lh(t,e){return new t({type:"string",format:"date",check:"string_format",...N(e)})}function Fh(t,e){return new t({type:"string",format:"time",check:"string_format",precision:null,...N(e)})}function Vh(t,e){return new t({type:"string",format:"duration",check:"string_format",...N(e)})}function nS(t,e){return new t(Y_({type:"number",checks:[],...N(e)}))}function MR(t,e){return new t(Y_({type:"number",coerce:!0,checks:[],...N(e)}))}function oS(t,e){return new t({type:"number",check:"number_format",abort:!1,format:"safeint",...N(e)})}function iS(t,e){return new t({type:"number",check:"number_format",abort:!1,format:"float32",...N(e)})}function sS(t,e){return new t({type:"number",check:"number_format",abort:!1,format:"float64",...N(e)})}function aS(t,e){return new t({type:"number",check:"number_format",abort:!1,format:"int32",...N(e)})}function cS(t,e){return new t({type:"number",check:"number_format",abort:!1,format:"uint32",...N(e)})}function uS(t,e){return new t({type:"boolean",...N(e)})}function UR(t,e){return new t({type:"boolean",coerce:!0,...N(e)})}function lS(t,e){return new t({type:"bigint",...N(e)})}function LR(t,e){return new t({type:"bigint",coerce:!0,...N(e)})}function dS(t,e){return new t({type:"bigint",check:"bigint_format",abort:!1,format:"int64",...N(e)})}function pS(t,e){return new t({type:"bigint",check:"bigint_format",abort:!1,format:"uint64",...N(e)})}function fS(t,e){return new t({type:"symbol",...N(e)})}function mS(t,e){return new t({type:"undefined",...N(e)})}function hS(t,e){return new t({type:"null",...N(e)})}function gS(t){return new t({type:"any"})}function yS(t){return new t({type:"unknown"})}function vS(t,e){return new t({type:"never",...N(e)})}function wS(t,e){return new t({type:"void",...N(e)})}function bS(t,e){return new t({type:"date",...N(e)})}function FR(t,e){return new t({type:"date",coerce:!0,...N(e)})}function _S(t,e){return new t({type:"nan",...N(e)})}function Wi(t,e){return new wb({check:"less_than",...N(e),value:t,inclusive:!1})}function Bn(t,e){return new wb({check:"less_than",...N(e),value:t,inclusive:!0})}function Ji(t,e){return new bb({check:"greater_than",...N(e),value:t,inclusive:!1})}function Kn(t,e){return new bb({check:"greater_than",...N(e),value:t,inclusive:!0})}function SS(t){return Ji(0,t)}function xS(t){return Wi(0,t)}function ES(t){return Bn(0,t)}function kS(t){return Kn(0,t)}function Ba(t,e){return new JP({check:"multiple_of",...N(e),value:t})}function Ka(t,e){return new YP({check:"max_size",...N(e),maximum:t})}function Gi(t,e){return new QP({check:"min_size",...N(e),minimum:t})}function ju(t,e){return new eR({check:"size_equals",...N(e),size:t})}function Mu(t,e){return new tR({check:"max_length",...N(e),maximum:t})}function ra(t,e){return new rR({check:"min_length",...N(e),minimum:t})}function Uu(t,e){return new nR({check:"length_equals",...N(e),length:t})}function Pd(t,e){return new oR({check:"string_format",format:"regex",...N(e),pattern:t})}function Rd(t){return new iR({check:"string_format",format:"lowercase",...N(t)})}function Cd(t){return new sR({check:"string_format",format:"uppercase",...N(t)})}function Od(t,e){return new aR({check:"string_format",format:"includes",...N(e),includes:t})}function Nd(t,e){return new cR({check:"string_format",format:"starts_with",...N(e),prefix:t})}function Dd(t,e){return new uR({check:"string_format",format:"ends_with",...N(e),suffix:t})}function IS(t,e,r){return new lR({check:"property",property:t,schema:e,...N(r)})}function zd(t,e){return new dR({check:"properties",shape:t,...N(e)})}function jd(t,e){return new pR({check:"mime_type",mime:t,...N(e)})}function Qo(t){return new fR({check:"overwrite",tx:t})}function Md(t){return Qo(e=>e.normalize(t))}function Ud(){return Qo(t=>t.trim())}function Ld(){return Qo(t=>t.toLowerCase())}function Fd(){return Qo(t=>t.toUpperCase())}function Vd(){return Qo(t=>GT(t))}function VR(t,e,r){return new t({type:"array",element:e,...N(r)})}function Kfe(t,e,r){return new t({type:"union",options:e,...N(r)})}function qfe(t,e,r){return new t({type:"union",options:e,inclusive:!1,...N(r)})}function Zfe(t,e,r,o){return new t({type:"union",options:r,discriminator:e,...N(o)})}function Wfe(t,e,r){return new t({type:"intersection",left:e,right:r})}function Jfe(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 Gfe(t,e,r,o){return new t({type:"record",keyType:e,valueType:r,...N(o)})}function Xfe(t,e,r,o){return new t({type:"map",keyType:e,valueType:r,...N(o)})}function Yfe(t,e,r){return new t({type:"set",valueType:e,...N(r)})}function Qfe(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 eme(t,e,r){return new t({type:"enum",entries:e,...N(r)})}function tme(t,e,r){return new t({type:"literal",values:Array.isArray(e)?e:[e],...N(r)})}function $S(t,e){return new t({type:"file",...N(e)})}function rme(t,e){return new t({type:"transform",transform:e})}function nme(t,e){return new t({type:"optional",innerType:e})}function ome(t,e){return new t({type:"nullable",innerType:e})}function ime(t,e,r){return new t({type:"default",innerType:e,get defaultValue(){return typeof r=="function"?r():cd(r)}})}function sme(t,e,r){return new t({type:"nonoptional",innerType:e,...N(r)})}function ame(t,e){return new t({type:"success",innerType:e})}function cme(t,e,r){return new t({type:"catch",innerType:e,catchValue:typeof r=="function"?r:nP(r)})}function ume(t,e,r){return new t({type:"pipe",in:e,out:r})}function lme(t,e){return new t({type:"readonly",innerType:e})}function dme(t,e,r){return new t({type:"template_literal",parts:e,...N(r)})}function pme(t,e){return new t({type:"lazy",getter:e})}function fme(t,e){return new t({type:"promise",innerType:e})}function AS(t,e,r){let o=N(r);return o.abort??(o.abort=!0),new t({type:"custom",check:"custom",fn:e,...o})}function TS(t,e,r){return new t({type:"custom",check:"custom",fn:e,...N(r)})}function PS(t,e){let r=DV(o=>(o.addIssue=n=>{if(typeof n=="string")o.issues.push(ld(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(ld(i))}},t(o.value,o)),e);return r}function DV(t,e){let r=new nt({check:"custom",...N(e)});return r._zod.check=t,r}function RS(t){let e=new nt({check:"describe"});return e._zod.onattach=[r=>{let o=wr.get(r)??{};wr.add(r,{...o,description:t})}],e._zod.check=()=>{},e}function CS(t){let e=new nt({check:"meta"});return e._zod.onattach=[r=>{let o=wr.get(r)??{};wr.add(r,{...o,...t})}],e._zod.check=()=>{},e}function OS(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??xd,c=t.Boolean??_d,u=t.String??Va,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 qa(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 Hh(t,...e){for(let r of e)for(let o of Reflect.ownKeys(r))Object.prototype.propertyIsEnumerable.call(r,o)&&vr(t,o,r[o]);return t}function Za(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??wr,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 Xt(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&&Hh(s.schema,c),e.io==="input"&&ln(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 zV(t){return t.replace(/~/g,"~0").replace(/\//g,"~1")}function Wa(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}/${zV(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+zV(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 UV(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;UV(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 LV=new Set(["type","properties","required","additionalProperties"]),jV=["oneOf","anyOf"];function MV(t){let e=t.additionalProperties;return e===void 0||e===!1||typeof e!="object"||e===null?null:Object.keys(e).length?e:null}function HR(t){let e=[];for(let i of t){if(typeof i!="object"||i.type!=="object")return null;for(let s in i)if(!LV.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]??MV(u);l!=null&&(a.some(d=>JSON.stringify(d)===JSON.stringify(l))||a.push(l))}let c=a.length===1?a[0]:HR(a)??{allOf:a};vr(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=MV(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 mme(t){let e=t.allOf;if(!Array.isArray(e)||e.length<2)return;for(let n of LV)if(n in t)return;let r=e.filter(n=>jV.some(i=>Array.isArray(n[i]))),o=null;if(!r.length)o=HR(e);else{let n=r[0],i=jV.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=>HR([...s,c]));if(a.some(c=>!c))return;o={[i]:a}}o&&(delete t.allOf,Hh(t,o))}function Ja(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)):Hh(u,m),Hh(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())UV(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)??[])mme(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)}Hh(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,vr(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:Hd(e,"input",t.processors),output:Hd(e,"output",t.processors)}},enumerable:!1,writable:!1}),a}catch{throw new Error("Error converting schema to JSON.")}}function ln(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 ln(o.element,r);if(o.type==="set")return ln(o.valueType,r);if(o.type==="lazy")return ln(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 ln(o.innerType,r);if(o.type==="intersection")return ln(o.left,r)||ln(o.right,r);if(o.type==="record"||o.type==="map")return ln(o.keyType,r)||ln(o.valueType,r);if(o.type==="pipe")return t._zod.traits.has("$ZodCodec")?!0:ln(o.in,r)||ln(o.out,r);if(o.type==="object"){for(let n in o.shape)if(ln(o.shape[n],r))return!0;return!1}if(o.type==="union"){for(let n of o.options)if(ln(n,r))return!0;return!1}if(o.type==="tuple"){for(let n of o.items)if(ln(n,r))return!0;return!!(o.rest&&ln(o.rest,r))}return!1}var BR=(t,e={})=>r=>{let o=Za({...r,processors:e});return et(t,o),Wa(o,t),Ja(o,t)},Hd=(t,e,r={})=>o=>{let{libraryOptions:n,target:i}=o??{},s=Za({...n??{},target:i,io:e,processors:r});return et(t,s),Wa(s,t),Ja(s,t)};var Bd=(t,e,r)=>{(t[e]===void 0||r>t[e])&&(t[e]=r)},Kd=(t,e,r)=>{(t[e]===void 0||r<t[e])&&(t[e]=r)},FV=(t,e)=>{Bd(t,"minimum",e),Kd(t,"maximum",e)},KV=(t,e)=>{t.multipleOf??(t.multipleOf=[]),t.multipleOf.includes(e)||t.multipleOf.push(e)},qV=(t,e)=>{t.patterns??(t.patterns=new Set),t.patterns.add(e)},ZV=(t,e)=>{t.mime=t.mime?t.mime.filter(r=>e.includes(r)):[...e]},WV=(t,e)=>{t.format=e,e.includes("int")&&(t.isInt=!0)},VV=(t,e)=>Bd(t,"minimum",e.minimum),HV=(t,e)=>Kd(t,"maximum",e.maximum),BV=t=>(e,r)=>{WV(e,r.format);let[o,n]=t[r.format];Bd(e,"minimum",o),Kd(e,"maximum",n)},hme={greater_than:(t,e)=>Bd(t,e.inclusive?"minimum":"exclusiveMinimum",e.value),less_than:(t,e)=>Kd(t,e.inclusive?"maximum":"exclusiveMaximum",e.value),multiple_of:(t,e)=>KV(t,e.value),number_format:BV(qm),bigint_format:BV(Zm),min_length:VV,max_length:HV,length_equals:(t,e)=>FV(t,e.length),min_size:VV,max_size:HV,size_equals:(t,e)=>FV(t,e.size),string_format:(t,e)=>{WV(t,e.format),e.pattern&&qV(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)=>ZV(t,e.mime)};function Yt(t){let e={},r=t._zod.def,o=t._zod.traits.has("$ZodCheck")?[t,...r.checks??[]]:r.checks??[];for(let i of o)hme[i._zod.def.check]?.(e,i._zod.def);let n=t._zod.bag;n.minimum!==void 0&&Bd(e,"minimum",n.minimum),n.exclusiveMinimum!==void 0&&Bd(e,"exclusiveMinimum",n.exclusiveMinimum),n.maximum!==void 0&&Kd(e,"maximum",n.maximum),n.exclusiveMaximum!==void 0&&Kd(e,"exclusiveMaximum",n.exclusiveMaximum),n.multipleOf!==void 0&&KV(e,n.multipleOf),n.format!==void 0&&(e.format??(e.format=n.format),n.format.includes("int")&&(e.isInt=!0)),n.mime&&ZV(e,n.mime);for(let i of n.patterns??[])qV(e,i);return e}var gme={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},yme=new Map([[qb,TP],[ch,PP]]),JV=t=>yme.get(t)??t,ZR=(t,e,r,o)=>{let n=r;n.type="string";let{minimum:i,maximum:s,format:a,patterns:c,contentEncoding:u,laxFormat:l}=Yt(t);if(typeof i=="number"&&(n.minLength=i),typeof s=="number"&&(n.maxLength=s),a&&(n.format=gme[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(JV);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}))])}},WR=(t,e,r,o)=>{let n=r,{minimum:i,maximum:s,multipleOf:a,exclusiveMaximum:c,exclusiveMinimum:u,isInt:l}=Yt(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)):Xt(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}))])}},JR=(t,e,r,o)=>{r.type="boolean"},GR=(t,e,r,o)=>{Xt(t,e,r,o,"BigInt cannot be represented in JSON Schema")},XR=(t,e,r,o)=>{Xt(t,e,r,o,"Symbols cannot be represented in JSON Schema")},YR=(t,e,r,o)=>{e.target==="openapi-3.0"?(r.type="string",r.nullable=!0,r.enum=[null]):r.type="null"},QR=(t,e,r,o)=>{Xt(t,e,r,o,"Undefined cannot be represented in JSON Schema")},eC=(t,e,r,o)=>{Xt(t,e,r,o,"Void cannot be represented in JSON Schema")},tC=(t,e,r,o)=>{r.not={}},rC=(t,e,r,o)=>{},nC=(t,e,r,o)=>{},oC=(t,e,r,o)=>{Xt(t,e,r,o,"Date cannot be represented in JSON Schema")},iC=(t,e,r,o)=>{let n=t._zod.def,i=od(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},sC=(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(Xt(t,e,r,o,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof s=="bigint"){if(Xt(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},aC=(t,e,r,o)=>{Xt(t,e,r,o,"NaN cannot be represented in JSON Schema")},cC=(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},uC=(t,e,r,o)=>{let n=r;n.type="string",n.format="binary",n.contentEncoding="binary";let{minimum:i,maximum:s,mime:a}=Yt(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})))},lC=(t,e,r,o)=>{r.type="boolean"},dC=(t,e,r,o)=>{Xt(t,e,r,o,"Custom types cannot be represented in JSON Schema")},pC=(t,e,r,o)=>{Xt(t,e,r,o,"Function types cannot be represented in JSON Schema")},fC=(t,e,r,o)=>{Xt(t,e,r,o,"Transforms cannot be represented in JSON Schema")},mC=(t,e,r,o)=>{Xt(t,e,r,o,"Map cannot be represented in JSON Schema")},hC=(t,e,r,o)=>{Xt(t,e,r,o,"Set cannot be represented in JSON Schema")},gC=(t,e,r,o)=>{let n=r,i=t._zod.def,{minimum:s,maximum:a}=Yt(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 Bh(t){let e=t._zod.def;return e.type==="pipe"&&e.in._zod.traits.has("$ZodTransform")?Bh(e.out):e.type==="catch"?Bh(e.innerType):t._zod.optin}var yC=(t,e,r,o)=>{let n=r,i=t._zod.def,s=i.shape;if(Object.getOwnPropertySymbols(s).length&&Xt(t,e,n,o,"Symbol keys cannot be represented in JSON Schema"))return;n.type="object",n.properties={};for(let u in s)vr(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"?Bh(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)},DS=(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},vC=(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)},wC=(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"?Bh(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}=Yt(t);typeof p=="number"&&(n.minItems=p),typeof m=="number"&&(n.maxItems=m)};function KR(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=KR(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=>KR(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")?ta:th).source)),p}var qR=new WeakMap;function vme(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 qR.get(t)??[]){let n=t.seen.get(o),i=(n?.def??n?.schema)?.propertyNames;if(!i||i===!0||r.has(i))continue;let s=KR(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 bC=(t,e,r,o)=>{let n=r,i=t._zod.def;n.type="object";let s=i.keyType,a=Yt(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)vr(n.patternProperties,JV(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=qR.get(e);l||(l=[],qR.set(e,l),e.deferred.push(()=>vme(e))),l.push(t)}n.additionalProperties=et(i.valueType,e,{...o,path:[...o.path,"additionalProperties"]})}let c=s._zod.values,u=e.io==="input"&&Bh(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))}},_C=(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"}]},SC=(t,e,r,o)=>{let n=t._zod.def;et(n.innerType,e,o);let i=e.seen.get(t);i.ref=n.innerType},xC=Symbol();function GV(t,e,r,o,n){let i=!1,s=JSON.stringify(t,(a,c)=>typeof c!="bigint"?c:(i=!0,null));return i?(Xt(e,r,o,n,"BigInt defaults cannot be represented in JSON Schema"),xC):JSON.parse(s)}var EC=(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=GV(n.defaultValue,t,e,r,o);s!==xC&&(r.default=s)},kC=(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=GV(n.defaultValue,t,e,r,o);s!==xC&&(r._prefault=s)},IC=(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{Xt(t,e,r,o,"Dynamic catch values are not supported in JSON Schema");return}r.default=s},$C=(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},AC=(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},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},zS=(t,e,r,o)=>{let n=t._zod.def;et(n.innerType,e,o);let i=e.seen.get(t);i.ref=n.innerType},PC=(t,e,r,o)=>{let n=t._zod.innerType;et(n,e,o);let i=e.seen.get(t);i.ref=n},NS={string:ZR,number:WR,boolean:JR,bigint:GR,symbol:XR,null:YR,undefined:QR,void:eC,never:tC,any:rC,unknown:nC,date:oC,enum:iC,literal:sC,nan:aC,template_literal:cC,file:uC,success:lC,custom:dC,function:pC,transform:fC,map:mC,set:hC,array:gC,object:yC,union:DS,intersection:vC,tuple:wC,record:bC,nullable:_C,nonoptional:SC,default:EC,prefault:kC,catch:IC,pipe:$C,readonly:AC,promise:TC,optional:zS,lazy:PC};function Lu(t,e){if("_idmap"in t){let o=t,n=Za({...e,processors:NS}),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;Wa(n,l),vr(s,u,Ja(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=Za({...e,processors:NS});return et(t,r),Wa(r,t),Ja(r,t)}var jS=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=Za({processors:NS,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,Wa(this.ctx,e);let o=Ja(this.ctx,e),{"~standard":n,...i}=o;return i}};var XV={};var Qd={};yt(Qd,{ZodAny:()=>JC,ZodArray:()=>QC,ZodBase64:()=>rx,ZodBase64URL:()=>nx,ZodBigInt:()=>Xd,ZodBigIntFormat:()=>sx,ZodBoolean:()=>Gd,ZodCIDRv4:()=>ex,ZodCIDRv6:()=>tx,ZodCUID:()=>ZS,ZodCUID2:()=>WS,ZodCatch:()=>vO,ZodCodec:()=>Qh,ZodCreditCard:()=>BC,ZodCustom:()=>eg,ZodCustomStringFormat:()=>Vu,ZodDate:()=>Wh,ZodDefault:()=>pO,ZodDiscriminatedUnion:()=>tO,ZodE164:()=>ox,ZodEmail:()=>HS,ZodEmoji:()=>KS,ZodEnum:()=>Zd,ZodExactOptional:()=>ux,ZodFile:()=>cO,ZodFunction:()=>AO,ZodGUID:()=>BS,ZodIBAN:()=>KC,ZodIPv4:()=>YS,ZodIPv6:()=>QS,ZodISODate:()=>Xa,ZodISODateTime:()=>Ga,ZodISODuration:()=>Qa,ZodISOTime:()=>Ya,ZodInstanceOf:()=>RO,ZodIntersection:()=>rO,ZodJWT:()=>ix,ZodKSUID:()=>XS,ZodLazy:()=>kO,ZodLiteral:()=>aO,ZodMAC:()=>HC,ZodMap:()=>iO,ZodNaN:()=>bO,ZodNanoID:()=>qS,ZodNever:()=>XC,ZodNonOptional:()=>lx,ZodNull:()=>WC,ZodNullable:()=>dO,ZodNumber:()=>Jd,ZodNumberFormat:()=>Hu,ZodObject:()=>Jh,ZodOptional:()=>Bu,ZodPipe:()=>Yh,ZodPrefault:()=>mO,ZodPreprocess:()=>_O,ZodPromise:()=>$O,ZodReadonly:()=>SO,ZodRecord:()=>qd,ZodSet:()=>sO,ZodString:()=>Wd,ZodStringFormat:()=>it,ZodSuccess:()=>yO,ZodSymbol:()=>qC,ZodTemplateLiteral:()=>EO,ZodTransform:()=>uO,ZodTuple:()=>nO,ZodType:()=>ge,ZodULID:()=>JS,ZodURL:()=>qh,ZodUUID:()=>Xi,ZodUndefined:()=>ZC,ZodUnion:()=>Gh,ZodUnknown:()=>GC,ZodVoid:()=>YC,ZodXID:()=>GS,ZodXor:()=>eO,_ZodString:()=>VS,_default:()=>fO,_function:()=>iB,any:()=>LH,array:()=>Ae,base64:()=>bH,base64url:()=>_H,bigint:()=>DH,boolean:()=>Vt,catch:()=>wO,check:()=>sB,cidrv4:()=>vH,cidrv6:()=>wH,codec:()=>tB,creditCard:()=>xH,cuid:()=>lH,cuid2:()=>dH,currencyCode:()=>TH,custom:()=>dx,date:()=>VH,describe:()=>aB,discriminatedUnion:()=>Xh,e164:()=>SH,email:()=>eH,emoji:()=>cH,enum:()=>_r,exactOptional:()=>lO,file:()=>XH,float32:()=>RH,float64:()=>CH,function:()=>iB,guid:()=>tH,hash:()=>PH,hex:()=>AH,hostname:()=>$H,httpUrl:()=>aH,iban:()=>EH,instanceof:()=>uB,int:()=>LS,int32:()=>OH,int64:()=>zH,intersection:()=>Yd,invertCodec:()=>rB,ipv4:()=>hH,ipv6:()=>yH,json:()=>dB,jwt:()=>kH,keyof:()=>HH,ksuid:()=>mH,lazy:()=>IO,literal:()=>G,looseObject:()=>br,looseRecord:()=>ZH,mac:()=>gH,map:()=>WH,meta:()=>cB,nan:()=>eB,nanoid:()=>uH,nativeEnum:()=>GH,never:()=>ax,nonoptional:()=>gO,null:()=>Zh,nullable:()=>Kh,nullish:()=>YH,number:()=>Ze,object:()=>H,optional:()=>ot,partialRecord:()=>qH,pipe:()=>FS,prefault:()=>hO,preprocess:()=>tg,promise:()=>oB,readonly:()=>xO,record:()=>st,refine:()=>TO,set:()=>JH,strictObject:()=>BH,string:()=>I,stringFormat:()=>IH,stringbool:()=>lB,success:()=>QH,superRefine:()=>PO,symbol:()=>MH,templateLiteral:()=>nB,transform:()=>cx,tuple:()=>oO,uint32:()=>NH,uint64:()=>jH,ulid:()=>pH,undefined:()=>UH,union:()=>tt,unknown:()=>ut,url:()=>sH,uuid:()=>rH,uuidv4:()=>nH,uuidv6:()=>oH,uuidv7:()=>iH,void:()=>FH,xid:()=>fH,xor:()=>KH});var MS={};yt(MS,{endsWith:()=>Dd,gt:()=>Ji,gte:()=>Kn,includes:()=>Od,length:()=>Uu,lowercase:()=>Rd,lt:()=>Wi,lte:()=>Bn,maxLength:()=>Mu,maxSize:()=>Ka,mime:()=>jd,minLength:()=>ra,minSize:()=>Gi,multipleOf:()=>Ba,negative:()=>xS,nonnegative:()=>kS,nonpositive:()=>ES,normalize:()=>Md,overwrite:()=>Qo,positive:()=>SS,properties:()=>zd,property:()=>IS,regex:()=>Pd,size:()=>ju,slugify:()=>Vd,startsWith:()=>Nd,toLowerCase:()=>Ld,toUpperCase:()=>Fd,trim:()=>Ud,uppercase:()=>Cd});var YV=new WeakSet([Object.prototype,Error.prototype]);function US(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 QV=(t,e)=>{uP.init(t,e),t.name="ZodError";let r=Object.getPrototypeOf(t);YV.has(r)||(YV.add(r),US(r,"format",o=>n=>Qm(o,n)),US(r,"flatten",o=>n=>Ym(o,n)),US(r,"addIssue",o=>n=>{o.issues.push(n),o.message=JSON.stringify(o.issues,id,2)}),US(r,"addIssues",o=>n=>{o.issues.push(...n),o.message=JSON.stringify(o.issues,id,2)}),Object.defineProperty(r,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},bme=S("ZodError",QV),An=S("ZodError",QV,void 0,{Parent:Error});var RC=dd(An),CC=pd(An),OC=fd(An),NC=hd(An),DC=ab(An),zC=cb(An),jC=ub(An),MC=lb(An),UC=db(An),LC=pb(An),FC=fb(An),VC=mb(An);function Sme(){cr.localeError||zt(K_())}function Fu(){cr.memoizer||zt({memoizer:gh()})}var ge=S("ZodType",(t,e)=>(Sme(),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(TO(t,e))},superRefine(t,e){return this.check(PO(t,e))},overwrite(t){return this.check(Qo(t))},optional(){return ot(this)},exactOptional(){return lO(this)},nullable(){return Kh(this)},nullish(){return ot(Kh(this))},nonoptional(t){return gO(this,t)},array(){return Ae(this)},or(t){return tt([this,t])},and(t){return Yd(this,t)},transform(t){return FS(this,cx(t))},default(t){return fO(this,t)},prefault(t){return hO(this,t)},catch(t){return wO(this,t)},pipe(t){return FS(this,t)},readonly(){return xO(this)},describe(t){let e=this.clone();return wr.add(e,{description:t}),e},meta(...t){if(t.length===0)return wr.get(this);let e=this.clone();return wr.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",{...kb(this),jsonSchema:{input:Hd(this,"input"),output:Hd(this,"output")}})},set"~standard"(t){A.own(this,"~standard",t)},parse:function t(e,r){return RC(this,e,r,{callee:t})},parseAsync:async function t(e,r){return await CC(this,e,r,{callee:t})},safeParse(t,e){return OC(this,t,e)},async safeParseAsync(t,e){return NC(this,t,e)},get spa(){return this?.safeParseAsync},set spa(t){A.own(this,"spa",t)},validate(t,e){return yd(this,t,e)},validateAsync(t,e){return vd(this,t,e)},encode:function t(e,r){return DC(this,e,r,{callee:t})},decode:function t(e,r){return zC(this,e,r,{callee:t})},encodeAsync:async function t(e,r){return await jC(this,e,r,{callee:t})},decodeAsync:async function t(e,r){return await MC(this,e,r,{callee:t})},safeEncode(t,e){return UC(this,t,e)},safeDecode(t,e){return LC(this,t,e)},async safeEncodeAsync(t,e){return FC(this,t,e)},async safeDecodeAsync(t,e){return VC(this,t,e)},toJSONSchema(t){return BR(this,{})(t)},get description(){return wr.get(this)?.description},get _def(){return this._zod.def}}),VS=S("_ZodString",(t,e)=>{Va.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>ZR(t,r,o,n)},A.derived({format:t=>Yt(t).format??null,minLength:t=>Yt(t).minimum??null,maxLength:t=>Yt(t).maximum??null},{regex(...t){return this.check(Pd(...t))},includes(...t){return this.check(Od(...t))},startsWith(...t){return this.check(Nd(...t))},endsWith(...t){return this.check(Dd(...t))},min(...t){return this.check(ra(...t))},max(...t){return this.check(Mu(...t))},length(...t){return this.check(Uu(...t))},nonempty(...t){return this.check(ra(1,...t))},lowercase(t){return this.check(Rd(t))},uppercase(t){return this.check(Cd(t))},trim(){return this.check(Ud())},normalize(...t){return this.check(Md(...t))},toLowerCase(){return this.check(Ld())},toUpperCase(){return this.check(Fd())},slugify(){return this.check(Vd())}})),Wd=S("ZodString",(t,e)=>{Va.init(t,e),VS.init(t,e)},{email(t){return this.check(vh(HS,t))},url(t){return this.check(Td(qh,t))},jwt(t){return this.check(Mh(ix,t))},emoji(t){return this.check(Eh(KS,t))},guid(t){return this.check(wh(BS,t))},uuid(t){return this.check(bh(Xi,t))},uuidv4(t){return this.check(_h(Xi,t))},uuidv6(t){return this.check(Sh(Xi,t))},uuidv7(t){return this.check(xh(Xi,t))},nanoid(t){return this.check(kh(qS,t))},cuid(t){return this.check(Ih(ZS,t))},cuid2(t){return this.check($h(WS,t))},ulid(t){return this.check(Ah(JS,t))},base64(t){return this.check(Dh(rx,t))},base64url(t){return this.check(zh(nx,t))},xid(t){return this.check(Th(GS,t))},ksuid(t){return this.check(Ph(XS,t))},ipv4(t){return this.check(Rh(YS,t))},ipv6(t){return this.check(Ch(QS,t))},cidrv4(t){return this.check(Oh(ex,t))},cidrv6(t){return this.check(Nh(tx,t))},e164(t){return this.check(jh(ox,t))},datetime(t){return this.check(Uh(Ga,t))},date(t){return this.check(Lh(Xa,t))},time(t){return this.check(Fh(Ya,t))},duration(t){return this.check(Vh(Qa,t))}});function I(t){return Q_(Wd,t)}var it=S("ZodStringFormat",(t,e)=>{Je.init(t,e),VS.init(t,e)}),Ga=S("ZodISODateTime",(t,e)=>{vR.init(t,e),it.init(t,e)}),Xa=S("ZodISODate",(t,e)=>{wR.init(t,e),it.init(t,e)}),Ya=S("ZodISOTime",(t,e)=>{bR.init(t,e),it.init(t,e)}),Qa=S("ZodISODuration",(t,e)=>{_R.init(t,e),it.init(t,e)}),HS=S("ZodEmail",(t,e)=>{Ab.init(t,e),it.init(t,e)});function eH(t){return vh(HS,t)}var BS=S("ZodGUID",(t,e)=>{Ib.init(t,e),it.init(t,e)});function tH(t){return wh(BS,t)}var Xi=S("ZodUUID",(t,e)=>{$b.init(t,e),it.init(t,e)});function rH(t){return bh(Xi,t)}function nH(t){return _h(Xi,t)}function oH(t){return Sh(Xi,t)}function iH(t){return xh(Xi,t)}var qh=S("ZodURL",(t,e)=>{Cb.init(t,e),it.init(t,e)});function sH(t){return Td(qh,t)}function aH(t){return Td(qh,{protocol:eh,hostname:CP,...A.normalizeParams(t)})}var KS=S("ZodEmoji",(t,e)=>{Ob.init(t,e),it.init(t,e)});function cH(t){return Eh(KS,t)}var qS=S("ZodNanoID",(t,e)=>{Nb.init(t,e),it.init(t,e)});function uH(t){return kh(qS,t)}var ZS=S("ZodCUID",(t,e)=>{Db.init(t,e),it.init(t,e)});function lH(t){return Ih(ZS,t)}var WS=S("ZodCUID2",(t,e)=>{zb.init(t,e),it.init(t,e)});function dH(t){return $h(WS,t)}var JS=S("ZodULID",(t,e)=>{jb.init(t,e),it.init(t,e)});function pH(t){return Ah(JS,t)}var GS=S("ZodXID",(t,e)=>{Mb.init(t,e),it.init(t,e)});function fH(t){return Th(GS,t)}var XS=S("ZodKSUID",(t,e)=>{Ub.init(t,e),it.init(t,e)});function mH(t){return Ph(XS,t)}var YS=S("ZodIPv4",(t,e)=>{Lb.init(t,e),it.init(t,e)});function hH(t){return Rh(YS,t)}var HC=S("ZodMAC",(t,e)=>{Vb.init(t,e),it.init(t,e)});function gH(t){return eS(HC,t)}var QS=S("ZodIPv6",(t,e)=>{Fb.init(t,e),it.init(t,e)});function yH(t){return Ch(QS,t)}var ex=S("ZodCIDRv4",(t,e)=>{Hb.init(t,e),it.init(t,e)});function vH(t){return Oh(ex,t)}var tx=S("ZodCIDRv6",(t,e)=>{Kb.init(t,e),it.init(t,e)});function wH(t){return Nh(tx,t)}var rx=S("ZodBase64",(t,e)=>{Zb.init(t,e),it.init(t,e)});function bH(t){return Dh(rx,t)}var nx=S("ZodBase64URL",(t,e)=>{Jb.init(t,e),it.init(t,e)});function _H(t){return zh(nx,t)}var ox=S("ZodE164",(t,e)=>{Gb.init(t,e),it.init(t,e)});function SH(t){return jh(ox,t)}var BC=S("ZodCreditCard",(t,e)=>{Yb.init(t,e),it.init(t,e)});function xH(t){return tS(BC,t)}var KC=S("ZodIBAN",(t,e)=>{e_.init(t,e),it.init(t,e)});function EH(t){return rS(KC,t)}var ix=S("ZodJWT",(t,e)=>{r_.init(t,e),it.init(t,e)});function kH(t){return Mh(ix,t)}var Vu=S("ZodCustomStringFormat",(t,e)=>{n_.init(t,e),it.init(t,e)});function IH(t,e,r={}){return qa(Vu,t,e,r)}function $H(t){return qa(Vu,"hostname",RP,t)}function AH(t){return qa(Vu,"hex",qP,t)}function TH(t){return qa(Vu,"currency_code",NP,t)}function PH(t,e){let r=e?.enc??"hex",o=`${t}_${r}`,n=Hn[o];if(!n)throw new Error(`Unrecognized hash format: ${o}`);return qa(Vu,o,n,e)}var Jd=S("ZodNumber",(t,e)=>{uh.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>WR(t,r,o,n),t.isFinite=!0},A.derived({minValue:t=>{let{minimum:e,exclusiveMinimum:r}=Yt(t);return Math.max(e??Number.NEGATIVE_INFINITY,r??Number.NEGATIVE_INFINITY)},maxValue:t=>{let{maximum:e,exclusiveMaximum:r}=Yt(t);return Math.min(e??Number.POSITIVE_INFINITY,r??Number.POSITIVE_INFINITY)},isInt:t=>{let{isInt:e,multipleOf:r}=Yt(t);return!!e||!!r?.some(Number.isSafeInteger)},format:t=>Yt(t).format??null},{gt(t,e){return this.check(Ji(t,e))},gte(t,e){return this.check(Kn(t,e))},min(t,e){return this.check(Kn(t,e))},lt(t,e){return this.check(Wi(t,e))},lte(t,e){return this.check(Bn(t,e))},max(t,e){return this.check(Bn(t,e))},int(t){return this.check(LS(t))},safe(t){return this.check(LS(t))},positive(t){return this.check(Ji(0,t))},nonnegative(t){return this.check(Kn(0,t))},negative(t){return this.check(Wi(0,t))},nonpositive(t){return this.check(Bn(0,t))},multipleOf(t,e){return this.check(Ba(t,e))},step(t,e){return this.check(Ba(t,e))},finite(){return this}}));function Ze(t){return nS(Jd,t)}var Hu=S("ZodNumberFormat",(t,e)=>{o_.init(t,e),Jd.init(t,e)});function LS(t){return oS(Hu,t)}function RH(t){return iS(Hu,t)}function CH(t){return sS(Hu,t)}function OH(t){return aS(Hu,t)}function NH(t){return cS(Hu,t)}var Gd=S("ZodBoolean",(t,e)=>{_d.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>JR(t,r,o,n)});function Vt(t){return uS(Gd,t)}var Xd=S("ZodBigInt",(t,e)=>{lh.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>GR(t,r,o,n)},A.derived({minValue:t=>Yt(t).minimum??null,maxValue:t=>Yt(t).maximum??null,format:t=>Yt(t).format??null},{gte(t,e){return this.check(Kn(t,e))},min(t,e){return this.check(Kn(t,e))},gt(t,e){return this.check(Ji(t,e))},lt(t,e){return this.check(Wi(t,e))},lte(t,e){return this.check(Bn(t,e))},max(t,e){return this.check(Bn(t,e))},positive(t){return this.check(Ji(BigInt(0),t))},negative(t){return this.check(Wi(BigInt(0),t))},nonpositive(t){return this.check(Bn(BigInt(0),t))},nonnegative(t){return this.check(Kn(BigInt(0),t))},multipleOf(t,e){return this.check(Ba(t,e))}}));function DH(t){return lS(Xd,t)}var sx=S("ZodBigIntFormat",(t,e)=>{i_.init(t,e),Xd.init(t,e)});function zH(t){return dS(sx,t)}function jH(t){return pS(sx,t)}var qC=S("ZodSymbol",(t,e)=>{s_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>XR(t,r,o,n)});function MH(t){return fS(qC,t)}var ZC=S("ZodUndefined",(t,e)=>{a_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>QR(t,r,o,n)});function UH(t){return mS(ZC,t)}var WC=S("ZodNull",(t,e)=>{c_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>YR(t,r,o,n)});function Zh(t){return hS(WC,t)}var JC=S("ZodAny",(t,e)=>{u_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>rC(t,r,o,n)});function LH(){return gS(JC)}var GC=S("ZodUnknown",(t,e)=>{l_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>nC(t,r,o,n)});function ut(){return yS(GC)}var XC=S("ZodNever",(t,e)=>{d_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>tC(t,r,o,n)});function ax(t){return vS(XC,t)}var YC=S("ZodVoid",(t,e)=>{p_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>eC(t,r,o,n)});function FH(t){return wS(YC,t)}var Wh=S("ZodDate",(t,e)=>{f_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>oC(t,r,o,n),t.min=(r,o)=>t.check(Kn(r,o)),t.max=(r,o)=>t.check(Bn(r,o))},A.derived({minDate:t=>{let{minimum:e}=Yt(t);return e?new Date(e):null},maxDate:t=>{let{maximum:e}=Yt(t);return e?new Date(e):null}},{}));function VH(t){return bS(Wh,t)}var QC=S("ZodArray",(t,e)=>{Fu(),m_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>gC(t,r,o,n),t.element=e.element},{min(t,e){return this.check(ra(t,e))},nonempty(t){return this.check(ra(1,t))},max(t,e){return this.check(Mu(t,e))},length(t,e){return this.check(Uu(t,e))},unwrap(){return this.element}});function Ae(t,e){return VR(QC,t,e)}function HH(t){let e=t._zod.def.shape;return _r(Object.keys(e))}var Jh=S("ZodObject",(t,e)=>{Fu(),xR.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>yC(t,r,o,n),A.installLazyProp(t,"shape",r=>r._zod.def.shape,!1)},{keyof(){return _r(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:ut()}))},loose(){return this.clone(A.mergeDefs(this._zod.def,{catchall:ut()}))},strict(){return this.clone(A.mergeDefs(this._zod.def,{catchall:ax()}))},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(Bu,this,t[0])},exactPartial(...t){return A.partial(ux,this,t[0],"exactPartial")},required(...t){return A.required(lx,this,t[0])}});function H(t,e){let r={type:"object",shape:t??{},...A.normalizeParams(e)};return new Jh(r)}function BH(t,e){return new Jh({type:"object",shape:t,catchall:ax(),...A.normalizeParams(e)})}function br(t,e){return new Jh({type:"object",shape:t,catchall:ut(),...A.normalizeParams(e)})}var Gh=S("ZodUnion",(t,e)=>{Sd.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>DS(t,r,o,n),t.options=e.options});function tt(t,e){return new Gh({type:"union",options:t,...A.normalizeParams(e)})}var eO=S("ZodXor",(t,e)=>{Gh.init(t,e),g_.init(t,e),t._zod.processJSONSchema=(r,o,n)=>DS(t,r,o,n),t.options=e.options});function KH(t,e){return new eO({type:"union",options:t,inclusive:!1,...A.normalizeParams(e)})}var tO=S("ZodDiscriminatedUnion",(t,e)=>{Gh.init(t,e),y_.init(t,e)});function Xh(t,e,r){return new tO({type:"union",options:e,discriminator:t,...A.normalizeParams(r)})}var rO=S("ZodIntersection",(t,e)=>{v_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>vC(t,r,o,n)});function Yd(t,e){return new rO({type:"intersection",left:t,right:e})}var nO=S("ZodTuple",(t,e)=>{Fu(),dh.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>wC(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 Bu({type:"optional",innerType:e}))})}});function oO(t,e,r){let o=e instanceof ae,n=o?r:e,i=o?e:null;return new nO({type:"tuple",items:t,rest:i,...A.normalizeParams(n)})}var qd=S("ZodRecord",(t,e)=>{Fu(),w_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>bC(t,r,o,n),t.keyType=e.keyType,t.valueType=e.valueType});function st(t,e,r){return!e||!e._zod?new qd({type:"record",keyType:I(),valueType:t,...A.normalizeParams(e)}):new qd({type:"record",keyType:t,valueType:e,...A.normalizeParams(r)})}function qH(t,e,r){return new qd({type:"record",keyType:t,valueType:e,...A.normalizeParams(r),partial:!0})}function ZH(t,e,r){return new qd({type:"record",keyType:t,valueType:e,mode:"loose",...A.normalizeParams(r)})}var iO=S("ZodMap",(t,e)=>{Fu(),b_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>mC(t,r,o,n),t.keyType=e.keyType,t.valueType=e.valueType,t.min=(...r)=>t.check(Gi(...r)),t.nonempty=r=>t.check(Gi(1,r)),t.max=(...r)=>t.check(Ka(...r)),t.size=(...r)=>t.check(ju(...r))});function WH(t,e,r){return new iO({type:"map",keyType:t,valueType:e,...A.normalizeParams(r)})}var sO=S("ZodSet",(t,e)=>{Fu(),__.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>hC(t,r,o,n),t.min=(...r)=>t.check(Gi(...r)),t.nonempty=r=>t.check(Gi(1,r)),t.max=(...r)=>t.check(Ka(...r)),t.size=(...r)=>t.check(ju(...r))});function JH(t,e){return new sO({type:"set",valueType:t,...A.normalizeParams(e)})}var Zd=S("ZodEnum",(t,e)=>{S_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(o,n,i)=>iC(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 Zd({...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 Zd({...e,checks:[],...A.normalizeParams(n),entries:i})}});function _r(t,e){let r=Array.isArray(t)?Object.fromEntries(t.map(o=>[o,o])):t;return new Zd({type:"enum",entries:r,...A.normalizeParams(e)})}function GH(t,e){return new Zd({type:"enum",entries:t,...A.normalizeParams(e)})}var aO=S("ZodLiteral",(t,e)=>{x_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>sC(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 aO({type:"literal",values:Array.isArray(t)?t:[t],...A.normalizeParams(e)})}var cO=S("ZodFile",(t,e)=>{E_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>uC(t,r,o,n),t.min=(r,o)=>t.check(Gi(r,o)),t.max=(r,o)=>t.check(Ka(r,o)),t.mime=(r,o)=>t.check(jd(Array.isArray(r)?r:[r],o))});function XH(t){return $S(cO,t)}var uO=S("ZodTransform",(t,e)=>{Fu(),k_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>fC(t,r,o,n),t._zod.parse=(r,o)=>{if(o.direction==="backward")throw new Fa(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 cx(t){return new uO({type:"transform",transform:t})}var Bu=S("ZodOptional",(t,e)=>{ph.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>zS(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function ot(t){return new Bu({type:"optional",innerType:t})}var ux=S("ZodExactOptional",(t,e)=>{I_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>zS(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function lO(t){return new ux({type:"optional",innerType:t})}var dO=S("ZodNullable",(t,e)=>{$_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>_C(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function Kh(t){return new dO({type:"nullable",innerType:t})}function YH(t){return ot(Kh(t))}var pO=S("ZodDefault",(t,e)=>{A_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>EC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType,t.removeDefault=t.unwrap});function fO(t,e){return new pO({type:"default",innerType:t,get defaultValue(){return typeof e=="function"?e():A.shallowClone(e)}})}var mO=S("ZodPrefault",(t,e)=>{T_.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 hO(t,e){return new mO({type:"prefault",innerType:t,get defaultValue(){return typeof e=="function"?e():A.shallowClone(e)}})}var lx=S("ZodNonOptional",(t,e)=>{P_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>SC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function gO(t,e){return new lx({type:"nonoptional",innerType:t,...A.normalizeParams(e)})}var yO=S("ZodSuccess",(t,e)=>{R_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>lC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function QH(t){return new yO({type:"success",innerType:t})}var vO=S("ZodCatch",(t,e)=>{C_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>IC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType,t.removeCatch=t.unwrap});function wO(t,e){return new vO({type:"catch",innerType:t,catchValue:typeof e=="function"?e:A.constantCatch(e)})}var bO=S("ZodNaN",(t,e)=>{O_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>aC(t,r,o,n)});function eB(t){return _S(bO,t)}var Yh=S("ZodPipe",(t,e)=>{fh.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>$C(t,r,o,n),t.in=e.in,t.out=e.out});function FS(t,e){return new Yh({type:"pipe",in:t,out:e})}var Qh=S("ZodCodec",(t,e)=>{Yh.init(t,e),xd.init(t,e)});function tB(t,e,r){return new Qh({type:"pipe",in:t,out:e,transform:r.decode,reverseTransform:r.encode})}function rB(t){let e=t._zod.def;return new Qh({type:"pipe",in:e.out,out:e.in,transform:e.reverseTransform,reverseTransform:e.transform})}var _O=S("ZodPreprocess",(t,e)=>{Yh.init(t,e),kR.init(t,e)}),SO=S("ZodReadonly",(t,e)=>{N_.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 xO(t){return new SO({type:"readonly",innerType:t})}var EO=S("ZodTemplateLiteral",(t,e)=>{D_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>cC(t,r,o,n)});function nB(t,e){return new EO({type:"template_literal",parts:t,...A.normalizeParams(e)})}var kO=S("ZodLazy",(t,e)=>{Ed.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>PC(t,r,o,n),t.unwrap=()=>t._zod.def.getter()});function IO(t){return new kO({type:"lazy",getter:t})}var $O=S("ZodPromise",(t,e)=>{j_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>TC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function oB(t){return new $O({type:"promise",innerType:t})}var AO=S("ZodFunction",(t,e)=>{z_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>pC(t,r,o,n)});function iB(t){return new AO({type:"function",input:Array.isArray(t?.input)?oO(t?.input):t?.input??Ae(ut()),output:t?.output??ut()})}var eg=S("ZodCustom",(t,e)=>{M_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>dC(t,r,o,n)});function sB(t){let e=new nt({check:"custom"});return e._zod.check=t,e}function dx(t,e){return AS(eg,t??(()=>!0),e)}function TO(t,e={}){return TS(eg,t,e)}function PO(t,e){return PS(t,e)}var aB=RS,cB=CS,RO=S("ZodInstanceOf",(t,e)=>{eg.init(t,e)},{properties(t,e){return this.check(zd(t,e))}});function uB(t,e={}){let r=new RO({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 lB=(...t)=>OS({Codec:Qh,Boolean:Gd,String:Wd},...t);function dB(t){let e=IO(()=>tt([I(t),Ze(),Vt(),Zh(),Ae(e),st(I(),e)]));return e}function tg(t,e){return new _O({type:"pipe",in:cx(t),out:e})}var xme={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 Eme(t){zt({customError:t})}function kme(){return zt().customError}var CO;CO||(CO={});var Ku={};yt(Ku,{ZodISODate:()=>Xa,ZodISODateTime:()=>Ga,ZodISODuration:()=>Qa,ZodISOTime:()=>Ya,date:()=>$me,datetime:()=>Ime,duration:()=>Tme,time:()=>Ame});function Ime(t){return Uh(Ga,t)}function $me(t){return Lh(Xa,t)}function Ame(t){return Fh(Ya,t)}function Tme(t){return Vh(Qa,t)}var V={...Qd,...MS,iso:Ku},Pme=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 Rme(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 pB(t,e){return t.map((r,o)=>o<e?r:r.optional())}function Cme(t){return t.replace(/~1/g,"/").replace(/~0/g,"~")}function Ome(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:Cme(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 Nme(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 OO(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=OO(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=OO(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 Dme=new Set(["items","prefixItems","additionalItems","additionalProperties","contains","propertyNames","not","if","then","else","allOf","anyOf","oneOf","unevaluatedItems","unevaluatedProperties","contentSchema"]),zme=new Set(["properties","patternProperties","dependentSchemas","dependencies","$defs","definitions"]);function rg(t){return typeof t!="object"||t===null?!1:Array.isArray(t)?t.some(rg):typeof t.$ref=="string"?!0:Object.entries(t).some(([e,r])=>Dme.has(e)?rg(r):!zme.has(e)||typeof r!="object"||r===null?!1:Object.values(r).some(rg))}function fB(t){return t===1?"element":"elements"}function jme(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=OO(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 ${fB(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 ${fB(e.maxContains)}`,input:n,continue:!0})}}}).pipe(t)}function mB(t,e){if(t!==!1)return t===void 0||t===!0?V.any():dn(t,e)}var Mme=/^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/;function hB(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=Ome(n,e),s=dn(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 hB(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(Mme)):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"?dn(t.additionalProperties,e):void 0;for(let[d,f]of Object.entries(i)){let p=dn(f,e);vr(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=dn(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(!mo(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=dn(f,e)}o=Nme(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=>dn(d,e)),c=pB(a,s),u=Array.isArray(i)?void 0:mB(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=>dn(d,e)),c=pB(a,s),u=mB(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=dn(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=jme(o,{uniqueItems:t.uniqueItems===!0,containsSchema:t.contains!==void 0?dn(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 dn(t,e){if(typeof t=="boolean")return t?V.any():V.never();let r=hB(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=>dn(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=>dn(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:dn(t.allOf[0],e),c=o?0:1;for(let u=c;u<t.allOf.length;u++)a=V.intersection(a,dn(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&&!rg(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&&!rg(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))Pme.has(a)||vr(n,a,t[a]);return Object.keys(n).length>0&&e.registry.add(r,n),t.description&&(r=r.describe(t.description)),r}function gB(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=Rme(r,e?.defaultTarget),n=r.$defs||r.definitions||{},i={version:o,defs:n,refs:new Map,processing:new Set,rootSchema:r,registry:e?.registry??wr};return dn(r,i)}var yB=Symbol("z.visit/resolving");function ng(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===yB)return new Ed({type:"lazy",getter:()=>o.get(s)});if(a!==void 0)return a;o.set(s,yB);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 vB(t){return ng(t,{object:e=>e.partial(),union:e=>{let r=e._zod.def;return r.discriminator===void 0?e:tt(r.options)}})}function Ume(t,e){if(!e?.length)return t;let r=t._zod.def;return qe(t,fo(r,{checks:[...r.checks??[],...e]}),{parent:!0})}function wB(t){return Ume(t.out,t.checks)}function Lme(t){return t.in._zod.traits.has("$ZodTransform")?wB(t):t.in}function bB(t){return ng(t,{pipe:e=>Lme(e._zod.def),default:(e,r)=>r?ot(e._zod.def.innerType):e,catch:(e,r)=>r?e._zod.def.innerType:e})}function _B(t){return ng(t,{pipe:e=>wB(e._zod.def),prefault:(e,r)=>r?e._zod.def.innerType:e})}var NO={};yt(NO,{bigint:()=>Bme,boolean:()=>Hme,date:()=>Kme,number:()=>Vme,string:()=>Fme});function Fme(t){return zR(Wd,t)}function Vme(t){return MR(Jd,t)}function Hme(t){return UR(Gd,t)}function Bme(t){return LR(Xd,t)}function Kme(t){return FR(Wh,t)}var og={name:"@tomato414941/foundation",version:"29.0.1",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 SB(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 ig=h.string().trim().max(8192).refine(t=>SB(t)!==null,"Use an OpenSSH public key from a .pub file.");function DO(t){if(!SB(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 ep=h.string().max(32).regex(/^[a-z_][a-z0-9_-]*$/,"Use a lowercase account name."),px=h.string().min(1).max(253).regex(/^[A-Za-z0-9_.:]+(?:-[A-Za-z0-9_.:]+)*$/,"Use a host name or IP address."),fx=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."),yFe=h.string().min(1).max(500).regex(/^[A-Za-z0-9.:*?/!_-]+(?:,[A-Za-z0-9.:*?/!_-]+)*$/,"Use comma-separated host or address patterns."),mx=h.string().regex(/^SHA256:[A-Za-z0-9+/]{43}$/);var tp=new TextEncoder,rp=new TextDecoder,xB=new TextDecoder("utf-8",{fatal:!0}),hx=2**32;function pn(...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 zO(t,e,r){if(e<0||e>=hx)throw new RangeError(`value must be >= 0 and <= ${hx-1}. Received ${e}`);t.set([e>>>24,e>>>16,e>>>8,e&255],r)}function jO(t){let e=Math.floor(t/hx),r=t%hx,o=new Uint8Array(8);return zO(o,e,0),zO(o,r,4),o}function gx(t){let e=new Uint8Array(4);return zO(e,t),e}var Zme=/[^\x00-\x7f]/;function Sr(t){if(typeof t=="string"&&t.length>=128){if(Zme.test(t))throw new TypeError("non-ASCII string encountered in encode()");return tp.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 EB(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 kB(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 yx(t,e){let r=`SHA-${t.slice(-3)}`;return new Uint8Array(await crypto.subtle.digest(r,e))}var na=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 qu=class extends na{static code="ERR_JOSE_ALG_NOT_ALLOWED";code="ERR_JOSE_ALG_NOT_ALLOWED"},at=class extends na{static code="ERR_JOSE_NOT_SUPPORTED";code="ERR_JOSE_NOT_SUPPORTED"},ec=class extends na{static code="ERR_JWE_DECRYPTION_FAILED";code="ERR_JWE_DECRYPTION_FAILED";constructor(e="decryption operation failed",r){super(e,r)}},U=class extends na{static code="ERR_JWE_INVALID";code="ERR_JWE_INVALID"},xt=class extends na{static code="ERR_JWS_INVALID";code="ERR_JWS_INVALID"};var sg=class extends na{static code="ERR_JWK_INVALID";code="ERR_JWK_INVALID"};var vx=class extends na{static code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";constructor(e="signature verification failed",r){super(e,r)}};var Wme="The input to be decoded is not correctly encoded.";function Zu(t){try{return kB(typeof t=="string"?t:rp.decode(t),!0)}catch(e){throw new TypeError(Wme,{cause:e})}}function Rt(t){return EB(typeof t=="string"?tp.encode(t):t,!0)}function qn(t,e){if(!(t instanceof Uint8Array))throw new TypeError(`${e} must be an instance of Uint8Array`)}function Kt(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 tc(...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 go(t,e){if(t!==void 0)throw new TypeError(`${e} can only be called once`)}function Tn(t,e,r){try{return Zu(t)}catch{throw new r(`Failed to base64url decode the ${e}`)}}function wx(t,e,r){try{return Sr(t)}catch{throw new r(`The ${e} is not a valid base64url string`)}}function np(t,e,r){let o;try{o=JSON.parse(xB.decode(Zu(t)))}catch{throw new e(r)}if(!Kt(o))throw new e(r);return o}var bx={__proto__:null,b64:!0},_x={__proto__:null};function ag(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 Sx(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 rc(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 at(`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 xx(t,e){if(e.includes("b64")){let r=t.b64;if(typeof r!="boolean")throw new xt('The "b64" (base64url-encode payload) Header Parameter must be a boolean');return r}return!0}function Wu(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(!Kt(o))throw new t("JOSE Header is not a JSON object");return[o,r]}var Jme=t=>t[Symbol.toStringTag],Gme=(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 ti(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(Kt(e)){if(s=HO(e),typeof s.kty!="string")throw IB(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(Gme(t,s,r),s.kty==="oct")return Zu(s.k);if(!Object.isFrozen(e)){let{key_ops:l}=e;Array.isArray(l)&&Object.freeze(l),Object.freeze(e)}}else{if(!LO(e))throw IB(o,e,n);let l=n?"secret":i?"private":"public";if(e.type!==l&&(n||["secret","public","private"].includes(e.type)))throw new TypeError(`${Jme(e)} instances must be of type "${l}" for the ${o} algorithm`);if(nc(e))return e;if(a=e,a.type==="secret")return a.export()}MO||=new WeakMap;let c=e,u=MO.get(c);if(u?.[o])return u[o];if(u||MO.set(c,u={}),a&&typeof a.toCryptoKey=="function"){let l=a.type==="public",d=Xme[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 ip(t,s)}var MO,Xme={__proto__:null,prime256v1:"P-256",secp384r1:"P-384",secp521r1:"P-521"};function kx(t){if(!nc(t))throw new Error("CryptoKey instance expected")}var nc=t=>{if(t?.[Symbol.toStringTag]==="CryptoKey")return!0;try{return t instanceof CryptoKey}catch{return!1}},UO=t=>t?.[Symbol.toStringTag]==="KeyObject",LO=t=>nc(t)||UO(t);function $B(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 oa=(t,...e)=>$B("Key must be ",t,...e);function IB(t,e,r){let o=["CryptoKey","KeyObject","JSON Web Key"];return r&&o.push("Uint8Array"),new TypeError($B(`Key for the ${t} algorithm must be `,e,...o))}var Ex=(t,e="algorithm.name")=>new TypeError(`CryptoKey does not support this operation, its ${e} must be ${t}`);function FO(t,e){if(e&&!t.usages.includes(e))throw new TypeError(`CryptoKey does not support this operation, its usages must include ${e}.`)}function op(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 VO(t,e,r){let o=t.algorithm;if(o.name!==e.name)throw Ex(e.name);if(e.hash&&o.hash?.name!==e.hash)throw Ex(e.hash,"algorithm.hash");if(e.namedCurve&&o.namedCurve!==e.namedCurve)throw Ex(e.namedCurve,"algorithm.namedCurve");if(e.length!==void 0&&o.length!==e.length)throw Ex(e.length,"algorithm.length");FO(t,r)}function Ix(t){return{__proto__:null,...t}}function HO(t){let e=Ix(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 $x(t){if(t!==void 0&&typeof t!="boolean")throw new TypeError('"extractable" option must be a boolean');return t}async function ip(t,e,r){if(!t.kty.includes(e.kty))throw new at('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 ri(t,e,r,o=!1){return t instanceof Uint8Array&&(t=await crypto.subtle.importKey("raw",t,e,o,[r])),VO(t,e,r),t}var Ju=t=>crypto.getRandomValues(new Uint8Array(t.cekBits>>3));function Ax(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 Yme=t=>crypto.getRandomValues(new Uint8Array(t.ivBits>>3));function AB(t,e){if(e.length<<3!==t.ivBits)throw new U("Invalid Initialization Vector length")}async function TB(t,e,r){if(!(e instanceof Uint8Array))throw new TypeError(oa(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 PB(t,e,r){return new Uint8Array((await crypto.subtle.sign("HMAC",t,e)).slice(0,r>>3))}async function Qme(t,e,r,o,n){let[i,s,a]=await TB(t,r,"encrypt"),c=new Uint8Array(await crypto.subtle.encrypt({iv:o,name:"AES-CBC"},i,e)),u=pn(n,o,c,jO(n.length*8)),l=await PB(s,u,a);return{ciphertext:c,tag:l,iv:o}}async function ehe(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 the(t,e,r,o,n,i){let[s,a,c]=await TB(t,e,"decrypt"),u=pn(i,o,r,jO(i.length*8)),l=await PB(a,u,c);try{if(await ehe(n,l))return new Uint8Array(await crypto.subtle.decrypt({iv:o,name:"AES-CBC"},s,r))}catch{}throw new ec}async function Tx(t,e,r,o,n){if(!nc(r)&&!(r instanceof Uint8Array))throw new TypeError(oa(r,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(o?AB(t,o):o=Yme(t),r instanceof Uint8Array&&Ax(r,t.cekBits),t.cbc)return Qme(t,e,r,o,n);let i=await ri(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 Px(t,e,r,o,n,i){if(!nc(e)&&!(e instanceof Uint8Array))throw new TypeError(oa(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(AB(t,o),e instanceof Uint8Array&&Ax(e,t.cekBits),t.cbc)return the(t,e,r,o,n,i);let s=await ri(e,t.subtle,"decrypt");try{return new Uint8Array(await crypto.subtle.decrypt({additionalData:i,iv:o,name:"AES-GCM",tagLength:128},s,pn(r,n)))}catch{throw new ec}}function cg(t){let e={__proto__:null};for(let r in t)e[r]={...t[r],alg:r};return e}var rhe=[["encrypt","wrapKey"],["decrypt","unwrapKey"]],nhe=[[],["deriveBits"]],Ox=[[],[]];function Rx(t){return{kty:["RSA"],mode:"key-encryption",subtle:{name:"RSA-OAEP",hash:`SHA-${t}`},usages:rhe,ops:["wrapKey","unwrapKey"]}}function Cx(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 at('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');return{name:"ECDH",namedCurve:r}},usages:nhe,ops:[void 0,"deriveBits"]}}function sp(t,e=!1){return{kty:["oct"],mode:"key-wrapping",secret:!0,subtle:{name:e?"AES-GCM":"AES-KW",length:t},usages:Ox,ops:e?["encrypt","decrypt"]:["wrapKey","unwrapKey"]}}function BO(){return{kty:["oct"],mode:"key-wrapping",secret:!0,subtle:{name:"PBKDF2"},usages:Ox,ops:["deriveBits","deriveBits"]}}var ia=cg({dir:{kty:["oct"],mode:"direct-encryption",secret:!0,subtle:{name:"AES-GCM"},usages:Ox,ops:["encrypt","decrypt"]},"RSA-OAEP":Rx(1),"RSA-OAEP-256":Rx(256),"RSA-OAEP-384":Rx(384),"RSA-OAEP-512":Rx(512),"ECDH-ES":Cx("direct-key-agreement"),"ECDH-ES+A128KW":Cx("key-agreement-with-key-wrapping"),"ECDH-ES+A192KW":Cx("key-agreement-with-key-wrapping"),"ECDH-ES+A256KW":Cx("key-agreement-with-key-wrapping"),A128KW:sp(128),A192KW:sp(192),A256KW:sp(256),A128GCMKW:sp(128,!0),A192GCMKW:sp(192,!0),A256GCMKW:sp(256,!0),"PBES2-HS256+A128KW":BO(),"PBES2-HS384+A192KW":BO(),"PBES2-HS512+A256KW":BO()}),ohe=["encrypt","decrypt"];function ap(t,e=!1){return{kty:["oct"],secret:!0,subtle:{name:e?"AES-CBC":"AES-GCM",length:t},usages:Ox,ops:ohe,cekBits:t,ivBits:e?128:96,cbc:e}}var ihe=cg({A128GCM:ap(128),A192GCM:ap(192),A256GCM:ap(256),"A128CBC-HS256":ap(256,!0),"A192CBC-HS384":ap(384,!0),"A256CBC-HS512":ap(512,!0)});function RB(t,e){throw new at(`Invalid or unsupported "${t}" (JWE ${e}) header value`)}function ni(t){return(typeof t=="string"?ia[t]:void 0)??RB("alg","Algorithm")}function oi(t){return t.mode==="key-wrapping"||t.mode==="key-encryption"||t.mode==="key-agreement-with-key-wrapping"}function Gu(t){return(typeof t=="string"?ihe[t]:void 0)??RB("enc","Encryption Algorithm")}function CB(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");FO(t,e)}async function she(t,e,r){let o=await ri(e,ni(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 ahe(t,e,r){let o=await ri(e,ni(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 NB(t,e,r){VO(e,ni(t).subtle,r),op(t,e)}async function DB(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=pn(Sr(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 ri(o,ni(e).subtle,"deriveBits");return new Uint8Array(await crypto.subtle.deriveBits(s,a,i))}function KO(t){return pn(gx(t.length),t)}async function che(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 yx("sha256",pn(gx(a),t,r));s.set(c,(a-1)*n)}return s.slice(0,o)}async function zB(t,e,r,o,n=new Uint8Array,i=new Uint8Array){CB(t),CB(e,"deriveBits");let s=pn(KO(Sr(r)),KO(n),KO(i),gx(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 che(a,o,s)}function jB(t){kx(t);let e=t.algorithm.namedCurve;if(e!=="P-256"&&e!=="P-384"&&e!=="P-521"&&t.algorithm.name!=="X25519")throw new at("ECDH with the provided key is not allowed or not supported by your javascript runtime")}function Nx(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 Tn(r,e,U)}}function MB(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 uhe(t){if(t===void 0)throw new U("JWE Encrypted Key missing")}function OB(t){if(t!==void 0)throw new U("Encountered unexpected JWE Encrypted Key")}function lhe(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 UB(t,e,r,o,n,i){let{alg:s}=t,a=t.mode;if(a==="direct-encryption")return OB(o),r;let c=a==="direct-key-agreement";switch(c?OB(o):uhe(o),t.subtle.name){case"ECDH":{let{epk:u}=n;if(!Kt(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');jB(r);let l=await ip(t,u),d=Nx(n,"apu"),f=Nx(n,"apv");MB(d,f);let p=await zB(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 kx(r),NB(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');lhe(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=Tn(n.p2s,"p2s",U);r=await DB(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=Tn(n.iv,"iv",U),l=Tn(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 Px(Gu(s.slice(0,-2)),r,o,u,l,new Uint8Array)}}return ahe(s.slice(-6),r,o)}async function Dx(t,e,r,o,n,i={}){let{alg:s,mode:a}=t,c=oi(t);if(n!==void 0&&!c)throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${s}`);let u=await ti(a==="direct-encryption"?e:t,r,"encrypt");if(a==="direct-encryption")return[u,void 0,void 0];let l=c?n??Ju(e):void 0;l&&Ax(l,e.cekBits);let d,f;switch(t.subtle.name){case"ECDH":{jB(u);let{apu:p,apv:m}=i;p!==void 0&&qn(p,'"apu"'),m!==void 0&&qn(m,'"apv"');let g=p??Nx(o,"apu"),y=m??Nx(o,"apv");MB(g,y);let w;i.epk!==void 0?w=await ti(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 zB(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":{kx(u),NB(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 DB(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 Tx(Gu(s.slice(0,-2)),l,u,p,new Uint8Array);d=m.ciphertext,f={iv:Rt(m.iv),tag:Rt(m.tag)}}}if(d??=await she(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 zx(t,e){if(t.zip!==void 0&&t.zip!=="DEF")throw new at('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 LB(t){if(typeof globalThis[t]>"u")throw new at(`JWE "zip" (Compression Algorithm) Header Parameter requires the ${t} API.`)}async function FB(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 pn(...n)}async function VB(t){return LB("CompressionStream"),FB(new CompressionStream("deflate-raw"),t)}async function HB(t,e){return LB("DecompressionStream"),FB(new DecompressionStream("deflate-raw"),t,e)}function BB(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&&!Kt(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 KB(t){let e,r;try{let{header:o}=t;if(Kt(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 qB(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&&!Kt(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 qO(t){let{protected:e,ciphertext:r,iv:o,tag:n,aad:i}=t,s;return e!==void 0&&(s=np(e,U,"JWE Protected Header is invalid")),[s,Tn(r,"ciphertext",U),o!==void 0?Tn(o,"iv",U):void 0,n!==void 0?Tn(n,"tag",U):void 0,wx((e??"")+(i!==void 0?`.${i}`:""),"aad",U)]}function jx(t){return[t&&ag("keyManagementAlgorithms",t.keyManagementAlgorithms),t&&ag("contentEncryptionAlgorithms",t.contentEncryptionAlgorithms),t?.crit,t?.maxPBES2Count,t?.maxDecompressedLength]}async function ZO(t,e,r,o=qO(t)){let[n,i,s,a,c]=o,{header:u,unprotected:l,aad:d}=t,f;if(u!==void 0||l!==void 0){if(!tc(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;rc(U,_x,g,n,f),zx(f,n);let{alg:_,enc:k}=f;if(typeof _!="string"||!_)throw new U("missing JWE Algorithm (alg) in JWE Header");let $=ia[_];if(b===""&&(!$||!oi($)))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 qu('"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 qu('"enc" (Encryption Algorithm) Header Parameter value not allowed');K=Gu(k)}let te;if(b!==void 0)try{te=Tn(b,"encrypted_key",U)}catch($e){if(!$||!oi($))throw $e;te=new Uint8Array}let Ie=!1;typeof r=="function"&&(r=await r(n,t),Ie=!0);let xe=$??ni(_);oi(xe)&&te===void 0&&(te=new Uint8Array);let Qe=await ti(xe.mode==="direct-encryption"?K:xe,r,"decrypt"),Fe;if(xe.mode==="integrated-encryption")Fe=await xe.decrypt(Qe,te,i,c,n,f);else{let $e=K,J;try{J=await UB(xe,$e,Qe,te,f,y),oi(xe)&&J instanceof Uint8Array&&J.byteLength<<3!==$e.cekBits&&(J=Ju($e))}catch(Tt){if(Tt instanceof TypeError||Tt instanceof U||Tt instanceof at)throw Tt;J=Ju($e)}Fe=await Px($e,J,i,s,a,c)}if(f.zip==="DEF"){let $e=w??25e4;if($e===0)throw new at('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");Fe=await HB(Fe,$e).catch(J=>{throw J instanceof U?J:new U("Failed to decompress plaintext",{cause:J})})}return{plaintext:Fe,...n&&{protectedHeader:n},...d!==void 0&&{additionalAuthenticatedData:Tn(d,"aad",U)},...l&&{sharedUnprotectedHeader:l},...u&&{unprotectedHeader:u},...Ie&&{key:Qe}}}async function ZB(t,e,r){if(t instanceof Uint8Array&&(t=rp.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 ZO({ciphertext:s,iv:i||void 0,protected:o,tag:a||void 0,encrypted_key:n||void 0},e,r)}async function ug(t,e,r){return ZB(t,jx(r),e)}async function WO(t,e,r){if(!Kt(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(Kt))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=jx(r),s=BB(t),a=qO(s)}catch{throw new ec}let c=n.map(u=>KB(u));if(n.length>1)for(let[,u]of c){let l=a[0]?.alg??u??s.unprotected?.alg,d=typeof l=="string"?ia[l]:void 0;if(d&&!oi(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 qB(l),await ZO(l,i,e,a)}catch{}throw new ec}function Mx(t,e,r){if(!tc(t,e,r))throw new U("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint")}function JO(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&&qn(s,"JWE Additional Authenticated Data"),a!==void 0&&qn(a,"JWE Content Encryption Key"),c!==void 0&&qn(c,"JWE Initialization Vector"),!r&&o!==void 0&&(o=Wu(U,o)[0],t[1]=o),n!==void 0&&(n=Wu(U,n)[0],t[2]=n),!r&&i!==void 0&&(i=Wu(U,i)[0],t[3]=i),u!==void 0&&!Kt(u))throw new TypeError("JWE Key Management Parameters must be an object");Mx(o,n,i);let d={...o,...n,...i};Sx(U,o),rc(U,_x,l,o,d),zx(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=ia[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,Gu(p),m]}async function GO(t,e,r){let[o,n,i]=e,[s,a,c,u,l,d,f,p,,m]=t,g=a,y=c,w=i??ni(o.alg),b,_,k;w.mode==="integrated-encryption"?k=await ti(w,r,"encrypt"):[k,b,_]=await Dx(w,n,r,o,d,p),_&&(m?y=y?{...y,..._}:_:g=g?{...g,..._}:_,Mx(g,y,u));let $=g?Rt(JSON.stringify(g)):"",D=l?.byteLength?Rt(l):void 0,K=Sr(D?`${$}.${D}`:$),te=s;o.zip==="DEF"&&(te=await VB(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 Tx(n,te,k,f,K);let Fe={ciphertext:Rt(Ie)};return Qe&&(Fe.iv=Rt(Qe)),xe&&(Fe.tag=Rt(xe)),b?.byteLength&&(Fe.encrypted_key=Rt(b)),D&&(Fe.aad=D),g&&(Fe.protected=$),u&&(Fe.unprotected=u),y&&(Fe.header=y),Fe}async function WB(t,e,r){return GO(t,JO(t,r),e)}function JB(t){return[t.protected,t.encrypted_key,t.iv,t.ciphertext,t.tag].join(".")}var XO=class{#e;state;constructor(e,r,o){this.#e=e,this.state=[void 0,void 0,r,o]}setUnprotectedHeader(e){return go(this.state[0],"setUnprotectedHeader"),this.state[0]=e,this}setKeyManagementParameters(e){return go(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}},lg=class{#e;#t=[];#r;#n;#o;constructor(e){this.#e=e}addRecipient(e,r){let o=new XO(this,e,r?.crit);return this.#t.push(o),o}setProtectedHeader(e){return go(this.#r,"setProtectedHeader"),this.#r=e,this}setSharedUnprotectedHeader(e){return go(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");qn(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=JO(_,void 0,i.length>0);i.length||(o=_[1],n=_[3]),i.push([_,k,w]);let[{alg:$,enc:D},,K]=k;if(e&&K&&!oi(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]??=ni(m[0].alg);let[s,a,c]=i[0],u=e?Ju(a[1]):void 0;s[5]=u;let{encrypted_key:l,header:d,...f}=await GO(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 Dx(b,w,_,y,u,g[7]),K={encrypted_key:Rt($)};if(k||D){let te={...k,...D};D&&Mx(g[1],te,g[3]),K.header=te}p.recipients.push(K)}return p}};var dg=[["verify"],["sign"]];function YO(t){let e={name:"HMAC",hash:`SHA-${t}`};return{kty:["oct"],secret:!0,subtle:e,signing:e,usages:dg}}function cp(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:dg,minRsaBits:2048}}function QO(t,e){return{kty:["EC"],crv:t,subtle:{name:"ECDSA",namedCurve:t},signing:{name:"ECDSA",hash:`SHA-${e}`},usages:dg}}function GB(){let t={name:"Ed25519"};return{kty:["OKP"],crv:"Ed25519",subtle:t,signing:t,usages:dg}}function eN(t){let e={name:`ML-DSA-${t}`};return{kty:["AKP"],subtle:e,signing:e,usages:dg}}var tN=cg({HS256:YO(256),HS384:YO(384),HS512:YO(512),RS256:cp(256),RS384:cp(384),RS512:cp(512),PS256:cp(256,32),PS384:cp(384,48),PS512:cp(512,64),ES256:QO("P-256",256),ES384:QO("P-384",384),ES512:QO("P-521",512),EdDSA:GB(),Ed25519:GB(),"ML-DSA-44":eN(44),"ML-DSA-65":eN(65),"ML-DSA-87":eN(87)});function Ux(t){let e=typeof t=="string"?tN[t]:void 0;if(!e)throw new at(`alg ${t} is not supported either by JOSE or your javascript runtime`);return e}function XB(t){return[t&&ag("algorithms",t.algorithms),t?.crit]}function dhe(t){return t===void 0?{}:np(t,xt,"JWS Protected Header is invalid")}function phe(t){try{return Sr(t)}catch{throw new xt("JWS Compact Serialization payload must use only ASCII characters")}}async function fhe(t,e,r,o,n){let{protected:i,header:s,payload:a}=t,c=n??dhe(i);if(!tc(c,s))throw new xt("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");let u={...c,...s},l=xx(c,rc(xt,bx,e[1],c,u)),{alg:d}=u;if(typeof d!="string"||!d)throw new xt('JWS "alg" (Algorithm) Header Parameter missing or invalid');if(e[0]&&!e[0].has(d))throw new qu('"alg" (Algorithm) Header Parameter value not allowed');if(l){if(typeof a!="string")throw new xt("JWS Payload must be a string")}else if(typeof a!="string"&&!(a instanceof Uint8Array))throw new xt("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=Ux(d),g=pn(i!==void 0?Sr(i):new Uint8Array,Sr("."),typeof f=="string"?e[2]??=wx(f,"payload",xt):f),y=Tn(t.signature,"signature",xt),w=await ti(m,r,"verify"),b=await ri(w,m.subtle,"verify");m.minRsaBits&&op(m.alg,b);let _=!1;try{_=await crypto.subtle.verify(m.signing,b,y,g)}catch{}if(!_)throw new vx;let k={payload:typeof f=="string"?Tn(f,"payload",xt):f};return i!==void 0&&(k.protectedHeader=c),s!==void 0&&(k.unprotectedHeader=s),p?[{...k,key:w},l]:[k,l]}async function YB(t,e,r){if(t instanceof Uint8Array&&(t=rp.decode(t)),typeof t!="string")throw new xt("Compact JWS must be a string or Uint8Array");let{0:o,1:n,2:i,length:s}=t.split(".");if(s!==3)throw new xt("Invalid Compact JWS");return fhe({payload:n,protected:o,signature:i},e,r,phe)}async function rN(t,e,r){let[o]=await YB(t,XB(r),e);return o}var up=class{#e;constructor(e){qn(e,"plaintext"),this.#e=[e]}setContentEncryptionKey(e){return go(this.#e[5],"setContentEncryptionKey"),this.#e[5]=e,this}setInitializationVector(e){return go(this.#e[6],"setInitializationVector"),this.#e[6]=e,this}setProtectedHeader(e){return go(this.#e[1],"setProtectedHeader"),this.#e[1]=e,this}setKeyManagementParameters(e){return go(this.#e[7],"setKeyManagementParameters"),this.#e[7]=e,this}async encrypt(e,r){return JB(await WB([...this.#e],e,r))}};async function mhe(t,e,r){let[o,n,i,s]=t,a="";if(n!==void 0){let w=Wu(xt,n);n=w[0],a=Rt(w[1])}if(i!==void 0&&(i=Wu(xt,i)[0]),!n&&!i)throw new xt("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");if(!tc(n,i))throw new xt("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");let c={...n,...i};Sx(xt,n);let u=xx(n,rc(xt,bx,s,n,c));u||r?.();let{alg:l}=c;if(typeof l!="string"||!l)throw new xt('JWS "alg" (Algorithm) Header Parameter missing or invalid');let d=Ux(l),f="",p=o,m;if(u){let w=t[4];w?(f=w[0]??=Rt(o),p=w[1]??=Sr(f)):(f=Rt(o),m=tp.encode(`${a}.${f}`))}m??=pn(Sr(a),Sr("."),p);let g=await ri(await ti(d,e,"sign"),d.subtle,"sign");d.minRsaBits&&op(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 QB(t,e,r,o,n){let[i]=await mhe([t,e,void 0,r],o,n);return`${i.protected}.${i.payload}.${i.signature}`}var pg=class{#e;#t;constructor(e){qn(e,"payload"),this.#e=e}setProtectedHeader(e){return go(this.#t,"setProtectedHeader"),this.#t=e,this}async sign(e,r){return QB(this.#e,this.#t,r?.crit,e,()=>{throw new TypeError("use the flattened module for creating JWS with b64: false")})}};var nN='"alg" (Algorithm)';function oN(t='JWK "alg" (Algorithm) Parameter'){throw new at(`Invalid or unsupported ${t} value`)}function fg(t,e){return(typeof t=="string"?tN[t]??ia[t]:void 0)??oN(e)}async function oc(t){if(UO(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(!nc(t))throw new TypeError(oa(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 sa=(t,e)=>{if(typeof t!="string"||!t)throw new sg(`${e} missing or invalid`)};async function iN(t,e){let r;if(Kt(t)){if(r=Ix(t),typeof r.kty!="string")throw new TypeError(oa(t,"CryptoKey","KeyObject","JSON Web Key"))}else if(LO(t))r=Ix(await oc(t));else throw new TypeError(oa(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":sa(r.alg,'"alg" (Algorithm) Parameter'),sa(r.pub,'"pub" (Public key) Parameter'),o={alg:r.alg,kty:r.kty,pub:r.pub};break;case"EC":sa(r.crv,'"crv" (Curve) Parameter'),sa(r.x,'"x" (X Coordinate) Parameter'),sa(r.y,'"y" (Y Coordinate) Parameter'),o={crv:r.crv,kty:r.kty,x:r.x,y:r.y};break;case"OKP":sa(r.crv,'"crv" (Subtype of Key Pair) Parameter'),sa(r.x,'"x" (Public Key) Parameter'),o={crv:r.crv,kty:r.kty,x:r.x};break;case"RSA":sa(r.e,'"e" (Exponent) Parameter'),sa(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 sg('"k" (Key Value) Parameter missing or invalid');o={k:r.k,kty:r.kty};break;default:throw new at('"kty" (Key Type) Parameter missing or unsupported')}let n=Sr(JSON.stringify(o));return Rt(await yx(e,n))}async function yo(t,e,r){if(!Kt(t))throw new TypeError("JWK must be an object");let o=HO(t),n=$x(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 Zu(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 ip(fg(e),o,n)}case"RSA":case"EC":case"OKP":return ip(fg(e),o,n);default:throw new at('Unsupported "kty" (Key Type) Parameter value')}}function sN(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 np(e,TypeError,r)}function hhe(t){let e=t?.modulusLength??2048;if(typeof e!="number"||!Number.isInteger(e)||e<2048)throw new at("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");return e}async function mg(t,e){let r=$x(e?.extractable),o=fg(t,nN);o.secret&&oN(nN);let n;if(o.resolve){let i=e?.crv??"P-256";if(!["P-256","P-384","P-521","X25519"].includes(i))throw new at("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 at(`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:hhe(e)}:o.subtle}return crypto.subtle.generateKey(n,r??!1,[...o.usages[1],...o.usages[0]])}var nK=h.string().regex(/^[a-z]{2}(?:-gov)?-[a-z]+-\d$/),oK=h.string().max(2e3).regex(/^arn:aws(?:-us-gov|-cn)?:iam::\d{12}:role\/.+/),eK=h.string().min(1).max(128),tK=h.string().min(1).max(16384),ghe=h.discriminatedUnion("kind",[h.object({kind:h.literal("access_key"),accessKeyId:eK,secretAccessKey:tK}).strict(),h.object({kind:h.literal("session"),accessKeyId:eK,secretAccessKey:tK,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()]),yhe=h.object({arn:oK,externalId:h.string().min(2).max(1224).regex(/^[\w+=,.@:\/-]+$/).optional()}).strict(),aa=h.object({authentication:ghe,region:nK,role:yhe.optional()}).strict(),Lx=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(),Fx=aa.extend({sourceIdentity:Lx.optional(),identity:Lx.optional()}).strict();function lp(t){return t.includes(":assumed-role/")?t.slice(0,t.lastIndexOf("/")):t}function rK(t){return{...t,arn:lp(t.arn)}}function iK(t){return{authentication:t.authentication.kind,region:t.region,role:t.role??null,...t.sourceIdentity?{sourceIdentity:rK(t.sourceIdentity)}:{},...t.identity?{identity:rK(t.identity)}:{}}}var Vx=h.object({authentication:h.enum(["access_key","session","environment"]),region:nK,sourceAccountId:h.string().regex(/^\d{12}$/).optional(),sourceArn:h.string().max(2e3).optional(),roleArn:oK.optional(),expiresAt:h.number().int().positive().optional()}).strict();function sK(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 aK=h.object({method:h.enum(["GET","POST","PUT","DELETE","PATCH"]),path:h.string().min(1).max(1e3).regex(/^\/[^\s\u0000]*$/)}).strict(),hg=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(aK),allowedIPs:h.array(h.string()).nullable(),expiresAt:h.number().nullable()}).strict();function cK(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 aK.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),Ve=h.iso.datetime(),Zn=h.json(),xr=h.record(h.string(),Zn),uK=h.enum(["ja","en"]),lK=h.enum(["read","create","update","delete","share","transfer","reveal","use","manage_credentials","manage_billing","export"]);var dK=h.enum(["variable","connection","service","method","app","object","keyring","ssh_key","ssh_host"]),fn=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(),vhe=h.object({alg:h.literal("dir"),enc:h.literal("A256GCM"),sub:E}).strict(),vg=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 vhe.safeParse(sN(t)).success}catch{return!1}},"Use an A256GCM JWE for the wrapped encryption key.").brand(),Fr=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:fn.optional(),alg:h.string().optional()}).passthrough()})).min(1).max(100)}).strict(),QVe=h.object({id:E,name:me,publicKey:fn}),Yu=h.object({id:E,name:me,owner:h.object({id:E,name:me}).nullable(),createdAt:Ve,permissions:h.array(lK),createKinds:h.array(dK),publicKey:fn.nullable()}),pK=h.object({id:E,kind:h.enum(["passkey","email","key"]),name:h.string(),createdAt:Ve,lastUsedAt:Ve.nullable(),expiresAt:Ve.nullable(),canOpen:h.boolean()}),aN=h.string().regex(/^[a-z][a-z_]*[a-z]$/).max(64),whe=h.object({subjectId:E,relation:aN,objectId:E}).strict(),fK=h.enum(["principal",...dK.options]),mK=whe.extend({objectType:fK,subjectName:me,objectName:me,createdAt:Ve}),eHe=h.object({error:h.object({code:h.string(),message:h.string(),details:Zn.optional()})}),tHe=h.object({ok:h.literal(!0)}),bhe=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(),Kx=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(bhe).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."})}),cN=h.record(h.string().regex(/^[A-Z_][A-Z0-9_]*$/),h.string()),_he=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)])),uN=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()}),Xu=h.string().min(1).max(4096),Bx=h.union([h.string(),h.array(h.string()).min(1)]),Pn="urn:ietf:params:oauth:grant-type:device_code",She=h.object({browserTokenExchange:h.enum(["available","unavailable","unknown"]).optional(),application:h.enum(["required","implicit"]).default("required"),grantType:h.enum(["authorization_code","client_credentials",Pn]).optional(),issuer:h.url().optional(),registrationUrl:h.url().optional(),authorizeUrl:Xu.optional(),deviceAuthorizationUrl:Xu.optional(),tokenUrl:Xu,identity:h.object({url:Xu.optional(),from:h.enum(["token","app"]).optional(),method:h.enum(["GET","POST"]).default("GET"),id:Bx.default("/id"),name:Bx.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:uN.default({default:[],separator:" "}),fields:h.array(Kx).default([]),outputs:cN.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===Pn||!!t.authorizeUrl,{path:["authorizeUrl"],message:"An authorization code flow requires an authorization URL."}).refine(t=>t.grantType!==Pn||!!t.deviceAuthorizationUrl,{path:["deviceAuthorizationUrl"],message:"A device flow requires a device authorization URL."}),xhe=h.object({fields:h.array(Kx).min(1),outputs:_he,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:Xu,headers:h.record(h.string(),h.string()),id:Bx,name:Bx}).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."})}),lN=h.enum(["oauth","token","aws","ovh","approval"]),Ehe=h.object({hint:h.string().optional()}).strict(),khe=h.object({authorization:h.enum(["api_key","consumer_key"]),apiBaseUrl:Xu,fields:h.array(Kx).min(1),scopes:uN.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 UV(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;UV(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 LV=new Set(["type","properties","required","additionalProperties"]),jV=["oneOf","anyOf"];function MV(t){let e=t.additionalProperties;return e===void 0||e===!1||typeof e!="object"||e===null?null:Object.keys(e).length?e:null}function HR(t){let e=[];for(let i of t){if(typeof i!="object"||i.type!=="object")return null;for(let s in i)if(!LV.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]??MV(u);l!=null&&(a.some(d=>JSON.stringify(d)===JSON.stringify(l))||a.push(l))}let c=a.length===1?a[0]:HR(a)??{allOf:a};vr(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=MV(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 mme(t){let e=t.allOf;if(!Array.isArray(e)||e.length<2)return;for(let n of LV)if(n in t)return;let r=e.filter(n=>jV.some(i=>Array.isArray(n[i]))),o=null;if(!r.length)o=HR(e);else{let n=r[0],i=jV.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=>HR([...s,c]));if(a.some(c=>!c))return;o={[i]:a}}o&&(delete t.allOf,Hh(t,o))}function Ja(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)):Hh(u,m),Hh(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())UV(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)??[])mme(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)}Hh(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,vr(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:Hd(e,"input",t.processors),output:Hd(e,"output",t.processors)}},enumerable:!1,writable:!1}),a}catch{throw new Error("Error converting schema to JSON.")}}function ln(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 ln(o.element,r);if(o.type==="set")return ln(o.valueType,r);if(o.type==="lazy")return ln(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 ln(o.innerType,r);if(o.type==="intersection")return ln(o.left,r)||ln(o.right,r);if(o.type==="record"||o.type==="map")return ln(o.keyType,r)||ln(o.valueType,r);if(o.type==="pipe")return t._zod.traits.has("$ZodCodec")?!0:ln(o.in,r)||ln(o.out,r);if(o.type==="object"){for(let n in o.shape)if(ln(o.shape[n],r))return!0;return!1}if(o.type==="union"){for(let n of o.options)if(ln(n,r))return!0;return!1}if(o.type==="tuple"){for(let n of o.items)if(ln(n,r))return!0;return!!(o.rest&&ln(o.rest,r))}return!1}var BR=(t,e={})=>r=>{let o=Za({...r,processors:e});return et(t,o),Wa(o,t),Ja(o,t)},Hd=(t,e,r={})=>o=>{let{libraryOptions:n,target:i}=o??{},s=Za({...n??{},target:i,io:e,processors:r});return et(t,s),Wa(s,t),Ja(s,t)};var Bd=(t,e,r)=>{(t[e]===void 0||r>t[e])&&(t[e]=r)},Kd=(t,e,r)=>{(t[e]===void 0||r<t[e])&&(t[e]=r)},FV=(t,e)=>{Bd(t,"minimum",e),Kd(t,"maximum",e)},KV=(t,e)=>{t.multipleOf??(t.multipleOf=[]),t.multipleOf.includes(e)||t.multipleOf.push(e)},qV=(t,e)=>{t.patterns??(t.patterns=new Set),t.patterns.add(e)},ZV=(t,e)=>{t.mime=t.mime?t.mime.filter(r=>e.includes(r)):[...e]},WV=(t,e)=>{t.format=e,e.includes("int")&&(t.isInt=!0)},VV=(t,e)=>Bd(t,"minimum",e.minimum),HV=(t,e)=>Kd(t,"maximum",e.maximum),BV=t=>(e,r)=>{WV(e,r.format);let[o,n]=t[r.format];Bd(e,"minimum",o),Kd(e,"maximum",n)},hme={greater_than:(t,e)=>Bd(t,e.inclusive?"minimum":"exclusiveMinimum",e.value),less_than:(t,e)=>Kd(t,e.inclusive?"maximum":"exclusiveMaximum",e.value),multiple_of:(t,e)=>KV(t,e.value),number_format:BV(qm),bigint_format:BV(Zm),min_length:VV,max_length:HV,length_equals:(t,e)=>FV(t,e.length),min_size:VV,max_size:HV,size_equals:(t,e)=>FV(t,e.size),string_format:(t,e)=>{WV(t,e.format),e.pattern&&qV(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)=>ZV(t,e.mime)};function Yt(t){let e={},r=t._zod.def,o=t._zod.traits.has("$ZodCheck")?[t,...r.checks??[]]:r.checks??[];for(let i of o)hme[i._zod.def.check]?.(e,i._zod.def);let n=t._zod.bag;n.minimum!==void 0&&Bd(e,"minimum",n.minimum),n.exclusiveMinimum!==void 0&&Bd(e,"exclusiveMinimum",n.exclusiveMinimum),n.maximum!==void 0&&Kd(e,"maximum",n.maximum),n.exclusiveMaximum!==void 0&&Kd(e,"exclusiveMaximum",n.exclusiveMaximum),n.multipleOf!==void 0&&KV(e,n.multipleOf),n.format!==void 0&&(e.format??(e.format=n.format),n.format.includes("int")&&(e.isInt=!0)),n.mime&&ZV(e,n.mime);for(let i of n.patterns??[])qV(e,i);return e}var gme={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},yme=new Map([[qb,TP],[ch,PP]]),JV=t=>yme.get(t)??t,ZR=(t,e,r,o)=>{let n=r;n.type="string";let{minimum:i,maximum:s,format:a,patterns:c,contentEncoding:u,laxFormat:l}=Yt(t);if(typeof i=="number"&&(n.minLength=i),typeof s=="number"&&(n.maxLength=s),a&&(n.format=gme[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(JV);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}))])}},WR=(t,e,r,o)=>{let n=r,{minimum:i,maximum:s,multipleOf:a,exclusiveMaximum:c,exclusiveMinimum:u,isInt:l}=Yt(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)):Xt(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}))])}},JR=(t,e,r,o)=>{r.type="boolean"},GR=(t,e,r,o)=>{Xt(t,e,r,o,"BigInt cannot be represented in JSON Schema")},XR=(t,e,r,o)=>{Xt(t,e,r,o,"Symbols cannot be represented in JSON Schema")},YR=(t,e,r,o)=>{e.target==="openapi-3.0"?(r.type="string",r.nullable=!0,r.enum=[null]):r.type="null"},QR=(t,e,r,o)=>{Xt(t,e,r,o,"Undefined cannot be represented in JSON Schema")},eC=(t,e,r,o)=>{Xt(t,e,r,o,"Void cannot be represented in JSON Schema")},tC=(t,e,r,o)=>{r.not={}},rC=(t,e,r,o)=>{},nC=(t,e,r,o)=>{},oC=(t,e,r,o)=>{Xt(t,e,r,o,"Date cannot be represented in JSON Schema")},iC=(t,e,r,o)=>{let n=t._zod.def,i=od(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},sC=(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(Xt(t,e,r,o,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof s=="bigint"){if(Xt(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},aC=(t,e,r,o)=>{Xt(t,e,r,o,"NaN cannot be represented in JSON Schema")},cC=(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},uC=(t,e,r,o)=>{let n=r;n.type="string",n.format="binary",n.contentEncoding="binary";let{minimum:i,maximum:s,mime:a}=Yt(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})))},lC=(t,e,r,o)=>{r.type="boolean"},dC=(t,e,r,o)=>{Xt(t,e,r,o,"Custom types cannot be represented in JSON Schema")},pC=(t,e,r,o)=>{Xt(t,e,r,o,"Function types cannot be represented in JSON Schema")},fC=(t,e,r,o)=>{Xt(t,e,r,o,"Transforms cannot be represented in JSON Schema")},mC=(t,e,r,o)=>{Xt(t,e,r,o,"Map cannot be represented in JSON Schema")},hC=(t,e,r,o)=>{Xt(t,e,r,o,"Set cannot be represented in JSON Schema")},gC=(t,e,r,o)=>{let n=r,i=t._zod.def,{minimum:s,maximum:a}=Yt(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 Bh(t){let e=t._zod.def;return e.type==="pipe"&&e.in._zod.traits.has("$ZodTransform")?Bh(e.out):e.type==="catch"?Bh(e.innerType):t._zod.optin}var yC=(t,e,r,o)=>{let n=r,i=t._zod.def,s=i.shape;if(Object.getOwnPropertySymbols(s).length&&Xt(t,e,n,o,"Symbol keys cannot be represented in JSON Schema"))return;n.type="object",n.properties={};for(let u in s)vr(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"?Bh(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)},DS=(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},vC=(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)},wC=(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"?Bh(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}=Yt(t);typeof p=="number"&&(n.minItems=p),typeof m=="number"&&(n.maxItems=m)};function KR(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=KR(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=>KR(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")?ta:th).source)),p}var qR=new WeakMap;function vme(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 qR.get(t)??[]){let n=t.seen.get(o),i=(n?.def??n?.schema)?.propertyNames;if(!i||i===!0||r.has(i))continue;let s=KR(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 bC=(t,e,r,o)=>{let n=r,i=t._zod.def;n.type="object";let s=i.keyType,a=Yt(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)vr(n.patternProperties,JV(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=qR.get(e);l||(l=[],qR.set(e,l),e.deferred.push(()=>vme(e))),l.push(t)}n.additionalProperties=et(i.valueType,e,{...o,path:[...o.path,"additionalProperties"]})}let c=s._zod.values,u=e.io==="input"&&Bh(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))}},_C=(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"}]},SC=(t,e,r,o)=>{let n=t._zod.def;et(n.innerType,e,o);let i=e.seen.get(t);i.ref=n.innerType},xC=Symbol();function GV(t,e,r,o,n){let i=!1,s=JSON.stringify(t,(a,c)=>typeof c!="bigint"?c:(i=!0,null));return i?(Xt(e,r,o,n,"BigInt defaults cannot be represented in JSON Schema"),xC):JSON.parse(s)}var EC=(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=GV(n.defaultValue,t,e,r,o);s!==xC&&(r.default=s)},kC=(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=GV(n.defaultValue,t,e,r,o);s!==xC&&(r._prefault=s)},IC=(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{Xt(t,e,r,o,"Dynamic catch values are not supported in JSON Schema");return}r.default=s},$C=(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},AC=(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},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},zS=(t,e,r,o)=>{let n=t._zod.def;et(n.innerType,e,o);let i=e.seen.get(t);i.ref=n.innerType},PC=(t,e,r,o)=>{let n=t._zod.innerType;et(n,e,o);let i=e.seen.get(t);i.ref=n},NS={string:ZR,number:WR,boolean:JR,bigint:GR,symbol:XR,null:YR,undefined:QR,void:eC,never:tC,any:rC,unknown:nC,date:oC,enum:iC,literal:sC,nan:aC,template_literal:cC,file:uC,success:lC,custom:dC,function:pC,transform:fC,map:mC,set:hC,array:gC,object:yC,union:DS,intersection:vC,tuple:wC,record:bC,nullable:_C,nonoptional:SC,default:EC,prefault:kC,catch:IC,pipe:$C,readonly:AC,promise:TC,optional:zS,lazy:PC};function Lu(t,e){if("_idmap"in t){let o=t,n=Za({...e,processors:NS}),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;Wa(n,l),vr(s,u,Ja(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=Za({...e,processors:NS});return et(t,r),Wa(r,t),Ja(r,t)}var jS=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=Za({processors:NS,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,Wa(this.ctx,e);let o=Ja(this.ctx,e),{"~standard":n,...i}=o;return i}};var XV={};var Qd={};yt(Qd,{ZodAny:()=>JC,ZodArray:()=>QC,ZodBase64:()=>rx,ZodBase64URL:()=>nx,ZodBigInt:()=>Xd,ZodBigIntFormat:()=>sx,ZodBoolean:()=>Gd,ZodCIDRv4:()=>ex,ZodCIDRv6:()=>tx,ZodCUID:()=>ZS,ZodCUID2:()=>WS,ZodCatch:()=>vO,ZodCodec:()=>Qh,ZodCreditCard:()=>BC,ZodCustom:()=>eg,ZodCustomStringFormat:()=>Vu,ZodDate:()=>Wh,ZodDefault:()=>pO,ZodDiscriminatedUnion:()=>tO,ZodE164:()=>ox,ZodEmail:()=>HS,ZodEmoji:()=>KS,ZodEnum:()=>Zd,ZodExactOptional:()=>ux,ZodFile:()=>cO,ZodFunction:()=>AO,ZodGUID:()=>BS,ZodIBAN:()=>KC,ZodIPv4:()=>YS,ZodIPv6:()=>QS,ZodISODate:()=>Xa,ZodISODateTime:()=>Ga,ZodISODuration:()=>Qa,ZodISOTime:()=>Ya,ZodInstanceOf:()=>RO,ZodIntersection:()=>rO,ZodJWT:()=>ix,ZodKSUID:()=>XS,ZodLazy:()=>kO,ZodLiteral:()=>aO,ZodMAC:()=>HC,ZodMap:()=>iO,ZodNaN:()=>bO,ZodNanoID:()=>qS,ZodNever:()=>XC,ZodNonOptional:()=>lx,ZodNull:()=>WC,ZodNullable:()=>dO,ZodNumber:()=>Jd,ZodNumberFormat:()=>Hu,ZodObject:()=>Jh,ZodOptional:()=>Bu,ZodPipe:()=>Yh,ZodPrefault:()=>mO,ZodPreprocess:()=>_O,ZodPromise:()=>$O,ZodReadonly:()=>SO,ZodRecord:()=>qd,ZodSet:()=>sO,ZodString:()=>Wd,ZodStringFormat:()=>it,ZodSuccess:()=>yO,ZodSymbol:()=>qC,ZodTemplateLiteral:()=>EO,ZodTransform:()=>uO,ZodTuple:()=>nO,ZodType:()=>ge,ZodULID:()=>JS,ZodURL:()=>qh,ZodUUID:()=>Xi,ZodUndefined:()=>ZC,ZodUnion:()=>Gh,ZodUnknown:()=>GC,ZodVoid:()=>YC,ZodXID:()=>GS,ZodXor:()=>eO,_ZodString:()=>VS,_default:()=>fO,_function:()=>iB,any:()=>LH,array:()=>Ae,base64:()=>bH,base64url:()=>_H,bigint:()=>DH,boolean:()=>Vt,catch:()=>wO,check:()=>sB,cidrv4:()=>vH,cidrv6:()=>wH,codec:()=>tB,creditCard:()=>xH,cuid:()=>lH,cuid2:()=>dH,currencyCode:()=>TH,custom:()=>dx,date:()=>VH,describe:()=>aB,discriminatedUnion:()=>Xh,e164:()=>SH,email:()=>eH,emoji:()=>cH,enum:()=>_r,exactOptional:()=>lO,file:()=>XH,float32:()=>RH,float64:()=>CH,function:()=>iB,guid:()=>tH,hash:()=>PH,hex:()=>AH,hostname:()=>$H,httpUrl:()=>aH,iban:()=>EH,instanceof:()=>uB,int:()=>LS,int32:()=>OH,int64:()=>zH,intersection:()=>Yd,invertCodec:()=>rB,ipv4:()=>hH,ipv6:()=>yH,json:()=>dB,jwt:()=>kH,keyof:()=>HH,ksuid:()=>mH,lazy:()=>IO,literal:()=>G,looseObject:()=>br,looseRecord:()=>ZH,mac:()=>gH,map:()=>WH,meta:()=>cB,nan:()=>eB,nanoid:()=>uH,nativeEnum:()=>GH,never:()=>ax,nonoptional:()=>gO,null:()=>Zh,nullable:()=>Kh,nullish:()=>YH,number:()=>Ze,object:()=>H,optional:()=>ot,partialRecord:()=>qH,pipe:()=>FS,prefault:()=>hO,preprocess:()=>tg,promise:()=>oB,readonly:()=>xO,record:()=>st,refine:()=>TO,set:()=>JH,strictObject:()=>BH,string:()=>I,stringFormat:()=>IH,stringbool:()=>lB,success:()=>QH,superRefine:()=>PO,symbol:()=>MH,templateLiteral:()=>nB,transform:()=>cx,tuple:()=>oO,uint32:()=>NH,uint64:()=>jH,ulid:()=>pH,undefined:()=>UH,union:()=>tt,unknown:()=>ut,url:()=>sH,uuid:()=>rH,uuidv4:()=>nH,uuidv6:()=>oH,uuidv7:()=>iH,void:()=>FH,xid:()=>fH,xor:()=>KH});var MS={};yt(MS,{endsWith:()=>Dd,gt:()=>Ji,gte:()=>Kn,includes:()=>Od,length:()=>Uu,lowercase:()=>Rd,lt:()=>Wi,lte:()=>Bn,maxLength:()=>Mu,maxSize:()=>Ka,mime:()=>jd,minLength:()=>ra,minSize:()=>Gi,multipleOf:()=>Ba,negative:()=>xS,nonnegative:()=>kS,nonpositive:()=>ES,normalize:()=>Md,overwrite:()=>Qo,positive:()=>SS,properties:()=>zd,property:()=>IS,regex:()=>Pd,size:()=>ju,slugify:()=>Vd,startsWith:()=>Nd,toLowerCase:()=>Ld,toUpperCase:()=>Fd,trim:()=>Ud,uppercase:()=>Cd});var YV=new WeakSet([Object.prototype,Error.prototype]);function US(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 QV=(t,e)=>{uP.init(t,e),t.name="ZodError";let r=Object.getPrototypeOf(t);YV.has(r)||(YV.add(r),US(r,"format",o=>n=>Qm(o,n)),US(r,"flatten",o=>n=>Ym(o,n)),US(r,"addIssue",o=>n=>{o.issues.push(n),o.message=JSON.stringify(o.issues,id,2)}),US(r,"addIssues",o=>n=>{o.issues.push(...n),o.message=JSON.stringify(o.issues,id,2)}),Object.defineProperty(r,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},bme=S("ZodError",QV),An=S("ZodError",QV,void 0,{Parent:Error});var RC=dd(An),CC=pd(An),OC=fd(An),NC=hd(An),DC=ab(An),zC=cb(An),jC=ub(An),MC=lb(An),UC=db(An),LC=pb(An),FC=fb(An),VC=mb(An);function Sme(){cr.localeError||zt(K_())}function Fu(){cr.memoizer||zt({memoizer:gh()})}var ge=S("ZodType",(t,e)=>(Sme(),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(TO(t,e))},superRefine(t,e){return this.check(PO(t,e))},overwrite(t){return this.check(Qo(t))},optional(){return ot(this)},exactOptional(){return lO(this)},nullable(){return Kh(this)},nullish(){return ot(Kh(this))},nonoptional(t){return gO(this,t)},array(){return Ae(this)},or(t){return tt([this,t])},and(t){return Yd(this,t)},transform(t){return FS(this,cx(t))},default(t){return fO(this,t)},prefault(t){return hO(this,t)},catch(t){return wO(this,t)},pipe(t){return FS(this,t)},readonly(){return xO(this)},describe(t){let e=this.clone();return wr.add(e,{description:t}),e},meta(...t){if(t.length===0)return wr.get(this);let e=this.clone();return wr.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",{...kb(this),jsonSchema:{input:Hd(this,"input"),output:Hd(this,"output")}})},set"~standard"(t){A.own(this,"~standard",t)},parse:function t(e,r){return RC(this,e,r,{callee:t})},parseAsync:async function t(e,r){return await CC(this,e,r,{callee:t})},safeParse(t,e){return OC(this,t,e)},async safeParseAsync(t,e){return NC(this,t,e)},get spa(){return this?.safeParseAsync},set spa(t){A.own(this,"spa",t)},validate(t,e){return yd(this,t,e)},validateAsync(t,e){return vd(this,t,e)},encode:function t(e,r){return DC(this,e,r,{callee:t})},decode:function t(e,r){return zC(this,e,r,{callee:t})},encodeAsync:async function t(e,r){return await jC(this,e,r,{callee:t})},decodeAsync:async function t(e,r){return await MC(this,e,r,{callee:t})},safeEncode(t,e){return UC(this,t,e)},safeDecode(t,e){return LC(this,t,e)},async safeEncodeAsync(t,e){return FC(this,t,e)},async safeDecodeAsync(t,e){return VC(this,t,e)},toJSONSchema(t){return BR(this,{})(t)},get description(){return wr.get(this)?.description},get _def(){return this._zod.def}}),VS=S("_ZodString",(t,e)=>{Va.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>ZR(t,r,o,n)},A.derived({format:t=>Yt(t).format??null,minLength:t=>Yt(t).minimum??null,maxLength:t=>Yt(t).maximum??null},{regex(...t){return this.check(Pd(...t))},includes(...t){return this.check(Od(...t))},startsWith(...t){return this.check(Nd(...t))},endsWith(...t){return this.check(Dd(...t))},min(...t){return this.check(ra(...t))},max(...t){return this.check(Mu(...t))},length(...t){return this.check(Uu(...t))},nonempty(...t){return this.check(ra(1,...t))},lowercase(t){return this.check(Rd(t))},uppercase(t){return this.check(Cd(t))},trim(){return this.check(Ud())},normalize(...t){return this.check(Md(...t))},toLowerCase(){return this.check(Ld())},toUpperCase(){return this.check(Fd())},slugify(){return this.check(Vd())}})),Wd=S("ZodString",(t,e)=>{Va.init(t,e),VS.init(t,e)},{email(t){return this.check(vh(HS,t))},url(t){return this.check(Td(qh,t))},jwt(t){return this.check(Mh(ix,t))},emoji(t){return this.check(Eh(KS,t))},guid(t){return this.check(wh(BS,t))},uuid(t){return this.check(bh(Xi,t))},uuidv4(t){return this.check(_h(Xi,t))},uuidv6(t){return this.check(Sh(Xi,t))},uuidv7(t){return this.check(xh(Xi,t))},nanoid(t){return this.check(kh(qS,t))},cuid(t){return this.check(Ih(ZS,t))},cuid2(t){return this.check($h(WS,t))},ulid(t){return this.check(Ah(JS,t))},base64(t){return this.check(Dh(rx,t))},base64url(t){return this.check(zh(nx,t))},xid(t){return this.check(Th(GS,t))},ksuid(t){return this.check(Ph(XS,t))},ipv4(t){return this.check(Rh(YS,t))},ipv6(t){return this.check(Ch(QS,t))},cidrv4(t){return this.check(Oh(ex,t))},cidrv6(t){return this.check(Nh(tx,t))},e164(t){return this.check(jh(ox,t))},datetime(t){return this.check(Uh(Ga,t))},date(t){return this.check(Lh(Xa,t))},time(t){return this.check(Fh(Ya,t))},duration(t){return this.check(Vh(Qa,t))}});function I(t){return Q_(Wd,t)}var it=S("ZodStringFormat",(t,e)=>{Je.init(t,e),VS.init(t,e)}),Ga=S("ZodISODateTime",(t,e)=>{vR.init(t,e),it.init(t,e)}),Xa=S("ZodISODate",(t,e)=>{wR.init(t,e),it.init(t,e)}),Ya=S("ZodISOTime",(t,e)=>{bR.init(t,e),it.init(t,e)}),Qa=S("ZodISODuration",(t,e)=>{_R.init(t,e),it.init(t,e)}),HS=S("ZodEmail",(t,e)=>{Ab.init(t,e),it.init(t,e)});function eH(t){return vh(HS,t)}var BS=S("ZodGUID",(t,e)=>{Ib.init(t,e),it.init(t,e)});function tH(t){return wh(BS,t)}var Xi=S("ZodUUID",(t,e)=>{$b.init(t,e),it.init(t,e)});function rH(t){return bh(Xi,t)}function nH(t){return _h(Xi,t)}function oH(t){return Sh(Xi,t)}function iH(t){return xh(Xi,t)}var qh=S("ZodURL",(t,e)=>{Cb.init(t,e),it.init(t,e)});function sH(t){return Td(qh,t)}function aH(t){return Td(qh,{protocol:eh,hostname:CP,...A.normalizeParams(t)})}var KS=S("ZodEmoji",(t,e)=>{Ob.init(t,e),it.init(t,e)});function cH(t){return Eh(KS,t)}var qS=S("ZodNanoID",(t,e)=>{Nb.init(t,e),it.init(t,e)});function uH(t){return kh(qS,t)}var ZS=S("ZodCUID",(t,e)=>{Db.init(t,e),it.init(t,e)});function lH(t){return Ih(ZS,t)}var WS=S("ZodCUID2",(t,e)=>{zb.init(t,e),it.init(t,e)});function dH(t){return $h(WS,t)}var JS=S("ZodULID",(t,e)=>{jb.init(t,e),it.init(t,e)});function pH(t){return Ah(JS,t)}var GS=S("ZodXID",(t,e)=>{Mb.init(t,e),it.init(t,e)});function fH(t){return Th(GS,t)}var XS=S("ZodKSUID",(t,e)=>{Ub.init(t,e),it.init(t,e)});function mH(t){return Ph(XS,t)}var YS=S("ZodIPv4",(t,e)=>{Lb.init(t,e),it.init(t,e)});function hH(t){return Rh(YS,t)}var HC=S("ZodMAC",(t,e)=>{Vb.init(t,e),it.init(t,e)});function gH(t){return eS(HC,t)}var QS=S("ZodIPv6",(t,e)=>{Fb.init(t,e),it.init(t,e)});function yH(t){return Ch(QS,t)}var ex=S("ZodCIDRv4",(t,e)=>{Hb.init(t,e),it.init(t,e)});function vH(t){return Oh(ex,t)}var tx=S("ZodCIDRv6",(t,e)=>{Kb.init(t,e),it.init(t,e)});function wH(t){return Nh(tx,t)}var rx=S("ZodBase64",(t,e)=>{Zb.init(t,e),it.init(t,e)});function bH(t){return Dh(rx,t)}var nx=S("ZodBase64URL",(t,e)=>{Jb.init(t,e),it.init(t,e)});function _H(t){return zh(nx,t)}var ox=S("ZodE164",(t,e)=>{Gb.init(t,e),it.init(t,e)});function SH(t){return jh(ox,t)}var BC=S("ZodCreditCard",(t,e)=>{Yb.init(t,e),it.init(t,e)});function xH(t){return tS(BC,t)}var KC=S("ZodIBAN",(t,e)=>{e_.init(t,e),it.init(t,e)});function EH(t){return rS(KC,t)}var ix=S("ZodJWT",(t,e)=>{r_.init(t,e),it.init(t,e)});function kH(t){return Mh(ix,t)}var Vu=S("ZodCustomStringFormat",(t,e)=>{n_.init(t,e),it.init(t,e)});function IH(t,e,r={}){return qa(Vu,t,e,r)}function $H(t){return qa(Vu,"hostname",RP,t)}function AH(t){return qa(Vu,"hex",qP,t)}function TH(t){return qa(Vu,"currency_code",NP,t)}function PH(t,e){let r=e?.enc??"hex",o=`${t}_${r}`,n=Hn[o];if(!n)throw new Error(`Unrecognized hash format: ${o}`);return qa(Vu,o,n,e)}var Jd=S("ZodNumber",(t,e)=>{uh.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>WR(t,r,o,n),t.isFinite=!0},A.derived({minValue:t=>{let{minimum:e,exclusiveMinimum:r}=Yt(t);return Math.max(e??Number.NEGATIVE_INFINITY,r??Number.NEGATIVE_INFINITY)},maxValue:t=>{let{maximum:e,exclusiveMaximum:r}=Yt(t);return Math.min(e??Number.POSITIVE_INFINITY,r??Number.POSITIVE_INFINITY)},isInt:t=>{let{isInt:e,multipleOf:r}=Yt(t);return!!e||!!r?.some(Number.isSafeInteger)},format:t=>Yt(t).format??null},{gt(t,e){return this.check(Ji(t,e))},gte(t,e){return this.check(Kn(t,e))},min(t,e){return this.check(Kn(t,e))},lt(t,e){return this.check(Wi(t,e))},lte(t,e){return this.check(Bn(t,e))},max(t,e){return this.check(Bn(t,e))},int(t){return this.check(LS(t))},safe(t){return this.check(LS(t))},positive(t){return this.check(Ji(0,t))},nonnegative(t){return this.check(Kn(0,t))},negative(t){return this.check(Wi(0,t))},nonpositive(t){return this.check(Bn(0,t))},multipleOf(t,e){return this.check(Ba(t,e))},step(t,e){return this.check(Ba(t,e))},finite(){return this}}));function Ze(t){return nS(Jd,t)}var Hu=S("ZodNumberFormat",(t,e)=>{o_.init(t,e),Jd.init(t,e)});function LS(t){return oS(Hu,t)}function RH(t){return iS(Hu,t)}function CH(t){return sS(Hu,t)}function OH(t){return aS(Hu,t)}function NH(t){return cS(Hu,t)}var Gd=S("ZodBoolean",(t,e)=>{_d.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>JR(t,r,o,n)});function Vt(t){return uS(Gd,t)}var Xd=S("ZodBigInt",(t,e)=>{lh.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>GR(t,r,o,n)},A.derived({minValue:t=>Yt(t).minimum??null,maxValue:t=>Yt(t).maximum??null,format:t=>Yt(t).format??null},{gte(t,e){return this.check(Kn(t,e))},min(t,e){return this.check(Kn(t,e))},gt(t,e){return this.check(Ji(t,e))},lt(t,e){return this.check(Wi(t,e))},lte(t,e){return this.check(Bn(t,e))},max(t,e){return this.check(Bn(t,e))},positive(t){return this.check(Ji(BigInt(0),t))},negative(t){return this.check(Wi(BigInt(0),t))},nonpositive(t){return this.check(Bn(BigInt(0),t))},nonnegative(t){return this.check(Kn(BigInt(0),t))},multipleOf(t,e){return this.check(Ba(t,e))}}));function DH(t){return lS(Xd,t)}var sx=S("ZodBigIntFormat",(t,e)=>{i_.init(t,e),Xd.init(t,e)});function zH(t){return dS(sx,t)}function jH(t){return pS(sx,t)}var qC=S("ZodSymbol",(t,e)=>{s_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>XR(t,r,o,n)});function MH(t){return fS(qC,t)}var ZC=S("ZodUndefined",(t,e)=>{a_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>QR(t,r,o,n)});function UH(t){return mS(ZC,t)}var WC=S("ZodNull",(t,e)=>{c_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>YR(t,r,o,n)});function Zh(t){return hS(WC,t)}var JC=S("ZodAny",(t,e)=>{u_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>rC(t,r,o,n)});function LH(){return gS(JC)}var GC=S("ZodUnknown",(t,e)=>{l_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>nC(t,r,o,n)});function ut(){return yS(GC)}var XC=S("ZodNever",(t,e)=>{d_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>tC(t,r,o,n)});function ax(t){return vS(XC,t)}var YC=S("ZodVoid",(t,e)=>{p_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>eC(t,r,o,n)});function FH(t){return wS(YC,t)}var Wh=S("ZodDate",(t,e)=>{f_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>oC(t,r,o,n),t.min=(r,o)=>t.check(Kn(r,o)),t.max=(r,o)=>t.check(Bn(r,o))},A.derived({minDate:t=>{let{minimum:e}=Yt(t);return e?new Date(e):null},maxDate:t=>{let{maximum:e}=Yt(t);return e?new Date(e):null}},{}));function VH(t){return bS(Wh,t)}var QC=S("ZodArray",(t,e)=>{Fu(),m_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>gC(t,r,o,n),t.element=e.element},{min(t,e){return this.check(ra(t,e))},nonempty(t){return this.check(ra(1,t))},max(t,e){return this.check(Mu(t,e))},length(t,e){return this.check(Uu(t,e))},unwrap(){return this.element}});function Ae(t,e){return VR(QC,t,e)}function HH(t){let e=t._zod.def.shape;return _r(Object.keys(e))}var Jh=S("ZodObject",(t,e)=>{Fu(),xR.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>yC(t,r,o,n),A.installLazyProp(t,"shape",r=>r._zod.def.shape,!1)},{keyof(){return _r(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:ut()}))},loose(){return this.clone(A.mergeDefs(this._zod.def,{catchall:ut()}))},strict(){return this.clone(A.mergeDefs(this._zod.def,{catchall:ax()}))},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(Bu,this,t[0])},exactPartial(...t){return A.partial(ux,this,t[0],"exactPartial")},required(...t){return A.required(lx,this,t[0])}});function H(t,e){let r={type:"object",shape:t??{},...A.normalizeParams(e)};return new Jh(r)}function BH(t,e){return new Jh({type:"object",shape:t,catchall:ax(),...A.normalizeParams(e)})}function br(t,e){return new Jh({type:"object",shape:t,catchall:ut(),...A.normalizeParams(e)})}var Gh=S("ZodUnion",(t,e)=>{Sd.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>DS(t,r,o,n),t.options=e.options});function tt(t,e){return new Gh({type:"union",options:t,...A.normalizeParams(e)})}var eO=S("ZodXor",(t,e)=>{Gh.init(t,e),g_.init(t,e),t._zod.processJSONSchema=(r,o,n)=>DS(t,r,o,n),t.options=e.options});function KH(t,e){return new eO({type:"union",options:t,inclusive:!1,...A.normalizeParams(e)})}var tO=S("ZodDiscriminatedUnion",(t,e)=>{Gh.init(t,e),y_.init(t,e)});function Xh(t,e,r){return new tO({type:"union",options:e,discriminator:t,...A.normalizeParams(r)})}var rO=S("ZodIntersection",(t,e)=>{v_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>vC(t,r,o,n)});function Yd(t,e){return new rO({type:"intersection",left:t,right:e})}var nO=S("ZodTuple",(t,e)=>{Fu(),dh.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>wC(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 Bu({type:"optional",innerType:e}))})}});function oO(t,e,r){let o=e instanceof ae,n=o?r:e,i=o?e:null;return new nO({type:"tuple",items:t,rest:i,...A.normalizeParams(n)})}var qd=S("ZodRecord",(t,e)=>{Fu(),w_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>bC(t,r,o,n),t.keyType=e.keyType,t.valueType=e.valueType});function st(t,e,r){return!e||!e._zod?new qd({type:"record",keyType:I(),valueType:t,...A.normalizeParams(e)}):new qd({type:"record",keyType:t,valueType:e,...A.normalizeParams(r)})}function qH(t,e,r){return new qd({type:"record",keyType:t,valueType:e,...A.normalizeParams(r),partial:!0})}function ZH(t,e,r){return new qd({type:"record",keyType:t,valueType:e,mode:"loose",...A.normalizeParams(r)})}var iO=S("ZodMap",(t,e)=>{Fu(),b_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>mC(t,r,o,n),t.keyType=e.keyType,t.valueType=e.valueType,t.min=(...r)=>t.check(Gi(...r)),t.nonempty=r=>t.check(Gi(1,r)),t.max=(...r)=>t.check(Ka(...r)),t.size=(...r)=>t.check(ju(...r))});function WH(t,e,r){return new iO({type:"map",keyType:t,valueType:e,...A.normalizeParams(r)})}var sO=S("ZodSet",(t,e)=>{Fu(),__.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>hC(t,r,o,n),t.min=(...r)=>t.check(Gi(...r)),t.nonempty=r=>t.check(Gi(1,r)),t.max=(...r)=>t.check(Ka(...r)),t.size=(...r)=>t.check(ju(...r))});function JH(t,e){return new sO({type:"set",valueType:t,...A.normalizeParams(e)})}var Zd=S("ZodEnum",(t,e)=>{S_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(o,n,i)=>iC(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 Zd({...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 Zd({...e,checks:[],...A.normalizeParams(n),entries:i})}});function _r(t,e){let r=Array.isArray(t)?Object.fromEntries(t.map(o=>[o,o])):t;return new Zd({type:"enum",entries:r,...A.normalizeParams(e)})}function GH(t,e){return new Zd({type:"enum",entries:t,...A.normalizeParams(e)})}var aO=S("ZodLiteral",(t,e)=>{x_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>sC(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 aO({type:"literal",values:Array.isArray(t)?t:[t],...A.normalizeParams(e)})}var cO=S("ZodFile",(t,e)=>{E_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>uC(t,r,o,n),t.min=(r,o)=>t.check(Gi(r,o)),t.max=(r,o)=>t.check(Ka(r,o)),t.mime=(r,o)=>t.check(jd(Array.isArray(r)?r:[r],o))});function XH(t){return $S(cO,t)}var uO=S("ZodTransform",(t,e)=>{Fu(),k_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>fC(t,r,o,n),t._zod.parse=(r,o)=>{if(o.direction==="backward")throw new Fa(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 cx(t){return new uO({type:"transform",transform:t})}var Bu=S("ZodOptional",(t,e)=>{ph.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>zS(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function ot(t){return new Bu({type:"optional",innerType:t})}var ux=S("ZodExactOptional",(t,e)=>{I_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>zS(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function lO(t){return new ux({type:"optional",innerType:t})}var dO=S("ZodNullable",(t,e)=>{$_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>_C(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function Kh(t){return new dO({type:"nullable",innerType:t})}function YH(t){return ot(Kh(t))}var pO=S("ZodDefault",(t,e)=>{A_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>EC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType,t.removeDefault=t.unwrap});function fO(t,e){return new pO({type:"default",innerType:t,get defaultValue(){return typeof e=="function"?e():A.shallowClone(e)}})}var mO=S("ZodPrefault",(t,e)=>{T_.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 hO(t,e){return new mO({type:"prefault",innerType:t,get defaultValue(){return typeof e=="function"?e():A.shallowClone(e)}})}var lx=S("ZodNonOptional",(t,e)=>{P_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>SC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function gO(t,e){return new lx({type:"nonoptional",innerType:t,...A.normalizeParams(e)})}var yO=S("ZodSuccess",(t,e)=>{R_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>lC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function QH(t){return new yO({type:"success",innerType:t})}var vO=S("ZodCatch",(t,e)=>{C_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>IC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType,t.removeCatch=t.unwrap});function wO(t,e){return new vO({type:"catch",innerType:t,catchValue:typeof e=="function"?e:A.constantCatch(e)})}var bO=S("ZodNaN",(t,e)=>{O_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>aC(t,r,o,n)});function eB(t){return _S(bO,t)}var Yh=S("ZodPipe",(t,e)=>{fh.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>$C(t,r,o,n),t.in=e.in,t.out=e.out});function FS(t,e){return new Yh({type:"pipe",in:t,out:e})}var Qh=S("ZodCodec",(t,e)=>{Yh.init(t,e),xd.init(t,e)});function tB(t,e,r){return new Qh({type:"pipe",in:t,out:e,transform:r.decode,reverseTransform:r.encode})}function rB(t){let e=t._zod.def;return new Qh({type:"pipe",in:e.out,out:e.in,transform:e.reverseTransform,reverseTransform:e.transform})}var _O=S("ZodPreprocess",(t,e)=>{Yh.init(t,e),kR.init(t,e)}),SO=S("ZodReadonly",(t,e)=>{N_.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 xO(t){return new SO({type:"readonly",innerType:t})}var EO=S("ZodTemplateLiteral",(t,e)=>{D_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>cC(t,r,o,n)});function nB(t,e){return new EO({type:"template_literal",parts:t,...A.normalizeParams(e)})}var kO=S("ZodLazy",(t,e)=>{Ed.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>PC(t,r,o,n),t.unwrap=()=>t._zod.def.getter()});function IO(t){return new kO({type:"lazy",getter:t})}var $O=S("ZodPromise",(t,e)=>{j_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>TC(t,r,o,n),t.unwrap=()=>t._zod.def.innerType});function oB(t){return new $O({type:"promise",innerType:t})}var AO=S("ZodFunction",(t,e)=>{z_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>pC(t,r,o,n)});function iB(t){return new AO({type:"function",input:Array.isArray(t?.input)?oO(t?.input):t?.input??Ae(ut()),output:t?.output??ut()})}var eg=S("ZodCustom",(t,e)=>{M_.init(t,e),ge.init(t,e),t._zod.processJSONSchema=(r,o,n)=>dC(t,r,o,n)});function sB(t){let e=new nt({check:"custom"});return e._zod.check=t,e}function dx(t,e){return AS(eg,t??(()=>!0),e)}function TO(t,e={}){return TS(eg,t,e)}function PO(t,e){return PS(t,e)}var aB=RS,cB=CS,RO=S("ZodInstanceOf",(t,e)=>{eg.init(t,e)},{properties(t,e){return this.check(zd(t,e))}});function uB(t,e={}){let r=new RO({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 lB=(...t)=>OS({Codec:Qh,Boolean:Gd,String:Wd},...t);function dB(t){let e=IO(()=>tt([I(t),Ze(),Vt(),Zh(),Ae(e),st(I(),e)]));return e}function tg(t,e){return new _O({type:"pipe",in:cx(t),out:e})}var xme={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 Eme(t){zt({customError:t})}function kme(){return zt().customError}var CO;CO||(CO={});var Ku={};yt(Ku,{ZodISODate:()=>Xa,ZodISODateTime:()=>Ga,ZodISODuration:()=>Qa,ZodISOTime:()=>Ya,date:()=>$me,datetime:()=>Ime,duration:()=>Tme,time:()=>Ame});function Ime(t){return Uh(Ga,t)}function $me(t){return Lh(Xa,t)}function Ame(t){return Fh(Ya,t)}function Tme(t){return Vh(Qa,t)}var V={...Qd,...MS,iso:Ku},Pme=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 Rme(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 pB(t,e){return t.map((r,o)=>o<e?r:r.optional())}function Cme(t){return t.replace(/~1/g,"/").replace(/~0/g,"~")}function Ome(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:Cme(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 Nme(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 OO(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=OO(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=OO(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 Dme=new Set(["items","prefixItems","additionalItems","additionalProperties","contains","propertyNames","not","if","then","else","allOf","anyOf","oneOf","unevaluatedItems","unevaluatedProperties","contentSchema"]),zme=new Set(["properties","patternProperties","dependentSchemas","dependencies","$defs","definitions"]);function rg(t){return typeof t!="object"||t===null?!1:Array.isArray(t)?t.some(rg):typeof t.$ref=="string"?!0:Object.entries(t).some(([e,r])=>Dme.has(e)?rg(r):!zme.has(e)||typeof r!="object"||r===null?!1:Object.values(r).some(rg))}function fB(t){return t===1?"element":"elements"}function jme(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=OO(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 ${fB(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 ${fB(e.maxContains)}`,input:n,continue:!0})}}}).pipe(t)}function mB(t,e){if(t!==!1)return t===void 0||t===!0?V.any():dn(t,e)}var Mme=/^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/;function hB(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=Ome(n,e),s=dn(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 hB(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(Mme)):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"?dn(t.additionalProperties,e):void 0;for(let[d,f]of Object.entries(i)){let p=dn(f,e);vr(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=dn(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(!mo(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=dn(f,e)}o=Nme(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=>dn(d,e)),c=pB(a,s),u=Array.isArray(i)?void 0:mB(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=>dn(d,e)),c=pB(a,s),u=mB(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=dn(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=jme(o,{uniqueItems:t.uniqueItems===!0,containsSchema:t.contains!==void 0?dn(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 dn(t,e){if(typeof t=="boolean")return t?V.any():V.never();let r=hB(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=>dn(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=>dn(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:dn(t.allOf[0],e),c=o?0:1;for(let u=c;u<t.allOf.length;u++)a=V.intersection(a,dn(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&&!rg(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&&!rg(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))Pme.has(a)||vr(n,a,t[a]);return Object.keys(n).length>0&&e.registry.add(r,n),t.description&&(r=r.describe(t.description)),r}function gB(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=Rme(r,e?.defaultTarget),n=r.$defs||r.definitions||{},i={version:o,defs:n,refs:new Map,processing:new Set,rootSchema:r,registry:e?.registry??wr};return dn(r,i)}var yB=Symbol("z.visit/resolving");function ng(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===yB)return new Ed({type:"lazy",getter:()=>o.get(s)});if(a!==void 0)return a;o.set(s,yB);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 vB(t){return ng(t,{object:e=>e.partial(),union:e=>{let r=e._zod.def;return r.discriminator===void 0?e:tt(r.options)}})}function Ume(t,e){if(!e?.length)return t;let r=t._zod.def;return qe(t,fo(r,{checks:[...r.checks??[],...e]}),{parent:!0})}function wB(t){return Ume(t.out,t.checks)}function Lme(t){return t.in._zod.traits.has("$ZodTransform")?wB(t):t.in}function bB(t){return ng(t,{pipe:e=>Lme(e._zod.def),default:(e,r)=>r?ot(e._zod.def.innerType):e,catch:(e,r)=>r?e._zod.def.innerType:e})}function _B(t){return ng(t,{pipe:e=>wB(e._zod.def),prefault:(e,r)=>r?e._zod.def.innerType:e})}var NO={};yt(NO,{bigint:()=>Bme,boolean:()=>Hme,date:()=>Kme,number:()=>Vme,string:()=>Fme});function Fme(t){return zR(Wd,t)}function Vme(t){return MR(Jd,t)}function Hme(t){return UR(Gd,t)}function Bme(t){return LR(Xd,t)}function Kme(t){return FR(Wh,t)}var og={name:"@tomato414941/foundation",version:"29.0.3",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 SB(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 ig=h.string().trim().max(8192).refine(t=>SB(t)!==null,"Use an OpenSSH public key from a .pub file.");function DO(t){if(!SB(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 ep=h.string().max(32).regex(/^[a-z_][a-z0-9_-]*$/,"Use a lowercase account name."),px=h.string().min(1).max(253).regex(/^[A-Za-z0-9_.:]+(?:-[A-Za-z0-9_.:]+)*$/,"Use a host name or IP address."),fx=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."),yFe=h.string().min(1).max(500).regex(/^[A-Za-z0-9.:*?/!_-]+(?:,[A-Za-z0-9.:*?/!_-]+)*$/,"Use comma-separated host or address patterns."),mx=h.string().regex(/^SHA256:[A-Za-z0-9+/]{43}$/);var tp=new TextEncoder,rp=new TextDecoder,xB=new TextDecoder("utf-8",{fatal:!0}),hx=2**32;function pn(...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 zO(t,e,r){if(e<0||e>=hx)throw new RangeError(`value must be >= 0 and <= ${hx-1}. Received ${e}`);t.set([e>>>24,e>>>16,e>>>8,e&255],r)}function jO(t){let e=Math.floor(t/hx),r=t%hx,o=new Uint8Array(8);return zO(o,e,0),zO(o,r,4),o}function gx(t){let e=new Uint8Array(4);return zO(e,t),e}var Zme=/[^\x00-\x7f]/;function Sr(t){if(typeof t=="string"&&t.length>=128){if(Zme.test(t))throw new TypeError("non-ASCII string encountered in encode()");return tp.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 EB(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 kB(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 yx(t,e){let r=`SHA-${t.slice(-3)}`;return new Uint8Array(await crypto.subtle.digest(r,e))}var na=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 qu=class extends na{static code="ERR_JOSE_ALG_NOT_ALLOWED";code="ERR_JOSE_ALG_NOT_ALLOWED"},at=class extends na{static code="ERR_JOSE_NOT_SUPPORTED";code="ERR_JOSE_NOT_SUPPORTED"},ec=class extends na{static code="ERR_JWE_DECRYPTION_FAILED";code="ERR_JWE_DECRYPTION_FAILED";constructor(e="decryption operation failed",r){super(e,r)}},U=class extends na{static code="ERR_JWE_INVALID";code="ERR_JWE_INVALID"},xt=class extends na{static code="ERR_JWS_INVALID";code="ERR_JWS_INVALID"};var sg=class extends na{static code="ERR_JWK_INVALID";code="ERR_JWK_INVALID"};var vx=class extends na{static code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";constructor(e="signature verification failed",r){super(e,r)}};var Wme="The input to be decoded is not correctly encoded.";function Zu(t){try{return kB(typeof t=="string"?t:rp.decode(t),!0)}catch(e){throw new TypeError(Wme,{cause:e})}}function Rt(t){return EB(typeof t=="string"?tp.encode(t):t,!0)}function qn(t,e){if(!(t instanceof Uint8Array))throw new TypeError(`${e} must be an instance of Uint8Array`)}function Kt(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 tc(...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 go(t,e){if(t!==void 0)throw new TypeError(`${e} can only be called once`)}function Tn(t,e,r){try{return Zu(t)}catch{throw new r(`Failed to base64url decode the ${e}`)}}function wx(t,e,r){try{return Sr(t)}catch{throw new r(`The ${e} is not a valid base64url string`)}}function np(t,e,r){let o;try{o=JSON.parse(xB.decode(Zu(t)))}catch{throw new e(r)}if(!Kt(o))throw new e(r);return o}var bx={__proto__:null,b64:!0},_x={__proto__:null};function ag(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 Sx(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 rc(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 at(`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 xx(t,e){if(e.includes("b64")){let r=t.b64;if(typeof r!="boolean")throw new xt('The "b64" (base64url-encode payload) Header Parameter must be a boolean');return r}return!0}function Wu(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(!Kt(o))throw new t("JOSE Header is not a JSON object");return[o,r]}var Jme=t=>t[Symbol.toStringTag],Gme=(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 ti(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(Kt(e)){if(s=HO(e),typeof s.kty!="string")throw IB(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(Gme(t,s,r),s.kty==="oct")return Zu(s.k);if(!Object.isFrozen(e)){let{key_ops:l}=e;Array.isArray(l)&&Object.freeze(l),Object.freeze(e)}}else{if(!LO(e))throw IB(o,e,n);let l=n?"secret":i?"private":"public";if(e.type!==l&&(n||["secret","public","private"].includes(e.type)))throw new TypeError(`${Jme(e)} instances must be of type "${l}" for the ${o} algorithm`);if(nc(e))return e;if(a=e,a.type==="secret")return a.export()}MO||=new WeakMap;let c=e,u=MO.get(c);if(u?.[o])return u[o];if(u||MO.set(c,u={}),a&&typeof a.toCryptoKey=="function"){let l=a.type==="public",d=Xme[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 ip(t,s)}var MO,Xme={__proto__:null,prime256v1:"P-256",secp384r1:"P-384",secp521r1:"P-521"};function kx(t){if(!nc(t))throw new Error("CryptoKey instance expected")}var nc=t=>{if(t?.[Symbol.toStringTag]==="CryptoKey")return!0;try{return t instanceof CryptoKey}catch{return!1}},UO=t=>t?.[Symbol.toStringTag]==="KeyObject",LO=t=>nc(t)||UO(t);function $B(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 oa=(t,...e)=>$B("Key must be ",t,...e);function IB(t,e,r){let o=["CryptoKey","KeyObject","JSON Web Key"];return r&&o.push("Uint8Array"),new TypeError($B(`Key for the ${t} algorithm must be `,e,...o))}var Ex=(t,e="algorithm.name")=>new TypeError(`CryptoKey does not support this operation, its ${e} must be ${t}`);function FO(t,e){if(e&&!t.usages.includes(e))throw new TypeError(`CryptoKey does not support this operation, its usages must include ${e}.`)}function op(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 VO(t,e,r){let o=t.algorithm;if(o.name!==e.name)throw Ex(e.name);if(e.hash&&o.hash?.name!==e.hash)throw Ex(e.hash,"algorithm.hash");if(e.namedCurve&&o.namedCurve!==e.namedCurve)throw Ex(e.namedCurve,"algorithm.namedCurve");if(e.length!==void 0&&o.length!==e.length)throw Ex(e.length,"algorithm.length");FO(t,r)}function Ix(t){return{__proto__:null,...t}}function HO(t){let e=Ix(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 $x(t){if(t!==void 0&&typeof t!="boolean")throw new TypeError('"extractable" option must be a boolean');return t}async function ip(t,e,r){if(!t.kty.includes(e.kty))throw new at('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 ri(t,e,r,o=!1){return t instanceof Uint8Array&&(t=await crypto.subtle.importKey("raw",t,e,o,[r])),VO(t,e,r),t}var Ju=t=>crypto.getRandomValues(new Uint8Array(t.cekBits>>3));function Ax(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 Yme=t=>crypto.getRandomValues(new Uint8Array(t.ivBits>>3));function AB(t,e){if(e.length<<3!==t.ivBits)throw new U("Invalid Initialization Vector length")}async function TB(t,e,r){if(!(e instanceof Uint8Array))throw new TypeError(oa(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 PB(t,e,r){return new Uint8Array((await crypto.subtle.sign("HMAC",t,e)).slice(0,r>>3))}async function Qme(t,e,r,o,n){let[i,s,a]=await TB(t,r,"encrypt"),c=new Uint8Array(await crypto.subtle.encrypt({iv:o,name:"AES-CBC"},i,e)),u=pn(n,o,c,jO(n.length*8)),l=await PB(s,u,a);return{ciphertext:c,tag:l,iv:o}}async function ehe(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 the(t,e,r,o,n,i){let[s,a,c]=await TB(t,e,"decrypt"),u=pn(i,o,r,jO(i.length*8)),l=await PB(a,u,c);try{if(await ehe(n,l))return new Uint8Array(await crypto.subtle.decrypt({iv:o,name:"AES-CBC"},s,r))}catch{}throw new ec}async function Tx(t,e,r,o,n){if(!nc(r)&&!(r instanceof Uint8Array))throw new TypeError(oa(r,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(o?AB(t,o):o=Yme(t),r instanceof Uint8Array&&Ax(r,t.cekBits),t.cbc)return Qme(t,e,r,o,n);let i=await ri(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 Px(t,e,r,o,n,i){if(!nc(e)&&!(e instanceof Uint8Array))throw new TypeError(oa(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(AB(t,o),e instanceof Uint8Array&&Ax(e,t.cekBits),t.cbc)return the(t,e,r,o,n,i);let s=await ri(e,t.subtle,"decrypt");try{return new Uint8Array(await crypto.subtle.decrypt({additionalData:i,iv:o,name:"AES-GCM",tagLength:128},s,pn(r,n)))}catch{throw new ec}}function cg(t){let e={__proto__:null};for(let r in t)e[r]={...t[r],alg:r};return e}var rhe=[["encrypt","wrapKey"],["decrypt","unwrapKey"]],nhe=[[],["deriveBits"]],Ox=[[],[]];function Rx(t){return{kty:["RSA"],mode:"key-encryption",subtle:{name:"RSA-OAEP",hash:`SHA-${t}`},usages:rhe,ops:["wrapKey","unwrapKey"]}}function Cx(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 at('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');return{name:"ECDH",namedCurve:r}},usages:nhe,ops:[void 0,"deriveBits"]}}function sp(t,e=!1){return{kty:["oct"],mode:"key-wrapping",secret:!0,subtle:{name:e?"AES-GCM":"AES-KW",length:t},usages:Ox,ops:e?["encrypt","decrypt"]:["wrapKey","unwrapKey"]}}function BO(){return{kty:["oct"],mode:"key-wrapping",secret:!0,subtle:{name:"PBKDF2"},usages:Ox,ops:["deriveBits","deriveBits"]}}var ia=cg({dir:{kty:["oct"],mode:"direct-encryption",secret:!0,subtle:{name:"AES-GCM"},usages:Ox,ops:["encrypt","decrypt"]},"RSA-OAEP":Rx(1),"RSA-OAEP-256":Rx(256),"RSA-OAEP-384":Rx(384),"RSA-OAEP-512":Rx(512),"ECDH-ES":Cx("direct-key-agreement"),"ECDH-ES+A128KW":Cx("key-agreement-with-key-wrapping"),"ECDH-ES+A192KW":Cx("key-agreement-with-key-wrapping"),"ECDH-ES+A256KW":Cx("key-agreement-with-key-wrapping"),A128KW:sp(128),A192KW:sp(192),A256KW:sp(256),A128GCMKW:sp(128,!0),A192GCMKW:sp(192,!0),A256GCMKW:sp(256,!0),"PBES2-HS256+A128KW":BO(),"PBES2-HS384+A192KW":BO(),"PBES2-HS512+A256KW":BO()}),ohe=["encrypt","decrypt"];function ap(t,e=!1){return{kty:["oct"],secret:!0,subtle:{name:e?"AES-CBC":"AES-GCM",length:t},usages:Ox,ops:ohe,cekBits:t,ivBits:e?128:96,cbc:e}}var ihe=cg({A128GCM:ap(128),A192GCM:ap(192),A256GCM:ap(256),"A128CBC-HS256":ap(256,!0),"A192CBC-HS384":ap(384,!0),"A256CBC-HS512":ap(512,!0)});function RB(t,e){throw new at(`Invalid or unsupported "${t}" (JWE ${e}) header value`)}function ni(t){return(typeof t=="string"?ia[t]:void 0)??RB("alg","Algorithm")}function oi(t){return t.mode==="key-wrapping"||t.mode==="key-encryption"||t.mode==="key-agreement-with-key-wrapping"}function Gu(t){return(typeof t=="string"?ihe[t]:void 0)??RB("enc","Encryption Algorithm")}function CB(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");FO(t,e)}async function she(t,e,r){let o=await ri(e,ni(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 ahe(t,e,r){let o=await ri(e,ni(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 NB(t,e,r){VO(e,ni(t).subtle,r),op(t,e)}async function DB(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=pn(Sr(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 ri(o,ni(e).subtle,"deriveBits");return new Uint8Array(await crypto.subtle.deriveBits(s,a,i))}function KO(t){return pn(gx(t.length),t)}async function che(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 yx("sha256",pn(gx(a),t,r));s.set(c,(a-1)*n)}return s.slice(0,o)}async function zB(t,e,r,o,n=new Uint8Array,i=new Uint8Array){CB(t),CB(e,"deriveBits");let s=pn(KO(Sr(r)),KO(n),KO(i),gx(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 che(a,o,s)}function jB(t){kx(t);let e=t.algorithm.namedCurve;if(e!=="P-256"&&e!=="P-384"&&e!=="P-521"&&t.algorithm.name!=="X25519")throw new at("ECDH with the provided key is not allowed or not supported by your javascript runtime")}function Nx(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 Tn(r,e,U)}}function MB(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 uhe(t){if(t===void 0)throw new U("JWE Encrypted Key missing")}function OB(t){if(t!==void 0)throw new U("Encountered unexpected JWE Encrypted Key")}function lhe(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 UB(t,e,r,o,n,i){let{alg:s}=t,a=t.mode;if(a==="direct-encryption")return OB(o),r;let c=a==="direct-key-agreement";switch(c?OB(o):uhe(o),t.subtle.name){case"ECDH":{let{epk:u}=n;if(!Kt(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');jB(r);let l=await ip(t,u),d=Nx(n,"apu"),f=Nx(n,"apv");MB(d,f);let p=await zB(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 kx(r),NB(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');lhe(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=Tn(n.p2s,"p2s",U);r=await DB(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=Tn(n.iv,"iv",U),l=Tn(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 Px(Gu(s.slice(0,-2)),r,o,u,l,new Uint8Array)}}return ahe(s.slice(-6),r,o)}async function Dx(t,e,r,o,n,i={}){let{alg:s,mode:a}=t,c=oi(t);if(n!==void 0&&!c)throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${s}`);let u=await ti(a==="direct-encryption"?e:t,r,"encrypt");if(a==="direct-encryption")return[u,void 0,void 0];let l=c?n??Ju(e):void 0;l&&Ax(l,e.cekBits);let d,f;switch(t.subtle.name){case"ECDH":{jB(u);let{apu:p,apv:m}=i;p!==void 0&&qn(p,'"apu"'),m!==void 0&&qn(m,'"apv"');let g=p??Nx(o,"apu"),y=m??Nx(o,"apv");MB(g,y);let w;i.epk!==void 0?w=await ti(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 zB(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":{kx(u),NB(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 DB(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 Tx(Gu(s.slice(0,-2)),l,u,p,new Uint8Array);d=m.ciphertext,f={iv:Rt(m.iv),tag:Rt(m.tag)}}}if(d??=await she(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 zx(t,e){if(t.zip!==void 0&&t.zip!=="DEF")throw new at('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 LB(t){if(typeof globalThis[t]>"u")throw new at(`JWE "zip" (Compression Algorithm) Header Parameter requires the ${t} API.`)}async function FB(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 pn(...n)}async function VB(t){return LB("CompressionStream"),FB(new CompressionStream("deflate-raw"),t)}async function HB(t,e){return LB("DecompressionStream"),FB(new DecompressionStream("deflate-raw"),t,e)}function BB(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&&!Kt(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 KB(t){let e,r;try{let{header:o}=t;if(Kt(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 qB(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&&!Kt(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 qO(t){let{protected:e,ciphertext:r,iv:o,tag:n,aad:i}=t,s;return e!==void 0&&(s=np(e,U,"JWE Protected Header is invalid")),[s,Tn(r,"ciphertext",U),o!==void 0?Tn(o,"iv",U):void 0,n!==void 0?Tn(n,"tag",U):void 0,wx((e??"")+(i!==void 0?`.${i}`:""),"aad",U)]}function jx(t){return[t&&ag("keyManagementAlgorithms",t.keyManagementAlgorithms),t&&ag("contentEncryptionAlgorithms",t.contentEncryptionAlgorithms),t?.crit,t?.maxPBES2Count,t?.maxDecompressedLength]}async function ZO(t,e,r,o=qO(t)){let[n,i,s,a,c]=o,{header:u,unprotected:l,aad:d}=t,f;if(u!==void 0||l!==void 0){if(!tc(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;rc(U,_x,g,n,f),zx(f,n);let{alg:_,enc:k}=f;if(typeof _!="string"||!_)throw new U("missing JWE Algorithm (alg) in JWE Header");let $=ia[_];if(b===""&&(!$||!oi($)))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 qu('"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 qu('"enc" (Encryption Algorithm) Header Parameter value not allowed');K=Gu(k)}let te;if(b!==void 0)try{te=Tn(b,"encrypted_key",U)}catch($e){if(!$||!oi($))throw $e;te=new Uint8Array}let Ie=!1;typeof r=="function"&&(r=await r(n,t),Ie=!0);let xe=$??ni(_);oi(xe)&&te===void 0&&(te=new Uint8Array);let Qe=await ti(xe.mode==="direct-encryption"?K:xe,r,"decrypt"),Fe;if(xe.mode==="integrated-encryption")Fe=await xe.decrypt(Qe,te,i,c,n,f);else{let $e=K,J;try{J=await UB(xe,$e,Qe,te,f,y),oi(xe)&&J instanceof Uint8Array&&J.byteLength<<3!==$e.cekBits&&(J=Ju($e))}catch(Tt){if(Tt instanceof TypeError||Tt instanceof U||Tt instanceof at)throw Tt;J=Ju($e)}Fe=await Px($e,J,i,s,a,c)}if(f.zip==="DEF"){let $e=w??25e4;if($e===0)throw new at('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");Fe=await HB(Fe,$e).catch(J=>{throw J instanceof U?J:new U("Failed to decompress plaintext",{cause:J})})}return{plaintext:Fe,...n&&{protectedHeader:n},...d!==void 0&&{additionalAuthenticatedData:Tn(d,"aad",U)},...l&&{sharedUnprotectedHeader:l},...u&&{unprotectedHeader:u},...Ie&&{key:Qe}}}async function ZB(t,e,r){if(t instanceof Uint8Array&&(t=rp.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 ZO({ciphertext:s,iv:i||void 0,protected:o,tag:a||void 0,encrypted_key:n||void 0},e,r)}async function ug(t,e,r){return ZB(t,jx(r),e)}async function WO(t,e,r){if(!Kt(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(Kt))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=jx(r),s=BB(t),a=qO(s)}catch{throw new ec}let c=n.map(u=>KB(u));if(n.length>1)for(let[,u]of c){let l=a[0]?.alg??u??s.unprotected?.alg,d=typeof l=="string"?ia[l]:void 0;if(d&&!oi(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 qB(l),await ZO(l,i,e,a)}catch{}throw new ec}function Mx(t,e,r){if(!tc(t,e,r))throw new U("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint")}function JO(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&&qn(s,"JWE Additional Authenticated Data"),a!==void 0&&qn(a,"JWE Content Encryption Key"),c!==void 0&&qn(c,"JWE Initialization Vector"),!r&&o!==void 0&&(o=Wu(U,o)[0],t[1]=o),n!==void 0&&(n=Wu(U,n)[0],t[2]=n),!r&&i!==void 0&&(i=Wu(U,i)[0],t[3]=i),u!==void 0&&!Kt(u))throw new TypeError("JWE Key Management Parameters must be an object");Mx(o,n,i);let d={...o,...n,...i};Sx(U,o),rc(U,_x,l,o,d),zx(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=ia[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,Gu(p),m]}async function GO(t,e,r){let[o,n,i]=e,[s,a,c,u,l,d,f,p,,m]=t,g=a,y=c,w=i??ni(o.alg),b,_,k;w.mode==="integrated-encryption"?k=await ti(w,r,"encrypt"):[k,b,_]=await Dx(w,n,r,o,d,p),_&&(m?y=y?{...y,..._}:_:g=g?{...g,..._}:_,Mx(g,y,u));let $=g?Rt(JSON.stringify(g)):"",D=l?.byteLength?Rt(l):void 0,K=Sr(D?`${$}.${D}`:$),te=s;o.zip==="DEF"&&(te=await VB(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 Tx(n,te,k,f,K);let Fe={ciphertext:Rt(Ie)};return Qe&&(Fe.iv=Rt(Qe)),xe&&(Fe.tag=Rt(xe)),b?.byteLength&&(Fe.encrypted_key=Rt(b)),D&&(Fe.aad=D),g&&(Fe.protected=$),u&&(Fe.unprotected=u),y&&(Fe.header=y),Fe}async function WB(t,e,r){return GO(t,JO(t,r),e)}function JB(t){return[t.protected,t.encrypted_key,t.iv,t.ciphertext,t.tag].join(".")}var XO=class{#e;state;constructor(e,r,o){this.#e=e,this.state=[void 0,void 0,r,o]}setUnprotectedHeader(e){return go(this.state[0],"setUnprotectedHeader"),this.state[0]=e,this}setKeyManagementParameters(e){return go(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}},lg=class{#e;#t=[];#r;#n;#o;constructor(e){this.#e=e}addRecipient(e,r){let o=new XO(this,e,r?.crit);return this.#t.push(o),o}setProtectedHeader(e){return go(this.#r,"setProtectedHeader"),this.#r=e,this}setSharedUnprotectedHeader(e){return go(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");qn(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=JO(_,void 0,i.length>0);i.length||(o=_[1],n=_[3]),i.push([_,k,w]);let[{alg:$,enc:D},,K]=k;if(e&&K&&!oi(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]??=ni(m[0].alg);let[s,a,c]=i[0],u=e?Ju(a[1]):void 0;s[5]=u;let{encrypted_key:l,header:d,...f}=await GO(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 Dx(b,w,_,y,u,g[7]),K={encrypted_key:Rt($)};if(k||D){let te={...k,...D};D&&Mx(g[1],te,g[3]),K.header=te}p.recipients.push(K)}return p}};var dg=[["verify"],["sign"]];function YO(t){let e={name:"HMAC",hash:`SHA-${t}`};return{kty:["oct"],secret:!0,subtle:e,signing:e,usages:dg}}function cp(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:dg,minRsaBits:2048}}function QO(t,e){return{kty:["EC"],crv:t,subtle:{name:"ECDSA",namedCurve:t},signing:{name:"ECDSA",hash:`SHA-${e}`},usages:dg}}function GB(){let t={name:"Ed25519"};return{kty:["OKP"],crv:"Ed25519",subtle:t,signing:t,usages:dg}}function eN(t){let e={name:`ML-DSA-${t}`};return{kty:["AKP"],subtle:e,signing:e,usages:dg}}var tN=cg({HS256:YO(256),HS384:YO(384),HS512:YO(512),RS256:cp(256),RS384:cp(384),RS512:cp(512),PS256:cp(256,32),PS384:cp(384,48),PS512:cp(512,64),ES256:QO("P-256",256),ES384:QO("P-384",384),ES512:QO("P-521",512),EdDSA:GB(),Ed25519:GB(),"ML-DSA-44":eN(44),"ML-DSA-65":eN(65),"ML-DSA-87":eN(87)});function Ux(t){let e=typeof t=="string"?tN[t]:void 0;if(!e)throw new at(`alg ${t} is not supported either by JOSE or your javascript runtime`);return e}function XB(t){return[t&&ag("algorithms",t.algorithms),t?.crit]}function dhe(t){return t===void 0?{}:np(t,xt,"JWS Protected Header is invalid")}function phe(t){try{return Sr(t)}catch{throw new xt("JWS Compact Serialization payload must use only ASCII characters")}}async function fhe(t,e,r,o,n){let{protected:i,header:s,payload:a}=t,c=n??dhe(i);if(!tc(c,s))throw new xt("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");let u={...c,...s},l=xx(c,rc(xt,bx,e[1],c,u)),{alg:d}=u;if(typeof d!="string"||!d)throw new xt('JWS "alg" (Algorithm) Header Parameter missing or invalid');if(e[0]&&!e[0].has(d))throw new qu('"alg" (Algorithm) Header Parameter value not allowed');if(l){if(typeof a!="string")throw new xt("JWS Payload must be a string")}else if(typeof a!="string"&&!(a instanceof Uint8Array))throw new xt("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=Ux(d),g=pn(i!==void 0?Sr(i):new Uint8Array,Sr("."),typeof f=="string"?e[2]??=wx(f,"payload",xt):f),y=Tn(t.signature,"signature",xt),w=await ti(m,r,"verify"),b=await ri(w,m.subtle,"verify");m.minRsaBits&&op(m.alg,b);let _=!1;try{_=await crypto.subtle.verify(m.signing,b,y,g)}catch{}if(!_)throw new vx;let k={payload:typeof f=="string"?Tn(f,"payload",xt):f};return i!==void 0&&(k.protectedHeader=c),s!==void 0&&(k.unprotectedHeader=s),p?[{...k,key:w},l]:[k,l]}async function YB(t,e,r){if(t instanceof Uint8Array&&(t=rp.decode(t)),typeof t!="string")throw new xt("Compact JWS must be a string or Uint8Array");let{0:o,1:n,2:i,length:s}=t.split(".");if(s!==3)throw new xt("Invalid Compact JWS");return fhe({payload:n,protected:o,signature:i},e,r,phe)}async function rN(t,e,r){let[o]=await YB(t,XB(r),e);return o}var up=class{#e;constructor(e){qn(e,"plaintext"),this.#e=[e]}setContentEncryptionKey(e){return go(this.#e[5],"setContentEncryptionKey"),this.#e[5]=e,this}setInitializationVector(e){return go(this.#e[6],"setInitializationVector"),this.#e[6]=e,this}setProtectedHeader(e){return go(this.#e[1],"setProtectedHeader"),this.#e[1]=e,this}setKeyManagementParameters(e){return go(this.#e[7],"setKeyManagementParameters"),this.#e[7]=e,this}async encrypt(e,r){return JB(await WB([...this.#e],e,r))}};async function mhe(t,e,r){let[o,n,i,s]=t,a="";if(n!==void 0){let w=Wu(xt,n);n=w[0],a=Rt(w[1])}if(i!==void 0&&(i=Wu(xt,i)[0]),!n&&!i)throw new xt("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");if(!tc(n,i))throw new xt("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");let c={...n,...i};Sx(xt,n);let u=xx(n,rc(xt,bx,s,n,c));u||r?.();let{alg:l}=c;if(typeof l!="string"||!l)throw new xt('JWS "alg" (Algorithm) Header Parameter missing or invalid');let d=Ux(l),f="",p=o,m;if(u){let w=t[4];w?(f=w[0]??=Rt(o),p=w[1]??=Sr(f)):(f=Rt(o),m=tp.encode(`${a}.${f}`))}m??=pn(Sr(a),Sr("."),p);let g=await ri(await ti(d,e,"sign"),d.subtle,"sign");d.minRsaBits&&op(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 QB(t,e,r,o,n){let[i]=await mhe([t,e,void 0,r],o,n);return`${i.protected}.${i.payload}.${i.signature}`}var pg=class{#e;#t;constructor(e){qn(e,"payload"),this.#e=e}setProtectedHeader(e){return go(this.#t,"setProtectedHeader"),this.#t=e,this}async sign(e,r){return QB(this.#e,this.#t,r?.crit,e,()=>{throw new TypeError("use the flattened module for creating JWS with b64: false")})}};var nN='"alg" (Algorithm)';function oN(t='JWK "alg" (Algorithm) Parameter'){throw new at(`Invalid or unsupported ${t} value`)}function fg(t,e){return(typeof t=="string"?tN[t]??ia[t]:void 0)??oN(e)}async function oc(t){if(UO(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(!nc(t))throw new TypeError(oa(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 sa=(t,e)=>{if(typeof t!="string"||!t)throw new sg(`${e} missing or invalid`)};async function iN(t,e){let r;if(Kt(t)){if(r=Ix(t),typeof r.kty!="string")throw new TypeError(oa(t,"CryptoKey","KeyObject","JSON Web Key"))}else if(LO(t))r=Ix(await oc(t));else throw new TypeError(oa(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":sa(r.alg,'"alg" (Algorithm) Parameter'),sa(r.pub,'"pub" (Public key) Parameter'),o={alg:r.alg,kty:r.kty,pub:r.pub};break;case"EC":sa(r.crv,'"crv" (Curve) Parameter'),sa(r.x,'"x" (X Coordinate) Parameter'),sa(r.y,'"y" (Y Coordinate) Parameter'),o={crv:r.crv,kty:r.kty,x:r.x,y:r.y};break;case"OKP":sa(r.crv,'"crv" (Subtype of Key Pair) Parameter'),sa(r.x,'"x" (Public Key) Parameter'),o={crv:r.crv,kty:r.kty,x:r.x};break;case"RSA":sa(r.e,'"e" (Exponent) Parameter'),sa(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 sg('"k" (Key Value) Parameter missing or invalid');o={k:r.k,kty:r.kty};break;default:throw new at('"kty" (Key Type) Parameter missing or unsupported')}let n=Sr(JSON.stringify(o));return Rt(await yx(e,n))}async function yo(t,e,r){if(!Kt(t))throw new TypeError("JWK must be an object");let o=HO(t),n=$x(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 Zu(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 ip(fg(e),o,n)}case"RSA":case"EC":case"OKP":return ip(fg(e),o,n);default:throw new at('Unsupported "kty" (Key Type) Parameter value')}}function sN(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 np(e,TypeError,r)}function hhe(t){let e=t?.modulusLength??2048;if(typeof e!="number"||!Number.isInteger(e)||e<2048)throw new at("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");return e}async function mg(t,e){let r=$x(e?.extractable),o=fg(t,nN);o.secret&&oN(nN);let n;if(o.resolve){let i=e?.crv??"P-256";if(!["P-256","P-384","P-521","X25519"].includes(i))throw new at("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 at(`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:hhe(e)}:o.subtle}return crypto.subtle.generateKey(n,r??!1,[...o.usages[1],...o.usages[0]])}var nK=h.string().regex(/^[a-z]{2}(?:-gov)?-[a-z]+-\d$/),oK=h.string().max(2e3).regex(/^arn:aws(?:-us-gov|-cn)?:iam::\d{12}:role\/.+/),eK=h.string().min(1).max(128),tK=h.string().min(1).max(16384),ghe=h.discriminatedUnion("kind",[h.object({kind:h.literal("access_key"),accessKeyId:eK,secretAccessKey:tK}).strict(),h.object({kind:h.literal("session"),accessKeyId:eK,secretAccessKey:tK,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()]),yhe=h.object({arn:oK,externalId:h.string().min(2).max(1224).regex(/^[\w+=,.@:\/-]+$/).optional()}).strict(),aa=h.object({authentication:ghe,region:nK,role:yhe.optional()}).strict(),Lx=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(),Fx=aa.extend({sourceIdentity:Lx.optional(),identity:Lx.optional()}).strict();function lp(t){return t.includes(":assumed-role/")?t.slice(0,t.lastIndexOf("/")):t}function rK(t){return{...t,arn:lp(t.arn)}}function iK(t){return{authentication:t.authentication.kind,region:t.region,role:t.role??null,...t.sourceIdentity?{sourceIdentity:rK(t.sourceIdentity)}:{},...t.identity?{identity:rK(t.identity)}:{}}}var Vx=h.object({authentication:h.enum(["access_key","session","environment"]),region:nK,sourceAccountId:h.string().regex(/^\d{12}$/).optional(),sourceArn:h.string().max(2e3).optional(),roleArn:oK.optional(),expiresAt:h.number().int().positive().optional()}).strict();function sK(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 aK=h.object({method:h.enum(["GET","POST","PUT","DELETE","PATCH"]),path:h.string().min(1).max(1e3).regex(/^\/[^\s\u0000]*$/)}).strict(),hg=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(aK),allowedIPs:h.array(h.string()).nullable(),expiresAt:h.number().nullable()}).strict();function cK(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 aK.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),Ve=h.iso.datetime(),Zn=h.json(),xr=h.record(h.string(),Zn),uK=h.enum(["ja","en"]),lK=h.enum(["read","create","update","delete","share","transfer","reveal","use","manage_credentials","manage_billing","export"]);var dK=h.enum(["variable","connection","service","method","app","object","keyring","ssh_key","ssh_host"]),fn=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(),vhe=h.object({alg:h.literal("dir"),enc:h.literal("A256GCM"),sub:E}).strict(),vg=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 vhe.safeParse(sN(t)).success}catch{return!1}},"Use an A256GCM JWE for the wrapped encryption key.").brand(),Fr=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:fn.optional(),alg:h.string().optional()}).passthrough()})).min(1).max(100)}).strict(),QVe=h.object({id:E,name:me,publicKey:fn}),Yu=h.object({id:E,name:me,owner:h.object({id:E,name:me}).nullable(),createdAt:Ve,permissions:h.array(lK),createKinds:h.array(dK),publicKey:fn.nullable()}),pK=h.object({id:E,kind:h.enum(["passkey","email","key"]),name:h.string(),createdAt:Ve,lastUsedAt:Ve.nullable(),expiresAt:Ve.nullable(),canOpen:h.boolean()}),aN=h.string().regex(/^[a-z][a-z_]*[a-z]$/).max(64),whe=h.object({subjectId:E,relation:aN,objectId:E}).strict(),fK=h.enum(["principal",...dK.options]),mK=whe.extend({objectType:fK,subjectName:me,objectName:me,createdAt:Ve}),eHe=h.object({error:h.object({code:h.string(),message:h.string(),details:Zn.optional()})}),tHe=h.object({ok:h.literal(!0)}),bhe=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(),Kx=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(bhe).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."})}),cN=h.record(h.string().regex(/^[A-Z_][A-Z0-9_]*$/),h.string()),_he=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)])),uN=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()}),Xu=h.string().min(1).max(4096),Bx=h.union([h.string(),h.array(h.string()).min(1)]),Pn="urn:ietf:params:oauth:grant-type:device_code",She=h.object({browserTokenExchange:h.enum(["available","unavailable","unknown"]).optional(),application:h.enum(["required","implicit"]).default("required"),grantType:h.enum(["authorization_code","client_credentials",Pn]).optional(),issuer:h.url().optional(),registrationUrl:h.url().optional(),authorizeUrl:Xu.optional(),deviceAuthorizationUrl:Xu.optional(),tokenUrl:Xu,identity:h.object({url:Xu.optional(),from:h.enum(["token","app"]).optional(),method:h.enum(["GET","POST"]).default("GET"),id:Bx.default("/id"),name:Bx.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:uN.default({default:[],separator:" "}),fields:h.array(Kx).default([]),outputs:cN.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===Pn||!!t.authorizeUrl,{path:["authorizeUrl"],message:"An authorization code flow requires an authorization URL."}).refine(t=>t.grantType!==Pn||!!t.deviceAuthorizationUrl,{path:["deviceAuthorizationUrl"],message:"A device flow requires a device authorization URL."}),xhe=h.object({fields:h.array(Kx).min(1),outputs:_he,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:Xu,headers:h.record(h.string(),h.string()),id:Bx,name:Bx}).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."})}),lN=h.enum(["oauth","token","aws","ovh","approval"]),Ehe=h.object({hint:h.string().optional()}).strict(),khe=h.object({authorization:h.enum(["api_key","consumer_key"]),apiBaseUrl:Xu,fields:h.array(Kx).min(1),scopes:uN.default({default:[],separator:`
|
|
129
129
|
`}),outputs:cN,hint:h.string().optional()}).strict(),wg={name:me,docs:h.url().optional(),console:Xu.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()},qx=h.object({...wg,kind:h.literal("oauth"),config:She}).strict(),Zx=h.object({...wg,kind:h.literal("token"),config:xhe}).strict(),Wx=h.object({...wg,kind:h.literal("aws"),config:Ehe}).strict(),Jx=h.object({...wg,kind:h.literal("ovh"),config:khe}).strict(),Gx=h.object({...wg,kind:h.literal("approval"),config:h.object({adapter:h.literal("runpod-flash"),fields:h.array(Kx).default([]),scopes:uN.default({default:[],separator:" "}),outputs:cN,hint:h.string().optional()}).strict()}).strict(),dp=h.discriminatedUnion("kind",[qx,Zx,Wx,Jx,Gx]),gg={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()},ii=h.discriminatedUnion("kind",[qx.extend(gg),Zx.extend(gg),Wx.extend(gg),Jx.extend(gg),Gx.extend(gg)]),yg=h.string().regex(/^[a-z][a-z0-9_-]{0,79}$/),dN=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:yg,name:me,api:h.url().optional(),methods:h.array(yg).min(1)}).strict()).max(32).optional()}).strict(),Ihe=dN.extend({methods:h.record(yg,h.string().min(1))}).strict(),hK=dN.extend({methods:h.record(yg,h.union([h.string().min(1),dp]))}).strict(),gK=dN.extend({id:h.string(),builtin:h.boolean(),methods:h.record(yg,ii)}),$he=h.object({id:E,output:h.string().min(1).max(100).optional()}).strict(),yK=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),vK=h.object({name:h.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/),source:$he,format:h.enum(["text","file","json"]).optional(),pointer:h.string().optional()}).strict(),ca={id:E,ownerId:E,name:me,createdAt:Ve,updatedAt:Ve,version:h.number().int().positive(),permissions:h.array(lK)},pN={recipients:h.array(E).default([]),custodyRevision:h.number().int().positive().nullable().default(null)},Ahe=h.object({...ca,kind:h.literal("variable"),data:h.object({...pN,bytes:h.number().int().nonnegative()})}),The=h.object({...ca,kind:h.literal("connection"),data:h.object({...pN,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:lN,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:Vx.optional(),ovh:hg.optional()})}),Phe=h.object({...ca,kind:h.literal("service"),data:Ihe}),Rhe=h.object({...ca,kind:h.literal("method"),data:dp}),Che=h.object({...ca,kind:h.literal("app"),data:h.object({...pN,methodId:h.string(),clientId:h.string(),fields:h.record(h.string(),h.string()).default({}),generation:E.optional()})}),Ohe=h.object({...ca,kind:h.literal("object"),data:h.object({size:h.number().int().nonnegative(),contentType:h.string()})}),Nhe=h.object({...ca,kind:h.literal("keyring"),data:h.object({revision:h.number().int().positive(),signature:h.string()})}),Dhe=h.object({publicKey:ig,algorithm:h.string(),fingerprint:mx,purpose:h.string().max(500),privateKeyId:E.nullable(),revokedAt:Ve.nullable()}),zhe=h.object({...ca,kind:h.literal("ssh_key"),data:Dhe}),jhe=h.object({address:px,port:h.number().int().min(1).max(65535),hostKeys:h.array(ig).min(1).max(16),authorizedKeysFile:fx}),Mhe=h.object({...ca,kind:h.literal("ssh_host"),data:jhe}),mt=h.discriminatedUnion("kind",[Ahe,The,Phe,Rhe,Che,Ohe,Nhe,zhe,Mhe]),rHe=h.discriminatedUnion("kind",[h.object({kind:h.literal("service"),name:me,definition:hK}).strict(),h.object({kind:h.literal("method"),name:me,definition:dp}).strict()]),nHe=h.object({version:h.number().int().positive(),name:me.optional(),definition:h.union([hK,dp]).optional()}).strict(),vo=h.object({name:h.string().regex(/^[a-z][a-z0-9]*(?:\.[a-z][a-z0-9]*)+$/),input:xr}).strict(),fN=vo.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([])}),Xx=h.object({ja:h.string(),en:h.string()}).strict(),Hx=h.object({id:E,name:me}),wK=h.discriminatedUnion("kind",[h.object({kind:h.literal("line"),subject:Hx,relation:aN,object:Hx}),h.object({kind:h.literal("transfer"),item:Hx,to:Hx})]),oHe=h.object({id:E,name:me,publicKey:fn,state:h.enum(["pending","approving","approved"]),principalId:E.nullable(),createdAt:Ve,expiresAt:Ve}),iHe=h.object({available:h.boolean(),required:h.boolean(),active:h.boolean(),payer:Yu.pick({id:!0,name:!0}).nullable()}),sHe=h.object({storageBytes:h.number().nonnegative(),storageLimit:h.number().positive(),month:h.string()}),aHe=h.object({id:h.string(),actorId:E.nullable(),action:h.string(),targetId:E.nullable(),createdAt:Ve,details:xr}),cHe=h.object({returnUrl:h.url().optional(),refreshUrl:h.url().optional()}).strict(),Qt=t=>h.object({items:h.array(t),next:h.string().nullable().default(null)}),uHe=h.object({id:E}),lHe=h.object({owner:E}),Uhe=h.object({limit:h.coerce.number().int().min(1).max(200).default(100),after:h.string().optional()}),dHe=Uhe.extend({object:E.optional(),subject:E.optional(),relation:aN.optional(),objectType:fK.optional()}).refine(t=>!!t.object!=!!t.subject,"Choose the object or the subject of the lines.");var Lhe=new TextEncoder,Fhe=new TextDecoder,bg="ECDH-ES+A256KW",mN="A256GCM",Et=t=>Lhe.encode(t),qt=t=>Fhe.decode(t);function Qu(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 Yx(t){return Uint8Array.from(atob(t.replaceAll("-","+").replaceAll("_","/")),e=>e.charCodeAt(0))}async function Qx(){let t=await mg(bg,{crv:"P-256",extractable:!0});return{publicKey:fn.parse(await oc(t.publicKey)),privateKey:await oc(t.privateKey)}}async function el(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 lg(t).setProtectedHeader({enc:mN}).setAdditionalAuthenticatedData(Et(r));for(let n of e)o.addRecipient(await yo(n.publicKey,bg)).setUnprotectedHeader({alg:bg,kid:n.id});return Fr.parse(await o.encrypt())}async function wo(t,e,r,o){if(t.aad!==Qu(Et(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 yo(e,bg);return(await WO({...t,recipients:[n]},i,{keyManagementAlgorithms:[bg],contentEncryptionAlgorithms:[mN]})).plaintext}async function Vhe(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:Et("Foundation"),info:Et("passkey encryption key")},e,256))}async function bK(t,e,r){let o=await ug(t,await Vhe(e),{keyManagementAlgorithms:["dir"],contentEncryptionAlgorithms:[mN]});if(o.protectedHeader.sub!==r)throw new Error("The key belongs to a different principal.");return JSON.parse(qt(o.plaintext))}var Vr=h.string().regex(/^[A-Za-z0-9_-]{43}$/),tr=h.string().min(100).max(4e6),_K=fn.extend({d:h.string().regex(/^[A-Za-z0-9_-]{43}$/)}),tl=h.object({encryption:_K,signing:_K}).strict(),si=h.object({id:E,principalId:E,generation:h.number().int().positive(),previous:Vr.nullable(),encryption:fn,signing:fn}).strict();function M(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,M).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)+":"+M(t[e])}).join(",")+"}";throw new Error("Use finite numbers, Unicode strings, arrays, and plain JSON objects.")}async function bo(t){return iN(fn.parse({kty:t.kty,crv:t.crv,x:t.x,y:t.y}),"sha256")}async function vt(t){return Qu(new Uint8Array(await crypto.subtle.digest("SHA-256",Et(M(t)))))}async function ic(t){let e=new Uint8Array(await crypto.subtle.digest("SHA-256",Et(M(t))));return"sha256:"+Array.from(e,r=>r.toString(16).padStart(2,"0")).join("")}async function e0(){let[t,e]=await Promise.all([Qx(),mg("ES256",{crv:"P-256",extractable:!0})]),r=await oc(e.privateKey);return tl.parse({encryption:t.privateKey,signing:r})}function pp(t){return fn.parse({kty:t.kty,crv:t.crv,x:t.x,y:t.y})}function t0(t,e){return si.parse({id:crypto.randomUUID(),principalId:t,generation:1,previous:null,encryption:pp(e.encryption),signing:pp(e.signing)})}async function rr(t,e,r){let o=e instanceof CryptoKey?e:await yo(e,"ES256");return new pg(Et(M(t))).setProtectedHeader({alg:"ES256",typ:"foundation."+r+"+jws"}).sign(o)}async function Yi(t,e,r,o){if(M(await hN(e,r,o))!==M(t))throw new Error("The signature does not authorize this content.")}async function hN(t,e,r){let o=await rN(t,await yo(fn.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(M(i)!==n)throw new Error("Sign canonical JSON content.");return i}var er=h.object({binding:si,signature:tr}).strict(),r0=h.object({previous:er,replacement:er,previousSignature:tr}).strict();async function _g(t,e,r){let o=t;for(let n of[...r].sort((i,s)=>i.replacement.binding.generation-s.replacement.binding.generation)){if(M(n.previous.binding)!==M(o))continue;let i=n.replacement.binding;if(i.principalId!==o.principalId||i.id===o.id||i.generation!==o.generation+1||i.previous!==await vt(o))return!1;if(await fp(n.previous),await fp(n.replacement),await Yi(i,n.previousSignature,o.signing,"key-replacement"),o=i,M(o)===M(e))return!0}return!1}async function mp(t,e){if(await hp(t),await bo(e.encryption)!==await bo(t.encryption)||await bo(e.signing)!==await bo(t.signing))throw new Error("The private keys do not match this identity.");return{binding:t,signature:await rr(t,e.signing,"key-binding")}}async function hp(t){let e=si.parse(t);if(e.generation===1!=(e.previous===null))throw new Error("Link each replacement key to its preceding binding.");if(await bo(e.encryption)===await bo(e.signing))throw new Error("Use separate encryption and signing keys.");await yo(e.encryption,"ECDH-ES+A256KW"),await yo(e.signing,"ES256")}async function fp(t){let{binding:e,signature:r}=er.parse(t);return await hp(e),await Yi(e,r,e.signing,"key-binding"),e}var Hhe=h.object({requestedAt:Ve,readyAt:Ve}).strict(),Bhe=h.object({email:h.boolean(),storage:h.boolean(),payments:h.boolean()}),n0=h.object({principal:Yu.nullable(),credentialId:E.nullable(),wrappedKey:vg.nullable(),requestId:E.nullable(),keyReset:Hhe.nullable(),server:h.object({name:me}),features:Bhe,principals:h.array(Yu)}),EHe=h.object({email:h.email().max(254),returnTo:h.string().max(2048).optional(),locale:uK.default("ja"),principalId:E.optional()}).strict(),kHe=h.object({intent:h.enum(["register","authenticate"]),name:me.optional(),principalId:E.optional(),credentialId:E.optional(),returnTo:h.string().max(2048).optional()}).strict(),IHe=h.object({challengeId:E,credential:h.json(),binding:er.optional(),existingPublicKey:fn.optional(),wrappedKey:vg.optional()}).strict(),$He=h.object({binding:er,wrappedKey:vg}).strict();import{createInterface as qhe}from"node:readline/promises";var xK=h.object({action:h.string().regex(/^[a-z][a-zA-Z]*(\.[a-z][a-zA-Z]*)+$/).max(64),principalId:E}).catchall(Zn),EK=h.enum(["signature","decryption","email","passkey"]),Khe=h.object({confirmationId:E,principalId:E,credentialId:E,bindingId:E.nullable(),operation:h.string(),nonce:h.string()}).strict(),SK=h.object({id:E,operation:xK,methods:h.array(EK),state:h.enum(["pending","confirmed","held"]),expiresAt:Ve,challenge:Khe,sealed:Fr.nullable()}).strict(),CHe=h.discriminatedUnion("method",[h.object({method:h.literal("signature"),signature:tr}).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()]),kK=h.object({operation:xK,methods:h.array(EK)}),IK="foundation-confirmation",$K=["confirmation_required","confirmation_invalid"],AK=(t,e)=>rr(t.challenge,e,"operation-confirmation"),TK=t=>"operation-confirmation:"+t;async function PK(t,e,r){let o=await t.json("/api/confirmations",{method:"POST",body:{operation:e.operation}},SK);return await t.json("/api/confirmations/"+o.id+"/proof",{method:"POST",body:await r(o,t)},SK),o.id}var ai=class extends Error{constructor(r,o,n,i){super(n);this.code=r;this.status=o;this.details=i}code;status;details},Qi=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?{[IK]: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 ai("http_error",n.status,"Foundation returned HTTP "+n.status+".")}let s=kK.safeParse(i.error.details);if(!r.confirmation&&$K.includes(i.error.code)&&s.success)return this.response(e,{...r,confirmation:await this.confirm(s.data)});throw new ai(i.error.code,n.status,i.error.message,i.error.details)}return n}confirm(e){return PK(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 AK(r,o.signing)};if(r.methods.includes("decryption")&&o&&r.sealed)return{method:"decryption",secret:qt(await wo(r.sealed,o.encryption,r.id,TK(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=qhe({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 ai("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",{},n0)}};import{rm as bge,stat as _ge}from"node:fs/promises";import{dirname as Sge,join as EN}from"node:path";import{chmod as Zhe,lstat as Whe,mkdir as Jhe,open as gN,readFile as CK,rename as Ghe,rm as Xhe}from"node:fs/promises";import{dirname as Yhe,join as yN,resolve as Qhe}from"node:path";import{homedir as ege}from"node:os";import{randomUUID as tge}from"node:crypto";var vN=h.object({origin:h.url(),principalId:h.uuid(),token:h.string().min(20),keys:tl.nullable(),binding:si.nullable()}).strict().refine(t=>!!t.keys==!!t.binding&&(!t.binding||t.binding.principalId===t.principalId),"Use the keys bound to this identity."),OK=h.object({current:h.uuid(),identities:h.array(vN).min(1)}).strict().refine(t=>t.identities.some(e=>e.principalId===t.current),"The current identity is missing.");function ci(){return yN(process.env.XDG_CONFIG_HOME||yN(ege(),".config"),"foundation","identity.json")}function gp(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 wN(){try{let t=ci(),e=await Whe(t);if(!e.isFile()||e.isSymbolicLink())throw new Error("The identity must be a regular file.");return process.platform!=="win32"&&e.mode&63&&await Zhe(t,384),OK.parse(JSON.parse(await CK(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 NK(){let t=await wN();return(t?.identities??[]).map(e=>({...e,current:e.principalId===t.current}))}async function DK(t){let e=await wN();if(!e?.identities.some(r=>r.principalId===t))throw new Error("No saved identity has principal "+t+". Run foundation identity list.");await ua(ci(),JSON.stringify({...e,current:t},null,2)+`
|
|
130
130
|
`,!0)}async function zK(t,e){let r=process.env.FOUNDATION_TOKEN,o=e||(r?void 0:process.env.FOUNDATION_PRINCIPAL_ID),n=await wN(),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=gp(t||process.env.FOUNDATION_ORIGIN||i?.origin);if(r){if(t&&process.env.FOUNDATION_ORIGIN&&s!==gp(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 vN.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!==gp(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 yp(t){let e=ci(),r;try{r=OK.parse(JSON.parse(await CK(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=vN.parse(t),n=(r?.identities??[]).filter(i=>!(i.origin===o.origin&&i.principalId===o.principalId));await ua(e,JSON.stringify({current:o.principalId,identities:[...n,o]},null,2)+`
|
|
131
131
|
`,!!r)}async function RK(t){if(process.platform==="win32")return;let e=await gN(t,"r");try{await e.sync()}finally{await e.close()}}async function ua(t,e,r){let o=Qhe(t),n=Yhe(o);if(await Jhe(n,{recursive:!0,mode:448}),!r){let s=await gN(o,"wx",384);try{await s.writeFile(e),await s.sync()}finally{await s.close()}await RK(n);return}let i=yN(n,".foundation-"+tge());try{let s=await gN(i,"wx",384);try{await s.writeFile(e),await s.sync()}finally{await s.close()}await Ghe(i,o),await RK(n)}finally{await Xhe(i,{force:!0})}}import{lstat as rge,mkdir as jK,readFile as nge,readdir as MK,rm as oge}from"node:fs/promises";import{join as vp}from"node:path";var bN=h.string().regex(/^(refresh|checkpoint|identity)_[A-Za-z0-9_-]{1,100}$/),UK=t=>bN.safeParse(t).success,sc=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 M({purpose:"executor-journal",origin:this.origin,bindingId:this.binding.id,id:bN.parse(e)})}async read(e){let r=this.context(e),o=vp(this.directory,e+".json");try{let n=await rge(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 nge(o,"utf8"))),s=await ug(i,await yo(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(qt(s.plaintext));if(a.context!==r)throw new Error("The journal entry belongs to another operation.");return await Yi({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 rr(n,this.privateKeys.signing,"journal"),s=Et(M({...n,signature:i}));if(s.byteLength>2e7)throw new Error("The execution record is too large.");let a=await new up(s).setProtectedHeader({alg:"ECDH-ES+A256KW",enc:"A256GCM",kid:this.binding.id,ctx:o}).encrypt(await yo(this.binding.encryption,"ECDH-ES+A256KW"));await jK(this.directory,{recursive:!0,mode:448}),await ua(vp(this.directory,e+".json"),M(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 jK(vp(this.directory,"pending"),{recursive:!0,mode:448}),await ua(vp(this.directory,"pending",bN.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 oge(vp(this.directory,"pending",e),{force:!0})}async pending(e){await this.index();let r;try{r=await MK(vp(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)&&UK(o.name)).map(o=>o.name)}async keys(e){let r;try{r=await MK(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")&&UK(o.name.slice(0,-5))).map(o=>o.name.slice(0,-5))}};var FK=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."),kt={value:"03546b17-fa44-409f-b151-8da1a398b324",tokenSet:"7d4b64dd-4546-4acb-8e96-91f864bccea6",clientCredential:"714fc044-2cce-4f3f-a477-281ee64fe632"},ige=h.enum([kt.value,kt.tokenSet,kt.clientCredential]),VK=1e6,HK=t=>t===kt.tokenSet,Wn=h.object({format:h.literal(3),origin:FK,id:E,ownerId:E,contentType:ige,revision:h.number().int().positive(),authorities:h.array(si).min(1).max(100),readers:h.array(si).min(1).max(100),observers:h.array(E).max(100).optional()}).strict(),LK=h.object({ownerId:E,authorities:h.array(si).min(1).max(100)}).strict(),BK=h.object({origin:FK,id:E,revision:h.number().int().positive(),from:LK,to:LK,policyDigest:Vr,previous:Vr.nullable(),signerId:E}).strict(),sge=BK.extend({signature:tr}),age=16,KK=h.array(sge).max(age),Hr=h.object({policy:Wn,authorityId:E,authorization:tr,lineage:KK.optional(),materialRevision:h.number().int().positive(),updatedAt:Ve,metadata:xr,sealed:Fr,signerId:E,signature:tr}).strict(),rl=t=>({ownerId:t.ownerId,authorities:t.authorities});async function cge(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||M(r.to)!==M(o.from))||o.previous!==(r?await vt(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 Yi(i,n,s.signing,"authority-handoff"),r=o}if(r&&M(r.to)!==M(rl(t)))throw new Error("Use the authorities approved by the latest handoff.")}function _N(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 qK(t,e){if(t.id!==e.policy.id||t.origin!==e.policy.origin||t.contentType!==e.policy.contentType)return!1;let r=M(rl(t));return r===M(rl(e.policy))?!0:!!e.lineage?.some(o=>o.revision>t.revision&&M(o.from)===r)}async function uge(t,e,r,o){let n=[...t?.lineage??[]];if(t&&M(rl(t.policy))!==M(rl(e))){if(!t.policy.authorities.some(s=>M(s)===M(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=BK.parse({origin:e.origin,id:e.id,revision:e.revision,from:rl(t.policy),to:rl(e),policyDigest:await vt(e),previous:n.length?await vt(n.at(-1)):null,signerId:r.id});n.push({...i,signature:await rr(i,o.signing,"authority-handoff")})}return n.length?{lineage:KK.parse(n)}:{}}async function ZK(t){let e=Wn.parse(t),r=new Map;for(let o of[...e.authorities,...e.readers]){await hp(o);let n=M(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 o0(t,e){return M({purpose:"resource",policyDigest:await vt(t),materialRevision:e})}async function wp(t,e,r,o,n,i,s){if(t.byteLength>VK)throw new Error("The content exceeds its storage limit.");let a=await ZK(e),c=await uge(s,a,o,n);if(!a.authorities.some(f=>M(f)===M(o))&&c.lineage?.at(-1)?.revision!==a.revision)throw new Error("Only a policy authority can replace its content.");let u=await el(t,a.readers.map(f=>({id:f.id,publicKey:f.encryption})),await o0(a,r)),l={policy:a,...c,authorityId:o.id,authorization:await rr(a,n.signing,"access-policy"),materialRevision:r,updatedAt:new Date().toISOString(),metadata:i??(a.contentType===kt.value?{bytes:t.byteLength}:{}),sealed:u,signerId:o.id},d=Hr.parse({...l,signature:await rr(l,n.signing,"resource")});return await ac(d),d}async function ac(t){let e=Hr.parse(t),{signature:r,...o}=e;await ZK(e.policy),await cge(e.policy,e.lineage);let n=_N(e),i=e.lineage?.at(-1);if(i?.revision===e.policy.revision&&i.policyDigest!==await vt(e.policy))throw new Error("The handoff approves a different access policy.");await Yi(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)??(HK(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 Yi(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(M(a)!==M(c)||e.sealed.aad!==Qu(Et(await o0(e.policy,e.materialRevision))))throw new Error("Encrypt content for exactly the readers its policy names.");return e}async function WK(t,e,r,o,n=t.metadata){let i=await ac(t);if(!HK(i.policy.contentType)||!i.policy.readers.some(f=>M(f)===M(r)))throw new Error("Only a reader of this connection can renew it.");if(e.byteLength>VK)throw new Error("The content exceeds its storage limit.");let s=i.materialRevision+1,a=await el(e,i.policy.readers.map(f=>({id:f.id,publicKey:f.encryption})),await o0(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 rr(l,o.signing,"resource")};return await ac(d),d}async function Jn(t,e,r){let o=await ac(t);if(!o.policy.readers.some(n=>M(n)===M(e)))throw new Error("This identity cannot reveal the content.");return wo(o.sealed,r,e.id,await o0(o.policy,o.materialRevision))}var lge=h.object({binding:si,verifiedAt:Ve}).strict(),SN=h.object({origin:h.url(),ownerId:E,signerId:E,revision:h.number().int().positive(),keys:h.array(lge).max(1e3)}).strict(),dge=h.object({version:h.number().int().positive(),signature:tr}).strict(),xN=h.object({keyring:dge.nullable()}).strict(),lBe=h.object({version:h.number().int().positive().nullable(),signature:tr}).strict();function i0(t,e){return rr(SN.parse(t),e,"keyring")}function JK(t){return SN.parse(JSON.parse(qt(Yx(t.split(".")[1]??""))))}async function s0(t,e){let r=SN.parse(await hN(t,e.signing,"keyring"));if(r.signerId!==e.id)throw new Error("Another identity signed this keyring.");return r}var GK=h.enum(["content","keyring"]),wBe=h.object({id:E,replacement:er,previousSignature:tr,handoff:Fr}).strict(),XK=h.object({replacement:r0,handoff:Fr}).strict(),YK=h.discriminatedUnion("kind",[h.object({kind:h.literal("content"),content:Hr}).strict(),h.object({kind:h.literal("keyring"),signature:tr}).strict()]),bBe=h.object({sourceDigest:Vr,payload:YK,signature:tr}).strict(),_Be=h.object({sourceDigest:Vr,payload:YK}).strict(),QK=h.record(h.string(),h.unknown()),pge=h.object({kind:GK,id:E,name:me.nullable(),sourceDigest:Vr,state:h.enum(["pending","prepared","stale"]),signers:h.array(E).nullable(),source:QK.nullable()}),eq=h.object({rotation:h.object({id:E,principalId:E,previous:er,replacement:er,previousSignature:tr}).strict(),kind:GK,id:E,name:me,sourceDigest:Vr,source:QK}).strict(),fge=h.object({kind:h.string(),id:E,reason:h.string()}),a0=h.object({id:E,principalId:E,state:h.enum(["preparing","committed","cancelled"]),previous:er,replacement:er,previousSignature:tr,handoff:Fr,createdAt:Ve,finishedAt:Ve.nullable(),total:h.number().int().nonnegative(),prepared:h.number().int().nonnegative(),blockers:h.array(fge),items:h.array(pge),next:h.string().nullable()});function mge(t,e,r){let o=n=>{if(n.id!==e.id)return n;if(M(n)!==M(e))throw new Error("Use the exact previous key binding.");return r};return Wn.parse({...t,revision:t.revision+1,readers:t.readers.map(o),authorities:t.authorities.map(o)})}async function tq(t,e,r,o,n,i){let s=await Jn(t,o,n.encryption),a=await wp(s,mge(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 rr(a.policy,i.signing,"access-policy")};return ac({...l,signature:await rr(l,i.signing,"resource")})}async function hge(t,e,r,o,n,i){return{rotationId:t,principalId:e,replacementId:r,itemId:o,sourceDigest:n,payloadDigest:await vt(i)}}async function gge(t,e,r,o,n,i,s){return{sourceDigest:n,payload:i,signature:await rr(await hge(t,e,r,o,n,i),s,"key-rotation-preparation")}}var rq=t=>"key-handoff:"+t.principalId+":"+t.id;function yge(t,e,r){return el(Et(JSON.stringify(r)),[{id:t.id,publicKey:t.encryption}],rq(e))}async function nq(t,e,r){let{replacement:o,handoff:n}=XK.parse(t);if(M(o.previous.binding)!==M(e))throw new Error("This key handoff follows other keys.");let i=o.replacement.binding;if(!await _g(e,i,[o]))throw new Error("The previous keys did not authorize these replacement keys.");let s=tl.parse(JSON.parse(qt(await wo(n,r,e.id,rq(i)))));return await mp(i,s),{binding:i,keys:s}}async function oq(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",{},er);if(n?M(c)===M(n):await bo(c.encryption)===await bo(pp(e.keys.encryption)))return s?{binding:c,keys:s}:null;if(n&&c.generation<=n.generation||a===32)throw new Sg("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 bo(pp(e.keys.encryption))}),{},XK),l=n??u.replacement.previous.binding;if(!n&&await bo(l.encryption)!==await bo(pp(e.keys.encryption)))throw new Error("This key handoff follows other keys.");let d=await nq(u,l,i.encryption);({binding:n}=d),i=s=d.keys}return null}var Sg=class extends Error{code="keys_replaced";constructor(e){super(e)}},vge=h.object({rotation:a0.nullable()});async function iq(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,{},vge),a;if(s)a=await nq({replacement:{previous:s.previous,replacement:s.replacement,previousSignature:s.previousSignature},handoff:s.handoff},r,o.encryption);else{let u=await e0(),l={...t0(n,u),generation:r.generation+1,previous:await vt(r)};a={binding:l,keys:u},s=await t.json(i,{method:"POST",body:{id:crypto.randomUUID(),replacement:await mp(l,u),previousSignature:await rr(l,o.signing,"key-replacement"),handoff:await yge(r,l,u)}},a0)}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}:{}}),{},a0);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 wge(m,r,a,o);await t.json(c+"/items/"+m.kind+"/"+m.id,{method:"PUT",body:await gge(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"},a0),{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 wge(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 tq(Hr.parse(n.content),e,r.binding,e,o,r.keys)};case"keyring":{let i=await s0(String(n.signature),e);return{kind:"keyring",signature:await i0({...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 sq(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 tq(Hr.parse(i.content),o,n,e,r)};throw new Error("Only the rotating identity prepares this item.")}var aq=t=>EN(Sge(ci()),"custody",t.id),xge=t=>_ge(t).then(()=>!0,()=>!1);async function cq(t,e,r){let o=aq(e.binding),n=aq(r.binding);if(!await xge(o))return;let i=async s=>{let a=new sc(EN(o,s),t,e.binding,e.keys),c=new sc(EN(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 bge(o,{recursive:!0,force:!0})}async function uq(t){if(!t.keys||!t.binding)return t;let e;try{e=await oq(new Qi(t),{binding:t.binding,keys:t.keys})}catch(o){if(!(o instanceof Sg))throw o;return process.stderr.write("foundation: "+o.message+`
|