xmcp 1.7.2 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.js CHANGED
@@ -1,6 +1,6 @@
1
1
  (()=>{var t,r,o={6507(t,r,o){"use strict";let a=o(5317),i=o(8388),n=o(442);function s(t,r,o){let s=i(t,r,o),l=a.spawn(s.command,s.args,s.options);return n.hookChildProcess(l,s),l}t.exports=s,t.exports.spawn=s,t.exports.sync=function(t,r,o){let s=i(t,r,o),l=a.spawnSync(s.command,s.args,s.options);return l.error=l.error||n.verifyENOENTSync(l.status,s),l},t.exports._parse=i,t.exports._enoent=n},442(t){"use strict";let r="win32"===process.platform;function o(t,r){return Object.assign(Error(`${r} ${t.command} ENOENT`),{code:"ENOENT",errno:"ENOENT",syscall:`${r} ${t.command}`,path:t.command,spawnargs:t.args})}function a(t,a){return r&&1===t&&!a.file?o(a.original,"spawn"):null}t.exports={hookChildProcess:function(t,o){if(!r)return;let i=t.emit;t.emit=function(r,n){if("exit"===r){let r=a(n,o);if(r)return i.call(t,"error",r)}return i.apply(t,arguments)}},verifyENOENT:a,verifyENOENTSync:function(t,a){return r&&1===t&&!a.file?o(a.original,"spawnSync"):null},notFoundError:o}},8388(t,r,o){"use strict";let a=o(6928),i=o(3803),n=o(2077),s=o(1880),l="win32"===process.platform,c=/\.(?:com|exe)$/i,u=/node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;t.exports=function(t,r,o){r&&!Array.isArray(r)&&(o=r,r=null);let d={command:t,args:r=r?r.slice(0):[],options:o=Object.assign({},o),file:void 0,original:{command:t,args:r}};return o.shell?d:function(t){let r;if(!l)return t;let o=(t.file=i(t),(r=t.file&&s(t.file))?(t.args.unshift(t.file),t.command=r,i(t)):t.file),d=!c.test(o);if(t.options.forceShell||d){let r=u.test(o);t.command=a.normalize(t.command),t.command=n.command(t.command),t.args=t.args.map(t=>n.argument(t,r));let i=[t.command].concat(t.args).join(" ");t.args=["/d","/s","/c",`"${i}"`],t.command=process.env.comspec||"cmd.exe",t.options.windowsVerbatimArguments=!0}return t}(d)}},2077(t){"use strict";let r=/([()\][%!^"`<>&|;, *?])/g;t.exports.command=function(t){return t.replace(r,"^$1")},t.exports.argument=function(t,o){return t=(t=(t=`${t}`).replace(/(?=(\\+?)?)\1"/g,'$1$1\\"')).replace(/(?=(\\+?)?)\1$/,"$1$1"),t=(t=`"${t}"`).replace(r,"^$1"),o&&(t=t.replace(r,"^$1")),t}},1880(t,r,o){"use strict";let a=o(9896),i=o(600);t.exports=function(t){let r,o=Buffer.alloc(150);try{r=a.openSync(t,"r"),a.readSync(r,o,0,150,0),a.closeSync(r)}catch(t){}return i(o.toString())}},3803(t,r,o){"use strict";let a=o(6928),i=o(1905),n=o(9695);function s(t,r){let o,s=t.options.env||process.env,l=process.cwd(),c=null!=t.options.cwd,u=c&&void 0!==process.chdir&&!process.chdir.disabled;if(u)try{process.chdir(t.options.cwd)}catch(t){}try{o=i.sync(t.command,{path:s[n({env:s})],pathExt:r?a.delimiter:void 0})}catch(t){}finally{u&&process.chdir(l)}return o&&(o=a.resolve(c?t.options.cwd:"",o)),o}t.exports=function(t){return s(t)||s(t,!0)}},9344(t,r,o){var a;function i(t,r,o){if("function"==typeof r&&(o=r,r={}),!o){if("function"!=typeof Promise)throw TypeError("callback not provided");return new Promise(function(o,a){i(t,r||{},function(t,r){t?a(t):o(r)})})}a(t,r||{},function(t,a){t&&("EACCES"===t.code||r&&r.ignoreErrors)&&(t=null,a=!1),o(t,a)})}o(9896),a="win32"===process.platform||global.TESTING_WINDOWS?o(8541):o(709),t.exports=i,i.sync=function(t,r){try{return a.sync(t,r||{})}catch(t){if(r&&r.ignoreErrors||"EACCES"===t.code)return!1;throw t}}},709(t,r,o){t.exports=i,i.sync=function(t,r){return n(a.statSync(t),r)};var a=o(9896);function i(t,r,o){a.stat(t,function(t,a){o(t,!t&&n(a,r))})}function n(t,r){var o,a,i,n,s,l,c,u,d;return t.isFile()&&(o=t,a=r,i=o.mode,n=o.uid,s=o.gid,l=void 0!==a.uid?a.uid:process.getuid&&process.getuid(),c=void 0!==a.gid?a.gid:process.getgid&&process.getgid(),u=parseInt("100",8),d=parseInt("010",8),i&parseInt("001",8)||i&d&&s===c||i&u&&n===l||i&(u|d)&&0===l)}},8541(t,r,o){t.exports=n,n.sync=function(t,r){return i(a.statSync(t),t,r)};var a=o(9896);function i(t,r,o){if(!t.isSymbolicLink()&&!t.isFile())return!1;var a=void 0!==o.pathExt?o.pathExt:process.env.PATHEXT;if(!a||-1!==(a=a.split(";")).indexOf(""))return!0;for(var i=0;i<a.length;i++){var n=a[i].toLowerCase();if(n&&r.substr(-n.length).toLowerCase()===n)return!0}return!1}function n(t,r,o){a.stat(t,function(a,n){o(a,!a&&i(n,t,r))})}},9695(t){"use strict";let r=(t={})=>{let r=t.env||process.env;return"win32"!==(t.platform||process.platform)?"PATH":Object.keys(r).reverse().find(t=>"PATH"===t.toUpperCase())||"Path"};t.exports=r,t.exports.default=r},600(t,r,o){"use strict";let a=o(9638);t.exports=(t="")=>{let r=t.match(a);if(!r)return null;let[o,i]=r[0].replace(/#! ?/,"").split(" "),n=o.split("/").pop();return"env"===n?i:i?`${n} ${i}`:n}},9638(t){"use strict";t.exports=/^#!(.*)/},1905(t,r,o){let a="win32"===process.platform||"cygwin"===process.env.OSTYPE||"msys"===process.env.OSTYPE,i=o(6928),n=a?";":":",s=o(9344),l=t=>Object.assign(Error(`not found: ${t}`),{code:"ENOENT"}),c=(t,r)=>{let o=r.colon||n,i=t.match(/\//)||a&&t.match(/\\/)?[""]:[...a?[process.cwd()]:[],...(r.path||process.env.PATH||"").split(o)],s=a?r.pathExt||process.env.PATHEXT||".EXE;.CMD;.BAT;.COM":"",l=a?s.split(o):[""];return a&&-1!==t.indexOf(".")&&""!==l[0]&&l.unshift(""),{pathEnv:i,pathExt:l,pathExtExe:s}},u=(t,r,o)=>{"function"==typeof r&&(o=r,r={}),r||(r={});let{pathEnv:a,pathExt:n,pathExtExe:u}=c(t,r),d=[],p=o=>new Promise((n,s)=>{if(o===a.length)return r.all&&d.length?n(d):s(l(t));let c=a[o],u=/^".*"$/.test(c)?c.slice(1,-1):c,p=i.join(u,t);n(h(!u&&/^\.[\\\/]/.test(t)?t.slice(0,2)+p:p,o,0))}),h=(t,o,a)=>new Promise((i,l)=>{if(a===n.length)return i(p(o+1));let c=n[a];s(t+c,{pathExt:u},(n,s)=>{if(!n&&s)if(!r.all)return i(t+c);else d.push(t+c);return i(h(t,o,a+1))})});return o?p(0).then(t=>o(null,t),o):p(0)};t.exports=u,u.sync=(t,r)=>{let{pathEnv:o,pathExt:a,pathExtExe:n}=c(t,r=r||{}),u=[];for(let l=0;l<o.length;l++){let c=o[l],d=/^".*"$/.test(c)?c.slice(1,-1):c,p=i.join(d,t),h=!d&&/^\.[\\\/]/.test(t)?t.slice(0,2)+p:p;for(let t=0;t<a.length;t++){let o=h+a[t];try{if(s.sync(o,{pathExt:n}))if(!r.all)return o;else u.push(o)}catch(t){}}}if(r.all&&u.length)return u;if(r.nothrow)return null;throw l(t)}},5317(t){"use strict";t.exports=require("child_process")},9896(t){"use strict";t.exports=require("fs")},7598(t){"use strict";t.exports=require("node:crypto")},6928(t){"use strict";t.exports=require("path")},8775(t,r,o){"use strict";let a,i;o.r(r),o.d(r,{jwksCache:()=>tL,FlattenedEncrypt:()=>tu,decodeProtectedHeader:()=>tW,generateSecret:()=>tG,flattenedDecrypt:()=>ts,exportSPKI:()=>e0,flattenedVerify:()=>th,jwtDecrypt:()=>tE,customFetch:()=>tU,importSPKI:()=>eZ,CompactEncrypt:()=>tP,importPKCS8:()=>eX,decodeJwt:()=>tF,errors:()=>s,generalVerify:()=>tm,compactDecrypt:()=>tl,compactVerify:()=>tf,EmbeddedJWK:()=>tN,exportPKCS8:()=>e1,CompactSign:()=>tR,cryptoRuntime:()=>tX,generalDecrypt:()=>tc,createLocalJWKSet:()=>tH,FlattenedSign:()=>tk,jwtVerify:()=>t$,GeneralEncrypt:()=>tp,EncryptJWT:()=>tT,calculateJwkThumbprintUri:()=>tI,SignJWT:()=>tA,exportJWK:()=>e2,importX509:()=>eG,importJWK:()=>eY,GeneralSign:()=>tC,createRemoteJWKSet:()=>tJ,generateKeyPair:()=>tZ,calculateJwkThumbprint:()=>tj,base64url:()=>n,UnsecuredJWT:()=>tV});var n={};o.r(n),o.d(n,{decode:()=>g,encode:()=>v});var s={};o.r(s),o.d(s,{JOSEAlgNotAllowed:()=>C,JOSEError:()=>k,JOSENotSupported:()=>A,JWEDecryptionFailed:()=>T,JWEInvalid:()=>O,JWKInvalid:()=>N,JWKSInvalid:()=>M,JWKSMultipleMatchingKeys:()=>q,JWKSNoMatchingKey:()=>z,JWKSTimeout:()=>H,JWSInvalid:()=>j,JWSSignatureVerificationFailed:()=>U,JWTClaimValidationFailed:()=>R,JWTExpired:()=>x,JWTInvalid:()=>I});let l=new TextEncoder,c=new TextDecoder;function u(...t){let r=new Uint8Array(t.reduce((t,{length:r})=>t+r,0)),o=0;for(let a of t)r.set(a,o),o+=a.length;return r}function d(t,r,o){if(r<0||r>=0x100000000)throw RangeError(`value must be >= 0 and <= ${0x100000000-1}. Received ${r}`);t.set([r>>>24,r>>>16,r>>>8,255&r],o)}function p(t){let r=Math.floor(t/0x100000000),o=new Uint8Array(8);return d(o,r,0),d(o,t%0x100000000,4),o}function h(t){let r=new Uint8Array(4);return d(r,t),r}function f(t){let r=new Uint8Array(t.length);for(let o=0;o<t.length;o++){let a=t.charCodeAt(o);if(a>127)throw TypeError("non-ASCII string encountered in encode()");r[o]=a}return r}function m(t){if(Uint8Array.prototype.toBase64)return t.toBase64();let r=[];for(let o=0;o<t.length;o+=32768)r.push(String.fromCharCode.apply(null,t.subarray(o,o+32768)));return btoa(r.join(""))}function y(t){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(t);let r=atob(t),o=new Uint8Array(r.length);for(let t=0;t<r.length;t++)o[t]=r.charCodeAt(t);return o}function g(t){if(Uint8Array.fromBase64)return Uint8Array.fromBase64("string"==typeof t?t:c.decode(t),{alphabet:"base64url"});let r=t;r instanceof Uint8Array&&(r=c.decode(r)),r=r.replace(/-/g,"+").replace(/_/g,"/");try{return y(r)}catch{throw TypeError("The input to be decoded is not correctly encoded.")}}function v(t){let r=t;return("string"==typeof r&&(r=l.encode(r)),Uint8Array.prototype.toBase64)?r.toBase64({alphabet:"base64url",omitPadding:!0}):m(r).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}let _=(t,r="algorithm.name")=>TypeError(`CryptoKey does not support this operation, its ${r} must be ${t}`);function b(t,r){if(parseInt(t.hash.name.slice(4),10)!==r)throw _(`SHA-${r}`,"algorithm.hash")}function S(t,r){if(r&&!t.usages.includes(r))throw TypeError(`CryptoKey does not support this operation, its usages must include ${r}.`)}function w(t,r,o){switch(r){case"A128GCM":case"A192GCM":case"A256GCM":{if("AES-GCM"!==t.algorithm.name)throw _("AES-GCM");let o=parseInt(r.slice(1,4),10);if(t.algorithm.length!==o)throw _(o,"algorithm.length");break}case"A128KW":case"A192KW":case"A256KW":{if("AES-KW"!==t.algorithm.name)throw _("AES-KW");let o=parseInt(r.slice(1,4),10);if(t.algorithm.length!==o)throw _(o,"algorithm.length");break}case"ECDH":switch(t.algorithm.name){case"ECDH":case"X25519":break;default:throw _("ECDH or X25519")}break;case"PBES2-HS256+A128KW":case"PBES2-HS384+A192KW":case"PBES2-HS512+A256KW":if("PBKDF2"!==t.algorithm.name)throw _("PBKDF2");break;case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":if("RSA-OAEP"!==t.algorithm.name)throw _("RSA-OAEP");b(t.algorithm,parseInt(r.slice(9),10)||1);break;default:throw TypeError("CryptoKey does not support this operation")}S(t,o)}function $(t,r,...o){if((o=o.filter(Boolean)).length>2){let r=o.pop();t+=`one of type ${o.join(", ")}, or ${r}.`}else 2===o.length?t+=`one of type ${o[0]} or ${o[1]}.`:t+=`of type ${o[0]}.`;return null==r?t+=` Received ${r}`:"function"==typeof r&&r.name?t+=` Received function ${r.name}`:"object"==typeof r&&null!=r&&r.constructor?.name&&(t+=` Received an instance of ${r.constructor.name}`),t}let E=(t,...r)=>$("Key must be ",t,...r),P=(t,r,...o)=>$(`Key for the ${t} algorithm must be `,r,...o);class k extends Error{static code="ERR_JOSE_GENERIC";code="ERR_JOSE_GENERIC";constructor(t,r){super(t,r),this.name=this.constructor.name,Error.captureStackTrace?.(this,this.constructor)}}class R extends k{static code="ERR_JWT_CLAIM_VALIDATION_FAILED";code="ERR_JWT_CLAIM_VALIDATION_FAILED";claim;reason;payload;constructor(t,r,o="unspecified",a="unspecified"){super(t,{cause:{claim:o,reason:a,payload:r}}),this.claim=o,this.reason=a,this.payload=r}}class x extends k{static code="ERR_JWT_EXPIRED";code="ERR_JWT_EXPIRED";claim;reason;payload;constructor(t,r,o="unspecified",a="unspecified"){super(t,{cause:{claim:o,reason:a,payload:r}}),this.claim=o,this.reason=a,this.payload=r}}class C extends k{static code="ERR_JOSE_ALG_NOT_ALLOWED";code="ERR_JOSE_ALG_NOT_ALLOWED"}class A extends k{static code="ERR_JOSE_NOT_SUPPORTED";code="ERR_JOSE_NOT_SUPPORTED"}class T extends k{static code="ERR_JWE_DECRYPTION_FAILED";code="ERR_JWE_DECRYPTION_FAILED";constructor(t="decryption operation failed",r){super(t,r)}}class O extends k{static code="ERR_JWE_INVALID";code="ERR_JWE_INVALID"}class j extends k{static code="ERR_JWS_INVALID";code="ERR_JWS_INVALID"}class I extends k{static code="ERR_JWT_INVALID";code="ERR_JWT_INVALID"}class N extends k{static code="ERR_JWK_INVALID";code="ERR_JWK_INVALID"}class M extends k{static code="ERR_JWKS_INVALID";code="ERR_JWKS_INVALID"}class z extends k{static code="ERR_JWKS_NO_MATCHING_KEY";code="ERR_JWKS_NO_MATCHING_KEY";constructor(t="no applicable key found in the JSON Web Key Set",r){super(t,r)}}class q extends k{[Symbol.asyncIterator];static code="ERR_JWKS_MULTIPLE_MATCHING_KEYS";code="ERR_JWKS_MULTIPLE_MATCHING_KEYS";constructor(t="multiple matching keys found in the JSON Web Key Set",r){super(t,r)}}class H extends k{static code="ERR_JWKS_TIMEOUT";code="ERR_JWKS_TIMEOUT";constructor(t="request timed out",r){super(t,r)}}class U extends k{static code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";constructor(t="signature verification failed",r){super(t,r)}}function D(t){if(!L(t))throw Error("CryptoKey instance expected")}let L=t=>{if(t?.[Symbol.toStringTag]==="CryptoKey")return!0;try{return t instanceof CryptoKey}catch{return!1}},K=t=>t?.[Symbol.toStringTag]==="KeyObject",J=t=>L(t)||K(t);function V(t){switch(t){case"A128GCM":return 128;case"A192GCM":return 192;case"A256GCM":case"A128CBC-HS256":return 256;case"A192CBC-HS384":return 384;case"A256CBC-HS512":return 512;default:throw new A(`Unsupported JWE Algorithm: ${t}`)}}let W=t=>crypto.getRandomValues(new Uint8Array(V(t)>>3));function F(t,r){let o=t.byteLength<<3;if(o!==r)throw new O(`Invalid Content Encryption Key length. Expected ${r} bits, got ${o} bits`)}function B(t){switch(t){case"A128GCM":case"A128GCMKW":case"A192GCM":case"A192GCMKW":case"A256GCM":case"A256GCMKW":return 96;case"A128CBC-HS256":case"A192CBC-HS384":case"A256CBC-HS512":return 128;default:throw new A(`Unsupported JWE Algorithm: ${t}`)}}function Z(t,r){if(r.length<<3!==B(t))throw new O("Invalid Initialization Vector length")}async function G(t,r,o){if(!(r instanceof Uint8Array))throw TypeError(E(r,"Uint8Array"));let a=parseInt(t.slice(1,4),10);return{encKey:await crypto.subtle.importKey("raw",r.subarray(a>>3),"AES-CBC",!1,[o]),macKey:await crypto.subtle.importKey("raw",r.subarray(0,a>>3),{hash:`SHA-${a<<1}`,name:"HMAC"},!1,["sign"]),keySize:a}}async function X(t,r,o){return new Uint8Array((await crypto.subtle.sign("HMAC",t,r)).slice(0,o>>3))}async function Y(t,r,o,a,i){let{encKey:n,macKey:s,keySize:l}=await G(t,o,"encrypt"),c=new Uint8Array(await crypto.subtle.encrypt({iv:a,name:"AES-CBC"},n,r)),d=u(i,a,c,p(i.length<<3));return{ciphertext:c,tag:await X(s,d,l),iv:a}}async function Q(t,r){if(!(t instanceof Uint8Array))throw TypeError("First argument must be a buffer");if(!(r instanceof Uint8Array))throw TypeError("Second argument must be a buffer");let o={name:"HMAC",hash:"SHA-256"},a=await crypto.subtle.generateKey(o,!1,["sign"]),i=new Uint8Array(await crypto.subtle.sign(o,a,t)),n=new Uint8Array(await crypto.subtle.sign(o,a,r)),s=0,l=-1;for(;++l<32;)s|=i[l]^n[l];return 0===s}async function ee(t,r,o,a,i,n){let s,l,{encKey:c,macKey:d,keySize:h}=await G(t,r,"decrypt"),f=u(n,a,o,p(n.length<<3)),m=await X(d,f,h);try{s=await Q(i,m)}catch{}if(!s)throw new T;try{l=new Uint8Array(await crypto.subtle.decrypt({iv:a,name:"AES-CBC"},c,o))}catch{}if(!l)throw new T;return l}async function et(t,r,o,a,i){let n;o instanceof Uint8Array?n=await crypto.subtle.importKey("raw",o,"AES-GCM",!1,["encrypt"]):(w(o,t,"encrypt"),n=o);let s=new Uint8Array(await crypto.subtle.encrypt({additionalData:i,iv:a,name:"AES-GCM",tagLength:128},n,r)),l=s.slice(-16);return{ciphertext:s.slice(0,-16),tag:l,iv:a}}async function er(t,r,o,a,i,n){let s;r instanceof Uint8Array?s=await crypto.subtle.importKey("raw",r,"AES-GCM",!1,["decrypt"]):(w(r,t,"decrypt"),s=r);try{return new Uint8Array(await crypto.subtle.decrypt({additionalData:n,iv:a,name:"AES-GCM",tagLength:128},s,u(o,i)))}catch{throw new T}}let eo="Unsupported JWE Content Encryption Algorithm";async function ea(t,r,o,a,i){if(!L(o)&&!(o instanceof Uint8Array))throw TypeError(E(o,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(a)Z(t,a);else a=crypto.getRandomValues(new Uint8Array(B(t)>>3));switch(t){case"A128CBC-HS256":case"A192CBC-HS384":case"A256CBC-HS512":return o instanceof Uint8Array&&F(o,parseInt(t.slice(-3),10)),Y(t,r,o,a,i);case"A128GCM":case"A192GCM":case"A256GCM":return o instanceof Uint8Array&&F(o,parseInt(t.slice(1,4),10)),et(t,r,o,a,i);default:throw new A(eo)}}async function ei(t,r,o,a,i,n){if(!L(r)&&!(r instanceof Uint8Array))throw TypeError(E(r,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(!a)throw new O("JWE Initialization Vector missing");if(!i)throw new O("JWE Authentication Tag missing");switch(Z(t,a),t){case"A128CBC-HS256":case"A192CBC-HS384":case"A256CBC-HS512":return r instanceof Uint8Array&&F(r,parseInt(t.slice(-3),10)),ee(t,r,o,a,i,n);case"A128GCM":case"A192GCM":case"A256GCM":return r instanceof Uint8Array&&F(r,parseInt(t.slice(1,4),10)),er(t,r,o,a,i,n);default:throw new A(eo)}}let en=Symbol();function es(t,r){if(t)throw TypeError(`${r} can only be called once`)}function el(t,r,o){try{return g(t)}catch{throw new o(`Failed to base64url decode the ${r}`)}}async function ec(t,r){let o=`SHA-${t.slice(-3)}`;return new Uint8Array(await crypto.subtle.digest(o,r))}function eu(t){if("object"!=typeof t||null===t||"[object Object]"!==Object.prototype.toString.call(t))return!1;if(null===Object.getPrototypeOf(t))return!0;let r=t;for(;null!==Object.getPrototypeOf(r);)r=Object.getPrototypeOf(r);return Object.getPrototypeOf(t)===r}function ed(...t){let r,o=t.filter(Boolean);if(0===o.length||1===o.length)return!0;for(let t of o){let o=Object.keys(t);if(!r||0===r.size){r=new Set(o);continue}for(let t of o){if(r.has(t))return!1;r.add(t)}}return!0}let ep=t=>eu(t)&&"string"==typeof t.kty;function eh(t,r){if(t.algorithm.length!==parseInt(r.slice(1,4),10))throw TypeError(`Invalid key size for alg: ${r}`)}function ef(t,r,o){return t instanceof Uint8Array?crypto.subtle.importKey("raw",t,"AES-KW",!0,[o]):(w(t,r,o),t)}async function em(t,r,o){let a=await ef(r,t,"wrapKey");eh(a,t);let i=await crypto.subtle.importKey("raw",o,{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.wrapKey("raw",i,a,"AES-KW"))}async function ey(t,r,o){let a=await ef(r,t,"unwrapKey");eh(a,t);let i=await crypto.subtle.unwrapKey("raw",o,a,"AES-KW",{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.exportKey("raw",i))}function eg(t){return u(h(t.length),t)}async function ev(t,r,o){let a=r>>3,i=Math.ceil(a/32),n=new Uint8Array(32*i);for(let r=1;r<=i;r++){let a=new Uint8Array(4+t.length+o.length);a.set(h(r),0),a.set(t,4),a.set(o,4+t.length);let i=await ec("sha256",a);n.set(i,(r-1)*32)}return n.slice(0,a)}async function e_(t,r,o,a,i=new Uint8Array,n=new Uint8Array){var s;w(t,"ECDH"),w(r,"ECDH","deriveBits");let l=u(eg(f(o)),eg(i),eg(n),h(a),new Uint8Array);return ev(new Uint8Array(await crypto.subtle.deriveBits({name:t.algorithm.name,public:t},r,"X25519"===(s=t).algorithm.name?256:Math.ceil(parseInt(s.algorithm.namedCurve.slice(-3),10)/8)<<3)),a,l)}function eb(t){switch(t.algorithm.namedCurve){case"P-256":case"P-384":case"P-521":return!0;default:return"X25519"===t.algorithm.name}}async function eS(t,r,o,a){if(!(t instanceof Uint8Array)||t.length<8)throw new O("PBES2 Salt Input must be 8 or more octets");if(!Number.isSafeInteger(o)||1!==Math.sign(o))throw new O("PBES2 Count Input must be a positive integer");let i=u(f(r),Uint8Array.of(0),t),n=parseInt(r.slice(13,16),10),s={hash:`SHA-${r.slice(8,11)}`,iterations:o,name:"PBKDF2",salt:i},l=await (a instanceof Uint8Array?crypto.subtle.importKey("raw",a,"PBKDF2",!1,["deriveBits"]):(w(a,r,"deriveBits"),a));return new Uint8Array(await crypto.subtle.deriveBits(s,l,n))}async function ew(t,r,o,a=2048,i=crypto.getRandomValues(new Uint8Array(16))){let n=await eS(i,t,a,r);return{encryptedKey:await em(t.slice(-6),n,o),p2c:a,p2s:v(i)}}async function e$(t,r,o,a,i){let n=await eS(i,t,a,r);return ey(t.slice(-6),n,o)}function eE(t,r){if(t.startsWith("RS")||t.startsWith("PS")){let{modulusLength:o}=r.algorithm;if("number"!=typeof o||o<2048)throw TypeError(`${t} requires key modulusLength to be 2048 bits or larger`)}}function eP(t,r){let o=`SHA-${t.slice(-3)}`;switch(t){case"HS256":case"HS384":case"HS512":return{hash:o,name:"HMAC"};case"PS256":case"PS384":case"PS512":return{hash:o,name:"RSA-PSS",saltLength:parseInt(t.slice(-3),10)>>3};case"RS256":case"RS384":case"RS512":return{hash:o,name:"RSASSA-PKCS1-v1_5"};case"ES256":case"ES384":case"ES512":return{hash:o,name:"ECDSA",namedCurve:r.namedCurve};case"Ed25519":case"EdDSA":return{name:"Ed25519"};case"ML-DSA-44":case"ML-DSA-65":case"ML-DSA-87":return{name:t};default:throw new A(`alg ${t} is not supported either by JOSE or your javascript runtime`)}}async function ek(t,r,o){if(r instanceof Uint8Array){if(!t.startsWith("HS"))throw TypeError(E(r,"CryptoKey","KeyObject","JSON Web Key"));return crypto.subtle.importKey("raw",r,{hash:`SHA-${t.slice(-3)}`,name:"HMAC"},!1,[o])}switch(t){case"HS256":case"HS384":case"HS512":if("HMAC"!==r.algorithm.name)throw _("HMAC");b(r.algorithm,parseInt(t.slice(2),10));break;case"RS256":case"RS384":case"RS512":if("RSASSA-PKCS1-v1_5"!==r.algorithm.name)throw _("RSASSA-PKCS1-v1_5");b(r.algorithm,parseInt(t.slice(2),10));break;case"PS256":case"PS384":case"PS512":if("RSA-PSS"!==r.algorithm.name)throw _("RSA-PSS");b(r.algorithm,parseInt(t.slice(2),10));break;case"Ed25519":case"EdDSA":if("Ed25519"!==r.algorithm.name)throw _("Ed25519");break;case"ML-DSA-44":case"ML-DSA-65":case"ML-DSA-87":let a;if(a=r.algorithm,a.name!==t)throw _(t);break;case"ES256":case"ES384":case"ES512":{if("ECDSA"!==r.algorithm.name)throw _("ECDSA");let o=function(t){switch(t){case"ES256":return"P-256";case"ES384":return"P-384";case"ES512":return"P-521";default:throw Error("unreachable")}}(t);if(r.algorithm.namedCurve!==o)throw _(o,"algorithm.namedCurve");break}default:throw TypeError("CryptoKey does not support this operation")}return S(r,o),r}async function eR(t,r,o){let a=await ek(t,r,"sign");return eE(t,a),new Uint8Array(await crypto.subtle.sign(eP(t,a.algorithm),a,o))}async function ex(t,r,o,a){let i=await ek(t,r,"verify");eE(t,i);let n=eP(t,i.algorithm);try{return await crypto.subtle.verify(n,i,o,a)}catch{return!1}}let eC=t=>{switch(t){case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":return"RSA-OAEP";default:throw new A(`alg ${t} is not supported either by JOSE or your javascript runtime`)}};async function eA(t,r,o){return w(r,t,"encrypt"),eE(t,r),new Uint8Array(await crypto.subtle.encrypt(eC(t),r,o))}async function eT(t,r,o){return w(r,t,"decrypt"),eE(t,r),new Uint8Array(await crypto.subtle.decrypt(eC(t),r,o))}let eO='Invalid or unsupported JWK "alg" (Algorithm) Parameter value';async function ej(t){if(!t.alg)throw TypeError('"alg" argument is required when "jwk.alg" is not present');let{algorithm:r,keyUsages:o}=function(t){let r,o;switch(t.kty){case"AKP":switch(t.alg){case"ML-DSA-44":case"ML-DSA-65":case"ML-DSA-87":r={name:t.alg},o=t.priv?["sign"]:["verify"];break;default:throw new A(eO)}break;case"RSA":switch(t.alg){case"PS256":case"PS384":case"PS512":r={name:"RSA-PSS",hash:`SHA-${t.alg.slice(-3)}`},o=t.d?["sign"]:["verify"];break;case"RS256":case"RS384":case"RS512":r={name:"RSASSA-PKCS1-v1_5",hash:`SHA-${t.alg.slice(-3)}`},o=t.d?["sign"]:["verify"];break;case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":r={name:"RSA-OAEP",hash:`SHA-${parseInt(t.alg.slice(-3),10)||1}`},o=t.d?["decrypt","unwrapKey"]:["encrypt","wrapKey"];break;default:throw new A(eO)}break;case"EC":switch(t.alg){case"ES256":case"ES384":case"ES512":r={name:"ECDSA",namedCurve:({ES256:"P-256",ES384:"P-384",ES512:"P-521"})[t.alg]},o=t.d?["sign"]:["verify"];break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":r={name:"ECDH",namedCurve:t.crv},o=t.d?["deriveBits"]:[];break;default:throw new A(eO)}break;case"OKP":switch(t.alg){case"Ed25519":case"EdDSA":r={name:"Ed25519"},o=t.d?["sign"]:["verify"];break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":r={name:t.crv},o=t.d?["deriveBits"]:[];break;default:throw new A(eO)}break;default:throw new A('Invalid or unsupported JWK "kty" (Key Type) Parameter value')}return{algorithm:r,keyUsages:o}}(t),a={...t};return"AKP"!==a.kty&&delete a.alg,delete a.use,crypto.subtle.importKey("jwk",a,r,t.ext??(!t.d&&!t.priv),t.key_ops??o)}let eI="given KeyObject instance cannot be used for this algorithm",eN=async(t,r,o,i=!1)=>{let n=(a||=new WeakMap).get(t);if(n?.[o])return n[o];let s=await ej({...r,alg:o});return i&&Object.freeze(t),n?n[o]=s:a.set(t,{[o]:s}),s};async function eM(t,r){if(t instanceof Uint8Array||L(t))return t;if(K(t)){if("secret"===t.type)return t.export();if("toCryptoKey"in t&&"function"==typeof t.toCryptoKey)try{return((t,r)=>{let o,i=(a||=new WeakMap).get(t);if(i?.[r])return i[r];let n="public"===t.type,s=!!n;if("x25519"===t.asymmetricKeyType){switch(r){case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":break;default:throw TypeError(eI)}o=t.toCryptoKey(t.asymmetricKeyType,s,n?[]:["deriveBits"])}if("ed25519"===t.asymmetricKeyType){if("EdDSA"!==r&&"Ed25519"!==r)throw TypeError(eI);o=t.toCryptoKey(t.asymmetricKeyType,s,[n?"verify":"sign"])}switch(t.asymmetricKeyType){case"ml-dsa-44":case"ml-dsa-65":case"ml-dsa-87":if(r!==t.asymmetricKeyType.toUpperCase())throw TypeError(eI);o=t.toCryptoKey(t.asymmetricKeyType,s,[n?"verify":"sign"])}if("rsa"===t.asymmetricKeyType){let a;switch(r){case"RSA-OAEP":a="SHA-1";break;case"RS256":case"PS256":case"RSA-OAEP-256":a="SHA-256";break;case"RS384":case"PS384":case"RSA-OAEP-384":a="SHA-384";break;case"RS512":case"PS512":case"RSA-OAEP-512":a="SHA-512";break;default:throw TypeError(eI)}if(r.startsWith("RSA-OAEP"))return t.toCryptoKey({name:"RSA-OAEP",hash:a},s,n?["encrypt"]:["decrypt"]);o=t.toCryptoKey({name:r.startsWith("PS")?"RSA-PSS":"RSASSA-PKCS1-v1_5",hash:a},s,[n?"verify":"sign"])}if("ec"===t.asymmetricKeyType){let a=new Map([["prime256v1","P-256"],["secp384r1","P-384"],["secp521r1","P-521"]]).get(t.asymmetricKeyDetails?.namedCurve);if(!a)throw TypeError(eI);let i={ES256:"P-256",ES384:"P-384",ES512:"P-521"};i[r]&&a===i[r]&&(o=t.toCryptoKey({name:"ECDSA",namedCurve:a},s,[n?"verify":"sign"])),r.startsWith("ECDH-ES")&&(o=t.toCryptoKey({name:"ECDH",namedCurve:a},s,n?[]:["deriveBits"]))}if(!o)throw TypeError(eI);return i?i[r]=o:a.set(t,{[r]:o}),o})(t,r)}catch(t){if(t instanceof TypeError)throw t}let o=t.export({format:"jwk"});return eN(t,o,r)}if(ep(t))return t.k?g(t.k):eN(t,t,r,!0);throw Error("unreachable")}let ez=(t,r)=>{let o=(t.match(/.{1,64}/g)||[]).join("\n");return`-----BEGIN ${r}-----
2
2
  ${o}
3
- -----END ${r}-----`},eq=async(t,r,o)=>{if(K(o)){if(o.type!==t)throw TypeError(`key is not a ${t} key`);return o.export({format:"pem",type:r})}if(!L(o))throw TypeError(E(o,"CryptoKey","KeyObject"));if(!o.extractable)throw TypeError("CryptoKey is not extractable");if(o.type!==t)throw TypeError(`key is not a ${t} key`);return ez(m(new Uint8Array(await crypto.subtle.exportKey(r,o))),`${t.toUpperCase()} KEY`)},eH=(t,r)=>{if(t.byteLength!==r.length)return!1;for(let o=0;o<t.byteLength;o++)if(t[o]!==r[o])return!1;return!0},eU=t=>({data:t,pos:0}),eD=t=>{let r=t.data[t.pos++];if(128&r){let o=127&r,a=0;for(let r=0;r<o;r++)a=a<<8|t.data[t.pos++];return a}return r},eL=(t,r=1)=>{if(r<=0)return;t.pos++;let o=eD(t);t.pos+=o,r>1&&eL(t,r-1)},eK=(t,r,o)=>{if(t.data[t.pos++]!==r)throw Error(o)},eJ=(t,r)=>{let o=t.data.subarray(t.pos,t.pos+r);return t.pos+=r,o},eV=t=>{let r,o=(eK(t,6,"Expected algorithm OID"),r=eD(t),eJ(t,r));if(eH(o,[43,101,110]))return"X25519";if(!eH(o,[42,134,72,206,61,2,1]))throw Error("Unsupported key algorithm");eK(t,6,"Expected curve OID");let a=eD(t),i=eJ(t,a);for(let{name:t,oid:r}of[{name:"P-256",oid:[42,134,72,206,61,3,1,7]},{name:"P-384",oid:[43,129,4,0,34]},{name:"P-521",oid:[43,129,4,0,35]}])if(eH(i,r))return t;throw Error("Unsupported named curve")},eW=async(t,r,o,a)=>{let i,n,s="spki"===t,l=()=>s?["verify"]:["sign"];switch(o){case"PS256":case"PS384":case"PS512":i={name:"RSA-PSS",hash:`SHA-${o.slice(-3)}`},n=l();break;case"RS256":case"RS384":case"RS512":i={name:"RSASSA-PKCS1-v1_5",hash:`SHA-${o.slice(-3)}`},n=l();break;case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":i={name:"RSA-OAEP",hash:`SHA-${parseInt(o.slice(-3),10)||1}`},n=s?["encrypt","wrapKey"]:["decrypt","unwrapKey"];break;case"ES256":case"ES384":case"ES512":i={name:"ECDSA",namedCurve:({ES256:"P-256",ES384:"P-384",ES512:"P-521"})[o]},n=l();break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":try{let t=a.getNamedCurve(r);i="X25519"===t?{name:"X25519"}:{name:"ECDH",namedCurve:t}}catch(t){throw new A("Invalid or unsupported key format")}n=s?[]:["deriveBits"];break;case"Ed25519":case"EdDSA":i={name:"Ed25519"},n=l();break;case"ML-DSA-44":case"ML-DSA-65":case"ML-DSA-87":i={name:o},n=l();break;default:throw new A('Invalid or unsupported "alg" (Algorithm) value')}return crypto.subtle.importKey(t,r,i,a?.extractable??!!s,n)},eF=(t,r)=>y(t.replace(r,"")),eB=(t,r,o)=>{let a=eF(t,/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g),i=o;return r?.startsWith?.("ECDH-ES")&&((i||={}).getNamedCurve=t=>{let r=eU(t);return eK(r,48,"Invalid SPKI structure"),eD(r),eK(r,48,"Expected algorithm identifier"),eD(r),r.pos,eV(r)}),eW("spki",a,r,i)};async function eZ(t,r,o){if("string"!=typeof t||0!==t.indexOf("-----BEGIN PUBLIC KEY-----"))throw TypeError('"spki" must be SPKI formatted string');return eB(t,r,o)}async function eG(t,r,o){if("string"!=typeof t||0!==t.indexOf("-----BEGIN CERTIFICATE-----"))throw TypeError('"x509" must be X.509 formatted string');return((t,r,o)=>{let a;try{var i;let r,o,n;r=eU(i=eF(t,/(?:-----(?:BEGIN|END) CERTIFICATE-----|\s)/g)),eK(r,48,"Invalid certificate structure"),eD(r),eK(r,48,"Invalid tbsCertificate structure"),eD(r),160===i[r.pos]?eL(r,6):eL(r,5),o=r.pos,eK(r,48,"Invalid SPKI structure"),n=eD(r),a=i.subarray(o,o+n+(r.pos-o))}catch(t){throw TypeError("Failed to parse the X.509 certificate",{cause:t})}return eB(ez(m(a),"PUBLIC KEY"),r,o)})(t,r,o)}async function eX(t,r,o){let a,i;if("string"!=typeof t||0!==t.indexOf("-----BEGIN PRIVATE KEY-----"))throw TypeError('"pkcs8" must be PKCS#8 formatted string');return a=eF(t,/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g),i=o,r?.startsWith?.("ECDH-ES")&&((i||={}).getNamedCurve=t=>{let r,o=eU(t);return eK(o,48,"Invalid PKCS#8 structure"),eD(o),eK(o,2,"Expected version field"),r=eD(o),o.pos+=r,eK(o,48,"Expected algorithm identifier"),eD(o),o.pos,eV(o)}),eW("pkcs8",a,r,i)}async function eY(t,r,o){let a;if(!eu(t))throw TypeError("JWK must be an object");switch(r??=t.alg,a??=o?.extractable??t.ext,t.kty){case"oct":if("string"!=typeof t.k||!t.k)throw TypeError('missing "k" (Key Value) Parameter value');return g(t.k);case"RSA":if("oth"in t&&void 0!==t.oth)throw new A('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');return ej({...t,alg:r,ext:a});case"AKP":if("string"!=typeof t.alg||!t.alg)throw TypeError('missing "alg" (Algorithm) Parameter value');if(void 0!==r&&r!==t.alg)throw TypeError("JWK alg and alg option value mismatch");return ej({...t,ext:a});case"EC":case"OKP":return ej({...t,alg:r,ext:a});default:throw new A('Unsupported "kty" (Key Type) Parameter value')}}async function eQ(t){if(K(t))if("secret"!==t.type)return t.export({format:"jwk"});else t=t.export();if(t instanceof Uint8Array)return{kty:"oct",k:v(t)};if(!L(t))throw TypeError(E(t,"CryptoKey","KeyObject","Uint8Array"));if(!t.extractable)throw TypeError("non-extractable CryptoKey cannot be exported as a JWK");let{ext:r,key_ops:o,alg:a,use:i,...n}=await crypto.subtle.exportKey("jwk",t);return"AKP"===n.kty&&(n.alg=a),n}async function e0(t){return eq("public","spki",t)}async function e1(t){return eq("private","pkcs8",t)}async function e2(t){return eQ(t)}async function e9(t,r,o,a){let i=t.slice(0,7),n=await ea(i,o,r,a,new Uint8Array);return{encryptedKey:n.ciphertext,iv:v(n.iv),tag:v(n.tag)}}async function e4(t,r,o,a,i){return ei(t.slice(0,7),r,o,a,i,new Uint8Array)}let e5='Invalid or unsupported "alg" (JWE Algorithm) header value';function e3(t){if(void 0===t)throw new O("JWE Encrypted Key missing")}async function e6(t,r,o,a,i){switch(t){case"dir":if(void 0!==o)throw new O("Encountered unexpected JWE Encrypted Key");return r;case"ECDH-ES":if(void 0!==o)throw new O("Encountered unexpected JWE Encrypted Key");case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":{let i,n;if(!eu(a.epk))throw new O('JOSE Header "epk" (Ephemeral Public Key) missing or invalid');if(D(r),!eb(r))throw new A("ECDH with the provided key is not allowed or not supported by your javascript runtime");let s=await eY(a.epk,t);if(D(s),void 0!==a.apu){if("string"!=typeof a.apu)throw new O('JOSE Header "apu" (Agreement PartyUInfo) invalid');i=el(a.apu,"apu",O)}if(void 0!==a.apv){if("string"!=typeof a.apv)throw new O('JOSE Header "apv" (Agreement PartyVInfo) invalid');n=el(a.apv,"apv",O)}let l=await e_(s,r,"ECDH-ES"===t?a.enc:t,"ECDH-ES"===t?V(a.enc):parseInt(t.slice(-5,-2),10),i,n);if("ECDH-ES"===t)return l;return e3(o),ey(t.slice(-6),l,o)}case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":return e3(o),D(r),eT(t,r,o);case"PBES2-HS256+A128KW":case"PBES2-HS384+A192KW":case"PBES2-HS512+A256KW":{let n;if(e3(o),"number"!=typeof a.p2c)throw new O('JOSE Header "p2c" (PBES2 Count) missing or invalid');let s=i?.maxPBES2Count||1e4;if(a.p2c>s)throw new O('JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds');if("string"!=typeof a.p2s)throw new O('JOSE Header "p2s" (PBES2 Salt) missing or invalid');return n=el(a.p2s,"p2s",O),e$(t,r,o,a.p2c,n)}case"A128KW":case"A192KW":case"A256KW":return e3(o),ey(t,r,o);case"A128GCMKW":case"A192GCMKW":case"A256GCMKW":if(e3(o),"string"!=typeof a.iv)throw new O('JOSE Header "iv" (Initialization Vector) missing or invalid');if("string"!=typeof a.tag)throw new O('JOSE Header "tag" (Authentication Tag) missing or invalid');return e4(t,r,o,el(a.iv,"iv",O),el(a.tag,"tag",O));default:throw new A(e5)}}async function e8(t,r,o,a,i={}){let n,s,l;switch(t){case"dir":l=o;break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":{let c;if(D(o),!eb(o))throw new A("ECDH with the provided key is not allowed or not supported by your javascript runtime");let{apu:u,apv:d}=i;c=i.epk?await eM(i.epk,t):(await crypto.subtle.generateKey(o.algorithm,!0,["deriveBits"])).privateKey;let{x:p,y:h,crv:f,kty:m}=await e2(c),y=await e_(o,c,"ECDH-ES"===t?r:t,"ECDH-ES"===t?V(r):parseInt(t.slice(-5,-2),10),u,d);if(s={epk:{x:p,crv:f,kty:m}},"EC"===m&&(s.epk.y=h),u&&(s.apu=v(u)),d&&(s.apv=v(d)),"ECDH-ES"===t){l=y;break}l=a||W(r);let g=t.slice(-6);n=await em(g,y,l);break}case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":l=a||W(r),D(o),n=await eA(t,o,l);break;case"PBES2-HS256+A128KW":case"PBES2-HS384+A192KW":case"PBES2-HS512+A256KW":{l=a||W(r);let{p2c:c,p2s:u}=i;({encryptedKey:n,...s}=await ew(t,o,l,c,u));break}case"A128KW":case"A192KW":case"A256KW":l=a||W(r),n=await em(t,o,l);break;case"A128GCMKW":case"A192GCMKW":case"A256GCMKW":{l=a||W(r);let{iv:c}=i;({encryptedKey:n,...s}=await e9(t,o,l,c));break}default:throw new A(e5)}return{cek:l,encryptedKey:n,parameters:s}}function e7(t,r,o,a,i){let n;if(void 0!==i.crit&&a?.crit===void 0)throw new t('"crit" (Critical) Header Parameter MUST be integrity protected');if(!a||void 0===a.crit)return new Set;if(!Array.isArray(a.crit)||0===a.crit.length||a.crit.some(t=>"string"!=typeof t||0===t.length))throw new t('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');for(let s of(n=void 0!==o?new Map([...Object.entries(o),...r.entries()]):r,a.crit)){if(!n.has(s))throw new A(`Extension Header Parameter "${s}" is not recognized`);if(void 0===i[s])throw new t(`Extension Header Parameter "${s}" is missing`);if(n.get(s)&&void 0===a[s])throw new t(`Extension Header Parameter "${s}" MUST be integrity protected`)}return new Set(a.crit)}function te(t,r){if(void 0!==r&&(!Array.isArray(r)||r.some(t=>"string"!=typeof t)))throw TypeError(`"${t}" option must be an array of strings`);if(r)return new Set(r)}let tt=t=>t?.[Symbol.toStringTag],tr=(t,r,o)=>{if(void 0!==r.use){let t;switch(o){case"sign":case"verify":t="sig";break;case"encrypt":case"decrypt":t="enc"}if(r.use!==t)throw TypeError(`Invalid key for this operation, its "use" must be "${t}" when present`)}if(void 0!==r.alg&&r.alg!==t)throw TypeError(`Invalid key for this operation, its "alg" must be "${t}" when present`);if(Array.isArray(r.key_ops)){let a;switch(!0){case"sign"===o||"verify"===o:case"dir"===t:case t.includes("CBC-HS"):a=o;break;case t.startsWith("PBES2"):a="deriveBits";break;case/^A\d{3}(?:GCM)?(?:KW)?$/.test(t):a=!t.includes("GCM")&&t.endsWith("KW")?"encrypt"===o?"wrapKey":"unwrapKey":o;break;case"encrypt"===o&&t.startsWith("RSA"):a="wrapKey";break;case"decrypt"===o:a=t.startsWith("RSA")?"unwrapKey":"deriveBits"}if(a&&r.key_ops?.includes?.(a)===!1)throw TypeError(`Invalid key for this operation, its "key_ops" must include "${a}" when present`)}return!0};function to(t,r,o){switch(t.substring(0,2)){case"A1":case"A2":case"di":case"HS":case"PB":((t,r,o)=>{if(!(r instanceof Uint8Array)){if(ep(r)){if("oct"===r.kty&&"string"==typeof r.k&&tr(t,r,o))return;throw TypeError('JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present')}if(!J(r))throw TypeError(P(t,r,"CryptoKey","KeyObject","JSON Web Key","Uint8Array"));if("secret"!==r.type)throw TypeError(`${tt(r)} instances for symmetric algorithms must be of type "secret"`)}})(t,r,o);break;default:((t,r,o)=>{if(ep(r))switch(o){case"decrypt":case"sign":if("oct"!==r.kty&&("AKP"===r.kty&&"string"==typeof r.priv||"string"==typeof r.d)&&tr(t,r,o))return;throw TypeError("JSON Web Key for this operation must be a private JWK");case"encrypt":case"verify":if("oct"!==r.kty&&void 0===r.d&&void 0===r.priv&&tr(t,r,o))return;throw TypeError("JSON Web Key for this operation must be a public JWK")}if(!J(r))throw TypeError(P(t,r,"CryptoKey","KeyObject","JSON Web Key"));if("secret"===r.type)throw TypeError(`${tt(r)} instances for asymmetric algorithms must not be of type "secret"`);if("public"===r.type)switch(o){case"sign":throw TypeError(`${tt(r)} instances for asymmetric algorithm signing must be of type "private"`);case"decrypt":throw TypeError(`${tt(r)} instances for asymmetric algorithm decryption must be of type "private"`)}if("private"===r.type)switch(o){case"verify":throw TypeError(`${tt(r)} instances for asymmetric algorithm verifying must be of type "public"`);case"encrypt":throw TypeError(`${tt(r)} instances for asymmetric algorithm encryption must be of type "public"`)}})(t,r,o)}}function ta(t){if(void 0===globalThis[t])throw new A(`JWE "zip" (Compression Algorithm) Header Parameter requires the ${t} API.`)}async function ti(t){ta("CompressionStream");let r=new CompressionStream("deflate-raw"),o=r.writable.getWriter();o.write(t).catch(()=>{}),o.close().catch(()=>{});let a=[],i=r.readable.getReader();for(;;){let{value:t,done:r}=await i.read();if(r)break;a.push(t)}return u(...a)}async function tn(t,r){ta("DecompressionStream");let o=new DecompressionStream("deflate-raw"),a=o.writable.getWriter();a.write(t).catch(()=>{}),a.close().catch(()=>{});let i=[],n=0,s=o.readable.getReader();for(;;){let{value:t,done:o}=await s.read();if(o)break;if(i.push(t),n+=t.byteLength,r!==1/0&&n>r)throw new O("Decompressed plaintext exceeded the configured limit")}return u(...i)}async function ts(t,r,o){let a,i,n,s,l,d;if(!eu(t))throw new O("Flattened JWE must be an object");if(void 0===t.protected&&void 0===t.header&&void 0===t.unprotected)throw new O("JOSE Header missing");if(void 0!==t.iv&&"string"!=typeof t.iv)throw new O("JWE Initialization Vector incorrect type");if("string"!=typeof t.ciphertext)throw new O("JWE Ciphertext missing or incorrect type");if(void 0!==t.tag&&"string"!=typeof t.tag)throw new O("JWE Authentication Tag incorrect type");if(void 0!==t.protected&&"string"!=typeof t.protected)throw new O("JWE Protected Header incorrect type");if(void 0!==t.encrypted_key&&"string"!=typeof t.encrypted_key)throw new O("JWE Encrypted Key incorrect type");if(void 0!==t.aad&&"string"!=typeof t.aad)throw new O("JWE AAD incorrect type");if(void 0!==t.header&&!eu(t.header))throw new O("JWE Shared Unprotected Header incorrect type");if(void 0!==t.unprotected&&!eu(t.unprotected))throw new O("JWE Per-Recipient Unprotected Header incorrect type");if(t.protected)try{let r=g(t.protected);a=JSON.parse(c.decode(r))}catch{throw new O("JWE Protected Header is invalid")}if(!ed(a,t.header,t.unprotected))throw new O("JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint");let p={...a,...t.header,...t.unprotected};if(e7(O,new Map,o?.crit,a,p),void 0!==p.zip&&"DEF"!==p.zip)throw new A('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');if(void 0!==p.zip&&!a?.zip)throw new O('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.');let{alg:h,enc:m}=p;if("string"!=typeof h||!h)throw new O("missing JWE Algorithm (alg) in JWE Header");if("string"!=typeof m||!m)throw new O("missing JWE Encryption Algorithm (enc) in JWE Header");let y=o&&te("keyManagementAlgorithms",o.keyManagementAlgorithms),v=o&&te("contentEncryptionAlgorithms",o.contentEncryptionAlgorithms);if(y&&!y.has(h)||!y&&h.startsWith("PBES2"))throw new C('"alg" (Algorithm) Header Parameter value not allowed');if(v&&!v.has(m))throw new C('"enc" (Encryption Algorithm) Header Parameter value not allowed');void 0!==t.encrypted_key&&(i=el(t.encrypted_key,"encrypted_key",O));let _=!1;"function"==typeof r&&(r=await r(a,t),_=!0),to("dir"===h?m:h,r,"decrypt");let b=await eM(r,h);try{n=await e6(h,b,i,p,o)}catch(t){if(t instanceof TypeError||t instanceof O||t instanceof A)throw t;n=W(m)}void 0!==t.iv&&(s=el(t.iv,"iv",O)),void 0!==t.tag&&(l=el(t.tag,"tag",O));let S=void 0!==t.protected?f(t.protected):new Uint8Array;d=void 0!==t.aad?u(S,f("."),f(t.aad)):S;let w=el(t.ciphertext,"ciphertext",O),$=await ei(m,n,w,s,l,d),E={plaintext:$};if("DEF"===p.zip){let t=o?.maxDecompressedLength??25e4;if(0===t)throw new A('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');if(t!==1/0&&(!Number.isSafeInteger(t)||t<1))throw TypeError("maxDecompressedLength must be 0, a positive safe integer, or Infinity");E.plaintext=await tn($,t).catch(t=>{if(t instanceof O)throw t;throw new O("Failed to decompress plaintext",{cause:t})})}return(void 0!==t.protected&&(E.protectedHeader=a),void 0!==t.aad&&(E.additionalAuthenticatedData=el(t.aad,"aad",O)),void 0!==t.unprotected&&(E.sharedUnprotectedHeader=t.unprotected),void 0!==t.header&&(E.unprotectedHeader=t.header),_)?{...E,key:b}:E}async function tl(t,r,o){if(t instanceof Uint8Array&&(t=c.decode(t)),"string"!=typeof t)throw new O("Compact JWE must be a string or Uint8Array");let{0:a,1:i,2:n,3:s,4:l,length:u}=t.split(".");if(5!==u)throw new O("Invalid Compact JWE");let d=await ts({ciphertext:s,iv:n||void 0,protected:a,tag:l||void 0,encrypted_key:i||void 0},r,o),p={plaintext:d.plaintext,protectedHeader:d.protectedHeader};return"function"==typeof r?{...p,key:d.key}:p}async function tc(t,r,o){if(!eu(t))throw new O("General JWE must be an object");if(!Array.isArray(t.recipients)||!t.recipients.every(eu))throw new O("JWE Recipients missing or incorrect type");if(!t.recipients.length)throw new O("JWE Recipients has no members");for(let a of t.recipients)try{return await ts({aad:t.aad,ciphertext:t.ciphertext,encrypted_key:a.encrypted_key,header:a.header,iv:t.iv,protected:t.protected,tag:t.tag,unprotected:t.unprotected},r,o)}catch{}throw new T}class tu{#e;#t;#r;#o;#a;#i;#n;#s;constructor(t){if(!(t instanceof Uint8Array))throw TypeError("plaintext must be an instance of Uint8Array");this.#e=t}setKeyManagementParameters(t){return es(this.#s,"setKeyManagementParameters"),this.#s=t,this}setProtectedHeader(t){return es(this.#t,"setProtectedHeader"),this.#t=t,this}setSharedUnprotectedHeader(t){return es(this.#r,"setSharedUnprotectedHeader"),this.#r=t,this}setUnprotectedHeader(t){return es(this.#o,"setUnprotectedHeader"),this.#o=t,this}setAdditionalAuthenticatedData(t){return this.#a=t,this}setContentEncryptionKey(t){return es(this.#i,"setContentEncryptionKey"),this.#i=t,this}setInitializationVector(t){return es(this.#n,"setInitializationVector"),this.#n=t,this}async encrypt(t,r){let o,a,i,n,s,l;if(!this.#t&&!this.#o&&!this.#r)throw new O("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");if(!ed(this.#t,this.#o,this.#r))throw new O("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");let c={...this.#t,...this.#o,...this.#r};if(e7(O,new Map,r?.crit,this.#t,c),void 0!==c.zip&&"DEF"!==c.zip)throw new A('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');if(void 0!==c.zip&&!this.#t?.zip)throw new O('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.');let{alg:d,enc:p}=c;if("string"!=typeof d||!d)throw new O('JWE "alg" (Algorithm) Header Parameter missing or invalid');if("string"!=typeof p||!p)throw new O('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');if(this.#i&&("dir"===d||"ECDH-ES"===d))throw TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${d}`);to("dir"===d?p:d,t,"encrypt");{let i,n=await eM(t,d);({cek:a,encryptedKey:o,parameters:i}=await e8(d,p,n,this.#i,this.#s)),i&&(r&&en in r?this.#o?this.#o={...this.#o,...i}:this.setUnprotectedHeader(i):this.#t?this.#t={...this.#t,...i}:this.setProtectedHeader(i))}if(this.#t?s=f(n=v(JSON.stringify(this.#t))):(n="",s=new Uint8Array),this.#a){let t=f(l=v(this.#a));i=u(s,f("."),t)}else i=s;let h=this.#e;"DEF"===c.zip&&(h=await ti(h).catch(t=>{throw new O("Failed to compress plaintext",{cause:t})}));let{ciphertext:m,tag:y,iv:g}=await ea(p,h,a,this.#n,i),_={ciphertext:v(m)};return g&&(_.iv=v(g)),y&&(_.tag=v(y)),o&&(_.encrypted_key=v(o)),l&&(_.aad=l),this.#t&&(_.protected=n),this.#r&&(_.unprotected=this.#r),this.#o&&(_.header=this.#o),_}}class td{#l;unprotectedHeader;keyManagementParameters;key;options;constructor(t,r,o){this.#l=t,this.key=r,this.options=o}setUnprotectedHeader(t){return es(this.unprotectedHeader,"setUnprotectedHeader"),this.unprotectedHeader=t,this}setKeyManagementParameters(t){return es(this.keyManagementParameters,"setKeyManagementParameters"),this.keyManagementParameters=t,this}addRecipient(...t){return this.#l.addRecipient(...t)}encrypt(...t){return this.#l.encrypt(...t)}done(){return this.#l}}class tp{#e;#c=[];#t;#o;#a;constructor(t){this.#e=t}addRecipient(t,r){let o=new td(this,t,{crit:r?.crit});return this.#c.push(o),o}setProtectedHeader(t){return es(this.#t,"setProtectedHeader"),this.#t=t,this}setSharedUnprotectedHeader(t){return es(this.#o,"setSharedUnprotectedHeader"),this.#o=t,this}setAdditionalAuthenticatedData(t){return this.#a=t,this}async encrypt(){let t;if(!this.#c.length)throw new O("at least one recipient must be added");if(1===this.#c.length){let[t]=this.#c,r=await new tu(this.#e).setAdditionalAuthenticatedData(this.#a).setProtectedHeader(this.#t).setSharedUnprotectedHeader(this.#o).setUnprotectedHeader(t.unprotectedHeader).encrypt(t.key,{...t.options}),o={ciphertext:r.ciphertext,iv:r.iv,recipients:[{}],tag:r.tag};return r.aad&&(o.aad=r.aad),r.protected&&(o.protected=r.protected),r.unprotected&&(o.unprotected=r.unprotected),r.encrypted_key&&(o.recipients[0].encrypted_key=r.encrypted_key),r.header&&(o.recipients[0].header=r.header),o}for(let r=0;r<this.#c.length;r++){let o=this.#c[r];if(!ed(this.#t,this.#o,o.unprotectedHeader))throw new O("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");let a={...this.#t,...this.#o,...o.unprotectedHeader},{alg:i}=a;if("string"!=typeof i||!i)throw new O('JWE "alg" (Algorithm) Header Parameter missing or invalid');if("dir"===i||"ECDH-ES"===i)throw new O('"dir" and "ECDH-ES" alg may only be used with a single recipient');if("string"!=typeof a.enc||!a.enc)throw new O('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');if(t){if(t!==a.enc)throw new O('JWE "enc" (Encryption Algorithm) Header Parameter must be the same for all recipients')}else t=a.enc;if(e7(O,new Map,o.options.crit,this.#t,a),void 0!==a.zip&&"DEF"!==a.zip)throw new A('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');if(void 0!==a.zip&&!this.#t?.zip)throw new O('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.')}let r=W(t),o={ciphertext:"",recipients:[]};for(let a=0;a<this.#c.length;a++){let i=this.#c[a],n={};if(o.recipients.push(n),0===a){let t=await new tu(this.#e).setAdditionalAuthenticatedData(this.#a).setContentEncryptionKey(r).setProtectedHeader(this.#t).setSharedUnprotectedHeader(this.#o).setUnprotectedHeader(i.unprotectedHeader).setKeyManagementParameters(i.keyManagementParameters).encrypt(i.key,{...i.options,[en]:!0});o.ciphertext=t.ciphertext,o.iv=t.iv,o.tag=t.tag,t.aad&&(o.aad=t.aad),t.protected&&(o.protected=t.protected),t.unprotected&&(o.unprotected=t.unprotected),n.encrypted_key=t.encrypted_key,t.header&&(n.header=t.header);continue}let s=i.unprotectedHeader?.alg||this.#t?.alg||this.#o?.alg;to("dir"===s?t:s,i.key,"encrypt");let l=await eM(i.key,s),{encryptedKey:c,parameters:u}=await e8(s,t,l,r,i.keyManagementParameters);n.encrypted_key=v(c),(i.unprotectedHeader||u)&&(n.header={...i.unprotectedHeader,...u})}return o}}async function th(t,r,o){if(!eu(t))throw new j("Flattened JWS must be an object");if(void 0===t.protected&&void 0===t.header)throw new j('Flattened JWS must have either of the "protected" or "header" members');if(void 0!==t.protected&&"string"!=typeof t.protected)throw new j("JWS Protected Header incorrect type");if(void 0===t.payload)throw new j("JWS Payload missing");if("string"!=typeof t.signature)throw new j("JWS Signature missing or incorrect type");if(void 0!==t.header&&!eu(t.header))throw new j("JWS Unprotected Header incorrect type");let a={};if(t.protected)try{let r=g(t.protected);a=JSON.parse(c.decode(r))}catch{throw new j("JWS Protected Header is invalid")}if(!ed(a,t.header))throw new j("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");let i={...a,...t.header},n=e7(j,new Map([["b64",!0]]),o?.crit,a,i),s=!0;if(n.has("b64")&&"boolean"!=typeof(s=a.b64))throw new j('The "b64" (base64url-encode payload) Header Parameter must be a boolean');let{alg:d}=i;if("string"!=typeof d||!d)throw new j('JWS "alg" (Algorithm) Header Parameter missing or invalid');let p=o&&te("algorithms",o.algorithms);if(p&&!p.has(d))throw new C('"alg" (Algorithm) Header Parameter value not allowed');if(s){if("string"!=typeof t.payload)throw new j("JWS Payload must be a string")}else if("string"!=typeof t.payload&&!(t.payload instanceof Uint8Array))throw new j("JWS Payload must be a string or an Uint8Array instance");let h=!1;"function"==typeof r&&(r=await r(a,t),h=!0),to(d,r,"verify");let m=u(void 0!==t.protected?f(t.protected):new Uint8Array,f("."),"string"==typeof t.payload?s?f(t.payload):l.encode(t.payload):t.payload),y=el(t.signature,"signature",j),v=await eM(r,d);if(!await ex(d,v,y,m))throw new U;let _={payload:s?el(t.payload,"payload",j):"string"==typeof t.payload?l.encode(t.payload):t.payload};return(void 0!==t.protected&&(_.protectedHeader=a),void 0!==t.header&&(_.unprotectedHeader=t.header),h)?{..._,key:v}:_}async function tf(t,r,o){if(t instanceof Uint8Array&&(t=c.decode(t)),"string"!=typeof t)throw new j("Compact JWS must be a string or Uint8Array");let{0:a,1:i,2:n,length:s}=t.split(".");if(3!==s)throw new j("Invalid Compact JWS");let l=await th({payload:i,protected:a,signature:n},r,o),u={payload:l.payload,protectedHeader:l.protectedHeader};return"function"==typeof r?{...u,key:l.key}:u}async function tm(t,r,o){if(!eu(t))throw new j("General JWS must be an object");if(!Array.isArray(t.signatures)||!t.signatures.every(eu))throw new j("JWS Signatures missing or incorrect type");for(let a of t.signatures)try{return await th({header:a.header,payload:t.payload,protected:a.protected,signature:a.signature},r,o)}catch{}throw new U}let ty=t=>Math.floor(t.getTime()/1e3),tg=/^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;function tv(t){let r,o=tg.exec(t);if(!o||o[4]&&o[1])throw TypeError("Invalid time period format");let a=parseFloat(o[2]);switch(o[3].toLowerCase()){case"sec":case"secs":case"second":case"seconds":case"s":r=Math.round(a);break;case"minute":case"minutes":case"min":case"mins":case"m":r=Math.round(60*a);break;case"hour":case"hours":case"hr":case"hrs":case"h":r=Math.round(3600*a);break;case"day":case"days":case"d":r=Math.round(86400*a);break;case"week":case"weeks":case"w":r=Math.round(604800*a);break;default:r=Math.round(0x1e187e0*a)}return"-"===o[1]||"ago"===o[4]?-r:r}function t_(t,r){if(!Number.isFinite(r))throw TypeError(`Invalid ${t} input`);return r}let tb=t=>t.includes("/")?t.toLowerCase():`application/${t.toLowerCase()}`;function tS(t,r,o={}){var a,i;let n,s;try{n=JSON.parse(c.decode(r))}catch{}if(!eu(n))throw new I("JWT Claims Set must be a top-level JSON object");let{typ:l}=o;if(l&&("string"!=typeof t.typ||tb(t.typ)!==tb(l)))throw new R('unexpected "typ" JWT header value',n,"typ","check_failed");let{requiredClaims:u=[],issuer:d,subject:p,audience:h,maxTokenAge:f}=o,m=[...u];for(let t of(void 0!==f&&m.push("iat"),void 0!==h&&m.push("aud"),void 0!==p&&m.push("sub"),void 0!==d&&m.push("iss"),new Set(m.reverse())))if(!(t in n))throw new R(`missing required "${t}" claim`,n,t,"missing");if(d&&!(Array.isArray(d)?d:[d]).includes(n.iss))throw new R('unexpected "iss" claim value',n,"iss","check_failed");if(p&&n.sub!==p)throw new R('unexpected "sub" claim value',n,"sub","check_failed");if(h&&(a=n.aud,i="string"==typeof h?[h]:h,"string"==typeof a?!i.includes(a):!(Array.isArray(a)&&i.some(Set.prototype.has.bind(new Set(a))))))throw new R('unexpected "aud" claim value',n,"aud","check_failed");switch(typeof o.clockTolerance){case"string":s=tv(o.clockTolerance);break;case"number":s=o.clockTolerance;break;case"undefined":s=0;break;default:throw TypeError("Invalid clockTolerance option type")}let{currentDate:y}=o,g=ty(y||new Date);if((void 0!==n.iat||f)&&"number"!=typeof n.iat)throw new R('"iat" claim must be a number',n,"iat","invalid");if(void 0!==n.nbf){if("number"!=typeof n.nbf)throw new R('"nbf" claim must be a number',n,"nbf","invalid");if(n.nbf>g+s)throw new R('"nbf" claim timestamp check failed',n,"nbf","check_failed")}if(void 0!==n.exp){if("number"!=typeof n.exp)throw new R('"exp" claim must be a number',n,"exp","invalid");if(n.exp<=g-s)throw new x('"exp" claim timestamp check failed',n,"exp","check_failed")}if(f){let t=g-n.iat;if(t-s>("number"==typeof f?f:tv(f)))throw new x('"iat" claim timestamp check failed (too far in the past)',n,"iat","check_failed");if(t<0-s)throw new R('"iat" claim timestamp check failed (it should be in the past)',n,"iat","check_failed")}return n}class tw{#u;constructor(t){if(!eu(t))throw TypeError("JWT Claims Set MUST be an object");this.#u=structuredClone(t)}data(){return l.encode(JSON.stringify(this.#u))}get iss(){return this.#u.iss}set iss(t){this.#u.iss=t}get sub(){return this.#u.sub}set sub(t){this.#u.sub=t}get aud(){return this.#u.aud}set aud(t){this.#u.aud=t}set jti(t){this.#u.jti=t}set nbf(t){"number"==typeof t?this.#u.nbf=t_("setNotBefore",t):t instanceof Date?this.#u.nbf=t_("setNotBefore",ty(t)):this.#u.nbf=ty(new Date)+tv(t)}set exp(t){"number"==typeof t?this.#u.exp=t_("setExpirationTime",t):t instanceof Date?this.#u.exp=t_("setExpirationTime",ty(t)):this.#u.exp=ty(new Date)+tv(t)}set iat(t){void 0===t?this.#u.iat=ty(new Date):t instanceof Date?this.#u.iat=t_("setIssuedAt",ty(t)):"string"==typeof t?this.#u.iat=t_("setIssuedAt",ty(new Date)+tv(t)):this.#u.iat=t_("setIssuedAt",t)}}async function t$(t,r,o){let a=await tf(t,r,o);if(a.protectedHeader.crit?.includes("b64")&&!1===a.protectedHeader.b64)throw new I("JWTs MUST NOT use unencoded payload");let i={payload:tS(a.protectedHeader,a.payload,o),protectedHeader:a.protectedHeader};return"function"==typeof r?{...i,key:a.key}:i}async function tE(t,r,o){let a=await tl(t,r,o),i=tS(a.protectedHeader,a.plaintext,o),{protectedHeader:n}=a;if(void 0!==n.iss&&n.iss!==i.iss)throw new R('replicated "iss" claim header parameter mismatch',i,"iss","mismatch");if(void 0!==n.sub&&n.sub!==i.sub)throw new R('replicated "sub" claim header parameter mismatch',i,"sub","mismatch");if(void 0!==n.aud&&JSON.stringify(n.aud)!==JSON.stringify(i.aud))throw new R('replicated "aud" claim header parameter mismatch',i,"aud","mismatch");let s={payload:i,protectedHeader:n};return"function"==typeof r?{...s,key:a.key}:s}class tP{#d;constructor(t){this.#d=new tu(t)}setContentEncryptionKey(t){return this.#d.setContentEncryptionKey(t),this}setInitializationVector(t){return this.#d.setInitializationVector(t),this}setProtectedHeader(t){return this.#d.setProtectedHeader(t),this}setKeyManagementParameters(t){return this.#d.setKeyManagementParameters(t),this}async encrypt(t,r){let o=await this.#d.encrypt(t,r);return[o.protected,o.encrypted_key,o.iv,o.ciphertext,o.tag].join(".")}}class tk{#u;#t;#o;constructor(t){if(!(t instanceof Uint8Array))throw TypeError("payload must be an instance of Uint8Array");this.#u=t}setProtectedHeader(t){return es(this.#t,"setProtectedHeader"),this.#t=t,this}setUnprotectedHeader(t){return es(this.#o,"setUnprotectedHeader"),this.#o=t,this}async sign(t,r){let o,a,i,n;if(!this.#t&&!this.#o)throw new j("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");if(!ed(this.#t,this.#o))throw new j("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");let s={...this.#t,...this.#o},l=e7(j,new Map([["b64",!0]]),r?.crit,this.#t,s),c=!0;if(l.has("b64")&&"boolean"!=typeof(c=this.#t.b64))throw new j('The "b64" (base64url-encode payload) Header Parameter must be a boolean');let{alg:d}=s;if("string"!=typeof d||!d)throw new j('JWS "alg" (Algorithm) Header Parameter missing or invalid');to(d,t,"sign"),c?a=f(o=v(this.#u)):(a=this.#u,o=""),this.#t?n=f(i=v(JSON.stringify(this.#t))):(i="",n=new Uint8Array);let p=u(n,f("."),a),h=await eM(t,d),m={signature:v(await eR(d,h,p)),payload:o};return this.#o&&(m.header=this.#o),this.#t&&(m.protected=i),m}}class tR{#d;constructor(t){this.#d=new tk(t)}setProtectedHeader(t){return this.#d.setProtectedHeader(t),this}async sign(t,r){let o=await this.#d.sign(t,r);if(void 0===o.payload)throw TypeError("use the flattened module for creating JWS with b64: false");return`${o.protected}.${o.payload}.${o.signature}`}}class tx{#l;protectedHeader;unprotectedHeader;options;key;constructor(t,r,o){this.#l=t,this.key=r,this.options=o}setProtectedHeader(t){return es(this.protectedHeader,"setProtectedHeader"),this.protectedHeader=t,this}setUnprotectedHeader(t){return es(this.unprotectedHeader,"setUnprotectedHeader"),this.unprotectedHeader=t,this}addSignature(...t){return this.#l.addSignature(...t)}sign(...t){return this.#l.sign(...t)}done(){return this.#l}}class tC{#u;#p=[];constructor(t){this.#u=t}addSignature(t,r){let o=new tx(this,t,r);return this.#p.push(o),o}async sign(){if(!this.#p.length)throw new j("at least one signature must be added");let t={signatures:[],payload:""};for(let r=0;r<this.#p.length;r++){let o=this.#p[r],a=new tk(this.#u);a.setProtectedHeader(o.protectedHeader),a.setUnprotectedHeader(o.unprotectedHeader);let{payload:i,...n}=await a.sign(o.key,o.options);if(0===r)t.payload=i;else if(t.payload!==i)throw new j("inconsistent use of JWS Unencoded Payload (RFC7797)");t.signatures.push(n)}return t}}class tA{#t;#h;constructor(t={}){this.#h=new tw(t)}setIssuer(t){return this.#h.iss=t,this}setSubject(t){return this.#h.sub=t,this}setAudience(t){return this.#h.aud=t,this}setJti(t){return this.#h.jti=t,this}setNotBefore(t){return this.#h.nbf=t,this}setExpirationTime(t){return this.#h.exp=t,this}setIssuedAt(t){return this.#h.iat=t,this}setProtectedHeader(t){return this.#t=t,this}async sign(t,r){let o=new tR(this.#h.data());if(o.setProtectedHeader(this.#t),Array.isArray(this.#t?.crit)&&this.#t.crit.includes("b64")&&!1===this.#t.b64)throw new I("JWTs MUST NOT use unencoded payload");return o.sign(t,r)}}class tT{#i;#n;#s;#t;#f;#m;#y;#h;constructor(t={}){this.#h=new tw(t)}setIssuer(t){return this.#h.iss=t,this}setSubject(t){return this.#h.sub=t,this}setAudience(t){return this.#h.aud=t,this}setJti(t){return this.#h.jti=t,this}setNotBefore(t){return this.#h.nbf=t,this}setExpirationTime(t){return this.#h.exp=t,this}setIssuedAt(t){return this.#h.iat=t,this}setProtectedHeader(t){return es(this.#t,"setProtectedHeader"),this.#t=t,this}setKeyManagementParameters(t){return es(this.#s,"setKeyManagementParameters"),this.#s=t,this}setContentEncryptionKey(t){return es(this.#i,"setContentEncryptionKey"),this.#i=t,this}setInitializationVector(t){return es(this.#n,"setInitializationVector"),this.#n=t,this}replicateIssuerAsHeader(){return this.#f=!0,this}replicateSubjectAsHeader(){return this.#m=!0,this}replicateAudienceAsHeader(){return this.#y=!0,this}async encrypt(t,r){let o=new tP(this.#h.data());return this.#t&&(this.#f||this.#m||this.#y)&&(this.#t={...this.#t,iss:this.#f?this.#h.iss:void 0,sub:this.#m?this.#h.sub:void 0,aud:this.#y?this.#h.aud:void 0}),o.setProtectedHeader(this.#t),this.#n&&o.setInitializationVector(this.#n),this.#i&&o.setContentEncryptionKey(this.#i),this.#s&&o.setKeyManagementParameters(this.#s),o.encrypt(t,r)}}let tO=(t,r)=>{if("string"!=typeof t||!t)throw new N(`${r} missing or invalid`)};async function tj(t,r){let o,a;if(ep(t))o=t;else if(J(t))o=await e2(t);else throw TypeError(E(t,"CryptoKey","KeyObject","JSON Web Key"));if("sha256"!==(r??="sha256")&&"sha384"!==r&&"sha512"!==r)throw TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');switch(o.kty){case"AKP":tO(o.alg,'"alg" (Algorithm) Parameter'),tO(o.pub,'"pub" (Public key) Parameter'),a={alg:o.alg,kty:o.kty,pub:o.pub};break;case"EC":tO(o.crv,'"crv" (Curve) Parameter'),tO(o.x,'"x" (X Coordinate) Parameter'),tO(o.y,'"y" (Y Coordinate) Parameter'),a={crv:o.crv,kty:o.kty,x:o.x,y:o.y};break;case"OKP":tO(o.crv,'"crv" (Subtype of Key Pair) Parameter'),tO(o.x,'"x" (Public Key) Parameter'),a={crv:o.crv,kty:o.kty,x:o.x};break;case"RSA":tO(o.e,'"e" (Exponent) Parameter'),tO(o.n,'"n" (Modulus) Parameter'),a={e:o.e,kty:o.kty,n:o.n};break;case"oct":tO(o.k,'"k" (Key Value) Parameter'),a={k:o.k,kty:o.kty};break;default:throw new A('"kty" (Key Type) Parameter missing or unsupported')}let i=f(JSON.stringify(a));return v(await ec(r,i))}async function tI(t,r){r??="sha256";let o=await tj(t,r);return`urn:ietf:params:oauth:jwk-thumbprint:sha-${r.slice(-3)}:${o}`}async function tN(t,r){let o={...t,...r?.header};if(!eu(o.jwk))throw new j('"jwk" (JSON Web Key) Header Parameter must be a JSON object');let a=await eY({...o.jwk,ext:!0},o.alg);if(a instanceof Uint8Array||"public"!==a.type)throw new j('"jwk" (JSON Web Key) Header Parameter must be a public key');return a}function tM(t){return eu(t)}class tz{#g;#v=new WeakMap;constructor(t){if(!function(t){return t&&"object"==typeof t&&Array.isArray(t.keys)&&t.keys.every(tM)}(t))throw new M("JSON Web Key Set malformed");this.#g=structuredClone(t)}jwks(){return this.#g}async getKey(t,r){let{alg:o,kid:a}={...t,...r?.header},i=function(t){switch("string"==typeof t&&t.slice(0,2)){case"RS":case"PS":return"RSA";case"ES":return"EC";case"Ed":return"OKP";case"ML":return"AKP";default:throw new A('Unsupported "alg" value for a JSON Web Key Set')}}(o),n=this.#g.keys.filter(t=>{let r=i===t.kty;if(r&&"string"==typeof a&&(r=a===t.kid),r&&("string"==typeof t.alg||"AKP"===i)&&(r=o===t.alg),r&&"string"==typeof t.use&&(r="sig"===t.use),r&&Array.isArray(t.key_ops)&&(r=t.key_ops.includes("verify")),r)switch(o){case"ES256":r="P-256"===t.crv;break;case"ES384":r="P-384"===t.crv;break;case"ES512":r="P-521"===t.crv;break;case"Ed25519":case"EdDSA":r="Ed25519"===t.crv}return r}),{0:s,length:l}=n;if(0===l)throw new z;if(1!==l){let t=new q,r=this.#v;throw t[Symbol.asyncIterator]=async function*(){for(let t of n)try{yield await tq(r,t,o)}catch{}},t}return tq(this.#v,s,o)}}async function tq(t,r,o){let a=t.get(r)||t.set(r,{}).get(r);if(void 0===a[o]){let t=await eY({...r,ext:!0},o);if(t instanceof Uint8Array||"public"!==t.type)throw new M("JSON Web Key Set members must be public keys");a[o]=t}return a[o]}function tH(t){let r=new tz(t),o=async(t,o)=>r.getKey(t,o);return Object.defineProperties(o,{jwks:{value:()=>structuredClone(r.jwks()),enumerable:!1,configurable:!1,writable:!1}}),o}"undefined"!=typeof navigator&&navigator.userAgent?.startsWith?.("Mozilla/5.0 ")||(i="jose/v6.2.3");let tU=Symbol();async function tD(t,r,o,a=fetch){let i=await a(t,{method:"GET",signal:o,redirect:"manual",headers:r}).catch(t=>{if("TimeoutError"===t.name)throw new H;throw t});if(200!==i.status)throw new k("Expected 200 OK from the JSON Web Key Set HTTP response");try{return await i.json()}catch{throw new k("Failed to parse the JSON Web Key Set HTTP response as JSON")}}let tL=Symbol();class tK{#_;#b;#S;#w;#$;#E;#P;#k;#R;#x;constructor(t,r){if(!(t instanceof URL))throw TypeError("url must be an instance of URL");this.#_=new URL(t.href),this.#b="number"==typeof r?.timeoutDuration?r?.timeoutDuration:5e3,this.#S="number"==typeof r?.cooldownDuration?r?.cooldownDuration:3e4,this.#w="number"==typeof r?.cacheMaxAge?r?.cacheMaxAge:6e5,this.#P=new Headers(r?.headers),i&&!this.#P.has("User-Agent")&&this.#P.set("User-Agent",i),this.#P.has("accept")||(this.#P.set("accept","application/json"),this.#P.append("accept","application/jwk-set+json")),this.#k=r?.[tU],r?.[tL]!==void 0&&(this.#x=r?.[tL],function(t,r){return!("object"!=typeof t||null===t||!("uat"in t)||"number"!=typeof t.uat||Date.now()-t.uat>=r)&&"jwks"in t&&!!eu(t.jwks)&&!!Array.isArray(t.jwks.keys)&&!!Array.prototype.every.call(t.jwks.keys,eu)}(r?.[tL],this.#w)&&(this.#$=this.#x.uat,this.#R=tH(this.#x.jwks)))}pendingFetch(){return!!this.#E}coolingDown(){return"number"==typeof this.#$&&Date.now()<this.#$+this.#S}fresh(){return"number"==typeof this.#$&&Date.now()<this.#$+this.#w}jwks(){return this.#R?.jwks()}async getKey(t,r){this.#R&&this.fresh()||await this.reload();try{return await this.#R(t,r)}catch(o){if(o instanceof z&&!1===this.coolingDown())return await this.reload(),this.#R(t,r);throw o}}async reload(){this.#E&&("undefined"!=typeof WebSocketPair||"undefined"!=typeof navigator&&"Cloudflare-Workers"===navigator.userAgent||"undefined"!=typeof EdgeRuntime&&"vercel"===EdgeRuntime)&&(this.#E=void 0),this.#E||=tD(this.#_.href,this.#P,AbortSignal.timeout(this.#b),this.#k).then(t=>{this.#R=tH(t),this.#x&&(this.#x.uat=Date.now(),this.#x.jwks=t),this.#$=Date.now(),this.#E=void 0}).catch(t=>{throw this.#E=void 0,t}),await this.#E}}function tJ(t,r){let o=new tK(t,r),a=async(t,r)=>o.getKey(t,r);return Object.defineProperties(a,{coolingDown:{get:()=>o.coolingDown(),enumerable:!0,configurable:!1},fresh:{get:()=>o.fresh(),enumerable:!0,configurable:!1},reload:{value:()=>o.reload(),enumerable:!0,configurable:!1,writable:!1},reloading:{get:()=>o.pendingFetch(),enumerable:!0,configurable:!1},jwks:{value:()=>o.jwks(),enumerable:!0,configurable:!1,writable:!1}}),a}class tV{#h;constructor(t={}){this.#h=new tw(t)}encode(){let t=v(JSON.stringify({alg:"none"})),r=v(this.#h.data());return`${t}.${r}.`}setIssuer(t){return this.#h.iss=t,this}setSubject(t){return this.#h.sub=t,this}setAudience(t){return this.#h.aud=t,this}setJti(t){return this.#h.jti=t,this}setNotBefore(t){return this.#h.nbf=t,this}setExpirationTime(t){return this.#h.exp=t,this}setIssuedAt(t){return this.#h.iat=t,this}static decode(t,r){let o;if("string"!=typeof t)throw new I("Unsecured JWT must be a string");let{0:a,1:i,2:n,length:s}=t.split(".");if(3!==s||""!==n)throw new I("Invalid Unsecured JWT");try{if(o=JSON.parse(c.decode(g(a))),"none"!==o.alg)throw Error()}catch{throw new I("Invalid Unsecured JWT")}return{payload:tS(o,g(i),r),header:o}}}function tW(t){let r;if("string"==typeof t){let o=t.split(".");(3===o.length||5===o.length)&&([r]=o)}else if("object"==typeof t&&t)if("protected"in t)r=t.protected;else throw TypeError("Token does not contain a Protected Header");try{if("string"!=typeof r||!r)throw Error();let t=JSON.parse(c.decode(g(r)));if(!eu(t))throw Error();return t}catch{throw TypeError("Invalid Token or Protected Header formatting")}}function tF(t){let r,o;if("string"!=typeof t)throw new I("JWTs must use Compact JWS serialization, JWT must be a string");let{1:a,length:i}=t.split(".");if(5===i)throw new I("Only JWTs using Compact JWS serialization can be decoded");if(3!==i)throw new I("Invalid JWT");if(!a)throw new I("JWTs must contain a payload");try{r=g(a)}catch{throw new I("Failed to base64url decode the payload")}try{o=JSON.parse(c.decode(r))}catch{throw new I("Failed to parse the decoded payload as JSON")}if(!eu(o))throw new I("Invalid JWT Claims Set");return o}function tB(t){let r=t?.modulusLength??2048;if("number"!=typeof r||r<2048)throw new A("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");return r}async function tZ(t,r){let o,a;switch(t){case"PS256":case"PS384":case"PS512":o={name:"RSA-PSS",hash:`SHA-${t.slice(-3)}`,publicExponent:Uint8Array.of(1,0,1),modulusLength:tB(r)},a=["sign","verify"];break;case"RS256":case"RS384":case"RS512":o={name:"RSASSA-PKCS1-v1_5",hash:`SHA-${t.slice(-3)}`,publicExponent:Uint8Array.of(1,0,1),modulusLength:tB(r)},a=["sign","verify"];break;case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":o={name:"RSA-OAEP",hash:`SHA-${parseInt(t.slice(-3),10)||1}`,publicExponent:Uint8Array.of(1,0,1),modulusLength:tB(r)},a=["decrypt","unwrapKey","encrypt","wrapKey"];break;case"ES256":o={name:"ECDSA",namedCurve:"P-256"},a=["sign","verify"];break;case"ES384":o={name:"ECDSA",namedCurve:"P-384"},a=["sign","verify"];break;case"ES512":o={name:"ECDSA",namedCurve:"P-521"},a=["sign","verify"];break;case"Ed25519":case"EdDSA":a=["sign","verify"],o={name:"Ed25519"};break;case"ML-DSA-44":case"ML-DSA-65":case"ML-DSA-87":a=["sign","verify"],o={name:t};break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":{a=["deriveBits"];let t=r?.crv??"P-256";switch(t){case"P-256":case"P-384":case"P-521":o={name:"ECDH",namedCurve:t};break;case"X25519":o={name:"X25519"};break;default:throw new A("Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, and X25519")}break}default:throw new A('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}return crypto.subtle.generateKey(o,r?.extractable??!1,a)}async function tG(t,r){let o,a,i;switch(t){case"HS256":case"HS384":case"HS512":o=parseInt(t.slice(-3),10),a={name:"HMAC",hash:`SHA-${o}`,length:o},i=["sign","verify"];break;case"A128CBC-HS256":case"A192CBC-HS384":case"A256CBC-HS512":return o=parseInt(t.slice(-3),10),crypto.getRandomValues(new Uint8Array(o>>3));case"A128KW":case"A192KW":case"A256KW":a={name:"AES-KW",length:o=parseInt(t.slice(1,4),10)},i=["wrapKey","unwrapKey"];break;case"A128GCMKW":case"A192GCMKW":case"A256GCMKW":case"A128GCM":case"A192GCM":case"A256GCM":a={name:"AES-GCM",length:o=parseInt(t.slice(1,4),10)},i=["encrypt","decrypt"];break;default:throw new A('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}return crypto.subtle.generateKey(a,r?.extractable??!1,i)}let tX="WebCryptoAPI"},8330(t){"use strict";t.exports=JSON.parse('{"name":"xmcp","description":"The MCP framework","version":"1.7.2","author":{"name":"xmcp","email":"support@xmcp.dev","url":"https://xmcp.dev"},"contributors":[{"name":"Valentina Bearzotti","email":"valebearzotti1@gmail.com","url":"https://github.com/valebearzotti"},{"name":"Jose Rago","email":"jose@basement.studio","url":"https://github.com/ragojose"}],"license":"MIT","keywords":["mcp","modelcontextprotocol","http","stdio"],"repository":{"type":"git","url":"https://github.com/basementstudio/xmcp"},"homepage":"https://xmcp.dev","type":"commonjs","main":"./dist/index.js","types":"./dist/index.d.ts","bin":{"xmcp":"dist/cli.js"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js","default":"./dist/index.js"},"./node":{"types":"./dist/node.d.ts","node":"./dist/node.js"},"./host-bridge":{"types":"./dist/host-bridge.d.ts","import":"./dist/host-bridge.js","require":"./dist/host-bridge.js","default":"./dist/host-bridge.js"},"./headers":{"types":"./dist/runtime/headers.d.ts","require":"./dist/runtime/headers.js","default":"./dist/runtime/headers.js"},"./cloudflare":{"types":"./dist/cloudflare.d.ts","import":"./dist/cloudflare.js","require":"./dist/cloudflare.js","default":"./dist/cloudflare.js"},"./config":{"types":"./dist/config/index.d.ts","import":"./dist/config.js","require":"./dist/config.js","default":"./dist/config.js"},"./package.json":"./package.json","./client":{"types":"./dist/client.d.ts","node":"./dist/client.js"}},"typesVersions":{"*":{"node":["dist/node.d.ts"],"host-bridge":["dist/host-bridge.d.ts"],"headers":["dist/runtime/headers.d.ts"],"cloudflare":["dist/cloudflare.d.ts"],"config":["dist/config/index.d.ts"],"client":["dist/client.d.ts"]}},"files":["dist"],"scripts":{"dev":"cross-env NODE_ENV=development tsx --watch --tsconfig ./bundler.tsconfig.json ./bundler/index.ts","build":"cross-env NODE_ENV=production tsx --tsconfig ./bundler.tsconfig.json ./bundler/index.ts","analyze":"cross-env GENERATE_STATS=true pnpm build && pnpm tsx scripts/analyze-rspack-stats.ts","bench":"tsx bench/run.mts","test:config":"pnpm --dir ../compiler test:config","test:adapters":"node --import tsx --test src/runtime/adapters/*/__tests__/*.test.ts","test:runtime":"node --import tsx --test src/runtime/utils/__tests__/*.test.ts src/runtime/utils/ui/__tests__/*.test.ts","test:client":"node --import tsx --test src/client/__tests__/*.test.ts"},"dependencies":{},"devDependencies":{"@modelcontextprotocol/client":"^2.2.0","@modelcontextprotocol/node":"^2.0.0","@modelcontextprotocol/server":"^2.0.0","@nestjs/common":"^11.1.12","@rspack/core":"^1.6.7","@types/async-retry":"^1.4.9","@types/content-type":"^1.1.9","@types/express":"^5.0.6","@types/fs-extra":"^11.0.4","@types/jsonwebtoken":"^9.0.10","@types/node":"^22.19.2","@types/react":"^19.2.7","@types/react-dom":"^19.2.3","async-retry":"^1.3.3","chalk":"^5.6.2","chokidar":"^3.6.0","ci-info":"^4.3.1","commander":"^11.1.0","content-type":"^1.0.5","cross-env":"^7.0.3","del":"^7.1.0","dotenv":"^16.6.1","express":"^4.22.1","fastify":"^5.12.5","fs-extra":"^11.3.2","glob":"^11.1.0","is-docker":"^4.0.0","is-wsl":"^3.1.0","jose":"^6.1.3","json5":"^2.2.3","jsonwebtoken":"^9.0.3","memfs":"^4.51.1","postcss-loader":"^8.2.0","raw-body":"^3.0.2","reflect-metadata":"^0.2.2","rxjs":"^7.8.2","ts-checker-rspack-plugin":"^1.2.1","tsx":"^4.21.0","typescript":"^5.9.3","zod-to-json-schema":"^3.25.0"},"peerDependencies":{"@modelcontextprotocol/client":"^2.2.0","@modelcontextprotocol/server":"^2.0.0","jose":"^6.1.3","react":">=19.0.0","react-dom":">=19.0.0","zod":"^3.25.76 || ^4.0.0"},"peerDependenciesMeta":{"@modelcontextprotocol/client":{"optional":true},"@modelcontextprotocol/server":{"optional":true},"jose":{"optional":true},"react":{"optional":true},"react-dom":{"optional":true}}}')}},a={};function i(t){var r=a[t];if(void 0!==r)return r.exports;var n=a[t]={exports:{}};return o[t](n,n.exports,i),n.exports}r=Object.getPrototypeOf?t=>Object.getPrototypeOf(t):t=>t.__proto__,i.t=function(o,a){if(1&a&&(o=this(o)),8&a||"object"==typeof o&&o&&(4&a&&o.__esModule||16&a&&"function"==typeof o.then))return o;var n=Object.create(null);i.r(n);var s={};t=t||[null,r({}),r([]),r(r)];for(var l=2&a&&o;("object"==typeof l||"function"==typeof l)&&!~t.indexOf(l);l=r(l))Object.getOwnPropertyNames(l).forEach(t=>{s[t]=()=>o[t]});return s.default=()=>o,i.d(n,s),n},i.d=(t,r)=>{for(var o in r)i.o(r,o)&&!i.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:r[o]})},i.o=(t,r)=>Object.prototype.hasOwnProperty.call(t,r),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};for(var s in(()=>{"use strict";let t,r,o,a,s,l,c,u,d,p,h,f,m,y,g,v,_,b,S,w;i.r(n),i.d(n,{createClient:()=>h$,withClient:()=>hE});var $,E,P,k,R,x,C,A,T=Object.create,O=Object.defineProperty,j=Object.getOwnPropertyDescriptor,I=Object.getOwnPropertyNames,N=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty,z=(t,r)=>()=>(r||t((r={exports:{}}).exports,r),r.exports),q=(t,r,o)=>(o=null!=t?T(N(t)):{},((t,r,o,a)=>{if(r&&"object"==typeof r||"function"==typeof r)for(var i,n=I(r),s=0,l=n.length;s<l;s++)i=n[s],M.call(t,i)||i===o||O(t,i,{get:(t=>r[t]).bind(null,i),enumerable:!(a=j(r,i))||a.enumerable});return t})(!r&&t&&t.__esModule?o:O(o,"default",{value:t,enumerable:!0}),t));let H=new Set(["https://json-schema.org/draft/2020-12/schema","http://json-schema.org/draft/2020-12/schema"]),U=new Set(["https://json-schema.org/draft/2019-09/schema","http://json-schema.org/draft/2019-09/schema"]),D=new Set(["https://json-schema.org/draft-07/schema","http://json-schema.org/draft-07/schema"]),L=new Set(["https://json-schema.org/draft-06/schema","http://json-schema.org/draft-06/schema"]);function K(t){let r=Object.values(t).filter(t=>"number"==typeof t);return Object.entries(t).filter(([t,o])=>-1===r.indexOf(+t)).map(([t,r])=>r)}function J(t,r="|"){return t.map(t=>ep(t)).join(r)}function V(t,r){return"bigint"==typeof r?r.toString():r}class W{constructor(t){this._getter=t,this._value=void 0}get value(){let t=this._getter;return void 0!==t&&(this._value=t(),this._getter=void 0),this._value}}function F(t){return new W(t)}function B(t){let r=+!!t.startsWith("^"),o=t.endsWith("$")?t.length-1:t.length;return t.slice(r,o)}let Z=Symbol("evaluating");function G(t,r,o){Object.defineProperty(t,r,{value:o,writable:!0,enumerable:!0,configurable:!0})}function X(t){let r=Object.getOwnPropertyDescriptor(t,"shape");return r?.get?r.get.raw:r?.value}function Y(t){return X(t._zod.def)??t._zod.def.shape}function Q(t,r,o){Object.defineProperty(t,r,{get(){let t=o();return G(this,r,t),t},enumerable:!0,configurable:!0})}function ee(t,r,o){r in t?G(t,r,o):t[r]=o}function et(t,r,o,a){let i=Y(r);for(let n of o){let o=Object.getOwnPropertyDescriptor(i,n);o.enumerable&&(o.get?Q(t,n,()=>{let t=r._zod.def.shape[n];return a?a(t,n):t}):ee(t,n,a?a(o.value,n):o.value))}}function er(...t){let r={};for(let o of t)Object.assign(r,Object.getOwnPropertyDescriptors(o));return Object.defineProperties({},r)}let eo="captureStackTrace"in Error?Error.captureStackTrace:(...t)=>{};function ea(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}let ei=F(()=>{if(eq.jitless||"undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return Function(""),!0}catch(t){return!1}});function en(t){if(!1===ea(t))return!1;let r=t.constructor;if(void 0===r||"function"!=typeof r)return!0;let o=r.prototype;return!1!==ea(o)&&!1!==Object.prototype.hasOwnProperty.call(o,"isPrototypeOf")}function es(t){return en(t)?{...t}:Array.isArray(t)?[...t]:t instanceof Map?new Map(t):t instanceof Set?new Set(t):t}let el=new Set(["string","number","symbol"]);function ec(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function eu(t,r,o){let a=new t._zod.constr(r??t._zod.def);return(!r||o?.parent)&&(a._zod.parent=t),a}function ed(t){if(!t)return{};if("string"==typeof t)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return(delete t.message,"string"==typeof t.error)?{...t,error:()=>t.error}:t}function ep(t){return"bigint"==typeof t?t.toString()+"n":"string"==typeof t?`"${t}"`:`${t}`}let eh={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-0x80000000,0x7fffffff],uint32:[0,0xffffffff],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]},ef={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function em(t,r){let o=Y(t),a=[];for(let t of Reflect.ownKeys(r)){if(!Object.getOwnPropertyDescriptor(o,t)?.enumerable)throw Error(`Unrecognized key: "${String(t)}"`);r[t]&&a.push(t)}return a}function ey(t,r){let o={};et(o,t,Reflect.ownKeys(Y(t)));var a=o,i=r;for(let t of Reflect.ownKeys(i)){let r=Object.getOwnPropertyDescriptor(i,t);r.enumerable&&(r.get?Q(a,t,()=>i[t]):ee(a,t,r.value))}return o}function eg(t,r,o,a="partial"){let i=r._zod.def.checks;if(i&&i.length>0)throw Error(`.${a}() cannot be used on object schemas containing refinements`);let n=o?new Set(em(r,o)):void 0,s={};return et(s,r,Reflect.ownKeys(Y(r)),t&&((r,o)=>n&&!n.has(o)?r:new t({type:"optional",innerType:r}))),eu(r,er(r._zod.def,{shape:s,checks:[]}))}function ev(t,r=0){if(!0===t.aborted)return!0;for(let o=r;o<t.issues.length;o++)if(t.issues[o]?.continue!==!0)return!0;return!1}function e_(t,r){return r.map(r=>(r.path??(r.path=[]),r.path.unshift(t),r))}function eb(t){return"string"==typeof t?t:t?.message}function eS(t,r,o){var a;for(let i=r;i<t.length;i++)(a=t[i]).schema??(a.schema=o)}function ew(t,r,o){let a=t.inst?._zod?.traits;a?.has("$ZodType")&&(a.has("$ZodCheck")?t.schema??(t.schema=t.inst):t.schema=t.inst);let i=t.schema!==t.inst?t.schema?._zod.def?.error:void 0,n=t.message?t.message:eb(t.inst?._zod.def?.error?.(t))??eb(i?.(t))??eb(r?.error?.(t))??eb(o.customError?.(t))??eb(o.localeError?.(t))??"Invalid input",s={};for(let r of Object.keys(t))"inst"!==r&&"schema"!==r&&"continue"!==r&&"input"!==r&&"__proto__"!==r&&(s[r]=t[r]);return s.path??(s.path=[]),s.message=n,r?.reportInput&&(s.input=t.input),s}let e$=/[\uD800-\uDBFF]/;function eE(t){let r=t.length;if(!e$.test(t))return r;let o=r;for(let a=0;a<r-1;a++)(64512&t.charCodeAt(a))==55296&&(64512&t.charCodeAt(a+1))==56320&&(o--,a++);return o}function eP(t){return Array.isArray(t)?"array":"string"==typeof t?"string":"unknown"}function ek(...t){let[r,o,a]=t;return"string"==typeof r?{message:r,code:"custom",input:o,inst:a}:{...r}}function eR(t,r,o,a=!0){return Object.defineProperty(t,r,{configurable:!0,writable:!0,enumerable:a,value:o}),o}function ex(t,r){for(let o in t){let a=t[o];Object.defineProperty(r,o,{configurable:!0,enumerable:!0,get(){return eR(this,o,a(this))},set(t){eR(this,o,t)}})}return r}let eC=!1,eA={configurable:!0,get(){eC=!0}};function eT(r,o,a){let i=Object.getPrototypeOf(r._zod);if(o in i&&t!==r._zod){t=void 0;return}t=r._zod,Object.defineProperty(i,o,{configurable:!0,get(){Object.defineProperty(this,o,eA);let t=eC;eC=!1;try{let r=a(this);return eC?delete this[o]:Object.defineProperty(this,o,{configurable:!0,writable:!0,value:r}),eC=eC||t,r}catch(r){throw delete this[o],eC=eC||t,r}},set(t){Object.defineProperty(this,o,{configurable:!0,writable:!0,value:t})}})}let eO=Object.freeze({status:"aborted"}),ej={value:void 0,enumerable:!1},eI="captureStackTrace"in Error?Error:null;function eN(t,r,o,a){function i(t){this.def=t,this.constr=u,this.traits=new Set}i.prototype={};let n=o&&new WeakSet;function s(a,s){if(a._zod){if(a._zod.traits.has(t))return}else{ej.value=new i(s);try{Object.defineProperty(a,"_zod",ej)}finally{ej.value=void 0}}if(a._zod.traits.add(t),r(a,s),n){let t=Object.getPrototypeOf(a),r=a._zod.constr.prototype,i=t;for(;i&&i!==r;)i=Object.getPrototypeOf(i);let s=i??t;if(!n.has(s)){n.add(s);var l=s,c=o;for(let t in c){let r=Object.getOwnPropertyDescriptor(c,t);r.get?Object.defineProperty(l,t,{...r,enumerable:!1}):function(t,r,o){Object.defineProperty(t,r,{configurable:!0,get(){return this==null?o:eR(this,r,o.bind(this))},set(t){eR(this,r,t)}})}(l,t,r.value)}}}let d=u.prototype;for(let t in d)Object.prototype.hasOwnProperty.call(d,t)&&(t in a||(a[t]=d[t].bind(a)))}let l=a?.Parent??Object;class c extends l{}function u(t){let r=a?.Parent?function(t){let r=eI;if(r){let o=r.stackTraceLimit;if("number"==typeof o){try{r.stackTraceLimit=0}catch{return eI=null,new t}try{return new t}finally{r.stackTraceLimit=o}}}return new t}(c):this;s(r,t);let o=r._zod.deferred;if(o){for(let t of o)t();r._zod.deferred=void 0}let i=globalThis.__zod_globalConfig?.postProcessor;return i&&i(r),r}return Object.defineProperty(c,"name",{value:t}),Object.defineProperty(u,"init",{value:s}),Object.defineProperty(u,Symbol.hasInstance,{value:r=>!!a?.Parent&&r instanceof a.Parent||r?._zod?.traits?.has(t)}),Object.defineProperty(u,"name",{value:t}),u}class eM extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class ez extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}(x=globalThis).__zod_globalConfig??(x.__zod_globalConfig={});let eq=globalThis.__zod_globalConfig;function eH(t){return t&&Object.assign(eq,t),eq}class eU extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform"),this.name="ZodCyclicError"}}let eD="~memo",eL=[];function eK(t){return null!==t&&"object"==typeof t}function eJ(t){return t.map(t=>t.path?{...t,path:t.path.slice()}:{...t})}let eV=new WeakMap,eW=[],eF={alloc(t,o,a){let i=r;if(!i)return a;r=void 0;let n={value:a,issues:null};return i.set(o.value,n),eW.push(n),a},guard(t){var r;(r=t._zod).deferred??(r.deferred=[]),t._zod.deferred.push(()=>{let r=t._zod.parse,o=(t,o)=>{var a,i;let n;if("backward"!==o.direction&&(a=o,i=t.value,void 0!==(n=a[eD]?.backEdges)&&eK(i)&&n.has(i)))throw new eU;return r(t,o)};t._zod.parse=o,t._zod.run===r&&(t._zod.run=o)})},attach(t){var o;let a,i,n,s=!1;(o=t._zod).deferred??(o.deferred=[]),t._zod.deferred.push(()=>{let o=t._zod.parse,l=(c,u)=>{let d;if(void 0===a){let r=function t(r,o,a){var i,n;let s=eV.get(r);if(void 0!==s)return 2*!!s;if(o.has(r))return 2;o.add(r);let l=0,c=r=>{if(2!==l&&r?._zod){let i=t(r,o,a);i>l&&(l=i)}},u=t=>{t>l&&(l=t)},d=r._zod.def;switch(d.type){case"object":{let r=X(d);u(r?((r,i)=>{let n=0;for(let s of Reflect.ownKeys(r)){let l=Object.getOwnPropertyDescriptor(r,s);if(i&&!l.enumerable)continue;let c=l.get?1:l.value?._zod?t(l.value,o,a):0;c>n&&(n=c)}return n})(r,!0):1),c(d.catchall);break}case"array":c(d.element);break;case"tuple":for(let t of d.items)c(t);c(d.rest);break;case"record":case"map":c(d.keyType),c(d.valueType);break;case"set":c(d.valueType);break;case"union":for(let t of d.options)c(t);break;case"intersection":c(d.left),c(d.right);break;case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":c(d.innerType);break;case"pipe":c(d.in),c(d.out);break;case"function":c(d.input),c(d.output);break;case"lazy":{let i=d._cachedInner??(a?r._zod.innerType:void 0);u(i?t(i,o,!1):1);break}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":break;default:for(let t in d){let r=Object.getOwnPropertyDescriptor(d,t);if(!r||r.get)continue;let o=r.value;if(o&&"object"==typeof o){if(o._zod)c(o);else if(Array.isArray(o))for(let t of o)c(t)}}}return o.delete(r),i=r,1!==(n=l)&&eV.set(i,2===n),n}(t,new Set,!1);if(0===r)return t._zod.parse=o,t._zod.run===l&&(t._zod.run=o),o(c,u);2===r||s?a=!0:s=!0}let p=c.value;if(!eK(p))return o(c,u);let h=u[eD];if(h||(h={buckets:new WeakMap,backEdges:void 0},u[eD]=h),i===u)d=n;else{var f,m;let r;f=h,m=t,(r=f.buckets.get(m))||(r=new WeakMap,f.buckets.set(m,r)),d=r,i=u,n=d}let y=d.get(p);if(y)return c.value=y.value,y.issues?y.issues.length&&c.issues.push(...eJ(y.issues)):(c.memo=!0,h.backEdges??(h.backEdges=new WeakSet),h.backEdges.add(y.value)),c;r=d;let g=eW.length,v=o(c,u);r=void 0;let _=eW.length>g?eW.pop():void 0;return v instanceof Promise?v.then(t=>(_&&(_.issues=t.issues.length?eJ(t.issues):eL),t)):(_&&(_.issues=v.issues.length?eJ(v.issues):eL),v)};t._zod.parse=l,t._zod.run===o&&(t._zod.run=l)})}},eB=/^[cC][0-9a-z]{6,}$/,eZ=/^[0-9a-z]+$/,eG=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,eX=/^[0-9a-vA-V]{20}$/,eY=/^[A-Za-z0-9]{27}$/,eQ=/^[a-zA-Z0-9_-]{21}$/,e0=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,e1=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,e2=t=>t?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,e9=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,e4=`^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`,e5=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,e3=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,e6=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,e8=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,e7=/^https?$/,te=/^\+[1-9]\d{6,14}$/,tt="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",tr=($=tt,RegExp(`^${$}$`));function to(t){let r="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof t.precision?-1===t.precision?`${r}`:0===t.precision?`${r}:[0-5]\\d`:`${r}:[0-5]\\d\\.\\d{${t.precision}}`:t.seconds?`${r}:[0-5]\\d(?:\\.\\d+)?`:`${r}(?::[0-5]\\d(?:\\.\\d+)?)?`}let ta=/^[\s\S]{0,}$/,ti=/^-?\d+$/,tn=/^-?\d+(?:\.\d+)?$/,ts=/^(?:true|false)$/i,tl=/^null$/i,tc=/^[^A-Z]*$/,tu=/^[^a-z]*$/,td=eN("$ZodCheck",(t,r)=>{var o;t._zod??(t._zod={}),t._zod.def=r,(o=t._zod).onattach??(o.onattach=[])}),tp=t=>{let r=t.value;return null!=r&&void 0!==r.length},th={number:"number",bigint:"bigint",object:"date"},tf=eN("$ZodCheckLessThan",(t,r)=>{td.init(t,r);let o=th[typeof r.value];t._zod.check=a=>{(r.inclusive?a.value<=r.value:a.value<r.value)||a.issues.push({origin:th[typeof a.value]??o,code:"too_big",maximum:"object"==typeof r.value?r.value.getTime():r.value,input:a.value,inclusive:r.inclusive,inst:t,continue:!r.abort})}}),tm=eN("$ZodCheckGreaterThan",(t,r)=>{td.init(t,r);let o=th[typeof r.value];t._zod.check=a=>{(r.inclusive?a.value>=r.value:a.value>r.value)||a.issues.push({origin:th[typeof a.value]??o,code:"too_small",minimum:"object"==typeof r.value?r.value.getTime():r.value,input:a.value,inclusive:r.inclusive,inst:t,continue:!r.abort})}}),ty=eN("$ZodCheckMultipleOf",(t,r)=>{td.init(t,r),t._zod.check=o=>{var a;let i,n,s;if(typeof o.value!=typeof r.value)throw Error("Cannot mix number and bigint in multiple_of check.");("bigint"==typeof o.value?r.value!==BigInt(0)&&o.value%r.value===BigInt(0):0==(n=Math.round(i=(a=o.value)/r.value),s=4*Number.EPSILON*Math.max(Math.abs(i),1),Math.abs(i-n)<s?0:i-n))||o.issues.push({origin:typeof o.value,code:"not_multiple_of",divisor:r.value,input:o.value,inst:t,continue:!r.abort})}}),tg=eN("$ZodCheckNumberFormat",(t,r)=>{td.init(t,r),r.format=r.format||"float64";let o=r.format?.includes("int"),a=o?"int":"number",[i,n]=eh[r.format];t._zod.check=s=>{let l=s.value;if(o){if(!Number.isInteger(l))return void s.issues.push({expected:a,format:r.format,code:"invalid_type",continue:!1,input:l,inst:t});if(!Number.isSafeInteger(l))return void(l>0?s.issues.push({input:l,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:a,inclusive:!0,continue:!r.abort}):s.issues.push({input:l,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:a,inclusive:!0,continue:!r.abort}))}l<i&&s.issues.push({origin:"number",input:l,code:"too_small",minimum:i,inclusive:!0,inst:t,continue:!r.abort}),l>n&&s.issues.push({origin:"number",input:l,code:"too_big",maximum:n,inclusive:!0,inst:t,continue:!r.abort})}}),tv=eN("$ZodCheckMaxLength",(t,r)=>{var o;td.init(t,r),(o=t._zod.def).when??(o.when=tp),t._zod.check=o=>{let a=o.value,i=a.length;if(("string"==typeof a&&i>r.maximum?eE(a):i)<=r.maximum)return;let n=eP(a);o.issues.push({origin:n,code:"too_big",maximum:r.maximum,inclusive:!0,input:a,inst:t,continue:!r.abort})}}),t_=eN("$ZodCheckMinLength",(t,r)=>{var o;td.init(t,r),(o=t._zod.def).when??(o.when=tp),t._zod.check=o=>{let a=o.value,i=a.length;if(("string"==typeof a&&i>=r.minimum&&i<2*r.minimum?eE(a):i)>=r.minimum)return;let n=eP(a);o.issues.push({origin:n,code:"too_small",minimum:r.minimum,inclusive:!0,input:a,inst:t,continue:!r.abort})}}),tb=eN("$ZodCheckLengthEquals",(t,r)=>{var o;td.init(t,r),(o=t._zod.def).when??(o.when=tp),t._zod.check=o=>{let a=o.value,i=a.length,n="string"==typeof a&&i>=r.length&&i<=2*r.length?eE(a):i;if(n===r.length)return;let s=eP(a),l=n>r.length;o.issues.push({origin:s,...l?{code:"too_big",maximum:r.length}:{code:"too_small",minimum:r.length},inclusive:!0,exact:!0,input:o.value,inst:t,continue:!r.abort})}}),tS=eN("$ZodCheckStringFormat",(t,r)=>{var o,a;td.init(t,r),r.pattern?(o=t._zod).check??(o.check=o=>{r.pattern.lastIndex=0,r.pattern.test(o.value)||o.issues.push({origin:"string",code:"invalid_format",format:r.format,input:o.value,...r.pattern?{pattern:r.pattern.toString()}:{},inst:t,continue:!r.abort})}):(a=t._zod).check??(a.check=()=>{})}),tw=eN("$ZodCheckRegex",(t,r)=>{tS.init(t,r),t._zod.check=o=>{r.pattern.lastIndex=0,r.pattern.test(o.value)||o.issues.push({origin:"string",code:"invalid_format",format:"regex",input:o.value,pattern:r.pattern.toString(),inst:t,continue:!r.abort})}}),t$=eN("$ZodCheckLowerCase",(t,r)=>{r.pattern??(r.pattern=tc),tS.init(t,r)}),tE=eN("$ZodCheckUpperCase",(t,r)=>{r.pattern??(r.pattern=tu),tS.init(t,r)}),tP=eN("$ZodCheckIncludes",(t,r)=>{td.init(t,r);let o=ec(r.includes),a=new RegExp("number"==typeof r.position?`^.{${r.position},}${o}`:o);r.pattern=a,t._zod.check=o=>{o.value.includes(r.includes,r.position)||o.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:r.includes,input:o.value,inst:t,continue:!r.abort})}}),tk=eN("$ZodCheckStartsWith",(t,r)=>{td.init(t,r);let o=RegExp(`^${ec(r.prefix)}.*`);r.pattern??(r.pattern=o),t._zod.check=o=>{o.value.startsWith(r.prefix)||o.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:r.prefix,input:o.value,inst:t,continue:!r.abort})}}),tR=eN("$ZodCheckEndsWith",(t,r)=>{td.init(t,r);let o=RegExp(`.*${ec(r.suffix)}$`);r.pattern??(r.pattern=o),t._zod.check=o=>{o.value.endsWith(r.suffix)||o.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:r.suffix,input:o.value,inst:t,continue:!r.abort})}}),tx=eN("$ZodCheckOverwrite",(t,r)=>{td.init(t,r),t._zod.check=t=>{t.value=r.tx(t.value)}});class tC{constructor(t=[],r={}){this.content=[],this.indent=0,this.args=t,this.closed=r}indented(t){this.indent+=1;try{t(this)}finally{this.indent-=1}}write(t){if("function"==typeof t){t(this,{execution:"sync"}),t(this,{execution:"async"});return}let r=t.split("\n").filter(t=>t),o=Math.min(...r.map(t=>t.length-t.trimStart().length));for(let t of r.map(t=>t.slice(o)).map(t=>" ".repeat(2*this.indent)+t))this.content.push(t)}compile(){let t=Function,r=this?.content??[""];return new t(...Object.keys(this.closed),`return function (${this.args.join(", ")}) {
3
+ -----END ${r}-----`},eq=async(t,r,o)=>{if(K(o)){if(o.type!==t)throw TypeError(`key is not a ${t} key`);return o.export({format:"pem",type:r})}if(!L(o))throw TypeError(E(o,"CryptoKey","KeyObject"));if(!o.extractable)throw TypeError("CryptoKey is not extractable");if(o.type!==t)throw TypeError(`key is not a ${t} key`);return ez(m(new Uint8Array(await crypto.subtle.exportKey(r,o))),`${t.toUpperCase()} KEY`)},eH=(t,r)=>{if(t.byteLength!==r.length)return!1;for(let o=0;o<t.byteLength;o++)if(t[o]!==r[o])return!1;return!0},eU=t=>({data:t,pos:0}),eD=t=>{let r=t.data[t.pos++];if(128&r){let o=127&r,a=0;for(let r=0;r<o;r++)a=a<<8|t.data[t.pos++];return a}return r},eL=(t,r=1)=>{if(r<=0)return;t.pos++;let o=eD(t);t.pos+=o,r>1&&eL(t,r-1)},eK=(t,r,o)=>{if(t.data[t.pos++]!==r)throw Error(o)},eJ=(t,r)=>{let o=t.data.subarray(t.pos,t.pos+r);return t.pos+=r,o},eV=t=>{let r,o=(eK(t,6,"Expected algorithm OID"),r=eD(t),eJ(t,r));if(eH(o,[43,101,110]))return"X25519";if(!eH(o,[42,134,72,206,61,2,1]))throw Error("Unsupported key algorithm");eK(t,6,"Expected curve OID");let a=eD(t),i=eJ(t,a);for(let{name:t,oid:r}of[{name:"P-256",oid:[42,134,72,206,61,3,1,7]},{name:"P-384",oid:[43,129,4,0,34]},{name:"P-521",oid:[43,129,4,0,35]}])if(eH(i,r))return t;throw Error("Unsupported named curve")},eW=async(t,r,o,a)=>{let i,n,s="spki"===t,l=()=>s?["verify"]:["sign"];switch(o){case"PS256":case"PS384":case"PS512":i={name:"RSA-PSS",hash:`SHA-${o.slice(-3)}`},n=l();break;case"RS256":case"RS384":case"RS512":i={name:"RSASSA-PKCS1-v1_5",hash:`SHA-${o.slice(-3)}`},n=l();break;case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":i={name:"RSA-OAEP",hash:`SHA-${parseInt(o.slice(-3),10)||1}`},n=s?["encrypt","wrapKey"]:["decrypt","unwrapKey"];break;case"ES256":case"ES384":case"ES512":i={name:"ECDSA",namedCurve:({ES256:"P-256",ES384:"P-384",ES512:"P-521"})[o]},n=l();break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":try{let t=a.getNamedCurve(r);i="X25519"===t?{name:"X25519"}:{name:"ECDH",namedCurve:t}}catch(t){throw new A("Invalid or unsupported key format")}n=s?[]:["deriveBits"];break;case"Ed25519":case"EdDSA":i={name:"Ed25519"},n=l();break;case"ML-DSA-44":case"ML-DSA-65":case"ML-DSA-87":i={name:o},n=l();break;default:throw new A('Invalid or unsupported "alg" (Algorithm) value')}return crypto.subtle.importKey(t,r,i,a?.extractable??!!s,n)},eF=(t,r)=>y(t.replace(r,"")),eB=(t,r,o)=>{let a=eF(t,/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g),i=o;return r?.startsWith?.("ECDH-ES")&&((i||={}).getNamedCurve=t=>{let r=eU(t);return eK(r,48,"Invalid SPKI structure"),eD(r),eK(r,48,"Expected algorithm identifier"),eD(r),r.pos,eV(r)}),eW("spki",a,r,i)};async function eZ(t,r,o){if("string"!=typeof t||0!==t.indexOf("-----BEGIN PUBLIC KEY-----"))throw TypeError('"spki" must be SPKI formatted string');return eB(t,r,o)}async function eG(t,r,o){if("string"!=typeof t||0!==t.indexOf("-----BEGIN CERTIFICATE-----"))throw TypeError('"x509" must be X.509 formatted string');return((t,r,o)=>{let a;try{var i;let r,o,n;r=eU(i=eF(t,/(?:-----(?:BEGIN|END) CERTIFICATE-----|\s)/g)),eK(r,48,"Invalid certificate structure"),eD(r),eK(r,48,"Invalid tbsCertificate structure"),eD(r),160===i[r.pos]?eL(r,6):eL(r,5),o=r.pos,eK(r,48,"Invalid SPKI structure"),n=eD(r),a=i.subarray(o,o+n+(r.pos-o))}catch(t){throw TypeError("Failed to parse the X.509 certificate",{cause:t})}return eB(ez(m(a),"PUBLIC KEY"),r,o)})(t,r,o)}async function eX(t,r,o){let a,i;if("string"!=typeof t||0!==t.indexOf("-----BEGIN PRIVATE KEY-----"))throw TypeError('"pkcs8" must be PKCS#8 formatted string');return a=eF(t,/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g),i=o,r?.startsWith?.("ECDH-ES")&&((i||={}).getNamedCurve=t=>{let r,o=eU(t);return eK(o,48,"Invalid PKCS#8 structure"),eD(o),eK(o,2,"Expected version field"),r=eD(o),o.pos+=r,eK(o,48,"Expected algorithm identifier"),eD(o),o.pos,eV(o)}),eW("pkcs8",a,r,i)}async function eY(t,r,o){let a;if(!eu(t))throw TypeError("JWK must be an object");switch(r??=t.alg,a??=o?.extractable??t.ext,t.kty){case"oct":if("string"!=typeof t.k||!t.k)throw TypeError('missing "k" (Key Value) Parameter value');return g(t.k);case"RSA":if("oth"in t&&void 0!==t.oth)throw new A('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');return ej({...t,alg:r,ext:a});case"AKP":if("string"!=typeof t.alg||!t.alg)throw TypeError('missing "alg" (Algorithm) Parameter value');if(void 0!==r&&r!==t.alg)throw TypeError("JWK alg and alg option value mismatch");return ej({...t,ext:a});case"EC":case"OKP":return ej({...t,alg:r,ext:a});default:throw new A('Unsupported "kty" (Key Type) Parameter value')}}async function eQ(t){if(K(t))if("secret"!==t.type)return t.export({format:"jwk"});else t=t.export();if(t instanceof Uint8Array)return{kty:"oct",k:v(t)};if(!L(t))throw TypeError(E(t,"CryptoKey","KeyObject","Uint8Array"));if(!t.extractable)throw TypeError("non-extractable CryptoKey cannot be exported as a JWK");let{ext:r,key_ops:o,alg:a,use:i,...n}=await crypto.subtle.exportKey("jwk",t);return"AKP"===n.kty&&(n.alg=a),n}async function e0(t){return eq("public","spki",t)}async function e1(t){return eq("private","pkcs8",t)}async function e2(t){return eQ(t)}async function e9(t,r,o,a){let i=t.slice(0,7),n=await ea(i,o,r,a,new Uint8Array);return{encryptedKey:n.ciphertext,iv:v(n.iv),tag:v(n.tag)}}async function e4(t,r,o,a,i){return ei(t.slice(0,7),r,o,a,i,new Uint8Array)}let e5='Invalid or unsupported "alg" (JWE Algorithm) header value';function e3(t){if(void 0===t)throw new O("JWE Encrypted Key missing")}async function e6(t,r,o,a,i){switch(t){case"dir":if(void 0!==o)throw new O("Encountered unexpected JWE Encrypted Key");return r;case"ECDH-ES":if(void 0!==o)throw new O("Encountered unexpected JWE Encrypted Key");case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":{let i,n;if(!eu(a.epk))throw new O('JOSE Header "epk" (Ephemeral Public Key) missing or invalid');if(D(r),!eb(r))throw new A("ECDH with the provided key is not allowed or not supported by your javascript runtime");let s=await eY(a.epk,t);if(D(s),void 0!==a.apu){if("string"!=typeof a.apu)throw new O('JOSE Header "apu" (Agreement PartyUInfo) invalid');i=el(a.apu,"apu",O)}if(void 0!==a.apv){if("string"!=typeof a.apv)throw new O('JOSE Header "apv" (Agreement PartyVInfo) invalid');n=el(a.apv,"apv",O)}let l=await e_(s,r,"ECDH-ES"===t?a.enc:t,"ECDH-ES"===t?V(a.enc):parseInt(t.slice(-5,-2),10),i,n);if("ECDH-ES"===t)return l;return e3(o),ey(t.slice(-6),l,o)}case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":return e3(o),D(r),eT(t,r,o);case"PBES2-HS256+A128KW":case"PBES2-HS384+A192KW":case"PBES2-HS512+A256KW":{let n;if(e3(o),"number"!=typeof a.p2c)throw new O('JOSE Header "p2c" (PBES2 Count) missing or invalid');let s=i?.maxPBES2Count||1e4;if(a.p2c>s)throw new O('JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds');if("string"!=typeof a.p2s)throw new O('JOSE Header "p2s" (PBES2 Salt) missing or invalid');return n=el(a.p2s,"p2s",O),e$(t,r,o,a.p2c,n)}case"A128KW":case"A192KW":case"A256KW":return e3(o),ey(t,r,o);case"A128GCMKW":case"A192GCMKW":case"A256GCMKW":if(e3(o),"string"!=typeof a.iv)throw new O('JOSE Header "iv" (Initialization Vector) missing or invalid');if("string"!=typeof a.tag)throw new O('JOSE Header "tag" (Authentication Tag) missing or invalid');return e4(t,r,o,el(a.iv,"iv",O),el(a.tag,"tag",O));default:throw new A(e5)}}async function e8(t,r,o,a,i={}){let n,s,l;switch(t){case"dir":l=o;break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":{let c;if(D(o),!eb(o))throw new A("ECDH with the provided key is not allowed or not supported by your javascript runtime");let{apu:u,apv:d}=i;c=i.epk?await eM(i.epk,t):(await crypto.subtle.generateKey(o.algorithm,!0,["deriveBits"])).privateKey;let{x:p,y:h,crv:f,kty:m}=await e2(c),y=await e_(o,c,"ECDH-ES"===t?r:t,"ECDH-ES"===t?V(r):parseInt(t.slice(-5,-2),10),u,d);if(s={epk:{x:p,crv:f,kty:m}},"EC"===m&&(s.epk.y=h),u&&(s.apu=v(u)),d&&(s.apv=v(d)),"ECDH-ES"===t){l=y;break}l=a||W(r);let g=t.slice(-6);n=await em(g,y,l);break}case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":l=a||W(r),D(o),n=await eA(t,o,l);break;case"PBES2-HS256+A128KW":case"PBES2-HS384+A192KW":case"PBES2-HS512+A256KW":{l=a||W(r);let{p2c:c,p2s:u}=i;({encryptedKey:n,...s}=await ew(t,o,l,c,u));break}case"A128KW":case"A192KW":case"A256KW":l=a||W(r),n=await em(t,o,l);break;case"A128GCMKW":case"A192GCMKW":case"A256GCMKW":{l=a||W(r);let{iv:c}=i;({encryptedKey:n,...s}=await e9(t,o,l,c));break}default:throw new A(e5)}return{cek:l,encryptedKey:n,parameters:s}}function e7(t,r,o,a,i){let n;if(void 0!==i.crit&&a?.crit===void 0)throw new t('"crit" (Critical) Header Parameter MUST be integrity protected');if(!a||void 0===a.crit)return new Set;if(!Array.isArray(a.crit)||0===a.crit.length||a.crit.some(t=>"string"!=typeof t||0===t.length))throw new t('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');for(let s of(n=void 0!==o?new Map([...Object.entries(o),...r.entries()]):r,a.crit)){if(!n.has(s))throw new A(`Extension Header Parameter "${s}" is not recognized`);if(void 0===i[s])throw new t(`Extension Header Parameter "${s}" is missing`);if(n.get(s)&&void 0===a[s])throw new t(`Extension Header Parameter "${s}" MUST be integrity protected`)}return new Set(a.crit)}function te(t,r){if(void 0!==r&&(!Array.isArray(r)||r.some(t=>"string"!=typeof t)))throw TypeError(`"${t}" option must be an array of strings`);if(r)return new Set(r)}let tt=t=>t?.[Symbol.toStringTag],tr=(t,r,o)=>{if(void 0!==r.use){let t;switch(o){case"sign":case"verify":t="sig";break;case"encrypt":case"decrypt":t="enc"}if(r.use!==t)throw TypeError(`Invalid key for this operation, its "use" must be "${t}" when present`)}if(void 0!==r.alg&&r.alg!==t)throw TypeError(`Invalid key for this operation, its "alg" must be "${t}" when present`);if(Array.isArray(r.key_ops)){let a;switch(!0){case"sign"===o||"verify"===o:case"dir"===t:case t.includes("CBC-HS"):a=o;break;case t.startsWith("PBES2"):a="deriveBits";break;case/^A\d{3}(?:GCM)?(?:KW)?$/.test(t):a=!t.includes("GCM")&&t.endsWith("KW")?"encrypt"===o?"wrapKey":"unwrapKey":o;break;case"encrypt"===o&&t.startsWith("RSA"):a="wrapKey";break;case"decrypt"===o:a=t.startsWith("RSA")?"unwrapKey":"deriveBits"}if(a&&r.key_ops?.includes?.(a)===!1)throw TypeError(`Invalid key for this operation, its "key_ops" must include "${a}" when present`)}return!0};function to(t,r,o){switch(t.substring(0,2)){case"A1":case"A2":case"di":case"HS":case"PB":((t,r,o)=>{if(!(r instanceof Uint8Array)){if(ep(r)){if("oct"===r.kty&&"string"==typeof r.k&&tr(t,r,o))return;throw TypeError('JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present')}if(!J(r))throw TypeError(P(t,r,"CryptoKey","KeyObject","JSON Web Key","Uint8Array"));if("secret"!==r.type)throw TypeError(`${tt(r)} instances for symmetric algorithms must be of type "secret"`)}})(t,r,o);break;default:((t,r,o)=>{if(ep(r))switch(o){case"decrypt":case"sign":if("oct"!==r.kty&&("AKP"===r.kty&&"string"==typeof r.priv||"string"==typeof r.d)&&tr(t,r,o))return;throw TypeError("JSON Web Key for this operation must be a private JWK");case"encrypt":case"verify":if("oct"!==r.kty&&void 0===r.d&&void 0===r.priv&&tr(t,r,o))return;throw TypeError("JSON Web Key for this operation must be a public JWK")}if(!J(r))throw TypeError(P(t,r,"CryptoKey","KeyObject","JSON Web Key"));if("secret"===r.type)throw TypeError(`${tt(r)} instances for asymmetric algorithms must not be of type "secret"`);if("public"===r.type)switch(o){case"sign":throw TypeError(`${tt(r)} instances for asymmetric algorithm signing must be of type "private"`);case"decrypt":throw TypeError(`${tt(r)} instances for asymmetric algorithm decryption must be of type "private"`)}if("private"===r.type)switch(o){case"verify":throw TypeError(`${tt(r)} instances for asymmetric algorithm verifying must be of type "public"`);case"encrypt":throw TypeError(`${tt(r)} instances for asymmetric algorithm encryption must be of type "public"`)}})(t,r,o)}}function ta(t){if(void 0===globalThis[t])throw new A(`JWE "zip" (Compression Algorithm) Header Parameter requires the ${t} API.`)}async function ti(t){ta("CompressionStream");let r=new CompressionStream("deflate-raw"),o=r.writable.getWriter();o.write(t).catch(()=>{}),o.close().catch(()=>{});let a=[],i=r.readable.getReader();for(;;){let{value:t,done:r}=await i.read();if(r)break;a.push(t)}return u(...a)}async function tn(t,r){ta("DecompressionStream");let o=new DecompressionStream("deflate-raw"),a=o.writable.getWriter();a.write(t).catch(()=>{}),a.close().catch(()=>{});let i=[],n=0,s=o.readable.getReader();for(;;){let{value:t,done:o}=await s.read();if(o)break;if(i.push(t),n+=t.byteLength,r!==1/0&&n>r)throw new O("Decompressed plaintext exceeded the configured limit")}return u(...i)}async function ts(t,r,o){let a,i,n,s,l,d;if(!eu(t))throw new O("Flattened JWE must be an object");if(void 0===t.protected&&void 0===t.header&&void 0===t.unprotected)throw new O("JOSE Header missing");if(void 0!==t.iv&&"string"!=typeof t.iv)throw new O("JWE Initialization Vector incorrect type");if("string"!=typeof t.ciphertext)throw new O("JWE Ciphertext missing or incorrect type");if(void 0!==t.tag&&"string"!=typeof t.tag)throw new O("JWE Authentication Tag incorrect type");if(void 0!==t.protected&&"string"!=typeof t.protected)throw new O("JWE Protected Header incorrect type");if(void 0!==t.encrypted_key&&"string"!=typeof t.encrypted_key)throw new O("JWE Encrypted Key incorrect type");if(void 0!==t.aad&&"string"!=typeof t.aad)throw new O("JWE AAD incorrect type");if(void 0!==t.header&&!eu(t.header))throw new O("JWE Shared Unprotected Header incorrect type");if(void 0!==t.unprotected&&!eu(t.unprotected))throw new O("JWE Per-Recipient Unprotected Header incorrect type");if(t.protected)try{let r=g(t.protected);a=JSON.parse(c.decode(r))}catch{throw new O("JWE Protected Header is invalid")}if(!ed(a,t.header,t.unprotected))throw new O("JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint");let p={...a,...t.header,...t.unprotected};if(e7(O,new Map,o?.crit,a,p),void 0!==p.zip&&"DEF"!==p.zip)throw new A('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');if(void 0!==p.zip&&!a?.zip)throw new O('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.');let{alg:h,enc:m}=p;if("string"!=typeof h||!h)throw new O("missing JWE Algorithm (alg) in JWE Header");if("string"!=typeof m||!m)throw new O("missing JWE Encryption Algorithm (enc) in JWE Header");let y=o&&te("keyManagementAlgorithms",o.keyManagementAlgorithms),v=o&&te("contentEncryptionAlgorithms",o.contentEncryptionAlgorithms);if(y&&!y.has(h)||!y&&h.startsWith("PBES2"))throw new C('"alg" (Algorithm) Header Parameter value not allowed');if(v&&!v.has(m))throw new C('"enc" (Encryption Algorithm) Header Parameter value not allowed');void 0!==t.encrypted_key&&(i=el(t.encrypted_key,"encrypted_key",O));let _=!1;"function"==typeof r&&(r=await r(a,t),_=!0),to("dir"===h?m:h,r,"decrypt");let b=await eM(r,h);try{n=await e6(h,b,i,p,o)}catch(t){if(t instanceof TypeError||t instanceof O||t instanceof A)throw t;n=W(m)}void 0!==t.iv&&(s=el(t.iv,"iv",O)),void 0!==t.tag&&(l=el(t.tag,"tag",O));let S=void 0!==t.protected?f(t.protected):new Uint8Array;d=void 0!==t.aad?u(S,f("."),f(t.aad)):S;let w=el(t.ciphertext,"ciphertext",O),$=await ei(m,n,w,s,l,d),E={plaintext:$};if("DEF"===p.zip){let t=o?.maxDecompressedLength??25e4;if(0===t)throw new A('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');if(t!==1/0&&(!Number.isSafeInteger(t)||t<1))throw TypeError("maxDecompressedLength must be 0, a positive safe integer, or Infinity");E.plaintext=await tn($,t).catch(t=>{if(t instanceof O)throw t;throw new O("Failed to decompress plaintext",{cause:t})})}return(void 0!==t.protected&&(E.protectedHeader=a),void 0!==t.aad&&(E.additionalAuthenticatedData=el(t.aad,"aad",O)),void 0!==t.unprotected&&(E.sharedUnprotectedHeader=t.unprotected),void 0!==t.header&&(E.unprotectedHeader=t.header),_)?{...E,key:b}:E}async function tl(t,r,o){if(t instanceof Uint8Array&&(t=c.decode(t)),"string"!=typeof t)throw new O("Compact JWE must be a string or Uint8Array");let{0:a,1:i,2:n,3:s,4:l,length:u}=t.split(".");if(5!==u)throw new O("Invalid Compact JWE");let d=await ts({ciphertext:s,iv:n||void 0,protected:a,tag:l||void 0,encrypted_key:i||void 0},r,o),p={plaintext:d.plaintext,protectedHeader:d.protectedHeader};return"function"==typeof r?{...p,key:d.key}:p}async function tc(t,r,o){if(!eu(t))throw new O("General JWE must be an object");if(!Array.isArray(t.recipients)||!t.recipients.every(eu))throw new O("JWE Recipients missing or incorrect type");if(!t.recipients.length)throw new O("JWE Recipients has no members");for(let a of t.recipients)try{return await ts({aad:t.aad,ciphertext:t.ciphertext,encrypted_key:a.encrypted_key,header:a.header,iv:t.iv,protected:t.protected,tag:t.tag,unprotected:t.unprotected},r,o)}catch{}throw new T}class tu{#e;#t;#r;#o;#a;#i;#n;#s;constructor(t){if(!(t instanceof Uint8Array))throw TypeError("plaintext must be an instance of Uint8Array");this.#e=t}setKeyManagementParameters(t){return es(this.#s,"setKeyManagementParameters"),this.#s=t,this}setProtectedHeader(t){return es(this.#t,"setProtectedHeader"),this.#t=t,this}setSharedUnprotectedHeader(t){return es(this.#r,"setSharedUnprotectedHeader"),this.#r=t,this}setUnprotectedHeader(t){return es(this.#o,"setUnprotectedHeader"),this.#o=t,this}setAdditionalAuthenticatedData(t){return this.#a=t,this}setContentEncryptionKey(t){return es(this.#i,"setContentEncryptionKey"),this.#i=t,this}setInitializationVector(t){return es(this.#n,"setInitializationVector"),this.#n=t,this}async encrypt(t,r){let o,a,i,n,s,l;if(!this.#t&&!this.#o&&!this.#r)throw new O("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");if(!ed(this.#t,this.#o,this.#r))throw new O("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");let c={...this.#t,...this.#o,...this.#r};if(e7(O,new Map,r?.crit,this.#t,c),void 0!==c.zip&&"DEF"!==c.zip)throw new A('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');if(void 0!==c.zip&&!this.#t?.zip)throw new O('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.');let{alg:d,enc:p}=c;if("string"!=typeof d||!d)throw new O('JWE "alg" (Algorithm) Header Parameter missing or invalid');if("string"!=typeof p||!p)throw new O('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');if(this.#i&&("dir"===d||"ECDH-ES"===d))throw TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${d}`);to("dir"===d?p:d,t,"encrypt");{let i,n=await eM(t,d);({cek:a,encryptedKey:o,parameters:i}=await e8(d,p,n,this.#i,this.#s)),i&&(r&&en in r?this.#o?this.#o={...this.#o,...i}:this.setUnprotectedHeader(i):this.#t?this.#t={...this.#t,...i}:this.setProtectedHeader(i))}if(this.#t?s=f(n=v(JSON.stringify(this.#t))):(n="",s=new Uint8Array),this.#a){let t=f(l=v(this.#a));i=u(s,f("."),t)}else i=s;let h=this.#e;"DEF"===c.zip&&(h=await ti(h).catch(t=>{throw new O("Failed to compress plaintext",{cause:t})}));let{ciphertext:m,tag:y,iv:g}=await ea(p,h,a,this.#n,i),_={ciphertext:v(m)};return g&&(_.iv=v(g)),y&&(_.tag=v(y)),o&&(_.encrypted_key=v(o)),l&&(_.aad=l),this.#t&&(_.protected=n),this.#r&&(_.unprotected=this.#r),this.#o&&(_.header=this.#o),_}}class td{#l;unprotectedHeader;keyManagementParameters;key;options;constructor(t,r,o){this.#l=t,this.key=r,this.options=o}setUnprotectedHeader(t){return es(this.unprotectedHeader,"setUnprotectedHeader"),this.unprotectedHeader=t,this}setKeyManagementParameters(t){return es(this.keyManagementParameters,"setKeyManagementParameters"),this.keyManagementParameters=t,this}addRecipient(...t){return this.#l.addRecipient(...t)}encrypt(...t){return this.#l.encrypt(...t)}done(){return this.#l}}class tp{#e;#c=[];#t;#o;#a;constructor(t){this.#e=t}addRecipient(t,r){let o=new td(this,t,{crit:r?.crit});return this.#c.push(o),o}setProtectedHeader(t){return es(this.#t,"setProtectedHeader"),this.#t=t,this}setSharedUnprotectedHeader(t){return es(this.#o,"setSharedUnprotectedHeader"),this.#o=t,this}setAdditionalAuthenticatedData(t){return this.#a=t,this}async encrypt(){let t;if(!this.#c.length)throw new O("at least one recipient must be added");if(1===this.#c.length){let[t]=this.#c,r=await new tu(this.#e).setAdditionalAuthenticatedData(this.#a).setProtectedHeader(this.#t).setSharedUnprotectedHeader(this.#o).setUnprotectedHeader(t.unprotectedHeader).encrypt(t.key,{...t.options}),o={ciphertext:r.ciphertext,iv:r.iv,recipients:[{}],tag:r.tag};return r.aad&&(o.aad=r.aad),r.protected&&(o.protected=r.protected),r.unprotected&&(o.unprotected=r.unprotected),r.encrypted_key&&(o.recipients[0].encrypted_key=r.encrypted_key),r.header&&(o.recipients[0].header=r.header),o}for(let r=0;r<this.#c.length;r++){let o=this.#c[r];if(!ed(this.#t,this.#o,o.unprotectedHeader))throw new O("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");let a={...this.#t,...this.#o,...o.unprotectedHeader},{alg:i}=a;if("string"!=typeof i||!i)throw new O('JWE "alg" (Algorithm) Header Parameter missing or invalid');if("dir"===i||"ECDH-ES"===i)throw new O('"dir" and "ECDH-ES" alg may only be used with a single recipient');if("string"!=typeof a.enc||!a.enc)throw new O('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');if(t){if(t!==a.enc)throw new O('JWE "enc" (Encryption Algorithm) Header Parameter must be the same for all recipients')}else t=a.enc;if(e7(O,new Map,o.options.crit,this.#t,a),void 0!==a.zip&&"DEF"!==a.zip)throw new A('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');if(void 0!==a.zip&&!this.#t?.zip)throw new O('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.')}let r=W(t),o={ciphertext:"",recipients:[]};for(let a=0;a<this.#c.length;a++){let i=this.#c[a],n={};if(o.recipients.push(n),0===a){let t=await new tu(this.#e).setAdditionalAuthenticatedData(this.#a).setContentEncryptionKey(r).setProtectedHeader(this.#t).setSharedUnprotectedHeader(this.#o).setUnprotectedHeader(i.unprotectedHeader).setKeyManagementParameters(i.keyManagementParameters).encrypt(i.key,{...i.options,[en]:!0});o.ciphertext=t.ciphertext,o.iv=t.iv,o.tag=t.tag,t.aad&&(o.aad=t.aad),t.protected&&(o.protected=t.protected),t.unprotected&&(o.unprotected=t.unprotected),n.encrypted_key=t.encrypted_key,t.header&&(n.header=t.header);continue}let s=i.unprotectedHeader?.alg||this.#t?.alg||this.#o?.alg;to("dir"===s?t:s,i.key,"encrypt");let l=await eM(i.key,s),{encryptedKey:c,parameters:u}=await e8(s,t,l,r,i.keyManagementParameters);n.encrypted_key=v(c),(i.unprotectedHeader||u)&&(n.header={...i.unprotectedHeader,...u})}return o}}async function th(t,r,o){if(!eu(t))throw new j("Flattened JWS must be an object");if(void 0===t.protected&&void 0===t.header)throw new j('Flattened JWS must have either of the "protected" or "header" members');if(void 0!==t.protected&&"string"!=typeof t.protected)throw new j("JWS Protected Header incorrect type");if(void 0===t.payload)throw new j("JWS Payload missing");if("string"!=typeof t.signature)throw new j("JWS Signature missing or incorrect type");if(void 0!==t.header&&!eu(t.header))throw new j("JWS Unprotected Header incorrect type");let a={};if(t.protected)try{let r=g(t.protected);a=JSON.parse(c.decode(r))}catch{throw new j("JWS Protected Header is invalid")}if(!ed(a,t.header))throw new j("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");let i={...a,...t.header},n=e7(j,new Map([["b64",!0]]),o?.crit,a,i),s=!0;if(n.has("b64")&&"boolean"!=typeof(s=a.b64))throw new j('The "b64" (base64url-encode payload) Header Parameter must be a boolean');let{alg:d}=i;if("string"!=typeof d||!d)throw new j('JWS "alg" (Algorithm) Header Parameter missing or invalid');let p=o&&te("algorithms",o.algorithms);if(p&&!p.has(d))throw new C('"alg" (Algorithm) Header Parameter value not allowed');if(s){if("string"!=typeof t.payload)throw new j("JWS Payload must be a string")}else if("string"!=typeof t.payload&&!(t.payload instanceof Uint8Array))throw new j("JWS Payload must be a string or an Uint8Array instance");let h=!1;"function"==typeof r&&(r=await r(a,t),h=!0),to(d,r,"verify");let m=u(void 0!==t.protected?f(t.protected):new Uint8Array,f("."),"string"==typeof t.payload?s?f(t.payload):l.encode(t.payload):t.payload),y=el(t.signature,"signature",j),v=await eM(r,d);if(!await ex(d,v,y,m))throw new U;let _={payload:s?el(t.payload,"payload",j):"string"==typeof t.payload?l.encode(t.payload):t.payload};return(void 0!==t.protected&&(_.protectedHeader=a),void 0!==t.header&&(_.unprotectedHeader=t.header),h)?{..._,key:v}:_}async function tf(t,r,o){if(t instanceof Uint8Array&&(t=c.decode(t)),"string"!=typeof t)throw new j("Compact JWS must be a string or Uint8Array");let{0:a,1:i,2:n,length:s}=t.split(".");if(3!==s)throw new j("Invalid Compact JWS");let l=await th({payload:i,protected:a,signature:n},r,o),u={payload:l.payload,protectedHeader:l.protectedHeader};return"function"==typeof r?{...u,key:l.key}:u}async function tm(t,r,o){if(!eu(t))throw new j("General JWS must be an object");if(!Array.isArray(t.signatures)||!t.signatures.every(eu))throw new j("JWS Signatures missing or incorrect type");for(let a of t.signatures)try{return await th({header:a.header,payload:t.payload,protected:a.protected,signature:a.signature},r,o)}catch{}throw new U}let ty=t=>Math.floor(t.getTime()/1e3),tg=/^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;function tv(t){let r,o=tg.exec(t);if(!o||o[4]&&o[1])throw TypeError("Invalid time period format");let a=parseFloat(o[2]);switch(o[3].toLowerCase()){case"sec":case"secs":case"second":case"seconds":case"s":r=Math.round(a);break;case"minute":case"minutes":case"min":case"mins":case"m":r=Math.round(60*a);break;case"hour":case"hours":case"hr":case"hrs":case"h":r=Math.round(3600*a);break;case"day":case"days":case"d":r=Math.round(86400*a);break;case"week":case"weeks":case"w":r=Math.round(604800*a);break;default:r=Math.round(0x1e187e0*a)}return"-"===o[1]||"ago"===o[4]?-r:r}function t_(t,r){if(!Number.isFinite(r))throw TypeError(`Invalid ${t} input`);return r}let tb=t=>t.includes("/")?t.toLowerCase():`application/${t.toLowerCase()}`;function tS(t,r,o={}){var a,i;let n,s;try{n=JSON.parse(c.decode(r))}catch{}if(!eu(n))throw new I("JWT Claims Set must be a top-level JSON object");let{typ:l}=o;if(l&&("string"!=typeof t.typ||tb(t.typ)!==tb(l)))throw new R('unexpected "typ" JWT header value',n,"typ","check_failed");let{requiredClaims:u=[],issuer:d,subject:p,audience:h,maxTokenAge:f}=o,m=[...u];for(let t of(void 0!==f&&m.push("iat"),void 0!==h&&m.push("aud"),void 0!==p&&m.push("sub"),void 0!==d&&m.push("iss"),new Set(m.reverse())))if(!(t in n))throw new R(`missing required "${t}" claim`,n,t,"missing");if(d&&!(Array.isArray(d)?d:[d]).includes(n.iss))throw new R('unexpected "iss" claim value',n,"iss","check_failed");if(p&&n.sub!==p)throw new R('unexpected "sub" claim value',n,"sub","check_failed");if(h&&(a=n.aud,i="string"==typeof h?[h]:h,"string"==typeof a?!i.includes(a):!(Array.isArray(a)&&i.some(Set.prototype.has.bind(new Set(a))))))throw new R('unexpected "aud" claim value',n,"aud","check_failed");switch(typeof o.clockTolerance){case"string":s=tv(o.clockTolerance);break;case"number":s=o.clockTolerance;break;case"undefined":s=0;break;default:throw TypeError("Invalid clockTolerance option type")}let{currentDate:y}=o,g=ty(y||new Date);if((void 0!==n.iat||f)&&"number"!=typeof n.iat)throw new R('"iat" claim must be a number',n,"iat","invalid");if(void 0!==n.nbf){if("number"!=typeof n.nbf)throw new R('"nbf" claim must be a number',n,"nbf","invalid");if(n.nbf>g+s)throw new R('"nbf" claim timestamp check failed',n,"nbf","check_failed")}if(void 0!==n.exp){if("number"!=typeof n.exp)throw new R('"exp" claim must be a number',n,"exp","invalid");if(n.exp<=g-s)throw new x('"exp" claim timestamp check failed',n,"exp","check_failed")}if(f){let t=g-n.iat;if(t-s>("number"==typeof f?f:tv(f)))throw new x('"iat" claim timestamp check failed (too far in the past)',n,"iat","check_failed");if(t<0-s)throw new R('"iat" claim timestamp check failed (it should be in the past)',n,"iat","check_failed")}return n}class tw{#u;constructor(t){if(!eu(t))throw TypeError("JWT Claims Set MUST be an object");this.#u=structuredClone(t)}data(){return l.encode(JSON.stringify(this.#u))}get iss(){return this.#u.iss}set iss(t){this.#u.iss=t}get sub(){return this.#u.sub}set sub(t){this.#u.sub=t}get aud(){return this.#u.aud}set aud(t){this.#u.aud=t}set jti(t){this.#u.jti=t}set nbf(t){"number"==typeof t?this.#u.nbf=t_("setNotBefore",t):t instanceof Date?this.#u.nbf=t_("setNotBefore",ty(t)):this.#u.nbf=ty(new Date)+tv(t)}set exp(t){"number"==typeof t?this.#u.exp=t_("setExpirationTime",t):t instanceof Date?this.#u.exp=t_("setExpirationTime",ty(t)):this.#u.exp=ty(new Date)+tv(t)}set iat(t){void 0===t?this.#u.iat=ty(new Date):t instanceof Date?this.#u.iat=t_("setIssuedAt",ty(t)):"string"==typeof t?this.#u.iat=t_("setIssuedAt",ty(new Date)+tv(t)):this.#u.iat=t_("setIssuedAt",t)}}async function t$(t,r,o){let a=await tf(t,r,o);if(a.protectedHeader.crit?.includes("b64")&&!1===a.protectedHeader.b64)throw new I("JWTs MUST NOT use unencoded payload");let i={payload:tS(a.protectedHeader,a.payload,o),protectedHeader:a.protectedHeader};return"function"==typeof r?{...i,key:a.key}:i}async function tE(t,r,o){let a=await tl(t,r,o),i=tS(a.protectedHeader,a.plaintext,o),{protectedHeader:n}=a;if(void 0!==n.iss&&n.iss!==i.iss)throw new R('replicated "iss" claim header parameter mismatch',i,"iss","mismatch");if(void 0!==n.sub&&n.sub!==i.sub)throw new R('replicated "sub" claim header parameter mismatch',i,"sub","mismatch");if(void 0!==n.aud&&JSON.stringify(n.aud)!==JSON.stringify(i.aud))throw new R('replicated "aud" claim header parameter mismatch',i,"aud","mismatch");let s={payload:i,protectedHeader:n};return"function"==typeof r?{...s,key:a.key}:s}class tP{#d;constructor(t){this.#d=new tu(t)}setContentEncryptionKey(t){return this.#d.setContentEncryptionKey(t),this}setInitializationVector(t){return this.#d.setInitializationVector(t),this}setProtectedHeader(t){return this.#d.setProtectedHeader(t),this}setKeyManagementParameters(t){return this.#d.setKeyManagementParameters(t),this}async encrypt(t,r){let o=await this.#d.encrypt(t,r);return[o.protected,o.encrypted_key,o.iv,o.ciphertext,o.tag].join(".")}}class tk{#u;#t;#o;constructor(t){if(!(t instanceof Uint8Array))throw TypeError("payload must be an instance of Uint8Array");this.#u=t}setProtectedHeader(t){return es(this.#t,"setProtectedHeader"),this.#t=t,this}setUnprotectedHeader(t){return es(this.#o,"setUnprotectedHeader"),this.#o=t,this}async sign(t,r){let o,a,i,n;if(!this.#t&&!this.#o)throw new j("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");if(!ed(this.#t,this.#o))throw new j("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");let s={...this.#t,...this.#o},l=e7(j,new Map([["b64",!0]]),r?.crit,this.#t,s),c=!0;if(l.has("b64")&&"boolean"!=typeof(c=this.#t.b64))throw new j('The "b64" (base64url-encode payload) Header Parameter must be a boolean');let{alg:d}=s;if("string"!=typeof d||!d)throw new j('JWS "alg" (Algorithm) Header Parameter missing or invalid');to(d,t,"sign"),c?a=f(o=v(this.#u)):(a=this.#u,o=""),this.#t?n=f(i=v(JSON.stringify(this.#t))):(i="",n=new Uint8Array);let p=u(n,f("."),a),h=await eM(t,d),m={signature:v(await eR(d,h,p)),payload:o};return this.#o&&(m.header=this.#o),this.#t&&(m.protected=i),m}}class tR{#d;constructor(t){this.#d=new tk(t)}setProtectedHeader(t){return this.#d.setProtectedHeader(t),this}async sign(t,r){let o=await this.#d.sign(t,r);if(void 0===o.payload)throw TypeError("use the flattened module for creating JWS with b64: false");return`${o.protected}.${o.payload}.${o.signature}`}}class tx{#l;protectedHeader;unprotectedHeader;options;key;constructor(t,r,o){this.#l=t,this.key=r,this.options=o}setProtectedHeader(t){return es(this.protectedHeader,"setProtectedHeader"),this.protectedHeader=t,this}setUnprotectedHeader(t){return es(this.unprotectedHeader,"setUnprotectedHeader"),this.unprotectedHeader=t,this}addSignature(...t){return this.#l.addSignature(...t)}sign(...t){return this.#l.sign(...t)}done(){return this.#l}}class tC{#u;#p=[];constructor(t){this.#u=t}addSignature(t,r){let o=new tx(this,t,r);return this.#p.push(o),o}async sign(){if(!this.#p.length)throw new j("at least one signature must be added");let t={signatures:[],payload:""};for(let r=0;r<this.#p.length;r++){let o=this.#p[r],a=new tk(this.#u);a.setProtectedHeader(o.protectedHeader),a.setUnprotectedHeader(o.unprotectedHeader);let{payload:i,...n}=await a.sign(o.key,o.options);if(0===r)t.payload=i;else if(t.payload!==i)throw new j("inconsistent use of JWS Unencoded Payload (RFC7797)");t.signatures.push(n)}return t}}class tA{#t;#h;constructor(t={}){this.#h=new tw(t)}setIssuer(t){return this.#h.iss=t,this}setSubject(t){return this.#h.sub=t,this}setAudience(t){return this.#h.aud=t,this}setJti(t){return this.#h.jti=t,this}setNotBefore(t){return this.#h.nbf=t,this}setExpirationTime(t){return this.#h.exp=t,this}setIssuedAt(t){return this.#h.iat=t,this}setProtectedHeader(t){return this.#t=t,this}async sign(t,r){let o=new tR(this.#h.data());if(o.setProtectedHeader(this.#t),Array.isArray(this.#t?.crit)&&this.#t.crit.includes("b64")&&!1===this.#t.b64)throw new I("JWTs MUST NOT use unencoded payload");return o.sign(t,r)}}class tT{#i;#n;#s;#t;#f;#m;#y;#h;constructor(t={}){this.#h=new tw(t)}setIssuer(t){return this.#h.iss=t,this}setSubject(t){return this.#h.sub=t,this}setAudience(t){return this.#h.aud=t,this}setJti(t){return this.#h.jti=t,this}setNotBefore(t){return this.#h.nbf=t,this}setExpirationTime(t){return this.#h.exp=t,this}setIssuedAt(t){return this.#h.iat=t,this}setProtectedHeader(t){return es(this.#t,"setProtectedHeader"),this.#t=t,this}setKeyManagementParameters(t){return es(this.#s,"setKeyManagementParameters"),this.#s=t,this}setContentEncryptionKey(t){return es(this.#i,"setContentEncryptionKey"),this.#i=t,this}setInitializationVector(t){return es(this.#n,"setInitializationVector"),this.#n=t,this}replicateIssuerAsHeader(){return this.#f=!0,this}replicateSubjectAsHeader(){return this.#m=!0,this}replicateAudienceAsHeader(){return this.#y=!0,this}async encrypt(t,r){let o=new tP(this.#h.data());return this.#t&&(this.#f||this.#m||this.#y)&&(this.#t={...this.#t,iss:this.#f?this.#h.iss:void 0,sub:this.#m?this.#h.sub:void 0,aud:this.#y?this.#h.aud:void 0}),o.setProtectedHeader(this.#t),this.#n&&o.setInitializationVector(this.#n),this.#i&&o.setContentEncryptionKey(this.#i),this.#s&&o.setKeyManagementParameters(this.#s),o.encrypt(t,r)}}let tO=(t,r)=>{if("string"!=typeof t||!t)throw new N(`${r} missing or invalid`)};async function tj(t,r){let o,a;if(ep(t))o=t;else if(J(t))o=await e2(t);else throw TypeError(E(t,"CryptoKey","KeyObject","JSON Web Key"));if("sha256"!==(r??="sha256")&&"sha384"!==r&&"sha512"!==r)throw TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');switch(o.kty){case"AKP":tO(o.alg,'"alg" (Algorithm) Parameter'),tO(o.pub,'"pub" (Public key) Parameter'),a={alg:o.alg,kty:o.kty,pub:o.pub};break;case"EC":tO(o.crv,'"crv" (Curve) Parameter'),tO(o.x,'"x" (X Coordinate) Parameter'),tO(o.y,'"y" (Y Coordinate) Parameter'),a={crv:o.crv,kty:o.kty,x:o.x,y:o.y};break;case"OKP":tO(o.crv,'"crv" (Subtype of Key Pair) Parameter'),tO(o.x,'"x" (Public Key) Parameter'),a={crv:o.crv,kty:o.kty,x:o.x};break;case"RSA":tO(o.e,'"e" (Exponent) Parameter'),tO(o.n,'"n" (Modulus) Parameter'),a={e:o.e,kty:o.kty,n:o.n};break;case"oct":tO(o.k,'"k" (Key Value) Parameter'),a={k:o.k,kty:o.kty};break;default:throw new A('"kty" (Key Type) Parameter missing or unsupported')}let i=f(JSON.stringify(a));return v(await ec(r,i))}async function tI(t,r){r??="sha256";let o=await tj(t,r);return`urn:ietf:params:oauth:jwk-thumbprint:sha-${r.slice(-3)}:${o}`}async function tN(t,r){let o={...t,...r?.header};if(!eu(o.jwk))throw new j('"jwk" (JSON Web Key) Header Parameter must be a JSON object');let a=await eY({...o.jwk,ext:!0},o.alg);if(a instanceof Uint8Array||"public"!==a.type)throw new j('"jwk" (JSON Web Key) Header Parameter must be a public key');return a}function tM(t){return eu(t)}class tz{#g;#v=new WeakMap;constructor(t){if(!function(t){return t&&"object"==typeof t&&Array.isArray(t.keys)&&t.keys.every(tM)}(t))throw new M("JSON Web Key Set malformed");this.#g=structuredClone(t)}jwks(){return this.#g}async getKey(t,r){let{alg:o,kid:a}={...t,...r?.header},i=function(t){switch("string"==typeof t&&t.slice(0,2)){case"RS":case"PS":return"RSA";case"ES":return"EC";case"Ed":return"OKP";case"ML":return"AKP";default:throw new A('Unsupported "alg" value for a JSON Web Key Set')}}(o),n=this.#g.keys.filter(t=>{let r=i===t.kty;if(r&&"string"==typeof a&&(r=a===t.kid),r&&("string"==typeof t.alg||"AKP"===i)&&(r=o===t.alg),r&&"string"==typeof t.use&&(r="sig"===t.use),r&&Array.isArray(t.key_ops)&&(r=t.key_ops.includes("verify")),r)switch(o){case"ES256":r="P-256"===t.crv;break;case"ES384":r="P-384"===t.crv;break;case"ES512":r="P-521"===t.crv;break;case"Ed25519":case"EdDSA":r="Ed25519"===t.crv}return r}),{0:s,length:l}=n;if(0===l)throw new z;if(1!==l){let t=new q,r=this.#v;throw t[Symbol.asyncIterator]=async function*(){for(let t of n)try{yield await tq(r,t,o)}catch{}},t}return tq(this.#v,s,o)}}async function tq(t,r,o){let a=t.get(r)||t.set(r,{}).get(r);if(void 0===a[o]){let t=await eY({...r,ext:!0},o);if(t instanceof Uint8Array||"public"!==t.type)throw new M("JSON Web Key Set members must be public keys");a[o]=t}return a[o]}function tH(t){let r=new tz(t),o=async(t,o)=>r.getKey(t,o);return Object.defineProperties(o,{jwks:{value:()=>structuredClone(r.jwks()),enumerable:!1,configurable:!1,writable:!1}}),o}"undefined"!=typeof navigator&&navigator.userAgent?.startsWith?.("Mozilla/5.0 ")||(i="jose/v6.2.3");let tU=Symbol();async function tD(t,r,o,a=fetch){let i=await a(t,{method:"GET",signal:o,redirect:"manual",headers:r}).catch(t=>{if("TimeoutError"===t.name)throw new H;throw t});if(200!==i.status)throw new k("Expected 200 OK from the JSON Web Key Set HTTP response");try{return await i.json()}catch{throw new k("Failed to parse the JSON Web Key Set HTTP response as JSON")}}let tL=Symbol();class tK{#_;#b;#S;#w;#$;#E;#P;#k;#R;#x;constructor(t,r){if(!(t instanceof URL))throw TypeError("url must be an instance of URL");this.#_=new URL(t.href),this.#b="number"==typeof r?.timeoutDuration?r?.timeoutDuration:5e3,this.#S="number"==typeof r?.cooldownDuration?r?.cooldownDuration:3e4,this.#w="number"==typeof r?.cacheMaxAge?r?.cacheMaxAge:6e5,this.#P=new Headers(r?.headers),i&&!this.#P.has("User-Agent")&&this.#P.set("User-Agent",i),this.#P.has("accept")||(this.#P.set("accept","application/json"),this.#P.append("accept","application/jwk-set+json")),this.#k=r?.[tU],r?.[tL]!==void 0&&(this.#x=r?.[tL],function(t,r){return!("object"!=typeof t||null===t||!("uat"in t)||"number"!=typeof t.uat||Date.now()-t.uat>=r)&&"jwks"in t&&!!eu(t.jwks)&&!!Array.isArray(t.jwks.keys)&&!!Array.prototype.every.call(t.jwks.keys,eu)}(r?.[tL],this.#w)&&(this.#$=this.#x.uat,this.#R=tH(this.#x.jwks)))}pendingFetch(){return!!this.#E}coolingDown(){return"number"==typeof this.#$&&Date.now()<this.#$+this.#S}fresh(){return"number"==typeof this.#$&&Date.now()<this.#$+this.#w}jwks(){return this.#R?.jwks()}async getKey(t,r){this.#R&&this.fresh()||await this.reload();try{return await this.#R(t,r)}catch(o){if(o instanceof z&&!1===this.coolingDown())return await this.reload(),this.#R(t,r);throw o}}async reload(){this.#E&&("undefined"!=typeof WebSocketPair||"undefined"!=typeof navigator&&"Cloudflare-Workers"===navigator.userAgent||"undefined"!=typeof EdgeRuntime&&"vercel"===EdgeRuntime)&&(this.#E=void 0),this.#E||=tD(this.#_.href,this.#P,AbortSignal.timeout(this.#b),this.#k).then(t=>{this.#R=tH(t),this.#x&&(this.#x.uat=Date.now(),this.#x.jwks=t),this.#$=Date.now(),this.#E=void 0}).catch(t=>{throw this.#E=void 0,t}),await this.#E}}function tJ(t,r){let o=new tK(t,r),a=async(t,r)=>o.getKey(t,r);return Object.defineProperties(a,{coolingDown:{get:()=>o.coolingDown(),enumerable:!0,configurable:!1},fresh:{get:()=>o.fresh(),enumerable:!0,configurable:!1},reload:{value:()=>o.reload(),enumerable:!0,configurable:!1,writable:!1},reloading:{get:()=>o.pendingFetch(),enumerable:!0,configurable:!1},jwks:{value:()=>o.jwks(),enumerable:!0,configurable:!1,writable:!1}}),a}class tV{#h;constructor(t={}){this.#h=new tw(t)}encode(){let t=v(JSON.stringify({alg:"none"})),r=v(this.#h.data());return`${t}.${r}.`}setIssuer(t){return this.#h.iss=t,this}setSubject(t){return this.#h.sub=t,this}setAudience(t){return this.#h.aud=t,this}setJti(t){return this.#h.jti=t,this}setNotBefore(t){return this.#h.nbf=t,this}setExpirationTime(t){return this.#h.exp=t,this}setIssuedAt(t){return this.#h.iat=t,this}static decode(t,r){let o;if("string"!=typeof t)throw new I("Unsecured JWT must be a string");let{0:a,1:i,2:n,length:s}=t.split(".");if(3!==s||""!==n)throw new I("Invalid Unsecured JWT");try{if(o=JSON.parse(c.decode(g(a))),"none"!==o.alg)throw Error()}catch{throw new I("Invalid Unsecured JWT")}return{payload:tS(o,g(i),r),header:o}}}function tW(t){let r;if("string"==typeof t){let o=t.split(".");(3===o.length||5===o.length)&&([r]=o)}else if("object"==typeof t&&t)if("protected"in t)r=t.protected;else throw TypeError("Token does not contain a Protected Header");try{if("string"!=typeof r||!r)throw Error();let t=JSON.parse(c.decode(g(r)));if(!eu(t))throw Error();return t}catch{throw TypeError("Invalid Token or Protected Header formatting")}}function tF(t){let r,o;if("string"!=typeof t)throw new I("JWTs must use Compact JWS serialization, JWT must be a string");let{1:a,length:i}=t.split(".");if(5===i)throw new I("Only JWTs using Compact JWS serialization can be decoded");if(3!==i)throw new I("Invalid JWT");if(!a)throw new I("JWTs must contain a payload");try{r=g(a)}catch{throw new I("Failed to base64url decode the payload")}try{o=JSON.parse(c.decode(r))}catch{throw new I("Failed to parse the decoded payload as JSON")}if(!eu(o))throw new I("Invalid JWT Claims Set");return o}function tB(t){let r=t?.modulusLength??2048;if("number"!=typeof r||r<2048)throw new A("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");return r}async function tZ(t,r){let o,a;switch(t){case"PS256":case"PS384":case"PS512":o={name:"RSA-PSS",hash:`SHA-${t.slice(-3)}`,publicExponent:Uint8Array.of(1,0,1),modulusLength:tB(r)},a=["sign","verify"];break;case"RS256":case"RS384":case"RS512":o={name:"RSASSA-PKCS1-v1_5",hash:`SHA-${t.slice(-3)}`,publicExponent:Uint8Array.of(1,0,1),modulusLength:tB(r)},a=["sign","verify"];break;case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":o={name:"RSA-OAEP",hash:`SHA-${parseInt(t.slice(-3),10)||1}`,publicExponent:Uint8Array.of(1,0,1),modulusLength:tB(r)},a=["decrypt","unwrapKey","encrypt","wrapKey"];break;case"ES256":o={name:"ECDSA",namedCurve:"P-256"},a=["sign","verify"];break;case"ES384":o={name:"ECDSA",namedCurve:"P-384"},a=["sign","verify"];break;case"ES512":o={name:"ECDSA",namedCurve:"P-521"},a=["sign","verify"];break;case"Ed25519":case"EdDSA":a=["sign","verify"],o={name:"Ed25519"};break;case"ML-DSA-44":case"ML-DSA-65":case"ML-DSA-87":a=["sign","verify"],o={name:t};break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":{a=["deriveBits"];let t=r?.crv??"P-256";switch(t){case"P-256":case"P-384":case"P-521":o={name:"ECDH",namedCurve:t};break;case"X25519":o={name:"X25519"};break;default:throw new A("Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, and X25519")}break}default:throw new A('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}return crypto.subtle.generateKey(o,r?.extractable??!1,a)}async function tG(t,r){let o,a,i;switch(t){case"HS256":case"HS384":case"HS512":o=parseInt(t.slice(-3),10),a={name:"HMAC",hash:`SHA-${o}`,length:o},i=["sign","verify"];break;case"A128CBC-HS256":case"A192CBC-HS384":case"A256CBC-HS512":return o=parseInt(t.slice(-3),10),crypto.getRandomValues(new Uint8Array(o>>3));case"A128KW":case"A192KW":case"A256KW":a={name:"AES-KW",length:o=parseInt(t.slice(1,4),10)},i=["wrapKey","unwrapKey"];break;case"A128GCMKW":case"A192GCMKW":case"A256GCMKW":case"A128GCM":case"A192GCM":case"A256GCM":a={name:"AES-GCM",length:o=parseInt(t.slice(1,4),10)},i=["encrypt","decrypt"];break;default:throw new A('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}return crypto.subtle.generateKey(a,r?.extractable??!1,i)}let tX="WebCryptoAPI"},8330(t){"use strict";t.exports=JSON.parse('{"name":"xmcp","description":"The MCP framework","version":"1.8.0","author":{"name":"xmcp","email":"support@xmcp.dev","url":"https://xmcp.dev"},"contributors":[{"name":"Valentina Bearzotti","email":"valebearzotti1@gmail.com","url":"https://github.com/valebearzotti"},{"name":"Jose Rago","email":"jose@basement.studio","url":"https://github.com/ragojose"}],"license":"MIT","keywords":["mcp","modelcontextprotocol","http","stdio"],"repository":{"type":"git","url":"https://github.com/basementstudio/xmcp"},"homepage":"https://xmcp.dev","type":"commonjs","main":"./dist/index.js","types":"./dist/index.d.ts","bin":{"xmcp":"dist/cli.js"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js","default":"./dist/index.js"},"./node":{"types":"./dist/node.d.ts","node":"./dist/node.js"},"./host-bridge":{"types":"./dist/host-bridge.d.ts","import":"./dist/host-bridge.js","require":"./dist/host-bridge.js","default":"./dist/host-bridge.js"},"./headers":{"types":"./dist/runtime/headers.d.ts","require":"./dist/runtime/headers.js","default":"./dist/runtime/headers.js"},"./cloudflare":{"types":"./dist/cloudflare.d.ts","import":"./dist/cloudflare.js","require":"./dist/cloudflare.js","default":"./dist/cloudflare.js"},"./config":{"types":"./dist/config/index.d.ts","import":"./dist/config.js","require":"./dist/config.js","default":"./dist/config.js"},"./package.json":"./package.json","./client":{"types":"./dist/client.d.ts","node":"./dist/client.js"}},"typesVersions":{"*":{"node":["dist/node.d.ts"],"host-bridge":["dist/host-bridge.d.ts"],"headers":["dist/runtime/headers.d.ts"],"cloudflare":["dist/cloudflare.d.ts"],"config":["dist/config/index.d.ts"],"client":["dist/client.d.ts"]}},"files":["dist"],"scripts":{"dev":"cross-env NODE_ENV=development tsx --watch --tsconfig ./bundler.tsconfig.json ./bundler/index.ts","build":"cross-env NODE_ENV=production tsx --tsconfig ./bundler.tsconfig.json ./bundler/index.ts","analyze":"cross-env GENERATE_STATS=true pnpm build && pnpm tsx scripts/analyze-rspack-stats.ts","bench":"tsx bench/run.mts","test:config":"pnpm --dir ../compiler test:config","test:adapters":"node --import tsx --test src/runtime/adapters/*/__tests__/*.test.ts","test:runtime":"node --import tsx --test src/runtime/utils/__tests__/*.test.ts src/runtime/utils/ui/__tests__/*.test.ts","test:client":"node --import tsx --test src/client/__tests__/*.test.ts"},"dependencies":{},"devDependencies":{"@modelcontextprotocol/client":"^2.2.0","@modelcontextprotocol/node":"^2.0.0","@modelcontextprotocol/server":"^2.3.0","@nestjs/common":"^11.1.12","@rspack/core":"^1.6.7","@types/async-retry":"^1.4.9","@types/content-type":"^1.1.9","@types/express":"^5.0.6","@types/fs-extra":"^11.0.4","@types/jsonwebtoken":"^9.0.10","@types/node":"^22.19.2","@types/react":"^19.2.7","@types/react-dom":"^19.2.3","async-retry":"^1.3.3","chalk":"^5.6.2","chokidar":"^3.6.0","ci-info":"^4.3.1","commander":"^11.1.0","content-type":"^1.0.5","cross-env":"^7.0.3","del":"^7.1.0","dotenv":"^16.6.1","express":"^4.22.1","fastify":"^5.12.5","fs-extra":"^11.3.2","glob":"^11.1.0","is-docker":"^4.0.0","is-wsl":"^3.1.0","jose":"^6.1.3","json5":"^2.2.3","jsonwebtoken":"^9.0.3","memfs":"^4.51.1","postcss-loader":"^8.2.0","raw-body":"^3.0.2","reflect-metadata":"^0.2.2","rxjs":"^7.8.2","ts-checker-rspack-plugin":"^1.2.1","tsx":"^4.21.0","typescript":"^5.9.3","zod-to-json-schema":"^3.25.0"},"peerDependencies":{"@modelcontextprotocol/client":"^2.2.0","@modelcontextprotocol/server":"^2.3.0","jose":"^6.1.3","react":">=19.0.0","react-dom":">=19.0.0","zod":"^3.25.76 || ^4.0.0"},"peerDependenciesMeta":{"@modelcontextprotocol/client":{"optional":true},"@modelcontextprotocol/server":{"optional":true},"jose":{"optional":true},"react":{"optional":true},"react-dom":{"optional":true}}}')}},a={};function i(t){var r=a[t];if(void 0!==r)return r.exports;var n=a[t]={exports:{}};return o[t](n,n.exports,i),n.exports}r=Object.getPrototypeOf?t=>Object.getPrototypeOf(t):t=>t.__proto__,i.t=function(o,a){if(1&a&&(o=this(o)),8&a||"object"==typeof o&&o&&(4&a&&o.__esModule||16&a&&"function"==typeof o.then))return o;var n=Object.create(null);i.r(n);var s={};t=t||[null,r({}),r([]),r(r)];for(var l=2&a&&o;("object"==typeof l||"function"==typeof l)&&!~t.indexOf(l);l=r(l))Object.getOwnPropertyNames(l).forEach(t=>{s[t]=()=>o[t]});return s.default=()=>o,i.d(n,s),n},i.d=(t,r)=>{for(var o in r)i.o(r,o)&&!i.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:r[o]})},i.o=(t,r)=>Object.prototype.hasOwnProperty.call(t,r),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};for(var s in(()=>{"use strict";let t,r,o,a,s,l,c,u,d,p,h,f,m,y,g,v,_,b,S,w;i.r(n),i.d(n,{createClient:()=>h$,withClient:()=>hE});var $,E,P,k,R,x,C,A,T=Object.create,O=Object.defineProperty,j=Object.getOwnPropertyDescriptor,I=Object.getOwnPropertyNames,N=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty,z=(t,r)=>()=>(r||t((r={exports:{}}).exports,r),r.exports),q=(t,r,o)=>(o=null!=t?T(N(t)):{},((t,r,o,a)=>{if(r&&"object"==typeof r||"function"==typeof r)for(var i,n=I(r),s=0,l=n.length;s<l;s++)i=n[s],M.call(t,i)||i===o||O(t,i,{get:(t=>r[t]).bind(null,i),enumerable:!(a=j(r,i))||a.enumerable});return t})(!r&&t&&t.__esModule?o:O(o,"default",{value:t,enumerable:!0}),t));let H=new Set(["https://json-schema.org/draft/2020-12/schema","http://json-schema.org/draft/2020-12/schema"]),U=new Set(["https://json-schema.org/draft/2019-09/schema","http://json-schema.org/draft/2019-09/schema"]),D=new Set(["https://json-schema.org/draft-07/schema","http://json-schema.org/draft-07/schema"]),L=new Set(["https://json-schema.org/draft-06/schema","http://json-schema.org/draft-06/schema"]);function K(t){let r=Object.values(t).filter(t=>"number"==typeof t);return Object.entries(t).filter(([t,o])=>-1===r.indexOf(+t)).map(([t,r])=>r)}function J(t,r="|"){return t.map(t=>ep(t)).join(r)}function V(t,r){return"bigint"==typeof r?r.toString():r}class W{constructor(t){this._getter=t,this._value=void 0}get value(){let t=this._getter;return void 0!==t&&(this._value=t(),this._getter=void 0),this._value}}function F(t){return new W(t)}function B(t){let r=+!!t.startsWith("^"),o=t.endsWith("$")?t.length-1:t.length;return t.slice(r,o)}let Z=Symbol("evaluating");function G(t,r,o){Object.defineProperty(t,r,{value:o,writable:!0,enumerable:!0,configurable:!0})}function X(t){let r=Object.getOwnPropertyDescriptor(t,"shape");return r?.get?r.get.raw:r?.value}function Y(t){return X(t._zod.def)??t._zod.def.shape}function Q(t,r,o){Object.defineProperty(t,r,{get(){let t=o();return G(this,r,t),t},enumerable:!0,configurable:!0})}function ee(t,r,o){r in t?G(t,r,o):t[r]=o}function et(t,r,o,a){let i=Y(r);for(let n of o){let o=Object.getOwnPropertyDescriptor(i,n);o.enumerable&&(o.get?Q(t,n,()=>{let t=r._zod.def.shape[n];return a?a(t,n):t}):ee(t,n,a?a(o.value,n):o.value))}}function er(...t){let r={};for(let o of t)Object.assign(r,Object.getOwnPropertyDescriptors(o));return Object.defineProperties({},r)}let eo="captureStackTrace"in Error?Error.captureStackTrace:(...t)=>{};function ea(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}let ei=F(()=>{if(eq.jitless||"undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return Function(""),!0}catch(t){return!1}});function en(t){if(!1===ea(t))return!1;let r=t.constructor;if(void 0===r||"function"!=typeof r)return!0;let o=r.prototype;return!1!==ea(o)&&!1!==Object.prototype.hasOwnProperty.call(o,"isPrototypeOf")}function es(t){return en(t)?{...t}:Array.isArray(t)?[...t]:t instanceof Map?new Map(t):t instanceof Set?new Set(t):t}let el=new Set(["string","number","symbol"]);function ec(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function eu(t,r,o){let a=new t._zod.constr(r??t._zod.def);return(!r||o?.parent)&&(a._zod.parent=t),a}function ed(t){if(!t)return{};if("string"==typeof t)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return(delete t.message,"string"==typeof t.error)?{...t,error:()=>t.error}:t}function ep(t){return"bigint"==typeof t?t.toString()+"n":"string"==typeof t?`"${t}"`:`${t}`}let eh={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-0x80000000,0x7fffffff],uint32:[0,0xffffffff],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]},ef={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function em(t,r){let o=Y(t),a=[];for(let t of Reflect.ownKeys(r)){if(!Object.getOwnPropertyDescriptor(o,t)?.enumerable)throw Error(`Unrecognized key: "${String(t)}"`);r[t]&&a.push(t)}return a}function ey(t,r){let o={};et(o,t,Reflect.ownKeys(Y(t)));var a=o,i=r;for(let t of Reflect.ownKeys(i)){let r=Object.getOwnPropertyDescriptor(i,t);r.enumerable&&(r.get?Q(a,t,()=>i[t]):ee(a,t,r.value))}return o}function eg(t,r,o,a="partial"){let i=r._zod.def.checks;if(i&&i.length>0)throw Error(`.${a}() cannot be used on object schemas containing refinements`);let n=o?new Set(em(r,o)):void 0,s={};return et(s,r,Reflect.ownKeys(Y(r)),t&&((r,o)=>n&&!n.has(o)?r:new t({type:"optional",innerType:r}))),eu(r,er(r._zod.def,{shape:s,checks:[]}))}function ev(t,r=0){if(!0===t.aborted)return!0;for(let o=r;o<t.issues.length;o++)if(t.issues[o]?.continue!==!0)return!0;return!1}function e_(t,r){return r.map(r=>(r.path??(r.path=[]),r.path.unshift(t),r))}function eb(t){return"string"==typeof t?t:t?.message}function eS(t,r,o){var a;for(let i=r;i<t.length;i++)(a=t[i]).schema??(a.schema=o)}function ew(t,r,o){let a=t.inst?._zod?.traits;a?.has("$ZodType")&&(a.has("$ZodCheck")?t.schema??(t.schema=t.inst):t.schema=t.inst);let i=t.schema!==t.inst?t.schema?._zod.def?.error:void 0,n=t.message?t.message:eb(t.inst?._zod.def?.error?.(t))??eb(i?.(t))??eb(r?.error?.(t))??eb(o.customError?.(t))??eb(o.localeError?.(t))??"Invalid input",s={};for(let r of Object.keys(t))"inst"!==r&&"schema"!==r&&"continue"!==r&&"input"!==r&&"__proto__"!==r&&(s[r]=t[r]);return s.path??(s.path=[]),s.message=n,r?.reportInput&&(s.input=t.input),s}let e$=/[\uD800-\uDBFF]/;function eE(t){let r=t.length;if(!e$.test(t))return r;let o=r;for(let a=0;a<r-1;a++)(64512&t.charCodeAt(a))==55296&&(64512&t.charCodeAt(a+1))==56320&&(o--,a++);return o}function eP(t){return Array.isArray(t)?"array":"string"==typeof t?"string":"unknown"}function ek(...t){let[r,o,a]=t;return"string"==typeof r?{message:r,code:"custom",input:o,inst:a}:{...r}}function eR(t,r,o,a=!0){return Object.defineProperty(t,r,{configurable:!0,writable:!0,enumerable:a,value:o}),o}function ex(t,r){for(let o in t){let a=t[o];Object.defineProperty(r,o,{configurable:!0,enumerable:!0,get(){return eR(this,o,a(this))},set(t){eR(this,o,t)}})}return r}let eC=!1,eA={configurable:!0,get(){eC=!0}};function eT(r,o,a){let i=Object.getPrototypeOf(r._zod);if(o in i&&t!==r._zod){t=void 0;return}t=r._zod,Object.defineProperty(i,o,{configurable:!0,get(){Object.defineProperty(this,o,eA);let t=eC;eC=!1;try{let r=a(this);return eC?delete this[o]:Object.defineProperty(this,o,{configurable:!0,writable:!0,value:r}),eC=eC||t,r}catch(r){throw delete this[o],eC=eC||t,r}},set(t){Object.defineProperty(this,o,{configurable:!0,writable:!0,value:t})}})}let eO=Object.freeze({status:"aborted"}),ej={value:void 0,enumerable:!1},eI="captureStackTrace"in Error?Error:null;function eN(t,r,o,a){function i(t){this.def=t,this.constr=u,this.traits=new Set}i.prototype={};let n=o&&new WeakSet;function s(a,s){if(a._zod){if(a._zod.traits.has(t))return}else{ej.value=new i(s);try{Object.defineProperty(a,"_zod",ej)}finally{ej.value=void 0}}if(a._zod.traits.add(t),r(a,s),n){let t=Object.getPrototypeOf(a),r=a._zod.constr.prototype,i=t;for(;i&&i!==r;)i=Object.getPrototypeOf(i);let s=i??t;if(!n.has(s)){n.add(s);var l=s,c=o;for(let t in c){let r=Object.getOwnPropertyDescriptor(c,t);r.get?Object.defineProperty(l,t,{...r,enumerable:!1}):function(t,r,o){Object.defineProperty(t,r,{configurable:!0,get(){return this==null?o:eR(this,r,o.bind(this))},set(t){eR(this,r,t)}})}(l,t,r.value)}}}let d=u.prototype;for(let t in d)Object.prototype.hasOwnProperty.call(d,t)&&(t in a||(a[t]=d[t].bind(a)))}let l=a?.Parent??Object;class c extends l{}function u(t){let r=a?.Parent?function(t){let r=eI;if(r){let o=r.stackTraceLimit;if("number"==typeof o){try{r.stackTraceLimit=0}catch{return eI=null,new t}try{return new t}finally{r.stackTraceLimit=o}}}return new t}(c):this;s(r,t);let o=r._zod.deferred;if(o){for(let t of o)t();r._zod.deferred=void 0}let i=globalThis.__zod_globalConfig?.postProcessor;return i&&i(r),r}return Object.defineProperty(c,"name",{value:t}),Object.defineProperty(u,"init",{value:s}),Object.defineProperty(u,Symbol.hasInstance,{value:r=>!!a?.Parent&&r instanceof a.Parent||r?._zod?.traits?.has(t)}),Object.defineProperty(u,"name",{value:t}),u}class eM extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class ez extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}(x=globalThis).__zod_globalConfig??(x.__zod_globalConfig={});let eq=globalThis.__zod_globalConfig;function eH(t){return t&&Object.assign(eq,t),eq}class eU extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform"),this.name="ZodCyclicError"}}let eD="~memo",eL=[];function eK(t){return null!==t&&"object"==typeof t}function eJ(t){return t.map(t=>t.path?{...t,path:t.path.slice()}:{...t})}let eV=new WeakMap,eW=[],eF={alloc(t,o,a){let i=r;if(!i)return a;r=void 0;let n={value:a,issues:null};return i.set(o.value,n),eW.push(n),a},guard(t){var r;(r=t._zod).deferred??(r.deferred=[]),t._zod.deferred.push(()=>{let r=t._zod.parse,o=(t,o)=>{var a,i;let n;if("backward"!==o.direction&&(a=o,i=t.value,void 0!==(n=a[eD]?.backEdges)&&eK(i)&&n.has(i)))throw new eU;return r(t,o)};t._zod.parse=o,t._zod.run===r&&(t._zod.run=o)})},attach(t){var o;let a,i,n,s=!1;(o=t._zod).deferred??(o.deferred=[]),t._zod.deferred.push(()=>{let o=t._zod.parse,l=(c,u)=>{let d;if(void 0===a){let r=function t(r,o,a){var i,n;let s=eV.get(r);if(void 0!==s)return 2*!!s;if(o.has(r))return 2;o.add(r);let l=0,c=r=>{if(2!==l&&r?._zod){let i=t(r,o,a);i>l&&(l=i)}},u=t=>{t>l&&(l=t)},d=r._zod.def;switch(d.type){case"object":{let r=X(d);u(r?((r,i)=>{let n=0;for(let s of Reflect.ownKeys(r)){let l=Object.getOwnPropertyDescriptor(r,s);if(i&&!l.enumerable)continue;let c=l.get?1:l.value?._zod?t(l.value,o,a):0;c>n&&(n=c)}return n})(r,!0):1),c(d.catchall);break}case"array":c(d.element);break;case"tuple":for(let t of d.items)c(t);c(d.rest);break;case"record":case"map":c(d.keyType),c(d.valueType);break;case"set":c(d.valueType);break;case"union":for(let t of d.options)c(t);break;case"intersection":c(d.left),c(d.right);break;case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":c(d.innerType);break;case"pipe":c(d.in),c(d.out);break;case"function":c(d.input),c(d.output);break;case"lazy":{let i=d._cachedInner??(a?r._zod.innerType:void 0);u(i?t(i,o,!1):1);break}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":break;default:for(let t in d){let r=Object.getOwnPropertyDescriptor(d,t);if(!r||r.get)continue;let o=r.value;if(o&&"object"==typeof o){if(o._zod)c(o);else if(Array.isArray(o))for(let t of o)c(t)}}}return o.delete(r),i=r,1!==(n=l)&&eV.set(i,2===n),n}(t,new Set,!1);if(0===r)return t._zod.parse=o,t._zod.run===l&&(t._zod.run=o),o(c,u);2===r||s?a=!0:s=!0}let p=c.value;if(!eK(p))return o(c,u);let h=u[eD];if(h||(h={buckets:new WeakMap,backEdges:void 0},u[eD]=h),i===u)d=n;else{var f,m;let r;f=h,m=t,(r=f.buckets.get(m))||(r=new WeakMap,f.buckets.set(m,r)),d=r,i=u,n=d}let y=d.get(p);if(y)return c.value=y.value,y.issues?y.issues.length&&c.issues.push(...eJ(y.issues)):(c.memo=!0,h.backEdges??(h.backEdges=new WeakSet),h.backEdges.add(y.value)),c;r=d;let g=eW.length,v=o(c,u);r=void 0;let _=eW.length>g?eW.pop():void 0;return v instanceof Promise?v.then(t=>(_&&(_.issues=t.issues.length?eJ(t.issues):eL),t)):(_&&(_.issues=v.issues.length?eJ(v.issues):eL),v)};t._zod.parse=l,t._zod.run===o&&(t._zod.run=l)})}},eB=/^[cC][0-9a-z]{6,}$/,eZ=/^[0-9a-z]+$/,eG=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,eX=/^[0-9a-vA-V]{20}$/,eY=/^[A-Za-z0-9]{27}$/,eQ=/^[a-zA-Z0-9_-]{21}$/,e0=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,e1=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,e2=t=>t?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,e9=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,e4=`^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`,e5=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,e3=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,e6=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,e8=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,e7=/^https?$/,te=/^\+[1-9]\d{6,14}$/,tt="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",tr=($=tt,RegExp(`^${$}$`));function to(t){let r="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof t.precision?-1===t.precision?`${r}`:0===t.precision?`${r}:[0-5]\\d`:`${r}:[0-5]\\d\\.\\d{${t.precision}}`:t.seconds?`${r}:[0-5]\\d(?:\\.\\d+)?`:`${r}(?::[0-5]\\d(?:\\.\\d+)?)?`}let ta=/^[\s\S]{0,}$/,ti=/^-?\d+$/,tn=/^-?\d+(?:\.\d+)?$/,ts=/^(?:true|false)$/i,tl=/^null$/i,tc=/^[^A-Z]*$/,tu=/^[^a-z]*$/,td=eN("$ZodCheck",(t,r)=>{var o;t._zod??(t._zod={}),t._zod.def=r,(o=t._zod).onattach??(o.onattach=[])}),tp=t=>{let r=t.value;return null!=r&&void 0!==r.length},th={number:"number",bigint:"bigint",object:"date"},tf=eN("$ZodCheckLessThan",(t,r)=>{td.init(t,r);let o=th[typeof r.value];t._zod.check=a=>{(r.inclusive?a.value<=r.value:a.value<r.value)||a.issues.push({origin:th[typeof a.value]??o,code:"too_big",maximum:"object"==typeof r.value?r.value.getTime():r.value,input:a.value,inclusive:r.inclusive,inst:t,continue:!r.abort})}}),tm=eN("$ZodCheckGreaterThan",(t,r)=>{td.init(t,r);let o=th[typeof r.value];t._zod.check=a=>{(r.inclusive?a.value>=r.value:a.value>r.value)||a.issues.push({origin:th[typeof a.value]??o,code:"too_small",minimum:"object"==typeof r.value?r.value.getTime():r.value,input:a.value,inclusive:r.inclusive,inst:t,continue:!r.abort})}}),ty=eN("$ZodCheckMultipleOf",(t,r)=>{td.init(t,r),t._zod.check=o=>{var a;let i,n,s;if(typeof o.value!=typeof r.value)throw Error("Cannot mix number and bigint in multiple_of check.");("bigint"==typeof o.value?r.value!==BigInt(0)&&o.value%r.value===BigInt(0):0==(n=Math.round(i=(a=o.value)/r.value),s=4*Number.EPSILON*Math.max(Math.abs(i),1),Math.abs(i-n)<s?0:i-n))||o.issues.push({origin:typeof o.value,code:"not_multiple_of",divisor:r.value,input:o.value,inst:t,continue:!r.abort})}}),tg=eN("$ZodCheckNumberFormat",(t,r)=>{td.init(t,r),r.format=r.format||"float64";let o=r.format?.includes("int"),a=o?"int":"number",[i,n]=eh[r.format];t._zod.check=s=>{let l=s.value;if(o){if(!Number.isInteger(l))return void s.issues.push({expected:a,format:r.format,code:"invalid_type",continue:!1,input:l,inst:t});if(!Number.isSafeInteger(l))return void(l>0?s.issues.push({input:l,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:a,inclusive:!0,continue:!r.abort}):s.issues.push({input:l,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:a,inclusive:!0,continue:!r.abort}))}l<i&&s.issues.push({origin:"number",input:l,code:"too_small",minimum:i,inclusive:!0,inst:t,continue:!r.abort}),l>n&&s.issues.push({origin:"number",input:l,code:"too_big",maximum:n,inclusive:!0,inst:t,continue:!r.abort})}}),tv=eN("$ZodCheckMaxLength",(t,r)=>{var o;td.init(t,r),(o=t._zod.def).when??(o.when=tp),t._zod.check=o=>{let a=o.value,i=a.length;if(("string"==typeof a&&i>r.maximum?eE(a):i)<=r.maximum)return;let n=eP(a);o.issues.push({origin:n,code:"too_big",maximum:r.maximum,inclusive:!0,input:a,inst:t,continue:!r.abort})}}),t_=eN("$ZodCheckMinLength",(t,r)=>{var o;td.init(t,r),(o=t._zod.def).when??(o.when=tp),t._zod.check=o=>{let a=o.value,i=a.length;if(("string"==typeof a&&i>=r.minimum&&i<2*r.minimum?eE(a):i)>=r.minimum)return;let n=eP(a);o.issues.push({origin:n,code:"too_small",minimum:r.minimum,inclusive:!0,input:a,inst:t,continue:!r.abort})}}),tb=eN("$ZodCheckLengthEquals",(t,r)=>{var o;td.init(t,r),(o=t._zod.def).when??(o.when=tp),t._zod.check=o=>{let a=o.value,i=a.length,n="string"==typeof a&&i>=r.length&&i<=2*r.length?eE(a):i;if(n===r.length)return;let s=eP(a),l=n>r.length;o.issues.push({origin:s,...l?{code:"too_big",maximum:r.length}:{code:"too_small",minimum:r.length},inclusive:!0,exact:!0,input:o.value,inst:t,continue:!r.abort})}}),tS=eN("$ZodCheckStringFormat",(t,r)=>{var o,a;td.init(t,r),r.pattern?(o=t._zod).check??(o.check=o=>{r.pattern.lastIndex=0,r.pattern.test(o.value)||o.issues.push({origin:"string",code:"invalid_format",format:r.format,input:o.value,...r.pattern?{pattern:r.pattern.toString()}:{},inst:t,continue:!r.abort})}):(a=t._zod).check??(a.check=()=>{})}),tw=eN("$ZodCheckRegex",(t,r)=>{tS.init(t,r),t._zod.check=o=>{r.pattern.lastIndex=0,r.pattern.test(o.value)||o.issues.push({origin:"string",code:"invalid_format",format:"regex",input:o.value,pattern:r.pattern.toString(),inst:t,continue:!r.abort})}}),t$=eN("$ZodCheckLowerCase",(t,r)=>{r.pattern??(r.pattern=tc),tS.init(t,r)}),tE=eN("$ZodCheckUpperCase",(t,r)=>{r.pattern??(r.pattern=tu),tS.init(t,r)}),tP=eN("$ZodCheckIncludes",(t,r)=>{td.init(t,r);let o=ec(r.includes),a=new RegExp("number"==typeof r.position?`^.{${r.position},}${o}`:o);r.pattern=a,t._zod.check=o=>{o.value.includes(r.includes,r.position)||o.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:r.includes,input:o.value,inst:t,continue:!r.abort})}}),tk=eN("$ZodCheckStartsWith",(t,r)=>{td.init(t,r);let o=RegExp(`^${ec(r.prefix)}.*`);r.pattern??(r.pattern=o),t._zod.check=o=>{o.value.startsWith(r.prefix)||o.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:r.prefix,input:o.value,inst:t,continue:!r.abort})}}),tR=eN("$ZodCheckEndsWith",(t,r)=>{td.init(t,r);let o=RegExp(`.*${ec(r.suffix)}$`);r.pattern??(r.pattern=o),t._zod.check=o=>{o.value.endsWith(r.suffix)||o.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:r.suffix,input:o.value,inst:t,continue:!r.abort})}}),tx=eN("$ZodCheckOverwrite",(t,r)=>{td.init(t,r),t._zod.check=t=>{t.value=r.tx(t.value)}});class tC{constructor(t=[],r={}){this.content=[],this.indent=0,this.args=t,this.closed=r}indented(t){this.indent+=1;try{t(this)}finally{this.indent-=1}}write(t){if("function"==typeof t){t(this,{execution:"sync"}),t(this,{execution:"async"});return}let r=t.split("\n").filter(t=>t),o=Math.min(...r.map(t=>t.length-t.trimStart().length));for(let t of r.map(t=>t.slice(o)).map(t=>" ".repeat(2*this.indent)+t))this.content.push(t)}compile(){let t=Function,r=this?.content??[""];return new t(...Object.keys(this.closed),`return function (${this.args.join(", ")}) {
4
4
  ${r.join("\n")}
5
5
  };`)(...Object.values(this.closed))}}let tA={major:4,minor:6,patch:5},tT=eN("$ZodType",(t,r)=>{var o;t??(t={}),t._zod.def=r,t._zod.bag=t._zod.bag||{},t._zod.version=tA;let a=t._zod.def.checks,i=t._zod.traits.has("$ZodCheck")?[t,...a??[]]:a?.length?[...a]:[];for(let r of i)for(let o of r._zod.onattach)o(t);if(0===i.length)(o=t._zod).deferred??(o.deferred=[]),t._zod.deferred?.push(()=>{t._zod.run=t._zod.parse});else{let r=(r,o,a)=>{let i;if(r.memo)return r;let n=ev(r);for(let s of o){if(s._zod.def.when){if(function(t,r=0){if(!0===t.aborted)return!0;for(let o=r;o<t.issues.length;o++)if(t.issues[o]?.continue===!1)return!0;return!1}(r)||!s._zod.def.when(r))continue}else if(n)continue;let o=r.issues.length,l=s._zod.check(r);if(l instanceof Promise&&a?.async===!1)throw new eM;if(i||l instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await l,r.issues.length!==o&&(eS(r.issues,o,t),n||(n=ev(r,o)))});else{if(r.issues.length===o)continue;eS(r.issues,o,t),n||(n=ev(r,o))}}return i?i.then(()=>r):r},o=(o,a,n)=>{if(ev(o))return o.aborted=!0,o;let s=r(a,i,n);if(s instanceof Promise){if(!1===n.async)throw new eM;return s.then(r=>t._zod.parse(r,n))}return t._zod.parse(s,n)};t._zod.run=(a,n)=>{if(n.skipChecks)return t._zod.parse(a,n);if("backward"===n.direction){let r=t._zod.parse({value:a.value,issues:[]},{...n,skipChecks:!0});return r instanceof Promise?r.then(t=>o(t,a,n)):o(r,a,n)}let s=t._zod.parse(a,n);if(s instanceof Promise){if(!1===n.async)throw new eM;return s.then(t=>r(t,i,n))}return r(s,i,n)}}},{get"~standard"(){var tO;return tO=this,eR(tO,"~standard",tN(this),!1)},set"~standard"(value){eR(this,"~standard",value)}}),tj=(t,r)=>t.issues.length?{issues:t.issues.map(t=>ew(t,r,eH()))}:{value:t.value};async function tI(t,r){let o={async:!0};return tj(await t._zod.run({value:r,issues:[]},o),o)}function tN(t){return{validate:r=>{let o={async:!1};try{let a=t._zod.run({value:r,issues:[]},o);if(!(a instanceof Promise))return tj(a,o)}catch(t){}return tI(t,r)},vendor:"zod",version:1}}let tM=eN("$ZodString",(t,r)=>{tT.init(t,r),t._zod.pattern=r.pattern??ta,t._zod.parse=(o,a)=>{if(r.coerce)try{o.value=String(o.value)}catch(t){}return"string"==typeof o.value||o.issues.push({expected:"string",code:"invalid_type",input:o.value,inst:t}),o}}),tz=eN("$ZodStringFormat",(t,r)=>{tS.init(t,r),tM.init(t,r)}),tq=eN("$ZodGUID",(t,r)=>{r.pattern??(r.pattern=e1),tz.init(t,r)}),tH=eN("$ZodUUID",(t,r)=>{if(r.version){let t={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[r.version];if(void 0===t)throw Error(`Invalid UUID version: "${r.version}"`);r.pattern??(r.pattern=e2(t))}else r.pattern??(r.pattern=e2());tz.init(t,r)}),tU=eN("$ZodEmail",(t,r)=>{r.pattern??(r.pattern=e9),tz.init(t,r)});function tD(t){try{if("undefined"!=typeof URL&&"function"==typeof URL.canParse)return URL.canParse(t);return new URL(t),!0}catch{return!1}}let tL=/[\t\n\r]/g;function tK(t){return t.replace(tL,"")}let tJ=eN("$ZodURL",(t,r)=>{tz.init(t,r),t._zod.check=o=>{try{var a,i,n,s,l,c;let u=o.value.trim(),d=(a=u,i=r,"normalize"in i||"hostname"in i||"protocol"in i?function(t,r){if(!r.normalize&&r.protocol?.source===e7.source&&!/^https?:\/\//i.test(t))return 1;try{if("undefined"!=typeof URL){let r=URL;if("function"==typeof r.parse)return r.parse(t)??2}return new URL(t)}catch{return 2}}(a,i):tD(a)||2);if(1===d)return void o.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:o.value,inst:t,continue:!r.abort});if(2===d)return void o.issues.push({code:"invalid_format",format:"url",input:o.value,inst:t,continue:!r.abort});if(!0===d){o.value=tK(u);return}r.hostname&&(n=d,(s=r.hostname).lastIndex=0,!s.test(n.hostname))&&o.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:r.hostname.source,input:o.value,inst:t,continue:!r.abort}),r.protocol&&(l=d,(c=r.protocol).lastIndex=0,!c.test(l.protocol.endsWith(":")?l.protocol.slice(0,-1):l.protocol))&&o.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:r.protocol.source,input:o.value,inst:t,continue:!r.abort}),o.value=r.normalize?d.href:tK(u);return}catch(a){o.issues.push({code:"invalid_format",format:"url",input:o.value,inst:t,continue:!r.abort})}}}),tV=eN("$ZodEmoji",(t,r)=>{r.pattern??(r.pattern=RegExp(e4,"u")),tz.init(t,r)}),tW=eN("$ZodNanoID",(t,r)=>{var o;if(void 0!==r.length&&(!Number.isInteger(r.length)||r.length<1))throw Error(`Invalid nanoid length: ${r.length}`);r.pattern??(r.pattern=void 0===r.length?eQ:(o=r.length,RegExp(`^[a-zA-Z0-9_-]{${o}}$`))),tz.init(t,r)}),tF=eN("$ZodCUID",(t,r)=>{r.pattern??(r.pattern=eB),tz.init(t,r)}),tB=eN("$ZodCUID2",(t,r)=>{r.pattern??(r.pattern=eZ),tz.init(t,r)}),tZ=eN("$ZodULID",(t,r)=>{r.pattern??(r.pattern=eG),tz.init(t,r)}),tG=eN("$ZodXID",(t,r)=>{r.pattern??(r.pattern=eX),tz.init(t,r)}),tX=eN("$ZodKSUID",(t,r)=>{r.pattern??(r.pattern=eY),tz.init(t,r)}),tY=eN("$ZodISODateTime",(t,r)=>{var o;let a,i,n;r.pattern??(a=["Z"],(o=r).offset&&a.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)"),i=`${to({precision:o.precision,seconds:!0})}(?:${a.join("|")})`,n=o.local?`${i}|${to({precision:o.precision})}`:i,r.pattern=RegExp(`^${tt}T(?:${n})$`)),tz.init(t,r)}),tQ=eN("$ZodISODate",(t,r)=>{r.pattern??(r.pattern=tr),tz.init(t,r)}),t0=eN("$ZodISOTime",(t,r)=>{var o;r.pattern??(o=r,r.pattern=RegExp(`^${to(o)}$`)),tz.init(t,r)}),t1=eN("$ZodISODuration",(t,r)=>{r.pattern??(r.pattern=e0),tz.init(t,r)}),t2=eN("$ZodIPv4",(t,r)=>{r.pattern??(r.pattern=e5),tz.init(t,r)}),t9=/^[0-9a-fA-F:.]+$/;function t4(t){return!!t9.test(t)&&tD(`http://[${t}]`)}let t5=eN("$ZodIPv6",(t,r)=>{r.pattern??(r.pattern=e3),tz.init(t,r),t._zod.check=o=>{t4(o.value)||o.issues.push({code:"invalid_format",format:"ipv6",input:o.value,inst:t,continue:!r.abort})}}),t3=eN("$ZodCIDRv4",(t,r)=>{r.pattern??(r.pattern=e6),tz.init(t,r)}),t6=eN("$ZodCIDRv6",(t,r)=>{r.pattern??(r.pattern=e8),tz.init(t,r),t._zod.check=o=>{!function(t){let r=t.split("/");if(2!==r.length)return!1;let[o,a]=r;if(!a)return!1;let i=Number(a);return`${i}`===a&&!(i<0)&&!(i>128)&&t4(o)}(o.value)&&o.issues.push({code:"invalid_format",format:"cidrv6",input:o.value,inst:t,continue:!r.abort})}});function t8(t){if(""===t)return!0;if(/\s/.test(t)||t.length%4!=0)return!1;try{return atob(t),!0}catch{return!1}}let t7=/^[0-9a-zA-Z+/]*={0,2}$/,re=eN("$ZodBase64",(t,r)=>{r.pattern??(r.pattern=t7),tz.init(t,r),t._zod.check=o=>{t8(o.value)||o.issues.push({code:"invalid_format",format:"base64",input:o.value,inst:t,continue:!r.abort})}}),rt=/^[A-Za-z0-9_-]*$/,rr=eN("$ZodBase64URL",(t,r)=>{r.pattern??(r.pattern=rt),tz.init(t,r),t._zod.check=o=>{!function(t){if(!rt.test(t))return!1;let r=t.replace(/[-_]/g,t=>"-"===t?"+":"/");return t8(r.padEnd(4*Math.ceil(r.length/4),"="))}(o.value)&&o.issues.push({code:"invalid_format",format:"base64url",input:o.value,inst:t,continue:!r.abort})}}),ro=eN("$ZodE164",(t,r)=>{r.pattern??(r.pattern=te),tz.init(t,r)}),ra=eN("$ZodJWT",(t,r)=>{tz.init(t,r),t._zod.check=o=>{!function(t,r=null){try{let o=t.split(".");if(3!==o.length)return!1;let[a]=o;if(!a)return!1;let i=JSON.parse(atob(a));if("typ"in i&&i?.typ!=="JWT"||!i.alg||r&&(!("alg"in i)||i.alg!==r))return!1;return!0}catch{return!1}}(o.value,r.alg)&&o.issues.push({code:"invalid_format",format:"jwt",input:o.value,inst:t,continue:!r.abort})}}),ri=eN("$ZodNumber",(t,r)=>{tT.init(t,r),t._zod.pattern=tn,t._zod.parse=(o,a)=>{if(r.coerce)try{o.value=Number(o.value)}catch(t){}let i=o.value;if("number"==typeof i&&!Number.isNaN(i)&&Number.isFinite(i))return o;let n="number"==typeof i?Number.isNaN(i)?"NaN":Number.isFinite(i)?void 0:String(i):void 0;return o.issues.push({expected:"number",code:"invalid_type",input:i,inst:t,...n?{received:n}:{}}),o}}),rn=eN("$ZodNumberFormat",(t,r)=>{tg.init(t,r),ri.init(t,r)}),rs=eN("$ZodBoolean",(t,r)=>{tT.init(t,r),t._zod.pattern=ts,t._zod.parse=(o,a)=>{if(r.coerce)try{o.value=!!o.value}catch(t){}let i=o.value;return"boolean"==typeof i||o.issues.push({expected:"boolean",code:"invalid_type",input:i,inst:t}),o}}),rl=eN("$ZodNull",(t,r)=>{tT.init(t,r),t._zod.pattern=tl,t._zod.values=new Set([null]),t._zod.parse=(r,o)=>{let a=r.value;return null===a||r.issues.push({expected:"null",code:"invalid_type",input:a,inst:t}),r}}),rc=eN("$ZodAny",(t,r)=>{tT.init(t,r),t._zod.parse=t=>t}),ru=eN("$ZodUnknown",(t,r)=>{tT.init(t,r),t._zod.parse=t=>t}),rd=eN("$ZodNever",(t,r)=>{tT.init(t,r),t._zod.parse=(r,o)=>(r.issues.push({expected:"never",code:"invalid_type",input:r.value,inst:t}),r)});function rp(t,r,o){t.issues.length&&r.issues.push(...e_(o,t.issues)),r.value[o]=t.value}let rh=eN("$ZodArray",(t,r)=>{tT.init(t,r);let o=eq.memoizer;o?.attach(t),t._zod.parse=(a,i)=>{let n=a.value;if(!Array.isArray(n))return a.issues.push({expected:"array",code:"invalid_type",input:n,inst:t}),a;a.value=o?o.alloc(t,a,Array(n.length),i):Array(n.length);let s=[],l=i?.abortEarly;for(let t=0;t<n.length;t++){let o=n[t],c=r.element._zod.run({value:o,issues:[]},i);if(c instanceof Promise)s.push(c.then(r=>rp(r,a,t)));else if(rp(c,a,t),l&&0!==c.issues.length&&ev(c))break}return s.length?Promise.all(s).then(()=>a):a}});function rf(t,r,o,a,i,n){let s=o in a,l="optional"===n;if(s||!l||"optional"!==i){if(t.issues.length){if(void 0!==i&&l&&!s)return;r.issues.push(...e_(o,t.issues))}if(!s&&void 0===i){t.issues.length||r.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[o]});return}void 0===t.value?(s||"defaulted"===i&&!l)&&(r.value[o]=void 0):r.value[o]=t.value}}let rm=[];function ry(t){var r;let o=Object.keys(t.shape),a=Object.getOwnPropertySymbols(t.shape),i=a.length?a:rm,n=i.length?[...o,...i]:o;for(let r of n)if(!t.shape?.[r]?._zod?.traits?.has("$ZodType"))throw Error(`Invalid element at key "${String(r)}": expected a Zod schema`);let s=Object.keys(r=t.shape).filter(t=>void 0!==r[t]._zod.optin&&"optional"===r[t]._zod.optout);return{...t,allKeys:n,symbolKeys:i,keySet:new Set(o),numKeys:o.length,optionalKeys:new Set(s)}}function rg(t,r,o,a,i,n,s){let l=[],c=i.keySet,u=i.catchall._zod,d=u.def.type,p=u.optin,h=u.optout,f=0;for(let i in r){if(s&&o.issues.length!==f){if(ev(o,f))break;f=o.issues.length}if(c.has(i))continue;if("__proto__"===i){"never"===d&&l.push(i);continue}if("never"===d){l.push(i);continue}let n=u.run({value:r[i],issues:[]},a);n instanceof Promise?t.push(n.then(t=>rf(t,o,i,r,p,h))):rf(n,o,i,r,p,h)}return(l.length&&o.issues.push({code:"unrecognized_keys",keys:l,input:r,inst:n,continue:!0}),t.length)?Promise.all(t).then(()=>o):o}let rv=eN("$ZodObject",(t,r)=>{let o;tT.init(t,r);let a=Object.getOwnPropertyDescriptor(r,"shape"),i=a?.get?a.get.raw:r.shape??{};if(i){let t=()=>{let o={...i};return Object.defineProperty(r,"shape",{value:o}),t.raw=o,o};t.raw=i,Object.defineProperty(r,"shape",{get:t})}let n=F(()=>ry(r));eT(t,"propValues",t=>{let r=t.def.shape,o={};for(let t in r){let a=r[t]._zod;if(a.values){for(let r of(Object.prototype.hasOwnProperty.call(o,t)||G(o,t,new Set),a.values))o[t].add(r);void 0!==a.optin&&o[t].add(void 0)}}return o});let s=r.catchall,l=eq.memoizer;l?.attach(t),t._zod.parse=(r,a)=>{o??(o=n.value);let i=r.value;if(!ea(i))return r.issues.push({expected:"object",code:"invalid_type",input:i,inst:t}),r;r.value=l?l.alloc(t,r,{},a):{};let c=[],u=o.shape,d=a?.abortEarly,p=r.issues.length;for(let t of o.allKeys){if(d&&r.issues.length!==p){if(ev(r,p))break;p=r.issues.length}if("__proto__"===t)continue;let o=u[t],n=o._zod.optin,s=o._zod.optout,l=o._zod.run({value:i[t],issues:[]},a);l instanceof Promise?c.push(l.then(o=>rf(o,r,t,i,n,s))):rf(l,r,t,i,n,s)}return s?rg(c,i,r,a,n.value,t,!0===d):c.length?Promise.all(c).then(()=>r):r}}),r_=eN("$ZodObjectJIT",(t,r)=>{let o,a;rv.init(t,r);let i=t._zod.parse,n=F(()=>ry(r)),s=eq.memoizer,l=!eq.jitless,c=l&&ei.value,u=r.catchall;t._zod.parse=(d,p)=>{a??(a=n.value);let h=d.value;return ea(h)?l&&c&&p?.async===!1&&!0!==p.jitless?(o||(o=(r=>{let o=n.value,a=o.symbolKeys,i=new tC(["payload","ctx"],{shape:r,inst:t,memo:s,syms:a}),l=t=>`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`,c=(t,r)=>`
6
6
  let ${t}_ab = false;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export type { Middleware, WebMiddleware, WebMiddlewareContext, } from "./types/middleware";
2
- export type { McpMiddleware, McpMiddlewareContext, McpMiddlewareMethod, McpMiddlewareNext, McpMiddlewareResult, } from "./types/mcp-middleware";
2
+ export type { McpMiddleware, McpMiddlewareContext, McpMiddlewareMethod, McpMiddlewareNext, McpMiddlewareResult, McpToolMetadata, } from "./types/mcp-middleware";
3
3
  export type { ToolMetadata, ToolSchema, ToolOutputSchema, ToolExtraArguments, InferSchema, ElicitResult, SampleRequest, SampleResult, } from "./types/tool";
4
4
  export type { McpClientInfo } from "./types/client-info";
5
5
  export type { PromptMetadata, PromptMessage, GetPromptResult, } from "./types/prompt";