authhero 0.259.0 → 0.261.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/authhero.cjs CHANGED
@@ -1,8 +1,8 @@
1
- "use strict";var lw=Object.defineProperty;var dw=(t,e,n)=>e in t?lw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var ae=(t,e,n)=>dw(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@hono/zod-openapi"),he=t=>typeof t=="string",Pi=()=>{let t,e;const n=new Promise((r,i)=>{t=r,e=i});return n.resolve=t,n.reject=e,n},Gp=t=>t==null?"":""+t,uw=(t,e,n)=>{t.forEach(r=>{e[r]&&(n[r]=e[r])})},pw=/###/g,Wp=t=>t&&t.indexOf("###")>-1?t.replace(pw,"."):t,Jp=t=>!t||he(t),Vi=(t,e,n)=>{const r=he(e)?e.split("."):e;let i=0;for(;i<r.length-1;){if(Jp(t))return{};const s=Wp(r[i]);!t[s]&&n&&(t[s]=new n),Object.prototype.hasOwnProperty.call(t,s)?t=t[s]:t={},++i}return Jp(t)?{}:{obj:t,k:Wp(r[i])}},Xp=(t,e,n)=>{const{obj:r,k:i}=Vi(t,e,Object);if(r!==void 0||e.length===1){r[i]=n;return}let s=e[e.length-1],a=e.slice(0,e.length-1),c=Vi(t,a,Object);for(;c.obj===void 0&&a.length;)s=`${a[a.length-1]}.${s}`,a=a.slice(0,a.length-1),c=Vi(t,a,Object),c!=null&&c.obj&&typeof c.obj[`${c.k}.${s}`]<"u"&&(c.obj=void 0);c.obj[`${c.k}.${s}`]=n},fw=(t,e,n,r)=>{const{obj:i,k:s}=Vi(t,e,Object);i[s]=i[s]||[],i[s].push(n)},Cs=(t,e)=>{const{obj:n,k:r}=Vi(t,e);if(n&&Object.prototype.hasOwnProperty.call(n,r))return n[r]},hw=(t,e,n)=>{const r=Cs(t,n);return r!==void 0?r:Cs(e,n)},f0=(t,e,n)=>{for(const r in e)r!=="__proto__"&&r!=="constructor"&&(r in t?he(t[r])||t[r]instanceof String||he(e[r])||e[r]instanceof String?n&&(t[r]=e[r]):f0(t[r],e[r],n):t[r]=e[r]);return t},Lr=t=>t.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&");var gw={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;"};const mw=t=>he(t)?t.replace(/[&<>"'\/]/g,e=>gw[e]):t;class _w{constructor(e){this.capacity=e,this.regExpMap=new Map,this.regExpQueue=[]}getRegExp(e){const n=this.regExpMap.get(e);if(n!==void 0)return n;const r=new RegExp(e);return this.regExpQueue.length===this.capacity&&this.regExpMap.delete(this.regExpQueue.shift()),this.regExpMap.set(e,r),this.regExpQueue.push(e),r}}const yw=[" ",",","?","!",";"],ww=new _w(20),vw=(t,e,n)=>{e=e||"",n=n||"";const r=yw.filter(a=>e.indexOf(a)<0&&n.indexOf(a)<0);if(r.length===0)return!0;const i=ww.getRegExp(`(${r.map(a=>a==="?"?"\\?":a).join("|")})`);let s=!i.test(t);if(!s){const a=t.indexOf(n);a>0&&!i.test(t.substring(0,a))&&(s=!0)}return s},$l=function(t,e){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:".";if(!t)return;if(t[e])return Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;const r=e.split(n);let i=t;for(let s=0;s<r.length;){if(!i||typeof i!="object")return;let a,c="";for(let l=s;l<r.length;++l)if(l!==s&&(c+=n),c+=r[l],a=i[c],a!==void 0){if(["string","number","boolean"].indexOf(typeof a)>-1&&l<r.length-1)continue;s+=l-s+1;break}i=a}return i},Ns=t=>t==null?void 0:t.replace("_","-"),bw={type:"logger",log(t){this.output("log",t)},warn(t){this.output("warn",t)},error(t){this.output("error",t)},output(t,e){var n,r;(r=(n=console==null?void 0:console[t])==null?void 0:n.apply)==null||r.call(n,console,e)}};class Is{constructor(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.init(e,n)}init(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.prefix=n.prefix||"i18next:",this.logger=e||bw,this.options=n,this.debug=n.debug}log(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return this.forward(n,"log","",!0)}warn(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return this.forward(n,"warn","",!0)}error(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return this.forward(n,"error","")}deprecate(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return this.forward(n,"warn","WARNING DEPRECATED: ",!0)}forward(e,n,r,i){return i&&!this.debug?null:(he(e[0])&&(e[0]=`${r}${this.prefix} ${e[0]}`),this.logger[n](e))}create(e){return new Is(this.logger,{prefix:`${this.prefix}:${e}:`,...this.options})}clone(e){return e=e||this.options,e.prefix=e.prefix||this.prefix,new Is(this.logger,e)}}var ln=new Is;class ja{constructor(){this.observers={}}on(e,n){return e.split(" ").forEach(r=>{this.observers[r]||(this.observers[r]=new Map);const i=this.observers[r].get(n)||0;this.observers[r].set(n,i+1)}),this}off(e,n){if(this.observers[e]){if(!n){delete this.observers[e];return}this.observers[e].delete(n)}}emit(e){for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];this.observers[e]&&Array.from(this.observers[e].entries()).forEach(a=>{let[c,l]=a;for(let d=0;d<l;d++)c(...r)}),this.observers["*"]&&Array.from(this.observers["*"].entries()).forEach(a=>{let[c,l]=a;for(let d=0;d<l;d++)c.apply(c,[e,...r])})}}class Zp extends ja{constructor(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{ns:["translation"],defaultNS:"translation"};super(),this.data=e||{},this.options=n,this.options.keySeparator===void 0&&(this.options.keySeparator="."),this.options.ignoreJSONStructure===void 0&&(this.options.ignoreJSONStructure=!0)}addNamespaces(e){this.options.ns.indexOf(e)<0&&this.options.ns.push(e)}removeNamespaces(e){const n=this.options.ns.indexOf(e);n>-1&&this.options.ns.splice(n,1)}getResource(e,n,r){var d,u;let i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};const s=i.keySeparator!==void 0?i.keySeparator:this.options.keySeparator,a=i.ignoreJSONStructure!==void 0?i.ignoreJSONStructure:this.options.ignoreJSONStructure;let c;e.indexOf(".")>-1?c=e.split("."):(c=[e,n],r&&(Array.isArray(r)?c.push(...r):he(r)&&s?c.push(...r.split(s)):c.push(r)));const l=Cs(this.data,c);return!l&&!n&&!r&&e.indexOf(".")>-1&&(e=c[0],n=c[1],r=c.slice(2).join(".")),l||!a||!he(r)?l:$l((u=(d=this.data)==null?void 0:d[e])==null?void 0:u[n],r,s)}addResource(e,n,r,i){let s=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{silent:!1};const a=s.keySeparator!==void 0?s.keySeparator:this.options.keySeparator;let c=[e,n];r&&(c=c.concat(a?r.split(a):r)),e.indexOf(".")>-1&&(c=e.split("."),i=n,n=c[1]),this.addNamespaces(n),Xp(this.data,c,i),s.silent||this.emit("added",e,n,r,i)}addResources(e,n,r){let i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{silent:!1};for(const s in r)(he(r[s])||Array.isArray(r[s]))&&this.addResource(e,n,s,r[s],{silent:!0});i.silent||this.emit("added",e,n,r)}addResourceBundle(e,n,r,i,s){let a=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{silent:!1,skipCopy:!1},c=[e,n];e.indexOf(".")>-1&&(c=e.split("."),i=r,r=n,n=c[1]),this.addNamespaces(n);let l=Cs(this.data,c)||{};a.skipCopy||(r=JSON.parse(JSON.stringify(r))),i?f0(l,r,s):l={...l,...r},Xp(this.data,c,l),a.silent||this.emit("added",e,n,r)}removeResourceBundle(e,n){this.hasResourceBundle(e,n)&&delete this.data[e][n],this.removeNamespaces(n),this.emit("removed",e,n)}hasResourceBundle(e,n){return this.getResource(e,n)!==void 0}getResourceBundle(e,n){return n||(n=this.options.defaultNS),this.getResource(e,n)}getDataByLanguage(e){return this.data[e]}hasLanguageSomeTranslations(e){const n=this.getDataByLanguage(e);return!!(n&&Object.keys(n)||[]).find(i=>n[i]&&Object.keys(n[i]).length>0)}toJSON(){return this.data}}var h0={processors:{},addPostProcessor(t){this.processors[t.name]=t},handle(t,e,n,r,i){return t.forEach(s=>{var a;e=((a=this.processors[s])==null?void 0:a.process(e,n,r,i))??e}),e}};const Yp={};class js extends ja{constructor(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),uw(["resourceStore","languageUtils","pluralResolver","interpolator","backendConnector","i18nFormat","utils"],e,this),this.options=n,this.options.keySeparator===void 0&&(this.options.keySeparator="."),this.logger=ln.create("translator")}changeLanguage(e){e&&(this.language=e)}exists(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{interpolation:{}};if(e==null)return!1;const r=this.resolve(e,n);return(r==null?void 0:r.res)!==void 0}extractFromKey(e,n){let r=n.nsSeparator!==void 0?n.nsSeparator:this.options.nsSeparator;r===void 0&&(r=":");const i=n.keySeparator!==void 0?n.keySeparator:this.options.keySeparator;let s=n.ns||this.options.defaultNS||[];const a=r&&e.indexOf(r)>-1,c=!this.options.userDefinedKeySeparator&&!n.keySeparator&&!this.options.userDefinedNsSeparator&&!n.nsSeparator&&!vw(e,r,i);if(a&&!c){const l=e.match(this.interpolator.nestingRegexp);if(l&&l.length>0)return{key:e,namespaces:he(s)?[s]:s};const d=e.split(r);(r!==i||r===i&&this.options.ns.indexOf(d[0])>-1)&&(s=d.shift()),e=d.join(i)}return{key:e,namespaces:he(s)?[s]:s}}translate(e,n,r){if(typeof n!="object"&&this.options.overloadTranslationOptionHandler&&(n=this.options.overloadTranslationOptionHandler(arguments)),typeof n=="object"&&(n={...n}),n||(n={}),e==null)return"";Array.isArray(e)||(e=[String(e)]);const i=n.returnDetails!==void 0?n.returnDetails:this.options.returnDetails,s=n.keySeparator!==void 0?n.keySeparator:this.options.keySeparator,{key:a,namespaces:c}=this.extractFromKey(e[e.length-1],n),l=c[c.length-1],d=n.lng||this.language,u=n.appendNamespaceToCIMode||this.options.appendNamespaceToCIMode;if((d==null?void 0:d.toLowerCase())==="cimode"){if(u){const T=n.nsSeparator||this.options.nsSeparator;return i?{res:`${l}${T}${a}`,usedKey:a,exactUsedKey:a,usedLng:d,usedNS:l,usedParams:this.getUsedParamsDetails(n)}:`${l}${T}${a}`}return i?{res:a,usedKey:a,exactUsedKey:a,usedLng:d,usedNS:l,usedParams:this.getUsedParamsDetails(n)}:a}const f=this.resolve(e,n);let h=f==null?void 0:f.res;const m=(f==null?void 0:f.usedKey)||a,y=(f==null?void 0:f.exactUsedKey)||a,v=Object.prototype.toString.apply(h),b=["[object Number]","[object Function]","[object RegExp]"],A=n.joinArrays!==void 0?n.joinArrays:this.options.joinArrays,O=!this.i18nFormat||this.i18nFormat.handleAsObject,U=!he(h)&&typeof h!="boolean"&&typeof h!="number";if(O&&h&&U&&b.indexOf(v)<0&&!(he(A)&&Array.isArray(h))){if(!n.returnObjects&&!this.options.returnObjects){this.options.returnedObjectHandler||this.logger.warn("accessing an object - but returnObjects options is not enabled!");const T=this.options.returnedObjectHandler?this.options.returnedObjectHandler(m,h,{...n,ns:c}):`key '${a} (${this.language})' returned an object instead of string.`;return i?(f.res=T,f.usedParams=this.getUsedParamsDetails(n),f):T}if(s){const T=Array.isArray(h),R=T?[]:{},W=T?y:m;for(const ne in h)if(Object.prototype.hasOwnProperty.call(h,ne)){const Q=`${W}${s}${ne}`;R[ne]=this.translate(Q,{...n,joinArrays:!1,ns:c}),R[ne]===Q&&(R[ne]=h[ne])}h=R}}else if(O&&he(A)&&Array.isArray(h))h=h.join(A),h&&(h=this.extendTranslation(h,e,n,r));else{let T=!1,R=!1;const W=n.count!==void 0&&!he(n.count),ne=js.hasDefaultValue(n),Q=W?this.pluralResolver.getSuffix(d,n.count,n):"",K=n.ordinal&&W?this.pluralResolver.getSuffix(d,n.count,{ordinal:!1}):"",de=W&&!n.ordinal&&n.count===0,N=de&&n[`defaultValue${this.options.pluralSeparator}zero`]||n[`defaultValue${Q}`]||n[`defaultValue${K}`]||n.defaultValue;!this.isValidLookup(h)&&ne&&(T=!0,h=N),this.isValidLookup(h)||(R=!0,h=a);const z=(n.missingKeyNoValueFallbackToKey||this.options.missingKeyNoValueFallbackToKey)&&R?void 0:h,k=ne&&N!==h&&this.options.updateMissing;if(R||T||k){if(this.logger.log(k?"updateKey":"missingKey",d,l,a,k?N:h),s){const q=this.resolve(a,{...n,keySeparator:!1});q&&q.res&&this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.")}let $=[];const I=this.languageUtils.getFallbackCodes(this.options.fallbackLng,n.lng||this.language);if(this.options.saveMissingTo==="fallback"&&I&&I[0])for(let q=0;q<I.length;q++)$.push(I[q]);else this.options.saveMissingTo==="all"?$=this.languageUtils.toResolveHierarchy(n.lng||this.language):$.push(n.lng||this.language);const L=(q,F,Z)=>{var D;const se=ne&&Z!==h?Z:z;this.options.missingKeyHandler?this.options.missingKeyHandler(q,l,F,se,k,n):(D=this.backendConnector)!=null&&D.saveMissing&&this.backendConnector.saveMissing(q,l,F,se,k,n),this.emit("missingKey",q,l,F,h)};this.options.saveMissing&&(this.options.saveMissingPlurals&&W?$.forEach(q=>{const F=this.pluralResolver.getSuffixes(q,n);de&&n[`defaultValue${this.options.pluralSeparator}zero`]&&F.indexOf(`${this.options.pluralSeparator}zero`)<0&&F.push(`${this.options.pluralSeparator}zero`),F.forEach(Z=>{L([q],a+Z,n[`defaultValue${Z}`]||N)})}):L($,a,N))}h=this.extendTranslation(h,e,n,f,r),R&&h===a&&this.options.appendNamespaceToMissingKey&&(h=`${l}:${a}`),(R||T)&&this.options.parseMissingKeyHandler&&(h=this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey?`${l}:${a}`:a,T?h:void 0))}return i?(f.res=h,f.usedParams=this.getUsedParamsDetails(n),f):h}extendTranslation(e,n,r,i,s){var d,u;var a=this;if((d=this.i18nFormat)!=null&&d.parse)e=this.i18nFormat.parse(e,{...this.options.interpolation.defaultVariables,...r},r.lng||this.language||i.usedLng,i.usedNS,i.usedKey,{resolved:i});else if(!r.skipInterpolation){r.interpolation&&this.interpolator.init({...r,interpolation:{...this.options.interpolation,...r.interpolation}});const f=he(e)&&(((u=r==null?void 0:r.interpolation)==null?void 0:u.skipOnVariables)!==void 0?r.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables);let h;if(f){const y=e.match(this.interpolator.nestingRegexp);h=y&&y.length}let m=r.replace&&!he(r.replace)?r.replace:r;if(this.options.interpolation.defaultVariables&&(m={...this.options.interpolation.defaultVariables,...m}),e=this.interpolator.interpolate(e,m,r.lng||this.language||i.usedLng,r),f){const y=e.match(this.interpolator.nestingRegexp),v=y&&y.length;h<v&&(r.nest=!1)}!r.lng&&i&&i.res&&(r.lng=this.language||i.usedLng),r.nest!==!1&&(e=this.interpolator.nest(e,function(){for(var y=arguments.length,v=new Array(y),b=0;b<y;b++)v[b]=arguments[b];return(s==null?void 0:s[0])===v[0]&&!r.context?(a.logger.warn(`It seems you are nesting recursively key: ${v[0]} in key: ${n[0]}`),null):a.translate(...v,n)},r)),r.interpolation&&this.interpolator.reset()}const c=r.postProcess||this.options.postProcess,l=he(c)?[c]:c;return e!=null&&(l!=null&&l.length)&&r.applyPostProcessor!==!1&&(e=h0.handle(l,e,n,this.options&&this.options.postProcessPassResolved?{i18nResolved:{...i,usedParams:this.getUsedParamsDetails(r)},...r}:r,this)),e}resolve(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r,i,s,a,c;return he(e)&&(e=[e]),e.forEach(l=>{if(this.isValidLookup(r))return;const d=this.extractFromKey(l,n),u=d.key;i=u;let f=d.namespaces;this.options.fallbackNS&&(f=f.concat(this.options.fallbackNS));const h=n.count!==void 0&&!he(n.count),m=h&&!n.ordinal&&n.count===0,y=n.context!==void 0&&(he(n.context)||typeof n.context=="number")&&n.context!=="",v=n.lngs?n.lngs:this.languageUtils.toResolveHierarchy(n.lng||this.language,n.fallbackLng);f.forEach(b=>{var A,O;this.isValidLookup(r)||(c=b,!Yp[`${v[0]}-${b}`]&&((A=this.utils)!=null&&A.hasLoadedNamespace)&&!((O=this.utils)!=null&&O.hasLoadedNamespace(c))&&(Yp[`${v[0]}-${b}`]=!0,this.logger.warn(`key "${i}" for languages "${v.join(", ")}" won't get resolved as namespace "${c}" was not yet loaded`,"This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!")),v.forEach(U=>{var W;if(this.isValidLookup(r))return;a=U;const T=[u];if((W=this.i18nFormat)!=null&&W.addLookupKeys)this.i18nFormat.addLookupKeys(T,u,U,b,n);else{let ne;h&&(ne=this.pluralResolver.getSuffix(U,n.count,n));const Q=`${this.options.pluralSeparator}zero`,K=`${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;if(h&&(T.push(u+ne),n.ordinal&&ne.indexOf(K)===0&&T.push(u+ne.replace(K,this.options.pluralSeparator)),m&&T.push(u+Q)),y){const de=`${u}${this.options.contextSeparator}${n.context}`;T.push(de),h&&(T.push(de+ne),n.ordinal&&ne.indexOf(K)===0&&T.push(de+ne.replace(K,this.options.pluralSeparator)),m&&T.push(de+Q))}}let R;for(;R=T.pop();)this.isValidLookup(r)||(s=R,r=this.getResource(U,b,R,n))}))})}),{res:r,usedKey:i,exactUsedKey:s,usedLng:a,usedNS:c}}isValidLookup(e){return e!==void 0&&!(!this.options.returnNull&&e===null)&&!(!this.options.returnEmptyString&&e==="")}getResource(e,n,r){var s;let i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};return(s=this.i18nFormat)!=null&&s.getResource?this.i18nFormat.getResource(e,n,r,i):this.resourceStore.getResource(e,n,r,i)}getUsedParamsDetails(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const n=["defaultValue","ordinal","context","replace","lng","lngs","fallbackLng","ns","keySeparator","nsSeparator","returnObjects","returnDetails","joinArrays","postProcess","interpolation"],r=e.replace&&!he(e.replace);let i=r?e.replace:e;if(r&&typeof e.count<"u"&&(i.count=e.count),this.options.interpolation.defaultVariables&&(i={...this.options.interpolation.defaultVariables,...i}),!r){i={...i};for(const s of n)delete i[s]}return i}static hasDefaultValue(e){const n="defaultValue";for(const r in e)if(Object.prototype.hasOwnProperty.call(e,r)&&n===r.substring(0,n.length)&&e[r]!==void 0)return!0;return!1}}class Qp{constructor(e){this.options=e,this.supportedLngs=this.options.supportedLngs||!1,this.logger=ln.create("languageUtils")}getScriptPartFromCode(e){if(e=Ns(e),!e||e.indexOf("-")<0)return null;const n=e.split("-");return n.length===2||(n.pop(),n[n.length-1].toLowerCase()==="x")?null:this.formatLanguageCode(n.join("-"))}getLanguagePartFromCode(e){if(e=Ns(e),!e||e.indexOf("-")<0)return e;const n=e.split("-");return this.formatLanguageCode(n[0])}formatLanguageCode(e){if(he(e)&&e.indexOf("-")>-1){let n;try{n=Intl.getCanonicalLocales(e)[0]}catch{}return n&&this.options.lowerCaseLng&&(n=n.toLowerCase()),n||(this.options.lowerCaseLng?e.toLowerCase():e)}return this.options.cleanCode||this.options.lowerCaseLng?e.toLowerCase():e}isSupportedCode(e){return(this.options.load==="languageOnly"||this.options.nonExplicitSupportedLngs)&&(e=this.getLanguagePartFromCode(e)),!this.supportedLngs||!this.supportedLngs.length||this.supportedLngs.indexOf(e)>-1}getBestMatchFromCodes(e){if(!e)return null;let n;return e.forEach(r=>{if(n)return;const i=this.formatLanguageCode(r);(!this.options.supportedLngs||this.isSupportedCode(i))&&(n=i)}),!n&&this.options.supportedLngs&&e.forEach(r=>{if(n)return;const i=this.getLanguagePartFromCode(r);if(this.isSupportedCode(i))return n=i;n=this.options.supportedLngs.find(s=>{if(s===i)return s;if(!(s.indexOf("-")<0&&i.indexOf("-")<0)&&(s.indexOf("-")>0&&i.indexOf("-")<0&&s.substring(0,s.indexOf("-"))===i||s.indexOf(i)===0&&i.length>1))return s})}),n||(n=this.getFallbackCodes(this.options.fallbackLng)[0]),n}getFallbackCodes(e,n){if(!e)return[];if(typeof e=="function"&&(e=e(n)),he(e)&&(e=[e]),Array.isArray(e))return e;if(!n)return e.default||[];let r=e[n];return r||(r=e[this.getScriptPartFromCode(n)]),r||(r=e[this.formatLanguageCode(n)]),r||(r=e[this.getLanguagePartFromCode(n)]),r||(r=e.default),r||[]}toResolveHierarchy(e,n){const r=this.getFallbackCodes(n||this.options.fallbackLng||[],e),i=[],s=a=>{a&&(this.isSupportedCode(a)?i.push(a):this.logger.warn(`rejecting language code not found in supportedLngs: ${a}`))};return he(e)&&(e.indexOf("-")>-1||e.indexOf("_")>-1)?(this.options.load!=="languageOnly"&&s(this.formatLanguageCode(e)),this.options.load!=="languageOnly"&&this.options.load!=="currentOnly"&&s(this.getScriptPartFromCode(e)),this.options.load!=="currentOnly"&&s(this.getLanguagePartFromCode(e))):he(e)&&s(this.formatLanguageCode(e)),r.forEach(a=>{i.indexOf(a)<0&&s(this.formatLanguageCode(a))}),i}}const ef={zero:0,one:1,two:2,few:3,many:4,other:5},tf={select:t=>t===1?"one":"other",resolvedOptions:()=>({pluralCategories:["one","other"]})};class $w{constructor(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.languageUtils=e,this.options=n,this.logger=ln.create("pluralResolver"),this.pluralRulesCache={}}addRule(e,n){this.rules[e]=n}clearCache(){this.pluralRulesCache={}}getRule(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const r=Ns(e==="dev"?"en":e),i=n.ordinal?"ordinal":"cardinal",s=JSON.stringify({cleanedCode:r,type:i});if(s in this.pluralRulesCache)return this.pluralRulesCache[s];let a;try{a=new Intl.PluralRules(r,{type:i})}catch{if(!Intl)return this.logger.error("No Intl support, please use an Intl polyfill!"),tf;if(!e.match(/-|_/))return tf;const l=this.languageUtils.getLanguagePartFromCode(e);a=this.getRule(l,n)}return this.pluralRulesCache[s]=a,a}needsPlural(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=this.getRule(e,n);return r||(r=this.getRule("dev",n)),(r==null?void 0:r.resolvedOptions().pluralCategories.length)>1}getPluralFormsOfKey(e,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return this.getSuffixes(e,r).map(i=>`${n}${i}`)}getSuffixes(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=this.getRule(e,n);return r||(r=this.getRule("dev",n)),r?r.resolvedOptions().pluralCategories.sort((i,s)=>ef[i]-ef[s]).map(i=>`${this.options.prepend}${n.ordinal?`ordinal${this.options.prepend}`:""}${i}`):[]}getSuffix(e,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const i=this.getRule(e,r);return i?`${this.options.prepend}${r.ordinal?`ordinal${this.options.prepend}`:""}${i.select(n)}`:(this.logger.warn(`no plural rule found for: ${e}`),this.getSuffix("dev",n,r))}}const nf=function(t,e,n){let r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:".",i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:!0,s=hw(t,e,n);return!s&&i&&he(n)&&(s=$l(t,n,r),s===void 0&&(s=$l(e,n,r))),s},Wc=t=>t.replace(/\$/g,"$$$$");class kw{constructor(){var n;let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.logger=ln.create("interpolator"),this.options=e,this.format=((n=e==null?void 0:e.interpolation)==null?void 0:n.format)||(r=>r),this.init(e)}init(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};e.interpolation||(e.interpolation={escapeValue:!0});const{escape:n,escapeValue:r,useRawValueToEscape:i,prefix:s,prefixEscaped:a,suffix:c,suffixEscaped:l,formatSeparator:d,unescapeSuffix:u,unescapePrefix:f,nestingPrefix:h,nestingPrefixEscaped:m,nestingSuffix:y,nestingSuffixEscaped:v,nestingOptionsSeparator:b,maxReplaces:A,alwaysFormat:O}=e.interpolation;this.escape=n!==void 0?n:mw,this.escapeValue=r!==void 0?r:!0,this.useRawValueToEscape=i!==void 0?i:!1,this.prefix=s?Lr(s):a||"{{",this.suffix=c?Lr(c):l||"}}",this.formatSeparator=d||",",this.unescapePrefix=u?"":f||"-",this.unescapeSuffix=this.unescapePrefix?"":u||"",this.nestingPrefix=h?Lr(h):m||Lr("$t("),this.nestingSuffix=y?Lr(y):v||Lr(")"),this.nestingOptionsSeparator=b||",",this.maxReplaces=A||1e3,this.alwaysFormat=O!==void 0?O:!1,this.resetRegExp()}reset(){this.options&&this.init(this.options)}resetRegExp(){const e=(n,r)=>(n==null?void 0:n.source)===r?(n.lastIndex=0,n):new RegExp(r,"g");this.regexp=e(this.regexp,`${this.prefix}(.+?)${this.suffix}`),this.regexpUnescape=e(this.regexpUnescape,`${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`),this.nestingRegexp=e(this.nestingRegexp,`${this.nestingPrefix}(.+?)${this.nestingSuffix}`)}interpolate(e,n,r,i){var m;let s,a,c;const l=this.options&&this.options.interpolation&&this.options.interpolation.defaultVariables||{},d=y=>{if(y.indexOf(this.formatSeparator)<0){const O=nf(n,l,y,this.options.keySeparator,this.options.ignoreJSONStructure);return this.alwaysFormat?this.format(O,void 0,r,{...i,...n,interpolationkey:y}):O}const v=y.split(this.formatSeparator),b=v.shift().trim(),A=v.join(this.formatSeparator).trim();return this.format(nf(n,l,b,this.options.keySeparator,this.options.ignoreJSONStructure),A,r,{...i,...n,interpolationkey:b})};this.resetRegExp();const u=(i==null?void 0:i.missingInterpolationHandler)||this.options.missingInterpolationHandler,f=((m=i==null?void 0:i.interpolation)==null?void 0:m.skipOnVariables)!==void 0?i.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables;return[{regex:this.regexpUnescape,safeValue:y=>Wc(y)},{regex:this.regexp,safeValue:y=>this.escapeValue?Wc(this.escape(y)):Wc(y)}].forEach(y=>{for(c=0;s=y.regex.exec(e);){const v=s[1].trim();if(a=d(v),a===void 0)if(typeof u=="function"){const A=u(e,s,i);a=he(A)?A:""}else if(i&&Object.prototype.hasOwnProperty.call(i,v))a="";else if(f){a=s[0];continue}else this.logger.warn(`missed to pass in variable ${v} for interpolating ${e}`),a="";else!he(a)&&!this.useRawValueToEscape&&(a=Gp(a));const b=y.safeValue(a);if(e=e.replace(s[0],b),f?(y.regex.lastIndex+=a.length,y.regex.lastIndex-=s[0].length):y.regex.lastIndex=0,c++,c>=this.maxReplaces)break}}),e}nest(e,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},i,s,a;const c=(l,d)=>{const u=this.nestingOptionsSeparator;if(l.indexOf(u)<0)return l;const f=l.split(new RegExp(`${u}[ ]*{`));let h=`{${f[1]}`;l=f[0],h=this.interpolate(h,a);const m=h.match(/'/g),y=h.match(/"/g);(((m==null?void 0:m.length)??0)%2===0&&!y||y.length%2!==0)&&(h=h.replace(/'/g,'"'));try{a=JSON.parse(h),d&&(a={...d,...a})}catch(v){return this.logger.warn(`failed parsing options string in nesting for key ${l}`,v),`${l}${u}${h}`}return a.defaultValue&&a.defaultValue.indexOf(this.prefix)>-1&&delete a.defaultValue,l};for(;i=this.nestingRegexp.exec(e);){let l=[];a={...r},a=a.replace&&!he(a.replace)?a.replace:a,a.applyPostProcessor=!1,delete a.defaultValue;let d=!1;if(i[0].indexOf(this.formatSeparator)!==-1&&!/{.*}/.test(i[1])){const u=i[1].split(this.formatSeparator).map(f=>f.trim());i[1]=u.shift(),l=u,d=!0}if(s=n(c.call(this,i[1].trim(),a),a),s&&i[0]===e&&!he(s))return s;he(s)||(s=Gp(s)),s||(this.logger.warn(`missed to resolve ${i[1]} for nesting ${e}`),s=""),d&&(s=l.reduce((u,f)=>this.format(u,f,r.lng,{...r,interpolationkey:i[1].trim()}),s.trim())),e=e.replace(i[0],s),this.regexp.lastIndex=0}return e}}const xw=t=>{let e=t.toLowerCase().trim();const n={};if(t.indexOf("(")>-1){const r=t.split("(");e=r[0].toLowerCase().trim();const i=r[1].substring(0,r[1].length-1);e==="currency"&&i.indexOf(":")<0?n.currency||(n.currency=i.trim()):e==="relativetime"&&i.indexOf(":")<0?n.range||(n.range=i.trim()):i.split(";").forEach(a=>{if(a){const[c,...l]=a.split(":"),d=l.join(":").trim().replace(/^'+|'+$/g,""),u=c.trim();n[u]||(n[u]=d),d==="false"&&(n[u]=!1),d==="true"&&(n[u]=!0),isNaN(d)||(n[u]=parseInt(d,10))}})}return{formatName:e,formatOptions:n}},Ur=t=>{const e={};return(n,r,i)=>{let s=i;i&&i.interpolationkey&&i.formatParams&&i.formatParams[i.interpolationkey]&&i[i.interpolationkey]&&(s={...s,[i.interpolationkey]:void 0});const a=r+JSON.stringify(s);let c=e[a];return c||(c=t(Ns(r),i),e[a]=c),c(n)}};class Sw{constructor(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.logger=ln.create("formatter"),this.options=e,this.formats={number:Ur((n,r)=>{const i=new Intl.NumberFormat(n,{...r});return s=>i.format(s)}),currency:Ur((n,r)=>{const i=new Intl.NumberFormat(n,{...r,style:"currency"});return s=>i.format(s)}),datetime:Ur((n,r)=>{const i=new Intl.DateTimeFormat(n,{...r});return s=>i.format(s)}),relativetime:Ur((n,r)=>{const i=new Intl.RelativeTimeFormat(n,{...r});return s=>i.format(s,r.range||"day")}),list:Ur((n,r)=>{const i=new Intl.ListFormat(n,{...r});return s=>i.format(s)})},this.init(e)}init(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{interpolation:{}};this.formatSeparator=n.interpolation.formatSeparator||","}add(e,n){this.formats[e.toLowerCase().trim()]=n}addCached(e,n){this.formats[e.toLowerCase().trim()]=Ur(n)}format(e,n,r){let i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};const s=n.split(this.formatSeparator);if(s.length>1&&s[0].indexOf("(")>1&&s[0].indexOf(")")<0&&s.find(c=>c.indexOf(")")>-1)){const c=s.findIndex(l=>l.indexOf(")")>-1);s[0]=[s[0],...s.splice(1,c)].join(this.formatSeparator)}return s.reduce((c,l)=>{var f;const{formatName:d,formatOptions:u}=xw(l);if(this.formats[d]){let h=c;try{const m=((f=i==null?void 0:i.formatParams)==null?void 0:f[i.interpolationkey])||{},y=m.locale||m.lng||i.locale||i.lng||r;h=this.formats[d](c,y,{...u,...i,...m})}catch(m){this.logger.warn(m)}return h}else this.logger.warn(`there was no format function for ${d}`);return c},e)}}const zw=(t,e)=>{t.pending[e]!==void 0&&(delete t.pending[e],t.pendingCount--)};class Aw extends ja{constructor(e,n,r){var s,a;let i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};super(),this.backend=e,this.store=n,this.services=r,this.languageUtils=r.languageUtils,this.options=i,this.logger=ln.create("backendConnector"),this.waitingReads=[],this.maxParallelReads=i.maxParallelReads||10,this.readingCalls=0,this.maxRetries=i.maxRetries>=0?i.maxRetries:5,this.retryTimeout=i.retryTimeout>=1?i.retryTimeout:350,this.state={},this.queue=[],(a=(s=this.backend)==null?void 0:s.init)==null||a.call(s,r,i.backend,i)}queueLoad(e,n,r,i){const s={},a={},c={},l={};return e.forEach(d=>{let u=!0;n.forEach(f=>{const h=`${d}|${f}`;!r.reload&&this.store.hasResourceBundle(d,f)?this.state[h]=2:this.state[h]<0||(this.state[h]===1?a[h]===void 0&&(a[h]=!0):(this.state[h]=1,u=!1,a[h]===void 0&&(a[h]=!0),s[h]===void 0&&(s[h]=!0),l[f]===void 0&&(l[f]=!0)))}),u||(c[d]=!0)}),(Object.keys(s).length||Object.keys(a).length)&&this.queue.push({pending:a,pendingCount:Object.keys(a).length,loaded:{},errors:[],callback:i}),{toLoad:Object.keys(s),pending:Object.keys(a),toLoadLanguages:Object.keys(c),toLoadNamespaces:Object.keys(l)}}loaded(e,n,r){const i=e.split("|"),s=i[0],a=i[1];n&&this.emit("failedLoading",s,a,n),!n&&r&&this.store.addResourceBundle(s,a,r,void 0,void 0,{skipCopy:!0}),this.state[e]=n?-1:2,n&&r&&(this.state[e]=0);const c={};this.queue.forEach(l=>{fw(l.loaded,[s],a),zw(l,e),n&&l.errors.push(n),l.pendingCount===0&&!l.done&&(Object.keys(l.loaded).forEach(d=>{c[d]||(c[d]={});const u=l.loaded[d];u.length&&u.forEach(f=>{c[d][f]===void 0&&(c[d][f]=!0)})}),l.done=!0,l.errors.length?l.callback(l.errors):l.callback())}),this.emit("loaded",c),this.queue=this.queue.filter(l=>!l.done)}read(e,n,r){let i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0,s=arguments.length>4&&arguments[4]!==void 0?arguments[4]:this.retryTimeout,a=arguments.length>5?arguments[5]:void 0;if(!e.length)return a(null,{});if(this.readingCalls>=this.maxParallelReads){this.waitingReads.push({lng:e,ns:n,fcName:r,tried:i,wait:s,callback:a});return}this.readingCalls++;const c=(d,u)=>{if(this.readingCalls--,this.waitingReads.length>0){const f=this.waitingReads.shift();this.read(f.lng,f.ns,f.fcName,f.tried,f.wait,f.callback)}if(d&&u&&i<this.maxRetries){setTimeout(()=>{this.read.call(this,e,n,r,i+1,s*2,a)},s);return}a(d,u)},l=this.backend[r].bind(this.backend);if(l.length===2){try{const d=l(e,n);d&&typeof d.then=="function"?d.then(u=>c(null,u)).catch(c):c(null,d)}catch(d){c(d)}return}return l(e,n,c)}prepareLoading(e,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},i=arguments.length>3?arguments[3]:void 0;if(!this.backend)return this.logger.warn("No backend was added via i18next.use. Will not load resources."),i&&i();he(e)&&(e=this.languageUtils.toResolveHierarchy(e)),he(n)&&(n=[n]);const s=this.queueLoad(e,n,r,i);if(!s.toLoad.length)return s.pending.length||i(),null;s.toLoad.forEach(a=>{this.loadOne(a)})}load(e,n,r){this.prepareLoading(e,n,{},r)}reload(e,n,r){this.prepareLoading(e,n,{reload:!0},r)}loadOne(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"";const r=e.split("|"),i=r[0],s=r[1];this.read(i,s,"read",void 0,void 0,(a,c)=>{a&&this.logger.warn(`${n}loading namespace ${s} for language ${i} failed`,a),!a&&c&&this.logger.log(`${n}loaded namespace ${s} for language ${i}`,c),this.loaded(e,a,c)})}saveMissing(e,n,r,i,s){var l,d,u,f,h;let a=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{},c=arguments.length>6&&arguments[6]!==void 0?arguments[6]:()=>{};if((d=(l=this.services)==null?void 0:l.utils)!=null&&d.hasLoadedNamespace&&!((f=(u=this.services)==null?void 0:u.utils)!=null&&f.hasLoadedNamespace(n))){this.logger.warn(`did not save key "${r}" as the namespace "${n}" was not yet loaded`,"This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");return}if(!(r==null||r==="")){if((h=this.backend)!=null&&h.create){const m={...a,isUpdate:s},y=this.backend.create.bind(this.backend);if(y.length<6)try{let v;y.length===5?v=y(e,n,r,i,m):v=y(e,n,r,i),v&&typeof v.then=="function"?v.then(b=>c(null,b)).catch(c):c(null,v)}catch(v){c(v)}else y(e,n,r,i,c,m)}!e||!e[0]||this.store.addResource(e[0],n,r,i)}}}const rf=()=>({debug:!1,initAsync:!0,ns:["translation"],defaultNS:["translation"],fallbackLng:["dev"],fallbackNS:!1,supportedLngs:!1,nonExplicitSupportedLngs:!1,load:"all",preload:!1,simplifyPluralSuffix:!0,keySeparator:".",nsSeparator:":",pluralSeparator:"_",contextSeparator:"_",partialBundledLanguages:!1,saveMissing:!1,updateMissing:!1,saveMissingTo:"fallback",saveMissingPlurals:!0,missingKeyHandler:!1,missingInterpolationHandler:!1,postProcess:!1,postProcessPassResolved:!1,returnNull:!1,returnEmptyString:!0,returnObjects:!1,joinArrays:!1,returnedObjectHandler:!1,parseMissingKeyHandler:!1,appendNamespaceToMissingKey:!1,appendNamespaceToCIMode:!1,overloadTranslationOptionHandler:t=>{let e={};if(typeof t[1]=="object"&&(e=t[1]),he(t[1])&&(e.defaultValue=t[1]),he(t[2])&&(e.tDescription=t[2]),typeof t[2]=="object"||typeof t[3]=="object"){const n=t[3]||t[2];Object.keys(n).forEach(r=>{e[r]=n[r]})}return e},interpolation:{escapeValue:!0,format:t=>t,prefix:"{{",suffix:"}}",formatSeparator:",",unescapePrefix:"-",nestingPrefix:"$t(",nestingSuffix:")",nestingOptionsSeparator:",",maxReplaces:1e3,skipOnVariables:!0}}),of=t=>{var e,n;return he(t.ns)&&(t.ns=[t.ns]),he(t.fallbackLng)&&(t.fallbackLng=[t.fallbackLng]),he(t.fallbackNS)&&(t.fallbackNS=[t.fallbackNS]),((n=(e=t.supportedLngs)==null?void 0:e.indexOf)==null?void 0:n.call(e,"cimode"))<0&&(t.supportedLngs=t.supportedLngs.concat(["cimode"])),typeof t.initImmediate=="boolean"&&(t.initAsync=t.initImmediate),t},ts=()=>{},Ew=t=>{Object.getOwnPropertyNames(Object.getPrototypeOf(t)).forEach(n=>{typeof t[n]=="function"&&(t[n]=t[n].bind(t))})};class no extends ja{constructor(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(super(),this.options=of(e),this.services={},this.logger=ln,this.modules={external:[]},Ew(this),n&&!this.isInitialized&&!e.isClone){if(!this.options.initAsync)return this.init(e,n),this;setTimeout(()=>{this.init(e,n)},0)}}init(){var e=this;let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;this.isInitializing=!0,typeof n=="function"&&(r=n,n={}),!n.defaultNS&&n.defaultNS!==!1&&n.ns&&(he(n.ns)?n.defaultNS=n.ns:n.ns.indexOf("translation")<0&&(n.defaultNS=n.ns[0]));const i=rf();this.options={...i,...this.options,...of(n)},this.options.interpolation={...i.interpolation,...this.options.interpolation},n.keySeparator!==void 0&&(this.options.userDefinedKeySeparator=n.keySeparator),n.nsSeparator!==void 0&&(this.options.userDefinedNsSeparator=n.nsSeparator);const s=u=>u?typeof u=="function"?new u:u:null;if(!this.options.isClone){this.modules.logger?ln.init(s(this.modules.logger),this.options):ln.init(null,this.options);let u;this.modules.formatter?u=this.modules.formatter:u=Sw;const f=new Qp(this.options);this.store=new Zp(this.options.resources,this.options);const h=this.services;h.logger=ln,h.resourceStore=this.store,h.languageUtils=f,h.pluralResolver=new $w(f,{prepend:this.options.pluralSeparator,simplifyPluralSuffix:this.options.simplifyPluralSuffix}),u&&(!this.options.interpolation.format||this.options.interpolation.format===i.interpolation.format)&&(h.formatter=s(u),h.formatter.init(h,this.options),this.options.interpolation.format=h.formatter.format.bind(h.formatter)),h.interpolator=new kw(this.options),h.utils={hasLoadedNamespace:this.hasLoadedNamespace.bind(this)},h.backendConnector=new Aw(s(this.modules.backend),h.resourceStore,h,this.options),h.backendConnector.on("*",function(m){for(var y=arguments.length,v=new Array(y>1?y-1:0),b=1;b<y;b++)v[b-1]=arguments[b];e.emit(m,...v)}),this.modules.languageDetector&&(h.languageDetector=s(this.modules.languageDetector),h.languageDetector.init&&h.languageDetector.init(h,this.options.detection,this.options)),this.modules.i18nFormat&&(h.i18nFormat=s(this.modules.i18nFormat),h.i18nFormat.init&&h.i18nFormat.init(this)),this.translator=new js(this.services,this.options),this.translator.on("*",function(m){for(var y=arguments.length,v=new Array(y>1?y-1:0),b=1;b<y;b++)v[b-1]=arguments[b];e.emit(m,...v)}),this.modules.external.forEach(m=>{m.init&&m.init(this)})}if(this.format=this.options.interpolation.format,r||(r=ts),this.options.fallbackLng&&!this.services.languageDetector&&!this.options.lng){const u=this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);u.length>0&&u[0]!=="dev"&&(this.options.lng=u[0])}!this.services.languageDetector&&!this.options.lng&&this.logger.warn("init: no languageDetector is used and no lng is defined"),["getResource","hasResourceBundle","getResourceBundle","getDataByLanguage"].forEach(u=>{this[u]=function(){return e.store[u](...arguments)}}),["addResource","addResources","addResourceBundle","removeResourceBundle"].forEach(u=>{this[u]=function(){return e.store[u](...arguments),e}});const l=Pi(),d=()=>{const u=(f,h)=>{this.isInitializing=!1,this.isInitialized&&!this.initializedStoreOnce&&this.logger.warn("init: i18next is already initialized. You should call init just once!"),this.isInitialized=!0,this.options.isClone||this.logger.log("initialized",this.options),this.emit("initialized",this.options),l.resolve(h),r(f,h)};if(this.languages&&!this.isInitialized)return u(null,this.t.bind(this));this.changeLanguage(this.options.lng,u)};return this.options.resources||!this.options.initAsync?d():setTimeout(d,0),l}loadResources(e){var s,a;let r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:ts;const i=he(e)?e:this.language;if(typeof e=="function"&&(r=e),!this.options.resources||this.options.partialBundledLanguages){if((i==null?void 0:i.toLowerCase())==="cimode"&&(!this.options.preload||this.options.preload.length===0))return r();const c=[],l=d=>{if(!d||d==="cimode")return;this.services.languageUtils.toResolveHierarchy(d).forEach(f=>{f!=="cimode"&&c.indexOf(f)<0&&c.push(f)})};i?l(i):this.services.languageUtils.getFallbackCodes(this.options.fallbackLng).forEach(u=>l(u)),(a=(s=this.options.preload)==null?void 0:s.forEach)==null||a.call(s,d=>l(d)),this.services.backendConnector.load(c,this.options.ns,d=>{!d&&!this.resolvedLanguage&&this.language&&this.setResolvedLanguage(this.language),r(d)})}else r(null)}reloadResources(e,n,r){const i=Pi();return typeof e=="function"&&(r=e,e=void 0),typeof n=="function"&&(r=n,n=void 0),e||(e=this.languages),n||(n=this.options.ns),r||(r=ts),this.services.backendConnector.reload(e,n,s=>{i.resolve(),r(s)}),i}use(e){if(!e)throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");if(!e.type)throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");return e.type==="backend"&&(this.modules.backend=e),(e.type==="logger"||e.log&&e.warn&&e.error)&&(this.modules.logger=e),e.type==="languageDetector"&&(this.modules.languageDetector=e),e.type==="i18nFormat"&&(this.modules.i18nFormat=e),e.type==="postProcessor"&&h0.addPostProcessor(e),e.type==="formatter"&&(this.modules.formatter=e),e.type==="3rdParty"&&this.modules.external.push(e),this}setResolvedLanguage(e){if(!(!e||!this.languages)&&!(["cimode","dev"].indexOf(e)>-1))for(let n=0;n<this.languages.length;n++){const r=this.languages[n];if(!(["cimode","dev"].indexOf(r)>-1)&&this.store.hasLanguageSomeTranslations(r)){this.resolvedLanguage=r;break}}}changeLanguage(e,n){var r=this;this.isLanguageChangingTo=e;const i=Pi();this.emit("languageChanging",e);const s=l=>{this.language=l,this.languages=this.services.languageUtils.toResolveHierarchy(l),this.resolvedLanguage=void 0,this.setResolvedLanguage(l)},a=(l,d)=>{d?(s(d),this.translator.changeLanguage(d),this.isLanguageChangingTo=void 0,this.emit("languageChanged",d),this.logger.log("languageChanged",d)):this.isLanguageChangingTo=void 0,i.resolve(function(){return r.t(...arguments)}),n&&n(l,function(){return r.t(...arguments)})},c=l=>{var u,f;!e&&!l&&this.services.languageDetector&&(l=[]);const d=he(l)?l:this.services.languageUtils.getBestMatchFromCodes(l);d&&(this.language||s(d),this.translator.language||this.translator.changeLanguage(d),(f=(u=this.services.languageDetector)==null?void 0:u.cacheUserLanguage)==null||f.call(u,d)),this.loadResources(d,h=>{a(h,d)})};return!e&&this.services.languageDetector&&!this.services.languageDetector.async?c(this.services.languageDetector.detect()):!e&&this.services.languageDetector&&this.services.languageDetector.async?this.services.languageDetector.detect.length===0?this.services.languageDetector.detect().then(c):this.services.languageDetector.detect(c):c(e),i}getFixedT(e,n,r){var i=this;const s=function(a,c){let l;if(typeof c!="object"){for(var d=arguments.length,u=new Array(d>2?d-2:0),f=2;f<d;f++)u[f-2]=arguments[f];l=i.options.overloadTranslationOptionHandler([a,c].concat(u))}else l={...c};l.lng=l.lng||s.lng,l.lngs=l.lngs||s.lngs,l.ns=l.ns||s.ns,l.keyPrefix!==""&&(l.keyPrefix=l.keyPrefix||r||s.keyPrefix);const h=i.options.keySeparator||".";let m;return l.keyPrefix&&Array.isArray(a)?m=a.map(y=>`${l.keyPrefix}${h}${y}`):m=l.keyPrefix?`${l.keyPrefix}${h}${a}`:a,i.t(m,l)};return he(e)?s.lng=e:s.lngs=e,s.ns=n,s.keyPrefix=r,s}t(){var i;for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return(i=this.translator)==null?void 0:i.translate(...n)}exists(){var i;for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return(i=this.translator)==null?void 0:i.exists(...n)}setDefaultNamespace(e){this.options.defaultNS=e}hasLoadedNamespace(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!this.isInitialized)return this.logger.warn("hasLoadedNamespace: i18next was not initialized",this.languages),!1;if(!this.languages||!this.languages.length)return this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty",this.languages),!1;const r=n.lng||this.resolvedLanguage||this.languages[0],i=this.options?this.options.fallbackLng:!1,s=this.languages[this.languages.length-1];if(r.toLowerCase()==="cimode")return!0;const a=(c,l)=>{const d=this.services.backendConnector.state[`${c}|${l}`];return d===-1||d===0||d===2};if(n.precheck){const c=n.precheck(this,a);if(c!==void 0)return c}return!!(this.hasResourceBundle(r,e)||!this.services.backendConnector.backend||this.options.resources&&!this.options.partialBundledLanguages||a(r,e)&&(!i||a(s,e)))}loadNamespaces(e,n){const r=Pi();return this.options.ns?(he(e)&&(e=[e]),e.forEach(i=>{this.options.ns.indexOf(i)<0&&this.options.ns.push(i)}),this.loadResources(i=>{r.resolve(),n&&n(i)}),r):(n&&n(),Promise.resolve())}loadLanguages(e,n){const r=Pi();he(e)&&(e=[e]);const i=this.options.preload||[],s=e.filter(a=>i.indexOf(a)<0&&this.services.languageUtils.isSupportedCode(a));return s.length?(this.options.preload=i.concat(s),this.loadResources(a=>{r.resolve(),n&&n(a)}),r):(n&&n(),Promise.resolve())}dir(e){var i,s;if(e||(e=this.resolvedLanguage||(((i=this.languages)==null?void 0:i.length)>0?this.languages[0]:this.language)),!e)return"rtl";const n=["ar","shu","sqr","ssh","xaa","yhd","yud","aao","abh","abv","acm","acq","acw","acx","acy","adf","ads","aeb","aec","afb","ajp","apc","apd","arb","arq","ars","ary","arz","auz","avl","ayh","ayl","ayn","ayp","bbz","pga","he","iw","ps","pbt","pbu","pst","prp","prd","ug","ur","ydd","yds","yih","ji","yi","hbo","men","xmn","fa","jpr","peo","pes","prs","dv","sam","ckb"],r=((s=this.services)==null?void 0:s.languageUtils)||new Qp(rf());return n.indexOf(r.getLanguagePartFromCode(e))>-1||e.toLowerCase().indexOf("-arab")>1?"rtl":"ltr"}static createInstance(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;return new no(e,n)}cloneInstance(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:ts;const r=e.forkResourceStore;r&&delete e.forkResourceStore;const i={...this.options,...e,isClone:!0},s=new no(i);if((e.debug!==void 0||e.prefix!==void 0)&&(s.logger=s.logger.clone(e)),["store","services","language"].forEach(c=>{s[c]=this[c]}),s.services={...this.services},s.services.utils={hasLoadedNamespace:s.hasLoadedNamespace.bind(s)},r){const c=Object.keys(this.store.data).reduce((l,d)=>(l[d]={...this.store.data[d]},Object.keys(l[d]).reduce((u,f)=>(u[f]={...l[d][f]},u),{})),{});s.store=new Zp(c,i),s.services.resourceStore=s.store}return s.translator=new js(s.services,i),s.translator.on("*",function(c){for(var l=arguments.length,d=new Array(l>1?l-1:0),u=1;u<l;u++)d[u-1]=arguments[u];s.emit(c,...d)}),s.init(i,n),s.translator.options=i,s.translator.backendConnector.services.utils={hasLoadedNamespace:s.hasLoadedNamespace.bind(s)},s}toJSON(){return{options:this.options,store:this.store,language:this.language,languages:this.languages,resolvedLanguage:this.resolvedLanguage}}}const w=no.createInstance();w.createInstance=no.createInstance;w.createInstance;w.dir;w.init;w.loadResources;w.reloadResources;w.use;w.changeLanguage;w.getFixedT;const pe=w.t;w.exists;w.setDefaultNamespace;w.hasLoadedNamespace;w.loadNamespaces;w.loadLanguages;var g0=t=>{const n={...{origin:"*",allowMethods:["GET","HEAD","PUT","POST","DELETE","PATCH"],allowHeaders:[],exposeHeaders:[]},...t},r=(s=>typeof s=="string"?s==="*"?()=>s:a=>s===a?a:null:typeof s=="function"?s:a=>s.includes(a)?a:null)(n.origin),i=(s=>typeof s=="function"?s:Array.isArray(s)?()=>s:()=>[])(n.allowMethods);return async function(a,c){var u;function l(f,h){a.res.headers.set(f,h)}const d=r(a.req.header("origin")||"",a);if(d&&l("Access-Control-Allow-Origin",d),n.origin!=="*"){const f=a.req.header("Vary");f?l("Vary",f):l("Vary","Origin")}if(n.credentials&&l("Access-Control-Allow-Credentials","true"),(u=n.exposeHeaders)!=null&&u.length&&l("Access-Control-Expose-Headers",n.exposeHeaders.join(",")),a.req.method==="OPTIONS"){n.maxAge!=null&&l("Access-Control-Max-Age",n.maxAge.toString());const f=i(a.req.header("origin")||"",a);f.length&&l("Access-Control-Allow-Methods",f.join(","));let h=n.allowHeaders;if(!(h!=null&&h.length)){const m=a.req.header("Access-Control-Request-Headers");m&&(h=m.split(/\s*,\s*/))}return h!=null&&h.length&&(l("Access-Control-Allow-Headers",h.join(",")),a.res.headers.append("Vary","Access-Control-Request-Headers")),a.res.headers.delete("Content-Length"),a.res.headers.delete("Content-Type"),new Response(null,{headers:a.res.headers,status:204,statusText:"No Content"})}await c()}};const St=o.z.object({start:o.z.number(),limit:o.z.number(),length:o.z.number()}),yi=o.z.object({created_at:o.z.string(),updated_at:o.z.string()}),m0=o.z.object({email:o.z.string().optional(),email_verified:o.z.boolean().optional(),name:o.z.string().optional(),username:o.z.string().optional(),given_name:o.z.string().optional(),phone_number:o.z.string().optional(),phone_verified:o.z.boolean().optional(),family_name:o.z.string().optional()}).catchall(o.z.any()),_0=o.z.object({connection:o.z.string(),user_id:o.z.string(),provider:o.z.string(),isSocial:o.z.boolean(),access_token:o.z.string().optional(),access_token_secret:o.z.string().optional(),refresh_token:o.z.string().optional(),profileData:m0.optional()}),Oa=o.z.object({email:o.z.string().optional().transform(t=>t&&t.toLowerCase()),username:o.z.string().optional(),phone_number:o.z.string().optional(),given_name:o.z.string().optional(),family_name:o.z.string().optional(),nickname:o.z.string().optional(),name:o.z.string().optional(),picture:o.z.string().optional(),locale:o.z.string().optional(),linked_to:o.z.string().optional(),profileData:o.z.string().optional(),user_id:o.z.string().optional(),app_metadata:o.z.any().default({}).optional(),user_metadata:o.z.any().default({}).optional()}),Os=Oa.extend({email_verified:o.z.boolean().default(!1),verify_email:o.z.boolean().optional(),last_ip:o.z.string().optional(),last_login:o.z.string().optional(),user_id:o.z.string().optional(),provider:o.z.string().default("email"),connection:o.z.string().default("email"),is_social:o.z.boolean().optional()}),gu=o.z.object({...Os.shape,...yi.shape,user_id:o.z.string(),is_social:o.z.boolean(),email:o.z.string().optional(),login_count:o.z.number().default(0),identities:o.z.array(_0).optional()}),cn=gu,Cw=Oa.extend({login_count:o.z.number(),multifactor:o.z.array(o.z.string()).optional(),last_ip:o.z.string().optional(),last_login:o.z.string().optional(),user_id:o.z.string()}).catchall(o.z.any()),Nw="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Iw=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t));for(;t--;)e+=Nw[n[t]&63];return e};const Ts=o.z.object({client_id:o.z.string().openapi({description:"ID of this client."}),name:o.z.string().min(1).openapi({description:"Name of this client (min length: 1 character, does not allow < or >)."}),description:o.z.string().max(140).optional().openapi({description:"Free text description of this client (max length: 140 characters)."}),global:o.z.boolean().default(!1).openapi({description:"Whether this is your global 'All Applications' client representing legacy tenant settings (true) or a regular client (false)."}),client_secret:o.z.string().default(()=>Iw()).optional().openapi({description:"Client secret (which you must not make public)."}),app_type:o.z.enum(["native","spa","regular_web","non_interactive","resource_server","express_configuration","rms","box","cloudbees","concur","dropbox","mscrm","echosign","egnyte","newrelic","office365","salesforce","sentry","sharepoint","slack","springcm","zendesk","zoom","sso_integration","oag"]).default("regular_web").optional().openapi({description:"The type of application this client represents"}),logo_uri:o.z.string().url().optional().openapi({description:"URL of the logo to display for this client. Recommended size is 150x150 pixels."}),is_first_party:o.z.boolean().default(!1).openapi({description:"Whether this client a first party client (true) or not (false)."}),oidc_conformant:o.z.boolean().default(!0).openapi({description:"Whether this client conforms to strict OIDC specifications (true) or uses legacy features (false)."}),callbacks:o.z.array(o.z.string()).default([]).optional().openapi({description:"Comma-separated list of URLs whitelisted for Auth0 to use as a callback to the client after authentication."}),allowed_origins:o.z.array(o.z.string()).default([]).optional().openapi({description:"Comma-separated list of URLs allowed to make requests from JavaScript to Auth0 API (typically used with CORS). By default, all your callback URLs will be allowed. This field allows you to enter other origins if necessary. You can also use wildcards at the subdomain level (e.g., https://*.contoso.com). Query strings and hash information are not taken into account when validating these URLs."}),web_origins:o.z.array(o.z.string()).default([]).optional().openapi({description:"Comma-separated list of allowed origins for use with Cross-Origin Authentication, Device Flow, and web message response mode."}),client_aliases:o.z.array(o.z.string()).default([]).optional().openapi({description:"List of audiences/realms for SAML protocol. Used by the wsfed addon."}),allowed_clients:o.z.array(o.z.string()).default([]).optional().openapi({description:"List of allow clients and API ids that are allowed to make delegation requests. Empty means all all your clients are allowed."}),allowed_logout_urls:o.z.array(o.z.string()).default([]).optional().openapi({description:"Comma-separated list of URLs that are valid to redirect to after logout from Auth0. Wildcards are allowed for subdomains."}),session_transfer:o.z.record(o.z.any()).default({}).optional().openapi({description:"Native to Web SSO Configuration"}),oidc_logout:o.z.record(o.z.any()).default({}).optional().openapi({description:"Configuration for OIDC backchannel logout"}),grant_types:o.z.array(o.z.string()).default([]).optional().openapi({description:"List of grant types supported for this application. Can include authorization_code, implicit, refresh_token, client_credentials, password, http://auth0.com/oauth/grant-type/password-realm, http://auth0.com/oauth/grant-type/mfa-oob, http://auth0.com/oauth/grant-type/mfa-otp, http://auth0.com/oauth/grant-type/mfa-recovery-code, urn:openid:params:grant-type:ciba, and urn:ietf:params:oauth:grant-type:device_code."}),jwt_configuration:o.z.record(o.z.any()).default({}).optional().openapi({description:"Configuration related to JWTs for the client."}),signing_keys:o.z.array(o.z.record(o.z.any())).default([]).optional().openapi({description:"Signing certificates associated with this client."}),encryption_key:o.z.record(o.z.any()).default({}).optional().openapi({description:"Encryption used for WsFed responses with this client."}),sso:o.z.boolean().default(!1).openapi({description:"Applies only to SSO clients and determines whether Auth0 will handle Single Sign On (true) or whether the Identity Provider will (false)."}),sso_disabled:o.z.boolean().default(!0).openapi({description:"Whether Single Sign On is disabled (true) or enabled (true). Defaults to true."}),cross_origin_authentication:o.z.boolean().default(!1).openapi({description:"Whether this client can be used to make cross-origin authentication requests (true) or it is not allowed to make such requests (false)."}),cross_origin_loc:o.z.string().url().optional().openapi({description:"URL of the location in your site where the cross origin verification takes place for the cross-origin auth flow when performing Auth in your own domain instead of Auth0 hosted login page."}),custom_login_page_on:o.z.boolean().default(!1).openapi({description:"Whether a custom login page is to be used (true) or the default provided login page (false)."}),custom_login_page:o.z.string().optional().openapi({description:"The content (HTML, CSS, JS) of the custom login page."}),custom_login_page_preview:o.z.string().optional().openapi({description:"The content (HTML, CSS, JS) of the custom login page. (Used on Previews)"}),form_template:o.z.string().optional().openapi({description:"HTML form template to be used for WS-Federation."}),addons:o.z.record(o.z.any()).default({}).optional().openapi({description:"Addons enabled for this client and their associated configurations."}),token_endpoint_auth_method:o.z.enum(["none","client_secret_post","client_secret_basic"]).default("client_secret_basic").optional().openapi({description:"Defines the requested authentication method for the token endpoint. Can be none (public client without a client secret), client_secret_post (client uses HTTP POST parameters), or client_secret_basic (client uses HTTP Basic)."}),client_metadata:o.z.record(o.z.string().max(255)).default({}).optional().openapi({description:'Metadata associated with the client, in the form of an object with string values (max 255 chars). Maximum of 10 metadata properties allowed. Field names (max 255 chars) are alphanumeric and may only include the following special characters: :,-+=_*?"/()<>@ [Tab][Space]'}),mobile:o.z.record(o.z.any()).default({}).optional().openapi({description:"Additional configuration for native mobile apps."}),initiate_login_uri:o.z.string().url().optional().openapi({description:"Initiate login uri, must be https"}),native_social_login:o.z.record(o.z.any()).default({}).optional(),refresh_token:o.z.record(o.z.any()).default({}).optional().openapi({description:"Refresh token configuration"}),default_organization:o.z.record(o.z.any()).default({}).optional().openapi({description:"Defines the default Organization ID and flows"}),organization_usage:o.z.enum(["deny","allow","require"]).default("deny").optional().openapi({description:"Defines how to proceed during an authentication transaction with regards an organization. Can be deny (default), allow or require."}),organization_require_behavior:o.z.enum(["no_prompt","pre_login_prompt","post_login_prompt"]).default("no_prompt").optional().openapi({description:"Defines how to proceed during an authentication transaction when client.organization_usage: 'require'. Can be no_prompt (default), pre_login_prompt or post_login_prompt. post_login_prompt requires oidc_conformant: true."}),client_authentication_methods:o.z.record(o.z.any()).default({}).optional().openapi({description:"Defines client authentication methods."}),require_pushed_authorization_requests:o.z.boolean().default(!1).openapi({description:"Makes the use of Pushed Authorization Requests mandatory for this client"}),require_proof_of_possession:o.z.boolean().default(!1).openapi({description:"Makes the use of Proof-of-Possession mandatory for this client"}),signed_request_object:o.z.record(o.z.any()).default({}).optional().openapi({description:"JWT-secured Authorization Requests (JAR) settings."}),compliance_level:o.z.enum(["none","fapi1_adv_pkj_par","fapi1_adv_mtls_par","fapi2_sp_pkj_mtls","fapi2_sp_mtls_mtls"]).optional().openapi({description:"Defines the compliance level for this client, which may restrict it's capabilities"}),par_request_expiry:o.z.number().optional().openapi({description:"Specifies how long, in seconds, a Pushed Authorization Request URI remains valid"}),token_quota:o.z.record(o.z.any()).default({}).optional()}),sr=o.z.object({created_at:o.z.string(),updated_at:o.z.string(),...Ts.shape}),Ps=o.z.object({client_id:o.z.string().min(1).openapi({description:"ID of the client."}),audience:o.z.string().min(1).openapi({description:"The audience (API identifier) of this client grant."}),scope:o.z.array(o.z.string()).optional().openapi({description:"Scopes allowed for this client grant."}),organization_usage:o.z.enum(["deny","allow","require"]).optional().openapi({description:"Defines whether organizations can be used with client credentials exchanges for this grant."}),allow_any_organization:o.z.boolean().optional().openapi({description:"If enabled, any organization can be used with this grant. If disabled (default), the grant must be explicitly assigned to the desired organizations."}),is_system:o.z.boolean().optional().openapi({description:"If enabled, this grant is a special grant created by Auth0. It cannot be modified or deleted directly."}),subject_type:o.z.enum(["client","user"]).optional().openapi({description:"The type of application access the client grant allows. Use of this field is subject to the applicable Free Trial terms in Okta's Master Subscription Agreement."}),authorization_details_types:o.z.array(o.z.string()).optional().openapi({description:"Types of authorization_details allowed for this client grant. Use of this field is subject to the applicable Free Trial terms in Okta's Master Subscription Agreement."})}),ar=o.z.object({id:o.z.string().openapi({description:"ID of the client grant."}),...Ps.shape,created_at:o.z.string().optional(),updated_at:o.z.string().optional()}),jw=o.z.array(ar),wi=o.z.object({x:o.z.number(),y:o.z.number()});var mu=(t=>(t.RICH_TEXT="RICH_TEXT",t.NEXT_BUTTON="NEXT_BUTTON",t.BACK_BUTTON="BACK_BUTTON",t.SUBMIT_BUTTON="SUBMIT_BUTTON",t.DIVIDER="DIVIDER",t.TEXT="TEXT",t.EMAIL="EMAIL",t.PASSWORD="PASSWORD",t.NUMBER="NUMBER",t.PHONE="PHONE",t.DATE="DATE",t.CHECKBOX="CHECKBOX",t.RADIO="RADIO",t.SELECT="SELECT",t.HIDDEN="HIDDEN",t.LEGAL="LEGAL",t))(mu||{}),_u=(t=>(t.BLOCK="BLOCK",t.FIELD="FIELD",t))(_u||{});const Ta=o.z.object({id:o.z.string(),category:o.z.nativeEnum(_u),type:o.z.nativeEnum(mu)}),y0=Ta.extend({category:o.z.literal("BLOCK"),type:o.z.literal("RICH_TEXT"),config:o.z.object({content:o.z.string()}).passthrough()}),w0=Ta.extend({category:o.z.literal("BLOCK"),type:o.z.union([o.z.literal("NEXT_BUTTON"),o.z.literal("BACK_BUTTON"),o.z.literal("SUBMIT_BUTTON")]),config:o.z.object({text:o.z.string()}).passthrough()}),v0=Ta.extend({category:o.z.literal("FIELD"),type:o.z.literal("LEGAL"),required:o.z.boolean().optional(),sensitive:o.z.boolean().optional(),config:o.z.object({text:o.z.string()}).passthrough()}),b0=Ta.extend({category:o.z.literal("FIELD"),type:o.z.union([o.z.literal("TEXT"),o.z.literal("EMAIL"),o.z.literal("PASSWORD"),o.z.literal("NUMBER"),o.z.literal("PHONE"),o.z.literal("DATE"),o.z.literal("CHECKBOX"),o.z.literal("RADIO"),o.z.literal("SELECT"),o.z.literal("HIDDEN")]),required:o.z.boolean().optional(),sensitive:o.z.boolean().optional(),config:o.z.object({label:o.z.string().optional(),placeholder:o.z.string().optional()}).passthrough()}),$0=o.z.object({id:o.z.string(),category:o.z.string(),type:o.z.string()}).passthrough(),k0=o.z.union([y0,w0,v0,b0,$0]);var x0=(t=>(t.STEP="STEP",t.FLOW="FLOW",t.CONDITION="CONDITION",t.ACTION="ACTION",t))(x0||{});const S0=o.z.object({id:o.z.string(),type:o.z.literal("STEP"),coordinates:wi,alias:o.z.string().optional(),config:o.z.object({components:o.z.array(k0),next_node:o.z.string()}).passthrough()}),z0=o.z.object({id:o.z.string(),type:o.z.literal("FLOW"),coordinates:wi,alias:o.z.string().optional(),config:o.z.object({flow_id:o.z.string(),next_node:o.z.string()})}),A0=o.z.object({id:o.z.string(),type:o.z.string(),coordinates:wi}).passthrough(),E0=o.z.union([S0,z0,A0]),C0=o.z.object({next_node:o.z.string(),coordinates:wi}).passthrough(),N0=o.z.object({resume_flow:o.z.boolean().optional(),coordinates:wi}).passthrough(),I0=o.z.object({id:o.z.string(),name:o.z.string(),languages:o.z.object({primary:o.z.string()}).passthrough(),nodes:o.z.array(E0),start:C0,ending:N0,created_at:o.z.string(),updated_at:o.z.string(),links:o.z.object({sdkSrc:o.z.string().optional(),sdk_src:o.z.string().optional()}).passthrough()}).passthrough(),Ow=I0.omit({id:!0,created_at:!0,updated_at:!0});var Nt=(t=>(t.TOKEN="token",t.TOKEN_ID_TOKEN="token id_token",t.CODE="code",t))(Nt||{}),Wt=(t=>(t.QUERY="query",t.FRAGMENT="fragment",t.FORM_POST="form_post",t.WEB_MESSAGE="web_message",t.SAML_POST="saml_post",t))(Wt||{}),Pa=(t=>(t.S256="S256",t.Plain="plain",t))(Pa||{});const ro=o.z.object({client_id:o.z.string(),act_as:o.z.string().optional(),response_type:o.z.nativeEnum(Nt).optional(),response_mode:o.z.nativeEnum(Wt).optional(),redirect_uri:o.z.string().optional(),audience:o.z.string().optional(),organization:o.z.string().optional(),state:o.z.string().optional(),nonce:o.z.string().optional(),scope:o.z.string().optional(),prompt:o.z.string().optional(),code_challenge_method:o.z.nativeEnum(Pa).optional(),code_challenge:o.z.string().optional(),username:o.z.string().optional(),ui_locales:o.z.string().optional(),vendor_id:o.z.string().optional()}),kl=o.z.object({colors:o.z.object({primary:o.z.string(),page_background:o.z.object({type:o.z.string().optional(),start:o.z.string().optional(),end:o.z.string().optional(),angle_deg:o.z.number().optional()}).optional()}).optional(),logo_url:o.z.string().optional(),favicon_url:o.z.string().optional(),powered_by_logo_url:o.z.string().optional(),font:o.z.object({url:o.z.string()}).optional()}),Wr=o.z.object({kid:o.z.string().optional(),team_id:o.z.string().optional(),realms:o.z.string().optional(),authentication_method:o.z.string().optional(),client_id:o.z.string().optional(),client_secret:o.z.string().optional(),app_secret:o.z.string().optional(),scope:o.z.string().optional(),authorization_endpoint:o.z.string().optional(),token_endpoint:o.z.string().optional(),userinfo_endpoint:o.z.string().optional(),jwks_uri:o.z.string().optional(),discovery_url:o.z.string().optional(),issuer:o.z.string().optional(),provider:o.z.string().optional(),from:o.z.string().optional(),twilio_sid:o.z.string().optional(),twilio_token:o.z.string().optional()}),Rs=o.z.object({id:o.z.string().optional(),name:o.z.string(),strategy:o.z.string(),options:Wr.default({}),enabled_clients:o.z.array(o.z.string()).default([]).optional(),response_type:o.z.custom().optional(),response_mode:o.z.custom().optional()}),Kt=o.z.object({id:o.z.string(),created_at:o.z.string().transform(t=>t===null?"":t),updated_at:o.z.string().transform(t=>t===null?"":t)}).extend(Rs.shape),Ki=o.z.object({id:o.z.string().optional(),audience:o.z.string(),friendly_name:o.z.string(),picture_url:o.z.string().optional(),support_email:o.z.string().optional(),support_url:o.z.string().optional(),sender_email:o.z.string().email(),sender_name:o.z.string(),session_lifetime:o.z.number().optional(),idle_session_lifetime:o.z.number().optional(),ephemeral_session_lifetime:o.z.number().optional(),idle_ephemeral_session_lifetime:o.z.number().optional(),session_cookie:o.z.object({mode:o.z.enum(["persistent","non-persistent"]).optional()}).optional(),allowed_logout_urls:o.z.array(o.z.string()).optional(),default_redirection_uri:o.z.string().optional(),enabled_locales:o.z.array(o.z.string()).optional(),default_directory:o.z.string().optional(),error_page:o.z.object({html:o.z.string().optional(),show_log_link:o.z.boolean().optional(),url:o.z.string().optional()}).optional(),flags:o.z.object({allow_changing_enable_sso:o.z.boolean().optional(),allow_legacy_delegation_grant_types:o.z.boolean().optional(),allow_legacy_ro_grant_types:o.z.boolean().optional(),allow_legacy_tokeninfo_endpoint:o.z.boolean().optional(),change_pwd_flow_v1:o.z.boolean().optional(),custom_domains_provisioning:o.z.boolean().optional(),dashboard_insights_view:o.z.boolean().optional(),dashboard_log_streams_next:o.z.boolean().optional(),disable_clickjack_protection_headers:o.z.boolean().optional(),disable_fields_map_fix:o.z.boolean().optional(),disable_impersonation:o.z.boolean().optional(),disable_management_api_sms_obfuscation:o.z.boolean().optional(),enable_adfs_waad_email_verification:o.z.boolean().optional(),enable_apis_section:o.z.boolean().optional(),enable_client_connections:o.z.boolean().optional(),enable_custom_domain_in_emails:o.z.boolean().optional(),enable_dynamic_client_registration:o.z.boolean().optional(),enable_idtoken_api2:o.z.boolean().optional(),enable_legacy_logs_search_v2:o.z.boolean().optional(),enable_legacy_profile:o.z.boolean().optional(),enable_pipeline2:o.z.boolean().optional(),enable_public_signup_user_exists_error:o.z.boolean().optional(),enable_sso:o.z.boolean().optional(),enforce_client_authentication_on_passwordless_start:o.z.boolean().optional(),genai_trial:o.z.boolean().optional(),improved_signup_bot_detection_in_classic:o.z.boolean().optional(),mfa_show_factor_list_on_enrollment:o.z.boolean().optional(),no_disclose_enterprise_connections:o.z.boolean().optional(),remove_alg_from_jwks:o.z.boolean().optional(),revoke_refresh_token_grant:o.z.boolean().optional(),trust_azure_adfs_email_verified_connection_property:o.z.boolean().optional(),use_scope_descriptions_for_consent:o.z.boolean().optional()}).optional(),sandbox_version:o.z.string().optional(),legacy_sandbox_version:o.z.string().optional(),sandbox_versions_available:o.z.array(o.z.string()).optional(),change_password:o.z.object({enabled:o.z.boolean().optional(),html:o.z.string().optional()}).optional(),guardian_mfa_page:o.z.object({enabled:o.z.boolean().optional(),html:o.z.string().optional()}).optional(),device_flow:o.z.object({charset:o.z.enum(["base20","digits"]).optional(),mask:o.z.string().max(20).optional()}).optional(),default_token_quota:o.z.object({clients:o.z.object({client_credentials:o.z.record(o.z.any()).optional()}).optional(),organizations:o.z.object({client_credentials:o.z.record(o.z.any()).optional()}).optional()}).optional(),default_audience:o.z.string().optional(),default_organization:o.z.string().optional(),sessions:o.z.object({oidc_logout_prompt_enabled:o.z.boolean().optional()}).optional(),oidc_logout:o.z.object({rp_logout_end_session_endpoint_discovery:o.z.boolean().optional()}).optional(),allow_organization_name_in_authentication_api:o.z.boolean().optional(),customize_mfa_in_postlogin_action:o.z.boolean().optional(),acr_values_supported:o.z.array(o.z.string()).optional(),mtls:o.z.object({enable_endpoint_aliases:o.z.boolean().optional()}).optional(),pushed_authorization_requests_supported:o.z.boolean().optional(),authorization_response_iss_parameter_supported:o.z.boolean().optional()}),Un=o.z.object({created_at:o.z.string().nullable().transform(t=>t??""),updated_at:o.z.string().nullable().transform(t=>t??""),...Ki.shape,id:o.z.string()});o.z.object({...sr.shape,tenant:Un,connections:o.z.array(Kt)});const j0=o.z.enum(["password_reset","email_verification","otp","authorization_code","oauth2_state","ticket"]),O0=o.z.object({code_id:o.z.string().openapi({description:"The code that will be used in for instance an email verification flow"}),login_id:o.z.string().openapi({description:"The id of the login session that the code is connected to"}),connection_id:o.z.string().optional().openapi({description:"The connection that the code is connected to"}),code_type:j0,code_verifier:o.z.string().optional().openapi({description:"The code verifier used in PKCE in outbound flows"}),code_challenge:o.z.string().optional().openapi({description:"The code challenge used in PKCE in outbound flows"}),code_challenge_method:o.z.enum(["plain","S256"]).optional().openapi({description:"The code challenge method used in PKCE in outbound flows"}),redirect_uri:o.z.string().optional().openapi({description:"The redirect URI associated with the code"}),nonce:o.z.string().optional().openapi({description:"The nonce value used for security in OIDC flows"}),state:o.z.string().optional().openapi({description:"The state parameter used for CSRF protection in OAuth flows"}),expires_at:o.z.string(),used_at:o.z.string().optional(),user_id:o.z.string().optional()}),Tw=o.z.object({...O0.shape,created_at:o.z.string()}),yu=o.z.object({domain:o.z.string(),custom_domain_id:o.z.string().optional(),type:o.z.enum(["auth0_managed_certs","self_managed_certs"]),verification_method:o.z.enum(["txt"]).optional(),tls_policy:o.z.enum(["recommended"]).optional(),custom_client_ip_header:o.z.enum(["true-client-ip","cf-connecting-ip","x-forwarded-for","x-azure-clientip","null"]).optional(),domain_metadata:o.z.record(o.z.string().max(255)).optional()}),T0=o.z.object({name:o.z.literal("txt"),record:o.z.string(),domain:o.z.string()}),Ln=o.z.object({...yu.shape,custom_domain_id:o.z.string(),primary:o.z.boolean(),status:o.z.enum(["disabled","pending","pending_verification","ready"]),origin_domain_name:o.z.string().optional(),verification:o.z.object({methods:o.z.array(T0)}).optional(),tls_policy:o.z.string().optional()}),Pw=Ln.extend({tenant_id:o.z.string()}),Rw=o.z.object({id:o.z.string(),type:o.z.literal("submit"),label:o.z.string(),className:o.z.string().optional(),disabled:o.z.boolean().optional().default(!1),order:o.z.number().optional(),visible:o.z.boolean().optional().default(!0),customizations:o.z.record(o.z.string(),o.z.any()).optional()}),P0=o.z.discriminatedUnion("type",[o.z.object({id:o.z.string(),type:o.z.literal("RICH_TEXT"),config:o.z.object({content:o.z.string()}),order:o.z.number().optional(),visible:o.z.boolean().optional().default(!0)}),o.z.object({id:o.z.string(),type:o.z.literal("LEGAL"),config:o.z.object({text:o.z.string(),html:o.z.boolean().optional()}),required:o.z.boolean().optional(),order:o.z.number().optional(),visible:o.z.boolean().optional().default(!0)}),o.z.object({id:o.z.string(),type:o.z.literal("TEXT"),config:o.z.object({placeholder:o.z.string().optional(),multiline:o.z.boolean().optional()}),required:o.z.boolean().optional(),sensitive:o.z.boolean().optional(),order:o.z.number().optional(),visible:o.z.boolean().optional().default(!0)}),o.z.object({id:o.z.string(),type:o.z.literal("NEXT_BUTTON"),config:o.z.object({text:o.z.string().optional()}),order:o.z.number().optional(),visible:o.z.boolean().optional().default(!0)})]),Bs=o.z.object({name:o.z.string().openapi({description:"The name of the form"}),messages:o.z.object({errors:o.z.record(o.z.string(),o.z.any()).optional(),custom:o.z.record(o.z.string(),o.z.any()).optional()}).optional(),languages:o.z.object({primary:o.z.string().optional(),default:o.z.string().optional()}).optional(),translations:o.z.record(o.z.string(),o.z.any()).optional(),nodes:o.z.array(o.z.discriminatedUnion("type",[o.z.object({id:o.z.string(),type:o.z.literal("FLOW"),coordinates:o.z.object({x:o.z.number(),y:o.z.number()}),alias:o.z.string().min(1).max(150).optional(),config:o.z.object({flow_id:o.z.string().max(30),next_node:o.z.string()})}),o.z.object({id:o.z.string(),type:o.z.literal("ROUTER"),coordinates:o.z.object({x:o.z.number(),y:o.z.number()}),alias:o.z.string().min(1).max(150),config:o.z.object({rules:o.z.array(o.z.object({id:o.z.string(),alias:o.z.string().min(1).max(150).optional(),condition:o.z.any(),next_node:o.z.string()})),fallback:o.z.array(o.z.string())})}),o.z.object({id:o.z.string(),type:o.z.literal("STEP"),coordinates:o.z.object({x:o.z.number(),y:o.z.number()}),alias:o.z.string().min(1).max(150).optional(),config:o.z.object({components:o.z.array(P0),next_node:o.z.string()})})])).optional(),start:o.z.object({hidden_fields:o.z.array(o.z.object({key:o.z.string(),value:o.z.string()})).optional(),next_node:o.z.string().optional(),coordinates:o.z.object({x:o.z.number(),y:o.z.number()}).optional()}).optional(),ending:o.z.object({redirection:o.z.object({delay:o.z.number().optional(),target:o.z.string().optional()}).optional(),after_submit:o.z.object({flow_id:o.z.string().optional()}).optional(),coordinates:o.z.object({x:o.z.number(),y:o.z.number()}).optional(),resume_flow:o.z.boolean().optional()}).optional(),style:o.z.object({css:o.z.string().optional()}).optional()}).openapi({description:"Schema for flow-based forms (matches new JSON structure)"}),Vr=o.z.object({...yi.shape,...Bs.shape,id:o.z.string()}),R0=o.z.enum(["pre-user-signup","post-user-registration","post-user-login"]),B0=o.z.enum(["pre-user-signup","post-user-registration","post-user-login"]),Ra={enabled:o.z.boolean().default(!1),synchronous:o.z.boolean().default(!1),priority:o.z.number().optional(),hook_id:o.z.string().optional()},Bw=o.z.object({...Ra,trigger_id:R0,url:o.z.string()}),Lw=o.z.object({...Ra,trigger_id:B0,form_id:o.z.string()}),ds=o.z.union([Bw,Lw]),Uw=o.z.object({...Ra,trigger_id:R0,...yi.shape,hook_id:o.z.string(),url:o.z.string()}),Dw=o.z.object({...Ra,trigger_id:B0,...yi.shape,hook_id:o.z.string(),form_id:o.z.string()}),Kr=o.z.union([Uw,Dw]),L0=o.z.object({name:o.z.string().optional()}),U0=o.z.object({email:o.z.string().optional()}),wu=o.z.object({organization_id:o.z.string().max(50),inviter:L0,invitee:U0,invitation_url:o.z.string().url(),client_id:o.z.string(),connection_id:o.z.string().optional(),app_metadata:o.z.record(o.z.any()).default({}).optional(),user_metadata:o.z.record(o.z.any()).default({}).optional(),ttl_sec:o.z.number().int().max(2592e3).default(604800).optional(),roles:o.z.array(o.z.string()).default([]).optional(),send_invitation_email:o.z.boolean().default(!0).optional()}),Gi=o.z.object({id:o.z.string(),organization_id:o.z.string().max(50),created_at:o.z.string().datetime(),expires_at:o.z.string().datetime(),ticket_id:o.z.string().optional()}).extend(wu.shape),vu=o.z.object({alg:o.z.enum(["RS256","RS384","RS512","ES256","ES384","ES512","HS256","HS384","HS512"]),e:o.z.string(),kid:o.z.string(),kty:o.z.enum(["RSA","EC","oct"]),n:o.z.string(),x5t:o.z.string().optional(),x5c:o.z.array(o.z.string()).optional(),use:o.z.enum(["sig","enc"]).optional()}),D0=o.z.object({keys:o.z.array(vu)}),xl=o.z.object({issuer:o.z.string(),authorization_endpoint:o.z.string(),token_endpoint:o.z.string(),device_authorization_endpoint:o.z.string(),userinfo_endpoint:o.z.string(),mfa_challenge_endpoint:o.z.string(),jwks_uri:o.z.string(),registration_endpoint:o.z.string(),revocation_endpoint:o.z.string(),scopes_supported:o.z.array(o.z.string()),response_types_supported:o.z.array(o.z.string()),code_challenge_methods_supported:o.z.array(o.z.string()),response_modes_supported:o.z.array(o.z.string()),subject_types_supported:o.z.array(o.z.string()),id_token_signing_alg_values_supported:o.z.array(o.z.string()),token_endpoint_auth_methods_supported:o.z.array(o.z.string()),claims_supported:o.z.array(o.z.string()),request_uri_parameter_supported:o.z.boolean(),request_parameter_supported:o.z.boolean(),token_endpoint_auth_signing_alg_values_supported:o.z.array(o.z.string())}),M0=o.z.object({csrf_token:o.z.string(),auth0Client:o.z.string().optional(),authParams:ro,expires_at:o.z.string(),deleted_at:o.z.string().optional(),ip:o.z.string().optional(),useragent:o.z.string().optional(),session_id:o.z.string().optional(),authorization_url:o.z.string().optional(),login_completed:o.z.boolean().optional().default(!1)}).openapi({description:"This represents a login sesion"}),Mw=o.z.object({...M0.shape,id:o.z.string().openapi({description:"This is is used as the state in the universal login"}),created_at:o.z.string(),updated_at:o.z.string()}),_e={ACLS_SUMMARY:"acls_summary",ACTIONS_EXECUTION_FAILED:"actions_execution_failed",API_LIMIT:"api_limit",API_LIMIT_WARNING:"api_limit_warning",APPI:"appi",CIBA_EXCHANGE_FAILED:"ciba_exchange_failed",CIBA_EXCHANGE_SUCCEEDED:"ciba_exchange_succeeded",CIBA_START_FAILED:"ciba_start_failed",CIBA_START_SUCCEEDED:"ciba_start_succeeded",CODE_LINK_SENT:"cls",CODE_SENT:"cs",DEPRECATION_NOTICE:"depnote",FAILED_LOGIN:"f",FAILED_BY_CONNECTOR:"fc",FAILED_CHANGE_EMAIL:"fce",FAILED_BY_CORS:"fco",FAILED_CROSS_ORIGIN_AUTHENTICATION:"fcoa",FAILED_CHANGE_PASSWORD:"fcp",FAILED_POST_CHANGE_PASSWORD_HOOK:"fcph",FAILED_CHANGE_PHONE_NUMBER:"fcpn",FAILED_CHANGE_PASSWORD_REQUEST:"fcpr",FAILED_CONNECTOR_PROVISIONING:"fcpro",FAILED_CHANGE_USERNAME:"fcu",FAILED_DELEGATION:"fd",FAILED_DEVICE_ACTIVATION:"fdeac",FAILED_DEVICE_AUTHORIZATION_REQUEST:"fdeaz",USER_CANCELED_DEVICE_CONFIRMATION:"fdecc",FAILED_USER_DELETION:"fdu",FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN:"feacft",FAILED_EXCHANGE_ACCESS_TOKEN_FOR_CLIENT_CREDENTIALS:"feccft",FAILED_EXCHANGE_CUSTOM_TOKEN:"fecte",FAILED_EXCHANGE_DEVICE_CODE_FOR_ACCESS_TOKEN:"fede",FAILED_FEDERATED_LOGOUT:"federated_logout_failed",FAILED_EXCHANGE_NATIVE_SOCIAL_LOGIN:"fens",FAILED_EXCHANGE_PASSWORD_OOB_FOR_ACCESS_TOKEN:"feoobft",FAILED_EXCHANGE_PASSWORD_OTP_FOR_ACCESS_TOKEN:"feotpft",FAILED_EXCHANGE_PASSWORD_FOR_ACCESS_TOKEN:"fepft",FAILED_EXCHANGE_PASSWORDLESS_OTP_FOR_ACCESS_TOKEN:"fepotpft",FAILED_EXCHANGE_PASSWORD_MFA_RECOVERY_FOR_ACCESS_TOKEN:"fercft",FAILED_EXCHANGE_ROTATING_REFRESH_TOKEN:"ferrt",FAILED_EXCHANGE_REFRESH_TOKEN_FOR_ACCESS_TOKEN:"fertft",FAILED_HOOK:"fh",FAILED_INVITE_ACCEPT:"fi",FAILED_LOGOUT:"flo",FLOWS_EXECUTION_COMPLETED:"flows_execution_completed",FLOWS_EXECUTION_FAILED:"flows_execution_failed",FAILED_SENDING_NOTIFICATION:"fn",FORMS_SUBMISSION_FAILED:"forms_submission_failed",FORMS_SUBMISSION_SUCCEEDED:"forms_submission_succeeded",FAILED_LOGIN_INCORRECT_PASSWORD:"fp",FAILED_PUSHED_AUTHORIZATION_REQUEST:"fpar",FAILED_POST_USER_REGISTRATION_HOOK:"fpurh",FAILED_SIGNUP:"fs",FAILED_SILENT_AUTH:"fsa",FAILED_LOGIN_INVALID_EMAIL_USERNAME:"fu",FAILED_USERS_IMPORT:"fui",FAILED_VERIFICATION_EMAIL:"fv",FAILED_VERIFICATION_EMAIL_REQUEST:"fvr",EMAIL_VERIFICATION_CONFIRMED:"gd_auth_email_verification",EMAIL_VERIFICATION_FAILED:"gd_auth_fail_email_verification",MFA_AUTH_FAILED:"gd_auth_failed",MFA_AUTH_REJECTED:"gd_auth_rejected",MFA_AUTH_SUCCESS:"gd_auth_succeed",MFA_ENROLLMENT_COMPLETE:"gd_enrollment_complete",TOO_MANY_MFA_FAILURES:"gd_otp_rate_limit_exceed",MFA_RECOVERY_FAILED:"gd_recovery_failed",MFA_RECOVERY_RATE_LIMIT_EXCEED:"gd_recovery_rate_limit_exceed",MFA_RECOVERY_SUCCESS:"gd_recovery_succeed",MFA_EMAIL_SENT:"gd_send_email",EMAIL_VERIFICATION_SENT:"gd_send_email_verification",EMAIL_VERIFICATION_SEND_FAILURE:"gd_send_email_verification_failure",PUSH_NOTIFICATION_SENT:"gd_send_pn",ERROR_SENDING_MFA_PUSH_NOTIFICATION:"gd_send_pn_failure",MFA_SMS_SENT:"gd_send_sms",ERROR_SENDING_MFA_SMS:"gd_send_sms_failure",MFA_VOICE_CALL_SUCCESS:"gd_send_voice",MFA_VOICE_CALL_FAILED:"gd_send_voice_failure",SECOND_FACTOR_STARTED:"gd_start_auth",MFA_ENROLL_STARTED:"gd_start_enroll",MFA_ENROLLMENT_FAILED:"gd_start_enroll_failed",GUARDIAN_TENANT_UPDATE:"gd_tenant_update",UNENROLL_DEVICE_ACCOUNT:"gd_unenroll",UPDATE_DEVICE_ACCOUNT:"gd_update_device_account",WEBAUTHN_CHALLENGE_FAILED:"gd_webauthn_challenge_failed",WEBAUTHN_ENROLLMENT_FAILED:"gd_webauthn_enrollment_failed",FAILED_KMS_API_OPERATION:"kms_key_management_failure",SUCCESS_KMS_API_OPERATION:"kms_key_management_success",KMS_KEY_STATE_CHANGED:"kms_key_state_changed",TOO_MANY_CALLS_TO_DELEGATION:"limit_delegation",BLOCKED_IP_ADDRESS:"limit_mu",BLOCKED_ACCOUNT_IP:"limit_sul",BLOCKED_ACCOUNT_EMAIL:"limit_wc",MFA_REQUIRED:"mfar",MANAGEMENT_API_READ_OPERATION:"mgmt_api_read",FAILED_AUTHENTICATION_METHOD_OPERATION_MY_ACCOUNT:"my_account_authentication_method_failed",SUCCESSFUL_AUTHENTICATION_METHOD_OPERATION_MY_ACCOUNT:"my_account_authentication_method_succeeded",FAILED_OIDC_BACKCHANNEL_LOGOUT:"oidc_backchannel_logout_failed",SUCCESSFUL_OIDC_BACKCHANNEL_LOGOUT:"oidc_backchannel_logout_succeeded",ORGANIZATION_MEMBER_ADDED:"organization_member_added",PASSKEY_CHALLENGE_FAILED:"passkey_challenge_failed",PASSKEY_CHALLENGE_STARTED:"passkey_challenge_started",PRE_LOGIN_ASSESSMENT:"pla",BREACHED_PASSWORD:"pwd_leak",BREACHED_PASSWORD_ON_RESET:"reset_pwd_leak",SUCCESS_RESOURCE_CLEANUP:"resource_cleanup",RICH_CONSENTS_ACCESS_ERROR:"rich_consents_access_error",SUCCESS_LOGIN:"s",SUCCESS_API_OPERATION:"sapi",SUCCESS_CHANGE_EMAIL:"sce",SUCCESS_CROSS_ORIGIN_AUTHENTICATION:"scoa",SUCCESS_CHANGE_PASSWORD:"scp",SUCCESS_CHANGE_PHONE_NUMBER:"scpn",SUCCESS_CHANGE_PASSWORD_REQUEST:"scpr",SUCCESS_CHANGE_USERNAME:"scu",SUCCESS_CREDENTIAL_VALIDATION:"scv",SUCCESS_DELEGATION:"sd",SUCCESS_USER_DELETION:"sdu",SUCCESS_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN:"seacft",SUCCESS_EXCHANGE_ACCESS_TOKEN_FOR_CLIENT_CREDENTIALS:"seccft",SUCCESS_EXCHANGE_CUSTOM_TOKEN:"secte",SUCCESS_EXCHANGE_DEVICE_CODE_FOR_ACCESS_TOKEN:"sede",SUCCESS_EXCHANGE_NATIVE_SOCIAL_LOGIN:"sens",SUCCESS_EXCHANGE_PASSWORD_OOB_FOR_ACCESS_TOKEN:"seoobft",SUCCESS_EXCHANGE_PASSWORD_OTP_FOR_ACCESS_TOKEN:"seotpft",SUCCESS_EXCHANGE_PASSWORD_FOR_ACCESS_TOKEN:"sepft",SUCCESS_EXCHANGE_PASSKEY_OOB_FOR_ACCESS_TOKEN:"sepkoobft",SUCCESS_EXCHANGE_PASSKEY_OTP_FOR_ACCESS_TOKEN:"sepkotpft",SUCCESS_EXCHANGE_PASSKEY_MFA_RECOVERY_FOR_ACCESS_TOKEN:"sepkrcft",SUCCESS_EXCHANGE_PASSWORD_MFA_RECOVERY_FOR_ACCESS_TOKEN:"sercft",SUCCESS_EXCHANGE_REFRESH_TOKEN_FOR_ACCESS_TOKEN:"sertft",SUCCESSFULLY_ACCEPTED_USER_INVITE:"si",BREACHED_PASSWORD_ON_SIGNUP:"signup_pwd_leak",SUCCESS_LOGOUT:"slo",SUCCESS_REVOCATION:"srrt",SUCCESS_SIGNUP:"ss",FAILED_SS_SSO_OPERATION:"ss_sso_failure",INFORMATION_FROM_SS_SSO_OPERATION:"ss_sso_info",SUCCESS_SS_SSO_OPERATION:"ss_sso_success",SUCCESS_SILENT_AUTH:"ssa",SUCCESSFUL_SCIM_OPERATION:"sscim",SUCCESSFULLY_IMPORTED_USERS:"sui",SUCCESS_VERIFICATION_EMAIL:"sv",SUCCESS_VERIFICATION_EMAIL_REQUEST:"svr",MAX_AMOUNT_OF_AUTHENTICATORS:"too_many_records",USER_LOGIN_BLOCK_RELEASED:"ublkdu",FAILED_UNIVERSAL_LOGOUT:"universal_logout_failed",SUCCESSFUL_UNIVERSAL_LOGOUT:"universal_logout_succeeded",WARNING_DURING_LOGIN:"w",WARNING_SENDING_NOTIFICATION:"wn",WARNING_USER_MANAGEMENT:"wum"},Fw=o.z.string().refine(t=>Object.values(_e).includes(t),{message:"Invalid log type"}),F0=o.z.object({name:o.z.string(),version:o.z.string(),env:o.z.object({node:o.z.string().optional()}).optional()}),Ls=o.z.object({type:Fw,date:o.z.string(),description:o.z.string().optional(),log_id:o.z.string().optional(),_id:o.z.string().optional(),ip:o.z.string(),user_agent:o.z.string(),details:o.z.any().optional(),isMobile:o.z.boolean(),user_id:o.z.string().optional(),user_name:o.z.string().optional(),connection:o.z.string().optional(),connection_id:o.z.string().optional(),client_id:o.z.string().optional(),client_name:o.z.string().optional(),audience:o.z.string().optional(),scope:o.z.array(o.z.string()).optional(),strategy:o.z.string().optional(),strategy_type:o.z.string().optional(),hostname:o.z.string().optional(),auth0_client:F0.optional()}),q0=o.z.object({user_id:o.z.string(),password:o.z.string(),algorithm:o.z.enum(["bcrypt","argon2id"]).default("argon2id")}),qw=o.z.object({...q0.shape,created_at:o.z.string(),updated_at:o.z.string()}),H0=o.z.object({initial_user_agent:o.z.string().describe("First user agent of the device from which this user logged in"),initial_ip:o.z.string().describe("First IP address associated with this session"),initial_asn:o.z.string().describe("First autonomous system number associated with this session"),last_user_agent:o.z.string().describe("Last user agent of the device from which this user logged in"),last_ip:o.z.string().describe("Last IP address from which this user logged in"),last_asn:o.z.string().describe("Last autonomous system number from which this user logged in")}),V0=o.z.object({id:o.z.string(),revoked_at:o.z.string().optional(),used_at:o.z.string().optional(),user_id:o.z.string().describe("The user ID associated with the session"),expires_at:o.z.string().optional(),login_session_id:o.z.string(),idle_expires_at:o.z.string().optional(),device:H0.describe("Metadata related to the device used in the session"),clients:o.z.array(o.z.string()).describe("List of client details for the session")}),Ba=o.z.object({created_at:o.z.string(),updated_at:o.z.string(),authenticated_at:o.z.string(),last_interaction_at:o.z.string(),...V0.shape}),Sl=o.z.object({kid:o.z.string().openapi({description:"The key id of the signing key"}),cert:o.z.string().openapi({description:"The public certificate of the signing key"}),fingerprint:o.z.string().openapi({description:"The cert fingerprint"}),thumbprint:o.z.string().openapi({description:"The cert thumbprint"}),pkcs7:o.z.string().optional().openapi({description:"The private key in pkcs7 format"}),current:o.z.boolean().optional().openapi({description:"True if the key is the current key"}),next:o.z.boolean().optional().openapi({description:"True if the key is the next key"}),previous:o.z.boolean().optional().openapi({description:"True if the key is the previous key"}),current_since:o.z.string().optional().openapi({description:"The date and time when the key became the current key"}),current_until:o.z.string().optional().openapi({description:"The date and time when the current key was rotated"}),revoked:o.z.boolean().optional().openapi({description:"True if the key is revoked"}),revoked_at:o.z.string().optional().openapi({description:"The date and time when the key was revoked"}),connection:o.z.string().optional().openapi({description:"The connection identifier associated with the key"}),type:o.z.enum(["jwt_signing","saml_encryption"]).openapi({description:"The type of the signing key"})});var Vt=(t=>(t.RefreshToken="refresh_token",t.AuthorizationCode="authorization_code",t.ClientCredential="client_credentials",t.Passwordless="passwordless",t.Password="password",t.OTP="http://auth0.com/oauth/grant-type/passwordless/otp",t))(Vt||{});const bu=o.z.object({access_token:o.z.string(),id_token:o.z.string().optional(),scope:o.z.string().optional(),state:o.z.string().optional(),refresh_token:o.z.string().optional(),token_type:o.z.string(),expires_in:o.z.number()});o.z.object({code:o.z.string(),state:o.z.string().optional()});const K0=o.z.object({button_border_radius:o.z.number(),button_border_weight:o.z.number(),buttons_style:o.z.enum(["pill","rounded","sharp"]),input_border_radius:o.z.number(),input_border_weight:o.z.number(),inputs_style:o.z.enum(["pill","rounded","sharp"]),show_widget_shadow:o.z.boolean(),widget_border_weight:o.z.number(),widget_corner_radius:o.z.number()}),G0=o.z.object({base_focus_color:o.z.string(),base_hover_color:o.z.string(),body_text:o.z.string(),captcha_widget_theme:o.z.enum(["auto","dark","light"]),error:o.z.string(),header:o.z.string(),icons:o.z.string(),input_background:o.z.string(),input_border:o.z.string(),input_filled_text:o.z.string(),input_labels_placeholders:o.z.string(),links_focused_components:o.z.string(),primary_button:o.z.string(),primary_button_label:o.z.string(),secondary_button_border:o.z.string(),secondary_button_label:o.z.string(),success:o.z.string(),widget_background:o.z.string(),widget_border:o.z.string()}),rr=o.z.object({bold:o.z.boolean(),size:o.z.number()}),W0=o.z.object({body_text:rr,buttons_text:rr,font_url:o.z.string(),input_labels:rr,links:rr,links_style:o.z.enum(["normal","underlined"]),reference_text_size:o.z.number(),subtitle:rr,title:rr}),J0=o.z.object({background_color:o.z.string(),background_image_url:o.z.string(),page_layout:o.z.enum(["center","left","right"])}),X0=o.z.object({header_text_alignment:o.z.enum(["center","left","right"]),logo_height:o.z.number(),logo_position:o.z.enum(["center","left","none","right"]),logo_url:o.z.string(),social_buttons_layout:o.z.enum(["bottom","top"])}),Z0=o.z.object({borders:K0,colors:G0,displayName:o.z.string(),fonts:W0,page_background:J0,widget:X0}),us=Z0.extend({themeId:o.z.string()}),ps=o.z.object({universal_login_experience:o.z.enum(["new","classic"]).default("new"),identifier_first:o.z.boolean().default(!0),password_first:o.z.boolean().default(!1),webauthn_platform_first_factor:o.z.boolean()}),fs=o.z.object({name:o.z.string(),enabled:o.z.boolean().optional().default(!0),default_from_address:o.z.string().optional(),credentials:o.z.union([o.z.object({accessKeyId:o.z.string(),secretAccessKey:o.z.string(),region:o.z.string()}),o.z.object({smtp_host:o.z.array(o.z.string()),smtp_port:o.z.number(),smtp_user:o.z.string(),smtp_pass:o.z.string()}),o.z.object({api_key:o.z.string(),domain:o.z.string().optional()}),o.z.object({connectionString:o.z.string()}),o.z.object({tenantId:o.z.string(),clientId:o.z.string(),clientSecret:o.z.string()})]),settings:o.z.object({}).optional()}),$u=o.z.object({id:o.z.string(),session_id:o.z.string(),user_id:o.z.string(),client_id:o.z.string(),expires_at:o.z.string().optional(),idle_expires_at:o.z.string().optional(),last_exchanged_at:o.z.string().optional(),device:H0,resource_servers:o.z.array(o.z.object({audience:o.z.string(),scopes:o.z.string()})),rotating:o.z.boolean()}),Hw=o.z.object({created_at:o.z.string(),...$u.shape}),Vw=o.z.object({to:o.z.string(),message:o.z.string()}),Kw=o.z.object({name:o.z.string(),options:o.z.object({})}),Y0=o.z.object({value:o.z.string(),description:o.z.string().optional()}),Q0=o.z.object({token_dialect:o.z.enum(["access_token","access_token_authz"]).optional(),enforce_policies:o.z.boolean().optional(),allow_skipping_userinfo:o.z.boolean().optional(),skip_userinfo:o.z.boolean().optional(),persist_client_authorization:o.z.boolean().optional(),enable_introspection_endpoint:o.z.boolean().optional(),mtls:o.z.object({bound_access_tokens:o.z.boolean().optional()}).optional()}),Us=o.z.object({name:o.z.string(),identifier:o.z.string(),scopes:o.z.array(Y0).optional(),signing_alg:o.z.string().optional(),signing_secret:o.z.string().optional(),token_lifetime:o.z.number().optional(),token_lifetime_for_web:o.z.number().optional(),skip_consent_for_verifiable_first_party_clients:o.z.boolean().optional(),allow_offline_access:o.z.boolean().optional(),verificationKey:o.z.string().optional(),options:Q0.optional()}),cr=o.z.object({id:o.z.string().optional(),...Us.shape,created_at:o.z.string().optional(),updated_at:o.z.string().optional()}),Gw=o.z.array(cr),em=o.z.object({role_id:o.z.string(),resource_server_identifier:o.z.string(),permission_name:o.z.string()}),tm=o.z.object({...em.shape,tenant_id:o.z.string(),created_at:o.z.string().optional()}),Ww=o.z.array(tm),nm=o.z.object({role_id:o.z.string(),resource_server_identifier:o.z.string(),resource_server_name:o.z.string(),permission_name:o.z.string(),description:o.z.string().nullable().optional(),created_at:o.z.string().optional()}),rm=o.z.array(nm),im=o.z.object({user_id:o.z.string(),resource_server_identifier:o.z.string(),permission_name:o.z.string(),organization_id:o.z.string().optional()}),om=o.z.object({...im.shape,tenant_id:o.z.string(),created_at:o.z.string().optional()}),Jw=o.z.array(om),sm=o.z.object({user_id:o.z.string(),resource_server_identifier:o.z.string(),resource_server_name:o.z.string(),permission_name:o.z.string(),description:o.z.string().nullable().optional(),created_at:o.z.string().optional(),organization_id:o.z.string().optional()}),am=o.z.array(sm),cm=o.z.object({user_id:o.z.string(),role_id:o.z.string(),organization_id:o.z.string().optional()}),lm=o.z.object({...cm.shape,tenant_id:o.z.string(),created_at:o.z.string().optional()}),Xw=o.z.array(lm),Ds=o.z.object({name:o.z.string().min(1).max(50).openapi({description:"The name of the role. Cannot include '<' or '>'"}),description:o.z.string().max(255).optional().openapi({description:"The description of the role"})}),lr=o.z.object({id:o.z.string().openapi({description:"The unique identifier of the role"}),...Ds.shape,created_at:o.z.string().optional(),updated_at:o.z.string().optional()}),Ms=o.z.array(lr),dm=o.z.object({logo_url:o.z.string().optional().openapi({description:"URL of the organization's logo"}),colors:o.z.object({primary:o.z.string().optional().openapi({description:"Primary color in hex format (e.g., #FF0000)"}),page_background:o.z.string().optional().openapi({description:"Page background color in hex format (e.g., #FFFFFF)"})}).optional()}).optional(),um=o.z.object({connection_id:o.z.string().openapi({description:"ID of the connection"}),assign_membership_on_login:o.z.boolean().default(!1).openapi({description:"Whether to assign membership to the organization on login"}),show_as_button:o.z.boolean().default(!0).openapi({description:"Whether to show this connection as a button in the login screen"}),is_signup_enabled:o.z.boolean().default(!0).openapi({description:"Whether signup is enabled for this connection"})}),pm=o.z.object({client_credentials:o.z.object({enforce:o.z.boolean().default(!1).openapi({description:"Whether to enforce token quota limits"}),per_day:o.z.number().min(0).default(0).openapi({description:"Maximum tokens per day (0 = unlimited)"}),per_hour:o.z.number().min(0).default(0).openapi({description:"Maximum tokens per hour (0 = unlimited)"})}).optional()}).optional(),Fs=o.z.object({id:o.z.string().optional(),name:o.z.string().min(1).openapi({description:"The name of the organization"}),display_name:o.z.string().optional().openapi({description:"The display name of the organization"}),branding:dm,metadata:o.z.record(o.z.any()).default({}).optional().openapi({description:"Custom metadata for the organization"}),enabled_connections:o.z.array(um).default([]).optional().openapi({description:"List of enabled connections for the organization"}),token_quota:pm}),Dn=o.z.object({...Fs.shape,...yi.shape,id:o.z.string()}),fm=o.z.object({user_id:o.z.string().openapi({description:"ID of the user"}),organization_id:o.z.string().openapi({description:"ID of the organization"})}),Zw=o.z.object({...fm.shape,...yi.shape,id:o.z.string()}),Yw=o.z.object({idle_session_lifetime:o.z.number().optional(),session_lifetime:o.z.number().optional(),session_cookie:o.z.object({mode:o.z.enum(["persistent","non-persistent"]).optional()}).optional(),enable_client_connections:o.z.boolean().optional(),default_redirection_uri:o.z.string().optional(),enabled_locales:o.z.array(o.z.string()).optional(),default_directory:o.z.string().optional(),error_page:o.z.object({html:o.z.string().optional(),show_log_link:o.z.boolean().optional(),url:o.z.string().optional()}).optional(),flags:o.z.object({allow_legacy_delegation_grant_types:o.z.boolean().optional(),allow_legacy_ro_grant_types:o.z.boolean().optional(),allow_legacy_tokeninfo_endpoint:o.z.boolean().optional(),disable_clickjack_protection_headers:o.z.boolean().optional(),enable_apis_section:o.z.boolean().optional(),enable_client_connections:o.z.boolean().optional(),enable_custom_domain_in_emails:o.z.boolean().optional(),enable_dynamic_client_registration:o.z.boolean().optional(),enable_idtoken_api2:o.z.boolean().optional(),enable_legacy_logs_search_v2:o.z.boolean().optional(),enable_legacy_profile:o.z.boolean().optional(),enable_pipeline2:o.z.boolean().optional(),enable_public_signup_user_exists_error:o.z.boolean().optional(),use_scope_descriptions_for_consent:o.z.boolean().optional(),disable_management_api_sms_obfuscation:o.z.boolean().optional(),enable_adfs_waad_email_verification:o.z.boolean().optional(),revoke_refresh_token_grant:o.z.boolean().optional(),dashboard_log_streams_next:o.z.boolean().optional(),dashboard_insights_view:o.z.boolean().optional(),disable_fields_map_fix:o.z.boolean().optional(),mfa_show_factor_list_on_enrollment:o.z.boolean().optional()}).optional(),friendly_name:o.z.string().optional(),picture_url:o.z.string().optional(),support_email:o.z.string().optional(),support_url:o.z.string().optional(),sandbox_version:o.z.string().optional(),sandbox_versions_available:o.z.array(o.z.string()).optional(),change_password:o.z.object({enabled:o.z.boolean(),html:o.z.string()}).optional(),guardian_mfa_page:o.z.object({enabled:o.z.boolean(),html:o.z.string()}).optional(),default_audience:o.z.string().optional(),default_organization:o.z.string().optional(),sessions:o.z.object({oidc_logout_prompt_enabled:o.z.boolean().optional()}).optional()});function Qw(t){const[e,n]=t.split("|");if(!e||!n)throw new Error(`Invalid user_id: ${t}`);return{connection:e,id:n}}const sf={themeId:"default",borders:{button_border_radius:8,button_border_weight:1,buttons_style:"pill",input_border_radius:8,input_border_weight:1,inputs_style:"pill",show_widget_shadow:!0,widget_border_weight:1,widget_corner_radius:16},colors:{base_focus_color:"#7D68F4",base_hover_color:"#A091F2",body_text:"#000000",captcha_widget_theme:"auto",error:"#FC5A5A",header:"#000000",icons:"#666666",input_background:"#FFFFFF",input_border:"#BFBCD7",input_filled_text:"#000000",input_labels_placeholders:"#88869F",links_focused_components:"#7D68F4",primary_button:"#7D68F4",primary_button_label:"#FFFFFF",secondary_button_border:"#BFBCD7",secondary_button_label:"#000000",success:"#36BF76",widget_background:"#FFFFFF",widget_border:"#BFBCD7"},displayName:"Default Theme",fonts:{body_text:{bold:!1,size:16},buttons_text:{bold:!1,size:16},font_url:"https://assets.sesamy.com/fonts/khteka/WOFF2/KHTeka-Regular.woff2",input_labels:{bold:!1,size:14},links:{bold:!1,size:16},links_style:"normal",reference_text_size:16,subtitle:{bold:!1,size:18},title:{bold:!0,size:24}},page_background:{background_color:"#F8F9FB",background_image_url:"https://assets.sesamy.com/images/login-bg.jpg",page_layout:"center"},widget:{header_text_alignment:"center",logo_height:36,logo_position:"center",logo_url:"https://assets.sesamy.com/static/images/sesamy/logos/sesamy_logo_black.svg",social_buttons_layout:"bottom"}};function zl(t,e){const n=structuredClone(t);function r(i,s){for(const a in s)s[a]!==void 0&&typeof s[a]=="object"&&!Array.isArray(s[a])&&typeof i[a]=="object"&&i[a]!==null?r(i[a],s[a]):i[a]=s[a];return i}return r(n,e)}const ev=new o.OpenAPIHono().openapi(o.createRoute({tags:["branding"],method:"get",path:"/default",request:{headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:us}},description:"Default theme settings"}}}),async t=>{const e=await t.env.data.themes.get(t.var.tenant_id,"default");return e?t.json(e):t.json(sf)}).openapi(o.createRoute({tags:["branding"],method:"patch",path:"/default",request:{body:{content:{"application/json":{schema:us.deepPartial()}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:us}},description:"Updated theme settings"}}}),async t=>{const e=t.req.valid("json"),n=await t.env.data.themes.get(t.var.tenant_id,"default");if(n){const r=zl(n,e);await t.env.data.themes.update(t.var.tenant_id,"default",r);const i=await t.env.data.themes.get(t.var.tenant_id,"default");return t.json(i)}else{const r=zl(sf,e),i=await t.env.data.themes.create(t.var.tenant_id,r);return t.json(i)}}),tv={colors:{primary:"#7D68F4",page_background:{type:"solid",start:"#F8F9FB",end:"#F8F9FB",angle_deg:0}},logo_url:"https://assets.sesamy.com/static/images/sesamy/logos/sesamy_logo_black.svg",favicon_url:"https://assets.sesamy.com/images/favicon.ico",font:{url:"https://assets.sesamy.com/fonts/khteka/WOFF2/KHTeka-Regular.woff2"}},nv=new o.OpenAPIHono().openapi(o.createRoute({tags:["branding"],method:"get",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:kl}},description:"Branding settings"}}}),async t=>{const e=await t.env.data.branding.get(t.var.tenant_id);return e?t.json(e):t.json(tv)}).openapi(o.createRoute({tags:["branding"],method:"patch",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object(kl.shape).partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Branding settings"}}}),async t=>{const e=t.req.valid("json");return await t.env.data.branding.set(t.var.tenant_id,e),t.text("OK")}).route("/themes",ev);var S=class extends Error{constructor(e=500,n){super(n==null?void 0:n.message,{cause:n==null?void 0:n.cause});ae(this,"res");ae(this,"status");this.res=n==null?void 0:n.res,this.status=e}getResponse(){return this.res?new Response(this.res.body,{status:this.status,headers:this.res.headers}):new Response(this.message,{status:this.status})}},Al=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function hm(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function rv(t){if(t.__esModule)return t;var e=t.default;if(typeof e=="function"){var n=function r(){return this instanceof r?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};n.prototype=e.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(t).forEach(function(r){var i=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(n,r,i.get?i:{enumerable:!0,get:function(){return t[r]}})}),n}function iv(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var gm={exports:{}};const ov={},sv=Object.freeze(Object.defineProperty({__proto__:null,default:ov},Symbol.toStringTag,{value:"Module"})),av=rv(sv);(function(t){/**
1
+ "use strict";var lw=Object.defineProperty;var dw=(t,e,n)=>e in t?lw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var ae=(t,e,n)=>dw(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@hono/zod-openapi"),he=t=>typeof t=="string",Pi=()=>{let t,e;const n=new Promise((r,i)=>{t=r,e=i});return n.resolve=t,n.reject=e,n},Gp=t=>t==null?"":""+t,uw=(t,e,n)=>{t.forEach(r=>{e[r]&&(n[r]=e[r])})},pw=/###/g,Wp=t=>t&&t.indexOf("###")>-1?t.replace(pw,"."):t,Jp=t=>!t||he(t),Vi=(t,e,n)=>{const r=he(e)?e.split("."):e;let i=0;for(;i<r.length-1;){if(Jp(t))return{};const s=Wp(r[i]);!t[s]&&n&&(t[s]=new n),Object.prototype.hasOwnProperty.call(t,s)?t=t[s]:t={},++i}return Jp(t)?{}:{obj:t,k:Wp(r[i])}},Xp=(t,e,n)=>{const{obj:r,k:i}=Vi(t,e,Object);if(r!==void 0||e.length===1){r[i]=n;return}let s=e[e.length-1],a=e.slice(0,e.length-1),c=Vi(t,a,Object);for(;c.obj===void 0&&a.length;)s=`${a[a.length-1]}.${s}`,a=a.slice(0,a.length-1),c=Vi(t,a,Object),c!=null&&c.obj&&typeof c.obj[`${c.k}.${s}`]<"u"&&(c.obj=void 0);c.obj[`${c.k}.${s}`]=n},fw=(t,e,n,r)=>{const{obj:i,k:s}=Vi(t,e,Object);i[s]=i[s]||[],i[s].push(n)},Cs=(t,e)=>{const{obj:n,k:r}=Vi(t,e);if(n&&Object.prototype.hasOwnProperty.call(n,r))return n[r]},hw=(t,e,n)=>{const r=Cs(t,n);return r!==void 0?r:Cs(e,n)},f0=(t,e,n)=>{for(const r in e)r!=="__proto__"&&r!=="constructor"&&(r in t?he(t[r])||t[r]instanceof String||he(e[r])||e[r]instanceof String?n&&(t[r]=e[r]):f0(t[r],e[r],n):t[r]=e[r]);return t},Lr=t=>t.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&");var gw={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;"};const mw=t=>he(t)?t.replace(/[&<>"'\/]/g,e=>gw[e]):t;class _w{constructor(e){this.capacity=e,this.regExpMap=new Map,this.regExpQueue=[]}getRegExp(e){const n=this.regExpMap.get(e);if(n!==void 0)return n;const r=new RegExp(e);return this.regExpQueue.length===this.capacity&&this.regExpMap.delete(this.regExpQueue.shift()),this.regExpMap.set(e,r),this.regExpQueue.push(e),r}}const yw=[" ",",","?","!",";"],ww=new _w(20),vw=(t,e,n)=>{e=e||"",n=n||"";const r=yw.filter(a=>e.indexOf(a)<0&&n.indexOf(a)<0);if(r.length===0)return!0;const i=ww.getRegExp(`(${r.map(a=>a==="?"?"\\?":a).join("|")})`);let s=!i.test(t);if(!s){const a=t.indexOf(n);a>0&&!i.test(t.substring(0,a))&&(s=!0)}return s},$l=function(t,e){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:".";if(!t)return;if(t[e])return Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;const r=e.split(n);let i=t;for(let s=0;s<r.length;){if(!i||typeof i!="object")return;let a,c="";for(let l=s;l<r.length;++l)if(l!==s&&(c+=n),c+=r[l],a=i[c],a!==void 0){if(["string","number","boolean"].indexOf(typeof a)>-1&&l<r.length-1)continue;s+=l-s+1;break}i=a}return i},Ns=t=>t==null?void 0:t.replace("_","-"),bw={type:"logger",log(t){this.output("log",t)},warn(t){this.output("warn",t)},error(t){this.output("error",t)},output(t,e){var n,r;(r=(n=console==null?void 0:console[t])==null?void 0:n.apply)==null||r.call(n,console,e)}};class Is{constructor(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.init(e,n)}init(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.prefix=n.prefix||"i18next:",this.logger=e||bw,this.options=n,this.debug=n.debug}log(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return this.forward(n,"log","",!0)}warn(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return this.forward(n,"warn","",!0)}error(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return this.forward(n,"error","")}deprecate(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return this.forward(n,"warn","WARNING DEPRECATED: ",!0)}forward(e,n,r,i){return i&&!this.debug?null:(he(e[0])&&(e[0]=`${r}${this.prefix} ${e[0]}`),this.logger[n](e))}create(e){return new Is(this.logger,{prefix:`${this.prefix}:${e}:`,...this.options})}clone(e){return e=e||this.options,e.prefix=e.prefix||this.prefix,new Is(this.logger,e)}}var cn=new Is;class ja{constructor(){this.observers={}}on(e,n){return e.split(" ").forEach(r=>{this.observers[r]||(this.observers[r]=new Map);const i=this.observers[r].get(n)||0;this.observers[r].set(n,i+1)}),this}off(e,n){if(this.observers[e]){if(!n){delete this.observers[e];return}this.observers[e].delete(n)}}emit(e){for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];this.observers[e]&&Array.from(this.observers[e].entries()).forEach(a=>{let[c,l]=a;for(let d=0;d<l;d++)c(...r)}),this.observers["*"]&&Array.from(this.observers["*"].entries()).forEach(a=>{let[c,l]=a;for(let d=0;d<l;d++)c.apply(c,[e,...r])})}}class Zp extends ja{constructor(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{ns:["translation"],defaultNS:"translation"};super(),this.data=e||{},this.options=n,this.options.keySeparator===void 0&&(this.options.keySeparator="."),this.options.ignoreJSONStructure===void 0&&(this.options.ignoreJSONStructure=!0)}addNamespaces(e){this.options.ns.indexOf(e)<0&&this.options.ns.push(e)}removeNamespaces(e){const n=this.options.ns.indexOf(e);n>-1&&this.options.ns.splice(n,1)}getResource(e,n,r){var d,u;let i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};const s=i.keySeparator!==void 0?i.keySeparator:this.options.keySeparator,a=i.ignoreJSONStructure!==void 0?i.ignoreJSONStructure:this.options.ignoreJSONStructure;let c;e.indexOf(".")>-1?c=e.split("."):(c=[e,n],r&&(Array.isArray(r)?c.push(...r):he(r)&&s?c.push(...r.split(s)):c.push(r)));const l=Cs(this.data,c);return!l&&!n&&!r&&e.indexOf(".")>-1&&(e=c[0],n=c[1],r=c.slice(2).join(".")),l||!a||!he(r)?l:$l((u=(d=this.data)==null?void 0:d[e])==null?void 0:u[n],r,s)}addResource(e,n,r,i){let s=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{silent:!1};const a=s.keySeparator!==void 0?s.keySeparator:this.options.keySeparator;let c=[e,n];r&&(c=c.concat(a?r.split(a):r)),e.indexOf(".")>-1&&(c=e.split("."),i=n,n=c[1]),this.addNamespaces(n),Xp(this.data,c,i),s.silent||this.emit("added",e,n,r,i)}addResources(e,n,r){let i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{silent:!1};for(const s in r)(he(r[s])||Array.isArray(r[s]))&&this.addResource(e,n,s,r[s],{silent:!0});i.silent||this.emit("added",e,n,r)}addResourceBundle(e,n,r,i,s){let a=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{silent:!1,skipCopy:!1},c=[e,n];e.indexOf(".")>-1&&(c=e.split("."),i=r,r=n,n=c[1]),this.addNamespaces(n);let l=Cs(this.data,c)||{};a.skipCopy||(r=JSON.parse(JSON.stringify(r))),i?f0(l,r,s):l={...l,...r},Xp(this.data,c,l),a.silent||this.emit("added",e,n,r)}removeResourceBundle(e,n){this.hasResourceBundle(e,n)&&delete this.data[e][n],this.removeNamespaces(n),this.emit("removed",e,n)}hasResourceBundle(e,n){return this.getResource(e,n)!==void 0}getResourceBundle(e,n){return n||(n=this.options.defaultNS),this.getResource(e,n)}getDataByLanguage(e){return this.data[e]}hasLanguageSomeTranslations(e){const n=this.getDataByLanguage(e);return!!(n&&Object.keys(n)||[]).find(i=>n[i]&&Object.keys(n[i]).length>0)}toJSON(){return this.data}}var h0={processors:{},addPostProcessor(t){this.processors[t.name]=t},handle(t,e,n,r,i){return t.forEach(s=>{var a;e=((a=this.processors[s])==null?void 0:a.process(e,n,r,i))??e}),e}};const Yp={};class js extends ja{constructor(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),uw(["resourceStore","languageUtils","pluralResolver","interpolator","backendConnector","i18nFormat","utils"],e,this),this.options=n,this.options.keySeparator===void 0&&(this.options.keySeparator="."),this.logger=cn.create("translator")}changeLanguage(e){e&&(this.language=e)}exists(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{interpolation:{}};if(e==null)return!1;const r=this.resolve(e,n);return(r==null?void 0:r.res)!==void 0}extractFromKey(e,n){let r=n.nsSeparator!==void 0?n.nsSeparator:this.options.nsSeparator;r===void 0&&(r=":");const i=n.keySeparator!==void 0?n.keySeparator:this.options.keySeparator;let s=n.ns||this.options.defaultNS||[];const a=r&&e.indexOf(r)>-1,c=!this.options.userDefinedKeySeparator&&!n.keySeparator&&!this.options.userDefinedNsSeparator&&!n.nsSeparator&&!vw(e,r,i);if(a&&!c){const l=e.match(this.interpolator.nestingRegexp);if(l&&l.length>0)return{key:e,namespaces:he(s)?[s]:s};const d=e.split(r);(r!==i||r===i&&this.options.ns.indexOf(d[0])>-1)&&(s=d.shift()),e=d.join(i)}return{key:e,namespaces:he(s)?[s]:s}}translate(e,n,r){if(typeof n!="object"&&this.options.overloadTranslationOptionHandler&&(n=this.options.overloadTranslationOptionHandler(arguments)),typeof n=="object"&&(n={...n}),n||(n={}),e==null)return"";Array.isArray(e)||(e=[String(e)]);const i=n.returnDetails!==void 0?n.returnDetails:this.options.returnDetails,s=n.keySeparator!==void 0?n.keySeparator:this.options.keySeparator,{key:a,namespaces:c}=this.extractFromKey(e[e.length-1],n),l=c[c.length-1],d=n.lng||this.language,u=n.appendNamespaceToCIMode||this.options.appendNamespaceToCIMode;if((d==null?void 0:d.toLowerCase())==="cimode"){if(u){const T=n.nsSeparator||this.options.nsSeparator;return i?{res:`${l}${T}${a}`,usedKey:a,exactUsedKey:a,usedLng:d,usedNS:l,usedParams:this.getUsedParamsDetails(n)}:`${l}${T}${a}`}return i?{res:a,usedKey:a,exactUsedKey:a,usedLng:d,usedNS:l,usedParams:this.getUsedParamsDetails(n)}:a}const f=this.resolve(e,n);let h=f==null?void 0:f.res;const m=(f==null?void 0:f.usedKey)||a,y=(f==null?void 0:f.exactUsedKey)||a,v=Object.prototype.toString.apply(h),b=["[object Number]","[object Function]","[object RegExp]"],A=n.joinArrays!==void 0?n.joinArrays:this.options.joinArrays,O=!this.i18nFormat||this.i18nFormat.handleAsObject,U=!he(h)&&typeof h!="boolean"&&typeof h!="number";if(O&&h&&U&&b.indexOf(v)<0&&!(he(A)&&Array.isArray(h))){if(!n.returnObjects&&!this.options.returnObjects){this.options.returnedObjectHandler||this.logger.warn("accessing an object - but returnObjects options is not enabled!");const T=this.options.returnedObjectHandler?this.options.returnedObjectHandler(m,h,{...n,ns:c}):`key '${a} (${this.language})' returned an object instead of string.`;return i?(f.res=T,f.usedParams=this.getUsedParamsDetails(n),f):T}if(s){const T=Array.isArray(h),R=T?[]:{},W=T?y:m;for(const ne in h)if(Object.prototype.hasOwnProperty.call(h,ne)){const Q=`${W}${s}${ne}`;R[ne]=this.translate(Q,{...n,joinArrays:!1,ns:c}),R[ne]===Q&&(R[ne]=h[ne])}h=R}}else if(O&&he(A)&&Array.isArray(h))h=h.join(A),h&&(h=this.extendTranslation(h,e,n,r));else{let T=!1,R=!1;const W=n.count!==void 0&&!he(n.count),ne=js.hasDefaultValue(n),Q=W?this.pluralResolver.getSuffix(d,n.count,n):"",K=n.ordinal&&W?this.pluralResolver.getSuffix(d,n.count,{ordinal:!1}):"",de=W&&!n.ordinal&&n.count===0,N=de&&n[`defaultValue${this.options.pluralSeparator}zero`]||n[`defaultValue${Q}`]||n[`defaultValue${K}`]||n.defaultValue;!this.isValidLookup(h)&&ne&&(T=!0,h=N),this.isValidLookup(h)||(R=!0,h=a);const z=(n.missingKeyNoValueFallbackToKey||this.options.missingKeyNoValueFallbackToKey)&&R?void 0:h,k=ne&&N!==h&&this.options.updateMissing;if(R||T||k){if(this.logger.log(k?"updateKey":"missingKey",d,l,a,k?N:h),s){const q=this.resolve(a,{...n,keySeparator:!1});q&&q.res&&this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.")}let $=[];const I=this.languageUtils.getFallbackCodes(this.options.fallbackLng,n.lng||this.language);if(this.options.saveMissingTo==="fallback"&&I&&I[0])for(let q=0;q<I.length;q++)$.push(I[q]);else this.options.saveMissingTo==="all"?$=this.languageUtils.toResolveHierarchy(n.lng||this.language):$.push(n.lng||this.language);const L=(q,F,Z)=>{var D;const se=ne&&Z!==h?Z:z;this.options.missingKeyHandler?this.options.missingKeyHandler(q,l,F,se,k,n):(D=this.backendConnector)!=null&&D.saveMissing&&this.backendConnector.saveMissing(q,l,F,se,k,n),this.emit("missingKey",q,l,F,h)};this.options.saveMissing&&(this.options.saveMissingPlurals&&W?$.forEach(q=>{const F=this.pluralResolver.getSuffixes(q,n);de&&n[`defaultValue${this.options.pluralSeparator}zero`]&&F.indexOf(`${this.options.pluralSeparator}zero`)<0&&F.push(`${this.options.pluralSeparator}zero`),F.forEach(Z=>{L([q],a+Z,n[`defaultValue${Z}`]||N)})}):L($,a,N))}h=this.extendTranslation(h,e,n,f,r),R&&h===a&&this.options.appendNamespaceToMissingKey&&(h=`${l}:${a}`),(R||T)&&this.options.parseMissingKeyHandler&&(h=this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey?`${l}:${a}`:a,T?h:void 0))}return i?(f.res=h,f.usedParams=this.getUsedParamsDetails(n),f):h}extendTranslation(e,n,r,i,s){var d,u;var a=this;if((d=this.i18nFormat)!=null&&d.parse)e=this.i18nFormat.parse(e,{...this.options.interpolation.defaultVariables,...r},r.lng||this.language||i.usedLng,i.usedNS,i.usedKey,{resolved:i});else if(!r.skipInterpolation){r.interpolation&&this.interpolator.init({...r,interpolation:{...this.options.interpolation,...r.interpolation}});const f=he(e)&&(((u=r==null?void 0:r.interpolation)==null?void 0:u.skipOnVariables)!==void 0?r.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables);let h;if(f){const y=e.match(this.interpolator.nestingRegexp);h=y&&y.length}let m=r.replace&&!he(r.replace)?r.replace:r;if(this.options.interpolation.defaultVariables&&(m={...this.options.interpolation.defaultVariables,...m}),e=this.interpolator.interpolate(e,m,r.lng||this.language||i.usedLng,r),f){const y=e.match(this.interpolator.nestingRegexp),v=y&&y.length;h<v&&(r.nest=!1)}!r.lng&&i&&i.res&&(r.lng=this.language||i.usedLng),r.nest!==!1&&(e=this.interpolator.nest(e,function(){for(var y=arguments.length,v=new Array(y),b=0;b<y;b++)v[b]=arguments[b];return(s==null?void 0:s[0])===v[0]&&!r.context?(a.logger.warn(`It seems you are nesting recursively key: ${v[0]} in key: ${n[0]}`),null):a.translate(...v,n)},r)),r.interpolation&&this.interpolator.reset()}const c=r.postProcess||this.options.postProcess,l=he(c)?[c]:c;return e!=null&&(l!=null&&l.length)&&r.applyPostProcessor!==!1&&(e=h0.handle(l,e,n,this.options&&this.options.postProcessPassResolved?{i18nResolved:{...i,usedParams:this.getUsedParamsDetails(r)},...r}:r,this)),e}resolve(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r,i,s,a,c;return he(e)&&(e=[e]),e.forEach(l=>{if(this.isValidLookup(r))return;const d=this.extractFromKey(l,n),u=d.key;i=u;let f=d.namespaces;this.options.fallbackNS&&(f=f.concat(this.options.fallbackNS));const h=n.count!==void 0&&!he(n.count),m=h&&!n.ordinal&&n.count===0,y=n.context!==void 0&&(he(n.context)||typeof n.context=="number")&&n.context!=="",v=n.lngs?n.lngs:this.languageUtils.toResolveHierarchy(n.lng||this.language,n.fallbackLng);f.forEach(b=>{var A,O;this.isValidLookup(r)||(c=b,!Yp[`${v[0]}-${b}`]&&((A=this.utils)!=null&&A.hasLoadedNamespace)&&!((O=this.utils)!=null&&O.hasLoadedNamespace(c))&&(Yp[`${v[0]}-${b}`]=!0,this.logger.warn(`key "${i}" for languages "${v.join(", ")}" won't get resolved as namespace "${c}" was not yet loaded`,"This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!")),v.forEach(U=>{var W;if(this.isValidLookup(r))return;a=U;const T=[u];if((W=this.i18nFormat)!=null&&W.addLookupKeys)this.i18nFormat.addLookupKeys(T,u,U,b,n);else{let ne;h&&(ne=this.pluralResolver.getSuffix(U,n.count,n));const Q=`${this.options.pluralSeparator}zero`,K=`${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;if(h&&(T.push(u+ne),n.ordinal&&ne.indexOf(K)===0&&T.push(u+ne.replace(K,this.options.pluralSeparator)),m&&T.push(u+Q)),y){const de=`${u}${this.options.contextSeparator}${n.context}`;T.push(de),h&&(T.push(de+ne),n.ordinal&&ne.indexOf(K)===0&&T.push(de+ne.replace(K,this.options.pluralSeparator)),m&&T.push(de+Q))}}let R;for(;R=T.pop();)this.isValidLookup(r)||(s=R,r=this.getResource(U,b,R,n))}))})}),{res:r,usedKey:i,exactUsedKey:s,usedLng:a,usedNS:c}}isValidLookup(e){return e!==void 0&&!(!this.options.returnNull&&e===null)&&!(!this.options.returnEmptyString&&e==="")}getResource(e,n,r){var s;let i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};return(s=this.i18nFormat)!=null&&s.getResource?this.i18nFormat.getResource(e,n,r,i):this.resourceStore.getResource(e,n,r,i)}getUsedParamsDetails(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const n=["defaultValue","ordinal","context","replace","lng","lngs","fallbackLng","ns","keySeparator","nsSeparator","returnObjects","returnDetails","joinArrays","postProcess","interpolation"],r=e.replace&&!he(e.replace);let i=r?e.replace:e;if(r&&typeof e.count<"u"&&(i.count=e.count),this.options.interpolation.defaultVariables&&(i={...this.options.interpolation.defaultVariables,...i}),!r){i={...i};for(const s of n)delete i[s]}return i}static hasDefaultValue(e){const n="defaultValue";for(const r in e)if(Object.prototype.hasOwnProperty.call(e,r)&&n===r.substring(0,n.length)&&e[r]!==void 0)return!0;return!1}}class Qp{constructor(e){this.options=e,this.supportedLngs=this.options.supportedLngs||!1,this.logger=cn.create("languageUtils")}getScriptPartFromCode(e){if(e=Ns(e),!e||e.indexOf("-")<0)return null;const n=e.split("-");return n.length===2||(n.pop(),n[n.length-1].toLowerCase()==="x")?null:this.formatLanguageCode(n.join("-"))}getLanguagePartFromCode(e){if(e=Ns(e),!e||e.indexOf("-")<0)return e;const n=e.split("-");return this.formatLanguageCode(n[0])}formatLanguageCode(e){if(he(e)&&e.indexOf("-")>-1){let n;try{n=Intl.getCanonicalLocales(e)[0]}catch{}return n&&this.options.lowerCaseLng&&(n=n.toLowerCase()),n||(this.options.lowerCaseLng?e.toLowerCase():e)}return this.options.cleanCode||this.options.lowerCaseLng?e.toLowerCase():e}isSupportedCode(e){return(this.options.load==="languageOnly"||this.options.nonExplicitSupportedLngs)&&(e=this.getLanguagePartFromCode(e)),!this.supportedLngs||!this.supportedLngs.length||this.supportedLngs.indexOf(e)>-1}getBestMatchFromCodes(e){if(!e)return null;let n;return e.forEach(r=>{if(n)return;const i=this.formatLanguageCode(r);(!this.options.supportedLngs||this.isSupportedCode(i))&&(n=i)}),!n&&this.options.supportedLngs&&e.forEach(r=>{if(n)return;const i=this.getLanguagePartFromCode(r);if(this.isSupportedCode(i))return n=i;n=this.options.supportedLngs.find(s=>{if(s===i)return s;if(!(s.indexOf("-")<0&&i.indexOf("-")<0)&&(s.indexOf("-")>0&&i.indexOf("-")<0&&s.substring(0,s.indexOf("-"))===i||s.indexOf(i)===0&&i.length>1))return s})}),n||(n=this.getFallbackCodes(this.options.fallbackLng)[0]),n}getFallbackCodes(e,n){if(!e)return[];if(typeof e=="function"&&(e=e(n)),he(e)&&(e=[e]),Array.isArray(e))return e;if(!n)return e.default||[];let r=e[n];return r||(r=e[this.getScriptPartFromCode(n)]),r||(r=e[this.formatLanguageCode(n)]),r||(r=e[this.getLanguagePartFromCode(n)]),r||(r=e.default),r||[]}toResolveHierarchy(e,n){const r=this.getFallbackCodes(n||this.options.fallbackLng||[],e),i=[],s=a=>{a&&(this.isSupportedCode(a)?i.push(a):this.logger.warn(`rejecting language code not found in supportedLngs: ${a}`))};return he(e)&&(e.indexOf("-")>-1||e.indexOf("_")>-1)?(this.options.load!=="languageOnly"&&s(this.formatLanguageCode(e)),this.options.load!=="languageOnly"&&this.options.load!=="currentOnly"&&s(this.getScriptPartFromCode(e)),this.options.load!=="currentOnly"&&s(this.getLanguagePartFromCode(e))):he(e)&&s(this.formatLanguageCode(e)),r.forEach(a=>{i.indexOf(a)<0&&s(this.formatLanguageCode(a))}),i}}const ef={zero:0,one:1,two:2,few:3,many:4,other:5},tf={select:t=>t===1?"one":"other",resolvedOptions:()=>({pluralCategories:["one","other"]})};class $w{constructor(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.languageUtils=e,this.options=n,this.logger=cn.create("pluralResolver"),this.pluralRulesCache={}}addRule(e,n){this.rules[e]=n}clearCache(){this.pluralRulesCache={}}getRule(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const r=Ns(e==="dev"?"en":e),i=n.ordinal?"ordinal":"cardinal",s=JSON.stringify({cleanedCode:r,type:i});if(s in this.pluralRulesCache)return this.pluralRulesCache[s];let a;try{a=new Intl.PluralRules(r,{type:i})}catch{if(!Intl)return this.logger.error("No Intl support, please use an Intl polyfill!"),tf;if(!e.match(/-|_/))return tf;const l=this.languageUtils.getLanguagePartFromCode(e);a=this.getRule(l,n)}return this.pluralRulesCache[s]=a,a}needsPlural(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=this.getRule(e,n);return r||(r=this.getRule("dev",n)),(r==null?void 0:r.resolvedOptions().pluralCategories.length)>1}getPluralFormsOfKey(e,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return this.getSuffixes(e,r).map(i=>`${n}${i}`)}getSuffixes(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=this.getRule(e,n);return r||(r=this.getRule("dev",n)),r?r.resolvedOptions().pluralCategories.sort((i,s)=>ef[i]-ef[s]).map(i=>`${this.options.prepend}${n.ordinal?`ordinal${this.options.prepend}`:""}${i}`):[]}getSuffix(e,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const i=this.getRule(e,r);return i?`${this.options.prepend}${r.ordinal?`ordinal${this.options.prepend}`:""}${i.select(n)}`:(this.logger.warn(`no plural rule found for: ${e}`),this.getSuffix("dev",n,r))}}const nf=function(t,e,n){let r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:".",i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:!0,s=hw(t,e,n);return!s&&i&&he(n)&&(s=$l(t,n,r),s===void 0&&(s=$l(e,n,r))),s},Wc=t=>t.replace(/\$/g,"$$$$");class kw{constructor(){var n;let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.logger=cn.create("interpolator"),this.options=e,this.format=((n=e==null?void 0:e.interpolation)==null?void 0:n.format)||(r=>r),this.init(e)}init(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};e.interpolation||(e.interpolation={escapeValue:!0});const{escape:n,escapeValue:r,useRawValueToEscape:i,prefix:s,prefixEscaped:a,suffix:c,suffixEscaped:l,formatSeparator:d,unescapeSuffix:u,unescapePrefix:f,nestingPrefix:h,nestingPrefixEscaped:m,nestingSuffix:y,nestingSuffixEscaped:v,nestingOptionsSeparator:b,maxReplaces:A,alwaysFormat:O}=e.interpolation;this.escape=n!==void 0?n:mw,this.escapeValue=r!==void 0?r:!0,this.useRawValueToEscape=i!==void 0?i:!1,this.prefix=s?Lr(s):a||"{{",this.suffix=c?Lr(c):l||"}}",this.formatSeparator=d||",",this.unescapePrefix=u?"":f||"-",this.unescapeSuffix=this.unescapePrefix?"":u||"",this.nestingPrefix=h?Lr(h):m||Lr("$t("),this.nestingSuffix=y?Lr(y):v||Lr(")"),this.nestingOptionsSeparator=b||",",this.maxReplaces=A||1e3,this.alwaysFormat=O!==void 0?O:!1,this.resetRegExp()}reset(){this.options&&this.init(this.options)}resetRegExp(){const e=(n,r)=>(n==null?void 0:n.source)===r?(n.lastIndex=0,n):new RegExp(r,"g");this.regexp=e(this.regexp,`${this.prefix}(.+?)${this.suffix}`),this.regexpUnescape=e(this.regexpUnescape,`${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`),this.nestingRegexp=e(this.nestingRegexp,`${this.nestingPrefix}(.+?)${this.nestingSuffix}`)}interpolate(e,n,r,i){var m;let s,a,c;const l=this.options&&this.options.interpolation&&this.options.interpolation.defaultVariables||{},d=y=>{if(y.indexOf(this.formatSeparator)<0){const O=nf(n,l,y,this.options.keySeparator,this.options.ignoreJSONStructure);return this.alwaysFormat?this.format(O,void 0,r,{...i,...n,interpolationkey:y}):O}const v=y.split(this.formatSeparator),b=v.shift().trim(),A=v.join(this.formatSeparator).trim();return this.format(nf(n,l,b,this.options.keySeparator,this.options.ignoreJSONStructure),A,r,{...i,...n,interpolationkey:b})};this.resetRegExp();const u=(i==null?void 0:i.missingInterpolationHandler)||this.options.missingInterpolationHandler,f=((m=i==null?void 0:i.interpolation)==null?void 0:m.skipOnVariables)!==void 0?i.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables;return[{regex:this.regexpUnescape,safeValue:y=>Wc(y)},{regex:this.regexp,safeValue:y=>this.escapeValue?Wc(this.escape(y)):Wc(y)}].forEach(y=>{for(c=0;s=y.regex.exec(e);){const v=s[1].trim();if(a=d(v),a===void 0)if(typeof u=="function"){const A=u(e,s,i);a=he(A)?A:""}else if(i&&Object.prototype.hasOwnProperty.call(i,v))a="";else if(f){a=s[0];continue}else this.logger.warn(`missed to pass in variable ${v} for interpolating ${e}`),a="";else!he(a)&&!this.useRawValueToEscape&&(a=Gp(a));const b=y.safeValue(a);if(e=e.replace(s[0],b),f?(y.regex.lastIndex+=a.length,y.regex.lastIndex-=s[0].length):y.regex.lastIndex=0,c++,c>=this.maxReplaces)break}}),e}nest(e,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},i,s,a;const c=(l,d)=>{const u=this.nestingOptionsSeparator;if(l.indexOf(u)<0)return l;const f=l.split(new RegExp(`${u}[ ]*{`));let h=`{${f[1]}`;l=f[0],h=this.interpolate(h,a);const m=h.match(/'/g),y=h.match(/"/g);(((m==null?void 0:m.length)??0)%2===0&&!y||y.length%2!==0)&&(h=h.replace(/'/g,'"'));try{a=JSON.parse(h),d&&(a={...d,...a})}catch(v){return this.logger.warn(`failed parsing options string in nesting for key ${l}`,v),`${l}${u}${h}`}return a.defaultValue&&a.defaultValue.indexOf(this.prefix)>-1&&delete a.defaultValue,l};for(;i=this.nestingRegexp.exec(e);){let l=[];a={...r},a=a.replace&&!he(a.replace)?a.replace:a,a.applyPostProcessor=!1,delete a.defaultValue;let d=!1;if(i[0].indexOf(this.formatSeparator)!==-1&&!/{.*}/.test(i[1])){const u=i[1].split(this.formatSeparator).map(f=>f.trim());i[1]=u.shift(),l=u,d=!0}if(s=n(c.call(this,i[1].trim(),a),a),s&&i[0]===e&&!he(s))return s;he(s)||(s=Gp(s)),s||(this.logger.warn(`missed to resolve ${i[1]} for nesting ${e}`),s=""),d&&(s=l.reduce((u,f)=>this.format(u,f,r.lng,{...r,interpolationkey:i[1].trim()}),s.trim())),e=e.replace(i[0],s),this.regexp.lastIndex=0}return e}}const xw=t=>{let e=t.toLowerCase().trim();const n={};if(t.indexOf("(")>-1){const r=t.split("(");e=r[0].toLowerCase().trim();const i=r[1].substring(0,r[1].length-1);e==="currency"&&i.indexOf(":")<0?n.currency||(n.currency=i.trim()):e==="relativetime"&&i.indexOf(":")<0?n.range||(n.range=i.trim()):i.split(";").forEach(a=>{if(a){const[c,...l]=a.split(":"),d=l.join(":").trim().replace(/^'+|'+$/g,""),u=c.trim();n[u]||(n[u]=d),d==="false"&&(n[u]=!1),d==="true"&&(n[u]=!0),isNaN(d)||(n[u]=parseInt(d,10))}})}return{formatName:e,formatOptions:n}},Ur=t=>{const e={};return(n,r,i)=>{let s=i;i&&i.interpolationkey&&i.formatParams&&i.formatParams[i.interpolationkey]&&i[i.interpolationkey]&&(s={...s,[i.interpolationkey]:void 0});const a=r+JSON.stringify(s);let c=e[a];return c||(c=t(Ns(r),i),e[a]=c),c(n)}};class Sw{constructor(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.logger=cn.create("formatter"),this.options=e,this.formats={number:Ur((n,r)=>{const i=new Intl.NumberFormat(n,{...r});return s=>i.format(s)}),currency:Ur((n,r)=>{const i=new Intl.NumberFormat(n,{...r,style:"currency"});return s=>i.format(s)}),datetime:Ur((n,r)=>{const i=new Intl.DateTimeFormat(n,{...r});return s=>i.format(s)}),relativetime:Ur((n,r)=>{const i=new Intl.RelativeTimeFormat(n,{...r});return s=>i.format(s,r.range||"day")}),list:Ur((n,r)=>{const i=new Intl.ListFormat(n,{...r});return s=>i.format(s)})},this.init(e)}init(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{interpolation:{}};this.formatSeparator=n.interpolation.formatSeparator||","}add(e,n){this.formats[e.toLowerCase().trim()]=n}addCached(e,n){this.formats[e.toLowerCase().trim()]=Ur(n)}format(e,n,r){let i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};const s=n.split(this.formatSeparator);if(s.length>1&&s[0].indexOf("(")>1&&s[0].indexOf(")")<0&&s.find(c=>c.indexOf(")")>-1)){const c=s.findIndex(l=>l.indexOf(")")>-1);s[0]=[s[0],...s.splice(1,c)].join(this.formatSeparator)}return s.reduce((c,l)=>{var f;const{formatName:d,formatOptions:u}=xw(l);if(this.formats[d]){let h=c;try{const m=((f=i==null?void 0:i.formatParams)==null?void 0:f[i.interpolationkey])||{},y=m.locale||m.lng||i.locale||i.lng||r;h=this.formats[d](c,y,{...u,...i,...m})}catch(m){this.logger.warn(m)}return h}else this.logger.warn(`there was no format function for ${d}`);return c},e)}}const zw=(t,e)=>{t.pending[e]!==void 0&&(delete t.pending[e],t.pendingCount--)};class Aw extends ja{constructor(e,n,r){var s,a;let i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};super(),this.backend=e,this.store=n,this.services=r,this.languageUtils=r.languageUtils,this.options=i,this.logger=cn.create("backendConnector"),this.waitingReads=[],this.maxParallelReads=i.maxParallelReads||10,this.readingCalls=0,this.maxRetries=i.maxRetries>=0?i.maxRetries:5,this.retryTimeout=i.retryTimeout>=1?i.retryTimeout:350,this.state={},this.queue=[],(a=(s=this.backend)==null?void 0:s.init)==null||a.call(s,r,i.backend,i)}queueLoad(e,n,r,i){const s={},a={},c={},l={};return e.forEach(d=>{let u=!0;n.forEach(f=>{const h=`${d}|${f}`;!r.reload&&this.store.hasResourceBundle(d,f)?this.state[h]=2:this.state[h]<0||(this.state[h]===1?a[h]===void 0&&(a[h]=!0):(this.state[h]=1,u=!1,a[h]===void 0&&(a[h]=!0),s[h]===void 0&&(s[h]=!0),l[f]===void 0&&(l[f]=!0)))}),u||(c[d]=!0)}),(Object.keys(s).length||Object.keys(a).length)&&this.queue.push({pending:a,pendingCount:Object.keys(a).length,loaded:{},errors:[],callback:i}),{toLoad:Object.keys(s),pending:Object.keys(a),toLoadLanguages:Object.keys(c),toLoadNamespaces:Object.keys(l)}}loaded(e,n,r){const i=e.split("|"),s=i[0],a=i[1];n&&this.emit("failedLoading",s,a,n),!n&&r&&this.store.addResourceBundle(s,a,r,void 0,void 0,{skipCopy:!0}),this.state[e]=n?-1:2,n&&r&&(this.state[e]=0);const c={};this.queue.forEach(l=>{fw(l.loaded,[s],a),zw(l,e),n&&l.errors.push(n),l.pendingCount===0&&!l.done&&(Object.keys(l.loaded).forEach(d=>{c[d]||(c[d]={});const u=l.loaded[d];u.length&&u.forEach(f=>{c[d][f]===void 0&&(c[d][f]=!0)})}),l.done=!0,l.errors.length?l.callback(l.errors):l.callback())}),this.emit("loaded",c),this.queue=this.queue.filter(l=>!l.done)}read(e,n,r){let i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0,s=arguments.length>4&&arguments[4]!==void 0?arguments[4]:this.retryTimeout,a=arguments.length>5?arguments[5]:void 0;if(!e.length)return a(null,{});if(this.readingCalls>=this.maxParallelReads){this.waitingReads.push({lng:e,ns:n,fcName:r,tried:i,wait:s,callback:a});return}this.readingCalls++;const c=(d,u)=>{if(this.readingCalls--,this.waitingReads.length>0){const f=this.waitingReads.shift();this.read(f.lng,f.ns,f.fcName,f.tried,f.wait,f.callback)}if(d&&u&&i<this.maxRetries){setTimeout(()=>{this.read.call(this,e,n,r,i+1,s*2,a)},s);return}a(d,u)},l=this.backend[r].bind(this.backend);if(l.length===2){try{const d=l(e,n);d&&typeof d.then=="function"?d.then(u=>c(null,u)).catch(c):c(null,d)}catch(d){c(d)}return}return l(e,n,c)}prepareLoading(e,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},i=arguments.length>3?arguments[3]:void 0;if(!this.backend)return this.logger.warn("No backend was added via i18next.use. Will not load resources."),i&&i();he(e)&&(e=this.languageUtils.toResolveHierarchy(e)),he(n)&&(n=[n]);const s=this.queueLoad(e,n,r,i);if(!s.toLoad.length)return s.pending.length||i(),null;s.toLoad.forEach(a=>{this.loadOne(a)})}load(e,n,r){this.prepareLoading(e,n,{},r)}reload(e,n,r){this.prepareLoading(e,n,{reload:!0},r)}loadOne(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"";const r=e.split("|"),i=r[0],s=r[1];this.read(i,s,"read",void 0,void 0,(a,c)=>{a&&this.logger.warn(`${n}loading namespace ${s} for language ${i} failed`,a),!a&&c&&this.logger.log(`${n}loaded namespace ${s} for language ${i}`,c),this.loaded(e,a,c)})}saveMissing(e,n,r,i,s){var l,d,u,f,h;let a=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{},c=arguments.length>6&&arguments[6]!==void 0?arguments[6]:()=>{};if((d=(l=this.services)==null?void 0:l.utils)!=null&&d.hasLoadedNamespace&&!((f=(u=this.services)==null?void 0:u.utils)!=null&&f.hasLoadedNamespace(n))){this.logger.warn(`did not save key "${r}" as the namespace "${n}" was not yet loaded`,"This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");return}if(!(r==null||r==="")){if((h=this.backend)!=null&&h.create){const m={...a,isUpdate:s},y=this.backend.create.bind(this.backend);if(y.length<6)try{let v;y.length===5?v=y(e,n,r,i,m):v=y(e,n,r,i),v&&typeof v.then=="function"?v.then(b=>c(null,b)).catch(c):c(null,v)}catch(v){c(v)}else y(e,n,r,i,c,m)}!e||!e[0]||this.store.addResource(e[0],n,r,i)}}}const rf=()=>({debug:!1,initAsync:!0,ns:["translation"],defaultNS:["translation"],fallbackLng:["dev"],fallbackNS:!1,supportedLngs:!1,nonExplicitSupportedLngs:!1,load:"all",preload:!1,simplifyPluralSuffix:!0,keySeparator:".",nsSeparator:":",pluralSeparator:"_",contextSeparator:"_",partialBundledLanguages:!1,saveMissing:!1,updateMissing:!1,saveMissingTo:"fallback",saveMissingPlurals:!0,missingKeyHandler:!1,missingInterpolationHandler:!1,postProcess:!1,postProcessPassResolved:!1,returnNull:!1,returnEmptyString:!0,returnObjects:!1,joinArrays:!1,returnedObjectHandler:!1,parseMissingKeyHandler:!1,appendNamespaceToMissingKey:!1,appendNamespaceToCIMode:!1,overloadTranslationOptionHandler:t=>{let e={};if(typeof t[1]=="object"&&(e=t[1]),he(t[1])&&(e.defaultValue=t[1]),he(t[2])&&(e.tDescription=t[2]),typeof t[2]=="object"||typeof t[3]=="object"){const n=t[3]||t[2];Object.keys(n).forEach(r=>{e[r]=n[r]})}return e},interpolation:{escapeValue:!0,format:t=>t,prefix:"{{",suffix:"}}",formatSeparator:",",unescapePrefix:"-",nestingPrefix:"$t(",nestingSuffix:")",nestingOptionsSeparator:",",maxReplaces:1e3,skipOnVariables:!0}}),of=t=>{var e,n;return he(t.ns)&&(t.ns=[t.ns]),he(t.fallbackLng)&&(t.fallbackLng=[t.fallbackLng]),he(t.fallbackNS)&&(t.fallbackNS=[t.fallbackNS]),((n=(e=t.supportedLngs)==null?void 0:e.indexOf)==null?void 0:n.call(e,"cimode"))<0&&(t.supportedLngs=t.supportedLngs.concat(["cimode"])),typeof t.initImmediate=="boolean"&&(t.initAsync=t.initImmediate),t},ts=()=>{},Ew=t=>{Object.getOwnPropertyNames(Object.getPrototypeOf(t)).forEach(n=>{typeof t[n]=="function"&&(t[n]=t[n].bind(t))})};class no extends ja{constructor(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(super(),this.options=of(e),this.services={},this.logger=cn,this.modules={external:[]},Ew(this),n&&!this.isInitialized&&!e.isClone){if(!this.options.initAsync)return this.init(e,n),this;setTimeout(()=>{this.init(e,n)},0)}}init(){var e=this;let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;this.isInitializing=!0,typeof n=="function"&&(r=n,n={}),!n.defaultNS&&n.defaultNS!==!1&&n.ns&&(he(n.ns)?n.defaultNS=n.ns:n.ns.indexOf("translation")<0&&(n.defaultNS=n.ns[0]));const i=rf();this.options={...i,...this.options,...of(n)},this.options.interpolation={...i.interpolation,...this.options.interpolation},n.keySeparator!==void 0&&(this.options.userDefinedKeySeparator=n.keySeparator),n.nsSeparator!==void 0&&(this.options.userDefinedNsSeparator=n.nsSeparator);const s=u=>u?typeof u=="function"?new u:u:null;if(!this.options.isClone){this.modules.logger?cn.init(s(this.modules.logger),this.options):cn.init(null,this.options);let u;this.modules.formatter?u=this.modules.formatter:u=Sw;const f=new Qp(this.options);this.store=new Zp(this.options.resources,this.options);const h=this.services;h.logger=cn,h.resourceStore=this.store,h.languageUtils=f,h.pluralResolver=new $w(f,{prepend:this.options.pluralSeparator,simplifyPluralSuffix:this.options.simplifyPluralSuffix}),u&&(!this.options.interpolation.format||this.options.interpolation.format===i.interpolation.format)&&(h.formatter=s(u),h.formatter.init(h,this.options),this.options.interpolation.format=h.formatter.format.bind(h.formatter)),h.interpolator=new kw(this.options),h.utils={hasLoadedNamespace:this.hasLoadedNamespace.bind(this)},h.backendConnector=new Aw(s(this.modules.backend),h.resourceStore,h,this.options),h.backendConnector.on("*",function(m){for(var y=arguments.length,v=new Array(y>1?y-1:0),b=1;b<y;b++)v[b-1]=arguments[b];e.emit(m,...v)}),this.modules.languageDetector&&(h.languageDetector=s(this.modules.languageDetector),h.languageDetector.init&&h.languageDetector.init(h,this.options.detection,this.options)),this.modules.i18nFormat&&(h.i18nFormat=s(this.modules.i18nFormat),h.i18nFormat.init&&h.i18nFormat.init(this)),this.translator=new js(this.services,this.options),this.translator.on("*",function(m){for(var y=arguments.length,v=new Array(y>1?y-1:0),b=1;b<y;b++)v[b-1]=arguments[b];e.emit(m,...v)}),this.modules.external.forEach(m=>{m.init&&m.init(this)})}if(this.format=this.options.interpolation.format,r||(r=ts),this.options.fallbackLng&&!this.services.languageDetector&&!this.options.lng){const u=this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);u.length>0&&u[0]!=="dev"&&(this.options.lng=u[0])}!this.services.languageDetector&&!this.options.lng&&this.logger.warn("init: no languageDetector is used and no lng is defined"),["getResource","hasResourceBundle","getResourceBundle","getDataByLanguage"].forEach(u=>{this[u]=function(){return e.store[u](...arguments)}}),["addResource","addResources","addResourceBundle","removeResourceBundle"].forEach(u=>{this[u]=function(){return e.store[u](...arguments),e}});const l=Pi(),d=()=>{const u=(f,h)=>{this.isInitializing=!1,this.isInitialized&&!this.initializedStoreOnce&&this.logger.warn("init: i18next is already initialized. You should call init just once!"),this.isInitialized=!0,this.options.isClone||this.logger.log("initialized",this.options),this.emit("initialized",this.options),l.resolve(h),r(f,h)};if(this.languages&&!this.isInitialized)return u(null,this.t.bind(this));this.changeLanguage(this.options.lng,u)};return this.options.resources||!this.options.initAsync?d():setTimeout(d,0),l}loadResources(e){var s,a;let r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:ts;const i=he(e)?e:this.language;if(typeof e=="function"&&(r=e),!this.options.resources||this.options.partialBundledLanguages){if((i==null?void 0:i.toLowerCase())==="cimode"&&(!this.options.preload||this.options.preload.length===0))return r();const c=[],l=d=>{if(!d||d==="cimode")return;this.services.languageUtils.toResolveHierarchy(d).forEach(f=>{f!=="cimode"&&c.indexOf(f)<0&&c.push(f)})};i?l(i):this.services.languageUtils.getFallbackCodes(this.options.fallbackLng).forEach(u=>l(u)),(a=(s=this.options.preload)==null?void 0:s.forEach)==null||a.call(s,d=>l(d)),this.services.backendConnector.load(c,this.options.ns,d=>{!d&&!this.resolvedLanguage&&this.language&&this.setResolvedLanguage(this.language),r(d)})}else r(null)}reloadResources(e,n,r){const i=Pi();return typeof e=="function"&&(r=e,e=void 0),typeof n=="function"&&(r=n,n=void 0),e||(e=this.languages),n||(n=this.options.ns),r||(r=ts),this.services.backendConnector.reload(e,n,s=>{i.resolve(),r(s)}),i}use(e){if(!e)throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");if(!e.type)throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");return e.type==="backend"&&(this.modules.backend=e),(e.type==="logger"||e.log&&e.warn&&e.error)&&(this.modules.logger=e),e.type==="languageDetector"&&(this.modules.languageDetector=e),e.type==="i18nFormat"&&(this.modules.i18nFormat=e),e.type==="postProcessor"&&h0.addPostProcessor(e),e.type==="formatter"&&(this.modules.formatter=e),e.type==="3rdParty"&&this.modules.external.push(e),this}setResolvedLanguage(e){if(!(!e||!this.languages)&&!(["cimode","dev"].indexOf(e)>-1))for(let n=0;n<this.languages.length;n++){const r=this.languages[n];if(!(["cimode","dev"].indexOf(r)>-1)&&this.store.hasLanguageSomeTranslations(r)){this.resolvedLanguage=r;break}}}changeLanguage(e,n){var r=this;this.isLanguageChangingTo=e;const i=Pi();this.emit("languageChanging",e);const s=l=>{this.language=l,this.languages=this.services.languageUtils.toResolveHierarchy(l),this.resolvedLanguage=void 0,this.setResolvedLanguage(l)},a=(l,d)=>{d?(s(d),this.translator.changeLanguage(d),this.isLanguageChangingTo=void 0,this.emit("languageChanged",d),this.logger.log("languageChanged",d)):this.isLanguageChangingTo=void 0,i.resolve(function(){return r.t(...arguments)}),n&&n(l,function(){return r.t(...arguments)})},c=l=>{var u,f;!e&&!l&&this.services.languageDetector&&(l=[]);const d=he(l)?l:this.services.languageUtils.getBestMatchFromCodes(l);d&&(this.language||s(d),this.translator.language||this.translator.changeLanguage(d),(f=(u=this.services.languageDetector)==null?void 0:u.cacheUserLanguage)==null||f.call(u,d)),this.loadResources(d,h=>{a(h,d)})};return!e&&this.services.languageDetector&&!this.services.languageDetector.async?c(this.services.languageDetector.detect()):!e&&this.services.languageDetector&&this.services.languageDetector.async?this.services.languageDetector.detect.length===0?this.services.languageDetector.detect().then(c):this.services.languageDetector.detect(c):c(e),i}getFixedT(e,n,r){var i=this;const s=function(a,c){let l;if(typeof c!="object"){for(var d=arguments.length,u=new Array(d>2?d-2:0),f=2;f<d;f++)u[f-2]=arguments[f];l=i.options.overloadTranslationOptionHandler([a,c].concat(u))}else l={...c};l.lng=l.lng||s.lng,l.lngs=l.lngs||s.lngs,l.ns=l.ns||s.ns,l.keyPrefix!==""&&(l.keyPrefix=l.keyPrefix||r||s.keyPrefix);const h=i.options.keySeparator||".";let m;return l.keyPrefix&&Array.isArray(a)?m=a.map(y=>`${l.keyPrefix}${h}${y}`):m=l.keyPrefix?`${l.keyPrefix}${h}${a}`:a,i.t(m,l)};return he(e)?s.lng=e:s.lngs=e,s.ns=n,s.keyPrefix=r,s}t(){var i;for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return(i=this.translator)==null?void 0:i.translate(...n)}exists(){var i;for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return(i=this.translator)==null?void 0:i.exists(...n)}setDefaultNamespace(e){this.options.defaultNS=e}hasLoadedNamespace(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!this.isInitialized)return this.logger.warn("hasLoadedNamespace: i18next was not initialized",this.languages),!1;if(!this.languages||!this.languages.length)return this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty",this.languages),!1;const r=n.lng||this.resolvedLanguage||this.languages[0],i=this.options?this.options.fallbackLng:!1,s=this.languages[this.languages.length-1];if(r.toLowerCase()==="cimode")return!0;const a=(c,l)=>{const d=this.services.backendConnector.state[`${c}|${l}`];return d===-1||d===0||d===2};if(n.precheck){const c=n.precheck(this,a);if(c!==void 0)return c}return!!(this.hasResourceBundle(r,e)||!this.services.backendConnector.backend||this.options.resources&&!this.options.partialBundledLanguages||a(r,e)&&(!i||a(s,e)))}loadNamespaces(e,n){const r=Pi();return this.options.ns?(he(e)&&(e=[e]),e.forEach(i=>{this.options.ns.indexOf(i)<0&&this.options.ns.push(i)}),this.loadResources(i=>{r.resolve(),n&&n(i)}),r):(n&&n(),Promise.resolve())}loadLanguages(e,n){const r=Pi();he(e)&&(e=[e]);const i=this.options.preload||[],s=e.filter(a=>i.indexOf(a)<0&&this.services.languageUtils.isSupportedCode(a));return s.length?(this.options.preload=i.concat(s),this.loadResources(a=>{r.resolve(),n&&n(a)}),r):(n&&n(),Promise.resolve())}dir(e){var i,s;if(e||(e=this.resolvedLanguage||(((i=this.languages)==null?void 0:i.length)>0?this.languages[0]:this.language)),!e)return"rtl";const n=["ar","shu","sqr","ssh","xaa","yhd","yud","aao","abh","abv","acm","acq","acw","acx","acy","adf","ads","aeb","aec","afb","ajp","apc","apd","arb","arq","ars","ary","arz","auz","avl","ayh","ayl","ayn","ayp","bbz","pga","he","iw","ps","pbt","pbu","pst","prp","prd","ug","ur","ydd","yds","yih","ji","yi","hbo","men","xmn","fa","jpr","peo","pes","prs","dv","sam","ckb"],r=((s=this.services)==null?void 0:s.languageUtils)||new Qp(rf());return n.indexOf(r.getLanguagePartFromCode(e))>-1||e.toLowerCase().indexOf("-arab")>1?"rtl":"ltr"}static createInstance(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;return new no(e,n)}cloneInstance(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:ts;const r=e.forkResourceStore;r&&delete e.forkResourceStore;const i={...this.options,...e,isClone:!0},s=new no(i);if((e.debug!==void 0||e.prefix!==void 0)&&(s.logger=s.logger.clone(e)),["store","services","language"].forEach(c=>{s[c]=this[c]}),s.services={...this.services},s.services.utils={hasLoadedNamespace:s.hasLoadedNamespace.bind(s)},r){const c=Object.keys(this.store.data).reduce((l,d)=>(l[d]={...this.store.data[d]},Object.keys(l[d]).reduce((u,f)=>(u[f]={...l[d][f]},u),{})),{});s.store=new Zp(c,i),s.services.resourceStore=s.store}return s.translator=new js(s.services,i),s.translator.on("*",function(c){for(var l=arguments.length,d=new Array(l>1?l-1:0),u=1;u<l;u++)d[u-1]=arguments[u];s.emit(c,...d)}),s.init(i,n),s.translator.options=i,s.translator.backendConnector.services.utils={hasLoadedNamespace:s.hasLoadedNamespace.bind(s)},s}toJSON(){return{options:this.options,store:this.store,language:this.language,languages:this.languages,resolvedLanguage:this.resolvedLanguage}}}const w=no.createInstance();w.createInstance=no.createInstance;w.createInstance;w.dir;w.init;w.loadResources;w.reloadResources;w.use;w.changeLanguage;w.getFixedT;const pe=w.t;w.exists;w.setDefaultNamespace;w.hasLoadedNamespace;w.loadNamespaces;w.loadLanguages;var g0=t=>{const n={...{origin:"*",allowMethods:["GET","HEAD","PUT","POST","DELETE","PATCH"],allowHeaders:[],exposeHeaders:[]},...t},r=(s=>typeof s=="string"?s==="*"?()=>s:a=>s===a?a:null:typeof s=="function"?s:a=>s.includes(a)?a:null)(n.origin),i=(s=>typeof s=="function"?s:Array.isArray(s)?()=>s:()=>[])(n.allowMethods);return async function(a,c){var u;function l(f,h){a.res.headers.set(f,h)}const d=r(a.req.header("origin")||"",a);if(d&&l("Access-Control-Allow-Origin",d),n.origin!=="*"){const f=a.req.header("Vary");f?l("Vary",f):l("Vary","Origin")}if(n.credentials&&l("Access-Control-Allow-Credentials","true"),(u=n.exposeHeaders)!=null&&u.length&&l("Access-Control-Expose-Headers",n.exposeHeaders.join(",")),a.req.method==="OPTIONS"){n.maxAge!=null&&l("Access-Control-Max-Age",n.maxAge.toString());const f=i(a.req.header("origin")||"",a);f.length&&l("Access-Control-Allow-Methods",f.join(","));let h=n.allowHeaders;if(!(h!=null&&h.length)){const m=a.req.header("Access-Control-Request-Headers");m&&(h=m.split(/\s*,\s*/))}return h!=null&&h.length&&(l("Access-Control-Allow-Headers",h.join(",")),a.res.headers.append("Vary","Access-Control-Request-Headers")),a.res.headers.delete("Content-Length"),a.res.headers.delete("Content-Type"),new Response(null,{headers:a.res.headers,status:204,statusText:"No Content"})}await c()}};const St=o.z.object({start:o.z.number(),limit:o.z.number(),length:o.z.number()}),yi=o.z.object({created_at:o.z.string(),updated_at:o.z.string()}),m0=o.z.object({email:o.z.string().optional(),email_verified:o.z.boolean().optional(),name:o.z.string().optional(),username:o.z.string().optional(),given_name:o.z.string().optional(),phone_number:o.z.string().optional(),phone_verified:o.z.boolean().optional(),family_name:o.z.string().optional()}).catchall(o.z.any()),_0=o.z.object({connection:o.z.string(),user_id:o.z.string(),provider:o.z.string(),isSocial:o.z.boolean(),access_token:o.z.string().optional(),access_token_secret:o.z.string().optional(),refresh_token:o.z.string().optional(),profileData:m0.optional()}),Oa=o.z.object({email:o.z.string().optional().transform(t=>t&&t.toLowerCase()),username:o.z.string().optional(),phone_number:o.z.string().optional(),given_name:o.z.string().optional(),family_name:o.z.string().optional(),nickname:o.z.string().optional(),name:o.z.string().optional(),picture:o.z.string().optional(),locale:o.z.string().optional(),linked_to:o.z.string().optional(),profileData:o.z.string().optional(),user_id:o.z.string().optional(),app_metadata:o.z.any().default({}).optional(),user_metadata:o.z.any().default({}).optional()}),Os=Oa.extend({email_verified:o.z.boolean().default(!1),verify_email:o.z.boolean().optional(),last_ip:o.z.string().optional(),last_login:o.z.string().optional(),user_id:o.z.string().optional(),provider:o.z.string().default("email"),connection:o.z.string().default("email"),is_social:o.z.boolean().optional()}),gu=o.z.object({...Os.shape,...yi.shape,user_id:o.z.string(),is_social:o.z.boolean(),email:o.z.string().optional(),login_count:o.z.number().default(0),identities:o.z.array(_0).optional()}),an=gu,Cw=Oa.extend({login_count:o.z.number(),multifactor:o.z.array(o.z.string()).optional(),last_ip:o.z.string().optional(),last_login:o.z.string().optional(),user_id:o.z.string()}).catchall(o.z.any()),Nw="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Iw=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t));for(;t--;)e+=Nw[n[t]&63];return e};const Ts=o.z.object({client_id:o.z.string().openapi({description:"ID of this client."}),name:o.z.string().min(1).openapi({description:"Name of this client (min length: 1 character, does not allow < or >)."}),description:o.z.string().max(140).optional().openapi({description:"Free text description of this client (max length: 140 characters)."}),global:o.z.boolean().default(!1).openapi({description:"Whether this is your global 'All Applications' client representing legacy tenant settings (true) or a regular client (false)."}),client_secret:o.z.string().default(()=>Iw()).optional().openapi({description:"Client secret (which you must not make public)."}),app_type:o.z.enum(["native","spa","regular_web","non_interactive","resource_server","express_configuration","rms","box","cloudbees","concur","dropbox","mscrm","echosign","egnyte","newrelic","office365","salesforce","sentry","sharepoint","slack","springcm","zendesk","zoom","sso_integration","oag"]).default("regular_web").optional().openapi({description:"The type of application this client represents"}),logo_uri:o.z.string().url().optional().openapi({description:"URL of the logo to display for this client. Recommended size is 150x150 pixels."}),is_first_party:o.z.boolean().default(!1).openapi({description:"Whether this client a first party client (true) or not (false)."}),oidc_conformant:o.z.boolean().default(!0).openapi({description:"Whether this client conforms to strict OIDC specifications (true) or uses legacy features (false)."}),callbacks:o.z.array(o.z.string()).default([]).optional().openapi({description:"Comma-separated list of URLs whitelisted for Auth0 to use as a callback to the client after authentication."}),allowed_origins:o.z.array(o.z.string()).default([]).optional().openapi({description:"Comma-separated list of URLs allowed to make requests from JavaScript to Auth0 API (typically used with CORS). By default, all your callback URLs will be allowed. This field allows you to enter other origins if necessary. You can also use wildcards at the subdomain level (e.g., https://*.contoso.com). Query strings and hash information are not taken into account when validating these URLs."}),web_origins:o.z.array(o.z.string()).default([]).optional().openapi({description:"Comma-separated list of allowed origins for use with Cross-Origin Authentication, Device Flow, and web message response mode."}),client_aliases:o.z.array(o.z.string()).default([]).optional().openapi({description:"List of audiences/realms for SAML protocol. Used by the wsfed addon."}),allowed_clients:o.z.array(o.z.string()).default([]).optional().openapi({description:"List of allow clients and API ids that are allowed to make delegation requests. Empty means all all your clients are allowed."}),allowed_logout_urls:o.z.array(o.z.string()).default([]).optional().openapi({description:"Comma-separated list of URLs that are valid to redirect to after logout from Auth0. Wildcards are allowed for subdomains."}),session_transfer:o.z.record(o.z.any()).default({}).optional().openapi({description:"Native to Web SSO Configuration"}),oidc_logout:o.z.record(o.z.any()).default({}).optional().openapi({description:"Configuration for OIDC backchannel logout"}),grant_types:o.z.array(o.z.string()).default([]).optional().openapi({description:"List of grant types supported for this application. Can include authorization_code, implicit, refresh_token, client_credentials, password, http://auth0.com/oauth/grant-type/password-realm, http://auth0.com/oauth/grant-type/mfa-oob, http://auth0.com/oauth/grant-type/mfa-otp, http://auth0.com/oauth/grant-type/mfa-recovery-code, urn:openid:params:grant-type:ciba, and urn:ietf:params:oauth:grant-type:device_code."}),jwt_configuration:o.z.record(o.z.any()).default({}).optional().openapi({description:"Configuration related to JWTs for the client."}),signing_keys:o.z.array(o.z.record(o.z.any())).default([]).optional().openapi({description:"Signing certificates associated with this client."}),encryption_key:o.z.record(o.z.any()).default({}).optional().openapi({description:"Encryption used for WsFed responses with this client."}),sso:o.z.boolean().default(!1).openapi({description:"Applies only to SSO clients and determines whether Auth0 will handle Single Sign On (true) or whether the Identity Provider will (false)."}),sso_disabled:o.z.boolean().default(!0).openapi({description:"Whether Single Sign On is disabled (true) or enabled (true). Defaults to true."}),cross_origin_authentication:o.z.boolean().default(!1).openapi({description:"Whether this client can be used to make cross-origin authentication requests (true) or it is not allowed to make such requests (false)."}),cross_origin_loc:o.z.string().url().optional().openapi({description:"URL of the location in your site where the cross origin verification takes place for the cross-origin auth flow when performing Auth in your own domain instead of Auth0 hosted login page."}),custom_login_page_on:o.z.boolean().default(!1).openapi({description:"Whether a custom login page is to be used (true) or the default provided login page (false)."}),custom_login_page:o.z.string().optional().openapi({description:"The content (HTML, CSS, JS) of the custom login page."}),custom_login_page_preview:o.z.string().optional().openapi({description:"The content (HTML, CSS, JS) of the custom login page. (Used on Previews)"}),form_template:o.z.string().optional().openapi({description:"HTML form template to be used for WS-Federation."}),addons:o.z.record(o.z.any()).default({}).optional().openapi({description:"Addons enabled for this client and their associated configurations."}),token_endpoint_auth_method:o.z.enum(["none","client_secret_post","client_secret_basic"]).default("client_secret_basic").optional().openapi({description:"Defines the requested authentication method for the token endpoint. Can be none (public client without a client secret), client_secret_post (client uses HTTP POST parameters), or client_secret_basic (client uses HTTP Basic)."}),client_metadata:o.z.record(o.z.string().max(255)).default({}).optional().openapi({description:'Metadata associated with the client, in the form of an object with string values (max 255 chars). Maximum of 10 metadata properties allowed. Field names (max 255 chars) are alphanumeric and may only include the following special characters: :,-+=_*?"/()<>@ [Tab][Space]'}),mobile:o.z.record(o.z.any()).default({}).optional().openapi({description:"Additional configuration for native mobile apps."}),initiate_login_uri:o.z.string().url().optional().openapi({description:"Initiate login uri, must be https"}),native_social_login:o.z.record(o.z.any()).default({}).optional(),refresh_token:o.z.record(o.z.any()).default({}).optional().openapi({description:"Refresh token configuration"}),default_organization:o.z.record(o.z.any()).default({}).optional().openapi({description:"Defines the default Organization ID and flows"}),organization_usage:o.z.enum(["deny","allow","require"]).default("deny").optional().openapi({description:"Defines how to proceed during an authentication transaction with regards an organization. Can be deny (default), allow or require."}),organization_require_behavior:o.z.enum(["no_prompt","pre_login_prompt","post_login_prompt"]).default("no_prompt").optional().openapi({description:"Defines how to proceed during an authentication transaction when client.organization_usage: 'require'. Can be no_prompt (default), pre_login_prompt or post_login_prompt. post_login_prompt requires oidc_conformant: true."}),client_authentication_methods:o.z.record(o.z.any()).default({}).optional().openapi({description:"Defines client authentication methods."}),require_pushed_authorization_requests:o.z.boolean().default(!1).openapi({description:"Makes the use of Pushed Authorization Requests mandatory for this client"}),require_proof_of_possession:o.z.boolean().default(!1).openapi({description:"Makes the use of Proof-of-Possession mandatory for this client"}),signed_request_object:o.z.record(o.z.any()).default({}).optional().openapi({description:"JWT-secured Authorization Requests (JAR) settings."}),compliance_level:o.z.enum(["none","fapi1_adv_pkj_par","fapi1_adv_mtls_par","fapi2_sp_pkj_mtls","fapi2_sp_mtls_mtls"]).optional().openapi({description:"Defines the compliance level for this client, which may restrict it's capabilities"}),par_request_expiry:o.z.number().optional().openapi({description:"Specifies how long, in seconds, a Pushed Authorization Request URI remains valid"}),token_quota:o.z.record(o.z.any()).default({}).optional()}),sr=o.z.object({created_at:o.z.string(),updated_at:o.z.string(),...Ts.shape}),Ps=o.z.object({client_id:o.z.string().min(1).openapi({description:"ID of the client."}),audience:o.z.string().min(1).openapi({description:"The audience (API identifier) of this client grant."}),scope:o.z.array(o.z.string()).optional().openapi({description:"Scopes allowed for this client grant."}),organization_usage:o.z.enum(["deny","allow","require"]).optional().openapi({description:"Defines whether organizations can be used with client credentials exchanges for this grant."}),allow_any_organization:o.z.boolean().optional().openapi({description:"If enabled, any organization can be used with this grant. If disabled (default), the grant must be explicitly assigned to the desired organizations."}),is_system:o.z.boolean().optional().openapi({description:"If enabled, this grant is a special grant created by Auth0. It cannot be modified or deleted directly."}),subject_type:o.z.enum(["client","user"]).optional().openapi({description:"The type of application access the client grant allows. Use of this field is subject to the applicable Free Trial terms in Okta's Master Subscription Agreement."}),authorization_details_types:o.z.array(o.z.string()).optional().openapi({description:"Types of authorization_details allowed for this client grant. Use of this field is subject to the applicable Free Trial terms in Okta's Master Subscription Agreement."})}),ar=o.z.object({id:o.z.string().openapi({description:"ID of the client grant."}),...Ps.shape,created_at:o.z.string().optional(),updated_at:o.z.string().optional()}),jw=o.z.array(ar),wi=o.z.object({x:o.z.number(),y:o.z.number()});var mu=(t=>(t.RICH_TEXT="RICH_TEXT",t.NEXT_BUTTON="NEXT_BUTTON",t.BACK_BUTTON="BACK_BUTTON",t.SUBMIT_BUTTON="SUBMIT_BUTTON",t.DIVIDER="DIVIDER",t.TEXT="TEXT",t.EMAIL="EMAIL",t.PASSWORD="PASSWORD",t.NUMBER="NUMBER",t.PHONE="PHONE",t.DATE="DATE",t.CHECKBOX="CHECKBOX",t.RADIO="RADIO",t.SELECT="SELECT",t.HIDDEN="HIDDEN",t.LEGAL="LEGAL",t))(mu||{}),_u=(t=>(t.BLOCK="BLOCK",t.FIELD="FIELD",t))(_u||{});const Ta=o.z.object({id:o.z.string(),category:o.z.nativeEnum(_u),type:o.z.nativeEnum(mu)}),y0=Ta.extend({category:o.z.literal("BLOCK"),type:o.z.literal("RICH_TEXT"),config:o.z.object({content:o.z.string()}).passthrough()}),w0=Ta.extend({category:o.z.literal("BLOCK"),type:o.z.union([o.z.literal("NEXT_BUTTON"),o.z.literal("BACK_BUTTON"),o.z.literal("SUBMIT_BUTTON")]),config:o.z.object({text:o.z.string()}).passthrough()}),v0=Ta.extend({category:o.z.literal("FIELD"),type:o.z.literal("LEGAL"),required:o.z.boolean().optional(),sensitive:o.z.boolean().optional(),config:o.z.object({text:o.z.string()}).passthrough()}),b0=Ta.extend({category:o.z.literal("FIELD"),type:o.z.union([o.z.literal("TEXT"),o.z.literal("EMAIL"),o.z.literal("PASSWORD"),o.z.literal("NUMBER"),o.z.literal("PHONE"),o.z.literal("DATE"),o.z.literal("CHECKBOX"),o.z.literal("RADIO"),o.z.literal("SELECT"),o.z.literal("HIDDEN")]),required:o.z.boolean().optional(),sensitive:o.z.boolean().optional(),config:o.z.object({label:o.z.string().optional(),placeholder:o.z.string().optional()}).passthrough()}),$0=o.z.object({id:o.z.string(),category:o.z.string(),type:o.z.string()}).passthrough(),k0=o.z.union([y0,w0,v0,b0,$0]);var x0=(t=>(t.STEP="STEP",t.FLOW="FLOW",t.CONDITION="CONDITION",t.ACTION="ACTION",t))(x0||{});const S0=o.z.object({id:o.z.string(),type:o.z.literal("STEP"),coordinates:wi,alias:o.z.string().optional(),config:o.z.object({components:o.z.array(k0),next_node:o.z.string()}).passthrough()}),z0=o.z.object({id:o.z.string(),type:o.z.literal("FLOW"),coordinates:wi,alias:o.z.string().optional(),config:o.z.object({flow_id:o.z.string(),next_node:o.z.string()})}),A0=o.z.object({id:o.z.string(),type:o.z.string(),coordinates:wi}).passthrough(),E0=o.z.union([S0,z0,A0]),C0=o.z.object({next_node:o.z.string(),coordinates:wi}).passthrough(),N0=o.z.object({resume_flow:o.z.boolean().optional(),coordinates:wi}).passthrough(),I0=o.z.object({id:o.z.string(),name:o.z.string(),languages:o.z.object({primary:o.z.string()}).passthrough(),nodes:o.z.array(E0),start:C0,ending:N0,created_at:o.z.string(),updated_at:o.z.string(),links:o.z.object({sdkSrc:o.z.string().optional(),sdk_src:o.z.string().optional()}).passthrough()}).passthrough(),Ow=I0.omit({id:!0,created_at:!0,updated_at:!0});var Bt=(t=>(t.TOKEN="token",t.TOKEN_ID_TOKEN="token id_token",t.CODE="code",t))(Bt||{}),ln=(t=>(t.QUERY="query",t.FRAGMENT="fragment",t.FORM_POST="form_post",t.WEB_MESSAGE="web_message",t.SAML_POST="saml_post",t))(ln||{}),Pa=(t=>(t.S256="S256",t.Plain="plain",t))(Pa||{});const ro=o.z.object({client_id:o.z.string(),act_as:o.z.string().optional(),response_type:o.z.nativeEnum(Bt).optional(),response_mode:o.z.nativeEnum(ln).optional(),redirect_uri:o.z.string().optional(),audience:o.z.string().optional(),organization:o.z.string().optional(),state:o.z.string().optional(),nonce:o.z.string().optional(),scope:o.z.string().optional(),prompt:o.z.string().optional(),code_challenge_method:o.z.nativeEnum(Pa).optional(),code_challenge:o.z.string().optional(),username:o.z.string().optional(),ui_locales:o.z.string().optional(),vendor_id:o.z.string().optional()}),kl=o.z.object({colors:o.z.object({primary:o.z.string(),page_background:o.z.object({type:o.z.string().optional(),start:o.z.string().optional(),end:o.z.string().optional(),angle_deg:o.z.number().optional()}).optional()}).optional(),logo_url:o.z.string().optional(),favicon_url:o.z.string().optional(),powered_by_logo_url:o.z.string().optional(),font:o.z.object({url:o.z.string()}).optional()}),Wr=o.z.object({kid:o.z.string().optional(),team_id:o.z.string().optional(),realms:o.z.string().optional(),authentication_method:o.z.string().optional(),client_id:o.z.string().optional(),client_secret:o.z.string().optional(),app_secret:o.z.string().optional(),scope:o.z.string().optional(),authorization_endpoint:o.z.string().optional(),token_endpoint:o.z.string().optional(),userinfo_endpoint:o.z.string().optional(),jwks_uri:o.z.string().optional(),discovery_url:o.z.string().optional(),issuer:o.z.string().optional(),provider:o.z.string().optional(),from:o.z.string().optional(),twilio_sid:o.z.string().optional(),twilio_token:o.z.string().optional()}),Rs=o.z.object({id:o.z.string().optional(),name:o.z.string(),strategy:o.z.string(),options:Wr.default({}),enabled_clients:o.z.array(o.z.string()).default([]).optional(),response_type:o.z.custom().optional(),response_mode:o.z.custom().optional()}),Kt=o.z.object({id:o.z.string(),created_at:o.z.string().transform(t=>t===null?"":t),updated_at:o.z.string().transform(t=>t===null?"":t)}).extend(Rs.shape),Ki=o.z.object({id:o.z.string().optional(),audience:o.z.string(),friendly_name:o.z.string(),picture_url:o.z.string().optional(),support_email:o.z.string().optional(),support_url:o.z.string().optional(),sender_email:o.z.string().email(),sender_name:o.z.string(),session_lifetime:o.z.number().optional(),idle_session_lifetime:o.z.number().optional(),ephemeral_session_lifetime:o.z.number().optional(),idle_ephemeral_session_lifetime:o.z.number().optional(),session_cookie:o.z.object({mode:o.z.enum(["persistent","non-persistent"]).optional()}).optional(),allowed_logout_urls:o.z.array(o.z.string()).optional(),default_redirection_uri:o.z.string().optional(),enabled_locales:o.z.array(o.z.string()).optional(),default_directory:o.z.string().optional(),error_page:o.z.object({html:o.z.string().optional(),show_log_link:o.z.boolean().optional(),url:o.z.string().optional()}).optional(),flags:o.z.object({allow_changing_enable_sso:o.z.boolean().optional(),allow_legacy_delegation_grant_types:o.z.boolean().optional(),allow_legacy_ro_grant_types:o.z.boolean().optional(),allow_legacy_tokeninfo_endpoint:o.z.boolean().optional(),change_pwd_flow_v1:o.z.boolean().optional(),custom_domains_provisioning:o.z.boolean().optional(),dashboard_insights_view:o.z.boolean().optional(),dashboard_log_streams_next:o.z.boolean().optional(),disable_clickjack_protection_headers:o.z.boolean().optional(),disable_fields_map_fix:o.z.boolean().optional(),disable_impersonation:o.z.boolean().optional(),disable_management_api_sms_obfuscation:o.z.boolean().optional(),enable_adfs_waad_email_verification:o.z.boolean().optional(),enable_apis_section:o.z.boolean().optional(),enable_client_connections:o.z.boolean().optional(),enable_custom_domain_in_emails:o.z.boolean().optional(),enable_dynamic_client_registration:o.z.boolean().optional(),enable_idtoken_api2:o.z.boolean().optional(),enable_legacy_logs_search_v2:o.z.boolean().optional(),enable_legacy_profile:o.z.boolean().optional(),enable_pipeline2:o.z.boolean().optional(),enable_public_signup_user_exists_error:o.z.boolean().optional(),enable_sso:o.z.boolean().optional(),enforce_client_authentication_on_passwordless_start:o.z.boolean().optional(),genai_trial:o.z.boolean().optional(),improved_signup_bot_detection_in_classic:o.z.boolean().optional(),mfa_show_factor_list_on_enrollment:o.z.boolean().optional(),no_disclose_enterprise_connections:o.z.boolean().optional(),remove_alg_from_jwks:o.z.boolean().optional(),revoke_refresh_token_grant:o.z.boolean().optional(),trust_azure_adfs_email_verified_connection_property:o.z.boolean().optional(),use_scope_descriptions_for_consent:o.z.boolean().optional()}).optional(),sandbox_version:o.z.string().optional(),legacy_sandbox_version:o.z.string().optional(),sandbox_versions_available:o.z.array(o.z.string()).optional(),change_password:o.z.object({enabled:o.z.boolean().optional(),html:o.z.string().optional()}).optional(),guardian_mfa_page:o.z.object({enabled:o.z.boolean().optional(),html:o.z.string().optional()}).optional(),device_flow:o.z.object({charset:o.z.enum(["base20","digits"]).optional(),mask:o.z.string().max(20).optional()}).optional(),default_token_quota:o.z.object({clients:o.z.object({client_credentials:o.z.record(o.z.any()).optional()}).optional(),organizations:o.z.object({client_credentials:o.z.record(o.z.any()).optional()}).optional()}).optional(),default_audience:o.z.string().optional(),default_organization:o.z.string().optional(),sessions:o.z.object({oidc_logout_prompt_enabled:o.z.boolean().optional()}).optional(),oidc_logout:o.z.object({rp_logout_end_session_endpoint_discovery:o.z.boolean().optional()}).optional(),allow_organization_name_in_authentication_api:o.z.boolean().optional(),customize_mfa_in_postlogin_action:o.z.boolean().optional(),acr_values_supported:o.z.array(o.z.string()).optional(),mtls:o.z.object({enable_endpoint_aliases:o.z.boolean().optional()}).optional(),pushed_authorization_requests_supported:o.z.boolean().optional(),authorization_response_iss_parameter_supported:o.z.boolean().optional()}),Un=o.z.object({created_at:o.z.string().nullable().transform(t=>t??""),updated_at:o.z.string().nullable().transform(t=>t??""),...Ki.shape,id:o.z.string()});o.z.object({...sr.shape,tenant:Un,connections:o.z.array(Kt)});const j0=o.z.enum(["password_reset","email_verification","otp","authorization_code","oauth2_state","ticket"]),O0=o.z.object({code_id:o.z.string().openapi({description:"The code that will be used in for instance an email verification flow"}),login_id:o.z.string().openapi({description:"The id of the login session that the code is connected to"}),connection_id:o.z.string().optional().openapi({description:"The connection that the code is connected to"}),code_type:j0,code_verifier:o.z.string().optional().openapi({description:"The code verifier used in PKCE in outbound flows"}),code_challenge:o.z.string().optional().openapi({description:"The code challenge used in PKCE in outbound flows"}),code_challenge_method:o.z.enum(["plain","S256"]).optional().openapi({description:"The code challenge method used in PKCE in outbound flows"}),redirect_uri:o.z.string().optional().openapi({description:"The redirect URI associated with the code"}),nonce:o.z.string().optional().openapi({description:"The nonce value used for security in OIDC flows"}),state:o.z.string().optional().openapi({description:"The state parameter used for CSRF protection in OAuth flows"}),expires_at:o.z.string(),used_at:o.z.string().optional(),user_id:o.z.string().optional()}),Tw=o.z.object({...O0.shape,created_at:o.z.string()}),yu=o.z.object({domain:o.z.string(),custom_domain_id:o.z.string().optional(),type:o.z.enum(["auth0_managed_certs","self_managed_certs"]),verification_method:o.z.enum(["txt"]).optional(),tls_policy:o.z.enum(["recommended"]).optional(),custom_client_ip_header:o.z.enum(["true-client-ip","cf-connecting-ip","x-forwarded-for","x-azure-clientip","null"]).optional(),domain_metadata:o.z.record(o.z.string().max(255)).optional()}),T0=o.z.object({name:o.z.literal("txt"),record:o.z.string(),domain:o.z.string()}),Ln=o.z.object({...yu.shape,custom_domain_id:o.z.string(),primary:o.z.boolean(),status:o.z.enum(["disabled","pending","pending_verification","ready"]),origin_domain_name:o.z.string().optional(),verification:o.z.object({methods:o.z.array(T0)}).optional(),tls_policy:o.z.string().optional()}),Pw=Ln.extend({tenant_id:o.z.string()}),Rw=o.z.object({id:o.z.string(),type:o.z.literal("submit"),label:o.z.string(),className:o.z.string().optional(),disabled:o.z.boolean().optional().default(!1),order:o.z.number().optional(),visible:o.z.boolean().optional().default(!0),customizations:o.z.record(o.z.string(),o.z.any()).optional()}),P0=o.z.discriminatedUnion("type",[o.z.object({id:o.z.string(),type:o.z.literal("RICH_TEXT"),config:o.z.object({content:o.z.string()}),order:o.z.number().optional(),visible:o.z.boolean().optional().default(!0)}),o.z.object({id:o.z.string(),type:o.z.literal("LEGAL"),config:o.z.object({text:o.z.string(),html:o.z.boolean().optional()}),required:o.z.boolean().optional(),order:o.z.number().optional(),visible:o.z.boolean().optional().default(!0)}),o.z.object({id:o.z.string(),type:o.z.literal("TEXT"),config:o.z.object({placeholder:o.z.string().optional(),multiline:o.z.boolean().optional()}),required:o.z.boolean().optional(),sensitive:o.z.boolean().optional(),order:o.z.number().optional(),visible:o.z.boolean().optional().default(!0)}),o.z.object({id:o.z.string(),type:o.z.literal("NEXT_BUTTON"),config:o.z.object({text:o.z.string().optional()}),order:o.z.number().optional(),visible:o.z.boolean().optional().default(!0)})]),Bs=o.z.object({name:o.z.string().openapi({description:"The name of the form"}),messages:o.z.object({errors:o.z.record(o.z.string(),o.z.any()).optional(),custom:o.z.record(o.z.string(),o.z.any()).optional()}).optional(),languages:o.z.object({primary:o.z.string().optional(),default:o.z.string().optional()}).optional(),translations:o.z.record(o.z.string(),o.z.any()).optional(),nodes:o.z.array(o.z.discriminatedUnion("type",[o.z.object({id:o.z.string(),type:o.z.literal("FLOW"),coordinates:o.z.object({x:o.z.number(),y:o.z.number()}),alias:o.z.string().min(1).max(150).optional(),config:o.z.object({flow_id:o.z.string().max(30),next_node:o.z.string()})}),o.z.object({id:o.z.string(),type:o.z.literal("ROUTER"),coordinates:o.z.object({x:o.z.number(),y:o.z.number()}),alias:o.z.string().min(1).max(150),config:o.z.object({rules:o.z.array(o.z.object({id:o.z.string(),alias:o.z.string().min(1).max(150).optional(),condition:o.z.any(),next_node:o.z.string()})),fallback:o.z.array(o.z.string())})}),o.z.object({id:o.z.string(),type:o.z.literal("STEP"),coordinates:o.z.object({x:o.z.number(),y:o.z.number()}),alias:o.z.string().min(1).max(150).optional(),config:o.z.object({components:o.z.array(P0),next_node:o.z.string()})})])).optional(),start:o.z.object({hidden_fields:o.z.array(o.z.object({key:o.z.string(),value:o.z.string()})).optional(),next_node:o.z.string().optional(),coordinates:o.z.object({x:o.z.number(),y:o.z.number()}).optional()}).optional(),ending:o.z.object({redirection:o.z.object({delay:o.z.number().optional(),target:o.z.string().optional()}).optional(),after_submit:o.z.object({flow_id:o.z.string().optional()}).optional(),coordinates:o.z.object({x:o.z.number(),y:o.z.number()}).optional(),resume_flow:o.z.boolean().optional()}).optional(),style:o.z.object({css:o.z.string().optional()}).optional()}).openapi({description:"Schema for flow-based forms (matches new JSON structure)"}),Vr=o.z.object({...yi.shape,...Bs.shape,id:o.z.string()}),R0=o.z.enum(["pre-user-signup","post-user-registration","post-user-login"]),B0=o.z.enum(["pre-user-signup","post-user-registration","post-user-login"]),Ra={enabled:o.z.boolean().default(!1),synchronous:o.z.boolean().default(!1),priority:o.z.number().optional(),hook_id:o.z.string().optional()},Bw=o.z.object({...Ra,trigger_id:R0,url:o.z.string()}),Lw=o.z.object({...Ra,trigger_id:B0,form_id:o.z.string()}),ds=o.z.union([Bw,Lw]),Uw=o.z.object({...Ra,trigger_id:R0,...yi.shape,hook_id:o.z.string(),url:o.z.string()}),Dw=o.z.object({...Ra,trigger_id:B0,...yi.shape,hook_id:o.z.string(),form_id:o.z.string()}),Kr=o.z.union([Uw,Dw]),L0=o.z.object({name:o.z.string().optional()}),U0=o.z.object({email:o.z.string().optional()}),wu=o.z.object({organization_id:o.z.string().max(50),inviter:L0,invitee:U0,invitation_url:o.z.string().url(),client_id:o.z.string(),connection_id:o.z.string().optional(),app_metadata:o.z.record(o.z.any()).default({}).optional(),user_metadata:o.z.record(o.z.any()).default({}).optional(),ttl_sec:o.z.number().int().max(2592e3).default(604800).optional(),roles:o.z.array(o.z.string()).default([]).optional(),send_invitation_email:o.z.boolean().default(!0).optional()}),Gi=o.z.object({id:o.z.string(),organization_id:o.z.string().max(50),created_at:o.z.string().datetime(),expires_at:o.z.string().datetime(),ticket_id:o.z.string().optional()}).extend(wu.shape),vu=o.z.object({alg:o.z.enum(["RS256","RS384","RS512","ES256","ES384","ES512","HS256","HS384","HS512"]),e:o.z.string(),kid:o.z.string(),kty:o.z.enum(["RSA","EC","oct"]),n:o.z.string(),x5t:o.z.string().optional(),x5c:o.z.array(o.z.string()).optional(),use:o.z.enum(["sig","enc"]).optional()}),D0=o.z.object({keys:o.z.array(vu)}),xl=o.z.object({issuer:o.z.string(),authorization_endpoint:o.z.string(),token_endpoint:o.z.string(),device_authorization_endpoint:o.z.string(),userinfo_endpoint:o.z.string(),mfa_challenge_endpoint:o.z.string(),jwks_uri:o.z.string(),registration_endpoint:o.z.string(),revocation_endpoint:o.z.string(),scopes_supported:o.z.array(o.z.string()),response_types_supported:o.z.array(o.z.string()),code_challenge_methods_supported:o.z.array(o.z.string()),response_modes_supported:o.z.array(o.z.string()),subject_types_supported:o.z.array(o.z.string()),id_token_signing_alg_values_supported:o.z.array(o.z.string()),token_endpoint_auth_methods_supported:o.z.array(o.z.string()),claims_supported:o.z.array(o.z.string()),request_uri_parameter_supported:o.z.boolean(),request_parameter_supported:o.z.boolean(),token_endpoint_auth_signing_alg_values_supported:o.z.array(o.z.string())}),M0=o.z.object({csrf_token:o.z.string(),auth0Client:o.z.string().optional(),authParams:ro,expires_at:o.z.string(),deleted_at:o.z.string().optional(),ip:o.z.string().optional(),useragent:o.z.string().optional(),session_id:o.z.string().optional(),authorization_url:o.z.string().optional(),login_completed:o.z.boolean().optional().default(!1)}).openapi({description:"This represents a login sesion"}),Mw=o.z.object({...M0.shape,id:o.z.string().openapi({description:"This is is used as the state in the universal login"}),created_at:o.z.string(),updated_at:o.z.string()}),_e={ACLS_SUMMARY:"acls_summary",ACTIONS_EXECUTION_FAILED:"actions_execution_failed",API_LIMIT:"api_limit",API_LIMIT_WARNING:"api_limit_warning",APPI:"appi",CIBA_EXCHANGE_FAILED:"ciba_exchange_failed",CIBA_EXCHANGE_SUCCEEDED:"ciba_exchange_succeeded",CIBA_START_FAILED:"ciba_start_failed",CIBA_START_SUCCEEDED:"ciba_start_succeeded",CODE_LINK_SENT:"cls",CODE_SENT:"cs",DEPRECATION_NOTICE:"depnote",FAILED_LOGIN:"f",FAILED_BY_CONNECTOR:"fc",FAILED_CHANGE_EMAIL:"fce",FAILED_BY_CORS:"fco",FAILED_CROSS_ORIGIN_AUTHENTICATION:"fcoa",FAILED_CHANGE_PASSWORD:"fcp",FAILED_POST_CHANGE_PASSWORD_HOOK:"fcph",FAILED_CHANGE_PHONE_NUMBER:"fcpn",FAILED_CHANGE_PASSWORD_REQUEST:"fcpr",FAILED_CONNECTOR_PROVISIONING:"fcpro",FAILED_CHANGE_USERNAME:"fcu",FAILED_DELEGATION:"fd",FAILED_DEVICE_ACTIVATION:"fdeac",FAILED_DEVICE_AUTHORIZATION_REQUEST:"fdeaz",USER_CANCELED_DEVICE_CONFIRMATION:"fdecc",FAILED_USER_DELETION:"fdu",FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN:"feacft",FAILED_EXCHANGE_ACCESS_TOKEN_FOR_CLIENT_CREDENTIALS:"feccft",FAILED_EXCHANGE_CUSTOM_TOKEN:"fecte",FAILED_EXCHANGE_DEVICE_CODE_FOR_ACCESS_TOKEN:"fede",FAILED_FEDERATED_LOGOUT:"federated_logout_failed",FAILED_EXCHANGE_NATIVE_SOCIAL_LOGIN:"fens",FAILED_EXCHANGE_PASSWORD_OOB_FOR_ACCESS_TOKEN:"feoobft",FAILED_EXCHANGE_PASSWORD_OTP_FOR_ACCESS_TOKEN:"feotpft",FAILED_EXCHANGE_PASSWORD_FOR_ACCESS_TOKEN:"fepft",FAILED_EXCHANGE_PASSWORDLESS_OTP_FOR_ACCESS_TOKEN:"fepotpft",FAILED_EXCHANGE_PASSWORD_MFA_RECOVERY_FOR_ACCESS_TOKEN:"fercft",FAILED_EXCHANGE_ROTATING_REFRESH_TOKEN:"ferrt",FAILED_EXCHANGE_REFRESH_TOKEN_FOR_ACCESS_TOKEN:"fertft",FAILED_HOOK:"fh",FAILED_INVITE_ACCEPT:"fi",FAILED_LOGOUT:"flo",FLOWS_EXECUTION_COMPLETED:"flows_execution_completed",FLOWS_EXECUTION_FAILED:"flows_execution_failed",FAILED_SENDING_NOTIFICATION:"fn",FORMS_SUBMISSION_FAILED:"forms_submission_failed",FORMS_SUBMISSION_SUCCEEDED:"forms_submission_succeeded",FAILED_LOGIN_INCORRECT_PASSWORD:"fp",FAILED_PUSHED_AUTHORIZATION_REQUEST:"fpar",FAILED_POST_USER_REGISTRATION_HOOK:"fpurh",FAILED_SIGNUP:"fs",FAILED_SILENT_AUTH:"fsa",FAILED_LOGIN_INVALID_EMAIL_USERNAME:"fu",FAILED_USERS_IMPORT:"fui",FAILED_VERIFICATION_EMAIL:"fv",FAILED_VERIFICATION_EMAIL_REQUEST:"fvr",EMAIL_VERIFICATION_CONFIRMED:"gd_auth_email_verification",EMAIL_VERIFICATION_FAILED:"gd_auth_fail_email_verification",MFA_AUTH_FAILED:"gd_auth_failed",MFA_AUTH_REJECTED:"gd_auth_rejected",MFA_AUTH_SUCCESS:"gd_auth_succeed",MFA_ENROLLMENT_COMPLETE:"gd_enrollment_complete",TOO_MANY_MFA_FAILURES:"gd_otp_rate_limit_exceed",MFA_RECOVERY_FAILED:"gd_recovery_failed",MFA_RECOVERY_RATE_LIMIT_EXCEED:"gd_recovery_rate_limit_exceed",MFA_RECOVERY_SUCCESS:"gd_recovery_succeed",MFA_EMAIL_SENT:"gd_send_email",EMAIL_VERIFICATION_SENT:"gd_send_email_verification",EMAIL_VERIFICATION_SEND_FAILURE:"gd_send_email_verification_failure",PUSH_NOTIFICATION_SENT:"gd_send_pn",ERROR_SENDING_MFA_PUSH_NOTIFICATION:"gd_send_pn_failure",MFA_SMS_SENT:"gd_send_sms",ERROR_SENDING_MFA_SMS:"gd_send_sms_failure",MFA_VOICE_CALL_SUCCESS:"gd_send_voice",MFA_VOICE_CALL_FAILED:"gd_send_voice_failure",SECOND_FACTOR_STARTED:"gd_start_auth",MFA_ENROLL_STARTED:"gd_start_enroll",MFA_ENROLLMENT_FAILED:"gd_start_enroll_failed",GUARDIAN_TENANT_UPDATE:"gd_tenant_update",UNENROLL_DEVICE_ACCOUNT:"gd_unenroll",UPDATE_DEVICE_ACCOUNT:"gd_update_device_account",WEBAUTHN_CHALLENGE_FAILED:"gd_webauthn_challenge_failed",WEBAUTHN_ENROLLMENT_FAILED:"gd_webauthn_enrollment_failed",FAILED_KMS_API_OPERATION:"kms_key_management_failure",SUCCESS_KMS_API_OPERATION:"kms_key_management_success",KMS_KEY_STATE_CHANGED:"kms_key_state_changed",TOO_MANY_CALLS_TO_DELEGATION:"limit_delegation",BLOCKED_IP_ADDRESS:"limit_mu",BLOCKED_ACCOUNT_IP:"limit_sul",BLOCKED_ACCOUNT_EMAIL:"limit_wc",MFA_REQUIRED:"mfar",MANAGEMENT_API_READ_OPERATION:"mgmt_api_read",FAILED_AUTHENTICATION_METHOD_OPERATION_MY_ACCOUNT:"my_account_authentication_method_failed",SUCCESSFUL_AUTHENTICATION_METHOD_OPERATION_MY_ACCOUNT:"my_account_authentication_method_succeeded",FAILED_OIDC_BACKCHANNEL_LOGOUT:"oidc_backchannel_logout_failed",SUCCESSFUL_OIDC_BACKCHANNEL_LOGOUT:"oidc_backchannel_logout_succeeded",ORGANIZATION_MEMBER_ADDED:"organization_member_added",PASSKEY_CHALLENGE_FAILED:"passkey_challenge_failed",PASSKEY_CHALLENGE_STARTED:"passkey_challenge_started",PRE_LOGIN_ASSESSMENT:"pla",BREACHED_PASSWORD:"pwd_leak",BREACHED_PASSWORD_ON_RESET:"reset_pwd_leak",SUCCESS_RESOURCE_CLEANUP:"resource_cleanup",RICH_CONSENTS_ACCESS_ERROR:"rich_consents_access_error",SUCCESS_LOGIN:"s",SUCCESS_API_OPERATION:"sapi",SUCCESS_CHANGE_EMAIL:"sce",SUCCESS_CROSS_ORIGIN_AUTHENTICATION:"scoa",SUCCESS_CHANGE_PASSWORD:"scp",SUCCESS_CHANGE_PHONE_NUMBER:"scpn",SUCCESS_CHANGE_PASSWORD_REQUEST:"scpr",SUCCESS_CHANGE_USERNAME:"scu",SUCCESS_CREDENTIAL_VALIDATION:"scv",SUCCESS_DELEGATION:"sd",SUCCESS_USER_DELETION:"sdu",SUCCESS_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN:"seacft",SUCCESS_EXCHANGE_ACCESS_TOKEN_FOR_CLIENT_CREDENTIALS:"seccft",SUCCESS_EXCHANGE_CUSTOM_TOKEN:"secte",SUCCESS_EXCHANGE_DEVICE_CODE_FOR_ACCESS_TOKEN:"sede",SUCCESS_EXCHANGE_NATIVE_SOCIAL_LOGIN:"sens",SUCCESS_EXCHANGE_PASSWORD_OOB_FOR_ACCESS_TOKEN:"seoobft",SUCCESS_EXCHANGE_PASSWORD_OTP_FOR_ACCESS_TOKEN:"seotpft",SUCCESS_EXCHANGE_PASSWORD_FOR_ACCESS_TOKEN:"sepft",SUCCESS_EXCHANGE_PASSKEY_OOB_FOR_ACCESS_TOKEN:"sepkoobft",SUCCESS_EXCHANGE_PASSKEY_OTP_FOR_ACCESS_TOKEN:"sepkotpft",SUCCESS_EXCHANGE_PASSKEY_MFA_RECOVERY_FOR_ACCESS_TOKEN:"sepkrcft",SUCCESS_EXCHANGE_PASSWORD_MFA_RECOVERY_FOR_ACCESS_TOKEN:"sercft",SUCCESS_EXCHANGE_REFRESH_TOKEN_FOR_ACCESS_TOKEN:"sertft",SUCCESSFULLY_ACCEPTED_USER_INVITE:"si",BREACHED_PASSWORD_ON_SIGNUP:"signup_pwd_leak",SUCCESS_LOGOUT:"slo",SUCCESS_REVOCATION:"srrt",SUCCESS_SIGNUP:"ss",FAILED_SS_SSO_OPERATION:"ss_sso_failure",INFORMATION_FROM_SS_SSO_OPERATION:"ss_sso_info",SUCCESS_SS_SSO_OPERATION:"ss_sso_success",SUCCESS_SILENT_AUTH:"ssa",SUCCESSFUL_SCIM_OPERATION:"sscim",SUCCESSFULLY_IMPORTED_USERS:"sui",SUCCESS_VERIFICATION_EMAIL:"sv",SUCCESS_VERIFICATION_EMAIL_REQUEST:"svr",MAX_AMOUNT_OF_AUTHENTICATORS:"too_many_records",USER_LOGIN_BLOCK_RELEASED:"ublkdu",FAILED_UNIVERSAL_LOGOUT:"universal_logout_failed",SUCCESSFUL_UNIVERSAL_LOGOUT:"universal_logout_succeeded",WARNING_DURING_LOGIN:"w",WARNING_SENDING_NOTIFICATION:"wn",WARNING_USER_MANAGEMENT:"wum"},Fw=o.z.string().refine(t=>Object.values(_e).includes(t),{message:"Invalid log type"}),F0=o.z.object({name:o.z.string(),version:o.z.string(),env:o.z.object({node:o.z.string().optional()}).optional()}),Ls=o.z.object({type:Fw,date:o.z.string(),description:o.z.string().optional(),log_id:o.z.string().optional(),_id:o.z.string().optional(),ip:o.z.string(),user_agent:o.z.string(),details:o.z.any().optional(),isMobile:o.z.boolean(),user_id:o.z.string().optional(),user_name:o.z.string().optional(),connection:o.z.string().optional(),connection_id:o.z.string().optional(),client_id:o.z.string().optional(),client_name:o.z.string().optional(),audience:o.z.string().optional(),scope:o.z.array(o.z.string()).optional(),strategy:o.z.string().optional(),strategy_type:o.z.string().optional(),hostname:o.z.string().optional(),auth0_client:F0.optional()}),q0=o.z.object({user_id:o.z.string(),password:o.z.string(),algorithm:o.z.enum(["bcrypt","argon2id"]).default("argon2id")}),qw=o.z.object({...q0.shape,created_at:o.z.string(),updated_at:o.z.string()}),H0=o.z.object({initial_user_agent:o.z.string().describe("First user agent of the device from which this user logged in"),initial_ip:o.z.string().describe("First IP address associated with this session"),initial_asn:o.z.string().describe("First autonomous system number associated with this session"),last_user_agent:o.z.string().describe("Last user agent of the device from which this user logged in"),last_ip:o.z.string().describe("Last IP address from which this user logged in"),last_asn:o.z.string().describe("Last autonomous system number from which this user logged in")}),V0=o.z.object({id:o.z.string(),revoked_at:o.z.string().optional(),used_at:o.z.string().optional(),user_id:o.z.string().describe("The user ID associated with the session"),expires_at:o.z.string().optional(),login_session_id:o.z.string(),idle_expires_at:o.z.string().optional(),device:H0.describe("Metadata related to the device used in the session"),clients:o.z.array(o.z.string()).describe("List of client details for the session")}),Ba=o.z.object({created_at:o.z.string(),updated_at:o.z.string(),authenticated_at:o.z.string(),last_interaction_at:o.z.string(),...V0.shape}),Sl=o.z.object({kid:o.z.string().openapi({description:"The key id of the signing key"}),cert:o.z.string().openapi({description:"The public certificate of the signing key"}),fingerprint:o.z.string().openapi({description:"The cert fingerprint"}),thumbprint:o.z.string().openapi({description:"The cert thumbprint"}),pkcs7:o.z.string().optional().openapi({description:"The private key in pkcs7 format"}),current:o.z.boolean().optional().openapi({description:"True if the key is the current key"}),next:o.z.boolean().optional().openapi({description:"True if the key is the next key"}),previous:o.z.boolean().optional().openapi({description:"True if the key is the previous key"}),current_since:o.z.string().optional().openapi({description:"The date and time when the key became the current key"}),current_until:o.z.string().optional().openapi({description:"The date and time when the current key was rotated"}),revoked:o.z.boolean().optional().openapi({description:"True if the key is revoked"}),revoked_at:o.z.string().optional().openapi({description:"The date and time when the key was revoked"}),connection:o.z.string().optional().openapi({description:"The connection identifier associated with the key"}),type:o.z.enum(["jwt_signing","saml_encryption"]).openapi({description:"The type of the signing key"})});var Vt=(t=>(t.RefreshToken="refresh_token",t.AuthorizationCode="authorization_code",t.ClientCredential="client_credentials",t.Passwordless="passwordless",t.Password="password",t.OTP="http://auth0.com/oauth/grant-type/passwordless/otp",t))(Vt||{});const bu=o.z.object({access_token:o.z.string(),id_token:o.z.string().optional(),scope:o.z.string().optional(),state:o.z.string().optional(),refresh_token:o.z.string().optional(),token_type:o.z.string(),expires_in:o.z.number()});o.z.object({code:o.z.string(),state:o.z.string().optional()});const K0=o.z.object({button_border_radius:o.z.number(),button_border_weight:o.z.number(),buttons_style:o.z.enum(["pill","rounded","sharp"]),input_border_radius:o.z.number(),input_border_weight:o.z.number(),inputs_style:o.z.enum(["pill","rounded","sharp"]),show_widget_shadow:o.z.boolean(),widget_border_weight:o.z.number(),widget_corner_radius:o.z.number()}),G0=o.z.object({base_focus_color:o.z.string(),base_hover_color:o.z.string(),body_text:o.z.string(),captcha_widget_theme:o.z.enum(["auto","dark","light"]),error:o.z.string(),header:o.z.string(),icons:o.z.string(),input_background:o.z.string(),input_border:o.z.string(),input_filled_text:o.z.string(),input_labels_placeholders:o.z.string(),links_focused_components:o.z.string(),primary_button:o.z.string(),primary_button_label:o.z.string(),secondary_button_border:o.z.string(),secondary_button_label:o.z.string(),success:o.z.string(),widget_background:o.z.string(),widget_border:o.z.string()}),rr=o.z.object({bold:o.z.boolean(),size:o.z.number()}),W0=o.z.object({body_text:rr,buttons_text:rr,font_url:o.z.string(),input_labels:rr,links:rr,links_style:o.z.enum(["normal","underlined"]),reference_text_size:o.z.number(),subtitle:rr,title:rr}),J0=o.z.object({background_color:o.z.string(),background_image_url:o.z.string(),page_layout:o.z.enum(["center","left","right"])}),X0=o.z.object({header_text_alignment:o.z.enum(["center","left","right"]),logo_height:o.z.number(),logo_position:o.z.enum(["center","left","none","right"]),logo_url:o.z.string(),social_buttons_layout:o.z.enum(["bottom","top"])}),Z0=o.z.object({borders:K0,colors:G0,displayName:o.z.string(),fonts:W0,page_background:J0,widget:X0}),us=Z0.extend({themeId:o.z.string()}),ps=o.z.object({universal_login_experience:o.z.enum(["new","classic"]).default("new"),identifier_first:o.z.boolean().default(!0),password_first:o.z.boolean().default(!1),webauthn_platform_first_factor:o.z.boolean()}),fs=o.z.object({name:o.z.string(),enabled:o.z.boolean().optional().default(!0),default_from_address:o.z.string().optional(),credentials:o.z.union([o.z.object({accessKeyId:o.z.string(),secretAccessKey:o.z.string(),region:o.z.string()}),o.z.object({smtp_host:o.z.array(o.z.string()),smtp_port:o.z.number(),smtp_user:o.z.string(),smtp_pass:o.z.string()}),o.z.object({api_key:o.z.string(),domain:o.z.string().optional()}),o.z.object({connectionString:o.z.string()}),o.z.object({tenantId:o.z.string(),clientId:o.z.string(),clientSecret:o.z.string()})]),settings:o.z.object({}).optional()}),$u=o.z.object({id:o.z.string(),session_id:o.z.string(),user_id:o.z.string(),client_id:o.z.string(),expires_at:o.z.string().optional(),idle_expires_at:o.z.string().optional(),last_exchanged_at:o.z.string().optional(),device:H0,resource_servers:o.z.array(o.z.object({audience:o.z.string(),scopes:o.z.string()})),rotating:o.z.boolean()}),Hw=o.z.object({created_at:o.z.string(),...$u.shape}),Vw=o.z.object({to:o.z.string(),message:o.z.string()}),Kw=o.z.object({name:o.z.string(),options:o.z.object({})}),Y0=o.z.object({value:o.z.string(),description:o.z.string().optional()}),Q0=o.z.object({token_dialect:o.z.enum(["access_token","access_token_authz"]).optional(),enforce_policies:o.z.boolean().optional(),allow_skipping_userinfo:o.z.boolean().optional(),skip_userinfo:o.z.boolean().optional(),persist_client_authorization:o.z.boolean().optional(),enable_introspection_endpoint:o.z.boolean().optional(),mtls:o.z.object({bound_access_tokens:o.z.boolean().optional()}).optional()}),Us=o.z.object({name:o.z.string(),identifier:o.z.string(),scopes:o.z.array(Y0).optional(),signing_alg:o.z.string().optional(),signing_secret:o.z.string().optional(),token_lifetime:o.z.number().optional(),token_lifetime_for_web:o.z.number().optional(),skip_consent_for_verifiable_first_party_clients:o.z.boolean().optional(),allow_offline_access:o.z.boolean().optional(),verificationKey:o.z.string().optional(),options:Q0.optional()}),cr=o.z.object({id:o.z.string().optional(),...Us.shape,created_at:o.z.string().optional(),updated_at:o.z.string().optional()}),Gw=o.z.array(cr),em=o.z.object({role_id:o.z.string(),resource_server_identifier:o.z.string(),permission_name:o.z.string()}),tm=o.z.object({...em.shape,tenant_id:o.z.string(),created_at:o.z.string().optional()}),Ww=o.z.array(tm),nm=o.z.object({role_id:o.z.string(),resource_server_identifier:o.z.string(),resource_server_name:o.z.string(),permission_name:o.z.string(),description:o.z.string().nullable().optional(),created_at:o.z.string().optional()}),rm=o.z.array(nm),im=o.z.object({user_id:o.z.string(),resource_server_identifier:o.z.string(),permission_name:o.z.string(),organization_id:o.z.string().optional()}),om=o.z.object({...im.shape,tenant_id:o.z.string(),created_at:o.z.string().optional()}),Jw=o.z.array(om),sm=o.z.object({user_id:o.z.string(),resource_server_identifier:o.z.string(),resource_server_name:o.z.string(),permission_name:o.z.string(),description:o.z.string().nullable().optional(),created_at:o.z.string().optional(),organization_id:o.z.string().optional()}),am=o.z.array(sm),cm=o.z.object({user_id:o.z.string(),role_id:o.z.string(),organization_id:o.z.string().optional()}),lm=o.z.object({...cm.shape,tenant_id:o.z.string(),created_at:o.z.string().optional()}),Xw=o.z.array(lm),Ds=o.z.object({name:o.z.string().min(1).max(50).openapi({description:"The name of the role. Cannot include '<' or '>'"}),description:o.z.string().max(255).optional().openapi({description:"The description of the role"})}),lr=o.z.object({id:o.z.string().openapi({description:"The unique identifier of the role"}),...Ds.shape,created_at:o.z.string().optional(),updated_at:o.z.string().optional()}),Ms=o.z.array(lr),dm=o.z.object({logo_url:o.z.string().optional().openapi({description:"URL of the organization's logo"}),colors:o.z.object({primary:o.z.string().optional().openapi({description:"Primary color in hex format (e.g., #FF0000)"}),page_background:o.z.string().optional().openapi({description:"Page background color in hex format (e.g., #FFFFFF)"})}).optional()}).optional(),um=o.z.object({connection_id:o.z.string().openapi({description:"ID of the connection"}),assign_membership_on_login:o.z.boolean().default(!1).openapi({description:"Whether to assign membership to the organization on login"}),show_as_button:o.z.boolean().default(!0).openapi({description:"Whether to show this connection as a button in the login screen"}),is_signup_enabled:o.z.boolean().default(!0).openapi({description:"Whether signup is enabled for this connection"})}),pm=o.z.object({client_credentials:o.z.object({enforce:o.z.boolean().default(!1).openapi({description:"Whether to enforce token quota limits"}),per_day:o.z.number().min(0).default(0).openapi({description:"Maximum tokens per day (0 = unlimited)"}),per_hour:o.z.number().min(0).default(0).openapi({description:"Maximum tokens per hour (0 = unlimited)"})}).optional()}).optional(),Fs=o.z.object({id:o.z.string().optional(),name:o.z.string().min(1).openapi({description:"The name of the organization"}),display_name:o.z.string().optional().openapi({description:"The display name of the organization"}),branding:dm,metadata:o.z.record(o.z.any()).default({}).optional().openapi({description:"Custom metadata for the organization"}),enabled_connections:o.z.array(um).default([]).optional().openapi({description:"List of enabled connections for the organization"}),token_quota:pm}),Dn=o.z.object({...Fs.shape,...yi.shape,id:o.z.string()}),fm=o.z.object({user_id:o.z.string().openapi({description:"ID of the user"}),organization_id:o.z.string().openapi({description:"ID of the organization"})}),Zw=o.z.object({...fm.shape,...yi.shape,id:o.z.string()}),Yw=o.z.object({idle_session_lifetime:o.z.number().optional(),session_lifetime:o.z.number().optional(),session_cookie:o.z.object({mode:o.z.enum(["persistent","non-persistent"]).optional()}).optional(),enable_client_connections:o.z.boolean().optional(),default_redirection_uri:o.z.string().optional(),enabled_locales:o.z.array(o.z.string()).optional(),default_directory:o.z.string().optional(),error_page:o.z.object({html:o.z.string().optional(),show_log_link:o.z.boolean().optional(),url:o.z.string().optional()}).optional(),flags:o.z.object({allow_legacy_delegation_grant_types:o.z.boolean().optional(),allow_legacy_ro_grant_types:o.z.boolean().optional(),allow_legacy_tokeninfo_endpoint:o.z.boolean().optional(),disable_clickjack_protection_headers:o.z.boolean().optional(),enable_apis_section:o.z.boolean().optional(),enable_client_connections:o.z.boolean().optional(),enable_custom_domain_in_emails:o.z.boolean().optional(),enable_dynamic_client_registration:o.z.boolean().optional(),enable_idtoken_api2:o.z.boolean().optional(),enable_legacy_logs_search_v2:o.z.boolean().optional(),enable_legacy_profile:o.z.boolean().optional(),enable_pipeline2:o.z.boolean().optional(),enable_public_signup_user_exists_error:o.z.boolean().optional(),use_scope_descriptions_for_consent:o.z.boolean().optional(),disable_management_api_sms_obfuscation:o.z.boolean().optional(),enable_adfs_waad_email_verification:o.z.boolean().optional(),revoke_refresh_token_grant:o.z.boolean().optional(),dashboard_log_streams_next:o.z.boolean().optional(),dashboard_insights_view:o.z.boolean().optional(),disable_fields_map_fix:o.z.boolean().optional(),mfa_show_factor_list_on_enrollment:o.z.boolean().optional()}).optional(),friendly_name:o.z.string().optional(),picture_url:o.z.string().optional(),support_email:o.z.string().optional(),support_url:o.z.string().optional(),sandbox_version:o.z.string().optional(),sandbox_versions_available:o.z.array(o.z.string()).optional(),change_password:o.z.object({enabled:o.z.boolean(),html:o.z.string()}).optional(),guardian_mfa_page:o.z.object({enabled:o.z.boolean(),html:o.z.string()}).optional(),default_audience:o.z.string().optional(),default_organization:o.z.string().optional(),sessions:o.z.object({oidc_logout_prompt_enabled:o.z.boolean().optional()}).optional()});function Qw(t){const[e,n]=t.split("|");if(!e||!n)throw new Error(`Invalid user_id: ${t}`);return{connection:e,id:n}}const sf={themeId:"default",borders:{button_border_radius:8,button_border_weight:1,buttons_style:"pill",input_border_radius:8,input_border_weight:1,inputs_style:"pill",show_widget_shadow:!0,widget_border_weight:1,widget_corner_radius:16},colors:{base_focus_color:"#7D68F4",base_hover_color:"#A091F2",body_text:"#000000",captcha_widget_theme:"auto",error:"#FC5A5A",header:"#000000",icons:"#666666",input_background:"#FFFFFF",input_border:"#BFBCD7",input_filled_text:"#000000",input_labels_placeholders:"#88869F",links_focused_components:"#7D68F4",primary_button:"#7D68F4",primary_button_label:"#FFFFFF",secondary_button_border:"#BFBCD7",secondary_button_label:"#000000",success:"#36BF76",widget_background:"#FFFFFF",widget_border:"#BFBCD7"},displayName:"Default Theme",fonts:{body_text:{bold:!1,size:16},buttons_text:{bold:!1,size:16},font_url:"https://assets.sesamy.com/fonts/khteka/WOFF2/KHTeka-Regular.woff2",input_labels:{bold:!1,size:14},links:{bold:!1,size:16},links_style:"normal",reference_text_size:16,subtitle:{bold:!1,size:18},title:{bold:!0,size:24}},page_background:{background_color:"#F8F9FB",background_image_url:"https://assets.sesamy.com/images/login-bg.jpg",page_layout:"center"},widget:{header_text_alignment:"center",logo_height:36,logo_position:"center",logo_url:"https://assets.sesamy.com/static/images/sesamy/logos/sesamy_logo_black.svg",social_buttons_layout:"bottom"}};function zl(t,e){const n=structuredClone(t);function r(i,s){for(const a in s)s[a]!==void 0&&typeof s[a]=="object"&&!Array.isArray(s[a])&&typeof i[a]=="object"&&i[a]!==null?r(i[a],s[a]):i[a]=s[a];return i}return r(n,e)}const ev=new o.OpenAPIHono().openapi(o.createRoute({tags:["branding"],method:"get",path:"/default",request:{headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:us}},description:"Default theme settings"}}}),async t=>{const e=await t.env.data.themes.get(t.var.tenant_id,"default");return e?t.json(e):t.json(sf)}).openapi(o.createRoute({tags:["branding"],method:"patch",path:"/default",request:{body:{content:{"application/json":{schema:us.deepPartial()}}},headers:o.z.object({"tenant-id":o.z.string().optional()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:us}},description:"Updated theme settings"}}}),async t=>{const e=t.req.valid("json"),n=await t.env.data.themes.get(t.var.tenant_id,"default");if(n){const r=zl(n,e);await t.env.data.themes.update(t.var.tenant_id,"default",r);const i=await t.env.data.themes.get(t.var.tenant_id,"default");return t.json(i)}else{const r=zl(sf,e),i=await t.env.data.themes.create(t.var.tenant_id,r);return t.json(i)}}),tv={colors:{primary:"#7D68F4",page_background:{type:"solid",start:"#F8F9FB",end:"#F8F9FB",angle_deg:0}},logo_url:"https://assets.sesamy.com/static/images/sesamy/logos/sesamy_logo_black.svg",favicon_url:"https://assets.sesamy.com/images/favicon.ico",font:{url:"https://assets.sesamy.com/fonts/khteka/WOFF2/KHTeka-Regular.woff2"}},nv=new o.OpenAPIHono().openapi(o.createRoute({tags:["branding"],method:"get",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:kl}},description:"Branding settings"}}}),async t=>{const e=await t.env.data.branding.get(t.var.tenant_id);return e?t.json(e):t.json(tv)}).openapi(o.createRoute({tags:["branding"],method:"patch",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object(kl.shape).partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Branding settings"}}}),async t=>{const e=t.req.valid("json");return await t.env.data.branding.set(t.var.tenant_id,e),t.text("OK")}).route("/themes",ev);var S=class extends Error{constructor(e=500,n){super(n==null?void 0:n.message,{cause:n==null?void 0:n.cause});ae(this,"res");ae(this,"status");this.res=n==null?void 0:n.res,this.status=e}getResponse(){return this.res?new Response(this.res.body,{status:this.status,headers:this.res.headers}):new Response(this.message,{status:this.status})}},Al=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function hm(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function rv(t){if(t.__esModule)return t;var e=t.default;if(typeof e=="function"){var n=function r(){return this instanceof r?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};n.prototype=e.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(t).forEach(function(r){var i=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(n,r,i.get?i:{enumerable:!0,get:function(){return t[r]}})}),n}function iv(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var gm={exports:{}};const ov={},sv=Object.freeze(Object.defineProperty({__proto__:null,default:ov},Symbol.toStringTag,{value:"Module"})),av=rv(sv);(function(t){/**
2
2
  * @license bcrypt.js (c) 2013 Daniel Wirtz <dcode@dcode.io>
3
3
  * Released under the Apache License, Version 2.0
4
4
  * see: https://github.com/dcodeIO/bcrypt.js for details
5
- */(function(e,n){typeof iv=="function"&&t&&t.exports?t.exports=n():(e.dcodeIO=e.dcodeIO||{}).bcrypt=n()})(Al,function(){var e={},n=null;function r(N){if(t&&t.exports)try{return av.randomBytes(N)}catch{}try{var C;return(self.crypto||self.msCrypto).getRandomValues(C=new Uint32Array(N)),Array.prototype.slice.call(C)}catch{}if(!n)throw Error("Neither WebCryptoAPI nor a crypto module is available. Use bcrypt.setRandomFallback to set an alternative");return n(N)}var i=!1;try{r(1),i=!0}catch{}n=null,e.setRandomFallback=function(N){n=N},e.genSaltSync=function(N,C){if(N=N||v,typeof N!="number")throw Error("Illegal arguments: "+typeof N+", "+typeof C);N<4?N=4:N>31&&(N=31);var z=[];return z.push("$2a$"),N<10&&z.push("0"),z.push(N.toString()),z.push("$"),z.push(f(r(y),y)),z.join("")},e.genSalt=function(N,C,z){if(typeof C=="function"&&(z=C,C=void 0),typeof N=="function"&&(z=N,N=void 0),typeof N>"u")N=v;else if(typeof N!="number")throw Error("illegal arguments: "+typeof N);function k($){a(function(){try{$(null,e.genSaltSync(N))}catch(I){$(I)}})}if(z){if(typeof z!="function")throw Error("Illegal callback: "+typeof z);k(z)}else return new Promise(function($,I){k(function(L,q){if(L){I(L);return}$(q)})})},e.hashSync=function(N,C){if(typeof C>"u"&&(C=v),typeof C=="number"&&(C=e.genSaltSync(C)),typeof N!="string"||typeof C!="string")throw Error("Illegal arguments: "+typeof N+", "+typeof C);return de(N,C)},e.hash=function(N,C,z,k){function $(I){typeof N=="string"&&typeof C=="number"?e.genSalt(C,function(L,q){de(N,q,I,k)}):typeof N=="string"&&typeof C=="string"?de(N,C,I,k):a(I.bind(this,Error("Illegal arguments: "+typeof N+", "+typeof C)))}if(z){if(typeof z!="function")throw Error("Illegal callback: "+typeof z);$(z)}else return new Promise(function(I,L){$(function(q,F){if(q){L(q);return}I(F)})})};function s(N,C){for(var z=0,k=0,$=0,I=N.length;$<I;++$)N.charCodeAt($)===C.charCodeAt($)?++z:++k;return z<0?!1:k===0}e.compareSync=function(N,C){if(typeof N!="string"||typeof C!="string")throw Error("Illegal arguments: "+typeof N+", "+typeof C);return C.length!==60?!1:s(e.hashSync(N,C.substr(0,C.length-31)),C)},e.compare=function(N,C,z,k){function $(I){if(typeof N!="string"||typeof C!="string"){a(I.bind(this,Error("Illegal arguments: "+typeof N+", "+typeof C)));return}if(C.length!==60){a(I.bind(this,null,!1));return}e.hash(N,C.substr(0,29),function(L,q){L?I(L):I(null,s(q,C))},k)}if(z){if(typeof z!="function")throw Error("Illegal callback: "+typeof z);$(z)}else return new Promise(function(I,L){$(function(q,F){if(q){L(q);return}I(F)})})},e.getRounds=function(N){if(typeof N!="string")throw Error("Illegal arguments: "+typeof N);return parseInt(N.split("$")[2],10)},e.getSalt=function(N){if(typeof N!="string")throw Error("Illegal arguments: "+typeof N);if(N.length!==60)throw Error("Illegal hash length: "+N.length+" != 60");return N.substring(0,29)};var a=typeof process<"u"&&process&&typeof process.nextTick=="function"?typeof setImmediate=="function"?setImmediate:process.nextTick:setTimeout;function c(N){var C=[],z=0;return m.encodeUTF16toUTF8(function(){return z>=N.length?null:N.charCodeAt(z++)},function(k){C.push(k)}),C}var l="./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),d=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,54,55,56,57,58,59,60,61,62,63,-1,-1,-1,-1,-1,-1,-1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,-1,-1,-1,-1,-1,-1,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,-1,-1,-1,-1,-1],u=String.fromCharCode;function f(N,C){var z=0,k=[],$,I;if(C<=0||C>N.length)throw Error("Illegal len: "+C);for(;z<C;){if($=N[z++]&255,k.push(l[$>>2&63]),$=($&3)<<4,z>=C){k.push(l[$&63]);break}if(I=N[z++]&255,$|=I>>4&15,k.push(l[$&63]),$=(I&15)<<2,z>=C){k.push(l[$&63]);break}I=N[z++]&255,$|=I>>6&3,k.push(l[$&63]),k.push(l[I&63])}return k.join("")}function h(N,C){var z=0,k=N.length,$=0,I=[],L,q,F,Z,se,D;if(C<=0)throw Error("Illegal len: "+C);for(;z<k-1&&$<C&&(D=N.charCodeAt(z++),L=D<d.length?d[D]:-1,D=N.charCodeAt(z++),q=D<d.length?d[D]:-1,!(L==-1||q==-1||(se=L<<2>>>0,se|=(q&48)>>4,I.push(u(se)),++$>=C||z>=k)||(D=N.charCodeAt(z++),F=D<d.length?d[D]:-1,F==-1)||(se=(q&15)<<4>>>0,se|=(F&60)>>2,I.push(u(se)),++$>=C||z>=k)));)D=N.charCodeAt(z++),Z=D<d.length?d[D]:-1,se=(F&3)<<6>>>0,se|=Z,I.push(u(se)),++$;var fe=[];for(z=0;z<$;z++)fe.push(I[z].charCodeAt(0));return fe}var m=function(){var N={};return N.MAX_CODEPOINT=1114111,N.encodeUTF8=function(C,z){var k=null;for(typeof C=="number"&&(k=C,C=function(){return null});k!==null||(k=C())!==null;)k<128?z(k&127):k<2048?(z(k>>6&31|192),z(k&63|128)):k<65536?(z(k>>12&15|224),z(k>>6&63|128),z(k&63|128)):(z(k>>18&7|240),z(k>>12&63|128),z(k>>6&63|128),z(k&63|128)),k=null},N.decodeUTF8=function(C,z){for(var k,$,I,L,q=function(F){F=F.slice(0,F.indexOf(null));var Z=Error(F.toString());throw Z.name="TruncatedError",Z.bytes=F,Z};(k=C())!==null;)if(!(k&128))z(k);else if((k&224)===192)($=C())===null&&q([k,$]),z((k&31)<<6|$&63);else if((k&240)===224)(($=C())===null||(I=C())===null)&&q([k,$,I]),z((k&15)<<12|($&63)<<6|I&63);else if((k&248)===240)(($=C())===null||(I=C())===null||(L=C())===null)&&q([k,$,I,L]),z((k&7)<<18|($&63)<<12|(I&63)<<6|L&63);else throw RangeError("Illegal starting byte: "+k)},N.UTF16toUTF8=function(C,z){for(var k,$=null;(k=$!==null?$:C())!==null;){if(k>=55296&&k<=57343&&($=C())!==null&&$>=56320&&$<=57343){z((k-55296)*1024+$-56320+65536),$=null;continue}z(k)}$!==null&&z($)},N.UTF8toUTF16=function(C,z){var k=null;for(typeof C=="number"&&(k=C,C=function(){return null});k!==null||(k=C())!==null;)k<=65535?z(k):(k-=65536,z((k>>10)+55296),z(k%1024+56320)),k=null},N.encodeUTF16toUTF8=function(C,z){N.UTF16toUTF8(C,function(k){N.encodeUTF8(k,z)})},N.decodeUTF8toUTF16=function(C,z){N.decodeUTF8(C,function(k){N.UTF8toUTF16(k,z)})},N.calculateCodePoint=function(C){return C<128?1:C<2048?2:C<65536?3:4},N.calculateUTF8=function(C){for(var z,k=0;(z=C())!==null;)k+=N.calculateCodePoint(z);return k},N.calculateUTF16asUTF8=function(C){var z=0,k=0;return N.UTF16toUTF8(C,function($){++z,k+=N.calculateCodePoint($)}),[z,k]},N}();Date.now=Date.now||function(){return+new Date};var y=16,v=10,b=16,A=100,O=[608135816,2242054355,320440878,57701188,2752067618,698298832,137296536,3964562569,1160258022,953160567,3193202383,887688300,3232508343,3380367581,1065670069,3041331479,2450970073,2306472731],U=[3509652390,2564797868,805139163,3491422135,3101798381,1780907670,3128725573,4046225305,614570311,3012652279,134345442,2240740374,1667834072,1901547113,2757295779,4103290238,227898511,1921955416,1904987480,2182433518,2069144605,3260701109,2620446009,720527379,3318853667,677414384,3393288472,3101374703,2390351024,1614419982,1822297739,2954791486,3608508353,3174124327,2024746970,1432378464,3864339955,2857741204,1464375394,1676153920,1439316330,715854006,3033291828,289532110,2706671279,2087905683,3018724369,1668267050,732546397,1947742710,3462151702,2609353502,2950085171,1814351708,2050118529,680887927,999245976,1800124847,3300911131,1713906067,1641548236,4213287313,1216130144,1575780402,4018429277,3917837745,3693486850,3949271944,596196993,3549867205,258830323,2213823033,772490370,2760122372,1774776394,2652871518,566650946,4142492826,1728879713,2882767088,1783734482,3629395816,2517608232,2874225571,1861159788,326777828,3124490320,2130389656,2716951837,967770486,1724537150,2185432712,2364442137,1164943284,2105845187,998989502,3765401048,2244026483,1075463327,1455516326,1322494562,910128902,469688178,1117454909,936433444,3490320968,3675253459,1240580251,122909385,2157517691,634681816,4142456567,3825094682,3061402683,2540495037,79693498,3249098678,1084186820,1583128258,426386531,1761308591,1047286709,322548459,995290223,1845252383,2603652396,3431023940,2942221577,3202600964,3727903485,1712269319,422464435,3234572375,1170764815,3523960633,3117677531,1434042557,442511882,3600875718,1076654713,1738483198,4213154764,2393238008,3677496056,1014306527,4251020053,793779912,2902807211,842905082,4246964064,1395751752,1040244610,2656851899,3396308128,445077038,3742853595,3577915638,679411651,2892444358,2354009459,1767581616,3150600392,3791627101,3102740896,284835224,4246832056,1258075500,768725851,2589189241,3069724005,3532540348,1274779536,3789419226,2764799539,1660621633,3471099624,4011903706,913787905,3497959166,737222580,2514213453,2928710040,3937242737,1804850592,3499020752,2949064160,2386320175,2390070455,2415321851,4061277028,2290661394,2416832540,1336762016,1754252060,3520065937,3014181293,791618072,3188594551,3933548030,2332172193,3852520463,3043980520,413987798,3465142937,3030929376,4245938359,2093235073,3534596313,375366246,2157278981,2479649556,555357303,3870105701,2008414854,3344188149,4221384143,3956125452,2067696032,3594591187,2921233993,2428461,544322398,577241275,1471733935,610547355,4027169054,1432588573,1507829418,2025931657,3646575487,545086370,48609733,2200306550,1653985193,298326376,1316178497,3007786442,2064951626,458293330,2589141269,3591329599,3164325604,727753846,2179363840,146436021,1461446943,4069977195,705550613,3059967265,3887724982,4281599278,3313849956,1404054877,2845806497,146425753,1854211946,1266315497,3048417604,3681880366,3289982499,290971e4,1235738493,2632868024,2414719590,3970600049,1771706367,1449415276,3266420449,422970021,1963543593,2690192192,3826793022,1062508698,1531092325,1804592342,2583117782,2714934279,4024971509,1294809318,4028980673,1289560198,2221992742,1669523910,35572830,157838143,1052438473,1016535060,1802137761,1753167236,1386275462,3080475397,2857371447,1040679964,2145300060,2390574316,1461121720,2956646967,4031777805,4028374788,33600511,2920084762,1018524850,629373528,3691585981,3515945977,2091462646,2486323059,586499841,988145025,935516892,3367335476,2599673255,2839830854,265290510,3972581182,2759138881,3795373465,1005194799,847297441,406762289,1314163512,1332590856,1866599683,4127851711,750260880,613907577,1450815602,3165620655,3734664991,3650291728,3012275730,3704569646,1427272223,778793252,1343938022,2676280711,2052605720,1946737175,3164576444,3914038668,3967478842,3682934266,1661551462,3294938066,4011595847,840292616,3712170807,616741398,312560963,711312465,1351876610,322626781,1910503582,271666773,2175563734,1594956187,70604529,3617834859,1007753275,1495573769,4069517037,2549218298,2663038764,504708206,2263041392,3941167025,2249088522,1514023603,1998579484,1312622330,694541497,2582060303,2151582166,1382467621,776784248,2618340202,3323268794,2497899128,2784771155,503983604,4076293799,907881277,423175695,432175456,1378068232,4145222326,3954048622,3938656102,3820766613,2793130115,2977904593,26017576,3274890735,3194772133,1700274565,1756076034,4006520079,3677328699,720338349,1533947780,354530856,688349552,3973924725,1637815568,332179504,3949051286,53804574,2852348879,3044236432,1282449977,3583942155,3416972820,4006381244,1617046695,2628476075,3002303598,1686838959,431878346,2686675385,1700445008,1080580658,1009431731,832498133,3223435511,2605976345,2271191193,2516031870,1648197032,4164389018,2548247927,300782431,375919233,238389289,3353747414,2531188641,2019080857,1475708069,455242339,2609103871,448939670,3451063019,1395535956,2413381860,1841049896,1491858159,885456874,4264095073,4001119347,1565136089,3898914787,1108368660,540939232,1173283510,2745871338,3681308437,4207628240,3343053890,4016749493,1699691293,1103962373,3625875870,2256883143,3830138730,1031889488,3479347698,1535977030,4236805024,3251091107,2132092099,1774941330,1199868427,1452454533,157007616,2904115357,342012276,595725824,1480756522,206960106,497939518,591360097,863170706,2375253569,3596610801,1814182875,2094937945,3421402208,1082520231,3463918190,2785509508,435703966,3908032597,1641649973,2842273706,3305899714,1510255612,2148256476,2655287854,3276092548,4258621189,236887753,3681803219,274041037,1734335097,3815195456,3317970021,1899903192,1026095262,4050517792,356393447,2410691914,3873677099,3682840055,3913112168,2491498743,4132185628,2489919796,1091903735,1979897079,3170134830,3567386728,3557303409,857797738,1136121015,1342202287,507115054,2535736646,337727348,3213592640,1301675037,2528481711,1895095763,1721773893,3216771564,62756741,2142006736,835421444,2531993523,1442658625,3659876326,2882144922,676362277,1392781812,170690266,3921047035,1759253602,3611846912,1745797284,664899054,1329594018,3901205900,3045908486,2062866102,2865634940,3543621612,3464012697,1080764994,553557557,3656615353,3996768171,991055499,499776247,1265440854,648242737,3940784050,980351604,3713745714,1749149687,3396870395,4211799374,3640570775,1161844396,3125318951,1431517754,545492359,4268468663,3499529547,1437099964,2702547544,3433638243,2581715763,2787789398,1060185593,1593081372,2418618748,4260947970,69676912,2159744348,86519011,2512459080,3838209314,1220612927,3339683548,133810670,1090789135,1078426020,1569222167,845107691,3583754449,4072456591,1091646820,628848692,1613405280,3757631651,526609435,236106946,48312990,2942717905,3402727701,1797494240,859738849,992217954,4005476642,2243076622,3870952857,3732016268,765654824,3490871365,2511836413,1685915746,3888969200,1414112111,2273134842,3281911079,4080962846,172450625,2569994100,980381355,4109958455,2819808352,2716589560,2568741196,3681446669,3329971472,1835478071,660984891,3704678404,4045999559,3422617507,3040415634,1762651403,1719377915,3470491036,2693910283,3642056355,3138596744,1364962596,2073328063,1983633131,926494387,3423689081,2150032023,4096667949,1749200295,3328846651,309677260,2016342300,1779581495,3079819751,111262694,1274766160,443224088,298511866,1025883608,3806446537,1145181785,168956806,3641502830,3584813610,1689216846,3666258015,3200248200,1692713982,2646376535,4042768518,1618508792,1610833997,3523052358,4130873264,2001055236,3610705100,2202168115,4028541809,2961195399,1006657119,2006996926,3186142756,1430667929,3210227297,1314452623,4074634658,4101304120,2273951170,1399257539,3367210612,3027628629,1190975929,2062231137,2333990788,2221543033,2438960610,1181637006,548689776,2362791313,3372408396,3104550113,3145860560,296247880,1970579870,3078560182,3769228297,1714227617,3291629107,3898220290,166772364,1251581989,493813264,448347421,195405023,2709975567,677966185,3703036547,1463355134,2715995803,1338867538,1343315457,2802222074,2684532164,233230375,2599980071,2000651841,3277868038,1638401717,4028070440,3237316320,6314154,819756386,300326615,590932579,1405279636,3267499572,3150704214,2428286686,3959192993,3461946742,1862657033,1266418056,963775037,2089974820,2263052895,1917689273,448879540,3550394620,3981727096,150775221,3627908307,1303187396,508620638,2975983352,2726630617,1817252668,1876281319,1457606340,908771278,3720792119,3617206836,2455994898,1729034894,1080033504,976866871,3556439503,2881648439,1522871579,1555064734,1336096578,3548522304,2579274686,3574697629,3205460757,3593280638,3338716283,3079412587,564236357,2993598910,1781952180,1464380207,3163844217,3332601554,1699332808,1393555694,1183702653,3581086237,1288719814,691649499,2847557200,2895455976,3193889540,2717570544,1781354906,1676643554,2592534050,3230253752,1126444790,2770207658,2633158820,2210423226,2615765581,2414155088,3127139286,673620729,2805611233,1269405062,4015350505,3341807571,4149409754,1057255273,2012875353,2162469141,2276492801,2601117357,993977747,3918593370,2654263191,753973209,36408145,2530585658,25011837,3520020182,2088578344,530523599,2918365339,1524020338,1518925132,3760827505,3759777254,1202760957,3985898139,3906192525,674977740,4174734889,2031300136,2019492241,3983892565,4153806404,3822280332,352677332,2297720250,60907813,90501309,3286998549,1016092578,2535922412,2839152426,457141659,509813237,4120667899,652014361,1966332200,2975202805,55981186,2327461051,676427537,3255491064,2882294119,3433927263,1307055953,942726286,933058658,2468411793,3933900994,4215176142,1361170020,2001714738,2830558078,3274259782,1222529897,1679025792,2729314320,3714953764,1770335741,151462246,3013232138,1682292957,1483529935,471910574,1539241949,458788160,3436315007,1807016891,3718408830,978976581,1043663428,3165965781,1927990952,4200891579,2372276910,3208408903,3533431907,1412390302,2931980059,4132332400,1947078029,3881505623,4168226417,2941484381,1077988104,1320477388,886195818,18198404,3786409e3,2509781533,112762804,3463356488,1866414978,891333506,18488651,661792760,1628790961,3885187036,3141171499,876946877,2693282273,1372485963,791857591,2686433993,3759982718,3167212022,3472953795,2716379847,445679433,3561995674,3504004811,3574258232,54117162,3331405415,2381918588,3769707343,4154350007,1140177722,4074052095,668550556,3214352940,367459370,261225585,2610173221,4209349473,3468074219,3265815641,314222801,3066103646,3808782860,282218597,3406013506,3773591054,379116347,1285071038,846784868,2669647154,3771962079,3550491691,2305946142,453669953,1268987020,3317592352,3279303384,3744833421,2610507566,3859509063,266596637,3847019092,517658769,3462560207,3443424879,370717030,4247526661,2224018117,4143653529,4112773975,2788324899,2477274417,1456262402,2901442914,1517677493,1846949527,2295493580,3734397586,2176403920,1280348187,1908823572,3871786941,846861322,1172426758,3287448474,3383383037,1655181056,3139813346,901632758,1897031941,2986607138,3066810236,3447102507,1393639104,373351379,950779232,625454576,3124240540,4148612726,2007998917,544563296,2244738638,2330496472,2058025392,1291430526,424198748,50039436,29584100,3605783033,2429876329,2791104160,1057563949,3255363231,3075367218,3463963227,1469046755,985887462],T=[1332899944,1700884034,1701343084,1684370003,1668446532,1869963892];function R(N,C,z,k){var $,I=N[C],L=N[C+1];return I^=z[0],$=k[I>>>24],$+=k[256|I>>16&255],$^=k[512|I>>8&255],$+=k[768|I&255],L^=$^z[1],$=k[L>>>24],$+=k[256|L>>16&255],$^=k[512|L>>8&255],$+=k[768|L&255],I^=$^z[2],$=k[I>>>24],$+=k[256|I>>16&255],$^=k[512|I>>8&255],$+=k[768|I&255],L^=$^z[3],$=k[L>>>24],$+=k[256|L>>16&255],$^=k[512|L>>8&255],$+=k[768|L&255],I^=$^z[4],$=k[I>>>24],$+=k[256|I>>16&255],$^=k[512|I>>8&255],$+=k[768|I&255],L^=$^z[5],$=k[L>>>24],$+=k[256|L>>16&255],$^=k[512|L>>8&255],$+=k[768|L&255],I^=$^z[6],$=k[I>>>24],$+=k[256|I>>16&255],$^=k[512|I>>8&255],$+=k[768|I&255],L^=$^z[7],$=k[L>>>24],$+=k[256|L>>16&255],$^=k[512|L>>8&255],$+=k[768|L&255],I^=$^z[8],$=k[I>>>24],$+=k[256|I>>16&255],$^=k[512|I>>8&255],$+=k[768|I&255],L^=$^z[9],$=k[L>>>24],$+=k[256|L>>16&255],$^=k[512|L>>8&255],$+=k[768|L&255],I^=$^z[10],$=k[I>>>24],$+=k[256|I>>16&255],$^=k[512|I>>8&255],$+=k[768|I&255],L^=$^z[11],$=k[L>>>24],$+=k[256|L>>16&255],$^=k[512|L>>8&255],$+=k[768|L&255],I^=$^z[12],$=k[I>>>24],$+=k[256|I>>16&255],$^=k[512|I>>8&255],$+=k[768|I&255],L^=$^z[13],$=k[L>>>24],$+=k[256|L>>16&255],$^=k[512|L>>8&255],$+=k[768|L&255],I^=$^z[14],$=k[I>>>24],$+=k[256|I>>16&255],$^=k[512|I>>8&255],$+=k[768|I&255],L^=$^z[15],$=k[L>>>24],$+=k[256|L>>16&255],$^=k[512|L>>8&255],$+=k[768|L&255],I^=$^z[16],N[C]=L^z[b+1],N[C+1]=I,N}function W(N,C){for(var z=0,k=0;z<4;++z)k=k<<8|N[C]&255,C=(C+1)%N.length;return{key:k,offp:C}}function ne(N,C,z){for(var k=0,$=[0,0],I=C.length,L=z.length,q,F=0;F<I;F++)q=W(N,k),k=q.offp,C[F]=C[F]^q.key;for(F=0;F<I;F+=2)$=R($,0,C,z),C[F]=$[0],C[F+1]=$[1];for(F=0;F<L;F+=2)$=R($,0,C,z),z[F]=$[0],z[F+1]=$[1]}function Q(N,C,z,k){for(var $=0,I=[0,0],L=z.length,q=k.length,F,Z=0;Z<L;Z++)F=W(C,$),$=F.offp,z[Z]=z[Z]^F.key;for($=0,Z=0;Z<L;Z+=2)F=W(N,$),$=F.offp,I[0]^=F.key,F=W(N,$),$=F.offp,I[1]^=F.key,I=R(I,0,z,k),z[Z]=I[0],z[Z+1]=I[1];for(Z=0;Z<q;Z+=2)F=W(N,$),$=F.offp,I[0]^=F.key,F=W(N,$),$=F.offp,I[1]^=F.key,I=R(I,0,z,k),k[Z]=I[0],k[Z+1]=I[1]}function K(N,C,z,k,$){var I=T.slice(),L=I.length,q;if(z<4||z>31)if(q=Error("Illegal number of rounds (4-31): "+z),k){a(k.bind(this,q));return}else throw q;if(C.length!==y)if(q=Error("Illegal salt length: "+C.length+" != "+y),k){a(k.bind(this,q));return}else throw q;z=1<<z>>>0;var F,Z,se=0,D;Int32Array?(F=new Int32Array(O),Z=new Int32Array(U)):(F=O.slice(),Z=U.slice()),Q(C,N,F,Z);function fe(){if($&&$(se/z),se<z)for(var ce=Date.now();se<z&&(se=se+1,ne(N,F,Z),ne(C,F,Z),!(Date.now()-ce>A)););else{for(se=0;se<64;se++)for(D=0;D<L>>1;D++)R(I,D<<1,F,Z);var ue=[];for(se=0;se<L;se++)ue.push((I[se]>>24&255)>>>0),ue.push((I[se]>>16&255)>>>0),ue.push((I[se]>>8&255)>>>0),ue.push((I[se]&255)>>>0);if(k){k(null,ue);return}else return ue}k&&a(fe)}if(typeof k<"u")fe();else for(var $e;;)if(typeof($e=fe())<"u")return $e||[]}function de(N,C,z,k){var $;if(typeof N!="string"||typeof C!="string")if($=Error("Invalid string / salt: Not a string"),z){a(z.bind(this,$));return}else throw $;var I,L;if(C.charAt(0)!=="$"||C.charAt(1)!=="2")if($=Error("Invalid salt version: "+C.substring(0,2)),z){a(z.bind(this,$));return}else throw $;if(C.charAt(2)==="$")I="\0",L=3;else{if(I=C.charAt(2),I!=="a"&&I!=="b"&&I!=="y"||C.charAt(3)!=="$")if($=Error("Invalid salt revision: "+C.substring(2,4)),z){a(z.bind(this,$));return}else throw $;L=4}if(C.charAt(L+2)>"$")if($=Error("Missing salt rounds"),z){a(z.bind(this,$));return}else throw $;var q=parseInt(C.substring(L,L+1),10)*10,F=parseInt(C.substring(L+1,L+2),10),Z=q+F,se=C.substring(L+3,L+25);N+=I>="a"?"\0":"";var D=c(N),fe=h(se,y);function $e(ce){var ue=[];return ue.push("$2"),I>="a"&&ue.push(I),ue.push("$"),Z<10&&ue.push("0"),ue.push(Z.toString()),ue.push("$"),ue.push(f(fe,fe.length)),ue.push(f(ce,T.length*4-1)),ue.join("")}if(typeof z>"u")return $e(K(D,fe,Z));K(D,fe,Z,function(ce,ue){ce?z(ce,null):z(null,$e(ue))},k)}return e.encodeBase64=f,e.decodeBase64=h,e})})(gm);var cv=gm.exports;const ti=hm(cv),lv="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let dv=t=>crypto.getRandomValues(new Uint8Array(t)),uv=(t,e,n)=>{let r=(2<<Math.log2(t.length-1))-1,i=-~(1.6*r*e/t.length);return(s=e)=>{let a="";for(;;){let c=n(i),l=i;for(;l--;)if(a+=t[c[l]&r]||"",a.length===s)return a}}},mm=(t,e=21)=>uv(t,e,dv),Ne=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t));for(;t--;)e+=lv[n[t]&63];return e};const pv=24;function La(){return mm("0123456789abcdef",pv)()}function ns(t){if(!t.includes("|"))return console.error("Invalid user_id format"),t;const[,e]=t.split("|");return e}function fv(t){return async(e,n)=>{if(!n.email||!n.email_verified)return t.users.create(e,n);const r=await Cu({userAdapter:t.users,tenant_id:e,email:n.email});return r?(await t.users.create(e,{...n,linked_to:r.user_id}),r):t.users.create(e,n)}}function be(t,e){return{type:e.type,description:e.description||"",ip:t.var.ip,user_agent:t.var.useragent||"",auth0_client:t.var.auth0_client,date:new Date().toISOString(),details:{request:{method:t.req.method,path:t.req.path,qs:t.req.queries(),body:e.body||t.var.body||""}},isMobile:!1,client_id:t.var.client_id,client_name:"",user_id:e.userId||t.var.user_id||"",hostname:t.req.header("host")||"",user_name:t.var.username||"",connection_id:"",connection:e.connection||t.var.connection||"",strategy:e.strategy||"",strategy_type:e.strategy_type||"",audience:e.audience||"",scope:e.scope?e.scope.split(" "):[]}}class qs{constructor(e,n){ae(this,"value");ae(this,"unit");this.value=e,this.unit=n}milliseconds(){return this.unit==="ms"?this.value:this.unit==="s"?this.value*1e3:this.unit==="m"?this.value*1e3*60:this.unit==="h"?this.value*1e3*60*60:this.unit==="d"?this.value*1e3*60*60*24:this.value*1e3*60*60*24*7}seconds(){return this.milliseconds()/1e3}transform(e){return new qs(Math.round(this.milliseconds()*e),"ms")}}class hv{constructor(e){ae(this,"hash");this.hash=e}async verify(e,n,r){const i=await crypto.subtle.importKey("spki",e,{name:"RSASSA-PKCS1-v1_5",hash:this.hash},!1,["verify"]);return await crypto.subtle.verify("RSASSA-PKCS1-v1_5",i,n,r)}async sign(e,n){const r=await crypto.subtle.importKey("pkcs8",e,{name:"RSASSA-PKCS1-v1_5",hash:this.hash},!1,["sign"]);return await crypto.subtle.sign("RSASSA-PKCS1-v1_5",r,n)}async generateKeyPair(e){const n=await crypto.subtle.generateKey({name:"RSASSA-PKCS1-v1_5",hash:this.hash,modulusLength:e??2048,publicExponent:new Uint8Array([1,0,1])},!0,["sign"]),r=await crypto.subtle.exportKey("pkcs8",n.privateKey),i=await crypto.subtle.exportKey("spki",n.publicKey);return{privateKey:r,publicKey:i}}}async function _m(t){return await crypto.subtle.digest("SHA-256",t)}const af="0123456789abcdef";function El(t){const e=new Uint8Array(t);let n="";for(let r=0;r<e.length;r++){const i=e[r]>>4;n+=af[i];const s=e[r]&15;n+=af[s]}return n}class ym{constructor(e,n){ae(this,"alphabet");ae(this,"padding");ae(this,"decodeMap",new Map);if(e.length!==32)throw new Error("Invalid alphabet");if(this.alphabet=e,this.padding=(n==null?void 0:n.padding)??"=",this.alphabet.includes(this.padding)||this.padding.length!==1)throw new Error("Invalid padding");for(let r=0;r<e.length;r++)this.decodeMap.set(e[r],r)}encode(e,n){let r="",i=0,s=0;for(let c=0;c<e.length;c++)for(i=i<<8|e[c],s+=8;s>=5;)s-=5,r+=this.alphabet[i>>s&31];if(s>0&&(r+=this.alphabet[i<<5-s&31]),(n==null?void 0:n.includePadding)??!0){const c=(8-r.length%8)%8;for(let l=0;l<c;l++)r+="="}return r}decode(e,n){const r=(n==null?void 0:n.strict)??!0,i=Math.ceil(e.length/8),s=[];for(let a=0;a<i;a++){let c=0;const l=[];for(let u=0;u<8;u++){const f=e[a*8+u];if(f==="="){if(a+1!==i)throw new Error(`Invalid character: ${f}`);c+=1;continue}if(f===void 0){if(r)throw new Error("Invalid data");c+=1;continue}const h=this.decodeMap.get(f)??null;if(h===null)throw new Error(`Invalid character: ${f}`);l.push(h)}if(c===8||c===7||c===5||c===2)throw new Error("Invalid padding");const d=(l[0]<<3)+(l[1]>>2);if(s.push(d),c<6){const u=((l[1]&3)<<6)+(l[2]<<1)+(l[3]>>4);s.push(u)}if(c<4){const u=((l[3]&255)<<4)+(l[4]>>1);s.push(u)}if(c<3){const u=((l[4]&1)<<7)+(l[5]<<2)+(l[6]>>3);s.push(u)}if(c<1){const u=((l[6]&7)<<5)+l[7];s.push(u)}}return Uint8Array.from(s)}}new ym("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567");new ym("0123456789ABCDEFGHIJKLMNOPQRSTUV");class wm{constructor(e,n){ae(this,"alphabet");ae(this,"padding");ae(this,"decodeMap",new Map);if(e.length!==64)throw new Error("Invalid alphabet");if(this.alphabet=e,this.padding=(n==null?void 0:n.padding)??"=",this.alphabet.includes(this.padding)||this.padding.length!==1)throw new Error("Invalid padding");for(let r=0;r<e.length;r++)this.decodeMap.set(e[r],r)}encode(e,n){let r="",i=0,s=0;for(let c=0;c<e.length;c++)for(i=i<<8|e[c],s+=8;s>=6;)s+=-6,r+=this.alphabet[i>>s&63];if(s>0&&(r+=this.alphabet[i<<6-s&63]),(n==null?void 0:n.includePadding)??!0){const c=(4-r.length%4)%4;for(let l=0;l<c;l++)r+="="}return r}decode(e,n){const r=(n==null?void 0:n.strict)??!0,i=Math.ceil(e.length/4),s=[];for(let a=0;a<i;a++){let c=0,l=0;for(let d=0;d<4;d++){const u=e[a*4+d];if(u==="="){if(a+1!==i)throw new Error(`Invalid character: ${u}`);c+=1;continue}if(u===void 0){if(r)throw new Error("Invalid data");c+=1;continue}const f=this.decodeMap.get(u)??null;if(f===null)throw new Error(`Invalid character: ${u}`);l+=f<<6*(3-d)}s.push(l>>16&255),c<2&&s.push(l>>8&255),c<1&&s.push(l&255)}return Uint8Array.from(s)}}const gv=new wm("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),fr=new wm("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");async function cf(t,e,n,r){const i={alg:t,typ:"JWT",...r==null?void 0:r.headers},s={...n};(r==null?void 0:r.audiences)!==void 0&&(s.aud=r.audiences),(r==null?void 0:r.subject)!==void 0&&(s.sub=r.subject),(r==null?void 0:r.issuer)!==void 0&&(s.iss=r.issuer),(r==null?void 0:r.jwtId)!==void 0&&(s.jti=r.jwtId),(r==null?void 0:r.expiresIn)!==void 0&&(s.exp=Math.floor(Date.now()/1e3)+r.expiresIn.seconds()),(r==null?void 0:r.notBefore)!==void 0&&(s.nbf=Math.floor(r.notBefore.getTime()/1e3)),s.iat=Math.floor(Date.now()/1e3);const a=new TextEncoder,c=fr.encode(a.encode(JSON.stringify(i)),{includePadding:!1}),l=fr.encode(a.encode(JSON.stringify(s)),{includePadding:!1}),d=a.encode([c,l].join(".")),u=await _v(t).sign(e,d),f=fr.encode(new Uint8Array(u),{includePadding:!1});return[c,l,f].join(".")}function mv(t){const e=t.split(".");return e.length!==3?null:e}function Ua(t){const e=mv(t);if(!e)return null;const n=new TextDecoder,r=fr.decode(e[0],{strict:!1}),i=fr.decode(e[1],{strict:!1}),s=JSON.parse(n.decode(r));if(typeof s!="object"||s===null||!("alg"in s)||!yv(s.alg)||"typ"in s&&s.typ!=="JWT")return null;const a=JSON.parse(n.decode(i));if(typeof a!="object"||a===null)return null;const c={algorithm:s.alg,expiresAt:null,subject:null,issuedAt:null,issuer:null,jwtId:null,audiences:null,notBefore:null};if("exp"in a){if(typeof a.exp!="number")return null;c.expiresAt=new Date(a.exp*1e3)}if("iss"in a){if(typeof a.iss!="string")return null;c.issuer=a.iss}if("sub"in a){if(typeof a.sub!="string")return null;c.subject=a.sub}if("aud"in a)if(Array.isArray(a.aud)){for(const l of a.aud)if(typeof l!="string")return null;c.audiences=a.aud}else{if(typeof a.aud!="string")return null;c.audiences=[a.aud]}if("nbf"in a){if(typeof a.nbf!="number")return null;c.notBefore=new Date(a.nbf*1e3)}if("iat"in a){if(typeof a.iat!="number")return null;c.issuedAt=new Date(a.iat*1e3)}if("jti"in a){if(typeof a.jti!="string")return null;c.jwtId=a.jti}return{value:t,header:{...s,typ:"JWT",alg:s.alg},payload:{...a},parts:e,...c}}function _v(t){return new hv(wv[t])}function yv(t){return typeof t!="string"?!1:["HS256","HS384","HS512","RS256","RS384","RS512","ES256","ES384","ES512","PS256","PS384","PS512"].includes(t)}const wv={RS256:"SHA-256",RS384:"SHA-384",RS512:"SHA-512"};function vv(){const t=new Uint8Array(32);return crypto.getRandomValues(t),fr.encode(t,{includePadding:!1})}function bv(t){try{const n=/-----BEGIN (?:RSA )?(?:PRIVATE|PUBLIC) KEY-----([^-]*)-----END (?:RSA )?(?:PRIVATE|PUBLIC) KEY-----/.exec(t);if(!n||!n[1])throw new Error("Invalid PEM format");return Uint8Array.from(atob(n[1].replace(/\s/g,"")),r=>r.charCodeAt(0)).buffer}finally{t=t.replace(/./g,"\0")}}async function $v(t,e){if(e==="plain")return t;const n=new TextEncoder().encode(t),r=await _m(n);return fr.encode(new Uint8Array(r),{includePadding:!1})}const rs=60*5,Da=30*24*60*60,_r=24*60*60,kv="auth-token",hs=30*60*1e3,Cl=7*24*60*60*1e3,xv=5*60,Sv=5*60,zv=30*60*1e3,Av=30*60*1e3,Ev=24*60*60*1e3;function vm(t,e,n){const r=[];return r.push([encodeURIComponent(t),encodeURIComponent(e)]),(n==null?void 0:n.domain)!==void 0&&r.push(["Domain",n.domain]),(n==null?void 0:n.expires)!==void 0&&r.push(["Expires",n.expires.toUTCString()]),n!=null&&n.httpOnly&&r.push(["HttpOnly"]),(n==null?void 0:n.maxAge)!==void 0&&r.push(["Max-Age",n.maxAge.toString()]),(n==null?void 0:n.path)!==void 0&&r.push(["Path",n.path]),(n==null?void 0:n.sameSite)==="lax"&&r.push(["SameSite","Lax"]),(n==null?void 0:n.sameSite)==="none"&&r.push(["SameSite","None"]),(n==null?void 0:n.sameSite)==="strict"&&r.push(["SameSite","Strict"]),n!=null&&n.secure&&r.push(["Secure"]),r.map(i=>i.join("=")).join("; ")}function Cv(t){const e=new Map,n=t.split("; ");for(const r of n){const i=r.split("="),s=i[0],a=i[1]??"";s&&e.set(decodeURIComponent(s),decodeURIComponent(a))}return e}function ku(t){return`${t}-${kv}`}function bm(t){if(!t)return;const[e]=t.split(":");if(!e||e==="localhost"||/^(\d{1,3}\.){3}\d{1,3}$/.test(e))return;const n=e.split(".");return n.length>2?`.${n.slice(-2).join(".")}`:`.${e}`}function ni(t,e){return e?Cv(e).get(ku(t)):void 0}function Nv(t,e){return vm(ku(t),"",{path:"/",httpOnly:!0,secure:!0,maxAge:0,sameSite:"none",domain:e?bm(e):void 0})}function Hs(t,e,n){return vm(ku(t),e,{path:"/",httpOnly:!0,secure:!0,maxAge:Da,sameSite:"none",domain:n?bm(n):void 0})}class ee extends S{constructor(e,n){super(e,{message:JSON.stringify(n),res:new Response(JSON.stringify(n),{status:e,headers:{"Content-Type":"application/json"}})})}}var Iv=Object.defineProperty,jv=(t,e,n)=>e in t?Iv(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Jr=(t,e,n)=>jv(t,typeof e!="symbol"?e+"":e,n);const ut=o.z.object({"#text":o.z.string()}),Ov=o.z.object({"#text":o.z.string(),"@_xmlns:saml":o.z.string().optional()});o.z.object({"samlp:AuthnRequest":o.z.object({"saml:Issuer":Ov,"@_xmlns:samlp":o.z.string(),"@_xmlns:saml":o.z.string().optional(),"@_ForceAuthn":o.z.string().transform(t=>t.toLowerCase()==="true").optional(),"@_ID":o.z.string(),"@_IssueInstant":o.z.string().datetime(),"@_Destination":o.z.string().url(),"@_AssertionConsumerServiceURL":o.z.string().url().optional(),"@_ProtocolBinding":o.z.string().optional(),"@_Version":o.z.string()})});o.z.array(o.z.object({":@":o.z.object({"@_xmlns":o.z.string(),"@_entityID":o.z.string()}),EntityDescriptor:o.z.array(o.z.object({":@":o.z.object({"@_protocolSupportEnumeration":o.z.string()}),IDPSSODescriptor:o.z.array(o.z.union([o.z.object({KeyDescriptor:o.z.array(o.z.object({KeyInfo:o.z.array(o.z.object({X509Data:o.z.array(o.z.object({X509Certificate:o.z.array(ut)}))})),":@":o.z.object({"@_xmlns":o.z.string()})})),":@":o.z.object({"@_use":o.z.string()})}),o.z.object({SingleLogoutService:o.z.array(o.z.object({})),":@":o.z.object({"@_Binding":o.z.string(),"@_Location":o.z.string()})}),o.z.object({NameIDFormat:o.z.array(ut)}),o.z.object({SingleSignOnService:o.z.array(o.z.object({})),":@":o.z.object({"@_Binding":o.z.string(),"@_Location":o.z.string()})}),o.z.object({Attribute:o.z.array(o.z.object({})),":@":o.z.object({"@_Name":o.z.string(),"@_NameFormat":o.z.string(),"@_FriendlyName":o.z.string(),"@_xmlns":o.z.string()})})]))}))}));const Tv=o.z.object({"saml:Attribute":o.z.array(o.z.object({"saml:AttributeValue":o.z.array(o.z.object({"#text":o.z.string()})),":@":o.z.object({"@_xmlns:xs":o.z.string().optional(),"@_xmlns:xsi":o.z.string(),"@_xsi:type":o.z.string()}).optional()})),":@":o.z.object({"@_Name":o.z.string(),"@_NameFormat":o.z.string(),"@_FriendlyName":o.z.string().optional()})}),Pv=o.z.object({"ds:Transform":o.z.array(o.z.any()),":@":o.z.object({"@_Algorithm":o.z.string()})}),lf=o.z.object({"ds:Signature":o.z.array(o.z.union([o.z.object({"ds:SignedInfo":o.z.array(o.z.union([o.z.object({"ds:CanonicalizationMethod":o.z.array(o.z.object({":@":o.z.object({"@_Algorithm":o.z.string()})}))}),o.z.object({"ds:SignatureMethod":o.z.array(o.z.object({":@":o.z.object({"@_Algorithm":o.z.string()})}))}),o.z.object({"ds:Reference":o.z.array(o.z.union([o.z.object({"ds:Transforms":o.z.array(Pv)}),o.z.object({"ds:DigestMethod":o.z.array(o.z.object({":@":o.z.object({"@_Algorithm":o.z.string()})}))}),o.z.object({"ds:DigestValue":o.z.array(ut)})])),":@":o.z.object({"@_URI":o.z.string().optional()}).optional()})]))}),o.z.object({"ds:SignatureValue":o.z.array(ut)}),o.z.object({"ds:KeyInfo":o.z.array(o.z.union([o.z.object({"ds:KeyValue":o.z.array(o.z.object({"ds:RSAKeyValue":o.z.array(o.z.union([o.z.object({"ds:Modulus":o.z.array(ut)}),o.z.object({"ds:Exponent":o.z.array(ut)})]))}))}),o.z.object({"ds:X509Data":o.z.array(o.z.object({"ds:X509Certificate":o.z.array(ut)}))}),o.z.object({"ds:KeyValue":o.z.array(o.z.object({"ds:RSAKeyValue":o.z.array(o.z.union([o.z.object({"ds:Modulus":o.z.array(ut)}),o.z.object({"ds:Exponent":o.z.array(ut)})]))})),"ds:X509Data":o.z.array(o.z.object({"ds:X509Certificate":o.z.array(ut)}))})]))})])),":@":o.z.object({"@_xmlns:ds":o.z.string().optional()}).optional()});o.z.array(o.z.object({"samlp:Response":o.z.array(o.z.union([o.z.object({"saml:Issuer":o.z.array(ut)}),lf,o.z.object({"samlp:Status":o.z.array(o.z.object({"samlp:StatusCode":o.z.array(ut),":@":o.z.object({"@_Value":o.z.string()})}))}),o.z.object({"saml:Assertion":o.z.array(o.z.union([o.z.object({"saml:Issuer":o.z.array(ut)}),lf,o.z.object({"saml:Subject":o.z.array(o.z.union([o.z.object({"saml:NameID":o.z.array(ut),":@":o.z.object({"@_Format":o.z.string()})}),o.z.object({"saml:SubjectConfirmation":o.z.array(o.z.object({"saml:SubjectConfirmationData":o.z.array(o.z.any()),":@":o.z.object({"@_InResponseTo":o.z.string(),"@_NotOnOrAfter":o.z.string(),"@_Recipient":o.z.string()})})),":@":o.z.object({"@_Method":o.z.string()})})]))}),o.z.object({"saml:Conditions":o.z.array(o.z.object({"saml:AudienceRestriction":o.z.array(o.z.object({"saml:Audience":o.z.array(ut)}))})),":@":o.z.object({"@_NotBefore":o.z.string(),"@_NotOnOrAfter":o.z.string()})}),o.z.object({"saml:AuthnStatement":o.z.array(o.z.object({"saml:AuthnContext":o.z.array(o.z.object({"saml:AuthnContextClassRef":o.z.array(ut)}))})),":@":o.z.object({"@_AuthnInstant":o.z.string(),"@_SessionIndex":o.z.string(),"@_SessionNotOnOrAfter":o.z.string()})}),o.z.object({"saml:AttributeStatement":o.z.array(Tv)})])),":@":o.z.object({"@_xmlns":o.z.string(),"@_ID":o.z.string(),"@_IssueInstant":o.z.string(),"@_Version":o.z.string()})})])),":@":o.z.object({"@_xmlns:samlp":o.z.string(),"@_xmlns:saml":o.z.string(),"@_Destination":o.z.string(),"@_ID":o.z.string(),"@_InResponseTo":o.z.string(),"@_IssueInstant":o.z.string(),"@_Version":o.z.string()})}));var xu={},Ma={};(function(t){const e=":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD",n=e+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040",r="["+e+"]["+n+"]*",i=new RegExp("^"+r+"$"),s=function(c,l){const d=[];let u=l.exec(c);for(;u;){const f=[];f.startIndex=l.lastIndex-u[0].length;const h=u.length;for(let m=0;m<h;m++)f.push(u[m]);d.push(f),u=l.exec(c)}return d},a=function(c){const l=i.exec(c);return!(l===null||typeof l>"u")};t.isExist=function(c){return typeof c<"u"},t.isEmptyObject=function(c){return Object.keys(c).length===0},t.merge=function(c,l,d){if(l){const u=Object.keys(l),f=u.length;for(let h=0;h<f;h++)d==="strict"?c[u[h]]=[l[u[h]]]:c[u[h]]=l[u[h]]}},t.getValue=function(c){return t.isExist(c)?c:""},t.isName=a,t.getAllMatches=s,t.nameRegexp=r})(Ma);const Su=Ma,Rv={allowBooleanAttributes:!1,unpairedTags:[]};xu.validate=function(t,e){e=Object.assign({},Rv,e);const n=[];let r=!1,i=!1;t[0]==="\uFEFF"&&(t=t.substr(1));for(let s=0;s<t.length;s++)if(t[s]==="<"&&t[s+1]==="?"){if(s+=2,s=uf(t,s),s.err)return s}else if(t[s]==="<"){let a=s;if(s++,t[s]==="!"){s=pf(t,s);continue}else{let c=!1;t[s]==="/"&&(c=!0,s++);let l="";for(;s<t.length&&t[s]!==">"&&t[s]!==" "&&t[s]!==" "&&t[s]!==`
5
+ */(function(e,n){typeof iv=="function"&&t&&t.exports?t.exports=n():(e.dcodeIO=e.dcodeIO||{}).bcrypt=n()})(Al,function(){var e={},n=null;function r(N){if(t&&t.exports)try{return av.randomBytes(N)}catch{}try{var C;return(self.crypto||self.msCrypto).getRandomValues(C=new Uint32Array(N)),Array.prototype.slice.call(C)}catch{}if(!n)throw Error("Neither WebCryptoAPI nor a crypto module is available. Use bcrypt.setRandomFallback to set an alternative");return n(N)}var i=!1;try{r(1),i=!0}catch{}n=null,e.setRandomFallback=function(N){n=N},e.genSaltSync=function(N,C){if(N=N||v,typeof N!="number")throw Error("Illegal arguments: "+typeof N+", "+typeof C);N<4?N=4:N>31&&(N=31);var z=[];return z.push("$2a$"),N<10&&z.push("0"),z.push(N.toString()),z.push("$"),z.push(f(r(y),y)),z.join("")},e.genSalt=function(N,C,z){if(typeof C=="function"&&(z=C,C=void 0),typeof N=="function"&&(z=N,N=void 0),typeof N>"u")N=v;else if(typeof N!="number")throw Error("illegal arguments: "+typeof N);function k($){a(function(){try{$(null,e.genSaltSync(N))}catch(I){$(I)}})}if(z){if(typeof z!="function")throw Error("Illegal callback: "+typeof z);k(z)}else return new Promise(function($,I){k(function(L,q){if(L){I(L);return}$(q)})})},e.hashSync=function(N,C){if(typeof C>"u"&&(C=v),typeof C=="number"&&(C=e.genSaltSync(C)),typeof N!="string"||typeof C!="string")throw Error("Illegal arguments: "+typeof N+", "+typeof C);return de(N,C)},e.hash=function(N,C,z,k){function $(I){typeof N=="string"&&typeof C=="number"?e.genSalt(C,function(L,q){de(N,q,I,k)}):typeof N=="string"&&typeof C=="string"?de(N,C,I,k):a(I.bind(this,Error("Illegal arguments: "+typeof N+", "+typeof C)))}if(z){if(typeof z!="function")throw Error("Illegal callback: "+typeof z);$(z)}else return new Promise(function(I,L){$(function(q,F){if(q){L(q);return}I(F)})})};function s(N,C){for(var z=0,k=0,$=0,I=N.length;$<I;++$)N.charCodeAt($)===C.charCodeAt($)?++z:++k;return z<0?!1:k===0}e.compareSync=function(N,C){if(typeof N!="string"||typeof C!="string")throw Error("Illegal arguments: "+typeof N+", "+typeof C);return C.length!==60?!1:s(e.hashSync(N,C.substr(0,C.length-31)),C)},e.compare=function(N,C,z,k){function $(I){if(typeof N!="string"||typeof C!="string"){a(I.bind(this,Error("Illegal arguments: "+typeof N+", "+typeof C)));return}if(C.length!==60){a(I.bind(this,null,!1));return}e.hash(N,C.substr(0,29),function(L,q){L?I(L):I(null,s(q,C))},k)}if(z){if(typeof z!="function")throw Error("Illegal callback: "+typeof z);$(z)}else return new Promise(function(I,L){$(function(q,F){if(q){L(q);return}I(F)})})},e.getRounds=function(N){if(typeof N!="string")throw Error("Illegal arguments: "+typeof N);return parseInt(N.split("$")[2],10)},e.getSalt=function(N){if(typeof N!="string")throw Error("Illegal arguments: "+typeof N);if(N.length!==60)throw Error("Illegal hash length: "+N.length+" != 60");return N.substring(0,29)};var a=typeof process<"u"&&process&&typeof process.nextTick=="function"?typeof setImmediate=="function"?setImmediate:process.nextTick:setTimeout;function c(N){var C=[],z=0;return m.encodeUTF16toUTF8(function(){return z>=N.length?null:N.charCodeAt(z++)},function(k){C.push(k)}),C}var l="./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),d=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,54,55,56,57,58,59,60,61,62,63,-1,-1,-1,-1,-1,-1,-1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,-1,-1,-1,-1,-1,-1,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,-1,-1,-1,-1,-1],u=String.fromCharCode;function f(N,C){var z=0,k=[],$,I;if(C<=0||C>N.length)throw Error("Illegal len: "+C);for(;z<C;){if($=N[z++]&255,k.push(l[$>>2&63]),$=($&3)<<4,z>=C){k.push(l[$&63]);break}if(I=N[z++]&255,$|=I>>4&15,k.push(l[$&63]),$=(I&15)<<2,z>=C){k.push(l[$&63]);break}I=N[z++]&255,$|=I>>6&3,k.push(l[$&63]),k.push(l[I&63])}return k.join("")}function h(N,C){var z=0,k=N.length,$=0,I=[],L,q,F,Z,se,D;if(C<=0)throw Error("Illegal len: "+C);for(;z<k-1&&$<C&&(D=N.charCodeAt(z++),L=D<d.length?d[D]:-1,D=N.charCodeAt(z++),q=D<d.length?d[D]:-1,!(L==-1||q==-1||(se=L<<2>>>0,se|=(q&48)>>4,I.push(u(se)),++$>=C||z>=k)||(D=N.charCodeAt(z++),F=D<d.length?d[D]:-1,F==-1)||(se=(q&15)<<4>>>0,se|=(F&60)>>2,I.push(u(se)),++$>=C||z>=k)));)D=N.charCodeAt(z++),Z=D<d.length?d[D]:-1,se=(F&3)<<6>>>0,se|=Z,I.push(u(se)),++$;var fe=[];for(z=0;z<$;z++)fe.push(I[z].charCodeAt(0));return fe}var m=function(){var N={};return N.MAX_CODEPOINT=1114111,N.encodeUTF8=function(C,z){var k=null;for(typeof C=="number"&&(k=C,C=function(){return null});k!==null||(k=C())!==null;)k<128?z(k&127):k<2048?(z(k>>6&31|192),z(k&63|128)):k<65536?(z(k>>12&15|224),z(k>>6&63|128),z(k&63|128)):(z(k>>18&7|240),z(k>>12&63|128),z(k>>6&63|128),z(k&63|128)),k=null},N.decodeUTF8=function(C,z){for(var k,$,I,L,q=function(F){F=F.slice(0,F.indexOf(null));var Z=Error(F.toString());throw Z.name="TruncatedError",Z.bytes=F,Z};(k=C())!==null;)if(!(k&128))z(k);else if((k&224)===192)($=C())===null&&q([k,$]),z((k&31)<<6|$&63);else if((k&240)===224)(($=C())===null||(I=C())===null)&&q([k,$,I]),z((k&15)<<12|($&63)<<6|I&63);else if((k&248)===240)(($=C())===null||(I=C())===null||(L=C())===null)&&q([k,$,I,L]),z((k&7)<<18|($&63)<<12|(I&63)<<6|L&63);else throw RangeError("Illegal starting byte: "+k)},N.UTF16toUTF8=function(C,z){for(var k,$=null;(k=$!==null?$:C())!==null;){if(k>=55296&&k<=57343&&($=C())!==null&&$>=56320&&$<=57343){z((k-55296)*1024+$-56320+65536),$=null;continue}z(k)}$!==null&&z($)},N.UTF8toUTF16=function(C,z){var k=null;for(typeof C=="number"&&(k=C,C=function(){return null});k!==null||(k=C())!==null;)k<=65535?z(k):(k-=65536,z((k>>10)+55296),z(k%1024+56320)),k=null},N.encodeUTF16toUTF8=function(C,z){N.UTF16toUTF8(C,function(k){N.encodeUTF8(k,z)})},N.decodeUTF8toUTF16=function(C,z){N.decodeUTF8(C,function(k){N.UTF8toUTF16(k,z)})},N.calculateCodePoint=function(C){return C<128?1:C<2048?2:C<65536?3:4},N.calculateUTF8=function(C){for(var z,k=0;(z=C())!==null;)k+=N.calculateCodePoint(z);return k},N.calculateUTF16asUTF8=function(C){var z=0,k=0;return N.UTF16toUTF8(C,function($){++z,k+=N.calculateCodePoint($)}),[z,k]},N}();Date.now=Date.now||function(){return+new Date};var y=16,v=10,b=16,A=100,O=[608135816,2242054355,320440878,57701188,2752067618,698298832,137296536,3964562569,1160258022,953160567,3193202383,887688300,3232508343,3380367581,1065670069,3041331479,2450970073,2306472731],U=[3509652390,2564797868,805139163,3491422135,3101798381,1780907670,3128725573,4046225305,614570311,3012652279,134345442,2240740374,1667834072,1901547113,2757295779,4103290238,227898511,1921955416,1904987480,2182433518,2069144605,3260701109,2620446009,720527379,3318853667,677414384,3393288472,3101374703,2390351024,1614419982,1822297739,2954791486,3608508353,3174124327,2024746970,1432378464,3864339955,2857741204,1464375394,1676153920,1439316330,715854006,3033291828,289532110,2706671279,2087905683,3018724369,1668267050,732546397,1947742710,3462151702,2609353502,2950085171,1814351708,2050118529,680887927,999245976,1800124847,3300911131,1713906067,1641548236,4213287313,1216130144,1575780402,4018429277,3917837745,3693486850,3949271944,596196993,3549867205,258830323,2213823033,772490370,2760122372,1774776394,2652871518,566650946,4142492826,1728879713,2882767088,1783734482,3629395816,2517608232,2874225571,1861159788,326777828,3124490320,2130389656,2716951837,967770486,1724537150,2185432712,2364442137,1164943284,2105845187,998989502,3765401048,2244026483,1075463327,1455516326,1322494562,910128902,469688178,1117454909,936433444,3490320968,3675253459,1240580251,122909385,2157517691,634681816,4142456567,3825094682,3061402683,2540495037,79693498,3249098678,1084186820,1583128258,426386531,1761308591,1047286709,322548459,995290223,1845252383,2603652396,3431023940,2942221577,3202600964,3727903485,1712269319,422464435,3234572375,1170764815,3523960633,3117677531,1434042557,442511882,3600875718,1076654713,1738483198,4213154764,2393238008,3677496056,1014306527,4251020053,793779912,2902807211,842905082,4246964064,1395751752,1040244610,2656851899,3396308128,445077038,3742853595,3577915638,679411651,2892444358,2354009459,1767581616,3150600392,3791627101,3102740896,284835224,4246832056,1258075500,768725851,2589189241,3069724005,3532540348,1274779536,3789419226,2764799539,1660621633,3471099624,4011903706,913787905,3497959166,737222580,2514213453,2928710040,3937242737,1804850592,3499020752,2949064160,2386320175,2390070455,2415321851,4061277028,2290661394,2416832540,1336762016,1754252060,3520065937,3014181293,791618072,3188594551,3933548030,2332172193,3852520463,3043980520,413987798,3465142937,3030929376,4245938359,2093235073,3534596313,375366246,2157278981,2479649556,555357303,3870105701,2008414854,3344188149,4221384143,3956125452,2067696032,3594591187,2921233993,2428461,544322398,577241275,1471733935,610547355,4027169054,1432588573,1507829418,2025931657,3646575487,545086370,48609733,2200306550,1653985193,298326376,1316178497,3007786442,2064951626,458293330,2589141269,3591329599,3164325604,727753846,2179363840,146436021,1461446943,4069977195,705550613,3059967265,3887724982,4281599278,3313849956,1404054877,2845806497,146425753,1854211946,1266315497,3048417604,3681880366,3289982499,290971e4,1235738493,2632868024,2414719590,3970600049,1771706367,1449415276,3266420449,422970021,1963543593,2690192192,3826793022,1062508698,1531092325,1804592342,2583117782,2714934279,4024971509,1294809318,4028980673,1289560198,2221992742,1669523910,35572830,157838143,1052438473,1016535060,1802137761,1753167236,1386275462,3080475397,2857371447,1040679964,2145300060,2390574316,1461121720,2956646967,4031777805,4028374788,33600511,2920084762,1018524850,629373528,3691585981,3515945977,2091462646,2486323059,586499841,988145025,935516892,3367335476,2599673255,2839830854,265290510,3972581182,2759138881,3795373465,1005194799,847297441,406762289,1314163512,1332590856,1866599683,4127851711,750260880,613907577,1450815602,3165620655,3734664991,3650291728,3012275730,3704569646,1427272223,778793252,1343938022,2676280711,2052605720,1946737175,3164576444,3914038668,3967478842,3682934266,1661551462,3294938066,4011595847,840292616,3712170807,616741398,312560963,711312465,1351876610,322626781,1910503582,271666773,2175563734,1594956187,70604529,3617834859,1007753275,1495573769,4069517037,2549218298,2663038764,504708206,2263041392,3941167025,2249088522,1514023603,1998579484,1312622330,694541497,2582060303,2151582166,1382467621,776784248,2618340202,3323268794,2497899128,2784771155,503983604,4076293799,907881277,423175695,432175456,1378068232,4145222326,3954048622,3938656102,3820766613,2793130115,2977904593,26017576,3274890735,3194772133,1700274565,1756076034,4006520079,3677328699,720338349,1533947780,354530856,688349552,3973924725,1637815568,332179504,3949051286,53804574,2852348879,3044236432,1282449977,3583942155,3416972820,4006381244,1617046695,2628476075,3002303598,1686838959,431878346,2686675385,1700445008,1080580658,1009431731,832498133,3223435511,2605976345,2271191193,2516031870,1648197032,4164389018,2548247927,300782431,375919233,238389289,3353747414,2531188641,2019080857,1475708069,455242339,2609103871,448939670,3451063019,1395535956,2413381860,1841049896,1491858159,885456874,4264095073,4001119347,1565136089,3898914787,1108368660,540939232,1173283510,2745871338,3681308437,4207628240,3343053890,4016749493,1699691293,1103962373,3625875870,2256883143,3830138730,1031889488,3479347698,1535977030,4236805024,3251091107,2132092099,1774941330,1199868427,1452454533,157007616,2904115357,342012276,595725824,1480756522,206960106,497939518,591360097,863170706,2375253569,3596610801,1814182875,2094937945,3421402208,1082520231,3463918190,2785509508,435703966,3908032597,1641649973,2842273706,3305899714,1510255612,2148256476,2655287854,3276092548,4258621189,236887753,3681803219,274041037,1734335097,3815195456,3317970021,1899903192,1026095262,4050517792,356393447,2410691914,3873677099,3682840055,3913112168,2491498743,4132185628,2489919796,1091903735,1979897079,3170134830,3567386728,3557303409,857797738,1136121015,1342202287,507115054,2535736646,337727348,3213592640,1301675037,2528481711,1895095763,1721773893,3216771564,62756741,2142006736,835421444,2531993523,1442658625,3659876326,2882144922,676362277,1392781812,170690266,3921047035,1759253602,3611846912,1745797284,664899054,1329594018,3901205900,3045908486,2062866102,2865634940,3543621612,3464012697,1080764994,553557557,3656615353,3996768171,991055499,499776247,1265440854,648242737,3940784050,980351604,3713745714,1749149687,3396870395,4211799374,3640570775,1161844396,3125318951,1431517754,545492359,4268468663,3499529547,1437099964,2702547544,3433638243,2581715763,2787789398,1060185593,1593081372,2418618748,4260947970,69676912,2159744348,86519011,2512459080,3838209314,1220612927,3339683548,133810670,1090789135,1078426020,1569222167,845107691,3583754449,4072456591,1091646820,628848692,1613405280,3757631651,526609435,236106946,48312990,2942717905,3402727701,1797494240,859738849,992217954,4005476642,2243076622,3870952857,3732016268,765654824,3490871365,2511836413,1685915746,3888969200,1414112111,2273134842,3281911079,4080962846,172450625,2569994100,980381355,4109958455,2819808352,2716589560,2568741196,3681446669,3329971472,1835478071,660984891,3704678404,4045999559,3422617507,3040415634,1762651403,1719377915,3470491036,2693910283,3642056355,3138596744,1364962596,2073328063,1983633131,926494387,3423689081,2150032023,4096667949,1749200295,3328846651,309677260,2016342300,1779581495,3079819751,111262694,1274766160,443224088,298511866,1025883608,3806446537,1145181785,168956806,3641502830,3584813610,1689216846,3666258015,3200248200,1692713982,2646376535,4042768518,1618508792,1610833997,3523052358,4130873264,2001055236,3610705100,2202168115,4028541809,2961195399,1006657119,2006996926,3186142756,1430667929,3210227297,1314452623,4074634658,4101304120,2273951170,1399257539,3367210612,3027628629,1190975929,2062231137,2333990788,2221543033,2438960610,1181637006,548689776,2362791313,3372408396,3104550113,3145860560,296247880,1970579870,3078560182,3769228297,1714227617,3291629107,3898220290,166772364,1251581989,493813264,448347421,195405023,2709975567,677966185,3703036547,1463355134,2715995803,1338867538,1343315457,2802222074,2684532164,233230375,2599980071,2000651841,3277868038,1638401717,4028070440,3237316320,6314154,819756386,300326615,590932579,1405279636,3267499572,3150704214,2428286686,3959192993,3461946742,1862657033,1266418056,963775037,2089974820,2263052895,1917689273,448879540,3550394620,3981727096,150775221,3627908307,1303187396,508620638,2975983352,2726630617,1817252668,1876281319,1457606340,908771278,3720792119,3617206836,2455994898,1729034894,1080033504,976866871,3556439503,2881648439,1522871579,1555064734,1336096578,3548522304,2579274686,3574697629,3205460757,3593280638,3338716283,3079412587,564236357,2993598910,1781952180,1464380207,3163844217,3332601554,1699332808,1393555694,1183702653,3581086237,1288719814,691649499,2847557200,2895455976,3193889540,2717570544,1781354906,1676643554,2592534050,3230253752,1126444790,2770207658,2633158820,2210423226,2615765581,2414155088,3127139286,673620729,2805611233,1269405062,4015350505,3341807571,4149409754,1057255273,2012875353,2162469141,2276492801,2601117357,993977747,3918593370,2654263191,753973209,36408145,2530585658,25011837,3520020182,2088578344,530523599,2918365339,1524020338,1518925132,3760827505,3759777254,1202760957,3985898139,3906192525,674977740,4174734889,2031300136,2019492241,3983892565,4153806404,3822280332,352677332,2297720250,60907813,90501309,3286998549,1016092578,2535922412,2839152426,457141659,509813237,4120667899,652014361,1966332200,2975202805,55981186,2327461051,676427537,3255491064,2882294119,3433927263,1307055953,942726286,933058658,2468411793,3933900994,4215176142,1361170020,2001714738,2830558078,3274259782,1222529897,1679025792,2729314320,3714953764,1770335741,151462246,3013232138,1682292957,1483529935,471910574,1539241949,458788160,3436315007,1807016891,3718408830,978976581,1043663428,3165965781,1927990952,4200891579,2372276910,3208408903,3533431907,1412390302,2931980059,4132332400,1947078029,3881505623,4168226417,2941484381,1077988104,1320477388,886195818,18198404,3786409e3,2509781533,112762804,3463356488,1866414978,891333506,18488651,661792760,1628790961,3885187036,3141171499,876946877,2693282273,1372485963,791857591,2686433993,3759982718,3167212022,3472953795,2716379847,445679433,3561995674,3504004811,3574258232,54117162,3331405415,2381918588,3769707343,4154350007,1140177722,4074052095,668550556,3214352940,367459370,261225585,2610173221,4209349473,3468074219,3265815641,314222801,3066103646,3808782860,282218597,3406013506,3773591054,379116347,1285071038,846784868,2669647154,3771962079,3550491691,2305946142,453669953,1268987020,3317592352,3279303384,3744833421,2610507566,3859509063,266596637,3847019092,517658769,3462560207,3443424879,370717030,4247526661,2224018117,4143653529,4112773975,2788324899,2477274417,1456262402,2901442914,1517677493,1846949527,2295493580,3734397586,2176403920,1280348187,1908823572,3871786941,846861322,1172426758,3287448474,3383383037,1655181056,3139813346,901632758,1897031941,2986607138,3066810236,3447102507,1393639104,373351379,950779232,625454576,3124240540,4148612726,2007998917,544563296,2244738638,2330496472,2058025392,1291430526,424198748,50039436,29584100,3605783033,2429876329,2791104160,1057563949,3255363231,3075367218,3463963227,1469046755,985887462],T=[1332899944,1700884034,1701343084,1684370003,1668446532,1869963892];function R(N,C,z,k){var $,I=N[C],L=N[C+1];return I^=z[0],$=k[I>>>24],$+=k[256|I>>16&255],$^=k[512|I>>8&255],$+=k[768|I&255],L^=$^z[1],$=k[L>>>24],$+=k[256|L>>16&255],$^=k[512|L>>8&255],$+=k[768|L&255],I^=$^z[2],$=k[I>>>24],$+=k[256|I>>16&255],$^=k[512|I>>8&255],$+=k[768|I&255],L^=$^z[3],$=k[L>>>24],$+=k[256|L>>16&255],$^=k[512|L>>8&255],$+=k[768|L&255],I^=$^z[4],$=k[I>>>24],$+=k[256|I>>16&255],$^=k[512|I>>8&255],$+=k[768|I&255],L^=$^z[5],$=k[L>>>24],$+=k[256|L>>16&255],$^=k[512|L>>8&255],$+=k[768|L&255],I^=$^z[6],$=k[I>>>24],$+=k[256|I>>16&255],$^=k[512|I>>8&255],$+=k[768|I&255],L^=$^z[7],$=k[L>>>24],$+=k[256|L>>16&255],$^=k[512|L>>8&255],$+=k[768|L&255],I^=$^z[8],$=k[I>>>24],$+=k[256|I>>16&255],$^=k[512|I>>8&255],$+=k[768|I&255],L^=$^z[9],$=k[L>>>24],$+=k[256|L>>16&255],$^=k[512|L>>8&255],$+=k[768|L&255],I^=$^z[10],$=k[I>>>24],$+=k[256|I>>16&255],$^=k[512|I>>8&255],$+=k[768|I&255],L^=$^z[11],$=k[L>>>24],$+=k[256|L>>16&255],$^=k[512|L>>8&255],$+=k[768|L&255],I^=$^z[12],$=k[I>>>24],$+=k[256|I>>16&255],$^=k[512|I>>8&255],$+=k[768|I&255],L^=$^z[13],$=k[L>>>24],$+=k[256|L>>16&255],$^=k[512|L>>8&255],$+=k[768|L&255],I^=$^z[14],$=k[I>>>24],$+=k[256|I>>16&255],$^=k[512|I>>8&255],$+=k[768|I&255],L^=$^z[15],$=k[L>>>24],$+=k[256|L>>16&255],$^=k[512|L>>8&255],$+=k[768|L&255],I^=$^z[16],N[C]=L^z[b+1],N[C+1]=I,N}function W(N,C){for(var z=0,k=0;z<4;++z)k=k<<8|N[C]&255,C=(C+1)%N.length;return{key:k,offp:C}}function ne(N,C,z){for(var k=0,$=[0,0],I=C.length,L=z.length,q,F=0;F<I;F++)q=W(N,k),k=q.offp,C[F]=C[F]^q.key;for(F=0;F<I;F+=2)$=R($,0,C,z),C[F]=$[0],C[F+1]=$[1];for(F=0;F<L;F+=2)$=R($,0,C,z),z[F]=$[0],z[F+1]=$[1]}function Q(N,C,z,k){for(var $=0,I=[0,0],L=z.length,q=k.length,F,Z=0;Z<L;Z++)F=W(C,$),$=F.offp,z[Z]=z[Z]^F.key;for($=0,Z=0;Z<L;Z+=2)F=W(N,$),$=F.offp,I[0]^=F.key,F=W(N,$),$=F.offp,I[1]^=F.key,I=R(I,0,z,k),z[Z]=I[0],z[Z+1]=I[1];for(Z=0;Z<q;Z+=2)F=W(N,$),$=F.offp,I[0]^=F.key,F=W(N,$),$=F.offp,I[1]^=F.key,I=R(I,0,z,k),k[Z]=I[0],k[Z+1]=I[1]}function K(N,C,z,k,$){var I=T.slice(),L=I.length,q;if(z<4||z>31)if(q=Error("Illegal number of rounds (4-31): "+z),k){a(k.bind(this,q));return}else throw q;if(C.length!==y)if(q=Error("Illegal salt length: "+C.length+" != "+y),k){a(k.bind(this,q));return}else throw q;z=1<<z>>>0;var F,Z,se=0,D;Int32Array?(F=new Int32Array(O),Z=new Int32Array(U)):(F=O.slice(),Z=U.slice()),Q(C,N,F,Z);function fe(){if($&&$(se/z),se<z)for(var ce=Date.now();se<z&&(se=se+1,ne(N,F,Z),ne(C,F,Z),!(Date.now()-ce>A)););else{for(se=0;se<64;se++)for(D=0;D<L>>1;D++)R(I,D<<1,F,Z);var ue=[];for(se=0;se<L;se++)ue.push((I[se]>>24&255)>>>0),ue.push((I[se]>>16&255)>>>0),ue.push((I[se]>>8&255)>>>0),ue.push((I[se]&255)>>>0);if(k){k(null,ue);return}else return ue}k&&a(fe)}if(typeof k<"u")fe();else for(var $e;;)if(typeof($e=fe())<"u")return $e||[]}function de(N,C,z,k){var $;if(typeof N!="string"||typeof C!="string")if($=Error("Invalid string / salt: Not a string"),z){a(z.bind(this,$));return}else throw $;var I,L;if(C.charAt(0)!=="$"||C.charAt(1)!=="2")if($=Error("Invalid salt version: "+C.substring(0,2)),z){a(z.bind(this,$));return}else throw $;if(C.charAt(2)==="$")I="\0",L=3;else{if(I=C.charAt(2),I!=="a"&&I!=="b"&&I!=="y"||C.charAt(3)!=="$")if($=Error("Invalid salt revision: "+C.substring(2,4)),z){a(z.bind(this,$));return}else throw $;L=4}if(C.charAt(L+2)>"$")if($=Error("Missing salt rounds"),z){a(z.bind(this,$));return}else throw $;var q=parseInt(C.substring(L,L+1),10)*10,F=parseInt(C.substring(L+1,L+2),10),Z=q+F,se=C.substring(L+3,L+25);N+=I>="a"?"\0":"";var D=c(N),fe=h(se,y);function $e(ce){var ue=[];return ue.push("$2"),I>="a"&&ue.push(I),ue.push("$"),Z<10&&ue.push("0"),ue.push(Z.toString()),ue.push("$"),ue.push(f(fe,fe.length)),ue.push(f(ce,T.length*4-1)),ue.join("")}if(typeof z>"u")return $e(K(D,fe,Z));K(D,fe,Z,function(ce,ue){ce?z(ce,null):z(null,$e(ue))},k)}return e.encodeBase64=f,e.decodeBase64=h,e})})(gm);var cv=gm.exports;const ti=hm(cv),lv="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let dv=t=>crypto.getRandomValues(new Uint8Array(t)),uv=(t,e,n)=>{let r=(2<<Math.log2(t.length-1))-1,i=-~(1.6*r*e/t.length);return(s=e)=>{let a="";for(;;){let c=n(i),l=i;for(;l--;)if(a+=t[c[l]&r]||"",a.length===s)return a}}},mm=(t,e=21)=>uv(t,e,dv),Ne=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t));for(;t--;)e+=lv[n[t]&63];return e};const pv=24;function La(){return mm("0123456789abcdef",pv)()}function ns(t){if(!t.includes("|"))return console.error("Invalid user_id format"),t;const[,e]=t.split("|");return e}function fv(t){return async(e,n)=>{if(!n.email||!n.email_verified)return t.users.create(e,n);const r=await Cu({userAdapter:t.users,tenant_id:e,email:n.email});if(!r)return t.users.create(e,n);await t.users.create(e,{...n,linked_to:r.user_id});const i=await t.users.get(e,r.user_id);if(!i)throw new Error("Failed to fetch primary user after linking");return i}}function be(t,e){return{type:e.type,description:e.description||"",ip:t.var.ip,user_agent:t.var.useragent||"",auth0_client:t.var.auth0_client,date:new Date().toISOString(),details:{request:{method:t.req.method,path:t.req.path,qs:t.req.queries(),body:e.body||t.var.body||""}},isMobile:!1,client_id:t.var.client_id,client_name:"",user_id:e.userId||t.var.user_id||"",hostname:t.req.header("host")||"",user_name:t.var.username||"",connection_id:"",connection:e.connection||t.var.connection||"",strategy:e.strategy||"",strategy_type:e.strategy_type||"",audience:e.audience||"",scope:e.scope?e.scope.split(" "):[]}}class qs{constructor(e,n){ae(this,"value");ae(this,"unit");this.value=e,this.unit=n}milliseconds(){return this.unit==="ms"?this.value:this.unit==="s"?this.value*1e3:this.unit==="m"?this.value*1e3*60:this.unit==="h"?this.value*1e3*60*60:this.unit==="d"?this.value*1e3*60*60*24:this.value*1e3*60*60*24*7}seconds(){return this.milliseconds()/1e3}transform(e){return new qs(Math.round(this.milliseconds()*e),"ms")}}class hv{constructor(e){ae(this,"hash");this.hash=e}async verify(e,n,r){const i=await crypto.subtle.importKey("spki",e,{name:"RSASSA-PKCS1-v1_5",hash:this.hash},!1,["verify"]);return await crypto.subtle.verify("RSASSA-PKCS1-v1_5",i,n,r)}async sign(e,n){const r=await crypto.subtle.importKey("pkcs8",e,{name:"RSASSA-PKCS1-v1_5",hash:this.hash},!1,["sign"]);return await crypto.subtle.sign("RSASSA-PKCS1-v1_5",r,n)}async generateKeyPair(e){const n=await crypto.subtle.generateKey({name:"RSASSA-PKCS1-v1_5",hash:this.hash,modulusLength:e??2048,publicExponent:new Uint8Array([1,0,1])},!0,["sign"]),r=await crypto.subtle.exportKey("pkcs8",n.privateKey),i=await crypto.subtle.exportKey("spki",n.publicKey);return{privateKey:r,publicKey:i}}}async function _m(t){return await crypto.subtle.digest("SHA-256",t)}const af="0123456789abcdef";function El(t){const e=new Uint8Array(t);let n="";for(let r=0;r<e.length;r++){const i=e[r]>>4;n+=af[i];const s=e[r]&15;n+=af[s]}return n}class ym{constructor(e,n){ae(this,"alphabet");ae(this,"padding");ae(this,"decodeMap",new Map);if(e.length!==32)throw new Error("Invalid alphabet");if(this.alphabet=e,this.padding=(n==null?void 0:n.padding)??"=",this.alphabet.includes(this.padding)||this.padding.length!==1)throw new Error("Invalid padding");for(let r=0;r<e.length;r++)this.decodeMap.set(e[r],r)}encode(e,n){let r="",i=0,s=0;for(let c=0;c<e.length;c++)for(i=i<<8|e[c],s+=8;s>=5;)s-=5,r+=this.alphabet[i>>s&31];if(s>0&&(r+=this.alphabet[i<<5-s&31]),(n==null?void 0:n.includePadding)??!0){const c=(8-r.length%8)%8;for(let l=0;l<c;l++)r+="="}return r}decode(e,n){const r=(n==null?void 0:n.strict)??!0,i=Math.ceil(e.length/8),s=[];for(let a=0;a<i;a++){let c=0;const l=[];for(let u=0;u<8;u++){const f=e[a*8+u];if(f==="="){if(a+1!==i)throw new Error(`Invalid character: ${f}`);c+=1;continue}if(f===void 0){if(r)throw new Error("Invalid data");c+=1;continue}const h=this.decodeMap.get(f)??null;if(h===null)throw new Error(`Invalid character: ${f}`);l.push(h)}if(c===8||c===7||c===5||c===2)throw new Error("Invalid padding");const d=(l[0]<<3)+(l[1]>>2);if(s.push(d),c<6){const u=((l[1]&3)<<6)+(l[2]<<1)+(l[3]>>4);s.push(u)}if(c<4){const u=((l[3]&255)<<4)+(l[4]>>1);s.push(u)}if(c<3){const u=((l[4]&1)<<7)+(l[5]<<2)+(l[6]>>3);s.push(u)}if(c<1){const u=((l[6]&7)<<5)+l[7];s.push(u)}}return Uint8Array.from(s)}}new ym("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567");new ym("0123456789ABCDEFGHIJKLMNOPQRSTUV");class wm{constructor(e,n){ae(this,"alphabet");ae(this,"padding");ae(this,"decodeMap",new Map);if(e.length!==64)throw new Error("Invalid alphabet");if(this.alphabet=e,this.padding=(n==null?void 0:n.padding)??"=",this.alphabet.includes(this.padding)||this.padding.length!==1)throw new Error("Invalid padding");for(let r=0;r<e.length;r++)this.decodeMap.set(e[r],r)}encode(e,n){let r="",i=0,s=0;for(let c=0;c<e.length;c++)for(i=i<<8|e[c],s+=8;s>=6;)s+=-6,r+=this.alphabet[i>>s&63];if(s>0&&(r+=this.alphabet[i<<6-s&63]),(n==null?void 0:n.includePadding)??!0){const c=(4-r.length%4)%4;for(let l=0;l<c;l++)r+="="}return r}decode(e,n){const r=(n==null?void 0:n.strict)??!0,i=Math.ceil(e.length/4),s=[];for(let a=0;a<i;a++){let c=0,l=0;for(let d=0;d<4;d++){const u=e[a*4+d];if(u==="="){if(a+1!==i)throw new Error(`Invalid character: ${u}`);c+=1;continue}if(u===void 0){if(r)throw new Error("Invalid data");c+=1;continue}const f=this.decodeMap.get(u)??null;if(f===null)throw new Error(`Invalid character: ${u}`);l+=f<<6*(3-d)}s.push(l>>16&255),c<2&&s.push(l>>8&255),c<1&&s.push(l&255)}return Uint8Array.from(s)}}const gv=new wm("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),fr=new wm("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");async function cf(t,e,n,r){const i={alg:t,typ:"JWT",...r==null?void 0:r.headers},s={...n};(r==null?void 0:r.audiences)!==void 0&&(s.aud=r.audiences),(r==null?void 0:r.subject)!==void 0&&(s.sub=r.subject),(r==null?void 0:r.issuer)!==void 0&&(s.iss=r.issuer),(r==null?void 0:r.jwtId)!==void 0&&(s.jti=r.jwtId),(r==null?void 0:r.expiresIn)!==void 0&&(s.exp=Math.floor(Date.now()/1e3)+r.expiresIn.seconds()),(r==null?void 0:r.notBefore)!==void 0&&(s.nbf=Math.floor(r.notBefore.getTime()/1e3)),s.iat=Math.floor(Date.now()/1e3);const a=new TextEncoder,c=fr.encode(a.encode(JSON.stringify(i)),{includePadding:!1}),l=fr.encode(a.encode(JSON.stringify(s)),{includePadding:!1}),d=a.encode([c,l].join(".")),u=await _v(t).sign(e,d),f=fr.encode(new Uint8Array(u),{includePadding:!1});return[c,l,f].join(".")}function mv(t){const e=t.split(".");return e.length!==3?null:e}function Ua(t){const e=mv(t);if(!e)return null;const n=new TextDecoder,r=fr.decode(e[0],{strict:!1}),i=fr.decode(e[1],{strict:!1}),s=JSON.parse(n.decode(r));if(typeof s!="object"||s===null||!("alg"in s)||!yv(s.alg)||"typ"in s&&s.typ!=="JWT")return null;const a=JSON.parse(n.decode(i));if(typeof a!="object"||a===null)return null;const c={algorithm:s.alg,expiresAt:null,subject:null,issuedAt:null,issuer:null,jwtId:null,audiences:null,notBefore:null};if("exp"in a){if(typeof a.exp!="number")return null;c.expiresAt=new Date(a.exp*1e3)}if("iss"in a){if(typeof a.iss!="string")return null;c.issuer=a.iss}if("sub"in a){if(typeof a.sub!="string")return null;c.subject=a.sub}if("aud"in a)if(Array.isArray(a.aud)){for(const l of a.aud)if(typeof l!="string")return null;c.audiences=a.aud}else{if(typeof a.aud!="string")return null;c.audiences=[a.aud]}if("nbf"in a){if(typeof a.nbf!="number")return null;c.notBefore=new Date(a.nbf*1e3)}if("iat"in a){if(typeof a.iat!="number")return null;c.issuedAt=new Date(a.iat*1e3)}if("jti"in a){if(typeof a.jti!="string")return null;c.jwtId=a.jti}return{value:t,header:{...s,typ:"JWT",alg:s.alg},payload:{...a},parts:e,...c}}function _v(t){return new hv(wv[t])}function yv(t){return typeof t!="string"?!1:["HS256","HS384","HS512","RS256","RS384","RS512","ES256","ES384","ES512","PS256","PS384","PS512"].includes(t)}const wv={RS256:"SHA-256",RS384:"SHA-384",RS512:"SHA-512"};function vv(){const t=new Uint8Array(32);return crypto.getRandomValues(t),fr.encode(t,{includePadding:!1})}function bv(t){try{const n=/-----BEGIN (?:RSA )?(?:PRIVATE|PUBLIC) KEY-----([^-]*)-----END (?:RSA )?(?:PRIVATE|PUBLIC) KEY-----/.exec(t);if(!n||!n[1])throw new Error("Invalid PEM format");return Uint8Array.from(atob(n[1].replace(/\s/g,"")),r=>r.charCodeAt(0)).buffer}finally{t=t.replace(/./g,"\0")}}async function $v(t,e){if(e==="plain")return t;const n=new TextEncoder().encode(t),r=await _m(n);return fr.encode(new Uint8Array(r),{includePadding:!1})}const rs=60*5,Da=30*24*60*60,_r=24*60*60,kv="auth-token",hs=30*60*1e3,Cl=7*24*60*60*1e3,xv=5*60,Sv=5*60,zv=30*60*1e3,Av=30*60*1e3,Ev=24*60*60*1e3;function vm(t,e,n){const r=[];return r.push([encodeURIComponent(t),encodeURIComponent(e)]),(n==null?void 0:n.domain)!==void 0&&r.push(["Domain",n.domain]),(n==null?void 0:n.expires)!==void 0&&r.push(["Expires",n.expires.toUTCString()]),n!=null&&n.httpOnly&&r.push(["HttpOnly"]),(n==null?void 0:n.maxAge)!==void 0&&r.push(["Max-Age",n.maxAge.toString()]),(n==null?void 0:n.path)!==void 0&&r.push(["Path",n.path]),(n==null?void 0:n.sameSite)==="lax"&&r.push(["SameSite","Lax"]),(n==null?void 0:n.sameSite)==="none"&&r.push(["SameSite","None"]),(n==null?void 0:n.sameSite)==="strict"&&r.push(["SameSite","Strict"]),n!=null&&n.secure&&r.push(["Secure"]),r.map(i=>i.join("=")).join("; ")}function Cv(t){const e=new Map,n=t.split("; ");for(const r of n){const i=r.split("="),s=i[0],a=i[1]??"";s&&e.set(decodeURIComponent(s),decodeURIComponent(a))}return e}function ku(t){return`${t}-${kv}`}function bm(t){if(!t)return;const[e]=t.split(":");if(!e||e==="localhost"||/^(\d{1,3}\.){3}\d{1,3}$/.test(e))return;const n=e.split(".");return n.length>2?`.${n.slice(-2).join(".")}`:`.${e}`}function ni(t,e){return e?Cv(e).get(ku(t)):void 0}function Nv(t,e){return vm(ku(t),"",{path:"/",httpOnly:!0,secure:!0,maxAge:0,sameSite:"none",domain:e?bm(e):void 0})}function Hs(t,e,n){return vm(ku(t),e,{path:"/",httpOnly:!0,secure:!0,maxAge:Da,sameSite:"none",domain:n?bm(n):void 0})}class ee extends S{constructor(e,n){super(e,{message:JSON.stringify(n),res:new Response(JSON.stringify(n),{status:e,headers:{"Content-Type":"application/json"}})})}}var Iv=Object.defineProperty,jv=(t,e,n)=>e in t?Iv(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Jr=(t,e,n)=>jv(t,typeof e!="symbol"?e+"":e,n);const ut=o.z.object({"#text":o.z.string()}),Ov=o.z.object({"#text":o.z.string(),"@_xmlns:saml":o.z.string().optional()});o.z.object({"samlp:AuthnRequest":o.z.object({"saml:Issuer":Ov,"@_xmlns:samlp":o.z.string(),"@_xmlns:saml":o.z.string().optional(),"@_ForceAuthn":o.z.string().transform(t=>t.toLowerCase()==="true").optional(),"@_ID":o.z.string(),"@_IssueInstant":o.z.string().datetime(),"@_Destination":o.z.string().url(),"@_AssertionConsumerServiceURL":o.z.string().url().optional(),"@_ProtocolBinding":o.z.string().optional(),"@_Version":o.z.string()})});o.z.array(o.z.object({":@":o.z.object({"@_xmlns":o.z.string(),"@_entityID":o.z.string()}),EntityDescriptor:o.z.array(o.z.object({":@":o.z.object({"@_protocolSupportEnumeration":o.z.string()}),IDPSSODescriptor:o.z.array(o.z.union([o.z.object({KeyDescriptor:o.z.array(o.z.object({KeyInfo:o.z.array(o.z.object({X509Data:o.z.array(o.z.object({X509Certificate:o.z.array(ut)}))})),":@":o.z.object({"@_xmlns":o.z.string()})})),":@":o.z.object({"@_use":o.z.string()})}),o.z.object({SingleLogoutService:o.z.array(o.z.object({})),":@":o.z.object({"@_Binding":o.z.string(),"@_Location":o.z.string()})}),o.z.object({NameIDFormat:o.z.array(ut)}),o.z.object({SingleSignOnService:o.z.array(o.z.object({})),":@":o.z.object({"@_Binding":o.z.string(),"@_Location":o.z.string()})}),o.z.object({Attribute:o.z.array(o.z.object({})),":@":o.z.object({"@_Name":o.z.string(),"@_NameFormat":o.z.string(),"@_FriendlyName":o.z.string(),"@_xmlns":o.z.string()})})]))}))}));const Tv=o.z.object({"saml:Attribute":o.z.array(o.z.object({"saml:AttributeValue":o.z.array(o.z.object({"#text":o.z.string()})),":@":o.z.object({"@_xmlns:xs":o.z.string().optional(),"@_xmlns:xsi":o.z.string(),"@_xsi:type":o.z.string()}).optional()})),":@":o.z.object({"@_Name":o.z.string(),"@_NameFormat":o.z.string(),"@_FriendlyName":o.z.string().optional()})}),Pv=o.z.object({"ds:Transform":o.z.array(o.z.any()),":@":o.z.object({"@_Algorithm":o.z.string()})}),lf=o.z.object({"ds:Signature":o.z.array(o.z.union([o.z.object({"ds:SignedInfo":o.z.array(o.z.union([o.z.object({"ds:CanonicalizationMethod":o.z.array(o.z.object({":@":o.z.object({"@_Algorithm":o.z.string()})}))}),o.z.object({"ds:SignatureMethod":o.z.array(o.z.object({":@":o.z.object({"@_Algorithm":o.z.string()})}))}),o.z.object({"ds:Reference":o.z.array(o.z.union([o.z.object({"ds:Transforms":o.z.array(Pv)}),o.z.object({"ds:DigestMethod":o.z.array(o.z.object({":@":o.z.object({"@_Algorithm":o.z.string()})}))}),o.z.object({"ds:DigestValue":o.z.array(ut)})])),":@":o.z.object({"@_URI":o.z.string().optional()}).optional()})]))}),o.z.object({"ds:SignatureValue":o.z.array(ut)}),o.z.object({"ds:KeyInfo":o.z.array(o.z.union([o.z.object({"ds:KeyValue":o.z.array(o.z.object({"ds:RSAKeyValue":o.z.array(o.z.union([o.z.object({"ds:Modulus":o.z.array(ut)}),o.z.object({"ds:Exponent":o.z.array(ut)})]))}))}),o.z.object({"ds:X509Data":o.z.array(o.z.object({"ds:X509Certificate":o.z.array(ut)}))}),o.z.object({"ds:KeyValue":o.z.array(o.z.object({"ds:RSAKeyValue":o.z.array(o.z.union([o.z.object({"ds:Modulus":o.z.array(ut)}),o.z.object({"ds:Exponent":o.z.array(ut)})]))})),"ds:X509Data":o.z.array(o.z.object({"ds:X509Certificate":o.z.array(ut)}))})]))})])),":@":o.z.object({"@_xmlns:ds":o.z.string().optional()}).optional()});o.z.array(o.z.object({"samlp:Response":o.z.array(o.z.union([o.z.object({"saml:Issuer":o.z.array(ut)}),lf,o.z.object({"samlp:Status":o.z.array(o.z.object({"samlp:StatusCode":o.z.array(ut),":@":o.z.object({"@_Value":o.z.string()})}))}),o.z.object({"saml:Assertion":o.z.array(o.z.union([o.z.object({"saml:Issuer":o.z.array(ut)}),lf,o.z.object({"saml:Subject":o.z.array(o.z.union([o.z.object({"saml:NameID":o.z.array(ut),":@":o.z.object({"@_Format":o.z.string()})}),o.z.object({"saml:SubjectConfirmation":o.z.array(o.z.object({"saml:SubjectConfirmationData":o.z.array(o.z.any()),":@":o.z.object({"@_InResponseTo":o.z.string(),"@_NotOnOrAfter":o.z.string(),"@_Recipient":o.z.string()})})),":@":o.z.object({"@_Method":o.z.string()})})]))}),o.z.object({"saml:Conditions":o.z.array(o.z.object({"saml:AudienceRestriction":o.z.array(o.z.object({"saml:Audience":o.z.array(ut)}))})),":@":o.z.object({"@_NotBefore":o.z.string(),"@_NotOnOrAfter":o.z.string()})}),o.z.object({"saml:AuthnStatement":o.z.array(o.z.object({"saml:AuthnContext":o.z.array(o.z.object({"saml:AuthnContextClassRef":o.z.array(ut)}))})),":@":o.z.object({"@_AuthnInstant":o.z.string(),"@_SessionIndex":o.z.string(),"@_SessionNotOnOrAfter":o.z.string()})}),o.z.object({"saml:AttributeStatement":o.z.array(Tv)})])),":@":o.z.object({"@_xmlns":o.z.string(),"@_ID":o.z.string(),"@_IssueInstant":o.z.string(),"@_Version":o.z.string()})})])),":@":o.z.object({"@_xmlns:samlp":o.z.string(),"@_xmlns:saml":o.z.string(),"@_Destination":o.z.string(),"@_ID":o.z.string(),"@_InResponseTo":o.z.string(),"@_IssueInstant":o.z.string(),"@_Version":o.z.string()})}));var xu={},Ma={};(function(t){const e=":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD",n=e+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040",r="["+e+"]["+n+"]*",i=new RegExp("^"+r+"$"),s=function(c,l){const d=[];let u=l.exec(c);for(;u;){const f=[];f.startIndex=l.lastIndex-u[0].length;const h=u.length;for(let m=0;m<h;m++)f.push(u[m]);d.push(f),u=l.exec(c)}return d},a=function(c){const l=i.exec(c);return!(l===null||typeof l>"u")};t.isExist=function(c){return typeof c<"u"},t.isEmptyObject=function(c){return Object.keys(c).length===0},t.merge=function(c,l,d){if(l){const u=Object.keys(l),f=u.length;for(let h=0;h<f;h++)d==="strict"?c[u[h]]=[l[u[h]]]:c[u[h]]=l[u[h]]}},t.getValue=function(c){return t.isExist(c)?c:""},t.isName=a,t.getAllMatches=s,t.nameRegexp=r})(Ma);const Su=Ma,Rv={allowBooleanAttributes:!1,unpairedTags:[]};xu.validate=function(t,e){e=Object.assign({},Rv,e);const n=[];let r=!1,i=!1;t[0]==="\uFEFF"&&(t=t.substr(1));for(let s=0;s<t.length;s++)if(t[s]==="<"&&t[s+1]==="?"){if(s+=2,s=uf(t,s),s.err)return s}else if(t[s]==="<"){let a=s;if(s++,t[s]==="!"){s=pf(t,s);continue}else{let c=!1;t[s]==="/"&&(c=!0,s++);let l="";for(;s<t.length&&t[s]!==">"&&t[s]!==" "&&t[s]!==" "&&t[s]!==`
6
6
  `&&t[s]!=="\r";s++)l+=t[s];if(l=l.trim(),l[l.length-1]==="/"&&(l=l.substring(0,l.length-1),s--),!Hv(l)){let f;return l.trim().length===0?f="Invalid space after '<'.":f="Tag '"+l+"' is an invalid name.",Fe("InvalidTag",f,mt(t,s))}const d=Uv(t,s);if(d===!1)return Fe("InvalidAttr","Attributes for '"+l+"' have open quote.",mt(t,s));let u=d.value;if(s=d.index,u[u.length-1]==="/"){const f=s-u.length;u=u.substring(0,u.length-1);const h=ff(u,e);if(h===!0)r=!0;else return Fe(h.err.code,h.err.msg,mt(t,f+h.err.line))}else if(c)if(d.tagClosed){if(u.trim().length>0)return Fe("InvalidTag","Closing tag '"+l+"' can't have attributes or invalid starting.",mt(t,a));if(n.length===0)return Fe("InvalidTag","Closing tag '"+l+"' has not been opened.",mt(t,a));{const f=n.pop();if(l!==f.tagName){let h=mt(t,f.tagStartPos);return Fe("InvalidTag","Expected closing tag '"+f.tagName+"' (opened in line "+h.line+", col "+h.col+") instead of closing tag '"+l+"'.",mt(t,a))}n.length==0&&(i=!0)}}else return Fe("InvalidTag","Closing tag '"+l+"' doesn't have proper closing.",mt(t,s));else{const f=ff(u,e);if(f!==!0)return Fe(f.err.code,f.err.msg,mt(t,s-u.length+f.err.line));if(i===!0)return Fe("InvalidXml","Multiple possible root nodes found.",mt(t,s));e.unpairedTags.indexOf(l)!==-1||n.push({tagName:l,tagStartPos:a}),r=!0}for(s++;s<t.length;s++)if(t[s]==="<")if(t[s+1]==="!"){s++,s=pf(t,s);continue}else if(t[s+1]==="?"){if(s=uf(t,++s),s.err)return s}else break;else if(t[s]==="&"){const f=Fv(t,s);if(f==-1)return Fe("InvalidChar","char '&' is not expected.",mt(t,s));s=f}else if(i===!0&&!df(t[s]))return Fe("InvalidXml","Extra text at the end",mt(t,s));t[s]==="<"&&s--}}else{if(df(t[s]))continue;return Fe("InvalidChar","char '"+t[s]+"' is not expected.",mt(t,s))}if(r){if(n.length==1)return Fe("InvalidTag","Unclosed tag '"+n[0].tagName+"'.",mt(t,n[0].tagStartPos));if(n.length>0)return Fe("InvalidXml","Invalid '"+JSON.stringify(n.map(s=>s.tagName),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1})}else return Fe("InvalidXml","Start tag expected.",1);return!0};function df(t){return t===" "||t===" "||t===`
7
7
  `||t==="\r"}function uf(t,e){const n=e;for(;e<t.length;e++)if(t[e]=="?"||t[e]==" "){const r=t.substr(n,e-n);if(e>5&&r==="xml")return Fe("InvalidXml","XML declaration allowed only at the start of the document.",mt(t,e));if(t[e]=="?"&&t[e+1]==">"){e++;break}else continue}return e}function pf(t,e){if(t.length>e+5&&t[e+1]==="-"&&t[e+2]==="-"){for(e+=3;e<t.length;e++)if(t[e]==="-"&&t[e+1]==="-"&&t[e+2]===">"){e+=2;break}}else if(t.length>e+8&&t[e+1]==="D"&&t[e+2]==="O"&&t[e+3]==="C"&&t[e+4]==="T"&&t[e+5]==="Y"&&t[e+6]==="P"&&t[e+7]==="E"){let n=1;for(e+=8;e<t.length;e++)if(t[e]==="<")n++;else if(t[e]===">"&&(n--,n===0))break}else if(t.length>e+9&&t[e+1]==="["&&t[e+2]==="C"&&t[e+3]==="D"&&t[e+4]==="A"&&t[e+5]==="T"&&t[e+6]==="A"&&t[e+7]==="["){for(e+=8;e<t.length;e++)if(t[e]==="]"&&t[e+1]==="]"&&t[e+2]===">"){e+=2;break}}return e}const Bv='"',Lv="'";function Uv(t,e){let n="",r="",i=!1;for(;e<t.length;e++){if(t[e]===Bv||t[e]===Lv)r===""?r=t[e]:r!==t[e]||(r="");else if(t[e]===">"&&r===""){i=!0;break}n+=t[e]}return r!==""?!1:{value:n,index:e,tagClosed:i}}const Dv=new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`,"g");function ff(t,e){const n=Su.getAllMatches(t,Dv),r={};for(let i=0;i<n.length;i++){if(n[i][1].length===0)return Fe("InvalidAttr","Attribute '"+n[i][2]+"' has no space in starting.",Ri(n[i]));if(n[i][3]!==void 0&&n[i][4]===void 0)return Fe("InvalidAttr","Attribute '"+n[i][2]+"' is without value.",Ri(n[i]));if(n[i][3]===void 0&&!e.allowBooleanAttributes)return Fe("InvalidAttr","boolean attribute '"+n[i][2]+"' is not allowed.",Ri(n[i]));const s=n[i][2];if(!qv(s))return Fe("InvalidAttr","Attribute '"+s+"' is an invalid name.",Ri(n[i]));if(!r.hasOwnProperty(s))r[s]=1;else return Fe("InvalidAttr","Attribute '"+s+"' is repeated.",Ri(n[i]))}return!0}function Mv(t,e){let n=/\d/;for(t[e]==="x"&&(e++,n=/[\da-fA-F]/);e<t.length;e++){if(t[e]===";")return e;if(!t[e].match(n))break}return-1}function Fv(t,e){if(e++,t[e]===";")return-1;if(t[e]==="#")return e++,Mv(t,e);let n=0;for(;e<t.length;e++,n++)if(!(t[e].match(/\w/)&&n<20)){if(t[e]===";")break;return-1}return e}function Fe(t,e,n){return{err:{code:t,msg:e,line:n.line||n,col:n.col}}}function qv(t){return Su.isName(t)}function Hv(t){return Su.isName(t)}function mt(t,e){const n=t.substring(0,e).split(/\r?\n/);return{line:n.length,col:n[n.length-1].length+1}}function Ri(t){return t.startIndex+t[1].length}var zu={};const $m={preserveOrder:!1,attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,removeNSPrefix:!1,allowBooleanAttributes:!1,parseTagValue:!0,parseAttributeValue:!1,trimValues:!0,cdataPropName:!1,numberParseOptions:{hex:!0,leadingZeros:!0,eNotation:!0},tagValueProcessor:function(t,e){return e},attributeValueProcessor:function(t,e){return e},stopNodes:[],alwaysCreateTextNode:!1,isArray:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(t,e,n){return t}},Vv=function(t){return Object.assign({},$m,t)};zu.buildOptions=Vv;zu.defaultOptions=$m;let Kv=class{constructor(e){this.tagname=e,this.child=[],this[":@"]={}}add(e,n){e==="__proto__"&&(e="#__proto__"),this.child.push({[e]:n})}addChild(e){e.tagname==="__proto__"&&(e.tagname="#__proto__"),e[":@"]&&Object.keys(e[":@"]).length>0?this.child.push({[e.tagname]:e.child,":@":e[":@"]}):this.child.push({[e.tagname]:e.child})}};var Gv=Kv;const Wv=Ma;function Jv(t,e){const n={};if(t[e+3]==="O"&&t[e+4]==="C"&&t[e+5]==="T"&&t[e+6]==="Y"&&t[e+7]==="P"&&t[e+8]==="E"){e=e+9;let r=1,i=!1,s=!1,a="";for(;e<t.length;e++)if(t[e]==="<"&&!s){if(i&&Yv(t,e)){e+=7;let c,l;[c,l,e]=Xv(t,e+1),l.indexOf("&")===-1&&(n[n2(c)]={regx:RegExp(`&${c};`,"g"),val:l})}else if(i&&Qv(t,e))e+=8;else if(i&&e2(t,e))e+=8;else if(i&&t2(t,e))e+=9;else if(Zv)s=!0;else throw new Error("Invalid DOCTYPE");r++,a=""}else if(t[e]===">"){if(s?t[e-1]==="-"&&t[e-2]==="-"&&(s=!1,r--):r--,r===0)break}else t[e]==="["?i=!0:a+=t[e];if(r!==0)throw new Error("Unclosed DOCTYPE")}else throw new Error("Invalid Tag instead of DOCTYPE");return{entities:n,i:e}}function Xv(t,e){let n="";for(;e<t.length&&t[e]!=="'"&&t[e]!=='"';e++)n+=t[e];if(n=n.trim(),n.indexOf(" ")!==-1)throw new Error("External entites are not supported");const r=t[e++];let i="";for(;e<t.length&&t[e]!==r;e++)i+=t[e];return[n,i,e]}function Zv(t,e){return t[e+1]==="!"&&t[e+2]==="-"&&t[e+3]==="-"}function Yv(t,e){return t[e+1]==="!"&&t[e+2]==="E"&&t[e+3]==="N"&&t[e+4]==="T"&&t[e+5]==="I"&&t[e+6]==="T"&&t[e+7]==="Y"}function Qv(t,e){return t[e+1]==="!"&&t[e+2]==="E"&&t[e+3]==="L"&&t[e+4]==="E"&&t[e+5]==="M"&&t[e+6]==="E"&&t[e+7]==="N"&&t[e+8]==="T"}function e2(t,e){return t[e+1]==="!"&&t[e+2]==="A"&&t[e+3]==="T"&&t[e+4]==="T"&&t[e+5]==="L"&&t[e+6]==="I"&&t[e+7]==="S"&&t[e+8]==="T"}function t2(t,e){return t[e+1]==="!"&&t[e+2]==="N"&&t[e+3]==="O"&&t[e+4]==="T"&&t[e+5]==="A"&&t[e+6]==="T"&&t[e+7]==="I"&&t[e+8]==="O"&&t[e+9]==="N"}function n2(t){if(Wv.isName(t))return t;throw new Error(`Invalid entity name ${t}`)}var r2=Jv;const i2=/^[-+]?0x[a-fA-F0-9]+$/,o2=/^([\-\+])?(0*)(\.[0-9]+([eE]\-?[0-9]+)?|[0-9]+(\.[0-9]+([eE]\-?[0-9]+)?)?)$/;!Number.parseInt&&window.parseInt&&(Number.parseInt=window.parseInt);!Number.parseFloat&&window.parseFloat&&(Number.parseFloat=window.parseFloat);const s2={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};function a2(t,e={}){if(e=Object.assign({},s2,e),!t||typeof t!="string")return t;let n=t.trim();if(e.skipLike!==void 0&&e.skipLike.test(n))return t;if(e.hex&&i2.test(n))return Number.parseInt(n,16);{const r=o2.exec(n);if(r){const i=r[1],s=r[2];let a=c2(r[3]);const c=r[4]||r[6];if(!e.leadingZeros&&s.length>0&&i&&n[2]!=="."||!e.leadingZeros&&s.length>0&&!i&&n[1]!==".")return t;{const l=Number(n),d=""+l;return d.search(/[eE]/)!==-1||c?e.eNotation?l:t:n.indexOf(".")!==-1?d==="0"&&a===""||d===a||i&&d==="-"+a?l:t:s?a===d||i+a===d?l:t:n===d||n===i+d?l:t}}else return t}}function c2(t){return t&&t.indexOf(".")!==-1&&(t=t.replace(/0+$/,""),t==="."?t="0":t[0]==="."?t="0"+t:t[t.length-1]==="."&&(t=t.substr(0,t.length-1))),t}var l2=a2;function d2(t){return typeof t=="function"?t:Array.isArray(t)?e=>{for(const n of t)if(typeof n=="string"&&e===n||n instanceof RegExp&&n.test(e))return!0}:()=>!1}var km=d2;const xm=Ma,Bi=Gv,u2=r2,p2=l2,f2=km;let h2=class{constructor(e){this.options=e,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:"'"},gt:{regex:/&(gt|#62|#x3E);/g,val:">"},lt:{regex:/&(lt|#60|#x3C);/g,val:"<"},quot:{regex:/&(quot|#34|#x22);/g,val:'"'}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:"&"},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:" "},cent:{regex:/&(cent|#162);/g,val:"¢"},pound:{regex:/&(pound|#163);/g,val:"£"},yen:{regex:/&(yen|#165);/g,val:"¥"},euro:{regex:/&(euro|#8364);/g,val:"€"},copyright:{regex:/&(copy|#169);/g,val:"©"},reg:{regex:/&(reg|#174);/g,val:"®"},inr:{regex:/&(inr|#8377);/g,val:"₹"},num_dec:{regex:/&#([0-9]{1,7});/g,val:(n,r)=>String.fromCharCode(Number.parseInt(r,10))},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:(n,r)=>String.fromCharCode(Number.parseInt(r,16))}},this.addExternalEntities=g2,this.parseXml=v2,this.parseTextData=m2,this.resolveNameSpace=_2,this.buildAttributesMap=w2,this.isItStopNode=x2,this.replaceEntitiesValue=$2,this.readStopNodeData=z2,this.saveTextToParentTag=k2,this.addChild=b2,this.ignoreAttributesFn=f2(this.options.ignoreAttributes)}};function g2(t){const e=Object.keys(t);for(let n=0;n<e.length;n++){const r=e[n];this.lastEntities[r]={regex:new RegExp("&"+r+";","g"),val:t[r]}}}function m2(t,e,n,r,i,s,a){if(t!==void 0&&(this.options.trimValues&&!r&&(t=t.trim()),t.length>0)){a||(t=this.replaceEntitiesValue(t));const c=this.options.tagValueProcessor(e,t,n,i,s);return c==null?t:typeof c!=typeof t||c!==t?c:this.options.trimValues?Il(t,this.options.parseTagValue,this.options.numberParseOptions):t.trim()===t?Il(t,this.options.parseTagValue,this.options.numberParseOptions):t}}function _2(t){if(this.options.removeNSPrefix){const e=t.split(":"),n=t.charAt(0)==="/"?"/":"";if(e[0]==="xmlns")return"";e.length===2&&(t=n+e[1])}return t}const y2=new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`,"gm");function w2(t,e,n){if(this.options.ignoreAttributes!==!0&&typeof t=="string"){const r=xm.getAllMatches(t,y2),i=r.length,s={};for(let a=0;a<i;a++){const c=this.resolveNameSpace(r[a][1]);if(this.ignoreAttributesFn(c,e))continue;let l=r[a][4],d=this.options.attributeNamePrefix+c;if(c.length)if(this.options.transformAttributeName&&(d=this.options.transformAttributeName(d)),d==="__proto__"&&(d="#__proto__"),l!==void 0){this.options.trimValues&&(l=l.trim()),l=this.replaceEntitiesValue(l);const u=this.options.attributeValueProcessor(c,l,e);u==null?s[d]=l:typeof u!=typeof l||u!==l?s[d]=u:s[d]=Il(l,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(s[d]=!0)}if(!Object.keys(s).length)return;if(this.options.attributesGroupName){const a={};return a[this.options.attributesGroupName]=s,a}return s}}const v2=function(t){t=t.replace(/\r\n?/g,`
8
8
  `);const e=new Bi("!xml");let n=e,r="",i="";for(let s=0;s<t.length;s++)if(t[s]==="<")if(t[s+1]==="/"){const a=dr(t,">",s,"Closing Tag is not closed.");let c=t.substring(s+2,a).trim();if(this.options.removeNSPrefix){const u=c.indexOf(":");u!==-1&&(c=c.substr(u+1))}this.options.transformTagName&&(c=this.options.transformTagName(c)),n&&(r=this.saveTextToParentTag(r,n,i));const l=i.substring(i.lastIndexOf(".")+1);if(c&&this.options.unpairedTags.indexOf(c)!==-1)throw new Error(`Unpaired tag can not be used as closing tag: </${c}>`);let d=0;l&&this.options.unpairedTags.indexOf(l)!==-1?(d=i.lastIndexOf(".",i.lastIndexOf(".")-1),this.tagsNodeStack.pop()):d=i.lastIndexOf("."),i=i.substring(0,d),n=this.tagsNodeStack.pop(),r="",s=a}else if(t[s+1]==="?"){let a=Nl(t,s,!1,"?>");if(!a)throw new Error("Pi Tag is not closed.");if(r=this.saveTextToParentTag(r,n,i),!(this.options.ignoreDeclaration&&a.tagName==="?xml"||this.options.ignorePiTags)){const c=new Bi(a.tagName);c.add(this.options.textNodeName,""),a.tagName!==a.tagExp&&a.attrExpPresent&&(c[":@"]=this.buildAttributesMap(a.tagExp,i,a.tagName)),this.addChild(n,c,i)}s=a.closeIndex+1}else if(t.substr(s+1,3)==="!--"){const a=dr(t,"-->",s+4,"Comment is not closed.");if(this.options.commentPropName){const c=t.substring(s+4,a-2);r=this.saveTextToParentTag(r,n,i),n.add(this.options.commentPropName,[{[this.options.textNodeName]:c}])}s=a}else if(t.substr(s+1,2)==="!D"){const a=u2(t,s);this.docTypeEntities=a.entities,s=a.i}else if(t.substr(s+1,2)==="!["){const a=dr(t,"]]>",s,"CDATA is not closed.")-2,c=t.substring(s+9,a);r=this.saveTextToParentTag(r,n,i);let l=this.parseTextData(c,n.tagname,i,!0,!1,!0,!0);l==null&&(l=""),this.options.cdataPropName?n.add(this.options.cdataPropName,[{[this.options.textNodeName]:c}]):n.add(this.options.textNodeName,l),s=a+2}else{let a=Nl(t,s,this.options.removeNSPrefix),c=a.tagName;const l=a.rawTagName;let d=a.tagExp,u=a.attrExpPresent,f=a.closeIndex;this.options.transformTagName&&(c=this.options.transformTagName(c)),n&&r&&n.tagname!=="!xml"&&(r=this.saveTextToParentTag(r,n,i,!1));const h=n;if(h&&this.options.unpairedTags.indexOf(h.tagname)!==-1&&(n=this.tagsNodeStack.pop(),i=i.substring(0,i.lastIndexOf("."))),c!==e.tagname&&(i+=i?"."+c:c),this.isItStopNode(this.options.stopNodes,i,c)){let m="";if(d.length>0&&d.lastIndexOf("/")===d.length-1)c[c.length-1]==="/"?(c=c.substr(0,c.length-1),i=i.substr(0,i.length-1),d=c):d=d.substr(0,d.length-1),s=a.closeIndex;else if(this.options.unpairedTags.indexOf(c)!==-1)s=a.closeIndex;else{const v=this.readStopNodeData(t,l,f+1);if(!v)throw new Error(`Unexpected end of ${l}`);s=v.i,m=v.tagContent}const y=new Bi(c);c!==d&&u&&(y[":@"]=this.buildAttributesMap(d,i,c)),m&&(m=this.parseTextData(m,c,i,!0,u,!0,!0)),i=i.substr(0,i.lastIndexOf(".")),y.add(this.options.textNodeName,m),this.addChild(n,y,i)}else{if(d.length>0&&d.lastIndexOf("/")===d.length-1){c[c.length-1]==="/"?(c=c.substr(0,c.length-1),i=i.substr(0,i.length-1),d=c):d=d.substr(0,d.length-1),this.options.transformTagName&&(c=this.options.transformTagName(c));const m=new Bi(c);c!==d&&u&&(m[":@"]=this.buildAttributesMap(d,i,c)),this.addChild(n,m,i),i=i.substr(0,i.lastIndexOf("."))}else{const m=new Bi(c);this.tagsNodeStack.push(n),c!==d&&u&&(m[":@"]=this.buildAttributesMap(d,i,c)),this.addChild(n,m,i),n=m}r="",s=f}}else r+=t[s];return e.child};function b2(t,e,n){const r=this.options.updateTag(e.tagname,n,e[":@"]);r===!1||(typeof r=="string"&&(e.tagname=r),t.addChild(e))}const $2=function(t){if(this.options.processEntities){for(let e in this.docTypeEntities){const n=this.docTypeEntities[e];t=t.replace(n.regx,n.val)}for(let e in this.lastEntities){const n=this.lastEntities[e];t=t.replace(n.regex,n.val)}if(this.options.htmlEntities)for(let e in this.htmlEntities){const n=this.htmlEntities[e];t=t.replace(n.regex,n.val)}t=t.replace(this.ampEntity.regex,this.ampEntity.val)}return t};function k2(t,e,n,r){return t&&(r===void 0&&(r=Object.keys(e.child).length===0),t=this.parseTextData(t,e.tagname,n,!1,e[":@"]?Object.keys(e[":@"]).length!==0:!1,r),t!==void 0&&t!==""&&e.add(this.options.textNodeName,t),t=""),t}function x2(t,e,n){const r="*."+n;for(const i in t){const s=t[i];if(r===s||e===s)return!0}return!1}function S2(t,e,n=">"){let r,i="";for(let s=e;s<t.length;s++){let a=t[s];if(r)a===r&&(r="");else if(a==='"'||a==="'")r=a;else if(a===n[0])if(n[1]){if(t[s+1]===n[1])return{data:i,index:s}}else return{data:i,index:s};else a===" "&&(a=" ");i+=a}}function dr(t,e,n,r){const i=t.indexOf(e,n);if(i===-1)throw new Error(r);return i+e.length-1}function Nl(t,e,n,r=">"){const i=S2(t,e+1,r);if(!i)return;let s=i.data;const a=i.index,c=s.search(/\s/);let l=s,d=!0;c!==-1&&(l=s.substring(0,c),s=s.substring(c+1).trimStart());const u=l;if(n){const f=l.indexOf(":");f!==-1&&(l=l.substr(f+1),d=l!==i.data.substr(f+1))}return{tagName:l,tagExp:s,closeIndex:a,attrExpPresent:d,rawTagName:u}}function z2(t,e,n){const r=n;let i=1;for(;n<t.length;n++)if(t[n]==="<")if(t[n+1]==="/"){const s=dr(t,">",n,`${e} is not closed`);if(t.substring(n+2,s).trim()===e&&(i--,i===0))return{tagContent:t.substring(r,n),i:s};n=s}else if(t[n+1]==="?")n=dr(t,"?>",n+1,"StopNode is not closed.");else if(t.substr(n+1,3)==="!--")n=dr(t,"-->",n+3,"StopNode is not closed.");else if(t.substr(n+1,2)==="![")n=dr(t,"]]>",n,"StopNode is not closed.")-2;else{const s=Nl(t,n,">");s&&((s&&s.tagName)===e&&s.tagExp[s.tagExp.length-1]!=="/"&&i++,n=s.closeIndex)}}function Il(t,e,n){if(e&&typeof t=="string"){const r=t.trim();return r==="true"?!0:r==="false"?!1:p2(t,n)}else return xm.isExist(t)?t:""}var A2=h2,Sm={};function E2(t,e){return zm(t,e)}function zm(t,e,n){let r;const i={};for(let s=0;s<t.length;s++){const a=t[s],c=C2(a);let l="";if(n===void 0?l=c:l=n+"."+c,c===e.textNodeName)r===void 0?r=a[c]:r+=""+a[c];else{if(c===void 0)continue;if(a[c]){let d=zm(a[c],e,l);const u=I2(d,e);a[":@"]?N2(d,a[":@"],l,e):Object.keys(d).length===1&&d[e.textNodeName]!==void 0&&!e.alwaysCreateTextNode?d=d[e.textNodeName]:Object.keys(d).length===0&&(e.alwaysCreateTextNode?d[e.textNodeName]="":d=""),i[c]!==void 0&&i.hasOwnProperty(c)?(Array.isArray(i[c])||(i[c]=[i[c]]),i[c].push(d)):e.isArray(c,l,u)?i[c]=[d]:i[c]=d}}}return typeof r=="string"?r.length>0&&(i[e.textNodeName]=r):r!==void 0&&(i[e.textNodeName]=r),i}function C2(t){const e=Object.keys(t);for(let n=0;n<e.length;n++){const r=e[n];if(r!==":@")return r}}function N2(t,e,n,r){if(e){const i=Object.keys(e),s=i.length;for(let a=0;a<s;a++){const c=i[a];r.isArray(c,n+"."+c,!0,!0)?t[c]=[e[c]]:t[c]=e[c]}}}function I2(t,e){const{textNodeName:n}=e,r=Object.keys(t).length;return!!(r===0||r===1&&(t[n]||typeof t[n]=="boolean"||t[n]===0))}Sm.prettify=E2;const{buildOptions:j2}=zu,O2=A2,{prettify:T2}=Sm,P2=xu;let R2=class{constructor(e){this.externalEntities={},this.options=j2(e)}parse(e,n){if(typeof e!="string")if(e.toString)e=e.toString();else throw new Error("XML data is accepted in String or Bytes[] form.");if(n){n===!0&&(n={});const s=P2.validate(e,n);if(s!==!0)throw Error(`${s.err.msg}:${s.err.line}:${s.err.col}`)}const r=new O2(this.options);r.addExternalEntities(this.externalEntities);const i=r.parseXml(e);return this.options.preserveOrder||i===void 0?i:T2(i,this.options)}addEntity(e,n){if(n.indexOf("&")!==-1)throw new Error("Entity value can't have '&'");if(e.indexOf("&")!==-1||e.indexOf(";")!==-1)throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '&#xD;'");if(n==="&")throw new Error("An entity with value '&' is not permitted");this.externalEntities[e]=n}};var B2=R2;const L2=`
@@ -69,7 +69,7 @@
69
69
  <\/script>
70
70
  </body>
71
71
 
72
- </html>`}const jm=["openid","profile","email","address","phone"];async function ib(t,e){var O,U;const{tenantId:n,clientId:r,audience:i,requestedScopes:s}=e,a=s.filter(T=>jm.includes(T)),l=(await t.env.data.resourceServers.list(n)).resource_servers.filter(T=>T.identifier===i);if(l.length===0)return{scopes:a,permissions:[]};const d=l[0];if(!d)return{scopes:a,permissions:[]};const u=((O=d.options)==null?void 0:O.enforce_policies)===!0,f=((U=d.options)==null?void 0:U.token_dialect)||"access_token",m=(await t.env.data.clientGrants.list(n,{q:`client_id:"${r}"`})).client_grants.find(T=>T.audience===i);if(!m)return{scopes:a,permissions:[]};const y=m.scope||[],v=(d.scopes||[]).map(T=>T.value);if(!u){let T;return s.length===0?T=y.filter(W=>v.includes(W)):T=s.filter(W=>v.includes(W)&&y.includes(W)),{scopes:[...new Set([...a,...T])],permissions:[]}}if(f==="access_token_authz"){const T=y.filter(R=>v.includes(R));return{scopes:a,permissions:T}}let b;return s.length===0?b=y.filter(T=>v.includes(T)):b=s.filter(T=>v.includes(T)&&y.includes(T)),{scopes:[...new Set([...a,...b])],permissions:[]}}async function Vs(t,e){var ne,Q;if(e.grantType===Vt.ClientCredential)return await ib(t,{tenantId:e.tenantId,clientId:e.clientId,audience:e.audience,requestedScopes:e.requestedScopes});const{tenantId:n,userId:r,audience:i,requestedScopes:s,organizationId:a}=e;if(a&&!(await t.env.data.userOrganizations.list(n,{q:`user_id:${r}`,per_page:1e3})).userOrganizations.some(N=>N.organization_id===a))throw new ee(403,{error:"access_denied",error_description:"User is not a member of the specified organization"});const c=s.filter(K=>jm.includes(K)),d=(await t.env.data.resourceServers.list(n)).resource_servers.filter(K=>K.identifier===i);if(d.length===0)return{scopes:c,permissions:[]};const u=d[0];if(!u)return{scopes:c,permissions:[]};const f=(u.scopes||[]).map(K=>K.value),h=((ne=u.options)==null?void 0:ne.enforce_policies)===!0,m=((Q=u.options)==null?void 0:Q.token_dialect)||"access_token";if(!h){const K=s.filter(N=>f.includes(N));return{scopes:[...new Set([...c,...K])],permissions:[]}}const y=await t.env.data.userPermissions.list(n,r,void 0,a),v=await t.env.data.userRoles.list(n,r,void 0,""),b=a?await t.env.data.userRoles.list(n,r,void 0,a):[],A=[...v,...b],O=[];for(const K of A)(await t.env.data.rolePermissions.list(n,K.id)).forEach(N=>{N.resource_server_identifier===i&&O.push(N.permission_name)});const U=new Set;y.forEach(K=>{K.resource_server_identifier===i&&U.add(K.permission_name)}),O.forEach(K=>{U.add(K)});const T=Array.from(U);if(m==="access_token_authz"){const K=T.filter(de=>f.includes(de));return{scopes:c,permissions:K}}const R=s.filter(K=>f.includes(K)&&T.includes(K));return{scopes:[...new Set([...c,...R])],permissions:[]}}const mf=["sub","iss","aud","exp","nbf","iat","jti"];async function Fa(t,e){var U,T;const{authParams:n,user:r,client:i,session_id:s,organization:a,permissions:c,impersonatingUser:l}=e,{signingKeys:d}=await t.env.data.keys.list({q:"type:jwt_signing"}),u=d.filter(R=>!R.revoked_at||new Date(R.revoked_at)>new Date),f=u[u.length-1];if(!(f!=null&&f.pkcs7))throw new ee(500,{message:"No signing key available"});const h=bv(f.pkcs7),m=t.var.custom_domain?`https://${t.var.custom_domain}/`:t.env.ISSUER,y={aud:n.audience||"default",scope:n.scope||"",sub:(r==null?void 0:r.user_id)||n.client_id,iss:m,tenant_id:t.var.tenant_id,sid:s,act:l?{sub:l.user_id}:void 0,org_id:a?a.id:void 0,permissions:c},v=r&&((U=n.scope)!=null&&U.split(" ").includes("openid"))?{aud:n.client_id,sub:r.user_id,iss:m,sid:s,nonce:n.nonce,given_name:r.given_name,family_name:r.family_name,nickname:r.nickname,picture:r.picture,locale:r.locale,name:r.name,email:r.email,email_verified:r.email_verified,act:l?{sub:l.user_id}:void 0,org_id:a==null?void 0:a.id,org_name:a==null?void 0:a.name}:void 0;(T=t.env.hooks)!=null&&T.onExecuteCredentialsExchange&&await t.env.hooks.onExecuteCredentialsExchange({ctx:t,client:i,user:r,request:{ip:t.var.ip||"",user_agent:t.var.useragent||"",method:t.req.method,url:t.req.url},scope:n.scope||"",grant_type:""},{accessToken:{setCustomClaim:(R,W)=>{if(mf.includes(R))throw new Error(`Cannot overwrite reserved claim '${R}'`);y[R]=W}},idToken:{setCustomClaim:(R,W)=>{if(mf.includes(R))throw new Error(`Cannot overwrite reserved claim '${R}'`);v&&(v[R]=W)}},access:{deny:R=>{throw new ee(400,{message:`Access denied: ${R}`})}},token:{createServiceToken:async R=>{const{createServiceToken:W}=await Promise.resolve().then(()=>sb);return(await W(t,t.var.tenant_id,R.scope,R.expiresInSeconds)).access_token}}});const b={includeIssuedTimestamp:!0,expiresIn:l?new qs(1,"h"):new qs(1,"d"),headers:{kid:f.kid}},A=await cf("RS256",h,y,b),O=v?await cf("RS256",h,v,b):void 0;return{access_token:A,refresh_token:e.refresh_token,id_token:O,token_type:"Bearer",expires_in:l?3600:86400}}async function Om(t,e){return{code:(await t.env.data.codes.create(e.client.tenant.id,{code_id:Ne(),user_id:e.user.user_id,code_type:"authorization_code",login_id:e.login_id,expires_at:new Date(Date.now()+xv*1e3).toISOString(),code_challenge:e.authParams.code_challenge,code_challenge_method:e.authParams.code_challenge_method,redirect_uri:e.authParams.redirect_uri,state:e.authParams.state,nonce:e.authParams.nonce})).code_id,state:e.authParams.state}}async function Tm(t,e){const{client:n,scope:r,audience:i=n.tenant.audience,session_id:s}=e;return await t.env.data.refreshTokens.create(n.tenant.id,{id:Ne(),session_id:s,client_id:n.client_id,idle_expires_at:new Date(Date.now()+Da*1e3).toISOString(),user_id:e.user.user_id,device:{last_ip:t.var.ip,initial_ip:t.var.ip,last_user_agent:t.var.useragent||"",initial_user_agent:t.var.useragent||"",initial_asn:"",last_asn:""},resource_servers:[{audience:i,scopes:r}],rotating:!1})}async function Pm(t,{user:e,client:n,loginSession:r}){const i=await t.env.data.sessions.create(n.tenant.id,{id:Ne(),user_id:e.user_id,login_session_id:r.id,idle_expires_at:new Date(Date.now()+Da*1e3).toISOString(),device:{last_ip:t.var.ip||"",initial_ip:t.var.ip||"",last_user_agent:t.var.useragent||"",initial_user_agent:t.var.useragent||"",initial_asn:"",last_asn:""},clients:[n.client_id]});return await t.env.data.loginSessions.update(n.tenant.id,r.id,{session_id:i.id}),i}async function un(t,e){var m,y;const{authParams:n,client:r,ticketAuth:i}=e;let{user:s}=e;const a=n.response_type||Nt.CODE,c=n.response_mode||Wt.QUERY;if(i){if(!e.loginSession)throw new ee(500,{message:"Login session not found for ticket auth."});const v=vv(),b=Ne(12),A=await t.env.data.codes.create(r.tenant.id,{code_id:Ne(),code_type:"ticket",login_id:e.loginSession.id,expires_at:new Date(Date.now()+zv).toISOString(),code_verifier:[b,v].join("|"),redirect_uri:n.redirect_uri,state:n.state,nonce:n.nonce});return t.json({login_ticket:A.code_id,co_verifier:v,co_id:b})}let l=e.refreshToken,d=e.sessionId;if(!d&&((m=e.loginSession)!=null&&m.session_id)){d=e.loginSession.session_id;const v=await t.env.data.sessions.get(r.tenant.id,d);v&&!v.clients.includes(r.client_id)&&await t.env.data.sessions.update(r.tenant.id,d,{clients:[...v.clients,r.client_id]})}else if(!d){if(!e.loginSession)throw new ee(500,{message:"Login session not found for creating a new session."});d=(await Pm(t,{user:s,client:r,loginSession:e.loginSession})).id}if(!l&&((y=n.scope)!=null&&y.split(" ").includes("offline_access"))&&![Nt.TOKEN,Nt.CODE].includes(a)&&!e.impersonatingUser&&(l=(await Tm(t,{user:s,client:r,session_id:d,scope:n.scope,audience:n.audience})).id),c===Wt.SAML_POST){if(!d)throw new S(500,{message:"Session ID not available for SAML response"});return rb(t,e.client,e.authParams,s,d)}const u=await ob(t,{authParams:n,user:s,client:r,session_id:d,refresh_token:l,strategy:e.strategy,loginSession:e.loginSession,responseType:a,skipHooks:e.skipHooks,organization:e.organization,impersonatingUser:e.impersonatingUser});if(u instanceof Response)return u;if(c===Wt.WEB_MESSAGE){if(!n.redirect_uri)throw new ee(400,{message:"Redirect URI not allowed for WEB_MESSAGE response mode."});const v=new Headers;if(d){const O=Hs(r.tenant.id,d,t.var.host||"");O&&v.set("set-cookie",O)}else console.warn("Session ID not available for WEB_MESSAGE, cookie will not be set.");const b=new URL(n.redirect_uri),A=`${b.protocol}//${b.host}`;return t.html(jl(A,JSON.stringify({...u,state:n.state})),{headers:v})}if(!n.redirect_uri)throw new ee(400,{message:"Redirect uri not found for this response mode."});const f=new Headers;if(d){const v=Hs(r.tenant.id,d,t.var.custom_domain||t.req.header("host")||"");v&&f.set("set-cookie",v)}const h=new URL(n.redirect_uri);if("code"in u)h.searchParams.set("code",u.code),u.state&&h.searchParams.set("state",u.state);else if("access_token"in u)h.hash=new URLSearchParams({access_token:u.access_token,...u.id_token&&{id_token:u.id_token},token_type:u.token_type,expires_in:u.expires_in.toString(),...n.state&&{state:n.state},...n.scope&&{scope:n.scope}}).toString();else throw new ee(500,{message:"Invalid token response for implicit flow."});return f.set("location",h.toString()),new Response("Redirecting",{status:302,headers:f})}async function ob(t,e){var c,l,d,u,f,h;let{user:n}=e;const r=e.responseType||Nt.TOKEN;if(n&&e.organization&&!(await t.env.data.userOrganizations.list(e.client.tenant.id,{q:`user_id:${n.user_id}`,per_page:1e3})).userOrganizations.some(v=>v.organization_id===e.organization.id))throw new ee(403,{error:"access_denied",error_description:"User is not a member of the specified organization"});let i=e.authParams.scope||"",s=[];if(e.authParams.audience)try{let m;if(e.grantType===Vt.ClientCredential||!n&&!e.user)m=await Vs(t,{grantType:Vt.ClientCredential,tenantId:e.client.tenant.id,clientId:e.client.client_id,audience:e.authParams.audience,requestedScopes:((c=e.authParams.scope)==null?void 0:c.split(" "))||[],organizationId:(l=e.organization)==null?void 0:l.id});else{const y=(n==null?void 0:n.user_id)||((d=e.user)==null?void 0:d.user_id);if(!y)throw new ee(400,{error:"invalid_request",error_description:"User ID is required for user-based grants"});m=await Vs(t,{grantType:e.grantType,tenantId:e.client.tenant.id,userId:y,clientId:e.client.client_id,audience:e.authParams.audience,requestedScopes:((u=e.authParams.scope)==null?void 0:u.split(" "))||[],organizationId:(f=e.organization)==null?void 0:f.id})}i=m.scopes.join(" "),s=m.permissions}catch(m){if(m instanceof S)throw m}const a={...e.authParams,scope:i};if(e.loginSession&&n&&!e.skipHooks){e.strategy&&((h=n.app_metadata)==null?void 0:h.strategy)!==e.strategy&&(n.app_metadata={...n.app_metadata,strategy:e.strategy},await t.env.data.users.update(e.client.tenant.id,n.user_id,{app_metadata:{...n.app_metadata||{},strategy:e.strategy}}));const m=await Um(t,t.env.data,e.client.tenant.id,n,e.loginSession,{client:e.client,authParams:a,authStrategy:e.strategy?{strategy:e.strategy,strategy_type:"social"}:void 0});if(m instanceof Response)return m;n=m}if(r===Nt.CODE){if(!n||!e.loginSession)throw new ee(500,{message:"User and loginSession is required for code flow"});return await Om(t,{user:n,client:e.client,authParams:a,login_id:e.loginSession.id})}else return Fa(t,{...e,user:n,authParams:a,permissions:s})}const _f="auth-service";async function Au(t,e,n,r){const i=await t.env.data.tenants.get(e);if(!i)throw new Error(`Tenant not found: ${e}`);const s={client_id:_f,tenant:i,created_at:new Date().toISOString(),updated_at:new Date().toISOString(),name:"Auth Service",global:!1,is_first_party:!0,oidc_conformant:!1,sso:!1,sso_disabled:!1,cross_origin_authentication:!1,custom_login_page_on:!1,require_pushed_authorization_requests:!1,require_proof_of_possession:!1,client_metadata:{disable_sign_ups:"false",email_validation:"disabled"},disable_sign_ups:!1,email_validation:"disabled",connections:[]},a=await Fa(t,{client:s,authParams:{client_id:_f,response_type:Nt.TOKEN,scope:n}});return{access_token:a.access_token,token_type:a.token_type,expires_in:r||3600}}const sb=Object.freeze(Object.defineProperty({__proto__:null,createServiceToken:Au},Symbol.toStringTag,{value:"Module"}));var ab={deno:"Deno",bun:"Bun",workerd:"Cloudflare-Workers",node:"Node.js"},Rm=()=>{var n,r;const t=globalThis;if(typeof navigator<"u"&&typeof navigator.userAgent=="string"){for(const[i,s]of Object.entries(ab))if(cb(s))return i}return typeof(t==null?void 0:t.EdgeRuntime)=="string"?"edge-light":(t==null?void 0:t.fastly)!==void 0?"fastly":((r=(n=t==null?void 0:t.process)==null?void 0:n.release)==null?void 0:r.name)==="node"?"node":"other"},cb=t=>navigator.userAgent.startsWith(t);function ve(t,e){Rm()==="workerd"&&t.executionCtx.waitUntil(e)}async function Bm(t,e,n){const r=await Au(t,n.tenant_id,"webhook");for await(const i of e.filter(s=>"url"in s))if(!(await fetch(i.url,{method:"POST",headers:{Authorization:`Bearer ${r.access_token}`,"Content-Type":"application/json"},body:JSON.stringify(n)})).ok){const a=be(t,{type:_e.FAILED_HOOK,description:`Failed to invoke hook ${i.hook_id}`});ve(t,t.env.data.logs.create(n.tenant_id,a))}}function lb(t){return async(e,n)=>{const{hooks:r}=await t.env.data.hooks.list(e);return await Bm(t,r,{tenant_id:e,user:n,trigger_id:"post-user-registration"}),n}}function db(t){return async(e,n)=>{const{hooks:r}=await t.env.data.hooks.list(e,{q:"trigger_id:pre-user-signup",page:0,per_page:100,include_totals:!1});await Bm(t,r,{tenant_id:e,email:n,trigger_id:"pre-user-signup"})}}function yf(t){return typeof t.form_id=="string"}async function ub(t,e,n){var l;const r=t.env.data,i=t.var.tenant_id||t.req.header("tenant-id");if(!i)throw new S(400,{message:"Missing tenant_id in context"});const s=await r.forms.get(i,e);if(!s)throw new S(404,{message:"Form not found for post-user-login hook"});let a=(l=s.start)==null?void 0:l.next_node;if(!a&&s.nodes&&s.nodes.length>0){const d=s.nodes.find(u=>u.type==="STEP");a=d==null?void 0:d.id}if(!a)throw new S(400,{message:"No start node found in form"});let c=`/u/forms/${s.id}/nodes/${a}?state=${encodeURIComponent(n.id)}`;return new Response(null,{status:302,headers:{location:c}})}function wf(t){return typeof t.page_id=="string"&&typeof t.enabled=="boolean"}async function pb(t,e,n,r,i){const s=t.env.data,a=t.var.tenant_id||t.req.header("tenant-id");if(!a)throw new S(400,{message:"Missing tenant_id in context"});if(i&&!(await s.userPermissions.list(a,r.user_id)).some(u=>u.permission_name===i))return r;let c=`/u/${e}?state=${encodeURIComponent(n.id)}`;return new Response(null,{status:302,headers:{location:c}})}function ri(t,e){return{createServiceToken:async n=>(await Au(t,e,n.scope,n.expiresInSeconds)).access_token}}function vf(t){return typeof t.url=="string"}function fb(t,e){return async(n,r)=>{var a,c,l;if(t.var.client_id){const d=await e.legacyClients.get(t.var.client_id);if(!d)throw new ee(400,{message:"Client not found"});r.email&&await Lm(t,d,e,r.email)}const i={method:t.req.method,ip:t.req.query("x-real-ip")||"",user_agent:t.req.query("user-agent"),url:((a=t.var.loginSession)==null?void 0:a.authorization_url)||t.req.url};if((c=t.env.hooks)!=null&&c.onExecutePreUserRegistration)try{await t.env.hooks.onExecutePreUserRegistration({ctx:t,user:r,request:i},{user:{setUserMetadata:async(d,u)=>{r[d]=u}},token:ri(t,n)})}catch{const u=be(t,{type:_e.FAILED_SIGNUP,description:"Pre user registration hook failed"});ve(t,e.logs.create(n,u))}let s=await fv(e)(n,r);if((l=t.env.hooks)!=null&&l.onExecutePostUserRegistration)try{await t.env.hooks.onExecutePostUserRegistration({ctx:t,user:r,request:i},{user:{},token:ri(t,n)})}catch{const u=be(t,{type:_e.FAILED_SIGNUP,description:"Post user registration hook failed"});ve(t,t.env.data.logs.create(n,u))}return await lb(t)(n,s),s}}function hb(t,e){return async(n,r,i)=>{var c;if(Object.keys(i).length===1&&"linked_to"in i)return e.users.update(n,r,i);const s=await e.users.get(n,r);if(!s)throw new ee(404,{message:"User not found"});const a={method:t.req.method,ip:t.var.ip||t.get("ip")||"",user_agent:t.var.useragent||t.get("useragent")||"",url:t.req.url};if((c=t.env.hooks)!=null&&c.onExecutePreUserUpdate)try{await t.env.hooks.onExecutePreUserUpdate({ctx:t,tenant:{id:n},user_id:r,user:s,updates:i,request:a},{user:{setUserMetadata:async(l,d)=>{i[l]=d}},cancel:()=>{throw new ee(400,{message:"User update cancelled by pre-update hook"})},token:ri(t,n)})}catch{throw new ee(400,{message:"Pre user update hook failed"})}if(await e.users.update(n,r,i),i.email||i.email_verified){const l=await e.users.get(n,r);if(l&&l.email&&l.email_verified){const{users:d}=await e.users.list(n,{page:0,per_page:10,include_totals:!1,q:`email:${l.email}`}),u=d.filter(f=>f.email_verified&&f.user_id!==r&&!f.linked_to);u.length>0&&await e.users.update(n,r,{linked_to:u[0].user_id})}}if(i.email){const l=be(t,{type:_e.SUCCESS_CHANGE_EMAIL,description:`Email updated to ${i.email}`,userId:r});ve(t,e.logs.create(n,l))}return!0}}async function gb(t,e,n,r){var i,s;if(((i=e.client_metadata)==null?void 0:i.disable_sign_ups)==="true"){const a=(s=t.var.loginSession)==null?void 0:s.authorization_url;if(a&&new URL(a).searchParams.get("screen_hint")==="signup")return{allowed:!0};if(!await Cu({userAdapter:n.users,tenant_id:e.tenant.id,email:r}))return{allowed:!1,reason:"Public signup is disabled for this client"}}return{allowed:!0}}async function Lm(t,e,n,r){const i=await gb(t,e,n,r);if(!i.allowed){const s=be(t,{type:_e.FAILED_SIGNUP,description:i.reason||"Signup not allowed"});throw ve(t,n.logs.create(e.tenant.id,s)),new ee(400,{message:i.reason||"Signups are disabled for this client"})}await db(t)(e.tenant.id,r)}function mb(t,e){return async(n,r)=>{var c,l;const i=await e.users.get(n,r);if(!i)return!1;const s={method:t.req.method,ip:t.var.ip||t.get("ip")||"",user_agent:t.var.useragent||t.get("useragent")||"",url:t.req.url};if((c=t.env.hooks)!=null&&c.onExecutePreUserDeletion)try{await t.env.hooks.onExecutePreUserDeletion({ctx:t,user:i,user_id:r,request:s,tenant:{id:n}},{cancel:()=>{throw new ee(400,{message:"User deletion cancelled by pre-deletion hook"})},token:ri(t,n)})}catch(d){if(d instanceof S)throw d;const u=be(t,{type:_e.FAILED_HOOK,description:`Pre user deletion hook failed: ${d instanceof Error?d.message:String(d)}`});throw ve(t,e.logs.create(n,u)),new ee(400,{message:"Pre user deletion hook failed"})}const a=await e.users.remove(n,r);if(a){const d=be(t,{type:_e.SUCCESS_USER_DELETION,description:`user_id: ${r}`,strategy:i.provider||"auth0",strategy_type:i.is_social?"social":"database"});d.connection=i.connection||"",d.connection_id="",d.details={...d.details,body:{tenant:n,connection:i.connection||""}},ve(t,e.logs.create(n,d))}if(a&&((l=t.env.hooks)!=null&&l.onExecutePostUserDeletion))try{await t.env.hooks.onExecutePostUserDeletion({ctx:t,user:i,user_id:r,request:s,tenant:{id:n}},{token:ri(t,n)})}catch(d){const u=be(t,{type:_e.FAILED_HOOK,description:`Post user deletion hook failed: ${d instanceof Error?d.message:String(d)}`});ve(t,e.logs.create(n,u))}return a}}function xo(t,e){const n=e;return{...e,users:{...e.users,create:fb(t,n),update:hb(t,n),remove:mb(t,n)}}}async function _b(t,e,n,r,i,s){var u,f,h,m,y,v,b,A,O,U,T,R,W,ne;let a=[];try{a=(await e.userRoles.list(n,r.user_id,void 0,"")).map(de=>de.name||de.id)}catch(Q){console.error("Error fetching user roles:",Q)}let c={};if(r.connection)try{const K=(await e.connections.list(n,{page:0,per_page:100,include_totals:!1})).connections.find(de=>de.name===r.connection);K&&(c={id:K.id,name:K.name,strategy:K.strategy||r.provider,metadata:K.options||{}})}catch(Q){console.error("Error fetching connection info:",Q)}let l;try{if((u=i.authParams)!=null&&u.organization){const Q=await e.organizations.get(n,i.authParams.organization);Q&&(l={id:Q.id,name:Q.name,display_name:Q.display_name||Q.name,metadata:Q.metadata||{}})}}catch(Q){console.error("Error fetching organization info:",Q)}const d=t.get("countryCode");return{ctx:t,client:s.client,user:r,request:{asn:void 0,ip:t.get("ip")||"",user_agent:t.get("useragent"),method:t.req.method,url:t.req.url,geoip:{cityName:void 0,continentCode:void 0,countryCode:d||void 0,countryName:void 0,latitude:void 0,longitude:void 0,timeZone:void 0}},transaction:{id:i.id,locale:((f=i.authParams)==null?void 0:f.ui_locales)||"en",login_hint:void 0,prompt:(h=i.authParams)==null?void 0:h.prompt,redirect_uri:(m=i.authParams)==null?void 0:m.redirect_uri,requested_scopes:((v=(y=i.authParams)==null?void 0:y.scope)==null?void 0:v.split(" "))||[],response_mode:(b=i.authParams)==null?void 0:b.response_mode,response_type:(A=i.authParams)==null?void 0:A.response_type,state:(O=i.authParams)==null?void 0:O.state,ui_locales:(U=i.authParams)==null?void 0:U.ui_locales},scope:((T=s.authParams)==null?void 0:T.scope)||"",grant_type:((R=s.authParams)==null?void 0:R.grant_type)||"",audience:(W=s.authParams)==null?void 0:W.audience,authentication:{methods:[{name:r.is_social?"federated":"pwd",timestamp:new Date().toISOString()}]},authorization:{roles:a},connection:Object.keys(c).length>0?c:{id:r.connection||"Username-Password-Authentication",name:r.connection||"Username-Password-Authentication",strategy:r.provider||"auth0"},organization:l,resource_server:(ne=s.authParams)!=null&&ne.audience?{identifier:s.authParams.audience}:void 0,stats:{logins_count:r.login_count||0},tenant:{id:n},session:{id:i.id,created_at:i.created_at,authenticated_at:new Date().toISOString(),clients:[{client_id:s.client.client_id}],device:{initial_ip:t.get("ip"),initial_user_agent:t.get("useragent"),last_ip:r.last_ip||t.get("ip"),last_user_agent:t.get("useragent")}}}}async function Um(t,e,n,r,i,s){var f,h,m,y,v;const a=(f=s==null?void 0:s.authStrategy)!=null&&f.strategy_type?s.authStrategy.strategy_type:r.is_social?"social":"database",c=((h=s==null?void 0:s.authStrategy)==null?void 0:h.strategy)||r.connection||"",l=be(t,{type:_e.SUCCESS_LOGIN,description:`Successful login for ${r.user_id}`,userId:r.user_id,strategy_type:a,strategy:c,connection:c,audience:(m=s==null?void 0:s.authParams)==null?void 0:m.audience,scope:(y=s==null?void 0:s.authParams)==null?void 0:y.scope});if(ve(t,e.logs.create(n,l)),await e.users.update(n,r.user_id,{last_login:new Date().toISOString(),last_ip:t.var.ip||"",login_count:r.login_count+1}),(v=t.env.hooks)!=null&&v.onExecutePostLogin&&(s!=null&&s.client)&&(s!=null&&s.authParams)&&i){let b=null;const A=await _b(t,e,n,r,i,{client:s.client,authParams:s.authParams});if(await t.env.hooks.onExecutePostLogin(A,{prompt:{render:O=>{}},redirect:{sendUserTo:(O,U)=>{const T=new URL(O,t.req.url);T.searchParams.set("state",i.id),U!=null&&U.query&&Object.entries(U.query).forEach(([R,W])=>{T.searchParams.set(R,W)}),b=T.toString()},encodeToken:O=>JSON.stringify({payload:O.payload,exp:Date.now()+(O.expiresInSeconds||900)*1e3}),validateToken:O=>null},token:ri(t,n)}),b)return new Response(null,{status:302,headers:{location:b}})}const{hooks:d}=await e.hooks.list(n,{q:"trigger_id:post-user-login",page:0,per_page:100,include_totals:!1});if(i){const b=d.find(O=>O.enabled&&yf(O));if(b&&yf(b))return ub(t,b.form_id,i);const A=d.find(O=>O.enabled&&wf(O));if(A&&wf(A))return pb(t,A.page_id,i,r,A.permission_required)}const u=d.filter(b=>b.enabled&&vf(b));for(const b of u)if(vf(b))try{await fetch(b.url,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tenant_id:n,user:r,trigger_id:"post-user-login"})})}catch{const O=be(t,{type:_e.FAILED_HOOK,description:`Failed to invoke post-user-login webhook: ${b.url}`});ve(t,e.logs.create(n,O))}return r}function yb(t){return xo(t,t.env.data)}async function Eu(t,e,n){return(await t.list(e,{page:0,per_page:10,include_totals:!1,q:`email:${n}`})).users}async function vi({userAdapter:t,tenant_id:e,username:n,provider:r}){const i=r==="sms"?`phone_number:${n}`:`email:${n}`,{users:s}=await t.list(e,{page:0,per_page:10,include_totals:!1,q:`${i} provider:${r}`});return s.length>1&&console.error("More than one user found for same email and provider"),s[0]||null}async function Cu({userAdapter:t,tenant_id:e,email:n}){var c;const{users:r}=await t.list(e,{page:0,per_page:10,include_totals:!1,q:`email:${n}`}),i=r.filter(l=>!(l.provider==="auth2"&&!l.email_verified));if(i.length===0)return;const s=i.filter(l=>!l.linked_to);if(s.length>0)return s.length>1&&console.error("More than one primary user found for same email"),s[0];const a=await t.get(e,(c=i[0])==null?void 0:c.linked_to);if(!a)throw new Error("Primary account not found");return a}async function io({userAdapter:t,tenant_id:e,username:n,provider:r}){const i=await vi({userAdapter:t,tenant_id:e,username:n,provider:r});return i?i.linked_to?t.get(e,i.linked_to):i:null}async function qa(t,e){const{username:n,provider:r,connection:i,client:s,userId:a,isSocial:c,profileData:l={},ip:d=""}=e;let u=await io({userAdapter:t.env.data.users,tenant_id:e.client.tenant.id,username:n,provider:r});if(!u){const f={user_id:`${r}|${a||La()}`,email:i!=="sms"?n:void 0,phone_number:i==="sms"?n:void 0,name:n,provider:r,connection:i,email_verified:!0,last_ip:d,is_social:c,last_login:new Date().toISOString(),profileData:JSON.stringify(l)};u=await yb(t).users.create(s.tenant.id,f),t.set("user_id",u.user_id)}return u}const Qe=o.z.object({page:o.z.string().min(0).optional().default("0").transform(t=>parseInt(t,10)).openapi({description:"The page number where 0 is the first page"}),per_page:o.z.string().min(1).optional().default("10").transform(t=>parseInt(t,10)).openapi({description:"The number of items per page"}),include_totals:o.z.string().optional().default("false").transform(t=>t==="true").openapi({description:"If the total number of items should be included in the response"}),sort:o.z.string().regex(/^.+:(-1|1)$/).optional().openapi({description:"A property that should have the format 'string:-1' or 'string:1'"}),q:o.z.string().optional().openapi({description:"A lucene query string used to filter the results"})});function ft(t){if(!t)return;const[e,n]=t.split(":"),r=n==="1"?"asc":"desc";if(!(!e||!r))return{sort_by:e,sort_order:r}}const bf=St.extend({users:o.z.array(cn)}),wb=St.extend({sessions:o.z.array(Ba)}),vb=St.extend({organizations:o.z.array(Dn)}),bb=new o.OpenAPIHono().openapi(o.createRoute({tags:["users"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(cn),bf])}},description:"List of users"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query");if(s!=null&&s.includes("identities.profileData.email")){const d=s.split("=")[1],f=(await t.env.data.users.list(t.var.tenant_id,{page:e,per_page:n,include_totals:r,q:`email:${d}`})).users.filter(y=>y.linked_to),[h]=f;if(!h)return t.json([]);const m=await t.env.data.users.get(t.var.tenant_id,h.linked_to);if(!m)throw new S(500,{message:"Primary account not found"});return t.json([cn.parse(m)])}const a=["-_exists_:linked_to"];s&&a.push(s);const c=await t.env.data.users.list(t.var.tenant_id,{page:e,per_page:n,include_totals:r,sort:ft(i),q:a.join(" ")}),l=c.users.filter(d=>!d.linked_to);return r?t.json(bf.parse({users:l,length:c.length,start:c.start,limit:c.limit})):t.json(o.z.array(cn).parse(l))}).openapi(o.createRoute({tags:["users"],method:"get",path:"/{user_id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({user_id:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:cn}},description:"List of users"}}}),async t=>{const{user_id:e}=t.req.valid("param"),n=await t.env.data.users.get(t.var.tenant_id,e);if(!n)throw new S(404);if(n.linked_to)throw new S(404,{message:"User is linked to another user"});return t.json(n)}).openapi(o.createRoute({tags:["users"],method:"delete",path:"/{user_id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({user_id:o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{user_id:e}=t.req.valid("param");if(!await t.env.data.users.remove(t.var.tenant_id,e))throw new S(404);const r=be(t,{type:_e.SUCCESS_API_OPERATION,description:"Delete a User"});return r.details={...r.details,response:{statusCode:204,body:{}}},ve(t,t.env.data.logs.create(t.var.tenant_id,r)),t.text("OK")}).openapi(o.createRoute({tags:["users"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({...Os.shape,password:o.z.string().optional()})}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:cn}},description:"Status"}}}),async t=>{const e=t.req.valid("json");t.set("body",e);const{email:n,phone_number:r,name:i,linked_to:s,email_verified:a,provider:c,connection:l,password:d}=e,u=e.user_id,f=u?ns(u):La(),h=`${e.provider}|${f}`;try{const m=await t.env.data.users.create(t.var.tenant_id,{email:n,user_id:h,name:i||n||r,phone_number:r,provider:c,connection:l,linked_to:s??void 0,email_verified:a||!1,last_ip:"",is_social:!1,last_login:new Date().toISOString()});if(d){const b={user_id:m.user_id,password:await ti.hash(d,10),algorithm:"bcrypt"};await t.env.data.passwords.create(t.var.tenant_id,b)}t.set("user_id",m.user_id);const y=be(t,{type:_e.SUCCESS_API_OPERATION,description:"User created"});ve(t,t.env.data.logs.create(t.var.tenant_id,y));const v={...m,identities:[{connection:m.connection,provider:m.provider,user_id:ns(m.user_id),isSocial:m.is_social}]};return t.json(cn.parse(v),{status:201})}catch(m){throw m.message==="User already exists"?new S(409,{message:"User already exists"}):m}}).openapi(o.createRoute({tags:["users"],method:"patch",path:"/{user_id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({...Os.shape,verify_email:o.z.boolean(),password:o.z.string()}).partial()}}},params:o.z.object({user_id:o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{var m;const{data:e}=t.env,n=t.req.valid("json"),{user_id:r}=t.req.valid("param"),{verify_email:i,password:s,connection:a,...c}=n,l=await e.users.get(t.var.tenant_id,r);if(!l)throw new S(404);if(l.linked_to)throw new S(404,{message:"User is linked to another user"});let d=r,u=l;if(a)if(l.connection===a)d=r,u=l;else{const v=(await e.users.list(t.var.tenant_id,{page:0,per_page:100,include_totals:!1,q:`linked_to:${r}`})).users.find(b=>b.connection===a);if(!v)throw new S(404,{message:`No identity found with connection: ${a}`});d=v.user_id,u=v}if(c.email&&c.email!==u.email){const y=await Eu(t.env.data.users,t.var.tenant_id,c.email);if(y.length&&y.some(v=>v.user_id!==d))throw new S(409,{message:"Another user with the same email address already exists."})}if(await t.env.data.users.update(t.var.tenant_id,d,c),s){let y;if(a)if(a==="Username-Password-Authentication")y={provider:u.provider,user_id:ns(d)};else throw new S(400,{message:`Cannot set password for connection: ${a}`});else if(y=(m=l.identities)==null?void 0:m.find(A=>A.connection==="Username-Password-Authentication"),!y)throw new S(400,{message:"User does not have a password identity"});const v={user_id:`${y.provider}|${y.user_id}`,password:await ti.hash(s,10),algorithm:"bcrypt"};await e.passwords.get(t.var.tenant_id,`${y.provider}|${y.user_id}`)?await e.passwords.update(t.var.tenant_id,v):await e.passwords.create(t.var.tenant_id,v)}const f=await t.env.data.users.get(t.var.tenant_id,r);if(!f)throw new S(500);const h=be(t,{type:_e.SUCCESS_API_OPERATION,description:"Update a User",body:n});return h.details={...h.details,response:{statusCode:200,body:f}},ve(t,t.env.data.logs.create(t.var.tenant_id,h)),t.json(f)}).openapi(o.createRoute({tags:["users"],method:"post",path:"/{user_id}/identities",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.union([o.z.object({link_with:o.z.string()}),o.z.object({user_id:o.z.string(),provider:o.z.string(),connection:o.z.string().optional()})])}}},params:o.z.object({user_id:o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:o.z.array(o.z.object({connection:o.z.string(),provider:o.z.string(),user_id:o.z.string(),isSocial:o.z.boolean()}))}},description:"Status"}}}),async t=>{const e=t.req.valid("json"),{user_id:n}=t.req.valid("param"),r="link_with"in e?e.link_with:e.user_id,i=await t.env.data.users.get(t.var.tenant_id,n);if(!i)throw new S(400,{message:"Linking an inexistent identity is not allowed."});await t.env.data.users.update(t.var.tenant_id,r,{linked_to:n});const s=await t.env.data.users.list(t.var.tenant_id,{page:0,per_page:10,include_totals:!1,q:`linked_to:${n}`}),a=[i,...s.users].map(c=>({connection:c.connection,provider:c.provider,user_id:ns(c.user_id),isSocial:c.is_social}));return t.json(a,{status:201})}).openapi(o.createRoute({tags:["users"],method:"delete",path:"/{user_id}/identities/{provider}/{linked_user_id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({user_id:o.z.string(),provider:o.z.string(),linked_user_id:o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:o.z.array(cn)}},description:"Status"}}}),async t=>{const{user_id:e,provider:n,linked_user_id:r}=t.req.valid("param");await t.env.data.users.unlink(t.var.tenant_id,e,n,r);const i=await t.env.data.users.get(t.var.tenant_id,e);if(!i)throw new S(404);return t.json([cn.parse(i)])}).openapi(o.createRoute({tags:["users"],method:"get",path:"/{user_id}/sessions",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({user_id:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Ba),wb])}},description:"List of sessions"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{include_totals:n,page:r,per_page:i}=t.req.valid("query"),s=await t.env.data.sessions.list(t.var.tenant_id,{page:r,per_page:i,include_totals:n,q:`user_id:${e}`});return n?t.json(s):t.json(s.sessions)}).openapi(o.createRoute({tags:["users"],method:"get",path:"/{user_id}/permissions",request:{params:o.z.object({user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),query:Qe},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:am}},description:"User permissions"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{page:n,per_page:r,sort:i,q:s}=t.req.valid("query");if(!await t.env.data.users.get(t.var.tenant_id,e))throw new S(404,{message:"User not found"});const c=await t.env.data.userPermissions.list(t.var.tenant_id,e,{page:n,per_page:r,include_totals:!1,sort:ft(i),q:s});return t.json(c)}).openapi(o.createRoute({tags:["users"],method:"post",path:"/{user_id}/permissions",request:{params:o.z.object({user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({permissions:o.z.array(o.z.object({permission_name:o.z.string(),resource_server_identifier:o.z.string()}))})}}}},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Permissions assigned to user"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{permissions:n}=t.req.valid("json");if(!await t.env.data.users.get(t.var.tenant_id,e))throw new S(404,{message:"User not found"});for(const i of n)if(!await t.env.data.userPermissions.create(t.var.tenant_id,e,{user_id:e,resource_server_identifier:i.resource_server_identifier,permission_name:i.permission_name}))throw new S(500,{message:"Failed to assign permissions to user"});return t.json({message:"Permissions assigned successfully"},{status:201})}).openapi(o.createRoute({tags:["users"],method:"delete",path:"/{user_id}/permissions",request:{params:o.z.object({user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({permissions:o.z.array(o.z.object({permission_name:o.z.string(),resource_server_identifier:o.z.string()}))})}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Permissions removed from user"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{permissions:n}=t.req.valid("json");if(!await t.env.data.users.get(t.var.tenant_id,e))throw new S(404,{message:"User not found"});for(const i of n)if(!await t.env.data.userPermissions.remove(t.var.tenant_id,e,i))throw new S(500,{message:"Failed to remove permissions from user"});return t.json({message:"Permissions removed successfully"})}).openapi(o.createRoute({tags:["users"],method:"get",path:"/{user_id}/roles",request:{params:o.z.object({user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ms}},description:"User roles"}}}),async t=>{const{user_id:e}=t.req.valid("param");if(!await t.env.data.users.get(t.var.tenant_id,e))throw new S(404,{message:"User not found"});const r=await t.env.data.userRoles.list(t.var.tenant_id,e,void 0,"");return t.json(r)}).openapi(o.createRoute({tags:["users"],method:"post",path:"/{user_id}/roles",request:{params:o.z.object({user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({roles:o.z.array(o.z.string())})}}}},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Roles assigned to user"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{roles:n}=t.req.valid("json");if(!await t.env.data.users.get(t.var.tenant_id,e))throw new S(404,{message:"User not found"});for(const i of n)if(!await t.env.data.userRoles.create(t.var.tenant_id,e,i,""))throw new S(500,{message:"Failed to assign roles to user"});return t.json({message:"Roles assigned successfully"},{status:201})}).openapi(o.createRoute({tags:["users"],method:"delete",path:"/{user_id}/roles",request:{params:o.z.object({user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({roles:o.z.array(o.z.string())})}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Roles removed from user"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{roles:n}=t.req.valid("json");if(!await t.env.data.users.get(t.var.tenant_id,e))throw new S(404,{message:"User not found"});for(const i of n)if(!await t.env.data.userRoles.remove(t.var.tenant_id,e,i,""))throw new S(500,{message:"Failed to remove roles from user"});return t.json({message:"Roles removed successfully"})}).openapi(o.createRoute({tags:["users"],method:"get",path:"/{user_id}/organizations",request:{params:o.z.object({user_id:o.z.string()}),query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([vb,o.z.array(Dn)])}},description:"List of user organizations"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{page:n,per_page:r,include_totals:i,sort:s}=t.req.valid("query");if(!await t.env.data.users.get(t.var.tenant_id,e))throw new S(404,{message:"User not found"});const c=await t.env.data.userOrganizations.listUserOrganizations(t.var.tenant_id,e,{page:n,per_page:r,sort:ft(s)});return i?t.json({organizations:c.organizations,start:c.start,limit:c.limit,length:c.length}):t.json(c.organizations)}).openapi(o.createRoute({tags:["users"],method:"delete",path:"/{user_id}/organizations/{organization_id}",request:{params:o.z.object({user_id:o.z.string(),organization_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"User removed from organization successfully"}}}),async t=>{const{user_id:e,organization_id:n}=t.req.valid("param");if(!await t.env.data.users.get(t.var.tenant_id,e))throw new S(404,{message:"User not found"});const s=(await t.env.data.userOrganizations.list(t.var.tenant_id,{q:`user_id:${e}`,per_page:100})).userOrganizations.find(a=>a.organization_id===n);if(!s)throw new S(404,{message:"User is not a member of this organization"});return await t.env.data.userOrganizations.remove(t.var.tenant_id,s.id),t.json({message:"User removed from organization successfully"})});/*! *****************************************************************************
72
+ </html>`}const jm=["openid","profile","email","address","phone"];async function ib(t,e){var O,U;const{tenantId:n,clientId:r,audience:i,requestedScopes:s}=e,a=s.filter(T=>jm.includes(T)),l=(await t.env.data.resourceServers.list(n)).resource_servers.filter(T=>T.identifier===i);if(l.length===0)return{scopes:a,permissions:[]};const d=l[0];if(!d)return{scopes:a,permissions:[]};const u=((O=d.options)==null?void 0:O.enforce_policies)===!0,f=((U=d.options)==null?void 0:U.token_dialect)||"access_token",m=(await t.env.data.clientGrants.list(n,{q:`client_id:"${r}"`})).client_grants.find(T=>T.audience===i);if(!m)return{scopes:a,permissions:[]};const y=m.scope||[],v=(d.scopes||[]).map(T=>T.value);if(!u){let T;return s.length===0?T=y.filter(W=>v.includes(W)):T=s.filter(W=>v.includes(W)&&y.includes(W)),{scopes:[...new Set([...a,...T])],permissions:[]}}if(f==="access_token_authz"){const T=y.filter(R=>v.includes(R));return{scopes:a,permissions:T}}let b;return s.length===0?b=y.filter(T=>v.includes(T)):b=s.filter(T=>v.includes(T)&&y.includes(T)),{scopes:[...new Set([...a,...b])],permissions:[]}}async function Vs(t,e){var ne,Q;if(e.grantType===Vt.ClientCredential)return await ib(t,{tenantId:e.tenantId,clientId:e.clientId,audience:e.audience,requestedScopes:e.requestedScopes});const{tenantId:n,userId:r,audience:i,requestedScopes:s,organizationId:a}=e;if(a&&!(await t.env.data.userOrganizations.list(n,{q:`user_id:${r}`,per_page:1e3})).userOrganizations.some(N=>N.organization_id===a))throw new ee(403,{error:"access_denied",error_description:"User is not a member of the specified organization"});const c=s.filter(K=>jm.includes(K)),d=(await t.env.data.resourceServers.list(n)).resource_servers.filter(K=>K.identifier===i);if(d.length===0)return{scopes:c,permissions:[]};const u=d[0];if(!u)return{scopes:c,permissions:[]};const f=(u.scopes||[]).map(K=>K.value),h=((ne=u.options)==null?void 0:ne.enforce_policies)===!0,m=((Q=u.options)==null?void 0:Q.token_dialect)||"access_token";if(!h){const K=s.filter(N=>f.includes(N));return{scopes:[...new Set([...c,...K])],permissions:[]}}const y=await t.env.data.userPermissions.list(n,r,void 0,a),v=await t.env.data.userRoles.list(n,r,void 0,""),b=a?await t.env.data.userRoles.list(n,r,void 0,a):[],A=[...v,...b],O=[];for(const K of A)(await t.env.data.rolePermissions.list(n,K.id)).forEach(N=>{N.resource_server_identifier===i&&O.push(N.permission_name)});const U=new Set;y.forEach(K=>{K.resource_server_identifier===i&&U.add(K.permission_name)}),O.forEach(K=>{U.add(K)});const T=Array.from(U);if(m==="access_token_authz"){const K=T.filter(de=>f.includes(de));return{scopes:c,permissions:K}}const R=s.filter(K=>f.includes(K)&&T.includes(K));return{scopes:[...new Set([...c,...R])],permissions:[]}}const mf=["sub","iss","aud","exp","nbf","iat","jti"];async function Fa(t,e){var U,T;const{authParams:n,user:r,client:i,session_id:s,organization:a,permissions:c,impersonatingUser:l}=e,{signingKeys:d}=await t.env.data.keys.list({q:"type:jwt_signing"}),u=d.filter(R=>!R.revoked_at||new Date(R.revoked_at)>new Date),f=u[u.length-1];if(!(f!=null&&f.pkcs7))throw new ee(500,{message:"No signing key available"});const h=bv(f.pkcs7),m=t.var.custom_domain?`https://${t.var.custom_domain}/`:t.env.ISSUER,y={aud:n.audience||"default",scope:n.scope||"",sub:(r==null?void 0:r.user_id)||n.client_id,iss:m,tenant_id:t.var.tenant_id,sid:s,act:l?{sub:l.user_id}:void 0,org_id:a?a.id:void 0,permissions:c},v=r&&((U=n.scope)!=null&&U.split(" ").includes("openid"))?{aud:n.client_id,sub:r.user_id,iss:m,sid:s,nonce:n.nonce,given_name:r.given_name,family_name:r.family_name,nickname:r.nickname,picture:r.picture,locale:r.locale,name:r.name,email:r.email,email_verified:r.email_verified,act:l?{sub:l.user_id}:void 0,org_id:a==null?void 0:a.id,org_name:a==null?void 0:a.name}:void 0;(T=t.env.hooks)!=null&&T.onExecuteCredentialsExchange&&await t.env.hooks.onExecuteCredentialsExchange({ctx:t,client:i,user:r,request:{ip:t.var.ip||"",user_agent:t.var.useragent||"",method:t.req.method,url:t.req.url},scope:n.scope||"",grant_type:""},{accessToken:{setCustomClaim:(R,W)=>{if(mf.includes(R))throw new Error(`Cannot overwrite reserved claim '${R}'`);y[R]=W}},idToken:{setCustomClaim:(R,W)=>{if(mf.includes(R))throw new Error(`Cannot overwrite reserved claim '${R}'`);v&&(v[R]=W)}},access:{deny:R=>{throw new ee(400,{message:`Access denied: ${R}`})}},token:{createServiceToken:async R=>{const{createServiceToken:W}=await Promise.resolve().then(()=>sb);return(await W(t,t.var.tenant_id,R.scope,R.expiresInSeconds)).access_token}}});const b={includeIssuedTimestamp:!0,expiresIn:l?new qs(1,"h"):new qs(1,"d"),headers:{kid:f.kid}},A=await cf("RS256",h,y,b),O=v?await cf("RS256",h,v,b):void 0;return{access_token:A,refresh_token:e.refresh_token,id_token:O,token_type:"Bearer",expires_in:l?3600:86400}}async function Om(t,e){return{code:(await t.env.data.codes.create(e.client.tenant.id,{code_id:Ne(),user_id:e.user.user_id,code_type:"authorization_code",login_id:e.login_id,expires_at:new Date(Date.now()+xv*1e3).toISOString(),code_challenge:e.authParams.code_challenge,code_challenge_method:e.authParams.code_challenge_method,redirect_uri:e.authParams.redirect_uri,state:e.authParams.state,nonce:e.authParams.nonce})).code_id,state:e.authParams.state}}async function Tm(t,e){const{client:n,scope:r,audience:i=n.tenant.audience,session_id:s}=e;return await t.env.data.refreshTokens.create(n.tenant.id,{id:Ne(),session_id:s,client_id:n.client_id,idle_expires_at:new Date(Date.now()+Da*1e3).toISOString(),user_id:e.user.user_id,device:{last_ip:t.var.ip,initial_ip:t.var.ip,last_user_agent:t.var.useragent||"",initial_user_agent:t.var.useragent||"",initial_asn:"",last_asn:""},resource_servers:[{audience:i,scopes:r}],rotating:!1})}async function Pm(t,{user:e,client:n,loginSession:r}){const i=await t.env.data.sessions.create(n.tenant.id,{id:Ne(),user_id:e.user_id,login_session_id:r.id,idle_expires_at:new Date(Date.now()+Da*1e3).toISOString(),device:{last_ip:t.var.ip||"",initial_ip:t.var.ip||"",last_user_agent:t.var.useragent||"",initial_user_agent:t.var.useragent||"",initial_asn:"",last_asn:""},clients:[n.client_id]});return await t.env.data.loginSessions.update(n.tenant.id,r.id,{session_id:i.id}),i}async function un(t,e){var m,y;const{authParams:n,client:r,ticketAuth:i}=e;let{user:s}=e;const a=n.response_type||Bt.CODE,c=n.response_mode||ln.QUERY;if(i){if(!e.loginSession)throw new ee(500,{message:"Login session not found for ticket auth."});const v=vv(),b=Ne(12),A=await t.env.data.codes.create(r.tenant.id,{code_id:Ne(),code_type:"ticket",login_id:e.loginSession.id,expires_at:new Date(Date.now()+zv).toISOString(),code_verifier:[b,v].join("|"),redirect_uri:n.redirect_uri,state:n.state,nonce:n.nonce});return t.json({login_ticket:A.code_id,co_verifier:v,co_id:b})}let l=e.refreshToken,d=e.sessionId;if(!d&&((m=e.loginSession)!=null&&m.session_id)){d=e.loginSession.session_id;const v=await t.env.data.sessions.get(r.tenant.id,d);v&&!v.clients.includes(r.client_id)&&await t.env.data.sessions.update(r.tenant.id,d,{clients:[...v.clients,r.client_id]})}else if(!d){if(!e.loginSession)throw new ee(500,{message:"Login session not found for creating a new session."});d=(await Pm(t,{user:s,client:r,loginSession:e.loginSession})).id}if(!l&&((y=n.scope)!=null&&y.split(" ").includes("offline_access"))&&![Bt.TOKEN,Bt.CODE].includes(a)&&!e.impersonatingUser&&(l=(await Tm(t,{user:s,client:r,session_id:d,scope:n.scope,audience:n.audience})).id),c===ln.SAML_POST){if(!d)throw new S(500,{message:"Session ID not available for SAML response"});return rb(t,e.client,e.authParams,s,d)}const u=await ob(t,{authParams:n,user:s,client:r,session_id:d,refresh_token:l,strategy:e.strategy,loginSession:e.loginSession,responseType:a,skipHooks:e.skipHooks,organization:e.organization,impersonatingUser:e.impersonatingUser});if(u instanceof Response)return u;if(c===ln.WEB_MESSAGE){if(!n.redirect_uri)throw new ee(400,{message:"Redirect URI not allowed for WEB_MESSAGE response mode."});const v=new Headers;if(d){const O=Hs(r.tenant.id,d,t.var.host||"");O&&v.set("set-cookie",O)}else console.warn("Session ID not available for WEB_MESSAGE, cookie will not be set.");const b=new URL(n.redirect_uri),A=`${b.protocol}//${b.host}`;return t.html(jl(A,JSON.stringify({...u,state:n.state})),{headers:v})}if(!n.redirect_uri)throw new ee(400,{message:"Redirect uri not found for this response mode."});const f=new Headers;if(d){const v=Hs(r.tenant.id,d,t.var.custom_domain||t.req.header("host")||"");v&&f.set("set-cookie",v)}const h=new URL(n.redirect_uri);if("code"in u)h.searchParams.set("code",u.code),u.state&&h.searchParams.set("state",u.state);else if("access_token"in u)h.hash=new URLSearchParams({access_token:u.access_token,...u.id_token&&{id_token:u.id_token},token_type:u.token_type,expires_in:u.expires_in.toString(),...n.state&&{state:n.state},...n.scope&&{scope:n.scope}}).toString();else throw new ee(500,{message:"Invalid token response for implicit flow."});return f.set("location",h.toString()),new Response("Redirecting",{status:302,headers:f})}async function ob(t,e){var c,l,d,u,f,h;let{user:n}=e;const r=e.responseType||Bt.TOKEN;if(n&&e.organization&&!(await t.env.data.userOrganizations.list(e.client.tenant.id,{q:`user_id:${n.user_id}`,per_page:1e3})).userOrganizations.some(v=>v.organization_id===e.organization.id))throw new ee(403,{error:"access_denied",error_description:"User is not a member of the specified organization"});let i=e.authParams.scope||"",s=[];if(e.authParams.audience)try{let m;if(e.grantType===Vt.ClientCredential||!n&&!e.user)m=await Vs(t,{grantType:Vt.ClientCredential,tenantId:e.client.tenant.id,clientId:e.client.client_id,audience:e.authParams.audience,requestedScopes:((c=e.authParams.scope)==null?void 0:c.split(" "))||[],organizationId:(l=e.organization)==null?void 0:l.id});else{const y=(n==null?void 0:n.user_id)||((d=e.user)==null?void 0:d.user_id);if(!y)throw new ee(400,{error:"invalid_request",error_description:"User ID is required for user-based grants"});m=await Vs(t,{grantType:e.grantType,tenantId:e.client.tenant.id,userId:y,clientId:e.client.client_id,audience:e.authParams.audience,requestedScopes:((u=e.authParams.scope)==null?void 0:u.split(" "))||[],organizationId:(f=e.organization)==null?void 0:f.id})}i=m.scopes.join(" "),s=m.permissions}catch(m){if(m instanceof S)throw m}const a={...e.authParams,scope:i};if(e.loginSession&&n&&!e.skipHooks){e.strategy&&((h=n.app_metadata)==null?void 0:h.strategy)!==e.strategy&&(n.app_metadata={...n.app_metadata,strategy:e.strategy},await t.env.data.users.update(e.client.tenant.id,n.user_id,{app_metadata:{...n.app_metadata||{},strategy:e.strategy}}));const m=await Um(t,t.env.data,e.client.tenant.id,n,e.loginSession,{client:e.client,authParams:a,authStrategy:e.strategy?{strategy:e.strategy,strategy_type:"social"}:void 0});if(m instanceof Response)return m;n=m}if(r===Bt.CODE){if(!n||!e.loginSession)throw new ee(500,{message:"User and loginSession is required for code flow"});return await Om(t,{user:n,client:e.client,authParams:a,login_id:e.loginSession.id})}else return Fa(t,{...e,user:n,authParams:a,permissions:s})}const _f="auth-service";async function Au(t,e,n,r){const i=await t.env.data.tenants.get(e);if(!i)throw new Error(`Tenant not found: ${e}`);const s={client_id:_f,tenant:i,created_at:new Date().toISOString(),updated_at:new Date().toISOString(),name:"Auth Service",global:!1,is_first_party:!0,oidc_conformant:!1,sso:!1,sso_disabled:!1,cross_origin_authentication:!1,custom_login_page_on:!1,require_pushed_authorization_requests:!1,require_proof_of_possession:!1,client_metadata:{disable_sign_ups:"false",email_validation:"disabled"},disable_sign_ups:!1,email_validation:"disabled",connections:[]},a=await Fa(t,{client:s,authParams:{client_id:_f,response_type:Bt.TOKEN,scope:n}});return{access_token:a.access_token,token_type:a.token_type,expires_in:r||3600}}const sb=Object.freeze(Object.defineProperty({__proto__:null,createServiceToken:Au},Symbol.toStringTag,{value:"Module"}));var ab={deno:"Deno",bun:"Bun",workerd:"Cloudflare-Workers",node:"Node.js"},Rm=()=>{var n,r;const t=globalThis;if(typeof navigator<"u"&&typeof navigator.userAgent=="string"){for(const[i,s]of Object.entries(ab))if(cb(s))return i}return typeof(t==null?void 0:t.EdgeRuntime)=="string"?"edge-light":(t==null?void 0:t.fastly)!==void 0?"fastly":((r=(n=t==null?void 0:t.process)==null?void 0:n.release)==null?void 0:r.name)==="node"?"node":"other"},cb=t=>navigator.userAgent.startsWith(t);function ve(t,e){Rm()==="workerd"&&t.executionCtx.waitUntil(e)}async function Bm(t,e,n){const r=await Au(t,n.tenant_id,"webhook");for await(const i of e.filter(s=>"url"in s))if(!(await fetch(i.url,{method:"POST",headers:{Authorization:`Bearer ${r.access_token}`,"Content-Type":"application/json"},body:JSON.stringify(n)})).ok){const a=be(t,{type:_e.FAILED_HOOK,description:`Failed to invoke hook ${i.hook_id}`});ve(t,t.env.data.logs.create(n.tenant_id,a))}}function lb(t){return async(e,n)=>{const{hooks:r}=await t.env.data.hooks.list(e);return await Bm(t,r,{tenant_id:e,user:n,trigger_id:"post-user-registration"}),n}}function db(t){return async(e,n)=>{const{hooks:r}=await t.env.data.hooks.list(e,{q:"trigger_id:pre-user-signup",page:0,per_page:100,include_totals:!1});await Bm(t,r,{tenant_id:e,email:n,trigger_id:"pre-user-signup"})}}function yf(t){return typeof t.form_id=="string"}async function ub(t,e,n){var l;const r=t.env.data,i=t.var.tenant_id||t.req.header("tenant-id");if(!i)throw new S(400,{message:"Missing tenant_id in context"});const s=await r.forms.get(i,e);if(!s)throw new S(404,{message:"Form not found for post-user-login hook"});let a=(l=s.start)==null?void 0:l.next_node;if(!a&&s.nodes&&s.nodes.length>0){const d=s.nodes.find(u=>u.type==="STEP");a=d==null?void 0:d.id}if(!a)throw new S(400,{message:"No start node found in form"});let c=`/u/forms/${s.id}/nodes/${a}?state=${encodeURIComponent(n.id)}`;return new Response(null,{status:302,headers:{location:c}})}function wf(t){return typeof t.page_id=="string"&&typeof t.enabled=="boolean"}async function pb(t,e,n,r,i){const s=t.env.data,a=t.var.tenant_id||t.req.header("tenant-id");if(!a)throw new S(400,{message:"Missing tenant_id in context"});if(i&&!(await s.userPermissions.list(a,r.user_id)).some(u=>u.permission_name===i))return r;let c=`/u/${e}?state=${encodeURIComponent(n.id)}`;return new Response(null,{status:302,headers:{location:c}})}function ri(t,e){return{createServiceToken:async n=>(await Au(t,e,n.scope,n.expiresInSeconds)).access_token}}function vf(t){return typeof t.url=="string"}function fb(t,e){return async(n,r)=>{var a,c,l;if(t.var.client_id){const d=await e.legacyClients.get(t.var.client_id);if(!d)throw new ee(400,{message:"Client not found"});r.email&&await Lm(t,d,e,r.email)}const i={method:t.req.method,ip:t.req.query("x-real-ip")||"",user_agent:t.req.query("user-agent"),url:((a=t.var.loginSession)==null?void 0:a.authorization_url)||t.req.url};if((c=t.env.hooks)!=null&&c.onExecutePreUserRegistration)try{await t.env.hooks.onExecutePreUserRegistration({ctx:t,user:r,request:i},{user:{setUserMetadata:async(d,u)=>{r[d]=u}},token:ri(t,n)})}catch{const u=be(t,{type:_e.FAILED_SIGNUP,description:"Pre user registration hook failed"});ve(t,e.logs.create(n,u))}let s=await fv(e)(n,r);if((l=t.env.hooks)!=null&&l.onExecutePostUserRegistration)try{await t.env.hooks.onExecutePostUserRegistration({ctx:t,user:r,request:i},{user:{},token:ri(t,n)})}catch{const u=be(t,{type:_e.FAILED_SIGNUP,description:"Post user registration hook failed"});ve(t,t.env.data.logs.create(n,u))}return await lb(t)(n,s),s}}function hb(t,e){return async(n,r,i)=>{var c;if(Object.keys(i).length===1&&"linked_to"in i)return e.users.update(n,r,i);const s=await e.users.get(n,r);if(!s)throw new ee(404,{message:"User not found"});const a={method:t.req.method,ip:t.var.ip||t.get("ip")||"",user_agent:t.var.useragent||t.get("useragent")||"",url:t.req.url};if((c=t.env.hooks)!=null&&c.onExecutePreUserUpdate)try{await t.env.hooks.onExecutePreUserUpdate({ctx:t,tenant:{id:n},user_id:r,user:s,updates:i,request:a},{user:{setUserMetadata:async(l,d)=>{i[l]=d}},cancel:()=>{throw new ee(400,{message:"User update cancelled by pre-update hook"})},token:ri(t,n)})}catch{throw new ee(400,{message:"Pre user update hook failed"})}if(await e.users.update(n,r,i),i.email||i.email_verified){const l=await e.users.get(n,r);if(l&&l.email&&l.email_verified){const{users:d}=await e.users.list(n,{page:0,per_page:10,include_totals:!1,q:`email:${l.email}`}),u=d.filter(f=>f.email_verified&&f.user_id!==r&&!f.linked_to);u.length>0&&await e.users.update(n,r,{linked_to:u[0].user_id})}}if(i.email){const l=be(t,{type:_e.SUCCESS_CHANGE_EMAIL,description:`Email updated to ${i.email}`,userId:r});ve(t,e.logs.create(n,l))}return!0}}async function gb(t,e,n,r){var i,s;if(((i=e.client_metadata)==null?void 0:i.disable_sign_ups)==="true"){const a=(s=t.var.loginSession)==null?void 0:s.authorization_url;if(a&&new URL(a).searchParams.get("screen_hint")==="signup")return{allowed:!0};if(!await Cu({userAdapter:n.users,tenant_id:e.tenant.id,email:r}))return{allowed:!1,reason:"Public signup is disabled for this client"}}return{allowed:!0}}async function Lm(t,e,n,r){const i=await gb(t,e,n,r);if(!i.allowed){const s=be(t,{type:_e.FAILED_SIGNUP,description:i.reason||"Signup not allowed"});throw ve(t,n.logs.create(e.tenant.id,s)),new ee(400,{message:i.reason||"Signups are disabled for this client"})}await db(t)(e.tenant.id,r)}function mb(t,e){return async(n,r)=>{var c,l;const i=await e.users.get(n,r);if(!i)return!1;const s={method:t.req.method,ip:t.var.ip||t.get("ip")||"",user_agent:t.var.useragent||t.get("useragent")||"",url:t.req.url};if((c=t.env.hooks)!=null&&c.onExecutePreUserDeletion)try{await t.env.hooks.onExecutePreUserDeletion({ctx:t,user:i,user_id:r,request:s,tenant:{id:n}},{cancel:()=>{throw new ee(400,{message:"User deletion cancelled by pre-deletion hook"})},token:ri(t,n)})}catch(d){if(d instanceof S)throw d;const u=be(t,{type:_e.FAILED_HOOK,description:`Pre user deletion hook failed: ${d instanceof Error?d.message:String(d)}`});throw ve(t,e.logs.create(n,u)),new ee(400,{message:"Pre user deletion hook failed"})}const a=await e.users.remove(n,r);if(a){const d=be(t,{type:_e.SUCCESS_USER_DELETION,description:`user_id: ${r}`,strategy:i.provider||"auth0",strategy_type:i.is_social?"social":"database"});d.connection=i.connection||"",d.connection_id="",d.details={...d.details,body:{tenant:n,connection:i.connection||""}},ve(t,e.logs.create(n,d))}if(a&&((l=t.env.hooks)!=null&&l.onExecutePostUserDeletion))try{await t.env.hooks.onExecutePostUserDeletion({ctx:t,user:i,user_id:r,request:s,tenant:{id:n}},{token:ri(t,n)})}catch(d){const u=be(t,{type:_e.FAILED_HOOK,description:`Post user deletion hook failed: ${d instanceof Error?d.message:String(d)}`});ve(t,e.logs.create(n,u))}return a}}function xo(t,e){const n=e;return{...e,users:{...e.users,create:fb(t,n),update:hb(t,n),remove:mb(t,n)}}}async function _b(t,e,n,r,i,s){var u,f,h,m,y,v,b,A,O,U,T,R,W,ne;let a=[];try{a=(await e.userRoles.list(n,r.user_id,void 0,"")).map(de=>de.name||de.id)}catch(Q){console.error("Error fetching user roles:",Q)}let c={};if(r.connection)try{const K=(await e.connections.list(n,{page:0,per_page:100,include_totals:!1})).connections.find(de=>de.name===r.connection);K&&(c={id:K.id,name:K.name,strategy:K.strategy||r.provider,metadata:K.options||{}})}catch(Q){console.error("Error fetching connection info:",Q)}let l;try{if((u=i.authParams)!=null&&u.organization){const Q=await e.organizations.get(n,i.authParams.organization);Q&&(l={id:Q.id,name:Q.name,display_name:Q.display_name||Q.name,metadata:Q.metadata||{}})}}catch(Q){console.error("Error fetching organization info:",Q)}const d=t.get("countryCode");return{ctx:t,client:s.client,user:r,request:{asn:void 0,ip:t.get("ip")||"",user_agent:t.get("useragent"),method:t.req.method,url:t.req.url,geoip:{cityName:void 0,continentCode:void 0,countryCode:d||void 0,countryName:void 0,latitude:void 0,longitude:void 0,timeZone:void 0}},transaction:{id:i.id,locale:((f=i.authParams)==null?void 0:f.ui_locales)||"en",login_hint:void 0,prompt:(h=i.authParams)==null?void 0:h.prompt,redirect_uri:(m=i.authParams)==null?void 0:m.redirect_uri,requested_scopes:((v=(y=i.authParams)==null?void 0:y.scope)==null?void 0:v.split(" "))||[],response_mode:(b=i.authParams)==null?void 0:b.response_mode,response_type:(A=i.authParams)==null?void 0:A.response_type,state:(O=i.authParams)==null?void 0:O.state,ui_locales:(U=i.authParams)==null?void 0:U.ui_locales},scope:((T=s.authParams)==null?void 0:T.scope)||"",grant_type:((R=s.authParams)==null?void 0:R.grant_type)||"",audience:(W=s.authParams)==null?void 0:W.audience,authentication:{methods:[{name:r.is_social?"federated":"pwd",timestamp:new Date().toISOString()}]},authorization:{roles:a},connection:Object.keys(c).length>0?c:{id:r.connection||"Username-Password-Authentication",name:r.connection||"Username-Password-Authentication",strategy:r.provider||"auth0"},organization:l,resource_server:(ne=s.authParams)!=null&&ne.audience?{identifier:s.authParams.audience}:void 0,stats:{logins_count:r.login_count||0},tenant:{id:n},session:{id:i.id,created_at:i.created_at,authenticated_at:new Date().toISOString(),clients:[{client_id:s.client.client_id}],device:{initial_ip:t.get("ip"),initial_user_agent:t.get("useragent"),last_ip:r.last_ip||t.get("ip"),last_user_agent:t.get("useragent")}}}}async function Um(t,e,n,r,i,s){var f,h,m,y,v;const a=(f=s==null?void 0:s.authStrategy)!=null&&f.strategy_type?s.authStrategy.strategy_type:r.is_social?"social":"database",c=((h=s==null?void 0:s.authStrategy)==null?void 0:h.strategy)||r.connection||"",l=be(t,{type:_e.SUCCESS_LOGIN,description:`Successful login for ${r.user_id}`,userId:r.user_id,strategy_type:a,strategy:c,connection:c,audience:(m=s==null?void 0:s.authParams)==null?void 0:m.audience,scope:(y=s==null?void 0:s.authParams)==null?void 0:y.scope});if(ve(t,e.logs.create(n,l)),await e.users.update(n,r.user_id,{last_login:new Date().toISOString(),last_ip:t.var.ip||"",login_count:r.login_count+1}),(v=t.env.hooks)!=null&&v.onExecutePostLogin&&(s!=null&&s.client)&&(s!=null&&s.authParams)&&i){let b=null;const A=await _b(t,e,n,r,i,{client:s.client,authParams:s.authParams});if(await t.env.hooks.onExecutePostLogin(A,{prompt:{render:O=>{}},redirect:{sendUserTo:(O,U)=>{const T=new URL(O,t.req.url);T.searchParams.set("state",i.id),U!=null&&U.query&&Object.entries(U.query).forEach(([R,W])=>{T.searchParams.set(R,W)}),b=T.toString()},encodeToken:O=>JSON.stringify({payload:O.payload,exp:Date.now()+(O.expiresInSeconds||900)*1e3}),validateToken:O=>null},token:ri(t,n)}),b)return new Response(null,{status:302,headers:{location:b}})}const{hooks:d}=await e.hooks.list(n,{q:"trigger_id:post-user-login",page:0,per_page:100,include_totals:!1});if(i){const b=d.find(O=>O.enabled&&yf(O));if(b&&yf(b))return ub(t,b.form_id,i);const A=d.find(O=>O.enabled&&wf(O));if(A&&wf(A))return pb(t,A.page_id,i,r,A.permission_required)}const u=d.filter(b=>b.enabled&&vf(b));for(const b of u)if(vf(b))try{await fetch(b.url,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tenant_id:n,user:r,trigger_id:"post-user-login"})})}catch{const O=be(t,{type:_e.FAILED_HOOK,description:`Failed to invoke post-user-login webhook: ${b.url}`});ve(t,e.logs.create(n,O))}return r}function yb(t){return xo(t,t.env.data)}async function Eu(t,e,n){return(await t.list(e,{page:0,per_page:10,include_totals:!1,q:`email:${n}`})).users}async function vi({userAdapter:t,tenant_id:e,username:n,provider:r}){const i=r==="sms"?`phone_number:${n}`:`email:${n}`,{users:s}=await t.list(e,{page:0,per_page:10,include_totals:!1,q:`${i} provider:${r}`});return s.length>1&&console.error("More than one user found for same email and provider"),s[0]||null}async function Cu({userAdapter:t,tenant_id:e,email:n}){var c;const{users:r}=await t.list(e,{page:0,per_page:10,include_totals:!1,q:`email:${n}`}),i=r.filter(l=>!(l.provider==="auth2"&&!l.email_verified));if(i.length===0)return;const s=i.filter(l=>!l.linked_to);if(s.length>0)return s.length>1&&console.error("More than one primary user found for same email"),s[0];const a=await t.get(e,(c=i[0])==null?void 0:c.linked_to);if(!a)throw new Error("Primary account not found");return a}async function io({userAdapter:t,tenant_id:e,username:n,provider:r}){const i=await vi({userAdapter:t,tenant_id:e,username:n,provider:r});return i?i.linked_to?t.get(e,i.linked_to):i:null}async function qa(t,e){const{username:n,provider:r,connection:i,client:s,userId:a,isSocial:c,profileData:l={},ip:d=""}=e;let u=await io({userAdapter:t.env.data.users,tenant_id:e.client.tenant.id,username:n,provider:r});if(!u){const f={user_id:`${r}|${a||La()}`,email:i!=="sms"?n:void 0,phone_number:i==="sms"?n:void 0,name:n,provider:r,connection:i,email_verified:!0,last_ip:d,is_social:c,last_login:new Date().toISOString(),profileData:JSON.stringify(l)};u=await yb(t).users.create(s.tenant.id,f),t.set("user_id",u.user_id)}return u}const Qe=o.z.object({page:o.z.string().min(0).optional().default("0").transform(t=>parseInt(t,10)).openapi({description:"The page number where 0 is the first page"}),per_page:o.z.string().min(1).optional().default("10").transform(t=>parseInt(t,10)).openapi({description:"The number of items per page"}),include_totals:o.z.string().optional().default("false").transform(t=>t==="true").openapi({description:"If the total number of items should be included in the response"}),sort:o.z.string().regex(/^.+:(-1|1)$/).optional().openapi({description:"A property that should have the format 'string:-1' or 'string:1'"}),q:o.z.string().optional().openapi({description:"A lucene query string used to filter the results"})});function ft(t){if(!t)return;const[e,n]=t.split(":"),r=n==="1"?"asc":"desc";if(!(!e||!r))return{sort_by:e,sort_order:r}}const bf=St.extend({users:o.z.array(an)}),wb=St.extend({sessions:o.z.array(Ba)}),vb=St.extend({organizations:o.z.array(Dn)}),bb=new o.OpenAPIHono().openapi(o.createRoute({tags:["users"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(an),bf])}},description:"List of users"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query");if(s!=null&&s.includes("identities.profileData.email")){const d=s.split("=")[1],f=(await t.env.data.users.list(t.var.tenant_id,{page:e,per_page:n,include_totals:r,q:`email:${d}`})).users.filter(y=>y.linked_to),[h]=f;if(!h)return t.json([]);const m=await t.env.data.users.get(t.var.tenant_id,h.linked_to);if(!m)throw new S(500,{message:"Primary account not found"});return t.json([an.parse(m)])}const a=["-_exists_:linked_to"];s&&a.push(s);const c=await t.env.data.users.list(t.var.tenant_id,{page:e,per_page:n,include_totals:r,sort:ft(i),q:a.join(" ")}),l=c.users.filter(d=>!d.linked_to);return r?t.json(bf.parse({users:l,length:c.length,start:c.start,limit:c.limit})):t.json(o.z.array(an).parse(l))}).openapi(o.createRoute({tags:["users"],method:"get",path:"/{user_id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({user_id:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:an}},description:"List of users"}}}),async t=>{const{user_id:e}=t.req.valid("param"),n=await t.env.data.users.get(t.var.tenant_id,e);if(!n)throw new S(404);if(n.linked_to)throw new S(404,{message:"User is linked to another user"});return t.json(n)}).openapi(o.createRoute({tags:["users"],method:"delete",path:"/{user_id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({user_id:o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{user_id:e}=t.req.valid("param");if(!await t.env.data.users.remove(t.var.tenant_id,e))throw new S(404);const r=be(t,{type:_e.SUCCESS_API_OPERATION,description:"Delete a User"});return r.details={...r.details,response:{statusCode:204,body:{}}},ve(t,t.env.data.logs.create(t.var.tenant_id,r)),t.text("OK")}).openapi(o.createRoute({tags:["users"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({...Os.shape,password:o.z.string().optional()})}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:an}},description:"Status"}}}),async t=>{const e=t.req.valid("json");t.set("body",e);const{email:n,phone_number:r,name:i,linked_to:s,email_verified:a,provider:c,connection:l,password:d}=e,u=e.user_id,f=u?ns(u):La(),h=`${e.provider}|${f}`;try{const m={email:n,user_id:h,name:i||n||r,phone_number:r,provider:c,connection:l,linked_to:s??void 0,email_verified:a||!1,last_ip:"",is_social:!1,last_login:new Date().toISOString()},y=await t.env.data.users.create(t.var.tenant_id,m);if(d){const A={user_id:h,password:await ti.hash(d,10),algorithm:"bcrypt"};await t.env.data.passwords.create(t.var.tenant_id,A)}t.set("user_id",y.user_id);const v=be(t,{type:_e.SUCCESS_API_OPERATION,description:"User created"});ve(t,t.env.data.logs.create(t.var.tenant_id,v));const b=y.identities?y:{...y,identities:[{connection:y.connection,provider:y.provider,user_id:ns(y.user_id),isSocial:y.is_social}]};return t.json(an.parse(b),{status:201})}catch(m){throw m.message==="User already exists"?new S(409,{message:"User already exists"}):m}}).openapi(o.createRoute({tags:["users"],method:"patch",path:"/{user_id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({...Os.shape,verify_email:o.z.boolean(),password:o.z.string()}).partial()}}},params:o.z.object({user_id:o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{var m;const{data:e}=t.env,n=t.req.valid("json"),{user_id:r}=t.req.valid("param"),{verify_email:i,password:s,connection:a,...c}=n,l=await e.users.get(t.var.tenant_id,r);if(!l)throw new S(404);if(l.linked_to)throw new S(404,{message:"User is linked to another user"});let d=r,u=l;if(a)if(l.connection===a)d=r,u=l;else{const v=(await e.users.list(t.var.tenant_id,{page:0,per_page:100,include_totals:!1,q:`linked_to:${r}`})).users.find(b=>b.connection===a);if(!v)throw new S(404,{message:`No identity found with connection: ${a}`});d=v.user_id,u=v}if(c.email&&c.email!==u.email){const y=await Eu(t.env.data.users,t.var.tenant_id,c.email);if(y.length&&y.some(v=>v.user_id!==d))throw new S(409,{message:"Another user with the same email address already exists."})}if(await t.env.data.users.update(t.var.tenant_id,d,c),s){let y;if(a)if(a==="Username-Password-Authentication")y={provider:u.provider,user_id:ns(d)};else throw new S(400,{message:`Cannot set password for connection: ${a}`});else if(y=(m=l.identities)==null?void 0:m.find(A=>A.connection==="Username-Password-Authentication"),!y)throw new S(400,{message:"User does not have a password identity"});const v={user_id:`${y.provider}|${y.user_id}`,password:await ti.hash(s,10),algorithm:"bcrypt"};await e.passwords.get(t.var.tenant_id,`${y.provider}|${y.user_id}`)?await e.passwords.update(t.var.tenant_id,v):await e.passwords.create(t.var.tenant_id,v)}const f=await t.env.data.users.get(t.var.tenant_id,r);if(!f)throw new S(500);const h=be(t,{type:_e.SUCCESS_API_OPERATION,description:"Update a User",body:n});return h.details={...h.details,response:{statusCode:200,body:f}},ve(t,t.env.data.logs.create(t.var.tenant_id,h)),t.json(f)}).openapi(o.createRoute({tags:["users"],method:"post",path:"/{user_id}/identities",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.union([o.z.object({link_with:o.z.string()}),o.z.object({user_id:o.z.string(),provider:o.z.string(),connection:o.z.string().optional()})])}}},params:o.z.object({user_id:o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:o.z.array(o.z.object({connection:o.z.string(),provider:o.z.string(),user_id:o.z.string(),isSocial:o.z.boolean()}))}},description:"Status"}}}),async t=>{const e=t.req.valid("json"),{user_id:n}=t.req.valid("param"),r="link_with"in e?e.link_with:e.user_id,i=await t.env.data.users.get(t.var.tenant_id,n);if(!i)throw new S(400,{message:"Linking an inexistent identity is not allowed."});await t.env.data.users.update(t.var.tenant_id,r,{linked_to:n});const s=await t.env.data.users.list(t.var.tenant_id,{page:0,per_page:10,include_totals:!1,q:`linked_to:${n}`}),a=[i,...s.users].map(c=>({connection:c.connection,provider:c.provider,user_id:ns(c.user_id),isSocial:c.is_social}));return t.json(a,{status:201})}).openapi(o.createRoute({tags:["users"],method:"delete",path:"/{user_id}/identities/{provider}/{linked_user_id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({user_id:o.z.string(),provider:o.z.string(),linked_user_id:o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:o.z.array(an)}},description:"Status"}}}),async t=>{const{user_id:e,provider:n,linked_user_id:r}=t.req.valid("param");await t.env.data.users.unlink(t.var.tenant_id,e,n,r);const i=await t.env.data.users.get(t.var.tenant_id,e);if(!i)throw new S(404);return t.json([an.parse(i)])}).openapi(o.createRoute({tags:["users"],method:"get",path:"/{user_id}/sessions",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({user_id:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Ba),wb])}},description:"List of sessions"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{include_totals:n,page:r,per_page:i}=t.req.valid("query"),s=await t.env.data.sessions.list(t.var.tenant_id,{page:r,per_page:i,include_totals:n,q:`user_id:${e}`});return n?t.json(s):t.json(s.sessions)}).openapi(o.createRoute({tags:["users"],method:"get",path:"/{user_id}/permissions",request:{params:o.z.object({user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),query:Qe},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:am}},description:"User permissions"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{page:n,per_page:r,sort:i,q:s}=t.req.valid("query");if(!await t.env.data.users.get(t.var.tenant_id,e))throw new S(404,{message:"User not found"});const c=await t.env.data.userPermissions.list(t.var.tenant_id,e,{page:n,per_page:r,include_totals:!1,sort:ft(i),q:s});return t.json(c)}).openapi(o.createRoute({tags:["users"],method:"post",path:"/{user_id}/permissions",request:{params:o.z.object({user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({permissions:o.z.array(o.z.object({permission_name:o.z.string(),resource_server_identifier:o.z.string()}))})}}}},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Permissions assigned to user"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{permissions:n}=t.req.valid("json");if(!await t.env.data.users.get(t.var.tenant_id,e))throw new S(404,{message:"User not found"});for(const i of n)if(!await t.env.data.userPermissions.create(t.var.tenant_id,e,{user_id:e,resource_server_identifier:i.resource_server_identifier,permission_name:i.permission_name}))throw new S(500,{message:"Failed to assign permissions to user"});return t.json({message:"Permissions assigned successfully"},{status:201})}).openapi(o.createRoute({tags:["users"],method:"delete",path:"/{user_id}/permissions",request:{params:o.z.object({user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({permissions:o.z.array(o.z.object({permission_name:o.z.string(),resource_server_identifier:o.z.string()}))})}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Permissions removed from user"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{permissions:n}=t.req.valid("json");if(!await t.env.data.users.get(t.var.tenant_id,e))throw new S(404,{message:"User not found"});for(const i of n)if(!await t.env.data.userPermissions.remove(t.var.tenant_id,e,i))throw new S(500,{message:"Failed to remove permissions from user"});return t.json({message:"Permissions removed successfully"})}).openapi(o.createRoute({tags:["users"],method:"get",path:"/{user_id}/roles",request:{params:o.z.object({user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ms}},description:"User roles"}}}),async t=>{const{user_id:e}=t.req.valid("param");if(!await t.env.data.users.get(t.var.tenant_id,e))throw new S(404,{message:"User not found"});const r=await t.env.data.userRoles.list(t.var.tenant_id,e,void 0,"");return t.json(r)}).openapi(o.createRoute({tags:["users"],method:"post",path:"/{user_id}/roles",request:{params:o.z.object({user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({roles:o.z.array(o.z.string())})}}}},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Roles assigned to user"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{roles:n}=t.req.valid("json");if(!await t.env.data.users.get(t.var.tenant_id,e))throw new S(404,{message:"User not found"});for(const i of n)if(!await t.env.data.userRoles.create(t.var.tenant_id,e,i,""))throw new S(500,{message:"Failed to assign roles to user"});return t.json({message:"Roles assigned successfully"},{status:201})}).openapi(o.createRoute({tags:["users"],method:"delete",path:"/{user_id}/roles",request:{params:o.z.object({user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({roles:o.z.array(o.z.string())})}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Roles removed from user"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{roles:n}=t.req.valid("json");if(!await t.env.data.users.get(t.var.tenant_id,e))throw new S(404,{message:"User not found"});for(const i of n)if(!await t.env.data.userRoles.remove(t.var.tenant_id,e,i,""))throw new S(500,{message:"Failed to remove roles from user"});return t.json({message:"Roles removed successfully"})}).openapi(o.createRoute({tags:["users"],method:"get",path:"/{user_id}/organizations",request:{params:o.z.object({user_id:o.z.string()}),query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([vb,o.z.array(Dn)])}},description:"List of user organizations"}}}),async t=>{const{user_id:e}=t.req.valid("param"),{page:n,per_page:r,include_totals:i,sort:s}=t.req.valid("query");if(!await t.env.data.users.get(t.var.tenant_id,e))throw new S(404,{message:"User not found"});const c=await t.env.data.userOrganizations.listUserOrganizations(t.var.tenant_id,e,{page:n,per_page:r,sort:ft(s)});return i?t.json({organizations:c.organizations,start:c.start,limit:c.limit,length:c.length}):t.json(c.organizations)}).openapi(o.createRoute({tags:["users"],method:"delete",path:"/{user_id}/organizations/{organization_id}",request:{params:o.z.object({user_id:o.z.string(),organization_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"User removed from organization successfully"}}}),async t=>{const{user_id:e,organization_id:n}=t.req.valid("param");if(!await t.env.data.users.get(t.var.tenant_id,e))throw new S(404,{message:"User not found"});const s=(await t.env.data.userOrganizations.list(t.var.tenant_id,{q:`user_id:${e}`,per_page:100})).userOrganizations.find(a=>a.organization_id===n);if(!s)throw new S(404,{message:"User is not a member of this organization"});return await t.env.data.userOrganizations.remove(t.var.tenant_id,s.id),t.json({message:"User removed from organization successfully"})});/*! *****************************************************************************
73
73
  Copyright (C) Microsoft. All rights reserved.
74
74
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use
75
75
  this file except in compliance with the License. You may obtain a copy of the
@@ -105,7 +105,7 @@ and limitations under the License.
105
105
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
106
106
  * SOFTWARE.
107
107
  *
108
- */const $b="[object ArrayBuffer]";class G{static isArrayBuffer(e){return Object.prototype.toString.call(e)===$b}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,n){if(e.constructor===n)return e;if(this.isArrayBuffer(e))return new n(e);if(this.isArrayBufferView(e))return new n(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,n){const r=G.toUint8Array(e),i=G.toUint8Array(n);if(r.length!==i.byteLength)return!1;for(let s=0;s<r.length;s++)if(r[s]!==i[s])return!1;return!0}static concat(...e){let n;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?n=e[0]:e[e.length-1]instanceof Function?n=e.slice(0,e.length-1):n=e;let r=0;for(const a of n)r+=a.byteLength;const i=new Uint8Array(r);let s=0;for(const a of n){const c=this.toUint8Array(a);i.set(c,s),s+=c.length}return e[e.length-1]instanceof Function?this.toView(i,e[e.length-1]):i.buffer}}const Jc="string",kb=/^[0-9a-f\s]+$/i,xb=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Sb=/^[a-zA-Z0-9-_]+$/;class kf{static fromString(e){const n=unescape(encodeURIComponent(e)),r=new Uint8Array(n.length);for(let i=0;i<n.length;i++)r[i]=n.charCodeAt(i);return r.buffer}static toString(e){const n=G.toUint8Array(e);let r="";for(let s=0;s<n.length;s++)r+=String.fromCharCode(n[s]);return decodeURIComponent(escape(r))}}class sn{static toString(e,n=!1){const r=G.toArrayBuffer(e),i=new DataView(r);let s="";for(let a=0;a<r.byteLength;a+=2){const c=i.getUint16(a,n);s+=String.fromCharCode(c)}return s}static fromString(e,n=!1){const r=new ArrayBuffer(e.length*2),i=new DataView(r);for(let s=0;s<e.length;s++)i.setUint16(s*2,e.charCodeAt(s),n);return r}}class re{static isHex(e){return typeof e===Jc&&kb.test(e)}static isBase64(e){return typeof e===Jc&&xb.test(e)}static isBase64Url(e){return typeof e===Jc&&Sb.test(e)}static ToString(e,n="utf8"){const r=G.toUint8Array(e);switch(n.toLowerCase()){case"utf8":return this.ToUtf8String(r);case"binary":return this.ToBinary(r);case"hex":return this.ToHex(r);case"base64":return this.ToBase64(r);case"base64url":return this.ToBase64Url(r);case"utf16le":return sn.toString(r,!0);case"utf16":case"utf16be":return sn.toString(r);default:throw new Error(`Unknown type of encoding '${n}'`)}}static FromString(e,n="utf8"){if(!e)return new ArrayBuffer(0);switch(n.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return sn.fromString(e,!0);case"utf16":case"utf16be":return sn.fromString(e);default:throw new Error(`Unknown type of encoding '${n}'`)}}static ToBase64(e){const n=G.toUint8Array(e);if(typeof btoa<"u"){const r=this.ToString(n,"binary");return btoa(r)}else return Buffer.from(n).toString("base64")}static FromBase64(e){const n=this.formatString(e);if(!n)return new ArrayBuffer(0);if(!re.isBase64(n))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(n)):new Uint8Array(Buffer.from(n,"base64")).buffer}static FromBase64Url(e){const n=this.formatString(e);if(!n)return new ArrayBuffer(0);if(!re.isBase64Url(n))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(n.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,n=re.DEFAULT_UTF8_ENCODING){switch(n){case"ascii":return this.FromBinary(e);case"utf8":return kf.fromString(e);case"utf16":case"utf16be":return sn.fromString(e);case"utf16le":case"usc2":return sn.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${n}'`)}}static ToUtf8String(e,n=re.DEFAULT_UTF8_ENCODING){switch(n){case"ascii":return this.ToBinary(e);case"utf8":return kf.toString(e);case"utf16":case"utf16be":return sn.toString(e);case"utf16le":case"usc2":return sn.toString(e,!0);default:throw new Error(`Unknown type of encoding '${n}'`)}}static FromBinary(e){const n=e.length,r=new Uint8Array(n);for(let i=0;i<n;i++)r[i]=e.charCodeAt(i);return r.buffer}static ToBinary(e){const n=G.toUint8Array(e);let r="";for(let i=0;i<n.length;i++)r+=String.fromCharCode(n[i]);return r}static ToHex(e){const n=G.toUint8Array(e);let r="";const i=n.length;for(let s=0;s<i;s++){const a=n[s];a<16&&(r+="0"),r+=a.toString(16)}return r}static FromHex(e){let n=this.formatString(e);if(!n)return new ArrayBuffer(0);if(!re.isHex(n))throw new TypeError("Argument 'hexString' is not HEX encoded");n.length%2&&(n=`0${n}`);const r=new Uint8Array(n.length/2);for(let i=0;i<n.length;i=i+2){const s=n.slice(i,i+2);r[i/2]=parseInt(s,16)}return r.buffer}static ToUtf16String(e,n=!1){return sn.toString(e,n)}static FromUtf16String(e,n=!1){return sn.fromString(e,n)}static Base64Padding(e){const n=4-e.length%4;if(n<4)for(let r=0;r<n;r++)e+="=";return e}static formatString(e){return(e==null?void 0:e.replace(/[\n\r\t ]/g,""))||""}}re.DEFAULT_UTF8_ENCODING="utf8";function zb(...t){const e=t.map(i=>i.byteLength).reduce((i,s)=>i+s),n=new Uint8Array(e);let r=0;return t.map(i=>new Uint8Array(i)).forEach(i=>{for(const s of i)n[r++]=s}),n.buffer}function Dm(t,e){if(!(t&&e)||t.byteLength!==e.byteLength)return!1;const n=new Uint8Array(t),r=new Uint8Array(e);for(let i=0;i<t.byteLength;i++)if(n[i]!==r[i])return!1;return!0}/*!
108
+ */const $b="[object ArrayBuffer]";class G{static isArrayBuffer(e){return Object.prototype.toString.call(e)===$b}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,n){if(e.constructor===n)return e;if(this.isArrayBuffer(e))return new n(e);if(this.isArrayBufferView(e))return new n(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,n){const r=G.toUint8Array(e),i=G.toUint8Array(n);if(r.length!==i.byteLength)return!1;for(let s=0;s<r.length;s++)if(r[s]!==i[s])return!1;return!0}static concat(...e){let n;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?n=e[0]:e[e.length-1]instanceof Function?n=e.slice(0,e.length-1):n=e;let r=0;for(const a of n)r+=a.byteLength;const i=new Uint8Array(r);let s=0;for(const a of n){const c=this.toUint8Array(a);i.set(c,s),s+=c.length}return e[e.length-1]instanceof Function?this.toView(i,e[e.length-1]):i.buffer}}const Jc="string",kb=/^[0-9a-f\s]+$/i,xb=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Sb=/^[a-zA-Z0-9-_]+$/;class kf{static fromString(e){const n=unescape(encodeURIComponent(e)),r=new Uint8Array(n.length);for(let i=0;i<n.length;i++)r[i]=n.charCodeAt(i);return r.buffer}static toString(e){const n=G.toUint8Array(e);let r="";for(let s=0;s<n.length;s++)r+=String.fromCharCode(n[s]);return decodeURIComponent(escape(r))}}class on{static toString(e,n=!1){const r=G.toArrayBuffer(e),i=new DataView(r);let s="";for(let a=0;a<r.byteLength;a+=2){const c=i.getUint16(a,n);s+=String.fromCharCode(c)}return s}static fromString(e,n=!1){const r=new ArrayBuffer(e.length*2),i=new DataView(r);for(let s=0;s<e.length;s++)i.setUint16(s*2,e.charCodeAt(s),n);return r}}class re{static isHex(e){return typeof e===Jc&&kb.test(e)}static isBase64(e){return typeof e===Jc&&xb.test(e)}static isBase64Url(e){return typeof e===Jc&&Sb.test(e)}static ToString(e,n="utf8"){const r=G.toUint8Array(e);switch(n.toLowerCase()){case"utf8":return this.ToUtf8String(r);case"binary":return this.ToBinary(r);case"hex":return this.ToHex(r);case"base64":return this.ToBase64(r);case"base64url":return this.ToBase64Url(r);case"utf16le":return on.toString(r,!0);case"utf16":case"utf16be":return on.toString(r);default:throw new Error(`Unknown type of encoding '${n}'`)}}static FromString(e,n="utf8"){if(!e)return new ArrayBuffer(0);switch(n.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return on.fromString(e,!0);case"utf16":case"utf16be":return on.fromString(e);default:throw new Error(`Unknown type of encoding '${n}'`)}}static ToBase64(e){const n=G.toUint8Array(e);if(typeof btoa<"u"){const r=this.ToString(n,"binary");return btoa(r)}else return Buffer.from(n).toString("base64")}static FromBase64(e){const n=this.formatString(e);if(!n)return new ArrayBuffer(0);if(!re.isBase64(n))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(n)):new Uint8Array(Buffer.from(n,"base64")).buffer}static FromBase64Url(e){const n=this.formatString(e);if(!n)return new ArrayBuffer(0);if(!re.isBase64Url(n))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(n.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,n=re.DEFAULT_UTF8_ENCODING){switch(n){case"ascii":return this.FromBinary(e);case"utf8":return kf.fromString(e);case"utf16":case"utf16be":return on.fromString(e);case"utf16le":case"usc2":return on.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${n}'`)}}static ToUtf8String(e,n=re.DEFAULT_UTF8_ENCODING){switch(n){case"ascii":return this.ToBinary(e);case"utf8":return kf.toString(e);case"utf16":case"utf16be":return on.toString(e);case"utf16le":case"usc2":return on.toString(e,!0);default:throw new Error(`Unknown type of encoding '${n}'`)}}static FromBinary(e){const n=e.length,r=new Uint8Array(n);for(let i=0;i<n;i++)r[i]=e.charCodeAt(i);return r.buffer}static ToBinary(e){const n=G.toUint8Array(e);let r="";for(let i=0;i<n.length;i++)r+=String.fromCharCode(n[i]);return r}static ToHex(e){const n=G.toUint8Array(e);let r="";const i=n.length;for(let s=0;s<i;s++){const a=n[s];a<16&&(r+="0"),r+=a.toString(16)}return r}static FromHex(e){let n=this.formatString(e);if(!n)return new ArrayBuffer(0);if(!re.isHex(n))throw new TypeError("Argument 'hexString' is not HEX encoded");n.length%2&&(n=`0${n}`);const r=new Uint8Array(n.length/2);for(let i=0;i<n.length;i=i+2){const s=n.slice(i,i+2);r[i/2]=parseInt(s,16)}return r.buffer}static ToUtf16String(e,n=!1){return on.toString(e,n)}static FromUtf16String(e,n=!1){return on.fromString(e,n)}static Base64Padding(e){const n=4-e.length%4;if(n<4)for(let r=0;r<n;r++)e+="=";return e}static formatString(e){return(e==null?void 0:e.replace(/[\n\r\t ]/g,""))||""}}re.DEFAULT_UTF8_ENCODING="utf8";function zb(...t){const e=t.map(i=>i.byteLength).reduce((i,s)=>i+s),n=new Uint8Array(e);let r=0;return t.map(i=>new Uint8Array(i)).forEach(i=>{for(const s of i)n[r++]=s}),n.buffer}function Dm(t,e){if(!(t&&e)||t.byteLength!==e.byteLength)return!1;const n=new Uint8Array(t),r=new Uint8Array(e);for(let i=0;i<t.byteLength;i++)if(n[i]!==r[i])return!1;return!0}/*!
109
109
  Copyright (c) Peculiar Ventures, LLC
110
110
  */function ii(t,e){let n=0;if(t.length===1)return t[0];for(let r=t.length-1;r>=0;r--)n+=t[t.length-1-r]*Math.pow(2,e*r);return n}function yr(t,e,n=-1){const r=n;let i=t,s=0,a=Math.pow(2,e);for(let c=1;c<8;c++){if(t<a){let l;if(r<0)l=new ArrayBuffer(c),s=c;else{if(r<c)return new ArrayBuffer(0);l=new ArrayBuffer(r),s=r}const d=new Uint8Array(l);for(let u=c-1;u>=0;u--){const f=Math.pow(2,u*e);d[s-u-1]=Math.floor(i/f),i-=d[s-u-1]*f}return l}a*=Math.pow(2,e)}return new ArrayBuffer(0)}function Ol(...t){let e=0,n=0;for(const s of t)e+=s.length;const r=new ArrayBuffer(e),i=new Uint8Array(r);for(const s of t)i.set(s,n),n+=s.length;return i}function Mm(){const t=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){const c=t[0]===255&&t[1]&128,l=t[0]===0&&(t[1]&128)===0;(c||l)&&this.warnings.push("Needlessly long format")}const e=new ArrayBuffer(this.valueHex.byteLength),n=new Uint8Array(e);for(let c=0;c<this.valueHex.byteLength;c++)n[c]=0;n[0]=t[0]&128;const r=ii(n,8),i=new ArrayBuffer(this.valueHex.byteLength),s=new Uint8Array(i);for(let c=0;c<this.valueHex.byteLength;c++)s[c]=t[c];return s[0]&=127,ii(s,8)-r}function Ab(t){const e=t<0?t*-1:t;let n=128;for(let r=1;r<8;r++){if(e<=n){if(t<0){const a=n-e,c=yr(a,8,r),l=new Uint8Array(c);return l[0]|=128,c}let i=yr(e,8,r),s=new Uint8Array(i);if(s[0]&128){const a=i.slice(0),c=new Uint8Array(a);i=new ArrayBuffer(i.byteLength+1),s=new Uint8Array(i);for(let l=0;l<a.byteLength;l++)s[l+1]=c[l];s[0]=0}return i}n*=Math.pow(2,8)}return new ArrayBuffer(0)}function Eb(t,e){if(t.byteLength!==e.byteLength)return!1;const n=new Uint8Array(t),r=new Uint8Array(e);for(let i=0;i<n.length;i++)if(n[i]!==r[i])return!1;return!0}function Et(t,e){const n=t.toString(10);if(e<n.length)return"";const r=e-n.length,i=new Array(r);for(let a=0;a<r;a++)i[a]="0";return i.join("").concat(n)}/*!
111
111
  * Copyright (c) 2014, GMO GlobalSign
@@ -139,11 +139,11 @@ and limitations under the License.
139
139
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
140
140
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
141
141
  *
142
- */function Ks(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Nu(t){let e=0,n=0;for(let i=0;i<t.length;i++){const s=t[i];e+=s.byteLength}const r=new Uint8Array(e);for(let i=0;i<t.length;i++){const s=t[i];r.set(new Uint8Array(s),n),n+=s.byteLength}return r.buffer}function jn(t,e,n,r){return e instanceof Uint8Array?e.byteLength?n<0?(t.error="Wrong parameter: inputOffset less than zero",!1):r<0?(t.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-n-r<0?(t.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(t.error="Wrong parameter: inputBuffer has zero length",!1):(t.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}class Ha{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Nu(this.items)}}const Li=[new Uint8Array([1])],xf="0123456789",Xc="name",Sf="valueHexView",Cb="isHexOnly",Nb="idBlock",Ib="tagClass",jb="tagNumber",Ob="isConstructed",Tb="fromBER",Pb="toBER",Rb="local",kt="",tn=new ArrayBuffer(0),Va=new Uint8Array(0),oo="EndOfContent",Fm="OCTET STRING",qm="BIT STRING";function hn(t){var e;return e=class extends t{get valueHex(){return this.valueHexView.slice().buffer}set valueHex(r){this.valueHexView=new Uint8Array(r)}constructor(...r){var i;super(...r);const s=r[0]||{};this.isHexOnly=(i=s.isHexOnly)!==null&&i!==void 0?i:!1,this.valueHexView=s.valueHex?G.toUint8Array(s.valueHex):Va}fromBER(r,i,s){const a=r instanceof ArrayBuffer?new Uint8Array(r):r;if(!jn(this,a,i,s))return-1;const c=i+s;return this.valueHexView=a.subarray(i,c),this.valueHexView.length?(this.blockLength=s,c):(this.warnings.push("Zero buffer length"),i)}toBER(r=!1){return this.isHexOnly?r?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",tn)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:re.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}class Or{static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}constructor({blockLength:e=0,error:n=kt,warnings:r=[],valueBeforeDecode:i=Va}={}){this.blockLength=e,this.error=n,this.warnings=r,this.valueBeforeDecodeView=G.toUint8Array(i)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:re.ToHex(this.valueBeforeDecodeView)}}}Or.NAME="baseBlock";class wt extends Or{fromBER(e,n,r){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}}wt.NAME="valueBlock";class Hm extends hn(Or){constructor({idBlock:e={}}={}){var n,r,i,s;super(),e?(this.isHexOnly=(n=e.isHexOnly)!==null&&n!==void 0?n:!1,this.valueHexView=e.valueHex?G.toUint8Array(e.valueHex):Va,this.tagClass=(r=e.tagClass)!==null&&r!==void 0?r:-1,this.tagNumber=(i=e.tagNumber)!==null&&i!==void 0?i:-1,this.isConstructed=(s=e.isConstructed)!==null&&s!==void 0?s:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let n=0;switch(this.tagClass){case 1:n|=0;break;case 2:n|=64;break;case 3:n|=128;break;case 4:n|=192;break;default:return this.error="Unknown tag class",tn}if(this.isConstructed&&(n|=32),this.tagNumber<31&&!this.isHexOnly){const i=new Uint8Array(1);if(!e){let s=this.tagNumber;s&=31,n|=s,i[0]=n}return i.buffer}if(!this.isHexOnly){const i=yr(this.tagNumber,7),s=new Uint8Array(i),a=i.byteLength,c=new Uint8Array(a+1);if(c[0]=n|31,!e){for(let l=0;l<a-1;l++)c[l+1]=s[l]|128;c[a]=s[a-1]}return c.buffer}const r=new Uint8Array(this.valueHexView.byteLength+1);if(r[0]=n|31,!e){const i=this.valueHexView;for(let s=0;s<i.length-1;s++)r[s+1]=i[s]|128;r[this.valueHexView.byteLength]=i[i.length-1]}return r.buffer}fromBER(e,n,r){const i=G.toUint8Array(e);if(!jn(this,i,n,r))return-1;const s=i.subarray(n,n+r);if(s.length===0)return this.error="Zero buffer length",-1;switch(s[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(s[0]&32)===32,this.isHexOnly=!1;const c=s[0]&31;if(c!==31)this.tagNumber=c,this.blockLength=1;else{let l=1,d=this.valueHexView=new Uint8Array(255),u=255;for(;s[l]&128;){if(d[l-1]=s[l]&127,l++,l>=s.length)return this.error="End of input reached before message was fully decoded",-1;if(l===u){u+=255;const h=new Uint8Array(u);for(let m=0;m<d.length;m++)h[m]=d[m];d=this.valueHexView=new Uint8Array(u)}}this.blockLength=l+1,d[l-1]=s[l]&127;const f=new Uint8Array(l);for(let h=0;h<l;h++)f[h]=d[h];d=this.valueHexView=new Uint8Array(l),d.set(f),this.blockLength<=9?this.tagNumber=ii(d,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return n+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}}Hm.NAME="identificationBlock";class Vm extends Or{constructor({lenBlock:e={}}={}){var n,r,i;super(),this.isIndefiniteForm=(n=e.isIndefiniteForm)!==null&&n!==void 0?n:!1,this.longFormUsed=(r=e.longFormUsed)!==null&&r!==void 0?r:!1,this.length=(i=e.length)!==null&&i!==void 0?i:0}fromBER(e,n,r){const i=G.toUint8Array(e);if(!jn(this,i,n,r))return-1;const s=i.subarray(n,n+r);if(s.length===0)return this.error="Zero buffer length",-1;if(s[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=s[0]===128,this.isIndefiniteForm)return this.blockLength=1,n+this.blockLength;if(this.longFormUsed=!!(s[0]&128),this.longFormUsed===!1)return this.length=s[0],this.blockLength=1,n+this.blockLength;const a=s[0]&127;if(a>8)return this.error="Too big integer",-1;if(a+1>s.length)return this.error="End of input reached before message was fully decoded",-1;const c=n+1,l=i.subarray(c,c+a);return l[a-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=ii(l,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=a+1,n+this.blockLength}toBER(e=!1){let n,r;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return n=new ArrayBuffer(1),e===!1&&(r=new Uint8Array(n),r[0]=128),n;if(this.longFormUsed){const i=yr(this.length,8);if(i.byteLength>127)return this.error="Too big length",tn;if(n=new ArrayBuffer(i.byteLength+1),e)return n;const s=new Uint8Array(i);r=new Uint8Array(n),r[0]=i.byteLength|128;for(let a=0;a<i.byteLength;a++)r[a+1]=s[a];return n}return n=new ArrayBuffer(1),e===!1&&(r=new Uint8Array(n),r[0]=this.length),n}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}}Vm.NAME="lengthBlock";const Y={};class at extends Or{constructor({name:e=kt,optional:n=!1,primitiveSchema:r,...i}={},s){super(i),this.name=e,this.optional=n,r&&(this.primitiveSchema=r),this.idBlock=new Hm(i),this.lenBlock=new Vm(i),this.valueBlock=s?new s(i):new wt(i)}fromBER(e,n,r){const i=this.valueBlock.fromBER(e,n,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}toBER(e,n){const r=n||new Ha;n||Km(this);const i=this.idBlock.toBER(e);if(r.write(i),this.lenBlock.isIndefiniteForm)r.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,r),r.write(new ArrayBuffer(2));else{const s=this.valueBlock.toBER(e);this.lenBlock.length=s.byteLength;const a=this.lenBlock.toBER(e);r.write(a),r.write(s)}return n?tn:r.final()}toJSON(){const e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():re.ToHex(this.toBER())}onAsciiEncoding(){const e=this.constructor.NAME,n=re.ToHex(this.valueBlock.valueBeforeDecodeView);return`${e} : ${n}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;const n=this.toBER(),r=e.toBER();return Eb(n,r)}}at.NAME="BaseBlock";function Km(t){var e;if(t instanceof Y.Constructed)for(const n of t.valueBlock.value)Km(n)&&(t.lenBlock.isIndefiniteForm=!0);return!!(!((e=t.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}class Iu extends at{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=kt,...n}={},r){super(n,r),e&&this.fromString(e)}fromBER(e,n,r){const i=this.valueBlock.fromBER(e,n,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}}Iu.NAME="BaseStringBlock";class Gm extends hn(wt){constructor({isHexOnly:e=!0,...n}={}){super(n),this.isHexOnly=e}}Gm.NAME="PrimitiveValueBlock";var Wm;class So extends at{constructor(e={}){super(e,Gm),this.idBlock.isConstructed=!1}}Wm=So;Y.Primitive=Wm;So.NAME="PRIMITIVE";function Bb(t,e){if(t instanceof e)return t;const n=new e;return n.idBlock=t.idBlock,n.lenBlock=t.lenBlock,n.warnings=t.warnings,n.valueBeforeDecodeView=t.valueBeforeDecodeView,n}function bi(t,e=0,n=t.length){const r=e;let i=new at({},wt);const s=new Or;if(!jn(s,t,e,n))return i.error=s.error,{offset:-1,result:i};if(!t.subarray(e,e+n).length)return i.error="Zero buffer length",{offset:-1,result:i};let c=i.idBlock.fromBER(t,e,n);if(i.idBlock.warnings.length&&i.warnings.concat(i.idBlock.warnings),c===-1)return i.error=i.idBlock.error,{offset:-1,result:i};if(e=c,n-=i.idBlock.blockLength,c=i.lenBlock.fromBER(t,e,n),i.lenBlock.warnings.length&&i.warnings.concat(i.lenBlock.warnings),c===-1)return i.error=i.lenBlock.error,{offset:-1,result:i};if(e=c,n-=i.lenBlock.blockLength,!i.idBlock.isConstructed&&i.lenBlock.isIndefiniteForm)return i.error="Indefinite length form used for primitive encoding form",{offset:-1,result:i};let l=at;switch(i.idBlock.tagClass){case 1:if(i.idBlock.tagNumber>=37&&i.idBlock.isHexOnly===!1)return i.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:i};switch(i.idBlock.tagNumber){case 0:if(i.idBlock.isConstructed&&i.lenBlock.length>0)return i.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:i};l=Y.EndOfContent;break;case 1:l=Y.Boolean;break;case 2:l=Y.Integer;break;case 3:l=Y.BitString;break;case 4:l=Y.OctetString;break;case 5:l=Y.Null;break;case 6:l=Y.ObjectIdentifier;break;case 10:l=Y.Enumerated;break;case 12:l=Y.Utf8String;break;case 13:l=Y.RelativeObjectIdentifier;break;case 14:l=Y.TIME;break;case 15:return i.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:i};case 16:l=Y.Sequence;break;case 17:l=Y.Set;break;case 18:l=Y.NumericString;break;case 19:l=Y.PrintableString;break;case 20:l=Y.TeletexString;break;case 21:l=Y.VideotexString;break;case 22:l=Y.IA5String;break;case 23:l=Y.UTCTime;break;case 24:l=Y.GeneralizedTime;break;case 25:l=Y.GraphicString;break;case 26:l=Y.VisibleString;break;case 27:l=Y.GeneralString;break;case 28:l=Y.UniversalString;break;case 29:l=Y.CharacterString;break;case 30:l=Y.BmpString;break;case 31:l=Y.DATE;break;case 32:l=Y.TimeOfDay;break;case 33:l=Y.DateTime;break;case 34:l=Y.Duration;break;default:{const d=i.idBlock.isConstructed?new Y.Constructed:new Y.Primitive;d.idBlock=i.idBlock,d.lenBlock=i.lenBlock,d.warnings=i.warnings,i=d}}break;case 2:case 3:case 4:default:l=i.idBlock.isConstructed?Y.Constructed:Y.Primitive}return i=Bb(i,l),c=i.fromBER(t,e,i.lenBlock.isIndefiniteForm?n:i.lenBlock.length),i.valueBeforeDecodeView=t.subarray(r,r+i.blockLength),{offset:c,result:i}}function Xr(t){if(!t.byteLength){const e=new at({},wt);return e.error="Input buffer has zero length",{offset:-1,result:e}}return bi(G.toUint8Array(t).slice(),0,t.byteLength)}function Lb(t,e){return t?1:e}class Hn extends wt{constructor({value:e=[],isIndefiniteForm:n=!1,...r}={}){super(r),this.value=e,this.isIndefiniteForm=n}fromBER(e,n,r){const i=G.toUint8Array(e);if(!jn(this,i,n,r))return-1;if(this.valueBeforeDecodeView=i.subarray(n,n+r),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),n;let s=n;for(;Lb(this.isIndefiniteForm,r)>0;){const a=bi(i,s,r);if(a.offset===-1)return this.error=a.result.error,this.warnings.concat(a.result.warnings),-1;if(s=a.offset,this.blockLength+=a.result.blockLength,r-=a.result.blockLength,this.value.push(a.result),this.isIndefiniteForm&&a.result.constructor.NAME===oo)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===oo?this.value.pop():this.warnings.push("No EndOfContent block encoded")),s}toBER(e,n){const r=n||new Ha;for(let i=0;i<this.value.length;i++)this.value[i].toBER(e,r);return n?tn:r.final()}toJSON(){const e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(const n of this.value)e.value.push(n.toJSON());return e}}Hn.NAME="ConstructedValueBlock";var Jm;class yt extends at{constructor(e={}){super(e,Hn),this.idBlock.isConstructed=!0}fromBER(e,n,r){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;const i=this.valueBlock.fromBER(e,n,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}onAsciiEncoding(){const e=[];for(const r of this.valueBlock.value)e.push(r.toString("ascii").split(`
142
+ */function Ks(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Nu(t){let e=0,n=0;for(let i=0;i<t.length;i++){const s=t[i];e+=s.byteLength}const r=new Uint8Array(e);for(let i=0;i<t.length;i++){const s=t[i];r.set(new Uint8Array(s),n),n+=s.byteLength}return r.buffer}function jn(t,e,n,r){return e instanceof Uint8Array?e.byteLength?n<0?(t.error="Wrong parameter: inputOffset less than zero",!1):r<0?(t.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-n-r<0?(t.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(t.error="Wrong parameter: inputBuffer has zero length",!1):(t.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}class Ha{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Nu(this.items)}}const Li=[new Uint8Array([1])],xf="0123456789",Xc="name",Sf="valueHexView",Cb="isHexOnly",Nb="idBlock",Ib="tagClass",jb="tagNumber",Ob="isConstructed",Tb="fromBER",Pb="toBER",Rb="local",kt="",en=new ArrayBuffer(0),Va=new Uint8Array(0),oo="EndOfContent",Fm="OCTET STRING",qm="BIT STRING";function hn(t){var e;return e=class extends t{get valueHex(){return this.valueHexView.slice().buffer}set valueHex(r){this.valueHexView=new Uint8Array(r)}constructor(...r){var i;super(...r);const s=r[0]||{};this.isHexOnly=(i=s.isHexOnly)!==null&&i!==void 0?i:!1,this.valueHexView=s.valueHex?G.toUint8Array(s.valueHex):Va}fromBER(r,i,s){const a=r instanceof ArrayBuffer?new Uint8Array(r):r;if(!jn(this,a,i,s))return-1;const c=i+s;return this.valueHexView=a.subarray(i,c),this.valueHexView.length?(this.blockLength=s,c):(this.warnings.push("Zero buffer length"),i)}toBER(r=!1){return this.isHexOnly?r?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",en)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:re.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}class Or{static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}constructor({blockLength:e=0,error:n=kt,warnings:r=[],valueBeforeDecode:i=Va}={}){this.blockLength=e,this.error=n,this.warnings=r,this.valueBeforeDecodeView=G.toUint8Array(i)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:re.ToHex(this.valueBeforeDecodeView)}}}Or.NAME="baseBlock";class wt extends Or{fromBER(e,n,r){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}}wt.NAME="valueBlock";class Hm extends hn(Or){constructor({idBlock:e={}}={}){var n,r,i,s;super(),e?(this.isHexOnly=(n=e.isHexOnly)!==null&&n!==void 0?n:!1,this.valueHexView=e.valueHex?G.toUint8Array(e.valueHex):Va,this.tagClass=(r=e.tagClass)!==null&&r!==void 0?r:-1,this.tagNumber=(i=e.tagNumber)!==null&&i!==void 0?i:-1,this.isConstructed=(s=e.isConstructed)!==null&&s!==void 0?s:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let n=0;switch(this.tagClass){case 1:n|=0;break;case 2:n|=64;break;case 3:n|=128;break;case 4:n|=192;break;default:return this.error="Unknown tag class",en}if(this.isConstructed&&(n|=32),this.tagNumber<31&&!this.isHexOnly){const i=new Uint8Array(1);if(!e){let s=this.tagNumber;s&=31,n|=s,i[0]=n}return i.buffer}if(!this.isHexOnly){const i=yr(this.tagNumber,7),s=new Uint8Array(i),a=i.byteLength,c=new Uint8Array(a+1);if(c[0]=n|31,!e){for(let l=0;l<a-1;l++)c[l+1]=s[l]|128;c[a]=s[a-1]}return c.buffer}const r=new Uint8Array(this.valueHexView.byteLength+1);if(r[0]=n|31,!e){const i=this.valueHexView;for(let s=0;s<i.length-1;s++)r[s+1]=i[s]|128;r[this.valueHexView.byteLength]=i[i.length-1]}return r.buffer}fromBER(e,n,r){const i=G.toUint8Array(e);if(!jn(this,i,n,r))return-1;const s=i.subarray(n,n+r);if(s.length===0)return this.error="Zero buffer length",-1;switch(s[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(s[0]&32)===32,this.isHexOnly=!1;const c=s[0]&31;if(c!==31)this.tagNumber=c,this.blockLength=1;else{let l=1,d=this.valueHexView=new Uint8Array(255),u=255;for(;s[l]&128;){if(d[l-1]=s[l]&127,l++,l>=s.length)return this.error="End of input reached before message was fully decoded",-1;if(l===u){u+=255;const h=new Uint8Array(u);for(let m=0;m<d.length;m++)h[m]=d[m];d=this.valueHexView=new Uint8Array(u)}}this.blockLength=l+1,d[l-1]=s[l]&127;const f=new Uint8Array(l);for(let h=0;h<l;h++)f[h]=d[h];d=this.valueHexView=new Uint8Array(l),d.set(f),this.blockLength<=9?this.tagNumber=ii(d,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return n+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}}Hm.NAME="identificationBlock";class Vm extends Or{constructor({lenBlock:e={}}={}){var n,r,i;super(),this.isIndefiniteForm=(n=e.isIndefiniteForm)!==null&&n!==void 0?n:!1,this.longFormUsed=(r=e.longFormUsed)!==null&&r!==void 0?r:!1,this.length=(i=e.length)!==null&&i!==void 0?i:0}fromBER(e,n,r){const i=G.toUint8Array(e);if(!jn(this,i,n,r))return-1;const s=i.subarray(n,n+r);if(s.length===0)return this.error="Zero buffer length",-1;if(s[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=s[0]===128,this.isIndefiniteForm)return this.blockLength=1,n+this.blockLength;if(this.longFormUsed=!!(s[0]&128),this.longFormUsed===!1)return this.length=s[0],this.blockLength=1,n+this.blockLength;const a=s[0]&127;if(a>8)return this.error="Too big integer",-1;if(a+1>s.length)return this.error="End of input reached before message was fully decoded",-1;const c=n+1,l=i.subarray(c,c+a);return l[a-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=ii(l,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=a+1,n+this.blockLength}toBER(e=!1){let n,r;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return n=new ArrayBuffer(1),e===!1&&(r=new Uint8Array(n),r[0]=128),n;if(this.longFormUsed){const i=yr(this.length,8);if(i.byteLength>127)return this.error="Too big length",en;if(n=new ArrayBuffer(i.byteLength+1),e)return n;const s=new Uint8Array(i);r=new Uint8Array(n),r[0]=i.byteLength|128;for(let a=0;a<i.byteLength;a++)r[a+1]=s[a];return n}return n=new ArrayBuffer(1),e===!1&&(r=new Uint8Array(n),r[0]=this.length),n}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}}Vm.NAME="lengthBlock";const Y={};class at extends Or{constructor({name:e=kt,optional:n=!1,primitiveSchema:r,...i}={},s){super(i),this.name=e,this.optional=n,r&&(this.primitiveSchema=r),this.idBlock=new Hm(i),this.lenBlock=new Vm(i),this.valueBlock=s?new s(i):new wt(i)}fromBER(e,n,r){const i=this.valueBlock.fromBER(e,n,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}toBER(e,n){const r=n||new Ha;n||Km(this);const i=this.idBlock.toBER(e);if(r.write(i),this.lenBlock.isIndefiniteForm)r.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,r),r.write(new ArrayBuffer(2));else{const s=this.valueBlock.toBER(e);this.lenBlock.length=s.byteLength;const a=this.lenBlock.toBER(e);r.write(a),r.write(s)}return n?en:r.final()}toJSON(){const e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():re.ToHex(this.toBER())}onAsciiEncoding(){const e=this.constructor.NAME,n=re.ToHex(this.valueBlock.valueBeforeDecodeView);return`${e} : ${n}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;const n=this.toBER(),r=e.toBER();return Eb(n,r)}}at.NAME="BaseBlock";function Km(t){var e;if(t instanceof Y.Constructed)for(const n of t.valueBlock.value)Km(n)&&(t.lenBlock.isIndefiniteForm=!0);return!!(!((e=t.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}class Iu extends at{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=kt,...n}={},r){super(n,r),e&&this.fromString(e)}fromBER(e,n,r){const i=this.valueBlock.fromBER(e,n,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}}Iu.NAME="BaseStringBlock";class Gm extends hn(wt){constructor({isHexOnly:e=!0,...n}={}){super(n),this.isHexOnly=e}}Gm.NAME="PrimitiveValueBlock";var Wm;class So extends at{constructor(e={}){super(e,Gm),this.idBlock.isConstructed=!1}}Wm=So;Y.Primitive=Wm;So.NAME="PRIMITIVE";function Bb(t,e){if(t instanceof e)return t;const n=new e;return n.idBlock=t.idBlock,n.lenBlock=t.lenBlock,n.warnings=t.warnings,n.valueBeforeDecodeView=t.valueBeforeDecodeView,n}function bi(t,e=0,n=t.length){const r=e;let i=new at({},wt);const s=new Or;if(!jn(s,t,e,n))return i.error=s.error,{offset:-1,result:i};if(!t.subarray(e,e+n).length)return i.error="Zero buffer length",{offset:-1,result:i};let c=i.idBlock.fromBER(t,e,n);if(i.idBlock.warnings.length&&i.warnings.concat(i.idBlock.warnings),c===-1)return i.error=i.idBlock.error,{offset:-1,result:i};if(e=c,n-=i.idBlock.blockLength,c=i.lenBlock.fromBER(t,e,n),i.lenBlock.warnings.length&&i.warnings.concat(i.lenBlock.warnings),c===-1)return i.error=i.lenBlock.error,{offset:-1,result:i};if(e=c,n-=i.lenBlock.blockLength,!i.idBlock.isConstructed&&i.lenBlock.isIndefiniteForm)return i.error="Indefinite length form used for primitive encoding form",{offset:-1,result:i};let l=at;switch(i.idBlock.tagClass){case 1:if(i.idBlock.tagNumber>=37&&i.idBlock.isHexOnly===!1)return i.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:i};switch(i.idBlock.tagNumber){case 0:if(i.idBlock.isConstructed&&i.lenBlock.length>0)return i.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:i};l=Y.EndOfContent;break;case 1:l=Y.Boolean;break;case 2:l=Y.Integer;break;case 3:l=Y.BitString;break;case 4:l=Y.OctetString;break;case 5:l=Y.Null;break;case 6:l=Y.ObjectIdentifier;break;case 10:l=Y.Enumerated;break;case 12:l=Y.Utf8String;break;case 13:l=Y.RelativeObjectIdentifier;break;case 14:l=Y.TIME;break;case 15:return i.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:i};case 16:l=Y.Sequence;break;case 17:l=Y.Set;break;case 18:l=Y.NumericString;break;case 19:l=Y.PrintableString;break;case 20:l=Y.TeletexString;break;case 21:l=Y.VideotexString;break;case 22:l=Y.IA5String;break;case 23:l=Y.UTCTime;break;case 24:l=Y.GeneralizedTime;break;case 25:l=Y.GraphicString;break;case 26:l=Y.VisibleString;break;case 27:l=Y.GeneralString;break;case 28:l=Y.UniversalString;break;case 29:l=Y.CharacterString;break;case 30:l=Y.BmpString;break;case 31:l=Y.DATE;break;case 32:l=Y.TimeOfDay;break;case 33:l=Y.DateTime;break;case 34:l=Y.Duration;break;default:{const d=i.idBlock.isConstructed?new Y.Constructed:new Y.Primitive;d.idBlock=i.idBlock,d.lenBlock=i.lenBlock,d.warnings=i.warnings,i=d}}break;case 2:case 3:case 4:default:l=i.idBlock.isConstructed?Y.Constructed:Y.Primitive}return i=Bb(i,l),c=i.fromBER(t,e,i.lenBlock.isIndefiniteForm?n:i.lenBlock.length),i.valueBeforeDecodeView=t.subarray(r,r+i.blockLength),{offset:c,result:i}}function Xr(t){if(!t.byteLength){const e=new at({},wt);return e.error="Input buffer has zero length",{offset:-1,result:e}}return bi(G.toUint8Array(t).slice(),0,t.byteLength)}function Lb(t,e){return t?1:e}class Hn extends wt{constructor({value:e=[],isIndefiniteForm:n=!1,...r}={}){super(r),this.value=e,this.isIndefiniteForm=n}fromBER(e,n,r){const i=G.toUint8Array(e);if(!jn(this,i,n,r))return-1;if(this.valueBeforeDecodeView=i.subarray(n,n+r),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),n;let s=n;for(;Lb(this.isIndefiniteForm,r)>0;){const a=bi(i,s,r);if(a.offset===-1)return this.error=a.result.error,this.warnings.concat(a.result.warnings),-1;if(s=a.offset,this.blockLength+=a.result.blockLength,r-=a.result.blockLength,this.value.push(a.result),this.isIndefiniteForm&&a.result.constructor.NAME===oo)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===oo?this.value.pop():this.warnings.push("No EndOfContent block encoded")),s}toBER(e,n){const r=n||new Ha;for(let i=0;i<this.value.length;i++)this.value[i].toBER(e,r);return n?en:r.final()}toJSON(){const e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(const n of this.value)e.value.push(n.toJSON());return e}}Hn.NAME="ConstructedValueBlock";var Jm;class yt extends at{constructor(e={}){super(e,Hn),this.idBlock.isConstructed=!0}fromBER(e,n,r){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;const i=this.valueBlock.fromBER(e,n,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}onAsciiEncoding(){const e=[];for(const r of this.valueBlock.value)e.push(r.toString("ascii").split(`
143
143
  `).map(i=>` ${i}`).join(`
144
144
  `));const n=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${n} :
145
145
  ${e.join(`
146
- `)}`:`${n} :`}}Jm=yt;Y.Constructed=Jm;yt.NAME="CONSTRUCTED";class Xm extends wt{fromBER(e,n,r){return n}toBER(e){return tn}}Xm.override="EndOfContentValueBlock";var Zm;class ju extends at{constructor(e={}){super(e,Xm),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}}Zm=ju;Y.EndOfContent=Zm;ju.NAME=oo;var Ym;class wr extends at{constructor(e={}){super(e,wt),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,n,r){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=r,n+r>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):n+r}toBER(e,n){const r=new ArrayBuffer(2);if(!e){const i=new Uint8Array(r);i[0]=5,i[1]=0}return n&&n.write(r),r}onAsciiEncoding(){return`${this.constructor.NAME}`}}Ym=wr;Y.Null=Ym;wr.NAME="NULL";class Qm extends hn(wt){get value(){for(const e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}constructor({value:e,...n}={}){super(n),n.valueHex?this.valueHexView=G.toUint8Array(n.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,n,r){const i=G.toUint8Array(e);return jn(this,i,n,r)?(this.valueHexView=i.subarray(n,n+r),r>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Mm.call(this),this.blockLength=r,n+r):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}}Qm.NAME="BooleanValueBlock";var e_;let Ka=class extends at{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,Qm),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};e_=Ka;Y.Boolean=e_;Ka.NAME="BOOLEAN";class t_ extends hn(Hn){constructor({isConstructed:e=!1,...n}={}){super(n),this.isConstructed=e}fromBER(e,n,r){let i=0;if(this.isConstructed){if(this.isHexOnly=!1,i=Hn.prototype.fromBER.call(this,e,n,r),i===-1)return i;for(let s=0;s<this.value.length;s++){const a=this.value[s].constructor.NAME;if(a===oo){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(a!==Fm)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,i=super.fromBER(e,n,r),this.blockLength=r;return i}toBER(e,n){return this.isConstructed?Hn.prototype.toBER.call(this,e,n):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}}t_.NAME="OctetStringValueBlock";var Ou;let hr=class extends at{constructor({idBlock:e={},lenBlock:n={},...r}={}){var i,s;(i=r.isConstructed)!==null&&i!==void 0||(r.isConstructed=!!(!((s=r.value)===null||s===void 0)&&s.length)),super({idBlock:{isConstructed:r.isConstructed,...e},lenBlock:{...n,isIndefiniteForm:!!r.isIndefiniteForm},...r},t_),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,n,r){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,r===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),n;if(!this.valueBlock.isConstructed){const s=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(n,n+r);try{if(s.byteLength){const a=bi(s,0,s.byteLength);a.offset!==-1&&a.offset===r&&(this.valueBlock.value=[a.result])}}catch{}}return super.fromBER(e,n,r)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return yt.prototype.onAsciiEncoding.call(this);const e=this.constructor.NAME,n=re.ToHex(this.valueBlock.valueHexView);return`${e} : ${n}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;const e=[];for(const n of this.valueBlock.value)n instanceof Ou&&e.push(n.valueBlock.valueHexView);return G.concat(e)}};Ou=hr;Y.OctetString=Ou;hr.NAME=Fm;class n_ extends hn(Hn){constructor({unusedBits:e=0,isConstructed:n=!1,...r}={}){super(r),this.unusedBits=e,this.isConstructed=n,this.blockLength=this.valueHexView.byteLength}fromBER(e,n,r){if(!r)return n;let i=-1;if(this.isConstructed){if(i=Hn.prototype.fromBER.call(this,e,n,r),i===-1)return i;for(const c of this.value){const l=c.constructor.NAME;if(l===oo){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(l!==qm)return this.error="BIT STRING may consists of BIT STRINGs only",-1;const d=c.valueBlock;if(this.unusedBits>0&&d.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=d.unusedBits}return i}const s=G.toUint8Array(e);if(!jn(this,s,n,r))return-1;const a=s.subarray(n,n+r);if(this.unusedBits=a[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){const c=a.subarray(1);try{if(c.byteLength){const l=bi(c,0,c.byteLength);l.offset!==-1&&l.offset===r-1&&(this.value=[l.result])}}catch{}}return this.valueHexView=a.subarray(1),this.blockLength=a.length,n+r}toBER(e,n){if(this.isConstructed)return Hn.prototype.toBER.call(this,e,n);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return tn;const r=new Uint8Array(this.valueHexView.length+1);return r[0]=this.unusedBits,r.set(this.valueHexView,1),r.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}}n_.NAME="BitStringValueBlock";var r_;let gr=class extends at{constructor({idBlock:e={},lenBlock:n={},...r}={}){var i,s;(i=r.isConstructed)!==null&&i!==void 0||(r.isConstructed=!!(!((s=r.value)===null||s===void 0)&&s.length)),super({idBlock:{isConstructed:r.isConstructed,...e},lenBlock:{...n,isIndefiniteForm:!!r.isIndefiniteForm},...r},n_),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,n,r){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,n,r)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return yt.prototype.onAsciiEncoding.call(this);{const e=[],n=this.valueBlock.valueHexView;for(const a of n)e.push(a.toString(2).padStart(8,"0"));const r=e.join(""),i=this.constructor.NAME,s=r.substring(0,r.length-this.valueBlock.unusedBits);return`${i} : ${s}`}}};r_=gr;Y.BitString=r_;gr.NAME=qm;var i_;function Ub(t,e){const n=new Uint8Array([0]),r=new Uint8Array(t),i=new Uint8Array(e);let s=r.slice(0);const a=s.length-1,c=i.slice(0),l=c.length-1;let d=0;const u=l<a?a:l;let f=0;for(let h=u;h>=0;h--,f++){switch(!0){case f<c.length:d=s[a-f]+c[l-f]+n[0];break;default:d=s[a-f]+n[0]}switch(n[0]=d/10,!0){case f>=s.length:s=Ol(new Uint8Array([d%10]),s);break;default:s[a-f]=d%10}}return n[0]>0&&(s=Ol(n,s)),s}function zf(t){if(t>=Li.length)for(let e=Li.length;e<=t;e++){const n=new Uint8Array([0]);let r=Li[e-1].slice(0);for(let i=r.length-1;i>=0;i--){const s=new Uint8Array([(r[i]<<1)+n[0]]);n[0]=s[0]/10,r[i]=s[0]%10}n[0]>0&&(r=Ol(n,r)),Li.push(r)}return Li[t]}function Db(t,e){let n=0;const r=new Uint8Array(t),i=new Uint8Array(e),s=r.slice(0),a=s.length-1,c=i.slice(0),l=c.length-1;let d,u=0;for(let f=l;f>=0;f--,u++)switch(d=s[a-u]-c[l-u]-n,!0){case d<0:n=1,s[a-u]=d+10;break;default:n=0,s[a-u]=d}if(n>0)for(let f=a-l+1;f>=0;f--,u++)if(d=s[a-u]-n,d<0)n=1,s[a-u]=d+10;else{n=0,s[a-u]=d;break}return s.slice()}class Tu extends hn(wt){setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Mm.call(this)))}constructor({value:e,...n}={}){super(n),this._valueDec=0,n.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Ab(e))}get valueDec(){return this._valueDec}fromDER(e,n,r,i=0){const s=this.fromBER(e,n,r);if(s===-1)return s;const a=this.valueHexView;return a[0]===0&&a[1]&128?this.valueHexView=a.subarray(1):i!==0&&a.length<i&&(i-a.length>1&&(i=a.length+1),this.valueHexView=a.subarray(i-a.length)),s}toDER(e=!1){const n=this.valueHexView;switch(!0){case(n[0]&128)!==0:{const r=new Uint8Array(this.valueHexView.length+1);r[0]=0,r.set(n,1),this.valueHexView=r}break;case(n[0]===0&&(n[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,n,r){const i=super.fromBER(e,n,r);return i===-1||this.setValueHex(),i}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){const e=this.valueHexView.length*8-1;let n=new Uint8Array(this.valueHexView.length*8/3),r=0,i;const s=this.valueHexView;let a="",c=!1;for(let l=s.byteLength-1;l>=0;l--){i=s[l];for(let d=0;d<8;d++){if((i&1)===1)switch(r){case e:n=Db(zf(r),n),a="-";break;default:n=Ub(n,zf(r))}r++,i>>=1}}for(let l=0;l<n.length;l++)n[l]&&(c=!0),c&&(a+=xf.charAt(n[l]));return c===!1&&(a+=xf.charAt(0)),a}}i_=Tu;Tu.NAME="IntegerValueBlock";Object.defineProperty(i_.prototype,"valueHex",{set:function(t){this.valueHexView=new Uint8Array(t),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Wi;class $i extends at{constructor(e={}){super(e,Tu),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Ks(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Ks();const n=BigInt(e),r=new Ha,i=n.toString(16).replace(/^-/,""),s=new Uint8Array(re.FromHex(i));if(n<0){const c=new Uint8Array(s.length+(s[0]&128?1:0));c[0]|=128;const d=BigInt(`0x${re.ToHex(c)}`)+n,u=G.toUint8Array(re.FromHex(d.toString(16)));u[0]|=128,r.write(u)}else s[0]&128&&r.write(new Uint8Array([0])),r.write(s);return new Wi({valueHex:r.final()})}convertToDER(){const e=new Wi({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new Wi({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}}Wi=$i;Y.Integer=Wi;$i.NAME="INTEGER";var o_;class Ga extends $i{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}}o_=Ga;Y.Enumerated=o_;Ga.NAME="ENUMERATED";class Tl extends hn(wt){constructor({valueDec:e=-1,isFirstSid:n=!1,...r}={}){super(r),this.valueDec=e,this.isFirstSid=n}fromBER(e,n,r){if(!r)return n;const i=G.toUint8Array(e);if(!jn(this,i,n,r))return-1;const s=i.subarray(n,n+r);this.valueHexView=new Uint8Array(r);for(let c=0;c<r&&(this.valueHexView[c]=s[c]&127,this.blockLength++,!!(s[c]&128));c++);const a=new Uint8Array(this.blockLength);for(let c=0;c<this.blockLength;c++)a[c]=this.valueHexView[c];return this.valueHexView=a,s[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=ii(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),n+this.blockLength)}set valueBigInt(e){Ks();let n=BigInt(e).toString(2);for(;n.length%7;)n="0"+n;const r=new Uint8Array(n.length/7);for(let i=0;i<r.length;i++)r[i]=parseInt(n.slice(i*7,i*7+7),2)+(i+1<r.length?128:0);this.fromBER(r.buffer,0,r.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const i=this.valueHexView,s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength-1;a++)s[a]=i[a]|128;return s[this.blockLength-1]=i[this.blockLength-1],s.buffer}const n=yr(this.valueDec,7);if(n.byteLength===0)return this.error="Error during encoding SID value",tn;const r=new Uint8Array(n.byteLength);if(!e){const i=new Uint8Array(n),s=n.byteLength-1;for(let a=0;a<s;a++)r[a]=i[a]|128;r[s]=i[s]}return r}toString(){let e="";if(this.isHexOnly)e=re.ToHex(this.valueHexView);else if(this.isFirstSid){let n=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",n-=40):(e="2.",n-=80),e+=n.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}}Tl.NAME="sidBlock";class s_ extends wt{constructor({value:e=kt,...n}={}){super(n),this.value=[],e&&this.fromString(e)}fromBER(e,n,r){let i=n;for(;r>0;){const s=new Tl;if(i=s.fromBER(e,i,r),i===-1)return this.blockLength=0,this.error=s.error,i;this.value.length===0&&(s.isFirstSid=!0),this.blockLength+=s.blockLength,r-=s.blockLength,this.value.push(s)}return i}toBER(e){const n=[];for(let r=0;r<this.value.length;r++){const i=this.value[r].toBER(e);if(i.byteLength===0)return this.error=this.value[r].error,tn;n.push(i)}return Nu(n)}fromString(e){this.value=[];let n=0,r=0,i="",s=!1;do if(r=e.indexOf(".",n),r===-1?i=e.substring(n):i=e.substring(n,r),n=r+1,s){const a=this.value[0];let c=0;switch(a.valueDec){case 0:break;case 1:c=40;break;case 2:c=80;break;default:this.value=[];return}const l=parseInt(i,10);if(isNaN(l))return;a.valueDec=l+c,s=!1}else{const a=new Tl;if(i>Number.MAX_SAFE_INTEGER){Ks();const c=BigInt(i);a.valueBigInt=c}else if(a.valueDec=parseInt(i,10),isNaN(a.valueDec))return;this.value.length||(a.isFirstSid=!0,s=!0),this.value.push(a)}while(r!==-1)}toString(){let e="",n=!1;for(let r=0;r<this.value.length;r++){n=this.value[r].isHexOnly;let i=this.value[r].toString();r!==0&&(e=`${e}.`),n?(i=`{${i}}`,this.value[r].isFirstSid?e=`2.{${i} - 80}`:e+=i):e+=i}return e}toJSON(){const e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let n=0;n<this.value.length;n++)e.sidArray.push(this.value[n].toJSON());return e}}s_.NAME="ObjectIdentifierValueBlock";var a_;class Wa extends at{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,s_),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}a_=Wa;Y.ObjectIdentifier=a_;Wa.NAME="OBJECT IDENTIFIER";class Pl extends hn(Or){constructor({valueDec:e=0,...n}={}){super(n),this.valueDec=e}fromBER(e,n,r){if(r===0)return n;const i=G.toUint8Array(e);if(!jn(this,i,n,r))return-1;const s=i.subarray(n,n+r);this.valueHexView=new Uint8Array(r);for(let c=0;c<r&&(this.valueHexView[c]=s[c]&127,this.blockLength++,!!(s[c]&128));c++);const a=new Uint8Array(this.blockLength);for(let c=0;c<this.blockLength;c++)a[c]=this.valueHexView[c];return this.valueHexView=a,s[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=ii(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),n+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const i=this.valueHexView,s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength-1;a++)s[a]=i[a]|128;return s[this.blockLength-1]=i[this.blockLength-1],s.buffer}const n=yr(this.valueDec,7);if(n.byteLength===0)return this.error="Error during encoding SID value",tn;const r=new Uint8Array(n.byteLength);if(!e){const i=new Uint8Array(n),s=n.byteLength-1;for(let a=0;a<s;a++)r[a]=i[a]|128;r[s]=i[s]}return r.buffer}toString(){let e="";return this.isHexOnly?e=re.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}}Pl.NAME="relativeSidBlock";class c_ extends wt{constructor({value:e=kt,...n}={}){super(n),this.value=[],e&&this.fromString(e)}fromBER(e,n,r){let i=n;for(;r>0;){const s=new Pl;if(i=s.fromBER(e,i,r),i===-1)return this.blockLength=0,this.error=s.error,i;this.blockLength+=s.blockLength,r-=s.blockLength,this.value.push(s)}return i}toBER(e,n){const r=[];for(let i=0;i<this.value.length;i++){const s=this.value[i].toBER(e);if(s.byteLength===0)return this.error=this.value[i].error,tn;r.push(s)}return Nu(r)}fromString(e){this.value=[];let n=0,r=0,i="";do{r=e.indexOf(".",n),r===-1?i=e.substring(n):i=e.substring(n,r),n=r+1;const s=new Pl;if(s.valueDec=parseInt(i,10),isNaN(s.valueDec))return!0;this.value.push(s)}while(r!==-1);return!0}toString(){let e="",n=!1;for(let r=0;r<this.value.length;r++){n=this.value[r].isHexOnly;let i=this.value[r].toString();r!==0&&(e=`${e}.`),n&&(i=`{${i}}`),e+=i}return e}toJSON(){const e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let n=0;n<this.value.length;n++)e.sidArray.push(this.value[n].toJSON());return e}}c_.NAME="RelativeObjectIdentifierValueBlock";var l_;class Pu extends at{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,c_),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}l_=Pu;Y.RelativeObjectIdentifier=l_;Pu.NAME="RelativeObjectIdentifier";var d_;class Jt extends yt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}}d_=Jt;Y.Sequence=d_;Jt.NAME="SEQUENCE";var u_;let dn=class extends yt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};u_=dn;Y.Set=u_;dn.NAME="SET";class p_ extends hn(wt){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=kt}toJSON(){return{...super.toJSON(),value:this.value}}}p_.NAME="StringValueBlock";class f_ extends p_{}f_.NAME="SimpleStringValueBlock";class jt extends Iu{constructor({...e}={}){super(e,f_)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,G.toUint8Array(e))}fromString(e){const n=e.length,r=this.valueBlock.valueHexView=new Uint8Array(n);for(let i=0;i<n;i++)r[i]=e.charCodeAt(i);this.valueBlock.value=e}}jt.NAME="SIMPLE STRING";class h_ extends jt{fromBuffer(e){this.valueBlock.valueHexView=G.toUint8Array(e);try{this.valueBlock.value=re.ToUtf8String(e)}catch(n){this.warnings.push(`Error during "decodeURIComponent": ${n}, using raw string`),this.valueBlock.value=re.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(re.FromUtf8String(e)),this.valueBlock.value=e}}h_.NAME="Utf8StringValueBlock";var g_;class On extends h_{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}}g_=On;Y.Utf8String=g_;On.NAME="UTF8String";class m_ extends jt{fromBuffer(e){this.valueBlock.value=re.ToUtf16String(e),this.valueBlock.valueHexView=G.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(re.FromUtf16String(e))}}m_.NAME="BmpStringValueBlock";var __;class Ja extends m_{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}}__=Ja;Y.BmpString=__;Ja.NAME="BMPString";class y_ extends jt{fromBuffer(e){const n=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),r=new Uint8Array(n);for(let i=0;i<r.length;i+=4)r[i]=r[i+3],r[i+1]=r[i+2],r[i+2]=0,r[i+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(n))}fromString(e){const n=e.length,r=this.valueBlock.valueHexView=new Uint8Array(n*4);for(let i=0;i<n;i++){const s=yr(e.charCodeAt(i),8),a=new Uint8Array(s);if(a.length>4)continue;const c=4-a.length;for(let l=a.length-1;l>=0;l--)r[i*4+l+c]=a[l]}this.valueBlock.value=e}}y_.NAME="UniversalStringValueBlock";var w_;class Xa extends y_{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}}w_=Xa;Y.UniversalString=w_;Xa.NAME="UniversalString";var v_;class Za extends jt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}}v_=Za;Y.NumericString=v_;Za.NAME="NumericString";var b_;class Ya extends jt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}}b_=Ya;Y.PrintableString=b_;Ya.NAME="PrintableString";var $_;class Qa extends jt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}}$_=Qa;Y.TeletexString=$_;Qa.NAME="TeletexString";var k_;class ec extends jt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}}k_=ec;Y.VideotexString=k_;ec.NAME="VideotexString";var x_;class tc extends jt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}}x_=tc;Y.IA5String=x_;tc.NAME="IA5String";var S_;class nc extends jt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}}S_=nc;Y.GraphicString=S_;nc.NAME="GraphicString";var z_;class zo extends jt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}}z_=zo;Y.VisibleString=z_;zo.NAME="VisibleString";var A_;class rc extends jt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}}A_=rc;Y.GeneralString=A_;rc.NAME="GeneralString";var E_;class ic extends jt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}}E_=ic;Y.CharacterString=E_;ic.NAME="CharacterString";var C_;class Ao extends zo{constructor({value:e,valueDate:n,...r}={}){if(super(r),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let i=0;i<e.length;i++)this.valueBlock.valueHexView[i]=e.charCodeAt(i)}n&&(this.fromDate(n),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,G.toUint8Array(e)))}toBuffer(){const e=this.toString(),n=new ArrayBuffer(e.length),r=new Uint8Array(n);for(let i=0;i<e.length;i++)r[i]=e.charCodeAt(i);return n}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){const r=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(r===null){this.error="Wrong input string for conversion";return}const i=parseInt(r[1],10);i>=50?this.year=1900+i:this.year=2e3+i,this.month=parseInt(r[2],10),this.day=parseInt(r[3],10),this.hour=parseInt(r[4],10),this.minute=parseInt(r[5],10),this.second=parseInt(r[6],10)}toString(e="iso"){if(e==="iso"){const n=new Array(7);return n[0]=Et(this.year<2e3?this.year-1900:this.year-2e3,2),n[1]=Et(this.month,2),n[2]=Et(this.day,2),n[3]=Et(this.hour,2),n[4]=Et(this.minute,2),n[5]=Et(this.second,2),n[6]="Z",n.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}}C_=Ao;Y.UTCTime=C_;Ao.NAME="UTCTime";var N_;class oc extends Ao{constructor(e={}){var n;super(e),(n=this.millisecond)!==null&&n!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){const e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(e)}fromString(e){let n=!1,r="",i="",s=0,a,c=0,l=0;if(e[e.length-1]==="Z")r=e.substring(0,e.length-1),n=!0;else{const f=new Number(e[e.length-1]);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");r=e}if(n){if(r.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(r.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let f=1,h=r.indexOf("+"),m="";if(h===-1&&(h=r.indexOf("-"),f=-1),h!==-1){if(m=r.substring(h+1),r=r.substring(0,h),m.length!==2&&m.length!==4)throw new Error("Wrong input string for conversion");let y=parseInt(m.substring(0,2),10);if(isNaN(y.valueOf()))throw new Error("Wrong input string for conversion");if(c=f*y,m.length===4){if(y=parseInt(m.substring(2,4),10),isNaN(y.valueOf()))throw new Error("Wrong input string for conversion");l=f*y}}}let d=r.indexOf(".");if(d===-1&&(d=r.indexOf(",")),d!==-1){const f=new Number(`0${r.substring(d)}`);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");s=f.valueOf(),i=r.substring(0,d)}else i=r;switch(!0){case i.length===8:if(a=/(\d{4})(\d{2})(\d{2})/ig,d!==-1)throw new Error("Wrong input string for conversion");break;case i.length===10:if(a=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,d!==-1){let f=60*s;this.minute=Math.floor(f),f=60*(f-this.minute),this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case i.length===12:if(a=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,d!==-1){let f=60*s;this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case i.length===14:if(a=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,d!==-1){const f=1e3*s;this.millisecond=Math.floor(f)}break;default:throw new Error("Wrong input string for conversion")}const u=a.exec(i);if(u===null)throw new Error("Wrong input string for conversion");for(let f=1;f<u.length;f++)switch(f){case 1:this.year=parseInt(u[f],10);break;case 2:this.month=parseInt(u[f],10);break;case 3:this.day=parseInt(u[f],10);break;case 4:this.hour=parseInt(u[f],10)+c;break;case 5:this.minute=parseInt(u[f],10)+l;break;case 6:this.second=parseInt(u[f],10);break;default:throw new Error("Wrong input string for conversion")}if(n===!1){const f=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=f.getUTCFullYear(),this.month=f.getUTCMonth(),this.day=f.getUTCDay(),this.hour=f.getUTCHours(),this.minute=f.getUTCMinutes(),this.second=f.getUTCSeconds(),this.millisecond=f.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){const n=[];return n.push(Et(this.year,4)),n.push(Et(this.month,2)),n.push(Et(this.day,2)),n.push(Et(this.hour,2)),n.push(Et(this.minute,2)),n.push(Et(this.second,2)),this.millisecond!==0&&(n.push("."),n.push(Et(this.millisecond,3))),n.push("Z"),n.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}}N_=oc;Y.GeneralizedTime=N_;oc.NAME="GeneralizedTime";var I_;class Ru extends On{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}}I_=Ru;Y.DATE=I_;Ru.NAME="DATE";var j_;class Bu extends On{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}}j_=Bu;Y.TimeOfDay=j_;Bu.NAME="TimeOfDay";var O_;class Lu extends On{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}}O_=Lu;Y.DateTime=O_;Lu.NAME="DateTime";var T_;class Uu extends On{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}}T_=Uu;Y.Duration=T_;Uu.NAME="Duration";var P_;class Du extends On{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}}P_=Du;Y.TIME=P_;Du.NAME="TIME";class vr{constructor({name:e=kt,optional:n=!1}={}){this.name=e,this.optional=n}}class Mu extends vr{constructor({value:e=[],...n}={}){super(n),this.value=e}}class Gs extends vr{constructor({value:e=new vr,local:n=!1,...r}={}){super(r),this.value=e,this.local=n}}class Mb{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=G.toUint8Array(e)}constructor({data:e=Va}={}){this.dataView=G.toUint8Array(e)}fromBER(e,n,r){const i=n+r;return this.dataView=G.toUint8Array(e).subarray(n,i),i}toBER(e){return this.dataView.slice().buffer}}function Mn(t,e,n){if(n instanceof Mu){for(const s of n.value)if(Mn(t,e,s).verified)return{verified:!0,result:t};{const s={verified:!1,result:{error:"Wrong values for Choice type"}};return n.hasOwnProperty(Xc)&&(s.name=n.name),s}}if(n instanceof vr)return n.hasOwnProperty(Xc)&&(t[n.name]=e),{verified:!0,result:t};if(!(t instanceof Object))return{verified:!1,result:{error:"Wrong root object"}};if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 data"}};if(!(n instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(Nb in n))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(Tb in n.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(Pb in n.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};const r=n.idBlock.toBER(!1);if(r.byteLength===0)return{verified:!1,result:{error:"Error encoding idBlock for ASN.1 schema"}};if(n.idBlock.fromBER(r,0,r.byteLength)===-1)return{verified:!1,result:{error:"Error decoding idBlock for ASN.1 schema"}};if(n.idBlock.hasOwnProperty(Ib)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(n.idBlock.tagClass!==e.idBlock.tagClass)return{verified:!1,result:t};if(n.idBlock.hasOwnProperty(jb)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(n.idBlock.tagNumber!==e.idBlock.tagNumber)return{verified:!1,result:t};if(n.idBlock.hasOwnProperty(Ob)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(n.idBlock.isConstructed!==e.idBlock.isConstructed)return{verified:!1,result:t};if(!(Cb in n.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(n.idBlock.isHexOnly!==e.idBlock.isHexOnly)return{verified:!1,result:t};if(n.idBlock.isHexOnly){if(!(Sf in n.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};const s=n.idBlock.valueHexView,a=e.idBlock.valueHexView;if(s.length!==a.length)return{verified:!1,result:t};for(let c=0;c<s.length;c++)if(s[c]!==a[1])return{verified:!1,result:t}}if(n.name&&(n.name=n.name.replace(/^\s+|\s+$/g,kt),n.name&&(t[n.name]=e)),n instanceof Y.Constructed){let s=0,a={verified:!1,result:{error:"Unknown error"}},c=n.valueBlock.value.length;if(c>0&&n.valueBlock.value[0]instanceof Gs&&(c=e.valueBlock.value.length),c===0)return{verified:!0,result:t};if(e.valueBlock.value.length===0&&n.valueBlock.value.length!==0){let l=!0;for(let d=0;d<n.valueBlock.value.length;d++)l=l&&(n.valueBlock.value[d].optional||!1);return l?{verified:!0,result:t}:(n.name&&(n.name=n.name.replace(/^\s+|\s+$/g,kt),n.name&&delete t[n.name]),t.error="Inconsistent object length",{verified:!1,result:t})}for(let l=0;l<c;l++)if(l-s>=e.valueBlock.value.length){if(n.valueBlock.value[l].optional===!1){const d={verified:!1,result:t};return t.error="Inconsistent length between ASN.1 data and schema",n.name&&(n.name=n.name.replace(/^\s+|\s+$/g,kt),n.name&&(delete t[n.name],d.name=n.name)),d}}else if(n.valueBlock.value[0]instanceof Gs){if(a=Mn(t,e.valueBlock.value[l],n.valueBlock.value[0].value),a.verified===!1)if(n.valueBlock.value[0].optional)s++;else return n.name&&(n.name=n.name.replace(/^\s+|\s+$/g,kt),n.name&&delete t[n.name]),a;if(Xc in n.valueBlock.value[0]&&n.valueBlock.value[0].name.length>0){let d={};Rb in n.valueBlock.value[0]&&n.valueBlock.value[0].local?d=e:d=t,typeof d[n.valueBlock.value[0].name]>"u"&&(d[n.valueBlock.value[0].name]=[]),d[n.valueBlock.value[0].name].push(e.valueBlock.value[l])}}else if(a=Mn(t,e.valueBlock.value[l-s],n.valueBlock.value[l]),a.verified===!1)if(n.valueBlock.value[l].optional)s++;else return n.name&&(n.name=n.name.replace(/^\s+|\s+$/g,kt),n.name&&delete t[n.name]),a;if(a.verified===!1){const l={verified:!1,result:t};return n.name&&(n.name=n.name.replace(/^\s+|\s+$/g,kt),n.name&&(delete t[n.name],l.name=n.name)),l}return{verified:!0,result:t}}if(n.primitiveSchema&&Sf in e.valueBlock){const s=bi(e.valueBlock.valueHexView);if(s.offset===-1){const a={verified:!1,result:s.result};return n.name&&(n.name=n.name.replace(/^\s+|\s+$/g,kt),n.name&&(delete t[n.name],a.name=n.name)),a}return Mn(t,s.result,n.primitiveSchema)}return{verified:!0,result:t}}function Fb(t,e){if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};const n=bi(G.toUint8Array(t));return n.offset===-1?{verified:!1,result:n.result}:Mn(n.result,n.result,e)}const R_=Object.freeze(Object.defineProperty({__proto__:null,Any:vr,BaseBlock:at,BaseStringBlock:Iu,BitString:gr,BmpString:Ja,Boolean:Ka,CharacterString:ic,Choice:Mu,Constructed:yt,DATE:Ru,DateTime:Lu,Duration:Uu,EndOfContent:ju,Enumerated:Ga,GeneralString:rc,GeneralizedTime:oc,GraphicString:nc,HexBlock:hn,IA5String:tc,Integer:$i,Null:wr,NumericString:Za,ObjectIdentifier:Wa,OctetString:hr,Primitive:So,PrintableString:Ya,RawData:Mb,RelativeObjectIdentifier:Pu,Repeated:Gs,Sequence:Jt,Set:dn,TIME:Du,TeletexString:Qa,TimeOfDay:Bu,UTCTime:Ao,UniversalString:Xa,Utf8String:On,ValueBlock:wt,VideotexString:ec,ViewWriter:Ha,VisibleString:zo,compareSchema:Mn,fromBER:Xr,verifySchema:Fb},Symbol.toStringTag,{value:"Module"}));var B;(function(t){t[t.Sequence=0]="Sequence",t[t.Set=1]="Set",t[t.Choice=2]="Choice"})(B||(B={}));var x;(function(t){t[t.Any=1]="Any",t[t.Boolean=2]="Boolean",t[t.OctetString=3]="OctetString",t[t.BitString=4]="BitString",t[t.Integer=5]="Integer",t[t.Enumerated=6]="Enumerated",t[t.ObjectIdentifier=7]="ObjectIdentifier",t[t.Utf8String=8]="Utf8String",t[t.BmpString=9]="BmpString",t[t.UniversalString=10]="UniversalString",t[t.NumericString=11]="NumericString",t[t.PrintableString=12]="PrintableString",t[t.TeletexString=13]="TeletexString",t[t.VideotexString=14]="VideotexString",t[t.IA5String=15]="IA5String",t[t.GraphicString=16]="GraphicString",t[t.VisibleString=17]="VisibleString",t[t.GeneralString=18]="GeneralString",t[t.CharacterString=19]="CharacterString",t[t.UTCTime=20]="UTCTime",t[t.GeneralizedTime=21]="GeneralizedTime",t[t.DATE=22]="DATE",t[t.TimeOfDay=23]="TimeOfDay",t[t.DateTime=24]="DateTime",t[t.Duration=25]="Duration",t[t.TIME=26]="TIME",t[t.Null=27]="Null"})(x||(x={}));class sc{constructor(e,n=0){if(this.unusedBits=0,this.value=new ArrayBuffer(0),e)if(typeof e=="number")this.fromNumber(e);else if(G.isBufferSource(e))this.unusedBits=n,this.value=G.toArrayBuffer(e);else throw TypeError("Unsupported type of 'params' argument for BitString")}fromASN(e){if(!(e instanceof gr))throw new TypeError("Argument 'asn' is not instance of ASN.1 BitString");return this.unusedBits=e.valueBlock.unusedBits,this.value=e.valueBlock.valueHex,this}toASN(){return new gr({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(e){return new gr({name:e})}toNumber(){let e="";const n=new Uint8Array(this.value);for(const r of n)e+=r.toString(2).padStart(8,"0");return e=e.split("").reverse().join(""),this.unusedBits&&(e=e.slice(this.unusedBits).padStart(this.unusedBits,"0")),parseInt(e,2)}fromNumber(e){let n=e.toString(2);const r=n.length+7>>3;this.unusedBits=(r<<3)-n.length;const i=new Uint8Array(r);n=n.padStart(r<<3,"0").split("").reverse().join("");let s=0;for(;s<r;)i[s]=parseInt(n.slice(s<<3,(s<<3)+8),2),s++;this.value=i.buffer}}class ke{get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(e){typeof e=="number"?this.buffer=new ArrayBuffer(e):G.isBufferSource(e)?this.buffer=G.toArrayBuffer(e):Array.isArray(e)?this.buffer=new Uint8Array(e):this.buffer=new ArrayBuffer(0)}fromASN(e){if(!(e instanceof hr))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=e.valueBlock.valueHex,this}toASN(){return new hr({valueHex:this.buffer})}toSchema(e){return new hr({name:e})}}const qb={fromASN:t=>t instanceof wr?null:t.valueBeforeDecodeView,toASN:t=>{if(t===null)return new wr;const e=Xr(t);if(e.result.error)throw new Error(e.result.error);return e.result}},Hb={fromASN:t=>t.valueBlock.valueHexView.byteLength>=4?t.valueBlock.toString():t.valueBlock.valueDec,toASN:t=>new $i({value:+t})},Vb={fromASN:t=>t.valueBlock.valueDec,toASN:t=>new Ga({value:t})},je={fromASN:t=>t.valueBlock.valueHexView,toASN:t=>new $i({valueHex:t})},Kb={fromASN:t=>t.valueBlock.valueHexView,toASN:t=>new gr({valueHex:t})},Gb={fromASN:t=>t.valueBlock.toString(),toASN:t=>new Wa({value:t})},Wb={fromASN:t=>t.valueBlock.value,toASN:t=>new Ka({value:t})},Ws={fromASN:t=>t.valueBlock.valueHexView,toASN:t=>new hr({valueHex:t})},Jb={fromASN:t=>new ke(t.getValue()),toASN:t=>t.toASN()};function Mt(t){return{fromASN:e=>e.valueBlock.value,toASN:e=>new t({value:e})}}const B_=Mt(On),Xb=Mt(Ja),Zb=Mt(Xa),Yb=Mt(Za),Qb=Mt(Ya),e3=Mt(Qa),t3=Mt(ec),n3=Mt(tc),r3=Mt(nc),i3=Mt(zo),o3=Mt(rc),s3=Mt(ic),a3={fromASN:t=>t.toDate(),toASN:t=>new Ao({valueDate:t})},c3={fromASN:t=>t.toDate(),toASN:t=>new oc({valueDate:t})},l3={fromASN:()=>null,toASN:()=>new wr};function Ji(t){switch(t){case x.Any:return qb;case x.BitString:return Kb;case x.BmpString:return Xb;case x.Boolean:return Wb;case x.CharacterString:return s3;case x.Enumerated:return Vb;case x.GeneralString:return o3;case x.GeneralizedTime:return c3;case x.GraphicString:return r3;case x.IA5String:return n3;case x.Integer:return Hb;case x.Null:return l3;case x.NumericString:return Yb;case x.ObjectIdentifier:return Gb;case x.OctetString:return Ws;case x.PrintableString:return Qb;case x.TeletexString:return e3;case x.UTCTime:return a3;case x.UniversalString:return Zb;case x.Utf8String:return B_;case x.VideotexString:return t3;case x.VisibleString:return i3;default:return null}}function xn(t){return typeof t=="function"&&t.prototype?t.prototype.toASN&&t.prototype.fromASN?!0:xn(t.prototype):!!(t&&typeof t=="object"&&"toASN"in t&&"fromASN"in t)}function L_(t){var e;if(t){const n=Object.getPrototypeOf(t);return((e=n==null?void 0:n.prototype)===null||e===void 0?void 0:e.constructor)===Array?!0:L_(n)}return!1}function d3(t,e){if(!(t&&e)||t.byteLength!==e.byteLength)return!1;const n=new Uint8Array(t),r=new Uint8Array(e);for(let i=0;i<t.byteLength;i++)if(n[i]!==r[i])return!1;return!0}class u3{constructor(){this.items=new WeakMap}has(e){return this.items.has(e)}get(e,n=!1){const r=this.items.get(e);if(!r)throw new Error(`Cannot get schema for '${e.prototype.constructor.name}' target`);if(n&&!r.schema)throw new Error(`Schema '${e.prototype.constructor.name}' doesn't contain ASN.1 schema. Call 'AsnSchemaStorage.cache'.`);return r}cache(e){const n=this.get(e);n.schema||(n.schema=this.create(e,!0))}createDefault(e){const n={type:B.Sequence,items:{}},r=this.findParentSchema(e);return r&&(Object.assign(n,r),n.items=Object.assign({},n.items,r.items)),n}create(e,n){const r=this.items.get(e)||this.createDefault(e),i=[];for(const s in r.items){const a=r.items[s],c=n?s:"";let l;if(typeof a.type=="number"){const u=x[a.type],f=R_[u];if(!f)throw new Error(`Cannot get ASN1 class by name '${u}'`);l=new f({name:c})}else xn(a.type)?l=new a.type().toSchema(c):a.optional?this.get(a.type).type===B.Choice?l=new vr({name:c}):(l=this.create(a.type,!1),l.name=c):l=new vr({name:c});const d=!!a.optional||a.defaultValue!==void 0;if(a.repeated){l.name="";const u=a.repeated==="set"?dn:Jt;l=new u({name:"",value:[new Gs({name:c,value:l})]})}if(a.context!==null&&a.context!==void 0)if(a.implicit)if(typeof a.type=="number"||xn(a.type)){const u=a.repeated?yt:So;i.push(new u({name:c,optional:d,idBlock:{tagClass:3,tagNumber:a.context}}))}else{this.cache(a.type);const u=!!a.repeated;let f=u?l:this.get(a.type,!0).schema;f="valueBlock"in f?f.valueBlock.value:f.value,i.push(new yt({name:u?"":c,optional:d,idBlock:{tagClass:3,tagNumber:a.context},value:f}))}else i.push(new yt({optional:d,idBlock:{tagClass:3,tagNumber:a.context},value:[l]}));else l.optional=d,i.push(l)}switch(r.type){case B.Sequence:return new Jt({value:i,name:""});case B.Set:return new dn({value:i,name:""});case B.Choice:return new Mu({value:i,name:""});default:throw new Error("Unsupported ASN1 type in use")}}set(e,n){return this.items.set(e,n),this}findParentSchema(e){const n=Object.getPrototypeOf(e);return n?this.items.get(n)||this.findParentSchema(n):null}}const Je=new u3,M=t=>e=>{let n;Je.has(e)?n=Je.get(e):(n=Je.createDefault(e),Je.set(e,n)),Object.assign(n,t)},_=t=>(e,n)=>{let r;Je.has(e.constructor)?r=Je.get(e.constructor):(r=Je.createDefault(e.constructor),Je.set(e.constructor,r));const i=Object.assign({},t);if(typeof i.type=="number"&&!i.converter){const s=Ji(t.type);if(!s)throw new Error(`Cannot get default converter for property '${n}' of ${e.constructor.name}`);i.converter=s}r.items[n]=i};class Ui extends Error{constructor(){super(...arguments),this.schemas=[]}}class p3{static parse(e,n){const r=Xr(e);if(r.result.error)throw new Error(r.result.error);return this.fromASN(r.result,n)}static fromASN(e,n){try{if(xn(n))return new n().fromASN(e);const r=Je.get(n);Je.cache(n);let i=r.schema;const s=this.handleChoiceTypes(e,r,n,i);if(s!=null&&s.result)return s.result;s!=null&&s.targetSchema&&(i=s.targetSchema);const a=this.handleSequenceTypes(e,r,n,i);if(a&&"isManualMapping"in a)return a.result;const c=a,l=new n;return L_(n)?this.handleArrayTypes(e,r,n):(this.processSchemaItems(r,c,l),l)}catch(r){throw r instanceof Ui&&r.schemas.push(n.name),r}}static handleChoiceTypes(e,n,r,i){if(e.constructor===yt&&n.type===B.Choice&&e.idBlock.tagClass===3)for(const s in n.items){const a=n.items[s];if(a.context===e.idBlock.tagNumber&&a.implicit&&typeof a.type=="function"&&Je.has(a.type)){const c=Je.get(a.type);if(c&&c.type===B.Sequence){const l=new Jt;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in l.valueBlock){l.valueBlock.value=e.valueBlock.value;const d=this.fromASN(l,a.type),u=new r;return u[s]=d,{result:u}}}}}else if(e.constructor===yt&&n.type!==B.Choice){const s=new yt({idBlock:{tagClass:3,tagNumber:e.idBlock.tagNumber},value:n.schema.valueBlock.value});for(const a in n.items)delete e[a];return{targetSchema:s}}return null}static handleSequenceTypes(e,n,r,i){if(n.type===B.Sequence){if(Object.keys(n.items).filter(c=>{const l=n.items[c];return l.optional&&typeof l.type=="function"&&Je.has(l.type)&&Je.get(l.type).type===B.Choice}).length>0&&"value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&r.name==="CertReqMsg")return this.handleManualMapping(e,n,r);const a=Mn({},e,i);if(!a.verified)throw new Ui(`Data does not match to ${r.name} ASN1 schema. ${a.result.error}`);return a}else{const s=Mn({},e,i);if(!s.verified)throw new Ui(`Data does not match to ${r.name} ASN1 schema. ${s.result.error}`);return s}}static handleManualMapping(e,n,r){const i=new r,s=e.valueBlock.value,a=Object.keys(n.items);let c=0;for(let l=0;l<a.length;l++){const d=a[l],u=n.items[d];if(c>=s.length)break;if(u.repeated){i[d]=this.processRepeatedField(s,c,u);break}else if(typeof u.type=="number")i[d]=this.processPrimitiveField(s[c],u),c++;else if(this.isOptionalChoiceField(u)){const f=this.processOptionalChoiceField(s[c],u);f.processed&&(i[d]=f.value,c++)}else i[d]=this.fromASN(s[c],u.type),c++}return{result:i,verified:!0,isManualMapping:!0}}static processRepeatedField(e,n,r){let i=e.slice(n);if(i.length===1&&i[0].constructor.name==="Sequence"){const s=i[0];s.valueBlock&&s.valueBlock.value&&Array.isArray(s.valueBlock.value)&&(i=s.valueBlock.value)}if(typeof r.type=="number"){const s=Ji(r.type);if(!s)throw new Error(`No converter for ASN.1 type ${r.type}`);return i.filter(a=>a&&a.valueBlock).map(a=>{try{return s.fromASN(a)}catch{return}}).filter(a=>a!==void 0)}else return i.filter(s=>s&&s.valueBlock).map(s=>{try{return this.fromASN(s,r.type)}catch{return}}).filter(s=>s!==void 0)}static processPrimitiveField(e,n){const r=Ji(n.type);if(!r)throw new Error(`No converter for ASN.1 type ${n.type}`);return r.fromASN(e)}static isOptionalChoiceField(e){return e.optional&&typeof e.type=="function"&&Je.has(e.type)&&Je.get(e.type).type===B.Choice}static processOptionalChoiceField(e,n){try{return{processed:!0,value:this.fromASN(e,n.type)}}catch(r){if(r instanceof Ui&&/Wrong values for Choice type/.test(r.message))return{processed:!1};throw r}}static handleArrayTypes(e,n,r){if(!("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");const i=n.itemType;if(typeof i=="number"){const s=Ji(i);if(!s)throw new Error(`Cannot get default converter for array item of ${r.name} ASN1 schema`);return r.from(e.valueBlock.value,a=>s.fromASN(a))}else return r.from(e.valueBlock.value,s=>this.fromASN(s,i))}static processSchemaItems(e,n,r){for(const i in e.items){const s=n.result[i];if(!s)continue;const a=e.items[i],c=a.type;typeof c=="number"||xn(c)?r[i]=this.processPrimitiveSchemaItem(s,a,c):r[i]=this.processComplexSchemaItem(s,a,c)}}static processPrimitiveSchemaItem(e,n,r){var i;const s=(i=n.converter)!==null&&i!==void 0?i:xn(r)?new r:null;if(!s)throw new Error("Converter is empty");return n.repeated?this.processRepeatedPrimitiveItem(e,n,s):this.processSinglePrimitiveItem(e,n,r,s)}static processRepeatedPrimitiveItem(e,n,r){if(n.implicit){const i=n.repeated==="sequence"?Jt:dn,s=new i;s.valueBlock=e.valueBlock;const a=Xr(s.toBER(!1));if(a.offset===-1)throw new Error(`Cannot parse the child item. ${a.result.error}`);if(!("value"in a.result.valueBlock&&Array.isArray(a.result.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");const c=a.result.valueBlock.value;return Array.from(c,l=>r.fromASN(l))}else return Array.from(e,i=>r.fromASN(i))}static processSinglePrimitiveItem(e,n,r,i){let s=e;if(n.implicit){let a;if(xn(r))a=new r().toSchema("");else{const c=x[r],l=R_[c];if(!l)throw new Error(`Cannot get '${c}' class from asn1js module`);a=new l}a.valueBlock=s.valueBlock,s=Xr(a.toBER(!1)).result}return i.fromASN(s)}static processComplexSchemaItem(e,n,r){if(n.repeated){if(!Array.isArray(e))throw new Error("Cannot get list of items from the ASN.1 parsed value. ASN.1 value should be iterable.");return Array.from(e,i=>this.fromASN(i,r))}else{const i=this.handleImplicitTagging(e,n,r);if(this.isOptionalChoiceField(n))try{return this.fromASN(i,r)}catch(s){if(s instanceof Ui&&/Wrong values for Choice type/.test(s.message))return;throw s}else return this.fromASN(i,r)}}static handleImplicitTagging(e,n,r){if(n.implicit&&typeof n.context=="number"){const i=Je.get(r);if(i.type===B.Sequence){const s=new Jt;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in s.valueBlock)return s.valueBlock.value=e.valueBlock.value,s}else if(i.type===B.Set){const s=new dn;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in s.valueBlock)return s.valueBlock.value=e.valueBlock.value,s}}return e}}class Fu{static serialize(e){return e instanceof at?e.toBER(!1):this.toASN(e).toBER(!1)}static toASN(e){if(e&&typeof e=="object"&&xn(e))return e.toASN();if(!(e&&typeof e=="object"))throw new TypeError("Parameter 1 should be type of Object.");const n=e.constructor,r=Je.get(n);Je.cache(n);let i=[];if(r.itemType){if(!Array.isArray(e))throw new TypeError("Parameter 1 should be type of Array.");if(typeof r.itemType=="number"){const a=Ji(r.itemType);if(!a)throw new Error(`Cannot get default converter for array item of ${n.name} ASN1 schema`);i=e.map(c=>a.toASN(c))}else i=e.map(a=>this.toAsnItem({type:r.itemType},"[]",n,a))}else for(const a in r.items){const c=r.items[a],l=e[a];if(l===void 0||c.defaultValue===l||typeof c.defaultValue=="object"&&typeof l=="object"&&d3(this.serialize(c.defaultValue),this.serialize(l)))continue;const d=Fu.toAsnItem(c,a,n,l);if(typeof c.context=="number")if(c.implicit)if(!c.repeated&&(typeof c.type=="number"||xn(c.type))){const u={};u.valueHex=d instanceof wr?d.valueBeforeDecodeView:d.valueBlock.toBER(),i.push(new So({optional:c.optional,idBlock:{tagClass:3,tagNumber:c.context},...u}))}else i.push(new yt({optional:c.optional,idBlock:{tagClass:3,tagNumber:c.context},value:d.valueBlock.value}));else i.push(new yt({optional:c.optional,idBlock:{tagClass:3,tagNumber:c.context},value:[d]}));else c.repeated?i=i.concat(d):i.push(d)}let s;switch(r.type){case B.Sequence:s=new Jt({value:i});break;case B.Set:s=new dn({value:i});break;case B.Choice:if(!i[0])throw new Error(`Schema '${n.name}' has wrong data. Choice cannot be empty.`);s=i[0];break}return s}static toAsnItem(e,n,r,i){let s;if(typeof e.type=="number"){const a=e.converter;if(!a)throw new Error(`Property '${n}' doesn't have converter for type ${x[e.type]} in schema '${r.name}'`);if(e.repeated){if(!Array.isArray(i))throw new TypeError("Parameter 'objProp' should be type of Array.");const c=Array.from(i,d=>a.toASN(d)),l=e.repeated==="sequence"?Jt:dn;s=new l({value:c})}else s=a.toASN(i)}else if(e.repeated){if(!Array.isArray(i))throw new TypeError("Parameter 'objProp' should be type of Array.");const a=Array.from(i,l=>this.toASN(l)),c=e.repeated==="sequence"?Jt:dn;s=new c({value:a})}else s=this.toASN(i);return s}}class ze extends Array{constructor(e=[]){if(typeof e=="number")super(e);else{super();for(const n of e)this.push(n)}}}class H{static serialize(e){return Fu.serialize(e)}static parse(e,n){return p3.parse(e,n)}static toString(e){const n=G.isBufferSource(e)?G.toArrayBuffer(e):H.serialize(e),r=Xr(n);if(r.offset===-1)throw new Error(`Cannot decode ASN.1 data. ${r.result.error}`);return r.result.toString()}}function g(t,e,n,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,n):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(t,e,n,r);else for(var c=t.length-1;c>=0;c--)(a=t[c])&&(s=(i<3?a(s):i>3?a(e,n,s):a(e,n))||s);return i>3&&s&&Object.defineProperty(e,n,s),s}class Af{static isIPv4(e){return/^(\d{1,3}\.){3}\d{1,3}$/.test(e)}static parseIPv4(e){const n=e.split(".");if(n.length!==4)throw new Error("Invalid IPv4 address");return n.map(r=>{const i=parseInt(r,10);if(isNaN(i)||i<0||i>255)throw new Error("Invalid IPv4 address part");return i})}static parseIPv6(e){const r=this.expandIPv6(e).split(":");if(r.length!==8)throw new Error("Invalid IPv6 address");return r.reduce((i,s)=>{const a=parseInt(s,16);if(isNaN(a)||a<0||a>65535)throw new Error("Invalid IPv6 address part");return i.push(a>>8&255),i.push(a&255),i},[])}static expandIPv6(e){if(!e.includes("::"))return e;const n=e.split("::");if(n.length>2)throw new Error("Invalid IPv6 address");const r=n[0]?n[0].split(":"):[],i=n[1]?n[1].split(":"):[],s=8-(r.length+i.length);if(s<0)throw new Error("Invalid IPv6 address");return[...r,...Array(s).fill("0"),...i].join(":")}static formatIPv6(e){const n=[];for(let r=0;r<16;r+=2)n.push((e[r]<<8|e[r+1]).toString(16));return this.compressIPv6(n.join(":"))}static compressIPv6(e){const n=e.split(":");let r=-1,i=0,s=-1,a=0;for(let c=0;c<n.length;c++)n[c]==="0"?(s===-1&&(s=c),a++):(a>i&&(r=s,i=a),s=-1,a=0);if(a>i&&(r=s,i=a),i>1){const c=n.slice(0,r).join(":"),l=n.slice(r+i).join(":");return`${c}::${l}`}return e}static parseCIDR(e){const[n,r]=e.split("/"),i=parseInt(r,10);if(this.isIPv4(n)){if(i<0||i>32)throw new Error("Invalid IPv4 prefix length");return[this.parseIPv4(n),i]}else{if(i<0||i>128)throw new Error("Invalid IPv6 prefix length");return[this.parseIPv6(n),i]}}static decodeIP(e){if(e.length===64&&parseInt(e,16)===0)return"::/0";if(e.length!==16)return e;const n=parseInt(e.slice(8),16).toString(2).split("").reduce((i,s)=>i+ +s,0);let r=e.slice(0,8).replace(/(.{2})/g,i=>`${parseInt(i,16)}.`);return r=r.slice(0,-1),`${r}/${n}`}static toString(e){const n=new Uint8Array(e);if(n.length===4)return Array.from(n).join(".");if(n.length===16)return this.formatIPv6(n);if(n.length===8||n.length===32){const r=n.length/2,i=n.slice(0,r),s=n.slice(r);if(n.every(l=>l===0))return n.length===8?"0.0.0.0/0":"::/0";const c=s.reduce((l,d)=>l+(d.toString(2).match(/1/g)||[]).length,0);return n.length===8?`${Array.from(i).join(".")}/${c}`:`${this.formatIPv6(i)}/${c}`}return this.decodeIP(re.ToHex(e))}static fromString(e){if(e.includes("/")){const[r,i]=this.parseCIDR(e),s=new Uint8Array(r.length);let a=i;for(let l=0;l<s.length;l++)a>=8?(s[l]=255,a-=8):a>0&&(s[l]=255<<8-a,a=0);const c=new Uint8Array(r.length*2);return c.set(r,0),c.set(s,r.length),c.buffer}const n=this.isIPv4(e)?this.parseIPv4(e):this.parseIPv6(e);return new Uint8Array(n).buffer}}var Rl,Bl,Ll;let ct=class{constructor(e={}){Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};g([_({type:x.TeletexString})],ct.prototype,"teletexString",void 0);g([_({type:x.PrintableString})],ct.prototype,"printableString",void 0);g([_({type:x.UniversalString})],ct.prototype,"universalString",void 0);g([_({type:x.Utf8String})],ct.prototype,"utf8String",void 0);g([_({type:x.BmpString})],ct.prototype,"bmpString",void 0);ct=g([M({type:B.Choice})],ct);let oi=class extends ct{constructor(e={}){super(e),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?re.ToHex(this.anyValue):super.toString())}};g([_({type:x.IA5String})],oi.prototype,"ia5String",void 0);g([_({type:x.Any})],oi.prototype,"anyValue",void 0);oi=g([M({type:B.Choice})],oi);class ac{constructor(e={}){this.type="",this.value=new oi,Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],ac.prototype,"type",void 0);g([_({type:oi})],ac.prototype,"value",void 0);let si=Rl=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,Rl.prototype)}};si=Rl=g([M({type:B.Set,itemType:ac})],si);let Ul=Bl=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,Bl.prototype)}};Ul=Bl=g([M({type:B.Sequence,itemType:si})],Ul);let Ve=Ll=class extends Ul{constructor(e){super(e),Object.setPrototypeOf(this,Ll.prototype)}};Ve=Ll=g([M({type:B.Sequence})],Ve);const f3={fromASN:t=>Af.toString(Ws.fromASN(t)),toASN:t=>Ws.toASN(Af.fromString(t))};class so{constructor(e={}){this.typeId="",this.value=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],so.prototype,"typeId",void 0);g([_({type:x.Any,context:0})],so.prototype,"value",void 0);class qu{constructor(e={}){this.partyName=new ct,Object.assign(this,e)}}g([_({type:ct,optional:!0,context:0,implicit:!0})],qu.prototype,"nameAssigner",void 0);g([_({type:ct,context:1,implicit:!0})],qu.prototype,"partyName",void 0);let me=class{constructor(e={}){Object.assign(this,e)}};g([_({type:so,context:0,implicit:!0})],me.prototype,"otherName",void 0);g([_({type:x.IA5String,context:1,implicit:!0})],me.prototype,"rfc822Name",void 0);g([_({type:x.IA5String,context:2,implicit:!0})],me.prototype,"dNSName",void 0);g([_({type:x.Any,context:3,implicit:!0})],me.prototype,"x400Address",void 0);g([_({type:Ve,context:4,implicit:!1})],me.prototype,"directoryName",void 0);g([_({type:qu,context:5})],me.prototype,"ediPartyName",void 0);g([_({type:x.IA5String,context:6,implicit:!0})],me.prototype,"uniformResourceIdentifier",void 0);g([_({type:x.OctetString,context:7,implicit:!0,converter:f3})],me.prototype,"iPAddress",void 0);g([_({type:x.ObjectIdentifier,context:8,implicit:!0})],me.prototype,"registeredID",void 0);me=g([M({type:B.Choice})],me);const Hu="1.3.6.1.5.5.7",h3=`${Hu}.1`,ki=`${Hu}.3`,cc=`${Hu}.48`,Ef=`${cc}.1`,Cf=`${cc}.2`,Nf=`${cc}.3`,If=`${cc}.5`,Tn="2.5.29";var Dl;const Ml=`${h3}.1`;class Eo{constructor(e={}){this.accessMethod="",this.accessLocation=new me,Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],Eo.prototype,"accessMethod",void 0);g([_({type:me})],Eo.prototype,"accessLocation",void 0);let Gr=Dl=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,Dl.prototype)}};Gr=Dl=g([M({type:B.Sequence,itemType:Eo})],Gr);const Fl=`${Tn}.35`;class Vu extends ke{}class ur{constructor(e={}){e&&Object.assign(this,e)}}g([_({type:Vu,context:0,optional:!0,implicit:!0})],ur.prototype,"keyIdentifier",void 0);g([_({type:me,context:1,optional:!0,implicit:!0,repeated:"sequence"})],ur.prototype,"authorityCertIssuer",void 0);g([_({type:x.Integer,context:2,optional:!0,implicit:!0,converter:je})],ur.prototype,"authorityCertSerialNumber",void 0);const U_=`${Tn}.19`;class Js{constructor(e={}){this.cA=!1,Object.assign(this,e)}}g([_({type:x.Boolean,defaultValue:!1})],Js.prototype,"cA",void 0);g([_({type:x.Integer,optional:!0})],Js.prototype,"pathLenConstraint",void 0);var ql;let gt=ql=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,ql.prototype)}};gt=ql=g([M({type:B.Sequence,itemType:me})],gt);var Hl;let jf=Hl=class extends gt{constructor(e){super(e),Object.setPrototypeOf(this,Hl.prototype)}};jf=Hl=g([M({type:B.Sequence})],jf);var Vl;const D_=`${Tn}.32`;let Sn=class{constructor(e={}){Object.assign(this,e)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};g([_({type:x.IA5String})],Sn.prototype,"ia5String",void 0);g([_({type:x.VisibleString})],Sn.prototype,"visibleString",void 0);g([_({type:x.BmpString})],Sn.prototype,"bmpString",void 0);g([_({type:x.Utf8String})],Sn.prototype,"utf8String",void 0);Sn=g([M({type:B.Choice})],Sn);class Ku{constructor(e={}){this.organization=new Sn,this.noticeNumbers=[],Object.assign(this,e)}}g([_({type:Sn})],Ku.prototype,"organization",void 0);g([_({type:x.Integer,repeated:"sequence"})],Ku.prototype,"noticeNumbers",void 0);class Gu{constructor(e={}){Object.assign(this,e)}}g([_({type:Ku,optional:!0})],Gu.prototype,"noticeRef",void 0);g([_({type:Sn,optional:!0})],Gu.prototype,"explicitText",void 0);let Xs=class{constructor(e={}){Object.assign(this,e)}};g([_({type:x.IA5String})],Xs.prototype,"cPSuri",void 0);g([_({type:Gu})],Xs.prototype,"userNotice",void 0);Xs=g([M({type:B.Choice})],Xs);class Wu{constructor(e={}){this.policyQualifierId="",this.qualifier=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],Wu.prototype,"policyQualifierId",void 0);g([_({type:x.Any})],Wu.prototype,"qualifier",void 0);class lc{constructor(e={}){this.policyIdentifier="",Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],lc.prototype,"policyIdentifier",void 0);g([_({type:Wu,repeated:"sequence",optional:!0})],lc.prototype,"policyQualifiers",void 0);let Zs=Vl=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,Vl.prototype)}};Zs=Vl=g([M({type:B.Sequence,itemType:lc})],Zs);let Ys=class{constructor(e=0){this.value=e}};g([_({type:x.Integer})],Ys.prototype,"value",void 0);Ys=g([M({type:B.Choice})],Ys);let Of=class extends Ys{};Of=g([M({type:B.Choice})],Of);var Kl;const Gl=`${Tn}.31`;var qt;(function(t){t[t.unused=1]="unused",t[t.keyCompromise=2]="keyCompromise",t[t.cACompromise=4]="cACompromise",t[t.affiliationChanged=8]="affiliationChanged",t[t.superseded=16]="superseded",t[t.cessationOfOperation=32]="cessationOfOperation",t[t.certificateHold=64]="certificateHold",t[t.privilegeWithdrawn=128]="privilegeWithdrawn",t[t.aACompromise=256]="aACompromise"})(qt||(qt={}));class M_ extends sc{toJSON(){const e=[],n=this.toNumber();return n&qt.aACompromise&&e.push("aACompromise"),n&qt.affiliationChanged&&e.push("affiliationChanged"),n&qt.cACompromise&&e.push("cACompromise"),n&qt.certificateHold&&e.push("certificateHold"),n&qt.cessationOfOperation&&e.push("cessationOfOperation"),n&qt.keyCompromise&&e.push("keyCompromise"),n&qt.privilegeWithdrawn&&e.push("privilegeWithdrawn"),n&qt.superseded&&e.push("superseded"),n&qt.unused&&e.push("unused"),e}toString(){return`[${this.toJSON().join(", ")}]`}}let br=class{constructor(e={}){Object.assign(this,e)}};g([_({type:me,context:0,repeated:"sequence",implicit:!0})],br.prototype,"fullName",void 0);g([_({type:si,context:1,implicit:!0})],br.prototype,"nameRelativeToCRLIssuer",void 0);br=g([M({type:B.Choice})],br);class xi{constructor(e={}){Object.assign(this,e)}}g([_({type:br,context:0,optional:!0})],xi.prototype,"distributionPoint",void 0);g([_({type:M_,context:1,optional:!0,implicit:!0})],xi.prototype,"reasons",void 0);g([_({type:me,context:2,optional:!0,repeated:"sequence",implicit:!0})],xi.prototype,"cRLIssuer",void 0);let Zr=Kl=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,Kl.prototype)}};Zr=Kl=g([M({type:B.Sequence,itemType:xi})],Zr);var Wl;let Tf=Wl=class extends Zr{constructor(e){super(e),Object.setPrototypeOf(this,Wl.prototype)}};Tf=Wl=g([M({type:B.Sequence,itemType:xi})],Tf);class ht{constructor(e={}){this.onlyContainsUserCerts=ht.ONLY,this.onlyContainsCACerts=ht.ONLY,this.indirectCRL=ht.ONLY,this.onlyContainsAttributeCerts=ht.ONLY,Object.assign(this,e)}}ht.ONLY=!1;g([_({type:br,context:0,optional:!0})],ht.prototype,"distributionPoint",void 0);g([_({type:x.Boolean,context:1,defaultValue:ht.ONLY,implicit:!0})],ht.prototype,"onlyContainsUserCerts",void 0);g([_({type:x.Boolean,context:2,defaultValue:ht.ONLY,implicit:!0})],ht.prototype,"onlyContainsCACerts",void 0);g([_({type:M_,context:3,optional:!0,implicit:!0})],ht.prototype,"onlySomeReasons",void 0);g([_({type:x.Boolean,context:4,defaultValue:ht.ONLY,implicit:!0})],ht.prototype,"indirectCRL",void 0);g([_({type:x.Boolean,context:5,defaultValue:ht.ONLY,implicit:!0})],ht.prototype,"onlyContainsAttributeCerts",void 0);var Xi;(function(t){t[t.unspecified=0]="unspecified",t[t.keyCompromise=1]="keyCompromise",t[t.cACompromise=2]="cACompromise",t[t.affiliationChanged=3]="affiliationChanged",t[t.superseded=4]="superseded",t[t.cessationOfOperation=5]="cessationOfOperation",t[t.certificateHold=6]="certificateHold",t[t.removeFromCRL=8]="removeFromCRL",t[t.privilegeWithdrawn=9]="privilegeWithdrawn",t[t.aACompromise=10]="aACompromise"})(Xi||(Xi={}));let Jl=class{constructor(e=Xi.unspecified){this.reason=Xi.unspecified,this.reason=e}toJSON(){return Xi[this.reason]}toString(){return this.toJSON()}};g([_({type:x.Enumerated})],Jl.prototype,"reason",void 0);Jl=g([M({type:B.Choice})],Jl);var Xl;const F_=`${Tn}.37`;let Qs=Xl=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,Xl.prototype)}};Qs=Xl=g([M({type:B.Sequence,itemType:x.ObjectIdentifier})],Qs);const g3=`${ki}.1`,m3=`${ki}.2`,_3=`${ki}.3`,y3=`${ki}.4`,w3=`${ki}.8`,v3=`${ki}.9`;let Zl=class{constructor(e=new ArrayBuffer(0)){this.value=e}};g([_({type:x.Integer,converter:je})],Zl.prototype,"value",void 0);Zl=g([M({type:B.Choice})],Zl);let Yl=class{constructor(e){this.value=new Date,e&&(this.value=e)}};g([_({type:x.GeneralizedTime})],Yl.prototype,"value",void 0);Yl=g([M({type:B.Choice})],Yl);var Ql;const q_=`${Tn}.18`;let Pf=Ql=class extends gt{constructor(e){super(e),Object.setPrototypeOf(this,Ql.prototype)}};Pf=Ql=g([M({type:B.Sequence})],Pf);const H_=`${Tn}.15`;var Ht;(function(t){t[t.digitalSignature=1]="digitalSignature",t[t.nonRepudiation=2]="nonRepudiation",t[t.keyEncipherment=4]="keyEncipherment",t[t.dataEncipherment=8]="dataEncipherment",t[t.keyAgreement=16]="keyAgreement",t[t.keyCertSign=32]="keyCertSign",t[t.cRLSign=64]="cRLSign",t[t.encipherOnly=128]="encipherOnly",t[t.decipherOnly=256]="decipherOnly"})(Ht||(Ht={}));class Zc extends sc{toJSON(){const e=this.toNumber(),n=[];return e&Ht.cRLSign&&n.push("crlSign"),e&Ht.dataEncipherment&&n.push("dataEncipherment"),e&Ht.decipherOnly&&n.push("decipherOnly"),e&Ht.digitalSignature&&n.push("digitalSignature"),e&Ht.encipherOnly&&n.push("encipherOnly"),e&Ht.keyAgreement&&n.push("keyAgreement"),e&Ht.keyCertSign&&n.push("keyCertSign"),e&Ht.keyEncipherment&&n.push("keyEncipherment"),e&Ht.nonRepudiation&&n.push("nonRepudiation"),n}toString(){return`[${this.toJSON().join(", ")}]`}}var ed;class dc{constructor(e={}){this.base=new me,this.minimum=0,Object.assign(this,e)}}g([_({type:me})],dc.prototype,"base",void 0);g([_({type:x.Integer,context:0,defaultValue:0,implicit:!0})],dc.prototype,"minimum",void 0);g([_({type:x.Integer,context:1,optional:!0,implicit:!0})],dc.prototype,"maximum",void 0);let ea=ed=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,ed.prototype)}};ea=ed=g([M({type:B.Sequence,itemType:dc})],ea);class V_{constructor(e={}){Object.assign(this,e)}}g([_({type:ea,context:0,optional:!0,implicit:!0})],V_.prototype,"permittedSubtrees",void 0);g([_({type:ea,context:1,optional:!0,implicit:!0})],V_.prototype,"excludedSubtrees",void 0);class K_{constructor(e={}){Object.assign(this,e)}}g([_({type:x.Integer,context:0,implicit:!0,optional:!0,converter:je})],K_.prototype,"requireExplicitPolicy",void 0);g([_({type:x.Integer,context:1,implicit:!0,optional:!0,converter:je})],K_.prototype,"inhibitPolicyMapping",void 0);var td;class Ju{constructor(e={}){this.issuerDomainPolicy="",this.subjectDomainPolicy="",Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],Ju.prototype,"issuerDomainPolicy",void 0);g([_({type:x.ObjectIdentifier})],Ju.prototype,"subjectDomainPolicy",void 0);let Rf=td=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,td.prototype)}};Rf=td=g([M({type:B.Sequence,itemType:Ju})],Rf);var nd;const G_=`${Tn}.17`;let rd=nd=class extends gt{constructor(e){super(e),Object.setPrototypeOf(this,nd.prototype)}};rd=nd=g([M({type:B.Sequence})],rd);let zn=class{constructor(e={}){this.type="",this.values=[],Object.assign(this,e)}};g([_({type:x.ObjectIdentifier})],zn.prototype,"type",void 0);g([_({type:x.Any,repeated:"set"})],zn.prototype,"values",void 0);var id;let Bf=id=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,id.prototype)}};Bf=id=g([M({type:B.Sequence,itemType:zn})],Bf);const W_=`${Tn}.14`;class Vn extends Vu{}class J_{constructor(e={}){Object.assign(this,e)}}g([_({type:x.GeneralizedTime,context:0,implicit:!0,optional:!0})],J_.prototype,"notBefore",void 0);g([_({type:x.GeneralizedTime,context:1,implicit:!0,optional:!0})],J_.prototype,"notAfter",void 0);var Zi;(function(t){t[t.keyUpdateAllowed=1]="keyUpdateAllowed",t[t.newExtensions=2]="newExtensions",t[t.pKIXCertificate=4]="pKIXCertificate"})(Zi||(Zi={}));class X_ extends sc{toJSON(){const e=[],n=this.toNumber();return n&Zi.pKIXCertificate&&e.push("pKIXCertificate"),n&Zi.newExtensions&&e.push("newExtensions"),n&Zi.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}}class Z_{constructor(e={}){this.entrustVers="",this.entrustInfoFlags=new X_,Object.assign(this,e)}}g([_({type:x.GeneralString})],Z_.prototype,"entrustVers",void 0);g([_({type:X_})],Z_.prototype,"entrustInfoFlags",void 0);var od;let Lf=od=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,od.prototype)}};Lf=od=g([M({type:B.Sequence,itemType:Eo})],Lf);class X{constructor(e={}){this.algorithm="",Object.assign(this,e)}isEqual(e){return e instanceof X&&e.algorithm==this.algorithm&&(e.parameters&&this.parameters&&Dm(e.parameters,this.parameters)||e.parameters===this.parameters)}}g([_({type:x.ObjectIdentifier})],X.prototype,"algorithm",void 0);g([_({type:x.Any,optional:!0})],X.prototype,"parameters",void 0);class Gt{constructor(e={}){this.algorithm=new X,this.subjectPublicKey=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:X})],Gt.prototype,"algorithm",void 0);g([_({type:x.BitString})],Gt.prototype,"subjectPublicKey",void 0);let ot=class{constructor(e){if(e)if(typeof e=="string"||typeof e=="number"||e instanceof Date){const n=new Date(e);n.getUTCFullYear()>2049?this.generalTime=n:this.utcTime=n}else Object.assign(this,e)}getTime(){const e=this.utcTime||this.generalTime;if(!e)throw new Error("Cannot get time from CHOICE object");return e}};g([_({type:x.UTCTime})],ot.prototype,"utcTime",void 0);g([_({type:x.GeneralizedTime})],ot.prototype,"generalTime",void 0);ot=g([M({type:B.Choice})],ot);class Co{constructor(e){this.notBefore=new ot(new Date),this.notAfter=new ot(new Date),e&&(this.notBefore=new ot(e.notBefore),this.notAfter=new ot(e.notAfter))}}g([_({type:ot})],Co.prototype,"notBefore",void 0);g([_({type:ot})],Co.prototype,"notAfter",void 0);var sd;let Ut=class Y_{constructor(e={}){this.extnID="",this.critical=Y_.CRITICAL,this.extnValue=new ke,Object.assign(this,e)}};Ut.CRITICAL=!1;g([_({type:x.ObjectIdentifier})],Ut.prototype,"extnID",void 0);g([_({type:x.Boolean,defaultValue:Ut.CRITICAL})],Ut.prototype,"critical",void 0);g([_({type:ke})],Ut.prototype,"extnValue",void 0);let Wn=sd=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,sd.prototype)}};Wn=sd=g([M({type:B.Sequence,itemType:Ut})],Wn);var $r;(function(t){t[t.v1=0]="v1",t[t.v2=1]="v2",t[t.v3=2]="v3"})($r||($r={}));class Ot{constructor(e={}){this.version=$r.v1,this.serialNumber=new ArrayBuffer(0),this.signature=new X,this.issuer=new Ve,this.validity=new Co,this.subject=new Ve,this.subjectPublicKeyInfo=new Gt,Object.assign(this,e)}}g([_({type:x.Integer,context:0,defaultValue:$r.v1})],Ot.prototype,"version",void 0);g([_({type:x.Integer,converter:je})],Ot.prototype,"serialNumber",void 0);g([_({type:X})],Ot.prototype,"signature",void 0);g([_({type:Ve})],Ot.prototype,"issuer",void 0);g([_({type:Co})],Ot.prototype,"validity",void 0);g([_({type:Ve})],Ot.prototype,"subject",void 0);g([_({type:Gt})],Ot.prototype,"subjectPublicKeyInfo",void 0);g([_({type:x.BitString,context:1,implicit:!0,optional:!0})],Ot.prototype,"issuerUniqueID",void 0);g([_({type:x.BitString,context:2,implicit:!0,optional:!0})],Ot.prototype,"subjectUniqueID",void 0);g([_({type:Wn,context:3,optional:!0})],Ot.prototype,"extensions",void 0);class kr{constructor(e={}){this.tbsCertificate=new Ot,this.signatureAlgorithm=new X,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:Ot})],kr.prototype,"tbsCertificate",void 0);g([_({type:X})],kr.prototype,"signatureAlgorithm",void 0);g([_({type:x.BitString})],kr.prototype,"signatureValue",void 0);class uc{constructor(e={}){this.userCertificate=new ArrayBuffer(0),this.revocationDate=new ot,Object.assign(this,e)}}g([_({type:x.Integer,converter:je})],uc.prototype,"userCertificate",void 0);g([_({type:ot})],uc.prototype,"revocationDate",void 0);g([_({type:Ut,optional:!0,repeated:"sequence"})],uc.prototype,"crlEntryExtensions",void 0);class Pn{constructor(e={}){this.signature=new X,this.issuer=new Ve,this.thisUpdate=new ot,Object.assign(this,e)}}g([_({type:x.Integer,optional:!0})],Pn.prototype,"version",void 0);g([_({type:X})],Pn.prototype,"signature",void 0);g([_({type:Ve})],Pn.prototype,"issuer",void 0);g([_({type:ot})],Pn.prototype,"thisUpdate",void 0);g([_({type:ot,optional:!0})],Pn.prototype,"nextUpdate",void 0);g([_({type:uc,repeated:"sequence",optional:!0})],Pn.prototype,"revokedCertificates",void 0);g([_({type:Ut,optional:!0,context:0,repeated:"sequence"})],Pn.prototype,"crlExtensions",void 0);class Xu{constructor(e={}){this.tbsCertList=new Pn,this.signatureAlgorithm=new X,this.signature=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:Pn})],Xu.prototype,"tbsCertList",void 0);g([_({type:X})],Xu.prototype,"signatureAlgorithm",void 0);g([_({type:x.BitString})],Xu.prototype,"signature",void 0);class Si{constructor(e={}){this.issuer=new Ve,this.serialNumber=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:Ve})],Si.prototype,"issuer",void 0);g([_({type:x.Integer,converter:je})],Si.prototype,"serialNumber",void 0);let ai=class{constructor(e={}){Object.assign(this,e)}};g([_({type:Vn,context:0,implicit:!0})],ai.prototype,"subjectKeyIdentifier",void 0);g([_({type:Si})],ai.prototype,"issuerAndSerialNumber",void 0);ai=g([M({type:B.Choice})],ai);var An;(function(t){t[t.v0=0]="v0",t[t.v1=1]="v1",t[t.v2=2]="v2",t[t.v3=3]="v3",t[t.v4=4]="v4",t[t.v5=5]="v5"})(An||(An={}));let ao=class extends X{};ao=g([M({type:B.Sequence})],ao);let ta=class extends X{};ta=g([M({type:B.Sequence})],ta);let pn=class extends X{};pn=g([M({type:B.Sequence})],pn);let na=class extends X{};na=g([M({type:B.Sequence})],na);let Uf=class extends X{};Uf=g([M({type:B.Sequence})],Uf);let ad=class extends X{};ad=g([M({type:B.Sequence})],ad);let zi=class{constructor(e={}){this.attrType="",this.attrValues=[],Object.assign(this,e)}};g([_({type:x.ObjectIdentifier})],zi.prototype,"attrType",void 0);g([_({type:x.Any,repeated:"set"})],zi.prototype,"attrValues",void 0);var cd;class gn{constructor(e={}){this.version=An.v0,this.sid=new ai,this.digestAlgorithm=new ao,this.signatureAlgorithm=new ta,this.signature=new ke,Object.assign(this,e)}}g([_({type:x.Integer})],gn.prototype,"version",void 0);g([_({type:ai})],gn.prototype,"sid",void 0);g([_({type:ao})],gn.prototype,"digestAlgorithm",void 0);g([_({type:zi,repeated:"set",context:0,implicit:!0,optional:!0})],gn.prototype,"signedAttrs",void 0);g([_({type:ta})],gn.prototype,"signatureAlgorithm",void 0);g([_({type:ke})],gn.prototype,"signature",void 0);g([_({type:zi,repeated:"set",context:1,implicit:!0,optional:!0})],gn.prototype,"unsignedAttrs",void 0);let ra=cd=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,cd.prototype)}};ra=cd=g([M({type:B.Set,itemType:gn})],ra);let Df=class extends ot{};Df=g([M({type:B.Choice})],Df);let Mf=class extends gn{};Mf=g([M({type:B.Sequence})],Mf);class Zu{constructor(e={}){this.acIssuer=new me,this.acSerial=0,this.attrs=[],Object.assign(this,e)}}g([_({type:me})],Zu.prototype,"acIssuer",void 0);g([_({type:x.Integer})],Zu.prototype,"acSerial",void 0);g([_({type:zn,repeated:"sequence"})],Zu.prototype,"attrs",void 0);var ld;let ia=ld=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,ld.prototype)}};ia=ld=g([M({type:B.Sequence,itemType:x.ObjectIdentifier})],ia);class pc{constructor(e={}){this.permitUnSpecified=!0,Object.assign(this,e)}}g([_({type:x.Integer,optional:!0})],pc.prototype,"pathLenConstraint",void 0);g([_({type:ia,implicit:!0,context:0,optional:!0})],pc.prototype,"permittedAttrs",void 0);g([_({type:ia,implicit:!0,context:1,optional:!0})],pc.prototype,"excludedAttrs",void 0);g([_({type:x.Boolean,defaultValue:!0})],pc.prototype,"permitUnSpecified",void 0);class Tr{constructor(e={}){this.issuer=new gt,this.serial=new ArrayBuffer(0),this.issuerUID=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:gt})],Tr.prototype,"issuer",void 0);g([_({type:x.Integer,converter:je})],Tr.prototype,"serial",void 0);g([_({type:x.BitString,optional:!0})],Tr.prototype,"issuerUID",void 0);var dd;(function(t){t[t.publicKey=0]="publicKey",t[t.publicKeyCert=1]="publicKeyCert",t[t.otherObjectTypes=2]="otherObjectTypes"})(dd||(dd={}));class Pr{constructor(e={}){this.digestedObjectType=dd.publicKey,this.digestAlgorithm=new X,this.objectDigest=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.Enumerated})],Pr.prototype,"digestedObjectType",void 0);g([_({type:x.ObjectIdentifier,optional:!0})],Pr.prototype,"otherObjectTypeID",void 0);g([_({type:X})],Pr.prototype,"digestAlgorithm",void 0);g([_({type:x.BitString})],Pr.prototype,"objectDigest",void 0);class fc{constructor(e={}){Object.assign(this,e)}}g([_({type:gt,optional:!0})],fc.prototype,"issuerName",void 0);g([_({type:Tr,context:0,implicit:!0,optional:!0})],fc.prototype,"baseCertificateID",void 0);g([_({type:Pr,context:1,implicit:!0,optional:!0})],fc.prototype,"objectDigestInfo",void 0);let ci=class{constructor(e={}){Object.assign(this,e)}};g([_({type:me,repeated:"sequence"})],ci.prototype,"v1Form",void 0);g([_({type:fc,context:0,implicit:!0})],ci.prototype,"v2Form",void 0);ci=g([M({type:B.Choice})],ci);class hc{constructor(e={}){this.notBeforeTime=new Date,this.notAfterTime=new Date,Object.assign(this,e)}}g([_({type:x.GeneralizedTime})],hc.prototype,"notBeforeTime",void 0);g([_({type:x.GeneralizedTime})],hc.prototype,"notAfterTime",void 0);class No{constructor(e={}){Object.assign(this,e)}}g([_({type:Tr,implicit:!0,context:0,optional:!0})],No.prototype,"baseCertificateID",void 0);g([_({type:gt,implicit:!0,context:1,optional:!0})],No.prototype,"entityName",void 0);g([_({type:Pr,implicit:!0,context:2,optional:!0})],No.prototype,"objectDigestInfo",void 0);var ud;(function(t){t[t.v2=1]="v2"})(ud||(ud={}));class nn{constructor(e={}){this.version=ud.v2,this.holder=new No,this.issuer=new ci,this.signature=new X,this.serialNumber=new ArrayBuffer(0),this.attrCertValidityPeriod=new hc,this.attributes=[],Object.assign(this,e)}}g([_({type:x.Integer})],nn.prototype,"version",void 0);g([_({type:No})],nn.prototype,"holder",void 0);g([_({type:ci})],nn.prototype,"issuer",void 0);g([_({type:X})],nn.prototype,"signature",void 0);g([_({type:x.Integer,converter:je})],nn.prototype,"serialNumber",void 0);g([_({type:hc})],nn.prototype,"attrCertValidityPeriod",void 0);g([_({type:zn,repeated:"sequence"})],nn.prototype,"attributes",void 0);g([_({type:x.BitString,optional:!0})],nn.prototype,"issuerUniqueID",void 0);g([_({type:Wn,optional:!0})],nn.prototype,"extensions",void 0);class gc{constructor(e={}){this.acinfo=new nn,this.signatureAlgorithm=new X,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:nn})],gc.prototype,"acinfo",void 0);g([_({type:X})],gc.prototype,"signatureAlgorithm",void 0);g([_({type:x.BitString})],gc.prototype,"signatureValue",void 0);var oa;(function(t){t[t.unmarked=1]="unmarked",t[t.unclassified=2]="unclassified",t[t.restricted=4]="restricted",t[t.confidential=8]="confidential",t[t.secret=16]="secret",t[t.topSecret=32]="topSecret"})(oa||(oa={}));class pd extends sc{}class Yu{constructor(e={}){this.type="",this.value=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.ObjectIdentifier,implicit:!0,context:0})],Yu.prototype,"type",void 0);g([_({type:x.Any,implicit:!0,context:1})],Yu.prototype,"value",void 0);class Qu{constructor(e={}){this.policyId="",this.classList=new pd(oa.unclassified),Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],Qu.prototype,"policyId",void 0);g([_({type:pd,defaultValue:new pd(oa.unclassified)})],Qu.prototype,"classList",void 0);g([_({type:Yu,repeated:"set"})],Qu.prototype,"securityCategories",void 0);class mc{constructor(e={}){Object.assign(this,e)}}g([_({type:ke})],mc.prototype,"cotets",void 0);g([_({type:x.ObjectIdentifier})],mc.prototype,"oid",void 0);g([_({type:x.Utf8String})],mc.prototype,"string",void 0);class Q_{constructor(e={}){this.values=[],Object.assign(this,e)}}g([_({type:gt,implicit:!0,context:0,optional:!0})],Q_.prototype,"policyAuthority",void 0);g([_({type:mc,repeated:"sequence"})],Q_.prototype,"values",void 0);var fd;class _c{constructor(e={}){this.targetCertificate=new Tr,Object.assign(this,e)}}g([_({type:Tr})],_c.prototype,"targetCertificate",void 0);g([_({type:me,optional:!0})],_c.prototype,"targetName",void 0);g([_({type:Pr,optional:!0})],_c.prototype,"certDigestInfo",void 0);let li=class{constructor(e={}){Object.assign(this,e)}};g([_({type:me,context:0,implicit:!0})],li.prototype,"targetName",void 0);g([_({type:me,context:1,implicit:!0})],li.prototype,"targetGroup",void 0);g([_({type:_c,context:2,implicit:!0})],li.prototype,"targetCert",void 0);li=g([M({type:B.Choice})],li);let hd=fd=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,fd.prototype)}};hd=fd=g([M({type:B.Sequence,itemType:li})],hd);var gd;let Ff=gd=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,gd.prototype)}};Ff=gd=g([M({type:B.Sequence,itemType:hd})],Ff);class ey{constructor(e={}){Object.assign(this,e)}}g([_({type:gt,implicit:!0,context:0,optional:!0})],ey.prototype,"roleAuthority",void 0);g([_({type:me,implicit:!0,context:1})],ey.prototype,"roleName",void 0);class ep{constructor(e={}){this.service=new me,this.ident=new me,Object.assign(this,e)}}g([_({type:me})],ep.prototype,"service",void 0);g([_({type:me})],ep.prototype,"ident",void 0);g([_({type:ke,optional:!0})],ep.prototype,"authInfo",void 0);var md;class tp{constructor(e={}){this.otherCertFormat="",this.otherCert=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],tp.prototype,"otherCertFormat",void 0);g([_({type:x.Any})],tp.prototype,"otherCert",void 0);let di=class{constructor(e={}){Object.assign(this,e)}};g([_({type:kr})],di.prototype,"certificate",void 0);g([_({type:gc,context:2,implicit:!0})],di.prototype,"v2AttrCert",void 0);g([_({type:tp,context:3,implicit:!0})],di.prototype,"other",void 0);di=g([M({type:B.Choice})],di);let sa=md=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,md.prototype)}};sa=md=g([M({type:B.Set,itemType:di})],sa);class Ai{constructor(e={}){this.contentType="",this.content=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],Ai.prototype,"contentType",void 0);g([_({type:x.Any,context:0})],Ai.prototype,"content",void 0);let co=class{constructor(e={}){Object.assign(this,e)}};g([_({type:ke})],co.prototype,"single",void 0);g([_({type:x.Any})],co.prototype,"any",void 0);co=g([M({type:B.Choice})],co);class yc{constructor(e={}){this.eContentType="",Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],yc.prototype,"eContentType",void 0);g([_({type:co,context:0,optional:!0})],yc.prototype,"eContent",void 0);let lo=class{constructor(e={}){Object.assign(this,e)}};g([_({type:ke,context:0,implicit:!0,optional:!0})],lo.prototype,"value",void 0);g([_({type:ke,converter:Jb,context:0,implicit:!0,optional:!0,repeated:"sequence"})],lo.prototype,"constructedValue",void 0);lo=g([M({type:B.Choice})],lo);class Io{constructor(e={}){this.contentType="",this.contentEncryptionAlgorithm=new na,Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],Io.prototype,"contentType",void 0);g([_({type:na})],Io.prototype,"contentEncryptionAlgorithm",void 0);g([_({type:lo,optional:!0})],Io.prototype,"encryptedContent",void 0);class wc{constructor(e={}){this.keyAttrId="",Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],wc.prototype,"keyAttrId",void 0);g([_({type:x.Any,optional:!0})],wc.prototype,"keyAttr",void 0);var _d;class vc{constructor(e={}){this.subjectKeyIdentifier=new Vn,Object.assign(this,e)}}g([_({type:Vn})],vc.prototype,"subjectKeyIdentifier",void 0);g([_({type:x.GeneralizedTime,optional:!0})],vc.prototype,"date",void 0);g([_({type:wc,optional:!0})],vc.prototype,"other",void 0);let ui=class{constructor(e={}){Object.assign(this,e)}};g([_({type:vc,context:0,implicit:!0,optional:!0})],ui.prototype,"rKeyId",void 0);g([_({type:Si,optional:!0})],ui.prototype,"issuerAndSerialNumber",void 0);ui=g([M({type:B.Choice})],ui);class np{constructor(e={}){this.rid=new ui,this.encryptedKey=new ke,Object.assign(this,e)}}g([_({type:ui})],np.prototype,"rid",void 0);g([_({type:ke})],np.prototype,"encryptedKey",void 0);let aa=_d=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,_d.prototype)}};aa=_d=g([M({type:B.Sequence,itemType:np})],aa);class rp{constructor(e={}){this.algorithm=new X,this.publicKey=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:X})],rp.prototype,"algorithm",void 0);g([_({type:x.BitString})],rp.prototype,"publicKey",void 0);let xr=class{constructor(e={}){Object.assign(this,e)}};g([_({type:Vn,context:0,implicit:!0,optional:!0})],xr.prototype,"subjectKeyIdentifier",void 0);g([_({type:rp,context:1,implicit:!0,optional:!0})],xr.prototype,"originatorKey",void 0);g([_({type:Si,optional:!0})],xr.prototype,"issuerAndSerialNumber",void 0);xr=g([M({type:B.Choice})],xr);class Ei{constructor(e={}){this.version=An.v3,this.originator=new xr,this.keyEncryptionAlgorithm=new pn,this.recipientEncryptedKeys=new aa,Object.assign(this,e)}}g([_({type:x.Integer})],Ei.prototype,"version",void 0);g([_({type:xr,context:0})],Ei.prototype,"originator",void 0);g([_({type:ke,context:1,optional:!0})],Ei.prototype,"ukm",void 0);g([_({type:pn})],Ei.prototype,"keyEncryptionAlgorithm",void 0);g([_({type:aa})],Ei.prototype,"recipientEncryptedKeys",void 0);let pi=class{constructor(e={}){Object.assign(this,e)}};g([_({type:Vn,context:0,implicit:!0})],pi.prototype,"subjectKeyIdentifier",void 0);g([_({type:Si})],pi.prototype,"issuerAndSerialNumber",void 0);pi=g([M({type:B.Choice})],pi);class jo{constructor(e={}){this.version=An.v0,this.rid=new pi,this.keyEncryptionAlgorithm=new pn,this.encryptedKey=new ke,Object.assign(this,e)}}g([_({type:x.Integer})],jo.prototype,"version",void 0);g([_({type:pi})],jo.prototype,"rid",void 0);g([_({type:pn})],jo.prototype,"keyEncryptionAlgorithm",void 0);g([_({type:ke})],jo.prototype,"encryptedKey",void 0);class Oo{constructor(e={}){this.keyIdentifier=new ke,Object.assign(this,e)}}g([_({type:ke})],Oo.prototype,"keyIdentifier",void 0);g([_({type:x.GeneralizedTime,optional:!0})],Oo.prototype,"date",void 0);g([_({type:wc,optional:!0})],Oo.prototype,"other",void 0);class To{constructor(e={}){this.version=An.v4,this.kekid=new Oo,this.keyEncryptionAlgorithm=new pn,this.encryptedKey=new ke,Object.assign(this,e)}}g([_({type:x.Integer})],To.prototype,"version",void 0);g([_({type:Oo})],To.prototype,"kekid",void 0);g([_({type:pn})],To.prototype,"keyEncryptionAlgorithm",void 0);g([_({type:ke})],To.prototype,"encryptedKey",void 0);class Po{constructor(e={}){this.version=An.v0,this.keyEncryptionAlgorithm=new pn,this.encryptedKey=new ke,Object.assign(this,e)}}g([_({type:x.Integer})],Po.prototype,"version",void 0);g([_({type:ad,context:0,optional:!0})],Po.prototype,"keyDerivationAlgorithm",void 0);g([_({type:pn})],Po.prototype,"keyEncryptionAlgorithm",void 0);g([_({type:ke})],Po.prototype,"encryptedKey",void 0);class ip{constructor(e={}){this.oriType="",this.oriValue=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],ip.prototype,"oriType",void 0);g([_({type:x.Any})],ip.prototype,"oriValue",void 0);let Jn=class{constructor(e={}){Object.assign(this,e)}};g([_({type:jo,optional:!0})],Jn.prototype,"ktri",void 0);g([_({type:Ei,context:1,implicit:!0,optional:!0})],Jn.prototype,"kari",void 0);g([_({type:To,context:2,implicit:!0,optional:!0})],Jn.prototype,"kekri",void 0);g([_({type:Po,context:3,implicit:!0,optional:!0})],Jn.prototype,"pwri",void 0);g([_({type:ip,context:4,implicit:!0,optional:!0})],Jn.prototype,"ori",void 0);Jn=g([M({type:B.Choice})],Jn);var yd;let ca=yd=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,yd.prototype)}};ca=yd=g([M({type:B.Set,itemType:Jn})],ca);var wd;class bc{constructor(e={}){this.otherRevInfoFormat="",this.otherRevInfo=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],bc.prototype,"otherRevInfoFormat",void 0);g([_({type:x.Any})],bc.prototype,"otherRevInfo",void 0);let la=class{constructor(e={}){this.other=new bc,Object.assign(this,e)}};g([_({type:bc,context:1,implicit:!0})],la.prototype,"other",void 0);la=g([M({type:B.Choice})],la);let da=wd=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,wd.prototype)}};da=wd=g([M({type:B.Set,itemType:la})],da);class op{constructor(e={}){Object.assign(this,e)}}g([_({type:sa,context:0,implicit:!0,optional:!0})],op.prototype,"certs",void 0);g([_({type:da,context:1,implicit:!0,optional:!0})],op.prototype,"crls",void 0);var vd;let bd=vd=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,vd.prototype)}};bd=vd=g([M({type:B.Set,itemType:zi})],bd);class Ro{constructor(e={}){this.version=An.v0,this.recipientInfos=new ca,this.encryptedContentInfo=new Io,Object.assign(this,e)}}g([_({type:x.Integer})],Ro.prototype,"version",void 0);g([_({type:op,context:0,implicit:!0,optional:!0})],Ro.prototype,"originatorInfo",void 0);g([_({type:ca})],Ro.prototype,"recipientInfos",void 0);g([_({type:Io})],Ro.prototype,"encryptedContentInfo",void 0);g([_({type:bd,context:1,implicit:!0,optional:!0})],Ro.prototype,"unprotectedAttrs",void 0);const b3="1.2.840.113549.1.7.2";var $d;let ua=$d=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,$d.prototype)}};ua=$d=g([M({type:B.Set,itemType:ao})],ua);class Ci{constructor(e={}){this.version=An.v0,this.digestAlgorithms=new ua,this.encapContentInfo=new yc,this.signerInfos=new ra,Object.assign(this,e)}}g([_({type:x.Integer})],Ci.prototype,"version",void 0);g([_({type:ua})],Ci.prototype,"digestAlgorithms",void 0);g([_({type:yc})],Ci.prototype,"encapContentInfo",void 0);g([_({type:sa,context:0,implicit:!0,optional:!0})],Ci.prototype,"certificates",void 0);g([_({type:da,context:1,implicit:!0,optional:!0})],Ci.prototype,"crls",void 0);g([_({type:ra})],Ci.prototype,"signerInfos",void 0);const uo="1.2.840.10045.2.1",sp="1.2.840.10045.4.1",ty="1.2.840.10045.4.3.1",ap="1.2.840.10045.4.3.2",cp="1.2.840.10045.4.3.3",lp="1.2.840.10045.4.3.4",qf="1.2.840.10045.3.1.7",Hf="1.3.132.0.34",Vf="1.3.132.0.35";function Bo(t){return new X({algorithm:t})}const $3=Bo(sp);Bo(ty);const k3=Bo(ap),x3=Bo(cp),S3=Bo(lp);let po=class{constructor(e={}){Object.assign(this,e)}};g([_({type:x.ObjectIdentifier})],po.prototype,"fieldType",void 0);g([_({type:x.Any})],po.prototype,"parameters",void 0);po=g([M({type:B.Sequence})],po);class z3 extends ke{}let fi=class{constructor(e={}){Object.assign(this,e)}};g([_({type:x.OctetString})],fi.prototype,"a",void 0);g([_({type:x.OctetString})],fi.prototype,"b",void 0);g([_({type:x.BitString,optional:!0})],fi.prototype,"seed",void 0);fi=g([M({type:B.Sequence})],fi);var kd;(function(t){t[t.ecpVer1=1]="ecpVer1"})(kd||(kd={}));let En=class{constructor(e={}){this.version=kd.ecpVer1,Object.assign(this,e)}};g([_({type:x.Integer})],En.prototype,"version",void 0);g([_({type:po})],En.prototype,"fieldID",void 0);g([_({type:fi})],En.prototype,"curve",void 0);g([_({type:z3})],En.prototype,"base",void 0);g([_({type:x.Integer,converter:je})],En.prototype,"order",void 0);g([_({type:x.Integer,optional:!0})],En.prototype,"cofactor",void 0);En=g([M({type:B.Sequence})],En);let Xn=class{constructor(e={}){Object.assign(this,e)}};g([_({type:x.ObjectIdentifier})],Xn.prototype,"namedCurve",void 0);g([_({type:x.Null})],Xn.prototype,"implicitCurve",void 0);g([_({type:En})],Xn.prototype,"specifiedCurve",void 0);Xn=g([M({type:B.Choice})],Xn);class $c{constructor(e={}){this.version=1,this.privateKey=new ke,Object.assign(this,e)}}g([_({type:x.Integer})],$c.prototype,"version",void 0);g([_({type:ke})],$c.prototype,"privateKey",void 0);g([_({type:Xn,context:0,optional:!0})],$c.prototype,"parameters",void 0);g([_({type:x.BitString,context:1,optional:!0})],$c.prototype,"publicKey",void 0);class pa{constructor(e={}){this.r=new ArrayBuffer(0),this.s=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.Integer,converter:je})],pa.prototype,"r",void 0);g([_({type:x.Integer,converter:je})],pa.prototype,"s",void 0);const zt="1.2.840.113549.1.1",Sr=`${zt}.1`,A3=`${zt}.7`,E3=`${zt}.9`,Yi=`${zt}.10`,C3=`${zt}.2`,N3=`${zt}.4`,fa=`${zt}.5`,I3=`${zt}.14`,xd=`${zt}.11`,ha=`${zt}.12`,ga=`${zt}.13`,ny=`${zt}.15`,ry=`${zt}.16`,ma="1.3.14.3.2.26",iy="2.16.840.1.101.3.4.2.4",_a="2.16.840.1.101.3.4.2.1",ya="2.16.840.1.101.3.4.2.2",wa="2.16.840.1.101.3.4.2.3",j3="2.16.840.1.101.3.4.2.5",O3="2.16.840.1.101.3.4.2.6",T3="1.2.840.113549.2.2",P3="1.2.840.113549.2.5",kc=`${zt}.8`;function Xe(t){return new X({algorithm:t,parameters:null})}Xe(T3);Xe(P3);const zr=Xe(ma);Xe(iy);Xe(_a);Xe(ya);Xe(wa);Xe(j3);Xe(O3);const oy=new X({algorithm:kc,parameters:H.serialize(zr)}),sy=new X({algorithm:E3,parameters:H.serialize(Ws.toASN(new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer))});Xe(Sr);Xe(C3);Xe(N3);Xe(fa);Xe(ny);Xe(ry);Xe(ha);Xe(ga);Xe(ny);Xe(ry);class xc{constructor(e={}){this.hashAlgorithm=new X(zr),this.maskGenAlgorithm=new X({algorithm:kc,parameters:H.serialize(zr)}),this.pSourceAlgorithm=new X(sy),Object.assign(this,e)}}g([_({type:X,context:0,defaultValue:zr})],xc.prototype,"hashAlgorithm",void 0);g([_({type:X,context:1,defaultValue:oy})],xc.prototype,"maskGenAlgorithm",void 0);g([_({type:X,context:2,defaultValue:sy})],xc.prototype,"pSourceAlgorithm",void 0);new X({algorithm:A3,parameters:H.serialize(new xc)});class Ar{constructor(e={}){this.hashAlgorithm=new X(zr),this.maskGenAlgorithm=new X({algorithm:kc,parameters:H.serialize(zr)}),this.saltLength=20,this.trailerField=1,Object.assign(this,e)}}g([_({type:X,context:0,defaultValue:zr})],Ar.prototype,"hashAlgorithm",void 0);g([_({type:X,context:1,defaultValue:oy})],Ar.prototype,"maskGenAlgorithm",void 0);g([_({type:x.Integer,context:2,defaultValue:20})],Ar.prototype,"saltLength",void 0);g([_({type:x.Integer,context:3,defaultValue:1})],Ar.prototype,"trailerField",void 0);new X({algorithm:Yi,parameters:H.serialize(new Ar)});class Sc{constructor(e={}){this.digestAlgorithm=new X,this.digest=new ke,Object.assign(this,e)}}g([_({type:X})],Sc.prototype,"digestAlgorithm",void 0);g([_({type:ke})],Sc.prototype,"digest",void 0);var Sd;class zc{constructor(e={}){this.prime=new ArrayBuffer(0),this.exponent=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.Integer,converter:je})],zc.prototype,"prime",void 0);g([_({type:x.Integer,converter:je})],zc.prototype,"exponent",void 0);g([_({type:x.Integer,converter:je})],zc.prototype,"coefficient",void 0);let zd=Sd=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,Sd.prototype)}};zd=Sd=g([M({type:B.Sequence,itemType:zc})],zd);class mn{constructor(e={}){this.version=0,this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),this.privateExponent=new ArrayBuffer(0),this.prime1=new ArrayBuffer(0),this.prime2=new ArrayBuffer(0),this.exponent1=new ArrayBuffer(0),this.exponent2=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.Integer})],mn.prototype,"version",void 0);g([_({type:x.Integer,converter:je})],mn.prototype,"modulus",void 0);g([_({type:x.Integer,converter:je})],mn.prototype,"publicExponent",void 0);g([_({type:x.Integer,converter:je})],mn.prototype,"privateExponent",void 0);g([_({type:x.Integer,converter:je})],mn.prototype,"prime1",void 0);g([_({type:x.Integer,converter:je})],mn.prototype,"prime2",void 0);g([_({type:x.Integer,converter:je})],mn.prototype,"exponent1",void 0);g([_({type:x.Integer,converter:je})],mn.prototype,"exponent2",void 0);g([_({type:x.Integer,converter:je})],mn.prototype,"coefficient",void 0);g([_({type:zd,optional:!0})],mn.prototype,"otherPrimeInfos",void 0);class dp{constructor(e={}){this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.Integer,converter:je})],dp.prototype,"modulus",void 0);g([_({type:x.Integer,converter:je})],dp.prototype,"publicExponent",void 0);var Ad;(function(t){t[t.Transient=0]="Transient",t[t.Singleton=1]="Singleton",t[t.ResolutionScoped=2]="ResolutionScoped",t[t.ContainerScoped=3]="ContainerScoped"})(Ad||(Ad={}));const $t=Ad;/*! *****************************************************************************
146
+ `)}`:`${n} :`}}Jm=yt;Y.Constructed=Jm;yt.NAME="CONSTRUCTED";class Xm extends wt{fromBER(e,n,r){return n}toBER(e){return en}}Xm.override="EndOfContentValueBlock";var Zm;class ju extends at{constructor(e={}){super(e,Xm),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}}Zm=ju;Y.EndOfContent=Zm;ju.NAME=oo;var Ym;class wr extends at{constructor(e={}){super(e,wt),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,n,r){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=r,n+r>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):n+r}toBER(e,n){const r=new ArrayBuffer(2);if(!e){const i=new Uint8Array(r);i[0]=5,i[1]=0}return n&&n.write(r),r}onAsciiEncoding(){return`${this.constructor.NAME}`}}Ym=wr;Y.Null=Ym;wr.NAME="NULL";class Qm extends hn(wt){get value(){for(const e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}constructor({value:e,...n}={}){super(n),n.valueHex?this.valueHexView=G.toUint8Array(n.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,n,r){const i=G.toUint8Array(e);return jn(this,i,n,r)?(this.valueHexView=i.subarray(n,n+r),r>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Mm.call(this),this.blockLength=r,n+r):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}}Qm.NAME="BooleanValueBlock";var e_;let Ka=class extends at{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,Qm),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};e_=Ka;Y.Boolean=e_;Ka.NAME="BOOLEAN";class t_ extends hn(Hn){constructor({isConstructed:e=!1,...n}={}){super(n),this.isConstructed=e}fromBER(e,n,r){let i=0;if(this.isConstructed){if(this.isHexOnly=!1,i=Hn.prototype.fromBER.call(this,e,n,r),i===-1)return i;for(let s=0;s<this.value.length;s++){const a=this.value[s].constructor.NAME;if(a===oo){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(a!==Fm)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,i=super.fromBER(e,n,r),this.blockLength=r;return i}toBER(e,n){return this.isConstructed?Hn.prototype.toBER.call(this,e,n):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}}t_.NAME="OctetStringValueBlock";var Ou;let hr=class extends at{constructor({idBlock:e={},lenBlock:n={},...r}={}){var i,s;(i=r.isConstructed)!==null&&i!==void 0||(r.isConstructed=!!(!((s=r.value)===null||s===void 0)&&s.length)),super({idBlock:{isConstructed:r.isConstructed,...e},lenBlock:{...n,isIndefiniteForm:!!r.isIndefiniteForm},...r},t_),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,n,r){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,r===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),n;if(!this.valueBlock.isConstructed){const s=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(n,n+r);try{if(s.byteLength){const a=bi(s,0,s.byteLength);a.offset!==-1&&a.offset===r&&(this.valueBlock.value=[a.result])}}catch{}}return super.fromBER(e,n,r)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return yt.prototype.onAsciiEncoding.call(this);const e=this.constructor.NAME,n=re.ToHex(this.valueBlock.valueHexView);return`${e} : ${n}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;const e=[];for(const n of this.valueBlock.value)n instanceof Ou&&e.push(n.valueBlock.valueHexView);return G.concat(e)}};Ou=hr;Y.OctetString=Ou;hr.NAME=Fm;class n_ extends hn(Hn){constructor({unusedBits:e=0,isConstructed:n=!1,...r}={}){super(r),this.unusedBits=e,this.isConstructed=n,this.blockLength=this.valueHexView.byteLength}fromBER(e,n,r){if(!r)return n;let i=-1;if(this.isConstructed){if(i=Hn.prototype.fromBER.call(this,e,n,r),i===-1)return i;for(const c of this.value){const l=c.constructor.NAME;if(l===oo){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(l!==qm)return this.error="BIT STRING may consists of BIT STRINGs only",-1;const d=c.valueBlock;if(this.unusedBits>0&&d.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=d.unusedBits}return i}const s=G.toUint8Array(e);if(!jn(this,s,n,r))return-1;const a=s.subarray(n,n+r);if(this.unusedBits=a[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){const c=a.subarray(1);try{if(c.byteLength){const l=bi(c,0,c.byteLength);l.offset!==-1&&l.offset===r-1&&(this.value=[l.result])}}catch{}}return this.valueHexView=a.subarray(1),this.blockLength=a.length,n+r}toBER(e,n){if(this.isConstructed)return Hn.prototype.toBER.call(this,e,n);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return en;const r=new Uint8Array(this.valueHexView.length+1);return r[0]=this.unusedBits,r.set(this.valueHexView,1),r.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}}n_.NAME="BitStringValueBlock";var r_;let gr=class extends at{constructor({idBlock:e={},lenBlock:n={},...r}={}){var i,s;(i=r.isConstructed)!==null&&i!==void 0||(r.isConstructed=!!(!((s=r.value)===null||s===void 0)&&s.length)),super({idBlock:{isConstructed:r.isConstructed,...e},lenBlock:{...n,isIndefiniteForm:!!r.isIndefiniteForm},...r},n_),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,n,r){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,n,r)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return yt.prototype.onAsciiEncoding.call(this);{const e=[],n=this.valueBlock.valueHexView;for(const a of n)e.push(a.toString(2).padStart(8,"0"));const r=e.join(""),i=this.constructor.NAME,s=r.substring(0,r.length-this.valueBlock.unusedBits);return`${i} : ${s}`}}};r_=gr;Y.BitString=r_;gr.NAME=qm;var i_;function Ub(t,e){const n=new Uint8Array([0]),r=new Uint8Array(t),i=new Uint8Array(e);let s=r.slice(0);const a=s.length-1,c=i.slice(0),l=c.length-1;let d=0;const u=l<a?a:l;let f=0;for(let h=u;h>=0;h--,f++){switch(!0){case f<c.length:d=s[a-f]+c[l-f]+n[0];break;default:d=s[a-f]+n[0]}switch(n[0]=d/10,!0){case f>=s.length:s=Ol(new Uint8Array([d%10]),s);break;default:s[a-f]=d%10}}return n[0]>0&&(s=Ol(n,s)),s}function zf(t){if(t>=Li.length)for(let e=Li.length;e<=t;e++){const n=new Uint8Array([0]);let r=Li[e-1].slice(0);for(let i=r.length-1;i>=0;i--){const s=new Uint8Array([(r[i]<<1)+n[0]]);n[0]=s[0]/10,r[i]=s[0]%10}n[0]>0&&(r=Ol(n,r)),Li.push(r)}return Li[t]}function Db(t,e){let n=0;const r=new Uint8Array(t),i=new Uint8Array(e),s=r.slice(0),a=s.length-1,c=i.slice(0),l=c.length-1;let d,u=0;for(let f=l;f>=0;f--,u++)switch(d=s[a-u]-c[l-u]-n,!0){case d<0:n=1,s[a-u]=d+10;break;default:n=0,s[a-u]=d}if(n>0)for(let f=a-l+1;f>=0;f--,u++)if(d=s[a-u]-n,d<0)n=1,s[a-u]=d+10;else{n=0,s[a-u]=d;break}return s.slice()}class Tu extends hn(wt){setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Mm.call(this)))}constructor({value:e,...n}={}){super(n),this._valueDec=0,n.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Ab(e))}get valueDec(){return this._valueDec}fromDER(e,n,r,i=0){const s=this.fromBER(e,n,r);if(s===-1)return s;const a=this.valueHexView;return a[0]===0&&a[1]&128?this.valueHexView=a.subarray(1):i!==0&&a.length<i&&(i-a.length>1&&(i=a.length+1),this.valueHexView=a.subarray(i-a.length)),s}toDER(e=!1){const n=this.valueHexView;switch(!0){case(n[0]&128)!==0:{const r=new Uint8Array(this.valueHexView.length+1);r[0]=0,r.set(n,1),this.valueHexView=r}break;case(n[0]===0&&(n[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,n,r){const i=super.fromBER(e,n,r);return i===-1||this.setValueHex(),i}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){const e=this.valueHexView.length*8-1;let n=new Uint8Array(this.valueHexView.length*8/3),r=0,i;const s=this.valueHexView;let a="",c=!1;for(let l=s.byteLength-1;l>=0;l--){i=s[l];for(let d=0;d<8;d++){if((i&1)===1)switch(r){case e:n=Db(zf(r),n),a="-";break;default:n=Ub(n,zf(r))}r++,i>>=1}}for(let l=0;l<n.length;l++)n[l]&&(c=!0),c&&(a+=xf.charAt(n[l]));return c===!1&&(a+=xf.charAt(0)),a}}i_=Tu;Tu.NAME="IntegerValueBlock";Object.defineProperty(i_.prototype,"valueHex",{set:function(t){this.valueHexView=new Uint8Array(t),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Wi;class $i extends at{constructor(e={}){super(e,Tu),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Ks(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Ks();const n=BigInt(e),r=new Ha,i=n.toString(16).replace(/^-/,""),s=new Uint8Array(re.FromHex(i));if(n<0){const c=new Uint8Array(s.length+(s[0]&128?1:0));c[0]|=128;const d=BigInt(`0x${re.ToHex(c)}`)+n,u=G.toUint8Array(re.FromHex(d.toString(16)));u[0]|=128,r.write(u)}else s[0]&128&&r.write(new Uint8Array([0])),r.write(s);return new Wi({valueHex:r.final()})}convertToDER(){const e=new Wi({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new Wi({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}}Wi=$i;Y.Integer=Wi;$i.NAME="INTEGER";var o_;class Ga extends $i{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}}o_=Ga;Y.Enumerated=o_;Ga.NAME="ENUMERATED";class Tl extends hn(wt){constructor({valueDec:e=-1,isFirstSid:n=!1,...r}={}){super(r),this.valueDec=e,this.isFirstSid=n}fromBER(e,n,r){if(!r)return n;const i=G.toUint8Array(e);if(!jn(this,i,n,r))return-1;const s=i.subarray(n,n+r);this.valueHexView=new Uint8Array(r);for(let c=0;c<r&&(this.valueHexView[c]=s[c]&127,this.blockLength++,!!(s[c]&128));c++);const a=new Uint8Array(this.blockLength);for(let c=0;c<this.blockLength;c++)a[c]=this.valueHexView[c];return this.valueHexView=a,s[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=ii(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),n+this.blockLength)}set valueBigInt(e){Ks();let n=BigInt(e).toString(2);for(;n.length%7;)n="0"+n;const r=new Uint8Array(n.length/7);for(let i=0;i<r.length;i++)r[i]=parseInt(n.slice(i*7,i*7+7),2)+(i+1<r.length?128:0);this.fromBER(r.buffer,0,r.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const i=this.valueHexView,s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength-1;a++)s[a]=i[a]|128;return s[this.blockLength-1]=i[this.blockLength-1],s.buffer}const n=yr(this.valueDec,7);if(n.byteLength===0)return this.error="Error during encoding SID value",en;const r=new Uint8Array(n.byteLength);if(!e){const i=new Uint8Array(n),s=n.byteLength-1;for(let a=0;a<s;a++)r[a]=i[a]|128;r[s]=i[s]}return r}toString(){let e="";if(this.isHexOnly)e=re.ToHex(this.valueHexView);else if(this.isFirstSid){let n=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",n-=40):(e="2.",n-=80),e+=n.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}}Tl.NAME="sidBlock";class s_ extends wt{constructor({value:e=kt,...n}={}){super(n),this.value=[],e&&this.fromString(e)}fromBER(e,n,r){let i=n;for(;r>0;){const s=new Tl;if(i=s.fromBER(e,i,r),i===-1)return this.blockLength=0,this.error=s.error,i;this.value.length===0&&(s.isFirstSid=!0),this.blockLength+=s.blockLength,r-=s.blockLength,this.value.push(s)}return i}toBER(e){const n=[];for(let r=0;r<this.value.length;r++){const i=this.value[r].toBER(e);if(i.byteLength===0)return this.error=this.value[r].error,en;n.push(i)}return Nu(n)}fromString(e){this.value=[];let n=0,r=0,i="",s=!1;do if(r=e.indexOf(".",n),r===-1?i=e.substring(n):i=e.substring(n,r),n=r+1,s){const a=this.value[0];let c=0;switch(a.valueDec){case 0:break;case 1:c=40;break;case 2:c=80;break;default:this.value=[];return}const l=parseInt(i,10);if(isNaN(l))return;a.valueDec=l+c,s=!1}else{const a=new Tl;if(i>Number.MAX_SAFE_INTEGER){Ks();const c=BigInt(i);a.valueBigInt=c}else if(a.valueDec=parseInt(i,10),isNaN(a.valueDec))return;this.value.length||(a.isFirstSid=!0,s=!0),this.value.push(a)}while(r!==-1)}toString(){let e="",n=!1;for(let r=0;r<this.value.length;r++){n=this.value[r].isHexOnly;let i=this.value[r].toString();r!==0&&(e=`${e}.`),n?(i=`{${i}}`,this.value[r].isFirstSid?e=`2.{${i} - 80}`:e+=i):e+=i}return e}toJSON(){const e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let n=0;n<this.value.length;n++)e.sidArray.push(this.value[n].toJSON());return e}}s_.NAME="ObjectIdentifierValueBlock";var a_;class Wa extends at{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,s_),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}a_=Wa;Y.ObjectIdentifier=a_;Wa.NAME="OBJECT IDENTIFIER";class Pl extends hn(Or){constructor({valueDec:e=0,...n}={}){super(n),this.valueDec=e}fromBER(e,n,r){if(r===0)return n;const i=G.toUint8Array(e);if(!jn(this,i,n,r))return-1;const s=i.subarray(n,n+r);this.valueHexView=new Uint8Array(r);for(let c=0;c<r&&(this.valueHexView[c]=s[c]&127,this.blockLength++,!!(s[c]&128));c++);const a=new Uint8Array(this.blockLength);for(let c=0;c<this.blockLength;c++)a[c]=this.valueHexView[c];return this.valueHexView=a,s[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=ii(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),n+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const i=this.valueHexView,s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength-1;a++)s[a]=i[a]|128;return s[this.blockLength-1]=i[this.blockLength-1],s.buffer}const n=yr(this.valueDec,7);if(n.byteLength===0)return this.error="Error during encoding SID value",en;const r=new Uint8Array(n.byteLength);if(!e){const i=new Uint8Array(n),s=n.byteLength-1;for(let a=0;a<s;a++)r[a]=i[a]|128;r[s]=i[s]}return r.buffer}toString(){let e="";return this.isHexOnly?e=re.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}}Pl.NAME="relativeSidBlock";class c_ extends wt{constructor({value:e=kt,...n}={}){super(n),this.value=[],e&&this.fromString(e)}fromBER(e,n,r){let i=n;for(;r>0;){const s=new Pl;if(i=s.fromBER(e,i,r),i===-1)return this.blockLength=0,this.error=s.error,i;this.blockLength+=s.blockLength,r-=s.blockLength,this.value.push(s)}return i}toBER(e,n){const r=[];for(let i=0;i<this.value.length;i++){const s=this.value[i].toBER(e);if(s.byteLength===0)return this.error=this.value[i].error,en;r.push(s)}return Nu(r)}fromString(e){this.value=[];let n=0,r=0,i="";do{r=e.indexOf(".",n),r===-1?i=e.substring(n):i=e.substring(n,r),n=r+1;const s=new Pl;if(s.valueDec=parseInt(i,10),isNaN(s.valueDec))return!0;this.value.push(s)}while(r!==-1);return!0}toString(){let e="",n=!1;for(let r=0;r<this.value.length;r++){n=this.value[r].isHexOnly;let i=this.value[r].toString();r!==0&&(e=`${e}.`),n&&(i=`{${i}}`),e+=i}return e}toJSON(){const e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let n=0;n<this.value.length;n++)e.sidArray.push(this.value[n].toJSON());return e}}c_.NAME="RelativeObjectIdentifierValueBlock";var l_;class Pu extends at{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,c_),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}l_=Pu;Y.RelativeObjectIdentifier=l_;Pu.NAME="RelativeObjectIdentifier";var d_;class Wt extends yt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}}d_=Wt;Y.Sequence=d_;Wt.NAME="SEQUENCE";var u_;let dn=class extends yt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};u_=dn;Y.Set=u_;dn.NAME="SET";class p_ extends hn(wt){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=kt}toJSON(){return{...super.toJSON(),value:this.value}}}p_.NAME="StringValueBlock";class f_ extends p_{}f_.NAME="SimpleStringValueBlock";class It extends Iu{constructor({...e}={}){super(e,f_)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,G.toUint8Array(e))}fromString(e){const n=e.length,r=this.valueBlock.valueHexView=new Uint8Array(n);for(let i=0;i<n;i++)r[i]=e.charCodeAt(i);this.valueBlock.value=e}}It.NAME="SIMPLE STRING";class h_ extends It{fromBuffer(e){this.valueBlock.valueHexView=G.toUint8Array(e);try{this.valueBlock.value=re.ToUtf8String(e)}catch(n){this.warnings.push(`Error during "decodeURIComponent": ${n}, using raw string`),this.valueBlock.value=re.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(re.FromUtf8String(e)),this.valueBlock.value=e}}h_.NAME="Utf8StringValueBlock";var g_;class On extends h_{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}}g_=On;Y.Utf8String=g_;On.NAME="UTF8String";class m_ extends It{fromBuffer(e){this.valueBlock.value=re.ToUtf16String(e),this.valueBlock.valueHexView=G.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(re.FromUtf16String(e))}}m_.NAME="BmpStringValueBlock";var __;class Ja extends m_{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}}__=Ja;Y.BmpString=__;Ja.NAME="BMPString";class y_ extends It{fromBuffer(e){const n=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),r=new Uint8Array(n);for(let i=0;i<r.length;i+=4)r[i]=r[i+3],r[i+1]=r[i+2],r[i+2]=0,r[i+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(n))}fromString(e){const n=e.length,r=this.valueBlock.valueHexView=new Uint8Array(n*4);for(let i=0;i<n;i++){const s=yr(e.charCodeAt(i),8),a=new Uint8Array(s);if(a.length>4)continue;const c=4-a.length;for(let l=a.length-1;l>=0;l--)r[i*4+l+c]=a[l]}this.valueBlock.value=e}}y_.NAME="UniversalStringValueBlock";var w_;class Xa extends y_{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}}w_=Xa;Y.UniversalString=w_;Xa.NAME="UniversalString";var v_;class Za extends It{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}}v_=Za;Y.NumericString=v_;Za.NAME="NumericString";var b_;class Ya extends It{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}}b_=Ya;Y.PrintableString=b_;Ya.NAME="PrintableString";var $_;class Qa extends It{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}}$_=Qa;Y.TeletexString=$_;Qa.NAME="TeletexString";var k_;class ec extends It{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}}k_=ec;Y.VideotexString=k_;ec.NAME="VideotexString";var x_;class tc extends It{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}}x_=tc;Y.IA5String=x_;tc.NAME="IA5String";var S_;class nc extends It{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}}S_=nc;Y.GraphicString=S_;nc.NAME="GraphicString";var z_;class zo extends It{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}}z_=zo;Y.VisibleString=z_;zo.NAME="VisibleString";var A_;class rc extends It{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}}A_=rc;Y.GeneralString=A_;rc.NAME="GeneralString";var E_;class ic extends It{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}}E_=ic;Y.CharacterString=E_;ic.NAME="CharacterString";var C_;class Ao extends zo{constructor({value:e,valueDate:n,...r}={}){if(super(r),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let i=0;i<e.length;i++)this.valueBlock.valueHexView[i]=e.charCodeAt(i)}n&&(this.fromDate(n),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,G.toUint8Array(e)))}toBuffer(){const e=this.toString(),n=new ArrayBuffer(e.length),r=new Uint8Array(n);for(let i=0;i<e.length;i++)r[i]=e.charCodeAt(i);return n}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){const r=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(r===null){this.error="Wrong input string for conversion";return}const i=parseInt(r[1],10);i>=50?this.year=1900+i:this.year=2e3+i,this.month=parseInt(r[2],10),this.day=parseInt(r[3],10),this.hour=parseInt(r[4],10),this.minute=parseInt(r[5],10),this.second=parseInt(r[6],10)}toString(e="iso"){if(e==="iso"){const n=new Array(7);return n[0]=Et(this.year<2e3?this.year-1900:this.year-2e3,2),n[1]=Et(this.month,2),n[2]=Et(this.day,2),n[3]=Et(this.hour,2),n[4]=Et(this.minute,2),n[5]=Et(this.second,2),n[6]="Z",n.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}}C_=Ao;Y.UTCTime=C_;Ao.NAME="UTCTime";var N_;class oc extends Ao{constructor(e={}){var n;super(e),(n=this.millisecond)!==null&&n!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){const e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(e)}fromString(e){let n=!1,r="",i="",s=0,a,c=0,l=0;if(e[e.length-1]==="Z")r=e.substring(0,e.length-1),n=!0;else{const f=new Number(e[e.length-1]);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");r=e}if(n){if(r.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(r.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let f=1,h=r.indexOf("+"),m="";if(h===-1&&(h=r.indexOf("-"),f=-1),h!==-1){if(m=r.substring(h+1),r=r.substring(0,h),m.length!==2&&m.length!==4)throw new Error("Wrong input string for conversion");let y=parseInt(m.substring(0,2),10);if(isNaN(y.valueOf()))throw new Error("Wrong input string for conversion");if(c=f*y,m.length===4){if(y=parseInt(m.substring(2,4),10),isNaN(y.valueOf()))throw new Error("Wrong input string for conversion");l=f*y}}}let d=r.indexOf(".");if(d===-1&&(d=r.indexOf(",")),d!==-1){const f=new Number(`0${r.substring(d)}`);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");s=f.valueOf(),i=r.substring(0,d)}else i=r;switch(!0){case i.length===8:if(a=/(\d{4})(\d{2})(\d{2})/ig,d!==-1)throw new Error("Wrong input string for conversion");break;case i.length===10:if(a=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,d!==-1){let f=60*s;this.minute=Math.floor(f),f=60*(f-this.minute),this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case i.length===12:if(a=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,d!==-1){let f=60*s;this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case i.length===14:if(a=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,d!==-1){const f=1e3*s;this.millisecond=Math.floor(f)}break;default:throw new Error("Wrong input string for conversion")}const u=a.exec(i);if(u===null)throw new Error("Wrong input string for conversion");for(let f=1;f<u.length;f++)switch(f){case 1:this.year=parseInt(u[f],10);break;case 2:this.month=parseInt(u[f],10);break;case 3:this.day=parseInt(u[f],10);break;case 4:this.hour=parseInt(u[f],10)+c;break;case 5:this.minute=parseInt(u[f],10)+l;break;case 6:this.second=parseInt(u[f],10);break;default:throw new Error("Wrong input string for conversion")}if(n===!1){const f=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=f.getUTCFullYear(),this.month=f.getUTCMonth(),this.day=f.getUTCDay(),this.hour=f.getUTCHours(),this.minute=f.getUTCMinutes(),this.second=f.getUTCSeconds(),this.millisecond=f.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){const n=[];return n.push(Et(this.year,4)),n.push(Et(this.month,2)),n.push(Et(this.day,2)),n.push(Et(this.hour,2)),n.push(Et(this.minute,2)),n.push(Et(this.second,2)),this.millisecond!==0&&(n.push("."),n.push(Et(this.millisecond,3))),n.push("Z"),n.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}}N_=oc;Y.GeneralizedTime=N_;oc.NAME="GeneralizedTime";var I_;class Ru extends On{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}}I_=Ru;Y.DATE=I_;Ru.NAME="DATE";var j_;class Bu extends On{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}}j_=Bu;Y.TimeOfDay=j_;Bu.NAME="TimeOfDay";var O_;class Lu extends On{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}}O_=Lu;Y.DateTime=O_;Lu.NAME="DateTime";var T_;class Uu extends On{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}}T_=Uu;Y.Duration=T_;Uu.NAME="Duration";var P_;class Du extends On{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}}P_=Du;Y.TIME=P_;Du.NAME="TIME";class vr{constructor({name:e=kt,optional:n=!1}={}){this.name=e,this.optional=n}}class Mu extends vr{constructor({value:e=[],...n}={}){super(n),this.value=e}}class Gs extends vr{constructor({value:e=new vr,local:n=!1,...r}={}){super(r),this.value=e,this.local=n}}class Mb{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=G.toUint8Array(e)}constructor({data:e=Va}={}){this.dataView=G.toUint8Array(e)}fromBER(e,n,r){const i=n+r;return this.dataView=G.toUint8Array(e).subarray(n,i),i}toBER(e){return this.dataView.slice().buffer}}function Mn(t,e,n){if(n instanceof Mu){for(const s of n.value)if(Mn(t,e,s).verified)return{verified:!0,result:t};{const s={verified:!1,result:{error:"Wrong values for Choice type"}};return n.hasOwnProperty(Xc)&&(s.name=n.name),s}}if(n instanceof vr)return n.hasOwnProperty(Xc)&&(t[n.name]=e),{verified:!0,result:t};if(!(t instanceof Object))return{verified:!1,result:{error:"Wrong root object"}};if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 data"}};if(!(n instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(Nb in n))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(Tb in n.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(Pb in n.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};const r=n.idBlock.toBER(!1);if(r.byteLength===0)return{verified:!1,result:{error:"Error encoding idBlock for ASN.1 schema"}};if(n.idBlock.fromBER(r,0,r.byteLength)===-1)return{verified:!1,result:{error:"Error decoding idBlock for ASN.1 schema"}};if(n.idBlock.hasOwnProperty(Ib)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(n.idBlock.tagClass!==e.idBlock.tagClass)return{verified:!1,result:t};if(n.idBlock.hasOwnProperty(jb)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(n.idBlock.tagNumber!==e.idBlock.tagNumber)return{verified:!1,result:t};if(n.idBlock.hasOwnProperty(Ob)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(n.idBlock.isConstructed!==e.idBlock.isConstructed)return{verified:!1,result:t};if(!(Cb in n.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(n.idBlock.isHexOnly!==e.idBlock.isHexOnly)return{verified:!1,result:t};if(n.idBlock.isHexOnly){if(!(Sf in n.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};const s=n.idBlock.valueHexView,a=e.idBlock.valueHexView;if(s.length!==a.length)return{verified:!1,result:t};for(let c=0;c<s.length;c++)if(s[c]!==a[1])return{verified:!1,result:t}}if(n.name&&(n.name=n.name.replace(/^\s+|\s+$/g,kt),n.name&&(t[n.name]=e)),n instanceof Y.Constructed){let s=0,a={verified:!1,result:{error:"Unknown error"}},c=n.valueBlock.value.length;if(c>0&&n.valueBlock.value[0]instanceof Gs&&(c=e.valueBlock.value.length),c===0)return{verified:!0,result:t};if(e.valueBlock.value.length===0&&n.valueBlock.value.length!==0){let l=!0;for(let d=0;d<n.valueBlock.value.length;d++)l=l&&(n.valueBlock.value[d].optional||!1);return l?{verified:!0,result:t}:(n.name&&(n.name=n.name.replace(/^\s+|\s+$/g,kt),n.name&&delete t[n.name]),t.error="Inconsistent object length",{verified:!1,result:t})}for(let l=0;l<c;l++)if(l-s>=e.valueBlock.value.length){if(n.valueBlock.value[l].optional===!1){const d={verified:!1,result:t};return t.error="Inconsistent length between ASN.1 data and schema",n.name&&(n.name=n.name.replace(/^\s+|\s+$/g,kt),n.name&&(delete t[n.name],d.name=n.name)),d}}else if(n.valueBlock.value[0]instanceof Gs){if(a=Mn(t,e.valueBlock.value[l],n.valueBlock.value[0].value),a.verified===!1)if(n.valueBlock.value[0].optional)s++;else return n.name&&(n.name=n.name.replace(/^\s+|\s+$/g,kt),n.name&&delete t[n.name]),a;if(Xc in n.valueBlock.value[0]&&n.valueBlock.value[0].name.length>0){let d={};Rb in n.valueBlock.value[0]&&n.valueBlock.value[0].local?d=e:d=t,typeof d[n.valueBlock.value[0].name]>"u"&&(d[n.valueBlock.value[0].name]=[]),d[n.valueBlock.value[0].name].push(e.valueBlock.value[l])}}else if(a=Mn(t,e.valueBlock.value[l-s],n.valueBlock.value[l]),a.verified===!1)if(n.valueBlock.value[l].optional)s++;else return n.name&&(n.name=n.name.replace(/^\s+|\s+$/g,kt),n.name&&delete t[n.name]),a;if(a.verified===!1){const l={verified:!1,result:t};return n.name&&(n.name=n.name.replace(/^\s+|\s+$/g,kt),n.name&&(delete t[n.name],l.name=n.name)),l}return{verified:!0,result:t}}if(n.primitiveSchema&&Sf in e.valueBlock){const s=bi(e.valueBlock.valueHexView);if(s.offset===-1){const a={verified:!1,result:s.result};return n.name&&(n.name=n.name.replace(/^\s+|\s+$/g,kt),n.name&&(delete t[n.name],a.name=n.name)),a}return Mn(t,s.result,n.primitiveSchema)}return{verified:!0,result:t}}function Fb(t,e){if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};const n=bi(G.toUint8Array(t));return n.offset===-1?{verified:!1,result:n.result}:Mn(n.result,n.result,e)}const R_=Object.freeze(Object.defineProperty({__proto__:null,Any:vr,BaseBlock:at,BaseStringBlock:Iu,BitString:gr,BmpString:Ja,Boolean:Ka,CharacterString:ic,Choice:Mu,Constructed:yt,DATE:Ru,DateTime:Lu,Duration:Uu,EndOfContent:ju,Enumerated:Ga,GeneralString:rc,GeneralizedTime:oc,GraphicString:nc,HexBlock:hn,IA5String:tc,Integer:$i,Null:wr,NumericString:Za,ObjectIdentifier:Wa,OctetString:hr,Primitive:So,PrintableString:Ya,RawData:Mb,RelativeObjectIdentifier:Pu,Repeated:Gs,Sequence:Wt,Set:dn,TIME:Du,TeletexString:Qa,TimeOfDay:Bu,UTCTime:Ao,UniversalString:Xa,Utf8String:On,ValueBlock:wt,VideotexString:ec,ViewWriter:Ha,VisibleString:zo,compareSchema:Mn,fromBER:Xr,verifySchema:Fb},Symbol.toStringTag,{value:"Module"}));var B;(function(t){t[t.Sequence=0]="Sequence",t[t.Set=1]="Set",t[t.Choice=2]="Choice"})(B||(B={}));var x;(function(t){t[t.Any=1]="Any",t[t.Boolean=2]="Boolean",t[t.OctetString=3]="OctetString",t[t.BitString=4]="BitString",t[t.Integer=5]="Integer",t[t.Enumerated=6]="Enumerated",t[t.ObjectIdentifier=7]="ObjectIdentifier",t[t.Utf8String=8]="Utf8String",t[t.BmpString=9]="BmpString",t[t.UniversalString=10]="UniversalString",t[t.NumericString=11]="NumericString",t[t.PrintableString=12]="PrintableString",t[t.TeletexString=13]="TeletexString",t[t.VideotexString=14]="VideotexString",t[t.IA5String=15]="IA5String",t[t.GraphicString=16]="GraphicString",t[t.VisibleString=17]="VisibleString",t[t.GeneralString=18]="GeneralString",t[t.CharacterString=19]="CharacterString",t[t.UTCTime=20]="UTCTime",t[t.GeneralizedTime=21]="GeneralizedTime",t[t.DATE=22]="DATE",t[t.TimeOfDay=23]="TimeOfDay",t[t.DateTime=24]="DateTime",t[t.Duration=25]="Duration",t[t.TIME=26]="TIME",t[t.Null=27]="Null"})(x||(x={}));class sc{constructor(e,n=0){if(this.unusedBits=0,this.value=new ArrayBuffer(0),e)if(typeof e=="number")this.fromNumber(e);else if(G.isBufferSource(e))this.unusedBits=n,this.value=G.toArrayBuffer(e);else throw TypeError("Unsupported type of 'params' argument for BitString")}fromASN(e){if(!(e instanceof gr))throw new TypeError("Argument 'asn' is not instance of ASN.1 BitString");return this.unusedBits=e.valueBlock.unusedBits,this.value=e.valueBlock.valueHex,this}toASN(){return new gr({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(e){return new gr({name:e})}toNumber(){let e="";const n=new Uint8Array(this.value);for(const r of n)e+=r.toString(2).padStart(8,"0");return e=e.split("").reverse().join(""),this.unusedBits&&(e=e.slice(this.unusedBits).padStart(this.unusedBits,"0")),parseInt(e,2)}fromNumber(e){let n=e.toString(2);const r=n.length+7>>3;this.unusedBits=(r<<3)-n.length;const i=new Uint8Array(r);n=n.padStart(r<<3,"0").split("").reverse().join("");let s=0;for(;s<r;)i[s]=parseInt(n.slice(s<<3,(s<<3)+8),2),s++;this.value=i.buffer}}class ke{get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(e){typeof e=="number"?this.buffer=new ArrayBuffer(e):G.isBufferSource(e)?this.buffer=G.toArrayBuffer(e):Array.isArray(e)?this.buffer=new Uint8Array(e):this.buffer=new ArrayBuffer(0)}fromASN(e){if(!(e instanceof hr))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=e.valueBlock.valueHex,this}toASN(){return new hr({valueHex:this.buffer})}toSchema(e){return new hr({name:e})}}const qb={fromASN:t=>t instanceof wr?null:t.valueBeforeDecodeView,toASN:t=>{if(t===null)return new wr;const e=Xr(t);if(e.result.error)throw new Error(e.result.error);return e.result}},Hb={fromASN:t=>t.valueBlock.valueHexView.byteLength>=4?t.valueBlock.toString():t.valueBlock.valueDec,toASN:t=>new $i({value:+t})},Vb={fromASN:t=>t.valueBlock.valueDec,toASN:t=>new Ga({value:t})},je={fromASN:t=>t.valueBlock.valueHexView,toASN:t=>new $i({valueHex:t})},Kb={fromASN:t=>t.valueBlock.valueHexView,toASN:t=>new gr({valueHex:t})},Gb={fromASN:t=>t.valueBlock.toString(),toASN:t=>new Wa({value:t})},Wb={fromASN:t=>t.valueBlock.value,toASN:t=>new Ka({value:t})},Ws={fromASN:t=>t.valueBlock.valueHexView,toASN:t=>new hr({valueHex:t})},Jb={fromASN:t=>new ke(t.getValue()),toASN:t=>t.toASN()};function Mt(t){return{fromASN:e=>e.valueBlock.value,toASN:e=>new t({value:e})}}const B_=Mt(On),Xb=Mt(Ja),Zb=Mt(Xa),Yb=Mt(Za),Qb=Mt(Ya),e3=Mt(Qa),t3=Mt(ec),n3=Mt(tc),r3=Mt(nc),i3=Mt(zo),o3=Mt(rc),s3=Mt(ic),a3={fromASN:t=>t.toDate(),toASN:t=>new Ao({valueDate:t})},c3={fromASN:t=>t.toDate(),toASN:t=>new oc({valueDate:t})},l3={fromASN:()=>null,toASN:()=>new wr};function Ji(t){switch(t){case x.Any:return qb;case x.BitString:return Kb;case x.BmpString:return Xb;case x.Boolean:return Wb;case x.CharacterString:return s3;case x.Enumerated:return Vb;case x.GeneralString:return o3;case x.GeneralizedTime:return c3;case x.GraphicString:return r3;case x.IA5String:return n3;case x.Integer:return Hb;case x.Null:return l3;case x.NumericString:return Yb;case x.ObjectIdentifier:return Gb;case x.OctetString:return Ws;case x.PrintableString:return Qb;case x.TeletexString:return e3;case x.UTCTime:return a3;case x.UniversalString:return Zb;case x.Utf8String:return B_;case x.VideotexString:return t3;case x.VisibleString:return i3;default:return null}}function xn(t){return typeof t=="function"&&t.prototype?t.prototype.toASN&&t.prototype.fromASN?!0:xn(t.prototype):!!(t&&typeof t=="object"&&"toASN"in t&&"fromASN"in t)}function L_(t){var e;if(t){const n=Object.getPrototypeOf(t);return((e=n==null?void 0:n.prototype)===null||e===void 0?void 0:e.constructor)===Array?!0:L_(n)}return!1}function d3(t,e){if(!(t&&e)||t.byteLength!==e.byteLength)return!1;const n=new Uint8Array(t),r=new Uint8Array(e);for(let i=0;i<t.byteLength;i++)if(n[i]!==r[i])return!1;return!0}class u3{constructor(){this.items=new WeakMap}has(e){return this.items.has(e)}get(e,n=!1){const r=this.items.get(e);if(!r)throw new Error(`Cannot get schema for '${e.prototype.constructor.name}' target`);if(n&&!r.schema)throw new Error(`Schema '${e.prototype.constructor.name}' doesn't contain ASN.1 schema. Call 'AsnSchemaStorage.cache'.`);return r}cache(e){const n=this.get(e);n.schema||(n.schema=this.create(e,!0))}createDefault(e){const n={type:B.Sequence,items:{}},r=this.findParentSchema(e);return r&&(Object.assign(n,r),n.items=Object.assign({},n.items,r.items)),n}create(e,n){const r=this.items.get(e)||this.createDefault(e),i=[];for(const s in r.items){const a=r.items[s],c=n?s:"";let l;if(typeof a.type=="number"){const u=x[a.type],f=R_[u];if(!f)throw new Error(`Cannot get ASN1 class by name '${u}'`);l=new f({name:c})}else xn(a.type)?l=new a.type().toSchema(c):a.optional?this.get(a.type).type===B.Choice?l=new vr({name:c}):(l=this.create(a.type,!1),l.name=c):l=new vr({name:c});const d=!!a.optional||a.defaultValue!==void 0;if(a.repeated){l.name="";const u=a.repeated==="set"?dn:Wt;l=new u({name:"",value:[new Gs({name:c,value:l})]})}if(a.context!==null&&a.context!==void 0)if(a.implicit)if(typeof a.type=="number"||xn(a.type)){const u=a.repeated?yt:So;i.push(new u({name:c,optional:d,idBlock:{tagClass:3,tagNumber:a.context}}))}else{this.cache(a.type);const u=!!a.repeated;let f=u?l:this.get(a.type,!0).schema;f="valueBlock"in f?f.valueBlock.value:f.value,i.push(new yt({name:u?"":c,optional:d,idBlock:{tagClass:3,tagNumber:a.context},value:f}))}else i.push(new yt({optional:d,idBlock:{tagClass:3,tagNumber:a.context},value:[l]}));else l.optional=d,i.push(l)}switch(r.type){case B.Sequence:return new Wt({value:i,name:""});case B.Set:return new dn({value:i,name:""});case B.Choice:return new Mu({value:i,name:""});default:throw new Error("Unsupported ASN1 type in use")}}set(e,n){return this.items.set(e,n),this}findParentSchema(e){const n=Object.getPrototypeOf(e);return n?this.items.get(n)||this.findParentSchema(n):null}}const Je=new u3,M=t=>e=>{let n;Je.has(e)?n=Je.get(e):(n=Je.createDefault(e),Je.set(e,n)),Object.assign(n,t)},_=t=>(e,n)=>{let r;Je.has(e.constructor)?r=Je.get(e.constructor):(r=Je.createDefault(e.constructor),Je.set(e.constructor,r));const i=Object.assign({},t);if(typeof i.type=="number"&&!i.converter){const s=Ji(t.type);if(!s)throw new Error(`Cannot get default converter for property '${n}' of ${e.constructor.name}`);i.converter=s}r.items[n]=i};class Ui extends Error{constructor(){super(...arguments),this.schemas=[]}}class p3{static parse(e,n){const r=Xr(e);if(r.result.error)throw new Error(r.result.error);return this.fromASN(r.result,n)}static fromASN(e,n){try{if(xn(n))return new n().fromASN(e);const r=Je.get(n);Je.cache(n);let i=r.schema;const s=this.handleChoiceTypes(e,r,n,i);if(s!=null&&s.result)return s.result;s!=null&&s.targetSchema&&(i=s.targetSchema);const a=this.handleSequenceTypes(e,r,n,i);if(a&&"isManualMapping"in a)return a.result;const c=a,l=new n;return L_(n)?this.handleArrayTypes(e,r,n):(this.processSchemaItems(r,c,l),l)}catch(r){throw r instanceof Ui&&r.schemas.push(n.name),r}}static handleChoiceTypes(e,n,r,i){if(e.constructor===yt&&n.type===B.Choice&&e.idBlock.tagClass===3)for(const s in n.items){const a=n.items[s];if(a.context===e.idBlock.tagNumber&&a.implicit&&typeof a.type=="function"&&Je.has(a.type)){const c=Je.get(a.type);if(c&&c.type===B.Sequence){const l=new Wt;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in l.valueBlock){l.valueBlock.value=e.valueBlock.value;const d=this.fromASN(l,a.type),u=new r;return u[s]=d,{result:u}}}}}else if(e.constructor===yt&&n.type!==B.Choice){const s=new yt({idBlock:{tagClass:3,tagNumber:e.idBlock.tagNumber},value:n.schema.valueBlock.value});for(const a in n.items)delete e[a];return{targetSchema:s}}return null}static handleSequenceTypes(e,n,r,i){if(n.type===B.Sequence){if(Object.keys(n.items).filter(c=>{const l=n.items[c];return l.optional&&typeof l.type=="function"&&Je.has(l.type)&&Je.get(l.type).type===B.Choice}).length>0&&"value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&r.name==="CertReqMsg")return this.handleManualMapping(e,n,r);const a=Mn({},e,i);if(!a.verified)throw new Ui(`Data does not match to ${r.name} ASN1 schema. ${a.result.error}`);return a}else{const s=Mn({},e,i);if(!s.verified)throw new Ui(`Data does not match to ${r.name} ASN1 schema. ${s.result.error}`);return s}}static handleManualMapping(e,n,r){const i=new r,s=e.valueBlock.value,a=Object.keys(n.items);let c=0;for(let l=0;l<a.length;l++){const d=a[l],u=n.items[d];if(c>=s.length)break;if(u.repeated){i[d]=this.processRepeatedField(s,c,u);break}else if(typeof u.type=="number")i[d]=this.processPrimitiveField(s[c],u),c++;else if(this.isOptionalChoiceField(u)){const f=this.processOptionalChoiceField(s[c],u);f.processed&&(i[d]=f.value,c++)}else i[d]=this.fromASN(s[c],u.type),c++}return{result:i,verified:!0,isManualMapping:!0}}static processRepeatedField(e,n,r){let i=e.slice(n);if(i.length===1&&i[0].constructor.name==="Sequence"){const s=i[0];s.valueBlock&&s.valueBlock.value&&Array.isArray(s.valueBlock.value)&&(i=s.valueBlock.value)}if(typeof r.type=="number"){const s=Ji(r.type);if(!s)throw new Error(`No converter for ASN.1 type ${r.type}`);return i.filter(a=>a&&a.valueBlock).map(a=>{try{return s.fromASN(a)}catch{return}}).filter(a=>a!==void 0)}else return i.filter(s=>s&&s.valueBlock).map(s=>{try{return this.fromASN(s,r.type)}catch{return}}).filter(s=>s!==void 0)}static processPrimitiveField(e,n){const r=Ji(n.type);if(!r)throw new Error(`No converter for ASN.1 type ${n.type}`);return r.fromASN(e)}static isOptionalChoiceField(e){return e.optional&&typeof e.type=="function"&&Je.has(e.type)&&Je.get(e.type).type===B.Choice}static processOptionalChoiceField(e,n){try{return{processed:!0,value:this.fromASN(e,n.type)}}catch(r){if(r instanceof Ui&&/Wrong values for Choice type/.test(r.message))return{processed:!1};throw r}}static handleArrayTypes(e,n,r){if(!("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");const i=n.itemType;if(typeof i=="number"){const s=Ji(i);if(!s)throw new Error(`Cannot get default converter for array item of ${r.name} ASN1 schema`);return r.from(e.valueBlock.value,a=>s.fromASN(a))}else return r.from(e.valueBlock.value,s=>this.fromASN(s,i))}static processSchemaItems(e,n,r){for(const i in e.items){const s=n.result[i];if(!s)continue;const a=e.items[i],c=a.type;typeof c=="number"||xn(c)?r[i]=this.processPrimitiveSchemaItem(s,a,c):r[i]=this.processComplexSchemaItem(s,a,c)}}static processPrimitiveSchemaItem(e,n,r){var i;const s=(i=n.converter)!==null&&i!==void 0?i:xn(r)?new r:null;if(!s)throw new Error("Converter is empty");return n.repeated?this.processRepeatedPrimitiveItem(e,n,s):this.processSinglePrimitiveItem(e,n,r,s)}static processRepeatedPrimitiveItem(e,n,r){if(n.implicit){const i=n.repeated==="sequence"?Wt:dn,s=new i;s.valueBlock=e.valueBlock;const a=Xr(s.toBER(!1));if(a.offset===-1)throw new Error(`Cannot parse the child item. ${a.result.error}`);if(!("value"in a.result.valueBlock&&Array.isArray(a.result.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");const c=a.result.valueBlock.value;return Array.from(c,l=>r.fromASN(l))}else return Array.from(e,i=>r.fromASN(i))}static processSinglePrimitiveItem(e,n,r,i){let s=e;if(n.implicit){let a;if(xn(r))a=new r().toSchema("");else{const c=x[r],l=R_[c];if(!l)throw new Error(`Cannot get '${c}' class from asn1js module`);a=new l}a.valueBlock=s.valueBlock,s=Xr(a.toBER(!1)).result}return i.fromASN(s)}static processComplexSchemaItem(e,n,r){if(n.repeated){if(!Array.isArray(e))throw new Error("Cannot get list of items from the ASN.1 parsed value. ASN.1 value should be iterable.");return Array.from(e,i=>this.fromASN(i,r))}else{const i=this.handleImplicitTagging(e,n,r);if(this.isOptionalChoiceField(n))try{return this.fromASN(i,r)}catch(s){if(s instanceof Ui&&/Wrong values for Choice type/.test(s.message))return;throw s}else return this.fromASN(i,r)}}static handleImplicitTagging(e,n,r){if(n.implicit&&typeof n.context=="number"){const i=Je.get(r);if(i.type===B.Sequence){const s=new Wt;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in s.valueBlock)return s.valueBlock.value=e.valueBlock.value,s}else if(i.type===B.Set){const s=new dn;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in s.valueBlock)return s.valueBlock.value=e.valueBlock.value,s}}return e}}class Fu{static serialize(e){return e instanceof at?e.toBER(!1):this.toASN(e).toBER(!1)}static toASN(e){if(e&&typeof e=="object"&&xn(e))return e.toASN();if(!(e&&typeof e=="object"))throw new TypeError("Parameter 1 should be type of Object.");const n=e.constructor,r=Je.get(n);Je.cache(n);let i=[];if(r.itemType){if(!Array.isArray(e))throw new TypeError("Parameter 1 should be type of Array.");if(typeof r.itemType=="number"){const a=Ji(r.itemType);if(!a)throw new Error(`Cannot get default converter for array item of ${n.name} ASN1 schema`);i=e.map(c=>a.toASN(c))}else i=e.map(a=>this.toAsnItem({type:r.itemType},"[]",n,a))}else for(const a in r.items){const c=r.items[a],l=e[a];if(l===void 0||c.defaultValue===l||typeof c.defaultValue=="object"&&typeof l=="object"&&d3(this.serialize(c.defaultValue),this.serialize(l)))continue;const d=Fu.toAsnItem(c,a,n,l);if(typeof c.context=="number")if(c.implicit)if(!c.repeated&&(typeof c.type=="number"||xn(c.type))){const u={};u.valueHex=d instanceof wr?d.valueBeforeDecodeView:d.valueBlock.toBER(),i.push(new So({optional:c.optional,idBlock:{tagClass:3,tagNumber:c.context},...u}))}else i.push(new yt({optional:c.optional,idBlock:{tagClass:3,tagNumber:c.context},value:d.valueBlock.value}));else i.push(new yt({optional:c.optional,idBlock:{tagClass:3,tagNumber:c.context},value:[d]}));else c.repeated?i=i.concat(d):i.push(d)}let s;switch(r.type){case B.Sequence:s=new Wt({value:i});break;case B.Set:s=new dn({value:i});break;case B.Choice:if(!i[0])throw new Error(`Schema '${n.name}' has wrong data. Choice cannot be empty.`);s=i[0];break}return s}static toAsnItem(e,n,r,i){let s;if(typeof e.type=="number"){const a=e.converter;if(!a)throw new Error(`Property '${n}' doesn't have converter for type ${x[e.type]} in schema '${r.name}'`);if(e.repeated){if(!Array.isArray(i))throw new TypeError("Parameter 'objProp' should be type of Array.");const c=Array.from(i,d=>a.toASN(d)),l=e.repeated==="sequence"?Wt:dn;s=new l({value:c})}else s=a.toASN(i)}else if(e.repeated){if(!Array.isArray(i))throw new TypeError("Parameter 'objProp' should be type of Array.");const a=Array.from(i,l=>this.toASN(l)),c=e.repeated==="sequence"?Wt:dn;s=new c({value:a})}else s=this.toASN(i);return s}}class ze extends Array{constructor(e=[]){if(typeof e=="number")super(e);else{super();for(const n of e)this.push(n)}}}class H{static serialize(e){return Fu.serialize(e)}static parse(e,n){return p3.parse(e,n)}static toString(e){const n=G.isBufferSource(e)?G.toArrayBuffer(e):H.serialize(e),r=Xr(n);if(r.offset===-1)throw new Error(`Cannot decode ASN.1 data. ${r.result.error}`);return r.result.toString()}}function g(t,e,n,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,n):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(t,e,n,r);else for(var c=t.length-1;c>=0;c--)(a=t[c])&&(s=(i<3?a(s):i>3?a(e,n,s):a(e,n))||s);return i>3&&s&&Object.defineProperty(e,n,s),s}class Af{static isIPv4(e){return/^(\d{1,3}\.){3}\d{1,3}$/.test(e)}static parseIPv4(e){const n=e.split(".");if(n.length!==4)throw new Error("Invalid IPv4 address");return n.map(r=>{const i=parseInt(r,10);if(isNaN(i)||i<0||i>255)throw new Error("Invalid IPv4 address part");return i})}static parseIPv6(e){const r=this.expandIPv6(e).split(":");if(r.length!==8)throw new Error("Invalid IPv6 address");return r.reduce((i,s)=>{const a=parseInt(s,16);if(isNaN(a)||a<0||a>65535)throw new Error("Invalid IPv6 address part");return i.push(a>>8&255),i.push(a&255),i},[])}static expandIPv6(e){if(!e.includes("::"))return e;const n=e.split("::");if(n.length>2)throw new Error("Invalid IPv6 address");const r=n[0]?n[0].split(":"):[],i=n[1]?n[1].split(":"):[],s=8-(r.length+i.length);if(s<0)throw new Error("Invalid IPv6 address");return[...r,...Array(s).fill("0"),...i].join(":")}static formatIPv6(e){const n=[];for(let r=0;r<16;r+=2)n.push((e[r]<<8|e[r+1]).toString(16));return this.compressIPv6(n.join(":"))}static compressIPv6(e){const n=e.split(":");let r=-1,i=0,s=-1,a=0;for(let c=0;c<n.length;c++)n[c]==="0"?(s===-1&&(s=c),a++):(a>i&&(r=s,i=a),s=-1,a=0);if(a>i&&(r=s,i=a),i>1){const c=n.slice(0,r).join(":"),l=n.slice(r+i).join(":");return`${c}::${l}`}return e}static parseCIDR(e){const[n,r]=e.split("/"),i=parseInt(r,10);if(this.isIPv4(n)){if(i<0||i>32)throw new Error("Invalid IPv4 prefix length");return[this.parseIPv4(n),i]}else{if(i<0||i>128)throw new Error("Invalid IPv6 prefix length");return[this.parseIPv6(n),i]}}static decodeIP(e){if(e.length===64&&parseInt(e,16)===0)return"::/0";if(e.length!==16)return e;const n=parseInt(e.slice(8),16).toString(2).split("").reduce((i,s)=>i+ +s,0);let r=e.slice(0,8).replace(/(.{2})/g,i=>`${parseInt(i,16)}.`);return r=r.slice(0,-1),`${r}/${n}`}static toString(e){const n=new Uint8Array(e);if(n.length===4)return Array.from(n).join(".");if(n.length===16)return this.formatIPv6(n);if(n.length===8||n.length===32){const r=n.length/2,i=n.slice(0,r),s=n.slice(r);if(n.every(l=>l===0))return n.length===8?"0.0.0.0/0":"::/0";const c=s.reduce((l,d)=>l+(d.toString(2).match(/1/g)||[]).length,0);return n.length===8?`${Array.from(i).join(".")}/${c}`:`${this.formatIPv6(i)}/${c}`}return this.decodeIP(re.ToHex(e))}static fromString(e){if(e.includes("/")){const[r,i]=this.parseCIDR(e),s=new Uint8Array(r.length);let a=i;for(let l=0;l<s.length;l++)a>=8?(s[l]=255,a-=8):a>0&&(s[l]=255<<8-a,a=0);const c=new Uint8Array(r.length*2);return c.set(r,0),c.set(s,r.length),c.buffer}const n=this.isIPv4(e)?this.parseIPv4(e):this.parseIPv6(e);return new Uint8Array(n).buffer}}var Rl,Bl,Ll;let ct=class{constructor(e={}){Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};g([_({type:x.TeletexString})],ct.prototype,"teletexString",void 0);g([_({type:x.PrintableString})],ct.prototype,"printableString",void 0);g([_({type:x.UniversalString})],ct.prototype,"universalString",void 0);g([_({type:x.Utf8String})],ct.prototype,"utf8String",void 0);g([_({type:x.BmpString})],ct.prototype,"bmpString",void 0);ct=g([M({type:B.Choice})],ct);let oi=class extends ct{constructor(e={}){super(e),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?re.ToHex(this.anyValue):super.toString())}};g([_({type:x.IA5String})],oi.prototype,"ia5String",void 0);g([_({type:x.Any})],oi.prototype,"anyValue",void 0);oi=g([M({type:B.Choice})],oi);class ac{constructor(e={}){this.type="",this.value=new oi,Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],ac.prototype,"type",void 0);g([_({type:oi})],ac.prototype,"value",void 0);let si=Rl=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,Rl.prototype)}};si=Rl=g([M({type:B.Set,itemType:ac})],si);let Ul=Bl=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,Bl.prototype)}};Ul=Bl=g([M({type:B.Sequence,itemType:si})],Ul);let Ve=Ll=class extends Ul{constructor(e){super(e),Object.setPrototypeOf(this,Ll.prototype)}};Ve=Ll=g([M({type:B.Sequence})],Ve);const f3={fromASN:t=>Af.toString(Ws.fromASN(t)),toASN:t=>Ws.toASN(Af.fromString(t))};class so{constructor(e={}){this.typeId="",this.value=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],so.prototype,"typeId",void 0);g([_({type:x.Any,context:0})],so.prototype,"value",void 0);class qu{constructor(e={}){this.partyName=new ct,Object.assign(this,e)}}g([_({type:ct,optional:!0,context:0,implicit:!0})],qu.prototype,"nameAssigner",void 0);g([_({type:ct,context:1,implicit:!0})],qu.prototype,"partyName",void 0);let me=class{constructor(e={}){Object.assign(this,e)}};g([_({type:so,context:0,implicit:!0})],me.prototype,"otherName",void 0);g([_({type:x.IA5String,context:1,implicit:!0})],me.prototype,"rfc822Name",void 0);g([_({type:x.IA5String,context:2,implicit:!0})],me.prototype,"dNSName",void 0);g([_({type:x.Any,context:3,implicit:!0})],me.prototype,"x400Address",void 0);g([_({type:Ve,context:4,implicit:!1})],me.prototype,"directoryName",void 0);g([_({type:qu,context:5})],me.prototype,"ediPartyName",void 0);g([_({type:x.IA5String,context:6,implicit:!0})],me.prototype,"uniformResourceIdentifier",void 0);g([_({type:x.OctetString,context:7,implicit:!0,converter:f3})],me.prototype,"iPAddress",void 0);g([_({type:x.ObjectIdentifier,context:8,implicit:!0})],me.prototype,"registeredID",void 0);me=g([M({type:B.Choice})],me);const Hu="1.3.6.1.5.5.7",h3=`${Hu}.1`,ki=`${Hu}.3`,cc=`${Hu}.48`,Ef=`${cc}.1`,Cf=`${cc}.2`,Nf=`${cc}.3`,If=`${cc}.5`,Tn="2.5.29";var Dl;const Ml=`${h3}.1`;class Eo{constructor(e={}){this.accessMethod="",this.accessLocation=new me,Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],Eo.prototype,"accessMethod",void 0);g([_({type:me})],Eo.prototype,"accessLocation",void 0);let Gr=Dl=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,Dl.prototype)}};Gr=Dl=g([M({type:B.Sequence,itemType:Eo})],Gr);const Fl=`${Tn}.35`;class Vu extends ke{}class ur{constructor(e={}){e&&Object.assign(this,e)}}g([_({type:Vu,context:0,optional:!0,implicit:!0})],ur.prototype,"keyIdentifier",void 0);g([_({type:me,context:1,optional:!0,implicit:!0,repeated:"sequence"})],ur.prototype,"authorityCertIssuer",void 0);g([_({type:x.Integer,context:2,optional:!0,implicit:!0,converter:je})],ur.prototype,"authorityCertSerialNumber",void 0);const U_=`${Tn}.19`;class Js{constructor(e={}){this.cA=!1,Object.assign(this,e)}}g([_({type:x.Boolean,defaultValue:!1})],Js.prototype,"cA",void 0);g([_({type:x.Integer,optional:!0})],Js.prototype,"pathLenConstraint",void 0);var ql;let gt=ql=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,ql.prototype)}};gt=ql=g([M({type:B.Sequence,itemType:me})],gt);var Hl;let jf=Hl=class extends gt{constructor(e){super(e),Object.setPrototypeOf(this,Hl.prototype)}};jf=Hl=g([M({type:B.Sequence})],jf);var Vl;const D_=`${Tn}.32`;let Sn=class{constructor(e={}){Object.assign(this,e)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};g([_({type:x.IA5String})],Sn.prototype,"ia5String",void 0);g([_({type:x.VisibleString})],Sn.prototype,"visibleString",void 0);g([_({type:x.BmpString})],Sn.prototype,"bmpString",void 0);g([_({type:x.Utf8String})],Sn.prototype,"utf8String",void 0);Sn=g([M({type:B.Choice})],Sn);class Ku{constructor(e={}){this.organization=new Sn,this.noticeNumbers=[],Object.assign(this,e)}}g([_({type:Sn})],Ku.prototype,"organization",void 0);g([_({type:x.Integer,repeated:"sequence"})],Ku.prototype,"noticeNumbers",void 0);class Gu{constructor(e={}){Object.assign(this,e)}}g([_({type:Ku,optional:!0})],Gu.prototype,"noticeRef",void 0);g([_({type:Sn,optional:!0})],Gu.prototype,"explicitText",void 0);let Xs=class{constructor(e={}){Object.assign(this,e)}};g([_({type:x.IA5String})],Xs.prototype,"cPSuri",void 0);g([_({type:Gu})],Xs.prototype,"userNotice",void 0);Xs=g([M({type:B.Choice})],Xs);class Wu{constructor(e={}){this.policyQualifierId="",this.qualifier=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],Wu.prototype,"policyQualifierId",void 0);g([_({type:x.Any})],Wu.prototype,"qualifier",void 0);class lc{constructor(e={}){this.policyIdentifier="",Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],lc.prototype,"policyIdentifier",void 0);g([_({type:Wu,repeated:"sequence",optional:!0})],lc.prototype,"policyQualifiers",void 0);let Zs=Vl=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,Vl.prototype)}};Zs=Vl=g([M({type:B.Sequence,itemType:lc})],Zs);let Ys=class{constructor(e=0){this.value=e}};g([_({type:x.Integer})],Ys.prototype,"value",void 0);Ys=g([M({type:B.Choice})],Ys);let Of=class extends Ys{};Of=g([M({type:B.Choice})],Of);var Kl;const Gl=`${Tn}.31`;var qt;(function(t){t[t.unused=1]="unused",t[t.keyCompromise=2]="keyCompromise",t[t.cACompromise=4]="cACompromise",t[t.affiliationChanged=8]="affiliationChanged",t[t.superseded=16]="superseded",t[t.cessationOfOperation=32]="cessationOfOperation",t[t.certificateHold=64]="certificateHold",t[t.privilegeWithdrawn=128]="privilegeWithdrawn",t[t.aACompromise=256]="aACompromise"})(qt||(qt={}));class M_ extends sc{toJSON(){const e=[],n=this.toNumber();return n&qt.aACompromise&&e.push("aACompromise"),n&qt.affiliationChanged&&e.push("affiliationChanged"),n&qt.cACompromise&&e.push("cACompromise"),n&qt.certificateHold&&e.push("certificateHold"),n&qt.cessationOfOperation&&e.push("cessationOfOperation"),n&qt.keyCompromise&&e.push("keyCompromise"),n&qt.privilegeWithdrawn&&e.push("privilegeWithdrawn"),n&qt.superseded&&e.push("superseded"),n&qt.unused&&e.push("unused"),e}toString(){return`[${this.toJSON().join(", ")}]`}}let br=class{constructor(e={}){Object.assign(this,e)}};g([_({type:me,context:0,repeated:"sequence",implicit:!0})],br.prototype,"fullName",void 0);g([_({type:si,context:1,implicit:!0})],br.prototype,"nameRelativeToCRLIssuer",void 0);br=g([M({type:B.Choice})],br);class xi{constructor(e={}){Object.assign(this,e)}}g([_({type:br,context:0,optional:!0})],xi.prototype,"distributionPoint",void 0);g([_({type:M_,context:1,optional:!0,implicit:!0})],xi.prototype,"reasons",void 0);g([_({type:me,context:2,optional:!0,repeated:"sequence",implicit:!0})],xi.prototype,"cRLIssuer",void 0);let Zr=Kl=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,Kl.prototype)}};Zr=Kl=g([M({type:B.Sequence,itemType:xi})],Zr);var Wl;let Tf=Wl=class extends Zr{constructor(e){super(e),Object.setPrototypeOf(this,Wl.prototype)}};Tf=Wl=g([M({type:B.Sequence,itemType:xi})],Tf);class ht{constructor(e={}){this.onlyContainsUserCerts=ht.ONLY,this.onlyContainsCACerts=ht.ONLY,this.indirectCRL=ht.ONLY,this.onlyContainsAttributeCerts=ht.ONLY,Object.assign(this,e)}}ht.ONLY=!1;g([_({type:br,context:0,optional:!0})],ht.prototype,"distributionPoint",void 0);g([_({type:x.Boolean,context:1,defaultValue:ht.ONLY,implicit:!0})],ht.prototype,"onlyContainsUserCerts",void 0);g([_({type:x.Boolean,context:2,defaultValue:ht.ONLY,implicit:!0})],ht.prototype,"onlyContainsCACerts",void 0);g([_({type:M_,context:3,optional:!0,implicit:!0})],ht.prototype,"onlySomeReasons",void 0);g([_({type:x.Boolean,context:4,defaultValue:ht.ONLY,implicit:!0})],ht.prototype,"indirectCRL",void 0);g([_({type:x.Boolean,context:5,defaultValue:ht.ONLY,implicit:!0})],ht.prototype,"onlyContainsAttributeCerts",void 0);var Xi;(function(t){t[t.unspecified=0]="unspecified",t[t.keyCompromise=1]="keyCompromise",t[t.cACompromise=2]="cACompromise",t[t.affiliationChanged=3]="affiliationChanged",t[t.superseded=4]="superseded",t[t.cessationOfOperation=5]="cessationOfOperation",t[t.certificateHold=6]="certificateHold",t[t.removeFromCRL=8]="removeFromCRL",t[t.privilegeWithdrawn=9]="privilegeWithdrawn",t[t.aACompromise=10]="aACompromise"})(Xi||(Xi={}));let Jl=class{constructor(e=Xi.unspecified){this.reason=Xi.unspecified,this.reason=e}toJSON(){return Xi[this.reason]}toString(){return this.toJSON()}};g([_({type:x.Enumerated})],Jl.prototype,"reason",void 0);Jl=g([M({type:B.Choice})],Jl);var Xl;const F_=`${Tn}.37`;let Qs=Xl=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,Xl.prototype)}};Qs=Xl=g([M({type:B.Sequence,itemType:x.ObjectIdentifier})],Qs);const g3=`${ki}.1`,m3=`${ki}.2`,_3=`${ki}.3`,y3=`${ki}.4`,w3=`${ki}.8`,v3=`${ki}.9`;let Zl=class{constructor(e=new ArrayBuffer(0)){this.value=e}};g([_({type:x.Integer,converter:je})],Zl.prototype,"value",void 0);Zl=g([M({type:B.Choice})],Zl);let Yl=class{constructor(e){this.value=new Date,e&&(this.value=e)}};g([_({type:x.GeneralizedTime})],Yl.prototype,"value",void 0);Yl=g([M({type:B.Choice})],Yl);var Ql;const q_=`${Tn}.18`;let Pf=Ql=class extends gt{constructor(e){super(e),Object.setPrototypeOf(this,Ql.prototype)}};Pf=Ql=g([M({type:B.Sequence})],Pf);const H_=`${Tn}.15`;var Ht;(function(t){t[t.digitalSignature=1]="digitalSignature",t[t.nonRepudiation=2]="nonRepudiation",t[t.keyEncipherment=4]="keyEncipherment",t[t.dataEncipherment=8]="dataEncipherment",t[t.keyAgreement=16]="keyAgreement",t[t.keyCertSign=32]="keyCertSign",t[t.cRLSign=64]="cRLSign",t[t.encipherOnly=128]="encipherOnly",t[t.decipherOnly=256]="decipherOnly"})(Ht||(Ht={}));class Zc extends sc{toJSON(){const e=this.toNumber(),n=[];return e&Ht.cRLSign&&n.push("crlSign"),e&Ht.dataEncipherment&&n.push("dataEncipherment"),e&Ht.decipherOnly&&n.push("decipherOnly"),e&Ht.digitalSignature&&n.push("digitalSignature"),e&Ht.encipherOnly&&n.push("encipherOnly"),e&Ht.keyAgreement&&n.push("keyAgreement"),e&Ht.keyCertSign&&n.push("keyCertSign"),e&Ht.keyEncipherment&&n.push("keyEncipherment"),e&Ht.nonRepudiation&&n.push("nonRepudiation"),n}toString(){return`[${this.toJSON().join(", ")}]`}}var ed;class dc{constructor(e={}){this.base=new me,this.minimum=0,Object.assign(this,e)}}g([_({type:me})],dc.prototype,"base",void 0);g([_({type:x.Integer,context:0,defaultValue:0,implicit:!0})],dc.prototype,"minimum",void 0);g([_({type:x.Integer,context:1,optional:!0,implicit:!0})],dc.prototype,"maximum",void 0);let ea=ed=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,ed.prototype)}};ea=ed=g([M({type:B.Sequence,itemType:dc})],ea);class V_{constructor(e={}){Object.assign(this,e)}}g([_({type:ea,context:0,optional:!0,implicit:!0})],V_.prototype,"permittedSubtrees",void 0);g([_({type:ea,context:1,optional:!0,implicit:!0})],V_.prototype,"excludedSubtrees",void 0);class K_{constructor(e={}){Object.assign(this,e)}}g([_({type:x.Integer,context:0,implicit:!0,optional:!0,converter:je})],K_.prototype,"requireExplicitPolicy",void 0);g([_({type:x.Integer,context:1,implicit:!0,optional:!0,converter:je})],K_.prototype,"inhibitPolicyMapping",void 0);var td;class Ju{constructor(e={}){this.issuerDomainPolicy="",this.subjectDomainPolicy="",Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],Ju.prototype,"issuerDomainPolicy",void 0);g([_({type:x.ObjectIdentifier})],Ju.prototype,"subjectDomainPolicy",void 0);let Rf=td=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,td.prototype)}};Rf=td=g([M({type:B.Sequence,itemType:Ju})],Rf);var nd;const G_=`${Tn}.17`;let rd=nd=class extends gt{constructor(e){super(e),Object.setPrototypeOf(this,nd.prototype)}};rd=nd=g([M({type:B.Sequence})],rd);let zn=class{constructor(e={}){this.type="",this.values=[],Object.assign(this,e)}};g([_({type:x.ObjectIdentifier})],zn.prototype,"type",void 0);g([_({type:x.Any,repeated:"set"})],zn.prototype,"values",void 0);var id;let Bf=id=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,id.prototype)}};Bf=id=g([M({type:B.Sequence,itemType:zn})],Bf);const W_=`${Tn}.14`;class Vn extends Vu{}class J_{constructor(e={}){Object.assign(this,e)}}g([_({type:x.GeneralizedTime,context:0,implicit:!0,optional:!0})],J_.prototype,"notBefore",void 0);g([_({type:x.GeneralizedTime,context:1,implicit:!0,optional:!0})],J_.prototype,"notAfter",void 0);var Zi;(function(t){t[t.keyUpdateAllowed=1]="keyUpdateAllowed",t[t.newExtensions=2]="newExtensions",t[t.pKIXCertificate=4]="pKIXCertificate"})(Zi||(Zi={}));class X_ extends sc{toJSON(){const e=[],n=this.toNumber();return n&Zi.pKIXCertificate&&e.push("pKIXCertificate"),n&Zi.newExtensions&&e.push("newExtensions"),n&Zi.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}}class Z_{constructor(e={}){this.entrustVers="",this.entrustInfoFlags=new X_,Object.assign(this,e)}}g([_({type:x.GeneralString})],Z_.prototype,"entrustVers",void 0);g([_({type:X_})],Z_.prototype,"entrustInfoFlags",void 0);var od;let Lf=od=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,od.prototype)}};Lf=od=g([M({type:B.Sequence,itemType:Eo})],Lf);class X{constructor(e={}){this.algorithm="",Object.assign(this,e)}isEqual(e){return e instanceof X&&e.algorithm==this.algorithm&&(e.parameters&&this.parameters&&Dm(e.parameters,this.parameters)||e.parameters===this.parameters)}}g([_({type:x.ObjectIdentifier})],X.prototype,"algorithm",void 0);g([_({type:x.Any,optional:!0})],X.prototype,"parameters",void 0);class Gt{constructor(e={}){this.algorithm=new X,this.subjectPublicKey=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:X})],Gt.prototype,"algorithm",void 0);g([_({type:x.BitString})],Gt.prototype,"subjectPublicKey",void 0);let ot=class{constructor(e){if(e)if(typeof e=="string"||typeof e=="number"||e instanceof Date){const n=new Date(e);n.getUTCFullYear()>2049?this.generalTime=n:this.utcTime=n}else Object.assign(this,e)}getTime(){const e=this.utcTime||this.generalTime;if(!e)throw new Error("Cannot get time from CHOICE object");return e}};g([_({type:x.UTCTime})],ot.prototype,"utcTime",void 0);g([_({type:x.GeneralizedTime})],ot.prototype,"generalTime",void 0);ot=g([M({type:B.Choice})],ot);class Co{constructor(e){this.notBefore=new ot(new Date),this.notAfter=new ot(new Date),e&&(this.notBefore=new ot(e.notBefore),this.notAfter=new ot(e.notAfter))}}g([_({type:ot})],Co.prototype,"notBefore",void 0);g([_({type:ot})],Co.prototype,"notAfter",void 0);var sd;let Ut=class Y_{constructor(e={}){this.extnID="",this.critical=Y_.CRITICAL,this.extnValue=new ke,Object.assign(this,e)}};Ut.CRITICAL=!1;g([_({type:x.ObjectIdentifier})],Ut.prototype,"extnID",void 0);g([_({type:x.Boolean,defaultValue:Ut.CRITICAL})],Ut.prototype,"critical",void 0);g([_({type:ke})],Ut.prototype,"extnValue",void 0);let Wn=sd=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,sd.prototype)}};Wn=sd=g([M({type:B.Sequence,itemType:Ut})],Wn);var $r;(function(t){t[t.v1=0]="v1",t[t.v2=1]="v2",t[t.v3=2]="v3"})($r||($r={}));class jt{constructor(e={}){this.version=$r.v1,this.serialNumber=new ArrayBuffer(0),this.signature=new X,this.issuer=new Ve,this.validity=new Co,this.subject=new Ve,this.subjectPublicKeyInfo=new Gt,Object.assign(this,e)}}g([_({type:x.Integer,context:0,defaultValue:$r.v1})],jt.prototype,"version",void 0);g([_({type:x.Integer,converter:je})],jt.prototype,"serialNumber",void 0);g([_({type:X})],jt.prototype,"signature",void 0);g([_({type:Ve})],jt.prototype,"issuer",void 0);g([_({type:Co})],jt.prototype,"validity",void 0);g([_({type:Ve})],jt.prototype,"subject",void 0);g([_({type:Gt})],jt.prototype,"subjectPublicKeyInfo",void 0);g([_({type:x.BitString,context:1,implicit:!0,optional:!0})],jt.prototype,"issuerUniqueID",void 0);g([_({type:x.BitString,context:2,implicit:!0,optional:!0})],jt.prototype,"subjectUniqueID",void 0);g([_({type:Wn,context:3,optional:!0})],jt.prototype,"extensions",void 0);class kr{constructor(e={}){this.tbsCertificate=new jt,this.signatureAlgorithm=new X,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:jt})],kr.prototype,"tbsCertificate",void 0);g([_({type:X})],kr.prototype,"signatureAlgorithm",void 0);g([_({type:x.BitString})],kr.prototype,"signatureValue",void 0);class uc{constructor(e={}){this.userCertificate=new ArrayBuffer(0),this.revocationDate=new ot,Object.assign(this,e)}}g([_({type:x.Integer,converter:je})],uc.prototype,"userCertificate",void 0);g([_({type:ot})],uc.prototype,"revocationDate",void 0);g([_({type:Ut,optional:!0,repeated:"sequence"})],uc.prototype,"crlEntryExtensions",void 0);class Pn{constructor(e={}){this.signature=new X,this.issuer=new Ve,this.thisUpdate=new ot,Object.assign(this,e)}}g([_({type:x.Integer,optional:!0})],Pn.prototype,"version",void 0);g([_({type:X})],Pn.prototype,"signature",void 0);g([_({type:Ve})],Pn.prototype,"issuer",void 0);g([_({type:ot})],Pn.prototype,"thisUpdate",void 0);g([_({type:ot,optional:!0})],Pn.prototype,"nextUpdate",void 0);g([_({type:uc,repeated:"sequence",optional:!0})],Pn.prototype,"revokedCertificates",void 0);g([_({type:Ut,optional:!0,context:0,repeated:"sequence"})],Pn.prototype,"crlExtensions",void 0);class Xu{constructor(e={}){this.tbsCertList=new Pn,this.signatureAlgorithm=new X,this.signature=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:Pn})],Xu.prototype,"tbsCertList",void 0);g([_({type:X})],Xu.prototype,"signatureAlgorithm",void 0);g([_({type:x.BitString})],Xu.prototype,"signature",void 0);class Si{constructor(e={}){this.issuer=new Ve,this.serialNumber=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:Ve})],Si.prototype,"issuer",void 0);g([_({type:x.Integer,converter:je})],Si.prototype,"serialNumber",void 0);let ai=class{constructor(e={}){Object.assign(this,e)}};g([_({type:Vn,context:0,implicit:!0})],ai.prototype,"subjectKeyIdentifier",void 0);g([_({type:Si})],ai.prototype,"issuerAndSerialNumber",void 0);ai=g([M({type:B.Choice})],ai);var An;(function(t){t[t.v0=0]="v0",t[t.v1=1]="v1",t[t.v2=2]="v2",t[t.v3=3]="v3",t[t.v4=4]="v4",t[t.v5=5]="v5"})(An||(An={}));let ao=class extends X{};ao=g([M({type:B.Sequence})],ao);let ta=class extends X{};ta=g([M({type:B.Sequence})],ta);let pn=class extends X{};pn=g([M({type:B.Sequence})],pn);let na=class extends X{};na=g([M({type:B.Sequence})],na);let Uf=class extends X{};Uf=g([M({type:B.Sequence})],Uf);let ad=class extends X{};ad=g([M({type:B.Sequence})],ad);let zi=class{constructor(e={}){this.attrType="",this.attrValues=[],Object.assign(this,e)}};g([_({type:x.ObjectIdentifier})],zi.prototype,"attrType",void 0);g([_({type:x.Any,repeated:"set"})],zi.prototype,"attrValues",void 0);var cd;class gn{constructor(e={}){this.version=An.v0,this.sid=new ai,this.digestAlgorithm=new ao,this.signatureAlgorithm=new ta,this.signature=new ke,Object.assign(this,e)}}g([_({type:x.Integer})],gn.prototype,"version",void 0);g([_({type:ai})],gn.prototype,"sid",void 0);g([_({type:ao})],gn.prototype,"digestAlgorithm",void 0);g([_({type:zi,repeated:"set",context:0,implicit:!0,optional:!0})],gn.prototype,"signedAttrs",void 0);g([_({type:ta})],gn.prototype,"signatureAlgorithm",void 0);g([_({type:ke})],gn.prototype,"signature",void 0);g([_({type:zi,repeated:"set",context:1,implicit:!0,optional:!0})],gn.prototype,"unsignedAttrs",void 0);let ra=cd=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,cd.prototype)}};ra=cd=g([M({type:B.Set,itemType:gn})],ra);let Df=class extends ot{};Df=g([M({type:B.Choice})],Df);let Mf=class extends gn{};Mf=g([M({type:B.Sequence})],Mf);class Zu{constructor(e={}){this.acIssuer=new me,this.acSerial=0,this.attrs=[],Object.assign(this,e)}}g([_({type:me})],Zu.prototype,"acIssuer",void 0);g([_({type:x.Integer})],Zu.prototype,"acSerial",void 0);g([_({type:zn,repeated:"sequence"})],Zu.prototype,"attrs",void 0);var ld;let ia=ld=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,ld.prototype)}};ia=ld=g([M({type:B.Sequence,itemType:x.ObjectIdentifier})],ia);class pc{constructor(e={}){this.permitUnSpecified=!0,Object.assign(this,e)}}g([_({type:x.Integer,optional:!0})],pc.prototype,"pathLenConstraint",void 0);g([_({type:ia,implicit:!0,context:0,optional:!0})],pc.prototype,"permittedAttrs",void 0);g([_({type:ia,implicit:!0,context:1,optional:!0})],pc.prototype,"excludedAttrs",void 0);g([_({type:x.Boolean,defaultValue:!0})],pc.prototype,"permitUnSpecified",void 0);class Tr{constructor(e={}){this.issuer=new gt,this.serial=new ArrayBuffer(0),this.issuerUID=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:gt})],Tr.prototype,"issuer",void 0);g([_({type:x.Integer,converter:je})],Tr.prototype,"serial",void 0);g([_({type:x.BitString,optional:!0})],Tr.prototype,"issuerUID",void 0);var dd;(function(t){t[t.publicKey=0]="publicKey",t[t.publicKeyCert=1]="publicKeyCert",t[t.otherObjectTypes=2]="otherObjectTypes"})(dd||(dd={}));class Pr{constructor(e={}){this.digestedObjectType=dd.publicKey,this.digestAlgorithm=new X,this.objectDigest=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.Enumerated})],Pr.prototype,"digestedObjectType",void 0);g([_({type:x.ObjectIdentifier,optional:!0})],Pr.prototype,"otherObjectTypeID",void 0);g([_({type:X})],Pr.prototype,"digestAlgorithm",void 0);g([_({type:x.BitString})],Pr.prototype,"objectDigest",void 0);class fc{constructor(e={}){Object.assign(this,e)}}g([_({type:gt,optional:!0})],fc.prototype,"issuerName",void 0);g([_({type:Tr,context:0,implicit:!0,optional:!0})],fc.prototype,"baseCertificateID",void 0);g([_({type:Pr,context:1,implicit:!0,optional:!0})],fc.prototype,"objectDigestInfo",void 0);let ci=class{constructor(e={}){Object.assign(this,e)}};g([_({type:me,repeated:"sequence"})],ci.prototype,"v1Form",void 0);g([_({type:fc,context:0,implicit:!0})],ci.prototype,"v2Form",void 0);ci=g([M({type:B.Choice})],ci);class hc{constructor(e={}){this.notBeforeTime=new Date,this.notAfterTime=new Date,Object.assign(this,e)}}g([_({type:x.GeneralizedTime})],hc.prototype,"notBeforeTime",void 0);g([_({type:x.GeneralizedTime})],hc.prototype,"notAfterTime",void 0);class No{constructor(e={}){Object.assign(this,e)}}g([_({type:Tr,implicit:!0,context:0,optional:!0})],No.prototype,"baseCertificateID",void 0);g([_({type:gt,implicit:!0,context:1,optional:!0})],No.prototype,"entityName",void 0);g([_({type:Pr,implicit:!0,context:2,optional:!0})],No.prototype,"objectDigestInfo",void 0);var ud;(function(t){t[t.v2=1]="v2"})(ud||(ud={}));class tn{constructor(e={}){this.version=ud.v2,this.holder=new No,this.issuer=new ci,this.signature=new X,this.serialNumber=new ArrayBuffer(0),this.attrCertValidityPeriod=new hc,this.attributes=[],Object.assign(this,e)}}g([_({type:x.Integer})],tn.prototype,"version",void 0);g([_({type:No})],tn.prototype,"holder",void 0);g([_({type:ci})],tn.prototype,"issuer",void 0);g([_({type:X})],tn.prototype,"signature",void 0);g([_({type:x.Integer,converter:je})],tn.prototype,"serialNumber",void 0);g([_({type:hc})],tn.prototype,"attrCertValidityPeriod",void 0);g([_({type:zn,repeated:"sequence"})],tn.prototype,"attributes",void 0);g([_({type:x.BitString,optional:!0})],tn.prototype,"issuerUniqueID",void 0);g([_({type:Wn,optional:!0})],tn.prototype,"extensions",void 0);class gc{constructor(e={}){this.acinfo=new tn,this.signatureAlgorithm=new X,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:tn})],gc.prototype,"acinfo",void 0);g([_({type:X})],gc.prototype,"signatureAlgorithm",void 0);g([_({type:x.BitString})],gc.prototype,"signatureValue",void 0);var oa;(function(t){t[t.unmarked=1]="unmarked",t[t.unclassified=2]="unclassified",t[t.restricted=4]="restricted",t[t.confidential=8]="confidential",t[t.secret=16]="secret",t[t.topSecret=32]="topSecret"})(oa||(oa={}));class pd extends sc{}class Yu{constructor(e={}){this.type="",this.value=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.ObjectIdentifier,implicit:!0,context:0})],Yu.prototype,"type",void 0);g([_({type:x.Any,implicit:!0,context:1})],Yu.prototype,"value",void 0);class Qu{constructor(e={}){this.policyId="",this.classList=new pd(oa.unclassified),Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],Qu.prototype,"policyId",void 0);g([_({type:pd,defaultValue:new pd(oa.unclassified)})],Qu.prototype,"classList",void 0);g([_({type:Yu,repeated:"set"})],Qu.prototype,"securityCategories",void 0);class mc{constructor(e={}){Object.assign(this,e)}}g([_({type:ke})],mc.prototype,"cotets",void 0);g([_({type:x.ObjectIdentifier})],mc.prototype,"oid",void 0);g([_({type:x.Utf8String})],mc.prototype,"string",void 0);class Q_{constructor(e={}){this.values=[],Object.assign(this,e)}}g([_({type:gt,implicit:!0,context:0,optional:!0})],Q_.prototype,"policyAuthority",void 0);g([_({type:mc,repeated:"sequence"})],Q_.prototype,"values",void 0);var fd;class _c{constructor(e={}){this.targetCertificate=new Tr,Object.assign(this,e)}}g([_({type:Tr})],_c.prototype,"targetCertificate",void 0);g([_({type:me,optional:!0})],_c.prototype,"targetName",void 0);g([_({type:Pr,optional:!0})],_c.prototype,"certDigestInfo",void 0);let li=class{constructor(e={}){Object.assign(this,e)}};g([_({type:me,context:0,implicit:!0})],li.prototype,"targetName",void 0);g([_({type:me,context:1,implicit:!0})],li.prototype,"targetGroup",void 0);g([_({type:_c,context:2,implicit:!0})],li.prototype,"targetCert",void 0);li=g([M({type:B.Choice})],li);let hd=fd=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,fd.prototype)}};hd=fd=g([M({type:B.Sequence,itemType:li})],hd);var gd;let Ff=gd=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,gd.prototype)}};Ff=gd=g([M({type:B.Sequence,itemType:hd})],Ff);class ey{constructor(e={}){Object.assign(this,e)}}g([_({type:gt,implicit:!0,context:0,optional:!0})],ey.prototype,"roleAuthority",void 0);g([_({type:me,implicit:!0,context:1})],ey.prototype,"roleName",void 0);class ep{constructor(e={}){this.service=new me,this.ident=new me,Object.assign(this,e)}}g([_({type:me})],ep.prototype,"service",void 0);g([_({type:me})],ep.prototype,"ident",void 0);g([_({type:ke,optional:!0})],ep.prototype,"authInfo",void 0);var md;class tp{constructor(e={}){this.otherCertFormat="",this.otherCert=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],tp.prototype,"otherCertFormat",void 0);g([_({type:x.Any})],tp.prototype,"otherCert",void 0);let di=class{constructor(e={}){Object.assign(this,e)}};g([_({type:kr})],di.prototype,"certificate",void 0);g([_({type:gc,context:2,implicit:!0})],di.prototype,"v2AttrCert",void 0);g([_({type:tp,context:3,implicit:!0})],di.prototype,"other",void 0);di=g([M({type:B.Choice})],di);let sa=md=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,md.prototype)}};sa=md=g([M({type:B.Set,itemType:di})],sa);class Ai{constructor(e={}){this.contentType="",this.content=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],Ai.prototype,"contentType",void 0);g([_({type:x.Any,context:0})],Ai.prototype,"content",void 0);let co=class{constructor(e={}){Object.assign(this,e)}};g([_({type:ke})],co.prototype,"single",void 0);g([_({type:x.Any})],co.prototype,"any",void 0);co=g([M({type:B.Choice})],co);class yc{constructor(e={}){this.eContentType="",Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],yc.prototype,"eContentType",void 0);g([_({type:co,context:0,optional:!0})],yc.prototype,"eContent",void 0);let lo=class{constructor(e={}){Object.assign(this,e)}};g([_({type:ke,context:0,implicit:!0,optional:!0})],lo.prototype,"value",void 0);g([_({type:ke,converter:Jb,context:0,implicit:!0,optional:!0,repeated:"sequence"})],lo.prototype,"constructedValue",void 0);lo=g([M({type:B.Choice})],lo);class Io{constructor(e={}){this.contentType="",this.contentEncryptionAlgorithm=new na,Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],Io.prototype,"contentType",void 0);g([_({type:na})],Io.prototype,"contentEncryptionAlgorithm",void 0);g([_({type:lo,optional:!0})],Io.prototype,"encryptedContent",void 0);class wc{constructor(e={}){this.keyAttrId="",Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],wc.prototype,"keyAttrId",void 0);g([_({type:x.Any,optional:!0})],wc.prototype,"keyAttr",void 0);var _d;class vc{constructor(e={}){this.subjectKeyIdentifier=new Vn,Object.assign(this,e)}}g([_({type:Vn})],vc.prototype,"subjectKeyIdentifier",void 0);g([_({type:x.GeneralizedTime,optional:!0})],vc.prototype,"date",void 0);g([_({type:wc,optional:!0})],vc.prototype,"other",void 0);let ui=class{constructor(e={}){Object.assign(this,e)}};g([_({type:vc,context:0,implicit:!0,optional:!0})],ui.prototype,"rKeyId",void 0);g([_({type:Si,optional:!0})],ui.prototype,"issuerAndSerialNumber",void 0);ui=g([M({type:B.Choice})],ui);class np{constructor(e={}){this.rid=new ui,this.encryptedKey=new ke,Object.assign(this,e)}}g([_({type:ui})],np.prototype,"rid",void 0);g([_({type:ke})],np.prototype,"encryptedKey",void 0);let aa=_d=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,_d.prototype)}};aa=_d=g([M({type:B.Sequence,itemType:np})],aa);class rp{constructor(e={}){this.algorithm=new X,this.publicKey=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:X})],rp.prototype,"algorithm",void 0);g([_({type:x.BitString})],rp.prototype,"publicKey",void 0);let xr=class{constructor(e={}){Object.assign(this,e)}};g([_({type:Vn,context:0,implicit:!0,optional:!0})],xr.prototype,"subjectKeyIdentifier",void 0);g([_({type:rp,context:1,implicit:!0,optional:!0})],xr.prototype,"originatorKey",void 0);g([_({type:Si,optional:!0})],xr.prototype,"issuerAndSerialNumber",void 0);xr=g([M({type:B.Choice})],xr);class Ei{constructor(e={}){this.version=An.v3,this.originator=new xr,this.keyEncryptionAlgorithm=new pn,this.recipientEncryptedKeys=new aa,Object.assign(this,e)}}g([_({type:x.Integer})],Ei.prototype,"version",void 0);g([_({type:xr,context:0})],Ei.prototype,"originator",void 0);g([_({type:ke,context:1,optional:!0})],Ei.prototype,"ukm",void 0);g([_({type:pn})],Ei.prototype,"keyEncryptionAlgorithm",void 0);g([_({type:aa})],Ei.prototype,"recipientEncryptedKeys",void 0);let pi=class{constructor(e={}){Object.assign(this,e)}};g([_({type:Vn,context:0,implicit:!0})],pi.prototype,"subjectKeyIdentifier",void 0);g([_({type:Si})],pi.prototype,"issuerAndSerialNumber",void 0);pi=g([M({type:B.Choice})],pi);class jo{constructor(e={}){this.version=An.v0,this.rid=new pi,this.keyEncryptionAlgorithm=new pn,this.encryptedKey=new ke,Object.assign(this,e)}}g([_({type:x.Integer})],jo.prototype,"version",void 0);g([_({type:pi})],jo.prototype,"rid",void 0);g([_({type:pn})],jo.prototype,"keyEncryptionAlgorithm",void 0);g([_({type:ke})],jo.prototype,"encryptedKey",void 0);class Oo{constructor(e={}){this.keyIdentifier=new ke,Object.assign(this,e)}}g([_({type:ke})],Oo.prototype,"keyIdentifier",void 0);g([_({type:x.GeneralizedTime,optional:!0})],Oo.prototype,"date",void 0);g([_({type:wc,optional:!0})],Oo.prototype,"other",void 0);class To{constructor(e={}){this.version=An.v4,this.kekid=new Oo,this.keyEncryptionAlgorithm=new pn,this.encryptedKey=new ke,Object.assign(this,e)}}g([_({type:x.Integer})],To.prototype,"version",void 0);g([_({type:Oo})],To.prototype,"kekid",void 0);g([_({type:pn})],To.prototype,"keyEncryptionAlgorithm",void 0);g([_({type:ke})],To.prototype,"encryptedKey",void 0);class Po{constructor(e={}){this.version=An.v0,this.keyEncryptionAlgorithm=new pn,this.encryptedKey=new ke,Object.assign(this,e)}}g([_({type:x.Integer})],Po.prototype,"version",void 0);g([_({type:ad,context:0,optional:!0})],Po.prototype,"keyDerivationAlgorithm",void 0);g([_({type:pn})],Po.prototype,"keyEncryptionAlgorithm",void 0);g([_({type:ke})],Po.prototype,"encryptedKey",void 0);class ip{constructor(e={}){this.oriType="",this.oriValue=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],ip.prototype,"oriType",void 0);g([_({type:x.Any})],ip.prototype,"oriValue",void 0);let Jn=class{constructor(e={}){Object.assign(this,e)}};g([_({type:jo,optional:!0})],Jn.prototype,"ktri",void 0);g([_({type:Ei,context:1,implicit:!0,optional:!0})],Jn.prototype,"kari",void 0);g([_({type:To,context:2,implicit:!0,optional:!0})],Jn.prototype,"kekri",void 0);g([_({type:Po,context:3,implicit:!0,optional:!0})],Jn.prototype,"pwri",void 0);g([_({type:ip,context:4,implicit:!0,optional:!0})],Jn.prototype,"ori",void 0);Jn=g([M({type:B.Choice})],Jn);var yd;let ca=yd=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,yd.prototype)}};ca=yd=g([M({type:B.Set,itemType:Jn})],ca);var wd;class bc{constructor(e={}){this.otherRevInfoFormat="",this.otherRevInfo=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.ObjectIdentifier})],bc.prototype,"otherRevInfoFormat",void 0);g([_({type:x.Any})],bc.prototype,"otherRevInfo",void 0);let la=class{constructor(e={}){this.other=new bc,Object.assign(this,e)}};g([_({type:bc,context:1,implicit:!0})],la.prototype,"other",void 0);la=g([M({type:B.Choice})],la);let da=wd=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,wd.prototype)}};da=wd=g([M({type:B.Set,itemType:la})],da);class op{constructor(e={}){Object.assign(this,e)}}g([_({type:sa,context:0,implicit:!0,optional:!0})],op.prototype,"certs",void 0);g([_({type:da,context:1,implicit:!0,optional:!0})],op.prototype,"crls",void 0);var vd;let bd=vd=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,vd.prototype)}};bd=vd=g([M({type:B.Set,itemType:zi})],bd);class Ro{constructor(e={}){this.version=An.v0,this.recipientInfos=new ca,this.encryptedContentInfo=new Io,Object.assign(this,e)}}g([_({type:x.Integer})],Ro.prototype,"version",void 0);g([_({type:op,context:0,implicit:!0,optional:!0})],Ro.prototype,"originatorInfo",void 0);g([_({type:ca})],Ro.prototype,"recipientInfos",void 0);g([_({type:Io})],Ro.prototype,"encryptedContentInfo",void 0);g([_({type:bd,context:1,implicit:!0,optional:!0})],Ro.prototype,"unprotectedAttrs",void 0);const b3="1.2.840.113549.1.7.2";var $d;let ua=$d=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,$d.prototype)}};ua=$d=g([M({type:B.Set,itemType:ao})],ua);class Ci{constructor(e={}){this.version=An.v0,this.digestAlgorithms=new ua,this.encapContentInfo=new yc,this.signerInfos=new ra,Object.assign(this,e)}}g([_({type:x.Integer})],Ci.prototype,"version",void 0);g([_({type:ua})],Ci.prototype,"digestAlgorithms",void 0);g([_({type:yc})],Ci.prototype,"encapContentInfo",void 0);g([_({type:sa,context:0,implicit:!0,optional:!0})],Ci.prototype,"certificates",void 0);g([_({type:da,context:1,implicit:!0,optional:!0})],Ci.prototype,"crls",void 0);g([_({type:ra})],Ci.prototype,"signerInfos",void 0);const uo="1.2.840.10045.2.1",sp="1.2.840.10045.4.1",ty="1.2.840.10045.4.3.1",ap="1.2.840.10045.4.3.2",cp="1.2.840.10045.4.3.3",lp="1.2.840.10045.4.3.4",qf="1.2.840.10045.3.1.7",Hf="1.3.132.0.34",Vf="1.3.132.0.35";function Bo(t){return new X({algorithm:t})}const $3=Bo(sp);Bo(ty);const k3=Bo(ap),x3=Bo(cp),S3=Bo(lp);let po=class{constructor(e={}){Object.assign(this,e)}};g([_({type:x.ObjectIdentifier})],po.prototype,"fieldType",void 0);g([_({type:x.Any})],po.prototype,"parameters",void 0);po=g([M({type:B.Sequence})],po);class z3 extends ke{}let fi=class{constructor(e={}){Object.assign(this,e)}};g([_({type:x.OctetString})],fi.prototype,"a",void 0);g([_({type:x.OctetString})],fi.prototype,"b",void 0);g([_({type:x.BitString,optional:!0})],fi.prototype,"seed",void 0);fi=g([M({type:B.Sequence})],fi);var kd;(function(t){t[t.ecpVer1=1]="ecpVer1"})(kd||(kd={}));let En=class{constructor(e={}){this.version=kd.ecpVer1,Object.assign(this,e)}};g([_({type:x.Integer})],En.prototype,"version",void 0);g([_({type:po})],En.prototype,"fieldID",void 0);g([_({type:fi})],En.prototype,"curve",void 0);g([_({type:z3})],En.prototype,"base",void 0);g([_({type:x.Integer,converter:je})],En.prototype,"order",void 0);g([_({type:x.Integer,optional:!0})],En.prototype,"cofactor",void 0);En=g([M({type:B.Sequence})],En);let Xn=class{constructor(e={}){Object.assign(this,e)}};g([_({type:x.ObjectIdentifier})],Xn.prototype,"namedCurve",void 0);g([_({type:x.Null})],Xn.prototype,"implicitCurve",void 0);g([_({type:En})],Xn.prototype,"specifiedCurve",void 0);Xn=g([M({type:B.Choice})],Xn);class $c{constructor(e={}){this.version=1,this.privateKey=new ke,Object.assign(this,e)}}g([_({type:x.Integer})],$c.prototype,"version",void 0);g([_({type:ke})],$c.prototype,"privateKey",void 0);g([_({type:Xn,context:0,optional:!0})],$c.prototype,"parameters",void 0);g([_({type:x.BitString,context:1,optional:!0})],$c.prototype,"publicKey",void 0);class pa{constructor(e={}){this.r=new ArrayBuffer(0),this.s=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.Integer,converter:je})],pa.prototype,"r",void 0);g([_({type:x.Integer,converter:je})],pa.prototype,"s",void 0);const zt="1.2.840.113549.1.1",Sr=`${zt}.1`,A3=`${zt}.7`,E3=`${zt}.9`,Yi=`${zt}.10`,C3=`${zt}.2`,N3=`${zt}.4`,fa=`${zt}.5`,I3=`${zt}.14`,xd=`${zt}.11`,ha=`${zt}.12`,ga=`${zt}.13`,ny=`${zt}.15`,ry=`${zt}.16`,ma="1.3.14.3.2.26",iy="2.16.840.1.101.3.4.2.4",_a="2.16.840.1.101.3.4.2.1",ya="2.16.840.1.101.3.4.2.2",wa="2.16.840.1.101.3.4.2.3",j3="2.16.840.1.101.3.4.2.5",O3="2.16.840.1.101.3.4.2.6",T3="1.2.840.113549.2.2",P3="1.2.840.113549.2.5",kc=`${zt}.8`;function Xe(t){return new X({algorithm:t,parameters:null})}Xe(T3);Xe(P3);const zr=Xe(ma);Xe(iy);Xe(_a);Xe(ya);Xe(wa);Xe(j3);Xe(O3);const oy=new X({algorithm:kc,parameters:H.serialize(zr)}),sy=new X({algorithm:E3,parameters:H.serialize(Ws.toASN(new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer))});Xe(Sr);Xe(C3);Xe(N3);Xe(fa);Xe(ny);Xe(ry);Xe(ha);Xe(ga);Xe(ny);Xe(ry);class xc{constructor(e={}){this.hashAlgorithm=new X(zr),this.maskGenAlgorithm=new X({algorithm:kc,parameters:H.serialize(zr)}),this.pSourceAlgorithm=new X(sy),Object.assign(this,e)}}g([_({type:X,context:0,defaultValue:zr})],xc.prototype,"hashAlgorithm",void 0);g([_({type:X,context:1,defaultValue:oy})],xc.prototype,"maskGenAlgorithm",void 0);g([_({type:X,context:2,defaultValue:sy})],xc.prototype,"pSourceAlgorithm",void 0);new X({algorithm:A3,parameters:H.serialize(new xc)});class Ar{constructor(e={}){this.hashAlgorithm=new X(zr),this.maskGenAlgorithm=new X({algorithm:kc,parameters:H.serialize(zr)}),this.saltLength=20,this.trailerField=1,Object.assign(this,e)}}g([_({type:X,context:0,defaultValue:zr})],Ar.prototype,"hashAlgorithm",void 0);g([_({type:X,context:1,defaultValue:oy})],Ar.prototype,"maskGenAlgorithm",void 0);g([_({type:x.Integer,context:2,defaultValue:20})],Ar.prototype,"saltLength",void 0);g([_({type:x.Integer,context:3,defaultValue:1})],Ar.prototype,"trailerField",void 0);new X({algorithm:Yi,parameters:H.serialize(new Ar)});class Sc{constructor(e={}){this.digestAlgorithm=new X,this.digest=new ke,Object.assign(this,e)}}g([_({type:X})],Sc.prototype,"digestAlgorithm",void 0);g([_({type:ke})],Sc.prototype,"digest",void 0);var Sd;class zc{constructor(e={}){this.prime=new ArrayBuffer(0),this.exponent=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.Integer,converter:je})],zc.prototype,"prime",void 0);g([_({type:x.Integer,converter:je})],zc.prototype,"exponent",void 0);g([_({type:x.Integer,converter:je})],zc.prototype,"coefficient",void 0);let zd=Sd=class extends ze{constructor(e){super(e),Object.setPrototypeOf(this,Sd.prototype)}};zd=Sd=g([M({type:B.Sequence,itemType:zc})],zd);class mn{constructor(e={}){this.version=0,this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),this.privateExponent=new ArrayBuffer(0),this.prime1=new ArrayBuffer(0),this.prime2=new ArrayBuffer(0),this.exponent1=new ArrayBuffer(0),this.exponent2=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.Integer})],mn.prototype,"version",void 0);g([_({type:x.Integer,converter:je})],mn.prototype,"modulus",void 0);g([_({type:x.Integer,converter:je})],mn.prototype,"publicExponent",void 0);g([_({type:x.Integer,converter:je})],mn.prototype,"privateExponent",void 0);g([_({type:x.Integer,converter:je})],mn.prototype,"prime1",void 0);g([_({type:x.Integer,converter:je})],mn.prototype,"prime2",void 0);g([_({type:x.Integer,converter:je})],mn.prototype,"exponent1",void 0);g([_({type:x.Integer,converter:je})],mn.prototype,"exponent2",void 0);g([_({type:x.Integer,converter:je})],mn.prototype,"coefficient",void 0);g([_({type:zd,optional:!0})],mn.prototype,"otherPrimeInfos",void 0);class dp{constructor(e={}){this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),Object.assign(this,e)}}g([_({type:x.Integer,converter:je})],dp.prototype,"modulus",void 0);g([_({type:x.Integer,converter:je})],dp.prototype,"publicExponent",void 0);var Ad;(function(t){t[t.Transient=0]="Transient",t[t.Singleton=1]="Singleton",t[t.ResolutionScoped=2]="ResolutionScoped",t[t.ContainerScoped=3]="ContainerScoped"})(Ad||(Ad={}));const $t=Ad;/*! *****************************************************************************
147
147
  Copyright (c) Microsoft Corporation.
148
148
 
149
149
  Permission to use, copy, modify, and/or distribute this software for any
@@ -182,31 +182,31 @@ PERFORMANCE OF THIS SOFTWARE.
182
182
  * SOFTWARE.
183
183
  *
184
184
  */const Do="crypto.algorithm";class Y3{getAlgorithms(){return lt.resolveAll(Do)}toAsnAlgorithm(e){({...e});for(const n of this.getAlgorithms()){const r=n.toAsnAlgorithm(e);if(r)return r}if(/^[0-9.]+$/.test(e.name)){const n=new X({algorithm:e.name});if("parameters"in e){const r=e;n.parameters=r.parameters}return n}throw new Error("Cannot convert WebCrypto algorithm to ASN.1 algorithm")}toWebAlgorithm(e){for(const r of this.getAlgorithms()){const i=r.toWebAlgorithm(e);if(i)return i}return{name:e.algorithm,parameters:e.parameters}}}const Er="crypto.algorithmProvider";lt.registerSingleton(Er,Y3);var _s;const At="1.3.36.3.3.2.8.1.1",uh=`${At}.1`,ph=`${At}.2`,fh=`${At}.3`,hh=`${At}.4`,gh=`${At}.5`,mh=`${At}.6`,_h=`${At}.7`,yh=`${At}.8`,wh=`${At}.9`,vh=`${At}.10`,bh=`${At}.11`,$h=`${At}.12`,kh=`${At}.13`,xh=`${At}.14`,Sh="brainpoolP160r1",zh="brainpoolP160t1",Ah="brainpoolP192r1",Eh="brainpoolP192t1",Ch="brainpoolP224r1",Nh="brainpoolP224t1",Ih="brainpoolP256r1",jh="brainpoolP256t1",Oh="brainpoolP320r1",Th="brainpoolP320t1",Ph="brainpoolP384r1",Rh="brainpoolP384t1",Bh="brainpoolP512r1",Lh="brainpoolP512t1",Pe="ECDSA";let ho=_s=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case Pe.toLowerCase():if("hash"in e)switch((typeof e.hash=="string"?e.hash:e.hash.name).toLowerCase()){case"sha-1":return $3;case"sha-256":return k3;case"sha-384":return x3;case"sha-512":return S3}else if("namedCurve"in e){let n="";switch(e.namedCurve){case"P-256":n=qf;break;case"K-256":n=_s.SECP256K1;break;case"P-384":n=Hf;break;case"P-521":n=Vf;break;case Sh:n=uh;break;case zh:n=ph;break;case Ah:n=fh;break;case Eh:n=hh;break;case Ch:n=gh;break;case Nh:n=mh;break;case Ih:n=_h;break;case jh:n=yh;break;case Oh:n=wh;break;case Th:n=vh;break;case Ph:n=bh;break;case Rh:n=$h;break;case Bh:n=kh;break;case Lh:n=xh;break}if(n)return new X({algorithm:uo,parameters:H.serialize(new Xn({namedCurve:n}))})}}return null}toWebAlgorithm(e){switch(e.algorithm){case sp:return{name:Pe,hash:{name:"SHA-1"}};case ap:return{name:Pe,hash:{name:"SHA-256"}};case cp:return{name:Pe,hash:{name:"SHA-384"}};case lp:return{name:Pe,hash:{name:"SHA-512"}};case uo:{if(!e.parameters)throw new TypeError("Cannot get required parameters from EC algorithm");switch(H.parse(e.parameters,Xn).namedCurve){case qf:return{name:Pe,namedCurve:"P-256"};case _s.SECP256K1:return{name:Pe,namedCurve:"K-256"};case Hf:return{name:Pe,namedCurve:"P-384"};case Vf:return{name:Pe,namedCurve:"P-521"};case uh:return{name:Pe,namedCurve:Sh};case ph:return{name:Pe,namedCurve:zh};case fh:return{name:Pe,namedCurve:Ah};case hh:return{name:Pe,namedCurve:Eh};case gh:return{name:Pe,namedCurve:Ch};case mh:return{name:Pe,namedCurve:Nh};case _h:return{name:Pe,namedCurve:Ih};case yh:return{name:Pe,namedCurve:jh};case wh:return{name:Pe,namedCurve:Oh};case vh:return{name:Pe,namedCurve:Th};case bh:return{name:Pe,namedCurve:Ph};case $h:return{name:Pe,namedCurve:Rh};case kh:return{name:Pe,namedCurve:Bh};case xh:return{name:Pe,namedCurve:Lh}}}}return null}};ho.SECP256K1="1.3.132.0.10";ho=_s=g([Ac()],ho);lt.registerSingleton(Do,ho);const _y=Symbol("name"),yy=Symbol("value");class xe{constructor(e,n={},r=""){this[_y]=e,this[yy]=r;for(const i in n)this[i]=n[i]}}xe.NAME=_y;xe.VALUE=yy;class Q3{static toTextObject(e){const n=new xe("Algorithm Identifier",{},er.toString(e.algorithm));if(e.parameters)switch(e.algorithm){case uo:{const r=new ho().toWebAlgorithm(e);r&&"namedCurve"in r?n["Named Curve"]=r.namedCurve:n.Parameters=e.parameters;break}default:n.Parameters=e.parameters}return n}}class er{static toString(e){const n=this.items[e];return n||e}}er.items={[ma]:"sha1",[iy]:"sha224",[_a]:"sha256",[ya]:"sha384",[wa]:"sha512",[Sr]:"rsaEncryption",[fa]:"sha1WithRSAEncryption",[I3]:"sha224WithRSAEncryption",[xd]:"sha256WithRSAEncryption",[ha]:"sha384WithRSAEncryption",[ga]:"sha512WithRSAEncryption",[uo]:"ecPublicKey",[sp]:"ecdsaWithSHA1",[ty]:"ecdsaWithSHA224",[ap]:"ecdsaWithSHA256",[cp]:"ecdsaWithSHA384",[lp]:"ecdsaWithSHA512",[g3]:"TLS WWW server authentication",[m3]:"TLS WWW client authentication",[_3]:"Code Signing",[y3]:"E-mail Protection",[w3]:"Time Stamping",[v3]:"OCSP Signing",[b3]:"Signed Data"};class Cr{static serialize(e){return this.serializeObj(e).join(`
185
- `)}static pad(e=0){return"".padStart(2*e," ")}static serializeObj(e,n=0){const r=[];let i=this.pad(n++),s="";const a=e[xe.VALUE];a&&(s=` ${a}`),r.push(`${i}${e[xe.NAME]}:${s}`),i=this.pad(n);for(const c in e){if(typeof c=="symbol")continue;const l=e[c],d=c?`${c}: `:"";if(typeof l=="string"||typeof l=="number"||typeof l=="boolean")r.push(`${i}${d}${l}`);else if(l instanceof Date)r.push(`${i}${d}${l.toUTCString()}`);else if(Array.isArray(l))for(const u of l)u[xe.NAME]=c,r.push(...this.serializeObj(u,n));else if(l instanceof xe)l[xe.NAME]=c,r.push(...this.serializeObj(l,n));else if(G.isBufferSource(l))c?(r.push(`${i}${d}`),r.push(...this.serializeBufferSource(l,n+1))):r.push(...this.serializeBufferSource(l,n));else if("toTextObject"in l){const u=l.toTextObject();u[xe.NAME]=c,r.push(...this.serializeObj(u,n))}else throw new TypeError("Cannot serialize data in text format. Unsupported type.")}return r}static serializeBufferSource(e,n=0){const r=this.pad(n),i=G.toUint8Array(e),s=[];for(let a=0;a<i.length;){const c=[];for(let l=0;l<16&&a<i.length;l++){l===8&&c.push("");const d=i[a++].toString(16).padStart(2,"0");c.push(d)}s.push(`${r}${c.join(" ")}`)}return s}static serializeAlgorithm(e){return this.algorithmSerializer.toTextObject(e)}}Cr.oidSerializer=er;Cr.algorithmSerializer=Q3;class tr{constructor(...e){if(e.length===1){const n=e[0];this.rawData=H.serialize(n),this.onInit(n)}else{const n=H.parse(e[0],e[1]);this.rawData=G.toArrayBuffer(e[0]),this.onInit(n)}}equal(e){return e instanceof tr?Dm(e.rawData,this.rawData):!1}toString(e="text"){switch(e){case"asn":return H.toString(this.rawData);case"text":return Cr.serialize(this.toTextObject());case"hex":return re.ToHex(this.rawData);case"base64":return re.ToBase64(this.rawData);case"base64url":return re.ToBase64Url(this.rawData);default:throw TypeError("Argument 'format' is unsupported value")}}getTextName(){return this.constructor.NAME}toTextObject(){const e=this.toTextObjectEmpty();return e[""]=this.rawData,e}toTextObjectEmpty(e){return new xe(this.getTextName(),{},e)}}tr.NAME="ASN";class Tt extends tr{constructor(...e){let n;G.isBufferSource(e[0])?n=G.toArrayBuffer(e[0]):n=H.serialize(new Ut({extnID:e[0],critical:e[1],extnValue:new ke(G.toArrayBuffer(e[2]))})),super(n,Ut)}onInit(e){this.type=e.extnID,this.critical=e.critical,this.value=e.extnValue.buffer}toTextObject(){const e=this.toTextObjectWithoutValue();return e[""]=this.value,e}toTextObjectWithoutValue(){const e=this.toTextObjectEmpty(this.critical?"critical":void 0);return e[xe.NAME]===Tt.NAME&&(e[xe.NAME]=er.toString(this.type)),e}}var wy;class Fn{static isCryptoKeyPair(e){return e&&e.privateKey&&e.publicKey}static isCryptoKey(e){return e&&e.usages&&e.type&&e.algorithm&&e.extractable!==void 0}constructor(){this.items=new Map,this[wy]="CryptoProvider",typeof self<"u"&&typeof crypto<"u"?this.set(Fn.DEFAULT,crypto):typeof global<"u"&&global.crypto&&global.crypto.subtle&&this.set(Fn.DEFAULT,global.crypto)}clear(){this.items.clear()}delete(e){return this.items.delete(e)}forEach(e,n){return this.items.forEach(e,n)}has(e){return this.items.has(e)}get size(){return this.items.size}entries(){return this.items.entries()}keys(){return this.items.keys()}values(){return this.items.values()}[Symbol.iterator](){return this.items[Symbol.iterator]()}get(e=Fn.DEFAULT){const n=this.items.get(e.toLowerCase());if(!n)throw new Error(`Cannot get Crypto by name '${e}'`);return n}set(e,n){if(typeof e=="string"){if(!n)throw new TypeError("Argument 'value' is required");this.items.set(e.toLowerCase(),n)}else this.items.set(Fn.DEFAULT,e);return this}}wy=Symbol.toStringTag;Fn.DEFAULT="default";const it=new Fn,e$=/^[0-2](?:\.[1-9][0-9]*)+$/;function t$(t){return new RegExp(e$).test(t)}class vy{constructor(e={}){this.items={};for(const n in e)this.register(n,e[n])}get(e){return this.items[e]||null}findId(e){return t$(e)?e:this.get(e)}register(e,n){this.items[e]=n,this.items[n]=e}}const xt=new vy;xt.register("CN","2.5.4.3");xt.register("L","2.5.4.7");xt.register("ST","2.5.4.8");xt.register("O","2.5.4.10");xt.register("OU","2.5.4.11");xt.register("C","2.5.4.6");xt.register("DC","0.9.2342.19200300.100.1.25");xt.register("E","1.2.840.113549.1.9.1");xt.register("G","2.5.4.42");xt.register("I","2.5.4.43");xt.register("SN","2.5.4.4");xt.register("T","2.5.4.12");function n$(t,e){return`\\${re.ToHex(re.FromUtf8String(e)).toUpperCase()}`}function r$(t){return t.replace(/([,+"\\<>;])/g,"\\$1").replace(/^([ #])/,"\\$1").replace(/([ ]$)/,"\\$1").replace(/([\r\n\t])/,n$)}class Rt{static isASCII(e){for(let n=0;n<e.length;n++)if(e.charCodeAt(n)>255)return!1;return!0}static isPrintableString(e){return/^[A-Za-z0-9 '()+,-./:=?]*$/g.test(e)}constructor(e,n={}){this.extraNames=new vy,this.asn=new Ve;for(const r in n)if(Object.prototype.hasOwnProperty.call(n,r)){const i=n[r];this.extraNames.register(r,i)}typeof e=="string"?this.asn=this.fromString(e):e instanceof Ve?this.asn=e:G.isBufferSource(e)?this.asn=H.parse(e,Ve):this.asn=this.fromJSON(e)}getField(e){const n=this.extraNames.findId(e)||xt.findId(e),r=[];for(const i of this.asn)for(const s of i)s.type===n&&r.push(s.value.toString());return r}getName(e){return this.extraNames.get(e)||xt.get(e)}toString(){return this.asn.map(e=>e.map(n=>{const r=this.getName(n.type)||n.type,i=n.value.anyValue?`#${re.ToHex(n.value.anyValue)}`:r$(n.value.toString());return`${r}=${i}`}).join("+")).join(", ")}toJSON(){var e;const n=[];for(const r of this.asn){const i={};for(const s of r){const a=this.getName(s.type)||s.type;(e=i[a])!==null&&e!==void 0||(i[a]=[]),i[a].push(s.value.anyValue?`#${re.ToHex(s.value.anyValue)}`:s.value.toString())}n.push(i)}return n}fromString(e){const n=new Ve,r=/(\d\.[\d.]*\d|[A-Za-z]+)=((?:"")|(?:".*?[^\\]")|(?:[^,+"\\](?=[,+]|$))|(?:[^,+].*?(?:[^\\][,+]))|(?:))([,+])?/g;let i=null,s=",";for(;i=r.exec(`${e},`);){let[,a,c]=i;const l=c[c.length-1];(l===","||l==="+")&&(c=c.slice(0,c.length-1),i[3]=l);const d=i[3];a=this.getTypeOid(a);const u=this.createAttribute(a,c);s==="+"?n[n.length-1].push(u):n.push(new si([u])),s=d}return n}fromJSON(e){const n=new Ve;for(const r of e){const i=new si;for(const s in r){const a=this.getTypeOid(s),c=r[s];for(const l of c){const d=this.createAttribute(a,l);i.push(d)}}n.push(i)}return n}getTypeOid(e){if(/[\d.]+/.test(e)||(e=this.getName(e)||""),!e)throw new Error(`Cannot get OID for name type '${e}'`);return e}createAttribute(e,n){const r=new ac({type:e});if(typeof n=="object")for(const i in n)switch(i){case"ia5String":r.value.ia5String=n[i];break;case"utf8String":r.value.utf8String=n[i];break;case"universalString":r.value.universalString=n[i];break;case"bmpString":r.value.bmpString=n[i];break;case"printableString":r.value.printableString=n[i];break}else if(n[0]==="#")r.value.anyValue=re.FromHex(n.slice(1));else{const i=this.processStringValue(n);e===this.getName("E")||e===this.getName("DC")?r.value.ia5String=i:Rt.isPrintableString(i)?r.value.printableString=i:r.value.utf8String=i}return r}processStringValue(e){const n=/"(.*?[^\\])?"/.exec(e);return n&&(e=n[1]),e.replace(/\\0a/ig,`
186
- `).replace(/\\0d/ig,"\r").replace(/\\0g/ig," ").replace(/\\(.)/g,"$1")}toArrayBuffer(){return H.serialize(this.asn)}async getThumbprint(...e){var n;let r,i="SHA-1";return e.length>=1&&!(!((n=e[0])===null||n===void 0)&&n.subtle)?(i=e[0]||i,r=e[1]||it.get()):r=e[0]||it.get(),await r.subtle.digest(i,this.toArrayBuffer())}}const by="Cannot initialize GeneralName from ASN.1 data.",Uh=`${by} Unsupported string format in use.`,i$=`${by} Value doesn't match to GUID regular expression.`,Dh=/^([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})$/i,Mh="1.3.6.1.4.1.311.25.1",Fh="1.3.6.1.4.1.311.20.2.3",Yc="dns",Qc="dn",el="email",tl="ip",nl="url",rl="guid",il="upn",ss="id";class qn extends tr{constructor(...e){let n;if(e.length===2)switch(e[0]){case Qc:{const r=new Rt(e[1]).toArrayBuffer(),i=H.parse(r,Ve);n=new me({directoryName:i});break}case Yc:n=new me({dNSName:e[1]});break;case el:n=new me({rfc822Name:e[1]});break;case rl:{const r=new RegExp(Dh,"i").exec(e[1]);if(!r)throw new Error("Cannot parse GUID value. Value doesn't match to regular expression");const i=r.slice(1).map((s,a)=>a<3?re.ToHex(new Uint8Array(re.FromHex(s)).reverse()):s).join("");n=new me({otherName:new so({typeId:Mh,value:H.serialize(new ke(re.FromHex(i)))})});break}case tl:n=new me({iPAddress:e[1]});break;case ss:n=new me({registeredID:e[1]});break;case il:{n=new me({otherName:new so({typeId:Fh,value:H.serialize(B_.toASN(e[1]))})});break}case nl:n=new me({uniformResourceIdentifier:e[1]});break;default:throw new Error("Cannot create GeneralName. Unsupported type of the name")}else G.isBufferSource(e[0])?n=H.parse(e[0],me):n=e[0];super(n)}onInit(e){if(e.dNSName!=null)this.type=Yc,this.value=e.dNSName;else if(e.rfc822Name!=null)this.type=el,this.value=e.rfc822Name;else if(e.iPAddress!=null)this.type=tl,this.value=e.iPAddress;else if(e.uniformResourceIdentifier!=null)this.type=nl,this.value=e.uniformResourceIdentifier;else if(e.registeredID!=null)this.type=ss,this.value=e.registeredID;else if(e.directoryName!=null)this.type=Qc,this.value=new Rt(e.directoryName).toString();else if(e.otherName!=null)if(e.otherName.typeId===Mh){this.type=rl;const n=H.parse(e.otherName.value,ke),r=new RegExp(Dh,"i").exec(re.ToHex(n));if(!r)throw new Error(i$);this.value=r.slice(1).map((i,s)=>s<3?re.ToHex(new Uint8Array(re.FromHex(i)).reverse()):i).join("-")}else if(e.otherName.typeId===Fh)this.type=il,this.value=H.parse(e.otherName.value,ct).toString();else throw new Error(Uh);else throw new Error(Uh)}toJSON(){return{type:this.type,value:this.value}}toTextObject(){let e;switch(this.type){case Qc:case Yc:case rl:case tl:case ss:case il:case nl:e=this.type.toUpperCase();break;case el:e="Email";break;default:throw new Error("Unsupported GeneralName type")}let n=this.value;return this.type===ss&&(n=er.toString(n)),new xe(e,void 0,n)}}class Nr extends tr{constructor(e){let n;if(e instanceof gt)n=e;else if(Array.isArray(e)){const r=[];for(const i of e)if(i instanceof me)r.push(i);else{const s=H.parse(new qn(i.type,i.value).rawData,me);r.push(s)}n=new gt(r)}else if(G.isBufferSource(e))n=H.parse(e,gt);else throw new Error("Cannot initialize GeneralNames. Incorrect incoming arguments");super(n)}onInit(e){const n=[];for(const r of e){let i=null;try{i=new qn(r)}catch{continue}n.push(i)}this.items=n}toJSON(){return this.items.map(e=>e.toJSON())}toTextObject(){const e=super.toTextObjectEmpty();for(const n of this.items){const r=n.toTextObject();let i=e[r[xe.NAME]];Array.isArray(i)||(i=[],e[r[xe.NAME]]=i),i.push(r)}return e}}Nr.NAME="GeneralNames";const Qi="-{5}",go="\\n",o$=`[^${go}]+`,s$=`${Qi}BEGIN (${o$}(?=${Qi}))${Qi}`,a$=`${Qi}END \\1${Qi}`,hi="\\n",c$=`[^:${go}]+`,l$=`(?:[^${go}]+${hi}(?: +[^${go}]+${hi})*)`,d$="[a-zA-Z0-9=+/]+",u$=`(?:${d$}${hi})+`,qh=`${s$}${hi}(?:((?:${c$}: ${l$})+))?${hi}?(${u$})${a$}`;class Ct{static isPem(e){return typeof e=="string"&&new RegExp(qh,"g").test(e.replace(/\r/g,""))}static decodeWithHeaders(e){e=e.replace(/\r/g,"");const n=new RegExp(qh,"g"),r=[];let i=null;for(;i=n.exec(e);){const s=i[3].replace(new RegExp(`[${go}]+`,"g"),""),a={type:i[1],headers:[],rawData:re.FromBase64(s)},c=i[2];if(c){const l=c.split(new RegExp(hi,"g"));let d=null;for(const u of l){const[f,h]=u.split(/:(.*)/);if(h===void 0){if(!d)throw new Error("Cannot parse PEM string. Incorrect header value");d.value+=f.trim()}else d&&a.headers.push(d),d={key:f,value:h.trim()}}d&&a.headers.push(d)}r.push(a)}return r}static decode(e){return this.decodeWithHeaders(e).map(r=>r.rawData)}static decodeFirst(e){const n=this.decode(e);if(!n.length)throw new RangeError("PEM string doesn't contain any objects");return n[0]}static encode(e,n){if(Array.isArray(e)){const r=new Array;return n?e.forEach(i=>{if(!G.isBufferSource(i))throw new TypeError("Cannot encode array of BufferSource in PEM format. Not all items of the array are BufferSource");r.push(this.encodeStruct({type:n,rawData:G.toArrayBuffer(i)}))}):e.forEach(i=>{if(!("type"in i))throw new TypeError("Cannot encode array of PemStruct in PEM format. Not all items of the array are PemStrut");r.push(this.encodeStruct(i))}),r.join(`
185
+ `)}static pad(e=0){return"".padStart(2*e," ")}static serializeObj(e,n=0){const r=[];let i=this.pad(n++),s="";const a=e[xe.VALUE];a&&(s=` ${a}`),r.push(`${i}${e[xe.NAME]}:${s}`),i=this.pad(n);for(const c in e){if(typeof c=="symbol")continue;const l=e[c],d=c?`${c}: `:"";if(typeof l=="string"||typeof l=="number"||typeof l=="boolean")r.push(`${i}${d}${l}`);else if(l instanceof Date)r.push(`${i}${d}${l.toUTCString()}`);else if(Array.isArray(l))for(const u of l)u[xe.NAME]=c,r.push(...this.serializeObj(u,n));else if(l instanceof xe)l[xe.NAME]=c,r.push(...this.serializeObj(l,n));else if(G.isBufferSource(l))c?(r.push(`${i}${d}`),r.push(...this.serializeBufferSource(l,n+1))):r.push(...this.serializeBufferSource(l,n));else if("toTextObject"in l){const u=l.toTextObject();u[xe.NAME]=c,r.push(...this.serializeObj(u,n))}else throw new TypeError("Cannot serialize data in text format. Unsupported type.")}return r}static serializeBufferSource(e,n=0){const r=this.pad(n),i=G.toUint8Array(e),s=[];for(let a=0;a<i.length;){const c=[];for(let l=0;l<16&&a<i.length;l++){l===8&&c.push("");const d=i[a++].toString(16).padStart(2,"0");c.push(d)}s.push(`${r}${c.join(" ")}`)}return s}static serializeAlgorithm(e){return this.algorithmSerializer.toTextObject(e)}}Cr.oidSerializer=er;Cr.algorithmSerializer=Q3;class tr{constructor(...e){if(e.length===1){const n=e[0];this.rawData=H.serialize(n),this.onInit(n)}else{const n=H.parse(e[0],e[1]);this.rawData=G.toArrayBuffer(e[0]),this.onInit(n)}}equal(e){return e instanceof tr?Dm(e.rawData,this.rawData):!1}toString(e="text"){switch(e){case"asn":return H.toString(this.rawData);case"text":return Cr.serialize(this.toTextObject());case"hex":return re.ToHex(this.rawData);case"base64":return re.ToBase64(this.rawData);case"base64url":return re.ToBase64Url(this.rawData);default:throw TypeError("Argument 'format' is unsupported value")}}getTextName(){return this.constructor.NAME}toTextObject(){const e=this.toTextObjectEmpty();return e[""]=this.rawData,e}toTextObjectEmpty(e){return new xe(this.getTextName(),{},e)}}tr.NAME="ASN";class Ot extends tr{constructor(...e){let n;G.isBufferSource(e[0])?n=G.toArrayBuffer(e[0]):n=H.serialize(new Ut({extnID:e[0],critical:e[1],extnValue:new ke(G.toArrayBuffer(e[2]))})),super(n,Ut)}onInit(e){this.type=e.extnID,this.critical=e.critical,this.value=e.extnValue.buffer}toTextObject(){const e=this.toTextObjectWithoutValue();return e[""]=this.value,e}toTextObjectWithoutValue(){const e=this.toTextObjectEmpty(this.critical?"critical":void 0);return e[xe.NAME]===Ot.NAME&&(e[xe.NAME]=er.toString(this.type)),e}}var wy;class Fn{static isCryptoKeyPair(e){return e&&e.privateKey&&e.publicKey}static isCryptoKey(e){return e&&e.usages&&e.type&&e.algorithm&&e.extractable!==void 0}constructor(){this.items=new Map,this[wy]="CryptoProvider",typeof self<"u"&&typeof crypto<"u"?this.set(Fn.DEFAULT,crypto):typeof global<"u"&&global.crypto&&global.crypto.subtle&&this.set(Fn.DEFAULT,global.crypto)}clear(){this.items.clear()}delete(e){return this.items.delete(e)}forEach(e,n){return this.items.forEach(e,n)}has(e){return this.items.has(e)}get size(){return this.items.size}entries(){return this.items.entries()}keys(){return this.items.keys()}values(){return this.items.values()}[Symbol.iterator](){return this.items[Symbol.iterator]()}get(e=Fn.DEFAULT){const n=this.items.get(e.toLowerCase());if(!n)throw new Error(`Cannot get Crypto by name '${e}'`);return n}set(e,n){if(typeof e=="string"){if(!n)throw new TypeError("Argument 'value' is required");this.items.set(e.toLowerCase(),n)}else this.items.set(Fn.DEFAULT,e);return this}}wy=Symbol.toStringTag;Fn.DEFAULT="default";const it=new Fn,e$=/^[0-2](?:\.[1-9][0-9]*)+$/;function t$(t){return new RegExp(e$).test(t)}class vy{constructor(e={}){this.items={};for(const n in e)this.register(n,e[n])}get(e){return this.items[e]||null}findId(e){return t$(e)?e:this.get(e)}register(e,n){this.items[e]=n,this.items[n]=e}}const xt=new vy;xt.register("CN","2.5.4.3");xt.register("L","2.5.4.7");xt.register("ST","2.5.4.8");xt.register("O","2.5.4.10");xt.register("OU","2.5.4.11");xt.register("C","2.5.4.6");xt.register("DC","0.9.2342.19200300.100.1.25");xt.register("E","1.2.840.113549.1.9.1");xt.register("G","2.5.4.42");xt.register("I","2.5.4.43");xt.register("SN","2.5.4.4");xt.register("T","2.5.4.12");function n$(t,e){return`\\${re.ToHex(re.FromUtf8String(e)).toUpperCase()}`}function r$(t){return t.replace(/([,+"\\<>;])/g,"\\$1").replace(/^([ #])/,"\\$1").replace(/([ ]$)/,"\\$1").replace(/([\r\n\t])/,n$)}class Pt{static isASCII(e){for(let n=0;n<e.length;n++)if(e.charCodeAt(n)>255)return!1;return!0}static isPrintableString(e){return/^[A-Za-z0-9 '()+,-./:=?]*$/g.test(e)}constructor(e,n={}){this.extraNames=new vy,this.asn=new Ve;for(const r in n)if(Object.prototype.hasOwnProperty.call(n,r)){const i=n[r];this.extraNames.register(r,i)}typeof e=="string"?this.asn=this.fromString(e):e instanceof Ve?this.asn=e:G.isBufferSource(e)?this.asn=H.parse(e,Ve):this.asn=this.fromJSON(e)}getField(e){const n=this.extraNames.findId(e)||xt.findId(e),r=[];for(const i of this.asn)for(const s of i)s.type===n&&r.push(s.value.toString());return r}getName(e){return this.extraNames.get(e)||xt.get(e)}toString(){return this.asn.map(e=>e.map(n=>{const r=this.getName(n.type)||n.type,i=n.value.anyValue?`#${re.ToHex(n.value.anyValue)}`:r$(n.value.toString());return`${r}=${i}`}).join("+")).join(", ")}toJSON(){var e;const n=[];for(const r of this.asn){const i={};for(const s of r){const a=this.getName(s.type)||s.type;(e=i[a])!==null&&e!==void 0||(i[a]=[]),i[a].push(s.value.anyValue?`#${re.ToHex(s.value.anyValue)}`:s.value.toString())}n.push(i)}return n}fromString(e){const n=new Ve,r=/(\d\.[\d.]*\d|[A-Za-z]+)=((?:"")|(?:".*?[^\\]")|(?:[^,+"\\](?=[,+]|$))|(?:[^,+].*?(?:[^\\][,+]))|(?:))([,+])?/g;let i=null,s=",";for(;i=r.exec(`${e},`);){let[,a,c]=i;const l=c[c.length-1];(l===","||l==="+")&&(c=c.slice(0,c.length-1),i[3]=l);const d=i[3];a=this.getTypeOid(a);const u=this.createAttribute(a,c);s==="+"?n[n.length-1].push(u):n.push(new si([u])),s=d}return n}fromJSON(e){const n=new Ve;for(const r of e){const i=new si;for(const s in r){const a=this.getTypeOid(s),c=r[s];for(const l of c){const d=this.createAttribute(a,l);i.push(d)}}n.push(i)}return n}getTypeOid(e){if(/[\d.]+/.test(e)||(e=this.getName(e)||""),!e)throw new Error(`Cannot get OID for name type '${e}'`);return e}createAttribute(e,n){const r=new ac({type:e});if(typeof n=="object")for(const i in n)switch(i){case"ia5String":r.value.ia5String=n[i];break;case"utf8String":r.value.utf8String=n[i];break;case"universalString":r.value.universalString=n[i];break;case"bmpString":r.value.bmpString=n[i];break;case"printableString":r.value.printableString=n[i];break}else if(n[0]==="#")r.value.anyValue=re.FromHex(n.slice(1));else{const i=this.processStringValue(n);e===this.getName("E")||e===this.getName("DC")?r.value.ia5String=i:Pt.isPrintableString(i)?r.value.printableString=i:r.value.utf8String=i}return r}processStringValue(e){const n=/"(.*?[^\\])?"/.exec(e);return n&&(e=n[1]),e.replace(/\\0a/ig,`
186
+ `).replace(/\\0d/ig,"\r").replace(/\\0g/ig," ").replace(/\\(.)/g,"$1")}toArrayBuffer(){return H.serialize(this.asn)}async getThumbprint(...e){var n;let r,i="SHA-1";return e.length>=1&&!(!((n=e[0])===null||n===void 0)&&n.subtle)?(i=e[0]||i,r=e[1]||it.get()):r=e[0]||it.get(),await r.subtle.digest(i,this.toArrayBuffer())}}const by="Cannot initialize GeneralName from ASN.1 data.",Uh=`${by} Unsupported string format in use.`,i$=`${by} Value doesn't match to GUID regular expression.`,Dh=/^([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})$/i,Mh="1.3.6.1.4.1.311.25.1",Fh="1.3.6.1.4.1.311.20.2.3",Yc="dns",Qc="dn",el="email",tl="ip",nl="url",rl="guid",il="upn",ss="id";class qn extends tr{constructor(...e){let n;if(e.length===2)switch(e[0]){case Qc:{const r=new Pt(e[1]).toArrayBuffer(),i=H.parse(r,Ve);n=new me({directoryName:i});break}case Yc:n=new me({dNSName:e[1]});break;case el:n=new me({rfc822Name:e[1]});break;case rl:{const r=new RegExp(Dh,"i").exec(e[1]);if(!r)throw new Error("Cannot parse GUID value. Value doesn't match to regular expression");const i=r.slice(1).map((s,a)=>a<3?re.ToHex(new Uint8Array(re.FromHex(s)).reverse()):s).join("");n=new me({otherName:new so({typeId:Mh,value:H.serialize(new ke(re.FromHex(i)))})});break}case tl:n=new me({iPAddress:e[1]});break;case ss:n=new me({registeredID:e[1]});break;case il:{n=new me({otherName:new so({typeId:Fh,value:H.serialize(B_.toASN(e[1]))})});break}case nl:n=new me({uniformResourceIdentifier:e[1]});break;default:throw new Error("Cannot create GeneralName. Unsupported type of the name")}else G.isBufferSource(e[0])?n=H.parse(e[0],me):n=e[0];super(n)}onInit(e){if(e.dNSName!=null)this.type=Yc,this.value=e.dNSName;else if(e.rfc822Name!=null)this.type=el,this.value=e.rfc822Name;else if(e.iPAddress!=null)this.type=tl,this.value=e.iPAddress;else if(e.uniformResourceIdentifier!=null)this.type=nl,this.value=e.uniformResourceIdentifier;else if(e.registeredID!=null)this.type=ss,this.value=e.registeredID;else if(e.directoryName!=null)this.type=Qc,this.value=new Pt(e.directoryName).toString();else if(e.otherName!=null)if(e.otherName.typeId===Mh){this.type=rl;const n=H.parse(e.otherName.value,ke),r=new RegExp(Dh,"i").exec(re.ToHex(n));if(!r)throw new Error(i$);this.value=r.slice(1).map((i,s)=>s<3?re.ToHex(new Uint8Array(re.FromHex(i)).reverse()):i).join("-")}else if(e.otherName.typeId===Fh)this.type=il,this.value=H.parse(e.otherName.value,ct).toString();else throw new Error(Uh);else throw new Error(Uh)}toJSON(){return{type:this.type,value:this.value}}toTextObject(){let e;switch(this.type){case Qc:case Yc:case rl:case tl:case ss:case il:case nl:e=this.type.toUpperCase();break;case el:e="Email";break;default:throw new Error("Unsupported GeneralName type")}let n=this.value;return this.type===ss&&(n=er.toString(n)),new xe(e,void 0,n)}}class Nr extends tr{constructor(e){let n;if(e instanceof gt)n=e;else if(Array.isArray(e)){const r=[];for(const i of e)if(i instanceof me)r.push(i);else{const s=H.parse(new qn(i.type,i.value).rawData,me);r.push(s)}n=new gt(r)}else if(G.isBufferSource(e))n=H.parse(e,gt);else throw new Error("Cannot initialize GeneralNames. Incorrect incoming arguments");super(n)}onInit(e){const n=[];for(const r of e){let i=null;try{i=new qn(r)}catch{continue}n.push(i)}this.items=n}toJSON(){return this.items.map(e=>e.toJSON())}toTextObject(){const e=super.toTextObjectEmpty();for(const n of this.items){const r=n.toTextObject();let i=e[r[xe.NAME]];Array.isArray(i)||(i=[],e[r[xe.NAME]]=i),i.push(r)}return e}}Nr.NAME="GeneralNames";const Qi="-{5}",go="\\n",o$=`[^${go}]+`,s$=`${Qi}BEGIN (${o$}(?=${Qi}))${Qi}`,a$=`${Qi}END \\1${Qi}`,hi="\\n",c$=`[^:${go}]+`,l$=`(?:[^${go}]+${hi}(?: +[^${go}]+${hi})*)`,d$="[a-zA-Z0-9=+/]+",u$=`(?:${d$}${hi})+`,qh=`${s$}${hi}(?:((?:${c$}: ${l$})+))?${hi}?(${u$})${a$}`;class Ct{static isPem(e){return typeof e=="string"&&new RegExp(qh,"g").test(e.replace(/\r/g,""))}static decodeWithHeaders(e){e=e.replace(/\r/g,"");const n=new RegExp(qh,"g"),r=[];let i=null;for(;i=n.exec(e);){const s=i[3].replace(new RegExp(`[${go}]+`,"g"),""),a={type:i[1],headers:[],rawData:re.FromBase64(s)},c=i[2];if(c){const l=c.split(new RegExp(hi,"g"));let d=null;for(const u of l){const[f,h]=u.split(/:(.*)/);if(h===void 0){if(!d)throw new Error("Cannot parse PEM string. Incorrect header value");d.value+=f.trim()}else d&&a.headers.push(d),d={key:f,value:h.trim()}}d&&a.headers.push(d)}r.push(a)}return r}static decode(e){return this.decodeWithHeaders(e).map(r=>r.rawData)}static decodeFirst(e){const n=this.decode(e);if(!n.length)throw new RangeError("PEM string doesn't contain any objects");return n[0]}static encode(e,n){if(Array.isArray(e)){const r=new Array;return n?e.forEach(i=>{if(!G.isBufferSource(i))throw new TypeError("Cannot encode array of BufferSource in PEM format. Not all items of the array are BufferSource");r.push(this.encodeStruct({type:n,rawData:G.toArrayBuffer(i)}))}):e.forEach(i=>{if(!("type"in i))throw new TypeError("Cannot encode array of PemStruct in PEM format. Not all items of the array are PemStrut");r.push(this.encodeStruct(i))}),r.join(`
187
187
  `)}else{if(!n)throw new Error("Required argument 'tag' is missed");return this.encodeStruct({type:n,rawData:G.toArrayBuffer(e)})}}static encodeStruct(e){var n;const r=e.type.toLocaleUpperCase(),i=[];if(i.push(`-----BEGIN ${r}-----`),!((n=e.headers)===null||n===void 0)&&n.length){for(const d of e.headers)i.push(`${d.key}: ${d.value}`);i.push("")}const s=re.ToBase64(e.rawData);let a,c=0;const l=Array();for(;c<s.length&&(s.length-c<64?a=s.substring(c):(a=s.substring(c,c+64),c+=64),a.length!==0);)if(l.push(a),a.length<64)break;return i.push(...l),i.push(`-----END ${r}-----`),i.join(`
188
- `)}}Ct.CertificateTag="CERTIFICATE";Ct.CrlTag="CRL";Ct.CertificateRequestTag="CERTIFICATE REQUEST";Ct.PublicKeyTag="PUBLIC KEY";Ct.PrivateKeyTag="PRIVATE KEY";class Cn extends tr{static isAsnEncoded(e){return G.isBufferSource(e)||typeof e=="string"}static toArrayBuffer(e){if(typeof e=="string"){if(Ct.isPem(e))return Ct.decode(e)[0];if(re.isHex(e))return re.FromHex(e);if(re.isBase64(e))return re.FromBase64(e);if(re.isBase64Url(e))return re.FromBase64Url(e);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}else{const n=re.ToBinary(e);return Ct.isPem(n)?Ct.decode(n)[0]:re.isHex(n)?re.FromHex(n):re.isBase64(n)?re.FromBase64(n):re.isBase64Url(n)?re.FromBase64Url(n):G.toArrayBuffer(e)}}constructor(...e){Cn.isAsnEncoded(e[0])?super(Cn.toArrayBuffer(e[0]),e[1]):super(e[0])}toString(e="pem"){switch(e){case"pem":return Ct.encode(this.rawData,this.tag);default:return super.toString(e)}}}class Xt extends Cn{static async create(e,n=it.get()){if(e instanceof Xt)return e;if(Fn.isCryptoKey(e)){if(e.type!=="public")throw new TypeError("Public key is required");const r=await n.subtle.exportKey("spki",e);return new Xt(r)}else{if(e.publicKey)return e.publicKey;if(G.isBufferSource(e))return new Xt(e);throw new TypeError("Unsupported PublicKeyType")}}constructor(e){Cn.isAsnEncoded(e)?super(e,Gt):super(e),this.tag=Ct.PublicKeyTag}async export(...e){let n,r=["verify"],i={hash:"SHA-256",...this.algorithm};e.length>1?(i=e[0]||i,r=e[1]||r,n=e[2]||it.get()):n=e[0]||it.get();let s=this.rawData;const a=H.parse(this.rawData,Gt);return a.algorithm.algorithm===Yi&&(s=p$(a,s)),n.subtle.importKey("spki",s,i,!0,r)}onInit(e){const n=lt.resolve(Er),r=this.algorithm=n.toWebAlgorithm(e.algorithm);switch(e.algorithm.algorithm){case Sr:{const i=H.parse(e.subjectPublicKey,dp),s=G.toUint8Array(i.modulus);r.publicExponent=G.toUint8Array(i.publicExponent),r.modulusLength=(s[0]?s:s.slice(1)).byteLength<<3;break}}}async getThumbprint(...e){var n;let r,i="SHA-1";return e.length>=1&&!(!((n=e[0])===null||n===void 0)&&n.subtle)?(i=e[0]||i,r=e[1]||it.get()):r=e[0]||it.get(),await r.subtle.digest(i,this.rawData)}async getKeyIdentifier(...e){let n,r="SHA-1";e.length===1?typeof e[0]=="string"?(r=e[0],n=it.get()):n=e[0]:e.length===2?(r=e[0],n=e[1]):n=it.get();const i=H.parse(this.rawData,Gt);return await n.subtle.digest(r,i.subjectPublicKey)}toTextObject(){const e=this.toTextObjectEmpty(),n=H.parse(this.rawData,Gt);switch(e.Algorithm=Cr.serializeAlgorithm(n.algorithm),n.algorithm.algorithm){case uo:e["EC Point"]=n.subjectPublicKey;break;case Sr:default:e["Raw Data"]=n.subjectPublicKey}return e}}function p$(t,e){return t.algorithm=new X({algorithm:Sr,parameters:null}),e=H.serialize(t),e}class mo extends Tt{static async create(e,n=!1,r=it.get()){if("name"in e&&"serialNumber"in e)return new mo(e,n);const s=await(await Xt.create(e,r)).getKeyIdentifier(r);return new mo(re.ToHex(s),n)}constructor(...e){if(G.isBufferSource(e[0]))super(e[0]);else if(typeof e[0]=="string"){const n=new ur({keyIdentifier:new Vu(re.FromHex(e[0]))});super(Fl,e[1],H.serialize(n))}else{const n=e[0],r=n.name instanceof Nr?H.parse(n.name.rawData,gt):n.name,i=new ur({authorityCertIssuer:r,authorityCertSerialNumber:re.FromHex(n.serialNumber)});super(Fl,e[1],H.serialize(i))}}onInit(e){super.onInit(e);const n=H.parse(e.extnValue,ur);n.keyIdentifier&&(this.keyId=re.ToHex(n.keyIdentifier)),(n.authorityCertIssuer||n.authorityCertSerialNumber)&&(this.certId={name:n.authorityCertIssuer||[],serialNumber:n.authorityCertSerialNumber?re.ToHex(n.authorityCertSerialNumber):""})}toTextObject(){const e=this.toTextObjectWithoutValue(),n=H.parse(this.value,ur);return n.authorityCertIssuer&&(e["Authority Issuer"]=new Nr(n.authorityCertIssuer).toTextObject()),n.authorityCertSerialNumber&&(e["Authority Serial Number"]=n.authorityCertSerialNumber),n.keyIdentifier&&(e[""]=n.keyIdentifier),e}}mo.NAME="Authority Key Identifier";class hp extends Tt{constructor(...e){if(G.isBufferSource(e[0])){super(e[0]);const n=H.parse(this.value,Js);this.ca=n.cA,this.pathLength=n.pathLenConstraint}else{const n=new Js({cA:e[0],pathLenConstraint:e[1]});super(U_,e[2],H.serialize(n)),this.ca=e[0],this.pathLength=e[1]}}toTextObject(){const e=this.toTextObjectWithoutValue();return this.ca&&(e.CA=this.ca),this.pathLength!==void 0&&(e["Path Length"]=this.pathLength),e}}hp.NAME="Basic Constraints";var Hh;(function(t){t.serverAuth="1.3.6.1.5.5.7.3.1",t.clientAuth="1.3.6.1.5.5.7.3.2",t.codeSigning="1.3.6.1.5.5.7.3.3",t.emailProtection="1.3.6.1.5.5.7.3.4",t.timeStamping="1.3.6.1.5.5.7.3.8",t.ocspSigning="1.3.6.1.5.5.7.3.9"})(Hh||(Hh={}));class gp extends Tt{constructor(...e){if(G.isBufferSource(e[0])){super(e[0]);const n=H.parse(this.value,Qs);this.usages=n.map(r=>r)}else{const n=new Qs(e[0]);super(F_,e[1],H.serialize(n)),this.usages=e[0]}}toTextObject(){const e=this.toTextObjectWithoutValue();return e[""]=this.usages.map(n=>er.toString(n)).join(", "),e}}gp.NAME="Extended Key Usages";var Sa;(function(t){t[t.digitalSignature=1]="digitalSignature",t[t.nonRepudiation=2]="nonRepudiation",t[t.keyEncipherment=4]="keyEncipherment",t[t.dataEncipherment=8]="dataEncipherment",t[t.keyAgreement=16]="keyAgreement",t[t.keyCertSign=32]="keyCertSign",t[t.cRLSign=64]="cRLSign",t[t.encipherOnly=128]="encipherOnly",t[t.decipherOnly=256]="decipherOnly"})(Sa||(Sa={}));class mp extends Tt{constructor(...e){if(G.isBufferSource(e[0])){super(e[0]);const n=H.parse(this.value,Zc);this.usages=n.toNumber()}else{const n=new Zc(e[0]);super(H_,e[1],H.serialize(n)),this.usages=e[0]}}toTextObject(){const e=this.toTextObjectWithoutValue(),n=H.parse(this.value,Zc);return e[""]=n.toJSON().join(", "),e}}mp.NAME="Key Usages";class Mo extends Tt{static async create(e,n=!1,r=it.get()){const s=await(await Xt.create(e,r)).getKeyIdentifier(r);return new Mo(re.ToHex(s),n)}constructor(...e){if(G.isBufferSource(e[0])){super(e[0]);const n=H.parse(this.value,Vn);this.keyId=re.ToHex(n)}else{const n=typeof e[0]=="string"?re.FromHex(e[0]):e[0],r=new Vn(n);super(W_,e[1],H.serialize(r)),this.keyId=re.ToHex(n)}}toTextObject(){const e=this.toTextObjectWithoutValue(),n=H.parse(this.value,Vn);return e[""]=n,e}}Mo.NAME="Subject Key Identifier";class $y extends Tt{constructor(...e){G.isBufferSource(e[0])?super(e[0]):super(G_,e[1],new Nr(e[0]||[]).rawData)}onInit(e){super.onInit(e);const n=H.parse(e.extnValue,rd);this.names=new Nr(n)}toTextObject(){const e=this.toTextObjectWithoutValue(),n=this.names.toTextObject();for(const r in n)e[r]=n[r];return e}}$y.NAME="Subject Alternative Name";class Pt{static register(e,n){this.items.set(e,n)}static create(e){const n=new Tt(e),r=this.items.get(n.type);return r?new r(e):n}}Pt.items=new Map;class ky extends Tt{constructor(...e){var n;if(G.isBufferSource(e[0])){super(e[0]);const r=H.parse(this.value,Zs);this.policies=r.map(i=>i.policyIdentifier)}else{const r=e[0],i=(n=e[1])!==null&&n!==void 0?n:!1,s=new Zs(r.map(a=>new lc({policyIdentifier:a})));super(D_,i,H.serialize(s)),this.policies=r}}toTextObject(){const e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map(n=>new xe("",{},er.toString(n))),e}}ky.NAME="Certificate Policies";Pt.register(D_,ky);class xy extends Tt{constructor(...e){var n;if(G.isBufferSource(e[0]))super(e[0]);else if(Array.isArray(e[0])&&typeof e[0][0]=="string"){const i=e[0].map(a=>new xi({distributionPoint:new br({fullName:[new me({uniformResourceIdentifier:a})]})})),s=new Zr(i);super(Gl,e[1],H.serialize(s))}else{const r=new Zr(e[0]);super(Gl,e[1],H.serialize(r))}(n=this.distributionPoints)!==null&&n!==void 0||(this.distributionPoints=[])}onInit(e){super.onInit(e);const n=H.parse(e.extnValue,Zr);this.distributionPoints=n}toTextObject(){const e=this.toTextObjectWithoutValue();return e["Distribution Point"]=this.distributionPoints.map(n=>{var r;const i={};return n.distributionPoint&&(i[""]=(r=n.distributionPoint.fullName)===null||r===void 0?void 0:r.map(s=>new qn(s).toString()).join(", ")),n.reasons&&(i.Reasons=n.reasons.toString()),n.cRLIssuer&&(i["CRL Issuer"]=n.cRLIssuer.map(s=>s.toString()).join(", ")),i}),e}}xy.NAME="CRL Distribution Points";class Sy extends Tt{constructor(...e){var n,r,i,s;if(G.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof Gr){const a=new Gr(e[0]);super(Ml,e[1],H.serialize(a))}else{const a=e[0],c=new Gr;cs(c,a,Ef,"ocsp"),cs(c,a,Cf,"caIssuers"),cs(c,a,Nf,"timeStamping"),cs(c,a,If,"caRepository"),super(Ml,e[1],H.serialize(c))}(n=this.ocsp)!==null&&n!==void 0||(this.ocsp=[]),(r=this.caIssuers)!==null&&r!==void 0||(this.caIssuers=[]),(i=this.timeStamping)!==null&&i!==void 0||(this.timeStamping=[]),(s=this.caRepository)!==null&&s!==void 0||(this.caRepository=[])}onInit(e){super.onInit(e),this.ocsp=[],this.caIssuers=[],this.timeStamping=[],this.caRepository=[],H.parse(e.extnValue,Gr).forEach(r=>{switch(r.accessMethod){case Ef:this.ocsp.push(new qn(r.accessLocation));break;case Cf:this.caIssuers.push(new qn(r.accessLocation));break;case Nf:this.timeStamping.push(new qn(r.accessLocation));break;case If:this.caRepository.push(new qn(r.accessLocation));break}})}toTextObject(){const e=this.toTextObjectWithoutValue();return this.ocsp.length&&as(e,"OCSP",this.ocsp),this.caIssuers.length&&as(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&as(e,"Time Stamping",this.timeStamping),this.caRepository.length&&as(e,"CA Repository",this.caRepository),e}}Sy.NAME="Authority Info Access";function as(t,e,n){if(n.length===1)t[e]=n[0].toTextObject();else{const r=new xe("");n.forEach((i,s)=>{const a=i.toTextObject(),c=`${a[xe.NAME]} ${s+1}`;let l=r[c];Array.isArray(l)||(l=[],r[c]=l),l.push(a)}),t[e]=r}}function cs(t,e,n,r){const i=e[r];i&&(Array.isArray(i)?i:[i]).forEach(a=>{typeof a=="string"&&(a=new qn("url",a)),t.push(new Eo({accessMethod:n,accessLocation:H.parse(a.rawData,me)}))})}class zy extends Tt{constructor(...e){G.isBufferSource(e[0])?super(e[0]):super(q_,e[1],new Nr(e[0]||[]).rawData)}onInit(e){super.onInit(e);const n=H.parse(e.extnValue,gt);this.names=new Nr(n)}toTextObject(){const e=this.toTextObjectWithoutValue(),n=this.names.toTextObject();for(const r in n)e[r]=n[r];return e}}zy.NAME="Issuer Alternative Name";class Ii extends tr{constructor(...e){let n;if(G.isBufferSource(e[0]))n=G.toArrayBuffer(e[0]);else{const r=e[0],i=Array.isArray(e[1])?e[1].map(s=>G.toArrayBuffer(s)):[];n=H.serialize(new zn({type:r,values:i}))}super(n,zn)}onInit(e){this.type=e.type,this.values=e.values}toTextObject(){const e=this.toTextObjectWithoutValue();return e.Value=this.values.map(n=>new xe("",{"":n})),e}toTextObjectWithoutValue(){const e=this.toTextObjectEmpty();return e[xe.NAME]===Ii.NAME&&(e[xe.NAME]=er.toString(this.type)),e}}Ii.NAME="Attribute";class Ay extends Ii{constructor(...e){var n;if(G.isBufferSource(e[0]))super(e[0]);else{const r=new ka({printableString:e[0]});super(my,[H.serialize(r)])}(n=this.password)!==null&&n!==void 0||(this.password="")}onInit(e){if(super.onInit(e),this.values[0]){const n=H.parse(this.values[0],ka);this.password=n.toString()}}toTextObject(){const e=this.toTextObjectWithoutValue();return e[xe.VALUE]=this.password,e}}Ay.NAME="Challenge Password";class _p extends Ii{constructor(...e){var n;if(G.isBufferSource(e[0]))super(e[0]);else{const r=e[0],i=new Wn;for(const s of r)i.push(H.parse(s.rawData,Ut));super(fp,[H.serialize(i)])}(n=this.items)!==null&&n!==void 0||(this.items=[])}onInit(e){if(super.onInit(e),this.values[0]){const n=H.parse(this.values[0],Wn);this.items=n.map(r=>Pt.create(H.serialize(r)))}}toTextObject(){const e=this.toTextObjectWithoutValue(),n=this.items.map(r=>r.toTextObject());for(const r of n)e[r[xe.NAME]]=r;return e}}_p.NAME="Extensions";class jc{static register(e,n){this.items.set(e,n)}static create(e){const n=new Ii(e),r=this.items.get(n.type);return r?new r(e):n}}jc.items=new Map;const Fo="crypto.signatureFormatter";class f${toAsnSignature(e,n){return G.toArrayBuffer(n)}toWebSignature(e,n){return G.toArrayBuffer(n)}}var ys;let Gd=ys=class{static createPssParams(e,n){const r=ys.getHashAlgorithm(e);return r?new Ar({hashAlgorithm:r,maskGenAlgorithm:new X({algorithm:kc,parameters:H.serialize(r)}),saltLength:n}):null}static getHashAlgorithm(e){const n=lt.resolve(Er);return typeof e=="string"?n.toAsnAlgorithm({name:e}):typeof e=="object"&&e&&"name"in e?n.toAsnAlgorithm(e):null}toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"rsassa-pkcs1-v1_5":if("hash"in e){let n;if(typeof e.hash=="string")n=e.hash;else if(e.hash&&typeof e.hash=="object"&&"name"in e.hash&&typeof e.hash.name=="string")n=e.hash.name.toUpperCase();else throw new Error("Cannot get hash algorithm name");switch(n.toLowerCase()){case"sha-1":return new X({algorithm:fa,parameters:null});case"sha-256":return new X({algorithm:xd,parameters:null});case"sha-384":return new X({algorithm:ha,parameters:null});case"sha-512":return new X({algorithm:ga,parameters:null})}}else return new X({algorithm:Sr,parameters:null});break;case"rsa-pss":if("hash"in e){if(!("saltLength"in e&&typeof e.saltLength=="number"))throw new Error("Cannot get 'saltLength' from 'alg' argument");const n=ys.createPssParams(e.hash,e.saltLength);if(!n)throw new Error("Cannot create PSS parameters");return new X({algorithm:Yi,parameters:H.serialize(n)})}else return new X({algorithm:Yi,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case Sr:return{name:"RSASSA-PKCS1-v1_5"};case fa:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case xd:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case ha:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case ga:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case Yi:if(e.parameters){const n=H.parse(e.parameters,Ar);return{name:"RSA-PSS",hash:lt.resolve(Er).toWebAlgorithm(n.hashAlgorithm),saltLength:n.saltLength}}else return{name:"RSA-PSS"}}return null}};Gd=ys=g([Ac()],Gd);lt.registerSingleton(Do,Gd);let Wd=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new X({algorithm:ma});case"sha-256":return new X({algorithm:_a});case"sha-384":return new X({algorithm:ya});case"sha-512":return new X({algorithm:wa})}return null}toWebAlgorithm(e){switch(e.algorithm){case ma:return{name:"SHA-1"};case _a:return{name:"SHA-256"};case ya:return{name:"SHA-384"};case wa:return{name:"SHA-512"}}return null}};Wd=g([Ac()],Wd);lt.registerSingleton(Do,Wd);class Bt{addPadding(e,n){const r=G.toUint8Array(n),i=new Uint8Array(e);return i.set(r,e-r.length),i}removePadding(e,n=!1){let r=G.toUint8Array(e);for(let i=0;i<r.length;i++)if(r[i]){r=r.slice(i);break}if(n&&r[0]>127){const i=new Uint8Array(r.length+1);return i.set(r,1),i.buffer}return r.buffer}toAsnSignature(e,n){if(e.name==="ECDSA"){const r=e.namedCurve,i=Bt.namedCurveSize.get(r)||Bt.defaultNamedCurveSize,s=new pa,a=G.toUint8Array(n);return s.r=this.removePadding(a.slice(0,i),!0),s.s=this.removePadding(a.slice(i,i+i),!0),H.serialize(s)}return null}toWebSignature(e,n){if(e.name==="ECDSA"){const r=H.parse(n,pa),i=e.namedCurve,s=Bt.namedCurveSize.get(i)||Bt.defaultNamedCurveSize,a=this.addPadding(s,this.removePadding(r.r)),c=this.addPadding(s,this.removePadding(r.s));return zb(a,c)}return null}}Bt.namedCurveSize=new Map;Bt.defaultNamedCurveSize=32;const ol="1.3.101.110",Vh="1.3.101.111",sl="1.3.101.112",Kh="1.3.101.113";let Jd=class{toAsnAlgorithm(e){let n=null;switch(e.name.toLowerCase()){case"ed25519":n=sl;break;case"x25519":n=ol;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":n=sl;break;case"ed448":n=Kh;break}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":n=ol;break;case"x448":n=Vh;break}}return n?new X({algorithm:n}):null}toWebAlgorithm(e){switch(e.algorithm){case sl:return{name:"Ed25519"};case Kh:return{name:"EdDSA",namedCurve:"Ed448"};case ol:return{name:"X25519"};case Vh:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};Jd=g([Ac()],Jd);lt.registerSingleton(Do,Jd);class h$ extends Cn{constructor(e){Cn.isAsnEncoded(e)?super(e,fo):super(e),this.tag=Ct.CertificateRequestTag}onInit(e){this.tbs=H.serialize(e.certificationRequestInfo),this.publicKey=new Xt(e.certificationRequestInfo.subjectPKInfo);const n=lt.resolve(Er);this.signatureAlgorithm=n.toWebAlgorithm(e.signatureAlgorithm),this.signature=e.signature,this.attributes=e.certificationRequestInfo.attributes.map(i=>jc.create(H.serialize(i)));const r=this.getAttribute(fp);this.extensions=[],r instanceof _p&&(this.extensions=r.items),this.subjectName=new Rt(e.certificationRequestInfo.subject),this.subject=this.subjectName.toString()}getAttribute(e){for(const n of this.attributes)if(n.type===e)return n;return null}getAttributes(e){return this.attributes.filter(n=>n.type===e)}getExtension(e){for(const n of this.extensions)if(n.type===e)return n;return null}getExtensions(e){return this.extensions.filter(n=>n.type===e)}async verify(e=it.get()){const n={...this.publicKey.algorithm,...this.signatureAlgorithm},r=await this.publicKey.export(n,["verify"],e),i=lt.resolveAll(Fo).reverse();let s=null;for(const c of i)if(s=c.toWebSignature(n,this.signature),s)break;if(!s)throw Error("Cannot convert WebCrypto signature value to ASN.1 format");return await e.subtle.verify(this.signatureAlgorithm,r,s,this.tbs)}toTextObject(){const e=this.toTextObjectEmpty(),n=H.parse(this.rawData,fo),r=n.certificationRequestInfo,i=new xe("",{Version:`${$r[r.version]} (${r.version})`,Subject:this.subject,"Subject Public Key Info":this.publicKey});if(this.attributes.length){const s=new xe("");for(const a of this.attributes){const c=a.toTextObject();s[c[xe.NAME]]=c}i.Attributes=s}return e.Data=i,e.Signature=new xe("",{Algorithm:Cr.serializeAlgorithm(n.signatureAlgorithm),"":n.signature}),e}}h$.NAME="PKCS#10 Certificate Request";class Oc extends Cn{constructor(e){Cn.isAsnEncoded(e)?super(e,kr):super(e),this.tag=Ct.CertificateTag}onInit(e){const n=e.tbsCertificate;this.tbs=H.serialize(n);let r=new Uint8Array(n.serialNumber);r.length>1&&r[0]===0&&r[1]>127&&(r=r.slice(1)),this.serialNumber=re.ToHex(r),this.subjectName=new Rt(n.subject),this.subject=new Rt(n.subject).toString(),this.issuerName=new Rt(n.issuer),this.issuer=this.issuerName.toString();const i=lt.resolve(Er);this.signatureAlgorithm=i.toWebAlgorithm(e.signatureAlgorithm),this.signature=e.signatureValue;const s=n.validity.notBefore.utcTime||n.validity.notBefore.generalTime;if(!s)throw new Error("Cannot get 'notBefore' value");this.notBefore=s;const a=n.validity.notAfter.utcTime||n.validity.notAfter.generalTime;if(!a)throw new Error("Cannot get 'notAfter' value");this.notAfter=a,this.extensions=[],n.extensions&&(this.extensions=n.extensions.map(c=>Pt.create(H.serialize(c)))),this.publicKey=new Xt(n.subjectPublicKeyInfo)}getExtension(e){for(const n of this.extensions)if(typeof e=="string"){if(n.type===e)return n}else if(n instanceof e)return n;return null}getExtensions(e){return this.extensions.filter(n=>typeof e=="string"?n.type===e:n instanceof e)}async verify(e={},n=it.get()){let r,i;const s=e.publicKey;try{if(!s)r={...this.publicKey.algorithm,...this.signatureAlgorithm},i=await this.publicKey.export(r,["verify"],n);else if("publicKey"in s)r={...s.publicKey.algorithm,...this.signatureAlgorithm},i=await s.publicKey.export(r,["verify"],n);else if(s instanceof Xt)r={...s.algorithm,...this.signatureAlgorithm},i=await s.export(r,["verify"],n);else if(G.isBufferSource(s)){const d=new Xt(s);r={...d.algorithm,...this.signatureAlgorithm},i=await d.export(r,["verify"],n)}else r={...s.algorithm,...this.signatureAlgorithm},i=s}catch{return!1}const a=lt.resolveAll(Fo).reverse();let c=null;for(const d of a)if(c=d.toWebSignature(r,this.signature),c)break;if(!c)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");const l=await n.subtle.verify(this.signatureAlgorithm,i,c,this.tbs);if(e.signatureOnly)return l;{const u=(e.date||new Date).getTime();return l&&this.notBefore.getTime()<u&&u<this.notAfter.getTime()}}async getThumbprint(...e){let n,r="SHA-1";return e[0]&&(e[0].subtle?n=e[0]:(r=e[0]||r,n=e[1])),n??(n=it.get()),await n.subtle.digest(r,this.rawData)}async isSelfSigned(e=it.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){const e=this.toTextObjectEmpty(),n=H.parse(this.rawData,kr),r=n.tbsCertificate,i=new xe("",{Version:`${$r[r.version]} (${r.version})`,"Serial Number":r.serialNumber,"Signature Algorithm":Cr.serializeAlgorithm(r.signature),Issuer:this.issuer,Validity:new xe("",{"Not Before":r.validity.notBefore.getTime(),"Not After":r.validity.notAfter.getTime()}),Subject:this.subject,"Subject Public Key Info":this.publicKey});if(r.issuerUniqueID&&(i["Issuer Unique ID"]=r.issuerUniqueID),r.subjectUniqueID&&(i["Subject Unique ID"]=r.subjectUniqueID),this.extensions.length){const s=new xe("");for(const a of this.extensions){const c=a.toTextObject();s[c[xe.NAME]]=c}i.Extensions=s}return e.Data=i,e.Signature=new xe("",{Algorithm:Cr.serializeAlgorithm(n.signatureAlgorithm),"":n.signatureValue}),e}}Oc.NAME="Certificate";class g${static async createSelfSigned(e,n=it.get()){if(!e.keys.privateKey)throw new Error("Bad field 'keys' in 'params' argument. 'privateKey' is empty");if(!e.keys.publicKey)throw new Error("Bad field 'keys' in 'params' argument. 'publicKey' is empty");return this.create({serialNumber:e.serialNumber,subject:e.name,issuer:e.name,notBefore:e.notBefore,notAfter:e.notAfter,publicKey:e.keys.publicKey,signingKey:e.keys.privateKey,signingAlgorithm:e.signingAlgorithm,extensions:e.extensions},n)}static async create(e,n=it.get()){var r;let i;e.publicKey instanceof Xt?i=e.publicKey.rawData:"publicKey"in e.publicKey?i=e.publicKey.publicKey.rawData:G.isBufferSource(e.publicKey)?i=e.publicKey:i=await n.subtle.exportKey("spki",e.publicKey);let s=e.serialNumber?G.toUint8Array(re.FromHex(e.serialNumber)):void 0;s=this.generateSerialNumber(s,n);const a=e.notBefore||new Date,c=e.notAfter||new Date(a.getTime()+31536e6),l=new kr({tbsCertificate:new Ot({version:$r.v3,serialNumber:s,validity:new Co({notBefore:a,notAfter:c}),extensions:new Wn(((r=e.extensions)===null||r===void 0?void 0:r.map(b=>H.parse(b.rawData,Ut)))||[]),subjectPublicKeyInfo:H.parse(i,Gt)})});if(e.subject){const b=e.subject instanceof Rt?e.subject:new Rt(e.subject);l.tbsCertificate.subject=H.parse(b.toArrayBuffer(),Ve)}if(e.issuer){const b=e.issuer instanceof Rt?e.issuer:new Rt(e.issuer);l.tbsCertificate.issuer=H.parse(b.toArrayBuffer(),Ve)}const d={hash:"SHA-256"},u="signingKey"in e?{...d,...e.signingAlgorithm,...e.signingKey.algorithm}:{...d,...e.signingAlgorithm},f=lt.resolve(Er);l.tbsCertificate.signature=l.signatureAlgorithm=f.toAsnAlgorithm(u);const h=H.serialize(l.tbsCertificate),m="signingKey"in e?await n.subtle.sign(u,e.signingKey,h):e.signature,y=lt.resolveAll(Fo).reverse();let v=null;for(const b of y)if(v=b.toAsnSignature(u,m),v)break;if(!v)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return l.signatureValue=v,new Oc(H.serialize(l))}static generateSerialNumber(e,n){let r=e&&e.length&&e.some(s=>s>0)?new Uint8Array(e):void 0;r||(r=n.getRandomValues(new Uint8Array(16)));let i=0;for(;i<r.length-1&&r[i]===0;)i++;if(r=r.slice(i),r[0]>127){const s=new Uint8Array(r.length+1);s[0]=0,s.set(r,1),r=s}return r}}var Gh;(function(t){t[t.unspecified=0]="unspecified",t[t.keyCompromise=1]="keyCompromise",t[t.cACompromise=2]="cACompromise",t[t.affiliationChanged=3]="affiliationChanged",t[t.superseded=4]="superseded",t[t.cessationOfOperation=5]="cessationOfOperation",t[t.certificateHold=6]="certificateHold",t[t.removeFromCRL=8]="removeFromCRL",t[t.privilegeWithdrawn=9]="privilegeWithdrawn",t[t.aACompromise=10]="aACompromise"})(Gh||(Gh={}));Pt.register(U_,hp);Pt.register(F_,gp);Pt.register(H_,mp);Pt.register(W_,Mo);Pt.register(Fl,mo);Pt.register(G_,$y);Pt.register(Gl,xy);Pt.register(Ml,Sy);Pt.register(q_,zy);jc.register(my,Ay);jc.register(fp,_p);lt.registerSingleton(Fo,f$);lt.registerSingleton(Fo,Bt);Bt.namedCurveSize.set("P-256",32);Bt.namedCurveSize.set("K-256",32);Bt.namedCurveSize.set("P-384",48);Bt.namedCurveSize.set("P-521",66);async function Xd(t){const e={name:"RSASSA-PKCS1-v1_5",hash:"SHA-256",publicExponent:new Uint8Array([1,0,1]),modulusLength:2048},n=await crypto.subtle.generateKey(e,!0,["sign","verify"]),r=Ne(),i=El(new TextEncoder().encode(r)),s=await g$.createSelfSigned({serialNumber:i,name:t.name,notBefore:new Date,notAfter:new Date(Date.now()+365*24*60*60*1e3),signingAlgorithm:e,keys:n,extensions:[new hp(!0,2,!0),new gp(["1.3.6.1.5.5.7.3.1"],!0),new mp(Sa.keyCertSign|Sa.cRLSign,!0),await Mo.create(n.publicKey)]}),a=await crypto.subtle.exportKey("pkcs8",n.privateKey),c=s.toString("pem"),l=await _$(s),d=El(await s.getThumbprint()),u=m$("PRIVATE",a);return{kid:s.serialNumber,cert:c,thumbprint:d,fingerprint:l,pkcs7:u,type:"jwt_signing"}}function m$(t,e){const n=gv.encode(new Uint8Array(e));let r=`-----BEGIN ${t} KEY-----\r
188
+ `)}}Ct.CertificateTag="CERTIFICATE";Ct.CrlTag="CRL";Ct.CertificateRequestTag="CERTIFICATE REQUEST";Ct.PublicKeyTag="PUBLIC KEY";Ct.PrivateKeyTag="PRIVATE KEY";class Cn extends tr{static isAsnEncoded(e){return G.isBufferSource(e)||typeof e=="string"}static toArrayBuffer(e){if(typeof e=="string"){if(Ct.isPem(e))return Ct.decode(e)[0];if(re.isHex(e))return re.FromHex(e);if(re.isBase64(e))return re.FromBase64(e);if(re.isBase64Url(e))return re.FromBase64Url(e);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}else{const n=re.ToBinary(e);return Ct.isPem(n)?Ct.decode(n)[0]:re.isHex(n)?re.FromHex(n):re.isBase64(n)?re.FromBase64(n):re.isBase64Url(n)?re.FromBase64Url(n):G.toArrayBuffer(e)}}constructor(...e){Cn.isAsnEncoded(e[0])?super(Cn.toArrayBuffer(e[0]),e[1]):super(e[0])}toString(e="pem"){switch(e){case"pem":return Ct.encode(this.rawData,this.tag);default:return super.toString(e)}}}class Jt extends Cn{static async create(e,n=it.get()){if(e instanceof Jt)return e;if(Fn.isCryptoKey(e)){if(e.type!=="public")throw new TypeError("Public key is required");const r=await n.subtle.exportKey("spki",e);return new Jt(r)}else{if(e.publicKey)return e.publicKey;if(G.isBufferSource(e))return new Jt(e);throw new TypeError("Unsupported PublicKeyType")}}constructor(e){Cn.isAsnEncoded(e)?super(e,Gt):super(e),this.tag=Ct.PublicKeyTag}async export(...e){let n,r=["verify"],i={hash:"SHA-256",...this.algorithm};e.length>1?(i=e[0]||i,r=e[1]||r,n=e[2]||it.get()):n=e[0]||it.get();let s=this.rawData;const a=H.parse(this.rawData,Gt);return a.algorithm.algorithm===Yi&&(s=p$(a,s)),n.subtle.importKey("spki",s,i,!0,r)}onInit(e){const n=lt.resolve(Er),r=this.algorithm=n.toWebAlgorithm(e.algorithm);switch(e.algorithm.algorithm){case Sr:{const i=H.parse(e.subjectPublicKey,dp),s=G.toUint8Array(i.modulus);r.publicExponent=G.toUint8Array(i.publicExponent),r.modulusLength=(s[0]?s:s.slice(1)).byteLength<<3;break}}}async getThumbprint(...e){var n;let r,i="SHA-1";return e.length>=1&&!(!((n=e[0])===null||n===void 0)&&n.subtle)?(i=e[0]||i,r=e[1]||it.get()):r=e[0]||it.get(),await r.subtle.digest(i,this.rawData)}async getKeyIdentifier(...e){let n,r="SHA-1";e.length===1?typeof e[0]=="string"?(r=e[0],n=it.get()):n=e[0]:e.length===2?(r=e[0],n=e[1]):n=it.get();const i=H.parse(this.rawData,Gt);return await n.subtle.digest(r,i.subjectPublicKey)}toTextObject(){const e=this.toTextObjectEmpty(),n=H.parse(this.rawData,Gt);switch(e.Algorithm=Cr.serializeAlgorithm(n.algorithm),n.algorithm.algorithm){case uo:e["EC Point"]=n.subjectPublicKey;break;case Sr:default:e["Raw Data"]=n.subjectPublicKey}return e}}function p$(t,e){return t.algorithm=new X({algorithm:Sr,parameters:null}),e=H.serialize(t),e}class mo extends Ot{static async create(e,n=!1,r=it.get()){if("name"in e&&"serialNumber"in e)return new mo(e,n);const s=await(await Jt.create(e,r)).getKeyIdentifier(r);return new mo(re.ToHex(s),n)}constructor(...e){if(G.isBufferSource(e[0]))super(e[0]);else if(typeof e[0]=="string"){const n=new ur({keyIdentifier:new Vu(re.FromHex(e[0]))});super(Fl,e[1],H.serialize(n))}else{const n=e[0],r=n.name instanceof Nr?H.parse(n.name.rawData,gt):n.name,i=new ur({authorityCertIssuer:r,authorityCertSerialNumber:re.FromHex(n.serialNumber)});super(Fl,e[1],H.serialize(i))}}onInit(e){super.onInit(e);const n=H.parse(e.extnValue,ur);n.keyIdentifier&&(this.keyId=re.ToHex(n.keyIdentifier)),(n.authorityCertIssuer||n.authorityCertSerialNumber)&&(this.certId={name:n.authorityCertIssuer||[],serialNumber:n.authorityCertSerialNumber?re.ToHex(n.authorityCertSerialNumber):""})}toTextObject(){const e=this.toTextObjectWithoutValue(),n=H.parse(this.value,ur);return n.authorityCertIssuer&&(e["Authority Issuer"]=new Nr(n.authorityCertIssuer).toTextObject()),n.authorityCertSerialNumber&&(e["Authority Serial Number"]=n.authorityCertSerialNumber),n.keyIdentifier&&(e[""]=n.keyIdentifier),e}}mo.NAME="Authority Key Identifier";class hp extends Ot{constructor(...e){if(G.isBufferSource(e[0])){super(e[0]);const n=H.parse(this.value,Js);this.ca=n.cA,this.pathLength=n.pathLenConstraint}else{const n=new Js({cA:e[0],pathLenConstraint:e[1]});super(U_,e[2],H.serialize(n)),this.ca=e[0],this.pathLength=e[1]}}toTextObject(){const e=this.toTextObjectWithoutValue();return this.ca&&(e.CA=this.ca),this.pathLength!==void 0&&(e["Path Length"]=this.pathLength),e}}hp.NAME="Basic Constraints";var Hh;(function(t){t.serverAuth="1.3.6.1.5.5.7.3.1",t.clientAuth="1.3.6.1.5.5.7.3.2",t.codeSigning="1.3.6.1.5.5.7.3.3",t.emailProtection="1.3.6.1.5.5.7.3.4",t.timeStamping="1.3.6.1.5.5.7.3.8",t.ocspSigning="1.3.6.1.5.5.7.3.9"})(Hh||(Hh={}));class gp extends Ot{constructor(...e){if(G.isBufferSource(e[0])){super(e[0]);const n=H.parse(this.value,Qs);this.usages=n.map(r=>r)}else{const n=new Qs(e[0]);super(F_,e[1],H.serialize(n)),this.usages=e[0]}}toTextObject(){const e=this.toTextObjectWithoutValue();return e[""]=this.usages.map(n=>er.toString(n)).join(", "),e}}gp.NAME="Extended Key Usages";var Sa;(function(t){t[t.digitalSignature=1]="digitalSignature",t[t.nonRepudiation=2]="nonRepudiation",t[t.keyEncipherment=4]="keyEncipherment",t[t.dataEncipherment=8]="dataEncipherment",t[t.keyAgreement=16]="keyAgreement",t[t.keyCertSign=32]="keyCertSign",t[t.cRLSign=64]="cRLSign",t[t.encipherOnly=128]="encipherOnly",t[t.decipherOnly=256]="decipherOnly"})(Sa||(Sa={}));class mp extends Ot{constructor(...e){if(G.isBufferSource(e[0])){super(e[0]);const n=H.parse(this.value,Zc);this.usages=n.toNumber()}else{const n=new Zc(e[0]);super(H_,e[1],H.serialize(n)),this.usages=e[0]}}toTextObject(){const e=this.toTextObjectWithoutValue(),n=H.parse(this.value,Zc);return e[""]=n.toJSON().join(", "),e}}mp.NAME="Key Usages";class Mo extends Ot{static async create(e,n=!1,r=it.get()){const s=await(await Jt.create(e,r)).getKeyIdentifier(r);return new Mo(re.ToHex(s),n)}constructor(...e){if(G.isBufferSource(e[0])){super(e[0]);const n=H.parse(this.value,Vn);this.keyId=re.ToHex(n)}else{const n=typeof e[0]=="string"?re.FromHex(e[0]):e[0],r=new Vn(n);super(W_,e[1],H.serialize(r)),this.keyId=re.ToHex(n)}}toTextObject(){const e=this.toTextObjectWithoutValue(),n=H.parse(this.value,Vn);return e[""]=n,e}}Mo.NAME="Subject Key Identifier";class $y extends Ot{constructor(...e){G.isBufferSource(e[0])?super(e[0]):super(G_,e[1],new Nr(e[0]||[]).rawData)}onInit(e){super.onInit(e);const n=H.parse(e.extnValue,rd);this.names=new Nr(n)}toTextObject(){const e=this.toTextObjectWithoutValue(),n=this.names.toTextObject();for(const r in n)e[r]=n[r];return e}}$y.NAME="Subject Alternative Name";class Tt{static register(e,n){this.items.set(e,n)}static create(e){const n=new Ot(e),r=this.items.get(n.type);return r?new r(e):n}}Tt.items=new Map;class ky extends Ot{constructor(...e){var n;if(G.isBufferSource(e[0])){super(e[0]);const r=H.parse(this.value,Zs);this.policies=r.map(i=>i.policyIdentifier)}else{const r=e[0],i=(n=e[1])!==null&&n!==void 0?n:!1,s=new Zs(r.map(a=>new lc({policyIdentifier:a})));super(D_,i,H.serialize(s)),this.policies=r}}toTextObject(){const e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map(n=>new xe("",{},er.toString(n))),e}}ky.NAME="Certificate Policies";Tt.register(D_,ky);class xy extends Ot{constructor(...e){var n;if(G.isBufferSource(e[0]))super(e[0]);else if(Array.isArray(e[0])&&typeof e[0][0]=="string"){const i=e[0].map(a=>new xi({distributionPoint:new br({fullName:[new me({uniformResourceIdentifier:a})]})})),s=new Zr(i);super(Gl,e[1],H.serialize(s))}else{const r=new Zr(e[0]);super(Gl,e[1],H.serialize(r))}(n=this.distributionPoints)!==null&&n!==void 0||(this.distributionPoints=[])}onInit(e){super.onInit(e);const n=H.parse(e.extnValue,Zr);this.distributionPoints=n}toTextObject(){const e=this.toTextObjectWithoutValue();return e["Distribution Point"]=this.distributionPoints.map(n=>{var r;const i={};return n.distributionPoint&&(i[""]=(r=n.distributionPoint.fullName)===null||r===void 0?void 0:r.map(s=>new qn(s).toString()).join(", ")),n.reasons&&(i.Reasons=n.reasons.toString()),n.cRLIssuer&&(i["CRL Issuer"]=n.cRLIssuer.map(s=>s.toString()).join(", ")),i}),e}}xy.NAME="CRL Distribution Points";class Sy extends Ot{constructor(...e){var n,r,i,s;if(G.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof Gr){const a=new Gr(e[0]);super(Ml,e[1],H.serialize(a))}else{const a=e[0],c=new Gr;cs(c,a,Ef,"ocsp"),cs(c,a,Cf,"caIssuers"),cs(c,a,Nf,"timeStamping"),cs(c,a,If,"caRepository"),super(Ml,e[1],H.serialize(c))}(n=this.ocsp)!==null&&n!==void 0||(this.ocsp=[]),(r=this.caIssuers)!==null&&r!==void 0||(this.caIssuers=[]),(i=this.timeStamping)!==null&&i!==void 0||(this.timeStamping=[]),(s=this.caRepository)!==null&&s!==void 0||(this.caRepository=[])}onInit(e){super.onInit(e),this.ocsp=[],this.caIssuers=[],this.timeStamping=[],this.caRepository=[],H.parse(e.extnValue,Gr).forEach(r=>{switch(r.accessMethod){case Ef:this.ocsp.push(new qn(r.accessLocation));break;case Cf:this.caIssuers.push(new qn(r.accessLocation));break;case Nf:this.timeStamping.push(new qn(r.accessLocation));break;case If:this.caRepository.push(new qn(r.accessLocation));break}})}toTextObject(){const e=this.toTextObjectWithoutValue();return this.ocsp.length&&as(e,"OCSP",this.ocsp),this.caIssuers.length&&as(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&as(e,"Time Stamping",this.timeStamping),this.caRepository.length&&as(e,"CA Repository",this.caRepository),e}}Sy.NAME="Authority Info Access";function as(t,e,n){if(n.length===1)t[e]=n[0].toTextObject();else{const r=new xe("");n.forEach((i,s)=>{const a=i.toTextObject(),c=`${a[xe.NAME]} ${s+1}`;let l=r[c];Array.isArray(l)||(l=[],r[c]=l),l.push(a)}),t[e]=r}}function cs(t,e,n,r){const i=e[r];i&&(Array.isArray(i)?i:[i]).forEach(a=>{typeof a=="string"&&(a=new qn("url",a)),t.push(new Eo({accessMethod:n,accessLocation:H.parse(a.rawData,me)}))})}class zy extends Ot{constructor(...e){G.isBufferSource(e[0])?super(e[0]):super(q_,e[1],new Nr(e[0]||[]).rawData)}onInit(e){super.onInit(e);const n=H.parse(e.extnValue,gt);this.names=new Nr(n)}toTextObject(){const e=this.toTextObjectWithoutValue(),n=this.names.toTextObject();for(const r in n)e[r]=n[r];return e}}zy.NAME="Issuer Alternative Name";class Ii extends tr{constructor(...e){let n;if(G.isBufferSource(e[0]))n=G.toArrayBuffer(e[0]);else{const r=e[0],i=Array.isArray(e[1])?e[1].map(s=>G.toArrayBuffer(s)):[];n=H.serialize(new zn({type:r,values:i}))}super(n,zn)}onInit(e){this.type=e.type,this.values=e.values}toTextObject(){const e=this.toTextObjectWithoutValue();return e.Value=this.values.map(n=>new xe("",{"":n})),e}toTextObjectWithoutValue(){const e=this.toTextObjectEmpty();return e[xe.NAME]===Ii.NAME&&(e[xe.NAME]=er.toString(this.type)),e}}Ii.NAME="Attribute";class Ay extends Ii{constructor(...e){var n;if(G.isBufferSource(e[0]))super(e[0]);else{const r=new ka({printableString:e[0]});super(my,[H.serialize(r)])}(n=this.password)!==null&&n!==void 0||(this.password="")}onInit(e){if(super.onInit(e),this.values[0]){const n=H.parse(this.values[0],ka);this.password=n.toString()}}toTextObject(){const e=this.toTextObjectWithoutValue();return e[xe.VALUE]=this.password,e}}Ay.NAME="Challenge Password";class _p extends Ii{constructor(...e){var n;if(G.isBufferSource(e[0]))super(e[0]);else{const r=e[0],i=new Wn;for(const s of r)i.push(H.parse(s.rawData,Ut));super(fp,[H.serialize(i)])}(n=this.items)!==null&&n!==void 0||(this.items=[])}onInit(e){if(super.onInit(e),this.values[0]){const n=H.parse(this.values[0],Wn);this.items=n.map(r=>Tt.create(H.serialize(r)))}}toTextObject(){const e=this.toTextObjectWithoutValue(),n=this.items.map(r=>r.toTextObject());for(const r of n)e[r[xe.NAME]]=r;return e}}_p.NAME="Extensions";class jc{static register(e,n){this.items.set(e,n)}static create(e){const n=new Ii(e),r=this.items.get(n.type);return r?new r(e):n}}jc.items=new Map;const Fo="crypto.signatureFormatter";class f${toAsnSignature(e,n){return G.toArrayBuffer(n)}toWebSignature(e,n){return G.toArrayBuffer(n)}}var ys;let Gd=ys=class{static createPssParams(e,n){const r=ys.getHashAlgorithm(e);return r?new Ar({hashAlgorithm:r,maskGenAlgorithm:new X({algorithm:kc,parameters:H.serialize(r)}),saltLength:n}):null}static getHashAlgorithm(e){const n=lt.resolve(Er);return typeof e=="string"?n.toAsnAlgorithm({name:e}):typeof e=="object"&&e&&"name"in e?n.toAsnAlgorithm(e):null}toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"rsassa-pkcs1-v1_5":if("hash"in e){let n;if(typeof e.hash=="string")n=e.hash;else if(e.hash&&typeof e.hash=="object"&&"name"in e.hash&&typeof e.hash.name=="string")n=e.hash.name.toUpperCase();else throw new Error("Cannot get hash algorithm name");switch(n.toLowerCase()){case"sha-1":return new X({algorithm:fa,parameters:null});case"sha-256":return new X({algorithm:xd,parameters:null});case"sha-384":return new X({algorithm:ha,parameters:null});case"sha-512":return new X({algorithm:ga,parameters:null})}}else return new X({algorithm:Sr,parameters:null});break;case"rsa-pss":if("hash"in e){if(!("saltLength"in e&&typeof e.saltLength=="number"))throw new Error("Cannot get 'saltLength' from 'alg' argument");const n=ys.createPssParams(e.hash,e.saltLength);if(!n)throw new Error("Cannot create PSS parameters");return new X({algorithm:Yi,parameters:H.serialize(n)})}else return new X({algorithm:Yi,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case Sr:return{name:"RSASSA-PKCS1-v1_5"};case fa:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case xd:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case ha:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case ga:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case Yi:if(e.parameters){const n=H.parse(e.parameters,Ar);return{name:"RSA-PSS",hash:lt.resolve(Er).toWebAlgorithm(n.hashAlgorithm),saltLength:n.saltLength}}else return{name:"RSA-PSS"}}return null}};Gd=ys=g([Ac()],Gd);lt.registerSingleton(Do,Gd);let Wd=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new X({algorithm:ma});case"sha-256":return new X({algorithm:_a});case"sha-384":return new X({algorithm:ya});case"sha-512":return new X({algorithm:wa})}return null}toWebAlgorithm(e){switch(e.algorithm){case ma:return{name:"SHA-1"};case _a:return{name:"SHA-256"};case ya:return{name:"SHA-384"};case wa:return{name:"SHA-512"}}return null}};Wd=g([Ac()],Wd);lt.registerSingleton(Do,Wd);class Rt{addPadding(e,n){const r=G.toUint8Array(n),i=new Uint8Array(e);return i.set(r,e-r.length),i}removePadding(e,n=!1){let r=G.toUint8Array(e);for(let i=0;i<r.length;i++)if(r[i]){r=r.slice(i);break}if(n&&r[0]>127){const i=new Uint8Array(r.length+1);return i.set(r,1),i.buffer}return r.buffer}toAsnSignature(e,n){if(e.name==="ECDSA"){const r=e.namedCurve,i=Rt.namedCurveSize.get(r)||Rt.defaultNamedCurveSize,s=new pa,a=G.toUint8Array(n);return s.r=this.removePadding(a.slice(0,i),!0),s.s=this.removePadding(a.slice(i,i+i),!0),H.serialize(s)}return null}toWebSignature(e,n){if(e.name==="ECDSA"){const r=H.parse(n,pa),i=e.namedCurve,s=Rt.namedCurveSize.get(i)||Rt.defaultNamedCurveSize,a=this.addPadding(s,this.removePadding(r.r)),c=this.addPadding(s,this.removePadding(r.s));return zb(a,c)}return null}}Rt.namedCurveSize=new Map;Rt.defaultNamedCurveSize=32;const ol="1.3.101.110",Vh="1.3.101.111",sl="1.3.101.112",Kh="1.3.101.113";let Jd=class{toAsnAlgorithm(e){let n=null;switch(e.name.toLowerCase()){case"ed25519":n=sl;break;case"x25519":n=ol;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":n=sl;break;case"ed448":n=Kh;break}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":n=ol;break;case"x448":n=Vh;break}}return n?new X({algorithm:n}):null}toWebAlgorithm(e){switch(e.algorithm){case sl:return{name:"Ed25519"};case Kh:return{name:"EdDSA",namedCurve:"Ed448"};case ol:return{name:"X25519"};case Vh:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};Jd=g([Ac()],Jd);lt.registerSingleton(Do,Jd);class h$ extends Cn{constructor(e){Cn.isAsnEncoded(e)?super(e,fo):super(e),this.tag=Ct.CertificateRequestTag}onInit(e){this.tbs=H.serialize(e.certificationRequestInfo),this.publicKey=new Jt(e.certificationRequestInfo.subjectPKInfo);const n=lt.resolve(Er);this.signatureAlgorithm=n.toWebAlgorithm(e.signatureAlgorithm),this.signature=e.signature,this.attributes=e.certificationRequestInfo.attributes.map(i=>jc.create(H.serialize(i)));const r=this.getAttribute(fp);this.extensions=[],r instanceof _p&&(this.extensions=r.items),this.subjectName=new Pt(e.certificationRequestInfo.subject),this.subject=this.subjectName.toString()}getAttribute(e){for(const n of this.attributes)if(n.type===e)return n;return null}getAttributes(e){return this.attributes.filter(n=>n.type===e)}getExtension(e){for(const n of this.extensions)if(n.type===e)return n;return null}getExtensions(e){return this.extensions.filter(n=>n.type===e)}async verify(e=it.get()){const n={...this.publicKey.algorithm,...this.signatureAlgorithm},r=await this.publicKey.export(n,["verify"],e),i=lt.resolveAll(Fo).reverse();let s=null;for(const c of i)if(s=c.toWebSignature(n,this.signature),s)break;if(!s)throw Error("Cannot convert WebCrypto signature value to ASN.1 format");return await e.subtle.verify(this.signatureAlgorithm,r,s,this.tbs)}toTextObject(){const e=this.toTextObjectEmpty(),n=H.parse(this.rawData,fo),r=n.certificationRequestInfo,i=new xe("",{Version:`${$r[r.version]} (${r.version})`,Subject:this.subject,"Subject Public Key Info":this.publicKey});if(this.attributes.length){const s=new xe("");for(const a of this.attributes){const c=a.toTextObject();s[c[xe.NAME]]=c}i.Attributes=s}return e.Data=i,e.Signature=new xe("",{Algorithm:Cr.serializeAlgorithm(n.signatureAlgorithm),"":n.signature}),e}}h$.NAME="PKCS#10 Certificate Request";class Oc extends Cn{constructor(e){Cn.isAsnEncoded(e)?super(e,kr):super(e),this.tag=Ct.CertificateTag}onInit(e){const n=e.tbsCertificate;this.tbs=H.serialize(n);let r=new Uint8Array(n.serialNumber);r.length>1&&r[0]===0&&r[1]>127&&(r=r.slice(1)),this.serialNumber=re.ToHex(r),this.subjectName=new Pt(n.subject),this.subject=new Pt(n.subject).toString(),this.issuerName=new Pt(n.issuer),this.issuer=this.issuerName.toString();const i=lt.resolve(Er);this.signatureAlgorithm=i.toWebAlgorithm(e.signatureAlgorithm),this.signature=e.signatureValue;const s=n.validity.notBefore.utcTime||n.validity.notBefore.generalTime;if(!s)throw new Error("Cannot get 'notBefore' value");this.notBefore=s;const a=n.validity.notAfter.utcTime||n.validity.notAfter.generalTime;if(!a)throw new Error("Cannot get 'notAfter' value");this.notAfter=a,this.extensions=[],n.extensions&&(this.extensions=n.extensions.map(c=>Tt.create(H.serialize(c)))),this.publicKey=new Jt(n.subjectPublicKeyInfo)}getExtension(e){for(const n of this.extensions)if(typeof e=="string"){if(n.type===e)return n}else if(n instanceof e)return n;return null}getExtensions(e){return this.extensions.filter(n=>typeof e=="string"?n.type===e:n instanceof e)}async verify(e={},n=it.get()){let r,i;const s=e.publicKey;try{if(!s)r={...this.publicKey.algorithm,...this.signatureAlgorithm},i=await this.publicKey.export(r,["verify"],n);else if("publicKey"in s)r={...s.publicKey.algorithm,...this.signatureAlgorithm},i=await s.publicKey.export(r,["verify"],n);else if(s instanceof Jt)r={...s.algorithm,...this.signatureAlgorithm},i=await s.export(r,["verify"],n);else if(G.isBufferSource(s)){const d=new Jt(s);r={...d.algorithm,...this.signatureAlgorithm},i=await d.export(r,["verify"],n)}else r={...s.algorithm,...this.signatureAlgorithm},i=s}catch{return!1}const a=lt.resolveAll(Fo).reverse();let c=null;for(const d of a)if(c=d.toWebSignature(r,this.signature),c)break;if(!c)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");const l=await n.subtle.verify(this.signatureAlgorithm,i,c,this.tbs);if(e.signatureOnly)return l;{const u=(e.date||new Date).getTime();return l&&this.notBefore.getTime()<u&&u<this.notAfter.getTime()}}async getThumbprint(...e){let n,r="SHA-1";return e[0]&&(e[0].subtle?n=e[0]:(r=e[0]||r,n=e[1])),n??(n=it.get()),await n.subtle.digest(r,this.rawData)}async isSelfSigned(e=it.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){const e=this.toTextObjectEmpty(),n=H.parse(this.rawData,kr),r=n.tbsCertificate,i=new xe("",{Version:`${$r[r.version]} (${r.version})`,"Serial Number":r.serialNumber,"Signature Algorithm":Cr.serializeAlgorithm(r.signature),Issuer:this.issuer,Validity:new xe("",{"Not Before":r.validity.notBefore.getTime(),"Not After":r.validity.notAfter.getTime()}),Subject:this.subject,"Subject Public Key Info":this.publicKey});if(r.issuerUniqueID&&(i["Issuer Unique ID"]=r.issuerUniqueID),r.subjectUniqueID&&(i["Subject Unique ID"]=r.subjectUniqueID),this.extensions.length){const s=new xe("");for(const a of this.extensions){const c=a.toTextObject();s[c[xe.NAME]]=c}i.Extensions=s}return e.Data=i,e.Signature=new xe("",{Algorithm:Cr.serializeAlgorithm(n.signatureAlgorithm),"":n.signatureValue}),e}}Oc.NAME="Certificate";class g${static async createSelfSigned(e,n=it.get()){if(!e.keys.privateKey)throw new Error("Bad field 'keys' in 'params' argument. 'privateKey' is empty");if(!e.keys.publicKey)throw new Error("Bad field 'keys' in 'params' argument. 'publicKey' is empty");return this.create({serialNumber:e.serialNumber,subject:e.name,issuer:e.name,notBefore:e.notBefore,notAfter:e.notAfter,publicKey:e.keys.publicKey,signingKey:e.keys.privateKey,signingAlgorithm:e.signingAlgorithm,extensions:e.extensions},n)}static async create(e,n=it.get()){var r;let i;e.publicKey instanceof Jt?i=e.publicKey.rawData:"publicKey"in e.publicKey?i=e.publicKey.publicKey.rawData:G.isBufferSource(e.publicKey)?i=e.publicKey:i=await n.subtle.exportKey("spki",e.publicKey);let s=e.serialNumber?G.toUint8Array(re.FromHex(e.serialNumber)):void 0;s=this.generateSerialNumber(s,n);const a=e.notBefore||new Date,c=e.notAfter||new Date(a.getTime()+31536e6),l=new kr({tbsCertificate:new jt({version:$r.v3,serialNumber:s,validity:new Co({notBefore:a,notAfter:c}),extensions:new Wn(((r=e.extensions)===null||r===void 0?void 0:r.map(b=>H.parse(b.rawData,Ut)))||[]),subjectPublicKeyInfo:H.parse(i,Gt)})});if(e.subject){const b=e.subject instanceof Pt?e.subject:new Pt(e.subject);l.tbsCertificate.subject=H.parse(b.toArrayBuffer(),Ve)}if(e.issuer){const b=e.issuer instanceof Pt?e.issuer:new Pt(e.issuer);l.tbsCertificate.issuer=H.parse(b.toArrayBuffer(),Ve)}const d={hash:"SHA-256"},u="signingKey"in e?{...d,...e.signingAlgorithm,...e.signingKey.algorithm}:{...d,...e.signingAlgorithm},f=lt.resolve(Er);l.tbsCertificate.signature=l.signatureAlgorithm=f.toAsnAlgorithm(u);const h=H.serialize(l.tbsCertificate),m="signingKey"in e?await n.subtle.sign(u,e.signingKey,h):e.signature,y=lt.resolveAll(Fo).reverse();let v=null;for(const b of y)if(v=b.toAsnSignature(u,m),v)break;if(!v)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return l.signatureValue=v,new Oc(H.serialize(l))}static generateSerialNumber(e,n){let r=e&&e.length&&e.some(s=>s>0)?new Uint8Array(e):void 0;r||(r=n.getRandomValues(new Uint8Array(16)));let i=0;for(;i<r.length-1&&r[i]===0;)i++;if(r=r.slice(i),r[0]>127){const s=new Uint8Array(r.length+1);s[0]=0,s.set(r,1),r=s}return r}}var Gh;(function(t){t[t.unspecified=0]="unspecified",t[t.keyCompromise=1]="keyCompromise",t[t.cACompromise=2]="cACompromise",t[t.affiliationChanged=3]="affiliationChanged",t[t.superseded=4]="superseded",t[t.cessationOfOperation=5]="cessationOfOperation",t[t.certificateHold=6]="certificateHold",t[t.removeFromCRL=8]="removeFromCRL",t[t.privilegeWithdrawn=9]="privilegeWithdrawn",t[t.aACompromise=10]="aACompromise"})(Gh||(Gh={}));Tt.register(U_,hp);Tt.register(F_,gp);Tt.register(H_,mp);Tt.register(W_,Mo);Tt.register(Fl,mo);Tt.register(G_,$y);Tt.register(Gl,xy);Tt.register(Ml,Sy);Tt.register(q_,zy);jc.register(my,Ay);jc.register(fp,_p);lt.registerSingleton(Fo,f$);lt.registerSingleton(Fo,Rt);Rt.namedCurveSize.set("P-256",32);Rt.namedCurveSize.set("K-256",32);Rt.namedCurveSize.set("P-384",48);Rt.namedCurveSize.set("P-521",66);async function Xd(t){const e={name:"RSASSA-PKCS1-v1_5",hash:"SHA-256",publicExponent:new Uint8Array([1,0,1]),modulusLength:2048},n=await crypto.subtle.generateKey(e,!0,["sign","verify"]),r=Ne(),i=El(new TextEncoder().encode(r)),s=await g$.createSelfSigned({serialNumber:i,name:t.name,notBefore:new Date,notAfter:new Date(Date.now()+365*24*60*60*1e3),signingAlgorithm:e,keys:n,extensions:[new hp(!0,2,!0),new gp(["1.3.6.1.5.5.7.3.1"],!0),new mp(Sa.keyCertSign|Sa.cRLSign,!0),await Mo.create(n.publicKey)]}),a=await crypto.subtle.exportKey("pkcs8",n.privateKey),c=s.toString("pem"),l=await _$(s),d=El(await s.getThumbprint()),u=m$("PRIVATE",a);return{kid:s.serialNumber,cert:c,thumbprint:d,fingerprint:l,pkcs7:u,type:"jwt_signing"}}function m$(t,e){const n=gv.encode(new Uint8Array(e));let r=`-----BEGIN ${t} KEY-----\r
189
189
  `,i=0;for(;i<n.length;)i+64<=n.length?r+=n.substr(i,64)+`\r
190
190
  `:r+=n.substr(i)+`\r
191
191
  `,i+=64;return r+=`-----END ${t} KEY-----\r
192
- `,r}async function _$(t){const e=await t.publicKey.export(),n=await crypto.subtle.exportKey("jwk",e),r=JSON.stringify(n,Object.keys(n).sort()),s=new TextEncoder().encode(r);return El(await _m(s))}const y$=1e3*60*60*24,w$=new o.OpenAPIHono().openapi(o.createRoute({tags:["keys"],method:"get",path:"/signing",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.array(Sl)}},description:"List of keys"}}}),async t=>{const{signingKeys:e}=await t.env.data.keys.list({q:"type:jwt_signing"}),n=e.filter(r=>"cert"in r).map(r=>r);return t.json(n)}).openapi(o.createRoute({tags:["keys"],method:"get",path:"/signing/{kid}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({kid:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Sl}},description:"The requested key"}}}),async t=>{const{kid:e}=t.req.valid("param"),{signingKeys:n}=await t.env.data.keys.list({q:"type:jwt_signing"}),r=n.find(i=>i.kid===e);if(!r)throw new S(404,{message:"Key not found"});return t.json(r)}).openapi(o.createRoute({tags:["keys"],method:"post",path:"/signing/rotate",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Status"}}}),async t=>{const{signingKeys:e}=await t.env.data.keys.list({q:"type:jwt_signing"});for await(const r of e)await t.env.data.keys.update(r.kid,{revoked_at:new Date(Date.now()+y$).toISOString()});const n=await Xd({name:`CN=${t.env.ORGANIZATION_NAME}`});return await t.env.data.keys.create({...n,type:"jwt_signing"}),t.text("OK",{status:201})}).openapi(o.createRoute({tags:["keys"],method:"put",path:"/signing/{kid}/revoke",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({kid:o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Status"}}}),async t=>{const{kid:e}=t.req.valid("param");if(!await t.env.data.keys.update(e,{revoked_at:new Date().toISOString()}))throw new S(404,{message:"Key not found"});const r=await Xd({name:`CN=${t.env.ORGANIZATION_NAME}`});return await t.env.data.keys.create({...r,type:"jwt_signing"}),t.text("OK")}),v$=new o.OpenAPIHono().openapi(o.createRoute({tags:["users"],method:"get",path:"/",request:{query:o.z.object({email:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"tenant/json":{schema:o.z.array(gu)}},description:"List of users"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{email:n}=t.req.valid("query"),i=(await Eu(t.env.data.users,e,n)).filter(s=>!s.linked_to);return t.json(i)}),b$=St.extend({clients:o.z.array(sr)}),$$=new o.OpenAPIHono().openapi(o.createRoute({tags:["clients"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([b$,o.z.array(sr)])}},description:"List of clients"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{page:n,per_page:r,include_totals:i,sort:s,q:a}=t.req.valid("query"),l=(await t.env.data.clients.list(e,{page:n,per_page:r,include_totals:i,sort:ft(s),q:a})).clients;return i?t.json({clients:l,start:0,limit:10,length:l.length}):t.json(l)}).openapi(o.createRoute({tags:["clients"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:sr}},description:"A client"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.clients.get(e,n);if(!r)throw new S(404);return t.json(r)}).openapi(o.createRoute({tags:["clients"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.clients.remove(e,n))throw new S(404,{message:"Client not found"});return t.text("OK")}).openapi(o.createRoute({tags:["clients"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Ts.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:sr}},description:"The updated client"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),i=t.req.valid("json");await t.env.data.clients.update(e,n,i);const s=await t.env.data.clients.get(e,n);if(!s)throw new S(404,{message:"Client not found"});return t.json(s)}).openapi(o.createRoute({tags:["clients"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Ts.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:o.z.object(sr.shape)}},description:"A client"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r={...n,client_secret:n.client_secret||Ne()},i=await t.env.data.clients.create(e,r);return t.json(i,{status:201})});o.z.object({start:o.z.number(),limit:o.z.number(),length:o.z.number()});Oa.extend({email:o.z.string(),login_count:o.z.number(),multifactor:o.z.array(o.z.string()).optional(),last_ip:o.z.string().optional(),last_login:o.z.string().optional(),user_id:o.z.string()}).catchall(o.z.any());const k$=St.extend({tenants:o.z.array(Un)}),x$=new o.OpenAPIHono().openapi(o.createRoute({tags:["tenants","settings"],method:"get",path:"/settings",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Un}},description:"Current tenant settings"}}}),async t=>{const e=await t.env.data.tenants.get(t.var.tenant_id);if(!e)throw new S(404,{message:"Tenant not found"});return t.json(e)}).openapi(o.createRoute({tags:["tenants","settings"],method:"patch",path:"/settings",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object(Ki.shape).partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Un}},description:"Updated tenant settings"}}}),async t=>{const e=t.req.valid("json"),{id:n,...r}=e,i=await t.env.data.tenants.get(t.var.tenant_id);if(!i)throw new S(404,{message:"Tenant not found"});const s=zl(i,r);await t.env.data.tenants.update(t.var.tenant_id,s);const a=await t.env.data.tenants.get(t.var.tenant_id);if(!a)throw new S(500,{message:"Failed to retrieve updated tenant"});return t.json(a)}).openapi(o.createRoute({tags:["tenants"],method:"get",path:"/",request:{query:Qe},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"tenant/json":{schema:o.z.union([o.z.array(Un),k$])}},description:"List of tenants"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),a=await t.env.data.tenants.list({page:e,per_page:n,include_totals:r,sort:ft(i),q:s});return r?t.json(a):t.json(a.tenants)}).openapi(o.createRoute({tags:["tenants"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"tenant/json":{schema:Un}},description:"A tenant"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.tenants.get(e);if(!n)throw new S(404);return t.json(n)}).openapi(o.createRoute({tags:["tenants"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");return await t.env.data.tenants.remove(e),t.text("OK")}).openapi(o.createRoute({tags:["tenants"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Ki.shape).partial()}}},params:o.z.object({id:o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param"),n=t.req.valid("json");return await t.env.data.tenants.update(e,n),t.text("OK")}).openapi(o.createRoute({tags:["tenants"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Ki.shape)}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"tenant/json":{schema:Un}},description:"An tenant"}}}),async t=>{const e=t.req.valid("json"),n=await t.env.data.tenants.create(e);return t.json(n,{status:201})}),S$=St.extend({logs:o.z.array(Ls)}),z$=new o.OpenAPIHono().openapi(o.createRoute({tags:["logs"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Ls),S$])}},description:"List of log rows"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),a=await t.env.data.logs.list(t.var.tenant_id,{page:e,per_page:n,include_totals:r,sort:ft(i),q:s});return r?t.json(a):t.json(a.logs)}).openapi(o.createRoute({tags:["logs"],method:"get",path:"/{id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({id:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ls}},description:"A log entry"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.logs.get(t.var.tenant_id,e);if(!n)throw new S(404);return t.json(n)}),A$=17,E$={organization:"org_",connection:"con_",action:"act_",hook:"h_",rule:"rul_",resource_server:"api_",guardian_factor:"gfa_",invite:"inv_"};function Tc(t){const r=mm("0123456789abcdefghijklmnopqrstuvwxyz",A$)();return`${E$[t]}${r}`}function C$(){return Tc("organization")}function N$(){return Tc("connection")}function I$(){return Tc("hook")}function j$(){return Tc("invite")}const O$=St.extend({hooks:o.z.array(Kr)}),T$=new o.OpenAPIHono().openapi(o.createRoute({tags:["hooks"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Kr),O$])}},description:"List of hooks"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),a=await t.env.data.hooks.list(t.var.tenant_id,{page:e,per_page:n,include_totals:r,sort:ft(i),q:s});return r?t.json(a):t.json(a.hooks)}).openapi(o.createRoute({tags:["hooks"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:ds}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Kr}},description:"The created hook"}}}),async t=>{const e=t.req.valid("json"),n={...e,hook_id:e.hook_id||I$()},r=await t.env.data.hooks.create(t.var.tenant_id,n);return t.json(r,{status:201})}).openapi(o.createRoute({tags:["hooks"],method:"patch",path:"/{hook_id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({hook_id:o.z.string()}),body:{content:{"application/json":{schema:o.z.union([ds.options[0].omit({hook_id:!0}).partial(),ds.options[1].omit({hook_id:!0}).partial()])}}}},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Kr}},description:"The updated hook"},404:{description:"Hook not found"}}}),async t=>{const{hook_id:e}=t.req.valid("param"),n=t.req.valid("json");await t.env.data.hooks.update(t.var.tenant_id,e,n);const r=await t.env.data.hooks.get(t.var.tenant_id,e);if(!r)throw new S(404,{message:"Hook not found"});return t.json(r)}).openapi(o.createRoute({tags:["hooks"],method:"get",path:"/{hook_id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({hook_id:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Kr}},description:"A hook"},404:{description:"Hook not found"}}}),async t=>{const{hook_id:e}=t.req.valid("param"),n=await t.env.data.hooks.get(t.var.tenant_id,e);if(!n)throw new S(404,{message:"Hook not found"});return t.json(n)}).openapi(o.createRoute({tags:["hooks"],method:"delete",path:"/{hook_id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({hook_id:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{description:"A hook"}}}),async t=>{const{hook_id:e}=t.req.valid("param");if(!await t.env.data.hooks.remove(t.var.tenant_id,e))throw new S(404,{message:"Hook not found"});return t.text("OK")}),P$=St.extend({connections:o.z.array(Kt)}),R$=new o.OpenAPIHono().openapi(o.createRoute({tags:["connections"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Kt),P$])}},description:"List of connectionss"}}}),async t=>{const{page:e,per_page:n,include_totals:r=!1,sort:i,q:s}=t.req.valid("query"),a=await t.env.data.connections.list(t.var.tenant_id,{page:e,per_page:n,include_totals:r,sort:ft(i),q:s});return r?t.json(a):t.json(a.connections)}).openapi(o.createRoute({tags:["connections"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Kt}},description:"A connection"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.connections.get(t.var.tenant_id,e);if(!n)throw new S(404);return t.json(n)}).openapi(o.createRoute({tags:["connections"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.connections.remove(t.var.tenant_id,e))throw new S(404,{message:"Connection not found"});return t.text("OK")}).openapi(o.createRoute({tags:["connections"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Rs.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Kt}},description:"The updated connection"}}}),async t=>{const{id:e}=t.req.valid("param"),n=t.req.valid("json");if(!await t.env.data.connections.update(t.var.tenant_id,e,n))throw new S(404,{message:"Connection not found"});const i=await t.env.data.connections.get(t.var.tenant_id,e);if(!i)throw new S(404,{message:"Connection not found"});return t.json(i)}).openapi(o.createRoute({tags:["connections"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Rs.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Kt}},description:"A connection"}}}),async t=>{const e=t.req.valid("json"),n={...e,id:e.id||N$()},r=await t.env.data.connections.create(t.var.tenant_id,n);return t.json(r,{status:201})}),B$=new o.OpenAPIHono().openapi(o.createRoute({tags:["prompts"],method:"get",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:ps}},description:"Branding settings"}}}),async t=>{const e=await t.env.data.promptSettings.get(t.var.tenant_id);return e?t.json(e):t.json(ps.parse({}))}).openapi(o.createRoute({tags:["prompts"],method:"patch",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object(ps.shape).partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Prompts settings"}}}),async t=>{const e=t.req.valid("json"),n=await t.env.data.promptSettings.get(t.var.tenant_id);return Object.assign(n,e),await t.env.data.promptSettings.set(t.var.tenant_id,n),t.json(n)});let Wh=!1;function yp(t){t.use(async(e,n)=>(Wh||(t.openAPIRegistry.registerComponent("securitySchemes","Bearer",{type:"oauth2",scheme:"bearer",flows:{implicit:{authorizationUrl:`${e.env.AUTH_URL}/authorize`,scopes:{openid:"Basic user information",email:"User email",profile:"User profile information"}}}}),Wh=!0),await n()))}var L$=(t,e)=>{try{return e(t)}catch{return t.replace(/(?:%[0-9A-Fa-f]{2})+/g,n=>{try{return e(n)}catch{return n}})}},U$=decodeURIComponent,D$=/^[\w!#$%&'*.^`|~+-]+$/,M$=/^[ !#-:<-[\]-~]*$/,F$=(t,e)=>{if(t.indexOf(e)===-1)return{};const n=t.trim().split(";"),r={};for(let i of n){i=i.trim();const s=i.indexOf("=");if(s===-1)continue;const a=i.substring(0,s).trim();if(e!==a||!D$.test(a))continue;let c=i.substring(s+1).trim();if(c.startsWith('"')&&c.endsWith('"')&&(c=c.slice(1,-1)),M$.test(c)){r[a]=c.indexOf("%")!==-1?L$(c,U$):c;break}}return r},q$=(t,e,n={})=>{let r=`${t}=${e}`;if(t.startsWith("__Secure-")&&!n.secure)throw new Error("__Secure- Cookie must have Secure attributes");if(t.startsWith("__Host-")){if(!n.secure)throw new Error("__Host- Cookie must have Secure attributes");if(n.path!=="/")throw new Error('__Host- Cookie must have Path attributes with "/"');if(n.domain)throw new Error("__Host- Cookie must not have Domain attributes")}if(n&&typeof n.maxAge=="number"&&n.maxAge>=0){if(n.maxAge>3456e4)throw new Error("Cookies Max-Age SHOULD NOT be greater than 400 days (34560000 seconds) in duration.");r+=`; Max-Age=${n.maxAge|0}`}if(n.domain&&n.prefix!=="host"&&(r+=`; Domain=${n.domain}`),n.path&&(r+=`; Path=${n.path}`),n.expires){if(n.expires.getTime()-Date.now()>3456e7)throw new Error("Cookies Expires SHOULD NOT be greater than 400 days (34560000 seconds) in the future.");r+=`; Expires=${n.expires.toUTCString()}`}if(n.httpOnly&&(r+="; HttpOnly"),n.secure&&(r+="; Secure"),n.sameSite&&(r+=`; SameSite=${n.sameSite.charAt(0).toUpperCase()+n.sameSite.slice(1)}`),n.priority&&(r+=`; Priority=${n.priority.charAt(0).toUpperCase()+n.priority.slice(1)}`),n.partitioned){if(!n.secure)throw new Error("Partitioned Cookie must have Secure attributes");r+="; Partitioned"}return r},al=(t,e,n)=>(e=encodeURIComponent(e),q$(t,e,n)),H$=(t,e,n)=>{const r=t.req.raw.headers.get("Cookie");{if(!r)return;let i=e;return F$(r,i)[i]}},V$=(t,e,n)=>{let r;return(n==null?void 0:n.prefix)==="secure"?r=al("__Secure-"+t,e,{path:"/",...n,secure:!0}):(n==null?void 0:n.prefix)==="host"?r=al("__Host-"+t,e,{...n,path:"/",secure:!0,domain:void 0}):r=al(t,e,{path:"/",...n}),r},Jh=(t,e,n,r)=>{const i=V$(e,n,r);t.header("Set-Cookie",i,{append:!0})},Ey=t=>Ny(t.replace(/_|-/g,e=>({_:"/","-":"+"})[e]??e)),Cy=t=>K$(t).replace(/\/|\+/g,e=>({"/":"_","+":"-"})[e]??e),K$=t=>{let e="";const n=new Uint8Array(t);for(let r=0,i=n.length;r<i;r++)e+=String.fromCharCode(n[r]);return btoa(e)},Ny=t=>{const e=atob(t),n=new Uint8Array(new ArrayBuffer(e.length)),r=e.length/2;for(let i=0,s=e.length-1;i<=r;i++,s--)n[i]=e.charCodeAt(i),n[s]=e.charCodeAt(s);return n},Iy=(t=>(t.HS256="HS256",t.HS384="HS384",t.HS512="HS512",t.RS256="RS256",t.RS384="RS384",t.RS512="RS512",t.PS256="PS256",t.PS384="PS384",t.PS512="PS512",t.ES256="ES256",t.ES384="ES384",t.ES512="ES512",t.EdDSA="EdDSA",t))(Iy||{}),G$=class extends Error{constructor(t){super(`${t} is not an implemented algorithm`),this.name="JwtAlgorithmNotImplemented"}},Pc=class extends Error{constructor(t){super(`invalid JWT token: ${t}`),this.name="JwtTokenInvalid"}},W$=class extends Error{constructor(t){super(`token (${t}) is being used before it's valid`),this.name="JwtTokenNotBefore"}},J$=class extends Error{constructor(t){super(`token (${t}) expired`),this.name="JwtTokenExpired"}},X$=class extends Error{constructor(t,e){super(`Invalid "iat" claim, must be a valid number lower than "${t}" (iat: "${e}")`),this.name="JwtTokenIssuedAt"}},cl=class extends Error{constructor(t,e){super(`expected issuer "${t}", got ${e?`"${e}"`:"none"} `),this.name="JwtTokenIssuer"}},jy=class extends Error{constructor(t){super(`jwt header is invalid: ${JSON.stringify(t)}`),this.name="JwtHeaderInvalid"}},Z$=class extends Error{constructor(t){super(`required "kid" in jwt header: ${JSON.stringify(t)}`),this.name="JwtHeaderRequiresKid"}},Y$=class extends Error{constructor(t){super(`token(${t}) signature mismatched`),this.name="JwtTokenSignatureMismatched"}},_o=(t=>(t.Encrypt="encrypt",t.Decrypt="decrypt",t.Sign="sign",t.Verify="verify",t.DeriveKey="deriveKey",t.DeriveBits="deriveBits",t.WrapKey="wrapKey",t.UnwrapKey="unwrapKey",t))(_o||{}),qo=new TextEncoder,Q$=new TextDecoder;async function e4(t,e,n){const r=Oy(e),i=await n4(t,r);return await crypto.subtle.sign(r,i,n)}async function t4(t,e,n,r){const i=Oy(e),s=await r4(t,i);return await crypto.subtle.verify(i,s,n,r)}function Zd(t){return Ny(t.replace(/-+(BEGIN|END).*/g,"").replace(/\s/g,""))}async function n4(t,e){if(!crypto.subtle||!crypto.subtle.importKey)throw new Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");if(Ty(t)){if(t.type!=="private"&&t.type!=="secret")throw new Error(`unexpected key type: CryptoKey.type is ${t.type}, expected private or secret`);return t}const n=[_o.Sign];return typeof t=="object"?await crypto.subtle.importKey("jwk",t,e,!1,n):t.includes("PRIVATE")?await crypto.subtle.importKey("pkcs8",Zd(t),e,!1,n):await crypto.subtle.importKey("raw",qo.encode(t),e,!1,n)}async function r4(t,e){if(!crypto.subtle||!crypto.subtle.importKey)throw new Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");if(Ty(t)){if(t.type==="public"||t.type==="secret")return t;t=await Xh(t)}if(typeof t=="string"&&t.includes("PRIVATE")){const r=await crypto.subtle.importKey("pkcs8",Zd(t),e,!0,[_o.Sign]);t=await Xh(r)}const n=[_o.Verify];return typeof t=="object"?await crypto.subtle.importKey("jwk",t,e,!1,n):t.includes("PUBLIC")?await crypto.subtle.importKey("spki",Zd(t),e,!1,n):await crypto.subtle.importKey("raw",qo.encode(t),e,!1,n)}async function Xh(t){if(t.type!=="private")throw new Error(`unexpected key type: ${t.type}`);if(!t.extractable)throw new Error("unexpected private key is unextractable");const e=await crypto.subtle.exportKey("jwk",t),{kty:n}=e,{alg:r,e:i,n:s}=e,{crv:a,x:c,y:l}=e;return{kty:n,alg:r,e:i,n:s,crv:a,x:c,y:l,key_ops:[_o.Verify]}}function Oy(t){switch(t){case"HS256":return{name:"HMAC",hash:{name:"SHA-256"}};case"HS384":return{name:"HMAC",hash:{name:"SHA-384"}};case"HS512":return{name:"HMAC",hash:{name:"SHA-512"}};case"RS256":return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case"RS384":return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case"RS512":return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case"PS256":return{name:"RSA-PSS",hash:{name:"SHA-256"},saltLength:32};case"PS384":return{name:"RSA-PSS",hash:{name:"SHA-384"},saltLength:48};case"PS512":return{name:"RSA-PSS",hash:{name:"SHA-512"},saltLength:64};case"ES256":return{name:"ECDSA",hash:{name:"SHA-256"},namedCurve:"P-256"};case"ES384":return{name:"ECDSA",hash:{name:"SHA-384"},namedCurve:"P-384"};case"ES512":return{name:"ECDSA",hash:{name:"SHA-512"},namedCurve:"P-521"};case"EdDSA":return{name:"Ed25519",namedCurve:"Ed25519"};default:throw new G$(t)}}function Ty(t){return Rm()==="node"&&crypto.webcrypto?t instanceof crypto.webcrypto.CryptoKey:t instanceof CryptoKey}var ll=t=>Cy(qo.encode(JSON.stringify(t)).buffer).replace(/=/g,""),i4=t=>Cy(t).replace(/=/g,""),Yd=t=>JSON.parse(Q$.decode(Ey(t)));function Py(t){if(typeof t=="object"&&t!==null){const e=t;return"alg"in e&&Object.values(Iy).includes(e.alg)&&(!("typ"in e)||e.typ==="JWT")}return!1}var o4=async(t,e,n="HS256")=>{const r=ll(t);let i;typeof e=="object"&&"alg"in e?(n=e.alg,i=ll({alg:n,typ:"JWT",kid:e.kid})):i=ll({alg:n,typ:"JWT"});const s=`${i}.${r}`,a=await e4(e,n,qo.encode(s)),c=i4(a);return`${s}.${c}`},Ry=async(t,e,n)=>{const r=typeof n=="string"?{alg:n}:n||{},i={alg:r.alg??"HS256",iss:r.iss,nbf:r.nbf??!0,exp:r.exp??!0,iat:r.iat??!0},s=t.split(".");if(s.length!==3)throw new Pc(t);const{header:a,payload:c}=By(t);if(!Py(a))throw new jy(a);const l=Date.now()/1e3|0;if(i.nbf&&c.nbf&&c.nbf>l)throw new W$(t);if(i.exp&&c.exp&&c.exp<=l)throw new J$(t);if(i.iat&&c.iat&&l<c.iat)throw new X$(l,c.iat);if(i.iss){if(!c.iss)throw new cl(i.iss,null);if(typeof i.iss=="string"&&c.iss!==i.iss)throw new cl(i.iss,c.iss);if(i.iss instanceof RegExp&&!i.iss.test(c.iss))throw new cl(i.iss,c.iss)}const d=t.substring(0,t.lastIndexOf("."));if(!await t4(e,i.alg,Ey(s[2]),qo.encode(d)))throw new Y$(t);return c},s4=async(t,e,n)=>{const r=e.verification||{},i=a4(t);if(!Py(i))throw new jy(i);if(!i.kid)throw new Z$(i);if(e.jwks_uri){const a=await fetch(e.jwks_uri,n);if(!a.ok)throw new Error(`failed to fetch JWKS from ${e.jwks_uri}`);const c=await a.json();if(!c.keys)throw new Error('invalid JWKS response. "keys" field is missing');if(!Array.isArray(c.keys))throw new Error('invalid JWKS response. "keys" field is not an array');e.keys?e.keys.push(...c.keys):e.keys=c.keys}else if(!e.keys)throw new Error('verifyWithJwks requires options for either "keys" or "jwks_uri" or both');const s=e.keys.find(a=>a.kid===i.kid);if(!s)throw new Pc(t);return await Ry(t,s,{alg:s.alg||i.alg,...r})},By=t=>{try{const[e,n]=t.split("."),r=Yd(e),i=Yd(n);return{header:r,payload:i}}catch{throw new Pc(t)}},a4=t=>{try{const[e]=t.split(".");return Yd(e)}catch{throw new Pc(t)}},Ly={sign:o4,verify:Ry,decode:By,verifyWithJwks:s4},c4={Stringify:1,BeforeStream:2,Stream:3},Zt=(t,e)=>{const n=new String(t);return n.isEscaped=!0,n.callbacks=e,n},l4=/[&<>'"]/,Uy=async(t,e)=>{let n="";e||(e=[]);const r=await Promise.all(t);for(let i=r.length-1;n+=r[i],i--,!(i<0);i--){let s=r[i];typeof s=="object"&&e.push(...s.callbacks||[]);const a=s.isEscaped;if(s=await(typeof s=="object"?s.toString():s),typeof s=="object"&&e.push(...s.callbacks||[]),s.isEscaped??a)n+=s;else{const c=[n];Kn(s,c),n=c[0]}}return Zt(n,e)},Kn=(t,e)=>{const n=t.search(l4);if(n===-1){e[0]+=t;return}let r,i,s=0;for(i=n;i<t.length;i++){switch(t.charCodeAt(i)){case 34:r="&quot;";break;case 39:r="&#39;";break;case 38:r="&amp;";break;case 60:r="&lt;";break;case 62:r="&gt;";break;default:continue}e[0]+=t.substring(s,i)+r,s=i+1}e[0]+=t.substring(s,i)},Dy=t=>{const e=t.callbacks;if(!(e!=null&&e.length))return t;const n=[t],r={};return e.forEach(i=>i({phase:c4.Stringify,buffer:n,context:r})),n[0]},d4=Ly.verify,u4=Ly.decode;async function Qd(t){const{signingKeys:e}=await t.keys.list({q:"type:jwt_signing"});return await Promise.all(e.map(async r=>{const s=await new Oc(r.cert).publicKey.export(),a=await crypto.subtle.exportKey("jwk",s);return vu.parse({...a,kid:r.kid})}))}o.z.object({alg:o.z.literal("RS256"),kty:o.z.literal("RSA"),use:o.z.literal("sig"),n:o.z.string(),e:o.z.string(),kid:o.z.string(),x5t:o.z.string(),x5c:o.z.array(o.z.string())});async function p4(t){if(t.JWKS_URL&&t.JWKS_SERVICE){const e=await t.JWKS_SERVICE.fetch(t.JWKS_URL);return e.ok?(await e.json()).keys:(console.warn(`JWKS fetch failed with status ${e.status}, falling back to database`),await Qd(t.data))}return await Qd(t.data)}async function f4(t,e){try{const{header:n}=u4(e),i=(await p4(t.env)).find(c=>c.kid===n.kid);if(!i)throw new ee(401,{message:"No matching kid found"});const s=await crypto.subtle.importKey("jwk",i,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!1,["verify"]);return await d4(e,s,"RS256")}catch(n){throw n instanceof S?n:new ee(403,{message:"Invalid JWT signature"})}}function h4(t){return t.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g,"{$1}")}function g4(t,e){return e.startsWith(t)?e:t+e}function wp(t){return async(e,n)=>{var c,l,d;const r=e.req.matchedRoutes.find(u=>u.method.toUpperCase()===e.req.method&&u.path!=="/*");if(!r)return await n();const i=h4(r.path),s="basePath"in r&&typeof r.basePath=="string"?r.basePath:"",a=t.openAPIRegistry.definitions.find(u=>"route"in u&&g4(s,u.route.path)===i&&u.route.method.toUpperCase()===e.req.method.toUpperCase());if(a&&"route"in a){const u=(l=(c=a.route.security)==null?void 0:c[0])==null?void 0:l.Bearer;if(!(u!=null&&u.length))return await n();const f=e.req.header("authorization")||"",[h,m]=f.split(" ");if((h==null?void 0:h.toLowerCase())!=="bearer"||!m)throw new ee(401,{message:"Missing bearer token"});try{const y=await f4(e,m);e.set("user_id",y.sub),e.set("user",y),!e.var.tenant_id&&y.tenant_id&&e.set("tenant_id",y.tenant_id);const v=y.permissions||[],b=((d=y.scope)==null?void 0:d.split(" "))||[];if(u.length&&!(u.some(A=>v.includes(A))||u.some(A=>b.includes(A))))throw new ee(403,{message:"Unauthorized"})}catch(y){throw y instanceof S?y:new ee(403,{message:"Invalid token"})}}return await n()}}const m4=new o.OpenAPIHono().openapi(o.createRoute({tags:["emails"],method:"get",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:fs}},description:"Email provider"}}}),async t=>{const e=await t.env.data.emailProviders.get(t.var.tenant_id);if(!e)throw new S(404,{message:"Email provider not found"});return t.json(e)}).openapi(o.createRoute({tags:["emails"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object(fs.shape)}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Branding settings"}}}),async t=>{const e=t.req.valid("json");return await t.env.data.emailProviders.create(t.var.tenant_id,e),t.text("OK",{status:201})}).openapi(o.createRoute({tags:["emails"],method:"patch",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object(fs.shape).partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Branding settings"}}}),async t=>{const e=t.req.valid("json");return await t.env.data.emailProviders.update(t.var.tenant_id,e),t.text("OK")}),_4=new o.OpenAPIHono().openapi(o.createRoute({tags:["sessions"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ba}},description:"A session"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.sessions.get(t.var.tenant_id,e);if(!n)throw new S(404);return t.json(n)}).openapi(o.createRoute({tags:["sessions"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.sessions.remove(t.var.tenant_id,e))throw new S(404,{message:"Session not found"});return t.text("OK")}).openapi(o.createRoute({tags:["sessions"],method:"post",path:"/{id}/revoke",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{202:{description:"Sesssion deletion status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.sessions.update(t.var.tenant_id,e,{revoked_at:new Date().toDateString()}))throw new S(404,{message:"Session not found"});return t.text("Session deletion request accepted.",{status:202})}),y4=new o.OpenAPIHono().openapi(o.createRoute({tags:["refresh_tokens"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:$u}},description:"A session"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.refreshTokens.get(t.var.tenant_id,e);if(!n)throw new S(404);return t.json(n)}).openapi(o.createRoute({tags:["refresh_tokens"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.refreshTokens.remove(t.var.tenant_id,e))throw new S(404,{message:"Session not found"});return t.text("OK")}),w4=new o.OpenAPIHono().openapi(o.createRoute({tags:["custom-domains"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.array(Ln)}},description:"List of custom domains"}}}),async t=>{const e=await t.env.data.customDomains.list(t.var.tenant_id);return t.json(e)}).openapi(o.createRoute({tags:["custom-domains"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ln}},description:"A customDomain"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.customDomains.get(t.var.tenant_id,e);if(!n)throw new S(404);return t.json(n)}).openapi(o.createRoute({tags:["custom-domains"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.customDomains.remove(t.var.tenant_id,e))throw new S(404,{message:"Custom domain not found"});return t.text("OK")}).openapi(o.createRoute({tags:["custom-domains"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Ln.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Ln}},description:"The updated custom domain"}}}),async t=>{const{id:e}=t.req.valid("param"),n=t.req.valid("json");if(!await t.env.data.customDomains.update(t.var.tenant_id,e,n))throw new S(404);const i=await t.env.data.customDomains.get(t.var.tenant_id,e);if(!i)throw new S(404);return t.json(i)}).openapi(o.createRoute({tags:["custom-domains"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(yu.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Ln}},description:"The created custom domain"}}}),async t=>{const e=t.req.valid("json"),n=await t.env.data.customDomains.create(t.var.tenant_id,e);return t.json(n,{status:201})}).openapi(o.createRoute({tags:["custom-domains"],method:"post",path:"/{id}/verify",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Ln}},description:"The custom domain"}}}),async()=>{throw new S(501,{message:"Not implemented"})});function Rc(t,e){const n={};for(const[r,i]of Object.entries(e)){const s={};for(const[a,c]of Object.entries(i))typeof c=="function"?s[a]=async(...l)=>{const d=performance.now();try{const u=await c(...l),h=performance.now()-d,m=t.res.headers.get("Server-Timing")||"",y=m?`${m}, ${r}-${a};dur=${h.toFixed(2)}`:`${r}-${a};dur=${h.toFixed(2)}`;return t.res.headers.set("Server-Timing",y),u}catch(u){const h=performance.now()-d,m=t.res.headers.get("Server-Timing")||"",y=m?`${m}, ${r}-${a}-error;dur=${h.toFixed(2)}`:`${r}-${a}-error;dur=${h.toFixed(2)}`;throw t.res.headers.set("Server-Timing",y),u}}:s[a]=c;n[r]=s}return n}function Bc(t){return t.ISSUER}function st(t){return t.UNIVERSAL_LOGIN_URL||`${t.ISSUER}u/`}function He(t){return t.OAUTH_API_URL||t.ISSUER}async function Lc(t,e){const n=t.req.header("x-forwarded-host");if(n){const i=await t.env.data.customDomains.getByDomain(n);if(i)return t.set("tenant_id",i.tenant_id),t.set("custom_domain",n),t.set("host",n),await e()}const r=t.req.header("host");if(r){t.set("host",r);const i=r.split(".");if(i.length>1&&typeof i[0]=="string"){const s=i[0];await t.env.data.tenants.get(s)&&t.set("tenant_id",s)}}else t.set("host",new URL(Bc(t.env)).host);if(!t.var.tenant_id){const i=t.req.header("tenant-id");i&&t.set("tenant_id",i)}return await e()}const v4=o.z.object({name:o.z.string(),version:o.z.string(),env:o.z.object({node:o.z.string().optional()}).optional()});function b4(t){if(t)try{let e=t;try{e=atob(t)}catch{}try{const n=JSON.parse(e);return v4.parse(n)}catch{}}catch{return}}const Uc=async(t,e)=>{var l,d,u,f;const n=(l=t.req.query("auth0Client"))==null?void 0:l.slice(0,255),i=(d=(()=>{var h;if(t.req.header("x-forwarded-host")&&t.req.header("x-forwarded-for")){const m=t.req.header("x-forwarded-for");return(h=m==null?void 0:m.split(",")[0])==null?void 0:h.trim()}return t.req.header("cf-connecting-ip")||t.req.header("x-real-ip")})())==null?void 0:d.slice(0,45),s=(u=t.req.header("user-agent"))==null?void 0:u.slice(0,512),a=(f=t.req.header("cf-ipcountry"))==null?void 0:f.slice(0,2),c=n?b4(n):void 0;c&&t.set("auth0_client",c),i&&t.set("ip",i),s&&t.set("useragent",s),a&&t.set("countryCode",a),await e()};function $4(t,e,n,r){try{const i=`${t}:${e}:${JSON.stringify(n)}`;return r?`${r}:${i}`:i}catch{const s=`${t}:${e}:${Date.now()}-${Math.random()}`;return r?`${r}:${s}`:s}}function Dc(t,e){const{cache:n,defaultTtl:r,customTtls:i={},excludeMethods:s=[],cacheEntities:a=[],keyPrefix:c}=e,l=new Set(s),d=a.length===0,u=new Set(a),f={};for(const[h,m]of Object.entries(t)){const y=d||u.has(h),v={};for(const[b,A]of Object.entries(m))if(typeof A=="function"){if(!y){v[b]=A;continue}const O=`${h}:${b}`;if(l.has(O)){v[b]=A;continue}const U=i[O]??r,T=["create","update","remove","delete","set","used"].includes(b);v[b]=async(...R)=>{if(T)return await A.apply(m,R);const W=$4(h,b,R,c),ne=await n.get(W);if(ne!==null)if(ne&&typeof ne=="object"&&"isCachedNull"in ne){const K=ne;return K.isCachedNull?null:K.value}else return ne;const Q=await A.apply(m,R);if(U>=0)if(Q!==null)await n.set(W,Q,U);else{const K={value:null,isCachedNull:!0};await n.set(W,K,U)}return Q}}else v[b]=A;f[h]=v}return f}class k4{constructor(e={}){ae(this,"cache",new Map);ae(this,"accessOrder",new Map);ae(this,"accessCounter",0);ae(this,"cleanupTimer");this.config=e;const n=e.cleanupIntervalMs;n&&n>0&&(this.cleanupTimer=setInterval(()=>{this.cleanupExpired()},n))}async get(e){const n=this.cache.get(e);return n?n.expiresAt&&n.expiresAt<new Date?(this.cache.delete(e),this.accessOrder.delete(e),null):(this.accessOrder.set(e,++this.accessCounter),n.value):null}async set(e,n,r){let i;const s=r??this.config.defaultTtlSeconds,a=s!==void 0,c=a?Math.max(0,s):0;a&&(i=new Date(Date.now()+(c>0?c*1e3:-1))),this.config.maxEntries&&this.cache.size>=this.config.maxEntries&&!this.cache.has(e)&&this.evictLeastRecentlyUsed();const l={value:n,expiresAt:i};this.cache.set(e,l),this.accessOrder.set(e,++this.accessCounter)}async delete(e){const n=this.cache.has(e);return this.cache.delete(e),this.accessOrder.delete(e),n}async clear(){this.cache.clear(),this.accessOrder.clear(),this.accessCounter=0}getStats(){return{size:this.cache.size,maxEntries:this.config.maxEntries,defaultTtlSeconds:this.config.defaultTtlSeconds}}cleanupExpired(){const e=new Date,n=[];for(const[r,i]of this.cache.entries())i.expiresAt&&i.expiresAt<e&&n.push(r);for(const r of n)this.cache.delete(r),this.accessOrder.delete(r)}evictLeastRecentlyUsed(){let e=null,n=1/0;for(const[r,i]of this.accessOrder.entries())i<n&&(n=i,e=r);e&&(this.cache.delete(e),this.accessOrder.delete(e))}destroy(){this.cleanupTimer&&(clearInterval(this.cleanupTimer),this.cleanupTimer=void 0)}}function Ho(t={}){return new k4(t)}const x4=St.extend({forms:o.z.array(Vr)}),S4=new o.OpenAPIHono().openapi(o.createRoute({tags:["forms"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Vr),x4])}},description:"List of forms"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{page:n,per_page:r,include_totals:i=!1,sort:s,q:a}=t.req.valid("query"),c=await t.env.data.forms.list(e,{page:n,per_page:r,include_totals:i,sort:ft(s),q:a});return i?t.json(c):t.json(c.forms)}).openapi(o.createRoute({tags:["forms"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Vr}},description:"A form"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.forms.get(e,n);if(!r)throw new S(404);return t.json(r)}).openapi(o.createRoute({tags:["forms"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.forms.remove(e,n))throw new S(404,{message:"Form not found"});return t.text("OK")}).openapi(o.createRoute({tags:["forms"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Bs.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Vr}},description:"The updated form"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=t.req.valid("json");if(!await t.env.data.forms.update(e,n,r))throw new S(404,{message:"Form not found"});const s=await t.env.data.forms.get(e,n);if(!s)throw new S(404,{message:"Form not found"});return t.json(s)}).openapi(o.createRoute({tags:["forms"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Bs.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Vr}},description:"A form"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.forms.create(e,n);return t.json(r,{status:201})}),z4=St.extend({roles:o.z.array(lr)}),A4=new o.OpenAPIHono().openapi(o.createRoute({tags:["roles"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(lr),z4])}},description:"List of roles"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),a=await t.env.data.roles.list(t.var.tenant_id,{page:e,per_page:n,include_totals:r,sort:ft(i),q:s});return r?t.json(a):t.json(a.roles)}).openapi(o.createRoute({tags:["roles"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:lr}},description:"A role"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.roles.get(t.var.tenant_id,e);if(!n)throw new S(404);return t.json(n)}).openapi(o.createRoute({tags:["roles"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:Ds}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:lr}},description:"Role created"}}}),async t=>{const e=t.req.valid("json"),n=await t.env.data.roles.create(t.var.tenant_id,e);return t.json(n,{status:201})}).openapi(o.createRoute({tags:["roles"],method:"patch",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:Ds.partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:lr}},description:"Updated role"}}}),async t=>{const{id:e}=t.req.valid("param"),n=t.req.valid("json");if(!await t.env.data.roles.update(t.var.tenant_id,e,n))throw new S(404);const i=await t.env.data.roles.get(t.var.tenant_id,e);return t.json(i)}).openapi(o.createRoute({tags:["roles"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.roles.remove(t.var.tenant_id,e))throw new S(404);return t.text("OK")}).openapi(o.createRoute({tags:["roles"],method:"get",path:"/{id}/permissions",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),query:Qe},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:rm}},description:"Role permissions"}}}),async t=>{const{id:e}=t.req.valid("param"),{page:n,per_page:r,sort:i,q:s}=t.req.valid("query");if(!await t.env.data.roles.get(t.var.tenant_id,e))throw new S(404,{message:"Role not found"});const c=await t.env.data.rolePermissions.list(t.var.tenant_id,e,{page:n,per_page:r,include_totals:!1,sort:ft(i),q:s});return t.json(c)}).openapi(o.createRoute({tags:["roles"],method:"post",path:"/{id}/permissions",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({permissions:o.z.array(o.z.object({permission_name:o.z.string(),resource_server_identifier:o.z.string()}))})}}}},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Permissions assigned to role"}}}),async t=>{const{id:e}=t.req.valid("param"),{permissions:n}=t.req.valid("json");if(!await t.env.data.roles.get(t.var.tenant_id,e))throw new S(404,{message:"Role not found"});if(!await t.env.data.rolePermissions.assign(t.var.tenant_id,e,n.map(s=>({role_id:e,resource_server_identifier:s.resource_server_identifier,permission_name:s.permission_name}))))throw new S(500,{message:"Failed to assign permissions to role"});return t.json({message:"Permissions assigned successfully"},{status:201})}).openapi(o.createRoute({tags:["roles"],method:"delete",path:"/{id}/permissions",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({permissions:o.z.array(o.z.object({permission_name:o.z.string(),resource_server_identifier:o.z.string()}))})}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Permissions removed from role"}}}),async t=>{const{id:e}=t.req.valid("param"),{permissions:n}=t.req.valid("json");if(!await t.env.data.roles.get(t.var.tenant_id,e))throw new S(404,{message:"Role not found"});if(!await t.env.data.rolePermissions.remove(t.var.tenant_id,e,n))throw new S(500,{message:"Failed to remove permissions from role"});return t.json({message:"Permissions removed successfully"})}),E4=St.extend({resource_servers:o.z.array(cr)}),C4=new o.OpenAPIHono().openapi(o.createRoute({tags:["resource-servers"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(cr),E4])}},description:"List of resource servers"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{page:n,per_page:r,include_totals:i=!1,sort:s,q:a}=t.req.valid("query"),c=await t.env.data.resourceServers.list(e,{page:n,per_page:r,include_totals:i,sort:ft(s),q:a});return i?t.json(c):t.json(c.resource_servers)}).openapi(o.createRoute({tags:["resource-servers"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:cr}},description:"A resource server"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.resourceServers.get(e,n);if(!r)throw new S(404);return t.json(r)}).openapi(o.createRoute({tags:["resource-servers"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.resourceServers.remove(e,n))throw new S(404,{message:"Resource server not found"});return t.text("OK")}).openapi(o.createRoute({tags:["resource-servers"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Us.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:cr}},description:"The updated resource server"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=t.req.valid("json");if(!await t.env.data.resourceServers.update(e,n,r))throw new S(404,{message:"Resource server not found"});const s=await t.env.data.resourceServers.get(e,n);if(!s)throw new S(404,{message:"Resource server not found"});return t.json(s)}).openapi(o.createRoute({tags:["resource-servers"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Us.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:cr}},description:"A resource server"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.resourceServers.create(e,n);return t.json(r,{status:201})}),N4=o.z.object({per_page:o.z.string().min(1).optional().default("50").transform(t=>parseInt(t,10)).openapi({description:"Number of results per page. Defaults to 50."}),page:o.z.string().min(0).optional().default("0").transform(t=>parseInt(t,10)).openapi({description:"Page index of the results to return. First page is 0."}),include_totals:o.z.string().optional().default("false").transform(t=>t==="true").openapi({description:"Return results inside an object that contains the total result count (true) or as a direct array of results (false, default)."}),from:o.z.string().optional().openapi({description:"Optional Id from which to start selection."}),take:o.z.string().min(1).optional().transform(t=>t?parseInt(t,10):void 0).openapi({description:"Number of results per page. Defaults to 50."}),audience:o.z.string().optional().openapi({description:"Optional filter on audience."}),client_id:o.z.string().optional().openapi({description:"Optional filter on client_id."}),allow_any_organization:o.z.string().optional().transform(t=>t==="true"?!0:t==="false"?!1:void 0).openapi({description:"Optional filter on allow_any_organization."}),subject_type:o.z.enum(["client","user"]).optional().openapi({description:"EA The type of application access the client grant allows. Use of this field is subject to the applicable Free Trial terms in Okta's Master Subscription Agreement."})}),I4=St.extend({client_grants:o.z.array(ar)}),j4=new o.OpenAPIHono().openapi(o.createRoute({tags:["client-grants"],method:"get",path:"/",request:{query:N4,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(ar),I4])}},description:"List of client grants"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{page:n,per_page:r,include_totals:i=!1,from:s,take:a,audience:c,client_id:l,allow_any_organization:d,subject_type:u}=t.req.valid("query"),f=[];l&&f.push(`client_id:"${l}"`),c&&f.push(`audience:"${c}"`),d!==void 0&&f.push(`allow_any_organization:${d}`),u&&f.push(`subject_type:"${u}"`),s&&f.push(`id:>${s}`);const h=f.length>0?f.join(" AND "):void 0,m=a??r,y=await t.env.data.clientGrants.list(e,{page:n,per_page:m,include_totals:i,q:h});return i?t.json(y):t.json(y.client_grants)}).openapi(o.createRoute({tags:["client-grants"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:ar}},description:"A client grant"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.clientGrants.get(e,n);if(!r)throw new S(404,{message:"Client grant not found"});return t.json(r)}).openapi(o.createRoute({tags:["client-grants"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.clientGrants.remove(e,n))throw new S(404,{message:"Client grant not found"});return t.text("OK")}).openapi(o.createRoute({tags:["client-grants"],method:"patch",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),body:{content:{"application/json":{schema:o.z.object(Ps.shape).partial()}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:ar}},description:"The updated client grant"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=t.req.valid("json");if(!await t.env.data.clientGrants.get(e,n))throw new S(404,{message:"Client grant not found"});if(!await t.env.data.clientGrants.update(e,n,r))throw new S(500,{message:"Failed to update client grant"});const a=await t.env.data.clientGrants.get(e,n);if(!a)throw new S(404,{message:"Client grant not found"});return t.json(a)}).openapi(o.createRoute({tags:["client-grants"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Ps.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:ar}},description:"A client grant"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.clientGrants.create(e,n);return t.json(r,{status:201})}),O4=o.z.object({page:o.z.string().optional().default("0").transform(t=>parseInt(t,10)).openapi({description:"Page index of the results to return. First page is 0."}),per_page:o.z.string().optional().default("50").transform(t=>parseInt(t,10)).openapi({description:"Number of results per page. Defaults to 50."}),include_totals:o.z.string().optional().default("false").transform(t=>t==="true").openapi({description:"When true, return results inside an object that also contains the start and limit. When false (default), a direct array of results is returned."}),fields:o.z.string().optional().openapi({description:"Comma-separated list of fields to include or exclude (based on value provided for include_fields) in the result. Leave empty to retrieve all fields."}),include_fields:o.z.string().optional().default("true").transform(t=>t==="true").openapi({description:"Whether specified fields are to be included (true) or excluded (false). Defaults to true."}),sort:o.z.string().optional().default("created_at:-1").openapi({description:"Field to sort by. Use field:order where order is 1 for ascending and -1 for descending. Defaults to created_at:-1."})}),T4=o.z.object({invitations:o.z.array(Gi),start:o.z.number(),limit:o.z.number(),length:o.z.number()}),P4=wu.omit({organization_id:!0,invitation_url:!0}),R4=St.extend({organizations:o.z.array(Dn)}),vp=o.z.object({user_id:o.z.string().openapi({description:"ID of this user"}),email:o.z.string().email().optional().openapi({description:"Email address of this user",format:"email"}),roles:o.z.array(o.z.object({})).default([]).openapi({description:"Array of roles assigned to this user in the organization"})}),B4=o.z.object({start:o.z.number().openapi({description:"Start index of the current page"}),limit:o.z.number().openapi({description:"Number of items per page"}),total:o.z.number().openapi({description:"Total number of members"}),members:o.z.array(vp).openapi({description:"Array of organization members"})}),L4=o.z.object({next:o.z.string().optional().openapi({description:"Checkpoint ID to be used to retrieve the next set of results"}),members:o.z.array(vp).openapi({description:"Array of organization members"})}),U4=o.z.object({members:o.z.array(o.z.string()).openapi({description:"Array of user IDs to add to the organization"})}),D4=o.z.object({members:o.z.array(o.z.string()).openapi({description:"Array of user IDs to remove from the organization"})}),M4=new o.OpenAPIHono().openapi(o.createRoute({tags:["organizations"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([R4,o.z.array(Dn)])}},description:"List of organizations"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{page:n,per_page:r,include_totals:i,sort:s,q:a}=t.req.valid("query"),c=await t.env.data.organizations.list(e,{page:n,per_page:r,include_totals:i,sort:ft(s),q:a});return i?t.json(c):t.json(c.organizations)}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Dn}},description:"An organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.organizations.get(e,n);if(!r)throw new S(404,{message:"Organization not found"});return t.json(r)}).openapi(o.createRoute({tags:["organizations"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Organization deleted successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.organizations.remove(e,n))throw new S(404,{message:"Organization not found"});return t.text("OK")}).openapi(o.createRoute({tags:["organizations"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:Fs.partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Dn}},description:"The updated organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=t.req.valid("json");if(!await t.env.data.organizations.update(e,n,r))throw new S(404,{message:"Organization not found"});const s=await t.env.data.organizations.get(e,n);if(!s)throw new S(404,{message:"Organization not found"});return t.json(s)}).openapi(o.createRoute({tags:["organizations"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:Fs}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Dn}},description:"The created organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r={...n,id:n.id||C$()},i=await t.env.data.organizations.create(e,r);return t.json(i,{status:201})}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/members",request:{params:o.z.object({id:o.z.string()}),query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(vp),B4,L4])}},description:"List of organization members"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{page:r,per_page:i,include_totals:s,sort:a}=t.req.valid("query");if(!await t.env.data.organizations.get(e,n))throw new S(404,{message:"Organization not found"});const l=await t.env.data.userOrganizations.list(e,{page:r,per_page:i,include_totals:s,sort:ft(a),q:`organization_id:${n}`}),d=[];for(const u of l.userOrganizations){const f=await t.env.data.users.get(e,u.user_id);f&&d.push({user_id:f.user_id,email:f.email||void 0,roles:[]})}return s?t.json({start:l.start,limit:l.limit,total:l.length,members:d}):t.json(d)}).openapi(o.createRoute({tags:["organizations"],method:"post",path:"/{id}/members",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:U4}}}},security:[{Bearer:["auth:write"]}],responses:{204:{description:"Members added successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{members:r}=t.req.valid("json");if(!await t.env.data.organizations.get(e,n))throw new S(404,{message:"Organization not found"});for(const s of r)(await t.env.data.userOrganizations.list(e,{q:`user_id:${s}`,per_page:1})).userOrganizations.some(l=>l.organization_id===n)||await t.env.data.userOrganizations.create(e,{user_id:s,organization_id:n});return new Response(null,{status:204})}).openapi(o.createRoute({tags:["organizations"],method:"delete",path:"/{id}/members",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:D4}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Members removed successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{members:r}=t.req.valid("json");for(const i of r){const a=(await t.env.data.userOrganizations.list(e,{q:`user_id:${i}`,per_page:100})).userOrganizations.find(c=>c.organization_id===n);a&&await t.env.data.userOrganizations.remove(e,a.id)}return t.json({message:"Members removed successfully"})}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/members/{user_id}/roles",request:{params:o.z.object({id:o.z.string(),user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),query:Qe},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ms}},description:"User roles in organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n,user_id:r}=t.req.valid("param");if(!await t.env.data.organizations.get(e,n))throw new S(404,{message:"Organization not found"});if(!await t.env.data.users.get(e,r))throw new S(404,{message:"User not found"});const a=await t.env.data.userRoles.list(e,r,void 0,n);return t.json(a)}).openapi(o.createRoute({tags:["organizations"],method:"post",path:"/{id}/members/{user_id}/roles",request:{params:o.z.object({id:o.z.string(),user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({roles:o.z.array(o.z.string()).openapi({description:"List of role IDs to associate with the user"})})}}}},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Roles assigned successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n,user_id:r}=t.req.valid("param"),{roles:i}=t.req.valid("json");if(!await t.env.data.organizations.get(e,n))throw new S(404,{message:"Organization not found"});if(!await t.env.data.users.get(e,r))throw new S(404,{message:"User not found"});for(const c of i){if(!await t.env.data.roles.get(e,c))throw new S(400,{message:`Role ${c} not found`});if(!await t.env.data.userRoles.create(e,r,c,n))throw new S(500,{message:`Failed to assign role ${c} to user`})}return t.json({message:"Roles assigned successfully"},{status:201})}).openapi(o.createRoute({tags:["organizations"],method:"delete",path:"/{id}/members/{user_id}/roles",request:{params:o.z.object({id:o.z.string(),user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({roles:o.z.array(o.z.string()).openapi({description:"List of role IDs to remove from the user"})})}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Roles removed successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n,user_id:r}=t.req.valid("param"),{roles:i}=t.req.valid("json");if(!await t.env.data.organizations.get(e,n))throw new S(404,{message:"Organization not found"});if(!await t.env.data.users.get(e,r))throw new S(404,{message:"User not found"});for(const c of i)if(!await t.env.data.userRoles.remove(e,r,c,n))throw new S(500,{message:`Failed to remove role ${c} from user`});return t.json({message:"Roles removed successfully"})}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/roles",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),query:Qe},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ms}},description:"List of roles available in organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{page:r,per_page:i,sort:s,q:a}=t.req.valid("query");if(!await t.env.data.organizations.get(e,n))throw new S(404,{message:"Organization not found"});const l=await t.env.data.roles.list(e,{page:r,per_page:i,sort:ft(s),q:a});return t.json(l.roles)}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/invitations",request:{params:o.z.object({id:o.z.string().openapi({description:"Organization ID",param:{name:"id",in:"path"}})}),query:O4,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Gi),T4])}},description:"List of organization invitations"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{page:r,per_page:i,include_totals:s,fields:a,include_fields:c,sort:l}=t.req.valid("query");if(!await t.env.data.organizations.get(e,n))throw new S(404,{message:"Organization not found"});let f=(await t.env.data.invites.list(e,{page:r,per_page:i})).invites.filter(h=>h.organization_id===n);if(l){const h=ft(l);if(h){const{sort_by:m,sort_order:y}=h;f.sort((v,b)=>{const A=v[m],O=b[m];if(A===void 0||O===void 0||A===O)return 0;const U=A<O?-1:1;return y==="asc"?U:-U})}}if(a){const h=a.split(",").map(m=>m.trim());f=f.map(m=>{const y={};for(const v of Object.keys(m))(c?h.includes(v):!h.includes(v))&&(y[v]=m[v]);return y})}return s?t.json({invitations:f,start:r*i,limit:i,length:f.length}):t.json(f)}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/invitations/{invitation_id}",request:{params:o.z.object({id:o.z.string().openapi({description:"Organization ID",param:{name:"id",in:"path"}}),invitation_id:o.z.string().openapi({description:"Invitation ID",param:{name:"invitation_id",in:"path"}})}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Gi}},description:"An invitation"},404:{description:"Invitation not found"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n,invitation_id:r}=t.req.valid("param"),i=await t.env.data.invites.get(e,r);if(!i||i.organization_id!==n)throw new S(404,{message:"Invitation not found"});return t.json(i)}).openapi(o.createRoute({tags:["organizations"],method:"post",path:"/{id}/invitations",request:{params:o.z.object({id:o.z.string().openapi({description:"Organization ID",param:{name:"id",in:"path"}})}),body:{content:{"application/json":{schema:P4}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Gi}},description:"The created invitation"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=t.req.valid("json");if(!await t.env.data.organizations.get(e,n))throw new S(404,{message:"Organization not found"});const a=`https://invite.placeholder/${j$()}`,c={...r,organization_id:n,invitation_url:a},l=await t.env.data.invites.create(e,c);return t.json(l,{status:201})}).openapi(o.createRoute({tags:["organizations"],method:"delete",path:"/{id}/invitations/{invitation_id}",request:{params:o.z.object({id:o.z.string().openapi({description:"Organization ID",param:{name:"id",in:"path"}}),invitation_id:o.z.string().openapi({description:"Invitation ID",param:{name:"invitation_id",in:"path"}})}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{204:{description:"Invitation deleted successfully"},404:{description:"Invitation not found"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n,invitation_id:r}=t.req.valid("param"),i=await t.env.data.invites.get(e,r);if(!i||i.organization_id!==n)throw new S(404,{message:"Invitation not found"});if(!await t.env.data.invites.remove(e,r))throw new S(404,{message:"Invitation not found"});return t.body(null,{status:204})});function F4(t){const e=new o.OpenAPIHono;e.use(g0({origin:r=>{var i;return r&&(i=t.allowedOrigins)!=null&&i.includes(r)?r:""},allowHeaders:["Tenant-Id","Content-Type","Content-Range","Auth0-Client","Authorization","Range","Upgrade-Insecure-Requests"],allowMethods:["POST","PUT","GET","DELETE","PATCH","OPTIONS"],exposeHeaders:["Content-Length","Content-Range"],maxAge:600,credentials:!0})),yp(e),e.use(async(r,i)=>{const s=xo(r,t.dataAdapter),a=Ho({defaultTtlSeconds:0,maxEntries:100,cleanupIntervalMs:0}),c=Dc(s,{defaultTtl:0,cacheEntities:["tenants","connections","clients","legacyClients","branding","themes","promptSettings","forms"],cache:a});return r.env.data=Rc(r,c),i()}),e.use(Uc).use(Lc).use(wp(e));const n=e.route("/branding",nv).route("/custom-domains",w4).route("/email/providers",m4).route("/users",bb).route("/keys",w$).route("/users-by-email",v$).route("/clients",$$).route("/client-grants",j4).route("/tenants",x$).route("/logs",z$).route("/hooks",T$).route("/connections",R$).route("/prompts",B$).route("/sessions",_4).route("/refresh_tokens",y4).route("/forms",S4).route("/roles",A4).route("/resource-servers",C4).route("/organizations",M4);return n.doc("/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"Management API"},servers:[{url:"/api/v2",description:"API V2"}],security:[{oauth2:["openid","email","profile"]}]}),n}function q4(t,e){Object.keys(e).forEach(n=>{const r=e[n];r!=null&&r.length&&t.searchParams.set(n,r)})}function Nn(t){var e;if(t)return`${t.name}/${t.version}${(e=t.env)!=null&&e.node?` (env: node/${t.env.node})`:""}`}var H4=(t,...e)=>{const n=[""];for(let r=0,i=t.length-1;r<i;r++){n[0]+=t[r];const s=Array.isArray(e[r])?e[r].flat(1/0):[e[r]];for(let a=0,c=s.length;a<c;a++){const l=s[a];if(typeof l=="string")Kn(l,n);else if(typeof l=="number")n[0]+=l;else{if(typeof l=="boolean"||l===null||l===void 0)continue;if(typeof l=="object"&&l.isEscaped)if(l.callbacks)n.unshift("",l);else{const d=l.toString();d instanceof Promise?n.unshift("",d):n[0]+=d}else l instanceof Promise?n.unshift("",l):Kn(l.toString(),n)}}}return n[0]+=t.at(-1),n.length===1?"callbacks"in n?Zt(Dy(Zt(n[0],n.callbacks))):Zt(n[0]):Uy(n,n.callbacks)},bp=Symbol("RENDERER"),eu=Symbol("ERROR_HANDLER"),Le=Symbol("STASH"),My=Symbol("INTERNAL"),V4=Symbol("MEMO"),za=Symbol("PERMALINK"),Zh=t=>(t[My]=!0,t),Fy=t=>({value:e,children:n})=>{if(!n)return;const r={children:[{tag:Zh(()=>{t.push(e)}),props:{}}]};Array.isArray(n)?r.children.push(...n.flat()):r.children.push(n),r.children.push({tag:Zh(()=>{t.pop()}),props:{}});const i={tag:"",props:r,type:""};return i[eu]=s=>{throw t.pop(),s},i},qy=t=>{const e=[t],n=Fy(e);return n.values=e,n.Provider=n,gi.push(n),n},gi=[],Hy=t=>{const e=[t],n=r=>{e.push(r.value);let i;try{i=r.children?(Array.isArray(r.children)?new Wy("",{},r.children):r.children).toString():""}finally{e.pop()}return i instanceof Promise?i.then(s=>Zt(s,s.callbacks)):Zt(i)};return n.values=e,n.Provider=n,n[bp]=Fy(e),gi.push(n),n},ji=t=>t.values.at(-1),ws={title:[],script:["src"],style:["data-href"],link:["href"],meta:["name","httpEquiv","charset","itemProp"]},tu={},vs="data-precedence",Vo=t=>Array.isArray(t)?t:[t],Yh=new WeakMap,Qh=(t,e,n,r)=>({buffer:i,context:s})=>{if(!i)return;const a=Yh.get(s)||{};Yh.set(s,a);const c=a[t]||(a[t]=[]);let l=!1;const d=ws[t];if(d.length>0){e:for(const[,u]of c)for(const f of d)if(((u==null?void 0:u[f])??null)===(n==null?void 0:n[f])){l=!0;break e}}if(l?i[0]=i[0].replaceAll(e,""):d.length>0?c.push([e,n,r]):c.unshift([e,n,r]),i[0].indexOf("</head>")!==-1){let u;if(r===void 0)u=c.map(([f])=>f);else{const f=[];u=c.map(([h,,m])=>{let y=f.indexOf(m);return y===-1&&(f.push(m),y=f.length-1),[h,y]}).sort((h,m)=>h[1]-m[1]).map(([h])=>h)}u.forEach(f=>{i[0]=i[0].replaceAll(f,"")}),i[0]=i[0].replace(/(?=<\/head>)/,u.join(""))}},Ko=(t,e,n)=>Zt(new Yt(t,n,Vo(e??[])).toString()),Go=(t,e,n,r)=>{if("itemProp"in n)return Ko(t,e,n);let{precedence:i,blocking:s,...a}=n;i=r?i??"":void 0,r&&(a[vs]=i);const c=new Yt(t,a,Vo(e||[])).toString();return c instanceof Promise?c.then(l=>Zt(c,[...l.callbacks||[],Qh(t,l,a,i)])):Zt(c,[Qh(t,c,a,i)])},K4=({children:t,...e})=>{const n=$p();if(n){const r=ji(n);if(r==="svg"||r==="head")return new Yt("title",e,Vo(t??[]))}return Go("title",t,e,!1)},G4=({children:t,...e})=>{const n=$p();return["src","async"].some(r=>!e[r])||n&&ji(n)==="head"?Ko("script",t,e):Go("script",t,e,!1)},W4=({children:t,...e})=>["href","precedence"].every(n=>n in e)?(e["data-href"]=e.href,delete e.href,Go("style",t,e,!0)):Ko("style",t,e),J4=({children:t,...e})=>["onLoad","onError"].some(n=>n in e)||e.rel==="stylesheet"&&(!("precedence"in e)||"disabled"in e)?Ko("link",t,e):Go("link",t,e,"precedence"in e),X4=({children:t,...e})=>{const n=$p();return n&&ji(n)==="head"?Ko("meta",t,e):Go("meta",t,e,!1)},Vy=(t,{children:e,...n})=>new Yt(t,n,Vo(e??[])),Z4=t=>(typeof t.action=="function"&&(t.action=za in t.action?t.action[za]:void 0),Vy("form",t)),Ky=(t,e)=>(typeof e.formAction=="function"&&(e.formAction=za in e.formAction?e.formAction[za]:void 0),Vy(t,e)),Y4=t=>Ky("input",t),Q4=t=>Ky("button",t);const dl=Object.freeze(Object.defineProperty({__proto__:null,button:Q4,form:Z4,input:Y4,link:J4,meta:X4,script:G4,style:W4,title:K4},Symbol.toStringTag,{value:"Module"}));var ek=new Map([["className","class"],["htmlFor","for"],["crossOrigin","crossorigin"],["httpEquiv","http-equiv"],["itemProp","itemprop"],["fetchPriority","fetchpriority"],["noModule","nomodule"],["formAction","formaction"]]),Aa=t=>ek.get(t)||t,Gy=(t,e)=>{for(const[n,r]of Object.entries(t)){const i=n[0]==="-"||!/[A-Z]/.test(n)?n:n.replace(/[A-Z]/g,s=>`-${s.toLowerCase()}`);e(i,r==null?null:typeof r=="number"?i.match(/^(?:a|border-im|column(?:-c|s)|flex(?:$|-[^b])|grid-(?:ar|[^a])|font-w|li|or|sca|st|ta|wido|z)|ty$/)?`${r}`:`${r}px`:r)}},yo=void 0,$p=()=>yo,tk=t=>/[A-Z]/.test(t)&&t.match(/^(?:al|basel|clip(?:Path|Rule)$|co|do|fill|fl|fo|gl|let|lig|i|marker[EMS]|o|pai|pointe|sh|st[or]|text[^L]|tr|u|ve|w)/)?t.replace(/([A-Z])/g,"-$1").toLowerCase():t,nk=["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],rk=["allowfullscreen","async","autofocus","autoplay","checked","controls","default","defer","disabled","download","formnovalidate","hidden","inert","ismap","itemscope","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","selected"],kp=(t,e)=>{for(let n=0,r=t.length;n<r;n++){const i=t[n];if(typeof i=="string")Kn(i,e);else{if(typeof i=="boolean"||i===null||i===void 0)continue;i instanceof Yt?i.toStringToBuffer(e):typeof i=="number"||i.isEscaped?e[0]+=i:i instanceof Promise?e.unshift("",i):kp(i,e)}}},Yt=class{constructor(t,e,n){ae(this,"tag");ae(this,"props");ae(this,"key");ae(this,"children");ae(this,"isEscaped",!0);ae(this,"localContexts");this.tag=t,this.props=e,this.children=n}get type(){return this.tag}get ref(){return this.props.ref||null}toString(){var e,n;const t=[""];(e=this.localContexts)==null||e.forEach(([r,i])=>{r.values.push(i)});try{this.toStringToBuffer(t)}finally{(n=this.localContexts)==null||n.forEach(([r])=>{r.values.pop()})}return t.length===1?"callbacks"in t?Dy(Zt(t[0],t.callbacks)).toString():t[0]:Uy(t,t.callbacks)}toStringToBuffer(t){const e=this.tag,n=this.props;let{children:r}=this;t[0]+=`<${e}`;const i=yo&&ji(yo)==="svg"?s=>tk(Aa(s)):s=>Aa(s);for(let[s,a]of Object.entries(n))if(s=i(s),s!=="children"){if(s==="style"&&typeof a=="object"){let c="";Gy(a,(l,d)=>{d!=null&&(c+=`${c?";":""}${l}:${d}`)}),t[0]+=' style="',Kn(c,t),t[0]+='"'}else if(typeof a=="string")t[0]+=` ${s}="`,Kn(a,t),t[0]+='"';else if(a!=null)if(typeof a=="number"||a.isEscaped)t[0]+=` ${s}="${a}"`;else if(typeof a=="boolean"&&rk.includes(s))a&&(t[0]+=` ${s}=""`);else if(s==="dangerouslySetInnerHTML"){if(r.length>0)throw new Error("Can only set one of `children` or `props.dangerouslySetInnerHTML`.");r=[Zt(a.__html)]}else if(a instanceof Promise)t[0]+=` ${s}="`,t.unshift('"',a);else if(typeof a=="function"){if(!s.startsWith("on")&&s!=="ref")throw new Error(`Invalid prop '${s}' of type 'function' supplied to '${e}'.`)}else t[0]+=` ${s}="`,Kn(a.toString(),t),t[0]+='"'}if(nk.includes(e)&&r.length===0){t[0]+="/>";return}t[0]+=">",kp(r,t),t[0]+=`</${e}>`}},ul=class extends Yt{toStringToBuffer(t){const{children:e}=this,n=this.tag.call(null,{...this.props,children:e.length<=1?e[0]:e});if(!(typeof n=="boolean"||n==null))if(n instanceof Promise)if(gi.length===0)t.unshift("",n);else{const r=gi.map(i=>[i,i.values.at(-1)]);t.unshift("",n.then(i=>(i instanceof Yt&&(i.localContexts=r),i)))}else n instanceof Yt?n.toStringToBuffer(t):typeof n=="number"||n.isEscaped?(t[0]+=n,n.callbacks&&(t.callbacks||(t.callbacks=[]),t.callbacks.push(...n.callbacks))):Kn(n,t)}},Wy=class extends Yt{toStringToBuffer(t){kp(this.children,t)}},ik=(t,e,...n)=>{e??(e={}),n.length&&(e.children=n.length===1?n[0]:n);const r=e.key;delete e.key;const i=bs(t,e,n);return i.key=r,i},eg=!1,bs=(t,e,n)=>{if(!eg){for(const r in tu)dl[r][bp]=tu[r];eg=!0}return typeof t=="function"?new ul(t,e,n):dl[t]?new ul(dl[t],e,n):t==="svg"||t==="head"?(yo||(yo=Hy("")),new Yt(t,e,[new ul(yo,{value:t},n)])):new Yt(t,e,n)},Mc=({children:t})=>new Wy("",{children:t},Array.isArray(t)?t:t?[t]:[]),ok=(t,e,...n)=>{let r;if(n.length>0)r=n;else{const i=t.props.children;r=Array.isArray(i)?i:[i]}return ik(t.tag,{...t.props,...e},...r)};function p(t,e,n){let r;if(!e||!("children"in e))r=bs(t,e,[]);else{const i=e.children;r=Array.isArray(i)?bs(t,e,i):bs(t,e,[i])}return r.key=n,r}var tg;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(tg||(tg={}));var ng;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(ng||(ng={}));function sk(t){return Xy(t,ak,wo.Include)}function Jy(t){return Xy(t,ck,wo.None)}function Xy(t,e,n){let r="";for(let i=0;i<t.byteLength;i+=3){let s=0,a=0;for(let c=0;c<3&&i+c<t.byteLength;c++)s=s<<8|t[i+c],a+=8;for(let c=0;c<4;c++)a>=6?(r+=e[s>>a-6&63],a-=6):a>0?(r+=e[s<<6-a&63],a=0):n===wo.Include&&(r+="=")}return r}const ak="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",ck="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";var wo;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(wo||(wo={}));var rg;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(rg||(rg={}));class lk{uint8(e,n){if(e.byteLength<n+1)throw new TypeError("Insufficient bytes");return e[n]}uint16(e,n){if(e.byteLength<n+2)throw new TypeError("Insufficient bytes");return e[n]<<8|e[n+1]}uint32(e,n){if(e.byteLength<n+4)throw new TypeError("Insufficient bytes");let r=0;for(let i=0;i<4;i++)r|=e[n+i]<<24-i*8;return r}uint64(e,n){if(e.byteLength<n+8)throw new TypeError("Insufficient bytes");let r=0n;for(let i=0;i<8;i++)r|=BigInt(e[n+i])<<BigInt(56-i*8);return r}putUint8(e,n,r){if(e.length<r+1)throw new TypeError("Not enough space");if(n<0||n>255)throw new TypeError("Invalid uint8 value");e[r]=n}putUint16(e,n,r){if(e.length<r+2)throw new TypeError("Not enough space");if(n<0||n>65535)throw new TypeError("Invalid uint16 value");e[r]=n>>8,e[r+1]=n&255}putUint32(e,n,r){if(e.length<r+4)throw new TypeError("Not enough space");if(n<0||n>4294967295)throw new TypeError("Invalid uint32 value");for(let i=0;i<4;i++)e[r+i]=n>>(3-i)*8&255}putUint64(e,n,r){if(e.length<r+8)throw new TypeError("Not enough space");if(n<0||n>18446744073709551615n)throw new TypeError("Invalid uint64 value");for(let i=0;i<8;i++)e[r+i]=Number(n>>BigInt((7-i)*8)&0xffn)}}const ig=new lk;function an(t,e){return(t<<32-e|t>>>e)>>>0}function dk(t){const e=new uk;return e.update(t),e.digest()}class uk{constructor(){ae(this,"blockSize",64);ae(this,"size",32);ae(this,"blocks",new Uint8Array(64));ae(this,"currentBlockSize",0);ae(this,"H",new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]));ae(this,"l",0n);ae(this,"w",new Uint32Array(64))}update(e){if(this.l+=BigInt(e.byteLength)*8n,this.currentBlockSize+e.byteLength<64){this.blocks.set(e,this.currentBlockSize),this.currentBlockSize+=e.byteLength;return}let n=0;if(this.currentBlockSize>0){const r=e.slice(0,64-this.currentBlockSize);this.blocks.set(r,this.currentBlockSize),this.process(),n+=r.byteLength,this.currentBlockSize=0}for(;n+64<=e.byteLength;){const r=e.slice(n,n+64);this.blocks.set(r),this.process(),n+=64}if(e.byteLength-n>0){const r=e.slice(n);this.blocks.set(r),this.currentBlockSize=r.byteLength}}digest(){this.blocks[this.currentBlockSize]=128,this.currentBlockSize+=1,64-this.currentBlockSize<8&&(this.blocks.fill(0,this.currentBlockSize),this.process(),this.currentBlockSize=0),this.blocks.fill(0,this.currentBlockSize),ig.putUint64(this.blocks,this.l,this.blockSize-8),this.process();const e=new Uint8Array(32);for(let n=0;n<8;n++)ig.putUint32(e,this.H[n],n*4);return e}process(){for(let d=0;d<16;d++)this.w[d]=(this.blocks[d*4]<<24|this.blocks[d*4+1]<<16|this.blocks[d*4+2]<<8|this.blocks[d*4+3])>>>0;for(let d=16;d<64;d++){const u=(an(this.w[d-2],17)^an(this.w[d-2],19)^this.w[d-2]>>>10)>>>0,f=(an(this.w[d-15],7)^an(this.w[d-15],18)^this.w[d-15]>>>3)>>>0;this.w[d]=u+this.w[d-7]+f+this.w[d-16]|0}let e=this.H[0],n=this.H[1],r=this.H[2],i=this.H[3],s=this.H[4],a=this.H[5],c=this.H[6],l=this.H[7];for(let d=0;d<64;d++){const u=(an(s,6)^an(s,11)^an(s,25))>>>0,f=(s&a^~s&c)>>>0,h=l+u+f+pk[d]+this.w[d]|0,m=(an(e,2)^an(e,13)^an(e,22))>>>0,y=(e&n^e&r^n&r)>>>0,v=m+y|0;l=c,c=a,a=s,s=i+h|0,i=r,r=n,n=e,e=h+v|0}this.H[0]=e+this.H[0]|0,this.H[1]=n+this.H[1]|0,this.H[2]=r+this.H[2]|0,this.H[3]=i+this.H[3]|0,this.H[4]=s+this.H[4]|0,this.H[5]=a+this.H[5]|0,this.H[6]=c+this.H[6]|0,this.H[7]=l+this.H[7]|0}}const pk=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);new BigUint64Array([0x428a2f98d728ae22n,0x7137449123ef65cdn,0xb5c0fbcfec4d3b2fn,0xe9b5dba58189dbbcn,0x3956c25bf348b538n,0x59f111f1b605d019n,0x923f82a4af194f9bn,0xab1c5ed5da6d8118n,0xd807aa98a3030242n,0x12835b0145706fben,0x243185be4ee4b28cn,0x550c7dc3d5ffb4e2n,0x72be5d74f27b896fn,0x80deb1fe3b1696b1n,0x9bdc06a725c71235n,0xc19bf174cf692694n,0xe49b69c19ef14ad2n,0xefbe4786384f25e3n,0x0fc19dc68b8cd5b5n,0x240ca1cc77ac9c65n,0x2de92c6f592b0275n,0x4a7484aa6ea6e483n,0x5cb0a9dcbd41fbd4n,0x76f988da831153b5n,0x983e5152ee66dfabn,0xa831c66d2db43210n,0xb00327c898fb213fn,0xbf597fc7beef0ee4n,0xc6e00bf33da88fc2n,0xd5a79147930aa725n,0x06ca6351e003826fn,0x142929670a0e6e70n,0x27b70a8546d22ffcn,0x2e1b21385c26c926n,0x4d2c6dfc5ac42aedn,0x53380d139d95b3dfn,0x650a73548baf63den,0x766a0abb3c77b2a8n,0x81c2c92e47edaee6n,0x92722c851482353bn,0xa2bfe8a14cf10364n,0xa81a664bbc423001n,0xc24b8b70d0f89791n,0xc76c51a30654be30n,0xd192e819d6ef5218n,0xd69906245565a910n,0xf40e35855771202an,0x106aa07032bbd1b8n,0x19a4c116b8d2d0c8n,0x1e376c085141ab53n,0x2748774cdf8eeb99n,0x34b0bcb5e19b48a8n,0x391c0cb3c5c95a63n,0x4ed8aa4ae3418acbn,0x5b9cca4f7763e373n,0x682e6ff3d6b2b8a3n,0x748f82ee5defb2fcn,0x78a5636f43172f60n,0x84c87814a1f0ab72n,0x8cc702081a6439ecn,0x90befffa23631e28n,0xa4506cebde82bde9n,0xbef9a3f7b2c67915n,0xc67178f2e372532bn,0xca273eceea26619cn,0xd186b8c721c0c207n,0xeada7dd6cde0eb1en,0xf57d4f7fee6ed178n,0x06f067aa72176fban,0x0a637dc5a2c898a6n,0x113f9804bef90daen,0x1b710b35131c471bn,0x28db77f523047d84n,0x32caab7b40c72493n,0x3c9ebe0a15c9bebcn,0x431d67c49c100d4cn,0x4cc5d4becb3e42b6n,0x597f299cfc657e2an,0x5fcb6fab3ad6faecn,0x6c44198c4a475817n]);class Zy{constructor(e){ae(this,"data");this.data=e}tokenType(){if("token_type"in this.data&&typeof this.data.token_type=="string")return this.data.token_type;throw new Error("Missing or invalid 'token_type' field")}accessToken(){if("access_token"in this.data&&typeof this.data.access_token=="string")return this.data.access_token;throw new Error("Missing or invalid 'access_token' field")}accessTokenExpiresInSeconds(){if("expires_in"in this.data&&typeof this.data.expires_in=="number")return this.data.expires_in;throw new Error("Missing or invalid 'expires_in' field")}accessTokenExpiresAt(){return new Date(Date.now()+this.accessTokenExpiresInSeconds()*1e3)}hasRefreshToken(){return"refresh_token"in this.data&&typeof this.data.refresh_token=="string"}refreshToken(){if("refresh_token"in this.data&&typeof this.data.refresh_token=="string")return this.data.refresh_token;throw new Error("Missing or invalid 'refresh_token' field")}hasScopes(){return"scope"in this.data&&typeof this.data.scope=="string"}scopes(){if("scope"in this.data&&typeof this.data.scope=="string")return this.data.scope.split(" ");throw new Error("Missing or invalid 'scope' field")}idToken(){if("id_token"in this.data&&typeof this.data.id_token=="string")return this.data.id_token;throw new Error("Missing or invalid field 'id_token'")}}function fk(t){const e=dk(new TextEncoder().encode(t));return Jy(e)}function Yy(){const t=new Uint8Array(32);return crypto.getRandomValues(t),Jy(t)}function hk(t,e){if(e.length!==1)throw new TypeError("Invalid character string");let n=0;for(;n<t.length&&t[n]===e;)n++;return t.slice(n)}function og(t,e){if(e.length!==1)throw new TypeError("Invalid character string");let n=t.length;for(;n>0&&t[n-1]===e;)n--;return t.slice(0,n)}function sg(t,...e){let n=og(t,"/");for(const r of e)n=og(n,"/")+"/"+hk(r,"/");return n}function mr(t,e){const n=new TextEncoder().encode(e.toString()),r=new Request(t,{method:"POST",body:n});return r.headers.set("Content-Type","application/x-www-form-urlencoded"),r.headers.set("Accept","application/json"),r.headers.set("User-Agent","arctic"),r.headers.set("Content-Length",n.byteLength.toString()),r}function eo(t,e){const n=new TextEncoder().encode(`${t}:${e}`);return sk(n)}async function Ea(t){let e;try{e=await fetch(t)}catch(n){throw new Sp(n)}if(e.status===400||e.status===401){let n;try{n=await e.json()}catch{throw new Yr(e.status)}if(typeof n!="object"||n===null)throw new Gn(e.status,n);let r;try{r=xp(n)}catch{throw new Gn(e.status,n)}throw r}if(e.status===200){let n;try{n=await e.json()}catch{throw new Yr(e.status)}if(typeof n!="object"||n===null)throw new Gn(e.status,n);return new Zy(n)}throw e.body!==null&&await e.body.cancel(),new Yr(e.status)}async function gk(t){let e;try{e=await fetch(t)}catch(n){throw new Sp(n)}if(e.status===400||e.status===401){let n;try{n=await e.json()}catch{throw new Gn(e.status,null)}if(typeof n!="object"||n===null)throw new Gn(e.status,n);let r;try{r=xp(n)}catch{throw new Gn(e.status,n)}throw r}if(e.status===200){e.body!==null&&await e.body.cancel();return}throw e.body!==null&&await e.body.cancel(),new Yr(e.status)}function xp(t){let e;if("error"in t&&typeof t.error=="string")e=t.error;else throw new Error("Invalid error response");let n=null,r=null,i=null;if("error_description"in t){if(typeof t.error_description!="string")throw new Error("Invalid data");n=t.error_description}if("error_uri"in t){if(typeof t.error_uri!="string")throw new Error("Invalid data");r=t.error_uri}if("state"in t){if(typeof t.state!="string")throw new Error("Invalid data");i=t.state}return new mk(e,n,r,i)}class Sp extends Error{constructor(e){super("Failed to send request",{cause:e})}}class mk extends Error{constructor(n,r,i,s){super(`OAuth request error: ${n}`);ae(this,"code");ae(this,"description");ae(this,"uri");ae(this,"state");this.code=n,this.description=r,this.uri=i,this.state=s}}class Yr extends Error{constructor(n){super("Unexpected error response");ae(this,"status");this.status=n}}class Gn extends Error{constructor(n,r){super("Unexpected error response body");ae(this,"status");ae(this,"data");this.status=n,this.data=r}}class Fc{constructor(e,n,r){ae(this,"clientId");ae(this,"clientPassword");ae(this,"redirectURI");this.clientId=e,this.clientPassword=n,this.redirectURI=r}createAuthorizationURL(e,n,r){const i=new URL(e);return i.searchParams.set("response_type","code"),i.searchParams.set("client_id",this.clientId),this.redirectURI!==null&&i.searchParams.set("redirect_uri",this.redirectURI),i.searchParams.set("state",n),r.length>0&&i.searchParams.set("scope",r.join(" ")),i}createAuthorizationURLWithPKCE(e,n,r,i,s){const a=new URL(e);if(a.searchParams.set("response_type","code"),a.searchParams.set("client_id",this.clientId),this.redirectURI!==null&&a.searchParams.set("redirect_uri",this.redirectURI),a.searchParams.set("state",n),r===mi.S256){const c=fk(i);a.searchParams.set("code_challenge_method","S256"),a.searchParams.set("code_challenge",c)}else r===mi.Plain&&(a.searchParams.set("code_challenge_method","plain"),a.searchParams.set("code_challenge",i));return s.length>0&&a.searchParams.set("scope",s.join(" ")),a}async validateAuthorizationCode(e,n,r){const i=new URLSearchParams;i.set("grant_type","authorization_code"),i.set("code",n),this.redirectURI!==null&&i.set("redirect_uri",this.redirectURI),r!==null&&i.set("code_verifier",r),this.clientPassword===null&&i.set("client_id",this.clientId);const s=mr(e,i);if(this.clientPassword!==null){const c=eo(this.clientId,this.clientPassword);s.headers.set("Authorization",`Basic ${c}`)}return await Ea(s)}async refreshAccessToken(e,n,r){const i=new URLSearchParams;i.set("grant_type","refresh_token"),i.set("refresh_token",n),this.clientPassword===null&&i.set("client_id",this.clientId),r.length>0&&i.set("scope",r.join(" "));const s=mr(e,i);if(this.clientPassword!==null){const c=eo(this.clientId,this.clientPassword);s.headers.set("Authorization",`Basic ${c}`)}return await Ea(s)}async revokeToken(e,n){const r=new URLSearchParams;r.set("token",n),this.clientPassword===null&&r.set("client_id",this.clientId);const i=mr(e,r);if(this.clientPassword!==null){const s=eo(this.clientId,this.clientPassword);i.headers.set("Authorization",`Basic ${s}`)}await gk(i)}}var mi;(function(t){t[t.S256=0]="S256",t[t.Plain=1]="Plain"})(mi||(mi={}));var ag;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(ag||(ag={}));var cg;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(cg||(cg={}));function to(t){return _k(t,yk,Ca.None)}function _k(t,e,n){let r="";for(let i=0;i<t.byteLength;i+=3){let s=0,a=0;for(let c=0;c<3&&i+c<t.byteLength;c++)s=s<<8|t[i+c],a+=8;for(let c=0;c<4;c++)a>=6?(r+=e[s>>a-6&63],a-=6):a>0?(r+=e[s<<6-a&63],a=0):n===Ca.Include&&(r+="=")}return r}const yk="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";var Ca;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(Ca||(Ca={}));var lg;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(lg||(lg={}));function wk(t,e,n){const r=to(new TextEncoder().encode(t)),i=to(new TextEncoder().encode(e)),s=to(n);return r+"."+i+"."+s}function vk(t,e){const n=to(new TextEncoder().encode(t)),r=to(new TextEncoder().encode(e)),i=n+"."+r;return new TextEncoder().encode(i)}const bk="https://appleid.apple.com/auth/authorize",$k="https://appleid.apple.com/auth/token";class Qy{constructor(e,n,r,i,s){ae(this,"clientId");ae(this,"teamId");ae(this,"keyId");ae(this,"pkcs8PrivateKey");ae(this,"redirectURI");this.clientId=e,this.teamId=n,this.keyId=r,this.pkcs8PrivateKey=i,this.redirectURI=s}createAuthorizationURL(e,n){const r=new URL(bk);return r.searchParams.set("response_type","code"),r.searchParams.set("client_id",this.clientId),r.searchParams.set("state",e),n.length>0&&r.searchParams.set("scope",n.join(" ")),r.searchParams.set("redirect_uri",this.redirectURI),r}async validateAuthorizationCode(e){const n=new URLSearchParams;n.set("grant_type","authorization_code"),n.set("code",e),n.set("redirect_uri",this.redirectURI),n.set("client_id",this.clientId);const r=await this.createClientSecret();n.set("client_secret",r);const i=mr($k,n);return await Ea(i)}async createClientSecret(){const e=await crypto.subtle.importKey("pkcs8",this.pkcs8PrivateKey,{name:"ECDSA",namedCurve:"P-256"},!1,["sign"]),n=Math.floor(Date.now()/1e3),r=JSON.stringify({typ:"JWT",alg:"ES256",kid:this.keyId}),i=JSON.stringify({iss:this.teamId,exp:n+5*60,aud:["https://appleid.apple.com"],sub:this.clientId,iat:n}),s=new Uint8Array(await crypto.subtle.sign({name:"ECDSA",hash:"SHA-256"},e,vk(r,i)));return wk(r,i,s)}}const kk="https://www.facebook.com/v16.0/dialog/oauth",xk="https://graph.facebook.com/v16.0/oauth/access_token";class e1{constructor(e,n,r){ae(this,"clientId");ae(this,"clientSecret");ae(this,"redirectURI");this.clientId=e,this.clientSecret=n,this.redirectURI=r}createAuthorizationURL(e,n){const r=new URL(kk);return r.searchParams.set("response_type","code"),r.searchParams.set("client_id",this.clientId),r.searchParams.set("state",e),n.length>0&&r.searchParams.set("scope",n.join(" ")),r.searchParams.set("redirect_uri",this.redirectURI),r}async validateAuthorizationCode(e){const n=new URLSearchParams;n.set("grant_type","authorization_code"),n.set("code",e),n.set("redirect_uri",this.redirectURI),n.set("client_id",this.clientId),n.set("client_secret",this.clientSecret);const r=mr(xk,n);return await Ea(r)}}const Sk="https://github.com/login/oauth/authorize",dg="https://github.com/login/oauth/access_token";class t1{constructor(e,n,r){ae(this,"clientId");ae(this,"clientSecret");ae(this,"redirectURI");this.clientId=e,this.clientSecret=n,this.redirectURI=r}createAuthorizationURL(e,n){const r=new URL(Sk);return r.searchParams.set("response_type","code"),r.searchParams.set("client_id",this.clientId),r.searchParams.set("state",e),n.length>0&&r.searchParams.set("scope",n.join(" ")),this.redirectURI!==null&&r.searchParams.set("redirect_uri",this.redirectURI),r}async validateAuthorizationCode(e){const n=new URLSearchParams;n.set("grant_type","authorization_code"),n.set("code",e),this.redirectURI!==null&&n.set("redirect_uri",this.redirectURI);const r=mr(dg,n),i=eo(this.clientId,this.clientSecret);return r.headers.set("Authorization",`Basic ${i}`),await ug(r)}async refreshAccessToken(e){const n=new URLSearchParams;n.set("grant_type","refresh_token"),n.set("refresh_token",e);const r=mr(dg,n),i=eo(this.clientId,this.clientSecret);return r.headers.set("Authorization",`Basic ${i}`),await ug(r)}}async function ug(t){let e;try{e=await fetch(t)}catch(i){throw new Sp(i)}if(e.status!==200)throw e.body!==null&&await e.body.cancel(),new Yr(e.status);let n;try{n=await e.json()}catch{throw new Yr(e.status)}if(typeof n!="object"||n===null)throw new Gn(e.status,n);if("error"in n&&typeof n.error=="string"){let i;try{i=xp(n)}catch{throw new Gn(e.status,n)}throw i}return new Zy(n)}const zk="https://accounts.google.com/o/oauth2/v2/auth",pg="https://oauth2.googleapis.com/token",Ak="https://oauth2.googleapis.com/revoke";let n1=class{constructor(e,n,r){ae(this,"client");this.client=new Fc(e,n,r)}createAuthorizationURL(e,n,r){return this.client.createAuthorizationURLWithPKCE(zk,e,mi.S256,n,r)}async validateAuthorizationCode(e,n){return await this.client.validateAuthorizationCode(pg,e,n)}async refreshAccessToken(e){return await this.client.refreshAccessToken(pg,e,[])}async revokeToken(e){await this.client.revokeToken(Ak,e)}};class r1{constructor(e,n,r,i){ae(this,"authorizationEndpoint");ae(this,"tokenEndpoint");ae(this,"client");this.authorizationEndpoint=sg("https://login.microsoftonline.com",e,"/oauth2/v2.0/authorize"),this.tokenEndpoint=sg("https://login.microsoftonline.com",e,"/oauth2/v2.0/token"),this.client=new Fc(n,r,i)}createAuthorizationURL(e,n,r){return this.client.createAuthorizationURLWithPKCE(this.authorizationEndpoint,e,mi.S256,n,r)}async validateAuthorizationCode(e,n){return await this.client.validateAuthorizationCode(this.tokenEndpoint,e,n)}async refreshAccessToken(e,n){return await this.client.refreshAccessToken(this.tokenEndpoint,e,n)}}const Wo=o.z.object({iss:o.z.string().url(),sub:o.z.string(),aud:o.z.string(),exp:o.z.number(),email:o.z.string().optional(),given_name:o.z.string().optional(),family_name:o.z.string().optional(),name:o.z.string().optional(),iat:o.z.number(),auth_time:o.z.number().optional(),nonce:o.z.string().optional(),acr:o.z.string().optional(),amr:o.z.array(o.z.string()).optional(),azp:o.z.string().optional(),at_hash:o.z.string().optional(),c_hash:o.z.string().optional()}).passthrough();Wo.omit({iat:!0,auth_time:!0,nonce:!0,acr:!0,amr:!0,azp:!0,at_hash:!0,c_hash:!0});const Ek="Apple",Ck=({className:t=""})=>p("svg",{width:"45",height:"45",viewBox:"0 0 45 45",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:t,children:[p("path",{d:"M45 0H0V45H45V0Z",fill:"white"}),p("path",{d:"M23.5344 10.3846C25.5313 10.3846 28.0344 9.01144 29.525 7.18055C30.875 5.5213 31.8594 3.20407 31.8594 0.886839C31.8594 0.572154 31.8313 0.25747 31.775 0C29.5531 0.0858233 26.8813 1.51621 25.2781 3.43293C24.0125 4.89193 22.8594 7.18055 22.8594 9.52638C22.8594 9.86968 22.9156 10.213 22.9438 10.3274C23.0844 10.356 23.3094 10.3846 23.5344 10.3846ZM16.5031 45C19.2313 45 20.4406 43.1405 23.8438 43.1405C27.3031 43.1405 28.0625 44.9428 31.1 44.9428C34.0813 44.9428 36.0781 42.1392 37.9625 39.3929C40.0719 36.246 40.9438 33.1564 41 33.0134C40.8031 32.9561 35.0938 30.5817 35.0938 23.9161C35.0938 18.1373 39.5938 15.534 39.8469 15.3338C36.8656 10.9854 32.3375 10.8709 31.1 10.8709C27.7531 10.8709 25.025 12.9307 23.3094 12.9307C21.4531 12.9307 19.0063 10.9854 16.1094 10.9854C10.5969 10.9854 5 15.6198 5 24.3738C5 29.8093 7.08125 35.5594 9.64063 39.2784C11.8344 42.4253 13.7469 45 16.5031 45Z",fill:"black"})]});function i1(t){const{options:e}=t;if(!e||!e.client_id||!e.team_id||!e.kid||!e.app_secret)throw new Error("Missing required Apple authentication parameters");const n=Buffer.from(e.app_secret,"utf-8"),r=n.toString().replace(/-----BEGIN PRIVATE KEY-----|-----END PRIVATE KEY-----|\s/g,""),i=Uint8Array.from(Buffer.from(r,"base64"));return n.fill(0),{options:e,keyArray:i}}async function Nk(t,e){var d,u;const{options:n,keyArray:r}=i1(e),i=`${He(t.env)}callback`,s=new Qy(n.client_id,n.team_id,n.kid,r,i),a=Ne(),c=await s.createAuthorizationURL(a,((d=n.scope)==null?void 0:d.split(" "))||["name","email"]);return(((u=n.scope)==null?void 0:u.split(" "))||["name","email"]).some(f=>["email","name"].includes(f))&&c.searchParams.set("response_mode","form_post"),{redirectUrl:c.href,code:a}}async function Ik(t,e,n){const{options:r,keyArray:i}=i1(e),a=await new Qy(r.client_id,r.team_id,r.kid,i,`${He(t.env)}callback`).validateAuthorizationCode(n),c=Ua(a.idToken());if(!c)throw new Error("Invalid ID token");const l=Wo.parse(c.payload);return{sub:l.sub,email:l.email,given_name:l.given_name,family_name:l.family_name,name:l.name,picture:l.picture,locale:l.locale}}const o1=Object.freeze(Object.defineProperty({__proto__:null,displayName:Ek,getRedirect:Nk,logo:Ck,validateAuthorizationCodeAndGetUser:Ik},Symbol.toStringTag,{value:"Module"})),jk="Facebook",Ok=({className:t=""})=>p("svg",{width:"45",height:"45",viewBox:"0 0 45 45",xmlns:"http://www.w3.org/2000/svg",className:t,children:[p("path",{d:"M45 22.5C45 10.0736 34.9264 0 22.5 0C10.0736 0 0 10.0736 0 22.5C0 33.7031 8.23242 42.9785 19.0039 44.6953V28.9746H13.2861V22.5H19.0039V17.5391C19.0039 11.8945 22.3828 8.75977 27.5391 8.75977C29.9658 8.75977 32.5049 9.19922 32.5049 9.19922V14.7656H29.7012C26.9414 14.7656 26.0156 16.4824 26.0156 18.2432V22.5H32.2412L31.2012 28.9746H26.0156V44.6953C36.7871 42.9785 45 33.7031 45 22.5Z",fill:"#1877F2"}),p("path",{d:"M31.2012 28.9746L32.2412 22.5H26.0156V18.2432C26.0156 16.4824 26.9414 14.7656 29.7012 14.7656H32.5049V9.19922C32.5049 9.19922 29.9658 8.75977 27.5391 8.75977C22.3828 8.75977 19.0039 11.8945 19.0039 17.5391V22.5H13.2861V28.9746H19.0039V44.6953C20.1562 44.8984 21.3203 45 22.5 45C23.6797 45 24.8438 44.8984 26.0156 44.6953V28.9746H31.2012Z",fill:"white"})]});async function Tk(t,e){var c;const{options:n}=e;if(!(n!=null&&n.client_id)||!n.client_secret)throw new Error("Missing required authentication parameters");const r=`${He(t.env)}callback`,i=new e1(n.client_id,n.client_secret,r),s=Ne();return{redirectUrl:i.createAuthorizationURL(s,((c=n.scope)==null?void 0:c.split(" "))||["email"]).href,code:s}}async function Pk(t,e,n){const{options:r}=e;if(!(r!=null&&r.client_id)||!r.client_secret)throw new Error("Missing required authentication parameters");const s=await new e1(r.client_id,r.client_secret,`${He(t.env)}callback`).validateAuthorizationCode(n),a=await fetch("https://graph.facebook.com/v22.0/me?fields=id,email,name",{headers:{Authorization:`Bearer ${s.accessToken()}`}});if(!a.ok)throw new Error("Failed to fetch user info");const c=await a.json();return t.set("log",`Userinfo: ${JSON.stringify(c)}`),{sub:c.id,email:c.email,name:c.name}}const s1=Object.freeze(Object.defineProperty({__proto__:null,displayName:jk,getRedirect:Tk,logo:Ok,validateAuthorizationCodeAndGetUser:Pk},Symbol.toStringTag,{value:"Module"})),Rk="Google",Bk=({className:t=""})=>p("svg",{width:"45",height:"45",viewBox:"0 0 45 45",xmlns:"http://www.w3.org/2000/svg",className:t,children:[p("path",{d:"M44.1035 23.0123C44.1054 21.4791 43.9758 19.9486 43.716 18.4375H22.498V27.1028H34.6507C34.4021 28.4868 33.8757 29.8061 33.1034 30.9812C32.3311 32.1562 31.3289 33.1628 30.1571 33.9401V39.5649H37.41C41.6567 35.6494 44.1035 29.859 44.1035 23.0123Z",fill:"#4285F4"}),p("path",{d:"M22.4982 44.9997C28.5698 44.9997 33.6821 43.0061 37.4101 39.5687L30.1573 33.9439C28.1386 35.3126 25.5387 36.0938 22.4982 36.0938C16.6296 36.0938 11.6485 32.1377 9.86736 26.8066H2.39575V32.6033C4.26839 36.3297 7.13989 39.4622 10.6896 41.6512C14.2394 43.8402 18.3277 44.9995 22.4982 44.9997Z",fill:"#34A853"}),p("path",{d:"M9.86737 26.8073C8.92572 24.0138 8.92572 20.9886 9.86737 18.1951V12.3984H2.39576C0.820432 15.5332 0 18.9929 0 22.5012C0 26.0095 0.820432 29.4692 2.39576 32.604L9.86737 26.8073Z",fill:"#FBBC04"}),p("path",{d:"M22.4982 8.90741C25.7068 8.85499 28.8071 10.0673 31.1291 12.2823L37.5507 5.86064C33.4788 2.03602 28.0843 -0.0637686 22.4982 0.00147616C18.3277 0.00166623 14.2394 1.16098 10.6896 3.34999C7.13989 5.539 4.26839 8.67155 2.39575 12.3979L9.86736 18.1946C11.6485 12.8635 16.6296 8.90741 22.4982 8.90741Z",fill:"#EA4335"})]});async function Lk(t,e){var l;const{options:n}=e;if(!(n!=null&&n.client_id)||!n.client_secret)throw new Error("Missing required Google authentication parameters");const r=`${He(t.env)}callback`,i=new n1(n.client_id,n.client_secret,r),s=Ne(),a=Yy();return{redirectUrl:i.createAuthorizationURL(s,a,((l=n.scope)==null?void 0:l.split(" "))??["email","profile"]).href,code:s,codeVerifier:a}}async function Uk(t,e,n,r){const{options:i}=e;if(!(i!=null&&i.client_id)||!i.client_secret||!r)throw new Error("Missing required authentication parameters");const a=await new n1(i.client_id,i.client_secret,`${He(t.env)}callback`).validateAuthorizationCode(n,r),c=Ua(a.idToken());if(!c)throw new Error("Invalid ID token");const l=Wo.parse(c.payload);return{sub:l.sub,email:l.email,given_name:l.given_name,family_name:l.family_name,name:l.name,picture:l.picture,locale:l.locale}}const a1=Object.freeze(Object.defineProperty({__proto__:null,displayName:Rk,getRedirect:Lk,logo:Bk,validateAuthorizationCodeAndGetUser:Uk},Symbol.toStringTag,{value:"Module"})),Dk="Vipps",Mk=({className:t=""})=>p("svg",{version:"1.1",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 48 48",width:"45",height:"45",className:t,children:[p("path",{fill:"#FF5B24",d:"M3.5,8h41c1.9,0,3.5,1.6,3.5,3.5v25c0,1.9-1.6,3.5-3.5,3.5h-41C1.6,40,0,38.4,0,36.5v-25C0,9.6,1.6,8,3.5,8z"}),p("path",{fillRule:"evenodd",clipRule:"evenodd",fill:"#FFFFFF",d:`M27.9,20.3c1.4,0,2.6-1,2.6-2.5h0c0-1.5-1.2-2.5-2.6-2.5c-1.4,0-2.6,1-2.6,2.5C25.3,19.2,26.5,20.3,27.9,20.3z
192
+ `,r}async function _$(t){const e=await t.publicKey.export(),n=await crypto.subtle.exportKey("jwk",e),r=JSON.stringify(n,Object.keys(n).sort()),s=new TextEncoder().encode(r);return El(await _m(s))}const y$=1e3*60*60*24,w$=new o.OpenAPIHono().openapi(o.createRoute({tags:["keys"],method:"get",path:"/signing",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.array(Sl)}},description:"List of keys"}}}),async t=>{const{signingKeys:e}=await t.env.data.keys.list({q:"type:jwt_signing"}),n=e.filter(r=>"cert"in r).map(r=>r);return t.json(n)}).openapi(o.createRoute({tags:["keys"],method:"get",path:"/signing/{kid}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({kid:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Sl}},description:"The requested key"}}}),async t=>{const{kid:e}=t.req.valid("param"),{signingKeys:n}=await t.env.data.keys.list({q:"type:jwt_signing"}),r=n.find(i=>i.kid===e);if(!r)throw new S(404,{message:"Key not found"});return t.json(r)}).openapi(o.createRoute({tags:["keys"],method:"post",path:"/signing/rotate",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Status"}}}),async t=>{const{signingKeys:e}=await t.env.data.keys.list({q:"type:jwt_signing"});for await(const r of e)await t.env.data.keys.update(r.kid,{revoked_at:new Date(Date.now()+y$).toISOString()});const n=await Xd({name:`CN=${t.env.ORGANIZATION_NAME}`});return await t.env.data.keys.create({...n,type:"jwt_signing"}),t.text("OK",{status:201})}).openapi(o.createRoute({tags:["keys"],method:"put",path:"/signing/{kid}/revoke",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({kid:o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Status"}}}),async t=>{const{kid:e}=t.req.valid("param");if(!await t.env.data.keys.update(e,{revoked_at:new Date().toISOString()}))throw new S(404,{message:"Key not found"});const r=await Xd({name:`CN=${t.env.ORGANIZATION_NAME}`});return await t.env.data.keys.create({...r,type:"jwt_signing"}),t.text("OK")}),v$=new o.OpenAPIHono().openapi(o.createRoute({tags:["users"],method:"get",path:"/",request:{query:o.z.object({email:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"tenant/json":{schema:o.z.array(gu)}},description:"List of users"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{email:n}=t.req.valid("query"),i=(await Eu(t.env.data.users,e,n)).filter(s=>!s.linked_to);return t.json(i)}),b$=St.extend({clients:o.z.array(sr)}),$$=new o.OpenAPIHono().openapi(o.createRoute({tags:["clients"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([b$,o.z.array(sr)])}},description:"List of clients"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{page:n,per_page:r,include_totals:i,sort:s,q:a}=t.req.valid("query"),l=(await t.env.data.clients.list(e,{page:n,per_page:r,include_totals:i,sort:ft(s),q:a})).clients;return i?t.json({clients:l,start:0,limit:10,length:l.length}):t.json(l)}).openapi(o.createRoute({tags:["clients"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:sr}},description:"A client"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.clients.get(e,n);if(!r)throw new S(404);return t.json(r)}).openapi(o.createRoute({tags:["clients"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.clients.remove(e,n))throw new S(404,{message:"Client not found"});return t.text("OK")}).openapi(o.createRoute({tags:["clients"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Ts.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:sr}},description:"The updated client"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),i=t.req.valid("json");await t.env.data.clients.update(e,n,i);const s=await t.env.data.clients.get(e,n);if(!s)throw new S(404,{message:"Client not found"});return t.json(s)}).openapi(o.createRoute({tags:["clients"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Ts.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:o.z.object(sr.shape)}},description:"A client"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r={...n,client_secret:n.client_secret||Ne()},i=await t.env.data.clients.create(e,r);return t.json(i,{status:201})});o.z.object({start:o.z.number(),limit:o.z.number(),length:o.z.number()});Oa.extend({email:o.z.string(),login_count:o.z.number(),multifactor:o.z.array(o.z.string()).optional(),last_ip:o.z.string().optional(),last_login:o.z.string().optional(),user_id:o.z.string()}).catchall(o.z.any());const k$=St.extend({tenants:o.z.array(Un)}),x$=new o.OpenAPIHono().openapi(o.createRoute({tags:["tenants","settings"],method:"get",path:"/settings",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Un}},description:"Current tenant settings"}}}),async t=>{const e=await t.env.data.tenants.get(t.var.tenant_id);if(!e)throw new S(404,{message:"Tenant not found"});return t.json(e)}).openapi(o.createRoute({tags:["tenants","settings"],method:"patch",path:"/settings",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object(Ki.shape).partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Un}},description:"Updated tenant settings"}}}),async t=>{const e=t.req.valid("json"),{id:n,...r}=e,i=await t.env.data.tenants.get(t.var.tenant_id);if(!i)throw new S(404,{message:"Tenant not found"});const s=zl(i,r);await t.env.data.tenants.update(t.var.tenant_id,s);const a=await t.env.data.tenants.get(t.var.tenant_id);if(!a)throw new S(500,{message:"Failed to retrieve updated tenant"});return t.json(a)}).openapi(o.createRoute({tags:["tenants"],method:"get",path:"/",request:{query:Qe},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"tenant/json":{schema:o.z.union([o.z.array(Un),k$])}},description:"List of tenants"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),a=await t.env.data.tenants.list({page:e,per_page:n,include_totals:r,sort:ft(i),q:s});return r?t.json(a):t.json(a.tenants)}).openapi(o.createRoute({tags:["tenants"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"tenant/json":{schema:Un}},description:"A tenant"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.tenants.get(e);if(!n)throw new S(404);return t.json(n)}).openapi(o.createRoute({tags:["tenants"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");return await t.env.data.tenants.remove(e),t.text("OK")}).openapi(o.createRoute({tags:["tenants"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Ki.shape).partial()}}},params:o.z.object({id:o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param"),n=t.req.valid("json");return await t.env.data.tenants.update(e,n),t.text("OK")}).openapi(o.createRoute({tags:["tenants"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Ki.shape)}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"tenant/json":{schema:Un}},description:"An tenant"}}}),async t=>{const e=t.req.valid("json"),n=await t.env.data.tenants.create(e);return t.json(n,{status:201})}),S$=St.extend({logs:o.z.array(Ls)}),z$=new o.OpenAPIHono().openapi(o.createRoute({tags:["logs"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Ls),S$])}},description:"List of log rows"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),a=await t.env.data.logs.list(t.var.tenant_id,{page:e,per_page:n,include_totals:r,sort:ft(i),q:s});return r?t.json(a):t.json(a.logs)}).openapi(o.createRoute({tags:["logs"],method:"get",path:"/{id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({id:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ls}},description:"A log entry"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.logs.get(t.var.tenant_id,e);if(!n)throw new S(404);return t.json(n)}),A$=17,E$={organization:"org_",connection:"con_",action:"act_",hook:"h_",rule:"rul_",resource_server:"api_",guardian_factor:"gfa_",invite:"inv_"};function Tc(t){const r=mm("0123456789abcdefghijklmnopqrstuvwxyz",A$)();return`${E$[t]}${r}`}function C$(){return Tc("organization")}function N$(){return Tc("connection")}function I$(){return Tc("hook")}function j$(){return Tc("invite")}const O$=St.extend({hooks:o.z.array(Kr)}),T$=new o.OpenAPIHono().openapi(o.createRoute({tags:["hooks"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Kr),O$])}},description:"List of hooks"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),a=await t.env.data.hooks.list(t.var.tenant_id,{page:e,per_page:n,include_totals:r,sort:ft(i),q:s});return r?t.json(a):t.json(a.hooks)}).openapi(o.createRoute({tags:["hooks"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:ds}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Kr}},description:"The created hook"}}}),async t=>{const e=t.req.valid("json"),n={...e,hook_id:e.hook_id||I$()},r=await t.env.data.hooks.create(t.var.tenant_id,n);return t.json(r,{status:201})}).openapi(o.createRoute({tags:["hooks"],method:"patch",path:"/{hook_id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({hook_id:o.z.string()}),body:{content:{"application/json":{schema:o.z.union([ds.options[0].omit({hook_id:!0}).partial(),ds.options[1].omit({hook_id:!0}).partial()])}}}},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Kr}},description:"The updated hook"},404:{description:"Hook not found"}}}),async t=>{const{hook_id:e}=t.req.valid("param"),n=t.req.valid("json");await t.env.data.hooks.update(t.var.tenant_id,e,n);const r=await t.env.data.hooks.get(t.var.tenant_id,e);if(!r)throw new S(404,{message:"Hook not found"});return t.json(r)}).openapi(o.createRoute({tags:["hooks"],method:"get",path:"/{hook_id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({hook_id:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Kr}},description:"A hook"},404:{description:"Hook not found"}}}),async t=>{const{hook_id:e}=t.req.valid("param"),n=await t.env.data.hooks.get(t.var.tenant_id,e);if(!n)throw new S(404,{message:"Hook not found"});return t.json(n)}).openapi(o.createRoute({tags:["hooks"],method:"delete",path:"/{hook_id}",request:{headers:o.z.object({"tenant-id":o.z.string()}),params:o.z.object({hook_id:o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{description:"A hook"}}}),async t=>{const{hook_id:e}=t.req.valid("param");if(!await t.env.data.hooks.remove(t.var.tenant_id,e))throw new S(404,{message:"Hook not found"});return t.text("OK")}),P$=St.extend({connections:o.z.array(Kt)}),R$=new o.OpenAPIHono().openapi(o.createRoute({tags:["connections"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Kt),P$])}},description:"List of connectionss"}}}),async t=>{const{page:e,per_page:n,include_totals:r=!1,sort:i,q:s}=t.req.valid("query"),a=await t.env.data.connections.list(t.var.tenant_id,{page:e,per_page:n,include_totals:r,sort:ft(i),q:s});return r?t.json(a):t.json(a.connections)}).openapi(o.createRoute({tags:["connections"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Kt}},description:"A connection"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.connections.get(t.var.tenant_id,e);if(!n)throw new S(404);return t.json(n)}).openapi(o.createRoute({tags:["connections"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.connections.remove(t.var.tenant_id,e))throw new S(404,{message:"Connection not found"});return t.text("OK")}).openapi(o.createRoute({tags:["connections"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Rs.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Kt}},description:"The updated connection"}}}),async t=>{const{id:e}=t.req.valid("param"),n=t.req.valid("json");if(!await t.env.data.connections.update(t.var.tenant_id,e,n))throw new S(404,{message:"Connection not found"});const i=await t.env.data.connections.get(t.var.tenant_id,e);if(!i)throw new S(404,{message:"Connection not found"});return t.json(i)}).openapi(o.createRoute({tags:["connections"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Rs.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Kt}},description:"A connection"}}}),async t=>{const e=t.req.valid("json"),n={...e,id:e.id||N$()},r=await t.env.data.connections.create(t.var.tenant_id,n);return t.json(r,{status:201})}),B$=new o.OpenAPIHono().openapi(o.createRoute({tags:["prompts"],method:"get",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:ps}},description:"Branding settings"}}}),async t=>{const e=await t.env.data.promptSettings.get(t.var.tenant_id);return e?t.json(e):t.json(ps.parse({}))}).openapi(o.createRoute({tags:["prompts"],method:"patch",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object(ps.shape).partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Prompts settings"}}}),async t=>{const e=t.req.valid("json"),n=await t.env.data.promptSettings.get(t.var.tenant_id);return Object.assign(n,e),await t.env.data.promptSettings.set(t.var.tenant_id,n),t.json(n)});let Wh=!1;function yp(t){t.use(async(e,n)=>(Wh||(t.openAPIRegistry.registerComponent("securitySchemes","Bearer",{type:"oauth2",scheme:"bearer",flows:{implicit:{authorizationUrl:`${e.env.AUTH_URL}/authorize`,scopes:{openid:"Basic user information",email:"User email",profile:"User profile information"}}}}),Wh=!0),await n()))}var L$=(t,e)=>{try{return e(t)}catch{return t.replace(/(?:%[0-9A-Fa-f]{2})+/g,n=>{try{return e(n)}catch{return n}})}},U$=decodeURIComponent,D$=/^[\w!#$%&'*.^`|~+-]+$/,M$=/^[ !#-:<-[\]-~]*$/,F$=(t,e)=>{if(t.indexOf(e)===-1)return{};const n=t.trim().split(";"),r={};for(let i of n){i=i.trim();const s=i.indexOf("=");if(s===-1)continue;const a=i.substring(0,s).trim();if(e!==a||!D$.test(a))continue;let c=i.substring(s+1).trim();if(c.startsWith('"')&&c.endsWith('"')&&(c=c.slice(1,-1)),M$.test(c)){r[a]=c.indexOf("%")!==-1?L$(c,U$):c;break}}return r},q$=(t,e,n={})=>{let r=`${t}=${e}`;if(t.startsWith("__Secure-")&&!n.secure)throw new Error("__Secure- Cookie must have Secure attributes");if(t.startsWith("__Host-")){if(!n.secure)throw new Error("__Host- Cookie must have Secure attributes");if(n.path!=="/")throw new Error('__Host- Cookie must have Path attributes with "/"');if(n.domain)throw new Error("__Host- Cookie must not have Domain attributes")}if(n&&typeof n.maxAge=="number"&&n.maxAge>=0){if(n.maxAge>3456e4)throw new Error("Cookies Max-Age SHOULD NOT be greater than 400 days (34560000 seconds) in duration.");r+=`; Max-Age=${n.maxAge|0}`}if(n.domain&&n.prefix!=="host"&&(r+=`; Domain=${n.domain}`),n.path&&(r+=`; Path=${n.path}`),n.expires){if(n.expires.getTime()-Date.now()>3456e7)throw new Error("Cookies Expires SHOULD NOT be greater than 400 days (34560000 seconds) in the future.");r+=`; Expires=${n.expires.toUTCString()}`}if(n.httpOnly&&(r+="; HttpOnly"),n.secure&&(r+="; Secure"),n.sameSite&&(r+=`; SameSite=${n.sameSite.charAt(0).toUpperCase()+n.sameSite.slice(1)}`),n.priority&&(r+=`; Priority=${n.priority.charAt(0).toUpperCase()+n.priority.slice(1)}`),n.partitioned){if(!n.secure)throw new Error("Partitioned Cookie must have Secure attributes");r+="; Partitioned"}return r},al=(t,e,n)=>(e=encodeURIComponent(e),q$(t,e,n)),H$=(t,e,n)=>{const r=t.req.raw.headers.get("Cookie");{if(!r)return;let i=e;return F$(r,i)[i]}},V$=(t,e,n)=>{let r;return(n==null?void 0:n.prefix)==="secure"?r=al("__Secure-"+t,e,{path:"/",...n,secure:!0}):(n==null?void 0:n.prefix)==="host"?r=al("__Host-"+t,e,{...n,path:"/",secure:!0,domain:void 0}):r=al(t,e,{path:"/",...n}),r},Jh=(t,e,n,r)=>{const i=V$(e,n,r);t.header("Set-Cookie",i,{append:!0})},Ey=t=>Ny(t.replace(/_|-/g,e=>({_:"/","-":"+"})[e]??e)),Cy=t=>K$(t).replace(/\/|\+/g,e=>({"/":"_","+":"-"})[e]??e),K$=t=>{let e="";const n=new Uint8Array(t);for(let r=0,i=n.length;r<i;r++)e+=String.fromCharCode(n[r]);return btoa(e)},Ny=t=>{const e=atob(t),n=new Uint8Array(new ArrayBuffer(e.length)),r=e.length/2;for(let i=0,s=e.length-1;i<=r;i++,s--)n[i]=e.charCodeAt(i),n[s]=e.charCodeAt(s);return n},Iy=(t=>(t.HS256="HS256",t.HS384="HS384",t.HS512="HS512",t.RS256="RS256",t.RS384="RS384",t.RS512="RS512",t.PS256="PS256",t.PS384="PS384",t.PS512="PS512",t.ES256="ES256",t.ES384="ES384",t.ES512="ES512",t.EdDSA="EdDSA",t))(Iy||{}),G$=class extends Error{constructor(t){super(`${t} is not an implemented algorithm`),this.name="JwtAlgorithmNotImplemented"}},Pc=class extends Error{constructor(t){super(`invalid JWT token: ${t}`),this.name="JwtTokenInvalid"}},W$=class extends Error{constructor(t){super(`token (${t}) is being used before it's valid`),this.name="JwtTokenNotBefore"}},J$=class extends Error{constructor(t){super(`token (${t}) expired`),this.name="JwtTokenExpired"}},X$=class extends Error{constructor(t,e){super(`Invalid "iat" claim, must be a valid number lower than "${t}" (iat: "${e}")`),this.name="JwtTokenIssuedAt"}},cl=class extends Error{constructor(t,e){super(`expected issuer "${t}", got ${e?`"${e}"`:"none"} `),this.name="JwtTokenIssuer"}},jy=class extends Error{constructor(t){super(`jwt header is invalid: ${JSON.stringify(t)}`),this.name="JwtHeaderInvalid"}},Z$=class extends Error{constructor(t){super(`required "kid" in jwt header: ${JSON.stringify(t)}`),this.name="JwtHeaderRequiresKid"}},Y$=class extends Error{constructor(t){super(`token(${t}) signature mismatched`),this.name="JwtTokenSignatureMismatched"}},_o=(t=>(t.Encrypt="encrypt",t.Decrypt="decrypt",t.Sign="sign",t.Verify="verify",t.DeriveKey="deriveKey",t.DeriveBits="deriveBits",t.WrapKey="wrapKey",t.UnwrapKey="unwrapKey",t))(_o||{}),qo=new TextEncoder,Q$=new TextDecoder;async function e4(t,e,n){const r=Oy(e),i=await n4(t,r);return await crypto.subtle.sign(r,i,n)}async function t4(t,e,n,r){const i=Oy(e),s=await r4(t,i);return await crypto.subtle.verify(i,s,n,r)}function Zd(t){return Ny(t.replace(/-+(BEGIN|END).*/g,"").replace(/\s/g,""))}async function n4(t,e){if(!crypto.subtle||!crypto.subtle.importKey)throw new Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");if(Ty(t)){if(t.type!=="private"&&t.type!=="secret")throw new Error(`unexpected key type: CryptoKey.type is ${t.type}, expected private or secret`);return t}const n=[_o.Sign];return typeof t=="object"?await crypto.subtle.importKey("jwk",t,e,!1,n):t.includes("PRIVATE")?await crypto.subtle.importKey("pkcs8",Zd(t),e,!1,n):await crypto.subtle.importKey("raw",qo.encode(t),e,!1,n)}async function r4(t,e){if(!crypto.subtle||!crypto.subtle.importKey)throw new Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");if(Ty(t)){if(t.type==="public"||t.type==="secret")return t;t=await Xh(t)}if(typeof t=="string"&&t.includes("PRIVATE")){const r=await crypto.subtle.importKey("pkcs8",Zd(t),e,!0,[_o.Sign]);t=await Xh(r)}const n=[_o.Verify];return typeof t=="object"?await crypto.subtle.importKey("jwk",t,e,!1,n):t.includes("PUBLIC")?await crypto.subtle.importKey("spki",Zd(t),e,!1,n):await crypto.subtle.importKey("raw",qo.encode(t),e,!1,n)}async function Xh(t){if(t.type!=="private")throw new Error(`unexpected key type: ${t.type}`);if(!t.extractable)throw new Error("unexpected private key is unextractable");const e=await crypto.subtle.exportKey("jwk",t),{kty:n}=e,{alg:r,e:i,n:s}=e,{crv:a,x:c,y:l}=e;return{kty:n,alg:r,e:i,n:s,crv:a,x:c,y:l,key_ops:[_o.Verify]}}function Oy(t){switch(t){case"HS256":return{name:"HMAC",hash:{name:"SHA-256"}};case"HS384":return{name:"HMAC",hash:{name:"SHA-384"}};case"HS512":return{name:"HMAC",hash:{name:"SHA-512"}};case"RS256":return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case"RS384":return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case"RS512":return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case"PS256":return{name:"RSA-PSS",hash:{name:"SHA-256"},saltLength:32};case"PS384":return{name:"RSA-PSS",hash:{name:"SHA-384"},saltLength:48};case"PS512":return{name:"RSA-PSS",hash:{name:"SHA-512"},saltLength:64};case"ES256":return{name:"ECDSA",hash:{name:"SHA-256"},namedCurve:"P-256"};case"ES384":return{name:"ECDSA",hash:{name:"SHA-384"},namedCurve:"P-384"};case"ES512":return{name:"ECDSA",hash:{name:"SHA-512"},namedCurve:"P-521"};case"EdDSA":return{name:"Ed25519",namedCurve:"Ed25519"};default:throw new G$(t)}}function Ty(t){return Rm()==="node"&&crypto.webcrypto?t instanceof crypto.webcrypto.CryptoKey:t instanceof CryptoKey}var ll=t=>Cy(qo.encode(JSON.stringify(t)).buffer).replace(/=/g,""),i4=t=>Cy(t).replace(/=/g,""),Yd=t=>JSON.parse(Q$.decode(Ey(t)));function Py(t){if(typeof t=="object"&&t!==null){const e=t;return"alg"in e&&Object.values(Iy).includes(e.alg)&&(!("typ"in e)||e.typ==="JWT")}return!1}var o4=async(t,e,n="HS256")=>{const r=ll(t);let i;typeof e=="object"&&"alg"in e?(n=e.alg,i=ll({alg:n,typ:"JWT",kid:e.kid})):i=ll({alg:n,typ:"JWT"});const s=`${i}.${r}`,a=await e4(e,n,qo.encode(s)),c=i4(a);return`${s}.${c}`},Ry=async(t,e,n)=>{const r=typeof n=="string"?{alg:n}:n||{},i={alg:r.alg??"HS256",iss:r.iss,nbf:r.nbf??!0,exp:r.exp??!0,iat:r.iat??!0},s=t.split(".");if(s.length!==3)throw new Pc(t);const{header:a,payload:c}=By(t);if(!Py(a))throw new jy(a);const l=Date.now()/1e3|0;if(i.nbf&&c.nbf&&c.nbf>l)throw new W$(t);if(i.exp&&c.exp&&c.exp<=l)throw new J$(t);if(i.iat&&c.iat&&l<c.iat)throw new X$(l,c.iat);if(i.iss){if(!c.iss)throw new cl(i.iss,null);if(typeof i.iss=="string"&&c.iss!==i.iss)throw new cl(i.iss,c.iss);if(i.iss instanceof RegExp&&!i.iss.test(c.iss))throw new cl(i.iss,c.iss)}const d=t.substring(0,t.lastIndexOf("."));if(!await t4(e,i.alg,Ey(s[2]),qo.encode(d)))throw new Y$(t);return c},s4=async(t,e,n)=>{const r=e.verification||{},i=a4(t);if(!Py(i))throw new jy(i);if(!i.kid)throw new Z$(i);if(e.jwks_uri){const a=await fetch(e.jwks_uri,n);if(!a.ok)throw new Error(`failed to fetch JWKS from ${e.jwks_uri}`);const c=await a.json();if(!c.keys)throw new Error('invalid JWKS response. "keys" field is missing');if(!Array.isArray(c.keys))throw new Error('invalid JWKS response. "keys" field is not an array');e.keys?e.keys.push(...c.keys):e.keys=c.keys}else if(!e.keys)throw new Error('verifyWithJwks requires options for either "keys" or "jwks_uri" or both');const s=e.keys.find(a=>a.kid===i.kid);if(!s)throw new Pc(t);return await Ry(t,s,{alg:s.alg||i.alg,...r})},By=t=>{try{const[e,n]=t.split("."),r=Yd(e),i=Yd(n);return{header:r,payload:i}}catch{throw new Pc(t)}},a4=t=>{try{const[e]=t.split(".");return Yd(e)}catch{throw new Pc(t)}},Ly={sign:o4,verify:Ry,decode:By,verifyWithJwks:s4},c4={Stringify:1,BeforeStream:2,Stream:3},Xt=(t,e)=>{const n=new String(t);return n.isEscaped=!0,n.callbacks=e,n},l4=/[&<>'"]/,Uy=async(t,e)=>{let n="";e||(e=[]);const r=await Promise.all(t);for(let i=r.length-1;n+=r[i],i--,!(i<0);i--){let s=r[i];typeof s=="object"&&e.push(...s.callbacks||[]);const a=s.isEscaped;if(s=await(typeof s=="object"?s.toString():s),typeof s=="object"&&e.push(...s.callbacks||[]),s.isEscaped??a)n+=s;else{const c=[n];Kn(s,c),n=c[0]}}return Xt(n,e)},Kn=(t,e)=>{const n=t.search(l4);if(n===-1){e[0]+=t;return}let r,i,s=0;for(i=n;i<t.length;i++){switch(t.charCodeAt(i)){case 34:r="&quot;";break;case 39:r="&#39;";break;case 38:r="&amp;";break;case 60:r="&lt;";break;case 62:r="&gt;";break;default:continue}e[0]+=t.substring(s,i)+r,s=i+1}e[0]+=t.substring(s,i)},Dy=t=>{const e=t.callbacks;if(!(e!=null&&e.length))return t;const n=[t],r={};return e.forEach(i=>i({phase:c4.Stringify,buffer:n,context:r})),n[0]},d4=Ly.verify,u4=Ly.decode;async function Qd(t){const{signingKeys:e}=await t.keys.list({q:"type:jwt_signing"});return await Promise.all(e.map(async r=>{const s=await new Oc(r.cert).publicKey.export(),a=await crypto.subtle.exportKey("jwk",s);return vu.parse({...a,kid:r.kid})}))}o.z.object({alg:o.z.literal("RS256"),kty:o.z.literal("RSA"),use:o.z.literal("sig"),n:o.z.string(),e:o.z.string(),kid:o.z.string(),x5t:o.z.string(),x5c:o.z.array(o.z.string())});async function p4(t){if(t.JWKS_URL&&t.JWKS_SERVICE){const e=await t.JWKS_SERVICE.fetch(t.JWKS_URL);return e.ok?(await e.json()).keys:(console.warn(`JWKS fetch failed with status ${e.status}, falling back to database`),await Qd(t.data))}return await Qd(t.data)}async function f4(t,e){try{const{header:n}=u4(e),i=(await p4(t.env)).find(c=>c.kid===n.kid);if(!i)throw new ee(401,{message:"No matching kid found"});const s=await crypto.subtle.importKey("jwk",i,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!1,["verify"]);return await d4(e,s,"RS256")}catch(n){throw n instanceof S?n:new ee(403,{message:"Invalid JWT signature"})}}function h4(t){return t.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g,"{$1}")}function g4(t,e){return e.startsWith(t)?e:t+e}function wp(t){return async(e,n)=>{var c,l,d;const r=e.req.matchedRoutes.find(u=>u.method.toUpperCase()===e.req.method&&u.path!=="/*");if(!r)return await n();const i=h4(r.path),s="basePath"in r&&typeof r.basePath=="string"?r.basePath:"",a=t.openAPIRegistry.definitions.find(u=>"route"in u&&g4(s,u.route.path)===i&&u.route.method.toUpperCase()===e.req.method.toUpperCase());if(a&&"route"in a){const u=(l=(c=a.route.security)==null?void 0:c[0])==null?void 0:l.Bearer;if(!(u!=null&&u.length))return await n();const f=e.req.header("authorization")||"",[h,m]=f.split(" ");if((h==null?void 0:h.toLowerCase())!=="bearer"||!m)throw new ee(401,{message:"Missing bearer token"});try{const y=await f4(e,m);e.set("user_id",y.sub),e.set("user",y),!e.var.tenant_id&&y.tenant_id&&e.set("tenant_id",y.tenant_id);const v=y.permissions||[],b=((d=y.scope)==null?void 0:d.split(" "))||[];if(u.length&&!(u.some(A=>v.includes(A))||u.some(A=>b.includes(A))))throw new ee(403,{message:"Unauthorized"})}catch(y){throw y instanceof S?y:new ee(403,{message:"Invalid token"})}}return await n()}}const m4=new o.OpenAPIHono().openapi(o.createRoute({tags:["emails"],method:"get",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:fs}},description:"Email provider"}}}),async t=>{const e=await t.env.data.emailProviders.get(t.var.tenant_id);if(!e)throw new S(404,{message:"Email provider not found"});return t.json(e)}).openapi(o.createRoute({tags:["emails"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object(fs.shape)}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Branding settings"}}}),async t=>{const e=t.req.valid("json");return await t.env.data.emailProviders.create(t.var.tenant_id,e),t.text("OK",{status:201})}).openapi(o.createRoute({tags:["emails"],method:"patch",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object(fs.shape).partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Branding settings"}}}),async t=>{const e=t.req.valid("json");return await t.env.data.emailProviders.update(t.var.tenant_id,e),t.text("OK")}),_4=new o.OpenAPIHono().openapi(o.createRoute({tags:["sessions"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ba}},description:"A session"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.sessions.get(t.var.tenant_id,e);if(!n)throw new S(404);return t.json(n)}).openapi(o.createRoute({tags:["sessions"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.sessions.remove(t.var.tenant_id,e))throw new S(404,{message:"Session not found"});return t.text("OK")}).openapi(o.createRoute({tags:["sessions"],method:"post",path:"/{id}/revoke",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{202:{description:"Sesssion deletion status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.sessions.update(t.var.tenant_id,e,{revoked_at:new Date().toDateString()}))throw new S(404,{message:"Session not found"});return t.text("Session deletion request accepted.",{status:202})}),y4=new o.OpenAPIHono().openapi(o.createRoute({tags:["refresh_tokens"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:$u}},description:"A session"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.refreshTokens.get(t.var.tenant_id,e);if(!n)throw new S(404);return t.json(n)}).openapi(o.createRoute({tags:["refresh_tokens"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.refreshTokens.remove(t.var.tenant_id,e))throw new S(404,{message:"Session not found"});return t.text("OK")}),w4=new o.OpenAPIHono().openapi(o.createRoute({tags:["custom-domains"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.array(Ln)}},description:"List of custom domains"}}}),async t=>{const e=await t.env.data.customDomains.list(t.var.tenant_id);return t.json(e)}).openapi(o.createRoute({tags:["custom-domains"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ln}},description:"A customDomain"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.customDomains.get(t.var.tenant_id,e);if(!n)throw new S(404);return t.json(n)}).openapi(o.createRoute({tags:["custom-domains"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.customDomains.remove(t.var.tenant_id,e))throw new S(404,{message:"Custom domain not found"});return t.text("OK")}).openapi(o.createRoute({tags:["custom-domains"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Ln.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Ln}},description:"The updated custom domain"}}}),async t=>{const{id:e}=t.req.valid("param"),n=t.req.valid("json");if(!await t.env.data.customDomains.update(t.var.tenant_id,e,n))throw new S(404);const i=await t.env.data.customDomains.get(t.var.tenant_id,e);if(!i)throw new S(404);return t.json(i)}).openapi(o.createRoute({tags:["custom-domains"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(yu.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Ln}},description:"The created custom domain"}}}),async t=>{const e=t.req.valid("json"),n=await t.env.data.customDomains.create(t.var.tenant_id,e);return t.json(n,{status:201})}).openapi(o.createRoute({tags:["custom-domains"],method:"post",path:"/{id}/verify",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Ln}},description:"The custom domain"}}}),async()=>{throw new S(501,{message:"Not implemented"})});function Rc(t,e){const n={};for(const[r,i]of Object.entries(e)){const s={};for(const[a,c]of Object.entries(i))typeof c=="function"?s[a]=async(...l)=>{const d=performance.now();try{const u=await c(...l),h=performance.now()-d,m=t.res.headers.get("Server-Timing")||"",y=m?`${m}, ${r}-${a};dur=${h.toFixed(2)}`:`${r}-${a};dur=${h.toFixed(2)}`;return t.res.headers.set("Server-Timing",y),u}catch(u){const h=performance.now()-d,m=t.res.headers.get("Server-Timing")||"",y=m?`${m}, ${r}-${a}-error;dur=${h.toFixed(2)}`:`${r}-${a}-error;dur=${h.toFixed(2)}`;throw t.res.headers.set("Server-Timing",y),u}}:s[a]=c;n[r]=s}return n}function Bc(t){return t.ISSUER}function st(t){return t.UNIVERSAL_LOGIN_URL||`${t.ISSUER}u/`}function He(t){return t.OAUTH_API_URL||t.ISSUER}async function Lc(t,e){const n=t.req.header("x-forwarded-host");if(n){const i=await t.env.data.customDomains.getByDomain(n);if(i)return t.set("tenant_id",i.tenant_id),t.set("custom_domain",n),t.set("host",n),await e()}const r=t.req.header("host");if(r){t.set("host",r);const i=r.split(".");if(i.length>1&&typeof i[0]=="string"){const s=i[0];await t.env.data.tenants.get(s)&&t.set("tenant_id",s)}}else t.set("host",new URL(Bc(t.env)).host);if(!t.var.tenant_id){const i=t.req.header("tenant-id");i&&t.set("tenant_id",i)}return await e()}const v4=o.z.object({name:o.z.string(),version:o.z.string(),env:o.z.object({node:o.z.string().optional()}).optional()});function b4(t){if(t)try{let e=t;try{e=atob(t)}catch{}try{const n=JSON.parse(e);return v4.parse(n)}catch{}}catch{return}}const Uc=async(t,e)=>{var l,d,u,f;const n=(l=t.req.query("auth0Client"))==null?void 0:l.slice(0,255),i=(d=(()=>{var h;if(t.req.header("x-forwarded-host")&&t.req.header("x-forwarded-for")){const m=t.req.header("x-forwarded-for");return(h=m==null?void 0:m.split(",")[0])==null?void 0:h.trim()}return t.req.header("cf-connecting-ip")||t.req.header("x-real-ip")})())==null?void 0:d.slice(0,45),s=(u=t.req.header("user-agent"))==null?void 0:u.slice(0,512),a=(f=t.req.header("cf-ipcountry"))==null?void 0:f.slice(0,2),c=n?b4(n):void 0;c&&t.set("auth0_client",c),i&&t.set("ip",i),s&&t.set("useragent",s),a&&t.set("countryCode",a),await e()};function $4(t,e,n,r){try{const i=`${t}:${e}:${JSON.stringify(n)}`;return r?`${r}:${i}`:i}catch{const s=`${t}:${e}:${Date.now()}-${Math.random()}`;return r?`${r}:${s}`:s}}function Dc(t,e){const{cache:n,defaultTtl:r,customTtls:i={},excludeMethods:s=[],cacheEntities:a=[],keyPrefix:c}=e,l=new Set(s),d=a.length===0,u=new Set(a),f={};for(const[h,m]of Object.entries(t)){const y=d||u.has(h),v={};for(const[b,A]of Object.entries(m))if(typeof A=="function"){if(!y){v[b]=A;continue}const O=`${h}:${b}`;if(l.has(O)){v[b]=A;continue}const U=i[O]??r,T=["create","update","remove","delete","set","used"].includes(b);v[b]=async(...R)=>{if(T)return await A.apply(m,R);const W=$4(h,b,R,c),ne=await n.get(W);if(ne!==null)if(ne&&typeof ne=="object"&&"isCachedNull"in ne){const K=ne;return K.isCachedNull?null:K.value}else return ne;const Q=await A.apply(m,R);if(U>=0)if(Q!==null)await n.set(W,Q,U);else{const K={value:null,isCachedNull:!0};await n.set(W,K,U)}return Q}}else v[b]=A;f[h]=v}return f}class k4{constructor(e={}){ae(this,"cache",new Map);ae(this,"accessOrder",new Map);ae(this,"accessCounter",0);ae(this,"cleanupTimer");this.config=e;const n=e.cleanupIntervalMs;n&&n>0&&(this.cleanupTimer=setInterval(()=>{this.cleanupExpired()},n))}async get(e){const n=this.cache.get(e);return n?n.expiresAt&&n.expiresAt<new Date?(this.cache.delete(e),this.accessOrder.delete(e),null):(this.accessOrder.set(e,++this.accessCounter),n.value):null}async set(e,n,r){let i;const s=r??this.config.defaultTtlSeconds,a=s!==void 0,c=a?Math.max(0,s):0;a&&(i=new Date(Date.now()+(c>0?c*1e3:-1))),this.config.maxEntries&&this.cache.size>=this.config.maxEntries&&!this.cache.has(e)&&this.evictLeastRecentlyUsed();const l={value:n,expiresAt:i};this.cache.set(e,l),this.accessOrder.set(e,++this.accessCounter)}async delete(e){const n=this.cache.has(e);return this.cache.delete(e),this.accessOrder.delete(e),n}async clear(){this.cache.clear(),this.accessOrder.clear(),this.accessCounter=0}getStats(){return{size:this.cache.size,maxEntries:this.config.maxEntries,defaultTtlSeconds:this.config.defaultTtlSeconds}}cleanupExpired(){const e=new Date,n=[];for(const[r,i]of this.cache.entries())i.expiresAt&&i.expiresAt<e&&n.push(r);for(const r of n)this.cache.delete(r),this.accessOrder.delete(r)}evictLeastRecentlyUsed(){let e=null,n=1/0;for(const[r,i]of this.accessOrder.entries())i<n&&(n=i,e=r);e&&(this.cache.delete(e),this.accessOrder.delete(e))}destroy(){this.cleanupTimer&&(clearInterval(this.cleanupTimer),this.cleanupTimer=void 0)}}function Ho(t={}){return new k4(t)}const x4=St.extend({forms:o.z.array(Vr)}),S4=new o.OpenAPIHono().openapi(o.createRoute({tags:["forms"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Vr),x4])}},description:"List of forms"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{page:n,per_page:r,include_totals:i=!1,sort:s,q:a}=t.req.valid("query"),c=await t.env.data.forms.list(e,{page:n,per_page:r,include_totals:i,sort:ft(s),q:a});return i?t.json(c):t.json(c.forms)}).openapi(o.createRoute({tags:["forms"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Vr}},description:"A form"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.forms.get(e,n);if(!r)throw new S(404);return t.json(r)}).openapi(o.createRoute({tags:["forms"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.forms.remove(e,n))throw new S(404,{message:"Form not found"});return t.text("OK")}).openapi(o.createRoute({tags:["forms"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Bs.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Vr}},description:"The updated form"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=t.req.valid("json");if(!await t.env.data.forms.update(e,n,r))throw new S(404,{message:"Form not found"});const s=await t.env.data.forms.get(e,n);if(!s)throw new S(404,{message:"Form not found"});return t.json(s)}).openapi(o.createRoute({tags:["forms"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Bs.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Vr}},description:"A form"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.forms.create(e,n);return t.json(r,{status:201})}),z4=St.extend({roles:o.z.array(lr)}),A4=new o.OpenAPIHono().openapi(o.createRoute({tags:["roles"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(lr),z4])}},description:"List of roles"}}}),async t=>{const{page:e,per_page:n,include_totals:r,sort:i,q:s}=t.req.valid("query"),a=await t.env.data.roles.list(t.var.tenant_id,{page:e,per_page:n,include_totals:r,sort:ft(i),q:s});return r?t.json(a):t.json(a.roles)}).openapi(o.createRoute({tags:["roles"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:lr}},description:"A role"}}}),async t=>{const{id:e}=t.req.valid("param"),n=await t.env.data.roles.get(t.var.tenant_id,e);if(!n)throw new S(404);return t.json(n)}).openapi(o.createRoute({tags:["roles"],method:"post",path:"/",request:{headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:Ds}}}},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:lr}},description:"Role created"}}}),async t=>{const e=t.req.valid("json"),n=await t.env.data.roles.create(t.var.tenant_id,e);return t.json(n,{status:201})}).openapi(o.createRoute({tags:["roles"],method:"patch",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:Ds.partial()}}}},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:lr}},description:"Updated role"}}}),async t=>{const{id:e}=t.req.valid("param"),n=t.req.valid("json");if(!await t.env.data.roles.update(t.var.tenant_id,e,n))throw new S(404);const i=await t.env.data.roles.get(t.var.tenant_id,e);return t.json(i)}).openapi(o.createRoute({tags:["roles"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{id:e}=t.req.valid("param");if(!await t.env.data.roles.remove(t.var.tenant_id,e))throw new S(404);return t.text("OK")}).openapi(o.createRoute({tags:["roles"],method:"get",path:"/{id}/permissions",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),query:Qe},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:rm}},description:"Role permissions"}}}),async t=>{const{id:e}=t.req.valid("param"),{page:n,per_page:r,sort:i,q:s}=t.req.valid("query");if(!await t.env.data.roles.get(t.var.tenant_id,e))throw new S(404,{message:"Role not found"});const c=await t.env.data.rolePermissions.list(t.var.tenant_id,e,{page:n,per_page:r,include_totals:!1,sort:ft(i),q:s});return t.json(c)}).openapi(o.createRoute({tags:["roles"],method:"post",path:"/{id}/permissions",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({permissions:o.z.array(o.z.object({permission_name:o.z.string(),resource_server_identifier:o.z.string()}))})}}}},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Permissions assigned to role"}}}),async t=>{const{id:e}=t.req.valid("param"),{permissions:n}=t.req.valid("json");if(!await t.env.data.roles.get(t.var.tenant_id,e))throw new S(404,{message:"Role not found"});if(!await t.env.data.rolePermissions.assign(t.var.tenant_id,e,n.map(s=>({role_id:e,resource_server_identifier:s.resource_server_identifier,permission_name:s.permission_name}))))throw new S(500,{message:"Failed to assign permissions to role"});return t.json({message:"Permissions assigned successfully"},{status:201})}).openapi(o.createRoute({tags:["roles"],method:"delete",path:"/{id}/permissions",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({permissions:o.z.array(o.z.object({permission_name:o.z.string(),resource_server_identifier:o.z.string()}))})}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Permissions removed from role"}}}),async t=>{const{id:e}=t.req.valid("param"),{permissions:n}=t.req.valid("json");if(!await t.env.data.roles.get(t.var.tenant_id,e))throw new S(404,{message:"Role not found"});if(!await t.env.data.rolePermissions.remove(t.var.tenant_id,e,n))throw new S(500,{message:"Failed to remove permissions from role"});return t.json({message:"Permissions removed successfully"})}),E4=St.extend({resource_servers:o.z.array(cr)}),C4=new o.OpenAPIHono().openapi(o.createRoute({tags:["resource-servers"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(cr),E4])}},description:"List of resource servers"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{page:n,per_page:r,include_totals:i=!1,sort:s,q:a}=t.req.valid("query"),c=await t.env.data.resourceServers.list(e,{page:n,per_page:r,include_totals:i,sort:ft(s),q:a});return i?t.json(c):t.json(c.resource_servers)}).openapi(o.createRoute({tags:["resource-servers"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:cr}},description:"A resource server"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.resourceServers.get(e,n);if(!r)throw new S(404);return t.json(r)}).openapi(o.createRoute({tags:["resource-servers"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.resourceServers.remove(e,n))throw new S(404,{message:"Resource server not found"});return t.text("OK")}).openapi(o.createRoute({tags:["resource-servers"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:o.z.object(Us.shape).partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:cr}},description:"The updated resource server"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=t.req.valid("json");if(!await t.env.data.resourceServers.update(e,n,r))throw new S(404,{message:"Resource server not found"});const s=await t.env.data.resourceServers.get(e,n);if(!s)throw new S(404,{message:"Resource server not found"});return t.json(s)}).openapi(o.createRoute({tags:["resource-servers"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Us.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:cr}},description:"A resource server"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.resourceServers.create(e,n);return t.json(r,{status:201})}),N4=o.z.object({per_page:o.z.string().min(1).optional().default("50").transform(t=>parseInt(t,10)).openapi({description:"Number of results per page. Defaults to 50."}),page:o.z.string().min(0).optional().default("0").transform(t=>parseInt(t,10)).openapi({description:"Page index of the results to return. First page is 0."}),include_totals:o.z.string().optional().default("false").transform(t=>t==="true").openapi({description:"Return results inside an object that contains the total result count (true) or as a direct array of results (false, default)."}),from:o.z.string().optional().openapi({description:"Optional Id from which to start selection."}),take:o.z.string().min(1).optional().transform(t=>t?parseInt(t,10):void 0).openapi({description:"Number of results per page. Defaults to 50."}),audience:o.z.string().optional().openapi({description:"Optional filter on audience."}),client_id:o.z.string().optional().openapi({description:"Optional filter on client_id."}),allow_any_organization:o.z.string().optional().transform(t=>t==="true"?!0:t==="false"?!1:void 0).openapi({description:"Optional filter on allow_any_organization."}),subject_type:o.z.enum(["client","user"]).optional().openapi({description:"EA The type of application access the client grant allows. Use of this field is subject to the applicable Free Trial terms in Okta's Master Subscription Agreement."})}),I4=St.extend({client_grants:o.z.array(ar)}),j4=new o.OpenAPIHono().openapi(o.createRoute({tags:["client-grants"],method:"get",path:"/",request:{query:N4,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(ar),I4])}},description:"List of client grants"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{page:n,per_page:r,include_totals:i=!1,from:s,take:a,audience:c,client_id:l,allow_any_organization:d,subject_type:u}=t.req.valid("query"),f=[];l&&f.push(`client_id:"${l}"`),c&&f.push(`audience:"${c}"`),d!==void 0&&f.push(`allow_any_organization:${d}`),u&&f.push(`subject_type:"${u}"`),s&&f.push(`id:>${s}`);const h=f.length>0?f.join(" AND "):void 0,m=a??r,y=await t.env.data.clientGrants.list(e,{page:n,per_page:m,include_totals:i,q:h});return i?t.json(y):t.json(y.client_grants)}).openapi(o.createRoute({tags:["client-grants"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:ar}},description:"A client grant"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.clientGrants.get(e,n);if(!r)throw new S(404,{message:"Client grant not found"});return t.json(r)}).openapi(o.createRoute({tags:["client-grants"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.clientGrants.remove(e,n))throw new S(404,{message:"Client grant not found"});return t.text("OK")}).openapi(o.createRoute({tags:["client-grants"],method:"patch",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),body:{content:{"application/json":{schema:o.z.object(Ps.shape).partial()}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:ar}},description:"The updated client grant"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=t.req.valid("json");if(!await t.env.data.clientGrants.get(e,n))throw new S(404,{message:"Client grant not found"});if(!await t.env.data.clientGrants.update(e,n,r))throw new S(500,{message:"Failed to update client grant"});const a=await t.env.data.clientGrants.get(e,n);if(!a)throw new S(404,{message:"Client grant not found"});return t.json(a)}).openapi(o.createRoute({tags:["client-grants"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.object(Ps.shape)}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:ar}},description:"A client grant"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r=await t.env.data.clientGrants.create(e,n);return t.json(r,{status:201})}),O4=o.z.object({page:o.z.string().optional().default("0").transform(t=>parseInt(t,10)).openapi({description:"Page index of the results to return. First page is 0."}),per_page:o.z.string().optional().default("50").transform(t=>parseInt(t,10)).openapi({description:"Number of results per page. Defaults to 50."}),include_totals:o.z.string().optional().default("false").transform(t=>t==="true").openapi({description:"When true, return results inside an object that also contains the start and limit. When false (default), a direct array of results is returned."}),fields:o.z.string().optional().openapi({description:"Comma-separated list of fields to include or exclude (based on value provided for include_fields) in the result. Leave empty to retrieve all fields."}),include_fields:o.z.string().optional().default("true").transform(t=>t==="true").openapi({description:"Whether specified fields are to be included (true) or excluded (false). Defaults to true."}),sort:o.z.string().optional().default("created_at:-1").openapi({description:"Field to sort by. Use field:order where order is 1 for ascending and -1 for descending. Defaults to created_at:-1."})}),T4=o.z.object({invitations:o.z.array(Gi),start:o.z.number(),limit:o.z.number(),length:o.z.number()}),P4=wu.omit({organization_id:!0,invitation_url:!0}),R4=St.extend({organizations:o.z.array(Dn)}),vp=o.z.object({user_id:o.z.string().openapi({description:"ID of this user"}),email:o.z.string().email().optional().openapi({description:"Email address of this user",format:"email"}),roles:o.z.array(o.z.object({})).default([]).openapi({description:"Array of roles assigned to this user in the organization"})}),B4=o.z.object({start:o.z.number().openapi({description:"Start index of the current page"}),limit:o.z.number().openapi({description:"Number of items per page"}),total:o.z.number().openapi({description:"Total number of members"}),members:o.z.array(vp).openapi({description:"Array of organization members"})}),L4=o.z.object({next:o.z.string().optional().openapi({description:"Checkpoint ID to be used to retrieve the next set of results"}),members:o.z.array(vp).openapi({description:"Array of organization members"})}),U4=o.z.object({members:o.z.array(o.z.string()).openapi({description:"Array of user IDs to add to the organization"})}),D4=o.z.object({members:o.z.array(o.z.string()).openapi({description:"Array of user IDs to remove from the organization"})}),M4=new o.OpenAPIHono().openapi(o.createRoute({tags:["organizations"],method:"get",path:"/",request:{query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([R4,o.z.array(Dn)])}},description:"List of organizations"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{page:n,per_page:r,include_totals:i,sort:s,q:a}=t.req.valid("query"),c=await t.env.data.organizations.list(e,{page:n,per_page:r,include_totals:i,sort:ft(s),q:a});return i?t.json(c):t.json(c.organizations)}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Dn}},description:"An organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=await t.env.data.organizations.get(e,n);if(!r)throw new S(404,{message:"Organization not found"});return t.json(r)}).openapi(o.createRoute({tags:["organizations"],method:"delete",path:"/{id}",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Organization deleted successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param");if(!await t.env.data.organizations.remove(e,n))throw new S(404,{message:"Organization not found"});return t.text("OK")}).openapi(o.createRoute({tags:["organizations"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:Fs.partial()}}},params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"application/json":{schema:Dn}},description:"The updated organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=t.req.valid("json");if(!await t.env.data.organizations.update(e,n,r))throw new S(404,{message:"Organization not found"});const s=await t.env.data.organizations.get(e,n);if(!s)throw new S(404,{message:"Organization not found"});return t.json(s)}).openapi(o.createRoute({tags:["organizations"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:Fs}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Dn}},description:"The created organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),n=t.req.valid("json"),r={...n,id:n.id||C$()},i=await t.env.data.organizations.create(e,r);return t.json(i,{status:201})}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/members",request:{params:o.z.object({id:o.z.string()}),query:Qe,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(vp),B4,L4])}},description:"List of organization members"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{page:r,per_page:i,include_totals:s,sort:a}=t.req.valid("query");if(!await t.env.data.organizations.get(e,n))throw new S(404,{message:"Organization not found"});const l=await t.env.data.userOrganizations.list(e,{page:r,per_page:i,include_totals:s,sort:ft(a),q:`organization_id:${n}`}),d=[];for(const u of l.userOrganizations){const f=await t.env.data.users.get(e,u.user_id);f&&d.push({user_id:f.user_id,email:f.email||void 0,roles:[]})}return s?t.json({start:l.start,limit:l.limit,total:l.length,members:d}):t.json(d)}).openapi(o.createRoute({tags:["organizations"],method:"post",path:"/{id}/members",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:U4}}}},security:[{Bearer:["auth:write"]}],responses:{204:{description:"Members added successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{members:r}=t.req.valid("json");if(!await t.env.data.organizations.get(e,n))throw new S(404,{message:"Organization not found"});for(const s of r)(await t.env.data.userOrganizations.list(e,{q:`user_id:${s}`,per_page:1})).userOrganizations.some(l=>l.organization_id===n)||await t.env.data.userOrganizations.create(e,{user_id:s,organization_id:n});return new Response(null,{status:204})}).openapi(o.createRoute({tags:["organizations"],method:"delete",path:"/{id}/members",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:D4}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Members removed successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{members:r}=t.req.valid("json");for(const i of r){const a=(await t.env.data.userOrganizations.list(e,{q:`user_id:${i}`,per_page:100})).userOrganizations.find(c=>c.organization_id===n);a&&await t.env.data.userOrganizations.remove(e,a.id)}return t.json({message:"Members removed successfully"})}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/members/{user_id}/roles",request:{params:o.z.object({id:o.z.string(),user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),query:Qe},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ms}},description:"User roles in organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n,user_id:r}=t.req.valid("param");if(!await t.env.data.organizations.get(e,n))throw new S(404,{message:"Organization not found"});if(!await t.env.data.users.get(e,r))throw new S(404,{message:"User not found"});const a=await t.env.data.userRoles.list(e,r,void 0,n);return t.json(a)}).openapi(o.createRoute({tags:["organizations"],method:"post",path:"/{id}/members/{user_id}/roles",request:{params:o.z.object({id:o.z.string(),user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({roles:o.z.array(o.z.string()).openapi({description:"List of role IDs to associate with the user"})})}}}},security:[{Bearer:["auth:write"]}],responses:{201:{description:"Roles assigned successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n,user_id:r}=t.req.valid("param"),{roles:i}=t.req.valid("json");if(!await t.env.data.organizations.get(e,n))throw new S(404,{message:"Organization not found"});if(!await t.env.data.users.get(e,r))throw new S(404,{message:"User not found"});for(const c of i){if(!await t.env.data.roles.get(e,c))throw new S(400,{message:`Role ${c} not found`});if(!await t.env.data.userRoles.create(e,r,c,n))throw new S(500,{message:`Failed to assign role ${c} to user`})}return t.json({message:"Roles assigned successfully"},{status:201})}).openapi(o.createRoute({tags:["organizations"],method:"delete",path:"/{id}/members/{user_id}/roles",request:{params:o.z.object({id:o.z.string(),user_id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),body:{content:{"application/json":{schema:o.z.object({roles:o.z.array(o.z.string()).openapi({description:"List of role IDs to remove from the user"})})}}}},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Roles removed successfully"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n,user_id:r}=t.req.valid("param"),{roles:i}=t.req.valid("json");if(!await t.env.data.organizations.get(e,n))throw new S(404,{message:"Organization not found"});if(!await t.env.data.users.get(e,r))throw new S(404,{message:"User not found"});for(const c of i)if(!await t.env.data.userRoles.remove(e,r,c,n))throw new S(500,{message:`Failed to remove role ${c} from user`});return t.json({message:"Roles removed successfully"})}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/roles",request:{params:o.z.object({id:o.z.string()}),headers:o.z.object({"tenant-id":o.z.string()}),query:Qe},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Ms}},description:"List of roles available in organization"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{page:r,per_page:i,sort:s,q:a}=t.req.valid("query");if(!await t.env.data.organizations.get(e,n))throw new S(404,{message:"Organization not found"});const l=await t.env.data.roles.list(e,{page:r,per_page:i,sort:ft(s),q:a});return t.json(l.roles)}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/invitations",request:{params:o.z.object({id:o.z.string().openapi({description:"Organization ID",param:{name:"id",in:"path"}})}),query:O4,headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:o.z.union([o.z.array(Gi),T4])}},description:"List of organization invitations"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),{page:r,per_page:i,include_totals:s,fields:a,include_fields:c,sort:l}=t.req.valid("query");if(!await t.env.data.organizations.get(e,n))throw new S(404,{message:"Organization not found"});let f=(await t.env.data.invites.list(e,{page:r,per_page:i})).invites.filter(h=>h.organization_id===n);if(l){const h=ft(l);if(h){const{sort_by:m,sort_order:y}=h;f.sort((v,b)=>{const A=v[m],O=b[m];if(A===void 0||O===void 0||A===O)return 0;const U=A<O?-1:1;return y==="asc"?U:-U})}}if(a){const h=a.split(",").map(m=>m.trim());f=f.map(m=>{const y={};for(const v of Object.keys(m))(c?h.includes(v):!h.includes(v))&&(y[v]=m[v]);return y})}return s?t.json({invitations:f,start:r*i,limit:i,length:f.length}):t.json(f)}).openapi(o.createRoute({tags:["organizations"],method:"get",path:"/{id}/invitations/{invitation_id}",request:{params:o.z.object({id:o.z.string().openapi({description:"Organization ID",param:{name:"id",in:"path"}}),invitation_id:o.z.string().openapi({description:"Invitation ID",param:{name:"invitation_id",in:"path"}})}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"application/json":{schema:Gi}},description:"An invitation"},404:{description:"Invitation not found"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n,invitation_id:r}=t.req.valid("param"),i=await t.env.data.invites.get(e,r);if(!i||i.organization_id!==n)throw new S(404,{message:"Invitation not found"});return t.json(i)}).openapi(o.createRoute({tags:["organizations"],method:"post",path:"/{id}/invitations",request:{params:o.z.object({id:o.z.string().openapi({description:"Organization ID",param:{name:"id",in:"path"}})}),body:{content:{"application/json":{schema:P4}}},headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{201:{content:{"application/json":{schema:Gi}},description:"The created invitation"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n}=t.req.valid("param"),r=t.req.valid("json");if(!await t.env.data.organizations.get(e,n))throw new S(404,{message:"Organization not found"});const a=`https://invite.placeholder/${j$()}`,c={...r,organization_id:n,invitation_url:a},l=await t.env.data.invites.create(e,c);return t.json(l,{status:201})}).openapi(o.createRoute({tags:["organizations"],method:"delete",path:"/{id}/invitations/{invitation_id}",request:{params:o.z.object({id:o.z.string().openapi({description:"Organization ID",param:{name:"id",in:"path"}}),invitation_id:o.z.string().openapi({description:"Invitation ID",param:{name:"invitation_id",in:"path"}})}),headers:o.z.object({"tenant-id":o.z.string()})},security:[{Bearer:["auth:write"]}],responses:{204:{description:"Invitation deleted successfully"},404:{description:"Invitation not found"}}}),async t=>{const{"tenant-id":e}=t.req.valid("header"),{id:n,invitation_id:r}=t.req.valid("param"),i=await t.env.data.invites.get(e,r);if(!i||i.organization_id!==n)throw new S(404,{message:"Invitation not found"});if(!await t.env.data.invites.remove(e,r))throw new S(404,{message:"Invitation not found"});return t.body(null,{status:204})});function F4(t){const e=new o.OpenAPIHono;e.use(g0({origin:r=>{var i;return r&&(i=t.allowedOrigins)!=null&&i.includes(r)?r:""},allowHeaders:["Tenant-Id","Content-Type","Content-Range","Auth0-Client","Authorization","Range","Upgrade-Insecure-Requests"],allowMethods:["POST","PUT","GET","DELETE","PATCH","OPTIONS"],exposeHeaders:["Content-Length","Content-Range"],maxAge:600,credentials:!0})),yp(e),e.use(async(r,i)=>{const s=xo(r,t.dataAdapter),a=Ho({defaultTtlSeconds:0,maxEntries:100,cleanupIntervalMs:0}),c=Dc(s,{defaultTtl:0,cacheEntities:["tenants","connections","clients","legacyClients","branding","themes","promptSettings","forms"],cache:a});return r.env.data=Rc(r,c),i()}),e.use(Uc).use(Lc).use(wp(e));const n=e.route("/branding",nv).route("/custom-domains",w4).route("/email/providers",m4).route("/users",bb).route("/keys",w$).route("/users-by-email",v$).route("/clients",$$).route("/client-grants",j4).route("/tenants",x$).route("/logs",z$).route("/hooks",T$).route("/connections",R$).route("/prompts",B$).route("/sessions",_4).route("/refresh_tokens",y4).route("/forms",S4).route("/roles",A4).route("/resource-servers",C4).route("/organizations",M4);return n.doc("/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"Management API"},servers:[{url:"/api/v2",description:"API V2"}],security:[{oauth2:["openid","email","profile"]}]}),n}function q4(t,e){Object.keys(e).forEach(n=>{const r=e[n];r!=null&&r.length&&t.searchParams.set(n,r)})}function Nn(t){var e;if(t)return`${t.name}/${t.version}${(e=t.env)!=null&&e.node?` (env: node/${t.env.node})`:""}`}var H4=(t,...e)=>{const n=[""];for(let r=0,i=t.length-1;r<i;r++){n[0]+=t[r];const s=Array.isArray(e[r])?e[r].flat(1/0):[e[r]];for(let a=0,c=s.length;a<c;a++){const l=s[a];if(typeof l=="string")Kn(l,n);else if(typeof l=="number")n[0]+=l;else{if(typeof l=="boolean"||l===null||l===void 0)continue;if(typeof l=="object"&&l.isEscaped)if(l.callbacks)n.unshift("",l);else{const d=l.toString();d instanceof Promise?n.unshift("",d):n[0]+=d}else l instanceof Promise?n.unshift("",l):Kn(l.toString(),n)}}}return n[0]+=t.at(-1),n.length===1?"callbacks"in n?Xt(Dy(Xt(n[0],n.callbacks))):Xt(n[0]):Uy(n,n.callbacks)},bp=Symbol("RENDERER"),eu=Symbol("ERROR_HANDLER"),Le=Symbol("STASH"),My=Symbol("INTERNAL"),V4=Symbol("MEMO"),za=Symbol("PERMALINK"),Zh=t=>(t[My]=!0,t),Fy=t=>({value:e,children:n})=>{if(!n)return;const r={children:[{tag:Zh(()=>{t.push(e)}),props:{}}]};Array.isArray(n)?r.children.push(...n.flat()):r.children.push(n),r.children.push({tag:Zh(()=>{t.pop()}),props:{}});const i={tag:"",props:r,type:""};return i[eu]=s=>{throw t.pop(),s},i},qy=t=>{const e=[t],n=Fy(e);return n.values=e,n.Provider=n,gi.push(n),n},gi=[],Hy=t=>{const e=[t],n=r=>{e.push(r.value);let i;try{i=r.children?(Array.isArray(r.children)?new Wy("",{},r.children):r.children).toString():""}finally{e.pop()}return i instanceof Promise?i.then(s=>Xt(s,s.callbacks)):Xt(i)};return n.values=e,n.Provider=n,n[bp]=Fy(e),gi.push(n),n},ji=t=>t.values.at(-1),ws={title:[],script:["src"],style:["data-href"],link:["href"],meta:["name","httpEquiv","charset","itemProp"]},tu={},vs="data-precedence",Vo=t=>Array.isArray(t)?t:[t],Yh=new WeakMap,Qh=(t,e,n,r)=>({buffer:i,context:s})=>{if(!i)return;const a=Yh.get(s)||{};Yh.set(s,a);const c=a[t]||(a[t]=[]);let l=!1;const d=ws[t];if(d.length>0){e:for(const[,u]of c)for(const f of d)if(((u==null?void 0:u[f])??null)===(n==null?void 0:n[f])){l=!0;break e}}if(l?i[0]=i[0].replaceAll(e,""):d.length>0?c.push([e,n,r]):c.unshift([e,n,r]),i[0].indexOf("</head>")!==-1){let u;if(r===void 0)u=c.map(([f])=>f);else{const f=[];u=c.map(([h,,m])=>{let y=f.indexOf(m);return y===-1&&(f.push(m),y=f.length-1),[h,y]}).sort((h,m)=>h[1]-m[1]).map(([h])=>h)}u.forEach(f=>{i[0]=i[0].replaceAll(f,"")}),i[0]=i[0].replace(/(?=<\/head>)/,u.join(""))}},Ko=(t,e,n)=>Xt(new Zt(t,n,Vo(e??[])).toString()),Go=(t,e,n,r)=>{if("itemProp"in n)return Ko(t,e,n);let{precedence:i,blocking:s,...a}=n;i=r?i??"":void 0,r&&(a[vs]=i);const c=new Zt(t,a,Vo(e||[])).toString();return c instanceof Promise?c.then(l=>Xt(c,[...l.callbacks||[],Qh(t,l,a,i)])):Xt(c,[Qh(t,c,a,i)])},K4=({children:t,...e})=>{const n=$p();if(n){const r=ji(n);if(r==="svg"||r==="head")return new Zt("title",e,Vo(t??[]))}return Go("title",t,e,!1)},G4=({children:t,...e})=>{const n=$p();return["src","async"].some(r=>!e[r])||n&&ji(n)==="head"?Ko("script",t,e):Go("script",t,e,!1)},W4=({children:t,...e})=>["href","precedence"].every(n=>n in e)?(e["data-href"]=e.href,delete e.href,Go("style",t,e,!0)):Ko("style",t,e),J4=({children:t,...e})=>["onLoad","onError"].some(n=>n in e)||e.rel==="stylesheet"&&(!("precedence"in e)||"disabled"in e)?Ko("link",t,e):Go("link",t,e,"precedence"in e),X4=({children:t,...e})=>{const n=$p();return n&&ji(n)==="head"?Ko("meta",t,e):Go("meta",t,e,!1)},Vy=(t,{children:e,...n})=>new Zt(t,n,Vo(e??[])),Z4=t=>(typeof t.action=="function"&&(t.action=za in t.action?t.action[za]:void 0),Vy("form",t)),Ky=(t,e)=>(typeof e.formAction=="function"&&(e.formAction=za in e.formAction?e.formAction[za]:void 0),Vy(t,e)),Y4=t=>Ky("input",t),Q4=t=>Ky("button",t);const dl=Object.freeze(Object.defineProperty({__proto__:null,button:Q4,form:Z4,input:Y4,link:J4,meta:X4,script:G4,style:W4,title:K4},Symbol.toStringTag,{value:"Module"}));var ek=new Map([["className","class"],["htmlFor","for"],["crossOrigin","crossorigin"],["httpEquiv","http-equiv"],["itemProp","itemprop"],["fetchPriority","fetchpriority"],["noModule","nomodule"],["formAction","formaction"]]),Aa=t=>ek.get(t)||t,Gy=(t,e)=>{for(const[n,r]of Object.entries(t)){const i=n[0]==="-"||!/[A-Z]/.test(n)?n:n.replace(/[A-Z]/g,s=>`-${s.toLowerCase()}`);e(i,r==null?null:typeof r=="number"?i.match(/^(?:a|border-im|column(?:-c|s)|flex(?:$|-[^b])|grid-(?:ar|[^a])|font-w|li|or|sca|st|ta|wido|z)|ty$/)?`${r}`:`${r}px`:r)}},yo=void 0,$p=()=>yo,tk=t=>/[A-Z]/.test(t)&&t.match(/^(?:al|basel|clip(?:Path|Rule)$|co|do|fill|fl|fo|gl|let|lig|i|marker[EMS]|o|pai|pointe|sh|st[or]|text[^L]|tr|u|ve|w)/)?t.replace(/([A-Z])/g,"-$1").toLowerCase():t,nk=["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],rk=["allowfullscreen","async","autofocus","autoplay","checked","controls","default","defer","disabled","download","formnovalidate","hidden","inert","ismap","itemscope","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","selected"],kp=(t,e)=>{for(let n=0,r=t.length;n<r;n++){const i=t[n];if(typeof i=="string")Kn(i,e);else{if(typeof i=="boolean"||i===null||i===void 0)continue;i instanceof Zt?i.toStringToBuffer(e):typeof i=="number"||i.isEscaped?e[0]+=i:i instanceof Promise?e.unshift("",i):kp(i,e)}}},Zt=class{constructor(t,e,n){ae(this,"tag");ae(this,"props");ae(this,"key");ae(this,"children");ae(this,"isEscaped",!0);ae(this,"localContexts");this.tag=t,this.props=e,this.children=n}get type(){return this.tag}get ref(){return this.props.ref||null}toString(){var e,n;const t=[""];(e=this.localContexts)==null||e.forEach(([r,i])=>{r.values.push(i)});try{this.toStringToBuffer(t)}finally{(n=this.localContexts)==null||n.forEach(([r])=>{r.values.pop()})}return t.length===1?"callbacks"in t?Dy(Xt(t[0],t.callbacks)).toString():t[0]:Uy(t,t.callbacks)}toStringToBuffer(t){const e=this.tag,n=this.props;let{children:r}=this;t[0]+=`<${e}`;const i=yo&&ji(yo)==="svg"?s=>tk(Aa(s)):s=>Aa(s);for(let[s,a]of Object.entries(n))if(s=i(s),s!=="children"){if(s==="style"&&typeof a=="object"){let c="";Gy(a,(l,d)=>{d!=null&&(c+=`${c?";":""}${l}:${d}`)}),t[0]+=' style="',Kn(c,t),t[0]+='"'}else if(typeof a=="string")t[0]+=` ${s}="`,Kn(a,t),t[0]+='"';else if(a!=null)if(typeof a=="number"||a.isEscaped)t[0]+=` ${s}="${a}"`;else if(typeof a=="boolean"&&rk.includes(s))a&&(t[0]+=` ${s}=""`);else if(s==="dangerouslySetInnerHTML"){if(r.length>0)throw new Error("Can only set one of `children` or `props.dangerouslySetInnerHTML`.");r=[Xt(a.__html)]}else if(a instanceof Promise)t[0]+=` ${s}="`,t.unshift('"',a);else if(typeof a=="function"){if(!s.startsWith("on")&&s!=="ref")throw new Error(`Invalid prop '${s}' of type 'function' supplied to '${e}'.`)}else t[0]+=` ${s}="`,Kn(a.toString(),t),t[0]+='"'}if(nk.includes(e)&&r.length===0){t[0]+="/>";return}t[0]+=">",kp(r,t),t[0]+=`</${e}>`}},ul=class extends Zt{toStringToBuffer(t){const{children:e}=this,n=this.tag.call(null,{...this.props,children:e.length<=1?e[0]:e});if(!(typeof n=="boolean"||n==null))if(n instanceof Promise)if(gi.length===0)t.unshift("",n);else{const r=gi.map(i=>[i,i.values.at(-1)]);t.unshift("",n.then(i=>(i instanceof Zt&&(i.localContexts=r),i)))}else n instanceof Zt?n.toStringToBuffer(t):typeof n=="number"||n.isEscaped?(t[0]+=n,n.callbacks&&(t.callbacks||(t.callbacks=[]),t.callbacks.push(...n.callbacks))):Kn(n,t)}},Wy=class extends Zt{toStringToBuffer(t){kp(this.children,t)}},ik=(t,e,...n)=>{e??(e={}),n.length&&(e.children=n.length===1?n[0]:n);const r=e.key;delete e.key;const i=bs(t,e,n);return i.key=r,i},eg=!1,bs=(t,e,n)=>{if(!eg){for(const r in tu)dl[r][bp]=tu[r];eg=!0}return typeof t=="function"?new ul(t,e,n):dl[t]?new ul(dl[t],e,n):t==="svg"||t==="head"?(yo||(yo=Hy("")),new Zt(t,e,[new ul(yo,{value:t},n)])):new Zt(t,e,n)},Mc=({children:t})=>new Wy("",{children:t},Array.isArray(t)?t:t?[t]:[]),ok=(t,e,...n)=>{let r;if(n.length>0)r=n;else{const i=t.props.children;r=Array.isArray(i)?i:[i]}return ik(t.tag,{...t.props,...e},...r)};function p(t,e,n){let r;if(!e||!("children"in e))r=bs(t,e,[]);else{const i=e.children;r=Array.isArray(i)?bs(t,e,i):bs(t,e,[i])}return r.key=n,r}var tg;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(tg||(tg={}));var ng;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(ng||(ng={}));function sk(t){return Xy(t,ak,wo.Include)}function Jy(t){return Xy(t,ck,wo.None)}function Xy(t,e,n){let r="";for(let i=0;i<t.byteLength;i+=3){let s=0,a=0;for(let c=0;c<3&&i+c<t.byteLength;c++)s=s<<8|t[i+c],a+=8;for(let c=0;c<4;c++)a>=6?(r+=e[s>>a-6&63],a-=6):a>0?(r+=e[s<<6-a&63],a=0):n===wo.Include&&(r+="=")}return r}const ak="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",ck="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";var wo;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(wo||(wo={}));var rg;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(rg||(rg={}));class lk{uint8(e,n){if(e.byteLength<n+1)throw new TypeError("Insufficient bytes");return e[n]}uint16(e,n){if(e.byteLength<n+2)throw new TypeError("Insufficient bytes");return e[n]<<8|e[n+1]}uint32(e,n){if(e.byteLength<n+4)throw new TypeError("Insufficient bytes");let r=0;for(let i=0;i<4;i++)r|=e[n+i]<<24-i*8;return r}uint64(e,n){if(e.byteLength<n+8)throw new TypeError("Insufficient bytes");let r=0n;for(let i=0;i<8;i++)r|=BigInt(e[n+i])<<BigInt(56-i*8);return r}putUint8(e,n,r){if(e.length<r+1)throw new TypeError("Not enough space");if(n<0||n>255)throw new TypeError("Invalid uint8 value");e[r]=n}putUint16(e,n,r){if(e.length<r+2)throw new TypeError("Not enough space");if(n<0||n>65535)throw new TypeError("Invalid uint16 value");e[r]=n>>8,e[r+1]=n&255}putUint32(e,n,r){if(e.length<r+4)throw new TypeError("Not enough space");if(n<0||n>4294967295)throw new TypeError("Invalid uint32 value");for(let i=0;i<4;i++)e[r+i]=n>>(3-i)*8&255}putUint64(e,n,r){if(e.length<r+8)throw new TypeError("Not enough space");if(n<0||n>18446744073709551615n)throw new TypeError("Invalid uint64 value");for(let i=0;i<8;i++)e[r+i]=Number(n>>BigInt((7-i)*8)&0xffn)}}const ig=new lk;function sn(t,e){return(t<<32-e|t>>>e)>>>0}function dk(t){const e=new uk;return e.update(t),e.digest()}class uk{constructor(){ae(this,"blockSize",64);ae(this,"size",32);ae(this,"blocks",new Uint8Array(64));ae(this,"currentBlockSize",0);ae(this,"H",new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]));ae(this,"l",0n);ae(this,"w",new Uint32Array(64))}update(e){if(this.l+=BigInt(e.byteLength)*8n,this.currentBlockSize+e.byteLength<64){this.blocks.set(e,this.currentBlockSize),this.currentBlockSize+=e.byteLength;return}let n=0;if(this.currentBlockSize>0){const r=e.slice(0,64-this.currentBlockSize);this.blocks.set(r,this.currentBlockSize),this.process(),n+=r.byteLength,this.currentBlockSize=0}for(;n+64<=e.byteLength;){const r=e.slice(n,n+64);this.blocks.set(r),this.process(),n+=64}if(e.byteLength-n>0){const r=e.slice(n);this.blocks.set(r),this.currentBlockSize=r.byteLength}}digest(){this.blocks[this.currentBlockSize]=128,this.currentBlockSize+=1,64-this.currentBlockSize<8&&(this.blocks.fill(0,this.currentBlockSize),this.process(),this.currentBlockSize=0),this.blocks.fill(0,this.currentBlockSize),ig.putUint64(this.blocks,this.l,this.blockSize-8),this.process();const e=new Uint8Array(32);for(let n=0;n<8;n++)ig.putUint32(e,this.H[n],n*4);return e}process(){for(let d=0;d<16;d++)this.w[d]=(this.blocks[d*4]<<24|this.blocks[d*4+1]<<16|this.blocks[d*4+2]<<8|this.blocks[d*4+3])>>>0;for(let d=16;d<64;d++){const u=(sn(this.w[d-2],17)^sn(this.w[d-2],19)^this.w[d-2]>>>10)>>>0,f=(sn(this.w[d-15],7)^sn(this.w[d-15],18)^this.w[d-15]>>>3)>>>0;this.w[d]=u+this.w[d-7]+f+this.w[d-16]|0}let e=this.H[0],n=this.H[1],r=this.H[2],i=this.H[3],s=this.H[4],a=this.H[5],c=this.H[6],l=this.H[7];for(let d=0;d<64;d++){const u=(sn(s,6)^sn(s,11)^sn(s,25))>>>0,f=(s&a^~s&c)>>>0,h=l+u+f+pk[d]+this.w[d]|0,m=(sn(e,2)^sn(e,13)^sn(e,22))>>>0,y=(e&n^e&r^n&r)>>>0,v=m+y|0;l=c,c=a,a=s,s=i+h|0,i=r,r=n,n=e,e=h+v|0}this.H[0]=e+this.H[0]|0,this.H[1]=n+this.H[1]|0,this.H[2]=r+this.H[2]|0,this.H[3]=i+this.H[3]|0,this.H[4]=s+this.H[4]|0,this.H[5]=a+this.H[5]|0,this.H[6]=c+this.H[6]|0,this.H[7]=l+this.H[7]|0}}const pk=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);new BigUint64Array([0x428a2f98d728ae22n,0x7137449123ef65cdn,0xb5c0fbcfec4d3b2fn,0xe9b5dba58189dbbcn,0x3956c25bf348b538n,0x59f111f1b605d019n,0x923f82a4af194f9bn,0xab1c5ed5da6d8118n,0xd807aa98a3030242n,0x12835b0145706fben,0x243185be4ee4b28cn,0x550c7dc3d5ffb4e2n,0x72be5d74f27b896fn,0x80deb1fe3b1696b1n,0x9bdc06a725c71235n,0xc19bf174cf692694n,0xe49b69c19ef14ad2n,0xefbe4786384f25e3n,0x0fc19dc68b8cd5b5n,0x240ca1cc77ac9c65n,0x2de92c6f592b0275n,0x4a7484aa6ea6e483n,0x5cb0a9dcbd41fbd4n,0x76f988da831153b5n,0x983e5152ee66dfabn,0xa831c66d2db43210n,0xb00327c898fb213fn,0xbf597fc7beef0ee4n,0xc6e00bf33da88fc2n,0xd5a79147930aa725n,0x06ca6351e003826fn,0x142929670a0e6e70n,0x27b70a8546d22ffcn,0x2e1b21385c26c926n,0x4d2c6dfc5ac42aedn,0x53380d139d95b3dfn,0x650a73548baf63den,0x766a0abb3c77b2a8n,0x81c2c92e47edaee6n,0x92722c851482353bn,0xa2bfe8a14cf10364n,0xa81a664bbc423001n,0xc24b8b70d0f89791n,0xc76c51a30654be30n,0xd192e819d6ef5218n,0xd69906245565a910n,0xf40e35855771202an,0x106aa07032bbd1b8n,0x19a4c116b8d2d0c8n,0x1e376c085141ab53n,0x2748774cdf8eeb99n,0x34b0bcb5e19b48a8n,0x391c0cb3c5c95a63n,0x4ed8aa4ae3418acbn,0x5b9cca4f7763e373n,0x682e6ff3d6b2b8a3n,0x748f82ee5defb2fcn,0x78a5636f43172f60n,0x84c87814a1f0ab72n,0x8cc702081a6439ecn,0x90befffa23631e28n,0xa4506cebde82bde9n,0xbef9a3f7b2c67915n,0xc67178f2e372532bn,0xca273eceea26619cn,0xd186b8c721c0c207n,0xeada7dd6cde0eb1en,0xf57d4f7fee6ed178n,0x06f067aa72176fban,0x0a637dc5a2c898a6n,0x113f9804bef90daen,0x1b710b35131c471bn,0x28db77f523047d84n,0x32caab7b40c72493n,0x3c9ebe0a15c9bebcn,0x431d67c49c100d4cn,0x4cc5d4becb3e42b6n,0x597f299cfc657e2an,0x5fcb6fab3ad6faecn,0x6c44198c4a475817n]);class Zy{constructor(e){ae(this,"data");this.data=e}tokenType(){if("token_type"in this.data&&typeof this.data.token_type=="string")return this.data.token_type;throw new Error("Missing or invalid 'token_type' field")}accessToken(){if("access_token"in this.data&&typeof this.data.access_token=="string")return this.data.access_token;throw new Error("Missing or invalid 'access_token' field")}accessTokenExpiresInSeconds(){if("expires_in"in this.data&&typeof this.data.expires_in=="number")return this.data.expires_in;throw new Error("Missing or invalid 'expires_in' field")}accessTokenExpiresAt(){return new Date(Date.now()+this.accessTokenExpiresInSeconds()*1e3)}hasRefreshToken(){return"refresh_token"in this.data&&typeof this.data.refresh_token=="string"}refreshToken(){if("refresh_token"in this.data&&typeof this.data.refresh_token=="string")return this.data.refresh_token;throw new Error("Missing or invalid 'refresh_token' field")}hasScopes(){return"scope"in this.data&&typeof this.data.scope=="string"}scopes(){if("scope"in this.data&&typeof this.data.scope=="string")return this.data.scope.split(" ");throw new Error("Missing or invalid 'scope' field")}idToken(){if("id_token"in this.data&&typeof this.data.id_token=="string")return this.data.id_token;throw new Error("Missing or invalid field 'id_token'")}}function fk(t){const e=dk(new TextEncoder().encode(t));return Jy(e)}function Yy(){const t=new Uint8Array(32);return crypto.getRandomValues(t),Jy(t)}function hk(t,e){if(e.length!==1)throw new TypeError("Invalid character string");let n=0;for(;n<t.length&&t[n]===e;)n++;return t.slice(n)}function og(t,e){if(e.length!==1)throw new TypeError("Invalid character string");let n=t.length;for(;n>0&&t[n-1]===e;)n--;return t.slice(0,n)}function sg(t,...e){let n=og(t,"/");for(const r of e)n=og(n,"/")+"/"+hk(r,"/");return n}function mr(t,e){const n=new TextEncoder().encode(e.toString()),r=new Request(t,{method:"POST",body:n});return r.headers.set("Content-Type","application/x-www-form-urlencoded"),r.headers.set("Accept","application/json"),r.headers.set("User-Agent","arctic"),r.headers.set("Content-Length",n.byteLength.toString()),r}function eo(t,e){const n=new TextEncoder().encode(`${t}:${e}`);return sk(n)}async function Ea(t){let e;try{e=await fetch(t)}catch(n){throw new Sp(n)}if(e.status===400||e.status===401){let n;try{n=await e.json()}catch{throw new Yr(e.status)}if(typeof n!="object"||n===null)throw new Gn(e.status,n);let r;try{r=xp(n)}catch{throw new Gn(e.status,n)}throw r}if(e.status===200){let n;try{n=await e.json()}catch{throw new Yr(e.status)}if(typeof n!="object"||n===null)throw new Gn(e.status,n);return new Zy(n)}throw e.body!==null&&await e.body.cancel(),new Yr(e.status)}async function gk(t){let e;try{e=await fetch(t)}catch(n){throw new Sp(n)}if(e.status===400||e.status===401){let n;try{n=await e.json()}catch{throw new Gn(e.status,null)}if(typeof n!="object"||n===null)throw new Gn(e.status,n);let r;try{r=xp(n)}catch{throw new Gn(e.status,n)}throw r}if(e.status===200){e.body!==null&&await e.body.cancel();return}throw e.body!==null&&await e.body.cancel(),new Yr(e.status)}function xp(t){let e;if("error"in t&&typeof t.error=="string")e=t.error;else throw new Error("Invalid error response");let n=null,r=null,i=null;if("error_description"in t){if(typeof t.error_description!="string")throw new Error("Invalid data");n=t.error_description}if("error_uri"in t){if(typeof t.error_uri!="string")throw new Error("Invalid data");r=t.error_uri}if("state"in t){if(typeof t.state!="string")throw new Error("Invalid data");i=t.state}return new mk(e,n,r,i)}class Sp extends Error{constructor(e){super("Failed to send request",{cause:e})}}class mk extends Error{constructor(n,r,i,s){super(`OAuth request error: ${n}`);ae(this,"code");ae(this,"description");ae(this,"uri");ae(this,"state");this.code=n,this.description=r,this.uri=i,this.state=s}}class Yr extends Error{constructor(n){super("Unexpected error response");ae(this,"status");this.status=n}}class Gn extends Error{constructor(n,r){super("Unexpected error response body");ae(this,"status");ae(this,"data");this.status=n,this.data=r}}class Fc{constructor(e,n,r){ae(this,"clientId");ae(this,"clientPassword");ae(this,"redirectURI");this.clientId=e,this.clientPassword=n,this.redirectURI=r}createAuthorizationURL(e,n,r){const i=new URL(e);return i.searchParams.set("response_type","code"),i.searchParams.set("client_id",this.clientId),this.redirectURI!==null&&i.searchParams.set("redirect_uri",this.redirectURI),i.searchParams.set("state",n),r.length>0&&i.searchParams.set("scope",r.join(" ")),i}createAuthorizationURLWithPKCE(e,n,r,i,s){const a=new URL(e);if(a.searchParams.set("response_type","code"),a.searchParams.set("client_id",this.clientId),this.redirectURI!==null&&a.searchParams.set("redirect_uri",this.redirectURI),a.searchParams.set("state",n),r===mi.S256){const c=fk(i);a.searchParams.set("code_challenge_method","S256"),a.searchParams.set("code_challenge",c)}else r===mi.Plain&&(a.searchParams.set("code_challenge_method","plain"),a.searchParams.set("code_challenge",i));return s.length>0&&a.searchParams.set("scope",s.join(" ")),a}async validateAuthorizationCode(e,n,r){const i=new URLSearchParams;i.set("grant_type","authorization_code"),i.set("code",n),this.redirectURI!==null&&i.set("redirect_uri",this.redirectURI),r!==null&&i.set("code_verifier",r),this.clientPassword===null&&i.set("client_id",this.clientId);const s=mr(e,i);if(this.clientPassword!==null){const c=eo(this.clientId,this.clientPassword);s.headers.set("Authorization",`Basic ${c}`)}return await Ea(s)}async refreshAccessToken(e,n,r){const i=new URLSearchParams;i.set("grant_type","refresh_token"),i.set("refresh_token",n),this.clientPassword===null&&i.set("client_id",this.clientId),r.length>0&&i.set("scope",r.join(" "));const s=mr(e,i);if(this.clientPassword!==null){const c=eo(this.clientId,this.clientPassword);s.headers.set("Authorization",`Basic ${c}`)}return await Ea(s)}async revokeToken(e,n){const r=new URLSearchParams;r.set("token",n),this.clientPassword===null&&r.set("client_id",this.clientId);const i=mr(e,r);if(this.clientPassword!==null){const s=eo(this.clientId,this.clientPassword);i.headers.set("Authorization",`Basic ${s}`)}await gk(i)}}var mi;(function(t){t[t.S256=0]="S256",t[t.Plain=1]="Plain"})(mi||(mi={}));var ag;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(ag||(ag={}));var cg;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(cg||(cg={}));function to(t){return _k(t,yk,Ca.None)}function _k(t,e,n){let r="";for(let i=0;i<t.byteLength;i+=3){let s=0,a=0;for(let c=0;c<3&&i+c<t.byteLength;c++)s=s<<8|t[i+c],a+=8;for(let c=0;c<4;c++)a>=6?(r+=e[s>>a-6&63],a-=6):a>0?(r+=e[s<<6-a&63],a=0):n===Ca.Include&&(r+="=")}return r}const yk="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";var Ca;(function(t){t[t.Include=0]="Include",t[t.None=1]="None"})(Ca||(Ca={}));var lg;(function(t){t[t.Required=0]="Required",t[t.Ignore=1]="Ignore"})(lg||(lg={}));function wk(t,e,n){const r=to(new TextEncoder().encode(t)),i=to(new TextEncoder().encode(e)),s=to(n);return r+"."+i+"."+s}function vk(t,e){const n=to(new TextEncoder().encode(t)),r=to(new TextEncoder().encode(e)),i=n+"."+r;return new TextEncoder().encode(i)}const bk="https://appleid.apple.com/auth/authorize",$k="https://appleid.apple.com/auth/token";class Qy{constructor(e,n,r,i,s){ae(this,"clientId");ae(this,"teamId");ae(this,"keyId");ae(this,"pkcs8PrivateKey");ae(this,"redirectURI");this.clientId=e,this.teamId=n,this.keyId=r,this.pkcs8PrivateKey=i,this.redirectURI=s}createAuthorizationURL(e,n){const r=new URL(bk);return r.searchParams.set("response_type","code"),r.searchParams.set("client_id",this.clientId),r.searchParams.set("state",e),n.length>0&&r.searchParams.set("scope",n.join(" ")),r.searchParams.set("redirect_uri",this.redirectURI),r}async validateAuthorizationCode(e){const n=new URLSearchParams;n.set("grant_type","authorization_code"),n.set("code",e),n.set("redirect_uri",this.redirectURI),n.set("client_id",this.clientId);const r=await this.createClientSecret();n.set("client_secret",r);const i=mr($k,n);return await Ea(i)}async createClientSecret(){const e=await crypto.subtle.importKey("pkcs8",this.pkcs8PrivateKey,{name:"ECDSA",namedCurve:"P-256"},!1,["sign"]),n=Math.floor(Date.now()/1e3),r=JSON.stringify({typ:"JWT",alg:"ES256",kid:this.keyId}),i=JSON.stringify({iss:this.teamId,exp:n+5*60,aud:["https://appleid.apple.com"],sub:this.clientId,iat:n}),s=new Uint8Array(await crypto.subtle.sign({name:"ECDSA",hash:"SHA-256"},e,vk(r,i)));return wk(r,i,s)}}const kk="https://www.facebook.com/v16.0/dialog/oauth",xk="https://graph.facebook.com/v16.0/oauth/access_token";class e1{constructor(e,n,r){ae(this,"clientId");ae(this,"clientSecret");ae(this,"redirectURI");this.clientId=e,this.clientSecret=n,this.redirectURI=r}createAuthorizationURL(e,n){const r=new URL(kk);return r.searchParams.set("response_type","code"),r.searchParams.set("client_id",this.clientId),r.searchParams.set("state",e),n.length>0&&r.searchParams.set("scope",n.join(" ")),r.searchParams.set("redirect_uri",this.redirectURI),r}async validateAuthorizationCode(e){const n=new URLSearchParams;n.set("grant_type","authorization_code"),n.set("code",e),n.set("redirect_uri",this.redirectURI),n.set("client_id",this.clientId),n.set("client_secret",this.clientSecret);const r=mr(xk,n);return await Ea(r)}}const Sk="https://github.com/login/oauth/authorize",dg="https://github.com/login/oauth/access_token";class t1{constructor(e,n,r){ae(this,"clientId");ae(this,"clientSecret");ae(this,"redirectURI");this.clientId=e,this.clientSecret=n,this.redirectURI=r}createAuthorizationURL(e,n){const r=new URL(Sk);return r.searchParams.set("response_type","code"),r.searchParams.set("client_id",this.clientId),r.searchParams.set("state",e),n.length>0&&r.searchParams.set("scope",n.join(" ")),this.redirectURI!==null&&r.searchParams.set("redirect_uri",this.redirectURI),r}async validateAuthorizationCode(e){const n=new URLSearchParams;n.set("grant_type","authorization_code"),n.set("code",e),this.redirectURI!==null&&n.set("redirect_uri",this.redirectURI);const r=mr(dg,n),i=eo(this.clientId,this.clientSecret);return r.headers.set("Authorization",`Basic ${i}`),await ug(r)}async refreshAccessToken(e){const n=new URLSearchParams;n.set("grant_type","refresh_token"),n.set("refresh_token",e);const r=mr(dg,n),i=eo(this.clientId,this.clientSecret);return r.headers.set("Authorization",`Basic ${i}`),await ug(r)}}async function ug(t){let e;try{e=await fetch(t)}catch(i){throw new Sp(i)}if(e.status!==200)throw e.body!==null&&await e.body.cancel(),new Yr(e.status);let n;try{n=await e.json()}catch{throw new Yr(e.status)}if(typeof n!="object"||n===null)throw new Gn(e.status,n);if("error"in n&&typeof n.error=="string"){let i;try{i=xp(n)}catch{throw new Gn(e.status,n)}throw i}return new Zy(n)}const zk="https://accounts.google.com/o/oauth2/v2/auth",pg="https://oauth2.googleapis.com/token",Ak="https://oauth2.googleapis.com/revoke";let n1=class{constructor(e,n,r){ae(this,"client");this.client=new Fc(e,n,r)}createAuthorizationURL(e,n,r){return this.client.createAuthorizationURLWithPKCE(zk,e,mi.S256,n,r)}async validateAuthorizationCode(e,n){return await this.client.validateAuthorizationCode(pg,e,n)}async refreshAccessToken(e){return await this.client.refreshAccessToken(pg,e,[])}async revokeToken(e){await this.client.revokeToken(Ak,e)}};class r1{constructor(e,n,r,i){ae(this,"authorizationEndpoint");ae(this,"tokenEndpoint");ae(this,"client");this.authorizationEndpoint=sg("https://login.microsoftonline.com",e,"/oauth2/v2.0/authorize"),this.tokenEndpoint=sg("https://login.microsoftonline.com",e,"/oauth2/v2.0/token"),this.client=new Fc(n,r,i)}createAuthorizationURL(e,n,r){return this.client.createAuthorizationURLWithPKCE(this.authorizationEndpoint,e,mi.S256,n,r)}async validateAuthorizationCode(e,n){return await this.client.validateAuthorizationCode(this.tokenEndpoint,e,n)}async refreshAccessToken(e,n){return await this.client.refreshAccessToken(this.tokenEndpoint,e,n)}}const Wo=o.z.object({iss:o.z.string().url(),sub:o.z.string(),aud:o.z.string(),exp:o.z.number(),email:o.z.string().optional(),given_name:o.z.string().optional(),family_name:o.z.string().optional(),name:o.z.string().optional(),iat:o.z.number(),auth_time:o.z.number().optional(),nonce:o.z.string().optional(),acr:o.z.string().optional(),amr:o.z.array(o.z.string()).optional(),azp:o.z.string().optional(),at_hash:o.z.string().optional(),c_hash:o.z.string().optional()}).passthrough();Wo.omit({iat:!0,auth_time:!0,nonce:!0,acr:!0,amr:!0,azp:!0,at_hash:!0,c_hash:!0});const Ek="Apple",Ck=({className:t=""})=>p("svg",{width:"45",height:"45",viewBox:"0 0 45 45",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:t,children:[p("path",{d:"M45 0H0V45H45V0Z",fill:"white"}),p("path",{d:"M23.5344 10.3846C25.5313 10.3846 28.0344 9.01144 29.525 7.18055C30.875 5.5213 31.8594 3.20407 31.8594 0.886839C31.8594 0.572154 31.8313 0.25747 31.775 0C29.5531 0.0858233 26.8813 1.51621 25.2781 3.43293C24.0125 4.89193 22.8594 7.18055 22.8594 9.52638C22.8594 9.86968 22.9156 10.213 22.9438 10.3274C23.0844 10.356 23.3094 10.3846 23.5344 10.3846ZM16.5031 45C19.2313 45 20.4406 43.1405 23.8438 43.1405C27.3031 43.1405 28.0625 44.9428 31.1 44.9428C34.0813 44.9428 36.0781 42.1392 37.9625 39.3929C40.0719 36.246 40.9438 33.1564 41 33.0134C40.8031 32.9561 35.0938 30.5817 35.0938 23.9161C35.0938 18.1373 39.5938 15.534 39.8469 15.3338C36.8656 10.9854 32.3375 10.8709 31.1 10.8709C27.7531 10.8709 25.025 12.9307 23.3094 12.9307C21.4531 12.9307 19.0063 10.9854 16.1094 10.9854C10.5969 10.9854 5 15.6198 5 24.3738C5 29.8093 7.08125 35.5594 9.64063 39.2784C11.8344 42.4253 13.7469 45 16.5031 45Z",fill:"black"})]});function i1(t){const{options:e}=t;if(!e||!e.client_id||!e.team_id||!e.kid||!e.app_secret)throw new Error("Missing required Apple authentication parameters");const n=Buffer.from(e.app_secret,"utf-8"),r=n.toString().replace(/-----BEGIN PRIVATE KEY-----|-----END PRIVATE KEY-----|\s/g,""),i=Uint8Array.from(Buffer.from(r,"base64"));return n.fill(0),{options:e,keyArray:i}}async function Nk(t,e){var d,u;const{options:n,keyArray:r}=i1(e),i=`${He(t.env)}callback`,s=new Qy(n.client_id,n.team_id,n.kid,r,i),a=Ne(),c=await s.createAuthorizationURL(a,((d=n.scope)==null?void 0:d.split(" "))||["name","email"]);return(((u=n.scope)==null?void 0:u.split(" "))||["name","email"]).some(f=>["email","name"].includes(f))&&c.searchParams.set("response_mode","form_post"),{redirectUrl:c.href,code:a}}async function Ik(t,e,n){const{options:r,keyArray:i}=i1(e),a=await new Qy(r.client_id,r.team_id,r.kid,i,`${He(t.env)}callback`).validateAuthorizationCode(n),c=Ua(a.idToken());if(!c)throw new Error("Invalid ID token");const l=Wo.parse(c.payload);return{sub:l.sub,email:l.email,given_name:l.given_name,family_name:l.family_name,name:l.name,picture:l.picture,locale:l.locale}}const o1=Object.freeze(Object.defineProperty({__proto__:null,displayName:Ek,getRedirect:Nk,logo:Ck,validateAuthorizationCodeAndGetUser:Ik},Symbol.toStringTag,{value:"Module"})),jk="Facebook",Ok=({className:t=""})=>p("svg",{width:"45",height:"45",viewBox:"0 0 45 45",xmlns:"http://www.w3.org/2000/svg",className:t,children:[p("path",{d:"M45 22.5C45 10.0736 34.9264 0 22.5 0C10.0736 0 0 10.0736 0 22.5C0 33.7031 8.23242 42.9785 19.0039 44.6953V28.9746H13.2861V22.5H19.0039V17.5391C19.0039 11.8945 22.3828 8.75977 27.5391 8.75977C29.9658 8.75977 32.5049 9.19922 32.5049 9.19922V14.7656H29.7012C26.9414 14.7656 26.0156 16.4824 26.0156 18.2432V22.5H32.2412L31.2012 28.9746H26.0156V44.6953C36.7871 42.9785 45 33.7031 45 22.5Z",fill:"#1877F2"}),p("path",{d:"M31.2012 28.9746L32.2412 22.5H26.0156V18.2432C26.0156 16.4824 26.9414 14.7656 29.7012 14.7656H32.5049V9.19922C32.5049 9.19922 29.9658 8.75977 27.5391 8.75977C22.3828 8.75977 19.0039 11.8945 19.0039 17.5391V22.5H13.2861V28.9746H19.0039V44.6953C20.1562 44.8984 21.3203 45 22.5 45C23.6797 45 24.8438 44.8984 26.0156 44.6953V28.9746H31.2012Z",fill:"white"})]});async function Tk(t,e){var c;const{options:n}=e;if(!(n!=null&&n.client_id)||!n.client_secret)throw new Error("Missing required authentication parameters");const r=`${He(t.env)}callback`,i=new e1(n.client_id,n.client_secret,r),s=Ne();return{redirectUrl:i.createAuthorizationURL(s,((c=n.scope)==null?void 0:c.split(" "))||["email"]).href,code:s}}async function Pk(t,e,n){const{options:r}=e;if(!(r!=null&&r.client_id)||!r.client_secret)throw new Error("Missing required authentication parameters");const s=await new e1(r.client_id,r.client_secret,`${He(t.env)}callback`).validateAuthorizationCode(n),a=await fetch("https://graph.facebook.com/v22.0/me?fields=id,email,name",{headers:{Authorization:`Bearer ${s.accessToken()}`}});if(!a.ok)throw new Error("Failed to fetch user info");const c=await a.json();return t.set("log",`Userinfo: ${JSON.stringify(c)}`),{sub:c.id,email:c.email,name:c.name}}const s1=Object.freeze(Object.defineProperty({__proto__:null,displayName:jk,getRedirect:Tk,logo:Ok,validateAuthorizationCodeAndGetUser:Pk},Symbol.toStringTag,{value:"Module"})),Rk="Google",Bk=({className:t=""})=>p("svg",{width:"45",height:"45",viewBox:"0 0 45 45",xmlns:"http://www.w3.org/2000/svg",className:t,children:[p("path",{d:"M44.1035 23.0123C44.1054 21.4791 43.9758 19.9486 43.716 18.4375H22.498V27.1028H34.6507C34.4021 28.4868 33.8757 29.8061 33.1034 30.9812C32.3311 32.1562 31.3289 33.1628 30.1571 33.9401V39.5649H37.41C41.6567 35.6494 44.1035 29.859 44.1035 23.0123Z",fill:"#4285F4"}),p("path",{d:"M22.4982 44.9997C28.5698 44.9997 33.6821 43.0061 37.4101 39.5687L30.1573 33.9439C28.1386 35.3126 25.5387 36.0938 22.4982 36.0938C16.6296 36.0938 11.6485 32.1377 9.86736 26.8066H2.39575V32.6033C4.26839 36.3297 7.13989 39.4622 10.6896 41.6512C14.2394 43.8402 18.3277 44.9995 22.4982 44.9997Z",fill:"#34A853"}),p("path",{d:"M9.86737 26.8073C8.92572 24.0138 8.92572 20.9886 9.86737 18.1951V12.3984H2.39576C0.820432 15.5332 0 18.9929 0 22.5012C0 26.0095 0.820432 29.4692 2.39576 32.604L9.86737 26.8073Z",fill:"#FBBC04"}),p("path",{d:"M22.4982 8.90741C25.7068 8.85499 28.8071 10.0673 31.1291 12.2823L37.5507 5.86064C33.4788 2.03602 28.0843 -0.0637686 22.4982 0.00147616C18.3277 0.00166623 14.2394 1.16098 10.6896 3.34999C7.13989 5.539 4.26839 8.67155 2.39575 12.3979L9.86736 18.1946C11.6485 12.8635 16.6296 8.90741 22.4982 8.90741Z",fill:"#EA4335"})]});async function Lk(t,e){var l;const{options:n}=e;if(!(n!=null&&n.client_id)||!n.client_secret)throw new Error("Missing required Google authentication parameters");const r=`${He(t.env)}callback`,i=new n1(n.client_id,n.client_secret,r),s=Ne(),a=Yy();return{redirectUrl:i.createAuthorizationURL(s,a,((l=n.scope)==null?void 0:l.split(" "))??["email","profile"]).href,code:s,codeVerifier:a}}async function Uk(t,e,n,r){const{options:i}=e;if(!(i!=null&&i.client_id)||!i.client_secret||!r)throw new Error("Missing required authentication parameters");const a=await new n1(i.client_id,i.client_secret,`${He(t.env)}callback`).validateAuthorizationCode(n,r),c=Ua(a.idToken());if(!c)throw new Error("Invalid ID token");const l=Wo.parse(c.payload);return{sub:l.sub,email:l.email,given_name:l.given_name,family_name:l.family_name,name:l.name,picture:l.picture,locale:l.locale}}const a1=Object.freeze(Object.defineProperty({__proto__:null,displayName:Rk,getRedirect:Lk,logo:Bk,validateAuthorizationCodeAndGetUser:Uk},Symbol.toStringTag,{value:"Module"})),Dk="Vipps",Mk=({className:t=""})=>p("svg",{version:"1.1",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 48 48",width:"45",height:"45",className:t,children:[p("path",{fill:"#FF5B24",d:"M3.5,8h41c1.9,0,3.5,1.6,3.5,3.5v25c0,1.9-1.6,3.5-3.5,3.5h-41C1.6,40,0,38.4,0,36.5v-25C0,9.6,1.6,8,3.5,8z"}),p("path",{fillRule:"evenodd",clipRule:"evenodd",fill:"#FFFFFF",d:`M27.9,20.3c1.4,0,2.6-1,2.6-2.5h0c0-1.5-1.2-2.5-2.6-2.5c-1.4,0-2.6,1-2.6,2.5C25.3,19.2,26.5,20.3,27.9,20.3z
193
193
  M31.2,24.4c-1.7,2.2-3.5,3.8-6.7,3.8h0c-3.2,0-5.8-2-7.7-4.8c-0.8-1.2-2-1.4-2.9-0.8c-0.8,0.6-1,1.8-0.3,2.9
194
- c2.7,4.1,6.5,6.6,10.9,6.6c4,0,7.2-2,9.6-5.2c0.9-1.2,0.9-2.5,0-3.1C33.3,22.9,32.1,23.2,31.2,24.4z`})]});async function Fk(t,e){var a;const{options:n}=e;if(!(n!=null&&n.client_id)||!n.client_secret)throw new Error("Missing required authentication parameters");const r=new Fc(n.client_id,n.client_secret,`${He(t.env)}callback`),i=Ne(),s=r.createAuthorizationURL("https://api.vipps.no/access-management-1.0/access/oauth2/auth",i,((a=n.scope)==null?void 0:a.split(" "))||["openid","email","phoneNumber","name","address","birthDate"]);return s.searchParams.set("response_type","code"),s.searchParams.set("response_mode","query"),{redirectUrl:s.href,code:i}}async function qk(t,e,n){const{options:r}=e;if(!(r!=null&&r.client_id)||!r.client_secret)throw new Error("Missing required authentication parameters");const s=await new Fc(r.client_id,r.client_secret,`${He(t.env)}callback`).validateAuthorizationCode("https://api.vipps.no/access-management-1.0/access/oauth2/token",n,null),a=Ua(s.idToken());if(!a)throw new Error("Invalid ID token");const c=Wo.parse(a.payload);if(typeof c.msn!="string")throw new Error("msn not available in id token");const l=await fetch("https://api.vipps.no/vipps-userinfo-api/userinfo",{headers:{Authorization:`Bearer ${s.accessToken()}`,"Merchant-Serial-Number":c.msn}});if(!l.ok)throw new ee(400,{message:"Failed to get user from vipps"});return await l.json()}const c1=Object.freeze(Object.defineProperty({__proto__:null,displayName:Dk,getRedirect:Fk,logo:Mk,validateAuthorizationCodeAndGetUser:qk},Symbol.toStringTag,{value:"Module"})),Hk="GitHub",Vk=({className:t=""})=>p("svg",{width:"45",height:"45",viewBox:"0 0 45 45",xmlns:"http://www.w3.org/2000/svg",className:t,children:p("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M22.5 0C10.074 0 0 10.335 0 23.077C0 33.266 6.444 41.895 15.39 44.955C16.515 45.165 16.935 44.46 16.935 43.857C16.935 43.32 16.92 41.865 16.905 39.99C10.65 41.355 9.33 36.99 9.33 36.99C8.31 34.32 6.825 33.615 6.825 33.615C4.77 32.205 6.975 32.235 6.975 32.235C9.24 32.385 10.425 34.59 10.425 34.59C12.45 38.13 15.75 37.125 17.01 36.555C17.22 35.07 17.82 34.065 18.48 33.51C13.455 32.94 8.19 30.93 8.19 22.035C8.19 19.5 9.075 17.43 10.47 15.81C10.23 15.24 9.435 12.87 10.695 9.66C10.695 9.66 12.585 9.045 16.875 12.06C18.675 11.565 20.595 11.31 22.5 11.31C24.405 11.31 26.325 11.565 28.125 12.06C32.415 9.045 34.305 9.66 34.305 9.66C35.565 12.87 34.77 15.24 34.53 15.81C35.925 17.43 36.81 19.5 36.81 22.035C36.81 30.96 31.53 32.925 26.49 33.48C27.33 34.2 28.095 35.625 28.095 37.815C28.095 40.95 28.065 43.47 28.065 43.857C28.065 44.46 28.485 45.18 29.625 44.955C38.571 41.88 45 33.252 45 23.077C45 10.335 34.926 0 22.5 0Z",fill:"currentColor"})});async function Kk(t,e){var c;const{options:n}=e;if(!(n!=null&&n.client_id)||!n.client_secret)throw new Error("Missing required GitHub authentication parameters");const r=`${He(t.env)}callback`,i=new t1(n.client_id,n.client_secret,r),s=Ne();return{redirectUrl:i.createAuthorizationURL(s,((c=n.scope)==null?void 0:c.split(" "))||["user:email"]).href,code:s}}async function Gk(t,e,n){var u,f;const{options:r}=e;if(!(r!=null&&r.client_id)||!r.client_secret)throw new Error("Missing required authentication parameters");const s=await new t1(r.client_id,r.client_secret,`${He(t.env)}callback`).validateAuthorizationCode(n),a=await fetch("https://api.github.com/user",{headers:{Authorization:`Bearer ${s.accessToken()}`,"User-Agent":"AuthHero"}});if(!a.ok)throw new Error("Failed to fetch user info");const c=await a.json(),l=await fetch("https://api.github.com/user/emails",{headers:{Authorization:`Bearer ${s.accessToken()}`,"User-Agent":"AuthHero"}});let d=c.email;if(l.ok){const h=await l.json(),m=h.find(y=>y.primary&&y.verified)||h.find(y=>y.verified);m&&(d=m.email)}return t.set("log",`GitHub user: ${JSON.stringify(c)}`),{sub:c.id.toString(),email:d,name:c.name,given_name:(u=c.name)==null?void 0:u.split(" ")[0],family_name:(f=c.name)==null?void 0:f.split(" ").slice(1).join(" "),picture:c.avatar_url}}const l1=Object.freeze(Object.defineProperty({__proto__:null,displayName:Hk,getRedirect:Kk,logo:Vk,validateAuthorizationCodeAndGetUser:Gk},Symbol.toStringTag,{value:"Module"})),Wk="Microsoft",Jk=({className:t=""})=>p("svg",{width:"45",height:"45",viewBox:"0 0 45 45",xmlns:"http://www.w3.org/2000/svg",className:t,children:[p("path",{fill:"#F25022",d:"M0 0H21.43V21.43H0V0Z"}),p("path",{fill:"#7FBA00",d:"M23.57 0H45V21.43H23.57V0Z"}),p("path",{fill:"#00A4EF",d:"M0 23.57H21.43V45H0V23.57Z"}),p("path",{fill:"#FFB900",d:"M23.57 23.57H45V45H23.57V23.57Z"})]});async function Xk(t,e){var d;const{options:n}=e;if(!(n!=null&&n.client_id)||!n.client_secret)throw new Error("Missing required Microsoft authentication parameters");const r=`${He(t.env)}callback`,i=n.realms||"common",s=new r1(i,n.client_id,n.client_secret,r),a=Ne(),c=Yy();return{redirectUrl:s.createAuthorizationURL(a,c,((d=n.scope)==null?void 0:d.split(" "))||["openid","profile","email"]).href,code:a,codeVerifier:c}}async function Zk(t,e,n,r){const{options:i}=e;if(!(i!=null&&i.client_id)||!i.client_secret||!r)throw new Error("Missing required authentication parameters");const s=i.realms||"common",c=await new r1(s,i.client_id,i.client_secret,`${He(t.env)}callback`).validateAuthorizationCode(n,r),l=Ua(c.idToken());if(!l)throw new Error("Invalid ID token");const d=Wo.parse(l.payload);return t.set("log",`Microsoft user: ${JSON.stringify(d)}`),{sub:d.sub,email:d.email,given_name:d.given_name,family_name:d.family_name,name:d.name,picture:d.picture}}const d1=Object.freeze(Object.defineProperty({__proto__:null,displayName:Wk,getRedirect:Xk,logo:Jk,validateAuthorizationCodeAndGetUser:Zk},Symbol.toStringTag,{value:"Module"}));function u1(t,e){const n=t.env.STRATEGIES||{},i={apple:o1,facebook:s1,"google-oauth2":a1,vipps:c1,github:l1,microsoft:d1,...n}[e];if(!i)throw new Error(`Strategy ${e} not found`);return i}function p1(t){return{apple:o1,facebook:s1,"google-oauth2":a1,vipps:c1,github:l1,microsoft:d1}[t]}async function Oi(t,e){const n=await t.data.legacyClients.get(e);if(!n)throw new ee(403,{message:"Client not found"});let r=n;if(t.DEFAULT_CLIENT_ID||t.DEFAULT_TENANT_ID){const i=t.DEFAULT_CLIENT_ID?await t.data.legacyClients.get(t.DEFAULT_CLIENT_ID):void 0,s=await t.data.connections.list(n.tenant.id),a=t.DEFAULT_TENANT_ID?await t.data.connections.list(t.DEFAULT_TENANT_ID):{connections:[]},c=s.connections.map(l=>{var f;const d=(f=a.connections)==null?void 0:f.find(h=>h.name===l.name);if(!(d!=null&&d.options))return l;const u=Kt.parse({...d||{},...l});return u.options=Wr.passthrough().parse({...d.options||{},...l.options}),u}).filter(l=>l);r={...n,web_origins:[...(i==null?void 0:i.web_origins)||[],...n.web_origins||[]],allowed_logout_urls:[...(i==null?void 0:i.allowed_logout_urls)||[],...n.allowed_logout_urls||[]],callbacks:[...(i==null?void 0:i.callbacks)||[],...n.callbacks||[]],connections:c,tenant:{...(i==null?void 0:i.tenant)||{},...n.tenant}}}return{...r,web_origins:[...r.web_origins||[],`${st(t)}login`],allowed_logout_urls:[...r.allowed_logout_urls||[],t.ISSUER],callbacks:[...r.callbacks||[],`${st(t)}info`]}}async function fg(t,e,n,r){if(!r.state)throw new ee(400,{message:"State not found"});const i=e.connections.find(l=>l.name===n);if(!i){t.set("client_id",e.client_id);const l=be(t,{type:_e.FAILED_LOGIN,description:"Connection not found"});throw ve(t,t.env.data.logs.create(e.tenant.id,l)),new ee(403,{message:"Connection Not Found"})}let s=await t.env.data.loginSessions.get(e.tenant.id,r.state);if(!s){const l=t.get("ip"),d=t.get("useragent"),u=t.get("auth0_client");s=await t.env.data.loginSessions.create(e.tenant.id,{expires_at:new Date(Date.now()+_r*1e3).toISOString(),authParams:r,csrf_token:Ne(),ip:l,useragent:d,auth0Client:Nn(u)})}const c=await u1(t,i.strategy).getRedirect(t,i);return await t.env.data.codes.create(e.tenant.id,{login_id:s.id,code_id:c.code,code_type:"oauth2_state",connection_id:i.id,code_verifier:c.codeVerifier,expires_at:new Date(Date.now()+Sv*1e3).toISOString()}),new Response(null,{status:302,headers:{location:c.redirectUrl}})}async function hg(t,{code:e,state:n}){var y;const{env:r}=t,i=await r.data.codes.get(t.var.tenant_id||"",n,"oauth2_state");if(!i||!i.connection_id)throw new ee(403,{message:"State not found"});const s=await r.data.loginSessions.get(t.var.tenant_id||"",i.login_id);if(!s)throw new ee(403,{message:"Session not found"});if(s.authorization_url){const v=new URL(s.authorization_url).hostname,b=t.var.host||"";if(v!==b&&v){const A=new URL(`https://${v}/callback`);return A.searchParams.set("state",n),A.searchParams.set("code",e),new Response("Redirecting",{status:307,headers:{location:A.toString()}})}}const a=await Oi(r,s.authParams.client_id);t.set("client_id",a.client_id),t.set("tenant_id",a.tenant.id);const c=a.connections.find(v=>v.id===i.connection_id);if(!c){const v=be(t,{type:_e.FAILED_LOGIN,description:"Connection not found"});throw ve(t,r.data.logs.create(a.tenant.id,v)),new ee(403,{message:"Connection not found"})}if(t.set("connection",c.name),!s.authParams.redirect_uri){const v=be(t,{type:_e.FAILED_LOGIN,description:"Redirect URI not defined"});throw ve(t,r.data.logs.create(a.tenant.id,v)),new ee(403,{message:"Redirect URI not defined"})}const d=await u1(t,c.strategy).validateAuthorizationCodeAndGetUser(t,c,e,i.code_verifier),{sub:u,...f}=d;t.set("user_id",u);const h=((y=d.email)==null?void 0:y.toLocaleLowerCase())||`${c.name}.${u}@${new URL(t.env.ISSUER).hostname}`;t.set("username",h);const m=await qa(t,{client:a,username:h,provider:c.strategy,connection:c.name,userId:u,profileData:f,isSocial:!0,ip:t.var.ip});return un(t,{client:a,authParams:s.authParams,loginSession:s,user:m,strategy:c.strategy})}async function gg(t,e,n,r,i,s){const a=await t.env.data.codes.get(t.var.tenant_id||"",e,"oauth2_state");if(!a)throw new S(400,{message:"State not found"});const c=await t.env.data.loginSessions.get(t.var.tenant_id,a.login_id);if(!c)throw new S(400,{message:"Login not found"});const{redirect_uri:l}=c.authParams;if(!l)throw new S(400,{message:"Redirect uri not found"});const d=be(t,{type:_e.FAILED_LOGIN,description:`Failed connection login: ${i} ${n}, ${r}`});ve(t,t.env.data.logs.create(t.var.tenant_id,d));const u=new URL(l);return q4(u,{error:n,error_description:r,error_reason:s,error_code:i,state:c.authParams.state}),t.redirect(`${st(t.env)}login/identifier?state=${c.id}&error=${n}`)}const Yk=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth2"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string(),code:o.z.string().optional(),scope:o.z.string().optional(),hd:o.z.string().optional(),error:o.z.string().optional(),error_description:o.z.string().optional(),error_code:o.z.string().optional(),error_reason:o.z.string().optional()})},responses:{302:{description:"Redirect to the client's redirect uri"},400:{description:"Bad Request",content:{"application/json":{schema:o.z.object({message:o.z.string()})}}},500:{description:"Internal Server Error",content:{"application/json":{schema:o.z.object({message:o.z.string()})}}}}}),async t=>{const{state:e,code:n,error:r,error_description:i,error_code:s,error_reason:a}=t.req.valid("query");if(r)return gg(t,e,r,i,s,a);if(!n)throw new S(400,{message:"Code is required"});const c=await hg(t,{code:n,state:e});if(!(c instanceof Response))throw new S(500,{message:"Internal server error"});return c}).openapi(o.createRoute({tags:["oauth2"],method:"post",path:"/",request:{body:{content:{"application/x-www-form-urlencoded":{schema:o.z.object({state:o.z.string(),code:o.z.string().optional(),scope:o.z.string().optional(),hd:o.z.string().optional(),error:o.z.string().optional(),error_description:o.z.string().optional(),error_code:o.z.string().optional(),error_reason:o.z.string().optional()})}}}},responses:{302:{description:"Redirect to the client's redirect uri"},400:{description:"Bad Request",content:{"application/json":{schema:o.z.object({message:o.z.string()})}}},500:{description:"Internal Server Error",content:{"application/json":{schema:o.z.object({message:o.z.string()})}}}}}),async t=>{const{state:e,code:n,error:r,error_description:i,error_code:s,error_reason:a}=t.req.valid("form");if(r)return gg(t,e,r,i,s,a);if(!n)throw new S(400,{message:"Code is required"});const c=await hg(t,{code:n,state:e});if(!(c instanceof Response))throw new S(500,{message:"Internal server error"});return c});function zp(t,e=[],n={}){try{const r=new URL(t);return e.some(i=>{try{return Qk(r,new URL(i),n)}catch{return!1}})}catch{return!1}}function Qk(t,e,n={}){if(t.protocol!==e.protocol)return!1;if(n.allowPathWildcards&&e.pathname.includes("*")){const r=e.pathname.replace(/\*/g,".*").replace(/\//g,"\\/");if(!new RegExp(`^${r}$`).test(t.pathname))return!1}else if(t.pathname!==e.pathname)return!1;if(n.allowSubDomainWildcards&&e.hostname.startsWith("*.")&&e.hostname.split(".").length>2&&["http:","https:"].includes(e.protocol)){const r=e.hostname.split(".").slice(1).join(".");return t.hostname===r||t.hostname.endsWith("."+r)}return t.hostname===e.hostname}const e5=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth2"],method:"get",path:"/",request:{query:o.z.object({client_id:o.z.string(),returnTo:o.z.string().optional()}),header:o.z.object({cookie:o.z.string().optional()})},responses:{302:{description:"Log the user out"}}}),async t=>{const{client_id:e,returnTo:n}=t.req.valid("query"),r=await t.env.data.legacyClients.get(e);if(!r)return t.text("OK");const i=await t.env.data.legacyClients.get("DEFAULT_CLIENT");t.set("client_id",e),t.set("tenant_id",r.tenant.id);const s=n||t.req.header("referer");if(!s)return t.text("OK");if(!zp(s,[...r.allowed_logout_urls||[],...(i==null?void 0:i.allowed_logout_urls)||[]],{allowPathWildcards:!0,allowSubDomainWildcards:!0}))throw new S(400,{message:"Invalid redirect uri"});const a=t.req.header("cookie");if(a){const l=ni(r.tenant.id,a);if(l){const d=await t.env.data.sessions.get(r.tenant.id,l);if(d){const u=await t.env.data.users.get(r.tenant.id,d.user_id);u&&(t.set("user_id",u.user_id),t.set("connection",u.connection));const f=await t.env.data.refreshTokens.list(r.tenant.id,{q:`session_id=${l}`,page:0,per_page:100,include_totals:!1});await Promise.all(f.refresh_tokens.map(h=>t.env.data.refreshTokens.remove(r.tenant.id,h.id))),await t.env.data.sessions.update(r.tenant.id,l,{revoked_at:new Date().toISOString()})}}}const c=be(t,{type:_e.SUCCESS_LOGOUT,description:"User successfully logged out"});return ve(t,t.env.data.logs.create(r.tenant.id,c)),new Response("Redirecting",{status:302,headers:{"set-cookie":Nv(r.tenant.id,t.req.header("host")),location:s}})}),mg=o.z.object({sub:o.z.string(),email:o.z.string().optional(),family_name:o.z.string().optional(),given_name:o.z.string().optional(),email_verified:o.z.boolean()}),t5=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth2"],method:"get",path:"/",request:{},security:[{Bearer:["openid"]}],responses:{200:{content:{"application/json":{schema:mg}},description:"Userinfo"}}}),async t=>{if(!t.var.user)throw new S(404,{message:"User not found"});const e=await t.env.data.users.get(t.var.user.tenant_id,t.var.user.sub);if(!e)throw new S(404,{message:"User not found"});return t.json(mg.parse({...e,sub:e.user_id}))}),n5=new o.OpenAPIHono().openapi(o.createRoute({tags:["well known"],method:"get",path:"/jwks.json",request:{},responses:{200:{content:{"application/json":{schema:D0}},description:"List of tenants"}}}),async t=>{const e=await Qd(t.env.data);return t.json({keys:e},{headers:{"access-control-allow-origin":"*","access-control-allow-method":"GET","cache-control":`public, max-age=${rs}, stale-while-revalidate=${rs*2}, stale-if-error=86400`}})}).openapi(o.createRoute({tags:["well known"],method:"get",path:"/openid-configuration",request:{},responses:{200:{content:{"application/json":{schema:xl}},description:"List of tenants"}}}),async t=>{const e=xl.parse({issuer:Bc(t.env),authorization_endpoint:`${He(t.env)}authorize`,token_endpoint:`${He(t.env)}oauth/token`,device_authorization_endpoint:`${He(t.env)}oauth/device/code`,userinfo_endpoint:`${He(t.env)}userinfo`,mfa_challenge_endpoint:`${He(t.env)}mfa/challenge`,jwks_uri:`${He(t.env)}.well-known/jwks.json`,registration_endpoint:`${He(t.env)}oidc/register`,revocation_endpoint:`${He(t.env)}oauth/revoke`,scopes_supported:["openid","profile","offline_access","name","given_name","family_name","nickname","email","email_verified","picture","created_at","identities","phone","address"],response_types_supported:["code","token","id_token","code token","code id_token","token id_token","code token id_token"],code_challenge_methods_supported:["S256","plain"],response_modes_supported:["query","fragment","form_post"],subject_types_supported:["public"],id_token_signing_alg_values_supported:["RS256"],token_endpoint_auth_methods_supported:["client_secret_basic","client_secret_post"],claims_supported:["aud","auth_time","created_at","email","email_verified","exp","family_name","given_name","iat","identities","iss","name","nickname","phone_number","picture","sub"],request_uri_parameter_supported:!1,request_parameter_supported:!1,token_endpoint_auth_signing_alg_values_supported:["RS256","RS384","PS256"]});return t.json(e,{headers:{"access-control-allow-origin":"*","access-control-allow-method":"GET","cache-control":`public, max-age=${rs}, stale-while-revalidate=${rs*2}, stale-if-error=86400`}})});function $s(t,e){if(!t||!e||t.length!==e.length)return!1;let n=0;for(let r=0;r<t.length;r++)n|=t.charCodeAt(r)^e.charCodeAt(r);return n===0}const f1=o.z.object({grant_type:o.z.literal("client_credentials"),scope:o.z.string().optional(),client_secret:o.z.string(),client_id:o.z.string(),audience:o.z.string().optional()});async function r5(t,e){const n=await t.env.data.legacyClients.get(e.client_id);if(!n)throw new ee(403,{message:"Invalid client credentials"});if(n.client_secret&&!$s(n.client_secret,e.client_secret))throw new ee(403,{message:"Invalid client credentials"});const r={client_id:n.client_id,scope:e.scope,audience:e.audience};return{client:n,authParams:r}}const i5=o.z.object({grant_type:o.z.literal("authorization_code"),client_id:o.z.string(),code:o.z.string(),redirect_uri:o.z.string().optional(),client_secret:o.z.string().optional(),code_verifier:o.z.string().optional(),organization:o.z.string().optional()}).refine(t=>"client_secret"in t&&!("code_verifier"in t)||!("client_secret"in t)&&"code_verifier"in t,{message:"Must provide either client_secret (standard flow) or code_verifier/code_verifier_mode (PKCE flow), but not both"});async function o5(t,e){var l;const n=await t.env.data.legacyClients.get(e.client_id);if(!n)throw new ee(403,{message:"Client not found"});const r=await t.env.data.codes.get(n.tenant.id,e.code,"authorization_code");if(!r||!r.user_id){const d=be(t,{type:_e.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid client credentials"});throw ve(t,t.env.data.logs.create(n.tenant.id,d)),new ee(403,{message:"Invalid client credentials"})}else if(new Date(r.expires_at)<new Date){const d=be(t,{type:_e.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Code expired",userId:r.user_id});throw ve(t,t.env.data.logs.create(n.tenant.id,d)),new ee(403,{message:"Code expired"})}else if(r.used_at){const d=be(t,{type:_e.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid authorization code",userId:r.user_id});throw ve(t,t.env.data.logs.create(n.tenant.id,d)),new ee(403,{error:"invalid_grant",error_description:"Invalid authorization code"})}const i=await t.env.data.loginSessions.get(n.tenant.id,r.login_id);if(!i)throw new ee(403,{message:"Invalid login"});if(e.organization&&i.authParams.organization&&e.organization!==i.authParams.organization)throw new ee(400,{error:"invalid_request",error_description:"Organization parameter does not match login session organization"});if("client_secret"in e){const d=await t.env.data.legacyClients.get("DEFAULT_CLIENT");if(!$s(n.client_secret,e.client_secret)&&!$s(d==null?void 0:d.client_secret,e.client_secret)){const u=be(t,{type:_e.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid client credentials",userId:r.user_id});throw ve(t,t.env.data.logs.create(n.tenant.id,u)),new ee(403,{message:"Invalid client credentials"})}}else if(r.code_challenge&&r.code_challenge_method&&e.code_verifier){const d=await $v(e.code_verifier,r.code_challenge_method);if(!$s(d,r.code_challenge)){const u=be(t,{type:_e.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid client credentials",userId:r.user_id});throw ve(t,t.env.data.logs.create(n.tenant.id,u)),new ee(403,{message:"Invalid client credentials"})}}if(r.redirect_uri&&r.redirect_uri!==e.redirect_uri){const d=be(t,{type:_e.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid redirect uri",userId:r.user_id});throw ve(t,t.env.data.logs.create(n.tenant.id,d)),new ee(403,{message:"Invalid redirect uri"})}const s=await t.env.data.users.get(n.tenant.id,r.user_id);if(!s)throw new ee(403,{message:"User not found"});await t.env.data.codes.used(n.tenant.id,e.code);let a;i.session_id&&((l=i.authParams.scope)!=null&&l.split(" ").includes("offline_access"))&&(a=await Tm(t,{user:s,client:n,session_id:i.session_id,scope:i.authParams.scope,audience:i.authParams.audience}));let c;if(i.authParams.organization){const d=await t.env.data.organizations.get(n.tenant.id,i.authParams.organization);d?c={id:d.id,name:d.name}:c={id:i.authParams.organization,name:"Unknown"}}return{user:s,client:n,loginSession:i,session_id:i.session_id,refresh_token:a==null?void 0:a.id,organization:c,authParams:{...i.authParams,state:r.state,nonce:r.nonce,response_mode:Wt.WEB_MESSAGE,client_id:n.client_id,scope:i.authParams.scope,audience:i.authParams.audience}}}const s5=o.z.object({grant_type:o.z.literal("refresh_token"),client_id:o.z.string(),redirect_uri:o.z.string().optional(),refresh_token:o.z.string()});async function a5(t,e){const n=await t.env.data.legacyClients.get(e.client_id);if(!n)throw new ee(403,{message:"Client not found"});const r=await t.env.data.refreshTokens.get(n.tenant.id,e.refresh_token);if(r){if(r.expires_at&&new Date(r.expires_at)<new Date||r.idle_expires_at&&new Date(r.idle_expires_at)<new Date)throw new ee(403,{error:"invalid_grant",error_description:"Refresh token has expired"})}else throw new ee(403,{error:"invalid_grant",error_description:"Invalid refresh token"});const i=await t.env.data.users.get(n.tenant.id,r.user_id);if(!i)throw new ee(403,{message:"User not found"});const s=r.resource_servers[0];if(r.idle_expires_at){const a=new Date(Date.now()+2592e6);await t.env.data.refreshTokens.update(n.tenant.id,r.id,{idle_expires_at:a.toISOString(),last_exchanged_at:new Date().toISOString(),device:{...r.device,last_ip:t.req.header["x-real-ip"]||"",last_user_agent:t.req.header["user-agent"]||""}})}return{user:i,client:n,refresh_token:r.id,session_id:r.session_id,authParams:{client_id:n.client_id,audience:s==null?void 0:s.audience,scope:s==null?void 0:s.scopes,response_mode:Wt.WEB_MESSAGE}}}const c5={version:4,country_calling_codes:{1:["US","AG","AI","AS","BB","BM","BS","CA","DM","DO","GD","GU","JM","KN","KY","LC","MP","MS","PR","SX","TC","TT","VC","VG","VI"],7:["RU","KZ"],20:["EG"],27:["ZA"],30:["GR"],31:["NL"],32:["BE"],33:["FR"],34:["ES"],36:["HU"],39:["IT","VA"],40:["RO"],41:["CH"],43:["AT"],44:["GB","GG","IM","JE"],45:["DK"],46:["SE"],47:["NO","SJ"],48:["PL"],49:["DE"],51:["PE"],52:["MX"],53:["CU"],54:["AR"],55:["BR"],56:["CL"],57:["CO"],58:["VE"],60:["MY"],61:["AU","CC","CX"],62:["ID"],63:["PH"],64:["NZ"],65:["SG"],66:["TH"],81:["JP"],82:["KR"],84:["VN"],86:["CN"],90:["TR"],91:["IN"],92:["PK"],93:["AF"],94:["LK"],95:["MM"],98:["IR"],211:["SS"],212:["MA","EH"],213:["DZ"],216:["TN"],218:["LY"],220:["GM"],221:["SN"],222:["MR"],223:["ML"],224:["GN"],225:["CI"],226:["BF"],227:["NE"],228:["TG"],229:["BJ"],230:["MU"],231:["LR"],232:["SL"],233:["GH"],234:["NG"],235:["TD"],236:["CF"],237:["CM"],238:["CV"],239:["ST"],240:["GQ"],241:["GA"],242:["CG"],243:["CD"],244:["AO"],245:["GW"],246:["IO"],247:["AC"],248:["SC"],249:["SD"],250:["RW"],251:["ET"],252:["SO"],253:["DJ"],254:["KE"],255:["TZ"],256:["UG"],257:["BI"],258:["MZ"],260:["ZM"],261:["MG"],262:["RE","YT"],263:["ZW"],264:["NA"],265:["MW"],266:["LS"],267:["BW"],268:["SZ"],269:["KM"],290:["SH","TA"],291:["ER"],297:["AW"],298:["FO"],299:["GL"],350:["GI"],351:["PT"],352:["LU"],353:["IE"],354:["IS"],355:["AL"],356:["MT"],357:["CY"],358:["FI","AX"],359:["BG"],370:["LT"],371:["LV"],372:["EE"],373:["MD"],374:["AM"],375:["BY"],376:["AD"],377:["MC"],378:["SM"],380:["UA"],381:["RS"],382:["ME"],383:["XK"],385:["HR"],386:["SI"],387:["BA"],389:["MK"],420:["CZ"],421:["SK"],423:["LI"],500:["FK"],501:["BZ"],502:["GT"],503:["SV"],504:["HN"],505:["NI"],506:["CR"],507:["PA"],508:["PM"],509:["HT"],590:["GP","BL","MF"],591:["BO"],592:["GY"],593:["EC"],594:["GF"],595:["PY"],596:["MQ"],597:["SR"],598:["UY"],599:["CW","BQ"],670:["TL"],672:["NF"],673:["BN"],674:["NR"],675:["PG"],676:["TO"],677:["SB"],678:["VU"],679:["FJ"],680:["PW"],681:["WF"],682:["CK"],683:["NU"],685:["WS"],686:["KI"],687:["NC"],688:["TV"],689:["PF"],690:["TK"],691:["FM"],692:["MH"],850:["KP"],852:["HK"],853:["MO"],855:["KH"],856:["LA"],880:["BD"],886:["TW"],960:["MV"],961:["LB"],962:["JO"],963:["SY"],964:["IQ"],965:["KW"],966:["SA"],967:["YE"],968:["OM"],970:["PS"],971:["AE"],972:["IL"],973:["BH"],974:["QA"],975:["BT"],976:["MN"],977:["NP"],992:["TJ"],993:["TM"],994:["AZ"],995:["GE"],996:["KG"],998:["UZ"]},countries:{AC:["247","00","(?:[01589]\\d|[46])\\d{4}",[5,6]],AD:["376","00","(?:1|6\\d)\\d{7}|[135-9]\\d{5}",[6,8,9],[["(\\d{3})(\\d{3})","$1 $2",["[135-9]"]],["(\\d{4})(\\d{4})","$1 $2",["1"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["6"]]]],AE:["971","00","(?:[4-7]\\d|9[0-689])\\d{7}|800\\d{2,9}|[2-4679]\\d{7}",[5,6,7,8,9,10,11,12],[["(\\d{3})(\\d{2,9})","$1 $2",["60|8"]],["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["[236]|[479][2-8]"],"0$1"],["(\\d{3})(\\d)(\\d{5})","$1 $2 $3",["[479]"]],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["5"],"0$1"]],"0"],AF:["93","00","[2-7]\\d{8}",[9],[["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[2-7]"],"0$1"]],"0"],AG:["1","011","(?:268|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([457]\\d{6})$|1","268$1",0,"268"],AI:["1","011","(?:264|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2457]\\d{6})$|1","264$1",0,"264"],AL:["355","00","(?:700\\d\\d|900)\\d{3}|8\\d{5,7}|(?:[2-5]|6\\d)\\d{7}",[6,7,8,9],[["(\\d{3})(\\d{3,4})","$1 $2",["80|9"],"0$1"],["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["4[2-6]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[2358][2-5]|4"],"0$1"],["(\\d{3})(\\d{5})","$1 $2",["[23578]"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["6"],"0$1"]],"0"],AM:["374","00","(?:[1-489]\\d|55|60|77)\\d{6}",[8],[["(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3",["[89]0"],"0 $1"],["(\\d{3})(\\d{5})","$1 $2",["2|3[12]"],"(0$1)"],["(\\d{2})(\\d{6})","$1 $2",["1|47"],"(0$1)"],["(\\d{2})(\\d{6})","$1 $2",["[3-9]"],"0$1"]],"0"],AO:["244","00","[29]\\d{8}",[9],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[29]"]]]],AR:["54","00","(?:11|[89]\\d\\d)\\d{8}|[2368]\\d{9}",[10,11],[["(\\d{4})(\\d{2})(\\d{4})","$1 $2-$3",["2(?:2[024-9]|3[0-59]|47|6[245]|9[02-8])|3(?:3[28]|4[03-9]|5[2-46-8]|7[1-578]|8[2-9])","2(?:[23]02|6(?:[25]|4[6-8])|9(?:[02356]|4[02568]|72|8[23]))|3(?:3[28]|4(?:[04679]|3[5-8]|5[4-68]|8[2379])|5(?:[2467]|3[237]|8[2-5])|7[1-578]|8(?:[2469]|3[2578]|5[4-8]|7[36-8]|8[5-8]))|2(?:2[24-9]|3[1-59]|47)","2(?:[23]02|6(?:[25]|4(?:64|[78]))|9(?:[02356]|4(?:[0268]|5[2-6])|72|8[23]))|3(?:3[28]|4(?:[04679]|3[78]|5(?:4[46]|8)|8[2379])|5(?:[2467]|3[237]|8[23])|7[1-578]|8(?:[2469]|3[278]|5[56][46]|86[3-6]))|2(?:2[24-9]|3[1-59]|47)|38(?:[58][78]|7[378])|3(?:4[35][56]|58[45]|8(?:[38]5|54|76))[4-6]","2(?:[23]02|6(?:[25]|4(?:64|[78]))|9(?:[02356]|4(?:[0268]|5[2-6])|72|8[23]))|3(?:3[28]|4(?:[04679]|3(?:5(?:4[0-25689]|[56])|[78])|58|8[2379])|5(?:[2467]|3[237]|8(?:[23]|4(?:[45]|60)|5(?:4[0-39]|5|64)))|7[1-578]|8(?:[2469]|3[278]|54(?:4|5[13-7]|6[89])|86[3-6]))|2(?:2[24-9]|3[1-59]|47)|38(?:[58][78]|7[378])|3(?:454|85[56])[46]|3(?:4(?:36|5[56])|8(?:[38]5|76))[4-6]"],"0$1",1],["(\\d{2})(\\d{4})(\\d{4})","$1 $2-$3",["1"],"0$1",1],["(\\d{3})(\\d{3})(\\d{4})","$1-$2-$3",["[68]"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2-$3",["[23]"],"0$1",1],["(\\d)(\\d{4})(\\d{2})(\\d{4})","$2 15-$3-$4",["9(?:2[2-469]|3[3-578])","9(?:2(?:2[024-9]|3[0-59]|47|6[245]|9[02-8])|3(?:3[28]|4[03-9]|5[2-46-8]|7[1-578]|8[2-9]))","9(?:2(?:[23]02|6(?:[25]|4[6-8])|9(?:[02356]|4[02568]|72|8[23]))|3(?:3[28]|4(?:[04679]|3[5-8]|5[4-68]|8[2379])|5(?:[2467]|3[237]|8[2-5])|7[1-578]|8(?:[2469]|3[2578]|5[4-8]|7[36-8]|8[5-8])))|92(?:2[24-9]|3[1-59]|47)","9(?:2(?:[23]02|6(?:[25]|4(?:64|[78]))|9(?:[02356]|4(?:[0268]|5[2-6])|72|8[23]))|3(?:3[28]|4(?:[04679]|3[78]|5(?:4[46]|8)|8[2379])|5(?:[2467]|3[237]|8[23])|7[1-578]|8(?:[2469]|3[278]|5(?:[56][46]|[78])|7[378]|8(?:6[3-6]|[78]))))|92(?:2[24-9]|3[1-59]|47)|93(?:4[35][56]|58[45]|8(?:[38]5|54|76))[4-6]","9(?:2(?:[23]02|6(?:[25]|4(?:64|[78]))|9(?:[02356]|4(?:[0268]|5[2-6])|72|8[23]))|3(?:3[28]|4(?:[04679]|3(?:5(?:4[0-25689]|[56])|[78])|5(?:4[46]|8)|8[2379])|5(?:[2467]|3[237]|8(?:[23]|4(?:[45]|60)|5(?:4[0-39]|5|64)))|7[1-578]|8(?:[2469]|3[278]|5(?:4(?:4|5[13-7]|6[89])|[56][46]|[78])|7[378]|8(?:6[3-6]|[78]))))|92(?:2[24-9]|3[1-59]|47)|93(?:4(?:36|5[56])|8(?:[38]5|76))[4-6]"],"0$1",0,"$1 $2 $3-$4"],["(\\d)(\\d{2})(\\d{4})(\\d{4})","$2 15-$3-$4",["91"],"0$1",0,"$1 $2 $3-$4"],["(\\d{3})(\\d{3})(\\d{5})","$1-$2-$3",["8"],"0$1"],["(\\d)(\\d{3})(\\d{3})(\\d{4})","$2 15-$3-$4",["9"],"0$1",0,"$1 $2 $3-$4"]],"0",0,"0?(?:(11|2(?:2(?:02?|[13]|2[13-79]|4[1-6]|5[2457]|6[124-8]|7[1-4]|8[13-6]|9[1267])|3(?:02?|1[467]|2[03-6]|3[13-8]|[49][2-6]|5[2-8]|[67])|4(?:7[3-578]|9)|6(?:[0136]|2[24-6]|4[6-8]?|5[15-8])|80|9(?:0[1-3]|[19]|2\\d|3[1-6]|4[02568]?|5[2-4]|6[2-46]|72?|8[23]?))|3(?:3(?:2[79]|6|8[2578])|4(?:0[0-24-9]|[12]|3[5-8]?|4[24-7]|5[4-68]?|6[02-9]|7[126]|8[2379]?|9[1-36-8])|5(?:1|2[1245]|3[237]?|4[1-46-9]|6[2-4]|7[1-6]|8[2-5]?)|6[24]|7(?:[069]|1[1568]|2[15]|3[145]|4[13]|5[14-8]|7[2-57]|8[126])|8(?:[01]|2[15-7]|3[2578]?|4[13-6]|5[4-8]?|6[1-357-9]|7[36-8]?|8[5-8]?|9[124])))15)?","9$1"],AS:["1","011","(?:[58]\\d\\d|684|900)\\d{7}",[10],0,"1",0,"([267]\\d{6})$|1","684$1",0,"684"],AT:["43","00","1\\d{3,12}|2\\d{6,12}|43(?:(?:0\\d|5[02-9])\\d{3,9}|2\\d{4,5}|[3467]\\d{4}|8\\d{4,6}|9\\d{4,7})|5\\d{4,12}|8\\d{7,12}|9\\d{8,12}|(?:[367]\\d|4[0-24-9])\\d{4,11}",[4,5,6,7,8,9,10,11,12,13],[["(\\d)(\\d{3,12})","$1 $2",["1(?:11|[2-9])"],"0$1"],["(\\d{3})(\\d{2})","$1 $2",["517"],"0$1"],["(\\d{2})(\\d{3,5})","$1 $2",["5[079]"],"0$1"],["(\\d{3})(\\d{3,10})","$1 $2",["(?:31|4)6|51|6(?:48|5[0-3579]|[6-9])|7(?:20|32|8)|[89]","(?:31|4)6|51|6(?:485|5[0-3579]|[6-9])|7(?:20|32|8)|[89]"],"0$1"],["(\\d{4})(\\d{3,9})","$1 $2",["[2-467]|5[2-6]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["5"],"0$1"],["(\\d{2})(\\d{4})(\\d{4,7})","$1 $2 $3",["5"],"0$1"]],"0"],AU:["61","001[14-689]|14(?:1[14]|34|4[17]|[56]6|7[47]|88)0011","1(?:[0-79]\\d{7}(?:\\d(?:\\d{2})?)?|8[0-24-9]\\d{7})|[2-478]\\d{8}|1\\d{4,7}",[5,6,7,8,9,10,12],[["(\\d{2})(\\d{3,4})","$1 $2",["16"],"0$1"],["(\\d{2})(\\d{3})(\\d{2,4})","$1 $2 $3",["16"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["14|4"],"0$1"],["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["[2378]"],"(0$1)"],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["1(?:30|[89])"]]],"0",0,"(183[12])|0",0,0,0,[["(?:(?:(?:2(?:[0-26-9]\\d|3[0-8]|4[02-9]|5[0135-9])|7(?:[013-57-9]\\d|2[0-8]))\\d|3(?:(?:[0-3589]\\d|6[1-9]|7[0-35-9])\\d|4(?:[0-578]\\d|90)))\\d\\d|8(?:51(?:0(?:0[03-9]|[12479]\\d|3[2-9]|5[0-8]|6[1-9]|8[0-7])|1(?:[0235689]\\d|1[0-69]|4[0-589]|7[0-47-9])|2(?:0[0-79]|[18][13579]|2[14-9]|3[0-46-9]|[4-6]\\d|7[89]|9[0-4])|3\\d\\d)|(?:6[0-8]|[78]\\d)\\d{3}|9(?:[02-9]\\d{3}|1(?:(?:[0-58]\\d|6[0135-9])\\d|7(?:0[0-24-9]|[1-9]\\d)|9(?:[0-46-9]\\d|5[0-79])))))\\d{3}",[9]],["4(?:79[01]|83[0-389]|94[0-4])\\d{5}|4(?:[0-36]\\d|4[047-9]|5[0-25-9]|7[02-8]|8[0-24-9]|9[0-37-9])\\d{6}",[9]],["180(?:0\\d{3}|2)\\d{3}",[7,10]],["190[0-26]\\d{6}",[10]],0,0,0,["163\\d{2,6}",[5,6,7,8,9]],["14(?:5(?:1[0458]|[23][458])|71\\d)\\d{4}",[9]],["13(?:00\\d{6}(?:\\d{2})?|45[0-4]\\d{3})|13\\d{4}",[6,8,10,12]]],"0011"],AW:["297","00","(?:[25-79]\\d\\d|800)\\d{4}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[25-9]"]]]],AX:["358","00|99(?:[01469]|5(?:[14]1|3[23]|5[59]|77|88|9[09]))","2\\d{4,9}|35\\d{4,5}|(?:60\\d\\d|800)\\d{4,6}|7\\d{5,11}|(?:[14]\\d|3[0-46-9]|50)\\d{4,8}",[5,6,7,8,9,10,11,12],0,"0",0,0,0,0,"18",0,"00"],AZ:["994","00","365\\d{6}|(?:[124579]\\d|60|88)\\d{7}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["90"],"0$1"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["1[28]|2|365|46","1[28]|2|365[45]|46","1[28]|2|365(?:4|5[02])|46"],"(0$1)"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[13-9]"],"0$1"]],"0"],BA:["387","00","6\\d{8}|(?:[35689]\\d|49|70)\\d{6}",[8,9],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["6[1-3]|[7-9]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2-$3",["[3-5]|6[56]"],"0$1"],["(\\d{2})(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3 $4",["6"],"0$1"]],"0"],BB:["1","011","(?:246|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2-9]\\d{6})$|1","246$1",0,"246"],BD:["880","00","[1-469]\\d{9}|8[0-79]\\d{7,8}|[2-79]\\d{8}|[2-9]\\d{7}|[3-9]\\d{6}|[57-9]\\d{5}",[6,7,8,9,10],[["(\\d{2})(\\d{4,6})","$1-$2",["31[5-8]|[459]1"],"0$1"],["(\\d{3})(\\d{3,7})","$1-$2",["3(?:[67]|8[013-9])|4(?:6[168]|7|[89][18])|5(?:6[128]|9)|6(?:[15]|28|4[14])|7[2-589]|8(?:0[014-9]|[12])|9[358]|(?:3[2-5]|4[235]|5[2-578]|6[0389]|76|8[3-7]|9[24])1|(?:44|66)[01346-9]"],"0$1"],["(\\d{4})(\\d{3,6})","$1-$2",["[13-9]|2[23]"],"0$1"],["(\\d)(\\d{7,8})","$1-$2",["2"],"0$1"]],"0"],BE:["32","00","4\\d{8}|[1-9]\\d{7}",[8,9],[["(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3",["(?:80|9)0"],"0$1"],["(\\d)(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[239]|4[23]"],"0$1"],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[15-8]"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["4"],"0$1"]],"0"],BF:["226","00","[025-7]\\d{7}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[025-7]"]]]],BG:["359","00","00800\\d{7}|[2-7]\\d{6,7}|[89]\\d{6,8}|2\\d{5}",[6,7,8,9,12],[["(\\d)(\\d)(\\d{2})(\\d{2})","$1 $2 $3 $4",["2"],"0$1"],["(\\d{3})(\\d{4})","$1 $2",["43[1-6]|70[1-9]"],"0$1"],["(\\d)(\\d{3})(\\d{3,4})","$1 $2 $3",["2"],"0$1"],["(\\d{2})(\\d{3})(\\d{2,3})","$1 $2 $3",["[356]|4[124-7]|7[1-9]|8[1-6]|9[1-7]"],"0$1"],["(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3",["(?:70|8)0"],"0$1"],["(\\d{3})(\\d{3})(\\d{2})","$1 $2 $3",["43[1-7]|7"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[48]|9[08]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["9"],"0$1"]],"0"],BH:["973","00","[136-9]\\d{7}",[8],[["(\\d{4})(\\d{4})","$1 $2",["[13679]|8[02-4679]"]]]],BI:["257","00","(?:[267]\\d|31)\\d{6}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[2367]"]]]],BJ:["229","00","(?:01\\d|[24-689])\\d{7}",[8,10],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[24-689]"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4 $5",["0"]]]],BL:["590","00","(?:590\\d|7090)\\d{5}|(?:69|80|9\\d)\\d{7}",[9],0,"0",0,0,0,0,0,[["590(?:2[7-9]|3[3-7]|5[12]|87)\\d{4}"],["(?:69(?:0\\d\\d|1(?:2[2-9]|3[0-5])|4(?:0[89]|1[2-6]|9\\d)|6(?:1[016-9]|5[0-4]|[67]\\d))|7090[0-4])\\d{4}"],["80[0-5]\\d{6}"],0,0,0,0,0,["9(?:(?:39[5-7]|76[018])\\d|475[0-6])\\d{4}"]]],BM:["1","011","(?:441|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2-9]\\d{6})$|1","441$1",0,"441"],BN:["673","00","[2-578]\\d{6}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[2-578]"]]]],BO:["591","00(?:1\\d)?","8001\\d{5}|(?:[2-467]\\d|50)\\d{6}",[8,9],[["(\\d)(\\d{7})","$1 $2",["[235]|4[46]"]],["(\\d{8})","$1",["[67]"]],["(\\d{3})(\\d{2})(\\d{4})","$1 $2 $3",["8"]]],"0",0,"0(1\\d)?"],BQ:["599","00","(?:[34]1|7\\d)\\d{5}",[7],0,0,0,0,0,0,"[347]"],BR:["55","00(?:1[245]|2[1-35]|31|4[13]|[56]5|99)","[1-467]\\d{9,10}|55[0-46-9]\\d{8}|[34]\\d{7}|55\\d{7,8}|(?:5[0-46-9]|[89]\\d)\\d{7,9}",[8,9,10,11],[["(\\d{4})(\\d{4})","$1-$2",["300|4(?:0[02]|37|86)","300|4(?:0(?:0|20)|370|864)"]],["(\\d{3})(\\d{2,3})(\\d{4})","$1 $2 $3",["(?:[358]|90)0"],"0$1"],["(\\d{2})(\\d{4})(\\d{4})","$1 $2-$3",["(?:[14689][1-9]|2[12478]|3[1-578]|5[13-5]|7[13-579])[2-57]"],"($1)"],["(\\d{2})(\\d{5})(\\d{4})","$1 $2-$3",["[16][1-9]|[2-57-9]"],"($1)"]],"0",0,"(?:0|90)(?:(1[245]|2[1-35]|31|4[13]|[56]5|99)(\\d{10,11}))?","$2"],BS:["1","011","(?:242|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([3-8]\\d{6})$|1","242$1",0,"242"],BT:["975","00","[17]\\d{7}|[2-8]\\d{6}",[7,8],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["[2-68]|7[246]"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["1[67]|7"]]]],BW:["267","00","(?:0800|(?:[37]|800)\\d)\\d{6}|(?:[2-6]\\d|90)\\d{5}",[7,8,10],[["(\\d{2})(\\d{5})","$1 $2",["90"]],["(\\d{3})(\\d{4})","$1 $2",["[24-6]|3[15-9]"]],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[37]"]],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["0"]],["(\\d{3})(\\d{4})(\\d{3})","$1 $2 $3",["8"]]]],BY:["375","810","(?:[12]\\d|33|44|902)\\d{7}|8(?:0[0-79]\\d{5,7}|[1-7]\\d{9})|8(?:1[0-489]|[5-79]\\d)\\d{7}|8[1-79]\\d{6,7}|8[0-79]\\d{5}|8\\d{5}",[6,7,8,9,10,11],[["(\\d{3})(\\d{3})","$1 $2",["800"],"8 $1"],["(\\d{3})(\\d{2})(\\d{2,4})","$1 $2 $3",["800"],"8 $1"],["(\\d{4})(\\d{2})(\\d{3})","$1 $2-$3",["1(?:5[169]|6[3-5]|7[179])|2(?:1[35]|2[34]|3[3-5])","1(?:5[169]|6(?:3[1-3]|4|5[125])|7(?:1[3-9]|7[0-24-6]|9[2-7]))|2(?:1[35]|2[34]|3[3-5])"],"8 0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2-$3-$4",["1(?:[56]|7[467])|2[1-3]"],"8 0$1"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2-$3-$4",["[1-4]"],"8 0$1"],["(\\d{3})(\\d{3,4})(\\d{4})","$1 $2 $3",["[89]"],"8 $1"]],"8",0,"0|80?",0,0,0,0,"8~10"],BZ:["501","00","(?:0800\\d|[2-8])\\d{6}",[7,11],[["(\\d{3})(\\d{4})","$1-$2",["[2-8]"]],["(\\d)(\\d{3})(\\d{4})(\\d{3})","$1-$2-$3-$4",["0"]]]],CA:["1","011","[2-9]\\d{9}|3\\d{6}",[7,10],0,"1",0,0,0,0,0,[["(?:2(?:04|[23]6|[48]9|50|63)|3(?:06|43|54|6[578]|82)|4(?:03|1[68]|[26]8|3[178]|50|74)|5(?:06|1[49]|48|79|8[147])|6(?:04|[18]3|39|47|72)|7(?:0[59]|42|53|78|8[02])|8(?:[06]7|19|25|7[39])|9(?:0[25]|42))[2-9]\\d{6}",[10]],["",[10]],["8(?:00|33|44|55|66|77|88)[2-9]\\d{6}",[10]],["900[2-9]\\d{6}",[10]],["52(?:3(?:[2-46-9][02-9]\\d|5(?:[02-46-9]\\d|5[0-46-9]))|4(?:[2-478][02-9]\\d|5(?:[034]\\d|2[024-9]|5[0-46-9])|6(?:0[1-9]|[2-9]\\d)|9(?:[05-9]\\d|2[0-5]|49)))\\d{4}|52[34][2-9]1[02-9]\\d{4}|(?:5(?:2[125-9]|33|44|66|77|88)|6(?:22|33))[2-9]\\d{6}",[10]],0,["310\\d{4}",[7]],0,["600[2-9]\\d{6}",[10]]]],CC:["61","001[14-689]|14(?:1[14]|34|4[17]|[56]6|7[47]|88)0011","1(?:[0-79]\\d{8}(?:\\d{2})?|8[0-24-9]\\d{7})|[148]\\d{8}|1\\d{5,7}",[6,7,8,9,10,12],0,"0",0,"([59]\\d{7})$|0","8$1",0,0,[["8(?:51(?:0(?:02|31|60|89)|1(?:18|76)|223)|91(?:0(?:1[0-2]|29)|1(?:[28]2|50|79)|2(?:10|64)|3(?:[06]8|22)|4[29]8|62\\d|70[23]|959))\\d{3}",[9]],["4(?:79[01]|83[0-389]|94[0-4])\\d{5}|4(?:[0-36]\\d|4[047-9]|5[0-25-9]|7[02-8]|8[0-24-9]|9[0-37-9])\\d{6}",[9]],["180(?:0\\d{3}|2)\\d{3}",[7,10]],["190[0-26]\\d{6}",[10]],0,0,0,0,["14(?:5(?:1[0458]|[23][458])|71\\d)\\d{4}",[9]],["13(?:00\\d{6}(?:\\d{2})?|45[0-4]\\d{3})|13\\d{4}",[6,8,10,12]]],"0011"],CD:["243","00","(?:(?:[189]|5\\d)\\d|2)\\d{7}|[1-68]\\d{6}",[7,8,9,10],[["(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3",["88"],"0$1"],["(\\d{2})(\\d{5})","$1 $2",["[1-6]"],"0$1"],["(\\d{2})(\\d{2})(\\d{4})","$1 $2 $3",["2"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["1"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[89]"],"0$1"],["(\\d{2})(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3 $4",["5"],"0$1"]],"0"],CF:["236","00","(?:[27]\\d{3}|8776)\\d{4}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[278]"]]]],CG:["242","00","222\\d{6}|(?:0\\d|80)\\d{7}",[9],[["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["8"]],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[02]"]]]],CH:["41","00","8\\d{11}|[2-9]\\d{8}",[9,12],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["8[047]|90"],"0$1"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[2-79]|81"],"0$1"],["(\\d{3})(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4 $5",["8"],"0$1"]],"0"],CI:["225","00","[02]\\d{9}",[10],[["(\\d{2})(\\d{2})(\\d)(\\d{5})","$1 $2 $3 $4",["2"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{4})","$1 $2 $3 $4",["0"]]]],CK:["682","00","[2-578]\\d{4}",[5],[["(\\d{2})(\\d{3})","$1 $2",["[2-578]"]]]],CL:["56","(?:0|1(?:1[0-69]|2[02-5]|5[13-58]|69|7[0167]|8[018]))0","12300\\d{6}|6\\d{9,10}|[2-9]\\d{8}",[9,10,11],[["(\\d{5})(\\d{4})","$1 $2",["219","2196"],"($1)"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["44"]],["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["2[1-36]"],"($1)"],["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["9[2-9]"]],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["3[2-5]|[47]|5[1-3578]|6[13-57]|8(?:0[1-9]|[1-9])"],"($1)"],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["60|8"]],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["1"]],["(\\d{3})(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3 $4",["60"]]]],CM:["237","00","[26]\\d{8}|88\\d{6,7}",[8,9],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["88"]],["(\\d)(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4 $5",["[26]|88"]]]],CN:["86","00|1(?:[12]\\d|79)\\d\\d00","(?:(?:1[03-689]|2\\d)\\d\\d|6)\\d{8}|1\\d{10}|[126]\\d{6}(?:\\d(?:\\d{2})?)?|86\\d{5,6}|(?:[3-579]\\d|8[0-57-9])\\d{5,9}",[7,8,9,10,11,12],[["(\\d{2})(\\d{5,6})","$1 $2",["(?:10|2[0-57-9])[19]|3(?:[157]|35|49|9[1-68])|4(?:1[124-9]|2[179]|6[47-9]|7|8[23])|5(?:[1357]|2[37]|4[36]|6[1-46]|80)|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:07|1[236-8]|2[5-7]|[37]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|3|4[13]|5[1-5]|7[0-79]|9[0-35-9])|(?:4[35]|59|85)[1-9]","(?:10|2[0-57-9])(?:1[02]|9[56])|8078|(?:3(?:[157]\\d|35|49|9[1-68])|4(?:1[124-9]|2[179]|[35][1-9]|6[47-9]|7\\d|8[23])|5(?:[1357]\\d|2[37]|4[36]|6[1-46]|80|9[1-9])|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]\\d|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:1[236-8]|2[5-7]|[37]\\d|5[1-9]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|3\\d|4[13]|5[1-5]|7[0-79]|9[0-35-9]))1","10(?:1(?:0|23)|9[56])|2[0-57-9](?:1(?:00|23)|9[56])|80781|(?:3(?:[157]\\d|35|49|9[1-68])|4(?:1[124-9]|2[179]|[35][1-9]|6[47-9]|7\\d|8[23])|5(?:[1357]\\d|2[37]|4[36]|6[1-46]|80|9[1-9])|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]\\d|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:1[236-8]|2[5-7]|[37]\\d|5[1-9]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|3\\d|4[13]|5[1-5]|7[0-79]|9[0-35-9]))12","10(?:1(?:0|23)|9[56])|2[0-57-9](?:1(?:00|23)|9[56])|807812|(?:3(?:[157]\\d|35|49|9[1-68])|4(?:1[124-9]|2[179]|[35][1-9]|6[47-9]|7\\d|8[23])|5(?:[1357]\\d|2[37]|4[36]|6[1-46]|80|9[1-9])|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]\\d|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:1[236-8]|2[5-7]|[37]\\d|5[1-9]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|3\\d|4[13]|5[1-5]|7[0-79]|9[0-35-9]))123","10(?:1(?:0|23)|9[56])|2[0-57-9](?:1(?:00|23)|9[56])|(?:3(?:[157]\\d|35|49|9[1-68])|4(?:1[124-9]|2[179]|[35][1-9]|6[47-9]|7\\d|8[23])|5(?:[1357]\\d|2[37]|4[36]|6[1-46]|80|9[1-9])|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]\\d|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:078|1[236-8]|2[5-7]|[37]\\d|5[1-9]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|3\\d|4[13]|5[1-5]|7[0-79]|9[0-35-9]))123"],"0$1"],["(\\d{3})(\\d{5,6})","$1 $2",["3(?:[157]|35|49|9[1-68])|4(?:[17]|2[179]|6[47-9]|8[23])|5(?:[1357]|2[37]|4[36]|6[1-46]|80)|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:1[236-8]|2[5-7]|[37]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|[379]|4[13]|5[1-5])|(?:4[35]|59|85)[1-9]","(?:3(?:[157]\\d|35|49|9[1-68])|4(?:[17]\\d|2[179]|[35][1-9]|6[47-9]|8[23])|5(?:[1357]\\d|2[37]|4[36]|6[1-46]|80|9[1-9])|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]\\d|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:1[236-8]|2[5-7]|[37]\\d|5[1-9]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|[379]\\d|4[13]|5[1-5]))[19]","85[23](?:10|95)|(?:3(?:[157]\\d|35|49|9[1-68])|4(?:[17]\\d|2[179]|[35][1-9]|6[47-9]|8[23])|5(?:[1357]\\d|2[37]|4[36]|6[1-46]|80|9[1-9])|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]\\d|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:1[236-8]|2[5-7]|[37]\\d|5[14-9]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|[379]\\d|4[13]|5[1-5]))(?:10|9[56])","85[23](?:100|95)|(?:3(?:[157]\\d|35|49|9[1-68])|4(?:[17]\\d|2[179]|[35][1-9]|6[47-9]|8[23])|5(?:[1357]\\d|2[37]|4[36]|6[1-46]|80|9[1-9])|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]\\d|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:1[236-8]|2[5-7]|[37]\\d|5[14-9]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|[379]\\d|4[13]|5[1-5]))(?:100|9[56])"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["(?:4|80)0"]],["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["10|2(?:[02-57-9]|1[1-9])","10|2(?:[02-57-9]|1[1-9])","10[0-79]|2(?:[02-57-9]|1[1-79])|(?:10|21)8(?:0[1-9]|[1-9])"],"0$1",1],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["3(?:[3-59]|7[02-68])|4(?:[26-8]|3[3-9]|5[2-9])|5(?:3[03-9]|[468]|7[028]|9[2-46-9])|6|7(?:[0-247]|3[04-9]|5[0-4689]|6[2368])|8(?:[1-358]|9[1-7])|9(?:[013479]|5[1-5])|(?:[34]1|55|79|87)[02-9]"],"0$1",1],["(\\d{3})(\\d{7,8})","$1 $2",["9"]],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["80"],"0$1",1],["(\\d{3})(\\d{4})(\\d{4})","$1 $2 $3",["[3-578]"],"0$1",1],["(\\d{3})(\\d{4})(\\d{4})","$1 $2 $3",["1[3-9]"]],["(\\d{2})(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3 $4",["[12]"],"0$1",1]],"0",0,"(1(?:[12]\\d|79)\\d\\d)|0",0,0,0,0,"00"],CO:["57","00(?:4(?:[14]4|56)|[579])","(?:46|60\\d\\d)\\d{6}|(?:1\\d|[39])\\d{9}",[8,10,11],[["(\\d{4})(\\d{4})","$1 $2",["46"]],["(\\d{3})(\\d{7})","$1 $2",["6|90"],"($1)"],["(\\d{3})(\\d{7})","$1 $2",["3[0-357]|91"]],["(\\d)(\\d{3})(\\d{7})","$1-$2-$3",["1"],"0$1",0,"$1 $2 $3"]],"0",0,"0([3579]|4(?:[14]4|56))?"],CR:["506","00","(?:8\\d|90)\\d{8}|(?:[24-8]\\d{3}|3005)\\d{4}",[8,10],[["(\\d{4})(\\d{4})","$1 $2",["[2-7]|8[3-9]"]],["(\\d{3})(\\d{3})(\\d{4})","$1-$2-$3",["[89]"]]],0,0,"(19(?:0[0-2468]|1[09]|20|66|77|99))"],CU:["53","119","(?:[2-7]|8\\d\\d)\\d{7}|[2-47]\\d{6}|[34]\\d{5}",[6,7,8,10],[["(\\d{2})(\\d{4,6})","$1 $2",["2[1-4]|[34]"],"(0$1)"],["(\\d)(\\d{6,7})","$1 $2",["7"],"(0$1)"],["(\\d)(\\d{7})","$1 $2",["[56]"],"0$1"],["(\\d{3})(\\d{7})","$1 $2",["8"],"0$1"]],"0"],CV:["238","0","(?:[2-59]\\d\\d|800)\\d{4}",[7],[["(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3",["[2-589]"]]]],CW:["599","00","(?:[34]1|60|(?:7|9\\d)\\d)\\d{5}",[7,8],[["(\\d{3})(\\d{4})","$1 $2",["[3467]"]],["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["9[4-8]"]]],0,0,0,0,0,"[69]"],CX:["61","001[14-689]|14(?:1[14]|34|4[17]|[56]6|7[47]|88)0011","1(?:[0-79]\\d{8}(?:\\d{2})?|8[0-24-9]\\d{7})|[148]\\d{8}|1\\d{5,7}",[6,7,8,9,10,12],0,"0",0,"([59]\\d{7})$|0","8$1",0,0,[["8(?:51(?:0(?:01|30|59|88)|1(?:17|46|75)|2(?:22|35))|91(?:00[6-9]|1(?:[28]1|49|78)|2(?:09|63)|3(?:12|26|75)|4(?:56|97)|64\\d|7(?:0[01]|1[0-2])|958))\\d{3}",[9]],["4(?:79[01]|83[0-389]|94[0-4])\\d{5}|4(?:[0-36]\\d|4[047-9]|5[0-25-9]|7[02-8]|8[0-24-9]|9[0-37-9])\\d{6}",[9]],["180(?:0\\d{3}|2)\\d{3}",[7,10]],["190[0-26]\\d{6}",[10]],0,0,0,0,["14(?:5(?:1[0458]|[23][458])|71\\d)\\d{4}",[9]],["13(?:00\\d{6}(?:\\d{2})?|45[0-4]\\d{3})|13\\d{4}",[6,8,10,12]]],"0011"],CY:["357","00","(?:[279]\\d|[58]0)\\d{6}",[8],[["(\\d{2})(\\d{6})","$1 $2",["[257-9]"]]]],CZ:["420","00","(?:[2-578]\\d|60)\\d{7}|9\\d{8,11}",[9,10,11,12],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[2-8]|9[015-7]"]],["(\\d{2})(\\d{3})(\\d{3})(\\d{2})","$1 $2 $3 $4",["96"]],["(\\d{2})(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4",["9"]],["(\\d{3})(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4",["9"]]]],DE:["49","00","[2579]\\d{5,14}|49(?:[34]0|69|8\\d)\\d\\d?|49(?:37|49|60|7[089]|9\\d)\\d{1,3}|49(?:2[024-9]|3[2-689]|7[1-7])\\d{1,8}|(?:1|[368]\\d|4[0-8])\\d{3,13}|49(?:[015]\\d|2[13]|31|[46][1-8])\\d{1,9}",[4,5,6,7,8,9,10,11,12,13,14,15],[["(\\d{2})(\\d{3,13})","$1 $2",["3[02]|40|[68]9"],"0$1"],["(\\d{3})(\\d{3,12})","$1 $2",["2(?:0[1-389]|1[124]|2[18]|3[14])|3(?:[35-9][15]|4[015])|906|(?:2[4-9]|4[2-9]|[579][1-9]|[68][1-8])1","2(?:0[1-389]|12[0-8])|3(?:[35-9][15]|4[015])|906|2(?:[13][14]|2[18])|(?:2[4-9]|4[2-9]|[579][1-9]|[68][1-8])1"],"0$1"],["(\\d{4})(\\d{2,11})","$1 $2",["[24-6]|3(?:[3569][02-46-9]|4[2-4679]|7[2-467]|8[2-46-8])|70[2-8]|8(?:0[2-9]|[1-8])|90[7-9]|[79][1-9]","[24-6]|3(?:3(?:0[1-467]|2[127-9]|3[124578]|7[1257-9]|8[1256]|9[145])|4(?:2[135]|4[13578]|9[1346])|5(?:0[14]|2[1-3589]|6[1-4]|7[13468]|8[13568])|6(?:2[1-489]|3[124-6]|6[13]|7[12579]|8[1-356]|9[135])|7(?:2[1-7]|4[145]|6[1-5]|7[1-4])|8(?:21|3[1468]|6|7[1467]|8[136])|9(?:0[12479]|2[1358]|4[134679]|6[1-9]|7[136]|8[147]|9[1468]))|70[2-8]|8(?:0[2-9]|[1-8])|90[7-9]|[79][1-9]|3[68]4[1347]|3(?:47|60)[1356]|3(?:3[46]|46|5[49])[1246]|3[4579]3[1357]"],"0$1"],["(\\d{3})(\\d{4})","$1 $2",["138"],"0$1"],["(\\d{5})(\\d{2,10})","$1 $2",["3"],"0$1"],["(\\d{3})(\\d{5,11})","$1 $2",["181"],"0$1"],["(\\d{3})(\\d)(\\d{4,10})","$1 $2 $3",["1(?:3|80)|9"],"0$1"],["(\\d{3})(\\d{7,8})","$1 $2",["1[67]"],"0$1"],["(\\d{3})(\\d{7,12})","$1 $2",["8"],"0$1"],["(\\d{5})(\\d{6})","$1 $2",["185","1850","18500"],"0$1"],["(\\d{3})(\\d{4})(\\d{4})","$1 $2 $3",["7"],"0$1"],["(\\d{4})(\\d{7})","$1 $2",["18[68]"],"0$1"],["(\\d{4})(\\d{7})","$1 $2",["15[1279]"],"0$1"],["(\\d{5})(\\d{6})","$1 $2",["15[03568]","15(?:[0568]|31)"],"0$1"],["(\\d{3})(\\d{8})","$1 $2",["18"],"0$1"],["(\\d{3})(\\d{2})(\\d{7,8})","$1 $2 $3",["1(?:6[023]|7)"],"0$1"],["(\\d{4})(\\d{2})(\\d{7})","$1 $2 $3",["15[279]"],"0$1"],["(\\d{3})(\\d{2})(\\d{8})","$1 $2 $3",["15"],"0$1"]],"0"],DJ:["253","00","(?:2\\d|77)\\d{6}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[27]"]]]],DK:["45","00","[2-9]\\d{7}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[2-9]"]]]],DM:["1","011","(?:[58]\\d\\d|767|900)\\d{7}",[10],0,"1",0,"([2-7]\\d{6})$|1","767$1",0,"767"],DO:["1","011","(?:[58]\\d\\d|900)\\d{7}",[10],0,"1",0,0,0,0,"8001|8[024]9"],DZ:["213","00","(?:[1-4]|[5-79]\\d|80)\\d{7}",[8,9],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[1-4]"],"0$1"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["9"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[5-8]"],"0$1"]],"0"],EC:["593","00","1\\d{9,10}|(?:[2-7]|9\\d)\\d{7}",[8,9,10,11],[["(\\d)(\\d{3})(\\d{4})","$1 $2-$3",["[2-7]"],"(0$1)",0,"$1-$2-$3"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["9"],"0$1"],["(\\d{4})(\\d{3})(\\d{3,4})","$1 $2 $3",["1"]]],"0"],EE:["372","00","8\\d{9}|[4578]\\d{7}|(?:[3-8]\\d|90)\\d{5}",[7,8,10],[["(\\d{3})(\\d{4})","$1 $2",["[369]|4[3-8]|5(?:[0-2]|5[0-478]|6[45])|7[1-9]|88","[369]|4[3-8]|5(?:[02]|1(?:[0-8]|95)|5[0-478]|6(?:4[0-4]|5[1-589]))|7[1-9]|88"]],["(\\d{4})(\\d{3,4})","$1 $2",["[45]|8(?:00|[1-49])","[45]|8(?:00[1-9]|[1-49])"]],["(\\d{2})(\\d{2})(\\d{4})","$1 $2 $3",["7"]],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["8"]]]],EG:["20","00","[189]\\d{8,9}|[24-6]\\d{8}|[135]\\d{7}",[8,9,10],[["(\\d)(\\d{7,8})","$1 $2",["[23]"],"0$1"],["(\\d{2})(\\d{6,7})","$1 $2",["1[35]|[4-6]|8[2468]|9[235-7]"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[89]"],"0$1"],["(\\d{2})(\\d{8})","$1 $2",["1"],"0$1"]],"0"],EH:["212","00","[5-8]\\d{8}",[9],0,"0",0,0,0,0,"528[89]"],ER:["291","00","[178]\\d{6}",[7],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["[178]"],"0$1"]],"0"],ES:["34","00","[5-9]\\d{8}",[9],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[89]00"]],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[5-9]"]]]],ET:["251","00","(?:11|[2-579]\\d)\\d{7}",[9],[["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[1-579]"],"0$1"]],"0"],FI:["358","00|99(?:[01469]|5(?:[14]1|3[23]|5[59]|77|88|9[09]))","[1-35689]\\d{4}|7\\d{10,11}|(?:[124-7]\\d|3[0-46-9])\\d{8}|[1-9]\\d{5,8}",[5,6,7,8,9,10,11,12],[["(\\d{5})","$1",["20[2-59]"],"0$1"],["(\\d{3})(\\d{3,7})","$1 $2",["(?:[1-3]0|[68])0|70[07-9]"],"0$1"],["(\\d{2})(\\d{4,8})","$1 $2",["[14]|2[09]|50|7[135]"],"0$1"],["(\\d{2})(\\d{6,10})","$1 $2",["7"],"0$1"],["(\\d)(\\d{4,9})","$1 $2",["(?:19|[2568])[1-8]|3(?:0[1-9]|[1-9])|9"],"0$1"]],"0",0,0,0,0,"1[03-79]|[2-9]",0,"00"],FJ:["679","0(?:0|52)","45\\d{5}|(?:0800\\d|[235-9])\\d{6}",[7,11],[["(\\d{3})(\\d{4})","$1 $2",["[235-9]|45"]],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["0"]]],0,0,0,0,0,0,0,"00"],FK:["500","00","[2-7]\\d{4}",[5]],FM:["691","00","(?:[39]\\d\\d|820)\\d{4}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[389]"]]]],FO:["298","00","[2-9]\\d{5}",[6],[["(\\d{6})","$1",["[2-9]"]]],0,0,"(10(?:01|[12]0|88))"],FR:["33","00","[1-9]\\d{8}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"],"0 $1"],["(\\d)(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4 $5",["[1-79]"],"0$1"]],"0"],GA:["241","00","(?:[067]\\d|11)\\d{6}|[2-7]\\d{6}",[7,8],[["(\\d)(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[2-7]"],"0$1"],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["0"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["11|[67]"],"0$1"]],0,0,"0(11\\d{6}|60\\d{6}|61\\d{6}|6[256]\\d{6}|7[467]\\d{6})","$1"],GB:["44","00","[1-357-9]\\d{9}|[18]\\d{8}|8\\d{6}",[7,9,10],[["(\\d{3})(\\d{4})","$1 $2",["800","8001","80011","800111","8001111"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3",["845","8454","84546","845464"],"0$1"],["(\\d{3})(\\d{6})","$1 $2",["800"],"0$1"],["(\\d{5})(\\d{4,5})","$1 $2",["1(?:38|5[23]|69|76|94)","1(?:(?:38|69)7|5(?:24|39)|768|946)","1(?:3873|5(?:242|39[4-6])|(?:697|768)[347]|9467)"],"0$1"],["(\\d{4})(\\d{5,6})","$1 $2",["1(?:[2-69][02-9]|[78])"],"0$1"],["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["[25]|7(?:0|6[02-9])","[25]|7(?:0|6(?:[03-9]|2[356]))"],"0$1"],["(\\d{4})(\\d{6})","$1 $2",["7"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[1389]"],"0$1"]],"0",0,0,0,0,0,[["(?:1(?:1(?:3(?:[0-58]\\d\\d|73[0-35])|4(?:(?:[0-5]\\d|70)\\d|69[7-9])|(?:(?:5[0-26-9]|[78][0-49])\\d|6(?:[0-4]\\d|50))\\d)|(?:2(?:(?:0[024-9]|2[3-9]|3[3-79]|4[1-689]|[58][02-9]|6[0-47-9]|7[013-9]|9\\d)\\d|1(?:[0-7]\\d|8[0-3]))|(?:3(?:0\\d|1[0-8]|[25][02-9]|3[02-579]|[468][0-46-9]|7[1-35-79]|9[2-578])|4(?:0[03-9]|[137]\\d|[28][02-57-9]|4[02-69]|5[0-8]|[69][0-79])|5(?:0[1-35-9]|[16]\\d|2[024-9]|3[015689]|4[02-9]|5[03-9]|7[0-35-9]|8[0-468]|9[0-57-9])|6(?:0[034689]|1\\d|2[0-35689]|[38][013-9]|4[1-467]|5[0-69]|6[13-9]|7[0-8]|9[0-24578])|7(?:0[0246-9]|2\\d|3[0236-8]|4[03-9]|5[0-46-9]|6[013-9]|7[0-35-9]|8[024-9]|9[02-9])|8(?:0[35-9]|2[1-57-9]|3[02-578]|4[0-578]|5[124-9]|6[2-69]|7\\d|8[02-9]|9[02569])|9(?:0[02-589]|[18]\\d|2[02-689]|3[1-57-9]|4[2-9]|5[0-579]|6[2-47-9]|7[0-24578]|9[2-57]))\\d)\\d)|2(?:0[013478]|3[0189]|4[017]|8[0-46-9]|9[0-2])\\d{3})\\d{4}|1(?:2(?:0(?:46[1-4]|87[2-9])|545[1-79]|76(?:2\\d|3[1-8]|6[1-6])|9(?:7(?:2[0-4]|3[2-5])|8(?:2[2-8]|7[0-47-9]|8[3-5])))|3(?:6(?:38[2-5]|47[23])|8(?:47[04-9]|64[0157-9]))|4(?:044[1-7]|20(?:2[23]|8\\d)|6(?:0(?:30|5[2-57]|6[1-8]|7[2-8])|140)|8(?:052|87[1-3]))|5(?:2(?:4(?:3[2-79]|6\\d)|76\\d)|6(?:26[06-9]|686))|6(?:06(?:4\\d|7[4-79])|295[5-7]|35[34]\\d|47(?:24|61)|59(?:5[08]|6[67]|74)|9(?:55[0-4]|77[23]))|7(?:26(?:6[13-9]|7[0-7])|(?:442|688)\\d|50(?:2[0-3]|[3-68]2|76))|8(?:27[56]\\d|37(?:5[2-5]|8[239])|843[2-58])|9(?:0(?:0(?:6[1-8]|85)|52\\d)|3583|4(?:66[1-8]|9(?:2[01]|81))|63(?:23|3[1-4])|9561))\\d{3}",[9,10]],["7(?:457[0-57-9]|700[01]|911[028])\\d{5}|7(?:[1-3]\\d\\d|4(?:[0-46-9]\\d|5[0-689])|5(?:0[0-8]|[13-9]\\d|2[0-35-9])|7(?:0[1-9]|[1-7]\\d|8[02-9]|9[0-689])|8(?:[014-9]\\d|[23][0-8])|9(?:[024-9]\\d|1[02-9]|3[0-689]))\\d{6}",[10]],["80[08]\\d{7}|800\\d{6}|8001111"],["(?:8(?:4[2-5]|7[0-3])|9(?:[01]\\d|8[2-49]))\\d{7}|845464\\d",[7,10]],["70\\d{8}",[10]],0,["(?:3[0347]|55)\\d{8}",[10]],["76(?:464|652)\\d{5}|76(?:0[0-28]|2[356]|34|4[01347]|5[49]|6[0-369]|77|8[14]|9[139])\\d{6}",[10]],["56\\d{8}",[10]]],0," x"],GD:["1","011","(?:473|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2-9]\\d{6})$|1","473$1",0,"473"],GE:["995","00","(?:[3-57]\\d\\d|800)\\d{6}",[9],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["70"],"0$1"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["32"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[57]"]],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[348]"],"0$1"]],"0"],GF:["594","00","(?:[56]94\\d|7093)\\d{5}|(?:80|9\\d)\\d{7}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[5-7]|9[47]"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[89]"],"0$1"]],"0"],GG:["44","00","(?:1481|[357-9]\\d{3})\\d{6}|8\\d{6}(?:\\d{2})?",[7,9,10],0,"0",0,"([25-9]\\d{5})$|0","1481$1",0,0,[["1481[25-9]\\d{5}",[10]],["7(?:(?:781|839)\\d|911[17])\\d{5}",[10]],["80[08]\\d{7}|800\\d{6}|8001111"],["(?:8(?:4[2-5]|7[0-3])|9(?:[01]\\d|8[0-3]))\\d{7}|845464\\d",[7,10]],["70\\d{8}",[10]],0,["(?:3[0347]|55)\\d{8}",[10]],["76(?:464|652)\\d{5}|76(?:0[0-28]|2[356]|34|4[01347]|5[49]|6[0-369]|77|8[14]|9[139])\\d{6}",[10]],["56\\d{8}",[10]]]],GH:["233","00","(?:[235]\\d{3}|800)\\d{5}",[8,9],[["(\\d{3})(\\d{5})","$1 $2",["8"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[235]"],"0$1"]],"0"],GI:["350","00","(?:[25]\\d|60)\\d{6}",[8],[["(\\d{3})(\\d{5})","$1 $2",["2"]]]],GL:["299","00","(?:19|[2-689]\\d|70)\\d{4}",[6],[["(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3",["19|[2-9]"]]]],GM:["220","00","[2-9]\\d{6}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[2-9]"]]]],GN:["224","00","722\\d{6}|(?:3|6\\d)\\d{7}",[8,9],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["3"]],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[67]"]]]],GP:["590","00","(?:590\\d|7090)\\d{5}|(?:69|80|9\\d)\\d{7}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[5-79]"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"],"0$1"]],"0",0,0,0,0,0,[["590(?:0[1-68]|[14][0-24-9]|2[0-68]|3[1-9]|5[3-579]|[68][0-689]|7[08]|9\\d)\\d{4}"],["(?:69(?:0\\d\\d|1(?:2[2-9]|3[0-5])|4(?:0[89]|1[2-6]|9\\d)|6(?:1[016-9]|5[0-4]|[67]\\d))|7090[0-4])\\d{4}"],["80[0-5]\\d{6}"],0,0,0,0,0,["9(?:(?:39[5-7]|76[018])\\d|475[0-6])\\d{4}"]]],GQ:["240","00","222\\d{6}|(?:3\\d|55|[89]0)\\d{7}",[9],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[235]"]],["(\\d{3})(\\d{6})","$1 $2",["[89]"]]]],GR:["30","00","5005000\\d{3}|8\\d{9,11}|(?:[269]\\d|70)\\d{8}",[10,11,12],[["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["21|7"]],["(\\d{4})(\\d{6})","$1 $2",["2(?:2|3[2-57-9]|4[2-469]|5[2-59]|6[2-9]|7[2-69]|8[2-49])|5"]],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[2689]"]],["(\\d{3})(\\d{3,4})(\\d{5})","$1 $2 $3",["8"]]]],GT:["502","00","80\\d{6}|(?:1\\d{3}|[2-7])\\d{7}",[8,11],[["(\\d{4})(\\d{4})","$1 $2",["[2-8]"]],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["1"]]]],GU:["1","011","(?:[58]\\d\\d|671|900)\\d{7}",[10],0,"1",0,"([2-9]\\d{6})$|1","671$1",0,"671"],GW:["245","00","[49]\\d{8}|4\\d{6}",[7,9],[["(\\d{3})(\\d{4})","$1 $2",["40"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[49]"]]]],GY:["592","001","(?:[2-8]\\d{3}|9008)\\d{3}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[2-9]"]]]],HK:["852","00(?:30|5[09]|[126-9]?)","8[0-46-9]\\d{6,7}|9\\d{4,7}|(?:[2-7]|9\\d{3})\\d{7}",[5,6,7,8,9,11],[["(\\d{3})(\\d{2,5})","$1 $2",["900","9003"]],["(\\d{4})(\\d{4})","$1 $2",["[2-7]|8[1-4]|9(?:0[1-9]|[1-8])"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["8"]],["(\\d{3})(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3 $4",["9"]]],0,0,0,0,0,0,0,"00"],HN:["504","00","8\\d{10}|[237-9]\\d{7}",[8,11],[["(\\d{4})(\\d{4})","$1-$2",["[237-9]"]]]],HR:["385","00","[2-69]\\d{8}|80\\d{5,7}|[1-79]\\d{7}|6\\d{6}",[7,8,9],[["(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3",["6[01]"],"0$1"],["(\\d{3})(\\d{2})(\\d{2,3})","$1 $2 $3",["8"],"0$1"],["(\\d)(\\d{4})(\\d{3})","$1 $2 $3",["1"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["6|7[245]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["9"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[2-57]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["8"],"0$1"]],"0"],HT:["509","00","(?:[2-489]\\d|55)\\d{6}",[8],[["(\\d{2})(\\d{2})(\\d{4})","$1 $2 $3",["[2-589]"]]]],HU:["36","00","[235-7]\\d{8}|[1-9]\\d{7}",[8,9],[["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["1"],"(06 $1)"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[27][2-9]|3[2-7]|4[24-9]|5[2-79]|6|8[2-57-9]|9[2-69]"],"(06 $1)"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[2-9]"],"06 $1"]],"06"],ID:["62","00[89]","00[1-9]\\d{9,14}|(?:[1-36]|8\\d{5})\\d{6}|00\\d{9}|[1-9]\\d{8,10}|[2-9]\\d{7}",[7,8,9,10,11,12,13,14,15,16,17],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["15"]],["(\\d{2})(\\d{5,9})","$1 $2",["2[124]|[36]1"],"(0$1)"],["(\\d{3})(\\d{5,7})","$1 $2",["800"],"0$1"],["(\\d{3})(\\d{5,8})","$1 $2",["[2-79]"],"(0$1)"],["(\\d{3})(\\d{3,4})(\\d{3})","$1-$2-$3",["8[1-35-9]"],"0$1"],["(\\d{3})(\\d{6,8})","$1 $2",["1"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["804"],"0$1"],["(\\d{3})(\\d)(\\d{3})(\\d{3})","$1 $2 $3 $4",["80"],"0$1"],["(\\d{3})(\\d{4})(\\d{4,5})","$1-$2-$3",["8"],"0$1"]],"0"],IE:["353","00","(?:1\\d|[2569])\\d{6,8}|4\\d{6,9}|7\\d{8}|8\\d{8,9}",[7,8,9,10],[["(\\d{2})(\\d{5})","$1 $2",["2[24-9]|47|58|6[237-9]|9[35-9]"],"(0$1)"],["(\\d{3})(\\d{5})","$1 $2",["[45]0"],"(0$1)"],["(\\d)(\\d{3,4})(\\d{4})","$1 $2 $3",["1"],"(0$1)"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[2569]|4[1-69]|7[14]"],"(0$1)"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["70"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["81"],"(0$1)"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[78]"],"0$1"],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["1"]],["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["4"],"(0$1)"],["(\\d{2})(\\d)(\\d{3})(\\d{4})","$1 $2 $3 $4",["8"],"0$1"]],"0"],IL:["972","0(?:0|1[2-9])","1\\d{6}(?:\\d{3,5})?|[57]\\d{8}|[1-489]\\d{7}",[7,8,9,10,11,12],[["(\\d{4})(\\d{3})","$1-$2",["125"]],["(\\d{4})(\\d{2})(\\d{2})","$1-$2-$3",["121"]],["(\\d)(\\d{3})(\\d{4})","$1-$2-$3",["[2-489]"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1-$2-$3",["[57]"],"0$1"],["(\\d{4})(\\d{3})(\\d{3})","$1-$2-$3",["12"]],["(\\d{4})(\\d{6})","$1-$2",["159"]],["(\\d)(\\d{3})(\\d{3})(\\d{3})","$1-$2-$3-$4",["1[7-9]"]],["(\\d{3})(\\d{1,2})(\\d{3})(\\d{4})","$1-$2 $3-$4",["15"]]],"0"],IM:["44","00","1624\\d{6}|(?:[3578]\\d|90)\\d{8}",[10],0,"0",0,"([25-8]\\d{5})$|0","1624$1",0,"74576|(?:16|7[56])24"],IN:["91","00","(?:000800|[2-9]\\d\\d)\\d{7}|1\\d{7,12}",[8,9,10,11,12,13],[["(\\d{8})","$1",["5(?:0|2[23]|3[03]|[67]1|88)","5(?:0|2(?:21|3)|3(?:0|3[23])|616|717|888)","5(?:0|2(?:21|3)|3(?:0|3[23])|616|717|8888)"],0,1],["(\\d{4})(\\d{4,5})","$1 $2",["180","1800"],0,1],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["140"],0,1],["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["11|2[02]|33|4[04]|79[1-7]|80[2-46]","11|2[02]|33|4[04]|79(?:[1-6]|7[19])|80(?:[2-4]|6[0-589])","11|2[02]|33|4[04]|79(?:[124-6]|3(?:[02-9]|1[0-24-9])|7(?:1|9[1-6]))|80(?:[2-4]|6[0-589])"],"0$1",1],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["1(?:2[0-249]|3[0-25]|4[145]|[68]|7[1257])|2(?:1[257]|3[013]|4[01]|5[0137]|6[0158]|78|8[1568])|3(?:26|4[1-3]|5[34]|6[01489]|7[02-46]|8[159])|4(?:1[36]|2[1-47]|5[12]|6[0-26-9]|7[0-24-9]|8[013-57]|9[014-7])|5(?:1[025]|22|[36][25]|4[28]|5[12]|[78]1)|6(?:12|[2-4]1|5[17]|6[13]|80)|7(?:12|3[134]|4[47]|61|88)|8(?:16|2[014]|3[126]|6[136]|7[078]|8[34]|91)|(?:43|59|75)[15]|(?:1[59]|29|67|72)[14]","1(?:2[0-24]|3[0-25]|4[145]|[59][14]|6[1-9]|7[1257]|8[1-57-9])|2(?:1[257]|3[013]|4[01]|5[0137]|6[058]|78|8[1568]|9[14])|3(?:26|4[1-3]|5[34]|6[01489]|7[02-46]|8[159])|4(?:1[36]|2[1-47]|3[15]|5[12]|6[0-26-9]|7[0-24-9]|8[013-57]|9[014-7])|5(?:1[025]|22|[36][25]|4[28]|[578]1|9[15])|674|7(?:(?:2[14]|3[34]|5[15])[2-6]|61[346]|88[0-8])|8(?:70[2-6]|84[235-7]|91[3-7])|(?:1(?:29|60|8[06])|261|552|6(?:12|[2-47]1|5[17]|6[13]|80)|7(?:12|31|4[47])|8(?:16|2[014]|3[126]|6[136]|7[78]|83))[2-7]","1(?:2[0-24]|3[0-25]|4[145]|[59][14]|6[1-9]|7[1257]|8[1-57-9])|2(?:1[257]|3[013]|4[01]|5[0137]|6[058]|78|8[1568]|9[14])|3(?:26|4[1-3]|5[34]|6[01489]|7[02-46]|8[159])|4(?:1[36]|2[1-47]|3[15]|5[12]|6[0-26-9]|7[0-24-9]|8[013-57]|9[014-7])|5(?:1[025]|22|[36][25]|4[28]|[578]1|9[15])|6(?:12(?:[2-6]|7[0-8])|74[2-7])|7(?:(?:2[14]|5[15])[2-6]|3171|61[346]|88(?:[2-7]|82))|8(?:70[2-6]|84(?:[2356]|7[19])|91(?:[3-6]|7[19]))|73[134][2-6]|(?:74[47]|8(?:16|2[014]|3[126]|6[136]|7[78]|83))(?:[2-6]|7[19])|(?:1(?:29|60|8[06])|261|552|6(?:[2-4]1|5[17]|6[13]|7(?:1|4[0189])|80)|7(?:12|88[01]))[2-7]"],"0$1",1],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["1(?:[2-479]|5[0235-9])|[2-5]|6(?:1[1358]|2[2457-9]|3[2-5]|4[235-7]|5[2-689]|6[24578]|7[235689]|8[1-6])|7(?:1[013-9]|28|3[129]|4[1-35689]|5[29]|6[02-5]|70)|807","1(?:[2-479]|5[0235-9])|[2-5]|6(?:1[1358]|2(?:[2457]|84|95)|3(?:[2-4]|55)|4[235-7]|5[2-689]|6[24578]|7[235689]|8[1-6])|7(?:1(?:[013-8]|9[6-9])|28[6-8]|3(?:17|2[0-49]|9[2-57])|4(?:1[2-4]|[29][0-7]|3[0-8]|[56]|8[0-24-7])|5(?:2[1-3]|9[0-6])|6(?:0[5689]|2[5-9]|3[02-8]|4|5[0-367])|70[13-7])|807[19]","1(?:[2-479]|5(?:[0236-9]|5[013-9]))|[2-5]|6(?:2(?:84|95)|355|83)|73179|807(?:1|9[1-3])|(?:1552|6(?:1[1358]|2[2457]|3[2-4]|4[235-7]|5[2-689]|6[24578]|7[235689]|8[124-6])\\d|7(?:1(?:[013-8]\\d|9[6-9])|28[6-8]|3(?:2[0-49]|9[2-57])|4(?:1[2-4]|[29][0-7]|3[0-8]|[56]\\d|8[0-24-7])|5(?:2[1-3]|9[0-6])|6(?:0[5689]|2[5-9]|3[02-8]|4\\d|5[0-367])|70[13-7]))[2-7]"],"0$1",1],["(\\d{5})(\\d{5})","$1 $2",["[6-9]"],"0$1",1],["(\\d{4})(\\d{2,4})(\\d{4})","$1 $2 $3",["1(?:6|8[06])","1(?:6|8[06]0)"],0,1],["(\\d{4})(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4",["18"],0,1]],"0"],IO:["246","00","3\\d{6}",[7],[["(\\d{3})(\\d{4})","$1 $2",["3"]]]],IQ:["964","00","(?:1|7\\d\\d)\\d{7}|[2-6]\\d{7,8}",[8,9,10],[["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["1"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[2-6]"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["7"],"0$1"]],"0"],IR:["98","00","[1-9]\\d{9}|(?:[1-8]\\d\\d|9)\\d{3,4}",[4,5,6,7,10],[["(\\d{4,5})","$1",["96"],"0$1"],["(\\d{2})(\\d{4,5})","$1 $2",["(?:1[137]|2[13-68]|3[1458]|4[145]|5[1468]|6[16]|7[1467]|8[13467])[12689]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["9"],"0$1"],["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["[1-8]"],"0$1"]],"0"],IS:["354","00|1(?:0(?:01|[12]0)|100)","(?:38\\d|[4-9])\\d{6}",[7,9],[["(\\d{3})(\\d{4})","$1 $2",["[4-9]"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["3"]]],0,0,0,0,0,0,0,"00"],IT:["39","00","0\\d{5,10}|1\\d{8,10}|3(?:[0-8]\\d{7,10}|9\\d{7,8})|(?:43|55|70)\\d{8}|8\\d{5}(?:\\d{2,4})?",[6,7,8,9,10,11,12],[["(\\d{2})(\\d{4,6})","$1 $2",["0[26]"]],["(\\d{3})(\\d{3,6})","$1 $2",["0[13-57-9][0159]|8(?:03|4[17]|9[2-5])","0[13-57-9][0159]|8(?:03|4[17]|9(?:2|3[04]|[45][0-4]))"]],["(\\d{4})(\\d{2,6})","$1 $2",["0(?:[13-579][2-46-8]|8[236-8])"]],["(\\d{4})(\\d{4})","$1 $2",["894"]],["(\\d{2})(\\d{3,4})(\\d{4})","$1 $2 $3",["0[26]|5"]],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["1(?:44|[679])|[378]|43"]],["(\\d{3})(\\d{3,4})(\\d{4})","$1 $2 $3",["0[13-57-9][0159]|14"]],["(\\d{2})(\\d{4})(\\d{5})","$1 $2 $3",["0[26]"]],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["0"]],["(\\d{3})(\\d{4})(\\d{4,5})","$1 $2 $3",["3"]]],0,0,0,0,0,0,[["0669[0-79]\\d{1,6}|0(?:1(?:[0159]\\d|[27][1-5]|31|4[1-4]|6[1356]|8[2-57])|2\\d\\d|3(?:[0159]\\d|2[1-4]|3[12]|[48][1-6]|6[2-59]|7[1-7])|4(?:[0159]\\d|[23][1-9]|4[245]|6[1-5]|7[1-4]|81)|5(?:[0159]\\d|2[1-5]|3[2-6]|4[1-79]|6[4-6]|7[1-578]|8[3-8])|6(?:[0-57-9]\\d|6[0-8])|7(?:[0159]\\d|2[12]|3[1-7]|4[2-46]|6[13569]|7[13-6]|8[1-59])|8(?:[0159]\\d|2[3-578]|3[1-356]|[6-8][1-5])|9(?:[0159]\\d|[238][1-5]|4[12]|6[1-8]|7[1-6]))\\d{2,7}",[6,7,8,9,10,11]],["3[2-9]\\d{7,8}|(?:31|43)\\d{8}",[9,10]],["80(?:0\\d{3}|3)\\d{3}",[6,9]],["(?:0878\\d{3}|89(?:2\\d|3[04]|4(?:[0-4]|[5-9]\\d\\d)|5[0-4]))\\d\\d|(?:1(?:44|6[346])|89(?:38|5[5-9]|9))\\d{6}",[6,8,9,10]],["1(?:78\\d|99)\\d{6}",[9,10]],["3[2-8]\\d{9,10}",[11,12]],0,0,["55\\d{8}",[10]],["84(?:[08]\\d{3}|[17])\\d{3}",[6,9]]]],JE:["44","00","1534\\d{6}|(?:[3578]\\d|90)\\d{8}",[10],0,"0",0,"([0-24-8]\\d{5})$|0","1534$1",0,0,[["1534[0-24-8]\\d{5}"],["7(?:(?:(?:50|82)9|937)\\d|7(?:00[378]|97\\d))\\d{5}"],["80(?:07(?:35|81)|8901)\\d{4}"],["(?:8(?:4(?:4(?:4(?:05|42|69)|703)|5(?:041|800))|7(?:0002|1206))|90(?:066[59]|1810|71(?:07|55)))\\d{4}"],["701511\\d{4}"],0,["(?:3(?:0(?:07(?:35|81)|8901)|3\\d{4}|4(?:4(?:4(?:05|42|69)|703)|5(?:041|800))|7(?:0002|1206))|55\\d{4})\\d{4}"],["76(?:464|652)\\d{5}|76(?:0[0-28]|2[356]|34|4[01347]|5[49]|6[0-369]|77|8[14]|9[139])\\d{6}"],["56\\d{8}"]]],JM:["1","011","(?:[58]\\d\\d|658|900)\\d{7}",[10],0,"1",0,0,0,0,"658|876"],JO:["962","00","(?:(?:[2689]|7\\d)\\d|32|53)\\d{6}",[8,9],[["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["[2356]|87"],"(0$1)"],["(\\d{3})(\\d{5,6})","$1 $2",["[89]"],"0$1"],["(\\d{2})(\\d{7})","$1 $2",["70"],"0$1"],["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["7"],"0$1"]],"0"],JP:["81","010","00[1-9]\\d{6,14}|[257-9]\\d{9}|(?:00|[1-9]\\d\\d)\\d{6}",[8,9,10,11,12,13,14,15,16,17],[["(\\d{3})(\\d{3})(\\d{3})","$1-$2-$3",["(?:12|57|99)0"],"0$1"],["(\\d{4})(\\d)(\\d{4})","$1-$2-$3",["1(?:26|3[79]|4[56]|5[4-68]|6[3-5])|499|5(?:76|97)|746|8(?:3[89]|47|51)|9(?:80|9[16])","1(?:267|3(?:7[247]|9[278])|466|5(?:47|58|64)|6(?:3[245]|48|5[4-68]))|499[2468]|5(?:76|97)9|7468|8(?:3(?:8[7-9]|96)|477|51[2-9])|9(?:802|9(?:1[23]|69))|1(?:45|58)[67]","1(?:267|3(?:7[247]|9[278])|466|5(?:47|58|64)|6(?:3[245]|48|5[4-68]))|499[2468]|5(?:769|979[2-69])|7468|8(?:3(?:8[7-9]|96[2457-9])|477|51[2-9])|9(?:802|9(?:1[23]|69))|1(?:45|58)[67]"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1-$2-$3",["60"],"0$1"],["(\\d)(\\d{4})(\\d{4})","$1-$2-$3",["[36]|4(?:2[09]|7[01])","[36]|4(?:2(?:0|9[02-69])|7(?:0[019]|1))"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1-$2-$3",["1(?:1|5[45]|77|88|9[69])|2(?:2[1-37]|3[0-269]|4[59]|5|6[24]|7[1-358]|8[1369]|9[0-38])|4(?:[28][1-9]|3[0-57]|[45]|6[248]|7[2-579]|9[29])|5(?:2|3[0459]|4[0-369]|5[29]|8[02389]|9[0-389])|7(?:2[02-46-9]|34|[58]|6[0249]|7[57]|9[2-6])|8(?:2[124589]|3[26-9]|49|51|6|7[0-468]|8[68]|9[019])|9(?:[23][1-9]|4[15]|5[138]|6[1-3]|7[156]|8[189]|9[1-489])","1(?:1|5(?:4[018]|5[017])|77|88|9[69])|2(?:2(?:[127]|3[014-9])|3[0-269]|4[59]|5(?:[1-3]|5[0-69]|9[19])|62|7(?:[1-35]|8[0189])|8(?:[16]|3[0134]|9[0-5])|9(?:[028]|17))|4(?:2(?:[13-79]|8[014-6])|3[0-57]|[45]|6[248]|7[2-47]|8[1-9]|9[29])|5(?:2|3(?:[045]|9[0-8])|4[0-369]|5[29]|8[02389]|9[0-3])|7(?:2[02-46-9]|34|[58]|6[0249]|7[57]|9(?:[23]|4[0-59]|5[01569]|6[0167]))|8(?:2(?:[1258]|4[0-39]|9[0-2469])|3(?:[29]|60)|49|51|6(?:[0-24]|36|5[0-3589]|7[23]|9[01459])|7[0-468]|8[68])|9(?:[23][1-9]|4[15]|5[138]|6[1-3]|7[156]|8[189]|9(?:[1289]|3[34]|4[0178]))|(?:264|837)[016-9]|2(?:57|93)[015-9]|(?:25[0468]|422|838)[01]|(?:47[59]|59[89]|8(?:6[68]|9))[019]","1(?:1|5(?:4[018]|5[017])|77|88|9[69])|2(?:2[127]|3[0-269]|4[59]|5(?:[1-3]|5[0-69]|9(?:17|99))|6(?:2|4[016-9])|7(?:[1-35]|8[0189])|8(?:[16]|3[0134]|9[0-5])|9(?:[028]|17))|4(?:2(?:[13-79]|8[014-6])|3[0-57]|[45]|6[248]|7[2-47]|9[29])|5(?:2|3(?:[045]|9(?:[0-58]|6[4-9]|7[0-35689]))|4[0-369]|5[29]|8[02389]|9[0-3])|7(?:2[02-46-9]|34|[58]|6[0249]|7[57]|9(?:[23]|4[0-59]|5[01569]|6[0167]))|8(?:2(?:[1258]|4[0-39]|9[0169])|3(?:[29]|60|7(?:[017-9]|6[6-8]))|49|51|6(?:[0-24]|36[2-57-9]|5(?:[0-389]|5[23])|6(?:[01]|9[178])|7(?:2[2-468]|3[78])|9[0145])|7[0-468]|8[68])|9(?:4[15]|5[138]|7[156]|8[189]|9(?:[1289]|3(?:31|4[357])|4[0178]))|(?:8294|96)[1-3]|2(?:57|93)[015-9]|(?:223|8699)[014-9]|(?:25[0468]|422|838)[01]|(?:48|8292|9[23])[1-9]|(?:47[59]|59[89]|8(?:68|9))[019]"],"0$1"],["(\\d{3})(\\d{2})(\\d{4})","$1-$2-$3",["[14]|[289][2-9]|5[3-9]|7[2-4679]"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1-$2-$3",["800"],"0$1"],["(\\d{2})(\\d{4})(\\d{4})","$1-$2-$3",["[257-9]"],"0$1"]],"0",0,"(000[259]\\d{6})$|(?:(?:003768)0?)|0","$1"],KE:["254","000","(?:[17]\\d\\d|900)\\d{6}|(?:2|80)0\\d{6,7}|[4-6]\\d{6,8}",[7,8,9,10],[["(\\d{2})(\\d{5,7})","$1 $2",["[24-6]"],"0$1"],["(\\d{3})(\\d{6})","$1 $2",["[17]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["[89]"],"0$1"]],"0"],KG:["996","00","8\\d{9}|[235-9]\\d{8}",[9,10],[["(\\d{4})(\\d{5})","$1 $2",["3(?:1[346]|[24-79])"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[235-79]|88"],"0$1"],["(\\d{3})(\\d{3})(\\d)(\\d{2,3})","$1 $2 $3 $4",["8"],"0$1"]],"0"],KH:["855","00[14-9]","1\\d{9}|[1-9]\\d{7,8}",[8,9,10],[["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[1-9]"],"0$1"],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["1"]]],"0"],KI:["686","00","(?:[37]\\d|6[0-79])\\d{6}|(?:[2-48]\\d|50)\\d{3}",[5,8],0,"0"],KM:["269","00","[3478]\\d{6}",[7],[["(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3",["[3478]"]]]],KN:["1","011","(?:[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2-7]\\d{6})$|1","869$1",0,"869"],KP:["850","00|99","85\\d{6}|(?:19\\d|[2-7])\\d{7}",[8,10],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["8"],"0$1"],["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["[2-7]"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["1"],"0$1"]],"0"],KR:["82","00(?:[125689]|3(?:[46]5|91)|7(?:00|27|3|55|6[126]))","00[1-9]\\d{8,11}|(?:[12]|5\\d{3})\\d{7}|[13-6]\\d{9}|(?:[1-6]\\d|80)\\d{7}|[3-6]\\d{4,5}|(?:00|7)0\\d{8}",[5,6,8,9,10,11,12,13,14],[["(\\d{2})(\\d{3,4})","$1-$2",["(?:3[1-3]|[46][1-4]|5[1-5])1"],"0$1"],["(\\d{4})(\\d{4})","$1-$2",["1"]],["(\\d)(\\d{3,4})(\\d{4})","$1-$2-$3",["2"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1-$2-$3",["[36]0|8"],"0$1"],["(\\d{2})(\\d{3,4})(\\d{4})","$1-$2-$3",["[1346]|5[1-5]"],"0$1"],["(\\d{2})(\\d{4})(\\d{4})","$1-$2-$3",["[57]"],"0$1"],["(\\d{2})(\\d{5})(\\d{4})","$1-$2-$3",["5"],"0$1"]],"0",0,"0(8(?:[1-46-8]|5\\d\\d))?"],KW:["965","00","18\\d{5}|(?:[2569]\\d|41)\\d{6}",[7,8],[["(\\d{4})(\\d{3,4})","$1 $2",["[169]|2(?:[235]|4[1-35-9])|52"]],["(\\d{3})(\\d{5})","$1 $2",["[245]"]]]],KY:["1","011","(?:345|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2-9]\\d{6})$|1","345$1",0,"345"],KZ:["7","810","(?:33622|8\\d{8})\\d{5}|[78]\\d{9}",[10,14],0,"8",0,0,0,0,"33|7",0,"8~10"],LA:["856","00","[23]\\d{9}|3\\d{8}|(?:[235-8]\\d|41)\\d{6}",[8,9,10],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["2[13]|3[14]|[4-8]"],"0$1"],["(\\d{2})(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3 $4",["3"],"0$1"],["(\\d{2})(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3 $4",["[23]"],"0$1"]],"0"],LB:["961","00","[27-9]\\d{7}|[13-9]\\d{6}",[7,8],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["[13-69]|7(?:[2-57]|62|8[0-7]|9[04-9])|8[02-9]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[27-9]"]]],"0"],LC:["1","011","(?:[58]\\d\\d|758|900)\\d{7}",[10],0,"1",0,"([2-8]\\d{6})$|1","758$1",0,"758"],LI:["423","00","[68]\\d{8}|(?:[2378]\\d|90)\\d{5}",[7,9],[["(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3",["[2379]|8(?:0[09]|7)","[2379]|8(?:0(?:02|9)|7)"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["8"]],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["69"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["6"]]],"0",0,"(1001)|0"],LK:["94","00","[1-9]\\d{8}",[9],[["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["7"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[1-689]"],"0$1"]],"0"],LR:["231","00","(?:[245]\\d|33|77|88)\\d{7}|(?:2\\d|[4-6])\\d{6}",[7,8,9],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["4[67]|[56]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["2"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[2-578]"],"0$1"]],"0"],LS:["266","00","(?:[256]\\d\\d|800)\\d{5}",[8],[["(\\d{4})(\\d{4})","$1 $2",["[2568]"]]]],LT:["370","00","(?:[3469]\\d|52|[78]0)\\d{6}",[8],[["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["52[0-7]"],"(0-$1)",1],["(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3",["[7-9]"],"0 $1",1],["(\\d{2})(\\d{6})","$1 $2",["37|4(?:[15]|6[1-8])"],"(0-$1)",1],["(\\d{3})(\\d{5})","$1 $2",["[3-6]"],"(0-$1)",1]],"0",0,"[08]"],LU:["352","00","35[013-9]\\d{4,8}|6\\d{8}|35\\d{2,4}|(?:[2457-9]\\d|3[0-46-9])\\d{2,9}",[4,5,6,7,8,9,10,11],[["(\\d{2})(\\d{3})","$1 $2",["2(?:0[2-689]|[2-9])|[3-57]|8(?:0[2-9]|[13-9])|9(?:0[89]|[2-579])"]],["(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3",["2(?:0[2-689]|[2-9])|[3-57]|8(?:0[2-9]|[13-9])|9(?:0[89]|[2-579])"]],["(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3",["20[2-689]"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{1,2})","$1 $2 $3 $4",["2(?:[0367]|4[3-8])"]],["(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3",["80[01]|90[015]"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3 $4",["20"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["6"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{1,2})","$1 $2 $3 $4 $5",["2(?:[0367]|4[3-8])"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{1,5})","$1 $2 $3 $4",["[3-57]|8[13-9]|9(?:0[89]|[2-579])|(?:2|80)[2-9]"]]],0,0,"(15(?:0[06]|1[12]|[35]5|4[04]|6[26]|77|88|99)\\d)"],LV:["371","00","(?:[268]\\d|90)\\d{6}",[8],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[269]|8[01]"]]]],LY:["218","00","[2-9]\\d{8}",[9],[["(\\d{2})(\\d{7})","$1-$2",["[2-9]"],"0$1"]],"0"],MA:["212","00","[5-8]\\d{8}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["5[45]"],"0$1"],["(\\d{4})(\\d{5})","$1-$2",["5(?:2[2-46-9]|3[3-9]|9)|8(?:0[89]|92)"],"0$1"],["(\\d{2})(\\d{7})","$1-$2",["8"],"0$1"],["(\\d{3})(\\d{6})","$1-$2",["[5-7]"],"0$1"]],"0",0,0,0,0,0,[["5(?:2(?:[0-25-79]\\d|3[1-578]|4[02-46-8]|8[0235-7])|3(?:[0-47]\\d|5[02-9]|6[02-8]|8[014-9]|9[3-9])|(?:4[067]|5[03])\\d)\\d{5}"],["(?:6(?:[0-79]\\d|8[0-247-9])|7(?:[0167]\\d|2[0-467]|5[0-3]|8[0-7]))\\d{6}"],["80[0-7]\\d{6}"],["89\\d{7}"],0,0,0,0,["(?:592(?:4[0-2]|93)|80[89]\\d\\d)\\d{4}"]]],MC:["377","00","(?:[3489]|6\\d)\\d{7}",[8,9],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["4"],"0$1"],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[389]"]],["(\\d)(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4 $5",["6"],"0$1"]],"0"],MD:["373","00","(?:[235-7]\\d|[89]0)\\d{6}",[8],[["(\\d{3})(\\d{5})","$1 $2",["[89]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["22|3"],"0$1"],["(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3",["[25-7]"],"0$1"]],"0"],ME:["382","00","(?:20|[3-79]\\d)\\d{6}|80\\d{6,7}",[8,9],[["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[2-9]"],"0$1"]],"0"],MF:["590","00","(?:590\\d|7090)\\d{5}|(?:69|80|9\\d)\\d{7}",[9],0,"0",0,0,0,0,0,[["590(?:0[079]|[14]3|[27][79]|3[03-7]|5[0-268]|87)\\d{4}"],["(?:69(?:0\\d\\d|1(?:2[2-9]|3[0-5])|4(?:0[89]|1[2-6]|9\\d)|6(?:1[016-9]|5[0-4]|[67]\\d))|7090[0-4])\\d{4}"],["80[0-5]\\d{6}"],0,0,0,0,0,["9(?:(?:39[5-7]|76[018])\\d|475[0-6])\\d{4}"]]],MG:["261","00","[23]\\d{8}",[9],[["(\\d{2})(\\d{2})(\\d{3})(\\d{2})","$1 $2 $3 $4",["[23]"],"0$1"]],"0",0,"([24-9]\\d{6})$|0","20$1"],MH:["692","011","329\\d{4}|(?:[256]\\d|45)\\d{5}",[7],[["(\\d{3})(\\d{4})","$1-$2",["[2-6]"]]],"1"],MK:["389","00","[2-578]\\d{7}",[8],[["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["2|34[47]|4(?:[37]7|5[47]|64)"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[347]"],"0$1"],["(\\d{3})(\\d)(\\d{2})(\\d{2})","$1 $2 $3 $4",["[58]"],"0$1"]],"0"],ML:["223","00","[24-9]\\d{7}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[24-9]"]]]],MM:["95","00","1\\d{5,7}|95\\d{6}|(?:[4-7]|9[0-46-9])\\d{6,8}|(?:2|8\\d)\\d{5,8}",[6,7,8,9,10],[["(\\d)(\\d{2})(\\d{3})","$1 $2 $3",["16|2"],"0$1"],["(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3",["4(?:[2-46]|5[3-5])|5|6(?:[1-689]|7[235-7])|7(?:[0-4]|5[2-7])|8[1-5]|(?:60|86)[23]"],"0$1"],["(\\d)(\\d{3})(\\d{3,4})","$1 $2 $3",["[12]|452|678|86","[12]|452|6788|86"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[4-7]|8[1-35]"],"0$1"],["(\\d)(\\d{3})(\\d{4,6})","$1 $2 $3",["9(?:2[0-4]|[35-9]|4[137-9])"],"0$1"],["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["2"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["8"],"0$1"],["(\\d)(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4",["92"],"0$1"],["(\\d)(\\d{5})(\\d{4})","$1 $2 $3",["9"],"0$1"]],"0"],MN:["976","001","[12]\\d{7,9}|[5-9]\\d{7}",[8,9,10],[["(\\d{2})(\\d{2})(\\d{4})","$1 $2 $3",["[12]1"],"0$1"],["(\\d{4})(\\d{4})","$1 $2",["[5-9]"]],["(\\d{3})(\\d{5,6})","$1 $2",["[12]2[1-3]"],"0$1"],["(\\d{4})(\\d{5,6})","$1 $2",["[12](?:27|3[2-8]|4[2-68]|5[1-4689])","[12](?:27|3[2-8]|4[2-68]|5[1-4689])[0-3]"],"0$1"],["(\\d{5})(\\d{4,5})","$1 $2",["[12]"],"0$1"]],"0"],MO:["853","00","0800\\d{3}|(?:28|[68]\\d)\\d{6}",[7,8],[["(\\d{4})(\\d{3})","$1 $2",["0"]],["(\\d{4})(\\d{4})","$1 $2",["[268]"]]]],MP:["1","011","[58]\\d{9}|(?:67|90)0\\d{7}",[10],0,"1",0,"([2-9]\\d{6})$|1","670$1",0,"670"],MQ:["596","00","(?:596\\d|7091)\\d{5}|(?:69|[89]\\d)\\d{7}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[5-79]|8(?:0[6-9]|[36])"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"],"0$1"]],"0"],MR:["222","00","(?:[2-4]\\d\\d|800)\\d{5}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[2-48]"]]]],MS:["1","011","(?:[58]\\d\\d|664|900)\\d{7}",[10],0,"1",0,"([34]\\d{6})$|1","664$1",0,"664"],MT:["356","00","3550\\d{4}|(?:[2579]\\d\\d|800)\\d{5}",[8],[["(\\d{4})(\\d{4})","$1 $2",["[2357-9]"]]]],MU:["230","0(?:0|[24-7]0|3[03])","(?:[57]|8\\d\\d)\\d{7}|[2-468]\\d{6}",[7,8,10],[["(\\d{3})(\\d{4})","$1 $2",["[2-46]|8[013]"]],["(\\d{4})(\\d{4})","$1 $2",["[57]"]],["(\\d{5})(\\d{5})","$1 $2",["8"]]],0,0,0,0,0,0,0,"020"],MV:["960","0(?:0|19)","(?:800|9[0-57-9]\\d)\\d{7}|[34679]\\d{6}",[7,10],[["(\\d{3})(\\d{4})","$1-$2",["[34679]"]],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[89]"]]],0,0,0,0,0,0,0,"00"],MW:["265","00","(?:[1289]\\d|31|77)\\d{7}|1\\d{6}",[7,9],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["1[2-9]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["2"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[137-9]"],"0$1"]],"0"],MX:["52","0[09]","[2-9]\\d{9}",[10],[["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["33|5[56]|81"]],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[2-9]"]]],0,0,0,0,0,0,0,"00"],MY:["60","00","1\\d{8,9}|(?:3\\d|[4-9])\\d{7}",[8,9,10],[["(\\d)(\\d{3})(\\d{4})","$1-$2 $3",["[4-79]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1-$2 $3",["1(?:[02469]|[378][1-9]|53)|8","1(?:[02469]|[37][1-9]|53|8(?:[1-46-9]|5[7-9]))|8"],"0$1"],["(\\d)(\\d{4})(\\d{4})","$1-$2 $3",["3"],"0$1"],["(\\d)(\\d{3})(\\d{2})(\\d{4})","$1-$2-$3-$4",["1(?:[367]|80)"]],["(\\d{3})(\\d{3})(\\d{4})","$1-$2 $3",["15"],"0$1"],["(\\d{2})(\\d{4})(\\d{4})","$1-$2 $3",["1"],"0$1"]],"0"],MZ:["258","00","(?:2|8\\d)\\d{7}",[8,9],[["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["2|8[2-79]"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["8"]]]],NA:["264","00","[68]\\d{7,8}",[8,9],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["88"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["6"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["87"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["8"],"0$1"]],"0"],NC:["687","00","(?:050|[2-57-9]\\d\\d)\\d{3}",[6],[["(\\d{2})(\\d{2})(\\d{2})","$1.$2.$3",["[02-57-9]"]]]],NE:["227","00","[027-9]\\d{7}",[8],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["08"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[089]|2[013]|7[0467]"]]]],NF:["672","00","[13]\\d{5}",[6],[["(\\d{2})(\\d{4})","$1 $2",["1[0-3]"]],["(\\d)(\\d{5})","$1 $2",["[13]"]]],0,0,"([0-258]\\d{4})$","3$1"],NG:["234","009","(?:20|9\\d)\\d{8}|[78]\\d{9,13}",[10,11,12,13,14],[["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["[7-9]"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["20[129]"],"0$1"],["(\\d{4})(\\d{2})(\\d{4})","$1 $2 $3",["2"],"0$1"],["(\\d{3})(\\d{4})(\\d{4,5})","$1 $2 $3",["[78]"],"0$1"],["(\\d{3})(\\d{5})(\\d{5,6})","$1 $2 $3",["[78]"],"0$1"]],"0"],NI:["505","00","(?:1800|[25-8]\\d{3})\\d{4}",[8],[["(\\d{4})(\\d{4})","$1 $2",["[125-8]"]]]],NL:["31","00","(?:[124-7]\\d\\d|3(?:[02-9]\\d|1[0-8]))\\d{6}|8\\d{6,9}|9\\d{6,10}|1\\d{4,5}",[5,6,7,8,9,10,11],[["(\\d{3})(\\d{4,7})","$1 $2",["[89]0"],"0$1"],["(\\d{2})(\\d{7})","$1 $2",["66"],"0$1"],["(\\d)(\\d{8})","$1 $2",["6"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["1[16-8]|2[259]|3[124]|4[17-9]|5[124679]"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[1-578]|91"],"0$1"],["(\\d{3})(\\d{3})(\\d{5})","$1 $2 $3",["9"],"0$1"]],"0"],NO:["47","00","(?:0|[2-9]\\d{3})\\d{4}",[5,8],[["(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3",["8"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[2-79]"]]],0,0,0,0,0,"[02-689]|7[0-8]"],NP:["977","00","(?:1\\d|9)\\d{9}|[1-9]\\d{7}",[8,10,11],[["(\\d)(\\d{7})","$1-$2",["1[2-6]"],"0$1"],["(\\d{2})(\\d{6})","$1-$2",["1[01]|[2-8]|9(?:[1-59]|[67][2-6])"],"0$1"],["(\\d{3})(\\d{7})","$1-$2",["9"]]],"0"],NR:["674","00","(?:222|444|(?:55|8\\d)\\d|666|777|999)\\d{4}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[24-9]"]]]],NU:["683","00","(?:[4-7]|888\\d)\\d{3}",[4,7],[["(\\d{3})(\\d{4})","$1 $2",["8"]]]],NZ:["64","0(?:0|161)","[1289]\\d{9}|50\\d{5}(?:\\d{2,3})?|[27-9]\\d{7,8}|(?:[34]\\d|6[0-35-9])\\d{6}|8\\d{4,6}",[5,6,7,8,9,10],[["(\\d{2})(\\d{3,8})","$1 $2",["8[1-79]"],"0$1"],["(\\d{3})(\\d{2})(\\d{2,3})","$1 $2 $3",["50[036-8]|8|90","50(?:[0367]|88)|8|90"],"0$1"],["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["24|[346]|7[2-57-9]|9[2-9]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["2(?:10|74)|[589]"],"0$1"],["(\\d{2})(\\d{3,4})(\\d{4})","$1 $2 $3",["1|2[028]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,5})","$1 $2 $3",["2(?:[169]|7[0-35-9])|7"],"0$1"]],"0",0,0,0,0,0,0,"00"],OM:["968","00","(?:1505|[279]\\d{3}|500)\\d{4}|800\\d{5,6}",[7,8,9],[["(\\d{3})(\\d{4,6})","$1 $2",["[58]"]],["(\\d{2})(\\d{6})","$1 $2",["2"]],["(\\d{4})(\\d{4})","$1 $2",["[179]"]]]],PA:["507","00","(?:00800|8\\d{3})\\d{6}|[68]\\d{7}|[1-57-9]\\d{6}",[7,8,10,11],[["(\\d{3})(\\d{4})","$1-$2",["[1-57-9]"]],["(\\d{4})(\\d{4})","$1-$2",["[68]"]],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["8"]]]],PE:["51","00|19(?:1[124]|77|90)00","(?:[14-8]|9\\d)\\d{7}",[8,9],[["(\\d{3})(\\d{5})","$1 $2",["80"],"(0$1)"],["(\\d)(\\d{7})","$1 $2",["1"],"(0$1)"],["(\\d{2})(\\d{6})","$1 $2",["[4-8]"],"(0$1)"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["9"]]],"0",0,0,0,0,0,0,"00"," Anexo "],PF:["689","00","4\\d{5}(?:\\d{2})?|8\\d{7,8}",[6,8,9],[["(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3",["44"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["4|8[7-9]"]],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"]]]],PG:["675","00|140[1-3]","(?:180|[78]\\d{3})\\d{4}|(?:[2-589]\\d|64)\\d{5}",[7,8],[["(\\d{3})(\\d{4})","$1 $2",["18|[2-69]|85"]],["(\\d{4})(\\d{4})","$1 $2",["[78]"]]],0,0,0,0,0,0,0,"00"],PH:["63","00","(?:[2-7]|9\\d)\\d{8}|2\\d{5}|(?:1800|8)\\d{7,9}",[6,8,9,10,11,12,13],[["(\\d)(\\d{5})","$1 $2",["2"],"(0$1)"],["(\\d{4})(\\d{4,6})","$1 $2",["3(?:23|39|46)|4(?:2[3-6]|[35]9|4[26]|76)|544|88[245]|(?:52|64|86)2","3(?:230|397|461)|4(?:2(?:35|[46]4|51)|396|4(?:22|63)|59[347]|76[15])|5(?:221|446)|642[23]|8(?:622|8(?:[24]2|5[13]))"],"(0$1)"],["(\\d{5})(\\d{4})","$1 $2",["346|4(?:27|9[35])|883","3469|4(?:279|9(?:30|56))|8834"],"(0$1)"],["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["2"],"(0$1)"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[3-7]|8[2-8]"],"(0$1)"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[89]"],"0$1"],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["1"]],["(\\d{4})(\\d{1,2})(\\d{3})(\\d{4})","$1 $2 $3 $4",["1"]]],"0"],PK:["92","00","122\\d{6}|[24-8]\\d{10,11}|9(?:[013-9]\\d{8,10}|2(?:[01]\\d\\d|2(?:[06-8]\\d|1[01]))\\d{7})|(?:[2-8]\\d{3}|92(?:[0-7]\\d|8[1-9]))\\d{6}|[24-9]\\d{8}|[89]\\d{7}",[8,9,10,11,12],[["(\\d{3})(\\d{3})(\\d{2,7})","$1 $2 $3",["[89]0"],"0$1"],["(\\d{4})(\\d{5})","$1 $2",["1"]],["(\\d{3})(\\d{6,7})","$1 $2",["2(?:3[2358]|4[2-4]|9[2-8])|45[3479]|54[2-467]|60[468]|72[236]|8(?:2[2-689]|3[23578]|4[3478]|5[2356])|9(?:2[2-8]|3[27-9]|4[2-6]|6[3569]|9[25-8])","9(?:2[3-8]|98)|(?:2(?:3[2358]|4[2-4]|9[2-8])|45[3479]|54[2-467]|60[468]|72[236]|8(?:2[2-689]|3[23578]|4[3478]|5[2356])|9(?:22|3[27-9]|4[2-6]|6[3569]|9[25-7]))[2-9]"],"(0$1)"],["(\\d{2})(\\d{7,8})","$1 $2",["(?:2[125]|4[0-246-9]|5[1-35-7]|6[1-8]|7[14]|8[16]|91)[2-9]"],"(0$1)"],["(\\d{5})(\\d{5})","$1 $2",["58"],"(0$1)"],["(\\d{3})(\\d{7})","$1 $2",["3"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4",["2[125]|4[0-246-9]|5[1-35-7]|6[1-8]|7[14]|8[16]|91"],"(0$1)"],["(\\d{3})(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4",["[24-9]"],"(0$1)"]],"0"],PL:["48","00","(?:6|8\\d\\d)\\d{7}|[1-9]\\d{6}(?:\\d{2})?|[26]\\d{5}",[6,7,8,9,10],[["(\\d{5})","$1",["19"]],["(\\d{3})(\\d{3})","$1 $2",["11|20|64"]],["(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3",["(?:1[2-8]|2[2-69]|3[2-4]|4[1-468]|5[24-689]|6[1-3578]|7[14-7]|8[1-79]|9[145])1","(?:1[2-8]|2[2-69]|3[2-4]|4[1-468]|5[24-689]|6[1-3578]|7[14-7]|8[1-79]|9[145])19"]],["(\\d{3})(\\d{2})(\\d{2,3})","$1 $2 $3",["64"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["21|39|45|5[0137]|6[0469]|7[02389]|8(?:0[14]|8)"]],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["1[2-8]|[2-7]|8[1-79]|9[145]"]],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["8"]]]],PM:["508","00","[45]\\d{5}|(?:708|8\\d\\d)\\d{6}",[6,9],[["(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3",["[45]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["7"]],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"],"0$1"]],"0"],PR:["1","011","(?:[589]\\d\\d|787)\\d{7}",[10],0,"1",0,0,0,0,"787|939"],PS:["970","00","[2489]2\\d{6}|(?:1\\d|5)\\d{8}",[8,9,10],[["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["[2489]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["5"],"0$1"],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["1"]]],"0"],PT:["351","00","1693\\d{5}|(?:[26-9]\\d|30)\\d{7}",[9],[["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["2[12]"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["16|[236-9]"]]]],PW:["680","01[12]","(?:[24-8]\\d\\d|345|900)\\d{4}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[2-9]"]]]],PY:["595","00","59\\d{4,6}|9\\d{5,10}|(?:[2-46-8]\\d|5[0-8])\\d{4,7}",[6,7,8,9,10,11],[["(\\d{3})(\\d{3,6})","$1 $2",["[2-9]0"],"0$1"],["(\\d{2})(\\d{5})","$1 $2",["[26]1|3[289]|4[1246-8]|7[1-3]|8[1-36]"],"(0$1)"],["(\\d{3})(\\d{4,5})","$1 $2",["2[279]|3[13-5]|4[359]|5|6(?:[34]|7[1-46-8])|7[46-8]|85"],"(0$1)"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["2[14-68]|3[26-9]|4[1246-8]|6(?:1|75)|7[1-35]|8[1-36]"],"(0$1)"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["87"]],["(\\d{3})(\\d{6})","$1 $2",["9(?:[5-79]|8[1-7])"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[2-8]"],"0$1"],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["9"]]],"0"],QA:["974","00","800\\d{4}|(?:2|800)\\d{6}|(?:0080|[3-7])\\d{7}",[7,8,9,11],[["(\\d{3})(\\d{4})","$1 $2",["2[136]|8"]],["(\\d{4})(\\d{4})","$1 $2",["[3-7]"]]]],RE:["262","00","709\\d{6}|(?:26|[689]\\d)\\d{7}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[26-9]"],"0$1"]],"0",0,0,0,0,0,[["26(?:2\\d\\d|3(?:0\\d|1[0-6]))\\d{4}"],["(?:69(?:2\\d\\d|3(?:[06][0-6]|1[0-3]|2[0-2]|3[0-39]|4\\d|5[0-5]|7[0-37]|8[0-8]|9[0-479]))|7092[0-3])\\d{4}"],["80\\d{7}"],["89[1-37-9]\\d{6}"],0,0,0,0,["9(?:399[0-3]|479[0-6]|76(?:2[278]|3[0-37]))\\d{4}"],["8(?:1[019]|2[0156]|84|90)\\d{6}"]]],RO:["40","00","(?:[236-8]\\d|90)\\d{7}|[23]\\d{5}",[6,9],[["(\\d{3})(\\d{3})","$1 $2",["2[3-6]","2[3-6]\\d9"],"0$1"],["(\\d{2})(\\d{4})","$1 $2",["219|31"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[23]1"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[236-9]"],"0$1"]],"0",0,0,0,0,0,0,0," int "],RS:["381","00","38[02-9]\\d{6,9}|6\\d{7,9}|90\\d{4,8}|38\\d{5,6}|(?:7\\d\\d|800)\\d{3,9}|(?:[12]\\d|3[0-79])\\d{5,10}",[6,7,8,9,10,11,12],[["(\\d{3})(\\d{3,9})","$1 $2",["(?:2[389]|39)0|[7-9]"],"0$1"],["(\\d{2})(\\d{5,10})","$1 $2",["[1-36]"],"0$1"]],"0"],RU:["7","810","8\\d{13}|[347-9]\\d{9}",[10,14],[["(\\d{4})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["7(?:1[0-8]|2[1-9])","7(?:1(?:[0-356]2|4[29]|7|8[27])|2(?:1[23]|[2-9]2))","7(?:1(?:[0-356]2|4[29]|7|8[27])|2(?:13[03-69]|62[013-9]))|72[1-57-9]2"],"8 ($1)",1],["(\\d{5})(\\d)(\\d{2})(\\d{2})","$1 $2 $3 $4",["7(?:1[0-68]|2[1-9])","7(?:1(?:[06][3-6]|[18]|2[35]|[3-5][3-5])|2(?:[13][3-5]|[24-689]|7[457]))","7(?:1(?:0(?:[356]|4[023])|[18]|2(?:3[013-9]|5)|3[45]|43[013-79]|5(?:3[1-8]|4[1-7]|5)|6(?:3[0-35-9]|[4-6]))|2(?:1(?:3[178]|[45])|[24-689]|3[35]|7[457]))|7(?:14|23)4[0-8]|71(?:33|45)[1-79]"],"8 ($1)",1],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["7"],"8 ($1)",1],["(\\d{3})(\\d{3})(\\d{2})(\\d{2})","$1 $2-$3-$4",["[349]|8(?:[02-7]|1[1-8])"],"8 ($1)",1],["(\\d{4})(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3 $4",["8"],"8 ($1)"]],"8",0,0,0,0,"3[04-689]|[489]",0,"8~10"],RW:["250","00","(?:06|[27]\\d\\d|[89]00)\\d{6}",[8,9],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["0"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["2"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[7-9]"],"0$1"]],"0"],SA:["966","00","92\\d{7}|(?:[15]|8\\d)\\d{8}",[9,10],[["(\\d{4})(\\d{5})","$1 $2",["9"]],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["1"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["5"],"0$1"],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["81"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["8"]]],"0"],SB:["677","0[01]","[6-9]\\d{6}|[1-6]\\d{4}",[5,7],[["(\\d{2})(\\d{5})","$1 $2",["6[89]|7|8[4-9]|9(?:[1-8]|9[0-8])"]]]],SC:["248","010|0[0-2]","(?:[2489]\\d|64)\\d{5}",[7],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["[246]|9[57]"]]],0,0,0,0,0,0,0,"00"],SD:["249","00","[19]\\d{8}",[9],[["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[19]"],"0$1"]],"0"],SE:["46","00","(?:[26]\\d\\d|9)\\d{9}|[1-9]\\d{8}|[1-689]\\d{7}|[1-4689]\\d{6}|2\\d{5}",[6,7,8,9,10,12],[["(\\d{2})(\\d{2,3})(\\d{2})","$1-$2 $3",["20"],"0$1",0,"$1 $2 $3"],["(\\d{3})(\\d{4})","$1-$2",["9(?:00|39|44|9)"],"0$1",0,"$1 $2"],["(\\d{2})(\\d{3})(\\d{2})","$1-$2 $3",["[12][136]|3[356]|4[0246]|6[03]|90[1-9]"],"0$1",0,"$1 $2 $3"],["(\\d)(\\d{2,3})(\\d{2})(\\d{2})","$1-$2 $3 $4",["8"],"0$1",0,"$1 $2 $3 $4"],["(\\d{3})(\\d{2,3})(\\d{2})","$1-$2 $3",["1[2457]|2(?:[247-9]|5[0138])|3[0247-9]|4[1357-9]|5[0-35-9]|6(?:[125689]|4[02-57]|7[0-2])|9(?:[125-8]|3[02-5]|4[0-3])"],"0$1",0,"$1 $2 $3"],["(\\d{3})(\\d{2,3})(\\d{3})","$1-$2 $3",["9(?:00|39|44)"],"0$1",0,"$1 $2 $3"],["(\\d{2})(\\d{2,3})(\\d{2})(\\d{2})","$1-$2 $3 $4",["1[13689]|2[0136]|3[1356]|4[0246]|54|6[03]|90[1-9]"],"0$1",0,"$1 $2 $3 $4"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1-$2 $3 $4",["10|7"],"0$1",0,"$1 $2 $3 $4"],["(\\d)(\\d{3})(\\d{3})(\\d{2})","$1-$2 $3 $4",["8"],"0$1",0,"$1 $2 $3 $4"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1-$2 $3 $4",["[13-5]|2(?:[247-9]|5[0138])|6(?:[124-689]|7[0-2])|9(?:[125-8]|3[02-5]|4[0-3])"],"0$1",0,"$1 $2 $3 $4"],["(\\d{3})(\\d{2})(\\d{2})(\\d{3})","$1-$2 $3 $4",["9"],"0$1",0,"$1 $2 $3 $4"],["(\\d{3})(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1-$2 $3 $4 $5",["[26]"],"0$1",0,"$1 $2 $3 $4 $5"]],"0"],SG:["65","0[0-3]\\d","(?:(?:1\\d|8)\\d\\d|7000)\\d{7}|[3689]\\d{7}",[8,10,11],[["(\\d{4})(\\d{4})","$1 $2",["[369]|8(?:0[1-9]|[1-9])"]],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["8"]],["(\\d{4})(\\d{4})(\\d{3})","$1 $2 $3",["7"]],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["1"]]]],SH:["290","00","(?:[256]\\d|8)\\d{3}",[4,5],0,0,0,0,0,0,"[256]"],SI:["386","00|10(?:22|66|88|99)","[1-7]\\d{7}|8\\d{4,7}|90\\d{4,6}",[5,6,7,8],[["(\\d{2})(\\d{3,6})","$1 $2",["8[09]|9"],"0$1"],["(\\d{3})(\\d{5})","$1 $2",["59|8"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[37][01]|4[0139]|51|6"],"0$1"],["(\\d)(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[1-57]"],"(0$1)"]],"0",0,0,0,0,0,0,"00"],SJ:["47","00","0\\d{4}|(?:[489]\\d|79)\\d{6}",[5,8],0,0,0,0,0,0,"79"],SK:["421","00","[2-689]\\d{8}|[2-59]\\d{6}|[2-5]\\d{5}",[6,7,9],[["(\\d)(\\d{2})(\\d{3,4})","$1 $2 $3",["21"],"0$1"],["(\\d{2})(\\d{2})(\\d{2,3})","$1 $2 $3",["[3-5][1-8]1","[3-5][1-8]1[67]"],"0$1"],["(\\d)(\\d{3})(\\d{3})(\\d{2})","$1/$2 $3 $4",["2"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[689]"],"0$1"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1/$2 $3 $4",["[3-5]"],"0$1"]],"0"],SL:["232","00","(?:[237-9]\\d|66)\\d{6}",[8],[["(\\d{2})(\\d{6})","$1 $2",["[236-9]"],"(0$1)"]],"0"],SM:["378","00","(?:0549|[5-7]\\d)\\d{6}",[8,10],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[5-7]"]],["(\\d{4})(\\d{6})","$1 $2",["0"]]],0,0,"([89]\\d{5})$","0549$1"],SN:["221","00","(?:[378]\\d|93)\\d{7}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"]],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[379]"]]]],SO:["252","00","[346-9]\\d{8}|[12679]\\d{7}|[1-5]\\d{6}|[1348]\\d{5}",[6,7,8,9],[["(\\d{2})(\\d{4})","$1 $2",["8[125]"]],["(\\d{6})","$1",["[134]"]],["(\\d)(\\d{6})","$1 $2",["[15]|2[0-79]|3[0-46-8]|4[0-7]"]],["(\\d)(\\d{7})","$1 $2",["(?:2|90)4|[67]"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[348]|64|79|90"]],["(\\d{2})(\\d{5,7})","$1 $2",["1|28|6[0-35-9]|7[67]|9[2-9]"]]],"0"],SR:["597","00","(?:[2-5]|68|[78]\\d|90)\\d{5}",[6,7],[["(\\d{2})(\\d{2})(\\d{2})","$1-$2-$3",["56"]],["(\\d{3})(\\d{3})","$1-$2",["[2-5]"]],["(\\d{3})(\\d{4})","$1-$2",["[6-9]"]]]],SS:["211","00","[19]\\d{8}",[9],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[19]"],"0$1"]],"0"],ST:["239","00","(?:22|9\\d)\\d{5}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[29]"]]]],SV:["503","00","[267]\\d{7}|(?:80\\d|900)\\d{4}(?:\\d{4})?",[7,8,11],[["(\\d{3})(\\d{4})","$1 $2",["[89]"]],["(\\d{4})(\\d{4})","$1 $2",["[267]"]],["(\\d{3})(\\d{4})(\\d{4})","$1 $2 $3",["[89]"]]]],SX:["1","011","7215\\d{6}|(?:[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"(5\\d{6})$|1","721$1",0,"721"],SY:["963","00","[1-39]\\d{8}|[1-5]\\d{7}",[8,9],[["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[1-5]"],"0$1",1],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["9"],"0$1",1]],"0"],SZ:["268","00","0800\\d{4}|(?:[237]\\d|900)\\d{6}",[8,9],[["(\\d{4})(\\d{4})","$1 $2",["[0237]"]],["(\\d{5})(\\d{4})","$1 $2",["9"]]]],TA:["290","00","8\\d{3}",[4],0,0,0,0,0,0,"8"],TC:["1","011","(?:[58]\\d\\d|649|900)\\d{7}",[10],0,"1",0,"([2-479]\\d{6})$|1","649$1",0,"649"],TD:["235","00|16","(?:22|[689]\\d|77)\\d{6}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[26-9]"]]],0,0,0,0,0,0,0,"00"],TG:["228","00","[279]\\d{7}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[279]"]]]],TH:["66","00[1-9]","(?:001800|[2-57]|[689]\\d)\\d{7}|1\\d{7,9}",[8,9,10,13],[["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["2"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[13-9]"],"0$1"],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["1"]]],"0"],TJ:["992","810","[0-57-9]\\d{8}",[9],[["(\\d{6})(\\d)(\\d{2})","$1 $2 $3",["331","3317"]],["(\\d{3})(\\d{2})(\\d{4})","$1 $2 $3",["44[02-479]|[34]7"]],["(\\d{4})(\\d)(\\d{4})","$1 $2 $3",["3(?:[1245]|3[12])"]],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[0-57-9]"]]],0,0,0,0,0,0,0,"8~10"],TK:["690","00","[2-47]\\d{3,6}",[4,5,6,7]],TL:["670","00","7\\d{7}|(?:[2-47]\\d|[89]0)\\d{5}",[7,8],[["(\\d{3})(\\d{4})","$1 $2",["[2-489]|70"]],["(\\d{4})(\\d{4})","$1 $2",["7"]]]],TM:["993","810","(?:[1-6]\\d|71)\\d{6}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2-$3-$4",["12"],"(8 $1)"],["(\\d{3})(\\d)(\\d{2})(\\d{2})","$1 $2-$3-$4",["[1-5]"],"(8 $1)"],["(\\d{2})(\\d{6})","$1 $2",["[67]"],"8 $1"]],"8",0,0,0,0,0,0,"8~10"],TN:["216","00","[2-57-9]\\d{7}",[8],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[2-57-9]"]]]],TO:["676","00","(?:0800|(?:[5-8]\\d\\d|999)\\d)\\d{3}|[2-8]\\d{4}",[5,7],[["(\\d{2})(\\d{3})","$1-$2",["[2-4]|50|6[09]|7[0-24-69]|8[05]"]],["(\\d{4})(\\d{3})","$1 $2",["0"]],["(\\d{3})(\\d{4})","$1 $2",["[5-9]"]]]],TR:["90","00","4\\d{6}|8\\d{11,12}|(?:[2-58]\\d\\d|900)\\d{7}",[7,10,12,13],[["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["512|8[01589]|90"],"0$1",1],["(\\d{3})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["5(?:[0-59]|61)","5(?:[0-59]|61[06])","5(?:[0-59]|61[06]1)"],"0$1",1],["(\\d{3})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[24][1-8]|3[1-9]"],"(0$1)",1],["(\\d{3})(\\d{3})(\\d{6,7})","$1 $2 $3",["80"],"0$1",1]],"0"],TT:["1","011","(?:[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2-46-8]\\d{6})$|1","868$1",0,"868"],TV:["688","00","(?:2|7\\d\\d|90)\\d{4}",[5,6,7],[["(\\d{2})(\\d{3})","$1 $2",["2"]],["(\\d{2})(\\d{4})","$1 $2",["90"]],["(\\d{2})(\\d{5})","$1 $2",["7"]]]],TW:["886","0(?:0[25-79]|19)","[2-689]\\d{8}|7\\d{9,10}|[2-8]\\d{7}|2\\d{6}",[7,8,9,10,11],[["(\\d{2})(\\d)(\\d{4})","$1 $2 $3",["202"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[258]0"],"0$1"],["(\\d)(\\d{3,4})(\\d{4})","$1 $2 $3",["[23568]|4(?:0[02-48]|[1-47-9])|7[1-9]","[23568]|4(?:0[2-48]|[1-47-9])|(?:400|7)[1-9]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[49]"],"0$1"],["(\\d{2})(\\d{4})(\\d{4,5})","$1 $2 $3",["7"],"0$1"]],"0",0,0,0,0,0,0,0,"#"],TZ:["255","00[056]","(?:[25-8]\\d|41|90)\\d{7}",[9],[["(\\d{3})(\\d{2})(\\d{4})","$1 $2 $3",["[89]"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[24]"],"0$1"],["(\\d{2})(\\d{7})","$1 $2",["5"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[67]"],"0$1"]],"0"],UA:["380","00","[89]\\d{9}|[3-9]\\d{8}",[9,10],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["6[12][29]|(?:3[1-8]|4[136-8]|5[12457]|6[49])2|(?:56|65)[24]","6[12][29]|(?:35|4[1378]|5[12457]|6[49])2|(?:56|65)[24]|(?:3[1-46-8]|46)2[013-9]"],"0$1"],["(\\d{4})(\\d{5})","$1 $2",["3[1-8]|4(?:[1367]|[45][6-9]|8[4-6])|5(?:[1-5]|6[0135689]|7[4-6])|6(?:[12][3-7]|[459])","3[1-8]|4(?:[1367]|[45][6-9]|8[4-6])|5(?:[1-5]|6(?:[015689]|3[02389])|7[4-6])|6(?:[12][3-7]|[459])"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[3-7]|89|9[1-9]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["[89]"],"0$1"]],"0",0,0,0,0,0,0,"0~0"],UG:["256","00[057]","800\\d{6}|(?:[29]0|[347]\\d)\\d{7}",[9],[["(\\d{4})(\\d{5})","$1 $2",["202","2024"],"0$1"],["(\\d{3})(\\d{6})","$1 $2",["[27-9]|4(?:6[45]|[7-9])"],"0$1"],["(\\d{2})(\\d{7})","$1 $2",["[34]"],"0$1"]],"0"],US:["1","011","[2-9]\\d{9}|3\\d{6}",[10],[["(\\d{3})(\\d{4})","$1-$2",["310"],0,1],["(\\d{3})(\\d{3})(\\d{4})","($1) $2-$3",["[2-9]"],0,1,"$1-$2-$3"]],"1",0,0,0,0,0,[["(?:3052(?:0[0-8]|[1-9]\\d)|5056(?:[0-35-9]\\d|4[0-468]))\\d{4}|(?:2742|305[3-9]|472[247-9]|505[2-57-9]|983[2-47-9])\\d{6}|(?:2(?:0[1-35-9]|1[02-9]|2[03-57-9]|3[1459]|4[08]|5[1-46]|6[0279]|7[0269]|8[13])|3(?:0[1-47-9]|1[02-9]|2[0135-79]|3[0-24679]|4[167]|5[0-2]|6[01349]|8[056])|4(?:0[124-9]|1[02-579]|2[3-5]|3[0245]|4[023578]|58|6[349]|7[0589]|8[04])|5(?:0[1-47-9]|1[0235-8]|20|3[0149]|4[01]|5[179]|6[1-47]|7[0-5]|8[0256])|6(?:0[1-35-9]|1[024-9]|2[03689]|3[016]|4[0156]|5[01679]|6[0-279]|78|8[0-29])|7(?:0[1-46-8]|1[2-9]|2[04-8]|3[0-247]|4[037]|5[47]|6[02359]|7[0-59]|8[156])|8(?:0[1-68]|1[02-8]|2[0168]|3[0-2589]|4[03578]|5[046-9]|6[02-5]|7[028])|9(?:0[1346-9]|1[02-9]|2[0589]|3[0146-8]|4[01357-9]|5[12469]|7[0-389]|8[04-69]))[2-9]\\d{6}"],[""],["8(?:00|33|44|55|66|77|88)[2-9]\\d{6}"],["900[2-9]\\d{6}"],["52(?:3(?:[2-46-9][02-9]\\d|5(?:[02-46-9]\\d|5[0-46-9]))|4(?:[2-478][02-9]\\d|5(?:[034]\\d|2[024-9]|5[0-46-9])|6(?:0[1-9]|[2-9]\\d)|9(?:[05-9]\\d|2[0-5]|49)))\\d{4}|52[34][2-9]1[02-9]\\d{4}|5(?:00|2[125-9]|33|44|66|77|88)[2-9]\\d{6}"],0,0,0,["305209\\d{4}"]]],UY:["598","0(?:0|1[3-9]\\d)","0004\\d{2,9}|[1249]\\d{7}|(?:[49]\\d|80)\\d{5}",[6,7,8,9,10,11,12,13],[["(\\d{3})(\\d{3,4})","$1 $2",["0"]],["(\\d{3})(\\d{4})","$1 $2",["[49]0|8"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["9"],"0$1"],["(\\d{4})(\\d{4})","$1 $2",["[124]"]],["(\\d{3})(\\d{3})(\\d{2,4})","$1 $2 $3",["0"]],["(\\d{3})(\\d{3})(\\d{3})(\\d{2,4})","$1 $2 $3 $4",["0"]]],"0",0,0,0,0,0,0,"00"," int. "],UZ:["998","00","(?:20|33|[5-9]\\d)\\d{7}",[9],[["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[235-9]"]]]],VA:["39","00","0\\d{5,10}|3[0-8]\\d{7,10}|55\\d{8}|8\\d{5}(?:\\d{2,4})?|(?:1\\d|39)\\d{7,8}",[6,7,8,9,10,11,12],0,0,0,0,0,0,"06698"],VC:["1","011","(?:[58]\\d\\d|784|900)\\d{7}",[10],0,"1",0,"([2-7]\\d{6})$|1","784$1",0,"784"],VE:["58","00","[68]00\\d{7}|(?:[24]\\d|[59]0)\\d{8}",[10],[["(\\d{3})(\\d{7})","$1-$2",["[24-689]"],"0$1"]],"0"],VG:["1","011","(?:284|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2-578]\\d{6})$|1","284$1",0,"284"],VI:["1","011","[58]\\d{9}|(?:34|90)0\\d{7}",[10],0,"1",0,"([2-9]\\d{6})$|1","340$1",0,"340"],VN:["84","00","[12]\\d{9}|[135-9]\\d{8}|[16]\\d{7}|[16-8]\\d{6}",[7,8,9,10],[["(\\d{2})(\\d{5})","$1 $2",["80"],"0$1",1],["(\\d{4})(\\d{4,6})","$1 $2",["1"],0,1],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["6"],"0$1",1],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[357-9]"],"0$1",1],["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["2[48]"],"0$1",1],["(\\d{3})(\\d{4})(\\d{3})","$1 $2 $3",["2"],"0$1",1]],"0"],VU:["678","00","[57-9]\\d{6}|(?:[238]\\d|48)\\d{3}",[5,7],[["(\\d{3})(\\d{4})","$1 $2",["[57-9]"]]]],WF:["681","00","(?:40|72|8\\d{4})\\d{4}|[89]\\d{5}",[6,9],[["(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3",["[47-9]"]],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"]]]],WS:["685","0","(?:[2-6]|8\\d{5})\\d{4}|[78]\\d{6}|[68]\\d{5}",[5,6,7,10],[["(\\d{5})","$1",["[2-5]|6[1-9]"]],["(\\d{3})(\\d{3,7})","$1 $2",["[68]"]],["(\\d{2})(\\d{5})","$1 $2",["7"]]]],XK:["383","00","2\\d{7,8}|3\\d{7,11}|(?:4\\d\\d|[89]00)\\d{5}",[8,9,10,11,12],[["(\\d{3})(\\d{5})","$1 $2",["[89]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[2-4]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["2|39"],"0$1"],["(\\d{2})(\\d{7,10})","$1 $2",["3"],"0$1"]],"0"],YE:["967","00","(?:1|7\\d)\\d{7}|[1-7]\\d{6}",[7,8,9],[["(\\d)(\\d{3})(\\d{3,4})","$1 $2 $3",["[1-6]|7(?:[24-6]|8[0-7])"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["7"],"0$1"]],"0"],YT:["262","00","7093\\d{5}|(?:80|9\\d)\\d{7}|(?:26|63)9\\d{6}",[9],0,"0",0,0,0,0,0,[["269(?:0[0-467]|15|5[0-4]|6\\d|[78]0)\\d{4}"],["(?:639(?:0[0-79]|1[019]|[267]\\d|3[09]|40|5[05-9]|9[04-79])|7093[5-7])\\d{4}"],["80\\d{7}"],0,0,0,0,0,["9(?:(?:39|47)8[01]|769\\d)\\d{4}"]]],ZA:["27","00","[1-79]\\d{8}|8\\d{4,9}",[5,6,7,8,9,10],[["(\\d{2})(\\d{3,4})","$1 $2",["8[1-4]"],"0$1"],["(\\d{2})(\\d{3})(\\d{2,3})","$1 $2 $3",["8[1-4]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["860"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[1-9]"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["8"],"0$1"]],"0"],ZM:["260","00","800\\d{6}|(?:21|[579]\\d|63)\\d{7}",[9],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[28]"],"0$1"],["(\\d{2})(\\d{7})","$1 $2",["[579]"],"0$1"]],"0"],ZW:["263","00","2(?:[0-57-9]\\d{6,8}|6[0-24-9]\\d{6,7})|[38]\\d{9}|[35-8]\\d{8}|[3-6]\\d{7}|[1-689]\\d{6}|[1-3569]\\d{5}|[1356]\\d{4}",[5,6,7,8,9,10],[["(\\d{3})(\\d{3,5})","$1 $2",["2(?:0[45]|2[278]|[49]8)|3(?:[09]8|17)|6(?:[29]8|37|75)|[23][78]|(?:33|5[15]|6[68])[78]"],"0$1"],["(\\d)(\\d{3})(\\d{2,4})","$1 $2 $3",["[49]"],"0$1"],["(\\d{3})(\\d{4})","$1 $2",["80"],"0$1"],["(\\d{2})(\\d{7})","$1 $2",["24|8[13-59]|(?:2[05-79]|39|5[45]|6[15-8])2","2(?:02[014]|4|[56]20|[79]2)|392|5(?:42|525)|6(?:[16-8]21|52[013])|8[13-59]"],"(0$1)"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["7"],"0$1"],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["2(?:1[39]|2[0157]|[378]|[56][14])|3(?:12|29)","2(?:1[39]|2[0157]|[378]|[56][14])|3(?:123|29)"],"0$1"],["(\\d{4})(\\d{6})","$1 $2",["8"],"0$1"],["(\\d{2})(\\d{3,5})","$1 $2",["1|2(?:0[0-36-9]|12|29|[56])|3(?:1[0-689]|[24-6])|5(?:[0236-9]|1[2-4])|6(?:[013-59]|7[0-46-9])|(?:33|55|6[68])[0-69]|(?:29|3[09]|62)[0-79]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["29[013-9]|39|54"],"0$1"],["(\\d{4})(\\d{3,5})","$1 $2",["(?:25|54)8","258|5483"],"0$1"]],"0"]},nonGeographic:{800:["800",0,"(?:00|[1-9]\\d)\\d{6}",[8],[["(\\d{4})(\\d{4})","$1 $2",["\\d"]]],0,0,0,0,0,0,[0,0,["(?:00|[1-9]\\d)\\d{6}"]]],808:["808",0,"[1-9]\\d{7}",[8],[["(\\d{4})(\\d{4})","$1 $2",["[1-9]"]]],0,0,0,0,0,0,[0,0,0,0,0,0,0,0,0,["[1-9]\\d{7}"]]],870:["870",0,"7\\d{11}|[235-7]\\d{8}",[9,12],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[235-7]"]]],0,0,0,0,0,0,[0,["(?:[356]|774[45])\\d{8}|7[6-8]\\d{7}"],0,0,0,0,0,0,["2\\d{8}",[9]]]],878:["878",0,"10\\d{10}",[12],[["(\\d{2})(\\d{5})(\\d{5})","$1 $2 $3",["1"]]],0,0,0,0,0,0,[0,0,0,0,0,0,0,0,["10\\d{10}"]]],881:["881",0,"6\\d{9}|[0-36-9]\\d{8}",[9,10],[["(\\d)(\\d{3})(\\d{5})","$1 $2 $3",["[0-37-9]"]],["(\\d)(\\d{3})(\\d{5,6})","$1 $2 $3",["6"]]],0,0,0,0,0,0,[0,["6\\d{9}|[0-36-9]\\d{8}"]]],882:["882",0,"[13]\\d{6}(?:\\d{2,5})?|[19]\\d{7}|(?:[25]\\d\\d|4)\\d{7}(?:\\d{2})?",[7,8,9,10,11,12],[["(\\d{2})(\\d{5})","$1 $2",["16|342"]],["(\\d{2})(\\d{6})","$1 $2",["49"]],["(\\d{2})(\\d{2})(\\d{4})","$1 $2 $3",["1[36]|9"]],["(\\d{2})(\\d{4})(\\d{3})","$1 $2 $3",["3[23]"]],["(\\d{2})(\\d{3,4})(\\d{4})","$1 $2 $3",["16"]],["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["10|23|3(?:[15]|4[57])|4|51"]],["(\\d{3})(\\d{4})(\\d{4})","$1 $2 $3",["34"]],["(\\d{2})(\\d{4,5})(\\d{5})","$1 $2 $3",["[1-35]"]]],0,0,0,0,0,0,[0,["342\\d{4}|(?:337|49)\\d{6}|(?:3(?:2|47|7\\d{3})|50\\d{3})\\d{7}",[7,8,9,10,12]],0,0,0,["348[57]\\d{7}",[11]],0,0,["1(?:3(?:0[0347]|[13][0139]|2[035]|4[013568]|6[0459]|7[06]|8[15-8]|9[0689])\\d{4}|6\\d{5,10})|(?:345\\d|9[89])\\d{6}|(?:10|2(?:3|85\\d)|3(?:[15]|[69]\\d\\d)|4[15-8]|51)\\d{8}"]]],883:["883",0,"(?:[1-4]\\d|51)\\d{6,10}",[8,9,10,11,12],[["(\\d{3})(\\d{3})(\\d{2,8})","$1 $2 $3",["[14]|2[24-689]|3[02-689]|51[24-9]"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["510"]],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["21"]],["(\\d{4})(\\d{4})(\\d{4})","$1 $2 $3",["51[13]"]],["(\\d{3})(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4",["[235]"]]],0,0,0,0,0,0,[0,0,0,0,0,0,0,0,["(?:2(?:00\\d\\d|10)|(?:370[1-9]|51\\d0)\\d)\\d{7}|51(?:00\\d{5}|[24-9]0\\d{4,7})|(?:1[0-79]|2[24-689]|3[02-689]|4[0-4])0\\d{5,9}"]]],888:["888",0,"\\d{11}",[11],[["(\\d{3})(\\d{3})(\\d{5})","$1 $2 $3"]],0,0,0,0,0,0,[0,0,0,0,0,0,["\\d{11}"]]],979:["979",0,"[1359]\\d{8}",[9],[["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["[1359]"]]],0,0,0,0,0,0,[0,0,0,["[1359]\\d{8}"]]]}};function l5(t,e){var n=Array.prototype.slice.call(e);return n.push(c5),t.apply(this,n)}function _g(t,e){t=t.split("-"),e=e.split("-");for(var n=t[0].split("."),r=e[0].split("."),i=0;i<3;i++){var s=Number(n[i]),a=Number(r[i]);if(s>a)return 1;if(a>s)return-1;if(!isNaN(s)&&isNaN(a))return 1;if(isNaN(s)&&!isNaN(a))return-1}return t[1]&&e[1]?t[1]>e[1]?1:t[1]<e[1]?-1:0:!t[1]&&e[1]?1:t[1]&&!e[1]?-1:0}var d5={}.constructor;function Qr(t){return t!=null&&t.constructor===d5}function nu(t){"@babel/helpers - typeof";return nu=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},nu(t)}function qc(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function u5(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function Hc(t,e,n){return e&&u5(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t}var p5="1.2.0",f5="1.7.35",yg=" ext. ",h5=/^\d+$/,vt=function(){function t(e){qc(this,t),h1(e),this.metadata=e,g1.call(this,e)}return Hc(t,[{key:"getCountries",value:function(){return Object.keys(this.metadata.countries).filter(function(n){return n!=="001"})}},{key:"getCountryMetadata",value:function(n){return this.metadata.countries[n]}},{key:"nonGeographic",value:function(){if(!(this.v1||this.v2||this.v3))return this.metadata.nonGeographic||this.metadata.nonGeographical}},{key:"hasCountry",value:function(n){return this.getCountryMetadata(n)!==void 0}},{key:"hasCallingCode",value:function(n){if(this.getCountryCodesForCallingCode(n))return!0;if(this.nonGeographic()){if(this.nonGeographic()[n])return!0}else{var r=this.countryCallingCodes()[n];if(r&&r.length===1&&r[0]==="001")return!0}}},{key:"isNonGeographicCallingCode",value:function(n){return this.nonGeographic()?!!this.nonGeographic()[n]:!this.getCountryCodesForCallingCode(n)}},{key:"country",value:function(n){return this.selectNumberingPlan(n)}},{key:"selectNumberingPlan",value:function(n,r){if(n&&h5.test(n)&&(r=n,n=null),n&&n!=="001"){if(!this.hasCountry(n))throw new Error("Unknown country: ".concat(n));this.numberingPlan=new wg(this.getCountryMetadata(n),this)}else if(r){if(!this.hasCallingCode(r))throw new Error("Unknown calling code: ".concat(r));this.numberingPlan=new wg(this.getNumberingPlanMetadata(r),this)}else this.numberingPlan=void 0;return this}},{key:"getCountryCodesForCallingCode",value:function(n){var r=this.countryCallingCodes()[n];if(r)return r.length===1&&r[0].length===3?void 0:r}},{key:"getCountryCodeForCallingCode",value:function(n){var r=this.getCountryCodesForCallingCode(n);if(r)return r[0]}},{key:"getNumberingPlanMetadata",value:function(n){var r=this.getCountryCodeForCallingCode(n);if(r)return this.getCountryMetadata(r);if(this.nonGeographic()){var i=this.nonGeographic()[n];if(i)return i}else{var s=this.countryCallingCodes()[n];if(s&&s.length===1&&s[0]==="001")return this.metadata.countries["001"]}}},{key:"countryCallingCode",value:function(){return this.numberingPlan.callingCode()}},{key:"IDDPrefix",value:function(){return this.numberingPlan.IDDPrefix()}},{key:"defaultIDDPrefix",value:function(){return this.numberingPlan.defaultIDDPrefix()}},{key:"nationalNumberPattern",value:function(){return this.numberingPlan.nationalNumberPattern()}},{key:"possibleLengths",value:function(){return this.numberingPlan.possibleLengths()}},{key:"formats",value:function(){return this.numberingPlan.formats()}},{key:"nationalPrefixForParsing",value:function(){return this.numberingPlan.nationalPrefixForParsing()}},{key:"nationalPrefixTransformRule",value:function(){return this.numberingPlan.nationalPrefixTransformRule()}},{key:"leadingDigits",value:function(){return this.numberingPlan.leadingDigits()}},{key:"hasTypes",value:function(){return this.numberingPlan.hasTypes()}},{key:"type",value:function(n){return this.numberingPlan.type(n)}},{key:"ext",value:function(){return this.numberingPlan.ext()}},{key:"countryCallingCodes",value:function(){return this.v1?this.metadata.country_phone_code_to_countries:this.metadata.country_calling_codes}},{key:"chooseCountryByCountryCallingCode",value:function(n){return this.selectNumberingPlan(n)}},{key:"hasSelectedNumberingPlan",value:function(){return this.numberingPlan!==void 0}}]),t}(),wg=function(){function t(e,n){qc(this,t),this.globalMetadataObject=n,this.metadata=e,g1.call(this,n.metadata)}return Hc(t,[{key:"callingCode",value:function(){return this.metadata[0]}},{key:"getDefaultCountryMetadataForRegion",value:function(){return this.globalMetadataObject.getNumberingPlanMetadata(this.callingCode())}},{key:"IDDPrefix",value:function(){if(!(this.v1||this.v2))return this.metadata[1]}},{key:"defaultIDDPrefix",value:function(){if(!(this.v1||this.v2))return this.metadata[12]}},{key:"nationalNumberPattern",value:function(){return this.v1||this.v2?this.metadata[1]:this.metadata[2]}},{key:"possibleLengths",value:function(){if(!this.v1)return this.metadata[this.v2?2:3]}},{key:"_getFormats",value:function(n){return n[this.v1?2:this.v2?3:4]}},{key:"formats",value:function(){var n=this,r=this._getFormats(this.metadata)||this._getFormats(this.getDefaultCountryMetadataForRegion())||[];return r.map(function(i){return new g5(i,n)})}},{key:"nationalPrefix",value:function(){return this.metadata[this.v1?3:this.v2?4:5]}},{key:"_getNationalPrefixFormattingRule",value:function(n){return n[this.v1?4:this.v2?5:6]}},{key:"nationalPrefixFormattingRule",value:function(){return this._getNationalPrefixFormattingRule(this.metadata)||this._getNationalPrefixFormattingRule(this.getDefaultCountryMetadataForRegion())}},{key:"_nationalPrefixForParsing",value:function(){return this.metadata[this.v1?5:this.v2?6:7]}},{key:"nationalPrefixForParsing",value:function(){return this._nationalPrefixForParsing()||this.nationalPrefix()}},{key:"nationalPrefixTransformRule",value:function(){return this.metadata[this.v1?6:this.v2?7:8]}},{key:"_getNationalPrefixIsOptionalWhenFormatting",value:function(){return!!this.metadata[this.v1?7:this.v2?8:9]}},{key:"nationalPrefixIsOptionalWhenFormattingInNationalFormat",value:function(){return this._getNationalPrefixIsOptionalWhenFormatting(this.metadata)||this._getNationalPrefixIsOptionalWhenFormatting(this.getDefaultCountryMetadataForRegion())}},{key:"leadingDigits",value:function(){return this.metadata[this.v1?8:this.v2?9:10]}},{key:"types",value:function(){return this.metadata[this.v1?9:this.v2?10:11]}},{key:"hasTypes",value:function(){return this.types()&&this.types().length===0?!1:!!this.types()}},{key:"type",value:function(n){if(this.hasTypes()&&vg(this.types(),n))return new _5(vg(this.types(),n),this)}},{key:"ext",value:function(){return this.v1||this.v2?yg:this.metadata[13]||yg}}]),t}(),g5=function(){function t(e,n){qc(this,t),this._format=e,this.metadata=n}return Hc(t,[{key:"pattern",value:function(){return this._format[0]}},{key:"format",value:function(){return this._format[1]}},{key:"leadingDigitsPatterns",value:function(){return this._format[2]||[]}},{key:"nationalPrefixFormattingRule",value:function(){return this._format[3]||this.metadata.nationalPrefixFormattingRule()}},{key:"nationalPrefixIsOptionalWhenFormattingInNationalFormat",value:function(){return!!this._format[4]||this.metadata.nationalPrefixIsOptionalWhenFormattingInNationalFormat()}},{key:"nationalPrefixIsMandatoryWhenFormattingInNationalFormat",value:function(){return this.usesNationalPrefix()&&!this.nationalPrefixIsOptionalWhenFormattingInNationalFormat()}},{key:"usesNationalPrefix",value:function(){return!!(this.nationalPrefixFormattingRule()&&!m5.test(this.nationalPrefixFormattingRule()))}},{key:"internationalFormat",value:function(){return this._format[5]||this.format()}}]),t}(),m5=/^\(?\$1\)?$/,_5=function(){function t(e,n){qc(this,t),this.type=e,this.metadata=n}return Hc(t,[{key:"pattern",value:function(){return this.metadata.v1?this.type:this.type[0]}},{key:"possibleLengths",value:function(){if(!this.metadata.v1)return this.type[1]||this.metadata.possibleLengths()}}]),t}();function vg(t,e){switch(e){case"FIXED_LINE":return t[0];case"MOBILE":return t[1];case"TOLL_FREE":return t[2];case"PREMIUM_RATE":return t[3];case"PERSONAL_NUMBER":return t[4];case"VOICEMAIL":return t[5];case"UAN":return t[6];case"PAGER":return t[7];case"VOIP":return t[8];case"SHARED_COST":return t[9]}}function h1(t){if(!t)throw new Error("[libphonenumber-js] `metadata` argument not passed. Check your arguments.");if(!Qr(t)||!Qr(t.countries))throw new Error("[libphonenumber-js] `metadata` argument was passed but it's not a valid metadata. Must be an object having `.countries` child object property. Got ".concat(Qr(t)?"an object of shape: { "+Object.keys(t).join(", ")+" }":"a "+y5(t)+": "+t,"."))}var y5=function(e){return nu(e)};function Ap(t,e){if(e=new vt(e),e.hasCountry(t))return e.country(t).countryCallingCode();throw new Error("Unknown country: ".concat(t))}function w5(t,e){return e.countries.hasOwnProperty(t)}function g1(t){var e=t.version;typeof e=="number"?(this.v1=e===1,this.v2=e===2,this.v3=e===3,this.v4=e===4):e?_g(e,p5)===-1?this.v2=!0:_g(e,f5)===-1?this.v3=!0:this.v4=!0:this.v1=!0}function Ep(t,e){return v5(t,void 0,e)}function v5(t,e,n){var r=n.type(e),i=r&&r.possibleLengths()||n.possibleLengths();if(!i)return"IS_POSSIBLE";var s=t.length,a=i[0];return a===s?"IS_POSSIBLE":a>s?"TOO_SHORT":i[i.length-1]<s?"TOO_LONG":i.indexOf(s,1)>=0?"IS_POSSIBLE":"INVALID_LENGTH"}function b5(t,e,n){if(e===void 0&&(e={}),n=new vt(n),e.v2){if(!t.countryCallingCode)throw new Error("Invalid phone number object passed");n.selectNumberingPlan(t.countryCallingCode)}else{if(!t.phone)return!1;if(t.country){if(!n.hasCountry(t.country))throw new Error("Unknown country: ".concat(t.country));n.country(t.country)}else{if(!t.countryCallingCode)throw new Error("Invalid phone number object passed");n.selectNumberingPlan(t.countryCallingCode)}}if(n.possibleLengths())return m1(t.phone||t.nationalNumber,n);if(t.countryCallingCode&&n.isNonGeographicCallingCode(t.countryCallingCode))return!0;throw new Error('Missing "possibleLengths" in metadata. Perhaps the metadata has been generated before v1.0.18.')}function m1(t,e){switch(Ep(t,e)){case"IS_POSSIBLE":return!0;default:return!1}}function In(t,e){return t=t||"",new RegExp("^(?:"+e+")$").test(t)}function $5(t,e){var n=typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=k5(t))||e){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
195
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function k5(t,e){if(t){if(typeof t=="string")return bg(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set")return Array.from(t);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return bg(t,e)}}function bg(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var x5=["MOBILE","PREMIUM_RATE","TOLL_FREE","SHARED_COST","VOIP","PERSONAL_NUMBER","PAGER","UAN","VOICEMAIL"];function Cp(t,e,n){if(e=e||{},!(!t.country&&!t.countryCallingCode)){n=new vt(n),n.selectNumberingPlan(t.country,t.countryCallingCode);var r=e.v2?t.nationalNumber:t.phone;if(In(r,n.nationalNumberPattern())){if(pl(r,"FIXED_LINE",n))return n.type("MOBILE")&&n.type("MOBILE").pattern()===""||!n.type("MOBILE")||pl(r,"MOBILE",n)?"FIXED_LINE_OR_MOBILE":"FIXED_LINE";for(var i=$5(x5),s;!(s=i()).done;){var a=s.value;if(pl(r,a,n))return a}}}}function pl(t,e,n){return e=n.type(e),!e||!e.pattern()||e.possibleLengths()&&e.possibleLengths().indexOf(t.length)<0?!1:In(t,e.pattern())}function S5(t,e,n){if(e=e||{},n=new vt(n),n.selectNumberingPlan(t.country,t.countryCallingCode),n.hasTypes())return Cp(t,e,n.metadata)!==void 0;var r=e.v2?t.nationalNumber:t.phone;return In(r,n.nationalNumberPattern())}function z5(t,e,n){var r=new vt(n),i=r.getCountryCodesForCallingCode(t);return i?i.filter(function(s){return A5(e,s,n)}):[]}function A5(t,e,n){var r=new vt(n);return r.selectNumberingPlan(e),r.numberingPlan.possibleLengths().indexOf(t.length)>=0}var Np=2,E5=17,C5=3,en="0-90-9٠-٩۰-۹",N5="-‐-―−ー-",I5="//",j5="..",O5="  ­​⁠ ",T5="()()[]\\[\\]",P5="~⁓∼~",Na="".concat(N5).concat(I5).concat(j5).concat(O5).concat(T5).concat(P5),Ip="++",R5=new RegExp("(["+en+"])");function B5(t,e,n,r){if(e){var i=new vt(r);i.selectNumberingPlan(e,n);var s=new RegExp(i.IDDPrefix());if(t.search(s)===0){t=t.slice(t.match(s)[0].length);var a=t.match(R5);if(!(a&&a[1]!=null&&a[1].length>0&&a[1]==="0"))return t}}}function L5(t,e){if(t&&e.numberingPlan.nationalPrefixForParsing()){var n=new RegExp("^(?:"+e.numberingPlan.nationalPrefixForParsing()+")"),r=n.exec(t);if(r){var i,s,a=r.length-1,c=a>0&&r[a];if(e.nationalPrefixTransformRule()&&c)i=t.replace(n,e.nationalPrefixTransformRule()),a>1&&(s=r[1]);else{var l=r[0];i=t.slice(l.length),c&&(s=r[1])}var d;if(c){var u=t.indexOf(r[1]),f=t.slice(0,u);f===e.numberingPlan.nationalPrefix()&&(d=e.numberingPlan.nationalPrefix())}else d=r[0];return{nationalNumber:i,nationalPrefix:d,carrierCode:s}}}return{nationalNumber:t}}function ru(t,e){var n=L5(t,e),r=n.carrierCode,i=n.nationalNumber;if(i!==t){if(!U5(t,i,e))return{nationalNumber:t};if(e.possibleLengths()&&!D5(i,e))return{nationalNumber:t}}return{nationalNumber:i,carrierCode:r}}function U5(t,e,n){return!(In(t,n.nationalNumberPattern())&&!In(e,n.nationalNumberPattern()))}function D5(t,e){switch(Ep(t,e)){case"TOO_SHORT":case"INVALID_LENGTH":return!1;default:return!0}}function M5(t,e,n,r){var i=e?Ap(e,r):n;if(t.indexOf(i)===0){r=new vt(r),r.selectNumberingPlan(e,n);var s=t.slice(i.length),a=ru(s,r),c=a.nationalNumber,l=ru(t,r),d=l.nationalNumber;if(!In(d,r.nationalNumberPattern())&&In(c,r.nationalNumberPattern())||Ep(d,r)==="TOO_LONG")return{countryCallingCode:i,number:s}}return{number:t}}function _1(t,e,n,r){if(!t)return{};var i;if(t[0]!=="+"){var s=B5(t,e,n,r);if(s&&s!==t)i=!0,t="+"+s;else{if(e||n){var a=M5(t,e,n,r),c=a.countryCallingCode,l=a.number;if(c)return{countryCallingCodeSource:"FROM_NUMBER_WITHOUT_PLUS_SIGN",countryCallingCode:c,number:l}}return{number:t}}}if(t[1]==="0")return{};r=new vt(r);for(var d=2;d-1<=C5&&d<=t.length;){var u=t.slice(1,d);if(r.hasCallingCode(u))return r.selectNumberingPlan(u),{countryCallingCodeSource:i?"FROM_NUMBER_WITH_IDD":"FROM_NUMBER_WITH_PLUS_SIGN",countryCallingCode:u,number:t.slice(d)};d++}return{}}function F5(t){return t.replace(new RegExp("[".concat(Na,"]+"),"g")," ").trim()}var q5=/(\$\d)/;function H5(t,e,n){var r=n.useInternationalFormat,i=n.withNationalPrefix,s=t.replace(new RegExp(e.pattern()),r?e.internationalFormat():i&&e.nationalPrefixFormattingRule()?e.format().replace(q5,e.nationalPrefixFormattingRule()):e.format());return r?F5(s):s}var V5=/^[\d]+(?:[~\u2053\u223C\uFF5E][\d]+)?$/;function K5(t,e,n){var r=new vt(n);if(r.selectNumberingPlan(t,e),r.defaultIDDPrefix())return r.defaultIDDPrefix();if(V5.test(r.IDDPrefix()))return r.IDDPrefix()}var G5=";ext=",Mr=function(e){return"([".concat(en,"]{1,").concat(e,"})")};function y1(t){var e="20",n="15",r="9",i="6",s="[  \\t,]*",a="[:\\..]?[  \\t,-]*",c="#?",l="(?:e?xt(?:ensi(?:ó?|ó))?n?|e?xtn?|доб|anexo)",d="(?:[xx##~~]|int|int)",u="[- ]+",f="[  \\t]*",h="(?:,{2}|;)",m=G5+Mr(e),y=s+l+a+Mr(e)+c,v=s+d+a+Mr(r)+c,b=u+Mr(i)+"#",A=f+h+a+Mr(n)+c,O=f+"(?:,)+"+a+Mr(r)+c;return m+"|"+y+"|"+v+"|"+b+"|"+A+"|"+O}var W5="["+en+"]{"+Np+"}",J5="["+Ip+"]{0,1}(?:["+Na+"]*["+en+"]){3,}["+Na+en+"]*",X5=new RegExp("^["+Ip+"]{0,1}(?:["+Na+"]*["+en+"]){1,2}$","i"),Z5=J5+"(?:"+y1()+")?",Y5=new RegExp("^"+W5+"$|^"+Z5+"$","i");function Q5(t){return t.length>=Np&&Y5.test(t)}function e6(t){return X5.test(t)}function t6(t){var e=t.number,n=t.ext;if(!e)return"";if(e[0]!=="+")throw new Error('"formatRFC3966()" expects "number" to be in E.164 format.');return"tel:".concat(e).concat(n?";ext="+n:"")}function n6(t,e){var n=typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=r6(t))||e){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
194
+ c2.7,4.1,6.5,6.6,10.9,6.6c4,0,7.2-2,9.6-5.2c0.9-1.2,0.9-2.5,0-3.1C33.3,22.9,32.1,23.2,31.2,24.4z`})]});async function Fk(t,e){var a;const{options:n}=e;if(!(n!=null&&n.client_id)||!n.client_secret)throw new Error("Missing required authentication parameters");const r=new Fc(n.client_id,n.client_secret,`${He(t.env)}callback`),i=Ne(),s=r.createAuthorizationURL("https://api.vipps.no/access-management-1.0/access/oauth2/auth",i,((a=n.scope)==null?void 0:a.split(" "))||["openid","email","phoneNumber","name","address","birthDate"]);return s.searchParams.set("response_type","code"),s.searchParams.set("response_mode","query"),{redirectUrl:s.href,code:i}}async function qk(t,e,n){const{options:r}=e;if(!(r!=null&&r.client_id)||!r.client_secret)throw new Error("Missing required authentication parameters");const s=await new Fc(r.client_id,r.client_secret,`${He(t.env)}callback`).validateAuthorizationCode("https://api.vipps.no/access-management-1.0/access/oauth2/token",n,null),a=Ua(s.idToken());if(!a)throw new Error("Invalid ID token");const c=Wo.parse(a.payload);if(typeof c.msn!="string")throw new Error("msn not available in id token");const l=await fetch("https://api.vipps.no/vipps-userinfo-api/userinfo",{headers:{Authorization:`Bearer ${s.accessToken()}`,"Merchant-Serial-Number":c.msn}});if(!l.ok)throw new ee(400,{message:"Failed to get user from vipps"});return await l.json()}const c1=Object.freeze(Object.defineProperty({__proto__:null,displayName:Dk,getRedirect:Fk,logo:Mk,validateAuthorizationCodeAndGetUser:qk},Symbol.toStringTag,{value:"Module"})),Hk="GitHub",Vk=({className:t=""})=>p("svg",{width:"45",height:"45",viewBox:"0 0 45 45",xmlns:"http://www.w3.org/2000/svg",className:t,children:p("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M22.5 0C10.074 0 0 10.335 0 23.077C0 33.266 6.444 41.895 15.39 44.955C16.515 45.165 16.935 44.46 16.935 43.857C16.935 43.32 16.92 41.865 16.905 39.99C10.65 41.355 9.33 36.99 9.33 36.99C8.31 34.32 6.825 33.615 6.825 33.615C4.77 32.205 6.975 32.235 6.975 32.235C9.24 32.385 10.425 34.59 10.425 34.59C12.45 38.13 15.75 37.125 17.01 36.555C17.22 35.07 17.82 34.065 18.48 33.51C13.455 32.94 8.19 30.93 8.19 22.035C8.19 19.5 9.075 17.43 10.47 15.81C10.23 15.24 9.435 12.87 10.695 9.66C10.695 9.66 12.585 9.045 16.875 12.06C18.675 11.565 20.595 11.31 22.5 11.31C24.405 11.31 26.325 11.565 28.125 12.06C32.415 9.045 34.305 9.66 34.305 9.66C35.565 12.87 34.77 15.24 34.53 15.81C35.925 17.43 36.81 19.5 36.81 22.035C36.81 30.96 31.53 32.925 26.49 33.48C27.33 34.2 28.095 35.625 28.095 37.815C28.095 40.95 28.065 43.47 28.065 43.857C28.065 44.46 28.485 45.18 29.625 44.955C38.571 41.88 45 33.252 45 23.077C45 10.335 34.926 0 22.5 0Z",fill:"currentColor"})});async function Kk(t,e){var c;const{options:n}=e;if(!(n!=null&&n.client_id)||!n.client_secret)throw new Error("Missing required GitHub authentication parameters");const r=`${He(t.env)}callback`,i=new t1(n.client_id,n.client_secret,r),s=Ne();return{redirectUrl:i.createAuthorizationURL(s,((c=n.scope)==null?void 0:c.split(" "))||["user:email"]).href,code:s}}async function Gk(t,e,n){var u,f;const{options:r}=e;if(!(r!=null&&r.client_id)||!r.client_secret)throw new Error("Missing required authentication parameters");const s=await new t1(r.client_id,r.client_secret,`${He(t.env)}callback`).validateAuthorizationCode(n),a=await fetch("https://api.github.com/user",{headers:{Authorization:`Bearer ${s.accessToken()}`,"User-Agent":"AuthHero"}});if(!a.ok)throw new Error("Failed to fetch user info");const c=await a.json(),l=await fetch("https://api.github.com/user/emails",{headers:{Authorization:`Bearer ${s.accessToken()}`,"User-Agent":"AuthHero"}});let d=c.email;if(l.ok){const h=await l.json(),m=h.find(y=>y.primary&&y.verified)||h.find(y=>y.verified);m&&(d=m.email)}return t.set("log",`GitHub user: ${JSON.stringify(c)}`),{sub:c.id.toString(),email:d,name:c.name,given_name:(u=c.name)==null?void 0:u.split(" ")[0],family_name:(f=c.name)==null?void 0:f.split(" ").slice(1).join(" "),picture:c.avatar_url}}const l1=Object.freeze(Object.defineProperty({__proto__:null,displayName:Hk,getRedirect:Kk,logo:Vk,validateAuthorizationCodeAndGetUser:Gk},Symbol.toStringTag,{value:"Module"})),Wk="Microsoft",Jk=({className:t=""})=>p("svg",{width:"45",height:"45",viewBox:"0 0 45 45",xmlns:"http://www.w3.org/2000/svg",className:t,children:[p("path",{fill:"#F25022",d:"M0 0H21.43V21.43H0V0Z"}),p("path",{fill:"#7FBA00",d:"M23.57 0H45V21.43H23.57V0Z"}),p("path",{fill:"#00A4EF",d:"M0 23.57H21.43V45H0V23.57Z"}),p("path",{fill:"#FFB900",d:"M23.57 23.57H45V45H23.57V23.57Z"})]});async function Xk(t,e){var d;const{options:n}=e;if(!(n!=null&&n.client_id)||!n.client_secret)throw new Error("Missing required Microsoft authentication parameters");const r=`${He(t.env)}callback`,i=n.realms||"common",s=new r1(i,n.client_id,n.client_secret,r),a=Ne(),c=Yy();return{redirectUrl:s.createAuthorizationURL(a,c,((d=n.scope)==null?void 0:d.split(" "))||["openid","profile","email"]).href,code:a,codeVerifier:c}}async function Zk(t,e,n,r){const{options:i}=e;if(!(i!=null&&i.client_id)||!i.client_secret||!r)throw new Error("Missing required authentication parameters");const s=i.realms||"common",c=await new r1(s,i.client_id,i.client_secret,`${He(t.env)}callback`).validateAuthorizationCode(n,r),l=Ua(c.idToken());if(!l)throw new Error("Invalid ID token");const d=Wo.parse(l.payload);return t.set("log",`Microsoft user: ${JSON.stringify(d)}`),{sub:d.sub,email:d.email,given_name:d.given_name,family_name:d.family_name,name:d.name,picture:d.picture}}const d1=Object.freeze(Object.defineProperty({__proto__:null,displayName:Wk,getRedirect:Xk,logo:Jk,validateAuthorizationCodeAndGetUser:Zk},Symbol.toStringTag,{value:"Module"}));function u1(t,e){const n=t.env.STRATEGIES||{},i={apple:o1,facebook:s1,"google-oauth2":a1,vipps:c1,github:l1,microsoft:d1,...n}[e];if(!i)throw new Error(`Strategy ${e} not found`);return i}function p1(t){return{apple:o1,facebook:s1,"google-oauth2":a1,vipps:c1,github:l1,microsoft:d1}[t]}async function Oi(t,e){const n=await t.data.legacyClients.get(e);if(!n)throw new ee(403,{message:"Client not found"});let r=n;if(t.DEFAULT_CLIENT_ID||t.DEFAULT_TENANT_ID){const i=t.DEFAULT_CLIENT_ID?await t.data.legacyClients.get(t.DEFAULT_CLIENT_ID):void 0,s=await t.data.connections.list(n.tenant.id),a=t.DEFAULT_TENANT_ID?await t.data.connections.list(t.DEFAULT_TENANT_ID):{connections:[]},c=s.connections.map(l=>{var f;const d=(f=a.connections)==null?void 0:f.find(h=>h.name===l.name);if(!(d!=null&&d.options))return l;const u=Kt.parse({...d||{},...l});return u.options=Wr.passthrough().parse({...d.options||{},...l.options}),u}).filter(l=>l);r={...n,web_origins:[...(i==null?void 0:i.web_origins)||[],...n.web_origins||[]],allowed_logout_urls:[...(i==null?void 0:i.allowed_logout_urls)||[],...n.allowed_logout_urls||[]],callbacks:[...(i==null?void 0:i.callbacks)||[],...n.callbacks||[]],connections:c,tenant:{...(i==null?void 0:i.tenant)||{},...n.tenant}}}return{...r,web_origins:[...r.web_origins||[],`${st(t)}login`],allowed_logout_urls:[...r.allowed_logout_urls||[],t.ISSUER],callbacks:[...r.callbacks||[],`${st(t)}info`]}}async function fg(t,e,n,r){if(!r.state)throw new ee(400,{message:"State not found"});const i=e.connections.find(l=>l.name===n);if(!i){t.set("client_id",e.client_id);const l=be(t,{type:_e.FAILED_LOGIN,description:"Connection not found"});throw ve(t,t.env.data.logs.create(e.tenant.id,l)),new ee(403,{message:"Connection Not Found"})}let s=await t.env.data.loginSessions.get(e.tenant.id,r.state);if(!s){const l=t.get("ip"),d=t.get("useragent"),u=t.get("auth0_client");s=await t.env.data.loginSessions.create(e.tenant.id,{expires_at:new Date(Date.now()+_r*1e3).toISOString(),authParams:r,csrf_token:Ne(),ip:l,useragent:d,auth0Client:Nn(u)})}const c=await u1(t,i.strategy).getRedirect(t,i);return await t.env.data.codes.create(e.tenant.id,{login_id:s.id,code_id:c.code,code_type:"oauth2_state",connection_id:i.id,code_verifier:c.codeVerifier,expires_at:new Date(Date.now()+Sv*1e3).toISOString()}),new Response(null,{status:302,headers:{location:c.redirectUrl}})}async function hg(t,{code:e,state:n}){var y;const{env:r}=t,i=await r.data.codes.get(t.var.tenant_id||"",n,"oauth2_state");if(!i||!i.connection_id)throw new ee(403,{message:"State not found"});const s=await r.data.loginSessions.get(t.var.tenant_id||"",i.login_id);if(!s)throw new ee(403,{message:"Session not found"});if(s.authorization_url){const v=new URL(s.authorization_url).hostname,b=t.var.host||"";if(v!==b&&v){const A=new URL(`https://${v}/callback`);return A.searchParams.set("state",n),A.searchParams.set("code",e),new Response("Redirecting",{status:307,headers:{location:A.toString()}})}}const a=await Oi(r,s.authParams.client_id);t.set("client_id",a.client_id),t.set("tenant_id",a.tenant.id);const c=a.connections.find(v=>v.id===i.connection_id);if(!c){const v=be(t,{type:_e.FAILED_LOGIN,description:"Connection not found"});throw ve(t,r.data.logs.create(a.tenant.id,v)),new ee(403,{message:"Connection not found"})}if(t.set("connection",c.name),!s.authParams.redirect_uri){const v=be(t,{type:_e.FAILED_LOGIN,description:"Redirect URI not defined"});throw ve(t,r.data.logs.create(a.tenant.id,v)),new ee(403,{message:"Redirect URI not defined"})}const d=await u1(t,c.strategy).validateAuthorizationCodeAndGetUser(t,c,e,i.code_verifier),{sub:u,...f}=d;t.set("user_id",u);const h=((y=d.email)==null?void 0:y.toLocaleLowerCase())||`${c.name}.${u}@${new URL(t.env.ISSUER).hostname}`;t.set("username",h);const m=await qa(t,{client:a,username:h,provider:c.strategy,connection:c.name,userId:u,profileData:f,isSocial:!0,ip:t.var.ip});return un(t,{client:a,authParams:s.authParams,loginSession:s,user:m,strategy:c.strategy})}async function gg(t,e,n,r,i,s){const a=await t.env.data.codes.get(t.var.tenant_id||"",e,"oauth2_state");if(!a)throw new S(400,{message:"State not found"});const c=await t.env.data.loginSessions.get(t.var.tenant_id,a.login_id);if(!c)throw new S(400,{message:"Login not found"});const{redirect_uri:l}=c.authParams;if(!l)throw new S(400,{message:"Redirect uri not found"});const d=be(t,{type:_e.FAILED_LOGIN,description:`Failed connection login: ${i} ${n}, ${r}`});ve(t,t.env.data.logs.create(t.var.tenant_id,d));const u=new URL(l);return q4(u,{error:n,error_description:r,error_reason:s,error_code:i,state:c.authParams.state}),t.redirect(`${st(t.env)}login/identifier?state=${c.id}&error=${n}`)}const Yk=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth2"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string(),code:o.z.string().optional(),scope:o.z.string().optional(),hd:o.z.string().optional(),error:o.z.string().optional(),error_description:o.z.string().optional(),error_code:o.z.string().optional(),error_reason:o.z.string().optional()})},responses:{302:{description:"Redirect to the client's redirect uri"},400:{description:"Bad Request",content:{"application/json":{schema:o.z.object({message:o.z.string()})}}},500:{description:"Internal Server Error",content:{"application/json":{schema:o.z.object({message:o.z.string()})}}}}}),async t=>{const{state:e,code:n,error:r,error_description:i,error_code:s,error_reason:a}=t.req.valid("query");if(r)return gg(t,e,r,i,s,a);if(!n)throw new S(400,{message:"Code is required"});const c=await hg(t,{code:n,state:e});if(!(c instanceof Response))throw new S(500,{message:"Internal server error"});return c}).openapi(o.createRoute({tags:["oauth2"],method:"post",path:"/",request:{body:{content:{"application/x-www-form-urlencoded":{schema:o.z.object({state:o.z.string(),code:o.z.string().optional(),scope:o.z.string().optional(),hd:o.z.string().optional(),error:o.z.string().optional(),error_description:o.z.string().optional(),error_code:o.z.string().optional(),error_reason:o.z.string().optional()})}}}},responses:{302:{description:"Redirect to the client's redirect uri"},400:{description:"Bad Request",content:{"application/json":{schema:o.z.object({message:o.z.string()})}}},500:{description:"Internal Server Error",content:{"application/json":{schema:o.z.object({message:o.z.string()})}}}}}),async t=>{const{state:e,code:n,error:r,error_description:i,error_code:s,error_reason:a}=t.req.valid("form");if(r)return gg(t,e,r,i,s,a);if(!n)throw new S(400,{message:"Code is required"});const c=await hg(t,{code:n,state:e});if(!(c instanceof Response))throw new S(500,{message:"Internal server error"});return c});function zp(t,e=[],n={}){try{const r=new URL(t);return e.some(i=>{try{return Qk(r,new URL(i),n)}catch{return!1}})}catch{return!1}}function Qk(t,e,n={}){if(t.protocol!==e.protocol)return!1;if(n.allowPathWildcards&&e.pathname.includes("*")){const r=e.pathname.replace(/\*/g,".*").replace(/\//g,"\\/");if(!new RegExp(`^${r}$`).test(t.pathname))return!1}else if(t.pathname!==e.pathname)return!1;if(n.allowSubDomainWildcards&&e.hostname.startsWith("*.")&&e.hostname.split(".").length>2&&["http:","https:"].includes(e.protocol)){const r=e.hostname.split(".").slice(1).join(".");return t.hostname===r||t.hostname.endsWith("."+r)}return t.hostname===e.hostname}const e5=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth2"],method:"get",path:"/",request:{query:o.z.object({client_id:o.z.string(),returnTo:o.z.string().optional()}),header:o.z.object({cookie:o.z.string().optional()})},responses:{302:{description:"Log the user out"}}}),async t=>{const{client_id:e,returnTo:n}=t.req.valid("query"),r=await t.env.data.legacyClients.get(e);if(!r)return t.text("OK");const i=await t.env.data.legacyClients.get("DEFAULT_CLIENT");t.set("client_id",e),t.set("tenant_id",r.tenant.id);const s=n||t.req.header("referer");if(!s)return t.text("OK");if(!zp(s,[...r.allowed_logout_urls||[],...(i==null?void 0:i.allowed_logout_urls)||[]],{allowPathWildcards:!0,allowSubDomainWildcards:!0}))throw new S(400,{message:"Invalid redirect uri"});const a=t.req.header("cookie");if(a){const l=ni(r.tenant.id,a);if(l){const d=await t.env.data.sessions.get(r.tenant.id,l);if(d){const u=await t.env.data.users.get(r.tenant.id,d.user_id);u&&(t.set("user_id",u.user_id),t.set("connection",u.connection));const f=await t.env.data.refreshTokens.list(r.tenant.id,{q:`session_id=${l}`,page:0,per_page:100,include_totals:!1});await Promise.all(f.refresh_tokens.map(h=>t.env.data.refreshTokens.remove(r.tenant.id,h.id))),await t.env.data.sessions.update(r.tenant.id,l,{revoked_at:new Date().toISOString()})}}}const c=be(t,{type:_e.SUCCESS_LOGOUT,description:"User successfully logged out"});return ve(t,t.env.data.logs.create(r.tenant.id,c)),new Response("Redirecting",{status:302,headers:{"set-cookie":Nv(r.tenant.id,t.req.header("host")),location:s}})}),mg=o.z.object({sub:o.z.string(),email:o.z.string().optional(),family_name:o.z.string().optional(),given_name:o.z.string().optional(),email_verified:o.z.boolean()}),t5=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth2"],method:"get",path:"/",request:{},security:[{Bearer:["openid"]}],responses:{200:{content:{"application/json":{schema:mg}},description:"Userinfo"}}}),async t=>{if(!t.var.user)throw new S(404,{message:"User not found"});const e=await t.env.data.users.get(t.var.user.tenant_id,t.var.user.sub);if(!e)throw new S(404,{message:"User not found"});return t.json(mg.parse({...e,sub:e.user_id}))}),n5=new o.OpenAPIHono().openapi(o.createRoute({tags:["well known"],method:"get",path:"/jwks.json",request:{},responses:{200:{content:{"application/json":{schema:D0}},description:"List of tenants"}}}),async t=>{const e=await Qd(t.env.data);return t.json({keys:e},{headers:{"access-control-allow-origin":"*","access-control-allow-method":"GET","cache-control":`public, max-age=${rs}, stale-while-revalidate=${rs*2}, stale-if-error=86400`}})}).openapi(o.createRoute({tags:["well known"],method:"get",path:"/openid-configuration",request:{},responses:{200:{content:{"application/json":{schema:xl}},description:"List of tenants"}}}),async t=>{const e=xl.parse({issuer:Bc(t.env),authorization_endpoint:`${He(t.env)}authorize`,token_endpoint:`${He(t.env)}oauth/token`,device_authorization_endpoint:`${He(t.env)}oauth/device/code`,userinfo_endpoint:`${He(t.env)}userinfo`,mfa_challenge_endpoint:`${He(t.env)}mfa/challenge`,jwks_uri:`${He(t.env)}.well-known/jwks.json`,registration_endpoint:`${He(t.env)}oidc/register`,revocation_endpoint:`${He(t.env)}oauth/revoke`,scopes_supported:["openid","profile","offline_access","name","given_name","family_name","nickname","email","email_verified","picture","created_at","identities","phone","address"],response_types_supported:["code","token","id_token","code token","code id_token","token id_token","code token id_token"],code_challenge_methods_supported:["S256","plain"],response_modes_supported:["query","fragment","form_post"],subject_types_supported:["public"],id_token_signing_alg_values_supported:["RS256"],token_endpoint_auth_methods_supported:["client_secret_basic","client_secret_post"],claims_supported:["aud","auth_time","created_at","email","email_verified","exp","family_name","given_name","iat","identities","iss","name","nickname","phone_number","picture","sub"],request_uri_parameter_supported:!1,request_parameter_supported:!1,token_endpoint_auth_signing_alg_values_supported:["RS256","RS384","PS256"]});return t.json(e,{headers:{"access-control-allow-origin":"*","access-control-allow-method":"GET","cache-control":`public, max-age=${rs}, stale-while-revalidate=${rs*2}, stale-if-error=86400`}})});function $s(t,e){if(!t||!e||t.length!==e.length)return!1;let n=0;for(let r=0;r<t.length;r++)n|=t.charCodeAt(r)^e.charCodeAt(r);return n===0}const f1=o.z.object({grant_type:o.z.literal("client_credentials"),scope:o.z.string().optional(),client_secret:o.z.string(),client_id:o.z.string(),audience:o.z.string().optional()});async function r5(t,e){const n=await t.env.data.legacyClients.get(e.client_id);if(!n)throw new ee(403,{message:"Invalid client credentials"});if(n.client_secret&&!$s(n.client_secret,e.client_secret))throw new ee(403,{message:"Invalid client credentials"});const r={client_id:n.client_id,scope:e.scope,audience:e.audience};return{client:n,authParams:r}}const i5=o.z.object({grant_type:o.z.literal("authorization_code"),client_id:o.z.string(),code:o.z.string(),redirect_uri:o.z.string().optional(),client_secret:o.z.string().optional(),code_verifier:o.z.string().optional(),organization:o.z.string().optional()}).refine(t=>"client_secret"in t&&!("code_verifier"in t)||!("client_secret"in t)&&"code_verifier"in t,{message:"Must provide either client_secret (standard flow) or code_verifier/code_verifier_mode (PKCE flow), but not both"});async function o5(t,e){var l;const n=await t.env.data.legacyClients.get(e.client_id);if(!n)throw new ee(403,{message:"Client not found"});const r=await t.env.data.codes.get(n.tenant.id,e.code,"authorization_code");if(!r||!r.user_id){const d=be(t,{type:_e.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid client credentials"});throw ve(t,t.env.data.logs.create(n.tenant.id,d)),new ee(403,{message:"Invalid client credentials"})}else if(new Date(r.expires_at)<new Date){const d=be(t,{type:_e.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Code expired",userId:r.user_id});throw ve(t,t.env.data.logs.create(n.tenant.id,d)),new ee(403,{message:"Code expired"})}else if(r.used_at){const d=be(t,{type:_e.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid authorization code",userId:r.user_id});throw ve(t,t.env.data.logs.create(n.tenant.id,d)),new ee(403,{error:"invalid_grant",error_description:"Invalid authorization code"})}const i=await t.env.data.loginSessions.get(n.tenant.id,r.login_id);if(!i)throw new ee(403,{message:"Invalid login"});if(e.organization&&i.authParams.organization&&e.organization!==i.authParams.organization)throw new ee(400,{error:"invalid_request",error_description:"Organization parameter does not match login session organization"});if("client_secret"in e){const d=await t.env.data.legacyClients.get("DEFAULT_CLIENT");if(!$s(n.client_secret,e.client_secret)&&!$s(d==null?void 0:d.client_secret,e.client_secret)){const u=be(t,{type:_e.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid client credentials",userId:r.user_id});throw ve(t,t.env.data.logs.create(n.tenant.id,u)),new ee(403,{message:"Invalid client credentials"})}}else if(r.code_challenge&&r.code_challenge_method&&e.code_verifier){const d=await $v(e.code_verifier,r.code_challenge_method);if(!$s(d,r.code_challenge)){const u=be(t,{type:_e.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid client credentials",userId:r.user_id});throw ve(t,t.env.data.logs.create(n.tenant.id,u)),new ee(403,{message:"Invalid client credentials"})}}if(r.redirect_uri&&r.redirect_uri!==e.redirect_uri){const d=be(t,{type:_e.FAILED_EXCHANGE_AUTHORIZATION_CODE_FOR_ACCESS_TOKEN,description:"Invalid redirect uri",userId:r.user_id});throw ve(t,t.env.data.logs.create(n.tenant.id,d)),new ee(403,{message:"Invalid redirect uri"})}const s=await t.env.data.users.get(n.tenant.id,r.user_id);if(!s)throw new ee(403,{message:"User not found"});await t.env.data.codes.used(n.tenant.id,e.code);let a;i.session_id&&((l=i.authParams.scope)!=null&&l.split(" ").includes("offline_access"))&&(a=await Tm(t,{user:s,client:n,session_id:i.session_id,scope:i.authParams.scope,audience:i.authParams.audience}));let c;if(i.authParams.organization){const d=await t.env.data.organizations.get(n.tenant.id,i.authParams.organization);d?c={id:d.id,name:d.name}:c={id:i.authParams.organization,name:"Unknown"}}return{user:s,client:n,loginSession:i,session_id:i.session_id,refresh_token:a==null?void 0:a.id,organization:c,authParams:{...i.authParams,state:r.state,nonce:r.nonce,response_mode:ln.WEB_MESSAGE,client_id:n.client_id,scope:i.authParams.scope,audience:i.authParams.audience}}}const s5=o.z.object({grant_type:o.z.literal("refresh_token"),client_id:o.z.string(),redirect_uri:o.z.string().optional(),refresh_token:o.z.string()});async function a5(t,e){const n=await t.env.data.legacyClients.get(e.client_id);if(!n)throw new ee(403,{message:"Client not found"});const r=await t.env.data.refreshTokens.get(n.tenant.id,e.refresh_token);if(r){if(r.expires_at&&new Date(r.expires_at)<new Date||r.idle_expires_at&&new Date(r.idle_expires_at)<new Date)throw new ee(403,{error:"invalid_grant",error_description:"Refresh token has expired"})}else throw new ee(403,{error:"invalid_grant",error_description:"Invalid refresh token"});const i=await t.env.data.users.get(n.tenant.id,r.user_id);if(!i)throw new ee(403,{message:"User not found"});const s=r.resource_servers[0];if(r.idle_expires_at){const a=new Date(Date.now()+2592e6);await t.env.data.refreshTokens.update(n.tenant.id,r.id,{idle_expires_at:a.toISOString(),last_exchanged_at:new Date().toISOString(),device:{...r.device,last_ip:t.req.header["x-real-ip"]||"",last_user_agent:t.req.header["user-agent"]||""}})}return{user:i,client:n,refresh_token:r.id,session_id:r.session_id,authParams:{client_id:n.client_id,audience:s==null?void 0:s.audience,scope:s==null?void 0:s.scopes,response_mode:ln.WEB_MESSAGE}}}const c5={version:4,country_calling_codes:{1:["US","AG","AI","AS","BB","BM","BS","CA","DM","DO","GD","GU","JM","KN","KY","LC","MP","MS","PR","SX","TC","TT","VC","VG","VI"],7:["RU","KZ"],20:["EG"],27:["ZA"],30:["GR"],31:["NL"],32:["BE"],33:["FR"],34:["ES"],36:["HU"],39:["IT","VA"],40:["RO"],41:["CH"],43:["AT"],44:["GB","GG","IM","JE"],45:["DK"],46:["SE"],47:["NO","SJ"],48:["PL"],49:["DE"],51:["PE"],52:["MX"],53:["CU"],54:["AR"],55:["BR"],56:["CL"],57:["CO"],58:["VE"],60:["MY"],61:["AU","CC","CX"],62:["ID"],63:["PH"],64:["NZ"],65:["SG"],66:["TH"],81:["JP"],82:["KR"],84:["VN"],86:["CN"],90:["TR"],91:["IN"],92:["PK"],93:["AF"],94:["LK"],95:["MM"],98:["IR"],211:["SS"],212:["MA","EH"],213:["DZ"],216:["TN"],218:["LY"],220:["GM"],221:["SN"],222:["MR"],223:["ML"],224:["GN"],225:["CI"],226:["BF"],227:["NE"],228:["TG"],229:["BJ"],230:["MU"],231:["LR"],232:["SL"],233:["GH"],234:["NG"],235:["TD"],236:["CF"],237:["CM"],238:["CV"],239:["ST"],240:["GQ"],241:["GA"],242:["CG"],243:["CD"],244:["AO"],245:["GW"],246:["IO"],247:["AC"],248:["SC"],249:["SD"],250:["RW"],251:["ET"],252:["SO"],253:["DJ"],254:["KE"],255:["TZ"],256:["UG"],257:["BI"],258:["MZ"],260:["ZM"],261:["MG"],262:["RE","YT"],263:["ZW"],264:["NA"],265:["MW"],266:["LS"],267:["BW"],268:["SZ"],269:["KM"],290:["SH","TA"],291:["ER"],297:["AW"],298:["FO"],299:["GL"],350:["GI"],351:["PT"],352:["LU"],353:["IE"],354:["IS"],355:["AL"],356:["MT"],357:["CY"],358:["FI","AX"],359:["BG"],370:["LT"],371:["LV"],372:["EE"],373:["MD"],374:["AM"],375:["BY"],376:["AD"],377:["MC"],378:["SM"],380:["UA"],381:["RS"],382:["ME"],383:["XK"],385:["HR"],386:["SI"],387:["BA"],389:["MK"],420:["CZ"],421:["SK"],423:["LI"],500:["FK"],501:["BZ"],502:["GT"],503:["SV"],504:["HN"],505:["NI"],506:["CR"],507:["PA"],508:["PM"],509:["HT"],590:["GP","BL","MF"],591:["BO"],592:["GY"],593:["EC"],594:["GF"],595:["PY"],596:["MQ"],597:["SR"],598:["UY"],599:["CW","BQ"],670:["TL"],672:["NF"],673:["BN"],674:["NR"],675:["PG"],676:["TO"],677:["SB"],678:["VU"],679:["FJ"],680:["PW"],681:["WF"],682:["CK"],683:["NU"],685:["WS"],686:["KI"],687:["NC"],688:["TV"],689:["PF"],690:["TK"],691:["FM"],692:["MH"],850:["KP"],852:["HK"],853:["MO"],855:["KH"],856:["LA"],880:["BD"],886:["TW"],960:["MV"],961:["LB"],962:["JO"],963:["SY"],964:["IQ"],965:["KW"],966:["SA"],967:["YE"],968:["OM"],970:["PS"],971:["AE"],972:["IL"],973:["BH"],974:["QA"],975:["BT"],976:["MN"],977:["NP"],992:["TJ"],993:["TM"],994:["AZ"],995:["GE"],996:["KG"],998:["UZ"]},countries:{AC:["247","00","(?:[01589]\\d|[46])\\d{4}",[5,6]],AD:["376","00","(?:1|6\\d)\\d{7}|[135-9]\\d{5}",[6,8,9],[["(\\d{3})(\\d{3})","$1 $2",["[135-9]"]],["(\\d{4})(\\d{4})","$1 $2",["1"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["6"]]]],AE:["971","00","(?:[4-7]\\d|9[0-689])\\d{7}|800\\d{2,9}|[2-4679]\\d{7}",[5,6,7,8,9,10,11,12],[["(\\d{3})(\\d{2,9})","$1 $2",["60|8"]],["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["[236]|[479][2-8]"],"0$1"],["(\\d{3})(\\d)(\\d{5})","$1 $2 $3",["[479]"]],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["5"],"0$1"]],"0"],AF:["93","00","[2-7]\\d{8}",[9],[["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[2-7]"],"0$1"]],"0"],AG:["1","011","(?:268|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([457]\\d{6})$|1","268$1",0,"268"],AI:["1","011","(?:264|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2457]\\d{6})$|1","264$1",0,"264"],AL:["355","00","(?:700\\d\\d|900)\\d{3}|8\\d{5,7}|(?:[2-5]|6\\d)\\d{7}",[6,7,8,9],[["(\\d{3})(\\d{3,4})","$1 $2",["80|9"],"0$1"],["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["4[2-6]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[2358][2-5]|4"],"0$1"],["(\\d{3})(\\d{5})","$1 $2",["[23578]"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["6"],"0$1"]],"0"],AM:["374","00","(?:[1-489]\\d|55|60|77)\\d{6}",[8],[["(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3",["[89]0"],"0 $1"],["(\\d{3})(\\d{5})","$1 $2",["2|3[12]"],"(0$1)"],["(\\d{2})(\\d{6})","$1 $2",["1|47"],"(0$1)"],["(\\d{2})(\\d{6})","$1 $2",["[3-9]"],"0$1"]],"0"],AO:["244","00","[29]\\d{8}",[9],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[29]"]]]],AR:["54","00","(?:11|[89]\\d\\d)\\d{8}|[2368]\\d{9}",[10,11],[["(\\d{4})(\\d{2})(\\d{4})","$1 $2-$3",["2(?:2[024-9]|3[0-59]|47|6[245]|9[02-8])|3(?:3[28]|4[03-9]|5[2-46-8]|7[1-578]|8[2-9])","2(?:[23]02|6(?:[25]|4[6-8])|9(?:[02356]|4[02568]|72|8[23]))|3(?:3[28]|4(?:[04679]|3[5-8]|5[4-68]|8[2379])|5(?:[2467]|3[237]|8[2-5])|7[1-578]|8(?:[2469]|3[2578]|5[4-8]|7[36-8]|8[5-8]))|2(?:2[24-9]|3[1-59]|47)","2(?:[23]02|6(?:[25]|4(?:64|[78]))|9(?:[02356]|4(?:[0268]|5[2-6])|72|8[23]))|3(?:3[28]|4(?:[04679]|3[78]|5(?:4[46]|8)|8[2379])|5(?:[2467]|3[237]|8[23])|7[1-578]|8(?:[2469]|3[278]|5[56][46]|86[3-6]))|2(?:2[24-9]|3[1-59]|47)|38(?:[58][78]|7[378])|3(?:4[35][56]|58[45]|8(?:[38]5|54|76))[4-6]","2(?:[23]02|6(?:[25]|4(?:64|[78]))|9(?:[02356]|4(?:[0268]|5[2-6])|72|8[23]))|3(?:3[28]|4(?:[04679]|3(?:5(?:4[0-25689]|[56])|[78])|58|8[2379])|5(?:[2467]|3[237]|8(?:[23]|4(?:[45]|60)|5(?:4[0-39]|5|64)))|7[1-578]|8(?:[2469]|3[278]|54(?:4|5[13-7]|6[89])|86[3-6]))|2(?:2[24-9]|3[1-59]|47)|38(?:[58][78]|7[378])|3(?:454|85[56])[46]|3(?:4(?:36|5[56])|8(?:[38]5|76))[4-6]"],"0$1",1],["(\\d{2})(\\d{4})(\\d{4})","$1 $2-$3",["1"],"0$1",1],["(\\d{3})(\\d{3})(\\d{4})","$1-$2-$3",["[68]"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2-$3",["[23]"],"0$1",1],["(\\d)(\\d{4})(\\d{2})(\\d{4})","$2 15-$3-$4",["9(?:2[2-469]|3[3-578])","9(?:2(?:2[024-9]|3[0-59]|47|6[245]|9[02-8])|3(?:3[28]|4[03-9]|5[2-46-8]|7[1-578]|8[2-9]))","9(?:2(?:[23]02|6(?:[25]|4[6-8])|9(?:[02356]|4[02568]|72|8[23]))|3(?:3[28]|4(?:[04679]|3[5-8]|5[4-68]|8[2379])|5(?:[2467]|3[237]|8[2-5])|7[1-578]|8(?:[2469]|3[2578]|5[4-8]|7[36-8]|8[5-8])))|92(?:2[24-9]|3[1-59]|47)","9(?:2(?:[23]02|6(?:[25]|4(?:64|[78]))|9(?:[02356]|4(?:[0268]|5[2-6])|72|8[23]))|3(?:3[28]|4(?:[04679]|3[78]|5(?:4[46]|8)|8[2379])|5(?:[2467]|3[237]|8[23])|7[1-578]|8(?:[2469]|3[278]|5(?:[56][46]|[78])|7[378]|8(?:6[3-6]|[78]))))|92(?:2[24-9]|3[1-59]|47)|93(?:4[35][56]|58[45]|8(?:[38]5|54|76))[4-6]","9(?:2(?:[23]02|6(?:[25]|4(?:64|[78]))|9(?:[02356]|4(?:[0268]|5[2-6])|72|8[23]))|3(?:3[28]|4(?:[04679]|3(?:5(?:4[0-25689]|[56])|[78])|5(?:4[46]|8)|8[2379])|5(?:[2467]|3[237]|8(?:[23]|4(?:[45]|60)|5(?:4[0-39]|5|64)))|7[1-578]|8(?:[2469]|3[278]|5(?:4(?:4|5[13-7]|6[89])|[56][46]|[78])|7[378]|8(?:6[3-6]|[78]))))|92(?:2[24-9]|3[1-59]|47)|93(?:4(?:36|5[56])|8(?:[38]5|76))[4-6]"],"0$1",0,"$1 $2 $3-$4"],["(\\d)(\\d{2})(\\d{4})(\\d{4})","$2 15-$3-$4",["91"],"0$1",0,"$1 $2 $3-$4"],["(\\d{3})(\\d{3})(\\d{5})","$1-$2-$3",["8"],"0$1"],["(\\d)(\\d{3})(\\d{3})(\\d{4})","$2 15-$3-$4",["9"],"0$1",0,"$1 $2 $3-$4"]],"0",0,"0?(?:(11|2(?:2(?:02?|[13]|2[13-79]|4[1-6]|5[2457]|6[124-8]|7[1-4]|8[13-6]|9[1267])|3(?:02?|1[467]|2[03-6]|3[13-8]|[49][2-6]|5[2-8]|[67])|4(?:7[3-578]|9)|6(?:[0136]|2[24-6]|4[6-8]?|5[15-8])|80|9(?:0[1-3]|[19]|2\\d|3[1-6]|4[02568]?|5[2-4]|6[2-46]|72?|8[23]?))|3(?:3(?:2[79]|6|8[2578])|4(?:0[0-24-9]|[12]|3[5-8]?|4[24-7]|5[4-68]?|6[02-9]|7[126]|8[2379]?|9[1-36-8])|5(?:1|2[1245]|3[237]?|4[1-46-9]|6[2-4]|7[1-6]|8[2-5]?)|6[24]|7(?:[069]|1[1568]|2[15]|3[145]|4[13]|5[14-8]|7[2-57]|8[126])|8(?:[01]|2[15-7]|3[2578]?|4[13-6]|5[4-8]?|6[1-357-9]|7[36-8]?|8[5-8]?|9[124])))15)?","9$1"],AS:["1","011","(?:[58]\\d\\d|684|900)\\d{7}",[10],0,"1",0,"([267]\\d{6})$|1","684$1",0,"684"],AT:["43","00","1\\d{3,12}|2\\d{6,12}|43(?:(?:0\\d|5[02-9])\\d{3,9}|2\\d{4,5}|[3467]\\d{4}|8\\d{4,6}|9\\d{4,7})|5\\d{4,12}|8\\d{7,12}|9\\d{8,12}|(?:[367]\\d|4[0-24-9])\\d{4,11}",[4,5,6,7,8,9,10,11,12,13],[["(\\d)(\\d{3,12})","$1 $2",["1(?:11|[2-9])"],"0$1"],["(\\d{3})(\\d{2})","$1 $2",["517"],"0$1"],["(\\d{2})(\\d{3,5})","$1 $2",["5[079]"],"0$1"],["(\\d{3})(\\d{3,10})","$1 $2",["(?:31|4)6|51|6(?:48|5[0-3579]|[6-9])|7(?:20|32|8)|[89]","(?:31|4)6|51|6(?:485|5[0-3579]|[6-9])|7(?:20|32|8)|[89]"],"0$1"],["(\\d{4})(\\d{3,9})","$1 $2",["[2-467]|5[2-6]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["5"],"0$1"],["(\\d{2})(\\d{4})(\\d{4,7})","$1 $2 $3",["5"],"0$1"]],"0"],AU:["61","001[14-689]|14(?:1[14]|34|4[17]|[56]6|7[47]|88)0011","1(?:[0-79]\\d{7}(?:\\d(?:\\d{2})?)?|8[0-24-9]\\d{7})|[2-478]\\d{8}|1\\d{4,7}",[5,6,7,8,9,10,12],[["(\\d{2})(\\d{3,4})","$1 $2",["16"],"0$1"],["(\\d{2})(\\d{3})(\\d{2,4})","$1 $2 $3",["16"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["14|4"],"0$1"],["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["[2378]"],"(0$1)"],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["1(?:30|[89])"]]],"0",0,"(183[12])|0",0,0,0,[["(?:(?:(?:2(?:[0-26-9]\\d|3[0-8]|4[02-9]|5[0135-9])|7(?:[013-57-9]\\d|2[0-8]))\\d|3(?:(?:[0-3589]\\d|6[1-9]|7[0-35-9])\\d|4(?:[0-578]\\d|90)))\\d\\d|8(?:51(?:0(?:0[03-9]|[12479]\\d|3[2-9]|5[0-8]|6[1-9]|8[0-7])|1(?:[0235689]\\d|1[0-69]|4[0-589]|7[0-47-9])|2(?:0[0-79]|[18][13579]|2[14-9]|3[0-46-9]|[4-6]\\d|7[89]|9[0-4])|3\\d\\d)|(?:6[0-8]|[78]\\d)\\d{3}|9(?:[02-9]\\d{3}|1(?:(?:[0-58]\\d|6[0135-9])\\d|7(?:0[0-24-9]|[1-9]\\d)|9(?:[0-46-9]\\d|5[0-79])))))\\d{3}",[9]],["4(?:79[01]|83[0-389]|94[0-4])\\d{5}|4(?:[0-36]\\d|4[047-9]|5[0-25-9]|7[02-8]|8[0-24-9]|9[0-37-9])\\d{6}",[9]],["180(?:0\\d{3}|2)\\d{3}",[7,10]],["190[0-26]\\d{6}",[10]],0,0,0,["163\\d{2,6}",[5,6,7,8,9]],["14(?:5(?:1[0458]|[23][458])|71\\d)\\d{4}",[9]],["13(?:00\\d{6}(?:\\d{2})?|45[0-4]\\d{3})|13\\d{4}",[6,8,10,12]]],"0011"],AW:["297","00","(?:[25-79]\\d\\d|800)\\d{4}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[25-9]"]]]],AX:["358","00|99(?:[01469]|5(?:[14]1|3[23]|5[59]|77|88|9[09]))","2\\d{4,9}|35\\d{4,5}|(?:60\\d\\d|800)\\d{4,6}|7\\d{5,11}|(?:[14]\\d|3[0-46-9]|50)\\d{4,8}",[5,6,7,8,9,10,11,12],0,"0",0,0,0,0,"18",0,"00"],AZ:["994","00","365\\d{6}|(?:[124579]\\d|60|88)\\d{7}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["90"],"0$1"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["1[28]|2|365|46","1[28]|2|365[45]|46","1[28]|2|365(?:4|5[02])|46"],"(0$1)"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[13-9]"],"0$1"]],"0"],BA:["387","00","6\\d{8}|(?:[35689]\\d|49|70)\\d{6}",[8,9],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["6[1-3]|[7-9]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2-$3",["[3-5]|6[56]"],"0$1"],["(\\d{2})(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3 $4",["6"],"0$1"]],"0"],BB:["1","011","(?:246|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2-9]\\d{6})$|1","246$1",0,"246"],BD:["880","00","[1-469]\\d{9}|8[0-79]\\d{7,8}|[2-79]\\d{8}|[2-9]\\d{7}|[3-9]\\d{6}|[57-9]\\d{5}",[6,7,8,9,10],[["(\\d{2})(\\d{4,6})","$1-$2",["31[5-8]|[459]1"],"0$1"],["(\\d{3})(\\d{3,7})","$1-$2",["3(?:[67]|8[013-9])|4(?:6[168]|7|[89][18])|5(?:6[128]|9)|6(?:[15]|28|4[14])|7[2-589]|8(?:0[014-9]|[12])|9[358]|(?:3[2-5]|4[235]|5[2-578]|6[0389]|76|8[3-7]|9[24])1|(?:44|66)[01346-9]"],"0$1"],["(\\d{4})(\\d{3,6})","$1-$2",["[13-9]|2[23]"],"0$1"],["(\\d)(\\d{7,8})","$1-$2",["2"],"0$1"]],"0"],BE:["32","00","4\\d{8}|[1-9]\\d{7}",[8,9],[["(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3",["(?:80|9)0"],"0$1"],["(\\d)(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[239]|4[23]"],"0$1"],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[15-8]"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["4"],"0$1"]],"0"],BF:["226","00","[025-7]\\d{7}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[025-7]"]]]],BG:["359","00","00800\\d{7}|[2-7]\\d{6,7}|[89]\\d{6,8}|2\\d{5}",[6,7,8,9,12],[["(\\d)(\\d)(\\d{2})(\\d{2})","$1 $2 $3 $4",["2"],"0$1"],["(\\d{3})(\\d{4})","$1 $2",["43[1-6]|70[1-9]"],"0$1"],["(\\d)(\\d{3})(\\d{3,4})","$1 $2 $3",["2"],"0$1"],["(\\d{2})(\\d{3})(\\d{2,3})","$1 $2 $3",["[356]|4[124-7]|7[1-9]|8[1-6]|9[1-7]"],"0$1"],["(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3",["(?:70|8)0"],"0$1"],["(\\d{3})(\\d{3})(\\d{2})","$1 $2 $3",["43[1-7]|7"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[48]|9[08]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["9"],"0$1"]],"0"],BH:["973","00","[136-9]\\d{7}",[8],[["(\\d{4})(\\d{4})","$1 $2",["[13679]|8[02-4679]"]]]],BI:["257","00","(?:[267]\\d|31)\\d{6}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[2367]"]]]],BJ:["229","00","(?:01\\d|[24-689])\\d{7}",[8,10],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[24-689]"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4 $5",["0"]]]],BL:["590","00","(?:590\\d|7090)\\d{5}|(?:69|80|9\\d)\\d{7}",[9],0,"0",0,0,0,0,0,[["590(?:2[7-9]|3[3-7]|5[12]|87)\\d{4}"],["(?:69(?:0\\d\\d|1(?:2[2-9]|3[0-5])|4(?:0[89]|1[2-6]|9\\d)|6(?:1[016-9]|5[0-4]|[67]\\d))|7090[0-4])\\d{4}"],["80[0-5]\\d{6}"],0,0,0,0,0,["9(?:(?:39[5-7]|76[018])\\d|475[0-6])\\d{4}"]]],BM:["1","011","(?:441|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2-9]\\d{6})$|1","441$1",0,"441"],BN:["673","00","[2-578]\\d{6}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[2-578]"]]]],BO:["591","00(?:1\\d)?","8001\\d{5}|(?:[2-467]\\d|50)\\d{6}",[8,9],[["(\\d)(\\d{7})","$1 $2",["[235]|4[46]"]],["(\\d{8})","$1",["[67]"]],["(\\d{3})(\\d{2})(\\d{4})","$1 $2 $3",["8"]]],"0",0,"0(1\\d)?"],BQ:["599","00","(?:[34]1|7\\d)\\d{5}",[7],0,0,0,0,0,0,"[347]"],BR:["55","00(?:1[245]|2[1-35]|31|4[13]|[56]5|99)","[1-467]\\d{9,10}|55[0-46-9]\\d{8}|[34]\\d{7}|55\\d{7,8}|(?:5[0-46-9]|[89]\\d)\\d{7,9}",[8,9,10,11],[["(\\d{4})(\\d{4})","$1-$2",["300|4(?:0[02]|37|86)","300|4(?:0(?:0|20)|370|864)"]],["(\\d{3})(\\d{2,3})(\\d{4})","$1 $2 $3",["(?:[358]|90)0"],"0$1"],["(\\d{2})(\\d{4})(\\d{4})","$1 $2-$3",["(?:[14689][1-9]|2[12478]|3[1-578]|5[13-5]|7[13-579])[2-57]"],"($1)"],["(\\d{2})(\\d{5})(\\d{4})","$1 $2-$3",["[16][1-9]|[2-57-9]"],"($1)"]],"0",0,"(?:0|90)(?:(1[245]|2[1-35]|31|4[13]|[56]5|99)(\\d{10,11}))?","$2"],BS:["1","011","(?:242|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([3-8]\\d{6})$|1","242$1",0,"242"],BT:["975","00","[17]\\d{7}|[2-8]\\d{6}",[7,8],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["[2-68]|7[246]"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["1[67]|7"]]]],BW:["267","00","(?:0800|(?:[37]|800)\\d)\\d{6}|(?:[2-6]\\d|90)\\d{5}",[7,8,10],[["(\\d{2})(\\d{5})","$1 $2",["90"]],["(\\d{3})(\\d{4})","$1 $2",["[24-6]|3[15-9]"]],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[37]"]],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["0"]],["(\\d{3})(\\d{4})(\\d{3})","$1 $2 $3",["8"]]]],BY:["375","810","(?:[12]\\d|33|44|902)\\d{7}|8(?:0[0-79]\\d{5,7}|[1-7]\\d{9})|8(?:1[0-489]|[5-79]\\d)\\d{7}|8[1-79]\\d{6,7}|8[0-79]\\d{5}|8\\d{5}",[6,7,8,9,10,11],[["(\\d{3})(\\d{3})","$1 $2",["800"],"8 $1"],["(\\d{3})(\\d{2})(\\d{2,4})","$1 $2 $3",["800"],"8 $1"],["(\\d{4})(\\d{2})(\\d{3})","$1 $2-$3",["1(?:5[169]|6[3-5]|7[179])|2(?:1[35]|2[34]|3[3-5])","1(?:5[169]|6(?:3[1-3]|4|5[125])|7(?:1[3-9]|7[0-24-6]|9[2-7]))|2(?:1[35]|2[34]|3[3-5])"],"8 0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2-$3-$4",["1(?:[56]|7[467])|2[1-3]"],"8 0$1"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2-$3-$4",["[1-4]"],"8 0$1"],["(\\d{3})(\\d{3,4})(\\d{4})","$1 $2 $3",["[89]"],"8 $1"]],"8",0,"0|80?",0,0,0,0,"8~10"],BZ:["501","00","(?:0800\\d|[2-8])\\d{6}",[7,11],[["(\\d{3})(\\d{4})","$1-$2",["[2-8]"]],["(\\d)(\\d{3})(\\d{4})(\\d{3})","$1-$2-$3-$4",["0"]]]],CA:["1","011","[2-9]\\d{9}|3\\d{6}",[7,10],0,"1",0,0,0,0,0,[["(?:2(?:04|[23]6|[48]9|50|63)|3(?:06|43|54|6[578]|82)|4(?:03|1[68]|[26]8|3[178]|50|74)|5(?:06|1[49]|48|79|8[147])|6(?:04|[18]3|39|47|72)|7(?:0[59]|42|53|78|8[02])|8(?:[06]7|19|25|7[39])|9(?:0[25]|42))[2-9]\\d{6}",[10]],["",[10]],["8(?:00|33|44|55|66|77|88)[2-9]\\d{6}",[10]],["900[2-9]\\d{6}",[10]],["52(?:3(?:[2-46-9][02-9]\\d|5(?:[02-46-9]\\d|5[0-46-9]))|4(?:[2-478][02-9]\\d|5(?:[034]\\d|2[024-9]|5[0-46-9])|6(?:0[1-9]|[2-9]\\d)|9(?:[05-9]\\d|2[0-5]|49)))\\d{4}|52[34][2-9]1[02-9]\\d{4}|(?:5(?:2[125-9]|33|44|66|77|88)|6(?:22|33))[2-9]\\d{6}",[10]],0,["310\\d{4}",[7]],0,["600[2-9]\\d{6}",[10]]]],CC:["61","001[14-689]|14(?:1[14]|34|4[17]|[56]6|7[47]|88)0011","1(?:[0-79]\\d{8}(?:\\d{2})?|8[0-24-9]\\d{7})|[148]\\d{8}|1\\d{5,7}",[6,7,8,9,10,12],0,"0",0,"([59]\\d{7})$|0","8$1",0,0,[["8(?:51(?:0(?:02|31|60|89)|1(?:18|76)|223)|91(?:0(?:1[0-2]|29)|1(?:[28]2|50|79)|2(?:10|64)|3(?:[06]8|22)|4[29]8|62\\d|70[23]|959))\\d{3}",[9]],["4(?:79[01]|83[0-389]|94[0-4])\\d{5}|4(?:[0-36]\\d|4[047-9]|5[0-25-9]|7[02-8]|8[0-24-9]|9[0-37-9])\\d{6}",[9]],["180(?:0\\d{3}|2)\\d{3}",[7,10]],["190[0-26]\\d{6}",[10]],0,0,0,0,["14(?:5(?:1[0458]|[23][458])|71\\d)\\d{4}",[9]],["13(?:00\\d{6}(?:\\d{2})?|45[0-4]\\d{3})|13\\d{4}",[6,8,10,12]]],"0011"],CD:["243","00","(?:(?:[189]|5\\d)\\d|2)\\d{7}|[1-68]\\d{6}",[7,8,9,10],[["(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3",["88"],"0$1"],["(\\d{2})(\\d{5})","$1 $2",["[1-6]"],"0$1"],["(\\d{2})(\\d{2})(\\d{4})","$1 $2 $3",["2"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["1"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[89]"],"0$1"],["(\\d{2})(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3 $4",["5"],"0$1"]],"0"],CF:["236","00","(?:[27]\\d{3}|8776)\\d{4}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[278]"]]]],CG:["242","00","222\\d{6}|(?:0\\d|80)\\d{7}",[9],[["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["8"]],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[02]"]]]],CH:["41","00","8\\d{11}|[2-9]\\d{8}",[9,12],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["8[047]|90"],"0$1"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[2-79]|81"],"0$1"],["(\\d{3})(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4 $5",["8"],"0$1"]],"0"],CI:["225","00","[02]\\d{9}",[10],[["(\\d{2})(\\d{2})(\\d)(\\d{5})","$1 $2 $3 $4",["2"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{4})","$1 $2 $3 $4",["0"]]]],CK:["682","00","[2-578]\\d{4}",[5],[["(\\d{2})(\\d{3})","$1 $2",["[2-578]"]]]],CL:["56","(?:0|1(?:1[0-69]|2[02-5]|5[13-58]|69|7[0167]|8[018]))0","12300\\d{6}|6\\d{9,10}|[2-9]\\d{8}",[9,10,11],[["(\\d{5})(\\d{4})","$1 $2",["219","2196"],"($1)"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["44"]],["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["2[1-36]"],"($1)"],["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["9[2-9]"]],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["3[2-5]|[47]|5[1-3578]|6[13-57]|8(?:0[1-9]|[1-9])"],"($1)"],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["60|8"]],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["1"]],["(\\d{3})(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3 $4",["60"]]]],CM:["237","00","[26]\\d{8}|88\\d{6,7}",[8,9],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["88"]],["(\\d)(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4 $5",["[26]|88"]]]],CN:["86","00|1(?:[12]\\d|79)\\d\\d00","(?:(?:1[03-689]|2\\d)\\d\\d|6)\\d{8}|1\\d{10}|[126]\\d{6}(?:\\d(?:\\d{2})?)?|86\\d{5,6}|(?:[3-579]\\d|8[0-57-9])\\d{5,9}",[7,8,9,10,11,12],[["(\\d{2})(\\d{5,6})","$1 $2",["(?:10|2[0-57-9])[19]|3(?:[157]|35|49|9[1-68])|4(?:1[124-9]|2[179]|6[47-9]|7|8[23])|5(?:[1357]|2[37]|4[36]|6[1-46]|80)|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:07|1[236-8]|2[5-7]|[37]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|3|4[13]|5[1-5]|7[0-79]|9[0-35-9])|(?:4[35]|59|85)[1-9]","(?:10|2[0-57-9])(?:1[02]|9[56])|8078|(?:3(?:[157]\\d|35|49|9[1-68])|4(?:1[124-9]|2[179]|[35][1-9]|6[47-9]|7\\d|8[23])|5(?:[1357]\\d|2[37]|4[36]|6[1-46]|80|9[1-9])|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]\\d|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:1[236-8]|2[5-7]|[37]\\d|5[1-9]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|3\\d|4[13]|5[1-5]|7[0-79]|9[0-35-9]))1","10(?:1(?:0|23)|9[56])|2[0-57-9](?:1(?:00|23)|9[56])|80781|(?:3(?:[157]\\d|35|49|9[1-68])|4(?:1[124-9]|2[179]|[35][1-9]|6[47-9]|7\\d|8[23])|5(?:[1357]\\d|2[37]|4[36]|6[1-46]|80|9[1-9])|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]\\d|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:1[236-8]|2[5-7]|[37]\\d|5[1-9]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|3\\d|4[13]|5[1-5]|7[0-79]|9[0-35-9]))12","10(?:1(?:0|23)|9[56])|2[0-57-9](?:1(?:00|23)|9[56])|807812|(?:3(?:[157]\\d|35|49|9[1-68])|4(?:1[124-9]|2[179]|[35][1-9]|6[47-9]|7\\d|8[23])|5(?:[1357]\\d|2[37]|4[36]|6[1-46]|80|9[1-9])|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]\\d|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:1[236-8]|2[5-7]|[37]\\d|5[1-9]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|3\\d|4[13]|5[1-5]|7[0-79]|9[0-35-9]))123","10(?:1(?:0|23)|9[56])|2[0-57-9](?:1(?:00|23)|9[56])|(?:3(?:[157]\\d|35|49|9[1-68])|4(?:1[124-9]|2[179]|[35][1-9]|6[47-9]|7\\d|8[23])|5(?:[1357]\\d|2[37]|4[36]|6[1-46]|80|9[1-9])|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]\\d|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:078|1[236-8]|2[5-7]|[37]\\d|5[1-9]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|3\\d|4[13]|5[1-5]|7[0-79]|9[0-35-9]))123"],"0$1"],["(\\d{3})(\\d{5,6})","$1 $2",["3(?:[157]|35|49|9[1-68])|4(?:[17]|2[179]|6[47-9]|8[23])|5(?:[1357]|2[37]|4[36]|6[1-46]|80)|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:1[236-8]|2[5-7]|[37]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|[379]|4[13]|5[1-5])|(?:4[35]|59|85)[1-9]","(?:3(?:[157]\\d|35|49|9[1-68])|4(?:[17]\\d|2[179]|[35][1-9]|6[47-9]|8[23])|5(?:[1357]\\d|2[37]|4[36]|6[1-46]|80|9[1-9])|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]\\d|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:1[236-8]|2[5-7]|[37]\\d|5[1-9]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|[379]\\d|4[13]|5[1-5]))[19]","85[23](?:10|95)|(?:3(?:[157]\\d|35|49|9[1-68])|4(?:[17]\\d|2[179]|[35][1-9]|6[47-9]|8[23])|5(?:[1357]\\d|2[37]|4[36]|6[1-46]|80|9[1-9])|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]\\d|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:1[236-8]|2[5-7]|[37]\\d|5[14-9]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|[379]\\d|4[13]|5[1-5]))(?:10|9[56])","85[23](?:100|95)|(?:3(?:[157]\\d|35|49|9[1-68])|4(?:[17]\\d|2[179]|[35][1-9]|6[47-9]|8[23])|5(?:[1357]\\d|2[37]|4[36]|6[1-46]|80|9[1-9])|6(?:3[1-5]|6[0238]|9[12])|7(?:01|[1579]\\d|2[248]|3[014-9]|4[3-6]|6[023689])|8(?:1[236-8]|2[5-7]|[37]\\d|5[14-9]|8[36-8]|9[1-8])|9(?:0[1-3689]|1[1-79]|[379]\\d|4[13]|5[1-5]))(?:100|9[56])"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["(?:4|80)0"]],["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["10|2(?:[02-57-9]|1[1-9])","10|2(?:[02-57-9]|1[1-9])","10[0-79]|2(?:[02-57-9]|1[1-79])|(?:10|21)8(?:0[1-9]|[1-9])"],"0$1",1],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["3(?:[3-59]|7[02-68])|4(?:[26-8]|3[3-9]|5[2-9])|5(?:3[03-9]|[468]|7[028]|9[2-46-9])|6|7(?:[0-247]|3[04-9]|5[0-4689]|6[2368])|8(?:[1-358]|9[1-7])|9(?:[013479]|5[1-5])|(?:[34]1|55|79|87)[02-9]"],"0$1",1],["(\\d{3})(\\d{7,8})","$1 $2",["9"]],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["80"],"0$1",1],["(\\d{3})(\\d{4})(\\d{4})","$1 $2 $3",["[3-578]"],"0$1",1],["(\\d{3})(\\d{4})(\\d{4})","$1 $2 $3",["1[3-9]"]],["(\\d{2})(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3 $4",["[12]"],"0$1",1]],"0",0,"(1(?:[12]\\d|79)\\d\\d)|0",0,0,0,0,"00"],CO:["57","00(?:4(?:[14]4|56)|[579])","(?:46|60\\d\\d)\\d{6}|(?:1\\d|[39])\\d{9}",[8,10,11],[["(\\d{4})(\\d{4})","$1 $2",["46"]],["(\\d{3})(\\d{7})","$1 $2",["6|90"],"($1)"],["(\\d{3})(\\d{7})","$1 $2",["3[0-357]|91"]],["(\\d)(\\d{3})(\\d{7})","$1-$2-$3",["1"],"0$1",0,"$1 $2 $3"]],"0",0,"0([3579]|4(?:[14]4|56))?"],CR:["506","00","(?:8\\d|90)\\d{8}|(?:[24-8]\\d{3}|3005)\\d{4}",[8,10],[["(\\d{4})(\\d{4})","$1 $2",["[2-7]|8[3-9]"]],["(\\d{3})(\\d{3})(\\d{4})","$1-$2-$3",["[89]"]]],0,0,"(19(?:0[0-2468]|1[09]|20|66|77|99))"],CU:["53","119","(?:[2-7]|8\\d\\d)\\d{7}|[2-47]\\d{6}|[34]\\d{5}",[6,7,8,10],[["(\\d{2})(\\d{4,6})","$1 $2",["2[1-4]|[34]"],"(0$1)"],["(\\d)(\\d{6,7})","$1 $2",["7"],"(0$1)"],["(\\d)(\\d{7})","$1 $2",["[56]"],"0$1"],["(\\d{3})(\\d{7})","$1 $2",["8"],"0$1"]],"0"],CV:["238","0","(?:[2-59]\\d\\d|800)\\d{4}",[7],[["(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3",["[2-589]"]]]],CW:["599","00","(?:[34]1|60|(?:7|9\\d)\\d)\\d{5}",[7,8],[["(\\d{3})(\\d{4})","$1 $2",["[3467]"]],["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["9[4-8]"]]],0,0,0,0,0,"[69]"],CX:["61","001[14-689]|14(?:1[14]|34|4[17]|[56]6|7[47]|88)0011","1(?:[0-79]\\d{8}(?:\\d{2})?|8[0-24-9]\\d{7})|[148]\\d{8}|1\\d{5,7}",[6,7,8,9,10,12],0,"0",0,"([59]\\d{7})$|0","8$1",0,0,[["8(?:51(?:0(?:01|30|59|88)|1(?:17|46|75)|2(?:22|35))|91(?:00[6-9]|1(?:[28]1|49|78)|2(?:09|63)|3(?:12|26|75)|4(?:56|97)|64\\d|7(?:0[01]|1[0-2])|958))\\d{3}",[9]],["4(?:79[01]|83[0-389]|94[0-4])\\d{5}|4(?:[0-36]\\d|4[047-9]|5[0-25-9]|7[02-8]|8[0-24-9]|9[0-37-9])\\d{6}",[9]],["180(?:0\\d{3}|2)\\d{3}",[7,10]],["190[0-26]\\d{6}",[10]],0,0,0,0,["14(?:5(?:1[0458]|[23][458])|71\\d)\\d{4}",[9]],["13(?:00\\d{6}(?:\\d{2})?|45[0-4]\\d{3})|13\\d{4}",[6,8,10,12]]],"0011"],CY:["357","00","(?:[279]\\d|[58]0)\\d{6}",[8],[["(\\d{2})(\\d{6})","$1 $2",["[257-9]"]]]],CZ:["420","00","(?:[2-578]\\d|60)\\d{7}|9\\d{8,11}",[9,10,11,12],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[2-8]|9[015-7]"]],["(\\d{2})(\\d{3})(\\d{3})(\\d{2})","$1 $2 $3 $4",["96"]],["(\\d{2})(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4",["9"]],["(\\d{3})(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4",["9"]]]],DE:["49","00","[2579]\\d{5,14}|49(?:[34]0|69|8\\d)\\d\\d?|49(?:37|49|60|7[089]|9\\d)\\d{1,3}|49(?:2[024-9]|3[2-689]|7[1-7])\\d{1,8}|(?:1|[368]\\d|4[0-8])\\d{3,13}|49(?:[015]\\d|2[13]|31|[46][1-8])\\d{1,9}",[4,5,6,7,8,9,10,11,12,13,14,15],[["(\\d{2})(\\d{3,13})","$1 $2",["3[02]|40|[68]9"],"0$1"],["(\\d{3})(\\d{3,12})","$1 $2",["2(?:0[1-389]|1[124]|2[18]|3[14])|3(?:[35-9][15]|4[015])|906|(?:2[4-9]|4[2-9]|[579][1-9]|[68][1-8])1","2(?:0[1-389]|12[0-8])|3(?:[35-9][15]|4[015])|906|2(?:[13][14]|2[18])|(?:2[4-9]|4[2-9]|[579][1-9]|[68][1-8])1"],"0$1"],["(\\d{4})(\\d{2,11})","$1 $2",["[24-6]|3(?:[3569][02-46-9]|4[2-4679]|7[2-467]|8[2-46-8])|70[2-8]|8(?:0[2-9]|[1-8])|90[7-9]|[79][1-9]","[24-6]|3(?:3(?:0[1-467]|2[127-9]|3[124578]|7[1257-9]|8[1256]|9[145])|4(?:2[135]|4[13578]|9[1346])|5(?:0[14]|2[1-3589]|6[1-4]|7[13468]|8[13568])|6(?:2[1-489]|3[124-6]|6[13]|7[12579]|8[1-356]|9[135])|7(?:2[1-7]|4[145]|6[1-5]|7[1-4])|8(?:21|3[1468]|6|7[1467]|8[136])|9(?:0[12479]|2[1358]|4[134679]|6[1-9]|7[136]|8[147]|9[1468]))|70[2-8]|8(?:0[2-9]|[1-8])|90[7-9]|[79][1-9]|3[68]4[1347]|3(?:47|60)[1356]|3(?:3[46]|46|5[49])[1246]|3[4579]3[1357]"],"0$1"],["(\\d{3})(\\d{4})","$1 $2",["138"],"0$1"],["(\\d{5})(\\d{2,10})","$1 $2",["3"],"0$1"],["(\\d{3})(\\d{5,11})","$1 $2",["181"],"0$1"],["(\\d{3})(\\d)(\\d{4,10})","$1 $2 $3",["1(?:3|80)|9"],"0$1"],["(\\d{3})(\\d{7,8})","$1 $2",["1[67]"],"0$1"],["(\\d{3})(\\d{7,12})","$1 $2",["8"],"0$1"],["(\\d{5})(\\d{6})","$1 $2",["185","1850","18500"],"0$1"],["(\\d{3})(\\d{4})(\\d{4})","$1 $2 $3",["7"],"0$1"],["(\\d{4})(\\d{7})","$1 $2",["18[68]"],"0$1"],["(\\d{4})(\\d{7})","$1 $2",["15[1279]"],"0$1"],["(\\d{5})(\\d{6})","$1 $2",["15[03568]","15(?:[0568]|31)"],"0$1"],["(\\d{3})(\\d{8})","$1 $2",["18"],"0$1"],["(\\d{3})(\\d{2})(\\d{7,8})","$1 $2 $3",["1(?:6[023]|7)"],"0$1"],["(\\d{4})(\\d{2})(\\d{7})","$1 $2 $3",["15[279]"],"0$1"],["(\\d{3})(\\d{2})(\\d{8})","$1 $2 $3",["15"],"0$1"]],"0"],DJ:["253","00","(?:2\\d|77)\\d{6}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[27]"]]]],DK:["45","00","[2-9]\\d{7}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[2-9]"]]]],DM:["1","011","(?:[58]\\d\\d|767|900)\\d{7}",[10],0,"1",0,"([2-7]\\d{6})$|1","767$1",0,"767"],DO:["1","011","(?:[58]\\d\\d|900)\\d{7}",[10],0,"1",0,0,0,0,"8001|8[024]9"],DZ:["213","00","(?:[1-4]|[5-79]\\d|80)\\d{7}",[8,9],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[1-4]"],"0$1"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["9"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[5-8]"],"0$1"]],"0"],EC:["593","00","1\\d{9,10}|(?:[2-7]|9\\d)\\d{7}",[8,9,10,11],[["(\\d)(\\d{3})(\\d{4})","$1 $2-$3",["[2-7]"],"(0$1)",0,"$1-$2-$3"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["9"],"0$1"],["(\\d{4})(\\d{3})(\\d{3,4})","$1 $2 $3",["1"]]],"0"],EE:["372","00","8\\d{9}|[4578]\\d{7}|(?:[3-8]\\d|90)\\d{5}",[7,8,10],[["(\\d{3})(\\d{4})","$1 $2",["[369]|4[3-8]|5(?:[0-2]|5[0-478]|6[45])|7[1-9]|88","[369]|4[3-8]|5(?:[02]|1(?:[0-8]|95)|5[0-478]|6(?:4[0-4]|5[1-589]))|7[1-9]|88"]],["(\\d{4})(\\d{3,4})","$1 $2",["[45]|8(?:00|[1-49])","[45]|8(?:00[1-9]|[1-49])"]],["(\\d{2})(\\d{2})(\\d{4})","$1 $2 $3",["7"]],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["8"]]]],EG:["20","00","[189]\\d{8,9}|[24-6]\\d{8}|[135]\\d{7}",[8,9,10],[["(\\d)(\\d{7,8})","$1 $2",["[23]"],"0$1"],["(\\d{2})(\\d{6,7})","$1 $2",["1[35]|[4-6]|8[2468]|9[235-7]"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[89]"],"0$1"],["(\\d{2})(\\d{8})","$1 $2",["1"],"0$1"]],"0"],EH:["212","00","[5-8]\\d{8}",[9],0,"0",0,0,0,0,"528[89]"],ER:["291","00","[178]\\d{6}",[7],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["[178]"],"0$1"]],"0"],ES:["34","00","[5-9]\\d{8}",[9],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[89]00"]],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[5-9]"]]]],ET:["251","00","(?:11|[2-579]\\d)\\d{7}",[9],[["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[1-579]"],"0$1"]],"0"],FI:["358","00|99(?:[01469]|5(?:[14]1|3[23]|5[59]|77|88|9[09]))","[1-35689]\\d{4}|7\\d{10,11}|(?:[124-7]\\d|3[0-46-9])\\d{8}|[1-9]\\d{5,8}",[5,6,7,8,9,10,11,12],[["(\\d{5})","$1",["20[2-59]"],"0$1"],["(\\d{3})(\\d{3,7})","$1 $2",["(?:[1-3]0|[68])0|70[07-9]"],"0$1"],["(\\d{2})(\\d{4,8})","$1 $2",["[14]|2[09]|50|7[135]"],"0$1"],["(\\d{2})(\\d{6,10})","$1 $2",["7"],"0$1"],["(\\d)(\\d{4,9})","$1 $2",["(?:19|[2568])[1-8]|3(?:0[1-9]|[1-9])|9"],"0$1"]],"0",0,0,0,0,"1[03-79]|[2-9]",0,"00"],FJ:["679","0(?:0|52)","45\\d{5}|(?:0800\\d|[235-9])\\d{6}",[7,11],[["(\\d{3})(\\d{4})","$1 $2",["[235-9]|45"]],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["0"]]],0,0,0,0,0,0,0,"00"],FK:["500","00","[2-7]\\d{4}",[5]],FM:["691","00","(?:[39]\\d\\d|820)\\d{4}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[389]"]]]],FO:["298","00","[2-9]\\d{5}",[6],[["(\\d{6})","$1",["[2-9]"]]],0,0,"(10(?:01|[12]0|88))"],FR:["33","00","[1-9]\\d{8}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"],"0 $1"],["(\\d)(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4 $5",["[1-79]"],"0$1"]],"0"],GA:["241","00","(?:[067]\\d|11)\\d{6}|[2-7]\\d{6}",[7,8],[["(\\d)(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[2-7]"],"0$1"],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["0"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["11|[67]"],"0$1"]],0,0,"0(11\\d{6}|60\\d{6}|61\\d{6}|6[256]\\d{6}|7[467]\\d{6})","$1"],GB:["44","00","[1-357-9]\\d{9}|[18]\\d{8}|8\\d{6}",[7,9,10],[["(\\d{3})(\\d{4})","$1 $2",["800","8001","80011","800111","8001111"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3",["845","8454","84546","845464"],"0$1"],["(\\d{3})(\\d{6})","$1 $2",["800"],"0$1"],["(\\d{5})(\\d{4,5})","$1 $2",["1(?:38|5[23]|69|76|94)","1(?:(?:38|69)7|5(?:24|39)|768|946)","1(?:3873|5(?:242|39[4-6])|(?:697|768)[347]|9467)"],"0$1"],["(\\d{4})(\\d{5,6})","$1 $2",["1(?:[2-69][02-9]|[78])"],"0$1"],["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["[25]|7(?:0|6[02-9])","[25]|7(?:0|6(?:[03-9]|2[356]))"],"0$1"],["(\\d{4})(\\d{6})","$1 $2",["7"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[1389]"],"0$1"]],"0",0,0,0,0,0,[["(?:1(?:1(?:3(?:[0-58]\\d\\d|73[0-35])|4(?:(?:[0-5]\\d|70)\\d|69[7-9])|(?:(?:5[0-26-9]|[78][0-49])\\d|6(?:[0-4]\\d|50))\\d)|(?:2(?:(?:0[024-9]|2[3-9]|3[3-79]|4[1-689]|[58][02-9]|6[0-47-9]|7[013-9]|9\\d)\\d|1(?:[0-7]\\d|8[0-3]))|(?:3(?:0\\d|1[0-8]|[25][02-9]|3[02-579]|[468][0-46-9]|7[1-35-79]|9[2-578])|4(?:0[03-9]|[137]\\d|[28][02-57-9]|4[02-69]|5[0-8]|[69][0-79])|5(?:0[1-35-9]|[16]\\d|2[024-9]|3[015689]|4[02-9]|5[03-9]|7[0-35-9]|8[0-468]|9[0-57-9])|6(?:0[034689]|1\\d|2[0-35689]|[38][013-9]|4[1-467]|5[0-69]|6[13-9]|7[0-8]|9[0-24578])|7(?:0[0246-9]|2\\d|3[0236-8]|4[03-9]|5[0-46-9]|6[013-9]|7[0-35-9]|8[024-9]|9[02-9])|8(?:0[35-9]|2[1-57-9]|3[02-578]|4[0-578]|5[124-9]|6[2-69]|7\\d|8[02-9]|9[02569])|9(?:0[02-589]|[18]\\d|2[02-689]|3[1-57-9]|4[2-9]|5[0-579]|6[2-47-9]|7[0-24578]|9[2-57]))\\d)\\d)|2(?:0[013478]|3[0189]|4[017]|8[0-46-9]|9[0-2])\\d{3})\\d{4}|1(?:2(?:0(?:46[1-4]|87[2-9])|545[1-79]|76(?:2\\d|3[1-8]|6[1-6])|9(?:7(?:2[0-4]|3[2-5])|8(?:2[2-8]|7[0-47-9]|8[3-5])))|3(?:6(?:38[2-5]|47[23])|8(?:47[04-9]|64[0157-9]))|4(?:044[1-7]|20(?:2[23]|8\\d)|6(?:0(?:30|5[2-57]|6[1-8]|7[2-8])|140)|8(?:052|87[1-3]))|5(?:2(?:4(?:3[2-79]|6\\d)|76\\d)|6(?:26[06-9]|686))|6(?:06(?:4\\d|7[4-79])|295[5-7]|35[34]\\d|47(?:24|61)|59(?:5[08]|6[67]|74)|9(?:55[0-4]|77[23]))|7(?:26(?:6[13-9]|7[0-7])|(?:442|688)\\d|50(?:2[0-3]|[3-68]2|76))|8(?:27[56]\\d|37(?:5[2-5]|8[239])|843[2-58])|9(?:0(?:0(?:6[1-8]|85)|52\\d)|3583|4(?:66[1-8]|9(?:2[01]|81))|63(?:23|3[1-4])|9561))\\d{3}",[9,10]],["7(?:457[0-57-9]|700[01]|911[028])\\d{5}|7(?:[1-3]\\d\\d|4(?:[0-46-9]\\d|5[0-689])|5(?:0[0-8]|[13-9]\\d|2[0-35-9])|7(?:0[1-9]|[1-7]\\d|8[02-9]|9[0-689])|8(?:[014-9]\\d|[23][0-8])|9(?:[024-9]\\d|1[02-9]|3[0-689]))\\d{6}",[10]],["80[08]\\d{7}|800\\d{6}|8001111"],["(?:8(?:4[2-5]|7[0-3])|9(?:[01]\\d|8[2-49]))\\d{7}|845464\\d",[7,10]],["70\\d{8}",[10]],0,["(?:3[0347]|55)\\d{8}",[10]],["76(?:464|652)\\d{5}|76(?:0[0-28]|2[356]|34|4[01347]|5[49]|6[0-369]|77|8[14]|9[139])\\d{6}",[10]],["56\\d{8}",[10]]],0," x"],GD:["1","011","(?:473|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2-9]\\d{6})$|1","473$1",0,"473"],GE:["995","00","(?:[3-57]\\d\\d|800)\\d{6}",[9],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["70"],"0$1"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["32"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[57]"]],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[348]"],"0$1"]],"0"],GF:["594","00","(?:[56]94\\d|7093)\\d{5}|(?:80|9\\d)\\d{7}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[5-7]|9[47]"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[89]"],"0$1"]],"0"],GG:["44","00","(?:1481|[357-9]\\d{3})\\d{6}|8\\d{6}(?:\\d{2})?",[7,9,10],0,"0",0,"([25-9]\\d{5})$|0","1481$1",0,0,[["1481[25-9]\\d{5}",[10]],["7(?:(?:781|839)\\d|911[17])\\d{5}",[10]],["80[08]\\d{7}|800\\d{6}|8001111"],["(?:8(?:4[2-5]|7[0-3])|9(?:[01]\\d|8[0-3]))\\d{7}|845464\\d",[7,10]],["70\\d{8}",[10]],0,["(?:3[0347]|55)\\d{8}",[10]],["76(?:464|652)\\d{5}|76(?:0[0-28]|2[356]|34|4[01347]|5[49]|6[0-369]|77|8[14]|9[139])\\d{6}",[10]],["56\\d{8}",[10]]]],GH:["233","00","(?:[235]\\d{3}|800)\\d{5}",[8,9],[["(\\d{3})(\\d{5})","$1 $2",["8"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[235]"],"0$1"]],"0"],GI:["350","00","(?:[25]\\d|60)\\d{6}",[8],[["(\\d{3})(\\d{5})","$1 $2",["2"]]]],GL:["299","00","(?:19|[2-689]\\d|70)\\d{4}",[6],[["(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3",["19|[2-9]"]]]],GM:["220","00","[2-9]\\d{6}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[2-9]"]]]],GN:["224","00","722\\d{6}|(?:3|6\\d)\\d{7}",[8,9],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["3"]],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[67]"]]]],GP:["590","00","(?:590\\d|7090)\\d{5}|(?:69|80|9\\d)\\d{7}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[5-79]"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"],"0$1"]],"0",0,0,0,0,0,[["590(?:0[1-68]|[14][0-24-9]|2[0-68]|3[1-9]|5[3-579]|[68][0-689]|7[08]|9\\d)\\d{4}"],["(?:69(?:0\\d\\d|1(?:2[2-9]|3[0-5])|4(?:0[89]|1[2-6]|9\\d)|6(?:1[016-9]|5[0-4]|[67]\\d))|7090[0-4])\\d{4}"],["80[0-5]\\d{6}"],0,0,0,0,0,["9(?:(?:39[5-7]|76[018])\\d|475[0-6])\\d{4}"]]],GQ:["240","00","222\\d{6}|(?:3\\d|55|[89]0)\\d{7}",[9],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[235]"]],["(\\d{3})(\\d{6})","$1 $2",["[89]"]]]],GR:["30","00","5005000\\d{3}|8\\d{9,11}|(?:[269]\\d|70)\\d{8}",[10,11,12],[["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["21|7"]],["(\\d{4})(\\d{6})","$1 $2",["2(?:2|3[2-57-9]|4[2-469]|5[2-59]|6[2-9]|7[2-69]|8[2-49])|5"]],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[2689]"]],["(\\d{3})(\\d{3,4})(\\d{5})","$1 $2 $3",["8"]]]],GT:["502","00","80\\d{6}|(?:1\\d{3}|[2-7])\\d{7}",[8,11],[["(\\d{4})(\\d{4})","$1 $2",["[2-8]"]],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["1"]]]],GU:["1","011","(?:[58]\\d\\d|671|900)\\d{7}",[10],0,"1",0,"([2-9]\\d{6})$|1","671$1",0,"671"],GW:["245","00","[49]\\d{8}|4\\d{6}",[7,9],[["(\\d{3})(\\d{4})","$1 $2",["40"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[49]"]]]],GY:["592","001","(?:[2-8]\\d{3}|9008)\\d{3}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[2-9]"]]]],HK:["852","00(?:30|5[09]|[126-9]?)","8[0-46-9]\\d{6,7}|9\\d{4,7}|(?:[2-7]|9\\d{3})\\d{7}",[5,6,7,8,9,11],[["(\\d{3})(\\d{2,5})","$1 $2",["900","9003"]],["(\\d{4})(\\d{4})","$1 $2",["[2-7]|8[1-4]|9(?:0[1-9]|[1-8])"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["8"]],["(\\d{3})(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3 $4",["9"]]],0,0,0,0,0,0,0,"00"],HN:["504","00","8\\d{10}|[237-9]\\d{7}",[8,11],[["(\\d{4})(\\d{4})","$1-$2",["[237-9]"]]]],HR:["385","00","[2-69]\\d{8}|80\\d{5,7}|[1-79]\\d{7}|6\\d{6}",[7,8,9],[["(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3",["6[01]"],"0$1"],["(\\d{3})(\\d{2})(\\d{2,3})","$1 $2 $3",["8"],"0$1"],["(\\d)(\\d{4})(\\d{3})","$1 $2 $3",["1"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["6|7[245]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["9"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[2-57]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["8"],"0$1"]],"0"],HT:["509","00","(?:[2-489]\\d|55)\\d{6}",[8],[["(\\d{2})(\\d{2})(\\d{4})","$1 $2 $3",["[2-589]"]]]],HU:["36","00","[235-7]\\d{8}|[1-9]\\d{7}",[8,9],[["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["1"],"(06 $1)"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[27][2-9]|3[2-7]|4[24-9]|5[2-79]|6|8[2-57-9]|9[2-69]"],"(06 $1)"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[2-9]"],"06 $1"]],"06"],ID:["62","00[89]","00[1-9]\\d{9,14}|(?:[1-36]|8\\d{5})\\d{6}|00\\d{9}|[1-9]\\d{8,10}|[2-9]\\d{7}",[7,8,9,10,11,12,13,14,15,16,17],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["15"]],["(\\d{2})(\\d{5,9})","$1 $2",["2[124]|[36]1"],"(0$1)"],["(\\d{3})(\\d{5,7})","$1 $2",["800"],"0$1"],["(\\d{3})(\\d{5,8})","$1 $2",["[2-79]"],"(0$1)"],["(\\d{3})(\\d{3,4})(\\d{3})","$1-$2-$3",["8[1-35-9]"],"0$1"],["(\\d{3})(\\d{6,8})","$1 $2",["1"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["804"],"0$1"],["(\\d{3})(\\d)(\\d{3})(\\d{3})","$1 $2 $3 $4",["80"],"0$1"],["(\\d{3})(\\d{4})(\\d{4,5})","$1-$2-$3",["8"],"0$1"]],"0"],IE:["353","00","(?:1\\d|[2569])\\d{6,8}|4\\d{6,9}|7\\d{8}|8\\d{8,9}",[7,8,9,10],[["(\\d{2})(\\d{5})","$1 $2",["2[24-9]|47|58|6[237-9]|9[35-9]"],"(0$1)"],["(\\d{3})(\\d{5})","$1 $2",["[45]0"],"(0$1)"],["(\\d)(\\d{3,4})(\\d{4})","$1 $2 $3",["1"],"(0$1)"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[2569]|4[1-69]|7[14]"],"(0$1)"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["70"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["81"],"(0$1)"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[78]"],"0$1"],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["1"]],["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["4"],"(0$1)"],["(\\d{2})(\\d)(\\d{3})(\\d{4})","$1 $2 $3 $4",["8"],"0$1"]],"0"],IL:["972","0(?:0|1[2-9])","1\\d{6}(?:\\d{3,5})?|[57]\\d{8}|[1-489]\\d{7}",[7,8,9,10,11,12],[["(\\d{4})(\\d{3})","$1-$2",["125"]],["(\\d{4})(\\d{2})(\\d{2})","$1-$2-$3",["121"]],["(\\d)(\\d{3})(\\d{4})","$1-$2-$3",["[2-489]"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1-$2-$3",["[57]"],"0$1"],["(\\d{4})(\\d{3})(\\d{3})","$1-$2-$3",["12"]],["(\\d{4})(\\d{6})","$1-$2",["159"]],["(\\d)(\\d{3})(\\d{3})(\\d{3})","$1-$2-$3-$4",["1[7-9]"]],["(\\d{3})(\\d{1,2})(\\d{3})(\\d{4})","$1-$2 $3-$4",["15"]]],"0"],IM:["44","00","1624\\d{6}|(?:[3578]\\d|90)\\d{8}",[10],0,"0",0,"([25-8]\\d{5})$|0","1624$1",0,"74576|(?:16|7[56])24"],IN:["91","00","(?:000800|[2-9]\\d\\d)\\d{7}|1\\d{7,12}",[8,9,10,11,12,13],[["(\\d{8})","$1",["5(?:0|2[23]|3[03]|[67]1|88)","5(?:0|2(?:21|3)|3(?:0|3[23])|616|717|888)","5(?:0|2(?:21|3)|3(?:0|3[23])|616|717|8888)"],0,1],["(\\d{4})(\\d{4,5})","$1 $2",["180","1800"],0,1],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["140"],0,1],["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["11|2[02]|33|4[04]|79[1-7]|80[2-46]","11|2[02]|33|4[04]|79(?:[1-6]|7[19])|80(?:[2-4]|6[0-589])","11|2[02]|33|4[04]|79(?:[124-6]|3(?:[02-9]|1[0-24-9])|7(?:1|9[1-6]))|80(?:[2-4]|6[0-589])"],"0$1",1],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["1(?:2[0-249]|3[0-25]|4[145]|[68]|7[1257])|2(?:1[257]|3[013]|4[01]|5[0137]|6[0158]|78|8[1568])|3(?:26|4[1-3]|5[34]|6[01489]|7[02-46]|8[159])|4(?:1[36]|2[1-47]|5[12]|6[0-26-9]|7[0-24-9]|8[013-57]|9[014-7])|5(?:1[025]|22|[36][25]|4[28]|5[12]|[78]1)|6(?:12|[2-4]1|5[17]|6[13]|80)|7(?:12|3[134]|4[47]|61|88)|8(?:16|2[014]|3[126]|6[136]|7[078]|8[34]|91)|(?:43|59|75)[15]|(?:1[59]|29|67|72)[14]","1(?:2[0-24]|3[0-25]|4[145]|[59][14]|6[1-9]|7[1257]|8[1-57-9])|2(?:1[257]|3[013]|4[01]|5[0137]|6[058]|78|8[1568]|9[14])|3(?:26|4[1-3]|5[34]|6[01489]|7[02-46]|8[159])|4(?:1[36]|2[1-47]|3[15]|5[12]|6[0-26-9]|7[0-24-9]|8[013-57]|9[014-7])|5(?:1[025]|22|[36][25]|4[28]|[578]1|9[15])|674|7(?:(?:2[14]|3[34]|5[15])[2-6]|61[346]|88[0-8])|8(?:70[2-6]|84[235-7]|91[3-7])|(?:1(?:29|60|8[06])|261|552|6(?:12|[2-47]1|5[17]|6[13]|80)|7(?:12|31|4[47])|8(?:16|2[014]|3[126]|6[136]|7[78]|83))[2-7]","1(?:2[0-24]|3[0-25]|4[145]|[59][14]|6[1-9]|7[1257]|8[1-57-9])|2(?:1[257]|3[013]|4[01]|5[0137]|6[058]|78|8[1568]|9[14])|3(?:26|4[1-3]|5[34]|6[01489]|7[02-46]|8[159])|4(?:1[36]|2[1-47]|3[15]|5[12]|6[0-26-9]|7[0-24-9]|8[013-57]|9[014-7])|5(?:1[025]|22|[36][25]|4[28]|[578]1|9[15])|6(?:12(?:[2-6]|7[0-8])|74[2-7])|7(?:(?:2[14]|5[15])[2-6]|3171|61[346]|88(?:[2-7]|82))|8(?:70[2-6]|84(?:[2356]|7[19])|91(?:[3-6]|7[19]))|73[134][2-6]|(?:74[47]|8(?:16|2[014]|3[126]|6[136]|7[78]|83))(?:[2-6]|7[19])|(?:1(?:29|60|8[06])|261|552|6(?:[2-4]1|5[17]|6[13]|7(?:1|4[0189])|80)|7(?:12|88[01]))[2-7]"],"0$1",1],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["1(?:[2-479]|5[0235-9])|[2-5]|6(?:1[1358]|2[2457-9]|3[2-5]|4[235-7]|5[2-689]|6[24578]|7[235689]|8[1-6])|7(?:1[013-9]|28|3[129]|4[1-35689]|5[29]|6[02-5]|70)|807","1(?:[2-479]|5[0235-9])|[2-5]|6(?:1[1358]|2(?:[2457]|84|95)|3(?:[2-4]|55)|4[235-7]|5[2-689]|6[24578]|7[235689]|8[1-6])|7(?:1(?:[013-8]|9[6-9])|28[6-8]|3(?:17|2[0-49]|9[2-57])|4(?:1[2-4]|[29][0-7]|3[0-8]|[56]|8[0-24-7])|5(?:2[1-3]|9[0-6])|6(?:0[5689]|2[5-9]|3[02-8]|4|5[0-367])|70[13-7])|807[19]","1(?:[2-479]|5(?:[0236-9]|5[013-9]))|[2-5]|6(?:2(?:84|95)|355|83)|73179|807(?:1|9[1-3])|(?:1552|6(?:1[1358]|2[2457]|3[2-4]|4[235-7]|5[2-689]|6[24578]|7[235689]|8[124-6])\\d|7(?:1(?:[013-8]\\d|9[6-9])|28[6-8]|3(?:2[0-49]|9[2-57])|4(?:1[2-4]|[29][0-7]|3[0-8]|[56]\\d|8[0-24-7])|5(?:2[1-3]|9[0-6])|6(?:0[5689]|2[5-9]|3[02-8]|4\\d|5[0-367])|70[13-7]))[2-7]"],"0$1",1],["(\\d{5})(\\d{5})","$1 $2",["[6-9]"],"0$1",1],["(\\d{4})(\\d{2,4})(\\d{4})","$1 $2 $3",["1(?:6|8[06])","1(?:6|8[06]0)"],0,1],["(\\d{4})(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4",["18"],0,1]],"0"],IO:["246","00","3\\d{6}",[7],[["(\\d{3})(\\d{4})","$1 $2",["3"]]]],IQ:["964","00","(?:1|7\\d\\d)\\d{7}|[2-6]\\d{7,8}",[8,9,10],[["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["1"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[2-6]"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["7"],"0$1"]],"0"],IR:["98","00","[1-9]\\d{9}|(?:[1-8]\\d\\d|9)\\d{3,4}",[4,5,6,7,10],[["(\\d{4,5})","$1",["96"],"0$1"],["(\\d{2})(\\d{4,5})","$1 $2",["(?:1[137]|2[13-68]|3[1458]|4[145]|5[1468]|6[16]|7[1467]|8[13467])[12689]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["9"],"0$1"],["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["[1-8]"],"0$1"]],"0"],IS:["354","00|1(?:0(?:01|[12]0)|100)","(?:38\\d|[4-9])\\d{6}",[7,9],[["(\\d{3})(\\d{4})","$1 $2",["[4-9]"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["3"]]],0,0,0,0,0,0,0,"00"],IT:["39","00","0\\d{5,10}|1\\d{8,10}|3(?:[0-8]\\d{7,10}|9\\d{7,8})|(?:43|55|70)\\d{8}|8\\d{5}(?:\\d{2,4})?",[6,7,8,9,10,11,12],[["(\\d{2})(\\d{4,6})","$1 $2",["0[26]"]],["(\\d{3})(\\d{3,6})","$1 $2",["0[13-57-9][0159]|8(?:03|4[17]|9[2-5])","0[13-57-9][0159]|8(?:03|4[17]|9(?:2|3[04]|[45][0-4]))"]],["(\\d{4})(\\d{2,6})","$1 $2",["0(?:[13-579][2-46-8]|8[236-8])"]],["(\\d{4})(\\d{4})","$1 $2",["894"]],["(\\d{2})(\\d{3,4})(\\d{4})","$1 $2 $3",["0[26]|5"]],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["1(?:44|[679])|[378]|43"]],["(\\d{3})(\\d{3,4})(\\d{4})","$1 $2 $3",["0[13-57-9][0159]|14"]],["(\\d{2})(\\d{4})(\\d{5})","$1 $2 $3",["0[26]"]],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["0"]],["(\\d{3})(\\d{4})(\\d{4,5})","$1 $2 $3",["3"]]],0,0,0,0,0,0,[["0669[0-79]\\d{1,6}|0(?:1(?:[0159]\\d|[27][1-5]|31|4[1-4]|6[1356]|8[2-57])|2\\d\\d|3(?:[0159]\\d|2[1-4]|3[12]|[48][1-6]|6[2-59]|7[1-7])|4(?:[0159]\\d|[23][1-9]|4[245]|6[1-5]|7[1-4]|81)|5(?:[0159]\\d|2[1-5]|3[2-6]|4[1-79]|6[4-6]|7[1-578]|8[3-8])|6(?:[0-57-9]\\d|6[0-8])|7(?:[0159]\\d|2[12]|3[1-7]|4[2-46]|6[13569]|7[13-6]|8[1-59])|8(?:[0159]\\d|2[3-578]|3[1-356]|[6-8][1-5])|9(?:[0159]\\d|[238][1-5]|4[12]|6[1-8]|7[1-6]))\\d{2,7}",[6,7,8,9,10,11]],["3[2-9]\\d{7,8}|(?:31|43)\\d{8}",[9,10]],["80(?:0\\d{3}|3)\\d{3}",[6,9]],["(?:0878\\d{3}|89(?:2\\d|3[04]|4(?:[0-4]|[5-9]\\d\\d)|5[0-4]))\\d\\d|(?:1(?:44|6[346])|89(?:38|5[5-9]|9))\\d{6}",[6,8,9,10]],["1(?:78\\d|99)\\d{6}",[9,10]],["3[2-8]\\d{9,10}",[11,12]],0,0,["55\\d{8}",[10]],["84(?:[08]\\d{3}|[17])\\d{3}",[6,9]]]],JE:["44","00","1534\\d{6}|(?:[3578]\\d|90)\\d{8}",[10],0,"0",0,"([0-24-8]\\d{5})$|0","1534$1",0,0,[["1534[0-24-8]\\d{5}"],["7(?:(?:(?:50|82)9|937)\\d|7(?:00[378]|97\\d))\\d{5}"],["80(?:07(?:35|81)|8901)\\d{4}"],["(?:8(?:4(?:4(?:4(?:05|42|69)|703)|5(?:041|800))|7(?:0002|1206))|90(?:066[59]|1810|71(?:07|55)))\\d{4}"],["701511\\d{4}"],0,["(?:3(?:0(?:07(?:35|81)|8901)|3\\d{4}|4(?:4(?:4(?:05|42|69)|703)|5(?:041|800))|7(?:0002|1206))|55\\d{4})\\d{4}"],["76(?:464|652)\\d{5}|76(?:0[0-28]|2[356]|34|4[01347]|5[49]|6[0-369]|77|8[14]|9[139])\\d{6}"],["56\\d{8}"]]],JM:["1","011","(?:[58]\\d\\d|658|900)\\d{7}",[10],0,"1",0,0,0,0,"658|876"],JO:["962","00","(?:(?:[2689]|7\\d)\\d|32|53)\\d{6}",[8,9],[["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["[2356]|87"],"(0$1)"],["(\\d{3})(\\d{5,6})","$1 $2",["[89]"],"0$1"],["(\\d{2})(\\d{7})","$1 $2",["70"],"0$1"],["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["7"],"0$1"]],"0"],JP:["81","010","00[1-9]\\d{6,14}|[257-9]\\d{9}|(?:00|[1-9]\\d\\d)\\d{6}",[8,9,10,11,12,13,14,15,16,17],[["(\\d{3})(\\d{3})(\\d{3})","$1-$2-$3",["(?:12|57|99)0"],"0$1"],["(\\d{4})(\\d)(\\d{4})","$1-$2-$3",["1(?:26|3[79]|4[56]|5[4-68]|6[3-5])|499|5(?:76|97)|746|8(?:3[89]|47|51)|9(?:80|9[16])","1(?:267|3(?:7[247]|9[278])|466|5(?:47|58|64)|6(?:3[245]|48|5[4-68]))|499[2468]|5(?:76|97)9|7468|8(?:3(?:8[7-9]|96)|477|51[2-9])|9(?:802|9(?:1[23]|69))|1(?:45|58)[67]","1(?:267|3(?:7[247]|9[278])|466|5(?:47|58|64)|6(?:3[245]|48|5[4-68]))|499[2468]|5(?:769|979[2-69])|7468|8(?:3(?:8[7-9]|96[2457-9])|477|51[2-9])|9(?:802|9(?:1[23]|69))|1(?:45|58)[67]"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1-$2-$3",["60"],"0$1"],["(\\d)(\\d{4})(\\d{4})","$1-$2-$3",["[36]|4(?:2[09]|7[01])","[36]|4(?:2(?:0|9[02-69])|7(?:0[019]|1))"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1-$2-$3",["1(?:1|5[45]|77|88|9[69])|2(?:2[1-37]|3[0-269]|4[59]|5|6[24]|7[1-358]|8[1369]|9[0-38])|4(?:[28][1-9]|3[0-57]|[45]|6[248]|7[2-579]|9[29])|5(?:2|3[0459]|4[0-369]|5[29]|8[02389]|9[0-389])|7(?:2[02-46-9]|34|[58]|6[0249]|7[57]|9[2-6])|8(?:2[124589]|3[26-9]|49|51|6|7[0-468]|8[68]|9[019])|9(?:[23][1-9]|4[15]|5[138]|6[1-3]|7[156]|8[189]|9[1-489])","1(?:1|5(?:4[018]|5[017])|77|88|9[69])|2(?:2(?:[127]|3[014-9])|3[0-269]|4[59]|5(?:[1-3]|5[0-69]|9[19])|62|7(?:[1-35]|8[0189])|8(?:[16]|3[0134]|9[0-5])|9(?:[028]|17))|4(?:2(?:[13-79]|8[014-6])|3[0-57]|[45]|6[248]|7[2-47]|8[1-9]|9[29])|5(?:2|3(?:[045]|9[0-8])|4[0-369]|5[29]|8[02389]|9[0-3])|7(?:2[02-46-9]|34|[58]|6[0249]|7[57]|9(?:[23]|4[0-59]|5[01569]|6[0167]))|8(?:2(?:[1258]|4[0-39]|9[0-2469])|3(?:[29]|60)|49|51|6(?:[0-24]|36|5[0-3589]|7[23]|9[01459])|7[0-468]|8[68])|9(?:[23][1-9]|4[15]|5[138]|6[1-3]|7[156]|8[189]|9(?:[1289]|3[34]|4[0178]))|(?:264|837)[016-9]|2(?:57|93)[015-9]|(?:25[0468]|422|838)[01]|(?:47[59]|59[89]|8(?:6[68]|9))[019]","1(?:1|5(?:4[018]|5[017])|77|88|9[69])|2(?:2[127]|3[0-269]|4[59]|5(?:[1-3]|5[0-69]|9(?:17|99))|6(?:2|4[016-9])|7(?:[1-35]|8[0189])|8(?:[16]|3[0134]|9[0-5])|9(?:[028]|17))|4(?:2(?:[13-79]|8[014-6])|3[0-57]|[45]|6[248]|7[2-47]|9[29])|5(?:2|3(?:[045]|9(?:[0-58]|6[4-9]|7[0-35689]))|4[0-369]|5[29]|8[02389]|9[0-3])|7(?:2[02-46-9]|34|[58]|6[0249]|7[57]|9(?:[23]|4[0-59]|5[01569]|6[0167]))|8(?:2(?:[1258]|4[0-39]|9[0169])|3(?:[29]|60|7(?:[017-9]|6[6-8]))|49|51|6(?:[0-24]|36[2-57-9]|5(?:[0-389]|5[23])|6(?:[01]|9[178])|7(?:2[2-468]|3[78])|9[0145])|7[0-468]|8[68])|9(?:4[15]|5[138]|7[156]|8[189]|9(?:[1289]|3(?:31|4[357])|4[0178]))|(?:8294|96)[1-3]|2(?:57|93)[015-9]|(?:223|8699)[014-9]|(?:25[0468]|422|838)[01]|(?:48|8292|9[23])[1-9]|(?:47[59]|59[89]|8(?:68|9))[019]"],"0$1"],["(\\d{3})(\\d{2})(\\d{4})","$1-$2-$3",["[14]|[289][2-9]|5[3-9]|7[2-4679]"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1-$2-$3",["800"],"0$1"],["(\\d{2})(\\d{4})(\\d{4})","$1-$2-$3",["[257-9]"],"0$1"]],"0",0,"(000[259]\\d{6})$|(?:(?:003768)0?)|0","$1"],KE:["254","000","(?:[17]\\d\\d|900)\\d{6}|(?:2|80)0\\d{6,7}|[4-6]\\d{6,8}",[7,8,9,10],[["(\\d{2})(\\d{5,7})","$1 $2",["[24-6]"],"0$1"],["(\\d{3})(\\d{6})","$1 $2",["[17]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["[89]"],"0$1"]],"0"],KG:["996","00","8\\d{9}|[235-9]\\d{8}",[9,10],[["(\\d{4})(\\d{5})","$1 $2",["3(?:1[346]|[24-79])"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[235-79]|88"],"0$1"],["(\\d{3})(\\d{3})(\\d)(\\d{2,3})","$1 $2 $3 $4",["8"],"0$1"]],"0"],KH:["855","00[14-9]","1\\d{9}|[1-9]\\d{7,8}",[8,9,10],[["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[1-9]"],"0$1"],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["1"]]],"0"],KI:["686","00","(?:[37]\\d|6[0-79])\\d{6}|(?:[2-48]\\d|50)\\d{3}",[5,8],0,"0"],KM:["269","00","[3478]\\d{6}",[7],[["(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3",["[3478]"]]]],KN:["1","011","(?:[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2-7]\\d{6})$|1","869$1",0,"869"],KP:["850","00|99","85\\d{6}|(?:19\\d|[2-7])\\d{7}",[8,10],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["8"],"0$1"],["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["[2-7]"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["1"],"0$1"]],"0"],KR:["82","00(?:[125689]|3(?:[46]5|91)|7(?:00|27|3|55|6[126]))","00[1-9]\\d{8,11}|(?:[12]|5\\d{3})\\d{7}|[13-6]\\d{9}|(?:[1-6]\\d|80)\\d{7}|[3-6]\\d{4,5}|(?:00|7)0\\d{8}",[5,6,8,9,10,11,12,13,14],[["(\\d{2})(\\d{3,4})","$1-$2",["(?:3[1-3]|[46][1-4]|5[1-5])1"],"0$1"],["(\\d{4})(\\d{4})","$1-$2",["1"]],["(\\d)(\\d{3,4})(\\d{4})","$1-$2-$3",["2"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1-$2-$3",["[36]0|8"],"0$1"],["(\\d{2})(\\d{3,4})(\\d{4})","$1-$2-$3",["[1346]|5[1-5]"],"0$1"],["(\\d{2})(\\d{4})(\\d{4})","$1-$2-$3",["[57]"],"0$1"],["(\\d{2})(\\d{5})(\\d{4})","$1-$2-$3",["5"],"0$1"]],"0",0,"0(8(?:[1-46-8]|5\\d\\d))?"],KW:["965","00","18\\d{5}|(?:[2569]\\d|41)\\d{6}",[7,8],[["(\\d{4})(\\d{3,4})","$1 $2",["[169]|2(?:[235]|4[1-35-9])|52"]],["(\\d{3})(\\d{5})","$1 $2",["[245]"]]]],KY:["1","011","(?:345|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2-9]\\d{6})$|1","345$1",0,"345"],KZ:["7","810","(?:33622|8\\d{8})\\d{5}|[78]\\d{9}",[10,14],0,"8",0,0,0,0,"33|7",0,"8~10"],LA:["856","00","[23]\\d{9}|3\\d{8}|(?:[235-8]\\d|41)\\d{6}",[8,9,10],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["2[13]|3[14]|[4-8]"],"0$1"],["(\\d{2})(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3 $4",["3"],"0$1"],["(\\d{2})(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3 $4",["[23]"],"0$1"]],"0"],LB:["961","00","[27-9]\\d{7}|[13-9]\\d{6}",[7,8],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["[13-69]|7(?:[2-57]|62|8[0-7]|9[04-9])|8[02-9]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[27-9]"]]],"0"],LC:["1","011","(?:[58]\\d\\d|758|900)\\d{7}",[10],0,"1",0,"([2-8]\\d{6})$|1","758$1",0,"758"],LI:["423","00","[68]\\d{8}|(?:[2378]\\d|90)\\d{5}",[7,9],[["(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3",["[2379]|8(?:0[09]|7)","[2379]|8(?:0(?:02|9)|7)"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["8"]],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["69"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["6"]]],"0",0,"(1001)|0"],LK:["94","00","[1-9]\\d{8}",[9],[["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["7"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[1-689]"],"0$1"]],"0"],LR:["231","00","(?:[245]\\d|33|77|88)\\d{7}|(?:2\\d|[4-6])\\d{6}",[7,8,9],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["4[67]|[56]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["2"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[2-578]"],"0$1"]],"0"],LS:["266","00","(?:[256]\\d\\d|800)\\d{5}",[8],[["(\\d{4})(\\d{4})","$1 $2",["[2568]"]]]],LT:["370","00","(?:[3469]\\d|52|[78]0)\\d{6}",[8],[["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["52[0-7]"],"(0-$1)",1],["(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3",["[7-9]"],"0 $1",1],["(\\d{2})(\\d{6})","$1 $2",["37|4(?:[15]|6[1-8])"],"(0-$1)",1],["(\\d{3})(\\d{5})","$1 $2",["[3-6]"],"(0-$1)",1]],"0",0,"[08]"],LU:["352","00","35[013-9]\\d{4,8}|6\\d{8}|35\\d{2,4}|(?:[2457-9]\\d|3[0-46-9])\\d{2,9}",[4,5,6,7,8,9,10,11],[["(\\d{2})(\\d{3})","$1 $2",["2(?:0[2-689]|[2-9])|[3-57]|8(?:0[2-9]|[13-9])|9(?:0[89]|[2-579])"]],["(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3",["2(?:0[2-689]|[2-9])|[3-57]|8(?:0[2-9]|[13-9])|9(?:0[89]|[2-579])"]],["(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3",["20[2-689]"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{1,2})","$1 $2 $3 $4",["2(?:[0367]|4[3-8])"]],["(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3",["80[01]|90[015]"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3 $4",["20"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["6"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{1,2})","$1 $2 $3 $4 $5",["2(?:[0367]|4[3-8])"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{1,5})","$1 $2 $3 $4",["[3-57]|8[13-9]|9(?:0[89]|[2-579])|(?:2|80)[2-9]"]]],0,0,"(15(?:0[06]|1[12]|[35]5|4[04]|6[26]|77|88|99)\\d)"],LV:["371","00","(?:[268]\\d|90)\\d{6}",[8],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[269]|8[01]"]]]],LY:["218","00","[2-9]\\d{8}",[9],[["(\\d{2})(\\d{7})","$1-$2",["[2-9]"],"0$1"]],"0"],MA:["212","00","[5-8]\\d{8}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["5[45]"],"0$1"],["(\\d{4})(\\d{5})","$1-$2",["5(?:2[2-46-9]|3[3-9]|9)|8(?:0[89]|92)"],"0$1"],["(\\d{2})(\\d{7})","$1-$2",["8"],"0$1"],["(\\d{3})(\\d{6})","$1-$2",["[5-7]"],"0$1"]],"0",0,0,0,0,0,[["5(?:2(?:[0-25-79]\\d|3[1-578]|4[02-46-8]|8[0235-7])|3(?:[0-47]\\d|5[02-9]|6[02-8]|8[014-9]|9[3-9])|(?:4[067]|5[03])\\d)\\d{5}"],["(?:6(?:[0-79]\\d|8[0-247-9])|7(?:[0167]\\d|2[0-467]|5[0-3]|8[0-7]))\\d{6}"],["80[0-7]\\d{6}"],["89\\d{7}"],0,0,0,0,["(?:592(?:4[0-2]|93)|80[89]\\d\\d)\\d{4}"]]],MC:["377","00","(?:[3489]|6\\d)\\d{7}",[8,9],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["4"],"0$1"],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[389]"]],["(\\d)(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4 $5",["6"],"0$1"]],"0"],MD:["373","00","(?:[235-7]\\d|[89]0)\\d{6}",[8],[["(\\d{3})(\\d{5})","$1 $2",["[89]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["22|3"],"0$1"],["(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3",["[25-7]"],"0$1"]],"0"],ME:["382","00","(?:20|[3-79]\\d)\\d{6}|80\\d{6,7}",[8,9],[["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[2-9]"],"0$1"]],"0"],MF:["590","00","(?:590\\d|7090)\\d{5}|(?:69|80|9\\d)\\d{7}",[9],0,"0",0,0,0,0,0,[["590(?:0[079]|[14]3|[27][79]|3[03-7]|5[0-268]|87)\\d{4}"],["(?:69(?:0\\d\\d|1(?:2[2-9]|3[0-5])|4(?:0[89]|1[2-6]|9\\d)|6(?:1[016-9]|5[0-4]|[67]\\d))|7090[0-4])\\d{4}"],["80[0-5]\\d{6}"],0,0,0,0,0,["9(?:(?:39[5-7]|76[018])\\d|475[0-6])\\d{4}"]]],MG:["261","00","[23]\\d{8}",[9],[["(\\d{2})(\\d{2})(\\d{3})(\\d{2})","$1 $2 $3 $4",["[23]"],"0$1"]],"0",0,"([24-9]\\d{6})$|0","20$1"],MH:["692","011","329\\d{4}|(?:[256]\\d|45)\\d{5}",[7],[["(\\d{3})(\\d{4})","$1-$2",["[2-6]"]]],"1"],MK:["389","00","[2-578]\\d{7}",[8],[["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["2|34[47]|4(?:[37]7|5[47]|64)"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[347]"],"0$1"],["(\\d{3})(\\d)(\\d{2})(\\d{2})","$1 $2 $3 $4",["[58]"],"0$1"]],"0"],ML:["223","00","[24-9]\\d{7}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[24-9]"]]]],MM:["95","00","1\\d{5,7}|95\\d{6}|(?:[4-7]|9[0-46-9])\\d{6,8}|(?:2|8\\d)\\d{5,8}",[6,7,8,9,10],[["(\\d)(\\d{2})(\\d{3})","$1 $2 $3",["16|2"],"0$1"],["(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3",["4(?:[2-46]|5[3-5])|5|6(?:[1-689]|7[235-7])|7(?:[0-4]|5[2-7])|8[1-5]|(?:60|86)[23]"],"0$1"],["(\\d)(\\d{3})(\\d{3,4})","$1 $2 $3",["[12]|452|678|86","[12]|452|6788|86"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[4-7]|8[1-35]"],"0$1"],["(\\d)(\\d{3})(\\d{4,6})","$1 $2 $3",["9(?:2[0-4]|[35-9]|4[137-9])"],"0$1"],["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["2"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["8"],"0$1"],["(\\d)(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4",["92"],"0$1"],["(\\d)(\\d{5})(\\d{4})","$1 $2 $3",["9"],"0$1"]],"0"],MN:["976","001","[12]\\d{7,9}|[5-9]\\d{7}",[8,9,10],[["(\\d{2})(\\d{2})(\\d{4})","$1 $2 $3",["[12]1"],"0$1"],["(\\d{4})(\\d{4})","$1 $2",["[5-9]"]],["(\\d{3})(\\d{5,6})","$1 $2",["[12]2[1-3]"],"0$1"],["(\\d{4})(\\d{5,6})","$1 $2",["[12](?:27|3[2-8]|4[2-68]|5[1-4689])","[12](?:27|3[2-8]|4[2-68]|5[1-4689])[0-3]"],"0$1"],["(\\d{5})(\\d{4,5})","$1 $2",["[12]"],"0$1"]],"0"],MO:["853","00","0800\\d{3}|(?:28|[68]\\d)\\d{6}",[7,8],[["(\\d{4})(\\d{3})","$1 $2",["0"]],["(\\d{4})(\\d{4})","$1 $2",["[268]"]]]],MP:["1","011","[58]\\d{9}|(?:67|90)0\\d{7}",[10],0,"1",0,"([2-9]\\d{6})$|1","670$1",0,"670"],MQ:["596","00","(?:596\\d|7091)\\d{5}|(?:69|[89]\\d)\\d{7}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[5-79]|8(?:0[6-9]|[36])"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"],"0$1"]],"0"],MR:["222","00","(?:[2-4]\\d\\d|800)\\d{5}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[2-48]"]]]],MS:["1","011","(?:[58]\\d\\d|664|900)\\d{7}",[10],0,"1",0,"([34]\\d{6})$|1","664$1",0,"664"],MT:["356","00","3550\\d{4}|(?:[2579]\\d\\d|800)\\d{5}",[8],[["(\\d{4})(\\d{4})","$1 $2",["[2357-9]"]]]],MU:["230","0(?:0|[24-7]0|3[03])","(?:[57]|8\\d\\d)\\d{7}|[2-468]\\d{6}",[7,8,10],[["(\\d{3})(\\d{4})","$1 $2",["[2-46]|8[013]"]],["(\\d{4})(\\d{4})","$1 $2",["[57]"]],["(\\d{5})(\\d{5})","$1 $2",["8"]]],0,0,0,0,0,0,0,"020"],MV:["960","0(?:0|19)","(?:800|9[0-57-9]\\d)\\d{7}|[34679]\\d{6}",[7,10],[["(\\d{3})(\\d{4})","$1-$2",["[34679]"]],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[89]"]]],0,0,0,0,0,0,0,"00"],MW:["265","00","(?:[1289]\\d|31|77)\\d{7}|1\\d{6}",[7,9],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["1[2-9]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["2"],"0$1"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[137-9]"],"0$1"]],"0"],MX:["52","0[09]","[2-9]\\d{9}",[10],[["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["33|5[56]|81"]],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[2-9]"]]],0,0,0,0,0,0,0,"00"],MY:["60","00","1\\d{8,9}|(?:3\\d|[4-9])\\d{7}",[8,9,10],[["(\\d)(\\d{3})(\\d{4})","$1-$2 $3",["[4-79]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1-$2 $3",["1(?:[02469]|[378][1-9]|53)|8","1(?:[02469]|[37][1-9]|53|8(?:[1-46-9]|5[7-9]))|8"],"0$1"],["(\\d)(\\d{4})(\\d{4})","$1-$2 $3",["3"],"0$1"],["(\\d)(\\d{3})(\\d{2})(\\d{4})","$1-$2-$3-$4",["1(?:[367]|80)"]],["(\\d{3})(\\d{3})(\\d{4})","$1-$2 $3",["15"],"0$1"],["(\\d{2})(\\d{4})(\\d{4})","$1-$2 $3",["1"],"0$1"]],"0"],MZ:["258","00","(?:2|8\\d)\\d{7}",[8,9],[["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["2|8[2-79]"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["8"]]]],NA:["264","00","[68]\\d{7,8}",[8,9],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["88"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["6"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["87"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["8"],"0$1"]],"0"],NC:["687","00","(?:050|[2-57-9]\\d\\d)\\d{3}",[6],[["(\\d{2})(\\d{2})(\\d{2})","$1.$2.$3",["[02-57-9]"]]]],NE:["227","00","[027-9]\\d{7}",[8],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["08"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[089]|2[013]|7[0467]"]]]],NF:["672","00","[13]\\d{5}",[6],[["(\\d{2})(\\d{4})","$1 $2",["1[0-3]"]],["(\\d)(\\d{5})","$1 $2",["[13]"]]],0,0,"([0-258]\\d{4})$","3$1"],NG:["234","009","(?:20|9\\d)\\d{8}|[78]\\d{9,13}",[10,11,12,13,14],[["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["[7-9]"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["20[129]"],"0$1"],["(\\d{4})(\\d{2})(\\d{4})","$1 $2 $3",["2"],"0$1"],["(\\d{3})(\\d{4})(\\d{4,5})","$1 $2 $3",["[78]"],"0$1"],["(\\d{3})(\\d{5})(\\d{5,6})","$1 $2 $3",["[78]"],"0$1"]],"0"],NI:["505","00","(?:1800|[25-8]\\d{3})\\d{4}",[8],[["(\\d{4})(\\d{4})","$1 $2",["[125-8]"]]]],NL:["31","00","(?:[124-7]\\d\\d|3(?:[02-9]\\d|1[0-8]))\\d{6}|8\\d{6,9}|9\\d{6,10}|1\\d{4,5}",[5,6,7,8,9,10,11],[["(\\d{3})(\\d{4,7})","$1 $2",["[89]0"],"0$1"],["(\\d{2})(\\d{7})","$1 $2",["66"],"0$1"],["(\\d)(\\d{8})","$1 $2",["6"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["1[16-8]|2[259]|3[124]|4[17-9]|5[124679]"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[1-578]|91"],"0$1"],["(\\d{3})(\\d{3})(\\d{5})","$1 $2 $3",["9"],"0$1"]],"0"],NO:["47","00","(?:0|[2-9]\\d{3})\\d{4}",[5,8],[["(\\d{3})(\\d{2})(\\d{3})","$1 $2 $3",["8"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[2-79]"]]],0,0,0,0,0,"[02-689]|7[0-8]"],NP:["977","00","(?:1\\d|9)\\d{9}|[1-9]\\d{7}",[8,10,11],[["(\\d)(\\d{7})","$1-$2",["1[2-6]"],"0$1"],["(\\d{2})(\\d{6})","$1-$2",["1[01]|[2-8]|9(?:[1-59]|[67][2-6])"],"0$1"],["(\\d{3})(\\d{7})","$1-$2",["9"]]],"0"],NR:["674","00","(?:222|444|(?:55|8\\d)\\d|666|777|999)\\d{4}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[24-9]"]]]],NU:["683","00","(?:[4-7]|888\\d)\\d{3}",[4,7],[["(\\d{3})(\\d{4})","$1 $2",["8"]]]],NZ:["64","0(?:0|161)","[1289]\\d{9}|50\\d{5}(?:\\d{2,3})?|[27-9]\\d{7,8}|(?:[34]\\d|6[0-35-9])\\d{6}|8\\d{4,6}",[5,6,7,8,9,10],[["(\\d{2})(\\d{3,8})","$1 $2",["8[1-79]"],"0$1"],["(\\d{3})(\\d{2})(\\d{2,3})","$1 $2 $3",["50[036-8]|8|90","50(?:[0367]|88)|8|90"],"0$1"],["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["24|[346]|7[2-57-9]|9[2-9]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["2(?:10|74)|[589]"],"0$1"],["(\\d{2})(\\d{3,4})(\\d{4})","$1 $2 $3",["1|2[028]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,5})","$1 $2 $3",["2(?:[169]|7[0-35-9])|7"],"0$1"]],"0",0,0,0,0,0,0,"00"],OM:["968","00","(?:1505|[279]\\d{3}|500)\\d{4}|800\\d{5,6}",[7,8,9],[["(\\d{3})(\\d{4,6})","$1 $2",["[58]"]],["(\\d{2})(\\d{6})","$1 $2",["2"]],["(\\d{4})(\\d{4})","$1 $2",["[179]"]]]],PA:["507","00","(?:00800|8\\d{3})\\d{6}|[68]\\d{7}|[1-57-9]\\d{6}",[7,8,10,11],[["(\\d{3})(\\d{4})","$1-$2",["[1-57-9]"]],["(\\d{4})(\\d{4})","$1-$2",["[68]"]],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["8"]]]],PE:["51","00|19(?:1[124]|77|90)00","(?:[14-8]|9\\d)\\d{7}",[8,9],[["(\\d{3})(\\d{5})","$1 $2",["80"],"(0$1)"],["(\\d)(\\d{7})","$1 $2",["1"],"(0$1)"],["(\\d{2})(\\d{6})","$1 $2",["[4-8]"],"(0$1)"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["9"]]],"0",0,0,0,0,0,0,"00"," Anexo "],PF:["689","00","4\\d{5}(?:\\d{2})?|8\\d{7,8}",[6,8,9],[["(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3",["44"]],["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["4|8[7-9]"]],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"]]]],PG:["675","00|140[1-3]","(?:180|[78]\\d{3})\\d{4}|(?:[2-589]\\d|64)\\d{5}",[7,8],[["(\\d{3})(\\d{4})","$1 $2",["18|[2-69]|85"]],["(\\d{4})(\\d{4})","$1 $2",["[78]"]]],0,0,0,0,0,0,0,"00"],PH:["63","00","(?:[2-7]|9\\d)\\d{8}|2\\d{5}|(?:1800|8)\\d{7,9}",[6,8,9,10,11,12,13],[["(\\d)(\\d{5})","$1 $2",["2"],"(0$1)"],["(\\d{4})(\\d{4,6})","$1 $2",["3(?:23|39|46)|4(?:2[3-6]|[35]9|4[26]|76)|544|88[245]|(?:52|64|86)2","3(?:230|397|461)|4(?:2(?:35|[46]4|51)|396|4(?:22|63)|59[347]|76[15])|5(?:221|446)|642[23]|8(?:622|8(?:[24]2|5[13]))"],"(0$1)"],["(\\d{5})(\\d{4})","$1 $2",["346|4(?:27|9[35])|883","3469|4(?:279|9(?:30|56))|8834"],"(0$1)"],["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["2"],"(0$1)"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[3-7]|8[2-8]"],"(0$1)"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[89]"],"0$1"],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["1"]],["(\\d{4})(\\d{1,2})(\\d{3})(\\d{4})","$1 $2 $3 $4",["1"]]],"0"],PK:["92","00","122\\d{6}|[24-8]\\d{10,11}|9(?:[013-9]\\d{8,10}|2(?:[01]\\d\\d|2(?:[06-8]\\d|1[01]))\\d{7})|(?:[2-8]\\d{3}|92(?:[0-7]\\d|8[1-9]))\\d{6}|[24-9]\\d{8}|[89]\\d{7}",[8,9,10,11,12],[["(\\d{3})(\\d{3})(\\d{2,7})","$1 $2 $3",["[89]0"],"0$1"],["(\\d{4})(\\d{5})","$1 $2",["1"]],["(\\d{3})(\\d{6,7})","$1 $2",["2(?:3[2358]|4[2-4]|9[2-8])|45[3479]|54[2-467]|60[468]|72[236]|8(?:2[2-689]|3[23578]|4[3478]|5[2356])|9(?:2[2-8]|3[27-9]|4[2-6]|6[3569]|9[25-8])","9(?:2[3-8]|98)|(?:2(?:3[2358]|4[2-4]|9[2-8])|45[3479]|54[2-467]|60[468]|72[236]|8(?:2[2-689]|3[23578]|4[3478]|5[2356])|9(?:22|3[27-9]|4[2-6]|6[3569]|9[25-7]))[2-9]"],"(0$1)"],["(\\d{2})(\\d{7,8})","$1 $2",["(?:2[125]|4[0-246-9]|5[1-35-7]|6[1-8]|7[14]|8[16]|91)[2-9]"],"(0$1)"],["(\\d{5})(\\d{5})","$1 $2",["58"],"(0$1)"],["(\\d{3})(\\d{7})","$1 $2",["3"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4",["2[125]|4[0-246-9]|5[1-35-7]|6[1-8]|7[14]|8[16]|91"],"(0$1)"],["(\\d{3})(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4",["[24-9]"],"(0$1)"]],"0"],PL:["48","00","(?:6|8\\d\\d)\\d{7}|[1-9]\\d{6}(?:\\d{2})?|[26]\\d{5}",[6,7,8,9,10],[["(\\d{5})","$1",["19"]],["(\\d{3})(\\d{3})","$1 $2",["11|20|64"]],["(\\d{2})(\\d{2})(\\d{3})","$1 $2 $3",["(?:1[2-8]|2[2-69]|3[2-4]|4[1-468]|5[24-689]|6[1-3578]|7[14-7]|8[1-79]|9[145])1","(?:1[2-8]|2[2-69]|3[2-4]|4[1-468]|5[24-689]|6[1-3578]|7[14-7]|8[1-79]|9[145])19"]],["(\\d{3})(\\d{2})(\\d{2,3})","$1 $2 $3",["64"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["21|39|45|5[0137]|6[0469]|7[02389]|8(?:0[14]|8)"]],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["1[2-8]|[2-7]|8[1-79]|9[145]"]],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["8"]]]],PM:["508","00","[45]\\d{5}|(?:708|8\\d\\d)\\d{6}",[6,9],[["(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3",["[45]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["7"]],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"],"0$1"]],"0"],PR:["1","011","(?:[589]\\d\\d|787)\\d{7}",[10],0,"1",0,0,0,0,"787|939"],PS:["970","00","[2489]2\\d{6}|(?:1\\d|5)\\d{8}",[8,9,10],[["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["[2489]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["5"],"0$1"],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["1"]]],"0"],PT:["351","00","1693\\d{5}|(?:[26-9]\\d|30)\\d{7}",[9],[["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["2[12]"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["16|[236-9]"]]]],PW:["680","01[12]","(?:[24-8]\\d\\d|345|900)\\d{4}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[2-9]"]]]],PY:["595","00","59\\d{4,6}|9\\d{5,10}|(?:[2-46-8]\\d|5[0-8])\\d{4,7}",[6,7,8,9,10,11],[["(\\d{3})(\\d{3,6})","$1 $2",["[2-9]0"],"0$1"],["(\\d{2})(\\d{5})","$1 $2",["[26]1|3[289]|4[1246-8]|7[1-3]|8[1-36]"],"(0$1)"],["(\\d{3})(\\d{4,5})","$1 $2",["2[279]|3[13-5]|4[359]|5|6(?:[34]|7[1-46-8])|7[46-8]|85"],"(0$1)"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["2[14-68]|3[26-9]|4[1246-8]|6(?:1|75)|7[1-35]|8[1-36]"],"(0$1)"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["87"]],["(\\d{3})(\\d{6})","$1 $2",["9(?:[5-79]|8[1-7])"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[2-8]"],"0$1"],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["9"]]],"0"],QA:["974","00","800\\d{4}|(?:2|800)\\d{6}|(?:0080|[3-7])\\d{7}",[7,8,9,11],[["(\\d{3})(\\d{4})","$1 $2",["2[136]|8"]],["(\\d{4})(\\d{4})","$1 $2",["[3-7]"]]]],RE:["262","00","709\\d{6}|(?:26|[689]\\d)\\d{7}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[26-9]"],"0$1"]],"0",0,0,0,0,0,[["26(?:2\\d\\d|3(?:0\\d|1[0-6]))\\d{4}"],["(?:69(?:2\\d\\d|3(?:[06][0-6]|1[0-3]|2[0-2]|3[0-39]|4\\d|5[0-5]|7[0-37]|8[0-8]|9[0-479]))|7092[0-3])\\d{4}"],["80\\d{7}"],["89[1-37-9]\\d{6}"],0,0,0,0,["9(?:399[0-3]|479[0-6]|76(?:2[278]|3[0-37]))\\d{4}"],["8(?:1[019]|2[0156]|84|90)\\d{6}"]]],RO:["40","00","(?:[236-8]\\d|90)\\d{7}|[23]\\d{5}",[6,9],[["(\\d{3})(\\d{3})","$1 $2",["2[3-6]","2[3-6]\\d9"],"0$1"],["(\\d{2})(\\d{4})","$1 $2",["219|31"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[23]1"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[236-9]"],"0$1"]],"0",0,0,0,0,0,0,0," int "],RS:["381","00","38[02-9]\\d{6,9}|6\\d{7,9}|90\\d{4,8}|38\\d{5,6}|(?:7\\d\\d|800)\\d{3,9}|(?:[12]\\d|3[0-79])\\d{5,10}",[6,7,8,9,10,11,12],[["(\\d{3})(\\d{3,9})","$1 $2",["(?:2[389]|39)0|[7-9]"],"0$1"],["(\\d{2})(\\d{5,10})","$1 $2",["[1-36]"],"0$1"]],"0"],RU:["7","810","8\\d{13}|[347-9]\\d{9}",[10,14],[["(\\d{4})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["7(?:1[0-8]|2[1-9])","7(?:1(?:[0-356]2|4[29]|7|8[27])|2(?:1[23]|[2-9]2))","7(?:1(?:[0-356]2|4[29]|7|8[27])|2(?:13[03-69]|62[013-9]))|72[1-57-9]2"],"8 ($1)",1],["(\\d{5})(\\d)(\\d{2})(\\d{2})","$1 $2 $3 $4",["7(?:1[0-68]|2[1-9])","7(?:1(?:[06][3-6]|[18]|2[35]|[3-5][3-5])|2(?:[13][3-5]|[24-689]|7[457]))","7(?:1(?:0(?:[356]|4[023])|[18]|2(?:3[013-9]|5)|3[45]|43[013-79]|5(?:3[1-8]|4[1-7]|5)|6(?:3[0-35-9]|[4-6]))|2(?:1(?:3[178]|[45])|[24-689]|3[35]|7[457]))|7(?:14|23)4[0-8]|71(?:33|45)[1-79]"],"8 ($1)",1],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["7"],"8 ($1)",1],["(\\d{3})(\\d{3})(\\d{2})(\\d{2})","$1 $2-$3-$4",["[349]|8(?:[02-7]|1[1-8])"],"8 ($1)",1],["(\\d{4})(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3 $4",["8"],"8 ($1)"]],"8",0,0,0,0,"3[04-689]|[489]",0,"8~10"],RW:["250","00","(?:06|[27]\\d\\d|[89]00)\\d{6}",[8,9],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["0"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["2"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[7-9]"],"0$1"]],"0"],SA:["966","00","92\\d{7}|(?:[15]|8\\d)\\d{8}",[9,10],[["(\\d{4})(\\d{5})","$1 $2",["9"]],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["1"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["5"],"0$1"],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["81"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["8"]]],"0"],SB:["677","0[01]","[6-9]\\d{6}|[1-6]\\d{4}",[5,7],[["(\\d{2})(\\d{5})","$1 $2",["6[89]|7|8[4-9]|9(?:[1-8]|9[0-8])"]]]],SC:["248","010|0[0-2]","(?:[2489]\\d|64)\\d{5}",[7],[["(\\d)(\\d{3})(\\d{3})","$1 $2 $3",["[246]|9[57]"]]],0,0,0,0,0,0,0,"00"],SD:["249","00","[19]\\d{8}",[9],[["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[19]"],"0$1"]],"0"],SE:["46","00","(?:[26]\\d\\d|9)\\d{9}|[1-9]\\d{8}|[1-689]\\d{7}|[1-4689]\\d{6}|2\\d{5}",[6,7,8,9,10,12],[["(\\d{2})(\\d{2,3})(\\d{2})","$1-$2 $3",["20"],"0$1",0,"$1 $2 $3"],["(\\d{3})(\\d{4})","$1-$2",["9(?:00|39|44|9)"],"0$1",0,"$1 $2"],["(\\d{2})(\\d{3})(\\d{2})","$1-$2 $3",["[12][136]|3[356]|4[0246]|6[03]|90[1-9]"],"0$1",0,"$1 $2 $3"],["(\\d)(\\d{2,3})(\\d{2})(\\d{2})","$1-$2 $3 $4",["8"],"0$1",0,"$1 $2 $3 $4"],["(\\d{3})(\\d{2,3})(\\d{2})","$1-$2 $3",["1[2457]|2(?:[247-9]|5[0138])|3[0247-9]|4[1357-9]|5[0-35-9]|6(?:[125689]|4[02-57]|7[0-2])|9(?:[125-8]|3[02-5]|4[0-3])"],"0$1",0,"$1 $2 $3"],["(\\d{3})(\\d{2,3})(\\d{3})","$1-$2 $3",["9(?:00|39|44)"],"0$1",0,"$1 $2 $3"],["(\\d{2})(\\d{2,3})(\\d{2})(\\d{2})","$1-$2 $3 $4",["1[13689]|2[0136]|3[1356]|4[0246]|54|6[03]|90[1-9]"],"0$1",0,"$1 $2 $3 $4"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1-$2 $3 $4",["10|7"],"0$1",0,"$1 $2 $3 $4"],["(\\d)(\\d{3})(\\d{3})(\\d{2})","$1-$2 $3 $4",["8"],"0$1",0,"$1 $2 $3 $4"],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1-$2 $3 $4",["[13-5]|2(?:[247-9]|5[0138])|6(?:[124-689]|7[0-2])|9(?:[125-8]|3[02-5]|4[0-3])"],"0$1",0,"$1 $2 $3 $4"],["(\\d{3})(\\d{2})(\\d{2})(\\d{3})","$1-$2 $3 $4",["9"],"0$1",0,"$1 $2 $3 $4"],["(\\d{3})(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1-$2 $3 $4 $5",["[26]"],"0$1",0,"$1 $2 $3 $4 $5"]],"0"],SG:["65","0[0-3]\\d","(?:(?:1\\d|8)\\d\\d|7000)\\d{7}|[3689]\\d{7}",[8,10,11],[["(\\d{4})(\\d{4})","$1 $2",["[369]|8(?:0[1-9]|[1-9])"]],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["8"]],["(\\d{4})(\\d{4})(\\d{3})","$1 $2 $3",["7"]],["(\\d{4})(\\d{3})(\\d{4})","$1 $2 $3",["1"]]]],SH:["290","00","(?:[256]\\d|8)\\d{3}",[4,5],0,0,0,0,0,0,"[256]"],SI:["386","00|10(?:22|66|88|99)","[1-7]\\d{7}|8\\d{4,7}|90\\d{4,6}",[5,6,7,8],[["(\\d{2})(\\d{3,6})","$1 $2",["8[09]|9"],"0$1"],["(\\d{3})(\\d{5})","$1 $2",["59|8"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[37][01]|4[0139]|51|6"],"0$1"],["(\\d)(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[1-57]"],"(0$1)"]],"0",0,0,0,0,0,0,"00"],SJ:["47","00","0\\d{4}|(?:[489]\\d|79)\\d{6}",[5,8],0,0,0,0,0,0,"79"],SK:["421","00","[2-689]\\d{8}|[2-59]\\d{6}|[2-5]\\d{5}",[6,7,9],[["(\\d)(\\d{2})(\\d{3,4})","$1 $2 $3",["21"],"0$1"],["(\\d{2})(\\d{2})(\\d{2,3})","$1 $2 $3",["[3-5][1-8]1","[3-5][1-8]1[67]"],"0$1"],["(\\d)(\\d{3})(\\d{3})(\\d{2})","$1/$2 $3 $4",["2"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[689]"],"0$1"],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1/$2 $3 $4",["[3-5]"],"0$1"]],"0"],SL:["232","00","(?:[237-9]\\d|66)\\d{6}",[8],[["(\\d{2})(\\d{6})","$1 $2",["[236-9]"],"(0$1)"]],"0"],SM:["378","00","(?:0549|[5-7]\\d)\\d{6}",[8,10],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[5-7]"]],["(\\d{4})(\\d{6})","$1 $2",["0"]]],0,0,"([89]\\d{5})$","0549$1"],SN:["221","00","(?:[378]\\d|93)\\d{7}",[9],[["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"]],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[379]"]]]],SO:["252","00","[346-9]\\d{8}|[12679]\\d{7}|[1-5]\\d{6}|[1348]\\d{5}",[6,7,8,9],[["(\\d{2})(\\d{4})","$1 $2",["8[125]"]],["(\\d{6})","$1",["[134]"]],["(\\d)(\\d{6})","$1 $2",["[15]|2[0-79]|3[0-46-8]|4[0-7]"]],["(\\d)(\\d{7})","$1 $2",["(?:2|90)4|[67]"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[348]|64|79|90"]],["(\\d{2})(\\d{5,7})","$1 $2",["1|28|6[0-35-9]|7[67]|9[2-9]"]]],"0"],SR:["597","00","(?:[2-5]|68|[78]\\d|90)\\d{5}",[6,7],[["(\\d{2})(\\d{2})(\\d{2})","$1-$2-$3",["56"]],["(\\d{3})(\\d{3})","$1-$2",["[2-5]"]],["(\\d{3})(\\d{4})","$1-$2",["[6-9]"]]]],SS:["211","00","[19]\\d{8}",[9],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[19]"],"0$1"]],"0"],ST:["239","00","(?:22|9\\d)\\d{5}",[7],[["(\\d{3})(\\d{4})","$1 $2",["[29]"]]]],SV:["503","00","[267]\\d{7}|(?:80\\d|900)\\d{4}(?:\\d{4})?",[7,8,11],[["(\\d{3})(\\d{4})","$1 $2",["[89]"]],["(\\d{4})(\\d{4})","$1 $2",["[267]"]],["(\\d{3})(\\d{4})(\\d{4})","$1 $2 $3",["[89]"]]]],SX:["1","011","7215\\d{6}|(?:[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"(5\\d{6})$|1","721$1",0,"721"],SY:["963","00","[1-39]\\d{8}|[1-5]\\d{7}",[8,9],[["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[1-5]"],"0$1",1],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["9"],"0$1",1]],"0"],SZ:["268","00","0800\\d{4}|(?:[237]\\d|900)\\d{6}",[8,9],[["(\\d{4})(\\d{4})","$1 $2",["[0237]"]],["(\\d{5})(\\d{4})","$1 $2",["9"]]]],TA:["290","00","8\\d{3}",[4],0,0,0,0,0,0,"8"],TC:["1","011","(?:[58]\\d\\d|649|900)\\d{7}",[10],0,"1",0,"([2-479]\\d{6})$|1","649$1",0,"649"],TD:["235","00|16","(?:22|[689]\\d|77)\\d{6}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[26-9]"]]],0,0,0,0,0,0,0,"00"],TG:["228","00","[279]\\d{7}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[279]"]]]],TH:["66","00[1-9]","(?:001800|[2-57]|[689]\\d)\\d{7}|1\\d{7,9}",[8,9,10,13],[["(\\d)(\\d{3})(\\d{4})","$1 $2 $3",["2"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[13-9]"],"0$1"],["(\\d{4})(\\d{3})(\\d{3})","$1 $2 $3",["1"]]],"0"],TJ:["992","810","[0-57-9]\\d{8}",[9],[["(\\d{6})(\\d)(\\d{2})","$1 $2 $3",["331","3317"]],["(\\d{3})(\\d{2})(\\d{4})","$1 $2 $3",["44[02-479]|[34]7"]],["(\\d{4})(\\d)(\\d{4})","$1 $2 $3",["3(?:[1245]|3[12])"]],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[0-57-9]"]]],0,0,0,0,0,0,0,"8~10"],TK:["690","00","[2-47]\\d{3,6}",[4,5,6,7]],TL:["670","00","7\\d{7}|(?:[2-47]\\d|[89]0)\\d{5}",[7,8],[["(\\d{3})(\\d{4})","$1 $2",["[2-489]|70"]],["(\\d{4})(\\d{4})","$1 $2",["7"]]]],TM:["993","810","(?:[1-6]\\d|71)\\d{6}",[8],[["(\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2-$3-$4",["12"],"(8 $1)"],["(\\d{3})(\\d)(\\d{2})(\\d{2})","$1 $2-$3-$4",["[1-5]"],"(8 $1)"],["(\\d{2})(\\d{6})","$1 $2",["[67]"],"8 $1"]],"8",0,0,0,0,0,0,"8~10"],TN:["216","00","[2-57-9]\\d{7}",[8],[["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[2-57-9]"]]]],TO:["676","00","(?:0800|(?:[5-8]\\d\\d|999)\\d)\\d{3}|[2-8]\\d{4}",[5,7],[["(\\d{2})(\\d{3})","$1-$2",["[2-4]|50|6[09]|7[0-24-69]|8[05]"]],["(\\d{4})(\\d{3})","$1 $2",["0"]],["(\\d{3})(\\d{4})","$1 $2",["[5-9]"]]]],TR:["90","00","4\\d{6}|8\\d{11,12}|(?:[2-58]\\d\\d|900)\\d{7}",[7,10,12,13],[["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["512|8[01589]|90"],"0$1",1],["(\\d{3})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["5(?:[0-59]|61)","5(?:[0-59]|61[06])","5(?:[0-59]|61[06]1)"],"0$1",1],["(\\d{3})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[24][1-8]|3[1-9]"],"(0$1)",1],["(\\d{3})(\\d{3})(\\d{6,7})","$1 $2 $3",["80"],"0$1",1]],"0"],TT:["1","011","(?:[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2-46-8]\\d{6})$|1","868$1",0,"868"],TV:["688","00","(?:2|7\\d\\d|90)\\d{4}",[5,6,7],[["(\\d{2})(\\d{3})","$1 $2",["2"]],["(\\d{2})(\\d{4})","$1 $2",["90"]],["(\\d{2})(\\d{5})","$1 $2",["7"]]]],TW:["886","0(?:0[25-79]|19)","[2-689]\\d{8}|7\\d{9,10}|[2-8]\\d{7}|2\\d{6}",[7,8,9,10,11],[["(\\d{2})(\\d)(\\d{4})","$1 $2 $3",["202"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["[258]0"],"0$1"],["(\\d)(\\d{3,4})(\\d{4})","$1 $2 $3",["[23568]|4(?:0[02-48]|[1-47-9])|7[1-9]","[23568]|4(?:0[2-48]|[1-47-9])|(?:400|7)[1-9]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[49]"],"0$1"],["(\\d{2})(\\d{4})(\\d{4,5})","$1 $2 $3",["7"],"0$1"]],"0",0,0,0,0,0,0,0,"#"],TZ:["255","00[056]","(?:[25-8]\\d|41|90)\\d{7}",[9],[["(\\d{3})(\\d{2})(\\d{4})","$1 $2 $3",["[89]"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[24]"],"0$1"],["(\\d{2})(\\d{7})","$1 $2",["5"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[67]"],"0$1"]],"0"],UA:["380","00","[89]\\d{9}|[3-9]\\d{8}",[9,10],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["6[12][29]|(?:3[1-8]|4[136-8]|5[12457]|6[49])2|(?:56|65)[24]","6[12][29]|(?:35|4[1378]|5[12457]|6[49])2|(?:56|65)[24]|(?:3[1-46-8]|46)2[013-9]"],"0$1"],["(\\d{4})(\\d{5})","$1 $2",["3[1-8]|4(?:[1367]|[45][6-9]|8[4-6])|5(?:[1-5]|6[0135689]|7[4-6])|6(?:[12][3-7]|[459])","3[1-8]|4(?:[1367]|[45][6-9]|8[4-6])|5(?:[1-5]|6(?:[015689]|3[02389])|7[4-6])|6(?:[12][3-7]|[459])"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[3-7]|89|9[1-9]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["[89]"],"0$1"]],"0",0,0,0,0,0,0,"0~0"],UG:["256","00[057]","800\\d{6}|(?:[29]0|[347]\\d)\\d{7}",[9],[["(\\d{4})(\\d{5})","$1 $2",["202","2024"],"0$1"],["(\\d{3})(\\d{6})","$1 $2",["[27-9]|4(?:6[45]|[7-9])"],"0$1"],["(\\d{2})(\\d{7})","$1 $2",["[34]"],"0$1"]],"0"],US:["1","011","[2-9]\\d{9}|3\\d{6}",[10],[["(\\d{3})(\\d{4})","$1-$2",["310"],0,1],["(\\d{3})(\\d{3})(\\d{4})","($1) $2-$3",["[2-9]"],0,1,"$1-$2-$3"]],"1",0,0,0,0,0,[["(?:3052(?:0[0-8]|[1-9]\\d)|5056(?:[0-35-9]\\d|4[0-468]))\\d{4}|(?:2742|305[3-9]|472[247-9]|505[2-57-9]|983[2-47-9])\\d{6}|(?:2(?:0[1-35-9]|1[02-9]|2[03-57-9]|3[1459]|4[08]|5[1-46]|6[0279]|7[0269]|8[13])|3(?:0[1-47-9]|1[02-9]|2[0135-79]|3[0-24679]|4[167]|5[0-2]|6[01349]|8[056])|4(?:0[124-9]|1[02-579]|2[3-5]|3[0245]|4[023578]|58|6[349]|7[0589]|8[04])|5(?:0[1-47-9]|1[0235-8]|20|3[0149]|4[01]|5[179]|6[1-47]|7[0-5]|8[0256])|6(?:0[1-35-9]|1[024-9]|2[03689]|3[016]|4[0156]|5[01679]|6[0-279]|78|8[0-29])|7(?:0[1-46-8]|1[2-9]|2[04-8]|3[0-247]|4[037]|5[47]|6[02359]|7[0-59]|8[156])|8(?:0[1-68]|1[02-8]|2[0168]|3[0-2589]|4[03578]|5[046-9]|6[02-5]|7[028])|9(?:0[1346-9]|1[02-9]|2[0589]|3[0146-8]|4[01357-9]|5[12469]|7[0-389]|8[04-69]))[2-9]\\d{6}"],[""],["8(?:00|33|44|55|66|77|88)[2-9]\\d{6}"],["900[2-9]\\d{6}"],["52(?:3(?:[2-46-9][02-9]\\d|5(?:[02-46-9]\\d|5[0-46-9]))|4(?:[2-478][02-9]\\d|5(?:[034]\\d|2[024-9]|5[0-46-9])|6(?:0[1-9]|[2-9]\\d)|9(?:[05-9]\\d|2[0-5]|49)))\\d{4}|52[34][2-9]1[02-9]\\d{4}|5(?:00|2[125-9]|33|44|66|77|88)[2-9]\\d{6}"],0,0,0,["305209\\d{4}"]]],UY:["598","0(?:0|1[3-9]\\d)","0004\\d{2,9}|[1249]\\d{7}|(?:[49]\\d|80)\\d{5}",[6,7,8,9,10,11,12,13],[["(\\d{3})(\\d{3,4})","$1 $2",["0"]],["(\\d{3})(\\d{4})","$1 $2",["[49]0|8"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["9"],"0$1"],["(\\d{4})(\\d{4})","$1 $2",["[124]"]],["(\\d{3})(\\d{3})(\\d{2,4})","$1 $2 $3",["0"]],["(\\d{3})(\\d{3})(\\d{3})(\\d{2,4})","$1 $2 $3 $4",["0"]]],"0",0,0,0,0,0,0,"00"," int. "],UZ:["998","00","(?:20|33|[5-9]\\d)\\d{7}",[9],[["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["[235-9]"]]]],VA:["39","00","0\\d{5,10}|3[0-8]\\d{7,10}|55\\d{8}|8\\d{5}(?:\\d{2,4})?|(?:1\\d|39)\\d{7,8}",[6,7,8,9,10,11,12],0,0,0,0,0,0,"06698"],VC:["1","011","(?:[58]\\d\\d|784|900)\\d{7}",[10],0,"1",0,"([2-7]\\d{6})$|1","784$1",0,"784"],VE:["58","00","[68]00\\d{7}|(?:[24]\\d|[59]0)\\d{8}",[10],[["(\\d{3})(\\d{7})","$1-$2",["[24-689]"],"0$1"]],"0"],VG:["1","011","(?:284|[58]\\d\\d|900)\\d{7}",[10],0,"1",0,"([2-578]\\d{6})$|1","284$1",0,"284"],VI:["1","011","[58]\\d{9}|(?:34|90)0\\d{7}",[10],0,"1",0,"([2-9]\\d{6})$|1","340$1",0,"340"],VN:["84","00","[12]\\d{9}|[135-9]\\d{8}|[16]\\d{7}|[16-8]\\d{6}",[7,8,9,10],[["(\\d{2})(\\d{5})","$1 $2",["80"],"0$1",1],["(\\d{4})(\\d{4,6})","$1 $2",["1"],0,1],["(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",["6"],"0$1",1],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[357-9]"],"0$1",1],["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["2[48]"],"0$1",1],["(\\d{3})(\\d{4})(\\d{3})","$1 $2 $3",["2"],"0$1",1]],"0"],VU:["678","00","[57-9]\\d{6}|(?:[238]\\d|48)\\d{3}",[5,7],[["(\\d{3})(\\d{4})","$1 $2",["[57-9]"]]]],WF:["681","00","(?:40|72|8\\d{4})\\d{4}|[89]\\d{5}",[6,9],[["(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3",["[47-9]"]],["(\\d{3})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",["8"]]]],WS:["685","0","(?:[2-6]|8\\d{5})\\d{4}|[78]\\d{6}|[68]\\d{5}",[5,6,7,10],[["(\\d{5})","$1",["[2-5]|6[1-9]"]],["(\\d{3})(\\d{3,7})","$1 $2",["[68]"]],["(\\d{2})(\\d{5})","$1 $2",["7"]]]],XK:["383","00","2\\d{7,8}|3\\d{7,11}|(?:4\\d\\d|[89]00)\\d{5}",[8,9,10,11,12],[["(\\d{3})(\\d{5})","$1 $2",["[89]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3})","$1 $2 $3",["[2-4]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["2|39"],"0$1"],["(\\d{2})(\\d{7,10})","$1 $2",["3"],"0$1"]],"0"],YE:["967","00","(?:1|7\\d)\\d{7}|[1-7]\\d{6}",[7,8,9],[["(\\d)(\\d{3})(\\d{3,4})","$1 $2 $3",["[1-6]|7(?:[24-6]|8[0-7])"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["7"],"0$1"]],"0"],YT:["262","00","7093\\d{5}|(?:80|9\\d)\\d{7}|(?:26|63)9\\d{6}",[9],0,"0",0,0,0,0,0,[["269(?:0[0-467]|15|5[0-4]|6\\d|[78]0)\\d{4}"],["(?:639(?:0[0-79]|1[019]|[267]\\d|3[09]|40|5[05-9]|9[04-79])|7093[5-7])\\d{4}"],["80\\d{7}"],0,0,0,0,0,["9(?:(?:39|47)8[01]|769\\d)\\d{4}"]]],ZA:["27","00","[1-79]\\d{8}|8\\d{4,9}",[5,6,7,8,9,10],[["(\\d{2})(\\d{3,4})","$1 $2",["8[1-4]"],"0$1"],["(\\d{2})(\\d{3})(\\d{2,3})","$1 $2 $3",["8[1-4]"],"0$1"],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["860"],"0$1"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["[1-9]"],"0$1"],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["8"],"0$1"]],"0"],ZM:["260","00","800\\d{6}|(?:21|[579]\\d|63)\\d{7}",[9],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[28]"],"0$1"],["(\\d{2})(\\d{7})","$1 $2",["[579]"],"0$1"]],"0"],ZW:["263","00","2(?:[0-57-9]\\d{6,8}|6[0-24-9]\\d{6,7})|[38]\\d{9}|[35-8]\\d{8}|[3-6]\\d{7}|[1-689]\\d{6}|[1-3569]\\d{5}|[1356]\\d{4}",[5,6,7,8,9,10],[["(\\d{3})(\\d{3,5})","$1 $2",["2(?:0[45]|2[278]|[49]8)|3(?:[09]8|17)|6(?:[29]8|37|75)|[23][78]|(?:33|5[15]|6[68])[78]"],"0$1"],["(\\d)(\\d{3})(\\d{2,4})","$1 $2 $3",["[49]"],"0$1"],["(\\d{3})(\\d{4})","$1 $2",["80"],"0$1"],["(\\d{2})(\\d{7})","$1 $2",["24|8[13-59]|(?:2[05-79]|39|5[45]|6[15-8])2","2(?:02[014]|4|[56]20|[79]2)|392|5(?:42|525)|6(?:[16-8]21|52[013])|8[13-59]"],"(0$1)"],["(\\d{2})(\\d{3})(\\d{4})","$1 $2 $3",["7"],"0$1"],["(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["2(?:1[39]|2[0157]|[378]|[56][14])|3(?:12|29)","2(?:1[39]|2[0157]|[378]|[56][14])|3(?:123|29)"],"0$1"],["(\\d{4})(\\d{6})","$1 $2",["8"],"0$1"],["(\\d{2})(\\d{3,5})","$1 $2",["1|2(?:0[0-36-9]|12|29|[56])|3(?:1[0-689]|[24-6])|5(?:[0236-9]|1[2-4])|6(?:[013-59]|7[0-46-9])|(?:33|55|6[68])[0-69]|(?:29|3[09]|62)[0-79]"],"0$1"],["(\\d{2})(\\d{3})(\\d{3,4})","$1 $2 $3",["29[013-9]|39|54"],"0$1"],["(\\d{4})(\\d{3,5})","$1 $2",["(?:25|54)8","258|5483"],"0$1"]],"0"]},nonGeographic:{800:["800",0,"(?:00|[1-9]\\d)\\d{6}",[8],[["(\\d{4})(\\d{4})","$1 $2",["\\d"]]],0,0,0,0,0,0,[0,0,["(?:00|[1-9]\\d)\\d{6}"]]],808:["808",0,"[1-9]\\d{7}",[8],[["(\\d{4})(\\d{4})","$1 $2",["[1-9]"]]],0,0,0,0,0,0,[0,0,0,0,0,0,0,0,0,["[1-9]\\d{7}"]]],870:["870",0,"7\\d{11}|[235-7]\\d{8}",[9,12],[["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["[235-7]"]]],0,0,0,0,0,0,[0,["(?:[356]|774[45])\\d{8}|7[6-8]\\d{7}"],0,0,0,0,0,0,["2\\d{8}",[9]]]],878:["878",0,"10\\d{10}",[12],[["(\\d{2})(\\d{5})(\\d{5})","$1 $2 $3",["1"]]],0,0,0,0,0,0,[0,0,0,0,0,0,0,0,["10\\d{10}"]]],881:["881",0,"6\\d{9}|[0-36-9]\\d{8}",[9,10],[["(\\d)(\\d{3})(\\d{5})","$1 $2 $3",["[0-37-9]"]],["(\\d)(\\d{3})(\\d{5,6})","$1 $2 $3",["6"]]],0,0,0,0,0,0,[0,["6\\d{9}|[0-36-9]\\d{8}"]]],882:["882",0,"[13]\\d{6}(?:\\d{2,5})?|[19]\\d{7}|(?:[25]\\d\\d|4)\\d{7}(?:\\d{2})?",[7,8,9,10,11,12],[["(\\d{2})(\\d{5})","$1 $2",["16|342"]],["(\\d{2})(\\d{6})","$1 $2",["49"]],["(\\d{2})(\\d{2})(\\d{4})","$1 $2 $3",["1[36]|9"]],["(\\d{2})(\\d{4})(\\d{3})","$1 $2 $3",["3[23]"]],["(\\d{2})(\\d{3,4})(\\d{4})","$1 $2 $3",["16"]],["(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["10|23|3(?:[15]|4[57])|4|51"]],["(\\d{3})(\\d{4})(\\d{4})","$1 $2 $3",["34"]],["(\\d{2})(\\d{4,5})(\\d{5})","$1 $2 $3",["[1-35]"]]],0,0,0,0,0,0,[0,["342\\d{4}|(?:337|49)\\d{6}|(?:3(?:2|47|7\\d{3})|50\\d{3})\\d{7}",[7,8,9,10,12]],0,0,0,["348[57]\\d{7}",[11]],0,0,["1(?:3(?:0[0347]|[13][0139]|2[035]|4[013568]|6[0459]|7[06]|8[15-8]|9[0689])\\d{4}|6\\d{5,10})|(?:345\\d|9[89])\\d{6}|(?:10|2(?:3|85\\d)|3(?:[15]|[69]\\d\\d)|4[15-8]|51)\\d{8}"]]],883:["883",0,"(?:[1-4]\\d|51)\\d{6,10}",[8,9,10,11,12],[["(\\d{3})(\\d{3})(\\d{2,8})","$1 $2 $3",["[14]|2[24-689]|3[02-689]|51[24-9]"]],["(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",["510"]],["(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["21"]],["(\\d{4})(\\d{4})(\\d{4})","$1 $2 $3",["51[13]"]],["(\\d{3})(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3 $4",["[235]"]]],0,0,0,0,0,0,[0,0,0,0,0,0,0,0,["(?:2(?:00\\d\\d|10)|(?:370[1-9]|51\\d0)\\d)\\d{7}|51(?:00\\d{5}|[24-9]0\\d{4,7})|(?:1[0-79]|2[24-689]|3[02-689]|4[0-4])0\\d{5,9}"]]],888:["888",0,"\\d{11}",[11],[["(\\d{3})(\\d{3})(\\d{5})","$1 $2 $3"]],0,0,0,0,0,0,[0,0,0,0,0,0,["\\d{11}"]]],979:["979",0,"[1359]\\d{8}",[9],[["(\\d)(\\d{4})(\\d{4})","$1 $2 $3",["[1359]"]]],0,0,0,0,0,0,[0,0,0,["[1359]\\d{8}"]]]}};function l5(t,e){var n=Array.prototype.slice.call(e);return n.push(c5),t.apply(this,n)}function _g(t,e){t=t.split("-"),e=e.split("-");for(var n=t[0].split("."),r=e[0].split("."),i=0;i<3;i++){var s=Number(n[i]),a=Number(r[i]);if(s>a)return 1;if(a>s)return-1;if(!isNaN(s)&&isNaN(a))return 1;if(isNaN(s)&&!isNaN(a))return-1}return t[1]&&e[1]?t[1]>e[1]?1:t[1]<e[1]?-1:0:!t[1]&&e[1]?1:t[1]&&!e[1]?-1:0}var d5={}.constructor;function Qr(t){return t!=null&&t.constructor===d5}function nu(t){"@babel/helpers - typeof";return nu=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},nu(t)}function qc(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function u5(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function Hc(t,e,n){return e&&u5(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t}var p5="1.2.0",f5="1.7.35",yg=" ext. ",h5=/^\d+$/,vt=function(){function t(e){qc(this,t),h1(e),this.metadata=e,g1.call(this,e)}return Hc(t,[{key:"getCountries",value:function(){return Object.keys(this.metadata.countries).filter(function(n){return n!=="001"})}},{key:"getCountryMetadata",value:function(n){return this.metadata.countries[n]}},{key:"nonGeographic",value:function(){if(!(this.v1||this.v2||this.v3))return this.metadata.nonGeographic||this.metadata.nonGeographical}},{key:"hasCountry",value:function(n){return this.getCountryMetadata(n)!==void 0}},{key:"hasCallingCode",value:function(n){if(this.getCountryCodesForCallingCode(n))return!0;if(this.nonGeographic()){if(this.nonGeographic()[n])return!0}else{var r=this.countryCallingCodes()[n];if(r&&r.length===1&&r[0]==="001")return!0}}},{key:"isNonGeographicCallingCode",value:function(n){return this.nonGeographic()?!!this.nonGeographic()[n]:!this.getCountryCodesForCallingCode(n)}},{key:"country",value:function(n){return this.selectNumberingPlan(n)}},{key:"selectNumberingPlan",value:function(n,r){if(n&&h5.test(n)&&(r=n,n=null),n&&n!=="001"){if(!this.hasCountry(n))throw new Error("Unknown country: ".concat(n));this.numberingPlan=new wg(this.getCountryMetadata(n),this)}else if(r){if(!this.hasCallingCode(r))throw new Error("Unknown calling code: ".concat(r));this.numberingPlan=new wg(this.getNumberingPlanMetadata(r),this)}else this.numberingPlan=void 0;return this}},{key:"getCountryCodesForCallingCode",value:function(n){var r=this.countryCallingCodes()[n];if(r)return r.length===1&&r[0].length===3?void 0:r}},{key:"getCountryCodeForCallingCode",value:function(n){var r=this.getCountryCodesForCallingCode(n);if(r)return r[0]}},{key:"getNumberingPlanMetadata",value:function(n){var r=this.getCountryCodeForCallingCode(n);if(r)return this.getCountryMetadata(r);if(this.nonGeographic()){var i=this.nonGeographic()[n];if(i)return i}else{var s=this.countryCallingCodes()[n];if(s&&s.length===1&&s[0]==="001")return this.metadata.countries["001"]}}},{key:"countryCallingCode",value:function(){return this.numberingPlan.callingCode()}},{key:"IDDPrefix",value:function(){return this.numberingPlan.IDDPrefix()}},{key:"defaultIDDPrefix",value:function(){return this.numberingPlan.defaultIDDPrefix()}},{key:"nationalNumberPattern",value:function(){return this.numberingPlan.nationalNumberPattern()}},{key:"possibleLengths",value:function(){return this.numberingPlan.possibleLengths()}},{key:"formats",value:function(){return this.numberingPlan.formats()}},{key:"nationalPrefixForParsing",value:function(){return this.numberingPlan.nationalPrefixForParsing()}},{key:"nationalPrefixTransformRule",value:function(){return this.numberingPlan.nationalPrefixTransformRule()}},{key:"leadingDigits",value:function(){return this.numberingPlan.leadingDigits()}},{key:"hasTypes",value:function(){return this.numberingPlan.hasTypes()}},{key:"type",value:function(n){return this.numberingPlan.type(n)}},{key:"ext",value:function(){return this.numberingPlan.ext()}},{key:"countryCallingCodes",value:function(){return this.v1?this.metadata.country_phone_code_to_countries:this.metadata.country_calling_codes}},{key:"chooseCountryByCountryCallingCode",value:function(n){return this.selectNumberingPlan(n)}},{key:"hasSelectedNumberingPlan",value:function(){return this.numberingPlan!==void 0}}]),t}(),wg=function(){function t(e,n){qc(this,t),this.globalMetadataObject=n,this.metadata=e,g1.call(this,n.metadata)}return Hc(t,[{key:"callingCode",value:function(){return this.metadata[0]}},{key:"getDefaultCountryMetadataForRegion",value:function(){return this.globalMetadataObject.getNumberingPlanMetadata(this.callingCode())}},{key:"IDDPrefix",value:function(){if(!(this.v1||this.v2))return this.metadata[1]}},{key:"defaultIDDPrefix",value:function(){if(!(this.v1||this.v2))return this.metadata[12]}},{key:"nationalNumberPattern",value:function(){return this.v1||this.v2?this.metadata[1]:this.metadata[2]}},{key:"possibleLengths",value:function(){if(!this.v1)return this.metadata[this.v2?2:3]}},{key:"_getFormats",value:function(n){return n[this.v1?2:this.v2?3:4]}},{key:"formats",value:function(){var n=this,r=this._getFormats(this.metadata)||this._getFormats(this.getDefaultCountryMetadataForRegion())||[];return r.map(function(i){return new g5(i,n)})}},{key:"nationalPrefix",value:function(){return this.metadata[this.v1?3:this.v2?4:5]}},{key:"_getNationalPrefixFormattingRule",value:function(n){return n[this.v1?4:this.v2?5:6]}},{key:"nationalPrefixFormattingRule",value:function(){return this._getNationalPrefixFormattingRule(this.metadata)||this._getNationalPrefixFormattingRule(this.getDefaultCountryMetadataForRegion())}},{key:"_nationalPrefixForParsing",value:function(){return this.metadata[this.v1?5:this.v2?6:7]}},{key:"nationalPrefixForParsing",value:function(){return this._nationalPrefixForParsing()||this.nationalPrefix()}},{key:"nationalPrefixTransformRule",value:function(){return this.metadata[this.v1?6:this.v2?7:8]}},{key:"_getNationalPrefixIsOptionalWhenFormatting",value:function(){return!!this.metadata[this.v1?7:this.v2?8:9]}},{key:"nationalPrefixIsOptionalWhenFormattingInNationalFormat",value:function(){return this._getNationalPrefixIsOptionalWhenFormatting(this.metadata)||this._getNationalPrefixIsOptionalWhenFormatting(this.getDefaultCountryMetadataForRegion())}},{key:"leadingDigits",value:function(){return this.metadata[this.v1?8:this.v2?9:10]}},{key:"types",value:function(){return this.metadata[this.v1?9:this.v2?10:11]}},{key:"hasTypes",value:function(){return this.types()&&this.types().length===0?!1:!!this.types()}},{key:"type",value:function(n){if(this.hasTypes()&&vg(this.types(),n))return new _5(vg(this.types(),n),this)}},{key:"ext",value:function(){return this.v1||this.v2?yg:this.metadata[13]||yg}}]),t}(),g5=function(){function t(e,n){qc(this,t),this._format=e,this.metadata=n}return Hc(t,[{key:"pattern",value:function(){return this._format[0]}},{key:"format",value:function(){return this._format[1]}},{key:"leadingDigitsPatterns",value:function(){return this._format[2]||[]}},{key:"nationalPrefixFormattingRule",value:function(){return this._format[3]||this.metadata.nationalPrefixFormattingRule()}},{key:"nationalPrefixIsOptionalWhenFormattingInNationalFormat",value:function(){return!!this._format[4]||this.metadata.nationalPrefixIsOptionalWhenFormattingInNationalFormat()}},{key:"nationalPrefixIsMandatoryWhenFormattingInNationalFormat",value:function(){return this.usesNationalPrefix()&&!this.nationalPrefixIsOptionalWhenFormattingInNationalFormat()}},{key:"usesNationalPrefix",value:function(){return!!(this.nationalPrefixFormattingRule()&&!m5.test(this.nationalPrefixFormattingRule()))}},{key:"internationalFormat",value:function(){return this._format[5]||this.format()}}]),t}(),m5=/^\(?\$1\)?$/,_5=function(){function t(e,n){qc(this,t),this.type=e,this.metadata=n}return Hc(t,[{key:"pattern",value:function(){return this.metadata.v1?this.type:this.type[0]}},{key:"possibleLengths",value:function(){if(!this.metadata.v1)return this.type[1]||this.metadata.possibleLengths()}}]),t}();function vg(t,e){switch(e){case"FIXED_LINE":return t[0];case"MOBILE":return t[1];case"TOLL_FREE":return t[2];case"PREMIUM_RATE":return t[3];case"PERSONAL_NUMBER":return t[4];case"VOICEMAIL":return t[5];case"UAN":return t[6];case"PAGER":return t[7];case"VOIP":return t[8];case"SHARED_COST":return t[9]}}function h1(t){if(!t)throw new Error("[libphonenumber-js] `metadata` argument not passed. Check your arguments.");if(!Qr(t)||!Qr(t.countries))throw new Error("[libphonenumber-js] `metadata` argument was passed but it's not a valid metadata. Must be an object having `.countries` child object property. Got ".concat(Qr(t)?"an object of shape: { "+Object.keys(t).join(", ")+" }":"a "+y5(t)+": "+t,"."))}var y5=function(e){return nu(e)};function Ap(t,e){if(e=new vt(e),e.hasCountry(t))return e.country(t).countryCallingCode();throw new Error("Unknown country: ".concat(t))}function w5(t,e){return e.countries.hasOwnProperty(t)}function g1(t){var e=t.version;typeof e=="number"?(this.v1=e===1,this.v2=e===2,this.v3=e===3,this.v4=e===4):e?_g(e,p5)===-1?this.v2=!0:_g(e,f5)===-1?this.v3=!0:this.v4=!0:this.v1=!0}function Ep(t,e){return v5(t,void 0,e)}function v5(t,e,n){var r=n.type(e),i=r&&r.possibleLengths()||n.possibleLengths();if(!i)return"IS_POSSIBLE";var s=t.length,a=i[0];return a===s?"IS_POSSIBLE":a>s?"TOO_SHORT":i[i.length-1]<s?"TOO_LONG":i.indexOf(s,1)>=0?"IS_POSSIBLE":"INVALID_LENGTH"}function b5(t,e,n){if(e===void 0&&(e={}),n=new vt(n),e.v2){if(!t.countryCallingCode)throw new Error("Invalid phone number object passed");n.selectNumberingPlan(t.countryCallingCode)}else{if(!t.phone)return!1;if(t.country){if(!n.hasCountry(t.country))throw new Error("Unknown country: ".concat(t.country));n.country(t.country)}else{if(!t.countryCallingCode)throw new Error("Invalid phone number object passed");n.selectNumberingPlan(t.countryCallingCode)}}if(n.possibleLengths())return m1(t.phone||t.nationalNumber,n);if(t.countryCallingCode&&n.isNonGeographicCallingCode(t.countryCallingCode))return!0;throw new Error('Missing "possibleLengths" in metadata. Perhaps the metadata has been generated before v1.0.18.')}function m1(t,e){switch(Ep(t,e)){case"IS_POSSIBLE":return!0;default:return!1}}function In(t,e){return t=t||"",new RegExp("^(?:"+e+")$").test(t)}function $5(t,e){var n=typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=k5(t))||e){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
195
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function k5(t,e){if(t){if(typeof t=="string")return bg(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set")return Array.from(t);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return bg(t,e)}}function bg(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var x5=["MOBILE","PREMIUM_RATE","TOLL_FREE","SHARED_COST","VOIP","PERSONAL_NUMBER","PAGER","UAN","VOICEMAIL"];function Cp(t,e,n){if(e=e||{},!(!t.country&&!t.countryCallingCode)){n=new vt(n),n.selectNumberingPlan(t.country,t.countryCallingCode);var r=e.v2?t.nationalNumber:t.phone;if(In(r,n.nationalNumberPattern())){if(pl(r,"FIXED_LINE",n))return n.type("MOBILE")&&n.type("MOBILE").pattern()===""||!n.type("MOBILE")||pl(r,"MOBILE",n)?"FIXED_LINE_OR_MOBILE":"FIXED_LINE";for(var i=$5(x5),s;!(s=i()).done;){var a=s.value;if(pl(r,a,n))return a}}}}function pl(t,e,n){return e=n.type(e),!e||!e.pattern()||e.possibleLengths()&&e.possibleLengths().indexOf(t.length)<0?!1:In(t,e.pattern())}function S5(t,e,n){if(e=e||{},n=new vt(n),n.selectNumberingPlan(t.country,t.countryCallingCode),n.hasTypes())return Cp(t,e,n.metadata)!==void 0;var r=e.v2?t.nationalNumber:t.phone;return In(r,n.nationalNumberPattern())}function z5(t,e,n){var r=new vt(n),i=r.getCountryCodesForCallingCode(t);return i?i.filter(function(s){return A5(e,s,n)}):[]}function A5(t,e,n){var r=new vt(n);return r.selectNumberingPlan(e),r.numberingPlan.possibleLengths().indexOf(t.length)>=0}var Np=2,E5=17,C5=3,Qt="0-90-9٠-٩۰-۹",N5="-‐-―−ー-",I5="//",j5="..",O5="  ­​⁠ ",T5="()()[]\\[\\]",P5="~⁓∼~",Na="".concat(N5).concat(I5).concat(j5).concat(O5).concat(T5).concat(P5),Ip="++",R5=new RegExp("(["+Qt+"])");function B5(t,e,n,r){if(e){var i=new vt(r);i.selectNumberingPlan(e,n);var s=new RegExp(i.IDDPrefix());if(t.search(s)===0){t=t.slice(t.match(s)[0].length);var a=t.match(R5);if(!(a&&a[1]!=null&&a[1].length>0&&a[1]==="0"))return t}}}function L5(t,e){if(t&&e.numberingPlan.nationalPrefixForParsing()){var n=new RegExp("^(?:"+e.numberingPlan.nationalPrefixForParsing()+")"),r=n.exec(t);if(r){var i,s,a=r.length-1,c=a>0&&r[a];if(e.nationalPrefixTransformRule()&&c)i=t.replace(n,e.nationalPrefixTransformRule()),a>1&&(s=r[1]);else{var l=r[0];i=t.slice(l.length),c&&(s=r[1])}var d;if(c){var u=t.indexOf(r[1]),f=t.slice(0,u);f===e.numberingPlan.nationalPrefix()&&(d=e.numberingPlan.nationalPrefix())}else d=r[0];return{nationalNumber:i,nationalPrefix:d,carrierCode:s}}}return{nationalNumber:t}}function ru(t,e){var n=L5(t,e),r=n.carrierCode,i=n.nationalNumber;if(i!==t){if(!U5(t,i,e))return{nationalNumber:t};if(e.possibleLengths()&&!D5(i,e))return{nationalNumber:t}}return{nationalNumber:i,carrierCode:r}}function U5(t,e,n){return!(In(t,n.nationalNumberPattern())&&!In(e,n.nationalNumberPattern()))}function D5(t,e){switch(Ep(t,e)){case"TOO_SHORT":case"INVALID_LENGTH":return!1;default:return!0}}function M5(t,e,n,r){var i=e?Ap(e,r):n;if(t.indexOf(i)===0){r=new vt(r),r.selectNumberingPlan(e,n);var s=t.slice(i.length),a=ru(s,r),c=a.nationalNumber,l=ru(t,r),d=l.nationalNumber;if(!In(d,r.nationalNumberPattern())&&In(c,r.nationalNumberPattern())||Ep(d,r)==="TOO_LONG")return{countryCallingCode:i,number:s}}return{number:t}}function _1(t,e,n,r){if(!t)return{};var i;if(t[0]!=="+"){var s=B5(t,e,n,r);if(s&&s!==t)i=!0,t="+"+s;else{if(e||n){var a=M5(t,e,n,r),c=a.countryCallingCode,l=a.number;if(c)return{countryCallingCodeSource:"FROM_NUMBER_WITHOUT_PLUS_SIGN",countryCallingCode:c,number:l}}return{number:t}}}if(t[1]==="0")return{};r=new vt(r);for(var d=2;d-1<=C5&&d<=t.length;){var u=t.slice(1,d);if(r.hasCallingCode(u))return r.selectNumberingPlan(u),{countryCallingCodeSource:i?"FROM_NUMBER_WITH_IDD":"FROM_NUMBER_WITH_PLUS_SIGN",countryCallingCode:u,number:t.slice(d)};d++}return{}}function F5(t){return t.replace(new RegExp("[".concat(Na,"]+"),"g")," ").trim()}var q5=/(\$\d)/;function H5(t,e,n){var r=n.useInternationalFormat,i=n.withNationalPrefix,s=t.replace(new RegExp(e.pattern()),r?e.internationalFormat():i&&e.nationalPrefixFormattingRule()?e.format().replace(q5,e.nationalPrefixFormattingRule()):e.format());return r?F5(s):s}var V5=/^[\d]+(?:[~\u2053\u223C\uFF5E][\d]+)?$/;function K5(t,e,n){var r=new vt(n);if(r.selectNumberingPlan(t,e),r.defaultIDDPrefix())return r.defaultIDDPrefix();if(V5.test(r.IDDPrefix()))return r.IDDPrefix()}var G5=";ext=",Mr=function(e){return"([".concat(Qt,"]{1,").concat(e,"})")};function y1(t){var e="20",n="15",r="9",i="6",s="[  \\t,]*",a="[:\\..]?[  \\t,-]*",c="#?",l="(?:e?xt(?:ensi(?:ó?|ó))?n?|e?xtn?|доб|anexo)",d="(?:[xx##~~]|int|int)",u="[- ]+",f="[  \\t]*",h="(?:,{2}|;)",m=G5+Mr(e),y=s+l+a+Mr(e)+c,v=s+d+a+Mr(r)+c,b=u+Mr(i)+"#",A=f+h+a+Mr(n)+c,O=f+"(?:,)+"+a+Mr(r)+c;return m+"|"+y+"|"+v+"|"+b+"|"+A+"|"+O}var W5="["+Qt+"]{"+Np+"}",J5="["+Ip+"]{0,1}(?:["+Na+"]*["+Qt+"]){3,}["+Na+Qt+"]*",X5=new RegExp("^["+Ip+"]{0,1}(?:["+Na+"]*["+Qt+"]){1,2}$","i"),Z5=J5+"(?:"+y1()+")?",Y5=new RegExp("^"+W5+"$|^"+Z5+"$","i");function Q5(t){return t.length>=Np&&Y5.test(t)}function e6(t){return X5.test(t)}function t6(t){var e=t.number,n=t.ext;if(!e)return"";if(e[0]!=="+")throw new Error('"formatRFC3966()" expects "number" to be in E.164 format.');return"tel:".concat(e).concat(n?";ext="+n:"")}function n6(t,e){var n=typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=r6(t))||e){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
196
196
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function r6(t,e){if(t){if(typeof t=="string")return $g(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set")return Array.from(t);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return $g(t,e)}}function $g(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function kg(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function xg(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?kg(Object(n),!0).forEach(function(r){i6(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):kg(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function i6(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var Sg={formatExtension:function(e,n,r){return"".concat(e).concat(r.ext()).concat(n)}};function o6(t,e,n,r){if(n?n=xg(xg({},Sg),n):n=Sg,r=new vt(r),t.country&&t.country!=="001"){if(!r.hasCountry(t.country))throw new Error("Unknown country: ".concat(t.country));r.country(t.country)}else if(t.countryCallingCode)r.selectNumberingPlan(t.countryCallingCode);else return t.phone||"";var i=r.countryCallingCode(),s=n.v2?t.nationalNumber:t.phone,a;switch(e){case"NATIONAL":return s?(a=Ia(s,t.carrierCode,"NATIONAL",r,n),fl(a,t.ext,r,n.formatExtension)):"";case"INTERNATIONAL":return s?(a=Ia(s,null,"INTERNATIONAL",r,n),a="+".concat(i," ").concat(a),fl(a,t.ext,r,n.formatExtension)):"+".concat(i);case"E.164":return"+".concat(i).concat(s);case"RFC3966":return t6({number:"+".concat(i).concat(s),ext:t.ext});case"IDD":if(!n.fromCountry)return;var c=a6(s,t.carrierCode,i,n.fromCountry,r);return fl(c,t.ext,r,n.formatExtension);default:throw new Error('Unknown "format" argument passed to "formatNumber()": "'.concat(e,'"'))}}function Ia(t,e,n,r,i){var s=s6(r.formats(),t);return s?H5(t,s,{useInternationalFormat:n==="INTERNATIONAL",withNationalPrefix:!(s.nationalPrefixIsOptionalWhenFormattingInNationalFormat()&&i&&i.nationalPrefix===!1),carrierCode:e,metadata:r}):t}function s6(t,e){for(var n=n6(t),r;!(r=n()).done;){var i=r.value;if(i.leadingDigitsPatterns().length>0){var s=i.leadingDigitsPatterns()[i.leadingDigitsPatterns().length-1];if(e.search(s)!==0)continue}if(In(e,i.pattern()))return i}}function fl(t,e,n,r){return e?r(t,e,n):t}function a6(t,e,n,r,i){var s=Ap(r,i.metadata);if(s===n){var a=Ia(t,e,"NATIONAL",i);return n==="1"?n+" "+a:a}var c=K5(r,void 0,i.metadata);if(c)return"".concat(c," ").concat(n," ").concat(Ia(t,null,"INTERNATIONAL",i))}function zg(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function Ag(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?zg(Object(n),!0).forEach(function(r){c6(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):zg(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function c6(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function l6(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function d6(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function u6(t,e,n){return e&&d6(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t}var p6=function(){function t(e,n,r){if(l6(this,t),!e)throw new TypeError("First argument is required");if(typeof e!="string")throw new TypeError("First argument must be a string");if(typeof e=="string"){if(e[0]==="+"&&!n)throw new TypeError("`metadata` argument not passed");if(Qr(n)&&Qr(n.countries)){r=n;var i=e;if(!g6.test(i))throw new Error('Invalid `number` argument passed: must consist of a "+" followed by digits');var s=_1(i,void 0,void 0,r),a=s.countryCallingCode,c=s.number;if(n=c,e=a,!n)throw new Error("Invalid `number` argument passed: too short")}}if(!n)throw new TypeError("`nationalNumber` argument is required");if(typeof n!="string")throw new TypeError("`nationalNumber` argument must be a string");h1(r);var l=h6(e,r),d=l.country,u=l.countryCallingCode;this.country=d,this.countryCallingCode=u,this.nationalNumber=n,this.number="+"+this.countryCallingCode+this.nationalNumber,this.getMetadata=function(){return r}}return u6(t,[{key:"setExt",value:function(n){this.ext=n}},{key:"getPossibleCountries",value:function(){return this.country?[this.country]:z5(this.countryCallingCode,this.nationalNumber,this.getMetadata())}},{key:"isPossible",value:function(){return b5(this,{v2:!0},this.getMetadata())}},{key:"isValid",value:function(){return S5(this,{v2:!0},this.getMetadata())}},{key:"isNonGeographic",value:function(){var n=new vt(this.getMetadata());return n.isNonGeographicCallingCode(this.countryCallingCode)}},{key:"isEqual",value:function(n){return this.number===n.number&&this.ext===n.ext}},{key:"getType",value:function(){return Cp(this,{v2:!0},this.getMetadata())}},{key:"format",value:function(n,r){return o6(this,n,r?Ag(Ag({},r),{},{v2:!0}):{v2:!0},this.getMetadata())}},{key:"formatNational",value:function(n){return this.format("NATIONAL",n)}},{key:"formatInternational",value:function(n){return this.format("INTERNATIONAL",n)}},{key:"getURI",value:function(n){return this.format("RFC3966",n)}}]),t}(),f6=function(e){return/^[A-Z]{2}$/.test(e)};function h6(t,e){var n,r,i=new vt(e);return f6(t)?(n=t,i.selectNumberingPlan(n),r=i.countryCallingCode()):r=t,{country:n,countryCallingCode:r}}var g6=/^\+\d+$/;function iu(t){"@babel/helpers - typeof";return iu=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},iu(t)}function m6(t,e,n){return Object.defineProperty(t,"prototype",{writable:!1}),t}function _6(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function y6(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&vo(t,e)}function w6(t){var e=v1();return function(){var r=bo(t),i;if(e){var s=bo(this).constructor;i=Reflect.construct(r,arguments,s)}else i=r.apply(this,arguments);return v6(this,i)}}function v6(t,e){if(e&&(iu(e)==="object"||typeof e=="function"))return e;if(e!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return w1(t)}function w1(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function ou(t){var e=typeof Map=="function"?new Map:void 0;return ou=function(r){if(r===null||!b6(r))return r;if(typeof r!="function")throw new TypeError("Super expression must either be null or a function");if(typeof e<"u"){if(e.has(r))return e.get(r);e.set(r,i)}function i(){return ks(r,arguments,bo(this).constructor)}return i.prototype=Object.create(r.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),vo(i,r)},ou(t)}function ks(t,e,n){return v1()?ks=Reflect.construct:ks=function(i,s,a){var c=[null];c.push.apply(c,s);var l=Function.bind.apply(i,c),d=new l;return a&&vo(d,a.prototype),d},ks.apply(null,arguments)}function v1(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function b6(t){return Function.toString.call(t).indexOf("[native code]")!==-1}function vo(t,e){return vo=Object.setPrototypeOf||function(r,i){return r.__proto__=i,r},vo(t,e)}function bo(t){return bo=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},bo(t)}var $n=function(t){y6(n,t);var e=w6(n);function n(r){var i;return _6(this,n),i=e.call(this,r),Object.setPrototypeOf(w1(i),n.prototype),i.name=i.constructor.name,i}return m6(n)}(ou(Error)),Eg=new RegExp("(?:"+y1()+")$","i");function $6(t){var e=t.search(Eg);if(e<0)return{};for(var n=t.slice(0,e),r=t.match(Eg),i=1;i<r.length;){if(r[i])return{number:n,ext:r[i]};i++}}var k6={0:"0",1:"1",2:"2",3:"3",4:"4",5:"5",6:"6",7:"7",8:"8",9:"9","0":"0","1":"1","2":"2","3":"3","4":"4","5":"5","6":"6","7":"7","8":"8","9":"9","٠":"0","١":"1","٢":"2","٣":"3","٤":"4","٥":"5","٦":"6","٧":"7","٨":"8","٩":"9","۰":"0","۱":"1","۲":"2","۳":"3","۴":"4","۵":"5","۶":"6","۷":"7","۸":"8","۹":"9"};function x6(t){return k6[t]}function S6(t,e){var n=typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=z6(t))||e){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
197
197
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function z6(t,e){if(t){if(typeof t=="string")return Cg(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set")return Array.from(t);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Cg(t,e)}}function Cg(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function Ng(t){for(var e="",n=S6(t.split("")),r;!(r=n()).done;){var i=r.value;e+=A6(i,e)||""}return e}function A6(t,e,n){return t==="+"?e?void 0:"+":x6(t)}function E6(t,e){var n=typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=C6(t))||e){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
198
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function C6(t,e){if(t){if(typeof t=="string")return Ig(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set")return Array.from(t);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Ig(t,e)}}function Ig(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function N6(t,e){var n=e.countries,r=e.metadata;r=new vt(r);for(var i=E6(n),s;!(s=i()).done;){var a=s.value;if(r.country(a),r.leadingDigits()){if(t&&t.search(r.leadingDigits())===0)return a}else if(Cp({phone:t,country:a},void 0,r.metadata))return a}}function I6(t,e){var n=e.nationalNumber,r=e.defaultCountry,i=e.metadata,s=i.getCountryCodesForCallingCode(t);if(s)return s.length===1?s[0]:N6(n,{countries:s,defaultCountry:r,metadata:i.metadata})}var b1="+",j6="[\\-\\.\\(\\)]?",jg="(["+en+"]|"+j6+")",O6="^\\"+b1+jg+"*["+en+"]"+jg+"*$",T6=new RegExp(O6,"g"),su=en,P6="["+su+"]+((\\-)*["+su+"])*",R6="a-zA-Z",B6="["+R6+"]+((\\-)*["+su+"])*",L6="^("+P6+"\\.)*"+B6+"\\.?$",U6=new RegExp(L6,"g"),Og="tel:",au=";phone-context=",D6=";isub=";function M6(t){var e=t.indexOf(au);if(e<0)return null;var n=e+au.length;if(n>=t.length)return"";var r=t.indexOf(";",n);return r>=0?t.substring(n,r):t.substring(n)}function F6(t){return t===null?!0:t.length===0?!1:T6.test(t)||U6.test(t)}function q6(t,e){var n=e.extractFormattedPhoneNumber,r=M6(t);if(!F6(r))throw new $n("NOT_A_NUMBER");var i;if(r===null)i=n(t)||"";else{i="",r.charAt(0)===b1&&(i+=r);var s=t.indexOf(Og),a;s>=0?a=s+Og.length:a=0;var c=t.indexOf(au);i+=t.substring(a,c)}var l=i.indexOf(D6);if(l>0&&(i=i.substring(0,l)),i!=="")return i}var H6=250,V6=new RegExp("["+Ip+en+"]"),K6=new RegExp("[^"+en+"#]+$");function G6(t,e,n){if(e=e||{},n=new vt(n),e.defaultCountry&&!n.hasCountry(e.defaultCountry))throw e.v2?new $n("INVALID_COUNTRY"):new Error("Unknown country: ".concat(e.defaultCountry));var r=J6(t,e.v2,e.extract),i=r.number,s=r.ext,a=r.error;if(!i){if(e.v2)throw a==="TOO_SHORT"?new $n("TOO_SHORT"):new $n("NOT_A_NUMBER");return{}}var c=Z6(i,e.defaultCountry,e.defaultCallingCode,n),l=c.country,d=c.nationalNumber,u=c.countryCallingCode,f=c.countryCallingCodeSource,h=c.carrierCode;if(!n.hasSelectedNumberingPlan()){if(e.v2)throw new $n("INVALID_COUNTRY");return{}}if(!d||d.length<Np){if(e.v2)throw new $n("TOO_SHORT");return{}}if(d.length>E5){if(e.v2)throw new $n("TOO_LONG");return{}}if(e.v2){var m=new p6(u,d,n.metadata);return l&&(m.country=l),h&&(m.carrierCode=h),s&&(m.ext=s),m.__countryCallingCodeSource=f,m}var y=(e.extended?n.hasSelectedNumberingPlan():l)?In(d,n.nationalNumberPattern()):!1;return e.extended?{country:l,countryCallingCode:u,carrierCode:h,valid:y,possible:y?!0:!!(e.extended===!0&&n.possibleLengths()&&m1(d,n)),phone:d,ext:s}:y?X6(l,d,s):{}}function W6(t,e,n){if(t){if(t.length>H6){if(n)throw new $n("TOO_LONG");return}if(e===!1)return t;var r=t.search(V6);if(!(r<0))return t.slice(r).replace(K6,"")}}function J6(t,e,n){var r=q6(t,{extractFormattedPhoneNumber:function(a){return W6(a,n,e)}});if(!r)return{};if(!Q5(r))return e6(r)?{error:"TOO_SHORT"}:{};var i=$6(r);return i.ext?i:{number:r}}function X6(t,e,n){var r={country:t,phone:e};return n&&(r.ext=n),r}function Z6(t,e,n,r){var i=_1(Ng(t),e,n,r.metadata),s=i.countryCallingCodeSource,a=i.countryCallingCode,c=i.number,l;if(a)r.selectNumberingPlan(a);else if(c&&(e||n))r.selectNumberingPlan(e,n),e&&(l=e),a=n||Ap(e,r.metadata);else return{};if(!c)return{countryCallingCodeSource:s,countryCallingCode:a};var d=ru(Ng(c),r),u=d.nationalNumber,f=d.carrierCode,h=I6(a,{nationalNumber:u,defaultCountry:e,metadata:r});return h&&(l=h,h==="001"||r.country(l)),{country:l,countryCallingCode:a,countryCallingCodeSource:s,nationalNumber:u,carrierCode:f}}function Tg(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function Pg(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?Tg(Object(n),!0).forEach(function(r){Y6(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Tg(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function Y6(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Q6(t,e,n){return G6(t,Pg(Pg({},e),{},{v2:!0}),n)}function Rg(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function ex(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?Rg(Object(n),!0).forEach(function(r){tx(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Rg(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function tx(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function nx(t,e){return sx(t)||ox(t,e)||ix(t,e)||rx()}function rx(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
199
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ix(t,e){if(t){if(typeof t=="string")return Bg(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set")return Array.from(t);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Bg(t,e)}}function Bg(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function ox(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var r=[],i=!0,s=!1,a,c;try{for(n=n.call(t);!(i=(a=n.next()).done)&&(r.push(a.value),!(e&&r.length===e));i=!0);}catch(l){s=!0,c=l}finally{try{!i&&n.return!=null&&n.return()}finally{if(s)throw c}}return r}}function sx(t){if(Array.isArray(t))return t}function ax(t){var e=Array.prototype.slice.call(t),n=nx(e,4),r=n[0],i=n[1],s=n[2],a=n[3],c,l,d;if(typeof r=="string")c=r;else throw new TypeError("A text for parsing must be a string.");if(!i||typeof i=="string")a?(l=s,d=a):(l=void 0,d=s),i&&(l=ex({defaultCountry:i},l));else if(Qr(i))s?(l=i,d=s):d=i;else throw new Error("Invalid second argument: ".concat(i));return{text:c,options:l,metadata:d}}function Lg(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function Ug(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?Lg(Object(n),!0).forEach(function(r){cx(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Lg(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function cx(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function lx(t,e,n){e&&e.defaultCountry&&!w5(e.defaultCountry,n)&&(e=Ug(Ug({},e),{},{defaultCountry:void 0}));try{return Q6(t,e,n)}catch(r){if(!(r instanceof $n))throw r}}function dx(){var t=ax(arguments),e=t.text,n=t.options,r=t.metadata;return lx(e,n,r)}function ux(){return l5(dx,arguments)}function Vc(t,e="US"){const n=t.trim();if(n.includes("@")){const r=n.toLowerCase(),i=/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r);return{connectionType:"email",normalized:i?r:null,isValid:i}}else if(/^\+?\d[\d\s\-().]*$/.test(n)){const r=ux(n,{defaultCountry:e});return r&&r.isValid()?{connectionType:"sms",normalized:r.number,isValid:!0}:{connectionType:"sms",normalized:null,isValid:!1}}else return{connectionType:"username",normalized:n,isValid:!0}}function jp(t){let e=t.trim();e.startsWith("[")&&e.endsWith("]")&&(e=e.slice(1,-1));const n=e.indexOf("%");return n!==-1&&(e=e.slice(0,n)),e}function px(t){const n=jp(t).split(".");return n.length!==4?!1:n.every(r=>/^\d+$/.test(r)&&Number(r)>=0&&Number(r)<=255)}function fx(t){const e=jp(t);if(e.length<2||e.indexOf(":")===-1||!/^[0-9a-fA-F:.]+$/.test(e))return!1;const n=e.split(":");return e.includes("::")?n.length<=8:n.length===8}function hx(t){let e=t.trim();const n=/^\[([^\]]+)\](?::\d+)?$/,r=e.match(n);if(r&&r[1])return r[1];const i=e.lastIndexOf(":");if(i!==-1){const s=e.slice(0,i),a=e.slice(i+1);/^[0-9.]+$/.test(s)&&/^\d+$/.test(a)&&(e=s)}return e}function Dg(t){if(!t)return null;const e=jp(hx(t));return px(e)?{family:4,normalized:e}:fx(e)?{family:6,normalized:e.toLowerCase()}:null}function Mg(t){if(t.includes("::")){let[e,n]=t.split("::"),r=e?e.split(":").filter(Boolean):[],i=n?n.split(":").filter(Boolean):[],s=8-(r.length+i.length);return[...r.map(a=>a.toLowerCase()||"0"),...Array(s).fill("0"),...i.map(a=>a.toLowerCase()||"0")]}else return t.split(":").map(e=>e.toLowerCase()||"0")}function gx(t,e,n=!0){const r=Dg(t),i=Dg(e);if(!r||!i||r.family!==i.family)return!1;if(r.family===4)return r.normalized===i.normalized;const s=Mg(r.normalized),a=Mg(i.normalized);return n?s.length===8&&a.length===8&&s.join(":")===a.join(":"):s.slice(0,4).join(":")===a.slice(0,4).join(":")}class Ir extends Error{constructor(n,r=302){super(`Redirect to ${n}`);ae(this,"location");ae(this,"status");this.name=Ir.name,this.location=n,this.status=r}}const mx=o.z.object({client_id:o.z.string(),username:o.z.string().transform(t=>t.toLowerCase()),otp:o.z.string(),authParams:ro.optional(),enforceIpCheck:o.z.boolean().optional().default(!1)});async function $1(t,{client_id:e,username:n,otp:r,authParams:i,enforceIpCheck:s=!1}){const a=t.get("ip"),c=t.get("countryCode"),{connectionType:l,normalized:d}=Vc(n,c);if(!d)throw new ee(400,{message:"Invalid username format"});const u=await t.env.data.legacyClients.get(e);if(!u)throw new ee(403,{message:"Client not found"});const{env:f}=t,h=await f.data.codes.get(u.tenant.id,r,"otp");if(!h)throw new ee(400,{message:pe("code_invalid")});if(h.expires_at<new Date().toISOString())throw new ee(400,{message:pe("code_expired")});if(h.used_at)throw new ee(400,{message:pe("code_used")});const m=await f.data.loginSessions.get(u.tenant.id,h.login_id);if(!m||m.authParams.username!==n)throw new ee(400,{message:"Code not found or expired"});if(s&&m.ip&&a&&!gx(m.ip,a))throw new Ir(`${st(t.env)}invalid-session?state=${m.id}`);const y=await qa(t,{client:u,username:d,provider:l,connection:l,isSocial:!1,ip:t.var.ip});return await f.data.codes.used(u.tenant.id,r),{user:y,client:u,loginSession:m,session_id:m.session_id,authParams:{...m.authParams,...i||{}}}}async function Op(t,e){const n=await $1(t,e);return un(t,{authParams:n.authParams,client:n.client,user:n.user,loginSession:n.loginSession,strategy:"email"})}const Fg=o.z.object({client_id:o.z.string().optional(),client_secret:o.z.string().optional()}),qg=o.z.union([f1.extend(Fg.shape),o.z.object({grant_type:o.z.literal("authorization_code"),client_id:o.z.string(),code:o.z.string(),redirect_uri:o.z.string(),code_verifier:o.z.string().min(43).max(128),organization:o.z.string().optional()}),o.z.object({grant_type:o.z.literal("authorization_code"),code:o.z.string(),redirect_uri:o.z.string().optional(),organization:o.z.string().optional(),...Fg.shape}),o.z.object({grant_type:o.z.literal("refresh_token"),client_id:o.z.string(),refresh_token:o.z.string(),redirect_uri:o.z.string().optional()}),o.z.object({grant_type:o.z.literal("http://auth0.com/oauth/grant-type/passwordless/otp"),client_id:o.z.string(),username:o.z.string(),otp:o.z.string(),realm:o.z.enum(["email","sms"])})]);function _x(t){if(!t)return{};const[e,n]=t.split(" ");if((e==null?void 0:e.toLowerCase())==="basic"&&n){const[r,i]=atob(n).split(":");return{client_id:r,client_secret:i}}return{}}const yx=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth2"],method:"post",path:"/",request:{body:{content:{"application/x-www-form-urlencoded":{schema:qg},"application/json":{schema:qg}}}},responses:{200:{content:{"application/json":{schema:bu}},description:"Tokens"},302:{description:"Redirect for further user interaction (e.g., MFA, consent).",headers:o.z.object({Location:o.z.string().url()}).openapi({})},400:{description:"Bad Request - The request was malformed or invalid.",content:{"application/json":{schema:o.z.object({error:o.z.string(),error_description:o.z.string().optional()})}}},401:{description:"Unauthorized - Client authentication failed.",content:{"application/json":{schema:o.z.object({error:o.z.string(),error_description:o.z.string().optional()})}}},403:{description:"Forbidden - User is not a member of the required organization.",content:{"application/json":{schema:o.z.object({error:o.z.string(),error_description:o.z.string().optional()})}}}}}),async t=>{var d,u,f,h,m;const n=(t.req.header("Content-Type")||"").includes("application/json")?t.req.valid("json"):t.req.valid("form"),r=_x(t.req.header("Authorization")),i={...n,...r};if(!i.client_id)throw new S(400,{message:"client_id is required"});t.set("client_id",i.client_id);let s;switch(n.grant_type){case Vt.AuthorizationCode:s=await o5(t,i5.parse(i));break;case Vt.ClientCredential:s=await r5(t,f1.parse(i));break;case Vt.RefreshToken:s=await a5(t,s5.parse(i));break;case Vt.OTP:s=await $1(t,mx.parse(i));break;default:return t.json({error:"unsupported_grant_type",error_description:"Grant type not implemented"},400)}const a=new Headers;if(s.session_id){const y=Hs(s.client.tenant.id,s.session_id,t.var.host||"");a.set("Set-Cookie",y)}let c=[];if(s.authParams.audience)try{let y;if(n.grant_type===Vt.ClientCredential)y=await Vs(t,{grantType:Vt.ClientCredential,tenantId:s.client.tenant.id,clientId:s.client.client_id,audience:s.authParams.audience,requestedScopes:((d=s.authParams.scope)==null?void 0:d.split(" "))||[],organizationId:(u=s.organization)==null?void 0:u.id});else{if(!((f=s.user)!=null&&f.user_id))throw new ee(400,{error:"invalid_request",error_description:"User ID is required for user-based grants"});y=await Vs(t,{grantType:n.grant_type,tenantId:s.client.tenant.id,userId:s.user.user_id,clientId:s.client.client_id,audience:s.authParams.audience,requestedScopes:((h=s.authParams.scope)==null?void 0:h.split(" "))||[],organizationId:(m=s.organization)==null?void 0:m.id})}s.authParams.scope=y.scopes.join(" "),c=y.permissions}catch(y){if(y instanceof S)throw y;console.error("Error calculating scopes and permissions:",y)}const l=await Fa(t,{...s,grantType:n.grant_type,permissions:c.length>0?c:void 0});return t.json(l,{headers:a})});var Tp={exports:{}};const Pp=[{id:0,value:"Too weak",minDiversity:0,minLength:0},{id:1,value:"Weak",minDiversity:2,minLength:6},{id:2,value:"Medium",minDiversity:4,minLength:8},{id:3,value:"Strong",minDiversity:4,minLength:10}],k1=(t,e=Pp,n="!\"#$%&'()*+,-./:;<=>?@[\\\\\\]^_`{|}~")=>{let r=t||"";e[0].minDiversity=0,e[0].minLength=0;const i=[{regex:"[a-z]",message:"lowercase"},{regex:"[A-Z]",message:"uppercase"},{regex:"[0-9]",message:"number"}];n&&i.push({regex:`[${n}]`,message:"symbol"});let s={};s.contains=i.filter(c=>new RegExp(`${c.regex}`).test(r)).map(c=>c.message),s.length=r.length;let a=e.filter(c=>s.contains.length>=c.minDiversity).filter(c=>s.length>=c.minLength).sort((c,l)=>l.id-c.id).map(c=>({id:c.id,value:c.value}));return Object.assign(s,a[0]),s};Tp.exports={passwordStrength:k1,defaultOptions:Pp};var wx=Tp.exports.passwordStrength=k1;Tp.exports.defaultOptions=Pp;function Rp(t){return wx(t).id<2?!1:t.length>=8&&/[a-z]/.test(t)&&/[A-Z]/.test(t)&&/[0-9]/.test(t)&&/[^A-Za-z0-9]/.test(t)}async function Jo(t,e){var i;const n=await t.env.data.emailProviders.get(t.var.tenant_id)||(t.env.DEFAULT_TENANT_ID?await t.env.data.emailProviders.get(t.env.DEFAULT_TENANT_ID):null);if(!n)throw new S(500,{message:"Email provider not found"});const r=(i=t.env.emailProviders)==null?void 0:i[n.name];if(!r)throw new S(500,{message:"Email provider not found"});await r({emailProvider:n,...e,from:n.default_from_address||`login@${t.env.ISSUER}`})}async function x1(t,e){var a,c;if(!t.var.client_id)throw new S(500,{message:"Client not found"});const n=await Oi(t.env,t.var.client_id),r=n.connections.find(l=>l.strategy==="sms");if(!r)throw new S(500,{message:"SMS provider not found"});const i=((a=r.options)==null?void 0:a.provider)||"twilio",s=(c=t.env.smsProviders)==null?void 0:c[i];if(!s)throw new S(500,{message:"SMS provider not found"});await s({options:r.options,to:e.to,from:e.from,text:e.text,template:"auth-code",data:{code:e.code,tenantName:n.tenant.friendly_name,tenantId:n.tenant.id}})}async function S1(t,e,n,r,i){var f;const s=await t.env.data.tenants.get(t.var.tenant_id);if(!s)throw new S(500,{message:"Tenant not found"});const a=`${st(t.env)}reset-password?state=${r}&code=${n}`,c=await t.env.data.branding.get(t.var.tenant_id),l=(c==null?void 0:c.logo_url)||"",d=((f=c==null?void 0:c.colors)==null?void 0:f.primary)||"#7d68f4",u={vendorName:s.friendly_name,lng:"en"};await Jo(t,{to:e,subject:pe("reset_password_title",u),html:`Click here to reset your password: ${st(t.env)}reset-password?state=${r}&code=${n}`,template:"auth-password-reset",data:{vendorName:s.friendly_name,logo:l,passwordResetUrl:a,supportUrl:s.support_url||"https://support.sesamy.com",buttonColor:d,passwordResetTitle:pe("password_reset_title",u),resetPasswordEmailClickToReset:pe("reset_password_email_click_to_reset",u),resetPasswordEmailReset:pe("reset_password_email_reset",u),supportInfo:pe("support_info",u),contactUs:pe("contact_us",u),copyright:pe("copyright",u),tenantName:s.friendly_name,tenantId:s.id}})}async function Bp(t,{to:e,code:n,language:r}){var h;const i=await t.env.data.tenants.get(t.var.tenant_id);if(!i)throw new S(500,{message:"Tenant not found"});const{connectionType:s}=Vc(e),a=await t.env.data.branding.get(t.var.tenant_id),c=(a==null?void 0:a.logo_url)||"",l=((h=a==null?void 0:a.colors)==null?void 0:h.primary)||"#7d68f4",d=new URL(st(t.env)),u={vendorName:i.friendly_name,vendorId:i.id,loginDomain:d.hostname,code:n,lng:r||"en"};s==="email"?await Jo(t,{to:e,subject:pe("code_email_subject",u),html:`Click here to validate your email: ${st(t.env)}validate-email`,template:"auth-code",data:{code:n,vendorName:i.friendly_name,logo:c,supportUrl:i.support_url||"",buttonColor:l,welcomeToYourAccount:pe("welcome_to_your_account",u),linkEmailClickToLogin:pe("link_email_click_to_login",u),linkEmailLogin:pe("link_email_login",u),linkEmailOrEnterCode:pe("link_email_or_enter_code",u),codeValid30Mins:pe("code_valid_30_minutes",u),supportInfo:pe("support_info",u),contactUs:pe("contact_us",u),copyright:pe("copyright",u)}}):s==="sms"&&await x1(t,{to:e,text:pe("sms_code_text",u),code:n,from:i.friendly_name});const f=be(t,{type:_e.CODE_LINK_SENT,description:e});ve(t,t.env.data.logs.create(i.id,f))}async function Lp(t,{to:e,code:n,authParams:r,language:i}){var m;const s=await t.env.data.tenants.get(t.var.tenant_id);if(!s)throw new S(500,{message:"Tenant not found"});if(!r.redirect_uri)throw new S(400,{message:"redirect_uri is required"});const{connectionType:a}=Vc(e),c=await t.env.data.branding.get(t.var.tenant_id),l=(c==null?void 0:c.logo_url)||"",d=((m=c==null?void 0:c.colors)==null?void 0:m.primary)||"",u=new URL(He(t.env));u.pathname="passwordless/verify_redirect",u.searchParams.set("verification_code",n),u.searchParams.set("connection",a),u.searchParams.set("client_id",r.client_id),u.searchParams.set("redirect_uri",r.redirect_uri),u.searchParams.set("email",e),r.response_type&&u.searchParams.set("response_type",r.response_type),r.scope&&u.searchParams.set("scope",r.scope),r.state&&u.searchParams.set("state",r.state),r.nonce&&u.searchParams.set("nonce",r.nonce),r.code_challenge&&u.searchParams.set("code_challenge",r.code_challenge),r.code_challenge_method&&u.searchParams.set("code_challenge_method",r.code_challenge_method),r.audience&&u.searchParams.set("audience",r.audience);const f={vendorName:s.friendly_name,code:n,lng:i||"en"};if(a==="email")await Jo(t,{to:e,subject:pe("code_email_subject",f),html:`Click here to validate your email: ${st(t.env)}validate-email`,template:"auth-link",data:{code:n,vendorName:s.friendly_name,logo:l,supportUrl:s.support_url||"",magicLink:u.toString(),buttonColor:d,welcomeToYourAccount:pe("welcome_to_your_account",f),linkEmailClickToLogin:pe("link_email_click_to_login",f),linkEmailLogin:pe("link_email_login",f),linkEmailOrEnterCode:pe("link_email_or_enter_code",f),codeValid30Mins:pe("code_valid_30_minutes",f),supportInfo:pe("support_info",f),contactUs:pe("contact_us",f),copyright:pe("copyright",f)}});else if(a==="sms")await x1(t,{to:e,text:`${pe("link_sms_login",f)}: ${u.toString()}`,code:n,from:s.friendly_name});else throw new S(400,{message:"Only email and SMS connections are supported for magic links"});const h=be(t,{type:_e.CODE_LINK_SENT,description:e});ve(t,t.env.data.logs.create(s.id,h))}async function Up(t,e,n){var l;const r=await t.env.data.tenants.get(t.var.tenant_id);if(!r)throw new S(500,{message:"Tenant not found"});if(!e.email)throw new S(400,{message:"User has no email"});const i=await t.env.data.branding.get(t.var.tenant_id),s=(i==null?void 0:i.logo_url)||"",a=((l=i==null?void 0:i.colors)==null?void 0:l.primary)||"#7d68f4",c={vendorName:r.friendly_name,lng:n||"en"};await Jo(t,{to:e.email,subject:pe("welcome_to_your_account",c),html:`Click here to validate your email: ${st(t.env)}validate-email`,template:"auth-verify-email",data:{vendorName:r.friendly_name,logo:s,emailValidationUrl:`${st(t.env)}validate-email`,supportUrl:r.support_url||"https://support.sesamy.com",buttonColor:a,welcomeToYourAccount:pe("welcome_to_your_account",c),verifyEmailVerify:pe("verify_email_verify",c),supportInfo:pe("support_info",c),contactUs:pe("contact_us",c),copyright:pe("copyright",c)}})}async function vx(t,e,n,r,i){var f;const s=await t.env.data.tenants.get(t.var.tenant_id);if(!s)throw new S(500,{message:"Tenant not found"});const a=await t.env.data.branding.get(t.var.tenant_id),c=(a==null?void 0:a.logo_url)||"",l=((f=a==null?void 0:a.colors)==null?void 0:f.primary)||"#7d68f4",d={vendorName:s.friendly_name,lng:"en"},u=`${st(t.env)}signup?state=${r}&code=${n}`;await Jo(t,{to:e,subject:pe("register_password_account",d),html:`Click here to register: ${u}`,template:"auth-pre-signup-verification",data:{vendorName:s.friendly_name,logo:c,signupUrl:u,setPassword:pe("set_password",d),registerPasswordAccount:pe("register_password_account",d),clickToSignUpDescription:pe("click_to_sign_up_description",d),supportUrl:s.support_url||"https://support.sesamy.com",buttonColor:l,welcomeToYourAccount:pe("welcome_to_your_account",d),verifyEmailVerify:pe("verify_email_verify",d),supportInfo:pe("support_info",d),contactUs:pe("contact_us",d),copyright:pe("copyright",d)}})}const bx=new o.OpenAPIHono().openapi(o.createRoute({tags:["dbconnections"],method:"post",path:"/signup",request:{body:{content:{"application/json":{schema:o.z.object({client_id:o.z.string(),connection:o.z.literal("Username-Password-Authentication"),email:o.z.string().transform(t=>t.toLowerCase()),password:o.z.string()})}}}},responses:{200:{content:{"application/json":{schema:o.z.object({_id:o.z.string(),email:o.z.string().optional(),email_verified:o.z.boolean(),app_metadata:o.z.object({}),user_metadata:o.z.object({})})}},description:"Created user"}}}),async t=>{const{email:e,password:n,client_id:r}=t.req.valid("json"),i=await t.env.data.legacyClients.get(r);if(!i)throw new S(400,{message:"Client not found"});if(t.set("client_id",i.client_id),t.set("tenant_id",i.tenant.id),!Rp(n))throw new S(400,{message:"Password does not meet the requirements"});if(await io({userAdapter:t.env.data.users,tenant_id:i.tenant.id,username:e,provider:"auth2"}))throw new S(400,{message:"Invalid sign up"});const a=await t.env.data.users.create(i.tenant.id,{user_id:`auth2|${La()}`,email:e,email_verified:!1,provider:"auth2",connection:"Username-Password-Authentication",is_social:!1});t.set("user_id",a.user_id),t.set("username",a.email),t.set("connection",a.connection);const c=await ti.hash(n,10);await t.env.data.passwords.create(i.tenant.id,{user_id:a.user_id,password:c,algorithm:"bcrypt"}),await Up(t,a);const l=be(t,{type:_e.SUCCESS_SIGNUP,description:"Successful signup"});return ve(t,t.env.data.logs.create(i.tenant.id,l)),t.json({_id:a.user_id,email:a.email,email_verified:!1,app_metadata:{},user_metadata:{}})}).openapi(o.createRoute({tags:["dbconnections"],method:"post",path:"/change_password",request:{body:{content:{"application/json":{schema:o.z.object({client_id:o.z.string(),connection:o.z.literal("Username-Password-Authentication"),email:o.z.string().transform(t=>t.toLowerCase())})}}}},responses:{200:{description:"Redirect to the client's redirect uri"}}}),async t=>{const{email:e,client_id:n}=t.req.valid("json"),r=await t.env.data.legacyClients.get(n);if(!r)throw new S(400,{message:"Client not found"});if(t.set("client_id",r.client_id),t.set("tenant_id",r.tenant.id),!await vi({userAdapter:t.env.data.users,tenant_id:r.tenant.id,username:e,provider:"auth2"}))return t.html("If an account with that email exists, we've sent instructions to reset your password.");const s={client_id:n,username:e},a=await t.env.data.loginSessions.create(r.tenant.id,{expires_at:new Date(Date.now()+_r*1e3).toISOString(),authParams:s,csrf_token:Ne(),ip:t.get("ip"),useragent:t.get("useragent"),auth0Client:Nn(t.get("auth0_client"))});return await S1(t,e,a.id,a.authParams.state),t.html("If an account with that email exists, we've sent instructions to reset your password.")});function Zn(){const t="1234567890";let e="";for(let n=0;n<6;n+=1)e+=t[Math.floor(Math.random()*10)];return e.toString()}const $x=new o.OpenAPIHono().openapi(o.createRoute({tags:["passwordless"],method:"post",path:"/start",request:{body:{content:{"application/json":{schema:o.z.union([o.z.object({connection:o.z.literal("email"),client_id:o.z.string(),email:o.z.string().transform(t=>t.toLowerCase()),send:o.z.enum(["link","code"]),authParams:ro.omit({client_id:!0})}),o.z.object({client_id:o.z.string(),connection:o.z.literal("sms"),phone_number:o.z.string(),send:o.z.enum(["link","code"]),authParams:ro.omit({client_id:!0})})])}}}},responses:{200:{description:"Status"}}}),async t=>{var b,A;const e=t.req.valid("json"),{env:n}=t,{client_id:r,send:i,authParams:s,connection:a}=e,c=await t.env.data.legacyClients.get(r);if(!c)throw new S(400,{message:"Client not found"});t.set("client_id",c.client_id),t.set("tenant_id",c.tenant.id);const l=a==="email"?e.email:e.phone_number,d=t.get("ip"),u=t.get("useragent"),f=t.get("auth0_client"),h=Nn(f),m=await n.data.loginSessions.create(c.tenant.id,{authParams:{...s,client_id:r,username:l},expires_at:new Date(Date.now()+hs).toISOString(),csrf_token:Ne(),ip:d,useragent:u,auth0Client:h}),y=await n.data.codes.create(c.tenant.id,{code_id:Zn(),code_type:"otp",login_id:m.id,expires_at:new Date(Date.now()+hs).toISOString(),redirect_uri:s.redirect_uri}),v=(A=(b=s==null?void 0:s.ui_locales)==null?void 0:b.split(" "))==null?void 0:A.map(O=>O.split("-")[0])[0];return i==="link"?await Lp(t,{to:l,code:y.code_id,authParams:{...s,client_id:r},language:v}):await Bp(t,{to:l,code:y.code_id,language:v}),t.html("OK")}).openapi(o.createRoute({tags:["passwordless"],method:"get",path:"/verify_redirect",request:{query:o.z.object({scope:o.z.string(),response_type:o.z.nativeEnum(Nt),redirect_uri:o.z.string(),state:o.z.string(),nonce:o.z.string().optional(),verification_code:o.z.string(),connection:o.z.string(),client_id:o.z.string(),email:o.z.string().transform(t=>t.toLowerCase()),audience:o.z.string().optional()})},responses:{302:{description:"Successful verification, redirecting to continue flow.",headers:o.z.object({Location:o.z.string().url()}).openapi({})},400:{description:"Bad Request (e.g., invalid client, invalid code, missing parameters).",content:{"application/json":{schema:o.z.object({error:o.z.string(),error_description:o.z.string().optional()})}}},500:{description:"Internal Server Error.",content:{"application/json":{schema:o.z.object({error:o.z.string(),error_description:o.z.string().optional()})}}}}}),async t=>{const{env:e}=t,{client_id:n,email:r,verification_code:i,redirect_uri:s,state:a,scope:c,audience:l,response_type:d,nonce:u}=t.req.valid("query"),f=await Oi(e,n);t.set("client_id",f.client_id),t.set("tenant_id",f.tenant.id),t.set("connection","email");const h={client_id:n,redirect_uri:s,state:a,nonce:u,scope:c,audience:l,response_type:d};let m="Something went wrong. Please try again later.";try{const U=await Op(t,{client_id:n,username:r,otp:i,authParams:h,enforceIpCheck:!0});if(U instanceof Response)return U;if(U&&typeof U=="object"&&"access_token"in U)return t.json(U)}catch(U){const T=U;"message"in T&&typeof T.message=="string"&&(m=T.message)}const y=t.get("ip"),v=t.get("useragent"),b=t.get("auth0_client"),A=Nn(b),O=await e.data.loginSessions.create(f.tenant.id,{authParams:{...h,username:r},expires_at:new Date(Date.now()+hs).toISOString(),csrf_token:Ne(),ip:y,useragent:v,auth0Client:A});return t.redirect(`${st(t.env)}invalid-session?state=${O.id}&error=${encodeURIComponent(m)}`,302)});class qr extends S{constructor(n,r){super(n,r);ae(this,"_code");this._code=r==null?void 0:r.code}get code(){return this._code}}async function z1(t,e,n,r){var h,m,y,v;const{data:i}=t.env,{username:s}=n;if(t.set("username",s),!s)throw new ee(400,{message:"Username is required"});const a=await vi({userAdapter:t.env.data.users,tenant_id:e.tenant.id,username:s,provider:"auth2"});if(!a){const b=be(t,{type:_e.FAILED_LOGIN_INCORRECT_PASSWORD,description:"Invalid user"});throw ve(t,i.logs.create(e.tenant.id,b)),new qr(403,{message:"User not found",code:"USER_NOT_FOUND"})}const c=a.linked_to?await i.users.get(e.tenant.id,a.linked_to):a;if(!c)throw new qr(403,{message:"User not found",code:"USER_NOT_FOUND"});t.set("connection",a.connection),t.set("user_id",c.user_id);const l=await i.passwords.get(e.tenant.id,a.user_id);if(!(l&&await ti.compare(n.password,l.password))){const b=be(t,{type:_e.FAILED_LOGIN_INCORRECT_PASSWORD,description:"Invalid password"});throw ve(t,i.logs.create(e.tenant.id,b)),new qr(403,{message:"Invalid password",code:"INVALID_PASSWORD"})}if((await i.logs.list(e.tenant.id,{page:0,per_page:10,include_totals:!1,q:`user_id:${c.user_id}`})).logs.filter(b=>b.type===_e.FAILED_LOGIN_INCORRECT_PASSWORD&&new Date(b.date)>new Date(Date.now()-1e3*60*5)).length>=3){const b=be(t,{type:_e.FAILED_LOGIN,description:"Too many failed login attempts"});throw ve(t,i.logs.create(e.tenant.id,b)),new qr(403,{message:"Too many failed login attempts",code:"TOO_MANY_FAILED_LOGINS"})}if(!a.email_verified&&((h=e.client_metadata)==null?void 0:h.email_validation)==="enforced"){const b=(v=(y=(m=r==null?void 0:r.authParams)==null?void 0:m.ui_locales)==null?void 0:y.split(" "))==null?void 0:v.map(O=>O.split("-")[0])[0];await Up(t,a,b);const A=be(t,{type:_e.FAILED_LOGIN,description:"Email not verified"});throw ve(t,i.logs.create(e.tenant.id,A)),new qr(403,{message:"Email not verified",code:"EMAIL_NOT_VERIFIED"})}return{client:e,authParams:n,user:c,loginSession:r}}async function A1(t,e,n,r,i){const s=await z1(t,e,n,r),a=await Um(t,t.env.data,e.tenant.id,s.user,r,{client:e,authParams:n,authStrategy:{strategy:"Username-Password-Authentication",strategy_type:"database"}});return a instanceof Response?a:(s.user=a,un(t,{...s,ticketAuth:i,strategy:"Username-Password-Authentication"}))}async function kx(t,e,n,r){await qa(t,{client:e,username:n,provider:"auth2",connection:"Username-Password-Authentication",isSocial:!1,ip:t.var.ip});let i=Zn(),s=await t.env.data.codes.get(e.tenant.id,i,"password_reset");for(;s;)i=Zn(),s=await t.env.data.codes.get(e.tenant.id,i,"password_reset");const a=t.get("ip"),c=t.get("useragent"),l=t.get("auth0_client"),d=Nn(l),u=await t.env.data.loginSessions.create(e.tenant.id,{expires_at:new Date(Date.now()+Ev).toISOString(),authParams:{client_id:e.client_id,username:n},csrf_token:Ne(),ip:a,useragent:c,auth0Client:d}),f=await t.env.data.codes.create(e.tenant.id,{code_id:i,code_type:"password_reset",login_id:u.id,expires_at:new Date(Date.now()+Av).toISOString()});await S1(t,n,f.code_id,r)}const xx=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.union([o.z.object({credential_type:o.z.literal("http://auth0.com/oauth/grant-type/passwordless/otp"),otp:o.z.string(),client_id:o.z.string(),username:o.z.string().transform(t=>t.toLowerCase()),realm:o.z.enum(["email"]),scope:o.z.string().optional()}),o.z.object({credential_type:o.z.literal("http://auth0.com/oauth/grant-type/password-realm"),client_id:o.z.string(),username:o.z.string().transform(t=>t.toLowerCase()),password:o.z.string(),realm:o.z.enum(["Username-Password-Authentication"]),scope:o.z.string().optional()})])}}}},responses:{200:{description:"List of tenants"}}}),async t=>{const e=t.req.valid("json"),{client_id:n,username:r}=e;t.set("username",r);const i=await t.env.data.legacyClients.get(n);if(!i)throw new S(400,{message:"Client not found"});t.set("client_id",n),t.set("tenant_id",i.tenant.id);const s=r.toLocaleLowerCase(),a=t.get("ip"),c=t.get("useragent"),l=t.get("auth0_client");let d;if("otp"in e)d=await Op(t,{client_id:n,username:s,otp:e.otp});else if("password"in e){const u=await t.env.data.loginSessions.create(i.tenant.id,{expires_at:new Date(Date.now()+_r*1e3).toISOString(),authParams:{client_id:n,username:s},csrf_token:Ne(),ip:a,useragent:c,auth0Client:Nn(l)});d=await A1(t,i,{username:s,password:e.password,client_id:n},u,!0)}else throw new S(400,{message:"Code or password required"});if(!(d instanceof Response))throw new S(500,{message:"Unexpected response from loginWithPassword"});return d});function E1(t,e){var r,i,s;if(!t||e.length===0)return!1;const n=((r=hl(t))==null?void 0:r.host)??null;if(!n)return!1;for(const a of e){let c;if(a.startsWith("http://")||a.startsWith("https://")?c=((i=hl(a))==null?void 0:i.host)??null:c=((s=hl("https://"+a))==null?void 0:s.host)??null,n===c)return!0}return!1}function hl(t){try{return new URL(t)}catch{return null}}async function Sx({ctx:t,session:e,client:n,authParams:r,connection:i,login_hint:s}){const a=new URL(t.req.url);t.var.custom_domain&&(a.hostname=t.var.custom_domain);const{ip:c,auth0_client:l,useragent:d}=t.var,u=Nn(l),f=await t.env.data.loginSessions.create(n.tenant.id,{expires_at:new Date(Date.now()+_r*1e3).toISOString(),authParams:r,csrf_token:Ne(),authorization_url:a.toString(),ip:c,useragent:d,auth0Client:u});if(e&&s){const h=await t.env.data.users.get(n.tenant.id,e.user_id);if((h==null?void 0:h.email)===s)return await t.env.data.loginSessions.update(n.tenant.id,f.id,{session_id:e.id}),un(t,{client:n,loginSession:{...f,session_id:e.id},authParams:r,user:h,sessionId:e.id})}if(i==="email"&&s){const h=Zn();return await t.env.data.codes.create(n.tenant.id,{code_id:h,code_type:"otp",login_id:f.id,expires_at:new Date(Date.now()+_r*1e3).toISOString(),redirect_uri:r.redirect_uri}),await Lp(t,{code:h,to:s,authParams:r}),t.redirect(`/u/enter-code?state=${f.id}`)}return e?t.redirect(`/u/check-account?state=${f.id}`):t.redirect(`/u/login/identifier?state=${f.id}`)}function zx(t){if(t==="Username-Password-Authentication")return"auth2";if(t==="email")return"email";throw new ee(403,{message:"Invalid realm"})}async function Ax(t,e,n,r,i){var h;const{env:s}=t;t.set("connection",i);const a=await s.data.codes.get(e,n,"ticket");if(!a||a.used_at)throw new ee(403,{message:"Ticket not found"});const c=await s.data.loginSessions.get(e,a.login_id);if(!c||!c.authParams.username)throw new ee(403,{message:"Session not found"});const l=await s.data.legacyClients.get(c.authParams.client_id);if(!l)throw new ee(403,{message:"Client not found"});t.set("client_id",c.authParams.client_id),await s.data.codes.used(e,n);const d=zx(i);let u=await qa(t,{username:c.authParams.username,provider:d,client:l,connection:d==="auth2"?"Username-Password-Authentication":"email",isSocial:!1,ip:t.var.ip});t.set("username",u.email||u.phone_number),t.set("user_id",u.user_id);const f=await Pm(t,{user:u,client:l,loginSession:c});return un(t,{authParams:{scope:(h=c.authParams)==null?void 0:h.scope,...r},loginSession:c,sessionId:f.id,user:u,client:l})}async function Ex({ctx:t,client:e,session:n,redirect_uri:r,state:i,nonce:s,code_challenge_method:a,code_challenge:c,audience:l,scope:d,response_type:u,organization:f}){const{env:h}=t,m=new URL(r),y=`${m.protocol}//${m.host}`;async function v(Q="Login required"){const K=be(t,{type:_e.FAILED_SILENT_AUTH,description:Q});return ve(t,t.env.data.logs.create(e.tenant.id,K)),t.html(jl(y,JSON.stringify({error:"login_required",error_description:Q,state:i})))}if(!n||(n==null?void 0:n.expires_at)&&new Date(n.expires_at)<new Date||(n==null?void 0:n.idle_expires_at)&&new Date(n.idle_expires_at)<new Date)return v();t.set("user_id",n.user_id);const A=await h.data.users.get(e.tenant.id,n.user_id);if(!A)return console.error("User not found",n.user_id),v("User not found");t.set("username",A.email),t.set("connection",A.connection);const O=await h.data.loginSessions.create(e.tenant.id,{csrf_token:Ne(),authParams:{client_id:e.client_id,audience:l,scope:d,state:i,nonce:s,response_type:u,redirect_uri:r,organization:f},expires_at:new Date(Date.now()+5*60*1e3).toISOString(),session_id:n.id,ip:t.var.ip,useragent:t.var.useragent}),U={client:e,authParams:{client_id:e.client_id,audience:l,code_challenge_method:a,code_challenge:c,scope:d,state:i,nonce:s,response_type:u,redirect_uri:r},user:A,session_id:n.id},T=u===Nt.CODE?await Om(t,{user:A,client:e,authParams:U.authParams,login_id:O.id}):await Fa(t,U);await h.data.sessions.update(e.tenant.id,n.id,{used_at:new Date().toISOString(),last_interaction_at:new Date().toISOString(),login_session_id:O.id,device:{...n.device,last_ip:t.var.ip||"",last_user_agent:t.var.useragent||""},idle_expires_at:n.idle_expires_at?new Date(Date.now()+Da*1e3).toISOString():void 0});const R=be(t,{type:_e.SUCCESS_SILENT_AUTH,description:"Successful silent authentication"});ve(t,t.env.data.logs.create(e.tenant.id,R));const W=new Headers;W.set("Server-Timing","cf-nel=0; no-cloudflare-insights=1");const ne=Hs(e.tenant.id,n.id,t.req.header("host"));return W.set("set-cookie",ne),t.html(jl(y,JSON.stringify({...T,state:i})),{headers:W})}const Cx=["email","sms","Username-Password-Authentication"],Nx=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth"],method:"get",path:"/",request:{query:o.z.object({client_id:o.z.string(),vendor_id:o.z.string().optional(),redirect_uri:o.z.string(),scope:o.z.string().optional(),state:o.z.string(),prompt:o.z.string().optional(),response_mode:o.z.nativeEnum(Wt).optional(),response_type:o.z.nativeEnum(Nt).optional(),audience:o.z.string().optional(),connection:o.z.string().optional(),nonce:o.z.string().optional(),max_age:o.z.string().optional(),login_ticket:o.z.string().optional(),code_challenge_method:o.z.nativeEnum(Pa).optional(),code_challenge:o.z.string().optional(),realm:o.z.string().optional(),auth0Client:o.z.string().optional(),organization:o.z.string().optional(),login_hint:o.z.string().optional(),screen_hint:o.z.string().openapi({example:"signup",description:'Optional hint for the screen to show, like "signup" or "login".'}).optional(),ui_locales:o.z.string().optional()})},responses:{200:{description:"Successful authorization response. This can be an HTML page (e.g., for silent authentication iframe or universal login page) or a JSON object containing tokens (e.g., for response_mode=web_message).",content:{"text/html":{schema:o.z.string().openapi({example:"<html>...</html>"})},"application/json":{schema:bu}}},302:{description:"Redirect to the client's redirect URI, an authentication page, or an external identity provider.",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request. Invalid parameters or other client-side errors.",content:{"application/json":{schema:o.z.object({message:o.z.string()})}}},403:{description:"Forbidden. The request is not allowed (e.g., invalid origin).",content:{"application/json":{schema:o.z.object({message:o.z.string()})}}}}}),async t=>{const{env:e}=t,{client_id:n,vendor_id:r,redirect_uri:i,scope:s,state:a,audience:c,nonce:l,connection:d,response_type:u,response_mode:f,code_challenge:h,code_challenge_method:m,prompt:y,login_ticket:v,realm:b,auth0Client:A,login_hint:O,ui_locales:U,organization:T}=t.req.valid("query");t.set("log","authorize");const R=await Oi(e,n);t.set("client_id",R.client_id),t.set("tenant_id",R.tenant.id);const W={redirect_uri:i.split("#")[0],scope:s,state:a,client_id:n,vendor_id:r,audience:c,nonce:l,prompt:y,response_type:u,response_mode:f,code_challenge:h,code_challenge_method:m,username:O,ui_locales:U,organization:T},ne=t.req.header("origin");if(ne&&!E1(ne,R.web_origins||[]))throw new S(403,{message:`Origin ${ne} not allowed`});if(W.redirect_uri){const C=R.callbacks||[];if(t.var.host&&(C.push(`${Bc(t.env)}/*`),C.push(`${st(t.env)}/*`)),!zp(W.redirect_uri,C,{allowPathWildcards:!0,allowSubDomainWildcards:!0}))throw new S(400,{message:`Invalid redirect URI - ${W.redirect_uri}`})}const Q=ni(R.tenant.id,t.req.header("cookie")),K=Q?await e.data.sessions.get(R.tenant.id,Q):void 0,de=K&&!K.revoked_at?K:void 0;if(y=="none"){if(!u)throw new S(400,{message:"Missing response_type"});return Ex({ctx:t,session:de||void 0,redirect_uri:i,state:a,response_type:u,client:R,nonce:l,code_challenge_method:m,code_challenge:h,audience:c,scope:s,organization:T})}if(R.connections.length===1&&R.connections[0]&&!Cx.includes(R.connections[0].strategy||""))return fg(t,R,R.connections[0].name,W);if(d&&d!=="email")return fg(t,R,d,W);if(v){const C=await Ax(t,R.tenant.id,v,W,b);return C instanceof Response?C:t.json(C)}const N=await Sx({ctx:t,client:R,auth0Client:A,authParams:W,session:de||void 0,connection:d,login_hint:O});return N instanceof Response?N:t.json(N)}),Ix=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth"],method:"get",path:"/",request:{query:o.z.object({client_id:o.z.string(),redirect_url:o.z.string().optional(),login_hint:o.z.string().toLowerCase().optional(),screen_hint:o.z.enum(["account","change-email","change-phone","change-password"]).optional().default("account")})},responses:{302:{description:"Redirect to the account page with login session state or login page",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request. Invalid parameters or other client-side errors.",content:{"application/json":{schema:o.z.object({message:o.z.string()})}}}}}),async t=>{const{env:e}=t,{client_id:n,redirect_url:r,login_hint:i,screen_hint:s}=t.req.valid("query");t.set("log","account");const a=await Oi(e,n);t.set("client_id",a.client_id),t.set("tenant_id",a.tenant.id);const c={redirect_uri:r||t.req.url,client_id:n,username:i},l=t.req.header("origin");if(l&&!E1(l,a.web_origins||[]))throw new S(403,{message:`Origin ${l} not allowed`});if(c.redirect_uri){const O=a.callbacks||[];if(t.var.host&&(O.push(`${Bc(t.env)}/*`),O.push(`${st(t.env)}/*`)),!zp(c.redirect_uri,O,{allowPathWildcards:!0,allowSubDomainWildcards:!0}))throw new S(400,{message:`Invalid redirect URI - ${c.redirect_uri}`})}const d=ni(a.tenant.id,t.req.header("cookie")),u=d?await e.data.sessions.get(a.tenant.id,d):void 0,f=u&&!u.revoked_at?u:void 0,h=new URL(t.req.url);t.var.custom_domain&&(h.hostname=t.var.custom_domain);const{ip:m,auth0_client:y,useragent:v}=t.var,b=Nn(y),A=await e.data.loginSessions.create(a.tenant.id,{expires_at:new Date(Date.now()+_r*1e3).toISOString(),authParams:c,csrf_token:Ne(),authorization_url:h.toString(),ip:m,useragent:v,auth0Client:b});if(f){if(i){const U=await e.data.users.get(a.tenant.id,f.user_id);if((U==null?void 0:U.email)!==i)return t.redirect(`${st(t.env)}login/identifier?state=${encodeURIComponent(A.id)}`)}if(await e.data.loginSessions.update(a.tenant.id,A.id,{session_id:f.id}),s==="change-email"){const U=new URL("/u/account/change-email",t.req.url);return U.searchParams.set("state",A.id),t.redirect(U.toString())}const O=new URL("/u/account",t.req.url);return O.searchParams.set("state",A.id),t.redirect(O.toString())}return t.redirect(`${st(t.env)}login/identifier?state=${encodeURIComponent(A.id)}`)});function jx(t){const e=new o.OpenAPIHono;e.use(async(r,i)=>{const s=xo(r,t.dataAdapter),a=t.dataAdapter.cache||Ho({defaultTtlSeconds:0,maxEntries:100,cleanupIntervalMs:0}),c=t.dataAdapter.cache?300:0,l=Dc(s,{defaultTtl:c,cacheEntities:["tenants","connections","customDomains","clients","legacyClients","branding","themes","promptSettings","forms","resourceServers","roles","organizations","userRoles","userPermissions"],cache:a});return r.env.data=Rc(r,l),i()}),e.use("/oauth/token",g0({origin:r=>r||"",allowHeaders:["Tenant-Id","Content-Type","Auth0-Client","Upgrade-Insecure-Requests"],allowMethods:["POST"],maxAge:600})),e.use(Uc).use(Lc).use(wp(e));const n=e.route("/v2/logout",e5).route("/userinfo",t5).route("/.well-known",n5).route("/oauth/token",yx).route("/dbconnections",bx).route("/passwordless",$x).route("/co/authenticate",xx).route("/authorize",Nx).route("/account",Ix).route("/callback",Yk);return n.doc("/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"Oauth API"},security:[{oauth2:["openid","email","profile"]}]}),yp(n),n}async function Ce(t,e,n=!1){var h,m,y,v,b;const{env:r}=t,i=await r.data.loginSessions.get(t.var.tenant_id||"",e);if(!i)throw new ee(400,{message:"Login session not found"});t.set("loginSession",i);const s=await Oi(r,i.authParams.client_id);t.set("client_id",s.client_id),t.set("tenant_id",s.tenant.id);let a;try{a=H$(t,"auth_ui_style")}catch{a=void 0}let c=!1;(h=t.req)!=null&&h.url&&(c=(new URL(t.req.url).searchParams.get("style")||a||"classic")==="shadcn");const l=await r.data.tenants.get(s.tenant.id);if(l){if(i.session_id&&!n){if(!i.authParams.redirect_uri)throw new ee(400,{message:"Login session closed and no redirect URI available"});const A=new URL(i.authParams.redirect_uri);throw A.searchParams.set("error","access_denied"),A.searchParams.set("error_description","Login session closed"),i.authParams.state&&A.searchParams.set("state",i.authParams.state),new Ir(A.toString(),302)}}else throw new ee(400,{message:"Tenant not found"});const d=await r.data.themes.get(l.id,"default"),u=await r.data.branding.get(l.id),f=(b=(v=(y=(m=i.authParams)==null?void 0:m.ui_locales)==null?void 0:y.split(" "))==null?void 0:v.map(A=>A.split("-")[0]))==null?void 0:b.find(A=>{if(Array.isArray(w.options.supportedLngs))return w.options.supportedLngs.includes(A)});return await w.changeLanguage(f||"sv"),{theme:d,branding:u,client:s,tenant:l,loginSession:i,useShadcn:c}}async function jr(t,e){const{theme:n,branding:r,client:i,tenant:s,loginSession:a,useShadcn:c}=await Ce(t,e,!0),l=ni(i.tenant.id,t.req.header("cookie")),d=l?await t.env.data.sessions.get(i.tenant.id,l):null;if(!d||!a.session_id)throw new Ir(`/u/login/identifier?state=${encodeURIComponent(e)}`);const u=await t.env.data.sessions.get(i.tenant.id,a.session_id),f=await t.env.data.users.get(i.tenant.id,d.user_id);if(!f||(u==null?void 0:u.user_id)!==d.user_id)throw new Ir(`/u/login/identifier?state=${encodeURIComponent(e)}`);return{theme:n,branding:r,client:i,user:f,tenant:s,loginSession:a,session:u,useShadcn:c}}async function Ox(t,e,n,r){if(r!==void 0)return r==="password";const i=await Cu({userAdapter:t.env.data.users,tenant_id:e.tenant.id,email:n});return i!=null&&i.app_metadata.strategy?i.app_metadata.strategy==="Username-Password-Authentication":(await t.env.data.promptSettings.get(e.tenant.id)).password_first}var C1={exports:{}};/*!
198
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function C6(t,e){if(t){if(typeof t=="string")return Ig(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set")return Array.from(t);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Ig(t,e)}}function Ig(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function N6(t,e){var n=e.countries,r=e.metadata;r=new vt(r);for(var i=E6(n),s;!(s=i()).done;){var a=s.value;if(r.country(a),r.leadingDigits()){if(t&&t.search(r.leadingDigits())===0)return a}else if(Cp({phone:t,country:a},void 0,r.metadata))return a}}function I6(t,e){var n=e.nationalNumber,r=e.defaultCountry,i=e.metadata,s=i.getCountryCodesForCallingCode(t);if(s)return s.length===1?s[0]:N6(n,{countries:s,defaultCountry:r,metadata:i.metadata})}var b1="+",j6="[\\-\\.\\(\\)]?",jg="(["+Qt+"]|"+j6+")",O6="^\\"+b1+jg+"*["+Qt+"]"+jg+"*$",T6=new RegExp(O6,"g"),su=Qt,P6="["+su+"]+((\\-)*["+su+"])*",R6="a-zA-Z",B6="["+R6+"]+((\\-)*["+su+"])*",L6="^("+P6+"\\.)*"+B6+"\\.?$",U6=new RegExp(L6,"g"),Og="tel:",au=";phone-context=",D6=";isub=";function M6(t){var e=t.indexOf(au);if(e<0)return null;var n=e+au.length;if(n>=t.length)return"";var r=t.indexOf(";",n);return r>=0?t.substring(n,r):t.substring(n)}function F6(t){return t===null?!0:t.length===0?!1:T6.test(t)||U6.test(t)}function q6(t,e){var n=e.extractFormattedPhoneNumber,r=M6(t);if(!F6(r))throw new $n("NOT_A_NUMBER");var i;if(r===null)i=n(t)||"";else{i="",r.charAt(0)===b1&&(i+=r);var s=t.indexOf(Og),a;s>=0?a=s+Og.length:a=0;var c=t.indexOf(au);i+=t.substring(a,c)}var l=i.indexOf(D6);if(l>0&&(i=i.substring(0,l)),i!=="")return i}var H6=250,V6=new RegExp("["+Ip+Qt+"]"),K6=new RegExp("[^"+Qt+"#]+$");function G6(t,e,n){if(e=e||{},n=new vt(n),e.defaultCountry&&!n.hasCountry(e.defaultCountry))throw e.v2?new $n("INVALID_COUNTRY"):new Error("Unknown country: ".concat(e.defaultCountry));var r=J6(t,e.v2,e.extract),i=r.number,s=r.ext,a=r.error;if(!i){if(e.v2)throw a==="TOO_SHORT"?new $n("TOO_SHORT"):new $n("NOT_A_NUMBER");return{}}var c=Z6(i,e.defaultCountry,e.defaultCallingCode,n),l=c.country,d=c.nationalNumber,u=c.countryCallingCode,f=c.countryCallingCodeSource,h=c.carrierCode;if(!n.hasSelectedNumberingPlan()){if(e.v2)throw new $n("INVALID_COUNTRY");return{}}if(!d||d.length<Np){if(e.v2)throw new $n("TOO_SHORT");return{}}if(d.length>E5){if(e.v2)throw new $n("TOO_LONG");return{}}if(e.v2){var m=new p6(u,d,n.metadata);return l&&(m.country=l),h&&(m.carrierCode=h),s&&(m.ext=s),m.__countryCallingCodeSource=f,m}var y=(e.extended?n.hasSelectedNumberingPlan():l)?In(d,n.nationalNumberPattern()):!1;return e.extended?{country:l,countryCallingCode:u,carrierCode:h,valid:y,possible:y?!0:!!(e.extended===!0&&n.possibleLengths()&&m1(d,n)),phone:d,ext:s}:y?X6(l,d,s):{}}function W6(t,e,n){if(t){if(t.length>H6){if(n)throw new $n("TOO_LONG");return}if(e===!1)return t;var r=t.search(V6);if(!(r<0))return t.slice(r).replace(K6,"")}}function J6(t,e,n){var r=q6(t,{extractFormattedPhoneNumber:function(a){return W6(a,n,e)}});if(!r)return{};if(!Q5(r))return e6(r)?{error:"TOO_SHORT"}:{};var i=$6(r);return i.ext?i:{number:r}}function X6(t,e,n){var r={country:t,phone:e};return n&&(r.ext=n),r}function Z6(t,e,n,r){var i=_1(Ng(t),e,n,r.metadata),s=i.countryCallingCodeSource,a=i.countryCallingCode,c=i.number,l;if(a)r.selectNumberingPlan(a);else if(c&&(e||n))r.selectNumberingPlan(e,n),e&&(l=e),a=n||Ap(e,r.metadata);else return{};if(!c)return{countryCallingCodeSource:s,countryCallingCode:a};var d=ru(Ng(c),r),u=d.nationalNumber,f=d.carrierCode,h=I6(a,{nationalNumber:u,defaultCountry:e,metadata:r});return h&&(l=h,h==="001"||r.country(l)),{country:l,countryCallingCode:a,countryCallingCodeSource:s,nationalNumber:u,carrierCode:f}}function Tg(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function Pg(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?Tg(Object(n),!0).forEach(function(r){Y6(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Tg(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function Y6(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Q6(t,e,n){return G6(t,Pg(Pg({},e),{},{v2:!0}),n)}function Rg(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function ex(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?Rg(Object(n),!0).forEach(function(r){tx(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Rg(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function tx(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function nx(t,e){return sx(t)||ox(t,e)||ix(t,e)||rx()}function rx(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
199
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ix(t,e){if(t){if(typeof t=="string")return Bg(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set")return Array.from(t);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Bg(t,e)}}function Bg(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function ox(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var r=[],i=!0,s=!1,a,c;try{for(n=n.call(t);!(i=(a=n.next()).done)&&(r.push(a.value),!(e&&r.length===e));i=!0);}catch(l){s=!0,c=l}finally{try{!i&&n.return!=null&&n.return()}finally{if(s)throw c}}return r}}function sx(t){if(Array.isArray(t))return t}function ax(t){var e=Array.prototype.slice.call(t),n=nx(e,4),r=n[0],i=n[1],s=n[2],a=n[3],c,l,d;if(typeof r=="string")c=r;else throw new TypeError("A text for parsing must be a string.");if(!i||typeof i=="string")a?(l=s,d=a):(l=void 0,d=s),i&&(l=ex({defaultCountry:i},l));else if(Qr(i))s?(l=i,d=s):d=i;else throw new Error("Invalid second argument: ".concat(i));return{text:c,options:l,metadata:d}}function Lg(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function Ug(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?Lg(Object(n),!0).forEach(function(r){cx(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Lg(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function cx(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function lx(t,e,n){e&&e.defaultCountry&&!w5(e.defaultCountry,n)&&(e=Ug(Ug({},e),{},{defaultCountry:void 0}));try{return Q6(t,e,n)}catch(r){if(!(r instanceof $n))throw r}}function dx(){var t=ax(arguments),e=t.text,n=t.options,r=t.metadata;return lx(e,n,r)}function ux(){return l5(dx,arguments)}function Vc(t,e="US"){const n=t.trim();if(n.includes("@")){const r=n.toLowerCase(),i=/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r);return{connectionType:"email",normalized:i?r:null,isValid:i}}else if(/^\+?\d[\d\s\-().]*$/.test(n)){const r=ux(n,{defaultCountry:e});return r&&r.isValid()?{connectionType:"sms",normalized:r.number,isValid:!0}:{connectionType:"sms",normalized:null,isValid:!1}}else return{connectionType:"username",normalized:n,isValid:!0}}function jp(t){let e=t.trim();e.startsWith("[")&&e.endsWith("]")&&(e=e.slice(1,-1));const n=e.indexOf("%");return n!==-1&&(e=e.slice(0,n)),e}function px(t){const n=jp(t).split(".");return n.length!==4?!1:n.every(r=>/^\d+$/.test(r)&&Number(r)>=0&&Number(r)<=255)}function fx(t){const e=jp(t);if(e.length<2||e.indexOf(":")===-1||!/^[0-9a-fA-F:.]+$/.test(e))return!1;const n=e.split(":");return e.includes("::")?n.length<=8:n.length===8}function hx(t){let e=t.trim();const n=/^\[([^\]]+)\](?::\d+)?$/,r=e.match(n);if(r&&r[1])return r[1];const i=e.lastIndexOf(":");if(i!==-1){const s=e.slice(0,i),a=e.slice(i+1);/^[0-9.]+$/.test(s)&&/^\d+$/.test(a)&&(e=s)}return e}function Dg(t){if(!t)return null;const e=jp(hx(t));return px(e)?{family:4,normalized:e}:fx(e)?{family:6,normalized:e.toLowerCase()}:null}function Mg(t){if(t.includes("::")){let[e,n]=t.split("::"),r=e?e.split(":").filter(Boolean):[],i=n?n.split(":").filter(Boolean):[],s=8-(r.length+i.length);return[...r.map(a=>a.toLowerCase()||"0"),...Array(s).fill("0"),...i.map(a=>a.toLowerCase()||"0")]}else return t.split(":").map(e=>e.toLowerCase()||"0")}function gx(t,e,n=!0){const r=Dg(t),i=Dg(e);if(!r||!i||r.family!==i.family)return!1;if(r.family===4)return r.normalized===i.normalized;const s=Mg(r.normalized),a=Mg(i.normalized);return n?s.length===8&&a.length===8&&s.join(":")===a.join(":"):s.slice(0,4).join(":")===a.slice(0,4).join(":")}class Ir extends Error{constructor(n,r=302){super(`Redirect to ${n}`);ae(this,"location");ae(this,"status");this.name=Ir.name,this.location=n,this.status=r}}const mx=o.z.object({client_id:o.z.string(),username:o.z.string().transform(t=>t.toLowerCase()),otp:o.z.string(),authParams:ro.optional(),enforceIpCheck:o.z.boolean().optional().default(!1)});async function $1(t,{client_id:e,username:n,otp:r,authParams:i,enforceIpCheck:s=!1}){const a=t.get("ip"),c=t.get("countryCode"),{connectionType:l,normalized:d}=Vc(n,c);if(!d)throw new ee(400,{message:"Invalid username format"});const u=await t.env.data.legacyClients.get(e);if(!u)throw new ee(403,{message:"Client not found"});const{env:f}=t,h=await f.data.codes.get(u.tenant.id,r,"otp");if(!h)throw new ee(400,{message:pe("code_invalid")});if(h.expires_at<new Date().toISOString())throw new ee(400,{message:pe("code_expired")});if(h.used_at)throw new ee(400,{message:pe("code_used")});const m=await f.data.loginSessions.get(u.tenant.id,h.login_id);if(!m||m.authParams.username!==n)throw new ee(400,{message:"Code not found or expired"});if(s&&m.ip&&a&&!gx(m.ip,a))throw new Ir(`${st(t.env)}invalid-session?state=${m.id}`);const y=await qa(t,{client:u,username:d,provider:l,connection:l,isSocial:!1,ip:t.var.ip});return await f.data.codes.used(u.tenant.id,r),{user:y,client:u,loginSession:m,session_id:m.session_id,authParams:{...m.authParams,...i||{}}}}async function Op(t,e){const n=await $1(t,e);return un(t,{authParams:n.authParams,client:n.client,user:n.user,loginSession:n.loginSession,strategy:"email"})}const Fg=o.z.object({client_id:o.z.string().optional(),client_secret:o.z.string().optional()}),qg=o.z.union([f1.extend(Fg.shape),o.z.object({grant_type:o.z.literal("authorization_code"),client_id:o.z.string(),code:o.z.string(),redirect_uri:o.z.string(),code_verifier:o.z.string().min(43).max(128),organization:o.z.string().optional()}),o.z.object({grant_type:o.z.literal("authorization_code"),code:o.z.string(),redirect_uri:o.z.string().optional(),organization:o.z.string().optional(),...Fg.shape}),o.z.object({grant_type:o.z.literal("refresh_token"),client_id:o.z.string(),refresh_token:o.z.string(),redirect_uri:o.z.string().optional()}),o.z.object({grant_type:o.z.literal("http://auth0.com/oauth/grant-type/passwordless/otp"),client_id:o.z.string(),username:o.z.string(),otp:o.z.string(),realm:o.z.enum(["email","sms"])})]);function _x(t){if(!t)return{};const[e,n]=t.split(" ");if((e==null?void 0:e.toLowerCase())==="basic"&&n){const[r,i]=atob(n).split(":");return{client_id:r,client_secret:i}}return{}}const yx=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth2"],method:"post",path:"/",request:{body:{content:{"application/x-www-form-urlencoded":{schema:qg},"application/json":{schema:qg}}}},responses:{200:{content:{"application/json":{schema:bu}},description:"Tokens"},302:{description:"Redirect for further user interaction (e.g., MFA, consent).",headers:o.z.object({Location:o.z.string().url()}).openapi({})},400:{description:"Bad Request - The request was malformed or invalid.",content:{"application/json":{schema:o.z.object({error:o.z.string(),error_description:o.z.string().optional()})}}},401:{description:"Unauthorized - Client authentication failed.",content:{"application/json":{schema:o.z.object({error:o.z.string(),error_description:o.z.string().optional()})}}},403:{description:"Forbidden - User is not a member of the required organization.",content:{"application/json":{schema:o.z.object({error:o.z.string(),error_description:o.z.string().optional()})}}}}}),async t=>{var d,u,f,h,m;const n=(t.req.header("Content-Type")||"").includes("application/json")?t.req.valid("json"):t.req.valid("form"),r=_x(t.req.header("Authorization")),i={...n,...r};if(!i.client_id)throw new S(400,{message:"client_id is required"});t.set("client_id",i.client_id);let s;switch(n.grant_type){case Vt.AuthorizationCode:s=await o5(t,i5.parse(i));break;case Vt.ClientCredential:s=await r5(t,f1.parse(i));break;case Vt.RefreshToken:s=await a5(t,s5.parse(i));break;case Vt.OTP:s=await $1(t,mx.parse(i));break;default:return t.json({error:"unsupported_grant_type",error_description:"Grant type not implemented"},400)}const a=new Headers;if(s.session_id){const y=Hs(s.client.tenant.id,s.session_id,t.var.host||"");a.set("Set-Cookie",y)}let c=[];if(s.authParams.audience)try{let y;if(n.grant_type===Vt.ClientCredential)y=await Vs(t,{grantType:Vt.ClientCredential,tenantId:s.client.tenant.id,clientId:s.client.client_id,audience:s.authParams.audience,requestedScopes:((d=s.authParams.scope)==null?void 0:d.split(" "))||[],organizationId:(u=s.organization)==null?void 0:u.id});else{if(!((f=s.user)!=null&&f.user_id))throw new ee(400,{error:"invalid_request",error_description:"User ID is required for user-based grants"});y=await Vs(t,{grantType:n.grant_type,tenantId:s.client.tenant.id,userId:s.user.user_id,clientId:s.client.client_id,audience:s.authParams.audience,requestedScopes:((h=s.authParams.scope)==null?void 0:h.split(" "))||[],organizationId:(m=s.organization)==null?void 0:m.id})}s.authParams.scope=y.scopes.join(" "),c=y.permissions}catch(y){if(y instanceof S)throw y;console.error("Error calculating scopes and permissions:",y)}const l=await Fa(t,{...s,grantType:n.grant_type,permissions:c.length>0?c:void 0});return t.json(l,{headers:a})});var Tp={exports:{}};const Pp=[{id:0,value:"Too weak",minDiversity:0,minLength:0},{id:1,value:"Weak",minDiversity:2,minLength:6},{id:2,value:"Medium",minDiversity:4,minLength:8},{id:3,value:"Strong",minDiversity:4,minLength:10}],k1=(t,e=Pp,n="!\"#$%&'()*+,-./:;<=>?@[\\\\\\]^_`{|}~")=>{let r=t||"";e[0].minDiversity=0,e[0].minLength=0;const i=[{regex:"[a-z]",message:"lowercase"},{regex:"[A-Z]",message:"uppercase"},{regex:"[0-9]",message:"number"}];n&&i.push({regex:`[${n}]`,message:"symbol"});let s={};s.contains=i.filter(c=>new RegExp(`${c.regex}`).test(r)).map(c=>c.message),s.length=r.length;let a=e.filter(c=>s.contains.length>=c.minDiversity).filter(c=>s.length>=c.minLength).sort((c,l)=>l.id-c.id).map(c=>({id:c.id,value:c.value}));return Object.assign(s,a[0]),s};Tp.exports={passwordStrength:k1,defaultOptions:Pp};var wx=Tp.exports.passwordStrength=k1;Tp.exports.defaultOptions=Pp;function Rp(t){return wx(t).id<2?!1:t.length>=8&&/[a-z]/.test(t)&&/[A-Z]/.test(t)&&/[0-9]/.test(t)&&/[^A-Za-z0-9]/.test(t)}async function Jo(t,e){var i;const n=await t.env.data.emailProviders.get(t.var.tenant_id)||(t.env.DEFAULT_TENANT_ID?await t.env.data.emailProviders.get(t.env.DEFAULT_TENANT_ID):null);if(!n)throw new S(500,{message:"Email provider not found"});const r=(i=t.env.emailProviders)==null?void 0:i[n.name];if(!r)throw new S(500,{message:"Email provider not found"});await r({emailProvider:n,...e,from:n.default_from_address||`login@${t.env.ISSUER}`})}async function x1(t,e){var a,c;if(!t.var.client_id)throw new S(500,{message:"Client not found"});const n=await Oi(t.env,t.var.client_id),r=n.connections.find(l=>l.strategy==="sms");if(!r)throw new S(500,{message:"SMS provider not found"});const i=((a=r.options)==null?void 0:a.provider)||"twilio",s=(c=t.env.smsProviders)==null?void 0:c[i];if(!s)throw new S(500,{message:"SMS provider not found"});await s({options:r.options,to:e.to,from:e.from,text:e.text,template:"auth-code",data:{code:e.code,tenantName:n.tenant.friendly_name,tenantId:n.tenant.id}})}async function S1(t,e,n,r,i){var f;const s=await t.env.data.tenants.get(t.var.tenant_id);if(!s)throw new S(500,{message:"Tenant not found"});const a=`${st(t.env)}reset-password?state=${r}&code=${n}`,c=await t.env.data.branding.get(t.var.tenant_id),l=(c==null?void 0:c.logo_url)||"",d=((f=c==null?void 0:c.colors)==null?void 0:f.primary)||"#7d68f4",u={vendorName:s.friendly_name,lng:"en"};await Jo(t,{to:e,subject:pe("reset_password_title",u),html:`Click here to reset your password: ${st(t.env)}reset-password?state=${r}&code=${n}`,template:"auth-password-reset",data:{vendorName:s.friendly_name,logo:l,passwordResetUrl:a,supportUrl:s.support_url||"https://support.sesamy.com",buttonColor:d,passwordResetTitle:pe("password_reset_title",u),resetPasswordEmailClickToReset:pe("reset_password_email_click_to_reset",u),resetPasswordEmailReset:pe("reset_password_email_reset",u),supportInfo:pe("support_info",u),contactUs:pe("contact_us",u),copyright:pe("copyright",u),tenantName:s.friendly_name,tenantId:s.id}})}async function Bp(t,{to:e,code:n,language:r}){var h;const i=await t.env.data.tenants.get(t.var.tenant_id);if(!i)throw new S(500,{message:"Tenant not found"});const{connectionType:s}=Vc(e),a=await t.env.data.branding.get(t.var.tenant_id),c=(a==null?void 0:a.logo_url)||"",l=((h=a==null?void 0:a.colors)==null?void 0:h.primary)||"#7d68f4",d=new URL(st(t.env)),u={vendorName:i.friendly_name,vendorId:i.id,loginDomain:d.hostname,code:n,lng:r||"en"};s==="email"?await Jo(t,{to:e,subject:pe("code_email_subject",u),html:`Click here to validate your email: ${st(t.env)}validate-email`,template:"auth-code",data:{code:n,vendorName:i.friendly_name,logo:c,supportUrl:i.support_url||"",buttonColor:l,welcomeToYourAccount:pe("welcome_to_your_account",u),linkEmailClickToLogin:pe("link_email_click_to_login",u),linkEmailLogin:pe("link_email_login",u),linkEmailOrEnterCode:pe("link_email_or_enter_code",u),codeValid30Mins:pe("code_valid_30_minutes",u),supportInfo:pe("support_info",u),contactUs:pe("contact_us",u),copyright:pe("copyright",u)}}):s==="sms"&&await x1(t,{to:e,text:pe("sms_code_text",u),code:n,from:i.friendly_name});const f=be(t,{type:_e.CODE_LINK_SENT,description:e});ve(t,t.env.data.logs.create(i.id,f))}async function Lp(t,{to:e,code:n,authParams:r,language:i}){var m;const s=await t.env.data.tenants.get(t.var.tenant_id);if(!s)throw new S(500,{message:"Tenant not found"});if(!r.redirect_uri)throw new S(400,{message:"redirect_uri is required"});const{connectionType:a}=Vc(e),c=await t.env.data.branding.get(t.var.tenant_id),l=(c==null?void 0:c.logo_url)||"",d=((m=c==null?void 0:c.colors)==null?void 0:m.primary)||"",u=new URL(He(t.env));u.pathname="passwordless/verify_redirect",u.searchParams.set("verification_code",n),u.searchParams.set("connection",a),u.searchParams.set("client_id",r.client_id),u.searchParams.set("redirect_uri",r.redirect_uri),u.searchParams.set("email",e),r.response_type&&u.searchParams.set("response_type",r.response_type),r.scope&&u.searchParams.set("scope",r.scope),r.state&&u.searchParams.set("state",r.state),r.nonce&&u.searchParams.set("nonce",r.nonce),r.code_challenge&&u.searchParams.set("code_challenge",r.code_challenge),r.code_challenge_method&&u.searchParams.set("code_challenge_method",r.code_challenge_method),r.audience&&u.searchParams.set("audience",r.audience);const f={vendorName:s.friendly_name,code:n,lng:i||"en"};if(a==="email")await Jo(t,{to:e,subject:pe("code_email_subject",f),html:`Click here to validate your email: ${st(t.env)}validate-email`,template:"auth-link",data:{code:n,vendorName:s.friendly_name,logo:l,supportUrl:s.support_url||"",magicLink:u.toString(),buttonColor:d,welcomeToYourAccount:pe("welcome_to_your_account",f),linkEmailClickToLogin:pe("link_email_click_to_login",f),linkEmailLogin:pe("link_email_login",f),linkEmailOrEnterCode:pe("link_email_or_enter_code",f),codeValid30Mins:pe("code_valid_30_minutes",f),supportInfo:pe("support_info",f),contactUs:pe("contact_us",f),copyright:pe("copyright",f)}});else if(a==="sms")await x1(t,{to:e,text:`${pe("link_sms_login",f)}: ${u.toString()}`,code:n,from:s.friendly_name});else throw new S(400,{message:"Only email and SMS connections are supported for magic links"});const h=be(t,{type:_e.CODE_LINK_SENT,description:e});ve(t,t.env.data.logs.create(s.id,h))}async function Up(t,e,n){var l;const r=await t.env.data.tenants.get(t.var.tenant_id);if(!r)throw new S(500,{message:"Tenant not found"});if(!e.email)throw new S(400,{message:"User has no email"});const i=await t.env.data.branding.get(t.var.tenant_id),s=(i==null?void 0:i.logo_url)||"",a=((l=i==null?void 0:i.colors)==null?void 0:l.primary)||"#7d68f4",c={vendorName:r.friendly_name,lng:n||"en"};await Jo(t,{to:e.email,subject:pe("welcome_to_your_account",c),html:`Click here to validate your email: ${st(t.env)}validate-email`,template:"auth-verify-email",data:{vendorName:r.friendly_name,logo:s,emailValidationUrl:`${st(t.env)}validate-email`,supportUrl:r.support_url||"https://support.sesamy.com",buttonColor:a,welcomeToYourAccount:pe("welcome_to_your_account",c),verifyEmailVerify:pe("verify_email_verify",c),supportInfo:pe("support_info",c),contactUs:pe("contact_us",c),copyright:pe("copyright",c)}})}async function vx(t,e,n,r,i){var f;const s=await t.env.data.tenants.get(t.var.tenant_id);if(!s)throw new S(500,{message:"Tenant not found"});const a=await t.env.data.branding.get(t.var.tenant_id),c=(a==null?void 0:a.logo_url)||"",l=((f=a==null?void 0:a.colors)==null?void 0:f.primary)||"#7d68f4",d={vendorName:s.friendly_name,lng:"en"},u=`${st(t.env)}signup?state=${r}&code=${n}`;await Jo(t,{to:e,subject:pe("register_password_account",d),html:`Click here to register: ${u}`,template:"auth-pre-signup-verification",data:{vendorName:s.friendly_name,logo:c,signupUrl:u,setPassword:pe("set_password",d),registerPasswordAccount:pe("register_password_account",d),clickToSignUpDescription:pe("click_to_sign_up_description",d),supportUrl:s.support_url||"https://support.sesamy.com",buttonColor:l,welcomeToYourAccount:pe("welcome_to_your_account",d),verifyEmailVerify:pe("verify_email_verify",d),supportInfo:pe("support_info",d),contactUs:pe("contact_us",d),copyright:pe("copyright",d)}})}const bx=new o.OpenAPIHono().openapi(o.createRoute({tags:["dbconnections"],method:"post",path:"/signup",request:{body:{content:{"application/json":{schema:o.z.object({client_id:o.z.string(),connection:o.z.literal("Username-Password-Authentication"),email:o.z.string().transform(t=>t.toLowerCase()),password:o.z.string()})}}}},responses:{200:{content:{"application/json":{schema:o.z.object({_id:o.z.string(),email:o.z.string().optional(),email_verified:o.z.boolean(),app_metadata:o.z.object({}),user_metadata:o.z.object({})})}},description:"Created user"}}}),async t=>{const{email:e,password:n,client_id:r}=t.req.valid("json"),i=await t.env.data.legacyClients.get(r);if(!i)throw new S(400,{message:"Client not found"});if(t.set("client_id",i.client_id),t.set("tenant_id",i.tenant.id),!Rp(n))throw new S(400,{message:"Password does not meet the requirements"});if(await io({userAdapter:t.env.data.users,tenant_id:i.tenant.id,username:e,provider:"auth2"}))throw new S(400,{message:"Invalid sign up"});const a=await t.env.data.users.create(i.tenant.id,{user_id:`auth2|${La()}`,email:e,email_verified:!1,provider:"auth2",connection:"Username-Password-Authentication",is_social:!1});t.set("user_id",a.user_id),t.set("username",a.email),t.set("connection",a.connection);const c=await ti.hash(n,10);await t.env.data.passwords.create(i.tenant.id,{user_id:a.user_id,password:c,algorithm:"bcrypt"}),await Up(t,a);const l=be(t,{type:_e.SUCCESS_SIGNUP,description:"Successful signup"});return ve(t,t.env.data.logs.create(i.tenant.id,l)),t.json({_id:a.user_id,email:a.email,email_verified:!1,app_metadata:{},user_metadata:{}})}).openapi(o.createRoute({tags:["dbconnections"],method:"post",path:"/change_password",request:{body:{content:{"application/json":{schema:o.z.object({client_id:o.z.string(),connection:o.z.literal("Username-Password-Authentication"),email:o.z.string().transform(t=>t.toLowerCase())})}}}},responses:{200:{description:"Redirect to the client's redirect uri"}}}),async t=>{const{email:e,client_id:n}=t.req.valid("json"),r=await t.env.data.legacyClients.get(n);if(!r)throw new S(400,{message:"Client not found"});if(t.set("client_id",r.client_id),t.set("tenant_id",r.tenant.id),!await vi({userAdapter:t.env.data.users,tenant_id:r.tenant.id,username:e,provider:"auth2"}))return t.html("If an account with that email exists, we've sent instructions to reset your password.");const s={client_id:n,username:e},a=await t.env.data.loginSessions.create(r.tenant.id,{expires_at:new Date(Date.now()+_r*1e3).toISOString(),authParams:s,csrf_token:Ne(),ip:t.get("ip"),useragent:t.get("useragent"),auth0Client:Nn(t.get("auth0_client"))});return await S1(t,e,a.id,a.authParams.state),t.html("If an account with that email exists, we've sent instructions to reset your password.")});function Zn(){const t="1234567890";let e="";for(let n=0;n<6;n+=1)e+=t[Math.floor(Math.random()*10)];return e.toString()}const $x=new o.OpenAPIHono().openapi(o.createRoute({tags:["passwordless"],method:"post",path:"/start",request:{body:{content:{"application/json":{schema:o.z.union([o.z.object({connection:o.z.literal("email"),client_id:o.z.string(),email:o.z.string().transform(t=>t.toLowerCase()),send:o.z.enum(["link","code"]),authParams:ro.omit({client_id:!0})}),o.z.object({client_id:o.z.string(),connection:o.z.literal("sms"),phone_number:o.z.string(),send:o.z.enum(["link","code"]),authParams:ro.omit({client_id:!0})})])}}}},responses:{200:{description:"Status"}}}),async t=>{var b,A;const e=t.req.valid("json"),{env:n}=t,{client_id:r,send:i,authParams:s,connection:a}=e,c=await t.env.data.legacyClients.get(r);if(!c)throw new S(400,{message:"Client not found"});t.set("client_id",c.client_id),t.set("tenant_id",c.tenant.id);const l=a==="email"?e.email:e.phone_number,d=t.get("ip"),u=t.get("useragent"),f=t.get("auth0_client"),h=Nn(f),m=await n.data.loginSessions.create(c.tenant.id,{authParams:{...s,client_id:r,username:l},expires_at:new Date(Date.now()+hs).toISOString(),csrf_token:Ne(),ip:d,useragent:u,auth0Client:h}),y=await n.data.codes.create(c.tenant.id,{code_id:Zn(),code_type:"otp",login_id:m.id,expires_at:new Date(Date.now()+hs).toISOString(),redirect_uri:s.redirect_uri}),v=(A=(b=s==null?void 0:s.ui_locales)==null?void 0:b.split(" "))==null?void 0:A.map(O=>O.split("-")[0])[0];return i==="link"?await Lp(t,{to:l,code:y.code_id,authParams:{...s,client_id:r},language:v}):await Bp(t,{to:l,code:y.code_id,language:v}),t.html("OK")}).openapi(o.createRoute({tags:["passwordless"],method:"get",path:"/verify_redirect",request:{query:o.z.object({scope:o.z.string(),response_type:o.z.nativeEnum(Bt),redirect_uri:o.z.string(),state:o.z.string(),nonce:o.z.string().optional(),verification_code:o.z.string(),connection:o.z.string(),client_id:o.z.string(),email:o.z.string().transform(t=>t.toLowerCase()),audience:o.z.string().optional()})},responses:{302:{description:"Successful verification, redirecting to continue flow.",headers:o.z.object({Location:o.z.string().url()}).openapi({})},400:{description:"Bad Request (e.g., invalid client, invalid code, missing parameters).",content:{"application/json":{schema:o.z.object({error:o.z.string(),error_description:o.z.string().optional()})}}},500:{description:"Internal Server Error.",content:{"application/json":{schema:o.z.object({error:o.z.string(),error_description:o.z.string().optional()})}}}}}),async t=>{const{env:e}=t,{client_id:n,email:r,verification_code:i,redirect_uri:s,state:a,scope:c,audience:l,response_type:d,nonce:u}=t.req.valid("query"),f=await Oi(e,n);t.set("client_id",f.client_id),t.set("tenant_id",f.tenant.id),t.set("connection","email");const h={client_id:n,redirect_uri:s,state:a,nonce:u,scope:c,audience:l,response_type:d};let m="Something went wrong. Please try again later.";try{const U=await Op(t,{client_id:n,username:r,otp:i,authParams:h,enforceIpCheck:!0});if(U instanceof Response)return U;if(U&&typeof U=="object"&&"access_token"in U)return t.json(U)}catch(U){const T=U;"message"in T&&typeof T.message=="string"&&(m=T.message)}const y=t.get("ip"),v=t.get("useragent"),b=t.get("auth0_client"),A=Nn(b),O=await e.data.loginSessions.create(f.tenant.id,{authParams:{...h,username:r},expires_at:new Date(Date.now()+hs).toISOString(),csrf_token:Ne(),ip:y,useragent:v,auth0Client:A});return t.redirect(`${st(t.env)}invalid-session?state=${O.id}&error=${encodeURIComponent(m)}`,302)});class qr extends S{constructor(n,r){super(n,r);ae(this,"_code");this._code=r==null?void 0:r.code}get code(){return this._code}}async function z1(t,e,n,r){var h,m,y,v;const{data:i}=t.env,{username:s}=n;if(t.set("username",s),!s)throw new ee(400,{message:"Username is required"});const a=await vi({userAdapter:t.env.data.users,tenant_id:e.tenant.id,username:s,provider:"auth2"});if(!a){const b=be(t,{type:_e.FAILED_LOGIN_INCORRECT_PASSWORD,description:"Invalid user"});throw ve(t,i.logs.create(e.tenant.id,b)),new qr(403,{message:"User not found",code:"USER_NOT_FOUND"})}const c=a.linked_to?await i.users.get(e.tenant.id,a.linked_to):a;if(!c)throw new qr(403,{message:"User not found",code:"USER_NOT_FOUND"});t.set("connection",a.connection),t.set("user_id",c.user_id);const l=await i.passwords.get(e.tenant.id,a.user_id);if(!(l&&await ti.compare(n.password,l.password))){const b=be(t,{type:_e.FAILED_LOGIN_INCORRECT_PASSWORD,description:"Invalid password"});throw ve(t,i.logs.create(e.tenant.id,b)),new qr(403,{message:"Invalid password",code:"INVALID_PASSWORD"})}if((await i.logs.list(e.tenant.id,{page:0,per_page:10,include_totals:!1,q:`user_id:${c.user_id}`})).logs.filter(b=>b.type===_e.FAILED_LOGIN_INCORRECT_PASSWORD&&new Date(b.date)>new Date(Date.now()-1e3*60*5)).length>=3){const b=be(t,{type:_e.FAILED_LOGIN,description:"Too many failed login attempts"});throw ve(t,i.logs.create(e.tenant.id,b)),new qr(403,{message:"Too many failed login attempts",code:"TOO_MANY_FAILED_LOGINS"})}if(!a.email_verified&&((h=e.client_metadata)==null?void 0:h.email_validation)==="enforced"){const b=(v=(y=(m=r==null?void 0:r.authParams)==null?void 0:m.ui_locales)==null?void 0:y.split(" "))==null?void 0:v.map(O=>O.split("-")[0])[0];await Up(t,a,b);const A=be(t,{type:_e.FAILED_LOGIN,description:"Email not verified"});throw ve(t,i.logs.create(e.tenant.id,A)),new qr(403,{message:"Email not verified",code:"EMAIL_NOT_VERIFIED"})}return{client:e,authParams:n,user:c,loginSession:r}}async function A1(t,e,n,r,i){const s=await z1(t,e,n,r),a=await Um(t,t.env.data,e.tenant.id,s.user,r,{client:e,authParams:n,authStrategy:{strategy:"Username-Password-Authentication",strategy_type:"database"}});return a instanceof Response?a:(s.user=a,un(t,{...s,ticketAuth:i,strategy:"Username-Password-Authentication"}))}async function kx(t,e,n,r){await qa(t,{client:e,username:n,provider:"auth2",connection:"Username-Password-Authentication",isSocial:!1,ip:t.var.ip});let i=Zn(),s=await t.env.data.codes.get(e.tenant.id,i,"password_reset");for(;s;)i=Zn(),s=await t.env.data.codes.get(e.tenant.id,i,"password_reset");const a=t.get("ip"),c=t.get("useragent"),l=t.get("auth0_client"),d=Nn(l),u=await t.env.data.loginSessions.create(e.tenant.id,{expires_at:new Date(Date.now()+Ev).toISOString(),authParams:{client_id:e.client_id,username:n},csrf_token:Ne(),ip:a,useragent:c,auth0Client:d}),f=await t.env.data.codes.create(e.tenant.id,{code_id:i,code_type:"password_reset",login_id:u.id,expires_at:new Date(Date.now()+Av).toISOString()});await S1(t,n,f.code_id,r)}const xx=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:o.z.union([o.z.object({credential_type:o.z.literal("http://auth0.com/oauth/grant-type/passwordless/otp"),otp:o.z.string(),client_id:o.z.string(),username:o.z.string().transform(t=>t.toLowerCase()),realm:o.z.enum(["email"]),scope:o.z.string().optional()}),o.z.object({credential_type:o.z.literal("http://auth0.com/oauth/grant-type/password-realm"),client_id:o.z.string(),username:o.z.string().transform(t=>t.toLowerCase()),password:o.z.string(),realm:o.z.enum(["Username-Password-Authentication"]),scope:o.z.string().optional()})])}}}},responses:{200:{description:"List of tenants"}}}),async t=>{const e=t.req.valid("json"),{client_id:n,username:r}=e;t.set("username",r);const i=await t.env.data.legacyClients.get(n);if(!i)throw new S(400,{message:"Client not found"});t.set("client_id",n),t.set("tenant_id",i.tenant.id);const s=r.toLocaleLowerCase(),a=t.get("ip"),c=t.get("useragent"),l=t.get("auth0_client");let d;if("otp"in e)d=await Op(t,{client_id:n,username:s,otp:e.otp});else if("password"in e){const u=await t.env.data.loginSessions.create(i.tenant.id,{expires_at:new Date(Date.now()+_r*1e3).toISOString(),authParams:{client_id:n,username:s},csrf_token:Ne(),ip:a,useragent:c,auth0Client:Nn(l)});d=await A1(t,i,{username:s,password:e.password,client_id:n},u,!0)}else throw new S(400,{message:"Code or password required"});if(!(d instanceof Response))throw new S(500,{message:"Unexpected response from loginWithPassword"});return d});function E1(t,e){var r,i,s;if(!t||e.length===0)return!1;const n=((r=hl(t))==null?void 0:r.host)??null;if(!n)return!1;for(const a of e){let c;if(a.startsWith("http://")||a.startsWith("https://")?c=((i=hl(a))==null?void 0:i.host)??null:c=((s=hl("https://"+a))==null?void 0:s.host)??null,n===c)return!0}return!1}function hl(t){try{return new URL(t)}catch{return null}}async function Sx({ctx:t,session:e,client:n,authParams:r,connection:i,login_hint:s}){const a=new URL(t.req.url);t.var.custom_domain&&(a.hostname=t.var.custom_domain);const{ip:c,auth0_client:l,useragent:d}=t.var,u=Nn(l),f=await t.env.data.loginSessions.create(n.tenant.id,{expires_at:new Date(Date.now()+_r*1e3).toISOString(),authParams:r,csrf_token:Ne(),authorization_url:a.toString(),ip:c,useragent:d,auth0Client:u});if(e&&s){const h=await t.env.data.users.get(n.tenant.id,e.user_id);if((h==null?void 0:h.email)===s)return await t.env.data.loginSessions.update(n.tenant.id,f.id,{session_id:e.id}),un(t,{client:n,loginSession:{...f,session_id:e.id},authParams:r,user:h,sessionId:e.id})}if(i==="email"&&s){const h=Zn();return await t.env.data.codes.create(n.tenant.id,{code_id:h,code_type:"otp",login_id:f.id,expires_at:new Date(Date.now()+_r*1e3).toISOString(),redirect_uri:r.redirect_uri}),await Lp(t,{code:h,to:s,authParams:r}),t.redirect(`/u/enter-code?state=${f.id}`)}return e?t.redirect(`/u/check-account?state=${f.id}`):t.redirect(`/u/login/identifier?state=${f.id}`)}function zx(t){if(t==="Username-Password-Authentication")return"auth2";if(t==="email")return"email";throw new ee(403,{message:"Invalid realm"})}async function Ax(t,e,n,r,i){var h;const{env:s}=t;t.set("connection",i);const a=await s.data.codes.get(e,n,"ticket");if(!a||a.used_at)throw new ee(403,{message:"Ticket not found"});const c=await s.data.loginSessions.get(e,a.login_id);if(!c||!c.authParams.username)throw new ee(403,{message:"Session not found"});const l=await s.data.legacyClients.get(c.authParams.client_id);if(!l)throw new ee(403,{message:"Client not found"});t.set("client_id",c.authParams.client_id),await s.data.codes.used(e,n);const d=zx(i);let u=await qa(t,{username:c.authParams.username,provider:d,client:l,connection:d==="auth2"?"Username-Password-Authentication":"email",isSocial:!1,ip:t.var.ip});t.set("username",u.email||u.phone_number),t.set("user_id",u.user_id);const f=await Pm(t,{user:u,client:l,loginSession:c});return un(t,{authParams:{scope:(h=c.authParams)==null?void 0:h.scope,...r},loginSession:c,sessionId:f.id,user:u,client:l})}async function Ex({ctx:t,client:e,session:n,redirect_uri:r,state:i,nonce:s,code_challenge_method:a,code_challenge:c,audience:l,scope:d,response_type:u,organization:f}){const{env:h}=t,m=new URL(r),y=`${m.protocol}//${m.host}`;async function v(Q="Login required"){const K=be(t,{type:_e.FAILED_SILENT_AUTH,description:Q});return ve(t,t.env.data.logs.create(e.tenant.id,K)),t.html(jl(y,JSON.stringify({error:"login_required",error_description:Q,state:i})))}if(!n||(n==null?void 0:n.expires_at)&&new Date(n.expires_at)<new Date||(n==null?void 0:n.idle_expires_at)&&new Date(n.idle_expires_at)<new Date)return v();t.set("user_id",n.user_id);const A=await h.data.users.get(e.tenant.id,n.user_id);if(!A)return console.error("User not found",n.user_id),v("User not found");t.set("username",A.email),t.set("connection",A.connection);const O=await h.data.loginSessions.create(e.tenant.id,{csrf_token:Ne(),authParams:{client_id:e.client_id,audience:l,scope:d,state:i,nonce:s,response_type:u,redirect_uri:r,organization:f},expires_at:new Date(Date.now()+5*60*1e3).toISOString(),session_id:n.id,ip:t.var.ip,useragent:t.var.useragent}),U={client:e,authParams:{client_id:e.client_id,audience:l,code_challenge_method:a,code_challenge:c,scope:d,state:i,nonce:s,response_type:u,redirect_uri:r},user:A,session_id:n.id},T=u===Bt.CODE?await Om(t,{user:A,client:e,authParams:U.authParams,login_id:O.id}):await Fa(t,U);await h.data.sessions.update(e.tenant.id,n.id,{used_at:new Date().toISOString(),last_interaction_at:new Date().toISOString(),login_session_id:O.id,device:{...n.device,last_ip:t.var.ip||"",last_user_agent:t.var.useragent||""},idle_expires_at:n.idle_expires_at?new Date(Date.now()+Da*1e3).toISOString():void 0});const R=be(t,{type:_e.SUCCESS_SILENT_AUTH,description:"Successful silent authentication"});ve(t,t.env.data.logs.create(e.tenant.id,R));const W=new Headers;W.set("Server-Timing","cf-nel=0; no-cloudflare-insights=1");const ne=Hs(e.tenant.id,n.id,t.req.header("host"));return W.set("set-cookie",ne),t.html(jl(y,JSON.stringify({...T,state:i})),{headers:W})}const Cx=["email","sms","Username-Password-Authentication"],Nx=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth"],method:"get",path:"/",request:{query:o.z.object({client_id:o.z.string(),vendor_id:o.z.string().optional(),redirect_uri:o.z.string(),scope:o.z.string().optional(),state:o.z.string(),prompt:o.z.string().optional(),response_mode:o.z.nativeEnum(ln).optional(),response_type:o.z.nativeEnum(Bt).optional(),audience:o.z.string().optional(),connection:o.z.string().optional(),nonce:o.z.string().optional(),max_age:o.z.string().optional(),login_ticket:o.z.string().optional(),code_challenge_method:o.z.nativeEnum(Pa).optional(),code_challenge:o.z.string().optional(),realm:o.z.string().optional(),auth0Client:o.z.string().optional(),organization:o.z.string().optional(),login_hint:o.z.string().optional(),screen_hint:o.z.string().openapi({example:"signup",description:'Optional hint for the screen to show, like "signup" or "login".'}).optional(),ui_locales:o.z.string().optional()})},responses:{200:{description:"Successful authorization response. This can be an HTML page (e.g., for silent authentication iframe or universal login page) or a JSON object containing tokens (e.g., for response_mode=web_message).",content:{"text/html":{schema:o.z.string().openapi({example:"<html>...</html>"})},"application/json":{schema:bu}}},302:{description:"Redirect to the client's redirect URI, an authentication page, or an external identity provider.",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request. Invalid parameters or other client-side errors.",content:{"application/json":{schema:o.z.object({message:o.z.string()})}}},403:{description:"Forbidden. The request is not allowed (e.g., invalid origin).",content:{"application/json":{schema:o.z.object({message:o.z.string()})}}}}}),async t=>{const{env:e}=t,{client_id:n,vendor_id:r,redirect_uri:i,scope:s,state:a,audience:c,nonce:l,connection:d,response_type:u,response_mode:f,code_challenge:h,code_challenge_method:m,prompt:y,login_ticket:v,realm:b,auth0Client:A,login_hint:O,ui_locales:U,organization:T}=t.req.valid("query");t.set("log","authorize");const R=await Oi(e,n);t.set("client_id",R.client_id),t.set("tenant_id",R.tenant.id);const W={redirect_uri:i.split("#")[0],scope:s,state:a,client_id:n,vendor_id:r,audience:c,nonce:l,prompt:y,response_type:u,response_mode:f,code_challenge:h,code_challenge_method:m,username:O,ui_locales:U,organization:T},ne=t.req.header("origin");if(ne&&!E1(ne,R.web_origins||[]))throw new S(403,{message:`Origin ${ne} not allowed`});if(W.redirect_uri){const C=R.callbacks||[];if(t.var.host&&(C.push(`${Bc(t.env)}/*`),C.push(`${st(t.env)}/*`)),!zp(W.redirect_uri,C,{allowPathWildcards:!0,allowSubDomainWildcards:!0}))throw new S(400,{message:`Invalid redirect URI - ${W.redirect_uri}`})}const Q=ni(R.tenant.id,t.req.header("cookie")),K=Q?await e.data.sessions.get(R.tenant.id,Q):void 0,de=K&&!K.revoked_at?K:void 0;if(y=="none"){if(!u)throw new S(400,{message:"Missing response_type"});return Ex({ctx:t,session:de||void 0,redirect_uri:i,state:a,response_type:u,client:R,nonce:l,code_challenge_method:m,code_challenge:h,audience:c,scope:s,organization:T})}if(R.connections.length===1&&R.connections[0]&&!Cx.includes(R.connections[0].strategy||""))return fg(t,R,R.connections[0].name,W);if(d&&d!=="email")return fg(t,R,d,W);if(v){const C=await Ax(t,R.tenant.id,v,W,b);return C instanceof Response?C:t.json(C)}const N=await Sx({ctx:t,client:R,auth0Client:A,authParams:W,session:de||void 0,connection:d,login_hint:O});return N instanceof Response?N:t.json(N)}),Ix=new o.OpenAPIHono().openapi(o.createRoute({tags:["oauth"],method:"get",path:"/",request:{query:o.z.object({client_id:o.z.string(),redirect_url:o.z.string().optional(),login_hint:o.z.string().toLowerCase().optional(),screen_hint:o.z.enum(["account","change-email","change-phone","change-password"]).optional().default("account")})},responses:{302:{description:"Redirect to the account page with login session state or login page",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request. Invalid parameters or other client-side errors.",content:{"application/json":{schema:o.z.object({message:o.z.string()})}}}}}),async t=>{const{env:e}=t,{client_id:n,redirect_url:r,login_hint:i,screen_hint:s}=t.req.valid("query");t.set("log","account");const a=await Oi(e,n);t.set("client_id",a.client_id),t.set("tenant_id",a.tenant.id);const c={redirect_uri:r||t.req.url,client_id:n,username:i},l=t.req.header("origin");if(l&&!E1(l,a.web_origins||[]))throw new S(403,{message:`Origin ${l} not allowed`});if(c.redirect_uri){const O=a.callbacks||[];if(t.var.host&&(O.push(`${Bc(t.env)}/*`),O.push(`${st(t.env)}/*`)),!zp(c.redirect_uri,O,{allowPathWildcards:!0,allowSubDomainWildcards:!0}))throw new S(400,{message:`Invalid redirect URI - ${c.redirect_uri}`})}const d=ni(a.tenant.id,t.req.header("cookie")),u=d?await e.data.sessions.get(a.tenant.id,d):void 0,f=u&&!u.revoked_at?u:void 0,h=new URL(t.req.url);t.var.custom_domain&&(h.hostname=t.var.custom_domain);const{ip:m,auth0_client:y,useragent:v}=t.var,b=Nn(y),A=await e.data.loginSessions.create(a.tenant.id,{expires_at:new Date(Date.now()+_r*1e3).toISOString(),authParams:c,csrf_token:Ne(),authorization_url:h.toString(),ip:m,useragent:v,auth0Client:b});if(f){if(i){const U=await e.data.users.get(a.tenant.id,f.user_id);if((U==null?void 0:U.email)!==i)return t.redirect(`${st(t.env)}login/identifier?state=${encodeURIComponent(A.id)}`)}if(await e.data.loginSessions.update(a.tenant.id,A.id,{session_id:f.id}),s==="change-email"){const U=new URL("/u/account/change-email",t.req.url);return U.searchParams.set("state",A.id),t.redirect(U.toString())}const O=new URL("/u/account",t.req.url);return O.searchParams.set("state",A.id),t.redirect(O.toString())}return t.redirect(`${st(t.env)}login/identifier?state=${encodeURIComponent(A.id)}`)});function jx(t){const e=new o.OpenAPIHono;e.use(async(r,i)=>{const s=xo(r,t.dataAdapter),a=t.dataAdapter.cache||Ho({defaultTtlSeconds:0,maxEntries:100,cleanupIntervalMs:0}),c=t.dataAdapter.cache?300:0,l=Dc(s,{defaultTtl:c,cacheEntities:["tenants","connections","customDomains","clients","legacyClients","branding","themes","promptSettings","forms","resourceServers","roles","organizations","userRoles","userPermissions"],cache:a});return r.env.data=Rc(r,l),i()}),e.use("/oauth/token",g0({origin:r=>r||"",allowHeaders:["Tenant-Id","Content-Type","Auth0-Client","Upgrade-Insecure-Requests"],allowMethods:["POST"],maxAge:600})),e.use(Uc).use(Lc).use(wp(e));const n=e.route("/v2/logout",e5).route("/userinfo",t5).route("/.well-known",n5).route("/oauth/token",yx).route("/dbconnections",bx).route("/passwordless",$x).route("/co/authenticate",xx).route("/authorize",Nx).route("/account",Ix).route("/callback",Yk);return n.doc("/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"Oauth API"},security:[{oauth2:["openid","email","profile"]}]}),yp(n),n}async function Ce(t,e,n=!1){var h,m,y,v,b;const{env:r}=t,i=await r.data.loginSessions.get(t.var.tenant_id||"",e);if(!i)throw new ee(400,{message:"Login session not found"});t.set("loginSession",i);const s=await Oi(r,i.authParams.client_id);t.set("client_id",s.client_id),t.set("tenant_id",s.tenant.id);let a;try{a=H$(t,"auth_ui_style")}catch{a=void 0}let c=!1;(h=t.req)!=null&&h.url&&(c=(new URL(t.req.url).searchParams.get("style")||a||"classic")==="shadcn");const l=await r.data.tenants.get(s.tenant.id);if(l){if(i.session_id&&!n){if(!i.authParams.redirect_uri)throw new ee(400,{message:"Login session closed and no redirect URI available"});const A=new URL(i.authParams.redirect_uri);throw A.searchParams.set("error","access_denied"),A.searchParams.set("error_description","Login session closed"),i.authParams.state&&A.searchParams.set("state",i.authParams.state),new Ir(A.toString(),302)}}else throw new ee(400,{message:"Tenant not found"});const d=await r.data.themes.get(l.id,"default"),u=await r.data.branding.get(l.id),f=(b=(v=(y=(m=i.authParams)==null?void 0:m.ui_locales)==null?void 0:y.split(" "))==null?void 0:v.map(A=>A.split("-")[0]))==null?void 0:b.find(A=>{if(Array.isArray(w.options.supportedLngs))return w.options.supportedLngs.includes(A)});return await w.changeLanguage(f||"sv"),{theme:d,branding:u,client:s,tenant:l,loginSession:i,useShadcn:c}}async function jr(t,e){const{theme:n,branding:r,client:i,tenant:s,loginSession:a,useShadcn:c}=await Ce(t,e,!0),l=ni(i.tenant.id,t.req.header("cookie")),d=l?await t.env.data.sessions.get(i.tenant.id,l):null;if(!d||!a.session_id)throw new Ir(`/u/login/identifier?state=${encodeURIComponent(e)}`);const u=await t.env.data.sessions.get(i.tenant.id,a.session_id),f=await t.env.data.users.get(i.tenant.id,d.user_id);if(!f||(u==null?void 0:u.user_id)!==d.user_id)throw new Ir(`/u/login/identifier?state=${encodeURIComponent(e)}`);return{theme:n,branding:r,client:i,user:f,tenant:s,loginSession:a,session:u,useShadcn:c}}async function Ox(t,e,n,r){if(r!==void 0)return r==="password";const i=await Cu({userAdapter:t.env.data.users,tenant_id:e.tenant.id,email:n});return i!=null&&i.app_metadata.strategy?i.app_metadata.strategy==="Username-Password-Authentication":(await t.env.data.promptSettings.get(e.tenant.id)).password_first}var C1={exports:{}};/*!
200
200
  Copyright (c) 2018 Jed Watson.
201
201
  Licensed under the MIT License (MIT), see
202
202
  http://jedwatson.github.io/classnames
203
- */(function(t){(function(){var e={}.hasOwnProperty;function n(){for(var s="",a=0;a<arguments.length;a++){var c=arguments[a];c&&(s=i(s,r(c)))}return s}function r(s){if(typeof s=="string"||typeof s=="number")return s;if(typeof s!="object")return"";if(Array.isArray(s))return n.apply(null,s);if(s.toString!==Object.prototype.toString&&!s.toString.toString().includes("[native code]"))return s.toString();var a="";for(var c in s)e.call(s,c)&&s[c]&&(a=i(a,c));return a}function i(s,a){return a?s?s+" "+a:s+a:s}t.exports?(n.default=n,t.exports=n):window.classNames=n})()})(C1);var Tx=C1.exports;const ge=hm(Tx),_n=({children:t,className:e,style:n})=>p("div",{className:ge("rounded-lg border border-gray-200 bg-white shadow-sm dark:border-gray-700 dark:bg-gray-800",e),style:n,children:t}),yn=({children:t,className:e})=>p("div",{className:ge("flex flex-col space-y-1.5 p-6",e),children:t}),wn=({children:t,className:e,style:n})=>p("h3",{className:ge("text-2xl font-semibold leading-none tracking-tight",e),style:n,children:t}),vn=({children:t,className:e,style:n})=>p("p",{className:ge("text-sm text-gray-500 dark:text-gray-400",e),style:n,children:t}),bn=({children:t,className:e})=>p("div",{className:ge("p-6 pt-0",e),children:t}),N1=({children:t,className:e})=>p("div",{className:ge("flex items-center p-6 pt-0",e),children:t}),Qt=({id:t,type:e="text",name:n,placeholder:r,className:i,required:s=!1,value:a,disabled:c=!1,error:l=!1,style:d})=>p("input",{id:t,type:e,name:n,placeholder:r,required:s,value:a,disabled:c,className:ge("flex h-10 w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm ring-offset-white transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-gray-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-gray-600 dark:bg-gray-800 dark:ring-offset-gray-900 dark:placeholder:text-gray-400",l&&"border-red-500 focus-visible:ring-red-500",i),style:d}),fn=({children:t,className:e,variant:n="default",size:r="default",type:i="button",disabled:s=!1,style:a})=>{const c={default:"bg-blue-600 text-white hover:bg-blue-700 dark:bg-blue-700 dark:hover:bg-blue-800",outline:"border border-gray-300 bg-transparent hover:bg-gray-100 dark:border-gray-600 dark:hover:bg-gray-800",ghost:"hover:bg-gray-100 dark:hover:bg-gray-800"},l={default:"h-10 px-4 py-2",sm:"h-9 px-3 text-sm",lg:"h-11 px-8"};return p("button",{type:i,disabled:s,className:ge("inline-flex items-center justify-center gap-2 rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 disabled:pointer-events-none disabled:opacity-50",c[n],l[r],e),style:a,children:t})},Lt=({htmlFor:t,className:e,style:n,children:r})=>p("label",{for:t,className:ge("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",e),style:n,children:r}),et=({children:t,className:e})=>p("div",{className:ge("mb-2 text-sm text-red",e),children:t}),rn=({theme:t,branding:e})=>{var r;const n=((r=t==null?void 0:t.widget)==null?void 0:r.logo_url)||(e==null?void 0:e.logo_url);return n?p("div",{className:"inline-flex h-9 items-center",children:p("img",{src:n,className:"h-full w-auto",alt:"Logo"})}):p(Mc,{})},xs=({error:t,theme:e,branding:n,loginSession:r,email:i,client:s,className:a})=>{var D,fe,$e,ce,ue,Ae,Ee,Re,Se,Te,Be,Ge,dt,Ze,tt,nt,rt,Rn,Ti,Rr,Zo,Yo,Qo,es,Bn;const c=s.connections.map(({strategy:bt})=>bt),l=c.includes("email")||c.includes("Username-Password-Authentication"),d=c.includes("sms"),u=c.map(bt=>{const Br=p1(bt);return Br?{name:bt,...Br}:null}).filter(bt=>bt!==null),f=l&&d?"email_or_phone_placeholder":l?"email_placeholder":"phone_placeholder",h=w.t(f,l&&d?"Email or Phone Number":l?"Email Address":"Phone Number"),m=((D=e==null?void 0:e.colors)==null?void 0:D.primary_button)||((fe=n==null?void 0:n.colors)==null?void 0:fe.primary)||"#0066cc",y=(($e=e==null?void 0:e.colors)==null?void 0:$e.primary_button_label)||"#ffffff",v=((ce=e==null?void 0:e.colors)==null?void 0:ce.body_text)||"#333333",b=((ue=e==null?void 0:e.colors)==null?void 0:ue.input_background)||"#ffffff",A=((Ae=e==null?void 0:e.colors)==null?void 0:Ae.input_border)||"#d1d5db",O=((Ee=e==null?void 0:e.colors)==null?void 0:Ee.input_filled_text)||"#111827",U=((Re=e==null?void 0:e.colors)==null?void 0:Re.error)||"#dc2626",T=((Se=e==null?void 0:e.colors)==null?void 0:Se.widget_background)||"#ffffff",R=((Te=e==null?void 0:e.colors)==null?void 0:Te.widget_border)||"#e5e7eb",W=((Be=e==null?void 0:e.borders)==null?void 0:Be.widget_corner_radius)||8,ne=((Ge=e==null?void 0:e.borders)==null?void 0:Ge.input_border_radius)||4,Q=((dt=e==null?void 0:e.borders)==null?void 0:dt.button_border_radius)||4,K=((Ze=e==null?void 0:e.borders)==null?void 0:Ze.show_widget_shadow)??!0,de=((nt=(tt=e==null?void 0:e.fonts)==null?void 0:tt.title)==null?void 0:nt.size)||24,N=((Rn=(rt=e==null?void 0:e.fonts)==null?void 0:rt.title)==null?void 0:Rn.bold)??!0,C=((Rr=(Ti=e==null?void 0:e.fonts)==null?void 0:Ti.body_text)==null?void 0:Rr.size)||14,z={backgroundColor:T,borderColor:R,borderRadius:`${W}px`,boxShadow:K?"0 1px 3px 0 rgba(0, 0, 0, 0.1)":"none",color:v},k={fontSize:`${de}px`,fontWeight:N?"700":"400",color:((Zo=e==null?void 0:e.colors)==null?void 0:Zo.header)||v},$={fontSize:`${C}px`,color:((Yo=e==null?void 0:e.colors)==null?void 0:Yo.input_labels_placeholders)||"#6b7280"},I={backgroundColor:b,borderColor:t?U:A,borderRadius:`${ne}px`,color:O},L={backgroundColor:m,color:y,borderRadius:`${Q}px`},q=((Qo=e==null?void 0:e.widget)==null?void 0:Qo.logo_position)||"center",F=q==="left"?"text-left":q==="right"?"text-right":"text-center",Z=((es=e==null?void 0:e.widget)==null?void 0:es.logo_url)||(n==null?void 0:n.logo_url),se=q!=="none"&&Z;return p("div",{className:ge("flex flex-col gap-6 w-full max-w-sm",a),children:p(_n,{style:z,className:"border",children:[p(yn,{children:[se&&p("div",{className:ge("mb-4",F),children:p(rn,{theme:e,branding:n})}),p(wn,{style:k,children:w.t("welcome","Login")}),p(vn,{style:$,children:w.t("login_description_template",{authMethod:w.t(f,{defaultValue:l&&d?"email or phone number":l?"email address":"phone number"}).toLocaleLowerCase(),defaultValue:"Enter your {{authMethod}} below to login to your account"})})]}),p(bn,{children:p("form",{method:"post",children:p("div",{className:"grid gap-6",children:[p("div",{className:"grid gap-2",children:[p(Lt,{htmlFor:"username",style:$,children:w.t(f,l&&d?"Email or Phone Number":l?"Email":"Phone Number")}),p(Qt,{id:"username",name:"username",type:"text",placeholder:h,required:!0,value:i||"",error:!!t,className:"border",style:I}),t&&p(et,{children:t})]}),p(fn,{type:"submit",className:"w-full transition-colors hover:brightness-90",style:L,children:w.t("continue","Continue")}),u.length>0&&p(Mc,{children:[p("div",{className:"relative text-center",style:{color:((Bn=e==null?void 0:e.colors)==null?void 0:Bn.input_labels_placeholders)||"#6b7280",fontSize:`${C}px`},children:[p("div",{className:"absolute left-0 right-0 top-1/2 border-b",style:{borderColor:R}}),p("div",{className:"relative inline-block px-2",style:{backgroundColor:T},children:w.t("or","Or")})]}),p("div",{className:"flex gap-4 sm:flex-col short:flex-row",children:u.map(bt=>{const Br=bt.logo;return p("a",{href:`/authorize/redirect?state=${r.id}&connection=${bt.name}`,className:"inline-flex items-center justify-center gap-2 rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 disabled:pointer-events-none disabled:opacity-50 border bg-transparent hover:bg-gray-100 dark:hover:bg-gray-800 h-10 px-4 py-2 w-full sm:w-full short:flex-1",style:{borderColor:A,borderRadius:`${Q}px`,color:v},children:[p(Br,{className:"h-5 w-5"}),p("span",{className:"sm:inline short:hidden",children:w.t("continue_with","Login with {{provider}}",{provider:bt.displayName})}),p("span",{className:"hidden short:inline",children:bt.displayName})]},bt.name)})})]})]})})})]})})},I1=t=>{var e,n;return p("div",{className:"mt-8",children:((n=(e=t.client)==null?void 0:e.client_metadata)==null?void 0:n.termsAndConditionsUrl)&&p("div",{className:"text-xs text-gray-300",children:[w.t("agree_to")," ",p("a",{href:t.client.client_metadata.termsAndConditionsUrl,className:"text-primary hover:underline",target:"_blank",rel:"noreferrer",children:w.t("terms")})]})})},Px=t=>t==="small"?"text-base":t==="medium"?"text-2xl":t==="large"?"text-3xl":"",Ke=({name:t,size:e,className:n=""})=>{const r=Px(e);return p("span",{className:ge(`uicon-${t}`,n,r)})},Rx=(t,e)=>{const n=t.replace("#",""),r=parseInt(n,16),i=r>>16&255,s=r>>8&255,a=r&255,c=Math.min(255,Math.round(i+(255-i)*e)),l=Math.min(255,Math.round(s+(255-s)*e)),d=Math.min(255,Math.round(a+(255-a)*e));return`#${(c<<16|l<<8|d).toString(16).padStart(6,"0")}`},Bx=(t,e)=>{var s,a,c,l;const n=((s=t==null?void 0:t.colors)==null?void 0:s.primary_button)||((a=e==null?void 0:e.colors)==null?void 0:a.primary)||"#000000",r=((c=t==null?void 0:t.colors)==null?void 0:c.base_hover_color)||Rx(n,.2),i=((l=t==null?void 0:t.colors)==null?void 0:l.primary_button_label)||"#ffffff";return`
203
+ */(function(t){(function(){var e={}.hasOwnProperty;function n(){for(var s="",a=0;a<arguments.length;a++){var c=arguments[a];c&&(s=i(s,r(c)))}return s}function r(s){if(typeof s=="string"||typeof s=="number")return s;if(typeof s!="object")return"";if(Array.isArray(s))return n.apply(null,s);if(s.toString!==Object.prototype.toString&&!s.toString.toString().includes("[native code]"))return s.toString();var a="";for(var c in s)e.call(s,c)&&s[c]&&(a=i(a,c));return a}function i(s,a){return a?s?s+" "+a:s+a:s}t.exports?(n.default=n,t.exports=n):window.classNames=n})()})(C1);var Tx=C1.exports;const ge=hm(Tx),_n=({children:t,className:e,style:n})=>p("div",{className:ge("rounded-lg border border-gray-200 bg-white shadow-sm dark:border-gray-700 dark:bg-gray-800",e),style:n,children:t}),yn=({children:t,className:e})=>p("div",{className:ge("flex flex-col space-y-1.5 p-6",e),children:t}),wn=({children:t,className:e,style:n})=>p("h3",{className:ge("text-2xl font-semibold leading-none tracking-tight",e),style:n,children:t}),vn=({children:t,className:e,style:n})=>p("p",{className:ge("text-sm text-gray-500 dark:text-gray-400",e),style:n,children:t}),bn=({children:t,className:e})=>p("div",{className:ge("p-6 pt-0",e),children:t}),N1=({children:t,className:e})=>p("div",{className:ge("flex items-center p-6 pt-0",e),children:t}),Yt=({id:t,type:e="text",name:n,placeholder:r,className:i,required:s=!1,value:a,disabled:c=!1,error:l=!1,style:d})=>p("input",{id:t,type:e,name:n,placeholder:r,required:s,value:a,disabled:c,className:ge("flex h-10 w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm ring-offset-white transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-gray-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-gray-600 dark:bg-gray-800 dark:ring-offset-gray-900 dark:placeholder:text-gray-400",l&&"border-red-500 focus-visible:ring-red-500",i),style:d}),fn=({children:t,className:e,variant:n="default",size:r="default",type:i="button",disabled:s=!1,style:a})=>{const c={default:"bg-blue-600 text-white hover:bg-blue-700 dark:bg-blue-700 dark:hover:bg-blue-800",outline:"border border-gray-300 bg-transparent hover:bg-gray-100 dark:border-gray-600 dark:hover:bg-gray-800",ghost:"hover:bg-gray-100 dark:hover:bg-gray-800"},l={default:"h-10 px-4 py-2",sm:"h-9 px-3 text-sm",lg:"h-11 px-8"};return p("button",{type:i,disabled:s,className:ge("inline-flex items-center justify-center gap-2 rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 disabled:pointer-events-none disabled:opacity-50",c[n],l[r],e),style:a,children:t})},Lt=({htmlFor:t,className:e,style:n,children:r})=>p("label",{for:t,className:ge("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",e),style:n,children:r}),et=({children:t,className:e})=>p("div",{className:ge("mb-2 text-sm text-red",e),children:t}),nn=({theme:t,branding:e})=>{var r;const n=((r=t==null?void 0:t.widget)==null?void 0:r.logo_url)||(e==null?void 0:e.logo_url);return n?p("div",{className:"inline-flex h-9 items-center",children:p("img",{src:n,className:"h-full w-auto",alt:"Logo"})}):p(Mc,{})},xs=({error:t,theme:e,branding:n,loginSession:r,email:i,client:s,className:a})=>{var D,fe,$e,ce,ue,Ae,Ee,Re,Se,Te,Be,Ge,dt,Ze,tt,nt,rt,Rn,Ti,Rr,Zo,Yo,Qo,es,Bn;const c=s.connections.map(({strategy:bt})=>bt),l=c.includes("email")||c.includes("Username-Password-Authentication"),d=c.includes("sms"),u=c.map(bt=>{const Br=p1(bt);return Br?{name:bt,...Br}:null}).filter(bt=>bt!==null),f=l&&d?"email_or_phone_placeholder":l?"email_placeholder":"phone_placeholder",h=w.t(f,l&&d?"Email or Phone Number":l?"Email Address":"Phone Number"),m=((D=e==null?void 0:e.colors)==null?void 0:D.primary_button)||((fe=n==null?void 0:n.colors)==null?void 0:fe.primary)||"#0066cc",y=(($e=e==null?void 0:e.colors)==null?void 0:$e.primary_button_label)||"#ffffff",v=((ce=e==null?void 0:e.colors)==null?void 0:ce.body_text)||"#333333",b=((ue=e==null?void 0:e.colors)==null?void 0:ue.input_background)||"#ffffff",A=((Ae=e==null?void 0:e.colors)==null?void 0:Ae.input_border)||"#d1d5db",O=((Ee=e==null?void 0:e.colors)==null?void 0:Ee.input_filled_text)||"#111827",U=((Re=e==null?void 0:e.colors)==null?void 0:Re.error)||"#dc2626",T=((Se=e==null?void 0:e.colors)==null?void 0:Se.widget_background)||"#ffffff",R=((Te=e==null?void 0:e.colors)==null?void 0:Te.widget_border)||"#e5e7eb",W=((Be=e==null?void 0:e.borders)==null?void 0:Be.widget_corner_radius)||8,ne=((Ge=e==null?void 0:e.borders)==null?void 0:Ge.input_border_radius)||4,Q=((dt=e==null?void 0:e.borders)==null?void 0:dt.button_border_radius)||4,K=((Ze=e==null?void 0:e.borders)==null?void 0:Ze.show_widget_shadow)??!0,de=((nt=(tt=e==null?void 0:e.fonts)==null?void 0:tt.title)==null?void 0:nt.size)||24,N=((Rn=(rt=e==null?void 0:e.fonts)==null?void 0:rt.title)==null?void 0:Rn.bold)??!0,C=((Rr=(Ti=e==null?void 0:e.fonts)==null?void 0:Ti.body_text)==null?void 0:Rr.size)||14,z={backgroundColor:T,borderColor:R,borderRadius:`${W}px`,boxShadow:K?"0 1px 3px 0 rgba(0, 0, 0, 0.1)":"none",color:v},k={fontSize:`${de}px`,fontWeight:N?"700":"400",color:((Zo=e==null?void 0:e.colors)==null?void 0:Zo.header)||v},$={fontSize:`${C}px`,color:((Yo=e==null?void 0:e.colors)==null?void 0:Yo.input_labels_placeholders)||"#6b7280"},I={backgroundColor:b,borderColor:t?U:A,borderRadius:`${ne}px`,color:O},L={backgroundColor:m,color:y,borderRadius:`${Q}px`},q=((Qo=e==null?void 0:e.widget)==null?void 0:Qo.logo_position)||"center",F=q==="left"?"text-left":q==="right"?"text-right":"text-center",Z=((es=e==null?void 0:e.widget)==null?void 0:es.logo_url)||(n==null?void 0:n.logo_url),se=q!=="none"&&Z;return p("div",{className:ge("flex flex-col gap-6 w-full max-w-sm",a),children:p(_n,{style:z,className:"border",children:[p(yn,{children:[se&&p("div",{className:ge("mb-4",F),children:p(nn,{theme:e,branding:n})}),p(wn,{style:k,children:w.t("welcome","Login")}),p(vn,{style:$,children:w.t("login_description_template",{authMethod:w.t(f,{defaultValue:l&&d?"email or phone number":l?"email address":"phone number"}).toLocaleLowerCase(),defaultValue:"Enter your {{authMethod}} below to login to your account"})})]}),p(bn,{children:p("form",{method:"post",children:p("div",{className:"grid gap-6",children:[p("div",{className:"grid gap-2",children:[p(Lt,{htmlFor:"username",style:$,children:w.t(f,l&&d?"Email or Phone Number":l?"Email":"Phone Number")}),p(Yt,{id:"username",name:"username",type:"text",placeholder:h,required:!0,value:i||"",error:!!t,className:"border",style:I}),t&&p(et,{children:t})]}),p(fn,{type:"submit",className:"w-full transition-colors hover:brightness-90",style:L,children:w.t("continue","Continue")}),u.length>0&&p(Mc,{children:[p("div",{className:"relative text-center",style:{color:((Bn=e==null?void 0:e.colors)==null?void 0:Bn.input_labels_placeholders)||"#6b7280",fontSize:`${C}px`},children:[p("div",{className:"absolute left-0 right-0 top-1/2 border-b",style:{borderColor:R}}),p("div",{className:"relative inline-block px-2",style:{backgroundColor:T},children:w.t("or","Or")})]}),p("div",{className:"flex gap-4 sm:flex-col short:flex-row",children:u.map(bt=>{const Br=bt.logo;return p("a",{href:`/authorize/redirect?state=${r.id}&connection=${bt.name}`,className:"inline-flex items-center justify-center gap-2 rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 disabled:pointer-events-none disabled:opacity-50 border bg-transparent hover:bg-gray-100 dark:hover:bg-gray-800 h-10 px-4 py-2 w-full sm:w-full short:flex-1",style:{borderColor:A,borderRadius:`${Q}px`,color:v},children:[p(Br,{className:"h-5 w-5"}),p("span",{className:"sm:inline short:hidden",children:w.t("continue_with","Login with {{provider}}",{provider:bt.displayName})}),p("span",{className:"hidden short:inline",children:bt.displayName})]},bt.name)})})]})]})})})]})})},I1=t=>{var e,n;return p("div",{className:"mt-8",children:((n=(e=t.client)==null?void 0:e.client_metadata)==null?void 0:n.termsAndConditionsUrl)&&p("div",{className:"text-xs text-gray-300",children:[w.t("agree_to")," ",p("a",{href:t.client.client_metadata.termsAndConditionsUrl,className:"text-primary hover:underline",target:"_blank",rel:"noreferrer",children:w.t("terms")})]})})},Px=t=>t==="small"?"text-base":t==="medium"?"text-2xl":t==="large"?"text-3xl":"",Ke=({name:t,size:e,className:n=""})=>{const r=Px(e);return p("span",{className:ge(`uicon-${t}`,n,r)})},Rx=(t,e)=>{const n=t.replace("#",""),r=parseInt(n,16),i=r>>16&255,s=r>>8&255,a=r&255,c=Math.min(255,Math.round(i+(255-i)*e)),l=Math.min(255,Math.round(s+(255-s)*e)),d=Math.min(255,Math.round(a+(255-a)*e));return`#${(c<<16|l<<8|d).toString(16).padStart(6,"0")}`},Bx=(t,e)=>{var s,a,c,l;const n=((s=t==null?void 0:t.colors)==null?void 0:s.primary_button)||((a=e==null?void 0:e.colors)==null?void 0:a.primary)||"#000000",r=((c=t==null?void 0:t.colors)==null?void 0:c.base_hover_color)||Rx(n,.2),i=((l=t==null?void 0:t.colors)==null?void 0:l.primary_button_label)||"#ffffff";return`
204
204
  body {
205
205
  --primary-color: ${n};
206
206
  --primary-hover: ${r};
207
207
  --text-on-primary: ${i};
208
208
  }
209
- `},Lx="https://assets.sesamy.com/images/login-bg.jpg",De=({title:t,children:e,theme:n,branding:r,client:i})=>{var a;const s={backgroundImage:`url(${((a=n==null?void 0:n.page_background)==null?void 0:a.background_image_url)||Lx})`};return p("html",{lang:"en",children:[p("head",{children:[p("title",{children:t}),p("meta",{charset:"UTF-8"}),p("meta",{name:"robots",content:"noindex, follow"}),p("link",{rel:"preload",href:"https://assets.sesamy.com/fonts/khteka/WOFF2/KHTeka-Regular.woff2",as:"font",type:"font/woff2",crossOrigin:"anonymous"}),p("link",{rel:"preload",href:"https://assets.sesamy.com/fonts/khteka/WOFF2/KHTeka-Medium.woff2",as:"font",type:"font/woff2",crossOrigin:"anonymous"}),p("link",{rel:"preload",href:"https://assets.sesamy.com/fonts/khteka/WOFF2/KHTeka-Bold.woff2",as:"font",type:"font/woff2",crossOrigin:"anonymous"}),p("link",{rel:"stylesheet",href:"/u/css/tailwind.css"}),p("meta",{name:"viewport",content:"width=device-width, initial-scale=1, maximum-scale=1"}),p("style",{children:Bx(n,r)}),p("meta",{name:"theme-color",content:"#000000"})]}),p("body",{children:[p("div",{className:"row min-h-full w-full overflow-hidden bg-cover bg-center text-sm sm:bg-fixed sm:bg-left-top sm:pt-16 py-2",style:s,children:p("div",{className:"row-up-left w-[calc(100%-theme(space.2)-theme(space.2))] max-w-[1295px] !flex-nowrap sm:w-[calc(100%-theme(space.16)-theme(space.16))]",children:p("div",{className:"column-left w-full sm:w-auto",children:[p("div",{className:"relative flex w-full flex-col rounded-2xl bg-white px-5 py-10 dark:bg-gray-800 dark:text-white sm:min-h-[700px] sm:max-w-md sm:px-14 sm:py-14 md:min-w-[448px] short:min-h-[558px] min-h-[calc(100vh-83px)]",children:[p("div",{className:"mb-16",children:p(rn,{theme:n,branding:r})}),p("div",{className:"flex flex-1 flex-col",children:[e,p(I1,{theme:n,branding:r,client:i})]})]}),p("div",{className:"flex w-full items-center px-6 pb-8 pt-4 justify-between",children:[p("div",{className:"flex justify-center leading-[0]",children:p("a",{href:"https://sesamy.com",target:"_blank",rel:"noreferrer",children:p(Ke,{name:"sesamy",className:"text-xl text-white"})})}),p("div",{className:"flex justify-center space-x-2 text-xs text-white sm:justify-normal md:text-xs"})]})]})})}),p("div",{id:"client-root"})]}),p("script",{type:"module",src:"/u/js/client.js"})]})},Ux=t=>t==="small"?"text-base":t==="medium"?"text-2xl":t==="large"?"text-3xl":"",j1=({size:t})=>{const e=Ux(t);return p("div",{className:"relative inline-block leading-[0]",children:[p(Ke,{className:ge("text-gray-200 dark:text-[#201a41]",{[e]:e}),name:"spinner-circle"}),p(Ke,{className:ge("absolute inset-0 animate-spin text-primary",{[e]:e}),name:"spinner-inner"})]})},Ue=({children:t,className:e,Component:n="button",variant:r="primary",href:i,disabled:s,isLoading:a,id:c})=>{const l=n==="a"?{href:i}:{};return p(n,{class:ge("btn relative w-full rounded-lg text-center",{"px-4 py-5":r!=="custom","bg-primary text-textOnPrimary hover:bg-primaryHover":r==="primary","border border-gray-300 bg-white text-black":r==="secondary","pointer-events-none cursor-not-allowed opacity-40":s,"is-loading":a},"focus:outline-none focus:ring",e),type:"submit",disabled:s,id:c,...l,children:[p("span",{className:"btn-label flex items-center justify-center space-x-2",children:t}),p("div",{className:"btn-spinner absolute left-0 top-0 flex h-full w-full items-center justify-center",children:p(j1,{size:"medium"})})]})},O1=({connection:t,text:e,icon:n=null,canResize:r=!1,loginSession:i})=>{const s=new URLSearchParams({client_id:i.authParams.client_id,connection:t});i.authParams.response_type&&s.set("response_type",i.authParams.response_type),i.authParams.redirect_uri&&s.set("redirect_uri",i.authParams.redirect_uri),i.authParams.scope&&s.set("scope",i.authParams.scope),i.authParams.nonce&&s.set("nonce",i.authParams.nonce),i.authParams.response_type&&s.set("response_type",i.authParams.response_type),i.authParams.state&&s.set("state",i.id);const a=`/authorize?${s.toString()}`;return p(Ue,{className:ge("border border-gray-200 bg-white hover:bg-gray-100 dark:border-gray-400 dark:bg-black dark:hover:bg-black/90",{"px-0 py-3 sm:px-10 sm:py-4 short:px-0 short:py-3":r,"px-10 py-3":!r}),variant:"custom","aria-label":e,Component:"a",href:a,children:[n||"",p("div",{className:ge("text-left text-black dark:text-white sm:text-base",{"hidden sm:inline short:hidden":r}),children:e})]})},on=({children:t,className:e})=>p("form",{id:"form",method:"post",className:e,children:t}),Ss=({error:t,theme:e,branding:n,loginSession:r,email:i,client:s})=>{const a=s.connections.map(({strategy:b})=>b),c=a.includes("email")||a.includes("Username-Password-Authentication"),l=a.includes("sms"),d=a.map(b=>{const A=p1(b);return A?{name:b,...A}:null}).filter(b=>b!==null),u=c||l;let f="text",h="username";const m=c&&l?"email_or_phone_placeholder":c?"email_placeholder":"phone_placeholder";let y=w.t(m,c&&l?"Email or Phone Number":c?"Email Address":"Phone Number");return p(De,{title:w.t("welcome"),theme:e,branding:n,client:s,children:[p("div",{className:"mb-4 text-lg font-medium sm:text-2xl",children:w.t("welcome")}),p("div",{className:"mb-8 text-gray-300",children:w.t("login_description_template",{authMethod:w.t(m,{defaultValue:c&&l?"email or phone number":c?"email address":"phone number"}).toLocaleLowerCase(),defaultValue:"Sign in with your {{authMethod}}"})}),p("div",{className:"flex flex-1 flex-col justify-center",children:[u&&p(on,{className:"mb-7",children:[p("input",{type:f,name:h,placeholder:y,className:ge("mb-2 w-full rounded-lg border bg-gray-100 px-4 py-5 text-base placeholder:text-gray-300 dark:bg-gray-600 md:text-base",{"border-red":t,"border-gray-100 dark:border-gray-500":!t}),required:!0,value:i||""}),t&&p(et,{children:t}),p(Ue,{className:"sm:mt-4 !text-base",children:[p("span",{children:w.t("continue")}),p(Ke,{className:"text-xs",name:"arrow-right"})]})]}),u&&d.length>0&&p("div",{className:"relative mb-5 block text-center text-gray-300 dark:text-gray-300",children:[p("div",{className:"absolute left-0 right-0 top-1/2 border-b border-gray-200 dark:border-gray-600"}),p("div",{className:"relative inline-block bg-white px-2 dark:bg-gray-800",children:w.t("continue_social_login")})]}),p("div",{className:"flex space-x-4 sm:flex-col sm:space-x-0 sm:space-y-4 short:flex-row short:space-x-4 short:space-y-0",children:d.map(b=>{const A=b.logo;return p(O1,{connection:b.name,text:w.t("continue_with",{provider:b.displayName}),canResize:!0,icon:p(A,{className:"h-5 w-5 sm:absolute sm:left-4 sm:top-1/2 sm:h-6 sm:w-6 sm:-translate-y-1/2 short:static short:left-auto short:top-auto short:h-5 short:w-5 short:translate-y-0"}),loginSession:r},b.name)})})]})]})},Dx="https://assets.sesamy.com/images/login-bg.jpg",Oe=({title:t,children:e,theme:n,branding:r})=>{var v,b,A,O;const i=((v=n==null?void 0:n.page_background)==null?void 0:v.page_layout)||"center",s=((b=n==null?void 0:n.page_background)==null?void 0:b.background_color)||"#ffffff",a=(A=n==null?void 0:n.page_background)==null?void 0:A.background_image_url,c=a??Dx,l=(c==null?void 0:c.startsWith("linear-gradient"))||(c==null?void 0:c.startsWith("radial-gradient"))||(c==null?void 0:c.startsWith("conic-gradient")),d=c?l?c:`url(${c})`:void 0;let u="justify-center",f="p-6 md:p-10";i==="left"?(u="justify-start",f="pl-12 pr-6 py-6 md:pl-20 md:pr-10 md:py-10"):i==="right"&&(u="justify-end",f="pr-12 pl-6 py-6 md:pr-20 md:pl-10 md:py-10");const h=ge("min-h-screen w-full flex bg-cover bg-center",u,f),m={...d&&{backgroundImage:d},backgroundColor:s,display:"flex",alignItems:"stretch",justifyContent:i==="left"?"flex-start":i==="right"?"flex-end":"center",minHeight:"100vh",width:"100%"},y=ge("w-full max-w-sm","flex flex-col justify-center");return p("html",{lang:"en",children:[p("head",{children:[p("title",{children:t}),p("meta",{charset:"UTF-8"}),p("meta",{name:"robots",content:"noindex, follow"}),p("link",{rel:"stylesheet",href:"/u/css/tailwind.css"}),p("link",{rel:"stylesheet",href:"/u/css/shadcn-ui.css"}),p("meta",{name:"viewport",content:"width=device-width, initial-scale=1, maximum-scale=1"}),p("meta",{name:"theme-color",content:"#000000"}),(r==null?void 0:r.favicon_url)&&p("link",{rel:"icon",type:"image/x-icon",href:r.favicon_url}),((O=n==null?void 0:n.fonts)==null?void 0:O.font_url)&&p("link",{rel:"stylesheet",href:n.fonts.font_url})]}),p("body",{children:[p("div",{className:h,style:m,children:p("div",{className:y,children:[e,(r==null?void 0:r.powered_by_logo_url)&&p("div",{className:"mt-5 text-left",children:p("a",{href:"https://authhero.com",target:"_blank",rel:"noopener noreferrer",className:"inline-block",children:p("img",{src:r.powered_by_logo_url,alt:"Powered by",className:"h-9 opacity-60 hover:opacity-100 transition-opacity"})})})]})}),p("div",{id:"client-root"}),p("script",{type:"module",src:"/u/js/client.js"})]})]})},Mx=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"}),impersonation:o.z.string().optional()})},responses:{200:{description:"Response"}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,loginSession:i,client:s,useShadcn:a}=await Ce(t,e);return a?t.html(p(Oe,{title:w.t("welcome","Login"),theme:n,branding:r,client:s,children:p(xs,{theme:n,branding:r,loginSession:i,client:s,email:i.authParams.username})})):t.html(p(Ss,{theme:n,branding:r,loginSession:i,client:s,email:i.authParams.username}))}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"}),style:o.z.enum(["classic","shadcn"]).optional().openapi({description:"UI style to use for the login page"})}),body:{content:{"application/x-www-form-urlencoded":{schema:o.z.object({username:o.z.string().transform(t=>t.toLowerCase()),login_selection:o.z.enum(["code","password"]).optional()})}}}},responses:{400:{description:"Error response"},302:{description:"Redirect to enter code or password"}}}),async t=>{var O,U,T;const{env:e}=t,{state:n}=t.req.valid("query"),r=t.req.valid("form");t.set("body",r),t.set("username",r.username);const{client:i,loginSession:s,theme:a,branding:c,useShadcn:l}=await Ce(t,n);t.set("client_id",i.client_id);const d=t.get("countryCode"),{normalized:u,connectionType:f}=Vc(r.username,d);if(!i.connections.find(R=>R.strategy===f)||!u)return l?t.html(p(Oe,{title:w.t("welcome","Login"),theme:a,branding:c,client:i,children:p(xs,{theme:a,branding:c,loginSession:s,error:w.t("invalid_identifier"),email:r.username,client:i})}),400):t.html(p(Ss,{theme:a,branding:c,loginSession:s,error:w.t("invalid_identifier"),email:r.username,client:i}),400);const h=await io({userAdapter:e.data.users,tenant_id:i.tenant.id,username:u,provider:f});if(h&&t.set("user_id",h.user_id),!h)try{await Lm(t,i,t.env.data,u)}catch{const R=be(t,{type:_e.FAILED_SIGNUP,description:"Public signup is disabled"});return ve(t,t.env.data.logs.create(i.tenant.id,R)),l?t.html(p(Oe,{title:w.t("welcome","Login"),theme:a,branding:c,client:i,children:p(xs,{theme:a,branding:c,loginSession:s,error:w.t("user_account_does_not_exist"),email:r.username,client:i})}),400):t.html(p(Ss,{theme:a,branding:c,loginSession:s,error:w.t("user_account_does_not_exist"),email:r.username,client:i}),400)}if(s.authParams.username=u,await e.data.loginSessions.update(i.tenant.id,s.id,s),await Ox(t,i,r.username,r.login_selection))return t.redirect(`/u/enter-password?state=${n}`);let m=Zn(),y=await e.data.codes.get(i.tenant.id,m,"otp");for(;y;)m=Zn(),y=await e.data.codes.get(i.tenant.id,m,"otp");const v=await t.env.data.codes.create(i.tenant.id,{code_id:m,code_type:"otp",login_id:s.id,expires_at:new Date(Date.now()+hs).toISOString(),redirect_uri:s.authParams.redirect_uri}),b=i.connections.find(R=>R.strategy===f);if(!b)throw new S(400,{message:w.t("connection_not_found",{connection:f})});const A=(T=(U=(O=s.authParams)==null?void 0:O.ui_locales)==null?void 0:U.split(" "))==null?void 0:T.map(R=>R.split("-")[0])[0];return f==="email"&&b.options.authentication_method==="magic_link"?await Lp(t,{to:u,code:v.code_id,authParams:s.authParams,language:A}):await Bp(t,{to:u,code:v.code_id,language:A}),t.redirect(`/u/enter-code?state=${n}`)}),It=t=>p("a",{className:"block text-primary hover:text-primaryHover text-center",href:`/u/login/identifier?state=${t.state}`,children:w.t("go_back")});var $o="_hp",Fx={Change:"Input",DoubleClick:"DblClick"},qx={svg:"2000/svg",math:"1998/Math/MathML"},ko=[],cu=new WeakMap,_i=void 0,Hx=()=>_i,kn=t=>"t"in t,gl={onClick:["click",!1]},Hg=t=>{if(!t.startsWith("on"))return;if(gl[t])return gl[t];const e=t.match(/^on([A-Z][a-zA-Z]+?(?:PointerCapture)?)(Capture)?$/);if(e){const[,n,r]=e;return gl[t]=[(Fx[n]||n).toLowerCase(),!!r]}},Vg=(t,e)=>_i&&t instanceof SVGElement&&/[A-Z]/.test(e)&&(e in t.style||e.match(/^(?:o|pai|str|u|ve)/))?e.replace(/([A-Z])/g,"-$1").toLowerCase():e,Vx=(t,e,n)=>{var r;e||(e={});for(let i in e){const s=e[i];if(i!=="children"&&(!n||n[i]!==s)){i=Aa(i);const a=Hg(i);if(a){if((n==null?void 0:n[i])!==s&&(n&&t.removeEventListener(a[0],n[i],a[1]),s!=null)){if(typeof s!="function")throw new Error(`Event handler for "${i}" is not a function`);t.addEventListener(a[0],s,a[1])}}else if(i==="dangerouslySetInnerHTML"&&s)t.innerHTML=s.__html;else if(i==="ref"){let c;typeof s=="function"?c=s(t)||(()=>s(null)):s&&"current"in s&&(s.current=t,c=()=>s.current=null),cu.set(t,c)}else if(i==="style"){const c=t.style;typeof s=="string"?c.cssText=s:(c.cssText="",s!=null&&Gy(s,c.setProperty.bind(c)))}else{if(i==="value"){const l=t.nodeName;if(l==="INPUT"||l==="TEXTAREA"||l==="SELECT"){if(t.value=s==null||s===!1?null:s,l==="TEXTAREA"){t.textContent=s;continue}else if(l==="SELECT"){t.selectedIndex===-1&&(t.selectedIndex=0);continue}}}else(i==="checked"&&t.nodeName==="INPUT"||i==="selected"&&t.nodeName==="OPTION")&&(t[i]=s);const c=Vg(t,i);s==null||s===!1?t.removeAttribute(c):s===!0?t.setAttribute(c,""):typeof s=="string"||typeof s=="number"?t.setAttribute(c,s):t.setAttribute(c,s.toString())}}}if(n)for(let i in n){const s=n[i];if(i!=="children"&&!(i in e)){i=Aa(i);const a=Hg(i);a?t.removeEventListener(a[0],s,a[1]):i==="ref"?(r=cu.get(t))==null||r():t.removeAttribute(Vg(t,i))}}},Kx=(t,e)=>{e[Le][0]=0,ko.push([t,e]);const n=e.tag[bp]||e.tag,r=n.defaultProps?{...n.defaultProps,...e.props}:e.props;try{return[n.call(null,r)]}finally{ko.pop()}},T1=(t,e,n,r,i)=>{var s,a;(s=t.vR)!=null&&s.length&&(r.push(...t.vR),delete t.vR),typeof t.tag=="function"&&((a=t[Le][1][L1])==null||a.forEach(c=>i.push(c))),t.vC.forEach(c=>{var l;if(kn(c))n.push(c);else if(typeof c.tag=="function"||c.tag===""){c.c=e;const d=n.length;if(T1(c,e,n,r,i),c.s){for(let u=d;u<n.length;u++)n[u].s=!0;c.s=!1}}else n.push(c),(l=c.vR)!=null&&l.length&&(r.push(...c.vR),delete c.vR)})},Gx=t=>{for(;;t=t.tag===$o||!t.vC||!t.pP?t.nN:t.vC[0]){if(!t)return null;if(t.tag!==$o&&t.e)return t.e}},P1=t=>{var e,n,r,i,s,a;kn(t)||((n=(e=t[Le])==null?void 0:e[1][L1])==null||n.forEach(c=>{var l;return(l=c[2])==null?void 0:l.call(c)}),(r=cu.get(t.e))==null||r(),t.p===2&&((i=t.vC)==null||i.forEach(c=>c.p=2)),(s=t.vC)==null||s.forEach(P1)),t.p||((a=t.e)==null||a.remove(),delete t.e),typeof t.tag=="function"&&(Hi.delete(t),zs.delete(t),delete t[Le][3],t.a=!0)},R1=(t,e,n)=>{t.c=e,B1(t,e,n)},Kg=(t,e)=>{if(e){for(let n=0,r=t.length;n<r;n++)if(t[n]===e)return n}},Gg=Symbol(),B1=(t,e,n)=>{var d;const r=[],i=[],s=[];T1(t,e,r,i,s),i.forEach(P1);const a=n?void 0:e.childNodes;let c,l=null;if(n)c=-1;else if(!a.length)c=0;else{const u=Kg(a,Gx(t.nN));u!==void 0?(l=a[u],c=u):c=Kg(a,(d=r.find(f=>f.tag!==$o&&f.e))==null?void 0:d.e)??-1,c===-1&&(n=!0)}for(let u=0,f=r.length;u<f;u++,c++){const h=r[u];let m;if(h.s&&h.e)m=h.e,h.s=!1;else{const y=n||!h.e;kn(h)?(h.e&&h.d&&(h.e.textContent=h.t),h.d=!1,m=h.e||(h.e=document.createTextNode(h.t))):(m=h.e||(h.e=h.n?document.createElementNS(h.n,h.tag):document.createElement(h.tag)),Vx(m,h.props,h.pP),B1(h,m,y))}h.tag===$o?c--:n?m.parentNode||e.appendChild(m):a[c]!==m&&a[c-1]!==m&&(a[c+1]===m?e.appendChild(a[c]):e.insertBefore(m,l||a[c]||null))}if(t.pP&&delete t.pP,s.length){const u=[],f=[];s.forEach(([,h,,m,y])=>{h&&u.push(h),m&&f.push(m),y==null||y()}),u.forEach(h=>h()),f.length&&requestAnimationFrame(()=>{f.forEach(h=>h())})}},Wx=(t,e)=>!!(t&&t.length===e.length&&t.every((n,r)=>n[1]===e[r][1])),zs=new WeakMap,lu=(t,e,n)=>{var s,a,c,l,d,u;const r=!n&&e.pC;n&&(e.pC||(e.pC=e.vC));let i;try{n||(n=typeof e.tag=="function"?Kx(t,e):Vo(e.props.children)),((s=n[0])==null?void 0:s.tag)===""&&n[0][eu]&&(i=n[0][eu],t[5].push([t,i,e]));const f=r?[...e.pC]:e.vC?[...e.vC]:void 0,h=[];let m;for(let y=0;y<n.length;y++){Array.isArray(n[y])&&n.splice(y,1,...n[y].flat());let v=Jx(n[y]);if(v){typeof v.tag=="function"&&!v.tag[My]&&(gi.length>0&&(v[Le][2]=gi.map(A=>[A,A.values.at(-1)])),(a=t[5])!=null&&a.length&&(v[Le][3]=t[5].at(-1)));let b;if(f&&f.length){const A=f.findIndex(kn(v)?O=>kn(O):v.key!==void 0?O=>O.key===v.key&&O.tag===v.tag:O=>O.tag===v.tag);A!==-1&&(b=f[A],f.splice(A,1))}if(b)if(kn(v))b.t!==v.t&&(b.t=v.t,b.d=!0),v=b;else{const A=b.pP=b.props;if(b.props=v.props,b.f||(b.f=v.f||e.f),typeof v.tag=="function"){const O=b[Le][2];b[Le][2]=v[Le][2]||[],b[Le][3]=v[Le][3],!b.f&&((b.o||b)===v.o||(l=(c=b.tag)[V4])!=null&&l.call(c,A,b.props))&&Wx(O,b[Le][2])&&(b.s=!0)}v=b}else if(!kn(v)&&_i){const A=ji(_i);A&&(v.n=A)}if(!kn(v)&&!v.s&&(lu(t,v),delete v.f),h.push(v),m&&!m.s&&!v.s)for(let A=m;A&&!kn(A);A=(d=A.vC)==null?void 0:d.at(-1))A.nN=v;m=v}}e.vR=r?[...e.vC,...f||[]]:f||[],e.vC=h,r&&delete e.pC}catch(f){if(e.f=!0,f===Gg){if(i)return;throw f}const[h,m,y]=((u=e[Le])==null?void 0:u[3])||[];if(m){const v=()=>As([0,!1,t[2]],y),b=zs.get(y)||[];b.push(v),zs.set(y,b);const A=m(f,()=>{const O=zs.get(y);if(O){const U=O.indexOf(v);if(U!==-1)return O.splice(U,1),v()}});if(A){if(t[0]===1)t[1]=!0;else if(lu(t,y,[A]),(m.length===1||t!==h)&&y.c){R1(y,y.c,!1);return}throw Gg}}throw f}finally{i&&t[5].pop()}},Jx=t=>{if(!(t==null||typeof t=="boolean")){if(typeof t=="string"||typeof t=="number")return{t:t.toString(),d:!0};if("vR"in t&&(t={tag:t.tag,props:t.props,key:t.key,f:t.f,type:t.tag,ref:t.props.ref,o:t.o||t}),typeof t.tag=="function")t[Le]=[0,[]];else{const e=qx[t.tag];e&&(_i||(_i=qy("")),t.props.children=[{tag:_i,props:{value:t.n=`http://www.w3.org/${e}`,children:t.props.children}}])}return t}},Wg=(t,e)=>{var n,r;(n=e[Le][2])==null||n.forEach(([i,s])=>{i.values.push(s)});try{lu(t,e,void 0)}catch{return}if(e.a){delete e.a;return}(r=e[Le][2])==null||r.forEach(([i])=>{i.values.pop()}),(t[0]!==1||!t[1])&&R1(e,e.c,!1)},Hi=new WeakMap,Jg=[],As=async(t,e)=>{t[5]||(t[5]=[]);const n=Hi.get(e);n&&n[0](void 0);let r;const i=new Promise(s=>r=s);if(Hi.set(e,[r,()=>{t[2]?t[2](t,e,s=>{Wg(s,e)}).then(()=>r(e)):(Wg(t,e),r(e))}]),Jg.length)Jg.at(-1).add(e);else{await Promise.resolve();const s=Hi.get(e);s&&(Hi.delete(e),s[1]())}return i},Xx=(t,e,n)=>({tag:$o,props:{children:t},key:n,e,p:1}),ml=0,L1=1,_l=2,yl=3,wl=new WeakMap,U1=(t,e)=>!t||!e||t.length!==e.length||e.some((n,r)=>n!==t[r]),Zx=void 0,Xg=[],Yx=t=>{var a;const e=()=>typeof t=="function"?t():t,n=ko.at(-1);if(!n)return[e(),()=>{}];const[,r]=n,i=(a=r[Le][1])[ml]||(a[ml]=[]),s=r[Le][0]++;return i[s]||(i[s]=[e(),c=>{const l=Zx,d=i[s];if(typeof c=="function"&&(c=c(d[0])),!Object.is(c,d[0]))if(d[0]=c,Xg.length){const[u,f]=Xg.at(-1);Promise.all([u===3?r:As([u,!1,l],r),f]).then(([h])=>{if(!h||!(u===2||u===3))return;const m=h.vC;requestAnimationFrame(()=>{setTimeout(()=>{m===h.vC&&As([u===3?1:0,!1,l],h)})})})}else As([0,!1,l],r)}])},Dp=(t,e)=>{var c;const n=ko.at(-1);if(!n)return t;const[,r]=n,i=(c=r[Le][1])[_l]||(c[_l]=[]),s=r[Le][0]++,a=i[s];return U1(a==null?void 0:a[1],e)?i[s]=[t,e]:t=i[s][0],t},Qx=t=>{const e=wl.get(t);if(e){if(e.length===2)throw e[1];return e[0]}throw t.then(n=>wl.set(t,[n]),n=>wl.set(t,[void 0,n])),t},e8=(t,e)=>{var c;const n=ko.at(-1);if(!n)return t();const[,r]=n,i=(c=r[Le][1])[yl]||(c[yl]=[]),s=r[Le][0]++,a=i[s];return U1(a==null?void 0:a[1],e)&&(i[s]=[t(),e]),i[s][0]},t8=qy({pending:!1,data:null,method:null,action:null}),Zg=new Set,n8=t=>{Zg.add(t),t.finally(()=>Zg.delete(t))},Mp=(t,e)=>e8(()=>n=>{let r;t&&(typeof t=="function"?r=t(n)||(()=>{t(null)}):t&&"current"in t&&(t.current=n,r=()=>{t.current=null}));const i=e(n);return()=>{i==null||i(),r==null||r()}},[t]),Fr=Object.create(null),ls=Object.create(null),Xo=(t,e,n,r,i)=>{if(e!=null&&e.itemProp)return{tag:t,props:e,type:t,ref:e.ref};const s=document.head;let{onLoad:a,onError:c,precedence:l,blocking:d,...u}=e,f=null,h=!1;const m=ws[t];let y;if(m.length>0){const O=s.querySelectorAll(t);e:for(const U of O)for(const T of ws[t])if(U.getAttribute(T)===e[T]){f=U;break e}if(!f){const U=m.reduce((T,R)=>e[R]===void 0?T:`${T}-${R}-${e[R]}`,t);h=!ls[U],f=ls[U]||(ls[U]=(()=>{const T=document.createElement(t);for(const R of m)e[R]!==void 0&&T.setAttribute(R,e[R]),e.rel&&T.setAttribute("rel",e.rel);return T})())}}else y=s.querySelectorAll(t);l=r?l??"":void 0,r&&(u[vs]=l);const v=Dp(O=>{if(m.length>0){let U=!1;for(const T of s.querySelectorAll(t)){if(U&&T.getAttribute(vs)!==l){s.insertBefore(O,T);return}T.getAttribute(vs)===l&&(U=!0)}s.appendChild(O)}else if(y){let U=!1;for(const T of y)if(T===O){U=!0;break}U||s.insertBefore(O,s.contains(y[0])?y[0]:s.querySelector(t)),y=void 0}},[l]),b=Mp(e.ref,O=>{var R;const U=m[0];if(n===2&&(O.innerHTML=""),(h||y)&&v(O),!c&&!a)return;let T=Fr[R=O.getAttribute(U)]||(Fr[R]=new Promise((W,ne)=>{O.addEventListener("load",W),O.addEventListener("error",ne)}));a&&(T=T.then(a)),c&&(T=T.catch(c)),T.catch(()=>{})});if(i&&d==="render"){const O=ws[t][0];if(e[O]){const U=e[O],T=Fr[U]||(Fr[U]=new Promise((R,W)=>{v(f),f.addEventListener("load",R),f.addEventListener("error",W)}));Qx(T)}}const A={tag:t,type:t,props:{...u,ref:b},ref:b};return A.p=n,f&&(A.e=f),Xx(A,s)},r8=t=>{const e=Hx(),n=e&&ji(e);return n!=null&&n.endsWith("svg")?{tag:"title",props:t,type:"title",ref:t.ref}:Xo("title",t,void 0,!1,!1)},i8=t=>!t||["src","async"].some(e=>!t[e])?{tag:"script",props:t,type:"script",ref:t.ref}:Xo("script",t,1,!1,!0),o8=t=>!t||!["href","precedence"].every(e=>e in t)?{tag:"style",props:t,type:"style",ref:t.ref}:(t["data-href"]=t.href,delete t.href,Xo("style",t,2,!0,!0)),s8=t=>!t||["onLoad","onError"].some(e=>e in t)||t.rel==="stylesheet"&&(!("precedence"in t)||"disabled"in t)?{tag:"link",props:t,type:"link",ref:t.ref}:Xo("link",t,1,"precedence"in t,!0),a8=t=>Xo("meta",t,void 0,!1,!1),D1=Symbol(),c8=t=>{const{action:e,...n}=t;typeof e!="function"&&(n.action=e);const[r,i]=Yx([null,!1]),s=Dp(async d=>{const u=d.isTrusted?e:d.detail[D1];if(typeof u!="function")return;d.preventDefault();const f=new FormData(d.target);i([f,!0]);const h=u(f);h instanceof Promise&&(n8(h),await h),i([null,!0])},[]),a=Mp(t.ref,d=>(d.addEventListener("submit",s),()=>{d.removeEventListener("submit",s)})),[c,l]=r;return r[1]=!1,{tag:t8,props:{value:{pending:c!==null,data:c,method:c?"post":null,action:c?e:null},children:{tag:"form",props:{...n,ref:a},type:"form",ref:a}},f:l}},M1=(t,{formAction:e,...n})=>{if(typeof e=="function"){const r=Dp(i=>{i.preventDefault(),i.currentTarget.form.dispatchEvent(new CustomEvent("submit",{detail:{[D1]:e}}))},[]);n.ref=Mp(n.ref,i=>(i.addEventListener("click",r),()=>{i.removeEventListener("click",r)}))}return{tag:t,props:n,type:t,ref:n.ref}},l8=t=>M1("input",t),d8=t=>M1("button",t);Object.assign(tu,{title:r8,script:i8,style:o8,link:s8,meta:a8,form:c8,input:l8,button:d8});Hy(null);new TextEncoder;const Yn=t=>{const{i18nKey:e,values:n,components:r}=t,i=w.t(e,n),s=/<(\d+)>(.*?)<\/\d+>/g,a=[];let c=0,l;for(;(l=s.exec(i))!==null;){const[,d,u]=l,f=i.substring(c,l.index);f&&a.push(f);const h=parseInt(d,10);a.push(ok(r[h],{},u)),c=s.lastIndex}return c<i.length&&a.push(i.substring(c)),p(Mc,{children:a})},Yg=6,du=({error:t,theme:e,branding:n,email:r,state:i,client:s,hasPasswordLogin:a})=>{const c=new URLSearchParams({state:i}),d=s.connections.map(({name:u})=>u).includes("auth2");return p(De,{title:w.t("verify_your_email"),theme:e,branding:n,client:s,children:[p("div",{className:"mb-4 text-2xl font-medium",children:w.t("verify_your_email")}),p("div",{className:"mb-8 text-gray-300",children:p(Yn,{i18nKey:"code_sent_template",components:[p("span",{className:"text-black dark:text-white"},"span")],values:{username:r}})}),p("div",{className:"flex flex-1 flex-col justify-center",children:[p(on,{className:"pt-2",children:[p("input",{autoFocus:!0,type:"text",pattern:"[0-9]*",maxLength:Yg,inputMode:"numeric",name:"code",placeholder:"******",className:ge("mb-2 w-full rounded-lg border bg-gray-100 px-4 pb-2 pt-2.5 text-center indent-[5px] font-mono text-3xl placeholder:text-gray-300 dark:bg-gray-600 md:text-3xl",{"border-red":t,"border-gray-100 dark:border-gray-500":!t}),minLength:Yg,required:!0,id:"code-input"}),t&&p(et,{children:t}),p(Ue,{className:"sm:mt-4 !text-base",children:[p("span",{children:w.t("login")}),p(Ke,{className:"text-xs",name:"arrow-right"})]}),p("div",{className:"my-4 flex space-x-2 text-sm text-[#B2B2B2]",children:[p(Ke,{className:"text-base",name:"info-bubble"}),p("div",{className:"text-sm text-gray-300 md:text-sm",children:w.t("sent_code_spam")})]}),d&&p("div",{className:"text-center mb-12",children:[p("div",{className:"relative mb-5 block text-center text-gray-300 dark:text-gray-300",children:[p("div",{className:"absolute left-0 right-0 top-1/2 border-b border-gray-200 dark:border-gray-600"}),p("div",{className:"relative inline-block bg-white px-2 dark:bg-gray-800",children:w.t("or")})]}),p(Ue,{Component:"a",href:`/u/${a?"enter-password":"pre-signup"}?${c.toString()}`,variant:"secondary",className:"block",children:w.t("enter_your_password_btn")})]})]}),p(It,{state:i})]})]})},u8=({maxLength:t,value:e="",disabled:n=!1,className:r,containerClassName:i,name:s,id:a,required:c,autoFocus:l})=>p("div",{className:ge("flex items-center gap-2 has-[:disabled]:opacity-50",i),"data-input-otp-container":"",children:Array.from({length:t}).map((d,u)=>p("input",{type:"text",inputMode:"numeric",maxLength:1,value:e[u]||"",disabled:n,name:u===0?s:void 0,id:u===0?a:void 0,required:u===0?c:void 0,autoFocus:u===0?l:void 0,className:ge("relative flex h-9 w-9 items-center justify-center border-y border-r border-input text-sm shadow-sm transition-all first:rounded-l-md first:border-l last:rounded-r-md text-center font-mono","focus:z-10 focus:ring-1 focus:ring-ring","disabled:cursor-not-allowed disabled:opacity-50",r),"data-input-otp-slot":u},u))}),p8=6,Qg=({error:t,theme:e,branding:n,email:r,state:i,hasPasswordLogin:s,className:a})=>{var C,z,k,$,I,L,q,F,Z,se,D,fe,$e,ce,ue,Ae,Ee,Re,Se,Te;const c=new URLSearchParams({state:i}),l=((C=e==null?void 0:e.colors)==null?void 0:C.primary_button)||((z=n==null?void 0:n.colors)==null?void 0:z.primary)||"#0066cc",d=((k=e==null?void 0:e.colors)==null?void 0:k.primary_button_label)||"#ffffff",u=(($=e==null?void 0:e.colors)==null?void 0:$.body_text)||"#333333",f=((I=e==null?void 0:e.colors)==null?void 0:I.input_border)||"#d1d5db",h=((L=e==null?void 0:e.colors)==null?void 0:L.widget_background)||"#ffffff",m=((q=e==null?void 0:e.colors)==null?void 0:q.widget_border)||"#e5e7eb",y=((F=e==null?void 0:e.borders)==null?void 0:F.widget_corner_radius)||8,v=((Z=e==null?void 0:e.borders)==null?void 0:Z.button_border_radius)||4,b=((se=e==null?void 0:e.borders)==null?void 0:se.show_widget_shadow)??!0,A=((fe=(D=e==null?void 0:e.fonts)==null?void 0:D.title)==null?void 0:fe.size)||24,O=((ce=($e=e==null?void 0:e.fonts)==null?void 0:$e.title)==null?void 0:ce.bold)??!0,U=((Ae=(ue=e==null?void 0:e.fonts)==null?void 0:ue.body_text)==null?void 0:Ae.size)||14,T={backgroundColor:h,borderColor:m,borderRadius:`${y}px`,boxShadow:b?"0 1px 3px 0 rgba(0, 0, 0, 0.1)":"none",color:u},R={fontSize:`${A}px`,fontWeight:O?"700":"400",color:((Ee=e==null?void 0:e.colors)==null?void 0:Ee.header)||u},W={fontSize:`${U}px`,color:((Re=e==null?void 0:e.colors)==null?void 0:Re.input_labels_placeholders)||"#6b7280"},ne={backgroundColor:l,color:d,borderRadius:`${v}px`},Q=((Se=e==null?void 0:e.widget)==null?void 0:Se.logo_position)||"center",K=Q==="left"?"text-left":Q==="right"?"text-right":"text-center",de=((Te=e==null?void 0:e.widget)==null?void 0:Te.logo_url)||(n==null?void 0:n.logo_url),N=Q!=="none"&&de;return p("div",{className:ge("flex flex-col gap-6 w-full max-w-sm",a),children:[p(_n,{style:T,className:"border",children:[p(yn,{children:[N&&p("div",{className:ge("mb-4",K),children:p(rn,{theme:e,branding:n})}),p(wn,{style:R,children:w.t("verify_your_email","Verify your email")}),p(vn,{style:W,children:p(Yn,{i18nKey:"code_sent_template",components:[p("span",{className:"font-medium"},"span")],values:{username:r}})})]}),p(bn,{children:p("form",{method:"post",children:p("div",{className:"grid gap-6",children:[p("div",{className:"grid gap-4",children:[p(Lt,{htmlFor:"code",style:W,children:w.t("verification_code","Verification Code")}),p("div",{className:"flex justify-center",children:p(u8,{maxLength:p8,name:"code",id:"code",required:!0,autoFocus:!0,containerClassName:"gap-2",className:ge("w-12 h-12 text-center text-lg font-mono border rounded-md transition-colors",t?"border-red-500 focus:ring-red-500":"border-gray-300 focus:ring-blue-500 focus:border-blue-500")})}),t&&p(et,{children:t})]}),p(fn,{type:"submit",className:"w-full transition-colors hover:brightness-90",style:ne,children:w.t("login","Login")}),p("div",{className:"text-center text-xs text-gray-500",children:p("div",{className:"flex items-center justify-center gap-1",children:[p("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20",children:p("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z",clipRule:"evenodd"})}),p("span",{children:w.t("sent_code_spam","Check your spam folder if you don't see the code")})]})}),s&&p("div",{className:"text-center",children:[p("div",{className:"relative mb-5 block text-center",style:W,children:[p("div",{className:"absolute left-0 right-0 top-1/2 border-b",style:{borderColor:m}}),p("div",{className:"relative inline-block px-2",style:{backgroundColor:h},children:w.t("or","Or")})]}),p("a",{href:`/u/${s?"enter-password":"pre-signup"}?${c.toString()}`,className:ge("w-full inline-flex items-center justify-center gap-2 rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500","border border-gray-300 bg-transparent hover:bg-gray-100 dark:border-gray-600 dark:hover:bg-gray-800","h-10 px-4 py-2"),style:{borderColor:f,borderRadius:`${v}px`,color:u},children:w.t("enter_your_password_btn","Enter your password instead")})]})]})})})]}),p(It,{state:i})]})},Dt=t=>{const{message:e,theme:n,branding:r,client:i,pageTitle:s,state:a}=t;return p(De,{title:"Login",theme:n,branding:r,client:i,children:[s?p("div",{className:"mb-4 text-2xl font-medium",children:s}):"",p("div",{className:"text-gray-300 mb-12",children:e}),a?p(It,{state:a}):""]})},f8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state"}),style:o.z.enum(["classic","shadcn"]).optional().openapi({description:"UI style to use for the enter code page"})})},responses:{200:{description:"HTML page to enter verification code.",content:{"text/html":{schema:o.z.string()}}},400:{description:"Bad Request - HTML error page if username is missing in state.",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{const{state:e,style:n}=t.req.valid("query");let r,i,s,a,c;n&&Jh(t,"auth_ui_style",n,{path:"/",maxAge:60*60*24*365,httpOnly:!0,secure:!0,sameSite:"Lax"});try{if({theme:r,branding:i,loginSession:s,client:a,useShadcn:c}=await Ce(t,e),!s.authParams.username)return t.html(p(Dt,{theme:r,branding:i,client:a,state:e,pageTitle:w.t("error_page_title")||"Error",message:w.t("username_not_found_error")||"Username not found in session."}),400);const l=await io({userAdapter:t.env.data.users,tenant_id:a.tenant.id,username:s.authParams.username,provider:"auth2"});return c?t.html(p(Oe,{title:w.t("verify_your_email","Verify your email"),theme:r,branding:i,client:a,children:p(Qg,{theme:r,branding:i,email:s.authParams.username,state:e,hasPasswordLogin:!!l})})):t.html(p(du,{theme:r,branding:i,email:s.authParams.username,state:e,client:a,hasPasswordLogin:!!l}))}catch(l){return console.error("Error in GET /u/enter-code:",l),i||(i=null),r||(r=null),a||(a=null),t.html(p(Dt,{theme:r,branding:i,client:a,state:e,pageTitle:w.t("error_page_title")||"Error",message:w.t("unexpected_error_try_again")||"An unexpected error occurred. Please try again."}),500)}}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state"}),style:o.z.enum(["classic","shadcn"]).optional().openapi({description:"UI style to use for the enter code page"})}),body:{content:{"application/x-www-form-urlencoded":{schema:o.z.object({code:o.z.string()})}}}},responses:{302:{description:"Redirect to continue authentication flow.",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML page with an error message (e.g., invalid code, username missing).",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page for unexpected issues.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{var d,u;const{state:e,style:n}=t.req.valid("query"),{code:r}=t.req.valid("form");n&&Jh(t,"auth_ui_style",n,{path:"/",maxAge:60*60*24*365,httpOnly:!0,secure:!0,sameSite:"Lax"});const{theme:i,branding:s,client:a,loginSession:c,useShadcn:l}=await Ce(t,e);if(!c.authParams.username)throw new S(400,{message:w.t("username_not_found_error")||"Username not found in session."});try{t.set("client_id",a.client_id);const f=await Op(t,{client_id:a.client_id,authParams:c.authParams,username:c.authParams.username,otp:r});if(f instanceof Response)return f;throw new S(500,{message:w.t("unexpected_error_try_again")||"An unexpected error occurred. Please try again."})}catch(f){let h;try{h=await io({userAdapter:t.env.data.users,tenant_id:a.tenant.id,username:c.authParams.username,provider:"auth2"})}catch{h=null}return l?t.html(p(Oe,{title:w.t("verify_your_email","Verify your email"),theme:i,branding:s,client:a,children:p(Qg,{theme:i,branding:s,email:(d=c.authParams)==null?void 0:d.username,state:e,error:f.message,hasPasswordLogin:!!h})}),400):t.html(p(du,{theme:i,branding:s,email:(u=c.authParams)==null?void 0:u.username,state:e,client:a,error:f.message,hasPasswordLogin:!!h}),400)}}),F1=t=>{const{theme:e,branding:n,client:r,state:i}=t;return p(De,{title:w.t("unverified_email"),theme:e,branding:n,client:r,children:[p("div",{className:"flex flex-1 flex-col justify-center",children:[p("p",{className:"mb-8 text-gray-300 text-lg",children:w.t("unverified_email")}),p("div",{className:"my-4 flex space-x-2 text-sm text-[#B2B2B2]",children:[p(Ke,{className:"text-base",name:"info-bubble"}),p("div",{className:"text-sm text-gray-300 md:text-sm",children:w.t("sent_code_spam")})]}),p(It,{state:i})]}),p(It,{state:i})]})},h8=({width:t=22,height:e=17})=>p("svg",{width:t,height:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 576 512",children:p("path",{fill:"currentColor",d:"M288 32c-80.8 0-145.5 36.8-192.6 80.6C48.6 156 17.3 208 2.5 243.7c-3.3 7.9-3.3 16.7 0 24.6C17.3 304 48.6 356 95.4 399.4 142.5 443.2 207.2 480 288 480s145.5-36.8 192.6-80.6c46.8-43.5 78.1-95.4 93-131.1 3.3-7.9 3.3-16.7 0-24.6-14.9-35.7-46.2-87.7-93-131.1C433.5 68.8 368.8 32 288 32M144 256a144 144 0 1 1 288 0 144 144 0 1 1-288 0m144-64c0 35.3-28.7 64-64 64-7.1 0-13.9-1.2-20.3-3.3-5.5-1.8-11.9 1.6-11.7 7.4.3 6.9 1.3 13.8 3.2 20.7 13.7 51.2 66.4 81.6 117.6 67.9s81.6-66.4 67.9-117.6c-11.1-41.5-47.8-69.4-88.6-71.1-5.8-.2-9.2 6.1-7.4 11.7 2.1 6.4 3.3 13.2 3.3 20.3"})}),g8=({width:t=23,height:e=18})=>p("svg",{width:t,height:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 512",children:p("path",{fill:"currentColor",d:"M38.8 5.1C28.4-3.1 13.3-1.2 5.1 9.2s-6.3 25.5 4.1 33.7l592 464c10.4 8.2 25.5 6.3 33.7-4.1s6.3-25.5-4.1-33.7l-105.2-82.4c39.6-40.6 66.4-86.1 79.9-118.4 3.3-7.9 3.3-16.7 0-24.6-14.9-35.7-46.2-87.7-93-131.1C465.5 68.8 400.8 32 320 32c-68.2 0-125 26.3-169.3 60.8zm184.3 144.4c25.5-23.3 59.6-37.5 96.9-37.5 79.5 0 144 64.5 144 144 0 24.9-6.3 48.3-17.4 68.7L408 294.5c8.4-19.3 10.6-41.4 4.8-63.3-11.1-41.5-47.8-69.4-88.6-71.1-5.8-.2-9.2 6.1-7.4 11.7 2.1 6.4 3.3 13.2 3.3 20.3 0 10.2-2.4 19.8-6.6 28.3l-90.3-70.8zM373 389.9c-16.4 6.5-34.3 10.1-53 10.1-79.5 0-144-64.5-144-144 0-6.9.5-13.6 1.4-20.2l-94.3-74.3c-22.8 29.7-39.1 59.3-48.6 82.2-3.3 7.9-3.3 16.7 0 24.6 14.9 35.7 46.2 87.7 93 131.1 47 43.8 111.7 80.6 192.5 80.6 47.8 0 89.9-12.9 126.2-32.5z"})}),uu=({name:t,placeholder:e=w.t("password")})=>p("div",{className:"password-input relative mb-2",children:[p("input",{type:"password",name:t,placeholder:e,className:"w-full rounded-lg bg-gray-100 px-4 py-5 text-base placeholder:text-gray-300 dark:bg-gray-600 md:text-base",required:!0}),p("button",{type:"button","aria-label":w.t("show_password"),title:w.t("show_password"),className:"show-password-toggle-show absolute right-0 top-0 w-10 h-full rounded-r-lg text-gray-400 column hover:bg-black/5",children:p(h8,{})}),p("button",{type:"button","aria-label":w.t("hide_password"),title:w.t("hide_password"),className:"show-password-toggle-hide !hidden absolute right-0 top-0 w-10 h-full rounded-r-lg text-gray-400 column hover:bg-black/5",children:p(g8,{})})]});var e0=Object.freeze,m8=Object.defineProperty,_8=(t,e)=>e0(m8(t,"raw",{value:e0(t.slice())})),t0;const Es=t=>{const{error:e,theme:n,branding:r,email:i,state:s,client:a}=t,c=new URLSearchParams({state:s});return p(De,{title:w.t("enter_password"),theme:n,branding:r,client:a,children:[p("div",{className:"mb-4 text-lg font-medium sm:text-2xl",children:w.t("enter_password")}),p("div",{className:"mb-6 text-gray-300",children:w.t("enter_password_description")}),p("div",{className:"flex flex-1 flex-col justify-center",children:[p(on,{className:"mb-7",children:[p("input",{type:"text",name:"username",placeholder:w.t("email_placeholder"),className:"mb-2 w-full rounded-lg bg-gray-100 px-4 py-5 text-base placeholder:text-gray-300 dark:bg-gray-600 md:text-base",value:i}),p(uu,{name:"password"}),e&&p(et,{children:e}),p(Ue,{className:"sm:mt-4 !text-base",children:[p("span",{children:w.t("login")}),p(Ke,{className:"text-xs",name:"arrow-right"})]})]}),p("a",{href:`/u/forgot-password?${c.toString()}`,className:"text-primary hover:underline mb-4",children:w.t("forgot_password_link")}),p("div",{className:"text-center mb-12",children:[p("div",{className:"relative mb-5 block text-center text-gray-300 dark:text-gray-300",children:[p("div",{className:"absolute left-0 right-0 top-1/2 border-b border-gray-200 dark:border-gray-600"}),p("div",{className:"relative inline-block bg-white px-2 dark:bg-gray-800",children:w.t("or")})]}),p("form",{method:"post",action:`/u/login/identifier?${c.toString()}`,children:[p("input",{type:"hidden",name:"login_selection",value:"code"}),p("input",{type:"hidden",name:"username",value:i}),p(Ue,{variant:"secondary",className:"block",children:w.t("enter_a_code_btn")})]})]}),p(It,{state:s})]}),H4(t0||(t0=_8([`
209
+ `},Lx="https://assets.sesamy.com/images/login-bg.jpg",De=({title:t,children:e,theme:n,branding:r,client:i})=>{var a;const s={backgroundImage:`url(${((a=n==null?void 0:n.page_background)==null?void 0:a.background_image_url)||Lx})`};return p("html",{lang:"en",children:[p("head",{children:[p("title",{children:t}),p("meta",{charset:"UTF-8"}),p("meta",{name:"robots",content:"noindex, follow"}),p("link",{rel:"preload",href:"https://assets.sesamy.com/fonts/khteka/WOFF2/KHTeka-Regular.woff2",as:"font",type:"font/woff2",crossOrigin:"anonymous"}),p("link",{rel:"preload",href:"https://assets.sesamy.com/fonts/khteka/WOFF2/KHTeka-Medium.woff2",as:"font",type:"font/woff2",crossOrigin:"anonymous"}),p("link",{rel:"preload",href:"https://assets.sesamy.com/fonts/khteka/WOFF2/KHTeka-Bold.woff2",as:"font",type:"font/woff2",crossOrigin:"anonymous"}),p("link",{rel:"stylesheet",href:"/u/css/tailwind.css"}),p("meta",{name:"viewport",content:"width=device-width, initial-scale=1, maximum-scale=1"}),p("style",{children:Bx(n,r)}),p("meta",{name:"theme-color",content:"#000000"})]}),p("body",{children:[p("div",{className:"row min-h-full w-full overflow-hidden bg-cover bg-center text-sm sm:bg-fixed sm:bg-left-top sm:pt-16 py-2",style:s,children:p("div",{className:"row-up-left w-[calc(100%-theme(space.2)-theme(space.2))] max-w-[1295px] !flex-nowrap sm:w-[calc(100%-theme(space.16)-theme(space.16))]",children:p("div",{className:"column-left w-full sm:w-auto",children:[p("div",{className:"relative flex w-full flex-col rounded-2xl bg-white px-5 py-10 dark:bg-gray-800 dark:text-white sm:min-h-[700px] sm:max-w-md sm:px-14 sm:py-14 md:min-w-[448px] short:min-h-[558px] min-h-[calc(100vh-83px)]",children:[p("div",{className:"mb-16",children:p(nn,{theme:n,branding:r})}),p("div",{className:"flex flex-1 flex-col",children:[e,p(I1,{theme:n,branding:r,client:i})]})]}),p("div",{className:"flex w-full items-center px-6 pb-8 pt-4 justify-between",children:[p("div",{className:"flex justify-center leading-[0]",children:p("a",{href:"https://sesamy.com",target:"_blank",rel:"noreferrer",children:p(Ke,{name:"sesamy",className:"text-xl text-white"})})}),p("div",{className:"flex justify-center space-x-2 text-xs text-white sm:justify-normal md:text-xs"})]})]})})}),p("div",{id:"client-root"})]}),p("script",{type:"module",src:"/u/js/client.js"})]})},Ux=t=>t==="small"?"text-base":t==="medium"?"text-2xl":t==="large"?"text-3xl":"",j1=({size:t})=>{const e=Ux(t);return p("div",{className:"relative inline-block leading-[0]",children:[p(Ke,{className:ge("text-gray-200 dark:text-[#201a41]",{[e]:e}),name:"spinner-circle"}),p(Ke,{className:ge("absolute inset-0 animate-spin text-primary",{[e]:e}),name:"spinner-inner"})]})},Ue=({children:t,className:e,Component:n="button",variant:r="primary",href:i,disabled:s,isLoading:a,id:c})=>{const l=n==="a"?{href:i}:{};return p(n,{class:ge("btn relative w-full rounded-lg text-center",{"px-4 py-5":r!=="custom","bg-primary text-textOnPrimary hover:bg-primaryHover":r==="primary","border border-gray-300 bg-white text-black":r==="secondary","pointer-events-none cursor-not-allowed opacity-40":s,"is-loading":a},"focus:outline-none focus:ring",e),type:"submit",disabled:s,id:c,...l,children:[p("span",{className:"btn-label flex items-center justify-center space-x-2",children:t}),p("div",{className:"btn-spinner absolute left-0 top-0 flex h-full w-full items-center justify-center",children:p(j1,{size:"medium"})})]})},O1=({connection:t,text:e,icon:n=null,canResize:r=!1,loginSession:i})=>{const s=new URLSearchParams({client_id:i.authParams.client_id,connection:t});i.authParams.response_type&&s.set("response_type",i.authParams.response_type),i.authParams.redirect_uri&&s.set("redirect_uri",i.authParams.redirect_uri),i.authParams.scope&&s.set("scope",i.authParams.scope),i.authParams.nonce&&s.set("nonce",i.authParams.nonce),i.authParams.response_type&&s.set("response_type",i.authParams.response_type),i.authParams.state&&s.set("state",i.id);const a=`/authorize?${s.toString()}`;return p(Ue,{className:ge("border border-gray-200 bg-white hover:bg-gray-100 dark:border-gray-400 dark:bg-black dark:hover:bg-black/90",{"px-0 py-3 sm:px-10 sm:py-4 short:px-0 short:py-3":r,"px-10 py-3":!r}),variant:"custom","aria-label":e,Component:"a",href:a,children:[n||"",p("div",{className:ge("text-left text-black dark:text-white sm:text-base",{"hidden sm:inline short:hidden":r}),children:e})]})},rn=({children:t,className:e})=>p("form",{id:"form",method:"post",className:e,children:t}),Ss=({error:t,theme:e,branding:n,loginSession:r,email:i,client:s})=>{const a=s.connections.map(({strategy:b})=>b),c=a.includes("email")||a.includes("Username-Password-Authentication"),l=a.includes("sms"),d=a.map(b=>{const A=p1(b);return A?{name:b,...A}:null}).filter(b=>b!==null),u=c||l;let f="text",h="username";const m=c&&l?"email_or_phone_placeholder":c?"email_placeholder":"phone_placeholder";let y=w.t(m,c&&l?"Email or Phone Number":c?"Email Address":"Phone Number");return p(De,{title:w.t("welcome"),theme:e,branding:n,client:s,children:[p("div",{className:"mb-4 text-lg font-medium sm:text-2xl",children:w.t("welcome")}),p("div",{className:"mb-8 text-gray-300",children:w.t("login_description_template",{authMethod:w.t(m,{defaultValue:c&&l?"email or phone number":c?"email address":"phone number"}).toLocaleLowerCase(),defaultValue:"Sign in with your {{authMethod}}"})}),p("div",{className:"flex flex-1 flex-col justify-center",children:[u&&p(rn,{className:"mb-7",children:[p("input",{type:f,name:h,placeholder:y,className:ge("mb-2 w-full rounded-lg border bg-gray-100 px-4 py-5 text-base placeholder:text-gray-300 dark:bg-gray-600 md:text-base",{"border-red":t,"border-gray-100 dark:border-gray-500":!t}),required:!0,value:i||""}),t&&p(et,{children:t}),p(Ue,{className:"sm:mt-4 !text-base",children:[p("span",{children:w.t("continue")}),p(Ke,{className:"text-xs",name:"arrow-right"})]})]}),u&&d.length>0&&p("div",{className:"relative mb-5 block text-center text-gray-300 dark:text-gray-300",children:[p("div",{className:"absolute left-0 right-0 top-1/2 border-b border-gray-200 dark:border-gray-600"}),p("div",{className:"relative inline-block bg-white px-2 dark:bg-gray-800",children:w.t("continue_social_login")})]}),p("div",{className:"flex space-x-4 sm:flex-col sm:space-x-0 sm:space-y-4 short:flex-row short:space-x-4 short:space-y-0",children:d.map(b=>{const A=b.logo;return p(O1,{connection:b.name,text:w.t("continue_with",{provider:b.displayName}),canResize:!0,icon:p(A,{className:"h-5 w-5 sm:absolute sm:left-4 sm:top-1/2 sm:h-6 sm:w-6 sm:-translate-y-1/2 short:static short:left-auto short:top-auto short:h-5 short:w-5 short:translate-y-0"}),loginSession:r},b.name)})})]})]})},Dx="https://assets.sesamy.com/images/login-bg.jpg",Oe=({title:t,children:e,theme:n,branding:r})=>{var v,b,A,O;const i=((v=n==null?void 0:n.page_background)==null?void 0:v.page_layout)||"center",s=((b=n==null?void 0:n.page_background)==null?void 0:b.background_color)||"#ffffff",a=(A=n==null?void 0:n.page_background)==null?void 0:A.background_image_url,c=a??Dx,l=(c==null?void 0:c.startsWith("linear-gradient"))||(c==null?void 0:c.startsWith("radial-gradient"))||(c==null?void 0:c.startsWith("conic-gradient")),d=c?l?c:`url(${c})`:void 0;let u="justify-center",f="p-6 md:p-10";i==="left"?(u="justify-start",f="pl-12 pr-6 py-6 md:pl-20 md:pr-10 md:py-10"):i==="right"&&(u="justify-end",f="pr-12 pl-6 py-6 md:pr-20 md:pl-10 md:py-10");const h=ge("min-h-screen w-full flex bg-cover bg-center",u,f),m={...d&&{backgroundImage:d},backgroundColor:s,display:"flex",alignItems:"stretch",justifyContent:i==="left"?"flex-start":i==="right"?"flex-end":"center",minHeight:"100vh",width:"100%"},y=ge("w-full max-w-sm","flex flex-col justify-center");return p("html",{lang:"en",children:[p("head",{children:[p("title",{children:t}),p("meta",{charset:"UTF-8"}),p("meta",{name:"robots",content:"noindex, follow"}),p("link",{rel:"stylesheet",href:"/u/css/tailwind.css"}),p("link",{rel:"stylesheet",href:"/u/css/shadcn-ui.css"}),p("meta",{name:"viewport",content:"width=device-width, initial-scale=1, maximum-scale=1"}),p("meta",{name:"theme-color",content:"#000000"}),(r==null?void 0:r.favicon_url)&&p("link",{rel:"icon",type:"image/x-icon",href:r.favicon_url}),((O=n==null?void 0:n.fonts)==null?void 0:O.font_url)&&p("link",{rel:"stylesheet",href:n.fonts.font_url})]}),p("body",{children:[p("div",{className:h,style:m,children:p("div",{className:y,children:[e,(r==null?void 0:r.powered_by_logo_url)&&p("div",{className:"mt-5 text-left",children:p("a",{href:"https://authhero.com",target:"_blank",rel:"noopener noreferrer",className:"inline-block",children:p("img",{src:r.powered_by_logo_url,alt:"Powered by",className:"h-9 opacity-60 hover:opacity-100 transition-opacity"})})})]})}),p("div",{id:"client-root"}),p("script",{type:"module",src:"/u/js/client.js"})]})]})},Mx=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"}),impersonation:o.z.string().optional()})},responses:{200:{description:"Response"}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,loginSession:i,client:s,useShadcn:a}=await Ce(t,e);return a?t.html(p(Oe,{title:w.t("welcome","Login"),theme:n,branding:r,client:s,children:p(xs,{theme:n,branding:r,loginSession:i,client:s,email:i.authParams.username})})):t.html(p(Ss,{theme:n,branding:r,loginSession:i,client:s,email:i.authParams.username}))}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"}),style:o.z.enum(["classic","shadcn"]).optional().openapi({description:"UI style to use for the login page"})}),body:{content:{"application/x-www-form-urlencoded":{schema:o.z.object({username:o.z.string().transform(t=>t.toLowerCase()),login_selection:o.z.enum(["code","password"]).optional()})}}}},responses:{400:{description:"Error response"},302:{description:"Redirect to enter code or password"}}}),async t=>{var O,U,T;const{env:e}=t,{state:n}=t.req.valid("query"),r=t.req.valid("form");t.set("body",r),t.set("username",r.username);const{client:i,loginSession:s,theme:a,branding:c,useShadcn:l}=await Ce(t,n);t.set("client_id",i.client_id);const d=t.get("countryCode"),{normalized:u,connectionType:f}=Vc(r.username,d);if(!i.connections.find(R=>R.strategy===f)||!u)return l?t.html(p(Oe,{title:w.t("welcome","Login"),theme:a,branding:c,client:i,children:p(xs,{theme:a,branding:c,loginSession:s,error:w.t("invalid_identifier"),email:r.username,client:i})}),400):t.html(p(Ss,{theme:a,branding:c,loginSession:s,error:w.t("invalid_identifier"),email:r.username,client:i}),400);const h=await io({userAdapter:e.data.users,tenant_id:i.tenant.id,username:u,provider:f});if(h&&t.set("user_id",h.user_id),!h)try{await Lm(t,i,t.env.data,u)}catch{const R=be(t,{type:_e.FAILED_SIGNUP,description:"Public signup is disabled"});return ve(t,t.env.data.logs.create(i.tenant.id,R)),l?t.html(p(Oe,{title:w.t("welcome","Login"),theme:a,branding:c,client:i,children:p(xs,{theme:a,branding:c,loginSession:s,error:w.t("user_account_does_not_exist"),email:r.username,client:i})}),400):t.html(p(Ss,{theme:a,branding:c,loginSession:s,error:w.t("user_account_does_not_exist"),email:r.username,client:i}),400)}if(s.authParams.username=u,await e.data.loginSessions.update(i.tenant.id,s.id,s),await Ox(t,i,r.username,r.login_selection))return t.redirect(`/u/enter-password?state=${n}`);let m=Zn(),y=await e.data.codes.get(i.tenant.id,m,"otp");for(;y;)m=Zn(),y=await e.data.codes.get(i.tenant.id,m,"otp");const v=await t.env.data.codes.create(i.tenant.id,{code_id:m,code_type:"otp",login_id:s.id,expires_at:new Date(Date.now()+hs).toISOString(),redirect_uri:s.authParams.redirect_uri}),b=i.connections.find(R=>R.strategy===f);if(!b)throw new S(400,{message:w.t("connection_not_found",{connection:f})});const A=(T=(U=(O=s.authParams)==null?void 0:O.ui_locales)==null?void 0:U.split(" "))==null?void 0:T.map(R=>R.split("-")[0])[0];return f==="email"&&b.options.authentication_method==="magic_link"?await Lp(t,{to:u,code:v.code_id,authParams:s.authParams,language:A}):await Bp(t,{to:u,code:v.code_id,language:A}),t.redirect(`/u/enter-code?state=${n}`)}),Nt=t=>p("a",{className:"block text-primary hover:text-primaryHover text-center",href:`/u/login/identifier?state=${t.state}`,children:w.t("go_back")});var $o="_hp",Fx={Change:"Input",DoubleClick:"DblClick"},qx={svg:"2000/svg",math:"1998/Math/MathML"},ko=[],cu=new WeakMap,_i=void 0,Hx=()=>_i,kn=t=>"t"in t,gl={onClick:["click",!1]},Hg=t=>{if(!t.startsWith("on"))return;if(gl[t])return gl[t];const e=t.match(/^on([A-Z][a-zA-Z]+?(?:PointerCapture)?)(Capture)?$/);if(e){const[,n,r]=e;return gl[t]=[(Fx[n]||n).toLowerCase(),!!r]}},Vg=(t,e)=>_i&&t instanceof SVGElement&&/[A-Z]/.test(e)&&(e in t.style||e.match(/^(?:o|pai|str|u|ve)/))?e.replace(/([A-Z])/g,"-$1").toLowerCase():e,Vx=(t,e,n)=>{var r;e||(e={});for(let i in e){const s=e[i];if(i!=="children"&&(!n||n[i]!==s)){i=Aa(i);const a=Hg(i);if(a){if((n==null?void 0:n[i])!==s&&(n&&t.removeEventListener(a[0],n[i],a[1]),s!=null)){if(typeof s!="function")throw new Error(`Event handler for "${i}" is not a function`);t.addEventListener(a[0],s,a[1])}}else if(i==="dangerouslySetInnerHTML"&&s)t.innerHTML=s.__html;else if(i==="ref"){let c;typeof s=="function"?c=s(t)||(()=>s(null)):s&&"current"in s&&(s.current=t,c=()=>s.current=null),cu.set(t,c)}else if(i==="style"){const c=t.style;typeof s=="string"?c.cssText=s:(c.cssText="",s!=null&&Gy(s,c.setProperty.bind(c)))}else{if(i==="value"){const l=t.nodeName;if(l==="INPUT"||l==="TEXTAREA"||l==="SELECT"){if(t.value=s==null||s===!1?null:s,l==="TEXTAREA"){t.textContent=s;continue}else if(l==="SELECT"){t.selectedIndex===-1&&(t.selectedIndex=0);continue}}}else(i==="checked"&&t.nodeName==="INPUT"||i==="selected"&&t.nodeName==="OPTION")&&(t[i]=s);const c=Vg(t,i);s==null||s===!1?t.removeAttribute(c):s===!0?t.setAttribute(c,""):typeof s=="string"||typeof s=="number"?t.setAttribute(c,s):t.setAttribute(c,s.toString())}}}if(n)for(let i in n){const s=n[i];if(i!=="children"&&!(i in e)){i=Aa(i);const a=Hg(i);a?t.removeEventListener(a[0],s,a[1]):i==="ref"?(r=cu.get(t))==null||r():t.removeAttribute(Vg(t,i))}}},Kx=(t,e)=>{e[Le][0]=0,ko.push([t,e]);const n=e.tag[bp]||e.tag,r=n.defaultProps?{...n.defaultProps,...e.props}:e.props;try{return[n.call(null,r)]}finally{ko.pop()}},T1=(t,e,n,r,i)=>{var s,a;(s=t.vR)!=null&&s.length&&(r.push(...t.vR),delete t.vR),typeof t.tag=="function"&&((a=t[Le][1][L1])==null||a.forEach(c=>i.push(c))),t.vC.forEach(c=>{var l;if(kn(c))n.push(c);else if(typeof c.tag=="function"||c.tag===""){c.c=e;const d=n.length;if(T1(c,e,n,r,i),c.s){for(let u=d;u<n.length;u++)n[u].s=!0;c.s=!1}}else n.push(c),(l=c.vR)!=null&&l.length&&(r.push(...c.vR),delete c.vR)})},Gx=t=>{for(;;t=t.tag===$o||!t.vC||!t.pP?t.nN:t.vC[0]){if(!t)return null;if(t.tag!==$o&&t.e)return t.e}},P1=t=>{var e,n,r,i,s,a;kn(t)||((n=(e=t[Le])==null?void 0:e[1][L1])==null||n.forEach(c=>{var l;return(l=c[2])==null?void 0:l.call(c)}),(r=cu.get(t.e))==null||r(),t.p===2&&((i=t.vC)==null||i.forEach(c=>c.p=2)),(s=t.vC)==null||s.forEach(P1)),t.p||((a=t.e)==null||a.remove(),delete t.e),typeof t.tag=="function"&&(Hi.delete(t),zs.delete(t),delete t[Le][3],t.a=!0)},R1=(t,e,n)=>{t.c=e,B1(t,e,n)},Kg=(t,e)=>{if(e){for(let n=0,r=t.length;n<r;n++)if(t[n]===e)return n}},Gg=Symbol(),B1=(t,e,n)=>{var d;const r=[],i=[],s=[];T1(t,e,r,i,s),i.forEach(P1);const a=n?void 0:e.childNodes;let c,l=null;if(n)c=-1;else if(!a.length)c=0;else{const u=Kg(a,Gx(t.nN));u!==void 0?(l=a[u],c=u):c=Kg(a,(d=r.find(f=>f.tag!==$o&&f.e))==null?void 0:d.e)??-1,c===-1&&(n=!0)}for(let u=0,f=r.length;u<f;u++,c++){const h=r[u];let m;if(h.s&&h.e)m=h.e,h.s=!1;else{const y=n||!h.e;kn(h)?(h.e&&h.d&&(h.e.textContent=h.t),h.d=!1,m=h.e||(h.e=document.createTextNode(h.t))):(m=h.e||(h.e=h.n?document.createElementNS(h.n,h.tag):document.createElement(h.tag)),Vx(m,h.props,h.pP),B1(h,m,y))}h.tag===$o?c--:n?m.parentNode||e.appendChild(m):a[c]!==m&&a[c-1]!==m&&(a[c+1]===m?e.appendChild(a[c]):e.insertBefore(m,l||a[c]||null))}if(t.pP&&delete t.pP,s.length){const u=[],f=[];s.forEach(([,h,,m,y])=>{h&&u.push(h),m&&f.push(m),y==null||y()}),u.forEach(h=>h()),f.length&&requestAnimationFrame(()=>{f.forEach(h=>h())})}},Wx=(t,e)=>!!(t&&t.length===e.length&&t.every((n,r)=>n[1]===e[r][1])),zs=new WeakMap,lu=(t,e,n)=>{var s,a,c,l,d,u;const r=!n&&e.pC;n&&(e.pC||(e.pC=e.vC));let i;try{n||(n=typeof e.tag=="function"?Kx(t,e):Vo(e.props.children)),((s=n[0])==null?void 0:s.tag)===""&&n[0][eu]&&(i=n[0][eu],t[5].push([t,i,e]));const f=r?[...e.pC]:e.vC?[...e.vC]:void 0,h=[];let m;for(let y=0;y<n.length;y++){Array.isArray(n[y])&&n.splice(y,1,...n[y].flat());let v=Jx(n[y]);if(v){typeof v.tag=="function"&&!v.tag[My]&&(gi.length>0&&(v[Le][2]=gi.map(A=>[A,A.values.at(-1)])),(a=t[5])!=null&&a.length&&(v[Le][3]=t[5].at(-1)));let b;if(f&&f.length){const A=f.findIndex(kn(v)?O=>kn(O):v.key!==void 0?O=>O.key===v.key&&O.tag===v.tag:O=>O.tag===v.tag);A!==-1&&(b=f[A],f.splice(A,1))}if(b)if(kn(v))b.t!==v.t&&(b.t=v.t,b.d=!0),v=b;else{const A=b.pP=b.props;if(b.props=v.props,b.f||(b.f=v.f||e.f),typeof v.tag=="function"){const O=b[Le][2];b[Le][2]=v[Le][2]||[],b[Le][3]=v[Le][3],!b.f&&((b.o||b)===v.o||(l=(c=b.tag)[V4])!=null&&l.call(c,A,b.props))&&Wx(O,b[Le][2])&&(b.s=!0)}v=b}else if(!kn(v)&&_i){const A=ji(_i);A&&(v.n=A)}if(!kn(v)&&!v.s&&(lu(t,v),delete v.f),h.push(v),m&&!m.s&&!v.s)for(let A=m;A&&!kn(A);A=(d=A.vC)==null?void 0:d.at(-1))A.nN=v;m=v}}e.vR=r?[...e.vC,...f||[]]:f||[],e.vC=h,r&&delete e.pC}catch(f){if(e.f=!0,f===Gg){if(i)return;throw f}const[h,m,y]=((u=e[Le])==null?void 0:u[3])||[];if(m){const v=()=>As([0,!1,t[2]],y),b=zs.get(y)||[];b.push(v),zs.set(y,b);const A=m(f,()=>{const O=zs.get(y);if(O){const U=O.indexOf(v);if(U!==-1)return O.splice(U,1),v()}});if(A){if(t[0]===1)t[1]=!0;else if(lu(t,y,[A]),(m.length===1||t!==h)&&y.c){R1(y,y.c,!1);return}throw Gg}}throw f}finally{i&&t[5].pop()}},Jx=t=>{if(!(t==null||typeof t=="boolean")){if(typeof t=="string"||typeof t=="number")return{t:t.toString(),d:!0};if("vR"in t&&(t={tag:t.tag,props:t.props,key:t.key,f:t.f,type:t.tag,ref:t.props.ref,o:t.o||t}),typeof t.tag=="function")t[Le]=[0,[]];else{const e=qx[t.tag];e&&(_i||(_i=qy("")),t.props.children=[{tag:_i,props:{value:t.n=`http://www.w3.org/${e}`,children:t.props.children}}])}return t}},Wg=(t,e)=>{var n,r;(n=e[Le][2])==null||n.forEach(([i,s])=>{i.values.push(s)});try{lu(t,e,void 0)}catch{return}if(e.a){delete e.a;return}(r=e[Le][2])==null||r.forEach(([i])=>{i.values.pop()}),(t[0]!==1||!t[1])&&R1(e,e.c,!1)},Hi=new WeakMap,Jg=[],As=async(t,e)=>{t[5]||(t[5]=[]);const n=Hi.get(e);n&&n[0](void 0);let r;const i=new Promise(s=>r=s);if(Hi.set(e,[r,()=>{t[2]?t[2](t,e,s=>{Wg(s,e)}).then(()=>r(e)):(Wg(t,e),r(e))}]),Jg.length)Jg.at(-1).add(e);else{await Promise.resolve();const s=Hi.get(e);s&&(Hi.delete(e),s[1]())}return i},Xx=(t,e,n)=>({tag:$o,props:{children:t},key:n,e,p:1}),ml=0,L1=1,_l=2,yl=3,wl=new WeakMap,U1=(t,e)=>!t||!e||t.length!==e.length||e.some((n,r)=>n!==t[r]),Zx=void 0,Xg=[],Yx=t=>{var a;const e=()=>typeof t=="function"?t():t,n=ko.at(-1);if(!n)return[e(),()=>{}];const[,r]=n,i=(a=r[Le][1])[ml]||(a[ml]=[]),s=r[Le][0]++;return i[s]||(i[s]=[e(),c=>{const l=Zx,d=i[s];if(typeof c=="function"&&(c=c(d[0])),!Object.is(c,d[0]))if(d[0]=c,Xg.length){const[u,f]=Xg.at(-1);Promise.all([u===3?r:As([u,!1,l],r),f]).then(([h])=>{if(!h||!(u===2||u===3))return;const m=h.vC;requestAnimationFrame(()=>{setTimeout(()=>{m===h.vC&&As([u===3?1:0,!1,l],h)})})})}else As([0,!1,l],r)}])},Dp=(t,e)=>{var c;const n=ko.at(-1);if(!n)return t;const[,r]=n,i=(c=r[Le][1])[_l]||(c[_l]=[]),s=r[Le][0]++,a=i[s];return U1(a==null?void 0:a[1],e)?i[s]=[t,e]:t=i[s][0],t},Qx=t=>{const e=wl.get(t);if(e){if(e.length===2)throw e[1];return e[0]}throw t.then(n=>wl.set(t,[n]),n=>wl.set(t,[void 0,n])),t},e8=(t,e)=>{var c;const n=ko.at(-1);if(!n)return t();const[,r]=n,i=(c=r[Le][1])[yl]||(c[yl]=[]),s=r[Le][0]++,a=i[s];return U1(a==null?void 0:a[1],e)&&(i[s]=[t(),e]),i[s][0]},t8=qy({pending:!1,data:null,method:null,action:null}),Zg=new Set,n8=t=>{Zg.add(t),t.finally(()=>Zg.delete(t))},Mp=(t,e)=>e8(()=>n=>{let r;t&&(typeof t=="function"?r=t(n)||(()=>{t(null)}):t&&"current"in t&&(t.current=n,r=()=>{t.current=null}));const i=e(n);return()=>{i==null||i(),r==null||r()}},[t]),Fr=Object.create(null),ls=Object.create(null),Xo=(t,e,n,r,i)=>{if(e!=null&&e.itemProp)return{tag:t,props:e,type:t,ref:e.ref};const s=document.head;let{onLoad:a,onError:c,precedence:l,blocking:d,...u}=e,f=null,h=!1;const m=ws[t];let y;if(m.length>0){const O=s.querySelectorAll(t);e:for(const U of O)for(const T of ws[t])if(U.getAttribute(T)===e[T]){f=U;break e}if(!f){const U=m.reduce((T,R)=>e[R]===void 0?T:`${T}-${R}-${e[R]}`,t);h=!ls[U],f=ls[U]||(ls[U]=(()=>{const T=document.createElement(t);for(const R of m)e[R]!==void 0&&T.setAttribute(R,e[R]),e.rel&&T.setAttribute("rel",e.rel);return T})())}}else y=s.querySelectorAll(t);l=r?l??"":void 0,r&&(u[vs]=l);const v=Dp(O=>{if(m.length>0){let U=!1;for(const T of s.querySelectorAll(t)){if(U&&T.getAttribute(vs)!==l){s.insertBefore(O,T);return}T.getAttribute(vs)===l&&(U=!0)}s.appendChild(O)}else if(y){let U=!1;for(const T of y)if(T===O){U=!0;break}U||s.insertBefore(O,s.contains(y[0])?y[0]:s.querySelector(t)),y=void 0}},[l]),b=Mp(e.ref,O=>{var R;const U=m[0];if(n===2&&(O.innerHTML=""),(h||y)&&v(O),!c&&!a)return;let T=Fr[R=O.getAttribute(U)]||(Fr[R]=new Promise((W,ne)=>{O.addEventListener("load",W),O.addEventListener("error",ne)}));a&&(T=T.then(a)),c&&(T=T.catch(c)),T.catch(()=>{})});if(i&&d==="render"){const O=ws[t][0];if(e[O]){const U=e[O],T=Fr[U]||(Fr[U]=new Promise((R,W)=>{v(f),f.addEventListener("load",R),f.addEventListener("error",W)}));Qx(T)}}const A={tag:t,type:t,props:{...u,ref:b},ref:b};return A.p=n,f&&(A.e=f),Xx(A,s)},r8=t=>{const e=Hx(),n=e&&ji(e);return n!=null&&n.endsWith("svg")?{tag:"title",props:t,type:"title",ref:t.ref}:Xo("title",t,void 0,!1,!1)},i8=t=>!t||["src","async"].some(e=>!t[e])?{tag:"script",props:t,type:"script",ref:t.ref}:Xo("script",t,1,!1,!0),o8=t=>!t||!["href","precedence"].every(e=>e in t)?{tag:"style",props:t,type:"style",ref:t.ref}:(t["data-href"]=t.href,delete t.href,Xo("style",t,2,!0,!0)),s8=t=>!t||["onLoad","onError"].some(e=>e in t)||t.rel==="stylesheet"&&(!("precedence"in t)||"disabled"in t)?{tag:"link",props:t,type:"link",ref:t.ref}:Xo("link",t,1,"precedence"in t,!0),a8=t=>Xo("meta",t,void 0,!1,!1),D1=Symbol(),c8=t=>{const{action:e,...n}=t;typeof e!="function"&&(n.action=e);const[r,i]=Yx([null,!1]),s=Dp(async d=>{const u=d.isTrusted?e:d.detail[D1];if(typeof u!="function")return;d.preventDefault();const f=new FormData(d.target);i([f,!0]);const h=u(f);h instanceof Promise&&(n8(h),await h),i([null,!0])},[]),a=Mp(t.ref,d=>(d.addEventListener("submit",s),()=>{d.removeEventListener("submit",s)})),[c,l]=r;return r[1]=!1,{tag:t8,props:{value:{pending:c!==null,data:c,method:c?"post":null,action:c?e:null},children:{tag:"form",props:{...n,ref:a},type:"form",ref:a}},f:l}},M1=(t,{formAction:e,...n})=>{if(typeof e=="function"){const r=Dp(i=>{i.preventDefault(),i.currentTarget.form.dispatchEvent(new CustomEvent("submit",{detail:{[D1]:e}}))},[]);n.ref=Mp(n.ref,i=>(i.addEventListener("click",r),()=>{i.removeEventListener("click",r)}))}return{tag:t,props:n,type:t,ref:n.ref}},l8=t=>M1("input",t),d8=t=>M1("button",t);Object.assign(tu,{title:r8,script:i8,style:o8,link:s8,meta:a8,form:c8,input:l8,button:d8});Hy(null);new TextEncoder;const Yn=t=>{const{i18nKey:e,values:n,components:r}=t,i=w.t(e,n),s=/<(\d+)>(.*?)<\/\d+>/g,a=[];let c=0,l;for(;(l=s.exec(i))!==null;){const[,d,u]=l,f=i.substring(c,l.index);f&&a.push(f);const h=parseInt(d,10);a.push(ok(r[h],{},u)),c=s.lastIndex}return c<i.length&&a.push(i.substring(c)),p(Mc,{children:a})},Yg=6,du=({error:t,theme:e,branding:n,email:r,state:i,client:s,hasPasswordLogin:a})=>{const c=new URLSearchParams({state:i}),d=s.connections.map(({name:u})=>u).includes("auth2");return p(De,{title:w.t("verify_your_email"),theme:e,branding:n,client:s,children:[p("div",{className:"mb-4 text-2xl font-medium",children:w.t("verify_your_email")}),p("div",{className:"mb-8 text-gray-300",children:p(Yn,{i18nKey:"code_sent_template",components:[p("span",{className:"text-black dark:text-white"},"span")],values:{username:r}})}),p("div",{className:"flex flex-1 flex-col justify-center",children:[p(rn,{className:"pt-2",children:[p("input",{autoFocus:!0,type:"text",pattern:"[0-9]*",maxLength:Yg,inputMode:"numeric",name:"code",placeholder:"******",className:ge("mb-2 w-full rounded-lg border bg-gray-100 px-4 pb-2 pt-2.5 text-center indent-[5px] font-mono text-3xl placeholder:text-gray-300 dark:bg-gray-600 md:text-3xl",{"border-red":t,"border-gray-100 dark:border-gray-500":!t}),minLength:Yg,required:!0,id:"code-input"}),t&&p(et,{children:t}),p(Ue,{className:"sm:mt-4 !text-base",children:[p("span",{children:w.t("login")}),p(Ke,{className:"text-xs",name:"arrow-right"})]}),p("div",{className:"my-4 flex space-x-2 text-sm text-[#B2B2B2]",children:[p(Ke,{className:"text-base",name:"info-bubble"}),p("div",{className:"text-sm text-gray-300 md:text-sm",children:w.t("sent_code_spam")})]}),d&&p("div",{className:"text-center mb-12",children:[p("div",{className:"relative mb-5 block text-center text-gray-300 dark:text-gray-300",children:[p("div",{className:"absolute left-0 right-0 top-1/2 border-b border-gray-200 dark:border-gray-600"}),p("div",{className:"relative inline-block bg-white px-2 dark:bg-gray-800",children:w.t("or")})]}),p(Ue,{Component:"a",href:`/u/${a?"enter-password":"pre-signup"}?${c.toString()}`,variant:"secondary",className:"block",children:w.t("enter_your_password_btn")})]})]}),p(Nt,{state:i})]})]})},u8=({maxLength:t,value:e="",disabled:n=!1,className:r,containerClassName:i,name:s,id:a,required:c,autoFocus:l})=>p("div",{className:ge("flex items-center gap-2 has-[:disabled]:opacity-50",i),"data-input-otp-container":"",children:Array.from({length:t}).map((d,u)=>p("input",{type:"text",inputMode:"numeric",maxLength:1,value:e[u]||"",disabled:n,name:u===0?s:void 0,id:u===0?a:void 0,required:u===0?c:void 0,autoFocus:u===0?l:void 0,className:ge("relative flex h-9 w-9 items-center justify-center border-y border-r border-input text-sm shadow-sm transition-all first:rounded-l-md first:border-l last:rounded-r-md text-center font-mono","focus:z-10 focus:ring-1 focus:ring-ring","disabled:cursor-not-allowed disabled:opacity-50",r),"data-input-otp-slot":u},u))}),p8=6,Qg=({error:t,theme:e,branding:n,email:r,state:i,hasPasswordLogin:s,className:a})=>{var C,z,k,$,I,L,q,F,Z,se,D,fe,$e,ce,ue,Ae,Ee,Re,Se,Te;const c=new URLSearchParams({state:i}),l=((C=e==null?void 0:e.colors)==null?void 0:C.primary_button)||((z=n==null?void 0:n.colors)==null?void 0:z.primary)||"#0066cc",d=((k=e==null?void 0:e.colors)==null?void 0:k.primary_button_label)||"#ffffff",u=(($=e==null?void 0:e.colors)==null?void 0:$.body_text)||"#333333",f=((I=e==null?void 0:e.colors)==null?void 0:I.input_border)||"#d1d5db",h=((L=e==null?void 0:e.colors)==null?void 0:L.widget_background)||"#ffffff",m=((q=e==null?void 0:e.colors)==null?void 0:q.widget_border)||"#e5e7eb",y=((F=e==null?void 0:e.borders)==null?void 0:F.widget_corner_radius)||8,v=((Z=e==null?void 0:e.borders)==null?void 0:Z.button_border_radius)||4,b=((se=e==null?void 0:e.borders)==null?void 0:se.show_widget_shadow)??!0,A=((fe=(D=e==null?void 0:e.fonts)==null?void 0:D.title)==null?void 0:fe.size)||24,O=((ce=($e=e==null?void 0:e.fonts)==null?void 0:$e.title)==null?void 0:ce.bold)??!0,U=((Ae=(ue=e==null?void 0:e.fonts)==null?void 0:ue.body_text)==null?void 0:Ae.size)||14,T={backgroundColor:h,borderColor:m,borderRadius:`${y}px`,boxShadow:b?"0 1px 3px 0 rgba(0, 0, 0, 0.1)":"none",color:u},R={fontSize:`${A}px`,fontWeight:O?"700":"400",color:((Ee=e==null?void 0:e.colors)==null?void 0:Ee.header)||u},W={fontSize:`${U}px`,color:((Re=e==null?void 0:e.colors)==null?void 0:Re.input_labels_placeholders)||"#6b7280"},ne={backgroundColor:l,color:d,borderRadius:`${v}px`},Q=((Se=e==null?void 0:e.widget)==null?void 0:Se.logo_position)||"center",K=Q==="left"?"text-left":Q==="right"?"text-right":"text-center",de=((Te=e==null?void 0:e.widget)==null?void 0:Te.logo_url)||(n==null?void 0:n.logo_url),N=Q!=="none"&&de;return p("div",{className:ge("flex flex-col gap-6 w-full max-w-sm",a),children:[p(_n,{style:T,className:"border",children:[p(yn,{children:[N&&p("div",{className:ge("mb-4",K),children:p(nn,{theme:e,branding:n})}),p(wn,{style:R,children:w.t("verify_your_email","Verify your email")}),p(vn,{style:W,children:p(Yn,{i18nKey:"code_sent_template",components:[p("span",{className:"font-medium"},"span")],values:{username:r}})})]}),p(bn,{children:p("form",{method:"post",children:p("div",{className:"grid gap-6",children:[p("div",{className:"grid gap-4",children:[p(Lt,{htmlFor:"code",style:W,children:w.t("verification_code","Verification Code")}),p("div",{className:"flex justify-center",children:p(u8,{maxLength:p8,name:"code",id:"code",required:!0,autoFocus:!0,containerClassName:"gap-2",className:ge("w-12 h-12 text-center text-lg font-mono border rounded-md transition-colors",t?"border-red-500 focus:ring-red-500":"border-gray-300 focus:ring-blue-500 focus:border-blue-500")})}),t&&p(et,{children:t})]}),p(fn,{type:"submit",className:"w-full transition-colors hover:brightness-90",style:ne,children:w.t("login","Login")}),p("div",{className:"text-center text-xs text-gray-500",children:p("div",{className:"flex items-center justify-center gap-1",children:[p("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20",children:p("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z",clipRule:"evenodd"})}),p("span",{children:w.t("sent_code_spam","Check your spam folder if you don't see the code")})]})}),s&&p("div",{className:"text-center",children:[p("div",{className:"relative mb-5 block text-center",style:W,children:[p("div",{className:"absolute left-0 right-0 top-1/2 border-b",style:{borderColor:m}}),p("div",{className:"relative inline-block px-2",style:{backgroundColor:h},children:w.t("or","Or")})]}),p("a",{href:`/u/${s?"enter-password":"pre-signup"}?${c.toString()}`,className:ge("w-full inline-flex items-center justify-center gap-2 rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500","border border-gray-300 bg-transparent hover:bg-gray-100 dark:border-gray-600 dark:hover:bg-gray-800","h-10 px-4 py-2"),style:{borderColor:f,borderRadius:`${v}px`,color:u},children:w.t("enter_your_password_btn","Enter your password instead")})]})]})})})]}),p(Nt,{state:i})]})},Dt=t=>{const{message:e,theme:n,branding:r,client:i,pageTitle:s,state:a}=t;return p(De,{title:"Login",theme:n,branding:r,client:i,children:[s?p("div",{className:"mb-4 text-2xl font-medium",children:s}):"",p("div",{className:"text-gray-300 mb-12",children:e}),a?p(Nt,{state:a}):""]})},f8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state"}),style:o.z.enum(["classic","shadcn"]).optional().openapi({description:"UI style to use for the enter code page"})})},responses:{200:{description:"HTML page to enter verification code.",content:{"text/html":{schema:o.z.string()}}},400:{description:"Bad Request - HTML error page if username is missing in state.",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{const{state:e,style:n}=t.req.valid("query");let r,i,s,a,c;n&&Jh(t,"auth_ui_style",n,{path:"/",maxAge:60*60*24*365,httpOnly:!0,secure:!0,sameSite:"Lax"});try{if({theme:r,branding:i,loginSession:s,client:a,useShadcn:c}=await Ce(t,e),!s.authParams.username)return t.html(p(Dt,{theme:r,branding:i,client:a,state:e,pageTitle:w.t("error_page_title")||"Error",message:w.t("username_not_found_error")||"Username not found in session."}),400);const l=await io({userAdapter:t.env.data.users,tenant_id:a.tenant.id,username:s.authParams.username,provider:"auth2"});return c?t.html(p(Oe,{title:w.t("verify_your_email","Verify your email"),theme:r,branding:i,client:a,children:p(Qg,{theme:r,branding:i,email:s.authParams.username,state:e,hasPasswordLogin:!!l})})):t.html(p(du,{theme:r,branding:i,email:s.authParams.username,state:e,client:a,hasPasswordLogin:!!l}))}catch(l){return console.error("Error in GET /u/enter-code:",l),i||(i=null),r||(r=null),a||(a=null),t.html(p(Dt,{theme:r,branding:i,client:a,state:e,pageTitle:w.t("error_page_title")||"Error",message:w.t("unexpected_error_try_again")||"An unexpected error occurred. Please try again."}),500)}}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state"}),style:o.z.enum(["classic","shadcn"]).optional().openapi({description:"UI style to use for the enter code page"})}),body:{content:{"application/x-www-form-urlencoded":{schema:o.z.object({code:o.z.string()})}}}},responses:{302:{description:"Redirect to continue authentication flow.",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML page with an error message (e.g., invalid code, username missing).",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page for unexpected issues.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{var d,u;const{state:e,style:n}=t.req.valid("query"),{code:r}=t.req.valid("form");n&&Jh(t,"auth_ui_style",n,{path:"/",maxAge:60*60*24*365,httpOnly:!0,secure:!0,sameSite:"Lax"});const{theme:i,branding:s,client:a,loginSession:c,useShadcn:l}=await Ce(t,e);if(!c.authParams.username)throw new S(400,{message:w.t("username_not_found_error")||"Username not found in session."});try{t.set("client_id",a.client_id);const f=await Op(t,{client_id:a.client_id,authParams:c.authParams,username:c.authParams.username,otp:r});if(f instanceof Response)return f;throw new S(500,{message:w.t("unexpected_error_try_again")||"An unexpected error occurred. Please try again."})}catch(f){let h;try{h=await io({userAdapter:t.env.data.users,tenant_id:a.tenant.id,username:c.authParams.username,provider:"auth2"})}catch{h=null}return l?t.html(p(Oe,{title:w.t("verify_your_email","Verify your email"),theme:i,branding:s,client:a,children:p(Qg,{theme:i,branding:s,email:(d=c.authParams)==null?void 0:d.username,state:e,error:f.message,hasPasswordLogin:!!h})}),400):t.html(p(du,{theme:i,branding:s,email:(u=c.authParams)==null?void 0:u.username,state:e,client:a,error:f.message,hasPasswordLogin:!!h}),400)}}),F1=t=>{const{theme:e,branding:n,client:r,state:i}=t;return p(De,{title:w.t("unverified_email"),theme:e,branding:n,client:r,children:[p("div",{className:"flex flex-1 flex-col justify-center",children:[p("p",{className:"mb-8 text-gray-300 text-lg",children:w.t("unverified_email")}),p("div",{className:"my-4 flex space-x-2 text-sm text-[#B2B2B2]",children:[p(Ke,{className:"text-base",name:"info-bubble"}),p("div",{className:"text-sm text-gray-300 md:text-sm",children:w.t("sent_code_spam")})]}),p(Nt,{state:i})]}),p(Nt,{state:i})]})},h8=({width:t=22,height:e=17})=>p("svg",{width:t,height:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 576 512",children:p("path",{fill:"currentColor",d:"M288 32c-80.8 0-145.5 36.8-192.6 80.6C48.6 156 17.3 208 2.5 243.7c-3.3 7.9-3.3 16.7 0 24.6C17.3 304 48.6 356 95.4 399.4 142.5 443.2 207.2 480 288 480s145.5-36.8 192.6-80.6c46.8-43.5 78.1-95.4 93-131.1 3.3-7.9 3.3-16.7 0-24.6-14.9-35.7-46.2-87.7-93-131.1C433.5 68.8 368.8 32 288 32M144 256a144 144 0 1 1 288 0 144 144 0 1 1-288 0m144-64c0 35.3-28.7 64-64 64-7.1 0-13.9-1.2-20.3-3.3-5.5-1.8-11.9 1.6-11.7 7.4.3 6.9 1.3 13.8 3.2 20.7 13.7 51.2 66.4 81.6 117.6 67.9s81.6-66.4 67.9-117.6c-11.1-41.5-47.8-69.4-88.6-71.1-5.8-.2-9.2 6.1-7.4 11.7 2.1 6.4 3.3 13.2 3.3 20.3"})}),g8=({width:t=23,height:e=18})=>p("svg",{width:t,height:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 512",children:p("path",{fill:"currentColor",d:"M38.8 5.1C28.4-3.1 13.3-1.2 5.1 9.2s-6.3 25.5 4.1 33.7l592 464c10.4 8.2 25.5 6.3 33.7-4.1s6.3-25.5-4.1-33.7l-105.2-82.4c39.6-40.6 66.4-86.1 79.9-118.4 3.3-7.9 3.3-16.7 0-24.6-14.9-35.7-46.2-87.7-93-131.1C465.5 68.8 400.8 32 320 32c-68.2 0-125 26.3-169.3 60.8zm184.3 144.4c25.5-23.3 59.6-37.5 96.9-37.5 79.5 0 144 64.5 144 144 0 24.9-6.3 48.3-17.4 68.7L408 294.5c8.4-19.3 10.6-41.4 4.8-63.3-11.1-41.5-47.8-69.4-88.6-71.1-5.8-.2-9.2 6.1-7.4 11.7 2.1 6.4 3.3 13.2 3.3 20.3 0 10.2-2.4 19.8-6.6 28.3l-90.3-70.8zM373 389.9c-16.4 6.5-34.3 10.1-53 10.1-79.5 0-144-64.5-144-144 0-6.9.5-13.6 1.4-20.2l-94.3-74.3c-22.8 29.7-39.1 59.3-48.6 82.2-3.3 7.9-3.3 16.7 0 24.6 14.9 35.7 46.2 87.7 93 131.1 47 43.8 111.7 80.6 192.5 80.6 47.8 0 89.9-12.9 126.2-32.5z"})}),uu=({name:t,placeholder:e=w.t("password")})=>p("div",{className:"password-input relative mb-2",children:[p("input",{type:"password",name:t,placeholder:e,className:"w-full rounded-lg bg-gray-100 px-4 py-5 text-base placeholder:text-gray-300 dark:bg-gray-600 md:text-base",required:!0}),p("button",{type:"button","aria-label":w.t("show_password"),title:w.t("show_password"),className:"show-password-toggle-show absolute right-0 top-0 w-10 h-full rounded-r-lg text-gray-400 column hover:bg-black/5",children:p(h8,{})}),p("button",{type:"button","aria-label":w.t("hide_password"),title:w.t("hide_password"),className:"show-password-toggle-hide !hidden absolute right-0 top-0 w-10 h-full rounded-r-lg text-gray-400 column hover:bg-black/5",children:p(g8,{})})]});var e0=Object.freeze,m8=Object.defineProperty,_8=(t,e)=>e0(m8(t,"raw",{value:e0(t.slice())})),t0;const Es=t=>{const{error:e,theme:n,branding:r,email:i,state:s,client:a}=t,c=new URLSearchParams({state:s});return p(De,{title:w.t("enter_password"),theme:n,branding:r,client:a,children:[p("div",{className:"mb-4 text-lg font-medium sm:text-2xl",children:w.t("enter_password")}),p("div",{className:"mb-6 text-gray-300",children:w.t("enter_password_description")}),p("div",{className:"flex flex-1 flex-col justify-center",children:[p(rn,{className:"mb-7",children:[p("input",{type:"text",name:"username",placeholder:w.t("email_placeholder"),className:"mb-2 w-full rounded-lg bg-gray-100 px-4 py-5 text-base placeholder:text-gray-300 dark:bg-gray-600 md:text-base",value:i}),p(uu,{name:"password"}),e&&p(et,{children:e}),p(Ue,{className:"sm:mt-4 !text-base",children:[p("span",{children:w.t("login")}),p(Ke,{className:"text-xs",name:"arrow-right"})]})]}),p("a",{href:`/u/forgot-password?${c.toString()}`,className:"text-primary hover:underline mb-4",children:w.t("forgot_password_link")}),p("div",{className:"text-center mb-12",children:[p("div",{className:"relative mb-5 block text-center text-gray-300 dark:text-gray-300",children:[p("div",{className:"absolute left-0 right-0 top-1/2 border-b border-gray-200 dark:border-gray-600"}),p("div",{className:"relative inline-block bg-white px-2 dark:bg-gray-800",children:w.t("or")})]}),p("form",{method:"post",action:`/u/login/identifier?${c.toString()}`,children:[p("input",{type:"hidden",name:"login_selection",value:"code"}),p("input",{type:"hidden",name:"username",value:i}),p(Ue,{variant:"secondary",className:"block",children:w.t("enter_a_code_btn")})]})]}),p(Nt,{state:s})]}),H4(t0||(t0=_8([`
210
210
  <script>
211
211
  // Show password toggle
212
212
  var passwordInputs = document.querySelectorAll(".password-input");
@@ -230,7 +230,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
230
230
  });
231
231
  });
232
232
  <\/script>
233
- `])))]})},vl=({error:t,theme:e,branding:n,loginSession:r,email:i,className:s})=>{var $,I,L,q,F,Z,se,D,fe,$e,ce,ue,Ae,Ee,Re,Se,Te,Be,Ge,dt,Ze,tt,nt,rt;const a=(($=e==null?void 0:e.colors)==null?void 0:$.primary_button)||((I=n==null?void 0:n.colors)==null?void 0:I.primary)||"#0066cc",c=((L=e==null?void 0:e.colors)==null?void 0:L.primary_button_label)||"#ffffff",l=((q=e==null?void 0:e.colors)==null?void 0:q.body_text)||"#333333",d=((F=e==null?void 0:e.colors)==null?void 0:F.input_background)||"#ffffff",u=((Z=e==null?void 0:e.colors)==null?void 0:Z.input_border)||"#d1d5db",f=((se=e==null?void 0:e.colors)==null?void 0:se.input_filled_text)||"#111827",h=((D=e==null?void 0:e.colors)==null?void 0:D.error)||"#dc2626",m=((fe=e==null?void 0:e.colors)==null?void 0:fe.widget_background)||"#ffffff",y=(($e=e==null?void 0:e.colors)==null?void 0:$e.widget_border)||"#e5e7eb",v=((ce=e==null?void 0:e.borders)==null?void 0:ce.widget_corner_radius)||8,b=((ue=e==null?void 0:e.borders)==null?void 0:ue.input_border_radius)||4,A=((Ae=e==null?void 0:e.borders)==null?void 0:Ae.button_border_radius)||4,O=((Ee=e==null?void 0:e.borders)==null?void 0:Ee.show_widget_shadow)??!0,U=((Se=(Re=e==null?void 0:e.fonts)==null?void 0:Re.title)==null?void 0:Se.size)||24,T=((Be=(Te=e==null?void 0:e.fonts)==null?void 0:Te.title)==null?void 0:Be.bold)??!0,R=((dt=(Ge=e==null?void 0:e.fonts)==null?void 0:Ge.body_text)==null?void 0:dt.size)||14,W={backgroundColor:m,borderColor:y,borderRadius:`${v}px`,boxShadow:O?"0 1px 3px 0 rgba(0, 0, 0, 0.1)":"none",color:l},ne={fontSize:`${U}px`,fontWeight:T?"700":"400",color:((Ze=e==null?void 0:e.colors)==null?void 0:Ze.header)||l},Q={fontSize:`${R}px`,color:((tt=e==null?void 0:e.colors)==null?void 0:tt.input_labels_placeholders)||"#6b7280"},K={backgroundColor:d,borderColor:t?h:u,borderRadius:`${b}px`,color:f},de={backgroundColor:a,color:c,borderRadius:`${A}px`},N=((nt=e==null?void 0:e.widget)==null?void 0:nt.logo_position)||"center",C=N==="left"?"text-left":N==="right"?"text-right":"text-center",z=((rt=e==null?void 0:e.widget)==null?void 0:rt.logo_url)||(n==null?void 0:n.logo_url),k=N!=="none"&&z;return p("div",{className:ge("flex flex-col gap-6 w-full max-w-sm",s),children:p(_n,{style:W,className:"border",children:[p(yn,{children:[k&&p("div",{className:ge("mb-4",C),children:p(rn,{theme:e,branding:n})}),p(wn,{style:ne,children:w.t("enter_password","Enter your password")}),p(vn,{style:Q,children:w.t("enter_password_description","Enter your password to continue")})]}),p(bn,{children:p("form",{method:"post",children:p("div",{className:"grid gap-6",children:[p("div",{className:"grid gap-2",children:[p(Lt,{htmlFor:"email",style:Q,children:w.t("email","Email")}),p(Qt,{id:"email",name:"username",type:"email",value:i,disabled:!0,className:"border bg-gray-50",style:{...K,cursor:"not-allowed"}})]}),p("div",{className:"grid gap-2",children:[p("div",{className:"flex items-center justify-between",children:[p(Lt,{htmlFor:"password",style:Q,children:w.t("password","Password")}),p("a",{href:`/u/forgot-password?state=${r.id}`,className:"text-sm hover:underline",style:{color:a},children:w.t("forgot_password","Forgot password?")})]}),p("div",{className:"relative","data-password-toggle":!0,children:[p(Qt,{id:"password",name:"password",type:"password","data-password-input":"password",placeholder:w.t("password_placeholder","Enter your password"),required:!0,error:!!t,className:"border pr-8",style:K}),p("button",{type:"button","data-password-toggle-btn":!0,className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700 transition-colors","aria-label":w.t("toggle_password_visibility","Toggle password visibility"),children:[p("svg",{"data-show-icon":!0,xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"}),p("circle",{cx:"12",cy:"12",r:"3"})]}),p("svg",{"data-hide-icon":!0,className:"hidden",xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M9.88 9.88a3 3 0 1 0 4.24 4.24"}),p("path",{d:"M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"}),p("path",{d:"M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"}),p("line",{x1:"2",x2:"22",y1:"2",y2:"22"})]})]})]}),t&&p(et,{children:t})]}),p(fn,{type:"submit",className:"w-full transition-colors hover:brightness-90",style:de,children:w.t("continue","Continue")}),p("div",{className:"text-center",children:p("a",{href:`/u/login/identifier?state=${r.id}`,className:"text-sm hover:underline",style:Q,children:["← ",w.t("back","Back")]})})]})})})]})})},y8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{200:{description:"Response"}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,client:i,loginSession:s,useShadcn:a}=await Ce(t,e);if(!s.authParams.username)throw new S(400,{message:"Username required"});return a?t.html(p(Oe,{title:w.t("enter_your_password","Enter your password"),theme:n,branding:r,client:i,children:p(vl,{theme:n,branding:r,loginSession:s,email:s.authParams.username,client:i})})):t.html(p(Es,{theme:n,branding:r,email:s.authParams.username,state:e,client:i}))}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})}),body:{content:{"application/x-www-form-urlencoded":{schema:o.z.object({password:o.z.string()})}}}},responses:{200:{description:"HTML page indicating success or a next step (if not redirecting).",content:{"text/html":{schema:o.z.string()}}},302:{description:"Redirect to continue the authentication flow (e.g., to client, MFA, consent).",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML page with an error message (e.g., invalid password, username required).",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML page with an error message.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{const{state:e}=t.req.valid("query"),n=t.req.valid("form"),{password:r}=n,{theme:i,branding:s,client:a,loginSession:c,useShadcn:l}=await Ce(t,e),{username:d}=c.authParams;if(!d)throw new S(400,{message:"Username required"});try{return await A1(t,a,{...c.authParams,password:r},c)}catch(u){const f=u;return f.code==="INVALID_PASSWORD"||f.code==="USER_NOT_FOUND"?l?t.html(p(Oe,{title:w.t("enter_your_password","Enter your password"),theme:i,branding:s,client:a,children:p(vl,{theme:i,branding:s,loginSession:c,email:d,error:w.t("invalid_password"),client:a})}),400):t.html(p(Es,{theme:i,branding:s,email:d,error:w.t("invalid_password"),state:e,client:a}),400):f.code==="EMAIL_NOT_VERIFIED"?t.html(p(F1,{theme:i,branding:s,client:a,state:e}),400):l?t.html(p(Oe,{title:w.t("enter_your_password","Enter your password"),theme:i,branding:s,client:a,children:p(vl,{theme:i,branding:s,loginSession:c,email:d,error:f.message||"An unknown error occurred.",client:a})}),f.code?400:500):t.html(p(Es,{theme:i,branding:s,email:d,error:f.message||"An unknown error occurred.",state:e,client:a}),f.code?400:500)}}),ir=t=>{const{error:e,theme:n,branding:r,client:i,email:s,state:a,code:c}=t;return p(De,{title:w.t("sign_up"),theme:n,branding:r,client:i,children:[p("div",{className:"mb-4 text-lg font-medium sm:text-2xl",children:w.t("create_account_title")}),p("div",{className:"mb-6 text-gray-300",children:w.t("create_account_description")}),p("div",{className:"flex flex-1 flex-col justify-center",children:[p(on,{children:[p("input",{type:"hidden",name:"code",value:c}),p("input",{type:"email",name:"username",placeholder:w.t("email_placeholder"),className:"mb-2 w-full rounded-lg bg-gray-100 px-4 py-5 text-base placeholder:text-gray-300 dark:bg-gray-600 md:text-base",required:!0,value:s,disabled:!!s}),p("input",{type:"password",name:"password",placeholder:w.t("enter_new_password_placeholder"),className:"mb-2 w-full rounded-lg bg-gray-100 px-4 py-5 text-base placeholder:text-gray-300 dark:bg-gray-600 md:text-base"}),p("input",{type:"password",name:"re-enter-password",placeholder:w.t("reenter_new_password_placeholder"),className:"mb-2 w-full rounded-lg bg-gray-100 px-4 py-5 text-base placeholder:text-gray-300 dark:bg-gray-600 md:text-base"}),e&&p(et,{children:e}),p(Ue,{className:"sm:mt-4 !text-base",children:w.t("continue")})]}),p(It,{state:a})]})]})},Di=({error:t,theme:e,branding:n,loginSession:r,email:i,code:s,className:a})=>{var I,L,q,F,Z,se,D,fe,$e,ce,ue,Ae,Ee,Re,Se,Te,Be,Ge,dt,Ze,tt,nt,rt,Rn;const c=((I=e==null?void 0:e.colors)==null?void 0:I.primary_button)||((L=n==null?void 0:n.colors)==null?void 0:L.primary)||"#0066cc",l=((q=e==null?void 0:e.colors)==null?void 0:q.primary_button_label)||"#ffffff",d=((F=e==null?void 0:e.colors)==null?void 0:F.body_text)||"#333333",u=((Z=e==null?void 0:e.colors)==null?void 0:Z.input_background)||"#ffffff",f=((se=e==null?void 0:e.colors)==null?void 0:se.input_border)||"#d1d5db",h=((D=e==null?void 0:e.colors)==null?void 0:D.input_filled_text)||"#111827",m=((fe=e==null?void 0:e.colors)==null?void 0:fe.error)||"#dc2626",y=(($e=e==null?void 0:e.colors)==null?void 0:$e.widget_background)||"#ffffff",v=((ce=e==null?void 0:e.colors)==null?void 0:ce.widget_border)||"#e5e7eb",b=((ue=e==null?void 0:e.borders)==null?void 0:ue.widget_corner_radius)||8,A=((Ae=e==null?void 0:e.borders)==null?void 0:Ae.input_border_radius)||4,O=((Ee=e==null?void 0:e.borders)==null?void 0:Ee.button_border_radius)||4,U=((Re=e==null?void 0:e.borders)==null?void 0:Re.show_widget_shadow)??!0,T=((Te=(Se=e==null?void 0:e.fonts)==null?void 0:Se.title)==null?void 0:Te.size)||24,R=((Ge=(Be=e==null?void 0:e.fonts)==null?void 0:Be.title)==null?void 0:Ge.bold)??!0,W=((Ze=(dt=e==null?void 0:e.fonts)==null?void 0:dt.body_text)==null?void 0:Ze.size)||14,ne={backgroundColor:y,borderColor:v,borderRadius:`${b}px`,boxShadow:U?"0 1px 3px 0 rgba(0, 0, 0, 0.1)":"none",color:d},Q={fontSize:`${T}px`,fontWeight:R?"700":"400",color:((tt=e==null?void 0:e.colors)==null?void 0:tt.header)||d},K={fontSize:`${W}px`,color:((nt=e==null?void 0:e.colors)==null?void 0:nt.input_labels_placeholders)||"#6b7280"},de={backgroundColor:u,borderColor:t?m:f,borderRadius:`${A}px`,color:h},N={backgroundColor:c,color:l,borderRadius:`${O}px`},C=((rt=e==null?void 0:e.widget)==null?void 0:rt.logo_position)||"center",z=C==="left"?"text-left":C==="right"?"text-right":"text-center",k=((Rn=e==null?void 0:e.widget)==null?void 0:Rn.logo_url)||(n==null?void 0:n.logo_url),$=C!=="none"&&k;return p("div",{className:ge("flex flex-col gap-6 w-full max-w-sm",a),children:p(_n,{style:ne,className:"border",children:[p(yn,{children:[$&&p("div",{className:ge("mb-4",z),children:p(rn,{theme:e,branding:n})}),p(wn,{style:Q,children:w.t("create_account_title","Create Account")}),p(vn,{style:K,children:w.t("create_account_description","Sign up to get started")})]}),p(bn,{children:[p("form",{method:"post",className:"space-y-4",children:[p("input",{type:"hidden",name:"state",value:r.authParams.state}),s&&p("input",{type:"hidden",name:"code",value:s}),p("div",{className:"space-y-2",children:[p(Lt,{htmlFor:"username",style:K,children:w.t("email_label","Email")}),p(Qt,{id:"username",type:"email",name:"username",placeholder:w.t("email_placeholder","Email Address"),value:i,disabled:!!i,style:de,className:"w-full",required:!0})]}),p("div",{className:"space-y-2",children:[p(Lt,{htmlFor:"password",style:K,children:w.t("password","Password")}),p("div",{className:"relative","data-password-toggle":!0,children:[p(Qt,{id:"password",name:"password",type:"password","data-password-input":"password",placeholder:w.t("enter_new_password_placeholder","Enter new password"),required:!0,error:!!t,className:"border pr-8",style:de}),p("button",{type:"button","data-password-toggle-btn":!0,className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700 transition-colors","aria-label":w.t("toggle_password_visibility","Toggle password visibility"),children:[p("svg",{"data-show-icon":!0,xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"}),p("circle",{cx:"12",cy:"12",r:"3"})]}),p("svg",{"data-hide-icon":!0,className:"hidden",xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M9.88 9.88a3 3 0 1 0 4.24 4.24"}),p("path",{d:"M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"}),p("path",{d:"M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"}),p("line",{x1:"2",x2:"22",y1:"2",y2:"22"})]})]})]})]}),p("div",{className:"space-y-2",children:[p(Lt,{htmlFor:"re-enter-password",style:K,children:w.t("confirm_password","Confirm Password")}),p("div",{className:"relative","data-password-toggle":!0,children:[p(Qt,{id:"re-enter-password",name:"re-enter-password",type:"password","data-password-input":"re-enter-password",placeholder:w.t("reenter_new_password_placeholder","Re-enter new password"),required:!0,error:!!t,className:"border pr-8",style:de}),p("button",{type:"button","data-password-toggle-btn":!0,className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700 transition-colors","aria-label":w.t("toggle_password_visibility","Toggle password visibility"),children:[p("svg",{"data-show-icon":!0,xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"}),p("circle",{cx:"12",cy:"12",r:"3"})]}),p("svg",{"data-hide-icon":!0,className:"hidden",xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M9.88 9.88a3 3 0 1 0 4.24 4.24"}),p("path",{d:"M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"}),p("path",{d:"M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"}),p("line",{x1:"2",x2:"22",y1:"2",y2:"22"})]})]})]})]}),t&&p(et,{children:t}),p(fn,{type:"submit",className:"w-full",style:N,disabled:!1,children:w.t("continue","Continue")})]}),p("div",{className:"mt-4 text-center",children:p("a",{href:`/u/login/identifier?state=${encodeURIComponent(r.authParams.state||"")}`,className:"text-sm",style:{color:c},children:w.t("back_to_login","Back to Login")})})]})]})})},w8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"}),code:o.z.string().optional().openapi({description:"The code parameter from an email verification link"})})},responses:{200:{description:"Response"}}}),async t=>{const{state:e,code:n}=t.req.valid("query"),{theme:r,branding:i,client:s,loginSession:a,useShadcn:c}=await Ce(t,e),{username:l}=a.authParams;if(!l)throw new S(400,{message:"Username required"});return c?t.html(p(Oe,{title:w.t("sign_up","Sign Up"),theme:r,branding:i,client:s,children:p(Di,{theme:r,branding:i,loginSession:a,email:l,code:n,client:s})})):n?t.html(p(ir,{state:e,theme:r,branding:i,client:s,email:l,code:n})):t.html(p(ir,{state:e,theme:r,branding:i,client:s,email:l}))}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})}),body:{content:{"application/x-www-form-urlencoded":{schema:o.z.object({password:o.z.string(),"re-enter-password":o.z.string(),code:o.z.string().optional()})}}}},responses:{200:{description:"HTML page indicating success (e.g., email verification sent) or a next step.",content:{"text/html":{schema:o.z.string()}}},302:{description:"Redirect to continue the authentication flow (e.g., to client, MFA, consent) after successful login.",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML page with an error message (e.g., passwords don't match, weak password, user exists).",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML page with an error message.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{var d,u,f;const{state:e}=t.req.valid("query"),n=t.req.valid("form"),{env:r}=t,{theme:i,branding:s,client:a,loginSession:c,useShadcn:l}=await Ce(t,e);try{if(!c.authParams.username)throw new S(400,{message:"Username required"});const h="Username-Password-Authentication";if(t.set("connection",h),n.password!==n["re-enter-password"])return l?t.html(p(Oe,{title:w.t("sign_up","Sign Up"),theme:i,branding:s,client:a,children:p(Di,{theme:i,branding:s,loginSession:c,email:c.authParams.username,code:n.code,error:w.t("create_account_passwords_didnt_match"),client:a})}),400):t.html(p(ir,{state:e,code:n.code,theme:i,branding:s,client:a,error:w.t("create_account_passwords_didnt_match"),email:c.authParams.username}),400);if(!Rp(n.password))return l?t.html(p(Oe,{title:w.t("sign_up","Sign Up"),theme:i,branding:s,client:a,children:p(Di,{theme:i,branding:s,loginSession:c,email:c.authParams.username,code:n.code,error:w.t("create_account_weak_password"),client:a})}),400):t.html(p(ir,{state:e,code:n.code,theme:i,branding:s,client:a,error:w.t("create_account_weak_password"),email:c.authParams.username}),400);const m=n.code?await r.data.codes.get(a.tenant.id,n.code,"email_verification"):void 0,y=m?await r.data.loginSessions.get(a.tenant.id,m.login_id):void 0;if(await vi({userAdapter:t.env.data.users,tenant_id:a.tenant.id,username:c.authParams.username,provider:"auth2"}))return l?t.html(p(Oe,{title:w.t("sign_up","Sign Up"),theme:i,branding:s,client:a,children:p(Di,{theme:i,branding:s,loginSession:c,email:c.authParams.username,code:n.code,error:w.t("user_exists_error"),client:a})}),400):t.html(p(ir,{state:e,code:n.code,theme:i,branding:s,client:a,error:w.t("user_exists_error"),email:c.authParams.username}),400);const b=(y==null?void 0:y.authParams.username)===c.authParams.username,A=`auth2|${La()}`,O=await r.data.users.create(a.tenant.id,{user_id:A,email:c.authParams.username,email_verified:b,provider:"auth2",connection:h,is_social:!1});if(await r.data.passwords.create(a.tenant.id,{user_id:A,password:await ti.hash(n.password,10),algorithm:"bcrypt"}),!b){const T=(f=(u=(d=c.authParams)==null?void 0:d.ui_locales)==null?void 0:u.split(" "))==null?void 0:f.map(R=>R.split("-")[0])[0];return await Up(t,O,T),t.html(p(Dt,{message:w.t("validate_email_body"),pageTitle:w.t("validate_email_title"),theme:i,branding:s,client:a,state:e}))}const U=await z1(t,a,{...c.authParams,password:n.password},c);return un(t,U)}catch(h){let m=w.t("unknown_error_message"),y=400;return h instanceof S?(m=h.message||m,y=h.status===400?400:500):h instanceof qr?m=h.message||m:h instanceof Error&&(m=h.message||m,y=500),l?t.html(p(Oe,{title:w.t("sign_up","Sign Up"),theme:i,branding:s,client:a,children:p(Di,{theme:i,branding:s,loginSession:c,email:c.authParams.username,code:n.code,error:m,client:a})}),y):t.html(p(ir,{state:e,theme:i,branding:s,client:a,error:m,email:c.authParams.username,code:n.code}),y)}}),Hr=t=>{const{error:e,theme:n,branding:r,client:i,email:s}=t;return p(De,{title:w.t("reset_password_title"),theme:n,branding:r,client:i,children:[p("div",{className:"mb-4 text-lg font-medium sm:text-2xl",children:w.t("reset_password_title")}),p("div",{className:"mb-6 text-gray-300",children:`${w.t("reset_password_description")} ${s}`}),p("div",{className:"flex flex-1 flex-col justify-center",children:p(on,{children:[p(uu,{name:"password",placeholder:w.t("enter_new_password_placeholder")}),p(uu,{name:"re-enter-password",placeholder:w.t("reenter_new_password_placeholder")}),e&&p(et,{children:e}),p(Ue,{className:"sm:mt-4 !text-base",children:w.t("reset_password_cta")})]})})]})},Mi=({error:t,theme:e,branding:n,loginSession:r,email:i,className:s})=>{var $,I,L,q,F,Z,se,D,fe,$e,ce,ue,Ae,Ee,Re,Se,Te,Be,Ge,dt,Ze,tt,nt,rt;const a=(($=e==null?void 0:e.colors)==null?void 0:$.primary_button)||((I=n==null?void 0:n.colors)==null?void 0:I.primary)||"#0066cc",c=((L=e==null?void 0:e.colors)==null?void 0:L.primary_button_label)||"#ffffff",l=((q=e==null?void 0:e.colors)==null?void 0:q.body_text)||"#333333",d=((F=e==null?void 0:e.colors)==null?void 0:F.input_background)||"#ffffff",u=((Z=e==null?void 0:e.colors)==null?void 0:Z.input_border)||"#d1d5db",f=((se=e==null?void 0:e.colors)==null?void 0:se.input_filled_text)||"#111827",h=((D=e==null?void 0:e.colors)==null?void 0:D.error)||"#dc2626",m=((fe=e==null?void 0:e.colors)==null?void 0:fe.widget_background)||"#ffffff",y=(($e=e==null?void 0:e.colors)==null?void 0:$e.widget_border)||"#e5e7eb",v=((ce=e==null?void 0:e.borders)==null?void 0:ce.widget_corner_radius)||8,b=((ue=e==null?void 0:e.borders)==null?void 0:ue.input_border_radius)||4,A=((Ae=e==null?void 0:e.borders)==null?void 0:Ae.button_border_radius)||4,O=((Ee=e==null?void 0:e.borders)==null?void 0:Ee.show_widget_shadow)??!0,U=((Se=(Re=e==null?void 0:e.fonts)==null?void 0:Re.title)==null?void 0:Se.size)||24,T=((Be=(Te=e==null?void 0:e.fonts)==null?void 0:Te.title)==null?void 0:Be.bold)??!0,R=((dt=(Ge=e==null?void 0:e.fonts)==null?void 0:Ge.body_text)==null?void 0:dt.size)||14,W={backgroundColor:m,borderColor:y,borderRadius:`${v}px`,boxShadow:O?"0 1px 3px 0 rgba(0, 0, 0, 0.1)":"none",color:l},ne={fontSize:`${U}px`,fontWeight:T?"700":"400",color:((Ze=e==null?void 0:e.colors)==null?void 0:Ze.header)||l},Q={fontSize:`${R}px`,color:((tt=e==null?void 0:e.colors)==null?void 0:tt.input_labels_placeholders)||"#6b7280"},K={backgroundColor:d,borderColor:t?h:u,borderRadius:`${b}px`,color:f},de={backgroundColor:a,color:c,borderRadius:`${A}px`},N=((nt=e==null?void 0:e.widget)==null?void 0:nt.logo_position)||"center",C=N==="left"?"text-left":N==="right"?"text-right":"text-center",z=((rt=e==null?void 0:e.widget)==null?void 0:rt.logo_url)||(n==null?void 0:n.logo_url),k=N!=="none"&&z;return p("div",{className:ge("flex flex-col gap-6 w-full max-w-sm",s),children:p(_n,{style:W,className:"border",children:[p(yn,{children:[k&&p("div",{className:ge("mb-4",C),children:p(rn,{theme:e,branding:n})}),p(wn,{style:ne,children:w.t("reset_password_title","Reset Password")}),p(vn,{style:Q,children:`${w.t("reset_password_description","Set a new password for")} ${i}`})]}),p(bn,{children:p("form",{method:"post",className:"space-y-4",children:[p("input",{type:"hidden",name:"state",value:r.authParams.state}),p("div",{className:"space-y-2",children:[p(Lt,{htmlFor:"password",style:Q,children:w.t("new_password","New Password")}),p("div",{className:"relative","data-password-toggle":!0,children:[p(Qt,{id:"password",name:"password",type:"password","data-password-input":"password",placeholder:w.t("enter_new_password_placeholder","Enter new password"),required:!0,error:!!t,className:"border pr-8",style:K}),p("button",{type:"button","data-password-toggle-btn":!0,className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700 transition-colors","aria-label":w.t("toggle_password_visibility","Toggle password visibility"),children:[p("svg",{"data-show-icon":!0,xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"}),p("circle",{cx:"12",cy:"12",r:"3"})]}),p("svg",{"data-hide-icon":!0,className:"hidden",xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M9.88 9.88a3 3 0 1 0 4.24 4.24"}),p("path",{d:"M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"}),p("path",{d:"M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"}),p("line",{x1:"2",x2:"22",y1:"2",y2:"22"})]})]})]})]}),p("div",{className:"space-y-2",children:[p(Lt,{htmlFor:"re-enter-password",style:Q,children:w.t("confirm_password","Confirm Password")}),p("div",{className:"relative","data-password-toggle":!0,children:[p(Qt,{id:"re-enter-password",name:"re-enter-password",type:"password","data-password-input":"re-enter-password",placeholder:w.t("reenter_new_password_placeholder","Re-enter new password"),required:!0,error:!!t,className:"border pr-8",style:K}),p("button",{type:"button","data-password-toggle-btn":!0,className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700 transition-colors","aria-label":w.t("toggle_password_visibility","Toggle password visibility"),children:[p("svg",{"data-show-icon":!0,xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"}),p("circle",{cx:"12",cy:"12",r:"3"})]}),p("svg",{"data-hide-icon":!0,className:"hidden",xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M9.88 9.88a3 3 0 1 0 4.24 4.24"}),p("path",{d:"M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"}),p("path",{d:"M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"}),p("line",{x1:"2",x2:"22",y1:"2",y2:"22"})]})]})]})]}),t&&p(et,{children:t}),p(fn,{type:"submit",className:"w-full",style:de,disabled:!1,children:w.t("reset_password_cta","Reset Password")})]})})]})})},v8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"}),code:o.z.string().openapi({description:"The code parameter from the authorization request"})})},responses:{200:{description:"Response"}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,client:i,loginSession:s,useShadcn:a}=await Ce(t,e);if(!s.authParams.username)throw new S(400,{message:"Username required"});return a?t.html(p(Oe,{title:w.t("reset_password_title","Reset Password"),theme:n,branding:r,client:i,children:p(Mi,{theme:n,branding:r,loginSession:s,email:s.authParams.username,client:i})})):t.html(p(Hr,{theme:n,branding:r,client:i,email:s.authParams.username}))}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"}),code:o.z.string().openapi({description:"The code parameter from the authorization request"})}),body:{content:{"application/x-www-form-urlencoded":{schema:o.z.object({password:o.z.string(),"re-enter-password":o.z.string()})}}}},responses:{200:{description:"Response"}}}),async t=>{const{state:e,code:n}=t.req.valid("query"),{password:r,"re-enter-password":i}=t.req.valid("form"),{env:s}=t,{theme:a,branding:c,client:l,loginSession:d,useShadcn:u}=await Ce(t,e);if(!d.authParams.username)throw new S(400,{message:"Username required"});if(r!==i)return u?t.html(p(Oe,{title:w.t("reset_password_title","Reset Password"),theme:a,branding:c,client:l,children:p(Mi,{error:w.t("create_account_passwords_didnt_match"),theme:a,branding:c,loginSession:d,email:d.authParams.username,client:l})}),400):t.html(p(Hr,{error:w.t("create_account_passwords_didnt_match"),theme:a,branding:c,client:l,email:d.authParams.username}),400);if(!Rp(r))return u?t.html(p(Oe,{title:w.t("reset_password_title","Reset Password"),theme:a,branding:c,client:l,children:p(Mi,{error:w.t("create_account_weak_password"),theme:a,branding:c,loginSession:d,email:d.authParams.username,client:l})}),400):t.html(p(Hr,{error:w.t("create_account_weak_password"),theme:a,branding:c,client:l,email:d.authParams.username}),400);const f=await vi({userAdapter:s.data.users,tenant_id:l.tenant.id,username:d.authParams.username,provider:"auth2"});if(!f)throw new S(400,{message:"User not found"});try{if(!await s.data.codes.get(l.tenant.id,n,"password_reset"))return u?t.html(p(Oe,{title:w.t("reset_password_title","Reset Password"),theme:a,branding:c,client:l,children:p(Mi,{error:"Code not found or expired",theme:a,branding:c,loginSession:d,email:d.authParams.username,client:l})}),400):t.html(p(Hr,{error:"Code not found or expired",theme:a,branding:c,client:l,email:d.authParams.username}),400);const m={user_id:f.user_id,password:await ti.hash(r,10),algorithm:"bcrypt"};await s.data.passwords.get(l.tenant.id,f.user_id)?await s.data.passwords.update(l.tenant.id,m):await s.data.passwords.create(l.tenant.id,m),f.email_verified||await s.data.users.update(l.tenant.id,f.user_id,{email_verified:!0})}catch{return u?t.html(p(Oe,{title:w.t("reset_password_title","Reset Password"),theme:a,branding:c,client:l,children:p(Mi,{error:"The password could not be reset",theme:a,branding:c,loginSession:d,email:d.authParams.username,client:l})}),400):t.html(p(Hr,{error:"The password could not be reset",theme:a,branding:c,client:l,email:d.authParams.username}),400)}return t.html(p(Dt,{message:w.t("password_has_been_reset"),theme:a,branding:c,client:l,state:e}))}),q1=t=>{const{error:e,theme:n,branding:r,client:i,email:s,state:a}=t;return p(De,{title:w.t("forgot_password_title"),theme:n,branding:r,client:i,children:[p("div",{className:"mb-4 text-lg font-medium sm:text-2xl",children:w.t("forgot_password_title")}),p("div",{className:"mb-6 text-gray-300",children:w.t("forgot_password_description")}),p("div",{className:"flex flex-1 flex-col justify-center",children:[p(on,{className:"pt-2",children:[p("input",{type:"email",name:"username",placeholder:w.t("email_placeholder"),className:"mb-2 w-full rounded-lg bg-gray-100 px-4 py-5 text-base placeholder:text-gray-300 dark:bg-gray-600 md:text-base",value:s,disabled:!!s}),e&&p(et,{children:e}),p(Ue,{className:"sm:mt-4 !text-base",children:w.t("forgot_password_cta")})]}),p(It,{state:a})]})]})},b8=({error:t,theme:e,branding:n,loginSession:r,email:i,className:s})=>{var $,I,L,q,F,Z,se,D,fe,$e,ce,ue,Ae,Ee,Re,Se,Te,Be,Ge,dt,Ze,tt,nt,rt;const a=(($=e==null?void 0:e.colors)==null?void 0:$.primary_button)||((I=n==null?void 0:n.colors)==null?void 0:I.primary)||"#0066cc",c=((L=e==null?void 0:e.colors)==null?void 0:L.primary_button_label)||"#ffffff",l=((q=e==null?void 0:e.colors)==null?void 0:q.body_text)||"#333333",d=((F=e==null?void 0:e.colors)==null?void 0:F.input_background)||"#ffffff",u=((Z=e==null?void 0:e.colors)==null?void 0:Z.input_border)||"#d1d5db",f=((se=e==null?void 0:e.colors)==null?void 0:se.input_filled_text)||"#111827",h=((D=e==null?void 0:e.colors)==null?void 0:D.error)||"#dc2626",m=((fe=e==null?void 0:e.colors)==null?void 0:fe.widget_background)||"#ffffff",y=(($e=e==null?void 0:e.colors)==null?void 0:$e.widget_border)||"#e5e7eb",v=((ce=e==null?void 0:e.borders)==null?void 0:ce.widget_corner_radius)||8,b=((ue=e==null?void 0:e.borders)==null?void 0:ue.input_border_radius)||4,A=((Ae=e==null?void 0:e.borders)==null?void 0:Ae.button_border_radius)||4,O=((Ee=e==null?void 0:e.borders)==null?void 0:Ee.show_widget_shadow)??!0,U=((Se=(Re=e==null?void 0:e.fonts)==null?void 0:Re.title)==null?void 0:Se.size)||24,T=((Be=(Te=e==null?void 0:e.fonts)==null?void 0:Te.title)==null?void 0:Be.bold)??!0,R=((dt=(Ge=e==null?void 0:e.fonts)==null?void 0:Ge.body_text)==null?void 0:dt.size)||14,W={backgroundColor:m,borderColor:y,borderRadius:`${v}px`,boxShadow:O?"0 1px 3px 0 rgba(0, 0, 0, 0.1)":"none",color:l},ne={fontSize:`${U}px`,fontWeight:T?"700":"400",color:((Ze=e==null?void 0:e.colors)==null?void 0:Ze.header)||l},Q={fontSize:`${R}px`,color:((tt=e==null?void 0:e.colors)==null?void 0:tt.input_labels_placeholders)||"#6b7280"},K={backgroundColor:d,borderColor:t?h:u,borderRadius:`${b}px`,color:f},de={backgroundColor:a,color:c,borderRadius:`${A}px`},N=((nt=e==null?void 0:e.widget)==null?void 0:nt.logo_position)||"center",C=N==="left"?"text-left":N==="right"?"text-right":"text-center",z=((rt=e==null?void 0:e.widget)==null?void 0:rt.logo_url)||(n==null?void 0:n.logo_url),k=N!=="none"&&z;return p("div",{className:ge("flex flex-col gap-6 w-full max-w-sm",s),children:p(_n,{style:W,className:"border",children:[p(yn,{children:[k&&p("div",{className:ge("mb-4",C),children:p(rn,{theme:e,branding:n})}),p(wn,{style:ne,children:w.t("forgot_password_title","Forgot Password")}),p(vn,{style:Q,children:w.t("forgot_password_description","Enter your email address and we'll send you a link to reset your password.")})]}),p(bn,{children:[p("form",{method:"post",className:"space-y-4",children:[p("input",{type:"hidden",name:"state",value:r.authParams.state}),p("div",{className:"space-y-2",children:[p(Lt,{htmlFor:"username",style:Q,className:"text-sm font-medium",children:w.t("email_label","Email")}),p(Qt,{id:"username",type:"email",name:"username",placeholder:w.t("email_placeholder","Email Address"),value:i,disabled:!!i,style:K,className:"w-full",required:!0})]}),t&&p(et,{children:t}),p(fn,{type:"submit",className:"w-full",style:de,disabled:!1,children:w.t("forgot_password_cta","Send Reset Link")})]}),p("div",{className:"mt-4 text-center",children:p("a",{href:`/u/login/identifier?state=${encodeURIComponent(r.authParams.state||"")}`,className:"text-sm",style:{color:a},children:w.t("back_to_login","Back to Login")})})]})]})})},H1=t=>{const{theme:e,branding:n,client:r,state:i}=t;return p(De,{title:"Login",theme:e,branding:n,client:r,children:[p("div",{className:"flex flex-1 flex-col justify-center",children:[p("div",{children:w.t("forgot_password_email_sent")}),p("div",{className:"my-4 flex space-x-2 text-sm text-[#B2B2B2]",children:[p(Ke,{className:"text-base",name:"info-bubble"}),p("div",{className:"text-sm text-gray-300 md:text-sm",children:w.t("sent_code_spam")})]})]}),p(It,{state:i})]})},$8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{200:{description:"Response"}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,client:i,loginSession:s,useShadcn:a}=await Ce(t,e);return a?t.html(p(Oe,{title:w.t("forgot_password_title","Forgot Password"),theme:n,branding:r,client:i,children:p(b8,{theme:n,branding:r,loginSession:s,email:s.authParams.username,client:i})})):t.html(p(q1,{theme:n,branding:r,client:i,state:e,email:s.authParams.username}))}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{200:{description:"Response"}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,client:i,loginSession:s}=await Ce(t,e);return await kx(t,i,s.authParams.username,s.id),t.html(p(H1,{theme:n,branding:r,client:i,state:e}))}),V1=({theme:t,branding:e,client:n,state:r,user:i})=>p(De,{title:pe("check_email_title"),theme:t,branding:e,client:n,children:p("div",{className:"flex flex-1 flex-col justify-center",children:[p("div",{className:"mb-8 text-gray-700 dark:text-gray-300",children:[p(Yn,{i18nKey:"currently_logged_in_as",components:[p("span",{className:"font-semibold text-gray-900 dark:text-white"},"span")],values:{email:i.email||""}}),p("br",{}),pe("continue_with_sso_provider_headline")]}),p("div",{className:"space-y-6",children:[p(on,{children:p(Ue,{className:"!text-base",children:p("span",{children:w.t("yes_continue_with_existing_account")})})}),p("a",{className:"block text-center text-primary hover:text-primaryHover focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 dark:focus:ring-offset-gray-900",href:`/u/login/identifier?state=${encodeURIComponent(r)}`,children:w.t("no_use_another")})]})]})}),k8=({theme:t,branding:e,state:n,user:r,className:i})=>{var K,de,N,C,z,k,$,I,L,q,F,Z,se,D,fe,$e,ce,ue,Ae,Ee;const s=((K=t==null?void 0:t.colors)==null?void 0:K.primary_button)||((de=e==null?void 0:e.colors)==null?void 0:de.primary)||"#0066cc",a=((N=t==null?void 0:t.colors)==null?void 0:N.primary_button_label)||"#ffffff",c=((C=t==null?void 0:t.colors)==null?void 0:C.body_text)||"#333333",l=((z=t==null?void 0:t.colors)==null?void 0:z.widget_background)||"#ffffff",d=((k=t==null?void 0:t.colors)==null?void 0:k.widget_border)||"#e5e7eb",u=(($=t==null?void 0:t.borders)==null?void 0:$.widget_corner_radius)||8,f=((I=t==null?void 0:t.borders)==null?void 0:I.button_border_radius)||4,h=((L=t==null?void 0:t.borders)==null?void 0:L.show_widget_shadow)??!0,m=((F=(q=t==null?void 0:t.fonts)==null?void 0:q.title)==null?void 0:F.size)||24,y=((se=(Z=t==null?void 0:t.fonts)==null?void 0:Z.title)==null?void 0:se.bold)??!0,v=((fe=(D=t==null?void 0:t.fonts)==null?void 0:D.body_text)==null?void 0:fe.size)||14,b={backgroundColor:l,borderColor:d,borderRadius:`${u}px`,boxShadow:h?"0 1px 3px 0 rgba(0, 0, 0, 0.1)":"none",color:c},A={fontSize:`${m}px`,fontWeight:y?"700":"400",color:(($e=t==null?void 0:t.colors)==null?void 0:$e.header)||c},O={fontSize:`${v}px`,color:((ce=t==null?void 0:t.colors)==null?void 0:ce.input_labels_placeholders)||"#6b7280"},U={backgroundColor:s,color:a,borderRadius:`${f}px`},T={color:((ue=t==null?void 0:t.colors)==null?void 0:ue.links_focused_components)||s,fontSize:`${v}px`},R=((Ae=t==null?void 0:t.widget)==null?void 0:Ae.logo_position)||"center",W=R==="left"?"text-left":R==="right"?"text-right":"text-center",ne=((Ee=t==null?void 0:t.widget)==null?void 0:Ee.logo_url)||(e==null?void 0:e.logo_url),Q=R!=="none"&&ne;return p("div",{className:ge("flex flex-col gap-6 w-full max-w-sm",i),children:p(_n,{style:b,className:"border",children:[p(yn,{children:[Q&&p("div",{className:ge("mb-4",W),children:p(rn,{theme:t,branding:e})}),p(wn,{style:A,children:w.t("continue_with_account","Continue with account")}),p(vn,{style:O,children:[p(Yn,{i18nKey:"currently_logged_in_as",components:[p("span",{className:"font-semibold"},"span")],values:{email:r.email||""}}),p("br",{}),p("br",{}),w.t("continue_with_sso_provider_headline","Do you want to continue with this account?")]})]}),p(bn,{children:p("form",{method:"post",children:p("div",{className:"grid gap-4",children:[p(fn,{type:"submit",className:"w-full transition-colors hover:brightness-90",style:U,children:w.t("yes_continue_with_existing_account","Yes, continue")}),p("div",{className:"text-center",children:p("a",{href:`/u/login/identifier?state=${encodeURIComponent(n)}`,className:"text-sm hover:underline focus:outline-none focus:ring-2 focus:ring-offset-2 transition-colors",style:T,children:w.t("no_use_another","No, use another account")})})]})})})]})})},x8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{200:{description:"HTML page to check account status or verify email.",content:{"text/html":{schema:o.z.string()}}},302:{description:"Redirect to login identifier page if no valid session.",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML error page if state is missing or other input error.",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{var u;const{env:e}=t,{state:n}=t.req.valid("query"),{theme:r,branding:i,client:s,useShadcn:a}=await Ce(t,n);if(!s||!((u=s.tenant)!=null&&u.id))return console.error("Client or tenant ID missing in GET /u/check-account after initJSXRoute"),t.html(p(Dt,{theme:r,branding:i,client:s,state:n,pageTitle:w.t("error_page_title")||"Error",message:w.t("configuration_error_message")||"A configuration error occurred."}),500);const c=ni(s.tenant.id,t.req.header("cookie")),l=c?await e.data.sessions.get(s.tenant.id,c):null;if(!l)return t.redirect(`/u/login/identifier?state=${n}`);const d=await e.data.users.get(s.tenant.id,l.user_id);return d?a?t.html(p(Oe,{title:w.t("continue_with_account","Continue with account"),theme:r,branding:i,client:s,children:p(k8,{theme:r,branding:i,client:s,state:n,user:d})})):t.html(p(V1,{theme:r,branding:i,client:s,state:n,user:d})):t.redirect(`/u/login/identifier?state=${n}`)}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{302:{description:"Redirect to continue authentication flow or to login identifier.",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML error page if state is missing or other input error.",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page for unexpected issues or if TokenResponse is returned.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{var f;const{env:e}=t,{state:n}=t.req.valid("query"),{theme:r,branding:i,client:s,loginSession:a}=await Ce(t,n);if(!s||!((f=s.tenant)!=null&&f.id))return console.error("Client or tenant ID missing in POST /u/check-account after initJSXRoute"),t.html(p(Dt,{theme:r,branding:i,client:s,state:n,pageTitle:w.t("error_page_title")||"Error",message:w.t("configuration_error_message")}),500);const c=ni(s.tenant.id,t.req.header("cookie")),l=c?await e.data.sessions.get(s.tenant.id,c):null;if(!l)return t.redirect(`/u/login/identifier?state=${n}`);const d=await e.data.users.get(s.tenant.id,l.user_id);if(!d)return t.redirect(`/u/login/identifier?state=${n}`);await e.data.loginSessions.update(s.tenant.id,a.id,{session_id:l.id});const u=await un(t,{user:d,authParams:a.authParams,client:s,loginSession:{...a,session_id:l.id},sessionId:l.id});if(!(u instanceof Response))throw new S(500,{message:w.t("unexpected_error_try_again")});return u}),S8=({width:t=18,height:e=18,className:n})=>p("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:e,viewBox:"0 0 640 640",className:n,fill:"currentColor",role:"img",focusable:"false",children:p("path",{d:"M416.9 85.2 372 130.1 509.9 268l44.9-44.9c13.6-13.5 21.2-31.9 21.2-51.1s-7.6-37.6-21.2-51.1l-35.7-35.7C505.6 71.6 487.2 64 468 64s-37.6 7.6-51.1 21.2M338.1 164 122.9 379.1c-10.7 10.7-18.5 24.1-22.6 38.7L64.9 545.6c-2.3 8.3 0 17.3 6.2 23.4s15.1 8.5 23.4 6.2l127.8-35.5c14.6-4.1 27.9-11.8 38.7-22.6l215-215.2z"})}),z8=!1,n0=t=>{var d;const{theme:e,branding:n,user:r,client:i,error:s,success:a,state:c,csrfToken:l}=t;return(d=r.identities)!=null&&d.filter(u=>!(u.provider===r.provider&&u.user_id===r.user_id.split("|")[1])),p(De,{title:w.t("account_title")||"Account Settings",theme:e,branding:n,client:i,children:[p("div",{className:"mb-4 text-2xl font-medium",children:w.t("account_title")}),p("div",{className:"mb-8 text-gray-300",children:w.t("account_page_description")}),s&&p(et,{className:"mb-8",children:s}),a&&p("div",{className:"mb-8 text-green",children:a}),p("div",{className:"column-left gap-6 border-y border-gray-200/50 py-6 mb-8",children:[p("div",{className:"row-left w-full !justify-between !flex-nowrap gap-4",children:[p("div",{className:"column-left gap-1.5",children:[p("div",{className:"text-gray-300",children:w.t("email_placeholder")}),p("div",{className:"font-medium text-base text-gray-800 line-clamp-1 break-all",children:r.email||w.t("no_email_address")})]}),p("a",{className:"bg-gray-200/40 p-2 rounded-md hover:bg-gray-200/75",title:w.t("edit"),"aria-label":w.t("edit"),href:c?`/u/account/change-email?state=${encodeURIComponent(c)}`:`/u/account/change-email?client_id=${encodeURIComponent(i.client_id)}`,children:p(S8,{})})]}),z8]})]})},A8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{200:{description:"HTML page showing account management interface.",content:{"text/html":{schema:o.z.string()}}},302:{description:"Redirect to login if no session",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML error page if state is missing or other input error.",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{var d;const{env:e}=t,{state:n}=t.req.valid("query"),{theme:r,branding:i,client:s,user:a,loginSession:c}=await jr(t,n);if(!s||!((d=s.tenant)!=null&&d.id))return console.error("Client or tenant ID missing in GET /u/account after initJSXRoute"),t.html(p(Dt,{theme:r,branding:i,client:s,state:n,pageTitle:w.t("error_page_title")||"Error",message:w.t("configuration_error_message")||"A configuration error occurred."}),500);const l=Ne();return await e.data.loginSessions.update(s.tenant.id,c.id,{csrf_token:l}),t.html(p(n0,{theme:r,branding:i,user:a,client:s,state:n,csrfToken:l}))}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})}),body:{content:{"application/x-www-form-urlencoded":{schema:o.z.object({action:o.z.enum(["unlink_account"]),provider:o.z.string().optional(),user_id:o.z.string().optional(),csrf_token:o.z.string().optional()})}}}},responses:{200:{description:"HTML response with form results",content:{"text/html":{schema:o.z.string()}}},302:{description:"Redirect to login if no session",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML error page if state is missing or other input error.",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{const{env:e}=t,{state:n}=t.req.valid("query"),r=t.req.valid("form"),{theme:i,branding:s,client:a,user:c,loginSession:l}=await jr(t,n);let d,u;try{if(r.action==="unlink_account"&&r.provider&&r.user_id){if(!r.csrf_token||r.csrf_token!==l.csrf_token)throw new Error("Invalid CSRF token");await e.data.users.unlink(a.tenant.id,c.user_id,r.provider,r.user_id),u=w.t("account_unlinked_successfully")||"Account unlinked successfully"}}catch{d=w.t("operation_failed")||"Operation failed"}const f=await e.data.users.get(a.tenant.id,c.user_id),h=Ne();return await e.data.loginSessions.update(a.tenant.id,l.id,{csrf_token:h}),t.html(p(n0,{theme:i,branding:s,user:f||c,client:a,error:d,success:u,state:n,csrfToken:h}))}),r0=t=>{const{theme:e,branding:n,user:r,client:i,state:s,error:a}=t;return p(De,{title:w.t("change_email"),theme:e,branding:n,client:i,children:[p("div",{className:"mb-4 text-2xl font-medium",children:w.t("change_email")}),p("div",{className:"column-left gap-1 mb-8",children:[p("div",{className:"text-gray-300",children:w.t("current_email")}),p("div",{className:"font-medium text-base text-gray-800",children:r.email||w.t("no_email_address")})]}),p("div",{className:"flex flex-1 flex-col justify-center",children:[p(on,{children:[p("input",{type:"email",id:"email",name:"email",placeholder:w.t("new_email"),className:ge("mb-2 w-full rounded-lg border bg-gray-100 px-4 py-5 text-base placeholder:text-gray-300 dark:bg-gray-600 md:text-base",{"border-red":a,"border-gray-100 dark:border-gray-500":!a}),required:!0}),a&&p(et,{children:a}),p(Ue,{className:"sm:mt-4 !text-base",children:[p("span",{children:w.t("continue")}),p(Ke,{className:"text-xs",name:"arrow-right"})]}),p("div",{className:"my-4 flex space-x-2 text-sm text-[#B2B2B2]",children:[p("span",{className:"uicon-info-bubble text-base"}),p("div",{className:"text-sm text-gray-300 md:text-sm",children:w.t("new_email_code_info")})]})]}),p("a",{className:"block text-primary hover:text-primaryHover text-center",href:`/u/account?state=${encodeURIComponent(s)}`,children:w.t("go_back")})]})]})},E8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{200:{description:"HTML page showing email change interface.",content:{"text/html":{schema:o.z.string()}}},302:{description:"Redirect to login if no session",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML error page if state is missing or other input error.",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,client:i,user:s}=await jr(t,e);return t.html(p(r0,{theme:n,branding:r,user:s,client:i,state:e}))}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})}),body:{content:{"application/x-www-form-urlencoded":{schema:o.z.object({email:o.z.string().toLowerCase()})}}}},responses:{200:{description:"HTML response with form results",content:{"text/html":{schema:o.z.string()}}},302:{description:"Redirect to change-email verification page",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML error page if state is missing or other input error.",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{var m,y,v,b;const{env:e}=t,{state:n}=t.req.valid("query"),{email:r}=t.req.valid("form"),{theme:i,branding:s,client:a,user:c,loginSession:l}=await jr(t,n),d=await e.data.users.list(a.tenant.id,{page:1,per_page:1,include_totals:!1,q:`email:"${r}"`});if(d.users.length>0&&((m=d.users[0])==null?void 0:m.user_id)!==c.user_id)return t.html(p(r0,{theme:i,branding:s,user:c,client:a,state:n,error:w.t("email_already_taken")||"Email is already taken"}));const u=Zn(),f=Ne();await e.data.codes.create(a.tenant.id,{code_id:f,login_id:"",code_type:"email_verification",expires_at:new Date(Date.now()+Cl).toISOString(),user_id:c.user_id}),await e.data.codes.create(a.tenant.id,{code_id:u,login_id:"",code_type:"email_verification",expires_at:new Date(Date.now()+Cl).toISOString(),user_id:c.user_id});const h=(b=(v=(y=l.authParams)==null?void 0:y.ui_locales)==null?void 0:v.split(" "))==null?void 0:b.map(A=>A.split("-")[0])[0];return await Bp(t,{to:r,code:u,language:h}),t.redirect(`/u/account/change-email-verify?state=${encodeURIComponent(n)}&email=${encodeURIComponent(r)}&change_id=${f}`)}),i0=6,pu=({error:t,theme:e,branding:n,client:r,email:i,success:s,state:a,redirectUrl:c})=>s?p(De,{title:w.t("success"),theme:e,branding:n,client:r,children:[p("div",{className:"mb-4 text-2xl font-medium",children:w.t("success")}),p("div",{className:"mb-8 text-gray-300",children:p(Yn,{i18nKey:"email_changed_to_template",components:[p("span",{className:"text-black dark:text-white"},"span")],values:{email:i}})}),p("div",{className:"flex flex-1 flex-col justify-center",children:p(Ue,{Component:"a",href:c||(a?`/u/account?state=${encodeURIComponent(a)}`:`/u/account?client_id=${encodeURIComponent(r.client_id)}`),className:"sm:mt-4 !text-base",children:[p("span",{children:w.t("continue")}),p(Ke,{className:"text-xs",name:"arrow-right"})]})})]}):p(De,{title:w.t("verify_email_verify"),theme:e,branding:n,client:r,children:[p("div",{className:"mb-4 text-2xl font-medium",children:w.t("verify_email_verify")}),p("div",{className:"mb-8 text-gray-300",children:p(Yn,{i18nKey:"code_sent_template",components:[p("span",{className:"text-black dark:text-white"},"span")],values:{username:i}})}),p("div",{className:"flex flex-1 flex-col justify-center",children:[p(on,{className:"pt-2",children:[p("input",{autoFocus:!0,type:"text",pattern:"[0-9]*",maxLength:i0,inputMode:"numeric",name:"code",placeholder:"******",className:ge("mb-2 w-full rounded-lg border bg-gray-100 px-4 pb-2 pt-2.5 text-center indent-[5px] font-mono text-3xl placeholder:text-gray-300 dark:bg-gray-600 md:text-3xl",{"border-red":t,"border-gray-100 dark:border-gray-500":!t}),minLength:i0,required:!0,id:"code-input"}),t&&p(et,{children:t}),p(Ue,{className:"sm:mt-4 !text-base",children:[p("span",{children:w.t("continue")}),p(Ke,{className:"text-xs",name:"arrow-right"})]}),p("div",{className:"my-4 flex space-x-2 text-sm text-[#B2B2B2]",children:[p(Ke,{className:"text-base",name:"info-bubble"}),p("div",{className:"text-sm text-gray-300 md:text-sm",children:w.t("sent_code_spam")})]})]}),p("a",{className:"block text-primary hover:text-primaryHover text-center",href:a?`/u/account?state=${encodeURIComponent(a)}`:`/u/account?client_id=${encodeURIComponent(r.client_id)}`,children:w.t("go_back")})]})]}),C8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"}),email:o.z.string().email(),change_id:o.z.string()})},responses:{200:{description:"HTML page for email change verification",content:{"text/html":{schema:o.z.string()}}},302:{description:"Redirect to account or login if no session",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML error page if state is missing or other input error.",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{const{state:e,email:n,change_id:r}=t.req.valid("query"),{theme:i,branding:s,client:a,user:c}=await jr(t,e),l=await t.env.data.codes.get(a.tenant.id,r,"email_verification");return!l||l.user_id!==c.user_id?t.redirect(`/u/account?state=${e}`):t.html(p(pu,{theme:i,branding:s,client:a,email:n,state:e}))}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"}),email:o.z.string().toLowerCase(),change_id:o.z.string()}),body:{content:{"application/x-www-form-urlencoded":{schema:o.z.object({code:o.z.string()})}}}},responses:{200:{description:"HTML response with verification result",content:{"text/html":{schema:o.z.string()}}},302:{description:"Redirect to confirmation page on success",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML error page if state is missing or other input error.",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{const{env:e}=t,{state:n,email:r,change_id:i}=t.req.valid("query"),{code:s}=t.req.valid("form"),{theme:a,branding:c,client:l,user:d}=await jr(t,n);let u;try{const f=await e.data.codes.get(l.tenant.id,i,"email_verification");if(!f)u=w.t("invalid_request");else if(f.user_id!==d.user_id)u=w.t("invalid_request");else if(f.used_at)u=w.t("code_already_used");else if(new Date(f.expires_at)<new Date)u=w.t("code_expired");else{const h=await e.data.codes.get(l.tenant.id,s,"email_verification");if(!h)u=w.t("invalid_code");else if(h.used_at)u=w.t("code_already_used");else if(new Date(h.expires_at)<new Date)u=w.t("code_expired");else if(h.user_id!==d.user_id)u=w.t("invalid_code");else return await e.data.codes.used(l.tenant.id,i),await e.data.codes.used(l.tenant.id,s),await e.data.users.update(l.tenant.id,d.user_id,{email:r,email_verified:!0}),t.redirect(`/u/account/change-email-confirmation?state=${encodeURIComponent(n)}&email=${encodeURIComponent(r)}`)}}catch{u=w.t("operation_failed")}return t.html(p(pu,{theme:a,branding:c,client:l,email:r,error:u,state:n}))}),N8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"}),email:o.z.string().email()})},responses:{200:{description:"HTML page showing email change confirmation",content:{"text/html":{schema:o.z.string()}}},302:{description:"Redirect to login if no session",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML error page if state is missing or other input error.",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{var l,d;const{state:e,email:n}=t.req.valid("query"),{theme:r,branding:i,client:s,loginSession:a}=await jr(t,e);if(!s||!((l=s.tenant)!=null&&l.id))return console.error("Client or tenant ID missing in GET /u/change-email-confirmation after initJSXRoute"),t.html(p(Dt,{theme:r,branding:i,client:s,state:e,pageTitle:w.t("error_page_title")||"Error",message:w.t("configuration_error_message")||"A configuration error occurred."}),500);let c=`/u/account?state=${encodeURIComponent(e)}`;return a!=null&&a.authorization_url&&new URL(a.authorization_url).searchParams.get("screen_hint")==="change-email"&&(c=((d=a.authParams)==null?void 0:d.redirect_uri)||c),t.html(p(pu,{theme:r,branding:i,client:s,email:n,success:!0,state:e,redirectUrl:c}))}),K1=t=>{const{theme:e,branding:n,client:r,email:i,state:s}=t;return p(De,{title:w.t("create_password_account_title"),theme:e,branding:n,client:r,children:[p("div",{className:"mb-4 text-lg font-medium sm:text-2xl",children:w.t("create_password_account_title")}),p("div",{className:"mb-6 text-gray-300",children:w.t("enter_email_for_verification_description")}),p("div",{className:"flex flex-1 flex-col justify-center",children:p(on,{className:"pt-2",children:[p("input",{type:"email",name:"username",placeholder:w.t("email_placeholder"),className:"mb-2 w-full rounded-lg bg-gray-100 px-4 py-5 text-base placeholder:text-gray-300 dark:bg-gray-600 md:text-base",required:!0,value:i,disabled:!0}),p(Ue,{className:"sm:mt-4 !text-base",children:w.t("send")})]})}),p(It,{state:s})]})},I8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{200:{description:"Response"}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,client:i,loginSession:s}=await Ce(t,e),{username:a}=s.authParams;if(!a)throw new S(400,{message:"Username required"});return t.html(p(K1,{state:e,theme:n,branding:r,client:i,email:a}))}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{200:{description:"Response"}}}),async t=>{const{state:e}=t.req.valid("query"),{loginSession:n,client:r}=await Ce(t,e),{username:i}=n.authParams;if(!i)throw new S(400,{message:"Username required"});const s=await t.env.data.codes.create(r.tenant.id,{code_id:Zn(),code_type:"email_verification",login_id:n.id,expires_at:new Date(Date.now()+Cl).toISOString()});return await vx(t,i,s.code_id,n.id),t.redirect(`/u/pre-signup-sent?state=${e}`)}),G1=t=>{const{redirectUrl:e,theme:n,branding:r,client:i}=t;return p(De,{title:w.t("invalid_session_title"),theme:n,branding:r,client:i,children:[p("div",{className:"flex flex-1 flex-col justify-center",children:w.t("invalid_session_body")}),p("div",{className:"flex flex-1 flex-col justify-center",children:e&&p("a",{className:"block text-primary hover:text-primaryHover text-center",href:e,children:w.t("go_back")})})]})},j8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string()})},responses:{200:{description:"Response"}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,client:i,loginSession:s}=await Ce(t,e);let a;return s.authParams.redirect_uri&&s.authParams.state&&(a=new URL(s.authParams.redirect_uri),a.searchParams.set("state",s.authParams.state),a.searchParams.set("error","invalid_session"),a.searchParams.set("error_description",s.authParams.username||"")),t.html(p(G1,{redirectUrl:a==null?void 0:a.href,theme:n,branding:r,client:i}))}),O8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"}),code:o.z.string().openapi({description:"The code parameter from the authorization request"})})},responses:{200:{description:"Response"}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,client:i}=await Ce(t,e);return t.html(p(Dt,{message:"Not implemented",pageTitle:"User info",theme:n,branding:r,client:i,state:e}))}),W1=({theme:t,branding:e,client:n,state:r})=>{const i=new URLSearchParams({state:r});return p(De,{title:w.t("email_validated"),theme:t,branding:e,client:n,children:[p("div",{className:"mb-4 text-lg font-medium sm:text-2xl",children:w.t("email_validated")}),p("div",{className:"flex flex-1 flex-col justify-center mb-7",children:p(Ue,{Component:"a",href:`/u/enter-password?${i}`,className:"text-base sm:mt-4 md:text-base",children:p("div",{className:"flex items-center space-x-2",children:[p("span",{children:w.t("email_validated_cta")}),p(Ke,{className:"text-xs",name:"arrow-right"})]})})})]})},T8=({theme:t,branding:e,loginSession:n,className:r})=>{var Q,K,de,N,C,z,k,$,I,L,q,F,Z,se,D,fe,$e,ce,ue,Ae;const i=((Q=t==null?void 0:t.colors)==null?void 0:Q.primary_button)||((K=e==null?void 0:e.colors)==null?void 0:K.primary)||"#0066cc",s=((de=t==null?void 0:t.colors)==null?void 0:de.primary_button_label)||"#ffffff",a=((N=t==null?void 0:t.colors)==null?void 0:N.body_text)||"#333333",c=((C=t==null?void 0:t.colors)==null?void 0:C.widget_background)||"#ffffff",l=((z=t==null?void 0:t.colors)==null?void 0:z.widget_border)||"#e5e7eb",d=((k=t==null?void 0:t.colors)==null?void 0:k.success)||"#10b981",u=(($=t==null?void 0:t.borders)==null?void 0:$.widget_corner_radius)||8,f=((I=t==null?void 0:t.borders)==null?void 0:I.button_border_radius)||4,h=((L=t==null?void 0:t.borders)==null?void 0:L.show_widget_shadow)??!0,m=((F=(q=t==null?void 0:t.fonts)==null?void 0:q.title)==null?void 0:F.size)||24,y=((se=(Z=t==null?void 0:t.fonts)==null?void 0:Z.title)==null?void 0:se.bold)??!0,v=((fe=(D=t==null?void 0:t.fonts)==null?void 0:D.body_text)==null?void 0:fe.size)||14,b={backgroundColor:c,borderColor:l,borderRadius:`${u}px`,boxShadow:h?"0 1px 3px 0 rgba(0, 0, 0, 0.1)":"none",color:a},A={fontSize:`${m}px`,fontWeight:y?"700":"400",color:(($e=t==null?void 0:t.colors)==null?void 0:$e.header)||a},O={fontSize:`${v}px`,color:((ce=t==null?void 0:t.colors)==null?void 0:ce.input_labels_placeholders)||"#6b7280"},U={backgroundColor:i,color:s,borderRadius:`${f}px`},T=((ue=t==null?void 0:t.widget)==null?void 0:ue.logo_position)||"center",R=T==="left"?"text-left":T==="right"?"text-right":"text-center",W=((Ae=t==null?void 0:t.widget)==null?void 0:Ae.logo_url)||(e==null?void 0:e.logo_url),ne=T!=="none"&&W;return p("div",{className:ge("flex flex-col gap-6 w-full max-w-sm",r),children:p(_n,{style:b,className:"border",children:[p(yn,{children:[ne&&p("div",{className:ge("mb-4",R),children:p(rn,{theme:t,branding:e})}),p("div",{className:"flex justify-center mb-4",children:p("div",{className:"rounded-full p-3",style:{backgroundColor:`${d}15`},children:p("svg",{xmlns:"http://www.w3.org/2000/svg",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:d,"stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),p("polyline",{points:"22 4 12 14.01 9 11.01"})]})})}),p(wn,{style:A,className:"text-center",children:w.t("email_validated","Email Verified")}),p(vn,{style:O,className:"text-center",children:w.t("email_validated_description","Your email has been successfully verified. You can now continue to login.")})]}),p(bn,{children:p("a",{href:`/u/enter-password?state=${encodeURIComponent(n.authParams.state||"")}`,className:"w-full flex items-center justify-center gap-2 h-10 px-4 py-2 rounded-md font-medium transition-colors",style:U,children:[p("span",{children:w.t("email_validated_cta","Continue to Login")}),p("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("line",{x1:"5",y1:"12",x2:"19",y2:"12"}),p("polyline",{points:"12 5 19 12 12 19"})]})]})})]})})},P8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"}),code:o.z.string().openapi({description:"The code parameter from the authorization request"})})},responses:{200:{description:"Response"}}}),async t=>{var y;const{state:e,code:n}=t.req.valid("query"),{env:r}=t,{client:i,loginSession:s,theme:a,branding:c,useShadcn:l}=await Ce(t,e),{username:d}=s.authParams;if(!d)throw new S(400,{message:"Username not found in state"});const u=await vi({userAdapter:r.data.users,tenant_id:i.tenant.id,username:d,provider:"auth2"});if(!u)throw new S(500,{message:"No user found"});if(!await r.data.codes.get(i.tenant.id,n,"email_verification"))throw new S(400,{message:"Code not found or expired"});await r.data.users.update(i.tenant.id,u.user_id,{email_verified:!0});const m=(await Eu(r.data.users,i.tenant.id,d)).filter(v=>v.provider!=="auth2");if(m.length>0){const v=m.filter(b=>!b.linked_to);v.length>1&&console.error("More than one primary user found for email",d),v.length===0&&console.error("No primary user found for email",d),v.length===1&&await r.data.users.update(i.tenant.id,u.user_id,{linked_to:(y=v[0])==null?void 0:y.user_id})}return l?t.html(p(Oe,{title:w.t("email_validated","Email Verified"),theme:a,branding:c,client:i,children:p(T8,{theme:a,branding:c,loginSession:s,client:i})})):t.html(p(W1,{theme:a,branding:c,client:i,state:e}))}),J1=t=>{const{theme:e,branding:n,client:r,email:i,state:s}=t;return p(De,{title:w.t("sign_up_success"),theme:e,branding:n,client:r,children:[p("div",{className:"mb-4 text-lg font-medium sm:text-2xl",children:w.t("email_verification_for_signup_sent_title")}),p("div",{className:"flex flex-1 flex-col justify-center",children:[p("div",{className:"mb-6 text-gray-300",children:p(Yn,{i18nKey:"email_verification_for_signup_sent_description",components:[p("span",{className:"text-black dark:text-white"},"span")],values:{email:i}})}),p("div",{className:"my-4 flex space-x-2 text-sm text-[#B2B2B2]",children:[p(Ke,{className:"text-base",name:"info-bubble"}),p("div",{className:"text-sm text-gray-300 md:text-sm",children:w.t("sent_code_spam")})]})]}),p(It,{state:s})]})},R8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{200:{description:"Response"}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,client:i,loginSession:s}=await Ce(t,e),{username:a}=s.authParams;if(!a)throw new S(400,{message:"Username required"});return t.html(p(J1,{theme:n,branding:r,client:i,state:e,email:a}))}),Fp=`
233
+ `])))]})},vl=({error:t,theme:e,branding:n,loginSession:r,email:i,className:s})=>{var $,I,L,q,F,Z,se,D,fe,$e,ce,ue,Ae,Ee,Re,Se,Te,Be,Ge,dt,Ze,tt,nt,rt;const a=(($=e==null?void 0:e.colors)==null?void 0:$.primary_button)||((I=n==null?void 0:n.colors)==null?void 0:I.primary)||"#0066cc",c=((L=e==null?void 0:e.colors)==null?void 0:L.primary_button_label)||"#ffffff",l=((q=e==null?void 0:e.colors)==null?void 0:q.body_text)||"#333333",d=((F=e==null?void 0:e.colors)==null?void 0:F.input_background)||"#ffffff",u=((Z=e==null?void 0:e.colors)==null?void 0:Z.input_border)||"#d1d5db",f=((se=e==null?void 0:e.colors)==null?void 0:se.input_filled_text)||"#111827",h=((D=e==null?void 0:e.colors)==null?void 0:D.error)||"#dc2626",m=((fe=e==null?void 0:e.colors)==null?void 0:fe.widget_background)||"#ffffff",y=(($e=e==null?void 0:e.colors)==null?void 0:$e.widget_border)||"#e5e7eb",v=((ce=e==null?void 0:e.borders)==null?void 0:ce.widget_corner_radius)||8,b=((ue=e==null?void 0:e.borders)==null?void 0:ue.input_border_radius)||4,A=((Ae=e==null?void 0:e.borders)==null?void 0:Ae.button_border_radius)||4,O=((Ee=e==null?void 0:e.borders)==null?void 0:Ee.show_widget_shadow)??!0,U=((Se=(Re=e==null?void 0:e.fonts)==null?void 0:Re.title)==null?void 0:Se.size)||24,T=((Be=(Te=e==null?void 0:e.fonts)==null?void 0:Te.title)==null?void 0:Be.bold)??!0,R=((dt=(Ge=e==null?void 0:e.fonts)==null?void 0:Ge.body_text)==null?void 0:dt.size)||14,W={backgroundColor:m,borderColor:y,borderRadius:`${v}px`,boxShadow:O?"0 1px 3px 0 rgba(0, 0, 0, 0.1)":"none",color:l},ne={fontSize:`${U}px`,fontWeight:T?"700":"400",color:((Ze=e==null?void 0:e.colors)==null?void 0:Ze.header)||l},Q={fontSize:`${R}px`,color:((tt=e==null?void 0:e.colors)==null?void 0:tt.input_labels_placeholders)||"#6b7280"},K={backgroundColor:d,borderColor:t?h:u,borderRadius:`${b}px`,color:f},de={backgroundColor:a,color:c,borderRadius:`${A}px`},N=((nt=e==null?void 0:e.widget)==null?void 0:nt.logo_position)||"center",C=N==="left"?"text-left":N==="right"?"text-right":"text-center",z=((rt=e==null?void 0:e.widget)==null?void 0:rt.logo_url)||(n==null?void 0:n.logo_url),k=N!=="none"&&z;return p("div",{className:ge("flex flex-col gap-6 w-full max-w-sm",s),children:p(_n,{style:W,className:"border",children:[p(yn,{children:[k&&p("div",{className:ge("mb-4",C),children:p(nn,{theme:e,branding:n})}),p(wn,{style:ne,children:w.t("enter_password","Enter your password")}),p(vn,{style:Q,children:w.t("enter_password_description","Enter your password to continue")})]}),p(bn,{children:p("form",{method:"post",children:p("div",{className:"grid gap-6",children:[p("div",{className:"grid gap-2",children:[p(Lt,{htmlFor:"email",style:Q,children:w.t("email","Email")}),p(Yt,{id:"email",name:"username",type:"email",value:i,disabled:!0,className:"border bg-gray-50",style:{...K,cursor:"not-allowed"}})]}),p("div",{className:"grid gap-2",children:[p("div",{className:"flex items-center justify-between",children:[p(Lt,{htmlFor:"password",style:Q,children:w.t("password","Password")}),p("a",{href:`/u/forgot-password?state=${r.id}`,className:"text-sm hover:underline",style:{color:a},children:w.t("forgot_password","Forgot password?")})]}),p("div",{className:"relative","data-password-toggle":!0,children:[p(Yt,{id:"password",name:"password",type:"password","data-password-input":"password",placeholder:w.t("password_placeholder","Enter your password"),required:!0,error:!!t,className:"border pr-8",style:K}),p("button",{type:"button","data-password-toggle-btn":!0,className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700 transition-colors","aria-label":w.t("toggle_password_visibility","Toggle password visibility"),children:[p("svg",{"data-show-icon":!0,xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"}),p("circle",{cx:"12",cy:"12",r:"3"})]}),p("svg",{"data-hide-icon":!0,className:"hidden",xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M9.88 9.88a3 3 0 1 0 4.24 4.24"}),p("path",{d:"M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"}),p("path",{d:"M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"}),p("line",{x1:"2",x2:"22",y1:"2",y2:"22"})]})]})]}),t&&p(et,{children:t})]}),p(fn,{type:"submit",className:"w-full transition-colors hover:brightness-90",style:de,children:w.t("continue","Continue")}),p("div",{className:"text-center",children:p("a",{href:`/u/login/identifier?state=${r.id}`,className:"text-sm hover:underline",style:Q,children:["← ",w.t("back","Back")]})})]})})})]})})},y8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{200:{description:"Response"}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,client:i,loginSession:s,useShadcn:a}=await Ce(t,e);if(!s.authParams.username)throw new S(400,{message:"Username required"});return a?t.html(p(Oe,{title:w.t("enter_your_password","Enter your password"),theme:n,branding:r,client:i,children:p(vl,{theme:n,branding:r,loginSession:s,email:s.authParams.username,client:i})})):t.html(p(Es,{theme:n,branding:r,email:s.authParams.username,state:e,client:i}))}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})}),body:{content:{"application/x-www-form-urlencoded":{schema:o.z.object({password:o.z.string()})}}}},responses:{200:{description:"HTML page indicating success or a next step (if not redirecting).",content:{"text/html":{schema:o.z.string()}}},302:{description:"Redirect to continue the authentication flow (e.g., to client, MFA, consent).",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML page with an error message (e.g., invalid password, username required).",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML page with an error message.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{const{state:e}=t.req.valid("query"),n=t.req.valid("form"),{password:r}=n,{theme:i,branding:s,client:a,loginSession:c,useShadcn:l}=await Ce(t,e),{username:d}=c.authParams;if(!d)throw new S(400,{message:"Username required"});try{return await A1(t,a,{...c.authParams,password:r},c)}catch(u){const f=u;return f.code==="INVALID_PASSWORD"||f.code==="USER_NOT_FOUND"?l?t.html(p(Oe,{title:w.t("enter_your_password","Enter your password"),theme:i,branding:s,client:a,children:p(vl,{theme:i,branding:s,loginSession:c,email:d,error:w.t("invalid_password"),client:a})}),400):t.html(p(Es,{theme:i,branding:s,email:d,error:w.t("invalid_password"),state:e,client:a}),400):f.code==="EMAIL_NOT_VERIFIED"?t.html(p(F1,{theme:i,branding:s,client:a,state:e}),400):l?t.html(p(Oe,{title:w.t("enter_your_password","Enter your password"),theme:i,branding:s,client:a,children:p(vl,{theme:i,branding:s,loginSession:c,email:d,error:f.message||"An unknown error occurred.",client:a})}),f.code?400:500):t.html(p(Es,{theme:i,branding:s,email:d,error:f.message||"An unknown error occurred.",state:e,client:a}),f.code?400:500)}}),ir=t=>{const{error:e,theme:n,branding:r,client:i,email:s,state:a,code:c}=t;return p(De,{title:w.t("sign_up"),theme:n,branding:r,client:i,children:[p("div",{className:"mb-4 text-lg font-medium sm:text-2xl",children:w.t("create_account_title")}),p("div",{className:"mb-6 text-gray-300",children:w.t("create_account_description")}),p("div",{className:"flex flex-1 flex-col justify-center",children:[p(rn,{children:[p("input",{type:"hidden",name:"code",value:c}),p("input",{type:"email",name:"username",placeholder:w.t("email_placeholder"),className:"mb-2 w-full rounded-lg bg-gray-100 px-4 py-5 text-base placeholder:text-gray-300 dark:bg-gray-600 md:text-base",required:!0,value:s,disabled:!!s}),p("input",{type:"password",name:"password",placeholder:w.t("enter_new_password_placeholder"),className:"mb-2 w-full rounded-lg bg-gray-100 px-4 py-5 text-base placeholder:text-gray-300 dark:bg-gray-600 md:text-base"}),p("input",{type:"password",name:"re-enter-password",placeholder:w.t("reenter_new_password_placeholder"),className:"mb-2 w-full rounded-lg bg-gray-100 px-4 py-5 text-base placeholder:text-gray-300 dark:bg-gray-600 md:text-base"}),e&&p(et,{children:e}),p(Ue,{className:"sm:mt-4 !text-base",children:w.t("continue")})]}),p(Nt,{state:a})]})]})},Di=({error:t,theme:e,branding:n,loginSession:r,email:i,code:s,className:a})=>{var I,L,q,F,Z,se,D,fe,$e,ce,ue,Ae,Ee,Re,Se,Te,Be,Ge,dt,Ze,tt,nt,rt,Rn;const c=((I=e==null?void 0:e.colors)==null?void 0:I.primary_button)||((L=n==null?void 0:n.colors)==null?void 0:L.primary)||"#0066cc",l=((q=e==null?void 0:e.colors)==null?void 0:q.primary_button_label)||"#ffffff",d=((F=e==null?void 0:e.colors)==null?void 0:F.body_text)||"#333333",u=((Z=e==null?void 0:e.colors)==null?void 0:Z.input_background)||"#ffffff",f=((se=e==null?void 0:e.colors)==null?void 0:se.input_border)||"#d1d5db",h=((D=e==null?void 0:e.colors)==null?void 0:D.input_filled_text)||"#111827",m=((fe=e==null?void 0:e.colors)==null?void 0:fe.error)||"#dc2626",y=(($e=e==null?void 0:e.colors)==null?void 0:$e.widget_background)||"#ffffff",v=((ce=e==null?void 0:e.colors)==null?void 0:ce.widget_border)||"#e5e7eb",b=((ue=e==null?void 0:e.borders)==null?void 0:ue.widget_corner_radius)||8,A=((Ae=e==null?void 0:e.borders)==null?void 0:Ae.input_border_radius)||4,O=((Ee=e==null?void 0:e.borders)==null?void 0:Ee.button_border_radius)||4,U=((Re=e==null?void 0:e.borders)==null?void 0:Re.show_widget_shadow)??!0,T=((Te=(Se=e==null?void 0:e.fonts)==null?void 0:Se.title)==null?void 0:Te.size)||24,R=((Ge=(Be=e==null?void 0:e.fonts)==null?void 0:Be.title)==null?void 0:Ge.bold)??!0,W=((Ze=(dt=e==null?void 0:e.fonts)==null?void 0:dt.body_text)==null?void 0:Ze.size)||14,ne={backgroundColor:y,borderColor:v,borderRadius:`${b}px`,boxShadow:U?"0 1px 3px 0 rgba(0, 0, 0, 0.1)":"none",color:d},Q={fontSize:`${T}px`,fontWeight:R?"700":"400",color:((tt=e==null?void 0:e.colors)==null?void 0:tt.header)||d},K={fontSize:`${W}px`,color:((nt=e==null?void 0:e.colors)==null?void 0:nt.input_labels_placeholders)||"#6b7280"},de={backgroundColor:u,borderColor:t?m:f,borderRadius:`${A}px`,color:h},N={backgroundColor:c,color:l,borderRadius:`${O}px`},C=((rt=e==null?void 0:e.widget)==null?void 0:rt.logo_position)||"center",z=C==="left"?"text-left":C==="right"?"text-right":"text-center",k=((Rn=e==null?void 0:e.widget)==null?void 0:Rn.logo_url)||(n==null?void 0:n.logo_url),$=C!=="none"&&k;return p("div",{className:ge("flex flex-col gap-6 w-full max-w-sm",a),children:p(_n,{style:ne,className:"border",children:[p(yn,{children:[$&&p("div",{className:ge("mb-4",z),children:p(nn,{theme:e,branding:n})}),p(wn,{style:Q,children:w.t("create_account_title","Create Account")}),p(vn,{style:K,children:w.t("create_account_description","Sign up to get started")})]}),p(bn,{children:[p("form",{method:"post",className:"space-y-4",children:[p("input",{type:"hidden",name:"state",value:r.authParams.state}),s&&p("input",{type:"hidden",name:"code",value:s}),p("div",{className:"space-y-2",children:[p(Lt,{htmlFor:"username",style:K,children:w.t("email_label","Email")}),p(Yt,{id:"username",type:"email",name:"username",placeholder:w.t("email_placeholder","Email Address"),value:i,disabled:!!i,style:de,className:"w-full",required:!0})]}),p("div",{className:"space-y-2",children:[p(Lt,{htmlFor:"password",style:K,children:w.t("password","Password")}),p("div",{className:"relative","data-password-toggle":!0,children:[p(Yt,{id:"password",name:"password",type:"password","data-password-input":"password",placeholder:w.t("enter_new_password_placeholder","Enter new password"),required:!0,error:!!t,className:"border pr-8",style:de}),p("button",{type:"button","data-password-toggle-btn":!0,className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700 transition-colors","aria-label":w.t("toggle_password_visibility","Toggle password visibility"),children:[p("svg",{"data-show-icon":!0,xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"}),p("circle",{cx:"12",cy:"12",r:"3"})]}),p("svg",{"data-hide-icon":!0,className:"hidden",xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M9.88 9.88a3 3 0 1 0 4.24 4.24"}),p("path",{d:"M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"}),p("path",{d:"M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"}),p("line",{x1:"2",x2:"22",y1:"2",y2:"22"})]})]})]})]}),p("div",{className:"space-y-2",children:[p(Lt,{htmlFor:"re-enter-password",style:K,children:w.t("confirm_password","Confirm Password")}),p("div",{className:"relative","data-password-toggle":!0,children:[p(Yt,{id:"re-enter-password",name:"re-enter-password",type:"password","data-password-input":"re-enter-password",placeholder:w.t("reenter_new_password_placeholder","Re-enter new password"),required:!0,error:!!t,className:"border pr-8",style:de}),p("button",{type:"button","data-password-toggle-btn":!0,className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700 transition-colors","aria-label":w.t("toggle_password_visibility","Toggle password visibility"),children:[p("svg",{"data-show-icon":!0,xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"}),p("circle",{cx:"12",cy:"12",r:"3"})]}),p("svg",{"data-hide-icon":!0,className:"hidden",xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M9.88 9.88a3 3 0 1 0 4.24 4.24"}),p("path",{d:"M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"}),p("path",{d:"M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"}),p("line",{x1:"2",x2:"22",y1:"2",y2:"22"})]})]})]})]}),t&&p(et,{children:t}),p(fn,{type:"submit",className:"w-full",style:N,disabled:!1,children:w.t("continue","Continue")})]}),p("div",{className:"mt-4 text-center",children:p("a",{href:`/u/login/identifier?state=${encodeURIComponent(r.authParams.state||"")}`,className:"text-sm",style:{color:c},children:w.t("back_to_login","Back to Login")})})]})]})})},w8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"}),code:o.z.string().optional().openapi({description:"The code parameter from an email verification link"})})},responses:{200:{description:"Response"}}}),async t=>{const{state:e,code:n}=t.req.valid("query"),{theme:r,branding:i,client:s,loginSession:a,useShadcn:c}=await Ce(t,e),{username:l}=a.authParams;if(!l)throw new S(400,{message:"Username required"});return c?t.html(p(Oe,{title:w.t("sign_up","Sign Up"),theme:r,branding:i,client:s,children:p(Di,{theme:r,branding:i,loginSession:a,email:l,code:n,client:s})})):n?t.html(p(ir,{state:e,theme:r,branding:i,client:s,email:l,code:n})):t.html(p(ir,{state:e,theme:r,branding:i,client:s,email:l}))}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})}),body:{content:{"application/x-www-form-urlencoded":{schema:o.z.object({password:o.z.string(),"re-enter-password":o.z.string(),code:o.z.string().optional()})}}}},responses:{200:{description:"HTML page indicating success (e.g., email verification sent) or a next step.",content:{"text/html":{schema:o.z.string()}}},302:{description:"Redirect to continue the authentication flow (e.g., to client, MFA, consent) after successful login.",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML page with an error message (e.g., passwords don't match, weak password, user exists).",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML page with an error message.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{var d,u,f;const{state:e}=t.req.valid("query"),n=t.req.valid("form"),{env:r}=t,{theme:i,branding:s,client:a,loginSession:c,useShadcn:l}=await Ce(t,e);try{if(!c.authParams.username)throw new S(400,{message:"Username required"});const h="Username-Password-Authentication";if(t.set("connection",h),n.password!==n["re-enter-password"])return l?t.html(p(Oe,{title:w.t("sign_up","Sign Up"),theme:i,branding:s,client:a,children:p(Di,{theme:i,branding:s,loginSession:c,email:c.authParams.username,code:n.code,error:w.t("create_account_passwords_didnt_match"),client:a})}),400):t.html(p(ir,{state:e,code:n.code,theme:i,branding:s,client:a,error:w.t("create_account_passwords_didnt_match"),email:c.authParams.username}),400);if(!Rp(n.password))return l?t.html(p(Oe,{title:w.t("sign_up","Sign Up"),theme:i,branding:s,client:a,children:p(Di,{theme:i,branding:s,loginSession:c,email:c.authParams.username,code:n.code,error:w.t("create_account_weak_password"),client:a})}),400):t.html(p(ir,{state:e,code:n.code,theme:i,branding:s,client:a,error:w.t("create_account_weak_password"),email:c.authParams.username}),400);const m=n.code?await r.data.codes.get(a.tenant.id,n.code,"email_verification"):void 0,y=m?await r.data.loginSessions.get(a.tenant.id,m.login_id):void 0;if(await vi({userAdapter:t.env.data.users,tenant_id:a.tenant.id,username:c.authParams.username,provider:"auth2"}))return l?t.html(p(Oe,{title:w.t("sign_up","Sign Up"),theme:i,branding:s,client:a,children:p(Di,{theme:i,branding:s,loginSession:c,email:c.authParams.username,code:n.code,error:w.t("user_exists_error"),client:a})}),400):t.html(p(ir,{state:e,code:n.code,theme:i,branding:s,client:a,error:w.t("user_exists_error"),email:c.authParams.username}),400);const b=(y==null?void 0:y.authParams.username)===c.authParams.username,A=`auth2|${La()}`,O=await r.data.users.create(a.tenant.id,{user_id:A,email:c.authParams.username,email_verified:b,provider:"auth2",connection:h,is_social:!1});if(await r.data.passwords.create(a.tenant.id,{user_id:A,password:await ti.hash(n.password,10),algorithm:"bcrypt"}),!b){const T=(f=(u=(d=c.authParams)==null?void 0:d.ui_locales)==null?void 0:u.split(" "))==null?void 0:f.map(R=>R.split("-")[0])[0];return await Up(t,O,T),t.html(p(Dt,{message:w.t("validate_email_body"),pageTitle:w.t("validate_email_title"),theme:i,branding:s,client:a,state:e}))}const U=await z1(t,a,{...c.authParams,password:n.password},c);return un(t,U)}catch(h){let m=w.t("unknown_error_message"),y=400;return h instanceof S?(m=h.message||m,y=h.status===400?400:500):h instanceof qr?m=h.message||m:h instanceof Error&&(m=h.message||m,y=500),l?t.html(p(Oe,{title:w.t("sign_up","Sign Up"),theme:i,branding:s,client:a,children:p(Di,{theme:i,branding:s,loginSession:c,email:c.authParams.username,code:n.code,error:m,client:a})}),y):t.html(p(ir,{state:e,theme:i,branding:s,client:a,error:m,email:c.authParams.username,code:n.code}),y)}}),Hr=t=>{const{error:e,theme:n,branding:r,client:i,email:s}=t;return p(De,{title:w.t("reset_password_title"),theme:n,branding:r,client:i,children:[p("div",{className:"mb-4 text-lg font-medium sm:text-2xl",children:w.t("reset_password_title")}),p("div",{className:"mb-6 text-gray-300",children:`${w.t("reset_password_description")} ${s}`}),p("div",{className:"flex flex-1 flex-col justify-center",children:p(rn,{children:[p(uu,{name:"password",placeholder:w.t("enter_new_password_placeholder")}),p(uu,{name:"re-enter-password",placeholder:w.t("reenter_new_password_placeholder")}),e&&p(et,{children:e}),p(Ue,{className:"sm:mt-4 !text-base",children:w.t("reset_password_cta")})]})})]})},Mi=({error:t,theme:e,branding:n,loginSession:r,email:i,className:s})=>{var $,I,L,q,F,Z,se,D,fe,$e,ce,ue,Ae,Ee,Re,Se,Te,Be,Ge,dt,Ze,tt,nt,rt;const a=(($=e==null?void 0:e.colors)==null?void 0:$.primary_button)||((I=n==null?void 0:n.colors)==null?void 0:I.primary)||"#0066cc",c=((L=e==null?void 0:e.colors)==null?void 0:L.primary_button_label)||"#ffffff",l=((q=e==null?void 0:e.colors)==null?void 0:q.body_text)||"#333333",d=((F=e==null?void 0:e.colors)==null?void 0:F.input_background)||"#ffffff",u=((Z=e==null?void 0:e.colors)==null?void 0:Z.input_border)||"#d1d5db",f=((se=e==null?void 0:e.colors)==null?void 0:se.input_filled_text)||"#111827",h=((D=e==null?void 0:e.colors)==null?void 0:D.error)||"#dc2626",m=((fe=e==null?void 0:e.colors)==null?void 0:fe.widget_background)||"#ffffff",y=(($e=e==null?void 0:e.colors)==null?void 0:$e.widget_border)||"#e5e7eb",v=((ce=e==null?void 0:e.borders)==null?void 0:ce.widget_corner_radius)||8,b=((ue=e==null?void 0:e.borders)==null?void 0:ue.input_border_radius)||4,A=((Ae=e==null?void 0:e.borders)==null?void 0:Ae.button_border_radius)||4,O=((Ee=e==null?void 0:e.borders)==null?void 0:Ee.show_widget_shadow)??!0,U=((Se=(Re=e==null?void 0:e.fonts)==null?void 0:Re.title)==null?void 0:Se.size)||24,T=((Be=(Te=e==null?void 0:e.fonts)==null?void 0:Te.title)==null?void 0:Be.bold)??!0,R=((dt=(Ge=e==null?void 0:e.fonts)==null?void 0:Ge.body_text)==null?void 0:dt.size)||14,W={backgroundColor:m,borderColor:y,borderRadius:`${v}px`,boxShadow:O?"0 1px 3px 0 rgba(0, 0, 0, 0.1)":"none",color:l},ne={fontSize:`${U}px`,fontWeight:T?"700":"400",color:((Ze=e==null?void 0:e.colors)==null?void 0:Ze.header)||l},Q={fontSize:`${R}px`,color:((tt=e==null?void 0:e.colors)==null?void 0:tt.input_labels_placeholders)||"#6b7280"},K={backgroundColor:d,borderColor:t?h:u,borderRadius:`${b}px`,color:f},de={backgroundColor:a,color:c,borderRadius:`${A}px`},N=((nt=e==null?void 0:e.widget)==null?void 0:nt.logo_position)||"center",C=N==="left"?"text-left":N==="right"?"text-right":"text-center",z=((rt=e==null?void 0:e.widget)==null?void 0:rt.logo_url)||(n==null?void 0:n.logo_url),k=N!=="none"&&z;return p("div",{className:ge("flex flex-col gap-6 w-full max-w-sm",s),children:p(_n,{style:W,className:"border",children:[p(yn,{children:[k&&p("div",{className:ge("mb-4",C),children:p(nn,{theme:e,branding:n})}),p(wn,{style:ne,children:w.t("reset_password_title","Reset Password")}),p(vn,{style:Q,children:`${w.t("reset_password_description","Set a new password for")} ${i}`})]}),p(bn,{children:p("form",{method:"post",className:"space-y-4",children:[p("input",{type:"hidden",name:"state",value:r.authParams.state}),p("div",{className:"space-y-2",children:[p(Lt,{htmlFor:"password",style:Q,children:w.t("new_password","New Password")}),p("div",{className:"relative","data-password-toggle":!0,children:[p(Yt,{id:"password",name:"password",type:"password","data-password-input":"password",placeholder:w.t("enter_new_password_placeholder","Enter new password"),required:!0,error:!!t,className:"border pr-8",style:K}),p("button",{type:"button","data-password-toggle-btn":!0,className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700 transition-colors","aria-label":w.t("toggle_password_visibility","Toggle password visibility"),children:[p("svg",{"data-show-icon":!0,xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"}),p("circle",{cx:"12",cy:"12",r:"3"})]}),p("svg",{"data-hide-icon":!0,className:"hidden",xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M9.88 9.88a3 3 0 1 0 4.24 4.24"}),p("path",{d:"M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"}),p("path",{d:"M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"}),p("line",{x1:"2",x2:"22",y1:"2",y2:"22"})]})]})]})]}),p("div",{className:"space-y-2",children:[p(Lt,{htmlFor:"re-enter-password",style:Q,children:w.t("confirm_password","Confirm Password")}),p("div",{className:"relative","data-password-toggle":!0,children:[p(Yt,{id:"re-enter-password",name:"re-enter-password",type:"password","data-password-input":"re-enter-password",placeholder:w.t("reenter_new_password_placeholder","Re-enter new password"),required:!0,error:!!t,className:"border pr-8",style:K}),p("button",{type:"button","data-password-toggle-btn":!0,className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700 transition-colors","aria-label":w.t("toggle_password_visibility","Toggle password visibility"),children:[p("svg",{"data-show-icon":!0,xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"}),p("circle",{cx:"12",cy:"12",r:"3"})]}),p("svg",{"data-hide-icon":!0,className:"hidden",xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M9.88 9.88a3 3 0 1 0 4.24 4.24"}),p("path",{d:"M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"}),p("path",{d:"M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"}),p("line",{x1:"2",x2:"22",y1:"2",y2:"22"})]})]})]})]}),t&&p(et,{children:t}),p(fn,{type:"submit",className:"w-full",style:de,disabled:!1,children:w.t("reset_password_cta","Reset Password")})]})})]})})},v8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"}),code:o.z.string().openapi({description:"The code parameter from the authorization request"})})},responses:{200:{description:"Response"}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,client:i,loginSession:s,useShadcn:a}=await Ce(t,e);if(!s.authParams.username)throw new S(400,{message:"Username required"});return a?t.html(p(Oe,{title:w.t("reset_password_title","Reset Password"),theme:n,branding:r,client:i,children:p(Mi,{theme:n,branding:r,loginSession:s,email:s.authParams.username,client:i})})):t.html(p(Hr,{theme:n,branding:r,client:i,email:s.authParams.username}))}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"}),code:o.z.string().openapi({description:"The code parameter from the authorization request"})}),body:{content:{"application/x-www-form-urlencoded":{schema:o.z.object({password:o.z.string(),"re-enter-password":o.z.string()})}}}},responses:{200:{description:"Response"}}}),async t=>{const{state:e,code:n}=t.req.valid("query"),{password:r,"re-enter-password":i}=t.req.valid("form"),{env:s}=t,{theme:a,branding:c,client:l,loginSession:d,useShadcn:u}=await Ce(t,e);if(!d.authParams.username)throw new S(400,{message:"Username required"});if(r!==i)return u?t.html(p(Oe,{title:w.t("reset_password_title","Reset Password"),theme:a,branding:c,client:l,children:p(Mi,{error:w.t("create_account_passwords_didnt_match"),theme:a,branding:c,loginSession:d,email:d.authParams.username,client:l})}),400):t.html(p(Hr,{error:w.t("create_account_passwords_didnt_match"),theme:a,branding:c,client:l,email:d.authParams.username}),400);if(!Rp(r))return u?t.html(p(Oe,{title:w.t("reset_password_title","Reset Password"),theme:a,branding:c,client:l,children:p(Mi,{error:w.t("create_account_weak_password"),theme:a,branding:c,loginSession:d,email:d.authParams.username,client:l})}),400):t.html(p(Hr,{error:w.t("create_account_weak_password"),theme:a,branding:c,client:l,email:d.authParams.username}),400);const f=await vi({userAdapter:s.data.users,tenant_id:l.tenant.id,username:d.authParams.username,provider:"auth2"});if(!f)throw new S(400,{message:"User not found"});try{if(!await s.data.codes.get(l.tenant.id,n,"password_reset"))return u?t.html(p(Oe,{title:w.t("reset_password_title","Reset Password"),theme:a,branding:c,client:l,children:p(Mi,{error:"Code not found or expired",theme:a,branding:c,loginSession:d,email:d.authParams.username,client:l})}),400):t.html(p(Hr,{error:"Code not found or expired",theme:a,branding:c,client:l,email:d.authParams.username}),400);const m={user_id:f.user_id,password:await ti.hash(r,10),algorithm:"bcrypt"};await s.data.passwords.get(l.tenant.id,f.user_id)?await s.data.passwords.update(l.tenant.id,m):await s.data.passwords.create(l.tenant.id,m),f.email_verified||await s.data.users.update(l.tenant.id,f.user_id,{email_verified:!0})}catch{return u?t.html(p(Oe,{title:w.t("reset_password_title","Reset Password"),theme:a,branding:c,client:l,children:p(Mi,{error:"The password could not be reset",theme:a,branding:c,loginSession:d,email:d.authParams.username,client:l})}),400):t.html(p(Hr,{error:"The password could not be reset",theme:a,branding:c,client:l,email:d.authParams.username}),400)}return t.html(p(Dt,{message:w.t("password_has_been_reset"),theme:a,branding:c,client:l,state:e}))}),q1=t=>{const{error:e,theme:n,branding:r,client:i,email:s,state:a}=t;return p(De,{title:w.t("forgot_password_title"),theme:n,branding:r,client:i,children:[p("div",{className:"mb-4 text-lg font-medium sm:text-2xl",children:w.t("forgot_password_title")}),p("div",{className:"mb-6 text-gray-300",children:w.t("forgot_password_description")}),p("div",{className:"flex flex-1 flex-col justify-center",children:[p(rn,{className:"pt-2",children:[p("input",{type:"email",name:"username",placeholder:w.t("email_placeholder"),className:"mb-2 w-full rounded-lg bg-gray-100 px-4 py-5 text-base placeholder:text-gray-300 dark:bg-gray-600 md:text-base",value:s,disabled:!!s}),e&&p(et,{children:e}),p(Ue,{className:"sm:mt-4 !text-base",children:w.t("forgot_password_cta")})]}),p(Nt,{state:a})]})]})},b8=({error:t,theme:e,branding:n,loginSession:r,email:i,className:s})=>{var $,I,L,q,F,Z,se,D,fe,$e,ce,ue,Ae,Ee,Re,Se,Te,Be,Ge,dt,Ze,tt,nt,rt;const a=(($=e==null?void 0:e.colors)==null?void 0:$.primary_button)||((I=n==null?void 0:n.colors)==null?void 0:I.primary)||"#0066cc",c=((L=e==null?void 0:e.colors)==null?void 0:L.primary_button_label)||"#ffffff",l=((q=e==null?void 0:e.colors)==null?void 0:q.body_text)||"#333333",d=((F=e==null?void 0:e.colors)==null?void 0:F.input_background)||"#ffffff",u=((Z=e==null?void 0:e.colors)==null?void 0:Z.input_border)||"#d1d5db",f=((se=e==null?void 0:e.colors)==null?void 0:se.input_filled_text)||"#111827",h=((D=e==null?void 0:e.colors)==null?void 0:D.error)||"#dc2626",m=((fe=e==null?void 0:e.colors)==null?void 0:fe.widget_background)||"#ffffff",y=(($e=e==null?void 0:e.colors)==null?void 0:$e.widget_border)||"#e5e7eb",v=((ce=e==null?void 0:e.borders)==null?void 0:ce.widget_corner_radius)||8,b=((ue=e==null?void 0:e.borders)==null?void 0:ue.input_border_radius)||4,A=((Ae=e==null?void 0:e.borders)==null?void 0:Ae.button_border_radius)||4,O=((Ee=e==null?void 0:e.borders)==null?void 0:Ee.show_widget_shadow)??!0,U=((Se=(Re=e==null?void 0:e.fonts)==null?void 0:Re.title)==null?void 0:Se.size)||24,T=((Be=(Te=e==null?void 0:e.fonts)==null?void 0:Te.title)==null?void 0:Be.bold)??!0,R=((dt=(Ge=e==null?void 0:e.fonts)==null?void 0:Ge.body_text)==null?void 0:dt.size)||14,W={backgroundColor:m,borderColor:y,borderRadius:`${v}px`,boxShadow:O?"0 1px 3px 0 rgba(0, 0, 0, 0.1)":"none",color:l},ne={fontSize:`${U}px`,fontWeight:T?"700":"400",color:((Ze=e==null?void 0:e.colors)==null?void 0:Ze.header)||l},Q={fontSize:`${R}px`,color:((tt=e==null?void 0:e.colors)==null?void 0:tt.input_labels_placeholders)||"#6b7280"},K={backgroundColor:d,borderColor:t?h:u,borderRadius:`${b}px`,color:f},de={backgroundColor:a,color:c,borderRadius:`${A}px`},N=((nt=e==null?void 0:e.widget)==null?void 0:nt.logo_position)||"center",C=N==="left"?"text-left":N==="right"?"text-right":"text-center",z=((rt=e==null?void 0:e.widget)==null?void 0:rt.logo_url)||(n==null?void 0:n.logo_url),k=N!=="none"&&z;return p("div",{className:ge("flex flex-col gap-6 w-full max-w-sm",s),children:p(_n,{style:W,className:"border",children:[p(yn,{children:[k&&p("div",{className:ge("mb-4",C),children:p(nn,{theme:e,branding:n})}),p(wn,{style:ne,children:w.t("forgot_password_title","Forgot Password")}),p(vn,{style:Q,children:w.t("forgot_password_description","Enter your email address and we'll send you a link to reset your password.")})]}),p(bn,{children:[p("form",{method:"post",className:"space-y-4",children:[p("input",{type:"hidden",name:"state",value:r.authParams.state}),p("div",{className:"space-y-2",children:[p(Lt,{htmlFor:"username",style:Q,className:"text-sm font-medium",children:w.t("email_label","Email")}),p(Yt,{id:"username",type:"email",name:"username",placeholder:w.t("email_placeholder","Email Address"),value:i,disabled:!!i,style:K,className:"w-full",required:!0})]}),t&&p(et,{children:t}),p(fn,{type:"submit",className:"w-full",style:de,disabled:!1,children:w.t("forgot_password_cta","Send Reset Link")})]}),p("div",{className:"mt-4 text-center",children:p("a",{href:`/u/login/identifier?state=${encodeURIComponent(r.authParams.state||"")}`,className:"text-sm",style:{color:a},children:w.t("back_to_login","Back to Login")})})]})]})})},H1=t=>{const{theme:e,branding:n,client:r,state:i}=t;return p(De,{title:"Login",theme:e,branding:n,client:r,children:[p("div",{className:"flex flex-1 flex-col justify-center",children:[p("div",{children:w.t("forgot_password_email_sent")}),p("div",{className:"my-4 flex space-x-2 text-sm text-[#B2B2B2]",children:[p(Ke,{className:"text-base",name:"info-bubble"}),p("div",{className:"text-sm text-gray-300 md:text-sm",children:w.t("sent_code_spam")})]})]}),p(Nt,{state:i})]})},$8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{200:{description:"Response"}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,client:i,loginSession:s,useShadcn:a}=await Ce(t,e);return a?t.html(p(Oe,{title:w.t("forgot_password_title","Forgot Password"),theme:n,branding:r,client:i,children:p(b8,{theme:n,branding:r,loginSession:s,email:s.authParams.username,client:i})})):t.html(p(q1,{theme:n,branding:r,client:i,state:e,email:s.authParams.username}))}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{200:{description:"Response"}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,client:i,loginSession:s}=await Ce(t,e);return await kx(t,i,s.authParams.username,s.id),t.html(p(H1,{theme:n,branding:r,client:i,state:e}))}),V1=({theme:t,branding:e,client:n,state:r,user:i})=>p(De,{title:pe("check_email_title"),theme:t,branding:e,client:n,children:p("div",{className:"flex flex-1 flex-col justify-center",children:[p("div",{className:"mb-8 text-gray-700 dark:text-gray-300",children:[p(Yn,{i18nKey:"currently_logged_in_as",components:[p("span",{className:"font-semibold text-gray-900 dark:text-white"},"span")],values:{email:i.email||""}}),p("br",{}),pe("continue_with_sso_provider_headline")]}),p("div",{className:"space-y-6",children:[p(rn,{children:p(Ue,{className:"!text-base",children:p("span",{children:w.t("yes_continue_with_existing_account")})})}),p("a",{className:"block text-center text-primary hover:text-primaryHover focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 dark:focus:ring-offset-gray-900",href:`/u/login/identifier?state=${encodeURIComponent(r)}`,children:w.t("no_use_another")})]})]})}),k8=({theme:t,branding:e,state:n,user:r,className:i})=>{var K,de,N,C,z,k,$,I,L,q,F,Z,se,D,fe,$e,ce,ue,Ae,Ee;const s=((K=t==null?void 0:t.colors)==null?void 0:K.primary_button)||((de=e==null?void 0:e.colors)==null?void 0:de.primary)||"#0066cc",a=((N=t==null?void 0:t.colors)==null?void 0:N.primary_button_label)||"#ffffff",c=((C=t==null?void 0:t.colors)==null?void 0:C.body_text)||"#333333",l=((z=t==null?void 0:t.colors)==null?void 0:z.widget_background)||"#ffffff",d=((k=t==null?void 0:t.colors)==null?void 0:k.widget_border)||"#e5e7eb",u=(($=t==null?void 0:t.borders)==null?void 0:$.widget_corner_radius)||8,f=((I=t==null?void 0:t.borders)==null?void 0:I.button_border_radius)||4,h=((L=t==null?void 0:t.borders)==null?void 0:L.show_widget_shadow)??!0,m=((F=(q=t==null?void 0:t.fonts)==null?void 0:q.title)==null?void 0:F.size)||24,y=((se=(Z=t==null?void 0:t.fonts)==null?void 0:Z.title)==null?void 0:se.bold)??!0,v=((fe=(D=t==null?void 0:t.fonts)==null?void 0:D.body_text)==null?void 0:fe.size)||14,b={backgroundColor:l,borderColor:d,borderRadius:`${u}px`,boxShadow:h?"0 1px 3px 0 rgba(0, 0, 0, 0.1)":"none",color:c},A={fontSize:`${m}px`,fontWeight:y?"700":"400",color:(($e=t==null?void 0:t.colors)==null?void 0:$e.header)||c},O={fontSize:`${v}px`,color:((ce=t==null?void 0:t.colors)==null?void 0:ce.input_labels_placeholders)||"#6b7280"},U={backgroundColor:s,color:a,borderRadius:`${f}px`},T={color:((ue=t==null?void 0:t.colors)==null?void 0:ue.links_focused_components)||s,fontSize:`${v}px`},R=((Ae=t==null?void 0:t.widget)==null?void 0:Ae.logo_position)||"center",W=R==="left"?"text-left":R==="right"?"text-right":"text-center",ne=((Ee=t==null?void 0:t.widget)==null?void 0:Ee.logo_url)||(e==null?void 0:e.logo_url),Q=R!=="none"&&ne;return p("div",{className:ge("flex flex-col gap-6 w-full max-w-sm",i),children:p(_n,{style:b,className:"border",children:[p(yn,{children:[Q&&p("div",{className:ge("mb-4",W),children:p(nn,{theme:t,branding:e})}),p(wn,{style:A,children:w.t("continue_with_account","Continue with account")}),p(vn,{style:O,children:[p(Yn,{i18nKey:"currently_logged_in_as",components:[p("span",{className:"font-semibold"},"span")],values:{email:r.email||""}}),p("br",{}),p("br",{}),w.t("continue_with_sso_provider_headline","Do you want to continue with this account?")]})]}),p(bn,{children:p("form",{method:"post",children:p("div",{className:"grid gap-4",children:[p(fn,{type:"submit",className:"w-full transition-colors hover:brightness-90",style:U,children:w.t("yes_continue_with_existing_account","Yes, continue")}),p("div",{className:"text-center",children:p("a",{href:`/u/login/identifier?state=${encodeURIComponent(n)}`,className:"text-sm hover:underline focus:outline-none focus:ring-2 focus:ring-offset-2 transition-colors",style:T,children:w.t("no_use_another","No, use another account")})})]})})})]})})},x8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{200:{description:"HTML page to check account status or verify email.",content:{"text/html":{schema:o.z.string()}}},302:{description:"Redirect to login identifier page if no valid session.",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML error page if state is missing or other input error.",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{var u;const{env:e}=t,{state:n}=t.req.valid("query"),{theme:r,branding:i,client:s,useShadcn:a}=await Ce(t,n);if(!s||!((u=s.tenant)!=null&&u.id))return console.error("Client or tenant ID missing in GET /u/check-account after initJSXRoute"),t.html(p(Dt,{theme:r,branding:i,client:s,state:n,pageTitle:w.t("error_page_title")||"Error",message:w.t("configuration_error_message")||"A configuration error occurred."}),500);const c=ni(s.tenant.id,t.req.header("cookie")),l=c?await e.data.sessions.get(s.tenant.id,c):null;if(!l)return t.redirect(`/u/login/identifier?state=${n}`);const d=await e.data.users.get(s.tenant.id,l.user_id);return d?a?t.html(p(Oe,{title:w.t("continue_with_account","Continue with account"),theme:r,branding:i,client:s,children:p(k8,{theme:r,branding:i,client:s,state:n,user:d})})):t.html(p(V1,{theme:r,branding:i,client:s,state:n,user:d})):t.redirect(`/u/login/identifier?state=${n}`)}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{302:{description:"Redirect to continue authentication flow or to login identifier.",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML error page if state is missing or other input error.",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page for unexpected issues or if TokenResponse is returned.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{var f;const{env:e}=t,{state:n}=t.req.valid("query"),{theme:r,branding:i,client:s,loginSession:a}=await Ce(t,n);if(!s||!((f=s.tenant)!=null&&f.id))return console.error("Client or tenant ID missing in POST /u/check-account after initJSXRoute"),t.html(p(Dt,{theme:r,branding:i,client:s,state:n,pageTitle:w.t("error_page_title")||"Error",message:w.t("configuration_error_message")}),500);const c=ni(s.tenant.id,t.req.header("cookie")),l=c?await e.data.sessions.get(s.tenant.id,c):null;if(!l)return t.redirect(`/u/login/identifier?state=${n}`);const d=await e.data.users.get(s.tenant.id,l.user_id);if(!d)return t.redirect(`/u/login/identifier?state=${n}`);await e.data.loginSessions.update(s.tenant.id,a.id,{session_id:l.id});const u=await un(t,{user:d,authParams:a.authParams,client:s,loginSession:{...a,session_id:l.id},sessionId:l.id});if(!(u instanceof Response))throw new S(500,{message:w.t("unexpected_error_try_again")});return u}),S8=({width:t=18,height:e=18,className:n})=>p("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:e,viewBox:"0 0 640 640",className:n,fill:"currentColor",role:"img",focusable:"false",children:p("path",{d:"M416.9 85.2 372 130.1 509.9 268l44.9-44.9c13.6-13.5 21.2-31.9 21.2-51.1s-7.6-37.6-21.2-51.1l-35.7-35.7C505.6 71.6 487.2 64 468 64s-37.6 7.6-51.1 21.2M338.1 164 122.9 379.1c-10.7 10.7-18.5 24.1-22.6 38.7L64.9 545.6c-2.3 8.3 0 17.3 6.2 23.4s15.1 8.5 23.4 6.2l127.8-35.5c14.6-4.1 27.9-11.8 38.7-22.6l215-215.2z"})}),z8=!1,n0=t=>{var d;const{theme:e,branding:n,user:r,client:i,error:s,success:a,state:c,csrfToken:l}=t;return(d=r.identities)!=null&&d.filter(u=>!(u.provider===r.provider&&u.user_id===r.user_id.split("|")[1])),p(De,{title:w.t("account_title")||"Account Settings",theme:e,branding:n,client:i,children:[p("div",{className:"mb-4 text-2xl font-medium",children:w.t("account_title")}),p("div",{className:"mb-8 text-gray-300",children:w.t("account_page_description")}),s&&p(et,{className:"mb-8",children:s}),a&&p("div",{className:"mb-8 text-green",children:a}),p("div",{className:"column-left gap-6 border-y border-gray-200/50 py-6 mb-8",children:[p("div",{className:"row-left w-full !justify-between !flex-nowrap gap-4",children:[p("div",{className:"column-left gap-1.5",children:[p("div",{className:"text-gray-300",children:w.t("email_placeholder")}),p("div",{className:"font-medium text-base text-gray-800 line-clamp-1 break-all",children:r.email||w.t("no_email_address")})]}),p("a",{className:"bg-gray-200/40 p-2 rounded-md hover:bg-gray-200/75",title:w.t("edit"),"aria-label":w.t("edit"),href:c?`/u/account/change-email?state=${encodeURIComponent(c)}`:`/u/account/change-email?client_id=${encodeURIComponent(i.client_id)}`,children:p(S8,{})})]}),z8]})]})},A8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{200:{description:"HTML page showing account management interface.",content:{"text/html":{schema:o.z.string()}}},302:{description:"Redirect to login if no session",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML error page if state is missing or other input error.",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{var d;const{env:e}=t,{state:n}=t.req.valid("query"),{theme:r,branding:i,client:s,user:a,loginSession:c}=await jr(t,n);if(!s||!((d=s.tenant)!=null&&d.id))return console.error("Client or tenant ID missing in GET /u/account after initJSXRoute"),t.html(p(Dt,{theme:r,branding:i,client:s,state:n,pageTitle:w.t("error_page_title")||"Error",message:w.t("configuration_error_message")||"A configuration error occurred."}),500);const l=Ne();return await e.data.loginSessions.update(s.tenant.id,c.id,{csrf_token:l}),t.html(p(n0,{theme:r,branding:i,user:a,client:s,state:n,csrfToken:l}))}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})}),body:{content:{"application/x-www-form-urlencoded":{schema:o.z.object({action:o.z.enum(["unlink_account"]),provider:o.z.string().optional(),user_id:o.z.string().optional(),csrf_token:o.z.string().optional()})}}}},responses:{200:{description:"HTML response with form results",content:{"text/html":{schema:o.z.string()}}},302:{description:"Redirect to login if no session",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML error page if state is missing or other input error.",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{const{env:e}=t,{state:n}=t.req.valid("query"),r=t.req.valid("form"),{theme:i,branding:s,client:a,user:c,loginSession:l}=await jr(t,n);let d,u;try{if(r.action==="unlink_account"&&r.provider&&r.user_id){if(!r.csrf_token||r.csrf_token!==l.csrf_token)throw new Error("Invalid CSRF token");await e.data.users.unlink(a.tenant.id,c.user_id,r.provider,r.user_id),u=w.t("account_unlinked_successfully")||"Account unlinked successfully"}}catch{d=w.t("operation_failed")||"Operation failed"}const f=await e.data.users.get(a.tenant.id,c.user_id),h=Ne();return await e.data.loginSessions.update(a.tenant.id,l.id,{csrf_token:h}),t.html(p(n0,{theme:i,branding:s,user:f||c,client:a,error:d,success:u,state:n,csrfToken:h}))}),r0=t=>{const{theme:e,branding:n,user:r,client:i,state:s,error:a}=t;return p(De,{title:w.t("change_email"),theme:e,branding:n,client:i,children:[p("div",{className:"mb-4 text-2xl font-medium",children:w.t("change_email")}),p("div",{className:"column-left gap-1 mb-8",children:[p("div",{className:"text-gray-300",children:w.t("current_email")}),p("div",{className:"font-medium text-base text-gray-800",children:r.email||w.t("no_email_address")})]}),p("div",{className:"flex flex-1 flex-col justify-center",children:[p(rn,{children:[p("input",{type:"email",id:"email",name:"email",placeholder:w.t("new_email"),className:ge("mb-2 w-full rounded-lg border bg-gray-100 px-4 py-5 text-base placeholder:text-gray-300 dark:bg-gray-600 md:text-base",{"border-red":a,"border-gray-100 dark:border-gray-500":!a}),required:!0}),a&&p(et,{children:a}),p(Ue,{className:"sm:mt-4 !text-base",children:[p("span",{children:w.t("continue")}),p(Ke,{className:"text-xs",name:"arrow-right"})]}),p("div",{className:"my-4 flex space-x-2 text-sm text-[#B2B2B2]",children:[p("span",{className:"uicon-info-bubble text-base"}),p("div",{className:"text-sm text-gray-300 md:text-sm",children:w.t("new_email_code_info")})]})]}),p("a",{className:"block text-primary hover:text-primaryHover text-center",href:`/u/account?state=${encodeURIComponent(s)}`,children:w.t("go_back")})]})]})},E8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{200:{description:"HTML page showing email change interface.",content:{"text/html":{schema:o.z.string()}}},302:{description:"Redirect to login if no session",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML error page if state is missing or other input error.",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,client:i,user:s}=await jr(t,e);return t.html(p(r0,{theme:n,branding:r,user:s,client:i,state:e}))}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})}),body:{content:{"application/x-www-form-urlencoded":{schema:o.z.object({email:o.z.string().toLowerCase()})}}}},responses:{200:{description:"HTML response with form results",content:{"text/html":{schema:o.z.string()}}},302:{description:"Redirect to change-email verification page",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML error page if state is missing or other input error.",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{var m,y,v,b;const{env:e}=t,{state:n}=t.req.valid("query"),{email:r}=t.req.valid("form"),{theme:i,branding:s,client:a,user:c,loginSession:l}=await jr(t,n),d=await e.data.users.list(a.tenant.id,{page:1,per_page:1,include_totals:!1,q:`email:"${r}"`});if(d.users.length>0&&((m=d.users[0])==null?void 0:m.user_id)!==c.user_id)return t.html(p(r0,{theme:i,branding:s,user:c,client:a,state:n,error:w.t("email_already_taken")||"Email is already taken"}));const u=Zn(),f=Ne();await e.data.codes.create(a.tenant.id,{code_id:f,login_id:"",code_type:"email_verification",expires_at:new Date(Date.now()+Cl).toISOString(),user_id:c.user_id}),await e.data.codes.create(a.tenant.id,{code_id:u,login_id:"",code_type:"email_verification",expires_at:new Date(Date.now()+Cl).toISOString(),user_id:c.user_id});const h=(b=(v=(y=l.authParams)==null?void 0:y.ui_locales)==null?void 0:v.split(" "))==null?void 0:b.map(A=>A.split("-")[0])[0];return await Bp(t,{to:r,code:u,language:h}),t.redirect(`/u/account/change-email-verify?state=${encodeURIComponent(n)}&email=${encodeURIComponent(r)}&change_id=${f}`)}),i0=6,pu=({error:t,theme:e,branding:n,client:r,email:i,success:s,state:a,redirectUrl:c})=>s?p(De,{title:w.t("success"),theme:e,branding:n,client:r,children:[p("div",{className:"mb-4 text-2xl font-medium",children:w.t("success")}),p("div",{className:"mb-8 text-gray-300",children:p(Yn,{i18nKey:"email_changed_to_template",components:[p("span",{className:"text-black dark:text-white"},"span")],values:{email:i}})}),p("div",{className:"flex flex-1 flex-col justify-center",children:p(Ue,{Component:"a",href:c||(a?`/u/account?state=${encodeURIComponent(a)}`:`/u/account?client_id=${encodeURIComponent(r.client_id)}`),className:"sm:mt-4 !text-base",children:[p("span",{children:w.t("continue")}),p(Ke,{className:"text-xs",name:"arrow-right"})]})})]}):p(De,{title:w.t("verify_email_verify"),theme:e,branding:n,client:r,children:[p("div",{className:"mb-4 text-2xl font-medium",children:w.t("verify_email_verify")}),p("div",{className:"mb-8 text-gray-300",children:p(Yn,{i18nKey:"code_sent_template",components:[p("span",{className:"text-black dark:text-white"},"span")],values:{username:i}})}),p("div",{className:"flex flex-1 flex-col justify-center",children:[p(rn,{className:"pt-2",children:[p("input",{autoFocus:!0,type:"text",pattern:"[0-9]*",maxLength:i0,inputMode:"numeric",name:"code",placeholder:"******",className:ge("mb-2 w-full rounded-lg border bg-gray-100 px-4 pb-2 pt-2.5 text-center indent-[5px] font-mono text-3xl placeholder:text-gray-300 dark:bg-gray-600 md:text-3xl",{"border-red":t,"border-gray-100 dark:border-gray-500":!t}),minLength:i0,required:!0,id:"code-input"}),t&&p(et,{children:t}),p(Ue,{className:"sm:mt-4 !text-base",children:[p("span",{children:w.t("continue")}),p(Ke,{className:"text-xs",name:"arrow-right"})]}),p("div",{className:"my-4 flex space-x-2 text-sm text-[#B2B2B2]",children:[p(Ke,{className:"text-base",name:"info-bubble"}),p("div",{className:"text-sm text-gray-300 md:text-sm",children:w.t("sent_code_spam")})]})]}),p("a",{className:"block text-primary hover:text-primaryHover text-center",href:a?`/u/account?state=${encodeURIComponent(a)}`:`/u/account?client_id=${encodeURIComponent(r.client_id)}`,children:w.t("go_back")})]})]}),C8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"}),email:o.z.string().email(),change_id:o.z.string()})},responses:{200:{description:"HTML page for email change verification",content:{"text/html":{schema:o.z.string()}}},302:{description:"Redirect to account or login if no session",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML error page if state is missing or other input error.",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{const{state:e,email:n,change_id:r}=t.req.valid("query"),{theme:i,branding:s,client:a,user:c}=await jr(t,e),l=await t.env.data.codes.get(a.tenant.id,r,"email_verification");return!l||l.user_id!==c.user_id?t.redirect(`/u/account?state=${e}`):t.html(p(pu,{theme:i,branding:s,client:a,email:n,state:e}))}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"}),email:o.z.string().toLowerCase(),change_id:o.z.string()}),body:{content:{"application/x-www-form-urlencoded":{schema:o.z.object({code:o.z.string()})}}}},responses:{200:{description:"HTML response with verification result",content:{"text/html":{schema:o.z.string()}}},302:{description:"Redirect to confirmation page on success",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML error page if state is missing or other input error.",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{const{env:e}=t,{state:n,email:r,change_id:i}=t.req.valid("query"),{code:s}=t.req.valid("form"),{theme:a,branding:c,client:l,user:d}=await jr(t,n);let u;try{const f=await e.data.codes.get(l.tenant.id,i,"email_verification");if(!f)u=w.t("invalid_request");else if(f.user_id!==d.user_id)u=w.t("invalid_request");else if(f.used_at)u=w.t("code_already_used");else if(new Date(f.expires_at)<new Date)u=w.t("code_expired");else{const h=await e.data.codes.get(l.tenant.id,s,"email_verification");if(!h)u=w.t("invalid_code");else if(h.used_at)u=w.t("code_already_used");else if(new Date(h.expires_at)<new Date)u=w.t("code_expired");else if(h.user_id!==d.user_id)u=w.t("invalid_code");else return await e.data.codes.used(l.tenant.id,i),await e.data.codes.used(l.tenant.id,s),await e.data.users.update(l.tenant.id,d.user_id,{email:r,email_verified:!0}),t.redirect(`/u/account/change-email-confirmation?state=${encodeURIComponent(n)}&email=${encodeURIComponent(r)}`)}}catch{u=w.t("operation_failed")}return t.html(p(pu,{theme:a,branding:c,client:l,email:r,error:u,state:n}))}),N8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"}),email:o.z.string().email()})},responses:{200:{description:"HTML page showing email change confirmation",content:{"text/html":{schema:o.z.string()}}},302:{description:"Redirect to login if no session",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - HTML error page if state is missing or other input error.",content:{"text/html":{schema:o.z.string()}}},500:{description:"Internal Server Error - HTML error page.",content:{"text/html":{schema:o.z.string()}}}}}),async t=>{var l,d;const{state:e,email:n}=t.req.valid("query"),{theme:r,branding:i,client:s,loginSession:a}=await jr(t,e);if(!s||!((l=s.tenant)!=null&&l.id))return console.error("Client or tenant ID missing in GET /u/change-email-confirmation after initJSXRoute"),t.html(p(Dt,{theme:r,branding:i,client:s,state:e,pageTitle:w.t("error_page_title")||"Error",message:w.t("configuration_error_message")||"A configuration error occurred."}),500);let c=`/u/account?state=${encodeURIComponent(e)}`;return a!=null&&a.authorization_url&&new URL(a.authorization_url).searchParams.get("screen_hint")==="change-email"&&(c=((d=a.authParams)==null?void 0:d.redirect_uri)||c),t.html(p(pu,{theme:r,branding:i,client:s,email:n,success:!0,state:e,redirectUrl:c}))}),K1=t=>{const{theme:e,branding:n,client:r,email:i,state:s}=t;return p(De,{title:w.t("create_password_account_title"),theme:e,branding:n,client:r,children:[p("div",{className:"mb-4 text-lg font-medium sm:text-2xl",children:w.t("create_password_account_title")}),p("div",{className:"mb-6 text-gray-300",children:w.t("enter_email_for_verification_description")}),p("div",{className:"flex flex-1 flex-col justify-center",children:p(rn,{className:"pt-2",children:[p("input",{type:"email",name:"username",placeholder:w.t("email_placeholder"),className:"mb-2 w-full rounded-lg bg-gray-100 px-4 py-5 text-base placeholder:text-gray-300 dark:bg-gray-600 md:text-base",required:!0,value:i,disabled:!0}),p(Ue,{className:"sm:mt-4 !text-base",children:w.t("send")})]})}),p(Nt,{state:s})]})},I8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{200:{description:"Response"}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,client:i,loginSession:s}=await Ce(t,e),{username:a}=s.authParams;if(!a)throw new S(400,{message:"Username required"});return t.html(p(K1,{state:e,theme:n,branding:r,client:i,email:a}))}).openapi(o.createRoute({tags:["login"],method:"post",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{200:{description:"Response"}}}),async t=>{const{state:e}=t.req.valid("query"),{loginSession:n,client:r}=await Ce(t,e),{username:i}=n.authParams;if(!i)throw new S(400,{message:"Username required"});const s=await t.env.data.codes.create(r.tenant.id,{code_id:Zn(),code_type:"email_verification",login_id:n.id,expires_at:new Date(Date.now()+Cl).toISOString()});return await vx(t,i,s.code_id,n.id),t.redirect(`/u/pre-signup-sent?state=${e}`)}),G1=t=>{const{redirectUrl:e,theme:n,branding:r,client:i}=t;return p(De,{title:w.t("invalid_session_title"),theme:n,branding:r,client:i,children:[p("div",{className:"flex flex-1 flex-col justify-center",children:w.t("invalid_session_body")}),p("div",{className:"flex flex-1 flex-col justify-center",children:e&&p("a",{className:"block text-primary hover:text-primaryHover text-center",href:e,children:w.t("go_back")})})]})},j8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string()})},responses:{200:{description:"Response"}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,client:i,loginSession:s}=await Ce(t,e);let a;return s.authParams.redirect_uri&&s.authParams.state&&(a=new URL(s.authParams.redirect_uri),a.searchParams.set("state",s.authParams.state),a.searchParams.set("error","invalid_session"),a.searchParams.set("error_description",s.authParams.username||"")),t.html(p(G1,{redirectUrl:a==null?void 0:a.href,theme:n,branding:r,client:i}))}),O8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"}),code:o.z.string().openapi({description:"The code parameter from the authorization request"})})},responses:{200:{description:"Response"}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,client:i}=await Ce(t,e);return t.html(p(Dt,{message:"Not implemented",pageTitle:"User info",theme:n,branding:r,client:i,state:e}))}),W1=({theme:t,branding:e,client:n,state:r})=>{const i=new URLSearchParams({state:r});return p(De,{title:w.t("email_validated"),theme:t,branding:e,client:n,children:[p("div",{className:"mb-4 text-lg font-medium sm:text-2xl",children:w.t("email_validated")}),p("div",{className:"flex flex-1 flex-col justify-center mb-7",children:p(Ue,{Component:"a",href:`/u/enter-password?${i}`,className:"text-base sm:mt-4 md:text-base",children:p("div",{className:"flex items-center space-x-2",children:[p("span",{children:w.t("email_validated_cta")}),p(Ke,{className:"text-xs",name:"arrow-right"})]})})})]})},T8=({theme:t,branding:e,loginSession:n,className:r})=>{var Q,K,de,N,C,z,k,$,I,L,q,F,Z,se,D,fe,$e,ce,ue,Ae;const i=((Q=t==null?void 0:t.colors)==null?void 0:Q.primary_button)||((K=e==null?void 0:e.colors)==null?void 0:K.primary)||"#0066cc",s=((de=t==null?void 0:t.colors)==null?void 0:de.primary_button_label)||"#ffffff",a=((N=t==null?void 0:t.colors)==null?void 0:N.body_text)||"#333333",c=((C=t==null?void 0:t.colors)==null?void 0:C.widget_background)||"#ffffff",l=((z=t==null?void 0:t.colors)==null?void 0:z.widget_border)||"#e5e7eb",d=((k=t==null?void 0:t.colors)==null?void 0:k.success)||"#10b981",u=(($=t==null?void 0:t.borders)==null?void 0:$.widget_corner_radius)||8,f=((I=t==null?void 0:t.borders)==null?void 0:I.button_border_radius)||4,h=((L=t==null?void 0:t.borders)==null?void 0:L.show_widget_shadow)??!0,m=((F=(q=t==null?void 0:t.fonts)==null?void 0:q.title)==null?void 0:F.size)||24,y=((se=(Z=t==null?void 0:t.fonts)==null?void 0:Z.title)==null?void 0:se.bold)??!0,v=((fe=(D=t==null?void 0:t.fonts)==null?void 0:D.body_text)==null?void 0:fe.size)||14,b={backgroundColor:c,borderColor:l,borderRadius:`${u}px`,boxShadow:h?"0 1px 3px 0 rgba(0, 0, 0, 0.1)":"none",color:a},A={fontSize:`${m}px`,fontWeight:y?"700":"400",color:(($e=t==null?void 0:t.colors)==null?void 0:$e.header)||a},O={fontSize:`${v}px`,color:((ce=t==null?void 0:t.colors)==null?void 0:ce.input_labels_placeholders)||"#6b7280"},U={backgroundColor:i,color:s,borderRadius:`${f}px`},T=((ue=t==null?void 0:t.widget)==null?void 0:ue.logo_position)||"center",R=T==="left"?"text-left":T==="right"?"text-right":"text-center",W=((Ae=t==null?void 0:t.widget)==null?void 0:Ae.logo_url)||(e==null?void 0:e.logo_url),ne=T!=="none"&&W;return p("div",{className:ge("flex flex-col gap-6 w-full max-w-sm",r),children:p(_n,{style:b,className:"border",children:[p(yn,{children:[ne&&p("div",{className:ge("mb-4",R),children:p(nn,{theme:t,branding:e})}),p("div",{className:"flex justify-center mb-4",children:p("div",{className:"rounded-full p-3",style:{backgroundColor:`${d}15`},children:p("svg",{xmlns:"http://www.w3.org/2000/svg",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:d,"stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),p("polyline",{points:"22 4 12 14.01 9 11.01"})]})})}),p(wn,{style:A,className:"text-center",children:w.t("email_validated","Email Verified")}),p(vn,{style:O,className:"text-center",children:w.t("email_validated_description","Your email has been successfully verified. You can now continue to login.")})]}),p(bn,{children:p("a",{href:`/u/enter-password?state=${encodeURIComponent(n.authParams.state||"")}`,className:"w-full flex items-center justify-center gap-2 h-10 px-4 py-2 rounded-md font-medium transition-colors",style:U,children:[p("span",{children:w.t("email_validated_cta","Continue to Login")}),p("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[p("line",{x1:"5",y1:"12",x2:"19",y2:"12"}),p("polyline",{points:"12 5 19 12 12 19"})]})]})})]})})},P8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"}),code:o.z.string().openapi({description:"The code parameter from the authorization request"})})},responses:{200:{description:"Response"}}}),async t=>{var y;const{state:e,code:n}=t.req.valid("query"),{env:r}=t,{client:i,loginSession:s,theme:a,branding:c,useShadcn:l}=await Ce(t,e),{username:d}=s.authParams;if(!d)throw new S(400,{message:"Username not found in state"});const u=await vi({userAdapter:r.data.users,tenant_id:i.tenant.id,username:d,provider:"auth2"});if(!u)throw new S(500,{message:"No user found"});if(!await r.data.codes.get(i.tenant.id,n,"email_verification"))throw new S(400,{message:"Code not found or expired"});await r.data.users.update(i.tenant.id,u.user_id,{email_verified:!0});const m=(await Eu(r.data.users,i.tenant.id,d)).filter(v=>v.provider!=="auth2");if(m.length>0){const v=m.filter(b=>!b.linked_to);v.length>1&&console.error("More than one primary user found for email",d),v.length===0&&console.error("No primary user found for email",d),v.length===1&&await r.data.users.update(i.tenant.id,u.user_id,{linked_to:(y=v[0])==null?void 0:y.user_id})}return l?t.html(p(Oe,{title:w.t("email_validated","Email Verified"),theme:a,branding:c,client:i,children:p(T8,{theme:a,branding:c,loginSession:s,client:i})})):t.html(p(W1,{theme:a,branding:c,client:i,state:e}))}),J1=t=>{const{theme:e,branding:n,client:r,email:i,state:s}=t;return p(De,{title:w.t("sign_up_success"),theme:e,branding:n,client:r,children:[p("div",{className:"mb-4 text-lg font-medium sm:text-2xl",children:w.t("email_verification_for_signup_sent_title")}),p("div",{className:"flex flex-1 flex-col justify-center",children:[p("div",{className:"mb-6 text-gray-300",children:p(Yn,{i18nKey:"email_verification_for_signup_sent_description",components:[p("span",{className:"text-black dark:text-white"},"span")],values:{email:i}})}),p("div",{className:"my-4 flex space-x-2 text-sm text-[#B2B2B2]",children:[p(Ke,{className:"text-base",name:"info-bubble"}),p("div",{className:"text-sm text-gray-300 md:text-sm",children:w.t("sent_code_spam")})]})]}),p(Nt,{state:s})]})},R8=new o.OpenAPIHono().openapi(o.createRoute({tags:["login"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{200:{description:"Response"}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,client:i,loginSession:s}=await Ce(t,e),{username:a}=s.authParams;if(!a)throw new S(400,{message:"Username required"});return t.html(p(J1,{theme:n,branding:r,client:i,state:e,email:a}))}),Fp=`
234
234
  @font-face{font-display:swap;font-family:KHTeka;font-style:normal;font-weight:400;src:url(https://assets.sesamy.com/fonts/khteka/WOFF2/KHTeka-Regular.woff2) format("woff2")}@font-face{font-display:swap;font-family:KHTeka;font-style:normal;font-weight:500;src:url(https://assets.sesamy.com/fonts/khteka/WOFF2/KHTeka-Medium.woff2) format("woff2")}@font-face{font-display:swap;font-family:KHTeka;font-style:normal;font-weight:600;src:url(https://assets.sesamy.com/fonts/khteka/WOFF2/KHTeka-Bold.woff2) format("woff2")}@font-face{font-family:uicon;src:url(https://login2.sesamy.com/_next/static/media/uicon.0b00e08a.woff2)}[class*=" uicon-"],[class^=uicon-]{font-family:uicon!important;font-size:inherit;font-style:normal;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased}.uicon-apple:before{content:"\\ea01"}.uicon-arrow-down:before{content:"\\ea02"}.uicon-arrow-left:before{content:"\\ea03"}.uicon-arrow-right:before{content:"\\ea04"}.uicon-arrow-up:before{content:"\\ea05"}.uicon-facebook:before{content:"\\ea06"}.uicon-google:before{content:"\\ea07"}.uicon-info-bubble:before{content:"\\ea08"}.uicon-info:before{content:"\\ea09"}.uicon-sesamy:before{content:"\\ea0a"}.uicon-spinner-circle:before{content:"\\ea0b"}.uicon-spinner-inner:before{content:"\\ea0c"}
235
235
 
236
236
  /*! tailwindcss v3.4.1 | MIT License | https://tailwindcss.com*/*,:after,:before{border:0 solid #bfbcd7;box-sizing:border-box}:after,:before{--tw-content:""}:host,html{line-height:1.5;-webkit-text-size-adjust:100%;font-family:KHTeka,Helvetica Neue,HelveticaNeue,TeX Gyre Heros,TeXGyreHeros,FreeSans,Nimbus Sans L,Liberation Sans,Arimo,Helvetica,sans-serif;font-feature-settings:normal;font-variation-settings:normal;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-tap-highlight-color:transparent}body{line-height:inherit;margin:0}hr{border-top-width:1px;color:inherit;height:0}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-size:1em;font-variation-settings:normal}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{border-collapse:collapse;border-color:inherit;text-indent:0}button,input,optgroup,select,textarea{color:inherit;font-family:inherit;font-feature-settings:inherit;font-size:100%;font-variation-settings:inherit;font-weight:inherit;line-height:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{color:#4b4a58;opacity:1}input::placeholder,textarea::placeholder{color:#4b4a58;opacity:1}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{height:auto;max-width:100%}[hidden]{display:none}body,html{height:100%}body{--tw-bg-opacity:1;background-color:rgb(248 249 251/var(--tw-bg-opacity));font-size:1rem;letter-spacing:.0125rem;line-height:120%;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}@media (min-width:1280px){body{font-size:1.125rem;line-height:120%}}:is(.dark body){--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity))}button,input,optgroup,select,textarea{font-size:.875rem;letter-spacing:.0125rem;line-height:120%}@media (min-width:1280px){button,input,optgroup,select,textarea{font-size:1rem;line-height:120%}}h1{font-size:1.5rem;font-weight:500;line-height:120%}@media (min-width:1280px){h1{font-size:2rem;line-height:120%}}@media (min-width:640px){h1{font-size:3rem;letter-spacing:-.0625rem;line-height:100%}}@media (min-width:1280px){h1{font-size:3.5rem;letter-spacing:-.0625rem;line-height:100%}}h2{font-size:1.25rem;font-weight:500;line-height:120%}@media (min-width:1280px){h2{font-size:1.5rem;line-height:120%}}@media (min-width:640px){h2{font-size:2rem;letter-spacing:0;line-height:120%}}@media (min-width:1280px){h2{font-size:3rem;letter-spacing:-.0625rem;line-height:100%}}h3{font-size:1.125rem;font-weight:500;line-height:120%}@media (min-width:1280px){h3{font-size:1.25rem;line-height:120%}}@media (min-width:640px){h3{font-size:1.5rem;line-height:120%}}@media (min-width:1280px){h3{font-size:2rem;line-height:120%}}h4{font-size:1rem;font-weight:500;line-height:120%}@media (min-width:1280px){h4{font-size:1.125rem;line-height:120%}}@media (min-width:640px){h4{font-size:1.125rem;line-height:120%}}@media (min-width:1280px){h4{font-size:1.5rem;line-height:120%}}h5{font-size:.875rem;font-weight:500;line-height:120%}@media (min-width:1280px){h5{font-size:1rem;line-height:120%}}@media (min-width:640px){h5{font-size:1rem;line-height:120%}}@media (min-width:1280px){h5{font-size:1.125rem;line-height:120%}}h6{font-size:.75rem;font-weight:500;line-height:135%}@media (min-width:1280px){h6{font-size:.875rem;line-height:120%}}@media (min-width:640px){h6{font-size:.875rem;line-height:120%}}@media (min-width:1280px){h6{font-size:1rem;line-height:120%}}*,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.container{width:100%}@media (min-width:640px){.container{max-width:640px}}@media (min-width:1280px){.container{max-width:1280px}}@media (min-width:1920px){.container{max-width:1920px}}.pointer-events-none{pointer-events:none}.absolute{position:absolute}.relative{position:relative}.inset-0{inset:0}.left-0{left:0}.right-0{right:0}.right-2{right:.5rem}.top-0{top:0}.top-1\\/2{top:50%}.my-4{margin-bottom:1rem;margin-top:1rem}.mb-1{margin-bottom:.25rem}.mb-12{margin-bottom:3rem}.mb-16{margin-bottom:4rem}.mb-2{margin-bottom:.5rem}.mb-3{margin-bottom:.75rem}.mb-4{margin-bottom:1rem}.mb-5{margin-bottom:1.25rem}.mb-6{margin-bottom:1.5rem}.mb-7{margin-bottom:1.75rem}.mb-8{margin-bottom:2rem}.mr-2{margin-right:.5rem}.mr-4{margin-right:1rem}.mt-0{margin-top:0}.mt-0\\.5{margin-top:.125rem}.mt-3{margin-top:.75rem}.mt-4{margin-top:1rem}.mt-5{margin-top:1.25rem}.mt-8{margin-top:2rem}.line-clamp-1{display:-webkit-box;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:1}.block{display:block}.inline-block{display:inline-block}.inline{display:inline}.flex{display:flex}.inline-flex{display:inline-flex}.grid{display:grid}.\\!hidden{display:none!important}.hidden{display:none}.h-10{height:2.5rem}.h-11{height:2.75rem}.h-12{height:3rem}.h-5{height:1.25rem}.h-9{height:2.25rem}.h-full{height:100%}.min-h-\\[calc\\(100vh-83px\\)\\]{min-height:calc(100vh - 83px)}.min-h-full{min-height:100%}.min-h-screen{min-height:100vh}.w-10{width:2.5rem}.w-12{width:3rem}.w-5{width:1.25rem}.w-9{width:2.25rem}.w-\\[calc\\(100\\%-theme\\(space\\.2\\)-theme\\(space\\.2\\)\\)\\]{width:calc(100% - 1rem)}.w-auto{width:auto}.w-full{width:100%}.min-w-0{min-width:0}.max-w-\\[1295px\\]{max-width:1295px}.max-w-md{max-width:28rem}.max-w-none{max-width:none}.max-w-sm{max-width:24rem}.flex-1{flex:1 1 0%}.flex-shrink-0{flex-shrink:0}.grow{flex-grow:1}.-translate-y-1\\/2{--tw-translate-y:-50%}.-translate-y-1\\/2,.transform{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}@keyframes spin{to{transform:rotate(1turn)}}.animate-spin{animation:spin 1s linear infinite}.cursor-not-allowed{cursor:not-allowed}.cursor-pointer{cursor:pointer}.select-none{-webkit-user-select:none;-moz-user-select:none;user-select:none}.flex-col{flex-direction:column}.\\!flex-nowrap{flex-wrap:nowrap!important}.items-center{align-items:center}.justify-start{justify-content:flex-start}.justify-end{justify-content:flex-end}.justify-center{justify-content:center}.\\!justify-between{justify-content:space-between!important}.justify-between{justify-content:space-between}.gap-1{gap:.25rem}.gap-1\\.5{gap:.375rem}.gap-2{gap:.5rem}.gap-4{gap:1rem}.gap-6{gap:1.5rem}.space-x-2>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-left:calc(.5rem*(1 - var(--tw-space-x-reverse)));margin-right:calc(.5rem*var(--tw-space-x-reverse))}.space-x-4>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-left:calc(1rem*(1 - var(--tw-space-x-reverse)));margin-right:calc(1rem*var(--tw-space-x-reverse))}.space-y-1>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(.25rem*var(--tw-space-y-reverse));margin-top:calc(.25rem*(1 - var(--tw-space-y-reverse)))}.space-y-1\\.5>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(.375rem*var(--tw-space-y-reverse));margin-top:calc(.375rem*(1 - var(--tw-space-y-reverse)))}.space-y-2>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(.5rem*var(--tw-space-y-reverse));margin-top:calc(.5rem*(1 - var(--tw-space-y-reverse)))}.space-y-3>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(.75rem*var(--tw-space-y-reverse));margin-top:calc(.75rem*(1 - var(--tw-space-y-reverse)))}.space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(1rem*var(--tw-space-y-reverse));margin-top:calc(1rem*(1 - var(--tw-space-y-reverse)))}.space-y-6>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(1.5rem*var(--tw-space-y-reverse));margin-top:calc(1.5rem*(1 - var(--tw-space-y-reverse)))}.overflow-hidden,.truncate{overflow:hidden}.truncate{text-overflow:ellipsis;white-space:nowrap}.break-all{word-break:break-all}.rounded-2xl{border-radius:1.25rem}.rounded-full{border-radius:9999px}.rounded-lg{border-radius:.625rem}.rounded-md{border-radius:.375rem}.rounded-r-lg{border-bottom-right-radius:.625rem;border-top-right-radius:.625rem}.border{border-width:1px}.border-y{border-top-width:1px}.border-b,.border-y{border-bottom-width:1px}.border-r{border-right-width:1px}.border-t{border-top-width:1px}.border-gray-100{--tw-border-opacity:1;border-color:rgb(248 249 251/var(--tw-border-opacity))}.border-gray-200{--tw-border-opacity:1;border-color:rgb(191 188 215/var(--tw-border-opacity))}.border-gray-200\\/50{border-color:rgba(191,188,215,.5)}.border-gray-300{--tw-border-opacity:1;border-color:rgb(136 134 159/var(--tw-border-opacity))}.border-gray-500{--tw-border-opacity:1;border-color:rgb(59 57 70/var(--tw-border-opacity))}.border-red{--tw-border-opacity:1;border-color:rgb(252 90 90/var(--tw-border-opacity))}.bg-gray-100{--tw-bg-opacity:1;background-color:rgb(248 249 251/var(--tw-bg-opacity))}.bg-gray-200\\/40{background-color:rgba(191,188,215,.4)}.bg-primary{background-color:var(--primary-color)}.bg-primaryHover{background-color:var(--primary-hover)}.bg-red\\/80{background-color:rgba(252,90,90,.8)}.bg-white{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity))}.bg-cover{background-size:cover}.bg-center{background-position:50%}.p-2{padding:.5rem}.p-3{padding:.75rem}.p-4{padding:1rem}.p-6{padding:1.5rem}.px-0{padding-left:0;padding-right:0}.px-10{padding-left:2.5rem;padding-right:2.5rem}.px-2{padding-left:.5rem;padding-right:.5rem}.px-3{padding-left:.75rem;padding-right:.75rem}.px-4{padding-left:1rem;padding-right:1rem}.px-5{padding-left:1.25rem;padding-right:1.25rem}.px-6{padding-left:1.5rem;padding-right:1.5rem}.px-8{padding-left:2rem;padding-right:2rem}.py-1{padding-bottom:.25rem;padding-top:.25rem}.py-1\\.5{padding-bottom:.375rem;padding-top:.375rem}.py-10{padding-bottom:2.5rem;padding-top:2.5rem}.py-2{padding-bottom:.5rem;padding-top:.5rem}.py-3{padding-bottom:.75rem;padding-top:.75rem}.py-5{padding-bottom:1.25rem;padding-top:1.25rem}.py-6{padding-bottom:1.5rem;padding-top:1.5rem}.pb-2{padding-bottom:.5rem}.pb-8{padding-bottom:2rem}.pl-12{padding-left:3rem}.pl-6{padding-left:1.5rem}.pr-12{padding-right:3rem}.pr-6{padding-right:1.5rem}.pr-8{padding-right:2rem}.pt-0{padding-top:0}.pt-2{padding-top:.5rem}.pt-2\\.5{padding-top:.625rem}.pt-4{padding-top:1rem}.text-left{text-align:left}.text-center{text-align:center}.text-right{text-align:right}.indent-\\[5px\\]{text-indent:5px}.align-middle{vertical-align:middle}.font-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}.\\!text-base{font-size:1rem!important;line-height:120%!important}.\\!text-xs{font-size:.75rem!important;line-height:135%!important}.text-2xl{font-size:1.5rem;line-height:120%}.text-3xl{font-size:2rem;line-height:120%}.text-base{font-size:1rem;line-height:120%}.text-lg{font-size:1.125rem;line-height:120%}.text-sm{font-size:.875rem;line-height:120%}.text-xl{font-size:1.25rem;line-height:120%}.text-xs{font-size:.75rem;line-height:135%}.font-bold{font-weight:700}.font-medium{font-weight:500}.font-semibold{font-weight:600}.uppercase{text-transform:uppercase}.leading-\\[0\\]{line-height:0}.leading-none{line-height:1}.leading-tight{line-height:1.25}.tracking-tight{letter-spacing:-.025em}.text-\\[\\#B2B2B2\\]{--tw-text-opacity:1;color:rgb(178 178 178/var(--tw-text-opacity))}.text-black{--tw-text-opacity:1;color:rgb(0 0 0/var(--tw-text-opacity))}.text-gray-200{--tw-text-opacity:1;color:rgb(191 188 215/var(--tw-text-opacity))}.text-gray-300{--tw-text-opacity:1;color:rgb(136 134 159/var(--tw-text-opacity))}.text-gray-400{--tw-text-opacity:1;color:rgb(75 74 88/var(--tw-text-opacity))}.text-gray-500{--tw-text-opacity:1;color:rgb(59 57 70/var(--tw-text-opacity))}.text-gray-700{--tw-text-opacity:1;color:rgb(30 30 39/var(--tw-text-opacity))}.text-gray-800{--tw-text-opacity:1;color:rgb(20 20 26/var(--tw-text-opacity))}.text-gray-900{--tw-text-opacity:1;color:rgb(8 8 14/var(--tw-text-opacity))}.text-green{--tw-text-opacity:1;color:rgb(54 191 118/var(--tw-text-opacity))}.text-primary{color:var(--primary-color)}.text-red{--tw-text-opacity:1;color:rgb(252 90 90/var(--tw-text-opacity))}.text-textOnPrimary{color:var(--text-on-primary)}.text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity))}.accent-\\[\\#4F2D7F\\]{accent-color:#4f2d7f}.opacity-40{opacity:.4}.opacity-50{opacity:.5}.opacity-60{opacity:.6}.shadow-sm{--tw-shadow:0 1px 2px 0 rgba(0,0,0,.05);--tw-shadow-colored:0 1px 2px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.outline{outline-style:solid}.ring-offset-white{--tw-ring-offset-color:#fff}.filter{filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.transition-all{transition-duration:.15s;transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1)}.transition-colors{transition-duration:.15s;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1)}.transition-opacity{transition-duration:.15s;transition-property:opacity;transition-timing-function:cubic-bezier(.4,0,.2,1)}.transition-transform{transition-duration:.15s;transition-property:transform;transition-timing-function:cubic-bezier(.4,0,.2,1)}.duration-200{transition-duration:.2s}.row-up-left{align-content:flex-start;display:flex;flex-direction:row;flex-wrap:wrap;justify-content:flex-start}.row-left{justify-content:flex-start}.row,.row-left{align-content:center;align-items:center;display:flex;flex-direction:row;flex-wrap:wrap}.row{justify-content:center}.column-left{align-items:flex-start}.column,.column-left{display:flex;flex-direction:column;justify-content:center}.column{align-items:center}@media (min-width:1280px){.text-5xl{font-size:5.125rem;letter-spacing:-.125rem;line-height:100%}.text-4xl{font-size:3.5rem}.text-3xl,.text-4xl{letter-spacing:-.0625rem;line-height:100%}.text-3xl{font-size:3rem}.text-2xl{font-size:2rem}.text-2xl,.text-xl{line-height:120%}.text-xl{font-size:1.5rem}.text-lg{font-size:1.25rem}.text-base,.text-lg{line-height:120%}.text-base{font-size:1.125rem}.text-sm{font-size:1rem}.text-sm,.text-xs{line-height:120%}.text-xs{font-size:.875rem}}:root{--primary-color:#7d68f4;--primary-hover:#9786f6;--text-on-primary:#fff}svg{transform:translate3d(var(--tw-translate-x),var(--tw-translate-y),0) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}*,:after,:before{text-underline-offset:4px}input[type=number],input[type=number]::-webkit-inner-spin-button,input[type=number]::-webkit-outer-spin-button{-webkit-appearance:none;-moz-appearance:textfield!important}.btn.is-loading{cursor:not-allowed;opacity:.4;pointer-events:none}.btn .btn-spinner,.btn.is-loading .btn-label{opacity:0;visibility:hidden}.btn.is-loading .btn-spinner{opacity:1;visibility:visible}[class*=" uicon-"],[class^=uicon-]{letter-spacing:0;line-height:100%}.file\\:border-0::file-selector-button{border-width:0}.file\\:text-sm::file-selector-button{font-size:.875rem;line-height:120%}.file\\:font-medium::file-selector-button{font-weight:500}.placeholder\\:text-gray-300::-moz-placeholder{--tw-text-opacity:1;color:rgb(136 134 159/var(--tw-text-opacity))}.placeholder\\:text-gray-300::placeholder{--tw-text-opacity:1;color:rgb(136 134 159/var(--tw-text-opacity))}.placeholder\\:text-gray-500::-moz-placeholder{--tw-text-opacity:1;color:rgb(59 57 70/var(--tw-text-opacity))}.placeholder\\:text-gray-500::placeholder{--tw-text-opacity:1;color:rgb(59 57 70/var(--tw-text-opacity))}.first\\:rounded-l-md:first-child{border-bottom-left-radius:.375rem;border-top-left-radius:.375rem}.first\\:border-l:first-child{border-left-width:1px}.last\\:rounded-r-md:last-child{border-bottom-right-radius:.375rem;border-top-right-radius:.375rem}.hover\\:bg-black\\/5:hover{background-color:rgba(0,0,0,.05)}.hover\\:bg-gray-100:hover{--tw-bg-opacity:1;background-color:rgb(248 249 251/var(--tw-bg-opacity))}.hover\\:bg-gray-200:hover{--tw-bg-opacity:1;background-color:rgb(191 188 215/var(--tw-bg-opacity))}.hover\\:bg-gray-200\\/75:hover{background-color:rgba(191,188,215,.75)}.hover\\:bg-primaryHover:hover{background-color:var(--primary-hover)}.hover\\:bg-red\\/90:hover{background-color:rgba(252,90,90,.9)}.hover\\:text-gray-700:hover{--tw-text-opacity:1;color:rgb(30 30 39/var(--tw-text-opacity))}.hover\\:text-primaryHover:hover{color:var(--primary-hover)}.hover\\:underline:hover{text-decoration-line:underline}.hover\\:opacity-100:hover{opacity:1}.hover\\:brightness-90:hover{--tw-brightness:brightness(.9);filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.focus\\:z-10:focus{z-index:10}.focus\\:outline-none:focus{outline:2px solid transparent;outline-offset:2px}.focus\\:ring:focus{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width)) var(--tw-ring-color)}.focus\\:ring-1:focus,.focus\\:ring:focus{box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus\\:ring-1:focus{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color)}.focus\\:ring-2:focus{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus\\:ring-primary:focus{--tw-ring-color:var(--primary-color)}.focus\\:ring-offset-2:focus{--tw-ring-offset-width:2px}.focus-visible\\:outline-none:focus-visible{outline:2px solid transparent;outline-offset:2px}.focus-visible\\:ring-2:focus-visible{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus-visible\\:ring-offset-2:focus-visible{--tw-ring-offset-width:2px}.disabled\\:pointer-events-none:disabled{pointer-events:none}.disabled\\:cursor-not-allowed:disabled{cursor:not-allowed}.disabled\\:opacity-50:disabled{opacity:.5}.group[open] .group-open\\:rotate-90{--tw-rotate:90deg;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.peer:disabled~.peer-disabled\\:cursor-not-allowed{cursor:not-allowed}.peer:disabled~.peer-disabled\\:opacity-70{opacity:.7}.has-\\[\\:disabled\\]\\:opacity-50:has(:disabled){opacity:.5}:is(.dark .dark\\:border-gray-400){--tw-border-opacity:1;border-color:rgb(75 74 88/var(--tw-border-opacity))}:is(.dark .dark\\:border-gray-500){--tw-border-opacity:1;border-color:rgb(59 57 70/var(--tw-border-opacity))}:is(.dark .dark\\:border-gray-600){--tw-border-opacity:1;border-color:rgb(40 40 52/var(--tw-border-opacity))}:is(.dark .dark\\:border-gray-700){--tw-border-opacity:1;border-color:rgb(30 30 39/var(--tw-border-opacity))}:is(.dark .dark\\:bg-black){--tw-bg-opacity:1;background-color:rgb(0 0 0/var(--tw-bg-opacity))}:is(.dark .dark\\:bg-gray-600){--tw-bg-opacity:1;background-color:rgb(40 40 52/var(--tw-bg-opacity))}:is(.dark .dark\\:bg-gray-700){--tw-bg-opacity:1;background-color:rgb(30 30 39/var(--tw-bg-opacity))}:is(.dark .dark\\:bg-gray-800){--tw-bg-opacity:1;background-color:rgb(20 20 26/var(--tw-bg-opacity))}:is(.dark .dark\\:text-\\[\\#201a41\\]){--tw-text-opacity:1;color:rgb(32 26 65/var(--tw-text-opacity))}:is(.dark .dark\\:text-gray-300){--tw-text-opacity:1;color:rgb(136 134 159/var(--tw-text-opacity))}:is(.dark .dark\\:text-gray-400){--tw-text-opacity:1;color:rgb(75 74 88/var(--tw-text-opacity))}:is(.dark .dark\\:text-white){--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity))}:is(.dark .dark\\:ring-offset-gray-900){--tw-ring-offset-color:#08080e}:is(.dark .dark\\:placeholder\\:text-gray-400)::-moz-placeholder{--tw-text-opacity:1;color:rgb(75 74 88/var(--tw-text-opacity))}:is(.dark .dark\\:placeholder\\:text-gray-400)::placeholder{--tw-text-opacity:1;color:rgb(75 74 88/var(--tw-text-opacity))}:is(.dark .dark\\:hover\\:bg-black\\/90:hover){background-color:rgba(0,0,0,.9)}:is(.dark .dark\\:hover\\:bg-gray-700:hover){--tw-bg-opacity:1;background-color:rgb(30 30 39/var(--tw-bg-opacity))}:is(.dark .dark\\:hover\\:bg-gray-800:hover){--tw-bg-opacity:1;background-color:rgb(20 20 26/var(--tw-bg-opacity))}:is(.dark .dark\\:focus\\:ring-offset-gray-900:focus){--tw-ring-offset-color:#08080e}@media (min-width:640px){.sm\\:absolute{position:absolute}.sm\\:left-4{left:1rem}.sm\\:top-1\\/2{top:50%}.sm\\:mt-4{margin-top:1rem}.sm\\:inline{display:inline}.sm\\:h-6{height:1.5rem}.sm\\:min-h-\\[700px\\]{min-height:700px}.sm\\:w-6{width:1.5rem}.sm\\:w-\\[calc\\(100\\%-theme\\(space\\.16\\)-theme\\(space\\.16\\)\\)\\]{width:calc(100% - 8rem)}.sm\\:w-auto{width:auto}.sm\\:w-full{width:100%}.sm\\:max-w-md{max-width:28rem}.sm\\:-translate-y-1\\/2{--tw-translate-y:-50%;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.sm\\:flex-col{flex-direction:column}.sm\\:justify-normal{justify-content:normal}.sm\\:space-x-0>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-left:calc(0px*(1 - var(--tw-space-x-reverse)));margin-right:calc(0px*var(--tw-space-x-reverse))}.sm\\:space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(1rem*var(--tw-space-y-reverse));margin-top:calc(1rem*(1 - var(--tw-space-y-reverse)))}.sm\\:bg-fixed{background-attachment:fixed}.sm\\:bg-left-top{background-position:0 0}.sm\\:px-10{padding-left:2.5rem;padding-right:2.5rem}.sm\\:px-14{padding-left:3.5rem;padding-right:3.5rem}.sm\\:py-14{padding-bottom:3.5rem;padding-top:3.5rem}.sm\\:py-4{padding-bottom:1rem;padding-top:1rem}.sm\\:pt-16{padding-top:4rem}.sm\\:text-2xl{font-size:1.5rem;line-height:120%}.sm\\:text-base{font-size:1rem;line-height:120%}}@media (min-width:1280px){.md\\:min-w-\\[448px\\]{min-width:448px}.md\\:p-10{padding:2.5rem}.md\\:py-10{padding-bottom:2.5rem;padding-top:2.5rem}.md\\:pl-10{padding-left:2.5rem}.md\\:pl-20{padding-left:5rem}.md\\:pr-10{padding-right:2.5rem}.md\\:pr-20{padding-right:5rem}.md\\:text-3xl{font-size:2rem;line-height:120%}.md\\:text-base{font-size:1rem;line-height:120%}.md\\:text-sm{font-size:.875rem;line-height:120%}.md\\:text-xs{font-size:.75rem;line-height:135%}}@media (max-height:900px) and (min-width:640px){.short\\:static{position:static}.short\\:left-auto{left:auto}.short\\:top-auto{top:auto}.short\\:inline{display:inline}.short\\:hidden{display:none}.short\\:h-5{height:1.25rem}.short\\:min-h-\\[558px\\]{min-height:558px}.short\\:w-5{width:1.25rem}.short\\:flex-1{flex:1 1 0%}.short\\:translate-y-0{--tw-translate-y:0px;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.short\\:flex-row{flex-direction:row}.short\\:space-x-4>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-left:calc(1rem*(1 - var(--tw-space-x-reverse)));margin-right:calc(1rem*var(--tw-space-x-reverse))}.short\\:space-y-0>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(0px*var(--tw-space-y-reverse));margin-top:calc(0px*(1 - var(--tw-space-y-reverse)))}.short\\:px-0{padding-left:0;padding-right:0}.short\\:py-3{padding-bottom:.75rem;padding-top:.75rem}}.\\[\\&\\>\\*\\:last-child\\]\\:mb-0>:last-child{margin-bottom:0}.\\[\\&_h1\\]\\:mb-6 h1,.\\[\\&_h2\\]\\:mb-6 h2{margin-bottom:1.5rem}`;function B8(){if(typeof document<"u"){const t=document.createElement("style");t.innerHTML=Fp,t.setAttribute("data-authhero-tailwind",""),document.head.appendChild(t)}}const L8='var Ve=Object.defineProperty;var ze=(e,t,r)=>t in e?Ve(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var L=(e,t,r)=>ze(e,typeof t!="symbol"?t+"":t,r);var Ke={Stringify:1,BeforeStream:2,Stream:3},C=(e,t)=>{const r=new String(e);return r.isEscaped=!0,r.callbacks=t,r},Xe=/[&<>\'"]/,Je=async(e,t)=>{let r="";t||(t=[]);const a=await Promise.all(e);for(let n=a.length-1;r+=a[n],n--,!(n<0);n--){let s=a[n];typeof s=="object"&&t.push(...s.callbacks||[]);const l=s.isEscaped;if(s=await(typeof s=="object"?s.toString():s),typeof s=="object"&&t.push(...s.callbacks||[]),s.isEscaped??l)r+=s;else{const i=[r];T(s,i),r=i[0]}}return C(r,t)},T=(e,t)=>{const r=e.search(Xe);if(r===-1){t[0]+=e;return}let a,n,s=0;for(n=r;n<e.length;n++){switch(e.charCodeAt(n)){case 34:a="&quot;";break;case 39:a="&#39;";break;case 38:a="&amp;";break;case 60:a="&lt;";break;case 62:a="&gt;";break;default:continue}t[0]+=e.substring(s,n)+a,s=n+1}t[0]+=e.substring(s,n)},Ge=e=>{const t=e.callbacks;if(!(t!=null&&t.length))return e;const r=[e],a={};return t.forEach(n=>n({phase:Ke.Stringify,buffer:r,context:a})),r[0]},oe=Symbol("RENDERER"),se=Symbol("ERROR_HANDLER"),E=Symbol("STASH"),Te=Symbol("INTERNAL"),Qe=Symbol("MEMO"),z=Symbol("PERMALINK"),me=e=>(e[Te]=!0,e),Ne=e=>({value:t,children:r})=>{if(!r)return;const a={children:[{tag:me(()=>{e.push(t)}),props:{}}]};Array.isArray(r)?a.children.push(...r.flat()):a.children.push(r),a.children.push({tag:me(()=>{e.pop()}),props:{}});const n={tag:"",props:a,type:""};return n[se]=s=>{throw e.pop(),s},n},$e=e=>{const t=[e],r=Ne(t);return r.values=t,r.Provider=r,N.push(r),r},N=[],Me=e=>{const t=[e],r=a=>{t.push(a.value);let n;try{n=a.children?(Array.isArray(a.children)?new Oe("",{},a.children):a.children).toString():""}finally{t.pop()}return n instanceof Promise?n.then(s=>C(s,s.callbacks)):C(n)};return r.values=t,r.Provider=r,r[oe]=Ne(t),N.push(r),r},R=e=>e.values.at(-1),W={title:[],script:["src"],style:["data-href"],link:["href"],meta:["name","httpEquiv","charset","itemProp"]},ie={},U="data-precedence",q=e=>Array.isArray(e)?e:[e],pe=new WeakMap,ge=(e,t,r,a)=>({buffer:n,context:s})=>{if(!n)return;const l=pe.get(s)||{};pe.set(s,l);const i=l[e]||(l[e]=[]);let c=!1;const d=W[e];if(d.length>0){e:for(const[,u]of i)for(const f of d)if(((u==null?void 0:u[f])??null)===(r==null?void 0:r[f])){c=!0;break e}}if(c?n[0]=n[0].replaceAll(t,""):d.length>0?i.push([t,r,a]):i.unshift([t,r,a]),n[0].indexOf("</head>")!==-1){let u;if(a===void 0)u=i.map(([f])=>f);else{const f=[];u=i.map(([o,,h])=>{let m=f.indexOf(h);return m===-1&&(f.push(h),m=f.length-1),[o,m]}).sort((o,h)=>o[1]-h[1]).map(([o])=>o)}u.forEach(f=>{n[0]=n[0].replaceAll(f,"")}),n[0]=n[0].replace(/(?=<\\/head>)/,u.join(""))}},j=(e,t,r)=>C(new k(e,r,q(t??[])).toString()),B=(e,t,r,a)=>{if("itemProp"in r)return j(e,t,r);let{precedence:n,blocking:s,...l}=r;n=a?n??"":void 0,a&&(l[U]=n);const i=new k(e,l,q(t||[])).toString();return i instanceof Promise?i.then(c=>C(i,[...c.callbacks||[],ge(e,c,l,n)])):C(i,[ge(e,i,l,n)])},Ye=({children:e,...t})=>{const r=ce();if(r){const a=R(r);if(a==="svg"||a==="head")return new k("title",t,q(e??[]))}return B("title",e,t,!1)},et=({children:e,...t})=>{const r=ce();return["src","async"].some(a=>!t[a])||r&&R(r)==="head"?j("script",e,t):B("script",e,t,!1)},tt=({children:e,...t})=>["href","precedence"].every(r=>r in t)?(t["data-href"]=t.href,delete t.href,B("style",e,t,!0)):j("style",e,t),rt=({children:e,...t})=>["onLoad","onError"].some(r=>r in t)||t.rel==="stylesheet"&&(!("precedence"in t)||"disabled"in t)?j("link",e,t):B("link",e,t,"precedence"in t),nt=({children:e,...t})=>{const r=ce();return r&&R(r)==="head"?j("meta",e,t):B("meta",e,t,!1)},Re=(e,{children:t,...r})=>new k(e,r,q(t??[])),at=e=>(typeof e.action=="function"&&(e.action=z in e.action?e.action[z]:void 0),Re("form",e)),De=(e,t)=>(typeof t.formAction=="function"&&(t.formAction=z in t.formAction?t.formAction[z]:void 0),Re(e,t)),st=e=>De("input",e),it=e=>De("button",e);const G=Object.freeze(Object.defineProperty({__proto__:null,button:it,form:at,input:st,link:rt,meta:nt,script:et,style:tt,title:Ye},Symbol.toStringTag,{value:"Module"}));var lt=new Map([["className","class"],["htmlFor","for"],["crossOrigin","crossorigin"],["httpEquiv","http-equiv"],["itemProp","itemprop"],["fetchPriority","fetchpriority"],["noModule","nomodule"],["formAction","formaction"]]),K=e=>lt.get(e)||e,Ie=(e,t)=>{for(const[r,a]of Object.entries(e)){const n=r[0]==="-"||!/[A-Z]/.test(r)?r:r.replace(/[A-Z]/g,s=>`-${s.toLowerCase()}`);t(n,a==null?null:typeof a=="number"?n.match(/^(?:a|border-im|column(?:-c|s)|flex(?:$|-[^b])|grid-(?:ar|[^a])|font-w|li|or|sca|st|ta|wido|z)|ty$/)?`${a}`:`${a}px`:a)}},O=void 0,ce=()=>O,ot=e=>/[A-Z]/.test(e)&&e.match(/^(?:al|basel|clip(?:Path|Rule)$|co|do|fill|fl|fo|gl|let|lig|i|marker[EMS]|o|pai|pointe|sh|st[or]|text[^L]|tr|u|ve|w)/)?e.replace(/([A-Z])/g,"-$1").toLowerCase():e,ct=["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],ft=["allowfullscreen","async","autofocus","autoplay","checked","controls","default","defer","disabled","download","formnovalidate","hidden","inert","ismap","itemscope","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","selected"],fe=(e,t)=>{for(let r=0,a=e.length;r<a;r++){const n=e[r];if(typeof n=="string")T(n,t);else{if(typeof n=="boolean"||n===null||n===void 0)continue;n instanceof k?n.toStringToBuffer(t):typeof n=="number"||n.isEscaped?t[0]+=n:n instanceof Promise?t.unshift("",n):fe(n,t)}}},k=class{constructor(e,t,r){L(this,"tag");L(this,"props");L(this,"key");L(this,"children");L(this,"isEscaped",!0);L(this,"localContexts");this.tag=e,this.props=t,this.children=r}get type(){return this.tag}get ref(){return this.props.ref||null}toString(){var t,r;const e=[""];(t=this.localContexts)==null||t.forEach(([a,n])=>{a.values.push(n)});try{this.toStringToBuffer(e)}finally{(r=this.localContexts)==null||r.forEach(([a])=>{a.values.pop()})}return e.length===1?"callbacks"in e?Ge(C(e[0],e.callbacks)).toString():e[0]:Je(e,e.callbacks)}toStringToBuffer(e){const t=this.tag,r=this.props;let{children:a}=this;e[0]+=`<${t}`;const n=O&&R(O)==="svg"?s=>ot(K(s)):s=>K(s);for(let[s,l]of Object.entries(r))if(s=n(s),s!=="children"){if(s==="style"&&typeof l=="object"){let i="";Ie(l,(c,d)=>{d!=null&&(i+=`${i?";":""}${c}:${d}`)}),e[0]+=\' style="\',T(i,e),e[0]+=\'"\'}else if(typeof l=="string")e[0]+=` ${s}="`,T(l,e),e[0]+=\'"\';else if(l!=null)if(typeof l=="number"||l.isEscaped)e[0]+=` ${s}="${l}"`;else if(typeof l=="boolean"&&ft.includes(s))l&&(e[0]+=` ${s}=""`);else if(s==="dangerouslySetInnerHTML"){if(a.length>0)throw new Error("Can only set one of `children` or `props.dangerouslySetInnerHTML`.");a=[C(l.__html)]}else if(l instanceof Promise)e[0]+=` ${s}="`,e.unshift(\'"\',l);else if(typeof l=="function"){if(!s.startsWith("on")&&s!=="ref")throw new Error(`Invalid prop \'${s}\' of type \'function\' supplied to \'${t}\'.`)}else e[0]+=` ${s}="`,T(l.toString(),e),e[0]+=\'"\'}if(ct.includes(t)&&a.length===0){e[0]+="/>";return}e[0]+=">",fe(a,e),e[0]+=`</${t}>`}},Q=class extends k{toStringToBuffer(e){const{children:t}=this,r=this.tag.call(null,{...this.props,children:t.length<=1?t[0]:t});if(!(typeof r=="boolean"||r==null))if(r instanceof Promise)if(N.length===0)e.unshift("",r);else{const a=N.map(n=>[n,n.values.at(-1)]);e.unshift("",r.then(n=>(n instanceof k&&(n.localContexts=a),n)))}else r instanceof k?r.toStringToBuffer(e):typeof r=="number"||r.isEscaped?(e[0]+=r,r.callbacks&&(e.callbacks||(e.callbacks=[]),e.callbacks.push(...r.callbacks))):T(r,e)}},Oe=class extends k{toStringToBuffer(e){fe(this.children,e)}},ye=!1,Y=(e,t,r)=>{if(!ye){for(const a in ie)G[a][oe]=ie[a];ye=!0}return typeof e=="function"?new Q(e,t,r):G[e]?new Q(G[e],t,r):e==="svg"||e==="head"?(O||(O=Me("")),new k(e,t,[new Q(O,{value:e},r)])):new k(e,t,r)},ut=({children:e})=>new Oe("",{children:e},Array.isArray(e)?e:e?[e]:[]);function H(e,t,r){let a;if(!t||!("children"in t))a=Y(e,t,[]);else{const n=t.children;a=Array.isArray(n)?Y(e,t,n):Y(e,t,[n])}return a.key=r,a}var x="_hp",vt={Change:"Input",DoubleClick:"DblClick"},dt={svg:"2000/svg",math:"1998/Math/MathML"},$=[],le=new WeakMap,M=void 0,ht=()=>M,A=e=>"t"in e,ee={onClick:["click",!1]},Ee=e=>{if(!e.startsWith("on"))return;if(ee[e])return ee[e];const t=e.match(/^on([A-Z][a-zA-Z]+?(?:PointerCapture)?)(Capture)?$/);if(t){const[,r,a]=t;return ee[e]=[(vt[r]||r).toLowerCase(),!!a]}},we=(e,t)=>M&&e instanceof SVGElement&&/[A-Z]/.test(t)&&(t in e.style||t.match(/^(?:o|pai|str|u|ve)/))?t.replace(/([A-Z])/g,"-$1").toLowerCase():t,mt=(e,t,r)=>{var a;t||(t={});for(let n in t){const s=t[n];if(n!=="children"&&(!r||r[n]!==s)){n=K(n);const l=Ee(n);if(l){if((r==null?void 0:r[n])!==s&&(r&&e.removeEventListener(l[0],r[n],l[1]),s!=null)){if(typeof s!="function")throw new Error(`Event handler for "${n}" is not a function`);e.addEventListener(l[0],s,l[1])}}else if(n==="dangerouslySetInnerHTML"&&s)e.innerHTML=s.__html;else if(n==="ref"){let i;typeof s=="function"?i=s(e)||(()=>s(null)):s&&"current"in s&&(s.current=e,i=()=>s.current=null),le.set(e,i)}else if(n==="style"){const i=e.style;typeof s=="string"?i.cssText=s:(i.cssText="",s!=null&&Ie(s,i.setProperty.bind(i)))}else{if(n==="value"){const c=e.nodeName;if(c==="INPUT"||c==="TEXTAREA"||c==="SELECT"){if(e.value=s==null||s===!1?null:s,c==="TEXTAREA"){e.textContent=s;continue}else if(c==="SELECT"){e.selectedIndex===-1&&(e.selectedIndex=0);continue}}}else(n==="checked"&&e.nodeName==="INPUT"||n==="selected"&&e.nodeName==="OPTION")&&(e[n]=s);const i=we(e,n);s==null||s===!1?e.removeAttribute(i):s===!0?e.setAttribute(i,""):typeof s=="string"||typeof s=="number"?e.setAttribute(i,s):e.setAttribute(i,s.toString())}}}if(r)for(let n in r){const s=r[n];if(n!=="children"&&!(n in t)){n=K(n);const l=Ee(n);l?e.removeEventListener(l[0],s,l[1]):n==="ref"?(a=le.get(e))==null||a():e.removeAttribute(we(e,n))}}},pt=(e,t)=>{t[E][0]=0,$.push([e,t]);const r=t.tag[oe]||t.tag,a=r.defaultProps?{...r.defaultProps,...t.props}:t.props;try{return[r.call(null,a)]}finally{$.pop()}},xe=(e,t,r,a,n)=>{var s,l;(s=e.vR)!=null&&s.length&&(a.push(...e.vR),delete e.vR),typeof e.tag=="function"&&((l=e[E][1][I])==null||l.forEach(i=>n.push(i))),e.vC.forEach(i=>{var c;if(A(i))r.push(i);else if(typeof i.tag=="function"||i.tag===""){i.c=t;const d=r.length;if(xe(i,t,r,a,n),i.s){for(let u=d;u<r.length;u++)r[u].s=!0;i.s=!1}}else r.push(i),(c=i.vR)!=null&&c.length&&(a.push(...i.vR),delete i.vR)})},gt=e=>{for(;;e=e.tag===x||!e.vC||!e.pP?e.nN:e.vC[0]){if(!e)return null;if(e.tag!==x&&e.e)return e.e}},qe=e=>{var t,r,a,n,s,l;A(e)||((r=(t=e[E])==null?void 0:t[1][I])==null||r.forEach(i=>{var c;return(c=i[2])==null?void 0:c.call(i)}),(a=le.get(e.e))==null||a(),e.p===2&&((n=e.vC)==null||n.forEach(i=>i.p=2)),(s=e.vC)==null||s.forEach(qe)),e.p||((l=e.e)==null||l.remove(),delete e.e),typeof e.tag=="function"&&(D.delete(e),Z.delete(e),delete e[E][3],e.a=!0)},ue=(e,t,r)=>{e.c=t,je(e,t,r)},Se=(e,t)=>{if(t){for(let r=0,a=e.length;r<a;r++)if(e[r]===t)return r}},be=Symbol(),je=(e,t,r)=>{var d;const a=[],n=[],s=[];xe(e,t,a,n,s),n.forEach(qe);const l=r?void 0:t.childNodes;let i,c=null;if(r)i=-1;else if(!l.length)i=0;else{const u=Se(l,gt(e.nN));u!==void 0?(c=l[u],i=u):i=Se(l,(d=a.find(f=>f.tag!==x&&f.e))==null?void 0:d.e)??-1,i===-1&&(r=!0)}for(let u=0,f=a.length;u<f;u++,i++){const o=a[u];let h;if(o.s&&o.e)h=o.e,o.s=!1;else{const m=r||!o.e;A(o)?(o.e&&o.d&&(o.e.textContent=o.t),o.d=!1,h=o.e||(o.e=document.createTextNode(o.t))):(h=o.e||(o.e=o.n?document.createElementNS(o.n,o.tag):document.createElement(o.tag)),mt(h,o.props,o.pP),je(o,h,m))}o.tag===x?i--:r?h.parentNode||t.appendChild(h):l[i]!==h&&l[i-1]!==h&&(l[i+1]===h?t.appendChild(l[i]):t.insertBefore(h,c||l[i]||null))}if(e.pP&&delete e.pP,s.length){const u=[],f=[];s.forEach(([,o,,h,m])=>{o&&u.push(o),h&&f.push(h),m==null||m()}),u.forEach(o=>o()),f.length&&requestAnimationFrame(()=>{f.forEach(o=>o())})}},yt=(e,t)=>!!(e&&e.length===t.length&&e.every((r,a)=>r[1]===t[a][1])),Z=new WeakMap,X=(e,t,r)=>{var s,l,i,c,d,u;const a=!r&&t.pC;r&&(t.pC||(t.pC=t.vC));let n;try{r||(r=typeof t.tag=="function"?pt(e,t):q(t.props.children)),((s=r[0])==null?void 0:s.tag)===""&&r[0][se]&&(n=r[0][se],e[5].push([e,n,t]));const f=a?[...t.pC]:t.vC?[...t.vC]:void 0,o=[];let h;for(let m=0;m<r.length;m++){Array.isArray(r[m])&&r.splice(m,1,...r[m].flat());let v=Be(r[m]);if(v){typeof v.tag=="function"&&!v.tag[Te]&&(N.length>0&&(v[E][2]=N.map(y=>[y,y.values.at(-1)])),(l=e[5])!=null&&l.length&&(v[E][3]=e[5].at(-1)));let p;if(f&&f.length){const y=f.findIndex(A(v)?g=>A(g):v.key!==void 0?g=>g.key===v.key&&g.tag===v.tag:g=>g.tag===v.tag);y!==-1&&(p=f[y],f.splice(y,1))}if(p)if(A(v))p.t!==v.t&&(p.t=v.t,p.d=!0),v=p;else{const y=p.pP=p.props;if(p.props=v.props,p.f||(p.f=v.f||t.f),typeof v.tag=="function"){const g=p[E][2];p[E][2]=v[E][2]||[],p[E][3]=v[E][3],!p.f&&((p.o||p)===v.o||(c=(i=p.tag)[Qe])!=null&&c.call(i,y,p.props))&&yt(g,p[E][2])&&(p.s=!0)}v=p}else if(!A(v)&&M){const y=R(M);y&&(v.n=y)}if(!A(v)&&!v.s&&(X(e,v),delete v.f),o.push(v),h&&!h.s&&!v.s)for(let y=h;y&&!A(y);y=(d=y.vC)==null?void 0:d.at(-1))y.nN=v;h=v}}t.vR=a?[...t.vC,...f||[]]:f||[],t.vC=o,a&&delete t.pC}catch(f){if(t.f=!0,f===be){if(n)return;throw f}const[o,h,m]=((u=t[E])==null?void 0:u[3])||[];if(h){const v=()=>V([0,!1,e[2]],m),p=Z.get(m)||[];p.push(v),Z.set(m,p);const y=h(f,()=>{const g=Z.get(m);if(g){const S=g.indexOf(v);if(S!==-1)return g.splice(S,1),v()}});if(y){if(e[0]===1)e[1]=!0;else if(X(e,m,[y]),(h.length===1||e!==o)&&m.c){ue(m,m.c,!1);return}throw be}}throw f}finally{n&&e[5].pop()}},Be=e=>{if(!(e==null||typeof e=="boolean")){if(typeof e=="string"||typeof e=="number")return{t:e.toString(),d:!0};if("vR"in e&&(e={tag:e.tag,props:e.props,key:e.key,f:e.f,type:e.tag,ref:e.props.ref,o:e.o||e}),typeof e.tag=="function")e[E]=[0,[]];else{const t=dt[e.tag];t&&(M||(M=$e("")),e.props.children=[{tag:M,props:{value:e.n=`http://www.w3.org/${t}`,children:e.props.children}}])}return e}},Fe=(e,t,r)=>{e.c===t&&(e.c=r,e.vC.forEach(a=>Fe(a,t,r)))},ke=(e,t)=>{var r,a;(r=t[E][2])==null||r.forEach(([n,s])=>{n.values.push(s)});try{X(e,t,void 0)}catch{return}if(t.a){delete t.a;return}(a=t[E][2])==null||a.forEach(([n])=>{n.values.pop()}),(e[0]!==1||!e[1])&&ue(t,t.c,!1)},D=new WeakMap,Ae=[],V=async(e,t)=>{e[5]||(e[5]=[]);const r=D.get(t);r&&r[0](void 0);let a;const n=new Promise(s=>a=s);if(D.set(t,[a,()=>{e[2]?e[2](e,t,s=>{ke(s,t)}).then(()=>a(t)):(ke(e,t),a(t))}]),Ae.length)Ae.at(-1).add(t);else{await Promise.resolve();const s=D.get(t);s&&(D.delete(t),s[1]())}return n},Et=(e,t)=>{const r=[];r[5]=[],r[4]=!0,X(r,e,void 0),r[4]=!1;const a=document.createDocumentFragment();ue(e,a,!0),Fe(e,a,t),t.replaceChildren(a)},wt=(e,t,r)=>({tag:x,props:{children:e},key:r,e:t,p:1}),te=0,I=1,re=2,ne=3,ae=new WeakMap,ve=(e,t)=>!e||!t||e.length!==t.length||t.some((r,a)=>r!==e[a]),St=void 0,Ce=[],He=e=>{var l;const t=()=>typeof e=="function"?e():e,r=$.at(-1);if(!r)return[t(),()=>{}];const[,a]=r,n=(l=a[E][1])[te]||(l[te]=[]),s=a[E][0]++;return n[s]||(n[s]=[t(),i=>{const c=St,d=n[s];if(typeof i=="function"&&(i=i(d[0])),!Object.is(i,d[0]))if(d[0]=i,Ce.length){const[u,f]=Ce.at(-1);Promise.all([u===3?a:V([u,!1,c],a),f]).then(([o])=>{if(!o||!(u===2||u===3))return;const h=o.vC;requestAnimationFrame(()=>{setTimeout(()=>{h===o.vC&&V([u===3?1:0,!1,c],o)})})})}else V([0,!1,c],a)}])},bt=(e,t,r)=>{var d;const a=$.at(-1);if(!a)return;const[,n]=a,s=(d=n[E][1])[I]||(d[I]=[]),l=n[E][0]++,[i,,c]=s[l]||(s[l]=[]);if(ve(i,r)){c&&c();const u=()=>{f[e]=void 0,f[2]=t()},f=[r,void 0,void 0,void 0,void 0];f[e]=u,s[l]=f}},_e=(e,t)=>bt(3,e,t),de=(e,t)=>{var i;const r=$.at(-1);if(!r)return e;const[,a]=r,n=(i=a[E][1])[re]||(i[re]=[]),s=a[E][0]++,l=n[s];return ve(l==null?void 0:l[1],t)?n[s]=[e,t]:e=n[s][0],e},kt=e=>{const t=ae.get(e);if(t){if(t.length===2)throw t[1];return t[0]}throw e.then(r=>ae.set(e,[r]),r=>ae.set(e,[void 0,r])),e},At=(e,t)=>{var i;const r=$.at(-1);if(!r)return e();const[,a]=r,n=(i=a[E][1])[ne]||(i[ne]=[]),s=a[E][0]++,l=n[s];return ve(l==null?void 0:l[1],t)&&(n[s]=[e(),t]),n[s][0]},Ct=$e({pending:!1,data:null,method:null,action:null}),Le=new Set,Lt=e=>{Le.add(e),e.finally(()=>Le.delete(e))},he=(e,t)=>At(()=>r=>{let a;e&&(typeof e=="function"?a=e(r)||(()=>{e(null)}):e&&"current"in e&&(e.current=r,a=()=>{e.current=null}));const n=t(r);return()=>{n==null||n(),a==null||a()}},[e]),P=Object.create(null),_=Object.create(null),F=(e,t,r,a,n)=>{if(t!=null&&t.itemProp)return{tag:e,props:t,type:e,ref:t.ref};const s=document.head;let{onLoad:l,onError:i,precedence:c,blocking:d,...u}=t,f=null,o=!1;const h=W[e];let m;if(h.length>0){const g=s.querySelectorAll(e);e:for(const S of g)for(const w of W[e])if(S.getAttribute(w)===t[w]){f=S;break e}if(!f){const S=h.reduce((w,b)=>t[b]===void 0?w:`${w}-${b}-${t[b]}`,e);o=!_[S],f=_[S]||(_[S]=(()=>{const w=document.createElement(e);for(const b of h)t[b]!==void 0&&w.setAttribute(b,t[b]),t.rel&&w.setAttribute("rel",t.rel);return w})())}}else m=s.querySelectorAll(e);c=a?c??"":void 0,a&&(u[U]=c);const v=de(g=>{if(h.length>0){let S=!1;for(const w of s.querySelectorAll(e)){if(S&&w.getAttribute(U)!==c){s.insertBefore(g,w);return}w.getAttribute(U)===c&&(S=!0)}s.appendChild(g)}else if(m){let S=!1;for(const w of m)if(w===g){S=!0;break}S||s.insertBefore(g,s.contains(m[0])?m[0]:s.querySelector(e)),m=void 0}},[c]),p=he(t.ref,g=>{var b;const S=h[0];if(r===2&&(g.innerHTML=""),(o||m)&&v(g),!i&&!l)return;let w=P[b=g.getAttribute(S)]||(P[b]=new Promise((J,Ze)=>{g.addEventListener("load",J),g.addEventListener("error",Ze)}));l&&(w=w.then(l)),i&&(w=w.catch(i)),w.catch(()=>{})});if(n&&d==="render"){const g=W[e][0];if(t[g]){const S=t[g],w=P[S]||(P[S]=new Promise((b,J)=>{v(f),f.addEventListener("load",b),f.addEventListener("error",J)}));kt(w)}}const y={tag:e,type:e,props:{...u,ref:p},ref:p};return y.p=r,f&&(y.e=f),wt(y,s)},Pt=e=>{const t=ht(),r=t&&R(t);return r!=null&&r.endsWith("svg")?{tag:"title",props:e,type:"title",ref:e.ref}:F("title",e,void 0,!1,!1)},Tt=e=>!e||["src","async"].some(t=>!e[t])?{tag:"script",props:e,type:"script",ref:e.ref}:F("script",e,1,!1,!0),Nt=e=>!e||!["href","precedence"].every(t=>t in e)?{tag:"style",props:e,type:"style",ref:e.ref}:(e["data-href"]=e.href,delete e.href,F("style",e,2,!0,!0)),$t=e=>!e||["onLoad","onError"].some(t=>t in e)||e.rel==="stylesheet"&&(!("precedence"in e)||"disabled"in e)?{tag:"link",props:e,type:"link",ref:e.ref}:F("link",e,1,"precedence"in e,!0),Mt=e=>F("meta",e,void 0,!1,!1),We=Symbol(),Rt=e=>{const{action:t,...r}=e;typeof t!="function"&&(r.action=t);const[a,n]=He([null,!1]),s=de(async d=>{const u=d.isTrusted?t:d.detail[We];if(typeof u!="function")return;d.preventDefault();const f=new FormData(d.target);n([f,!0]);const o=u(f);o instanceof Promise&&(Lt(o),await o),n([null,!0])},[]),l=he(e.ref,d=>(d.addEventListener("submit",s),()=>{d.removeEventListener("submit",s)})),[i,c]=a;return a[1]=!1,{tag:Ct,props:{value:{pending:i!==null,data:i,method:i?"post":null,action:i?t:null},children:{tag:"form",props:{...r,ref:l},type:"form",ref:l}},f:c}},Ue=(e,{formAction:t,...r})=>{if(typeof t=="function"){const a=de(n=>{n.preventDefault(),n.currentTarget.form.dispatchEvent(new CustomEvent("submit",{detail:{[We]:t}}))},[]);r.ref=he(r.ref,n=>(n.addEventListener("click",a),()=>{n.removeEventListener("click",a)}))}return{tag:e,props:r,type:e,ref:r.ref}},Dt=e=>Ue("input",e),It=e=>Ue("button",e);Object.assign(ie,{title:Pt,script:Tt,style:Nt,link:$t,meta:Mt,form:Rt,input:Dt,button:It});Me(null);new TextEncoder;var Ot=(e,t={})=>{let r;return Object.keys(t).length>0&&console.warn("createRoot options are not supported yet"),{render(a){if(r===null)throw new Error("Cannot update an unmounted root");r?r(a):Et(Be({tag:()=>{const[n,s]=He(a);return r=s,n},props:{}}),e)},unmount(){r==null||r(null),r=null}}},xt=(e,t,r={})=>{const a=Ot(e,r);return a.render(t),a};function qt(){return _e(()=>{const e=document.querySelectorAll("form"),t=[];return e.forEach(r=>{const a=s=>{if(s.defaultPrevented)return;const l=s.submitter;l&&l.type==="submit"&&(l.classList.add("is-loading"),l.disabled=!0)};r.addEventListener("submit",a);const n=s=>{s.persisted&&r.querySelectorAll("button[type=submit]").forEach(i=>{i.classList.remove("is-loading"),i.disabled=!1})};window.addEventListener("pageshow",n),t.push(()=>{r.removeEventListener("submit",a),window.removeEventListener("pageshow",n)})}),()=>{t.forEach(r=>r())}},[]),null}function jt(){return _e(()=>{document.querySelectorAll("[data-password-toggle]").forEach(t=>{const r=t.querySelector("input[type=\'password\'], input[data-password-input]"),a=t.querySelector("[data-password-toggle-btn]"),n=a==null?void 0:a.querySelector("[data-show-icon]"),s=a==null?void 0:a.querySelector("[data-hide-icon]");if(!r||!a||!n||!s)return;const l=c=>{c?(r.type="text",r.setAttribute("data-password-input","text"),n.classList.add("hidden"),s.classList.remove("hidden")):(r.type="password",r.setAttribute("data-password-input","password"),s.classList.add("hidden"),n.classList.remove("hidden"))},i=c=>{c.preventDefault();const d=r.type==="password";l(d)};return a.addEventListener("click",i),()=>{a.removeEventListener("click",i)}})},[]),null}function Bt(){return document.querySelectorAll("[data-input-otp-container]").forEach(t=>{const r=Array.from(t.querySelectorAll("[data-input-otp-slot]"));if(!r.length)return;const a=t.closest("form");let n=null;if(a&&r.length>0){const l=r[0],i=l==null?void 0:l.getAttribute("name");i&&(n=a.querySelector(`input[name="${i}"][type="hidden"]`),n||(n=document.createElement("input"),n.type="hidden",n.name=i,a.appendChild(n)),r.forEach(c=>c.removeAttribute("name")))}const s=()=>{if(n){const l=r.map(i=>i.value).join("");n.value=l,l.length===r.length&&a&&setTimeout(()=>{a.requestSubmit()},100)}};r.forEach((l,i)=>{l.addEventListener("input",c=>{var f;const d=c.target;let u=d.value;u=u.replace(/[^0-9]/g,""),u.length>1&&(u=u.charAt(0)),d.value=u,u&&i<r.length-1&&((f=r[i+1])==null||f.focus()),s()}),l.addEventListener("paste",c=>{var o,h,m;c.preventDefault();const u=(((o=c.clipboardData)==null?void 0:o.getData("text"))||"").replace(/[^0-9]/g,"");for(let v=0;v<Math.min(u.length,r.length-i);v++){const p=r[i+v],y=u.charAt(v);p&&y&&(p.value=y)}const f=r.findIndex((v,p)=>p>=i&&!v.value);f!==-1?(h=r[f])==null||h.focus():(m=r[Math.min(i+u.length,r.length-1)])==null||m.focus(),s()}),l.addEventListener("keydown",c=>{var d,u;if(c.key==="Backspace"){const f=c.target;if(!f.value&&i>0){c.preventDefault();const o=r[i-1];o&&(o.value="",o.focus()),s()}else f.value&&setTimeout(()=>s(),0)}else c.key==="ArrowLeft"&&i>0?(c.preventDefault(),(d=r[i-1])==null||d.focus()):c.key==="ArrowRight"&&i<r.length-1&&(c.preventDefault(),(u=r[i+1])==null||u.focus())}),l.addEventListener("focus",()=>{l.select()})}),s()}),null}const Pe=document.getElementById("client-root");Pe&&xt(Pe,H(ut,{children:[H(qt,{}),H(jt,{}),H(Bt,{})]}));\n',U8=t=>p("div",{className:"rich-text mb-6 prose prose-gray max-w-none [&>*:last-child]:mb-0 [&_h1]:mb-6 [&_h2]:mb-6",dangerouslySetInnerHTML:{__html:t.config.content}},t.id),D8=t=>p("div",{className:"flex items-center gap-2",children:[p("input",{type:"checkbox",name:t.id,required:!!t.required,className:"w-5 h-5 accent-[#4F2D7F] align-middle",id:t.id}),p("span",{className:"text-base leading-tight",children:p("span",{dangerouslySetInnerHTML:{__html:t.config.text}})})]},t.id),M8=t=>{var e;return p("div",{className:"mb-4",children:p("input",{type:"text",name:t.id,placeholder:((e=t.config)==null?void 0:e.placeholder)||"",required:!!t.required,className:"w-full rounded-lg border bg-gray-100 px-4 py-5 text-base placeholder:text-gray-300 dark:bg-gray-600 border-gray-100 dark:border-gray-500",id:t.id})},t.id)};function F8(t){switch(t.type){case"RICH_TEXT":return U8(t);case"LEGAL":return D8(t);case"TEXT":return M8(t);default:return null}}const bl=({theme:t,branding:e,client:n,formName:r,error:i,components:s})=>{const a=s==null?void 0:s.find(d=>d.type==="LEGAL"&&d.required),c=a==null?void 0:a.id,l=s==null?void 0:s.find(d=>d.type==="NEXT_BUTTON");return p(De,{title:r,theme:t,branding:e,client:n,children:[i&&p("div",{className:"mb-4 text-red-500",children:i}),p("div",{className:"flex flex-1 flex-col justify-center",children:p("form",{className:"pt-2",method:"post",children:[c&&p("style",{dangerouslySetInnerHTML:{__html:`
@@ -246,7 +246,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
246
246
  #_legalWrapper:not(:has(#${c}:checked)) #continueBtnDisabled {
247
247
  display: block;
248
248
  }
249
- `}}),p("div",{id:"_legalWrapper",children:[s&&s.map(d=>{if(d.type==="NEXT_BUTTON")return null;const u=F8(d);return u?p("div",{className:d.type==="RICH_TEXT"?"mb-6":"mb-4",children:u},d.id):null}),l&&p("div",{className:"mb-4",children:c?p(Mc,{children:[p(Ue,{id:"continueBtn",className:"sm:mt-4 !text-base w-full",children:[p("span",{children:l.config.text||"Continue"}),p(Ke,{className:"text-xs",name:"arrow-right"})]}),p(Ue,{id:"continueBtnDisabled",className:"sm:mt-4 !text-base w-full opacity-50 cursor-not-allowed",disabled:!0,children:[p("span",{children:l.config.text||"Continue"}),p(Ke,{className:"text-xs",name:"arrow-right"})]})]}):p(Ue,{className:"sm:mt-4 !text-base w-full",children:[p("span",{children:l.config.text||"Continue"}),p(Ke,{className:"text-xs",name:"arrow-right"})]})})]})]})})]})},q8=new o.OpenAPIHono().openapi(o.createRoute({tags:["forms"],method:"get",path:"/:formId/nodes/:nodeId",request:{params:o.z.object({formId:o.z.string(),nodeId:o.z.string()}),query:o.z.object({state:o.z.string()})},responses:{200:{description:"Form node HTML"},404:{description:"Form or node not found"}}}),async t=>{const{formId:e,nodeId:n}=t.req.valid("param"),{state:r}=t.req.valid("query"),{client:i,theme:s,branding:a}=await Ce(t,r,!0),c=await t.env.data.forms.get(i.tenant.id,e);if(!c)throw new S(404,{message:"Form not found"});const l=(c.nodes||[]).find(d=>d.id===n&&d.type==="STEP");if(!l)throw new S(404,{message:"Node not found or not a STEP node"});return t.html(p(bl,{theme:s,branding:a,client:i,state:r,formName:c.name,nodeAlias:l.alias||l.type,components:"components"in l.config?l.config.components:[]}))}).openapi(o.createRoute({tags:["forms"],method:"post",path:"/:formId/nodes/:nodeId",request:{params:o.z.object({formId:o.z.string(),nodeId:o.z.string()}),query:o.z.object({state:o.z.string()}),body:{content:{"application/x-www-form-urlencoded":{schema:o.z.record(o.z.string())}}}},responses:{200:{description:"Form node submitted"},404:{description:"Form or node not found"}}}),async t=>{const{formId:e,nodeId:n}=t.req.valid("param"),{state:r}=t.req.valid("query"),{theme:i,branding:s,client:a}=await Ce(t,r,!0);let c,l,d=[];try{if(c=await t.env.data.forms.get(a.tenant.id,e),!c)throw new S(404,{message:"Form not found"});if(l=(c.nodes||[]).find(A=>A.id===n&&A.type==="STEP"),!l)throw new S(404,{message:"Node not found or not a STEP node"});d="components"in l.config?l.config.components:[];const u=await t.req.parseBody(),f=[],h={};for(const A of d)if(A.type==="LEGAL"){const O=A.id,U=!!A.required,T=u[O];U&&(!T||T==="")?f.push(O):typeof T=="string"&&(h[O]=T)}if(f.length>0)return t.html(p(bl,{theme:i,branding:s,client:a,state:r,formName:c.name,nodeAlias:l.alias||l.type,components:d,error:`Missing required fields: ${f.join(", ")}`}));const m=await t.env.data.loginSessions.get(a.tenant.id,r);if(!m||!m.session_id||!m.authParams)throw new Error("Session expired");const y=await t.env.data.sessions.get(a.tenant.id,m.session_id);if(!y||!y.user_id)throw new Error("Session expired");const v=await t.env.data.users.get(t.var.tenant_id,y.user_id);if(!v)throw new Error("Session expired");return await un(t,{authParams:m.authParams,client:a,user:v,loginSession:m,skipHooks:!0})}catch{return t.html(p(bl,{theme:i,branding:s,client:a,state:r,formName:(c==null?void 0:c.name)||"",nodeAlias:(l==null?void 0:l.alias)||n||"",components:d||[],error:"Your session has expired. Please try again."}))}}),o0=t=>{const{error:e,theme:n,branding:r,user:i,state:s,client:a}=t;return p(De,{title:"Impersonation",theme:n,branding:r,client:a,children:[p("div",{className:"flex flex-1 flex-col justify-center",children:[p("div",{className:"mb-6",children:[p("p",{className:"text-sm text-gray-500 mb-4",children:["Current user: ",p("strong",{children:i.email})]}),p("form",{method:"post",action:`/u/impersonate/continue?state=${encodeURIComponent(s)}`,className:"mb-4",children:p(Ue,{className:"w-full !text-base",children:[p("span",{children:"Continue"}),p(Ke,{className:"text-xs",name:"arrow-right"})]})}),p("details",{className:"mb-4",children:[p("summary",{className:"cursor-pointer text-primary hover:underline mb-4 select-none flex items-center",children:[p("span",{className:"details-arrow mr-2 transition-transform duration-200",children:"▶"}),"Advanced Options"]}),p("div",{className:"mt-4 p-4 border border-gray-200 dark:border-gray-600 rounded-lg bg-gray-50 dark:bg-gray-700",children:p("form",{method:"post",action:`/u/impersonate/switch?state=${encodeURIComponent(s)}`,children:[p("input",{type:"text",id:"user_id",name:"user_id",placeholder:"Enter user ID to impersonate",className:"mb-4 w-full rounded-lg bg-gray-100 px-4 py-3 text-base placeholder:text-gray-300 dark:bg-gray-600 md:text-base",required:!0}),e&&p(et,{children:e}),p(Ue,{variant:"secondary",className:"w-full !text-base",children:[p("span",{children:"Impersonate"}),p(Ke,{className:"text-xs",name:"arrow-right"})]})]})})]})]}),p(It,{state:s})]}),p("style",{children:`
249
+ `}}),p("div",{id:"_legalWrapper",children:[s&&s.map(d=>{if(d.type==="NEXT_BUTTON")return null;const u=F8(d);return u?p("div",{className:d.type==="RICH_TEXT"?"mb-6":"mb-4",children:u},d.id):null}),l&&p("div",{className:"mb-4",children:c?p(Mc,{children:[p(Ue,{id:"continueBtn",className:"sm:mt-4 !text-base w-full",children:[p("span",{children:l.config.text||"Continue"}),p(Ke,{className:"text-xs",name:"arrow-right"})]}),p(Ue,{id:"continueBtnDisabled",className:"sm:mt-4 !text-base w-full opacity-50 cursor-not-allowed",disabled:!0,children:[p("span",{children:l.config.text||"Continue"}),p(Ke,{className:"text-xs",name:"arrow-right"})]})]}):p(Ue,{className:"sm:mt-4 !text-base w-full",children:[p("span",{children:l.config.text||"Continue"}),p(Ke,{className:"text-xs",name:"arrow-right"})]})})]})]})})]})},q8=new o.OpenAPIHono().openapi(o.createRoute({tags:["forms"],method:"get",path:"/:formId/nodes/:nodeId",request:{params:o.z.object({formId:o.z.string(),nodeId:o.z.string()}),query:o.z.object({state:o.z.string()})},responses:{200:{description:"Form node HTML"},404:{description:"Form or node not found"}}}),async t=>{const{formId:e,nodeId:n}=t.req.valid("param"),{state:r}=t.req.valid("query"),{client:i,theme:s,branding:a}=await Ce(t,r,!0),c=await t.env.data.forms.get(i.tenant.id,e);if(!c)throw new S(404,{message:"Form not found"});const l=(c.nodes||[]).find(d=>d.id===n&&d.type==="STEP");if(!l)throw new S(404,{message:"Node not found or not a STEP node"});return t.html(p(bl,{theme:s,branding:a,client:i,state:r,formName:c.name,nodeAlias:l.alias||l.type,components:"components"in l.config?l.config.components:[]}))}).openapi(o.createRoute({tags:["forms"],method:"post",path:"/:formId/nodes/:nodeId",request:{params:o.z.object({formId:o.z.string(),nodeId:o.z.string()}),query:o.z.object({state:o.z.string()}),body:{content:{"application/x-www-form-urlencoded":{schema:o.z.record(o.z.string())}}}},responses:{200:{description:"Form node submitted"},404:{description:"Form or node not found"}}}),async t=>{const{formId:e,nodeId:n}=t.req.valid("param"),{state:r}=t.req.valid("query"),{theme:i,branding:s,client:a}=await Ce(t,r,!0);let c,l,d=[];try{if(c=await t.env.data.forms.get(a.tenant.id,e),!c)throw new S(404,{message:"Form not found"});if(l=(c.nodes||[]).find(A=>A.id===n&&A.type==="STEP"),!l)throw new S(404,{message:"Node not found or not a STEP node"});d="components"in l.config?l.config.components:[];const u=await t.req.parseBody(),f=[],h={};for(const A of d)if(A.type==="LEGAL"){const O=A.id,U=!!A.required,T=u[O];U&&(!T||T==="")?f.push(O):typeof T=="string"&&(h[O]=T)}if(f.length>0)return t.html(p(bl,{theme:i,branding:s,client:a,state:r,formName:c.name,nodeAlias:l.alias||l.type,components:d,error:`Missing required fields: ${f.join(", ")}`}));const m=await t.env.data.loginSessions.get(a.tenant.id,r);if(!m||!m.session_id||!m.authParams)throw new Error("Session expired");const y=await t.env.data.sessions.get(a.tenant.id,m.session_id);if(!y||!y.user_id)throw new Error("Session expired");const v=await t.env.data.users.get(t.var.tenant_id,y.user_id);if(!v)throw new Error("Session expired");return await un(t,{authParams:m.authParams,client:a,user:v,loginSession:m,skipHooks:!0})}catch{return t.html(p(bl,{theme:i,branding:s,client:a,state:r,formName:(c==null?void 0:c.name)||"",nodeAlias:(l==null?void 0:l.alias)||n||"",components:d||[],error:"Your session has expired. Please try again."}))}}),o0=t=>{const{error:e,theme:n,branding:r,user:i,state:s,client:a}=t;return p(De,{title:"Impersonation",theme:n,branding:r,client:a,children:[p("div",{className:"flex flex-1 flex-col justify-center",children:[p("div",{className:"mb-6",children:[p("p",{className:"text-sm text-gray-500 mb-4",children:["Current user: ",p("strong",{children:i.email})]}),p("form",{method:"post",action:`/u/impersonate/continue?state=${encodeURIComponent(s)}`,className:"mb-4",children:p(Ue,{className:"w-full !text-base",children:[p("span",{children:"Continue"}),p(Ke,{className:"text-xs",name:"arrow-right"})]})}),p("details",{className:"mb-4",children:[p("summary",{className:"cursor-pointer text-primary hover:underline mb-4 select-none flex items-center",children:[p("span",{className:"details-arrow mr-2 transition-transform duration-200",children:"▶"}),"Advanced Options"]}),p("div",{className:"mt-4 p-4 border border-gray-200 dark:border-gray-600 rounded-lg bg-gray-50 dark:bg-gray-700",children:p("form",{method:"post",action:`/u/impersonate/switch?state=${encodeURIComponent(s)}`,children:[p("input",{type:"text",id:"user_id",name:"user_id",placeholder:"Enter user ID to impersonate",className:"mb-4 w-full rounded-lg bg-gray-100 px-4 py-3 text-base placeholder:text-gray-300 dark:bg-gray-600 md:text-base",required:!0}),e&&p(et,{children:e}),p(Ue,{variant:"secondary",className:"w-full !text-base",children:[p("span",{children:"Impersonate"}),p(Ke,{className:"text-xs",name:"arrow-right"})]})]})})]})]}),p(Nt,{state:s})]}),p("style",{children:`
250
250
  details[open] .details-arrow {
251
251
  transform: rotate(90deg);
252
252
  }
@@ -259,13 +259,13 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
259
259
  details > summary::-webkit-details-marker {
260
260
  display: none;
261
261
  }
262
- `})]})},s0=({error:t,theme:e,branding:n,state:r,user:i,className:s})=>{var z,k,$,I,L,q,F,Z,se,D,fe,$e,ce,ue,Ae,Ee,Re,Se,Te,Be,Ge;const a=((z=e==null?void 0:e.colors)==null?void 0:z.primary_button)||((k=n==null?void 0:n.colors)==null?void 0:k.primary)||"#0066cc",c=(($=e==null?void 0:e.colors)==null?void 0:$.primary_button_label)||"#ffffff",l=((I=e==null?void 0:e.colors)==null?void 0:I.body_text)||"#333333",d=((L=e==null?void 0:e.colors)==null?void 0:L.input_border)||"#d1d5db",u=((q=e==null?void 0:e.colors)==null?void 0:q.widget_background)||"#ffffff",f=((F=e==null?void 0:e.colors)==null?void 0:F.widget_border)||"#e5e7eb",h=((Z=e==null?void 0:e.borders)==null?void 0:Z.widget_corner_radius)||8,m=((se=e==null?void 0:e.borders)==null?void 0:se.button_border_radius)||4,y=((D=e==null?void 0:e.borders)==null?void 0:D.show_widget_shadow)??!0,v=(($e=(fe=e==null?void 0:e.fonts)==null?void 0:fe.title)==null?void 0:$e.size)||24,b=((ue=(ce=e==null?void 0:e.fonts)==null?void 0:ce.title)==null?void 0:ue.bold)??!0,A=((Ee=(Ae=e==null?void 0:e.fonts)==null?void 0:Ae.body_text)==null?void 0:Ee.size)||14,O={backgroundColor:u,borderColor:f,borderRadius:`${h}px`,boxShadow:y?"0 1px 3px 0 rgba(0, 0, 0, 0.1)":"none",color:l},U={fontSize:`${v}px`,fontWeight:b?"700":"400",color:((Re=e==null?void 0:e.colors)==null?void 0:Re.header)||l},T={fontSize:`${A}px`,color:((Se=e==null?void 0:e.colors)==null?void 0:Se.input_labels_placeholders)||"#6b7280"},R={backgroundColor:a,color:c,borderRadius:`${m}px`},W={backgroundColor:"transparent",color:l,borderColor:d,borderRadius:`${m}px`},ne={color:((Te=e==null?void 0:e.colors)==null?void 0:Te.links_focused_components)||a,fontSize:`${A}px`},Q={borderColor:d,borderRadius:`${m}px`,fontSize:`${A}px`,color:l},K=((Be=e==null?void 0:e.widget)==null?void 0:Be.logo_position)||"center",de=K==="left"?"text-left":K==="right"?"text-right":"text-center",N=((Ge=e==null?void 0:e.widget)==null?void 0:Ge.logo_url)||(n==null?void 0:n.logo_url),C=K!=="none"&&N;return p("div",{className:ge("flex flex-col gap-6 w-full max-w-sm",s),children:p(_n,{style:O,className:"border",children:[p(yn,{children:[C&&p("div",{className:ge("mb-4",de),children:p(rn,{theme:e,branding:n})}),p(wn,{style:U,children:w.t("impersonation","Impersonation")}),p(vn,{style:T,children:w.t("impersonation_description","You have permission to impersonate other users.")})]}),p(bn,{children:p("div",{className:"space-y-4",children:[p("div",{className:"p-3 bg-gray-50 dark:bg-gray-800 rounded-md",children:[p("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-1",children:[w.t("current_user","Current user"),":"]}),p("p",{className:"font-semibold",style:{fontSize:`${A}px`},children:i.email})]}),p("form",{method:"post",action:`/u/impersonate/continue?state=${encodeURIComponent(r)}`,children:p(fn,{type:"submit",className:"w-full transition-colors hover:brightness-90",style:R,children:w.t("continue","Continue")})}),p("div",{className:"relative",children:[p("div",{className:"absolute inset-0 flex items-center","aria-hidden":"true",children:p("div",{className:"w-full border-t",style:{borderColor:f}})}),p("div",{className:"relative flex justify-center text-xs uppercase",children:p("span",{className:"px-2",style:{backgroundColor:u,...T},children:w.t("or","Or")})})]}),p("details",{className:"group",children:[p("summary",{className:"cursor-pointer select-none flex items-center justify-between p-3 rounded-md hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors",style:ne,children:[p("span",{className:"font-medium",children:w.t("advanced_options","Advanced Options")}),p("svg",{className:"w-5 h-5 transition-transform group-open:rotate-90",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:p("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})]}),p("div",{className:"mt-3 p-4 border rounded-md",style:{borderColor:f},children:p("form",{method:"post",action:`/u/impersonate/switch?state=${encodeURIComponent(r)}`,children:p("div",{className:"space-y-4",children:[p("div",{className:"space-y-2",children:[p(Lt,{htmlFor:"user_id",style:T,children:w.t("user_id_to_impersonate","User ID to Impersonate")}),p(Qt,{type:"text",id:"user_id",name:"user_id",placeholder:w.t("enter_user_id","Enter user ID"),required:!0,style:Q,className:"w-full"}),t&&p(et,{children:t})]}),p(fn,{type:"submit",variant:"outline",className:"w-full transition-colors border",style:W,children:w.t("impersonate_user","Impersonate User")})]})})})]})]})}),p(N1,{children:p("a",{href:`/u/login/identifier?state=${encodeURIComponent(r)}`,className:"text-sm hover:underline focus:outline-none focus:ring-2 focus:ring-offset-2 transition-colors w-full text-center",style:ne,children:w.t("go_back","Go back")})})]})})},H8=new o.OpenAPIHono().openapi(o.createRoute({tags:["impersonation"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{200:{description:"Impersonation page"},400:{description:"Bad Request"}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,client:i,loginSession:s,useShadcn:a}=await Ce(t,e,!0);if(!s.session_id)throw new S(400,{message:"No session linked to login session"});const c=await t.env.data.sessions.get(i.tenant.id,s.session_id);if(!c)throw new S(400,{message:"Session not found"});const l=await t.env.data.users.get(i.tenant.id,c.user_id);if(!l)throw new S(400,{message:"User not found"});return(await t.env.data.userPermissions.list(i.tenant.id,l.user_id)).some(f=>f.permission_name==="users:impersonate")?a?t.html(p(Oe,{title:w.t("impersonation","Impersonation"),theme:n,branding:r,client:i,children:p(s0,{theme:n,branding:r,client:i,user:l,state:e})})):t.html(p(o0,{theme:n,branding:r,client:i,user:l,state:e})):t.html(p(Dt,{theme:n,branding:r,client:i,state:e,pageTitle:"Access Denied",message:"You do not have permission to impersonate other users."}),403)}).openapi(o.createRoute({tags:["impersonation"],method:"post",path:"/continue",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{302:{description:"Redirect to continue authentication flow",headers:o.z.object({Location:o.z.string().url()})}}}),async t=>{const{state:e}=t.req.valid("query"),{client:n,loginSession:r}=await Ce(t,e,!0);if(!r.session_id)throw new S(400,{message:"No session linked to login session"});const i=await t.env.data.sessions.get(n.tenant.id,r.session_id);if(!i)throw new S(400,{message:"Session not found"});const s=await t.env.data.users.get(n.tenant.id,i.user_id);if(!s)throw new S(400,{message:"User not found"});if(!(await t.env.data.userPermissions.list(n.tenant.id,s.user_id)).some(l=>l.permission_name==="users:impersonate"))throw new S(403,{message:"Access denied: insufficient permissions"});return un(t,{client:n,authParams:r.authParams,loginSession:r,user:s,sessionId:i.id,skipHooks:!0})}).openapi(o.createRoute({tags:["impersonation"],method:"post",path:"/switch",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})}),body:{content:{"application/x-www-form-urlencoded":{schema:o.z.object({user_id:o.z.string().min(1,"User ID is required")})}}}},responses:{302:{description:"Redirect to continue authentication flow as impersonated user",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - User not found or impersonation failed"}}}),async t=>{const{state:e}=t.req.valid("query"),{user_id:n}=t.req.valid("form"),{theme:r,branding:i,client:s,loginSession:a,useShadcn:c}=await Ce(t,e,!0);if(!a.session_id)throw new S(400,{message:"No session linked to login session"});const l=await t.env.data.sessions.get(s.tenant.id,a.session_id);if(!l)throw new S(400,{message:"Current session not found"});const d=await t.env.data.users.get(s.tenant.id,l.user_id);if(!d)throw new S(400,{message:"Current user not found"});if(!(await t.env.data.userPermissions.list(s.tenant.id,d.user_id)).some(y=>y.permission_name==="users:impersonate"))return t.html(p(Dt,{theme:r,branding:i,client:s,state:e,pageTitle:"Access Denied",message:"You do not have permission to impersonate other users."}),403);const h=await t.env.data.users.get(s.tenant.id,n);if(!h)return c?t.html(p(Oe,{title:w.t("impersonation","Impersonation"),theme:r,branding:i,client:s,children:p(s0,{theme:r,branding:i,client:s,user:d,state:e,error:`User with ID "${n}" not found.`})}),400):t.html(p(o0,{theme:r,branding:i,client:s,user:d,state:e,error:`User with ID "${n}" not found.`}),400);await t.env.data.sessions.update(s.tenant.id,l.id,{user_id:h.user_id});const m=be(t,{type:_e.SUCCESS_LOGIN,description:`${h.email||h.user_id} (impersonated by ${d.email||d.user_id})`,userId:h.user_id,connection:h.connection,strategy:h.connection,strategy_type:h.is_social?"social":"database"});return ve(t,t.env.data.logs.create(s.tenant.id,m)),un(t,{client:s,authParams:{...a.authParams,response_type:Nt.TOKEN_ID_TOKEN,response_mode:Wt.QUERY},loginSession:a,user:h,sessionId:l.id,skipHooks:!0,impersonatingUser:d})});function V8(t){const e=new o.OpenAPIHono,n=t.dataAdapter.cache||Ho({defaultTtlSeconds:0,maxEntries:100,cleanupIntervalMs:0}),r=t.dataAdapter.cache?300:0;e.onError((s,a)=>s instanceof Ir?a.redirect(s.location,s.status):s instanceof S?a.text(s.message||"Error",s.status):a.text("Unexpected error",500)),e.get("/css/tailwind.css",async s=>{const a=Fp;return s.text(a,200,{"content-type":"text/css; charset=utf-8"})}),e.get("/js/client.js",async s=>s.text(L8,200,{"content-type":"application/javascript; charset=utf-8"})),e.use(async(s,a)=>{const c=xo(s,t.dataAdapter),l=Dc(c,{defaultTtl:r,cacheEntities:["tenants","connections","clients","legacyClients","customDomains","resourceServers","roles","organizations","userRoles","userPermissions","branding","themes","promptSettings","forms"],cache:n});return s.env.data=Rc(s,l),a()}).use(Uc).use(Lc);const i=e.route("/info",O8).route("/check-account",x8).route("/account",A8).route("/account/change-email",E8).route("/account/change-email-verify",C8).route("/account/change-email-confirmation",N8).route("/login/identifier",Mx).route("/enter-code",f8).route("/enter-password",y8).route("/invalid-session",j8).route("/pre-signup",I8).route("/pre-signup-sent",R8).route("/reset-password",v8).route("/forgot-password",$8).route("/validate-email",P8).route("/signup",w8).route("/impersonate",H8).route("/forms",q8);return i.doc("/u/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"Universal login"}}),i}var K8=Object.defineProperty,G8=(t,e,n)=>e in t?K8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ei=(t,e,n)=>G8(t,typeof e!="symbol"?e+"":e,n);const pt=o.z.object({"#text":o.z.string()}),W8=o.z.object({"#text":o.z.string(),"@_xmlns:saml":o.z.string().optional()}),J8=o.z.object({"samlp:AuthnRequest":o.z.object({"saml:Issuer":W8,"@_xmlns:samlp":o.z.string(),"@_xmlns:saml":o.z.string().optional(),"@_ForceAuthn":o.z.string().transform(t=>t.toLowerCase()==="true").optional(),"@_ID":o.z.string(),"@_IssueInstant":o.z.string().datetime(),"@_Destination":o.z.string().url(),"@_AssertionConsumerServiceURL":o.z.string().url().optional(),"@_ProtocolBinding":o.z.string().optional(),"@_Version":o.z.string()})});o.z.array(o.z.object({":@":o.z.object({"@_xmlns":o.z.string(),"@_entityID":o.z.string()}),EntityDescriptor:o.z.array(o.z.object({":@":o.z.object({"@_protocolSupportEnumeration":o.z.string()}),IDPSSODescriptor:o.z.array(o.z.union([o.z.object({KeyDescriptor:o.z.array(o.z.object({KeyInfo:o.z.array(o.z.object({X509Data:o.z.array(o.z.object({X509Certificate:o.z.array(pt)}))})),":@":o.z.object({"@_xmlns":o.z.string()})})),":@":o.z.object({"@_use":o.z.string()})}),o.z.object({SingleLogoutService:o.z.array(o.z.object({})),":@":o.z.object({"@_Binding":o.z.string(),"@_Location":o.z.string()})}),o.z.object({NameIDFormat:o.z.array(pt)}),o.z.object({SingleSignOnService:o.z.array(o.z.object({})),":@":o.z.object({"@_Binding":o.z.string(),"@_Location":o.z.string()})}),o.z.object({Attribute:o.z.array(o.z.object({})),":@":o.z.object({"@_Name":o.z.string(),"@_NameFormat":o.z.string(),"@_FriendlyName":o.z.string(),"@_xmlns":o.z.string()})})]))}))}));const X8=o.z.object({"saml:Attribute":o.z.array(o.z.object({"saml:AttributeValue":o.z.array(o.z.object({"#text":o.z.string()})),":@":o.z.object({"@_xmlns:xs":o.z.string().optional(),"@_xmlns:xsi":o.z.string(),"@_xsi:type":o.z.string()}).optional()})),":@":o.z.object({"@_Name":o.z.string(),"@_NameFormat":o.z.string(),"@_FriendlyName":o.z.string().optional()})}),Z8=o.z.object({"ds:Transform":o.z.array(o.z.any()),":@":o.z.object({"@_Algorithm":o.z.string()})}),a0=o.z.object({"ds:Signature":o.z.array(o.z.union([o.z.object({"ds:SignedInfo":o.z.array(o.z.union([o.z.object({"ds:CanonicalizationMethod":o.z.array(o.z.object({":@":o.z.object({"@_Algorithm":o.z.string()})}))}),o.z.object({"ds:SignatureMethod":o.z.array(o.z.object({":@":o.z.object({"@_Algorithm":o.z.string()})}))}),o.z.object({"ds:Reference":o.z.array(o.z.union([o.z.object({"ds:Transforms":o.z.array(Z8)}),o.z.object({"ds:DigestMethod":o.z.array(o.z.object({":@":o.z.object({"@_Algorithm":o.z.string()})}))}),o.z.object({"ds:DigestValue":o.z.array(pt)})])),":@":o.z.object({"@_URI":o.z.string().optional()}).optional()})]))}),o.z.object({"ds:SignatureValue":o.z.array(pt)}),o.z.object({"ds:KeyInfo":o.z.array(o.z.union([o.z.object({"ds:KeyValue":o.z.array(o.z.object({"ds:RSAKeyValue":o.z.array(o.z.union([o.z.object({"ds:Modulus":o.z.array(pt)}),o.z.object({"ds:Exponent":o.z.array(pt)})]))}))}),o.z.object({"ds:X509Data":o.z.array(o.z.object({"ds:X509Certificate":o.z.array(pt)}))}),o.z.object({"ds:KeyValue":o.z.array(o.z.object({"ds:RSAKeyValue":o.z.array(o.z.union([o.z.object({"ds:Modulus":o.z.array(pt)}),o.z.object({"ds:Exponent":o.z.array(pt)})]))})),"ds:X509Data":o.z.array(o.z.object({"ds:X509Certificate":o.z.array(pt)}))})]))})])),":@":o.z.object({"@_xmlns:ds":o.z.string().optional()}).optional()});o.z.array(o.z.object({"samlp:Response":o.z.array(o.z.union([o.z.object({"saml:Issuer":o.z.array(pt)}),a0,o.z.object({"samlp:Status":o.z.array(o.z.object({"samlp:StatusCode":o.z.array(pt),":@":o.z.object({"@_Value":o.z.string()})}))}),o.z.object({"saml:Assertion":o.z.array(o.z.union([o.z.object({"saml:Issuer":o.z.array(pt)}),a0,o.z.object({"saml:Subject":o.z.array(o.z.union([o.z.object({"saml:NameID":o.z.array(pt),":@":o.z.object({"@_Format":o.z.string()})}),o.z.object({"saml:SubjectConfirmation":o.z.array(o.z.object({"saml:SubjectConfirmationData":o.z.array(o.z.any()),":@":o.z.object({"@_InResponseTo":o.z.string(),"@_NotOnOrAfter":o.z.string(),"@_Recipient":o.z.string()})})),":@":o.z.object({"@_Method":o.z.string()})})]))}),o.z.object({"saml:Conditions":o.z.array(o.z.object({"saml:AudienceRestriction":o.z.array(o.z.object({"saml:Audience":o.z.array(pt)}))})),":@":o.z.object({"@_NotBefore":o.z.string(),"@_NotOnOrAfter":o.z.string()})}),o.z.object({"saml:AuthnStatement":o.z.array(o.z.object({"saml:AuthnContext":o.z.array(o.z.object({"saml:AuthnContextClassRef":o.z.array(pt)}))})),":@":o.z.object({"@_AuthnInstant":o.z.string(),"@_SessionIndex":o.z.string(),"@_SessionNotOnOrAfter":o.z.string()})}),o.z.object({"saml:AttributeStatement":o.z.array(X8)})])),":@":o.z.object({"@_xmlns":o.z.string(),"@_ID":o.z.string(),"@_IssueInstant":o.z.string(),"@_Version":o.z.string()})})])),":@":o.z.object({"@_xmlns:samlp":o.z.string(),"@_xmlns:saml":o.z.string(),"@_Destination":o.z.string(),"@_ID":o.z.string(),"@_InResponseTo":o.z.string(),"@_IssueInstant":o.z.string(),"@_Version":o.z.string()})}));var qp={},Kc={};(function(t){const e=":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD",n=e+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040",r="["+e+"]["+n+"]*",i=new RegExp("^"+r+"$"),s=function(c,l){const d=[];let u=l.exec(c);for(;u;){const f=[];f.startIndex=l.lastIndex-u[0].length;const h=u.length;for(let m=0;m<h;m++)f.push(u[m]);d.push(f),u=l.exec(c)}return d},a=function(c){const l=i.exec(c);return!(l===null||typeof l>"u")};t.isExist=function(c){return typeof c<"u"},t.isEmptyObject=function(c){return Object.keys(c).length===0},t.merge=function(c,l,d){if(l){const u=Object.keys(l),f=u.length;for(let h=0;h<f;h++)d==="strict"?c[u[h]]=[l[u[h]]]:c[u[h]]=l[u[h]]}},t.getValue=function(c){return t.isExist(c)?c:""},t.isName=a,t.getAllMatches=s,t.nameRegexp=r})(Kc);const Hp=Kc,Y8={allowBooleanAttributes:!1,unpairedTags:[]};qp.validate=function(t,e){e=Object.assign({},Y8,e);const n=[];let r=!1,i=!1;t[0]==="\uFEFF"&&(t=t.substr(1));for(let s=0;s<t.length;s++)if(t[s]==="<"&&t[s+1]==="?"){if(s+=2,s=l0(t,s),s.err)return s}else if(t[s]==="<"){let a=s;if(s++,t[s]==="!"){s=d0(t,s);continue}else{let c=!1;t[s]==="/"&&(c=!0,s++);let l="";for(;s<t.length&&t[s]!==">"&&t[s]!==" "&&t[s]!==" "&&t[s]!==`
262
+ `})]})},s0=({error:t,theme:e,branding:n,state:r,user:i,className:s})=>{var z,k,$,I,L,q,F,Z,se,D,fe,$e,ce,ue,Ae,Ee,Re,Se,Te,Be,Ge;const a=((z=e==null?void 0:e.colors)==null?void 0:z.primary_button)||((k=n==null?void 0:n.colors)==null?void 0:k.primary)||"#0066cc",c=(($=e==null?void 0:e.colors)==null?void 0:$.primary_button_label)||"#ffffff",l=((I=e==null?void 0:e.colors)==null?void 0:I.body_text)||"#333333",d=((L=e==null?void 0:e.colors)==null?void 0:L.input_border)||"#d1d5db",u=((q=e==null?void 0:e.colors)==null?void 0:q.widget_background)||"#ffffff",f=((F=e==null?void 0:e.colors)==null?void 0:F.widget_border)||"#e5e7eb",h=((Z=e==null?void 0:e.borders)==null?void 0:Z.widget_corner_radius)||8,m=((se=e==null?void 0:e.borders)==null?void 0:se.button_border_radius)||4,y=((D=e==null?void 0:e.borders)==null?void 0:D.show_widget_shadow)??!0,v=(($e=(fe=e==null?void 0:e.fonts)==null?void 0:fe.title)==null?void 0:$e.size)||24,b=((ue=(ce=e==null?void 0:e.fonts)==null?void 0:ce.title)==null?void 0:ue.bold)??!0,A=((Ee=(Ae=e==null?void 0:e.fonts)==null?void 0:Ae.body_text)==null?void 0:Ee.size)||14,O={backgroundColor:u,borderColor:f,borderRadius:`${h}px`,boxShadow:y?"0 1px 3px 0 rgba(0, 0, 0, 0.1)":"none",color:l},U={fontSize:`${v}px`,fontWeight:b?"700":"400",color:((Re=e==null?void 0:e.colors)==null?void 0:Re.header)||l},T={fontSize:`${A}px`,color:((Se=e==null?void 0:e.colors)==null?void 0:Se.input_labels_placeholders)||"#6b7280"},R={backgroundColor:a,color:c,borderRadius:`${m}px`},W={backgroundColor:"transparent",color:l,borderColor:d,borderRadius:`${m}px`},ne={color:((Te=e==null?void 0:e.colors)==null?void 0:Te.links_focused_components)||a,fontSize:`${A}px`},Q={borderColor:d,borderRadius:`${m}px`,fontSize:`${A}px`,color:l},K=((Be=e==null?void 0:e.widget)==null?void 0:Be.logo_position)||"center",de=K==="left"?"text-left":K==="right"?"text-right":"text-center",N=((Ge=e==null?void 0:e.widget)==null?void 0:Ge.logo_url)||(n==null?void 0:n.logo_url),C=K!=="none"&&N;return p("div",{className:ge("flex flex-col gap-6 w-full max-w-sm",s),children:p(_n,{style:O,className:"border",children:[p(yn,{children:[C&&p("div",{className:ge("mb-4",de),children:p(nn,{theme:e,branding:n})}),p(wn,{style:U,children:w.t("impersonation","Impersonation")}),p(vn,{style:T,children:w.t("impersonation_description","You have permission to impersonate other users.")})]}),p(bn,{children:p("div",{className:"space-y-4",children:[p("div",{className:"p-3 bg-gray-50 dark:bg-gray-800 rounded-md",children:[p("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-1",children:[w.t("current_user","Current user"),":"]}),p("p",{className:"font-semibold",style:{fontSize:`${A}px`},children:i.email})]}),p("form",{method:"post",action:`/u/impersonate/continue?state=${encodeURIComponent(r)}`,children:p(fn,{type:"submit",className:"w-full transition-colors hover:brightness-90",style:R,children:w.t("continue","Continue")})}),p("div",{className:"relative",children:[p("div",{className:"absolute inset-0 flex items-center","aria-hidden":"true",children:p("div",{className:"w-full border-t",style:{borderColor:f}})}),p("div",{className:"relative flex justify-center text-xs uppercase",children:p("span",{className:"px-2",style:{backgroundColor:u,...T},children:w.t("or","Or")})})]}),p("details",{className:"group",children:[p("summary",{className:"cursor-pointer select-none flex items-center justify-between p-3 rounded-md hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors",style:ne,children:[p("span",{className:"font-medium",children:w.t("advanced_options","Advanced Options")}),p("svg",{className:"w-5 h-5 transition-transform group-open:rotate-90",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:p("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})]}),p("div",{className:"mt-3 p-4 border rounded-md",style:{borderColor:f},children:p("form",{method:"post",action:`/u/impersonate/switch?state=${encodeURIComponent(r)}`,children:p("div",{className:"space-y-4",children:[p("div",{className:"space-y-2",children:[p(Lt,{htmlFor:"user_id",style:T,children:w.t("user_id_to_impersonate","User ID to Impersonate")}),p(Yt,{type:"text",id:"user_id",name:"user_id",placeholder:w.t("enter_user_id","Enter user ID"),required:!0,style:Q,className:"w-full"}),t&&p(et,{children:t})]}),p(fn,{type:"submit",variant:"outline",className:"w-full transition-colors border",style:W,children:w.t("impersonate_user","Impersonate User")})]})})})]})]})}),p(N1,{children:p("a",{href:`/u/login/identifier?state=${encodeURIComponent(r)}`,className:"text-sm hover:underline focus:outline-none focus:ring-2 focus:ring-offset-2 transition-colors w-full text-center",style:ne,children:w.t("go_back","Go back")})})]})})},H8=new o.OpenAPIHono().openapi(o.createRoute({tags:["impersonation"],method:"get",path:"/",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{200:{description:"Impersonation page"},400:{description:"Bad Request"}}}),async t=>{const{state:e}=t.req.valid("query"),{theme:n,branding:r,client:i,loginSession:s,useShadcn:a}=await Ce(t,e,!0);if(!s.session_id)throw new S(400,{message:"No session linked to login session"});const c=await t.env.data.sessions.get(i.tenant.id,s.session_id);if(!c)throw new S(400,{message:"Session not found"});const l=await t.env.data.users.get(i.tenant.id,c.user_id);if(!l)throw new S(400,{message:"User not found"});return(await t.env.data.userPermissions.list(i.tenant.id,l.user_id)).some(f=>f.permission_name==="users:impersonate")?a?t.html(p(Oe,{title:w.t("impersonation","Impersonation"),theme:n,branding:r,client:i,children:p(s0,{theme:n,branding:r,client:i,user:l,state:e})})):t.html(p(o0,{theme:n,branding:r,client:i,user:l,state:e})):t.html(p(Dt,{theme:n,branding:r,client:i,state:e,pageTitle:"Access Denied",message:"You do not have permission to impersonate other users."}),403)}).openapi(o.createRoute({tags:["impersonation"],method:"post",path:"/continue",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})})},responses:{302:{description:"Redirect to continue authentication flow",headers:o.z.object({Location:o.z.string().url()})}}}),async t=>{const{state:e}=t.req.valid("query"),{client:n,loginSession:r}=await Ce(t,e,!0);if(!r.session_id)throw new S(400,{message:"No session linked to login session"});const i=await t.env.data.sessions.get(n.tenant.id,r.session_id);if(!i)throw new S(400,{message:"Session not found"});const s=await t.env.data.users.get(n.tenant.id,i.user_id);if(!s)throw new S(400,{message:"User not found"});if(!(await t.env.data.userPermissions.list(n.tenant.id,s.user_id)).some(l=>l.permission_name==="users:impersonate"))throw new S(403,{message:"Access denied: insufficient permissions"});return un(t,{client:n,authParams:r.authParams,loginSession:r,user:s,sessionId:i.id,skipHooks:!0})}).openapi(o.createRoute({tags:["impersonation"],method:"post",path:"/switch",request:{query:o.z.object({state:o.z.string().openapi({description:"The state parameter from the authorization request"})}),body:{content:{"application/x-www-form-urlencoded":{schema:o.z.object({user_id:o.z.string().min(1,"User ID is required")})}}}},responses:{302:{description:"Redirect to continue authentication flow as impersonated user",headers:o.z.object({Location:o.z.string().url()})},400:{description:"Bad Request - User not found or impersonation failed"}}}),async t=>{const{state:e}=t.req.valid("query"),{user_id:n}=t.req.valid("form"),{theme:r,branding:i,client:s,loginSession:a,useShadcn:c}=await Ce(t,e,!0);if(!a.session_id)throw new S(400,{message:"No session linked to login session"});const l=await t.env.data.sessions.get(s.tenant.id,a.session_id);if(!l)throw new S(400,{message:"Current session not found"});const d=await t.env.data.users.get(s.tenant.id,l.user_id);if(!d)throw new S(400,{message:"Current user not found"});if(!(await t.env.data.userPermissions.list(s.tenant.id,d.user_id)).some(y=>y.permission_name==="users:impersonate"))return t.html(p(Dt,{theme:r,branding:i,client:s,state:e,pageTitle:"Access Denied",message:"You do not have permission to impersonate other users."}),403);const h=await t.env.data.users.get(s.tenant.id,n);if(!h)return c?t.html(p(Oe,{title:w.t("impersonation","Impersonation"),theme:r,branding:i,client:s,children:p(s0,{theme:r,branding:i,client:s,user:d,state:e,error:`User with ID "${n}" not found.`})}),400):t.html(p(o0,{theme:r,branding:i,client:s,user:d,state:e,error:`User with ID "${n}" not found.`}),400);await t.env.data.sessions.update(s.tenant.id,l.id,{user_id:h.user_id});const m=be(t,{type:_e.SUCCESS_LOGIN,description:`${h.email||h.user_id} (impersonated by ${d.email||d.user_id})`,userId:h.user_id,connection:h.connection,strategy:h.connection,strategy_type:h.is_social?"social":"database"});return ve(t,t.env.data.logs.create(s.tenant.id,m)),un(t,{client:s,authParams:a.authParams,loginSession:a,user:h,sessionId:l.id,skipHooks:!0,impersonatingUser:d})});function V8(t){const e=new o.OpenAPIHono,n=t.dataAdapter.cache||Ho({defaultTtlSeconds:0,maxEntries:100,cleanupIntervalMs:0}),r=t.dataAdapter.cache?300:0;e.onError((s,a)=>s instanceof Ir?a.redirect(s.location,s.status):s instanceof S?a.text(s.message||"Error",s.status):a.text("Unexpected error",500)),e.get("/css/tailwind.css",async s=>{const a=Fp;return s.text(a,200,{"content-type":"text/css; charset=utf-8"})}),e.get("/js/client.js",async s=>s.text(L8,200,{"content-type":"application/javascript; charset=utf-8"})),e.use(async(s,a)=>{const c=xo(s,t.dataAdapter),l=Dc(c,{defaultTtl:r,cacheEntities:["tenants","connections","clients","legacyClients","customDomains","resourceServers","roles","organizations","userRoles","userPermissions","branding","themes","promptSettings","forms"],cache:n});return s.env.data=Rc(s,l),a()}).use(Uc).use(Lc);const i=e.route("/info",O8).route("/check-account",x8).route("/account",A8).route("/account/change-email",E8).route("/account/change-email-verify",C8).route("/account/change-email-confirmation",N8).route("/login/identifier",Mx).route("/enter-code",f8).route("/enter-password",y8).route("/invalid-session",j8).route("/pre-signup",I8).route("/pre-signup-sent",R8).route("/reset-password",v8).route("/forgot-password",$8).route("/validate-email",P8).route("/signup",w8).route("/impersonate",H8).route("/forms",q8);return i.doc("/u/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"Universal login"}}),i}var K8=Object.defineProperty,G8=(t,e,n)=>e in t?K8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ei=(t,e,n)=>G8(t,typeof e!="symbol"?e+"":e,n);const pt=o.z.object({"#text":o.z.string()}),W8=o.z.object({"#text":o.z.string(),"@_xmlns:saml":o.z.string().optional()}),J8=o.z.object({"samlp:AuthnRequest":o.z.object({"saml:Issuer":W8,"@_xmlns:samlp":o.z.string(),"@_xmlns:saml":o.z.string().optional(),"@_ForceAuthn":o.z.string().transform(t=>t.toLowerCase()==="true").optional(),"@_ID":o.z.string(),"@_IssueInstant":o.z.string().datetime(),"@_Destination":o.z.string().url(),"@_AssertionConsumerServiceURL":o.z.string().url().optional(),"@_ProtocolBinding":o.z.string().optional(),"@_Version":o.z.string()})});o.z.array(o.z.object({":@":o.z.object({"@_xmlns":o.z.string(),"@_entityID":o.z.string()}),EntityDescriptor:o.z.array(o.z.object({":@":o.z.object({"@_protocolSupportEnumeration":o.z.string()}),IDPSSODescriptor:o.z.array(o.z.union([o.z.object({KeyDescriptor:o.z.array(o.z.object({KeyInfo:o.z.array(o.z.object({X509Data:o.z.array(o.z.object({X509Certificate:o.z.array(pt)}))})),":@":o.z.object({"@_xmlns":o.z.string()})})),":@":o.z.object({"@_use":o.z.string()})}),o.z.object({SingleLogoutService:o.z.array(o.z.object({})),":@":o.z.object({"@_Binding":o.z.string(),"@_Location":o.z.string()})}),o.z.object({NameIDFormat:o.z.array(pt)}),o.z.object({SingleSignOnService:o.z.array(o.z.object({})),":@":o.z.object({"@_Binding":o.z.string(),"@_Location":o.z.string()})}),o.z.object({Attribute:o.z.array(o.z.object({})),":@":o.z.object({"@_Name":o.z.string(),"@_NameFormat":o.z.string(),"@_FriendlyName":o.z.string(),"@_xmlns":o.z.string()})})]))}))}));const X8=o.z.object({"saml:Attribute":o.z.array(o.z.object({"saml:AttributeValue":o.z.array(o.z.object({"#text":o.z.string()})),":@":o.z.object({"@_xmlns:xs":o.z.string().optional(),"@_xmlns:xsi":o.z.string(),"@_xsi:type":o.z.string()}).optional()})),":@":o.z.object({"@_Name":o.z.string(),"@_NameFormat":o.z.string(),"@_FriendlyName":o.z.string().optional()})}),Z8=o.z.object({"ds:Transform":o.z.array(o.z.any()),":@":o.z.object({"@_Algorithm":o.z.string()})}),a0=o.z.object({"ds:Signature":o.z.array(o.z.union([o.z.object({"ds:SignedInfo":o.z.array(o.z.union([o.z.object({"ds:CanonicalizationMethod":o.z.array(o.z.object({":@":o.z.object({"@_Algorithm":o.z.string()})}))}),o.z.object({"ds:SignatureMethod":o.z.array(o.z.object({":@":o.z.object({"@_Algorithm":o.z.string()})}))}),o.z.object({"ds:Reference":o.z.array(o.z.union([o.z.object({"ds:Transforms":o.z.array(Z8)}),o.z.object({"ds:DigestMethod":o.z.array(o.z.object({":@":o.z.object({"@_Algorithm":o.z.string()})}))}),o.z.object({"ds:DigestValue":o.z.array(pt)})])),":@":o.z.object({"@_URI":o.z.string().optional()}).optional()})]))}),o.z.object({"ds:SignatureValue":o.z.array(pt)}),o.z.object({"ds:KeyInfo":o.z.array(o.z.union([o.z.object({"ds:KeyValue":o.z.array(o.z.object({"ds:RSAKeyValue":o.z.array(o.z.union([o.z.object({"ds:Modulus":o.z.array(pt)}),o.z.object({"ds:Exponent":o.z.array(pt)})]))}))}),o.z.object({"ds:X509Data":o.z.array(o.z.object({"ds:X509Certificate":o.z.array(pt)}))}),o.z.object({"ds:KeyValue":o.z.array(o.z.object({"ds:RSAKeyValue":o.z.array(o.z.union([o.z.object({"ds:Modulus":o.z.array(pt)}),o.z.object({"ds:Exponent":o.z.array(pt)})]))})),"ds:X509Data":o.z.array(o.z.object({"ds:X509Certificate":o.z.array(pt)}))})]))})])),":@":o.z.object({"@_xmlns:ds":o.z.string().optional()}).optional()});o.z.array(o.z.object({"samlp:Response":o.z.array(o.z.union([o.z.object({"saml:Issuer":o.z.array(pt)}),a0,o.z.object({"samlp:Status":o.z.array(o.z.object({"samlp:StatusCode":o.z.array(pt),":@":o.z.object({"@_Value":o.z.string()})}))}),o.z.object({"saml:Assertion":o.z.array(o.z.union([o.z.object({"saml:Issuer":o.z.array(pt)}),a0,o.z.object({"saml:Subject":o.z.array(o.z.union([o.z.object({"saml:NameID":o.z.array(pt),":@":o.z.object({"@_Format":o.z.string()})}),o.z.object({"saml:SubjectConfirmation":o.z.array(o.z.object({"saml:SubjectConfirmationData":o.z.array(o.z.any()),":@":o.z.object({"@_InResponseTo":o.z.string(),"@_NotOnOrAfter":o.z.string(),"@_Recipient":o.z.string()})})),":@":o.z.object({"@_Method":o.z.string()})})]))}),o.z.object({"saml:Conditions":o.z.array(o.z.object({"saml:AudienceRestriction":o.z.array(o.z.object({"saml:Audience":o.z.array(pt)}))})),":@":o.z.object({"@_NotBefore":o.z.string(),"@_NotOnOrAfter":o.z.string()})}),o.z.object({"saml:AuthnStatement":o.z.array(o.z.object({"saml:AuthnContext":o.z.array(o.z.object({"saml:AuthnContextClassRef":o.z.array(pt)}))})),":@":o.z.object({"@_AuthnInstant":o.z.string(),"@_SessionIndex":o.z.string(),"@_SessionNotOnOrAfter":o.z.string()})}),o.z.object({"saml:AttributeStatement":o.z.array(X8)})])),":@":o.z.object({"@_xmlns":o.z.string(),"@_ID":o.z.string(),"@_IssueInstant":o.z.string(),"@_Version":o.z.string()})})])),":@":o.z.object({"@_xmlns:samlp":o.z.string(),"@_xmlns:saml":o.z.string(),"@_Destination":o.z.string(),"@_ID":o.z.string(),"@_InResponseTo":o.z.string(),"@_IssueInstant":o.z.string(),"@_Version":o.z.string()})}));var qp={},Kc={};(function(t){const e=":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD",n=e+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040",r="["+e+"]["+n+"]*",i=new RegExp("^"+r+"$"),s=function(c,l){const d=[];let u=l.exec(c);for(;u;){const f=[];f.startIndex=l.lastIndex-u[0].length;const h=u.length;for(let m=0;m<h;m++)f.push(u[m]);d.push(f),u=l.exec(c)}return d},a=function(c){const l=i.exec(c);return!(l===null||typeof l>"u")};t.isExist=function(c){return typeof c<"u"},t.isEmptyObject=function(c){return Object.keys(c).length===0},t.merge=function(c,l,d){if(l){const u=Object.keys(l),f=u.length;for(let h=0;h<f;h++)d==="strict"?c[u[h]]=[l[u[h]]]:c[u[h]]=l[u[h]]}},t.getValue=function(c){return t.isExist(c)?c:""},t.isName=a,t.getAllMatches=s,t.nameRegexp=r})(Kc);const Hp=Kc,Y8={allowBooleanAttributes:!1,unpairedTags:[]};qp.validate=function(t,e){e=Object.assign({},Y8,e);const n=[];let r=!1,i=!1;t[0]==="\uFEFF"&&(t=t.substr(1));for(let s=0;s<t.length;s++)if(t[s]==="<"&&t[s+1]==="?"){if(s+=2,s=l0(t,s),s.err)return s}else if(t[s]==="<"){let a=s;if(s++,t[s]==="!"){s=d0(t,s);continue}else{let c=!1;t[s]==="/"&&(c=!0,s++);let l="";for(;s<t.length&&t[s]!==">"&&t[s]!==" "&&t[s]!==" "&&t[s]!==`
263
263
  `&&t[s]!=="\r";s++)l+=t[s];if(l=l.trim(),l[l.length-1]==="/"&&(l=l.substring(0,l.length-1),s--),!sS(l)){let f;return l.trim().length===0?f="Invalid space after '<'.":f="Tag '"+l+"' is an invalid name.",qe("InvalidTag",f,_t(t,s))}const d=tS(t,s);if(d===!1)return qe("InvalidAttr","Attributes for '"+l+"' have open quote.",_t(t,s));let u=d.value;if(s=d.index,u[u.length-1]==="/"){const f=s-u.length;u=u.substring(0,u.length-1);const h=u0(u,e);if(h===!0)r=!0;else return qe(h.err.code,h.err.msg,_t(t,f+h.err.line))}else if(c)if(d.tagClosed){if(u.trim().length>0)return qe("InvalidTag","Closing tag '"+l+"' can't have attributes or invalid starting.",_t(t,a));if(n.length===0)return qe("InvalidTag","Closing tag '"+l+"' has not been opened.",_t(t,a));{const f=n.pop();if(l!==f.tagName){let h=_t(t,f.tagStartPos);return qe("InvalidTag","Expected closing tag '"+f.tagName+"' (opened in line "+h.line+", col "+h.col+") instead of closing tag '"+l+"'.",_t(t,a))}n.length==0&&(i=!0)}}else return qe("InvalidTag","Closing tag '"+l+"' doesn't have proper closing.",_t(t,s));else{const f=u0(u,e);if(f!==!0)return qe(f.err.code,f.err.msg,_t(t,s-u.length+f.err.line));if(i===!0)return qe("InvalidXml","Multiple possible root nodes found.",_t(t,s));e.unpairedTags.indexOf(l)!==-1||n.push({tagName:l,tagStartPos:a}),r=!0}for(s++;s<t.length;s++)if(t[s]==="<")if(t[s+1]==="!"){s++,s=d0(t,s);continue}else if(t[s+1]==="?"){if(s=l0(t,++s),s.err)return s}else break;else if(t[s]==="&"){const f=iS(t,s);if(f==-1)return qe("InvalidChar","char '&' is not expected.",_t(t,s));s=f}else if(i===!0&&!c0(t[s]))return qe("InvalidXml","Extra text at the end",_t(t,s));t[s]==="<"&&s--}}else{if(c0(t[s]))continue;return qe("InvalidChar","char '"+t[s]+"' is not expected.",_t(t,s))}if(r){if(n.length==1)return qe("InvalidTag","Unclosed tag '"+n[0].tagName+"'.",_t(t,n[0].tagStartPos));if(n.length>0)return qe("InvalidXml","Invalid '"+JSON.stringify(n.map(s=>s.tagName),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1})}else return qe("InvalidXml","Start tag expected.",1);return!0};function c0(t){return t===" "||t===" "||t===`
264
264
  `||t==="\r"}function l0(t,e){const n=e;for(;e<t.length;e++)if(t[e]=="?"||t[e]==" "){const r=t.substr(n,e-n);if(e>5&&r==="xml")return qe("InvalidXml","XML declaration allowed only at the start of the document.",_t(t,e));if(t[e]=="?"&&t[e+1]==">"){e++;break}else continue}return e}function d0(t,e){if(t.length>e+5&&t[e+1]==="-"&&t[e+2]==="-"){for(e+=3;e<t.length;e++)if(t[e]==="-"&&t[e+1]==="-"&&t[e+2]===">"){e+=2;break}}else if(t.length>e+8&&t[e+1]==="D"&&t[e+2]==="O"&&t[e+3]==="C"&&t[e+4]==="T"&&t[e+5]==="Y"&&t[e+6]==="P"&&t[e+7]==="E"){let n=1;for(e+=8;e<t.length;e++)if(t[e]==="<")n++;else if(t[e]===">"&&(n--,n===0))break}else if(t.length>e+9&&t[e+1]==="["&&t[e+2]==="C"&&t[e+3]==="D"&&t[e+4]==="A"&&t[e+5]==="T"&&t[e+6]==="A"&&t[e+7]==="["){for(e+=8;e<t.length;e++)if(t[e]==="]"&&t[e+1]==="]"&&t[e+2]===">"){e+=2;break}}return e}const Q8='"',eS="'";function tS(t,e){let n="",r="",i=!1;for(;e<t.length;e++){if(t[e]===Q8||t[e]===eS)r===""?r=t[e]:r!==t[e]||(r="");else if(t[e]===">"&&r===""){i=!0;break}n+=t[e]}return r!==""?!1:{value:n,index:e,tagClosed:i}}const nS=new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`,"g");function u0(t,e){const n=Hp.getAllMatches(t,nS),r={};for(let i=0;i<n.length;i++){if(n[i][1].length===0)return qe("InvalidAttr","Attribute '"+n[i][2]+"' has no space in starting.",Fi(n[i]));if(n[i][3]!==void 0&&n[i][4]===void 0)return qe("InvalidAttr","Attribute '"+n[i][2]+"' is without value.",Fi(n[i]));if(n[i][3]===void 0&&!e.allowBooleanAttributes)return qe("InvalidAttr","boolean attribute '"+n[i][2]+"' is not allowed.",Fi(n[i]));const s=n[i][2];if(!oS(s))return qe("InvalidAttr","Attribute '"+s+"' is an invalid name.",Fi(n[i]));if(!r.hasOwnProperty(s))r[s]=1;else return qe("InvalidAttr","Attribute '"+s+"' is repeated.",Fi(n[i]))}return!0}function rS(t,e){let n=/\d/;for(t[e]==="x"&&(e++,n=/[\da-fA-F]/);e<t.length;e++){if(t[e]===";")return e;if(!t[e].match(n))break}return-1}function iS(t,e){if(e++,t[e]===";")return-1;if(t[e]==="#")return e++,rS(t,e);let n=0;for(;e<t.length;e++,n++)if(!(t[e].match(/\w/)&&n<20)){if(t[e]===";")break;return-1}return e}function qe(t,e,n){return{err:{code:t,msg:e,line:n.line||n,col:n.col}}}function oS(t){return Hp.isName(t)}function sS(t){return Hp.isName(t)}function _t(t,e){const n=t.substring(0,e).split(/\r?\n/);return{line:n.length,col:n[n.length-1].length+1}}function Fi(t){return t.startIndex+t[1].length}var Vp={};const X1={preserveOrder:!1,attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,removeNSPrefix:!1,allowBooleanAttributes:!1,parseTagValue:!0,parseAttributeValue:!1,trimValues:!0,cdataPropName:!1,numberParseOptions:{hex:!0,leadingZeros:!0,eNotation:!0},tagValueProcessor:function(t,e){return e},attributeValueProcessor:function(t,e){return e},stopNodes:[],alwaysCreateTextNode:!1,isArray:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(t,e,n){return t}},aS=function(t){return Object.assign({},X1,t)};Vp.buildOptions=aS;Vp.defaultOptions=X1;class cS{constructor(e){this.tagname=e,this.child=[],this[":@"]={}}add(e,n){e==="__proto__"&&(e="#__proto__"),this.child.push({[e]:n})}addChild(e){e.tagname==="__proto__"&&(e.tagname="#__proto__"),e[":@"]&&Object.keys(e[":@"]).length>0?this.child.push({[e.tagname]:e.child,":@":e[":@"]}):this.child.push({[e.tagname]:e.child})}}var lS=cS;const dS=Kc;function uS(t,e){const n={};if(t[e+3]==="O"&&t[e+4]==="C"&&t[e+5]==="T"&&t[e+6]==="Y"&&t[e+7]==="P"&&t[e+8]==="E"){e=e+9;let r=1,i=!1,s=!1,a="";for(;e<t.length;e++)if(t[e]==="<"&&!s){if(i&&hS(t,e)){e+=7;let c,l;[c,l,e]=pS(t,e+1),l.indexOf("&")===-1&&(n[yS(c)]={regx:RegExp(`&${c};`,"g"),val:l})}else if(i&&gS(t,e))e+=8;else if(i&&mS(t,e))e+=8;else if(i&&_S(t,e))e+=9;else if(fS)s=!0;else throw new Error("Invalid DOCTYPE");r++,a=""}else if(t[e]===">"){if(s?t[e-1]==="-"&&t[e-2]==="-"&&(s=!1,r--):r--,r===0)break}else t[e]==="["?i=!0:a+=t[e];if(r!==0)throw new Error("Unclosed DOCTYPE")}else throw new Error("Invalid Tag instead of DOCTYPE");return{entities:n,i:e}}function pS(t,e){let n="";for(;e<t.length&&t[e]!=="'"&&t[e]!=='"';e++)n+=t[e];if(n=n.trim(),n.indexOf(" ")!==-1)throw new Error("External entites are not supported");const r=t[e++];let i="";for(;e<t.length&&t[e]!==r;e++)i+=t[e];return[n,i,e]}function fS(t,e){return t[e+1]==="!"&&t[e+2]==="-"&&t[e+3]==="-"}function hS(t,e){return t[e+1]==="!"&&t[e+2]==="E"&&t[e+3]==="N"&&t[e+4]==="T"&&t[e+5]==="I"&&t[e+6]==="T"&&t[e+7]==="Y"}function gS(t,e){return t[e+1]==="!"&&t[e+2]==="E"&&t[e+3]==="L"&&t[e+4]==="E"&&t[e+5]==="M"&&t[e+6]==="E"&&t[e+7]==="N"&&t[e+8]==="T"}function mS(t,e){return t[e+1]==="!"&&t[e+2]==="A"&&t[e+3]==="T"&&t[e+4]==="T"&&t[e+5]==="L"&&t[e+6]==="I"&&t[e+7]==="S"&&t[e+8]==="T"}function _S(t,e){return t[e+1]==="!"&&t[e+2]==="N"&&t[e+3]==="O"&&t[e+4]==="T"&&t[e+5]==="A"&&t[e+6]==="T"&&t[e+7]==="I"&&t[e+8]==="O"&&t[e+9]==="N"}function yS(t){if(dS.isName(t))return t;throw new Error(`Invalid entity name ${t}`)}var wS=uS;const vS=/^[-+]?0x[a-fA-F0-9]+$/,bS=/^([\-\+])?(0*)(\.[0-9]+([eE]\-?[0-9]+)?|[0-9]+(\.[0-9]+([eE]\-?[0-9]+)?)?)$/;!Number.parseInt&&window.parseInt&&(Number.parseInt=window.parseInt);!Number.parseFloat&&window.parseFloat&&(Number.parseFloat=window.parseFloat);const $S={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};function kS(t,e={}){if(e=Object.assign({},$S,e),!t||typeof t!="string")return t;let n=t.trim();if(e.skipLike!==void 0&&e.skipLike.test(n))return t;if(e.hex&&vS.test(n))return Number.parseInt(n,16);{const r=bS.exec(n);if(r){const i=r[1],s=r[2];let a=xS(r[3]);const c=r[4]||r[6];if(!e.leadingZeros&&s.length>0&&i&&n[2]!=="."||!e.leadingZeros&&s.length>0&&!i&&n[1]!==".")return t;{const l=Number(n),d=""+l;return d.search(/[eE]/)!==-1||c?e.eNotation?l:t:n.indexOf(".")!==-1?d==="0"&&a===""||d===a||i&&d==="-"+a?l:t:s?a===d||i+a===d?l:t:n===d||n===i+d?l:t}}else return t}}function xS(t){return t&&t.indexOf(".")!==-1&&(t=t.replace(/0+$/,""),t==="."?t="0":t[0]==="."?t="0"+t:t[t.length-1]==="."&&(t=t.substr(0,t.length-1))),t}var SS=kS;function zS(t){return typeof t=="function"?t:Array.isArray(t)?e=>{for(const n of t)if(typeof n=="string"&&e===n||n instanceof RegExp&&n.test(e))return!0}:()=>!1}var Z1=zS;const Y1=Kc,qi=lS,AS=wS,ES=SS,CS=Z1;let NS=class{constructor(t){this.options=t,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:"'"},gt:{regex:/&(gt|#62|#x3E);/g,val:">"},lt:{regex:/&(lt|#60|#x3C);/g,val:"<"},quot:{regex:/&(quot|#34|#x22);/g,val:'"'}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:"&"},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:" "},cent:{regex:/&(cent|#162);/g,val:"¢"},pound:{regex:/&(pound|#163);/g,val:"£"},yen:{regex:/&(yen|#165);/g,val:"¥"},euro:{regex:/&(euro|#8364);/g,val:"€"},copyright:{regex:/&(copy|#169);/g,val:"©"},reg:{regex:/&(reg|#174);/g,val:"®"},inr:{regex:/&(inr|#8377);/g,val:"₹"},num_dec:{regex:/&#([0-9]{1,7});/g,val:(e,n)=>String.fromCharCode(Number.parseInt(n,10))},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:(e,n)=>String.fromCharCode(Number.parseInt(n,16))}},this.addExternalEntities=IS,this.parseXml=RS,this.parseTextData=jS,this.resolveNameSpace=OS,this.buildAttributesMap=PS,this.isItStopNode=DS,this.replaceEntitiesValue=LS,this.readStopNodeData=FS,this.saveTextToParentTag=US,this.addChild=BS,this.ignoreAttributesFn=CS(this.options.ignoreAttributes)}};function IS(t){const e=Object.keys(t);for(let n=0;n<e.length;n++){const r=e[n];this.lastEntities[r]={regex:new RegExp("&"+r+";","g"),val:t[r]}}}function jS(t,e,n,r,i,s,a){if(t!==void 0&&(this.options.trimValues&&!r&&(t=t.trim()),t.length>0)){a||(t=this.replaceEntitiesValue(t));const c=this.options.tagValueProcessor(e,t,n,i,s);return c==null?t:typeof c!=typeof t||c!==t?c:this.options.trimValues?hu(t,this.options.parseTagValue,this.options.numberParseOptions):t.trim()===t?hu(t,this.options.parseTagValue,this.options.numberParseOptions):t}}function OS(t){if(this.options.removeNSPrefix){const e=t.split(":"),n=t.charAt(0)==="/"?"/":"";if(e[0]==="xmlns")return"";e.length===2&&(t=n+e[1])}return t}const TS=new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`,"gm");function PS(t,e,n){if(this.options.ignoreAttributes!==!0&&typeof t=="string"){const r=Y1.getAllMatches(t,TS),i=r.length,s={};for(let a=0;a<i;a++){const c=this.resolveNameSpace(r[a][1]);if(this.ignoreAttributesFn(c,e))continue;let l=r[a][4],d=this.options.attributeNamePrefix+c;if(c.length)if(this.options.transformAttributeName&&(d=this.options.transformAttributeName(d)),d==="__proto__"&&(d="#__proto__"),l!==void 0){this.options.trimValues&&(l=l.trim()),l=this.replaceEntitiesValue(l);const u=this.options.attributeValueProcessor(c,l,e);u==null?s[d]=l:typeof u!=typeof l||u!==l?s[d]=u:s[d]=hu(l,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(s[d]=!0)}if(!Object.keys(s).length)return;if(this.options.attributesGroupName){const a={};return a[this.options.attributesGroupName]=s,a}return s}}const RS=function(t){t=t.replace(/\r\n?/g,`
265
265
  `);const e=new qi("!xml");let n=e,r="",i="";for(let s=0;s<t.length;s++)if(t[s]==="<")if(t[s+1]==="/"){const a=pr(t,">",s,"Closing Tag is not closed.");let c=t.substring(s+2,a).trim();if(this.options.removeNSPrefix){const u=c.indexOf(":");u!==-1&&(c=c.substr(u+1))}this.options.transformTagName&&(c=this.options.transformTagName(c)),n&&(r=this.saveTextToParentTag(r,n,i));const l=i.substring(i.lastIndexOf(".")+1);if(c&&this.options.unpairedTags.indexOf(c)!==-1)throw new Error(`Unpaired tag can not be used as closing tag: </${c}>`);let d=0;l&&this.options.unpairedTags.indexOf(l)!==-1?(d=i.lastIndexOf(".",i.lastIndexOf(".")-1),this.tagsNodeStack.pop()):d=i.lastIndexOf("."),i=i.substring(0,d),n=this.tagsNodeStack.pop(),r="",s=a}else if(t[s+1]==="?"){let a=fu(t,s,!1,"?>");if(!a)throw new Error("Pi Tag is not closed.");if(r=this.saveTextToParentTag(r,n,i),!(this.options.ignoreDeclaration&&a.tagName==="?xml"||this.options.ignorePiTags)){const c=new qi(a.tagName);c.add(this.options.textNodeName,""),a.tagName!==a.tagExp&&a.attrExpPresent&&(c[":@"]=this.buildAttributesMap(a.tagExp,i,a.tagName)),this.addChild(n,c,i)}s=a.closeIndex+1}else if(t.substr(s+1,3)==="!--"){const a=pr(t,"-->",s+4,"Comment is not closed.");if(this.options.commentPropName){const c=t.substring(s+4,a-2);r=this.saveTextToParentTag(r,n,i),n.add(this.options.commentPropName,[{[this.options.textNodeName]:c}])}s=a}else if(t.substr(s+1,2)==="!D"){const a=AS(t,s);this.docTypeEntities=a.entities,s=a.i}else if(t.substr(s+1,2)==="!["){const a=pr(t,"]]>",s,"CDATA is not closed.")-2,c=t.substring(s+9,a);r=this.saveTextToParentTag(r,n,i);let l=this.parseTextData(c,n.tagname,i,!0,!1,!0,!0);l==null&&(l=""),this.options.cdataPropName?n.add(this.options.cdataPropName,[{[this.options.textNodeName]:c}]):n.add(this.options.textNodeName,l),s=a+2}else{let a=fu(t,s,this.options.removeNSPrefix),c=a.tagName;const l=a.rawTagName;let d=a.tagExp,u=a.attrExpPresent,f=a.closeIndex;this.options.transformTagName&&(c=this.options.transformTagName(c)),n&&r&&n.tagname!=="!xml"&&(r=this.saveTextToParentTag(r,n,i,!1));const h=n;if(h&&this.options.unpairedTags.indexOf(h.tagname)!==-1&&(n=this.tagsNodeStack.pop(),i=i.substring(0,i.lastIndexOf("."))),c!==e.tagname&&(i+=i?"."+c:c),this.isItStopNode(this.options.stopNodes,i,c)){let m="";if(d.length>0&&d.lastIndexOf("/")===d.length-1)c[c.length-1]==="/"?(c=c.substr(0,c.length-1),i=i.substr(0,i.length-1),d=c):d=d.substr(0,d.length-1),s=a.closeIndex;else if(this.options.unpairedTags.indexOf(c)!==-1)s=a.closeIndex;else{const v=this.readStopNodeData(t,l,f+1);if(!v)throw new Error(`Unexpected end of ${l}`);s=v.i,m=v.tagContent}const y=new qi(c);c!==d&&u&&(y[":@"]=this.buildAttributesMap(d,i,c)),m&&(m=this.parseTextData(m,c,i,!0,u,!0,!0)),i=i.substr(0,i.lastIndexOf(".")),y.add(this.options.textNodeName,m),this.addChild(n,y,i)}else{if(d.length>0&&d.lastIndexOf("/")===d.length-1){c[c.length-1]==="/"?(c=c.substr(0,c.length-1),i=i.substr(0,i.length-1),d=c):d=d.substr(0,d.length-1),this.options.transformTagName&&(c=this.options.transformTagName(c));const m=new qi(c);c!==d&&u&&(m[":@"]=this.buildAttributesMap(d,i,c)),this.addChild(n,m,i),i=i.substr(0,i.lastIndexOf("."))}else{const m=new qi(c);this.tagsNodeStack.push(n),c!==d&&u&&(m[":@"]=this.buildAttributesMap(d,i,c)),this.addChild(n,m,i),n=m}r="",s=f}}else r+=t[s];return e.child};function BS(t,e,n){const r=this.options.updateTag(e.tagname,n,e[":@"]);r===!1||(typeof r=="string"&&(e.tagname=r),t.addChild(e))}const LS=function(t){if(this.options.processEntities){for(let e in this.docTypeEntities){const n=this.docTypeEntities[e];t=t.replace(n.regx,n.val)}for(let e in this.lastEntities){const n=this.lastEntities[e];t=t.replace(n.regex,n.val)}if(this.options.htmlEntities)for(let e in this.htmlEntities){const n=this.htmlEntities[e];t=t.replace(n.regex,n.val)}t=t.replace(this.ampEntity.regex,this.ampEntity.val)}return t};function US(t,e,n,r){return t&&(r===void 0&&(r=Object.keys(e.child).length===0),t=this.parseTextData(t,e.tagname,n,!1,e[":@"]?Object.keys(e[":@"]).length!==0:!1,r),t!==void 0&&t!==""&&e.add(this.options.textNodeName,t),t=""),t}function DS(t,e,n){const r="*."+n;for(const i in t){const s=t[i];if(r===s||e===s)return!0}return!1}function MS(t,e,n=">"){let r,i="";for(let s=e;s<t.length;s++){let a=t[s];if(r)a===r&&(r="");else if(a==='"'||a==="'")r=a;else if(a===n[0])if(n[1]){if(t[s+1]===n[1])return{data:i,index:s}}else return{data:i,index:s};else a===" "&&(a=" ");i+=a}}function pr(t,e,n,r){const i=t.indexOf(e,n);if(i===-1)throw new Error(r);return i+e.length-1}function fu(t,e,n,r=">"){const i=MS(t,e+1,r);if(!i)return;let s=i.data;const a=i.index,c=s.search(/\s/);let l=s,d=!0;c!==-1&&(l=s.substring(0,c),s=s.substring(c+1).trimStart());const u=l;if(n){const f=l.indexOf(":");f!==-1&&(l=l.substr(f+1),d=l!==i.data.substr(f+1))}return{tagName:l,tagExp:s,closeIndex:a,attrExpPresent:d,rawTagName:u}}function FS(t,e,n){const r=n;let i=1;for(;n<t.length;n++)if(t[n]==="<")if(t[n+1]==="/"){const s=pr(t,">",n,`${e} is not closed`);if(t.substring(n+2,s).trim()===e&&(i--,i===0))return{tagContent:t.substring(r,n),i:s};n=s}else if(t[n+1]==="?")n=pr(t,"?>",n+1,"StopNode is not closed.");else if(t.substr(n+1,3)==="!--")n=pr(t,"-->",n+3,"StopNode is not closed.");else if(t.substr(n+1,2)==="![")n=pr(t,"]]>",n,"StopNode is not closed.")-2;else{const s=fu(t,n,">");s&&((s&&s.tagName)===e&&s.tagExp[s.tagExp.length-1]!=="/"&&i++,n=s.closeIndex)}}function hu(t,e,n){if(e&&typeof t=="string"){const r=t.trim();return r==="true"?!0:r==="false"?!1:ES(t,n)}else return Y1.isExist(t)?t:""}var qS=NS,Q1={};function HS(t,e){return ew(t,e)}function ew(t,e,n){let r;const i={};for(let s=0;s<t.length;s++){const a=t[s],c=VS(a);let l="";if(n===void 0?l=c:l=n+"."+c,c===e.textNodeName)r===void 0?r=a[c]:r+=""+a[c];else{if(c===void 0)continue;if(a[c]){let d=ew(a[c],e,l);const u=GS(d,e);a[":@"]?KS(d,a[":@"],l,e):Object.keys(d).length===1&&d[e.textNodeName]!==void 0&&!e.alwaysCreateTextNode?d=d[e.textNodeName]:Object.keys(d).length===0&&(e.alwaysCreateTextNode?d[e.textNodeName]="":d=""),i[c]!==void 0&&i.hasOwnProperty(c)?(Array.isArray(i[c])||(i[c]=[i[c]]),i[c].push(d)):e.isArray(c,l,u)?i[c]=[d]:i[c]=d}}}return typeof r=="string"?r.length>0&&(i[e.textNodeName]=r):r!==void 0&&(i[e.textNodeName]=r),i}function VS(t){const e=Object.keys(t);for(let n=0;n<e.length;n++){const r=e[n];if(r!==":@")return r}}function KS(t,e,n,r){if(e){const i=Object.keys(e),s=i.length;for(let a=0;a<s;a++){const c=i[a];r.isArray(c,n+"."+c,!0,!0)?t[c]=[e[c]]:t[c]=e[c]}}}function GS(t,e){const{textNodeName:n}=e,r=Object.keys(t).length;return!!(r===0||r===1&&(t[n]||typeof t[n]=="boolean"||t[n]===0))}Q1.prettify=HS;const{buildOptions:WS}=Vp,JS=qS,{prettify:XS}=Q1,ZS=qp;let YS=class{constructor(t){this.externalEntities={},this.options=WS(t)}parse(t,e){if(typeof t!="string")if(t.toString)t=t.toString();else throw new Error("XML data is accepted in String or Bytes[] form.");if(e){e===!0&&(e={});const i=ZS.validate(t,e);if(i!==!0)throw Error(`${i.err.msg}:${i.err.line}:${i.err.col}`)}const n=new JS(this.options);n.addExternalEntities(this.externalEntities);const r=n.parseXml(t);return this.options.preserveOrder||r===void 0?r:XS(r,this.options)}addEntity(t,e){if(e.indexOf("&")!==-1)throw new Error("Entity value can't have '&'");if(t.indexOf("&")!==-1||t.indexOf(";")!==-1)throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '&#xD;'");if(e==="&")throw new Error("An entity with value '&' is not permitted");this.externalEntities[t]=e}};var QS=YS;const e9=`
266
266
  `;function t9(t,e){let n="";return e.format&&e.indentBy.length>0&&(n=e9),tw(t,e,"",n)}function tw(t,e,n,r){let i="",s=!1;for(let a=0;a<t.length;a++){const c=t[a],l=n9(c);if(l===void 0)continue;let d="";if(n.length===0?d=l:d=`${n}.${l}`,l===e.textNodeName){let y=c[l];r9(d,e)||(y=e.tagValueProcessor(l,y),y=nw(y,e)),s&&(i+=r),i+=y,s=!1;continue}else if(l===e.cdataPropName){s&&(i+=r),i+=`<![CDATA[${c[l][0][e.textNodeName]}]]>`,s=!1;continue}else if(l===e.commentPropName){i+=r+`<!--${c[l][0][e.textNodeName]}-->`,s=!0;continue}else if(l[0]==="?"){const y=p0(c[":@"],e),v=l==="?xml"?"":r;let b=c[l][0][e.textNodeName];b=b.length!==0?" "+b:"",i+=v+`<${l}${b}${y}?>`,s=!0;continue}let u=r;u!==""&&(u+=e.indentBy);const f=p0(c[":@"],e),h=r+`<${l}${f}`,m=tw(c[l],e,d,u);e.unpairedTags.indexOf(l)!==-1?e.suppressUnpairedNode?i+=h+">":i+=h+"/>":(!m||m.length===0)&&e.suppressEmptyNode?i+=h+"/>":m&&m.endsWith(">")?i+=h+`>${m}${r}</${l}>`:(i+=h+">",m&&r!==""&&(m.includes("/>")||m.includes("</"))?i+=r+e.indentBy+m+r:i+=m,i+=`</${l}>`),s=!0}return i}function n9(t){const e=Object.keys(t);for(let n=0;n<e.length;n++){const r=e[n];if(t.hasOwnProperty(r)&&r!==":@")return r}}function p0(t,e){let n="";if(t&&!e.ignoreAttributes)for(let r in t){if(!t.hasOwnProperty(r))continue;let i=e.attributeValueProcessor(r,t[r]);i=nw(i,e),i===!0&&e.suppressBooleanAttributes?n+=` ${r.substr(e.attributeNamePrefix.length)}`:n+=` ${r.substr(e.attributeNamePrefix.length)}="${i}"`}return n}function r9(t,e){t=t.substr(0,t.length-e.textNodeName.length-1);let n=t.substr(t.lastIndexOf(".")+1);for(let r in e.stopNodes)if(e.stopNodes[r]===t||e.stopNodes[r]==="*."+n)return!0;return!1}function nw(t,e){if(t&&t.length>0&&e.processEntities)for(let n=0;n<e.entities.length;n++){const r=e.entities[n];t=t.replace(r.regex,r.val)}return t}var i9=t9;const o9=i9,s9=Z1,a9={attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,cdataPropName:!1,format:!1,indentBy:" ",suppressEmptyNode:!1,suppressUnpairedNode:!0,suppressBooleanAttributes:!0,tagValueProcessor:function(t,e){return e},attributeValueProcessor:function(t,e){return e},preserveOrder:!1,commentPropName:!1,unpairedTags:[],entities:[{regex:new RegExp("&","g"),val:"&amp;"},{regex:new RegExp(">","g"),val:"&gt;"},{regex:new RegExp("<","g"),val:"&lt;"},{regex:new RegExp("'","g"),val:"&apos;"},{regex:new RegExp('"',"g"),val:"&quot;"}],processEntities:!0,stopNodes:[],oneListGroup:!1};function nr(t){this.options=Object.assign({},a9,t),this.options.ignoreAttributes===!0||this.options.attributesGroupName?this.isAttribute=function(){return!1}:(this.ignoreAttributesFn=s9(this.options.ignoreAttributes),this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=d9),this.processTextOrObjNode=c9,this.options.format?(this.indentate=l9,this.tagEndChar=`>
267
267
  `,this.newLine=`
268
- `):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}nr.prototype.build=function(t){return this.options.preserveOrder?o9(t,this.options):(Array.isArray(t)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(t={[this.options.arrayNodeName]:t}),this.j2x(t,0,[]).val)};nr.prototype.j2x=function(t,e,n){let r="",i="";const s=n.join(".");for(let a in t)if(Object.prototype.hasOwnProperty.call(t,a))if(typeof t[a]>"u")this.isAttribute(a)&&(i+="");else if(t[a]===null)this.isAttribute(a)?i+="":a[0]==="?"?i+=this.indentate(e)+"<"+a+"?"+this.tagEndChar:i+=this.indentate(e)+"<"+a+"/"+this.tagEndChar;else if(t[a]instanceof Date)i+=this.buildTextValNode(t[a],a,"",e);else if(typeof t[a]!="object"){const c=this.isAttribute(a);if(c&&!this.ignoreAttributesFn(c,s))r+=this.buildAttrPairStr(c,""+t[a]);else if(!c)if(a===this.options.textNodeName){let l=this.options.tagValueProcessor(a,""+t[a]);i+=this.replaceEntitiesValue(l)}else i+=this.buildTextValNode(t[a],a,"",e)}else if(Array.isArray(t[a])){const c=t[a].length;let l="",d="";for(let u=0;u<c;u++){const f=t[a][u];if(!(typeof f>"u"))if(f===null)a[0]==="?"?i+=this.indentate(e)+"<"+a+"?"+this.tagEndChar:i+=this.indentate(e)+"<"+a+"/"+this.tagEndChar;else if(typeof f=="object")if(this.options.oneListGroup){const h=this.j2x(f,e+1,n.concat(a));l+=h.val,this.options.attributesGroupName&&f.hasOwnProperty(this.options.attributesGroupName)&&(d+=h.attrStr)}else l+=this.processTextOrObjNode(f,a,e,n);else if(this.options.oneListGroup){let h=this.options.tagValueProcessor(a,f);h=this.replaceEntitiesValue(h),l+=h}else l+=this.buildTextValNode(f,a,"",e)}this.options.oneListGroup&&(l=this.buildObjectNode(l,a,d,e)),i+=l}else if(this.options.attributesGroupName&&a===this.options.attributesGroupName){const c=Object.keys(t[a]),l=c.length;for(let d=0;d<l;d++)r+=this.buildAttrPairStr(c[d],""+t[a][c[d]])}else i+=this.processTextOrObjNode(t[a],a,e,n);return{attrStr:r,val:i}};nr.prototype.buildAttrPairStr=function(t,e){return e=this.options.attributeValueProcessor(t,""+e),e=this.replaceEntitiesValue(e),this.options.suppressBooleanAttributes&&e==="true"?" "+t:" "+t+'="'+e+'"'};function c9(t,e,n,r){const i=this.j2x(t,n+1,r.concat(e));return t[this.options.textNodeName]!==void 0&&Object.keys(t).length===1?this.buildTextValNode(t[this.options.textNodeName],e,i.attrStr,n):this.buildObjectNode(i.val,e,i.attrStr,n)}nr.prototype.buildObjectNode=function(t,e,n,r){if(t==="")return e[0]==="?"?this.indentate(r)+"<"+e+n+"?"+this.tagEndChar:this.indentate(r)+"<"+e+n+this.closeTag(e)+this.tagEndChar;{let i="</"+e+this.tagEndChar,s="";return e[0]==="?"&&(s="?",i=""),(n||n==="")&&t.indexOf("<")===-1?this.indentate(r)+"<"+e+n+s+">"+t+i:this.options.commentPropName!==!1&&e===this.options.commentPropName&&s.length===0?this.indentate(r)+`<!--${t}-->`+this.newLine:this.indentate(r)+"<"+e+n+s+this.tagEndChar+t+this.indentate(r)+i}};nr.prototype.closeTag=function(t){let e="";return this.options.unpairedTags.indexOf(t)!==-1?this.options.suppressUnpairedNode||(e="/"):this.options.suppressEmptyNode?e="/":e=`></${t}`,e};nr.prototype.buildTextValNode=function(t,e,n,r){if(this.options.cdataPropName!==!1&&e===this.options.cdataPropName)return this.indentate(r)+`<![CDATA[${t}]]>`+this.newLine;if(this.options.commentPropName!==!1&&e===this.options.commentPropName)return this.indentate(r)+`<!--${t}-->`+this.newLine;if(e[0]==="?")return this.indentate(r)+"<"+e+n+"?"+this.tagEndChar;{let i=this.options.tagValueProcessor(e,t);return i=this.replaceEntitiesValue(i),i===""?this.indentate(r)+"<"+e+n+this.closeTag(e)+this.tagEndChar:this.indentate(r)+"<"+e+n+">"+i+"</"+e+this.tagEndChar}};nr.prototype.replaceEntitiesValue=function(t){if(t&&t.length>0&&this.options.processEntities)for(let e=0;e<this.options.entities.length;e++){const n=this.options.entities[e];t=t.replace(n.regex,n.val)}return t};function l9(t){return this.options.indentBy.repeat(t)}function d9(t){return t.startsWith(this.options.attributeNamePrefix)&&t!==this.options.textNodeName?t.substr(this.attrPrefixLen):!1}var u9=nr;const p9=qp,f9=QS,h9=u9;var rw={XMLParser:f9,XMLValidator:p9,XMLBuilder:h9};class iw{constructor(e,n){if(ei(this,"alphabet"),ei(this,"padding"),ei(this,"decodeMap",new Map),e.length!==32)throw new Error("Invalid alphabet");if(this.alphabet=e,this.padding=(n==null?void 0:n.padding)??"=",this.alphabet.includes(this.padding)||this.padding.length!==1)throw new Error("Invalid padding");for(let r=0;r<e.length;r++)this.decodeMap.set(e[r],r)}encode(e,n){let r="",i=0,s=0;for(let a=0;a<e.length;a++)for(i=i<<8|e[a],s+=8;s>=5;)s-=5,r+=this.alphabet[i>>s&31];if(s>0&&(r+=this.alphabet[i<<5-s&31]),(n==null?void 0:n.includePadding)??!0){const a=(8-r.length%8)%8;for(let c=0;c<a;c++)r+="="}return r}decode(e,n){const r=(n==null?void 0:n.strict)??!0,i=Math.ceil(e.length/8),s=[];for(let a=0;a<i;a++){let c=0;const l=[];for(let u=0;u<8;u++){const f=e[a*8+u];if(f==="="){if(a+1!==i)throw new Error(`Invalid character: ${f}`);c+=1;continue}if(f===void 0){if(r)throw new Error("Invalid data");c+=1;continue}const h=this.decodeMap.get(f)??null;if(h===null)throw new Error(`Invalid character: ${f}`);l.push(h)}if(c===8||c===7||c===5||c===2)throw new Error("Invalid padding");const d=(l[0]<<3)+(l[1]>>2);if(s.push(d),c<6){const u=((l[1]&3)<<6)+(l[2]<<1)+(l[3]>>4);s.push(u)}if(c<4){const u=((l[3]&255)<<4)+(l[4]>>1);s.push(u)}if(c<3){const u=((l[4]&1)<<7)+(l[5]<<2)+(l[6]>>3);s.push(u)}if(c<1){const u=((l[6]&7)<<5)+l[7];s.push(u)}}return Uint8Array.from(s)}}new iw("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567");new iw("0123456789ABCDEFGHIJKLMNOPQRSTUV");class ow{constructor(e,n){if(ei(this,"alphabet"),ei(this,"padding"),ei(this,"decodeMap",new Map),e.length!==64)throw new Error("Invalid alphabet");if(this.alphabet=e,this.padding=(n==null?void 0:n.padding)??"=",this.alphabet.includes(this.padding)||this.padding.length!==1)throw new Error("Invalid padding");for(let r=0;r<e.length;r++)this.decodeMap.set(e[r],r)}encode(e,n){let r="",i=0,s=0;for(let a=0;a<e.length;a++)for(i=i<<8|e[a],s+=8;s>=6;)s+=-6,r+=this.alphabet[i>>s&63];if(s>0&&(r+=this.alphabet[i<<6-s&63]),(n==null?void 0:n.includePadding)??!0){const a=(4-r.length%4)%4;for(let c=0;c<a;c++)r+="="}return r}decode(e,n){const r=(n==null?void 0:n.strict)??!0,i=Math.ceil(e.length/4),s=[];for(let a=0;a<i;a++){let c=0,l=0;for(let d=0;d<4;d++){const u=e[a*4+d];if(u==="="){if(a+1!==i)throw new Error(`Invalid character: ${u}`);c+=1;continue}if(u===void 0){if(r)throw new Error("Invalid data");c+=1;continue}const f=this.decodeMap.get(u)??null;if(f===null)throw new Error(`Invalid character: ${u}`);l+=f<<6*(3-d)}s.push(l>>16&255),c<2&&s.push(l>>8&255),c<1&&s.push(l&255)}return Uint8Array.from(s)}}const g9=new ow("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");new ow("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");async function m9(t){const e=new DecompressionStream("deflate-raw"),n=new Uint8Array(t),r=new Blob([n]).stream().pipeThrough(e);return new Uint8Array(await new Response(r).arrayBuffer())}async function _9(t){const e=await g9.decode(t.replace(/ /g,"+"));try{const n=await m9(e);return new TextDecoder().decode(n)}catch(n){return console.warn("Decompression failed, assuming data is not compressed:",n),new TextDecoder().decode(e)}}async function y9(t){const e=await _9(t),n=new rw.XMLParser({attributeNamePrefix:"@_",alwaysCreateTextNode:!0,ignoreAttributes:!1}).parse(e);return J8.parse(n)}function w9(t){const e=t.certificates.map(r=>({"@_use":"signing",KeyInfo:{"@_xmlns":"http://www.w3.org/2000/09/xmldsig#",X509Data:{X509Certificate:r}}})),n={EntityDescriptor:{"@_entityID":t.entityId,"@_xmlns":"urn:oasis:names:tc:SAML:2.0:metadata",IDPSSODescriptor:{"@_protocolSupportEnumeration":"urn:oasis:names:tc:SAML:2.0:protocol",KeyDescriptor:e,SingleLogoutService:[{"@_Binding":"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect","@_Location":t.singleLogoutServiceUrl},{"@_Binding":"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST","@_Location":t.singleLogoutServiceUrl}],NameIDFormat:["urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress","urn:oasis:names:tc:SAML:2.0:nameid-format:persistent","urn:oasis:names:tc:SAML:2.0:nameid-format:transient"],SingleSignOnService:[{"@_Binding":"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect","@_Location":t.assertionConsumerServiceUrl},{"@_Binding":"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST","@_Location":t.assertionConsumerServiceUrl}],Attribute:[{"@_Name":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:uri","@_FriendlyName":"E-Mail Address","@_xmlns":"urn:oasis:names:tc:SAML:2.0:assertion"},{"@_Name":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:uri","@_FriendlyName":"Given Name","@_xmlns":"urn:oasis:names:tc:SAML:2.0:assertion"},{"@_Name":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:uri","@_FriendlyName":"Name","@_xmlns":"urn:oasis:names:tc:SAML:2.0:assertion"},{"@_Name":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:uri","@_FriendlyName":"Surname","@_xmlns":"urn:oasis:names:tc:SAML:2.0:assertion"},{"@_Name":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:uri","@_FriendlyName":"Name ID","@_xmlns":"urn:oasis:names:tc:SAML:2.0:assertion"}]}}};return new rw.XMLBuilder({ignoreAttributes:!1,suppressEmptyNode:!0,preserveOrder:!1,format:!0,attributeNamePrefix:"@_"}).build(n)}const v9=new o.OpenAPIHono().openapi(o.createRoute({tags:["saml"],method:"get",path:"/metadata/{client_id}",request:{params:o.z.object({client_id:o.z.string()})},responses:{200:{description:"Decoded SAML Request",content:{"text/xml":{schema:o.z.string()}}},400:{description:"Bad Request"}}}),async t=>{var c,l;const{client_id:e}=t.req.valid("param"),n=await t.env.data.legacyClients.get(e);if(!n)throw new S(404,{message:"Client not found"});const{signingKeys:r}=await t.env.data.keys.list({q:"type:saml_encryption"});if(r.length===0)throw new S(500,{message:"No signing key found"});const i=r.map(d=>new Oc(d.cert).toString("base64")),s=t.env.ISSUER,a=w9({entityId:((l=(c=n.addons)==null?void 0:c.samlp)==null?void 0:l.audience)||n.client_id,certificates:i,assertionConsumerServiceUrl:`${s}samlp/${e}`,singleLogoutServiceUrl:`${s}samlp/${e}/logout`});return new Response(a,{headers:{"Content-Type":"text/xml"}})}).openapi(o.createRoute({tags:["saml"],method:"get",path:"/{client_id}",request:{query:o.z.object({SAMLRequest:o.z.string(),RelayState:o.z.string().optional(),SigAlg:o.z.string().optional(),Signature:o.z.string().optional()}),params:o.z.object({client_id:o.z.string()})},responses:{200:{description:"Decoded SAML Request",content:{"text/xml":{schema:o.z.string()}}},400:{description:"Bad Request"}}}),async t=>{const{client_id:e}=t.req.valid("param"),{SAMLRequest:n,RelayState:r}=t.req.valid("query"),i=await t.env.data.legacyClients.get(e);if(!i)throw new S(404,{message:"Client not found"});t.set("client_id",i.client_id),t.set("tenant_id",i.tenant.id);const s=await y9(n),a=s["samlp:AuthnRequest"]["saml:Issuer"]["#text"],c=await t.env.data.loginSessions.create(t.var.tenant_id,{csrf_token:Ne(),authParams:{client_id:e,state:JSON.stringify({requestId:s["samlp:AuthnRequest"]["@_ID"],relayState:r}),response_mode:Wt.SAML_POST,redirect_uri:s["samlp:AuthnRequest"]["@_AssertionConsumerServiceURL"],audience:a},expires_at:new Date(Date.now()+_r*1e3).toISOString(),ip:t.get("ip"),useragent:t.get("useragent"),auth0Client:Nn(t.get("auth0_client"))});return t.redirect(`/u/login/identifier?state=${c.id}`)});function b9(t){const e=new o.OpenAPIHono;e.use(async(r,i)=>{const s=xo(r,t.dataAdapter),a=t.dataAdapter.cache||Ho({defaultTtlSeconds:0,maxEntries:100,cleanupIntervalMs:0}),c=t.dataAdapter.cache?300:0,l=Dc(s,{defaultTtl:c,cacheEntities:["tenants","connections","clients","branding","themes","promptSettings","forms"],cache:a});return r.env.data=Rc(r,l),i()}),e.use(Uc).use(Lc).use(wp(e));const n=e.route("/",v9);return n.doc("/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"SAML API"},security:[{oauth2:["openid","email","profile"]}]}),yp(n),n}const $9="Account detected",k9="Manage your account details",x9="Account",S9="We have detected that you have already created an account through",z9="By signing in, you agree to our",A9="and",E9="email address",C9="email or phone number",N9="phone number",I9="Callback URL mismatch",j9="The provided redirect_uri is not in the list of allowed callback URLs.",O9="Change email address",T9="continue with user",P9="Please click the button to create a new password account.",R9="Enter the code at {{vendorName}} to complete the login",B9="Welcome to {{vendorName}}! {{code}} is the login code",L9="Welcome to {{vendorName}}! {{code}} is the login code",U9="Code expired",D9="Invalid code",M9="Please check <0>{{username}}</0> and enter the six-digit code that we've sent you.",F9="The code is already used",q9="The code is valid for 30 minutes",H9="A configuration error occurred.",V9="Confirm password",K9="Are you sure you want to unlink this account?",G9="Need Help?",W9="Contact us",J9="or continue with social account",X9="Continue with {{provider}}",Z9="Would you like to continue with your existing account?",Y9="Copyright © 2023 SESAMY. All rights reserved.",Q9="©2023 Sesamy",ez="Choose a password with a mix of uppercase and lowercase letters, numbers, and symbols.",tz="Please enter a valid email address.",nz="The passwords didn't match. Try again.",rz="Choose password",iz="Password must be at least 8 characters long and contain at least one lowercase letter, one uppercase letter, one number and one symbol.",oz="Create new account",sz="Sign up with password",az="Current email address",cz="You are currently logged in as <0>{{email}}</0>",lz="Edit",dz="Email",uz="Email is already taken",pz="Email changed to <0>{{email}}</0> ",fz="Email or Phone Number",hz="Email address",gz="Your email address has been validated",mz="Now enter your password to login again",_z="An email has been sent to <0>{{email}}</0> with a verification link. Please click the link to verify your email address and set a password.",yz="Email verification sent",wz="Enter a code",vz="We'll send you a verification link to ensure you own this email address.",bz="Enter new email",$z="Enter new password",kz="Enter password",xz="Enter your email address and password to login.",Sz="Enter your password",zz="Something went wrong",Az="The magic link has expired. Please click on the button below to receive a new link in your inbox.",Ez="Hey! We updated our login experience. <0>Click here to learn more about it.</0>",Cz="Send password reset email",Nz="Click the button below and we’ll send instructions on how to reset your password.",Iz="Password reset email sent",jz="Forgot password?",Oz="Forgot password?",Tz="Go back",Pz="Hide password",Rz="Invalid identifier",Bz="Invalid password",Lz=`The link is no longer valid.
268
+ `):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}nr.prototype.build=function(t){return this.options.preserveOrder?o9(t,this.options):(Array.isArray(t)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(t={[this.options.arrayNodeName]:t}),this.j2x(t,0,[]).val)};nr.prototype.j2x=function(t,e,n){let r="",i="";const s=n.join(".");for(let a in t)if(Object.prototype.hasOwnProperty.call(t,a))if(typeof t[a]>"u")this.isAttribute(a)&&(i+="");else if(t[a]===null)this.isAttribute(a)?i+="":a[0]==="?"?i+=this.indentate(e)+"<"+a+"?"+this.tagEndChar:i+=this.indentate(e)+"<"+a+"/"+this.tagEndChar;else if(t[a]instanceof Date)i+=this.buildTextValNode(t[a],a,"",e);else if(typeof t[a]!="object"){const c=this.isAttribute(a);if(c&&!this.ignoreAttributesFn(c,s))r+=this.buildAttrPairStr(c,""+t[a]);else if(!c)if(a===this.options.textNodeName){let l=this.options.tagValueProcessor(a,""+t[a]);i+=this.replaceEntitiesValue(l)}else i+=this.buildTextValNode(t[a],a,"",e)}else if(Array.isArray(t[a])){const c=t[a].length;let l="",d="";for(let u=0;u<c;u++){const f=t[a][u];if(!(typeof f>"u"))if(f===null)a[0]==="?"?i+=this.indentate(e)+"<"+a+"?"+this.tagEndChar:i+=this.indentate(e)+"<"+a+"/"+this.tagEndChar;else if(typeof f=="object")if(this.options.oneListGroup){const h=this.j2x(f,e+1,n.concat(a));l+=h.val,this.options.attributesGroupName&&f.hasOwnProperty(this.options.attributesGroupName)&&(d+=h.attrStr)}else l+=this.processTextOrObjNode(f,a,e,n);else if(this.options.oneListGroup){let h=this.options.tagValueProcessor(a,f);h=this.replaceEntitiesValue(h),l+=h}else l+=this.buildTextValNode(f,a,"",e)}this.options.oneListGroup&&(l=this.buildObjectNode(l,a,d,e)),i+=l}else if(this.options.attributesGroupName&&a===this.options.attributesGroupName){const c=Object.keys(t[a]),l=c.length;for(let d=0;d<l;d++)r+=this.buildAttrPairStr(c[d],""+t[a][c[d]])}else i+=this.processTextOrObjNode(t[a],a,e,n);return{attrStr:r,val:i}};nr.prototype.buildAttrPairStr=function(t,e){return e=this.options.attributeValueProcessor(t,""+e),e=this.replaceEntitiesValue(e),this.options.suppressBooleanAttributes&&e==="true"?" "+t:" "+t+'="'+e+'"'};function c9(t,e,n,r){const i=this.j2x(t,n+1,r.concat(e));return t[this.options.textNodeName]!==void 0&&Object.keys(t).length===1?this.buildTextValNode(t[this.options.textNodeName],e,i.attrStr,n):this.buildObjectNode(i.val,e,i.attrStr,n)}nr.prototype.buildObjectNode=function(t,e,n,r){if(t==="")return e[0]==="?"?this.indentate(r)+"<"+e+n+"?"+this.tagEndChar:this.indentate(r)+"<"+e+n+this.closeTag(e)+this.tagEndChar;{let i="</"+e+this.tagEndChar,s="";return e[0]==="?"&&(s="?",i=""),(n||n==="")&&t.indexOf("<")===-1?this.indentate(r)+"<"+e+n+s+">"+t+i:this.options.commentPropName!==!1&&e===this.options.commentPropName&&s.length===0?this.indentate(r)+`<!--${t}-->`+this.newLine:this.indentate(r)+"<"+e+n+s+this.tagEndChar+t+this.indentate(r)+i}};nr.prototype.closeTag=function(t){let e="";return this.options.unpairedTags.indexOf(t)!==-1?this.options.suppressUnpairedNode||(e="/"):this.options.suppressEmptyNode?e="/":e=`></${t}`,e};nr.prototype.buildTextValNode=function(t,e,n,r){if(this.options.cdataPropName!==!1&&e===this.options.cdataPropName)return this.indentate(r)+`<![CDATA[${t}]]>`+this.newLine;if(this.options.commentPropName!==!1&&e===this.options.commentPropName)return this.indentate(r)+`<!--${t}-->`+this.newLine;if(e[0]==="?")return this.indentate(r)+"<"+e+n+"?"+this.tagEndChar;{let i=this.options.tagValueProcessor(e,t);return i=this.replaceEntitiesValue(i),i===""?this.indentate(r)+"<"+e+n+this.closeTag(e)+this.tagEndChar:this.indentate(r)+"<"+e+n+">"+i+"</"+e+this.tagEndChar}};nr.prototype.replaceEntitiesValue=function(t){if(t&&t.length>0&&this.options.processEntities)for(let e=0;e<this.options.entities.length;e++){const n=this.options.entities[e];t=t.replace(n.regex,n.val)}return t};function l9(t){return this.options.indentBy.repeat(t)}function d9(t){return t.startsWith(this.options.attributeNamePrefix)&&t!==this.options.textNodeName?t.substr(this.attrPrefixLen):!1}var u9=nr;const p9=qp,f9=QS,h9=u9;var rw={XMLParser:f9,XMLValidator:p9,XMLBuilder:h9};class iw{constructor(e,n){if(ei(this,"alphabet"),ei(this,"padding"),ei(this,"decodeMap",new Map),e.length!==32)throw new Error("Invalid alphabet");if(this.alphabet=e,this.padding=(n==null?void 0:n.padding)??"=",this.alphabet.includes(this.padding)||this.padding.length!==1)throw new Error("Invalid padding");for(let r=0;r<e.length;r++)this.decodeMap.set(e[r],r)}encode(e,n){let r="",i=0,s=0;for(let a=0;a<e.length;a++)for(i=i<<8|e[a],s+=8;s>=5;)s-=5,r+=this.alphabet[i>>s&31];if(s>0&&(r+=this.alphabet[i<<5-s&31]),(n==null?void 0:n.includePadding)??!0){const a=(8-r.length%8)%8;for(let c=0;c<a;c++)r+="="}return r}decode(e,n){const r=(n==null?void 0:n.strict)??!0,i=Math.ceil(e.length/8),s=[];for(let a=0;a<i;a++){let c=0;const l=[];for(let u=0;u<8;u++){const f=e[a*8+u];if(f==="="){if(a+1!==i)throw new Error(`Invalid character: ${f}`);c+=1;continue}if(f===void 0){if(r)throw new Error("Invalid data");c+=1;continue}const h=this.decodeMap.get(f)??null;if(h===null)throw new Error(`Invalid character: ${f}`);l.push(h)}if(c===8||c===7||c===5||c===2)throw new Error("Invalid padding");const d=(l[0]<<3)+(l[1]>>2);if(s.push(d),c<6){const u=((l[1]&3)<<6)+(l[2]<<1)+(l[3]>>4);s.push(u)}if(c<4){const u=((l[3]&255)<<4)+(l[4]>>1);s.push(u)}if(c<3){const u=((l[4]&1)<<7)+(l[5]<<2)+(l[6]>>3);s.push(u)}if(c<1){const u=((l[6]&7)<<5)+l[7];s.push(u)}}return Uint8Array.from(s)}}new iw("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567");new iw("0123456789ABCDEFGHIJKLMNOPQRSTUV");class ow{constructor(e,n){if(ei(this,"alphabet"),ei(this,"padding"),ei(this,"decodeMap",new Map),e.length!==64)throw new Error("Invalid alphabet");if(this.alphabet=e,this.padding=(n==null?void 0:n.padding)??"=",this.alphabet.includes(this.padding)||this.padding.length!==1)throw new Error("Invalid padding");for(let r=0;r<e.length;r++)this.decodeMap.set(e[r],r)}encode(e,n){let r="",i=0,s=0;for(let a=0;a<e.length;a++)for(i=i<<8|e[a],s+=8;s>=6;)s+=-6,r+=this.alphabet[i>>s&63];if(s>0&&(r+=this.alphabet[i<<6-s&63]),(n==null?void 0:n.includePadding)??!0){const a=(4-r.length%4)%4;for(let c=0;c<a;c++)r+="="}return r}decode(e,n){const r=(n==null?void 0:n.strict)??!0,i=Math.ceil(e.length/4),s=[];for(let a=0;a<i;a++){let c=0,l=0;for(let d=0;d<4;d++){const u=e[a*4+d];if(u==="="){if(a+1!==i)throw new Error(`Invalid character: ${u}`);c+=1;continue}if(u===void 0){if(r)throw new Error("Invalid data");c+=1;continue}const f=this.decodeMap.get(u)??null;if(f===null)throw new Error(`Invalid character: ${u}`);l+=f<<6*(3-d)}s.push(l>>16&255),c<2&&s.push(l>>8&255),c<1&&s.push(l&255)}return Uint8Array.from(s)}}const g9=new ow("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");new ow("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");async function m9(t){const e=new DecompressionStream("deflate-raw"),n=new Uint8Array(t),r=new Blob([n]).stream().pipeThrough(e);return new Uint8Array(await new Response(r).arrayBuffer())}async function _9(t){const e=await g9.decode(t.replace(/ /g,"+"));try{const n=await m9(e);return new TextDecoder().decode(n)}catch(n){return console.warn("Decompression failed, assuming data is not compressed:",n),new TextDecoder().decode(e)}}async function y9(t){const e=await _9(t),n=new rw.XMLParser({attributeNamePrefix:"@_",alwaysCreateTextNode:!0,ignoreAttributes:!1}).parse(e);return J8.parse(n)}function w9(t){const e=t.certificates.map(r=>({"@_use":"signing",KeyInfo:{"@_xmlns":"http://www.w3.org/2000/09/xmldsig#",X509Data:{X509Certificate:r}}})),n={EntityDescriptor:{"@_entityID":t.entityId,"@_xmlns":"urn:oasis:names:tc:SAML:2.0:metadata",IDPSSODescriptor:{"@_protocolSupportEnumeration":"urn:oasis:names:tc:SAML:2.0:protocol",KeyDescriptor:e,SingleLogoutService:[{"@_Binding":"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect","@_Location":t.singleLogoutServiceUrl},{"@_Binding":"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST","@_Location":t.singleLogoutServiceUrl}],NameIDFormat:["urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress","urn:oasis:names:tc:SAML:2.0:nameid-format:persistent","urn:oasis:names:tc:SAML:2.0:nameid-format:transient"],SingleSignOnService:[{"@_Binding":"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect","@_Location":t.assertionConsumerServiceUrl},{"@_Binding":"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST","@_Location":t.assertionConsumerServiceUrl}],Attribute:[{"@_Name":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:uri","@_FriendlyName":"E-Mail Address","@_xmlns":"urn:oasis:names:tc:SAML:2.0:assertion"},{"@_Name":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:uri","@_FriendlyName":"Given Name","@_xmlns":"urn:oasis:names:tc:SAML:2.0:assertion"},{"@_Name":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:uri","@_FriendlyName":"Name","@_xmlns":"urn:oasis:names:tc:SAML:2.0:assertion"},{"@_Name":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:uri","@_FriendlyName":"Surname","@_xmlns":"urn:oasis:names:tc:SAML:2.0:assertion"},{"@_Name":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:uri","@_FriendlyName":"Name ID","@_xmlns":"urn:oasis:names:tc:SAML:2.0:assertion"}]}}};return new rw.XMLBuilder({ignoreAttributes:!1,suppressEmptyNode:!0,preserveOrder:!1,format:!0,attributeNamePrefix:"@_"}).build(n)}const v9=new o.OpenAPIHono().openapi(o.createRoute({tags:["saml"],method:"get",path:"/metadata/{client_id}",request:{params:o.z.object({client_id:o.z.string()})},responses:{200:{description:"Decoded SAML Request",content:{"text/xml":{schema:o.z.string()}}},400:{description:"Bad Request"}}}),async t=>{var c,l;const{client_id:e}=t.req.valid("param"),n=await t.env.data.legacyClients.get(e);if(!n)throw new S(404,{message:"Client not found"});const{signingKeys:r}=await t.env.data.keys.list({q:"type:saml_encryption"});if(r.length===0)throw new S(500,{message:"No signing key found"});const i=r.map(d=>new Oc(d.cert).toString("base64")),s=t.env.ISSUER,a=w9({entityId:((l=(c=n.addons)==null?void 0:c.samlp)==null?void 0:l.audience)||n.client_id,certificates:i,assertionConsumerServiceUrl:`${s}samlp/${e}`,singleLogoutServiceUrl:`${s}samlp/${e}/logout`});return new Response(a,{headers:{"Content-Type":"text/xml"}})}).openapi(o.createRoute({tags:["saml"],method:"get",path:"/{client_id}",request:{query:o.z.object({SAMLRequest:o.z.string(),RelayState:o.z.string().optional(),SigAlg:o.z.string().optional(),Signature:o.z.string().optional()}),params:o.z.object({client_id:o.z.string()})},responses:{200:{description:"Decoded SAML Request",content:{"text/xml":{schema:o.z.string()}}},400:{description:"Bad Request"}}}),async t=>{const{client_id:e}=t.req.valid("param"),{SAMLRequest:n,RelayState:r}=t.req.valid("query"),i=await t.env.data.legacyClients.get(e);if(!i)throw new S(404,{message:"Client not found"});t.set("client_id",i.client_id),t.set("tenant_id",i.tenant.id);const s=await y9(n),a=s["samlp:AuthnRequest"]["saml:Issuer"]["#text"],c=await t.env.data.loginSessions.create(t.var.tenant_id,{csrf_token:Ne(),authParams:{client_id:e,state:JSON.stringify({requestId:s["samlp:AuthnRequest"]["@_ID"],relayState:r}),response_mode:ln.SAML_POST,redirect_uri:s["samlp:AuthnRequest"]["@_AssertionConsumerServiceURL"],audience:a},expires_at:new Date(Date.now()+_r*1e3).toISOString(),ip:t.get("ip"),useragent:t.get("useragent"),auth0Client:Nn(t.get("auth0_client"))});return t.redirect(`/u/login/identifier?state=${c.id}`)});function b9(t){const e=new o.OpenAPIHono;e.use(async(r,i)=>{const s=xo(r,t.dataAdapter),a=t.dataAdapter.cache||Ho({defaultTtlSeconds:0,maxEntries:100,cleanupIntervalMs:0}),c=t.dataAdapter.cache?300:0,l=Dc(s,{defaultTtl:c,cacheEntities:["tenants","connections","clients","branding","themes","promptSettings","forms"],cache:a});return r.env.data=Rc(r,l),i()}),e.use(Uc).use(Lc).use(wp(e));const n=e.route("/",v9);return n.doc("/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"SAML API"},security:[{oauth2:["openid","email","profile"]}]}),yp(n),n}const $9="Account detected",k9="Manage your account details",x9="Account",S9="We have detected that you have already created an account through",z9="By signing in, you agree to our",A9="and",E9="email address",C9="email or phone number",N9="phone number",I9="Callback URL mismatch",j9="The provided redirect_uri is not in the list of allowed callback URLs.",O9="Change email address",T9="continue with user",P9="Please click the button to create a new password account.",R9="Enter the code at {{vendorName}} to complete the login",B9="Welcome to {{vendorName}}! {{code}} is the login code",L9="Welcome to {{vendorName}}! {{code}} is the login code",U9="Code expired",D9="Invalid code",M9="Please check <0>{{username}}</0> and enter the six-digit code that we've sent you.",F9="The code is already used",q9="The code is valid for 30 minutes",H9="A configuration error occurred.",V9="Confirm password",K9="Are you sure you want to unlink this account?",G9="Need Help?",W9="Contact us",J9="or continue with social account",X9="Continue with {{provider}}",Z9="Would you like to continue with your existing account?",Y9="Copyright © 2023 SESAMY. All rights reserved.",Q9="©2023 Sesamy",ez="Choose a password with a mix of uppercase and lowercase letters, numbers, and symbols.",tz="Please enter a valid email address.",nz="The passwords didn't match. Try again.",rz="Choose password",iz="Password must be at least 8 characters long and contain at least one lowercase letter, one uppercase letter, one number and one symbol.",oz="Create new account",sz="Sign up with password",az="Current email address",cz="You are currently logged in as <0>{{email}}</0>",lz="Edit",dz="Email",uz="Email is already taken",pz="Email changed to <0>{{email}}</0> ",fz="Email or Phone Number",hz="Email address",gz="Your email address has been validated",mz="Now enter your password to login again",_z="An email has been sent to <0>{{email}}</0> with a verification link. Please click the link to verify your email address and set a password.",yz="Email verification sent",wz="Enter a code",vz="We'll send you a verification link to ensure you own this email address.",bz="Enter new email",$z="Enter new password",kz="Enter password",xz="Enter your email address and password to login.",Sz="Enter your password",zz="Something went wrong",Az="The magic link has expired. Please click on the button below to receive a new link in your inbox.",Ez="Hey! We updated our login experience. <0>Click here to learn more about it.</0>",Cz="Send password reset email",Nz="Click the button below and we’ll send instructions on how to reset your password.",Iz="Password reset email sent",jz="Forgot password?",Oz="Forgot password?",Tz="Go back",Pz="Hide password",Rz="Invalid identifier",Bz="Invalid password",Lz=`The link is no longer valid.
269
269
 
270
270
  Please make sure to open the login link in the same browser you started the login with.
271
271
 
@@ -295,4 +295,4 @@ Varmista, että avaat kirjautumislinkin samalla selaimella, jolla aloitit kirjau
295
295
 
296
296
  Voit aloittaa uuden kirjautumisen klikkaamalla alla olevaa linkkiä.`,OF="Virheellinen linkki",TF="Linkitetyt tilit",PF="Kirjaudu sisään napsauttamalla painiketta",RF="Kirjaudu sisään",BF="Tai kirjoita koodi osoitteessa {{vendorName}} kirjautumisen loppuun saattamiseksi.",LF="Kirjoita sähköpostiosoitteesi avataksesi tämän ohjelman osoitteessa {{service}}",UF="Yhdistä tilisi {{service}}",DF="Olet kirjautunut sisään nimellä",MF="Kirjaudu sisään",FF="Kirjoita sähköpostiosoitteesi kirjautuaksesi sisään.",qF="Anna sähköpostiosoitteesi, niin lähetämme sinulle kirjautumiskoodin.",HF="Kirjoita sähköpostiosoitteesi tai puhelinnumerosi kirjautuaksesi sisään",VF="Anna sähköpostiosoitteesi, niin lähetämme sinulle kirjautumislinkin.",KF="Anna puhelinnumerosi kirjautuaksesi sisään",GF="Kirjoita {{authMethod}} kirjautuaksesi sisään.",WF="Kirjaudu ulos",JF="Uusi sähköpostiosoite",XF="Yksi kertainen koodi lähetetään uuteen sähköpostiosoitteeseesi, syötä koodi seuraavassa vaiheessa.",ZF="Ei sähköpostiosoitetta asetettu",YF="Ei, haluan käyttää toista tiliä",QF="tai",eq="Salasana",tq="Salasana on nollattu",nq="Menestys",rq="Vaihda salasana tilillesi {{vendorName}} ",iq="Vaihda salasana tilillesi {{vendorName}} ",oq="Puhelinnumero",sq="Tietosuojakäytäntö",aq="Uudelleenohjaus",cq="Vahvista salasana",lq="Rekisteröi uusi salasana",dq="Lähetä koodi uudelleen",uq="Vaihda salasana",pq="Kirjoita alla oleva uusi salasanasi sähköpostitiliä varten: ",fq="Napsauta painiketta salasanasi palauttamiseksi",hq="Napsauta painiketta salasanasi palauttamiseksi",gq="Nollaa salasanasi",mq="Vaihda salasana tilillesi {{vendorName}} ",_q="Nollaa salasana",yq="Lähetä",wq="Lähetä minulle uusi maaginen linkki",vq="Muista tarkistaa roskapostikansiosi, jos sähköposti ei ole saapunut.",bq="Aseta salasana",$q="Näytä salasana",kq="Kirjaudu sisään",xq="Rekisteröityminen",Sq="Rekisteröidy onnistuneesti",zq="{{code}} on kirjautumiskoodisi {{vendorName}}",Aq="Näyttää siltä, että Spotify-tilisi on tällä hetkellä yhdistetty toiseen Sesamy-tiliin. Mutta älä pelkää, me opastamme sinua prosessin läpi, jotta saat tämän korjattua.",Eq="Siirry Spotifyn Content Access -sivulle",Cq='Aloitetaan poistamalla Spotify-tilisi linkitys. Klikkaa alla olevaa painiketta siirtyäksesi Spotifyn Content Access -sivulle. Kun olet kirjautunut sisään Spotify-tilillesi, etsi Sesamy yhdistettyjen alustojen luettelosta. Napsauta "Unlink" Sesamyn logon vieressä.',Nq="Vaihe 1: Poista Spotify-tilisi linkitys",Iq="Kun olet onnistuneesti irrottanut Spotify-tilisi, voit yhdistää sen uudelleen Sesamyn kanssa. Toista vain aiemmin tekemäsi vaiheet, jotka johtivat sinut tälle sivulle.",jq="Vaihe 2: Yhdistä Spotify-tilisi uudelleen Sesamyn kanssa",Oq="Hups! Spotify-tilisi on jo linkitetty",Tq="Valmis",Pq="Jos sinulla on kysyttävää tai tarvitset apua, voit ottaa yhteyttä tukitiimiimme.",Rq="Ehdot ja edellytykset",Bq="Jokin meni pieleen. Yritä uudelleen.",Lq="Irrota",Uq="Sähköpostiosoitteesi on vahvistettava. Olemme lähettäneet uuden sähköpostiviestin sähköpostiisi.",Dq="Päivitä sähköposti",Mq="Käyttäjätiliä ei ole olemassa",Fq="Käyttäjätiliä ei ole olemassa",qq="Emme löytäneet käyttäjää, jolla on annettu sähköpostiosoite. Yritä uudelleen.",Hq="Yritä uudelleen.",Vq="Validoi koodi",Kq="Tarkista sähköpostin vahvistusohjeet postilaatikostasi.",Gq="Rekisteröitynyt",Wq="Vahvista sähköpostiosoitteesi napsauttamalla painiketta",Jq="Vahvista sähköpostiosoitteesi",Xq="Vahvista sähköpostiosoitteesi",Zq="Vahvista tili",Yq="Vahvista sähköpostiosoitteesi",Qq="Tervetuloa",eH="Tervetuloa tilillesi {{vendorName}}!",tH="Tarkista sähköpostisi osoitteesta <0>{{email}}</0> ja syötä lähettämämme kuusinumeroinen koodi.",nH="Jatka tällä tilillä",rH="Kyllä, jatka {{text}}",iH="Kyllä, jatka olemassa olevalla tilillä",oH={account_detected:mM,account_page_description:_M,account_title:yM,account_with_sso_provider:wM,agree_to:vM,and:bM,auth_method_email:$M,auth_method_email_or_phone:kM,auth_method_phone:xM,callback_url_mismatch:SM,callback_url_not_allowed:zM,change_email:AM,check_email_title:EM,click_to_sign_up_description:CM,code_email_enter_code:NM,code_email_subject:IM,code_email_title:jM,code_expired:OM,code_invalid:TM,code_sent_template:PM,code_used:RM,code_valid_30_minutes:BM,configuration_error_message:LM,confirm_password:UM,confirm_unlink:DM,contact_support:MM,contact_us:FM,continue:"Jatka",continue_social_login:qM,continue_with:HM,continue_with_sso_provider_headline:VM,copyright:KM,copyright_sesamy:GM,create_account_description:WM,create_account_email_invalid:JM,create_account_passwords_didnt_match:XM,create_account_title:ZM,create_account_weak_password:YM,create_new_account_link:QM,create_password_account_title:eF,current_email:tF,currently_logged_in_as:nF,edit:rF,email:iF,email_already_taken:oF,email_changed_to_template:sF,email_or_phone_placeholder:aF,email_placeholder:cF,email_validated:lF,email_validated_cta:dF,email_verification_for_signup_sent_description:uF,email_verification_for_signup_sent_title:pF,enter_a_code_btn:fF,enter_email_for_verification_description:hF,enter_new_email:gF,enter_new_password_placeholder:mF,enter_password:_F,enter_password_description:yF,enter_your_password_btn:wF,error_page_title:vF,expired_code:bF,fokus_info_message:$F,forgot_password_cta:kF,forgot_password_description:xF,forgot_password_email_sent:SF,forgot_password_link:zF,forgot_password_title:AF,go_back:EF,hide_password:CF,"invalid-email":"Virheellinen sähköpostiosoite",invalid_identifier:NF,invalid_password:IF,invalid_session_body:jF,invalid_session_title:OF,linked_accounts:TF,link_email_click_to_login:PF,link_email_login:RF,link_email_or_enter_code:BF,link_page_body:LF,link_page_headline:UF,logged_in_as:DF,login:MF,login_description:FF,login_description_code:qF,login_description_combined:HF,login_description_link:VF,login_description_phone:KF,login_description_template:GF,logout:WF,new_email:JF,new_email_code_info:XF,no_email_address:ZF,no_use_another:YF,or:QF,password:eq,password_has_been_reset:tq,password_has_been_reset_title:nq,password_reset_subject:rq,password_reset_title:iq,phone_placeholder:oq,privacy_policy:sq,redirecting:aq,reenter_new_password_placeholder:cq,register_password_account:lq,resend_code:dq,reset_password_cta:uq,reset_password_description:pq,reset_password_email_click_to_reset:fq,reset_password_email_cta:hq,reset_password_email_reset:gq,reset_password_subject:mq,reset_password_title:_q,send:yq,send_me_a_new_magic_link:wq,sent_code_spam:vq,"Server error: Invalid code":"Virheellinen koodi",set_password:bq,show_password:$q,sign_in:kq,signup:xq,signup_success:Sq,sms_code_text:zq,spotify_already_linked_body:Aq,spotify_already_linked_cta:Eq,spotify_already_linked_step1_body:Cq,spotify_already_linked_step1_title:Nq,spotify_already_linked_step2_body:Iq,spotify_already_linked_step2_title:jq,spotify_already_linked_title:Oq,success:Tq,support_info:Pq,terms:Rq,unexpected_error_try_again:Bq,unlink:Lq,unverified_email:Uq,update_email:Dq,user_account_does_not_exist:Mq,user_not_found:Fq,user_not_found_body:qq,user_not_found_cta:Hq,validate_code:Vq,validate_email_body:Kq,validate_email_title:Gq,verify_email_click_to_verify:Wq,verify_email_subject:Jq,verify_email_title:Xq,verify_email_verify:Zq,verify_your_email:Yq,welcome:Qq,welcome_to_your_account:eH,we_sent_a_code_to:tH,yes_continue:nH,yes_continue_with:rH,yes_continue_with_existing_account:iH},sH="Konto opdaget",aH="Administrer dine kontooplysninger",cH="Konto",lH="Vi har opdaget, at du allerede har oprettet en konto gennem",dH="Når du logger ind, accepterer du vores",uH="og",pH="e-mail-adresse",fH="e-mail eller telefonnummer",hH="Telefonnummer",gH="Uoverensstemmelse mellem URL og tilbagekald",mH="Den angivne redirect_uri er ikke på listen over tilladte tilbagekalds-URL'er.",_H="Ændre e-mailadresse",yH="Fortsæt med brugeren",wH="Klik på knappen for at oprette en ny adgangskodekonto.",vH="Indtast koden på {{vendorName}} for at gennemføre login.",bH="Velkommen til {{vendorName}}! {{code}} er login-koden",$H="Velkommen til {{vendorName}}! {{code}} er login-koden",kH="Koden er udløbet",xH="Ugyldig kode",SH="Tjek venligst <0>{{username}}</0> og indtast den sekscifrede kode, som vi har sendt til dig.",zH="Koden er allerede brugt",AH="Koden er gyldig i 30 minutter",EH="Der opstod en konfigurationsfejl.",CH="Bekræft adgangskode",NH="Er du sikker på, at du vil fjerne forbindelsen til denne konto?",IH="Har du brug for hjælp?",jH="Kontakt os",OH="eller fortsæt med social konto",TH="Fortsæt med {{provider}}",PH="Vil du gerne fortsætte med din eksisterende konto?",RH="Ophavsret © 2023 SESAMY. Alle rettigheder forbeholdes.",BH="©2023 Sesamy",LH="Vælg en adgangskode med en blanding af store og små bogstaver, tal og symboler.",UH="Indtast venligst en gyldig e-mailadresse.",DH="Adgangskoderne stemte ikke overens. Prøv igen.",MH="Vælg adgangskode",FH="Adgangskoden skal være mindst 8 tegn lang og indeholde mindst et lille bogstav, et stort bogstav, et tal og et symbol.",qH="Opret ny konto",HH="Tilmeld dig med adgangskode",VH="Nuværende e-mailadresse",KH="Du er i øjeblikket logget ind som <0>{{email}}</0>",GH="Rediger",WH="E-mail",JH="E-mailen er allerede optaget",XH="E-mail ændret til <0>{{email}}</0> ",ZH="E-mail eller telefonnummer",YH="E-mail-adresse",QH="Din e-mailadresse er blevet valideret",eV="Indtast nu din adgangskode for at logge ind igen",tV="Der er sendt en e-mail til <0>{{email}}</0> med et bekræftelseslink. Klik på linket for at bekræfte din e-mailadresse og angive en adgangskode.",nV="E-mail-bekræftelse sendt",rV="Indtast en kode",iV="Vi sender dig et bekræftelseslink for at sikre, at du ejer denne e-mailadresse.",oV="Indtast ny e-mail",sV="Indtast ny adgangskode",aV="Indtast adgangskode",cV="Indtast din e-mailadresse og adgangskode for at logge ind.",lV="Indtast din adgangskode",dV="Noget gik galt",uV="Det magiske link er udløbet. Klik på knappen nedenfor for at modtage et nyt link i din indbakke.",pV="Hej! Vi har opdateret vores login-oplevelse. <0>Klik her for at lære mere om det.</0>",fV="Send e-mail til nulstilling af adgangskode",hV="Klik på knappen nedenfor, så sender vi instruktioner om, hvordan du nulstiller din adgangskode.",gV="E-mail til nulstilling af adgangskode sendt",mV="Har du glemt din adgangskode?",_V="Har du glemt din adgangskode?",yV="Gå tilbage",wV="Skjul adgangskode",vV="Ugyldig identifikator",bV="Ugyldig adgangskode",$V="Linket er ikke længere gyldigt. Sørg for at åbne login-linket i den samme browser, som du startede login med. Du kan klikke på linket nedenfor for at starte et nyt login.",kV="Ugyldigt link",xV="Koblede konti",SV="Klik på knappen for at logge ind",zV="Login",AV="Eller indtast koden på {{vendorName}} for at gennemføre login.",EV="Indtast din e-mailadresse for at låse op for dette show på {{service}}",CV="Forbind din konto med {{service}}",NV="Du er logget ind som",IV="Login",jV="Indtast din e-mailadresse for at logge ind.",OV="Indtast din e-mailadresse, så sender vi dig en login-kode.",TV="Indtast din e-mail eller dit telefonnummer for at logge ind",PV="Indtast din e-mailadresse, så sender vi dig et login-link.",RV="Indtast dit telefonnummer for at logge ind",BV="Indtast din {{authMethod}} for at logge ind.",LV="Log ud",UV="Ny emailadresse",DV="En engangskode vil blive sendt til din nye e-mailadresse, indtast koden i næste trin.",MV="Ingen e-mailadresse er angivet",FV="Nej, jeg vil bruge en anden konto",qV="eller",HV="Adgangskode",VV="Adgangskoden er blevet nulstillet",KV="Succes",GV="Skift adgangskode til din {{vendorName}} -konto",WV="Skift adgangskode til din {{vendorName}} -konto",JV="Telefonnummer",XV="Politik for beskyttelse af personlige oplysninger",ZV="Omdirigering",YV="Bekræft adgangskode",QV="Registrer en ny adgangskode",eK="Send koden igen",tK="Skift adgangskode",nK="Indtast din nye adgangskode til e-mailkontoen nedenfor: ",rK="Klik på knappen for at nulstille din adgangskode",iK="Klik på knappen for at nulstille din adgangskode",oK="Nulstil din adgangskode",sK="Skift adgangskode til din {{vendorName}} -konto",aK="Nulstil adgangskode",cK="Send",lK="Send mig et nyt magisk link",dK="Husk at tjekke din spam-mappe, hvis e-mailen ikke er kommet frem.",uK="Indstil adgangskode",pK="Vis adgangskode",fK="Log ind",hK="Tilmelding",gK="Tilmeld dig med succes",mK="{{code}} er din login-kode til {{vendorName}}",_K="Det ser ud til, at din Spotify-konto i øjeblikket er knyttet til en anden Sesamy-konto. Men frygt ikke, vi er her for at guide dig gennem processen med at få det løst.",yK="Gå til Spotifys side for adgang til indhold",wK='Lad os starte med at fjerne forbindelsen til din Spotify-konto. Klik på knappen nedenfor for at gå til Spotifys Content Access-side. Når du har logget ind på din Spotify-konto, skal du finde Sesamy på listen over tilsluttede platforme. Klik på "Unlink" ved siden af Sesamy-logoet.',vK="Trin 1: Fjern forbindelsen til din Spotify-konto",bK="Når du har afkoblet din Spotify-konto, kan du koble den til Sesamy igen. Du skal blot gentage de trin, du tidligere har taget, og som førte dig til denne side.",$K="Trin 2: Relink din Spotify-konto til Sesamy",kK="Ups! Din Spotify-konto er allerede forbundet",xK="Færdig",SK="Hvis du har spørgsmål eller brug for hjælp, kan du kontakte vores supportteam",zK="Vilkår og betingelser",AK="Noget gik galt. Prøv venligst igen.",EK="Frakobl",CK="Din e-mailadresse skal valideres. Vi har sendt en ny e-mail til din indbakke",NK="Opdatering af e-mail",IK="Brugerkontoen findes ikke",jK="Brugerkontoen findes ikke",OK="Vi kunne ikke finde en bruger med den angivne e-mailadresse. Prøv venligst igen.",TK="Prøv igen.",PK="Valider koden",RK="Tjek din indbakke for instruktioner om validering af e-mail.",BK="Tilmeldte sig",LK="Klik på knappen for at bekræfte din e-mailadresse",UK="Bekræft din e-mailadresse",DK="Bekræft din e-mailadresse",MK="Bekræft konto",FK="Bekræft din e-mail",qK="Velkommen",HK="Velkommen til din {{vendorName}} konto!",VK="Tjek venligst din e-mail på <0>{{email}}</0> og indtast den sekscifrede kode, vi har sendt dig.",KK="Fortsæt med denne konto",GK="Ja, fortsæt med {{text}}",WK="Ja, fortsæt med eksisterende konto",JK={account_detected:sH,account_page_description:aH,account_title:cH,account_with_sso_provider:lH,agree_to:dH,and:uH,auth_method_email:pH,auth_method_email_or_phone:fH,auth_method_phone:hH,callback_url_mismatch:gH,callback_url_not_allowed:mH,change_email:_H,check_email_title:yH,click_to_sign_up_description:wH,code_email_enter_code:vH,code_email_subject:bH,code_email_title:$H,code_expired:kH,code_invalid:xH,code_sent_template:SH,code_used:zH,code_valid_30_minutes:AH,configuration_error_message:EH,confirm_password:CH,confirm_unlink:NH,contact_support:IH,contact_us:jH,continue:"Fortsæt",continue_social_login:OH,continue_with:TH,continue_with_sso_provider_headline:PH,copyright:RH,copyright_sesamy:BH,create_account_description:LH,create_account_email_invalid:UH,create_account_passwords_didnt_match:DH,create_account_title:MH,create_account_weak_password:FH,create_new_account_link:qH,create_password_account_title:HH,current_email:VH,currently_logged_in_as:KH,edit:GH,email:WH,email_already_taken:JH,email_changed_to_template:XH,email_or_phone_placeholder:ZH,email_placeholder:YH,email_validated:QH,email_validated_cta:eV,email_verification_for_signup_sent_description:tV,email_verification_for_signup_sent_title:nV,enter_a_code_btn:rV,enter_email_for_verification_description:iV,enter_new_email:oV,enter_new_password_placeholder:sV,enter_password:aV,enter_password_description:cV,enter_your_password_btn:lV,error_page_title:dV,expired_code:uV,fokus_info_message:pV,forgot_password_cta:fV,forgot_password_description:hV,forgot_password_email_sent:gV,forgot_password_link:mV,forgot_password_title:_V,go_back:yV,hide_password:wV,"invalid-email":"Ugyldig e-mail",invalid_identifier:vV,invalid_password:bV,invalid_session_body:$V,invalid_session_title:kV,linked_accounts:xV,link_email_click_to_login:SV,link_email_login:zV,link_email_or_enter_code:AV,link_page_body:EV,link_page_headline:CV,logged_in_as:NV,login:IV,login_description:jV,login_description_code:OV,login_description_combined:TV,login_description_link:PV,login_description_phone:RV,login_description_template:BV,logout:LV,new_email:UV,new_email_code_info:DV,no_email_address:MV,no_use_another:FV,or:qV,password:HV,password_has_been_reset:VV,password_has_been_reset_title:KV,password_reset_subject:GV,password_reset_title:WV,phone_placeholder:JV,privacy_policy:XV,redirecting:ZV,reenter_new_password_placeholder:YV,register_password_account:QV,resend_code:eK,reset_password_cta:tK,reset_password_description:nK,reset_password_email_click_to_reset:rK,reset_password_email_cta:iK,reset_password_email_reset:oK,reset_password_subject:sK,reset_password_title:aK,send:cK,send_me_a_new_magic_link:lK,sent_code_spam:dK,"Server error: Invalid code":"Ugyldig kode",set_password:uK,show_password:pK,sign_in:fK,signup:hK,signup_success:gK,sms_code_text:mK,spotify_already_linked_body:_K,spotify_already_linked_cta:yK,spotify_already_linked_step1_body:wK,spotify_already_linked_step1_title:vK,spotify_already_linked_step2_body:bK,spotify_already_linked_step2_title:$K,spotify_already_linked_title:kK,success:xK,support_info:SK,terms:zK,unexpected_error_try_again:AK,unlink:EK,unverified_email:CK,update_email:NK,user_account_does_not_exist:IK,user_not_found:jK,user_not_found_body:OK,user_not_found_cta:TK,validate_code:PK,validate_email_body:RK,validate_email_title:BK,verify_email_click_to_verify:LK,verify_email_subject:UK,verify_email_title:DK,verify_email_verify:MK,verify_your_email:FK,welcome:qK,welcome_to_your_account:HK,we_sent_a_code_to:VK,yes_continue:KK,yes_continue_with:GK,yes_continue_with_existing_account:WK},XK=({...t})=>p("svg",{width:"45",height:"45",viewBox:"0 0 45 45",xmlns:"http://www.w3.org/2000/svg",...t,children:[p("path",{d:"M44.1035 23.0123C44.1054 21.4791 43.9758 19.9486 43.716 18.4375H22.498V27.1028H34.6507C34.4021 28.4868 33.8757 29.8061 33.1034 30.9812C32.3311 32.1562 31.3289 33.1628 30.1571 33.9401V39.5649H37.41C41.6567 35.6494 44.1035 29.859 44.1035 23.0123Z",fill:"#4285F4"}),p("path",{d:"M22.4982 44.9997C28.5698 44.9997 33.6821 43.0061 37.4101 39.5687L30.1573 33.9439C28.1386 35.3126 25.5387 36.0938 22.4982 36.0938C16.6296 36.0938 11.6485 32.1377 9.86736 26.8066H2.39575V32.6033C4.26839 36.3297 7.13989 39.4622 10.6896 41.6512C14.2394 43.8402 18.3277 44.9995 22.4982 44.9997Z",fill:"#34A853"}),p("path",{d:"M9.86737 26.8073C8.92572 24.0138 8.92572 20.9886 9.86737 18.1951V12.3984H2.39576C0.820432 15.5332 0 18.9929 0 22.5012C0 26.0095 0.820432 29.4692 2.39576 32.604L9.86737 26.8073Z",fill:"#FBBC04"}),p("path",{d:"M22.4982 8.90741C25.7068 8.85499 28.8071 10.0673 31.1291 12.2823L37.5507 5.86064C33.4788 2.03602 28.0843 -0.0637686 22.4982 0.00147616C18.3277 0.00166623 14.2394 1.16098 10.6896 3.34999C7.13989 5.539 4.26839 8.67155 2.39575 12.3979L9.86736 18.1946C11.6485 12.8635 16.6296 8.90741 22.4982 8.90741Z",fill:"#EA4335"})]}),ZK=t=>{const{theme:e,branding:n,client:r,authParams:i}=t,a=`/authorize?${new URLSearchParams({...i})}`;return p(De,{theme:e,branding:n,client:r,title:w.t("user_not_found"),children:p("div",{className:"flex flex-1 flex-col justify-center",children:[p("p",{className:"mb-8 text-gray-300 text-lg",children:w.t("user_not_found_body")}),p(Ue,{Component:"a",href:a,children:w.t("user_not_found_cta")})]})})},YK=({...t})=>p("svg",{version:"1.1",id:"Layer_1",xmlns:"http://www.w3.org/2000/svg",x:"0px",y:"0px",viewBox:"0 0 48 48",enableBackground:"new 0 0 48 48",width:"45",height:"45",...t,children:[p("path",{fill:"#FF5B24",d:"M3.5,8h41c1.9,0,3.5,1.6,3.5,3.5v25c0,1.9-1.6,3.5-3.5,3.5h-41C1.6,40,0,38.4,0,36.5v-25C0,9.6,1.6,8,3.5,8z"}),p("path",{fillRule:"evenodd",clipRule:"evenodd",fill:"#FFFFFF",d:`M27.9,20.3c1.4,0,2.6-1,2.6-2.5h0c0-1.5-1.2-2.5-2.6-2.5c-1.4,0-2.6,1-2.6,2.5C25.3,19.2,26.5,20.3,27.9,20.3z
297
297
  M31.2,24.4c-1.7,2.2-3.5,3.8-6.7,3.8h0c-3.2,0-5.8-2-7.7-4.8c-0.8-1.2-2-1.4-2.9-0.8c-0.8,0.6-1,1.8-0.3,2.9
298
- c2.7,4.1,6.5,6.6,10.9,6.6c4,0,7.2-2,9.6-5.2c0.9-1.2,0.9-2.5,0-3.1C33.3,22.9,32.1,23.2,31.2,24.4z`})]});function QK(t,e){const{mainTenantId:n,mainClientId:r}=e;return{...t,legacyClients:{get:async i=>{const s=await t.legacyClients.get(i);if(!s)return null;const a=r?await t.legacyClients.get(r):void 0,c=await t.connections.list(s.tenant.id),l=n?await t.connections.list(n):{connections:[]},d=c.connections.map(u=>{var m;const f=(m=l.connections)==null?void 0:m.find(y=>y.name===u.name);if(!(f!=null&&f.options))return u;const h=Kt.parse({...f||{},...u});return h.options=Wr.passthrough().parse({...f.options||{},...u.options}),h}).filter(u=>u);return{...s,web_origins:[...(a==null?void 0:a.web_origins)||[],...s.web_origins||[]],allowed_logout_urls:[...(a==null?void 0:a.allowed_logout_urls)||[],...s.allowed_logout_urls||[]],callbacks:[...(a==null?void 0:a.callbacks)||[],...s.callbacks||[]],connections:d,tenant:{...(a==null?void 0:a.tenant)||{},...s.tenant}}}},connections:{...t.connections,get:async(i,s)=>{const a=await t.connections.get(i,s);if(!a||!n)return a;const c=await t.connections.get(n,s);if(!c)return a;const l=Kt.parse({...c,...a});return l.options=Wr.passthrough().parse({...c.options||{},...a.options}),l},list:async(i,s)=>{const a=await t.connections.list(i,s);if(!n||i===n)return a;const c=await t.connections.list(n),l=a.connections.map(d=>{var h;const u=(h=c.connections)==null?void 0:h.find(m=>m.name===d.name);if(!(u!=null&&u.options))return d;const f=Kt.parse({...u,...d});return f.options=Wr.passthrough().parse({...u.options||{},...d.options}),f});return{...a,connections:l}}}}}function eG(t,e){return QK(t,e)}w.init({supportedLngs:["en","it","nb","sv","pl","cs","fi","da"],fallbackLng:"en",resources:{en:{translation:uA},it:{translation:tN},nb:{translation:Vj},sv:{translation:PP},pl:{translation:SL},cs:{translation:gM},fi:{translation:oH},da:{translation:JK}}});function tG(t){const e=new o.OpenAPIHono;e.use("*",async(a,c)=>{t.hooks&&(a.env.hooks={...t.hooks,...a.env.hooks||{}}),t.samlSigner&&(a.env.samlSigner=t.samlSigner),await c()}),e.get("/",a=>a.json({name:"authhero"}));const n=F4(t);e.route("/api/v2",n);const r=V8(t);e.route("/u",r);const i=b9(t);e.route("/samlp",i);const s=jx(t);return e.route("/",s),{app:e,managementApp:n,oauthApp:s,samlApp:i,universalApp:r,createX509Certificate:Xd}}exports.AppLogo=rn;exports.Auth0Client=F0;exports.AuthLayout=Oe;exports.AuthorizationResponseMode=Wt;exports.AuthorizationResponseType=Nt;exports.Button=Ue;exports.ButtonUI=fn;exports.CardContent=bn;exports.CardDescription=vn;exports.CardFooter=N1;exports.CardHeader=yn;exports.CardTitle=wn;exports.CardUI=_n;exports.CheckEmailPage=V1;exports.CodeChallengeMethod=Pa;exports.ComponentCategory=_u;exports.ComponentType=mu;exports.EmailValidatedPage=W1;exports.EnterCodePage=du;exports.EnterPasswordPage=Es;exports.ErrorMessage=et;exports.Footer=I1;exports.ForgotPasswordPage=q1;exports.ForgotPasswordSentPage=H1;exports.FormComponent=on;exports.GoBack=It;exports.GoogleLogo=XK;exports.GrantType=Vt;exports.HttpSamlSigner=Im;exports.Icon=Ke;exports.IdentifierForm=xs;exports.IdentifierPage=Ss;exports.InputUI=Qt;exports.InvalidSession=G1;exports.LabelUI=Lt;exports.Layout=De;exports.LogTypes=_e;exports.Message=Dt;exports.NodeType=x0;exports.PreSignUpConfirmationPage=J1;exports.PreSignUpPage=K1;exports.ResetPasswordPage=Hr;exports.SignUpPage=ir;exports.SocialButton=O1;exports.Spinner=j1;exports.Trans=Yn;exports.UnverifiedEmailPage=F1;exports.UserNotFoundPage=ZK;exports.VippsLogo=YK;exports.auth0FlowInsertSchema=Ow;exports.auth0FlowSchema=I0;exports.auth0UserResponseSchema=cn;exports.authParamsSchema=ro;exports.baseUserSchema=Oa;exports.bordersSchema=K0;exports.brandingSchema=kl;exports.buttonComponentSchema=w0;exports.clientGrantInsertSchema=Ps;exports.clientGrantListSchema=jw;exports.clientGrantSchema=ar;exports.clientInsertSchema=Ts;exports.clientSchema=sr;exports.codeInsertSchema=O0;exports.codeSchema=Tw;exports.codeTypeSchema=j0;exports.colorsSchema=G0;exports.componentSchema=k0;exports.connectionInsertSchema=Rs;exports.connectionOptionsSchema=Wr;exports.connectionSchema=Kt;exports.coordinatesSchema=wi;exports.createInMemoryCache=Ho;exports.customDomainInsertSchema=yu;exports.customDomainSchema=Ln;exports.customDomainWithTenantIdSchema=Pw;exports.emailProviderSchema=fs;exports.endingSchema=N0;exports.fieldComponentSchema=b0;exports.flowNodeSchema=z0;exports.fontDetailsSchema=rr;exports.fontsSchema=W0;exports.formControlSchema=Rw;exports.formInsertSchema=Bs;exports.formNodeComponentDefinition=P0;exports.formSchema=Vr;exports.genericComponentSchema=$0;exports.genericNodeSchema=A0;exports.hookInsertSchema=ds;exports.hookSchema=Kr;exports.identitySchema=_0;exports.init=tG;exports.injectTailwindCSS=B8;exports.inviteInsertSchema=wu;exports.inviteSchema=Gi;exports.inviteeSchema=U0;exports.inviterSchema=L0;exports.jwksKeySchema=D0;exports.jwksSchema=vu;exports.legalComponentSchema=v0;exports.logSchema=Ls;exports.loginSessionInsertSchema=M0;exports.loginSessionSchema=Mw;exports.nodeSchema=E0;exports.openIDConfigurationSchema=xl;exports.organizationBrandingSchema=dm;exports.organizationEnabledConnectionSchema=um;exports.organizationInsertSchema=Fs;exports.organizationSchema=Dn;exports.organizationTokenQuotaSchema=pm;exports.pageBackgroundSchema=J0;exports.parseUserId=Qw;exports.passwordInsertSchema=q0;exports.passwordSchema=qw;exports.profileDataSchema=m0;exports.promptSettingSchema=ps;exports.refreshTokenInsertSchema=$u;exports.refreshTokenSchema=Hw;exports.resourceServerInsertSchema=Us;exports.resourceServerListSchema=Gw;exports.resourceServerOptionsSchema=Q0;exports.resourceServerSchema=cr;exports.resourceServerScopeSchema=Y0;exports.richTextComponentSchema=y0;exports.roleInsertSchema=Ds;exports.roleListSchema=Ms;exports.rolePermissionInsertSchema=em;exports.rolePermissionListSchema=Ww;exports.rolePermissionSchema=tm;exports.rolePermissionWithDetailsListSchema=rm;exports.rolePermissionWithDetailsSchema=nm;exports.roleSchema=lr;exports.sessionInsertSchema=V0;exports.sessionSchema=Ba;exports.signingKeySchema=Sl;exports.smsProviderSchema=Kw;exports.smsSendParamsSchema=Vw;exports.startSchema=C0;exports.stepNodeSchema=S0;exports.tailwindCss=Fp;exports.tenantInsertSchema=Ki;exports.tenantSchema=Un;exports.tenantSettingsSchema=Yw;exports.themeInsertSchema=Z0;exports.themeSchema=us;exports.tokenResponseSchema=bu;exports.totalsSchema=St;exports.userInsertSchema=Os;exports.userOrganizationInsertSchema=fm;exports.userOrganizationSchema=Zw;exports.userPermissionInsertSchema=im;exports.userPermissionListSchema=Jw;exports.userPermissionSchema=om;exports.userPermissionWithDetailsListSchema=am;exports.userPermissionWithDetailsSchema=sm;exports.userResponseSchema=Cw;exports.userRoleInsertSchema=cm;exports.userRoleListSchema=Xw;exports.userRoleSchema=lm;exports.userSchema=gu;exports.verificationMethodsSchema=T0;exports.waitUntil=ve;exports.widgetSchema=X0;exports.withMainTenantFallback=eG;
298
+ c2.7,4.1,6.5,6.6,10.9,6.6c4,0,7.2-2,9.6-5.2c0.9-1.2,0.9-2.5,0-3.1C33.3,22.9,32.1,23.2,31.2,24.4z`})]});function QK(t,e){const{mainTenantId:n,mainClientId:r}=e;return{...t,legacyClients:{get:async i=>{const s=await t.legacyClients.get(i);if(!s)return null;const a=r?await t.legacyClients.get(r):void 0,c=await t.connections.list(s.tenant.id),l=n?await t.connections.list(n):{connections:[]},d=c.connections.map(u=>{var m;const f=(m=l.connections)==null?void 0:m.find(y=>y.name===u.name);if(!(f!=null&&f.options))return u;const h=Kt.parse({...f||{},...u});return h.options=Wr.passthrough().parse({...f.options||{},...u.options}),h}).filter(u=>u);return{...s,web_origins:[...(a==null?void 0:a.web_origins)||[],...s.web_origins||[]],allowed_logout_urls:[...(a==null?void 0:a.allowed_logout_urls)||[],...s.allowed_logout_urls||[]],callbacks:[...(a==null?void 0:a.callbacks)||[],...s.callbacks||[]],connections:d,tenant:{...(a==null?void 0:a.tenant)||{},...s.tenant}}}},connections:{...t.connections,get:async(i,s)=>{const a=await t.connections.get(i,s);if(!a||!n)return a;const c=await t.connections.get(n,s);if(!c)return a;const l=Kt.parse({...c,...a});return l.options=Wr.passthrough().parse({...c.options||{},...a.options}),l},list:async(i,s)=>{const a=await t.connections.list(i,s);if(!n||i===n)return a;const c=await t.connections.list(n),l=a.connections.map(d=>{var h;const u=(h=c.connections)==null?void 0:h.find(m=>m.name===d.name);if(!(u!=null&&u.options))return d;const f=Kt.parse({...u,...d});return f.options=Wr.passthrough().parse({...u.options||{},...d.options}),f});return{...a,connections:l}}}}}function eG(t,e){return QK(t,e)}w.init({supportedLngs:["en","it","nb","sv","pl","cs","fi","da"],fallbackLng:"en",resources:{en:{translation:uA},it:{translation:tN},nb:{translation:Vj},sv:{translation:PP},pl:{translation:SL},cs:{translation:gM},fi:{translation:oH},da:{translation:JK}}});function tG(t){const e=new o.OpenAPIHono;e.use("*",async(a,c)=>{t.hooks&&(a.env.hooks={...t.hooks,...a.env.hooks||{}}),t.samlSigner&&(a.env.samlSigner=t.samlSigner),await c()}),e.get("/",a=>a.json({name:"authhero"}));const n=F4(t);e.route("/api/v2",n);const r=V8(t);e.route("/u",r);const i=b9(t);e.route("/samlp",i);const s=jx(t);return e.route("/",s),{app:e,managementApp:n,oauthApp:s,samlApp:i,universalApp:r,createX509Certificate:Xd}}exports.AppLogo=nn;exports.Auth0Client=F0;exports.AuthLayout=Oe;exports.AuthorizationResponseMode=ln;exports.AuthorizationResponseType=Bt;exports.Button=Ue;exports.ButtonUI=fn;exports.CardContent=bn;exports.CardDescription=vn;exports.CardFooter=N1;exports.CardHeader=yn;exports.CardTitle=wn;exports.CardUI=_n;exports.CheckEmailPage=V1;exports.CodeChallengeMethod=Pa;exports.ComponentCategory=_u;exports.ComponentType=mu;exports.EmailValidatedPage=W1;exports.EnterCodePage=du;exports.EnterPasswordPage=Es;exports.ErrorMessage=et;exports.Footer=I1;exports.ForgotPasswordPage=q1;exports.ForgotPasswordSentPage=H1;exports.FormComponent=rn;exports.GoBack=Nt;exports.GoogleLogo=XK;exports.GrantType=Vt;exports.HttpSamlSigner=Im;exports.Icon=Ke;exports.IdentifierForm=xs;exports.IdentifierPage=Ss;exports.InputUI=Yt;exports.InvalidSession=G1;exports.LabelUI=Lt;exports.Layout=De;exports.LogTypes=_e;exports.Message=Dt;exports.NodeType=x0;exports.PreSignUpConfirmationPage=J1;exports.PreSignUpPage=K1;exports.ResetPasswordPage=Hr;exports.SignUpPage=ir;exports.SocialButton=O1;exports.Spinner=j1;exports.Trans=Yn;exports.UnverifiedEmailPage=F1;exports.UserNotFoundPage=ZK;exports.VippsLogo=YK;exports.auth0FlowInsertSchema=Ow;exports.auth0FlowSchema=I0;exports.auth0UserResponseSchema=an;exports.authParamsSchema=ro;exports.baseUserSchema=Oa;exports.bordersSchema=K0;exports.brandingSchema=kl;exports.buttonComponentSchema=w0;exports.clientGrantInsertSchema=Ps;exports.clientGrantListSchema=jw;exports.clientGrantSchema=ar;exports.clientInsertSchema=Ts;exports.clientSchema=sr;exports.codeInsertSchema=O0;exports.codeSchema=Tw;exports.codeTypeSchema=j0;exports.colorsSchema=G0;exports.componentSchema=k0;exports.connectionInsertSchema=Rs;exports.connectionOptionsSchema=Wr;exports.connectionSchema=Kt;exports.coordinatesSchema=wi;exports.createInMemoryCache=Ho;exports.customDomainInsertSchema=yu;exports.customDomainSchema=Ln;exports.customDomainWithTenantIdSchema=Pw;exports.emailProviderSchema=fs;exports.endingSchema=N0;exports.fieldComponentSchema=b0;exports.flowNodeSchema=z0;exports.fontDetailsSchema=rr;exports.fontsSchema=W0;exports.formControlSchema=Rw;exports.formInsertSchema=Bs;exports.formNodeComponentDefinition=P0;exports.formSchema=Vr;exports.genericComponentSchema=$0;exports.genericNodeSchema=A0;exports.hookInsertSchema=ds;exports.hookSchema=Kr;exports.identitySchema=_0;exports.init=tG;exports.injectTailwindCSS=B8;exports.inviteInsertSchema=wu;exports.inviteSchema=Gi;exports.inviteeSchema=U0;exports.inviterSchema=L0;exports.jwksKeySchema=D0;exports.jwksSchema=vu;exports.legalComponentSchema=v0;exports.logSchema=Ls;exports.loginSessionInsertSchema=M0;exports.loginSessionSchema=Mw;exports.nodeSchema=E0;exports.openIDConfigurationSchema=xl;exports.organizationBrandingSchema=dm;exports.organizationEnabledConnectionSchema=um;exports.organizationInsertSchema=Fs;exports.organizationSchema=Dn;exports.organizationTokenQuotaSchema=pm;exports.pageBackgroundSchema=J0;exports.parseUserId=Qw;exports.passwordInsertSchema=q0;exports.passwordSchema=qw;exports.profileDataSchema=m0;exports.promptSettingSchema=ps;exports.refreshTokenInsertSchema=$u;exports.refreshTokenSchema=Hw;exports.resourceServerInsertSchema=Us;exports.resourceServerListSchema=Gw;exports.resourceServerOptionsSchema=Q0;exports.resourceServerSchema=cr;exports.resourceServerScopeSchema=Y0;exports.richTextComponentSchema=y0;exports.roleInsertSchema=Ds;exports.roleListSchema=Ms;exports.rolePermissionInsertSchema=em;exports.rolePermissionListSchema=Ww;exports.rolePermissionSchema=tm;exports.rolePermissionWithDetailsListSchema=rm;exports.rolePermissionWithDetailsSchema=nm;exports.roleSchema=lr;exports.sessionInsertSchema=V0;exports.sessionSchema=Ba;exports.signingKeySchema=Sl;exports.smsProviderSchema=Kw;exports.smsSendParamsSchema=Vw;exports.startSchema=C0;exports.stepNodeSchema=S0;exports.tailwindCss=Fp;exports.tenantInsertSchema=Ki;exports.tenantSchema=Un;exports.tenantSettingsSchema=Yw;exports.themeInsertSchema=Z0;exports.themeSchema=us;exports.tokenResponseSchema=bu;exports.totalsSchema=St;exports.userInsertSchema=Os;exports.userOrganizationInsertSchema=fm;exports.userOrganizationSchema=Zw;exports.userPermissionInsertSchema=im;exports.userPermissionListSchema=Jw;exports.userPermissionSchema=om;exports.userPermissionWithDetailsListSchema=am;exports.userPermissionWithDetailsSchema=sm;exports.userResponseSchema=Cw;exports.userRoleInsertSchema=cm;exports.userRoleListSchema=Xw;exports.userRoleSchema=lm;exports.userSchema=gu;exports.verificationMethodsSchema=T0;exports.waitUntil=ve;exports.widgetSchema=X0;exports.withMainTenantFallback=eG;