@ymys/directus-extension-sso 2.5.21 → 2.6.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{createRequire as e}from"module";import r from"node:crypto";import t from"buffer";import n from"stream";import i from"util";import o from"crypto";function s(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var a,c,u,l,f,p,h,d,m,g,y,E,w,b,v,S,$,I,A,R,O,L,T,N,k,x,j,_,P,C,D={},M={exports:{}};function B(){return a||(a=1,function(e,r){var n=t,i=n.Buffer;function o(e,r){for(var t in e)r[t]=e[t]}function s(e,r,t){return i(e,r,t)}i.from&&i.alloc&&i.allocUnsafe&&i.allocUnsafeSlow?e.exports=n:(o(n,r),r.Buffer=s),s.prototype=Object.create(i.prototype),o(i,s),s.from=function(e,r,t){if("number"==typeof e)throw new TypeError("Argument must not be a number");return i(e,r,t)},s.alloc=function(e,r,t){if("number"!=typeof e)throw new TypeError("Argument must be a number");var n=i(e);return void 0!==r?"string"==typeof t?n.fill(r,t):n.fill(r):n.fill(0),n},s.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return i(e)},s.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return n.SlowBuffer(e)}}(M,M.exports)),M.exports}function K(){if(u)return c;u=1;var e=B().Buffer,r=n;function t(r){if(this.buffer=null,this.writable=!0,this.readable=!0,!r)return this.buffer=e.alloc(0),this;if("function"==typeof r.pipe)return this.buffer=e.alloc(0),r.pipe(this),this;if(r.length||"object"==typeof r)return this.buffer=r,this.writable=!1,process.nextTick(function(){this.emit("end",r),this.readable=!1,this.emit("close")}.bind(this)),this;throw new TypeError("Unexpected data type ("+typeof r+")")}return i.inherits(t,r),t.prototype.write=function(r){this.buffer=e.concat([this.buffer,e.from(r)]),this.emit("data",r)},t.prototype.end=function(e){e&&this.write(e),this.emit("end",e),this.emit("close"),this.writable=!1,this.readable=!1},c=t}function F(){if(h)return p;h=1;var e=B().Buffer,r=function(){if(f)return l;function e(e){return(e/8|0)+(e%8==0?0:1)}f=1;var r={ES256:e(256),ES384:e(384),ES512:e(521)};return l=function(e){var t=r[e];if(t)return t;throw new Error('Unknown algorithm "'+e+'"')}}(),t=128;function n(r){if(e.isBuffer(r))return r;if("string"==typeof r)return e.from(r,"base64");throw new TypeError("ECDSA signature must be a Base64 string or a Buffer")}function i(e,r,n){for(var i=0;r+i<n&&0===e[r+i];)++i;return e[r+i]>=t&&--i,i}return p={derToJose:function(t,i){t=n(t);var o=r(i),s=o+1,a=t.length,c=0;if(48!==t[c++])throw new Error('Could not find expected "seq"');var u=t[c++];if(129===u&&(u=t[c++]),a-c<u)throw new Error('"seq" specified length of "'+u+'", only "'+(a-c)+'" remaining');if(2!==t[c++])throw new Error('Could not find expected "int" for "r"');var l=t[c++];if(a-c-2<l)throw new Error('"r" specified length of "'+l+'", only "'+(a-c-2)+'" available');if(s<l)throw new Error('"r" specified length of "'+l+'", max of "'+s+'" is acceptable');var f=c;if(c+=l,2!==t[c++])throw new Error('Could not find expected "int" for "s"');var p=t[c++];if(a-c!==p)throw new Error('"s" specified length of "'+p+'", expected "'+(a-c)+'"');if(s<p)throw new Error('"s" specified length of "'+p+'", max of "'+s+'" is acceptable');var h=c;if((c+=p)!==a)throw new Error('Expected to consume entire buffer, but "'+(a-c)+'" bytes remain');var d=o-l,m=o-p,g=e.allocUnsafe(d+l+m+p);for(c=0;c<d;++c)g[c]=0;t.copy(g,c,f+Math.max(-d,0),f+l);for(var y=c=o;c<y+m;++c)g[c]=0;return t.copy(g,c,h+Math.max(-m,0),h+p),g=(g=g.toString("base64")).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")},joseToDer:function(o,s){o=n(o);var a=r(s),c=o.length;if(c!==2*a)throw new TypeError('"'+s+'" signatures must be "'+2*a+'" bytes, saw "'+c+'"');var u=i(o,0,a),l=i(o,a,o.length),f=a-u,p=a-l,h=2+f+1+1+p,d=h<t,m=e.allocUnsafe((d?2:3)+h),g=0;return m[g++]=48,d?m[g++]=h:(m[g++]=129,m[g++]=255&h),m[g++]=2,m[g++]=f,u<0?(m[g++]=0,g+=o.copy(m,g,0,a)):g+=o.copy(m,g,u,a),m[g++]=2,m[g++]=p,l<0?(m[g++]=0,o.copy(m,g,a)):o.copy(m,g,a+l),m}}}function G(){if(y)return g;y=1;var e,r=B().Buffer,n=o,s=F(),a=i,c="secret must be a string or buffer",u="key must be a string or a buffer",l="function"==typeof n.createPublicKey;function f(e){if(!r.isBuffer(e)&&"string"!=typeof e){if(!l)throw w(u);if("object"!=typeof e)throw w(u);if("string"!=typeof e.type)throw w(u);if("string"!=typeof e.asymmetricKeyType)throw w(u);if("function"!=typeof e.export)throw w(u)}}function p(e){if(!r.isBuffer(e)&&"string"!=typeof e&&"object"!=typeof e)throw w("key must be a string, a buffer or an object")}function h(e){return e.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function E(e){var r=4-(e=e.toString()).length%4;if(4!==r)for(var t=0;t<r;++t)e+="=";return e.replace(/\-/g,"+").replace(/_/g,"/")}function w(e){var r=[].slice.call(arguments,1),t=a.format.bind(a,e).apply(null,r);return new TypeError(t)}function b(e){var t;return t=e,r.isBuffer(t)||"string"==typeof t||(e=JSON.stringify(e)),e}function v(e){return function(t,i){!function(e){if(!r.isBuffer(e)){if("string"==typeof e)return e;if(!l)throw w(c);if("object"!=typeof e)throw w(c);if("secret"!==e.type)throw w(c);if("function"!=typeof e.export)throw w(c)}}(i),t=b(t);var o=n.createHmac("sha"+e,i);return h((o.update(t),o.digest("base64")))}}l&&(u+=" or a KeyObject",c+="or a KeyObject");var S="timingSafeEqual"in n?function(e,r){return e.byteLength===r.byteLength&&n.timingSafeEqual(e,r)}:function(r,n){return e||(e=function(){if(m)return d;m=1;var e=t.Buffer,r=t.SlowBuffer;function n(r,t){if(!e.isBuffer(r)||!e.isBuffer(t))return!1;if(r.length!==t.length)return!1;for(var n=0,i=0;i<r.length;i++)n|=r[i]^t[i];return 0===n}d=n,n.install=function(){e.prototype.equal=r.prototype.equal=function(e){return n(this,e)}};var i=e.prototype.equal,o=r.prototype.equal;return n.restore=function(){e.prototype.equal=i,r.prototype.equal=o},d}()),e(r,n)};function $(e){return function(t,n,i){var o=v(e)(t,i);return S(r.from(n),r.from(o))}}function I(e){return function(r,t){p(t),r=b(r);var i=n.createSign("RSA-SHA"+e);return h((i.update(r),i.sign(t,"base64")))}}function A(e){return function(r,t,i){f(i),r=b(r),t=E(t);var o=n.createVerify("RSA-SHA"+e);return o.update(r),o.verify(i,t,"base64")}}function R(e){return function(r,t){p(t),r=b(r);var i=n.createSign("RSA-SHA"+e);return h((i.update(r),i.sign({key:t,padding:n.constants.RSA_PKCS1_PSS_PADDING,saltLength:n.constants.RSA_PSS_SALTLEN_DIGEST},"base64")))}}function O(e){return function(r,t,i){f(i),r=b(r),t=E(t);var o=n.createVerify("RSA-SHA"+e);return o.update(r),o.verify({key:i,padding:n.constants.RSA_PKCS1_PSS_PADDING,saltLength:n.constants.RSA_PSS_SALTLEN_DIGEST},t,"base64")}}function L(e){var r=I(e);return function(){var t=r.apply(null,arguments);return t=s.derToJose(t,"ES"+e)}}function T(e){var r=A(e);return function(t,n,i){return n=s.joseToDer(n,"ES"+e).toString("base64"),r(t,n,i)}}function N(){return function(){return""}}function k(){return function(e,r){return""===r}}return g=function(e){var r={hs:v,rs:I,ps:R,es:L,none:N},t={hs:$,rs:A,ps:O,es:T,none:k},n=e.match(/^(RS|PS|ES|HS)(256|384|512)$|^(none)$/);if(!n)throw w('"%s" is not a valid algorithm.\n Supported algorithms are:\n "HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "PS256", "PS384", "PS512", "ES256", "ES384", "ES512" and "none".',e);var i=(n[1]||n[3]).toLowerCase(),o=n[2];return{sign:r[i](o),verify:t[i](o)}}}function U(){if(w)return E;w=1;var e=t.Buffer;return E=function(r){return"string"==typeof r?r:"number"==typeof r||e.isBuffer(r)?r.toString():JSON.stringify(r)}}function H(){if(v)return b;v=1;var e=B().Buffer,r=K(),t=G(),o=n,s=U(),a=i;function c(r,t){return e.from(r,t).toString("base64").replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function u(e){var r=e.header,n=e.payload,i=e.secret||e.privateKey,o=e.encoding,u=t(r.alg),l=function(e,r,t){t=t||"utf8";var n=c(s(e),"binary"),i=c(s(r),t);return a.format("%s.%s",n,i)}(r,n,o),f=u.sign(l,i);return a.format("%s.%s",l,f)}function l(e){var t=e.secret;if(t=null==(t=null==t?e.privateKey:t)?e.key:t,!0===/^hs/i.test(e.header.alg)&&null==t)throw new TypeError("secret must be a string or buffer or a KeyObject");var n=new r(t);this.readable=!0,this.header=e.header,this.encoding=e.encoding,this.secret=this.privateKey=this.key=n,this.payload=new r(e.payload),this.secret.once("close",function(){!this.payload.writable&&this.readable&&this.sign()}.bind(this)),this.payload.once("close",function(){!this.secret.writable&&this.readable&&this.sign()}.bind(this))}return a.inherits(l,o),l.prototype.sign=function(){try{var e=u({header:this.header,payload:this.payload.buffer,secret:this.secret.buffer,encoding:this.encoding});return this.emit("done",e),this.emit("data",e),this.emit("end"),this.readable=!1,e}catch(e){this.readable=!1,this.emit("error",e),this.emit("close")}},l.sign=u,b=l}function V(){if($)return S;$=1;var e=B().Buffer,r=K(),t=G(),o=n,s=U(),a=/^[a-zA-Z0-9\-_]+?\.[a-zA-Z0-9\-_]+?\.([a-zA-Z0-9\-_]+)?$/;function c(e){if(function(e){return"[object Object]"===Object.prototype.toString.call(e)}(e))return e;try{return JSON.parse(e)}catch(e){return}}function u(r){var t=r.split(".",1)[0];return c(e.from(t,"base64").toString("binary"))}function l(e){return e.split(".")[2]}function f(e){return a.test(e)&&!!u(e)}function p(e,r,n){if(!r){var i=new Error("Missing algorithm parameter for jws.verify");throw i.code="MISSING_ALGORITHM",i}var o=l(e=s(e)),a=function(e){return e.split(".",2).join(".")}(e);return t(r).verify(a,o,n)}function h(r,t){if(t=t||{},!f(r=s(r)))return null;var n=u(r);if(!n)return null;var i=function(r,t){t=t||"utf8";var n=r.split(".")[1];return e.from(n,"base64").toString(t)}(r);return("JWT"===n.typ||t.json)&&(i=JSON.parse(i,t.encoding)),{header:n,payload:i,signature:l(r)}}function d(e){var t=(e=e||{}).secret;if(t=null==(t=null==t?e.publicKey:t)?e.key:t,!0===/^hs/i.test(e.algorithm)&&null==t)throw new TypeError("secret must be a string or buffer or a KeyObject");var n=new r(t);this.readable=!0,this.algorithm=e.algorithm,this.encoding=e.encoding,this.secret=this.publicKey=this.key=n,this.signature=new r(e.signature),this.secret.once("close",function(){!this.signature.writable&&this.readable&&this.verify()}.bind(this)),this.signature.once("close",function(){!this.secret.writable&&this.readable&&this.verify()}.bind(this))}return i.inherits(d,o),d.prototype.verify=function(){try{var e=p(this.signature.buffer,this.algorithm,this.key.buffer),r=h(this.signature.buffer,this.encoding);return this.emit("done",e,r),this.emit("data",e),this.emit("end"),this.readable=!1,e}catch(e){this.readable=!1,this.emit("error",e),this.emit("close")}},d.decode=h,d.isValid=f,d.verify=p,S=d}function q(){if(I)return D;I=1;var e=H(),r=V();return D.ALGORITHMS=["HS256","HS384","HS512","RS256","RS384","RS512","PS256","PS384","PS512","ES256","ES384","ES512"],D.sign=e.sign,D.verify=r.verify,D.decode=r.decode,D.isValid=r.isValid,D.createSign=function(r){return new e(r)},D.createVerify=function(e){return new r(e)},D}function z(){if(R)return A;R=1;var e=q();return A=function(r,t){t=t||{};var n=e.decode(r,t);if(!n)return null;var i=n.payload;if("string"==typeof i)try{var o=JSON.parse(i);null!==o&&"object"==typeof o&&(i=o)}catch(e){}return!0===t.complete?{header:n.header,payload:i,signature:n.signature}:i},A}function X(){if(L)return O;L=1;var e=function(e,r){Error.call(this,e),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.name="JsonWebTokenError",this.message=e,r&&(this.inner=r)};return(e.prototype=Object.create(Error.prototype)).constructor=e,O=e}function Y(){if(N)return T;N=1;var e=X(),r=function(r,t){e.call(this,r),this.name="NotBeforeError",this.date=t};return(r.prototype=Object.create(e.prototype)).constructor=r,T=r}function W(){if(x)return k;x=1;var e=X(),r=function(r,t){e.call(this,r),this.name="TokenExpiredError",this.expiredAt=t};return(r.prototype=Object.create(e.prototype)).constructor=r,k=r}function J(){if(_)return j;_=1;var e=1e3,r=60*e,t=60*r,n=24*t,i=7*n,o=365.25*n;function s(e,r,t,n){var i=r>=1.5*t;return Math.round(e/t)+" "+n+(i?"s":"")}return j=function(a,c){c=c||{};var u=typeof a;if("string"===u&&a.length>0)return function(s){if((s=String(s)).length>100)return;var a=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(s);if(!a)return;var c=parseFloat(a[1]);switch((a[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return c*o;case"weeks":case"week":case"w":return c*i;case"days":case"day":case"d":return c*n;case"hours":case"hour":case"hrs":case"hr":case"h":return c*t;case"minutes":case"minute":case"mins":case"min":case"m":return c*r;case"seconds":case"second":case"secs":case"sec":case"s":return c*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return c;default:return}}(a);if("number"===u&&isFinite(a))return c.long?function(i){var o=Math.abs(i);if(o>=n)return s(i,o,n,"day");if(o>=t)return s(i,o,t,"hour");if(o>=r)return s(i,o,r,"minute");if(o>=e)return s(i,o,e,"second");return i+" ms"}(a):function(i){var o=Math.abs(i);if(o>=n)return Math.round(i/n)+"d";if(o>=t)return Math.round(i/t)+"h";if(o>=r)return Math.round(i/r)+"m";if(o>=e)return Math.round(i/e)+"s";return i+"ms"}(a);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(a))}}function Z(){if(C)return P;C=1;var e=J();return P=function(r,t){var n=t||Math.floor(Date.now()/1e3);if("string"==typeof r){var i=e(r);if(void 0===i)return;return Math.floor(n+i/1e3)}return"number"==typeof r?n+r:void 0}}var Q,ee,re,te,ne,ie,oe,se,ae,ce,ue,le,fe,pe,he,de,me,ge,ye,Ee,we,be,ve,Se,$e,Ie,Ae,Re,Oe,Le,Te,Ne,ke,xe,je,_e,Pe,Ce,De,Me,Be,Ke,Fe,Ge,Ue,He,Ve,qe,ze,Xe,Ye,We,Je,Ze,Qe,er,rr,tr,nr,ir,or,sr,ar,cr,ur,lr,fr,pr,hr,dr,mr,gr,yr,Er,wr,br,vr,Sr,$r,Ir,Ar,Rr,Or,Lr,Tr,Nr,kr,xr,jr,_r,Pr,Cr,Dr,Mr,Br,Kr,Fr,Gr,Ur,Hr,Vr,qr,zr,Xr,Yr,Wr,Jr,Zr,Qr,et,rt,tt,nt,it,ot,st,at,ct={exports:{}};function ut(){if(ee)return Q;ee=1;const e=Number.MAX_SAFE_INTEGER||9007199254740991;return Q={MAX_LENGTH:256,MAX_SAFE_COMPONENT_LENGTH:16,MAX_SAFE_BUILD_LENGTH:250,MAX_SAFE_INTEGER:e,RELEASE_TYPES:["major","premajor","minor","preminor","patch","prepatch","prerelease"],SEMVER_SPEC_VERSION:"2.0.0",FLAG_INCLUDE_PRERELEASE:1,FLAG_LOOSE:2}}function lt(){if(te)return re;te=1;const e="object"==typeof process&&process.env&&process.env.NODE_DEBUG&&/\bsemver\b/i.test(process.env.NODE_DEBUG)?(...e)=>console.error("SEMVER",...e):()=>{};return re=e}function ft(){return ne||(ne=1,function(e,r){const{MAX_SAFE_COMPONENT_LENGTH:t,MAX_SAFE_BUILD_LENGTH:n,MAX_LENGTH:i}=ut(),o=lt(),s=(r=e.exports={}).re=[],a=r.safeRe=[],c=r.src=[],u=r.safeSrc=[],l=r.t={};let f=0;const p="[a-zA-Z0-9-]",h=[["\\s",1],["\\d",i],[p,n]],d=(e,r,t)=>{const n=(e=>{for(const[r,t]of h)e=e.split(`${r}*`).join(`${r}{0,${t}}`).split(`${r}+`).join(`${r}{1,${t}}`);return e})(r),i=f++;o(e,i,r),l[e]=i,c[i]=r,u[i]=n,s[i]=new RegExp(r,t?"g":void 0),a[i]=new RegExp(n,t?"g":void 0)};d("NUMERICIDENTIFIER","0|[1-9]\\d*"),d("NUMERICIDENTIFIERLOOSE","\\d+"),d("NONNUMERICIDENTIFIER",`\\d*[a-zA-Z-]${p}*`),d("MAINVERSION",`(${c[l.NUMERICIDENTIFIER]})\\.(${c[l.NUMERICIDENTIFIER]})\\.(${c[l.NUMERICIDENTIFIER]})`),d("MAINVERSIONLOOSE",`(${c[l.NUMERICIDENTIFIERLOOSE]})\\.(${c[l.NUMERICIDENTIFIERLOOSE]})\\.(${c[l.NUMERICIDENTIFIERLOOSE]})`),d("PRERELEASEIDENTIFIER",`(?:${c[l.NONNUMERICIDENTIFIER]}|${c[l.NUMERICIDENTIFIER]})`),d("PRERELEASEIDENTIFIERLOOSE",`(?:${c[l.NONNUMERICIDENTIFIER]}|${c[l.NUMERICIDENTIFIERLOOSE]})`),d("PRERELEASE",`(?:-(${c[l.PRERELEASEIDENTIFIER]}(?:\\.${c[l.PRERELEASEIDENTIFIER]})*))`),d("PRERELEASELOOSE",`(?:-?(${c[l.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${c[l.PRERELEASEIDENTIFIERLOOSE]})*))`),d("BUILDIDENTIFIER",`${p}+`),d("BUILD",`(?:\\+(${c[l.BUILDIDENTIFIER]}(?:\\.${c[l.BUILDIDENTIFIER]})*))`),d("FULLPLAIN",`v?${c[l.MAINVERSION]}${c[l.PRERELEASE]}?${c[l.BUILD]}?`),d("FULL",`^${c[l.FULLPLAIN]}$`),d("LOOSEPLAIN",`[v=\\s]*${c[l.MAINVERSIONLOOSE]}${c[l.PRERELEASELOOSE]}?${c[l.BUILD]}?`),d("LOOSE",`^${c[l.LOOSEPLAIN]}$`),d("GTLT","((?:<|>)?=?)"),d("XRANGEIDENTIFIERLOOSE",`${c[l.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`),d("XRANGEIDENTIFIER",`${c[l.NUMERICIDENTIFIER]}|x|X|\\*`),d("XRANGEPLAIN",`[v=\\s]*(${c[l.XRANGEIDENTIFIER]})(?:\\.(${c[l.XRANGEIDENTIFIER]})(?:\\.(${c[l.XRANGEIDENTIFIER]})(?:${c[l.PRERELEASE]})?${c[l.BUILD]}?)?)?`),d("XRANGEPLAINLOOSE",`[v=\\s]*(${c[l.XRANGEIDENTIFIERLOOSE]})(?:\\.(${c[l.XRANGEIDENTIFIERLOOSE]})(?:\\.(${c[l.XRANGEIDENTIFIERLOOSE]})(?:${c[l.PRERELEASELOOSE]})?${c[l.BUILD]}?)?)?`),d("XRANGE",`^${c[l.GTLT]}\\s*${c[l.XRANGEPLAIN]}$`),d("XRANGELOOSE",`^${c[l.GTLT]}\\s*${c[l.XRANGEPLAINLOOSE]}$`),d("COERCEPLAIN",`(^|[^\\d])(\\d{1,${t}})(?:\\.(\\d{1,${t}}))?(?:\\.(\\d{1,${t}}))?`),d("COERCE",`${c[l.COERCEPLAIN]}(?:$|[^\\d])`),d("COERCEFULL",c[l.COERCEPLAIN]+`(?:${c[l.PRERELEASE]})?`+`(?:${c[l.BUILD]})?(?:$|[^\\d])`),d("COERCERTL",c[l.COERCE],!0),d("COERCERTLFULL",c[l.COERCEFULL],!0),d("LONETILDE","(?:~>?)"),d("TILDETRIM",`(\\s*)${c[l.LONETILDE]}\\s+`,!0),r.tildeTrimReplace="$1~",d("TILDE",`^${c[l.LONETILDE]}${c[l.XRANGEPLAIN]}$`),d("TILDELOOSE",`^${c[l.LONETILDE]}${c[l.XRANGEPLAINLOOSE]}$`),d("LONECARET","(?:\\^)"),d("CARETTRIM",`(\\s*)${c[l.LONECARET]}\\s+`,!0),r.caretTrimReplace="$1^",d("CARET",`^${c[l.LONECARET]}${c[l.XRANGEPLAIN]}$`),d("CARETLOOSE",`^${c[l.LONECARET]}${c[l.XRANGEPLAINLOOSE]}$`),d("COMPARATORLOOSE",`^${c[l.GTLT]}\\s*(${c[l.LOOSEPLAIN]})$|^$`),d("COMPARATOR",`^${c[l.GTLT]}\\s*(${c[l.FULLPLAIN]})$|^$`),d("COMPARATORTRIM",`(\\s*)${c[l.GTLT]}\\s*(${c[l.LOOSEPLAIN]}|${c[l.XRANGEPLAIN]})`,!0),r.comparatorTrimReplace="$1$2$3",d("HYPHENRANGE",`^\\s*(${c[l.XRANGEPLAIN]})\\s+-\\s+(${c[l.XRANGEPLAIN]})\\s*$`),d("HYPHENRANGELOOSE",`^\\s*(${c[l.XRANGEPLAINLOOSE]})\\s+-\\s+(${c[l.XRANGEPLAINLOOSE]})\\s*$`),d("STAR","(<|>)?=?\\s*\\*"),d("GTE0","^\\s*>=\\s*0\\.0\\.0\\s*$"),d("GTE0PRE","^\\s*>=\\s*0\\.0\\.0-0\\s*$")}(ct,ct.exports)),ct.exports}function pt(){if(oe)return ie;oe=1;const e=Object.freeze({loose:!0}),r=Object.freeze({});return ie=t=>t?"object"!=typeof t?e:t:r}function ht(){if(ae)return se;ae=1;const e=/^[0-9]+$/,r=(r,t)=>{if("number"==typeof r&&"number"==typeof t)return r===t?0:r<t?-1:1;const n=e.test(r),i=e.test(t);return n&&i&&(r=+r,t=+t),r===t?0:n&&!i?-1:i&&!n?1:r<t?-1:1};return se={compareIdentifiers:r,rcompareIdentifiers:(e,t)=>r(t,e)}}function dt(){if(ue)return ce;ue=1;const e=lt(),{MAX_LENGTH:r,MAX_SAFE_INTEGER:t}=ut(),{safeRe:n,t:i}=ft(),o=pt(),{compareIdentifiers:s}=ht();class a{constructor(s,c){if(c=o(c),s instanceof a){if(s.loose===!!c.loose&&s.includePrerelease===!!c.includePrerelease)return s;s=s.version}else if("string"!=typeof s)throw new TypeError(`Invalid version. Must be a string. Got type "${typeof s}".`);if(s.length>r)throw new TypeError(`version is longer than ${r} characters`);e("SemVer",s,c),this.options=c,this.loose=!!c.loose,this.includePrerelease=!!c.includePrerelease;const u=s.trim().match(c.loose?n[i.LOOSE]:n[i.FULL]);if(!u)throw new TypeError(`Invalid Version: ${s}`);if(this.raw=s,this.major=+u[1],this.minor=+u[2],this.patch=+u[3],this.major>t||this.major<0)throw new TypeError("Invalid major version");if(this.minor>t||this.minor<0)throw new TypeError("Invalid minor version");if(this.patch>t||this.patch<0)throw new TypeError("Invalid patch version");u[4]?this.prerelease=u[4].split(".").map(e=>{if(/^[0-9]+$/.test(e)){const r=+e;if(r>=0&&r<t)return r}return e}):this.prerelease=[],this.build=u[5]?u[5].split("."):[],this.format()}format(){return this.version=`${this.major}.${this.minor}.${this.patch}`,this.prerelease.length&&(this.version+=`-${this.prerelease.join(".")}`),this.version}toString(){return this.version}compare(r){if(e("SemVer.compare",this.version,this.options,r),!(r instanceof a)){if("string"==typeof r&&r===this.version)return 0;r=new a(r,this.options)}return r.version===this.version?0:this.compareMain(r)||this.comparePre(r)}compareMain(e){return e instanceof a||(e=new a(e,this.options)),this.major<e.major?-1:this.major>e.major?1:this.minor<e.minor?-1:this.minor>e.minor?1:this.patch<e.patch?-1:this.patch>e.patch?1:0}comparePre(r){if(r instanceof a||(r=new a(r,this.options)),this.prerelease.length&&!r.prerelease.length)return-1;if(!this.prerelease.length&&r.prerelease.length)return 1;if(!this.prerelease.length&&!r.prerelease.length)return 0;let t=0;do{const n=this.prerelease[t],i=r.prerelease[t];if(e("prerelease compare",t,n,i),void 0===n&&void 0===i)return 0;if(void 0===i)return 1;if(void 0===n)return-1;if(n!==i)return s(n,i)}while(++t)}compareBuild(r){r instanceof a||(r=new a(r,this.options));let t=0;do{const n=this.build[t],i=r.build[t];if(e("build compare",t,n,i),void 0===n&&void 0===i)return 0;if(void 0===i)return 1;if(void 0===n)return-1;if(n!==i)return s(n,i)}while(++t)}inc(e,r,t){if(e.startsWith("pre")){if(!r&&!1===t)throw new Error("invalid increment argument: identifier is empty");if(r){const e=`-${r}`.match(this.options.loose?n[i.PRERELEASELOOSE]:n[i.PRERELEASE]);if(!e||e[1]!==r)throw new Error(`invalid identifier: ${r}`)}}switch(e){case"premajor":this.prerelease.length=0,this.patch=0,this.minor=0,this.major++,this.inc("pre",r,t);break;case"preminor":this.prerelease.length=0,this.patch=0,this.minor++,this.inc("pre",r,t);break;case"prepatch":this.prerelease.length=0,this.inc("patch",r,t),this.inc("pre",r,t);break;case"prerelease":0===this.prerelease.length&&this.inc("patch",r,t),this.inc("pre",r,t);break;case"release":if(0===this.prerelease.length)throw new Error(`version ${this.raw} is not a prerelease`);this.prerelease.length=0;break;case"major":0===this.minor&&0===this.patch&&0!==this.prerelease.length||this.major++,this.minor=0,this.patch=0,this.prerelease=[];break;case"minor":0===this.patch&&0!==this.prerelease.length||this.minor++,this.patch=0,this.prerelease=[];break;case"patch":0===this.prerelease.length&&this.patch++,this.prerelease=[];break;case"pre":{const e=Number(t)?1:0;if(0===this.prerelease.length)this.prerelease=[e];else{let n=this.prerelease.length;for(;--n>=0;)"number"==typeof this.prerelease[n]&&(this.prerelease[n]++,n=-2);if(-1===n){if(r===this.prerelease.join(".")&&!1===t)throw new Error("invalid increment argument: identifier already exists");this.prerelease.push(e)}}if(r){let n=[r,e];!1===t&&(n=[r]),0===s(this.prerelease[0],r)?isNaN(this.prerelease[1])&&(this.prerelease=n):this.prerelease=n}break}default:throw new Error(`invalid increment argument: ${e}`)}return this.raw=this.format(),this.build.length&&(this.raw+=`+${this.build.join(".")}`),this}}return ce=a}function mt(){if(fe)return le;fe=1;const e=dt();return le=(r,t,n=!1)=>{if(r instanceof e)return r;try{return new e(r,t)}catch(e){if(!n)return null;throw e}},le}function gt(){if(Te)return Le;Te=1;const e=dt();return Le=(r,t,n)=>new e(r,n).compare(new e(t,n))}function yt(){if(Pe)return _e;Pe=1;const e=dt();return _e=(r,t,n)=>{const i=new e(r,n),o=new e(t,n);return i.compare(o)||i.compareBuild(o)}}function Et(){if(Fe)return Ke;Fe=1;const e=gt();return Ke=(r,t,n)=>e(r,t,n)>0}function wt(){if(Ue)return Ge;Ue=1;const e=gt();return Ge=(r,t,n)=>e(r,t,n)<0}function bt(){if(Ve)return He;Ve=1;const e=gt();return He=(r,t,n)=>0===e(r,t,n)}function vt(){if(ze)return qe;ze=1;const e=gt();return qe=(r,t,n)=>0!==e(r,t,n)}function St(){if(Ye)return Xe;Ye=1;const e=gt();return Xe=(r,t,n)=>e(r,t,n)>=0}function $t(){if(Je)return We;Je=1;const e=gt();return We=(r,t,n)=>e(r,t,n)<=0}function It(){if(Qe)return Ze;Qe=1;const e=bt(),r=vt(),t=Et(),n=St(),i=wt(),o=$t();return Ze=(s,a,c,u)=>{switch(a){case"===":return"object"==typeof s&&(s=s.version),"object"==typeof c&&(c=c.version),s===c;case"!==":return"object"==typeof s&&(s=s.version),"object"==typeof c&&(c=c.version),s!==c;case"":case"=":case"==":return e(s,c,u);case"!=":return r(s,c,u);case">":return t(s,c,u);case">=":return n(s,c,u);case"<":return i(s,c,u);case"<=":return o(s,c,u);default:throw new TypeError(`Invalid operator: ${a}`)}}}function At(){if(or)return ir;or=1;const e=/\s+/g;class r{constructor(t,o){if(o=n(o),t instanceof r)return t.loose===!!o.loose&&t.includePrerelease===!!o.includePrerelease?t:new r(t.raw,o);if(t instanceof i)return this.raw=t.value,this.set=[[t]],this.formatted=void 0,this;if(this.options=o,this.loose=!!o.loose,this.includePrerelease=!!o.includePrerelease,this.raw=t.trim().replace(e," "),this.set=this.raw.split("||").map(e=>this.parseRange(e.trim())).filter(e=>e.length),!this.set.length)throw new TypeError(`Invalid SemVer Range: ${this.raw}`);if(this.set.length>1){const e=this.set[0];if(this.set=this.set.filter(e=>!d(e[0])),0===this.set.length)this.set=[e];else if(this.set.length>1)for(const e of this.set)if(1===e.length&&m(e[0])){this.set=[e];break}}this.formatted=void 0}get range(){if(void 0===this.formatted){this.formatted="";for(let e=0;e<this.set.length;e++){e>0&&(this.formatted+="||");const r=this.set[e];for(let e=0;e<r.length;e++)e>0&&(this.formatted+=" "),this.formatted+=r[e].toString().trim()}}return this.formatted}format(){return this.range}toString(){return this.range}parseRange(e){const r=((this.options.includePrerelease&&p)|(this.options.loose&&h))+":"+e,n=t.get(r);if(n)return n;const s=this.options.loose,m=s?a[c.HYPHENRANGELOOSE]:a[c.HYPHENRANGE];e=e.replace(m,O(this.options.includePrerelease)),o("hyphen replace",e),e=e.replace(a[c.COMPARATORTRIM],u),o("comparator trim",e),e=e.replace(a[c.TILDETRIM],l),o("tilde trim",e),e=e.replace(a[c.CARETTRIM],f),o("caret trim",e);let g=e.split(" ").map(e=>y(e,this.options)).join(" ").split(/\s+/).map(e=>R(e,this.options));s&&(g=g.filter(e=>(o("loose invalid filter",e,this.options),!!e.match(a[c.COMPARATORLOOSE])))),o("range list",g);const E=new Map,w=g.map(e=>new i(e,this.options));for(const e of w){if(d(e))return[e];E.set(e.value,e)}E.size>1&&E.has("")&&E.delete("");const b=[...E.values()];return t.set(r,b),b}intersects(e,t){if(!(e instanceof r))throw new TypeError("a Range is required");return this.set.some(r=>g(r,t)&&e.set.some(e=>g(e,t)&&r.every(r=>e.every(e=>r.intersects(e,t)))))}test(e){if(!e)return!1;if("string"==typeof e)try{e=new s(e,this.options)}catch(e){return!1}for(let r=0;r<this.set.length;r++)if(L(this.set[r],e,this.options))return!0;return!1}}ir=r;const t=new(nr?tr:(nr=1,tr=class{constructor(){this.max=1e3,this.map=new Map}get(e){const r=this.map.get(e);return void 0===r?void 0:(this.map.delete(e),this.map.set(e,r),r)}delete(e){return this.map.delete(e)}set(e,r){if(!this.delete(e)&&void 0!==r){if(this.map.size>=this.max){const e=this.map.keys().next().value;this.delete(e)}this.map.set(e,r)}return this}})),n=pt(),i=Rt(),o=lt(),s=dt(),{safeRe:a,t:c,comparatorTrimReplace:u,tildeTrimReplace:l,caretTrimReplace:f}=ft(),{FLAG_INCLUDE_PRERELEASE:p,FLAG_LOOSE:h}=ut(),d=e=>"<0.0.0-0"===e.value,m=e=>""===e.value,g=(e,r)=>{let t=!0;const n=e.slice();let i=n.pop();for(;t&&n.length;)t=n.every(e=>i.intersects(e,r)),i=n.pop();return t},y=(e,r)=>(e=e.replace(a[c.BUILD],""),o("comp",e,r),e=v(e,r),o("caret",e),e=w(e,r),o("tildes",e),e=$(e,r),o("xrange",e),e=A(e,r),o("stars",e),e),E=e=>!e||"x"===e.toLowerCase()||"*"===e,w=(e,r)=>e.trim().split(/\s+/).map(e=>b(e,r)).join(" "),b=(e,r)=>{const t=r.loose?a[c.TILDELOOSE]:a[c.TILDE];return e.replace(t,(r,t,n,i,s)=>{let a;return o("tilde",e,r,t,n,i,s),E(t)?a="":E(n)?a=`>=${t}.0.0 <${+t+1}.0.0-0`:E(i)?a=`>=${t}.${n}.0 <${t}.${+n+1}.0-0`:s?(o("replaceTilde pr",s),a=`>=${t}.${n}.${i}-${s} <${t}.${+n+1}.0-0`):a=`>=${t}.${n}.${i} <${t}.${+n+1}.0-0`,o("tilde return",a),a})},v=(e,r)=>e.trim().split(/\s+/).map(e=>S(e,r)).join(" "),S=(e,r)=>{o("caret",e,r);const t=r.loose?a[c.CARETLOOSE]:a[c.CARET],n=r.includePrerelease?"-0":"";return e.replace(t,(r,t,i,s,a)=>{let c;return o("caret",e,r,t,i,s,a),E(t)?c="":E(i)?c=`>=${t}.0.0${n} <${+t+1}.0.0-0`:E(s)?c="0"===t?`>=${t}.${i}.0${n} <${t}.${+i+1}.0-0`:`>=${t}.${i}.0${n} <${+t+1}.0.0-0`:a?(o("replaceCaret pr",a),c="0"===t?"0"===i?`>=${t}.${i}.${s}-${a} <${t}.${i}.${+s+1}-0`:`>=${t}.${i}.${s}-${a} <${t}.${+i+1}.0-0`:`>=${t}.${i}.${s}-${a} <${+t+1}.0.0-0`):(o("no pr"),c="0"===t?"0"===i?`>=${t}.${i}.${s}${n} <${t}.${i}.${+s+1}-0`:`>=${t}.${i}.${s}${n} <${t}.${+i+1}.0-0`:`>=${t}.${i}.${s} <${+t+1}.0.0-0`),o("caret return",c),c})},$=(e,r)=>(o("replaceXRanges",e,r),e.split(/\s+/).map(e=>I(e,r)).join(" ")),I=(e,r)=>{e=e.trim();const t=r.loose?a[c.XRANGELOOSE]:a[c.XRANGE];return e.replace(t,(t,n,i,s,a,c)=>{o("xRange",e,t,n,i,s,a,c);const u=E(i),l=u||E(s),f=l||E(a),p=f;return"="===n&&p&&(n=""),c=r.includePrerelease?"-0":"",u?t=">"===n||"<"===n?"<0.0.0-0":"*":n&&p?(l&&(s=0),a=0,">"===n?(n=">=",l?(i=+i+1,s=0,a=0):(s=+s+1,a=0)):"<="===n&&(n="<",l?i=+i+1:s=+s+1),"<"===n&&(c="-0"),t=`${n+i}.${s}.${a}${c}`):l?t=`>=${i}.0.0${c} <${+i+1}.0.0-0`:f&&(t=`>=${i}.${s}.0${c} <${i}.${+s+1}.0-0`),o("xRange return",t),t})},A=(e,r)=>(o("replaceStars",e,r),e.trim().replace(a[c.STAR],"")),R=(e,r)=>(o("replaceGTE0",e,r),e.trim().replace(a[r.includePrerelease?c.GTE0PRE:c.GTE0],"")),O=e=>(r,t,n,i,o,s,a,c,u,l,f,p)=>`${t=E(n)?"":E(i)?`>=${n}.0.0${e?"-0":""}`:E(o)?`>=${n}.${i}.0${e?"-0":""}`:s?`>=${t}`:`>=${t}${e?"-0":""}`} ${c=E(u)?"":E(l)?`<${+u+1}.0.0-0`:E(f)?`<${u}.${+l+1}.0-0`:p?`<=${u}.${l}.${f}-${p}`:e?`<${u}.${l}.${+f+1}-0`:`<=${c}`}`.trim(),L=(e,r,t)=>{for(let t=0;t<e.length;t++)if(!e[t].test(r))return!1;if(r.prerelease.length&&!t.includePrerelease){for(let t=0;t<e.length;t++)if(o(e[t].semver),e[t].semver!==i.ANY&&e[t].semver.prerelease.length>0){const n=e[t].semver;if(n.major===r.major&&n.minor===r.minor&&n.patch===r.patch)return!0}return!1}return!0};return ir}function Rt(){if(ar)return sr;ar=1;const e=Symbol("SemVer ANY");class r{static get ANY(){return e}constructor(n,i){if(i=t(i),n instanceof r){if(n.loose===!!i.loose)return n;n=n.value}n=n.trim().split(/\s+/).join(" "),s("comparator",n,i),this.options=i,this.loose=!!i.loose,this.parse(n),this.semver===e?this.value="":this.value=this.operator+this.semver.version,s("comp",this)}parse(r){const t=this.options.loose?n[i.COMPARATORLOOSE]:n[i.COMPARATOR],o=r.match(t);if(!o)throw new TypeError(`Invalid comparator: ${r}`);this.operator=void 0!==o[1]?o[1]:"","="===this.operator&&(this.operator=""),o[2]?this.semver=new a(o[2],this.options.loose):this.semver=e}toString(){return this.value}test(r){if(s("Comparator.test",r,this.options.loose),this.semver===e||r===e)return!0;if("string"==typeof r)try{r=new a(r,this.options)}catch(e){return!1}return o(r,this.operator,this.semver,this.options)}intersects(e,n){if(!(e instanceof r))throw new TypeError("a Comparator is required");return""===this.operator?""===this.value||new c(e.value,n).test(this.value):""===e.operator?""===e.value||new c(this.value,n).test(e.semver):(!(n=t(n)).includePrerelease||"<0.0.0-0"!==this.value&&"<0.0.0-0"!==e.value)&&(!(!n.includePrerelease&&(this.value.startsWith("<0.0.0")||e.value.startsWith("<0.0.0")))&&(!(!this.operator.startsWith(">")||!e.operator.startsWith(">"))||(!(!this.operator.startsWith("<")||!e.operator.startsWith("<"))||(!(this.semver.version!==e.semver.version||!this.operator.includes("=")||!e.operator.includes("="))||(!!(o(this.semver,"<",e.semver,n)&&this.operator.startsWith(">")&&e.operator.startsWith("<"))||!!(o(this.semver,">",e.semver,n)&&this.operator.startsWith("<")&&e.operator.startsWith(">")))))))}}sr=r;const t=pt(),{safeRe:n,t:i}=ft(),o=It(),s=lt(),a=dt(),c=At();return sr}function Ot(){if(ur)return cr;ur=1;const e=At();return cr=(r,t,n)=>{try{t=new e(t,n)}catch(e){return!1}return t.test(r)},cr}function Lt(){if(wr)return Er;wr=1;const e=At();return Er=(r,t)=>{try{return new e(r,t).range||"*"}catch(e){return null}},Er}function Tt(){if(vr)return br;vr=1;const e=dt(),r=Rt(),{ANY:t}=r,n=At(),i=Ot(),o=Et(),s=wt(),a=$t(),c=St();return br=(u,l,f,p)=>{let h,d,m,g,y;switch(u=new e(u,p),l=new n(l,p),f){case">":h=o,d=a,m=s,g=">",y=">=";break;case"<":h=s,d=c,m=o,g="<",y="<=";break;default:throw new TypeError('Must provide a hilo val of "<" or ">"')}if(i(u,l,p))return!1;for(let e=0;e<l.set.length;++e){const n=l.set[e];let i=null,o=null;if(n.forEach(e=>{e.semver===t&&(e=new r(">=0.0.0")),i=i||e,o=o||e,h(e.semver,i.semver,p)?i=e:m(e.semver,o.semver,p)&&(o=e)}),i.operator===g||i.operator===y)return!1;if((!o.operator||o.operator===g)&&d(u,o.semver))return!1;if(o.operator===y&&m(u,o.semver))return!1}return!0},br}function Nt(){if(jr)return xr;jr=1;const e=ft(),r=ut(),t=dt(),n=ht(),i=mt(),o=function(){if(he)return pe;he=1;const e=mt();return pe=(r,t)=>{const n=e(r,t);return n?n.version:null},pe}(),s=function(){if(me)return de;me=1;const e=mt();return de=(r,t)=>{const n=e(r.trim().replace(/^[=v]+/,""),t);return n?n.version:null},de}(),a=function(){if(ye)return ge;ye=1;const e=dt();return ge=(r,t,n,i,o)=>{"string"==typeof n&&(o=i,i=n,n=void 0);try{return new e(r instanceof e?r.version:r,n).inc(t,i,o).version}catch(e){return null}},ge}(),c=function(){if(we)return Ee;we=1;const e=mt();return Ee=(r,t)=>{const n=e(r,null,!0),i=e(t,null,!0),o=n.compare(i);if(0===o)return null;const s=o>0,a=s?n:i,c=s?i:n,u=!!a.prerelease.length;if(c.prerelease.length&&!u){if(!c.patch&&!c.minor)return"major";if(0===c.compareMain(a))return c.minor&&!c.patch?"minor":"patch"}const l=u?"pre":"";return n.major!==i.major?l+"major":n.minor!==i.minor?l+"minor":n.patch!==i.patch?l+"patch":"prerelease"}}(),u=function(){if(ve)return be;ve=1;const e=dt();return be=(r,t)=>new e(r,t).major}(),l=function(){if($e)return Se;$e=1;const e=dt();return Se=(r,t)=>new e(r,t).minor}(),f=function(){if(Ae)return Ie;Ae=1;const e=dt();return Ie=(r,t)=>new e(r,t).patch}(),p=function(){if(Oe)return Re;Oe=1;const e=mt();return Re=(r,t)=>{const n=e(r,t);return n&&n.prerelease.length?n.prerelease:null},Re}(),h=gt(),d=function(){if(ke)return Ne;ke=1;const e=gt();return Ne=(r,t,n)=>e(t,r,n)}(),m=function(){if(je)return xe;je=1;const e=gt();return xe=(r,t)=>e(r,t,!0)}(),g=yt(),y=function(){if(De)return Ce;De=1;const e=yt();return Ce=(r,t)=>r.sort((r,n)=>e(r,n,t))}(),E=function(){if(Be)return Me;Be=1;const e=yt();return Me=(r,t)=>r.sort((r,n)=>e(n,r,t))}(),w=Et(),b=wt(),v=bt(),S=vt(),$=St(),I=$t(),A=It(),R=function(){if(rr)return er;rr=1;const e=dt(),r=mt(),{safeRe:t,t:n}=ft();return er=(i,o)=>{if(i instanceof e)return i;if("number"==typeof i&&(i=String(i)),"string"!=typeof i)return null;let s=null;if((o=o||{}).rtl){const e=o.includePrerelease?t[n.COERCERTLFULL]:t[n.COERCERTL];let r;for(;(r=e.exec(i))&&(!s||s.index+s[0].length!==i.length);)s&&r.index+r[0].length===s.index+s[0].length||(s=r),e.lastIndex=r.index+r[1].length+r[2].length;e.lastIndex=-1}else s=i.match(o.includePrerelease?t[n.COERCEFULL]:t[n.COERCE]);if(null===s)return null;const a=s[2],c=s[3]||"0",u=s[4]||"0",l=o.includePrerelease&&s[5]?`-${s[5]}`:"",f=o.includePrerelease&&s[6]?`+${s[6]}`:"";return r(`${a}.${c}.${u}${l}${f}`,o)},er}(),O=Rt(),L=At(),T=Ot(),N=function(){if(fr)return lr;fr=1;const e=At();return lr=(r,t)=>new e(r,t).set.map(e=>e.map(e=>e.value).join(" ").trim().split(" ")),lr}(),k=function(){if(hr)return pr;hr=1;const e=dt(),r=At();return pr=(t,n,i)=>{let o=null,s=null,a=null;try{a=new r(n,i)}catch(e){return null}return t.forEach(r=>{a.test(r)&&(o&&-1!==s.compare(r)||(o=r,s=new e(o,i)))}),o},pr}(),x=function(){if(mr)return dr;mr=1;const e=dt(),r=At();return dr=(t,n,i)=>{let o=null,s=null,a=null;try{a=new r(n,i)}catch(e){return null}return t.forEach(r=>{a.test(r)&&(o&&1!==s.compare(r)||(o=r,s=new e(o,i)))}),o},dr}(),j=function(){if(yr)return gr;yr=1;const e=dt(),r=At(),t=Et();return gr=(n,i)=>{n=new r(n,i);let o=new e("0.0.0");if(n.test(o))return o;if(o=new e("0.0.0-0"),n.test(o))return o;o=null;for(let r=0;r<n.set.length;++r){const i=n.set[r];let s=null;i.forEach(r=>{const n=new e(r.semver.version);switch(r.operator){case">":0===n.prerelease.length?n.patch++:n.prerelease.push(0),n.raw=n.format();case"":case">=":s&&!t(n,s)||(s=n);break;case"<":case"<=":break;default:throw new Error(`Unexpected operation: ${r.operator}`)}}),!s||o&&!t(o,s)||(o=s)}return o&&n.test(o)?o:null},gr}(),_=Lt(),P=Tt(),C=function(){if($r)return Sr;$r=1;const e=Tt();return Sr=(r,t,n)=>e(r,t,">",n),Sr}(),D=function(){if(Ar)return Ir;Ar=1;const e=Tt();return Ir=(r,t,n)=>e(r,t,"<",n),Ir}(),M=function(){if(Or)return Rr;Or=1;const e=At();return Rr=(r,t,n)=>(r=new e(r,n),t=new e(t,n),r.intersects(t,n))}(),B=function(){if(Tr)return Lr;Tr=1;const e=Ot(),r=gt();return Lr=(t,n,i)=>{const o=[];let s=null,a=null;const c=t.sort((e,t)=>r(e,t,i));for(const r of c)e(r,n,i)?(a=r,s||(s=r)):(a&&o.push([s,a]),a=null,s=null);s&&o.push([s,null]);const u=[];for(const[e,r]of o)e===r?u.push(e):r||e!==c[0]?r?e===c[0]?u.push(`<=${r}`):u.push(`${e} - ${r}`):u.push(`>=${e}`):u.push("*");const l=u.join(" || "),f="string"==typeof n.raw?n.raw:String(n);return l.length<f.length?l:n},Lr}(),K=function(){if(kr)return Nr;kr=1;const e=At(),r=Rt(),{ANY:t}=r,n=Ot(),i=gt(),o=[new r(">=0.0.0-0")],s=[new r(">=0.0.0")],a=(e,r,a)=>{if(e===r)return!0;if(1===e.length&&e[0].semver===t){if(1===r.length&&r[0].semver===t)return!0;e=a.includePrerelease?o:s}if(1===r.length&&r[0].semver===t){if(a.includePrerelease)return!0;r=s}const l=new Set;let f,p,h,d,m,g,y;for(const r of e)">"===r.operator||">="===r.operator?f=c(f,r,a):"<"===r.operator||"<="===r.operator?p=u(p,r,a):l.add(r.semver);if(l.size>1)return null;if(f&&p){if(h=i(f.semver,p.semver,a),h>0)return null;if(0===h&&(">="!==f.operator||"<="!==p.operator))return null}for(const e of l){if(f&&!n(e,String(f),a))return null;if(p&&!n(e,String(p),a))return null;for(const t of r)if(!n(e,String(t),a))return!1;return!0}let E=!(!p||a.includePrerelease||!p.semver.prerelease.length)&&p.semver,w=!(!f||a.includePrerelease||!f.semver.prerelease.length)&&f.semver;E&&1===E.prerelease.length&&"<"===p.operator&&0===E.prerelease[0]&&(E=!1);for(const e of r){if(y=y||">"===e.operator||">="===e.operator,g=g||"<"===e.operator||"<="===e.operator,f)if(w&&e.semver.prerelease&&e.semver.prerelease.length&&e.semver.major===w.major&&e.semver.minor===w.minor&&e.semver.patch===w.patch&&(w=!1),">"===e.operator||">="===e.operator){if(d=c(f,e,a),d===e&&d!==f)return!1}else if(">="===f.operator&&!n(f.semver,String(e),a))return!1;if(p)if(E&&e.semver.prerelease&&e.semver.prerelease.length&&e.semver.major===E.major&&e.semver.minor===E.minor&&e.semver.patch===E.patch&&(E=!1),"<"===e.operator||"<="===e.operator){if(m=u(p,e,a),m===e&&m!==p)return!1}else if("<="===p.operator&&!n(p.semver,String(e),a))return!1;if(!e.operator&&(p||f)&&0!==h)return!1}return!(f&&g&&!p&&0!==h||p&&y&&!f&&0!==h||w||E)},c=(e,r,t)=>{if(!e)return r;const n=i(e.semver,r.semver,t);return n>0?e:n<0||">"===r.operator&&">="===e.operator?r:e},u=(e,r,t)=>{if(!e)return r;const n=i(e.semver,r.semver,t);return n<0?e:n>0||"<"===r.operator&&"<="===e.operator?r:e};return Nr=(r,t,n={})=>{if(r===t)return!0;r=new e(r,n),t=new e(t,n);let i=!1;e:for(const e of r.set){for(const r of t.set){const t=a(e,r,n);if(i=i||null!==t,t)continue e}if(i)return!1}return!0}}();return xr={parse:i,valid:o,clean:s,inc:a,diff:c,major:u,minor:l,patch:f,prerelease:p,compare:h,rcompare:d,compareLoose:m,compareBuild:g,sort:y,rsort:E,gt:w,lt:b,eq:v,neq:S,gte:$,lte:I,cmp:A,coerce:R,Comparator:O,Range:L,satisfies:T,toComparators:N,maxSatisfying:k,minSatisfying:x,minVersion:j,validRange:_,outside:P,gtr:C,ltr:D,intersects:M,simplifyRange:B,subset:K,SemVer:t,re:e.re,src:e.src,tokens:e.t,SEMVER_SPEC_VERSION:r.SEMVER_SPEC_VERSION,RELEASE_TYPES:r.RELEASE_TYPES,compareIdentifiers:n.compareIdentifiers,rcompareIdentifiers:n.rcompareIdentifiers}}function kt(){if(Br)return Mr;Br=1;const e=function(){if(Pr)return _r;Pr=1;const e=Nt();return _r=e.satisfies(process.version,">=15.7.0")}(),r=function(){if(Dr)return Cr;Dr=1;const e=Nt();return Cr=e.satisfies(process.version,">=16.9.0")}(),t={ec:["ES256","ES384","ES512"],rsa:["RS256","PS256","RS384","PS384","RS512","PS512"],"rsa-pss":["PS256","PS384","PS512"]},n={ES256:"prime256v1",ES384:"secp384r1",ES512:"secp521r1"};return Mr=function(i,o){if(!i||!o)return;const s=o.asymmetricKeyType;if(!s)return;const a=t[s];if(!a)throw new Error(`Unknown key type "${s}".`);if(!a.includes(i))throw new Error(`"alg" parameter for "${s}" key type must be one of: ${a.join(", ")}.`);if(e)switch(s){case"ec":const e=o.asymmetricKeyDetails.namedCurve,t=n[i];if(e!==t)throw new Error(`"alg" parameter "${i}" requires curve "${t}".`);break;case"rsa-pss":if(r){const e=parseInt(i.slice(-3),10),{hashAlgorithm:r,mgf1HashAlgorithm:t,saltLength:n}=o.asymmetricKeyDetails;if(r!==`sha${e}`||t!==r)throw new Error(`Invalid key for this operation, its RSA-PSS parameters do not meet the requirements of "alg" ${i}.`);if(void 0!==n&&n>e>>3)throw new Error(`Invalid key for this operation, its RSA-PSS parameter saltLength does not meet the requirements of "alg" ${i}.`)}}}}function xt(){if(Fr)return Kr;Fr=1;var e=Nt();return Kr=e.satisfies(process.version,"^6.12.0 || >=8.0.0")}function jt(){if(Ur)return Gr;Ur=1;const e=X(),r=Y(),t=W(),n=z(),i=Z(),s=kt(),a=xt(),c=q(),{KeyObject:u,createSecretKey:l,createPublicKey:f}=o,p=["RS256","RS384","RS512"],h=["ES256","ES384","ES512"],d=["RS256","RS384","RS512"],m=["HS256","HS384","HS512"];return a&&(p.splice(p.length,0,"PS256","PS384","PS512"),d.splice(d.length,0,"PS256","PS384","PS512")),Gr=function(o,a,g,y){let E;if("function"!=typeof g||y||(y=g,g={}),g||(g={}),g=Object.assign({},g),E=y||function(e,r){if(e)throw e;return r},g.clockTimestamp&&"number"!=typeof g.clockTimestamp)return E(new e("clockTimestamp must be a number"));if(void 0!==g.nonce&&("string"!=typeof g.nonce||""===g.nonce.trim()))return E(new e("nonce must be a non-empty string"));if(void 0!==g.allowInvalidAsymmetricKeyTypes&&"boolean"!=typeof g.allowInvalidAsymmetricKeyTypes)return E(new e("allowInvalidAsymmetricKeyTypes must be a boolean"));const w=g.clockTimestamp||Math.floor(Date.now()/1e3);if(!o)return E(new e("jwt must be provided"));if("string"!=typeof o)return E(new e("jwt must be a string"));const b=o.split(".");if(3!==b.length)return E(new e("jwt malformed"));let v;try{v=n(o,{complete:!0})}catch(e){return E(e)}if(!v)return E(new e("invalid token"));const S=v.header;let $;if("function"==typeof a){if(!y)return E(new e("verify must be called asynchronous if secret or public key is provided as a callback"));$=a}else $=function(e,r){return r(null,a)};return $(S,function(n,a){if(n)return E(new e("error in secret or public key callback: "+n.message));const y=""!==b[2].trim();if(!y&&a)return E(new e("jwt signature is required"));if(y&&!a)return E(new e("secret or public key must be provided"));if(!y&&!g.algorithms)return E(new e('please specify "none" in "algorithms" to verify unsigned tokens'));if(null!=a&&!(a instanceof u))try{a=f(a)}catch(r){try{a=l("string"==typeof a?Buffer.from(a):a)}catch(r){return E(new e("secretOrPublicKey is not valid key material"))}}if(g.algorithms||("secret"===a.type?g.algorithms=m:["rsa","rsa-pss"].includes(a.asymmetricKeyType)?g.algorithms=d:"ec"===a.asymmetricKeyType?g.algorithms=h:g.algorithms=p),-1===g.algorithms.indexOf(v.header.alg))return E(new e("invalid algorithm"));if(S.alg.startsWith("HS")&&"secret"!==a.type)return E(new e(`secretOrPublicKey must be a symmetric key when using ${S.alg}`));if(/^(?:RS|PS|ES)/.test(S.alg)&&"public"!==a.type)return E(new e(`secretOrPublicKey must be an asymmetric key when using ${S.alg}`));if(!g.allowInvalidAsymmetricKeyTypes)try{s(S.alg,a)}catch(e){return E(e)}let $;try{$=c.verify(o,v.header.alg,a)}catch(e){return E(e)}if(!$)return E(new e("invalid signature"));const I=v.payload;if(void 0!==I.nbf&&!g.ignoreNotBefore){if("number"!=typeof I.nbf)return E(new e("invalid nbf value"));if(I.nbf>w+(g.clockTolerance||0))return E(new r("jwt not active",new Date(1e3*I.nbf)))}if(void 0!==I.exp&&!g.ignoreExpiration){if("number"!=typeof I.exp)return E(new e("invalid exp value"));if(w>=I.exp+(g.clockTolerance||0))return E(new t("jwt expired",new Date(1e3*I.exp)))}if(g.audience){const r=Array.isArray(g.audience)?g.audience:[g.audience];if(!(Array.isArray(I.aud)?I.aud:[I.aud]).some(function(e){return r.some(function(r){return r instanceof RegExp?r.test(e):r===e})}))return E(new e("jwt audience invalid. expected: "+r.join(" or ")))}if(g.issuer){if("string"==typeof g.issuer&&I.iss!==g.issuer||Array.isArray(g.issuer)&&-1===g.issuer.indexOf(I.iss))return E(new e("jwt issuer invalid. expected: "+g.issuer))}if(g.subject&&I.sub!==g.subject)return E(new e("jwt subject invalid. expected: "+g.subject));if(g.jwtid&&I.jti!==g.jwtid)return E(new e("jwt jwtid invalid. expected: "+g.jwtid));if(g.nonce&&I.nonce!==g.nonce)return E(new e("jwt nonce invalid. expected: "+g.nonce));if(g.maxAge){if("number"!=typeof I.iat)return E(new e("iat required when maxAge is specified"));const r=i(g.maxAge,I.iat);if(void 0===r)return E(new e('"maxAge" should be a number of seconds or string representing a timespan eg: "1d", "20h", 60'));if(w>=r+(g.clockTolerance||0))return E(new t("maxAge exceeded",new Date(1e3*r)))}if(!0===g.complete){const e=v.signature;return E(null,{header:S,payload:I,signature:e})}return E(null,I)})},Gr}function _t(){if(Vr)return Hr;Vr=1;var e=1/0,r=9007199254740991,t=17976931348623157e292,n=NaN,i="[object Arguments]",o="[object Function]",s="[object GeneratorFunction]",a="[object String]",c="[object Symbol]",u=/^\s+|\s+$/g,l=/^[-+]0x[0-9a-f]+$/i,f=/^0b[01]+$/i,p=/^0o[0-7]+$/i,h=/^(?:0|[1-9]\d*)$/,d=parseInt;function m(e){return e!=e}function g(e,r){return function(e,r){for(var t=-1,n=e?e.length:0,i=Array(n);++t<n;)i[t]=r(e[t],t,e);return i}(r,function(r){return e[r]})}var y,E,w=Object.prototype,b=w.hasOwnProperty,v=w.toString,S=w.propertyIsEnumerable,$=(y=Object.keys,E=Object,function(e){return y(E(e))}),I=Math.max;function A(e,r){var t=L(e)||function(e){return function(e){return k(e)&&T(e)}(e)&&b.call(e,"callee")&&(!S.call(e,"callee")||v.call(e)==i)}(e)?function(e,r){for(var t=-1,n=Array(e);++t<e;)n[t]=r(t);return n}(e.length,String):[],n=t.length,o=!!n;for(var s in e)!b.call(e,s)||o&&("length"==s||O(s,n))||t.push(s);return t}function R(e){if(t=(r=e)&&r.constructor,n="function"==typeof t&&t.prototype||w,r!==n)return $(e);var r,t,n,i=[];for(var o in Object(e))b.call(e,o)&&"constructor"!=o&&i.push(o);return i}function O(e,t){return!!(t=null==t?r:t)&&("number"==typeof e||h.test(e))&&e>-1&&e%1==0&&e<t}var L=Array.isArray;function T(e){return null!=e&&function(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=r}(e.length)&&!function(e){var r=N(e)?v.call(e):"";return r==o||r==s}(e)}function N(e){var r=typeof e;return!!e&&("object"==r||"function"==r)}function k(e){return!!e&&"object"==typeof e}return Hr=function(r,i,o,s){var h;r=T(r)?r:(h=r)?g(h,function(e){return T(e)?A(e):R(e)}(h)):[],o=o&&!s?function(r){var i=function(r){if(!r)return 0===r?r:0;if(r=function(e){if("number"==typeof e)return e;if(function(e){return"symbol"==typeof e||k(e)&&v.call(e)==c}(e))return n;if(N(e)){var r="function"==typeof e.valueOf?e.valueOf():e;e=N(r)?r+"":r}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(u,"");var t=f.test(e);return t||p.test(e)?d(e.slice(2),t?2:8):l.test(e)?n:+e}(r),r===e||r===-1/0){return(r<0?-1:1)*t}return r==r?r:0}(r),o=i%1;return i==i?o?i-o:i:0}(o):0;var y=r.length;return o<0&&(o=I(y+o,0)),function(e){return"string"==typeof e||!L(e)&&k(e)&&v.call(e)==a}(r)?o<=y&&r.indexOf(i,o)>-1:!!y&&function(e,r,t){if(r!=r)return function(e,r,t){for(var n=e.length,i=t+-1;++i<n;)if(r(e[i],i,e))return i;return-1}(e,m,t);for(var n=t-1,i=e.length;++n<i;)if(e[n]===r)return n;return-1}(r,i,o)>-1},Hr}function Pt(){if(Yr)return Xr;Yr=1;var e=1/0,r=17976931348623157e292,t=NaN,n="[object Symbol]",i=/^\s+|\s+$/g,o=/^[-+]0x[0-9a-f]+$/i,s=/^0b[01]+$/i,a=/^0o[0-7]+$/i,c=parseInt,u=Object.prototype.toString;function l(e){var r=typeof e;return!!e&&("object"==r||"function"==r)}return Xr=function(f){return"number"==typeof f&&f==function(f){var p=function(f){if(!f)return 0===f?f:0;if(f=function(e){if("number"==typeof e)return e;if(function(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&u.call(e)==n}(e))return t;if(l(e)){var r="function"==typeof e.valueOf?e.valueOf():e;e=l(r)?r+"":r}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(i,"");var f=s.test(e);return f||a.test(e)?c(e.slice(2),f?2:8):o.test(e)?t:+e}(f),f===e||f===-1/0){return(f<0?-1:1)*r}return f==f?f:0}(f),h=p%1;return p==p?h?p-h:p:0}(f)}}function Ct(){if(nt)return tt;nt=1;var e=1/0,r=17976931348623157e292,t=NaN,n="[object Symbol]",i=/^\s+|\s+$/g,o=/^[-+]0x[0-9a-f]+$/i,s=/^0b[01]+$/i,a=/^0o[0-7]+$/i,c=parseInt,u=Object.prototype.toString;function l(l,p){var h;if("function"!=typeof p)throw new TypeError("Expected a function");return l=function(l){var p=function(l){if(!l)return 0===l?l:0;if(l=function(e){if("number"==typeof e)return e;if(function(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&u.call(e)==n}(e))return t;if(f(e)){var r="function"==typeof e.valueOf?e.valueOf():e;e=f(r)?r+"":r}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(i,"");var l=s.test(e);return l||a.test(e)?c(e.slice(2),l?2:8):o.test(e)?t:+e}(l),l===e||l===-1/0){return(l<0?-1:1)*r}return l==l?l:0}(l),h=p%1;return p==p?h?p-h:p:0}(l),function(){return--l>0&&(h=p.apply(this,arguments)),l<=1&&(p=void 0),h}}function f(e){var r=typeof e;return!!e&&("object"==r||"function"==r)}return tt=function(e){return l(2,e)}}function Dt(){if(ot)return it;ot=1;const e=Z(),r=xt(),t=kt(),n=q(),i=_t(),s=function(){if(zr)return qr;zr=1;var e=Object.prototype.toString;return qr=function(r){return!0===r||!1===r||function(e){return!!e&&"object"==typeof e}(r)&&"[object Boolean]"==e.call(r)}}(),a=Pt(),c=function(){if(Jr)return Wr;Jr=1;var e=Object.prototype.toString;return Wr=function(r){return"number"==typeof r||function(e){return!!e&&"object"==typeof e}(r)&&"[object Number]"==e.call(r)}}(),u=function(){if(Qr)return Zr;Qr=1;var e,r,t=Function.prototype,n=Object.prototype,i=t.toString,o=n.hasOwnProperty,s=i.call(Object),a=n.toString,c=(e=Object.getPrototypeOf,r=Object,function(t){return e(r(t))});return Zr=function(e){if(!function(e){return!!e&&"object"==typeof e}(e)||"[object Object]"!=a.call(e)||function(e){var r=!1;if(null!=e&&"function"!=typeof e.toString)try{r=!!(e+"")}catch(e){}return r}(e))return!1;var r=c(e);if(null===r)return!0;var t=o.call(r,"constructor")&&r.constructor;return"function"==typeof t&&t instanceof t&&i.call(t)==s}}(),l=function(){if(rt)return et;rt=1;var e=Object.prototype.toString,r=Array.isArray;return et=function(t){return"string"==typeof t||!r(t)&&function(e){return!!e&&"object"==typeof e}(t)&&"[object String]"==e.call(t)}}(),f=Ct(),{KeyObject:p,createSecretKey:h,createPrivateKey:d}=o,m=["RS256","RS384","RS512","ES256","ES384","ES512","HS256","HS384","HS512","none"];r&&m.splice(3,0,"PS256","PS384","PS512");const g={expiresIn:{isValid:function(e){return a(e)||l(e)&&e},message:'"expiresIn" should be a number of seconds or string representing a timespan'},notBefore:{isValid:function(e){return a(e)||l(e)&&e},message:'"notBefore" should be a number of seconds or string representing a timespan'},audience:{isValid:function(e){return l(e)||Array.isArray(e)},message:'"audience" must be a string or array'},algorithm:{isValid:i.bind(null,m),message:'"algorithm" must be a valid string enum value'},header:{isValid:u,message:'"header" must be an object'},encoding:{isValid:l,message:'"encoding" must be a string'},issuer:{isValid:l,message:'"issuer" must be a string'},subject:{isValid:l,message:'"subject" must be a string'},jwtid:{isValid:l,message:'"jwtid" must be a string'},noTimestamp:{isValid:s,message:'"noTimestamp" must be a boolean'},keyid:{isValid:l,message:'"keyid" must be a string'},mutatePayload:{isValid:s,message:'"mutatePayload" must be a boolean'},allowInsecureKeySizes:{isValid:s,message:'"allowInsecureKeySizes" must be a boolean'},allowInvalidAsymmetricKeyTypes:{isValid:s,message:'"allowInvalidAsymmetricKeyTypes" must be a boolean'}},y={iat:{isValid:c,message:'"iat" should be a number of seconds'},exp:{isValid:c,message:'"exp" should be a number of seconds'},nbf:{isValid:c,message:'"nbf" should be a number of seconds'}};function E(e,r,t,n){if(!u(t))throw new Error('Expected "'+n+'" to be a plain object.');Object.keys(t).forEach(function(i){const o=e[i];if(o){if(!o.isValid(t[i]))throw new Error(o.message)}else if(!r)throw new Error('"'+i+'" is not allowed in "'+n+'"')})}const w={audience:"aud",issuer:"iss",subject:"sub",jwtid:"jti"},b=["expiresIn","notBefore","noTimestamp","audience","issuer","subject","jwtid"];return it=function(r,i,o,s){"function"==typeof o?(s=o,o={}):o=o||{};const a="object"==typeof r&&!Buffer.isBuffer(r),c=Object.assign({alg:o.algorithm||"HS256",typ:a?"JWT":void 0,kid:o.keyid},o.header);function u(e){if(s)return s(e);throw e}if(!i&&"none"!==o.algorithm)return u(new Error("secretOrPrivateKey must have a value"));if(null!=i&&!(i instanceof p))try{i=d(i)}catch(e){try{i=h("string"==typeof i?Buffer.from(i):i)}catch(e){return u(new Error("secretOrPrivateKey is not valid key material"))}}if(c.alg.startsWith("HS")&&"secret"!==i.type)return u(new Error(`secretOrPrivateKey must be a symmetric key when using ${c.alg}`));if(/^(?:RS|PS|ES)/.test(c.alg)){if("private"!==i.type)return u(new Error(`secretOrPrivateKey must be an asymmetric key when using ${c.alg}`));if(!o.allowInsecureKeySizes&&!c.alg.startsWith("ES")&&void 0!==i.asymmetricKeyDetails&&i.asymmetricKeyDetails.modulusLength<2048)return u(new Error(`secretOrPrivateKey has a minimum key size of 2048 bits for ${c.alg}`))}if(void 0===r)return u(new Error("payload is required"));if(a){try{!function(e){E(y,!0,e,"payload")}(r)}catch(e){return u(e)}o.mutatePayload||(r=Object.assign({},r))}else{const e=b.filter(function(e){return void 0!==o[e]});if(e.length>0)return u(new Error("invalid "+e.join(",")+" option for "+typeof r+" payload"))}if(void 0!==r.exp&&void 0!==o.expiresIn)return u(new Error('Bad "options.expiresIn" option the payload already has an "exp" property.'));if(void 0!==r.nbf&&void 0!==o.notBefore)return u(new Error('Bad "options.notBefore" option the payload already has an "nbf" property.'));try{!function(e){E(g,!1,e,"options")}(o)}catch(e){return u(e)}if(!o.allowInvalidAsymmetricKeyTypes)try{t(c.alg,i)}catch(e){return u(e)}const l=r.iat||Math.floor(Date.now()/1e3);if(o.noTimestamp?delete r.iat:a&&(r.iat=l),void 0!==o.notBefore){try{r.nbf=e(o.notBefore,l)}catch(e){return u(e)}if(void 0===r.nbf)return u(new Error('"notBefore" should be a number of seconds or string representing a timespan eg: "1d", "20h", 60'))}if(void 0!==o.expiresIn&&"object"==typeof r){try{r.exp=e(o.expiresIn,l)}catch(e){return u(e)}if(void 0===r.exp)return u(new Error('"expiresIn" should be a number of seconds or string representing a timespan eg: "1d", "20h", 60'))}Object.keys(w).forEach(function(e){const t=w[e];if(void 0!==o[e]){if(void 0!==r[t])return u(new Error('Bad "options.'+e+'" option. The payload already has an "'+t+'" property.'));r[t]=o[e]}});const m=o.encoding||"utf8";if("function"!=typeof s){let e=n.sign({header:c,payload:r,secret:i,encoding:m});if(!o.allowInsecureKeySizes&&/^(?:RS|PS)/.test(c.alg)&&e.length<256)throw new Error(`secretOrPrivateKey has a minimum key size of 2048 bits for ${c.alg}`);return e}s=s&&f(s),n.createSign({header:c,privateKey:i,payload:r,encoding:m}).once("error",s).once("done",function(e){if(!o.allowInsecureKeySizes&&/^(?:RS|PS)/.test(c.alg)&&e.length<256)return s(new Error(`secretOrPrivateKey has a minimum key size of 2048 bits for ${c.alg}`));s(null,e)})}}var Mt=s(at?st:(at=1,st={decode:z(),verify:jt(),sign:Dt(),JsonWebTokenError:X(),NotBeforeError:Y(),TokenExpiredError:W()}));const Bt=e(import.meta.url),{version:Kt}=Bt("../package.json");var Ft={id:"sso",handler:(e,t)=>{const{env:n,logger:i,services:o,database:s,getSchema:a}=t,c=n.KEYCLOAK_URL||"http://keycloak:8080",u=n.KEYCLOAK_REALM||"testing",l=n.KEYCLOAK_ADMIN_USER||"admin",f=n.KEYCLOAK_ADMIN_PASSWORD||"admin",p=n.PUBLIC_URL||"http://localhost:8055",h=n.MOBILE_APP_SCHEME||"finsnapp",d=Array.isArray(h)?h.map(e=>String(e).trim()):String(h).split(",").map(e=>e.trim()),m=d[0],g=n.MOBILE_APP_CALLBACK_PATH||"/auth/callback",y=n.GOOGLE_CALLBACK_PATH||"/auth/callback/google",E=n.APPLE_CLIENT_ID||"com.forumbandung.app",w=Array.isArray(E)?E.map(e=>String(e).trim().toLowerCase()):String(E).split(",").map(e=>e.trim().toLowerCase()),b=n.KEYCLOAK_CLIENT_ID||"admin-cli",v=n.COOKIE_DOMAIN||null,S="false"!==n.COOKIE_SECURE,$=n.COOKIE_SAME_SITE||"lax",I=n.SESSION_COOKIE_NAME||"directus_session_token",A=n.REFRESH_TOKEN_COOKIE_NAME||"directus_refresh_token",R=n.DEFAULT_ROLE_ID||null,O="directus_session_token";function L(e){return"string"!=typeof e?"":e.replace(/[&<>"']/g,e=>{switch(e){case"&":return"&amp;";case"<":return"&lt;";case">":return"&gt;";case'"':return"&quot;";case"'":return"&#039;";default:return e}})}function T(e,r,t="AUTHENTICATION_FAILED"){const n=L(e);return`<!DOCTYPE html>\n<html lang="en">\n<head>\n <meta charset="UTF-8">\n <meta name="viewport" content="width=device-width, initial-scale=1.0">\n <title>${n}</title>\n <link rel="preconnect" href="https://fonts.googleapis.com">\n <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>\n <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700&display=swap" rel="stylesheet">\n <style>\n * {\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n }\n body {\n font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;\n background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);\n min-height: 100vh;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 24px;\n color: #1e293b;\n }\n .container {\n width: 100%;\n max-width: 440px;\n background: rgba(255, 255, 255, 0.95);\n backdrop-filter: blur(16px);\n -webkit-backdrop-filter: blur(16px);\n border: 1px solid rgba(255, 255, 255, 0.6);\n border-radius: 24px;\n padding: 40px 32px;\n box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.08);\n text-align: center;\n animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);\n }\n @keyframes slideUp {\n from {\n opacity: 0;\n transform: translateY(20px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n }\n .icon-wrapper {\n width: 72px;\n height: 72px;\n background: #fef2f2;\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n margin: 0 auto 24px;\n color: #ef4444;\n border: 1px solid #fee2e2;\n animation: scaleIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);\n }\n @keyframes scaleIn {\n from { transform: scale(0); }\n to { transform: scale(1); }\n }\n .icon {\n width: 32px;\n height: 32px;\n fill: none;\n stroke: currentColor;\n stroke-width: 2.5;\n stroke-linecap: round;\n stroke-linejoin: round;\n }\n h1 {\n font-size: 24px;\n font-weight: 700;\n color: #0f172a;\n margin-bottom: 12px;\n letter-spacing: -0.02em;\n }\n p {\n font-size: 15px;\n line-height: 1.6;\n color: #64748b;\n margin-bottom: 32px;\n }\n .instruction-card {\n background: #f8fafc;\n border: 1px solid #f1f5f9;\n border-radius: 16px;\n padding: 20px;\n margin-bottom: 28px;\n text-align: left;\n }\n .instruction-card h3 {\n font-size: 13px;\n font-weight: 700;\n color: #475569;\n margin-bottom: 10px;\n text-transform: uppercase;\n letter-spacing: 0.05em;\n }\n .instruction-list {\n list-style: none;\n }\n .instruction-list li {\n font-size: 14px;\n line-height: 1.5;\n color: #475569;\n margin-bottom: 10px;\n display: flex;\n align-items: flex-start;\n }\n .instruction-list li::before {\n content: "•";\n color: #ef4444;\n font-weight: bold;\n display: inline-block;\n width: 1em;\n margin-left: -0.2em;\n flex-shrink: 0;\n }\n .instruction-list li:last-child {\n margin-bottom: 0;\n }\n .btn {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 100%;\n padding: 14px 24px;\n background: #0f172a;\n color: #ffffff;\n border: none;\n border-radius: 16px;\n font-size: 16px;\n font-weight: 600;\n cursor: pointer;\n transition: all 0.2s ease;\n box-shadow: 0 4px 6px -1px rgba(15, 23, 42, 0.1);\n text-decoration: none;\n }\n .btn:hover {\n background: #1e293b;\n transform: translateY(-1px);\n box-shadow: 0 10px 15px -3px rgba(15, 23, 42, 0.15);\n }\n .btn:active {\n transform: translateY(0);\n }\n .footer-text {\n font-size: 12px;\n color: #94a3b8;\n margin-top: 24px;\n }\n </style>\n</head>\n<body>\n <div class="container">\n <div class="icon-wrapper">\n <svg class="icon" viewBox="0 0 24 24">\n <circle cx="12" cy="12" r="10"></circle>\n <line x1="12" y1="8" x2="12" y2="12"></line>\n <line x1="12" y1="16" x2="12.01" y2="16"></line>\n </svg>\n </div>\n <h1>${n}</h1>\n <p>${L(r)}</p>\n \n <div class="instruction-card">\n <h3>How to resolve this</h3>\n <ul class="instruction-list">\n <li>Tap the <strong>✕</strong> close icon at the top left of this screen.</li>\n <li>You will return to your mobile app automatically.</li>\n <li>Try logging in again from the app.</li>\n </ul>\n </div>\n\n <button class="btn" onclick="try { window.close(); } catch(e) {}">Return to App</button>\n \n <div class="footer-text">\n Error Code: ${L(t)}\n </div>\n </div>\n</body>\n</html>`}function N(e,r="/"){if(!e||"string"!=typeof e)return r;try{if(d.some(r=>e.startsWith(`${r}://`)))return e;if(e.startsWith("/")&&!e.startsWith("//")&&!e.startsWith("/\\"))return e;const r=new URL(e),t=new URL(p).origin;if(r.origin===t)return e}catch(e){}return i.warn(`⚠️ Warning: Blocked potentially unsafe redirect URL: "${e}". Defaulting to fallback: "${r}"`),r}const k=n.FCM_PROJECT_ID||null;async function x(){try{const e=await fetch(`${c}/realms/master/protocol/openid-connect/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"password",client_id:b,username:l,password:f}).toString()});if(!e.ok)throw new Error("Failed to get admin token");return(await e.json()).access_token}catch(e){return i.error("Error getting admin token:",e),null}}async function j(e,r){try{const t=await fetch(`${c}/admin/realms/${u}/users?email=${encodeURIComponent(r)}`,{headers:{Authorization:`Bearer ${e}`}});if(!t.ok)throw new Error("Failed to get user");const n=await t.json();return n.length>0?n[0].id:null}catch(e){return i.error("Error getting user ID:",e),null}}async function _(e,r){try{const t=await fetch(`${c}/admin/realms/${u}/users/${r}/logout`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});return t.ok||204===t.status}catch(e){return i.error("Error logging out user from Keycloak:",e),!1}}function P(e){if("browser"===e.query.type)return!0;if("mobile"===e.query.type)return!1;if(e.query.app_scheme||e.query.app_path)return!1;const r=e.headers["user-agent"]||"";return/Mozilla|Chrome|Safari|Firefox|Edge|Opera/i.test(r)&&!/Mobile.*App|ReactNative|Expo/i.test(r)}async function C(e,r){const t=e.headers.cookie;if(!t)return null;const n=t.split(";").map(e=>e.trim()).filter(e=>e.startsWith(`${r}=`)).map(e=>e.substring(r.length+1));if(0===n.length)return null;for(let e=0;e<n.length;e++){const t=n[e];try{const e=await fetch(`${p}/users/me`,{headers:{Cookie:`${r}=${t}`}});if(e.ok){return{token:t,userData:(await e.json()).data}}}catch(e){}}return null}async function D(e){const r=e.headers.cookie;if(!r)return null;const t=r.split(";").map(e=>e.trim()).map(e=>{const r=e.split("=");return r.length>1?r[1]:null}).filter(e=>e&&e.startsWith("eyJ")&&e.length>50);if(0===t.length)return null;for(let e=0;e<t.length;e++){const r=t[e];try{const e=await fetch(`${p}/users/me`,{headers:{Authorization:`Bearer ${r}`}});if(e.ok){return{token:r,userData:(await e.json()).data}}}catch(e){}}return null}async function M(e){const r=e.cookies[A];if(!r)return null;try{const e=await fetch(`${p}/auth/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:r})});if(e.ok){const r=(await e.json()).data.access_token,t=await fetch(`${p}/users/me`,{headers:{Authorization:`Bearer ${r}`}});if(t.ok){return{token:r,userData:(await t.json()).data}}}}catch(e){}return null}function B(e){const r=e.query.app_scheme;return r&&d.includes(r)?r:(r&&i.warn(`⚠️ Warning: App requested scheme '${r}', but it is not in .env. Falling back to '${m}'`),m)}n.FCM_CLIENT_EMAIL,n.FCM_PRIVATE_KEY&&n.FCM_PRIVATE_KEY.replace(/\\n/g,"\n"),n.FCM_WEBHOOK_SECRET,i.info("🚀 Mobile Auth Extension loaded"),i.info("📱 Allowed Mobile App Schemes: "+d.join(", "));let K=!1;e.use((e,r,t)=>{e.app&&function(e){if(K||e.__sso_error_interceptor_registered)return;e.__sso_error_interceptor_registered=!0,K=!0,i.info("🛠️ SSO global error interceptor registered on Express app");const r=(e,r,t)=>{if(P(e)){const e=r.json;r.json=function(t){return t&&t.errors&&Array.isArray(t.errors)&&t.errors.length>0&&t.errors.some(e=>"INVALID_CREDENTIALS"===e.extensions?.code||e.message?.toLowerCase().includes("credentials"))?(r.setHeader("Content-Type","text/html"),r.status(401),r.send(T("Login Session Expired","Your login credentials are invalid or your session has expired. Please return to the app and try logging in again.","INVALID_CREDENTIALS"))):e.apply(this,arguments)}}t()};e._router&&Array.isArray(e._router.stack)?e._router.stack.unshift({handle:r,name:"ssoErrorInterceptor",params:void 0,path:void 0,keys:[],regexp:/^\/?/}):e.use(r)}(e.app),t()}),e.get("/health",(e,r)=>{r.json({status:"ok",service:"directus-extension-sso",version:Kt,allowed_schemes:d,fcm_enabled:!!k})}),e.get("/mobile-callback",async(e,r)=>{const t=P(e);try{let n=null;if(I!==O&&(n=await C(e,I)),n||(n=await C(e,O)),n||(n=await D(e)),n||(n=await M(e)),!n)return t?(r.setHeader("Content-Type","text/html"),r.status(401).send(T("Authentication Failed","Your login session is invalid or has expired. Please go back to the app and try logging in again.","INVALID_CREDENTIALS"))):r.status(401).json({error:"Authentication failed"});const{token:i,userData:o}=n,s=o.id,a=o.email,c=i;if(t){r.cookie(I,i,{httpOnly:!0,secure:S,domain:v,sameSite:$,maxAge:6048e5,path:"/"}),I!==O&&r.cookie(O,"",{maxAge:0,path:"/"});let t=e.query.redirect_uri||e.query.redirect||"/";return t=N(t,"/"),r.redirect(t)}const u=B(e),l=`${u}://${(e.query.app_path||g).replace(/^\/+/,"")}?access_token=${c}&user_id=${s}&email=${encodeURIComponent(a||"")}`;return r.setHeader("Location",l),r.status(302).send(`<html><head><meta http-equiv="refresh" content="0;url=${l}"></head><body>Redirecting...</body></html>`)}catch(e){if(i.error("Error in mobile-callback:",e),t)return r.setHeader("Content-Type","text/html"),r.status(500).send(T("Authentication Error",e.message||"An unexpected error occurred during mobile authentication.","INTERNAL_SERVER_ERROR"));r.status(500).json({error:e.message})}}),e.get("/google-callback",async(e,r)=>{const t=P(e);try{let n=null;if(e.query.access_token){n={token:e.query.access_token,refresh_token:e.query.refresh_token||null,expires:e.query.expires||null};try{const e=await fetch(`${p}/users/me`,{headers:{Authorization:`Bearer ${n.token}`}});if(e.ok){const r=await e.json();n.userData=r.data}else n=null}catch(e){n=null}}if(n||I===O||(n=await C(e,I)),n||(n=await C(e,O)),n||(n=await D(e)),n||(n=await M(e)),!n)return t?(r.setHeader("Content-Type","text/html"),r.status(401).send(T("Authentication Failed","Your Google login session is invalid or has expired. Please go back to the app and try logging in again.","INVALID_CREDENTIALS"))):r.status(401).json({error:"Authentication failed"});const{token:o,userData:s}=n,a=s.id,c=s.email,u=o;if(t){r.cookie(I,o,{httpOnly:!0,secure:S,domain:v,sameSite:$,maxAge:6048e5,path:"/"}),I!==O&&r.cookie(O,"",{maxAge:0,path:"/"});let t=e.query.redirect_uri||e.query.redirect||"/";t=N(t,"/");const n=L(t);return r.send(`<html><head><meta http-equiv="refresh" content="2;url=${n}"></head><body>Login Successful!</body></html>`)}const l=B(e),f=e.query.app_path||y,h=new URL(`${l}://${f.replace(/^\/+/,"")}`);return h.searchParams.set("access_token",u),h.searchParams.set("user_id",a),h.searchParams.set("email",c||""),h.searchParams.set("provider","google"),i.info("🚀 Performing direct 302 redirect to app: "+h.toString()),r.redirect(302,h.toString())}catch(e){if(i.error("Error in google-callback:",e),t)return r.setHeader("Content-Type","text/html"),r.status(500).send(T("Authentication Error",e.message||"An unexpected error occurred during Google authentication.","INTERNAL_SERVER_ERROR"));r.status(500).json({error:e.message})}}),e.get("/logout-clear",(e,r)=>{const t={httpOnly:!0,secure:S,sameSite:$,path:"/"};if(r.clearCookie(I,t),I!==O&&r.clearCookie(O,t),r.clearCookie(A,t),v){const e={...t,domain:v};r.clearCookie(I,e),I!==O&&r.clearCookie(O,e),r.clearCookie(A,e)}try{r.clearCookie(I,{...t,domain:".goyong.in"}),r.clearCookie(O,{...t,domain:".goyong.in"}),r.clearCookie(A,{...t,domain:".goyong.in"})}catch(e){}let n=e.query.redirect;return n?(n=N(n,"/"),i.info(`🧹 Cleared cookies and redirecting to: ${n}`),r.redirect(n)):(i.info("🧹 Cleared cookies successfully (no redirect provided)"),r.json({success:!0,message:"Cookies cleared successfully"}))}),e.post("/mobile-logout",async(e,r)=>{try{const t=e.headers.authorization,n=t?.replace("Bearer ","");if(!n)return r.status(400).json({error:"No token provided"});let i=null;try{const e=await fetch(`${p}/users/me`,{headers:{Authorization:`Bearer ${n}`}});if(e.ok){i=(await e.json()).data.email}}catch(e){}try{await fetch(`${p}/auth/logout`,{method:"POST",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},body:JSON.stringify({refresh_token:n})})}catch(e){}if(i)try{const e=await x();if(e){const r=await j(e,i);r&&await _(e,r)}}catch(e){}r.json({success:!0,message:"Logged out successfully"})}catch(e){r.status(500).json({error:e.message})}}),e.post("/delete-account",async(e,r)=>{try{const t=e.headers.authorization,c=t?.replace("Bearer ","");if(!c)return r.status(400).json({error:"No token provided"});let u=null,l=null;try{const e=await fetch(`${p}/users/me`,{headers:{Authorization:`Bearer ${c}`}});if(e.ok){const r=await e.json();u=r.data.id,l=r.data.email}}catch(e){i.error("[SSO] Error verifying token during account deletion:",e)}if(!u||!l)return r.status(401).json({error:"Invalid or expired token"});i.info(`[SSO] Deleting account for user: ${u} (${l})`);let f=!1;try{const e=await fetch(`${p}/auth/logout`,{method:"POST",headers:{Authorization:`Bearer ${c}`,"Content-Type":"application/json"},body:JSON.stringify({})});f=e.ok||204===e.status,i.info(`[SSO] Directus /auth/logout → ${e.status} for user ${u}`)}catch(e){i.warn("[SSO] /auth/logout network error (non-fatal):",e.message)}let h=0;try{const e=Mt.decode(c),r=e?.session;if(r){const e=await s("directus_sessions").where("token",r).delete();h+=e,i.info(`[SSO] Deleted ${e} session(s) by token for user ${u}`)}const t=await s("directus_sessions").where("user",u).delete();h+=t,t>0&&i.info(`[SSO] Deleted ${t} additional session(s) by user ID for ${u}`)}catch(e){i.error("[SSO] Error deleting sessions:",e)}const{UsersService:d}=o,m=new d({schema:await a(),knex:s}),g=`DELETED_${Date.now()}_${l}`;await m.updateOne(u,{first_name:"DELETED",last_name:"ACCOUNT",status:"suspended",email:g,external_identifier:null,provider:"default"}),i.info(`[SSO] Soft-deleted user ${u} → ${g}, sessions cleared: ${h}, directus logout: ${f}`);if(!!(n.KEYCLOAK_URL&&n.KEYCLOAK_REALM&&n.KEYCLOAK_ADMIN_USER&&n.KEYCLOAK_ADMIN_PASSWORD))try{const e=await x();if(e){const r=await j(e,l);r&&(await _(e,r),i.info(`[SSO] Logged out user ${l} from Keycloak`))}}catch(e){i.error("[SSO] Keycloak logout error:",e)}const y=`${p}/sso/logout-clear`;return r.json({success:!0,message:"Account deleted successfully, sessions cleared.",sessions_cleared:h,browser_logout_url:y})}catch(e){return i.error("[SSO] Account deletion failed:",e),r.status(500).json({error:e.message,message:"Failed to delete account"})}}),e.post("/apple-token",async(e,t)=>{const{identityToken:c,firstName:u,lastName:l}=e.body;if(i.info("🍎 Apple token exchange request received"),!c)return t.status(400).json({error:"identityToken is required",message:"Apple identityToken must be provided in the request body"});try{const e=async e=>{const[t,n,i]=e.split("."),o=JSON.parse(Buffer.from(t,"base64").toString()),s=JSON.parse(Buffer.from(n,"base64").toString());if("https://appleid.apple.com"!==s.iss)throw new Error("Invalid issuer");const a=[...w,"host.exp.exponent"],c=s.aud.toLowerCase();if(!a.includes(c))throw new Error(`Invalid audience: ${c}. Allowed: ${a.join(", ")}`);if(s.exp<Math.floor(Date.now()/1e3))throw new Error("Token expired");const u=await fetch("https://appleid.apple.com/auth/keys"),{keys:l}=await u.json(),f=l.find(e=>e.kid===o.kid);if(!f)throw new Error("Apple public key not found");const p=r.createPublicKey({key:f,format:"jwk"}),h=r.createVerify("RSA-SHA256");h.update(`${t}.${n}`);if(!h.verify(p,i,"base64url"))throw new Error("Invalid signature");return s},i=await e(c),{email:f,sub:p}=i;if(!f)throw new Error("Apple token did not contain an email");const{UsersService:h}=o,d=new h({schema:await a(),knex:s});let m,g=await d.readByQuery({filter:{_and:[{external_identifier:{_eq:p}},{provider:{_eq:"apple"}}]}}),y=g.length>0?g[0]:null;y||(g=await d.readByQuery({filter:{email:{_eq:f}}}),g.length>0&&(y=g[0],await d.updateOne(y.id,{external_identifier:p,provider:"apple"}))),y?m=y.id:(m=await d.createOne({email:f,first_name:u||"Apple User",last_name:l||"",role:R,status:"active",provider:"apple",external_identifier:p}),y=await d.readOne(m));const E={id:m,role:y.role||R,app_access:!0,admin_access:!1},b=Mt.sign(E,n.SECRET,{expiresIn:"7d",issuer:"directus"}),v={id:m,type:"refresh"},S=Mt.sign(v,n.SECRET,{expiresIn:"30d",issuer:"directus"});t.json({success:!0,data:{access_token:b,refresh_token:S,expires:604800,user:y},user_id:m,email:f,provider:"apple"})}catch(e){t.status(500).json({error:e.message,message:"Failed to verify Apple token"})}}),e.post("/bridge-token",async(e,r)=>{try{const t=e.headers.authorization,i=t?.replace("Bearer ","");if(!i)return r.status(400).json({error:"No token provided"});const o=await fetch(`${p}/users/me`,{headers:{Authorization:`Bearer ${i}`}});if(!o.ok)return r.status(401).json({error:"Invalid token"});const s={sub:(await o.json()).data.id,purpose:"bridge"},a=Mt.sign(s,n.SECRET,{expiresIn:"60s",issuer:"directus-sso"});r.json({success:!0,bridge_token:a})}catch(e){r.status(500).json({error:e.message})}}),e.get("/bridge",async(e,r)=>{const{token:t,bridge_token:o,redirect_uri:s,redirect:a}=e.query,c=N(s||a,"/"),u="true"===n.ENABLE_LEGACY_BRIDGE,l=P(e);let f=null,h=null;if(o)try{const e=Mt.verify(o,n.SECRET,{issuer:"directus-sso"});if("bridge"!==e.purpose)return l?(r.setHeader("Content-Type","text/html"),r.status(400).send(T("Authentication Failed","Invalid token purpose.","INVALID_BRIDGE_TOKEN"))):r.status(400).json({error:"Invalid token purpose"});f=e.sub;const t={id:f,app_access:!0,admin_access:!1};h=Mt.sign(t,n.SECRET,{expiresIn:"7d",issuer:"directus"})}catch(e){return l?(r.setHeader("Content-Type","text/html"),r.status(401).send(T("Session Expired","Your secure login session has expired or is invalid. Please go back to the app and try logging in again.","EXPIRED_BRIDGE_TOKEN"))):r.status(401).json({error:"Invalid or expired bridge token",message:e.message})}else{if(!t||!u)return l?(r.setHeader("Content-Type","text/html"),r.status(400).send(T("Authentication Failed","Secure bridge token is required to start your session.","MISSING_BRIDGE_TOKEN"))):r.status(400).json({error:"Secure bridge token required"});i.warn("⚠️ Warning: Legacy bridge token used. This flow is vulnerable to session fixation.");try{const e=await fetch(`${p}/users/me`,{headers:{Authorization:`Bearer ${t}`}});if(!e.ok)return l?(r.setHeader("Content-Type","text/html"),r.status(401).send(T("Session Expired","Your secure login session has expired or is invalid. Please go back to the app and try logging in again.","INVALID_CREDENTIALS"))):r.status(401).json({error:"Invalid token"});f=(await e.json()).data.id,h=t}catch(e){return l?(r.setHeader("Content-Type","text/html"),r.status(500).send(T("Authentication Error","An unexpected error occurred while bridging your session.","BRIDGE_FAILURE"))):r.status(500).json({error:"Bridge failure",message:e.message})}}return r.cookie(I,h,{httpOnly:!0,secure:S,domain:v,sameSite:$,maxAge:6048e5,path:"/"}),I!==O&&r.cookie(O,h,{httpOnly:!0,secure:S,domain:v,sameSite:$,maxAge:6048e5,path:"/"}),r.redirect(c)})}};export{Ft as default};
1
+ import{createRequire as e}from"module";import r from"node:crypto";import t from"buffer";import n from"stream";import i from"util";import o from"crypto";function s(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var a,c,u,l,f,p,h,d,m,g,E,y,w,b,v,S,$,I,A,R,O,L,T,N,x,k,j,_,P,C,D={},M={exports:{}};function B(){return a||(a=1,function(e,r){var n=t,i=n.Buffer;function o(e,r){for(var t in e)r[t]=e[t]}function s(e,r,t){return i(e,r,t)}i.from&&i.alloc&&i.allocUnsafe&&i.allocUnsafeSlow?e.exports=n:(o(n,r),r.Buffer=s),s.prototype=Object.create(i.prototype),o(i,s),s.from=function(e,r,t){if("number"==typeof e)throw new TypeError("Argument must not be a number");return i(e,r,t)},s.alloc=function(e,r,t){if("number"!=typeof e)throw new TypeError("Argument must be a number");var n=i(e);return void 0!==r?"string"==typeof t?n.fill(r,t):n.fill(r):n.fill(0),n},s.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return i(e)},s.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return n.SlowBuffer(e)}}(M,M.exports)),M.exports}function K(){if(u)return c;u=1;var e=B().Buffer,r=n;function t(r){if(this.buffer=null,this.writable=!0,this.readable=!0,!r)return this.buffer=e.alloc(0),this;if("function"==typeof r.pipe)return this.buffer=e.alloc(0),r.pipe(this),this;if(r.length||"object"==typeof r)return this.buffer=r,this.writable=!1,process.nextTick(function(){this.emit("end",r),this.readable=!1,this.emit("close")}.bind(this)),this;throw new TypeError("Unexpected data type ("+typeof r+")")}return i.inherits(t,r),t.prototype.write=function(r){this.buffer=e.concat([this.buffer,e.from(r)]),this.emit("data",r)},t.prototype.end=function(e){e&&this.write(e),this.emit("end",e),this.emit("close"),this.writable=!1,this.readable=!1},c=t}function F(){if(h)return p;h=1;var e=B().Buffer,r=function(){if(f)return l;function e(e){return(e/8|0)+(e%8==0?0:1)}f=1;var r={ES256:e(256),ES384:e(384),ES512:e(521)};return l=function(e){var t=r[e];if(t)return t;throw new Error('Unknown algorithm "'+e+'"')}}(),t=128;function n(r){if(e.isBuffer(r))return r;if("string"==typeof r)return e.from(r,"base64");throw new TypeError("ECDSA signature must be a Base64 string or a Buffer")}function i(e,r,n){for(var i=0;r+i<n&&0===e[r+i];)++i;return e[r+i]>=t&&--i,i}return p={derToJose:function(t,i){t=n(t);var o=r(i),s=o+1,a=t.length,c=0;if(48!==t[c++])throw new Error('Could not find expected "seq"');var u=t[c++];if(129===u&&(u=t[c++]),a-c<u)throw new Error('"seq" specified length of "'+u+'", only "'+(a-c)+'" remaining');if(2!==t[c++])throw new Error('Could not find expected "int" for "r"');var l=t[c++];if(a-c-2<l)throw new Error('"r" specified length of "'+l+'", only "'+(a-c-2)+'" available');if(s<l)throw new Error('"r" specified length of "'+l+'", max of "'+s+'" is acceptable');var f=c;if(c+=l,2!==t[c++])throw new Error('Could not find expected "int" for "s"');var p=t[c++];if(a-c!==p)throw new Error('"s" specified length of "'+p+'", expected "'+(a-c)+'"');if(s<p)throw new Error('"s" specified length of "'+p+'", max of "'+s+'" is acceptable');var h=c;if((c+=p)!==a)throw new Error('Expected to consume entire buffer, but "'+(a-c)+'" bytes remain');var d=o-l,m=o-p,g=e.allocUnsafe(d+l+m+p);for(c=0;c<d;++c)g[c]=0;t.copy(g,c,f+Math.max(-d,0),f+l);for(var E=c=o;c<E+m;++c)g[c]=0;return t.copy(g,c,h+Math.max(-m,0),h+p),g=(g=g.toString("base64")).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")},joseToDer:function(o,s){o=n(o);var a=r(s),c=o.length;if(c!==2*a)throw new TypeError('"'+s+'" signatures must be "'+2*a+'" bytes, saw "'+c+'"');var u=i(o,0,a),l=i(o,a,o.length),f=a-u,p=a-l,h=2+f+1+1+p,d=h<t,m=e.allocUnsafe((d?2:3)+h),g=0;return m[g++]=48,d?m[g++]=h:(m[g++]=129,m[g++]=255&h),m[g++]=2,m[g++]=f,u<0?(m[g++]=0,g+=o.copy(m,g,0,a)):g+=o.copy(m,g,u,a),m[g++]=2,m[g++]=p,l<0?(m[g++]=0,o.copy(m,g,a)):o.copy(m,g,a+l),m}}}function G(){if(E)return g;E=1;var e,r=B().Buffer,n=o,s=F(),a=i,c="secret must be a string or buffer",u="key must be a string or a buffer",l="function"==typeof n.createPublicKey;function f(e){if(!r.isBuffer(e)&&"string"!=typeof e){if(!l)throw w(u);if("object"!=typeof e)throw w(u);if("string"!=typeof e.type)throw w(u);if("string"!=typeof e.asymmetricKeyType)throw w(u);if("function"!=typeof e.export)throw w(u)}}function p(e){if(!r.isBuffer(e)&&"string"!=typeof e&&"object"!=typeof e)throw w("key must be a string, a buffer or an object")}function h(e){return e.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function y(e){var r=4-(e=e.toString()).length%4;if(4!==r)for(var t=0;t<r;++t)e+="=";return e.replace(/\-/g,"+").replace(/_/g,"/")}function w(e){var r=[].slice.call(arguments,1),t=a.format.bind(a,e).apply(null,r);return new TypeError(t)}function b(e){var t;return t=e,r.isBuffer(t)||"string"==typeof t||(e=JSON.stringify(e)),e}function v(e){return function(t,i){!function(e){if(!r.isBuffer(e)){if("string"==typeof e)return e;if(!l)throw w(c);if("object"!=typeof e)throw w(c);if("secret"!==e.type)throw w(c);if("function"!=typeof e.export)throw w(c)}}(i),t=b(t);var o=n.createHmac("sha"+e,i);return h((o.update(t),o.digest("base64")))}}l&&(u+=" or a KeyObject",c+="or a KeyObject");var S="timingSafeEqual"in n?function(e,r){return e.byteLength===r.byteLength&&n.timingSafeEqual(e,r)}:function(r,n){return e||(e=function(){if(m)return d;m=1;var e=t.Buffer,r=t.SlowBuffer;function n(r,t){if(!e.isBuffer(r)||!e.isBuffer(t))return!1;if(r.length!==t.length)return!1;for(var n=0,i=0;i<r.length;i++)n|=r[i]^t[i];return 0===n}d=n,n.install=function(){e.prototype.equal=r.prototype.equal=function(e){return n(this,e)}};var i=e.prototype.equal,o=r.prototype.equal;return n.restore=function(){e.prototype.equal=i,r.prototype.equal=o},d}()),e(r,n)};function $(e){return function(t,n,i){var o=v(e)(t,i);return S(r.from(n),r.from(o))}}function I(e){return function(r,t){p(t),r=b(r);var i=n.createSign("RSA-SHA"+e);return h((i.update(r),i.sign(t,"base64")))}}function A(e){return function(r,t,i){f(i),r=b(r),t=y(t);var o=n.createVerify("RSA-SHA"+e);return o.update(r),o.verify(i,t,"base64")}}function R(e){return function(r,t){p(t),r=b(r);var i=n.createSign("RSA-SHA"+e);return h((i.update(r),i.sign({key:t,padding:n.constants.RSA_PKCS1_PSS_PADDING,saltLength:n.constants.RSA_PSS_SALTLEN_DIGEST},"base64")))}}function O(e){return function(r,t,i){f(i),r=b(r),t=y(t);var o=n.createVerify("RSA-SHA"+e);return o.update(r),o.verify({key:i,padding:n.constants.RSA_PKCS1_PSS_PADDING,saltLength:n.constants.RSA_PSS_SALTLEN_DIGEST},t,"base64")}}function L(e){var r=I(e);return function(){var t=r.apply(null,arguments);return t=s.derToJose(t,"ES"+e)}}function T(e){var r=A(e);return function(t,n,i){return n=s.joseToDer(n,"ES"+e).toString("base64"),r(t,n,i)}}function N(){return function(){return""}}function x(){return function(e,r){return""===r}}return g=function(e){var r={hs:v,rs:I,ps:R,es:L,none:N},t={hs:$,rs:A,ps:O,es:T,none:x},n=e.match(/^(RS|PS|ES|HS)(256|384|512)$|^(none)$/);if(!n)throw w('"%s" is not a valid algorithm.\n Supported algorithms are:\n "HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "PS256", "PS384", "PS512", "ES256", "ES384", "ES512" and "none".',e);var i=(n[1]||n[3]).toLowerCase(),o=n[2];return{sign:r[i](o),verify:t[i](o)}}}function U(){if(w)return y;w=1;var e=t.Buffer;return y=function(r){return"string"==typeof r?r:"number"==typeof r||e.isBuffer(r)?r.toString():JSON.stringify(r)}}function H(){if(v)return b;v=1;var e=B().Buffer,r=K(),t=G(),o=n,s=U(),a=i;function c(r,t){return e.from(r,t).toString("base64").replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function u(e){var r=e.header,n=e.payload,i=e.secret||e.privateKey,o=e.encoding,u=t(r.alg),l=function(e,r,t){t=t||"utf8";var n=c(s(e),"binary"),i=c(s(r),t);return a.format("%s.%s",n,i)}(r,n,o),f=u.sign(l,i);return a.format("%s.%s",l,f)}function l(e){var t=e.secret;if(t=null==(t=null==t?e.privateKey:t)?e.key:t,!0===/^hs/i.test(e.header.alg)&&null==t)throw new TypeError("secret must be a string or buffer or a KeyObject");var n=new r(t);this.readable=!0,this.header=e.header,this.encoding=e.encoding,this.secret=this.privateKey=this.key=n,this.payload=new r(e.payload),this.secret.once("close",function(){!this.payload.writable&&this.readable&&this.sign()}.bind(this)),this.payload.once("close",function(){!this.secret.writable&&this.readable&&this.sign()}.bind(this))}return a.inherits(l,o),l.prototype.sign=function(){try{var e=u({header:this.header,payload:this.payload.buffer,secret:this.secret.buffer,encoding:this.encoding});return this.emit("done",e),this.emit("data",e),this.emit("end"),this.readable=!1,e}catch(e){this.readable=!1,this.emit("error",e),this.emit("close")}},l.sign=u,b=l}function V(){if($)return S;$=1;var e=B().Buffer,r=K(),t=G(),o=n,s=U(),a=/^[a-zA-Z0-9\-_]+?\.[a-zA-Z0-9\-_]+?\.([a-zA-Z0-9\-_]+)?$/;function c(e){if(function(e){return"[object Object]"===Object.prototype.toString.call(e)}(e))return e;try{return JSON.parse(e)}catch(e){return}}function u(r){var t=r.split(".",1)[0];return c(e.from(t,"base64").toString("binary"))}function l(e){return e.split(".")[2]}function f(e){return a.test(e)&&!!u(e)}function p(e,r,n){if(!r){var i=new Error("Missing algorithm parameter for jws.verify");throw i.code="MISSING_ALGORITHM",i}var o=l(e=s(e)),a=function(e){return e.split(".",2).join(".")}(e);return t(r).verify(a,o,n)}function h(r,t){if(t=t||{},!f(r=s(r)))return null;var n=u(r);if(!n)return null;var i=function(r,t){t=t||"utf8";var n=r.split(".")[1];return e.from(n,"base64").toString(t)}(r);return("JWT"===n.typ||t.json)&&(i=JSON.parse(i,t.encoding)),{header:n,payload:i,signature:l(r)}}function d(e){var t=(e=e||{}).secret;if(t=null==(t=null==t?e.publicKey:t)?e.key:t,!0===/^hs/i.test(e.algorithm)&&null==t)throw new TypeError("secret must be a string or buffer or a KeyObject");var n=new r(t);this.readable=!0,this.algorithm=e.algorithm,this.encoding=e.encoding,this.secret=this.publicKey=this.key=n,this.signature=new r(e.signature),this.secret.once("close",function(){!this.signature.writable&&this.readable&&this.verify()}.bind(this)),this.signature.once("close",function(){!this.secret.writable&&this.readable&&this.verify()}.bind(this))}return i.inherits(d,o),d.prototype.verify=function(){try{var e=p(this.signature.buffer,this.algorithm,this.key.buffer),r=h(this.signature.buffer,this.encoding);return this.emit("done",e,r),this.emit("data",e),this.emit("end"),this.readable=!1,e}catch(e){this.readable=!1,this.emit("error",e),this.emit("close")}},d.decode=h,d.isValid=f,d.verify=p,S=d}function q(){if(I)return D;I=1;var e=H(),r=V();return D.ALGORITHMS=["HS256","HS384","HS512","RS256","RS384","RS512","PS256","PS384","PS512","ES256","ES384","ES512"],D.sign=e.sign,D.verify=r.verify,D.decode=r.decode,D.isValid=r.isValid,D.createSign=function(r){return new e(r)},D.createVerify=function(e){return new r(e)},D}function z(){if(R)return A;R=1;var e=q();return A=function(r,t){t=t||{};var n=e.decode(r,t);if(!n)return null;var i=n.payload;if("string"==typeof i)try{var o=JSON.parse(i);null!==o&&"object"==typeof o&&(i=o)}catch(e){}return!0===t.complete?{header:n.header,payload:i,signature:n.signature}:i},A}function X(){if(L)return O;L=1;var e=function(e,r){Error.call(this,e),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.name="JsonWebTokenError",this.message=e,r&&(this.inner=r)};return(e.prototype=Object.create(Error.prototype)).constructor=e,O=e}function Y(){if(N)return T;N=1;var e=X(),r=function(r,t){e.call(this,r),this.name="NotBeforeError",this.date=t};return(r.prototype=Object.create(e.prototype)).constructor=r,T=r}function W(){if(k)return x;k=1;var e=X(),r=function(r,t){e.call(this,r),this.name="TokenExpiredError",this.expiredAt=t};return(r.prototype=Object.create(e.prototype)).constructor=r,x=r}function J(){if(_)return j;_=1;var e=1e3,r=60*e,t=60*r,n=24*t,i=7*n,o=365.25*n;function s(e,r,t,n){var i=r>=1.5*t;return Math.round(e/t)+" "+n+(i?"s":"")}return j=function(a,c){c=c||{};var u=typeof a;if("string"===u&&a.length>0)return function(s){if((s=String(s)).length>100)return;var a=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(s);if(!a)return;var c=parseFloat(a[1]);switch((a[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return c*o;case"weeks":case"week":case"w":return c*i;case"days":case"day":case"d":return c*n;case"hours":case"hour":case"hrs":case"hr":case"h":return c*t;case"minutes":case"minute":case"mins":case"min":case"m":return c*r;case"seconds":case"second":case"secs":case"sec":case"s":return c*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return c;default:return}}(a);if("number"===u&&isFinite(a))return c.long?function(i){var o=Math.abs(i);if(o>=n)return s(i,o,n,"day");if(o>=t)return s(i,o,t,"hour");if(o>=r)return s(i,o,r,"minute");if(o>=e)return s(i,o,e,"second");return i+" ms"}(a):function(i){var o=Math.abs(i);if(o>=n)return Math.round(i/n)+"d";if(o>=t)return Math.round(i/t)+"h";if(o>=r)return Math.round(i/r)+"m";if(o>=e)return Math.round(i/e)+"s";return i+"ms"}(a);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(a))}}function Z(){if(C)return P;C=1;var e=J();return P=function(r,t){var n=t||Math.floor(Date.now()/1e3);if("string"==typeof r){var i=e(r);if(void 0===i)return;return Math.floor(n+i/1e3)}return"number"==typeof r?n+r:void 0}}var Q,ee,re,te,ne,ie,oe,se,ae,ce,ue,le,fe,pe,he,de,me,ge,Ee,ye,we,be,ve,Se,$e,Ie,Ae,Re,Oe,Le,Te,Ne,xe,ke,je,_e,Pe,Ce,De,Me,Be,Ke,Fe,Ge,Ue,He,Ve,qe,ze,Xe,Ye,We,Je,Ze,Qe,er,rr,tr,nr,ir,or,sr,ar,cr,ur,lr,fr,pr,hr,dr,mr,gr,Er,yr,wr,br,vr,Sr,$r,Ir,Ar,Rr,Or,Lr,Tr,Nr,xr,kr,jr,_r,Pr,Cr,Dr,Mr,Br,Kr,Fr,Gr,Ur,Hr,Vr,qr,zr,Xr,Yr,Wr,Jr,Zr,Qr,et,rt,tt,nt,it,ot,st,at,ct={exports:{}};function ut(){if(ee)return Q;ee=1;const e=Number.MAX_SAFE_INTEGER||9007199254740991;return Q={MAX_LENGTH:256,MAX_SAFE_COMPONENT_LENGTH:16,MAX_SAFE_BUILD_LENGTH:250,MAX_SAFE_INTEGER:e,RELEASE_TYPES:["major","premajor","minor","preminor","patch","prepatch","prerelease"],SEMVER_SPEC_VERSION:"2.0.0",FLAG_INCLUDE_PRERELEASE:1,FLAG_LOOSE:2}}function lt(){if(te)return re;te=1;const e="object"==typeof process&&process.env&&process.env.NODE_DEBUG&&/\bsemver\b/i.test(process.env.NODE_DEBUG)?(...e)=>console.error("SEMVER",...e):()=>{};return re=e}function ft(){return ne||(ne=1,function(e,r){const{MAX_SAFE_COMPONENT_LENGTH:t,MAX_SAFE_BUILD_LENGTH:n,MAX_LENGTH:i}=ut(),o=lt(),s=(r=e.exports={}).re=[],a=r.safeRe=[],c=r.src=[],u=r.safeSrc=[],l=r.t={};let f=0;const p="[a-zA-Z0-9-]",h=[["\\s",1],["\\d",i],[p,n]],d=(e,r,t)=>{const n=(e=>{for(const[r,t]of h)e=e.split(`${r}*`).join(`${r}{0,${t}}`).split(`${r}+`).join(`${r}{1,${t}}`);return e})(r),i=f++;o(e,i,r),l[e]=i,c[i]=r,u[i]=n,s[i]=new RegExp(r,t?"g":void 0),a[i]=new RegExp(n,t?"g":void 0)};d("NUMERICIDENTIFIER","0|[1-9]\\d*"),d("NUMERICIDENTIFIERLOOSE","\\d+"),d("NONNUMERICIDENTIFIER",`\\d*[a-zA-Z-]${p}*`),d("MAINVERSION",`(${c[l.NUMERICIDENTIFIER]})\\.(${c[l.NUMERICIDENTIFIER]})\\.(${c[l.NUMERICIDENTIFIER]})`),d("MAINVERSIONLOOSE",`(${c[l.NUMERICIDENTIFIERLOOSE]})\\.(${c[l.NUMERICIDENTIFIERLOOSE]})\\.(${c[l.NUMERICIDENTIFIERLOOSE]})`),d("PRERELEASEIDENTIFIER",`(?:${c[l.NONNUMERICIDENTIFIER]}|${c[l.NUMERICIDENTIFIER]})`),d("PRERELEASEIDENTIFIERLOOSE",`(?:${c[l.NONNUMERICIDENTIFIER]}|${c[l.NUMERICIDENTIFIERLOOSE]})`),d("PRERELEASE",`(?:-(${c[l.PRERELEASEIDENTIFIER]}(?:\\.${c[l.PRERELEASEIDENTIFIER]})*))`),d("PRERELEASELOOSE",`(?:-?(${c[l.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${c[l.PRERELEASEIDENTIFIERLOOSE]})*))`),d("BUILDIDENTIFIER",`${p}+`),d("BUILD",`(?:\\+(${c[l.BUILDIDENTIFIER]}(?:\\.${c[l.BUILDIDENTIFIER]})*))`),d("FULLPLAIN",`v?${c[l.MAINVERSION]}${c[l.PRERELEASE]}?${c[l.BUILD]}?`),d("FULL",`^${c[l.FULLPLAIN]}$`),d("LOOSEPLAIN",`[v=\\s]*${c[l.MAINVERSIONLOOSE]}${c[l.PRERELEASELOOSE]}?${c[l.BUILD]}?`),d("LOOSE",`^${c[l.LOOSEPLAIN]}$`),d("GTLT","((?:<|>)?=?)"),d("XRANGEIDENTIFIERLOOSE",`${c[l.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`),d("XRANGEIDENTIFIER",`${c[l.NUMERICIDENTIFIER]}|x|X|\\*`),d("XRANGEPLAIN",`[v=\\s]*(${c[l.XRANGEIDENTIFIER]})(?:\\.(${c[l.XRANGEIDENTIFIER]})(?:\\.(${c[l.XRANGEIDENTIFIER]})(?:${c[l.PRERELEASE]})?${c[l.BUILD]}?)?)?`),d("XRANGEPLAINLOOSE",`[v=\\s]*(${c[l.XRANGEIDENTIFIERLOOSE]})(?:\\.(${c[l.XRANGEIDENTIFIERLOOSE]})(?:\\.(${c[l.XRANGEIDENTIFIERLOOSE]})(?:${c[l.PRERELEASELOOSE]})?${c[l.BUILD]}?)?)?`),d("XRANGE",`^${c[l.GTLT]}\\s*${c[l.XRANGEPLAIN]}$`),d("XRANGELOOSE",`^${c[l.GTLT]}\\s*${c[l.XRANGEPLAINLOOSE]}$`),d("COERCEPLAIN",`(^|[^\\d])(\\d{1,${t}})(?:\\.(\\d{1,${t}}))?(?:\\.(\\d{1,${t}}))?`),d("COERCE",`${c[l.COERCEPLAIN]}(?:$|[^\\d])`),d("COERCEFULL",c[l.COERCEPLAIN]+`(?:${c[l.PRERELEASE]})?`+`(?:${c[l.BUILD]})?(?:$|[^\\d])`),d("COERCERTL",c[l.COERCE],!0),d("COERCERTLFULL",c[l.COERCEFULL],!0),d("LONETILDE","(?:~>?)"),d("TILDETRIM",`(\\s*)${c[l.LONETILDE]}\\s+`,!0),r.tildeTrimReplace="$1~",d("TILDE",`^${c[l.LONETILDE]}${c[l.XRANGEPLAIN]}$`),d("TILDELOOSE",`^${c[l.LONETILDE]}${c[l.XRANGEPLAINLOOSE]}$`),d("LONECARET","(?:\\^)"),d("CARETTRIM",`(\\s*)${c[l.LONECARET]}\\s+`,!0),r.caretTrimReplace="$1^",d("CARET",`^${c[l.LONECARET]}${c[l.XRANGEPLAIN]}$`),d("CARETLOOSE",`^${c[l.LONECARET]}${c[l.XRANGEPLAINLOOSE]}$`),d("COMPARATORLOOSE",`^${c[l.GTLT]}\\s*(${c[l.LOOSEPLAIN]})$|^$`),d("COMPARATOR",`^${c[l.GTLT]}\\s*(${c[l.FULLPLAIN]})$|^$`),d("COMPARATORTRIM",`(\\s*)${c[l.GTLT]}\\s*(${c[l.LOOSEPLAIN]}|${c[l.XRANGEPLAIN]})`,!0),r.comparatorTrimReplace="$1$2$3",d("HYPHENRANGE",`^\\s*(${c[l.XRANGEPLAIN]})\\s+-\\s+(${c[l.XRANGEPLAIN]})\\s*$`),d("HYPHENRANGELOOSE",`^\\s*(${c[l.XRANGEPLAINLOOSE]})\\s+-\\s+(${c[l.XRANGEPLAINLOOSE]})\\s*$`),d("STAR","(<|>)?=?\\s*\\*"),d("GTE0","^\\s*>=\\s*0\\.0\\.0\\s*$"),d("GTE0PRE","^\\s*>=\\s*0\\.0\\.0-0\\s*$")}(ct,ct.exports)),ct.exports}function pt(){if(oe)return ie;oe=1;const e=Object.freeze({loose:!0}),r=Object.freeze({});return ie=t=>t?"object"!=typeof t?e:t:r}function ht(){if(ae)return se;ae=1;const e=/^[0-9]+$/,r=(r,t)=>{if("number"==typeof r&&"number"==typeof t)return r===t?0:r<t?-1:1;const n=e.test(r),i=e.test(t);return n&&i&&(r=+r,t=+t),r===t?0:n&&!i?-1:i&&!n?1:r<t?-1:1};return se={compareIdentifiers:r,rcompareIdentifiers:(e,t)=>r(t,e)}}function dt(){if(ue)return ce;ue=1;const e=lt(),{MAX_LENGTH:r,MAX_SAFE_INTEGER:t}=ut(),{safeRe:n,t:i}=ft(),o=pt(),{compareIdentifiers:s}=ht();class a{constructor(s,c){if(c=o(c),s instanceof a){if(s.loose===!!c.loose&&s.includePrerelease===!!c.includePrerelease)return s;s=s.version}else if("string"!=typeof s)throw new TypeError(`Invalid version. Must be a string. Got type "${typeof s}".`);if(s.length>r)throw new TypeError(`version is longer than ${r} characters`);e("SemVer",s,c),this.options=c,this.loose=!!c.loose,this.includePrerelease=!!c.includePrerelease;const u=s.trim().match(c.loose?n[i.LOOSE]:n[i.FULL]);if(!u)throw new TypeError(`Invalid Version: ${s}`);if(this.raw=s,this.major=+u[1],this.minor=+u[2],this.patch=+u[3],this.major>t||this.major<0)throw new TypeError("Invalid major version");if(this.minor>t||this.minor<0)throw new TypeError("Invalid minor version");if(this.patch>t||this.patch<0)throw new TypeError("Invalid patch version");u[4]?this.prerelease=u[4].split(".").map(e=>{if(/^[0-9]+$/.test(e)){const r=+e;if(r>=0&&r<t)return r}return e}):this.prerelease=[],this.build=u[5]?u[5].split("."):[],this.format()}format(){return this.version=`${this.major}.${this.minor}.${this.patch}`,this.prerelease.length&&(this.version+=`-${this.prerelease.join(".")}`),this.version}toString(){return this.version}compare(r){if(e("SemVer.compare",this.version,this.options,r),!(r instanceof a)){if("string"==typeof r&&r===this.version)return 0;r=new a(r,this.options)}return r.version===this.version?0:this.compareMain(r)||this.comparePre(r)}compareMain(e){return e instanceof a||(e=new a(e,this.options)),this.major<e.major?-1:this.major>e.major?1:this.minor<e.minor?-1:this.minor>e.minor?1:this.patch<e.patch?-1:this.patch>e.patch?1:0}comparePre(r){if(r instanceof a||(r=new a(r,this.options)),this.prerelease.length&&!r.prerelease.length)return-1;if(!this.prerelease.length&&r.prerelease.length)return 1;if(!this.prerelease.length&&!r.prerelease.length)return 0;let t=0;do{const n=this.prerelease[t],i=r.prerelease[t];if(e("prerelease compare",t,n,i),void 0===n&&void 0===i)return 0;if(void 0===i)return 1;if(void 0===n)return-1;if(n!==i)return s(n,i)}while(++t)}compareBuild(r){r instanceof a||(r=new a(r,this.options));let t=0;do{const n=this.build[t],i=r.build[t];if(e("build compare",t,n,i),void 0===n&&void 0===i)return 0;if(void 0===i)return 1;if(void 0===n)return-1;if(n!==i)return s(n,i)}while(++t)}inc(e,r,t){if(e.startsWith("pre")){if(!r&&!1===t)throw new Error("invalid increment argument: identifier is empty");if(r){const e=`-${r}`.match(this.options.loose?n[i.PRERELEASELOOSE]:n[i.PRERELEASE]);if(!e||e[1]!==r)throw new Error(`invalid identifier: ${r}`)}}switch(e){case"premajor":this.prerelease.length=0,this.patch=0,this.minor=0,this.major++,this.inc("pre",r,t);break;case"preminor":this.prerelease.length=0,this.patch=0,this.minor++,this.inc("pre",r,t);break;case"prepatch":this.prerelease.length=0,this.inc("patch",r,t),this.inc("pre",r,t);break;case"prerelease":0===this.prerelease.length&&this.inc("patch",r,t),this.inc("pre",r,t);break;case"release":if(0===this.prerelease.length)throw new Error(`version ${this.raw} is not a prerelease`);this.prerelease.length=0;break;case"major":0===this.minor&&0===this.patch&&0!==this.prerelease.length||this.major++,this.minor=0,this.patch=0,this.prerelease=[];break;case"minor":0===this.patch&&0!==this.prerelease.length||this.minor++,this.patch=0,this.prerelease=[];break;case"patch":0===this.prerelease.length&&this.patch++,this.prerelease=[];break;case"pre":{const e=Number(t)?1:0;if(0===this.prerelease.length)this.prerelease=[e];else{let n=this.prerelease.length;for(;--n>=0;)"number"==typeof this.prerelease[n]&&(this.prerelease[n]++,n=-2);if(-1===n){if(r===this.prerelease.join(".")&&!1===t)throw new Error("invalid increment argument: identifier already exists");this.prerelease.push(e)}}if(r){let n=[r,e];!1===t&&(n=[r]),0===s(this.prerelease[0],r)?isNaN(this.prerelease[1])&&(this.prerelease=n):this.prerelease=n}break}default:throw new Error(`invalid increment argument: ${e}`)}return this.raw=this.format(),this.build.length&&(this.raw+=`+${this.build.join(".")}`),this}}return ce=a}function mt(){if(fe)return le;fe=1;const e=dt();return le=(r,t,n=!1)=>{if(r instanceof e)return r;try{return new e(r,t)}catch(e){if(!n)return null;throw e}},le}function gt(){if(Te)return Le;Te=1;const e=dt();return Le=(r,t,n)=>new e(r,n).compare(new e(t,n))}function Et(){if(Pe)return _e;Pe=1;const e=dt();return _e=(r,t,n)=>{const i=new e(r,n),o=new e(t,n);return i.compare(o)||i.compareBuild(o)}}function yt(){if(Fe)return Ke;Fe=1;const e=gt();return Ke=(r,t,n)=>e(r,t,n)>0}function wt(){if(Ue)return Ge;Ue=1;const e=gt();return Ge=(r,t,n)=>e(r,t,n)<0}function bt(){if(Ve)return He;Ve=1;const e=gt();return He=(r,t,n)=>0===e(r,t,n)}function vt(){if(ze)return qe;ze=1;const e=gt();return qe=(r,t,n)=>0!==e(r,t,n)}function St(){if(Ye)return Xe;Ye=1;const e=gt();return Xe=(r,t,n)=>e(r,t,n)>=0}function $t(){if(Je)return We;Je=1;const e=gt();return We=(r,t,n)=>e(r,t,n)<=0}function It(){if(Qe)return Ze;Qe=1;const e=bt(),r=vt(),t=yt(),n=St(),i=wt(),o=$t();return Ze=(s,a,c,u)=>{switch(a){case"===":return"object"==typeof s&&(s=s.version),"object"==typeof c&&(c=c.version),s===c;case"!==":return"object"==typeof s&&(s=s.version),"object"==typeof c&&(c=c.version),s!==c;case"":case"=":case"==":return e(s,c,u);case"!=":return r(s,c,u);case">":return t(s,c,u);case">=":return n(s,c,u);case"<":return i(s,c,u);case"<=":return o(s,c,u);default:throw new TypeError(`Invalid operator: ${a}`)}}}function At(){if(or)return ir;or=1;const e=/\s+/g;class r{constructor(t,o){if(o=n(o),t instanceof r)return t.loose===!!o.loose&&t.includePrerelease===!!o.includePrerelease?t:new r(t.raw,o);if(t instanceof i)return this.raw=t.value,this.set=[[t]],this.formatted=void 0,this;if(this.options=o,this.loose=!!o.loose,this.includePrerelease=!!o.includePrerelease,this.raw=t.trim().replace(e," "),this.set=this.raw.split("||").map(e=>this.parseRange(e.trim())).filter(e=>e.length),!this.set.length)throw new TypeError(`Invalid SemVer Range: ${this.raw}`);if(this.set.length>1){const e=this.set[0];if(this.set=this.set.filter(e=>!d(e[0])),0===this.set.length)this.set=[e];else if(this.set.length>1)for(const e of this.set)if(1===e.length&&m(e[0])){this.set=[e];break}}this.formatted=void 0}get range(){if(void 0===this.formatted){this.formatted="";for(let e=0;e<this.set.length;e++){e>0&&(this.formatted+="||");const r=this.set[e];for(let e=0;e<r.length;e++)e>0&&(this.formatted+=" "),this.formatted+=r[e].toString().trim()}}return this.formatted}format(){return this.range}toString(){return this.range}parseRange(e){const r=((this.options.includePrerelease&&p)|(this.options.loose&&h))+":"+e,n=t.get(r);if(n)return n;const s=this.options.loose,m=s?a[c.HYPHENRANGELOOSE]:a[c.HYPHENRANGE];e=e.replace(m,O(this.options.includePrerelease)),o("hyphen replace",e),e=e.replace(a[c.COMPARATORTRIM],u),o("comparator trim",e),e=e.replace(a[c.TILDETRIM],l),o("tilde trim",e),e=e.replace(a[c.CARETTRIM],f),o("caret trim",e);let g=e.split(" ").map(e=>E(e,this.options)).join(" ").split(/\s+/).map(e=>R(e,this.options));s&&(g=g.filter(e=>(o("loose invalid filter",e,this.options),!!e.match(a[c.COMPARATORLOOSE])))),o("range list",g);const y=new Map,w=g.map(e=>new i(e,this.options));for(const e of w){if(d(e))return[e];y.set(e.value,e)}y.size>1&&y.has("")&&y.delete("");const b=[...y.values()];return t.set(r,b),b}intersects(e,t){if(!(e instanceof r))throw new TypeError("a Range is required");return this.set.some(r=>g(r,t)&&e.set.some(e=>g(e,t)&&r.every(r=>e.every(e=>r.intersects(e,t)))))}test(e){if(!e)return!1;if("string"==typeof e)try{e=new s(e,this.options)}catch(e){return!1}for(let r=0;r<this.set.length;r++)if(L(this.set[r],e,this.options))return!0;return!1}}ir=r;const t=new(nr?tr:(nr=1,tr=class{constructor(){this.max=1e3,this.map=new Map}get(e){const r=this.map.get(e);return void 0===r?void 0:(this.map.delete(e),this.map.set(e,r),r)}delete(e){return this.map.delete(e)}set(e,r){if(!this.delete(e)&&void 0!==r){if(this.map.size>=this.max){const e=this.map.keys().next().value;this.delete(e)}this.map.set(e,r)}return this}})),n=pt(),i=Rt(),o=lt(),s=dt(),{safeRe:a,t:c,comparatorTrimReplace:u,tildeTrimReplace:l,caretTrimReplace:f}=ft(),{FLAG_INCLUDE_PRERELEASE:p,FLAG_LOOSE:h}=ut(),d=e=>"<0.0.0-0"===e.value,m=e=>""===e.value,g=(e,r)=>{let t=!0;const n=e.slice();let i=n.pop();for(;t&&n.length;)t=n.every(e=>i.intersects(e,r)),i=n.pop();return t},E=(e,r)=>(e=e.replace(a[c.BUILD],""),o("comp",e,r),e=v(e,r),o("caret",e),e=w(e,r),o("tildes",e),e=$(e,r),o("xrange",e),e=A(e,r),o("stars",e),e),y=e=>!e||"x"===e.toLowerCase()||"*"===e,w=(e,r)=>e.trim().split(/\s+/).map(e=>b(e,r)).join(" "),b=(e,r)=>{const t=r.loose?a[c.TILDELOOSE]:a[c.TILDE];return e.replace(t,(r,t,n,i,s)=>{let a;return o("tilde",e,r,t,n,i,s),y(t)?a="":y(n)?a=`>=${t}.0.0 <${+t+1}.0.0-0`:y(i)?a=`>=${t}.${n}.0 <${t}.${+n+1}.0-0`:s?(o("replaceTilde pr",s),a=`>=${t}.${n}.${i}-${s} <${t}.${+n+1}.0-0`):a=`>=${t}.${n}.${i} <${t}.${+n+1}.0-0`,o("tilde return",a),a})},v=(e,r)=>e.trim().split(/\s+/).map(e=>S(e,r)).join(" "),S=(e,r)=>{o("caret",e,r);const t=r.loose?a[c.CARETLOOSE]:a[c.CARET],n=r.includePrerelease?"-0":"";return e.replace(t,(r,t,i,s,a)=>{let c;return o("caret",e,r,t,i,s,a),y(t)?c="":y(i)?c=`>=${t}.0.0${n} <${+t+1}.0.0-0`:y(s)?c="0"===t?`>=${t}.${i}.0${n} <${t}.${+i+1}.0-0`:`>=${t}.${i}.0${n} <${+t+1}.0.0-0`:a?(o("replaceCaret pr",a),c="0"===t?"0"===i?`>=${t}.${i}.${s}-${a} <${t}.${i}.${+s+1}-0`:`>=${t}.${i}.${s}-${a} <${t}.${+i+1}.0-0`:`>=${t}.${i}.${s}-${a} <${+t+1}.0.0-0`):(o("no pr"),c="0"===t?"0"===i?`>=${t}.${i}.${s}${n} <${t}.${i}.${+s+1}-0`:`>=${t}.${i}.${s}${n} <${t}.${+i+1}.0-0`:`>=${t}.${i}.${s} <${+t+1}.0.0-0`),o("caret return",c),c})},$=(e,r)=>(o("replaceXRanges",e,r),e.split(/\s+/).map(e=>I(e,r)).join(" ")),I=(e,r)=>{e=e.trim();const t=r.loose?a[c.XRANGELOOSE]:a[c.XRANGE];return e.replace(t,(t,n,i,s,a,c)=>{o("xRange",e,t,n,i,s,a,c);const u=y(i),l=u||y(s),f=l||y(a),p=f;return"="===n&&p&&(n=""),c=r.includePrerelease?"-0":"",u?t=">"===n||"<"===n?"<0.0.0-0":"*":n&&p?(l&&(s=0),a=0,">"===n?(n=">=",l?(i=+i+1,s=0,a=0):(s=+s+1,a=0)):"<="===n&&(n="<",l?i=+i+1:s=+s+1),"<"===n&&(c="-0"),t=`${n+i}.${s}.${a}${c}`):l?t=`>=${i}.0.0${c} <${+i+1}.0.0-0`:f&&(t=`>=${i}.${s}.0${c} <${i}.${+s+1}.0-0`),o("xRange return",t),t})},A=(e,r)=>(o("replaceStars",e,r),e.trim().replace(a[c.STAR],"")),R=(e,r)=>(o("replaceGTE0",e,r),e.trim().replace(a[r.includePrerelease?c.GTE0PRE:c.GTE0],"")),O=e=>(r,t,n,i,o,s,a,c,u,l,f,p)=>`${t=y(n)?"":y(i)?`>=${n}.0.0${e?"-0":""}`:y(o)?`>=${n}.${i}.0${e?"-0":""}`:s?`>=${t}`:`>=${t}${e?"-0":""}`} ${c=y(u)?"":y(l)?`<${+u+1}.0.0-0`:y(f)?`<${u}.${+l+1}.0-0`:p?`<=${u}.${l}.${f}-${p}`:e?`<${u}.${l}.${+f+1}-0`:`<=${c}`}`.trim(),L=(e,r,t)=>{for(let t=0;t<e.length;t++)if(!e[t].test(r))return!1;if(r.prerelease.length&&!t.includePrerelease){for(let t=0;t<e.length;t++)if(o(e[t].semver),e[t].semver!==i.ANY&&e[t].semver.prerelease.length>0){const n=e[t].semver;if(n.major===r.major&&n.minor===r.minor&&n.patch===r.patch)return!0}return!1}return!0};return ir}function Rt(){if(ar)return sr;ar=1;const e=Symbol("SemVer ANY");class r{static get ANY(){return e}constructor(n,i){if(i=t(i),n instanceof r){if(n.loose===!!i.loose)return n;n=n.value}n=n.trim().split(/\s+/).join(" "),s("comparator",n,i),this.options=i,this.loose=!!i.loose,this.parse(n),this.semver===e?this.value="":this.value=this.operator+this.semver.version,s("comp",this)}parse(r){const t=this.options.loose?n[i.COMPARATORLOOSE]:n[i.COMPARATOR],o=r.match(t);if(!o)throw new TypeError(`Invalid comparator: ${r}`);this.operator=void 0!==o[1]?o[1]:"","="===this.operator&&(this.operator=""),o[2]?this.semver=new a(o[2],this.options.loose):this.semver=e}toString(){return this.value}test(r){if(s("Comparator.test",r,this.options.loose),this.semver===e||r===e)return!0;if("string"==typeof r)try{r=new a(r,this.options)}catch(e){return!1}return o(r,this.operator,this.semver,this.options)}intersects(e,n){if(!(e instanceof r))throw new TypeError("a Comparator is required");return""===this.operator?""===this.value||new c(e.value,n).test(this.value):""===e.operator?""===e.value||new c(this.value,n).test(e.semver):(!(n=t(n)).includePrerelease||"<0.0.0-0"!==this.value&&"<0.0.0-0"!==e.value)&&(!(!n.includePrerelease&&(this.value.startsWith("<0.0.0")||e.value.startsWith("<0.0.0")))&&(!(!this.operator.startsWith(">")||!e.operator.startsWith(">"))||(!(!this.operator.startsWith("<")||!e.operator.startsWith("<"))||(!(this.semver.version!==e.semver.version||!this.operator.includes("=")||!e.operator.includes("="))||(!!(o(this.semver,"<",e.semver,n)&&this.operator.startsWith(">")&&e.operator.startsWith("<"))||!!(o(this.semver,">",e.semver,n)&&this.operator.startsWith("<")&&e.operator.startsWith(">")))))))}}sr=r;const t=pt(),{safeRe:n,t:i}=ft(),o=It(),s=lt(),a=dt(),c=At();return sr}function Ot(){if(ur)return cr;ur=1;const e=At();return cr=(r,t,n)=>{try{t=new e(t,n)}catch(e){return!1}return t.test(r)},cr}function Lt(){if(wr)return yr;wr=1;const e=At();return yr=(r,t)=>{try{return new e(r,t).range||"*"}catch(e){return null}},yr}function Tt(){if(vr)return br;vr=1;const e=dt(),r=Rt(),{ANY:t}=r,n=At(),i=Ot(),o=yt(),s=wt(),a=$t(),c=St();return br=(u,l,f,p)=>{let h,d,m,g,E;switch(u=new e(u,p),l=new n(l,p),f){case">":h=o,d=a,m=s,g=">",E=">=";break;case"<":h=s,d=c,m=o,g="<",E="<=";break;default:throw new TypeError('Must provide a hilo val of "<" or ">"')}if(i(u,l,p))return!1;for(let e=0;e<l.set.length;++e){const n=l.set[e];let i=null,o=null;if(n.forEach(e=>{e.semver===t&&(e=new r(">=0.0.0")),i=i||e,o=o||e,h(e.semver,i.semver,p)?i=e:m(e.semver,o.semver,p)&&(o=e)}),i.operator===g||i.operator===E)return!1;if((!o.operator||o.operator===g)&&d(u,o.semver))return!1;if(o.operator===E&&m(u,o.semver))return!1}return!0},br}function Nt(){if(jr)return kr;jr=1;const e=ft(),r=ut(),t=dt(),n=ht(),i=mt(),o=function(){if(he)return pe;he=1;const e=mt();return pe=(r,t)=>{const n=e(r,t);return n?n.version:null},pe}(),s=function(){if(me)return de;me=1;const e=mt();return de=(r,t)=>{const n=e(r.trim().replace(/^[=v]+/,""),t);return n?n.version:null},de}(),a=function(){if(Ee)return ge;Ee=1;const e=dt();return ge=(r,t,n,i,o)=>{"string"==typeof n&&(o=i,i=n,n=void 0);try{return new e(r instanceof e?r.version:r,n).inc(t,i,o).version}catch(e){return null}},ge}(),c=function(){if(we)return ye;we=1;const e=mt();return ye=(r,t)=>{const n=e(r,null,!0),i=e(t,null,!0),o=n.compare(i);if(0===o)return null;const s=o>0,a=s?n:i,c=s?i:n,u=!!a.prerelease.length;if(c.prerelease.length&&!u){if(!c.patch&&!c.minor)return"major";if(0===c.compareMain(a))return c.minor&&!c.patch?"minor":"patch"}const l=u?"pre":"";return n.major!==i.major?l+"major":n.minor!==i.minor?l+"minor":n.patch!==i.patch?l+"patch":"prerelease"}}(),u=function(){if(ve)return be;ve=1;const e=dt();return be=(r,t)=>new e(r,t).major}(),l=function(){if($e)return Se;$e=1;const e=dt();return Se=(r,t)=>new e(r,t).minor}(),f=function(){if(Ae)return Ie;Ae=1;const e=dt();return Ie=(r,t)=>new e(r,t).patch}(),p=function(){if(Oe)return Re;Oe=1;const e=mt();return Re=(r,t)=>{const n=e(r,t);return n&&n.prerelease.length?n.prerelease:null},Re}(),h=gt(),d=function(){if(xe)return Ne;xe=1;const e=gt();return Ne=(r,t,n)=>e(t,r,n)}(),m=function(){if(je)return ke;je=1;const e=gt();return ke=(r,t)=>e(r,t,!0)}(),g=Et(),E=function(){if(De)return Ce;De=1;const e=Et();return Ce=(r,t)=>r.sort((r,n)=>e(r,n,t))}(),y=function(){if(Be)return Me;Be=1;const e=Et();return Me=(r,t)=>r.sort((r,n)=>e(n,r,t))}(),w=yt(),b=wt(),v=bt(),S=vt(),$=St(),I=$t(),A=It(),R=function(){if(rr)return er;rr=1;const e=dt(),r=mt(),{safeRe:t,t:n}=ft();return er=(i,o)=>{if(i instanceof e)return i;if("number"==typeof i&&(i=String(i)),"string"!=typeof i)return null;let s=null;if((o=o||{}).rtl){const e=o.includePrerelease?t[n.COERCERTLFULL]:t[n.COERCERTL];let r;for(;(r=e.exec(i))&&(!s||s.index+s[0].length!==i.length);)s&&r.index+r[0].length===s.index+s[0].length||(s=r),e.lastIndex=r.index+r[1].length+r[2].length;e.lastIndex=-1}else s=i.match(o.includePrerelease?t[n.COERCEFULL]:t[n.COERCE]);if(null===s)return null;const a=s[2],c=s[3]||"0",u=s[4]||"0",l=o.includePrerelease&&s[5]?`-${s[5]}`:"",f=o.includePrerelease&&s[6]?`+${s[6]}`:"";return r(`${a}.${c}.${u}${l}${f}`,o)},er}(),O=Rt(),L=At(),T=Ot(),N=function(){if(fr)return lr;fr=1;const e=At();return lr=(r,t)=>new e(r,t).set.map(e=>e.map(e=>e.value).join(" ").trim().split(" ")),lr}(),x=function(){if(hr)return pr;hr=1;const e=dt(),r=At();return pr=(t,n,i)=>{let o=null,s=null,a=null;try{a=new r(n,i)}catch(e){return null}return t.forEach(r=>{a.test(r)&&(o&&-1!==s.compare(r)||(o=r,s=new e(o,i)))}),o},pr}(),k=function(){if(mr)return dr;mr=1;const e=dt(),r=At();return dr=(t,n,i)=>{let o=null,s=null,a=null;try{a=new r(n,i)}catch(e){return null}return t.forEach(r=>{a.test(r)&&(o&&1!==s.compare(r)||(o=r,s=new e(o,i)))}),o},dr}(),j=function(){if(Er)return gr;Er=1;const e=dt(),r=At(),t=yt();return gr=(n,i)=>{n=new r(n,i);let o=new e("0.0.0");if(n.test(o))return o;if(o=new e("0.0.0-0"),n.test(o))return o;o=null;for(let r=0;r<n.set.length;++r){const i=n.set[r];let s=null;i.forEach(r=>{const n=new e(r.semver.version);switch(r.operator){case">":0===n.prerelease.length?n.patch++:n.prerelease.push(0),n.raw=n.format();case"":case">=":s&&!t(n,s)||(s=n);break;case"<":case"<=":break;default:throw new Error(`Unexpected operation: ${r.operator}`)}}),!s||o&&!t(o,s)||(o=s)}return o&&n.test(o)?o:null},gr}(),_=Lt(),P=Tt(),C=function(){if($r)return Sr;$r=1;const e=Tt();return Sr=(r,t,n)=>e(r,t,">",n),Sr}(),D=function(){if(Ar)return Ir;Ar=1;const e=Tt();return Ir=(r,t,n)=>e(r,t,"<",n),Ir}(),M=function(){if(Or)return Rr;Or=1;const e=At();return Rr=(r,t,n)=>(r=new e(r,n),t=new e(t,n),r.intersects(t,n))}(),B=function(){if(Tr)return Lr;Tr=1;const e=Ot(),r=gt();return Lr=(t,n,i)=>{const o=[];let s=null,a=null;const c=t.sort((e,t)=>r(e,t,i));for(const r of c)e(r,n,i)?(a=r,s||(s=r)):(a&&o.push([s,a]),a=null,s=null);s&&o.push([s,null]);const u=[];for(const[e,r]of o)e===r?u.push(e):r||e!==c[0]?r?e===c[0]?u.push(`<=${r}`):u.push(`${e} - ${r}`):u.push(`>=${e}`):u.push("*");const l=u.join(" || "),f="string"==typeof n.raw?n.raw:String(n);return l.length<f.length?l:n},Lr}(),K=function(){if(xr)return Nr;xr=1;const e=At(),r=Rt(),{ANY:t}=r,n=Ot(),i=gt(),o=[new r(">=0.0.0-0")],s=[new r(">=0.0.0")],a=(e,r,a)=>{if(e===r)return!0;if(1===e.length&&e[0].semver===t){if(1===r.length&&r[0].semver===t)return!0;e=a.includePrerelease?o:s}if(1===r.length&&r[0].semver===t){if(a.includePrerelease)return!0;r=s}const l=new Set;let f,p,h,d,m,g,E;for(const r of e)">"===r.operator||">="===r.operator?f=c(f,r,a):"<"===r.operator||"<="===r.operator?p=u(p,r,a):l.add(r.semver);if(l.size>1)return null;if(f&&p){if(h=i(f.semver,p.semver,a),h>0)return null;if(0===h&&(">="!==f.operator||"<="!==p.operator))return null}for(const e of l){if(f&&!n(e,String(f),a))return null;if(p&&!n(e,String(p),a))return null;for(const t of r)if(!n(e,String(t),a))return!1;return!0}let y=!(!p||a.includePrerelease||!p.semver.prerelease.length)&&p.semver,w=!(!f||a.includePrerelease||!f.semver.prerelease.length)&&f.semver;y&&1===y.prerelease.length&&"<"===p.operator&&0===y.prerelease[0]&&(y=!1);for(const e of r){if(E=E||">"===e.operator||">="===e.operator,g=g||"<"===e.operator||"<="===e.operator,f)if(w&&e.semver.prerelease&&e.semver.prerelease.length&&e.semver.major===w.major&&e.semver.minor===w.minor&&e.semver.patch===w.patch&&(w=!1),">"===e.operator||">="===e.operator){if(d=c(f,e,a),d===e&&d!==f)return!1}else if(">="===f.operator&&!n(f.semver,String(e),a))return!1;if(p)if(y&&e.semver.prerelease&&e.semver.prerelease.length&&e.semver.major===y.major&&e.semver.minor===y.minor&&e.semver.patch===y.patch&&(y=!1),"<"===e.operator||"<="===e.operator){if(m=u(p,e,a),m===e&&m!==p)return!1}else if("<="===p.operator&&!n(p.semver,String(e),a))return!1;if(!e.operator&&(p||f)&&0!==h)return!1}return!(f&&g&&!p&&0!==h||p&&E&&!f&&0!==h||w||y)},c=(e,r,t)=>{if(!e)return r;const n=i(e.semver,r.semver,t);return n>0?e:n<0||">"===r.operator&&">="===e.operator?r:e},u=(e,r,t)=>{if(!e)return r;const n=i(e.semver,r.semver,t);return n<0?e:n>0||"<"===r.operator&&"<="===e.operator?r:e};return Nr=(r,t,n={})=>{if(r===t)return!0;r=new e(r,n),t=new e(t,n);let i=!1;e:for(const e of r.set){for(const r of t.set){const t=a(e,r,n);if(i=i||null!==t,t)continue e}if(i)return!1}return!0}}();return kr={parse:i,valid:o,clean:s,inc:a,diff:c,major:u,minor:l,patch:f,prerelease:p,compare:h,rcompare:d,compareLoose:m,compareBuild:g,sort:E,rsort:y,gt:w,lt:b,eq:v,neq:S,gte:$,lte:I,cmp:A,coerce:R,Comparator:O,Range:L,satisfies:T,toComparators:N,maxSatisfying:x,minSatisfying:k,minVersion:j,validRange:_,outside:P,gtr:C,ltr:D,intersects:M,simplifyRange:B,subset:K,SemVer:t,re:e.re,src:e.src,tokens:e.t,SEMVER_SPEC_VERSION:r.SEMVER_SPEC_VERSION,RELEASE_TYPES:r.RELEASE_TYPES,compareIdentifiers:n.compareIdentifiers,rcompareIdentifiers:n.rcompareIdentifiers}}function xt(){if(Br)return Mr;Br=1;const e=function(){if(Pr)return _r;Pr=1;const e=Nt();return _r=e.satisfies(process.version,">=15.7.0")}(),r=function(){if(Dr)return Cr;Dr=1;const e=Nt();return Cr=e.satisfies(process.version,">=16.9.0")}(),t={ec:["ES256","ES384","ES512"],rsa:["RS256","PS256","RS384","PS384","RS512","PS512"],"rsa-pss":["PS256","PS384","PS512"]},n={ES256:"prime256v1",ES384:"secp384r1",ES512:"secp521r1"};return Mr=function(i,o){if(!i||!o)return;const s=o.asymmetricKeyType;if(!s)return;const a=t[s];if(!a)throw new Error(`Unknown key type "${s}".`);if(!a.includes(i))throw new Error(`"alg" parameter for "${s}" key type must be one of: ${a.join(", ")}.`);if(e)switch(s){case"ec":const e=o.asymmetricKeyDetails.namedCurve,t=n[i];if(e!==t)throw new Error(`"alg" parameter "${i}" requires curve "${t}".`);break;case"rsa-pss":if(r){const e=parseInt(i.slice(-3),10),{hashAlgorithm:r,mgf1HashAlgorithm:t,saltLength:n}=o.asymmetricKeyDetails;if(r!==`sha${e}`||t!==r)throw new Error(`Invalid key for this operation, its RSA-PSS parameters do not meet the requirements of "alg" ${i}.`);if(void 0!==n&&n>e>>3)throw new Error(`Invalid key for this operation, its RSA-PSS parameter saltLength does not meet the requirements of "alg" ${i}.`)}}}}function kt(){if(Fr)return Kr;Fr=1;var e=Nt();return Kr=e.satisfies(process.version,"^6.12.0 || >=8.0.0")}function jt(){if(Ur)return Gr;Ur=1;const e=X(),r=Y(),t=W(),n=z(),i=Z(),s=xt(),a=kt(),c=q(),{KeyObject:u,createSecretKey:l,createPublicKey:f}=o,p=["RS256","RS384","RS512"],h=["ES256","ES384","ES512"],d=["RS256","RS384","RS512"],m=["HS256","HS384","HS512"];return a&&(p.splice(p.length,0,"PS256","PS384","PS512"),d.splice(d.length,0,"PS256","PS384","PS512")),Gr=function(o,a,g,E){let y;if("function"!=typeof g||E||(E=g,g={}),g||(g={}),g=Object.assign({},g),y=E||function(e,r){if(e)throw e;return r},g.clockTimestamp&&"number"!=typeof g.clockTimestamp)return y(new e("clockTimestamp must be a number"));if(void 0!==g.nonce&&("string"!=typeof g.nonce||""===g.nonce.trim()))return y(new e("nonce must be a non-empty string"));if(void 0!==g.allowInvalidAsymmetricKeyTypes&&"boolean"!=typeof g.allowInvalidAsymmetricKeyTypes)return y(new e("allowInvalidAsymmetricKeyTypes must be a boolean"));const w=g.clockTimestamp||Math.floor(Date.now()/1e3);if(!o)return y(new e("jwt must be provided"));if("string"!=typeof o)return y(new e("jwt must be a string"));const b=o.split(".");if(3!==b.length)return y(new e("jwt malformed"));let v;try{v=n(o,{complete:!0})}catch(e){return y(e)}if(!v)return y(new e("invalid token"));const S=v.header;let $;if("function"==typeof a){if(!E)return y(new e("verify must be called asynchronous if secret or public key is provided as a callback"));$=a}else $=function(e,r){return r(null,a)};return $(S,function(n,a){if(n)return y(new e("error in secret or public key callback: "+n.message));const E=""!==b[2].trim();if(!E&&a)return y(new e("jwt signature is required"));if(E&&!a)return y(new e("secret or public key must be provided"));if(!E&&!g.algorithms)return y(new e('please specify "none" in "algorithms" to verify unsigned tokens'));if(null!=a&&!(a instanceof u))try{a=f(a)}catch(r){try{a=l("string"==typeof a?Buffer.from(a):a)}catch(r){return y(new e("secretOrPublicKey is not valid key material"))}}if(g.algorithms||("secret"===a.type?g.algorithms=m:["rsa","rsa-pss"].includes(a.asymmetricKeyType)?g.algorithms=d:"ec"===a.asymmetricKeyType?g.algorithms=h:g.algorithms=p),-1===g.algorithms.indexOf(v.header.alg))return y(new e("invalid algorithm"));if(S.alg.startsWith("HS")&&"secret"!==a.type)return y(new e(`secretOrPublicKey must be a symmetric key when using ${S.alg}`));if(/^(?:RS|PS|ES)/.test(S.alg)&&"public"!==a.type)return y(new e(`secretOrPublicKey must be an asymmetric key when using ${S.alg}`));if(!g.allowInvalidAsymmetricKeyTypes)try{s(S.alg,a)}catch(e){return y(e)}let $;try{$=c.verify(o,v.header.alg,a)}catch(e){return y(e)}if(!$)return y(new e("invalid signature"));const I=v.payload;if(void 0!==I.nbf&&!g.ignoreNotBefore){if("number"!=typeof I.nbf)return y(new e("invalid nbf value"));if(I.nbf>w+(g.clockTolerance||0))return y(new r("jwt not active",new Date(1e3*I.nbf)))}if(void 0!==I.exp&&!g.ignoreExpiration){if("number"!=typeof I.exp)return y(new e("invalid exp value"));if(w>=I.exp+(g.clockTolerance||0))return y(new t("jwt expired",new Date(1e3*I.exp)))}if(g.audience){const r=Array.isArray(g.audience)?g.audience:[g.audience];if(!(Array.isArray(I.aud)?I.aud:[I.aud]).some(function(e){return r.some(function(r){return r instanceof RegExp?r.test(e):r===e})}))return y(new e("jwt audience invalid. expected: "+r.join(" or ")))}if(g.issuer){if("string"==typeof g.issuer&&I.iss!==g.issuer||Array.isArray(g.issuer)&&-1===g.issuer.indexOf(I.iss))return y(new e("jwt issuer invalid. expected: "+g.issuer))}if(g.subject&&I.sub!==g.subject)return y(new e("jwt subject invalid. expected: "+g.subject));if(g.jwtid&&I.jti!==g.jwtid)return y(new e("jwt jwtid invalid. expected: "+g.jwtid));if(g.nonce&&I.nonce!==g.nonce)return y(new e("jwt nonce invalid. expected: "+g.nonce));if(g.maxAge){if("number"!=typeof I.iat)return y(new e("iat required when maxAge is specified"));const r=i(g.maxAge,I.iat);if(void 0===r)return y(new e('"maxAge" should be a number of seconds or string representing a timespan eg: "1d", "20h", 60'));if(w>=r+(g.clockTolerance||0))return y(new t("maxAge exceeded",new Date(1e3*r)))}if(!0===g.complete){const e=v.signature;return y(null,{header:S,payload:I,signature:e})}return y(null,I)})},Gr}function _t(){if(Vr)return Hr;Vr=1;var e=1/0,r=9007199254740991,t=17976931348623157e292,n=NaN,i="[object Arguments]",o="[object Function]",s="[object GeneratorFunction]",a="[object String]",c="[object Symbol]",u=/^\s+|\s+$/g,l=/^[-+]0x[0-9a-f]+$/i,f=/^0b[01]+$/i,p=/^0o[0-7]+$/i,h=/^(?:0|[1-9]\d*)$/,d=parseInt;function m(e){return e!=e}function g(e,r){return function(e,r){for(var t=-1,n=e?e.length:0,i=Array(n);++t<n;)i[t]=r(e[t],t,e);return i}(r,function(r){return e[r]})}var E,y,w=Object.prototype,b=w.hasOwnProperty,v=w.toString,S=w.propertyIsEnumerable,$=(E=Object.keys,y=Object,function(e){return E(y(e))}),I=Math.max;function A(e,r){var t=L(e)||function(e){return function(e){return x(e)&&T(e)}(e)&&b.call(e,"callee")&&(!S.call(e,"callee")||v.call(e)==i)}(e)?function(e,r){for(var t=-1,n=Array(e);++t<e;)n[t]=r(t);return n}(e.length,String):[],n=t.length,o=!!n;for(var s in e)!b.call(e,s)||o&&("length"==s||O(s,n))||t.push(s);return t}function R(e){if(t=(r=e)&&r.constructor,n="function"==typeof t&&t.prototype||w,r!==n)return $(e);var r,t,n,i=[];for(var o in Object(e))b.call(e,o)&&"constructor"!=o&&i.push(o);return i}function O(e,t){return!!(t=null==t?r:t)&&("number"==typeof e||h.test(e))&&e>-1&&e%1==0&&e<t}var L=Array.isArray;function T(e){return null!=e&&function(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=r}(e.length)&&!function(e){var r=N(e)?v.call(e):"";return r==o||r==s}(e)}function N(e){var r=typeof e;return!!e&&("object"==r||"function"==r)}function x(e){return!!e&&"object"==typeof e}return Hr=function(r,i,o,s){var h;r=T(r)?r:(h=r)?g(h,function(e){return T(e)?A(e):R(e)}(h)):[],o=o&&!s?function(r){var i=function(r){if(!r)return 0===r?r:0;if(r=function(e){if("number"==typeof e)return e;if(function(e){return"symbol"==typeof e||x(e)&&v.call(e)==c}(e))return n;if(N(e)){var r="function"==typeof e.valueOf?e.valueOf():e;e=N(r)?r+"":r}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(u,"");var t=f.test(e);return t||p.test(e)?d(e.slice(2),t?2:8):l.test(e)?n:+e}(r),r===e||r===-1/0){return(r<0?-1:1)*t}return r==r?r:0}(r),o=i%1;return i==i?o?i-o:i:0}(o):0;var E=r.length;return o<0&&(o=I(E+o,0)),function(e){return"string"==typeof e||!L(e)&&x(e)&&v.call(e)==a}(r)?o<=E&&r.indexOf(i,o)>-1:!!E&&function(e,r,t){if(r!=r)return function(e,r,t){for(var n=e.length,i=t+-1;++i<n;)if(r(e[i],i,e))return i;return-1}(e,m,t);for(var n=t-1,i=e.length;++n<i;)if(e[n]===r)return n;return-1}(r,i,o)>-1},Hr}function Pt(){if(Yr)return Xr;Yr=1;var e=1/0,r=17976931348623157e292,t=NaN,n="[object Symbol]",i=/^\s+|\s+$/g,o=/^[-+]0x[0-9a-f]+$/i,s=/^0b[01]+$/i,a=/^0o[0-7]+$/i,c=parseInt,u=Object.prototype.toString;function l(e){var r=typeof e;return!!e&&("object"==r||"function"==r)}return Xr=function(f){return"number"==typeof f&&f==function(f){var p=function(f){if(!f)return 0===f?f:0;if(f=function(e){if("number"==typeof e)return e;if(function(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&u.call(e)==n}(e))return t;if(l(e)){var r="function"==typeof e.valueOf?e.valueOf():e;e=l(r)?r+"":r}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(i,"");var f=s.test(e);return f||a.test(e)?c(e.slice(2),f?2:8):o.test(e)?t:+e}(f),f===e||f===-1/0){return(f<0?-1:1)*r}return f==f?f:0}(f),h=p%1;return p==p?h?p-h:p:0}(f)}}function Ct(){if(nt)return tt;nt=1;var e=1/0,r=17976931348623157e292,t=NaN,n="[object Symbol]",i=/^\s+|\s+$/g,o=/^[-+]0x[0-9a-f]+$/i,s=/^0b[01]+$/i,a=/^0o[0-7]+$/i,c=parseInt,u=Object.prototype.toString;function l(l,p){var h;if("function"!=typeof p)throw new TypeError("Expected a function");return l=function(l){var p=function(l){if(!l)return 0===l?l:0;if(l=function(e){if("number"==typeof e)return e;if(function(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&u.call(e)==n}(e))return t;if(f(e)){var r="function"==typeof e.valueOf?e.valueOf():e;e=f(r)?r+"":r}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(i,"");var l=s.test(e);return l||a.test(e)?c(e.slice(2),l?2:8):o.test(e)?t:+e}(l),l===e||l===-1/0){return(l<0?-1:1)*r}return l==l?l:0}(l),h=p%1;return p==p?h?p-h:p:0}(l),function(){return--l>0&&(h=p.apply(this,arguments)),l<=1&&(p=void 0),h}}function f(e){var r=typeof e;return!!e&&("object"==r||"function"==r)}return tt=function(e){return l(2,e)}}function Dt(){if(ot)return it;ot=1;const e=Z(),r=kt(),t=xt(),n=q(),i=_t(),s=function(){if(zr)return qr;zr=1;var e=Object.prototype.toString;return qr=function(r){return!0===r||!1===r||function(e){return!!e&&"object"==typeof e}(r)&&"[object Boolean]"==e.call(r)}}(),a=Pt(),c=function(){if(Jr)return Wr;Jr=1;var e=Object.prototype.toString;return Wr=function(r){return"number"==typeof r||function(e){return!!e&&"object"==typeof e}(r)&&"[object Number]"==e.call(r)}}(),u=function(){if(Qr)return Zr;Qr=1;var e,r,t=Function.prototype,n=Object.prototype,i=t.toString,o=n.hasOwnProperty,s=i.call(Object),a=n.toString,c=(e=Object.getPrototypeOf,r=Object,function(t){return e(r(t))});return Zr=function(e){if(!function(e){return!!e&&"object"==typeof e}(e)||"[object Object]"!=a.call(e)||function(e){var r=!1;if(null!=e&&"function"!=typeof e.toString)try{r=!!(e+"")}catch(e){}return r}(e))return!1;var r=c(e);if(null===r)return!0;var t=o.call(r,"constructor")&&r.constructor;return"function"==typeof t&&t instanceof t&&i.call(t)==s}}(),l=function(){if(rt)return et;rt=1;var e=Object.prototype.toString,r=Array.isArray;return et=function(t){return"string"==typeof t||!r(t)&&function(e){return!!e&&"object"==typeof e}(t)&&"[object String]"==e.call(t)}}(),f=Ct(),{KeyObject:p,createSecretKey:h,createPrivateKey:d}=o,m=["RS256","RS384","RS512","ES256","ES384","ES512","HS256","HS384","HS512","none"];r&&m.splice(3,0,"PS256","PS384","PS512");const g={expiresIn:{isValid:function(e){return a(e)||l(e)&&e},message:'"expiresIn" should be a number of seconds or string representing a timespan'},notBefore:{isValid:function(e){return a(e)||l(e)&&e},message:'"notBefore" should be a number of seconds or string representing a timespan'},audience:{isValid:function(e){return l(e)||Array.isArray(e)},message:'"audience" must be a string or array'},algorithm:{isValid:i.bind(null,m),message:'"algorithm" must be a valid string enum value'},header:{isValid:u,message:'"header" must be an object'},encoding:{isValid:l,message:'"encoding" must be a string'},issuer:{isValid:l,message:'"issuer" must be a string'},subject:{isValid:l,message:'"subject" must be a string'},jwtid:{isValid:l,message:'"jwtid" must be a string'},noTimestamp:{isValid:s,message:'"noTimestamp" must be a boolean'},keyid:{isValid:l,message:'"keyid" must be a string'},mutatePayload:{isValid:s,message:'"mutatePayload" must be a boolean'},allowInsecureKeySizes:{isValid:s,message:'"allowInsecureKeySizes" must be a boolean'},allowInvalidAsymmetricKeyTypes:{isValid:s,message:'"allowInvalidAsymmetricKeyTypes" must be a boolean'}},E={iat:{isValid:c,message:'"iat" should be a number of seconds'},exp:{isValid:c,message:'"exp" should be a number of seconds'},nbf:{isValid:c,message:'"nbf" should be a number of seconds'}};function y(e,r,t,n){if(!u(t))throw new Error('Expected "'+n+'" to be a plain object.');Object.keys(t).forEach(function(i){const o=e[i];if(o){if(!o.isValid(t[i]))throw new Error(o.message)}else if(!r)throw new Error('"'+i+'" is not allowed in "'+n+'"')})}const w={audience:"aud",issuer:"iss",subject:"sub",jwtid:"jti"},b=["expiresIn","notBefore","noTimestamp","audience","issuer","subject","jwtid"];return it=function(r,i,o,s){"function"==typeof o?(s=o,o={}):o=o||{};const a="object"==typeof r&&!Buffer.isBuffer(r),c=Object.assign({alg:o.algorithm||"HS256",typ:a?"JWT":void 0,kid:o.keyid},o.header);function u(e){if(s)return s(e);throw e}if(!i&&"none"!==o.algorithm)return u(new Error("secretOrPrivateKey must have a value"));if(null!=i&&!(i instanceof p))try{i=d(i)}catch(e){try{i=h("string"==typeof i?Buffer.from(i):i)}catch(e){return u(new Error("secretOrPrivateKey is not valid key material"))}}if(c.alg.startsWith("HS")&&"secret"!==i.type)return u(new Error(`secretOrPrivateKey must be a symmetric key when using ${c.alg}`));if(/^(?:RS|PS|ES)/.test(c.alg)){if("private"!==i.type)return u(new Error(`secretOrPrivateKey must be an asymmetric key when using ${c.alg}`));if(!o.allowInsecureKeySizes&&!c.alg.startsWith("ES")&&void 0!==i.asymmetricKeyDetails&&i.asymmetricKeyDetails.modulusLength<2048)return u(new Error(`secretOrPrivateKey has a minimum key size of 2048 bits for ${c.alg}`))}if(void 0===r)return u(new Error("payload is required"));if(a){try{!function(e){y(E,!0,e,"payload")}(r)}catch(e){return u(e)}o.mutatePayload||(r=Object.assign({},r))}else{const e=b.filter(function(e){return void 0!==o[e]});if(e.length>0)return u(new Error("invalid "+e.join(",")+" option for "+typeof r+" payload"))}if(void 0!==r.exp&&void 0!==o.expiresIn)return u(new Error('Bad "options.expiresIn" option the payload already has an "exp" property.'));if(void 0!==r.nbf&&void 0!==o.notBefore)return u(new Error('Bad "options.notBefore" option the payload already has an "nbf" property.'));try{!function(e){y(g,!1,e,"options")}(o)}catch(e){return u(e)}if(!o.allowInvalidAsymmetricKeyTypes)try{t(c.alg,i)}catch(e){return u(e)}const l=r.iat||Math.floor(Date.now()/1e3);if(o.noTimestamp?delete r.iat:a&&(r.iat=l),void 0!==o.notBefore){try{r.nbf=e(o.notBefore,l)}catch(e){return u(e)}if(void 0===r.nbf)return u(new Error('"notBefore" should be a number of seconds or string representing a timespan eg: "1d", "20h", 60'))}if(void 0!==o.expiresIn&&"object"==typeof r){try{r.exp=e(o.expiresIn,l)}catch(e){return u(e)}if(void 0===r.exp)return u(new Error('"expiresIn" should be a number of seconds or string representing a timespan eg: "1d", "20h", 60'))}Object.keys(w).forEach(function(e){const t=w[e];if(void 0!==o[e]){if(void 0!==r[t])return u(new Error('Bad "options.'+e+'" option. The payload already has an "'+t+'" property.'));r[t]=o[e]}});const m=o.encoding||"utf8";if("function"!=typeof s){let e=n.sign({header:c,payload:r,secret:i,encoding:m});if(!o.allowInsecureKeySizes&&/^(?:RS|PS)/.test(c.alg)&&e.length<256)throw new Error(`secretOrPrivateKey has a minimum key size of 2048 bits for ${c.alg}`);return e}s=s&&f(s),n.createSign({header:c,privateKey:i,payload:r,encoding:m}).once("error",s).once("done",function(e){if(!o.allowInsecureKeySizes&&/^(?:RS|PS)/.test(c.alg)&&e.length<256)return s(new Error(`secretOrPrivateKey has a minimum key size of 2048 bits for ${c.alg}`));s(null,e)})}}var Mt=s(at?st:(at=1,st={decode:z(),verify:jt(),sign:Dt(),JsonWebTokenError:X(),NotBeforeError:Y(),TokenExpiredError:W()}));const Bt=e(import.meta.url),{version:Kt}=Bt("../package.json");var Ft={id:"sso",handler:(e,t)=>{const{env:n,logger:i,services:o,database:s,getSchema:a}=t,c=n.KEYCLOAK_URL||"http://keycloak:8080",u=n.KEYCLOAK_REALM||"testing",l=n.KEYCLOAK_ADMIN_USER||"admin",f=n.KEYCLOAK_ADMIN_PASSWORD||"admin",p=n.PUBLIC_URL||"http://localhost:8055",h=n.MOBILE_APP_SCHEME||"finsnapp",d=Array.isArray(h)?h.map(e=>String(e).trim()):String(h).split(",").map(e=>e.trim()),m=d[0],g=n.MOBILE_APP_CALLBACK_PATH||"/auth/callback",E=n.GOOGLE_CALLBACK_PATH||"/auth/callback/google",y=n.APPLE_CLIENT_ID||"com.forumbandung.app",w=Array.isArray(y)?y.map(e=>String(e).trim().toLowerCase()):String(y).split(",").map(e=>e.trim().toLowerCase()),b=n.KEYCLOAK_CLIENT_ID||"admin-cli",v=n.COOKIE_DOMAIN||null,S="false"!==n.COOKIE_SECURE,$=n.COOKIE_SAME_SITE||"lax",I=n.SESSION_COOKIE_NAME||"directus_session_token",A=n.REFRESH_TOKEN_COOKIE_NAME||"directus_refresh_token",R=n.DEFAULT_ROLE_ID||null,O="directus_session_token";function L(e){return"string"!=typeof e?"":e.replace(/[&<>"']/g,e=>{switch(e){case"&":return"&amp;";case"<":return"&lt;";case">":return"&gt;";case'"':return"&quot;";case"'":return"&#039;";default:return e}})}function T(e,r,t="AUTHENTICATION_FAILED"){const n=L(e);return`<!DOCTYPE html>\n<html lang="en">\n<head>\n <meta charset="UTF-8">\n <meta name="viewport" content="width=device-width, initial-scale=1.0">\n <title>${n}</title>\n <link rel="preconnect" href="https://fonts.googleapis.com">\n <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>\n <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700&display=swap" rel="stylesheet">\n <style>\n * {\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n }\n body {\n font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;\n background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);\n min-height: 100vh;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 24px;\n color: #1e293b;\n }\n .container {\n width: 100%;\n max-width: 440px;\n background: rgba(255, 255, 255, 0.95);\n backdrop-filter: blur(16px);\n -webkit-backdrop-filter: blur(16px);\n border: 1px solid rgba(255, 255, 255, 0.6);\n border-radius: 24px;\n padding: 40px 32px;\n box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.08);\n text-align: center;\n animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);\n }\n @keyframes slideUp {\n from {\n opacity: 0;\n transform: translateY(20px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n }\n .icon-wrapper {\n width: 72px;\n height: 72px;\n background: #fef2f2;\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n margin: 0 auto 24px;\n color: #ef4444;\n border: 1px solid #fee2e2;\n animation: scaleIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);\n }\n @keyframes scaleIn {\n from { transform: scale(0); }\n to { transform: scale(1); }\n }\n .icon {\n width: 32px;\n height: 32px;\n fill: none;\n stroke: currentColor;\n stroke-width: 2.5;\n stroke-linecap: round;\n stroke-linejoin: round;\n }\n h1 {\n font-size: 24px;\n font-weight: 700;\n color: #0f172a;\n margin-bottom: 12px;\n letter-spacing: -0.02em;\n }\n p {\n font-size: 15px;\n line-height: 1.6;\n color: #64748b;\n margin-bottom: 32px;\n }\n .instruction-card {\n background: #f8fafc;\n border: 1px solid #f1f5f9;\n border-radius: 16px;\n padding: 20px;\n margin-bottom: 28px;\n text-align: left;\n }\n .instruction-card h3 {\n font-size: 13px;\n font-weight: 700;\n color: #475569;\n margin-bottom: 10px;\n text-transform: uppercase;\n letter-spacing: 0.05em;\n }\n .instruction-list {\n list-style: none;\n }\n .instruction-list li {\n font-size: 14px;\n line-height: 1.5;\n color: #475569;\n margin-bottom: 10px;\n display: flex;\n align-items: flex-start;\n }\n .instruction-list li::before {\n content: "•";\n color: #ef4444;\n font-weight: bold;\n display: inline-block;\n width: 1em;\n margin-left: -0.2em;\n flex-shrink: 0;\n }\n .instruction-list li:last-child {\n margin-bottom: 0;\n }\n .btn {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 100%;\n padding: 14px 24px;\n background: #0f172a;\n color: #ffffff;\n border: none;\n border-radius: 16px;\n font-size: 16px;\n font-weight: 600;\n cursor: pointer;\n transition: all 0.2s ease;\n box-shadow: 0 4px 6px -1px rgba(15, 23, 42, 0.1);\n text-decoration: none;\n }\n .btn:hover {\n background: #1e293b;\n transform: translateY(-1px);\n box-shadow: 0 10px 15px -3px rgba(15, 23, 42, 0.15);\n }\n .btn:active {\n transform: translateY(0);\n }\n .footer-text {\n font-size: 12px;\n color: #94a3b8;\n margin-top: 24px;\n }\n </style>\n</head>\n<body>\n <div class="container">\n <div class="icon-wrapper">\n <svg class="icon" viewBox="0 0 24 24">\n <circle cx="12" cy="12" r="10"></circle>\n <line x1="12" y1="8" x2="12" y2="12"></line>\n <line x1="12" y1="16" x2="12.01" y2="16"></line>\n </svg>\n </div>\n <h1>${n}</h1>\n <p>${L(r)}</p>\n \n <div class="instruction-card">\n <h3>How to resolve this</h3>\n <ul class="instruction-list">\n <li>Tap the <strong>✕</strong> close icon at the top left of this screen.</li>\n <li>You will return to your mobile app automatically.</li>\n <li>Try logging in again from the app.</li>\n </ul>\n </div>\n\n <button class="btn" onclick="try { window.close(); } catch(e) {}">Return to App</button>\n \n <div class="footer-text">\n Error Code: ${L(t)}\n </div>\n </div>\n</body>\n</html>`}function N(e,r="/"){if(!e||"string"!=typeof e)return r;try{if(d.some(r=>e.startsWith(`${r}://`)))return e;if(e.startsWith("/")&&!e.startsWith("//")&&!e.startsWith("/\\"))return e;const r=new URL(e),t=new URL(p).origin;if(r.origin===t)return e}catch(e){}return i.warn(`⚠️ Warning: Blocked potentially unsafe redirect URL: "${e}". Defaulting to fallback: "${r}"`),r}const x=n.FCM_PROJECT_ID||null;async function k(){try{const e=await fetch(`${c}/realms/master/protocol/openid-connect/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"password",client_id:b,username:l,password:f}).toString()});if(!e.ok)throw new Error("Failed to get admin token");return(await e.json()).access_token}catch(e){return i.error("Error getting admin token:",e),null}}async function j(e,r){try{const t=await fetch(`${c}/admin/realms/${u}/users?email=${encodeURIComponent(r)}`,{headers:{Authorization:`Bearer ${e}`}});if(!t.ok)throw new Error("Failed to get user");const n=await t.json();return n.length>0?n[0].id:null}catch(e){return i.error("Error getting user ID:",e),null}}async function _(e,r){try{const t=await fetch(`${c}/admin/realms/${u}/users/${r}/logout`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});return t.ok||204===t.status}catch(e){return i.error("Error logging out user from Keycloak:",e),!1}}function P(e){if("browser"===e.query.type)return!0;if("mobile"===e.query.type)return!1;if(e.query.app_scheme||e.query.app_path)return!1;const r=e.headers["user-agent"]||"";return/Mozilla|Chrome|Safari|Firefox|Edge|Opera/i.test(r)&&!/Mobile.*App|ReactNative|Expo/i.test(r)}async function C(e,r){const t=e.headers.cookie;if(!t)return null;const n=t.split(";").map(e=>e.trim()).filter(e=>e.startsWith(`${r}=`)).map(e=>e.substring(r.length+1));if(0===n.length)return null;for(let e=0;e<n.length;e++){const t=n[e];try{const e=await fetch(`${p}/users/me`,{headers:{Cookie:`${r}=${t}`}});if(e.ok){return{token:t,userData:(await e.json()).data}}}catch(e){}}return null}async function D(e){const r=e.headers.cookie;if(!r)return null;const t=r.split(";").map(e=>e.trim()).map(e=>{const r=e.split("=");return r.length>1?r[1]:null}).filter(e=>e&&e.startsWith("eyJ")&&e.length>50);if(0===t.length)return null;for(let e=0;e<t.length;e++){const r=t[e];try{const e=await fetch(`${p}/users/me`,{headers:{Authorization:`Bearer ${r}`}});if(e.ok){return{token:r,userData:(await e.json()).data}}}catch(e){}}return null}async function M(e){const r=e.cookies[A];if(!r)return null;try{const e=await fetch(`${p}/auth/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:r})});if(e.ok){const r=(await e.json()).data.access_token,t=await fetch(`${p}/users/me`,{headers:{Authorization:`Bearer ${r}`}});if(t.ok){return{token:r,userData:(await t.json()).data}}}}catch(e){}return null}function B(e){const r=e.query.app_scheme;return r&&d.includes(r)?r:(r&&i.warn(`⚠️ Warning: App requested scheme '${r}', but it is not in .env. Falling back to '${m}'`),m)}n.FCM_CLIENT_EMAIL,n.FCM_PRIVATE_KEY&&n.FCM_PRIVATE_KEY.replace(/\\n/g,"\n"),n.FCM_WEBHOOK_SECRET,i.info("🚀 Mobile Auth Extension loaded"),i.info("📱 Allowed Mobile App Schemes: "+d.join(", "));let K=!1;e.use((e,r,t)=>{e.app&&function(e){if(K||e.__sso_error_interceptor_registered)return;e.__sso_error_interceptor_registered=!0,K=!0,i.info("🛠️ SSO global error interceptor registered on Express app");const r=(e,r,t)=>{const n=e.accepts("html")||e.headers.accept?.includes("text/html"),i=/Mozilla|Chrome|Safari|Firefox|Edge|Opera/i.test(e.headers["user-agent"]||"");if(n||i){const e=r.json;r.json=function(t){return t&&t.errors&&Array.isArray(t.errors)&&t.errors.length>0&&t.errors.some(e=>"INVALID_CREDENTIALS"===e.extensions?.code||e.message?.toLowerCase().includes("credentials"))?(r.setHeader("Content-Type","text/html"),r.status(401),r.send(T("Login Session Expired","Your login credentials are invalid or your session has expired. Please return to the app and try logging in again.","INVALID_CREDENTIALS"))):e.apply(this,arguments)}}t()};e._router&&Array.isArray(e._router.stack)?e._router.stack.unshift({handle:r,name:"ssoErrorInterceptor",params:void 0,path:void 0,keys:[],regexp:/^\/?/}):e.use(r)}(e.app),t()}),e.get("/health",(e,r)=>{r.json({status:"ok",service:"directus-extension-sso",version:Kt,allowed_schemes:d,fcm_enabled:!!x})}),e.get("/mobile-callback",async(e,r)=>{const t=P(e),n=e.accepts("html")||e.headers.accept?.includes("text/html")||/Mozilla|Chrome|Safari|Firefox|Edge|Opera/i.test(e.headers["user-agent"]||"");try{let i=null;if(I!==O&&(i=await C(e,I)),i||(i=await C(e,O)),i||(i=await D(e)),i||(i=await M(e)),!i)return n?(r.setHeader("Content-Type","text/html"),r.status(401).send(T("Authentication Failed","Your login session is invalid or has expired. Please go back to the app and try logging in again.","INVALID_CREDENTIALS"))):r.status(401).json({error:"Authentication failed"});const{token:o,userData:s}=i,a=s.id,c=s.email,u=o;if(t){r.cookie(I,o,{httpOnly:!0,secure:S,domain:v,sameSite:$,maxAge:6048e5,path:"/"}),I!==O&&r.cookie(O,"",{maxAge:0,path:"/"});let t=e.query.redirect_uri||e.query.redirect||"/";return t=N(t,"/"),r.redirect(t)}const l=B(e),f=`${l}://${(e.query.app_path||g).replace(/^\/+/,"")}?access_token=${u}&user_id=${a}&email=${encodeURIComponent(c||"")}`;return r.setHeader("Location",f),r.status(302).send(`<html><head><meta http-equiv="refresh" content="0;url=${f}"></head><body>Redirecting...</body></html>`)}catch(e){if(i.error("Error in mobile-callback:",e),n)return r.setHeader("Content-Type","text/html"),r.status(500).send(T("Authentication Error",e.message||"An unexpected error occurred during mobile authentication.","INTERNAL_SERVER_ERROR"));r.status(500).json({error:e.message})}}),e.get("/google-callback",async(e,r)=>{const t=P(e),n=e.accepts("html")||e.headers.accept?.includes("text/html")||/Mozilla|Chrome|Safari|Firefox|Edge|Opera/i.test(e.headers["user-agent"]||"");try{let o=null;if(e.query.access_token){o={token:e.query.access_token,refresh_token:e.query.refresh_token||null,expires:e.query.expires||null};try{const e=await fetch(`${p}/users/me`,{headers:{Authorization:`Bearer ${o.token}`}});if(e.ok){const r=await e.json();o.userData=r.data}else o=null}catch(e){o=null}}if(o||I===O||(o=await C(e,I)),o||(o=await C(e,O)),o||(o=await D(e)),o||(o=await M(e)),!o)return n?(r.setHeader("Content-Type","text/html"),r.status(401).send(T("Authentication Failed","Your Google login session is invalid or has expired. Please go back to the app and try logging in again.","INVALID_CREDENTIALS"))):r.status(401).json({error:"Authentication failed"});const{token:s,userData:a}=o,c=a.id,u=a.email,l=s;if(t){r.cookie(I,s,{httpOnly:!0,secure:S,domain:v,sameSite:$,maxAge:6048e5,path:"/"}),I!==O&&r.cookie(O,"",{maxAge:0,path:"/"});let t=e.query.redirect_uri||e.query.redirect||"/";t=N(t,"/");const n=L(t);return r.send(`<html><head><meta http-equiv="refresh" content="2;url=${n}"></head><body>Login Successful!</body></html>`)}const f=B(e),h=e.query.app_path||E,d=new URL(`${f}://${h.replace(/^\/+/,"")}`);return d.searchParams.set("access_token",l),d.searchParams.set("user_id",c),d.searchParams.set("email",u||""),d.searchParams.set("provider","google"),i.info("🚀 Performing direct 302 redirect to app: "+d.toString()),r.redirect(302,d.toString())}catch(e){if(i.error("Error in google-callback:",e),n)return r.setHeader("Content-Type","text/html"),r.status(500).send(T("Authentication Error",e.message||"An unexpected error occurred during Google authentication.","INTERNAL_SERVER_ERROR"));r.status(500).json({error:e.message})}}),e.get("/logout-clear",(e,r)=>{const t={httpOnly:!0,secure:S,sameSite:$,path:"/"};if(r.clearCookie(I,t),I!==O&&r.clearCookie(O,t),r.clearCookie(A,t),v){const e={...t,domain:v};r.clearCookie(I,e),I!==O&&r.clearCookie(O,e),r.clearCookie(A,e)}try{r.clearCookie(I,{...t,domain:".goyong.in"}),r.clearCookie(O,{...t,domain:".goyong.in"}),r.clearCookie(A,{...t,domain:".goyong.in"})}catch(e){}let n=e.query.redirect;return n?(n=N(n,"/"),i.info(`🧹 Cleared cookies and redirecting to: ${n}`),r.redirect(n)):(i.info("🧹 Cleared cookies successfully (no redirect provided)"),r.json({success:!0,message:"Cookies cleared successfully"}))}),e.post("/mobile-logout",async(e,r)=>{try{const t=e.headers.authorization,n=t?.replace("Bearer ","");if(!n)return r.status(400).json({error:"No token provided"});let i=null;try{const e=await fetch(`${p}/users/me`,{headers:{Authorization:`Bearer ${n}`}});if(e.ok){i=(await e.json()).data.email}}catch(e){}try{await fetch(`${p}/auth/logout`,{method:"POST",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},body:JSON.stringify({refresh_token:n})})}catch(e){}if(i)try{const e=await k();if(e){const r=await j(e,i);r&&await _(e,r)}}catch(e){}r.json({success:!0,message:"Logged out successfully"})}catch(e){r.status(500).json({error:e.message})}}),e.post("/delete-account",async(e,r)=>{try{const t=e.headers.authorization,c=t?.replace("Bearer ","");if(!c)return r.status(400).json({error:"No token provided"});let u=null,l=null;try{const e=await fetch(`${p}/users/me`,{headers:{Authorization:`Bearer ${c}`}});if(e.ok){const r=await e.json();u=r.data.id,l=r.data.email}}catch(e){i.error("[SSO] Error verifying token during account deletion:",e)}if(!u||!l)return r.status(401).json({error:"Invalid or expired token"});i.info(`[SSO] Deleting account for user: ${u} (${l})`);let f=!1;try{const e=await fetch(`${p}/auth/logout`,{method:"POST",headers:{Authorization:`Bearer ${c}`,"Content-Type":"application/json"},body:JSON.stringify({})});f=e.ok||204===e.status,i.info(`[SSO] Directus /auth/logout → ${e.status} for user ${u}`)}catch(e){i.warn("[SSO] /auth/logout network error (non-fatal):",e.message)}let h=0;try{const e=Mt.decode(c),r=e?.session;if(r){const e=await s("directus_sessions").where("token",r).delete();h+=e,i.info(`[SSO] Deleted ${e} session(s) by token for user ${u}`)}const t=await s("directus_sessions").where("user",u).delete();h+=t,t>0&&i.info(`[SSO] Deleted ${t} additional session(s) by user ID for ${u}`)}catch(e){i.error("[SSO] Error deleting sessions:",e)}const{UsersService:d}=o,m=new d({schema:await a(),knex:s}),g=`DELETED_${Date.now()}_${l}`;await m.updateOne(u,{first_name:"DELETED",last_name:"ACCOUNT",status:"suspended",email:g,external_identifier:null,provider:"default"}),i.info(`[SSO] Soft-deleted user ${u} → ${g}, sessions cleared: ${h}, directus logout: ${f}`);if(!!(n.KEYCLOAK_URL&&n.KEYCLOAK_REALM&&n.KEYCLOAK_ADMIN_USER&&n.KEYCLOAK_ADMIN_PASSWORD))try{const e=await k();if(e){const r=await j(e,l);r&&(await _(e,r),i.info(`[SSO] Logged out user ${l} from Keycloak`))}}catch(e){i.error("[SSO] Keycloak logout error:",e)}const E=`${p}/sso/logout-clear`;return r.json({success:!0,message:"Account deleted successfully, sessions cleared.",sessions_cleared:h,browser_logout_url:E})}catch(e){return i.error("[SSO] Account deletion failed:",e),r.status(500).json({error:e.message,message:"Failed to delete account"})}}),e.post("/apple-token",async(e,t)=>{const{identityToken:c,firstName:u,lastName:l}=e.body;if(i.info("🍎 Apple token exchange request received"),!c)return t.status(400).json({error:"identityToken is required",message:"Apple identityToken must be provided in the request body"});try{const e=async e=>{const[t,n,i]=e.split("."),o=JSON.parse(Buffer.from(t,"base64").toString()),s=JSON.parse(Buffer.from(n,"base64").toString());if("https://appleid.apple.com"!==s.iss)throw new Error("Invalid issuer");const a=[...w,"host.exp.exponent"],c=s.aud.toLowerCase();if(!a.includes(c))throw new Error(`Invalid audience: ${c}. Allowed: ${a.join(", ")}`);if(s.exp<Math.floor(Date.now()/1e3))throw new Error("Token expired");const u=await fetch("https://appleid.apple.com/auth/keys"),{keys:l}=await u.json(),f=l.find(e=>e.kid===o.kid);if(!f)throw new Error("Apple public key not found");const p=r.createPublicKey({key:f,format:"jwk"}),h=r.createVerify("RSA-SHA256");h.update(`${t}.${n}`);if(!h.verify(p,i,"base64url"))throw new Error("Invalid signature");return s},i=await e(c),{email:f,sub:p}=i;if(!f)throw new Error("Apple token did not contain an email");const{UsersService:h}=o,d=new h({schema:await a(),knex:s});let m,g=await d.readByQuery({filter:{_and:[{external_identifier:{_eq:p}},{provider:{_eq:"apple"}}]}}),E=g.length>0?g[0]:null;E||(g=await d.readByQuery({filter:{email:{_eq:f}}}),g.length>0&&(E=g[0],await d.updateOne(E.id,{external_identifier:p,provider:"apple"}))),E?m=E.id:(m=await d.createOne({email:f,first_name:u||"Apple User",last_name:l||"",role:R,status:"active",provider:"apple",external_identifier:p}),E=await d.readOne(m));const y={id:m,role:E.role||R,app_access:!0,admin_access:!1},b=Mt.sign(y,n.SECRET,{expiresIn:"7d",issuer:"directus"}),v={id:m,type:"refresh"},S=Mt.sign(v,n.SECRET,{expiresIn:"30d",issuer:"directus"});t.json({success:!0,data:{access_token:b,refresh_token:S,expires:604800,user:E},user_id:m,email:f,provider:"apple"})}catch(e){t.status(500).json({error:e.message,message:"Failed to verify Apple token"})}}),e.post("/bridge-token",async(e,r)=>{try{const t=e.headers.authorization,i=t?.replace("Bearer ","");if(!i)return r.status(400).json({error:"No token provided"});const o=await fetch(`${p}/users/me`,{headers:{Authorization:`Bearer ${i}`}});if(!o.ok)return r.status(401).json({error:"Invalid token"});const s={sub:(await o.json()).data.id,purpose:"bridge"},a=Mt.sign(s,n.SECRET,{expiresIn:"60s",issuer:"directus-sso"});r.json({success:!0,bridge_token:a})}catch(e){r.status(500).json({error:e.message})}}),e.get("/bridge",async(e,r)=>{const{token:t,bridge_token:o,redirect_uri:s,redirect:a}=e.query,c=N(s||a,"/"),u="true"===n.ENABLE_LEGACY_BRIDGE;P(e);const l=e.accepts("html")||e.headers.accept?.includes("text/html")||/Mozilla|Chrome|Safari|Firefox|Edge|Opera/i.test(e.headers["user-agent"]||"");let f=null,h=null;if(o)try{const e=Mt.verify(o,n.SECRET,{issuer:"directus-sso"});if("bridge"!==e.purpose)return l?(r.setHeader("Content-Type","text/html"),r.status(400).send(T("Authentication Failed","Invalid token purpose.","INVALID_BRIDGE_TOKEN"))):r.status(400).json({error:"Invalid token purpose"});f=e.sub;const t={id:f,app_access:!0,admin_access:!1};h=Mt.sign(t,n.SECRET,{expiresIn:"7d",issuer:"directus"})}catch(e){return l?(r.setHeader("Content-Type","text/html"),r.status(401).send(T("Session Expired","Your secure login session has expired or is invalid. Please go back to the app and try logging in again.","EXPIRED_BRIDGE_TOKEN"))):r.status(401).json({error:"Invalid or expired bridge token",message:e.message})}else{if(!t||!u)return l?(r.setHeader("Content-Type","text/html"),r.status(400).send(T("Authentication Failed","Secure bridge token is required to start your session.","MISSING_BRIDGE_TOKEN"))):r.status(400).json({error:"Secure bridge token required"});i.warn("⚠️ Warning: Legacy bridge token used. This flow is vulnerable to session fixation.");try{const e=await fetch(`${p}/users/me`,{headers:{Authorization:`Bearer ${t}`}});if(!e.ok)return l?(r.setHeader("Content-Type","text/html"),r.status(401).send(T("Session Expired","Your secure login session has expired or is invalid. Please go back to the app and try logging in again.","INVALID_CREDENTIALS"))):r.status(401).json({error:"Invalid token"});f=(await e.json()).data.id,h=t}catch(e){return l?(r.setHeader("Content-Type","text/html"),r.status(500).send(T("Authentication Error","An unexpected error occurred while bridging your session.","BRIDGE_FAILURE"))):r.status(500).json({error:"Bridge failure",message:e.message})}}return r.cookie(I,h,{httpOnly:!0,secure:S,domain:v,sameSite:$,maxAge:6048e5,path:"/"}),I!==O&&r.cookie(O,h,{httpOnly:!0,secure:S,domain:v,sameSite:$,maxAge:6048e5,path:"/"}),r.redirect(c)})}};export{Ft as default};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@ymys/directus-extension-sso",
3
3
  "description": "Mobile OAuth proxy endpoints for Directus + Keycloak + Google + Apple",
4
4
  "icon": "smartphone",
5
- "version": "2.5.21",
5
+ "version": "2.6.22",
6
6
  "keywords": [
7
7
  "directus",
8
8
  "directus-extension",